import { defineComponent, ref, computed, createVNode, mergeProps } from 'vue';
import classNames from '../_util/classNames.mjs';
import '../vc-select/index.mjs';
import PropTypes from '../_util/vue-types/index.mjs';
import '../hooks/index.mjs';
import { DefaultRenderEmpty } from '../config-provider/renderEmpty.mjs';
import omit from '../_util/omit.mjs';
import { useInjectFormItemContext, FormItemInputContext } from '../form/FormItemContext.mjs';
import { getTransitionName, getTransitionDirection } from '../_util/components/transition.mjs';
import '../_util/props-util/index.mjs';
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils.mjs';
import { someType, stringType, booleanType, functionType } from '../_util/type.mjs';
import { useCompactItemContext } from '../space/Compact.mjs';
import { useInjectDisabled } from '../config-provider/DisabledContext.mjs';
import devWarning from '../vc-util/devWarning.mjs';
import getIcons from './utils/iconUtil.mjs';
import useSelectStyle from './style/index.mjs';
import Select$1, { selectProps as selectProps$1 } from '../vc-select/Select.mjs';
import Option from '../vc-select/Option.mjs';
import OptGroup from '../vc-select/OptGroup.mjs';
import initDefaultProps from '../_util/props-util/initDefaultProps.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';

const SECRET_COMBOBOX_MODE_DO_NOT_USE = "SECRET_COMBOBOX_MODE_DO_NOT_USE";
const selectProps = () => ({
  ...omit(selectProps$1(), ["inputIcon", "mode", "getInputElement", "getRawInputElement", "backfill"]),
  "value": someType([Array, Object, String, Number]),
  "defaultValue": someType([Array, Object, String, Number]),
  "notFoundContent": PropTypes.any,
  "suffixIcon": PropTypes.any,
  "itemIcon": PropTypes.any,
  "size": stringType(),
  "mode": stringType(),
  "bordered": booleanType(true),
  "transitionName": String,
  "choiceTransitionName": stringType(""),
  "popupClassName": String,
  /** @deprecated Please use `popupClassName` instead */
  "dropdownClassName": String,
  "placement": stringType(),
  "status": stringType(),
  "onUpdate:value": functionType()
});
var Select = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ASelect",
  Option,
  OptGroup,
  inheritAttrs: false,
  props: initDefaultProps(selectProps(), {
    listHeight: 256,
    listItemHeight: 24
  }),
  SECRET_COMBOBOX_MODE_DO_NOT_USE,
  slots: Object,
  setup(props, {
    attrs,
    emit,
    slots,
    expose
  }) {
    const selectRef = ref();
    const formItemContext = useInjectFormItemContext();
    const formItemInputContext = FormItemInputContext.useInject();
    const mergedStatus = computed(() => 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 = 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(!props.dropdownClassName, "Select", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
    }
    const {
      prefixCls,
      customizePrefixCls,
      direction,
      renderEmpty,
      size: contextSize,
      getPrefixCls,
      getPopupContainer,
      disabled,
      select
    } = useConfigInject("select", props);
    const {
      compactSize,
      compactItemClassnames
    } = useCompactItemContext(prefixCls, direction);
    const mergedSize = computed(() => compactSize.value || contextSize.value);
    const contextDisabled = useInjectDisabled();
    const mergedDisabled = computed(() => {
      var _a;
      return (_a = disabled.value) != null ? _a : contextDisabled.value;
    });
    const [wrapSSR, hashId] = useSelectStyle(prefixCls);
    const rootPrefixCls = computed(() => getPrefixCls());
    const placement = computed(() => {
      if (props.placement !== void 0)
        return props.placement;
      return direction.value === "rtl" ? "bottomRight" : "bottomLeft";
    });
    const transitionName = computed(() => getTransitionName(rootPrefixCls.value, getTransitionDirection(placement.value), props.transitionName));
    const mergedClassName = computed(() => classNames({
      [`${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
    }, 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 = computed(() => mode.value === "multiple" || mode.value === "tags");
    const mergedShowArrow = 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 == null ? void 0 : renderEmpty("Select")) || createVNode(DefaultRenderEmpty, {
          "componentName": "Select",
          "prefixCls": customizePrefixCls.value
        }, null);
      const {
        suffixIcon,
        itemIcon,
        removeIcon,
        clearIcon
      } = getIcons({
        ...props,
        multiple: isMultiple.value,
        prefixCls: prefixCls.value,
        hasFeedback,
        feedbackIcon,
        showArrow: mergedShowArrow.value
      }, slots);
      const selectProps2 = omit(props, ["prefixCls", "suffixIcon", "itemIcon", "removeIcon", "clearIcon", "onChange", "size", "bordered", "status"]);
      const rcSelectRtlDropdownClassName = classNames(popupClassName || dropdownClassName, {
        [`${prefixCls.value}-dropdown-${direction.value}`]: direction.value === "rtl"
      }, hashId.value);
      return wrapSSR(createVNode(Select$1, 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
      }));
    };
  }
});

export { Select as default, selectProps };
//# sourceMappingURL=select.mjs.map
