"use client"; import { useCallback, useRef, useState } from "react"; import { UploadCloud, FileText, X, Play, Loader2 } from "lucide-react"; import { api } from "@/lib/api"; import type { CrisisRoomSummary } from "@/lib/types"; interface UploadPanelProps { onResults: (summary: CrisisRoomSummary, demoMode: boolean) => void; onProcessing: (processing: boolean) => void; processing: boolean; } interface FileItem { name: string; size: number; type: string; } export function UploadPanel({ onResults, onProcessing, processing, }: UploadPanelProps) { const [files, setFiles] = useState([]); const [dragOver, setDragOver] = useState(false); const inputRef = useRef(null); const addFiles = useCallback((newFiles: FileList | null) => { if (!newFiles) return; const items: FileItem[] = Array.from(newFiles).map((f) => ({ name: f.name, size: f.size, type: f.type, })); setFiles((prev) => [ ...prev, ...items.filter((nf) => !prev.find((pf) => pf.name === nf.name)), ]); }, []); function removeFile(name: string) { setFiles((prev) => prev.filter((f) => f.name !== name)); } function formatBytes(bytes: number) { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } async function handleLoadDemo() { onProcessing(true); try { const res = await api.runDemo(); onResults(res.data as CrisisRoomSummary, false); } catch { // Backend unreachable — return mock summary signal onResults( { session_id: "demo-mock", total_incidents: 5, p0_count: 2, p1_count: 1, p2_count: 1, p3_count: 1, incidents: [], processing_time_ms: 1240, status: "completed", }, true ); } finally { onProcessing(false); } } return (
{/* Drag & drop zone */}
{ e.preventDefault(); setDragOver(true); }} onDragLeave={() => setDragOver(false)} onDrop={(e) => { e.preventDefault(); setDragOver(false); addFiles(e.dataTransfer.files); }} onClick={() => inputRef.current?.click()} > addFiles(e.target.files)} />

Arrastre archivos aquí

Texto, imágenes, audio, CSV

{/* File list */} {files.length > 0 && (
    {files.map((f) => (
  • {f.name} {formatBytes(f.size)}
  • ))}
)} {/* Load Demo button */}
); }