"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useState, useEffect } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { Menu, X, Sparkles } from "lucide-react"; // import { Button } from "@/components/ui/button"; // TODO: Uncomment when adding login/register buttons import { LanguageSwitcher } from "./LanguageSwitcher"; import { useTranslation, getServerTranslations } from "@/lib/i18n"; import { cn } from "@/lib/utils"; function useNavItems() { const { t } = useTranslation(); return [ { name: t("nav.tools"), href: "/tools/image-compress" }, { name: t("nav.pricing"), href: "/tools/video-frames" }, { name: t("nav.docs"), href: "/tools/audio-compress" }, // Note: Temporarily redirecting to existing tool pages // TODO: Create dedicated pages for pricing, docs, about ]; } export function Header() { const pathname = usePathname(); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); const [mounted, setMounted] = useState(false); const navItems = useNavItems(); const { t, locale, setLocale } = useTranslation(); useEffect(() => { setMounted(true); // Auto detect language on first mount if not manually set const stored = localStorage.getItem("locale-storage"); if (!stored) { const lang = navigator.language.toLowerCase(); if (lang.includes("zh")) { setLocale("zh"); } } }, [setLocale]); useEffect(() => { if (mounted) { document.documentElement.lang = locale; } }, [locale, mounted]); // Prevent hydration mismatch by rendering a stable version initially const displayT = (key: string, params?: any) => { if (!mounted) return getServerTranslations("en").t(key, params); return t(key, params); }; const currentNavItems = mounted ? navItems : [ { name: "Tools", href: "/tools/image-compress" }, { name: "Pricing", href: "/tools/video-frames" }, { name: "Docs", href: "/tools/audio-compress" }, ]; return (
{/* Mobile Menu */} {isMobileMenuOpen && (
{currentNavItems.map((item) => ( setIsMobileMenuOpen(false)} className={cn( "block text-sm font-medium transition-colors hover:text-primary", pathname === item.href ? "text-primary" : "text-muted-foreground" )} > {item.name} ))}
{mounted && } {/* TODO: Create login/register pages */}
)}
); }