'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var renderEmpty = require('../../config-provider/src/renderEmpty.cjs');
var FormItemContext = require('../../form/src/FormItemContext.cjs');
require('../../space/index.cjs');
require('../../config-provider/index.cjs');
var index = require('../style/index.cjs');
var props = require('./props.cjs');
var iconUtil = require('./iconUtil.cjs');
var Option = require('../../../vue-components/vc-select/src/Option.cjs');
var OptGroup = require('../../../vue-components/vc-select/src/OptGroup.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var statusUtils = require('../../../utils/statusUtils.cjs');
var log = require('../../../utils/log.cjs');
var context = require('../../space/src/context.cjs');
var disabledContext = require('../../config-provider/src/context/disabledContext.cjs');
var transition = require('../../../vue-components/transition/src/transition.cjs');
var _class = require('../../../utils/dom/class.cjs');
var omit = require('../../../utils/lang/omit.cjs');
var Select = require('../../../vue-components/vc-select/src/Select.cjs');

const SECRET_COMBOBOX_MODE_DO_NOT_USE = "SECRET_COMBOBOX_MODE_DO_NOT_USE";
var ASelect = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ASelect",
  Option: Option.default,
  OptionGroup: OptGroup.default,
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.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 getMode = vue.computed(() => {
      const {
        mode
      } = props;
      if (mode === "combobox")
        return void 0;
      if (mode === SECRET_COMBOBOX_MODE_DO_NOT_USE)
        return "combobox";
      return mode;
    });
    if (process.env.NODE_ENV !== "production") {
      log.devWarning(!props.dropdownClassName, "Select", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
    }
    const {
      prefixCls,
      direction,
      renderEmpty: renderEmpty$1,
      size: contextSize,
      getPrefixCls,
      getPopupContainer,
      disabled,
      select
    } = useConfigInject.default("select", props);
    const {
      compactSize,
      compactItemClassnames
    } = context.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.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(() => _class.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
    }, 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(() => getMode.value === "multiple" || getMode.value === "tags");
    const mergedShowArrow = vue.computed(() => props.showArrow !== void 0 ? props.showArrow : props.loading || !(isMultiple.value || getMode.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 (getMode.value === "combobox")
        mergedNotFound = null;
      else
        mergedNotFound = (renderEmpty$1 == null ? void 0 : renderEmpty$1("Select")) || vue.createVNode(renderEmpty.DefaultRenderEmpty, {
          "componentName": "Select"
        }, null);
      const {
        suffixIcon,
        itemIcon,
        removeIcon,
        clearIcon
      } = iconUtil.default({
        ...props,
        multiple: isMultiple.value,
        prefixCls: prefixCls.value,
        hasFeedback,
        feedbackIcon,
        showArrow: mergedShowArrow.value
      }, slots);
      const selectProps2 = omit.omit(props, ["prefixCls", "suffixIcon", "itemIcon", "removeIcon", "clearIcon", "size", "bordered", "status"]);
      const rcSelectRtlDropdownClassName = _class.classNames(popupClassName || dropdownClassName, {
        [`${prefixCls.value}-dropdown-${direction.value}`]: direction.value === "rtl"
      }, hashId.value);
      return wrapSSR(vue.createVNode(Select.default, {
        "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": getMode.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 = ASelect;
//# sourceMappingURL=Select.cjs.map
