"use client"; import { Check, Eye, Link2 } from "lucide-react"; import { useState } from "react"; import type { Watchlist } from "@/lib/api"; import { ownerFetch } from "@/lib/owner"; /** Adds an entity/source to the user's default watchlist (created on demand). */ export function WatchButton({ kind, value, label }: { kind: "entity" | "source" | "keyword" | "category"; value: string; label?: string }) { const [state, setState] = useState<"idle" | "busy" | "done" | "error">("idle"); const add = async (): Promise => { setState("busy"); try { const { items } = await ownerFetch<{ items: Watchlist[] }>("/api/v1/watchlists"); let wl = items[0]; if (!wl) wl = await ownerFetch("/api/v1/watchlists", { method: "POST", body: JSON.stringify({ name: "My watchlist", items: [] }) }); const existing = (wl.items ?? []).map((i) => ({ kind: i.kind, value: i.value })); if (!existing.some((i) => i.kind === kind && i.value === value)) existing.push({ kind, value }); await ownerFetch(`/api/v1/watchlists/${wl.id}`, { method: "PUT", body: JSON.stringify({ items: existing }) }); setState("done"); } catch { setState("error"); } }; return ( ); } export function ShareButton({ path }: { path: string }) { const [done, setDone] = useState(false); return ( ); }