import { useEffect, forwardRef } from 'react' interface Props { /** Title shown in the dialog header. */ title: string /** Body text explaining what will happen. */ message: string /** Label for the confirm button. Defaults to "Confirm". */ confirmLabel?: string /** Called when the user confirms. */ onConfirm: () => void /** Optional: called when the user cancels. */ onCancel?: () => void /** Danger style — makes confirm button red. Default true. */ danger?: boolean } const ConfirmDialog = forwardRef(function ConfirmDialog({ title, message, confirmLabel = 'Confirm', onConfirm, onCancel, danger = true, }, ref) { useEffect(() => { if (!ref || !('current' in ref) || !ref.current) return const dialog = ref.current const handleClose = () => onCancel?.() dialog.addEventListener('close', handleClose) return () => dialog.removeEventListener('close', handleClose) }, [ref, onCancel]) const handleConfirm = () => { if (ref && 'current' in ref && ref.current) ref.current.close('confirm') onConfirm() } const handleCancel = () => { if (ref && 'current' in ref && ref.current) ref.current.close('cancel') } return ( { if (ref && 'current' in ref && e.target === ref.current) handleCancel() }} >

{title}

{message}

) }) export default ConfirmDialog