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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var hooks_useConfig = require('../../hooks/useConfig.js');
var hooks_useLazyLoad = require('../../hooks/useLazyLoad.js');
var tree_hooks_useItemEvents = require('./useItemEvents.js');
var tree_hooks_useRenderIcon = require('./useRenderIcon.js');
var tree_hooks_useRenderLabel = require('./useRenderLabel.js');
var tree_hooks_useRenderLine = require('./useRenderLine.js');
var tree_hooks_useRenderOperations = require('./useRenderOperations.js');
var tree_hooks_useDraggable = require('./useDraggable.js');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('lodash/merge');
require('lodash/mergeWith');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-7c884501.js');
require('dayjs');
require('../../_common/js/utils/observe.js');
require('@ldesign/icons-vue');
require('../../hooks/useGlobalIcon.js');
require('../../loading/index.js');
require('../../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../../loading/plugin.js');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../loading/loading.js');
require('../../utils/render-tnode.js');
require('lodash/camelCase');
require('lodash/kebabCase');
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('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('../util.js');
require('../../_chunks/dep-c3e1ffac.js');
require('lodash/isBoolean');
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('lodash/throttle');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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; }
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 = hooks_useConfig.usePrefixClass().value;
  var componentName = hooks_useConfig.usePrefixClass("tree").value;
  var _useItemEvents = tree_hooks_useItemEvents["default"](props, context),
    handleClick = _useItemEvents.handleClick;
  var _useRenderIcon = tree_hooks_useRenderIcon["default"](props),
    renderIcon = _useRenderIcon.renderIcon;
  var _useRenderLabel = tree_hooks_useRenderLabel["default"](props, context),
    renderLabel = _useRenderLabel.renderLabel;
  var _useRenderLine = tree_hooks_useRenderLine["default"](props),
    renderLine = _useRenderLine.renderLine;
  var _useRenderOperations = tree_hooks_useRenderOperations["default"](props),
    renderOperations = _useRenderOperations.renderOperations;
  var _useDraggable = tree_hooks_useDraggable["default"](props, treeItemRef),
    dragStates = _useDraggable.dragStates,
    handleDragStart = _useDraggable.handleDragStart,
    handleDragEnd = _useDraggable.handleDragEnd,
    handleDragOver = _useDraggable.handleDragOver,
    handleDragLeave = _useDraggable.handleDragLeave,
    handleDrop = _useDraggable.handleDrop;
  var _useLazyLoad = hooks_useLazyLoad["default"](treeContentRef, treeItemRef, VueCompositionAPI.reactive(_objectSpread({}, scrollProps === null || scrollProps === void 0 ? void 0 : scrollProps.value))),
    hasLazyLoadHolder = _useLazyLoad.hasLazyLoadHolder,
    tRowHeight = _useLazyLoad.tRowHeight;
  VueCompositionAPI.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__default["default"](_list$push, "".concat(componentName, "__item--open"), node.expanded), _defineProperty__default["default"](_list$push, "".concat(classPrefix, "-is-active"), node.isActivable() ? node.actived : false), _defineProperty__default["default"](_list$push, "".concat(classPrefix, "-is-disabled"), node.isDisabled()), _list$push));
    list.push(_defineProperty__default["default"]({}, "".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__default["default"](_list$push3, "".concat(componentName, "__item--dragging"), isDragging), _defineProperty__default["default"](_list$push3, "".concat(componentName, "__item--tip-top"), isDragOver && dropPosition < 0), _defineProperty__default["default"](_list$push3, "".concat(componentName, "__item--tip-bottom"), isDragOver && dropPosition > 0), _defineProperty__default["default"](_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
  };
}

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