import React, { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { Code2, Copy, Check, Braces, FileCode2, FileText, Sparkles, ChevronDown, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { cn } from "@/lib/utils"; // Mock extracted data const mockData = { document: { type: "Invoice", confidence: 0.98, }, vendor: { name: "Acme Corporation", address: "123 Business Ave, Suite 400", city: "San Francisco", state: "CA", zip: "94102", phone: "+1 (555) 123-4567", }, invoice: { number: "INV-2024-0847", date: "2024-01-15", due_date: "2024-02-14", po_number: "PO-9823", }, items: [ { description: "Professional Services", quantity: 40, unit_price: 150.0, total: 6000.0 }, { description: "Software License", quantity: 5, unit_price: 299.99, total: 1499.95 }, { description: "Support Package", quantity: 1, unit_price: 500.0, total: 500.0 }, ], totals: { subtotal: 7999.95, tax_rate: 0.0875, tax_amount: 699.99, total: 8699.94, }, }; const mockXML = ` Acme Corporation
123 Business Ave, Suite 400
San Francisco CA 94102
INV-2024-0847 2024-01-15 2024-02-14 Professional Services 40 6000.00 7999.95 699.99 8699.94
`; const mockText = `INVOICE ACME CORPORATION 123 Business Ave, Suite 400 San Francisco, CA 94102 Phone: +1 (555) 123-4567 Invoice Number: INV-2024-0847 Invoice Date: January 15, 2024 Due Date: February 14, 2024 PO Number: PO-9823 BILL TO: Customer Name 456 Client Street New York, NY 10001 ITEMS: ───────────────────────────────────────────────────────── Description Qty Unit Price Total ───────────────────────────────────────────────────────── Professional Services 40 $150.00 $6,000.00 Software License 5 $299.99 $1,499.95 Support Package 1 $500.00 $500.00 ───────────────────────────────────────────────────────── Subtotal: $7,999.95 Tax (8.75%): $699.99 ───────────────────────── TOTAL: $8,699.94 Payment Terms: Net 30 Thank you for your business!`; export default function ExtractionOutput({ hasFile, isProcessing, isComplete }) { const [activeTab, setActiveTab] = useState("text"); const [copied, setCopied] = useState(false); const [expandedSections, setExpandedSections] = useState(["vendor", "invoice", "items", "totals"]); const handleCopy = () => { const content = activeTab === "json" ? JSON.stringify(mockData, null, 2) : activeTab === "xml" ? mockXML : mockText; navigator.clipboard.writeText(content); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const toggleSection = (section) => { setExpandedSections((prev) => prev.includes(section) ? prev.filter((s) => s !== section) : [...prev, section] ); }; const renderValue = (value) => { if (typeof value === "number") { return {value}; } if (typeof value === "string") { return "{value}"; } return String(value); }; const renderSection = (key, value, level = 0) => { const isExpanded = expandedSections.includes(key); const isObject = typeof value === "object" && value !== null; const isArray = Array.isArray(value); if (!isObject) { return (
"{key}" : {renderValue(value)}
); } return (
{isExpanded && ( {isArray ? ( value.map((item, idx) => (
{Object.entries(item).map(([k, v]) => renderSection(k, v, level + 2))} {idx < value.length - 1 &&
}
)) ) : ( Object.entries(value).map(([k, v]) => renderSection(k, v, level + 1)) )}
{isArray ? "]" : "}"}
)}
); }; return (
{/* Header */}

Extracted Data

{isComplete ? "25 fields extracted" : "Waiting for extraction"}

{isComplete && (
Text JSON XML
)}
{/* Output Area */}
{!hasFile ? (

Extracted data will appear here

) : isProcessing ? (

AI is extracting data...

Analyzing document structure

{[0, 1, 2].map((i) => ( ))}
) : (
{activeTab === "text" ? (
                {mockText}
              
) : activeTab === "json" ? (
{"{"} {Object.entries(mockData).map(([key, value]) => renderSection(key, value, 1) )} {"}"}
) : (
                {mockXML.split("\n").map((line, i) => (
                  
{line.includes("<") ? ( <> {line.split(/(<\/?[\w\s=".-]+>)/g).map((part, j) => { if (part.startsWith(" {part} ); } if (part.startsWith("<")) { return ( {part} ); } return ( {part} ); })} ) : ( line )}
))}
)}
)}
{/* Confidence Footer */} {isComplete && (
Confidence: 98%
Fields: 25
Processed in 2.3s
)}
); }