"use client"; import { useMemo, useState } from "react"; import { CheckCircle2, ChevronDown, ChevronUp, FileText, Image, MapPin, Mic, Radio, Send, Table, Users } from "lucide-react"; import { PriorityBadge } from "@/components/PriorityBadge"; import { api } from "@/lib/api"; import type { DispatchMessage, EvidenceItem, Incident, ResourceRecommendation } from "@/lib/types"; const MODALITY_ICON: Record = { text: , image: , audio: , csv: , location: , }; const STATUS_LABELS: Record = { new: "Nuevo", acknowledged: "Recibido", in_progress: "En progreso", resolved: "Resuelto", }; interface IncidentCardProps { incident: Incident; resources?: ResourceRecommendation[]; dispatch?: DispatchMessage | null; onApprove?: (id: string) => void; } function EvidenceRow({ item }: { item: EvidenceItem }) { return (
{MODALITY_ICON[item.modality] ?? MODALITY_ICON.text} {item.description}
); } export function IncidentCard({ incident, resources = [], dispatch, onApprove }: IncidentCardProps) { const [expanded, setExpanded] = useState(false); const [approved, setApproved] = useState(incident.human_approved); const [dispatchMessage, setDispatchMessage] = useState(dispatch?.message ?? ""); const [generatingDispatch, setGeneratingDispatch] = useState(false); const confidencePct = Math.round(incident.confidence * 100); const statusLabel = STATUS_LABELS[incident.status] ?? incident.status; const resourceSummary = useMemo( () => resources .map((resource) => resource.quantity ? `${resource.quantity} ${resource.description}` : resource.description, ) .slice(0, 3) .join(" · "), [resources], ); async function handleApprove() { try { await api.approveIncident(incident.id); } catch { // optimistic update } setApproved(true); onApprove?.(incident.id); } async function handleGenerateDispatch() { setGeneratingDispatch(true); try { const res = await api.generateDispatch(incident.id); setDispatchMessage(res.data?.message ?? ""); } finally { setGeneratingDispatch(false); } } return (
{expanded ? (

Situación

{incident.description}

Evidencia ({incident.evidence.length})

{incident.evidence.map((item) => ( ))}

Recursos sugeridos

{resources.length > 0 ? (
{resources.map((resource) => (

{resource.quantity ? `${resource.quantity} ` : ""} {resource.description}

{resource.urgency} · {resource.rationale}

))}
) : (

Sin recursos asociados en esta sesión.

)}

Mensaje de despacho

{dispatchMessage || "Todavía no hay mensaje generado para este incidente."}
Human-in-the-loop requerido para despacho crítico
) : null}
); }