@bowlos/reservations 0.1.0 → 0.4.0

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.
Files changed (48) hide show
  1. package/README.md +83 -0
  2. package/dist/account-COEgvwfx.d.cts +43 -0
  3. package/dist/account-CzyIERC5.d.ts +43 -0
  4. package/dist/{chunk-TZTFJVDI.js → chunk-2RMK6BWO.js} +2 -2
  5. package/dist/{chunk-TZTFJVDI.js.map → chunk-2RMK6BWO.js.map} +1 -1
  6. package/dist/{chunk-T5DDHWEC.js → chunk-4FL2QYSS.js} +3 -3
  7. package/dist/{chunk-T5DDHWEC.js.map → chunk-4FL2QYSS.js.map} +1 -1
  8. package/dist/chunk-NYTGLAQH.js +299 -0
  9. package/dist/chunk-NYTGLAQH.js.map +1 -0
  10. package/dist/{chunk-TCYTNCUL.js → chunk-QGTGKNJW.js} +11 -3
  11. package/dist/chunk-QGTGKNJW.js.map +1 -0
  12. package/dist/cli.cjs +74 -4
  13. package/dist/cli.cjs.map +1 -1
  14. package/dist/cli.js +76 -6
  15. package/dist/cli.js.map +1 -1
  16. package/dist/components.cjs +1120 -0
  17. package/dist/components.cjs.map +1 -0
  18. package/dist/components.d.cts +353 -0
  19. package/dist/components.d.ts +353 -0
  20. package/dist/components.js +765 -0
  21. package/dist/components.js.map +1 -0
  22. package/dist/{account-Cl6hElpL.d.cts → data-DrM0D6Pi.d.cts} +1 -41
  23. package/dist/{account-Cl6hElpL.d.ts → data-DrM0D6Pi.d.ts} +1 -41
  24. package/dist/index.d.cts +3 -2
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +3 -3
  27. package/dist/react-B_8H7AyT.d.cts +43 -0
  28. package/dist/react-bG9YV_xP.d.ts +43 -0
  29. package/dist/react.d.cts +7 -42
  30. package/dist/react.d.ts +7 -42
  31. package/dist/react.js +3 -297
  32. package/dist/react.js.map +1 -1
  33. package/package.json +14 -3
  34. package/templates/center-site/README.md +85 -0
  35. package/templates/center-site/app/account/page.tsx +19 -0
  36. package/templates/center-site/app/book/checkout-form.tsx +85 -0
  37. package/templates/center-site/app/book/page.tsx +181 -0
  38. package/templates/center-site/app/flash/[slug]/page.tsx +24 -0
  39. package/templates/center-site/app/layout.tsx +17 -0
  40. package/templates/center-site/app/page.tsx +26 -0
  41. package/templates/center-site/app/providers.tsx +21 -0
  42. package/templates/center-site/env.example +18 -0
  43. package/templates/center-site/gitignore +8 -0
  44. package/templates/center-site/lib/bowlos.ts +31 -0
  45. package/templates/center-site/next.config.mjs +8 -0
  46. package/templates/center-site/package.json +26 -0
  47. package/templates/center-site/tsconfig.json +38 -0
  48. package/dist/chunk-TCYTNCUL.js.map +0 -1
