"use client";
import Link from "next/link";
import { useState } from "react";
import { postBenchHref } from "@/lib/hrefs";
import { comboKnobs } from "umtool-report-to-video/post-combo";
import type { ComboInfo } from "./review/ComboBadge";
// ---------------------------------------------------------------------------
// THE POST BENCH's COMBO PANEL (report-to-video/post-combo.mjs; knobs.md, "The
// combo counter"): when this item's attachment is one other items of the cut
// play too -- its repeat group in the cut's order (each post's date, the tier
// that matched, a link to its bench), which use this is, and the badge on THIS
// item turned off or on: one write (updatePostCombo, POST /api/report/post-combo
// {op: "set"}), the writer `umtool posts combo
off|on` runs. An item
// with its badge off still counts: the next use is still ×(n+1).
// ---------------------------------------------------------------------------
const TIER: Record = { "media-id": "the same X media", sha256: "the same file", audio: "the same sound" };
export default function PostComboPanel({
project, entry, token, combo, render, onEntry,
}: {
project: string;
entry: Record & { id: string; combo?: unknown };
token: string | null;
combo: ComboInfo;
render: Record;
onEntry: (entry: Record & { id: string }, token: string | null) => void;
}) {
const [error, setError] = useState(null);
const [busy, setBusy] = useState(false);
// The box follows the click at once; the write's answer settles it (a refusal puts it back).
const [pending, setPending] = useState(null);
const cut = comboKnobs(render);
const off = entry.combo === false;
const members = combo.members ?? [];
const set = async (on: boolean) => {
setError(null);
setBusy(true);
setPending(on);
const res = await fetch("/api/report/post-combo", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ project, op: "set", id: entry.id, combo: on ? null : false, token }),
});
const j = (await res.json().catch(() => ({}))) as { entry?: Record & { id: string }; token?: string; error?: string; errors?: string[] };
setBusy(false);
setPending(null);
if (!res.ok || !j.entry) {
setError(j.errors?.join("; ") ?? j.error ?? `HTTP ${res.status}`);
return;
}
onEntry(j.entry, j.token ?? null);
};
return (
combo · attachment {combo.media + 1} · use {combo.count} of {members.length}
{cut.on === false
? "the cut's combo badge is off (umtool posts combo
on=on)"
: combo.count < Math.max(2, cut.minCount)
? `the first use${combo.count > 1 ? "s" : ""} draw${combo.count > 1 ? "" : "s"} none: the badge from ×${cut.minCount}`
: off
? "off here: it still counts, the next use stays ×" + (combo.count + 1)
: `“${String(combo.knobs?.label ?? cut.label)} ×${combo.count}” pops as the attachment starts`}