"use client"; import Link from "next/link"; import { playHref, takesHref } from "@/lib/hrefs"; import { cn } from "@/lib/utils"; // --------------------------------------------------------------------------- // WHAT PLAYS (umtool redesign L3): THE DRAFT, named first -- "Draft · from v5 // · 3 edits" / "Draft · unsaved" (lib/report/workingCut.mjs draftLine): the // project's manifest, where every edit lands -- and the switch to a saved // version, played read-only (`?take=`). The pick (verdicts.json) is // secondary: named small. Every switch is a link (nothing for the draft, // `?take=` for a version); `onNavigate` lets Play stop writing its own URL // while one is in flight. // --------------------------------------------------------------------------- export type WorkingCut = { latest: { id: string; label: string; builtAt: string | null; seconds: number | null } | null; /** The draft's parent: what it was last saved as or opened from (takes/draft.json), else the latest. */ parent?: { id: string; label: string; version?: boolean; via?: string } | null; edits: { count: number; words: string[]; same: boolean } | null; picked: { id: string; at: string | null; pinned: boolean; label: string } | null; } | null; export type WhatPlaysTake = { id: string; label: string; summary: string; made: boolean; from: string; ownTimeline?: boolean; version?: boolean; frozen?: boolean } | null; export type DraftLine = { line: string; parent: string | null; edits: number | null } | null; const day = (iso: string | null) => { if (!iso) return null; const d = new Date(iso); return Number.isNaN(d.getTime()) ? null : d.toLocaleDateString(undefined, { day: "numeric", month: "short" }); }; /** "3 edits" / "no edits" / "edits unknown": the draft's distance from its parent. */ export function editsLine(w: WorkingCut) { if (!w?.parent && !w?.latest) return ""; if (!w.edits) return "edits unknown"; return w.edits.count === 0 ? "no edits" : `${w.edits.count} edit${w.edits.count === 1 ? "" : "s"}`; } /** The draft's line, alone (the bench's head, the Takes page): "Draft · from v5 · 3 edits" / "Draft · unsaved". */ export function LatestLine({ project, working, className }: { project: string; working: WorkingCut; className?: string }) { if (!working) return null; const p = working.parent ?? (working.latest ? { id: working.latest.id, label: working.latest.label } : null); return ( Draft {p ? ( <> from {p.id} · {editsLine(working)} ) : ( · unsaved )} ); } export default function WhatPlays({ project, take, takes, working, draft = null, onNavigate, }: { project: string; take: WhatPlaysTake; takes: { id: string; label: string; made: boolean }[]; working: WorkingCut; draft?: DraftLine; onNavigate?: () => void; }) { const current = take?.id ?? null; const parent = draft?.parent ?? working?.parent?.id ?? null; // A few versions are pills; many are a list (the draft's parent and the one playing stay pills). const many = takes.length > 4; const pills = many ? takes.filter((t) => t.id === current || t.id === parent) : takes; const rest = many ? takes.filter((t) => !pills.includes(t)) : []; const link = (t: { id: string | null; label: string; made: boolean }, label: string) => { const on = t.id === null ? take === null : t.id === current; const href = t.id === null ? playHref(project) : playHref(project, { take: t.id }); return ( {label} ); }; const line = draft?.line ?? "Draft"; return (
{/* The draft's name, first and largest: where every edit lands. */} {take ? ( {line} ) : ( {line} )} {working?.picked && ( picked: {working.picked.id} {day(working.picked.at) ? ` (${day(working.picked.at)})` : ""} {working.picked.pinned ? ", pinned" : ""} )}
); }