__vite_ssr_exportName__("formatMegabytes", () => { try { return formatMegabytes } catch {} });
__vite_ssr_exportName__("formatSpan", () => { try { return formatSpan } catch {} });
__vite_ssr_exportName__("formatClock", () => { try { return formatClock } catch {} });
__vite_ssr_exportName__("describeMetrics", () => { try { return describeMetrics } catch {} });
__vite_ssr_exportName__("describeEta", () => { try { return describeEta } catch {} });
__vite_ssr_exportName__("elapsedSeconds", () => { try { return elapsedSeconds } catch {} });
__vite_ssr_exportName__("currentStage", () => { try { return currentStage } catch {} });
__vite_ssr_exportName__("currentLine", () => { try { return currentLine } catch {} });
__vite_ssr_exportName__("failedStage", () => { try { return failedStage } catch {} });
const MB = 1e6;
const GB = 1e9;
/** `312.4 MB` for 312 400 000 bytes: megabytes (gigabytes from 10 GB) with one decimal. */
function formatMegabytes(bytes) {
	return bytes >= 10 * GB ? `${(bytes / GB).toFixed(1)} GB` : `${(bytes / MB).toFixed(1)} MB`;
};
/** `1m 23s`, `45s`, `1h 05m`: a remaining or elapsed time. */
function formatSpan(seconds) {
	const whole = Math.max(0, Math.round(seconds));
	if (whole >= 3600) {
		return `${Math.floor(whole / 3600)}h ${String(Math.floor(whole % 3600 / 60)).padStart(2, "0")}m`;
	};
	if (whole >= 60) return `${Math.floor(whole / 60)}m ${String(whole % 60).padStart(2, "0")}s`;
	return `${whole}s`;
};
/** `1:02:09` or `02:09`: a position in a video. */
function formatClock(seconds) {
	const whole = Math.max(0, Math.floor(seconds));
	const h = Math.floor(whole / 3600);
	const mm = String(Math.floor(whole % 3600 / 60)).padStart(2, "0");
	const ss = String(whole % 60).padStart(2, "0");
	return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;
};
/** What the running stage measures, ready to be put into words (bytes, speed, chat, video time). */
function describeMetrics(stage) {
	const m = stage.metrics;
	const parts = [];
	const bytesDone = m.bytes_done;
	if (bytesDone !== undefined) {
		const total = m.bytes_total;
		const scale = (total ?? bytesDone) >= 10 * GB ? GB : MB;
		const unit = scale === GB ? "GB" : "MB";
		parts.push({
			kind: "bytes",
			done: (bytesDone / scale).toFixed(1),
			total: total === undefined ? null : `${(total / scale).toFixed(1)} ${unit}`
		});
	};
	if (m.bytes_per_s !== undefined) parts.push({
		kind: "speed",
		perSecond: `${(m.bytes_per_s / MB).toFixed(1)} MB/s`
	});
	if (m.messages !== undefined) parts.push({
		kind: "messages",
		count: m.messages
	});
	if (m.seconds_done !== undefined) {
		const total = m.seconds_total;
		parts.push({
			kind: "video",
			done: formatClock(m.seconds_done),
			total: total === undefined ? null : formatClock(total)
		});
	};
	if (m.speed_x !== undefined) parts.push({
		kind: "realtime",
		times: m.speed_x.toFixed(1)
	});
	return parts;
};
/** The remaining time: a number only when the server had enough data, else "estimating". */
function describeEta(status, detail) {
	if (status !== "running" && status !== "queued") return { kind: "none" };
	if (detail === null || detail.eta_s === null) return { kind: "estimating" };
	return {
		kind: "left",
		text: formatSpan(detail.eta_s)
	};
};
/** Seconds since the job started, as of `now` (ms); a finished job stops at its last update. */
function elapsedSeconds(detail, finished, now) {
	const start = new Date(detail.started_at).getTime();
	const end = finished ? new Date(detail.updated_at).getTime() : now;
	return Number.isNaN(start) || Number.isNaN(end) ? 0 : Math.max(0, (end - start) / 1e3);
};
function currentStage(detail) {
	if (detail === null || detail.current_stage === null) return null;
	return detail.stages.find((s) => s.key === detail.current_stage) ?? null;
};
/** The short line for dashboards and toasts: the current stage's sentence, or the job's step. */
function currentLine(job) {
	return currentStage(job.detail)?.detail || job.step;
};
function failedStage(detail) {
	return detail?.stages.find((s) => s.status === "failed") ?? null;
}

