export async function fetchPcStatus(origin, fetchImpl = globalThis.fetch, now = () => new Date()) {
  try {
    const response = await fetchImpl(`${origin}/api/health`, { cache: "no-store", credentials: "include" });
    if (!response.ok) throw new Error("pc_unreachable");
    const body = await response.json();
    const name = String(body?.pc?.name ?? "").trim();
    return { state: "online", name, checkedAt: now() };
  } catch {
    return { state: "offline", name: "", checkedAt: null };
  }
}
