import { ref, onMounted, onBeforeUnmount } from "vue";
function useDraggableScroll(containerRef) {
  const isDragging = ref(false);
  let startX, startY;
  let scrollLeft, scrollTop;
  const onMouseDown = (e) => {
    if (!containerRef.value) return;
    isDragging.value = true;
    startX = e.pageX;
    startY = e.pageY;
    scrollLeft = containerRef.value.scrollLeft;
    scrollTop = containerRef.value.scrollTop;
    document.addEventListener("mousemove", onMouseMove);
    document.addEventListener("mouseup", onMouseUp);
  };
  const onMouseMove = (e) => {
    if (!isDragging.value || !containerRef.value) return;
    const deltaX = e.pageX - startX;
    const deltaY = e.pageY - startY;
    containerRef.value.scrollLeft = scrollLeft - deltaX;
    containerRef.value.scrollTop = scrollTop - deltaY;
  };
  const onMouseUp = () => {
    isDragging.value = false;
    document.removeEventListener("mousemove", onMouseMove);
    document.removeEventListener("mouseup", onMouseUp);
  };
  onMounted(() => {
    var _a;
    (_a = containerRef.value) == null ? void 0 : _a.addEventListener("mousedown", onMouseDown);
  });
  onBeforeUnmount(() => {
    var _a;
    (_a = containerRef.value) == null ? void 0 : _a.removeEventListener("mousedown", onMouseDown);
  });
  return {
    isDragging
  };
}
export {
  useDraggableScroll
};
