import { today } from "./dates.js";

export interface Gate { projectClosed: boolean; providerClosed: boolean; active: boolean; from: string | null; until: string | null; lateUntil: string | null; closesOn: string }
/** One rule for every page: the gate closes by hand (project or provider), by the provider's dates, or 14 days after the class starts. */
export function closedBecause(g: Gate, now = today()): string | null {
  if (g.projectClosed) return "Registration is closed for the project.";
  if (g.providerClosed) return "Registration is closed for this provider.";
  if (!g.active) return "This provider is not active.";
  if (g.lateUntil && now <= g.lateUntil) return null;
  if ((g.from && now < g.from) || (g.until && now > g.until)) return "Registration is not open on this date.";
  return now > g.closesOn ? `Registration for this class closed on ${g.closesOn}.` : null;
}
