'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var classNames = require('../_util/classNames.js');
require('../vc-select/index.js');
var index = require('../_util/vue-types/index.js');
require('../hooks/index.js');
var renderEmpty = require('../config-provider/renderEmpty.js');
var omit = require('../_util/omit.js');
var FormItemContext = require('../form/FormItemContext.js');
var transition = require('../_util/components/transition.js');
require('../_util/props-util/index.js');
var statusUtils = require('../_util/statusUtils.js');
var type = require('../_util/type.js');
var Compact = require('../space/Compact.js');
var DisabledContext = require('../config-provider/DisabledContext.js');
var devWarning = require('../vc-util/devWarning.js');
var iconUtil = require('./utils/iconUtil.js');
var index$1 = require('./style/index.js');
var Select$1 = require('../vc-select/Select.js');
var Option = require('../vc-select/Option.js');
var OptGroup = require('../vc-select/OptGroup.js');
var initDefaultProps = require('../_util/props-util/initDefaultProps.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

const SECRET_COMBOBOX_MODE_DO_NOT_USE = "SECRET_COMBOBOX_MODE_DO_NOT_USE";
const selectProps = () => ({
  ...omit.default(Select$1.selectProps(), ["inputIcon", "mode", "getInputElement", "getRawInputElement", "backfill"]),
  "value": type.someType([Array, Object, String, Number]),
  "defaultValue": type.someType([Array, Object, String, Number]),
  "notFoundContent": index.default.any,
  "suffixIcon": index.default.any,
  "itemIcon": index.default.any,
  "size": type.stringType(),
  "mode": type.stringType(),
  "bordered": type.booleanType(true),
  "transitionName": String,
  "choiceTransitionName": type.stringType(""),
  "popupClassName": String,
  /** @deprecated Please use `popupClassName` instead */
  "dropdownClassName": String,
  "placement": type.stringType(),
  "status": type.stringType(),
  "onUpdate:value": type.functionType()
});
var Select = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ASelect",
  Option: Option.default,
  OptGroup: OptGroup.default,
  inheritAttrs: false,
  props: initDefaultProps.default(selectProps(), {
    listHeight: 256,
    listItemHeight: 24
  }),
  SECRET_COMBOBOX_MODE_DO_NOT_USE,
  slots: Object,
  setup(props, {
    attrs,
    emit,
    slots,
    expose
  }) {
    const selectRef = vue.ref();
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
    const mergedStatus = vue.computed(() => statusUtils.getMergedStatus(formItemInputContext.status, props.status));
    const focus = () => {
      var _a;
      (_a = selectRef.value) == null ? void 0 : _a.focus();
    };
    const blur = () => {
      var _a;
      (_a = selectRef.value) == null ? void 0 : _a.blur();
    };
    const scrollTo = (arg) => {
      var _a;
      (_a = selectRef.value) == null ? void 0 : _a.scrollTo(arg);
    };
    const mode = vue.computed(() => {
      const {
        mode: mode2
      } = props;
      if (mode2 === "combobox")
        return void 0;
      if (mode2 === SECRET_COMBOBOX_MODE_DO_NOT_USE)
        return "combobox";
      return mode2;
    });
    if (process.env.NODE_ENV !== "production") {
      devWarning.default(!props.dropdownClassName, "Select", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
    }
    const {
      prefixCls,
      customizePrefixCls,
      direction,
      renderEmpty: renderEmpty$1,
      size: contextSize,
      getPrefixCls,
      getPopupContainer,
      disabled,
      select
    } = useConfigInject.default("select", props);
    const {
      compactSize,
      compactItemClassnames
    } = Compact.useCompactItemContext(prefixCls, direction);
    const mergedSize = vue.computed(() => compactSize.value || contextSize.value);
    const contextDisabled = DisabledContext.useInjectDisabled();
    const mergedDisabled = vue.computed(() => {
      var _a;
      return (_a = disabled.value) != null ? _a : contextDisabled.value;
    });
    const [wrapSSR, hashId] = index$1.default(prefixCls);
    const rootPrefixCls = vue.computed(() => getPrefixCls());
    const placement = vue.computed(() => {
      if (props.placement !== void 0)
        return props.placement;
      return direction.value === "rtl" ? "bottomRight" : "bottomLeft";
    });
    const transitionName = vue.computed(() => transition.getTransitionName(rootPrefixCls.value, transition.getTransitionDirection(placement.value), props.transitionName));
    const mergedClassName = vue.computed(() => classNames.default({
      [`${prefixCls.value}-lg`]: mergedSize.value === "large",
      [`${prefixCls.value}-sm`]: mergedSize.value === "small",
      [`${prefixCls.value}-rtl`]: direction.value === "rtl",
      [`${prefixCls.value}-borderless`]: !props.bordered,
      [`${prefixCls.value}-in-form-item`]: formItemInputContext.isFormItemInput
    }, statusUtils.getStatusClassNames(prefixCls.value, mergedStatus.value, formItemInputContext.hasFeedback), compactItemClassnames.value, hashId.value));
    const triggerChange = (...args) => {
      emit("update:value", args[0]);
      emit("change", ...args);
      formItemContext.onFieldChange();
    };
    const handleBlur = (e) => {
      emit("blur", e);
      formItemContext.onFieldBlur();
    };
    expose({
      blur,
      focus,
      scrollTo
    });
    const isMultiple = vue.computed(() => mode.value === "multiple" || mode.value === "tags");
    const mergedShowArrow = vue.computed(() => props.showArrow !== void 0 ? props.showArrow : props.loading || !(isMultiple.value || mode.value === "combobox"));
    return () => {
      var _a, _b, _c, _d;
      const {
        notFoundContent,
        listHeight = 256,
        listItemHeight = 24,
        popupClassName,
        dropdownClassName,
        virtual,
        dropdownMatchSelectWidth,
        id = formItemContext.id.value,
        placeholder = (_a = slots.placeholder) == null ? void 0 : _a.call(slots),
        showArrow
      } = props;
      const {
        hasFeedback,
        feedbackIcon
      } = formItemInputContext;
      let mergedNotFound;
      if (notFoundContent !== void 0)
        mergedNotFound = notFoundContent;
      else if (slots.notFoundContent)
        mergedNotFound = slots.notFoundContent();
      else if (mode.value === "combobox")
        mergedNotFound = null;
      else
        mergedNotFound = (renderEmpty$1 == null ? void 0 : renderEmpty$1("Select")) || vue.createVNode(renderEmpty.DefaultRenderEmpty, {
          "componentName": "Select",
          "prefixCls": customizePrefixCls.value
        }, null);
      const {
        suffixIcon,
        itemIcon,
        removeIcon,
        clearIcon
      } = iconUtil.default({
        ...props,
        multiple: isMultiple.value,
        prefixCls: prefixCls.value,
        hasFeedback,
        feedbackIcon,
        showArrow: mergedShowArrow.value
      }, slots);
      const selectProps2 = omit.default(props, ["prefixCls", "suffixIcon", "itemIcon", "removeIcon", "clearIcon", "onChange", "size", "bordered", "status"]);
      const rcSelectRtlDropdownClassName = classNames.default(popupClassName || dropdownClassName, {
        [`${prefixCls.value}-dropdown-${direction.value}`]: direction.value === "rtl"
      }, hashId.value);
      return wrapSSR(vue.createVNode(Select$1.default, vue.mergeProps({
        "ref": selectRef,
        "virtual": virtual,
        "dropdownMatchSelectWidth": dropdownMatchSelectWidth
      }, selectProps2, attrs, {
        "showSearch": (_c = props.showSearch) != null ? _c : (_b = select == null ? void 0 : select.value) == null ? void 0 : _b.showSearch,
        "placeholder": placeholder,
        "listHeight": listHeight,
        "listItemHeight": listItemHeight,
        "mode": mode.value,
        "prefixCls": prefixCls.value,
        "direction": direction.value,
        "inputIcon": suffixIcon,
        "menuItemSelectedIcon": itemIcon,
        "removeIcon": removeIcon,
        "clearIcon": clearIcon,
        "notFoundContent": mergedNotFound,
        "class": [mergedClassName.value, attrs.class],
        "getPopupContainer": getPopupContainer == null ? void 0 : getPopupContainer.value,
        "dropdownClassName": rcSelectRtlDropdownClassName,
        "onChange": triggerChange,
        "onBlur": handleBlur,
        "id": id,
        "dropdownRender": selectProps2.dropdownRender || slots.dropdownRender,
        "transitionName": transitionName.value,
        "children": (_d = slots.default) == null ? void 0 : _d.call(slots),
        "tagRender": props.tagRender || slots.tagRender,
        "optionLabelRender": slots.optionLabel,
        "maxTagPlaceholder": props.maxTagPlaceholder || slots.maxTagPlaceholder,
        "showArrow": hasFeedback || showArrow,
        "disabled": mergedDisabled.value
      }), {
        option: slots.option
      }));
    };
  }
});

exports.default = Select;
exports.selectProps = selectProps;
//# sourceMappingURL=select.js.map
