text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = void 0;
  
  var _react = _interopRequireDefault(require("react"));
  
  var _dva = require("dva");
  
  var _antd = require("antd");
  
  var _model = _interopRequireDefault(require("./model"));
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
  
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  
  function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  
  function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  var FormItem = _antd.Form.Item;
  var Option = _antd.Select.Option;
  
  function toString(data) {
    if (typeof data === 'string') return data;else if (_typeof(data) === 'object') return JSON.stringify(data);else if (typeof data === 'boolean') return JSON.stringify(data);else throw new Error("unsupport data type: ".concat(_typeof(data)));
  }
  
  function ConfigItem(props) {
    /* eslint-disable no-unused-expressions */
    var name = props.name,
        data = props.data;
    return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement("li", null, name, name === 'plugins' ? _react.default.createElement(PluginList, {
      data: data
    }) : _react.default.createElement(ConfigPropertyItem, props)));
    /* eslint-enable no-unused-expressions */
  }
  
  function ConfigPropertyItem(_ref) {
    var name = _ref.name,
        data = _ref.data;
  
    function blurHandler(e) {
      window.send('config', ['set', name, "".concat(e.target.value)]);
    }
  
    return _react.default.createElement(_antd.Input, {
      size: "small",
      defaultValue: toString(data),
      onBlur: blurHandler
    });
  }
  
  function PluginList(_ref2) {
    var data = _ref2.data;
    return _react.default.createElement("ul", null, data.map(function (item, i) {
      return (// eslint-disable-next-line react/no-array-index-key
        _react.default.createElement(PluginItem, {
          key: i,
          data: item
        })
      );
    }));
  }
  
  function PluginItem(_ref3) {
    var data = _ref3.data;
  
    var _ref4 = Array.isArray(data) ? data : [data],
        _ref5 = _slicedToArray(_ref4, 2),
        name = _ref5[0],
        opts = _ref5[1];
  
    return _react.default.createElement("li", null, name, opts ? _react.default.createElement("input", {
      defaultValue: JSON.stringify(opts)
    }) : '');
  }
  
  var formItemLayout = {
    labelCol: {
      xs: {
        span: 24
      },
      sm: {
        span: 4
      }
    },
    wrapperCol: {
      xs: {
        span: 24
      },
      sm: {
        span: 16
      }
    }
  };
  var ConfigManager = (0, _dva.connect)(function (state) {
    return {
      config: state.config
    };
  })(_antd.Form.create()(function (props) {
    var getFieldDecorator = props.form.getFieldDecorator;
    var config = props.config.data;
  
    function onChange(name, value) {
      window.send('config', ['set', name, "".concat(value.target ? value.target.value : value)]);
    }
  
    return _react.default.createElement("div", null, _react.default.createElement("h2", null, "Basic"), _react.default.createElement(FormItem, _extends({}, formItemLayout, {
      label: "history",
      help: "\u9664\u975E\u77E5\u9053\u4E3A\u4EC0\u4E48\uFF0C\u5426\u5219\u4E0D\u8981\u914D\u7F6E\u4E3A memory"
    }), getFieldDecorator('history', {
      initialValue: config.history || 'browser'
    })(_react.default.createElement(_antd.Select, {
      style: {
        width: 160
      },
      onChange: onChange.bind(null, 'history')
    }, _react.default.createElement(Option, {
      value: "hash"
    }, "hash"), _react.default.createElement(Option, {
      value: "browser"
    }, "browser"), _react.default.createElement(Option, {
      value: "memory"
    }, "memory")))), _react.default.createElement(FormItem, _extends({}, formItemLayout, {
      label: "publicPath",
      help: "\u6307\u5B9A webpack \u7684 publicPath \u914D\u7F6E\uFF0C\u90E8\u7F72\u9759\u6001\u6587\u4EF6\u5230\u975E\u6839\u76EE\u5F55\u65F6\u9700\u8981\u914D\u7F6E"
    }), getFieldDecorator('publicPath', {
      initialValue: config.publicPath || '/'
    })(_react.default.createElement(_antd.Input, {
      style: {
        width: 160
      },
      onBlur: onChange.bind(null, 'publicPath')
    }))), _react.default.createElement(FormItem, _extends({}, formItemLayout, {
      label: "base",
      help: "\u6307\u5B9A\u8DEF\u7531\u7684 base \u8DEF\u5F84\uFF0C\u90E8\u7F72\u5230\u975E\u6839\u76EE\u5F55\u65F6\u9700\u8981\u914D\u7F6E"
    }), getFieldDecorator('base', {
      initialValue: config.base || '/'
    })(_react.default.createElement(_antd.Input, {
      style: {
        width: 160
      },
      onBlur: onChange.bind(null, 'base')
    }))), _react.default.createElement(FormItem, _extends({}, formItemLayout, {
      label: "outputPath",
      help: "\u6307\u5B9A\u6784\u5EFA\u4EA7\u7269\u8F93\u51FA\u8DEF\u5F84"
    }), getFieldDecorator('outputPath', {
      initialValue: config.outputPath || './dist'
    })(_react.default.createElement(_antd.Input, {
      style: {
        width: 160
      },
      onBlur: onChange.bind(null, 'outputPath')
    }))), _react.default.createElement(FormItem, _extends({}, formItemLayout, {
      label: "runtimePublicPath",
      help: "\u542F\u7528\u8FD0\u884C\u65F6 publicPath\uFF0C\u5BF9 JavaScript \u6709\u6548"
    }), getFieldDecorator('runtimePublicPath', {
      valuePropName: 'checked',
      initialValue: config.runtimePublicPath
    })(_react.default.createElement(_antd.Switch, {
      onChange: onChange.bind(null, 'runtimePublicPath')
    }))), _react.default.createElement(FormItem, _extends({}, formItemLayout, {
      label: "hash",
      help: "\u6307\u5B9A\u8F93\u51FA\u6587\u4EF6\u662F\u5426\u5E26\u4E0A hash \u540E\u7F00"
    }), getFieldDecorator('hash', {
      valuePropName: 'checked',
      initialValue: config.hash
    })(_react.default.createElement(_antd.Switch, {
      onChange: onChange.bind(null, 'hash')
    }))), _react.default.createElement(FormItem, _extends({}, formItemLayout, {
      label: "mountElementId",
      help: "\u6307\u5B9A\u9875\u9762\u6839\u8282\u70B9\u5143\u7D20"
    }), getFieldDecorator('mountElementId', {
      initialValue: config.mountElementId || 'root'
    })(_react.default.createElement(_antd.Input, {
      style: {
        width: 160
      },
      onBlur: onChange.bind(null, 'mountElementId')
    }))), _react.default.createElement("h2", null, "Targets"), _react.default.createElement("h2", null, "Plugins"), _react.default.createElement("h2", null, "Webpack"), _react.default.createElement("ul", null, Object.keys(props.config.data).map(function (key) {
      return _react.default.createElement(ConfigItem, {
        key: key,
        name: key,
        data: props.config.data[key]
      });
    })));
  }));
  
  var _default = function _default(api) {
    api.addPanel({
      title: 'Config Manager',
      path: '/config',
      component: ConfigManager,
      models: [_model.default]
    });
  };
  
  exports.default = _default;