"use client"; import Link from "next/link"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { Check, X, Sparkles, ArrowRight } from "lucide-react"; import { api } from "@/lib/client/api"; import { toast } from "@/components/ui/toast"; import { Button } from "@/components/ui/button"; import { Empty, Spinner } from "@/components/ui/primitives"; import { cn, timeAgo } from "@/lib/utils"; import type { Suggestion } from "@/lib/graph/types"; export function useDecide() { const qc = useQueryClient(); return useMutation({ mutationFn: (v: { id: string; status: "accepted" | "rejected" }) => api("/api/graph/suggestions", { method: "PATCH", json: v }), onSuccess: (_d, v) => { toast(v.status === "accepted" ? "Link accepted" : "Suggestion rejected", { tone: v.status === "accepted" ? "success" : "neutral" }); qc.invalidateQueries({ queryKey: ["graph"] }); qc.invalidateQueries({ queryKey: ["graph-suggestions"] }); qc.invalidateQueries({ queryKey: ["graph-neighbors"] }); qc.invalidateQueries({ queryKey: ["backlinks"] }); }, onError: (e: any) => toast("Could not update suggestion", { description: e.message, tone: "danger" }), }); } export function ConfidenceBar({ value }: { value: number | null }) { const v = Math.round((value ?? 0) * 100); return = 70 ? "bg-success" : v >= 45 ? "bg-ai" : "bg-warning")} style={{ width: `${v}%` }} />{v}%; } export function SuggestionItem({ s, onFocus, dense }: { s: Suggestion; onFocus?: (id: string) => void; dense?: boolean }) { const decide = useDecide(); const busy = decide.isPending && decide.variables?.id === s.id; const P = ({ id, title, icon }: { id: string; title: string; icon: string | null }) => onFocus ? : {icon ?? "đź“„"} {title}; return (

{s.rationale &&

{s.rationale}

}
{!dense && s.model && {s.model}}
); } export function SuggestionList({ items, loading, onFocus, dense, emptyHint }: { items: Suggestion[]; loading?: boolean; onFocus?: (id: string) => void; dense?: boolean; emptyHint?: string }) { if (loading) return
; if (!items.length) return } title="No pending suggestions" hint={emptyHint ?? "Run “Suggest connections” on a page or on the whole workspace. Candidates come from embedding similarity and are confirmed by a quick model."} />; return
{items.map((s) => )}
; }