// 主题类型定义
export const ThemeTypes = {
  LIGHT: 'light',
  DARK: 'dark',
  CUSTOM: 'custom'
};

// 应用主题到整个应用
export const applyGlobalTheme = (theme) => {
  const html = document.documentElement;
  
  // 移除所有主题类
  Object.values(ThemeTypes).forEach(type => {
    html.classList.remove(`theme-${type}`);
  });
  
  // 添加当前主题类
  html.classList.add(`theme-${theme}`);
};

// 初始化主题
export const initTheme = () => {
  const savedTheme = localStorage.getItem('app_theme');
  const defaultTheme = ThemeTypes.LIGHT;
  const themeToApply = savedTheme || defaultTheme;
  
  applyGlobalTheme(themeToApply);
  return themeToApply;
};

// 切换主题
export const switchTheme = (theme) => {
  if (!Object.values(ThemeTypes).includes(theme)) {
    console.warn('无效的主题类型');
    return;
  }
  
  applyGlobalTheme(theme);
  localStorage.setItem('app_theme', theme);
  return theme;
};
