'use client';
import { useEffect } from 'react';
import { useTheme } from '../components/ThemeProvider.js';
import { appearanceApiToSnapshot } from '../lib/appearance-api.js';
import { cmsApi } from '../lib/api.js';
/**
 * Hydrate ThemeProvider from the DB-backed appearance settings as soon as the
 * admin shell mounts with a session. Without this, the sidebar only picks up
 * uploaded admin logos after visiting Settings → Appearance (which calls
 * applyAppearance on tab load).
 */
export function useAppearanceBootstrap(session) {
    const { applyAppearance } = useTheme();
    const active = Boolean(session);
    useEffect(() => {
        if (!active)
            return;
        let cancelled = false;
        const hydrate = async () => {
            try {
                const res = await cmsApi('/appearance');
                if (cancelled || res.error || !res.data)
                    return;
                applyAppearance(appearanceApiToSnapshot(res.data));
            }
            catch {
                /* keep localStorage / config fallbacks */
            }
        };
        void hydrate();
        return () => {
            cancelled = true;
        };
    }, [active, applyAppearance]);
}
//# sourceMappingURL=useAppearanceBootstrap.js.map