"use client"; import * as React from "react"; import { Moon, Sun } from "lucide-react"; import { useTheme } from "next-themes"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; /** * TopNav - A responsive navigation header component with theme switching functionality * Features: * - Colorful brand logo/text * - Navigation links for teachers and students * - Theme switcher (light/dark/system) with animated icons * - Client-side hydration handling */ export function TopNav() { const { setTheme } = useTheme(); // Track component mounting to prevent hydration mismatch const [mounted, setMounted] = React.useState(false); // Enable theme switching only after client-side hydration React.useEffect(() => { setMounted(true); }, []); // Pre-hydration render - shows a simplified version without theme toggle if (!mounted) { return (
P l a y G o A I
{" "} {/* Placeholder maintaining layout consistency during hydration */}
); } // Post-hydration render - includes full functionality with theme toggle return (
{/* Brand logo with multi-colored letters */} P l a y G o A I {/* Navigation links with language-specific text (Traditional Chinese) */} {/* Theme switcher dropdown with animated sun/moon icons */} {/* Theme selection menu */} setTheme("light")}> Light setTheme("dark")}> Dark setTheme("system")}> System
); }