"use client"; import { useCallback, useEffect, useRef, useState } from "react"; import { useLocale } from "~/components/locale-provider"; import type { Locale } from "~/lib/i18n"; const OPTIONS: { value: Locale; label: string }[] = [ { value: "zh", label: "中文" }, { value: "en", label: "English" }, ]; const UNLOCK_CLICKS = 5; const CLICK_WINDOW_MS = 2500; const UNLOCK_KEY = "nomadro-lang-unlock"; export function LanguageSwitcher({ className = "" }: { className?: string }) { const { locale, setLocale, t } = useLocale(); const [visible, setVisible] = useState(false); const clicksRef = useRef(0); const timerRef = useRef | null>(null); useEffect(() => { try { if (window.sessionStorage.getItem(UNLOCK_KEY) === "1") { setVisible(true); } } catch { // ignore } }, []); const handleSecretClick = useCallback(() => { if (visible) return; clicksRef.current += 1; if (timerRef.current) clearTimeout(timerRef.current); timerRef.current = setTimeout(() => { clicksRef.current = 0; }, CLICK_WINDOW_MS); if (clicksRef.current >= UNLOCK_CLICKS) { clicksRef.current = 0; if (timerRef.current) clearTimeout(timerRef.current); setVisible(true); try { window.sessionStorage.setItem(UNLOCK_KEY, "1"); } catch { // ignore } } }, [visible]); return (
{/* Invisible hit area — tap 5 times to reveal */}
); }