import { defineComponent, ref, computed, watchEffect, createVNode, mergeProps } from 'vue';
import '../vc-tree/index.mjs';
import { treeProps as treeProps$1 } from '../vc-tree/props.mjs';
import devWarning from '../vc-util/devWarning.mjs';
import { warning } from '../vc-util/warning.mjs';
import { someType, booleanType, arrayType, functionType, objectType } from '../_util/type.mjs';
import omit from '../_util/omit.mjs';
import '../hooks/index.mjs';
import initDefaultProps from '../_util/props-util/initDefaultProps.mjs';
import { filterEmpty } from '../_util/props-util/index.mjs';
import PropTypes from '../_util/vue-types/index.mjs';
import classNames from '../_util/classNames.mjs';
import renderSwitcherIcon from './utils/iconUtil.mjs';
import dropIndicatorRender from './utils/dropIndicator.mjs';
import useStyle from './style/index.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';
import Tree$1 from '../vc-tree/Tree.mjs';

const treeProps = () => {
  const baseTreeProps = treeProps$1();
  return {
    ...baseTreeProps,
    "showLine": someType([Boolean, Object]),
    /** 是否支持多选 */
    "multiple": booleanType(),
    /** 是否自动展开父节点 */
    "autoExpandParent": booleanType(),
    /** checkable状态下节点选择完全受控（父子节点选中状态不再关联） */
    "checkStrictly": booleanType(),
    /** 是否支持选中 */
    "checkable": booleanType(),
    /** 是否禁用树 */
    "disabled": booleanType(),
    /** 默认展开所有树节点 */
    "defaultExpandAll": booleanType(),
    /** 默认展开对应树节点 */
    "defaultExpandParent": booleanType(),
    /** 默认展开指定的树节点 */
    "defaultExpandedKeys": arrayType(),
    /** （受控）展开指定的树节点 */
    "expandedKeys": arrayType(),
    /** （受控）选中复选框的树节点 */
    "checkedKeys": someType([Array, Object]),
    /** 默认选中复选框的树节点 */
    "defaultCheckedKeys": arrayType(),
    /** （受控）设置选中的树节点 */
    "selectedKeys": arrayType(),
    /** 默认选中的树节点 */
    "defaultSelectedKeys": arrayType(),
    "selectable": booleanType(),
    "loadedKeys": arrayType(),
    "draggable": booleanType(),
    "showIcon": booleanType(),
    "icon": functionType(),
    "switcherIcon": PropTypes.any,
    "prefixCls": String,
    /**
     * @default{title,key,children}
     * deprecated, please use `fieldNames` instead
     * 替换treeNode中 title,key,children字段为treeData中对应的字段
     */
    "replaceFields": objectType(),
    "blockNode": booleanType(),
    "openAnimation": PropTypes.any,
    "onDoubleclick": baseTreeProps.onDblclick,
    "onUpdate:selectedKeys": functionType(),
    "onUpdate:checkedKeys": functionType(),
    "onUpdate:expandedKeys": functionType()
  };
};
var Tree = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATree",
  inheritAttrs: false,
  props: initDefaultProps(treeProps(), {
    checkable: false,
    selectable: true,
    showIcon: false,
    blockNode: false
  }),
  slots: Object,
  setup(props, {
    attrs,
    expose,
    emit,
    slots
  }) {
    warning(!(props.treeData === void 0 && slots.default), "`children` of Tree is deprecated. Please use `treeData` instead.");
    const {
      prefixCls,
      direction,
      virtual
    } = useConfigInject("tree", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const treeRef = ref();
    const scrollTo = (scroll) => {
      var _a;
      (_a = treeRef.value) == null ? void 0 : _a.scrollTo(scroll);
    };
    expose({
      treeRef,
      onNodeExpand: (...args) => {
        var _a;
        (_a = treeRef.value) == null ? void 0 : _a.onNodeExpand(...args);
      },
      scrollTo,
      selectedKeys: computed(() => {
        var _a;
        return (_a = treeRef.value) == null ? void 0 : _a.selectedKeys;
      }),
      checkedKeys: computed(() => {
        var _a;
        return (_a = treeRef.value) == null ? void 0 : _a.checkedKeys;
      }),
      halfCheckedKeys: computed(() => {
        var _a;
        return (_a = treeRef.value) == null ? void 0 : _a.halfCheckedKeys;
      }),
      loadedKeys: computed(() => {
        var _a;
        return (_a = treeRef.value) == null ? void 0 : _a.loadedKeys;
      }),
      loadingKeys: computed(() => {
        var _a;
        return (_a = treeRef.value) == null ? void 0 : _a.loadingKeys;
      }),
      expandedKeys: computed(() => {
        var _a;
        return (_a = treeRef.value) == null ? void 0 : _a.expandedKeys;
      })
    });
    watchEffect(() => {
      devWarning(props.replaceFields === void 0, "Tree", "`replaceFields` is deprecated, please use fieldNames instead");
    });
    const handleCheck = (checkedObjOrKeys, eventObj) => {
      emit("update:checkedKeys", checkedObjOrKeys);
      emit("check", checkedObjOrKeys, eventObj);
    };
    const handleExpand = (expandedKeys, eventObj) => {
      emit("update:expandedKeys", expandedKeys);
      emit("expand", expandedKeys, eventObj);
    };
    const handleSelect = (selectedKeys, eventObj) => {
      emit("update:selectedKeys", selectedKeys);
      emit("select", selectedKeys, eventObj);
    };
    return () => {
      const {
        showIcon,
        showLine,
        switcherIcon = slots.switcherIcon,
        icon = slots.icon,
        blockNode,
        checkable,
        selectable,
        fieldNames = props.replaceFields,
        motion = props.openAnimation,
        itemHeight = 28,
        onDoubleclick,
        onDblclick
      } = props;
      const newProps = {
        ...attrs,
        ...omit(props, ["onUpdate:checkedKeys", "onUpdate:expandedKeys", "onUpdate:selectedKeys", "onDoubleclick"]),
        showLine: Boolean(showLine),
        dropIndicatorRender,
        fieldNames,
        icon,
        itemHeight
      };
      const children = slots.default ? filterEmpty(slots.default()) : void 0;
      return wrapSSR(createVNode(Tree$1, mergeProps(newProps, {
        "virtual": virtual.value,
        "motion": motion,
        "ref": treeRef,
        "prefixCls": prefixCls.value,
        "class": classNames({
          [`${prefixCls.value}-icon-hide`]: !showIcon,
          [`${prefixCls.value}-block-node`]: blockNode,
          [`${prefixCls.value}-unselectable`]: !selectable,
          [`${prefixCls.value}-rtl`]: direction.value === "rtl"
        }, attrs.class, hashId.value),
        "direction": direction.value,
        "checkable": checkable,
        "selectable": selectable,
        "switcherIcon": (nodeProps) => renderSwitcherIcon(prefixCls.value, switcherIcon, nodeProps, slots.leafIcon, showLine),
        "onCheck": handleCheck,
        "onExpand": handleExpand,
        "onSelect": handleSelect,
        "onDblclick": onDblclick || onDoubleclick,
        "children": children
      }), {
        ...slots,
        checkable: () => createVNode("span", {
          "class": `${prefixCls.value}-checkbox-inner`
        }, null)
      }));
    };
  }
});

export { Tree as default, treeProps };
//# sourceMappingURL=Tree.mjs.map
