// ── State persistence ────────────────────────────────────────────

async function saveFinishedState(data, clear = false) {
    try {
        const res = await fetch(`${baseUrl}/project/${projectSlug}/finished/save`, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ data, clear })
        });
        return await res.json();
    } catch (err) {
        return { success: false };
    }
}

// NOTE: no pagehide auto-save here — lastBuild/history are written by the
// server when actions run; a beacon with stale client state would wipe them.

// ── Expose for manual save ───────────────────────────────────────
window.saveFinishedState = saveFinishedState;
