import React from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { Home, Store, BarChart3, HeartPulse, Wrench, ShoppingBag, AlertTriangle, UserCheck, ShieldCheck, LogOut, LayoutGrid } from 'lucide-react'; import { useAuth } from '../context/useAuth'; export function NavigationHeader({ title, subtitle, icon: TitleIcon, health, onResetHome, children, }) { const location = useLocation(); const path = location.pathname; const search = location.search; const navigate = useNavigate(); const { user, role, logout } = useAuth(); const handleLogout = () => { logout(); navigate('/login'); }; const getRoleBadge = () => { if (role === 'admin') { return ( Admin ); } return ( User ); }; return ( {/* Left Section: Home/Back Button + Page Title */} { if (onResetHome) onResetHome(); }} title={role === 'admin' ? 'Navigate to Catalog' : 'Navigate to User Workspace'} className="group flex items-center gap-2 rounded-full bg-gradient-to-r from-amber-500 to-amber-600 hover:from-amber-600 hover:to-amber-700 text-white px-4 py-2 text-xs font-semibold shadow-sm transition-all duration-200 active:scale-95 hover:shadow-md" > {role === 'admin' ? 'Home / Catalog' : 'Home / Workspace'} {title && ( {TitleIcon && ( )} {title} {subtitle && {subtitle}} )} {/* Right Section: System Health + Role-Based Nav Tabs + Logout Button */} {health && health.status !== 'ok' && ( {!health.database && !health.ollama ? 'DB & Ollama offline' : !health.database ? 'Database offline' : 'Ollama offline'} )} {/* User Role Profile Badge */} {user?.display_name || user?.username || 'Guest'} {getRoleBadge()} {/* Role-tailored Navigation Tabs */} {/* Catalog tab ONLY visible to Admin role */} {role === 'admin' && ( { if (onResetHome) onResetHome(); }} className={`flex items-center gap-1.5 rounded-full px-3.5 py-1.5 transition-all ${ path === '/' ? 'bg-ink-950 text-paper-100 shadow-sm font-semibold' : 'text-slate-600 hover:text-ink-950 hover:bg-white/60' }`} > Catalog )} {/* User Upload tab */} User Upload {/* Product Cards tab for User role */} Product Cards {/* Stores tab */} Stores {/* Analytics tab */} Analytics {/* Nutrition tab */} Nutrition {/* Admin Panel tab ONLY visible to Admin role */} {role === 'admin' && ( Admin )} {/* Top Right Logout Button */} Logout {children} ); }
{subtitle}