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

'use strict';

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

var vue = require('vue');
var tree_constants = require('../constants.js');
require('../../hooks/useConfig.js');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
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-7f0559c3.js');
require('dayjs');

function useOnDrag(treeStore) {
  var dragNode = vue.ref();
  var _getCurrentInstance = vue.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);
  };
  vue.provide(tree_constants.dragInjectKey, {
    onDragStart: onDragStart,
    onDragEnd: onDragEnd,
    onDragOver: onDragOver,
    onDragLeave: onDragLeave,
    onDrop: onDrop
  });
}

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