import { ReactNode, useMemo } from 'react';
import { ConfigProvider, theme } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import { useThemeStore } from '../stores/themeStore';
import { getThemeByMode } from '../theme';

interface ThemeProviderProps {
  children: ReactNode;
}

// 主题提供者组件
export const ThemeProvider = ({ children }: ThemeProviderProps) => {
  const { themeMode } = useThemeStore();

  // 根据主题模式获取主题配置和算法
  const currentTheme = useMemo(() => {
    const customTheme = getThemeByMode(themeMode);
    const algorithm = themeMode === 'dark' ? theme.darkAlgorithm : theme.defaultAlgorithm;
    
    return {
      algorithm,
      ...customTheme,
    };
  }, [themeMode]);

  return (
    <ConfigProvider 
      locale={zhCN} 
      theme={currentTheme}
    >
      {children}
    </ConfigProvider>
  );
};
