@bowlos/reservations 0.41.0 → 1.0.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 (61) hide show
  1. package/AGENTS.md +20 -5
  2. package/CHANGELOG.md +22 -0
  3. package/HEADLESS.md +187 -41
  4. package/README.md +77 -0
  5. package/dist/{account-DEX2Lr78.d.cts → account-b8chVpED.d.cts} +892 -14
  6. package/dist/{account-DEX2Lr78.d.ts → account-b8chVpED.d.ts} +892 -14
  7. package/dist/booking-change-B-ADuVEz.d.cts +562 -0
  8. package/dist/booking-change-BrJ-XESC.d.ts +562 -0
  9. package/dist/chunk-43WZ6TLQ.js +12 -0
  10. package/dist/chunk-43WZ6TLQ.js.map +1 -0
  11. package/dist/{chunk-VJIS56OO.js → chunk-CTJODEHR.js} +119 -7
  12. package/dist/chunk-CTJODEHR.js.map +1 -0
  13. package/dist/{chunk-YAXBZJMI.js → chunk-EPYGIJRJ.js} +20 -3
  14. package/dist/chunk-EPYGIJRJ.js.map +1 -0
  15. package/dist/{chunk-BWJHRJN6.js → chunk-EXEKCMQ2.js} +57 -22
  16. package/dist/chunk-EXEKCMQ2.js.map +1 -0
  17. package/dist/{chunk-44WKP6MW.js → chunk-IDRTMFJJ.js} +36 -3
  18. package/dist/chunk-IDRTMFJJ.js.map +1 -0
  19. package/dist/{chunk-FMFHNBDH.js → chunk-LFFANITL.js} +98 -12
  20. package/dist/chunk-LFFANITL.js.map +1 -0
  21. package/dist/cli.cjs +5 -0
  22. package/dist/cli.cjs.map +1 -1
  23. package/dist/components.cjs +670 -131
  24. package/dist/components.cjs.map +1 -1
  25. package/dist/components.d.cts +19 -7
  26. package/dist/components.d.ts +19 -7
  27. package/dist/components.js +304 -66
  28. package/dist/components.js.map +1 -1
  29. package/dist/index.cjs +67 -0
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +4 -4
  32. package/dist/index.d.ts +4 -4
  33. package/dist/index.js +5 -4
  34. package/dist/index.js.map +1 -1
  35. package/dist/payments.cjs +34 -12
  36. package/dist/payments.cjs.map +1 -1
  37. package/dist/payments.d.cts +10 -2
  38. package/dist/payments.d.ts +10 -2
  39. package/dist/payments.js +6 -78
  40. package/dist/payments.js.map +1 -1
  41. package/dist/{react-CrRciA7I.d.ts → react-cqGEohr0.d.cts} +4 -2
  42. package/dist/{react-QJrsaOnN.d.cts → react-s4J-e10i.d.ts} +4 -2
  43. package/dist/react.cjs +202 -19
  44. package/dist/react.cjs.map +1 -1
  45. package/dist/react.d.cts +28 -6
  46. package/dist/react.d.ts +28 -6
  47. package/dist/react.js +5 -5
  48. package/package.json +2 -1
  49. package/templates/center-site/README.md +1 -0
  50. package/templates/center-site/app/book/event-reservation-form.tsx +276 -0
  51. package/templates/center-site/app/book/page.tsx +107 -49
  52. package/templates/center-site/app/catalog/page.tsx +3 -1
  53. package/templates/center-site/app/events/[slug]/page.tsx +7 -10
  54. package/templates/center-site/package.json +1 -1
  55. package/dist/booking-change-4DGu-B08.d.ts +0 -1282
  56. package/dist/booking-change-aK6P37FZ.d.cts +0 -1282
  57. package/dist/chunk-44WKP6MW.js.map +0 -1
  58. package/dist/chunk-BWJHRJN6.js.map +0 -1
  59. package/dist/chunk-FMFHNBDH.js.map +0 -1
  60. package/dist/chunk-VJIS56OO.js.map +0 -1
  61. package/dist/chunk-YAXBZJMI.js.map +0 -1
@@ -2,6 +2,8 @@
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var react = require('react');
5
+ var stripeJs = require('@stripe/stripe-js');
6
+ var reactStripeJs = require('@stripe/react-stripe-js');
5
7
 
6
8
  // src/components/theme.tsx
