import { useEffect, useRef } from 'react' interface ConfirmModalProps { isOpen: boolean title: string message: string confirmText?: string cancelText?: string confirmStyle?: 'danger' | 'primary' onConfirm: () => void onCancel: () => void } export function ConfirmModal({ isOpen, title, message, confirmText = 'Confirm', cancelText = 'Cancel', confirmStyle = 'danger', onConfirm, onCancel, }: ConfirmModalProps) { const modalOverlayRef = useRef(null) const confirmButtonRef = useRef(null) // A11Y: Handle Escape key to close modal useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape' && isOpen) { onCancel() } } if (isOpen) { document.addEventListener('keydown', handleKeyDown) // Focus confirm button when modal opens confirmButtonRef.current?.focus() } return () => { document.removeEventListener('keydown', handleKeyDown) } }, [isOpen, onCancel]) if (!isOpen) return null const handleOverlayClick = (e: React.MouseEvent) => { if (e.target === e.currentTarget) { onCancel() } } return (

{title}

{message}

) } const styles: Record = { overlay: { position: 'fixed', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: 'rgba(0, 0, 0, 0.5)', display: 'flex', justifyContent: 'center', alignItems: 'center', zIndex: 1200, }, modal: { backgroundColor: 'white', borderRadius: '8px', padding: '24px', width: '400px', maxWidth: '90%', boxShadow: '0 8px 32px rgba(0, 0, 0, 0.2)', }, title: { margin: '0 0 12px 0', fontSize: '18px', fontWeight: 600, color: '#212529', }, message: { margin: '0 0 24px 0', fontSize: '14px', color: '#495057', lineHeight: 1.5, }, actions: { display: 'flex', justifyContent: 'flex-end', gap: '12px', }, cancelButton: { padding: '10px 20px', backgroundColor: '#f8f9fa', color: '#495057', border: '1px solid #dee2e6', borderRadius: '6px', fontSize: '14px', cursor: 'pointer', }, confirmButton: { padding: '10px 20px', color: 'white', border: 'none', borderRadius: '6px', fontSize: '14px', fontWeight: 500, cursor: 'pointer', }, dangerButton: { backgroundColor: '#dc3545', }, primaryButton: { backgroundColor: '#0066cc', }, } export default ConfirmModal