import React, { useState } from 'react'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { Button } from './ui/button'; import { useAuth } from '../context/AuthContext'; import { ChevronDown, Menu, X } from 'lucide-react'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from './ui/dropdown-menu'; const PublicNavbar = () => { const { user, logout } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); // Helper function to check if a path is active const isActive = (path) => { if (path.includes('#')) { // For hash links like /#welcome return location.pathname + location.hash === path || location.hash === path.replace('/', ''); } return location.pathname === path || location.pathname.startsWith(path + '/'); }; // Check if any About Us sub-page is active const isAboutActive = () => { return location.pathname.startsWith('/about'); }; // LOAF logo (local) const loafLogo = `${process.env.PUBLIC_URL}/loaf-logo.png`; const handleAuthAction = () => { if (user) { logout(); navigate('/'); } else { navigate('/login'); } }; // Active and inactive link styles for desktop const getDesktopLinkClasses = (path) => { const baseClasses = "text-[17.5px] font-medium transition-all px-3 py-1 rounded-md"; if (isActive(path)) { return `${baseClasses} text-[#ff9e77] hover:text-[#ff8c64] `; } return `${baseClasses} text-white hover:opacity-80`; }; // Active and inactive link styles for mobile const getMobileLinkClasses = (path) => { const baseClasses = "text-base font-medium px-4 py-3 rounded-md transition-colors"; if (isActive(path)) { return `${baseClasses} bg-[#ff9e77] hover:bg-[#ff8c64] text-[#48286e]`; } return `${baseClasses} text-white hover:bg-[#48286e]`; }; // Active and inactive link styles for mobile sub-items (About Us) const getMobileSubLinkClasses = (path) => { const baseClasses = "text-sm font-medium px-6 py-2 rounded-md transition-colors block"; if (isActive(path)) { return `${baseClasses} bg-[#ff9e77] hover:bg-[#ff8c64] text-[#48286e]`; } return `${baseClasses} text-[#ddd8eb] hover:bg-[#48286e] hover:text-white`; }; return ( <> {/* Top Header - Auth Actions */}
{!user && ( Register )}
{/* Main Header - Navigation */}
LOAF Logo {/* Mobile Menu Button */} {/* Desktop Navigation */}
{/* Mobile Menu Drawer */} {isMobileMenuOpen && (
{/* Backdrop */}
setIsMobileMenuOpen(false)} /> {/* Drawer */}
{/* Header */}
Menu
{/* Navigation Links */}
)} ); }; export default PublicNavbar;