'use client';

/**
 * Shares one useSentinelData() instance across the shell + all section pages,
 * so the header's refresh re-stamps the clock and replays every screen's
 * entrance animations (via `cycle`), and Export uses the live snapshot. The
 * standalone /wall lives outside this provider and uses the hook directly.
 */
import { createContext, useContext } from 'react';
import { useSentinelData, type UseSentinelData } from '@/lib/executive/useSentinelData';

const Ctx = createContext<UseSentinelData | null>(null);

export function SentinelDataProvider({
    children,
    autoRefreshMs,
}: {
    children: React.ReactNode;
    autoRefreshMs?: number;
}) {
    const value = useSentinelData({ autoRefreshMs });
    return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
}

export function useSentinelContext(): UseSentinelData {
    const ctx = useContext(Ctx);
    if (!ctx) throw new Error('useSentinelContext must be used within <SentinelDataProvider>');
    return ctx;
}
