@loczer/storefront-sdk 0.219.0 → 0.221.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +1,30 @@
1
1
  import { applyBookingParamsToSearch as e, getBookingParamsFromSearch as t, pickBookingSearchParams as n, resolveBookingSearchParamsFromSessionStorage as r, writeBookingSearchParamsToSessionStorage as i } from "../lib/booking.js";
2
2
  import { useStorefrontCart as ee } from "../lib/cart.js";
3
- import { calculateBookingRentalUnitSummary as te, formatRentalUnitQuantity as ne, getPricingUnitLabel as re } from "../lib/pricing.js";
4
- import { buildStorefrontCartSummary as ie } from "../lib/cartSummary.js";
5
- import { ROUTE as ae, responseSchema as oe } from "../lib/checkoutPaymentDecision.js";
6
- import { ROUTE as se, responseSchema as ce } from "../lib/checkoutSubmit.js";
7
- import { ROUTE as le, buildStorefrontAvailabilityKey as ue, getStorefrontAvailabilityIssue as de, getValidStorefrontAvailabilitySchedule as fe, responseSchema as pe } from "../lib/storefrontAvailability.js";
8
- import { Button as me } from "../ui/button.js";
9
- import { useStorefront as he, useStorefrontProducts as ge } from "../StorefrontContext.js";
10
- import { toast as _e } from "../lib/toast.js";
11
- import { apiPost as a } from "../lib/apiCall.js";
12
- import { FulfillmentSection as ve } from "../components/FulfillmentSection/index.js";
13
- import { BookingFlowPageLayout as ye } from "../components/BookingFlowPageLayout/index.js";
14
- import { ROUTE as be, responseSchema as xe } from "../lib/checkoutVerifyCoupon.js";
15
- import { CheckoutDetailsCard as Se } from "./checkout/components/CheckoutDetailsCard.js";
16
- import { CheckoutPaymentSummaryCard as Ce } from "./checkout/components/CheckoutPaymentSummaryCard.js";
17
- import { CheckoutInsuranceCard as we } from "./checkout/components/CheckoutInsuranceCard.js";
18
- import { CheckoutSummaryColumn as Te } from "./checkout/components/CheckoutSummaryColumn.js";
19
- import { checkoutFormSchema as Ee } from "./checkout/types.js";
20
- import { useEffect as o, useMemo as s, useRef as De, useState as c } from "react";
21
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
22
- import { Link as Oe, useNavigate as ke, useParams as Ae, useSearchParams as je } from "@rpcbase/router";
23
- import { useTranslation as Me } from "react-i18next";
24
- import { ArrowLeft as Ne } from "lucide-react";
25
- import { useForm as Pe, zodResolver as Fe } from "@rpcbase/form";
3
+ import { calculateBookingRentalUnitSummary as te, getPricingUnitLabel as ne } from "../lib/pricing.js";
4
+ import { buildStorefrontCartSummary as re } from "../lib/cartSummary.js";
5
+ import { ROUTE as ie, responseSchema as ae } from "../lib/checkoutSubmit.js";
6
+ import { ROUTE as oe, buildStorefrontAvailabilityKey as se, getStorefrontAvailabilityIssue as ce, getValidStorefrontAvailabilitySchedule as le, responseSchema as ue } from "../lib/storefrontAvailability.js";
7
+ import { Button as de } from "../ui/button.js";
8
+ import { useStorefront as fe, useStorefrontProducts as pe } from "../StorefrontContext.js";
9
+ import { toast as a } from "../lib/toast.js";
10
+ import { apiPost as o } from "../lib/apiCall.js";
11
+ import { FulfillmentSection as me } from "../components/FulfillmentSection/index.js";
12
+ import { BookingFlowPageLayout as he } from "../components/BookingFlowPageLayout/index.js";
13
+ import { Spinner as ge } from "../chunks/pkg/ui/dist/Spinner/index-Cgi70z_E.js";
14
+ import { ROUTE as _e, responseSchema as ve } from "../lib/checkoutPaymentDecision.js";
15
+ import { ROUTE as ye, responseSchema as be } from "../lib/checkoutVerifyCoupon.js";
16
+ import { CheckoutDetailsCard as xe } from "./checkout/components/CheckoutDetailsCard.js";
17
+ import { CheckoutInsuranceCard as Se } from "./checkout/components/CheckoutInsuranceCard.js";
18
+ import { CheckoutSummaryColumn as Ce } from "./checkout/components/CheckoutSummaryColumn.js";
19
+ import { checkoutFormSchema as we } from "./checkout/types.js";
20
+ import { useEffect as s, useMemo as c, useRef as Te, useState as l } from "react";
21
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
22
+ import { Link as Ee, useNavigate as De, useParams as Oe, useSearchParams as ke } from "@rpcbase/router";
23
+ import { useTranslation as Ae } from "react-i18next";
24
+ import { AlertTriangle as je, ArrowLeft as Me } from "lucide-react";
25
+ import { useForm as Ne, zodResolver as Pe } from "@rpcbase/form";
26
26
  //#region src/pages/CheckoutPage.tsx
