import { useCallback, useEffect, useRef, useState } from "react";
const EVENT_START_POLL_INTERVAL = 150;
function useScrollCapture() {
    const ref = useRef(null);
    const [captureScroll, setCaptureScroll] = useState(false);
    const wheelActiveRef = useRef(false);
    const wheelTimeoutRef = useRef(null);
    useEffect(()=>{
        const onWheel = ()=>{
            wheelActiveRef.current = true;
            if (wheelTimeoutRef.current) clearTimeout(wheelTimeoutRef.current);
            wheelTimeoutRef.current = setTimeout(()=>{
                wheelActiveRef.current = false;
            }, EVENT_START_POLL_INTERVAL);
        };
        window.addEventListener('wheel', onWheel, {
            passive: true
        });
        return ()=>window.removeEventListener('wheel', onWheel);
    }, []);
    const onMouseEnter = useCallback(()=>{
        if (wheelActiveRef.current) return;
        const el = ref.current;
        if (el && el.scrollHeight > el.clientHeight) setCaptureScroll(true);
    }, []);
    const onMouseLeave = useCallback(()=>{
        setCaptureScroll(false);
    }, []);
    return {
        ref,
        scrollCaptureProps: {
            className: captureScroll ? 'nowheel' : void 0,
            onMouseEnter,
            onMouseLeave
        }
    };
}
export { useScrollCapture };