7
9
  var VAR = {
@@ -57,10 +59,30 @@ var BOWLOS_ERROR_CODES = {
57
59
  API_KEY_INVALID: "API_KEY_INVALID",
58
60
  ORIGIN_NOT_ALLOWED: "ORIGIN_NOT_ALLOWED",
59
61
  RATE_LIMITED: "RATE_LIMITED",
62
+ // Auth
63
+ PASSWORD_TOO_WEAK: "PASSWORD_TOO_WEAK",
64
+ CURRENT_PASSWORD_INCORRECT: "CURRENT_PASSWORD_INCORRECT",
65
+ CURRENT_PASSWORD_REQUIRED: "CURRENT_PASSWORD_REQUIRED",
60
66
  INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
67
+ SIGNUP_FAILED: "SIGNUP_FAILED",
68
+ // Shared backend codes
69
+ VALIDATION_FAILED: "VALIDATION_FAILED",
61
70
  PERMISSION_DENIED: "PERMISSION_DENIED",
62
71
  SCOPE_REVOKED: "SCOPE_REVOKED",
63
- NOT_FOUND: "NOT_FOUND"};
72
+ NOT_FOUND: "NOT_FOUND",
73
+ VERSION_CONFLICT: "VERSION_CONFLICT",
74
+ PRICING_SNAPSHOT_STALE: "PRICING_SNAPSHOT_STALE",
75
+ PAYMENTS_NOT_CONNECTED: "PAYMENTS_NOT_CONNECTED",
76
+ CONNECT_ACCOUNT_RESTRICTED: "CONNECT_ACCOUNT_RESTRICTED",
77
+ BILLING_PORTAL_UNAVAILABLE: "BILLING_PORTAL_UNAVAILABLE",
78
+ RETURN_URL_NOT_ALLOWED: "RETURN_URL_NOT_ALLOWED",
79
+ CONFLICT_RETRY: "CONFLICT_RETRY",
80
+ CHECKOUT_EXPIRED: "CHECKOUT_EXPIRED",
81
+ // Client-side
82
+ ROUTE_NOT_FOUND: "ROUTE_NOT_FOUND",
83
+ NETWORK_ERROR: "NETWORK_ERROR",
84
+ UNKNOWN: "ERROR"
85
+ };
64
86
  var BowlosApiError = class _BowlosApiError extends Error {
65
87
  /** Stable, machine-readable code. Branch on this, not on `message`. */
66
88
  code;
@@ -78,6 +100,11 @@ var BowlosApiError = class _BowlosApiError extends Error {
78
100
  this.retryAfterSeconds = options.retryAfterSeconds;
79
101
  Object.setPrototypeOf(this, _BowlosApiError.prototype);
80
102
  }
103
+ /** Typed additive createAnonymousBooking slot-full details, when present. */
104
+ get slotFullDetails() {
105
+ const d = this.details;
106
+ return this.code === "VALIDATION_FAILED" && d?.reason === "slot_full" && typeof d.waitlistAvailable === "boolean" && typeof d.requested === "number" && typeof d.available === "number" ? d : void 0;
107
+ }
81
108
  /** Too many requests — caller should back off `retryAfterSeconds`. */
82
109
  get isRateLimited() {
83
110
  return this.code === BOWLOS_ERROR_CODES.RATE_LIMITED;
@@ -112,29 +139,48 @@ function useBowlosQuery(name, args = {}, options = {}) {
112
139
  const client = useBowlosClient();
113
140
  const auth = options.auth ?? false;
114
141
  const enabled = options.enabled ?? true;
115
- const [data, setData] = react.useState(null);
116
- const [error, setError] = react.useState(null);
117
- const [loading, setLoading] = react.useState(enabled);
142
+ const keepPreviousData = options.keepPreviousData ?? true;
143
+ const [state, setState] = react.useState(null);
144
+ const request = react.useRef(0);
118
145
  const argsKey = JSON.stringify(args);
146
+ const key = react.useMemo(
147
+ () => ({ client, name, argsKey, auth, enabled }),
148
+ [client, name, argsKey, auth, enabled]
149
+ );
119
150
  const refetch = react.useCallback(async () => {
120
- setLoading(true);
121
- setError(null);
151
+ const id = ++request.current;
152
+ setState((previous) => ({
153
+ key,
154
+ data: keepPreviousData || previous?.key === key ? previous?.data ?? null : null,
155
+ error: null,
156
+ loading: true
157
+ }));
122
158
  try {
123
- const result = await client.call(name, JSON.parse(argsKey), {
124
- auth
125
- });
126
- setData(result);
159
+ const data = await key.client.call(
160
+ key.name,
161
+ JSON.parse(key.argsKey),
162
+ { auth: key.auth }
163
+ );
164
+ if (request.current === id) setState({ key, data, error: null, loading: false });
127
165
  } catch (e) {
128
- if (e instanceof BowlosApiError) setError(e);
129
- setData(null);
130
- } finally {
131
- setLoading(false);
166
+ if (request.current === id) {
167
+ setState({ key, data: null, error: e instanceof BowlosApiError ? e : null, loading: false });
168
+ }
132
169
  }
133
- }, [client, name, argsKey, auth]);
170
+ }, [key, keepPreviousData]);
134
171
  react.useEffect(() => {
135
172
  if (enabled) void refetch();
173
+ return () => {
174
+ request.current++;
175
+ };
136
176
  }, [enabled, refetch]);
137
- return { data, error, loading, refetch };
177
+ const visible = keepPreviousData || state?.key === key ? state : null;
178
+ return {
179
+ data: visible?.data ?? null,
180
+ error: visible?.error ?? null,
181
+ loading: visible?.key === key ? visible.loading : enabled,
182
+ refetch
183
+ };
138
184
  }
