/** * NotificationItem — single notification row inside the dropdown. * * Props: * notification: NotificationItem * onMarkRead: (id: string) => void */ import React from 'react'; import clsx from 'clsx'; import { Info, Mail, CheckSquare, Calendar, AlertCircle, User, FileText, Bell, type LucideIcon, } from 'lucide-react'; import type { NotificationItem as NotificationItemType } from '@/api/notifications'; // ── helpers ── /** * Returns a German relative-time string like "vor 5 Min" or "vor 2 Stunden". * Falls back to "gerade eben" for < 1 min and an absolute date for > 7 days. */ function relativeTime(isoDate: string | null | undefined): string { if (!isoDate) return ''; const now = Date.now(); const then = new Date(isoDate).getTime(); if (Number.isNaN(then)) return ''; const diffMs = now - then; if (diffMs < 0) return 'gerade eben'; const diffMin = Math.floor(diffMs / 60000); if (diffMin < 1) return 'gerade eben'; if (diffMin < 60) return `vor ${diffMin} Min`; const diffHrs = Math.floor(diffMin / 60); if (diffHrs < 24) return `vor ${diffHrs} Std`; const diffDays = Math.floor(diffHrs / 24); if (diffDays < 7) return `vor ${diffDays} ${diffDays === 1 ? 'Tag' : 'Tagen'}`; // > 7 days: show absolute date return new Date(isoDate).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', }); } /** Map notification type → lucide icon. */ const typeIconMap: Record = { info: Info, email: Mail, mail: Mail, task: CheckSquare, calendar: Calendar, event: Calendar, alert: AlertCircle, warning: AlertCircle, error: AlertCircle, contact: User, user: User, document: FileText, file: FileText, }; function getIconForType(type: string): LucideIcon { return typeIconMap[type] ?? Bell; } // ── component ── export interface NotificationItemProps { notification: NotificationItemType; onMarkRead: (id: string) => void; } export function NotificationItem({ notification, onMarkRead }: NotificationItemProps) { const isUnread = notification.read_at == null; const Icon = getIconForType(notification.type); const handleClick = () => { if (isUnread) { onMarkRead(notification.id); } }; return ( ); }