@bowlos/reservations 0.36.0 → 0.43.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 (76) hide show
  1. package/AGENTS.md +306 -0
  2. package/HEADLESS.md +595 -10
  3. package/README.md +303 -2
  4. package/dist/account-B4sZBmPI.d.cts +1837 -0
  5. package/dist/account-B4sZBmPI.d.ts +1837 -0
  6. package/dist/booking-change-Dd4PVgd3.d.cts +487 -0
  7. package/dist/booking-change-DzYs9133.d.ts +487 -0
  8. package/dist/chunk-4JMGS4YB.js +808 -0
  9. package/dist/chunk-4JMGS4YB.js.map +1 -0
  10. package/dist/chunk-I37IJNYU.js +139 -0
  11. package/dist/chunk-I37IJNYU.js.map +1 -0
  12. package/dist/{chunk-Y3YSDO3H.js → chunk-T2E6AEC7.js} +150 -6
  13. package/dist/chunk-T2E6AEC7.js.map +1 -0
  14. package/dist/{chunk-3JSVEOKG.js → chunk-V4JRDYW4.js} +61 -6
  15. package/dist/chunk-V4JRDYW4.js.map +1 -0
  16. package/dist/{chunk-TEHRROVY.js → chunk-YQRTBGXU.js} +47 -192
  17. package/dist/chunk-YQRTBGXU.js.map +1 -0
  18. package/dist/cli.cjs +34 -3
  19. package/dist/cli.cjs.map +1 -1
  20. package/dist/components.cjs +2059 -153
  21. package/dist/components.cjs.map +1 -1
  22. package/dist/components.d.cts +214 -7
  23. package/dist/components.d.ts +214 -7
  24. package/dist/components.js +1148 -7
  25. package/dist/components.js.map +1 -1
  26. package/dist/index.cjs +303 -3
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +56 -5
  29. package/dist/index.d.ts +56 -5
  30. package/dist/index.js +58 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/payments.cjs +225 -0
  33. package/dist/payments.cjs.map +1 -1
  34. package/dist/payments.d.cts +24 -2
  35. package/dist/payments.d.ts +24 -2
  36. package/dist/payments.js +4 -1
  37. package/dist/payments.js.map +1 -1
  38. package/dist/{react-CWAG4cW0.d.cts → react-C6NWC80d.d.cts} +2 -2
  39. package/dist/{react-0MyyTtE4.d.ts → react-DVdtpw5n.d.ts} +2 -2
  40. package/dist/react.cjs +870 -27
  41. package/dist/react.cjs.map +1 -1
  42. package/dist/react.d.cts +155 -12
  43. package/dist/react.d.ts +155 -12
  44. package/dist/react.js +72 -4
  45. package/dist/react.js.map +1 -1
  46. package/package.json +8 -2
  47. package/templates/center-site/README.md +5 -0
  48. package/templates/center-site/app/account/game-cards/page.tsx +17 -0
  49. package/templates/center-site/app/account/layout.tsx +16 -0
  50. package/templates/center-site/app/account/memberships/[id]/page.tsx +23 -0
  51. package/templates/center-site/app/account/memberships/page.tsx +33 -0
  52. package/templates/center-site/app/account/orders/page.tsx +17 -0
  53. package/templates/center-site/app/account/page.tsx +14 -0
  54. package/templates/center-site/app/account/payment-methods/page.tsx +23 -0
  55. package/templates/center-site/app/account/privacy/page.tsx +17 -0
  56. package/templates/center-site/app/account/profile/page.tsx +45 -0
  57. package/templates/center-site/app/account/reservations/[displayId]/change/page.tsx +46 -0
  58. package/templates/center-site/app/account/reservations/[displayId]/page.tsx +41 -0
  59. package/templates/center-site/app/account/reservations/page.tsx +35 -0
  60. package/templates/center-site/app/account/security/page.tsx +17 -0
  61. package/templates/center-site/app/events/[slug]/page.tsx +130 -0
  62. package/templates/center-site/app/events/page.tsx +57 -0
  63. package/templates/center-site/app/pay/[token]/page.tsx +53 -0
  64. package/templates/center-site/app/site-header.tsx +1 -0
  65. package/templates/center-site/lib/reservation.ts +14 -0
  66. package/templates/center-site/package.json +1 -1
  67. package/templates/center-site/tsconfig.json +7 -9
  68. package/dist/account-DfM2COaz.d.ts +0 -210
  69. package/dist/account-oCvYWmO9.d.cts +0 -210
  70. package/dist/catalog-DbhdwmnX.d.cts +0 -224
  71. package/dist/catalog-XkjgPI5C.d.ts +0 -224
  72. package/dist/chunk-3JSVEOKG.js.map +0 -1
  73. package/dist/chunk-TEHRROVY.js.map +0 -1
  74. package/dist/chunk-Y3YSDO3H.js.map +0 -1
  75. package/dist/data-BJkB-tvM.d.cts +0 -778
  76. package/dist/data-BJkB-tvM.d.ts +0 -778
