import { useEffect } from 'react'; import { createPortal } from 'react-dom'; import { HardDriveDownload, Check, X } from 'lucide-react'; import { useZipDownloadStore } from '../store/zipDownloadStore'; function formatMB(bytes: number): string { if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } function ZipDownloadItem({ id }: { id: string }) { const dismiss = useZipDownloadStore(s => s.dismiss); const item = useZipDownloadStore(s => s.downloads.find(d => d.id === id)); // Auto-dismiss 3 s after completion or error. useEffect(() => { if (!item?.done && !item?.error) return; const timer = setTimeout(() => dismiss(id), 3000); return () => clearTimeout(timer); }, [item?.done, item?.error, id, dismiss]); if (!item) return null; const pct = item.total && item.total > 0 ? Math.min(100, (item.bytes / item.total) * 100) : null; const isIndeterminate = !item.done && !item.error && (item.total === null || item.total === 0); return (