ferst-core 0.16.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,926 +1,1147 @@
1
- ---
2
- /**
3
- * Book — visitors book one of the organisation's offers, from the Ferst Events and bookings module.
4
- * One block, shaped by the offer (0.13.0; myai4-webdev docs/EVENTS.md slice 6c, the maintainer
5
- * 2026-11-23: "a tile that introduces what we are booking … where … and the calendar below it, all
6
- * in one block"). The head says what it is, how long, with whom or where, and the price; below it
7
- * is the way to book that offer, as the platform says (`mode`):
8
- * - times: a day, then a time of its length (a haircut);
9
- * - chosen: a day, a start, then an end, the price worked out as they choose (hall hire);
10
- * - places: the coming dates with the places left, then how many (a class, a concert); `event`
11
- * names one event of the offer (the Christmas concert) to show only its dates.
12
- * What's picked is held for the visitor at once, for 10 minutes, while they give their details; then
13
- * it's booked, emailed with an invitation, and the page offers "Add to calendar".
14
- *
15
- * The offer's name, length, price and who gives it are read from the platform at build time
16
- * (lib/book); its free times and places in the browser, since they change by the minute. Needs
17
- * JavaScript: choosing among live times can't be a plain form. Without it, the block says so.
18
- *
19
- * Or a person or a place (0.14.0; the maintainer 2026-11-24: "we need both and its up to the person
20
- * configuring the module to pick what is suitable"). `resource` alone: the head introduces them (Sam,
21
- * the Hall), then the offers they provide online as choices, and below, the chosen one's calendar,
22
- * booked with them only. `service` and `resource`: that offer, with them only.
23
- *
24
- * Shown outside a site (the Ferst portal's preview, the maintainer 2026-11-24: "utilise the core
25
- * ferst events and bookings module block as it would be applied … to visualise it before someone
26
- * clicks 'add it to my site'"): the host says which site and platform through `Astro.locals.ferstBook`,
27
- * and `demo` plays every step with the real free times but never holds or books anything.
28
- */
29
- import ContactForm from './ContactForm.astro';
30
- import Heading from '../blocks/Heading.astro';
31
- import { bookTarget, eventsData, ldJson, loadBookResource, loadBookService, loadEventDates, metaLine, whereText, type BookService, type BookWho, type EventsContext } from '../../lib/book';
32
- import { resolveGitBase, resolveSiteId } from '../../lib/git-base.mjs';
33
- import { canonicalUrl } from '../../lib/seo.mjs';
34
- import { loadSiteSettings } from '../../lib/siteSettings';
35
-
36
- interface Props {
37
- service?: string;
38
- resource?: string;
39
- event?: string;
40
- /** `button`: "Book now" for one date of a class or an event (its next with places, or `date`). */
41
- look?: 'button';
42
- date?: string;
43
- /** Dates across chosen classes and events, as one list: each an offer booked by places, or one event of it. */
44
- list?: Array<{ service: string; event?: string }>;
45
- title?: string;
46
- intro?: string;
47
- note?: string;
48
- buttonLabel?: string;
49
- }
50
- const { event, title, intro, note, buttonLabel = 'Book', look, date } = Astro.props;
51
- const list = Astro.props.list?.length ? Astro.props.list : null;
52
- const target = list ? { service: null, resource: null } : bookTarget(Astro.props);
53
- const host = (Astro.locals as { ferstBook?: { siteId?: string; platform?: string; demo?: boolean } } | undefined)?.ferstBook;
54
- const base = host?.platform ?? resolveGitBase();
55
- const siteId = host?.siteId ?? resolveSiteId();
56
- const demo = !!host?.demo;
57
- let who: BookWho | null = null;
58
- let offers: BookService[];
59
- if (list) {
60
- // A custom list (the maintainer, 2026-11-24): the dates of each, as one list.
61
- offers = await Promise.all(list.map((l) => loadBookService(l.service, { base, siteId, event: l.event ?? null })));
62
- const timed = offers.find((o) => o.mode !== 'places');
63
- if (timed) throw new Error(`Book block: a list is of classes and events, booked by places; "${timed.name}" is booked by time. Give it a block of its own, or run \`npx ferst-modules\` to list what's booked by places.`);
64
- } else if (target.service) {
65
- offers = [await loadBookService(target.service, { base, siteId, event: event ?? null, resource: target.resource })];
66
- } else {
67
- const got = await loadBookResource(target.resource!, { base, siteId });
68
- who = got.resource;
69
- offers = got.services;
70
- }
71
- const lead = offers[0];
72
- // "Book now" (the maintainer's fourth way, 2026-11-24): one date of a class or an event, nothing to pick
73
- // but how many places. A haircut or a hire becomes one date only when it's booked, so it has no button.
74
- const one = look === 'button';
75
- if (one && (who || lead.mode !== 'places')) {
76
- throw new Error(`Book block: a "Book now" button is for a class or an event, booked by places; "${lead.name}" is booked by time. Leave out "look" to show its calendar, or run \`npx ferst-modules\` to list what's booked by places.`);
77
- }
78
- const anchor = `book-${who ? who.id : `${lead.id}${lead.event ? `-${lead.event}` : ''}${lead.resource ? `-${lead.resource}` : ''}`}`;
79
- const { align: blockAlign, headingAlign } = Astro.props as { align?: 'start' | 'center' | 'end'; headingAlign?: 'start' | 'center' | 'end' };
80
- const headAlign = headingAlign ?? blockAlign ?? 'center';
81
- // The head: the offer (its length, with whom or where, its price), or the person or place it names.
82
- const heading = title ?? (list ? 'Coming up' : who ? who.name : lead.name);
83
- const meta = list ? '' : who ? (offers.length === 1 ? metaLine({ ...lead, resources: [] }) : '') : metaLine(lead);
84
- const lines = intro ?? (list ? '' : who ? who.description : lead.description);
85
- const many = !list && offers.length > 1;
86
- const panels = list ? [lead] : offers;
87
- const sources = list ? JSON.stringify(offers.map((o) => ({ book: o.definition, event: o.event ?? '' }))) : undefined;
88
- const placeOf = (d: BookService) => d.resources.find((r) => r.kind === 'place')?.name ?? '';
89
-
90
- // For search engines (0.15.0; myai4-webdev docs/EVENTS.md slice 6d): each coming date of a class or an
91
- // event as a schema.org Event, once the site has an address (as all its structured data, Base.astro).
92
- // Read at build, and brought up to date as the page loads. A preview (no site address) has none.
93
- const siteUrl = (import.meta.env.FERST_SITE_URL as string | undefined) || '';
94
- let ldContext: EventsContext | null = null;
95
- if (siteUrl) {
96
- const settings = await loadSiteSettings().catch(() => null);
97
- ldContext = {
98
- url: `${canonicalUrl(siteUrl, Astro.url?.pathname ?? '/')}#${anchor}`,
99
- organisation: { name: settings?.identity?.siteTitle, url: `${siteUrl.replace(/\/+$/, '')}/` },
100
- places: (settings?.places ?? []) as EventsContext['places'],
101
- };
102
- }
103
- const ldOf = async (def: BookService): Promise<string | null> => {
104
- if (!ldContext || def.mode !== 'places') return null;
105
- const dates = list
106
- ? (await Promise.all(offers.map((o) => loadEventDates(o.definition, { event: o.event })))).flat().sort((a, b) => a.start.localeCompare(b.start))
107
- : await loadEventDates(def.definition, { event: def.event, resource: def.resource });
108
- const data = eventsData(dates, ldContext);
109
- return data ? ldJson(data) : null;
110
- };
111
- const lds = await Promise.all(panels.map(ldOf));
112
- ---
113
-
114
- <section class="b-book" id={anchor} data-book-block data-demo={demo ? '1' : undefined} data-find={`${base}/sites/${encodeURIComponent(siteId ?? '')}/book/find`}>
115
- {demo && <p class="b-book__notice" data-book-demo>A preview: try it as a visitor would. The free times are real; nothing is held or booked.</p>}
116
- <div class="b-book__head" data-recipe-head data-content-align={headAlign}>
117
- <Heading text={heading} level={2} />
118
- {meta && <p class="b-book__meta" data-book-meta>{meta}</p>}
119
- {lines && <p class="b-book__intro">{lines}</p>}
120
- </div>
121
-
122
- <noscript><p class="b-book__notice">Booking needs JavaScript switched on in your browser.</p></noscript>
123
-
124
- {many && (
125
- <div class="b-book__offers" role="group" aria-label="What would you like to book?" data-book-offers>
126
- {offers.map((d, i) => (
127
- <button type="button" class="b-book__offer" data-book-offer={d.id} aria-pressed={String(i === 0)}>
128
- <strong>{d.name}</strong>
129
- <span>{metaLine({ ...d, resources: [] })}</span>
130
- </button>
131
- ))}
132
- </div>
133
- )}
134
-
135
- {panels.map((def, i) => {
136
- const where = placeOf(def);
137
- const picksWho = def.mode !== 'places' && def.resources.length > 1;
138
- return (
139
- <div class="b-book__panel" data-book={def.definition} data-holds={def.holds} data-name={def.name} data-label={buttonLabel} data-offer={def.id}
140
- data-mode={def.mode} data-event={list ? '' : def.event ?? ''} data-resource={def.resource ?? ''} data-minutes={def.minutes} data-step={def.step} data-where={list ? '' : where}
141
- data-list={sources}
142
- data-look={one ? 'button' : undefined} data-date={one ? date ?? '' : undefined}
143
- data-with={whereText(def.resources)} hidden={i > 0}>
144
- {lds[i] && <script type="application/ld+json" is:inline data-book-ld data-ctx={JSON.stringify(ldContext)} set:html={lds[i]} />}
145
- {many && def.description && <p class="b-book__intro">{def.description}</p>}
146
- <div class="b-book__notice" role="alert" data-book-error hidden></div>
147
-
148
- {/* Step 1: what to book */}
149
- <div class="b-book__pick" data-book-pick hidden>
150
- {picksWho && (
151
- <label class="b-book__who">
152
- <span>{def.resources.every((r) => r.kind === 'place') ? 'Where' : 'Who with'}</span>
153
- <select data-book-who>
154
- <option value="">{def.resources.every((r) => r.kind === 'place') ? 'Anywhere free' : 'Anyone available'}</option>
155
- {def.resources.map((r) => <option value={r.id}>{r.name}</option>)}
156
- </select>
157
- </label>
158
- )}
159
- <div class="b-book__days-bar" hidden={one}>
160
- <button type="button" class="b-book__nav" data-book-earlier aria-label="Earlier dates" disabled>‹</button>
161
- <div class="b-book__days" role="group" aria-label="Choose a day" data-book-days></div>
162
- <button type="button" class="b-book__nav" data-book-later aria-label="Later dates">›</button>
163
- </div>
164
- <div class="b-book__times" role="group" aria-label={def.mode === 'places' ? 'Choose a date' : def.mode === 'chosen' ? 'Choose when it starts' : 'Choose a time'} data-book-times aria-live="polite">
165
- <p class="b-book__empty">{def.mode === 'places' ? 'Loading dates…' : 'Loading free times…'}</p>
166
- </div>
167
- {def.mode === 'chosen' && (
168
- <div class="b-book__more" data-book-end hidden>
169
- <label class="b-book__who"><span>Until</span><select data-book-end-select></select></label>
170
- <p class="b-book__quote" data-book-quote aria-live="polite"></p>
171
- <button type="button" class="b-book__go" data-book-hold>Hold this time</button>
172
- </div>
173
- )}
174
- {def.mode === 'places' && (
175
- <div class="b-book__more" data-book-places hidden>
176
- <p class="b-book__chosen" data-book-chosen></p>
177
- <label class="b-book__who"><span>How many places</span><input type="number" min="1" value="1" inputmode="numeric" data-book-count /></label>
178
- <p class="b-book__quote" data-book-quote aria-live="polite"></p>
179
- <button type="button" class="b-book__go" data-book-hold>{one ? 'Book now' : 'Hold these places'}</button>
180
- </div>
181
- )}
182
- </div>
183
-
184
- {/* Step 2: who they are */}
185
- <div class="b-book__details" data-book-details hidden>
186
- <p class="b-book__held" data-book-held></p>
187
- <ContactForm
188
- action={def.holds}
189
- method="post"
190
- submitLabel={buttonLabel}
191
- note={note ?? 'We’ll email you the booking, with an invitation for your calendar.'}
192
- fields={[
193
- { name: 'name', label: 'Your name', type: 'text', required: true },
194
- { name: 'email', label: 'Your email', type: 'email', required: true },
195
- { name: 'phone', label: 'Your phone (optional)', type: 'tel' },
196
- { name: 'notes', label: 'Anything we should know? (optional)', type: 'textarea' },
197
- ]}
198
- honeypot
199
- idPrefix={many ? `${anchor}-${def.id}` : anchor}
200
- />
201
- <button type="button" class="b-book__link" data-book-again>{def.mode === 'places' ? 'Choose another date' : 'Choose another time'}</button>
202
- </div>
203
-
204
- {/* Step 3: booked, and "Add to calendar" */}
205
- <div class="b-book__notice b-book__notice--done" role="status" data-book-done hidden></div>
206
- </div>
207
- );
208
- })}
209
-
210
- {/* Their own bookings: the links, emailed to the address they booked with (2026-11-24). */}
211
- <details class="b-book__find" data-book-find>
212
- <summary>Change or cancel a booking</summary>
213
- <form class="b-book__find-form" data-book-find-form>
214
- <label class="b-book__who"><span>The email you booked with</span><input type="email" name="email" required autocomplete="email" id={`${anchor}-find-email`} /></label>
215
- <button type="submit" class="b-book__go">Email me my bookings</button>
216
- </form>
217
- <p class="b-book__find-said" role="status" data-book-find-said></p>
218
- </details>
219
- </section>
220
-
221
- <script>
222
- import { addDays, bookingMessage, calendarFile, dayChip, endChoices, eventsData, googleCalendarLink, londonDay, whenText, whichFree, type EventDate, type EventsContext, type TimesAnswer } from '../../lib/book';
223
-
224
- const SPAN = 14; // days shown at once (dates for a class: four weeks)
225
- const AHEAD = 60; // how far ahead the platform takes bookings
226
-
227
- type Hold = { id: string; start: string; end: string; places?: number; title?: string; resource: { name: string }; price: { label: string; note?: string | null } | null };
228
-
229
- /** One offer's way to book, in its panel. Returns how to start it (once shown) and to leave it. */
230
- function setUp(block: HTMLElement) {
231
- const src = block.dataset.book!;
232
- const holds = block.dataset.holds!;
233
- const mode = (block.dataset.mode ?? 'times') as 'times' | 'chosen' | 'places';
234
- const onlyEvent = block.dataset.event || '';
235
- const onlyWith = block.dataset.resource || ''; // the person or place the block names: booked with them only
236
- const demo = !!block.closest('[data-book-block]')?.hasAttribute('data-demo'); // a preview: nothing is held or booked
237
- const minutes = Number(block.dataset.minutes ?? '30');
238
- const step = Number(block.dataset.step ?? '30');
239
- const where = block.dataset.where ?? '';
240
- const one = block.dataset.look === 'button'; // "Book now": one date, only how many places left to choose
241
- // A custom list: each source's dates, as one list; each date booked through its own offer.
242
- const sources = block.dataset.list ? (JSON.parse(block.dataset.list) as Array<{ book: string; event: string }>) : null;
243
- const srcOf = (d: EventDate | null) => (d as (EventDate & { src?: string }) | null)?.src ?? src;
244
- const pinned = block.dataset.date || '';
245
- const span = one ? 31 : mode === 'places' ? SPAN * 2 : SPAN;
246
- const $ = <T extends HTMLElement>(sel: string) => block.querySelector<T>(sel)!;
247
- const pick = $('[data-book-pick]');
248
- const details = $('[data-book-details]');
249
- const done = $('[data-book-done]');
250
- const error = $('[data-book-error]');
251
- const daysEl = $('[data-book-days]');
252
- const timesEl = $('[data-book-times]');
253
- const earlier = $<HTMLButtonElement>('[data-book-earlier]');
254
- const later = $<HTMLButtonElement>('[data-book-later]');
255
- const who = block.querySelector<HTMLSelectElement>('[data-book-who]');
256
- const more = block.querySelector<HTMLElement>('[data-book-end], [data-book-places]');
257
- const endSel = block.querySelector<HTMLSelectElement>('[data-book-end-select]');
258
- const count = block.querySelector<HTMLInputElement>('[data-book-count]');
259
- const quoteEl = block.querySelector<HTMLElement>('[data-book-quote]');
260
- const holdBtn = block.querySelector<HTMLButtonElement>('[data-book-hold]');
261
- const chosenEl = block.querySelector<HTMLElement>('[data-book-chosen]');
262
- const form = details.querySelector<HTMLFormElement>('form')!;
263
- const submit = form.querySelector<HTMLButtonElement>('button[type="submit"]');
264
-
265
- const today = londonDay();
266
- let from = today;
267
- let answer: TimesAnswer | null = null;
268
- let day: string | null = null;
269
- let start: string | null = null; // chosen: the start picked (HH:MM)
270
- let date: EventDate | null = null; // places: the date picked
271
- let hold: Hold | null = null;
272
-
273
- const say = (text: string | null) => { error.textContent = text ?? ''; error.hidden = !text; };
274
- const show = (stepName: 'pick' | 'details' | 'done') => { pick.hidden = stepName !== 'pick'; details.hidden = stepName !== 'details'; done.hidden = stepName !== 'done'; };
275
- const free = (d: string) => (answer?.days.find((x) => x.day === d)?.times ?? []).filter((t) => !who?.value || t.resources.includes(who.value));
276
- const button = (cls: string, text: string, onClick: () => void, disabled = false) => {
277
- const b = document.createElement('button');
278
- b.type = 'button'; b.className = cls; b.textContent = text; b.disabled = disabled;
279
- b.addEventListener('click', onClick);
280
- return b;
281
- };
282
-
283
- // ── The days (times and chosen) ────────────────────────────────────────────
284
- function drawDays() {
285
- daysEl.hidden = mode === 'places';
286
- if (mode !== 'places') {
287
- daysEl.replaceChildren(...(answer?.days ?? []).map((d) => {
288
- const chip = dayChip(d.day);
289
- const b = document.createElement('button');
290
- b.type = 'button';
291
- b.className = 'b-book__day';
292
- b.disabled = free(d.day).length === 0;
293
- b.setAttribute('aria-pressed', String(d.day === day));
294
- b.innerHTML = `<span>${chip.weekday}</span><strong>${chip.date}</strong>`;
295
- b.setAttribute('aria-label', `${chip.weekday} ${chip.date}${b.disabled ? ', nothing free' : ''}`);
296
- b.addEventListener('click', () => { day = d.day; start = null; drawDays(); drawTimes(); });
297
- return b;
298
- }));
299
- }
300
- earlier.disabled = from <= today;
301
- later.disabled = addDays(from, span) > addDays(today, AHEAD);
302
- }
303
-
304
- function drawTimes() {
305
- if (more) more.hidden = true;
306
- if (mode === 'places') return drawDates();
307
- const times = day ? free(day) : [];
308
- if (!day) { timesEl.innerHTML = `<p class="b-book__empty">${answer?.days.some((d) => free(d.day).length) ? 'Choose a day.' : 'Nothing free in these dates. Try later dates.'}</p>`; return; }
309
- if (!times.length) { timesEl.innerHTML = '<p class="b-book__empty">Nothing free that day.</p>'; return; }
310
- // Several places, "Anywhere free" (the maintainer's second way, 2026-11-24: "hall hire showing any
311
- // hall available"): each time says which are free then.
312
- const places = answer?.resources ?? [];
313
- timesEl.replaceChildren(...times.map((t) => {
314
- const b = button('b-book__time', t.time, () => (mode === 'chosen' ? chooseStart(t.time) : void take({ start: t.start })));
315
- const which = who?.value ? null : whichFree(t.resources, places);
316
- if (which) {
317
- b.innerHTML = '<strong></strong><span></span>';
318
- b.querySelector('strong')!.textContent = t.time;
319
- b.querySelector('span')!.textContent = which;
320
- b.setAttribute('aria-label', `${t.time}, free: ${which}`);
321
- b.classList.add('b-book__time--which');
322
- }
323
- if (mode === 'chosen') b.setAttribute('aria-pressed', String(t.time === start));
324
- return b;
325
- }));
326
- }
327
-
328
- // ── Hall hire: a start, then an end, and what it comes to ─────────────────
329
- function chooseStart(time: string) {
330
- start = time;
331
- drawTimes();
332
- const ends = endChoices(free(day!).map((t) => t.time), time, minutes, step);
333
- endSel!.replaceChildren(...ends.map((e) => { const o = document.createElement('option'); o.value = e; o.textContent = e === '24:00' ? 'midnight' : e; return o; }));
334
- more!.hidden = !ends.length;
335
- void quote();
336
- }
337
-
338
- // ── A class or a concert: its coming dates, then how many places ──────────
339
- function drawDates() {
340
- const dates = answer?.events ?? [];
341
- if (one) {
342
- const d = dates.find((x) => (pinned ? x.start === pinned : x.left > 0));
343
- if (!d || d.left === 0) { timesEl.innerHTML = `<p class="b-book__empty">${d ? 'It’s full.' : 'No dates with places just now.'}</p>`; return; }
344
- const card = document.createElement('div');
345
- card.className = 'b-book__one';
346
- card.innerHTML = '<strong></strong><span></span>';
347
- card.querySelector('strong')!.textContent = d.title;
348
- card.querySelector('span')!.textContent = `${whenText(d.start)}${where ? `, at ${where}` : ''} · ${d.left} ${d.left === 1 ? 'place' : 'places'} left · ${d.price}`;
349
- timesEl.replaceChildren(card);
350
- date = d;
351
- chosenEl!.textContent = '';
352
- count!.max = String(d.left);
353
- if (Number(count!.value) > d.left) count!.value = String(d.left);
354
- more!.hidden = false;
355
- void quote();
356
- return;
357
- }
358
- if (!dates.length) { timesEl.innerHTML = `<p class="b-book__empty">${onlyEvent ? 'No dates to book in these weeks.' : 'Nothing to book in these weeks. Try later dates.'}</p>`; return; }
359
- timesEl.replaceChildren(...dates.map((d) => {
360
- const chip = dayChip(d.start.slice(0, 10));
361
- const left = d.left === 0 ? 'Full' : `${d.left} ${d.left === 1 ? 'place' : 'places'} left`;
362
- const b = button('b-book__date', '', () => chooseDate(d), d.left === 0);
363
- b.innerHTML = `<strong>${chip.weekday} ${chip.date}, ${d.start.slice(11)}</strong><span>${onlyEvent ? '' : `${d.title} · `}${left} · ${d.price}</span>`;
364
- b.setAttribute('aria-pressed', String(date?.event_id === d.event_id && date?.start === d.start));
365
- return b;
366
- }));
367
- }
368
- function chooseDate(d: EventDate) {
369
- date = d;
370
- drawDates();
371
- chosenEl!.textContent = `${d.title}, ${whenText(d.start)}${where ? `, at ${where}` : ''}.`;
372
- count!.max = String(d.left);
373
- if (Number(count!.value) > d.left) count!.value = String(d.left);
374
- more!.hidden = false;
375
- void quote();
376
- }
377
-
378
- /** What it comes to, from the platform, as they choose. */
379
- async function quote() {
380
- if (!quoteEl) return;
381
- quoteEl.textContent = '';
382
- let q = '';
383
- if (mode === 'chosen' && day && start && endSel?.value) {
384
- const end = endSel.value === '24:00' ? `${addDays(day, 1)}T00:00` : `${day}T${endSel.value}`;
385
- q = `start=${day}T${start}&end=${end}`;
386
- } else if (mode === 'places' && date) {
387
- q = `start=${date.start}&end=${date.end}&places=${Math.max(1, Number(count!.value) || 1)}&event=${encodeURIComponent(date.event_id)}`;
388
- }
389
- if (!q) return;
390
- const res = await fetch(`${srcOf(date)}/quote?${q}`, { headers: { Accept: 'application/json' } }).catch(() => null);
391
- const body = res?.ok ? await res.json().catch(() => null) : null;
392
- if (!body) return;
393
- quoteEl.textContent = body.price ? `${body.price.label} · ${body.price.lines.join('; ')} · paid on the day` : 'Free';
394
- if (holdBtn && mode === 'places' && !one) { const n = Math.max(1, Number(count!.value) || 1); holdBtn.textContent = `Hold ${n === 1 ? 'this place' : `${n} places`}`; }
395
- }
396
-
397
- /** The page's dates for search engines, brought up to date (the places left) from what's just been read. */
398
- function freshForSearch() {
399
- const ld = block.querySelector<HTMLScriptElement>('script[data-book-ld]');
400
- if (!ld || !answer || from !== today) return;
401
- const data = eventsData(answer.events ?? [], JSON.parse(ld.dataset.ctx ?? '{}') as EventsContext);
402
- if (data) ld.textContent = JSON.stringify(data);
403
- else ld.remove();
404
- }
405
-
406
- async function load() {
407
- say(null);
408
- timesEl.innerHTML = `<p class="b-book__empty">${mode === 'places' ? 'Loading dates…' : 'Loading free times…'}</p>`;
409
- try {
410
- if (sources) {
411
- const all = await Promise.all(sources.map(async (s) => {
412
- const r = await fetch(`${s.book}?from=${from}&to=${addDays(from, span)}${s.event ? `&event=${encodeURIComponent(s.event)}` : ''}`, { headers: { Accept: 'application/json' } });
413
- if (!r.ok) { const b = await r.json().catch(() => ({})); throw new Error(b.error ?? String(r.status)); }
414
- return ((await r.json()) as TimesAnswer).events?.map((e) => ({ ...e, src: s.book })) ?? [];
415
- }));
416
- answer = { service: { id: '', name: block.dataset.name ?? '', minutes }, resources: [], days: [], events: all.flat().sort((a, b) => a.start.localeCompare(b.start)) };
417
- start = null; date = null;
418
- drawDays(); drawTimes(); freshForSearch();
419
- return;
420
- }
421
- const res = await fetch(`${src}?from=${from}&to=${addDays(from, span)}${onlyEvent ? `&event=${encodeURIComponent(onlyEvent)}` : ''}${onlyWith ? `&resource=${encodeURIComponent(onlyWith)}` : ''}`, { headers: { Accept: 'application/json' } });
422
- if (!res.ok) { const b = await res.json().catch(() => ({})); throw new Error(b.error ?? String(res.status)); }
423
- answer = (await res.json()) as TimesAnswer;
424
- day = answer.days.find((d) => free(d.day).length)?.day ?? null;
425
- start = null; date = null;
426
- drawDays(); drawTimes(); freshForSearch();
427
- } catch (e) {
428
- timesEl.innerHTML = '';
429
- say(bookingMessage(e instanceof Error ? e.message : ''));
430
- }
431
- }
432
-
433
- /** A preview's hold: what a visitor would see held, with nothing sent. */
434
- function pretend(body: Record<string, unknown>) {
435
- const start = String(body.start);
436
- const plus = (local: string, m: number) => { const t = Number(local.slice(11, 13)) * 60 + Number(local.slice(14, 16)) + m; return `${local.slice(0, 11)}${String(Math.floor(t / 60) % 24).padStart(2, '0')}:${String(t % 60).padStart(2, '0')}`; };
437
- hold = { id: '', start, end: typeof body.end === 'string' ? body.end : date ? date.end : plus(start, minutes), places: typeof body.places === 'number' ? body.places : undefined, title: date?.title, resource: { name: '' }, price: null };
438
- const h = hold;
439
- const what = h.places ? `${h.title ?? block.dataset.name}, ${whenText(h.start)}, ${h.places} ${h.places === 1 ? 'place' : 'places'}` : `${whenText(h.start)} to ${h.end.slice(11)}`;
440
- $('[data-book-held]').textContent = `${what}. On your website, this is kept for the visitor for 10 minutes while they give their details. In this preview, nothing is kept.`;
441
- show('details');
442
- }
443
-
444
- /** Hold what was picked: a time (and an end), or places at a date. */
445
- async function take(body: Record<string, unknown>) {
446
- say(null);
447
- if (demo) { pretend(body); return; }
448
- const res = await fetch(`${mode === 'places' ? srcOf(date) : src}/hold`, {
449
- method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
450
- body: JSON.stringify({ ...body, ...(who?.value || onlyWith ? { resource_id: who?.value || onlyWith } : {}) }),
451
- }).catch(() => null);
452
- const answerBody = res ? await res.json().catch(() => ({})) : {};
453
- if (!res || res.status !== 201) { say(bookingMessage(answerBody.error ?? '')); await load(); return; }
454
- hold = answerBody.hold as Hold;
455
- const h = hold;
456
- const what = h.places ? `${h.title ?? block.dataset.name}, ${whenText(h.start)}, ${h.places} ${h.places === 1 ? 'place' : 'places'}` : `${whenText(h.start)} to ${h.end.slice(11)}, ${h.resource.name ? `${where ? 'at' : 'with'} ${h.resource.name}` : ''}`;
457
- const price = h.price ? ` ${h.price.label}, paid on the day.` : '';
458
- $('[data-book-held]').textContent = `${what}.${price} We’re keeping this for you for 10 minutes while you give your details.`;
459
- show('details');
460
- form.querySelector<HTMLInputElement>('input[name="name"]')?.focus();
461
- }
462
-
463
- holdBtn?.addEventListener('click', () => {
464
- if (mode === 'chosen' && day && start && endSel?.value) {
465
- void take({ start: `${day}T${start}`, end: endSel.value === '24:00' ? `${addDays(day, 1)}T00:00` : `${day}T${endSel.value}` });
466
- } else if (mode === 'places' && date) {
467
- void take({ event_id: date.event_id, start: date.start, places: Math.max(1, Number(count!.value) || 1) });
468
- }
469
- });
470
- endSel?.addEventListener('change', () => void quote());
471
- count?.addEventListener('input', () => void quote());
472
-
473
- form.addEventListener('submit', async (ev) => {
474
- ev.preventDefault();
475
- if (!hold) return;
476
- say(null);
477
- if (demo) {
478
- done.innerHTML = '';
479
- const strong = document.createElement('strong');
480
- strong.textContent = 'This is a preview: nothing was booked.';
481
- done.append(strong, ' On your website, the visitor would now be booked, emailed the booking with an invitation for their calendar, and offered “Add to calendar”.');
482
- hold = null;
483
- show('done');
484
- done.focus();
485
- return;
486
- }
487
- const data = Object.fromEntries(new FormData(form).entries());
488
- if (submit) submit.disabled = true;
489
- const res = await fetch(`${holds}/${hold.id}`, {
490
- method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify(data),
491
- }).catch(() => null);
492
- if (submit) submit.disabled = false;
493
- const body = res ? await res.json().catch(() => ({})) : {};
494
- if (!res || !res.ok) {
495
- say(bookingMessage(body.error ?? ''));
496
- if (body.error === 'hold_expired' || body.error === 'already_booked') { hold = null; show('pick'); await load(); }
497
- return;
498
- }
499
- const b = body.booking as { id: string; status?: string; start: string; end: string; starts_at?: string; ends_at?: string; service: string; resource: string; places?: number };
500
- done.innerHTML = '';
501
- const strong = document.createElement('strong');
502
- const withWhom = b.resource ? `, ${where ? 'at' : 'with'} ${b.resource}` : '';
503
- // On request (platform 2026-11-24): asked for, its time kept, until the organisation confirms it.
504
- if (b.status === 'requested') {
505
- strong.textContent = `Requested: ${b.service}, ${whenText(b.start)}${b.places ? `, ${b.places} ${b.places === 1 ? 'place' : 'places'}` : ''}${withWhom}.`;
506
- done.append(strong, ' The time is kept for you while they answer. We’ve emailed you, and you’ll get the booking, with an invitation for your calendar, once it’s confirmed.');
507
- hold = null;
508
- show('done');
509
- done.focus();
510
- return;
511
- }
512
- strong.textContent = `Booked: ${b.service}, ${whenText(b.start)}${b.places ? `, ${b.places} ${b.places === 1 ? 'place' : 'places'}` : ''}${withWhom}.`;
513
- done.append(strong, ' We’ve emailed you the booking, with an invitation for your calendar.');
514
- if (b.starts_at && b.ends_at) {
515
- const booked = { title: `${b.service}${withWhom.replace(/^, /, ' ')}`, starts_at: b.starts_at, ends_at: b.ends_at, location: where || null, uid: b.id };
516
- const add = document.createElement('p');
517
- add.className = 'b-book__add';
518
- const google = document.createElement('a');
519
- google.href = googleCalendarLink(booked); google.target = '_blank'; google.rel = 'noopener'; google.textContent = 'Add to Google Calendar';
520
- const file = document.createElement('a');
521
- file.href = `data:text/calendar;charset=utf-8,${encodeURIComponent(calendarFile(booked))}`; file.download = 'booking.ics'; file.textContent = 'Add to Apple Calendar or Outlook';
522
- add.append(google, ' · ', file);
523
- done.append(add);
524
- }
525
- hold = null;
526
- show('done');
527
- done.focus();
528
- });
529
-
530
- $('[data-book-again]').addEventListener('click', async () => {
531
- if (hold?.id) await fetch(`${holds}/${hold.id}`, { method: 'DELETE' }).catch(() => null);
532
- hold = null;
533
- show('pick');
534
- await load();
535
- });
536
- earlier.addEventListener('click', () => { from = addDays(from, -span) < today ? today : addDays(from, -span); void load(); });
537
- later.addEventListener('click', () => { from = addDays(from, span); void load(); });
538
- who?.addEventListener('change', () => { day = answer?.days.find((d) => free(d.day).length)?.day ?? null; start = null; drawDays(); drawTimes(); });
539
- done.tabIndex = -1;
540
-
541
- let started = false;
542
- return {
543
- /** Shown: load its times the first time. */
544
- start() { if (!started) { started = true; show('pick'); void load(); } },
545
- /** Another offer chosen: let go of anything held here. */
546
- async leave() {
547
- if (hold?.id) await fetch(`${holds}/${hold.id}`, { method: 'DELETE' }).catch(() => null);
548
- hold = null;
549
- if (started) { show('pick'); say(null); }
550
- },
551
- };
552
- }
553
-
554
- // A block for a person or a place shows each offer they provide as a choice, and the chosen one's panel.
555
- document.querySelectorAll<HTMLElement>('[data-book-block]').forEach((section) => {
556
- const panels = [...section.querySelectorAll<HTMLElement>('[data-book]')].map((el) => ({ el, run: setUp(el) }));
557
- const choices = [...section.querySelectorAll<HTMLButtonElement>('[data-book-offer]')];
558
- const choose = (offer: string) => {
559
- for (const p of panels) {
560
- const on = p.el.dataset.offer === offer;
561
- if (!on && !p.el.hidden) void p.run.leave();
562
- p.el.hidden = !on;
563
- if (on) p.run.start();
564
- }
565
- for (const c of choices) c.setAttribute('aria-pressed', String(c.dataset.bookOffer === offer));
566
- };
567
- for (const c of choices) c.addEventListener('click', () => choose(c.dataset.bookOffer!));
568
- if (panels[0]) choose(panels[0].el.dataset.offer!);
569
-
570
- // "Change or cancel a booking": the same answer whatever the address, from the platform.
571
- const findForm = section.querySelector<HTMLFormElement>('[data-book-find-form]');
572
- const said = section.querySelector<HTMLElement>('[data-book-find-said]');
573
- findForm?.addEventListener('submit', async (ev) => {
574
- ev.preventDefault();
575
- if (!said) return;
576
- const email = String(new FormData(findForm).get('email') ?? '').trim();
577
- if (section.hasAttribute('data-demo')) { said.textContent = `In this preview, nothing is sent. On your website, ${email || 'they'} would be emailed a link to each of their bookings.`; return; }
578
- said.textContent = 'One moment…';
579
- const res = await fetch(section.dataset.find!, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify({ email }) }).catch(() => null);
580
- const body = res ? await res.json().catch(() => ({})) : {};
581
- said.textContent = res?.ok ? (body.message ?? 'If you have bookings with us under that address, we’ve emailed you a link to each.') : bookingMessage(body.error ?? '');
582
- });
583
- });
584
- </script>
585
-
586
- <style>
587
- .b-book {
588
- display: flex;
589
- flex-direction: column;
590
- gap: 1.25rem;
591
- max-width: 40rem;
592
- margin-inline: auto;
593
- padding-inline: 1rem;
594
- }
595
- .b-book :global(.b-contact-form) {
596
- padding-inline: 0;
597
- }
598
- .b-book__head {
599
- display: flex;
600
- flex-direction: column;
601
- gap: 0.5rem;
602
- }
603
- .b-book__meta {
604
- margin: 0;
605
- color: var(--muted);
606
- font-weight: 600;
607
- }
608
- .b-book__intro {
609
- margin: 0;
610
- color: var(--muted);
611
- line-height: 1.6;
612
- }
613
- .b-book__pick,
614
- .b-book__details {
615
- display: flex;
616
- flex-direction: column;
617
- gap: 1rem;
618
- }
619
- .b-book__who {
620
- display: flex;
621
- flex-direction: column;
622
- gap: 0.4rem;
623
- font-weight: 600;
624
- color: var(--fg);
625
- }
626
- .b-book__who select {
627
- font: inherit;
628
- font-weight: 400;
629
- color: var(--fg);
630
- background: var(--field-bg, var(--bg-surface));
631
- border: var(--field-border, 1px solid var(--border));
632
- border-radius: var(--field-radius, var(--radius-sm));
633
- padding: 0.6rem 0.75rem;
634
- max-width: 20rem;
635
- }
636
- .b-book__days-bar {
637
- display: flex;
638
- align-items: center;
639
- gap: 0.5rem;
640
- }
641
- .b-book__days {
642
- display: flex;
643
- gap: 0.5rem;
644
- overflow-x: auto;
645
- flex: 1;
646
- padding-block: 0.25rem;
647
- scrollbar-width: thin;
648
- }
649
- .b-book__day,
650
- .b-book__time,
651
- .b-book__nav {
652
- font: inherit;
653
- color: var(--fg);
654
- background: var(--bg-surface);
655
- border: 1px solid var(--border);
656
- border-radius: var(--radius-sm);
657
- cursor: pointer;
658
- transition: border-color 0.15s ease, background 0.15s ease;
659
- }
660
- .b-book__day {
661
- display: flex;
662
- flex-direction: column;
663
- align-items: center;
664
- min-width: 4.25rem;
665
- padding: 0.5rem 0.4rem;
666
- font-size: 0.85rem;
667
- line-height: 1.3;
668
- }
669
- .b-book__day strong {
670
- font-size: 0.95rem;
671
- }
672
- .b-book__nav {
673
- padding: 0.6rem 0.8rem;
674
- font-size: 1.1rem;
675
- }
676
- .b-book__day[aria-pressed='true'] {
677
- border-color: var(--gold);
678
- background: var(--gold-light);
679
- }
680
- .b-book__day:disabled,
681
- .b-book__nav:disabled {
682
- opacity: 0.4;
683
- cursor: default;
684
- }
685
- .b-book__day:not(:disabled):hover,
686
- .b-book__time:hover,
687
- .b-book__nav:not(:disabled):hover {
688
- border-color: var(--gold);
689
- }
690
- .b-book__day:focus-visible,
691
- .b-book__time:focus-visible,
692
- .b-book__nav:focus-visible,
693
- .b-book__link:focus-visible {
694
- outline: 2px solid var(--gold);
695
- outline-offset: 2px;
696
- }
697
- .b-book__times {
698
- display: grid;
699
- grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
700
- gap: 0.5rem;
701
- }
702
- .b-book__time {
703
- padding: 0.6rem 0.5rem;
704
- font-variant-numeric: tabular-nums;
705
- font-weight: 600;
706
- }
707
- .b-book__empty {
708
- grid-column: 1 / -1;
709
- margin: 0;
710
- color: var(--muted);
711
- }
712
- .b-book__held {
713
- margin: 0;
714
- padding: 0.85rem 1rem;
715
- border-radius: var(--radius-sm);
716
- background: var(--bg-section);
717
- line-height: 1.5;
718
- }
719
- .b-book__link {
720
- align-self: flex-start;
721
- padding: 0;
722
- border: 0;
723
- background: none;
724
- color: var(--fg);
725
- font: inherit;
726
- text-decoration: underline;
727
- cursor: pointer;
728
- }
729
- .b-book__notice {
730
- padding: 0.85rem 1rem;
731
- border: 1px solid var(--border);
732
- border-radius: var(--radius-sm);
733
- background: var(--bg-section);
734
- color: var(--fg);
735
- line-height: 1.5;
736
- }
737
- .b-book__notice--done {
738
- border-color: var(--gold);
739
- background: var(--gold-light);
740
- }
741
- .b-book__notice[hidden],
742
- .b-book__pick[hidden],
743
- .b-book__details[hidden] {
744
- display: none;
745
- }
746
- .b-book__more {
747
- display: flex;
748
- flex-direction: column;
749
- gap: 0.75rem;
750
- padding: 1rem;
751
- border: 1px solid var(--border);
752
- border-radius: var(--radius-sm);
753
- background: var(--bg-section);
754
- }
755
- .b-book__more input,
756
- .b-book__more select {
757
- font: inherit;
758
- font-weight: 400;
759
- color: var(--fg);
760
- background: var(--field-bg, var(--bg-surface));
761
- border: var(--field-border, 1px solid var(--border));
762
- border-radius: var(--field-radius, var(--radius-sm));
763
- padding: 0.6rem 0.75rem;
764
- max-width: 12rem;
765
- }
766
- .b-book__quote,
767
- .b-book__chosen {
768
- margin: 0;
769
- font-weight: 600;
770
- font-variant-numeric: tabular-nums;
771
- }
772
- .b-book__go {
773
- align-self: flex-start;
774
- font: inherit;
775
- font-weight: 700;
776
- padding: 0.65rem 1.25rem;
777
- border: 0;
778
- border-radius: var(--radius-sm);
779
- background: var(--gold);
780
- color: var(--on-gold, #fff);
781
- cursor: pointer;
782
- }
783
- .b-book__go:focus-visible,
784
- .b-book__date:focus-visible {
785
- outline: 2px solid var(--gold);
786
- outline-offset: 2px;
787
- }
788
- .b-book__times:has(.b-book__date) {
789
- grid-template-columns: 1fr;
790
- }
791
- .b-book__date {
792
- display: flex;
793
- flex-direction: column;
794
- align-items: flex-start;
795
- gap: 0.15rem;
796
- padding: 0.7rem 0.9rem;
797
- font: inherit;
798
- text-align: start;
799
- color: var(--fg);
800
- background: var(--bg-surface);
801
- border: 1px solid var(--border);
802
- border-radius: var(--radius-sm);
803
- cursor: pointer;
804
- }
805
- .b-book__date span {
806
- color: var(--muted);
807
- font-size: 0.92rem;
808
- }
809
- .b-book__date[aria-pressed='true'],
810
- .b-book__time[aria-pressed='true'] {
811
- border-color: var(--gold);
812
- background: var(--gold-light);
813
- }
814
- .b-book__date:disabled {
815
- opacity: 0.5;
816
- cursor: default;
817
- }
818
- .b-book__add {
819
- margin: 0.6rem 0 0;
820
- }
821
- .b-book__find summary {
822
- cursor: pointer;
823
- color: var(--fg);
824
- text-decoration: underline;
825
- }
826
- .b-book__find-form {
827
- display: flex;
828
- flex-direction: column;
829
- gap: 0.75rem;
830
- margin-top: 0.75rem;
831
- }
832
- .b-book__find-form input {
833
- font: inherit;
834
- color: var(--fg);
835
- background: var(--field-bg, var(--bg-surface));
836
- border: var(--field-border, 1px solid var(--border));
837
- border-radius: var(--field-radius, var(--radius-sm));
838
- padding: 0.6rem 0.75rem;
839
- max-width: 20rem;
840
- }
841
- .b-book__find-said {
842
- margin: 0.5rem 0 0;
843
- color: var(--muted);
844
- }
845
- .b-book__time--which {
846
- display: flex;
847
- flex-direction: column;
848
- align-items: center;
849
- gap: 0.1rem;
850
- }
851
- .b-book__time--which span {
852
- font-size: 0.75rem;
853
- font-weight: 400;
854
- color: var(--muted);
855
- }
856
- .b-book__times:has(.b-book__time--which) {
857
- grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
858
- }
859
- .b-book__days-bar[hidden] {
860
- display: none;
861
- }
862
- .b-book__one {
863
- display: flex;
864
- flex-direction: column;
865
- gap: 0.15rem;
866
- padding: 0.85rem 1rem;
867
- border: 1px solid var(--border);
868
- border-radius: var(--radius-sm);
869
- background: var(--bg-surface);
870
- grid-column: 1 / -1;
871
- }
872
- .b-book__one span {
873
- color: var(--muted);
874
- }
875
- .b-book__panel {
876
- display: flex;
877
- flex-direction: column;
878
- gap: 1rem;
879
- }
880
- .b-book__panel[hidden] {
881
- display: none;
882
- }
883
- .b-book__offers {
884
- display: grid;
885
- grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
886
- gap: 0.5rem;
887
- }
888
- .b-book__offer {
889
- display: flex;
890
- flex-direction: column;
891
- align-items: flex-start;
892
- gap: 0.15rem;
893
- padding: 0.75rem 0.9rem;
894
- font: inherit;
895
- text-align: start;
896
- color: var(--fg);
897
- background: var(--bg-surface);
898
- border: 1px solid var(--border);
899
- border-radius: var(--radius-sm);
900
- cursor: pointer;
901
- transition: border-color 0.15s ease, background 0.15s ease;
902
- }
903
- .b-book__offer span {
904
- color: var(--muted);
905
- font-size: 0.92rem;
906
- }
907
- .b-book__offer:hover {
908
- border-color: var(--gold);
909
- }
910
- .b-book__offer[aria-pressed='true'] {
911
- border-color: var(--gold);
912
- background: var(--gold-light);
913
- }
914
- .b-book__offer:focus-visible {
915
- outline: 2px solid var(--gold);
916
- outline-offset: 2px;
917
- }
918
- .b-book__add a {
919
- color: var(--fg);
920
- font-weight: 600;
921
- }
922
- .b-book__more[hidden],
923
- .b-book__days[hidden] {
924
- display: none;
925
- }
926
- </style>
1
+ ---
2
+ /**
3
+ * Book — visitors book one of the organisation's offers, from the Ferst Events and bookings module.
4
+ * One block, shaped by the offer (0.13.0; myai4-webdev docs/EVENTS.md slice 6c, the maintainer
5
+ * 2026-11-23: "a tile that introduces what we are booking … where … and the calendar below it, all
6
+ * in one block"). The head says what it is, how long, with whom or where, and the price; below it
7
+ * is the way to book that offer, as the platform says (`mode`):
8
+ * - times: a day, then a time of its length (a haircut);
9
+ * - chosen: a day, a start, then an end, the price worked out as they choose (hall hire);
10
+ * - places: the coming dates with the places left, then how many (a class, a concert); `event`
11
+ * names one event of the offer (the Christmas concert) to show only its dates.
12
+ * What's picked is held for the visitor at once, for 10 minutes, while they give their details; then
13
+ * it's booked, emailed with an invitation, and the page offers "Add to calendar".
14
+ *
15
+ * The offer's name, length, price and who gives it are read from the platform at build time
16
+ * (lib/book); its free times and places in the browser, since they change by the minute. Needs
17
+ * JavaScript: choosing among live times can't be a plain form. Without it, the block says so.
18
+ *
19
+ * Or a person or a place (0.14.0; the maintainer 2026-11-24: "we need both and its up to the person
20
+ * configuring the module to pick what is suitable"). `resource` alone: the head introduces them (Sam,
21
+ * the Hall), then the offers they provide online as choices, and below, the chosen one's calendar,
22
+ * booked with them only. `service` and `resource`: that offer, with them only.
23
+ *
24
+ * Shown outside a site (the Ferst portal's preview, the maintainer 2026-11-24: "utilise the core
25
+ * ferst events and bookings module block as it would be applied … to visualise it before someone
26
+ * clicks 'add it to my site'"): the host says which site and platform through `Astro.locals.ferstBook`,
27
+ * and `demo` plays every step with the real free times but never holds or books anything.
28
+ */
29
+ import ContactForm from './ContactForm.astro';
30
+ import BookMonth from '../islands/BookMonth.tsx';
31
+ import Heading from '../blocks/Heading.astro';
32
+ import { bookTarget, eventsData, ldJson, loadBookResource, loadBookService, loadEventDates, metaLine, whereText, type BookService, type BookWho, type EventsContext } from '../../lib/book';
33
+ import { resolveGitBase, resolveSiteId } from '../../lib/git-base.mjs';
34
+ import { canonicalUrl } from '../../lib/seo.mjs';
35
+ import { loadSiteSettings } from '../../lib/siteSettings';
36
+
37
+ interface Props {
38
+ service?: string;
39
+ resource?: string;
40
+ event?: string;
41
+ /** `button`: "Book now" for one date of a class or an event (its next with places, or `date`).
42
+ * `calendar` (#239, a trial): an offer booked by time shows a month, its free days marked, and the
43
+ * chosen day's times beside it (under it on a phone). Other ways of booking keep their own look. */
44
+ look?: 'button' | 'calendar';
45
+ date?: string;
46
+ /** Dates across chosen classes and events, as one list: each an offer booked by places, or one event of it. */
47
+ list?: Array<{ service: string; event?: string }>;
48
+ title?: string;
49
+ intro?: string;
50
+ note?: string;
51
+ buttonLabel?: string;
52
+ }
53
+ const { event, title, intro, note, buttonLabel = 'Book', look, date } = Astro.props;
54
+ const list = Astro.props.list?.length ? Astro.props.list : null;
55
+ const target = list ? { service: null, resource: null } : bookTarget(Astro.props);
56
+ const host = (Astro.locals as { ferstBook?: { siteId?: string; platform?: string; demo?: boolean } } | undefined)?.ferstBook;
57
+ const base = host?.platform ?? resolveGitBase();
58
+ const siteId = host?.siteId ?? resolveSiteId();
59
+ const demo = !!host?.demo;
60
+ let who: BookWho | null = null;
61
+ let offers: BookService[];
62
+ if (list) {
63
+ // A custom list (the maintainer, 2026-11-24): the dates of each, as one list.
64
+ offers = await Promise.all(list.map((l) => loadBookService(l.service, { base, siteId, event: l.event ?? null })));
65
+ const timed = offers.find((o) => o.mode !== 'places');
66
+ if (timed) throw new Error(`Book block: a list is of classes and events, booked by places; "${timed.name}" is booked by time. Give it a block of its own, or run \`npx ferst-modules\` to list what's booked by places.`);
67
+ } else if (target.service) {
68
+ offers = [await loadBookService(target.service, { base, siteId, event: event ?? null, resource: target.resource })];
69
+ } else {
70
+ const got = await loadBookResource(target.resource!, { base, siteId });
71
+ who = got.resource;
72
+ offers = got.services;
73
+ }
74
+ const lead = offers[0];
75
+ // "Book now" (the maintainer's fourth way, 2026-11-24): one date of a class or an event, nothing to pick
76
+ // but how many places. A haircut or a hire becomes one date only when it's booked, so it has no button.
77
+ const one = look === 'button';
78
+ // The month (myai4-webdev #239): booking as people book everywhere. A month grid, its free days marked,
79
+ // that day's times beside it: a React island (React Aria), loaded only on a page that shows one (§8).
80
+ const calendar = look === 'calendar';
81
+ if (one && (who || lead.mode !== 'places')) {
82
+ throw new Error(`Book block: a "Book now" button is for a class or an event, booked by places; "${lead.name}" is booked by time. Leave out "look" to show its calendar, or run \`npx ferst-modules\` to list what's booked by places.`);
83
+ }
84
+ const anchor = `book-${who ? who.id : `${lead.id}${lead.event ? `-${lead.event}` : ''}${lead.resource ? `-${lead.resource}` : ''}`}`;
85
+ const { align: blockAlign, headingAlign } = Astro.props as { align?: 'start' | 'center' | 'end'; headingAlign?: 'start' | 'center' | 'end' };
86
+ const headAlign = headingAlign ?? blockAlign ?? 'center';
87
+ // The head: the offer (its length, with whom or where, its price), or the person or place it names.
88
+ const heading = title ?? (list ? 'Coming up' : who ? who.name : lead.name);
89
+ const meta = list ? '' : who ? (offers.length === 1 ? metaLine({ ...lead, resources: [] }) : '') : metaLine(lead);
90
+ const lines = intro ?? (list ? '' : who ? who.description : lead.description);
91
+ const many = !list && offers.length > 1;
92
+ const panels = list ? [lead] : offers;
93
+ const sources = list ? JSON.stringify(offers.map((o) => ({ book: o.definition, event: o.event ?? '' }))) : undefined;
94
+ const placeOf = (d: BookService) => d.resources.find((r) => r.kind === 'place')?.name ?? '';
95
+
96
+ // For search engines (0.15.0; myai4-webdev docs/EVENTS.md slice 6d): each coming date of a class or an
97
+ // event as a schema.org Event, once the site has an address (as all its structured data, Base.astro).
98
+ // Read at build, and brought up to date as the page loads. A preview (no site address) has none.
99
+ const siteUrl = (import.meta.env.FERST_SITE_URL as string | undefined) || '';
100
+ let ldContext: EventsContext | null = null;
101
+ if (siteUrl) {
102
+ const settings = await loadSiteSettings().catch(() => null);
103
+ ldContext = {
104
+ url: `${canonicalUrl(siteUrl, Astro.url?.pathname ?? '/')}#${anchor}`,
105
+ organisation: { name: settings?.identity?.siteTitle, url: `${siteUrl.replace(/\/+$/, '')}/` },
106
+ places: (settings?.places ?? []) as EventsContext['places'],
107
+ };
108
+ }
109
+ const ldOf = async (def: BookService): Promise<string | null> => {
110
+ if (!ldContext || def.mode !== 'places') return null;
111
+ const dates = list
112
+ ? (await Promise.all(offers.map((o) => loadEventDates(o.definition, { event: o.event })))).flat().sort((a, b) => a.start.localeCompare(b.start))
113
+ : await loadEventDates(def.definition, { event: def.event, resource: def.resource });
114
+ const data = eventsData(dates, ldContext);
115
+ return data ? ldJson(data) : null;
116
+ };
117
+ const lds = await Promise.all(panels.map(ldOf));
118
+ ---
119
+
120
+ <section class:list={['b-book', calendar && 'b-book--calendar']} id={anchor} data-book-block data-demo={demo ? '1' : undefined} data-find={`${base}/sites/${encodeURIComponent(siteId ?? '')}/book/find`}>
121
+ {demo && <p class="b-book__notice" data-book-demo>A preview: try it as a visitor would. The free times are real; nothing is held or booked.</p>}
122
+ <div class="b-book__head" data-recipe-head data-content-align={headAlign}>
123
+ <Heading text={heading} level={2} />
124
+ {meta && <p class="b-book__meta" data-book-meta>{meta}</p>}
125
+ {lines && <p class="b-book__intro">{lines}</p>}
126
+ </div>
127
+
128
+ <noscript><p class="b-book__notice">Booking needs JavaScript switched on in your browser.</p></noscript>
129
+
130
+ {many && (
131
+ <div class="b-book__offers" role="group" aria-label="What would you like to book?" data-book-offers>
132
+ {offers.map((d, i) => (
133
+ <button type="button" class="b-book__offer" data-book-offer={d.id} aria-pressed={String(i === 0)}>
134
+ <strong>{d.name}</strong>
135
+ <span>{metaLine({ ...d, resources: [] })}</span>
136
+ </button>
137
+ ))}
138
+ </div>
139
+ )}
140
+
141
+ {panels.map((def, i) => {
142
+ const where = placeOf(def);
143
+ const picksWho = def.mode !== 'places' && def.resources.length > 1;
144
+ const cal = calendar && def.mode === 'times';
145
+ return (
146
+ <div class="b-book__panel" data-book={def.definition} data-holds={def.holds} data-name={def.name} data-label={buttonLabel} data-offer={def.id}
147
+ data-mode={def.mode} data-event={list ? '' : def.event ?? ''} data-resource={def.resource ?? ''} data-minutes={def.minutes} data-step={def.step} data-where={list ? '' : where}
148
+ data-list={sources}
149
+ data-look={one ? 'button' : undefined} data-date={one ? date ?? '' : undefined}
150
+ data-with={whereText(def.resources)} data-cal={cal ? '1' : undefined} hidden={i > 0}>
151
+ {lds[i] && <script type="application/ld+json" is:inline data-book-ld data-ctx={JSON.stringify(ldContext)} set:html={lds[i]} />}
152
+ {many && def.description && <p class="b-book__intro">{def.description}</p>}
153
+ <div class="b-book__notice" role="alert" data-book-error hidden></div>
154
+
155
+ {/* Step 1: what to book */}
156
+ <div class="b-book__pick" data-book-pick hidden>
157
+ {picksWho && (
158
+ <label class="b-book__who">
159
+ <span>{def.resources.every((r) => r.kind === 'place') ? 'Where' : 'Who with'}</span>
160
+ <select data-book-who>
161
+ <option value="">{def.resources.every((r) => r.kind === 'place') ? 'Anywhere free' : 'Anyone available'}</option>
162
+ {def.resources.map((r) => <option value={r.id}>{r.name}</option>)}
163
+ </select>
164
+ </label>
165
+ )}
166
+ {cal ? (
167
+ <div class="b-book__cal" data-book-cal>
168
+ {/* A month: arrows for earlier and later months; a day with free times can be chosen, the rest can't. */}
169
+ {/* Nothing to draw at build: the month is the visitor's today and live free times. */}
170
+ <div class="b-book__month" data-book-month><BookMonth client:only="react" /></div>
171
+ <div class="b-book__on-day">
172
+ <h3 class="b-book__day-title" data-book-day-title></h3>
173
+ <div class="b-book__times" role="group" aria-label="Choose a time" data-book-times aria-live="polite">
174
+ <p class="b-book__empty">Loading free times…</p>
175
+ </div>
176
+ </div>
177
+ </div>
178
+ ) : (
179
+ <>
180
+ <div class="b-book__days-bar" hidden={one}>
181
+ <button type="button" class="b-book__nav" data-book-earlier aria-label="Earlier dates" disabled>‹</button>
182
+ <div class="b-book__days" role="group" aria-label="Choose a day" data-book-days></div>
183
+ <button type="button" class="b-book__nav" data-book-later aria-label="Later dates">›</button>
184
+ </div>
185
+ <div class="b-book__times" role="group" aria-label={def.mode === 'places' ? 'Choose a date' : def.mode === 'chosen' ? 'Choose when it starts' : 'Choose a time'} data-book-times aria-live="polite">
186
+ <p class="b-book__empty">{def.mode === 'places' ? 'Loading dates…' : 'Loading free times…'}</p>
187
+ </div>
188
+ </>
189
+ )}
190
+ {def.mode === 'chosen' && (
191
+ <div class="b-book__more" data-book-end hidden>
192
+ <label class="b-book__who"><span>Until</span><select data-book-end-select></select></label>
193
+ <p class="b-book__quote" data-book-quote aria-live="polite"></p>
194
+ <button type="button" class="b-book__go" data-book-hold>Hold this time</button>
195
+ </div>
196
+ )}
197
+ {def.mode === 'places' && (
198
+ <div class="b-book__more" data-book-places hidden>
199
+ <p class="b-book__chosen" data-book-chosen></p>
200
+ <label class="b-book__who"><span>How many places</span><input type="number" min="1" value="1" inputmode="numeric" data-book-count /></label>
201
+ <p class="b-book__quote" data-book-quote aria-live="polite"></p>
202
+ <button type="button" class="b-book__go" data-book-hold>{one ? 'Book now' : 'Hold these places'}</button>
203
+ </div>
204
+ )}
205
+ </div>
206
+
207
+ {/* Step 2: who they are */}
208
+ <div class="b-book__details" data-book-details hidden>
209
+ <p class="b-book__held" data-book-held></p>
210
+ <ContactForm
211
+ action={def.holds}
212
+ method="post"
213
+ submitLabel={buttonLabel}
214
+ note={note ?? 'We’ll email you the booking, with an invitation for your calendar.'}
215
+ fields={[
216
+ { name: 'name', label: 'Your name', type: 'text', required: true },
217
+ { name: 'email', label: 'Your email', type: 'email', required: true },
218
+ { name: 'phone', label: 'Your phone (optional)', type: 'tel' },
219
+ { name: 'notes', label: 'Anything we should know? (optional)', type: 'textarea' },
220
+ ]}
221
+ honeypot
222
+ idPrefix={many ? `${anchor}-${def.id}` : anchor}
223
+ />
224
+ <button type="button" class="b-book__link" data-book-again>{def.mode === 'places' ? 'Choose another date' : 'Choose another time'}</button>
225
+ </div>
226
+
227
+ {/* Step 3: booked, and "Add to calendar" */}
228
+ <div class="b-book__notice b-book__notice--done" role="status" data-book-done hidden></div>
229
+ </div>
230
+ );
231
+ })}
232
+
233
+ {/* Their own bookings: the links, emailed to the address they booked with (2026-11-24). */}
234
+ <details class="b-book__find" data-book-find>
235
+ <summary>Change or cancel a booking</summary>
236
+ <form class="b-book__find-form" data-book-find-form>
237
+ <label class="b-book__who"><span>The email you booked with</span><input type="email" name="email" required autocomplete="email" id={`${anchor}-find-email`} /></label>
238
+ <button type="submit" class="b-book__go">Email me my bookings</button>
239
+ </form>
240
+ <p class="b-book__find-said" role="status" data-book-find-said></p>
241
+ </details>
242
+ </section>
243
+
244
+ <script>
245
+ import { addDays, bookingMessage, calendarFile, dayChip, dayTitle, endChoices, eventsData, freeDays, googleCalendarLink, londonDay, monthOf, monthTitle, monthWindow, shiftMonth, whenText, whichFree, type EventDate, type EventsContext, type TimesAnswer } from '../../lib/book';
246
+
247
+ import type { MonthState } from '../islands/BookMonth';
248
+
249
+ /** Where the month island lives: what it shows is kept here, and it says what the visitor chose. */
250
+ type MonthHost = HTMLElement & { bookMonth?: MonthState };
251
+
252
+ const SPAN = 14; // days shown at once (dates for a class: four weeks)
253
+ const AHEAD = 60; // how far ahead the platform takes bookings
254
+
255
+ type Hold = { id: string; start: string; end: string; places?: number; title?: string; resource: { name: string }; price: { label: string; note?: string | null } | null };
256
+
257
+ /** One offer's way to book, in its panel. Returns how to start it (once shown) and to leave it. */
258
+ function setUp(block: HTMLElement) {
259
+ const src = block.dataset.book!;
260
+ const holds = block.dataset.holds!;
261
+ const mode = (block.dataset.mode ?? 'times') as 'times' | 'chosen' | 'places';
262
+ const onlyEvent = block.dataset.event || '';
263
+ const onlyWith = block.dataset.resource || ''; // the person or place the block names: booked with them only
264
+ const demo = !!block.closest('[data-book-block]')?.hasAttribute('data-demo'); // a preview: nothing is held or booked
265
+ const minutes = Number(block.dataset.minutes ?? '30');
266
+ const step = Number(block.dataset.step ?? '30');
267
+ const where = block.dataset.where ?? '';
268
+ const one = block.dataset.look === 'button'; // "Book now": one date, only how many places left to choose
269
+ // A custom list: each source's dates, as one list; each date booked through its own offer.
270
+ const sources = block.dataset.list ? (JSON.parse(block.dataset.list) as Array<{ book: string; event: string }>) : null;
271
+ const srcOf = (d: EventDate | null) => (d as (EventDate & { src?: string }) | null)?.src ?? src;
272
+ const pinned = block.dataset.date || '';
273
+ const span = one ? 31 : mode === 'places' ? SPAN * 2 : SPAN;
274
+ const $ = <T extends HTMLElement>(sel: string) => block.querySelector<T>(sel)!;
275
+ const pick = $('[data-book-pick]');
276
+ const details = $('[data-book-details]');
277
+ const done = $('[data-book-done]');
278
+ const error = $('[data-book-error]');
279
+ const daysEl = block.querySelector<HTMLElement>('[data-book-days]');
280
+ const timesEl = $('[data-book-times]');
281
+ const earlier = block.querySelector<HTMLButtonElement>('[data-book-earlier]');
282
+ const later = block.querySelector<HTMLButtonElement>('[data-book-later]');
283
+ // The month (look: calendar): the month shown, and the day's name over its times.
284
+ const monthEl = block.querySelector<MonthHost>('[data-book-month]');
285
+ const dayTitleEl = block.querySelector<HTMLElement>('[data-book-day-title]');
286
+ const who = block.querySelector<HTMLSelectElement>('[data-book-who]');
287
+ const more = block.querySelector<HTMLElement>('[data-book-end], [data-book-places]');
288
+ const endSel = block.querySelector<HTMLSelectElement>('[data-book-end-select]');
289
+ const count = block.querySelector<HTMLInputElement>('[data-book-count]');
290
+ const quoteEl = block.querySelector<HTMLElement>('[data-book-quote]');
291
+ const holdBtn = block.querySelector<HTMLButtonElement>('[data-book-hold]');
292
+ const chosenEl = block.querySelector<HTMLElement>('[data-book-chosen]');
293
+ const form = details.querySelector<HTMLFormElement>('form')!;
294
+ const submit = form.querySelector<HTMLButtonElement>('button[type="submit"]');
295
+
296
+ const today = londonDay();
297
+ let from = today;
298
+ let answer: TimesAnswer | null = null;
299
+ let day: string | null = null;
300
+ let start: string | null = null; // chosen: the start picked (HH:MM)
301
+ let date: EventDate | null = null; // places: the date picked
302
+ let hold: Hold | null = null;
303
+ let month = monthOf(today);
304
+ let asked = 0; // each read of a month's free times, so only the latest is drawn
305
+ let lookedOn = false; // a first month with nothing free looks on to the next, once
306
+
307
+ const say = (text: string | null) => { error.textContent = text ?? ''; error.hidden = !text; };
308
+ const show = (stepName: 'pick' | 'details' | 'done') => { pick.hidden = stepName !== 'pick'; details.hidden = stepName !== 'details'; done.hidden = stepName !== 'done'; };
309
+ const free = (d: string) => (answer?.days.find((x) => x.day === d)?.times ?? []).filter((t) => !who?.value || t.resources.includes(who.value));
310
+ const button = (cls: string, text: string, onClick: () => void, disabled = false) => {
311
+ const b = document.createElement('button');
312
+ b.type = 'button'; b.className = cls; b.textContent = text; b.disabled = disabled;
313
+ b.addEventListener('click', onClick);
314
+ return b;
315
+ };
316
+
317
+ // ── The days (times and chosen) ────────────────────────────────────────────
318
+ /** The month: a day with free times is marked and can be chosen; the rest can't. */
319
+ function drawMonth() {
320
+ const on = new Set(answer ? freeDays(answer.days, who?.value) : []);
321
+ monthEl!.bookMonth = { today, max: addDays(today, AHEAD), month, free: [...on], value: day };
322
+ monthEl!.dispatchEvent(new CustomEvent('book:month-state'));
323
+ }
324
+
325
+ function drawDays() {
326
+ if (monthEl) return drawMonth();
327
+ if (!daysEl || !earlier || !later) return;
328
+ daysEl.hidden = mode === 'places';
329
+ if (mode !== 'places') {
330
+ daysEl.replaceChildren(...(answer?.days ?? []).map((d) => {
331
+ const chip = dayChip(d.day);
332
+ const b = document.createElement('button');
333
+ b.type = 'button';
334
+ b.className = 'b-book__day';
335
+ b.disabled = free(d.day).length === 0;
336
+ b.setAttribute('aria-pressed', String(d.day === day));
337
+ b.innerHTML = `<span>${chip.weekday}</span><strong>${chip.date}</strong>`;
338
+ b.setAttribute('aria-label', `${chip.weekday} ${chip.date}${b.disabled ? ', nothing free' : ''}`);
339
+ b.addEventListener('click', () => { day = d.day; start = null; drawDays(); drawTimes(); });
340
+ return b;
341
+ }));
342
+ }
343
+ earlier.disabled = from <= today;
344
+ later.disabled = addDays(from, span) > addDays(today, AHEAD);
345
+ }
346
+
347
+ function drawTimes() {
348
+ if (more) more.hidden = true;
349
+ if (mode === 'places') return drawDates();
350
+ const times = day ? free(day) : [];
351
+ if (dayTitleEl) dayTitleEl.textContent = day ? dayTitle(day) : '';
352
+ if (!day && monthEl) { timesEl.innerHTML = `<p class="b-book__empty">${answer?.days.some((d) => free(d.day).length) ? 'Choose a day.' : `Nothing free in ${monthTitle(month)}. Try the next month.`}</p>`; return; }
353
+ if (!day) { timesEl.innerHTML = `<p class="b-book__empty">${answer?.days.some((d) => free(d.day).length) ? 'Choose a day.' : 'Nothing free in these dates. Try later dates.'}</p>`; return; }
354
+ if (!times.length) { timesEl.innerHTML = '<p class="b-book__empty">Nothing free that day.</p>'; return; }
355
+ // Several places, "Anywhere free" (the maintainer's second way, 2026-11-24: "hall hire showing any
356
+ // hall available"): each time says which are free then.
357
+ const places = answer?.resources ?? [];
358
+ timesEl.replaceChildren(...times.map((t) => {
359
+ const b = button('b-book__time', t.time, () => (mode === 'chosen' ? chooseStart(t.time) : void take({ start: t.start })));
360
+ const which = who?.value ? null : whichFree(t.resources, places);
361
+ if (which) {
362
+ b.innerHTML = '<strong></strong><span></span>';
363
+ b.querySelector('strong')!.textContent = t.time;
364
+ b.querySelector('span')!.textContent = which;
365
+ b.setAttribute('aria-label', `${t.time}, free: ${which}`);
366
+ b.classList.add('b-book__time--which');
367
+ }
368
+ if (mode === 'chosen') b.setAttribute('aria-pressed', String(t.time === start));
369
+ return b;
370
+ }));
371
+ }
372
+
373
+ // ── Hall hire: a start, then an end, and what it comes to ─────────────────
374
+ function chooseStart(time: string) {
375
+ start = time;
376
+ drawTimes();
377
+ const ends = endChoices(free(day!).map((t) => t.time), time, minutes, step);
378
+ endSel!.replaceChildren(...ends.map((e) => { const o = document.createElement('option'); o.value = e; o.textContent = e === '24:00' ? 'midnight' : e; return o; }));
379
+ more!.hidden = !ends.length;
380
+ void quote();
381
+ }
382
+
383
+ // ── A class or a concert: its coming dates, then how many places ──────────
384
+ function drawDates() {
385
+ const dates = answer?.events ?? [];
386
+ if (one) {
387
+ const d = dates.find((x) => (pinned ? x.start === pinned : x.left > 0));
388
+ if (!d || d.left === 0) { timesEl.innerHTML = `<p class="b-book__empty">${d ? 'It’s full.' : 'No dates with places just now.'}</p>`; return; }
389
+ const card = document.createElement('div');
390
+ card.className = 'b-book__one';
391
+ card.innerHTML = '<strong></strong><span></span>';
392
+ card.querySelector('strong')!.textContent = d.title;
393
+ card.querySelector('span')!.textContent = `${whenText(d.start)}${where ? `, at ${where}` : ''} · ${d.left} ${d.left === 1 ? 'place' : 'places'} left · ${d.price}`;
394
+ timesEl.replaceChildren(card);
395
+ date = d;
396
+ chosenEl!.textContent = '';
397
+ count!.max = String(d.left);
398
+ if (Number(count!.value) > d.left) count!.value = String(d.left);
399
+ more!.hidden = false;
400
+ void quote();
401
+ return;
402
+ }
403
+ if (!dates.length) { timesEl.innerHTML = `<p class="b-book__empty">${onlyEvent ? 'No dates to book in these weeks.' : 'Nothing to book in these weeks. Try later dates.'}</p>`; return; }
404
+ timesEl.replaceChildren(...dates.map((d) => {
405
+ const chip = dayChip(d.start.slice(0, 10));
406
+ const left = d.left === 0 ? 'Full' : `${d.left} ${d.left === 1 ? 'place' : 'places'} left`;
407
+ const b = button('b-book__date', '', () => chooseDate(d), d.left === 0);
408
+ b.innerHTML = `<strong>${chip.weekday} ${chip.date}, ${d.start.slice(11)}</strong><span>${onlyEvent ? '' : `${d.title} · `}${left} · ${d.price}</span>`;
409
+ b.setAttribute('aria-pressed', String(date?.event_id === d.event_id && date?.start === d.start));
410
+ return b;
411
+ }));
412
+ }
413
+ function chooseDate(d: EventDate) {
414
+ date = d;
415
+ drawDates();
416
+ chosenEl!.textContent = `${d.title}, ${whenText(d.start)}${where ? `, at ${where}` : ''}.`;
417
+ count!.max = String(d.left);
418
+ if (Number(count!.value) > d.left) count!.value = String(d.left);
419
+ more!.hidden = false;
420
+ void quote();
421
+ }
422
+
423
+ /** What it comes to, from the platform, as they choose. */
424
+ async function quote() {
425
+ if (!quoteEl) return;
426
+ quoteEl.textContent = '';
427
+ let q = '';
428
+ if (mode === 'chosen' && day && start && endSel?.value) {
429
+ const end = endSel.value === '24:00' ? `${addDays(day, 1)}T00:00` : `${day}T${endSel.value}`;
430
+ q = `start=${day}T${start}&end=${end}`;
431
+ } else if (mode === 'places' && date) {
432
+ q = `start=${date.start}&end=${date.end}&places=${Math.max(1, Number(count!.value) || 1)}&event=${encodeURIComponent(date.event_id)}`;
433
+ }
434
+ if (!q) return;
435
+ const res = await fetch(`${srcOf(date)}/quote?${q}`, { headers: { Accept: 'application/json' } }).catch(() => null);
436
+ const body = res?.ok ? await res.json().catch(() => null) : null;
437
+ if (!body) return;
438
+ quoteEl.textContent = body.price ? `${body.price.label} · ${body.price.lines.join('; ')} · paid on the day` : 'Free';
439
+ if (holdBtn && mode === 'places' && !one) { const n = Math.max(1, Number(count!.value) || 1); holdBtn.textContent = `Hold ${n === 1 ? 'this place' : `${n} places`}`; }
440
+ }
441
+
442
+ /** The page's dates for search engines, brought up to date (the places left) from what's just been read. */
443
+ function freshForSearch() {
444
+ const ld = block.querySelector<HTMLScriptElement>('script[data-book-ld]');
445
+ if (!ld || !answer || from !== today) return;
446
+ const data = eventsData(answer.events ?? [], JSON.parse(ld.dataset.ctx ?? '{}') as EventsContext);
447
+ if (data) ld.textContent = JSON.stringify(data);
448
+ else ld.remove();
449
+ }
450
+
451
+ async function load() {
452
+ say(null);
453
+ timesEl.innerHTML = `<p class="b-book__empty">${mode === 'places' ? 'Loading dates…' : 'Loading free times…'}</p>`;
454
+ try {
455
+ if (sources) {
456
+ const all = await Promise.all(sources.map(async (s) => {
457
+ const r = await fetch(`${s.book}?from=${from}&to=${addDays(from, span)}${s.event ? `&event=${encodeURIComponent(s.event)}` : ''}`, { headers: { Accept: 'application/json' } });
458
+ if (!r.ok) { const b = await r.json().catch(() => ({})); throw new Error(b.error ?? String(r.status)); }
459
+ return ((await r.json()) as TimesAnswer).events?.map((e) => ({ ...e, src: s.book })) ?? [];
460
+ }));
461
+ answer = { service: { id: '', name: block.dataset.name ?? '', minutes }, resources: [], days: [], events: all.flat().sort((a, b) => a.start.localeCompare(b.start)) };
462
+ start = null; date = null;
463
+ drawDays(); drawTimes(); freshForSearch();
464
+ return;
465
+ }
466
+ if (monthEl) return await loadMonth();
467
+ const res = await fetch(`${src}?from=${from}&to=${addDays(from, span)}${onlyEvent ? `&event=${encodeURIComponent(onlyEvent)}` : ''}${onlyWith ? `&resource=${encodeURIComponent(onlyWith)}` : ''}`, { headers: { Accept: 'application/json' } });
468
+ if (!res.ok) { const b = await res.json().catch(() => ({})); throw new Error(b.error ?? String(res.status)); }
469
+ answer = (await res.json()) as TimesAnswer;
470
+ day = answer.days.find((d) => free(d.day).length)?.day ?? null;
471
+ start = null; date = null;
472
+ drawDays(); drawTimes(); freshForSearch();
473
+ } catch (e) {
474
+ timesEl.innerHTML = '';
475
+ say(bookingMessage(e instanceof Error ? e.message : ''));
476
+ }
477
+ }
478
+
479
+ /** The month's free times (from today, up to the last day bookings are taken). */
480
+ async function loadMonth(): Promise<void> {
481
+ const mine = ++asked;
482
+ const busy = timesEl.closest('[data-book-cal]');
483
+ const win = monthWindow(month, today, AHEAD);
484
+ busy?.setAttribute('aria-busy', 'true');
485
+ let read: TimesAnswer = { service: { id: '', name: '', minutes }, resources: [], days: [] };
486
+ if (win) {
487
+ const res = await fetch(`${src}?from=${win.from}&to=${win.to}${onlyWith ? `&resource=${encodeURIComponent(onlyWith)}` : ''}`, { headers: { Accept: 'application/json' } });
488
+ if (!res.ok) { const b = await res.json().catch(() => ({})); throw new Error(b.error ?? String(res.status)); }
489
+ read = (await res.json()) as TimesAnswer;
490
+ }
491
+ if (mine !== asked) return; // a later month was asked for meanwhile
492
+ busy?.removeAttribute('aria-busy');
493
+ answer = read;
494
+ // Nothing free in the first month shown: look on to the next, once, as a visitor would.
495
+ if (!lookedOn && !freeDays(read.days, who?.value).length && monthWindow(shiftMonth(month, 1), today, AHEAD)) {
496
+ lookedOn = true;
497
+ month = shiftMonth(month, 1);
498
+ drawMonth();
499
+ return loadMonth();
500
+ }
501
+ lookedOn = true;
502
+ const keep = day && monthOf(day) === month && free(day).length ? day : null;
503
+ day = keep ?? answer.days.find((d) => free(d.day).length)?.day ?? null;
504
+ start = null; date = null;
505
+ drawDays(); drawTimes();
506
+ }
507
+ monthEl?.addEventListener('book:day', (e) => { day = (e as CustomEvent<string>).detail; start = null; drawDays(); drawTimes(); });
508
+ // Earlier or later months, by the arrows or the keyboard: read that month's free times.
509
+ monthEl?.addEventListener('book:month', (e) => {
510
+ const m = (e as CustomEvent<string>).detail;
511
+ if (m !== month) { month = m; drawMonth(); void load(); }
512
+ });
513
+
514
+ /** A preview's hold: what a visitor would see held, with nothing sent. */
515
+ function pretend(body: Record<string, unknown>) {
516
+ const start = String(body.start);
517
+ const plus = (local: string, m: number) => { const t = Number(local.slice(11, 13)) * 60 + Number(local.slice(14, 16)) + m; return `${local.slice(0, 11)}${String(Math.floor(t / 60) % 24).padStart(2, '0')}:${String(t % 60).padStart(2, '0')}`; };
518
+ hold = { id: '', start, end: typeof body.end === 'string' ? body.end : date ? date.end : plus(start, minutes), places: typeof body.places === 'number' ? body.places : undefined, title: date?.title, resource: { name: '' }, price: null };
519
+ const h = hold;
520
+ const what = h.places ? `${h.title ?? block.dataset.name}, ${whenText(h.start)}, ${h.places} ${h.places === 1 ? 'place' : 'places'}` : `${whenText(h.start)} to ${h.end.slice(11)}`;
521
+ $('[data-book-held]').textContent = `${what}. On your website, this is kept for the visitor for 10 minutes while they give their details. In this preview, nothing is kept.`;
522
+ show('details');
523
+ }
524
+
525
+ /** Hold what was picked: a time (and an end), or places at a date. */
526
+ async function take(body: Record<string, unknown>) {
527
+ say(null);
528
+ if (demo) { pretend(body); return; }
529
+ const res = await fetch(`${mode === 'places' ? srcOf(date) : src}/hold`, {
530
+ method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
531
+ body: JSON.stringify({ ...body, ...(who?.value || onlyWith ? { resource_id: who?.value || onlyWith } : {}) }),
532
+ }).catch(() => null);
533
+ const answerBody = res ? await res.json().catch(() => ({})) : {};
534
+ if (!res || res.status !== 201) { say(bookingMessage(answerBody.error ?? '')); await load(); return; }
535
+ hold = answerBody.hold as Hold;
536
+ const h = hold;
537
+ const what = h.places ? `${h.title ?? block.dataset.name}, ${whenText(h.start)}, ${h.places} ${h.places === 1 ? 'place' : 'places'}` : `${whenText(h.start)} to ${h.end.slice(11)}, ${h.resource.name ? `${where ? 'at' : 'with'} ${h.resource.name}` : ''}`;
538
+ const price = h.price ? ` ${h.price.label}, paid on the day.` : '';
539
+ $('[data-book-held]').textContent = `${what}.${price} We’re keeping this for you for 10 minutes while you give your details.`;
540
+ show('details');
541
+ form.querySelector<HTMLInputElement>('input[name="name"]')?.focus();
542
+ }
543
+
544
+ holdBtn?.addEventListener('click', () => {
545
+ if (mode === 'chosen' && day && start && endSel?.value) {
546
+ void take({ start: `${day}T${start}`, end: endSel.value === '24:00' ? `${addDays(day, 1)}T00:00` : `${day}T${endSel.value}` });
547
+ } else if (mode === 'places' && date) {
548
+ void take({ event_id: date.event_id, start: date.start, places: Math.max(1, Number(count!.value) || 1) });
549
+ }
550
+ });
551
+ endSel?.addEventListener('change', () => void quote());
552
+ count?.addEventListener('input', () => void quote());
553
+
554
+ form.addEventListener('submit', async (ev) => {
555
+ ev.preventDefault();
556
+ if (!hold) return;
557
+ say(null);
558
+ if (demo) {
559
+ done.innerHTML = '';
560
+ const strong = document.createElement('strong');
561
+ strong.textContent = 'This is a preview: nothing was booked.';
562
+ done.append(strong, ' On your website, the visitor would now be booked, emailed the booking with an invitation for their calendar, and offered “Add to calendar”.');
563
+ hold = null;
564
+ show('done');
565
+ done.focus();
566
+ return;
567
+ }
568
+ const data = Object.fromEntries(new FormData(form).entries());
569
+ if (submit) submit.disabled = true;
570
+ const res = await fetch(`${holds}/${hold.id}`, {
571
+ method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify(data),
572
+ }).catch(() => null);
573
+ if (submit) submit.disabled = false;
574
+ const body = res ? await res.json().catch(() => ({})) : {};
575
+ if (!res || !res.ok) {
576
+ say(bookingMessage(body.error ?? ''));
577
+ if (body.error === 'hold_expired' || body.error === 'already_booked') { hold = null; show('pick'); await load(); }
578
+ return;
579
+ }
580
+ const b = body.booking as { id: string; status?: string; start: string; end: string; starts_at?: string; ends_at?: string; service: string; resource: string; places?: number };
581
+ done.innerHTML = '';
582
+ const strong = document.createElement('strong');
583
+ const withWhom = b.resource ? `, ${where ? 'at' : 'with'} ${b.resource}` : '';
584
+ // On request (platform 2026-11-24): asked for, its time kept, until the organisation confirms it.
585
+ if (b.status === 'requested') {
586
+ strong.textContent = `Requested: ${b.service}, ${whenText(b.start)}${b.places ? `, ${b.places} ${b.places === 1 ? 'place' : 'places'}` : ''}${withWhom}.`;
587
+ done.append(strong, ' The time is kept for you while they answer. We’ve emailed you, and you’ll get the booking, with an invitation for your calendar, once it’s confirmed.');
588
+ hold = null;
589
+ show('done');
590
+ done.focus();
591
+ return;
592
+ }
593
+ strong.textContent = `Booked: ${b.service}, ${whenText(b.start)}${b.places ? `, ${b.places} ${b.places === 1 ? 'place' : 'places'}` : ''}${withWhom}.`;
594
+ done.append(strong, ' We’ve emailed you the booking, with an invitation for your calendar.');
595
+ if (b.starts_at && b.ends_at) {
596
+ const booked = { title: `${b.service}${withWhom.replace(/^, /, ' ')}`, starts_at: b.starts_at, ends_at: b.ends_at, location: where || null, uid: b.id };
597
+ const add = document.createElement('p');
598
+ add.className = 'b-book__add';
599
+ const google = document.createElement('a');
600
+ google.href = googleCalendarLink(booked); google.target = '_blank'; google.rel = 'noopener'; google.textContent = 'Add to Google Calendar';
601
+ const file = document.createElement('a');
602
+ file.href = `data:text/calendar;charset=utf-8,${encodeURIComponent(calendarFile(booked))}`; file.download = 'booking.ics'; file.textContent = 'Add to Apple Calendar or Outlook';
603
+ add.append(google, ' · ', file);
604
+ done.append(add);
605
+ }
606
+ hold = null;
607
+ show('done');
608
+ done.focus();
609
+ });
610
+
611
+ $('[data-book-again]').addEventListener('click', async () => {
612
+ if (hold?.id) await fetch(`${holds}/${hold.id}`, { method: 'DELETE' }).catch(() => null);
613
+ hold = null;
614
+ show('pick');
615
+ await load();
616
+ });
617
+ earlier?.addEventListener('click', () => { from = addDays(from, -span) < today ? today : addDays(from, -span); void load(); });
618
+ later?.addEventListener('click', () => { from = addDays(from, span); void load(); });
619
+ who?.addEventListener('change', () => { day = answer?.days.find((d) => free(d.day).length)?.day ?? null; start = null; drawDays(); drawTimes(); });
620
+ done.tabIndex = -1;
621
+
622
+ let started = false;
623
+ return {
624
+ /** Shown: load its times the first time. */
625
+ start() { if (!started) { started = true; show('pick'); void load(); } },
626
+ /** Another offer chosen: let go of anything held here. */
627
+ async leave() {
628
+ if (hold?.id) await fetch(`${holds}/${hold.id}`, { method: 'DELETE' }).catch(() => null);
629
+ hold = null;
630
+ if (started) { show('pick'); say(null); }
631
+ },
632
+ };
633
+ }
634
+
635
+ // A block for a person or a place shows each offer they provide as a choice, and the chosen one's panel.
636
+ document.querySelectorAll<HTMLElement>('[data-book-block]').forEach((section) => {
637
+ const panels = [...section.querySelectorAll<HTMLElement>('[data-book]')].map((el) => ({ el, run: setUp(el) }));
638
+ const choices = [...section.querySelectorAll<HTMLButtonElement>('[data-book-offer]')];
639
+ const choose = (offer: string) => {
640
+ for (const p of panels) {
641
+ const on = p.el.dataset.offer === offer;
642
+ if (!on && !p.el.hidden) void p.run.leave();
643
+ p.el.hidden = !on;
644
+ if (on) p.run.start();
645
+ }
646
+ for (const c of choices) c.setAttribute('aria-pressed', String(c.dataset.bookOffer === offer));
647
+ };
648
+ for (const c of choices) c.addEventListener('click', () => choose(c.dataset.bookOffer!));
649
+ if (panels[0]) choose(panels[0].el.dataset.offer!);
650
+
651
+ // "Change or cancel a booking": the same answer whatever the address, from the platform.
652
+ const findForm = section.querySelector<HTMLFormElement>('[data-book-find-form]');
653
+ const said = section.querySelector<HTMLElement>('[data-book-find-said]');
654
+ findForm?.addEventListener('submit', async (ev) => {
655
+ ev.preventDefault();
656
+ if (!said) return;
657
+ const email = String(new FormData(findForm).get('email') ?? '').trim();
658
+ if (section.hasAttribute('data-demo')) { said.textContent = `In this preview, nothing is sent. On your website, ${email || 'they'} would be emailed a link to each of their bookings.`; return; }
659
+ said.textContent = 'One moment…';
660
+ const res = await fetch(section.dataset.find!, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify({ email }) }).catch(() => null);
661
+ const body = res ? await res.json().catch(() => ({})) : {};
662
+ said.textContent = res?.ok ? (body.message ?? 'If you have bookings with us under that address, we’ve emailed you a link to each.') : bookingMessage(body.error ?? '');
663
+ });
664
+ });
665
+ </script>
666
+
667
+ <style is:global>
668
+ .b-book {
669
+ display: flex;
670
+ flex-direction: column;
671
+ gap: 1.25rem;
672
+ max-width: 40rem;
673
+ margin-inline: auto;
674
+ padding-inline: 1rem;
675
+ }
676
+ .b-book .b-book__details .b-contact-form {
677
+ padding-inline: 0;
678
+ }
679
+ .b-book__head {
680
+ display: flex;
681
+ flex-direction: column;
682
+ gap: 0.5rem;
683
+ }
684
+ .b-book__meta {
685
+ margin: 0;
686
+ color: var(--muted);
687
+ font-weight: 600;
688
+ }
689
+ .b-book__intro {
690
+ margin: 0;
691
+ color: var(--muted);
692
+ line-height: 1.6;
693
+ }
694
+ .b-book__pick,
695
+ .b-book__details {
696
+ display: flex;
697
+ flex-direction: column;
698
+ gap: 1rem;
699
+ }
700
+ .b-book__who {
701
+ display: flex;
702
+ flex-direction: column;
703
+ gap: 0.4rem;
704
+ font-weight: 600;
705
+ color: var(--fg);
706
+ }
707
+ .b-book__who select {
708
+ font: inherit;
709
+ font-weight: 400;
710
+ color: var(--fg);
711
+ background: var(--field-bg, var(--bg-surface));
712
+ border: var(--field-border, 1px solid var(--border));
713
+ border-radius: var(--field-radius, var(--radius-sm));
714
+ padding: 0.6rem 0.75rem;
715
+ max-width: 20rem;
716
+ }
717
+ .b-book__days-bar {
718
+ display: flex;
719
+ align-items: center;
720
+ gap: 0.5rem;
721
+ }
722
+ .b-book__days {
723
+ display: flex;
724
+ gap: 0.5rem;
725
+ overflow-x: auto;
726
+ flex: 1;
727
+ padding-block: 0.25rem;
728
+ scrollbar-width: thin;
729
+ }
730
+ .b-book__day,
731
+ .b-book__time,
732
+ .b-book__nav {
733
+ font: inherit;
734
+ color: var(--fg);
735
+ background: var(--bg-surface);
736
+ border: 1px solid var(--border);
737
+ border-radius: var(--radius-sm);
738
+ cursor: pointer;
739
+ transition: border-color 0.15s ease, background 0.15s ease;
740
+ }
741
+ .b-book__day {
742
+ display: flex;
743
+ flex-direction: column;
744
+ align-items: center;
745
+ min-width: 4.25rem;
746
+ padding: 0.5rem 0.4rem;
747
+ font-size: 0.85rem;
748
+ line-height: 1.3;
749
+ }
750
+ .b-book__day strong {
751
+ font-size: 0.95rem;
752
+ }
753
+ .b-book__nav {
754
+ padding: 0.6rem 0.8rem;
755
+ font-size: 1.1rem;
756
+ }
757
+ .b-book__day[aria-pressed='true'] {
758
+ border-color: var(--gold);
759
+ background: var(--gold-light);
760
+ }
761
+ .b-book__day:disabled,
762
+ .b-book__nav:disabled {
763
+ opacity: 0.4;
764
+ cursor: default;
765
+ }
766
+ .b-book__day:not(:disabled):hover,
767
+ .b-book__time:hover,
768
+ .b-book__nav:not(:disabled):hover {
769
+ border-color: var(--gold);
770
+ }
771
+ .b-book__day:focus-visible,
772
+ .b-book__time:focus-visible,
773
+ .b-book__nav:focus-visible,
774
+ .b-book__link:focus-visible {
775
+ outline: 2px solid var(--gold);
776
+ outline-offset: 2px;
777
+ }
778
+ .b-book__times {
779
+ display: grid;
780
+ grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
781
+ gap: 0.5rem;
782
+ }
783
+ .b-book__time {
784
+ padding: 0.6rem 0.5rem;
785
+ font-variant-numeric: tabular-nums;
786
+ font-weight: 600;
787
+ }
788
+ .b-book__empty {
789
+ grid-column: 1 / -1;
790
+ margin: 0;
791
+ color: var(--muted);
792
+ }
793
+ .b-book__held {
794
+ margin: 0;
795
+ padding: 0.85rem 1rem;
796
+ border-radius: var(--radius-sm);
797
+ background: var(--bg-section);
798
+ line-height: 1.5;
799
+ }
800
+ .b-book__link {
801
+ align-self: flex-start;
802
+ padding: 0;
803
+ border: 0;
804
+ background: none;
805
+ color: var(--fg);
806
+ font: inherit;
807
+ text-decoration: underline;
808
+ cursor: pointer;
809
+ }
810
+ .b-book__notice {
811
+ padding: 0.85rem 1rem;
812
+ border: 1px solid var(--border);
813
+ border-radius: var(--radius-sm);
814
+ background: var(--bg-section);
815
+ color: var(--fg);
816
+ line-height: 1.5;
817
+ }
818
+ .b-book__notice--done {
819
+ border-color: var(--gold);
820
+ background: var(--gold-light);
821
+ }
822
+ .b-book__notice[hidden],
823
+ .b-book__pick[hidden],
824
+ .b-book__details[hidden] {
825
+ display: none;
826
+ }
827
+ .b-book__more {
828
+ display: flex;
829
+ flex-direction: column;
830
+ gap: 0.75rem;
831
+ padding: 1rem;
832
+ border: 1px solid var(--border);
833
+ border-radius: var(--radius-sm);
834
+ background: var(--bg-section);
835
+ }
836
+ .b-book__more input,
837
+ .b-book__more select {
838
+ font: inherit;
839
+ font-weight: 400;
840
+ color: var(--fg);
841
+ background: var(--field-bg, var(--bg-surface));
842
+ border: var(--field-border, 1px solid var(--border));
843
+ border-radius: var(--field-radius, var(--radius-sm));
844
+ padding: 0.6rem 0.75rem;
845
+ max-width: 12rem;
846
+ }
847
+ .b-book__quote,
848
+ .b-book__chosen {
849
+ margin: 0;
850
+ font-weight: 600;
851
+ font-variant-numeric: tabular-nums;
852
+ }
853
+ .b-book__go {
854
+ align-self: flex-start;
855
+ font: inherit;
856
+ font-weight: 700;
857
+ padding: 0.65rem 1.25rem;
858
+ border: 0;
859
+ border-radius: var(--radius-sm);
860
+ background: var(--gold);
861
+ color: var(--on-gold, #fff);
862
+ cursor: pointer;
863
+ }
864
+ .b-book__go:focus-visible,
865
+ .b-book__date:focus-visible {
866
+ outline: 2px solid var(--gold);
867
+ outline-offset: 2px;
868
+ }
869
+ .b-book__times:has(.b-book__date) {
870
+ grid-template-columns: 1fr;
871
+ }
872
+ .b-book__date {
873
+ display: flex;
874
+ flex-direction: column;
875
+ align-items: flex-start;
876
+ gap: 0.15rem;
877
+ padding: 0.7rem 0.9rem;
878
+ font: inherit;
879
+ text-align: start;
880
+ color: var(--fg);
881
+ background: var(--bg-surface);
882
+ border: 1px solid var(--border);
883
+ border-radius: var(--radius-sm);
884
+ cursor: pointer;
885
+ }
886
+ .b-book__date span {
887
+ color: var(--muted);
888
+ font-size: 0.92rem;
889
+ }
890
+ .b-book__date[aria-pressed='true'],
891
+ .b-book__time[aria-pressed='true'] {
892
+ border-color: var(--gold);
893
+ background: var(--gold-light);
894
+ }
895
+ .b-book__date:disabled {
896
+ opacity: 0.5;
897
+ cursor: default;
898
+ }
899
+ .b-book__add {
900
+ margin: 0.6rem 0 0;
901
+ }
902
+ .b-book__find summary {
903
+ cursor: pointer;
904
+ color: var(--fg);
905
+ text-decoration: underline;
906
+ }
907
+ .b-book__find-form {
908
+ display: flex;
909
+ flex-direction: column;
910
+ gap: 0.75rem;
911
+ margin-top: 0.75rem;
912
+ }
913
+ .b-book__find-form input {
914
+ font: inherit;
915
+ color: var(--fg);
916
+ background: var(--field-bg, var(--bg-surface));
917
+ border: var(--field-border, 1px solid var(--border));
918
+ border-radius: var(--field-radius, var(--radius-sm));
919
+ padding: 0.6rem 0.75rem;
920
+ max-width: 20rem;
921
+ }
922
+ .b-book__find-said {
923
+ margin: 0.5rem 0 0;
924
+ color: var(--muted);
925
+ }
926
+ .b-book__time--which {
927
+ display: flex;
928
+ flex-direction: column;
929
+ align-items: center;
930
+ gap: 0.1rem;
931
+ }
932
+ .b-book__time--which span {
933
+ font-size: 0.75rem;
934
+ font-weight: 400;
935
+ color: var(--muted);
936
+ }
937
+ .b-book__times:has(.b-book__time--which) {
938
+ grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
939
+ }
940
+ .b-book__days-bar[hidden] {
941
+ display: none;
942
+ }
943
+ .b-book__one {
944
+ display: flex;
945
+ flex-direction: column;
946
+ gap: 0.15rem;
947
+ padding: 0.85rem 1rem;
948
+ border: 1px solid var(--border);
949
+ border-radius: var(--radius-sm);
950
+ background: var(--bg-surface);
951
+ grid-column: 1 / -1;
952
+ }
953
+ .b-book__one span {
954
+ color: var(--muted);
955
+ }
956
+ .b-book__panel {
957
+ display: flex;
958
+ flex-direction: column;
959
+ gap: 1rem;
960
+ }
961
+ .b-book__panel[hidden] {
962
+ display: none;
963
+ }
964
+ .b-book__offers {
965
+ display: grid;
966
+ grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
967
+ gap: 0.5rem;
968
+ }
969
+ .b-book__offer {
970
+ display: flex;
971
+ flex-direction: column;
972
+ align-items: flex-start;
973
+ gap: 0.15rem;
974
+ padding: 0.75rem 0.9rem;
975
+ font: inherit;
976
+ text-align: start;
977
+ color: var(--fg);
978
+ background: var(--bg-surface);
979
+ border: 1px solid var(--border);
980
+ border-radius: var(--radius-sm);
981
+ cursor: pointer;
982
+ transition: border-color 0.15s ease, background 0.15s ease;
983
+ }
984
+ .b-book__offer span {
985
+ color: var(--muted);
986
+ font-size: 0.92rem;
987
+ }
988
+ .b-book__offer:hover {
989
+ border-color: var(--gold);
990
+ }
991
+ .b-book__offer[aria-pressed='true'] {
992
+ border-color: var(--gold);
993
+ background: var(--gold-light);
994
+ }
995
+ .b-book__offer:focus-visible {
996
+ outline: 2px solid var(--gold);
997
+ outline-offset: 2px;
998
+ }
999
+ .b-book__add a {
1000
+ color: var(--fg);
1001
+ font-weight: 600;
1002
+ }
1003
+ .b-book__more[hidden],
1004
+ .b-book__days[hidden] {
1005
+ display: none;
1006
+ }
1007
+
1008
+ /* ── The month (look: calendar, #239) ─────────────────────────────────────────
1009
+ A React island (components/islands/BookMonth.tsx, React Aria) that brings no look of
1010
+ its own: its markup carries these classes, styled from the site's tokens in light and
1011
+ dark. Month and times side by side when there's room, the times under it when not. */
1012
+ .b-book--calendar {
1013
+ width: 100%;
1014
+ max-width: 52rem;
1015
+ }
1016
+ .b-book__pick:has(.b-book__cal) {
1017
+ container-type: inline-size;
1018
+ }
1019
+ .b-book__cal {
1020
+ display: grid;
1021
+ gap: 1.5rem;
1022
+ align-items: start;
1023
+ }
1024
+ @container (min-width: 38rem) {
1025
+ .b-book__cal {
1026
+ grid-template-columns: minmax(0, 1fr) minmax(10rem, 14rem);
1027
+ gap: 2rem;
1028
+ }
1029
+ .b-book__cal .b-book__times {
1030
+ grid-template-columns: 1fr;
1031
+ max-height: 23rem;
1032
+ overflow-y: auto;
1033
+ padding: 0.15rem 0.35rem 0.15rem 0.15rem;
1034
+ }
1035
+ }
1036
+ .b-book__cal .b-book__time {
1037
+ padding-block: 0.75rem;
1038
+ border-color: var(--gold);
1039
+ color: var(--fg);
1040
+ }
1041
+ .b-book__cal .b-book__time:hover {
1042
+ background: var(--gold-light);
1043
+ }
1044
+ .b-book__day-title {
1045
+ margin: 0 0 0.75rem;
1046
+ font-size: 1rem;
1047
+ font-weight: 700;
1048
+ color: var(--fg);
1049
+ }
1050
+ .b-book__day-title:empty {
1051
+ display: none;
1052
+ }
1053
+ .b-book__month {
1054
+ color: var(--fg);
1055
+ min-height: 19rem; /* the month's room, kept while its script loads */
1056
+ }
1057
+ .b-book__cal[aria-busy='true'] .b-book__grid {
1058
+ opacity: 0.6;
1059
+ }
1060
+ .b-book__month-head {
1061
+ display: flex;
1062
+ align-items: center;
1063
+ justify-content: space-between;
1064
+ gap: 0.5rem;
1065
+ margin-block-end: 0.5rem;
1066
+ }
1067
+ .b-book__month-title {
1068
+ margin: 0;
1069
+ font-family: var(--font-heading, inherit);
1070
+ font-size: 1.1rem;
1071
+ font-weight: 700;
1072
+ color: var(--fg);
1073
+ }
1074
+ .b-book__month-nav {
1075
+ font: inherit;
1076
+ font-size: 1.15rem;
1077
+ line-height: 1;
1078
+ min-width: 2.5rem;
1079
+ min-height: 2.5rem;
1080
+ padding: 0.4rem 0.7rem;
1081
+ color: var(--fg);
1082
+ background: var(--bg-surface);
1083
+ border: 1px solid var(--border);
1084
+ border-radius: var(--radius-sm);
1085
+ cursor: pointer;
1086
+ }
1087
+ .b-book__month-nav[data-hovered] {
1088
+ border-color: var(--gold);
1089
+ }
1090
+ .b-book__month-nav[data-focus-visible] {
1091
+ outline: 2px solid var(--gold);
1092
+ outline-offset: 2px;
1093
+ }
1094
+ .b-book__month-nav[data-disabled] {
1095
+ opacity: 0.4;
1096
+ cursor: default;
1097
+ }
1098
+ .b-book__grid {
1099
+ width: 100%;
1100
+ table-layout: fixed;
1101
+ border-collapse: separate;
1102
+ border-spacing: 0.2rem;
1103
+ }
1104
+ .b-book__weekday {
1105
+ padding-block: 0.25rem;
1106
+ font-size: 0.75rem;
1107
+ font-weight: 600;
1108
+ letter-spacing: 0.04em;
1109
+ text-transform: uppercase;
1110
+ color: var(--muted);
1111
+ }
1112
+ .b-book__cell {
1113
+ display: grid;
1114
+ place-items: center;
1115
+ width: 100%;
1116
+ max-width: 2.9rem;
1117
+ aspect-ratio: 1;
1118
+ margin-inline: auto;
1119
+ font-variant-numeric: tabular-nums;
1120
+ color: var(--muted);
1121
+ border-radius: var(--radius-sm);
1122
+ cursor: default;
1123
+ outline: none;
1124
+ }
1125
+ .b-book__cell.is-free {
1126
+ font-weight: 700;
1127
+ color: var(--fg);
1128
+ background: var(--gold-light);
1129
+ cursor: pointer;
1130
+ }
1131
+ .b-book__cell.is-free:hover {
1132
+ box-shadow: inset 0 0 0 2px var(--gold);
1133
+ }
1134
+ .b-book__cell.is-today {
1135
+ text-decoration: underline;
1136
+ text-decoration-thickness: 2px;
1137
+ text-underline-offset: 0.3em;
1138
+ }
1139
+ .b-book__cell.is-selected {
1140
+ color: var(--on-brand);
1141
+ background: var(--gold);
1142
+ }
1143
+ .b-book__cell:focus-visible {
1144
+ outline: 2px solid var(--gold);
1145
+ outline-offset: 2px;
1146
+ }
1147
+ </style>