'use client'; import { useState } from 'react'; import { CheckCircle2, XCircle, Clock, ChevronDown, ChevronUp, Terminal, AlertTriangle, Copy, Check, Image as ImageIcon, Download, ZoomIn, } from 'lucide-react'; import { clsx } from 'clsx'; export interface ExecutionResultData { success: boolean; output: string; error: string; executionTime: number; hasCircuitOutput?: boolean; images?: string[]; // Base64 encoded images } interface ExecutionResultProps { result: ExecutionResultData; isLoading?: boolean; } function ImageViewer({ images }: { images: string[] }) { const [selectedImage, setSelectedImage] = useState(null); const handleDownload = (base64: string, index: number) => { const link = document.createElement('a'); link.href = `data:image/png;base64,${base64}`; link.download = `quantum_output_${index + 1}.png`; link.click(); }; return (
Generated Figures ({images.length})
{images.map((base64, idx) => (
{`Output setSelectedImage(idx)} />
))}
{/* Full-size image modal */} {selectedImage !== null && (
setSelectedImage(null)} >
{`Output e.stopPropagation()} />
)}
); } export function ExecutionResult({ result, isLoading }: ExecutionResultProps) { const [isExpanded, setIsExpanded] = useState(true); const [copied, setCopied] = useState(false); const hasOutput = result.output.trim().length > 0; const hasError = result.error.trim().length > 0; const hasImages = result.images && result.images.length > 0; const outputToShow = hasError ? result.error : result.output; const handleCopy = async () => { await navigator.clipboard.writeText(outputToShow); setCopied(true); setTimeout(() => setCopied(false), 2000); }; if (isLoading) { return (
Executing code...
Running Python with Qiskit...
); } return (
{/* Header */} {/* Output */} {isExpanded && (hasOutput || hasError || hasImages) && (
{(hasOutput || hasError) && (
)}
{hasError && (
{result.error}
)} {hasOutput && (
                                {result.output}
                            
)} {!hasOutput && !hasError && !hasImages && result.success && ( Code executed successfully with no output )} {/* Display generated images */} {hasImages && ( )}
)}
); }