const { useState, useEffect, useRef } = React; const Navbar = ({ activePage = 'home' }) => { const [isExpanded, setIsExpanded] = useState(true); const [isGrey, setIsGrey] = useState(false); const [isHovered, setIsHovered] = useState(false); const hoverTimerRef = useRef(null); const [hash, setHash] = useState(() => (typeof window !== 'undefined' ? window.location.hash : '')); useEffect(() => { const syncHash = () => setHash(window.location.hash); window.addEventListener('hashchange', syncHash); window.addEventListener('load', syncHash); return () => { window.removeEventListener('hashchange', syncHash); window.removeEventListener('load', syncHash); }; }, []); useEffect(() => { const mq = window.matchMedia('(min-width: 768px)'); let collapseTimer; let colorTimer; const syncCollapse = () => { if (collapseTimer) clearTimeout(collapseTimer); if (mq.matches) { collapseTimer = setTimeout(() => setIsExpanded(false), 2000); } else { setIsExpanded(true); } }; const syncGrey = () => { if (colorTimer) clearTimeout(colorTimer); if (!mq.matches) { setIsGrey(false); return; } colorTimer = setTimeout(() => setIsGrey(true), 2800); }; const onViewportChange = () => { syncCollapse(); syncGrey(); }; onViewportChange(); mq.addEventListener('change', onViewportChange); return () => { if (collapseTimer) clearTimeout(collapseTimer); if (colorTimer) clearTimeout(colorTimer); mq.removeEventListener('change', onViewportChange); }; }, []); const handleMouseEnter = () => { setIsHovered(true); if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current); hoverTimerRef.current = setTimeout(() => { setIsGrey(false); }, 800); }; const handleMouseLeave = () => { setIsHovered(false); if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current); hoverTimerRef.current = setTimeout(() => { if (typeof window !== 'undefined' && window.matchMedia('(min-width: 768px)').matches) { setIsGrey(true); } }, 800); }; const onHomePage = activePage === 'home'; const isWork = activePage === 'work'; const isStudio = activePage === 'studio'; const CONTACT_EMAIL = 'sedemoasis@gmail.com'; const linkClass = (active) => { if (active) { return isGrey && !isHovered ? 'text-black font-medium' : 'text-white font-medium'; } return isGrey && !isHovered ? 'text-black/40 hover:text-black' : 'text-white/40 hover:text-white'; }; return (