export type KbxThemeMode = 'light' | 'dark'

export const KBX_THEME_MODES: readonly KbxThemeMode[] = ['light', 'dark'] as const

export function normalizeKbxThemeMode(value: unknown): KbxThemeMode {
  return value === 'dark' ? 'dark' : 'light'
}

export function applyKbxTheme(mode: KbxThemeMode, root: HTMLElement = document.documentElement) {
  const normalized = normalizeKbxThemeMode(mode)
  root.dataset.kbxTheme = normalized
  root.style.colorScheme = normalized
  return normalized
}

export function nextKbxThemeMode(mode: KbxThemeMode): KbxThemeMode {
  return mode === 'dark' ? 'light' : 'dark'
}
