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 */} Cohorta {/* Center: LimelightNav */}
= 0 ? activeIndex : 0} />
{/* Right: auth buttons */}
{isAuthenticated ? ( ) : ( <> Log in )}
{/* Mobile toggle */}
{/* Mobile menu */} {mobileOpen && (
{isAuthenticated ? ( setMobileOpen(false)}> ) : ( <> setMobileOpen(false)} > Log in setMobileOpen(false)} > Get started free )}
)}
); }