"use client" import { useState, useRef, useEffect } from "react" import { useLocale } from "next-intl" import { useRouter } from "next/navigation" import { locales } from "@/i18n/config" const localeLabels: Record = { "zh-CN": "δΈ­", en: "EN", } function GlobeIcon({ className }: { className?: string }) { return ( ) } function ChevronDownIcon({ className }: { className?: string }) { return ( ) } export default function LocaleSwitcher() { const locale = useLocale() const router = useRouter() const [open, setOpen] = useState(false) const ref = useRef(null) useEffect(() => { function handleClickOutside(event: MouseEvent) { if (ref.current && !ref.current.contains(event.target as Node)) { setOpen(false) } } document.addEventListener("mousedown", handleClickOutside) return () => document.removeEventListener("mousedown", handleClickOutside) }, []) const otherLocale = locales.find((l) => l !== locale) if (!otherLocale) return null function setLocale(nextLocale: string) { document.cookie = `NEXT_LOCALE=${nextLocale}; path=/; max-age=31536000; samesite=lax` setOpen(false) router.refresh() } return (
{open && (
{locales.map((l) => ( ))}
)}
) }