139
185
  function useBowlosMutation(name, options = {}) {
140
186
  const client = useBowlosClient();
@@ -198,6 +244,21 @@ function getCheckoutStatus(client, refToken) {
198
244
  function abandonCheckout(client, refToken) {
199
245
  return client.call("abandonCheckout", { refToken }, { auth: true });
200
246
  }
247
+ function joinWaitlist(client, args) {
248
+ return client.call("joinWaitlist", args, {
249
+ auth: true
250
+ });
251
+ }
252
+ function createWaitlistSetupIntent(client, args) {
253
+ return client.call(
254
+ "createWaitlistSetupIntent",
255
+ args,
256
+ { auth: true }
257
+ );
258
+ }
259
+ function confirmWaitlistCard(client, args) {
260
+ return client.call("confirmWaitlistCard", args, { auth: true });
261
+ }
201
262
 
202
263
  // src/idempotent-mutation.ts
203
264
  function useIdempotentMutation(name, options = {}) {
@@ -239,13 +300,19 @@ function useAvailability(args, options) {
239
300
  return useBowlosQuery("checkAvailability", args, options);
240
301
  }
241
302
  function useBookingPreview(args, options) {
242
- return useBowlosQuery("bookingPreview", args, options);
303
+ return useBowlosQuery("bookingPreview", args, {
304
+ ...options,
305
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
306
+ });
243
307
  }
244
308
  function useAddons(args, options) {
245
309
  return useBowlosQuery("listPublicAddons", args, options);
246
310
  }
247
311
  function useStartTimes(args, options) {
248
- return useBowlosQuery("availableStartTimes", args, options);
312
+ return useBowlosQuery("availableStartTimes", args, {
313
+ ...options,
314
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
315
+ });
249
316
  }
250
317
  function useMyReservations(args, options) {
251
318
  return useBowlosQuery("listMyReservations", args, { ...options, auth: true });
@@ -287,12 +354,20 @@ function useTestMode(args, options) {
287
354
  loading: res.loading
288
355
  };
289
356
  }
357
+ function useEventOfferOptions(args, options) {
358
+ return useBowlosQuery("eventOfferOptions", args, { ...options, keepPreviousData: false });
359
+ }
290
360
  function useRetailPricing(args, options) {
291
361
  return useBowlosQuery("listRetailPricing", args, options);
292
362
  }
293
363
  function useSavedCards(args, options) {
294
364
  return useBowlosQuery("listMyPaymentMethods", args, { ...options, auth: true });
295
365
  }
366
+ function useCreateCardSetup() {
367
+ return useBowlosMutation("createSetupIntentForAddingCard", {
368
+ auth: true
369
+ });
370
+ }
296
371
  function useRemoveCard() {
297
372
  return useBowlosMutation("detachPaymentMethod", {
298
373
  auth: true
@@ -350,6 +425,84 @@ function MaintenanceBanner({
350
425
  }
351
426
  );
352
427
  }
428
+ function useUpdateMyProfile() {
429
+ return useBowlosMutation("updateMyProfile", {
430
+ auth: true
431
+ });
432
+ }
433
+ function useMyCommunicationPrefs(args, options) {
434
+ return useBowlosQuery("listMyMarketingPrefs", args, {
435
+ ...options,
436
+ auth: true
437
+ });
438
+ }
439
+ function useSetMyCommunicationPref() {
440
+ return useBowlosMutation(
441
+ "setMyMarketingPref",
442
+ { auth: true }
443
+ );
444
+ }
445
+ function useMyPackageOrders(args, options) {
446
+ return useBowlosQuery("listMyPackageOrders", args, {
447
+ ...options,
448
+ auth: true
449
+ });
450
+ }
451
+ function useMyMembershipMembers(args, options) {
452
+ return useBowlosQuery("listMyMembershipMembers", args, {
453
+ ...options,
454
+ auth: true
455
+ });
456
+ }
457
+ function useAddMyMembershipMember() {
458
+ return useBowlosMutation(
459
+ "addMyMembershipMember",
460
+ { auth: true }
461
+ );
462
+ }
463
+ function useProduct(args, options) {
464
+ return useBowlosQuery("getPublicProduct", args, { ...options, auth: false });
465
+ }
466
+ function useSlotPrices(args, options) {
467
+ return useBowlosQuery("previewSlotPrices", args, {
468
+ ...options,
469
+ auth: args.eventOfferSlug ? options?.auth : false,
470
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
471
+ });
472
+ }
473
+ function useCenters(args, options) {
474
+ return useBowlosQuery("listPublicCenters", args, {
475
+ ...options,
476
+ auth: false
477
+ });
478
+ }
479
+ function useCancelMyMembership() {
480
+ return useIdempotentMutation(
481
+ "cancelMyMembership",
482
+ { auth: true }
483
+ );
484
+ }
485
+
486
+ // src/time-label.ts
487
+ function formatMinuteLabel(min) {
488
+ const h24 = Math.floor(min / 60) % 24;
489
+ const m = min % 60;
490
+ const period = h24 < 12 ? "AM" : "PM";
491
+ const h12 = h24 % 12 === 0 ? 12 : h24 % 12;
492
+ return `${h12}:${m.toString().padStart(2, "0")} ${period}`;
493
+ }
494
+
495
+ // src/event-offers.ts
496
+ function isFixedSession(session) {
497
+ return session.fixedDurationMinutes !== null;
498
+ }
499
+ function durationsForStart(options, startMinuteOfDay) {
500
+ return options.find((option) => option.startMinuteOfDay === startMinuteOfDay)?.durationMinutes ?? [];
501
+ }
502
+ function formatSessionRange(startMinuteOfDay, endMinuteOfDay) {
503
+ const nextDay = endMinuteOfDay >= 1440 ? " (next day)" : "";
504
+ return `${formatMinuteLabel(startMinuteOfDay)}\u2013${formatMinuteLabel(endMinuteOfDay)}${nextDay}`;
505
+ }
353
506
  var DEFAULT_POLL_MS = 2500;
354
507
  function useBookingFlow() {
355
508
  const client = useBowlosClient();
@@ -390,6 +543,7 @@ function useBookingFlow() {
390
543
  stopPolling();
391
544
  break;
392
545
  case "expired":
546
+ setError(new BowlosApiError(BOWLOS_ERROR_CODES.CHECKOUT_EXPIRED, "Your hold expired \u2014 please pick your time again", 409));
393
547
  setStatus("expired");
394
548
  stopPolling();
395
549
  break;
@@ -448,12 +602,30 @@ function useBookingFlow() {
448
602
  },
449
603
  [client, stopPolling]
450
604
  );
605
+ const checkBeforePayment = react.useCallback(async () => {
606
+ const rt = refTokenRef.current;
607
+ if (!rt) return false;
608
+ try {
609
+ const latest = await getCheckoutStatus(client, rt);
610
+ if (latest.status === "pending_payment" || latest.status === "payment_failed_retryable") return true;
611
+ applyStatus(latest);
612
+ if (latest.status === "expired" || latest.status === "abandoned") {
613
+ setError(new BowlosApiError(BOWLOS_ERROR_CODES.CHECKOUT_EXPIRED, "Your hold expired \u2014 please pick your time again", 409));
614
+ }
615
+ return false;
616
+ } catch (e) {
617
+ if (e instanceof BowlosApiError) setError(e);
618
+ setStatus("error");
619
+ return false;
620
+ }
621
+ }, [client, applyStatus]);
451
622
  const preparePayment = react.useCallback(async () => {
452
623
  const rt = refTokenRef.current;
453
624
  if (!rt) return null;
454
625
  setError(null);
455
626
  setStatus("preparingPayment");
456
627
  try {
628
+ if (!await checkBeforePayment()) return null;
457
629
  const pi = await createCheckoutPaymentIntent(client, rt);
458
630
  setPaymentIntent(pi);
459
631
  setStatus("awaitingPayment");
@@ -463,7 +635,7 @@ function useBookingFlow() {
463
635
  setStatus("error");
464
636
  return null;
465
637
  }
466
- }, [client]);
638
+ }, [client, checkBeforePayment]);
467
639
  const pollStatus = react.useCallback(async () => {
468
640
  const rt = refTokenRef.current;
469
641
  if (!rt) return null;
@@ -507,6 +679,7 @@ function useBookingFlow() {
507
679
  error,
508
680
  startHold,
509
681
  preparePayment,
682
+ checkBeforePayment,
510
683
  pollStatus,
511
684
  startPolling,
512
685
  stopPolling,
@@ -655,13 +828,6 @@ function timeToMinutes(t) {
655
828
  const [h, m] = t.split(":").map(Number);
656
829
  return (h ?? 0) * 60 + (m ?? 0);
657
830
  }
658
- function formatMinuteLabel(min) {
659
- const h24 = Math.floor(min / 60) % 24;
660
- const m = min % 60;
661
- const period = h24 < 12 ? "AM" : "PM";
662
- const h12 = h24 % 12 === 0 ? 12 : h24 % 12;
663
- return `${h12}:${m.toString().padStart(2, "0")} ${period}`;
664
- }
665
831
  function useCountdown(targetMs) {
666
832
  const [now, setNow] = react.useState(null);
667
833
  react.useEffect(() => {
@@ -999,11 +1165,22 @@ function formatDateLabel(dateISO) {
999
1165
  day: "numeric"
1000
1166
  });
1001
1167
  }
1002
- function BookingFlow({
1168
+ function BookingFlow(props) {
1169
+ const offer = props.eventOffer;
1170
+ return /* @__PURE__ */ jsxRuntime.jsx(
1171
+ BookingFlowContent,
1172
+ {
1173
+ ...props
1174
+ },
1175
+ offer ? JSON.stringify([offer.slug, props.centerId, props.productId, offer.session?.dateISO]) : "regular"
1176
+ );
1177
+ }
1178
+ function BookingFlowContent({
1003
1179
  centerId,
1004
1180
  productId,
1005
- pricingMode = "per_unit_per_hour",
1006
- durationMinutes = 60,
1181
+ pricingMode: defaultPricingMode = "per_unit_per_hour",
1182
+ durationMinutes: defaultDurationMinutes = 60,
1183
+ eventOffer,
1007
1184
  defaultDateISO = "",
1008
1185
  defaultStartMinuteOfDay = 18 * 60,
1009
1186
  renderPayment,
@@ -1019,24 +1196,71 @@ function BookingFlow({
1019
1196
  const signedIn = account.status === "linked" && account.customer !== null;
1020
1197
  const acctName = account.customer?.fullName ?? "";
1021
1198
  const acctEmail = account.customer?.email ?? "";
1022
- const [dateISO, setDateISO] = react.useState(defaultDateISO);
1199
+ const session = eventOffer?.session;
1200
+ const eventOfferSlug = eventOffer?.slug.trim();
1201
+ const pricingMode = session?.pricingMode ?? defaultPricingMode;
1202
+ const [regularDate, setDateISO] = react.useState(defaultDateISO);
1203
+ const dateISO = eventOffer ? session?.dateISO ?? "" : regularDate;
1023
1204
  react.useEffect(() => {
1024
- if (!defaultDateISO && dateISO === "") setDateISO(todayISO());
1025
- }, [defaultDateISO, dateISO]);
1026
- const [startMinuteOfDay, setStartMinuteOfDay] = react.useState(defaultStartMinuteOfDay);
1027
- const endMinuteOfDay = startMinuteOfDay + durationMinutes;
1205
+ if (!eventOffer && !defaultDateISO && dateISO === "") setDateISO(todayISO());
1206
+ }, [eventOffer, defaultDateISO, dateISO]);
1207
+ const [pickedStart, setStartMinuteOfDay] = react.useState(defaultStartMinuteOfDay);
1208
+ const [pickedDuration, setDuration] = react.useState(0);
1028
1209
  const [count, setCount] = react.useState(1);
1210
+ const [bowlers, setBowlers] = react.useState(1);
1211
+ const [games, setGames] = react.useState(1);
1212
+ const partyCap = session?.maxPartySizePerUnit == null ? void 0 : session.maxPartySizePerUnit * count;
1213
+ const persons = Math.min(bowlers, partyCap ?? Infinity);
1214
+ const eventArgs = {
1215
+ centerId,
1216
+ productId,
1217
+ dateISO,
1218
+ eventOfferSlug: eventOfferSlug ?? "",
1219
+ mode: pricingMode,
1220
+ units: count,
1221
+ persons,
1222
+ ...pricingMode === "per_game" ? { games } : {}
1223
+ };
1224
+ const discovery = useEventOfferOptions(eventArgs, {
1225
+ enabled: Boolean(session && eventOfferSlug),
1226
+ auth: signedIn
1227
+ });
1228
+ const eventOptions = discovery.loading || discovery.error ? [] : discovery.data ?? [];
1229
+ const eventStart = eventOptions.some((option) => option.startMinuteOfDay === pickedStart) ? pickedStart : eventOptions[0]?.startMinuteOfDay;
1230
+ const startMinuteOfDay = eventOffer ? eventStart ?? 0 : pickedStart;
1231
+ const durations = durationsForStart(eventOptions, startMinuteOfDay);
1232
+ const durationMinutes = eventOffer ? durations.includes(pickedDuration) ? pickedDuration : durations[0] ?? 0 : defaultDurationMinutes;
1233
+ const endMinuteOfDay = startMinuteOfDay + durationMinutes;
1234
+ const eventSlotReady = Boolean(session && eventOfferSlug && eventStart !== void 0 && durationMinutes > 0);
1235
+ const fixed = session != null && isFixedSession(session);
1236
+ const slotPrices = useSlotPrices(
1237
+ { ...eventArgs, duration: durationMinutes, slots: [startMinuteOfDay] },
1238
+ { enabled: eventSlotReady, auth: signedIn }
1239
+ );
1240
+ const eventSlotUnavailable = slotPrices.data !== null && slotPrices.data[0]?.headlinePriceCents == null;
1029
1241
  const [payMessage, setPayMessage] = react.useState(null);
1030
1242
  const [reviewing, setReviewing] = react.useState(false);
1031
- const [addonQtys, setAddonQtys] = react.useState({});
1032
- const selectedAddons = react.useMemo(
1033
- () => Object.entries(addonQtys).filter(([, q]) => q > 0).map(([addonId, quantity]) => ({ addonId, quantity })),
1034
- [addonQtys]
1243
+ const [addonQtys, setAddonQtys] = react.useState(
1244
+ () => Object.fromEntries((eventOffer?.includedAddons ?? []).map(({ addonId, quantity }) => [addonId, quantity]))
1035
1245
  );
1036
- const countArgs = pricingMode === "per_person_per_hour" ? { persons: count } : pricingMode === "per_game" ? { games: count } : { units: count };
1246
+ const addons = useAddons({ productId }, { enabled: !eventOffer || Boolean(session && eventOfferSlug) });
1247
+ const knownShoeId = session?.defaultShoeAddonId !== void 0 ? session.defaultShoeAddonId : eventOffer?.defaultShoeAddonId;
1248
+ const needsShoeId = Boolean(
1249
+ session?.shoesIncluded && knownShoeId === void 0 && addons.data?.length
1250
+ );
1251
+ const product = useProduct({ productId }, {
1252
+ enabled: needsShoeId,
1253
+ keepPreviousData: false
1254
+ });
1255
+ const shoeAddonId = knownShoeId !== void 0 ? knownShoeId : product.data?.defaultShoeAddonId;
1256
+ const addonList = (addons.data ?? []).filter(
1257
+ (addon) => !session?.shoesIncluded || shoeAddonId !== void 0 && addon.id !== shoeAddonId
1258
+ );
1259
+ const selectedAddons = Object.entries(addonQtys).filter(([id, quantity]) => quantity > 0 && (!eventOffer || addonList.some((addon) => addon.id === id))).map(([addonId, quantity]) => ({ addonId, quantity }));
1260
+ const countArgs = eventOffer ? { units: count, persons, ...pricingMode === "per_game" ? { games } : {} } : pricingMode === "per_person_per_hour" ? { persons: count } : pricingMode === "per_game" ? { games: count } : { units: count };
1037
1261
  const availability = useAvailability(
1038
1262
  { productId, dateISO, startMinuteOfDay, endMinuteOfDay },
1039
- { enabled: dateISO !== "" }
1263
+ { enabled: !eventOffer && dateISO !== "" }
1040
1264
  );
1041
1265
  const preview = useBookingPreview(
1042
1266
  {
@@ -1047,14 +1271,14 @@ function BookingFlow({
1047
1271
  endMinuteOfDay,
1048
1272
  mode: pricingMode,
1049
1273
  ...countArgs,
1274
+ ...eventOffer ? { eventOfferSlug } : {},
1050
1275
  addons: selectedAddons
1051
1276
  },
1052
- { enabled: dateISO !== "", auth: signedIn }
1277
+ { enabled: eventOffer ? eventSlotReady : dateISO !== "", auth: signedIn }
1053
1278
  );
1054
- const addons = useAddons({ productId }, { enabled: true });
1055
1279
  const startTimes = useStartTimes(
1056
1280
  { productId, dateISO, durationMinutes, mode: pricingMode },
1057
- { enabled: dateISO !== "" }
1281
+ { enabled: !eventOffer && dateISO !== "" }
1058
1282
  );
1059
1283
  const flow = useBookingFlow();
1060
1284
  const onConfirmedRef = react.useRef(onConfirmed);
@@ -1082,25 +1306,25 @@ function BookingFlow({
1082
1306
  void prepareRef.current();
1083
1307
  }
1084
1308
  }, [completeSaleOnly, flow.status]);
1085
- const bookingArgs = react.useMemo(
1086
- () => ({
1087
- centerId,
1088
- productId,
1089
- dateISO,
1090
- startMinuteOfDay,
1091
- endMinuteOfDay,
1092
- mode: pricingMode,
1093
- ...pricingMode === "per_person_per_hour" ? { persons: count } : pricingMode === "per_game" ? { games: count } : { units: count },
1094
- addons: selectedAddons,
1095
- // Always the signed-in customer — online booking requires login.
1096
- customer: { fullName: acctName, email: acctEmail, marketingOptIn: false }
1097
- }),
1098
- [centerId, productId, dateISO, startMinuteOfDay, endMinuteOfDay, pricingMode, count, selectedAddons, acctName, acctEmail]
1099
- );
1309
+ const bookingArgs = {
1310
+ centerId,
1311
+ productId,
1312
+ dateISO,
1313
+ startMinuteOfDay,
1314
+ endMinuteOfDay,
1315
+ mode: pricingMode,
1316
+ ...countArgs,
1317
+ ...eventOffer ? { eventOfferSlug } : {},
1318
+ addons: selectedAddons,
1319
+ customer: { fullName: acctName, email: acctEmail, marketingOptIn: false }
1320
+ };
1100
1321
  const availableUnits = availability.data ? availableUnitCount(availability.data) : null;
1101
1322
  const quoteCents = preview.data?.totalCentsPerPlan?.[0]?.totalCents ?? null;
1102
- const addonList = addons.data ?? [];
1103
- const startOptions = startTimes.data ?? [];
1323
+ const startOptions = eventOffer ? eventOptions.map((option) => option.startMinuteOfDay) : startTimes.data ?? [];
1324
+ const addonsSettled = (addons.data !== null || addons.error !== null) && (!needsShoeId || product.data !== null || product.error !== null);
1325
+ const eventReady = eventSlotReady && addonsSettled && slotPrices.data !== null && !eventSlotUnavailable && !slotPrices.loading && !slotPrices.error && !preview.loading && !preview.error;
1326
+ const eventReadError = discovery.error ?? slotPrices.error ?? preview.error;
1327
+ const eventUnavailable = !session || !eventOfferSlug || eventSlotUnavailable || eventReadError?.code === "NOT_FOUND";
1104
1328
  const s = styles();
1105
1329
  if (flow.status === "confirmed") {
1106
1330
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
@@ -1169,7 +1393,7 @@ function BookingFlow({
1169
1393
  const fee = preview.data?.reservationFee;
1170
1394
  const feeCents = typeof fee?.amountCents === "number" ? fee.amountCents : 0;
1171
1395
  const feeLabel = typeof fee?.label === "string" && fee.label ? fee.label : t.reservationFeeLabel;
1172
- const reservationLine = t.reservationLineLabel.replace("{count}", String(count)).replace("{unit}", countNoun(preview.data?.unitNoun, count, COUNT_LABEL[pricingMode])).replace("{date}", formatDateLabel(dateISO)).replace("{time}", `${formatMinuteLabel(startMinuteOfDay)}\u2013${formatMinuteLabel(endMinuteOfDay)}`);
1396
+ const reservationLine = t.reservationLineLabel.replace("{count}", String(count)).replace("{unit}", countNoun(preview.data?.unitNoun, count, eventOffer ? unitLabel.plural : COUNT_LABEL[pricingMode])).replace("{date}", formatDateLabel(dateISO)).replace("{time}", eventOffer ? formatSessionRange(startMinuteOfDay, endMinuteOfDay) : `${formatMinuteLabel(startMinuteOfDay)}\u2013${formatMinuteLabel(endMinuteOfDay)}`);
1173
1397
  const chosenAddons = addonList.map((a) => ({ ...a, quantity: addonQtys[a.id] ?? 0 })).filter((a) => a.quantity > 0);
1174
1398
  const fallbackAddonsCents = chosenAddons.reduce(
1175
1399
  (sum, a) => sum + a.priceCents * a.quantity,
@@ -1192,7 +1416,7 @@ function BookingFlow({
1192
1416
  ] }),
1193
1417
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.muted, children: formatCents(a.lineSubtotalCents) })
1194
1418
  ] }, a.addonId)),
1195
- plan.shoesIncluded ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
1419
+ session?.shoesIncluded || plan.shoesIncluded ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
1196
1420
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.muted, children: "Shoes included" }),
1197
1421
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.muted, children: "\u2014" })
1198
1422
  ] }) : null,
@@ -1239,7 +1463,7 @@ function BookingFlow({
1239
1463
  {
1240
1464
  type: "button",
1241
1465
  style: s.primaryBtn,
1242
- disabled: holding || preview.loading || quoteCents == null,
1466
+ disabled: holding || preview.loading || quoteCents == null || Boolean(eventOffer && !eventReady),
1243
1467
  onClick: () => void flow.startHold(bookingArgs),
1244
1468
  children: holding ? t.securing : t.continueToPayment
1245
1469
  }
@@ -1254,6 +1478,7 @@ function BookingFlow({
1254
1478
  ] })
1255
1479
  ),
1256
1480
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.linkBtn, disabled: holding, onClick: () => setReviewing(false), children: t.editOrder }),
1481
+ eventOffer && eventReadError && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", style: s.error, children: eventUnavailable ? "This event session is unavailable." : eventReadError.message }),
1257
1482
  flow.error && /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.error, children: [
1258
1483
  flow.error.code,
1259
1484
  " \u2014 ",
@@ -1263,29 +1488,68 @@ function BookingFlow({
1263
1488
  }
1264
1489
  const onSubmit = (e) => {
1265
1490
  e.preventDefault();
1266
- setReviewing(true);
1491
+ if (!eventOffer || eventReady && quoteCents !== null) setReviewing(true);
1267
1492
  };
1268
1493
  return /* @__PURE__ */ jsxRuntime.jsxs("form", { className, style: s.card, onSubmit, children: [
1269
1494
  /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.heading }),
1270
- /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1271
- t.date,
1272
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", value: dateISO, onChange: (e) => setDateISO(e.target.value), style: s.input, required: true })
1273
- ] }),
1274
- /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1275
- t.start,
1276
- startTimes.loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.meta, children: t.loadingTimes }) : startOptions.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.meta, children: t.noTimes }) : /* @__PURE__ */ jsxRuntime.jsx(
1277
- "select",
1278
- {
1279
- value: startMinuteOfDay,
1280
- onChange: (e) => setStartMinuteOfDay(Number(e.target.value)),
1281
- style: s.input,
1282
- children: startOptions.map((min) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: min, children: formatMinuteLabel(min) }, min))
1283
- }
1284
- )
1495
+ eventOffer ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1496
+ session && /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.body, children: [
1497
+ t.date,
1498
+ " \xB7 ",
1499
+ /* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: dateISO, children: formatDateLabel(dateISO) })
1500
+ ] }),
1501
+ eventUnavailable && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", style: s.meta, children: "This event session is unavailable." }),
1502
+ !eventUnavailable && eventReadError && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", style: s.error, children: eventReadError.message }),
1503
+ discovery.loading ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", style: s.meta, children: t.loadingTimes }) : startOptions.length === 0 ? !eventUnavailable && !eventReadError && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", style: s.meta, children: "No event sessions available for this party." }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1504
+ fixed && startOptions.length === 1 ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.body, children: formatSessionRange(startMinuteOfDay, endMinuteOfDay) }) : /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1505
+ t.start,
1506
+ /* @__PURE__ */ jsxRuntime.jsx(
1507
+ "select",
1508
+ {
1509
+ value: startMinuteOfDay,
1510
+ style: s.input,
1511
+ onChange: (e) => setStartMinuteOfDay(Number(e.target.value)),
1512
+ children: startOptions.map((start) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: start, children: fixed ? formatSessionRange(start, start + durationMinutes) : formatMinuteLabel(start) }, start))
1513
+ }
1514
+ )
1515
+ ] }),
1516
+ !fixed && /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1517
+ "Duration",
1518
+ /* @__PURE__ */ jsxRuntime.jsx(
1519
+ "select",
1520
+ {
1521
+ value: durationMinutes,
1522
+ style: s.input,
1523
+ onChange: (e) => setDuration(Number(e.target.value)),
1524
+ children: durations.map((duration) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: duration, children: [
1525
+ duration,
1526
+ " minutes"
1527
+ ] }, duration))
1528
+ }
1529
+ )
1530
+ ] })
1531
+ ] })
1532
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1533
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1534
+ t.date,
1535
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "date", value: dateISO, onChange: (e) => setDateISO(e.target.value), style: s.input, required: true })
1536
+ ] }),
1537
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1538
+ t.start,
1539
+ startTimes.loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.meta, children: t.loadingTimes }) : startOptions.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.meta, children: t.noTimes }) : /* @__PURE__ */ jsxRuntime.jsx(
1540
+ "select",
1541
+ {
1542
+ value: startMinuteOfDay,
1543
+ onChange: (e) => setStartMinuteOfDay(Number(e.target.value)),
1544
+ style: s.input,
1545
+ children: startOptions.map((min) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: min, children: formatMinuteLabel(min) }, min))
1546
+ }
1547
+ )
1548
+ ] })
1285
1549
  ] }),
