'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var iconUtil = require('../../select/src/iconUtil.cjs');
var iconUtil$1 = require('../../tree/src/utils/iconUtil.cjs');
var FormItemContext = require('../../form/src/FormItemContext.cjs');
var index = require('../../select/style/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
require('../../config-provider/index.cjs');
var context = require('../../space/src/context.cjs');
var index$1 = require('../style/index.cjs');
var props = require('./props.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var log = require('../../../utils/log.cjs');
var statusUtils = require('../../../utils/statusUtils.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 props$1 = require('../../../utils/vue/props.cjs');
var TreeSelect = require('../../../vue-components/vc-tree-select/src/TreeSelect.cjs');

function getTransitionName(rootPrefixCls, motion, transitionName) {
  if (transitionName !== void 0)
    return transitionName;
  return `${rootPrefixCls}-${motion}`;
}
var ATreeSelect = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATreeSelect",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.treeSelectProps(), {
    choiceTransitionName: "",
    listHeight: 256,
    treeIcon: false,
    listItemHeight: 26,
    bordered: true
  }),
  slots: Object,
  setup(props, {
    attrs,
    slots,
    expose,
    emit
  }) {
    log.warning(!(props.treeData === void 0 && slots.default), "`children` of TreeSelect is deprecated. Please use `treeData` instead.");
    log.devWarning(props.multiple !== false || !props.treeCheckable, "TreeSelect", "`multiple` will always be `true` when `treeCheckable` is true");
    log.devWarning(props.replaceFields === void 0, "TreeSelect", "`replaceFields` is deprecated, please use fieldNames instead");
    log.devWarning(!props.dropdownClassName, "TreeSelect", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
    const mergedStatus = vue.computed(() => statusUtils.getMergedStatus(formItemInputContext.status, props.status));
    const {
      prefixCls,
      renderEmpty,
      direction,
      virtual,
      dropdownMatchSelectWidth,
      size: contextSize,
      getPopupContainer,
      getPrefixCls,
      disabled
    } = 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 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(() => getTransitionName(rootPrefixCls.value, transition.getTransitionDirection(placement.value), props.transitionName));
    const choiceTransitionName = vue.computed(() => getTransitionName(rootPrefixCls.value, "", props.choiceTransitionName));
    const treePrefixCls = vue.computed(() => getPrefixCls("select-tree", props.prefixCls));
    const treeSelectPrefixCls = vue.computed(() => getPrefixCls("tree-select", props.prefixCls));
    const [wrapSelectSSR, hashId] = index.default(prefixCls);
    const [wrapTreeSelectSSR] = index$1.default(treeSelectPrefixCls, treePrefixCls);
    const mergedDropdownClassName = vue.computed(() => _class.classNames(props.popupClassName || props.dropdownClassName, `${treeSelectPrefixCls.value}-dropdown`, {
      [`${treeSelectPrefixCls.value}-dropdown-rtl`]: direction.value === "rtl"
    }, hashId.value));
    const isMultiple = vue.computed(() => !!(props.treeCheckable || props.multiple));
    const mergedShowArrow = vue.computed(() => props.showArrow !== void 0 ? props.showArrow : props.loading || !isMultiple.value);
    const treeSelectRef = vue.ref();
    expose({
      focus() {
        var _a, _b;
        (_b = (_a = treeSelectRef.value).focus) == null ? void 0 : _b.call(_a);
      },
      blur() {
        var _a, _b;
        (_b = (_a = treeSelectRef.value).blur) == null ? void 0 : _b.call(_a);
      }
    });
    const handleChange = (...args) => {
      emit("update:value", args[0]);
      emit("change", ...args);
      formItemContext.onFieldChange();
    };
    const handleTreeExpand = (keys) => {
      emit("update:treeExpandedKeys", keys);
      emit("treeExpand", keys);
    };
    const handleSearch = (value) => {
      emit("update:searchValue", value);
      emit("search", value);
    };
    const handleBlur = (e) => {
      emit("blur", e);
      formItemContext.onFieldBlur();
    };
    return () => {
      var _a, _b;
      const {
        notFoundContent = (_a = slots.notFoundContent) == null ? void 0 : _a.call(slots),
        prefixCls: customizePrefixCls,
        bordered,
        listHeight,
        listItemHeight,
        multiple,
        treeIcon,
        treeLine,
        showArrow,
        switcherIcon = (_b = slots.switcherIcon) == null ? void 0 : _b.call(slots),
        fieldNames = props.replaceFields,
        id = formItemContext.id.value
      } = props;
      const {
        isFormItemInput,
        hasFeedback,
        feedbackIcon
      } = formItemInputContext;
      const {
        suffixIcon,
        removeIcon,
        clearIcon
      } = iconUtil.default({
        ...props,
        multiple: isMultiple.value,
        showArrow: mergedShowArrow.value,
        hasFeedback,
        feedbackIcon,
        prefixCls: prefixCls.value
      }, slots);
      let mergedNotFound;
      if (notFoundContent !== void 0)
        mergedNotFound = notFoundContent;
      else
        mergedNotFound = renderEmpty("Select");
      const selectProps = omit.omit(props, ["suffixIcon", "itemIcon", "removeIcon", "clearIcon", "switcherIcon", "bordered", "status", "onSearch", "onUpdate:value", "onUpdate:treeExpandedKeys", "onUpdate:searchValue"]);
      const mergedClassName = _class.classNames(!customizePrefixCls && treeSelectPrefixCls.value, {
        [`${prefixCls.value}-lg`]: mergedSize.value === "large",
        [`${prefixCls.value}-sm`]: mergedSize.value === "small",
        [`${prefixCls.value}-rtl`]: direction.value === "rtl",
        [`${prefixCls.value}-borderless`]: !bordered,
        [`${prefixCls.value}-in-form-item`]: isFormItemInput
      }, statusUtils.getStatusClassNames(prefixCls.value, mergedStatus.value, hasFeedback), compactItemClassnames.value, attrs.class, hashId.value);
      const otherProps = {};
      if (props.treeData === void 0 && slots.default)
        otherProps.children = props$1.flattenChildren(slots.default());
      return wrapSelectSSR(wrapTreeSelectSSR(vue.createVNode(TreeSelect.default, {
        ...attrs,
        ...selectProps,
        "disabled": mergedDisabled.value,
        "virtual": virtual.value,
        "dropdownMatchSelectWidth": dropdownMatchSelectWidth.value,
        "id": id,
        "fieldNames": fieldNames,
        "ref": treeSelectRef,
        "prefixCls": prefixCls.value,
        "class": mergedClassName,
        "listHeight": listHeight,
        "listItemHeight": listItemHeight,
        "treeLine": !!treeLine,
        "inputIcon": suffixIcon,
        "multiple": multiple,
        "removeIcon": removeIcon,
        "clearIcon": clearIcon,
        "switcherIcon": (nodeProps) => {
          return iconUtil$1.default(treePrefixCls.value, switcherIcon, nodeProps, slots.leafIcon, treeLine);
        },
        "showTreeIcon": treeIcon,
        "notFoundContent": mergedNotFound,
        "getPopupContainer": getPopupContainer == null ? void 0 : getPopupContainer.value,
        "treeMotion": null,
        "dropdownClassName": mergedDropdownClassName.value,
        "choiceTransitionName": choiceTransitionName.value,
        "onChange": handleChange,
        "onBlur": handleBlur,
        "onSearch": handleSearch,
        "onTreeExpand": handleTreeExpand,
        ...otherProps,
        "transitionName": transitionName.value,
        "customSlots": {
          ...slots,
          treeCheckable: () => vue.createVNode("span", {
            "class": `${prefixCls.value}-tree-checkbox-inner`
          }, null)
        },
        "maxTagPlaceholder": props.maxTagPlaceholder || slots.maxTagPlaceholder,
        "placement": placement.value,
        "showArrow": hasFeedback || showArrow
      }, {
        ...slots,
        treeCheckable: () => vue.createVNode("span", {
          "class": `${prefixCls.value}-tree-checkbox-inner`
        }, null)
      })));
    };
  }
});

exports.default = ATreeSelect;
//# sourceMappingURL=TreeSelect.cjs.map
