'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _lodash = require('lodash');

var _validateNpmPackageName = require('validate-npm-package-name');

var _validateNpmPackageName2 = _interopRequireDefault(_validateNpmPackageName);

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

const __ = window.i18n.setting.__.bind(window.i18n.setting);

class NameInput extends _react.PureComponent {
  constructor(...args) {
    var _temp;

    return _temp = super(...args), this.state = {
      manuallyInstallPackage: ''
    }, this.changeInstalledPackage = e => {
      this.setState({ manuallyInstallPackage: (0, _lodash.trim)(e.target.value) });
    }, _temp;
  }

  render() {
    const { manuallyInstallPackage } = this.state;
    const validPackageName = manuallyInstallPackage.length > 0 && /^poi-plugin-.*$/.test(manuallyInstallPackage) && (0, _validateNpmPackageName2.default)(manuallyInstallPackage).validForNewPackages;
    return _react2.default.createElement(
      _reactBootstrap.FormGroup,
      null,
      _react2.default.createElement(
        _reactBootstrap.ControlLabel,
        null,
        __('Install directly from npm')
      ),
      _react2.default.createElement(
        _reactBootstrap.InputGroup,
        { bsSize: 'small' },
        _react2.default.createElement(_reactBootstrap.FormControl, { type: 'text',
          value: this.state.manuallyInstallPackage,
          onChange: this.changeInstalledPackage,
          label: __('Install directly from npm'),
          disabled: this.props.manuallyInstallStatus === 1 || this.props.npmWorking,
          placeholder: __('Input plugin package name...') }),
        _react2.default.createElement(
          _reactBootstrap.InputGroup.Button,
          null,
          _react2.default.createElement(
            _reactBootstrap.Button,
            { bsStyle: 'primary',
              disabled: this.props.manuallyInstallStatus === 1 || this.props.npmWorking || !validPackageName,
              onClick: this.props.handleManuallyInstall.bind(null, this.state.manuallyInstallPackage) },
            __('Install')
          )
        )
      )
    );
  }
}
exports.default = NameInput;
NameInput.propTypes = {
  handleManuallyInstall: _propTypes2.default.func,
  manuallyInstallStatus: _propTypes2.default.number,
  npmWorking: _propTypes2.default.bool
};
module.exports = exports['default'];