import { useEffect, useState, useRef } from "react";
import { useParams, Link } from "react-router-dom";
import { forgesight } from "@/lib/api";
import AgentTranscript from "@/components/AgentTranscript";
import ReportDownloader from "@/components/ReportDownloader";
import { ArrowLeft, Loader2 } from "lucide-react";
export default function ReportView() {
const { id } = useParams();
const [result, setResult] = useState(null);
const [loading, setLoading] = useState(true);
const reportRef = useRef(null);
useEffect(() => {
async function load() {
try {
const data = await forgesight.getInspection(id);
setResult(data);
} catch (e) {
console.error("Failed to load inspection", e);
} finally {
setLoading(false);
}
}
load();
}, [id]);
if (loading) {
return (
);
}
if (!result) {
return (
Inspection not found.
);
}
// Same logic to extract summary as in backend, since frontend might not have `result.summary` populated if we just fetched raw doc
// Wait, backend does not attach `.summary` to raw doc, it's generated by `_summarize(doc)` for Feed.
// We can write a quick helper here.
const agents = result?.transcript?.agents || [];
const inspector = agents.find((a) => a.role === "inspector")?.output?.parsed || {};
const reporter = agents.find((a) => a.role === "reporter")?.output?.parsed || {};
const action = agents.find((a) => a.role === "action")?.output?.parsed || {};
const defects = inspector.defects || [];
const summary = {
verdict: inspector.verdict || "warn",
confidence: inspector.confidence || 0,
defect_count: defects.length,
priority: action.priority || "P2",
};
return (
Back to Feed
Inspection Report
ID: {result.id}
{/* RIGHT — transcript (Using 12 columns since we don't have the image input UI here) */}
);
}
function SummaryStat({ label, value, kind }) {
const color =
kind === "pass" ? "text-[#10B981]" :
kind === "warn" ? "text-[#F59E0B]" :
kind === "fail" ? "text-[#ED1C24]" : "text-white";
return (
);
}