@drawbridge/components 0.1.46 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/bridge/cart-drawer.js +152 -0
  2. package/dist/bridge/cart-drawer.mjs +123 -0
  3. package/dist/bridge/fields.js +278 -0
  4. package/dist/bridge/fields.mjs +276 -1
  5. package/dist/bridge/form-subdomain-checkout.js +687 -0
  6. package/dist/bridge/form-subdomain-checkout.mjs +665 -0
  7. package/dist/bridge/form-subdomain-shop-modal.js +234 -274
  8. package/dist/bridge/form-subdomain-shop-modal.mjs +233 -275
  9. package/dist/bridge/form-subdomain-shop.js +4 -1
  10. package/dist/bridge/form-subdomain-shop.mjs +4 -1
  11. package/dist/bridge/form-subdomain.js +24 -5
  12. package/dist/bridge/form-subdomain.mjs +25 -6
  13. package/dist/bridge/lib/age-gate.js +12 -0
  14. package/dist/bridge/lib/age-gate.mjs +11 -0
  15. package/dist/bridge/lib/cart.js +79 -0
  16. package/dist/bridge/lib/cart.mjs +48 -0
  17. package/dist/bridge/lib/checkout-kit.js +2 -32
  18. package/dist/bridge/lib/checkout-kit.mjs +2 -32
  19. package/dist/bridge/lib/entry.js +41 -0
  20. package/dist/bridge/lib/entry.mjs +40 -0
  21. package/dist/bridge/product-tile.js +13 -6
  22. package/dist/bridge/product-tile.mjs +13 -6
  23. package/dist/bridge/template-layout.js +263 -129
  24. package/dist/bridge/template-layout.mjs +264 -130
  25. package/dist/bridge/template-modal.js +39 -74
  26. package/dist/bridge/template-modal.mjs +40 -75
  27. package/dist/dashboard/avatar.js +2 -3
  28. package/dist/dashboard/avatar.mjs +2 -3
  29. package/dist/dashboard/buttons-subscription.js +1 -1
  30. package/dist/dashboard/buttons-subscription.mjs +1 -1
  31. package/dist/dashboard/campaign-form.js +179 -155
  32. package/dist/dashboard/campaign-form.mjs +179 -155
  33. package/dist/dashboard/campaign-share.js +347 -0
  34. package/dist/dashboard/campaign-share.mjs +314 -0
  35. package/dist/dashboard/card-affiliate.js +1 -1
  36. package/dist/dashboard/card-affiliate.mjs +1 -1
  37. package/dist/dashboard/card-campaign-switch.js +4 -1
  38. package/dist/dashboard/card-campaign-switch.mjs +4 -1
  39. package/dist/dashboard/card-order.js +22 -4
  40. package/dist/dashboard/card-order.mjs +22 -4
  41. package/dist/dashboard/embed-stripe.js +145 -0
  42. package/dist/dashboard/embed-stripe.mjs +116 -0
  43. package/dist/dashboard/form-admin-provider.js +71 -17
  44. package/dist/dashboard/form-admin-provider.mjs +71 -17
  45. package/dist/dashboard/form-file-upload.js +3 -2
  46. package/dist/dashboard/form-file-upload.mjs +4 -3
  47. package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
  48. package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
  49. package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
  50. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
  51. package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
  52. package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
  53. package/dist/dashboard/form-organization-campaign-page.js +73 -39
  54. package/dist/dashboard/form-organization-campaign-page.mjs +73 -39
  55. package/dist/dashboard/form-organization-campaign.js +82 -0
  56. package/dist/dashboard/form-organization-campaign.mjs +81 -0
  57. package/dist/dashboard/form-organization-connection.js +48 -6
  58. package/dist/dashboard/form-organization-connection.mjs +48 -7
  59. package/dist/dashboard/form-organization-product.js +1461 -0
  60. package/dist/dashboard/form-organization-product.mjs +1425 -0
  61. package/dist/dashboard/form-organization-workflow.js +72 -1
  62. package/dist/dashboard/form-organization-workflow.mjs +69 -1
  63. package/dist/dashboard/form-otc.js +4 -5
  64. package/dist/dashboard/form-otc.mjs +4 -5
  65. package/dist/dashboard/form-stripe.js +12 -5
  66. package/dist/dashboard/form-stripe.mjs +12 -5
  67. package/dist/dashboard/input-combobox.js +6 -0
  68. package/dist/dashboard/input-combobox.mjs +6 -0
  69. package/dist/dashboard/input-fields.js +37 -161
  70. package/dist/dashboard/input-fields.mjs +37 -161
  71. package/dist/dashboard/input-file.js +21 -4
  72. package/dist/dashboard/input-file.mjs +21 -4
  73. package/dist/dashboard/input-font.js +2 -0
  74. package/dist/dashboard/input-font.mjs +2 -0
  75. package/dist/dashboard/input-gallery.js +201 -0
  76. package/dist/dashboard/input-gallery.mjs +172 -0
  77. package/dist/dashboard/input-group-ai.js +15 -3
  78. package/dist/dashboard/input-group-ai.mjs +15 -3
  79. package/dist/dashboard/lib/ab-tests.js +2 -2
  80. package/dist/dashboard/lib/ab-tests.mjs +2 -2
  81. package/dist/dashboard/lib/connection-controls.js +5 -2
  82. package/dist/dashboard/lib/connection-controls.mjs +3 -1
  83. package/dist/dashboard/lib/form-page.js +1 -1
  84. package/dist/dashboard/lib/form-page.mjs +1 -1
  85. package/dist/dashboard/lib/menu.js +19 -0
  86. package/dist/dashboard/lib/menu.mjs +18 -0
  87. package/dist/dashboard/lib/products.js +169 -0
  88. package/dist/dashboard/lib/products.mjs +135 -0
  89. package/dist/dashboard/lib/settings-paths.js +35 -0
  90. package/dist/dashboard/lib/settings-paths.mjs +11 -0
  91. package/dist/dashboard/lib/uppy.js +10 -1
  92. package/dist/dashboard/lib/uppy.mjs +11 -2
  93. package/dist/dashboard/menu.js +13 -2
  94. package/dist/dashboard/menu.mjs +13 -2
  95. package/dist/dashboard/order-sections.js +456 -6
  96. package/dist/dashboard/order-sections.mjs +453 -7
  97. package/dist/dashboard/preview.js +119 -52
  98. package/dist/dashboard/preview.mjs +119 -52
  99. package/dist/dashboard/provider-ui.js +9 -7
  100. package/dist/dashboard/provider-ui.mjs +9 -7
  101. package/dist/dashboard/recharts.js +10 -4
  102. package/dist/dashboard/recharts.mjs +10 -4
  103. package/dist/dashboard/shipping-rates.js +404 -0
  104. package/dist/dashboard/shipping-rates.mjs +371 -0
  105. package/dist/dashboard/template-buyer.js +301 -0
  106. package/dist/dashboard/template-buyer.mjs +267 -0
  107. package/dist/dashboard/template-dashboard.js +11 -1
  108. package/dist/dashboard/template-dashboard.mjs +11 -1
  109. package/dist/dashboard/template-design.js +209 -130
  110. package/dist/dashboard/template-design.mjs +210 -131
  111. package/dist/dashboard/template-ui.js +157 -55
  112. package/dist/dashboard/template-ui.mjs +158 -56
  113. package/dist/icons/flags.js +134 -0
  114. package/dist/icons/flags.mjs +115 -0
  115. package/dist/input-checkbox.js +28 -10
  116. package/dist/input-checkbox.mjs +28 -10
  117. package/dist/product.js +96 -24
  118. package/dist/product.mjs +97 -25
  119. package/dist/shared/carousel.js +14 -5
  120. package/dist/shared/carousel.mjs +14 -5
  121. package/dist/shared/lib/helpers.js +54 -6
  122. package/dist/shared/lib/helpers.mjs +53 -8
  123. package/dist/shared/order-summary.js +139 -0
  124. package/dist/shared/order-summary.mjs +110 -0
  125. package/package.json +84 -4
  126. package/types/bridge/cart-drawer.d.ts +31 -0
  127. package/types/bridge/fields.d.ts +14 -2
  128. package/types/bridge/form-subdomain-checkout.d.ts +20 -0
  129. package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
  130. package/types/bridge/form-subdomain.d.ts +13 -0
  131. package/types/bridge/lib/age-gate.d.ts +5 -0
  132. package/types/bridge/lib/cart.d.ts +44 -0
  133. package/types/bridge/lib/checkout-kit.d.ts +2 -10
  134. package/types/bridge/lib/entry.d.ts +5 -0
  135. package/types/bridge/product-tile.d.ts +2 -0
  136. package/types/dashboard/campaign-share.d.ts +16 -0
  137. package/types/dashboard/card-order.d.ts +6 -0
  138. package/types/dashboard/embed-stripe.d.ts +25 -0
  139. package/types/dashboard/form-admin-provider.d.ts +9 -2
  140. package/types/dashboard/form-file-upload.d.ts +2 -1
  141. package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
  142. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
  143. package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
  144. package/types/dashboard/form-organization-campaign-page.d.ts +8 -1
  145. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  146. package/types/dashboard/form-organization-connection.d.ts +11 -0
  147. package/types/dashboard/form-organization-product.d.ts +24 -0
  148. package/types/dashboard/form-otc.d.ts +5 -1
  149. package/types/dashboard/form-stripe.d.ts +3 -2
  150. package/types/dashboard/input-combobox.d.ts +2 -0
  151. package/types/dashboard/input-file.d.ts +2 -0
  152. package/types/dashboard/input-gallery.d.ts +14 -0
  153. package/types/dashboard/lib/products.d.ts +14 -0
  154. package/types/dashboard/lib/settings-paths.d.ts +5 -0
  155. package/types/dashboard/order-sections.d.ts +24 -1
  156. package/types/dashboard/preview.d.ts +11 -3
  157. package/types/dashboard/shipping-rates.d.ts +26 -0
  158. package/types/dashboard/template-buyer.d.ts +50 -0
  159. package/types/icons/flags.d.ts +5 -0
  160. package/types/input-checkbox.d.ts +2 -0
  161. package/types/shared/lib/helpers.d.ts +4 -0
  162. package/types/shared/order-summary.d.ts +19 -0
