"use client"; import { useState, useRef, useEffect, useMemo, useId } from "react"; import { useTranslations } from 'next-intl'; import { useLocaleStore } from '@/stores/locale-store'; import { getEffectiveLocale } from '@/i18n/detect-locale'; import { Check, ChevronDown, Search } from '@/components/icons'; import { cn } from '@/lib/utils'; import { flagComponents } from './flag-icons'; const languages = [ { value: 'auto', label: 'Auto' }, { value: 'ar', label: 'العربية' }, { value: 'ca', label: 'Català' }, { value: 'cs', label: 'Česky' }, { value: 'sk', label: 'Slovenčina' }, { value: 'da', label: 'Dansk' }, { value: 'de', label: 'Deutsch' }, { value: 'en', label: 'English' }, { value: 'et', label: 'Eesti' }, { value: 'fa', label: 'فارسی' }, { value: 'es', label: 'Español' }, { value: 'fr', label: 'Français' }, { value: 'he', label: 'עברית' }, { value: 'it', label: 'Italiano' }, { value: 'hu', label: 'Magyar' }, { value: 'lv', label: 'Latviešu' }, { value: 'nl', label: 'Nederlands' }, { value: 'nb', label: 'Norsk bokmål' }, { value: 'pl', label: 'Polski' }, { value: 'pt', label: 'Português' }, { value: 'ro', label: 'Română' }, { value: 'tr', label: 'Türkçe' }, { value: 'ru', label: 'Русский' }, { value: 'uk', label: 'Українська' }, { value: 'ko', label: '한국어' }, { value: 'ja', label: '日本語' }, { value: 'mn', label: 'Монгол' }, { value: 'zh', label: '简体中文' }, { value: 'zh-TW', label: '繁體中文(台灣)' }, ]; // Case- and accent-insensitive, so "espanol" finds "Español". function fold(text: string): string { return text.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase(); } function displayNames(locale: string): ((code: string) => string | undefined) { try { const names = new Intl.DisplayNames([locale], { type: 'language' }); return (code) => names.of(code); } catch { return () => undefined; } } function FlagIcon({ locale }: { locale: string }) { const Flag = flagComponents[locale]; if (!Flag) return