'use strict';

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

var _class, _temp5;

var _pathExtra = require('path-extra');

var _pathExtra2 = _interopRequireDefault(_pathExtra);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _electron = require('electron');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactFontawesome = require('react-fontawesome');

var _reactFontawesome2 = _interopRequireDefault(_reactFontawesome);

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

var _lodash = require('lodash');

var _reactRedux = require('react-redux');

var _reactRemarkable = require('react-remarkable');

var _reactRemarkable2 = _interopRequireDefault(_reactRemarkable);

var _reactFileDropzone = require('react-file-dropzone');

var _reactFileDropzone2 = _interopRequireDefault(_reactFileDropzone);

var _utils = require('./utils');

var _pluginManager = require('views/services/plugin-manager');

var _pluginManager2 = _interopRequireDefault(_pluginManager);

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

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

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

const { dialog } = _electron.remote.require('electron');
const { PLUGIN_PATH } = window;

class PluginSettingWrap extends _react.Component {
  constructor(...args) {
    var _temp;

    return _temp = super(...args), this.shouldComponentUpdate = (nextProps, nextState) => this.props.plugin.timestamp !== nextProps.plugin.timestamp, _temp;
  }

  render() {
    return _react2.default.createElement(this.props.plugin.settingsClass);
  }
}

// class CollapsiblePanel extends Component {
//   static propTypes = {
//     expanded: PropTypes.bool,
//     transitionTime: PropTypes.number,
//     className: PropTypes.string,
//   }
//   constructor(props) {
//     super(props)
//     this.state = {
//       expanded: props.expanded,
//       hide: !props.expanded,
//     }
//   }
//   componentWillReceiveProps = (nextProps) => {
//     let transitionTime = this.props.transitionTime || 400
//     if (this.props.expanded && !nextProps.expanded) {
//       this.setState({expanded: false})
//       delay(() => {this.setState({hide: true})}, transitionTime)
//     }
//     else if (!this.props.expanded && nextProps.expanded) {
//       this.setState({hide: false})
//       defer(() => {this.setState({expanded: true})})
//     }
//   }
//   render() {
//     let className = classnames(this.props.className, {
//       'hidden': this.state.hide,
//     })
//     return (
//       <Panel {...this.props} className={className} />
//     )
//   }
// }

PluginSettingWrap.propTypes = {
  plugin: _propTypes2.default.object
};
class InstalledPlugin extends _react.PureComponent {
  constructor(...args) {
    var _temp2;

    return _temp2 = super(...args), this.state = {
      settingOpen: false
    }, this.toggleSettingPop = () => {
      this.setState({ settingOpen: !this.state.settingOpen });
    }, _temp2;
  }

