'use client' import { useState } from 'react' import { Check, Trash2 } from 'lucide-react' import { Alert } from '@/lib/types' import { cn } from '@/lib/utils' import { AlertIcon } from './AlertIcon' interface AlertItemProps { alert: Alert onMarkRead: () => void onDelete: () => void } const severityStyles = { info: 'text-blue-400', warning: 'text-amber-400', danger: 'text-red-400', } function getRelativeTime(date: string): string { const now = new Date() const alertDate = new Date(date) const diffMs = now.getTime() - alertDate.getTime() const diffMins = Math.floor(diffMs / (1000 * 60)) const diffHours = Math.floor(diffMs / (1000 * 60 * 60)) const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24)) if (diffMins < 1) { return 'ahora' } if (diffMins < 60) { return `hace ${diffMins} min` } if (diffHours < 24) { return `hace ${diffHours} hora${diffHours > 1 ? 's' : ''}` } if (diffDays === 1) { return 'ayer' } if (diffDays < 7) { return `hace ${diffDays} días` } return alertDate.toLocaleDateString('es-AR', { day: 'numeric', month: 'short', }) } export function AlertItem({ alert, onMarkRead, onDelete }: AlertItemProps) { const [showActions, setShowActions] = useState(false) const [isExiting, setIsExiting] = useState(false) const handleMarkRead = () => { setIsExiting(true) setTimeout(() => { onMarkRead() }, 200) } const handleDelete = () => { setIsExiting(true) setTimeout(() => { onDelete() }, 200) } return (
setShowActions(true)} onMouseLeave={() => setShowActions(false)} role="listitem" > {/* Unread indicator */} {!alert.isRead && ( )} {/* Icon */}
{/* Content */}

{alert.title}

{getRelativeTime(alert.date)}

{/* Actions */}
{!alert.isRead && ( )}
) }