"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const DashboardContext_1 = require("../../../DashboardContext");
const constants_1 = require("../../../PageContent/constants");
const useLogic = () => {
    const { isFocusedMode, setAlertElement } = (0, react_1.useContext)(DashboardContext_1.DashboardContext);
    const prevFocusedModeRef = (0, react_1.useRef)(isFocusedMode);
    const alertContainerRef = (0, react_1.useRef)(null);
    const elementRef = (0, react_1.useRef)(null);
    (0, react_1.useEffect)(() => {
        setAlertElement?.(alertContainerRef.current ?? null);
        return () => setAlertElement?.(null);
    }, [setAlertElement]);
    (0, react_1.useEffect)(() => {
        if (isFocusedMode || (prevFocusedModeRef.current && !isFocusedMode)) {
            elementRef.current = document.querySelector(`.${constants_1.pageContentClassnames.pageContent}`);
            elementRef.current?.classList.add(constants_1.pageContentClassnames.animation);
        }
    }, [isFocusedMode]);
    const onAnimationEnd = (event) => {
        if (event.animationName === constants_1.PAGE_CONTENT_ANIMATION) {
            elementRef.current?.classList.remove(constants_1.pageContentClassnames.animation);
            prevFocusedModeRef.current = isFocusedMode;
        }
    };
    return { onAnimationEnd, alertContainerRef };
};
exports.useLogic = useLogic;
