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

'use strict';

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

var helper = require('../_chunks/dep-c3e1ffac.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var upperFirst = require('lodash/upperFirst');
var isFunction = require('lodash/isFunction');
var VueCompositionAPI = require('@vue/composition-api');
var hooks_useConfig = require('../hooks/useConfig.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var tree_props = require('./props.js');
var tree_hooks_useTreeStore = require('./hooks/useTreeStore.js');
var tree_hooks_useTreeStyles = require('./hooks/useTreeStyles.js');
var tree_hooks_useTreeState = require('./hooks/useTreeState.js');
var tree_hooks_useTreeAction = require('./hooks/useTreeAction.js');
var tree_hooks_useTreeScroll = require('./hooks/useTreeScroll.js');
var tree_hooks_useTreeNodes = require('./hooks/useTreeNodes.js');
var tree_hooks_useDragHandle = require('./hooks/useDragHandle.js');
var tree_util = require('./util.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
require('@babel/runtime/helpers/typeof');
require('vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('lodash/pick');
require('../_common/js/tree/tree-store.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('lodash/isArray');
require('lodash/isNumber');
require('lodash/isString');
require('lodash/difference');
require('lodash/isPlainObject');
require('mitt');
require('../_common/js/tree/tree-node.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/regenerator');
require('lodash/isNull');
require('lodash/uniqueId');
require('lodash/isNil');
require('lodash/get');
require('../_common/js/log/log.js');
require('../_common/js/tree/tree-node-model.js');
require('lodash/isUndefined');
require('lodash/isBoolean');
require('lodash/omit');
require('../hooks/useVirtualScrollNew.js');
require('@babel/runtime/helpers/slicedToArray');
require('../hooks/useResizeObserver.js');
require('./tree-item.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/ripple.js');
require('../_common/js/utils/set-style.js');
require('../config.js');
require('./hooks/useTreeItem.js');
require('../hooks/useLazyLoad.js');
require('../_common/js/utils/observe.js');
require('./hooks/useItemEvents.js');
require('./hooks/useRenderIcon.js');
require('@ldesign/icons-vue');
require('../hooks/useGlobalIcon.js');
require('../loading/index.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../loading/plugin.js');
require('../utils/dom.js');
require('raf');
require('../utils/easing.js');
require('../loading/loading.js');
require('../utils/transfer-dom.js');
require('../utils/mixins.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('./hooks/useRenderLabel.js');
require('../checkbox/index.js');
require('../utils/map-props.js');
require('../checkbox/group.js');
require('lodash/intersection');
require('../utils/event.js');
require('../utils/helper.js');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../checkbox/checkbox-group-props.js');
require('./hooks/useRenderLine.js');
require('./hooks/useRenderOperations.js');
require('./hooks/useDraggable.js');
require('lodash/throttle');
require('./hooks/useTreeEvents.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var upperFirst__default = /*#__PURE__*/_interopDefaultLegacy(upperFirst);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

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__default["default"](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 = VueCompositionAPI.defineComponent({
  name: "TTree",
  model: {
    prop: "value",
    event: "change"
  },
  props: _objectSpread({}, tree_props["default"]),
  setup: function setup(props2, context) {
    var _useConfig = configProvider_useConfig.useConfig("tree"),
      t = _useConfig.t,
      global = _useConfig.global;
    var classPrefix = hooks_useConfig.usePrefixClass();
    var componentName = hooks_useConfig.usePrefixClass("tree");
    var refProps = VueCompositionAPI.toRefs(props2);
    var _useTreeStore = tree_hooks_useTreeStore["default"](props2, context),
      store = _useTreeStore.store,
      rebuild = _useTreeStore.rebuild,
      updateStoreConfig = _useTreeStore.updateStoreConfig;
    var _useTreeState = tree_hooks_useTreeState["default"](props2, store),
      state = _useTreeState.state,
      treeContentRef = _useTreeState.treeContentRef,
      isScrolling = _useTreeState.isScrolling;
    tree_hooks_useDragHandle["default"](props2, context, state);
    var _useTreeAction = tree_hooks_useTreeAction["default"](props2, context, state),
      setActived = _useTreeAction.setActived,
      setExpanded = _useTreeAction.setExpanded,
      setChecked = _useTreeAction.setChecked;
    var _useTreeScroll = tree_hooks_useTreeScroll["default"](props2, context, state),
      onInnerVirtualScroll = _useTreeScroll.onInnerVirtualScroll,
      virtualConfig = _useTreeScroll.virtualConfig;
    var _useTreeNodes = tree_hooks_useTreeNodes["default"](props2, context, state),
      renderTreeNodes = _useTreeNodes.renderTreeNodes,
      nodesEmpty = _useTreeNodes.nodesEmpty;
    var _useTreeStyles = tree_hooks_useTreeStyles["default"](props2, state),
      treeClasses = _useTreeStyles.treeClasses,
      treeContentStyles = _useTreeStyles.treeContentStyles,
      scrollStyles = _useTreeStyles.scrollStyles,
      cursorStyles = _useTreeStyles.cursorStyles;
    VueCompositionAPI.watch(refProps.data, function (list) {
      rebuild(list);
    });
    VueCompositionAPI.watch(refProps.keys, function (keys) {
      store.setConfig({
        keys: keys
      });
    });
    VueCompositionAPI.watch(refProps.value, function (nVal, previousVal) {
      if (nVal.join() === (previousVal === null || previousVal === void 0 ? void 0 : previousVal.join())) return;
      store.replaceChecked(nVal);
    });
    VueCompositionAPI.watch(refProps.expanded, function (nVal) {
      store.replaceExpanded(nVal);
    });
    VueCompositionAPI.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__default["default"](name));
            var setupMethod = _this[methodName];
            if (isFunction__default["default"](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 = tree_util.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 = tree_util.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 = tree_util.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) : utils_renderTnode.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.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;
  }
});

exports["default"] = _TdTree;
//# sourceMappingURL=td-tree.js.map
