"use client"; // Lista de cortes: uma linha por corte com o que decide (miniatura, título, fonte/sessão/trecho, situação, nota da IA, // duração, estado ou publicação, ações rápidas da etapa). Clique na linha (fora de botões) ou Enter abre o modal do // corte; a linha aberta fica destacada. A caixa de seleção só aparece no hover/foco ou no modo de seleção. import { type KeyboardEvent, type MouseEvent, type ReactNode } from "react"; import { CLIP_STATUS, SOURCE_LABEL, clipperCall, formatClock, formatDuration, formatScore, languageShort, useClipperAction, type Clip, type ClipperSession, } from "./clipper-client"; import { ClipPublishButton } from "./clip-publish"; import { VideoTag, canDelete, judgeScore, situationLabel, type DeleteClip } from "./clipper-clip-parts"; import type { QueueFilter } from "./clipper-queue"; import { ArrowRightIcon, CheckIcon, RefreshIcon, ScissorsIcon, SparkIcon, UndoIcon, XIcon } from "./icons"; import type { PublishJob } from "./publishing-client"; import { PublishChips } from "./publishing-ui"; import { Badge, Button, Feedback, Spinner, Table, THead, Td, Th, cx, fileUrl, formatRelative } from "./ui"; export type ClipTableProps = { clips: Clip[]; sessions: ClipperSession[]; stage: QueueFilter; nameOf: (clip: Clip) => string; /** Idioma padrão do serviço: só mostra o chip de idioma quando a sessão do corte difere dele. */ defaultLanguage: string; /** Etapa Aprovados: jobs de publicação por id do corte (null = ainda não lidos / etapa não é Aprovados). */ publishing: Map | null; onPublished: () => void; onChanged: () => void; onOpen: (clip: Clip) => void; /** Corte aberto no modal (linha destacada). */ openId: number | null; /** Modo de seleção ligado: a caixa aparece em todas as linhas. */ revealed: boolean; selected: ReadonlySet; onSelect: (id: number, on: boolean) => void; deleting: ReadonlySet; onDelete: DeleteClip; }; export function ClipTable(props: ClipTableProps) { const { clips, stage } = props; const approved = stage === "approved"; return ( {clips.map((clip) => )}
Selecionar Miniatura Corte Situação Nota IA Duração {approved ? "Publicação" : "Estado"} Ações
); } /** Clique num botão, link, input ou texto selecionado não conta como "abrir a linha". */ function isInteractive(target: EventTarget | null): boolean { return target instanceof Element && Boolean(target.closest("button, a, input, select, textarea, label, [role=dialog], video")); } function ClipRow({ clip, sessions, stage, nameOf, defaultLanguage, publishing, onPublished, onChanged, onOpen, openId, revealed, selected, onSelect, deleting, onDelete }: ClipTableProps & { clip: Clip }) { const { pending, message, setMessage, run } = useClipperAction(onChanged); const status = CLIP_STATUS[clip.status]; const isDeleting = deleting.has(clip.id); const isSelected = selected.has(clip.id); const open = openId === clip.id; const name = nameOf(clip); const title = clip.title || `Corte ${clip.id}`; const session = sessions.find((s) => s.id === clip.sessionId); const language = session?.language; const score = judgeScore(clip); const kept = clip.judge && "keep" in clip.judge ? clip.judge.keep : null; const situation = situationLabel(clip); const jobs = publishing?.get(String(clip.id)) ?? null; const horizontal = clip.aspect === "horizontal"; const poster = clip.thumb ? fileUrl(clip.thumb) : null; const onRowClick = (e: MouseEvent) => { if (isInteractive(e.target) || window.getSelection()?.toString()) return; onOpen(clip); }; const onRowKey = (e: KeyboardEvent) => { if (e.target !== e.currentTarget) return; if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onOpen(clip); } }; return ( <> onSelect(clip.id, e.target.checked)} aria-label={`Selecionar o corte ${clip.id}: ${title}`} title={canDelete(clip) ? "Selecionar para apagar" : "A IA ou o render está trabalhando neste corte"} className={cx("size-4 cursor-pointer accent-accent transition-opacity duration-150 motion-reduce:transition-none disabled:cursor-not-allowed", !canDelete(clip) ? (revealed ? "opacity-40" : "opacity-0 group-hover/row:opacity-40 group-focus-within/row:opacity-40") : revealed || isSelected ? "opacity-100" : "opacity-0 group-hover/row:opacity-100 group-focus-within/row:opacity-100")} /> {/* eslint-disable-next-line @next/next/no-img-element -- miniatura local servida por /api/files */} {poster ? : }

{title}

{/* Fonte em inglês: o título do post é o inglês acima; a tradução é só para a equipe entender. */} {clip.judge && "pt" in clip.judge && clip.judge.pt?.title && (

🇧🇷 {clip.judge.pt.title}

)}

{name} sessão #{clip.sessionId} {formatClock(clip.startS)}–{formatClock(clip.endS)} {formatRelative(clip.createdAt)} {language && language !== defaultLanguage && ( {languageShort(language)} )} {horizontal && 16:9}

{situation ? {situation} : {SOURCE_LABEL[clip.source]}} {score === null ? — : = 7 ? "text-success" : "text-fg")} title={kept === false ? "A IA descartou" : "Nota da IA (0–10)"}>{formatScore(score)}} {formatDuration(clip.durationS)} {stage === "approved" && jobs ? {status.label}ainda não foi para nenhuma rede} /> : {status.label}}
{ setMessage(m); onPublished(); }} />
{(message || (clip.status === "error" && clip.error)) && (
{clip.status === "error" && clip.error && !message && (

{clip.error}

)} {message && {message.text}}
)} ); } type Run = ReturnType["run"]; /** Ações rápidas da etapa, na própria linha (o resto fica no modal). */ function QuickActions({ clip, pending, run, jobs, onPublished }: { clip: Clip; pending: string | null; run: Run; jobs: PublishJob[] | null; onPublished: (m: { ok: boolean; text: string }) => void; }) { const base = `clips/${clip.id}`; const disabled = pending !== null; const icon = (key: string, fallback: ReactNode) => (pending === key ? : fallback); const setStatus = (key: string, status: "approved" | "rejected" | "ready", text: string) => run(key, () => clipperCall(base, "PATCH", { status }), text); const render = (text: string) => run("render", () => clipperCall(`${base}/render`, "POST"), text); const label = clip.title || `corte ${clip.id}`; switch (clip.status) { case "ready": return <> ; case "approved": return <> {jobs && } ; case "published": return jobs ? : null; case "rejected": return clip.file ? ( ) : null; case "discarded": return ( ); case "error": return ( ); default: return clip.status === "candidate" ? IA avaliando : null; } }