import { parseScreenPaneHabit, type ScreenPaneHabit } from "@rakazo/core"; function screenHabitKey(userId: string | null | undefined, botId: string | null | undefined) { if (!userId || !botId) return null; return `rakazo:screen-pane:${userId}:${botId}`; } export function readScreenPaneHabit( userId: string | null | undefined, botId: string | null | undefined, ): ScreenPaneHabit { const key = screenHabitKey(userId, botId); if (!key) return 0; try { return parseScreenPaneHabit(window.localStorage.getItem(key)); } catch { return 0; } } export function writeScreenPaneHabit( userId: string | null | undefined, botId: string | null | undefined, habit: ScreenPaneHabit, ): void { const key = screenHabitKey(userId, botId); if (!key) return; try { if (habit === 0) window.localStorage.removeItem(key); else window.localStorage.setItem(key, String(habit)); } catch { // Private mode or a full quota only loses the learned default. } } export function readPaneWidth(storageKey: string, fallback: number, min: number, max: number) { try { const stored = Number(window.localStorage.getItem(storageKey)); if (Number.isFinite(stored) && stored > 0) return Math.max(min, Math.min(max, stored)); } catch { // Fall through to the default width. } return fallback; } export function writePaneWidth(storageKey: string, width: number): void { try { window.localStorage.setItem(storageKey, String(Math.round(width))); } catch { // The width still applies for this session. } }