import { useCallback, useEffect, useRef } from 'react';
import { pageContentClassnames } from '../../../components/PageContent';
import { formPageLayoutClassnames } from '../../FormPageLayoutBase';
export const useLogic = () => {
    const footerRef = useRef(null);
    const updateStickyState = useCallback((container) => {
        if (!footerRef?.current) {
            return;
        }
        if (!container || !container.parentElement) {
            return;
        }
        if (container.scrollHeight > container.parentElement.clientHeight) {
            return footerRef.current.classList.add(formPageLayoutClassnames.footerShadow);
        }
        footerRef.current.classList.remove(formPageLayoutClassnames.footerShadow);
    }, []);
    useEffect(() => {
        const container = document.querySelector(`.${pageContentClassnames.content}`);
        const rootContainer = document.querySelector(`.${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 };
};
