import { useNavigate } from 'react-router-dom' import { useAuth } from '@/context/AuthContext' import { useNotifications } from '@/hooks/useNotifications' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { Popover, PopoverContent, PopoverTrigger, } from '@/components/ui/popover' import { ScrollArea } from '@/components/ui/scroll-area' import { Separator } from '@/components/ui/separator' import { Bell, CheckCheck, LogOut, Menu, Moon, Sun, UserCog } from 'lucide-react' import { useTheme } from '@/hooks/useTheme' interface HeaderProps { onToggleSidebar: () => void } export function Header({ onToggleSidebar }: HeaderProps) { const navigate = useNavigate() const { user, logout } = useAuth() const { notifications, unreadCount, markAsRead, markAllAsRead } = useNotifications() const { theme, toggleTheme } = useTheme() const initials = user?.username ? user.username .split(/[\s._-]/) .map((part) => part[0]) .join('') .toUpperCase() .slice(0, 2) : '??' const roleBadgeVariant = user?.role === 'admin' ? 'default' as const : 'secondary' as const const roleLabel = user?.role === 'admin' ? 'Admin' : 'DAK Mitarbeiter' return (
{/* Dark mode toggle */} {/* Notification bell with dropdown */}

Benachrichtigungen

{unreadCount > 0 && ( )}
{notifications.length === 0 ? (

Keine Benachrichtigungen

) : (
{notifications.map((n) => ( ))}
)}
{/* User menu */}

{user?.username}

{user?.email}

{roleLabel}
navigate('/account')} className="cursor-pointer"> Konto verwalten logout()} className="cursor-pointer"> Abmelden
) } function formatRelativeTime(dateStr: string): string { try { const date = new Date(dateStr) const now = new Date() const diffMs = now.getTime() - date.getTime() const diffMin = Math.floor(diffMs / 60_000) const diffHrs = Math.floor(diffMs / 3_600_000) const diffDays = Math.floor(diffMs / 86_400_000) if (diffMin < 1) return 'Gerade eben' if (diffMin < 60) return `vor ${diffMin} Min.` if (diffHrs < 24) return `vor ${diffHrs} Std.` if (diffDays < 7) return `vor ${diffDays} Tag${diffDays > 1 ? 'en' : ''}` return date.toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', }) } catch { return dateStr } }