"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 ( Zusaetzliche Beschreibung (optional) setDescription(e.target.value)} placeholder="z.B. 'SEP-Lizenzierung im Mobilfunkbereich, FRAND-Verteidigung...'" rows={2} className={inputClass} disabled={mutation.isPending} /> {mutation.isPending ? ( <> Suche laeuft... > ) : ( <> Aehnliche Faelle suchen > )} {mutation.isError && ( Suche fehlgeschlagen Die youpc.org-Datenbank ist moeglicherweise nicht verfuegbar. handleSearch()} className="inline-flex items-center gap-1 text-sm text-neutral-500 transition-colors hover:text-neutral-700" > Erneut versuchen )} {mutation.data && ( {mutation.data.count} aehnliche{" "} {mutation.data.count === 1 ? "Fall" : "Faelle"} gefunden handleSearch()} disabled={mutation.isPending} className="inline-flex items-center gap-1 rounded-md border border-neutral-200 px-2.5 py-1.5 text-xs font-medium text-neutral-600 transition-colors hover:bg-neutral-50" > Aktualisieren {mutation.data.cases?.length === 0 && ( Keine aehnlichen UPC-Faelle gefunden. )} {mutation.data.cases?.map((c, i) => ( {c.case_number} {c.url && ( )} {c.title} {c.court && {c.court}} {c.date && {c.date}} {c.explanation} {c.key_holdings && ( Relevante Entscheidungsgruende {c.key_holdings} )} ))} )} ); }
Suche fehlgeschlagen
Die youpc.org-Datenbank ist moeglicherweise nicht verfuegbar.
{mutation.data.count} aehnliche{" "} {mutation.data.count === 1 ? "Fall" : "Faelle"} gefunden
Keine aehnlichen UPC-Faelle gefunden.
{c.title}
{c.explanation}
Relevante Entscheidungsgruende
{c.key_holdings}