'use strict';

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

var vue = require('vue');
require('../vc-tree-select/index.js');
var devWarning = require('../vc-util/devWarning.js');
var iconUtil = require('../select/utils/iconUtil.js');
var iconUtil$1 = require('../tree/utils/iconUtil.js');
var warning = require('../vc-util/warning.js');
var FormItemContext = require('../form/FormItemContext.js');
var index$2 = require('../select/style/index.js');
var Compact = require('../space/Compact.js');
var classNames = require('../_util/classNames.js');
var initDefaultProps = require('../_util/props-util/initDefaultProps.js');
var omit = require('../_util/omit.js');
var index$1 = require('../_util/vue-types/index.js');
require('../hooks/index.js');
var index$4 = require('../_util/props-util/index.js');
var transition = require('../_util/components/transition.js');
var statusUtils = require('../_util/statusUtils.js');
var type = require('../_util/type.js');
var DisabledContext = require('../config-provider/DisabledContext.js');
var index$3 = require('./style/index.js');
var TreeSelect$1 = require('../vc-tree-select/TreeSelect.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var TreeNode = require('../vc-tree-select/TreeNode.js');
var strategyUtil = require('../vc-tree-select/utils/strategyUtil.js');

const getTransitionName = (rootPrefixCls, motion, transitionName) => {
  if (transitionName !== void 0)
    return transitionName;
  return `${rootPrefixCls}-${motion}`;
};
function treeSelectProps() {
  return {
    ...omit.default(TreeSelect$1.treeSelectProps(), ["showTreeIcon", "treeMotion", "inputIcon", "getInputElement", "treeLine", "customSlots"]),
    "suffixIcon": index$1.default.any,
    "size": type.stringType(),
    "bordered": type.booleanType(),
    "treeLine": type.someType([Boolean, Object]),
    "replaceFields": type.objectType(),
    "placement": type.stringType(),
    "status": type.stringType(),
    "popupClassName": String,
    /** @deprecated Please use `popupClassName` instead */
    "dropdownClassName": String,
    "onUpdate:value": type.functionType(),
    "onUpdate:treeExpandedKeys": type.functionType(),
    "onUpdate:searchValue": type.functionType()
  };
}
const TreeSelect = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATreeSelect",
  inheritAttrs: false,
  props: initDefaultProps.default(treeSelectProps(), {
    choiceTransitionName: "",
    listHeight: 256,
    treeIcon: false,
    listItemHeight: 26,
    bordered: true
  }),
  slots: Object,
  setup(props, {
    attrs,
    slots,
    expose,
    emit
  }) {
    warning.warning(!(props.treeData === void 0 && slots.default), "`children` of TreeSelect is deprecated. Please use `treeData` instead.");
    devWarning.default(props.multiple !== false || !props.treeCheckable, "TreeSelect", "`multiple` will always be `true` when `treeCheckable` is true");
    devWarning.default(props.replaceFields === void 0, "TreeSelect", "`replaceFields` is deprecated, please use fieldNames instead");
    devWarning.default(!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
    } = 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 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$2.default(prefixCls);
    const [wrapTreeSelectSSR] = index$3.default(treeSelectPrefixCls, treePrefixCls);
    const mergedDropdownClassName = vue.computed(() => classNames.default(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.default(props, ["suffixIcon", "itemIcon", "removeIcon", "clearIcon", "switcherIcon", "bordered", "status", "onSearch", "onUpdate:value", "onUpdate:treeExpandedKeys", "onUpdate:searchValue"]);
      const mergedClassName = classNames.default(!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 = index$4.flattenChildren(slots.default());
      return wrapSelectSSR(wrapTreeSelectSSR(vue.createVNode(TreeSelect$1.default, vue.mergeProps(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) => 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)
      })));
    };
  }
});
const TreeSelectNode = TreeNode.default;
var index = Object.assign(TreeSelect, {
  TreeNode: TreeNode.default,
  SHOW_ALL: strategyUtil.SHOW_ALL,
  SHOW_PARENT: strategyUtil.SHOW_PARENT,
  SHOW_CHILD: strategyUtil.SHOW_CHILD,
  install: (app) => {
    app.component(TreeSelect.name, TreeSelect);
    app.component(TreeSelectNode.displayName, TreeSelectNode);
    return app;
  }
});

exports.TreeSelectNode = TreeSelectNode;
exports.default = index;
exports.treeSelectProps = treeSelectProps;
//# sourceMappingURL=index.js.map