@@ -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 = {
@@ -66,6 +68,7 @@ var BowlosApiError = class _BowlosApiError extends Error {
66
68
  code;
67
69
  /** HTTP status (0 for a network failure before any response). */
68
70
  status;
71
+ details;
69
72
  /** Seconds to wait before retrying — present only on `RATE_LIMITED`. */
70
73
  retryAfterSeconds;
71
74
  constructor(code, message, status, options = {}) {
@@ -73,9 +76,15 @@ var BowlosApiError = class _BowlosApiError extends Error {
73
76
  this.name = "BowlosApiError";
74
77
  this.code = code;
75
78
  this.status = status;
79
+ this.details = options.details;
76
80
  this.retryAfterSeconds = options.retryAfterSeconds;
77
81
  Object.setPrototypeOf(this, _BowlosApiError.prototype);
78
82
  }
83
+ /** Typed additive createAnonymousBooking slot-full details, when present. */
84
+ get slotFullDetails() {
85
+ const d = this.details;
86
+ return this.code === "VALIDATION_FAILED" && d?.reason === "slot_full" && typeof d.waitlistAvailable === "boolean" && typeof d.requested === "number" && typeof d.available === "number" ? d : void 0;
87
+ }
79
88
  /** Too many requests — caller should back off `retryAfterSeconds`. */
80
89
  get isRateLimited() {
81
90
  return this.code === BOWLOS_ERROR_CODES.RATE_LIMITED;
@@ -134,6 +143,36 @@ function useBowlosQuery(name, args = {}, options = {}) {
134
143
  }, [enabled, refetch]);
135
144
  return { data, error, loading, refetch };
136
145
  }
146
+ function useBowlosMutation(name, options = {}) {
147
+ const client = useBowlosClient();
148
+ const auth = options.auth ?? false;
149
+ const [data, setData] = react.useState(null);
150
+ const [error, setError] = react.useState(null);
151
+ const [loading, setLoading] = react.useState(false);
152
+ const run = react.useCallback(
153
+ async (args) => {
154
+ setLoading(true);
155
+ setError(null);
156
+ try {
157
+ const result = await client.call(name, args, { auth });
158
+ setData(result);
159
+ return result;
160
+ } catch (e) {
161
+ if (e instanceof BowlosApiError) setError(e);
162
+ throw e;
163
+ } finally {
164
+ setLoading(false);
165
+ }
166
+ },
167
+ [client, name, auth]
168
+ );
169
+ const reset = react.useCallback(() => {
170
+ setData(null);
171
+ setError(null);
172
+ setLoading(false);
173
+ }, []);
174
+ return { run, data, error, loading, reset };
175
+ }
137
176
 
138
177
  // src/data.ts
139
178
  function availableUnitCount(availability) {
@@ -166,6 +205,56 @@ function getCheckoutStatus(client, refToken) {
166
205
  function abandonCheckout(client, refToken) {
167
206
  return client.call("abandonCheckout", { refToken }, { auth: true });
168
207
  }
208
+ function joinWaitlist(client, args) {
209
+ return client.call("joinWaitlist", args, {
210
+ auth: true
211
+ });
212
+ }
213
+ function createWaitlistSetupIntent(client, args) {
214
+ return client.call(
215
+ "createWaitlistSetupIntent",
216
+ args,
217
+ { auth: true }
218
+ );
219
+ }
220
+ function confirmWaitlistCard(client, args) {
221
+ return client.call("confirmWaitlistCard", args, { auth: true });
222
+ }
223
+
224
+ // src/idempotent-mutation.ts
225
+ function useIdempotentMutation(name, options = {}) {
226
+ const mutation = useBowlosMutation(name, options);
227
+ const pending = react.useRef(null);
228
+ const run = react.useCallback(
229
+ async (args) => {
230
+ const fingerprint = JSON.stringify(args, (_key, value) => {
231
+ if (value && typeof value === "object" && !Array.isArray(value)) {
232
+ return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)));
233
+ }
234
+ return value;
235
+ });
236
+ if (!pending.current || pending.current.fingerprint !== fingerprint) {
237
+ pending.current = { fingerprint, key: generateIdempotencyKey() };
238
+ }
239
+ const action = pending.current;
240
+ try {
241
+ const result = await mutation.run({ ...args, idempotencyKey: action.key });
242
+ if (pending.current === action) pending.current = null;
243
+ return result;
244
+ } catch (error) {
245
+ const retryable = !(error instanceof BowlosApiError) || error.status === 0 || error.status === 408 || error.status === 429 || error.status >= 500;
246
+ if (!retryable && pending.current === action) pending.current = null;
247
+ throw error;
248
+ }
249
+ },
250
+ [mutation.run]
251
+ );
252
+ const reset = react.useCallback(() => {
253
+ pending.current = null;
254
+ mutation.reset();
255
+ }, [mutation.reset]);
256
+ return { ...mutation, run, reset };
257
+ }
169
258
 
170
259
  // src/hooks.tsx
171
260
  function useAvailability(args, options) {
@@ -183,9 +272,15 @@ function useStartTimes(args, options) {
183
272
  function useMyReservations(args, options) {
184
273
  return useBowlosQuery("listMyReservations", args, { ...options, auth: true });
185
274
  }
275
+ function useMyEventOrders(args, options) {
276
+ return useBowlosQuery("listMyEventOrders", args, { ...options, auth: true });
277
+ }
186
278
  function useMyMemberships(args, options) {
187
279
  return useBowlosQuery("listMyMemberships", args, { ...options, auth: true });
188
280
  }
281
+ function useMyMembershipDetail(args, options) {
282
+ return useBowlosQuery("getMyMembershipDetail", args, { ...options, auth: true });
283
+ }
189
284
  function useMyLoyalty(args, options) {
190
285
  return useBowlosQuery("getMyLoyalty", args, { ...options, auth: true });
191
286
  }
@@ -195,6 +290,9 @@ function useMyCredits(args, options) {
195
290
  function useMyPasses(args, options) {
196
291
  return useBowlosQuery("listMyPasses", args, { ...options, auth: true });
197
292
  }
293
+ function useMyGameCards(args, options) {
294
+ return useBowlosQuery("listMyGameCards", args, { ...options, auth: true });
295
+ }
198
296
  function useFlashSale(args, options) {
199
297
  return useBowlosQuery("getPublicFlashSaleBySlug", args, { ...options, auth: true });
200
298
  }
@@ -214,6 +312,39 @@ function useTestMode(args, options) {
214
312
  function useRetailPricing(args, options) {
215
313
  return useBowlosQuery("listRetailPricing", args, options);
216
314
  }
315
+ function useSavedCards(args, options) {
316
+ return useBowlosQuery("listMyPaymentMethods", args, { ...options, auth: true });
317
+ }
318
+ function useCreateCardSetup() {
319
+ return useBowlosMutation("createSetupIntentForAddingCard", {
320
+ auth: true
321
+ });
322
+ }
323
+ function useRemoveCard() {
324
+ return useBowlosMutation("detachPaymentMethod", {
325
+ auth: true
326
+ });
327
+ }
328
+ function useSetDefaultCard() {
329
+ return useBowlosMutation("setDefaultPaymentMethod", {
330
+ auth: true
331
+ });
332
+ }
333
+ function useChangePassword() {
334
+ const client = useBowlosClient();
335
+ const mutation = useBowlosMutation("changeMyPassword", {
336
+ auth: true
337
+ });
338
+ const run = react.useCallback(
339
+ async (args) => {
340
+ const result = await mutation.run(args);
341
+ await client.signOut();
342
+ return result;
343
+ },
344
+ [client, mutation.run]
345
+ );
346
+ return { ...mutation, run };
347
+ }
217
348
  var DEFAULT_MESSAGE = "We're performing maintenance \u2014 online booking is temporarily unavailable. Please check back soon.";
218
349
  function MaintenanceBanner({
219
350
  brandId,
@@ -547,6 +678,10 @@ function minutesToTime(min) {
547
678
  const m = (min % 60).toString().padStart(2, "0");
548
679
  return `${h}:${m}`;
549
680
  }
681
+ function timeToMinutes(t) {
682
+ const [h, m] = t.split(":").map(Number);
683
+ return (h ?? 0) * 60 + (m ?? 0);
684
+ }
550
685
  function formatMinuteLabel(min) {
551
686
  const h24 = Math.floor(min / 60) % 24;
552
687
  const m = min % 60;
@@ -1277,170 +1412,1157 @@ function AccountMenu({ accountHref = "/account", labels, className }) {
1277
1412
  }
1278
1413
  return /* @__PURE__ */ jsxRuntime.jsx("a", { className, href: accountHref, style: { ...wrap, ...s.linkBtn }, children: t.signIn });
1279
1414
  }
1280
- var DEFAULT_LABELS4 = {
1281
- welcome: "Welcome, {name}",
1282
- signOut: "Sign out",
1283
- reservations: "Reservations",
1284
- memberships: "Memberships",
1285
- loyalty: "Loyalty",
1286
- credits: "Account credit",
1287
- passes: "Passes",
1288
- loading: "Loading\u2026",
1289
- loadError: "Couldn\u2019t load",
1290
- noReservations: "No reservations yet.",
1291
- noMemberships: "No memberships yet.",
1292
- noCredits: "No credit activity yet.",
1293
- noPasses: "No passes yet.",
1294
- balance: "Balance",
1295
- pointsSuffix: "points",
1296
- toNextTier: "{points} points to {tier}",
1297
- noTier: "Not yet ranked",
1298
- renews: "Renews",
1299
- autoRenews: "Auto-renews",
1300
- balanceDue: "Balance due"
1301
- };
1302
- var ALL_SECTIONS = ["reservations", "memberships", "loyalty", "credits", "passes"];
1303
- function AccountDashboard({ brandId, sections = ALL_SECTIONS, labels, className }) {
1304
- return /* @__PURE__ */ jsxRuntime.jsx(AuthGate, { labels, className, children: ({ customer, account }) => /* @__PURE__ */ jsxRuntime.jsx(
1305
- Dashboard,
1306
- {
1307
- brandId,
1308
- sections,
1309
- labels,
1310
- className,
1311
- customerName: customer.fullName,
1312
- onSignOut: () => void account.signOut()
1415
+ function useUpdateMyProfile() {
1416
+ return useBowlosMutation("updateMyProfile", {
1417
+ auth: true
1418
+ });
1419
+ }
1420
+ function useMyCommunicationPrefs(args, options) {
1421
+ return useBowlosQuery("listMyMarketingPrefs", args, {
1422
+ ...options,
1423
+ auth: true
1424
+ });
1425
+ }
1426
+ function useSetMyCommunicationPref() {
1427
+ return useBowlosMutation(
1428
+ "setMyMarketingPref",
1429
+ { auth: true }
1430
+ );
1431
+ }
1432
+ function useMyPackageOrders(args, options) {
1433
+ return useBowlosQuery("listMyPackageOrders", args, {
1434
+ ...options,
1435
+ auth: true
1436
+ });
1437
+ }
1438
+ function useMyMembershipMembers(args, options) {
1439
+ return useBowlosQuery("listMyMembershipMembers", args, {
1440
+ ...options,
1441
+ auth: true
1442
+ });
1443
+ }
1444
+ function useAddMyMembershipMember() {
1445
+ return useBowlosMutation(
1446
+ "addMyMembershipMember",
1447
+ { auth: true }
1448
+ );
1449
+ }
1450
+ function useCenters(args, options) {
1451
+ return useBowlosQuery("listPublicCenters", args, {
1452
+ ...options,
1453
+ auth: false
1454
+ });
1455
+ }
1456
+ function useCancelMyMembership() {
1457
+ return useIdempotentMutation(
1458
+ "cancelMyMembership",
1459
+ { auth: true }
1460
+ );
1461
+ }
1462
+ function useAccountAction() {
1463
+ const [busy, setBusy] = react.useState(false);
1464
+ const [message, setMessage] = react.useState("");
1465
+ const [failed, setFailed] = react.useState(false);
1466
+ const alert = react.useRef(null);
1467
+ const locked = react.useRef(false);
1468
+ async function run(action, success = "") {
1469
+ if (locked.current) return;
1470
+ locked.current = true;
1471
+ setBusy(true);
1472
+ setMessage("");
1473
+ setFailed(false);
1474
+ try {
1475
+ await action();
1476
+ setMessage(success);
1477
+ } catch (error) {
1478
+ setFailed(true);
1479
+ setMessage(error instanceof Error ? error.message : "Unable to complete this request.");
1480
+ setTimeout(() => alert.current?.focus(), 0);
1481
+ } finally {
1482
+ locked.current = false;
1483
+ setBusy(false);
1313
1484
  }
1314
- ) });
1485
+ }
1486
+ return {
1487
+ busy,
1488
+ run,
1489
+ feedback: message ? /* @__PURE__ */ jsxRuntime.jsx("p", { ref: alert, tabIndex: -1, role: failed ? "alert" : "status", children: message }) : null
1490
+ };
1315
1491
  }
1316
- function Dashboard({
1492
+ function AccountPanel({
1493
+ title,
1494
+ children,
1495
+ className
1496
+ }) {
1497
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { "aria-label": title, className, style: styles().panel, children: [
1498
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: styles().heading, children: title }),
1499
+ children
1500
+ ] });
1501
+ }
1502
+ function QueryState({
1503
+ loading,
1504
+ error,
1505
+ loadingLabel = "Loading\u2026"
1506
+ }) {
1507
+ return error ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: error.message }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", children: loadingLabel }) : null;
1508
+ }
1509
+
1510
+ // src/toolkit-hooks.tsx
1511
+ function useMyGameCardHistory(args, options) {
1512
+ return useBowlosQuery("getMyGameCardRedemptionsPage", args, {
1513
+ ...options,
1514
+ auth: true
1515
+ });
1516
+ }
1517
+ function useWalletPassUrl() {
1518
+ return useBowlosMutation("getMyWalletPassUrl", {
1519
+ auth: true
1520
+ });
1521
+ }
1522
+ function GameCardHistory({
1317
1523
  brandId,
1318
- sections,
1524
+ centerId,
1525
+ gameCardId,
1526
+ unitNoun = "games",
1527
+ timeZone,
1319
1528
  labels,
1320
- className,
1321
- customerName,
1322
- onSignOut
1529
+ className
1323
1530
  }) {
1324
- const t = { ...DEFAULT_LABELS4, ...labels };
1325
- const s = styles();
1326
- const show = (k) => sections.includes(k);
1327
- const reservations = useMyReservations(
1328
- { brandId },
1329
- { enabled: show("reservations") }
1330
- );
1331
- const memberships = useMyMemberships(
1332
- { brandId },
1333
- { enabled: show("memberships") }
1334
- );
1335
- const loyalty = useMyLoyalty({ brandId }, { enabled: show("loyalty") });
1336
- const credits = useMyCredits({ brandId }, { enabled: show("credits") });
1337
- const passes = useMyPasses({ brandId }, { enabled: show("passes") });
1338
- const firstName = customerName.split(" ")[0] || customerName;
1339
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.stack, children: [
1340
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
1341
- /* @__PURE__ */ jsxRuntime.jsx("h2", { style: s.heading, children: t.welcome.replace("{name}", firstName) }),
1342
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.ghostBtn, onClick: onSignOut, children: t.signOut })
1343
- ] }),
1344
- sections.map((section) => {
1345
- switch (section) {
1346
- case "reservations":
1347
- 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: [
1348
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1349
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: r.displayId }),
1350
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listMeta, children: [
1351
- r.dateISO,
1352
- " \xB7 ",
1353
- minutesToTime(r.startMinuteOfDay),
1354
- "\u2013",
1355
- minutesToTime(r.endMinuteOfDay)
1356
- ] })
1357
- ] }),
1358
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "right" }, children: [
1359
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: formatCents(r.finalCents) }),
1360
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: r.balanceDue ? t.balanceDue : /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: r.status }) })
1361
- ] })
1362
- ] }, r.id)) }) }, section);
1363
- case "memberships":
1364
- 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: [
1365
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1366
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: m.templateName }),
1367
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listMeta, children: [
1368
- t.renews,
1369
- " ",
1370
- formatDate(m.currentPeriodEndsAt),
1371
- m.autoRenews ? ` \xB7 ${t.autoRenews}` : ""
1372
- ] })
1373
- ] }),
1374
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "right" }, children: [
1375
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: formatCents(m.recurringPriceCents) }),
1376
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: m.status }) })
1377
- ] })
1378
- ] }, m.id)) }) }, section);
1379
- case "loyalty":
1380
- return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.loyalty, q: loyalty, t, children: (l) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
1381
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1382
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: l.currentTierName ?? t.noTier }),
1383
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: l.nextTierName ? t.toNextTier.replace("{points}", String(l.pointsToNextTier)).replace("{tier}", l.nextTierName) : "" })
1384
- ] }),
1385
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.priceSale, children: [
1386
- l.yearPoints,
1387
- " ",
1388
- t.pointsSuffix
1389
- ] })
1390
- ] }) }, section);
1391
- case "credits":
1392
- return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.credits, q: credits, t, children: (c) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1393
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
1394
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.listMeta, children: t.balance }),
1395
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.priceSale, children: formatCents(c.balanceCents) })
1396
- ] }),
1397
- 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: [
1398
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1399
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: e.note || e.entryType }),
1400
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: formatDate(e.createdAt) })
1401
- ] }),
1402
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listTitle, children: [
1403
- e.amountCents >= 0 ? "+" : "\u2212",
1404
- formatCents(Math.abs(e.amountCents))
1405
- ] })
1406
- ] }, e.id))
1407
- ] }) }, section);
1408
- case "passes":
1409
- 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: [
1410
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: p.kind }),
1411
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: p.state })
1412
- ] }, p.id)) }) }, section);
1413
- default:
1414
- return null;
1531
+ const t = {
1532
+ title: "Game card history",
1533
+ empty: "No activity yet.",
1534
+ more: "Next page",
1535
+ back: "First page",
1536
+ ...labels
1537
+ };
1538
+ const centers = useCenters({ brandId });
1539
+ const [cursor, setCursor] = react.useState(null);
1540
+ const history = useMyGameCardHistory({ brandId, centerId, gameCardId, cursor, numItems: 20 });
1541
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
1542
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...history }),
1543
+ history.data?.page.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { children: t.empty }),
1544
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: history.data?.page.map((row) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
1545
+ (timeZone ?? centers.data?.find((center) => center.name === row.centerName)?.timezone) && new Date(row.redeemedAt).toLocaleDateString(void 0, {
1546
+ timeZone: timeZone ?? centers.data?.find((center) => center.name === row.centerName)?.timezone
1547
+ }),
1548
+ " ",
1549
+ "\u2014 ",
1550
+ row.gamesConsumed,
1551
+ " ",
1552
+ unitNoun,
1553
+ " \u2014 ",
1554
+ row.centerName,
1555
+ row.notes && /* @__PURE__ */ jsxRuntime.jsx("p", { children: row.notes })
1556
+ ] }, row._id)) }),
1557
+ history.data && !history.data.isDone && /* @__PURE__ */ jsxRuntime.jsx(
1558
+ "button",
1559
+ {
1560
+ style: styles().ghostBtn,
1561
+ disabled: history.loading,
1562
+ onClick: () => setCursor(history.data.continueCursor),
1563
+ children: t.more
1415
1564
  }
1416
- })
1565
+ ),
1566
+ cursor && /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().ghostBtn, onClick: () => setCursor(null), children: t.back })
1417
1567
  ] });
