"use client"; import { useState, useEffect, useRef, useCallback } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { Volume2, VolumeX, Trophy, Star, Award, ShoppingBag } from "lucide-react"; import { useSound } from "@/hooks/useSound"; import { getStoredPlayer } from "@/lib/player-store"; import { getPlayerStarCoins } from "@/lib/supabase/queries"; import { useCosmeticContext } from "@/components/cosmetics/CosmeticProvider"; /** * Fixed top navigation header for Triviaverse. * Shows the logo (links to home), optionally displays the player name, * coin balance, trophy room link, shop link, a Leaderboard nav link, * and a mute/unmute toggle when showNav is true. */ interface HeaderProps { playerName?: string; showNav?: boolean; } export function Header({ playerName, showNav = true }: HeaderProps) { const { muted, toggleMute, play } = useSound(); const router = useRouter(); const [coins, setCoins] = useState(null); const { equipped } = useCosmeticContext(); const hasTitleEffect = equipped.title_effect !== null; // Easter egg: triple-click logo within 1.5s → /admin const clickCountRef = useRef(0); const clickTimerRef = useRef | null>(null); const handleLogoClick = useCallback((e: React.MouseEvent) => { e.preventDefault(); clickCountRef.current += 1; if (clickTimerRef.current) clearTimeout(clickTimerRef.current); if (clickCountRef.current >= 3) { clickCountRef.current = 0; router.push("/admin"); return; } clickTimerRef.current = setTimeout(() => { if (clickCountRef.current === 1) router.push("/"); clickCountRef.current = 0; }, 400); }, [router]); // Easter egg: TRIVIAMASTER name flag const [isMaster] = useState( () => typeof window !== "undefined" && localStorage.getItem("triviamaster_unlocked") === "1", ); useEffect(() => { const player = getStoredPlayer(); if (player?.id) { getPlayerStarCoins(player.id).then(setCoins); } }, []); return (
{/* Logo — single click goes to /, triple-click goes to /admin */} {/* Right section */} {showNav && ( )}
); }