27
- var Ie = .2, d = (e, t, n) => {
27
+ var Fe = .2, f = (e, t, n) => {
28
28
  try {
29
29
  return new Intl.NumberFormat(n, {
30
30
  style: "currency",
@@ -33,7 +33,7 @@ var Ie = .2, d = (e, t, n) => {
33
33
  } catch {
34
34
  return `${(e / 100).toFixed(2)} ${t.toUpperCase()}`;
35
35
  }
36
- }, Le = (e, t) => {
36
+ }, Ie = (e, t) => {
37
37
  try {
38
38
  return new Intl.NumberFormat(t, {
39
39
  style: "percent",
@@ -43,117 +43,105 @@ var Ie = .2, d = (e, t, n) => {
43
43
  } catch {
44
44
  return `${Number.parseFloat((e * 100).toFixed(2))}%`;
45
45
  }
46
- }, Re = (e, t, n) => {
47
- let r = {
48
- dateStyle: "medium",
49
- timeStyle: "short"
50
- };
51
- if (n) try {
52
- return new Intl.DateTimeFormat(t, {
53
- ...r,
54
- timeZone: n
55
- }).format(e);
56
- } catch {}
57
- return new Intl.DateTimeFormat(t, r).format(e);
58
46
  };
59
- function f() {
60
- let { t: f, i18n: p } = Me(), { storefrontConfiguration: m } = he(), ze = m.workspace?.workspaceLanguage, { bikes: h, accessories: Be } = ge(), { storeSlug: g } = Ae(), [_, Ve] = je(), He = ke(), { items: Ue, itemCount: We, setQuantity: Ge, removeItem: Ke, beginCheckoutSubmission: qe, confirmCheckoutPaymentSession: Je, clearCheckoutSession: Ye, clear: Xe } = ee(), [v, Ze] = c(!1), Qe = De(!1), [y, b] = c(null), [$e, et] = c(!1), [tt, x] = c(null), nt = _.get("coupon") ?? _.get("code") ?? "", [rt, it] = c(nt), [at, ot] = c(nt.trim()), [S, C] = c(null), [w, T] = c(null), [E, D] = c(!1), [st, O] = c(null), [ct, k] = c(null), [A, lt] = c(!1), [j, ut] = c(!1), dt = n(_).toString(), ft = s(() => r(new URLSearchParams(dt), g), [dt, g]), M = m.settings.fulfillmentModes.includes("delivery"), pt = m.settings.deliveryDisabledReason.trim(), mt = M || pt.length > 0, ht = m.shop.address?.trim() ?? "", N = s(() => {
61
- let e = t(ft, {
47
+ function p() {
48
+ let { t: p, i18n: m } = Ae(), { storefrontConfiguration: h } = fe(), Le = h.workspace?.workspaceLanguage, { bikes: Re, accessories: ze } = pe(), { storeSlug: g } = Oe(), [_, Be] = ke(), Ve = De(), { items: He, itemCount: Ue, setQuantity: We, removeItem: Ge, beginCheckoutSubmission: Ke, confirmCheckoutPaymentSession: qe, clearCheckoutSession: Je, clear: Ye } = ee(), [v, Xe] = l(!1), y = Te(!1), [b, x] = l(null), [Ze, S] = l(!1), [C, w] = l(null), Qe = _.get("coupon") ?? _.get("code") ?? "", [$e, et] = l(Qe), [tt, nt] = l(Qe.trim()), [T, E] = l(null), [D, O] = l(null), [k, A] = l(!1), [rt, j] = l(null), [it, M] = l(null), [N, at] = l(!1), [P, ot] = l(!1), st = n(_).toString(), ct = c(() => r(new URLSearchParams(st), g), [st, g]), F = h.settings.fulfillmentModes.includes("delivery"), lt = h.settings.deliveryDisabledReason.trim(), ut = F || lt.length > 0, dt = h.shop.address?.trim() ?? "", I = c(() => {
49
+ let e = t(ct, {
62
50
  start_time: "",
63
51
  end_time: ""
64
52
  });
65
- return e.fulfillment === "delivery" && !M ? {
53
+ return e.fulfillment === "delivery" && !F ? {
66
54
  ...e,
67
55
  fulfillment: "pickup"
68
56
  } : e;
69
- }, [ft, M]), P = s(() => fe(N), [N]), F = m.bookingEngine.pricing, I = te(N, F, m.bookingEngine.shop.timeZone), gt = re(F.baseUnit, f), _t = I ? ne(I.billableUnitCount, I.priceUnit, p.language, f) : void 0, vt = I?.billableUnitCount, L = s(() => ie({
70
- items: Ue,
71
- language: p.language,
72
- fallbackLanguage: ze,
57
+ }, [ct, F]), L = c(() => le(I), [I]), R = h.bookingEngine.pricing, ft = te(I, R, h.bookingEngine.shop.timeZone), pt = ne(R.baseUnit, p), mt = ft?.billableUnitCount, z = c(() => re({
58
+ items: He,
59
+ language: m.language,
60
+ fallbackLanguage: Le,
73
61
  products: {
74
- bikes: h,
75
- accessories: Be
62
+ bikes: Re,
63
+ accessories: ze
76
64
  },
77
- priceUnit: F.baseUnit,
78
- billableUnitCount: vt
65
+ priceUnit: R.baseUnit,
66
+ billableUnitCount: mt
79
67
  }), [
80
- Be,
81
- h,
82
- vt,
83
- p.language,
84
- Ue,
85
- F.baseUnit,
86
- ze
87
- ]), R = s(() => L.lines.map((e) => ({
68
+ ze,
69
+ Re,
70
+ mt,
71
+ m.language,
72
+ He,
73
+ R.baseUnit,
74
+ Le
75
+ ]), B = c(() => z.lines.map((e) => ({
88
76
  productId: e.checkoutProductId,
89
77
  productVariantId: e.productVariantId,
90
78
  quantity: e.quantity
91
- })), [L.lines]), [yt, z] = c([]), [bt, B] = c(!1);
92
- o(() => {
93
- if (!g || R.length === 0) {
94
- z([]), B(!1);
79
+ })), [z.lines]), [ht, V] = l([]), [H, U] = l(!1);
80
+ s(() => {
81
+ if (!g || B.length === 0) {
82
+ V([]), U(!1);
95
83
  return;
96
84
  }
97
- if (!P) {
98
- z([]), B(!1);
85
+ if (!L) {
86
+ V([]), U(!1);
99
87
  return;
100
88
  }
101
89
  let e = !1;
102
- return B(!0), z([]), (async () => {
90
+ return U(!0), V([]), (async () => {
103
91
  try {
104
- let t = await a(le, {
92
+ let t = await o(oe, {
105
93
  storeSlug: g,
106
- schedule: P,
107
- products: R
108
- }), n = pe.parse(t);
94
+ schedule: L,
95
+ products: B
96
+ }), n = ue.parse(t);
109
97
  if (e) return;
110
- z(n.success ? n.availability ?? [] : []);
98
+ V(n.success ? n.availability ?? [] : []);
111
99
  } catch (t) {
112
100
  if (e) return;
113
- console.error("Failed to load checkout cart availability", t), z([]);
101
+ console.error("Failed to load checkout cart availability", t), V([]);
114
102
  } finally {
115
- e || B(!1);
103
+ e || U(!1);
116
104
  }
117
105
  })(), () => {
118
106
  e = !0;
119
107
  };
120
108
  }, [
121
- N.end_date,
122
- N.end_time,
123
- N.start_date,
124
- N.start_time,
125
- P,
126
- R,
109
+ I.end_date,
110
+ I.end_time,
111
+ I.start_date,
112
+ I.start_time,
113
+ L,
114
+ B,
127
115
  g
128
116
  ]);
129
- let xt = s(() => new Map(yt.map((e) => [ue(e.productId, e.productVariantId), e])), [yt]), St = s(() => ({
130
- ...L,
131
- lines: L.lines.map((e) => {
132
- let t = xt.get(ue(e.checkoutProductId, e.productVariantId)), n = t ? de(t) : e.availabilityStatus === "OUT_OF_STOCK" ? "unavailable" : void 0;
117
+ let gt = c(() => new Map(ht.map((e) => [se(e.productId, e.productVariantId), e])), [ht]), _t = c(() => ({
118
+ ...z,
119
+ lines: z.lines.map((e) => {
120
+ let t = gt.get(se(e.checkoutProductId, e.productVariantId)), n = t ? ce(t) : e.availabilityStatus === "OUT_OF_STOCK" ? "unavailable" : void 0;
133
121
  return {
134
122
  ...e,
135
- insufficientCapacity: !bt && n !== void 0,
136
- availabilityIssue: bt ? void 0 : n
123
+ insufficientCapacity: !H && n !== void 0,
124
+ availabilityIssue: H ? void 0 : n
137
125
  };
138
126
  })
139
127
  }), [
140
- xt,
141
- bt,
142
- L
143
- ]), V = s(() => L.lines.map((e) => ({
128
+ gt,
129
+ H,
130
+ z
131
+ ]), W = c(() => z.lines.map((e) => ({
144
132
  kind: e.kind,
145
133
  productId: e.checkoutProductId,
146
134
  productVariantId: e.productVariantId,
147
135
  quantity: e.quantity
148
- })), [L.lines]), Ct = new Map(h.map((e) => [e.checkoutProductId?.trim() || e.id, e])), H = L.lines.flatMap((e) => {
149
- let t = Ct.get(e.checkoutProductId);
136
+ })), [z.lines]), vt = new Map(Re.map((e) => [e.checkoutProductId?.trim() || e.id, e])), G = z.lines.flatMap((e) => {
137
+ let t = vt.get(e.checkoutProductId);
150
138
  return t?.insurance?.enabled ? [{
151
139
  quantity: e.quantity,
152
140
  pricePerDayMinor: t.insurance.pricePerDayMinor,
153
141
  deductibleAmountMinor: t.insurance.deductibleAmountMinor
154
142
  }] : [];
155
- }), U = m.modules?.insurance?.enabled === !0 && H.length > 0, W = U && j, wt = H.reduce((e, t) => e + t.pricePerDayMinor * t.quantity, 0), Tt = H.reduce((e, t) => Math.max(e, t.deductibleAmountMinor), 0), Et = L.estimatedTotalMinor ?? L.totalPerBaseUnitMinor, G = w?.totalMinor ?? Et, K = S?.discountAmountMinor ?? 0, q = e(new URLSearchParams(), N).toString(), J = `/${g ?? ""}/booking${q ? `?${q}` : ""}`, Dt = `/${g ?? ""}/checkout${q ? `?${q}` : ""}`, Ot = Pe({
156
- resolver: Fe(Ee),
143
+ }), K = h.modules?.insurance?.enabled === !0 && G.length > 0, q = K && P, yt = G.reduce((e, t) => e + t.pricePerDayMinor * t.quantity, 0), bt = G.reduce((e, t) => Math.max(e, t.deductibleAmountMinor), 0), xt = z.estimatedTotalMinor ?? z.totalPerBaseUnitMinor, J = D?.totalMinor ?? xt, St = T?.discountAmountMinor ?? 0, Y = e(new URLSearchParams(), I).toString(), X = `/${g ?? ""}/booking${Y ? `?${Y}` : ""}`, Ct = `/${g ?? ""}/checkout${Y ? `?${Y}` : ""}`, wt = Ne({
144
+ resolver: Pe(we),
157
145
  defaultValues: {
158
146
  first_name: "",
159
147
  last_name: "",
@@ -162,139 +150,122 @@ function f() {
162
150
  notes: ""
163
151
  }
164
152
  });
165
- o(() => {
166
- i(g, N);
167
- }, [N, g]), o(() => {
168
- !U && j && ut(!1);
169
- }, [j, U]);
170
- let Y = (t) => {
153
+ s(() => {
154
+ i(g, I);
155
+ }, [I, g]), s(() => {
156
+ !K && P && ot(!1);
157
+ }, [P, K]);
158
+ let Z = (t) => {
171
159
  let n = {
172
- ...N,
160
+ ...I,
173
161
  ...t
174
162
  }, r = e(_, n);
175
- r.toString() !== _.toString() && (Ve(r, { replace: !0 }), i(g, r));
163
+ r.toString() !== _.toString() && (Be(r, { replace: !0 }), i(g, r));
176
164
  };
177
- o(() => {
178
- if (!g || V.length === 0 || !P) {
179
- C(null), T(null), D(!1), O(null), k(null);
165
+ s(() => {
166
+ if (!g || W.length === 0 || !L) {
167
+ E(null), O(null), A(!1), j(null), M(null);
180
168
  return;
181
169
  }
182
- let e = at.trim(), t = e.length === 0 && !A, n = !1;
183
- return D(!0), k(null), O(null), (async () => {
170
+ let e = tt.trim(), t = e.length === 0 && !N, n = !1;
171
+ return A(!0), M(null), j(null), (async () => {
184
172
  try {
185
- let r = await a(be, {
173
+ let r = await o(ye, {
186
174
  storeSlug: g,
187
- schedule: P,
188
- items: V,
175
+ schedule: L,
176
+ items: W,
189
177
  couponCode: e || void 0,
190
178
  includeAutoApply: t,
191
- insuranceAccepted: W
192
- }), i = xe.parse(r);
179
+ insuranceAccepted: q
180
+ }), i = be.parse(r);
193
181
  if (n) return;
194
- if (T(typeof i.subtotalMinor == "number" && typeof i.totalMinor == "number" ? {
182
+ if (O(typeof i.subtotalMinor == "number" && typeof i.totalMinor == "number" ? {
195
183
  subtotalMinor: i.subtotalMinor,
196
184
  totalMinor: i.totalMinor,
197
185
  lateReturnSurchargeMinor: i.lateReturnSurchargeMinor,
198
186
  insuranceSubtotalMinor: i.insuranceSubtotalMinor,
199
187
  insuranceBillableDays: i.insuranceBillableDays
200
188
  } : null), !i.success) {
201
- C(null), k(i.message || f("checkout_coupon_invalid"));
189
+ E(null), M(i.message || p("checkout_coupon_invalid"));
202
190
  return;
203
191
  }
204
- C(i.coupon ?? null), i.coupon && (i.coupon.autoApplied && e.length === 0 ? (it(i.coupon.code), O(f("checkout_coupon_auto_applied", { code: i.coupon.code }))) : O(f("checkout_coupon_manual_applied")));
192
+ E(i.coupon ?? null), i.coupon && (i.coupon.autoApplied && e.length === 0 ? (et(i.coupon.code), j(p("checkout_coupon_auto_applied", { code: i.coupon.code }))) : j(p("checkout_coupon_manual_applied")));
205
193
  } catch (e) {
206
194
  if (n) return;
207
- console.error("Failed to verify checkout coupon", e), C(null), T(null), k(f("checkout_coupon_error"));
195
+ console.error("Failed to verify checkout coupon", e), E(null), O(null), M(p("checkout_coupon_error"));
208
196
  } finally {
209
- n || D(!1);
197
+ n || A(!1);
210
198
  }
211
199
  })(), () => {
212
200
  n = !0;
213
201
  };
214
202
  }, [
215
- A,
216
- N.end_date,
217
- N.end_time,
218
- N.start_date,
219
- N.start_time,
220
- P,
221
- V,
203
+ N,
204
+ I.end_date,
205
+ I.end_time,
206
+ I.start_date,
207
+ I.start_time,
208
+ L,
222
209
  W,
210
+ q,
223
211
  g,
224
- at,
225
- f
226
- ]), o(() => {
227
- if (!g || L.lines.length === 0 || !P) {
228
- b(null), x(null), et(!1);
212
+ tt,
213
+ p
214
+ ]), s(() => {
215
+ if (!g || z.lines.length === 0 || !L) {
216
+ x(null), w(null), S(!1);
229
217
  return;
230
218
  }
231
219
  let e = !1;
232
- return et(!0), x(null), (async () => {
220
+ return S(!0), w(null), (async () => {
233
221
  try {
234
- let t = await a(ae, {
222
+ let t = await o(_e, {
235
223
  storeSlug: g,
236
- schedule: P,
237
- estimatedTotalMinor: G
238
- }), n = oe.parse(t);
224
+ schedule: L,
225
+ estimatedTotalMinor: J
226
+ }), n = ve.parse(t);
239
227
  if (e) return;
240
228
  if (!n.success || !n.decision) {
241
- b(null), x(n.errorCode === "online_payment_provider_missing" ? f("checkout_payment_error") : n.message || f("checkout_payment_error"));
229
+ x(null), w(n.message || p("checkout_payment_error"));
242
230
  return;
243
231
  }
244
- b(n.decision);
232
+ x(n.decision);
245
233
  } catch (t) {
246
234
  if (e) return;
247
- console.error("Failed to load checkout payment decision", t), b(null), x(f("checkout_payment_error"));
235
+ console.error("Failed to load checkout payment decision", t), x(null), w(p("checkout_payment_error"));
248
236
  } finally {
249
- e || et(!1);
237
+ e || S(!1);
250
238
  }
251
239
  })(), () => {
252
240
  e = !0;
253
241
  };
254
242
  }, [
255
- N.end_date,
256
- N.end_time,
257
- N.start_date,
258
- N.start_time,
259
- P,
260
- G,
261
- L.lines.length,
243
+ I.end_date,
244
+ I.end_time,
245
+ I.start_date,
246
+ I.start_time,
247
+ L,
248
+ J,
249
+ z.lines.length,
262
250
  g,
263
- f
251
+ p
264
252
  ]);
265
- let X = y?.currency ?? "EUR", kt = d(G, X, p.language), At = K > 0 ? `-${d(K, X, p.language)}` : null, Z = w?.insuranceSubtotalMinor ?? 0, jt = Math.max(0, G - Z), Mt = Math.round(jt / 1.2), Nt = Mt + Z, Pt = Math.max(0, jt - Mt), Ft = d(Nt, X, p.language), It = d(Pt, X, p.language), Lt = Le(Ie, p.language), Rt = Z > 0 ? d(Z, X, p.language) : void 0, Q = y?.amountToCollectMinor ?? 0, zt = d(Q, X, p.language), Bt = y?.paymentMode === "deposit" && Q > 0 ? d(Q, X, p.language) : null, Vt = y?.shouldCollectOnlinePayment === !0 && Q > 0, Ht = m.shop.timeZone?.trim() || void 0, $ = s(() => y ? Le(Math.max(0, Math.min(1, y.bookingDepositPercentage)), p.language) : null, [p.language, y]), Ut = s(() => {
266
- if (!y?.depositRefundableUntilIso) return null;
267
- let e = new Date(y.depositRefundableUntilIso);
268
- return Number.isNaN(e.getTime()) ? null : Re(e, p.language, Ht);
269
- }, [
270
- p.language,
271
- y?.depositRefundableUntilIso,
272
- Ht
273
- ]), Wt = s(() => y ? y.paymentMode === "deposit" && Q > 0 && $ ? Ut ? f("checkout_payment_due_now_helper_deposit_refundable_until", {
274
- percent: $,
275
- date: Ut
276
- }) : f("checkout_payment_due_now_helper_deposit", { percent: $ }) : y.paymentMode === "none" || Q <= 0 ? f("checkout_payment_due_now_helper_none") : null : null, [
277
- Q,
278
- $,
279
- Ut,
280
- y,
281
- f
282
- ]), Gt = Ot.handleSubmit(async (e) => {
283
- if (!g || V.length === 0 || !P || Qe.current) return;
284
- Ze(!0), Qe.current = !0;
285
- let t = qe();
253
+ let Q = b?.currency ?? "EUR", Tt = f(J, Q, m.language), $ = D?.insuranceSubtotalMinor ?? 0, Et = Math.max(0, J - $), Dt = Math.round(Et / 1.2), Ot = Dt + $, kt = Math.max(0, Et - Dt), At = f(Ot, Q, m.language), jt = f(kt, Q, m.language), Mt = Ie(Fe, m.language), Nt = $ > 0 ? f($, Q, m.language) : void 0, Pt = b?.amountToCollectMinor ?? 0, Ft = b?.shouldCollectOnlinePayment === !0 && Pt > 0, It = wt.handleSubmit(async (e) => {
254
+ if (!g || W.length === 0 || !L || y.current) return;
255
+ Xe(!0), y.current = !0;
256
+ let t = Ke();
286
257
  try {
287
- let n = await a(se, {
258
+ let n = await o(ie, {
288
259
  storeSlug: g,
289
260
  checkoutSessionId: t.checkoutSessionId,
290
261
  replacesCheckoutSessionId: t.replacesCheckoutSessionId,
291
- schedule: P,
292
- fulfillment: N.fulfillment,
293
- startAddress: N.fulfillment === "delivery" ? N.start_address : void 0,
294
- endAddress: N.fulfillment === "delivery" ? N.end_address : void 0,
295
- couponCode: S?.code,
296
- couponAutoApplied: !A && S?.autoApplied,
297
- insuranceAccepted: W,
262
+ schedule: L,
263
+ fulfillment: I.fulfillment,
264
+ startAddress: I.fulfillment === "delivery" ? I.start_address : void 0,
265
+ endAddress: I.fulfillment === "delivery" ? I.end_address : void 0,
266
+ couponCode: T?.code,
267
+ couponAutoApplied: !N && T?.autoApplied,
268
+ insuranceAccepted: q,
298
269
  customer: {
299
270
  firstName: e.first_name,
300
271
  lastName: e.last_name,
@@ -302,162 +273,156 @@ function f() {
302
273
  phone: e.phone,
303
274
  notes: e.notes
304
275
  },
305
- items: V
306
- }), r = ce.parse(n);
276
+ items: W
277
+ }), r = ae.parse(n);
307
278
  if (!r.success || !r.checkout) {
308
- Ye(), _e.error(r.errorCode === "online_payment_provider_missing" ? f("checkout_payment_error") : r.message || f("checkout_payment_error"));
279
+ Je(), a.error(r.message || p("checkout_payment_error"));
309
280
  return;
310
281
  }
311
- r.checkout.requiresPayment ? Je(r.checkout.checkoutSessionId ?? t.checkoutSessionId) : _e.success(f("checkout_success_toast")), await He(r.checkout.nextPath), r.checkout.requiresPayment || Xe();
282
+ r.checkout.requiresPayment ? qe(r.checkout.checkoutSessionId ?? t.checkoutSessionId) : a.success(p("checkout_success_toast")), await Ve(r.checkout.nextPath), r.checkout.requiresPayment || Ye();
312
283
  } catch (e) {
313
- console.error("Failed to submit storefront checkout", e), _e.error(f("checkout_payment_error"));
284
+ console.error("Failed to submit storefront checkout", e), a.error(p("checkout_payment_error"));
314
285
  } finally {
315
- Qe.current = !1, Ze(!1);
286
+ y.current = !1, Xe(!1);
316
287
  }
317
- }), Kt = f(Vt ? "checkout_continue_to_payment" : "checkout_submit"), qt = N.fulfillment === "delivery" && N.start_address.trim().length === 0, Jt = !v && !$e && !tt && !E && !ct && !!y && !!P && !qt && V.length > 0;
318
- return L.lines.length === 0 ? /* @__PURE__ */ l("div", {
288
+ }), Lt = p(Ft ? "checkout_continue_to_payment" : "checkout_submit"), Rt = I.fulfillment === "delivery" && I.start_address.trim().length === 0, zt = !v && !Ze && !C && !k && !it && !!b && !!L && !Rt && W.length > 0;
289
+ return z.lines.length === 0 ? /* @__PURE__ */ u("div", {
319
290
  className: "mx-auto max-w-3xl px-4 py-10 sm:px-6",
320
- children: /* @__PURE__ */ u("div", {
291
+ children: /* @__PURE__ */ d("div", {
321
292
  className: "rounded-xl border border-slate-200 bg-white p-4 shadow-sm",
322
293
  children: [
323
- /* @__PURE__ */ l("h1", {
294
+ /* @__PURE__ */ u("h1", {
324
295
  className: "text-xl font-semibold tracking-tight text-slate-950",
325
- children: /* @__PURE__ */ l("span", { children: f("cart_empty_title") })
296
+ children: /* @__PURE__ */ u("span", { children: p("cart_empty_title") })
326
297
  }),
327
- /* @__PURE__ */ l("p", {
298
+ /* @__PURE__ */ u("p", {
328
299
  className: "mt-2 text-sm text-slate-600",
329
- children: /* @__PURE__ */ l("span", { children: f("cart_empty_description") })
300
+ children: /* @__PURE__ */ u("span", { children: p("cart_empty_description") })
330
301
  }),
331
- /* @__PURE__ */ l("div", {
302
+ /* @__PURE__ */ u("div", {
332
303
  className: "mt-6",
333
- children: /* @__PURE__ */ l(Oe, {
334
- to: J,
335
- children: /* @__PURE__ */ u(me, {
304
+ children: /* @__PURE__ */ u(Ee, {
305
+ to: X,
306
+ children: /* @__PURE__ */ d(de, {
336
307
  className: "gap-2",
337
- children: [/* @__PURE__ */ l(Ne, {
308
+ children: [/* @__PURE__ */ u(Me, {
338
309
  className: "h-4 w-4",
339
310
  "aria-hidden": "true"
340
- }), /* @__PURE__ */ l("span", { children: f("back_to_booking") })]
311
+ }), /* @__PURE__ */ u("span", { children: p("back_to_booking") })]
341
312
  })
342
313
  })
343
314
  })
344
315
  ]
345
316
  })
346
- }) : /* @__PURE__ */ l(ye, {
317
+ }) : /* @__PURE__ */ u(he, {
347
318
  currentStep: "checkout",
348
- bookingPath: J,
349
- checkoutPath: Dt,
350
- backPath: J,
351
- backLabel: f("back_to_booking"),
352
- children: /* @__PURE__ */ u("div", {
319
+ bookingPath: X,
320
+ checkoutPath: Ct,
321
+ backPath: X,
322
+ backLabel: p("back_to_booking"),
323
+ children: /* @__PURE__ */ d("div", {
353
324
  className: "grid gap-6 lg:grid-cols-12",
354
- children: [/* @__PURE__ */ u("div", {
325
+ children: [/* @__PURE__ */ d("div", {
355
326
  className: "lg:col-span-7",
356
327
  children: [
357
- /* @__PURE__ */ l("h1", {
328
+ /* @__PURE__ */ u("h1", {
358
329
  className: "text-xl font-semibold tracking-tight text-slate-950",
359
- children: /* @__PURE__ */ l("span", { children: f("checkout_title") })
330
+ children: /* @__PURE__ */ u("span", { children: p("checkout_title") })
360
331
  }),
361
- P ? null : /* @__PURE__ */ l("p", {
332
+ L ? null : /* @__PURE__ */ u("p", {
362
333
  role: "alert",
363
334
  className: "mt-3 text-sm text-destructive",
364
- children: /* @__PURE__ */ l("span", { children: f("booking_time_slots_required") })
335
+ children: /* @__PURE__ */ u("span", { children: p("booking_time_slots_required") })
365
336
  }),
366
- /* @__PURE__ */ u("div", {
337
+ /* @__PURE__ */ d("div", {
367
338
  className: "mt-5 grid gap-4",
368
339
  children: [
369
- mt ? /* @__PURE__ */ l("div", {
340
+ ut ? /* @__PURE__ */ u("div", {
370
341
  className: "rounded-xl border border-slate-200 bg-white p-3 shadow-sm",
371
- children: /* @__PURE__ */ l(ve, {
372
- value: N.fulfillment,
373
- onValueChange: (e) => Y({ fulfillment: e }),
374
- pickupAddress: ht,
375
- deliveryEnabled: M,
376
- deliveryDisabledReason: pt,
377
- startAddress: N.start_address,
378
- onStartAddressChange: (e) => Y({ start_address: e }),
379
- endAddress: N.end_address,
380
- onEndAddressChange: (e) => Y({ end_address: e }),
342
+ children: /* @__PURE__ */ u(me, {
343
+ value: I.fulfillment,
344
+ onValueChange: (e) => Z({ fulfillment: e }),
345
+ pickupAddress: dt,
346
+ deliveryEnabled: F,
347
+ deliveryDisabledReason: lt,
348
+ startAddress: I.start_address,
349
+ onStartAddressChange: (e) => Z({ start_address: e }),
350
+ endAddress: I.end_address,
351
+ onEndAddressChange: (e) => Z({ end_address: e }),
381
352
  showPickupAddressWhenPickupOnly: !1,
382
353
  testIdPrefix: "storefront-checkout-fulfillment"
383
354
  })
384
355
  }) : null,
385
- /* @__PURE__ */ l(Se, { form: Ot }),
386
- U ? /* @__PURE__ */ l(we, {
387
- accepted: W,
388
- disabled: v || E,
389
- dailyAmountLabel: d(wt, X, p.language),
390
- totalAmountLabel: Rt,
391
- billableDays: w?.insuranceBillableDays,
392
- deductibleLabel: Tt > 0 ? d(Tt, X, p.language) : void 0,
393
- onAcceptedChange: ut
356
+ /* @__PURE__ */ u(xe, { form: wt }),
357
+ K ? /* @__PURE__ */ u(Se, {
358
+ accepted: q,
359
+ disabled: v || k,
360
+ dailyAmountLabel: f(yt, Q, m.language),
361
+ totalAmountLabel: Nt,
362
+ billableDays: D?.insuranceBillableDays,
363
+ deductibleLabel: bt > 0 ? f(bt, Q, m.language) : void 0,
364
+ onAcceptedChange: ot
394
365
  }) : null,
395
- /* @__PURE__ */ l(Ce, {
396
- estimatedTotalLabel: kt,
397
- couponCode: S?.code,
398
- discountAmountLabel: At,
399
- totalExcludingTaxLabel: Ft,
400
- vatAmountLabel: It,
401
- vatRateLabel: Lt,
402
- insuranceAmountLabel: Rt,
403
- depositAmountLabel: Bt,
404
- amountToCollectMinor: Q,
405
- amountToCollectLabel: zt,
406
- paymentSummaryHelper: Wt,
407
- paymentDecisionLoading: $e,
408
- paymentDecisionError: tt,
409
- canChoosePaymentMethod: !1,
410
- showAmountDueNowRow: !0,
411
- selectedPaymentMethod: "card",
412
- submitting: v,
413
- onSelectPaymentMethod: () => {}
414
- }),
415
- /* @__PURE__ */ l(me, {
366
+ Ze ? /* @__PURE__ */ d("div", {
367
+ className: "flex items-center gap-2 text-sm text-slate-600",
368
+ role: "status",
369
+ children: [/* @__PURE__ */ u(ge, {
370
+ className: "size-4",
371
+ "aria-hidden": "true"
372
+ }), /* @__PURE__ */ u("span", { children: p("checkout_payment_loading") })]
373
+ }) : null,
374
+ C ? /* @__PURE__ */ d("div", {
375
+ className: "flex items-start gap-2 rounded-md bg-destructive p-3 text-sm text-destructive-foreground shadow-sm",
376
+ role: "alert",
377
+ children: [/* @__PURE__ */ u(je, {
378
+ className: "mt-0.5 h-4 w-4",
379
+ "aria-hidden": "true"
380
+ }), /* @__PURE__ */ u("span", { children: C })]
381
+ }) : null,
382
+ /* @__PURE__ */ u(de, {
416
383
  type: "button",
417
384
  size: "lg",
418
385
  onClick: () => {
419
- Gt();
386
+ It();
420
387
  },
421
- disabled: !Jt,
388
+ disabled: !zt,
422
389
  className: "mt-4 w-fit",
423
- children: /* @__PURE__ */ l("span", { children: Kt })
390
+ children: /* @__PURE__ */ u("span", { children: Lt })
424
391
  }),
425
- qt ? /* @__PURE__ */ l("p", {
392
+ Rt ? /* @__PURE__ */ u("p", {
426
393
  className: "text-sm text-slate-600",
427
- children: /* @__PURE__ */ l("span", { children: f("checkout_delivery_address_required") })
394
+ children: /* @__PURE__ */ u("span", { children: p("checkout_delivery_address_required") })
428
395
  }) : null
429
396
  ]
430
397
  })
431
398
  ]
432
- }), /* @__PURE__ */ l(Te, {
433
- lines: St.lines,
434
- itemCount: We,
435
- totalPerBaseUnitMinor: St.totalPerBaseUnitMinor,
436
- baseUnitLabel: gt,
437
- estimatedTotalMinor: St.estimatedTotalMinor,
438
- discountedEstimatedTotalMinor: G,
439
- discountAmountMinor: K,
440
- lateReturnSurchargeMinor: w?.lateReturnSurchargeMinor,
441
- couponCode: S?.code,
442
- durationInBaseUnitLabel: _t,
443
- onQuantityChange: Ge,
444
- onRemove: Ke,
399
+ }), /* @__PURE__ */ u(Ce, {
400
+ lines: _t.lines,
401
+ itemCount: Ue,
402
+ totalPerBaseUnitMinor: _t.totalPerBaseUnitMinor,
403
+ baseUnitLabel: pt,
404
+ bookingSubtotalLabel: At,
405
+ vatAmountLabel: jt,
406
+ vatRateLabel: Mt,
407
+ bookingTotalLabel: Tt,
408
+ onQuantityChange: We,
409
+ onRemove: Ge,
445
410
  coupon: {
446
- code: rt,
447
- appliedCode: S?.code,
448
- discountLabel: S && K > 0 ? d(K, X, p.language) : null,
449
- message: st,
450
- error: ct,
451
- loading: E,
411
+ code: $e,
412
+ appliedCode: T?.code,
413
+ discountLabel: T && St > 0 ? f(St, Q, m.language) : null,
414
+ message: rt,
415
+ error: it,
416
+ loading: k,
452
417
  disabled: v,
453
418
  onCodeChange: (e) => {
454
- it(e), k(null), O(null);
419
+ et(e), M(null), j(null);
455
420
  },
456
421
  onApply: () => {
457
- lt(!1), ot(rt.trim());
422
+ at(!1), nt($e.trim());
458
423
  },
459
424
  onRemove: () => {
460
- it(""), ot(""), C(null), T(null), k(null), O(null), lt(!0);
425
+ et(""), nt(""), E(null), O(null), M(null), j(null), at(!0);
461
426
  }
462
427
  }
463
428
  })]
@@ -465,4 +430,4 @@ function f() {
465
430
  });
466
431
  }
467
432
  //#endregion
468
- export { f as default };
433
+ export { p as default };