import { v as validateAuth } from './auth-DuunT7Cg.js';
import { i as isViewerPresent, h as hasEverReported, r as reportPresence } from './presence-store-Bx_g0-Gd.js';
import { j as json } from './index-CoD1IJuy.js';
import './shared-server-DaWdgxVh.js';
import 'crypto';

const GET = ({ request }) => {
  const authError = validateAuth(request);
  if (authError) {
    return authError;
  }
  return json({ everReported: hasEverReported(), present: isViewerPresent() });
};
const POST = async ({ request }) => {
  const authError = validateAuth(request);
  if (authError) {
    return authError;
  }
  let body;
  try {
    body = await request.json();
  } catch {
    return json({ error: "Invalid JSON body" }, { status: 400 });
  }
  if (body.state !== "foreground" && body.state !== "background") {
    return json({ error: "state must be 'foreground' or 'background'" }, { status: 400 });
  }
  reportPresence(body.state);
  return json({ everReported: hasEverReported(), present: isViewerPresent(), state: body.state });
};

export { GET, POST };
//# sourceMappingURL=_server.ts-C6NRpe7e.js.map
