import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React, { useCallback } from 'react';
import classNames from 'classnames';
import getIcons from './utils/iconUtil';
import { ConfigContext } from '../config-provider/context';
import { RcSelect } from '../components';
import omit from '../components/rc-util/omit';
import { scrollInfiniteFun } from './scrollInfinite';
var SelectRc = RcSelect.default;
var Option = RcSelect.Option,
    OptGroup = RcSelect.OptGroup;
/* eslint-disable no-shadow */

var wrapSize;

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

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

  var resultRef = ref || React.useRef(null);

  var className = props.className,
      value = props.value,
      prefixCls = props.prefixCls,
      customSize = props.size,
      wSize = props.wSize,
      removeIcon = props.removeIcon,
      mode = props.mode,
      outerShowSearch = props.showSearch,
      prefix = props.prefix,
      suffix = props.suffix,
      notFoundContent = props.notFoundContent,
      dropdownRender = props.dropdownRender,
      bordered = props.bordered,
      dropdownMatchSelectWidth = props.dropdownMatchSelectWidth,
      selectGetPopupContainer = props.getPopupContainer,
      onPopupScroll = props.onPopupScroll,
      scrollInfinite = props.scrollInfinite,
      infiniteHasMore = props.infiniteHasMore,
      restProps = _objectWithoutProperties(props, ["className", "value", "prefixCls", "size", "wSize", "removeIcon", "mode", "showSearch", "prefix", "suffix", "notFoundContent", "dropdownRender", "bordered", "dropdownMatchSelectWidth", "getPopupContainer", "onPopupScroll", "scrollInfinite", "infiniteHasMore"]);

  var endSize = customSize || size;
  var selectCls = getPrefixClassName('select', prefixCls);
  var isMultiple = mode === 'multiple' || mode === 'tags';
  var showSearch = false;

  if (isMultiple) {
    showSearch = isMultiple;
  }

  if (typeof outerShowSearch !== 'undefined') {
    showSearch = outerShowSearch;
  }

  var extendsIconProps = Object.assign({}, props, {
    multiple: isMultiple,
    preCls: selectCls
  });
  var iconMap = getIcons(extendsIconProps);
  var sizeSuffixCls = wrapSize[endSize];
  var endCls = classNames(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 = _objectSpread({
    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 = omit(comProps, ['suffixIcon']); // fetch options by scroll infinite

  var handleScroll = useCallback(scrollInfiniteFun(infiniteHasMore, scrollInfinite, onPopupScroll), [infiniteHasMore, scrollInfinite, onPopupScroll]);
  return /*#__PURE__*/React.createElement(SelectRc, Object.assign({
    onClick: handelClick,
    prefixCls: selectCls,
    onPopupScroll: handleScroll,
    mode: mode,
    showSearch: 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,
  infiniteHasMore: true
};
export { Option, OptGroup };
export default Select;