"use client";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { buttonVariants } from "@/components/ui/button";
import { Dialog } from "@/components/ui/dialog";
import { useHydrated } from "@/components/ui/use-hydrated";
import type { RefreshPlan } from "yt-dlp-transcript-common/lib/report/draft/refresh/types";
// ---------------------------------------------------------------------------
// REFRESH, plan then confirm (plans/umtool-redesign.md, R4). The plan is the
// editor's dry run (`report-draft {"task": "refresh", "dryRun": true}`, through
// /api/articles/refresh): the iteration refreshed and what it is searched
// again with, each channel's fetches (or why one is skipped), the site built
// locally, the model and the cap. Nothing is written until **Refresh** --
// then it is one editor job (the Running list), and the Overview shows what
// it found.
//
// The ⋯ menu's item (RefreshMenuItem) and the Next card's action (`?refresh=1`)
// open the one dialog the page holds (RefreshHost): a menu item's own dialog
// would close with the menu.
// ---------------------------------------------------------------------------
const OPEN_EVENT = "umtool:refresh";
const usd = (n: number) => `$${n.toFixed(2)}`;
const day = (iso: string | null | undefined) => (iso ? iso.slice(0, 10) : "");
function Row({ k, children }: { k: string; children: React.ReactNode }) {
return (
<>
{k}
{children}
>
);
}
function PlanBody({ p }: { p: RefreshPlan }) {
const fetched = p.channels.filter((c) => !c.skip);
return (
i{p.parent.n} ({p.parent.kind}, made {day(p.parent.at)})
{p.parent.question ? {p.parent.question} : null}
{p.parent.queries.map((q) => `“${q}”`).join(", ")}
against {p.parent.knownCount.toLocaleString("en-US")} recording{p.parent.knownCount === 1 ? "" : "s"} matched then · {p.parent.citedCount} cited quote{p.parent.citedCount === 1 ? "" : "s"} read again
{!p.fetch ? (
"none: the corpus is read as it stands"
) : (