import type { SaveStatus } from './state'; /** When a snapshot was made, in the local time of the browser: `2026-09-25 17:39`. */ export function snapshotTime(at: Date): string { const two = (n: number) => String(n).padStart(2, '0'); return `${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())} ${two(at.getHours())}:${two(at.getMinutes())}`; } /** * Why a snapshot cannot be made or restored right now, or null when it can (#231). The server copies * what it has stored, so the editor has to have saved everything first: a snapshot without the * last edits would be a stand nobody ever saw. A release is a copy as well (#266) and asks the same. */ export function snapshotBlocker( status: SaveStatus, copy: 'snapshot' | 'release' = 'snapshot', ): string | null { switch (status) { case 'saved': return null; case 'conflict': return 'This project was changed elsewhere. Reload to continue.'; case 'error': return `The project could not be saved, so there is nothing current to ${copy === 'release' ? 'release' : 'take a snapshot of'}`; default: return 'The latest changes are not saved yet – stop the game or wait a moment'; } }