import React, { useEffect } from 'react'; import { createPortal } from 'react-dom'; import { AnimatePresence, motion } from 'framer-motion'; import Button from '@/components/ui/Button.tsx'; import { X } from 'lucide-react'; import { useTranslation } from '@/hooks/useI18n.tsx'; import { useFocusTrap } from '@/hooks/ui/useFocusTrap.ts'; import { useEscapeKey } from '@/hooks/useKeyboard.ts'; interface WizardProps { isOpen: boolean; onClose: () => void; title: string; children?: React.ReactNode; } const Wizard = ({ isOpen, onClose, title, children }: WizardProps): React.ReactPortal | null => { const { t } = useTranslation(); const trapRef = useFocusTrap(isOpen); useEscapeKey(onClose, { enabled: isOpen }); useEffect(() => { if (isOpen) { document.body.style.overflow = 'hidden'; } else { document.body.style.overflow = ''; } return () => { document.body.style.overflow = ''; }; }, [isOpen]); // Use portal for modal to render outside main DOM tree for better performance const modalContent = ( {isOpen && ( e.stopPropagation()} >

{title}

{children}
)}
); // Render modal in portal for better performance and z-index management return isOpen && typeof document !== 'undefined' ? createPortal(modalContent, document.body) : null; }; export default Wizard;