// Feature flag helpers. Server-side only — flags are read from process.env on
// each call so a process restart picks up changes without code edits.

function isOn(value) {
  if (value === undefined || value === null) return false;
  const v = String(value).trim().toLowerCase();
  return v === '1' || v === 'true' || v === 'yes' || v === 'on';
}

// MADARX_DASHBOARD_LIVE_DELTAS=1 → dashboard subscribes to SSE state.*.changed
// events and refetches /api/state on demand. When off, the dashboard falls back
// to the legacy 5s poll (P3 of specs/active/dashboard-refactor.md, default-off
// during the soak week).
export function isDashboardLiveDeltasEnabled() {
  return isOn(process.env.MADARX_DASHBOARD_LIVE_DELTAS);
}

// MADARX_PROJECTS_LIVE_DELTAS=1 → project detail pages subscribe to the shared
// SSE bus and resync only their library slices after disk/artifact/share/ACL
// mutations. When off, the page keeps the server-rendered snapshot semantics.
export function isProjectsLiveDeltasEnabled() {
  return isOn(process.env.MADARX_PROJECTS_LIVE_DELTAS);
}
