@artisanpack-ui/ecommerce-storefront-react 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -2
  3. package/dist/Addresses-D3ESHG3L.mjs +27 -0
  4. package/dist/Addresses-D3ESHG3L.mjs.map +1 -0
  5. package/dist/CategoryShow-OAGROEMA.mjs +12 -0
  6. package/dist/CategoryShow-OAGROEMA.mjs.map +1 -0
  7. package/dist/Claim-CJ4UOAUD.mjs +22 -0
  8. package/dist/Claim-CJ4UOAUD.mjs.map +1 -0
  9. package/dist/Confirmation-TLMMBPWS.mjs +20 -0
  10. package/dist/Confirmation-TLMMBPWS.mjs.map +1 -0
  11. package/dist/Dashboard-ARXORMTL.mjs +24 -0
  12. package/dist/Dashboard-ARXORMTL.mjs.map +1 -0
  13. package/dist/Downloads-CEQBY7JO.mjs +25 -0
  14. package/dist/Downloads-CEQBY7JO.mjs.map +1 -0
  15. package/dist/Index-KRR3Q7EJ.mjs +12 -0
  16. package/dist/Index-KRR3Q7EJ.mjs.map +1 -0
  17. package/dist/Index-RLQFEBTX.mjs +22 -0
  18. package/dist/Index-RLQFEBTX.mjs.map +1 -0
  19. package/dist/Index-WDJYGR5Q.mjs +12 -0
  20. package/dist/Index-WDJYGR5Q.mjs.map +1 -0
  21. package/dist/Index-XYU5QLUT.mjs +23 -0
  22. package/dist/Index-XYU5QLUT.mjs.map +1 -0
  23. package/dist/Lookup-QNUQKUID.mjs +19 -0
  24. package/dist/Lookup-QNUQKUID.mjs.map +1 -0
  25. package/dist/OrderShow-RYTP62YA.mjs +27 -0
  26. package/dist/OrderShow-RYTP62YA.mjs.map +1 -0
  27. package/dist/Orders-LZW57GE6.mjs +25 -0
  28. package/dist/Orders-LZW57GE6.mjs.map +1 -0
  29. package/dist/Profile-ZAAWFCAL.mjs +25 -0
  30. package/dist/Profile-ZAAWFCAL.mjs.map +1 -0
  31. package/dist/Show-LFWUO3KR.mjs +14 -0
  32. package/dist/Show-LFWUO3KR.mjs.map +1 -0
  33. package/dist/TagShow-FXKXRGY2.mjs +12 -0
  34. package/dist/TagShow-FXKXRGY2.mjs.map +1 -0
  35. package/dist/chunk-5UUNH3EH.mjs +1888 -0
  36. package/dist/chunk-5UUNH3EH.mjs.map +1 -0
  37. package/dist/chunk-A3MMQ2RY.mjs +183 -0
  38. package/dist/chunk-A3MMQ2RY.mjs.map +1 -0
  39. package/dist/chunk-ABGPTZ3Q.mjs +198 -0
  40. package/dist/chunk-ABGPTZ3Q.mjs.map +1 -0
  41. package/dist/chunk-BJ3FJFZQ.mjs +32 -0
  42. package/dist/chunk-BJ3FJFZQ.mjs.map +1 -0
  43. package/dist/chunk-BSASRFQ7.mjs +89 -0
  44. package/dist/chunk-BSASRFQ7.mjs.map +1 -0
  45. package/dist/chunk-CGCW3555.mjs +148 -0
  46. package/dist/chunk-CGCW3555.mjs.map +1 -0
  47. package/dist/chunk-DWR23FJD.mjs +643 -0
  48. package/dist/chunk-DWR23FJD.mjs.map +1 -0
  49. package/dist/chunk-ENY3MH2W.mjs +148 -0
  50. package/dist/chunk-ENY3MH2W.mjs.map +1 -0
  51. package/dist/chunk-EWJLRWPO.mjs +280 -0
  52. package/dist/chunk-EWJLRWPO.mjs.map +1 -0
  53. package/dist/chunk-FL5XL3ET.mjs +212 -0
  54. package/dist/chunk-FL5XL3ET.mjs.map +1 -0
  55. package/dist/chunk-FOOP6UK3.mjs +218 -0
  56. package/dist/chunk-FOOP6UK3.mjs.map +1 -0
  57. package/dist/chunk-HCC7GTVO.mjs +115 -0
  58. package/dist/chunk-HCC7GTVO.mjs.map +1 -0
  59. package/dist/chunk-HXZMY3GE.mjs +2331 -0
  60. package/dist/chunk-HXZMY3GE.mjs.map +1 -0
  61. package/dist/chunk-IOL2YQ62.mjs +109 -0
  62. package/dist/chunk-IOL2YQ62.mjs.map +1 -0
  63. package/dist/chunk-JH7SFSZA.mjs +104 -0
  64. package/dist/chunk-JH7SFSZA.mjs.map +1 -0
  65. package/dist/chunk-JJOPX4PI.mjs +205 -0
  66. package/dist/chunk-JJOPX4PI.mjs.map +1 -0
  67. package/dist/chunk-LT3GG7YQ.mjs +32 -0
  68. package/dist/chunk-LT3GG7YQ.mjs.map +1 -0
  69. package/dist/chunk-MZFULGDI.mjs +267 -0
  70. package/dist/chunk-MZFULGDI.mjs.map +1 -0
  71. package/dist/chunk-O4WPMMSH.mjs +58 -0
  72. package/dist/chunk-O4WPMMSH.mjs.map +1 -0
  73. package/dist/chunk-OU3WYFIH.mjs +397 -0
  74. package/dist/chunk-OU3WYFIH.mjs.map +1 -0
  75. package/dist/chunk-P3NIV4YG.mjs +998 -0
  76. package/dist/chunk-P3NIV4YG.mjs.map +1 -0
  77. package/dist/chunk-PEBBSZ5R.mjs +201 -0
  78. package/dist/chunk-PEBBSZ5R.mjs.map +1 -0
  79. package/dist/chunk-T5OWL6EG.mjs +73 -0
  80. package/dist/chunk-T5OWL6EG.mjs.map +1 -0
  81. package/dist/chunk-THPUK35U.mjs +132 -0
  82. package/dist/chunk-THPUK35U.mjs.map +1 -0
  83. package/dist/chunk-TPOKMH5E.mjs +142 -0
  84. package/dist/chunk-TPOKMH5E.mjs.map +1 -0
  85. package/dist/chunk-VX5TEJNU.mjs +1898 -0
  86. package/dist/chunk-VX5TEJNU.mjs.map +1 -0
  87. package/dist/chunk-WUL34MB2.mjs +268 -0
  88. package/dist/chunk-WUL34MB2.mjs.map +1 -0
  89. package/dist/chunk-WYGOMIZK.mjs +140 -0
  90. package/dist/chunk-WYGOMIZK.mjs.map +1 -0
  91. package/dist/chunk-Y2IOBBN7.mjs +127 -0
  92. package/dist/chunk-Y2IOBBN7.mjs.map +1 -0
  93. package/dist/chunk-Y5BRPEHA.mjs +54 -0
  94. package/dist/chunk-Y5BRPEHA.mjs.map +1 -0
  95. package/dist/index.d.ts +4607 -0
  96. package/dist/index.mjs +1515 -0
  97. package/dist/index.mjs.map +1 -0
  98. package/package.json +112 -4
