import { localeType } from '@/provider/i18n' import { Dialog, DialogBody, DialogHeader, Input, Option, Radio, Select, Typography } from '@material-tailwind/react' import { ChangeEvent, useEffect, useState } from 'react' import { FormattedMessage } from 'react-intl' type Props = { opened: boolean close: () => void reloadSettings: () => void } const languages = [ { label: 'English', value: 'en' }, { label: '日本語', value: 'ja' }, { label: 'Português', value: 'pt-PT' }, { label: '繁体字', value: 'zh-TW' }, { label: 'español', value: 'es-ES' } ] const themes = [ { label: 'Blue', value: 'theme-blue' }, { label: 'Orange', value: 'theme-orange' }, { label: 'Purple', value: 'theme-purple' }, { label: 'Green', value: 'theme-green' }, { label: 'Brown', value: 'theme-brown' }, { label: 'Gray', value: 'theme-gray' } ] export default function Settings(props: Props) { const [language, setLanguage] = useState('en') const [fontSize, setFontSize] = useState(16) const [theme, setTheme] = useState('theme-blue') const [isDark, setIsDark] = useState(false) useEffect(() => { if (typeof localStorage !== 'undefined') { const lang = localStorage.getItem('language') if (lang) { setLanguage(lang as localeType) } else { setLanguage('en') } const dark = localStorage.getItem('color-mode') if (dark === 'dark') { setIsDark(true) } else { setIsDark(false) } } }, []) const languageChanged = (e: string) => { setLanguage(e as localeType) if (typeof localStorage !== 'undefined') { localStorage.setItem('language', e) } props.reloadSettings() } const fontSizeChanged = (e: ChangeEvent) => { setFontSize(parseInt(e.target.value)) if (typeof localStorage !== 'undefined') { localStorage.setItem('fontSize', e.target.value) } props.reloadSettings() } const themeChanged = (e: string) => { setTheme(e) if (typeof localStorage !== 'undefined') { localStorage.setItem('theme', e) } props.reloadSettings() } const modeChanged = (isDark: boolean) => { setIsDark(isDark) if (typeof localStorage !== 'undefined') { if (isDark) { localStorage.setItem('color-mode', 'dark') } else { localStorage.setItem('color-mode', 'light') } } props.reloadSettings() } return (
} onClick={() => modeChanged(true)} defaultChecked={isDark} /> } onClick={() => modeChanged(false)} defaultChecked={!isDark} />
) }