"use client"; import Link from "next/link"; import { useCallback, useEffect, useMemo, useState } from "react"; import { cn } from "@/lib/utils"; import type { Readiness, ReadinessPill } from "@/lib/inbox/readiness"; import { MANIFEST_CHANGED } from "../timelineApi"; export type { Readiness }; // --------------------------------------------------------------------------- // THE READINESS BAR (umtool redesign L7b): under the workspace's top bar, one pill each for the quote check, the // links, the captures, the render and X's jar -- ✓, a count, ! or — -- read from what the Inbox reads for this // piece (GET /api/report/readiness, lib/inbox/readiness.ts) and read again after a write here. Each pill is a // click to its fix or its page; a clip with no media fetched selects that block. Read-only. // --------------------------------------------------------------------------- const GLYPH = { ok: "✓", bad: "!", none: "—" } as const; const TONE = { ok: "border-[color-mix(in_srgb,var(--color-good)_40%,transparent)] text-kept-text", count: "border-[color-mix(in_srgb,var(--color-dirty)_45%,transparent)] text-doubt-text", bad: "border-[color-mix(in_srgb,var(--color-bad)_55%,transparent)] bg-[color-mix(in_srgb,var(--color-bad)_10%,transparent)] text-reject-text", none: "border-seam-2 text-muted", } as const; export default function ReadinessBar({ project, initial, missing, onSelect, }: { project: string; initial: Readiness | null; /** The clips with no media fetched (the strip's "no media"): the captures pill counts them. */ missing: string[]; onSelect: (block: string) => void; }) { const [got, setGot] = useState(initial); const read = useCallback(async () => { try { const r = await fetch(`/api/report/readiness?project=${encodeURIComponent(project)}`, { cache: "no-store" }); if (r.ok) setGot((await r.json()) as Readiness); } catch { // The bar stays as it was. } }, [project]); useEffect(() => { if (!initial) void read(); }, [initial, read]); useEffect(() => { let t: ReturnType | null = null; const on = (e: Event) => { if ((e as CustomEvent).detail?.project !== project) return; if (t) clearTimeout(t); t = setTimeout(() => void read(), 400); }; window.addEventListener(MANIFEST_CHANGED, on); return () => { window.removeEventListener(MANIFEST_CHANGED, on); if (t) clearTimeout(t); }; }, [project, read]); const pills = useMemo(() => { const list = got?.pills ?? []; return list.map((p) => { if (p.id !== "captures" || !missing.length || p.state === "bad") return p; const why = `${missing.slice(0, 6).join(", ")}${missing.length > 6 ? ` and ${missing.length - 6} more` : ""}: no media fetched`; return { ...p, state: "count", count: (p.state === "count" ? p.count : 0) + missing.length, title: p.state === "count" ? `${p.title} · ${why}` : why, select: missing[0] }; }); }, [got, missing]); if (!pills.length) return null; return ( ); }