"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useStickyButton = void 0;
const react_1 = require("react");
const useToggle_1 = require("../useToggle");
/**
 * Управление кнопкой "наверх"
 */
const useStickyButton = (scrollRef) => {
    const virtuoso = (0, react_1.useRef)(null);
    const [isStickyButtonActive, showStickyButton, hideStickyButton] = (0, useToggle_1.useToggle)();
    const handleRangeChanged = (0, react_1.useCallback)((range) => {
        const shouldShow = range.startIndex > 2;
        if (isStickyButtonActive !== shouldShow) {
            shouldShow ? showStickyButton() : hideStickyButton();
        }
    }, [showStickyButton, hideStickyButton]);
    const handleScrollToTop = () => {
        scrollRef.current.style.scrollBehavior = 'auto';
        virtuoso.current?.scrollToIndex(0);
    };
    return {
        virtuoso,
        isStickyButtonActive,
        handleRangeChanged,
        handleScrollToTop,
    };
};
exports.useStickyButton = useStickyButton;
