"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _box = _interopRequireDefault(require("@alifd/next/lib/box"));
var _radio = _interopRequireDefault(require("@alifd/next/lib/radio"));
var _checkbox = _interopRequireDefault(require("@alifd/next/lib/checkbox"));
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireDefault(require("react"));
var _variables = require("../../variables");
require("./index.scss");
var CommonOption = /*#__PURE__*/function (_React$Component) {
  (0, _inheritsLoose2["default"])(CommonOption, _React$Component);
  function CommonOption(props) {
    var _this;
    _this = _React$Component.call(this, props) || this;
    _this.renderColumn = function () {
      var _this$props = _this.props,
        isMultiple = _this$props.isMultiple,
        isDeployment = _this$props.isDeployment,
        placeholder = _this$props.placeholder,
        isEdit = _this$props.isEdit,
        enumList = _this$props.enumList,
        defaultValue = _this$props.defaultValue;
      var childList = enumList ? enumList === null || enumList === void 0 ? void 0 : enumList.childList.map(function (item) {
        return (0, _extends2["default"])({}, item, {
          label: item.dictValue,
          value: item.id
        });
      }) : [{
        label: '选项一',
        value: '111'
      }, {
        label: '选项二',
        value: '222'
      }, {
        label: '选项三',
        value: '333'
      }];
      var defalueVal = childList === null || childList === void 0 ? void 0 : childList.filter(function (item) {
        return item.dictKey === defaultValue;
      });
      var mode = isMultiple ? 'multiple' : 'single';
      if (isDeployment === 'primary') {
        return /*#__PURE__*/_react["default"].createElement(_select["default"], {
          hasClear: true,
          defaultValue: defalueVal,
          value: _this.state.selectData,
          placeholder: placeholder,
          disabled: isEdit,
          mode: mode,
          dataSource: childList
        });
      } else {
        if (mode === 'multiple') {
          return /*#__PURE__*/_react["default"].createElement(_checkbox["default"].Group, {
            defaultValue: defalueVal,
            value: _this.state.selectData,
            disabled: isEdit,
            dataSource: childList
          });
        } else {
          return /*#__PURE__*/_react["default"].createElement(_radio["default"].Group, {
            defaultValue: defalueVal,
            value: _this.state.selectData,
            disabled: isEdit,
            dataSource: childList
          });
        }
      }
    };
    _this.state = {
      childList: [],
      selectData: []
    };
    return _this;
  }
  var _proto = CommonOption.prototype;
  _proto.render = function render() {
    return /*#__PURE__*/_react["default"].createElement(_box["default"], {
      direction: "row",
      align: "center",
      className: _variables.bizCssPrefix + '-option'
    }, this.renderColumn());
  };
  return CommonOption;
}(_react["default"].Component);
CommonOption.displyName = 'CommonOption';
var _default = CommonOption;
exports["default"] = _default;