  render() {
    const plugin = this.props.plugin;
    const outdatedLabelbsStyle = !plugin.latestVersion.includes('beta') ? 'primary' : 'warning';
    const outdatedLabelFAname = (0, _classnames2.default)({
      'spinner': plugin.isUpdating,
      'cloud-download': !plugin.isUpdating && plugin.isOutdated,
      'check': !plugin.isUpdating && !plugin.isOutdated
    });
    const outdatedLabelText = plugin.isUpdating ? `${__('Updating')}` : plugin.isOutdated ? `Version ${plugin.latestVersion}` : `${__('Latest')}`;
    let enableBtnText, enableBtnFAname;
    switch (_pluginManager2.default.getStatusOfPlugin(plugin)) {
      case _pluginManager2.default.VALID:
        enableBtnText = `${__('Disable')}`;
        enableBtnFAname = 'pause';
        break;
      case _pluginManager2.default.DISABLED:
        enableBtnText = `${__('Enable')}`;
        enableBtnFAname = 'play';
        break;
      case _pluginManager2.default.NEEDUPDATE:
        enableBtnText = `${__('Outdated')}`;
        enableBtnFAname = 'ban';
        break;
      case _pluginManager2.default.BROKEN:
        enableBtnText = `${__('Error')}`;
        enableBtnFAname = 'close';
        break;
      default:
        enableBtnText = '';
        enableBtnFAname = '';
    }
    const removeBtnText = plugin.isUninstalling ? `${__('Removing')}` : `${__('Remove')}`;
    const removeBtnFAname = plugin.isInstalled ? 'trash' : 'trash-o';
    const panelClass = (0, _classnames2.default)('plugin-content', {
      'plugin-content-disabled': _pluginManager2.default.getStatusOfPlugin(plugin) !== _pluginManager2.default.VALID
    });
    const outdatedLabelClass = (0, _classnames2.default)('update-label', {
      'hidden': !plugin.isOutdated
    });
    const settingAvailable = plugin.settingsClass || plugin.switchPluginPath || !plugin.multiWindow && plugin.windowURL;
    const btnGroupClass = (0, _classnames2.default)('plugin-buttongroup', {
      'btn-xs-12': settingAvailable,
      'btn-xs-8': !settingAvailable
    });
    const btnClass = (0, _classnames2.default)('plugin-control-button', {
      'btn-xs-4': settingAvailable,
      'btn-xs-6': !settingAvailable
    });
    return _react2.default.createElement(
      _reactBootstrap.Row,
      { className: 'plugin-wrapper' },
      _react2.default.createElement(
        _reactBootstrap.Col,
        { xs: 12 },
        _react2.default.createElement(
          _reactBootstrap.Panel,
          { className: panelClass },
          _react2.default.createElement(
            _reactBootstrap.Row,
            null,
            _react2.default.createElement(
              _reactBootstrap.Col,
              { xs: 12, className: 'div-row' },
              _react2.default.createElement(
                'span',
                { className: 'plugin-name' },
                plugin.displayName
              ),
              _react2.default.createElement(
                'div',
                { className: 'author-wrapper' },
                '@',
                _react2.default.createElement(
                  'a',
                  { className: 'author-link',
                    href: plugin.link },
                  plugin.author
                )
              ),
              _react2.default.createElement(
                'div',
                { className: 'update-wrapper' },
                _react2.default.createElement(
                  'div',
                  null,
                  _react2.default.createElement(
                    _reactBootstrap.Label,
                    { bsStyle: outdatedLabelbsStyle,
                      className: outdatedLabelClass,
                      onClick: this.props.handleUpdate },
                    _react2.default.createElement(_reactFontawesome2.default, { name: outdatedLabelFAname,
                      pulse: plugin.isUpdating }),
                    outdatedLabelText
                  )
                ),
                _react2.default.createElement(
                  'div',
                  null,
                  _react2.default.createElement(
                    'span',
                    null,
                    plugin.linkedPlugin && _react2.default.createElement(_reactFontawesome2.default, { name: 'link' })
                  ),
                  `Ver. ${plugin.version || '1.0.0'}`
                )
              )
            )
          ),
          _react2.default.createElement(
            _reactBootstrap.Row,
            null,
            _react2.default.createElement(
              _reactBootstrap.Col,
              { className: 'plugin-description', xs: 7 },
              _react2.default.createElement(_reactRemarkable2.default, { source: plugin.description })
            ),
            _react2.default.createElement(
              _reactBootstrap.Col,
              { className: 'plugin-option', xs: 5 },
              _react2.default.createElement(
                _reactBootstrap.ButtonGroup,
                { bsSize: 'small', className: btnGroupClass },
                settingAvailable ? _react2.default.createElement(
                  _reactBootstrap.OverlayTrigger,
                  { placement: 'top', overlay: _react2.default.createElement(
                      _reactBootstrap.Tooltip,
                      { id: `${plugin.id}-set-btn` },
                      __('Settings')
                    ) },
                  _react2.default.createElement(
                    _reactBootstrap.Button,
                    {
                      bsStyle: 'primary', bsSize: 'xs',
                      onClick: this.toggleSettingPop,
                      className: 'plugin-control-button btn-xs-4' },
                    _react2.default.createElement(_reactFontawesome2.default, { name: 'gear' })
                  )
                ) : null,
                _react2.default.createElement(
                  _reactBootstrap.OverlayTrigger,
                  { placement: 'top', overlay: _react2.default.createElement(
                      _reactBootstrap.Tooltip,
                      { id: `${plugin.id}-enb-btn` },
                      enableBtnText
                    ) },
                  _react2.default.createElement(
                    _reactBootstrap.Button,
                    { bsStyle: 'info',
                      disabled: _pluginManager2.default.getStatusOfPlugin(plugin) == _pluginManager2.default.NEEDUPDATE,
                      onClick: this.props.handleEnable,
                      className: btnClass },
                    _react2.default.createElement(_reactFontawesome2.default, { name: enableBtnFAname })
                  )
                ),
                _react2.default.createElement(
                  _reactBootstrap.OverlayTrigger,
                  { placement: 'top', overlay: _react2.default.createElement(
                      _reactBootstrap.Tooltip,
                      { id: `${plugin.id}-rm-btn` },
                      removeBtnText
                    ) },
                  _react2.default.createElement(
                    _reactBootstrap.Button,
                    { bsStyle: 'danger',
                      onClick: this.props.handleRemove,
                      disabled: !plugin.isInstalled,
                      className: btnClass },
                    _react2.default.createElement(_reactFontawesome2.default, { name: removeBtnFAname })
                  )
                )
              )
            )
          ),
          _react2.default.createElement(
            _reactBootstrap.Row,
            null,
            settingAvailable ? _react2.default.createElement(
              _reactBootstrap.Collapse,
              { 'in': this.state.settingOpen, className: 'plugin-setting-wrapper' },
              _react2.default.createElement(
                _reactBootstrap.Col,
                { xs: 12 },
                _react2.default.createElement(
                  _reactBootstrap.Well,
                  null,
                  !!plugin.switchPluginPath && _react2.default.createElement(
                    'div',
                    null,
                    _react2.default.createElement(_utils.CheckboxLabelConfig, {
                      label: __('Enable auto switch'),
                      configName: `poi.autoswitch.${plugin.id}`,
                      defaultVal: true })
                  ),
                  !plugin.multiWindow && plugin.windowURL && _react2.default.createElement(
                    'div',
                    null,
                    _react2.default.createElement(_utils.CheckboxLabelConfig, {
                      label: __('Keep plugin process running in background (re-enable to apply changes)'),
                      configName: `poi.backgroundProcess.${plugin.id}`,
                      defaultVal: !plugin.realClose })
                  ),
                  !!plugin.settingsClass && _react2.default.createElement(
                    'div',
                    null,
                    _react2.default.createElement(PluginSettingWrap, { plugin: plugin })
                  )
                )
              )
            ) : null
          )
        )
      )
    );
  }
}

