import Link from "next/link"; import { BenchBody, BenchFrame, BenchTop } from "./bench/BenchShell"; import { projectRef } from "@/lib/projects"; import { projectsHref, takesCompareHref, takesHref } from "@/lib/hrefs"; import { listTakes } from "@/lib/report/takes.mjs"; import { compareTakes, parseTakeRef, shortValue } from "@/lib/report/takeCompare.mjs"; import { variantFamily } from "@/lib/report/variantFork.mjs"; import { REPORTS_ROOT } from "@/lib/paths.mjs"; import type { ProjectRef } from "@/lib/project-types"; import TakesComparePlayers from "./TakesComparePlayers"; // `/projects//takes/compare?a=:&b=:` -- // two takes side by side (UI notes 2026-10-30, item 19): of the project, or of // the project and one of its variants (lib/report/variantFork.mjs). Two // players kept in step (TakesComparePlayers), and what differs between the // takes (lib/report/takeCompare.mjs): the cut's changes A → B, the look's. type Search = Record; export default async function TakesComparePage({ project, search }: { project: ProjectRef; search: Search }) { const family = await variantFamily(project, { root: REPORTS_ROOT }).catch(() => ({ parent: project.id, members: [] as Awaited>["members"] })); const all = family.members.flatMap((m) => (m.takes as Array<{ id: string; label: string; draft?: boolean }>).map((t) => ({ ref: `${m.id}:${t.id}`, project: m.id, take: t.id, label: t.label, draft: !!t.draft }))); const own = all.filter((x) => x.project === project.id); const a = parseTakeRef(search.a, project.id) ?? (own[0] ? { project: own[0].project, take: own[0].take } : null); const b = parseTakeRef(search.b, project.id) ?? (all.find((x) => !a || x.ref !== `${a.project}:${a.take}`) ?? null); let error: string | null = null; let c: Awaited> | null = null; if (!a || !b) error = "two takes are needed to compare: this project and its variants have fewer"; else { try { const pa = a.project === project.id ? project : await projectRef(a.project); const pb = b.project === project.id ? project : await projectRef(b.project); if (!pa || !pb) throw new Error(`no project ${!pa ? a.project : b.project}`); // Each must be a take its project lists (listTakes), as the preview route serves only those. for (const [p, ref] of [[pa, a], [pb, b]] as const) { if (!(await listTakes(p.dir)).takes.some((t: { id: string }) => t.id === ref.take)) throw new Error(`${p.id} has no take ${ref.take}`); } c = await compareTakes({ ref: { project: pa.id, take: a.take }, dir: pa.dir }, { ref: { project: pb.id, take: b.take }, dir: pb.dir }); } catch (e) { error = e instanceof Error ? e.message : String(e); } } const pickers = (
{(["a", "b"] as const).map((side) => ( ))} {a && b && ( swap A and B )}
); return ( } > {pickers} {error && (

{error}

)} {c && ( <>

what differs, A → B

A
B
{( [ ["project", c.a.project, c.b.project], ["take", c.a.take, c.b.take], ["label", c.a.label, c.b.label], ["length", typeof c.a.seconds === "number" ? `${c.a.seconds.toFixed(1)} s` : "not rendered", typeof c.b.seconds === "number" ? `${c.b.seconds.toFixed(1)} s` : "not rendered"], ["clips", String(c.a.clips), String(c.b.clips)], ["window", c.a.window === "full" ? "full cut" : c.a.window ? `${c.a.window.at}+${c.a.window.dur} s` : "—", c.b.window === "full" ? "full cut" : c.b.window ? `${c.b.window.at}+${c.b.window.dur} s` : "—"], ["style", c.a.style ?? "—", c.b.style ?? "—"], ["built", c.a.builtAt?.slice(0, 16).replace("T", " ") ?? "—", c.b.builtAt?.slice(0, 16).replace("T", " ") ?? "—"], ] as const ).map(([k, x, y]) => (
{k}
{x}
{y}
))}
{c.seconds !== null && c.seconds !== 0 && (

B is {Math.abs(c.seconds).toFixed(1)} s {c.seconds > 0 ? "longer" : "shorter"} than A.

)} {c.same &&

The same cut and the same look.

} {c.cut.lines.length > 0 && (

the cut — {c.cut.lines.length} change{c.cut.lines.length === 1 ? "" : "s"}

    {c.cut.lines.map((l, i) => (
  • {l}
  • ))}
)} {c.look.length > 0 && (

the look — {c.look.length} {c.lookMore ? `+${c.lookMore}` : ""} difference{c.look.length === 1 ? "" : "s"}

    {c.look.map((d) => (
  • {d.path}: {shortValue(d.a)} → {shortValue(d.b)}
  • ))}
)}

umtool takes compare {project.id} {c.a.ref} {c.b.ref} {" "} prints the same.

)}
); }