@@ -0,0 +1,2331 @@
1
+ import {
2
+ PURCHASE_ERROR_BAG,
3
+ REVIEW_ERROR_BAG,
4
+ linePrice,
5
+ requestJson,
6
+ useErrorBag,
7
+ useStorefrontPost,
8
+ visitWithQuery
9
+ } from "./chunk-Y2IOBBN7.mjs";
10
+ import {
11
+ Swatches
12
+ } from "./chunk-IOL2YQ62.mjs";
13
+ import {
14
+ RelatedProducts
15
+ } from "./chunk-PEBBSZ5R.mjs";
16
+ import {
17
+ RatingSummary,
18
+ StockStatus
19
+ } from "./chunk-ABGPTZ3Q.mjs";
20
+ import {
21
+ useStorefrontRouter
22
+ } from "./chunk-TPOKMH5E.mjs";
23
+ import {
24
+ Field
25
+ } from "./chunk-WYGOMIZK.mjs";
26
+ import {
27
+ EmptyState,
28
+ Price,
29
+ Quantity,
30
+ addBuiltInRegistration,
31
+ cx,
32
+ filled,
33
+ getRegistries,
34
+ idFragment,
35
+ storefrontLayout,
36
+ useStorefront,
37
+ useStorefrontPage
38
+ } from "./chunk-VX5TEJNU.mjs";
39
+
40
+ // src/pages/Product/Show.tsx
41
+ import { __ as __12 } from "@artisanpack-ui/ecommerce-storefront-core";
42
+ import { Accordion, AccordionItem, Alert as Alert4, Breadcrumbs, Icon as Icon9 } from "@artisanpack-ui/react";
43
+ import { useEffect as useEffect5, useMemo, useRef as useRef5 } from "react";
44
+
45
+ // src/components/Gallery.tsx
46
+ import { useLightbox } from "@artisanpack-ui/behavior/react";
47
+ import { __ } from "@artisanpack-ui/ecommerce-storefront-core";
48
+ import { Badge, Button, Icon } from "@artisanpack-ui/react";
49
+ import { useEffect, useId, useRef, useState } from "react";
50
+
51
+ // src/internal/portal.tsx
52
+ import { useSyncExternalStore } from "react";
53
+ import { createPortal } from "react-dom";
54
+ var subscribe = () => () => {
55
+ };
56
+ function useIsClient() {
57
+ return useSyncExternalStore(
58
+ subscribe,
59
+ () => true,
60
+ () => false
61
+ );
62
+ }
63
+ function Portal({ children }) {
64
+ const isClient = useIsClient();
65
+ return isClient ? createPortal(children, document.body) : null;
66
+ }
67
+
68
+ // src/components/Gallery.tsx
69
+ import { jsx, jsxs } from "react/jsx-runtime";
70
+ var GALLERY_SHOW_EVENT = "ecommerce-gallery-show";
71
+ function Gallery({
72
+ items,
73
+ name,
74
+ active: initial = 0,
75
+ thumbnails = "bottom",
76
+ zoom = true,
77
+ scope = null,
78
+ id,
79
+ className
80
+ }) {
81
+ const generated = `ec-gallery-${useId().replace(/[^A-Za-z0-9_-]/g, "")}`;
82
+ const baseId = id ?? generated;
83
+ const count = items.length;
84
+ const [active, setActive] = useState(Math.max(0, Math.min(initial, count - 1)));
85
+ const [announcement, setAnnouncement] = useState("");
86
+ const [open, setOpen] = useState(false);
87
+ const [layerDir, setLayerDir] = useState(void 0);
88
+ const root = useRef(null);
89
+ const show = (index) => {
90
+ const next = (index + count) % count;
91
+ const item = items[next];
92
+ setActive(next);
93
+ setAnnouncement(
94
+ __("Image :number of :total: :alt", {
95
+ number: next + 1,
96
+ total: count,
97
+ alt: item?.alt ?? ""
98
+ })
99
+ );
100
+ };
101
+ useEffect(() => {
102
+ const listener = (event) => {
103
+ const detail = event.detail ?? {};
104
+ if (null !== scope && detail.scope !== scope) {
105
+ return;
106
+ }
107
+ const index = items.findIndex((item) => item.url === detail.url || item.full === detail.url);
108
+ if (index >= 0) {
109
+ show(index);
110
+ }
111
+ };
112
+ window.addEventListener(GALLERY_SHOW_EVENT, listener);
113
+ return () => window.removeEventListener(GALLERY_SHOW_EVENT, listener);
114
+ });
115
+ const lightbox = useLightbox({
116
+ id: baseId,
117
+ count: Math.max(1, count),
118
+ open,
119
+ onOpenChange: ({ open: next }) => setOpen(next),
120
+ index: active,
121
+ onIndexChange: ({ index }) => {
122
+ if (open) {
123
+ setActive(Math.min(Math.max(index, 0), count - 1));
124
+ }
125
+ },
126
+ modal: true
127
+ });
128
+ if (0 === count) {
129
+ return /* @__PURE__ */ jsxs("div", { className: cx("ec-gallery", "ec-gallery--empty", className), "data-gallery": "empty", children: [
130
+ /* @__PURE__ */ jsx(Icon, { name: "image", "aria-hidden": "true" }),
131
+ /* @__PURE__ */ jsx("span", { className: "apui-sr-only", children: __("No image available") })
132
+ ] });
133
+ }
134
+ const current = items[active] ?? items[0];
135
+ const zoomLabel = "" !== current.alt ? __("Zoom image: :alt", { alt: current.alt }) : __("Zoom image");
136
+ const counter = __(":index / :count", { index: active + 1, count });
137
+ const zoomIn = () => {
138
+ if (null !== root.current) {
139
+ setLayerDir(getComputedStyle(root.current).direction);
140
+ }
141
+ setOpen(true);
142
+ };
143
+ return /* @__PURE__ */ jsxs(
144
+ "div",
145
+ {
146
+ ref: root,
147
+ className: cx("ec-gallery", className),
148
+ id: baseId,
149
+ role: "region",
150
+ "aria-roledescription": __("gallery"),
151
+ "aria-label": __(":name images", { name }),
152
+ "data-gallery": "",
153
+ "data-gallery-thumbnails": thumbnails,
154
+ children: [
155
+ /* @__PURE__ */ jsxs("div", { className: "ec-gallery__layout", children: [
156
+ /* @__PURE__ */ jsxs("div", { className: "ec-gallery__stage", "data-gallery-stage": "", children: [
157
+ items.map((item, index) => /* @__PURE__ */ jsx(
158
+ "img",
159
+ {
160
+ src: item.url,
161
+ srcSet: item.srcset ?? void 0,
162
+ sizes: null !== item.srcset ? "(min-width: 1024px) 50vw, 100vw" : void 0,
163
+ width: item.width ?? 1200,
164
+ height: item.height ?? 1200,
165
+ alt: item.alt,
166
+ loading: index !== initial ? "lazy" : void 0,
167
+ style: index !== active ? { display: "none" } : void 0,
168
+ decoding: "async",
169
+ className: "ec-gallery__image",
170
+ onClick: zoom ? zoomIn : void 0,
171
+ "data-gallery-image": index
172
+ },
173
+ item.key
174
+ )),
175
+ count > 1 ? /* @__PURE__ */ jsx(
176
+ Badge,
177
+ {
178
+ variant: "solid",
179
+ color: "neutral",
180
+ className: "ec-gallery__counter",
181
+ "aria-hidden": "true",
182
+ "data-gallery-counter": "",
183
+ children: /* @__PURE__ */ jsx("span", { children: counter })
184
+ }
185
+ ) : null,
186
+ zoom ? /* @__PURE__ */ jsx(
187
+ Button,
188
+ {
189
+ variant: "solid",
190
+ color: "neutral",
191
+ size: "sm",
192
+ leadingIcon: "zoom-in",
193
+ className: "ec-gallery__zoom",
194
+ "aria-haspopup": "dialog",
195
+ "aria-label": zoomLabel,
196
+ onClick: zoomIn,
197
+ "data-gallery-zoom": "",
198
+ children: __("Zoom")
199
+ }
200
+ ) : null
201
+ ] }),
202
+ /* @__PURE__ */ jsx(
203
+ "p",
204
+ {
205
+ className: "apui-sr-only",
206
+ "aria-live": "polite",
207
+ "aria-atomic": "true",
208
+ "data-gallery-announcement": "",
209
+ children: announcement
210
+ }
211
+ ),
212
+ count > 1 && "none" !== thumbnails ? /* @__PURE__ */ jsx("ul", { role: "list", className: "ec-gallery__thumbnails", "aria-label": __("Thumbnails"), children: items.map((item, index) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
213
+ "button",
214
+ {
215
+ type: "button",
216
+ className: "ec-gallery__thumbnail",
217
+ "aria-current": index === active ? "true" : void 0,
218
+ onClick: () => show(index),
219
+ "aria-label": __("Image :number of :total: :alt", {
220
+ number: index + 1,
221
+ total: count,
222
+ alt: item.alt
223
+ }),
224
+ "data-gallery-thumbnail": index,
225
+ children: /* @__PURE__ */ jsx(
226
+ "img",
227
+ {
228
+ src: item.url,
229
+ srcSet: item.srcset ?? void 0,
230
+ sizes: null !== item.srcset ? "128px" : void 0,
231
+ width: 128,
232
+ height: 128,
233
+ alt: "",
234
+ loading: "lazy",
235
+ decoding: "async"
236
+ }
237
+ )
238
+ }
239
+ ) }, item.key)) }) : null
240
+ ] }),
241
+ zoom ? /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(
242
+ "div",
243
+ {
244
+ id: `${baseId}-layer`,
245
+ className: "ec-gallery__layer",
246
+ dir: layerDir,
247
+ "data-gallery-lightbox": "",
248
+ children: [
249
+ /* @__PURE__ */ jsx("div", { ...lightbox.getBackdropProps() }),
250
+ /* @__PURE__ */ jsx("div", { ...lightbox.getPositionerProps(), children: /* @__PURE__ */ jsxs("div", { ...lightbox.getContentProps(), className: "apui-lightbox", children: [
251
+ /* @__PURE__ */ jsxs("div", { "data-scope": "image-gallery", "data-part": "bar", id: `${baseId}-bar`, children: [
252
+ /* @__PURE__ */ jsx("h2", { ...lightbox.getTitleProps(), "aria-live": "polite", children: `${counter} \xB7 ${name}` }),
253
+ /* @__PURE__ */ jsx(
254
+ Button,
255
+ {
256
+ ...lightbox.getCloseTriggerProps(),
257
+ variant: "ghost",
258
+ color: "neutral",
259
+ size: "sm",
260
+ iconOnly: true,
261
+ leadingIcon: "x",
262
+ "aria-label": __("Close")
263
+ }
264
+ )
265
+ ] }),
266
+ /* @__PURE__ */ jsxs("div", { "data-scope": "image-gallery", "data-part": "stage", id: `${baseId}-stage`, children: [
267
+ /* @__PURE__ */ jsx("img", { ...lightbox.getImageProps(), src: current.full, alt: current.alt }),
268
+ /* @__PURE__ */ jsx(
269
+ Button,
270
+ {
271
+ ...lightbox.getPrevTriggerProps(),
272
+ variant: "soft",
273
+ color: "neutral",
274
+ iconOnly: true,
275
+ leadingIcon: "chevron-left",
276
+ "aria-label": __("Previous image"),
277
+ disabled: count < 2
278
+ }
279
+ ),
280
+ /* @__PURE__ */ jsx(
281
+ Button,
282
+ {
283
+ ...lightbox.getNextTriggerProps(),
284
+ variant: "soft",
285
+ color: "neutral",
286
+ iconOnly: true,
287
+ leadingIcon: "chevron-right",
288
+ "aria-label": __("Next image"),
289
+ disabled: count < 2
290
+ }
291
+ )
292
+ ] }),
293
+ count > 1 ? /* @__PURE__ */ jsx(
294
+ "div",
295
+ {
296
+ "data-scope": "image-gallery",
297
+ "data-part": "thumbs",
298
+ id: `${baseId}-thumbs`,
299
+ role: "group",
300
+ "aria-label": __("Thumbnails"),
301
+ children: items.map((item, index) => /* @__PURE__ */ jsx(
302
+ "button",
303
+ {
304
+ type: "button",
305
+ ...lightbox.getThumbProps({ index }),
306
+ "aria-label": __("Image :number of :total: :alt", {
307
+ number: index + 1,
308
+ total: count,
309
+ alt: item.alt
310
+ }),
311
+ children: /* @__PURE__ */ jsx("img", { src: item.url, alt: "", loading: "lazy", decoding: "async" })
312
+ },
313
+ item.key
314
+ ))
315
+ }
316
+ ) : null
317
+ ] }) })
318
+ ]
319
+ }
320
+ ) }) : null
321
+ ]
322
+ }
323
+ );
324
+ }
325
+
326
+ // src/product/forms/BundledForm.tsx
327
+ import { __ as __3 } from "@artisanpack-ui/ecommerce-storefront-core";
328
+ import { Badge as Badge2, Checkbox } from "@artisanpack-ui/react";
329
+ import { useState as useState3 } from "react";
330
+
331
+ // src/product/AddToCart.tsx
332
+ import { __ as __2 } from "@artisanpack-ui/ecommerce-storefront-core";
333
+ import { Alert, Button as Button2, Input } from "@artisanpack-ui/react";
334
+ import { useState as useState2 } from "react";
335
+
336
+ // src/product/PurchaseFormContext.tsx
337
+ import { createContext, useContext } from "react";
338
+ var PurchaseFormContext = createContext({
339
+ productName: null,
340
+ productUrl: null,
341
+ variantId: null,
342
+ announcement: null,
343
+ notifySubscribed: false
344
+ });
345
+ function usePurchaseFormContext() {
346
+ return useContext(PurchaseFormContext);
347
+ }
348
+
349
+ // src/product/AddToCart.tsx
350
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
351
+ function AddToCart({
352
+ form,
353
+ formId,
354
+ quantity,
355
+ onQuantityChange,
356
+ onAdd,
357
+ processing,
358
+ showQuantity = true,
359
+ buttonLabel,
360
+ priceOnButton = true,
361
+ blockedReason,
362
+ notifyData = {}
363
+ }) {
364
+ const { locale } = useStorefront();
365
+ const { announcement, notifySubscribed, buttonText = null } = usePurchaseFormContext();
366
+ const errors = useErrorBag(PURCHASE_ERROR_BAG);
367
+ const notify = form.backInStock;
368
+ const offersNotify = null !== notify;
369
+ const withQuantity = showQuantity && form.showQuantity && !offersNotify;
370
+ const reason = void 0 === blockedReason ? form.blockedReason : blockedReason;
371
+ const price = form.canAdd && priceOnButton ? linePrice(form.unitPrice, withQuantity ? quantity : 1, locale) : null;
372
+ const describedBy = [
373
+ !form.canAdd && null !== reason && "" !== reason ? `${formId}-blocked` : null,
374
+ ...["variant", "quantities", "options"].map(
375
+ (key) => void 0 !== errors[key] ? `${formId}-${key}-error` : null
376
+ )
377
+ ].filter((id) => null !== id);
378
+ const errorKeys = Object.keys(errors);
379
+ const firstError = 0 === errorKeys.length ? null : errors[errorKeys[0]];
380
+ const actions = form.actions.map((key) => getRegistries().addToCartActions.get(key)).filter((entry) => void 0 !== entry);
381
+ return /* @__PURE__ */ jsxs2("div", { className: "ec-add-to-cart", "data-add-to-cart-row": "", children: [
382
+ offersNotify ? /* @__PURE__ */ jsx2(
383
+ NotifyMe,
384
+ {
385
+ formId,
386
+ notify,
387
+ subscribed: notifySubscribed,
388
+ error: errors.email ?? null,
389
+ data: notifyData
390
+ }
391
+ ) : /* @__PURE__ */ jsxs2("div", { className: "ec-add-to-cart__row", children: [
392
+ withQuantity ? /* @__PURE__ */ jsx2("div", { className: "ec-add-to-cart__quantity", children: /* @__PURE__ */ jsx2(
393
+ Quantity,
394
+ {
395
+ id: `${formId}-quantity`,
396
+ label: __2("Quantity"),
397
+ size: "lg",
398
+ max: form.maxQuantity,
399
+ value: quantity,
400
+ onValueChange: onQuantityChange,
401
+ error: errors.quantity ?? null,
402
+ disabled: !form.canAdd
403
+ }
404
+ ) }) : null,
405
+ /* @__PURE__ */ jsxs2(
406
+ Button2,
407
+ {
408
+ leadingIcon: "shopping-bag",
409
+ color: "primary",
410
+ size: "lg",
411
+ className: "ec-add-to-cart__button",
412
+ onClick: onAdd,
413
+ disabled: !form.canAdd || processing,
414
+ "aria-describedby": 0 === describedBy.length ? void 0 : describedBy.join(" "),
415
+ "data-add-to-cart": "",
416
+ children: [
417
+ buttonLabel ?? buttonText ?? __2("Add to cart"),
418
+ null !== price ? /* @__PURE__ */ jsxs2("span", { className: "ec-add-to-cart__price", "data-add-to-cart-price": "", children: [
419
+ " ",
420
+ /* @__PURE__ */ jsx2("span", { "aria-hidden": "true", children: "\xB7" }),
421
+ " ",
422
+ /* @__PURE__ */ jsx2("bdi", { children: price })
423
+ ] }) : null
424
+ ]
425
+ }
426
+ ),
427
+ 0 < actions.length ? /* @__PURE__ */ jsx2("div", { className: "ec-add-to-cart__actions", "data-add-to-cart-actions": "", children: actions.map(({ key, component: Action }) => /* @__PURE__ */ jsx2(Action, { ...form, formId }, key)) }) : null
428
+ ] }),
429
+ !withQuantity && void 0 !== errors.quantity ? /* @__PURE__ */ jsx2("p", { className: "ec-add-to-cart__error", "data-form-error": "", children: errors.quantity }) : null,
430
+ !form.canAdd && null !== reason && "" !== reason && !offersNotify ? /* @__PURE__ */ jsx2("p", { id: `${formId}-blocked`, className: "ec-add-to-cart__blocked", "data-add-blocked": "", children: reason }) : null,
431
+ /* @__PURE__ */ jsx2(
432
+ "p",
433
+ {
434
+ className: "apui-sr-only",
435
+ role: "status",
436
+ "aria-live": "polite",
437
+ "aria-atomic": "true",
438
+ "data-cart-announcement": "",
439
+ children: announcement
440
+ }
441
+ ),
442
+ offersNotify && void 0 !== errors.email ? /* @__PURE__ */ jsx2("p", { className: "apui-sr-only", role: "alert", "data-notify-me-error-announcement": "", children: __2("Not signed up: :reason", { reason: errors.email }) }) : null !== firstError && !offersNotify ? /* @__PURE__ */ jsx2("p", { className: "apui-sr-only", role: "alert", "data-cart-error-announcement": "", children: __2("Not added to your cart: :reason", { reason: firstError }) }) : null
443
+ ] });
444
+ }
445
+ function NotifyMe({
446
+ formId,
447
+ notify,
448
+ subscribed,
449
+ error,
450
+ data
451
+ }) {
452
+ const [email, setEmail] = useState2(notify.email);
453
+ const { post, processing } = useStorefrontPost(PURCHASE_ERROR_BAG);
454
+ const submit = (event) => {
455
+ event.preventDefault();
456
+ post(notify.url, { ...data, email, variant_id: notify.variantId }, [
457
+ "ecommerceStorefront",
458
+ "feedback",
459
+ "form"
460
+ ]);
461
+ };
462
+ return /* @__PURE__ */ jsx2(
463
+ Alert,
464
+ {
465
+ color: "neutral",
466
+ variant: "outline",
467
+ icon: subscribed ? "circle-check" : "mail",
468
+ title: notify.title,
469
+ className: "ec-notify-me",
470
+ "data-notify-me": "",
471
+ description: subscribed ? /* @__PURE__ */ jsx2("p", { className: "ec-notify-me__help", "data-notify-me-done": "", children: __2("We'll email you when it's back.") }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
472
+ /* @__PURE__ */ jsx2("p", { id: `${formId}-notify-help`, className: "ec-notify-me__help", children: __2("Leave your email and we'll tell you as soon as it's back in stock.") }),
473
+ /* @__PURE__ */ jsxs2(
474
+ "form",
475
+ {
476
+ className: "ec-notify-me__form",
477
+ onSubmit: submit,
478
+ noValidate: true,
479
+ "data-notify-me-form": "",
480
+ children: [
481
+ /* @__PURE__ */ jsx2(
482
+ Input,
483
+ {
484
+ id: `${formId}-notify-email`,
485
+ type: "email",
486
+ "aria-label": __2("Email address"),
487
+ placeholder: __2("you@example.com"),
488
+ autoComplete: "email",
489
+ className: "ec-notify-me__email",
490
+ value: email,
491
+ onValueChange: setEmail,
492
+ readonly: notify.emailLocked,
493
+ required: true,
494
+ "aria-describedby": `${formId}-notify-help`,
495
+ error: null === error ? void 0 : error
496
+ }
497
+ ),
498
+ /* @__PURE__ */ jsx2(
499
+ Button2,
500
+ {
501
+ type: "submit",
502
+ color: "neutral",
503
+ variant: "solid",
504
+ className: "ec-notify-me__button",
505
+ disabled: processing,
506
+ "data-notify-me-submit": "",
507
+ children: __2("Notify me")
508
+ }
509
+ )
510
+ ]
511
+ }
512
+ )
513
+ ] })
514
+ }
515
+ );
516
+ }
517
+
518
+ // src/product/forms/BundledForm.tsx
519
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
520
+ function BundledForm(props) {
521
+ const formId = `ec-product-${props.productId}`;
522
+ const { locale } = useStorefront();
523
+ const { buttonText = null } = usePurchaseFormContext();
524
+ const [quantity, setQuantity] = useState3(props.quantity);
525
+ const { post, processing } = useStorefrontPost(PURCHASE_ERROR_BAG);
526
+ const sets = null === quantity || quantity < 1 ? 1 : quantity;
527
+ const total = linePrice(props.total, sets, locale);
528
+ const saving = linePrice(props.saving, sets, locale);
529
+ return /* @__PURE__ */ jsxs3("div", { className: "ec-purchase-form", "data-purchase-form": "bundled", children: [
530
+ 0 < props.items.length ? /* @__PURE__ */ jsxs3("fieldset", { className: "ec-bundle-items", "data-bundle-items": "", children: [
531
+ /* @__PURE__ */ jsx3("legend", { className: "ec-bundle-items__legend", children: __3("In this set") }),
532
+ /* @__PURE__ */ jsx3("div", { className: "ec-bundle-items__list", children: props.items.map((item) => /* @__PURE__ */ jsx3(
533
+ Checkbox,
534
+ {
535
+ id: `${formId}-bundle-item-${item.id}`,
536
+ label: 1 === item.quantity ? item.name : __3(":quantity \xD7 :name", { quantity: item.quantity, name: item.name }),
537
+ description: __3("Included"),
538
+ checked: true,
539
+ disabled: true,
540
+ readOnly: true,
541
+ "data-bundle-item": item.id
542
+ },
543
+ item.id
544
+ )) })
545
+ ] }) : null,
546
+ null !== total ? /* @__PURE__ */ jsxs3("p", { className: "ec-bundle-total", "aria-live": "polite", "aria-atomic": "true", "data-bundle-total": "", children: [
547
+ /* @__PURE__ */ jsx3("span", { className: "apui-sr-only", children: __3("Total") }),
548
+ /* @__PURE__ */ jsx3("bdi", { className: "ec-bundle-total__price", children: total }),
549
+ null !== saving ? /* @__PURE__ */ jsx3(Badge2, { variant: "soft", color: "success", "data-bundle-saving": "", children: __3("You save :amount", { amount: saving }) }) : null
550
+ ] }) : null,
551
+ /* @__PURE__ */ jsx3(
552
+ AddToCart,
553
+ {
554
+ form: props,
555
+ formId,
556
+ quantity,
557
+ onQuantityChange: setQuantity,
558
+ onAdd: () => post(props.addUrl, { quantity }),
559
+ processing,
560
+ buttonLabel: buttonText ?? __3("Add set to cart"),
561
+ priceOnButton: false
562
+ }
563
+ )
564
+ ] });
565
+ }
566
+
567
+ // src/product/forms/DigitalForm.tsx
568
+ import { __ as __4 } from "@artisanpack-ui/ecommerce-storefront-core";
569
+ import { Icon as Icon2, RadioGroup } from "@artisanpack-ui/react";
570
+ import { useState as useState4 } from "react";
571
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
572
+ function DigitalForm(props) {
573
+ const formId = `ec-product-${props.productId}`;
574
+ const [quantity, setQuantity] = useState4(props.quantity);
575
+ const [licenseType, setLicenseType] = useState4(props.licenseType);
576
+ const errors = useErrorBag(PURCHASE_ERROR_BAG);
577
+ const { post, processing } = useStorefrontPost(PURCHASE_ERROR_BAG);
578
+ return /* @__PURE__ */ jsxs4("div", { className: "ec-purchase-form", "data-purchase-form": "digital", children: [
579
+ 0 < props.licenseTypes.length ? /* @__PURE__ */ jsx4(
580
+ RadioGroup,
581
+ {
582
+ id: `${formId}-license`,
583
+ label: __4("License"),
584
+ variant: "cards",
585
+ options: props.licenseTypes,
586
+ value: "" === licenseType ? null : licenseType,
587
+ required: true,
588
+ error: errors.license_type ?? void 0,
589
+ onValueChange: (value) => setLicenseType(String(value)),
590
+ "data-license-types": ""
591
+ }
592
+ ) : null,
593
+ /* @__PURE__ */ jsxs4("div", { className: "ec-digital-notes", "data-digital-notes": "", children: [
594
+ /* @__PURE__ */ jsx4(Icon2, { name: "download", className: "ec-digital-notes__icon", "aria-hidden": "true" }),
595
+ /* @__PURE__ */ jsx4("ul", { role: "list", className: "ec-digital-notes__list", children: props.notes.map((note) => /* @__PURE__ */ jsx4("li", { children: note }, note)) })
596
+ ] }),
597
+ /* @__PURE__ */ jsx4(
598
+ AddToCart,
599
+ {
600
+ form: props,
601
+ formId,
602
+ quantity,
603
+ onQuantityChange: setQuantity,
604
+ onAdd: () => post(props.addUrl, {
605
+ quantity,
606
+ ...0 < props.licenseTypes.length ? { license_type: licenseType } : {}
607
+ }),
608
+ processing
609
+ }
610
+ )
611
+ ] });
612
+ }
613
+
614
+ // src/product/forms/GroupedForm.tsx
615
+ import {
616
+ __ as __5,
617
+ formatMoney,
618
+ trans_choice
619
+ } from "@artisanpack-ui/ecommerce-storefront-core";
620
+ import { Badge as Badge3, Icon as Icon3, Input as Input2, Table } from "@artisanpack-ui/react";
621
+ import { useState as useState5 } from "react";
622
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
623
+ function groupedSummary(rows, quantities, locale) {
624
+ let count = 0;
625
+ let amount = 0;
626
+ let currency = null;
627
+ let priced = true;
628
+ for (const row of rows) {
629
+ const quantity = quantities[String(row.id)] ?? 0;
630
+ if (!row.buyable || null === quantity || quantity < 1) {
631
+ continue;
632
+ }
633
+ count += quantity;
634
+ if (null === row.unitPrice || null === row.unitPrice.amount) {
635
+ priced = false;
636
+ continue;
637
+ }
638
+ amount += row.unitPrice.amount * quantity;
639
+ currency = row.unitPrice.currency;
640
+ }
641
+ return {
642
+ count,
643
+ total: priced && null !== currency ? formatMoney(amount, currency, locale) : null
644
+ };
645
+ }
646
+ function GroupedForm(props) {
647
+ const formId = `ec-product-${props.productId}`;
648
+ const { locale } = useStorefront();
649
+ const { buttonText = null } = usePurchaseFormContext();
650
+ const errors = useErrorBag(PURCHASE_ERROR_BAG);
651
+ const [quantities, setQuantities] = useState5({});
652
+ const { post, processing } = useStorefrontPost(PURCHASE_ERROR_BAG);
653
+ const summary = groupedSummary(props.rows, quantities, locale);
654
+ if (0 === props.rows.length) {
655
+ return /* @__PURE__ */ jsx5("div", { className: "ec-purchase-form", "data-purchase-form": "grouped", children: /* @__PURE__ */ jsx5("p", { className: "ec-purchase-form__notice", children: __5("None of the products in this group are available right now.") }) });
656
+ }
657
+ return /* @__PURE__ */ jsxs5("div", { className: "ec-purchase-form", "data-purchase-form": "grouped", children: [
658
+ /* @__PURE__ */ jsx5(
659
+ Table,
660
+ {
661
+ headers: [
662
+ { key: "name", label: __5("Item") },
663
+ { key: "price", label: __5("Price"), numeric: true },
664
+ { key: "quantity", label: __5("Quantity"), numeric: true }
665
+ ],
666
+ rows: props.rows,
667
+ keyBy: "id",
668
+ label: __5("Products in this group"),
669
+ stickyHeader: false,
670
+ className: "ec-grouped-table",
671
+ "data-grouped-table": "",
672
+ renderHeader: (column) => "quantity" === column.key ? /* @__PURE__ */ jsxs5(Fragment2, { children: [
673
+ /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", children: __5("Qty") }),
674
+ /* @__PURE__ */ jsx5("span", { className: "apui-sr-only", children: column.label })
675
+ ] }) : column.label,
676
+ renderCell: (row, column) => {
677
+ if ("name" === column.key) {
678
+ return /* @__PURE__ */ jsxs5("span", { className: "ec-grouped-table__item", "data-grouped-child": row.id, children: [
679
+ /* @__PURE__ */ jsx5("span", { className: "ec-grouped-table__name", children: row.name }),
680
+ row.buyable ? null : row.stock.purchasable ? /* @__PURE__ */ jsx5(Badge3, { variant: "soft", color: "neutral", size: "sm", "data-grouped-unavailable": "", children: __5("Unavailable") }) : /* @__PURE__ */ jsx5(StockStatus, { stock: row.stock })
681
+ ] });
682
+ }
683
+ if ("price" === column.key) {
684
+ return /* @__PURE__ */ jsx5(Price, { price: row.price });
685
+ }
686
+ const id = String(row.id);
687
+ return row.buyable ? /* @__PURE__ */ jsx5(
688
+ Input2,
689
+ {
690
+ id: `${formId}-child-${row.id}`,
691
+ type: "number",
692
+ inputMode: "numeric",
693
+ min: 0,
694
+ max: props.maxQuantity,
695
+ step: 1,
696
+ placeholder: "0",
697
+ "aria-label": __5("Quantity of :name", { name: row.name }),
698
+ value: null === (quantities[id] ?? null) ? "" : String(quantities[id]),
699
+ onValueChange: (raw) => {
700
+ const number = "" === raw ? null : Number(raw);
701
+ setQuantities((current) => ({
702
+ ...current,
703
+ [id]: null === number || Number.isNaN(number) ? null : number
704
+ }));
705
+ },
706
+ error: errors[`quantities.${row.id}`] ?? void 0,
707
+ className: "ec-grouped-table__quantity",
708
+ "data-grouped-quantity": row.id
709
+ }
710
+ ) : /* @__PURE__ */ jsxs5(Fragment2, { children: [
711
+ /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", children: "\u2013" }),
712
+ /* @__PURE__ */ jsx5("span", { className: "apui-sr-only", children: __5(":name can't be added right now.", { name: row.name }) })
713
+ ] });
714
+ }
715
+ }
716
+ ),
717
+ void 0 !== errors.quantities ? /* @__PURE__ */ jsxs5("p", { id: `${formId}-quantities-error`, className: "ec-purchase-form__error", "data-form-error": "", children: [
718
+ /* @__PURE__ */ jsx5(Icon3, { name: "circle-alert", "aria-hidden": "true" }),
719
+ errors.quantities
720
+ ] }) : null,
721
+ /* @__PURE__ */ jsx5(
722
+ "p",
723
+ {
724
+ className: "ec-grouped-summary",
725
+ "aria-live": "polite",
726
+ "aria-atomic": "true",
727
+ "data-grouped-summary": "",
728
+ children: summary.count > 0 ? /* @__PURE__ */ jsxs5(Fragment2, { children: [
729
+ /* @__PURE__ */ jsx5("span", { children: trans_choice(":count item|:count items", summary.count, { count: summary.count }) }),
730
+ null !== summary.total ? /* @__PURE__ */ jsxs5(Fragment2, { children: [
731
+ /* @__PURE__ */ jsx5("span", { className: "apui-sr-only", children: "\xB7" }),
732
+ /* @__PURE__ */ jsx5("bdi", { className: "ec-grouped-summary__total", "data-grouped-total": "", children: summary.total })
733
+ ] }) : null
734
+ ] }) : null
735
+ }
736
+ ),
737
+ /* @__PURE__ */ jsx5(
738
+ AddToCart,
739
+ {
740
+ form: props,
741
+ formId,
742
+ quantity: null,
743
+ onQuantityChange: () => void 0,
744
+ onAdd: () => {
745
+ const chosen = {};
746
+ for (const [id, quantity] of Object.entries(quantities)) {
747
+ if (null !== quantity && quantity > 0) {
748
+ chosen[id] = quantity;
749
+ }
750
+ }
751
+ post(props.addUrl, { quantities: chosen });
752
+ },
753
+ processing,
754
+ showQuantity: false,
755
+ blockedReason: __5("None of these products are in stock."),
756
+ buttonLabel: buttonText ?? __5("Add selected to cart"),
757
+ priceOnButton: false
758
+ }
759
+ )
760
+ ] });
761
+ }
762
+
763
+ // src/product/forms/OptionsForm.tsx
764
+ import {
765
+ __ as __6
766
+ } from "@artisanpack-ui/ecommerce-storefront-core";
767
+ import { Icon as Icon5, RadioGroup as RadioGroup2 } from "@artisanpack-ui/react";
768
+ import { useEffect as useEffect2, useRef as useRef2, useState as useState6 } from "react";
769
+
770
+ // src/components/ChoiceCards.tsx
771
+ import { Icon as Icon4 } from "@artisanpack-ui/react";
772
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
773
+ function ChoiceCards({
774
+ name,
775
+ legend,
776
+ options,
777
+ idPrefix,
778
+ required = false,
779
+ hint = null,
780
+ error = null,
781
+ describedBy,
782
+ onValueChange,
783
+ className
784
+ }) {
785
+ const prefix = idPrefix ?? `ec-choice-${idFragment(name)}`;
786
+ const hintId = `${prefix}-hint`;
787
+ const errorId = `${prefix}-error`;
788
+ const hasHint = filled(hint);
789
+ const hasError = filled(error);
790
+ const describedByIds = [describedBy, hasHint ? hintId : null, hasError ? errorId : null].filter(filled).join(" ");
791
+ return /* @__PURE__ */ jsxs6(
792
+ "fieldset",
793
+ {
794
+ className: cx("ec-choice-cards", className),
795
+ "data-choice-cards": name,
796
+ "aria-describedby": "" !== describedByIds ? describedByIds : void 0,
797
+ "data-invalid": hasError ? "" : void 0,
798
+ tabIndex: hasError ? -1 : void 0,
799
+ children: [
800
+ /* @__PURE__ */ jsxs6("legend", { className: "ec-choice-cards__legend", children: [
801
+ legend,
802
+ required ? /* @__PURE__ */ jsx6("span", { className: "ec-choice-cards__required", "aria-hidden": "true", children: "*" }) : null
803
+ ] }),
804
+ hasHint ? /* @__PURE__ */ jsx6("p", { id: hintId, className: "ec-choice-cards__hint", children: hint }) : null,
805
+ /* @__PURE__ */ jsx6("div", { className: "ec-choice-cards__options", children: options.map((option, index) => {
806
+ const inputId = `${prefix}-${index}`;
807
+ const note = option.reason ?? option.hint;
808
+ const noteId = null !== note ? `${inputId}-note` : void 0;
809
+ return /* @__PURE__ */ jsxs6(
810
+ "label",
811
+ {
812
+ htmlFor: inputId,
813
+ className: "ec-choice-card",
814
+ "data-choice-card": option.value,
815
+ children: [
816
+ /* @__PURE__ */ jsx6(
817
+ "input",
818
+ {
819
+ id: inputId,
820
+ type: "radio",
821
+ name,
822
+ value: option.value,
823
+ className: "ec-choice-card__input",
824
+ checked: option.selected,
825
+ disabled: option.disabled,
826
+ required: required ? true : void 0,
827
+ "aria-invalid": hasError ? "true" : void 0,
828
+ "aria-describedby": noteId,
829
+ onChange: () => onValueChange?.(option.value)
830
+ }
831
+ ),
832
+ null !== option.image ? /* @__PURE__ */ jsx6(
833
+ "img",
834
+ {
835
+ src: option.image.url,
836
+ srcSet: option.image.srcset ?? void 0,
837
+ sizes: null !== option.image.srcset ? "48px" : void 0,
838
+ alt: option.image.alt,
839
+ className: "ec-choice-card__image",
840
+ width: 48,
841
+ height: 48,
842
+ loading: "lazy",
843
+ decoding: "async"
844
+ }
845
+ ) : null,
846
+ /* @__PURE__ */ jsxs6("span", { className: "ec-choice-card__text", children: [
847
+ /* @__PURE__ */ jsx6("span", { className: "ec-choice-card__label", children: option.label }),
848
+ void 0 !== noteId ? /* @__PURE__ */ jsx6("span", { id: noteId, className: "ec-choice-card__hint", children: note }) : null
849
+ ] }),
850
+ null !== option.meta ? /* @__PURE__ */ jsx6("span", { className: "ec-choice-card__meta", "data-choice-card-meta": "", children: /* @__PURE__ */ jsx6("bdi", { children: option.meta }) }) : null,
851
+ /* @__PURE__ */ jsx6(Icon4, { name: "check", className: "ec-choice-card__check", "aria-hidden": "true" })
852
+ ]
853
+ },
854
+ inputId
855
+ );
856
+ }) }),
857
+ hasError ? /* @__PURE__ */ jsxs6("p", { id: errorId, className: "ec-choice-cards__error", "data-choice-cards-error": "", children: [
858
+ /* @__PURE__ */ jsx6(Icon4, { name: "circle-alert", "aria-hidden": "true" }),
859
+ error
860
+ ] }) : null
861
+ ]
862
+ }
863
+ );
864
+ }
865
+
866
+ // src/product/forms/OptionsForm.tsx
867
+ import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
868
+ function optionValue(values, name) {
869
+ if (name in values) {
870
+ return values[name];
871
+ }
872
+ let current = values;
873
+ for (const segment of name.split(".")) {
874
+ if (null === current || "object" !== typeof current) {
875
+ return void 0;
876
+ }
877
+ current = current[segment];
878
+ }
879
+ return current;
880
+ }
881
+ function withOptionValue(values, name, value) {
882
+ const segments = name.split(".");
883
+ const copy = { ...values };
884
+ let target = copy;
885
+ segments.forEach((segment, index) => {
886
+ if (index === segments.length - 1) {
887
+ target[segment] = value;
888
+ return;
889
+ }
890
+ const next = target[segment];
891
+ const child = null !== next && "object" === typeof next ? { ...next } : {};
892
+ target[segment] = child;
893
+ target = child;
894
+ });
895
+ return copy;
896
+ }
897
+ function nested(values) {
898
+ return Object.entries(values).reduce(
899
+ (result, [name, value]) => withOptionValue(result, name, value),
900
+ {}
901
+ );
902
+ }
903
+ function codePoints(value) {
904
+ return [...String(value ?? "")].length;
905
+ }
906
+ function swatchLook(swatch) {
907
+ const color = null !== swatch && /^#[0-9a-f]{3,8}$/i.test(swatch) ? swatch : null;
908
+ return { color, image: null === color ? swatch : null };
909
+ }
910
+ function OptionsForm(props) {
911
+ const formId = `ec-product-${props.productId}`;
912
+ const [form, setForm] = useState6(props);
913
+ const [source, setSource] = useState6(props);
914
+ const [values, setValues] = useState6(() => nested(props.values));
915
+ const [quantity, setQuantity] = useState6(props.quantity);
916
+ const [refreshing, setRefreshing] = useState6(false);
917
+ const errors = useErrorBag(PURCHASE_ERROR_BAG);
918
+ const { post, processing } = useStorefrontPost(PURCHASE_ERROR_BAG);
919
+ const pending = useRef2(null);
920
+ const latestValues = useRef2(values);
921
+ const editedDuringRedraw = useRef2(/* @__PURE__ */ new Set());
922
+ useEffect2(() => {
923
+ latestValues.current = values;
924
+ }, [values]);
925
+ if (source !== props) {
926
+ setSource(props);
927
+ setForm(props);
928
+ setValues(nested(props.values));
929
+ }
930
+ const redraw = async (next) => {
931
+ if (!form.reactive) {
932
+ return;
933
+ }
934
+ pending.current?.abort();
935
+ const controller = new AbortController();
936
+ pending.current = controller;
937
+ editedDuringRedraw.current = /* @__PURE__ */ new Set();
938
+ setRefreshing(true);
939
+ const answer = await requestJson(
940
+ form.optionsUrl,
941
+ { options: next },
942
+ controller.signal
943
+ );
944
+ if (pending.current !== controller) {
945
+ return;
946
+ }
947
+ setRefreshing(false);
948
+ if (null !== answer) {
949
+ const redrawn = answer.props;
950
+ let merged = nested(redrawn.values);
951
+ for (const name of editedDuringRedraw.current) {
952
+ merged = withOptionValue(merged, name, optionValue(latestValues.current, name));
953
+ }
954
+ setForm({ ...redrawn, showQuantity: props.showQuantity && redrawn.showQuantity });
955
+ setValues(merged);
956
+ }
957
+ pending.current = null;
958
+ editedDuringRedraw.current = /* @__PURE__ */ new Set();
959
+ };
960
+ const change = (name, value, refresh = true) => {
961
+ const next = withOptionValue(latestValues.current, name, value);
962
+ if (null !== pending.current) {
963
+ editedDuringRedraw.current.add(name);
964
+ }
965
+ latestValues.current = next;
966
+ setValues(next);
967
+ if (refresh) {
968
+ void redraw(next);
969
+ }
970
+ return next;
971
+ };
972
+ const renderField = (field) => {
973
+ const key = `options.${field.name}`;
974
+ const error = errors[key] ?? null;
975
+ const value = optionValue(values, field.name);
976
+ const countId = null === field.maxLength ? void 0 : `${field.id}-count`;
977
+ switch (field.type) {
978
+ case "info": {
979
+ const items = field.meta.items;
980
+ return /* @__PURE__ */ jsxs7("div", { className: "ec-option-info", children: [
981
+ /* @__PURE__ */ jsx7("p", { className: "ec-option-info__label", children: field.label }),
982
+ Array.isArray(items) ? /* @__PURE__ */ jsx7("ul", { role: "list", className: "ec-option-info__list", children: items.map((item, index) => /* @__PURE__ */ jsx7("li", { children: __6(":quantity \xD7 :name", {
983
+ quantity: Number(item.quantity ?? 1),
984
+ name: String(item.name ?? "")
985
+ }) }, index)) }) : null,
986
+ null !== field.help ? /* @__PURE__ */ jsx7("p", { className: "ec-option-info__help", children: field.help }) : null
987
+ ] });
988
+ }
989
+ case "quantity":
990
+ return /* @__PURE__ */ jsx7(
991
+ Quantity,
992
+ {
993
+ id: field.id,
994
+ label: field.label,
995
+ min: 0,
996
+ itemName: field.label,
997
+ required: field.required,
998
+ value: null === value || void 0 === value || "" === value ? null : Number(value),
999
+ onValueChange: (next) => change(field.name, next),
1000
+ error
1001
+ }
1002
+ );
1003
+ case "textarea":
1004
+ return /* @__PURE__ */ jsx7(
1005
+ Field,
1006
+ {
1007
+ control: "textarea",
1008
+ id: field.id,
1009
+ label: field.label,
1010
+ hint: field.help,
1011
+ errorKey: key,
1012
+ value: String(value ?? ""),
1013
+ required: field.required,
1014
+ error,
1015
+ attributes: void 0 === countId ? {} : { "aria-describedby": countId },
1016
+ onValueChange: (next) => change(field.name, limit(next, field.maxLength), false),
1017
+ onBlur: () => void redraw(values)
1018
+ }
1019
+ );
1020
+ case "select":
1021
+ return /* @__PURE__ */ jsx7(
1022
+ Field,
1023
+ {
1024
+ control: "select",
1025
+ id: field.id,
1026
+ label: field.label,
1027
+ hint: field.help,
1028
+ errorKey: key,
1029
+ options: field.options.map((option) => ({
1030
+ value: option.value,
1031
+ label: [
1032
+ null === option.delta ? option.label : __6(":choice \xB7 :delta", { choice: option.label, delta: option.delta }),
1033
+ null === option.reason ? null : __6("(:reason)", { reason: option.reason })
1034
+ ].filter((part) => null !== part).join(" "),
1035
+ ...option.disabled ? { disabled: true } : {}
1036
+ })),
1037
+ placeholder: __6("Choose\u2026"),
1038
+ value: String(value ?? ""),
1039
+ required: field.required,
1040
+ error,
1041
+ onValueChange: (next) => change(field.name, next)
1042
+ }
1043
+ );
1044
+ case "radio":
1045
+ return field.cards ? /* @__PURE__ */ jsx7(
1046
+ ChoiceCards,
1047
+ {
1048
+ name: field.id,
1049
+ idPrefix: field.id,
1050
+ legend: field.label,
1051
+ hint: field.help,
1052
+ options: field.options.map((option) => ({
1053
+ value: option.value,
1054
+ label: option.label,
1055
+ hint: option.hint,
1056
+ meta: option.delta,
1057
+ image: option.image,
1058
+ selected: String(value ?? "") === option.value,
1059
+ disabled: option.disabled,
1060
+ reason: option.reason
1061
+ })),
1062
+ required: field.required,
1063
+ error,
1064
+ onValueChange: (next) => change(field.name, next)
1065
+ }
1066
+ ) : /* @__PURE__ */ jsx7(
1067
+ RadioGroup2,
1068
+ {
1069
+ id: field.id,
1070
+ label: field.label,
1071
+ hint: field.help ?? void 0,
1072
+ options: field.options.map((option) => ({
1073
+ value: option.value,
1074
+ label: option.label,
1075
+ ...null !== (option.reason ?? option.hint) ? { description: option.reason ?? option.hint } : {},
1076
+ ...null !== option.delta ? { meta: option.delta } : {},
1077
+ disabled: option.disabled
1078
+ })),
1079
+ required: field.required,
1080
+ value: void 0 === value || null === value ? null : String(value),
1081
+ error: error ?? void 0,
1082
+ onValueChange: (next) => change(field.name, String(next))
1083
+ }
1084
+ );
1085
+ case "swatch":
1086
+ return /* @__PURE__ */ jsxs7(Fragment3, { children: [
1087
+ /* @__PURE__ */ jsx7(
1088
+ Swatches,
1089
+ {
1090
+ name: field.id,
1091
+ idPrefix: field.id,
1092
+ legend: field.label,
1093
+ options: field.options.map((option) => ({
1094
+ value: option.value,
1095
+ label: option.label,
1096
+ ...swatchLook(option.swatch),
1097
+ count: null,
1098
+ meta: option.delta,
1099
+ selected: String(value ?? "") === option.value,
1100
+ disabled: option.disabled,
1101
+ soldOut: false,
1102
+ reason: option.reason ?? option.hint
1103
+ })),
1104
+ required: field.required,
1105
+ error,
1106
+ describedBy: null === field.help ? void 0 : `${field.id}-help`,
1107
+ onValueChange: (next) => change(field.name, next)
1108
+ }
1109
+ ),
1110
+ null !== field.help ? /* @__PURE__ */ jsx7("p", { id: `${field.id}-help`, className: "ec-option-field__help", children: field.help }) : null
1111
+ ] });
1112
+ case "checkbox":
1113
+ return /* @__PURE__ */ jsx7(
1114
+ Field,
1115
+ {
1116
+ control: "checkbox",
1117
+ id: field.id,
1118
+ label: field.label,
1119
+ hint: field.help,
1120
+ errorKey: key,
1121
+ checked: true === value || "1" === value || 1 === value,
1122
+ required: field.required,
1123
+ error,
1124
+ onCheckedChange: (next) => change(field.name, next)
1125
+ }
1126
+ );
1127
+ default:
1128
+ return /* @__PURE__ */ jsx7(
1129
+ Field,
1130
+ {
1131
+ id: field.id,
1132
+ label: field.label,
1133
+ hint: field.help,
1134
+ type: "number" === field.type ? "number" : "text",
1135
+ errorKey: key,
1136
+ value: String(value ?? ""),
1137
+ required: field.required,
1138
+ error,
1139
+ attributes: void 0 === countId ? {} : { "aria-describedby": countId },
1140
+ onValueChange: (next) => change(field.name, limit(next, field.maxLength), false),
1141
+ onBlur: () => void redraw(values)
1142
+ }
1143
+ );
1144
+ }
1145
+ };
1146
+ return /* @__PURE__ */ jsxs7("div", { className: "ec-purchase-form", "data-purchase-form": "options", children: [
1147
+ form.fields.map((field) => /* @__PURE__ */ jsxs7("div", { className: "ec-option-field", "data-option-field": field.name, children: [
1148
+ renderField(field),
1149
+ null !== field.maxLength ? /* @__PURE__ */ jsx7("p", { id: `${field.id}-count`, className: "ec-option-field__count", "data-character-count": "", children: __6(":count of :max characters", {
1150
+ count: Math.min(codePoints(optionValue(values, field.name)), field.maxLength),
1151
+ max: field.maxLength
1152
+ }) }) : null
1153
+ ] }, field.id)),
1154
+ form.showsQuote ? /* @__PURE__ */ jsxs7("p", { className: "ec-option-price", "data-quoted-price": "", children: [
1155
+ /* @__PURE__ */ jsx7("span", { role: "status", "aria-live": "polite", "aria-atomic": "true", "data-quoted-price-value": "", children: null !== form.quotedPrice ? /* @__PURE__ */ jsxs7(Fragment3, { children: [
1156
+ /* @__PURE__ */ jsx7("strong", { className: "ec-option-price__amount", children: /* @__PURE__ */ jsx7("bdi", { children: form.quotedPrice }) }),
1157
+ " ",
1158
+ __6("including options")
1159
+ ] }) : null }),
1160
+ refreshing ? /* @__PURE__ */ jsx7("span", { className: "ec-option-price__loading", "data-quoted-price-loading": "", children: __6("Updating price\u2026") }) : null
1161
+ ] }) : null,
1162
+ void 0 !== errors.options ? /* @__PURE__ */ jsxs7("p", { id: `${formId}-options-error`, className: "ec-purchase-form__error", "data-form-error": "", children: [
1163
+ /* @__PURE__ */ jsx7(Icon5, { name: "circle-alert", "aria-hidden": "true" }),
1164
+ errors.options
1165
+ ] }) : null,
1166
+ /* @__PURE__ */ jsx7(
1167
+ AddToCart,
1168
+ {
1169
+ form,
1170
+ formId,
1171
+ quantity,
1172
+ onQuantityChange: setQuantity,
1173
+ onAdd: () => post(form.addUrl, { quantity, options: values }),
1174
+ processing,
1175
+ showQuantity: form.showQuantity && !form.separately
1176
+ }
1177
+ )
1178
+ ] });
1179
+ }
1180
+ function limit(value, max) {
1181
+ if (null === max) {
1182
+ return value;
1183
+ }
1184
+ const characters = [...value];
1185
+ return characters.length > max ? characters.slice(0, max).join("") : value;
1186
+ }
1187
+
1188
+ // src/product/forms/SimpleForm.tsx
1189
+ import { useState as useState7 } from "react";
1190
+ import { jsx as jsx8 } from "react/jsx-runtime";
1191
+ function SimpleForm(props) {
1192
+ const formId = `ec-product-${props.productId}`;
1193
+ const [quantity, setQuantity] = useState7(props.quantity);
1194
+ const { post, processing } = useStorefrontPost(PURCHASE_ERROR_BAG);
1195
+ return /* @__PURE__ */ jsx8("div", { className: "ec-purchase-form", "data-purchase-form": "simple", children: /* @__PURE__ */ jsx8(
1196
+ AddToCart,
1197
+ {
1198
+ form: props,
1199
+ formId,
1200
+ quantity,
1201
+ onQuantityChange: setQuantity,
1202
+ onAdd: () => post(props.addUrl, { quantity }),
1203
+ processing
1204
+ }
1205
+ ) });
1206
+ }
1207
+
1208
+ // src/product/forms/VariableForm.tsx
1209
+ import { __ as __7 } from "@artisanpack-ui/ecommerce-storefront-core";
1210
+ import { Icon as Icon6, Select } from "@artisanpack-ui/react";
1211
+ import { useRef as useRef3, useState as useState8 } from "react";
1212
+ import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
1213
+ var VARIANT_RELOAD = ["variantId", "product", "gallery", "price", "stock", "soldOut"];
1214
+ function swatchOption(option) {
1215
+ const swatch = option.swatch;
1216
+ const color = null !== swatch && /^#[0-9a-f]{3,8}$/i.test(swatch) ? swatch : null;
1217
+ return {
1218
+ value: option.value,
1219
+ label: option.label,
1220
+ color,
1221
+ image: null === color ? swatch : null,
1222
+ count: null,
1223
+ meta: null,
1224
+ selected: option.selected,
1225
+ disabled: option.disabled,
1226
+ soldOut: option.soldOut,
1227
+ reason: option.reason
1228
+ };
1229
+ }
1230
+ function VariableForm(props) {
1231
+ const formId = `ec-product-${props.productId}`;
1232
+ const [form, setForm] = useState8(props);
1233
+ const [source, setSource] = useState8(props);
1234
+ const [quantity, setQuantity] = useState8(props.quantity);
1235
+ const { productUrl, variantId } = usePurchaseFormContext();
1236
+ const errors = useErrorBag(PURCHASE_ERROR_BAG);
1237
+ const { post, processing } = useStorefrontPost(PURCHASE_ERROR_BAG);
1238
+ const visits = useStorefrontRouter();
1239
+ const variantError = errors.variant;
1240
+ const pendingSelection = useRef3(null);
1241
+ const pendingRequest = useRef3(null);
1242
+ if (source !== props) {
1243
+ setSource(props);
1244
+ setForm(props);
1245
+ }
1246
+ const choose = async (groupId, value) => {
1247
+ const selected = { ...pendingSelection.current ?? form.selected };
1248
+ if ("" === value) {
1249
+ delete selected[String(groupId)];
1250
+ } else {
1251
+ selected[String(groupId)] = Number(value);
1252
+ }
1253
+ pendingSelection.current = selected;
1254
+ pendingRequest.current?.abort();
1255
+ const controller = new AbortController();
1256
+ pendingRequest.current = controller;
1257
+ const redraw = await requestJson(
1258
+ form.optionsUrl,
1259
+ { selected, changed: groupId },
1260
+ controller.signal
1261
+ );
1262
+ if (pendingRequest.current !== controller) {
1263
+ return;
1264
+ }
1265
+ pendingRequest.current = null;
1266
+ pendingSelection.current = null;
1267
+ if (null === redraw) {
1268
+ return;
1269
+ }
1270
+ const next = redraw.props;
1271
+ setForm({ ...next, showQuantity: props.showQuantity && next.showQuantity });
1272
+ if (null !== productUrl && next.variantId !== variantId) {
1273
+ visits.get(productUrl, null === next.variantId ? {} : { variant: next.variantId }, {
1274
+ only: VARIANT_RELOAD,
1275
+ preserveScroll: true,
1276
+ preserveState: true,
1277
+ replace: true
1278
+ });
1279
+ }
1280
+ };
1281
+ return /* @__PURE__ */ jsxs8("div", { className: "ec-purchase-form", "data-purchase-form": "variable", children: [
1282
+ form.groups.map((group) => {
1283
+ const groupId = `${formId}-attribute-${group.id}`;
1284
+ const groupError = errors[`selected.${group.id}`] ?? null;
1285
+ const describedBy = void 0 !== variantError ? `${formId}-variant-error` : void 0;
1286
+ if ("select" === group.control) {
1287
+ const chosen = group.options.find((option) => option.selected);
1288
+ return /* @__PURE__ */ jsx9(
1289
+ "div",
1290
+ {
1291
+ className: "ec-purchase-form__select",
1292
+ "data-variation-group": group.id,
1293
+ children: /* @__PURE__ */ jsx9(
1294
+ Select,
1295
+ {
1296
+ id: groupId,
1297
+ label: group.label,
1298
+ options: group.options.map((option) => ({
1299
+ value: option.value,
1300
+ label: null === option.reason ? option.label : __7(":value (:reason)", { value: option.label, reason: option.reason }),
1301
+ disabled: option.disabled
1302
+ })),
1303
+ value: chosen?.value ?? "",
1304
+ placeholder: group.placeholder,
1305
+ error: null === groupError ? void 0 : groupError,
1306
+ required: true,
1307
+ "aria-describedby": describedBy,
1308
+ onValueChange: (value) => void choose(group.id, String(value))
1309
+ }
1310
+ )
1311
+ },
1312
+ group.id
1313
+ );
1314
+ }
1315
+ return /* @__PURE__ */ jsx9(
1316
+ Swatches,
1317
+ {
1318
+ name: groupId,
1319
+ legend: group.label,
1320
+ options: group.options.map(swatchOption),
1321
+ idPrefix: groupId,
1322
+ error: groupError,
1323
+ required: true,
1324
+ describedBy,
1325
+ onValueChange: (value) => void choose(group.id, value)
1326
+ },
1327
+ group.id
1328
+ );
1329
+ }),
1330
+ /* @__PURE__ */ jsx9(
1331
+ "p",
1332
+ {
1333
+ className: cx(
1334
+ "ec-purchase-form__notice",
1335
+ null === form.selectionNotice || "" === form.selectionNotice ? "apui-sr-only" : null
1336
+ ),
1337
+ role: "status",
1338
+ "aria-live": "polite",
1339
+ "aria-atomic": "true",
1340
+ "data-selection-notice": "",
1341
+ children: form.selectionNotice
1342
+ }
1343
+ ),
1344
+ void 0 !== variantError ? /* @__PURE__ */ jsxs8("p", { id: `${formId}-variant-error`, className: "ec-purchase-form__error", "data-variant-error": "", children: [
1345
+ /* @__PURE__ */ jsx9(Icon6, { name: "circle-alert", "aria-hidden": "true" }),
1346
+ variantError
1347
+ ] }) : null,
1348
+ /* @__PURE__ */ jsx9(
1349
+ AddToCart,
1350
+ {
1351
+ form,
1352
+ formId,
1353
+ quantity,
1354
+ onQuantityChange: setQuantity,
1355
+ onAdd: () => post(form.addUrl, { quantity, selected: form.selected, variant_id: form.variantId }),
1356
+ processing,
1357
+ notifyData: { selected: form.selected }
1358
+ }
1359
+ )
1360
+ ] });
1361
+ }
1362
+
1363
+ // src/product/forms/registerProductForms.ts
1364
+ var CORE_PRODUCT_FORMS = {
1365
+ simple: SimpleForm,
1366
+ variable: VariableForm,
1367
+ grouped: GroupedForm,
1368
+ bundled: BundledForm,
1369
+ digital: DigitalForm,
1370
+ options: OptionsForm
1371
+ };
1372
+ function registerProductForms(registries) {
1373
+ Object.entries(CORE_PRODUCT_FORMS).forEach(([key, component], index) => {
1374
+ registries.productForms.register(key, component, { position: (index + 1) * 10 });
1375
+ });
1376
+ }
1377
+
1378
+ // src/product/sections/RecentlyViewed.tsx
1379
+ import { __ as __8 } from "@artisanpack-ui/ecommerce-storefront-core";
1380
+ import { Icon as Icon7, Skeleton as Bone } from "@artisanpack-ui/react";
1381
+ import { useEffect as useEffect3, useId as useId2, useState as useState9 } from "react";
1382
+ import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
1383
+ function RecentlyViewed({
1384
+ data = null,
1385
+ url = null,
1386
+ productId = null,
1387
+ limit: limit2 = null,
1388
+ columns = null,
1389
+ heading = null,
1390
+ refresh = false
1391
+ }) {
1392
+ const { routes } = useStorefront();
1393
+ const route = url ?? (null === routes.storefront.base ? null : `${routes.storefront.base.replace(/\/$/, "")}/recently-viewed`);
1394
+ const target = (null === data || refresh) && null !== route ? recentlyViewedUrl(route, { product: productId, limit: limit2, columns, heading }) : null;
1395
+ const [fetched, setFetched] = useState9(null);
1396
+ useEffect3(() => {
1397
+ if (null === target) {
1398
+ return;
1399
+ }
1400
+ const controller = new AbortController();
1401
+ void requestJson(target, void 0, controller.signal).then(
1402
+ (answer) => {
1403
+ if (!controller.signal.aborted) {
1404
+ setFetched({ url: target, row: answer });
1405
+ }
1406
+ }
1407
+ );
1408
+ return () => controller.abort();
1409
+ }, [target]);
1410
+ const loaded = null !== data ? null !== target && fetched?.url === target && null !== fetched.row ? fetched.row : data : null === target ? null : fetched?.url === target ? fetched.row : void 0;
1411
+ if (void 0 === loaded) {
1412
+ return /* @__PURE__ */ jsx10(
1413
+ RecentlyViewedPlaceholder,
1414
+ {
1415
+ title: null !== heading && "" !== heading.trim() ? heading : __8("Recently viewed"),
1416
+ count: limit2 ?? 4,
1417
+ columns: columns ?? 4
1418
+ }
1419
+ );
1420
+ }
1421
+ return /* @__PURE__ */ jsx10(RecentlyViewedRow, { row: loaded });
1422
+ }
1423
+ function recentlyViewedUrl(route, query) {
1424
+ const base = "undefined" !== typeof window ? window.location.origin : "http://localhost";
1425
+ const target = new URL(route, base);
1426
+ for (const [key, value] of Object.entries(query)) {
1427
+ if (null !== value && "" !== value) {
1428
+ target.searchParams.set(key, String(value));
1429
+ }
1430
+ }
1431
+ return target.toString();
1432
+ }
1433
+ function RecentlyViewedRow({ row }) {
1434
+ const headingId = `ec-recently-viewed-${useId2().replace(/[^A-Za-z0-9_-]/g, "")}`;
1435
+ return /* @__PURE__ */ jsx10("div", { "data-recently-viewed": "", children: null !== row && row.products.length > 0 ? /* @__PURE__ */ jsxs9("section", { className: "ec-recent", "aria-labelledby": headingId, children: [
1436
+ /* @__PURE__ */ jsx10("h2", { id: headingId, className: "ec-recent__title", children: row.title }),
1437
+ /* @__PURE__ */ jsx10("ul", { role: "list", className: "ec-recent__list", "data-columns": row.columns, children: row.products.map((product) => /* @__PURE__ */ jsx10("li", { className: "ec-recent__item", children: /* @__PURE__ */ jsxs9(
1438
+ "article",
1439
+ {
1440
+ className: "apui-card ec-recent__card",
1441
+ "data-surface": "default",
1442
+ "data-interactive": null !== product.url ? "" : void 0,
1443
+ "data-recently-viewed-product": product.id,
1444
+ children: [
1445
+ /* @__PURE__ */ jsx10("div", { className: "ec-recent__media", "aria-hidden": "true", children: null !== product.image ? /* @__PURE__ */ jsx10(
1446
+ "img",
1447
+ {
1448
+ src: product.image.url,
1449
+ srcSet: product.image.srcset ?? void 0,
1450
+ sizes: null !== product.image.srcset ? "64px" : void 0,
1451
+ width: 64,
1452
+ height: 64,
1453
+ alt: "",
1454
+ loading: "lazy",
1455
+ decoding: "async"
1456
+ }
1457
+ ) : /* @__PURE__ */ jsx10(Icon7, { name: "image" }) }),
1458
+ /* @__PURE__ */ jsxs9("div", { className: "ec-recent__body", children: [
1459
+ /* @__PURE__ */ jsx10("h3", { className: "ec-recent__name", children: null !== product.url ? /* @__PURE__ */ jsx10("a", { href: product.url, "data-product-link": "", children: product.name }) : product.name }),
1460
+ null !== product.price ? /* @__PURE__ */ jsx10(
1461
+ Price,
1462
+ {
1463
+ price: product.price,
1464
+ saleBadge: false,
1465
+ showTax: false,
1466
+ size: "sm",
1467
+ className: "ec-recent__price"
1468
+ }
1469
+ ) : null
1470
+ ] })
1471
+ ]
1472
+ }
1473
+ ) }, product.id)) })
1474
+ ] }) : null });
1475
+ }
1476
+ function RecentlyViewedPlaceholder({
1477
+ title,
1478
+ count = 4,
1479
+ columns = 4
1480
+ }) {
1481
+ const cards = Math.max(1, Math.min(12, Math.trunc(count)));
1482
+ return /* @__PURE__ */ jsx10("div", { "data-recently-viewed-placeholder": "", children: /* @__PURE__ */ jsxs9("section", { className: "ec-recent", children: [
1483
+ /* @__PURE__ */ jsx10("h2", { className: "ec-recent__title", children: title }),
1484
+ /* @__PURE__ */ jsx10("span", { className: "apui-sr-only", role: "status", children: __8("Loading recently viewed products\u2026") }),
1485
+ /* @__PURE__ */ jsx10(
1486
+ "ul",
1487
+ {
1488
+ className: "ec-recent__list",
1489
+ "data-columns": Math.max(1, Math.min(6, Math.trunc(columns))),
1490
+ "aria-busy": "true",
1491
+ "aria-hidden": "true",
1492
+ "data-skeleton": "recent",
1493
+ children: Array.from({ length: cards }, (_, index) => /* @__PURE__ */ jsx10("li", { className: "ec-recent__item", children: /* @__PURE__ */ jsxs9("div", { className: "apui-card ec-recent__card", "data-surface": "default", children: [
1494
+ /* @__PURE__ */ jsx10(Bone, { className: "ec-recent__skeleton-thumb" }),
1495
+ /* @__PURE__ */ jsxs9("div", { className: "ec-recent__body ec-recent__body--skeleton", children: [
1496
+ /* @__PURE__ */ jsx10(Bone, { shape: "text", className: "ec-recent__skeleton-line", "data-length": "long" }),
1497
+ /* @__PURE__ */ jsx10(Bone, { shape: "text", className: "ec-recent__skeleton-line", "data-length": "short" })
1498
+ ] })
1499
+ ] }) }, index))
1500
+ }
1501
+ )
1502
+ ] }) });
1503
+ }
1504
+
1505
+ // src/product/sections/Reviews.tsx
1506
+ import {
1507
+ __ as __10,
1508
+ trans_choice as trans_choice3
1509
+ } from "@artisanpack-ui/ecommerce-storefront-core";
1510
+ import {
1511
+ Alert as Alert2,
1512
+ Badge as Badge4,
1513
+ Button as Button3,
1514
+ Card,
1515
+ Icon as Icon8,
1516
+ Link,
1517
+ Pagination,
1518
+ Progress,
1519
+ Rating,
1520
+ ValidationSummary
1521
+ } from "@artisanpack-ui/react";
1522
+ import { useEffect as useEffect4, useRef as useRef4, useState as useState11 } from "react";
1523
+
1524
+ // src/components/RatingInput.tsx
1525
+ import {
1526
+ __ as __9,
1527
+ trans_choice as trans_choice2
1528
+ } from "@artisanpack-ui/ecommerce-storefront-core";
1529
+ import { useState as useState10 } from "react";
1530
+
1531
+ // src/internal/icon.tsx
1532
+ import { ICON_SVG_ATTRIBUTES, resolveIcon } from "@artisanpack-ui/behavior/icons";
1533
+ import { jsx as jsx11 } from "react/jsx-runtime";
1534
+ var SVG_PROPS = Object.fromEntries(
1535
+ Object.entries(ICON_SVG_ATTRIBUTES).map(([name, value]) => [
1536
+ name.startsWith("aria-") ? name : name.replace(/-([a-z])/g, (_, char) => char.toUpperCase()),
1537
+ value
1538
+ ])
1539
+ );
1540
+ function IconSvg({ name }) {
1541
+ const body = resolveIcon(name);
1542
+ if (void 0 === body) {
1543
+ return null;
1544
+ }
1545
+ return /* @__PURE__ */ jsx11("svg", { ...SVG_PROPS, dangerouslySetInnerHTML: { __html: body } });
1546
+ }
1547
+
1548
+ // src/components/RatingInput.tsx
1549
+ import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
1550
+ var STARS = [1, 2, 3, 4, 5];
1551
+ function RatingInput({
1552
+ id,
1553
+ label = null,
1554
+ error = null,
1555
+ required = false,
1556
+ value,
1557
+ onValueChange,
1558
+ className
1559
+ }) {
1560
+ const [preview, setPreview] = useState10(0);
1561
+ const hasError = filled(error);
1562
+ const shown = preview || value;
1563
+ return /* @__PURE__ */ jsxs10(
1564
+ "fieldset",
1565
+ {
1566
+ className: cx("apui-radio-group ec-rating-input", className),
1567
+ id,
1568
+ role: "radiogroup",
1569
+ "aria-required": required ? "true" : void 0,
1570
+ "data-invalid": hasError ? "" : void 0,
1571
+ "aria-describedby": hasError ? `${id}-error` : void 0,
1572
+ "data-rating-input": id,
1573
+ children: [
1574
+ /* @__PURE__ */ jsxs10("legend", { "data-scope": "radio-group", "data-part": "label", children: [
1575
+ label ?? __9("Rating"),
1576
+ required ? /* @__PURE__ */ jsx12("span", { "data-scope": "radio-group", "data-part": "required", "aria-hidden": "true", children: "*" }) : null
1577
+ ] }),
1578
+ /* @__PURE__ */ jsxs10("div", { className: "ec-rating-input__row", children: [
1579
+ /* @__PURE__ */ jsx12(
1580
+ "div",
1581
+ {
1582
+ className: "apui-rating ec-rating-input__stars",
1583
+ "data-size": "lg",
1584
+ "data-interactive": "",
1585
+ onMouseLeave: () => setPreview(0),
1586
+ children: STARS.map((star) => /* @__PURE__ */ jsxs10(
1587
+ "label",
1588
+ {
1589
+ "data-scope": "rating",
1590
+ "data-part": "item",
1591
+ onMouseEnter: () => setPreview(star),
1592
+ children: [
1593
+ /* @__PURE__ */ jsx12(
1594
+ "input",
1595
+ {
1596
+ type: "radio",
1597
+ "data-scope": "rating",
1598
+ "data-part": "control",
1599
+ id: `${id}-${star}`,
1600
+ name: id,
1601
+ value: star,
1602
+ checked: value === star,
1603
+ onChange: () => onValueChange(star),
1604
+ "aria-label": trans_choice2(":count star|:count stars", star, { count: star }),
1605
+ required: required && 1 === star ? true : void 0,
1606
+ "aria-invalid": hasError ? "true" : void 0
1607
+ }
1608
+ ),
1609
+ /* @__PURE__ */ jsx12("span", { "data-scope": "rating", "data-part": "star", "aria-hidden": "true", children: /* @__PURE__ */ jsx12(IconSvg, { name: "star" }) })
1610
+ ]
1611
+ },
1612
+ star
1613
+ ))
1614
+ }
1615
+ ),
1616
+ /* @__PURE__ */ jsx12(
1617
+ "span",
1618
+ {
1619
+ className: "ec-rating-input__value",
1620
+ "aria-hidden": "true",
1621
+ hidden: shown <= 0,
1622
+ "data-rating-input-value": "",
1623
+ children: shown > 0 ? __9(":rating of 5", { rating: shown }) : null
1624
+ }
1625
+ )
1626
+ ] }),
1627
+ hasError ? /* @__PURE__ */ jsxs10("p", { "data-scope": "radio-group", "data-part": "error", id: `${id}-error`, "data-rating-input-error": "", children: [
1628
+ /* @__PURE__ */ jsx12(IconSvg, { name: "circle-alert" }),
1629
+ error
1630
+ ] }) : null
1631
+ ]
1632
+ }
1633
+ );
1634
+ }
1635
+
1636
+ // src/product/sections/Reviews.tsx
1637
+ import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
1638
+ var REVIEW_RATING_QUERY = "review-rating";
1639
+ function Reviews({
1640
+ productId = 0,
1641
+ reviewSubmitted = null,
1642
+ allowForm = true,
1643
+ histogram,
1644
+ total,
1645
+ average,
1646
+ ratingFilter,
1647
+ reviews,
1648
+ pagination,
1649
+ canReview,
1650
+ reason,
1651
+ loginUrl,
1652
+ guest,
1653
+ honeypotName,
1654
+ submitUrl
1655
+ }) {
1656
+ const { locale } = useStorefront();
1657
+ const { url } = useStorefrontPage();
1658
+ const visits = useStorefrontRouter();
1659
+ const formId = `ec-review-form-${productId}`;
1660
+ const headingId = `ec-reviews-${productId}-heading`;
1661
+ const submitted = null !== reviewSubmitted;
1662
+ const canWrite = allowForm && canReview && !submitted;
1663
+ const [formOpen, setShowForm] = useState11(false);
1664
+ const showForm = formOpen && !submitted;
1665
+ const openButton = useRef4(null);
1666
+ const number = (value, minimum, maximum = minimum) => new Intl.NumberFormat(locale.replace("_", "-"), {
1667
+ minimumFractionDigits: minimum,
1668
+ maximumFractionDigits: maximum
1669
+ }).format(value);
1670
+ const reload = ["sections"];
1671
+ const filter = (stars) => {
1672
+ visitWithQuery(
1673
+ url,
1674
+ {
1675
+ [REVIEW_RATING_QUERY]: null === stars || stars === ratingFilter ? null : stars,
1676
+ [pagination.pageName]: null
1677
+ },
1678
+ reload,
1679
+ visits
1680
+ );
1681
+ };
1682
+ return /* @__PURE__ */ jsxs11(
1683
+ "section",
1684
+ {
1685
+ id: "reviews",
1686
+ className: "ec-reviews",
1687
+ "aria-labelledby": headingId,
1688
+ "data-product-reviews": productId,
1689
+ children: [
1690
+ /* @__PURE__ */ jsxs11("div", { className: "ec-reviews__header", children: [
1691
+ /* @__PURE__ */ jsx13("h2", { id: headingId, className: "ec-reviews__title", children: __10("Customer reviews") }),
1692
+ canWrite ? /* @__PURE__ */ jsx13(
1693
+ Button3,
1694
+ {
1695
+ ref: openButton,
1696
+ variant: "outline",
1697
+ color: "neutral",
1698
+ leadingIcon: "pencil",
1699
+ onClick: () => setShowForm((open) => !open),
1700
+ "aria-controls": formId,
1701
+ "aria-expanded": showForm ? "true" : "false",
1702
+ "data-review-cta": "",
1703
+ "data-review-open": "",
1704
+ children: __10("Write a review")
1705
+ }
1706
+ ) : null
1707
+ ] }),
1708
+ !allowForm ? null : submitted ? /* @__PURE__ */ jsx13(SubmittedNotice, { published: reviewSubmitted.published }) : !canReview && null !== reason ? /* @__PURE__ */ jsx13("p", { className: "ec-reviews__ineligible", "data-review-cta": "", "data-review-ineligible": "", children: null !== loginUrl ? /* @__PURE__ */ jsx13(Link, { href: loginUrl, children: reason }) : reason }) : null,
1709
+ /* @__PURE__ */ jsxs11("div", { className: cx("ec-reviews__layout", 0 === total ? "ec-reviews__layout--single" : null), children: [
1710
+ total > 0 ? /* @__PURE__ */ jsxs11(Card, { className: "ec-reviews__summary", "data-review-summary": "", children: [
1711
+ /* @__PURE__ */ jsxs11("div", { className: "ec-reviews__overall", children: [
1712
+ /* @__PURE__ */ jsx13("span", { className: "ec-reviews__average", "aria-hidden": "true", children: number(average, 1) }),
1713
+ /* @__PURE__ */ jsxs11("span", { className: "ec-reviews__overall-detail", children: [
1714
+ /* @__PURE__ */ jsx13(
1715
+ Rating,
1716
+ {
1717
+ value: average,
1718
+ readonly: true,
1719
+ size: "md",
1720
+ valueLabel: __10(":rating out of 5", { rating: number(average, 0, 1) })
1721
+ }
1722
+ ),
1723
+ /* @__PURE__ */ jsx13("span", { className: "ec-reviews__count", children: trans_choice3(":count review|:count reviews", total, { count: total }) })
1724
+ ] })
1725
+ ] }),
1726
+ /* @__PURE__ */ jsx13(
1727
+ "ul",
1728
+ {
1729
+ role: "list",
1730
+ className: "ec-reviews__breakdown",
1731
+ "aria-label": __10("Rating breakdown"),
1732
+ "data-review-histogram": "",
1733
+ children: histogram.map((row) => /* @__PURE__ */ jsx13("li", { children: /* @__PURE__ */ jsxs11(
1734
+ "button",
1735
+ {
1736
+ type: "button",
1737
+ className: "ec-reviews__bar",
1738
+ onClick: () => filter(row.stars),
1739
+ "aria-pressed": ratingFilter === row.stars ? "true" : "false",
1740
+ disabled: 0 === row.count && ratingFilter !== row.stars,
1741
+ "data-histogram-row": row.stars,
1742
+ children: [
1743
+ /* @__PURE__ */ jsxs11("span", { className: "ec-reviews__bar-stars", "aria-hidden": "true", children: [
1744
+ number(row.stars, 0),
1745
+ /* @__PURE__ */ jsx13(Icon8, { name: "star" })
1746
+ ] }),
1747
+ /* @__PURE__ */ jsx13(
1748
+ Progress,
1749
+ {
1750
+ value: row.percent,
1751
+ size: "sm",
1752
+ color: "accent",
1753
+ className: "ec-reviews__bar-track",
1754
+ "aria-hidden": "true"
1755
+ }
1756
+ ),
1757
+ /* @__PURE__ */ jsx13("span", { className: "ec-reviews__bar-count", "aria-hidden": "true", children: number(row.count, 0) }),
1758
+ /* @__PURE__ */ jsx13("span", { className: "apui-sr-only", children: __10(":stars: :reviews (:percent%)", {
1759
+ stars: trans_choice3(":count star|:count stars", row.stars, {
1760
+ count: row.stars
1761
+ }),
1762
+ reviews: trans_choice3(":count review|:count reviews", row.count, {
1763
+ count: row.count
1764
+ }),
1765
+ percent: row.percent
1766
+ }) })
1767
+ ]
1768
+ }
1769
+ ) }, row.stars))
1770
+ }
1771
+ )
1772
+ ] }) : null,
1773
+ /* @__PURE__ */ jsxs11("div", { className: "ec-reviews__main", children: [
1774
+ showForm && canWrite ? /* @__PURE__ */ jsx13(
1775
+ ReviewForm,
1776
+ {
1777
+ formId,
1778
+ guest,
1779
+ honeypotName,
1780
+ submitUrl,
1781
+ onCancel: () => {
1782
+ setShowForm(false);
1783
+ window.setTimeout(() => openButton.current?.focus(), 0);
1784
+ }
1785
+ }
1786
+ ) : null,
1787
+ null !== ratingFilter ? /* @__PURE__ */ jsxs11("div", { className: "ec-reviews__filter", "data-review-filter": ratingFilter, children: [
1788
+ /* @__PURE__ */ jsx13("span", { children: trans_choice3(
1789
+ "Showing reviews rated :count star|Showing reviews rated :count stars",
1790
+ ratingFilter,
1791
+ { count: ratingFilter }
1792
+ ) }),
1793
+ /* @__PURE__ */ jsx13(Button3, { variant: "ghost", color: "neutral", size: "sm", onClick: () => filter(null), children: __10("Show all reviews") })
1794
+ ] }) : null,
1795
+ /* @__PURE__ */ jsx13("p", { className: "apui-sr-only", role: "status", "aria-live": "polite", children: null !== ratingFilter ? trans_choice3(":count review shown|:count reviews shown", pagination.total, {
1796
+ count: pagination.total
1797
+ }) : null }),
1798
+ reviews.length > 0 ? /* @__PURE__ */ jsxs11(Fragment4, { children: [
1799
+ /* @__PURE__ */ jsx13("ol", { role: "list", className: "ec-reviews__list", "data-review-list": "", children: reviews.map((review) => /* @__PURE__ */ jsx13("li", { className: "ec-review", "data-review": review.id, children: /* @__PURE__ */ jsxs11(
1800
+ "article",
1801
+ {
1802
+ className: "ec-review__article",
1803
+ "aria-labelledby": `ec-review-${review.id}-author`,
1804
+ children: [
1805
+ /* @__PURE__ */ jsxs11("div", { className: "ec-review__heading", children: [
1806
+ /* @__PURE__ */ jsx13(
1807
+ Rating,
1808
+ {
1809
+ value: review.rating,
1810
+ readonly: true,
1811
+ size: "sm",
1812
+ valueLabel: __10("Rated :rating out of 5", { rating: review.rating })
1813
+ }
1814
+ ),
1815
+ null !== review.title && "" !== review.title ? /* @__PURE__ */ jsx13("h3", { className: "ec-review__title", children: review.title }) : null
1816
+ ] }),
1817
+ null !== review.body && "" !== review.body ? /* @__PURE__ */ jsx13("p", { className: "ec-review__body", children: review.body }) : null,
1818
+ /* @__PURE__ */ jsxs11("p", { className: "ec-review__meta", children: [
1819
+ /* @__PURE__ */ jsx13("span", { id: `ec-review-${review.id}-author`, className: "ec-review__author", children: review.author }),
1820
+ review.verifiedPurchase ? /* @__PURE__ */ jsx13(
1821
+ Badge4,
1822
+ {
1823
+ variant: "soft",
1824
+ color: "success",
1825
+ leadingIcon: "check",
1826
+ "data-review-verified": "",
1827
+ children: __10("Verified purchase")
1828
+ }
1829
+ ) : null,
1830
+ /* @__PURE__ */ jsx13("time", { dateTime: review.date ?? void 0, children: review.dateLabel })
1831
+ ] })
1832
+ ]
1833
+ }
1834
+ ) }, review.id)) }),
1835
+ /* @__PURE__ */ jsx13(
1836
+ Pagination,
1837
+ {
1838
+ page: pagination.currentPage,
1839
+ pageCount: pagination.lastPage,
1840
+ total: pagination.total,
1841
+ perPage: pagination.perPage,
1842
+ summary: true,
1843
+ summaryLabel: __10("Showing {from} to {to} of {total} reviews"),
1844
+ onPageChange: (page) => visitWithQuery(
1845
+ url,
1846
+ { [pagination.pageName]: 1 === page ? null : page },
1847
+ reload,
1848
+ visits
1849
+ )
1850
+ }
1851
+ )
1852
+ ] }) : null !== ratingFilter ? /* @__PURE__ */ jsx13(
1853
+ EmptyState,
1854
+ {
1855
+ icon: "search-x",
1856
+ title: __10("No reviews with this rating"),
1857
+ headingLevel: 3,
1858
+ size: "sm",
1859
+ children: /* @__PURE__ */ jsx13(Button3, { variant: "outline", color: "neutral", onClick: () => filter(null), children: __10("Show all reviews") })
1860
+ }
1861
+ ) : !showForm ? /* @__PURE__ */ jsx13(
1862
+ EmptyState,
1863
+ {
1864
+ icon: "message-square",
1865
+ title: __10("No reviews yet"),
1866
+ description: __10("Be the first to review this product."),
1867
+ headingLevel: 3
1868
+ }
1869
+ ) : null
1870
+ ] })
1871
+ ] })
1872
+ ]
1873
+ }
1874
+ );
1875
+ }
1876
+ function SubmittedNotice({ published }) {
1877
+ const notice = useRef4(null);
1878
+ useEffect4(() => {
1879
+ notice.current?.focus();
1880
+ }, []);
1881
+ return /* @__PURE__ */ jsx13(
1882
+ Alert2,
1883
+ {
1884
+ ref: notice,
1885
+ color: "success",
1886
+ icon: "circle-check",
1887
+ title: published ? __10("Thanks \u2014 your review is published") : __10("Thanks \u2014 your review is awaiting moderation"),
1888
+ role: "status",
1889
+ tabIndex: -1,
1890
+ "data-review-cta": "",
1891
+ "data-review-submitted": ""
1892
+ }
1893
+ );
1894
+ }
1895
+ function ReviewForm({
1896
+ formId,
1897
+ guest,
1898
+ honeypotName,
1899
+ submitUrl,
1900
+ onCancel
1901
+ }) {
1902
+ const errors = useErrorBag(REVIEW_ERROR_BAG);
1903
+ const { post, processing } = useStorefrontPost(REVIEW_ERROR_BAG);
1904
+ const heading = useRef4(null);
1905
+ const [rating, setRating] = useState11(0);
1906
+ const [title, setTitle] = useState11("");
1907
+ const [body, setBody] = useState11("");
1908
+ const [authorName, setAuthorName] = useState11("");
1909
+ const [authorEmail, setAuthorEmail] = useState11("");
1910
+ const [honeypot, setHoneypot] = useState11("");
1911
+ const fieldIds = {
1912
+ rating: `${formId}-rating`,
1913
+ title: `${formId}-title`,
1914
+ body: `${formId}-body`,
1915
+ author_name: `${formId}-name`,
1916
+ author_email: `${formId}-email`
1917
+ };
1918
+ const summary = Object.entries(errors).filter(([key]) => "review" !== key).map(([key, message]) => ({ field: fieldIds[key] ?? key, message }));
1919
+ useEffect4(() => {
1920
+ heading.current?.focus();
1921
+ }, []);
1922
+ const submit = (event) => {
1923
+ event.preventDefault();
1924
+ post(
1925
+ submitUrl,
1926
+ {
1927
+ rating,
1928
+ title,
1929
+ body,
1930
+ ...guest ? { author_name: authorName, author_email: authorEmail } : {},
1931
+ [honeypotName]: honeypot
1932
+ },
1933
+ ["ecommerceStorefront", "sections", "feedback", "product"]
1934
+ );
1935
+ };
1936
+ return /* @__PURE__ */ jsx13(Card, { className: "ec-review-form-card", children: /* @__PURE__ */ jsxs11(
1937
+ "form",
1938
+ {
1939
+ id: formId,
1940
+ onSubmit: submit,
1941
+ className: "ec-review-form",
1942
+ "aria-labelledby": `${formId}-heading`,
1943
+ noValidate: true,
1944
+ "data-review-form": "",
1945
+ children: [
1946
+ /* @__PURE__ */ jsx13("h3", { ref: heading, id: `${formId}-heading`, tabIndex: -1, className: "ec-review-form__title", children: __10("Write a review") }),
1947
+ summary.length > 0 ? /* @__PURE__ */ jsx13(
1948
+ ValidationSummary,
1949
+ {
1950
+ errors: summary,
1951
+ title: trans_choice3(
1952
+ "Fix :count thing to continue|Fix :count things to continue",
1953
+ summary.length,
1954
+ { count: summary.length }
1955
+ ),
1956
+ id: `${formId}-errors`,
1957
+ className: "ec-error-summary",
1958
+ "data-error-summary": ""
1959
+ }
1960
+ ) : null,
1961
+ void 0 !== errors.review ? /* @__PURE__ */ jsx13(Alert2, { color: "error", icon: "circle-alert", title: errors.review, "data-review-error": "" }) : null,
1962
+ /* @__PURE__ */ jsx13(
1963
+ RatingInput,
1964
+ {
1965
+ id: fieldIds.rating,
1966
+ label: __10("Your rating"),
1967
+ value: rating,
1968
+ onValueChange: setRating,
1969
+ error: errors.rating ?? null,
1970
+ required: true
1971
+ }
1972
+ ),
1973
+ /* @__PURE__ */ jsx13(
1974
+ Field,
1975
+ {
1976
+ id: fieldIds.title,
1977
+ label: __10("Title"),
1978
+ errorKey: "title",
1979
+ maxLength: 255,
1980
+ value: title,
1981
+ onValueChange: setTitle,
1982
+ error: errors.title ?? null
1983
+ }
1984
+ ),
1985
+ /* @__PURE__ */ jsx13(
1986
+ Field,
1987
+ {
1988
+ control: "textarea",
1989
+ id: fieldIds.body,
1990
+ label: __10("Your review"),
1991
+ errorKey: "body",
1992
+ maxLength: 1e4,
1993
+ value: body,
1994
+ onValueChange: setBody,
1995
+ error: errors.body ?? null,
1996
+ attributes: { rows: 5 }
1997
+ }
1998
+ ),
1999
+ guest ? /* @__PURE__ */ jsxs11("div", { className: "ec-review-form__pair", children: [
2000
+ /* @__PURE__ */ jsx13(
2001
+ Field,
2002
+ {
2003
+ id: fieldIds.author_name,
2004
+ label: __10("Your name"),
2005
+ errorKey: "author_name",
2006
+ autoComplete: "name",
2007
+ required: true,
2008
+ value: authorName,
2009
+ onValueChange: setAuthorName,
2010
+ error: errors.author_name ?? null
2011
+ }
2012
+ ),
2013
+ /* @__PURE__ */ jsx13(
2014
+ Field,
2015
+ {
2016
+ id: fieldIds.author_email,
2017
+ type: "email",
2018
+ label: __10("Your email"),
2019
+ hint: __10("Not shown with your review."),
2020
+ errorKey: "author_email",
2021
+ autoComplete: "email",
2022
+ required: true,
2023
+ value: authorEmail,
2024
+ onValueChange: setAuthorEmail,
2025
+ error: errors.author_email ?? null
2026
+ }
2027
+ )
2028
+ ] }) : null,
2029
+ /* @__PURE__ */ jsxs11("div", { className: "apui-sr-only", "aria-hidden": "true", children: [
2030
+ /* @__PURE__ */ jsx13("label", { htmlFor: `${formId}-${honeypotName}`, children: __10("Leave this field empty") }),
2031
+ /* @__PURE__ */ jsx13(
2032
+ "input",
2033
+ {
2034
+ id: `${formId}-${honeypotName}`,
2035
+ type: "text",
2036
+ name: honeypotName,
2037
+ value: honeypot,
2038
+ onChange: (event) => setHoneypot(event.target.value),
2039
+ tabIndex: -1,
2040
+ autoComplete: "off"
2041
+ }
2042
+ )
2043
+ ] }),
2044
+ /* @__PURE__ */ jsxs11("div", { className: "ec-review-form__actions", children: [
2045
+ /* @__PURE__ */ jsx13(Button3, { type: "submit", color: "primary", disabled: processing, "data-review-submit": "", children: __10("Submit review") }),
2046
+ /* @__PURE__ */ jsx13(Button3, { variant: "ghost", color: "neutral", onClick: onCancel, "data-review-cancel": "", children: __10("Cancel") })
2047
+ ] })
2048
+ ]
2049
+ }
2050
+ ) });
2051
+ }
2052
+
2053
+ // src/product/sections/SoldOutNotice.tsx
2054
+ import { __ as __11 } from "@artisanpack-ui/ecommerce-storefront-core";
2055
+ import { Alert as Alert3 } from "@artisanpack-ui/react";
2056
+ import { jsx as jsx14 } from "react/jsx-runtime";
2057
+ function SoldOutNotice(_props = {}) {
2058
+ return /* @__PURE__ */ jsx14(
2059
+ Alert3,
2060
+ {
2061
+ color: "neutral",
2062
+ icon: "mail",
2063
+ title: __11("This item is sold out"),
2064
+ className: "ec-product__sold-out",
2065
+ "data-product-sold-out": "",
2066
+ children: __11("Check back soon. It may be restocked, and similar pieces are below.")
2067
+ }
2068
+ );
2069
+ }
2070
+
2071
+ // src/product/sections/registerProductSections.ts
2072
+ function registerProductSections(registries) {
2073
+ registries.productSections.register("reviews", Reviews, { position: 10 });
2074
+ registries.productSections.register("related-products", RelatedProducts, { position: 20 });
2075
+ registries.productSections.register("recently-viewed", RecentlyViewed, { position: 30 });
2076
+ registries.productSections.register("sold-out", SoldOutNotice, { position: 40 });
2077
+ }
2078
+
2079
+ // src/product/builtIns.ts
2080
+ var registered = false;
2081
+ function registerProductBuiltIns() {
2082
+ if (registered) {
2083
+ return;
2084
+ }
2085
+ registered = true;
2086
+ addBuiltInRegistration((registries) => {
2087
+ registerProductForms(registries);
2088
+ registerProductSections(registries);
2089
+ });
2090
+ }
2091
+
2092
+ // src/product/StorefrontSections.tsx
2093
+ import { Fragment as Fragment5, jsx as jsx15 } from "react/jsx-runtime";
2094
+ registerProductBuiltIns();
2095
+ function StorefrontSections({
2096
+ sections,
2097
+ registry,
2098
+ className = "ec-product__section",
2099
+ keyAttribute = "data-product-section",
2100
+ extra = {}
2101
+ }) {
2102
+ const entries = getRegistries()[registry];
2103
+ return /* @__PURE__ */ jsx15(Fragment5, { children: sections.map((section) => {
2104
+ const entry = entries.get(section.component);
2105
+ if (void 0 === entry) {
2106
+ return null;
2107
+ }
2108
+ const Section = entry.component;
2109
+ return /* @__PURE__ */ jsx15("div", { className, ...{ [keyAttribute]: section.key }, children: /* @__PURE__ */ jsx15(Section, { ...extra, ...section.props, sectionKey: section.key }) }, section.key);
2110
+ }) });
2111
+ }
2112
+
2113
+ // src/pages/Product/Show.tsx
2114
+ import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
2115
+ registerProductBuiltIns();
2116
+ function ProductShow({
2117
+ product,
2118
+ variantId,
2119
+ gallery,
2120
+ price,
2121
+ stock,
2122
+ shortDescription,
2123
+ description,
2124
+ specifications,
2125
+ shippingReturns,
2126
+ category,
2127
+ breadcrumbs,
2128
+ highlights,
2129
+ form,
2130
+ soldOut,
2131
+ sections,
2132
+ feedback
2133
+ }) {
2134
+ const registries = getRegistries();
2135
+ const nameId = `ec-product-${product.id}-name`;
2136
+ const detailsId = `ec-product-${product.id}-details`;
2137
+ const scope = `product-${product.id}`;
2138
+ const Form = null === form ? void 0 : registries.productForms.get(form.component)?.component;
2139
+ const SoldOut = null === soldOut ? void 0 : registries.productSections.get(soldOut.component)?.component;
2140
+ const shownImage = useRef5(gallery.active);
2141
+ const formContext = useMemo(
2142
+ () => ({
2143
+ productName: product.name,
2144
+ productUrl: product.url,
2145
+ variantId,
2146
+ announcement: feedback.announcement,
2147
+ notifySubscribed: feedback.notifySubscribed
2148
+ }),
2149
+ [product.name, product.url, variantId, feedback.announcement, feedback.notifySubscribed]
2150
+ );
2151
+ useEffect5(() => {
2152
+ if (shownImage.current === gallery.active) {
2153
+ return;
2154
+ }
2155
+ shownImage.current = gallery.active;
2156
+ const image = gallery.items[gallery.active];
2157
+ if (void 0 !== image) {
2158
+ window.dispatchEvent(
2159
+ new CustomEvent(GALLERY_SHOW_EVENT, { detail: { scope, url: image.url } })
2160
+ );
2161
+ }
2162
+ }, [gallery, scope]);
2163
+ return /* @__PURE__ */ jsxs12("article", { className: "ec-product", "aria-labelledby": nameId, "data-product-page": product.id, children: [
2164
+ breadcrumbs.length > 1 ? /* @__PURE__ */ jsx16(
2165
+ Breadcrumbs,
2166
+ {
2167
+ items: breadcrumbs.map((crumb) => ({
2168
+ label: crumb.label,
2169
+ ...null !== crumb.url ? { href: crumb.url } : {}
2170
+ })),
2171
+ label: __12("Breadcrumb")
2172
+ }
2173
+ ) : null,
2174
+ /* @__PURE__ */ jsxs12("div", { className: "ec-product__top", children: [
2175
+ /* @__PURE__ */ jsx16(
2176
+ Gallery,
2177
+ {
2178
+ items: gallery.items,
2179
+ name: gallery.name,
2180
+ active: gallery.active,
2181
+ thumbnails: gallery.thumbnails,
2182
+ zoom: gallery.zoom,
2183
+ scope
2184
+ }
2185
+ ),
2186
+ /* @__PURE__ */ jsxs12("div", { className: "ec-product__summary", "data-product-summary": "", children: [
2187
+ null !== category ? null !== category.url ? /* @__PURE__ */ jsx16("a", { href: category.url, className: "ec-product__category", "data-product-category": "", children: category.name }) : /* @__PURE__ */ jsx16("p", { className: "ec-product__category", "data-product-category": "", children: category.name }) : null,
2188
+ /* @__PURE__ */ jsx16("h1", { id: nameId, className: "ec-product__name", children: product.name }),
2189
+ /* @__PURE__ */ jsx16(RatingSummary, { rating: product.rating }),
2190
+ /* @__PURE__ */ jsx16(Price, { price, size: "lg", "data-product-price": "" }),
2191
+ null !== shortDescription ? /* @__PURE__ */ jsx16(
2192
+ "div",
2193
+ {
2194
+ className: "apui-prose ec-product__short-description",
2195
+ "data-product-short-description": "",
2196
+ dangerouslySetInnerHTML: { __html: shortDescription }
2197
+ }
2198
+ ) : null,
2199
+ /* @__PURE__ */ jsxs12("div", { className: "ec-product__meta", children: [
2200
+ /* @__PURE__ */ jsx16(StockStatus, { stock, "data-product-stock": "" }),
2201
+ null !== product.sku && "" !== product.sku ? /* @__PURE__ */ jsxs12("p", { className: "ec-product__sku", "data-product-sku": "", children: [
2202
+ __12("SKU"),
2203
+ " ",
2204
+ /* @__PURE__ */ jsx16("code", { children: product.sku })
2205
+ ] }) : null
2206
+ ] }),
2207
+ /* @__PURE__ */ jsxs12("div", { className: "ec-product__purchase", children: [
2208
+ null !== form ? void 0 !== Form ? /* @__PURE__ */ jsx16(PurchaseFormContext.Provider, { value: formContext, children: /* @__PURE__ */ jsx16(Form, { ...form.props }, `${form.component}-${product.id}`) }) : null : /* @__PURE__ */ jsx16(
2209
+ Alert4,
2210
+ {
2211
+ icon: "info",
2212
+ title: __12("This product can't be purchased online"),
2213
+ "data-product-unavailable": ""
2214
+ }
2215
+ ),
2216
+ void 0 !== SoldOut ? /* @__PURE__ */ jsx16(SoldOut, { productId: product.id }) : null
2217
+ ] }),
2218
+ highlights.length > 0 ? /* @__PURE__ */ jsx16(
2219
+ "ul",
2220
+ {
2221
+ role: "list",
2222
+ className: "apui-card ec-product__highlights",
2223
+ "data-surface": "default",
2224
+ "data-product-highlights": "",
2225
+ children: highlights.map((highlight) => /* @__PURE__ */ jsxs12("li", { className: "ec-product__highlight", children: [
2226
+ /* @__PURE__ */ jsx16(
2227
+ Icon9,
2228
+ {
2229
+ name: highlight.icon,
2230
+ className: "ec-product__highlight-icon",
2231
+ "aria-hidden": "true"
2232
+ }
2233
+ ),
2234
+ /* @__PURE__ */ jsxs12("span", { children: [
2235
+ /* @__PURE__ */ jsx16("span", { className: "ec-product__highlight-title", children: highlight.title }),
2236
+ null !== highlight.description ? /* @__PURE__ */ jsx16("span", { className: "ec-product__highlight-description", children: highlight.description }) : null
2237
+ ] })
2238
+ ] }, highlight.title))
2239
+ }
2240
+ ) : null
2241
+ ] })
2242
+ ] }),
2243
+ null !== description || specifications.length > 0 || null !== shippingReturns ? /* @__PURE__ */ jsxs12(
2244
+ "section",
2245
+ {
2246
+ className: "ec-product__details",
2247
+ "aria-labelledby": detailsId,
2248
+ "data-product-details": "",
2249
+ children: [
2250
+ /* @__PURE__ */ jsx16("h2", { id: detailsId, className: "ec-product__section-title", children: __12("Product details") }),
2251
+ /* @__PURE__ */ jsxs12(Accordion, { defaultValue: ["description"], collapsible: true, className: "ec-product__accordion", children: [
2252
+ null !== description ? /* @__PURE__ */ jsx16(
2253
+ AccordionItem,
2254
+ {
2255
+ value: "description",
2256
+ title: __12("Description"),
2257
+ "data-details-section": "description",
2258
+ children: /* @__PURE__ */ jsx16("div", { className: "apui-prose", dangerouslySetInnerHTML: { __html: description } })
2259
+ }
2260
+ ) : null,
2261
+ specifications.length > 0 ? /* @__PURE__ */ jsx16(
2262
+ AccordionItem,
2263
+ {
2264
+ value: "specifications",
2265
+ title: __12("Specifications"),
2266
+ "data-details-section": "specifications",
2267
+ children: /* @__PURE__ */ jsx16("div", { className: "apui-table ec-product__specs", "data-density": "compact", children: /* @__PURE__ */ jsx16("div", { "data-scope": "table", "data-part": "scroll", children: /* @__PURE__ */ jsxs12("table", { "data-scope": "table", "data-part": "table", children: [
2268
+ /* @__PURE__ */ jsx16("caption", { className: "apui-sr-only", children: __12("Specifications") }),
2269
+ /* @__PURE__ */ jsx16("tbody", { children: specifications.map((row) => /* @__PURE__ */ jsxs12("tr", { "data-scope": "table", "data-part": "row", children: [
2270
+ /* @__PURE__ */ jsx16("th", { scope: "row", children: row.label }),
2271
+ /* @__PURE__ */ jsx16("td", { children: row.value })
2272
+ ] }, row.label)) })
2273
+ ] }) }) })
2274
+ }
2275
+ ) : null,
2276
+ null !== shippingReturns ? /* @__PURE__ */ jsx16(
2277
+ AccordionItem,
2278
+ {
2279
+ value: "shipping",
2280
+ title: __12("Shipping & returns"),
2281
+ "data-details-section": "shipping",
2282
+ children: /* @__PURE__ */ jsx16("div", { className: "apui-prose", dangerouslySetInnerHTML: { __html: shippingReturns } })
2283
+ }
2284
+ ) : null
2285
+ ] })
2286
+ ]
2287
+ }
2288
+ ) : null,
2289
+ /* @__PURE__ */ jsx16(
2290
+ StorefrontSections,
2291
+ {
2292
+ sections,
2293
+ registry: "productSections",
2294
+ extra: { productId: product.id, reviewSubmitted: feedback.reviewSubmitted }
2295
+ }
2296
+ )
2297
+ ] });
2298
+ }
2299
+ ProductShow.layout = storefrontLayout;
2300
+
2301
+ export {
2302
+ PurchaseFormContext,
2303
+ usePurchaseFormContext,
2304
+ AddToCart,
2305
+ BundledForm,
2306
+ DigitalForm,
2307
+ groupedSummary,
2308
+ GroupedForm,
2309
+ ChoiceCards,
2310
+ optionValue,
2311
+ withOptionValue,
2312
+ OptionsForm,
2313
+ SimpleForm,
2314
+ VARIANT_RELOAD,
2315
+ VariableForm,
2316
+ CORE_PRODUCT_FORMS,
2317
+ registerProductForms,
2318
+ RecentlyViewed,
2319
+ RecentlyViewedPlaceholder,
2320
+ RatingInput,
2321
+ REVIEW_RATING_QUERY,
2322
+ Reviews,
2323
+ SoldOutNotice,
2324
+ registerProductSections,
2325
+ registerProductBuiltIns,
2326
+ GALLERY_SHOW_EVENT,
2327
+ Gallery,
2328
+ StorefrontSections,
2329
+ ProductShow
2330
+ };
2331
+ //# sourceMappingURL=chunk-HXZMY3GE.mjs.map