import { useEffect, useRef } from 'react';
import { useShellStore, useWithoutShellParam } from '../stores/shellStore';
/**
 * Controls shell visibility based on layout flags, user presence, and route metadata.
 * Returns the effective hidden state that callers should use for rendering.
 */
export const useShellVisibility = ({ hideLayout, isPublicRoute, hasUser }) => {
    const { shellHidden, setShellHidden } = useShellStore();
    const shellHiddenBaselineRef = useRef();
    const withoutShell = useWithoutShellParam();
    const syncShellHiddenWithRouteState = () => {
        const shouldForceHideShell = hideLayout || isPublicRoute || !hasUser || withoutShell;
        if (shouldForceHideShell) {
            if (shellHiddenBaselineRef.current === undefined) {
                shellHiddenBaselineRef.current = shellHidden;
            }
            if (!shellHidden) {
                setShellHidden(true);
            }
        }
        else if (shellHiddenBaselineRef.current !== undefined) {
            if (shellHidden !== shellHiddenBaselineRef.current) {
                setShellHidden(shellHiddenBaselineRef.current);
            }
            else {
                setShellHidden(false);
            }
            shellHiddenBaselineRef.current = undefined;
        }
        else if (shellHidden) {
            setShellHidden(false);
        }
    };
    useEffect(syncShellHiddenWithRouteState, [
        hideLayout,
        isPublicRoute,
        hasUser,
        withoutShell,
        setShellHidden,
        shellHidden
    ]);
    return shellHidden || hideLayout || isPublicRoute || !hasUser || withoutShell;
};
//# sourceMappingURL=useShellVisibility.js.map