"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "useDragScroll", {
    enumerable: true,
    get: function() {
        return useDragScroll;
    }
});
const _react = require("react");
const SCROLL_SPEED = 2;
const useDragScroll = (scrollRef, isDragScrollDisabled)=>{
    const [isDragging, setDragging] = (0, _react.useState)(false);
    const [startX, setStartX] = (0, _react.useState)(0);
    const [scrollLeft, setScrollLeft] = (0, _react.useState)(0);
    const handleMouseMove = (0, _react.useCallback)((e)=>{
        if (isDragging && scrollRef && scrollRef.current) {
            const dx = (e.clientX - startX) * SCROLL_SPEED;
            scrollRef.current.scrollLeft = scrollLeft - dx;
        }
    }, [
        scrollRef,
        scrollLeft,
        isDragging,
        startX
    ]);
    const handleMouseUp = (0, _react.useCallback)(()=>{
        setDragging(false);
        if (scrollRef && scrollRef.current) {
            scrollRef.current.style.cursor = 'grab';
        }
    }, [
        scrollRef,
        setDragging
    ]);
    const handleMouseDown = (0, _react.useCallback)((e)=>{
        setDragging(true);
        if (scrollRef && scrollRef.current) {
            setStartX(e.clientX);
            setScrollLeft(scrollRef.current.scrollLeft);
            scrollRef.current.style.cursor = 'grabbing';
        }
    }, [
        scrollRef,
        setDragging,
        setStartX,
        setScrollLeft,
        handleMouseUp,
        handleMouseMove
    ]);
    (0, _react.useEffect)(()=>{
        if (scrollRef && scrollRef.current && !isDragScrollDisabled) {
            scrollRef.current.style.userSelect = 'none';
            scrollRef.current.addEventListener('mousedown', handleMouseDown);
            scrollRef.current.addEventListener('mouseup', handleMouseUp);
            scrollRef.current.addEventListener('mouseleave', handleMouseUp);
            scrollRef.current.addEventListener('mousemove', handleMouseMove);
        }
        return ()=>{
            if (scrollRef && scrollRef.current && !isDragScrollDisabled) {
                scrollRef.current.removeEventListener('mousedown', handleMouseDown);
                scrollRef.current.removeEventListener('mouseup', handleMouseUp);
                scrollRef.current.removeEventListener('mouseleave', handleMouseUp);
                scrollRef.current.removeEventListener('mousemove', handleMouseMove);
            }
        };
    }, [
        scrollRef,
        handleMouseDown,
        handleMouseUp,
        handleMouseMove,
        isDragScrollDisabled
    ]);
};
