// (Tech support with -4 hours of sleep and 6th mug of coffee) Uhm, sir, have you tried turning it off and on again? // Oh. // Oh... import { type ScreenName, setCurrentScreen } from "./state.js"; import { clear, hideTooltip } from "./ui.js"; export type ScreenRenderer = ( appEl: HTMLElement, params: Record, ) => (() => void) | void; const appEl = document.getElementById("app") as HTMLElement; let activeCleanup: (() => void) | null = null; let screenRenderers: Partial> = {}; const RIGHT_SIDEBAR_OFFSET_PX: Partial> = { dashboard: 370, builder: 440, config: 440, worldMap: 340, }; export function registerScreenRenderers( renderers: Partial>, ): void { screenRenderers = renderers; } export function navigate( screen: ScreenName, params: Record = {}, ): void { if (activeCleanup) { try { activeCleanup(); } catch (err) { console.warn("Cleanup error:", err); } activeCleanup = null; } setCurrentScreen(screen); const sidebarOffset = RIGHT_SIDEBAR_OFFSET_PX[screen] ?? 0; document.documentElement.style.setProperty( "--right-sidebar-offset", `${sidebarOffset}px`, ); document.documentElement.classList.toggle( "has-right-sidebar", sidebarOffset > 0, ); clear(appEl); hideTooltip(); const cleanup = screenRenderers[screen]?.(appEl, params); if (typeof cleanup === "function") { activeCleanup = cleanup; } }