1418
1568
  }
1419
- function Section({
1420
- title,
1421
- q,
1422
- t,
1423
- children
1569
+ function AddToWalletButtons({
1570
+ eligible = true,
1571
+ labels,
1572
+ className,
1573
+ ...scope
1424
1574
  }) {
1425
- const s = styles();
1426
- return /* @__PURE__ */ jsxRuntime.jsxs("section", { style: s.panel, children: [
1427
- /* @__PURE__ */ jsxRuntime.jsx("h4", { style: s.sectionTitle, children: title }),
1428
- q.loading ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading }) : q.error ? /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.error, children: [
1429
- t.loadError,
1430
- " (",
1431
- q.error.code,
1432
- ")"
1433
- ] }) : q.data == null ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading }) : children(q.data)
1575
+ const t = { apple: "Add to Apple Wallet", google: "Add to Google Wallet", ...labels };
1576
+ const wallet = useWalletPassUrl();
1577
+ const action = useAccountAction();
1578
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: styles().row, children: [
1579
+ eligible && ["apple", "google"].map((platform) => /* @__PURE__ */ jsxRuntime.jsx(
1580
+ "button",
1581
+ {
1582
+ style: styles().ghostBtn,
1583
+ disabled: action.busy,
1584
+ onClick: () => void action.run(async () => {
1585
+ const result = await wallet.run({ ...scope, platform });
1586
+ window.location.assign(result.url);
1587
+ }),
1588
+ children: t[platform]
1589
+ },
1590
+ platform
1591
+ )),
1592
+ action.feedback
1434
1593
  ] });
1435
1594
  }
