import React , { FC , ReactElement , useContext , memo } from 'react' ; import { Select } from '@contentpi/ui' ; import { getCurrentLanguage , redirectTo } from '@contentpi/utils' ; import { getSelectLanguages } from '@contentpi/core' ; import { I18nContext } from '@contexts/i18n' ; import config from '@config' ; import { StyledLanguageSwitcher } from './LanguageSwitcher.styled' ; const LanguageSwitcher = ( ) : ReactElement => { const { t } = useContext ( I18nContext ) ; const currentLanguage = getCurrentLanguage ( ) ; const options = getSelectLanguages ( config . languages . list ) ; return ( < StyledLanguageSwitcher > < Select top = "160px" type = "white" name = "language" label = { t ( 'Select language' ) } onClick = { ( { value } ) : void => { if ( value && value !== currentLanguage ) { redirectTo ( '_self' , value ) ; } } } options = { options } / > < /StyledLanguageSwitcher>); } ; export default memo ( LanguageSwitcher ) ;