import {useEffect, useState} from 'react'; import {createPortal} from 'react-dom'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faCheck, faExclamationTriangle, faInfoCircle, faTimes} from '@fortawesome/free-solid-svg-icons'; import ConfirmButton from "@/components/form/ConfirmButton"; import CancelButton from "@/components/form/CancelButton"; export type AlertType = 'alert' | 'danger' | 'informatif' | 'success'; interface AlertBoxProps { title: string; message: string; type: AlertType; confirmText?: string; cancelText?: string; onConfirm: () => Promise; onCancel: () => void; } export default function AlertBox( { title, message, type, confirmText = 'Confirmer', cancelText = 'Annuler', onConfirm, onCancel }: AlertBoxProps) { const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); return () => setMounted(false); }, []); function getAlertConfig(alertType: AlertType) { switch (alertType) { case 'alert': return { background: 'bg-warning', borderColor: 'border-warning/30', icon: faExclamationTriangle, iconBg: 'bg-warning/10' }; case 'danger': return { background: 'bg-error', borderColor: 'border-error/30', icon: faTimes, iconBg: 'bg-error/10' }; case 'informatif': return { background: 'bg-info', borderColor: 'border-info/30', icon: faInfoCircle, iconBg: 'bg-info/10' }; case 'success': default: return { background: 'bg-success', borderColor: 'border-success/30', icon: faCheck, iconBg: 'bg-success/10' }; } } const alertSettings = getAlertConfig(type); const alertContent = (

{title}

{message}

); if (!mounted) return null; return createPortal(alertContent, document.body); }