/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-c89aafbb.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import upperFirst from 'lodash/upperFirst';
import isFunction from 'lodash/isFunction';
import { defineComponent, toRefs, watch } from '@vue/composition-api';
import { usePrefixClass } from '../hooks/useConfig.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import props from './props.js';
import useTreeStore from './hooks/useTreeStore.js';
import useTreeStyles from './hooks/useTreeStyles.js';
import useTreeState from './hooks/useTreeState.js';
import useTreeAction from './hooks/useTreeAction.js';
import useTreeScroll from './hooks/useTreeScroll.js';
import useTreeNodes from './hooks/useTreeNodes.js';
import useDragHandle from './hooks/useDragHandle.js';
import { getNode } from './util.js';
import { useConfig } from '../config-provider/useConfig.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/pick';
import '../_common/js/tree/tree-store.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import 'lodash/isArray';
import 'lodash/isNumber';
import 'lodash/isString';
import 'lodash/difference';
import 'lodash/isPlainObject';
import 'mitt';
import '../_common/js/tree/tree-node.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/regenerator';
import 'lodash/isNull';
import 'lodash/uniqueId';
import 'lodash/isNil';
import 'lodash/get';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/tree/tree-node-model.js';
import 'lodash/isUndefined';
import 'lodash/isBoolean';
import 'lodash/omit';
import '../hooks/useVirtualScrollNew.js';
import '@babel/runtime/helpers/slicedToArray';
import '../hooks/useResizeObserver.js';
import './tree-item.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../_chunks/dep-67ff4010.js';
import '../config-provider/type.js';
import '../utils/ripple.js';
import '../_common/js/utils/set-style.js';
import '../config.js';
import './hooks/useTreeItem.js';
import '../hooks/useLazyLoad.js';
import '../_common/js/utils/observe.js';
import './hooks/useItemEvents.js';
import './hooks/useRenderIcon.js';
import '@ldesign/icons-vue';
import '../hooks/useGlobalIcon.js';
import '../loading/index.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import '../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.js';
import '../loading/loading.js';
import '../utils/transfer-dom.js';
import '../utils/mixins.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../loading/style/css.js';
import '../loading/type.js';
import './hooks/useRenderLabel.js';
import '../checkbox/index.js';
import '../utils/map-props.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../utils/event.js';
import '../utils/helper.js';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/style/css.js';
import '../checkbox/type.js';
import './hooks/useRenderLine.js';
import './hooks/useRenderOperations.js';
import './hooks/useDraggable.js';
import 'lodash/throttle';
import './hooks/useTreeEvents.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var _TdTree = defineComponent({
  name: "TTree",
  model: {
    prop: "value",
    event: "change"
  },
  props: _objectSpread({}, props),
  setup: function setup(props2, context) {
    var _useConfig = useConfig("tree"),
      t = _useConfig.t,
      global = _useConfig.global;
    var classPrefix = usePrefixClass();
    var componentName = usePrefixClass("tree");
    var refProps = toRefs(props2);
    var _useTreeStore = useTreeStore(props2, context),
      store = _useTreeStore.store,
      rebuild = _useTreeStore.rebuild,
      updateStoreConfig = _useTreeStore.updateStoreConfig;
    var _useTreeState = useTreeState(props2, store),
      state = _useTreeState.state,
      treeContentRef = _useTreeState.treeContentRef,
      isScrolling = _useTreeState.isScrolling;
    useDragHandle(props2, context, state);
    var _useTreeAction = useTreeAction(props2, context, state),
      setActived = _useTreeAction.setActived,
      setExpanded = _useTreeAction.setExpanded,
      setChecked = _useTreeAction.setChecked;
    var _useTreeScroll = useTreeScroll(props2, context, state),
      onInnerVirtualScroll = _useTreeScroll.onInnerVirtualScroll,
      virtualConfig = _useTreeScroll.virtualConfig;
    var _useTreeNodes = useTreeNodes(props2, context, state),
      renderTreeNodes = _useTreeNodes.renderTreeNodes,
      nodesEmpty = _useTreeNodes.nodesEmpty;
    var _useTreeStyles = useTreeStyles(props2, state),
      treeClasses = _useTreeStyles.treeClasses,
      treeContentStyles = _useTreeStyles.treeContentStyles,
      scrollStyles = _useTreeStyles.scrollStyles,
      cursorStyles = _useTreeStyles.cursorStyles;
    watch(refProps.data, function (list) {
      rebuild(list);
    });
    watch(refProps.keys, function (keys) {
      store.setConfig({
        keys: keys
      });
    });
    watch(refProps.value, function (nVal, previousVal) {
      if (nVal.join() === (previousVal === null || previousVal === void 0 ? void 0 : previousVal.join())) return;
      store.replaceChecked(nVal);
    });
    watch(refProps.expanded, function (nVal) {
      store.replaceExpanded(nVal);
    });
    watch(refProps.actived, function (nVal, previousVal) {
      if (nVal.join() === (previousVal === null || previousVal === void 0 ? void 0 : previousVal.join())) return;
      store.replaceActived(nVal);
    });
    return {
      t: t,
      global: global,
      classPrefix: classPrefix,
      componentName: componentName,
      state: state,
      store: store,
      treeClasses: treeClasses,
      treeContentRef: treeContentRef,
      updateStoreConfig: updateStoreConfig,
      setActived: setActived,
      setExpanded: setExpanded,
      setChecked: setChecked,
      renderTreeNodes: renderTreeNodes,
      nodesEmpty: nodesEmpty,
      isScrolling: isScrolling,
      onInnerVirtualScroll: onInnerVirtualScroll,
      treeContentStyles: treeContentStyles,
      scrollStyles: scrollStyles,
      cursorStyles: cursorStyles,
      virtualConfig: virtualConfig,
      scrollToElement: virtualConfig.scrollToElement
    };
  },
  methods: {
    setItem: function setItem(value, options) {
      var _this = this;
      var node = this.store.getNode(value);
      var spec = options;
      var keys = Object.keys(spec);
      if (node && spec) {
        ["expanded", "actived", "checked"].forEach(function (name) {
          if (keys.includes(name)) {
            var val = spec[name];
            delete spec[name];
            var methodName = "set".concat(upperFirst(name));
            var setupMethod = _this[methodName];
            if (isFunction(setupMethod)) setupMethod(node, val);
          }
        });
        node.set(spec);
      }
    },
    getItem: function getItem(value) {
      var node = this.store.getNode(value);
      return node === null || node === void 0 ? void 0 : node.getModel();
    },
    getItems: function getItems(value) {
      var nodes = this.store.getNodes(value);
      return nodes.map(function (node) {
        return node.getModel();
      });
    },
    appendTo: function appendTo(para, item) {
      var store = this.store;
      var list = [];
      if (Array.isArray(item)) list = item;else list = [item];
      list.forEach(function (item2) {
        var val = (item2 === null || item2 === void 0 ? void 0 : item2.value) || "";
        var node = getNode(store, val);
        if (node) store.appendNodes(para, node);else store.appendNodes(para, item2);
      });
    },
    insertBefore: function insertBefore(value, item) {
      var store = this.store;
      var val = (item === null || item === void 0 ? void 0 : item.value) || "";
      var node = getNode(store, val);
      if (node) store.insertBefore(value, node);else store.insertBefore(value, item);
    },
    insertAfter: function insertAfter(value, item) {
      var store = this.store;
      var val = (item === null || item === void 0 ? void 0 : item.value) || "";
      var node = getNode(store, val);
      if (node) store.insertAfter(value, node);else store.insertAfter(value, item);
    },
    remove: function remove(value) {
      return this.store.remove(value);
    },
    getIndex: function getIndex(value) {
      return this.store.getNodeIndex(value);
    },
    getParent: function getParent(value) {
      var node = this.store.getParent(value);
      return node === null || node === void 0 ? void 0 : node.getModel();
    },
    getParents: function getParents(value) {
      var nodes = this.store.getParents(value);
      return nodes.map(function (node) {
        return node.getModel();
      });
    },
    getPath: function getPath(value) {
      var node = this.store.getNode(value);
      var pathNodes = [];
      if (node) pathNodes = node.getPath().map(function (node2) {
        return node2.getModel();
      });
      return pathNodes;
    }
  },
  render: function render(h) {
    var state = this.state,
      treeClasses = this.treeClasses,
      updateStoreConfig = this.updateStoreConfig,
      renderTreeNodes = this.renderTreeNodes,
      nodesEmpty = this.nodesEmpty,
      isScrolling = this.isScrolling,
      virtualConfig = this.virtualConfig,
      treeContentStyles = this.treeContentStyles,
      scrollStyles = this.scrollStyles,
      cursorStyles = this.cursorStyles;
    updateStoreConfig();
    var scope = state.scope;
    scope.scopedSlots = this.$scopedSlots;
    var treeNodeViews = renderTreeNodes(h);
    var cname = this.componentName;
    var isVirtual = virtualConfig.isVirtualScroll.value;
    var emptyNode = null;
    if (nodesEmpty) {
      var useLocale = !this.empty && !this.$scopedSlots.empty;
      var emptyContent = useLocale ? this.t(this.global.empty) : renderTNodeJSX(this, "empty");
      emptyNode = h("div", {
        "class": "".concat(cname, "__empty")
      }, [emptyContent]);
    } else if (treeNodeViews.length <= 0) {
      emptyNode = h("div");
    }
    var $props = this.$props;
    var transition = $props.transition;
    var treeNodeList = null;
    if (!transition || isVirtual && isScrolling) {
      treeNodeList = h("div", {
        "class": "".concat(cname, "__list"),
        "style": scrollStyles
      }, [treeNodeViews]);
    } else {
      treeNodeList = h("transition-group", {
        "attrs": {
          "tag": "div",
          "enter-active-class": "".concat(cname, "__item--enter-active"),
          "leave-active-class": "".concat(cname, "__item--leave-active")
        },
        "class": "".concat(cname, "__list"),
        "style": scrollStyles
      }, [treeNodeViews]);
    }
    var treeNode = h("div", helper([{
      "class": treeClasses,
      "ref": "treeContentRef"
    }, {
      "on": {
        scroll: this.onInnerVirtualScroll
      }
    }, {
      "style": treeContentStyles
    }]), [isVirtual && h("div", {
      "class": "".concat(cname, "__vscroll-cursor"),
      "style": cursorStyles
    }), emptyNode || treeNodeList]);
    return treeNode;
  }
});

export { _TdTree as default };
//# sourceMappingURL=td-tree.js.map
