// Reusable in-development gate. Lets us ship a half-built game LIVE (so we can
// test the real, fully-wired experience) without any public visitor stumbling
// onto it:
//   • its card shows on /play only for admins (or a preview link)
//   • its route bounces non-admins back to the hub
//   • search engines never index it (the route guard + noindex)
// Launch = remove the game key from IN_DEV. Future dev games just join the set.
//
// This is casual concealment, not security — the API is harmless on its own.

// 'bloom' launched 2026-06-15 — public. 'match' (Memory/Color Match) launched
// 2026-06-17 — public. 'zen' (UB/Zen Den) gated while UB is ironed out (model
// tabled). Add a key here to gate any in-dev game/section.
export const IN_DEV = new Set(['zen']);

// A non-obvious bypass so we can test logged-out / incognito: /play?...&preview=KEY
const PREVIEW_KEY = 'sunflower';

export function isDevGated(gameKey) {
  return IN_DEV.has(gameKey);
}

// Can THIS viewer see in-dev games? Admins always; anyone with the preview token.
export function canSeeDev(user, url) {
  if (user?.is_admin) return true;
  try {
    return url?.searchParams?.get('preview') === PREVIEW_KEY;
  } catch {
    return false;
  }
}

// True when this game should be hidden/blocked for this viewer.
export function blockedForViewer(gameKey, user, url) {
  return isDevGated(gameKey) && !canSeeDev(user, url);
}
