/** * NotificationItem Component * Single notification display with actions */ import React from 'react'; interface Notification { id: string; type: string; title: string; message: string; actionUrl?: string; read: boolean; createdAt: string; } interface NotificationItemProps { notification: Notification; onMarkAsRead: (id: string) => void; onDelete: (id: string) => void; compact?: boolean; } const typeIcons: Record = { welcome: { icon: '👋', bgColor: 'bg-blue-100' }, plant_registered: { icon: '🌱', bgColor: 'bg-green-100' }, plant_reminder: { icon: '🌿', bgColor: 'bg-green-100' }, transport_alert: { icon: '🚚', bgColor: 'bg-yellow-100' }, farm_alert: { icon: '🏭', bgColor: 'bg-orange-100' }, harvest_ready: { icon: '🎉', bgColor: 'bg-green-100' }, demand_match: { icon: '🤝', bgColor: 'bg-purple-100' }, weekly_digest: { icon: '📊', bgColor: 'bg-blue-100' }, system_alert: { icon: '⚙️', bgColor: 'bg-gray-100' } }; export function NotificationItem({ notification, onMarkAsRead, onDelete, compact = false }: NotificationItemProps) { const { icon, bgColor } = typeIcons[notification.type] || typeIcons.system_alert; function formatTimeAgo(dateString: string): string { const date = new Date(dateString); const now = new Date(); const seconds = Math.floor((now.getTime() - date.getTime()) / 1000); if (seconds < 60) return 'Just now'; if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`; if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`; if (seconds < 604800) return `${Math.floor(seconds / 86400)}d ago`; return date.toLocaleDateString(); } function handleClick() { if (!notification.read) { onMarkAsRead(notification.id); } if (notification.actionUrl) { window.location.href = notification.actionUrl; } } return (
e.key === 'Enter' && handleClick()} > {/* Icon */}
{icon}
{/* Content */}

{notification.title}

{notification.message}

{/* Unread indicator */} {!notification.read && (
)}
{formatTimeAgo(notification.createdAt)} {notification.actionUrl && ( View details → )}
{/* Actions (visible on hover) */}
{!notification.read && ( )}
); }