import { Menu, UnstyledButton, Text, rem } from '@mantine/core'; import { IconWorld, IconCheck, IconChevronDown } from '@tabler/icons-react'; import { useTranslation } from 'react-i18next'; interface LanguageSwitcherProps { supportedLanguages: readonly string[]; /** `icon` renders a compact globe button; `button` shows the language label. */ variant?: 'icon' | 'button'; } export function LanguageSwitcher({ supportedLanguages, variant = 'icon' }: LanguageSwitcherProps) { const { t, i18n } = useTranslation(); const current = i18n.language; const change = (lng: string) => { if (lng !== current) i18n.changeLanguage(lng); }; return ( { e.currentTarget.style.background = 'var(--mantine-primary-color-light)'; e.currentTarget.style.color = 'var(--mantine-primary-color-6)'; e.currentTarget.style.boxShadow = '0 1px 3px rgba(0,0,0,0.04), 0 0 0 1px var(--mantine-primary-color-2)'; }} onMouseLeave={(e) => { e.currentTarget.style.background = 'var(--mantine-color-body)'; e.currentTarget.style.color = 'var(--mantine-color-gray-6)'; e.currentTarget.style.boxShadow = '0 1px 3px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.06)'; }} > {variant !== 'icon' && ( <> {t(`language.${current}`)} )} {t('language.label')} {supportedLanguages.map((lng) => ( change(lng)} rightSection={ current === lng ? : undefined } style={{ borderRadius: rem(8) }} > {t(`language.${lng}`)} ))} ); }