'use client'; import React, { useState, useEffect } from 'react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { Menu, X } from 'lucide-react'; import { SiteConfig } from '@/types'; import { BrandLogo } from './BrandLogo'; interface NavbarProps { config: SiteConfig; currentLocale: string; } export function Navbar({ config, currentLocale }: NavbarProps) { const [isScrolled, setIsScrolled] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const pathname = usePathname(); // 100% Off-Main-Thread Observer: 0% CPU, 0 Scroll Lag useEffect(() => { // On non-homepage pages, navbar is immediately in solid state if (pathname !== '/') { setIsScrolled(true); return; } setIsScrolled(false); const sentinel = document.getElementById('hero-sentinel'); if (!sentinel) { const handleScroll = () => { setIsScrolled(window.scrollY > 400); }; window.addEventListener('scroll', handleScroll, { passive: true }); return () => window.removeEventListener('scroll', handleScroll); } const observer = new IntersectionObserver( ([entry]) => { setIsScrolled(!entry.isIntersecting && entry.boundingClientRect.top < 0); }, { threshold: 0, rootMargin: '-60px 0px 0px 0px', } ); observer.observe(sentinel); return () => observer.disconnect(); }, [pathname]); // Close mobile menu on Escape key useEffect(() => { if (!mobileMenuOpen) return; const closeOnEscape = (event: KeyboardEvent) => { if (event.key === 'Escape') setMobileMenuOpen(false); }; document.addEventListener('keydown', closeOnEscape); return () => document.removeEventListener('keydown', closeOnEscape); }, [mobileMenuOpen]); // Lock body scroll on iOS/Mobile when mobile menu is open useEffect(() => { if (mobileMenuOpen) { document.body.style.overflow = 'hidden'; document.body.style.touchAction = 'none'; } else { document.body.style.overflow = ''; document.body.style.touchAction = ''; } return () => { document.body.style.overflow = ''; document.body.style.touchAction = ''; }; }, [mobileMenuOpen]); // Whether we are at top of homepage on the dark hero const isHeroTransparent = pathname === '/' && !isScrolled; return (
{/* Brand Logo */}
{/* Center Navigation Links: - On Hero: Clean white text buttons only (matching reference image) - Scrolled: Subtle semi-solid pill links */} {/* Right CTA Button: Blue "Get the App" pill button */}
Get the App
{/* Mobile Menu Trigger */}
{/* Mobile Drawer */} {mobileMenuOpen && ( )}
); }