/**
 * Warm-start snapshot for the Event Log page.
 *
 * The events page can't use the standard resource cache (`caches.ts`) because
 * its list is paginated, mutated by live SSE pushes, and edited by deletes —
 * far more than a fetch-and-replace list. Instead it keeps working in local
 * component state and mirrors the latest list/stats here. On revisit the page
 * seeds from this snapshot so it paints the last-known events immediately
 * instead of flashing a skeleton, then refreshes in the background.
 *
 * Module-scoped (survives navigation, cleared on logout via `resetAllCaches`).
 */

import type { EventLogEntry, EventLogStats } from '$lib/types';

export interface EventsSnapshot {
	events: EventLogEntry[];
	stats: EventLogStats;
}

let snapshot: EventsSnapshot | null = null;

export function getEventsSnapshot(): EventsSnapshot | null {
	return snapshot;
}

export function saveEventsSnapshot(s: EventsSnapshot): void {
	snapshot = s;
}

export function clearEventsSnapshot(): void {
	snapshot = null;
}
