import React, { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { AnalysisReview, ClipReview, FetchReview, FinalReview, GATE_CAN_BACK, GATE_ORDER, GateEdits, GateKey, NarrationReview, PlayreelJob, approvePlayreelGate, backPlayreelGate, retryPlayreelClip, } from '../../utils/playreelApi'; import { isAutoApprovable, useAutoApprove } from '../../utils/playreelPrefs'; interface PlayreelGateContentProps { /** `gate` 와 `review` 가 채워진 검수 대기 잡 */ job: PlayreelJob; /** 승인·되돌리기·재생성 요청이 끝나면 호출 — GenerationFlow 가 폴링을 다시 켠다 */ onChanged: () => void; /** 자동 승인이 성공했을 때 호출 — 진행 화면이 "자동 승인했습니다" 안내를 이어서 보여준다 */ onAutoApproved: (gate: GateKey) => void; } const Icon: React.FC<{ d: string; size?: number }> = ({ d, size = 12 }) => ( ); const CHECK = 'M20 6 9 17l-5-5'; const CROSS = 'M18 6 6 18M6 6l12 12'; const PLUS = 'M12 5v14M5 12h14'; const Lock: React.FC<{ size?: number }> = ({ size = 12 }) => ( ); /** 켜고 끄는 칩. `locked` 는 항상 켜져 있어 누를 수 없다 */ const Chip: React.FC<{ on: boolean; locked?: boolean; onClick?: () => void; children: React.ReactNode; }> = ({ on, locked, onClick, children }) => ( ); // ── ① 수집 확인 ───────────────────────────────────────────────────────── type FetchEdits = Extract; /** * 상세페이지 조각은 라벨이 겹친다 — "유의사항"만 일곱 개인 페이지가 흔하다. * 칩으로 그리면 같은 글자가 줄줄이 서서 무엇을 고르는지 알 수 없어 썸네일을 그린다. */ const FetchGate: React.FC<{ data: FetchReview; onChange: (edits: FetchEdits) => void }> = ({ data, onChange, }) => { const { t } = useTranslation(); const [sections, setSections] = useState(data.sections); const [meta, setMeta] = useState(data.meta); const emit = (nextSections = sections, nextMeta = meta) => onChange({ sections: nextSections.filter((s) => s.selected).map((s) => s.id), meta: nextMeta }); const chosen = sections.filter((s) => s.selected).length; return (

{t('playreel.fetch.info')}

{(['title', 'date_text', 'place'] as const).map((key) => (
{t(`playreel.fetch.field.${key}`)} { const next = { ...meta, [key]: e.target.value }; setMeta(next); emit(sections, next); }} />
))}

{t('playreel.fetch.cast', { cast: meta.cast.join(', ') })}

{t('playreel.fetch.sections')}

{t('playreel.fetch.sectionsHelp')}

{sections.map((s, i) => ( ))}

{t('playreel.fetch.sectionsCount', { total: sections.length, chosen })}

{data.poster_width <= 800 && (

{t('playreel.fetch.lowRes', { width: data.poster_width })}

)}

{t('playreel.fetch.poster')}

{t('playreel.fetch.poster')}
); }; // ── ② 연출 확인 ───────────────────────────────────────────────────────── type AnalysisEdits = Extract; const AnalysisGate: React.FC<{ data: AnalysisReview; onChange: (edits: AnalysisEdits) => void }> = ({ data, onChange, }) => { const { t } = useTranslation(); const [movable, setMovable] = useState(data.movable); const [fixed, setFixed] = useState(data.fixed); const emit = (nextMovable = movable, nextFixed = fixed) => onChange({ movable: nextMovable.filter((x) => x.on).map((x) => x.key), fixed: nextFixed.filter((x) => x.on).map((x) => x.key), model: data.model, }); return (

{t('playreel.analysis.movable')}

{t('playreel.analysis.movableHelp')}

{movable.map((m) => ( { const next = movable.map((x) => (x.key === m.key ? { ...x, on: !x.on } : x)); setMovable(next); emit(next); }} > {m.label} ))}

{t('playreel.analysis.fixed')}

{t('playreel.analysis.fixedHelp')}

{fixed.map((f) => ( { const next = fixed.map((x) => (x.key === f.key ? { ...x, on: !x.on } : x)); setFixed(next); emit(movable, next); }} > {f.label} ))}

{t('playreel.analysis.model')}

{t('playreel.analysis.modelValue')}

{data.ip_risk &&

{t('playreel.analysis.ipRisk')}

} {!data.has_qr &&

{t('playreel.analysis.noQr')}

}

{t('playreel.analysis.grid')}

{t('playreel.analysis.grid')}
); }; // ── ③ 나레이션·보이스 확인 ────────────────────────────────────────────── type NarrationEdits = Extract; const NARRATION_MIN_SECONDS = 28; const NARRATION_MAX_SECONDS = 31; const NarrationGate: React.FC<{ data: NarrationReview; onChange: (edits: NarrationEdits) => void }> = ({ data, onChange, }) => { const { t } = useTranslation(); const [lines, setLines] = useState(data.lines); const lengthOk = data.est_seconds >= NARRATION_MIN_SECONDS && data.est_seconds <= NARRATION_MAX_SECONDS; return (

