'use client'; import { useRouter } from 'next/navigation'; import { Search, Bell, Sun, Moon, LogOut, Menu, User, Settings, HelpCircle, ShieldAlert, AlertTriangle, ShoppingCart, Package, ChevronDown, } from 'lucide-react'; import { useTheme } from 'next-themes'; import { authService } from '@/services/api/authService'; import { parseJwt, getAccessToken } from '@/services/api/client'; import { useState, useEffect } from 'react'; import { toast } from 'sonner'; import Link from 'next/link'; import { SlideOver } from '@/components/ui/SlideOver'; interface HeaderProps { onMenuToggle: () => void; } interface NotificationItem { id: string; title: string; message: string; time: string; type: 'security' | 'stock' | 'order' | 'ticket'; read: boolean; } export function Header({ onMenuToggle }: HeaderProps) { const router = useRouter(); const { theme, setTheme } = useTheme(); const [userName, setUserName] = useState(''); const [userEmail, setUserEmail] = useState(''); const [dropdownOpen, setDropdownOpen] = useState(false); const [notificationsOpen, setNotificationsOpen] = useState(false); const [mounted, setMounted] = useState(false); const [notifications, setNotifications] = useState([]); const unreadCount = notifications.filter(n => !n.read).length; const markAllAsRead = () => { setNotifications(notifications.map(n => ({ ...n, read: true }))); toast.success('All notifications marked as read'); }; const toggleReadStatus = (id: string) => { setNotifications(notifications.map(n => n.id === id ? { ...n, read: !n.read } : n)); }; useEffect(() => { setMounted(true); const token = getAccessToken(); if (token) { const payload = parseJwt(token); if (payload) { setUserEmail((payload.email as string) || ''); setUserName((payload.email as string)?.split('@')[0] || 'Admin'); } } }, []); const handleLogout = async () => { try { await authService.logout(); toast.success('Signed out'); } catch { // Logout anyway on client side } router.push('/login'); }; return ( <>
{/* Left Side */}
{/* Right Side */}
{/* Theme Toggle */} {/* Divider */}
{/* User Profile Dropdown */}
{dropdownOpen && ( <>
setDropdownOpen(false)} />
{/* User Info Header */}
{userName ? userName.charAt(0).toUpperCase() : 'A'}

{userName || 'Admin'}

Administrator

{/* Menu Items */}
setDropdownOpen(false)} className="flex items-center gap-2.5 px-3 py-2 rounded-md hover:bg-muted hover:text-foreground transition-colors" > Profile Settings
Notifications
setDropdownOpen(false)} className="flex items-center gap-2.5 px-3 py-2 rounded-md hover:bg-muted hover:text-foreground transition-colors" > Help & Support setDropdownOpen(false)} className="flex items-center gap-2.5 px-3 py-2 rounded-md hover:bg-muted hover:text-foreground transition-colors" > Settings
{/* Sign Out */}
)}
setNotificationsOpen(false)} title="Notifications" icon={} size="compact" >

{unreadCount > 0 ? `${unreadCount} unread` : 'You are all caught up'}

{unreadCount > 0 && ( )}
{notifications.length === 0 ? (
No notifications yet.
) : ( notifications.map((notification) => ( )) )}
setNotificationsOpen(false)} className="inline-flex items-center justify-center h-9 w-full crm-radius-control border border-border bg-card text-[13px] font-semibold text-foreground hover:bg-muted cursor-pointer" > View all activity logs
); }