import { __assign } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useCallback, useEffect, useRef } from 'react';
import { WindowEventHandler } from './WindowEventHandler';
import { useRunOnceInNextFrame } from '../nextFrame';
var OPTIONS = {
    passive: true,
};
export var WindowScrollHandler = function (_a) {
    var _b = _a.disableThrottle, disableThrottle = _b === void 0 ? false : _b, options = _a.options, onScrollProp = _a.onScroll;
    var cb = useRef(onScrollProp);
    cb.current = onScrollProp;
    var onScrollCallback = useCallback(function (evt) {
        cb.current(evt);
    }, []);
    var onScroll = useRunOnceInNextFrame(onScrollCallback, disableThrottle);
    useEffect(function () {
        return onScroll.cancel;
    }, [onScroll]);
    return (_jsx(WindowEventHandler, { eventName: "scroll", listener: onScroll, options: __assign(__assign({}, OPTIONS), options) }, void 0));
};
