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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { reactive, onMounted } from '@vue/composition-api';
import { usePrefixClass } from '../../hooks/useConfig.js';
import useLazyLoad from '../../hooks/useLazyLoad.js';
import useItemEvents from './useItemEvents.js';
import useRenderIcon from './useRenderIcon.js';
import useRenderLabel from './useRenderLabel.js';
import useRenderLine from './useRenderLine.js';
import useRenderOperations from './useRenderOperations.js';
import useDraggable from './useDraggable.js';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../../_chunks/dep-67ff4010.js';
import '../../config-provider/type.js';
import '../../_common/js/utils/observe.js';
import '@ldesign/icons-vue';
import '../../hooks/useGlobalIcon.js';
import '../../loading/index.js';
import '../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../../loading/plugin.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../loading/loading.js';
import '../../utils/render-tnode.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.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/set-style.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../../loading/style/css.js';
import '../../loading/type.js';
import '../util.js';
import '../../_chunks/dep-c89aafbb.js';
import 'lodash/isBoolean';
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 'lodash/throttle';

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; }
function useTreeItem(props, context, treeItemRef) {
  var node = props.node,
    treeScope = props.treeScope;
  var virtualConfig = treeScope.virtualConfig,
    treeContentRef = treeScope.treeContentRef;
  var scrollProps = treeScope === null || treeScope === void 0 ? void 0 : treeScope.scrollProps;
  var classPrefix = usePrefixClass().value;
  var componentName = usePrefixClass("tree").value;
  var _useItemEvents = useItemEvents(props, context),
    handleClick = _useItemEvents.handleClick;
  var _useRenderIcon = useRenderIcon(props),
    renderIcon = _useRenderIcon.renderIcon;
  var _useRenderLabel = useRenderLabel(props, context),
    renderLabel = _useRenderLabel.renderLabel;
  var _useRenderLine = useRenderLine(props),
    renderLine = _useRenderLine.renderLine;
  var _useRenderOperations = useRenderOperations(props),
    renderOperations = _useRenderOperations.renderOperations;
  var _useDraggable = useDraggable(props, treeItemRef),
    dragStates = _useDraggable.dragStates,
    handleDragStart = _useDraggable.handleDragStart,
    handleDragEnd = _useDraggable.handleDragEnd,
    handleDragOver = _useDraggable.handleDragOver,
    handleDragLeave = _useDraggable.handleDragLeave,
    handleDrop = _useDraggable.handleDrop;
  var _useLazyLoad = useLazyLoad(treeContentRef, treeItemRef, reactive(_objectSpread({}, scrollProps === null || scrollProps === void 0 ? void 0 : scrollProps.value))),
    hasLazyLoadHolder = _useLazyLoad.hasLazyLoadHolder,
    tRowHeight = _useLazyLoad.tRowHeight;
  onMounted(function () {
    var isVirtual = virtualConfig === null || virtualConfig === void 0 ? void 0 : virtualConfig.isVirtualScroll.value;
    if (isVirtual) {
      virtualConfig.handleRowMounted({
        ref: treeItemRef,
        data: node
      });
    }
  });
  var getItemStyles = function getItemStyles() {
    var level = node.level;
    var levelStyle = "--level: ".concat(level, ";");
    var strStyle = "".concat(levelStyle);
    return strStyle;
  };
  var getItemClassList = function getItemClassList() {
    var _list$push, _list$push3;
    var isDragOver = dragStates.isDragOver,
      isDragging = dragStates.isDragging,
      dropPosition = dragStates.dropPosition;
    var list = [];
    list.push("".concat(componentName, "__item"));
    list.push((_list$push = {}, _defineProperty(_list$push, "".concat(componentName, "__item--open"), node.expanded), _defineProperty(_list$push, "".concat(classPrefix, "-is-active"), node.isActivable() ? node.actived : false), _defineProperty(_list$push, "".concat(classPrefix, "-is-disabled"), node.isDisabled()), _list$push));
    list.push(_defineProperty({}, "".concat(componentName, "__item--draggable"), node.isDraggable()));
    if (node.visible) list.push("".concat(componentName, "__item--visible"));else list.push("".concat(componentName, "__item--hidden"));
    if (node.vmIsLocked) list.push("".concat(componentName, "__item--locked"));
    if (node.vmIsRest) list.push("".concat(componentName, "__item--matched"));
    list.push((_list$push3 = {}, _defineProperty(_list$push3, "".concat(componentName, "__item--dragging"), isDragging), _defineProperty(_list$push3, "".concat(componentName, "__item--tip-top"), isDragOver && dropPosition < 0), _defineProperty(_list$push3, "".concat(componentName, "__item--tip-bottom"), isDragOver && dropPosition > 0), _defineProperty(_list$push3, "".concat(componentName, "__item--tip-highlight"), !isDragging && isDragOver && dropPosition === 0), _list$push3));
    return list;
  };
  var renderItem = function renderItem(h) {
    var itemNodes = [];
    var iconNode = renderIcon(h);
    var lineNode = renderLine(h);
    if (lineNode) itemNodes.push(lineNode);
    if (iconNode) itemNodes.push(iconNode);
    var labelNode = renderLabel(h);
    if (labelNode) itemNodes.push(labelNode);
    var opNode = renderOperations(h);
    if (opNode) itemNodes.push(opNode);
    return itemNodes;
  };
  var renderItemNode = function renderItemNode(h) {
    var level = node.level,
      value = node.value;
    var styles = getItemStyles();
    var classList = getItemClassList();
    var itemNode = h("div", {
      "ref": "treeItemRef",
      "class": classList,
      "attrs": {
        "data-value": value,
        "data-level": level,
        "draggable": node.isDraggable()
      },
      "style": styles,
      "on": {
        "click": function click(evt) {
          return handleClick(evt);
        },
        "dragstart": function dragstart(evt) {
          return handleDragStart(evt);
        },
        "dragend": function dragend(evt) {
          return handleDragEnd(evt);
        },
        "dragover": function dragover(evt) {
          return handleDragOver(evt);
        },
        "dragleave": function dragleave(evt) {
          return handleDragLeave(evt);
        },
        "drop": function drop(evt) {
          return handleDrop(evt);
        }
      }
    }, [hasLazyLoadHolder.value ? [h("div")] : renderItem(h)]);
    return itemNode;
  };
  return {
    hasLazyLoadHolder: hasLazyLoadHolder,
    tRowHeight: tRowHeight,
    renderItemNode: renderItemNode
  };
}

export { useTreeItem as default };
//# sourceMappingURL=useTreeItem.js.map
