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

import { toRefs, inject, ref } from 'vue';
import { t as throttle_1 } from '../../_chunks/dep-b069d97f.mjs';
import { dragInjectKey } from '../constants.mjs';
import '../../_chunks/dep-a0b4a044.mjs';
import '../../_chunks/dep-96bb54d5.mjs';
import '../../_chunks/dep-0f0c89ff.mjs';
import '../../_chunks/dep-b4041200.mjs';
import '../../_chunks/dep-6b22dd27.mjs';
import '../../_chunks/dep-c959a6fb.mjs';
import '../../_chunks/dep-6205fc47.mjs';
import '../../_chunks/dep-be27d184.mjs';
import '../../_chunks/dep-c31e1d9e.mjs';
import '../../hooks/useConfig.mjs';
import '../../config-provider/useConfig.mjs';
import '../../_chunks/dep-44417261.mjs';
import '../../_chunks/dep-bf74f1c2.mjs';
import '../../_chunks/dep-79821ff2.mjs';
import '../../_chunks/dep-0bfbf721.mjs';
import '../../_chunks/dep-39cc276d.mjs';
import '../../_chunks/dep-8f777748.mjs';
import '../../_chunks/dep-ae357f26.mjs';
import '../../_chunks/dep-352691c2.mjs';
import '../../_chunks/dep-2cfd5b3a.mjs';
import '../../_chunks/dep-05fa17c9.mjs';
import '../../_chunks/dep-e3b14d70.mjs';
import '../../_chunks/dep-66d6733b.mjs';
import '../../_chunks/dep-a9c8a5d5.mjs';
import '../../_chunks/dep-10085c61.mjs';
import '../../_chunks/dep-1b058de3.mjs';
import '../../_chunks/dep-c852a61a.mjs';
import '../../_chunks/dep-92e7085e.mjs';
import '../../_chunks/dep-44f056cd.mjs';
import '../../_chunks/dep-23a0f453.mjs';
import '../../_chunks/dep-1cf2b129.mjs';
import '../../_chunks/dep-99920870.mjs';
import '../../_chunks/dep-c7e9ce16.mjs';
import '../../_chunks/dep-3afa94cf.mjs';
import '../../_chunks/dep-ba3c0b2e.mjs';
import '../../_chunks/dep-ee57d235.mjs';
import '../../_common/js/global-config/default-config.mjs';
import '../../_common/js/global-config/locale/zh_CN.mjs';
import '../../_chunks/dep-6b4aa943.mjs';
import '../../_chunks/dep-d52291a9.mjs';
import '../../config-provider/type.mjs';

function useDraggable(props) {
  var _toRefs = toRefs(props),
    nodeRef = _toRefs.nodeRef,
    node = _toRefs.node;
  var onDrag = inject(dragInjectKey);
  var isDragOver = ref(false);
  var isDragging = ref(false);
  var dropPosition = ref(0);
  var updateDropPosition = throttle_1(function (e) {
    if (typeof window === "undefined") return;
    if (!nodeRef.value) return;
    var rect = nodeRef.value.getBoundingClientRect();
    var offsetY = window.pageYOffset + rect.top;
    var pageY = e.pageY;
    var gapHeight = rect.height / 4;
    var diff = pageY - offsetY;
    if (diff < gapHeight) dropPosition.value = -1;else if (diff < rect.height - gapHeight) dropPosition.value = 0;else dropPosition.value = 1;
  });
  var setDragStatus = function setDragStatus(status, e) {
    var _onDrag$onDragStart, _onDrag$onDragEnd, _onDrag$onDragOver, _onDrag$onDragLeave, _onDrag$onDrop;
    switch (status) {
      case "dragStart":
        isDragging.value = true;
        dropPosition.value = 0;
        (_onDrag$onDragStart = onDrag.onDragStart) === null || _onDrag$onDragStart === void 0 ? void 0 : _onDrag$onDragStart.call(onDrag, {
          node: node.value,
          e: e
        });
        e.dataTransfer.effectAllowed = "move";
        break;
      case "dragEnd":
        isDragging.value = false;
        isDragOver.value = false;
        dropPosition.value = 0;
        updateDropPosition.cancel();
        (_onDrag$onDragEnd = onDrag.onDragEnd) === null || _onDrag$onDragEnd === void 0 ? void 0 : _onDrag$onDragEnd.call(onDrag, {
          node: node.value,
          e: e
        });
        break;
      case "dragOver":
        isDragOver.value = true;
        updateDropPosition(e);
        (_onDrag$onDragOver = onDrag.onDragOver) === null || _onDrag$onDragOver === void 0 ? void 0 : _onDrag$onDragOver.call(onDrag, {
          node: node.value,
          e: e
        });
        break;
      case "dragLeave":
        isDragOver.value = false;
        dropPosition.value = 0;
        updateDropPosition.cancel();
        (_onDrag$onDragLeave = onDrag.onDragLeave) === null || _onDrag$onDragLeave === void 0 ? void 0 : _onDrag$onDragLeave.call(onDrag, {
          node: node.value,
          e: e
        });
        break;
      case "drop":
        (_onDrag$onDrop = onDrag.onDrop) === null || _onDrag$onDrop === void 0 ? void 0 : _onDrag$onDrop.call(onDrag, {
          node: node.value,
          dropPosition: dropPosition.value,
          e: e
        });
        isDragOver.value = false;
        updateDropPosition.cancel();
        break;
      default:
        break;
    }
  };
  return {
    isDragOver: isDragOver,
    isDragging: isDragging,
    dropPosition: dropPosition,
    setDragStatus: setDragStatus
  };
}

export { useDraggable as default };
//# sourceMappingURL=useDraggable.mjs.map