1286
1550
  /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1287
1551
  titleCase(
1288
- (availability.data?.unitNoun ?? preview.data?.unitNoun)?.plural ?? COUNT_LABEL[pricingMode]
1552
+ (availability.data?.unitNoun ?? preview.data?.unitNoun)?.plural ?? (eventOffer ? unitLabel.plural : COUNT_LABEL[pricingMode])
1289
1553
  ),
1290
1554
  /* @__PURE__ */ jsxRuntime.jsx(
1291
1555
  "input",
@@ -1293,11 +1557,47 @@ function BookingFlow({
1293
1557
  type: "number",
1294
1558
  min: 1,
1295
1559
  value: count,
1296
- onChange: (e) => setCount(Math.max(1, Number(e.target.value) || 1)),
1560
+ onChange: (e) => {
1561
+ const next = Math.max(1, Number(e.target.value) || 1);
1562
+ setCount(eventOffer ? Math.floor(next) : next);
1563
+ const cap = session?.maxPartySizePerUnit;
1564
+ if (cap != null) setBowlers(Math.min(persons, Math.floor(next) * cap));
1565
+ },
1297
1566
  style: s.input
1298
1567
  }
1299
1568
  )
1300
1569
  ] }),
1570
+ session && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1571
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1572
+ "Bowlers",
1573
+ /* @__PURE__ */ jsxRuntime.jsx(
1574
+ "input",
1575
+ {
1576
+ style: s.input,
1577
+ type: "number",
1578
+ min: 1,
1579
+ max: partyCap,
1580
+ value: persons,
1581
+ onChange: (e) => setBowlers(Math.min(partyCap ?? Infinity, Math.max(1, Math.floor(Number(e.target.value) || 1))))
1582
+ }
1583
+ )
1584
+ ] }),
1585
+ pricingMode === "per_game" && /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
1586
+ "Games",
1587
+ /* @__PURE__ */ jsxRuntime.jsx(
1588
+ "input",
1589
+ {
1590
+ style: s.input,
1591
+ type: "number",
1592
+ min: 1,
1593
+ value: games,
1594
+ onChange: (e) => setGames(Math.max(1, Math.floor(Number(e.target.value) || 1)))
1595
+ }
1596
+ )
1597
+ ] }),
1598
+ session.shoesIncluded && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.meta, children: "Shoes included" }),
1599
+ (product.error || addons.error) && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", style: s.error, children: "Unable to load add-ons." })
1600
+ ] }),
1301
1601
  addonList.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.stack, children: [
1302
1602
  /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.sectionTitle, children: t.addonsHeading }),
