@msm-platform/customer-react 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  "use client";
2
- import { createContext as e, useCallback as t, useContext as n, useEffect as r, useId as i, useMemo as a, useRef as o, useState as s } from "react";
3
- import { createCustomerClient as c, isCustomerApiError as l } from "@msm-platform/customer-sdk";
4
- import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
5
- import { Metadata as p, getCountries as m, getCountryCallingCode as h, parsePhoneNumberFromString as g, validatePhoneNumberLength as _ } from "libphonenumber-js";
6
- import v from "libphonenumber-js/min/metadata";
2
+ import { createContext as e, useCallback as t, useContext as n, useEffect as r, useId as i, useMemo as a, useRef as o, useState as s, useSyncExternalStore as c } from "react";
3
+ import { createCustomerClient as l, isCustomerApiError as u } from "@msm-platform/customer-sdk";
4
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
5
+ import { Metadata as m, getCountries as h, getCountryCallingCode as g, parsePhoneNumberFromString as _, validatePhoneNumberLength as v } from "libphonenumber-js";
6
+ import y from "libphonenumber-js/min/metadata";
7
7
  // src/context.ts
8
- var y = e(null);
9
- function b() {
10
- let e = n(y);
11
- if (!e) throw Error("usePortal needs MsmCustomer.");
8
+ var b = e(null);
9
+ function x() {
10
+ let e = n(b);
11
+ if (!e) throw Error("usePortal needs a customer screen component.");
12
12
  return e;
13
13
  }
14
14
  // src/i18n.ts
15
- var x = {
15
+ var S = {
16
16
  "app.loading": "Loading…",
17
17
  "app.loadFailed": "Something went wrong loading this page. Try again.",
18
18
  "app.retry": "Try again",
@@ -40,6 +40,7 @@ var x = {
40
40
  "register.submit": "Create account",
41
41
  "signIn.wait": "Please wait…",
42
42
  "signIn.differentNumber": "Use a different number",
43
+ "signIn.cancel": "Cancel",
43
44
  "signIn.error.tooMany": "Too many codes requested. Try again in about {wait}.",
44
45
  "signIn.error.tooManyLater": "Too many codes requested. Try again later.",
45
46
  "signIn.error.paused": "Sign-in codes are paused for now. Try again in about {wait}.",
@@ -93,6 +94,8 @@ var x = {
93
94
  "business.notFound": "This business isn't taking bookings here.",
94
95
  "business.types": "Services",
95
96
  "business.allTypes": "Everything",
97
+ "business.resources": "With",
98
+ "business.anyResource": "Anyone",
96
99
  "business.typeMissing": "This service can't be booked here.",
97
100
  "business.minutes": "{minutes} min",
98
101
  "business.week": "Which week",
@@ -115,6 +118,16 @@ var x = {
115
118
  "book.confirming": "Confirming…",
116
119
  "book.booked": "You're booked.",
117
120
  "book.toBookings": "See all my bookings",
121
+ "book.done": "Done",
122
+ "book.close": "Close",
123
+ "book.chooseType": "What would you like to book?",
124
+ "book.noTypes": "There is nothing to book here yet.",
125
+ "book.seeAll": "See all times",
126
+ "book.chooseResource": "Who would you like to book with?",
127
+ "book.anyResource": "Anyone",
128
+ "book.anyResourceHint": "The first free times with anyone who offers it",
129
+ "book.toTypes": "Back to services",
130
+ "book.otherResource": "Choose someone else",
118
131
  "book.reserveAgain": "Hold this time again",
119
132
  "book.full": "This class is full now. Choose another time.",
120
133
  "book.slotTaken": "Someone has just taken this time. Choose another.",
@@ -144,74 +157,74 @@ var x = {
144
157
  "details.signOutEverywhere": "Sign out everywhere",
145
158
  "details.signOutEverywhereHint": "Ends your sessions on every phone and computer, including this one.",
146
159
  "details.signOutEverywhereFailed": "Could not sign out everywhere. Try again."
147
- }, S = "en-GB", C = x;
148
- function w(e, t = {}) {
149
- return C[e].replace(/\{(\w+)\}/g, (e, n) => {
160
+ }, C = "en-GB", w = S;
161
+ function T(e, t = {}) {
162
+ return w[e].replace(/\{(\w+)\}/g, (e, n) => {
150
163
  let r = t[n];
151
- return r === void 0 ? e : typeof r == "number" ? D(r) : r;
164
+ return r === void 0 ? e : typeof r == "number" ? O(r) : r;
152
165
  });
153
166
  }
154
- var T = new Intl.PluralRules(S);
155
- function E(e, t, n = {}) {
156
- let r = `${e}.${T.select(t)}`;
157
- return w(r in C ? r : `${e}.other`, {
167
+ var E = new Intl.PluralRules(C);
168
+ function D(e, t, n = {}) {
169
+ let r = `${e}.${E.select(t)}`;
170
+ return T(r in w ? r : `${e}.other`, {
158
171
  count: t,
159
172
  ...n
160
173
  });
161
174
  }
162
- function D(e) {
163
- return new Intl.NumberFormat(S).format(e);
175
+ function O(e) {
176
+ return new Intl.NumberFormat(C).format(e);
164
177
  }
165
- function O(e, t) {
166
- return new Intl.DateTimeFormat(S, {
178
+ function k(e, t) {
179
+ return new Intl.DateTimeFormat(C, {
167
180
  dateStyle: "medium",
168
181
  timeStyle: "short",
169
182
  ...t && { timeZone: t }
170
183
  }).format(new Date(e));
171
184
  }
172
- function k(e, t) {
173
- return new Intl.DateTimeFormat(S, {
185
+ function A(e, t) {
186
+ return new Intl.DateTimeFormat(C, {
174
187
  timeStyle: "short",
175
188
  ...t && { timeZone: t }
176
189
  }).format(new Date(e));
177
190
  }
178
- function A(e, t) {
179
- return new Intl.DateTimeFormat(S, {
191
+ function j(e, t) {
192
+ return new Intl.DateTimeFormat(C, {
180
193
  dateStyle: "medium",
181
194
  ...t && { timeZone: t }
182
195
  }).format(new Date(e));
183
196
  }
184
- function j(e, t) {
185
- return new Intl.DateTimeFormat(S, {
197
+ function M(e, t) {
198
+ return new Intl.DateTimeFormat(C, {
186
199
  weekday: "long",
187
200
  day: "numeric",
188
201
  month: "long",
189
202
  ...t && { timeZone: t }
190
203
  }).format(new Date(e));
191
204
  }
192
- function M(e, t, n) {
193
- let r = A(e, n) === A(t, n);
194
- return w("bookings.when", {
195
- start: O(e, n),
196
- end: r ? k(t, n) : O(t, n)
205
+ function N(e, t, n) {
206
+ let r = j(e, n) === j(t, n);
207
+ return T("bookings.when", {
208
+ start: k(e, n),
209
+ end: r ? A(t, n) : k(t, n)
197
210
  });
198
211
  }
199
- function N(e) {
200
- if (e < 60) return E("wait.seconds", e);
212
+ function P(e) {
213
+ if (e < 60) return D("wait.seconds", e);
201
214
  let t = Math.round(e / 60);
202
- return t < 60 ? E("wait.minutes", t) : E("wait.hours", Math.round(e / 3600));
215
+ return t < 60 ? D("wait.minutes", t) : D("wait.hours", Math.round(e / 3600));
203
216
  }
204
217
  // src/cancellation.ts
205
- function P(e, t) {
218
+ function F(e, t) {
206
219
  if (e.status === "cancelled") return "cancelled";
207
220
  let n = t.getTime();
208
221
  return !e.cancellableUntil || n >= Date.parse(e.cancellableUntil) ? "closed" : e.lateCancellationFrom && n >= Date.parse(e.lateCancellationFrom) ? "late" : "open";
209
222
  }
210
223
  // src/screens/bookings.tsx
211
- var F = "/web/businesses/{businessId}/bookings/{bookingId}/cancel";
224
+ var I = "/web/businesses/{businessId}/bookings/{bookingId}/cancel";
212
225
  function ee() {
213
- let { client: e } = b(), [n, i] = s("upcoming"), [a, o] = s(), [c, l] = s(null), [u, p] = s(!1), [m, h] = s(), g = t(async (t) => {
214
- p(!1);
226
+ 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) => {
227
+ d(!1);
215
228
  try {
216
229
  let { data: r } = await e.GET("/web/me/bookings", { params: { query: {
217
230
  period: n,
@@ -220,72 +233,72 @@ function ee() {
220
233
  if (!r) return;
221
234
  o((e) => t ? [...e ?? [], ...r.items] : r.items), l(r.nextCursor);
222
235
  } catch {
223
- p(!0);
236
+ d(!0);
224
237
  }
225
238
  }, [e, n]);
226
239
  return r(() => {
227
240
  o(void 0), h(void 0), g();
228
- }, [g]), /* @__PURE__ */ f("section", {
241
+ }, [g]), /* @__PURE__ */ p("section", {
229
242
  className: "cp-screen",
230
243
  children: [
231
- /* @__PURE__ */ d("h1", { children: w("bookings.heading") }),
232
- /* @__PURE__ */ d("fieldset", {
244
+ /* @__PURE__ */ f("h1", { children: T("bookings.heading") }),
245
+ /* @__PURE__ */ f("fieldset", {
233
246
  className: "cp-tabs",
234
- "aria-label": w("bookings.period"),
235
- children: ["upcoming", "past"].map((e) => /* @__PURE__ */ d("button", {
247
+ "aria-label": T("bookings.period"),
248
+ children: ["upcoming", "past"].map((e) => /* @__PURE__ */ f("button", {
236
249
  type: "button",
237
250
  "aria-pressed": n === e,
238
251
  onClick: () => i(e),
239
- children: w(e === "upcoming" ? "bookings.upcoming" : "bookings.past")
252
+ children: T(e === "upcoming" ? "bookings.upcoming" : "bookings.past")
240
253
  }, e))
241
254
  }),
242
- m && /* @__PURE__ */ d("p", {
255
+ m && /* @__PURE__ */ f("p", {
243
256
  role: "status",
244
257
  className: "cp-notice",
245
- children: w(m)
258
+ children: T(m)
246
259
  }),
247
- u ? /* @__PURE__ */ d(I, { onRetry: () => g() }) : a ? a.length === 0 ? /* @__PURE__ */ d("p", {
260
+ u ? /* @__PURE__ */ f(L, { onRetry: () => g() }) : a ? a.length === 0 ? /* @__PURE__ */ f("p", {
248
261
  className: "cp-empty",
249
- children: w(n === "upcoming" ? "bookings.emptyUpcoming" : "bookings.emptyPast")
250
- }) : /* @__PURE__ */ d("ul", {
262
+ children: T(n === "upcoming" ? "bookings.emptyUpcoming" : "bookings.emptyPast")
263
+ }) : /* @__PURE__ */ f("ul", {
251
264
  className: "cp-list",
252
- children: a.map((e) => /* @__PURE__ */ d(L, {
265
+ children: a.map((e) => /* @__PURE__ */ f(te, {
253
266
  booking: e,
254
267
  onCancelled: (e, t) => {
255
268
  o((t) => t?.map((t) => t.id === e.id ? e : t)), h(t ? "bookings.doneLate" : "bookings.doneOnTime");
256
269
  }
257
270
  }, e.id))
258
- }) : /* @__PURE__ */ d("p", {
271
+ }) : /* @__PURE__ */ f("p", {
259
272
  role: "status",
260
- children: w("app.loading")
273
+ children: T("app.loading")
261
274
  }),
262
- a && c && !u && /* @__PURE__ */ d("button", {
275
+ a && c && !u && /* @__PURE__ */ f("button", {
263
276
  type: "button",
264
277
  className: "cp-secondary",
265
278
  onClick: () => g(c),
266
- children: w("bookings.more")
279
+ children: T("bookings.more")
267
280
  })
268
281
  ]
269
282
  });
270
283
  }
271
- function I({ onRetry: e }) {
272
- return /* @__PURE__ */ f("div", {
284
+ function L({ onRetry: e }) {
285
+ return /* @__PURE__ */ p("div", {
273
286
  role: "alert",
274
287
  className: "cp-error",
275
- children: [/* @__PURE__ */ d("p", { children: w("app.loadFailed") }), /* @__PURE__ */ d("button", {
288
+ children: [/* @__PURE__ */ f("p", { children: T("app.loadFailed") }), /* @__PURE__ */ f("button", {
276
289
  type: "button",
277
290
  className: "cp-secondary",
278
291
  onClick: e,
279
- children: w("app.retry")
292
+ children: T("app.retry")
280
293
  })]
281
294
  });
282
295
  }
283
- function L(e) {
284
- let { client: t, businesses: n } = b(), { booking: r } = e, i = n.get(r.businessId)?.timezone, [a, o] = s(!1), [c, u] = s(!1), [p, m] = s(), [h, g] = s(!1), _ = h ? "closed" : P(r, /* @__PURE__ */ new Date()), v = r.creditMembershipId !== null && r.creditRestoredAt === null;
296
+ function te(e) {
297
+ 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;
285
298
  async function y() {
286
- u(!0), m(void 0);
299
+ l(!0), m(void 0);
287
300
  try {
288
- let { data: n } = await t.POST(F, { params: { path: {
301
+ let { data: n } = await t.POST(I, { params: { path: {
289
302
  businessId: r.businessId,
290
303
  bookingId: r.id
291
304
  } } });
@@ -296,7 +309,7 @@ function L(e) {
296
309
  lateCancellationFrom: null
297
310
  }, n.cancelledLate === !0));
298
311
  } catch (e) {
299
- if (l(e, "post", F)) {
312
+ if (u(e, "post", I)) {
300
313
  if (e.code === "EventStarted") {
301
314
  g(!0), o(!1);
302
315
  return;
@@ -308,222 +321,228 @@ function L(e) {
308
321
  }
309
322
  m("bookings.cancelFailed");
310
323
  } finally {
311
- u(!1);
324
+ l(!1);
312
325
  }
313
326
  }
314
- return /* @__PURE__ */ f("li", {
327
+ return /* @__PURE__ */ p("li", {
315
328
  className: "cp-card",
316
329
  "data-state": _,
317
330
  children: [
318
- /* @__PURE__ */ f("div", {
331
+ /* @__PURE__ */ p("div", {
319
332
  className: "cp-card-head",
320
- children: [/* @__PURE__ */ d("h2", { children: r.event.eventTypeName }), r.status === "cancelled" ? /* @__PURE__ */ d("span", {
333
+ children: [/* @__PURE__ */ f("h2", { children: r.event.eventTypeName }), r.status === "cancelled" ? /* @__PURE__ */ f("span", {
321
334
  className: "cp-badge",
322
- children: w(r.cancelledLate ? "bookings.cancelledLate" : "bookings.cancelled")
323
- }) : r.attendance ? /* @__PURE__ */ d("span", {
335
+ children: T(r.cancelledLate ? "bookings.cancelledLate" : "bookings.cancelled")
336
+ }) : r.attendance ? /* @__PURE__ */ f("span", {
324
337
  className: "cp-badge",
325
- children: w(r.attendance === "attended" ? "bookings.attended" : "bookings.noShow")
338
+ children: T(r.attendance === "attended" ? "bookings.attended" : "bookings.noShow")
326
339
  }) : null]
327
340
  }),
328
- /* @__PURE__ */ d("p", { children: r.businessName }),
329
- /* @__PURE__ */ d("p", { children: M(r.event.startsAt, r.event.endsAt, i) }),
330
- (_ === "open" || _ === "late") && r.lateCancellationFrom && /* @__PURE__ */ d("p", {
341
+ /* @__PURE__ */ f("p", { children: r.businessName }),
342
+ /* @__PURE__ */ f("p", { children: N(r.event.startsAt, r.event.endsAt, i) }),
343
+ (_ === "open" || _ === "late") && r.lateCancellationFrom && /* @__PURE__ */ f("p", {
331
344
  className: "cp-hint",
332
- children: w("bookings.lateFrom", { time: O(r.lateCancellationFrom, i) })
345
+ children: T("bookings.lateFrom", { time: k(r.lateCancellationFrom, i) })
333
346
  }),
334
- _ === "closed" && r.status === "confirmed" && !r.attendance && /* @__PURE__ */ d("p", {
347
+ _ === "closed" && r.status === "confirmed" && !r.attendance && /* @__PURE__ */ f("p", {
335
348
  className: "cp-hint",
336
- children: w("bookings.started")
349
+ children: T("bookings.started")
337
350
  }),
338
- p && /* @__PURE__ */ d("p", {
351
+ d && /* @__PURE__ */ f("p", {
339
352
  role: "alert",
340
- children: w(p)
353
+ children: T(d)
341
354
  }),
342
- (_ === "open" || _ === "late") && (a ? /* @__PURE__ */ f("fieldset", {
355
+ (_ === "open" || _ === "late") && (a ? /* @__PURE__ */ p("fieldset", {
343
356
  className: "cp-confirm",
344
357
  children: [
345
- /* @__PURE__ */ d("legend", { children: w("bookings.confirmHeading") }),
346
- _ === "late" && /* @__PURE__ */ d("p", {
358
+ /* @__PURE__ */ f("legend", { children: T("bookings.confirmHeading") }),
359
+ _ === "late" && /* @__PURE__ */ f("p", {
347
360
  className: "cp-warning",
348
- children: w("bookings.confirmLate")
361
+ children: T("bookings.confirmLate")
349
362
  }),
350
- _ === "late" && v && /* @__PURE__ */ d("p", {
363
+ _ === "late" && v && /* @__PURE__ */ f("p", {
351
364
  className: "cp-warning",
352
- children: w("bookings.confirmCredit")
365
+ children: T("bookings.confirmCredit")
353
366
  }),
354
- /* @__PURE__ */ f("div", {
367
+ /* @__PURE__ */ p("div", {
355
368
  className: "cp-actions",
356
- children: [/* @__PURE__ */ d("button", {
369
+ children: [/* @__PURE__ */ f("button", {
357
370
  type: "button",
358
371
  disabled: c,
359
372
  onClick: y,
360
- children: w(c ? "bookings.cancelling" : "bookings.confirm")
361
- }), /* @__PURE__ */ d("button", {
373
+ children: T(c ? "bookings.cancelling" : "bookings.confirm")
374
+ }), /* @__PURE__ */ f("button", {
362
375
  type: "button",
363
376
  className: "cp-secondary",
364
377
  disabled: c,
365
378
  onClick: () => o(!1),
366
- children: w("bookings.keep")
379
+ children: T("bookings.keep")
367
380
  })]
368
381
  })
369
382
  ]
370
- }) : /* @__PURE__ */ d("button", {
383
+ }) : /* @__PURE__ */ f("button", {
371
384
  type: "button",
372
385
  className: "cp-secondary",
373
386
  onClick: () => o(!0),
374
- children: w("bookings.cancel")
387
+ children: T("bookings.cancel")
375
388
  }))
376
389
  ]
377
390
  });
378
391
  }
379
392
  // src/booking.tsx
380
- var R = "/web/businesses/{businessId}/reservations", z = "/web/businesses/{businessId}/reservations/{reservationId}/confirm";
381
- function B({ choice: e }) {
393
+ var ne = "/web/businesses/{businessId}/reservations", re = "/web/businesses/{businessId}/reservations/{reservationId}/confirm";
394
+ function R({ choice: e }) {
382
395
  let { business: t, candidate: n } = e;
383
- return /* @__PURE__ */ f("div", {
396
+ return /* @__PURE__ */ p("div", {
384
397
  className: "cp-summary",
385
398
  children: [
386
- /* @__PURE__ */ d("h2", { children: n.title }),
387
- /* @__PURE__ */ d("p", { children: t.displayName }),
388
- /* @__PURE__ */ d("p", { children: M(n.startsAt, n.endsAt, n.timezone) }),
389
- n.resource && /* @__PURE__ */ d("p", {
399
+ /* @__PURE__ */ f("h2", { children: n.title }),
400
+ /* @__PURE__ */ f("p", { children: t.displayName }),
401
+ /* @__PURE__ */ f("p", { children: N(n.startsAt, n.endsAt, n.timezone) }),
402
+ n.resource && /* @__PURE__ */ f("p", {
390
403
  className: "cp-hint",
391
- children: w("business.with", { resource: n.resource.displayName })
404
+ children: T("business.with", { resource: n.resource.displayName })
392
405
  })
393
406
  ]
394
407
  });
395
408
  }
396
- function te(e) {
397
- let { client: n, navigate: i } = b(), { business: a, candidate: c } = e.choice, [p, m] = s({ step: "reserving" }), [h, g] = s(), _ = t(async () => {
398
- m({ step: "reserving" });
409
+ function ie(e) {
410
+ let { client: n, navigate: i, accountNavigation: a } = x(), { business: c, candidate: l } = e.choice, [m, h] = s({ step: "reserving" }), [g, _] = s(), v = t(async () => {
411
+ h({ step: "reserving" });
399
412
  try {
400
- let { data: e } = await n.POST(R, {
401
- params: { path: { businessId: a.id } },
402
- body: c.eventId ? { eventId: c.eventId } : {
403
- eventTypeId: c.eventTypeId,
404
- startsAt: c.startsAt,
405
- ...c.resource && { resourceId: c.resource.id }
413
+ let { data: e } = await n.POST(ne, {
414
+ params: { path: { businessId: c.id } },
415
+ body: l.eventId ? { eventId: l.eventId } : {
416
+ eventTypeId: l.eventTypeId,
417
+ startsAt: l.startsAt,
418
+ ...l.resource && { resourceId: l.resource.id }
406
419
  }
407
420
  });
408
- e && m({
421
+ e && h({
409
422
  step: "held",
410
423
  reservationId: e.id,
411
424
  expiresAt: e.expiresAt
412
425
  });
413
426
  } catch (e) {
414
- let t = l(e, "post", R) ? e.code : void 0;
415
- m({
427
+ let t = u(e, "post", ne) ? e.code : void 0;
428
+ h({
416
429
  step: "refused",
417
- message: ne(t),
430
+ message: ae(t),
418
431
  again: !1
419
432
  });
420
433
  }
421
434
  }, [
422
435
  n,
423
- a.id,
424
- c
425
- ]), v = o(!1);
436
+ c.id,
437
+ l
438
+ ]), y = o(!1);
426
439
  r(() => {
427
- v.current || (v.current = !0, _());
428
- }, [_]);
429
- async function y(e, t) {
430
- m({
440
+ y.current || (y.current = !0, v());
441
+ }, [v]);
442
+ async function b(t, r) {
443
+ h({
431
444
  step: "confirming",
432
- reservationId: e,
433
- expiresAt: t
445
+ reservationId: t,
446
+ expiresAt: r
434
447
  });
435
448
  try {
436
- let { data: t } = await n.POST(z, { params: { path: {
437
- businessId: a.id,
438
- reservationId: e
449
+ let { data: r } = await n.POST(re, { params: { path: {
450
+ businessId: c.id,
451
+ reservationId: t
439
452
  } } });
440
- if (!t) return;
441
- let r = await n.GET("/web/businesses/{businessId}/bookings/{bookingId}", { params: { path: {
442
- businessId: a.id,
443
- bookingId: t.id
453
+ if (!r) return;
454
+ e.onBooked?.(r);
455
+ let i = await n.GET("/web/businesses/{businessId}/bookings/{bookingId}", { params: { path: {
456
+ businessId: c.id,
457
+ bookingId: r.id
444
458
  } } }).then(({ data: e }) => e ?? null).catch(() => null);
445
- m({
459
+ h({
446
460
  step: "booked",
447
- booking: r
461
+ booking: i
448
462
  });
449
463
  } catch (e) {
450
- let t = l(e, "post", z) ? e.code : void 0;
451
- m(t === "ReservationExpired" || t === "ReservationNotFound" ? {
464
+ let t = u(e, "post", re) ? e.code : void 0;
465
+ h(t === "ReservationExpired" || t === "ReservationNotFound" ? {
452
466
  step: "refused",
453
467
  message: "book.expired",
454
468
  again: !0
455
469
  } : {
456
470
  step: "refused",
457
- message: re(t),
471
+ message: oe(t),
458
472
  again: !1
459
473
  });
460
474
  }
461
475
  }
462
- let x = /* @__PURE__ */ d("button", {
476
+ let S = /* @__PURE__ */ f("button", {
463
477
  type: "button",
464
478
  className: "cp-secondary",
465
479
  onClick: e.onBack,
466
- children: w("book.back")
480
+ children: T("book.back")
467
481
  });
468
- return /* @__PURE__ */ f("section", {
482
+ return /* @__PURE__ */ p("section", {
469
483
  className: "cp-screen",
470
- children: [/* @__PURE__ */ d("h1", { children: w("book.heading") }), p.step === "booked" ? /* @__PURE__ */ f(u, { children: [
471
- /* @__PURE__ */ d("p", {
484
+ children: [/* @__PURE__ */ f("h1", { children: T("book.heading") }), m.step === "booked" ? /* @__PURE__ */ p(d, { children: [
485
+ /* @__PURE__ */ f("p", {
472
486
  role: "status",
473
487
  className: "cp-notice",
474
- children: w(h ?? "book.booked")
488
+ children: T(g ?? "book.booked")
475
489
  }),
476
- p.booking ? /* @__PURE__ */ d("ul", {
490
+ m.booking ? /* @__PURE__ */ f("ul", {
477
491
  className: "cp-list",
478
- children: /* @__PURE__ */ d(L, {
479
- booking: p.booking,
492
+ children: /* @__PURE__ */ f(te, {
493
+ booking: m.booking,
480
494
  onCancelled: (e, t) => {
481
- m({
495
+ h({
482
496
  step: "booked",
483
497
  booking: e
484
- }), g(t ? "bookings.doneLate" : "bookings.doneOnTime");
498
+ }), _(t ? "bookings.doneLate" : "bookings.doneOnTime");
485
499
  }
486
500
  })
487
- }) : /* @__PURE__ */ d(B, { choice: e.choice }),
488
- /* @__PURE__ */ d("button", {
501
+ }) : /* @__PURE__ */ f(R, { choice: e.choice }),
502
+ a ? /* @__PURE__ */ f("button", {
489
503
  type: "button",
490
504
  className: "cp-secondary",
491
505
  onClick: () => i("bookings"),
492
- children: w("book.toBookings")
506
+ children: T("book.toBookings")
507
+ }) : e.onDone && /* @__PURE__ */ f("button", {
508
+ type: "button",
509
+ className: "cp-secondary",
510
+ onClick: e.onDone,
511
+ children: T("book.done")
493
512
  })
494
- ] }) : /* @__PURE__ */ f(u, { children: [
495
- /* @__PURE__ */ d(B, { choice: e.choice }),
496
- p.step === "reserving" && /* @__PURE__ */ d("p", {
513
+ ] }) : /* @__PURE__ */ p(d, { children: [
514
+ /* @__PURE__ */ f(R, { choice: e.choice }),
515
+ m.step === "reserving" && /* @__PURE__ */ f("p", {
497
516
  role: "status",
498
- children: w("book.reserving")
517
+ children: T("book.reserving")
499
518
  }),
500
- (p.step === "held" || p.step === "confirming") && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("p", {
519
+ (m.step === "held" || m.step === "confirming") && /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("p", {
501
520
  className: "cp-hint",
502
- children: w("book.heldUntil", { time: k(p.expiresAt, c.timezone) })
503
- }), /* @__PURE__ */ f("div", {
521
+ children: T("book.heldUntil", { time: A(m.expiresAt, l.timezone) })
522
+ }), /* @__PURE__ */ p("div", {
504
523
  className: "cp-actions",
505
- children: [/* @__PURE__ */ d("button", {
524
+ children: [/* @__PURE__ */ f("button", {
506
525
  type: "button",
507
- disabled: p.step === "confirming",
508
- onClick: () => y(p.reservationId, p.expiresAt),
509
- children: p.step === "confirming" ? w("book.confirming") : w("book.confirm")
510
- }), x]
526
+ disabled: m.step === "confirming",
527
+ onClick: () => b(m.reservationId, m.expiresAt),
528
+ children: m.step === "confirming" ? T("book.confirming") : T("book.confirm")
529
+ }), S]
511
530
  })] }),
512
- p.step === "refused" && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("p", {
531
+ m.step === "refused" && /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("p", {
513
532
  role: "alert",
514
- children: w(p.message)
515
- }), /* @__PURE__ */ f("div", {
533
+ children: T(m.message)
534
+ }), /* @__PURE__ */ p("div", {
516
535
  className: "cp-actions",
517
- children: [p.again && /* @__PURE__ */ d("button", {
536
+ children: [m.again && /* @__PURE__ */ f("button", {
518
537
  type: "button",
519
- onClick: _,
520
- children: w("book.reserveAgain")
521
- }), x]
538
+ onClick: v,
539
+ children: T("book.reserveAgain")
540
+ }), S]
522
541
  })] })
523
542
  ] })]
524
543
  });
525
544
  }
526
- function ne(e) {
545
+ function ae(e) {
527
546
  switch (e) {
528
547
  case "EventFull": return "book.full";
529
548
  case "SlotTaken": return "book.slotTaken";
@@ -538,7 +557,7 @@ function ne(e) {
538
557
  default: return "book.failed";
539
558
  }
540
559
  }
541
- function re(e) {
560
+ function oe(e) {
542
561
  switch (e) {
543
562
  case "NotAuthorized": return "book.notAllowed";
544
563
  case "EventStarted":
@@ -548,322 +567,475 @@ function re(e) {
548
567
  default: return "book.failed";
549
568
  }
550
569
  }
551
- // src/client.ts
552
- var V = (e, t) => {
553
- let n = new Request(e, t);
554
- return n.headers.set("X-MSM-BFF", "1"), fetch(n);
555
- };
556
- function H(e, t, n) {
557
- return V(`${e}${t}`, {
558
- method: "POST",
559
- headers: { "content-type": "application/json" },
560
- body: JSON.stringify(n ?? {})
561
- });
562
- }
563
- function ie(e, t) {
564
- let n = c({ baseUrl: `${e}/engine` });
565
- return n.use({
566
- onRequest({ request: e }) {
567
- return e.headers.set("X-MSM-BFF", "1"), e;
568
- },
569
- onResponse({ response: e }) {
570
- e.status === 401 && t();
571
- }
572
- }), n;
573
- }
574
570
  // src/layout.tsx
575
- function U({ brand: e }) {
576
- return e ? /* @__PURE__ */ f("div", {
571
+ function se({ brand: e }) {
572
+ return e ? /* @__PURE__ */ p("div", {
577
573
  className: "cp-brand",
578
- children: [e.logo && /* @__PURE__ */ d("img", {
574
+ children: [e.logo && /* @__PURE__ */ f("img", {
579
575
  src: e.logo,
580
576
  alt: ""
581
- }), /* @__PURE__ */ d("span", { children: e.name })]
577
+ }), /* @__PURE__ */ f("span", { children: e.name })]
582
578
  }) : null;
583
579
  }
584
- var ae = [
585
- ["businesses", "nav.book"],
580
+ var ce = [["businesses", "nav.book"]], le = [
586
581
  ["bookings", "nav.bookings"],
587
582
  ["passes", "nav.passes"],
588
583
  ["details", "nav.details"]
589
- ];
590
- function oe(e) {
584
+ ], ue = [...ce, ...le];
585
+ function z(e) {
591
586
  let t = typeof e.screen == "string" ? e.screen : "businesses";
592
- return /* @__PURE__ */ f("div", {
587
+ return /* @__PURE__ */ p("div", {
593
588
  className: "cp-shell",
594
589
  children: [
595
- /* @__PURE__ */ f("header", {
590
+ /* @__PURE__ */ p("header", {
596
591
  className: "cp-header",
597
- children: [/* @__PURE__ */ d(U, { brand: e.brand }), e.signedIn ? /* @__PURE__ */ d("button", {
592
+ children: [/* @__PURE__ */ f(se, { brand: e.brand }), e.signedIn ? /* @__PURE__ */ f("button", {
598
593
  type: "button",
599
594
  className: "cp-link",
600
595
  onClick: e.onSignOut,
601
- children: w("nav.signOut")
602
- }) : !e.signingIn && /* @__PURE__ */ d("button", {
596
+ children: T("nav.signOut")
597
+ }) : !e.signingIn && /* @__PURE__ */ f("button", {
603
598
  type: "button",
604
599
  className: "cp-link",
605
600
  onClick: () => e.onNavigate("bookings"),
606
- children: w("nav.signIn")
601
+ children: T("nav.signIn")
607
602
  })]
608
603
  }),
609
- /* @__PURE__ */ d("nav", {
604
+ /* @__PURE__ */ f("nav", {
610
605
  className: "cp-nav",
611
- "aria-label": w("nav.label"),
612
- children: ae.map(([n, r]) => /* @__PURE__ */ d("button", {
606
+ "aria-label": T("nav.label"),
607
+ children: e.tabs.map(([n, r]) => /* @__PURE__ */ f("button", {
613
608
  type: "button",
614
609
  "aria-current": t === n ? "page" : void 0,
615
610
  onClick: () => e.onNavigate(n),
616
- children: w(r)
611
+ children: T(r)
617
612
  }, n))
618
613
  }),
619
- /* @__PURE__ */ d("main", {
614
+ /* @__PURE__ */ f("main", {
620
615
  className: "cp-main",
621
616
  children: e.children
622
617
  })
623
618
  ]
624
619
  });
625
620
  }
621
+ // src/client.ts
622
+ var B = (e, t) => {
623
+ let n = new Request(e, t);
624
+ return n.headers.set("X-MSM-BFF", "1"), fetch(n);
625
+ };
626
+ function V(e, t, n) {
627
+ return B(`${e}${t}`, {
628
+ method: "POST",
629
+ headers: { "content-type": "application/json" },
630
+ body: JSON.stringify(n ?? {})
631
+ });
632
+ }
633
+ function de(e, t) {
634
+ let n = l({ baseUrl: `${e}/engine` });
635
+ return n.use({
636
+ onRequest({ request: e }) {
637
+ return e.headers.set("X-MSM-BFF", "1"), e;
638
+ },
639
+ onResponse({ response: e }) {
640
+ e.status === 401 && t();
641
+ }
642
+ }), n;
643
+ }
644
+ // src/session.ts
645
+ var H = /* @__PURE__ */ new Map();
646
+ function U(e) {
647
+ let t = H.get(e);
648
+ return t || (t = {
649
+ value: void 0,
650
+ listeners: /* @__PURE__ */ new Set(),
651
+ generation: 0
652
+ }, H.set(e, t)), t;
653
+ }
654
+ function W(e, t) {
655
+ let n = U(e);
656
+ if (n.value !== t) {
657
+ n.value = t;
658
+ for (let e of n.listeners) e();
659
+ }
660
+ }
661
+ function fe(e, t) {
662
+ let { generation: n } = t, r = (r) => {
663
+ t.generation === n && t.value === void 0 && W(e, r);
664
+ };
665
+ B(`${e}/auth/session`).then(async (e) => r(e.ok ? (await e.json()).sessionKey : null)).catch(() => r(null));
666
+ }
667
+ function pe(e, t) {
668
+ let n = U(e);
669
+ return n.listeners.size === 0 && n.value === void 0 && fe(e, n), n.listeners.add(t), () => {
670
+ n.listeners.delete(t), n.listeners.size === 0 && queueMicrotask(() => {
671
+ n.listeners.size > 0 || (n.value = void 0, n.generation++);
672
+ });
673
+ };
674
+ }
675
+ function me(e, t) {
676
+ let n = c((t) => pe(e, t), () => U(e).value, () => void 0), i = o(void 0), a = o(t);
677
+ return a.current = t, r(() => {
678
+ if (n === void 0) return;
679
+ let e = n !== null;
680
+ i.current !== void 0 && i.current !== e && a.current?.(e), i.current = e;
681
+ }, [n]), n;
682
+ }
683
+ // src/portal.tsx
684
+ function G(e) {
685
+ let { navigate: n, accountNavigation: i } = e, c = e.basePath.replace(/\/$/, ""), l = me(c, e.onSessionChange), u = o(!1);
686
+ u.current = !!l;
687
+ let [d, f] = s(), [p, m] = s(/* @__PURE__ */ new Map()), [h, g] = s("loading"), _ = a(() => de(c, () => {
688
+ u.current && f("app.signedOut"), W(c, null);
689
+ }), [c]), v = t(async () => {
690
+ g("loading");
691
+ try {
692
+ let e = /* @__PURE__ */ new Map(), t;
693
+ do {
694
+ let { data: n } = await _.GET("/web/businesses", { params: { query: {
695
+ limit: 100,
696
+ ...t && { cursor: t }
697
+ } } });
698
+ for (let t of n?.items ?? []) e.set(t.id, t);
699
+ t = n?.nextCursor ?? void 0;
700
+ } while (t);
701
+ m(e), g("ready");
702
+ } catch {
703
+ g("failed");
704
+ }
705
+ }, [_]);
706
+ return r(() => {
707
+ v();
708
+ }, [v]), {
709
+ basePath: c,
710
+ sessionKey: l,
711
+ notice: d,
712
+ portal: a(() => ({
713
+ client: _,
714
+ businesses: p,
715
+ businessesStatus: h,
716
+ reloadBusinesses: () => void v(),
717
+ navigate: n,
718
+ accountNavigation: i,
719
+ signOut: async (e) => {
720
+ await V(c, "/auth/logout").catch(() => {}), f(e), W(c, null);
721
+ }
722
+ }), [
723
+ _,
724
+ p,
725
+ h,
726
+ v,
727
+ n,
728
+ i,
729
+ c
730
+ ]),
731
+ signedInAs: t((e) => {
732
+ f(void 0), W(c, e);
733
+ }, [c])
734
+ };
735
+ }
736
+ function K(e) {
737
+ return /* @__PURE__ */ f("div", {
738
+ className: "msm-customer",
739
+ children: e.loading ? /* @__PURE__ */ f("p", {
740
+ className: "cp-status",
741
+ role: "status",
742
+ children: T("app.loading")
743
+ }) : /* @__PURE__ */ f(b.Provider, {
744
+ value: e.portal,
745
+ children: e.children
746
+ })
747
+ });
748
+ }
626
749
  // src/screens/business.tsx
627
- var se = "/web/businesses/{businessId}", ce = /* @__PURE__ */ new Set([
750
+ var he = "/web/businesses/{businessId}", ge = /* @__PURE__ */ new Set([
628
751
  "BusinessNotFound",
629
752
  "OutsideClientScope",
630
753
  "ValidationFailed"
631
- ]), W = 7;
632
- function le(e) {
754
+ ]), _e = 7;
755
+ function ve(e, t = /* @__PURE__ */ new Date()) {
633
756
  return new Intl.DateTimeFormat("en-CA", {
634
757
  timeZone: e,
635
758
  year: "numeric",
636
759
  month: "2-digit",
637
760
  day: "2-digit"
638
- }).format(/* @__PURE__ */ new Date());
761
+ }).format(t);
639
762
  }
640
- function G(e, t) {
763
+ function q(e, t) {
641
764
  let n = /* @__PURE__ */ new Date(`${e}T00:00:00Z`);
642
765
  return n.setUTCDate(n.getUTCDate() + t), n.toISOString().slice(0, 10);
643
766
  }
644
- function ue(e) {
645
- let { client: n, navigate: i } = b(), { businessId: a, eventTypeId: o } = e, [c, p] = s(), [m, h] = s(), [g, _] = s(!1), v = t(async () => {
646
- _(!1), p(void 0);
767
+ function ye(e) {
768
+ let { client: n } = x(), [i, a] = s(), [o, c] = s(), [l, d] = s(!1), f = t(async () => {
769
+ d(!1), a(void 0);
647
770
  try {
648
- let [e, t] = await Promise.all([n.GET(se, { params: { path: { businessId: a } } }), n.GET("/web/businesses/{businessId}/event-types", { params: { path: { businessId: a } } })]);
649
- p(e.data ?? null), h(t.data?.items ?? []);
771
+ let [t, r] = await Promise.all([n.GET(he, { params: { path: { businessId: e } } }), n.GET("/web/businesses/{businessId}/event-types", { params: { path: { businessId: e } } })]);
772
+ a(t.data ?? null), c(r.data?.items ?? []);
650
773
  } catch (e) {
651
- l(e) && ce.has(e.code ?? "") ? p(null) : _(!0);
774
+ u(e) && ge.has(e.code ?? "") ? a(null) : d(!0);
652
775
  }
653
- }, [n, a]);
654
- r(() => {
655
- v();
656
- }, [v]);
657
- let y = /* @__PURE__ */ d("button", {
658
- type: "button",
659
- className: "cp-link cp-back",
660
- onClick: () => i("businesses"),
661
- children: w("business.all")
662
- });
663
- if (g) return /* @__PURE__ */ f("section", {
776
+ }, [n, e]);
777
+ return r(() => {
778
+ f();
779
+ }, [f]), {
780
+ business: i,
781
+ types: o,
782
+ failed: l,
783
+ reload: f
784
+ };
785
+ }
786
+ function be(e, t) {
787
+ if (e.failed) return /* @__PURE__ */ p("section", {
664
788
  className: "cp-screen",
665
- children: [y, /* @__PURE__ */ d(I, { onRetry: v })]
789
+ children: [t, /* @__PURE__ */ f(L, { onRetry: e.reload })]
666
790
  });
667
- if (c === null) return /* @__PURE__ */ f("section", {
791
+ if (e.business === null) return /* @__PURE__ */ p("section", {
668
792
  className: "cp-screen",
669
- children: [y, /* @__PURE__ */ d("p", {
793
+ children: [t, /* @__PURE__ */ f("p", {
670
794
  className: "cp-empty",
671
- children: w("business.notFound")
795
+ children: T("business.notFound")
672
796
  })]
673
797
  });
674
- if (c === void 0 || !m) return /* @__PURE__ */ f("section", {
798
+ if (e.business === void 0 || !e.types) return /* @__PURE__ */ p("section", {
675
799
  className: "cp-screen",
676
- children: [y, /* @__PURE__ */ d("p", {
800
+ children: [t, /* @__PURE__ */ f("p", {
677
801
  role: "status",
678
- children: w("app.loading")
802
+ children: T("app.loading")
679
803
  })]
680
804
  });
681
- let x = m.find((e) => e.id === o);
682
- return /* @__PURE__ */ f("section", {
805
+ }
806
+ function xe(e) {
807
+ let t = /* @__PURE__ */ new Map();
808
+ for (let n of e) for (let e of n.resources) t.has(e.id) || t.set(e.id, e);
809
+ return [...t.values()];
810
+ }
811
+ function Se(e) {
812
+ let { navigate: t, accountNavigation: n } = x(), { businessId: r, eventTypeId: i, onFilter: a } = e, o = ye(r), s = n && /* @__PURE__ */ f("button", {
813
+ type: "button",
814
+ className: "cp-link cp-back",
815
+ onClick: () => t("businesses"),
816
+ children: T("business.all")
817
+ }), c = be(o, s), { business: l, types: u } = o;
818
+ if (c || !l || !u) return c;
819
+ let m = u.find((e) => e.id === i), h = a ? xe(m ? [m] : u) : [], g = h.some((t) => t.id === e.resourceId) ? e.resourceId : void 0, _ = (e) => {
820
+ if (!a) return t(e ? {
821
+ businessId: r,
822
+ eventTypeId: e
823
+ } : { businessId: r });
824
+ let n = u.find((t) => t.id === e), i = g && xe(n ? [n] : u).some((e) => e.id === g);
825
+ a({
826
+ ...e && { eventTypeId: e },
827
+ ...i && { resourceId: g }
828
+ });
829
+ };
830
+ return /* @__PURE__ */ p("section", {
683
831
  className: "cp-screen",
684
832
  children: [
685
- y,
686
- /* @__PURE__ */ f("header", {
833
+ s,
834
+ /* @__PURE__ */ p("header", {
687
835
  className: "cp-business-head",
688
- children: [/* @__PURE__ */ d("h1", { children: c.displayName }), c.address && /* @__PURE__ */ d("p", {
836
+ children: [/* @__PURE__ */ f("h1", { children: l.displayName }), l.address && /* @__PURE__ */ f("p", {
689
837
  className: "cp-hint",
690
- children: c.address
838
+ children: l.address
691
839
  })]
692
840
  }),
693
- m.length > 0 && /* @__PURE__ */ f("fieldset", {
841
+ u.length > 0 && /* @__PURE__ */ p("fieldset", {
694
842
  className: "cp-chips",
695
- "aria-label": w("business.types"),
696
- children: [/* @__PURE__ */ d("button", {
843
+ "aria-label": T("business.types"),
844
+ children: [/* @__PURE__ */ f("button", {
697
845
  type: "button",
698
- "aria-pressed": !o,
699
- onClick: () => i({ businessId: a }),
700
- children: w("business.allTypes")
701
- }), m.map((e) => /* @__PURE__ */ d("button", {
846
+ "aria-pressed": !i,
847
+ onClick: () => _(void 0),
848
+ children: T("business.allTypes")
849
+ }), u.map((e) => /* @__PURE__ */ f("button", {
702
850
  type: "button",
703
- "aria-pressed": e.id === o,
704
- onClick: () => i({
705
- businessId: a,
706
- eventTypeId: e.id
707
- }),
851
+ "aria-pressed": e.id === i,
852
+ onClick: () => _(e.id),
708
853
  children: e.displayName
709
854
  }, e.id))]
710
855
  }),
711
- o && !x ? /* @__PURE__ */ d("p", {
712
- className: "cp-empty",
713
- children: w("business.typeMissing")
714
- }) : /* @__PURE__ */ f(u, { children: [x && /* @__PURE__ */ f("div", {
715
- className: "cp-type",
856
+ a && h.length > 1 && /* @__PURE__ */ p("fieldset", {
857
+ className: "cp-chips",
716
858
  children: [
717
- /* @__PURE__ */ d("h2", { children: x.displayName }),
718
- x.description && /* @__PURE__ */ d("p", { children: x.description }),
719
- /* @__PURE__ */ d("p", {
720
- className: "cp-hint",
721
- children: w("business.minutes", { minutes: x.durationMinutes })
722
- })
859
+ /* @__PURE__ */ f("legend", { children: T("business.resources") }),
860
+ /* @__PURE__ */ f("button", {
861
+ type: "button",
862
+ "aria-pressed": !g,
863
+ onClick: () => a({ ...i && { eventTypeId: i } }),
864
+ children: T("business.anyResource")
865
+ }),
866
+ h.map((e) => /* @__PURE__ */ f("button", {
867
+ type: "button",
868
+ "aria-pressed": e.id === g,
869
+ onClick: () => a({
870
+ ...i && { eventTypeId: i },
871
+ resourceId: e.id
872
+ }),
873
+ children: e.displayName
874
+ }, e.id))
723
875
  ]
724
- }), /* @__PURE__ */ d(de, {
725
- business: c,
726
- eventTypeId: o,
727
- onChoose: (t) => e.onChoose(c, t)
876
+ }),
877
+ i && !m ? /* @__PURE__ */ f("p", {
878
+ className: "cp-empty",
879
+ children: T("business.typeMissing")
880
+ }) : /* @__PURE__ */ p(d, { children: [m && /* @__PURE__ */ f(J, { type: m }), /* @__PURE__ */ f(Ce, {
881
+ business: l,
882
+ eventTypeId: i,
883
+ resourceId: g,
884
+ onChoose: (t) => e.onChoose(l, t)
728
885
  })] })
729
886
  ]
730
887
  });
731
888
  }
732
- function de(e) {
733
- let { client: n } = b(), { business: i, eventTypeId: a } = e, o = i.timezone, [c, l] = s(0), [p, m] = s(), [h, g] = s(!1), _ = G(le(o), c * W), v = G(_, W), y = t(async () => {
734
- g(!1), m(void 0);
889
+ function J({ type: e }) {
890
+ return /* @__PURE__ */ p("div", {
891
+ className: "cp-type",
892
+ children: [
893
+ /* @__PURE__ */ f("h2", { children: e.displayName }),
894
+ e.description && /* @__PURE__ */ f("p", { children: e.description }),
895
+ /* @__PURE__ */ f("p", {
896
+ className: "cp-hint",
897
+ children: T("business.minutes", { minutes: e.durationMinutes })
898
+ })
899
+ ]
900
+ });
901
+ }
902
+ function Ce(e) {
903
+ 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(ve(c), l * _e), y = q(v, _e), b = t(async () => {
904
+ _(!1), h(void 0);
735
905
  try {
736
906
  let { data: e } = await n.GET("/web/businesses/{businessId}/availability", { params: {
737
907
  path: { businessId: i.id },
738
908
  query: {
739
- from: `${_}T00:00`,
740
- to: `${v}T00:00`,
741
- ...a && { eventTypeId: a }
909
+ from: `${v}T00:00`,
910
+ to: `${y}T00:00`,
911
+ ...a && { eventTypeId: a },
912
+ ...o && { resourceId: o }
742
913
  }
743
914
  } });
744
- m(e?.items ?? []);
915
+ h(e?.items ?? []);
745
916
  } catch {
746
- g(!0);
917
+ _(!0);
747
918
  }
748
919
  }, [
749
920
  n,
750
921
  i.id,
751
922
  a,
752
- _,
753
- v
923
+ o,
924
+ v,
925
+ y
754
926
  ]);
755
927
  r(() => {
756
- y();
757
- }, [y]);
758
- let x = Date.now(), S = /* @__PURE__ */ new Map();
759
- for (let e of p ?? []) {
760
- if (Date.parse(e.startsAt) <= x) continue;
761
- let t = j(e.startsAt, e.timezone);
762
- S.set(t, [...S.get(t) ?? [], e]);
928
+ b();
929
+ }, [b]);
930
+ let S = Date.now(), C = /* @__PURE__ */ new Map();
931
+ for (let e of m ?? []) {
932
+ if (Date.parse(e.startsAt) <= S) continue;
933
+ let t = M(e.startsAt, e.timezone);
934
+ C.set(t, [...C.get(t) ?? [], e]);
763
935
  }
764
- let C = w("business.weekOf", {
765
- from: A(`${_}T12:00:00Z`, "UTC"),
766
- to: A(`${G(v, -1)}T12:00:00Z`, "UTC")
936
+ let w = T("business.weekOf", {
937
+ from: j(`${v}T12:00:00Z`, "UTC"),
938
+ to: j(`${q(y, -1)}T12:00:00Z`, "UTC")
767
939
  });
768
- return /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ f("fieldset", {
940
+ return /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("fieldset", {
769
941
  className: "cp-week",
770
- "aria-label": w("business.week"),
942
+ "aria-label": T("business.week"),
771
943
  children: [
772
- /* @__PURE__ */ d("button", {
944
+ /* @__PURE__ */ f("button", {
773
945
  type: "button",
774
946
  className: "cp-secondary",
775
- disabled: c === 0,
776
- onClick: () => l((e) => e - 1),
777
- "aria-label": w("business.previousWeek"),
947
+ disabled: l === 0,
948
+ onClick: () => u((e) => e - 1),
949
+ "aria-label": T("business.previousWeek"),
778
950
  children: "‹"
779
951
  }),
780
- /* @__PURE__ */ d("span", { children: C }),
781
- /* @__PURE__ */ d("button", {
952
+ /* @__PURE__ */ f("span", { children: w }),
953
+ /* @__PURE__ */ f("button", {
782
954
  type: "button",
783
955
  className: "cp-secondary",
784
- onClick: () => l((e) => e + 1),
785
- "aria-label": w("business.nextWeek"),
956
+ onClick: () => u((e) => e + 1),
957
+ "aria-label": T("business.nextWeek"),
786
958
  children: "›"
787
959
  })
788
960
  ]
789
- }), h ? /* @__PURE__ */ d(I, { onRetry: y }) : p ? S.size === 0 ? /* @__PURE__ */ d("p", {
961
+ }), g ? /* @__PURE__ */ f(L, { onRetry: b }) : m ? C.size === 0 ? /* @__PURE__ */ f("p", {
790
962
  className: "cp-empty",
791
- children: w("business.empty")
792
- }) : [...S].map(([t, n]) => /* @__PURE__ */ f("div", {
963
+ children: T("business.empty")
964
+ }) : [...C].map(([t, n]) => /* @__PURE__ */ p("div", {
793
965
  className: "cp-day",
794
- children: [/* @__PURE__ */ d("h2", { children: t }), /* @__PURE__ */ d("ul", {
966
+ children: [/* @__PURE__ */ f("h2", { children: t }), /* @__PURE__ */ f("ul", {
795
967
  className: "cp-list",
796
- children: n.map((t) => /* @__PURE__ */ d(fe, {
968
+ children: n.map((t) => /* @__PURE__ */ f(we, {
797
969
  candidate: t,
798
970
  onChoose: () => e.onChoose(t)
799
971
  }, `${t.eventId ?? t.eventTypeId}-${t.resource?.id ?? ""}-${t.startsAt}`))
800
972
  })]
801
- }, t)) : /* @__PURE__ */ d("p", {
973
+ }, t)) : /* @__PURE__ */ f("p", {
802
974
  role: "status",
803
- children: w("app.loading")
975
+ children: T("app.loading")
804
976
  })] });
805
977
  }
806
- function fe(e) {
978
+ function we(e) {
807
979
  let { candidate: t } = e, n = t.kind === "slot";
808
- return /* @__PURE__ */ f("li", {
980
+ return /* @__PURE__ */ p("li", {
809
981
  className: "cp-card cp-candidate",
810
982
  "data-kind": t.kind,
811
983
  children: [
812
- /* @__PURE__ */ f("p", {
984
+ /* @__PURE__ */ p("p", {
813
985
  className: "cp-time",
814
986
  children: [
815
- k(t.startsAt, t.timezone),
987
+ A(t.startsAt, t.timezone),
816
988
  " – ",
817
- k(t.endsAt, t.timezone)
989
+ A(t.endsAt, t.timezone)
818
990
  ]
819
991
  }),
820
- /* @__PURE__ */ f("div", {
992
+ /* @__PURE__ */ p("div", {
821
993
  className: "cp-candidate-body",
822
994
  children: [
823
- /* @__PURE__ */ d("h3", { children: t.title }),
824
- t.resource && /* @__PURE__ */ d("p", {
995
+ /* @__PURE__ */ f("h3", { children: t.title }),
996
+ t.resource && /* @__PURE__ */ f("p", {
825
997
  className: "cp-hint",
826
- children: w("business.with", { resource: t.resource.displayName })
998
+ children: T("business.with", { resource: t.resource.displayName })
827
999
  }),
828
- /* @__PURE__ */ d("p", {
1000
+ /* @__PURE__ */ f("p", {
829
1001
  className: "cp-hint",
830
- children: n ? w("business.openTime") : t.full ? w("business.full") : E("business.seatsLeft", t.seatsLeft)
1002
+ children: n ? T("business.openTime") : t.full ? T("business.full") : D("business.seatsLeft", t.seatsLeft)
831
1003
  })
832
1004
  ]
833
1005
  }),
834
- !t.full && /* @__PURE__ */ d("button", {
1006
+ !t.full && /* @__PURE__ */ f("button", {
835
1007
  type: "button",
836
1008
  onClick: e.onChoose,
837
- children: w("business.book")
1009
+ children: T("business.book")
838
1010
  })
839
1011
  ]
840
1012
  });
841
1013
  }
842
1014
  // src/screens/businesses.tsx
843
- function pe() {
844
- let { businesses: e, businessesStatus: t, reloadBusinesses: n, navigate: r } = b(), i = [...e.values()];
845
- return /* @__PURE__ */ f("section", {
1015
+ function Te() {
1016
+ let { businesses: e, businessesStatus: t, reloadBusinesses: n, navigate: r } = x(), i = [...e.values()];
1017
+ return /* @__PURE__ */ p("section", {
846
1018
  className: "cp-screen",
847
- children: [/* @__PURE__ */ d("h1", { children: w("businesses.heading") }), t === "failed" ? /* @__PURE__ */ d(I, { onRetry: n }) : t === "loading" ? /* @__PURE__ */ d("p", {
1019
+ children: [/* @__PURE__ */ f("h1", { children: T("businesses.heading") }), t === "failed" ? /* @__PURE__ */ f(L, { onRetry: n }) : t === "loading" ? /* @__PURE__ */ f("p", {
848
1020
  role: "status",
849
- children: w("app.loading")
850
- }) : i.length === 0 ? /* @__PURE__ */ d("p", {
1021
+ children: T("app.loading")
1022
+ }) : i.length === 0 ? /* @__PURE__ */ f("p", {
851
1023
  className: "cp-empty",
852
- children: w("businesses.empty")
853
- }) : /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("p", {
1024
+ children: T("businesses.empty")
1025
+ }) : /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("p", {
854
1026
  className: "cp-hint",
855
- children: w("businesses.intro")
856
- }), /* @__PURE__ */ d("ul", {
1027
+ children: T("businesses.intro")
1028
+ }), /* @__PURE__ */ f("ul", {
857
1029
  className: "cp-list",
858
- children: i.map((e) => /* @__PURE__ */ f("li", {
1030
+ children: i.map((e) => /* @__PURE__ */ p("li", {
859
1031
  className: "cp-card cp-business",
860
1032
  children: [
861
- /* @__PURE__ */ d("h2", { children: e.displayName }),
862
- e.address && /* @__PURE__ */ d("p", { children: e.address }),
863
- /* @__PURE__ */ d("button", {
1033
+ /* @__PURE__ */ f("h2", { children: e.displayName }),
1034
+ e.address && /* @__PURE__ */ f("p", { children: e.address }),
1035
+ /* @__PURE__ */ f("button", {
864
1036
  type: "button",
865
1037
  onClick: () => r({ businessId: e.id }),
866
- children: w("businesses.open")
1038
+ children: T("businesses.open")
867
1039
  })
868
1040
  ]
869
1041
  }, e.id))
@@ -871,14 +1043,14 @@ function pe() {
871
1043
  });
872
1044
  }
873
1045
  // src/screens/details.tsx
874
- function me() {
875
- let { client: e, signOut: n } = b(), [i, a] = s(), [o, c] = s(""), [l, p] = s(!1), [m, h] = s(!1), [g, _] = s(), v = t(async () => {
876
- p(!1);
1046
+ function Ee() {
1047
+ 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 () => {
1048
+ u(!1);
877
1049
  try {
878
1050
  let { data: t } = await e.GET("/web/me");
879
1051
  t && (a(t), c(t.name));
880
1052
  } catch {
881
- p(!0);
1053
+ u(!0);
882
1054
  }
883
1055
  }, [e]);
884
1056
  r(() => {
@@ -903,7 +1075,7 @@ function me() {
903
1075
  h(!1);
904
1076
  }
905
1077
  }
906
- async function x() {
1078
+ async function b() {
907
1079
  h(!0), _(void 0);
908
1080
  try {
909
1081
  await e.DELETE("/web/me/sessions"), await n("app.signedOutEverywhere");
@@ -914,61 +1086,61 @@ function me() {
914
1086
  }), h(!1);
915
1087
  }
916
1088
  }
917
- return /* @__PURE__ */ f("section", {
1089
+ return /* @__PURE__ */ p("section", {
918
1090
  className: "cp-screen",
919
- children: [/* @__PURE__ */ d("h1", { children: w("details.heading") }), l ? /* @__PURE__ */ d(I, { onRetry: v }) : i ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ f("form", {
1091
+ children: [/* @__PURE__ */ f("h1", { children: T("details.heading") }), l ? /* @__PURE__ */ f(L, { onRetry: v }) : i ? /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("form", {
920
1092
  className: "cp-card cp-form",
921
1093
  onSubmit: y,
922
1094
  "aria-busy": m,
923
1095
  children: [
924
- /* @__PURE__ */ f("label", { children: [w("details.name"), /* @__PURE__ */ d("input", {
1096
+ /* @__PURE__ */ p("label", { children: [T("details.name"), /* @__PURE__ */ f("input", {
925
1097
  value: o,
926
1098
  onChange: (e) => c(e.target.value),
927
1099
  autoComplete: "name",
928
1100
  maxLength: 200,
929
1101
  required: !0
930
1102
  })] }),
931
- /* @__PURE__ */ f("dl", { children: [
932
- /* @__PURE__ */ d("dt", { children: w("details.phone") }),
933
- /* @__PURE__ */ d("dd", { children: i.phone ?? w("details.none") }),
934
- /* @__PURE__ */ d("dt", { children: w("details.email") }),
935
- /* @__PURE__ */ d("dd", { children: i.email ?? w("details.none") })
1103
+ /* @__PURE__ */ p("dl", { children: [
1104
+ /* @__PURE__ */ f("dt", { children: T("details.phone") }),
1105
+ /* @__PURE__ */ f("dd", { children: i.phone ?? T("details.none") }),
1106
+ /* @__PURE__ */ f("dt", { children: T("details.email") }),
1107
+ /* @__PURE__ */ f("dd", { children: i.email ?? T("details.none") })
936
1108
  ] }),
937
- /* @__PURE__ */ d("p", {
1109
+ /* @__PURE__ */ f("p", {
938
1110
  className: "cp-hint",
939
- children: w("details.readOnly")
1111
+ children: T("details.readOnly")
940
1112
  }),
941
- g && /* @__PURE__ */ d("p", {
1113
+ g && /* @__PURE__ */ f("p", {
942
1114
  role: g.alert ? "alert" : "status",
943
- children: w(g.key)
1115
+ children: T(g.key)
944
1116
  }),
945
- /* @__PURE__ */ d("button", {
1117
+ /* @__PURE__ */ f("button", {
946
1118
  type: "submit",
947
1119
  disabled: m || !o.trim() || o.trim() === i.name,
948
- children: w(m ? "details.saving" : "details.save")
1120
+ children: T(m ? "details.saving" : "details.save")
949
1121
  })
950
1122
  ]
951
- }), /* @__PURE__ */ f("div", {
1123
+ }), /* @__PURE__ */ p("div", {
952
1124
  className: "cp-card cp-form",
953
- children: [/* @__PURE__ */ d("p", {
1125
+ children: [/* @__PURE__ */ f("p", {
954
1126
  className: "cp-hint",
955
- children: w("details.signOutEverywhereHint")
956
- }), /* @__PURE__ */ d("button", {
1127
+ children: T("details.signOutEverywhereHint")
1128
+ }), /* @__PURE__ */ f("button", {
957
1129
  type: "button",
958
1130
  className: "cp-secondary",
959
1131
  disabled: m,
960
- onClick: x,
961
- children: w("details.signOutEverywhere")
1132
+ onClick: b,
1133
+ children: T("details.signOutEverywhere")
962
1134
  })]
963
- })] }) : /* @__PURE__ */ d("p", {
1135
+ })] }) : /* @__PURE__ */ f("p", {
964
1136
  role: "status",
965
- children: w("app.loading")
1137
+ children: T("app.loading")
966
1138
  })]
967
1139
  });
968
1140
  }
969
1141
  // src/screens/passes.tsx
970
- function he() {
971
- let { client: e, businesses: n } = b(), [i, a] = s(), [o, c] = s(!1), l = t(async () => {
1142
+ function De() {
1143
+ let { client: e, businesses: n } = x(), [i, a] = s(), [o, c] = s(!1), l = t(async () => {
972
1144
  c(!1);
973
1145
  try {
974
1146
  let { data: t } = await e.GET("/web/me/memberships");
@@ -979,63 +1151,63 @@ function he() {
979
1151
  }, [e]);
980
1152
  return r(() => {
981
1153
  l();
982
- }, [l]), /* @__PURE__ */ f("section", {
1154
+ }, [l]), /* @__PURE__ */ p("section", {
983
1155
  className: "cp-screen",
984
- children: [/* @__PURE__ */ d("h1", { children: w("passes.heading") }), o ? /* @__PURE__ */ d(I, { onRetry: l }) : i ? i.length === 0 ? /* @__PURE__ */ d("p", {
1156
+ children: [/* @__PURE__ */ f("h1", { children: T("passes.heading") }), o ? /* @__PURE__ */ f(L, { onRetry: l }) : i ? i.length === 0 ? /* @__PURE__ */ f("p", {
985
1157
  className: "cp-empty",
986
- children: w("passes.empty")
987
- }) : /* @__PURE__ */ d("ul", {
1158
+ children: T("passes.empty")
1159
+ }) : /* @__PURE__ */ f("ul", {
988
1160
  className: "cp-list",
989
1161
  children: i.map((e) => {
990
1162
  let t = n.get(e.businessId), r = t?.timezone, i = e.validUntil !== null && Date.parse(e.validUntil) <= Date.now();
991
- return /* @__PURE__ */ f("li", {
1163
+ return /* @__PURE__ */ p("li", {
992
1164
  className: "cp-card",
993
1165
  children: [
994
- /* @__PURE__ */ f("div", {
1166
+ /* @__PURE__ */ p("div", {
995
1167
  className: "cp-card-head",
996
- children: [/* @__PURE__ */ d("h2", { children: e.displayName }), i && /* @__PURE__ */ d("span", {
1168
+ children: [/* @__PURE__ */ f("h2", { children: e.displayName }), i && /* @__PURE__ */ f("span", {
997
1169
  className: "cp-badge",
998
- children: w("passes.expired")
1170
+ children: T("passes.expired")
999
1171
  })]
1000
1172
  }),
1001
- t && /* @__PURE__ */ d("p", { children: t.displayName }),
1002
- /* @__PURE__ */ d("p", {
1173
+ t && /* @__PURE__ */ f("p", { children: t.displayName }),
1174
+ /* @__PURE__ */ f("p", {
1003
1175
  className: "cp-credits",
1004
- children: e.creditsRemaining === null || e.creditsTotal === null ? w("passes.unlimited") : w("passes.credits", {
1176
+ children: e.creditsRemaining === null || e.creditsTotal === null ? T("passes.unlimited") : T("passes.credits", {
1005
1177
  remaining: e.creditsRemaining,
1006
1178
  total: e.creditsTotal
1007
1179
  })
1008
1180
  }),
1009
- /* @__PURE__ */ d("p", {
1181
+ /* @__PURE__ */ f("p", {
1010
1182
  className: "cp-hint",
1011
- children: e.validUntil ? w("passes.validRange", {
1012
- from: A(e.validFrom, r),
1013
- until: A(e.validUntil, r)
1014
- }) : w("passes.validFrom", { date: A(e.validFrom, r) })
1183
+ children: e.validUntil ? T("passes.validRange", {
1184
+ from: j(e.validFrom, r),
1185
+ until: j(e.validUntil, r)
1186
+ }) : T("passes.validFrom", { date: j(e.validFrom, r) })
1015
1187
  })
1016
1188
  ]
1017
1189
  }, e.id);
1018
1190
  })
1019
- }) : /* @__PURE__ */ d("p", {
1191
+ }) : /* @__PURE__ */ f("p", {
1020
1192
  role: "status",
1021
- children: w("app.loading")
1193
+ children: T("app.loading")
1022
1194
  })]
1023
1195
  });
1024
1196
  }
1025
1197
  // ../ui/dist/index.js
1026
- var ge = new Intl.DisplayNames(["en"], { type: "region" }), K = (e) => e.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim(), q = m().map((e) => ({
1198
+ var Oe = new Intl.DisplayNames(["en"], { type: "region" }), ke = (e) => e.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim(), Y = h().map((e) => ({
1027
1199
  code: e,
1028
- name: ge.of(e) ?? e,
1029
- callingCode: h(e),
1200
+ name: Oe.of(e) ?? e,
1201
+ callingCode: g(e),
1030
1202
  flag: String.fromCodePoint(...[...e].map((e) => 127397 + e.charCodeAt(0)))
1031
- })).sort((e, t) => e.name.localeCompare(t.name)), _e = new Map(q.map((e) => [e.code, e])), J = (e) => _e.get(e);
1032
- function ve(e) {
1033
- let t = i(), n = o(null), a = o(null), c = o(null), [l, u] = s(""), p = e.search(l), m = () => n.current?.close(), h = (t) => {
1203
+ })).sort((e, t) => e.name.localeCompare(t.name)), Ae = new Map(Y.map((e) => [e.code, e])), je = (e) => Ae.get(e);
1204
+ function Me(e) {
1205
+ 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) => {
1034
1206
  m(), e.onPick(t);
1035
1207
  };
1036
1208
  return r(() => {
1037
1209
  n.current?.showModal(), a.current?.focus(), document.getElementById(`${t}-${e.selected}`)?.scrollIntoView({ block: "center" });
1038
- }, [t, e.selected]), /* @__PURE__ */ f("dialog", {
1210
+ }, [t, e.selected]), /* @__PURE__ */ p("dialog", {
1039
1211
  ref: n,
1040
1212
  className: "msm-picker-dialog",
1041
1213
  "aria-labelledby": `${t}-title`,
@@ -1044,18 +1216,18 @@ function ve(e) {
1044
1216
  e.target === n.current && m();
1045
1217
  },
1046
1218
  children: [
1047
- /* @__PURE__ */ f("div", {
1219
+ /* @__PURE__ */ p("div", {
1048
1220
  className: "msm-picker-head",
1049
- children: [/* @__PURE__ */ d("h2", {
1221
+ children: [/* @__PURE__ */ f("h2", {
1050
1222
  id: `${t}-title`,
1051
1223
  children: e.title
1052
- }), /* @__PURE__ */ d("button", {
1224
+ }), /* @__PURE__ */ f("button", {
1053
1225
  type: "button",
1054
1226
  onClick: m,
1055
1227
  children: "Close"
1056
1228
  })]
1057
1229
  }),
1058
- /* @__PURE__ */ d("input", {
1230
+ /* @__PURE__ */ f("input", {
1059
1231
  ref: a,
1060
1232
  className: "msm-picker-search",
1061
1233
  type: "search",
@@ -1068,45 +1240,45 @@ function ve(e) {
1068
1240
  u(e.target.value), c.current && (c.current.scrollTop = 0);
1069
1241
  },
1070
1242
  onKeyDown: (e) => {
1071
- e.key === "Enter" && (e.preventDefault(), l.trim() !== "" && p[0] && h(p[0].value));
1243
+ e.key === "Enter" && (e.preventDefault(), l.trim() !== "" && d[0] && h(d[0].value));
1072
1244
  }
1073
1245
  }),
1074
- /* @__PURE__ */ d("ul", {
1246
+ /* @__PURE__ */ f("ul", {
1075
1247
  ref: c,
1076
1248
  "aria-label": e.listLabel,
1077
- children: p.map((n, r) => /* @__PURE__ */ d("li", { children: /* @__PURE__ */ f("button", {
1249
+ children: d.map((n, r) => /* @__PURE__ */ f("li", { children: /* @__PURE__ */ p("button", {
1078
1250
  type: "button",
1079
1251
  id: `${t}-${n.value}`,
1080
1252
  "aria-current": n.value === e.selected || void 0,
1081
1253
  className: r === 0 && l.trim() !== "" ? "msm-picker-first" : void 0,
1082
1254
  onClick: () => h(n.value),
1083
1255
  children: [
1084
- n.flag && /* @__PURE__ */ d("span", {
1256
+ n.flag && /* @__PURE__ */ f("span", {
1085
1257
  "aria-hidden": "true",
1086
1258
  children: n.flag
1087
1259
  }),
1088
- /* @__PURE__ */ d("span", {
1260
+ /* @__PURE__ */ f("span", {
1089
1261
  className: "msm-picker-label",
1090
1262
  children: n.label
1091
1263
  }),
1092
- n.hint && /* @__PURE__ */ d("span", {
1264
+ n.hint && /* @__PURE__ */ f("span", {
1093
1265
  className: "msm-picker-hint",
1094
1266
  children: n.hint
1095
1267
  })
1096
1268
  ]
1097
1269
  }) }, n.value))
1098
1270
  }),
1099
- p.length === 0 && /* @__PURE__ */ d("p", {
1271
+ d.length === 0 && /* @__PURE__ */ f("p", {
1100
1272
  className: "msm-picker-empty",
1101
1273
  children: e.empty(l)
1102
1274
  })
1103
1275
  ]
1104
1276
  });
1105
1277
  }
1106
- var Y = new p(), X = (e) => J(e);
1107
- function Z(e) {
1278
+ var Ne = new m(), X = (e) => je(e);
1279
+ function Pe(e) {
1108
1280
  for (let t = 1; t <= 3 && t <= e.length; t++) {
1109
- let n = e.slice(0, t), r = (v.country_calling_codes[n] ?? []).filter((e) => J(e) !== void 0), [i] = r;
1281
+ let n = e.slice(0, t), r = (y.country_calling_codes[n] ?? []).filter((e) => je(e) !== void 0), [i] = r;
1110
1282
  if (i) return {
1111
1283
  code: n,
1112
1284
  first: i,
@@ -1115,97 +1287,97 @@ function Z(e) {
1115
1287
  }
1116
1288
  return null;
1117
1289
  }
1118
- function Q(e, t) {
1290
+ function Fe(e, t) {
1119
1291
  let n = /^\s*(\+|00)/.exec(e);
1120
1292
  if (!n) return null;
1121
- let r = e.slice(n[0].length), i = r.replace(/\D/g, ""), a = Z(i);
1293
+ let r = e.slice(n[0].length), i = r.replace(/\D/g, ""), a = Pe(i);
1122
1294
  if (!a) return null;
1123
- let o = g(`+${i}`), s = a.countries.includes(t) ? t : o?.country ?? a.first, c = 0;
1295
+ let o = _(`+${i}`), s = a.countries.includes(t) ? t : o?.country ?? a.first, c = 0;
1124
1296
  for (let e = 0; e < a.code.length; c++) /\d/.test(r.charAt(c)) && e++;
1125
1297
  return {
1126
1298
  country: s,
1127
1299
  text: o?.isValid() ? o.formatNational() : r.slice(c).replace(/^[\s\-().]+/, "")
1128
1300
  };
1129
1301
  }
1130
- function ye(e, t) {
1302
+ function Ie(e, t) {
1131
1303
  let n = t.replace(/\D/g, "");
1132
- return n === "" ? "" : t.trim().startsWith("+") ? `+${n}` : g(t, e)?.number ?? `+${X(e).callingCode}${n}`;
1304
+ return n === "" ? "" : t.trim().startsWith("+") ? `+${n}` : _(t, e)?.number ?? `+${X(e).callingCode}${n}`;
1133
1305
  }
1134
- function be(e) {
1135
- return Y.selectNumberingPlan(e), Y.numberingPlan?.possibleLengths() ?? [];
1306
+ function Le(e) {
1307
+ return Ne.selectNumberingPlan(e), Ne.numberingPlan?.possibleLengths() ?? [];
1136
1308
  }
1137
- function xe(e, t, n) {
1309
+ function Re(e, t, n) {
1138
1310
  if (e === "") return t ? "Enter a phone number." : "";
1139
- let r = g(e);
1311
+ let r = _(e);
1140
1312
  if (r?.isValid()) return "";
1141
- let i = e.replace(/\D/g, ""), a = Z(i);
1313
+ let i = e.replace(/\D/g, ""), a = Pe(i);
1142
1314
  if (!a) return "Unknown country code. Choose the country from the list.";
1143
- let o = n && a.countries.includes(n) ? n : r?.country ?? a.first, s = X(o).name, c = _(i.slice(a.code.length), o);
1315
+ let o = n && a.countries.includes(n) ? n : r?.country ?? a.first, s = X(o).name, c = v(i.slice(a.code.length), o);
1144
1316
  if (c && c !== "NOT_A_NUMBER") {
1145
- let e = be(o), t = e[0] ?? 0, n = e[e.length - 1] ?? 0;
1317
+ let e = Le(o), t = e[0] ?? 0, n = e[e.length - 1] ?? 0;
1146
1318
  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}.`;
1147
1319
  }
1148
1320
  return `This is not a valid number for ${s}.`;
1149
1321
  }
1150
- function Se(e, t = !1) {
1151
- return xe(e, t);
1322
+ function ze(e, t = !1) {
1323
+ return Re(e, t);
1152
1324
  }
1153
- function Ce(e, t) {
1154
- return Q(e, t) ?? {
1325
+ function Be(e, t) {
1326
+ return Fe(e, t) ?? {
1155
1327
  country: t,
1156
1328
  text: e
1157
1329
  };
1158
1330
  }
1159
- function we(e) {
1331
+ function Ve(e) {
1160
1332
  let t = i(), n = o(null), [a, c] = s(() => ({
1161
1333
  value: e.value,
1162
- ...Ce(e.value, "IS")
1334
+ ...Be(e.value, "IS")
1163
1335
  })), l = a;
1164
1336
  e.value !== a.value && (l = {
1165
1337
  value: e.value,
1166
- ...Ce(e.value, a.country)
1338
+ ...Be(e.value, a.country)
1167
1339
  }, c(l));
1168
- let [u, p] = s(!1), [m, h] = s(!1), g = X(l.country), _ = xe(l.value, e.required ?? !1, l.country), v = u && _ !== "" ? _ : e.error ?? "", y = v !== "";
1340
+ let [u, d] = s(!1), [m, h] = s(!1), g = X(l.country), _ = Re(l.value, e.required ?? !1, l.country), v = u && _ !== "" ? _ : e.error ?? "", y = v !== "";
1169
1341
  r(() => {
1170
1342
  let e = n.current?.form;
1171
1343
  if (!e) return;
1172
1344
  let t = () => {
1173
- p(!0), e.querySelector("[data-msm-phone-problem]") === n.current && n.current?.focus();
1345
+ d(!0), e.querySelector("[data-msm-phone-problem]") === n.current && n.current?.focus();
1174
1346
  };
1175
1347
  return e.addEventListener("submit", t), () => e.removeEventListener("submit", t);
1176
1348
  }, []);
1177
1349
  let b = (t, n) => {
1178
- let r = ye(t, n);
1350
+ let r = Ie(t, n);
1179
1351
  c({
1180
1352
  value: r,
1181
1353
  country: t,
1182
1354
  text: n
1183
1355
  }), r !== e.value && e.onChange(r);
1184
1356
  };
1185
- return /* @__PURE__ */ f("div", {
1357
+ return /* @__PURE__ */ p("div", {
1186
1358
  className: "msm-phone",
1187
1359
  children: [
1188
- /* @__PURE__ */ d("label", {
1360
+ /* @__PURE__ */ f("label", {
1189
1361
  htmlFor: `${t}-number`,
1190
1362
  children: e.label
1191
1363
  }),
1192
- /* @__PURE__ */ f("div", {
1364
+ /* @__PURE__ */ p("div", {
1193
1365
  className: "msm-phone-row",
1194
- children: [/* @__PURE__ */ f("button", {
1366
+ children: [/* @__PURE__ */ p("button", {
1195
1367
  type: "button",
1196
1368
  className: "msm-phone-country",
1197
1369
  "aria-label": `Country code: ${g.name} +${g.callingCode}`,
1198
1370
  "aria-haspopup": "dialog",
1199
1371
  onClick: () => h(!0),
1200
1372
  children: [
1201
- /* @__PURE__ */ d("span", {
1373
+ /* @__PURE__ */ f("span", {
1202
1374
  "aria-hidden": "true",
1203
1375
  children: g.flag
1204
1376
  }),
1205
1377
  "+",
1206
1378
  g.callingCode
1207
1379
  ]
1208
- }), /* @__PURE__ */ d("input", {
1380
+ }), /* @__PURE__ */ f("input", {
1209
1381
  ref: n,
1210
1382
  id: `${t}-number`,
1211
1383
  className: "msm-phone-number",
@@ -1218,26 +1390,26 @@ function we(e) {
1218
1390
  "aria-invalid": y || void 0,
1219
1391
  "aria-describedby": y ? `${t}-problem` : void 0,
1220
1392
  onChange: (e) => {
1221
- let t = e.target.value.replace(/[^\d\s\-().+]/g, ""), n = Q(t, l.country);
1393
+ let t = e.target.value.replace(/[^\d\s\-().+]/g, ""), n = Fe(t, l.country);
1222
1394
  b(n?.country ?? l.country, n?.text ?? t);
1223
1395
  },
1224
1396
  onBlur: () => {
1225
- l.text.trim() !== "" && p(!0);
1397
+ l.text.trim() !== "" && d(!0);
1226
1398
  }
1227
1399
  })]
1228
1400
  }),
1229
- y && /* @__PURE__ */ d("p", {
1401
+ y && /* @__PURE__ */ f("p", {
1230
1402
  id: `${t}-problem`,
1231
1403
  className: "msm-phone-problem",
1232
1404
  role: "alert",
1233
1405
  children: v
1234
1406
  }),
1235
- m && /* @__PURE__ */ d(ve, {
1407
+ m && /* @__PURE__ */ f(Me, {
1236
1408
  title: "Country code",
1237
1409
  searchLabel: "Search by country or code",
1238
1410
  listLabel: "Countries",
1239
1411
  empty: (e) => `No country matches “${e}”.`,
1240
- search: Te,
1412
+ search: He,
1241
1413
  selected: l.country,
1242
1414
  onClose: () => h(!1),
1243
1415
  onPick: (e) => {
@@ -1247,9 +1419,9 @@ function we(e) {
1247
1419
  ]
1248
1420
  });
1249
1421
  }
1250
- function Te(e) {
1251
- let t = K(e).replace(/^(\+|00)/, "");
1252
- return (t === "" ? q : /^\d+$/.test(t) ? q.filter((e) => e.callingCode.startsWith(t)) : q.filter((e) => K(e.name).includes(t) || e.code.toLowerCase() === t)).map((e) => ({
1422
+ function He(e) {
1423
+ let t = ke(e).replace(/^(\+|00)/, "");
1424
+ return (t === "" ? Y : /^\d+$/.test(t) ? Y.filter((e) => e.callingCode.startsWith(t)) : Y.filter((e) => ke(e.name).includes(t) || e.code.toLowerCase() === t)).map((e) => ({
1253
1425
  value: e.code,
1254
1426
  label: e.name,
1255
1427
  hint: `+${e.callingCode}`,
@@ -1257,31 +1429,31 @@ function Te(e) {
1257
1429
  }));
1258
1430
  }
1259
1431
  // src/bot-check.tsx
1260
- var Ee = () => window.turnstile, De = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit", $;
1261
- function Oe() {
1262
- let e = Ee();
1263
- return e ? Promise.resolve(e) : ($ ??= new Promise((e, t) => {
1432
+ var Ue = () => window.turnstile, We = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit", Z;
1433
+ function Ge() {
1434
+ let e = Ue();
1435
+ return e ? Promise.resolve(e) : (Z ??= new Promise((e, t) => {
1264
1436
  let n = document.createElement("script");
1265
- n.src = De, n.async = !0;
1437
+ n.src = We, n.async = !0;
1266
1438
  let r = () => {
1267
- $ = void 0, n.remove(), t(/* @__PURE__ */ Error("Turnstile did not load."));
1439
+ Z = void 0, n.remove(), t(/* @__PURE__ */ Error("Turnstile did not load."));
1268
1440
  };
1269
1441
  n.onload = () => {
1270
- let t = Ee();
1442
+ let t = Ue();
1271
1443
  t ? e(t) : r();
1272
1444
  }, n.onerror = r, document.head.append(n);
1273
- }), $);
1445
+ }), Z);
1274
1446
  }
1275
- function ke(e) {
1447
+ function Ke(e) {
1276
1448
  return e?.provider === "turnstile" && typeof e.siteKey == "string" && e.siteKey.trim() !== "";
1277
1449
  }
1278
- function Ae(e) {
1450
+ function qe(e) {
1279
1451
  let t = o(null), n = o(void 0), i = o(e);
1280
1452
  i.current = e;
1281
1453
  let { siteKey: a } = e.botCheck;
1282
1454
  r(() => {
1283
1455
  let e = !0;
1284
- return Oe().then((r) => {
1456
+ return Ge().then((r) => {
1285
1457
  let o = t.current;
1286
1458
  if (!e || !o) return;
1287
1459
  let s = r.render(o, {
@@ -1307,238 +1479,566 @@ function Ae(e) {
1307
1479
  if (s === 0) return;
1308
1480
  let e = n.current;
1309
1481
  i.current.onToken(void 0), e?.api.reset(e.id);
1310
- }, [s]), /* @__PURE__ */ d("div", {
1482
+ }, [s]), /* @__PURE__ */ f("div", {
1311
1483
  className: "cp-bot-check",
1312
1484
  ref: t
1313
1485
  });
1314
1486
  }
1315
1487
  // src/sign-in.tsx
1316
- function je(e) {
1317
- let [t, n] = s("sign-in"), [i, a] = s(""), [o, c] = s(""), [l, p] = s(""), [m, h] = s(), [g, _] = s(), [v, y] = s(!1), [b, x] = s(), [S, C] = s(0), T = ke(e.botCheck) ? e.botCheck : void 0, [E, D] = s();
1488
+ function Q(e) {
1489
+ let t = o(null), n = e.autoFocus;
1490
+ r(() => {
1491
+ n && t.current?.querySelector("input")?.focus();
1492
+ }, [n]);
1493
+ let [i, a] = s("sign-in"), [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 = Ke(e.botCheck) ? e.botCheck : void 0, [k, A] = s();
1318
1494
  r(() => {
1319
- if (!E) return;
1495
+ if (!k) return;
1320
1496
  let e = setTimeout(() => {
1321
- D(void 0), _((e) => e === E.message ? void 0 : e);
1322
- }, E.seconds * 1e3);
1497
+ A(void 0), b((e) => e === k.message ? void 0 : e);
1498
+ }, k.seconds * 1e3);
1323
1499
  return () => clearTimeout(e);
1324
- }, [E]);
1325
- let O = t === "register";
1326
- async function k(t) {
1327
- if (t.preventDefault(), m || !Se(o, !0) && T && b) {
1328
- y(!0), _(void 0);
1500
+ }, [k]);
1501
+ let j = i === "register";
1502
+ async function M(t) {
1503
+ if (t.preventDefault(), _ || !ze(u, !0) && O && C) {
1504
+ S(!0), b(void 0);
1329
1505
  try {
1330
- let t = m ? await H(e.basePath, O ? "/auth/register" : "/auth/login", {
1331
- challenge: m,
1332
- code: l
1333
- }) : O ? await H(e.basePath, "/auth/register/initiate", {
1334
- phone: o,
1335
- name: i.trim(),
1336
- botCheckToken: b
1337
- }) : await H(e.basePath, "/auth/initiate", {
1338
- phone: o,
1339
- botCheckToken: b
1506
+ let t = _ ? await V(e.basePath, j ? "/auth/register" : "/auth/login", {
1507
+ challenge: _,
1508
+ code: h
1509
+ }) : j ? await V(e.basePath, "/auth/register/initiate", {
1510
+ phone: u,
1511
+ name: c.trim(),
1512
+ botCheckToken: C
1513
+ }) : await V(e.basePath, "/auth/initiate", {
1514
+ phone: u,
1515
+ botCheckToken: C
1340
1516
  });
1341
1517
  if (t.ok) {
1342
1518
  let n = await t.json();
1343
- m ? e.onSignedIn(n.sessionKey) : h(n.challenge);
1519
+ _ ? e.onSignedIn(n.sessionKey) : v(n.challenge);
1344
1520
  return;
1345
1521
  }
1346
- let n = await t.json().catch(() => void 0), r = Number(t.headers.get("retry-after")), a = Number.isInteger(r) && r > 0 ? r : void 0, s = Me(t.status, n?.code, a, !!m, O);
1347
- t.status === 429 && a && !m && D({
1348
- phone: o,
1349
- seconds: a,
1350
- message: s
1351
- }), _(s);
1522
+ let n = await t.json().catch(() => void 0), r = Number(t.headers.get("retry-after")), i = Number.isInteger(r) && r > 0 ? r : void 0, a = Je(t.status, n?.code, i, !!_, j);
1523
+ t.status === 429 && i && !_ && A({
1524
+ phone: u,
1525
+ seconds: i,
1526
+ message: a
1527
+ }), b(a);
1352
1528
  } catch {
1353
- _(w("signIn.error.unreachable"));
1529
+ b(T("signIn.error.unreachable"));
1354
1530
  } finally {
1355
- y(!1), m || C((e) => e + 1);
1531
+ S(!1), _ || D((e) => e + 1);
1356
1532
  }
1357
1533
  }
1358
1534
  }
1359
- function A(e) {
1360
- n(e), h(void 0), p(""), _(void 0);
1535
+ function N(e) {
1536
+ a(e), v(void 0), g(""), b(void 0);
1361
1537
  }
1362
- return /* @__PURE__ */ d("div", {
1538
+ return /* @__PURE__ */ f("div", {
1363
1539
  className: "cp-sign-in",
1364
- children: /* @__PURE__ */ f("form", {
1365
- onSubmit: k,
1366
- "aria-busy": v,
1540
+ children: /* @__PURE__ */ p("form", {
1541
+ ref: t,
1542
+ onSubmit: M,
1543
+ "aria-busy": x,
1367
1544
  children: [
1368
- /* @__PURE__ */ d(U, { brand: e.brand }),
1369
- /* @__PURE__ */ d("h1", { children: w(O ? "register.heading" : "signIn.heading") }),
1545
+ /* @__PURE__ */ f(se, { brand: e.brand }),
1546
+ /* @__PURE__ */ f("h1", { children: T(j ? "register.heading" : "signIn.heading") }),
1370
1547
  e.children,
1371
- e.notice && !m && /* @__PURE__ */ d("p", {
1548
+ e.notice && !_ && /* @__PURE__ */ f("p", {
1372
1549
  role: "status",
1373
1550
  className: "cp-notice",
1374
- children: w(e.notice)
1551
+ children: T(e.notice)
1375
1552
  }),
1376
- m ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("p", { children: w("signIn.codeSent", { phone: o }) }), /* @__PURE__ */ f("label", { children: [w("signIn.code"), /* @__PURE__ */ d("input", {
1377
- value: l,
1378
- onChange: (e) => p(e.target.value),
1553
+ _ ? /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("p", { children: T("signIn.codeSent", { phone: u }) }), /* @__PURE__ */ p("label", { children: [T("signIn.code"), /* @__PURE__ */ f("input", {
1554
+ value: h,
1555
+ onChange: (e) => g(e.target.value),
1379
1556
  inputMode: "numeric",
1380
1557
  autoComplete: "one-time-code",
1381
1558
  required: !0,
1382
1559
  autoFocus: !0
1383
- })] })] }) : /* @__PURE__ */ f(u, { children: [
1384
- /* @__PURE__ */ d("p", { children: w(O ? "register.intro" : "signIn.intro") }),
1385
- O && /* @__PURE__ */ f("label", { children: [w("register.name"), /* @__PURE__ */ d("input", {
1386
- value: i,
1387
- onChange: (e) => a(e.target.value),
1560
+ })] })] }) : /* @__PURE__ */ p(d, { children: [
1561
+ /* @__PURE__ */ f("p", { children: T(j ? "register.intro" : "signIn.intro") }),
1562
+ j && /* @__PURE__ */ p("label", { children: [T("register.name"), /* @__PURE__ */ f("input", {
1563
+ value: c,
1564
+ onChange: (e) => l(e.target.value),
1388
1565
  autoComplete: "name",
1389
1566
  maxLength: 200,
1390
1567
  required: !0
1391
1568
  })] }),
1392
- /* @__PURE__ */ d(we, {
1393
- label: w("signIn.phone"),
1394
- value: o,
1395
- onChange: c,
1569
+ /* @__PURE__ */ f(Ve, {
1570
+ label: T("signIn.phone"),
1571
+ value: u,
1572
+ onChange: m,
1396
1573
  required: !0
1397
1574
  }),
1398
- T && /* @__PURE__ */ d(Ae, {
1399
- botCheck: T,
1400
- attempt: S,
1401
- onToken: x,
1402
- onUnavailable: () => _(w("signIn.error.botCheckUnavailable"))
1575
+ O && /* @__PURE__ */ f(qe, {
1576
+ botCheck: O,
1577
+ attempt: E,
1578
+ onToken: w,
1579
+ onUnavailable: () => b(T("signIn.error.botCheckUnavailable"))
1403
1580
  })
1404
1581
  ] }),
1405
- !m && !T && /* @__PURE__ */ d("p", {
1582
+ !_ && !O && /* @__PURE__ */ f("p", {
1406
1583
  role: "alert",
1407
- children: w("signIn.error.notConfigured")
1584
+ children: T("signIn.error.notConfigured")
1408
1585
  }),
1409
- g && /* @__PURE__ */ d("p", {
1586
+ y && /* @__PURE__ */ f("p", {
1410
1587
  role: "alert",
1411
- children: g
1588
+ children: y
1412
1589
  }),
1413
- /* @__PURE__ */ d("button", {
1590
+ /* @__PURE__ */ f("button", {
1414
1591
  type: "submit",
1415
- disabled: v || !m && (!T || !b || E?.phone === o),
1416
- children: w(v ? "signIn.wait" : m ? O ? "register.submit" : "signIn.submit" : "signIn.sendCode")
1592
+ disabled: x || !_ && (!O || !C || k?.phone === u),
1593
+ children: T(x ? "signIn.wait" : _ ? j ? "register.submit" : "signIn.submit" : "signIn.sendCode")
1417
1594
  }),
1418
- m ? /* @__PURE__ */ d("button", {
1595
+ _ ? /* @__PURE__ */ f("button", {
1419
1596
  type: "button",
1420
1597
  className: "cp-secondary",
1421
- onClick: () => A(t),
1422
- children: w("signIn.differentNumber")
1423
- }) : /* @__PURE__ */ d("button", {
1598
+ onClick: () => N(i),
1599
+ children: T("signIn.differentNumber")
1600
+ }) : /* @__PURE__ */ f("button", {
1424
1601
  type: "button",
1425
1602
  className: "cp-link",
1426
- onClick: () => A(O ? "sign-in" : "register"),
1427
- children: w(O ? "register.toSignIn" : "signIn.toRegister")
1603
+ onClick: () => N(j ? "sign-in" : "register"),
1604
+ children: T(j ? "register.toSignIn" : "signIn.toRegister")
1605
+ }),
1606
+ e.onCancel && /* @__PURE__ */ f("button", {
1607
+ type: "button",
1608
+ className: "cp-secondary",
1609
+ onClick: e.onCancel,
1610
+ children: T("signIn.cancel")
1428
1611
  })
1429
1612
  ]
1430
1613
  })
1431
1614
  });
1432
1615
  }
1433
- function Me(e, t, n, r, i) {
1434
- return e === 429 ? n ? w("signIn.error.tooMany", { wait: N(n) }) : w("signIn.error.tooManyLater") : !r && e === 403 && t === "BotCheckFailed" ? w("signIn.error.botCheck") : !r && e === 503 && t === "BotCheckUnavailable" ? w("signIn.error.botCheckUnavailable") : !r && e === 503 && (t === "LimiterUnavailable" || t === "ClientIpUnavailable") ? w("signIn.error.failed") : !r && e === 503 ? n ? w("signIn.error.paused", { wait: N(n) }) : w("signIn.error.pausedLater") : !r && e === 422 && t === "PhoneDestinationNotAllowed" ? w("signIn.error.destination") : r && [
1616
+ function Je(e, t, n, r, i) {
1617
+ return e === 429 ? n ? T("signIn.error.tooMany", { wait: P(n) }) : T("signIn.error.tooManyLater") : !r && e === 403 && t === "BotCheckFailed" ? T("signIn.error.botCheck") : !r && e === 503 && t === "BotCheckUnavailable" ? T("signIn.error.botCheckUnavailable") : !r && e === 503 && (t === "LimiterUnavailable" || t === "ClientIpUnavailable") ? T("signIn.error.failed") : !r && e === 503 ? n ? T("signIn.error.paused", { wait: P(n) }) : T("signIn.error.pausedLater") : !r && e === 422 && t === "PhoneDestinationNotAllowed" ? T("signIn.error.destination") : r && [
1435
1618
  400,
1436
1619
  401,
1437
1620
  403,
1438
1621
  404,
1439
1622
  409
1440
- ].includes(e) ? w(i ? "register.error.badCode" : "signIn.error.badCode") : w(e === 400 ? "signIn.error.invalid" : e === 403 ? "signIn.error.refused" : "signIn.error.failed");
1623
+ ].includes(e) ? T(i ? "register.error.badCode" : "signIn.error.badCode") : T(e === 400 ? "signIn.error.invalid" : e === 403 ? "signIn.error.refused" : "signIn.error.failed");
1441
1624
  }
1442
- // src/index.tsx
1443
- function Ne(e) {
1444
- let n = e.basePath.replace(/\/$/, ""), [i, c] = s(), l = o(!1);
1445
- l.current = !!i;
1446
- let [p, m] = s(), [h, g] = s(/* @__PURE__ */ new Map()), [_, v] = s("loading"), [b, x] = s("businesses"), S = e.screen ?? b, C = e.onNavigate ?? x, [T, E] = s(), D = typeof S == "string" ? S : `${S.businessId}/${S.eventTypeId ?? ""}`, [O, k] = s(D);
1447
- O !== D && (k(D), E(void 0));
1448
- let A = a(() => ie(n, () => {
1449
- l.current && m("app.signedOut"), c(null);
1450
- }), [n]);
1451
- r(() => {
1452
- V(`${n}/auth/session`).then(async (e) => c(e.ok ? (await e.json()).sessionKey : null)).catch(() => c(null));
1453
- }, [n]);
1454
- let j = t(async () => {
1455
- v("loading");
1456
- try {
1457
- let e = /* @__PURE__ */ new Map(), t;
1458
- do {
1459
- let { data: n } = await A.GET("/web/businesses", { params: { query: {
1460
- limit: 100,
1461
- ...t && { cursor: t }
1462
- } } });
1463
- for (let t of n?.items ?? []) e.set(t.id, t);
1464
- t = n?.nextCursor ?? void 0;
1465
- } while (t);
1466
- g(e), v("ready");
1467
- } catch {
1468
- v("failed");
1469
- }
1470
- }, [A]);
1471
- r(() => {
1472
- j();
1473
- }, [j]);
1474
- let M = a(() => ({
1475
- client: A,
1476
- businesses: h,
1477
- businessesStatus: _,
1478
- reloadBusinesses: () => void j(),
1479
- navigate: C,
1480
- signOut: async (e) => {
1481
- await H(n, "/auth/logout").catch(() => {}), m(e), c(null);
1482
- }
1483
- }), [
1484
- A,
1485
- h,
1486
- _,
1487
- j,
1488
- C,
1489
- n
1490
- ]);
1491
- if (i === void 0) return /* @__PURE__ */ d("div", {
1625
+ // src/account.tsx
1626
+ function Ye(e) {
1627
+ let [n, r] = s("bookings"), i = e.screen ?? n, a = e.onNavigate ?? r, o = t((e) => {
1628
+ (e === "bookings" || e === "passes" || e === "details") && a(e);
1629
+ }, [a]), { basePath: c, sessionKey: l, notice: u, portal: d, signedInAs: p } = G({
1630
+ basePath: e.basePath,
1631
+ navigate: o,
1632
+ accountNavigation: !0,
1633
+ onSessionChange: e.onSessionChange
1634
+ });
1635
+ return /* @__PURE__ */ f(K, {
1636
+ portal: d,
1637
+ loading: l === void 0,
1638
+ children: /* @__PURE__ */ f(z, {
1639
+ brand: e.brand,
1640
+ tabs: le,
1641
+ screen: i,
1642
+ signedIn: !!l,
1643
+ signingIn: !l,
1644
+ onNavigate: o,
1645
+ onSignOut: () => d.signOut(),
1646
+ children: l ? f(i === "passes" ? De : i === "details" ? Ee : ee, {}) : /* @__PURE__ */ f(Q, {
1647
+ basePath: c,
1648
+ brand: void 0,
1649
+ botCheck: e.botCheck,
1650
+ notice: u,
1651
+ onSignedIn: p,
1652
+ autoFocus: !0
1653
+ })
1654
+ })
1655
+ });
1656
+ }
1657
+ // src/booking-flow.tsx
1658
+ function Xe(e) {
1659
+ return {
1660
+ startsAt: e.startsAt,
1661
+ eventTypeId: e.eventTypeId,
1662
+ ...e.eventId && { eventId: e.eventId },
1663
+ ...e.resource && { resourceId: e.resource.id }
1664
+ };
1665
+ }
1666
+ function $(e) {
1667
+ return e ? [
1668
+ e.eventId ?? "",
1669
+ e.eventTypeId,
1670
+ Date.parse(e.startsAt),
1671
+ e.resourceId ?? ""
1672
+ ].join("|") : "";
1673
+ }
1674
+ function Ze(e, t) {
1675
+ 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);
1676
+ }
1677
+ function Qe(e) {
1678
+ let n = e.onChange !== void 0, r = {
1679
+ businessId: e.businessId,
1680
+ ...e.eventTypeId && { eventTypeId: e.eventTypeId },
1681
+ ...e.resourceId && { resourceId: e.resourceId },
1682
+ ...e.all && { all: !0 },
1683
+ ...e.time && { time: e.time }
1684
+ }, i = [
1685
+ e.businessId,
1686
+ e.eventTypeId ?? "",
1687
+ e.resourceId ?? "",
1688
+ e.all ? "all" : "",
1689
+ $(e.time)
1690
+ ].join("/"), [a, o] = s(r), [c, l] = s(i);
1691
+ !n && c !== i && (l(i), o(r));
1692
+ let u = n ? r : a, m = e.onChange, h = t((e) => (m ?? o)(e), [m]), g = t((e) => {
1693
+ typeof e == "object" && h({
1694
+ businessId: e.businessId,
1695
+ ...e.eventTypeId && { eventTypeId: e.eventTypeId }
1696
+ });
1697
+ }, [h]), { basePath: _, sessionKey: v, notice: y, portal: b, signedInAs: x } = G({
1698
+ basePath: e.basePath,
1699
+ navigate: g,
1700
+ accountNavigation: !1,
1701
+ onSessionChange: e.onSessionChange
1702
+ }), [S, C] = s(), [w, E] = s(), D = u.time, O = $(D), k = S && D && S.business.id === u.businessId && $(Xe(S.candidate)) === O ? S : void 0, A = () => {
1703
+ C(void 0);
1704
+ let { time: e, ...t } = u;
1705
+ h(t);
1706
+ }, j = (e, t) => {
1707
+ C({
1708
+ business: e,
1709
+ candidate: t
1710
+ }), h({
1711
+ ...u,
1712
+ time: Xe(t)
1713
+ });
1714
+ }, M;
1715
+ M = k ? v ? /* @__PURE__ */ f(ie, {
1716
+ choice: k,
1717
+ onBack: A,
1718
+ onBooked: e.onBooked,
1719
+ onDone: e.onClose
1720
+ }, `${k.candidate.startsAt}-${k.candidate.eventId ?? k.candidate.eventTypeId}`) : /* @__PURE__ */ p(Q, {
1721
+ basePath: _,
1722
+ brand: e.brand,
1723
+ botCheck: e.botCheck,
1724
+ notice: y,
1725
+ onSignedIn: x,
1726
+ autoFocus: !0,
1727
+ children: [
1728
+ /* @__PURE__ */ f("p", { children: T("book.signInFirst") }),
1729
+ /* @__PURE__ */ f(R, { choice: k }),
1730
+ /* @__PURE__ */ f("button", {
1731
+ type: "button",
1732
+ className: "cp-link",
1733
+ onClick: A,
1734
+ children: T("book.back")
1735
+ })
1736
+ ]
1737
+ }) : D && w !== O ? /* @__PURE__ */ f(et, {
1738
+ businessId: u.businessId,
1739
+ time: D,
1740
+ onFound: C,
1741
+ onMissing: () => E(O)
1742
+ }) : u.all ? /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("button", {
1743
+ type: "button",
1744
+ className: "cp-link cp-back",
1745
+ onClick: () => h({ businessId: u.businessId }),
1746
+ children: T("book.toTypes")
1747
+ }), /* @__PURE__ */ f(Se, {
1748
+ businessId: u.businessId,
1749
+ eventTypeId: u.eventTypeId,
1750
+ resourceId: u.resourceId,
1751
+ onFilter: (e) => h({
1752
+ businessId: u.businessId,
1753
+ all: !0,
1754
+ ...e
1755
+ }),
1756
+ onChoose: j
1757
+ })] }) : /* @__PURE__ */ f($e, {
1758
+ selection: u,
1759
+ change: h,
1760
+ onChoose: j
1761
+ });
1762
+ let N = k ? v ? "booking" : "sign-in" : [
1763
+ u.all ? "all" : "",
1764
+ u.eventTypeId ?? "",
1765
+ u.resourceId ?? "",
1766
+ D && w !== O ? "time" : ""
1767
+ ].join("/");
1768
+ return /* @__PURE__ */ f(K, {
1769
+ portal: b,
1770
+ loading: v === void 0,
1771
+ children: /* @__PURE__ */ p(nt, {
1772
+ step: N,
1773
+ children: [
1774
+ e.onClose && /* @__PURE__ */ f("div", {
1775
+ className: "cp-flow-head",
1776
+ children: /* @__PURE__ */ f("button", {
1777
+ type: "button",
1778
+ className: "cp-secondary",
1779
+ onClick: e.onClose,
1780
+ children: T("book.close")
1781
+ })
1782
+ }),
1783
+ D && w === O && /* @__PURE__ */ f("p", {
1784
+ role: "alert",
1785
+ className: "cp-notice",
1786
+ children: T("book.unavailable")
1787
+ }),
1788
+ M
1789
+ ]
1790
+ })
1791
+ });
1792
+ }
1793
+ function $e(e) {
1794
+ let { selection: t, change: n } = e, { businessId: r, eventTypeId: i } = t, a = ye(r), o = be(a, null), { business: s, types: c } = a;
1795
+ if (o || !s || !c) return o;
1796
+ let l = /* @__PURE__ */ p("header", {
1797
+ className: "cp-business-head",
1798
+ children: [/* @__PURE__ */ f("h1", { children: s.displayName }), s.address && /* @__PURE__ */ f("p", {
1799
+ className: "cp-hint",
1800
+ children: s.address
1801
+ })]
1802
+ }), u = /* @__PURE__ */ f("button", {
1803
+ type: "button",
1804
+ className: "cp-link cp-back",
1805
+ onClick: () => n({ businessId: r }),
1806
+ children: T("book.toTypes")
1807
+ }), d = c.find((e) => e.id === i);
1808
+ if (!d) return /* @__PURE__ */ p("section", {
1809
+ className: "cp-screen",
1810
+ children: [
1811
+ l,
1812
+ i && /* @__PURE__ */ f("p", {
1813
+ className: "cp-empty",
1814
+ children: T("business.typeMissing")
1815
+ }),
1816
+ /* @__PURE__ */ f("h2", { children: T("book.chooseType") }),
1817
+ c.length === 0 ? /* @__PURE__ */ f("p", {
1818
+ className: "cp-empty",
1819
+ children: T("book.noTypes")
1820
+ }) : /* @__PURE__ */ f("ul", {
1821
+ className: "cp-list",
1822
+ children: c.map((e) => /* @__PURE__ */ f("li", { children: /* @__PURE__ */ p("button", {
1823
+ type: "button",
1824
+ className: "cp-option",
1825
+ onClick: () => n({
1826
+ businessId: r,
1827
+ eventTypeId: e.id
1828
+ }),
1829
+ children: [
1830
+ /* @__PURE__ */ f("strong", { children: e.displayName }),
1831
+ e.description && /* @__PURE__ */ f("span", { children: e.description }),
1832
+ /* @__PURE__ */ f("span", { children: T("business.minutes", { minutes: e.durationMinutes }) })
1833
+ ]
1834
+ }) }, e.id))
1835
+ }),
1836
+ /* @__PURE__ */ f("button", {
1837
+ type: "button",
1838
+ className: "cp-secondary",
1839
+ onClick: () => n({
1840
+ businessId: r,
1841
+ all: !0
1842
+ }),
1843
+ children: T("book.seeAll")
1844
+ })
1845
+ ]
1846
+ });
1847
+ let m = d.resources.length > 1, h = d.resources.find((e) => e.id === t.resourceId);
1848
+ return m && !h && t.resourceId !== "any" ? /* @__PURE__ */ p("section", {
1849
+ className: "cp-screen",
1850
+ children: [
1851
+ u,
1852
+ l,
1853
+ /* @__PURE__ */ f(J, { type: d }),
1854
+ /* @__PURE__ */ f("h2", { children: T("book.chooseResource") }),
1855
+ /* @__PURE__ */ f("ul", {
1856
+ className: "cp-list",
1857
+ children: [{
1858
+ id: "any",
1859
+ displayName: T("book.anyResource"),
1860
+ description: T("book.anyResourceHint")
1861
+ }, ...d.resources].map((e) => /* @__PURE__ */ f("li", { children: /* @__PURE__ */ p("button", {
1862
+ type: "button",
1863
+ className: "cp-option",
1864
+ onClick: () => n({
1865
+ businessId: r,
1866
+ eventTypeId: d.id,
1867
+ resourceId: e.id
1868
+ }),
1869
+ children: [/* @__PURE__ */ f("strong", { children: e.displayName }), e.description && /* @__PURE__ */ f("span", { children: e.description })]
1870
+ }) }, e.id))
1871
+ })
1872
+ ]
1873
+ }) : /* @__PURE__ */ p("section", {
1874
+ className: "cp-screen",
1875
+ children: [
1876
+ m ? /* @__PURE__ */ f("button", {
1877
+ type: "button",
1878
+ className: "cp-link cp-back",
1879
+ onClick: () => n({
1880
+ businessId: r,
1881
+ eventTypeId: d.id
1882
+ }),
1883
+ children: T("book.otherResource")
1884
+ }) : u,
1885
+ l,
1886
+ /* @__PURE__ */ f(J, { type: d }),
1887
+ m && h && /* @__PURE__ */ f("p", {
1888
+ className: "cp-hint",
1889
+ children: T("business.with", { resource: h.displayName })
1890
+ }),
1891
+ /* @__PURE__ */ f(Ce, {
1892
+ business: s,
1893
+ eventTypeId: d.id,
1894
+ resourceId: m ? h?.id : void 0,
1895
+ onChoose: (t) => e.onChoose(s, t)
1896
+ })
1897
+ ]
1898
+ });
1899
+ }
1900
+ function et(e) {
1901
+ let { client: t } = x(), { businessId: n, time: i } = e, a = o(e);
1902
+ a.current = e;
1903
+ let s = $(i);
1904
+ return r(() => {
1905
+ let e = !0;
1906
+ return (async () => {
1907
+ let { data: r } = await t.GET("/web/businesses/{businessId}", { params: { path: { businessId: n } } });
1908
+ if (!r) throw Error("no business");
1909
+ let o = ve(r.timezone, new Date(i.startsAt)), { data: s } = await t.GET("/web/businesses/{businessId}/availability", { params: {
1910
+ path: { businessId: n },
1911
+ query: {
1912
+ from: `${o}T00:00`,
1913
+ to: `${q(o, 1)}T00:00`,
1914
+ eventTypeId: i.eventTypeId,
1915
+ ...!i.eventId && i.resourceId && { resourceId: i.resourceId }
1916
+ }
1917
+ } }), c = s?.items.find((e) => Ze(e, i));
1918
+ e && (c ? a.current.onFound({
1919
+ business: r,
1920
+ candidate: c
1921
+ }) : a.current.onMissing());
1922
+ })().catch(() => {
1923
+ e && a.current.onMissing();
1924
+ }), () => {
1925
+ e = !1;
1926
+ };
1927
+ }, [
1928
+ t,
1929
+ n,
1930
+ s
1931
+ ]), /* @__PURE__ */ f("section", {
1932
+ className: "cp-screen",
1933
+ children: /* @__PURE__ */ f("p", {
1934
+ role: "status",
1935
+ children: T("app.loading")
1936
+ })
1937
+ });
1938
+ }
1939
+ var tt = "input, .cp-option, .cp-chips button, .cp-candidate button, .cp-actions button:not(:disabled)";
1940
+ function nt(e) {
1941
+ let t = o(null), n = o(!1), { step: i } = e;
1942
+ return r(() => {
1943
+ let e = t.current;
1944
+ if (!e) return;
1945
+ let r = n.current;
1946
+ if (n.current = !0, r && e.contains(document.activeElement)) return;
1947
+ let i = () => {
1948
+ let t = e.querySelector(tt);
1949
+ return t?.focus(), !!t;
1950
+ };
1951
+ if (i()) return;
1952
+ let a = new MutationObserver(() => {
1953
+ i() && a.disconnect();
1954
+ });
1955
+ a.observe(e, {
1956
+ childList: !0,
1957
+ subtree: !0
1958
+ });
1959
+ let o = () => a.disconnect();
1960
+ return e.addEventListener("focusin", o), () => {
1961
+ a.disconnect(), e.removeEventListener("focusin", o);
1962
+ };
1963
+ }, [i]), /* @__PURE__ */ f("div", {
1964
+ ref: t,
1965
+ className: "cp-shell cp-flow",
1966
+ children: e.children
1967
+ });
1968
+ }
1969
+ // src/sign-in-standalone.tsx
1970
+ function rt(e) {
1971
+ let t = e.basePath.replace(/\/$/, ""), n = me(t, e.onSessionChange), i = o(e.onSignedIn);
1972
+ i.current = e.onSignedIn;
1973
+ let a = o(!1);
1974
+ return r(() => {
1975
+ n ? a.current || (a.current = !0, i.current?.()) : a.current = !1;
1976
+ }, [n]), /* @__PURE__ */ f("div", {
1492
1977
  className: "msm-customer",
1493
- children: /* @__PURE__ */ d("p", {
1978
+ children: n === void 0 ? /* @__PURE__ */ f("p", {
1494
1979
  className: "cp-status",
1495
1980
  role: "status",
1496
- children: w("app.loading")
1981
+ children: T("app.loading")
1982
+ }) : n === null && /* @__PURE__ */ f(Q, {
1983
+ basePath: t,
1984
+ brand: e.brand,
1985
+ botCheck: e.botCheck,
1986
+ notice: void 0,
1987
+ onSignedIn: (e) => W(t, e),
1988
+ onCancel: e.onCancel,
1989
+ autoFocus: !0
1497
1990
  })
1498
1991
  });
1499
- let N = (t) => /* @__PURE__ */ d(je, {
1500
- basePath: n,
1992
+ }
1993
+ // src/index.tsx
1994
+ function it(e) {
1995
+ let [t, n] = s("businesses"), r = e.screen ?? t, i = e.onNavigate ?? n, { basePath: a, sessionKey: o, notice: c, portal: l, signedInAs: u } = G({
1996
+ basePath: e.basePath,
1997
+ navigate: i,
1998
+ accountNavigation: !0,
1999
+ onSessionChange: void 0
2000
+ }), [m, h] = s(), g = typeof r == "string" ? r : `${r.businessId}/${r.eventTypeId ?? ""}`, [_, v] = s(g);
2001
+ _ !== g && (v(g), h(void 0));
2002
+ let y = (t) => /* @__PURE__ */ f(Q, {
2003
+ basePath: a,
1501
2004
  brand: void 0,
1502
2005
  botCheck: e.botCheck,
1503
- notice: p,
1504
- onSignedIn: (e) => {
1505
- m(void 0), c(e);
1506
- },
2006
+ notice: c,
2007
+ onSignedIn: u,
1507
2008
  children: t
1508
2009
  });
1509
- return /* @__PURE__ */ d("div", {
1510
- className: "msm-customer",
1511
- children: /* @__PURE__ */ d(y.Provider, {
1512
- value: M,
1513
- children: /* @__PURE__ */ d(oe, {
1514
- brand: e.brand,
1515
- screen: S,
1516
- signedIn: !!i,
1517
- signingIn: !i && (!!T || typeof S == "string" && S !== "businesses"),
1518
- onNavigate: C,
1519
- onSignOut: () => M.signOut(),
1520
- children: T ? i ? /* @__PURE__ */ d(te, {
1521
- choice: T,
1522
- onBack: () => E(void 0)
1523
- }, `${T.candidate.startsAt}-${T.candidate.eventId ?? T.candidate.eventTypeId}`) : N(/* @__PURE__ */ f(u, { children: [
1524
- /* @__PURE__ */ d("p", { children: w("book.signInFirst") }),
1525
- /* @__PURE__ */ d(B, { choice: T }),
1526
- /* @__PURE__ */ d("button", {
1527
- type: "button",
1528
- className: "cp-link",
1529
- onClick: () => E(void 0),
1530
- children: w("book.back")
1531
- })
1532
- ] })) : typeof S == "object" ? /* @__PURE__ */ d(ue, {
1533
- businessId: S.businessId,
1534
- eventTypeId: S.eventTypeId,
1535
- onChoose: (e, t) => E({
1536
- business: e,
1537
- candidate: t
1538
- })
1539
- }) : S === "businesses" ? /* @__PURE__ */ d(pe, {}) : i ? d(S === "passes" ? he : S === "details" ? me : ee, {}) : N()
1540
- })
2010
+ return /* @__PURE__ */ f(K, {
2011
+ portal: l,
2012
+ loading: o === void 0,
2013
+ children: /* @__PURE__ */ f(z, {
2014
+ brand: e.brand,
2015
+ tabs: ue,
2016
+ screen: r,
2017
+ signedIn: !!o,
2018
+ signingIn: !o && (!!m || typeof r == "string" && r !== "businesses"),
2019
+ onNavigate: i,
2020
+ onSignOut: () => l.signOut(),
2021
+ children: m ? o ? /* @__PURE__ */ f(ie, {
2022
+ choice: m,
2023
+ onBack: () => h(void 0)
2024
+ }, `${m.candidate.startsAt}-${m.candidate.eventId ?? m.candidate.eventTypeId}`) : y(/* @__PURE__ */ p(d, { children: [
2025
+ /* @__PURE__ */ f("p", { children: T("book.signInFirst") }),
2026
+ /* @__PURE__ */ f(R, { choice: m }),
2027
+ /* @__PURE__ */ f("button", {
2028
+ type: "button",
2029
+ className: "cp-link",
2030
+ onClick: () => h(void 0),
2031
+ children: T("book.back")
2032
+ })
2033
+ ] })) : typeof r == "object" ? /* @__PURE__ */ f(Se, {
2034
+ businessId: r.businessId,
2035
+ eventTypeId: r.eventTypeId,
2036
+ onChoose: (e, t) => h({
2037
+ business: e,
2038
+ candidate: t
2039
+ })
2040
+ }) : r === "businesses" ? /* @__PURE__ */ f(Te, {}) : o ? f(r === "passes" ? De : r === "details" ? Ee : ee, {}) : y()
1541
2041
  })
1542
2042
  });
1543
2043
  }
1544
- export { Ne as MsmCustomer, P as cancellationState, A as formatDate, O as formatDateTime, D as formatNumber, S as locale, w as t };
2044
+ export { Ye as MsmAccount, Qe as MsmBooking, it as MsmCustomer, rt as MsmSignIn, F as cancellationState, j as formatDate, k as formatDateTime, O as formatNumber, C as locale, T as t };