/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

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

var hooks_useConfig = require('../../../hooks/useConfig.js');
var components_tree_hooks_useItemEvents = require('./useItemEvents.js');
var components_tree_hooks_useRenderIcon = require('./useRenderIcon.js');
var components_tree_hooks_useRenderLabel = require('./useRenderLabel.js');
var components_tree_hooks_useRenderLine = require('./useRenderLine.js');
var components_tree_hooks_useRenderOperations = require('./useRenderOperations.js');
var components_tree_hooks_useDraggable = require('./useDraggable.js');
require('@vue/composition-api');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../../../chunks/zh_CN.js');
require('@ldesign/icons-vue');
require('../../../hooks/useGlobalIcon.js');
require('../../loading/index.js');
require('../../../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../../../config.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-fe796db6.js');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('lodash');
require('../../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('../../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-19da3d4c.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('../utils.js');
require('lodash/camelCase');
require('../../checkbox/index.js');
require('../../../utils/map-props.js');
require('../../checkbox/group.js');
require('../../../chunks/helper.js');
require('lodash/intersection');
require('../../../utils/event.js');
require('../../../utils/helper.js');
require('../../checkbox/checkbox.js');
require('../../checkbox/props.js');
require('lodash/throttle');

function useTreeItem(props, context, root) {
  const {
    node
  } = props;
  const classPrefix = hooks_useConfig.usePrefixClass().value;
  const componentName = hooks_useConfig.usePrefixClass("tree").value;
  const {
    handleClick
  } = components_tree_hooks_useItemEvents["default"](props, context);
  const {
    renderIcon
  } = components_tree_hooks_useRenderIcon["default"](props);
  const {
    renderLabel
  } = components_tree_hooks_useRenderLabel["default"](props, context);
  const {
    renderLine
  } = components_tree_hooks_useRenderLine["default"](props);
  const {
    renderOperations
  } = components_tree_hooks_useRenderOperations["default"](props);
  const {
    dragStates,
    handleDragStart,
    handleDragEnd,
    handleDragOver,
    handleDragLeave,
    handleDrop
  } = components_tree_hooks_useDraggable["default"](props, root);
  const getItemStyles = () => {
    const {
      level
    } = node;
    const levelStyle = `--level: ${level};`;
    const strStyle = `${levelStyle}`;
    return strStyle;
  };
  const getItemClassList = () => {
    const {
      isDragOver,
      isDragging,
      dropPosition
    } = dragStates;
    const list = [];
    list.push(`${componentName}__item`);
    list.push({
      [`${componentName}__item--open`]: node.expanded,
      [`${classPrefix}-is-active`]: node.isActivable() ? node.actived : false,
      [`${classPrefix}-is-disabled`]: node.isDisabled()
    });
    list.push({
      [`${componentName}__item--draggable`]: node.isDraggable()
    });
    if (node.visible) list.push(`${componentName}__item--visible`);else list.push(`${componentName}__item--hidden`);
    list.push({
      [`${componentName}__item--dragging`]: isDragging,
      [`${componentName}__item--tip-top`]: isDragOver && dropPosition < 0,
      [`${componentName}__item--tip-bottom`]: isDragOver && dropPosition > 0,
      [`${componentName}__item--tip-highlight`]: !isDragging && isDragOver && dropPosition === 0
    });
    return list;
  };
  const renderItem = h => {
    const itemNodes = [];
    const iconNode = renderIcon(h);
    const lineNode = renderLine(h);
    if (lineNode) itemNodes.push(lineNode);
    if (iconNode) itemNodes.push(iconNode);
    const labelNode = renderLabel(h);
    if (labelNode) itemNodes.push(labelNode);
    const opNode = renderOperations(h);
    if (opNode) itemNodes.push(opNode);
    return itemNodes;
  };
  const renderItemNode = h => {
    const {
      level,
      value
    } = node;
    const styles = getItemStyles();
    const classList = getItemClassList();
    const itemNode = h("div", {
      "ref": "root",
      "class": classList,
      "attrs": {
        "data-value": value,
        "data-level": level,
        "draggable": node.isDraggable()
      },
      "style": styles,
      "on": {
        "click": evt => handleClick(evt),
        "dragstart": evt => handleDragStart(evt),
        "dragend": evt => handleDragEnd(evt),
        "dragover": evt => handleDragOver(evt),
        "dragleave": evt => handleDragLeave(evt),
        "drop": evt => handleDrop(evt)
      }
    }, [renderItem(h)]);
    return itemNode;
  };
  return {
    renderItemNode
  };
}

exports["default"] = useTreeItem;
//# sourceMappingURL=useTreeItem.js.map
