"use client"; import { AnimatePresence, motion, useReducedMotion } from "framer-motion"; import { LayoutDashboard, Menu, X } from "lucide-react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useLocale, useTranslations } from "next-intl"; import { useEffect, useRef, useState } from "react"; import { toast } from "sonner"; import { Container } from "@/components/layout/container"; import { LocaleToggle } from "@/components/layout/locale-toggle"; import { SiteLogo } from "@/components/layout/site-logo"; import { SoundToggle } from "@/components/sound-toggle"; import { ThemeToggle } from "@/components/theme-toggle"; import { Button } from "@/components/ui/button"; import { getLocalizedPath, stripLocalePrefix } from "@/lib/locale"; import { cn } from "@/lib/utils"; const navItems = [ { key: "home", path: "" }, { key: "portfolio", path: "/portfolio" }, { key: "products", path: "/products" }, { key: "about", path: "/about" }, { key: "contact", path: "/contact" }, ]; type SiteHeaderProps = { isAdmin?: boolean; lightLogoUrl?: string | null; darkLogoUrl?: string | null; }; function getDirectionalReveal(direction: "rtl" | "ltr") { return direction === "rtl" ? { initial: { opacity: 0, x: -16, clipPath: "inset(0 0 0 100%)", filter: "blur(10px)" }, animate: { opacity: 1, x: 0, y: 0, clipPath: "inset(0 0 0 0)", filter: "blur(0px)" }, } : { initial: { opacity: 0, x: 16, clipPath: "inset(0 100% 0 0)", filter: "blur(10px)" }, animate: { opacity: 1, x: 0, y: 0, clipPath: "inset(0 0 0 0)", filter: "blur(0px)" }, }; } function isNavItemActive(currentPath: string, itemPath: string) { if (itemPath === "/") { return currentPath === "/"; } return currentPath === itemPath || currentPath.startsWith(`${itemPath}/`); } function NavLinks({ onNavigate, mobile = false, }: { onNavigate?: () => void; mobile?: boolean; }) { const locale = useLocale(); const pathname = usePathname(); const t = useTranslations("navigation"); const currentPath = stripLocalePrefix(pathname); return ( <> {navItems.map((item) => ( (() => { const itemPath = item.path || "/"; const isActive = isNavItemActive(currentPath, itemPath); return ( {isActive ? ( ) : null} {t(item.key)} ); })() ))} ); } export function SiteHeader({ isAdmin = false, lightLogoUrl, darkLogoUrl, }: SiteHeaderProps) { const [isOpen, setIsOpen] = useState(false); const [isScrolled, setIsScrolled] = useState(false); const [logoReplayKey, setLogoReplayKey] = useState(0); const logoClickTimesRef = useRef([]); const pathname = usePathname(); const locale = useLocale(); const t = useTranslations("navigation"); const reducedMotion = useReducedMotion(); const isArabic = locale === "ar"; const languageDirection = isArabic ? "rtl" : "ltr"; const titleMotion = getDirectionalReveal(languageDirection); const subtitleMotion = getDirectionalReveal(languageDirection); const brandSubtitle = isArabic ? "مــــــطـــــــــــــور ويــــــــــب | فــــــــــــريــــــلانــــــســــــر" : "Webdesigner Bremen | Freelancer"; const desktopControlRailClassName = "inline-flex items-center gap-1 rounded-pill border border-border/70 bg-background/80 p-1 backdrop-blur-chrome"; const desktopControlButtonClassName = "h-9 w-9 rounded-pill border border-transparent p-0 text-foreground/80 hover:bg-accent hover:text-foreground"; const mobileControlButtonClassName = "h-10 w-10 rounded-pill border border-border/70 bg-background text-foreground/80 shadow-xs hover:bg-accent hover:text-foreground"; useEffect(() => { const handleScroll = () => { setIsScrolled(window.scrollY > 24); }; handleScroll(); window.addEventListener("scroll", handleScroll, { passive: true }); return () => { window.removeEventListener("scroll", handleScroll); }; }, []); const handleLogoClick = (event: React.MouseEvent) => { setLogoReplayKey((value) => value + 1); const now = Date.now(); const recentClicks = logoClickTimesRef.current.filter((time) => now - time < 1200); const nextClicks = [...recentClicks, now]; logoClickTimesRef.current = nextClicks; if (nextClicks.length < 3) { return; } logoClickTimesRef.current = []; event.preventDefault(); toast(t("logoTripleClick")); }; return (
{isArabic ? ( <> مــــحـــمــد {" "} فــــرواتـــي ) : ( <> MOH {" "} FARAWATI )} {brandSubtitle}
{isOpen ? ( {navItems.map((item) => { const itemPath = item.path || "/"; const isActive = isNavItemActive(stripLocalePrefix(pathname), itemPath); return ( setIsOpen(false)} > {t(item.key)} 0{navItems.findIndex((navItem) => navItem.key === item.key) + 1} ); })}
{isAdmin ? ( ) : null}
) : null}
); }