//# vitestCache=W3siZmlsZSI6IjEiLCJpZCI6IjEiLCJpbXBvcnRzIjoiMiIsIm1hcHBpbmdzIjpmYWxzZSwiZGVwcyI6IjMiLCJkeW5hbWljRGVwcyI6IjQiLCJzdGF0aWNNb2NrcyI6bnVsbCwiaGFzQ292ZXJhZ2VEYXRhIjpmYWxzZX0sIkQ6L0dpdEh1Yi9WaWNlQ3V0L3dlYi9zcmMvZW50aXRpZXMvam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AM,KAAK,KAAK,OAAO,MAAM,GAAG,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,SAAS,GAAI;AACxF;AAEO,SAAS,aAAa,QAAwC;CACnE,IAAI,WAAW,QAAQ,OAAO,kBAAkB,MAAM,OAAO;CAC7D,OAAO,OAAO,OAAO,MAAM,MAAM,EAAE,QAAQ,OAAO,aAAa,KAAK;AACtE;;AAGO,SAAS,YAAY,KAAkB;CAC5C,OAAO,aAAa,IAAI,MAAM,CAAC,EAAE,UAAU,IAAI;AACjD;AAEO,SAAS,YAAY,QAAwC;CAClE,OAAO,QAAQ,OAAO,MAAM,MAAM,EAAE,WAAW,QAAQ,KAAK;AAC9D","names":[],"ignoreList":[],"sources":["progress.ts"],"sourcesContent":["import type { Job } from \"./api\";\n\nexport type JobDetail = NonNullable<Job[\"detail\"]>;\nexport type Stage = JobDetail[\"stages\"][number];\nexport type JobItem = JobDetail[\"items\"][number];\n\nconst MB = 1_000_000;\nconst GB = 1_000_000_000;\n\n/** `312.4 MB` for 312 400 000 bytes: megabytes (gigabytes from 10 GB) with one decimal. */\nexport function formatMegabytes(bytes: number): string {\n  return bytes >= 10 * GB ? `${(bytes / GB).toFixed(1)} GB` : `${(bytes / MB).toFixed(1)} MB`;\n}\n\n/** `1m 23s`, `45s`, `1h 05m`: a remaining or elapsed time. */\nexport function formatSpan(seconds: number): string {\n  const whole = Math.max(0, Math.round(seconds));\n  if (whole >= 3600) {\n    return `${Math.floor(whole / 3600)}h ${String(Math.floor((whole % 3600) / 60)).padStart(2, \"0\")}m`;\n  }\n  if (whole >= 60) return `${Math.floor(whole / 60)}m ${String(whole % 60).padStart(2, \"0\")}s`;\n  return `${whole}s`;\n}\n\n/** `1:02:09` or `02:09`: a position in a video. */\nexport function formatClock(seconds: number): string {\n  const whole = Math.max(0, Math.floor(seconds));\n  const h = Math.floor(whole / 3600);\n  const mm = String(Math.floor((whole % 3600) / 60)).padStart(2, \"0\");\n  const ss = String(whole % 60).padStart(2, \"0\");\n  return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;\n}\n\nexport type MetricPart =\n  | { kind: \"bytes\"; done: string; total: string | null }\n  | { kind: \"speed\"; perSecond: string }\n  | { kind: \"messages\"; count: number }\n  | { kind: \"video\"; done: string; total: string | null }\n  | { kind: \"realtime\"; times: string };\n\n/** What the running stage measures, ready to be put into words (bytes, speed, chat, video time). */\nexport function describeMetrics(stage: Stage): MetricPart[] {\n  const m = stage.metrics;\n  const parts: MetricPart[] = [];\n  const bytesDone = m.bytes_done;\n  if (bytesDone !== undefined) {\n    const total = m.bytes_total;\n    const scale = (total ?? bytesDone) >= 10 * GB ? GB : MB;\n    const unit = scale === GB ? \"GB\" : \"MB\";\n    parts.push({\n      kind: \"bytes\",\n      done: (bytesDone / scale).toFixed(1),\n      total: total === undefined ? null : `${(total / scale).toFixed(1)} ${unit}`,\n    });\n  }\n  if (m.bytes_per_s !== undefined) parts.push({ kind: \"speed\", perSecond: `${(m.bytes_per_s / MB).toFixed(1)} MB/s` });\n  if (m.messages !== undefined) parts.push({ kind: \"messages\", count: m.messages });\n  if (m.seconds_done !== undefined) {\n    const total = m.seconds_total;\n    parts.push({\n      kind: \"video\",\n      done: formatClock(m.seconds_done),\n      total: total === undefined ? null : formatClock(total),\n    });\n  }\n  if (m.speed_x !== undefined) parts.push({ kind: \"realtime\", times: m.speed_x.toFixed(1) });\n  return parts;\n}\n\nexport type Eta = { kind: \"estimating\" } | { kind: \"left\"; text: string } | { kind: \"none\" };\n\n/** The remaining time: a number only when the server had enough data, else \"estimating\". */\nexport function describeEta(status: string, detail: JobDetail | null): Eta {\n  if (status !== \"running\" && status !== \"queued\") return { kind: \"none\" };\n  if (detail === null || detail.eta_s === null) return { kind: \"estimating\" };\n  return { kind: \"left\", text: formatSpan(detail.eta_s) };\n}\n\n/** Seconds since the job started, as of `now` (ms); a finished job stops at its last update. */\nexport function elapsedSeconds(detail: JobDetail, finished: boolean, now: number): number {\n  const start = new Date(detail.started_at).getTime();\n  const end = finished ? new Date(detail.updated_at).getTime() : now;\n  return Number.isNaN(start) || Number.isNaN(end) ? 0 : Math.max(0, (end - start) / 1000);\n}\n\nexport function currentStage(detail: JobDetail | null): Stage | null {\n  if (detail === null || detail.current_stage === null) return null;\n  return detail.stages.find((s) => s.key === detail.current_stage) ?? null;\n}\n\n/** The short line for dashboards and toasts: the current stage's sentence, or the job's step. */\nexport function currentLine(job: Job): string {\n  return currentStage(job.detail)?.detail || job.step;\n}\n\nexport function failedStage(detail: JobDetail | null): Stage | null {\n  return detail?.stages.find((s) => s.status === \"failed\") ?? null;\n}\n"],"file":"/web/src/entities/job/progress.ts"}