InstalledPlugin.propTypes = {
  plugin: _propTypes2.default.object,
  handleUpdate: _propTypes2.default.func,
  handleEnable: _propTypes2.default.func,
  handleRemove: _propTypes2.default.func
};
class UninstalledPlugin extends _react.PureComponent {
  render() {
    const plugin = this.props.plugin;
    const installButtonText = this.props.installing ? `${__('Installing')}` : `${__('Install')}`;
    const installButtonFAname = this.props.installing ? 'spinner' : 'download';
    return _react2.default.createElement(
      _reactBootstrap.Row,
      { className: 'plugin-wrapper' },
      _react2.default.createElement(
        _reactBootstrap.Col,
        { xs: 12 },
        _react2.default.createElement(
          _reactBootstrap.Panel,
          { className: 'plugin-content' },
          _react2.default.createElement(
            _reactBootstrap.Row,
            null,
            _react2.default.createElement(
              _reactBootstrap.Col,
              { xs: 12, className: 'div-row' },
              _react2.default.createElement(
                'span',
                { className: 'plugin-name' },
                _react2.default.createElement(_reactFontawesome2.default, { name: plugin.icon }),
                ` ${plugin[window.language]}`
              ),
              _react2.default.createElement(
                'div',
                { className: 'author-wrapper' },
                '@',
                _react2.default.createElement(
                  'a',
                  { className: 'author-link',
                    href: plugin.link },
                  plugin.author
                )
              )
            )
          ),
          _react2.default.createElement(
            _reactBootstrap.Row,
            null,
            _react2.default.createElement(
              _reactBootstrap.Col,
              { className: 'plugin-description', xs: 7 },
              _react2.default.createElement(_reactRemarkable2.default, { source: plugin[`des${window.language}`] })
            ),
            _react2.default.createElement(
              _reactBootstrap.Col,
              { className: 'plugin-option-install', xs: 5 },
              _react2.default.createElement(
                _reactBootstrap.ButtonGroup,
                { bsSize: 'small', className: 'plugin-buttongroup btn-xs-4' },
                _react2.default.createElement(
                  _reactBootstrap.OverlayTrigger,
                  { placement: 'top', overlay: _react2.default.createElement(
                      _reactBootstrap.Tooltip,
                      { id: `${plugin.id}-ins-btn` },
                      installButtonText
                    ) },
                  _react2.default.createElement(
                    _reactBootstrap.Button,
                    { bsStyle: 'primary',
                      disabled: this.props.npmWorking,
                      onClick: this.props.handleInstall,
                      className: 'plugin-control-button btn-xs-12' },
                    _react2.default.createElement(_reactFontawesome2.default, { name: installButtonFAname,
                      pulse: this.props.installing })
                  )
                )
              )
            )
          )
        )
      )
    );
  }
}

