import React, { useMemo } from 'react' import { Button, useTheme, Select, Spacer } from 'components' import { useConfigs } from 'lib/config-context' import useLocale from 'lib/use-locale' import Router, { useRouter } from 'next/router' import MoonIcon from './icons/moon' import SunIcon from './icons/sun' const Controls: React.FC<{}> = React.memo(({ }) => { const theme = useTheme() const { updateCustomTheme, updateChineseState } = useConfigs() const { pathname } = useRouter() const { locale } = useLocale() const isChinese = useMemo(() => locale === 'zh-cn', [locale]) const isDark = useMemo(() => theme.type === 'dark', [theme.type]) const nextLocalePath = useMemo(() => { const nextLocale = isChinese ? 'en-us' : 'zh-cn' return pathname.replace(locale, nextLocale) }, [locale, pathname]) const switchThemes = (type: 'dark' | 'light') => { updateCustomTheme({ type }) } const switchLanguages = () => { updateChineseState(!isChinese) Router.push(nextLocalePath) } const redirectGithub = () => { if (typeof window !== 'undefined') { window.open('https://github.com/zeit-ui/react') } } return (
) }) export default Controls