// What both §9.6 detail pages share: the hero, the action bar's links, and // the removal confirmation. import { type CSSProperties, type ReactNode, useEffect, useRef, useState } from "react"; import { Icon, ProviderMark, Star } from "./icons"; import { control, NOTE, detail as page, type } from "./look"; /** each line keeps its height while empty, so the hero never grows in steps */ const HERO_LINE = "readout flex items-center gap-1 min-h-line m-0 text-xs"; import { formatMetaLine, formatRating, formatVoteCount, tmdbImage } from "./movie"; import { type ActionOutcome, formatSize, totalSize } from "./releases"; import { cx, flag, IconControl, IconLink, type Note, NoteLine } from "./ui"; /** What both detail heroes paint from TMDB (§9.6). */ export interface HeroDetail { poster_path: string | null; backdrop_path: string | null; vote_average: number | null; vote_count: number; runtime: number | null; genres: string[]; tagline: string | null; overview: string | null; } /** * The detail hero is a fixed grid: the poster's box, the chip line, one line * each for rating and meta, and three reserved lines of overview. Data fills * the slots; it never adds them, so the page does not grow in steps. */ export function Hero({ title, year, detail, chips, note, onBack, }: { title: string; year: number | null; detail: HeroDetail | null; chips: ReactNode; note: Note | null; onBack: () => void; }) { const heading = useRef(null); const [posterLoaded, setPosterLoaded] = useState(false); const [posterBroken, setPosterBroken] = useState(false); const [overviewFull, setOverviewFull] = useState(false); useEffect(() => { heading.current?.focus({ preventScroll: true }); window.scrollTo({ top: 0 }); }, []); const posterUrl = detail === null ? null : tmdbImage(detail.poster_path, "w342"); const backdropUrl = detail === null ? null : tmdbImage(detail.backdrop_path, "w1280"); const tagline = detail?.tagline; return (

{title === "" ? " " : title}

{year === null ? "" : year}
{posterUrl setPosterLoaded(true)} onError={() => setPosterBroken(true)} />
{chips}

{detail !== null && detail.vote_average !== null && ( <> {`${formatRating(detail.vote_average)} `} {`(${formatVoteCount(detail.vote_count)})`} )}

{detail === null ? "" : formatMetaLine(detail.runtime, detail.genres)}

{tagline !== null && tagline !== undefined && tagline !== "" ? `“${tagline}”` : ""}

{/* biome-ignore lint/a11y/useKeyWithClickEvents: a reading aid; the full text is in the DOM either way */}

setOverviewFull(!overviewFull)} > {detail?.overview ?? ""}

); } /** The trailer: the play glyph, and the word wherever there is room for it. */ export function TrailerLink({ href, title }: { href: string; title: string }) { return ( trailer ); } export function ProviderLink({ mark, label, href, }: { mark: "tmdb" | "tvdb" | "imdb" | "rt"; label: string; href: string; }) { return ( ); } /** The slice of a file the removal panel reads: evidence, nothing else. */ export interface RemoveFile { path: string; size: number; } /** * What the panel needs to know about a title (issue 175): a movie and a * series differ only in which endpoints they call, how their files roll up * to one folder, and how many torrents the §7.3 warning speaks of. */ export interface RemoveSubject { title: string; files: () => Promise<{ kind: "files"; files: RemoveFile[] } | { kind: "error"; detail: string }>; /** The one folder the delete takes, when the files agree on it. */ folder: (files: RemoveFile[]) => string | null; remove: () => Promise; /** What does not happen: seeding continues under its own rule (§7.3). */ seedLine: string; } /** * The removal confirmation (issue 104, simplified by 110): removing a title * always unlinks its §7.4 folder, so there is one decision, not two. * * It names the §7.4 folder it would unlink rather than promising in the * abstract — the service knows only what it wrote (§2), so the file list is * the whole truth about what disappears. And it says what does not happen: * seeding continues under its own rule (§7.3). */ export function RemovePanel({ subject, onCancel, onRemoved, }: { subject: RemoveSubject; onCancel: () => void; onRemoved: () => void; }) { const [evidence, setEvidence] = useState("reading files…"); const [path, setPath] = useState(null); const [files, setFiles] = useState(null); const [folderNamed, setFolderNamed] = useState(false); const [working, setWorking] = useState<{ text: string; tone?: "fault" } | null>(null); const [busy, setBusy] = useState(false); const keep = useRef(null); // cancel takes focus, not the destructive action: no toggle is left to arm first useEffect(() => { keep.current?.focus(); }, []); useEffect(() => { let live = true; void subject.files().then((outcome) => { if (!live) { return; } if (outcome.kind === "error") { setEvidence(`files unreadable — ${outcome.detail}`); return; } setFiles(outcome.files); if (outcome.files.length === 0) { setEvidence("nothing on disk"); return; } const count = `${outcome.files.length} ${outcome.files.length === 1 ? "file" : "files"}`; setEvidence(`${count} · ${formatSize(totalSize(outcome.files))}`); const folder = subject.folder(outcome.files); setFolderNamed(folder !== null); setPath(folder ?? outcome.files.map((file) => file.path).join("\n")); }); return () => { live = false; }; }, [subject]); const hasFiles = files !== null && files.length > 0; const note = working ?? (hasFiles ? { text: `${folderNamed ? "deletes the folder above." : "deletes the files above."} ${subject.seedLine}`, tone: "warn" as const, } : { text: "the library entry goes. nothing was imported for this title." }); const confirm = () => { setBusy(true); setWorking({ text: "removing title and files…" }); void subject.remove().then((outcome) => { if (outcome.kind === "done") { onRemoved(); return; } setBusy(false); // the row is still there on a failed unlink, so retrying is the fix setWorking({ text: `remove failed — ${outcome.detail}`, tone: "fault" }); }); }; // evidence, then what removing it costs return ( // biome-ignore lint/a11y/useSemanticElements: a fieldset brings its own border, padding and min-width, which this group does not want

{evidence}

{note.text}

{/* armed: the confirm turns caution amber with the rest of the panel */}
); }