import _Box from "@alifd/next/es/box";
import _Radio from "@alifd/next/es/radio";
import _Checkbox from "@alifd/next/es/checkbox";
import _Select from "@alifd/next/es/select";
import _extends from "@babel/runtime/helpers/extends";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import React from 'react';
import { bizCssPrefix } from "../../variables";
import "./index.scss";
var CommonOption = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(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 _extends({}, 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.createElement(_Select, {
          hasClear: true,
          defaultValue: defalueVal,
          value: _this.state.selectData,
          placeholder: placeholder,
          disabled: isEdit,
          mode: mode,
          dataSource: childList
        });
      } else {
        if (mode === 'multiple') {
          return /*#__PURE__*/React.createElement(_Checkbox.Group, {
            defaultValue: defalueVal,
            value: _this.state.selectData,
            disabled: isEdit,
            dataSource: childList
          });
        } else {
          return /*#__PURE__*/React.createElement(_Radio.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.createElement(_Box, {
      direction: "row",
      align: "center",
      className: bizCssPrefix + '-option'
    }, this.renderColumn());
  };
  return CommonOption;
}(React.Component);
CommonOption.displyName = 'CommonOption';
export default CommonOption;