@@ -0,0 +1,665 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
4
+ import { loadStripe } from "@stripe/stripe-js";
5
+ import {
6
+ BillingAddressElement,
7
+ CheckoutElementsProvider,
8
+ ExpressCheckoutElement,
9
+ PaymentElement,
10
+ ShippingAddressElement,
11
+ useCheckoutElements
12
+ } from "@stripe/react-stripe-js/checkout";
13
+ import { money as priceOf } from "../shared/lib/helpers.mjs";
14
+ import { request } from "@drawbridge/drawbridge-utils/fetch";
15
+ import { FormSubdomainHeader } from "./form-subdomain-header.mjs";
16
+ import { continueRequest, lineNote } from "./lib/cart.mjs";
17
+ import InputGroup from "../input-group.mjs";
18
+ import InputSelect from "../input-select.mjs";
19
+ import InputText from "../input-text.mjs";
20
+ import InputRadio from "../dashboard/input-radio.mjs";
21
+ import Button from "../shared/button.mjs";
22
+ import ErrorLine from "../shared/error.mjs";
23
+ import Loader from "../icons/loader.mjs";
24
+ import OrderSummary from "../shared/order-summary.mjs";
25
+ import ChevronDown from "../icons/chevron-down.mjs";
26
+ import ChevronUp from "../icons/chevron-up.mjs";
27
+ const stripes = /* @__PURE__ */ new Map();
28
+ const stripeFor = ({ account, publishable }) => {
29
+ const key = publishable + ":" + account;
30
+ if (!stripes.has(key)) stripes.set(key, loadStripe(publishable, { stripeAccount: account }));
31
+ return stripes.get(key);
32
+ };
33
+ const countryName = (code) => {
34
+ try {
35
+ return new Intl.DisplayNames(["en"], { type: "region" }).of(code) || code;
36
+ } catch {
37
+ return code;
38
+ }
39
+ };
40
+ const visitorCountry = () => {
41
+ try {
42
+ return new Intl.Locale(window.navigator.language).region || null;
43
+ } catch {
44
+ return null;
45
+ }
46
+ };
47
+ const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
48
+ const delivery = (estimate) => {
49
+ var _a, _b;
50
+ return ((_a = estimate == null ? void 0 : estimate.minimum) == null ? void 0 : _a.value) && ((_b = estimate == null ? void 0 : estimate.maximum) == null ? void 0 : _b.value) ? estimate.minimum.value + "\u2013" + estimate.maximum.value + " business days" : null;
51
+ };
52
+ const Step = ({ children, done, onEdit, open, style, summary, title }) => /* @__PURE__ */ jsxs(
53
+ "div",
54
+ {
55
+ ...{
56
+ className: "py-6 space-y-4 border-t border-current" + (!open && !done ? " opacity-40" : "")
57
+ },
58
+ children: [
59
+ /* @__PURE__ */ jsx(
60
+ FormSubdomainHeader,
61
+ {
62
+ ...{
63
+ button: !open && done && /* @__PURE__ */ jsx(
64
+ Button,
65
+ {
66
+ ...{
67
+ inline: true,
68
+ onClick: onEdit,
69
+ size: "small",
70
+ variant: "link"
71
+ },
72
+ children: "Edit"
73
+ }
74
+ ),
75
+ style,
76
+ title
77
+ }
78
+ }
79
+ ),
80
+ /* @__PURE__ */ jsx(
81
+ "div",
82
+ {
83
+ ...{
84
+ className: open ? "space-y-4" : "hidden"
85
+ },
86
+ children
87
+ }
88
+ ),
89
+ !open && done && /* @__PURE__ */ jsx(
90
+ "div",
91
+ {
92
+ ...{
93
+ className: "text-sm opacity-60 space-y-0.5"
94
+ },
95
+ children: summary
96
+ }
97
+ )
98
+ ]
99
+ }
100
+ );
101
+ const Steps = ({ back, button, cart, countries, country, cut, email, onContinue, onCountry, onEmail, onPaid, preview, shipping, style }) => {
102
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
103
+ const state = useCheckoutElements();
104
+ const steps = useMemo(() => shipping ? ["details", "shipping", "payment"] : ["details", "payment"], [shipping]);
105
+ const [step, setStep] = useState(steps[0]);
106
+ const [address, setAddress] = useState(null);
107
+ const [opened, setOpened] = useState(false);
108
+ const [error, setError] = useState(null);
109
+ const [paying, setPaying] = useState(false);
110
+ const go = useCallback((next2) => {
111
+ window.history.pushState({ checkout: next2 }, "");
112
+ setStep(next2);
113
+ }, []);
114
+ useEffect(() => {
115
+ const onPop = () => setStep((current) => steps[Math.max(steps.indexOf(current) - 1, 0)]);
116
+ window.addEventListener("popstate", onPop);
117
+ return () => window.removeEventListener("popstate", onPop);
118
+ }, [steps]);
119
+ const checkout = state.type === "success" ? state.checkout : null;
120
+ const options = (checkout == null ? void 0 : checkout.shippingOptions) || [];
121
+ const chosen = ((_b = (_a = checkout == null ? void 0 : checkout.shipping) == null ? void 0 : _a.shippingOption) == null ? void 0 : _b.id) || null;
122
+ useEffect(() => {
123
+ if (checkout && options.length && !chosen) checkout.updateShippingOption(options[0].id);
124
+ }, [checkout, chosen, options]);
125
+ const [billing, setBilling] = useState(false);
126
+ const taxStatus = (_c = checkout == null ? void 0 : checkout.tax) == null ? void 0 : _c.status;
127
+ useEffect(() => {
128
+ if (taxStatus === "requires_billing_address") setBilling(true);
129
+ }, [taxStatus]);
130
+ if (state.type === "error") return /* @__PURE__ */ jsx(ErrorLine, { ...{ error: (_d = state.error) == null ? void 0 : _d.message, style } });
131
+ if (!checkout) {
132
+ return /* @__PURE__ */ jsx(
133
+ Loader,
134
+ {
135
+ ...{
136
+ className: "w-5 h-5 animate-spin"
137
+ }
138
+ }
139
+ );
140
+ }
141
+ ;
142
+ const code = (_f = (_e = cart == null ? void 0 : cart.lines) == null ? void 0 : _e[0]) == null ? void 0 : _f.currency;
143
+ const money = (value) => priceOf({ code, value });
144
+ const reached = (name) => steps.indexOf(step) > steps.indexOf(name);
145
+ const next = () => go(steps[steps.indexOf(step) + 1]);
146
+ const detailsDone = EMAIL.test(email || "") && (!shipping || Boolean(address == null ? void 0 : address.complete));
147
+ const taxed = ((_g = checkout.tax) == null ? void 0 : _g.status) === "ready" && ((_i = (_h = checkout.total) == null ? void 0 : _h.taxExclusive) == null ? void 0 : _i.minorUnitsAmount) > 0;
148
+ const rate = (_j = checkout.shipping) == null ? void 0 : _j.shippingOption;
149
+ const Chevron = opened ? ChevronUp : ChevronDown;
150
+ const contact = async () => {
151
+ var _a2;
152
+ setError(null);
153
+ const result = await checkout.updateEmail(email);
154
+ if ((result == null ? void 0 : result.type) === "error") {
155
+ setError((_a2 = result.error) == null ? void 0 : _a2.message);
156
+ return;
157
+ }
158
+ ;
159
+ onContinue(email);
160
+ next();
161
+ };
162
+ const done = (result) => {
163
+ var _a2;
164
+ if ((result == null ? void 0 : result.type) === "error") {
165
+ setError((_a2 = result.error) == null ? void 0 : _a2.message);
166
+ return;
167
+ }
168
+ ;
169
+ onPaid();
170
+ };
171
+ const pay = async () => {
172
+ setPaying(true);
173
+ setError(null);
174
+ try {
175
+ done(await checkout.confirm({ redirect: "if_required" }));
176
+ } finally {
177
+ setPaying(false);
178
+ }
179
+ };
180
+ const unitOf = (item) => {
181
+ var _a2, _b2, _c2;
182
+ const name = item.variantTitle ? item.productTitle + " - " + item.variantTitle : item.productTitle;
183
+ return ((_c2 = (_b2 = (_a2 = checkout.lineItems) == null ? void 0 : _a2.find((stripeLine) => stripeLine.name === name)) == null ? void 0 : _b2.unitAmount) == null ? void 0 : _c2.amount) || money(item.price);
184
+ };
185
+ const line = ((_k = cart == null ? void 0 : cart.lines) == null ? void 0 : _k.length) ? cart.lines.map((item) => ({
186
+ id: item.id,
187
+ image: item.image,
188
+ name: item.productTitle,
189
+ note: lineNote(item, cut),
190
+ summary: [item.variantTitle, item.quantity + " \xD7 " + unitOf(item)].filter(Boolean).join(" \xB7 ")
191
+ })) : [];
192
+ return /* @__PURE__ */ jsxs("div", { children: [
193
+ /* @__PURE__ */ jsx(
194
+ FormSubdomainHeader,
195
+ {
196
+ ...{
197
+ back: {
198
+ onClick: () => step === steps[0] ? back() : window.history.back()
199
+ },
200
+ button,
201
+ style,
202
+ title: "Checkout"
203
+ }
204
+ }
205
+ ),
206
+ /* @__PURE__ */ jsxs(
207
+ "div",
208
+ {
209
+ ...{
210
+ className: "pt-6"
211
+ },
212
+ children: [
213
+ /* @__PURE__ */ jsxs(
214
+ "div",
215
+ {
216
+ ...{
217
+ className: "pb-6"
218
+ },
219
+ children: [
220
+ /* @__PURE__ */ jsx(
221
+ Button,
222
+ {
223
+ ...{
224
+ "aria-expanded": opened,
225
+ onClick: () => setOpened(!opened),
226
+ variant: "link"
227
+ },
228
+ children: /* @__PURE__ */ jsxs(
229
+ "span",
230
+ {
231
+ ...{
232
+ className: "flex items-center justify-between gap-3 w-full"
233
+ },
234
+ children: [
235
+ /* @__PURE__ */ jsx("span", { children: "Summary" }),
236
+ /* @__PURE__ */ jsxs(
237
+ "span",
238
+ {
239
+ ...{
240
+ className: "flex items-center gap-2"
241
+ },
242
+ children: [
243
+ /* @__PURE__ */ jsx("span", { children: (_m = (_l = checkout.total) == null ? void 0 : _l.total) == null ? void 0 : _m.amount }),
244
+ /* @__PURE__ */ jsx(
245
+ Chevron,
246
+ {
247
+ ...{
248
+ className: "w-5 h-5"
249
+ }
250
+ }
251
+ )
252
+ ]
253
+ }
254
+ )
255
+ ]
256
+ }
257
+ )
258
+ }
259
+ ),
260
+ (opened || (cut == null ? void 0 : cut.length) > 0) && /* @__PURE__ */ jsx(
261
+ "div",
262
+ {
263
+ ...{
264
+ className: "pt-4"
265
+ },
266
+ children: /* @__PURE__ */ jsx(
267
+ OrderSummary,
268
+ {
269
+ ...{
270
+ lines: line,
271
+ rows: [
272
+ ["Subtotal", (_o = (_n = checkout.total) == null ? void 0 : _n.subtotal) == null ? void 0 : _o.amount],
273
+ ...shipping ? [["Shipping", rate ? rate.minorUnitsAmount ? rate.amount : "Free" : null]] : [],
274
+ ["Tax", taxed ? checkout.total.taxExclusive.amount : null],
275
+ ["Total", (_q = (_p = checkout.total) == null ? void 0 : _p.total) == null ? void 0 : _q.amount]
276
+ ]
277
+ }
278
+ }
279
+ )
280
+ }
281
+ )
282
+ ]
283
+ }
284
+ ),
285
+ !preview && /* @__PURE__ */ jsx(
286
+ "div",
287
+ {
288
+ ...{
289
+ className: "pb-6"
290
+ },
291
+ children: /* @__PURE__ */ jsx(
292
+ ExpressCheckoutElement,
293
+ {
294
+ ...{
295
+ onConfirm: async (event) => done(await checkout.confirm({ expressCheckoutConfirmEvent: event }))
296
+ }
297
+ }
298
+ )
299
+ }
300
+ ),
301
+ /* @__PURE__ */ jsxs(
302
+ Step,
303
+ {
304
+ ...{
305
+ done: reached("details"),
306
+ onEdit: () => setStep("details"),
307
+ open: step === "details",
308
+ style,
309
+ summary: /* @__PURE__ */ jsxs(Fragment, { children: [
310
+ /* @__PURE__ */ jsx("p", { children: email }),
311
+ shipping && (address == null ? void 0 : address.value) && /* @__PURE__ */ jsxs(Fragment, { children: [
312
+ /* @__PURE__ */ jsx("p", { children: address.value.name }),
313
+ /* @__PURE__ */ jsx("p", { children: (_r = address.value.address) == null ? void 0 : _r.line1 }),
314
+ /* @__PURE__ */ jsx("p", { children: [(_s = address.value.address) == null ? void 0 : _s.city, (_t = address.value.address) == null ? void 0 : _t.state, (_u = address.value.address) == null ? void 0 : _u.postal_code].filter(Boolean).join(", ") }),
315
+ /* @__PURE__ */ jsx("p", { children: countryName(country) })
316
+ ] })
317
+ ] }),
318
+ title: shipping ? "Contact and address" : "Contact"
319
+ },
320
+ children: [
321
+ /* @__PURE__ */ jsx(
322
+ InputGroup,
323
+ {
324
+ ...{
325
+ input: /* @__PURE__ */ jsx(
326
+ InputText,
327
+ {
328
+ ...{
329
+ autoComplete: "email",
330
+ onChange: onEmail,
331
+ style,
332
+ type: "email",
333
+ value: email || ""
334
+ }
335
+ }
336
+ ),
337
+ label: "Email",
338
+ style
339
+ }
340
+ }
341
+ ),
342
+ shipping && countries.length > 1 && /* @__PURE__ */ jsx(
343
+ InputGroup,
344
+ {
345
+ ...{
346
+ input: /* @__PURE__ */ jsx(
347
+ InputSelect,
348
+ {
349
+ ...{
350
+ onChange: onCountry,
351
+ options: countries.map((value) => ({ label: countryName(value), value })),
352
+ style,
353
+ value: country
354
+ }
355
+ }
356
+ ),
357
+ label: "Country",
358
+ style
359
+ }
360
+ }
361
+ ),
362
+ shipping && /* @__PURE__ */ jsx(
363
+ ShippingAddressElement,
364
+ {
365
+ ...{
366
+ onChange: setAddress
367
+ }
368
+ }
369
+ ),
370
+ /* @__PURE__ */ jsx(
371
+ Button,
372
+ {
373
+ ...{
374
+ disabled: !detailsDone,
375
+ onClick: contact,
376
+ style
377
+ },
378
+ children: "Continue"
379
+ }
380
+ )
381
+ ]
382
+ }
383
+ ),
384
+ shipping && /* @__PURE__ */ jsxs(
385
+ Step,
386
+ {
387
+ ...{
388
+ done: reached("shipping"),
389
+ onEdit: () => setStep("shipping"),
390
+ open: step === "shipping",
391
+ style,
392
+ summary: rate && /* @__PURE__ */ jsx("p", { children: rate.displayName + " \xB7 " + (rate.minorUnitsAmount ? rate.amount : "Free") }),
393
+ title: "Shipping"
394
+ },
395
+ children: [
396
+ /* @__PURE__ */ jsx(
397
+ "div",
398
+ {
399
+ ...{
400
+ className: "space-y-3"
401
+ },
402
+ children: options.map((option) => /* @__PURE__ */ jsx(
403
+ InputRadio,
404
+ {
405
+ ...{
406
+ checked: option.id === chosen,
407
+ label: /* @__PURE__ */ jsxs(
408
+ "span",
409
+ {
410
+ ...{
411
+ className: "flex items-center justify-between gap-3 w-full"
412
+ },
413
+ children: [
414
+ /* @__PURE__ */ jsxs(
415
+ "span",
416
+ {
417
+ ...{
418
+ className: "flex flex-col min-w-0"
419
+ },
420
+ children: [
421
+ /* @__PURE__ */ jsx(
422
+ "span",
423
+ {
424
+ ...{
425
+ className: "truncate"
426
+ },
427
+ children: option.displayName
428
+ }
429
+ ),
430
+ delivery(option.deliveryEstimate) && /* @__PURE__ */ jsx(
431
+ "span",
432
+ {
433
+ ...{
434
+ className: "text-xs opacity-60 truncate"
435
+ },
436
+ children: delivery(option.deliveryEstimate)
437
+ }
438
+ )
439
+ ]
440
+ }
441
+ ),
442
+ /* @__PURE__ */ jsx(
443
+ "span",
444
+ {
445
+ ...{
446
+ className: "shrink-0"
447
+ },
448
+ children: option.minorUnitsAmount ? option.amount : "Free"
449
+ }
450
+ )
451
+ ]
452
+ }
453
+ ),
454
+ onChange: () => checkout.updateShippingOption(option.id),
455
+ value: option.id
456
+ }
457
+ },
458
+ option.id
459
+ ))
460
+ }
461
+ ),
462
+ /* @__PURE__ */ jsx(
463
+ Button,
464
+ {
465
+ ...{
466
+ disabled: !chosen,
467
+ onClick: next,
468
+ style
469
+ },
470
+ children: "Continue"
471
+ }
472
+ )
473
+ ]
474
+ }
475
+ ),
476
+ /* @__PURE__ */ jsxs(
477
+ Step,
478
+ {
479
+ ...{
480
+ open: step === "payment",
481
+ style,
482
+ title: "Payment"
483
+ },
484
+ children: [
485
+ (billing || taxStatus === "requires_billing_address") && /* @__PURE__ */ jsx(BillingAddressElement, {}),
486
+ /* @__PURE__ */ jsx(PaymentElement, {}),
487
+ /* @__PURE__ */ jsx(
488
+ ErrorLine,
489
+ {
490
+ ...{
491
+ error,
492
+ style
493
+ }
494
+ }
495
+ ),
496
+ /* @__PURE__ */ jsx(
497
+ Button,
498
+ {
499
+ ...{
500
+ // @story checkout/pay-on-page
501
+ // On a preview link every step works and Pay stays off.
502
+ disabled: preview || !checkout.canConfirm,
503
+ loading: paying,
504
+ onClick: pay,
505
+ style
506
+ },
507
+ children: "Pay " + (((_w = (_v = checkout.total) == null ? void 0 : _v.total) == null ? void 0 : _w.amount) || "")
508
+ }
509
+ )
510
+ ]
511
+ }
512
+ )
513
+ ]
514
+ }
515
+ )
516
+ ] });
517
+ };
518
+ const FormSubdomainCheckout = ({ back, button, cart: start, onCart, onPaid, params, preview, style }) => {
519
+ var _a;
520
+ const [country, setCountry] = useState(null);
521
+ const [email, setEmail] = useState("");
522
+ const [session, setSession] = useState(null);
523
+ const [error, setError] = useState(null);
524
+ const cartChanged = useRef(onCart);
525
+ useEffect(() => {
526
+ cartChanged.current = onCart;
527
+ }, [onCart]);
528
+ useEffect(() => {
529
+ let current = true;
530
+ setError(null);
531
+ request({
532
+ body: {
533
+ cartId: start == null ? void 0 : start.id,
534
+ country: country || visitorCountry()
535
+ },
536
+ endpoint: "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart/checkout" + (preview && (params == null ? void 0 : params.token) ? "?drwbrdg_pre=" + encodeURIComponent(params.token) : ""),
537
+ method: "POST"
538
+ }).then(({ result }) => {
539
+ var _a2;
540
+ if (!current) return;
541
+ setSession(result);
542
+ (_a2 = cartChanged.current) == null ? void 0 : _a2.call(cartChanged, result.cart);
543
+ }).catch((thrown) => {
544
+ if (current) setError((thrown == null ? void 0 : thrown.message) || "Checkout is not available right now");
545
+ });
546
+ return () => {
547
+ current = false;
548
+ };
549
+ }, [country, params == null ? void 0 : params.slug, params == null ? void 0 : params.subdomain, params == null ? void 0 : params.token, preview, start == null ? void 0 : start.id]);
550
+ const onContinue = (value) => {
551
+ const keep = continueRequest({ cartId: start == null ? void 0 : start.id, email: value, params, preview });
552
+ if (keep) request(keep).catch(() => {
553
+ });
554
+ };
555
+ const stripe = useMemo(() => (session == null ? void 0 : session.publishable) && (session == null ? void 0 : session.account) ? stripeFor(session) : null, [session]);
556
+ const appearance = useMemo(() => {
557
+ var _a2, _b, _c, _d;
558
+ return {
559
+ variables: {
560
+ ...((_b = (_a2 = style == null ? void 0 : style.text) == null ? void 0 : _a2.color) == null ? void 0 : _b.rgb) && {
561
+ colorText: style.text.color.rgb
562
+ },
563
+ ...((_d = (_c = style == null ? void 0 : style.background) == null ? void 0 : _c.color) == null ? void 0 : _d.rgb) && {
564
+ colorBackground: style.background.color.rgb
565
+ }
566
+ }
567
+ };
568
+ }, [style]);
569
+ if (error) {
570
+ return /* @__PURE__ */ jsxs(
571
+ "div",
572
+ {
573
+ ...{
574
+ className: "space-y-6"
575
+ },
576
+ children: [
577
+ /* @__PURE__ */ jsx(
578
+ FormSubdomainHeader,
579
+ {
580
+ ...{
581
+ back: {
582
+ onClick: back
583
+ },
584
+ button,
585
+ style,
586
+ title: "Checkout"
587
+ }
588
+ }
589
+ ),
590
+ /* @__PURE__ */ jsx(
591
+ ErrorLine,
592
+ {
593
+ ...{
594
+ error,
595
+ style
596
+ }
597
+ }
598
+ )
599
+ ]
600
+ }
601
+ );
602
+ }
603
+ ;
604
+ if (!session || !stripe) {
605
+ return /* @__PURE__ */ jsx(
606
+ FormSubdomainHeader,
607
+ {
608
+ ...{
609
+ back: {
610
+ onClick: back
611
+ },
612
+ button,
613
+ style,
614
+ title: "Checkout"
615
+ }
616
+ }
617
+ );
618
+ }
619
+ ;
620
+ return /* @__PURE__ */ jsx(
621
+ CheckoutElementsProvider,
622
+ {
623
+ ...{
624
+ options: {
625
+ clientSecret: session.clientSecret,
626
+ ...email && {
627
+ defaultValues: {
628
+ email
629
+ }
630
+ },
631
+ elementsOptions: {
632
+ appearance
633
+ }
634
+ },
635
+ stripe
636
+ },
637
+ children: /* @__PURE__ */ jsx(
638
+ Steps,
639
+ {
640
+ ...{
641
+ back,
642
+ button,
643
+ cart: session.cart,
644
+ countries: session.countries || [],
645
+ country: session.country,
646
+ cut: ((_a = session.cart) == null ? void 0 : _a.cut) || [],
647
+ email,
648
+ onContinue,
649
+ onCountry: setCountry,
650
+ onEmail: setEmail,
651
+ onPaid,
652
+ preview,
653
+ shipping: Boolean(session.shipping),
654
+ style
655
+ }
656
+ }
657
+ )
658
+ },
659
+ session.clientSecret
660
+ );
661
+ };
662
+ var form_subdomain_checkout_default = FormSubdomainCheckout;
663
+ export {
664
+ form_subdomain_checkout_default as default
665
+ };