1436
- function formatDate(value) {
1437
- const d = typeof value === "number" ? new Date(value) : new Date(value);
1438
- if (Number.isNaN(d.getTime())) return String(value);
1439
- return d.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
1440
- }
1441
- var DEFAULT_LABELS5 = {
1442
- loading: "Loading\u2026",
1443
- unavailable: "This flash sale isn\u2019t available.",
1595
+ function EventOrders({
1596
+ brandId,
1597
+ title = "Event orders",
1598
+ empty = "No event orders."
1599
+ }) {
1600
+ const orders = useMyEventOrders({ brandId });
1601
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title, children: [
1602
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...orders }),
1603
+ orders.data?.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { children: empty }),
1604
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: orders.data?.map((row) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
1605
+ row.displayId,
1606
+ " \u2014 ",
1607
+ row.eventName,
1608
+ " \u2014 ",
1609
+ row.quantity,
1610
+ " \u2014 ",
1611
+ row.status
1612
+ ] }, row.id)) })
1613
+ ] });
1614
+ }
1615
+ function PackageOrders({
1616
+ brandId,
1617
+ title = "Package orders",
1618
+ empty = "No package orders."
1619
+ }) {
1620
+ const orders = useMyPackageOrders({ brandId });
1621
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title, children: [
1622
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...orders }),
1623
+ orders.data?.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { children: empty }),
1624
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: orders.data?.map((row) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
1625
+ row.displayId,
1626
+ " \u2014 ",
1627
+ row.packageName,
1628
+ " \u2014 ",
1629
+ formatCents(row.grandTotalCents),
1630
+ " \u2014 ",
1631
+ row.status
1632
+ ] }, row.id)) })
1633
+ ] });
1634
+ }
1635
+ function GameCards({
1636
+ brandId,
1637
+ unitNoun = "games",
1638
+ title = "Game cards",
1639
+ historyLabel = "History",
1640
+ closeHistoryLabel = "Close history",
1641
+ empty = "No game cards."
1642
+ }) {
1643
+ const cards = useMyGameCards({ brandId });
1644
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title, children: [
1645
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...cards }),
1646
+ cards.data?.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { children: empty }),
1647
+ cards.data?.map((card) => /* @__PURE__ */ jsxRuntime.jsxs("article", { children: [
1648
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { children: card.cardName }),
1649
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
1650
+ card.remainingGames,
1651
+ " ",
1652
+ unitNoun
1653
+ ] }),
1654
+ /* @__PURE__ */ jsxRuntime.jsx(
1655
+ HistoryDrawer,
1656
+ {
1657
+ brandId,
1658
+ id: card.id,
1659
+ unitNoun,
1660
+ label: historyLabel,
1661
+ closeLabel: closeHistoryLabel
1662
+ }
1663
+ ),
1664
+ /* @__PURE__ */ jsxRuntime.jsx(
1665
+ AddToWalletButtons,
1666
+ {
1667
+ brandId,
1668
+ kind: "game_card",
1669
+ id: card.id,
1670
+ eligible: card.status === "active"
1671
+ }
1672
+ )
1673
+ ] }, card.id))
1674
+ ] });
1675
+ }
1676
+ function HistoryDrawer({
1677
+ brandId,
1678
+ id,
1679
+ unitNoun,
1680
+ label,
1681
+ closeLabel
1682
+ }) {
1683
+ const [open, setOpen] = react.useState(false);
1684
+ const dialogRef = react.useRef(null);
1685
+ react.useEffect(() => {
1686
+ if (!open) return;
1687
+ const dialog = dialogRef.current;
1688
+ dialog?.showModal();
1689
+ return () => {
1690
+ if (dialog?.open) dialog.close();
1691
+ };
1692
+ }, [open]);
1693
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1694
+ /* @__PURE__ */ jsxRuntime.jsx(
1695
+ "button",
1696
+ {
1697
+ style: styles().ghostBtn,
1698
+ "aria-haspopup": "dialog",
1699
+ "aria-expanded": open,
1700
+ onClick: () => setOpen(true),
1701
+ children: label
1702
+ }
1703
+ ),
1704
+ open && /* @__PURE__ */ jsxRuntime.jsxs(
1705
+ "dialog",
1706
+ {
1707
+ ref: dialogRef,
1708
+ "aria-label": label,
1709
+ onCancel: () => setOpen(false),
1710
+ style: {
1711
+ ...styles().panel,
1712
+ position: "fixed",
1713
+ marginRight: 0,
1714
+ width: "min(420px, 90vw)",
1715
+ maxHeight: "90vh",
1716
+ overflow: "auto"
1717
+ },
1718
+ children: [
1719
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().ghostBtn, "aria-label": closeLabel, onClick: () => setOpen(false), children: "\xD7" }),
1720
+ /* @__PURE__ */ jsxRuntime.jsx(GameCardHistory, { brandId, gameCardId: id, unitNoun })
1721
+ ]
1722
+ }
1723
+ )
1724
+ ] });
1725
+ }
1726
+ function ProfileForm({ brandId, labels, className }) {
1727
+ const t = {
1728
+ title: "Profile",
1729
+ name: "Name",
1730
+ mobile: "Mobile",
1731
+ save: "Save profile",
1732
+ saved: "Profile saved.",
1733
+ reload: "Reload profile",
1734
+ missingVersion: "Reload your account to load the current profile version.",
1735
+ ...labels
1736
+ };
1737
+ const account = useAccount();
1738
+ const update = useUpdateMyProfile();
1739
+ const action = useAccountAction();
1740
+ const [fullName, setName] = react.useState(account.customer?.fullName ?? "");
1741
+ const [mobile, setMobile] = react.useState(account.customer?.mobile ?? "");
1742
+ const [version, setVersion] = react.useState(
1743
+ typeof account.customer?.version === "number" ? account.customer.version : void 0
1744
+ );
1745
+ react.useEffect(() => {
1746
+ if (typeof account.customer?.version === "number") setVersion(account.customer.version);
1747
+ }, [account.customer?.version]);
1748
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
1749
+ /* @__PURE__ */ jsxRuntime.jsxs(
1750
+ "form",
1751
+ {
1752
+ style: styles().stack,
1753
+ onSubmit: (e) => {
1754
+ e.preventDefault();
1755
+ if (version === void 0) return;
1756
+ void action.run(async () => {
1757
+ const result = await update.run({
1758
+ brandId,
1759
+ expectedVersion: version,
1760
+ fullName,
1761
+ mobile: mobile || null
1762
+ });
1763
+ setVersion(result.version);
1764
+ }, t.saved);
1765
+ },
1766
+ children: [
1767
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
1768
+ t.name,
1769
+ /* @__PURE__ */ jsxRuntime.jsx(
1770
+ "input",
1771
+ {
1772
+ style: styles().input,
1773
+ required: true,
1774
+ autoComplete: "name",
1775
+ value: fullName,
1776
+ onChange: (e) => setName(e.target.value)
1777
+ }
1778
+ )
1779
+ ] }),
1780
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
1781
+ t.mobile,
1782
+ /* @__PURE__ */ jsxRuntime.jsx(
1783
+ "input",
1784
+ {
1785
+ style: styles().input,
1786
+ type: "tel",
1787
+ autoComplete: "tel",
1788
+ value: mobile,
1789
+ onChange: (e) => setMobile(e.target.value)
1790
+ }
1791
+ )
1792
+ ] }),
1793
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().primaryBtn, disabled: action.busy || version === void 0, children: t.save }),
1794
+ version === void 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: t.missingVersion })
1795
+ ]
1796
+ }
1797
+ ),
1798
+ /* @__PURE__ */ jsxRuntime.jsx(
1799
+ "button",
1800
+ {
1801
+ style: styles().ghostBtn,
1802
+ disabled: action.busy,
1803
+ onClick: () => void action.run(async () => {
1804
+ await account.refresh();
1805
+ }),
1806
+ children: t.reload
1807
+ }
1808
+ ),
1809
+ action.feedback
1810
+ ] });
1811
+ }
1812
+ function CommunicationPrefs({ brandId, labels, className }) {
1813
+ const t = {
1814
+ title: "Communications",
1815
+ email: "Email marketing",
1816
+ sms: "SMS marketing",
1817
+ transactional: "Booking confirmations and receipts are sent independently of marketing preferences.",
1818
+ consent: "I agree to receive marketing messages for this channel.",
1819
+ ...labels
1820
+ };
1821
+ const prefs = useMyCommunicationPrefs({ brandId });
1822
+ const update = useSetMyCommunicationPref();
1823
+ const action = useAccountAction();
1824
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
1825
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...prefs }),
1826
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: t.transactional }),
1827
+ prefs.data && ["email", "sms"].map((channel) => /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
1828
+ /* @__PURE__ */ jsxRuntime.jsx(
1829
+ "input",
1830
+ {
1831
+ style: styles().input,
1832
+ type: "checkbox",
1833
+ checked: prefs.data?.[channel].status === "subscribed",
1834
+ disabled: action.busy,
1835
+ onChange: (e) => {
1836
+ const subscribed = e.target.checked;
1837
+ void action.run(async () => {
1838
+ await update.run({
1839
+ brandId,
1840
+ channel,
1841
+ status: subscribed ? "subscribed" : "unsubscribed",
1842
+ acceptedTerms: subscribed
1843
+ });
1844
+ await prefs.refetch();
1845
+ });
1846
+ }
1847
+ }
1848
+ ),
1849
+ t[channel],
1850
+ " \u2014 ",
1851
+ t.consent
1852
+ ] }, channel)),
1853
+ action.feedback
1854
+ ] });
1855
+ }
1856
+ function MyWaitlist({ brandId, centerId }) {
1857
+ const rows = useBowlosQuery(
1858
+ "listMyWaitlist",
1859
+ { brandId, centerId },
1860
+ { auth: true }
1861
+ );
1862
+ const leave = useBowlosMutation("leaveWaitlist", {
1863
+ auth: true
1864
+ });
1865
+ const action = useAccountAction();
1866
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: "Pending \u2014 waitlist", children: [
1867
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...rows, loadingLabel: "Loading\u2026" }),
1868
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: rows.data?.filter((e) => e.status === "waiting" || e.status === "pending_card").map((e) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
1869
+ e.product,
1870
+ " \u2014 ",
1871
+ e.dateISO,
1872
+ " \u2014 ",
1873
+ formatCents(e.amountCents),
1874
+ " \u2014",
1875
+ " ",
1876
+ e.status === "pending_card" ? "Card required" : "Card on file",
1877
+ /* @__PURE__ */ jsxRuntime.jsx(
1878
+ "button",
1879
+ {
1880
+ disabled: action.busy,
1881
+ onClick: () => void action.run(async () => {
1882
+ await leave.run({ brandId, centerId, entryId: e.entryId });
1883
+ await rows.refetch();
1884
+ }, "Removed from waitlist \u2014 not charged."),
1885
+ children: "Leave"
1886
+ }
1887
+ )
1888
+ ] }, e.entryId)) }),
1889
+ action.feedback
1890
+ ] });
1891
+ }
1892
+ function SavedCards({
1893
+ brandId,
1894
+ centerId,
1895
+ labels,
1896
+ renderAddCard,
1897
+ className
1898
+ }) {
1899
+ const t = {
1900
+ title: "Payment methods",
1901
+ empty: "No saved cards.",
1902
+ remove: "Remove",
1903
+ makeDefault: "Make default",
1904
+ default: "Default",
1905
+ loading: "Loading\u2026",
1906
+ ...labels
1907
+ };
1908
+ const scope = { brandId, centerId };
1909
+ const cards = useSavedCards(scope);
1910
+ const remove = useRemoveCard();
1911
+ const setDefault = useSetDefaultCard();
1912
+ const action = useAccountAction();
1913
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
1914
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...cards, loadingLabel: t.loading }),
1915
+ cards.data?.methods.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { children: t.empty }),
1916
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: cards.data?.methods.map((card) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
1917
+ card.brand,
1918
+ " \u2022\u2022\u2022\u2022 ",
1919
+ card.last4,
1920
+ " (",
1921
+ card.expMonth,
1922
+ "/",
1923
+ card.expYear,
1924
+ ")",
1925
+ " ",
1926
+ card.isDefault && /* @__PURE__ */ jsxRuntime.jsx("span", { children: t.default }),
1927
+ /* @__PURE__ */ jsxRuntime.jsx(
1928
+ "button",
1929
+ {
1930
+ style: styles().ghostBtn,
1931
+ disabled: action.busy,
1932
+ "aria-label": `${t.remove} ${card.last4}`,
1933
+ onClick: () => void action.run(async () => {
1934
+ await remove.run({ ...scope, paymentMethodId: card.id });
1935
+ await cards.refetch();
1936
+ }),
1937
+ children: t.remove
1938
+ }
1939
+ ),
1940
+ !card.isDefault && /* @__PURE__ */ jsxRuntime.jsx(
1941
+ "button",
1942
+ {
1943
+ style: styles().ghostBtn,
1944
+ disabled: action.busy,
1945
+ "aria-label": `${t.makeDefault} ${card.last4}`,
1946
+ onClick: () => void action.run(async () => {
1947
+ await setDefault.run({ ...scope, paymentMethodId: card.id });
1948
+ await cards.refetch();
1949
+ }),
1950
+ children: t.makeDefault
1951
+ }
1952
+ )
1953
+ ] }, card.id)) }),
1954
+ action.feedback,
1955
+ renderAddCard?.(() => void cards.refetch())
1956
+ ] });
1957
+ }
1958
+ function ChangePasswordForm({ labels, className }) {
1959
+ const t = {
1960
+ title: "Security",
1961
+ currentPassword: "Current password",
1962
+ newPassword: "New password",
1963
+ save: "Change password",
1964
+ forgot: "Forgot your current password?",
1965
+ code: "Email code",
1966
+ reset: "Reset password",
1967
+ sent: "Check your email for a reset code.",
1968
+ success: "Password changed. Sign in again.",
1969
+ ...labels
1970
+ };
1971
+ const account = useAccount();
1972
+ const change = useChangePassword();
1973
+ const action = useAccountAction();
1974
+ const [currentPassword, setCurrent] = react.useState("");
1975
+ const [newPassword, setNew] = react.useState("");
1976
+ const [code, setCode] = react.useState("");
1977
+ const [recovery, setRecovery] = react.useState(false);
1978
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
1979
+ /* @__PURE__ */ jsxRuntime.jsxs(
1980
+ "form",
1981
+ {
1982
+ style: styles().stack,
1983
+ onSubmit: (e) => {
1984
+ e.preventDefault();
1985
+ void action.run(async () => {
1986
+ if (recovery)
1987
+ await account.resetPassword(account.customer?.email ?? "", code, newPassword);
1988
+ else await change.run({ currentPassword, newPassword });
1989
+ setCurrent("");
1990
+ setNew("");
1991
+ }, t.success);
1992
+ },
1993
+ children: [
1994
+ recovery ? /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
1995
+ t.code,
1996
+ /* @__PURE__ */ jsxRuntime.jsx(
1997
+ "input",
1998
+ {
1999
+ style: styles().input,
2000
+ autoFocus: true,
2001
+ required: true,
2002
+ value: code,
2003
+ onChange: (e) => setCode(e.target.value),
2004
+ autoComplete: "one-time-code"
2005
+ }
2006
+ )
2007
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
2008
+ t.currentPassword,
2009
+ /* @__PURE__ */ jsxRuntime.jsx(
2010
+ "input",
2011
+ {
2012
+ style: styles().input,
2013
+ required: true,
2014
+ type: "password",
2015
+ autoComplete: "current-password",
2016
+ value: currentPassword,
2017
+ onChange: (e) => setCurrent(e.target.value)
2018
+ }
2019
+ )
2020
+ ] }),
2021
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
2022
+ t.newPassword,
2023
+ /* @__PURE__ */ jsxRuntime.jsx(
2024
+ "input",
2025
+ {
2026
+ style: styles().input,
2027
+ required: true,
2028
+ type: "password",
2029
+ autoComplete: "new-password",
2030
+ value: newPassword,
2031
+ onChange: (e) => setNew(e.target.value)
2032
+ }
2033
+ )
2034
+ ] }),
2035
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().primaryBtn, disabled: action.busy, children: recovery ? t.reset : t.save })
2036
+ ]
2037
+ }
2038
+ ),
2039
+ /* @__PURE__ */ jsxRuntime.jsx(
2040
+ "a",
2041
+ {
2042
+ href: "#password-recovery",
2043
+ onClick: (e) => {
2044
+ e.preventDefault();
2045
+ void action.run(async () => {
2046
+ await account.requestPasswordReset(account.customer?.email ?? "");
2047
+ setRecovery(true);
2048
+ }, t.sent);
2049
+ },
2050
+ children: t.forgot
2051
+ }
2052
+ ),
2053
+ action.feedback
2054
+ ] });
2055
+ }
2056
+
2057
+ // src/routes.ts
2058
+ async function deleteMyAccount(client, args) {
2059
+ const result = await client.call("deleteMyAccount", args, {
2060
+ auth: true
2061
+ });
2062
+ await client.signOut();
2063
+ return result;
2064
+ }
2065
+ function previewAccountDeletion(client, args) {
2066
+ return client.call("previewMyAccountDeletion", args, { auth: true });
2067
+ }
2068
+
2069
+ // src/use-account-deletion.ts
2070
+ function useAccountDeletion(args) {
2071
+ const client = useBowlosClient();
2072
+ const [preview, setPreview] = react.useState();
2073
+ const [status, setStatus] = react.useState("loading");
2074
+ const [error, setError] = react.useState();
2075
+ const generation = react.useRef(0);
2076
+ const busy = react.useRef(false);
2077
+ const phrase = react.useRef(void 0);
2078
+ const timer = react.useRef(void 0);
2079
+ const wake = react.useRef(void 0);
2080
+ const reload = react.useCallback(async () => {
2081
+ const current = generation.current;
2082
+ const value = await previewAccountDeletion(client, { brandId: args.brandId });
2083
+ if (generation.current === current) setPreview(value);
2084
+ return value;
2085
+ }, [client, args.brandId]);
2086
+ react.useEffect(() => {
2087
+ const current = ++generation.current;
2088
+ busy.current = false;
2089
+ phrase.current = void 0;
2090
+ setPreview(void 0);
2091
+ setError(void 0);
2092
+ setStatus("loading");
2093
+ void previewAccountDeletion(client, { brandId: args.brandId }).then(
2094
+ (value) => {
2095
+ if (generation.current === current) {
2096
+ setPreview(value);
2097
+ setStatus("ready");
2098
+ }
2099
+ },
2100
+ (e) => {
2101
+ if (generation.current === current) {
2102
+ setError(e);
2103
+ setStatus("error");
2104
+ }
2105
+ }
2106
+ );
2107
+ return () => {
2108
+ generation.current++;
2109
+ clearTimeout(timer.current);
2110
+ wake.current?.();
2111
+ };
2112
+ }, [client, args.brandId]);
2113
+ const confirm = react.useCallback(
2114
+ async (typedPhrase) => {
2115
+ if (busy.current || !preview) return;
2116
+ if (typedPhrase !== preview.confirmPhrase) {
2117
+ setError(
2118
+ new BowlosApiError("VALIDATION_FAILED", "Enter the confirmation phrase exactly.", 400)
2119
+ );
2120
+ return;
2121
+ }
2122
+ busy.current = true;
2123
+ phrase.current = typedPhrase;
2124
+ const current = generation.current;
2125
+ setError(void 0);
2126
+ setStatus("deleting");
2127
+ try {
2128
+ for (let attempt = 0; attempt <= 5; attempt++) {
2129
+ if (generation.current !== current) return;
2130
+ try {
2131
+ await deleteMyAccount(client, {
2132
+ brandId: args.brandId,
2133
+ confirmPhrase: typedPhrase,
2134
+ previewToken: preview.previewToken
2135
+ });
2136
+ if (generation.current === current) setStatus("deleted");
2137
+ return;
2138
+ } catch (e) {
2139
+ if (generation.current !== current) return;
2140
+ if (e instanceof BowlosApiError && e.code === "DELETION_PREVIEW_STALE") {
2141
+ await reload();
2142
+ if (generation.current === current) {
2143
+ setError(e);
2144
+ setStatus("stale");
2145
+ }
2146
+ return;
2147
+ }
2148
+ if (!(e instanceof BowlosApiError) || e.code !== "DELETION_PENDING_STRIPE") throw e;
2149
+ setStatus("pending");
2150
+ if (attempt === 5) {
2151
+ setError(e);
2152
+ return;
2153
+ }
2154
+ const seconds = e.details?.retryAfterSec;
2155
+ const delay = typeof seconds === "number" && seconds >= 0 ? seconds * 1e3 : 1e3;
2156
+ await new Promise((resolve) => {
2157
+ wake.current = resolve;
2158
+ timer.current = setTimeout(resolve, Math.min(delay * 2 ** attempt, 2147483647));
2159
+ });
2160
+ }
2161
+ }
2162
+ } catch (e) {
2163
+ if (generation.current === current) {
2164
+ setError(e);
2165
+ setStatus("error");
2166
+ }
2167
+ } finally {
2168
+ if (generation.current === current) busy.current = false;
2169
+ }
2170
+ },
2171
+ [client, args.brandId, preview, reload]
2172
+ );
2173
+ const retry = react.useCallback(async () => {
2174
+ if (phrase.current && preview && status !== "stale") await confirm(phrase.current);
2175
+ else {
2176
+ try {
2177
+ await reload();
2178
+ setError(void 0);
2179
+ setStatus("ready");
2180
+ } catch (e) {
2181
+ setError(e);
2182
+ setStatus("error");
2183
+ }
2184
+ }
2185
+ }, [confirm, preview, reload, status]);
2186
+ return {
2187
+ preview,
2188
+ consequences: preview,
2189
+ confirmPhrase: preview?.confirmPhrase,
2190
+ status,
2191
+ error,
2192
+ confirm,
2193
+ retry
2194
+ };
2195
+ }
2196
+ function PrivacyCenter({
2197
+ brandId,
2198
+ supportHref = "/contact",
2199
+ labels,
2200
+ className
2201
+ }) {
2202
+ const t = {
2203
+ cancelRenewal: "Renewal will be cancelled",
2204
+ membershipEnds: "Membership will end",
2205
+ forfeits: "Remaining time forfeited",
2206
+ refund: "refund",
2207
+ credit: "credit",
2208
+ fee: "fee",
2209
+ title: "Privacy",
2210
+ export: "Export my data",
2211
+ download: "Download export",
2212
+ confirm: "Type {phrase} to delete your account",
2213
+ delete: "Delete my account",
2214
+ retry: "Retry",
2215
+ support: "Contact support",
2216
+ loading: "Loading consequences\u2026",
2217
+ deleted: "Account deleted.",
2218
+ pending: "Cancellation is still processing. Retry or contact support.",
2219
+ stale: "Consequences changed. Review them and type the phrase again.",
2220
+ ...labels
2221
+ };
2222
+ const deletion = useAccountDeletion({ brandId });
2223
+ const exporter = useBowlosMutation("exportMyDataV2", {
2224
+ auth: true
2225
+ });
2226
+ const action = useAccountAction();
2227
+ const [typed, setTyped] = react.useState("");
2228
+ react.useEffect(() => {
2229
+ setTyped("");
2230
+ }, [deletion.preview?.previewToken]);
2231
+ const busy = deletion.status === "deleting" || deletion.status === "loading";
2232
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
2233
+ /* @__PURE__ */ jsxRuntime.jsx(
2234
+ "button",
2235
+ {
2236
+ style: styles().ghostBtn,
2237
+ disabled: action.busy,
2238
+ onClick: () => void action.run(() => exporter.run({ brandId })),
2239
+ children: t.export
2240
+ }
2241
+ ),
2242
+ exporter.data && /* @__PURE__ */ jsxRuntime.jsx("a", { href: exporter.data.url, children: t.download }),
2243
+ action.feedback,
2244
+ /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", children: deletion.status === "loading" ? t.loading : deletion.status === "deleted" ? t.deleted : deletion.status === "pending" ? t.pending : deletion.status === "stale" ? t.stale : "" }),
2245
+ deletion.preview && deletion.status !== "deleted" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2246
+ /* @__PURE__ */ jsxRuntime.jsxs("ul", { children: [
2247
+ deletion.preview.memberships.map((m) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
2248
+ m.name,
2249
+ " \u2014 ",
2250
+ m.status,
2251
+ " \u2014 ",
2252
+ m.willCancelStripe ? t.cancelRenewal : t.membershipEnds,
2253
+ m.forfeitsRemainingTime && ` \u2014 ${t.forfeits}`
2254
+ ] }, m.id)),
2255
+ deletion.preview.upcoming.map((item) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
2256
+ item.displayId,
2257
+ " \u2014 ",
2258
+ item.date,
2259
+ " \u2014 ",
2260
+ item.centerName,
2261
+ ":",
2262
+ " ",
2263
+ formatCents(item.refundPreview.refundCents),
2264
+ " ",
2265
+ t.refund,
2266
+ ",",
2267
+ " ",
2268
+ formatCents(item.refundPreview.creditCents),
2269
+ " ",
2270
+ t.credit,
2271
+ ",",
2272
+ " ",
2273
+ formatCents(item.refundPreview.feeCents),
2274
+ " ",
2275
+ t.fee,
2276
+ " \u2014",
2277
+ " ",
2278
+ item.refundPreview.policyLabel
2279
+ ] }, item.id)),
2280
+ deletion.preview.loses.map((item) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: item }, item))
2281
+ ] }),
2282
+ /* @__PURE__ */ jsxRuntime.jsxs(
2283
+ "form",
2284
+ {
2285
+ onSubmit: (e) => {
2286
+ e.preventDefault();
2287
+ void deletion.confirm(typed);
2288
+ },
2289
+ children: [
2290
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
2291
+ t.confirm.replace("{phrase}", deletion.confirmPhrase ?? ""),
2292
+ /* @__PURE__ */ jsxRuntime.jsx(
2293
+ "input",
2294
+ {
2295
+ style: styles().input,
2296
+ required: true,
2297
+ autoCorrect: "off",
2298
+ autoComplete: "off",
2299
+ spellCheck: false,
2300
+ autoCapitalize: "none",
2301
+ value: typed,
2302
+ onChange: (e) => setTyped(e.target.value)
2303
+ }
2304
+ )
2305
+ ] }),
2306
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().primaryBtn, disabled: busy || typed !== deletion.confirmPhrase, children: t.delete })
2307
+ ]
2308
+ }
2309
+ )
2310
+ ] }),
2311
+ deletion.error != null && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: deletion.error instanceof Error ? deletion.error.message : t.pending }),
2312
+ deletion.status !== "deleted" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2313
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().ghostBtn, disabled: busy, onClick: () => void deletion.retry(), children: t.retry }),
2314
+ /* @__PURE__ */ jsxRuntime.jsx("a", { href: supportHref, children: t.support })
2315
+ ] })
2316
+ ] });
2317
+ }
2318
+ var DEFAULT_LABELS4 = {
2319
+ welcome: "Welcome, {name}",
2320
+ signOut: "Sign out",
2321
+ reservations: "Reservations",
2322
+ memberships: "Memberships",
2323
+ loyalty: "Loyalty",
2324
+ credits: "Account credit",
2325
+ passes: "Passes",
2326
+ loading: "Loading\u2026",
2327
+ loadError: "Couldn\u2019t load",
2328
+ noReservations: "No reservations yet.",
2329
+ noMemberships: "No memberships yet.",
2330
+ noCredits: "No credit activity yet.",
2331
+ noPasses: "No passes yet.",
2332
+ balance: "Balance",
2333
+ pointsSuffix: "points",
2334
+ toNextTier: "{points} points to {tier}",
2335
+ noTier: "Not yet ranked",
2336
+ renews: "Renews",
2337
+ autoRenews: "Auto-renews",
2338
+ balanceDue: "Balance due"
2339
+ };
2340
+ var ALL_SECTIONS = [
2341
+ "reservations",
2342
+ "memberships",
2343
+ "loyalty",
2344
+ "credits",
2345
+ "passes"
2346
+ ];
2347
+ function AccountDashboard({
2348
+ brandId,
2349
+ sections = ALL_SECTIONS,
2350
+ labels,
2351
+ className,
2352
+ centerId,
2353
+ unitNoun,
2354
+ supportHref
2355
+ }) {
2356
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthGate, { labels, className, children: ({ customer, account }) => /* @__PURE__ */ jsxRuntime.jsx(
2357
+ Dashboard,
2358
+ {
2359
+ centerId,
2360
+ unitNoun,
2361
+ supportHref,
2362
+ brandId,
2363
+ sections,
2364
+ labels,
2365
+ className,
2366
+ customerName: customer.fullName,
2367
+ onSignOut: () => void account.signOut()
2368
+ }
2369
+ ) });
2370
+ }
2371
+ function Dashboard({
2372
+ brandId,
2373
+ centerId,
2374
+ unitNoun,
2375
+ supportHref,
2376
+ sections,
2377
+ labels,
2378
+ className,
2379
+ customerName,
2380
+ onSignOut
2381
+ }) {
2382
+ const t = { ...DEFAULT_LABELS4, ...labels };
2383
+ const s = styles();
2384
+ const show = (k) => sections.includes(k);
2385
+ const reservations = useMyReservations(
2386
+ { brandId },
2387
+ { enabled: show("reservations") }
2388
+ );
2389
+ const memberships = useMyMemberships(
2390
+ { brandId },
2391
+ { enabled: show("memberships") }
2392
+ );
2393
+ const loyalty = useMyLoyalty({ brandId }, { enabled: show("loyalty") });
2394
+ const credits = useMyCredits({ brandId }, { enabled: show("credits") });
2395
+ const passes = useMyPasses({ brandId }, { enabled: show("passes") });
2396
+ const firstName = customerName.split(" ")[0] || customerName;
2397
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.stack, children: [
2398
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
2399
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: s.heading, children: t.welcome.replace("{name}", firstName) }),
2400
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.ghostBtn, onClick: onSignOut, children: t.signOut })
2401
+ ] }),
2402
+ sections.map((section) => {
2403
+ switch (section) {
2404
+ case "reservations":
2405
+ 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: [
2406
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2407
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: r.displayId }),
2408
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listMeta, children: [
2409
+ r.dateISO,
2410
+ " \xB7 ",
2411
+ minutesToTime(r.startMinuteOfDay),
2412
+ "\u2013",
2413
+ minutesToTime(r.endMinuteOfDay)
2414
+ ] })
2415
+ ] }),
2416
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "right" }, children: [
2417
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: formatCents(r.finalCents) }),
2418
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: r.balanceDue ? t.balanceDue : /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: r.status }) })
2419
+ ] })
2420
+ ] }, r.id)) }) }, section);
2421
+ case "memberships":
2422
+ 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: [
2423
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2424
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: m.templateName }),
2425
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listMeta, children: [
2426
+ t.renews,
2427
+ " ",
2428
+ formatDate(m.currentPeriodEndsAt),
2429
+ m.autoRenews ? ` \xB7 ${t.autoRenews}` : ""
2430
+ ] })
2431
+ ] }),
2432
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "right" }, children: [
2433
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: formatCents(m.recurringPriceCents) }),
2434
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: m.status }) })
2435
+ ] })
2436
+ ] }, m.id)) }) }, section);
2437
+ case "loyalty":
2438
+ return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.loyalty, q: loyalty, t, children: (l) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
2439
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2440
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: l.currentTierName ?? t.noTier }),
2441
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: l.nextTierName ? t.toNextTier.replace("{points}", String(l.pointsToNextTier)).replace("{tier}", l.nextTierName) : "" })
2442
+ ] }),
2443
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.priceSale, children: [
2444
+ l.yearPoints,
2445
+ " ",
2446
+ t.pointsSuffix
2447
+ ] })
2448
+ ] }) }, section);
2449
+ case "credits":
2450
+ return /* @__PURE__ */ jsxRuntime.jsx(Section, { title: t.credits, q: credits, t, children: (c) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2451
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.rowBetween, children: [
2452
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.listMeta, children: t.balance }),
2453
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.priceSale, children: formatCents(c.balanceCents) })
2454
+ ] }),
2455
+ 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: [
2456
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2457
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: e.note || e.entryType }),
2458
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: formatDate(e.createdAt) })
2459
+ ] }),
2460
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.listTitle, children: [
2461
+ e.amountCents >= 0 ? "+" : "\u2212",
2462
+ formatCents(Math.abs(e.amountCents))
2463
+ ] })
2464
+ ] }, e.id))
2465
+ ] }) }, section);
2466
+ case "passes":
2467
+ 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: [
2468
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: p.kind }),
2469
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: p.state })
2470
+ ] }, p.id)) }) }, section);
2471
+ case "waitlist":
2472
+ return /* @__PURE__ */ jsxRuntime.jsx(MyWaitlist, { brandId, centerId }, section);
2473
+ case "eventOrders":
2474
+ return /* @__PURE__ */ jsxRuntime.jsx(EventOrders, { brandId, title: labels?.eventOrders }, section);
2475
+ case "packageOrders":
2476
+ return /* @__PURE__ */ jsxRuntime.jsx(PackageOrders, { brandId, title: labels?.packageOrders }, section);
2477
+ case "gameCards":
2478
+ return /* @__PURE__ */ jsxRuntime.jsx(
2479
+ GameCards,
2480
+ {
2481
+ brandId,
2482
+ unitNoun,
2483
+ title: labels?.gameCards,
2484
+ historyLabel: labels?.history,
2485
+ closeHistoryLabel: labels?.closeHistory
2486
+ },
2487
+ section
2488
+ );
2489
+ case "profile":
2490
+ return /* @__PURE__ */ jsxRuntime.jsx(
2491
+ ProfileForm,
2492
+ {
2493
+ labels: { title: labels?.profile ?? "Profile" },
2494
+ brandId
2495
+ },
2496
+ section
2497
+ );
2498
+ case "communications":
2499
+ return /* @__PURE__ */ jsxRuntime.jsx(
2500
+ CommunicationPrefs,
2501
+ {
2502
+ labels: { title: labels?.communications ?? "Communications" },
2503
+ brandId
2504
+ },
2505
+ section
2506
+ );
2507
+ case "paymentMethods":
2508
+ return centerId ? /* @__PURE__ */ jsxRuntime.jsx(
2509
+ SavedCards,
2510
+ {
2511
+ labels: { title: labels?.paymentMethods ?? "Payment methods" },
2512
+ brandId,
2513
+ centerId
2514
+ },
2515
+ section
2516
+ ) : /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: "Select a center to manage payment methods." }, section);
2517
+ case "security":
2518
+ return /* @__PURE__ */ jsxRuntime.jsx(
2519
+ ChangePasswordForm,
2520
+ {
2521
+ labels: { title: labels?.security ?? "Security" }
2522
+ },
2523
+ section
2524
+ );
2525
+ case "privacy":
2526
+ return /* @__PURE__ */ jsxRuntime.jsx(
2527
+ PrivacyCenter,
2528
+ {
2529
+ labels: { title: labels?.privacy ?? "Privacy" },
2530
+ brandId,
2531
+ supportHref
2532
+ },
2533
+ section
2534
+ );
2535
+ default:
2536
+ return null;
2537
+ }
2538
+ })
2539
+ ] });
2540
+ }
2541
+ function Section({
2542
+ title,
2543
+ q,
2544
+ t,
2545
+ children
2546
+ }) {
2547
+ const s = styles();
2548
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { style: s.panel, children: [
2549
+ /* @__PURE__ */ jsxRuntime.jsx("h4", { style: s.sectionTitle, children: title }),
2550
+ q.loading ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading }) : q.error ? /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.error, children: [
2551
+ t.loadError,
2552
+ " (",
2553
+ q.error.code,
2554
+ ")"
2555
+ ] }) : q.data == null ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading }) : children(q.data)
2556
+ ] });
2557
+ }
2558
+ function formatDate(value) {
2559
+ const d = typeof value === "number" ? new Date(value) : new Date(value);
2560
+ if (Number.isNaN(d.getTime())) return String(value);
2561
+ return d.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
2562
+ }
2563
+ var DEFAULT_LABELS5 = {
2564
+ loading: "Loading\u2026",
2565
+ unavailable: "This flash sale isn\u2019t available.",
1444
2566
  ended: "This flash sale has ended.",
1445
2567
  endsIn: "Ends in {time}",
1446
2568
  lockedPrice: "\u{1F512} Sign in to see the flash price",
@@ -1984,20 +3106,804 @@ function PricingTable({
1984
3106
  }
1985
3107
  );
1986
3108
  }
