'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BasicAuth = undefined;

var _electron = require('electron');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactBootstrap = require('react-bootstrap');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const { i18n } = window;
const __ = i18n.others.__.bind(i18n.others);

const BALogin = (usr, pwd) => {
  _electron.ipcRenderer.send('basic-auth-info', usr, pwd);
};
class BasicAuth extends _react2.default.Component {
  constructor(...args) {
    var _temp;

    return _temp = super(...args), this.state = {
      showModal: false,
      user: '',
      password: ''
    }, this.login = (usr, passwd) => {
      BALogin(this.state.user, this.state.password);
      this.setState({
        showModal: false,
        user: '',
        password: ''
      });
    }, this.close = () => {
      this.setState({ showModal: false });
    }, this.open = () => {
      this.setState({ showModal: true });
    }, this.handleUser = e => {
      this.setState({ user: e.target.value });
    }, this.handlePassword = e => {
      this.setState({ password: e.target.value });
    }, this.componentDidMount = () => {
      _electron.ipcRenderer.on('http-basic-auth', (event, arg) => {
        this.open();
      });
    }, _temp;
  }

  render() {
    return _react2.default.createElement(
      _reactBootstrap.Modal,
      { show: this.state.showModal, onHide: this.close },
      _react2.default.createElement(
        _reactBootstrap.Modal.Header,
        { closeButton: true },
        _react2.default.createElement(
          _reactBootstrap.Modal.Title,
          null,
          __("Website requires login")
        )
      ),
      _react2.default.createElement(
        _reactBootstrap.Modal.Body,
        null,
        _react2.default.createElement(
          _reactBootstrap.Form,
          { horizontal: true },
          _react2.default.createElement(
            _reactBootstrap.FormGroup,
            { controlId: 'formHorizontalEmail' },
            _react2.default.createElement(
              _reactBootstrap.Col,
              { componentClass: _reactBootstrap.ControlLabel, sm: 2 },
              __("Username")
            ),
            _react2.default.createElement(
              _reactBootstrap.Col,
              { sm: 10 },
              _react2.default.createElement(_reactBootstrap.FormControl, { value: this.state.user, type: 'username', placeholder: __("Username"), onChange: this.handleUser })
            )
          ),
          _react2.default.createElement(
            _reactBootstrap.FormGroup,
            { controlId: 'formHorizontalPassword' },
            _react2.default.createElement(
              _reactBootstrap.Col,
              { componentClass: _reactBootstrap.ControlLabel, sm: 2 },
              __("Password")
            ),
            _react2.default.createElement(
              _reactBootstrap.Col,
              { sm: 10 },
              _react2.default.createElement(_reactBootstrap.FormControl, { value: this.state.password, type: 'password', placeholder: __("Password"), onChange: this.handlePassword })
            )
          )
        )
      ),
      _react2.default.createElement(
        _reactBootstrap.Modal.Footer,
        null,
        _react2.default.createElement(
          _reactBootstrap.Button,
          { onClick: this.close },
          __("Cancel")
        ),
        _react2.default.createElement(
          _reactBootstrap.Button,
          { bsStyle: 'primary', onClick: this.login },
          __("Confirm")
        )
      )
    );
  }
}

exports.BasicAuth = BasicAuth;