'use client' import { useState, useRef, useEffect } from 'react' import { useLocale } from 'next-intl' import { locales, localeNames, type Locale } from '@/i18n/config' import { Button } from '@/components/ui/button' function setLocaleCookie(locale: Locale) { document.cookie = `NEXT_LOCALE=${locale};path=/;max-age=31536000;SameSite=None;Secure` window.location.reload() } /** Popover-style language switcher for the header bar */ export function LanguageSwitcher() { const currentLocale = useLocale() as Locale const [open, setOpen] = useState(false) const ref = useRef(null) // Close on outside click useEffect(() => { if (!open) return const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false) } } document.addEventListener('mousedown', handler) return () => document.removeEventListener('mousedown', handler) }, [open]) return (
{open && ( <>
setOpen(false)} />
{locales.map((loc) => ( ))}
)}
) } /** Native select variant for settings panel and login page */ export function LanguageSwitcherSelect() { const currentLocale = useLocale() as Locale return ( ) } function GlobeIcon() { return ( ) }