export const themeCookie = 'hpc-theme';
export const themeStorageKey = 'hpc.theme.preference';
export const themePreferences = ['light', 'dark', 'system'] as const;
export type ThemePreference = (typeof themePreferences)[number];
export type ResolvedTheme = 'light' | 'dark';

export const themeCookieMaxAgeSeconds = 31_536_000;

export function isThemePreference(value: unknown): value is ThemePreference {
  return typeof value === 'string' && (themePreferences as readonly string[]).includes(value);
}

export function resolveTheme(preference: ThemePreference, systemDark: boolean): ResolvedTheme {
  return preference === 'system' ? (systemDark ? 'dark' : 'light') : preference;
}

export function serverResolvedTheme(preference: ThemePreference): ResolvedTheme {
  return preference === 'dark' ? 'dark' : 'light';
}
