import React, { useState } from 'react'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { Button } from './ui/button'; import { useAuth } from '../context/AuthContext'; import { useThemeConfig } from '../context/ThemeConfigContext'; import { ChevronDown, Menu, X } from 'lucide-react'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from './ui/dropdown-menu'; const PublicNavbar = () => { const { user, logout } = useAuth(); const { getLogoUrl } = useThemeConfig(); 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'); }; // Get logo URL from theme config (with fallback to default) const loafLogo = getLogoUrl(); 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-[var(--orange-light)] hover:text-[var(--orange-coral)] `; } 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-[var(--orange-light)] hover:bg-[var(--orange-coral)] text-[var(--purple-deep)]`; } return `${baseClasses} text-white hover:bg-[var(--purple-deep)]`; }; // 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-[var(--orange-light)] hover:bg-[var(--orange-coral)] text-[var(--purple-deep)]`; } return `${baseClasses} text-[var(--neutral-800)] hover:bg-[var(--purple-deep)] hover:text-white`; }; return ( <> {/* Top Header - Auth Actions */}
{user && ( Welcome, {user.first_name} )} {(user?.role === 'admin' || user?.role === 'superadmin') && ( Dashboard )} {!user && ( Register )}
{/* Main Header - Navigation */}
LOAF Logo {/* Mobile Menu Button */} {/* Desktop Navigation */}
{/* Mobile Menu Drawer */} {isMobileMenuOpen && (
{/* Backdrop */}
setIsMobileMenuOpen(false)} /> {/* Drawer */}
{/* Header */}
Menu
{/* User Info */} {user && (

Welcome,

{user.first_name} {user.last_name}

)} {/* Navigation Links */}
)} ); }; export default PublicNavbar;