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

import { usePrefixClass } from '../../../hooks/useConfig.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 '@vue/composition-api';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '@ldesign/icons-vue';
import '../../../hooks/useGlobalIcon.js';
import '../../loading/index.js';
import '../../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../../config.js';
import '../../loading/loading.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../chunks/index.js';
import '../../../chunks/log.js';
import '../../../chunks/_commonjsHelpers-fe796db6.js';
import '../../../utils/easing.js';
import '../../../utils/render-node.js';
import 'lodash';
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 '../../../chunks/defineProperty-19da3d4c.js';
import '../../../chunks/set-style.js';
import '../../../chunks/helper2.js';
import '../../loading/style';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../utils.js';
import 'lodash/camelCase';
import '../../checkbox/index.js';
import '../../../utils/map-props.js';
import '../../checkbox/group.js';
import '../../../chunks/helper.js';
import '../../../chunks/_commonjsHelpers.js';
import 'lodash/intersection';
import '../../../utils/event.js';
import '../../../utils/helper.js';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../checkbox/style';
import '../../checkbox/type.js';
import 'lodash/throttle';

function useTreeItem(props, context, root) {
  const {
    node
  } = props;
  const classPrefix = usePrefixClass().value;
  const componentName = usePrefixClass("tree").value;
  const {
    handleClick
  } = useItemEvents(props, context);
  const {
    renderIcon
  } = useRenderIcon(props);
  const {
    renderLabel
  } = useRenderLabel(props, context);
  const {
    renderLine
  } = useRenderLine(props);
  const {
    renderOperations
  } = useRenderOperations(props);
  const {
    dragStates,
    handleDragStart,
    handleDragEnd,
    handleDragOver,
    handleDragLeave,
    handleDrop
  } = useDraggable(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
  };
}

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