'use strict';

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

var vue = require('vue');
require('../vc-tree/index.js');
var props = require('../vc-tree/props.js');
var devWarning = require('../vc-util/devWarning.js');
var warning = require('../vc-util/warning.js');
var type = require('../_util/type.js');
var omit = require('../_util/omit.js');
require('../hooks/index.js');
var initDefaultProps = require('../_util/props-util/initDefaultProps.js');
var index$2 = require('../_util/props-util/index.js');
var index = require('../_util/vue-types/index.js');
var classNames = require('../_util/classNames.js');
var iconUtil = require('./utils/iconUtil.js');
var dropIndicator = require('./utils/dropIndicator.js');
var index$1 = require('./style/index.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var Tree$1 = require('../vc-tree/Tree.js');

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

exports.default = Tree;
exports.treeProps = treeProps;
//# sourceMappingURL=Tree.js.map