UninstalledPlugin.propTypes = {
  plugin: _propTypes2.default.object,
  installing: _propTypes2.default.bool,
  npmWorking: _propTypes2.default.bool,
  handleInstall: _propTypes2.default.func
};
class InstallByNameInput extends _react.PureComponent {
  constructor(...args) {
    var _temp3;

    return _temp3 = super(...args), this.state = {
      manuallyInstallPackage: ''
    }, this.changeInstalledPackage = e => {
      this.setState({ manuallyInstallPackage: e.target.value });
    }, this.validPackageName = () => {
      return (0, _lodash.get)(this.state, 'manuallyInstallPackage.length', 0) > 0 && /^poi-plugin-.*$/.test(this.state.manuallyInstallPackage);
    }, _temp3;
  }

  render() {
    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 || !this.validPackageName(),
              onClick: this.props.handleManuallyInstall.bind(null, this.state.manuallyInstallPackage) },
            __('Install')
          )
        )
      )
    );
  }
}

InstallByNameInput.propTypes = {
  handleManuallyInstall: _propTypes2.default.func,
  manuallyInstallStatus: _propTypes2.default.number,
  npmWorking: _propTypes2.default.bool
};
const PluginConfig = (0, _reactRedux.connect)((state, props) => ({
  plugins: state.plugins,
  mirrorName: (0, _lodash.get)(state, 'config.packageManager.mirrorName', navigator.language === 'zh-CN' ? "taobao" : "npm"),
  proxy: (0, _lodash.get)(state, 'config.packageManager.proxy', false),
  betaCheck: (0, _lodash.get)(state, 'config.packageManager.enableBetaPluginCheck', false),
  autoUpdate: (0, _lodash.get)(state, 'config.packageManager.enableAutoUpdate', true)
}))((_temp5 = _class = class pluginConfig extends _react.Component {
  constructor(...args) {
    var _temp4, _this;

    return _temp4 = _this = super(...args), this.state = {
      checkingUpdate: false,
      npmWorking: false,
      installingAll: false,
      installingPluginNames: [],
      updatingAll: false,
      reloading: false,
      advanced: false,
      manuallyInstallStatus: 0
    }, this.isUpdateAvailable = false, this.checkCount = 0, this.handleEnableBetaPluginCheck = () => {
      _pluginManager2.default.selectConfig(null, null, !this.props.betaCheck);
    }, this.handleEnableProxy = () => {
      _pluginManager2.default.selectConfig(null, !this.props.proxy, null);
    }, this.handleEnableAutoUpdate = () => {
      // unlike other options, autoUpdate will not write to npm conf
      window.config.set('packageManager.enableAutoUpdate', !this.props.autoUpdate);
    }, this.onSelectServer = state => {
      _pluginManager2.default.selectConfig(state, null, null);
    }, this.handleAdvancedShow = () => {
      this.setState({ advanced: !this.state.advanced });
    }, this.handleEnable = (() => {
      var _ref = _asyncToGenerator(function* (index) {
        const plugins = _pluginManager2.default.getInstalledPlugins();
        const plugin = plugins[index];
        switch (_pluginManager2.default.getStatusOfPlugin(plugin)) {
          case _pluginManager2.default.DISABLED:
            yield _pluginManager2.default.enablePlugin(plugin);
            break;
          case _pluginManager2.default.VALID:
            yield _pluginManager2.default.disablePlugin(plugin);
            break;
        }
      });

      return function (_x) {
        return _ref.apply(this, arguments);
      };
    })(), this.handleInstall = (() => {
      var _ref2 = _asyncToGenerator(function* (name, e) {
        if ((0, _lodash.get)(e, 'target.disabled')) {
          return;
        }
        let installingPluginNames = _this.state.installingPluginNames;
        installingPluginNames.push(name);
        _this.setState({
          installingPluginNames: installingPluginNames,
          npmWorking: true
        });
        try {
          yield _pluginManager2.default.installPlugin(name);
          installingPluginNames = _this.state.installingPluginNames;
          const index = installingPluginNames.indexOf(name);
          if (index > -1) {
            installingPluginNames.splice(index, 1);
            _this.setState({
              installingPluginNames: installingPluginNames,
              npmWorking: false
            });
          }
        } catch (error) {
          _this.setState({ npmWorking: false });
          throw error;
        }
      });

      return function (_x2, _x3) {
        return _ref2.apply(this, arguments);
      };
    })(), this.handleUpdate = (() => {
      var _ref3 = _asyncToGenerator(function* (index, e) {
        if ((0, _lodash.get)(e, 'target.disabled')) {
          return;
        }
        _this.setState({ npmWorking: true });
        const plugins = _pluginManager2.default.getInstalledPlugins();
        const plugin = plugins[index];
        if (plugin.linkedPlugin) {
          return;
        }
        try {
          yield _pluginManager2.default.installPlugin(plugin.packageName, plugin.latestVersion);
          _this.setState({ npmWorking: false });
        } catch (error) {
          _this.setState({ npmWorking: false });
          throw error;
        }
      });

      return function (_x4, _x5) {
        return _ref3.apply(this, arguments);
      };
    })(), this.handleInstallAll = _asyncToGenerator(function* () {
      _this.setState({
        installingAll: true,
        npmWorking: true
      });
      const settings = _pluginManager2.default.getUninstalledPluginSettings();
      for (const name in settings) {
        yield _this.handleInstall(name);
      }
      _this.setState({
        installingAll: false,
        npmWorking: false
      });
    }), this.handleUpdateAll = (() => {
      var _ref5 = _asyncToGenerator(function* (e) {
        if ((0, _lodash.get)(e, 'target.disabled')) {
          return;
        }
        _this.setState({
          updatingAll: true,
          npmWorking: true
        });
        const plugins = _pluginManager2.default.getInstalledPlugins();
        for (const index in plugins) {
          if (plugins[index].isOutdated) {
            try {
              yield _this.handleUpdate(index);
            } catch (error) {
              throw error;
            }
          }
        }
        _this.setState({
          updatingAll: false,
          npmWorking: false
        });
      });

      return function (_x6) {
        return _ref5.apply(this, arguments);
      };
    })(), this.handleRemove = (() => {
      var _ref6 = _asyncToGenerator(function* (index, e) {
        if ((0, _lodash.get)(e, 'target.disabled')) {
          return;
        }
        _this.setState({ npmWorking: true });
        try {
          const plugins = _pluginManager2.default.getInstalledPlugins();
          const plugin = plugins[index];
          yield _pluginManager2.default.uninstallPlugin(plugin);
          _this.setState({ npmWorking: false });
        } catch (error) {
          _this.setState({ npmWorking: false });
          throw error;
        }
      });

      return function (_x7, _x8) {
        return _ref6.apply(this, arguments);
      };
    })(), this.checkUpdate = _asyncToGenerator(function* () {
      _this.setState({
        checkingUpdate: true,
        npmWorking: true
      });
      yield _pluginManager2.default.getOutdatedPlugins();
      _this.setState({
        checkingUpdate: false,
        npmWorking: false
      });
    }), this.onSelectOpenFolder = () => {
      _electron.shell.openItem(_pathExtra2.default.join(PLUGIN_PATH, 'node_modules'));
    }, this.onSelectOpenSite = e => {
      _electron.shell.openExternal("https://www.npmjs.com/search?q=poi-plugin");
      e.preventDefault();
    }, this.onSelectInstallFromFile = () => {
      this.synchronize(_asyncToGenerator(function* () {
        const filenames = dialog.showOpenDialog({
          title: __('Select files'),
          defaultPath: _electron.remote.require('electron').app.getPath('downloads'),
          properties: ['openFile', 'multiSelections']
        });
        if (filenames) {
          for (const index in filenames) {
            const filename = filenames[index];
            _this.setState({ manuallyInstallStatus: 1 });
            try {
              yield _this.handleInstall(filename);
              _this.setState({ manuallyInstallStatus: 2 });
            } catch (error) {
              _this.setState({ manuallyInstallStatus: 3 });
            }
          }
        }
      }));
    }, this.onDropInstallFromFile = (() => {
      var _ref9 = _asyncToGenerator(function* (droppedFiles) {
        const filenames = [];
        // droppedFiles is not an Array, but a FileList
        for (let i = 0; i < droppedFiles.length; i++) {
          filenames.push(droppedFiles[i].path);
        }
        if (filenames.length > 0) {
          for (const index in filenames) {
            const filename = filenames[index];
            _this.setState({ manuallyInstallStatus: 1 });
            try {
              yield _this.handleInstall(filename);
              _this.setState({ manuallyInstallStatus: 2 });
            } catch (error) {
              _this.setState({ manuallyInstallStatus: 3 });
            }
          }
        }
      });

      return function (_x9) {
        return _ref9.apply(this, arguments);
      };
    })(), this.handleManuallyInstall = (() => {
      var _ref10 = _asyncToGenerator(function* (name) {
        _this.setState({ manuallyInstallStatus: 1 });
        try {
          yield _this.handleInstall(name);
          _this.setState({ manuallyInstallStatus: 2 });
        } catch (error) {
          _this.setState({ manuallyInstallStatus: 3 });
        }
      });

      return function (_x10) {
        return _ref10.apply(this, arguments);
      };
    })(), this.synchronize = callback => {
      if (this.lock) {
        return;
      }
      this.lock = true;
      callback();
      this.lock = false;
    }, this.componentDidUpdate = (prevProps, prevState) => {
      if (prevState.manuallyInstallStatus > 1 && prevState.manuallyInstallStatus === this.state.manuallyInstallStatus) {
        this.setState({ manuallyInstallStatus: 0 });
      }
    }, this.componentDidMount = _asyncToGenerator(function* () {
      _this.setState({
        checkingUpdate: true,
        npmWorking: true
      });
      const isNotif = window.config.get('config.packageManager.enablePluginCheck', true) && !_this.props.autoUpdate; // if we auto update plugins, don't toast notify
      const handleAutoUpdate = (() => {
        var _ref12 = _asyncToGenerator(function* () {
          yield _pluginManager2.default.getOutdatedPlugins(isNotif);
          if (_this.props.autoUpdate) {
            const plugins = _pluginManager2.default.getInstalledPlugins();
            for (const index in plugins) {
              if (plugins[index].isOutdated) {
                try {
                  yield _this.handleUpdate(index);
                } catch (error) {
                  throw error;
                }
              }
            }
          }
        });

        return function handleAutoUpdate() {
          return _ref12.apply(this, arguments);
        };
      })();
      _pluginManager2.default.on('initialized', handleAutoUpdate);
      _this.setState({
        checkingUpdate: false,
        npmWorking: false
      });
    }), _temp4;
  }

  render() {
    const uninstalledPluginSettings = _pluginManager2.default.getUninstalledPluginSettings();
    const mirrors = _pluginManager2.default.getMirrors();
    const updateStatusFAname = this.state.updatingAll ? 'spinner' : 'cloud-download';
    const installStatusFAname = this.state.installingAll ? 'spinner' : 'download';
    let installStatusbsStyle, installStatusText;
    switch (this.state.manuallyInstallStatus) {
      case 1:
        installStatusbsStyle = 'info';
        installStatusText = `${__("Installing")}...`;
        break;
      case 2:
        installStatusbsStyle = 'success';
        installStatusText = `${__("Plugins are installed successfully.")}`;
        break;
      case 3:
        installStatusbsStyle = 'danger';
        installStatusText = `${__("Install failed. Maybe the selected files are not plugin packages.")}`;
        break;
      default:
        installStatusbsStyle = 'warning';
        installStatusText = '';
    }
    const advanceFAname = this.state.advanced ? 'angle-up' : 'angle-down';
    return _react2.default.createElement(
      'form',
      { className: 'contents-wrapper', style: { marginTop: '10px' } },
      _react2.default.createElement(
        _reactFileDropzone2.default,
        {
          className: 'plugin-dropfile panel',
          onDrop: this.onDropInstallFromFile,
          acceptType: 'application/gzip, application/x-gzip'
        },
        __('Drop plugin tarballs here to install')
      ),
      _react2.default.createElement(
        _reactBootstrap.Grid,
        { className: 'correct-container' },
        _react2.default.createElement(
          _reactBootstrap.Row,
          { className: 'plugin-rowspace' },
          _react2.default.createElement(
            _reactBootstrap.Col,
            { xs: 12 },
            window.isSafeMode && _react2.default.createElement(
              _reactBootstrap.Panel,
              { header: __('Safe Mode'), bsStyle: 'warning' },
              __('Poi is running in safe mode, plugins are not enabled automatically.')
            ),
            _react2.default.createElement(
              _reactBootstrap.ButtonGroup,
              { bsSize: 'small', className: 'plugin-buttongroup' },
              _react2.default.createElement(
                _reactBootstrap.Button,
                { onClick: this.checkUpdate,
                  disabled: this.state.checkingUpdate,
                  className: 'control-button col-xs-3' },
                _react2.default.createElement(_reactFontawesome2.default, { name: 'refresh', spin: this.state.checkingUpdate }),
                _react2.default.createElement(
                  'span',
                  null,
                  ' ',
                  __("Check Update")
                )
              ),
              _react2.default.createElement(
                _reactBootstrap.Button,
                { onClick: this.handleUpdateAll,
                  disabled: this.state.npmWorking || this.state.checkingUpdate || !_pluginManager2.default.getUpdateStatus(),
                  className: 'control-button col-xs-3' },
                _react2.default.createElement(_reactFontawesome2.default, { name: updateStatusFAname,
                  pulse: this.state.updatingAll }),
                _react2.default.createElement(
                  'span',
                  null,
                  ' ',
                  __("Update all")
                )
              ),
              _react2.default.createElement(
                _reactBootstrap.Button,
                { onClick: this.handleInstallAll,
                  disabled: this.state.npmWorking || Object.keys(uninstalledPluginSettings).length === 0,
                  className: 'control-button col-xs-3' },
                _react2.default.createElement(_reactFontawesome2.default, { name: installStatusFAname,
                  pulse: this.state.installingAll }),
                _react2.default.createElement(
                  'span',
                  null,
                  ' ',
                  __("Install all")
                )
              ),
              _react2.default.createElement(
                _reactBootstrap.Button,
                { onClick: this.handleAdvancedShow,
                  className: 'control-button col-xs-3' },
                _react2.default.createElement(_reactFontawesome2.default, { name: 'gear' }),
                _react2.default.createElement(
                  'span',
                  null,
                  ' ',
                  __("Advanced"),
                  ' '
                ),
                _react2.default.createElement(_reactFontawesome2.default, { name: advanceFAname })
              )
            )
          )
        ),
        _react2.default.createElement(
          _reactBootstrap.Row,
          null,
          _react2.default.createElement(
            _reactBootstrap.Col,
            { xs: 12 },
            _react2.default.createElement(
              _reactBootstrap.Collapse,
              { 'in': this.state.advanced },
              _react2.default.createElement(
                _reactBootstrap.Well,
                null,
                _react2.default.createElement(
                  'div',
                  null,
                  _react2.default.createElement(
                    _reactBootstrap.Row,
                    null,
                    _react2.default.createElement(
                      _reactBootstrap.Col,
                      { xs: 12 },
                      _react2.default.createElement(_utils.CheckboxLabelConfig, {
                        label: __('Switch to Plugin Automatically'),
                        configName: 'poi.autoswitch.enabled',
                        defaultVal: true }),
                      _react2.default.createElement(_utils.CheckboxLabelConfig, {
                        label: __('Enable autoswitch for main panel'),
                        configName: 'poi.autoswitch.main',
                        defaultVal: true })
                    )
                  ),
                  _react2.default.createElement(
                    _reactBootstrap.Row,
                    null,
                    _react2.default.createElement(
                      _reactBootstrap.Col,
                      { xs: 12 },
                      _react2.default.createElement(
                        _reactBootstrap.Row,
                        null,
                        _react2.default.createElement(
                          _reactBootstrap.Col,
                          { xs: 12 },
                          _react2.default.createElement(
                            'label',
                            { className: 'control-label' },
                            __('Select npm server')
                          )
                        )
                      ),
                      _react2.default.createElement(
                        _reactBootstrap.Row,
                        null,
                        Object.keys(mirrors).map((server, index) => {
                          return _react2.default.createElement(
                            _reactBootstrap.OverlayTrigger,
                            { placement: 'top', key: index, overlay: _react2.default.createElement(
                                _reactBootstrap.Tooltip,
                                { id: `npm-server-${index}` },
                                mirrors[server].menuname
                              ) },
                            _react2.default.createElement(
                              _reactBootstrap.Col,
                              { key: index, xs: 6, className: 'select-npm-server' },
                              _react2.default.createElement(
                                _reactBootstrap.Radio,
                                { checked: this.props.mirrorName == server,
                                  onChange: this.onSelectServer.bind(this, server) },
                                mirrors[server].name
                              )
                            )
                          );
                        }, this)
                      )
                    ),
                    _react2.default.createElement(
                      _reactBootstrap.Col,
                      { xs: 12 },
                      _react2.default.createElement(
                        _reactBootstrap.Row,
                        null,
                        _react2.default.createElement(
                          _reactBootstrap.Col,
                          { xs: 12 },
                          _react2.default.createElement(
                            'label',
                            { className: 'control-label' },
                            __('Others')
                          )
                        )
                      ),
                      _react2.default.createElement(
                        'div',
                        null,
                        _react2.default.createElement(
                          _reactBootstrap.Checkbox,
                          { checked: this.props.proxy || false,
                            onChange: this.handleEnableProxy },
                          __('Connect to npm server through proxy')
                        )
                      ),
                      _react2.default.createElement(
                        'div',
                        null,
                        _react2.default.createElement(
                          _reactBootstrap.Checkbox,
                          { checked: this.props.autoUpdate || false,
                            onChange: this.handleEnableAutoUpdate },
                          __('Automatically update plugins')
                        )
                      ),
                      _react2.default.createElement(
                        'div',
                        null,
                        _react2.default.createElement(
                          _reactBootstrap.Checkbox,
                          { checked: this.props.betaCheck || false,
                            onChange: this.handleEnableBetaPluginCheck },
                          __('Developer option: check update of beta version')
                        )
                      ),
                      _react2.default.createElement(
                        _reactBootstrap.Row,
                        null,
                        _react2.default.createElement(
                          _reactBootstrap.ButtonGroup,
                          { className: 'plugin-buttongroup' },
                          _react2.default.createElement(
                            _reactBootstrap.Button,
                            { className: 'col-xs-6', onClick: this.onSelectOpenFolder },
                            __('Open plugin folder')
                          ),
                          _react2.default.createElement(
                            _reactBootstrap.Button,
                            { className: 'col-xs-6', onClick: this.onSelectOpenSite },
                            __('Search for plugins')
                          )
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        ),
        _react2.default.createElement(
          _reactBootstrap.Row,
          { className: 'plugin-rowspace' },
          _react2.default.createElement(
            _reactBootstrap.Collapse,
            { 'in': this.state.manuallyInstallStatus > 0 },
            _react2.default.createElement(
              _reactBootstrap.Col,
              { xs: 12 },
              _react2.default.createElement(
                _reactBootstrap.Alert,
                { bsStyle: installStatusbsStyle },
                installStatusText
              )
            )
          )
        ),
        _react2.default.createElement(
          _reactBootstrap.Row,
          { className: 'plugin-rowspace' },
          _react2.default.createElement(
            _reactBootstrap.Col,
            { xs: 12 },
            _react2.default.createElement(InstallByNameInput, { handleManuallyInstall: this.handleManuallyInstall,
              manuallyInstallStatus: this.state.manuallyInstallStatus,
              npmWorking: this.state.npmWorking })
          ),
          _react2.default.createElement(
            _reactBootstrap.Col,
            { xs: 12 },
            _react2.default.createElement(
              'div',
              { className: 'plugin-dropfile-static', onClick: this.onSelectInstallFromFile },
              __("Drop plugin packages here to install it, or click here to select them")
            )
          )
        ),
        this.props.plugins.map((plugin, index) => {
          return _react2.default.createElement(InstalledPlugin, {
            key: plugin.id,
            plugin: plugin,
            handleUpdate: (0, _lodash.partial)(this.handleUpdate, index),
            handleEnable: (0, _lodash.partial)(this.handleEnable, index),
            handleRemove: (0, _lodash.partial)(this.handleRemove, index)
          });
        }, this),
        Object.keys(uninstalledPluginSettings).map((name, index) => {
          const value = uninstalledPluginSettings[name];
          return _react2.default.createElement(UninstalledPlugin, {
            key: name,
            plugin: value,
            npmWorking: this.state.npmWorking,
            installing: this.state.installingPluginNames.includes(name),
            handleInstall: (0, _lodash.partial)(this.handleInstall, name)
          });
        }, this)
      )
    );
  }
}, _class.propTypes = {
  plugins: _propTypes2.default.array,
  mirrorName: _propTypes2.default.string,
  proxy: _propTypes2.default.bool,
  betaCheck: _propTypes2.default.bool,
  autoUpdate: _propTypes2.default.bool
}, _temp5));

exports.default = PluginConfig;
module.exports = exports['default'];