import { useState } from 'react'; /** * Display complete Docling parsing output with breakdown numbers * Shows all elements, element type counts, and stats */ export default function DoclingOutput({ results, onContinue, onDownload }) { const [expandedFiles, setExpandedFiles] = useState( // Expand first file by default results?.length > 0 ? { [results[0].filename]: true } : {} ); const toggleFile = (filename) => { setExpandedFiles(prev => ({ ...prev, [filename]: !prev[filename] })); }; const formatNumber = (num) => { return num?.toLocaleString() || '0'; }; const handleDownload = () => { const dataStr = JSON.stringify(results, null, 2); const dataBlob = new Blob([dataStr], { type: 'application/json' }); const url = URL.createObjectURL(dataBlob); const link = document.createElement('a'); link.href = url; link.download = `docling-output-${new Date().toISOString().slice(0, 10)}.json`; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url); onDownload?.(); }; // Get element type badge color const getTypeColor = (type) => { const colors = { heading: 'bg-blue-900/50 text-blue-300 border-blue-700', paragraph: 'bg-slate-700 text-slate-300 border-slate-600', table: 'bg-purple-900/50 text-purple-300 border-purple-700', list_item: 'bg-orange-900/50 text-orange-300 border-orange-700', list: 'bg-orange-900/50 text-orange-300 border-orange-700', code: 'bg-green-900/50 text-green-300 border-green-700', image: 'bg-pink-900/50 text-pink-300 border-pink-700', caption: 'bg-yellow-900/50 text-yellow-300 border-yellow-700', formula: 'bg-cyan-900/50 text-cyan-300 border-cyan-700', footer: 'bg-gray-700 text-gray-300 border-gray-600', header: 'bg-gray-700 text-gray-300 border-gray-600', }; return colors[type] || 'bg-slate-700 text-slate-300 border-slate-600'; }; if (!results || results.length === 0) { return (
{results.length} file{results.length !== 1 ? 's' : ''} parsed
{formatNumber(doc.total_elements)}
Elements
{formatNumber(doc.total_chars)}
Characters
{formatNumber(doc.total_words)}
Words
{doc.page_count || '-'}
Pages
{el.text || '(empty)'}