/**
 * useHermes — accessor for the HMR-safe runtime store on window.__hermes
 *
 * All state that must survive Vite HMR module re-evaluation lives here.
 * Initialized in main.ts (console hook), lazily created if accessed before main.ts runs.
 */

export interface HermesRuntime {
    // Console
    console: { t: number; l: string; m: string }[];
    _origConsole: Record<string, (...args: any[]) => void> | null;
    // WebSocket
    ws: WebSocket | null;
    wsPing: ReturnType<typeof setInterval> | null;
    wsCbs: ((data: any) => void)[];
    wsBuf: any[];
    wsConnected: any; // Ref<boolean>
    wsStatus: any;    // Ref<string>
    wsUser: any;      // Ref<string>
    wsSid: any;       // Ref<string | null>
    wsInit: any;      // Ref<boolean>
    // Capture
    captureStream: MediaStream | null;
}

export function useHermes(): HermesRuntime {
    const w = window as any;
    if (!w.__hermes) w.__hermes = {};
    return w.__hermes;
}
