import { Group, Image, Select, Stack, Text } from '@mantine/core'; import { showNotification } from '@mantine/notifications'; import { forwardRef, useState } from 'react'; import { useTranslation } from 'next-i18next'; import { useRouter } from 'next/router'; import { getLanguageByCode, Language } from '../../languages/language'; export default function LanguageSwitch() { const { t, i18n } = useTranslation('settings/general/internationalization'); const { changeLanguage } = i18n; const { locale, locales } = useRouter(); const [selectedLanguage, setSelectedLanguage] = useState(locale); const data = locales ? locales.map((localeItem) => ({ value: localeItem, label: getLanguageByCode(localeItem).originalName, image: `imgs/flags/${localeItem}.png`, language: getLanguageByCode(localeItem), })) : []; const onChangeSelect = (value: string) => { setSelectedLanguage(value); const newLanguage = getLanguageByCode(value); changeLanguage(value) .then(() => { showNotification({ title: 'Language changed', message: `You changed the language to '${newLanguage.originalName}'`, color: 'green', autoClose: 5000, }); }) .catch((err) => { showNotification({ title: 'Failed to change language', message: `Failed to change to '${newLanguage.originalName}', Error:'${err}`, color: 'red', autoClose: 5000, }); }); }; return (