@@ -0,0 +1,1120 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+
6
+ // src/components/theme.tsx
7
+ var VAR = {
8
+ colorPrimary: "--bowlos-color-primary",
9
+ colorPrimaryContrast: "--bowlos-color-primary-contrast",
10
+ colorText: "--bowlos-color-text",
11
+ colorMuted: "--bowlos-color-muted",
12
+ colorBg: "--bowlos-color-bg",
13
+ colorSurface: "--bowlos-color-surface",
14
+ colorBorder: "--bowlos-color-border",
15
+ colorError: "--bowlos-color-error",
16
+ colorSuccess: "--bowlos-color-success",
17
+ radius: "--bowlos-radius",
18
+ fontFamily: "--bowlos-font"
19
+ };
20
+ var BOWLOS_DEFAULT_THEME = {
21
+ colorPrimary: "#1f2937",
22
+ colorPrimaryContrast: "#ffffff",
23
+ colorText: "#111827",
24
+ colorMuted: "#6b7280",
25
+ colorBg: "#ffffff",
26
+ colorSurface: "#f9fafb",
27
+ colorBorder: "#e5e7eb",
28
+ colorError: "#dc2626",
29
+ colorSuccess: "#16a34a",
30
+ radius: "10px",
31
+ fontFamily: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif"
32
+ };
33
+ function themeToVars(theme) {
34
+ const out = {};
35
+ for (const key of Object.keys(VAR)) {
36
+ const value = theme[key];
37
+ if (value) out[VAR[key]] = value;
38
+ }
39
+ return out;
40
+ }
41
+ function BowlosTheme({
42
+ theme = {},
43
+ className,
44
+ style,
45
+ children
46
+ }) {
47
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { ...themeToVars(theme), ...style }, children });
48
+ }
49
+ function token(key) {
50
+ return `var(${VAR[key]}, ${BOWLOS_DEFAULT_THEME[key]})`;
51
+ }
52
+
53
+ // src/errors.ts
54
+ var BOWLOS_ERROR_CODES = {
55
+ // Gateway front door
56
+ API_KEY_MISSING: "API_KEY_MISSING",
57
+ API_KEY_INVALID: "API_KEY_INVALID",
58
+ ORIGIN_NOT_ALLOWED: "ORIGIN_NOT_ALLOWED",
59
+ RATE_LIMITED: "RATE_LIMITED",
60
+ // Auth
61
+ INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
62
+ PERMISSION_DENIED: "PERMISSION_DENIED",
63
+ SCOPE_REVOKED: "SCOPE_REVOKED",
64
+ NOT_FOUND: "NOT_FOUND"};
65
+ var BowlosApiError = class _BowlosApiError extends Error {
66
+ /** Stable, machine-readable code. Branch on this, not on `message`. */
67
+ code;
68
+ /** HTTP status (0 for a network failure before any response). */
69
+ status;
70
+ /** Seconds to wait before retrying — present only on `RATE_LIMITED`. */
71
+ retryAfterSeconds;
72
+ constructor(code, message, status, options = {}) {
73
+ super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
74
+ this.name = "BowlosApiError";
75
+ this.code = code;
76
+ this.status = status;
77
+ this.retryAfterSeconds = options.retryAfterSeconds;
78
+ Object.setPrototypeOf(this, _BowlosApiError.prototype);
79
+ }
80
+ /** Too many requests — caller should back off `retryAfterSeconds`. */
81
+ get isRateLimited() {
82
+ return this.code === BOWLOS_ERROR_CODES.RATE_LIMITED;
83
+ }
84
+ /** Bad/expired login. The session could not be established or has lapsed. */
85
+ get isAuthError() {
86
+ return this.code === BOWLOS_ERROR_CODES.INVALID_CREDENTIALS || this.code === BOWLOS_ERROR_CODES.PERMISSION_DENIED || this.code === BOWLOS_ERROR_CODES.SCOPE_REVOKED;
87
+ }
88
+ /** Wrong/missing API key or a disallowed origin — a site-config problem,
89
+ * not something the end customer can fix. */
90
+ get isConfigError() {
91
+ return this.code === BOWLOS_ERROR_CODES.API_KEY_MISSING || this.code === BOWLOS_ERROR_CODES.API_KEY_INVALID || this.code === BOWLOS_ERROR_CODES.ORIGIN_NOT_ALLOWED;
92
+ }
93
+ };
94
+ var BowlosContext = react.createContext(null);
95
+ function useBowlosClient() {
96
+ const client = react.useContext(BowlosContext);
97
+ if (!client) {
98
+ throw new Error("useBowlosClient must be used within a <BowlosProvider>.");
99
+ }
100
+ return client;
101
+ }
102
+ function useAccount() {
103
+ const client = useBowlosClient();
104
+ const [status, setStatus] = react.useState("loading");
105
+ const [customer, setCustomer] = react.useState(null);
106
+ const [error, setError] = react.useState(null);
107
+ const refresh = react.useCallback(async () => {
108
+ try {
109
+ const state = await client.probe();
110
+ setStatus(state);
111
+ setCustomer(state === "linked" ? await client.me() : null);
112
+ setError(null);
113
+ } catch (e) {
114
+ setStatus("unauthenticated");
115
+ setCustomer(null);
116
+ if (e instanceof BowlosApiError) setError(e);
117
+ }
118
+ }, [client]);
119
+ react.useEffect(() => {
120
+ void refresh();
121
+ }, [refresh]);
122
+ const run = react.useCallback(
123
+ async (action) => {
124
+ setError(null);
125
+ try {
126
+ await action();
127
+ await refresh();
128
+ } catch (e) {
129
+ if (e instanceof BowlosApiError) setError(e);
130
+ throw e;
131
+ }
132
+ },
133
+ [refresh]
134
+ );
135
+ const signIn = react.useCallback(
136
+ (email, password) => run(() => client.signIn(email, password)),
137
+ [client, run]
138
+ );
139
+ const signUp = react.useCallback(
140
+ (email, password) => run(() => client.signUp(email, password)),
141
+ [client, run]
142
+ );
143
+ const link = react.useCallback((profile) => run(() => client.link(profile)), [client, run]);
144
+ const signOut = react.useCallback(() => run(() => client.signOut()), [client, run]);
145
+ return { status, customer, error, signIn, signUp, link, signOut, refresh };
146
+ }
147
+ function useBowlosQuery(name, args = {}, options = {}) {
148
+ const client = useBowlosClient();
149
+ const auth = options.auth ?? false;
150
+ const enabled = options.enabled ?? true;
151
+ const [data, setData] = react.useState(null);
152
+ const [error, setError] = react.useState(null);
153
+ const [loading, setLoading] = react.useState(enabled);
154
+ const argsKey = JSON.stringify(args);
155
+ const refetch = react.useCallback(async () => {
156
+ setLoading(true);
157
+ setError(null);
158
+ try {
159
+ const result = await client.call(name, JSON.parse(argsKey), {
160
+ auth
161
+ });
162
+ setData(result);
163
+ } catch (e) {
164
+ if (e instanceof BowlosApiError) setError(e);
165
+ setData(null);
166
+ } finally {
167
+ setLoading(false);
168
+ }
169
+ }, [client, name, argsKey, auth]);
170
+ react.useEffect(() => {
171
+ if (enabled) void refetch();
172
+ }, [enabled, refetch]);
173
+ return { data, error, loading, refetch };
174
+ }
175
+
176
+ // src/hooks.tsx
177
+ function useAvailability(args, options) {
178
+ return useBowlosQuery("checkAvailability", args, options);
179
+ }
180
+ function useBookingPreview(args, options) {
181
+ return useBowlosQuery("bookingPreview", args, options);
182
+ }
183
+ function useMyReservations(args, options) {
184
+ return useBowlosQuery("listMyReservations", args, { ...options, auth: true });
185
+ }
186
+ function useMyMemberships(args, options) {
187
+ return useBowlosQuery("listMyMemberships", args, { ...options, auth: true });
188
+ }
189
+ function useMyLoyalty(args, options) {
190
+ return useBowlosQuery("getMyLoyalty", args, { ...options, auth: true });
191
+ }
192
+ function useMyCredits(args, options) {
193
+ return useBowlosQuery("listMyCredits", args, { ...options, auth: true });
194
+ }
195
+ function useMyPasses(args, options) {
196
+ return useBowlosQuery("listMyPasses", args, { ...options, auth: true });
197
+ }
198
+ function useFlashSale(args, options) {
199
+ return useBowlosQuery("getPublicFlashSaleBySlug", args, { ...options, auth: true });
200
+ }
201
+
202
+ // src/data.ts
203
+ function availableUnitCount(availability) {
204
+ return Math.max(0, availability.totalUnits - availability.busyUnitIds.length);
205
+ }
206
+ function generateIdempotencyKey() {
207
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
208
+ return crypto.randomUUID();
209
+ }
210
+ return `idem_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
211
+ }
212
+ function createBooking(client, args) {
213
+ const idempotencyKey = args.idempotencyKey ?? generateIdempotencyKey();
214
+ return client.call(
215
+ "createAnonymousBooking",
216
+ { ...args, idempotencyKey },
217
+ { auth: true }
218
+ );
219
+ }
220
+ function createCheckoutPaymentIntent(client, refToken) {
221
+ return client.call(
222
+ "createCheckoutPaymentIntent",
223
+ { refToken },
224
+ { auth: true }
225
+ );
226
+ }
227
+ function getCheckoutStatus(client, refToken) {
228
+ return client.call("getCheckoutStatus", { refToken }, { auth: true });
229
+ }
230
+ function abandonCheckout(client, refToken) {
231
+ return client.call("abandonCheckout", { refToken }, { auth: true });
232
+ }
233
+
234
+ // src/use-booking-flow.tsx
235
+ var DEFAULT_POLL_MS = 2500;
236
+ function useBookingFlow() {
237
+ const client = useBowlosClient();
238
+ const [status, setStatus] = react.useState("idle");
239
+ const [hold, setHold] = react.useState(null);
240
+ const [refToken, setRefToken] = react.useState(null);
241
+ const [paymentIntent, setPaymentIntent] = react.useState(null);
242
+ const [reservation, setReservation] = react.useState(null);
243
+ const [error, setError] = react.useState(null);
244
+ const refTokenRef = react.useRef(null);
245
+ const pollRef = react.useRef(null);
246
+ const stopPolling = react.useCallback(() => {
247
+ if (pollRef.current !== null) {
248
+ clearInterval(pollRef.current);
249
+ pollRef.current = null;
250
+ }
251
+ }, []);
252
+ react.useEffect(() => stopPolling, [stopPolling]);
253
+ const reset = react.useCallback(() => {
254
+ stopPolling();
255
+ refTokenRef.current = null;
256
+ setRefToken(null);
257
+ setHold(null);
258
+ setPaymentIntent(null);
259
+ setReservation(null);
260
+ setError(null);
261
+ setStatus("idle");
262
+ }, [stopPolling]);
263
+ const applyStatus = react.useCallback(
264
+ (s) => {
265
+ switch (s.status) {
266
+ case "paid_materialized":
267
+ setReservation({
268
+ reservationId: s.reservationId,
269
+ reservationDisplayId: s.reservationDisplayId
270
+ });
271
+ setStatus("confirmed");
272
+ stopPolling();
273
+ break;
274
+ case "expired":
275
+ setStatus("expired");
276
+ stopPolling();
277
+ break;
278
+ case "abandoned":
279
+ setStatus("abandoned");
280
+ stopPolling();
281
+ break;
282
+ case "payment_failed_retryable":
283
+ setStatus("failed");
284
+ stopPolling();
285
+ break;
286
+ case "not_found":
287
+ setError(new BowlosApiError(BOWLOS_ERROR_CODES.NOT_FOUND, "Checkout not found.", 404));
288
+ setStatus("error");
289
+ stopPolling();
290
+ break;
291
+ }
292
+ },
293
+ [stopPolling]
294
+ );
295
+ const startHold = react.useCallback(
296
+ async (args) => {
297
+ stopPolling();
298
+ setError(null);
299
+ setPaymentIntent(null);
300
+ setReservation(null);
301
+ setStatus("holding");
302
+ try {
303
+ const h = await createBooking(client, args);
304
+ setHold(h);
305
+ const rt = typeof h.checkoutRefToken === "string" ? h.checkoutRefToken : null;
306
+ refTokenRef.current = rt;
307
+ setRefToken(rt);
308
+ if (!h.requiresPayment) {
309
+ setReservation({
310
+ reservationId: h.reservationId ?? null,
311
+ reservationDisplayId: h.reservationDisplayId ?? null
312
+ });
313
+ setStatus("confirmed");
314
+ } else if (rt) {
315
+ setStatus("held");
316
+ } else {
317
+ setError(
318
+ new BowlosApiError(
319
+ "UNSUPPORTED_BOOKING_PATH",
320
+ "This booking requires payment but no checkout hold was returned.",
321
+ 0
322
+ )
323
+ );
324
+ setStatus("error");
325
+ }
326
+ } catch (e) {
327
+ if (e instanceof BowlosApiError) setError(e);
328
+ setStatus("error");
329
+ }
330
+ },
331
+ [client, stopPolling]
332
+ );
333
+ const preparePayment = react.useCallback(async () => {
334
+ const rt = refTokenRef.current;
335
+ if (!rt) return null;
336
+ setError(null);
337
+ setStatus("preparingPayment");
338
+ try {
339
+ const pi = await createCheckoutPaymentIntent(client, rt);
340
+ setPaymentIntent(pi);
341
+ setStatus("awaitingPayment");
342
+ return pi;
343
+ } catch (e) {
344
+ if (e instanceof BowlosApiError) setError(e);
345
+ setStatus("error");
346
+ return null;
347
+ }
348
+ }, [client]);
349
+ const pollStatus = react.useCallback(async () => {
350
+ const rt = refTokenRef.current;
351
+ if (!rt) return null;
352
+ try {
353
+ const s = await getCheckoutStatus(client, rt);
354
+ applyStatus(s);
355
+ return s;
356
+ } catch (e) {
357
+ if (e instanceof BowlosApiError) setError(e);
358
+ return null;
359
+ }
360
+ }, [client, applyStatus]);
361
+ const startPolling = react.useCallback(
362
+ (intervalMs = DEFAULT_POLL_MS) => {
363
+ stopPolling();
364
+ void pollStatus();
365
+ pollRef.current = setInterval(() => {
366
+ void pollStatus();
367
+ }, intervalMs);
368
+ },
369
+ [pollStatus, stopPolling]
370
+ );
371
+ const abandon = react.useCallback(async () => {
372
+ stopPolling();
373
+ const rt = refTokenRef.current;
374
+ if (rt) {
375
+ try {
376
+ await abandonCheckout(client, rt);
377
+ } catch {
378
+ }
379
+ }
380
+ setStatus("abandoned");
381
+ }, [client, stopPolling]);
382
+ return {
383
+ status,
384
+ hold,
385
+ refToken,
386
+ paymentIntent,
387
+ reservation,
388
+ requiresPayment: hold ? hold.requiresPayment : null,
389
+ error,
390
+ startHold,
391
+ preparePayment,
392
+ pollStatus,
393
+ startPolling,
394
+ stopPolling,
395
+ abandon,
396
+ reset
397
+ };
398
+ }
399
+ function styles() {
400
+ return {
401
+ // containers
402
+ card: {
403
+ fontFamily: token("fontFamily"),
404
+ color: token("colorText"),
405
+ background: token("colorBg"),
406
+ border: `1px solid ${token("colorBorder")}`,
407
+ borderRadius: token("radius"),
408
+ padding: "1.25rem",
409
+ display: "flex",
410
+ flexDirection: "column",
411
+ gap: "0.75rem",
412
+ maxWidth: 380
413
+ },
414
+ panel: {
415
+ fontFamily: token("fontFamily"),
416
+ color: token("colorText"),
417
+ background: token("colorBg"),
418
+ border: `1px solid ${token("colorBorder")}`,
419
+ borderRadius: token("radius"),
420
+ padding: "1rem 1.25rem",
421
+ display: "flex",
422
+ flexDirection: "column",
423
+ gap: "0.625rem"
424
+ },
425
+ // text
426
+ heading: { margin: "0 0 0.25rem", fontSize: "1.25rem" },
427
+ sectionTitle: {
428
+ margin: "0 0 0.5rem",
429
+ fontSize: "0.8rem",
430
+ fontWeight: 700,
431
+ letterSpacing: "0.04em",
432
+ textTransform: "uppercase",
433
+ color: token("colorMuted")
434
+ },
435
+ body: { margin: 0, color: token("colorText") },
436
+ meta: { margin: 0, fontSize: "0.9rem", color: token("colorMuted"), minHeight: "1.2em" },
437
+ muted: { margin: 0, fontSize: "0.9rem", color: token("colorMuted") },
438
+ error: { margin: 0, color: token("colorError"), fontSize: "0.9rem" },
439
+ // form
440
+ label: {
441
+ display: "flex",
442
+ flexDirection: "column",
443
+ gap: "0.25rem",
444
+ fontSize: "0.85rem",
445
+ color: token("colorMuted")
446
+ },
447
+ input: {
448
+ padding: "0.5rem 0.625rem",
449
+ fontSize: "1rem",
450
+ color: token("colorText"),
451
+ background: token("colorSurface"),
452
+ border: `1px solid ${token("colorBorder")}`,
453
+ borderRadius: token("radius")
454
+ },
455
+ // layout
456
+ row: { display: "flex", gap: "0.5rem", flexWrap: "wrap", alignItems: "center" },
457
+ rowBetween: { display: "flex", gap: "0.5rem", justifyContent: "space-between", alignItems: "center" },
458
+ stack: { display: "flex", flexDirection: "column", gap: "0.75rem" },
459
+ // buttons
460
+ primaryBtn: {
461
+ padding: "0.625rem 1rem",
462
+ fontSize: "1rem",
463
+ fontWeight: 600,
464
+ color: token("colorPrimaryContrast"),
465
+ background: token("colorPrimary"),
466
+ border: "none",
467
+ borderRadius: token("radius"),
468
+ cursor: "pointer"
469
+ },
470
+ ghostBtn: {
471
+ padding: "0.625rem 1rem",
472
+ fontSize: "1rem",
473
+ color: token("colorText"),
474
+ background: "transparent",
475
+ border: `1px solid ${token("colorBorder")}`,
476
+ borderRadius: token("radius"),
477
+ cursor: "pointer"
478
+ },
479
+ linkBtn: {
480
+ padding: 0,
481
+ fontSize: "0.9rem",
482
+ color: token("colorPrimary"),
483
+ background: "transparent",
484
+ border: "none",
485
+ cursor: "pointer",
486
+ textDecoration: "underline"
487
+ },
488
+ // list rows (reservations, memberships, ledger, passes, flash items)
489
+ listItem: {
490
+ display: "flex",
491
+ justifyContent: "space-between",
492
+ alignItems: "baseline",
493
+ gap: "0.75rem",
494
+ padding: "0.625rem 0",
495
+ borderTop: `1px solid ${token("colorBorder")}`
496
+ },
497
+ listTitle: { margin: 0, fontSize: "1rem", fontWeight: 600 },
498
+ listMeta: { margin: 0, fontSize: "0.85rem", color: token("colorMuted") },
499
+ // badges + prices
500
+ badge: {
501
+ display: "inline-block",
502
+ padding: "0.125rem 0.5rem",
503
+ fontSize: "0.75rem",
504
+ fontWeight: 600,
505
+ color: token("colorMuted"),
506
+ background: token("colorSurface"),
507
+ border: `1px solid ${token("colorBorder")}`,
508
+ borderRadius: "999px",
509
+ whiteSpace: "nowrap"
510
+ },
511
+ priceSale: { fontSize: "1.05rem", fontWeight: 700, color: token("colorText") },
512
+ priceStrike: { fontSize: "0.9rem", color: token("colorMuted"), textDecoration: "line-through" },
513
+ // flash hero
514
+ banner: {
515
+ width: "100%",
516
+ height: 140,
517
+ objectFit: "cover",
518
+ borderTopLeftRadius: token("radius"),
519
+ borderTopRightRadius: token("radius"),
520
+ display: "block"
521
+ },
522
+ countdown: { margin: 0, fontSize: "0.95rem", fontWeight: 600, color: token("colorPrimary") }
523
+ };
524
+ }
525
+ function formatCents(cents) {
526
+ return (cents / 100).toLocaleString(void 0, { style: "currency", currency: "USD" });
527
+ }
528
+ function formatCentsRange(minCents, maxCents) {
529
+ return maxCents > minCents ? `${formatCents(minCents)} \u2013 ${formatCents(maxCents)}` : formatCents(minCents);
530
+ }
531
+ function minutesToTime(min) {
532
+ const h = Math.floor(min / 60).toString().padStart(2, "0");
533
+ const m = (min % 60).toString().padStart(2, "0");
534
+ return `${h}:${m}`;
535
+ }
536
+ function timeToMinutes(t) {
537
+ const [h, m] = t.split(":").map(Number);
538
+ return (h ?? 0) * 60 + (m ?? 0);
539
+ }
540
+ function useCountdown(targetMs) {
541
+ const [now, setNow] = react.useState(null);
542
+ react.useEffect(() => {
543
+ if (targetMs === null) return;
544
+ setNow(Date.now());
545
+ const id = setInterval(() => setNow(Date.now()), 1e3);
546
+ return () => clearInterval(id);
547
+ }, [targetMs]);
548
+ if (now === null || targetMs === null) return null;
549
+ const remaining = targetMs - now;
550
+ if (remaining <= 0) return { ended: true, label: "" };
551
+ return { ended: false, label: humanizeRemaining(remaining) };
552
+ }
553
+ function humanizeRemaining(ms) {
554
+ const totalSec = Math.floor(ms / 1e3);
555
+ const d = Math.floor(totalSec / 86400);
556
+ const h = Math.floor(totalSec % 86400 / 3600);
557
+ const m = Math.floor(totalSec % 3600 / 60);
558
+ const s = totalSec % 60;
559
+ if (d > 0) return `${d}d ${h}h ${m}m`;
560
+ if (h > 0) return `${h}h ${m}m ${s}s`;
561
+ if (m > 0) return `${m}m ${s}s`;
562
+ return `${s}s`;
563
+ }
564
+ var DEFAULT_LABELS = {
565
+ heading: "Book",
566
+ date: "Date",
567
+ start: "Start time",
568
+ quantity: "Quantity",
569
+ name: "Name",
570
+ email: "Email",
571
+ hold: "Reserve",
572
+ holding: "Reserving\u2026",
573
+ continueToPayment: "Continue to payment",
574
+ preparing: "Preparing\u2026",
575
+ cancel: "Cancel",
576
+ releaseHold: "Release hold",
577
+ heldHeading: "Reserved",
578
+ heldBody: "We're holding your spot for a few minutes. Continue to payment to confirm.",
579
+ paymentHeading: "Payment",
580
+ confirmedHeading: "You're booked",
581
+ confirmationLabel: "Confirmation",
582
+ bookAnother: "Book another",
583
+ checkingAvailability: "Checking availability\u2026"
584
+ };
585
+ function BookingFlow({
586
+ centerId,
587
+ productId,
588
+ pricingMode = "per_unit_per_hour",
589
+ durationMinutes = 60,
590
+ defaultDateISO = "",
591
+ defaultStartMinuteOfDay = 18 * 60,
592
+ renderPayment,
593
+ onConfirmed,
594
+ unitLabel = { singular: "lane", plural: "lanes" },
595
+ labels,
596
+ className
597
+ }) {
598
+ const t = { ...DEFAULT_LABELS, ...labels };
599
+ const [dateISO, setDateISO] = react.useState(defaultDateISO);
600
+ const [startMinuteOfDay, setStartMinuteOfDay] = react.useState(defaultStartMinuteOfDay);
601
+ const endMinuteOfDay = startMinuteOfDay + durationMinutes;
602
+ const [units, setUnits] = react.useState(1);
603
+ const [fullName, setFullName] = react.useState("");
604
+ const [email, setEmail] = react.useState("");
605
+ const [payMessage, setPayMessage] = react.useState(null);
606
+ const availability = useAvailability(
607
+ { productId, dateISO, startMinuteOfDay, endMinuteOfDay },
608
+ { enabled: dateISO !== "" }
609
+ );
610
+ const preview = useBookingPreview(
611
+ { centerId, productId, dateISO, startMinuteOfDay, endMinuteOfDay, mode: pricingMode, units },
612
+ { enabled: dateISO !== "" }
613
+ );
614
+ const flow = useBookingFlow();
615
+ const onConfirmedRef = react.useRef(onConfirmed);
616
+ onConfirmedRef.current = onConfirmed;
617
+ react.useEffect(() => {
618
+ if (flow.status === "confirmed" && flow.reservation) {
619
+ onConfirmedRef.current?.(flow.reservation);
620
+ }
621
+ }, [flow.status, flow.reservation]);
622
+ const bookingArgs = react.useMemo(
623
+ () => ({
624
+ centerId,
625
+ productId,
626
+ dateISO,
627
+ startMinuteOfDay,
628
+ endMinuteOfDay,
629
+ mode: pricingMode,
630
+ units,
631
+ customer: { fullName, email, marketingOptIn: false }
632
+ }),
633
+ [centerId, productId, dateISO, startMinuteOfDay, endMinuteOfDay, pricingMode, units, fullName, email]
634
+ );
635
+ const freeUnits = availability.data ? availableUnitCount(availability.data) : null;
636
+ const quoteCents = preview.data?.totalCentsPerPlan?.[0]?.totalCents ?? null;
637
+ const unitNoun = units === 1 ? unitLabel.singular : unitLabel.plural;
638
+ const s = styles();
639
+ if (flow.status === "confirmed") {
640
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
641
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.confirmedHeading }),
642
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.body, children: [
643
+ t.confirmationLabel,
644
+ ": ",
645
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: flow.reservation?.reservationDisplayId ?? "\u2014" })
646
+ ] }),
647
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.primaryBtn, onClick: flow.reset, children: t.bookAnother })
648
+ ] });
649
+ }
650
+ if (flow.status === "awaitingPayment" && flow.paymentIntent) {
651
+ const pi = flow.paymentIntent;
652
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
653
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.paymentHeading }),
654
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.body, children: formatCents(pi.amountCents) }),
655
+ renderPayment({
656
+ paymentIntent: pi,
657
+ amountCents: pi.amountCents,
658
+ onPaid: () => flow.startPolling(),
659
+ onError: (m) => setPayMessage(m)
660
+ }),
661
+ payMessage && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.error, children: payMessage }),
662
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.ghostBtn, onClick: flow.abandon, children: t.cancel })
663
+ ] });
664
+ }
665
+ if (flow.status === "held" || flow.status === "preparingPayment") {
666
+ const preparing = flow.status === "preparingPayment";
667
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
668
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.heldHeading }),
669
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.body, children: t.heldBody }),
670
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.row, children: [
671
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.primaryBtn, disabled: preparing, onClick: () => flow.preparePayment(), children: preparing ? t.preparing : t.continueToPayment }),
672
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.ghostBtn, onClick: flow.abandon, children: t.releaseHold })
673
+ ] }),
674
+ flow.error && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.error, children: flow.error.code })
675
+ ] });
676
+ }
677
+ const holding = flow.status === "holding";
678
+ const onSubmit = (e) => {
679
+ e.preventDefault();
680
+ void flow.startHold(bookingArgs);
681
+ };
682
+ return /* @__PURE__ */ jsxRuntime.jsxs("form", { className, style: s.card, onSubmit, children: [
683
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.heading }),
684
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
685
+ t.date,
686
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", value: dateISO, onChange: (e) => setDateISO(e.target.value), style: s.input, required: true })
687
+ ] }),
688
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
689
+ t.start,
690
+ /* @__PURE__ */ jsxRuntime.jsx(
691
+ "input",
692
+ {
693
+ type: "time",
694
+ value: minutesToTime(startMinuteOfDay),
695
+ onChange: (e) => setStartMinuteOfDay(timeToMinutes(e.target.value)),
696
+ style: s.input
697
+ }
698
+ )
699
+ ] }),
700
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
701
+ t.quantity,
702
+ /* @__PURE__ */ jsxRuntime.jsx(
703
+ "input",
704
+ {
705
+ type: "number",
706
+ min: 1,
707
+ value: units,
708
+ onChange: (e) => setUnits(Math.max(1, Number(e.target.value) || 1)),
709
+ style: s.input
710
+ }
711
+ )
712
+ ] }),
713
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
714
+ t.name,
715
+ /* @__PURE__ */ jsxRuntime.jsx("input", { value: fullName, onChange: (e) => setFullName(e.target.value), style: s.input, required: true })
716
+ ] }),
717
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
718
+ t.email,
719
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "email", value: email, onChange: (e) => setEmail(e.target.value), style: s.input, required: true })
720
+ ] }),
721
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.meta, "aria-live": "polite", children: [
722
+ dateISO === "" ? "" : availability.loading ? t.checkingAvailability : freeUnits !== null ? `${freeUnits} ${freeUnits === 1 ? unitLabel.singular : unitLabel.plural} available` : availability.error ? availability.error.code : "",
723
+ quoteCents !== null ? ` \xB7 ${formatCents(quoteCents)}` : ""
724
+ ] }),
725
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", style: s.primaryBtn, disabled: holding || !fullName || !email || dateISO === "", children: holding ? t.holding : `${t.hold} ${unitNoun}` }),
726
+ flow.error && /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.error, children: [
727
+ flow.error.code,
728
+ " \u2014 ",
729
+ flow.error.message
730
+ ] })
731
+ ] });
732
+ }
733
+ var DEFAULT_LABELS2 = {
734
+ signInHeading: "Sign in",
735
+ signUpHeading: "Create your account",
736
+ linkHeading: "Finish your profile",
737
+ loading: "Loading\u2026",
738
+ email: "Email",
739
+ password: "Password",
740
+ name: "Name",
741
+ signIn: "Sign in",
742
+ signingIn: "Signing in\u2026",
743
+ createAccount: "Create account",
744
+ haveAccount: "Already have an account? Sign in",
745
+ needAccount: "New here? Create an account",
746
+ finishProfile: "Save profile",
747
+ saving: "Saving\u2026",
748
+ signOut: "Sign out"
749
+ };
750
+ function AuthForm({
751
+ account,
752
+ labels,
753
+ className
754
+ }) {
755
+ const t = { ...DEFAULT_LABELS2, ...labels };
756
+ const [mode, setMode] = react.useState("signIn");
757
+ const [email, setEmail] = react.useState("");
758
+ const [password, setPassword] = react.useState("");
759
+ const [fullName, setFullName] = react.useState("");
760
+ const [busy, setBusy] = react.useState(false);
761
+ const s = styles();
762
+ async function guard(action) {
763
+ setBusy(true);
764
+ try {
765
+ await action();
766
+ } catch {
767
+ } finally {
768
+ setBusy(false);
769
+ }
770
+ }
771
+ const onAuth = (e) => {
772
+ e.preventDefault();
773
+ void guard(
774
+ () => mode === "signIn" ? account.signIn(email, password) : account.signUp(email, password)
775
+ );
776
+ };
777
+ const onLink = (e) => {
778
+ e.preventDefault();
779
+ void guard(() => account.link({ fullName, email, marketingOptIn: false }));
780
+ };
781
+ if (account.status === "loading") {
782
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: s.card, children: /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading }) });
783
+ }
784
+ if (account.status === "authed_no_customer") {
785
+ return /* @__PURE__ */ jsxRuntime.jsxs("form", { className, style: s.card, onSubmit: onLink, children: [
786
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.linkHeading }),
787
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
788
+ t.name,
789
+ /* @__PURE__ */ jsxRuntime.jsx("input", { value: fullName, onChange: (e) => setFullName(e.target.value), style: s.input, required: true })
790
+ ] }),
791
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
792
+ t.email,
793
+ /* @__PURE__ */ jsxRuntime.jsx(
794
+ "input",
795
+ {
796
+ type: "email",
797
+ value: email,
798
+ onChange: (e) => setEmail(e.target.value),
799
+ style: s.input,
800
+ required: true
801
+ }
802
+ )
803
+ ] }),
804
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", style: s.primaryBtn, disabled: busy, children: busy ? t.saving : t.finishProfile }),
805
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.linkBtn, onClick: () => void account.signOut(), children: t.signOut }),
806
+ account.error && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.error, children: account.error.code })
807
+ ] });
808
+ }
809
+ if (account.status === "linked") return null;
810
+ return /* @__PURE__ */ jsxRuntime.jsxs("form", { className, style: s.card, onSubmit: onAuth, children: [
811
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: mode === "signIn" ? t.signInHeading : t.signUpHeading }),
812
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
813
+ t.email,
814
+ /* @__PURE__ */ jsxRuntime.jsx(
815
+ "input",
816
+ {
817
+ type: "email",
818
+ value: email,
819
+ onChange: (e) => setEmail(e.target.value),
820
+ style: s.input,
821
+ required: true
822
+ }
823
+ )
824
+ ] }),
825
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
826
+ t.password,
827
+ /* @__PURE__ */ jsxRuntime.jsx(
828
+ "input",
829
+ {
830
+ type: "password",
831
+ value: password,
832
+ onChange: (e) => setPassword(e.target.value),
833
+ style: s.input,
834
+ required: true
835
+ }
836
+ )
837
+ ] }),
838
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", style: s.primaryBtn, disabled: busy, children: busy ? t.signingIn : mode === "signIn" ? t.signIn : t.createAccount }),
839
+ /* @__PURE__ */ jsxRuntime.jsx(
840
+ "button",
841
+ {
842
+ type: "button",
843
+ style: s.linkBtn,
844
+ onClick: () => setMode(mode === "signIn" ? "signUp" : "signIn"),
845
+ children: mode === "signIn" ? t.needAccount : t.haveAccount
846
+ }
847
+ ),
848
+ account.error && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.error, children: account.error.code })
849
+ ] });
850
+ }
851
+ function AuthGate({ children, labels, className }) {
852
+ const account = useAccount();
853
+ if (account.status === "linked" && account.customer) {
854
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children?.({ customer: account.customer, account }) });
855
+ }
856
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthForm, { account, labels, className });
857
+ }
858
+ var DEFAULT_LABELS3 = {
859
+ welcome: "Welcome, {name}",
860
+ signOut: "Sign out",
861
+ reservations: "Reservations",
862
+ memberships: "Memberships",
863
+ loyalty: "Loyalty",
864
+ credits: "Account credit",
865
+ passes: "Passes",
866
+ loading: "Loading\u2026",
867
+ loadError: "Couldn\u2019t load",
868
+ noReservations: "No reservations yet.",
869
+ noMemberships: "No memberships yet.",
870
+ noCredits: "No credit activity yet.",
871
+ noPasses: "No passes yet.",
872
+ balance: "Balance",
873
+ pointsSuffix: "points",
874
+ toNextTier: "{points} points to {tier}",
875
+ noTier: "Not yet ranked",
876
+ renews: "Renews",
877
+ autoRenews: "Auto-renews",
878
+ balanceDue: "Balance due"
879
+ };
880
+ var ALL_SECTIONS = ["reservations", "memberships", "loyalty", "credits", "passes"];
881
+ function AccountDashboard({ brandId, sections = ALL_SECTIONS, labels, className }) {
882
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthGate, { labels, className, children: ({ customer, account }) => /* @__PURE__ */ jsxRuntime.jsx(
883
+ Dashboard,
884
+ {
885
+ brandId,
886
+ sections,
887
+ labels,
888
+ className,
889
+ customerName: customer.fullName,
890
+ onSignOut: () => void account.signOut()
891
+ }
892
+ ) });
893
+ }
894
+ function Dashboard({
895
+ brandId,
896
+ sections,
897
+ labels,
898
+ className,
899
+ customerName,
900
+ onSignOut
901
+ }) {
902
+ const t = { ...DEFAULT_LABELS3, ...labels };
903
+ const s = styles();
904
+ const show = (k) => sections.includes(k);
905
+ const reservations = useMyReservations(
906
+ { brandId },
907
+ { enabled: show("reservations") }
908
+ );
909
+ const memberships = useMyMemberships(
910
+ { brandId },
911
+ { enabled: show("memberships") }
912
+ );
913
+ const loyalty = useMyLoyalty({ brandId }, { enabled: show("loyalty") });
914
+ const credits = useMyCredits({ brandId }, { enabled: show("credits") });
915
+ const passes = useMyPasses({ brandId }, { enabled: show("passes") });
916
+ const firstName = customerName.split(" ")[0] || customerName;
917
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.stack, children: [
918
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
919
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: s.heading, children: t.welcome.replace("{name}", firstName) }),
920
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.ghostBtn, onClick: onSignOut, children: t.signOut })
921
+ ] }),
922
+ sections.map((section) => {
923
+ switch (section) {
924
+ case "reservations":
925
+ return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.reservations, q: reservations, t, children: (rows) => rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.noReservations }) : /* @__PURE__ */ jsxRuntime.jsx("div", { children: rows.map((r) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.listItem, children: [
926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
927
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: r.displayId }),
928
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listMeta, children: [
929
+ r.dateISO,
930
+ " \xB7 ",
931
+ minutesToTime(r.startMinuteOfDay),
932
+ "\u2013",
933
+ minutesToTime(r.endMinuteOfDay)
934
+ ] })
935
+ ] }),
936
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "right" }, children: [
937
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: formatCents(r.finalCents) }),
938
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: r.balanceDue ? t.balanceDue : /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: r.status }) })
939
+ ] })
940
+ ] }, r.id)) }) }, section);
941
+ case "memberships":
942
+ return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.memberships, q: memberships, t, children: (rows) => rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.noMemberships }) : /* @__PURE__ */ jsxRuntime.jsx("div", { children: rows.map((m) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.listItem, children: [
943
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
944
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: m.templateName }),
945
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listMeta, children: [
946
+ t.renews,
947
+ " ",
948
+ formatDate(m.currentPeriodEndsAt),
949
+ m.autoRenews ? ` \xB7 ${t.autoRenews}` : ""
950
+ ] })
951
+ ] }),
952
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "right" }, children: [
953
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: formatCents(m.recurringPriceCents) }),
954
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: m.status }) })
955
+ ] })
956
+ ] }, m.id)) }) }, section);
957
+ case "loyalty":
958
+ return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.loyalty, q: loyalty, t, children: (l) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
959
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
960
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: l.currentTierName ?? t.noTier }),
961
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: l.nextTierName ? t.toNextTier.replace("{points}", String(l.pointsToNextTier)).replace("{tier}", l.nextTierName) : "" })
962
+ ] }),
963
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.priceSale, children: [
964
+ l.yearPoints,
965
+ " ",
966
+ t.pointsSuffix
967
+ ] })
968
+ ] }) }, section);
969
+ case "credits":
970
+ return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.credits, q: credits, t, children: (c) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
971
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
972
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.listMeta, children: t.balance }),
973
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.priceSale, children: formatCents(c.balanceCents) })
974
+ ] }),
975
+ c.ledger.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.noCredits }) : c.ledger.slice(0, 5).map((e) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.listItem, children: [
976
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
977
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: e.note || e.entryType }),
978
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: formatDate(e.createdAt) })
979
+ ] }),
980
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listTitle, children: [
981
+ e.amountCents >= 0 ? "+" : "\u2212",
982
+ formatCents(Math.abs(e.amountCents))
983
+ ] })
984
+ ] }, e.id))
985
+ ] }) }, section);
986
+ case "passes":
987
+ return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.passes, q: passes, t, children: (rows) => rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.noPasses }) : /* @__PURE__ */ jsxRuntime.jsx("div", { children: rows.map((p) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.listItem, children: [
988
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: p.kind }),
989
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: p.state })
990
+ ] }, p.id)) }) }, section);
991
+ default:
992
+ return null;
993
+ }
994
+ })
995
+ ] });
996
+ }
997
+ function Section({
998
+ title,
999
+ q,
1000
+ t,
1001
+ children
1002
+ }) {
1003
+ const s = styles();
1004
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { style: s.panel, children: [
1005
+ /* @__PURE__ */ jsxRuntime.jsx("h4", { style: s.sectionTitle, children: title }),
1006
+ q.loading ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading }) : q.error ? /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.error, children: [
1007
+ t.loadError,
1008
+ " (",
1009
+ q.error.code,
1010
+ ")"
1011
+ ] }) : q.data == null ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading }) : children(q.data)
1012
+ ] });
1013
+ }
1014
+ function formatDate(value) {
1015
+ const d = typeof value === "number" ? new Date(value) : new Date(value);
1016
+ if (Number.isNaN(d.getTime())) return String(value);
1017
+ return d.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
1018
+ }
1019
+ var DEFAULT_LABELS4 = {
1020
+ loading: "Loading\u2026",
1021
+ unavailable: "This flash sale isn\u2019t available.",
1022
+ ended: "This flash sale has ended.",
1023
+ endsIn: "Ends in {time}",
1024
+ lockedPrice: "\u{1F512} Sign in to see the flash price",
1025
+ signInPrompt: "Sign in to unlock the flash-sale prices.",
1026
+ book: "Book",
1027
+ saleEnded: "Sale ended"
1028
+ };
1029
+ function FlashSale({ slug, onBook, labels, className }) {
1030
+ const t = { ...DEFAULT_LABELS4, ...labels };
1031
+ const account = useAccount();
1032
+ const sale = useFlashSale({ slug });
1033
+ const s = styles();
1034
+ const refetchRef = react.useRef(sale.refetch);
1035
+ refetchRef.current = sale.refetch;
1036
+ const prevStatus = react.useRef(account.status);
1037
+ react.useEffect(() => {
1038
+ if (prevStatus.current !== account.status) {
1039
+ prevStatus.current = account.status;
1040
+ void refetchRef.current();
1041
+ }
1042
+ }, [account.status]);
1043
+ const view = sale.data;
1044
+ const windowEndAt = view && view.kind !== "closed" ? view.windowEndAt : null;
1045
+ const countdown = useCountdown(windowEndAt);
1046
+ if (!view && sale.loading) {
1047
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: s.card, children: /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading }) });
1048
+ }
1049
+ if (!view) {
1050
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: s.card, children: /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.unavailable }) });
1051
+ }
1052
+ const countdownLine = view.kind !== "closed" ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.countdown, "aria-live": "polite", children: countdown === null ? "" : countdown.ended ? t.saleEnded : t.endsIn.replace("{time}", countdown.label) }) : null;
1053
+ if (view.kind === "closed") {
1054
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
1055
+ /* @__PURE__ */ jsxRuntime.jsx(Hero, { brand: view.brand, title: view.displayName, description: view.description }),
1056
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.ended })
1057
+ ] });
1058
+ }
1059
+ const saleEnded = countdown?.ended ?? false;
1060
+ if (view.kind === "live_locked") {
1061
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
1062
+ /* @__PURE__ */ jsxRuntime.jsx(Hero, { brand: view.brand, title: view.displayName, description: view.description }),
1063
+ countdownLine,
1064
+ view.preloginMessage && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.body, children: view.preloginMessage }),
1065
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: view.items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.listItem, children: [
1066
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: item.name }),
1067
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.listMeta, children: t.lockedPrice })
1068
+ ] }, item.id)) }),
1069
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.sectionTitle, children: t.signInPrompt }),
1070
+ /* @__PURE__ */ jsxRuntime.jsx(AuthForm, { account, labels })
1071
+ ] });
1072
+ }
1073
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
1074
+ /* @__PURE__ */ jsxRuntime.jsx(Hero, { brand: view.brand, title: view.displayName, description: view.description }),
1075
+ countdownLine,
1076
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: view.items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.listItem, children: [
1077
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1078
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: item.name }),
1079
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.priceStrike, children: formatCents(item.regularPriceCents) })
1080
+ ] }),
1081
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "0.75rem" }, children: [
1082
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.priceSale, children: formatCentsRange(item.salePriceCents, item.salePriceMaxCents) }),
1083
+ onBook && /* @__PURE__ */ jsxRuntime.jsx(
1084
+ "button",
1085
+ {
1086
+ type: "button",
1087
+ style: s.primaryBtn,
1088
+ disabled: saleEnded,
1089
+ onClick: () => onBook(item),
1090
+ children: saleEnded ? t.saleEnded : t.book
1091
+ }
1092
+ )
1093
+ ] })
1094
+ ] }, item.id)) })
1095
+ ] });
1096
+ }
1097
+ function Hero({
1098
+ brand,
1099
+ title,
1100
+ description
1101
+ }) {
1102
+ const s = styles();
1103
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1104
+ brand.bannerImageUrl ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: brand.bannerImageUrl, alt: brand.name, style: s.banner }) : brand.logoUrl ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: brand.logoUrl, alt: brand.name, style: { height: 40, display: "block" } }) : /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.sectionTitle, children: brand.name }),
1105
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { ...s.heading, marginTop: "0.75rem" }, children: title }),
1106
+ description && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.body, children: description })
1107
+ ] });
1108
+ }
1109
+
1110
+ exports.AccountDashboard = AccountDashboard;
1111
+ exports.AuthForm = AuthForm;
1112
+ exports.AuthGate = AuthGate;
1113
+ exports.BOWLOS_DEFAULT_THEME = BOWLOS_DEFAULT_THEME;
1114
+ exports.BookingFlow = BookingFlow;
1115
+ exports.BowlosTheme = BowlosTheme;
1116
+ exports.FlashSale = FlashSale;
1117
+ exports.formatCents = formatCents;
1118
+ exports.formatCentsRange = formatCentsRange;
1119
+ //# sourceMappingURL=components.cjs.map
1120
+ //# sourceMappingURL=components.cjs.map