const STORAGE_KEY = "moqbox-theme"; /** Apply a theme to the document root and persist to localStorage. */ export function applyTheme(t: string): void { const root = document.documentElement; if (t === "latte") { root.setAttribute("data-theme", "latte"); root.style.colorScheme = "light"; } else if (t === "macchiato") { root.setAttribute("data-theme", "macchiato"); root.style.colorScheme = "dark"; } else { root.removeAttribute("data-theme"); root.style.colorScheme = "light dark"; } localStorage.setItem(STORAGE_KEY, t); } /** Cycle to the next theme: macchiato → latte → system → macchiato. */ export function cycleTheme(current: string): string { return current === "macchiato" ? "latte" : current === "latte" ? "system" : "macchiato"; } /** Get the stored theme, defaulting to "system". */ export function storedTheme(): string { return localStorage.getItem(STORAGE_KEY) || "system"; }