import { useState, useEffect } from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { motion, AnimatePresence } from 'framer-motion'; import { HiMenu, HiX, HiChevronDown, HiHeart, HiUserCircle } from 'react-icons/hi'; import { useAuth } from '../../contexts/AuthContext'; import { NAV_LINKS, FOUNDATION_INFO } from '../../utils/constants'; import './Header.css'; export default function Header() { const [isScrolled, setIsScrolled] = useState(false); const [mobileOpen, setMobileOpen] = useState(false); const [dropdownOpen, setDropdownOpen] = useState(null); const { currentUser, userProfile, logout } = useAuth(); const location = useLocation(); const navigate = useNavigate(); useEffect(() => { const handleScroll = () => setIsScrolled(window.scrollY > 20); window.addEventListener('scroll', handleScroll); return () => window.removeEventListener('scroll', handleScroll); }, []); // Close mobile menu on route change useEffect(() => { setMobileOpen(false); setDropdownOpen(null); }, [location]); const handleLogout = async () => { try { await logout(); navigate('/'); } catch (error) { console.error('Logout error:', error); } }; const isActive = (path) => location.pathname === path; return (
{/* Logo */} {FOUNDATION_INFO.name}
Social Share & Care Foundation
{/* Desktop Navigation */} {/* Right Actions */}
Donate {currentUser ? (
setDropdownOpen('user')} onMouseLeave={() => setDropdownOpen(null)} > {dropdownOpen === 'user' && (
{userProfile?.displayName} {userProfile?.email}
Dashboard Profile My Donations
)}
) : ( Sign In )} {/* Mobile Toggle */}
{/* Mobile Menu */} {mobileOpen && ( )}
); }