1303
1603
  addonList.map((addon) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
@@ -1336,16 +1636,16 @@ function BookingFlow({
1336
1636
  /* @__PURE__ */ jsxRuntime.jsx("a", { href: accountHref, style: s.linkBtn, children: t.notYou })
1337
1637
  ] }) : null
1338
1638
  ] }) : t.signInAtCheckout }),
1339
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.meta, "aria-live": "polite", children: [
1639
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.meta, "aria-live": "polite", children: eventOffer ? eventReady && quoteCents !== null ? formatCents(quoteCents) : "" : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1340
1640
  dateISO === "" || startOptions.length === 0 ? "" : availability.loading ? t.checkingAvailability : availableUnits !== null ? `${availableUnits} ${countNoun(availability.data?.unitNoun ?? unitLabel, availableUnits, unitLabel.plural)} available` : availability.error ? availability.error.code : "",
1341
1641
  startOptions.length > 0 && quoteCents !== null ? ` \xB7 ${formatCents(quoteCents)}` : ""
1342
- ] }),
1642
+ ] }) }),
1343
1643
  /* @__PURE__ */ jsxRuntime.jsx(
1344
1644
  "button",
1345
1645
  {
1346
1646
  type: "submit",
1347
1647
  style: s.primaryBtn,
1348
- disabled: dateISO === "" || startOptions.length === 0 || quoteCents === null,
1648
+ disabled: dateISO === "" || startOptions.length === 0 || quoteCents === null || Boolean(eventOffer && !eventReady),
1349
1649
  children: t.reviewOrder
1350
1650
  }
1351
1651
  ),
