import React, { useEffect } from 'react'; import { Modal } from '../ui/modal'; import { ProgressBar } from '../ui/progress'; import Button from '../ui/button/Button'; export interface ProgressModalProps { isOpen: boolean; title: string; percentage: number; // 0-100 status: 'pending' | 'processing' | 'completed' | 'error'; message: string; details?: { current: number; total: number; completed: number; currentItem?: string; phase?: string; }; onClose?: () => void; onCancel?: () => void; taskId?: string; } export default function ProgressModal({ isOpen, title, percentage, status, message, details, onClose, onCancel, taskId, }: ProgressModalProps) { // Auto-close on completion after 2 seconds // Don't auto-close on error - let user manually close to see error details useEffect(() => { if (status === 'completed' && onClose) { const timer = setTimeout(() => { onClose(); }, 2000); return () => clearTimeout(timer); } // Don't auto-close on error - user should manually dismiss }, [status, onClose]); // Determine color based on status const getProgressColor = (): 'primary' | 'success' | 'error' | 'warning' => { if (status === 'error') return 'error'; if (status === 'completed') return 'success'; if (status === 'processing') return 'primary'; return 'primary'; }; // Get status icon const getStatusIcon = () => { if (status === 'completed') { return ( ); } if (status === 'error') { return ( ); } // Processing/Pending - spinner return ( ); }; return ( {})} className="max-w-lg" showCloseButton={status === 'completed' || status === 'error'} >
{/* Header */}
{getStatusIcon()}

{title}

{message}

{/* Progress Bar */}
{/* Details */} {details && (
{details.currentItem && (
Current:{' '} {details.currentItem}
)} {details.total > 0 && (
Progress:{' '} {details.current} of {details.total} completed
)} {details.phase && (
Phase: {details.phase}
)}
)} {/* Task ID (for debugging) */} {taskId && import.meta.env.DEV && (
Task ID: {taskId}
)} {/* Footer */}
{onCancel && status !== 'completed' && status !== 'error' && ( )} {(status === 'completed' || status === 'error') && onClose && ( )}
); }