{t('playreel.narration.lines', { count: lines.length })}

{lines.map((line, i) => (
{line.slot} { const next = lines.map((x, j) => (j === i ? { ...x, text: e.target.value } : x)); setLines(next); onChange({ lines: next.map((x) => x.text), voice_id: data.voice.id }); }} />
))}

{t('playreel.narration.voice')}

{data.voice.name}

{data.voice.sample_url ? (

{t('playreel.narration.estimate')}

{t('playreel.narration.seconds', { value: data.est_seconds.toFixed(1) })}

{t('playreel.narration.target', { min: NARRATION_MIN_SECONDS, max: NARRATION_MAX_SECONDS })} {!lengthOk && ` — ${t('playreel.narration.adjust')}`}

); }; // ── ④ 클립 검수 ───────────────────────────────────────────────────────── const ClipGate: React.FC<{ data: ClipReview }> = ({ data }) => { const { t } = useTranslation(); return (
{data.clip_url ? (

{t('playreel.clip.titleCheck')}

{t(data.gate_passed ? 'playreel.clip.passed' : 'playreel.clip.failed', { mae: data.title_mae.toFixed(2), })}

{t('playreel.clip.criteria')}

{data.gate_reason &&

{data.gate_reason}

}

{t('playreel.clip.frames')}

{t('playreel.clip.frames')}

{t('playreel.clip.redoNote')}

); }; // ── ⑤ 최종 검수 ───────────────────────────────────────────────────────── const FinalGate: React.FC<{ data: FinalReview }> = ({ data }) => { const { t } = useTranslation(); return (
{data.video_url ? (

{t('playreel.final.checks')}

{data.checks.map((c) => (

{c.label}

))}

{t('playreel.final.proof')}

{t('playreel.final.proof')}

{t('playreel.final.version', { version: data.version })}

); }; // ── 게이트 셸 ─────────────────────────────────────────────────────────── /** * 롱컷 검수 게이트. 파이프라인이 사람의 확인을 기다리며 멈추는 5개 지점 중 하나를 그린다. * * 승인하면 다음 단계가 이어지고, 크레딧을 이미 쓴 지점(연출 확인 이후)부터는 되돌릴 수 없다. * 고친 값은 `edits` ref 에 모았다가 승인할 때 함께 보낸다 — 입력마다 요청하지 않는다. */ const PlayreelGateContent: React.FC = ({ job, onChanged, onAutoApproved }) => { const { t } = useTranslation(); const edits = useRef(null); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const prefs = useAutoApprove(); const autoFired = useRef(false); // 같은 게이트에 두 번 보내지 않는다 const { gate, review } = job; // 자동 승인이 켜진 게이트(①·③)는 폴링이 검수 대기를 보는 순간 한 번만 승인한다. // 실패하면 카드가 그대로 남아 사람이 직접 누를 수 있다. const autoGate = isAutoApprovable(gate) && prefs[gate] ? gate : null; const autoActive = autoGate !== null && !error; useEffect(() => { if (!autoGate || autoFired.current) return; autoFired.current = true; approvePlayreelGate(job.id, autoGate, null) .then(() => { onAutoApproved(autoGate); onChanged(); }) .catch((e) => setError(t('playreel.auto.failed', { message: (e as Error).message }))); // eslint-disable-next-line react-hooks/exhaustive-deps }, [autoGate]); if (!gate || !review) return null; if (autoActive) { return (
); } const step = GATE_ORDER.indexOf(gate) + 1; const run = async (request: () => Promise) => { setBusy(true); setError(null); try { await request(); edits.current = null; onChanged(); } catch (e) { setError((e as Error).message); } finally { setBusy(false); } }; const approveLabel = gate === 'final_confirm' ? t('playreel.gate.approveFinal') : gate === 'clip_confirm' ? t('playreel.gate.approveClip') : t('playreel.gate.approve'); const renderBody = () => { switch (review.gate) { case 'fetch_confirm': return { edits.current = e; }} />; case 'analysis_confirm': return { edits.current = e; }} />; case 'narration_confirm': return { edits.current = e; }} />; case 'clip_confirm': return ; case 'final_confirm': return ; } }; return (

{t('playreel.gate.progress', { step, total: GATE_ORDER.length, name: t(`playreel.gates.${gate}.name`) })}

{t(`playreel.gates.${gate}.title`)}

{t(`playreel.gates.${gate}.why`)}

{renderBody()} {error &&
{error}
}
{gate === 'clip_confirm' && ( )} {GATE_CAN_BACK[gate] && ( )}

{t('playreel.gate.next', { next: t(`playreel.gates.${gate}.next`), eta: t(`playreel.gates.${gate}.eta`), })}

); }; export default PlayreelGateContent;