// The chips and row parts several views share: media state, waivers, live
// downloads, counts, ratings and the row poster.
import { useState } from "react";
import { useLive } from "./context";
import { downloadChipDetail, downloadChipLabel, findDownload } from "./downloads";
import { Icon, Star } from "./icons";
import { waiverLabel } from "./library";
import { CHIP_ICON } from "./look";
/** A row's lead thumbnail at 2:3; a missing one keeps the same box. */
const POSTER =
"block w-poster aspect-2/3 flex-none object-cover bg-panel-raised border border-line rounded-chip";
import { formatRating, formatVoteCount, tmdbImage } from "./movie";
import { Chip, type Say } from "./ui";
/**
* What the operator reads for the stored `blocked` flag. §6.3 gives it one
* effect — it stops the targeted-search lane and leaves RSS matching on —
* and "blocked" reads as "block this title outright", which is the wrong
* promise. The flag, the column and the API keep their name; only the words
* on screen say what it does. [`BLOCKED_EFFECT`] carries the RSS half.
*/
export const NO_TARGETED_SEARCH = "no targeted search";
/** The half a three-word label cannot hold, for titles and accessible names. */
export const BLOCKED_EFFECT = "arr stops searching for this title; RSS still matches it";
export function two(value: number): string {
return value < 10 ? `0${value}` : String(value);
}
export function seasonTag(seasonNumber: number): string {
return `S${two(seasonNumber)}`;
}
export function episodeTag(seasonNumber: number, episodeNumber: number): string {
return `${seasonTag(seasonNumber)}E${two(episodeNumber)}`;
}
/** A row's title: the name, then the year in the readout face. */
export function TitleText({ title, year }: { title: string; year: number | null }) {
return (
{title}
{year !== null && (
{year}
)}
);
}
/**
* §4.2 state ramp on a media-state chip. `available` is a drawn check glyph —
* a shape, not only a hue, so it still reads greyscale — with the word kept
* as the chip's aria-label; every other state keeps the word on the chip.
*/
export function MediaStateChip({ state, wanted }: { state: string; wanted: boolean }) {
if (state === "available") {
// a bare span's aria-label is not reliably exposed; role="img" is what
// makes the word reachable once the glyph replaced it
return (
);
}
return (
{state}
);
}
/**
* §5.7 honesty: a waived import is never presented as a clean match. The
* rule that was relaxed is a sentence, not a word, so the chip draws the
* warning glyph (§4.2's drawn-glyph exemption) and the sentence is a tap
* away in the row's status slot — never only in a tooltip.
*/
export function WaiverChip({ waiver, say }: { waiver: unknown; say?: Say }) {
const label = waiverLabel(waiver);
if (label === null) {
return null;
}
return (
);
}
/**
* §9.8: live download state on the row that owns the item. Absent unless
* arr itself grabbed this exact target — a season pack shows on the season
* row only, because the API only ever returns a row for the
* `target_kind`/`target_id` actually grabbed. Fixed width, and it sits last
* on its line, so the poll adding or dropping it never moves another chip.
* Its detail (rate, ETA) is a tap away rather than a hover away.
*/
export function DownloadChip({
targetKind,
targetId,
say,
}: {
targetKind: string;
targetId: number;
say?: Say;
}) {
const { downloads } = useLive();
const download = findDownload(downloads, targetKind, targetId);
return (
{download !== null && (
{downloadChipLabel(download)}
)}
);
}
/** The ramp read off N/M itself: green when full, amber while a gap remains. */
function countsTone(available: number, total: number): "complete" | "partial" | undefined {
if (total === 0) {
return undefined;
}
return available >= total ? "complete" : "partial";
}
export function CountsChip({
label,
available,
total,
ariaLabel,
glyph = false,
}: {
label: string;
available: number;
total: number;
ariaLabel: string;
/** Season rows lead the count with the disk glyph. */
glyph?: boolean;
}) {
return (
{glyph && }
{label}
);
}
/** Episode counts for a title, hidden rather than shown as `0/0`. */
export function EpisodeCountsChip({ available, total }: { available: number; total: number }) {
if (total === 0) {
return null;
}
return (
);
}
/**
* TMDB's rating as a chip (#148). No votes means no chip — never a 0.0.
*/
export function RatingChip({
voteAverage,
voteCount,
secondary = false,
}: {
voteAverage: number | null;
voteCount?: number;
secondary?: boolean;
}) {
if (voteAverage === null) {
return null;
}
const votes = voteCount === undefined ? "" : ` from ${formatVoteCount(voteCount)} votes`;
return (
{formatRating(voteAverage)}
);
}
/** A search row's poster at w92, or a same-size blank so the edge never jitters. */
export function RowPoster({ posterPath, title }: { posterPath: string | null; title: string }) {
const [broken, setBroken] = useState(false);
if (posterPath === null || broken) {
return ;
}
return (
setBroken(true)}
/>
);
}
/** The amber lamp that leads every attention-queue row. */
export function AttentionLamp() {
return (
);
}
/** The audience of a root, or its id when the roots list does not carry it. */
export function audienceOf(roots: { id: number; audience: string }[], rootId: number): string {
return roots.find((root) => root.id === rootId)?.audience ?? `root ${rootId}`;
}