import { useState, useEffect, useRef } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useLanguage } from '../../contexts/LanguageContext'; import { useAuth } from '../../contexts/AuthContext'; export default function MarketingNavbar() { const { language, setLanguage } = useLanguage(); const { user, signOut } = useAuth(); const location = useLocation(); const isHome = location.pathname === '/'; const [scrolled, setScrolled] = useState(false); const [activeSection, setActiveSection] = useState(''); const [userMenuOpen, setUserMenuOpen] = useState(false); const userMenuRef = useRef(null); // Scroll: sticky style + active nav section useEffect(() => { const handleScroll = () => { setScrolled(window.scrollY > 10); if (!isHome) return; let current = ''; document.querySelectorAll('section[id]').forEach((s) => { if (window.scrollY >= (s as HTMLElement).offsetTop - 100) { current = s.id; } }); setActiveSection(current); }; window.addEventListener('scroll', handleScroll, { passive: true }); return () => window.removeEventListener('scroll', handleScroll); }, [isHome]); // Close user menu on outside click useEffect(() => { const handle = (e: MouseEvent) => { if (userMenuRef.current && !userMenuRef.current.contains(e.target as Node)) { setUserMenuOpen(false); } }; document.addEventListener('mousedown', handle); return () => document.removeEventListener('mousedown', handle); }, []); const navLinks = [ { href: '/', label: language === 'zh' ? '首页' : 'Home' }, { href: '/docs', label: language === 'zh' ? '文档' : 'Docs' }, { href: '/blog', label: language === 'zh' ? '博客' : 'Blog' }, ]; const anchorLinks = isHome ? [{ href: '#pricing', label: language === 'zh' ? '价格' : 'Pricing' }] : []; return ( ); }