import { apiGet, apiPost } from "@/lib/api/client"; import { hasLiveSession } from "@/lib/api/mode"; import type { Phase3Activity } from "@/lib/phase3-learning"; /** * Backend persistence for the learning-support activity aggregate (PYQ result, * weak topics, revision saves, recovery actions). localStorage stays the * offline source of truth; this makes the data survive login / device change. * Best-effort, no-op when logged out. */ type Phase3ActivityRemote = { data: Phase3Activity; updated_at: string }; export async function savePhase3ActivityRemote(data: Phase3Activity): Promise { if (!hasLiveSession()) return false; try { await apiPost("/phase3-activity", { data }); return true; } catch { return false; } } export async function getPhase3ActivityRemote(): Promise { if (!hasLiveSession()) return null; try { const remote = await apiGet( "/phase3-activity/me?optional=true", ); return remote?.data ?? null; } catch { return null; } }