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

import { toRefs, inject, ref } from 'vue';
import { t as throttle_1 } from '../../_chunks/dep-4f3ad3f8.mjs';
import { dragInjectKey } from '../constants.mjs';
import '../../_chunks/dep-eba0ea6e.mjs';
import '../../_chunks/dep-9b6cf76d.mjs';
import '../../_chunks/dep-a8bcacea.mjs';
import '../../_chunks/dep-255303ba.mjs';
import '../../_chunks/dep-5717e263.mjs';
import '../../_chunks/dep-469b4ae0.mjs';
import '../../_chunks/dep-f709f709.mjs';
import '../../_chunks/dep-2bc37d52.mjs';
import '../../_chunks/dep-3da99438.mjs';
import '../../hooks/useConfig.mjs';
import '../../config-provider/useConfig.mjs';
import '../../_chunks/dep-095107f7.mjs';
import '../../_chunks/dep-c989dff3.mjs';
import '../../_chunks/dep-9cf86cf1.mjs';
import '../../_chunks/dep-bc1d737a.mjs';
import '../../_chunks/dep-4d7a675b.mjs';
import '../../_chunks/dep-2e7f59b1.mjs';
import '../../_chunks/dep-855db8bc.mjs';
import '../../_chunks/dep-a87f3e4c.mjs';
import '../../_chunks/dep-1e566bb5.mjs';
import '../../_chunks/dep-1434aa15.mjs';
import '../../_chunks/dep-b57180d0.mjs';
import '../../_chunks/dep-c8d7b6b4.mjs';
import '../../_chunks/dep-e5eb9f23.mjs';
import '../../_chunks/dep-9fe2ef12.mjs';
import '../../_chunks/dep-672e7d1a.mjs';
import '../../_chunks/dep-42a19209.mjs';
import '../../_chunks/dep-9262ee2f.mjs';
import '../../_chunks/dep-334a4f6b.mjs';
import '../../_chunks/dep-8d3e9aa3.mjs';
import '../../_chunks/dep-876fb3ec.mjs';
import '../../_chunks/dep-40d69a9c.mjs';
import '../../_chunks/dep-dcc83161.mjs';
import '../../_chunks/dep-0fc02184.mjs';
import '../../_chunks/dep-f1994936.mjs';
import '../../_chunks/dep-345e1be3.mjs';
import '../../_common/js/global-config/default-config.mjs';
import '../../_common/js/global-config/locale/zh_CN.mjs';
import '../../_chunks/dep-9888611c.mjs';
import '../../_chunks/dep-697a1365.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
