# Draw calendar (#10)


Public page: `calendar.html` (Spanish address: `calendario.html`). It lists **ongoing**, **upcoming** and **held** draws of every type (numbers, lotto and specials such as Christmas or 31 October), with a graphic month header (`?month=2026-12`). It uses the same list of draws as the multi-draw purchase (`public.*` + `public.draws`, see [multi-draw.md](multi-draw.md)): there is no second list.

## Labels come from the server (28/11/2026)

«On sale» is never computed from the dates alone: the calendar and the home page read `GET /api/draws` (the same
checks as `POST /api/invoice`). A draw the server does not sell yet is «Announced · not on sale yet»; a paused one,
«Sales paused». An id the server enables that is no longer in `public.draws` is still listed (from what the catalog
knows) instead of disappearing.

## Month view and buying (29/11/2026)

Each day box shows the name of every draw («LOTTO21 #2», «#1 Christmas») and its time; on the phone only the icon.
The rules card is a link to the draw's page (a tap outside its links and the «Rules» toggle opens it), and its main
button is a big «⚡ BUY · price» while the draw is on sale («See result» / «See draw» otherwise).

## Names and numbers: `seq` and `seriesStart` (26/11 and 29/11/2026)

Every page names the draws with **one function**, `calendar.js → drawNamer(draws, public)` (built on `drawName` and
`seriesNumbers`): the top bar and its ‹ › arrows, the calendar, the home page, the Audit (`treasury.html?draw=ID`),
My tickets, the rules and the ticket PDF. A draw with no name of its own is «LOTTO21 #3»; one with its own title is
«🎄 #1 Nabitdad» (lists add «POLLA» next to the date); a test event (`kind: "test"` / `resultMode: "manual-test"`) has
no number («LOTTO21 · MAINNET TEST»).

- **`seq`** (per event, optional): the event's number in its game. The panel sets it when the event is created and
  it can be edited in the event's editor («Number in its game»). Without it, a draw takes the number after the
  previous draw of the same game. Each game counts apart: POLLA, LOTTO21 (4 of 21), and any other Lotto shape.
- **`public.seriesStart`** (site setting, optional): start of the **public** numbering, an ISO date and time **with
  its zone**, e.g. `"seriesStart": "2026-12-03T00:00:00+01:00"`. Edited in the panel under Settings → «Public
  numbering of the draws» and saved with the same signed `PUT /admin/config` as the rest; validated by
  `CAL.normalizeSeriesStart` in the panel, in `publicForPublish` (`common.js`) and on the server
  (`server/lib/admin-config.mjs`). Empty (or emptied in the panel) = no start.
  - Without it, the numbering is exactly the one above.
  - With it, every real draw (not a test event) whose `drawAt` is **before** `seriesStart` was a test with real sats
    and is called **«Test #N»** («Prueba #N» in Spanish): N counts by draw time inside its game and ignores `seq`.
  - From `seriesStart` on, each game starts again at **#1**: `seq` if the event has one, otherwise by date counting
    only the draws from `seriesStart`. A new event created in the panel after the start gets, in `seq`, the number
    its date gives it; one before the start gets no `seq`.
  - The rules (home page), the FAQ and the calendar add one line, its date taken from `seriesStart` as written:
    «The draws before 3 December 2026 were tests with real sats before opening to the public.»
  - The panel warns, without blocking the save: events with `seq` before the start (that number is ignored), the
    first event of a game from the start that is not #1, and two events of the same game with the same number.
- **Presentation only.** Neither `seq` nor `seriesStart` nor the «#N» name is part of any id, invoice description,
  signed commitment, OpenTimestamps seal, close or anchor notice, sale or payment event, or `results/<id>.json`. The
  signed result carries the event's own `title` field as configured (not the «#N» name): keep the titles of draws
  already held as they are.

## Rules each draw shows

They come from the configuration through `calendar.js → drawRules()`:

| Field | Where it comes from |
|---|---|
| Type | `kind`: `weekly`, `special`, `test` (empty = normal) |
| Game, range and categories | `game` and `tickets`; in lotto, the draw's `lotto` rules (N of M, categories and %) |
| Costs | Lotto: `lotto.houseFee` (3 %, cap 5 %). Numbers: the draw's or the main draw's `houseFee` (0–5 %; 0 if not published). Deducted from each prize when it is collected; the pot is all the sales ([COSTS.md](COSTS.md)) |
| Price, close and draw | `price`, `closeAt`, `drawAt` |
| Opening | `openAt` (optional): before that time the draw shows as «Coming soon» and cannot be bought |
| How the winner is computed | fixed text according to the game (see [lotto.md](lotto.md)) |
| Claim period | 30 days (`CLAIM_DAYS`); whatever is not claimed goes back to the pot |
| Notes | `notes` (optional, public text, max. 400) |

Phases (`drawPhase`): `future` (before `openAt`), `open`, `closed` (less than 60 s to the close or already closed, waiting for the block) and `held` (the block time has passed). The month view puts each draw on its day in the user's time zone.

`kind`, `notes`, `openAt` and `template` belong to each draw: an announced draw does not inherit them from the main one.

## Templates (panel)

In Settings → «Draw templates» reusable draw types are stored in `public.templates`:

```json
{ "id": "christmas", "name": "Christmas Draw (22 Dec)", "kind": "special", "game": "numbers",
  "price": 5000, "tickets": 10000, "closeBefore": 60, "openBefore": 45,
  "titlePattern": "🎄 Christmas Draw {year}", "notes": "Lots of small prizes and one big one.",
  "i18n": { "es": { "titlePattern": "🎄 Sorteo de Navidad {year}", "notes": "Muchos premios pequeños y uno gordo." } } }
```

- `closeBefore`: minutes between the sales close and the block time. `openBefore` (optional): days before the draw when sales open.
- «Announce a draw from a template»: pick a template, id and block date, and it is added to «Upcoming announced draws» with its rules (`template` keeps which template it came from). It is announced when the `config.json` is published.
- «Save as template» on each announced draw creates a template with its rules.
- «Add the sample templates»: weekly numbers, weekly LottoPolla, Christmas and whitepaper.
- Validation on publishing (`normalizeTemplates`): unique ids, price > 0, valid numbers, minutes and days in range, https image or repo path. 20 at most.

A full example with several draws: [examples/config-calendar.json](examples/config-calendar.json).
