"use client"; import { useState } from "react"; import { Badge } from "@/components/primitives/badge"; import { Progress } from "@/components/primitives/progress"; import { cn } from "@/lib/utils"; interface AiAnalysisPanelProps { status?: string | null; severity?: string | null; confidence?: number | null; flags?: string[] | string | null; categories?: string[] | string | null; action?: string | null; score?: number | null; analysis?: string | null; } const severityColor: Record = { none: "text-[var(--color-ink-soft)]", low: "text-[var(--color-ink-soft)]", medium: "text-[var(--color-amber)]", high: "text-orange-500", critical: "text-[var(--color-vermilion)]", }; export function AiAnalysisPanel({ status, severity, confidence, flags, categories, action, score, analysis, }: AiAnalysisPanelProps) { const [expanded, setExpanded] = useState(false); if (!status || status === "pending") { return (
AI analysis pending
); } const flagsArray = typeof flags === "string" ? (flags ? JSON.parse(flags) : []) : flags || []; const categoriesArray = typeof categories === "string" ? categories ? JSON.parse(categories) : [] : categories || []; const statusTone = status === "clean" ? "signal" : status === "flagged" ? "vermilion" : status === "warn" ? "amber" : "neutral"; return (
AI Analysis {status}
{severity && (
Severity: {severity}
)} {confidence !== null && confidence !== undefined && (
Confidence
)} {score !== null && score !== undefined && (
Score {score.toFixed(2)}
)} {flagsArray.length > 0 && (
{flagsArray.map((f: string) => ( {f} ))}
)} {categoriesArray.length > 0 && (
{categoriesArray.map((c: string) => ( {c} ))}
)} {analysis && (

{analysis}

{analysis.length > 120 && ( )}
)} {action && action !== "none" && (
Recommended: {action}
)}
); }