import React, { useState, useCallback } from 'react'; import { X, ChevronLeft, ChevronRight } from 'lucide-react'; export interface WizardStep { id: string; title: string; description?: string; component: React.ComponentType; isOptional?: boolean; validate?: () => Promise | boolean; } export interface WizardStepProps { onNext: () => void; onBack: () => void; onComplete: () => void; isFirstStep: boolean; isLastStep: boolean; currentStepIndex: number; totalSteps: number; goToStep: (index: number) => void; } interface WizardModalProps { isOpen: boolean; onClose: () => void; onComplete: (data?: any) => void; title: string; steps: WizardStep[]; icon?: React.ReactNode; size?: 'sm' | 'md' | 'lg' | 'xl' | '2xl'; } export const WizardModal: React.FC = ({ isOpen, onClose, onComplete, title, steps, icon, size = 'xl' }) => { const [currentStepIndex, setCurrentStepIndex] = useState(0); const [isValidating, setIsValidating] = useState(false); const currentStep = steps[currentStepIndex]; const isFirstStep = currentStepIndex === 0; const isLastStep = currentStepIndex === steps.length - 1; const sizeClasses = { sm: 'max-w-md', md: 'max-w-2xl', lg: 'max-w-4xl', xl: 'max-w-5xl', '2xl': 'max-w-7xl' }; const handleNext = useCallback(async () => { // Validate current step if validator exists if (currentStep.validate) { setIsValidating(true); try { const isValid = await currentStep.validate(); if (!isValid) { setIsValidating(false); return; } } catch (error) { console.error('Validation error:', error); setIsValidating(false); return; } setIsValidating(false); } if (isLastStep) { handleComplete(); } else { setCurrentStepIndex(prev => Math.min(prev + 1, steps.length - 1)); } }, [currentStep, isLastStep, steps.length]); const handleBack = useCallback(() => { setCurrentStepIndex(prev => Math.max(prev - 1, 0)); }, []); const handleComplete = useCallback(() => { onComplete(); handleClose(); }, [onComplete]); const handleClose = useCallback(() => { setCurrentStepIndex(0); onClose(); }, [onClose]); const goToStep = useCallback((index: number) => { if (index >= 0 && index < steps.length) { setCurrentStepIndex(index); } }, [steps.length]); if (!isOpen) return null; const StepComponent = currentStep.component; const progressPercentage = ((currentStepIndex + 1) / steps.length) * 100; return ( <> {/* Backdrop */}
{/* Modal */}
e.stopPropagation()} > {/* Header */}
{/* Title Bar */}
{icon && (
{icon}
)}

{title}

{currentStep.description || `Step ${currentStepIndex + 1} of ${steps.length}`}

{/* Progress Bar */}
{steps.map((step, index) => (
{currentStep.title} {currentStepIndex + 1} / {steps.length}
{/* Step Content */}
{/* Footer Navigation */}
{/* Back Button */} {!isFirstStep && ( )}
{/* Skip Button (for optional steps) */} {currentStep.isOptional && !isLastStep && ( )} {/* Next/Complete Button */}
{/* Animation Styles */} ); };