3109
+ function EventList({ items, loading, error, labels, children, className }) {
3110
+ const text = {
3111
+ title: "Events",
3112
+ empty: "No upcoming events.",
3113
+ loading: "Loading events\u2026",
3114
+ error: "Unable to load events.",
3115
+ ...labels
3116
+ };
3117
+ const sorted = [...items].sort(
3118
+ (a, b) => a.date.localeCompare(b.date) || (a.startMinuteOfDay ?? 0) - (b.startMinuteOfDay ?? 0) || a.title.localeCompare(b.title)
3119
+ );
3120
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3121
+ "section",
3122
+ {
3123
+ className,
3124
+ "aria-label": text.title,
3125
+ "aria-busy": loading,
3126
+ style: { color: token("colorText"), fontFamily: token("fontFamily") },
3127
+ children: [
3128
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { children: text.title }),
3129
+ loading && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", children: text.loading }),
3130
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", style: { color: token("colorError") }, children: text.error }),
3131
+ !loading && !error && sorted.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { children: text.empty }),
3132
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: sorted.map((item) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: children ? children(item) : /* @__PURE__ */ jsxRuntime.jsxs(
3133
+ "a",
3134
+ {
3135
+ style: { color: token("colorPrimary") },
3136
+ href: `/events/${encodeURIComponent(item.slug)}`,
3137
+ children: [
3138
+ item.title,
3139
+ " \u2014 ",
3140
+ /* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: item.date, children: item.date })
3141
+ ]
3142
+ }
3143
+ ) }, item.id)) })
3144
+ ]
3145
+ }
3146
+ );
3147
+ }
3148
+
3149
+ // src/booking-change.ts
3150
+ function previewBookingChange(client, args) {
3151
+ return client.call("previewMyModification", args, { auth: true });
3152
+ }
3153
+ function getPendingBookingChange(client, args) {
3154
+ return client.call("getMyPendingModification", args, { auth: true });
3155
+ }
3156
+ function createBookingChangePayment(client, args) {
3157
+ const { pendingModificationId, brandId, centerId } = args;
3158
+ return client.call(
3159
+ "createModificationPaymentIntent",
3160
+ { pendingModificationId, brandId, centerId },
3161
+ { auth: true }
3162
+ );
3163
+ }
3164
+
3165
+ // src/use-booking-change.ts
3166
+ function useOpenMembershipBillingPortal() {
3167
+ return useBowlosMutation(
3168
+ "createBillingPortalSession",
3169
+ { auth: true }
3170
+ );
3171
+ }
3172
+ function useBookingChange(scope) {
3173
+ const client = useBowlosClient();
3174
+ const applyMutation = useIdempotentMutation(
3175
+ "applyMyModification",
3176
+ { auth: true }
3177
+ );
3178
+ const [status, setStatus] = react.useState("idle");
3179
+ const [preview, setPreview] = react.useState();
3180
+ const [payment, setPayment] = react.useState();
3181
+ const [pending, setPending] = react.useState();
3182
+ const [pendingId, setPendingId] = react.useState();
3183
+ const [error, setError] = react.useState();
3184
+ const generation = react.useRef(0);
3185
+ const busy = react.useRef(false);
3186
+ const reset = react.useCallback(() => {
3187
+ generation.current++;
3188
+ busy.current = false;
3189
+ setStatus("idle");
3190
+ setPreview(void 0);
3191
+ setPayment(void 0);
3192
+ setPending(void 0);
3193
+ setPendingId(void 0);
3194
+ setError(void 0);
3195
+ applyMutation.reset();
3196
+ }, [applyMutation.reset]);
3197
+ react.useEffect(() => {
3198
+ reset();
3199
+ return () => {
3200
+ generation.current++;
3201
+ };
3202
+ }, [scope.brandId, scope.centerId, reset]);
3203
+ const loadPreview = react.useCallback(
3204
+ async (args) => {
3205
+ if (busy.current) return;
3206
+ busy.current = true;
3207
+ const current = ++generation.current;
3208
+ setStatus("previewing");
3209
+ setError(void 0);
3210
+ setPayment(void 0);
3211
+ setPendingId(void 0);
3212
+ try {
3213
+ const value = await previewBookingChange(client, { ...args, ...scope });
3214
+ if (generation.current === current) {
3215
+ setPreview(value);
3216
+ setStatus("preview");
3217
+ }
3218
+ return value;
3219
+ } catch (e) {
3220
+ if (generation.current === current) {
3221
+ setError(e);
3222
+ setStatus("error");
3223
+ }
3224
+ throw e;
3225
+ } finally {
3226
+ if (generation.current === current) busy.current = false;
3227
+ }
3228
+ },
3229
+ [client, scope.brandId, scope.centerId]
3230
+ );
3231
+ const apply = react.useCallback(
3232
+ async (args) => {
3233
+ if (busy.current) return;
3234
+ busy.current = true;
3235
+ const current = generation.current;
3236
+ setError(void 0);
3237
+ setStatus("applying");
3238
+ try {
3239
+ const value = await applyMutation.run({ ...args, ...scope });
3240
+ if (generation.current !== current) return value;
3241
+ if (value.requiresPayment) {
3242
+ setPendingId(value.pendingModificationId);
3243
+ setStatus("pay");
3244
+ } else setStatus("done");
3245
+ return value;
3246
+ } catch (e) {
3247
+ if (generation.current === current) {
3248
+ setError(e);
3249
+ setStatus("error");
3250
+ }
3251
+ throw e;
3252
+ } finally {
3253
+ if (generation.current === current) busy.current = false;
3254
+ }
3255
+ },
3256
+ [applyMutation.run, scope.brandId, scope.centerId]
3257
+ );
3258
+ const createPayment = react.useCallback(async () => {
3259
+ if (!pendingId || busy.current || status !== "pay") return;
3260
+ busy.current = true;
3261
+ const current = generation.current;
3262
+ setError(void 0);
3263
+ try {
3264
+ const value = await createBookingChangePayment(client, {
3265
+ ...scope,
3266
+ pendingModificationId: pendingId
3267
+ });
3268
+ if (generation.current === current) setPayment(value);
3269
+ return value;
3270
+ } catch (e) {
3271
+ if (generation.current === current) setError(e);
3272
+ throw e;
3273
+ } finally {
3274
+ if (generation.current === current) busy.current = false;
3275
+ }
3276
+ }, [client, pendingId, scope.brandId, scope.centerId, status]);
3277
+ const resume = react.useCallback((args) => {
3278
+ generation.current++;
3279
+ busy.current = false;
3280
+ setPayment(void 0);
3281
+ setError(void 0);
3282
+ setPendingId(args.pendingModificationId);
3283
+ setStatus("pay");
3284
+ }, []);
3285
+ react.useEffect(() => {
3286
+ if (!pendingId || status !== "polling" && status !== "pay") return;
3287
+ let cancelled = false;
3288
+ let timer;
3289
+ const poll = async () => {
3290
+ try {
3291
+ const value = await getPendingBookingChange(client, {
3292
+ ...scope,
3293
+ pendingModificationId: pendingId
3294
+ });
3295
+ if (cancelled) return;
3296
+ setPending(value);
3297
+ setError(void 0);
3298
+ if (value.status === "applied") {
3299
+ setStatus("done");
3300
+ return;
3301
+ }
3302
+ if (value.status !== "pending_payment") {
3303
+ setStatus(value.status);
3304
+ return;
3305
+ }
3306
+ if (value.expiresAt <= Date.now()) {
3307
+ setStatus("expired");
3308
+ return;
3309
+ }
3310
+ } catch (e) {
3311
+ if (cancelled) return;
3312
+ setError(e);
3313
+ }
3314
+ timer = setTimeout(() => void poll(), 1500);
3315
+ };
3316
+ void poll();
3317
+ return () => {
3318
+ cancelled = true;
3319
+ clearTimeout(timer);
3320
+ };
3321
+ }, [client, scope.brandId, scope.centerId, pendingId, status]);
3322
+ const paymentConfirmed = react.useCallback(() => {
3323
+ if (pendingId) setStatus("polling");
3324
+ }, [pendingId]);
3325
+ return {
3326
+ status,
3327
+ preview,
3328
+ payment,
3329
+ pending,
3330
+ pendingModificationId: pendingId,
3331
+ error,
3332
+ loadPreview,
3333
+ apply,
3334
+ createPayment,
3335
+ paymentConfirmed,
3336
+ resume,
3337
+ reset
3338
+ };
3339
+ }
3340
+ function MembershipDetail({
3341
+ brandId,
3342
+ membershipId,
3343
+ centerId,
3344
+ timeZone,
3345
+ returnUrl,
3346
+ labels,
3347
+ className
3348
+ }) {
3349
+ const t = {
3350
+ title: "Membership",
3351
+ members: "Members",
3352
+ email: "Member email",
3353
+ add: "Add member",
3354
+ cancel: "Cancel at period end",
3355
+ reason: "Cancellation reason",
3356
+ billing: "Manage billing",
3357
+ ends: "Access ends",
3358
+ cancelled: "Renewal cancelled.",
3359
+ ...labels
3360
+ };
3361
+ const centers = useCenters({ brandId });
3362
+ const zone = timeZone ?? centers.data?.find((center) => center.id === centerId)?.timezone ?? (centers.data?.length === 1 ? centers.data[0]?.timezone : void 0);
3363
+ const scope = { brandId, membershipId };
3364
+ const detail = useMyMembershipDetail(scope);
3365
+ const members = useMyMembershipMembers(scope);
3366
+ const add = useAddMyMembershipMember();
3367
+ const cancel = useCancelMyMembership();
3368
+ const portal = useOpenMembershipBillingPortal();
3369
+ const action = useAccountAction();
3370
+ const [email, setEmail] = react.useState("");
3371
+ const [reason, setReason] = react.useState("");
3372
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
3373
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...detail }),
3374
+ detail.data && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3375
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { children: detail.data.template?.name }),
3376
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: detail.data.status }),
3377
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
3378
+ t.ends,
3379
+ ":",
3380
+ " ",
3381
+ zone ? new Date(detail.data.currentPeriodEndsAt).toLocaleDateString(void 0, {
3382
+ timeZone: zone
3383
+ }) : "\u2026"
3384
+ ] }),
3385
+ /* @__PURE__ */ jsxRuntime.jsxs(
3386
+ "form",
3387
+ {
3388
+ style: styles().stack,
3389
+ onSubmit: (e) => {
3390
+ e.preventDefault();
3391
+ void action.run(async () => {
3392
+ await cancel.run({ ...scope, expectedVersion: detail.data.version, reason });
3393
+ await detail.refetch();
3394
+ }, t.cancelled);
3395
+ },
3396
+ children: [
3397
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
3398
+ t.reason,
3399
+ /* @__PURE__ */ jsxRuntime.jsx(
3400
+ "input",
3401
+ {
3402
+ style: styles().input,
3403
+ required: true,
3404
+ value: reason,
3405
+ onChange: (e) => setReason(e.target.value)
3406
+ }
3407
+ )
3408
+ ] }),
3409
+ /* @__PURE__ */ jsxRuntime.jsx(
3410
+ "button",
3411
+ {
3412
+ style: styles().ghostBtn,
3413
+ disabled: action.busy || detail.data.status === "cancel_at_period_end",
3414
+ children: t.cancel
3415
+ }
3416
+ )
3417
+ ]
3418
+ }
3419
+ ),
3420
+ /* @__PURE__ */ jsxRuntime.jsx(
3421
+ "button",
3422
+ {
3423
+ style: styles().primaryBtn,
3424
+ disabled: action.busy,
3425
+ onClick: () => void action.run(async () => {
3426
+ const result = await portal.run({ ...scope, centerId, returnUrl });
3427
+ window.location.assign(result.url);
3428
+ }),
3429
+ children: t.billing
3430
+ }
3431
+ )
3432
+ ] }),
3433
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { children: t.members }),
3434
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...members }),
3435
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: members.data?.members.map((member) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: member.customerName }, member.customerId)) }),
3436
+ members.data?.canManage && /* @__PURE__ */ jsxRuntime.jsxs(
3437
+ "form",
3438
+ {
3439
+ onSubmit: (e) => {
3440
+ e.preventDefault();
3441
+ void action.run(async () => {
3442
+ await add.run({ ...scope, email });
3443
+ setEmail("");
3444
+ await members.refetch();
3445
+ });
3446
+ },
3447
+ children: [
3448
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
3449
+ t.email,
3450
+ /* @__PURE__ */ jsxRuntime.jsx(
3451
+ "input",
3452
+ {
3453
+ style: styles().input,
3454
+ type: "email",
3455
+ required: true,
3456
+ value: email,
3457
+ onChange: (e) => setEmail(e.target.value)
3458
+ }
3459
+ )
3460
+ ] }),
3461
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().ghostBtn, disabled: action.busy, children: t.add })
3462
+ ]
3463
+ }
3464
+ ),
3465
+ action.feedback
3466
+ ] });
3467
+ }
3468
+ function BookingChange({
3469
+ brandId,
3470
+ centerId,
3471
+ reservationId,
3472
+ expectedVersion,
3473
+ initial,
3474
+ unitNoun = "Units",
3475
+ renderPayment,
3476
+ labels,
3477
+ className
3478
+ }) {
3479
+ const t = {
3480
+ title: "Change reservation",
3481
+ date: "Date",
3482
+ start: "Start time",
3483
+ end: "End time",
3484
+ persons: "Guests",
3485
+ preview: "Preview change",
3486
+ apply: "Confirm change",
3487
+ payment: "Continue to payment",
3488
+ reset: "Start again",
3489
+ reason: "Change unavailable",
3490
+ done: "Reservation updated.",
3491
+ slotTaken: "The requested time is no longer available. Any payment will be refunded. Reload the reservation before trying again.",
3492
+ expired: "This change expired. Reload your reservation before trying again.",
3493
+ cancelled: "This change was cancelled.",
3494
+ paymentRequired: "Payment is required to complete this change.",
3495
+ ...labels
3496
+ };
3497
+ const change = useBookingChange({ brandId, centerId });
3498
+ const action = useAccountAction();
3499
+ const statusRef = react.useRef(null);
3500
+ react.useEffect(() => {
3501
+ if (change.status !== "idle") statusRef.current?.focus();
3502
+ }, [change.status]);
3503
+ const [date, setDate] = react.useState(initial.dateISO);
3504
+ const [start, setStart] = react.useState(initial.startMinuteOfDay);
3505
+ const [end, setEnd] = react.useState(initial.endMinuteOfDay);
3506
+ const [units, setUnits] = react.useState(initial.units);
3507
+ const [persons, setPersons] = react.useState(initial.persons);
3508
+ const args = {
3509
+ reservationId,
3510
+ newDateISO: date,
3511
+ newStartMinuteOfDay: start,
3512
+ newEndMinuteOfDay: end,
3513
+ newUnits: units,
3514
+ newPersons: persons
3515
+ };
3516
+ const editing = change.status === "idle" || change.status === "error";
3517
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
3518
+ editing && /* @__PURE__ */ jsxRuntime.jsxs(
3519
+ "form",
3520
+ {
3521
+ style: styles().stack,
3522
+ onSubmit: (e) => {
3523
+ e.preventDefault();
3524
+ void action.run(() => change.loadPreview(args));
3525
+ },
3526
+ children: [
3527
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
3528
+ t.date,
3529
+ /* @__PURE__ */ jsxRuntime.jsx(
3530
+ "input",
3531
+ {
3532
+ style: styles().input,
3533
+ required: true,
3534
+ type: "date",
3535
+ value: date,
3536
+ onChange: (e) => setDate(e.target.value)
3537
+ }
3538
+ )
3539
+ ] }),
3540
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
3541
+ t.start,
3542
+ /* @__PURE__ */ jsxRuntime.jsx(
3543
+ "input",
3544
+ {
3545
+ style: styles().input,
3546
+ required: true,
3547
+ type: "time",
3548
+ defaultValue: `${String(Math.floor(start / 60)).padStart(2, "0")}:${String(start % 60).padStart(2, "0")}`,
3549
+ onChange: (e) => setStart(timeToMinutes(e.target.value))
3550
+ }
3551
+ )
3552
+ ] }),
3553
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
3554
+ t.end,
3555
+ /* @__PURE__ */ jsxRuntime.jsx(
3556
+ "input",
3557
+ {
3558
+ style: styles().input,
3559
+ required: true,
3560
+ type: "time",
3561
+ defaultValue: `${String(Math.floor(end / 60)).padStart(2, "0")}:${String(end % 60).padStart(2, "0")}`,
3562
+ onChange: (e) => setEnd(timeToMinutes(e.target.value))
3563
+ }
3564
+ )
3565
+ ] }),
3566
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
3567
+ unitNoun,
3568
+ /* @__PURE__ */ jsxRuntime.jsx(
3569
+ "input",
3570
+ {
3571
+ style: styles().input,
3572
+ required: true,
3573
+ type: "number",
3574
+ min: 1,
3575
+ value: units,
3576
+ onChange: (e) => setUnits(Number(e.target.value))
3577
+ }
3578
+ )
3579
+ ] }),
3580
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: styles().label, children: [
3581
+ t.persons,
3582
+ /* @__PURE__ */ jsxRuntime.jsx(
3583
+ "input",
3584
+ {
3585
+ style: styles().input,
3586
+ required: true,
3587
+ type: "number",
3588
+ min: 1,
3589
+ value: persons,
3590
+ onChange: (e) => setPersons(Number(e.target.value))
3591
+ }
3592
+ )
3593
+ ] }),
3594
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().primaryBtn, disabled: action.busy, children: t.preview })
3595
+ ]
3596
+ }
3597
+ ),
3598
+ change.status === "preview" && change.preview && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3599
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
3600
+ formatCents(change.preview.oldFinalCents),
3601
+ " \u2192",
3602
+ " ",
3603
+ formatCents(change.preview.newFinalCents),
3604
+ " (",
3605
+ formatCents(change.preview.diffCents),
3606
+ ")"
3607
+ ] }),
3608
+ !change.preview.eligible && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: change.preview.reason ?? t.reason }),
3609
+ /* @__PURE__ */ jsxRuntime.jsx(
3610
+ "button",
3611
+ {
3612
+ style: styles().ghostBtn,
3613
+ disabled: !change.preview.eligible || action.busy,
3614
+ onClick: () => void action.run(() => change.apply({ ...args, expectedVersion })),
3615
+ children: t.apply
3616
+ }
3617
+ )
3618
+ ] }),
3619
+ change.status === "pay" && !change.payment && /* @__PURE__ */ jsxRuntime.jsx(
3620
+ "button",
3621
+ {
3622
+ style: styles().ghostBtn,
3623
+ disabled: action.busy,
3624
+ onClick: () => void action.run(() => change.createPayment()),
3625
+ children: t.payment
3626
+ }
3627
+ ),
3628
+ change.status === "pay" && change.payment && renderPayment?.(change.payment, change.paymentConfirmed),
3629
+ /* @__PURE__ */ jsxRuntime.jsx("p", { ref: statusRef, tabIndex: -1, role: "status", children: change.status === "done" ? t.done : change.status === "failed_slot_taken" ? t.slotTaken : change.status === "expired" ? t.expired : change.status === "cancelled" ? t.cancelled : change.status === "pay" ? t.paymentRequired : change.status }),
3630
+ change.error != null && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: change.error instanceof Error ? change.error.message : t.reason }),
3631
+ action.feedback,
3632
+ !["idle", "pay", "polling", "applying", "previewing"].includes(change.status) && /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().ghostBtn, disabled: action.busy, onClick: change.reset, children: t.reset })
3633
+ ] });
3634
+ }
3635
+ function useWaitlistJoin() {
3636
+ const client = useBowlosClient();
3637
+ const [status, setStatus] = react.useState("idle");
3638
+ const [entry, setEntry] = react.useState();
3639
+ const [setupIntent, setSetupIntent] = react.useState();
3640
+ const [error, setError] = react.useState();
3641
+ const generation = react.useRef(0);
3642
+ const busy = react.useRef(false);
3643
+ react.useEffect(
3644
+ () => () => {
3645
+ generation.current++;
3646
+ },
3647
+ [client]
3648
+ );
3649
+ function reset() {
3650
+ generation.current++;
3651
+ busy.current = false;
3652
+ setStatus("idle");
3653
+ setEntry(void 0);
3654
+ setSetupIntent(void 0);
3655
+ setError(void 0);
3656
+ }
3657
+ async function join(args) {
3658
+ if (busy.current) return;
3659
+ busy.current = true;
3660
+ const current = ++generation.current;
3661
+ setStatus("quoting");
3662
+ setError(void 0);
3663
+ setEntry(void 0);
3664
+ setSetupIntent(void 0);
3665
+ try {
3666
+ const value = await joinWaitlist(client, args);
3667
+ if (current === generation.current) {
3668
+ setEntry(value);
3669
+ setStatus("card");
3670
+ }
3671
+ return value;
3672
+ } catch (e) {
3673
+ if (current === generation.current) {
3674
+ setError(e);
3675
+ setStatus("error");
3676
+ }
3677
+ throw e;
3678
+ } finally {
3679
+ if (current === generation.current) busy.current = false;
3680
+ }
3681
+ }
3682
+ async function createCardSetup() {
3683
+ if (!entry || busy.current || status !== "card") return;
3684
+ busy.current = true;
3685
+ const current = generation.current;
3686
+ try {
3687
+ const value = await createWaitlistSetupIntent(client, { entryId: entry.entryId });
3688
+ if (current === generation.current) setSetupIntent(value);
3689
+ return value;
3690
+ } catch (e) {
3691
+ if (current === generation.current) {
3692
+ setError(e);
3693
+ setStatus("error");
3694
+ }
3695
+ throw e;
3696
+ } finally {
3697
+ if (current === generation.current) busy.current = false;
3698
+ }
3699
+ }
3700
+ async function cardConfirmed(intent) {
3701
+ if (!entry || busy.current || status !== "card") return;
3702
+ if (intent.status !== "succeeded") return;
3703
+ busy.current = true;
3704
+ const current = generation.current;
3705
+ setStatus("confirming");
3706
+ setError(void 0);
3707
+ try {
3708
+ const result = await confirmWaitlistCard(client, {
3709
+ entryId: entry.entryId,
3710
+ setupIntentId: intent.id
3711
+ });
3712
+ if (result.status !== "waiting") throw new Error("Waitlist card confirmation incomplete.");
3713
+ if (current === generation.current) setStatus("joined");
3714
+ } catch (e) {
3715
+ if (current === generation.current) {
3716
+ setError(e);
3717
+ setStatus("error");
3718
+ }
3719
+ throw e;
3720
+ } finally {
3721
+ if (current === generation.current) busy.current = false;
3722
+ }
3723
+ }
3724
+ return { status, entry, setupIntent, error, join, createCardSetup, cardConfirmed, reset };
3725
+ }
3726
+ function AddCardForm({
3727
+ brandId,
3728
+ centerId,
3729
+ onAdded,
3730
+ setupIntent,
3731
+ onSetupConfirmed,
3732
+ appearance,
3733
+ labels,
3734
+ className
3735
+ }) {
3736
+ const t = {
3737
+ title: "Add a card",
3738
+ start: "Add card",
3739
+ save: "Save card",
3740
+ saved: "Card saved.",
3741
+ error: "Unable to save this card.",
3742
+ ...labels
3743
+ };
3744
+ const setup = useCreateCardSetup();
3745
+ const action = useAccountAction();
3746
+ const [intent, setIntent] = react.useState();
3747
+ const activeIntent = setupIntent ?? intent;
3748
+ const stripe = react.useMemo(
3749
+ () => activeIntent ? stripeJs.loadStripe(activeIntent.publishableKey, { stripeAccount: activeIntent.stripeAccount }) : null,
3750
+ [activeIntent]
3751
+ );
3752
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
3753
+ !activeIntent ? /* @__PURE__ */ jsxRuntime.jsx(
3754
+ "button",
3755
+ {
3756
+ style: styles().primaryBtn,
3757
+ disabled: action.busy,
3758
+ onClick: () => void action.run(async () => setIntent(await setup.run({ brandId, centerId }))),
3759
+ children: t.start
3760
+ }
3761
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
3762
+ reactStripeJs.Elements,
3763
+ {
3764
+ stripe,
3765
+ options: {
3766
+ clientSecret: activeIntent.clientSecret,
3767
+ appearance,
3768
+ ..."customerSessionClientSecret" in activeIntent ? { customerSessionClientSecret: activeIntent.customerSessionClientSecret } : {}
3769
+ },
3770
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3771
+ SetupForm,
3772
+ {
3773
+ labels: t,
3774
+ onSetupConfirmed,
3775
+ onAdded: () => {
3776
+ setIntent(void 0);
3777
+ onAdded?.();
3778
+ }
3779
+ }
3780
+ )
3781
+ }
3782
+ ),
3783
+ action.feedback
3784
+ ] });
3785
+ }
3786
+ function SetupForm({
3787
+ labels,
3788
+ onAdded,
3789
+ onSetupConfirmed
3790
+ }) {
3791
+ const stripe = reactStripeJs.useStripe();
3792
+ const elements = reactStripeJs.useElements();
3793
+ const action = useAccountAction();
3794
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3795
+ "form",
3796
+ {
3797
+ style: styles().stack,
3798
+ onSubmit: (e) => {
3799
+ e.preventDefault();
3800
+ if (!stripe || !elements) return;
3801
+ void action.run(async () => {
3802
+ const result = await stripe.confirmSetup({ elements, redirect: "if_required" });
3803
+ if (result.error) throw new Error(result.error.message ?? labels.error);
3804
+ if (result.setupIntent?.status !== "succeeded") throw new Error(labels.error);
3805
+ await onSetupConfirmed?.(result.setupIntent);
3806
+ onAdded();
3807
+ }, labels.saved);
3808
+ },
3809
+ children: [
3810
+ /* @__PURE__ */ jsxRuntime.jsx(reactStripeJs.PaymentElement, {}),
3811
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().primaryBtn, disabled: !stripe || !elements || action.busy, children: labels.save }),
3812
+ action.feedback
3813
+ ]
3814
+ }
3815
+ );
3816
+ }
3817
+ function WaitlistJoin({ args, onJoined }) {
3818
+ const flow = useWaitlistJoin();
3819
+ const [consent, setConsent] = react.useState(false);
3820
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { "aria-label": "Join waitlist", children: [
3821
+ flow.status === "idle" && /* @__PURE__ */ jsxRuntime.jsx(
3822
+ "button",
3823
+ {
3824
+ onClick: () => {
3825
+ setConsent(false);
3826
+ void flow.join(args).catch(() => {
3827
+ });
3828
+ },
3829
+ children: "Join waitlist"
3830
+ }
3831
+ ),
3832
+ flow.status === "quoting" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Getting your price\u2026" }),
3833
+ flow.status === "card" && flow.entry && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3834
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
3835
+ formatCents(flow.entry.amountCents),
3836
+ " \u2014 charged only if a spot opens."
3837
+ ] }),
3838
+ !flow.setupIntent ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3839
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
3840
+ /* @__PURE__ */ jsxRuntime.jsx(
3841
+ "input",
3842
+ {
3843
+ type: "checkbox",
3844
+ checked: consent,
3845
+ onChange: (e) => setConsent(e.target.checked)
3846
+ }
3847
+ ),
3848
+ "I authorize a charge of ",
3849
+ formatCents(flow.entry.amountCents),
3850
+ " to this card if a spot opens."
3851
+ ] }),
3852
+ /* @__PURE__ */ jsxRuntime.jsx(
3853
+ "button",
3854
+ {
3855
+ disabled: !consent,
3856
+ onClick: () => void flow.createCardSetup().catch(() => {
3857
+ }),
3858
+ children: "Add card"
3859
+ }
3860
+ )
3861
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
3862
+ AddCardForm,
3863
+ {
3864
+ brandId: args.brandId ?? "",
3865
+ centerId: args.centerId,
3866
+ setupIntent: flow.setupIntent,
3867
+ onSetupConfirmed: async (intent) => {
3868
+ await flow.cardConfirmed(intent);
3869
+ onJoined?.();
3870
+ }
3871
+ }
3872
+ )
3873
+ ] }),
3874
+ flow.status === "confirming" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Confirming\u2026" }),
3875
+ flow.status === "joined" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Pending \u2014 waitlist. You will be charged only if a spot opens." }),
3876
+ flow.status === "error" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3877
+ /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: flow.error instanceof Error ? flow.error.message : "Unable to join waitlist." }),
3878
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: flow.reset, children: "Try again" })
3879
+ ] })
3880
+ ] });
3881
+ }
1987
3882
 
