export type ThemeName = 'dark-monokai' | 'light';

export function setTheme(theme: ThemeName) {
  const link = document.getElementById('theme-css') as HTMLLinkElement | null;
  if (link) {
    link.href = theme === 'dark-monokai' ? '/themes/theme-dark-monokai.css' : '/themes/theme-light.css';
  }
  document.documentElement.dataset.theme = theme;
}

export function initTheme() {
  const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
  const fallback: ThemeName = prefersDark ? 'dark-monokai' : 'light';
  setTheme(fallback);
  return fallback;
}
