"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const PageContent_1 = require("../../../components/PageContent");
const FormPageLayoutBase_1 = require("../../FormPageLayoutBase");
const useLogic = () => {
    const footerRef = (0, react_1.useRef)(null);
    const updateStickyState = (0, react_1.useCallback)((container) => {
        if (!footerRef?.current) {
            return;
        }
        if (!container || !container.parentElement) {
            return;
        }
        if (container.scrollHeight > container.parentElement.clientHeight) {
            return footerRef.current.classList.add(FormPageLayoutBase_1.formPageLayoutClassnames.footerShadow);
        }
        footerRef.current.classList.remove(FormPageLayoutBase_1.formPageLayoutClassnames.footerShadow);
    }, []);
    (0, react_1.useEffect)(() => {
        const container = document.querySelector(`.${PageContent_1.pageContentClassnames.content}`);
        const rootContainer = document.querySelector(`.${PageContent_1.pageContentClassnames.pageContent}`);
        updateStickyState(container);
        if (!container) {
            return;
        }
        // ResizeObserver следит за изменением размеров контейнера
        const resizeObserver = new ResizeObserver(() => updateStickyState(container));
        resizeObserver.observe(container);
        if (rootContainer) {
            resizeObserver.observe(rootContainer);
        }
        return () => {
            resizeObserver.disconnect();
        };
    }, [updateStickyState]);
    return { footerRef };
};
exports.useLogic = useLogic;
