import { useProgress } from "@/lib/progress";
function fmt(s: number): string {
const m = Math.floor(s / 60);
const sec = Math.floor(s % 60);
return `${m}:${sec.toString().padStart(2, "0")}`;
}
export default function ProgressBar() {
const state = useProgress();
if (state.phase === "idle") return null;
if (state.phase === "error") {
return (
progress error
{state.message}
);
}
const isRunning = state.phase === "running";
const isDialog = isRunning && state.kind === "dialog";
const fill =
state.phase === "done"
? 1
: isDialog && state.total > 0
? state.turn / state.total
: null;
const elapsedS = state.phase === "running" ? state.elapsedS : state.phase === "done" ? state.elapsedS : 0;
const label =
state.phase === "done"
? `done · ${fmt(elapsedS)}`
: isDialog
? `Turn ${state.turn} of ${state.total} · ${fmt(elapsedS)}`
: `Generating · ${fmt(elapsedS)}`;
return (
{label}
{fill === null ? (
) : (
)}
);
}