import { useModel } from '@umijs/max';
import { ConfigProvider, theme } from 'antd';
import React from 'react';

interface ThemeProviderProps {
  children: React.ReactNode;
}

const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
  const { initialState } = useModel('@@initialState');
  const isDark = (initialState?.theme as 'light' | 'dark') === 'dark';

  return (
    <ConfigProvider
      theme={{
        algorithm: isDark ? theme.darkAlgorithm : theme.defaultAlgorithm,
      }}
    >
      {children}
    </ConfigProvider>
  );
};

export default ThemeProvider;
