2026-07-28 10:05:08 +07:00
|
|
|
"use client";
|
|
|
|
|
|
2026-08-03 05:08:08 +07:00
|
|
|
import { useState } from "react";
|
2026-08-07 17:33:12 +07:00
|
|
|
import { Card } from "@/components/ui/card";
|
2026-07-28 10:05:08 +07:00
|
|
|
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;
|
2026-07-31 19:11:13 +07:00
|
|
|
analysis?: string | null;
|
2026-07-28 10:05:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const severityColor: Record<string, string> = {
|
|
|
|
|
none: "text-emerald-500",
|
|
|
|
|
low: "text-text-secondary",
|
|
|
|
|
medium: "text-accent-amber",
|
|
|
|
|
high: "text-accent-purple",
|
|
|
|
|
critical: "text-destructive",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function AiAnalysisPanel({
|
|
|
|
|
status,
|
|
|
|
|
severity,
|
|
|
|
|
confidence,
|
|
|
|
|
flags,
|
|
|
|
|
categories,
|
|
|
|
|
action,
|
|
|
|
|
score,
|
2026-07-31 19:11:13 +07:00
|
|
|
analysis,
|
2026-07-28 10:05:08 +07:00
|
|
|
}: AiAnalysisPanelProps) {
|
2026-08-03 05:08:08 +07:00
|
|
|
const [expanded, setExpanded] = useState(false);
|
|
|
|
|
|
2026-07-28 10:05:08 +07:00
|
|
|
if (!status || status === "pending") {
|
|
|
|
|
return (
|
2026-08-07 17:33:12 +07:00
|
|
|
<Card className={cn("[--card-spacing:0px]", "p-3")}>
|
2026-08-01 22:09:02 +07:00
|
|
|
<span className="text-xs text-text-secondary/50">
|
|
|
|
|
AI analysis pending
|
|
|
|
|
</span>
|
2026-08-07 17:33:12 +07:00
|
|
|
</Card>
|
2026-07-28 10:05:08 +07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-01 22:09:02 +07:00
|
|
|
const flagsArray =
|
|
|
|
|
typeof flags === "string" ? (flags ? JSON.parse(flags) : []) : flags || [];
|
|
|
|
|
const categoriesArray =
|
|
|
|
|
typeof categories === "string"
|
|
|
|
|
? categories
|
|
|
|
|
? JSON.parse(categories)
|
|
|
|
|
: []
|
|
|
|
|
: categories || [];
|
2026-07-28 10:05:08 +07:00
|
|
|
|
|
|
|
|
return (
|
2026-08-07 17:33:12 +07:00
|
|
|
<Card className={cn("space-y-2", "[--card-spacing:0px]", "p-3")}>
|
2026-07-28 10:05:08 +07:00
|
|
|
<div className="flex items-center gap-2">
|
2026-08-01 22:09:02 +07:00
|
|
|
<span className="text-xs font-semibold tracking-wide uppercase text-text-secondary">
|
|
|
|
|
AI Analysis
|
|
|
|
|
</span>
|
|
|
|
|
<span
|
|
|
|
|
className={cn(
|
|
|
|
|
"text-[10px] font-mono px-1.5 py-0.5 rounded",
|
|
|
|
|
status === "clean" && "bg-emerald-500/10 text-emerald-500",
|
|
|
|
|
status === "flagged" && "bg-accent-purple/10 text-accent-purple",
|
|
|
|
|
status === "warn" && "bg-accent-amber/10 text-accent-amber",
|
|
|
|
|
status === "error" && "bg-destructive/10 text-destructive",
|
|
|
|
|
)}
|
|
|
|
|
>
|
2026-07-28 10:05:08 +07:00
|
|
|
{status}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{severity && (
|
|
|
|
|
<div className="flex items-center gap-2 text-xs">
|
|
|
|
|
<span className="text-text-secondary/60">Severity:</span>
|
2026-08-01 22:09:02 +07:00
|
|
|
<span
|
|
|
|
|
className={cn(
|
|
|
|
|
"font-mono font-medium",
|
|
|
|
|
severityColor[severity] || "",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{severity}
|
|
|
|
|
</span>
|
2026-07-28 10:05:08 +07:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{confidence !== null && confidence !== undefined && (
|
|
|
|
|
<div className="flex items-center gap-2 text-xs">
|
|
|
|
|
<span className="text-text-secondary/60">Confidence:</span>
|
|
|
|
|
<span className="font-mono">{(confidence * 100).toFixed(0)}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{score !== null && score !== undefined && (
|
|
|
|
|
<div className="flex items-center gap-2 text-xs">
|
|
|
|
|
<span className="text-text-secondary/60">Score:</span>
|
|
|
|
|
<span className="font-mono">{score.toFixed(2)}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{flagsArray.length > 0 && (
|
|
|
|
|
<div className="flex flex-wrap gap-1">
|
|
|
|
|
{flagsArray.map((f: string) => (
|
2026-08-01 22:09:02 +07:00
|
|
|
<span
|
|
|
|
|
key={f}
|
|
|
|
|
className="text-[10px] font-mono px-1.5 py-0.5 rounded bg-destructive/10 text-destructive"
|
|
|
|
|
>
|
|
|
|
|
{f}
|
|
|
|
|
</span>
|
2026-07-28 10:05:08 +07:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{categoriesArray.length > 0 && (
|
|
|
|
|
<div className="flex flex-wrap gap-1">
|
|
|
|
|
{categoriesArray.map((c: string) => (
|
2026-08-01 22:09:02 +07:00
|
|
|
<span
|
|
|
|
|
key={c}
|
|
|
|
|
className="text-[10px] font-mono px-1.5 py-0.5 rounded bg-primary/10 text-primary"
|
|
|
|
|
>
|
|
|
|
|
{c}
|
|
|
|
|
</span>
|
2026-07-28 10:05:08 +07:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-07-31 19:11:13 +07:00
|
|
|
{analysis && (
|
2026-08-03 05:08:08 +07:00
|
|
|
<div className="border-l-2 border-glass-border pl-2">
|
|
|
|
|
<p
|
|
|
|
|
className={cn(
|
|
|
|
|
"text-xs leading-relaxed text-text-secondary/90",
|
|
|
|
|
!expanded && "line-clamp-3",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{analysis}
|
|
|
|
|
</p>
|
|
|
|
|
{analysis.length > 120 && (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setExpanded((v) => !v)}
|
|
|
|
|
className="mt-1 text-[10px] font-medium uppercase tracking-wide text-text-secondary/50 transition-colors hover:text-text-primary"
|
|
|
|
|
>
|
|
|
|
|
{expanded ? "Show less" : "Show more"}
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-07-31 19:11:13 +07:00
|
|
|
)}
|
|
|
|
|
|
2026-07-28 10:05:08 +07:00
|
|
|
{action && action !== "none" && (
|
|
|
|
|
<div className="text-xs">
|
|
|
|
|
<span className="text-text-secondary/60">Recommended: </span>
|
|
|
|
|
<span className="font-mono text-accent-amber">{action}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-08-07 17:33:12 +07:00
|
|
|
</Card>
|
2026-07-28 10:05:08 +07:00
|
|
|
);
|
|
|
|
|
}
|