import { useState, useEffect } from 'react'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { useAuth } from '@/contexts/AuthContext'; import UserDropdown from '@/components/brand/UserDropdown'; import { Menu, X } from 'lucide-react'; import { cn } from '@/lib/utils'; import { motion, useScroll, useSpring, useReducedMotion } from 'framer-motion'; import { LimelightNav } from '@/components/ui/LimelightNav'; const navLinks = [ { label: 'Home', to: '/', anchor: null }, { label: 'Product', to: '/', anchor: 'product' }, { label: 'Pricing', to: '/', anchor: 'pricing' }, { label: 'Contact', to: 'mailto:hello@ai-impress.com', anchor: null, external: true }, ]; export default function Header() { const { isAuthenticated } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const [scrolled, setScrolled] = useState(false); const [mobileOpen, setMobileOpen] = useState(false); const [activeIndex, setActiveIndex] = useState(0); const shouldReduce = useReducedMotion(); const { scrollYProgress } = useScroll(); const scaleX = useSpring(scrollYProgress, { stiffness: 200, damping: 30 }); useEffect(() => { const onScroll = () => setScrolled(window.scrollY > 24); window.addEventListener('scroll', onScroll, { passive: true }); return () => window.removeEventListener('scroll', onScroll); }, []); // Track active section based on scroll position (landing page only) useEffect(() => { if (location.pathname !== '/') { setActiveIndex(-1); return; } const anchorSections = ['product', 'pricing']; // maps to index 1, 2 const update = () => { let current = 0; for (let i = anchorSections.length - 1; i >= 0; i--) { const el = document.getElementById(anchorSections[i]); if (el && el.getBoundingClientRect().top <= 120) { current = i + 1; break; } } setActiveIndex(current); }; window.addEventListener('scroll', update, { passive: true }); update(); return () => window.removeEventListener('scroll', update); }, [location.pathname]); const handleNavClick = (anchor: string | null, to: string, external?: boolean) => { if (external) return; if (!anchor) { navigate(to); return; } if (location.pathname === '/') { document.getElementById(anchor)?.scrollIntoView({ behavior: 'smooth' }); } else { navigate(`/?scroll=${anchor}`); } }; const limelightItems = navLinks.map(({ label, to, anchor, external }, i) => ({ id: label, label, onClick: external ? () => { window.location.href = to; } : () => handleNavClick(anchor, to), icon: ( {label} ), })); return ( {!shouldReduce && ( )} {/* Left: Logo banner */} {/* Center: LimelightNav */} = 0 ? activeIndex : 0} /> {/* Right: auth buttons */} {isAuthenticated ? ( ) : ( <> Log in navigate('/register')} className="px-4 py-2 rounded-full text-sm font-semibold bg-primary text-primary-foreground hover:bg-primary/90 transition-all duration-200 shadow-sm whitespace-nowrap" > Get started > )} {/* Mobile toggle */} setMobileOpen(v => !v)} aria-label="Toggle menu" > {mobileOpen ? : } {/* Mobile menu */} {mobileOpen && ( {navLinks.map(({ label, to, anchor, external }) => { if (external) return ( setMobileOpen(false)} >{label} ); return ( { handleNavClick(anchor, to); setMobileOpen(false); }} >{label} ); })} {isAuthenticated ? ( setMobileOpen(false)}> My account ) : ( <> setMobileOpen(false)} > Log in setMobileOpen(false)} > Get started free > )} )} ); }