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

import { ref, getCurrentInstance, provide } from 'vue';
import { dragInjectKey } from '../constants.js';
import '../../hooks/useConfig.js';
import '../../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/isFunction';
import 'lodash/isString';
import '../../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
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-e041f5b0.js';
import 'dayjs';

function useOnDrag(treeStore) {
  var dragNode = ref();
  var _getCurrentInstance = getCurrentInstance(),
    emit = _getCurrentInstance.emit;
  var onDragStart = function onDragStart(context) {
    dragNode.value = context.node;
    emit === null || emit === void 0 ? void 0 : emit("dragStart", context);
  };
  var onDragEnd = function onDragEnd(context) {
    dragNode.value = context.node;
    emit === null || emit === void 0 ? void 0 : emit("dragEnd", context);
  };
  var onDragOver = function onDragOver(context) {
    emit === null || emit === void 0 ? void 0 : emit("dragOver", context);
  };
  var onDragLeave = function onDragLeave(context) {
    emit === null || emit === void 0 ? void 0 : emit("dragLeave", context);
  };
  var onDrop = function onDrop(context) {
    var node = context.node,
      dropPosition = context.dropPosition;
    if (node.value === dragNode.value.value || node.getParents().some(function (_node) {
      return _node.value === dragNode.value.value;
    })) return;
    var nodes = treeStore.value.getNodes();
    nodes.some(function (_node, _index) {
      if (_node.value === node.value) {
        if (dropPosition === 0) dragNode.value.appendTo(treeStore.value, _node);else if (dropPosition < 0) node.insertBefore(dragNode.value);else node.insertAfter(dragNode.value);
        return true;
      }
      return false;
    });
    emit === null || emit === void 0 ? void 0 : emit("drop", context);
  };
  provide(dragInjectKey, {
    onDragStart: onDragStart,
    onDragEnd: onDragEnd,
    onDragOver: onDragOver,
    onDragLeave: onDragLeave,
    onDrop: onDrop
  });
}

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