@msm-platform/customer-react 0.4.0 → 0.4.2

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.
package/dist/index.js CHANGED
@@ -134,6 +134,8 @@ var S = {
134
134
  "book.expired": "We held this time for as long as we could, and it has lapsed. Hold it again if it's still free.",
135
135
  "book.notAllowed": "Booking this needs a membership or pass that covers it. Ask the business.",
136
136
  "book.unavailable": "This time can no longer be booked. Choose another.",
137
+ "book.banned": "You can't book online until {date} because of bookings you didn't show up to. Contact the business if you think this is a mistake.",
138
+ "book.banned.undated": "You can't book online right now because of bookings you didn't show up to. Contact the business if you think this is a mistake.",
137
139
  "book.refused": "This business can't take your booking. Contact them.",
138
140
  "book.failed": "The booking could not be made. Try again.",
139
141
  "passes.heading": "Memberships and passes",
@@ -208,20 +210,20 @@ function N(e, t, n) {
208
210
  end: r ? A(t, n) : k(t, n)
209
211
  });
210
212
  }
211
- function P(e) {
213
+ function ee(e) {
212
214
  if (e < 60) return D("wait.seconds", e);
213
215
  let t = Math.round(e / 60);
214
216
  return t < 60 ? D("wait.minutes", t) : D("wait.hours", Math.round(e / 3600));
215
217
  }
216
218
  // src/cancellation.ts
217
- function F(e, t) {
219
+ function te(e, t) {
218
220
  if (e.status === "cancelled") return "cancelled";
219
221
  let n = t.getTime();
220
222
  return !e.cancellableUntil || n >= Date.parse(e.cancellableUntil) ? "closed" : e.lateCancellationFrom && n >= Date.parse(e.lateCancellationFrom) ? "late" : "open";
221
223
  }
222
224
  // src/screens/bookings.tsx
223
- var ee = "/web/businesses/{businessId}/bookings/{bookingId}/cancel";
224
- function te() {
225
+ var ne = "/web/businesses/{businessId}/bookings/{bookingId}/cancel";
226
+ function P() {
225
227
  let { client: e } = x(), [n, i] = s("upcoming"), [a, o] = s(), [c, l] = s(null), [u, d] = s(!1), [m, h] = s(), g = t(async (t) => {
226
228
  d(!1);
227
229
  try {
@@ -256,12 +258,12 @@ function te() {
256
258
  className: "cp-notice",
257
259
  children: T(m)
258
260
  }),
259
- u ? /* @__PURE__ */ f(I, { onRetry: () => g() }) : a ? a.length === 0 ? /* @__PURE__ */ f("p", {
261
+ u ? /* @__PURE__ */ f(F, { onRetry: () => g() }) : a ? a.length === 0 ? /* @__PURE__ */ f("p", {
260
262
  className: "cp-empty",
261
263
  children: T(n === "upcoming" ? "bookings.emptyUpcoming" : "bookings.emptyPast")
262
264
  }) : /* @__PURE__ */ f("ul", {
263
265
  className: "cp-list",
264
- children: a.map((e) => /* @__PURE__ */ f(ne, {
266
+ children: a.map((e) => /* @__PURE__ */ f(re, {
265
267
  booking: e,
266
268
  onCancelled: (e, t) => {
267
269
  o((t) => t?.map((t) => t.id === e.id ? e : t)), h(t ? "bookings.doneLate" : "bookings.doneOnTime");
@@ -280,7 +282,7 @@ function te() {
280
282
  ]
281
283
  });
282
284
  }
283
- function I({ onRetry: e }) {
285
+ function F({ onRetry: e }) {
284
286
  return /* @__PURE__ */ p("div", {
285
287
  role: "alert",
286
288
  className: "cp-error",
@@ -292,12 +294,12 @@ function I({ onRetry: e }) {
292
294
  })]
293
295
  });
294
296
  }
295
- function ne(e) {
296
- let { client: t, businesses: n } = x(), { booking: r } = e, i = n.get(r.businessId)?.timezone, [a, o] = s(!1), [c, l] = s(!1), [d, m] = s(), [h, g] = s(!1), _ = h ? "closed" : F(r, /* @__PURE__ */ new Date()), v = r.creditMembershipId !== null && r.creditRestoredAt === null;
297
+ function re(e) {
298
+ let { client: t, businesses: n } = x(), { booking: r } = e, i = n.get(r.businessId)?.timezone, [a, o] = s(!1), [c, l] = s(!1), [d, m] = s(), [h, g] = s(!1), _ = h ? "closed" : te(r, /* @__PURE__ */ new Date()), v = r.creditMembershipId !== null && r.creditRestoredAt === null;
297
299
  async function y() {
298
300
  l(!0), m(void 0);
299
301
  try {
300
- let { data: n } = await t.POST(ee, { params: { path: {
302
+ let { data: n } = await t.POST(ne, { params: { path: {
301
303
  businessId: r.businessId,
302
304
  bookingId: r.id
303
305
  } } });
@@ -308,7 +310,7 @@ function ne(e) {
308
310
  lateCancellationFrom: null
309
311
  }, n.cancelledLate === !0));
310
312
  } catch (e) {
311
- if (u(e, "post", ee)) {
313
+ if (u(e, "post", ne)) {
312
314
  if (e.code === "EventStarted") {
313
315
  g(!0), o(!1);
314
316
  return;
@@ -388,365 +390,8 @@ function ne(e) {
388
390
  ]
389
391
  });
390
392
  }
391
- // src/booking.tsx
392
- var re = "/web/businesses/{businessId}/reservations", ie = "/web/businesses/{businessId}/reservations/{reservationId}/confirm";
393
- function L({ choice: e }) {
394
- let { business: t, candidate: n } = e;
395
- return /* @__PURE__ */ p("div", {
396
- className: "cp-summary",
397
- children: [
398
- /* @__PURE__ */ f("h2", { children: n.title }),
399
- /* @__PURE__ */ f("p", { children: t.displayName }),
400
- /* @__PURE__ */ f("p", { children: N(n.startsAt, n.endsAt, n.timezone) }),
401
- n.resource && /* @__PURE__ */ f("p", {
402
- className: "cp-hint",
403
- children: T("business.with", { resource: n.resource.displayName })
404
- })
405
- ]
406
- });
407
- }
408
- function ae(e) {
409
- let { client: n, navigate: i, accountNavigation: a } = x(), { business: c, candidate: l } = e.choice, [m, h] = s({ step: "reserving" }), [g, _] = s(), v = t(async () => {
410
- h({ step: "reserving" });
411
- try {
412
- let { data: e } = await n.POST(re, {
413
- params: { path: { businessId: c.id } },
414
- body: l.eventId ? { eventId: l.eventId } : {
415
- eventTypeId: l.eventTypeId,
416
- startsAt: l.startsAt,
417
- ...l.resource && { resourceId: l.resource.id }
418
- }
419
- });
420
- e && h({
421
- step: "held",
422
- reservationId: e.id,
423
- expiresAt: e.expiresAt
424
- });
425
- } catch (e) {
426
- let t = u(e, "post", re) ? e.code : void 0;
427
- h({
428
- step: "refused",
429
- message: oe(t),
430
- again: !1
431
- });
432
- }
433
- }, [
434
- n,
435
- c.id,
436
- l
437
- ]), y = o(!1);
438
- r(() => {
439
- y.current || (y.current = !0, v());
440
- }, [v]);
441
- async function b(t, r) {
442
- h({
443
- step: "confirming",
444
- reservationId: t,
445
- expiresAt: r
446
- });
447
- try {
448
- let { data: r } = await n.POST(ie, { params: { path: {
449
- businessId: c.id,
450
- reservationId: t
451
- } } });
452
- if (!r) return;
453
- e.onBooked?.(r);
454
- let i = await n.GET("/web/businesses/{businessId}/bookings/{bookingId}", { params: { path: {
455
- businessId: c.id,
456
- bookingId: r.id
457
- } } }).then(({ data: e }) => e ?? null).catch(() => null);
458
- h({
459
- step: "booked",
460
- booking: i
461
- });
462
- } catch (e) {
463
- let t = u(e, "post", ie) ? e.code : void 0;
464
- h(t === "ReservationExpired" || t === "ReservationNotFound" ? {
465
- step: "refused",
466
- message: "book.expired",
467
- again: !0
468
- } : {
469
- step: "refused",
470
- message: se(t),
471
- again: !1
472
- });
473
- }
474
- }
475
- let S = /* @__PURE__ */ f("button", {
476
- type: "button",
477
- className: "cp-secondary",
478
- onClick: e.onBack,
479
- children: T("book.back")
480
- });
481
- return /* @__PURE__ */ p("section", {
482
- className: "cp-screen",
483
- children: [/* @__PURE__ */ f("h1", { children: T("book.heading") }), m.step === "booked" ? /* @__PURE__ */ p(d, { children: [
484
- /* @__PURE__ */ f("p", {
485
- role: "status",
486
- className: "cp-notice",
487
- children: T(g ?? "book.booked")
488
- }),
489
- m.booking ? /* @__PURE__ */ f("ul", {
490
- className: "cp-list",
491
- children: /* @__PURE__ */ f(ne, {
492
- booking: m.booking,
493
- onCancelled: (e, t) => {
494
- h({
495
- step: "booked",
496
- booking: e
497
- }), _(t ? "bookings.doneLate" : "bookings.doneOnTime");
498
- }
499
- })
500
- }) : /* @__PURE__ */ f(L, { choice: e.choice }),
501
- a ? /* @__PURE__ */ f("button", {
502
- type: "button",
503
- className: "cp-secondary",
504
- onClick: () => i("bookings"),
505
- children: T("book.toBookings")
506
- }) : e.onDone && /* @__PURE__ */ f("button", {
507
- type: "button",
508
- className: "cp-secondary",
509
- onClick: e.onDone,
510
- children: T("book.done")
511
- })
512
- ] }) : /* @__PURE__ */ p(d, { children: [
513
- /* @__PURE__ */ f(L, { choice: e.choice }),
514
- m.step === "reserving" && /* @__PURE__ */ f("p", {
515
- role: "status",
516
- children: T("book.reserving")
517
- }),
518
- (m.step === "held" || m.step === "confirming") && /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("p", {
519
- className: "cp-hint",
520
- children: T("book.heldUntil", { time: A(m.expiresAt, l.timezone) })
521
- }), /* @__PURE__ */ p("div", {
522
- className: "cp-actions",
523
- children: [/* @__PURE__ */ f("button", {
524
- type: "button",
525
- disabled: m.step === "confirming",
526
- onClick: () => b(m.reservationId, m.expiresAt),
527
- children: m.step === "confirming" ? T("book.confirming") : T("book.confirm")
528
- }), S]
529
- })] }),
530
- m.step === "refused" && /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("p", {
531
- role: "alert",
532
- children: T(m.message)
533
- }), /* @__PURE__ */ p("div", {
534
- className: "cp-actions",
535
- children: [m.again && /* @__PURE__ */ f("button", {
536
- type: "button",
537
- onClick: v,
538
- children: T("book.reserveAgain")
539
- }), S]
540
- })] })
541
- ] })]
542
- });
543
- }
544
- function oe(e) {
545
- switch (e) {
546
- case "EventFull": return "book.full";
547
- case "SlotTaken": return "book.slotTaken";
548
- case "ReservationLimitReached": return "book.limit";
549
- case "NotAuthorized": return "book.notAllowed";
550
- case "EventStarted":
551
- case "EventNotBookable":
552
- case "NotATimeSlot":
553
- case "EventNotFound":
554
- case "EventTypeNotFound":
555
- case "BusinessNotFound": return "book.unavailable";
556
- default: return "book.failed";
557
- }
558
- }
559
- function se(e) {
560
- switch (e) {
561
- case "NotAuthorized": return "book.notAllowed";
562
- case "EventStarted":
563
- case "EventNotBookable":
564
- case "BusinessNotFound": return "book.unavailable";
565
- case "CustomerOutsideBusiness": return "book.refused";
566
- default: return "book.failed";
567
- }
568
- }
569
- // src/layout.tsx
570
- function R({ brand: e }) {
571
- return e ? /* @__PURE__ */ p("div", {
572
- className: "cp-brand",
573
- children: [e.logo && /* @__PURE__ */ f("img", {
574
- src: e.logo,
575
- alt: ""
576
- }), /* @__PURE__ */ f("span", { children: e.name })]
577
- }) : null;
578
- }
579
- var ce = [["businesses", "nav.book"]], le = [
580
- ["bookings", "nav.bookings"],
581
- ["passes", "nav.passes"],
582
- ["details", "nav.details"]
583
- ], ue = [...ce, ...le];
584
- function de(e) {
585
- let t = typeof e.screen == "string" ? e.screen : "businesses";
586
- return /* @__PURE__ */ p("div", {
587
- className: "cp-shell",
588
- children: [
589
- /* @__PURE__ */ p("header", {
590
- className: "cp-header",
591
- children: [/* @__PURE__ */ f(R, { brand: e.brand }), e.signedIn ? /* @__PURE__ */ f("button", {
592
- type: "button",
593
- className: "cp-link",
594
- onClick: e.onSignOut,
595
- children: T("nav.signOut")
596
- }) : !e.signingIn && /* @__PURE__ */ f("button", {
597
- type: "button",
598
- className: "cp-link",
599
- onClick: () => e.onNavigate("bookings"),
600
- children: T("nav.signIn")
601
- })]
602
- }),
603
- /* @__PURE__ */ f("nav", {
604
- className: "cp-nav",
605
- "aria-label": T("nav.label"),
606
- children: e.tabs.map(([n, r]) => /* @__PURE__ */ f("button", {
607
- type: "button",
608
- "aria-current": t === n ? "page" : void 0,
609
- onClick: () => e.onNavigate(n),
610
- children: T(r)
611
- }, n))
612
- }),
613
- /* @__PURE__ */ f("main", {
614
- className: "cp-main",
615
- children: e.children
616
- })
617
- ]
618
- });
619
- }
620
- // src/client.ts
621
- var z = (e, t) => {
622
- let n = new Request(e, t);
623
- return n.headers.set("X-MSM-BFF", "1"), fetch(n);
624
- };
625
- function B(e, t, n) {
626
- return z(`${e}${t}`, {
627
- method: "POST",
628
- headers: { "content-type": "application/json" },
629
- body: JSON.stringify(n ?? {})
630
- });
631
- }
632
- function fe(e, t) {
633
- let n = l({ baseUrl: `${e}/engine` });
634
- return n.use({
635
- onRequest({ request: e }) {
636
- return e.headers.set("X-MSM-BFF", "1"), e;
637
- },
638
- onResponse({ response: e }) {
639
- e.status === 401 && t();
640
- }
641
- }), n;
642
- }
643
- // src/session.ts
644
- var V = /* @__PURE__ */ new Map();
645
- function H(e) {
646
- let t = V.get(e);
647
- return t || (t = {
648
- value: void 0,
649
- listeners: /* @__PURE__ */ new Set(),
650
- generation: 0
651
- }, V.set(e, t)), t;
652
- }
653
- function U(e, t) {
654
- let n = H(e);
655
- if (n.value !== t) {
656
- n.value = t;
657
- for (let e of n.listeners) e();
658
- }
659
- }
660
- function pe(e, t) {
661
- let { generation: n } = t, r = (r) => {
662
- t.generation === n && t.value === void 0 && U(e, r);
663
- };
664
- z(`${e}/auth/session`).then(async (e) => r(e.ok ? (await e.json()).sessionKey : null)).catch(() => r(null));
665
- }
666
- function me(e, t) {
667
- let n = H(e);
668
- return n.listeners.size === 0 && n.value === void 0 && pe(e, n), n.listeners.add(t), () => {
669
- n.listeners.delete(t), n.listeners.size === 0 && queueMicrotask(() => {
670
- n.listeners.size > 0 || (n.value = void 0, n.generation++);
671
- });
672
- };
673
- }
674
- function he(e, t) {
675
- let n = c((t) => me(e, t), () => H(e).value, () => void 0), i = o(void 0), a = o(t);
676
- return a.current = t, r(() => {
677
- if (n === void 0) return;
678
- let e = n !== null;
679
- i.current !== void 0 && i.current !== e && a.current?.(e), i.current = e;
680
- }, [n]), n;
681
- }
682
- // src/portal.tsx
683
- function W(e) {
684
- let { navigate: n, accountNavigation: i } = e, c = e.basePath.replace(/\/$/, ""), l = he(c, e.onSessionChange), u = o(!1);
685
- u.current = !!l;
686
- let [d, f] = s(), [p, m] = s(/* @__PURE__ */ new Map()), [h, g] = s("loading"), _ = a(() => fe(c, () => {
687
- u.current && f("app.signedOut"), U(c, null);
688
- }), [c]), v = t(async () => {
689
- g("loading");
690
- try {
691
- let e = /* @__PURE__ */ new Map(), t;
692
- do {
693
- let { data: n } = await _.GET("/web/businesses", { params: { query: {
694
- limit: 100,
695
- ...t && { cursor: t }
696
- } } });
697
- for (let t of n?.items ?? []) e.set(t.id, t);
698
- t = n?.nextCursor ?? void 0;
699
- } while (t);
700
- m(e), g("ready");
701
- } catch {
702
- g("failed");
703
- }
704
- }, [_]);
705
- return r(() => {
706
- v();
707
- }, [v]), {
708
- basePath: c,
709
- sessionKey: l,
710
- notice: d,
711
- portal: a(() => ({
712
- client: _,
713
- businesses: p,
714
- businessesStatus: h,
715
- reloadBusinesses: () => void v(),
716
- navigate: n,
717
- accountNavigation: i,
718
- signOut: async (e) => {
719
- await B(c, "/auth/logout").catch(() => {}), f(e), U(c, null);
720
- }
721
- }), [
722
- _,
723
- p,
724
- h,
725
- v,
726
- n,
727
- i,
728
- c
729
- ]),
730
- signedInAs: t((e) => {
731
- f(void 0), U(c, e);
732
- }, [c])
733
- };
734
- }
735
- function G(e) {
736
- return /* @__PURE__ */ f("div", {
737
- className: "msm-customer",
738
- children: e.loading ? /* @__PURE__ */ f("p", {
739
- className: "cp-status",
740
- role: "status",
741
- children: T("app.loading")
742
- }) : /* @__PURE__ */ f(b.Provider, {
743
- value: e.portal,
744
- children: e.children
745
- })
746
- });
747
- }
748
393
  // src/image.tsx
749
- function K(e) {
394
+ function I(e) {
750
395
  let { image: t, alt: n, className: r } = e;
751
396
  if (!t) return null;
752
397
  let { small: i } = t;
@@ -779,12 +424,12 @@ function K(e) {
779
424
  });
780
425
  }
781
426
  // src/screens/business.tsx
782
- var ge = "/web/businesses/{businessId}", _e = /* @__PURE__ */ new Set([
427
+ var ie = "/web/businesses/{businessId}", ae = /* @__PURE__ */ new Set([
783
428
  "BusinessNotFound",
784
429
  "OutsideClientScope",
785
430
  "ValidationFailed"
786
- ]), ve = 7;
787
- function ye(e, t = /* @__PURE__ */ new Date()) {
431
+ ]), oe = 7;
432
+ function se(e, t = /* @__PURE__ */ new Date()) {
788
433
  return new Intl.DateTimeFormat("en-CA", {
789
434
  timeZone: e,
790
435
  year: "numeric",
@@ -792,277 +437,658 @@ function ye(e, t = /* @__PURE__ */ new Date()) {
792
437
  day: "2-digit"
793
438
  }).format(t);
794
439
  }
795
- function q(e, t) {
440
+ function L(e, t) {
796
441
  let n = /* @__PURE__ */ new Date(`${e}T00:00:00Z`);
797
442
  return n.setUTCDate(n.getUTCDate() + t), n.toISOString().slice(0, 10);
798
443
  }
799
- function be(e) {
800
- let { client: n } = x(), [i, a] = s(), [o, c] = s(), [l, d] = s(!1), f = t(async () => {
801
- d(!1), a(void 0);
444
+ function ce(e) {
445
+ let { client: n } = x(), [i, a] = s(), [o, c] = s(), [l, d] = s(!1), f = t(async () => {
446
+ d(!1), a(void 0);
447
+ try {
448
+ let [t, r] = await Promise.all([n.GET(ie, { params: { path: { businessId: e } } }), n.GET("/web/businesses/{businessId}/event-types", { params: { path: { businessId: e } } })]);
449
+ a(t.data ?? null), c(r.data?.items ?? []);
450
+ } catch (e) {
451
+ u(e) && ae.has(e.code ?? "") ? a(null) : d(!0);
452
+ }
453
+ }, [n, e]);
454
+ return r(() => {
455
+ f();
456
+ }, [f]), {
457
+ business: i,
458
+ types: o,
459
+ failed: l,
460
+ reload: f
461
+ };
462
+ }
463
+ function le(e, t) {
464
+ if (e.failed) return /* @__PURE__ */ p("section", {
465
+ className: "cp-screen",
466
+ children: [t, /* @__PURE__ */ f(F, { onRetry: e.reload })]
467
+ });
468
+ if (e.business === null) return /* @__PURE__ */ p("section", {
469
+ className: "cp-screen",
470
+ children: [t, /* @__PURE__ */ f("p", {
471
+ className: "cp-empty",
472
+ children: T("business.notFound")
473
+ })]
474
+ });
475
+ if (e.business === void 0 || !e.types) return /* @__PURE__ */ p("section", {
476
+ className: "cp-screen",
477
+ children: [t, /* @__PURE__ */ f("p", {
478
+ role: "status",
479
+ children: T("app.loading")
480
+ })]
481
+ });
482
+ }
483
+ function ue(e) {
484
+ let t = /* @__PURE__ */ new Map();
485
+ for (let n of e) for (let e of n.resources) t.has(e.id) || t.set(e.id, e);
486
+ return [...t.values()];
487
+ }
488
+ function de(e) {
489
+ let { navigate: t, accountNavigation: n } = x(), { businessId: r, eventTypeId: i, onFilter: a } = e, o = ce(r), s = n && /* @__PURE__ */ f("button", {
490
+ type: "button",
491
+ className: "cp-link cp-back",
492
+ onClick: () => t("businesses"),
493
+ children: T("business.all")
494
+ }), c = le(o, s), { business: l, types: u } = o;
495
+ if (c || !l || !u) return c;
496
+ let m = u.find((e) => e.id === i), h = a ? ue(m ? [m] : u) : [], g = h.some((t) => t.id === e.resourceId) ? e.resourceId : void 0, _ = (e) => {
497
+ if (!a) return t(e ? {
498
+ businessId: r,
499
+ eventTypeId: e
500
+ } : { businessId: r });
501
+ let n = u.find((t) => t.id === e), i = g && ue(n ? [n] : u).some((e) => e.id === g);
502
+ a({
503
+ ...e && { eventTypeId: e },
504
+ ...i && { resourceId: g }
505
+ });
506
+ };
507
+ return /* @__PURE__ */ p("section", {
508
+ className: "cp-screen",
509
+ children: [
510
+ s,
511
+ /* @__PURE__ */ f(fe, { business: l }),
512
+ u.length > 0 && /* @__PURE__ */ p("fieldset", {
513
+ className: "cp-chips",
514
+ "aria-label": T("business.types"),
515
+ children: [/* @__PURE__ */ f("button", {
516
+ type: "button",
517
+ "aria-pressed": !i,
518
+ onClick: () => _(void 0),
519
+ children: T("business.allTypes")
520
+ }), u.map((e) => /* @__PURE__ */ f("button", {
521
+ type: "button",
522
+ "aria-pressed": e.id === i,
523
+ onClick: () => _(e.id),
524
+ children: e.displayName
525
+ }, e.id))]
526
+ }),
527
+ a && h.length > 1 && /* @__PURE__ */ p("fieldset", {
528
+ className: "cp-chips",
529
+ children: [
530
+ /* @__PURE__ */ f("legend", { children: T("business.resources") }),
531
+ /* @__PURE__ */ f("button", {
532
+ type: "button",
533
+ "aria-pressed": !g,
534
+ onClick: () => a({ ...i && { eventTypeId: i } }),
535
+ children: T("business.anyResource")
536
+ }),
537
+ h.map((e) => /* @__PURE__ */ f("button", {
538
+ type: "button",
539
+ "aria-pressed": e.id === g,
540
+ onClick: () => a({
541
+ ...i && { eventTypeId: i },
542
+ resourceId: e.id
543
+ }),
544
+ children: e.displayName
545
+ }, e.id))
546
+ ]
547
+ }),
548
+ i && !m ? /* @__PURE__ */ f("p", {
549
+ className: "cp-empty",
550
+ children: T("business.typeMissing")
551
+ }) : /* @__PURE__ */ p(d, { children: [m && /* @__PURE__ */ f(R, { type: m }), /* @__PURE__ */ f(z, {
552
+ business: l,
553
+ eventTypeId: i,
554
+ resourceId: g,
555
+ onChoose: (t) => e.onChoose(l, t)
556
+ })] })
557
+ ]
558
+ });
559
+ }
560
+ function fe({ business: e }) {
561
+ return /* @__PURE__ */ p("header", {
562
+ className: "cp-business-head",
563
+ children: [/* @__PURE__ */ f(I, {
564
+ image: e.logo,
565
+ alt: T("image.logo", { name: e.displayName }),
566
+ size: "small",
567
+ className: "cp-logo"
568
+ }), /* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("h1", { children: e.displayName }), e.address && /* @__PURE__ */ f("p", {
569
+ className: "cp-hint",
570
+ children: e.address
571
+ })] })]
572
+ });
573
+ }
574
+ function R({ type: e }) {
575
+ return /* @__PURE__ */ p("div", {
576
+ className: "cp-type",
577
+ children: [
578
+ /* @__PURE__ */ f(I, {
579
+ image: e.image,
580
+ alt: e.displayName,
581
+ size: "full",
582
+ className: "cp-detail-image"
583
+ }),
584
+ /* @__PURE__ */ f("h2", { children: e.displayName }),
585
+ e.description && /* @__PURE__ */ f("p", { children: e.description }),
586
+ /* @__PURE__ */ f("p", {
587
+ className: "cp-hint",
588
+ children: T("business.minutes", { minutes: e.durationMinutes })
589
+ })
590
+ ]
591
+ });
592
+ }
593
+ function z(e) {
594
+ let { client: n } = x(), { business: i, eventTypeId: a, resourceId: o } = e, c = i.timezone, [l, u] = s(0), [m, h] = s(), [g, _] = s(!1), v = L(se(c), l * oe), y = L(v, oe), b = t(async () => {
595
+ _(!1), h(void 0);
596
+ try {
597
+ let { data: e } = await n.GET("/web/businesses/{businessId}/availability", { params: {
598
+ path: { businessId: i.id },
599
+ query: {
600
+ from: `${v}T00:00`,
601
+ to: `${y}T00:00`,
602
+ ...a && { eventTypeId: a },
603
+ ...o && { resourceId: o }
604
+ }
605
+ } });
606
+ h(e?.items ?? []);
607
+ } catch {
608
+ _(!0);
609
+ }
610
+ }, [
611
+ n,
612
+ i.id,
613
+ a,
614
+ o,
615
+ v,
616
+ y
617
+ ]);
618
+ r(() => {
619
+ b();
620
+ }, [b]);
621
+ let S = Date.now(), C = /* @__PURE__ */ new Map();
622
+ for (let e of m ?? []) {
623
+ if (Date.parse(e.startsAt) <= S) continue;
624
+ let t = M(e.startsAt, e.timezone);
625
+ C.set(t, [...C.get(t) ?? [], e]);
626
+ }
627
+ let w = T("business.weekOf", {
628
+ from: j(`${v}T12:00:00Z`, "UTC"),
629
+ to: j(`${L(y, -1)}T12:00:00Z`, "UTC")
630
+ });
631
+ return /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("fieldset", {
632
+ className: "cp-week",
633
+ "aria-label": T("business.week"),
634
+ children: [
635
+ /* @__PURE__ */ f("button", {
636
+ type: "button",
637
+ className: "cp-secondary",
638
+ disabled: l === 0,
639
+ onClick: () => u((e) => e - 1),
640
+ "aria-label": T("business.previousWeek"),
641
+ children: "‹"
642
+ }),
643
+ /* @__PURE__ */ f("span", { children: w }),
644
+ /* @__PURE__ */ f("button", {
645
+ type: "button",
646
+ className: "cp-secondary",
647
+ onClick: () => u((e) => e + 1),
648
+ "aria-label": T("business.nextWeek"),
649
+ children: "›"
650
+ })
651
+ ]
652
+ }), g ? /* @__PURE__ */ f(F, { onRetry: b }) : m ? C.size === 0 ? /* @__PURE__ */ f("p", {
653
+ className: "cp-empty",
654
+ children: T("business.empty")
655
+ }) : [...C].map(([t, n]) => /* @__PURE__ */ p("div", {
656
+ className: "cp-day",
657
+ children: [/* @__PURE__ */ f("h2", { children: t }), /* @__PURE__ */ f("ul", {
658
+ className: "cp-list",
659
+ children: n.map((t) => /* @__PURE__ */ f(pe, {
660
+ candidate: t,
661
+ onChoose: () => e.onChoose(t)
662
+ }, `${t.eventId ?? t.eventTypeId}-${t.resource?.id ?? ""}-${t.startsAt}`))
663
+ })]
664
+ }, t)) : /* @__PURE__ */ f("p", {
665
+ role: "status",
666
+ children: T("app.loading")
667
+ })] });
668
+ }
669
+ function B({ candidate: e }) {
670
+ if (e.kind === "slot") return e.resource ? /* @__PURE__ */ f("p", {
671
+ className: "cp-hint",
672
+ children: T("business.with", { resource: e.resources?.[0]?.presentedAs?.name ?? e.resource.displayName })
673
+ }) : null;
674
+ let t = [];
675
+ for (let n of e.resources ?? []) {
676
+ let { label: e, name: r } = n.presentedAs ?? {
677
+ label: null,
678
+ name: n.displayName
679
+ }, i = t.at(-1);
680
+ i && e !== null && i.label === e ? i.names.push(r) : t.push({
681
+ label: e,
682
+ names: [r]
683
+ });
684
+ }
685
+ let n = t.map(({ label: e, names: t }) => e === null ? t.join(", ") : `${e}: ${t.join(", ")}`);
686
+ return n.length > 0 ? /* @__PURE__ */ f("p", {
687
+ className: "cp-hint cp-resources",
688
+ children: n.join(" · ")
689
+ }) : null;
690
+ }
691
+ function pe(e) {
692
+ let { candidate: t } = e, n = t.kind === "slot";
693
+ return /* @__PURE__ */ p("li", {
694
+ className: "cp-card cp-candidate",
695
+ "data-kind": t.kind,
696
+ children: [
697
+ /* @__PURE__ */ p("p", {
698
+ className: "cp-time",
699
+ children: [
700
+ A(t.startsAt, t.timezone),
701
+ " – ",
702
+ A(t.endsAt, t.timezone)
703
+ ]
704
+ }),
705
+ /* @__PURE__ */ p("div", {
706
+ className: "cp-candidate-body",
707
+ children: [
708
+ /* @__PURE__ */ f("h3", { children: t.title }),
709
+ /* @__PURE__ */ f(B, { candidate: t }),
710
+ /* @__PURE__ */ f("p", {
711
+ className: "cp-hint",
712
+ children: n ? T("business.openTime") : t.full ? T("business.full") : D("business.seatsLeft", t.seatsLeft)
713
+ })
714
+ ]
715
+ }),
716
+ !t.full && /* @__PURE__ */ f("button", {
717
+ type: "button",
718
+ onClick: e.onChoose,
719
+ children: T("business.book")
720
+ })
721
+ ]
722
+ });
723
+ }
724
+ // src/booking.tsx
725
+ var V = "/web/businesses/{businessId}/reservations", me = "/web/businesses/{businessId}/reservations/{reservationId}/confirm";
726
+ function H({ choice: e }) {
727
+ let { business: t, candidate: n } = e;
728
+ return /* @__PURE__ */ p("div", {
729
+ className: "cp-summary",
730
+ children: [
731
+ /* @__PURE__ */ f("h2", { children: n.title }),
732
+ /* @__PURE__ */ f("p", { children: t.displayName }),
733
+ /* @__PURE__ */ f("p", { children: N(n.startsAt, n.endsAt, n.timezone) }),
734
+ /* @__PURE__ */ f(B, { candidate: n })
735
+ ]
736
+ });
737
+ }
738
+ function he(e) {
739
+ let { client: n, navigate: i, accountNavigation: a } = x(), { business: c, candidate: l } = e.choice, [m, h] = s({ step: "reserving" }), [g, _] = s(), v = t(async () => {
740
+ h({ step: "reserving" });
802
741
  try {
803
- let [t, r] = await Promise.all([n.GET(ge, { params: { path: { businessId: e } } }), n.GET("/web/businesses/{businessId}/event-types", { params: { path: { businessId: e } } })]);
804
- a(t.data ?? null), c(r.data?.items ?? []);
742
+ let { data: e } = await n.POST(V, {
743
+ params: { path: { businessId: c.id } },
744
+ body: l.eventId ? { eventId: l.eventId } : {
745
+ eventTypeId: l.eventTypeId,
746
+ startsAt: l.startsAt,
747
+ ...l.resource && { resourceId: l.resource.id }
748
+ }
749
+ });
750
+ e && h({
751
+ step: "held",
752
+ reservationId: e.id,
753
+ expiresAt: e.expiresAt
754
+ });
805
755
  } catch (e) {
806
- u(e) && _e.has(e.code ?? "") ? a(null) : d(!0);
756
+ let t = u(e, "post", V) ? e : void 0;
757
+ h({
758
+ step: "refused",
759
+ ...ge(t, _e, l.timezone),
760
+ again: !1
761
+ });
807
762
  }
808
- }, [n, e]);
809
- return r(() => {
810
- f();
811
- }, [f]), {
812
- business: i,
813
- types: o,
814
- failed: l,
815
- reload: f
816
- };
817
- }
818
- function xe(e, t) {
819
- if (e.failed) return /* @__PURE__ */ p("section", {
820
- className: "cp-screen",
821
- children: [t, /* @__PURE__ */ f(I, { onRetry: e.reload })]
822
- });
823
- if (e.business === null) return /* @__PURE__ */ p("section", {
824
- className: "cp-screen",
825
- children: [t, /* @__PURE__ */ f("p", {
826
- className: "cp-empty",
827
- children: T("business.notFound")
828
- })]
829
- });
830
- if (e.business === void 0 || !e.types) return /* @__PURE__ */ p("section", {
831
- className: "cp-screen",
832
- children: [t, /* @__PURE__ */ f("p", {
833
- role: "status",
834
- children: T("app.loading")
835
- })]
836
- });
837
- }
838
- function Se(e) {
839
- let t = /* @__PURE__ */ new Map();
840
- for (let n of e) for (let e of n.resources) t.has(e.id) || t.set(e.id, e);
841
- return [...t.values()];
842
- }
843
- function Ce(e) {
844
- let { navigate: t, accountNavigation: n } = x(), { businessId: r, eventTypeId: i, onFilter: a } = e, o = be(r), s = n && /* @__PURE__ */ f("button", {
845
- type: "button",
846
- className: "cp-link cp-back",
847
- onClick: () => t("businesses"),
848
- children: T("business.all")
849
- }), c = xe(o, s), { business: l, types: u } = o;
850
- if (c || !l || !u) return c;
851
- let m = u.find((e) => e.id === i), h = a ? Se(m ? [m] : u) : [], g = h.some((t) => t.id === e.resourceId) ? e.resourceId : void 0, _ = (e) => {
852
- if (!a) return t(e ? {
853
- businessId: r,
854
- eventTypeId: e
855
- } : { businessId: r });
856
- let n = u.find((t) => t.id === e), i = g && Se(n ? [n] : u).some((e) => e.id === g);
857
- a({
858
- ...e && { eventTypeId: e },
859
- ...i && { resourceId: g }
763
+ }, [
764
+ n,
765
+ c.id,
766
+ l
767
+ ]), y = o(!1);
768
+ r(() => {
769
+ y.current || (y.current = !0, v());
770
+ }, [v]);
771
+ async function b(t, r) {
772
+ h({
773
+ step: "confirming",
774
+ reservationId: t,
775
+ expiresAt: r
860
776
  });
861
- };
777
+ try {
778
+ let { data: r } = await n.POST(me, { params: { path: {
779
+ businessId: c.id,
780
+ reservationId: t
781
+ } } });
782
+ if (!r) return;
783
+ e.onBooked?.(r);
784
+ let i = await n.GET("/web/businesses/{businessId}/bookings/{bookingId}", { params: { path: {
785
+ businessId: c.id,
786
+ bookingId: r.id
787
+ } } }).then(({ data: e }) => e ?? null).catch(() => null);
788
+ h({
789
+ step: "booked",
790
+ booking: i
791
+ });
792
+ } catch (e) {
793
+ let t = u(e, "post", me) ? e : void 0;
794
+ t?.code === "ReservationExpired" || t?.code === "ReservationNotFound" ? h({
795
+ step: "refused",
796
+ message: "book.expired",
797
+ again: !0
798
+ }) : h({
799
+ step: "refused",
800
+ ...ge(t, ve, l.timezone),
801
+ again: !1
802
+ });
803
+ }
804
+ }
805
+ let S = /* @__PURE__ */ f("button", {
806
+ type: "button",
807
+ className: "cp-secondary",
808
+ onClick: e.onBack,
809
+ children: T("book.back")
810
+ });
862
811
  return /* @__PURE__ */ p("section", {
863
812
  className: "cp-screen",
864
- children: [
865
- s,
866
- /* @__PURE__ */ f(we, { business: l }),
867
- u.length > 0 && /* @__PURE__ */ p("fieldset", {
868
- className: "cp-chips",
869
- "aria-label": T("business.types"),
813
+ children: [/* @__PURE__ */ f("h1", { children: T("book.heading") }), m.step === "booked" ? /* @__PURE__ */ p(d, { children: [
814
+ /* @__PURE__ */ f("p", {
815
+ role: "status",
816
+ className: "cp-notice",
817
+ children: T(g ?? "book.booked")
818
+ }),
819
+ m.booking ? /* @__PURE__ */ f("ul", {
820
+ className: "cp-list",
821
+ children: /* @__PURE__ */ f(re, {
822
+ booking: m.booking,
823
+ onCancelled: (e, t) => {
824
+ h({
825
+ step: "booked",
826
+ booking: e
827
+ }), _(t ? "bookings.doneLate" : "bookings.doneOnTime");
828
+ }
829
+ })
830
+ }) : /* @__PURE__ */ f(H, { choice: e.choice }),
831
+ a ? /* @__PURE__ */ f("button", {
832
+ type: "button",
833
+ className: "cp-secondary",
834
+ onClick: () => i("bookings"),
835
+ children: T("book.toBookings")
836
+ }) : e.onDone && /* @__PURE__ */ f("button", {
837
+ type: "button",
838
+ className: "cp-secondary",
839
+ onClick: e.onDone,
840
+ children: T("book.done")
841
+ })
842
+ ] }) : /* @__PURE__ */ p(d, { children: [
843
+ /* @__PURE__ */ f(H, { choice: e.choice }),
844
+ m.step === "reserving" && /* @__PURE__ */ f("p", {
845
+ role: "status",
846
+ children: T("book.reserving")
847
+ }),
848
+ (m.step === "held" || m.step === "confirming") && /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("p", {
849
+ className: "cp-hint",
850
+ children: T("book.heldUntil", { time: A(m.expiresAt, l.timezone) })
851
+ }), /* @__PURE__ */ p("div", {
852
+ className: "cp-actions",
870
853
  children: [/* @__PURE__ */ f("button", {
871
854
  type: "button",
872
- "aria-pressed": !i,
873
- onClick: () => _(void 0),
874
- children: T("business.allTypes")
875
- }), u.map((e) => /* @__PURE__ */ f("button", {
855
+ disabled: m.step === "confirming",
856
+ onClick: () => b(m.reservationId, m.expiresAt),
857
+ children: m.step === "confirming" ? T("book.confirming") : T("book.confirm")
858
+ }), S]
859
+ })] }),
860
+ m.step === "refused" && /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("p", {
861
+ role: "alert",
862
+ children: T(m.message, m.date ? { date: m.date } : {})
863
+ }), /* @__PURE__ */ p("div", {
864
+ className: "cp-actions",
865
+ children: [m.again && /* @__PURE__ */ f("button", {
876
866
  type: "button",
877
- "aria-pressed": e.id === i,
878
- onClick: () => _(e.id),
879
- children: e.displayName
880
- }, e.id))]
881
- }),
882
- a && h.length > 1 && /* @__PURE__ */ p("fieldset", {
883
- className: "cp-chips",
884
- children: [
885
- /* @__PURE__ */ f("legend", { children: T("business.resources") }),
886
- /* @__PURE__ */ f("button", {
887
- type: "button",
888
- "aria-pressed": !g,
889
- onClick: () => a({ ...i && { eventTypeId: i } }),
890
- children: T("business.anyResource")
891
- }),
892
- h.map((e) => /* @__PURE__ */ f("button", {
893
- type: "button",
894
- "aria-pressed": e.id === g,
895
- onClick: () => a({
896
- ...i && { eventTypeId: i },
897
- resourceId: e.id
898
- }),
899
- children: e.displayName
900
- }, e.id))
901
- ]
902
- }),
903
- i && !m ? /* @__PURE__ */ f("p", {
904
- className: "cp-empty",
905
- children: T("business.typeMissing")
906
- }) : /* @__PURE__ */ p(d, { children: [m && /* @__PURE__ */ f(J, { type: m }), /* @__PURE__ */ f(Te, {
907
- business: l,
908
- eventTypeId: i,
909
- resourceId: g,
910
- onChoose: (t) => e.onChoose(l, t)
867
+ onClick: v,
868
+ children: T("book.reserveAgain")
869
+ }), S]
911
870
  })] })
912
- ]
871
+ ] })]
913
872
  });
914
873
  }
915
- function we({ business: e }) {
916
- return /* @__PURE__ */ p("header", {
917
- className: "cp-business-head",
918
- children: [/* @__PURE__ */ f(K, {
919
- image: e.logo,
920
- alt: T("image.logo", { name: e.displayName }),
921
- size: "small",
922
- className: "cp-logo"
923
- }), /* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("h1", { children: e.displayName }), e.address && /* @__PURE__ */ f("p", {
924
- className: "cp-hint",
925
- children: e.address
926
- })] })]
927
- });
874
+ function ge(e, t, n) {
875
+ if (e?.code !== "BookingBanned") return { message: t(e?.code) };
876
+ let { bannedUntil: r } = e.body ?? {};
877
+ return r ? {
878
+ message: "book.banned",
879
+ date: j(r, n)
880
+ } : { message: "book.banned.undated" };
881
+ }
882
+ function _e(e) {
883
+ switch (e) {
884
+ case "EventFull": return "book.full";
885
+ case "SlotTaken": return "book.slotTaken";
886
+ case "ReservationLimitReached": return "book.limit";
887
+ case "NotAuthorized": return "book.notAllowed";
888
+ case "EventStarted":
889
+ case "EventNotBookable":
890
+ case "NotATimeSlot":
891
+ case "EventNotFound":
892
+ case "EventTypeNotFound":
893
+ case "BusinessNotFound": return "book.unavailable";
894
+ default: return "book.failed";
895
+ }
896
+ }
897
+ function ve(e) {
898
+ switch (e) {
899
+ case "NotAuthorized": return "book.notAllowed";
900
+ case "EventStarted":
901
+ case "EventNotBookable":
902
+ case "BusinessNotFound": return "book.unavailable";
903
+ case "CustomerOutsideBusiness": return "book.refused";
904
+ default: return "book.failed";
905
+ }
906
+ }
907
+ // src/layout.tsx
908
+ function ye({ brand: e }) {
909
+ return e ? /* @__PURE__ */ p("div", {
910
+ className: "cp-brand",
911
+ children: [e.logo && /* @__PURE__ */ f("img", {
912
+ src: e.logo,
913
+ alt: ""
914
+ }), /* @__PURE__ */ f("span", { children: e.name })]
915
+ }) : null;
928
916
  }
929
- function J({ type: e }) {
917
+ var be = [["businesses", "nav.book"]], xe = [
918
+ ["bookings", "nav.bookings"],
919
+ ["passes", "nav.passes"],
920
+ ["details", "nav.details"]
921
+ ], Se = [...be, ...xe];
922
+ function Ce(e) {
923
+ let t = typeof e.screen == "string" ? e.screen : "businesses";
930
924
  return /* @__PURE__ */ p("div", {
931
- className: "cp-type",
925
+ className: "cp-shell",
932
926
  children: [
933
- /* @__PURE__ */ f(K, {
934
- image: e.image,
935
- alt: e.displayName,
936
- size: "full",
937
- className: "cp-detail-image"
927
+ /* @__PURE__ */ p("header", {
928
+ className: "cp-header",
929
+ children: [/* @__PURE__ */ f(ye, { brand: e.brand }), e.signedIn ? /* @__PURE__ */ f("button", {
930
+ type: "button",
931
+ className: "cp-link",
932
+ onClick: e.onSignOut,
933
+ children: T("nav.signOut")
934
+ }) : !e.signingIn && /* @__PURE__ */ f("button", {
935
+ type: "button",
936
+ className: "cp-link",
937
+ onClick: () => e.onNavigate("bookings"),
938
+ children: T("nav.signIn")
939
+ })]
938
940
  }),
939
- /* @__PURE__ */ f("h2", { children: e.displayName }),
940
- e.description && /* @__PURE__ */ f("p", { children: e.description }),
941
- /* @__PURE__ */ f("p", {
942
- className: "cp-hint",
943
- children: T("business.minutes", { minutes: e.durationMinutes })
941
+ /* @__PURE__ */ f("nav", {
942
+ className: "cp-nav",
943
+ "aria-label": T("nav.label"),
944
+ children: e.tabs.map(([n, r]) => /* @__PURE__ */ f("button", {
945
+ type: "button",
946
+ "aria-current": t === n ? "page" : void 0,
947
+ onClick: () => e.onNavigate(n),
948
+ children: T(r)
949
+ }, n))
950
+ }),
951
+ /* @__PURE__ */ f("main", {
952
+ className: "cp-main",
953
+ children: e.children
944
954
  })
945
955
  ]
946
956
  });
947
957
  }
948
- function Te(e) {
949
- let { client: n } = x(), { business: i, eventTypeId: a, resourceId: o } = e, c = i.timezone, [l, u] = s(0), [m, h] = s(), [g, _] = s(!1), v = q(ye(c), l * ve), y = q(v, ve), b = t(async () => {
950
- _(!1), h(void 0);
958
+ // src/client.ts
959
+ var we = (e, t) => {
960
+ let n = new Request(e, t);
961
+ return n.headers.set("X-MSM-BFF", "1"), fetch(n);
962
+ };
963
+ function U(e, t, n) {
964
+ return we(`${e}${t}`, {
965
+ method: "POST",
966
+ headers: { "content-type": "application/json" },
967
+ body: JSON.stringify(n ?? {})
968
+ });
969
+ }
970
+ function Te(e, t) {
971
+ let n = l({ baseUrl: `${e}/engine` });
972
+ return n.use({
973
+ onRequest({ request: e }) {
974
+ return e.headers.set("X-MSM-BFF", "1"), e;
975
+ },
976
+ onResponse({ response: e }) {
977
+ e.status === 401 && t();
978
+ }
979
+ }), n;
980
+ }
981
+ // src/session.ts
982
+ var Ee = /* @__PURE__ */ new Map();
983
+ function W(e) {
984
+ let t = Ee.get(e);
985
+ return t || (t = {
986
+ value: void 0,
987
+ listeners: /* @__PURE__ */ new Set(),
988
+ generation: 0
989
+ }, Ee.set(e, t)), t;
990
+ }
991
+ function G(e, t) {
992
+ let n = W(e);
993
+ if (n.value !== t) {
994
+ n.value = t;
995
+ for (let e of n.listeners) e();
996
+ }
997
+ }
998
+ function De(e, t) {
999
+ let { generation: n } = t, r = (r) => {
1000
+ t.generation === n && t.value === void 0 && G(e, r);
1001
+ };
1002
+ we(`${e}/auth/session`).then(async (e) => r(e.ok ? (await e.json()).sessionKey : null)).catch(() => r(null));
1003
+ }
1004
+ function Oe(e, t) {
1005
+ let n = W(e);
1006
+ return n.listeners.size === 0 && n.value === void 0 && De(e, n), n.listeners.add(t), () => {
1007
+ n.listeners.delete(t), n.listeners.size === 0 && queueMicrotask(() => {
1008
+ n.listeners.size > 0 || (n.value = void 0, n.generation++);
1009
+ });
1010
+ };
1011
+ }
1012
+ function ke(e, t) {
1013
+ let n = c((t) => Oe(e, t), () => W(e).value, () => void 0), i = o(void 0), a = o(t);
1014
+ return a.current = t, r(() => {
1015
+ if (n === void 0) return;
1016
+ let e = n !== null;
1017
+ i.current !== void 0 && i.current !== e && a.current?.(e), i.current = e;
1018
+ }, [n]), n;
1019
+ }
1020
+ // src/portal.tsx
1021
+ function K(e) {
1022
+ let { navigate: n, accountNavigation: i } = e, c = e.basePath.replace(/\/$/, ""), l = ke(c, e.onSessionChange), u = o(!1);
1023
+ u.current = !!l;
1024
+ let [d, f] = s(), [p, m] = s(/* @__PURE__ */ new Map()), [h, g] = s("loading"), _ = a(() => Te(c, () => {
1025
+ u.current && f("app.signedOut"), G(c, null);
1026
+ }), [c]), v = t(async () => {
1027
+ g("loading");
951
1028
  try {
952
- let { data: e } = await n.GET("/web/businesses/{businessId}/availability", { params: {
953
- path: { businessId: i.id },
954
- query: {
955
- from: `${v}T00:00`,
956
- to: `${y}T00:00`,
957
- ...a && { eventTypeId: a },
958
- ...o && { resourceId: o }
959
- }
960
- } });
961
- h(e?.items ?? []);
1029
+ let e = /* @__PURE__ */ new Map(), t;
1030
+ do {
1031
+ let { data: n } = await _.GET("/web/businesses", { params: { query: {
1032
+ limit: 100,
1033
+ ...t && { cursor: t }
1034
+ } } });
1035
+ for (let t of n?.items ?? []) e.set(t.id, t);
1036
+ t = n?.nextCursor ?? void 0;
1037
+ } while (t);
1038
+ m(e), g("ready");
962
1039
  } catch {
963
- _(!0);
1040
+ g("failed");
964
1041
  }
965
- }, [
966
- n,
967
- i.id,
968
- a,
969
- o,
970
- v,
971
- y
972
- ]);
973
- r(() => {
974
- b();
975
- }, [b]);
976
- let S = Date.now(), C = /* @__PURE__ */ new Map();
977
- for (let e of m ?? []) {
978
- if (Date.parse(e.startsAt) <= S) continue;
979
- let t = M(e.startsAt, e.timezone);
980
- C.set(t, [...C.get(t) ?? [], e]);
981
- }
982
- let w = T("business.weekOf", {
983
- from: j(`${v}T12:00:00Z`, "UTC"),
984
- to: j(`${q(y, -1)}T12:00:00Z`, "UTC")
985
- });
986
- return /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("fieldset", {
987
- className: "cp-week",
988
- "aria-label": T("business.week"),
989
- children: [
990
- /* @__PURE__ */ f("button", {
991
- type: "button",
992
- className: "cp-secondary",
993
- disabled: l === 0,
994
- onClick: () => u((e) => e - 1),
995
- "aria-label": T("business.previousWeek"),
996
- children: "‹"
997
- }),
998
- /* @__PURE__ */ f("span", { children: w }),
999
- /* @__PURE__ */ f("button", {
1000
- type: "button",
1001
- className: "cp-secondary",
1002
- onClick: () => u((e) => e + 1),
1003
- "aria-label": T("business.nextWeek"),
1004
- children: "›"
1005
- })
1006
- ]
1007
- }), g ? /* @__PURE__ */ f(I, { onRetry: b }) : m ? C.size === 0 ? /* @__PURE__ */ f("p", {
1008
- className: "cp-empty",
1009
- children: T("business.empty")
1010
- }) : [...C].map(([t, n]) => /* @__PURE__ */ p("div", {
1011
- className: "cp-day",
1012
- children: [/* @__PURE__ */ f("h2", { children: t }), /* @__PURE__ */ f("ul", {
1013
- className: "cp-list",
1014
- children: n.map((t) => /* @__PURE__ */ f(Ee, {
1015
- candidate: t,
1016
- onChoose: () => e.onChoose(t)
1017
- }, `${t.eventId ?? t.eventTypeId}-${t.resource?.id ?? ""}-${t.startsAt}`))
1018
- })]
1019
- }, t)) : /* @__PURE__ */ f("p", {
1020
- role: "status",
1021
- children: T("app.loading")
1022
- })] });
1042
+ }, [_]);
1043
+ return r(() => {
1044
+ v();
1045
+ }, [v]), {
1046
+ basePath: c,
1047
+ sessionKey: l,
1048
+ notice: d,
1049
+ portal: a(() => ({
1050
+ client: _,
1051
+ businesses: p,
1052
+ businessesStatus: h,
1053
+ reloadBusinesses: () => void v(),
1054
+ navigate: n,
1055
+ accountNavigation: i,
1056
+ signOut: async (e) => {
1057
+ await U(c, "/auth/logout").catch(() => {}), f(e), G(c, null);
1058
+ }
1059
+ }), [
1060
+ _,
1061
+ p,
1062
+ h,
1063
+ v,
1064
+ n,
1065
+ i,
1066
+ c
1067
+ ]),
1068
+ signedInAs: t((e) => {
1069
+ f(void 0), G(c, e);
1070
+ }, [c])
1071
+ };
1023
1072
  }
1024
- function Ee(e) {
1025
- let { candidate: t } = e, n = t.kind === "slot";
1026
- return /* @__PURE__ */ p("li", {
1027
- className: "cp-card cp-candidate",
1028
- "data-kind": t.kind,
1029
- children: [
1030
- /* @__PURE__ */ p("p", {
1031
- className: "cp-time",
1032
- children: [
1033
- A(t.startsAt, t.timezone),
1034
- " – ",
1035
- A(t.endsAt, t.timezone)
1036
- ]
1037
- }),
1038
- /* @__PURE__ */ p("div", {
1039
- className: "cp-candidate-body",
1040
- children: [
1041
- /* @__PURE__ */ f("h3", { children: t.title }),
1042
- t.resource && /* @__PURE__ */ f("p", {
1043
- className: "cp-hint",
1044
- children: T("business.with", { resource: t.resource.displayName })
1045
- }),
1046
- /* @__PURE__ */ f("p", {
1047
- className: "cp-hint",
1048
- children: n ? T("business.openTime") : t.full ? T("business.full") : D("business.seatsLeft", t.seatsLeft)
1049
- })
1050
- ]
1051
- }),
1052
- !t.full && /* @__PURE__ */ f("button", {
1053
- type: "button",
1054
- onClick: e.onChoose,
1055
- children: T("business.book")
1056
- })
1057
- ]
1073
+ function q(e) {
1074
+ return /* @__PURE__ */ f("div", {
1075
+ className: "msm-customer",
1076
+ children: e.loading ? /* @__PURE__ */ f("p", {
1077
+ className: "cp-status",
1078
+ role: "status",
1079
+ children: T("app.loading")
1080
+ }) : /* @__PURE__ */ f(b.Provider, {
1081
+ value: e.portal,
1082
+ children: e.children
1083
+ })
1058
1084
  });
1059
1085
  }
1060
1086
  // src/screens/businesses.tsx
1061
- function De() {
1087
+ function Ae() {
1062
1088
  let { businesses: e, businessesStatus: t, reloadBusinesses: n, navigate: r } = x(), i = [...e.values()];
1063
1089
  return /* @__PURE__ */ p("section", {
1064
1090
  className: "cp-screen",
1065
- children: [/* @__PURE__ */ f("h1", { children: T("businesses.heading") }), t === "failed" ? /* @__PURE__ */ f(I, { onRetry: n }) : t === "loading" ? /* @__PURE__ */ f("p", {
1091
+ children: [/* @__PURE__ */ f("h1", { children: T("businesses.heading") }), t === "failed" ? /* @__PURE__ */ f(F, { onRetry: n }) : t === "loading" ? /* @__PURE__ */ f("p", {
1066
1092
  role: "status",
1067
1093
  children: T("app.loading")
1068
1094
  }) : i.length === 0 ? /* @__PURE__ */ f("p", {
@@ -1076,7 +1102,7 @@ function De() {
1076
1102
  children: i.map((e) => /* @__PURE__ */ p("li", {
1077
1103
  className: "cp-card cp-business",
1078
1104
  children: [
1079
- /* @__PURE__ */ f(K, {
1105
+ /* @__PURE__ */ f(I, {
1080
1106
  image: e.logo,
1081
1107
  alt: "",
1082
1108
  size: "small",
@@ -1095,7 +1121,7 @@ function De() {
1095
1121
  });
1096
1122
  }
1097
1123
  // src/screens/details.tsx
1098
- function Oe() {
1124
+ function je() {
1099
1125
  let { client: e, signOut: n } = x(), [i, a] = s(), [o, c] = s(""), [l, u] = s(!1), [m, h] = s(!1), [g, _] = s(), v = t(async () => {
1100
1126
  u(!1);
1101
1127
  try {
@@ -1140,7 +1166,7 @@ function Oe() {
1140
1166
  }
1141
1167
  return /* @__PURE__ */ p("section", {
1142
1168
  className: "cp-screen",
1143
- children: [/* @__PURE__ */ f("h1", { children: T("details.heading") }), l ? /* @__PURE__ */ f(I, { onRetry: v }) : i ? /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("form", {
1169
+ children: [/* @__PURE__ */ f("h1", { children: T("details.heading") }), l ? /* @__PURE__ */ f(F, { onRetry: v }) : i ? /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("form", {
1144
1170
  className: "cp-card cp-form",
1145
1171
  onSubmit: y,
1146
1172
  "aria-busy": m,
@@ -1191,7 +1217,7 @@ function Oe() {
1191
1217
  });
1192
1218
  }
1193
1219
  // src/screens/passes.tsx
1194
- function ke() {
1220
+ function Me() {
1195
1221
  let { client: e, businesses: n } = x(), [i, a] = s(), [o, c] = s(!1), l = t(async () => {
1196
1222
  c(!1);
1197
1223
  try {
@@ -1205,7 +1231,7 @@ function ke() {
1205
1231
  l();
1206
1232
  }, [l]), /* @__PURE__ */ p("section", {
1207
1233
  className: "cp-screen",
1208
- children: [/* @__PURE__ */ f("h1", { children: T("passes.heading") }), o ? /* @__PURE__ */ f(I, { onRetry: l }) : i ? i.length === 0 ? /* @__PURE__ */ f("p", {
1234
+ children: [/* @__PURE__ */ f("h1", { children: T("passes.heading") }), o ? /* @__PURE__ */ f(F, { onRetry: l }) : i ? i.length === 0 ? /* @__PURE__ */ f("p", {
1209
1235
  className: "cp-empty",
1210
1236
  children: T("passes.empty")
1211
1237
  }) : /* @__PURE__ */ f("ul", {
@@ -1247,13 +1273,13 @@ function ke() {
1247
1273
  });
1248
1274
  }
1249
1275
  // ../ui/dist/index.js
1250
- var Ae = new Intl.DisplayNames(["en"], { type: "region" }), je = (e) => e.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim(), Y = h().map((e) => ({
1276
+ var Ne = new Intl.DisplayNames(["en"], { type: "region" }), Pe = (e) => e.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim(), J = h().map((e) => ({
1251
1277
  code: e,
1252
- name: Ae.of(e) ?? e,
1278
+ name: Ne.of(e) ?? e,
1253
1279
  callingCode: g(e),
1254
1280
  flag: String.fromCodePoint(...[...e].map((e) => 127397 + e.charCodeAt(0)))
1255
- })).sort((e, t) => e.name.localeCompare(t.name)), Me = new Map(Y.map((e) => [e.code, e])), Ne = (e) => Me.get(e);
1256
- function Pe(e) {
1281
+ })).sort((e, t) => e.name.localeCompare(t.name)), Fe = new Map(J.map((e) => [e.code, e])), Ie = (e) => Fe.get(e);
1282
+ function Le(e) {
1257
1283
  let t = i(), n = o(null), a = o(null), c = o(null), [l, u] = s(""), d = e.search(l), m = () => n.current?.close(), h = (t) => {
1258
1284
  m(), e.onPick(t);
1259
1285
  };
@@ -1327,10 +1353,10 @@ function Pe(e) {
1327
1353
  ]
1328
1354
  });
1329
1355
  }
1330
- var Fe = new m(), X = (e) => Ne(e);
1331
- function Ie(e) {
1356
+ var Re = new m(), Y = (e) => Ie(e);
1357
+ function ze(e) {
1332
1358
  for (let t = 1; t <= 3 && t <= e.length; t++) {
1333
- let n = e.slice(0, t), r = (y.country_calling_codes[n] ?? []).filter((e) => Ne(e) !== void 0), [i] = r;
1359
+ let n = e.slice(0, t), r = (y.country_calling_codes[n] ?? []).filter((e) => Ie(e) !== void 0), [i] = r;
1334
1360
  if (i) return {
1335
1361
  code: n,
1336
1362
  first: i,
@@ -1339,10 +1365,10 @@ function Ie(e) {
1339
1365
  }
1340
1366
  return null;
1341
1367
  }
1342
- function Le(e, t) {
1368
+ function Be(e, t) {
1343
1369
  let n = /^\s*(\+|00)/.exec(e);
1344
1370
  if (!n) return null;
1345
- let r = e.slice(n[0].length), i = r.replace(/\D/g, ""), a = Ie(i);
1371
+ let r = e.slice(n[0].length), i = r.replace(/\D/g, ""), a = ze(i);
1346
1372
  if (!a) return null;
1347
1373
  let o = _(`+${i}`), s = a.countries.includes(t) ? t : o?.country ?? a.first, c = 0;
1348
1374
  for (let e = 0; e < a.code.length; c++) /\d/.test(r.charAt(c)) && e++;
@@ -1351,45 +1377,45 @@ function Le(e, t) {
1351
1377
  text: o?.isValid() ? o.formatNational() : r.slice(c).replace(/^[\s\-().]+/, "")
1352
1378
  };
1353
1379
  }
1354
- function Re(e, t) {
1380
+ function Ve(e, t) {
1355
1381
  let n = t.replace(/\D/g, "");
1356
- return n === "" ? "" : t.trim().startsWith("+") ? `+${n}` : _(t, e)?.number ?? `+${X(e).callingCode}${n}`;
1382
+ return n === "" ? "" : t.trim().startsWith("+") ? `+${n}` : _(t, e)?.number ?? `+${Y(e).callingCode}${n}`;
1357
1383
  }
1358
- function ze(e) {
1359
- return Fe.selectNumberingPlan(e), Fe.numberingPlan?.possibleLengths() ?? [];
1384
+ function He(e) {
1385
+ return Re.selectNumberingPlan(e), Re.numberingPlan?.possibleLengths() ?? [];
1360
1386
  }
1361
- function Be(e, t, n) {
1387
+ function Ue(e, t, n) {
1362
1388
  if (e === "") return t ? "Enter a phone number." : "";
1363
1389
  let r = _(e);
1364
1390
  if (r?.isValid()) return "";
1365
- let i = e.replace(/\D/g, ""), a = Ie(i);
1391
+ let i = e.replace(/\D/g, ""), a = ze(i);
1366
1392
  if (!a) return "Unknown country code. Choose the country from the list.";
1367
- let o = n && a.countries.includes(n) ? n : r?.country ?? a.first, s = X(o).name, c = v(i.slice(a.code.length), o);
1393
+ let o = n && a.countries.includes(n) ? n : r?.country ?? a.first, s = Y(o).name, c = v(i.slice(a.code.length), o);
1368
1394
  if (c && c !== "NOT_A_NUMBER") {
1369
- let e = ze(o), t = e[0] ?? 0, n = e[e.length - 1] ?? 0;
1395
+ let e = He(o), t = e[0] ?? 0, n = e[e.length - 1] ?? 0;
1370
1396
  return e.length === 1 ? `Enter a ${t}-digit number for ${s}.` : e.length > 2 && n - t === e.length - 1 ? `Enter ${t} to ${n} digits for ${s}.` : `Enter ${e.slice(0, -1).join(", ")} or ${n} digits for ${s}.`;
1371
1397
  }
1372
1398
  return `This is not a valid number for ${s}.`;
1373
1399
  }
1374
- function Ve(e, t = !1) {
1375
- return Be(e, t);
1400
+ function We(e, t = !1) {
1401
+ return Ue(e, t);
1376
1402
  }
1377
- function He(e, t) {
1378
- return Le(e, t) ?? {
1403
+ function Ge(e, t) {
1404
+ return Be(e, t) ?? {
1379
1405
  country: t,
1380
1406
  text: e
1381
1407
  };
1382
1408
  }
1383
- function Ue(e) {
1409
+ function Ke(e) {
1384
1410
  let t = i(), n = o(null), [a, c] = s(() => ({
1385
1411
  value: e.value,
1386
- ...He(e.value, "IS")
1412
+ ...Ge(e.value, "IS")
1387
1413
  })), l = a;
1388
1414
  e.value !== a.value && (l = {
1389
1415
  value: e.value,
1390
- ...He(e.value, a.country)
1416
+ ...Ge(e.value, a.country)
1391
1417
  }, c(l));
1392
- let [u, d] = s(!1), [m, h] = s(!1), g = X(l.country), _ = Be(l.value, e.required ?? !1, l.country), v = u && _ !== "" ? _ : e.error ?? "", y = v !== "";
1418
+ let [u, d] = s(!1), [m, h] = s(!1), g = Y(l.country), _ = Ue(l.value, e.required ?? !1, l.country), v = u && _ !== "" ? _ : e.error ?? "", y = v !== "";
1393
1419
  r(() => {
1394
1420
  let e = n.current?.form;
1395
1421
  if (!e) return;
@@ -1399,7 +1425,7 @@ function Ue(e) {
1399
1425
  return e.addEventListener("submit", t), () => e.removeEventListener("submit", t);
1400
1426
  }, []);
1401
1427
  let b = (t, n) => {
1402
- let r = Re(t, n);
1428
+ let r = Ve(t, n);
1403
1429
  c({
1404
1430
  value: r,
1405
1431
  country: t,
@@ -1442,7 +1468,7 @@ function Ue(e) {
1442
1468
  "aria-invalid": y || void 0,
1443
1469
  "aria-describedby": y ? `${t}-problem` : void 0,
1444
1470
  onChange: (e) => {
1445
- let t = e.target.value.replace(/[^\d\s\-().+]/g, ""), n = Le(t, l.country);
1471
+ let t = e.target.value.replace(/[^\d\s\-().+]/g, ""), n = Be(t, l.country);
1446
1472
  b(n?.country ?? l.country, n?.text ?? t);
1447
1473
  },
1448
1474
  onBlur: () => {
@@ -1456,12 +1482,12 @@ function Ue(e) {
1456
1482
  role: "alert",
1457
1483
  children: v
1458
1484
  }),
1459
- m && /* @__PURE__ */ f(Pe, {
1485
+ m && /* @__PURE__ */ f(Le, {
1460
1486
  title: "Country code",
1461
1487
  searchLabel: "Search by country or code",
1462
1488
  listLabel: "Countries",
1463
1489
  empty: (e) => `No country matches “${e}”.`,
1464
- search: We,
1490
+ search: qe,
1465
1491
  selected: l.country,
1466
1492
  onClose: () => h(!1),
1467
1493
  onPick: (e) => {
@@ -1471,41 +1497,95 @@ function Ue(e) {
1471
1497
  ]
1472
1498
  });
1473
1499
  }
1474
- function We(e) {
1475
- let t = je(e).replace(/^(\+|00)/, "");
1476
- return (t === "" ? Y : /^\d+$/.test(t) ? Y.filter((e) => e.callingCode.startsWith(t)) : Y.filter((e) => je(e.name).includes(t) || e.code.toLowerCase() === t)).map((e) => ({
1500
+ function qe(e) {
1501
+ let t = Pe(e).replace(/^(\+|00)/, "");
1502
+ return (t === "" ? J : /^\d+$/.test(t) ? J.filter((e) => e.callingCode.startsWith(t)) : J.filter((e) => Pe(e.name).includes(t) || e.code.toLowerCase() === t)).map((e) => ({
1477
1503
  value: e.code,
1478
1504
  label: e.name,
1479
1505
  hint: `+${e.callingCode}`,
1480
1506
  flag: e.flag
1481
1507
  }));
1482
1508
  }
1509
+ var X = {
1510
+ red: {
1511
+ light: "#d14b4b",
1512
+ dark: "#f07a7a"
1513
+ },
1514
+ orange: {
1515
+ light: "#d9773a",
1516
+ dark: "#f29a62"
1517
+ },
1518
+ amber: {
1519
+ light: "#b8891a",
1520
+ dark: "#e3b847"
1521
+ },
1522
+ lime: {
1523
+ light: "#6f9a1f",
1524
+ dark: "#a5cf4f"
1525
+ },
1526
+ green: {
1527
+ light: "#2f9a69",
1528
+ dark: "#5cc194"
1529
+ },
1530
+ teal: {
1531
+ light: "#24918f",
1532
+ dark: "#4fc0bd"
1533
+ },
1534
+ cyan: {
1535
+ light: "#1d8fb3",
1536
+ dark: "#5bc0e0"
1537
+ },
1538
+ blue: {
1539
+ light: "#4a7fe0",
1540
+ dark: "#7ea6f5"
1541
+ },
1542
+ indigo: {
1543
+ light: "#6366d8",
1544
+ dark: "#9a9cf2"
1545
+ },
1546
+ purple: {
1547
+ light: "#9666cf",
1548
+ dark: "#bb9be6"
1549
+ },
1550
+ pink: {
1551
+ light: "#cf5c94",
1552
+ dark: "#ea8cba"
1553
+ },
1554
+ slate: {
1555
+ light: "#6c778a",
1556
+ dark: "#9aa5b5"
1557
+ }
1558
+ };
1559
+ function Je(e) {
1560
+ let { light: t, dark: n } = X[e in X ? e : "slate"];
1561
+ return `light-dark(${t}, ${n})`;
1562
+ }
1483
1563
  // src/bot-check.tsx
1484
- var Ge = () => window.turnstile, Ke = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit", Z;
1485
- function qe() {
1486
- let e = Ge();
1564
+ var Ye = () => window.turnstile, Xe = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit", Z;
1565
+ function Ze() {
1566
+ let e = Ye();
1487
1567
  return e ? Promise.resolve(e) : (Z ??= new Promise((e, t) => {
1488
1568
  let n = document.createElement("script");
1489
- n.src = Ke, n.async = !0;
1569
+ n.src = Xe, n.async = !0;
1490
1570
  let r = () => {
1491
1571
  Z = void 0, n.remove(), t(/* @__PURE__ */ Error("Turnstile did not load."));
1492
1572
  };
1493
1573
  n.onload = () => {
1494
- let t = Ge();
1574
+ let t = Ye();
1495
1575
  t ? e(t) : r();
1496
1576
  }, n.onerror = r, document.head.append(n);
1497
1577
  }), Z);
1498
1578
  }
1499
- function Je(e) {
1579
+ function Qe(e) {
1500
1580
  return e?.provider === "turnstile" && typeof e.siteKey == "string" && e.siteKey.trim() !== "";
1501
1581
  }
1502
- function Ye(e) {
1582
+ function $e(e) {
1503
1583
  let t = o(null), n = o(void 0), i = o(e);
1504
1584
  i.current = e;
1505
1585
  let { siteKey: a } = e.botCheck;
1506
1586
  r(() => {
1507
1587
  let e = !0;
1508
- return qe().then((r) => {
1588
+ return Ze().then((r) => {
1509
1589
  let o = t.current;
1510
1590
  if (!e || !o) return;
1511
1591
  let s = r.render(o, {
@@ -1542,7 +1622,7 @@ function Q(e) {
1542
1622
  r(() => {
1543
1623
  n && t.current?.querySelector("input")?.focus();
1544
1624
  }, [n]);
1545
- let [i, a] = s("phone"), [c, l] = s(""), [u, m] = s(""), [h, g] = s(""), [_, v] = s(), [y, b] = s(), [x, S] = s(!1), [C, w] = s(), [E, D] = s(0), O = Je(e.botCheck) ? e.botCheck : void 0, [k, A] = s();
1625
+ let [i, a] = s("phone"), [c, l] = s(""), [u, m] = s(""), [h, g] = s(""), [_, v] = s(), [y, b] = s(), [x, S] = s(!1), [C, w] = s(), [E, D] = s(0), O = Qe(e.botCheck) ? e.botCheck : void 0, [k, A] = s();
1546
1626
  r(() => {
1547
1627
  if (!k) return;
1548
1628
  let e = setTimeout(() => {
@@ -1554,16 +1634,16 @@ function Q(e) {
1554
1634
  a("phone"), v(void 0), g(""), l(""), b(e);
1555
1635
  }
1556
1636
  async function M(t) {
1557
- if (t.preventDefault(), (i !== "phone" || !Ve(u, !0) && O && C) && (i !== "name" || c.trim())) {
1637
+ if (t.preventDefault(), (i !== "phone" || !We(u, !0) && O && C) && (i !== "name" || c.trim())) {
1558
1638
  S(!0), b(void 0);
1559
1639
  try {
1560
- let t = i === "phone" ? await B(e.basePath, "/auth/initiate", {
1640
+ let t = i === "phone" ? await U(e.basePath, "/auth/initiate", {
1561
1641
  phone: u,
1562
1642
  botCheckToken: C
1563
- }) : i === "code" ? await B(e.basePath, "/auth/login", {
1643
+ }) : i === "code" ? await U(e.basePath, "/auth/login", {
1564
1644
  challenge: _,
1565
1645
  code: h
1566
- }) : await B(e.basePath, "/auth/register", { name: c.trim() });
1646
+ }) : await U(e.basePath, "/auth/register", { name: c.trim() });
1567
1647
  if (t.ok) {
1568
1648
  let n = await t.json();
1569
1649
  i === "phone" ? (v(n.challenge), a("code")) : n.result === "nameRequired" ? a("name") : e.onSignedIn(n.sessionKey);
@@ -1574,7 +1654,7 @@ function Q(e) {
1574
1654
  j(T("register.error.expired"));
1575
1655
  return;
1576
1656
  }
1577
- let r = Number(t.headers.get("retry-after")), o = Number.isInteger(r) && r > 0 ? r : void 0, s = Xe(t.status, n?.code, o, i);
1657
+ let r = Number(t.headers.get("retry-after")), o = Number.isInteger(r) && r > 0 ? r : void 0, s = et(t.status, n?.code, o, i);
1578
1658
  t.status === 429 && o && i === "phone" && A({
1579
1659
  phone: u,
1580
1660
  seconds: o,
@@ -1594,7 +1674,7 @@ function Q(e) {
1594
1674
  onSubmit: M,
1595
1675
  "aria-busy": x,
1596
1676
  children: [
1597
- /* @__PURE__ */ f(R, { brand: e.brand }),
1677
+ /* @__PURE__ */ f(ye, { brand: e.brand }),
1598
1678
  /* @__PURE__ */ f("h1", { children: T("signIn.heading") }),
1599
1679
  e.children,
1600
1680
  e.notice && i === "phone" && /* @__PURE__ */ f("p", {
@@ -1618,13 +1698,13 @@ function Q(e) {
1618
1698
  autoFocus: !0
1619
1699
  })] })] }) : /* @__PURE__ */ p(d, { children: [
1620
1700
  /* @__PURE__ */ f("p", { children: T("signIn.intro") }),
1621
- /* @__PURE__ */ f(Ue, {
1701
+ /* @__PURE__ */ f(Ke, {
1622
1702
  label: T("signIn.phone"),
1623
1703
  value: u,
1624
1704
  onChange: m,
1625
1705
  required: !0
1626
1706
  }),
1627
- O && /* @__PURE__ */ f(Ye, {
1707
+ O && /* @__PURE__ */ f($e, {
1628
1708
  botCheck: O,
1629
1709
  attempt: E,
1630
1710
  onToken: w,
@@ -1660,11 +1740,11 @@ function Q(e) {
1660
1740
  })
1661
1741
  });
1662
1742
  }
1663
- function Xe(e, t, n, r) {
1664
- if (e === 429) return n ? T("signIn.error.tooMany", { wait: P(n) }) : T("signIn.error.tooManyLater");
1743
+ function et(e, t, n, r) {
1744
+ if (e === 429) return n ? T("signIn.error.tooMany", { wait: ee(n) }) : T("signIn.error.tooManyLater");
1665
1745
  if (r === "name" && (e === 400 || e === 422)) return T("register.error.name");
1666
1746
  let i = r === "phone";
1667
- return i && e === 403 && t === "BotCheckFailed" ? T("signIn.error.botCheck") : i && e === 503 && t === "BotCheckUnavailable" ? T("signIn.error.botCheckUnavailable") : i && e === 503 && (t === "LimiterUnavailable" || t === "ClientIpUnavailable") ? T("signIn.error.failed") : i && e === 503 ? n ? T("signIn.error.paused", { wait: P(n) }) : T("signIn.error.pausedLater") : i && e === 422 && t === "PhoneDestinationNotAllowed" ? T("signIn.error.destination") : r === "code" && [
1747
+ return i && e === 403 && t === "BotCheckFailed" ? T("signIn.error.botCheck") : i && e === 503 && t === "BotCheckUnavailable" ? T("signIn.error.botCheckUnavailable") : i && e === 503 && (t === "LimiterUnavailable" || t === "ClientIpUnavailable") ? T("signIn.error.failed") : i && e === 503 ? n ? T("signIn.error.paused", { wait: ee(n) }) : T("signIn.error.pausedLater") : i && e === 422 && t === "PhoneDestinationNotAllowed" ? T("signIn.error.destination") : r === "code" && [
1668
1748
  400,
1669
1749
  401,
1670
1750
  403,
@@ -1673,27 +1753,27 @@ function Xe(e, t, n, r) {
1673
1753
  ].includes(e) ? T("signIn.error.badCode") : T(e === 400 ? "signIn.error.invalid" : e === 403 ? "signIn.error.refused" : "signIn.error.failed");
1674
1754
  }
1675
1755
  // src/account.tsx
1676
- function Ze(e) {
1756
+ function tt(e) {
1677
1757
  let [n, r] = s("bookings"), i = e.screen ?? n, a = e.onNavigate ?? r, o = t((e) => {
1678
1758
  (e === "bookings" || e === "passes" || e === "details") && a(e);
1679
- }, [a]), { basePath: c, sessionKey: l, notice: u, portal: d, signedInAs: p } = W({
1759
+ }, [a]), { basePath: c, sessionKey: l, notice: u, portal: d, signedInAs: p } = K({
1680
1760
  basePath: e.basePath,
1681
1761
  navigate: o,
1682
1762
  accountNavigation: !0,
1683
1763
  onSessionChange: e.onSessionChange
1684
1764
  });
1685
- return /* @__PURE__ */ f(G, {
1765
+ return /* @__PURE__ */ f(q, {
1686
1766
  portal: d,
1687
1767
  loading: l === void 0,
1688
- children: /* @__PURE__ */ f(de, {
1768
+ children: /* @__PURE__ */ f(Ce, {
1689
1769
  brand: e.brand,
1690
- tabs: le,
1770
+ tabs: xe,
1691
1771
  screen: i,
1692
1772
  signedIn: !!l,
1693
1773
  signingIn: !l,
1694
1774
  onNavigate: o,
1695
1775
  onSignOut: () => d.signOut(),
1696
- children: l ? f(i === "passes" ? ke : i === "details" ? Oe : te, {}) : /* @__PURE__ */ f(Q, {
1776
+ children: l ? f(i === "passes" ? Me : i === "details" ? je : P, {}) : /* @__PURE__ */ f(Q, {
1697
1777
  basePath: c,
1698
1778
  brand: void 0,
1699
1779
  botCheck: e.botCheck,
@@ -1705,12 +1785,12 @@ function Ze(e) {
1705
1785
  });
1706
1786
  }
1707
1787
  // src/booking-flow.tsx
1708
- function Qe(e) {
1788
+ function nt(e) {
1709
1789
  return {
1710
1790
  startsAt: e.startsAt,
1711
1791
  eventTypeId: e.eventTypeId,
1712
1792
  ...e.eventId && { eventId: e.eventId },
1713
- ...e.resource && { resourceId: e.resource.id }
1793
+ ...!e.eventId && e.resource && { resourceId: e.resource.id }
1714
1794
  };
1715
1795
  }
1716
1796
  function $(e) {
@@ -1721,10 +1801,10 @@ function $(e) {
1721
1801
  e.resourceId ?? ""
1722
1802
  ].join("|") : "";
1723
1803
  }
1724
- function $e(e, t) {
1804
+ function rt(e, t) {
1725
1805
  return t.eventId ? e.eventId === t.eventId : e.eventTypeId === t.eventTypeId && Date.parse(e.startsAt) === Date.parse(t.startsAt) && (!t.resourceId || e.resource?.id === t.resourceId);
1726
1806
  }
1727
- function et(e) {
1807
+ function it(e) {
1728
1808
  let n = e.onChange !== void 0, r = {
1729
1809
  businessId: e.businessId,
1730
1810
  ...e.eventTypeId && { eventTypeId: e.eventTypeId },
@@ -1744,12 +1824,12 @@ function et(e) {
1744
1824
  businessId: e.businessId,
1745
1825
  ...e.eventTypeId && { eventTypeId: e.eventTypeId }
1746
1826
  });
1747
- }, [h]), { basePath: _, sessionKey: v, notice: y, portal: b, signedInAs: x } = W({
1827
+ }, [h]), { basePath: _, sessionKey: v, notice: y, portal: b, signedInAs: x } = K({
1748
1828
  basePath: e.basePath,
1749
1829
  navigate: g,
1750
1830
  accountNavigation: !1,
1751
1831
  onSessionChange: e.onSessionChange
1752
- }), [S, C] = s(), [w, E] = s(), D = u.time, O = $(D), k = S && D && S.business.id === u.businessId && $(Qe(S.candidate)) === O ? S : void 0, A = () => {
1832
+ }), [S, C] = s(), [w, E] = s(), D = u.time, O = $(D), k = S && D && S.business.id === u.businessId && $(nt(S.candidate)) === O ? S : void 0, A = () => {
1753
1833
  C(void 0);
1754
1834
  let { time: e, ...t } = u;
1755
1835
  h(t);
@@ -1759,10 +1839,10 @@ function et(e) {
1759
1839
  candidate: t
1760
1840
  }), h({
1761
1841
  ...u,
1762
- time: Qe(t)
1842
+ time: nt(t)
1763
1843
  });
1764
1844
  }, M;
1765
- M = k ? v ? /* @__PURE__ */ f(ae, {
1845
+ M = k ? v ? /* @__PURE__ */ f(he, {
1766
1846
  choice: k,
1767
1847
  onBack: A,
1768
1848
  onBooked: e.onBooked,
@@ -1776,7 +1856,7 @@ function et(e) {
1776
1856
  autoFocus: !0,
1777
1857
  children: [
1778
1858
  /* @__PURE__ */ f("p", { children: T("book.signInFirst") }),
1779
- /* @__PURE__ */ f(L, { choice: k }),
1859
+ /* @__PURE__ */ f(H, { choice: k }),
1780
1860
  /* @__PURE__ */ f("button", {
1781
1861
  type: "button",
1782
1862
  className: "cp-link",
@@ -1784,7 +1864,7 @@ function et(e) {
1784
1864
  children: T("book.back")
1785
1865
  })
1786
1866
  ]
1787
- }) : D && w !== O ? /* @__PURE__ */ f(nt, {
1867
+ }) : D && w !== O ? /* @__PURE__ */ f(ot, {
1788
1868
  businessId: u.businessId,
1789
1869
  time: D,
1790
1870
  onFound: C,
@@ -1794,7 +1874,7 @@ function et(e) {
1794
1874
  className: "cp-link cp-back",
1795
1875
  onClick: () => h({ businessId: u.businessId }),
1796
1876
  children: T("book.toTypes")
1797
- }), /* @__PURE__ */ f(Ce, {
1877
+ }), /* @__PURE__ */ f(de, {
1798
1878
  businessId: u.businessId,
1799
1879
  eventTypeId: u.eventTypeId,
1800
1880
  resourceId: u.resourceId,
@@ -1804,7 +1884,7 @@ function et(e) {
1804
1884
  ...e
1805
1885
  }),
1806
1886
  onChoose: j
1807
- })] }) : /* @__PURE__ */ f(tt, {
1887
+ })] }) : /* @__PURE__ */ f(at, {
1808
1888
  selection: u,
1809
1889
  change: h,
1810
1890
  onChoose: j
@@ -1815,10 +1895,10 @@ function et(e) {
1815
1895
  u.resourceId ?? "",
1816
1896
  D && w !== O ? "time" : ""
1817
1897
  ].join("/");
1818
- return /* @__PURE__ */ f(G, {
1898
+ return /* @__PURE__ */ f(q, {
1819
1899
  portal: b,
1820
1900
  loading: v === void 0,
1821
- children: /* @__PURE__ */ p(it, {
1901
+ children: /* @__PURE__ */ p(ct, {
1822
1902
  step: N,
1823
1903
  children: [
1824
1904
  e.onClose && /* @__PURE__ */ f("div", {
@@ -1840,10 +1920,10 @@ function et(e) {
1840
1920
  })
1841
1921
  });
1842
1922
  }
1843
- function tt(e) {
1844
- let { selection: t, change: n } = e, { businessId: r, eventTypeId: i } = t, a = be(r), o = xe(a, null), { business: s, types: c } = a;
1923
+ function at(e) {
1924
+ let { selection: t, change: n } = e, { businessId: r, eventTypeId: i } = t, a = ce(r), o = le(a, null), { business: s, types: c } = a;
1845
1925
  if (o || !s || !c) return o;
1846
- let l = /* @__PURE__ */ f(we, { business: s }), u = /* @__PURE__ */ f("button", {
1926
+ let l = /* @__PURE__ */ f(fe, { business: s }), u = /* @__PURE__ */ f("button", {
1847
1927
  type: "button",
1848
1928
  className: "cp-link cp-back",
1849
1929
  onClick: () => n({ businessId: r }),
@@ -1871,7 +1951,7 @@ function tt(e) {
1871
1951
  eventTypeId: e.id
1872
1952
  }),
1873
1953
  children: [
1874
- /* @__PURE__ */ f(K, {
1954
+ /* @__PURE__ */ f(I, {
1875
1955
  image: e.image,
1876
1956
  alt: "",
1877
1957
  size: "small",
@@ -1879,7 +1959,15 @@ function tt(e) {
1879
1959
  }),
1880
1960
  /* @__PURE__ */ f("strong", { children: e.displayName }),
1881
1961
  e.description && /* @__PURE__ */ f("span", { children: e.description }),
1882
- /* @__PURE__ */ f("span", { children: T("business.minutes", { minutes: e.durationMinutes }) })
1962
+ /* @__PURE__ */ f("span", { children: T("business.minutes", { minutes: e.durationMinutes }) }),
1963
+ e.tags.length > 0 && /* @__PURE__ */ f("span", {
1964
+ className: "cp-tags",
1965
+ children: e.tags.slice(0, 3).map((e) => /* @__PURE__ */ f("span", {
1966
+ className: "cp-tag",
1967
+ style: { "--cp-tag": Je(e.colour) },
1968
+ children: e.name
1969
+ }, e.id))
1970
+ })
1883
1971
  ]
1884
1972
  }) }, e.id))
1885
1973
  }),
@@ -1900,7 +1988,7 @@ function tt(e) {
1900
1988
  children: [
1901
1989
  u,
1902
1990
  l,
1903
- /* @__PURE__ */ f(J, { type: d }),
1991
+ /* @__PURE__ */ f(R, { type: d }),
1904
1992
  /* @__PURE__ */ f("h2", { children: T("book.chooseResource") }),
1905
1993
  /* @__PURE__ */ f("ul", {
1906
1994
  className: "cp-list",
@@ -1918,7 +2006,7 @@ function tt(e) {
1918
2006
  resourceId: e.id
1919
2007
  }),
1920
2008
  children: [
1921
- /* @__PURE__ */ f(K, {
2009
+ /* @__PURE__ */ f(I, {
1922
2010
  image: e.image,
1923
2011
  alt: "",
1924
2012
  size: "small",
@@ -1943,12 +2031,12 @@ function tt(e) {
1943
2031
  children: T("book.otherResource")
1944
2032
  }) : u,
1945
2033
  l,
1946
- /* @__PURE__ */ f(J, { type: d }),
2034
+ /* @__PURE__ */ f(R, { type: d }),
1947
2035
  m && h && /* @__PURE__ */ f("p", {
1948
2036
  className: "cp-hint",
1949
2037
  children: T("business.with", { resource: h.displayName })
1950
2038
  }),
1951
- /* @__PURE__ */ f(Te, {
2039
+ /* @__PURE__ */ f(z, {
1952
2040
  business: s,
1953
2041
  eventTypeId: d.id,
1954
2042
  resourceId: m ? h?.id : void 0,
@@ -1957,7 +2045,7 @@ function tt(e) {
1957
2045
  ]
1958
2046
  });
1959
2047
  }
1960
- function nt(e) {
2048
+ function ot(e) {
1961
2049
  let { client: t } = x(), { businessId: n, time: i } = e, a = o(e);
1962
2050
  a.current = e;
1963
2051
  let s = $(i);
@@ -1966,15 +2054,15 @@ function nt(e) {
1966
2054
  return (async () => {
1967
2055
  let { data: r } = await t.GET("/web/businesses/{businessId}", { params: { path: { businessId: n } } });
1968
2056
  if (!r) throw Error("no business");
1969
- let o = ye(r.timezone, new Date(i.startsAt)), { data: s } = await t.GET("/web/businesses/{businessId}/availability", { params: {
2057
+ let o = se(r.timezone, new Date(i.startsAt)), { data: s } = await t.GET("/web/businesses/{businessId}/availability", { params: {
1970
2058
  path: { businessId: n },
1971
2059
  query: {
1972
2060
  from: `${o}T00:00`,
1973
- to: `${q(o, 1)}T00:00`,
2061
+ to: `${L(o, 1)}T00:00`,
1974
2062
  eventTypeId: i.eventTypeId,
1975
2063
  ...!i.eventId && i.resourceId && { resourceId: i.resourceId }
1976
2064
  }
1977
- } }), c = s?.items.find((e) => $e(e, i));
2065
+ } }), c = s?.items.find((e) => rt(e, i));
1978
2066
  e && (c ? a.current.onFound({
1979
2067
  business: r,
1980
2068
  candidate: c
@@ -1996,8 +2084,8 @@ function nt(e) {
1996
2084
  })
1997
2085
  });
1998
2086
  }
1999
- var rt = "input, .cp-option, .cp-chips button, .cp-candidate button, .cp-actions button:not(:disabled)";
2000
- function it(e) {
2087
+ var st = "input, .cp-option, .cp-chips button, .cp-candidate button, .cp-actions button:not(:disabled)";
2088
+ function ct(e) {
2001
2089
  let t = o(null), n = o(!1), { step: i } = e;
2002
2090
  return r(() => {
2003
2091
  let e = t.current;
@@ -2005,7 +2093,7 @@ function it(e) {
2005
2093
  let r = n.current;
2006
2094
  if (n.current = !0, r && e.contains(document.activeElement)) return;
2007
2095
  let i = () => {
2008
- let t = e.querySelector(rt);
2096
+ let t = e.querySelector(st);
2009
2097
  return t?.focus(), !!t;
2010
2098
  };
2011
2099
  if (i()) return;
@@ -2027,8 +2115,8 @@ function it(e) {
2027
2115
  });
2028
2116
  }
2029
2117
  // src/sign-in-standalone.tsx
2030
- function at(e) {
2031
- let t = e.basePath.replace(/\/$/, ""), n = he(t, e.onSessionChange), i = o(e.onSignedIn);
2118
+ function lt(e) {
2119
+ let t = e.basePath.replace(/\/$/, ""), n = ke(t, e.onSessionChange), i = o(e.onSignedIn);
2032
2120
  i.current = e.onSignedIn;
2033
2121
  let a = o(!1);
2034
2122
  return r(() => {
@@ -2044,15 +2132,15 @@ function at(e) {
2044
2132
  brand: e.brand,
2045
2133
  botCheck: e.botCheck,
2046
2134
  notice: void 0,
2047
- onSignedIn: (e) => U(t, e),
2135
+ onSignedIn: (e) => G(t, e),
2048
2136
  onCancel: e.onCancel,
2049
2137
  autoFocus: !0
2050
2138
  })
2051
2139
  });
2052
2140
  }
2053
2141
  // src/index.tsx
2054
- function ot(e) {
2055
- let [t, n] = s("businesses"), r = e.screen ?? t, i = e.onNavigate ?? n, { basePath: a, sessionKey: o, notice: c, portal: l, signedInAs: u } = W({
2142
+ function ut(e) {
2143
+ let [t, n] = s("businesses"), r = e.screen ?? t, i = e.onNavigate ?? n, { basePath: a, sessionKey: o, notice: c, portal: l, signedInAs: u } = K({
2056
2144
  basePath: e.basePath,
2057
2145
  navigate: i,
2058
2146
  accountNavigation: !0,
@@ -2067,38 +2155,38 @@ function ot(e) {
2067
2155
  onSignedIn: u,
2068
2156
  children: t
2069
2157
  });
2070
- return /* @__PURE__ */ f(G, {
2158
+ return /* @__PURE__ */ f(q, {
2071
2159
  portal: l,
2072
2160
  loading: o === void 0,
2073
- children: /* @__PURE__ */ f(de, {
2161
+ children: /* @__PURE__ */ f(Ce, {
2074
2162
  brand: e.brand,
2075
- tabs: ue,
2163
+ tabs: Se,
2076
2164
  screen: r,
2077
2165
  signedIn: !!o,
2078
2166
  signingIn: !o && (!!m || typeof r == "string" && r !== "businesses"),
2079
2167
  onNavigate: i,
2080
2168
  onSignOut: () => l.signOut(),
2081
- children: m ? o ? /* @__PURE__ */ f(ae, {
2169
+ children: m ? o ? /* @__PURE__ */ f(he, {
2082
2170
  choice: m,
2083
2171
  onBack: () => h(void 0)
2084
2172
  }, `${m.candidate.startsAt}-${m.candidate.eventId ?? m.candidate.eventTypeId}`) : y(/* @__PURE__ */ p(d, { children: [
2085
2173
  /* @__PURE__ */ f("p", { children: T("book.signInFirst") }),
2086
- /* @__PURE__ */ f(L, { choice: m }),
2174
+ /* @__PURE__ */ f(H, { choice: m }),
2087
2175
  /* @__PURE__ */ f("button", {
2088
2176
  type: "button",
2089
2177
  className: "cp-link",
2090
2178
  onClick: () => h(void 0),
2091
2179
  children: T("book.back")
2092
2180
  })
2093
- ] })) : typeof r == "object" ? /* @__PURE__ */ f(Ce, {
2181
+ ] })) : typeof r == "object" ? /* @__PURE__ */ f(de, {
2094
2182
  businessId: r.businessId,
2095
2183
  eventTypeId: r.eventTypeId,
2096
2184
  onChoose: (e, t) => h({
2097
2185
  business: e,
2098
2186
  candidate: t
2099
2187
  })
2100
- }) : r === "businesses" ? /* @__PURE__ */ f(De, {}) : o ? f(r === "passes" ? ke : r === "details" ? Oe : te, {}) : y()
2188
+ }) : r === "businesses" ? /* @__PURE__ */ f(Ae, {}) : o ? f(r === "passes" ? Me : r === "details" ? je : P, {}) : y()
2101
2189
  })
2102
2190
  });
2103
2191
  }
2104
- export { Ze as MsmAccount, et as MsmBooking, ot as MsmCustomer, at as MsmSignIn, F as cancellationState, j as formatDate, k as formatDateTime, O as formatNumber, C as locale, T as t };
2192
+ export { tt as MsmAccount, it as MsmBooking, ut as MsmCustomer, lt as MsmSignIn, te as cancellationState, j as formatDate, k as formatDateTime, O as formatNumber, C as locale, T as t };