"use client"; import { useEffect, useState } from "react"; import { X, ShieldAlert, CheckCircle2, Server, HelpCircle } from "lucide-react"; import { Badge } from "@/components/ui/Badge"; import { ThreatStat } from "@/lib/api"; import { formatAppLabel } from "@/lib/utils"; import { getMitigationSteps } from "./getMitigationSteps"; interface ThreatRecommendationsDrawerProps { threat: ThreatStat | null; onClose: () => void; } export function ThreatRecommendationsDrawer({ threat, onClose, }: ThreatRecommendationsDrawerProps) { const [isClosing, setIsClosing] = useState(false); const [activeThreat, setActiveThreat] = useState(null); // Sync threat to activeThreat and handle mounting/resetting close state useEffect(() => { if (threat) { setActiveThreat(threat); setIsClosing(false); document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, [threat]); if (!threat && !activeThreat) return null; const handleClose = () => { setIsClosing(true); setTimeout(() => { onClose(); setActiveThreat(null); setIsClosing(false); }, 480); // Match 500ms keyframe animation duration }; const displayThreat = threat || activeThreat; if (!displayThreat) return null; const sev = (displayThreat.severity || "").toLowerCase(); let badgeVariant: "red" | "orange" | "yellow" | "blue" | "green" = "blue"; if (sev.includes("high") || sev.includes("critical")) badgeVariant = "red"; else if (sev.includes("med")) badgeVariant = "orange"; else if (sev.includes("low")) badgeVariant = "yellow"; const mitigation = getMitigationSteps(displayThreat.threat_type || ""); return (
{/* Backdrop overlay (fade in/out over 0.5s via keyframes) */}
{/* Centered Modal Content Box (fades and scales over 0.5s via keyframes) */}
e.stopPropagation()} > {/* Header */}

Mitigation Guide

{/* Scrollable Body */}
{/* Threat Metadata Card */}
Threat Type
{displayThreat.threat_type || "Unknown Threat"} {displayThreat.severity}
Description

{displayThreat.description || "No detailed description available."}

{/* Technical details block */}

Technical Details

Source IP {displayThreat.ip_address || "-"}
Source MAC {displayThreat.mac_address || "-"}
Destination IP {displayThreat.dst_ip || "-"}
Application {formatAppLabel(displayThreat.app_label)}
Domain {displayThreat.domain || "-"}
Detected At {displayThreat.detected_at ? new Date(displayThreat.detected_at).toLocaleString() : "-"}
{/* Recommendations checklist */}

Recommendations & Actions

{mitigation.intro}

{mitigation.steps.map((step, idx) => (

{step.title}

{step.desc}

))}
{/* Footer Action */}
); }