1988
3883
  exports.AccountDashboard = AccountDashboard;
1989
3884
  exports.AccountMenu = AccountMenu;
3885
+ exports.AddToWalletButtons = AddToWalletButtons;
1990
3886
  exports.AuthForm = AuthForm;
1991
3887
  exports.AuthGate = AuthGate;
1992
3888
  exports.BOWLOS_DEFAULT_THEME = BOWLOS_DEFAULT_THEME;
1993
3889
  exports.BookingCatalog = BookingCatalog;
3890
+ exports.BookingChange = BookingChange;
1994
3891
  exports.BookingFlow = BookingFlow;
1995
3892
  exports.BowlosTheme = BowlosTheme;
3893
+ exports.ChangePasswordForm = ChangePasswordForm;
3894
+ exports.CommunicationPrefs = CommunicationPrefs;
3895
+ exports.EventList = EventList;
1996
3896
  exports.FlashSale = FlashSale;
1997
3897
  exports.FlashSaleIndex = FlashSaleIndex;
3898
+ exports.GameCardHistory = GameCardHistory;
1998
3899
  exports.InquiryForm = InquiryForm;
1999
3900
  exports.MaintenanceBanner = MaintenanceBanner;
3901
+ exports.MembershipDetail = MembershipDetail;
2000
3902
  exports.PricingTable = PricingTable;
3903
+ exports.PrivacyCenter = PrivacyCenter;
3904
+ exports.ProfileForm = ProfileForm;
3905
+ exports.SavedCards = SavedCards;
3906
+ exports.WaitlistJoin = WaitlistJoin;
2001
3907
  exports.formatCents = formatCents;
2002
3908
  exports.formatCentsRange = formatCentsRange;
2003
3909
  //# sourceMappingURL=components.cjs.map