'use client'; import { useState } from 'react'; import { AlertTriangle, Loader2, X } from 'lucide-react'; import { toast } from 'react-hot-toast'; export interface ConfirmationModalProps { show: boolean; title: string; // "Delete User: alex_smith?" description: string; // "This will remove the user from the system." itemName?: string; // The item being deleted (for display) affectedCount?: number; // Number of affected items (e.g., 47) consequence?: string; // "This cannot be undone." or "Audit logs will remain." onConfirm: () => Promise; onCancel: () => void; loading?: boolean; dangerLevel?: 'low' | 'medium' | 'high'; // Determines if confirmation text is required } export default function ConfirmationModal({ show, title, description, itemName, affectedCount, consequence, onConfirm, onCancel, loading = false, dangerLevel = 'medium' }: ConfirmationModalProps) { const [confirmText, setConfirmText] = useState(''); const [error, setError] = useState(null); if (!show) return null; const isHighRisk = dangerLevel === 'high'; const requiresTextConfirm = isHighRisk && affectedCount && affectedCount > 10; const canConfirm = !requiresTextConfirm || confirmText === 'DELETE'; const handleConfirm = async () => { if (requiresTextConfirm && confirmText !== 'DELETE') { setError('Type "DELETE" to confirm this action'); return; } try { await onConfirm(); setConfirmText(''); setError(null); } catch (err: any) { setError(err?.message || 'Failed to delete item'); } }; return (
{/* Header */}

{title}

{/* Content */}
{/* Description */}

{description}

{/* Item Name (if provided) */} {itemName && (

Item

{itemName}

)} {/* Consequence Warning */} {consequence && (

{consequence}

)} {/* Affected Items Count (for medium-risk+) */} {affectedCount && affectedCount > 0 && (
{affectedCount === 1 ? 'This will affect 1 item.' : `This will affect ${affectedCount} items.`}
)} {/* High-Risk Warning & Confirmation Input */} {requiresTextConfirm && (

Type "DELETE" to confirm this high-risk action

{ setConfirmText(e.target.value); setError(null); }} placeholder="Type DELETE" className="w-full px-3 py-2.5 bg-slate-800 border border-slate-700 rounded text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-primary disabled:opacity-50" disabled={loading} onKeyDown={(e) => { if (e.key === 'Enter' && canConfirm && !loading) { handleConfirm(); } }} /> {error && (

{error}

)}
)}
{/* Actions */}
); }