import { tr } from '../lib/i18n'; import { useEffect, useRef, useState } from 'react'; import type { PreviewArtifact } from '../lib/artifacts'; import { plainTimeSkipError, replayTimeSkip, setTimeSkipResult, stopTimeSkip } from '../lib/store'; import { realTimeSkipDocuments, timeSkipCheckOutcomes, timeSkipDocumentMarkdown, timeSkipDocuments, timeSkipExample, timeSkipResultState, type TimeSkipDocument, type TimeSkipRun, type TimeSkipVersion } from '../lib/time-skip'; import { TimeSkipWorking } from './TimeSkipWorking'; import { isForkJob } from '../lib/time-skip'; import { FloatingMenu } from './FloatingMenu'; import { TimeSkipCompare } from './TimeSkipCompare'; import { Btn, Dialog, Icon } from './ui'; function VersionTabs({ version, onChange, done, fork }: { fork?: boolean; version: TimeSkipVersion; onChange: (version: TimeSkipVersion) => void; done: boolean; }) { const options = ['original', 'updated'] as const; return
; } function ImageResult({ document, original, compare }: { document: TimeSkipDocument; original?: TimeSkipDocument; compare: boolean; }) { const [position, setPosition] = useState(50); if (!document.image) return null; return
{tr(compare ?
{tr("Original")}{tr("Updated")}
: null)}
{tr(document.image.alt)}/ {tr(compare && original?.image ? <> {tr(original.image.alt)} setPosition(Number(event.target.value))}/> : null)}
{tr(compare ? <>{tr("Drag to compare")} : 'Sample image · 1200 × 900')}
; } function ResultDocument({ document, original, highlight = false, label, imageCompare = false }: { document: TimeSkipDocument; original?: TimeSkipDocument; highlight?: boolean; label?: string; imageCompare?: boolean; }) { const oldLines = new Set(original?.code?.split('\n')); const goal = document.successCheck.match(/^(\d+) of (\d+) testers complete setup\.$/); const total = goal ? Math.min(20, Number(goal[2])) : 0; return

{tr(document.title)}

{tr(label ?? (imageCompare ? 'Compare' : highlight ? 'Updated' : 'Original'))}
{document.image ? : document.code ?
{document.code.split('\n').map((line, i) => {line}{'\n'})}
:
    {tr(document.steps.map((step, i) =>
  1. {tr(step)}
  2. ))}
} {tr(!document.image && !document.hideCheck ?

{tr("Success check")}{tr(goal ? {tr("Setup goal")} : null)}

{tr(document.successCheck)}

{tr(goal ? : null)}
: null)}
; } function RealDetails({ run }: { run: TimeSkipRun }) { const job = run.job!; const outcomes = timeSkipCheckOutcomes(run); return <>

{tr("Checks")}

{outcomes.length ?
{tr("Check")}{tr("Result")}
{outcomes.map(c =>
{c.id}{c.outcome}
)}
:

{tr("No checks are set up for this folder, so nothing was judged automatically. Look at the two versions and choose which to keep.")}

}

{tr("History")}

  1. {tr("Original saved")}{tr("Preserved before any changes.")}
  2. {job.attempts.map(a =>
  3. {tr('Revision {0}', [a.index])}{a.reason}
  4. )}
{job.error ?

{tr("What went wrong")}{plainTimeSkipError(job.error)}

: null} ; } export function TimeSkipPanel({ run, sessionId, inline, expanded, onCompare, onClose, onPreview }: { run: TimeSkipRun; sessionId: string; inline: boolean; expanded: boolean; onCompare: (expanded: boolean) => void; onClose: () => void; onPreview: (a: PreviewArtifact) => void; }) { const [now, setNow] = useState(Date.now); const [version, setVersion] = useState(run.retainedVersion ?? 'updated'); const [details, setDetails] = useState(false); const [menu, setMenu] = useState(false); const [imageCompare, setImageCompare] = useState(false); const [wide, setWide] = useState(false); const panel = useRef(null); const menuAnchor = useRef(null); const { frame, ready, kept, status } = timeSkipResultState(run, now); const real = !!run.job; const documents = run.job ? realTimeSkipDocuments(run.job) : timeSkipDocuments(run.prompt); const checks = timeSkipExample(run.prompt); const sideBySide = expanded && wide; // A finished real run that changed files: the A versus B view, one window whatever was made. Everything else keeps the older layout. const compareReal = real && frame.done && (run.job?.files?.length ?? 0) > 0; const workingReal = real && !frame.done; const realEmpty = real && frame.done && !compareReal; useEffect(() => { if (!panel.current) return; const observer = new ResizeObserver(entries => setWide(entries[0].contentRect.width > 650)); observer.observe(panel.current); return () => observer.disconnect(); }, [inline]); useEffect(() => { setNow(Date.now()); if (run.completedAt) return; const timer = setInterval(() => setNow(Date.now()), 250); return () => clearInterval(timer); }, [run.id, run.startedAt, run.completedAt]); useEffect(() => { setVersion(run.retainedVersion ?? 'updated'); setDetails(false); setMenu(false); setImageCompare(false); }, [run.id, run.startedAt, run.retainedVersion]); function openResult(which: TimeSkipVersion) { const document = documents[which]; if (real) { onPreview({ id: `${run.id}-${run.startedAt}-${which}`, kind: 'markdown', title: `${which === 'original' ? 'Original' : 'Updated'} · ${document.title}`, content: timeSkipDocumentMarkdown(document) }); return; } if (document.image) { onPreview({ id: `${run.id}-${run.startedAt}-${which}`, kind: 'image', title: `${which}-fieldnotes-cover.svg`, url: document.image.url, demo: true }); return; } // Snapshot IDs include the run clock, so replaying never reuses an old artifact. onPreview({ id: `${run.id}-${run.startedAt}-${which}`, kind: 'markdown', title: `${which}-${document.code ? 'counter' : 'launch-plan'}.md`, content: timeSkipDocumentMarkdown(document), demo: true }); } const forkRun = isForkJob(run.job); function restore(which: TimeSkipVersion) { setTimeSkipResult(sessionId, run.id, which); setVersion(which); setMenu(false); } const result = (which: TimeSkipVersion) => which === 'updated' && !ready ?
{tr("Working on the update")}

{tr("The original is saved. The new result will appear here when it\u2019s ready to compare.")}

: ; const content = ; return inline ? content : {tr(content)}; }