import { useEffect, useState } from 'react'; import { X, Download, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import type { ExportProgress } from '@/lib/exporter'; interface ExportDialogProps { isOpen: boolean; onClose: () => void; progress: ExportProgress | null; isExporting: boolean; error: string | null; onCancel?: () => void; exportFormat?: 'mp4' | 'gif'; } export function ExportDialog({ isOpen, onClose, progress, isExporting, error, onCancel, exportFormat = 'mp4', }: ExportDialogProps) { const [showSuccess, setShowSuccess] = useState(false); // Reset showSuccess when a new export starts or dialog reopens useEffect(() => { if (isExporting) { setShowSuccess(false); } }, [isExporting]); // Reset showSuccess when dialog opens fresh useEffect(() => { if (isOpen && !isExporting && !progress) { setShowSuccess(false); } }, [isOpen, isExporting, progress]); useEffect(() => { if (!isExporting && progress && progress.percentage >= 100 && !error) { setShowSuccess(true); const timer = setTimeout(() => { setShowSuccess(false); onClose(); }, 2000); return () => clearTimeout(timer); } }, [isExporting, progress, error, onClose]); if (!isOpen) return null; const formatLabel = exportFormat === 'gif' ? 'GIF' : 'Video'; // Determine if we're in the compiling phase (frames done but still exporting) const isCompiling = isExporting && progress && progress.percentage >= 100 && exportFormat === 'gif'; const isFinalizing = progress?.phase === 'finalizing'; const renderProgress = progress?.renderProgress; // Get status message based on phase const getStatusMessage = () => { if (error) return 'Please try again'; if (isCompiling || isFinalizing) { if (renderProgress !== undefined && renderProgress > 0) { return `Compiling GIF... ${renderProgress}%`; } return 'Compiling GIF... This may take a while'; } return 'This may take a moment...'; }; // Get title based on phase const getTitle = () => { if (error) return 'Export Failed'; if (isCompiling || isFinalizing) return 'Compiling GIF'; return `Exporting ${formatLabel}`; }; return ( <>
{error}
{formatLabel} saved successfully!