"use client"; import { useState } from "react"; import { Loader2, RefreshCw, Tag } from "lucide-react"; import { api } from "@/lib/api"; import { toast } from "@/lib/toast"; import type { DocumentDetail } from "@/lib/types"; export default function ClassifyPanel({ detail, provider, onRefresh, }: { detail: DocumentDetail; provider: string | null; onRefresh: () => void; }) { const [busy, setBusy] = useState(false); const c = detail.classification; const reClassify = async () => { setBusy(true); try { await api.reClassify(detail.id, provider ?? undefined); toast.success("Re-classified"); onRefresh(); } catch (e: any) { toast.error("Classification failed", e?.message ?? String(e)); } finally { setBusy(false); } }; return (

Classification

{!c ? (
) : ( <>

Detected type

{c.doc_type.replace(/_/g, " ")}

Confidence

{Math.round(c.confidence * 100)}%

{c.rationale && (

{c.rationale}

)}
{c.candidates?.length > 0 && (

Other candidates

{c.candidates.map((cand, i) => (
{String(cand.type).replace(/_/g, " ")}
{Math.round((cand.confidence ?? 0) * 100)}%
))}
)} )}
); }