import React, {useEffect, useState} from 'react'; import {createPortal} from 'react-dom'; import {AlertTriangle, Check, Info, LucideIcon, X} from 'lucide-react'; import Button from "@/components/ui/Button"; export type AlertType = 'alert' | 'danger' | 'informatif' | 'success'; interface AlertBoxProps { title: string; message: string; type: AlertType; confirmText?: string; cancelText?: string; onConfirm: () => Promise; onCancel: () => void; } interface AlertConfig { background: string; borderColor: string; icon: LucideIcon; iconBg: string; } 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 getButtonVariant(alertType: AlertType): 'warning' | 'danger' | 'info' | 'success' { switch (alertType) { case 'alert': return 'warning'; case 'danger': return 'danger'; case 'informatif': return 'info'; case 'success': default: return 'success'; } } function getAlertConfig(alertType: AlertType): AlertConfig { switch (alertType) { case 'alert': return { background: 'bg-warning', borderColor: 'border-warning/30', icon: AlertTriangle, iconBg: 'bg-warning/10' }; case 'danger': return { background: 'bg-error', borderColor: 'border-error/30', icon: X, iconBg: 'bg-error/10' }; case 'informatif': return { background: 'bg-info', borderColor: 'border-info/30', icon: Info, iconBg: 'bg-info/10' }; case 'success': default: return { background: 'bg-success', borderColor: 'border-success/30', icon: Check, iconBg: 'bg-success/10' }; } } const alertSettings = getAlertConfig(type); const AlertIcon = alertSettings.icon; const alertContent = (

{title}

{message}

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