'use client' import { useState } from 'react' import { motion } from 'framer-motion' import { Download, CheckCircle2, XCircle, Archive, ExternalLink, FileText, Hash, Clock } from 'lucide-react' import type { BatchResult, ExportFormat } from '@/types' import { exportToFormat, getFilenameForFormat, EXPORT_FORMATS } from '@/lib/exporters' import JSZip from 'jszip' interface BatchResultsProps { results: BatchResult[] stats: { total: number successful: number failed: number totalTokens: number } processingTime: number } export default function BatchResults({ results, stats, processingTime }: BatchResultsProps) { const [exportFormat, setExportFormat] = useState('markdown') const [downloading, setDownloading] = useState(null) const successfulResults = results.filter(r => r.success && r.data) const downloadSingle = async (result: BatchResult) => { if (!result.data) return setDownloading(result.url) try { const content = exportToFormat(result.data, exportFormat) const siteName = new URL(result.url.startsWith('http') ? result.url : `https://${result.url}`).hostname.replace('www.', '').split('.')[0] const filename = getFilenameForFormat(siteName, exportFormat) const blob = new Blob([content], { type: 'text/plain' }) const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = filename document.body.appendChild(a) a.click() document.body.removeChild(a) URL.revokeObjectURL(url) } finally { setDownloading(null) } } const downloadAllAsZip = async () => { setDownloading('all') try { const zip = new JSZip() const folder = zip.folder('batch-extraction') if (!folder) throw new Error('Failed to create ZIP folder') for (const result of successfulResults) { if (!result.data) continue const siteName = new URL( result.url.startsWith('http') ? result.url : `https://${result.url}` ).hostname.replace('www.', '').split('.')[0] const content = exportToFormat(result.data, exportFormat) const filename = getFilenameForFormat(siteName, exportFormat) folder.file(filename, content) } const blob = await zip.generateAsync({ type: 'blob', compression: 'DEFLATE', compressionOptions: { level: 6 }, }) const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = `batch-docs-${Date.now()}.zip` document.body.appendChild(a) a.click() document.body.removeChild(a) URL.revokeObjectURL(url) } finally { setDownloading(null) } } return (
{/* Stats Header */}

Batch Complete

{(processingTime / 1000).toFixed(1)}s total
Total URLs
{stats.total}
Successful
{stats.successful}
Failed
{stats.failed}
Total Tokens
{stats.totalTokens.toLocaleString()}
{/* Download Section */} {successfulResults.length > 0 && (

Download Results

{/* Format Selector */}
{/* Download All Button */} {/* Individual Results */}
{results.map((result, index) => (
{result.success ? ( ) : ( )}
{result.url}
{result.error && (
{result.error}
)} {result.data && (
{result.data.stats.documentCount} sections • {result.data.stats.totalTokens.toLocaleString()} tokens
)}
{result.success && result.data && ( )}
))}
)}
) }