const STORAGE_KEY = "lab-theme-prefs"

export interface LocalThemePrefs {
  colorTheme?: string
  tweakcnTheme?: string
  radius?: string
  sidebarVariant?: string
  sidebarCollapsible?: string
  sidebarSide?: string
}

export function getLocalThemePrefs(): LocalThemePrefs {
  if (typeof window === "undefined") return {}
  try {
    const raw = localStorage.getItem(STORAGE_KEY)
    return raw ? (JSON.parse(raw) as LocalThemePrefs) : {}
  } catch {
    return {}
  }
}

export function saveLocalThemePrefs(update: Partial<LocalThemePrefs>): void {
  if (typeof window === "undefined") return
  try {
    const existing = getLocalThemePrefs()
    localStorage.setItem(STORAGE_KEY, JSON.stringify({ ...existing, ...update }))
  } catch {}
}
