"use client"; import { useState } from "react"; import { Check, Copy, FileJson, FileSpreadsheet, FileText } from "lucide-react"; import { api } from "@/lib/api"; import type { DocumentDetail } from "@/lib/types"; const FORMATS = [ { id: "json", label: "JSON", desc: "Full structured payload — fields, tables, classification, anomalies.", icon: FileJson, tint: "from-amber-500/20 to-amber-600/5 text-amber-300 ring-amber-500/20", }, { id: "csv", label: "CSV", desc: "Flat field / value / confidence table for spreadsheets.", icon: FileText, tint: "from-emerald-500/20 to-emerald-600/5 text-emerald-300 ring-emerald-500/20", }, { id: "xlsx", label: "Excel", desc: "Multi-sheet workbook with fields and extracted tables.", icon: FileSpreadsheet, tint: "from-green-500/20 to-green-600/5 text-green-300 ring-green-500/20", }, ]; export default function ExportPanel({ detail }: { detail: DocumentDetail }) { const ready = detail.status === "ready"; const [copied, setCopied] = useState(false); const ex = detail.extraction; const previewObj: Record = { doc_type: detail.classification?.doc_type, confidence: detail.classification?.confidence, }; if (ex && ex.fields.length > 0) { previewObj.fields = Object.fromEntries(ex.fields.map((f) => [f.name, f.value])); } if (ex && ex.records?.length > 0) { previewObj.record_type = ex.record_type; previewObj.records = ex.records.slice(0, 5).map((r) => Object.fromEntries(r.fields.map((f) => [f.name, f.value])), ); if (ex.records.length > 5) previewObj["…"] = `${ex.records.length - 5} more records`; } const preview = JSON.stringify(previewObj, null, 2); return (

Export extracted data

Download structured output for downstream systems — ERP, accounting, CRM.

{FORMATS.map((f) => { const Icon = f.icon; return ( !ready && e.preventDefault()} className={`card group flex flex-col gap-3 rounded-xl p-4 transition ${ ready ? "hover:-translate-y-0.5 hover:ring-brand-500/30" : "cursor-not-allowed opacity-50" }`} >

{f.label}

{f.desc}

Download →
); })}
{!ready && (

Export becomes available once processing completes.

)} {detail.extraction && (

Preview

            {preview}
          
)}
); }