@@ -1385,53 +1685,6 @@ function AccountMenu({ accountHref = "/account", labels, className }) {
1385
1685
  }
1386
1686
  return /* @__PURE__ */ jsxRuntime.jsx("a", { className, href: accountHref, style: { ...wrap, ...s.linkBtn }, children: t.signIn });
1387
1687
  }
1388
- function useUpdateMyProfile() {
1389
- return useBowlosMutation("updateMyProfile", {
1390
- auth: true
1391
- });
1392
- }
1393
- function useMyCommunicationPrefs(args, options) {
1394
- return useBowlosQuery("listMyMarketingPrefs", args, {
1395
- ...options,
1396
- auth: true
1397
- });
1398
- }
1399
- function useSetMyCommunicationPref() {
1400
- return useBowlosMutation(
1401
- "setMyMarketingPref",
1402
- { auth: true }
1403
- );
1404
- }
1405
- function useMyPackageOrders(args, options) {
1406
- return useBowlosQuery("listMyPackageOrders", args, {
1407
- ...options,
1408
- auth: true
1409
- });
1410
- }
1411
- function useMyMembershipMembers(args, options) {
1412
- return useBowlosQuery("listMyMembershipMembers", args, {
1413
- ...options,
1414
- auth: true
1415
- });
1416
- }
1417
- function useAddMyMembershipMember() {
1418
- return useBowlosMutation(
1419
- "addMyMembershipMember",
1420
- { auth: true }
1421
- );
1422
- }
1423
- function useCenters(args, options) {
1424
- return useBowlosQuery("listPublicCenters", args, {
1425
- ...options,
1426
- auth: false
1427
- });
1428
- }
1429
- function useCancelMyMembership() {
1430
- return useIdempotentMutation(
1431
- "cancelMyMembership",
1432
- { auth: true }
1433
- );
1434
- }
1435
1688
  function useAccountAction() {
1436
1689
  const [busy, setBusy] = react.useState(false);
1437
1690
  const [message, setMessage] = react.useState("");
@@ -1826,6 +2079,42 @@ function CommunicationPrefs({ brandId, labels, className }) {
1826
2079
  action.feedback
1827
2080
  ] });
