"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.OptGroup = exports.Option = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _iconUtil = _interopRequireDefault(require("./utils/iconUtil"));

var _context = require("../config-provider/context");

var _components = require("../components");

var _omit = _interopRequireDefault(require("../components/rc-util/omit"));

var SelectRc = _components.RcSelect.default;
var Option = _components.RcSelect.Option,
    OptGroup = _components.RcSelect.OptGroup;
/* eslint-disable no-shadow */

exports.OptGroup = OptGroup;
exports.Option = Option;
var wrapSize;

(function (wrapSize) {
  wrapSize["small"] = "sm";
  wrapSize["medium"] = "";
  wrapSize["large"] = "lg";
})(wrapSize || (wrapSize = {}));

var Select = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
  var _React$useContext = _react.default.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName,
      getPopupContainer = _React$useContext.getPopupContainer,
      size = _React$useContext.size;

  var resultRef = ref || _react.default.useRef(null);

  var className = props.className,
      value = props.value,
      prefixCls = props.prefixCls,
      customSize = props.size,
      wSize = props.wSize,
      removeIcon = props.removeIcon,
      mode = props.mode,
      showSearch = props.showSearch,
      prefix = props.prefix,
      suffix = props.suffix,
      notFoundContent = props.notFoundContent,
      dropdownRender = props.dropdownRender,
      bordered = props.bordered,
      dropdownMatchSelectWidth = props.dropdownMatchSelectWidth,
      selectGetPopupContainer = props.getPopupContainer,
      restProps = (0, _objectWithoutProperties2.default)(props, ["className", "value", "prefixCls", "size", "wSize", "removeIcon", "mode", "showSearch", "prefix", "suffix", "notFoundContent", "dropdownRender", "bordered", "dropdownMatchSelectWidth", "getPopupContainer"]);
  var endSize = customSize || size;
  var selectCls = getPrefixClassName('select', prefixCls);
  var isMultiple = mode === 'multiple' || mode === 'tags';
  var extendsIconProps = Object.assign({}, props, {
    multiple: isMultiple,
    preCls: selectCls
  });
  var iconMap = (0, _iconUtil.default)(extendsIconProps);
  var sizeSuffixCls = wrapSize[endSize];
  var endCls = (0, _classnames.default)(sizeSuffixCls && "".concat(selectCls, "-").concat(sizeSuffixCls), !bordered && "".concat(selectCls, "-borderless"), prefix && "".concat(selectCls, "-prefix"), suffix && "".concat(selectCls, "-suffix"), wSize && "".concat(selectCls, "-width-").concat(wSize), className); // issue about select dropdown cannot show in radio ---weimob

  var handelClick = function handelClick(e) {
    e.preventDefault();
    e.stopPropagation();
  };

  var comProps = (0, _objectSpread2.default)({
    value: value,
    ref: resultRef,
    inputIcon: iconMap.suffixIcon,
    clearIcon: iconMap.clearIcon,
    menuItemSelectedIcon: iconMap.itemIcon,
    removeIcon: iconMap.removeIcon,
    notFoundContent: notFoundContent,
    dropdownRender: dropdownRender,
    prefix: prefix,
    suffix: suffix,
    className: endCls
  }, restProps);
  var omitComProps = (0, _omit.default)(comProps, ['suffixIcon']);
  return /*#__PURE__*/_react.default.createElement(SelectRc, Object.assign({
    onClick: handelClick,
    prefixCls: selectCls,
    mode: mode,
    showSearch: isMultiple || showSearch,
    dropdownMatchSelectWidth: dropdownMatchSelectWidth,
    getPopupContainer: selectGetPopupContainer || getPopupContainer
  }, omitComProps));
});

Select.Option = Option;
Select.OptGroup = OptGroup;
Select.displayName = 'Select';
Select.defaultProps = {
  allowClear: false,
  // autoFocus: false,
  showSearch: false,
  // size: 'medium',
  bordered: true,
  filterOption: true,
  loading: false,
  virtual: true,
  // listHeight: 256,
  dropdownMatchSelectWidth: true
};
var _default = Select;
exports.default = _default;