import { useEffect, useState } from "react"; import { AlertTriangle, Check, ChevronDown, ChevronUp, Copy, Loader2, X } from "lucide-react"; import { api, type CrashItem } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { useT } from "@/i18n"; export function CrashHistoryModal({ serverId, onClose, }: { serverId: string; onClose: () => void; }) { const t = useT(); const [loading, setLoading] = useState(true); const [crashes, setCrashes] = useState([]); const [expandedId, setExpandedId] = useState(null); const [copiedId, setCopiedId] = useState(null); useEffect(() => { let alive = true; void api .listCrashes(serverId, 30) .then((items) => { if (alive) { setCrashes(items); setLoading(false); } }) .catch(() => { if (alive) setLoading(false); }); return () => { alive = false; }; }, [serverId]); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [onClose]); const copyReport = async (item: CrashItem) => { try { await navigator.clipboard.writeText(item.full_log); setCopiedId(item.id); setTimeout(() => setCopiedId(null), 2500); } catch { /* clipboard write failed */ } }; const getCategoryColor = (category: CrashItem["category"]) => { switch (category) { case "assertion": return "bg-amber-500/15 text-amber-400 border-amber-500/30"; case "access_violation": case "stack_overflow": case "out_of_memory": return "bg-bad/15 text-bad border-bad/30"; case "network": case "database": return "bg-blue-500/15 text-blue-400 border-blue-500/30"; default: return "bg-muted/15 text-muted border-line"; } }; return (
{ if (e.target === e.currentTarget) onClose(); }} >

{t("crash.historyTitle")}

{loading ? (
) : crashes.length === 0 ? (

{t("crash.noCrashes")}

) : (
{crashes.map((item) => { const isExpanded = expandedId === item.id; const isCopied = copiedId === item.id; return (
{item.exception_code ? `${item.category} (${item.exception_code})` : item.category}

{item.title}

{item.date_str}

{item.explanation}

{isExpanded && (
                          {item.full_log}
                        
)}
); })}
)}
); }