import variables from 'config/variables'; import { useState } from 'react'; import { MdAutoAwesome, MdLightMode, MdDarkMode } from 'react-icons/md'; import { loadSettings } from 'utils/settings'; import { Header, Content } from '../Layout'; const THEMES = { AUTO: 'auto', LIGHT: 'light', DARK: 'dark', }; function ThemeSelection() { const currentTheme = localStorage.getItem('theme') || THEMES.AUTO; const [theme, setTheme] = useState(currentTheme); const changeTheme = (type) => { setTheme(type); localStorage.setItem('theme', type); loadSettings(true); }; const themeMapping = { [THEMES.AUTO]: { className: theme === THEMES.AUTO ? 'toggle auto active' : 'toggle auto', icon: , text: variables.getMessage('modals.main.settings.sections.appearance.theme.auto'), }, [THEMES.LIGHT]: { className: theme === THEMES.LIGHT ? 'toggle lightTheme active' : 'toggle lightTheme', icon: , text: variables.getMessage('modals.main.settings.sections.appearance.theme.light'), }, [THEMES.DARK]: { className: theme === THEMES.DARK ? 'toggle darkTheme active' : 'toggle darkTheme', icon: , text: variables.getMessage('modals.main.settings.sections.appearance.theme.dark'), }, }; return (
changeTheme(THEMES.AUTO)} > {themeMapping[THEMES.AUTO].icon} {themeMapping[THEMES.AUTO].text}
{Object.entries(themeMapping) .filter(([type]) => type !== THEMES.AUTO) .map(([type, { className, icon, text }]) => (
changeTheme(type)} key={type}> {icon} {text}
))}
{variables.getMessage('modals.welcome.tip')} {variables.getMessage('modals.welcome.sections.theme.tip')} ); } export { ThemeSelection as default, ThemeSelection };