1828
2081
  }
2082
+ function MyWaitlist({ brandId, centerId }) {
2083
+ const rows = useBowlosQuery(
2084
+ "listMyWaitlist",
2085
+ { brandId, centerId },
2086
+ { auth: true }
2087
+ );
2088
+ const leave = useBowlosMutation("leaveWaitlist", {
2089
+ auth: true
2090
+ });
2091
+ const action = useAccountAction();
2092
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: "Pending \u2014 waitlist", children: [
2093
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...rows, loadingLabel: "Loading\u2026" }),
2094
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: rows.data?.filter((e) => e.status === "waiting" || e.status === "pending_card").map((e) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
2095
+ e.product,
2096
+ " \u2014 ",
2097
+ e.dateISO,
2098
+ " \u2014 ",
2099
+ formatCents(e.amountCents),
2100
+ " \u2014",
2101
+ " ",
2102
+ e.status === "pending_card" ? "Card required" : "Card on file",
2103
+ /* @__PURE__ */ jsxRuntime.jsx(
2104
+ "button",
2105
+ {
2106
+ disabled: action.busy,
2107
+ onClick: () => void action.run(async () => {
2108
+ await leave.run({ brandId, centerId, entryId: e.entryId });
2109
+ await rows.refetch();
2110
+ }, "Removed from waitlist \u2014 not charged."),
2111
+ children: "Leave"
2112
+ }
2113
+ )
2114
+ ] }, e.entryId)) }),
2115
+ action.feedback
2116
+ ] });
2117
+ }
1829
2118
  function SavedCards({
1830
2119
  brandId,
1831
2120
  centerId,
@@ -2405,6 +2694,8 @@ function Dashboard({
2405
2694
  /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: p.kind }),
2406
2695
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: p.state })
2407
2696
  ] }, p.id)) }) }, section);
2697
+ case "waitlist":
2698
+ return /* @__PURE__ */ jsxRuntime.jsx(MyWaitlist, { brandId, centerId }, section);
2408
2699
  case "eventOrders":
2409
2700
  return /* @__PURE__ */ jsxRuntime.jsx(EventOrders, { brandId, title: labels?.eventOrders }, section);
2410
2701
  case "packageOrders":
@@ -3567,6 +3858,253 @@ function BookingChange({
3567
3858
  !["idle", "pay", "polling", "applying", "previewing"].includes(change.status) && /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().ghostBtn, disabled: action.busy, onClick: change.reset, children: t.reset })
3568
3859
  ] });
3569
3860
  }
