import React, { PropsWithChildren, useEffect, useMemo, useState } from 'react' import Themes from '../themes' import { HuiThemes } from '../themes/presets' import { ThemeContext } from '../use-theme/theme-context' import { AllThemesConfig, AllThemesContext } from '../use-all-themes/all-themes-context' export interface Props { themeType?: string themes?: Array } const ThemeProvider: React.FC> = ({ children, themeType, themes = [] }) => { const [allThemes, setAllThemes] = useState({ themes: Themes.getPresets() }) const currentTheme = useMemo(() => { const theme = allThemes.themes.find((item) => item.type === themeType) if (theme) return theme return Themes.getPresetStaticTheme() }, [allThemes, themeType]) useEffect(() => { if (!themes?.length) return setAllThemes((last) => { const safeThemes = themes.filter((item) => Themes.isAvailableThemeType(item.type)) const nextThemes = Themes.getPresets().concat(safeThemes) return { ...last, themes: nextThemes } }) }, [themes]) return ( {children} ) } export default ThemeProvider