"use client"; import { useState } from "react"; import { useMutation } from "@tanstack/react-query"; import { api } from "@/lib/api"; import type { SimilarCasesResponse } from "@/lib/types"; import { Loader2, Search, ExternalLink, AlertTriangle, Scale, RefreshCw, } from "lucide-react"; interface SimilarCaseFinderProps { caseId: string; } const inputClass = "w-full rounded-md border border-neutral-200 bg-white px-3 py-2 text-sm text-neutral-900 outline-none transition-colors focus:border-neutral-400 focus:ring-1 focus:ring-neutral-400"; function RelevanceBadge({ score }: { score: number }) { const pct = Math.round(score * 100); let color = "bg-neutral-100 text-neutral-600"; if (pct >= 80) color = "bg-emerald-50 text-emerald-700"; else if (pct >= 60) color = "bg-blue-50 text-blue-700"; else if (pct >= 40) color = "bg-amber-50 text-amber-700"; return ( {pct}% ); } export function SimilarCaseFinder({ caseId }: SimilarCaseFinderProps) { const [description, setDescription] = useState(""); const mutation = useMutation({ mutationFn: (req: { case_id: string; description: string }) => api.post("/ai/similar-cases", req), }); function handleSearch(e?: React.FormEvent) { e?.preventDefault(); mutation.mutate({ case_id: caseId, description }); } return (