3861
+ function useWaitlistJoin() {
3862
+ const client = useBowlosClient();
3863
+ const [status, setStatus] = react.useState("idle");
3864
+ const [entry, setEntry] = react.useState();
3865
+ const [setupIntent, setSetupIntent] = react.useState();
3866
+ const [error, setError] = react.useState();
3867
+ const generation = react.useRef(0);
3868
+ const busy = react.useRef(false);
3869
+ react.useEffect(
3870
+ () => () => {
3871
+ generation.current++;
3872
+ },
3873
+ [client]
3874
+ );
3875
+ function reset() {
3876
+ generation.current++;
3877
+ busy.current = false;
3878
+ setStatus("idle");
3879
+ setEntry(void 0);
3880
+ setSetupIntent(void 0);
3881
+ setError(void 0);
3882
+ }
3883
+ async function join(args) {
3884
+ if (busy.current) return;
3885
+ busy.current = true;
3886
+ const current = ++generation.current;
3887
+ setStatus("quoting");
3888
+ setError(void 0);
3889
+ setEntry(void 0);
3890
+ setSetupIntent(void 0);
3891
+ try {
3892
+ const value = await joinWaitlist(client, args);
3893
+ if (current === generation.current) {
3894
+ setEntry(value);
3895
+ setStatus("card");
3896
+ }
3897
+ return value;
3898
+ } catch (e) {
3899
+ if (current === generation.current) {
3900
+ setError(e);
3901
+ setStatus("error");
3902
+ }
3903
+ throw e;
3904
+ } finally {
3905
+ if (current === generation.current) busy.current = false;
3906
+ }
3907
+ }
3908
+ async function createCardSetup() {
3909
+ if (!entry || busy.current || status !== "card") return;
3910
+ busy.current = true;
3911
+ const current = generation.current;
3912
+ try {
3913
+ const value = await createWaitlistSetupIntent(client, { entryId: entry.entryId });
3914
+ if (current === generation.current) setSetupIntent(value);
3915
+ return value;
3916
+ } catch (e) {
3917
+ if (current === generation.current) {
3918
+ setError(e);
3919
+ setStatus("error");
3920
+ }
3921
+ throw e;
3922
+ } finally {
3923
+ if (current === generation.current) busy.current = false;
3924
+ }
3925
+ }
3926
+ async function cardConfirmed(intent) {
3927
+ if (!entry || busy.current || status !== "card") return;
3928
+ if (intent.status !== "succeeded") return;
3929
+ busy.current = true;
3930
+ const current = generation.current;
3931
+ setStatus("confirming");
3932
+ setError(void 0);
3933
+ try {
3934
+ const result = await confirmWaitlistCard(client, {
3935
+ entryId: entry.entryId,
3936
+ setupIntentId: intent.id
3937
+ });
3938
+ if (result.status !== "waiting") throw new Error("Waitlist card confirmation incomplete.");
3939
+ if (current === generation.current) setStatus("joined");
3940
+ } catch (e) {
3941
+ if (current === generation.current) {
3942
+ setError(e);
3943
+ setStatus("error");
3944
+ }
3945
+ throw e;
3946
+ } finally {
3947
+ if (current === generation.current) busy.current = false;
3948
+ }
3949
+ }
3950
+ return { status, entry, setupIntent, error, join, createCardSetup, cardConfirmed, reset };
3951
+ }
3952
+ function AddCardForm({
3953
+ brandId,
3954
+ centerId,
3955
+ onAdded,
3956
+ setupIntent,
3957
+ onSetupConfirmed,
3958
+ appearance,
3959
+ labels,
3960
+ className
3961
+ }) {
3962
+ const t = {
3963
+ title: "Add a card",
3964
+ start: "Add card",
3965
+ save: "Save card",
3966
+ saved: "Card saved.",
3967
+ error: "Unable to save this card.",
3968
+ ...labels
3969
+ };
3970
+ const setup = useCreateCardSetup();
3971
+ const action = useAccountAction();
3972
+ const [intent, setIntent] = react.useState();
3973
+ const activeIntent = setupIntent ?? intent;
3974
+ const stripe = react.useMemo(
3975
+ () => activeIntent ? stripeJs.loadStripe(activeIntent.publishableKey, { stripeAccount: activeIntent.stripeAccount }) : null,
3976
+ [activeIntent]
3977
+ );
3978
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
3979
+ !activeIntent ? /* @__PURE__ */ jsxRuntime.jsx(
3980
+ "button",
3981
+ {
3982
+ style: styles().primaryBtn,
3983
+ disabled: action.busy,
3984
+ onClick: () => void action.run(async () => setIntent(await setup.run({ brandId, centerId }))),
3985
+ children: t.start
3986
+ }
3987
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
3988
+ reactStripeJs.Elements,
3989
+ {
3990
+ stripe,
3991
+ options: {
3992
+ clientSecret: activeIntent.clientSecret,
3993
+ appearance,
3994
+ ..."customerSessionClientSecret" in activeIntent ? { customerSessionClientSecret: activeIntent.customerSessionClientSecret } : {}
3995
+ },
3996
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3997
+ SetupForm,
3998
+ {
3999
+ labels: t,
4000
+ onSetupConfirmed,
4001
+ onAdded: () => {
4002
+ setIntent(void 0);
4003
+ onAdded?.();
4004
+ }
4005
+ }
4006
+ )
4007
+ }
4008
+ ),
4009
+ action.feedback
4010
+ ] });
4011
+ }
4012
+ function SetupForm({
4013
+ labels,
4014
+ onAdded,
4015
+ onSetupConfirmed
4016
+ }) {
4017
+ const stripe = reactStripeJs.useStripe();
4018
+ const elements = reactStripeJs.useElements();
4019
+ const action = useAccountAction();
4020
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4021
+ "form",
4022
+ {
4023
+ style: styles().stack,
4024
+ onSubmit: (e) => {
4025
+ e.preventDefault();
4026
+ if (!stripe || !elements) return;
4027
+ void action.run(async () => {
4028
+ const result = await stripe.confirmSetup({ elements, redirect: "if_required" });
4029
+ if (result.error) throw new Error(result.error.message ?? labels.error);
4030
+ if (result.setupIntent?.status !== "succeeded") throw new Error(labels.error);
4031
+ await onSetupConfirmed?.(result.setupIntent);
4032
+ onAdded();
4033
+ }, labels.saved);
4034
+ },
4035
+ children: [
4036
+ /* @__PURE__ */ jsxRuntime.jsx(reactStripeJs.PaymentElement, {}),
4037
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().primaryBtn, disabled: !stripe || !elements || action.busy, children: labels.save }),
4038
+ action.feedback
4039
+ ]
4040
+ }
4041
+ );
4042
+ }
4043
+ function WaitlistJoin({ args, onJoined }) {
4044
+ const flow = useWaitlistJoin();
4045
+ const [consent, setConsent] = react.useState(false);
4046
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { "aria-label": "Join waitlist", children: [
4047
+ flow.status === "idle" && /* @__PURE__ */ jsxRuntime.jsx(
4048
+ "button",
4049
+ {
4050
+ onClick: () => {
4051
+ setConsent(false);
4052
+ void flow.join(args).catch(() => {
4053
+ });
4054
+ },
4055
+ children: "Join waitlist"
4056
+ }
4057
+ ),
4058
+ flow.status === "quoting" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Getting your price\u2026" }),
4059
+ flow.status === "card" && flow.entry && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4060
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
4061
+ formatCents(flow.entry.amountCents),
4062
+ " \u2014 charged only if a spot opens."
4063
+ ] }),
4064
+ !flow.setupIntent ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4065
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
4066
+ /* @__PURE__ */ jsxRuntime.jsx(
4067
+ "input",
4068
+ {
4069
+ type: "checkbox",
4070
+ checked: consent,
4071
+ onChange: (e) => setConsent(e.target.checked)
4072
+ }
4073
+ ),
4074
+ "I authorize a charge of ",
4075
+ formatCents(flow.entry.amountCents),
4076
+ " to this card if a spot opens."
4077
+ ] }),
4078
+ /* @__PURE__ */ jsxRuntime.jsx(
4079
+ "button",
4080
+ {
4081
+ disabled: !consent,
4082
+ onClick: () => void flow.createCardSetup().catch(() => {
4083
+ }),
4084
+ children: "Add card"
4085
+ }
4086
+ )
4087
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
4088
+ AddCardForm,
4089
+ {
4090
+ brandId: args.brandId ?? "",
4091
+ centerId: args.centerId,
4092
+ setupIntent: flow.setupIntent,
4093
+ onSetupConfirmed: async (intent) => {
4094
+ await flow.cardConfirmed(intent);
4095
+ onJoined?.();
4096
+ }
4097
+ }
4098
+ )
4099
+ ] }),
4100
+ flow.status === "confirming" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Confirming\u2026" }),
4101
+ flow.status === "joined" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Pending \u2014 waitlist. You will be charged only if a spot opens." }),
4102
+ flow.status === "error" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4103
+ /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: flow.error instanceof Error ? flow.error.message : "Unable to join waitlist." }),
4104
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: flow.reset, children: "Try again" })
4105
+ ] })
4106
+ ] });
4107
+ }
3570
4108
 
3571
4109
  exports.AccountDashboard = AccountDashboard;
3572
4110
  exports.AccountMenu = AccountMenu;
@@ -3591,6 +4129,7 @@ exports.PricingTable = PricingTable;
3591
4129
  exports.PrivacyCenter = PrivacyCenter;
3592
4130
  exports.ProfileForm = ProfileForm;
3593
4131
  exports.SavedCards = SavedCards;
4132
+ exports.WaitlistJoin = WaitlistJoin;
3594
4133
  exports.formatCents = formatCents;
3595
4134
  exports.formatCentsRange = formatCentsRange;
3596
4135
  //# sourceMappingURL=components.cjs.map