import { useEffect, useState } from 'react' import useTranslation from 'next-translate/useTranslation' import setLanguage from 'next-translate/setLanguage' import { Arrow } from './Arrow' import { languages, Language as LanguageType } from 'utils/authentication' import { LanguageFlag } from './LanguageFlag' export const Language: React.FC = () => { const { lang: currentLanguage } = useTranslation() const [hiddenMenu, setHiddenMenu] = useState(true) useEffect(() => { if (!hiddenMenu) { window.document.addEventListener('click', handleHiddenMenu) } else { window.document.removeEventListener('click', handleHiddenMenu) } return () => { window.document.removeEventListener('click', handleHiddenMenu) } }, [hiddenMenu]) const handleLanguage = async (language: LanguageType): Promise => { await setLanguage(language) handleHiddenMenu() } const handleHiddenMenu = (): void => { setHiddenMenu(!hiddenMenu) } return ( <>
{!hiddenMenu && ( )}
) }