import _Select from "@alifd/next/es/select";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import React, { PureComponent } from 'react';
var formateOptions = function formateOptions(options) {
  return options.map(function (item) {
    if (item.children) {
      var children = item.children.map(function (child) {
        return {
          label: child.title || child.label || '-',
          value: child.value,
          disabled: child.disabled || false
        };
      });
      return {
        label: item.title || item.label || '-',
        children: children
      };
    } else {
      return {
        label: item.title || item.label || '-',
        value: item.value,
        disabled: item.disabled || false
      };
    }
  });
};
var SelectSetter = /*#__PURE__*/function (_PureComponent) {
  function SelectSetter() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
    _this.state = {
      setterValue: null
    };
    return _this;
  }
  _inheritsLoose(SelectSetter, _PureComponent);
  var _proto = SelectSetter.prototype;
  _proto.render = function render() {
    var _this$props = this.props,
      options = _this$props.options,
      _onChange = _this$props.onChange,
      mode = _this$props.mode,
      value = _this$props.value,
      showSearch = _this$props.showSearch,
      hasClear = _this$props.hasClear;
    return /*#__PURE__*/React.createElement(_Select, {
      autoWidth: false,
      size: "small",
      value: value,
      dataSource: formateOptions(options),
      mode: mode,
      onChange: function onChange(val) {
        _onChange && _onChange(val);
      },
      style: {
        width: '100%'
      },
      showSearch: showSearch,
      hasClear: hasClear
    });
  };
  return SelectSetter;
}(PureComponent);
SelectSetter.defaultProps = {
  placeholder: '请选择',
  options: [{
    label: '-',
    value: ''
  }],
  defaultValue: null,
  onChange: function onChange() {
    return undefined;
  }
};
SelectSetter.displayName = 'SelectSetter';
export { SelectSetter as default };