import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { AlertCircle, AlertTriangle, CheckCircle2, Clock, Eye } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import type { Incident } from '@/hooks/admin/useIncidents'; import { useAcknowledgeIncident, useResolveIncident } from '@/hooks/admin/useIncidents'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { Textarea } from '@/components/ui/textarea'; import { Label } from '@/components/ui/label'; import { useState } from 'react'; interface IncidentsPanelProps { incidents?: Incident[]; isLoading: boolean; } const SEVERITY_CONFIG = { critical: { color: 'text-destructive', icon: AlertCircle, badge: 'destructive' }, high: { color: 'text-orange-500', icon: AlertTriangle, badge: 'default' }, medium: { color: 'text-yellow-500', icon: AlertTriangle, badge: 'secondary' }, low: { color: 'text-blue-500', icon: AlertTriangle, badge: 'outline' }, }; const STATUS_CONFIG = { open: { label: 'Open', color: 'bg-red-500/10 text-red-600' }, investigating: { label: 'Investigating', color: 'bg-yellow-500/10 text-yellow-600' }, resolved: { label: 'Resolved', color: 'bg-green-500/10 text-green-600' }, closed: { label: 'Closed', color: 'bg-gray-500/10 text-gray-600' }, }; export function IncidentsPanel({ incidents, isLoading }: IncidentsPanelProps) { const acknowledgeIncident = useAcknowledgeIncident(); const resolveIncident = useResolveIncident(); const [resolutionNotes, setResolutionNotes] = useState(''); const [selectedIncident, setSelectedIncident] = useState(null); const handleAcknowledge = (incidentId: string) => { acknowledgeIncident.mutate(incidentId); }; const handleResolve = () => { if (selectedIncident) { resolveIncident.mutate({ incidentId: selectedIncident, resolutionNotes, resolveAlerts: true, }); setResolutionNotes(''); setSelectedIncident(null); } }; if (isLoading) { return ( Active Incidents Loading incidents...
); } if (!incidents || incidents.length === 0) { return ( Active Incidents No active incidents

All clear - no incidents detected

); } const openIncidents = incidents.filter(i => i.status === 'open' || i.status === 'investigating'); return ( Active Incidents {openIncidents.length} active • {incidents.length} total Automatically detected incidents from correlated alerts {incidents.map((incident) => { const severityConfig = SEVERITY_CONFIG[incident.severity]; const statusConfig = STATUS_CONFIG[incident.status]; const Icon = severityConfig.icon; return (
{incident.incident_number} {incident.severity.toUpperCase()} {statusConfig.label} {incident.alert_count} alerts

{incident.title}

{incident.description && (

{incident.description}

)}
Detected: {formatDistanceToNow(new Date(incident.detected_at), { addSuffix: true })} {incident.acknowledged_at && ( Acknowledged: {formatDistanceToNow(new Date(incident.acknowledged_at), { addSuffix: true })} )}
{incident.status === 'open' && ( )} {(incident.status === 'open' || incident.status === 'investigating') && ( Resolve Incident {incident.incident_number} Add resolution notes and close this incident. All linked alerts will be automatically resolved.