import { useCallback } from 'react'; interface Props { svg?: string; imageB64?: string; mime?: string; prompt: string; isGenerating?: boolean; } export default function ImageDisplay({ svg, imageB64, mime, prompt, isGenerating }: Props) { const handleDownload = useCallback(() => { if (imageB64 && mime) { const byteStr = atob(imageB64); const bytes = new Uint8Array(byteStr.length); for (let i = 0; i < byteStr.length; i++) bytes[i] = byteStr.charCodeAt(i); const blob = new Blob([bytes], { type: mime }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = (prompt.slice(0, 30) || 'image').replace(/[^a-zA-Z0-9]/g, '_') + '.png'; a.click(); URL.revokeObjectURL(url); } else if (svg) { const blob = new Blob([svg], { type: 'image/svg+xml' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = (prompt.slice(0, 30) || 'image').replace(/[^a-zA-Z0-9]/g, '_') + '.svg'; a.click(); URL.revokeObjectURL(url); } }, [svg, imageB64, mime, prompt]); const imageSrc = imageB64 ? `data:${mime || 'image/png'};base64,${imageB64}` : null; if (isGenerating) { return (
Creating image...
{/* Dot grid pattern */}
{/* Animated shimmer */}
{/* Pink-purple gradient pulse */}
); } return (
{imageSrc ? ( {prompt} ) : svg ? (
) : null} {imageSrc && ( )} {svg && !imageSrc && ( )}
); }