@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,1898 @@
1
+ // src/internal/sameOrigin.ts
2
+ var UNSAFE = /[\\\u0000-\u001f\u007f]/;
3
+ function hasUnsafeCharacters(url) {
4
+ return UNSAFE.test(url);
5
+ }
6
+ function isSameOrigin(url) {
7
+ if ("undefined" === typeof window || hasUnsafeCharacters(url)) {
8
+ return false;
9
+ }
10
+ try {
11
+ return new URL(url, window.location.href).origin === window.location.origin;
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+
17
+ // src/cart/cartRoutes.ts
18
+ var CART_DRAWER_ONLY = ["ecommerceStorefront", "ecommerceStorefrontCart"];
19
+ var CART_PAGE = "EcommerceStorefront/Cart/Index";
20
+ var CART_PAGE_RELOAD = ["cart", "estimate", "feedback", "sections", "relatedProducts"];
21
+ function cartWriteOnly(component) {
22
+ return CART_PAGE === component ? [...CART_DRAWER_ONLY, ...CART_PAGE_RELOAD] : CART_DRAWER_ONLY;
23
+ }
24
+ function cartActionUrl(cartUrl, path) {
25
+ let base = cartUrl;
26
+ try {
27
+ const parsed = new URL(cartUrl, "http://localhost");
28
+ base = parsed.pathname;
29
+ } catch {
30
+ }
31
+ return `${base.replace(/\/+$/, "")}/${path}`;
32
+ }
33
+ function csrfHeaders() {
34
+ const cookie = document.cookie.split("; ").find((part) => part.startsWith("XSRF-TOKEN="))?.slice("XSRF-TOKEN=".length);
35
+ if (void 0 !== cookie && "" !== cookie) {
36
+ try {
37
+ return { "X-XSRF-TOKEN": decodeURIComponent(cookie) };
38
+ } catch {
39
+ }
40
+ }
41
+ const meta = document.querySelector('meta[name="csrf-token"]')?.content;
42
+ return void 0 === meta || "" === meta ? {} : { "X-CSRF-TOKEN": meta };
43
+ }
44
+ async function postJson(url, data) {
45
+ try {
46
+ const response = await fetch(url, {
47
+ method: "POST",
48
+ credentials: "same-origin",
49
+ headers: {
50
+ Accept: "application/json",
51
+ "Content-Type": "application/json",
52
+ "X-Requested-With": "XMLHttpRequest",
53
+ // The token only goes to this site.
54
+ ...isSameOrigin(url) ? csrfHeaders() : {}
55
+ },
56
+ body: JSON.stringify(data)
57
+ });
58
+ let body = null;
59
+ try {
60
+ body = await response.json();
61
+ } catch {
62
+ body = null;
63
+ }
64
+ return { status: response.status, body };
65
+ } catch {
66
+ return { status: 0, body: null };
67
+ }
68
+ }
69
+
70
+ // src/icons.ts
71
+ import { registerIcons, resolveIcon } from "@artisanpack-ui/behavior/icons";
72
+ var STOREFRONT_ICONS = {
73
+ "circle-x": '<circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/>',
74
+ clock: '<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>',
75
+ "credit-card": '<rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/>',
76
+ folder: '<path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/>',
77
+ funnel: '<path d="M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z"/>',
78
+ gift: '<rect x="3" y="8" width="18" height="4" rx="1"/><path d="M12 8v13"/><path d="M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7"/><path d="M7.5 8a2.5 2.5 0 0 1 0-5A4.8 8 0 0 1 12 8a4.8 8 0 0 1 4.5-5 2.5 2.5 0 0 1 0 5"/>',
79
+ "map-pin": '<path d="M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"/><circle cx="12" cy="10" r="3"/>',
80
+ menu: '<line x1="4" x2="20" y1="12" y2="12"/><line x1="4" x2="20" y1="6" y2="6"/><line x1="4" x2="20" y1="18" y2="18"/>',
81
+ package: '<path d="M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z"/><path d="M12 22V12"/><path d="m3.3 7 7.703 4.734a2 2 0 0 0 1.994 0L20.7 7"/><path d="m7.5 4.27 9 5.15"/>',
82
+ shield: '<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/>',
83
+ "shopping-bag": '<path d="M16 10a4 4 0 0 1-8 0"/><path d="M3.103 6.034h17.794"/><path d="M3.4 5.467a2 2 0 0 0-.4 1.2V20a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6.667a2 2 0 0 0-.4-1.2l-2-2.667A2 2 0 0 0 17 2H7a2 2 0 0 0-1.6.8z"/>',
84
+ "sliders-horizontal": '<line x1="21" x2="14" y1="4" y2="4"/><line x1="10" x2="3" y1="4" y2="4"/><line x1="21" x2="12" y1="12" y2="12"/><line x1="8" x2="3" y1="12" y2="12"/><line x1="21" x2="16" y1="20" y2="20"/><line x1="12" x2="3" y1="20" y2="20"/><line x1="14" x2="14" y1="2" y2="6"/><line x1="8" x2="8" y1="10" y2="14"/><line x1="16" x2="16" y1="18" y2="22"/>',
85
+ tag: '<path d="M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"/><circle cx="7.5" cy="7.5" r=".5"/>',
86
+ truck: '<path d="M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2"/><path d="M15 18H9"/><path d="M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14"/><circle cx="17" cy="18" r="2"/><circle cx="7" cy="18" r="2"/>',
87
+ "zoom-in": '<circle cx="11" cy="11" r="8"/><line x1="21" x2="16.65" y1="21" y2="16.65"/><line x1="11" x2="11" y1="8" y2="14"/><line x1="8" x2="14" y1="11" y2="11"/>'
88
+ };
89
+ function registerStorefrontIcons() {
90
+ const missing = Object.fromEntries(
91
+ Object.entries(STOREFRONT_ICONS).filter(([name]) => void 0 === resolveIcon(name))
92
+ );
93
+ if (Object.keys(missing).length > 0) {
94
+ registerIcons(missing);
95
+ }
96
+ }
97
+
98
+ // src/registries.ts
99
+ import { doAction } from "@artisanpack-ui/hooks-js";
100
+ import {
101
+ HOOKS,
102
+ createRegistries
103
+ } from "@artisanpack-ui/ecommerce-storefront-core";
104
+ var builtIns = [];
105
+ var registries = null;
106
+ function addBuiltInRegistration(register) {
107
+ builtIns.push(register);
108
+ if (null !== registries) {
109
+ register(keepExisting(registries));
110
+ }
111
+ }
112
+ function keepExisting(current) {
113
+ const view = {};
114
+ for (const [name, registry] of Object.entries(current)) {
115
+ view[name] = {
116
+ ...registry,
117
+ register: (key, component, options) => {
118
+ if (!registry.has(key)) {
119
+ registry.register(key, component, options);
120
+ }
121
+ }
122
+ };
123
+ }
124
+ return view;
125
+ }
126
+ function getRegistries() {
127
+ if (null === registries) {
128
+ registerStorefrontIcons();
129
+ const created = createRegistries();
130
+ for (const register of builtIns) {
131
+ register(created);
132
+ }
133
+ registries = created;
134
+ doAction(HOOKS.register, created);
135
+ }
136
+ return registries;
137
+ }
138
+ function resetRegistries() {
139
+ registries = null;
140
+ }
141
+
142
+ // src/components/Price.tsx
143
+ import { __ } from "@artisanpack-ui/ecommerce-storefront-core";
144
+ import { Badge } from "@artisanpack-ui/react";
145
+
146
+ // src/internal/classes.ts
147
+ function cx(...names) {
148
+ return names.filter((name) => "string" === typeof name && "" !== name).join(" ");
149
+ }
150
+ function idFragment(value) {
151
+ return value.replace(/[^A-Za-z0-9_-]+/g, "-");
152
+ }
153
+ function filled(value) {
154
+ return "string" === typeof value && "" !== value.trim();
155
+ }
156
+
157
+ // src/components/Price.tsx
158
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
159
+ function Price({
160
+ price,
161
+ size = "md",
162
+ saleBadge = true,
163
+ from = false,
164
+ showTax = true,
165
+ className,
166
+ ...rest
167
+ }) {
168
+ const dataSize = ["sm", "md", "lg"].includes(size) ? size : "md";
169
+ if (null === price || "unavailable" === price.kind) {
170
+ return /* @__PURE__ */ jsx(
171
+ "span",
172
+ {
173
+ ...rest,
174
+ className: cx("ec-price", className),
175
+ "data-size": dataSize,
176
+ "data-price": "unavailable",
177
+ children: __("Price unavailable")
178
+ }
179
+ );
180
+ }
181
+ const saleTone = price.onSale ? "sale" : void 0;
182
+ const taxNote = showTax && null !== price.taxNote && "" !== price.taxNote ? price.taxNote : null;
183
+ let body;
184
+ if ("range" === price.kind) {
185
+ if (from) {
186
+ const [before = "", after = ""] = __("From :price").split(":price");
187
+ body = /* @__PURE__ */ jsxs("span", { className: "ec-price__from", children: [
188
+ before,
189
+ /* @__PURE__ */ jsx("span", { className: "ec-price__amount", "data-tone": saleTone, children: price.min }),
190
+ after
191
+ ] });
192
+ } else {
193
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
194
+ /* @__PURE__ */ jsx("span", { className: "apui-sr-only", children: __("From :min to :max", { min: price.min ?? "", max: price.max ?? "" }) }),
195
+ /* @__PURE__ */ jsxs("span", { className: "ec-price__amount", "data-tone": saleTone, "aria-hidden": "true", children: [
196
+ price.min,
197
+ " \u2013 ",
198
+ price.max
199
+ ] })
200
+ ] });
201
+ }
202
+ if (price.onSale) {
203
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
204
+ body,
205
+ /* @__PURE__ */ jsx("span", { className: "apui-sr-only", children: __("On sale") })
206
+ ] });
207
+ }
208
+ } else if (price.onSale && null !== price.was) {
209
+ body = /* @__PURE__ */ jsxs(Fragment, { children: [
210
+ /* @__PURE__ */ jsxs("ins", { className: "ec-price__amount", "data-tone": "sale", children: [
211
+ /* @__PURE__ */ jsxs("span", { className: "apui-sr-only", children: [
212
+ __("Sale price"),
213
+ " "
214
+ ] }),
215
+ price.amount
216
+ ] }),
217
+ /* @__PURE__ */ jsxs("del", { className: "ec-price__was", children: [
218
+ /* @__PURE__ */ jsxs("span", { className: "apui-sr-only", children: [
219
+ __("Original price"),
220
+ " "
221
+ ] }),
222
+ price.was
223
+ ] }),
224
+ saleBadge && null !== price.percentOff ? /* @__PURE__ */ jsx(Badge, { color: "error", size: "sm", "data-price-discount": "", children: __(":percent% off", { percent: price.percentOff }) }) : null
225
+ ] });
226
+ } else if ("free" === price.kind) {
227
+ body = /* @__PURE__ */ jsx("span", { className: "ec-price__amount", "data-tone": "free", children: __("Free") });
228
+ } else {
229
+ body = /* @__PURE__ */ jsx("span", { className: "ec-price__amount", children: price.amount });
230
+ }
231
+ return /* @__PURE__ */ jsxs(
232
+ "span",
233
+ {
234
+ ...rest,
235
+ className: cx("ec-price", className),
236
+ "data-size": dataSize,
237
+ "data-price": "",
238
+ "data-on-sale": price.onSale ? "" : void 0,
239
+ children: [
240
+ body,
241
+ null !== taxNote ? /* @__PURE__ */ jsx("span", { className: "ec-price__note", children: taxNote }) : null
242
+ ]
243
+ }
244
+ );
245
+ }
246
+
247
+ // src/useStorefront.ts
248
+ import { usePage } from "@inertiajs/react";
249
+ import { useContext } from "react";
250
+
251
+ // src/internal/pageContext.tsx
252
+ import { createContext } from "react";
253
+ var StorefrontPageContext = createContext(null);
254
+ var StorefrontBlockHostContext = createContext(null);
255
+
256
+ // src/useStorefront.ts
257
+ function useStorefrontPage() {
258
+ const override = useContext(StorefrontPageContext);
259
+ if (null !== override) {
260
+ return override;
261
+ }
262
+ return usePage();
263
+ }
264
+ function useStorefront() {
265
+ return useStorefrontPage().props.ecommerceStorefront;
266
+ }
267
+ function usePageErrors() {
268
+ const errors = useStorefrontPage().props.errors;
269
+ return null !== errors && "object" === typeof errors ? errors : {};
270
+ }
271
+ function useStorefrontCart() {
272
+ const cart = useStorefrontPage().props.ecommerceStorefrontCart;
273
+ return null !== cart && "object" === typeof cart ? cart : null;
274
+ }
275
+ function useStorefrontTemplate() {
276
+ const template = useStorefrontPage().props.ecommerceStorefrontTemplate;
277
+ return null !== template && "object" === typeof template ? template : null;
278
+ }
279
+
280
+ // src/cart/cartDrawerState.tsx
281
+ import {
282
+ createContext as createContext2,
283
+ useContext as useContext2,
284
+ useEffect,
285
+ useMemo,
286
+ useRef,
287
+ useState
288
+ } from "react";
289
+ import { jsx as jsx2 } from "react/jsx-runtime";
290
+ var noop = () => void 0;
291
+ var CartDrawerContext = createContext2({
292
+ open: false,
293
+ setOpen: noop,
294
+ available: false,
295
+ setAvailable: noop,
296
+ opener: { current: null },
297
+ openFrom: noop
298
+ });
299
+ function CartDrawerProvider({
300
+ openRequested = false,
301
+ children
302
+ }) {
303
+ const [open, setOpen] = useState(openRequested);
304
+ const [requested, setRequested] = useState(openRequested);
305
+ const [available, setAvailable] = useState(false);
306
+ const opener = useRef(null);
307
+ if (requested !== openRequested) {
308
+ setRequested(openRequested);
309
+ if (openRequested) {
310
+ setOpen(true);
311
+ }
312
+ }
313
+ const value = useMemo(
314
+ () => ({
315
+ open,
316
+ setOpen,
317
+ available,
318
+ setAvailable,
319
+ opener,
320
+ openFrom: (element) => {
321
+ opener.current = element;
322
+ setOpen(true);
323
+ }
324
+ }),
325
+ [open, available]
326
+ );
327
+ return /* @__PURE__ */ jsx2(CartDrawerContext.Provider, { value, children });
328
+ }
329
+ function useCartDrawer() {
330
+ return useContext2(CartDrawerContext);
331
+ }
332
+ function useRegisterCartDrawer() {
333
+ const { setAvailable } = useCartDrawer();
334
+ useEffect(() => {
335
+ setAvailable(true);
336
+ return () => setAvailable(false);
337
+ }, [setAvailable]);
338
+ }
339
+
340
+ // src/cart/CartHeaderButton.tsx
341
+ import { trans_choice } from "@artisanpack-ui/ecommerce-storefront-core";
342
+ import { Badge as Badge2, Icon } from "@artisanpack-ui/react";
343
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
344
+ function CartHeaderButton() {
345
+ const { cart } = useStorefront();
346
+ const drawer = useCartDrawer();
347
+ const onClick = (event) => {
348
+ if (!drawer.available) {
349
+ return;
350
+ }
351
+ event.preventDefault();
352
+ drawer.openFrom(event.currentTarget);
353
+ };
354
+ return /* @__PURE__ */ jsx3("div", { className: "ec-cart-button", "data-ecommerce-cart-button": "", children: null !== cart.url ? /* @__PURE__ */ jsxs2(
355
+ "a",
356
+ {
357
+ href: cart.url,
358
+ className: "apui-button",
359
+ "data-variant": "ghost",
360
+ "data-color": "neutral",
361
+ "data-size": "sm",
362
+ "aria-label": trans_choice("Cart, :count item|Cart, :count items", cart.count, {
363
+ count: cart.count
364
+ }),
365
+ "aria-haspopup": "dialog",
366
+ "aria-controls": "ecommerce-cart-drawer-content",
367
+ onClick,
368
+ "data-header-action": "cart",
369
+ children: [
370
+ /* @__PURE__ */ jsx3(Icon, { name: "shopping-bag", size: "lg" }),
371
+ cart.count > 0 ? /* @__PURE__ */ jsx3(Badge2, { variant: "solid", color: "primary", size: "sm", "aria-hidden": "true", "data-cart-count": "", children: cart.count }) : null
372
+ ]
373
+ }
374
+ ) : null });
375
+ }
376
+
377
+ // src/components/CurrencySwitcher.tsx
378
+ import { __ as __2 } from "@artisanpack-ui/ecommerce-storefront-core";
379
+ import { DropdownMenu } from "@artisanpack-ui/react";
380
+ import { router } from "@inertiajs/react";
381
+ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
382
+ function CurrencySwitcher({
383
+ switcher,
384
+ placement: placement2 = "header"
385
+ }) {
386
+ const shared = useStorefront();
387
+ const errors = usePageErrors();
388
+ const currency = switcher ?? shared.currency;
389
+ const error = errors.currency;
390
+ return /* @__PURE__ */ jsx4(
391
+ "div",
392
+ {
393
+ className: "ec-currency",
394
+ "data-ecommerce-currency-switcher": "",
395
+ "data-currency-placement": placement2,
396
+ children: currency.show ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
397
+ /* @__PURE__ */ jsx4(
398
+ DropdownMenu,
399
+ {
400
+ align: "end",
401
+ items: currency.items.map((item) => ({
402
+ type: item.type,
403
+ value: item.value,
404
+ label: item.label,
405
+ shortcut: item.shortcut,
406
+ checked: item.checked
407
+ })),
408
+ label: /* @__PURE__ */ jsxs3(Fragment2, { children: [
409
+ /* @__PURE__ */ jsx4("span", { className: "apui-sr-only", children: __2("Currency") }),
410
+ " ",
411
+ /* @__PURE__ */ jsx4("span", { "data-currency-code": "", children: currency.current })
412
+ ] }),
413
+ onCheckedChange: ({ value, checked }) => {
414
+ if (checked && value !== currency.current && null !== currency.url) {
415
+ router.post(currency.url, { currency: value }, { preserveScroll: true });
416
+ }
417
+ },
418
+ "data-currency-menu": ""
419
+ }
420
+ ),
421
+ void 0 !== error ? /* @__PURE__ */ jsx4("p", { className: "ec-currency__error", role: "alert", "data-currency-error": "", children: error }) : null
422
+ ] }) : null
423
+ }
424
+ );
425
+ }
426
+
427
+ // src/layout/headerActions.tsx
428
+ import { Button } from "@artisanpack-ui/react";
429
+ import { jsx as jsx5 } from "react/jsx-runtime";
430
+ function AccountAction() {
431
+ const { account } = useStorefront();
432
+ if (null === account) {
433
+ return null;
434
+ }
435
+ return /* @__PURE__ */ jsx5(
436
+ Button,
437
+ {
438
+ variant: "ghost",
439
+ color: "neutral",
440
+ size: "sm",
441
+ iconOnly: true,
442
+ leadingIcon: "user",
443
+ href: account.url,
444
+ "aria-label": account.label,
445
+ "data-header-action": "account"
446
+ }
447
+ );
448
+ }
449
+ function CurrencyAction() {
450
+ return /* @__PURE__ */ jsx5(CurrencySwitcher, { placement: "header" });
451
+ }
452
+ function registerHeaderActions(registries2) {
453
+ registries2.headerActions.register("currency", CurrencyAction, { position: 10 });
454
+ registries2.headerActions.register("account", AccountAction, { position: 20 });
455
+ registries2.headerActions.register("cart", CartHeaderButton, { position: 30 });
456
+ }
457
+ var headerActionsAdded = false;
458
+ function registerHeaderActionBuiltIns() {
459
+ if (headerActionsAdded) {
460
+ return;
461
+ }
462
+ headerActionsAdded = true;
463
+ addBuiltInRegistration(registerHeaderActions);
464
+ }
465
+
466
+ // src/components/Quantity.tsx
467
+ import { __ as __3 } from "@artisanpack-ui/ecommerce-storefront-core";
468
+ import { Button as Button2, Input } from "@artisanpack-ui/react";
469
+ import { jsx as jsx6 } from "react/jsx-runtime";
470
+ function Quantity({
471
+ id,
472
+ label = null,
473
+ min = 1,
474
+ max = null,
475
+ error = null,
476
+ itemName = null,
477
+ size = "md",
478
+ value,
479
+ onValueChange,
480
+ name,
481
+ disabled = false,
482
+ required = false,
483
+ placeholder,
484
+ className
485
+ }) {
486
+ const buttonSize = "sm" === size || "xs" === size ? "xs" : "sm";
487
+ const inputSize = "lg" === size ? "lg" : "sm" === size || "xs" === size ? "sm" : "md";
488
+ const atMin = null !== value && value <= min;
489
+ const atMax = null !== max && null !== value && value >= max;
490
+ const step = (direction) => {
491
+ if (disabled || (direction < 0 ? atMin : atMax)) {
492
+ return;
493
+ }
494
+ const current = null === value ? direction < 0 ? min + 1 : min - 1 : value;
495
+ let next = current + direction;
496
+ next = Math.max(min, null === max ? next : Math.min(max, next));
497
+ onValueChange(next);
498
+ };
499
+ return /* @__PURE__ */ jsx6("div", { className: cx("ec-quantity", className), "data-quantity": id, "data-size": size, children: /* @__PURE__ */ jsx6(
500
+ Input,
501
+ {
502
+ id,
503
+ name,
504
+ type: "number",
505
+ size: inputSize,
506
+ label: label ?? (null === itemName ? __3("Quantity") : __3("Quantity, :product", { product: itemName })),
507
+ error: null !== error && "" !== error ? error : void 0,
508
+ disabled,
509
+ required,
510
+ placeholder,
511
+ classes: null === label ? { label: "apui-sr-only" } : {},
512
+ inputMode: "numeric",
513
+ min,
514
+ max: max ?? void 0,
515
+ step: 1,
516
+ value: null === value ? "" : String(value),
517
+ onValueChange: (raw) => {
518
+ const number = "" === raw ? Number.NaN : Number(raw);
519
+ onValueChange(Number.isNaN(number) ? null : number);
520
+ },
521
+ "data-quantity-input": "",
522
+ prefix: /* @__PURE__ */ jsx6(
523
+ Button2,
524
+ {
525
+ variant: "ghost",
526
+ color: "neutral",
527
+ size: buttonSize,
528
+ iconOnly: true,
529
+ leadingIcon: "minus",
530
+ "aria-label": null === itemName ? __3("Decrease quantity") : __3("Decrease quantity, :name", { name: itemName }),
531
+ "aria-controls": id,
532
+ disabled,
533
+ "aria-disabled": atMin ? "true" : "false",
534
+ onClick: () => step(-1),
535
+ "data-quantity-decrease": ""
536
+ }
537
+ ),
538
+ suffix: /* @__PURE__ */ jsx6(
539
+ Button2,
540
+ {
541
+ variant: "ghost",
542
+ color: "neutral",
543
+ size: buttonSize,
544
+ iconOnly: true,
545
+ leadingIcon: "plus",
546
+ "aria-label": null === itemName ? __3("Increase quantity") : __3("Increase quantity, :name", { name: itemName }),
547
+ "aria-controls": id,
548
+ disabled,
549
+ "aria-disabled": atMax ? "true" : "false",
550
+ onClick: () => step(1),
551
+ "data-quantity-increase": ""
552
+ }
553
+ )
554
+ }
555
+ ) });
556
+ }
557
+
558
+ // src/toasts.ts
559
+ import { applyFilters } from "@artisanpack-ui/hooks-js";
560
+ import { HOOKS as HOOKS2 } from "@artisanpack-ui/ecommerce-storefront-core";
561
+ import { createToaster } from "@artisanpack-ui/react";
562
+ import { router as router2 } from "@inertiajs/react";
563
+ var toaster = null;
564
+ var TOAST_DURATION = 5e3;
565
+ function getStorefrontToaster() {
566
+ toaster ?? (toaster = createToaster({ max: 5, gap: 8, duration: TOAST_DURATION }));
567
+ return toaster;
568
+ }
569
+ var ROOT_RELATIVE = /^\/(?!\/)/;
570
+ var HTTP = /^https?:\/\//i;
571
+ function runToastAction(action) {
572
+ const url = action.url;
573
+ if (hasUnsafeCharacters(url)) {
574
+ return;
575
+ }
576
+ if ("post" === action.method) {
577
+ if (ROOT_RELATIVE.test(url) && isSameOrigin(url)) {
578
+ router2.post(url, {}, { preserveScroll: true });
579
+ }
580
+ return;
581
+ }
582
+ if (ROOT_RELATIVE.test(url) && isSameOrigin(url) || HTTP.test(url)) {
583
+ window.location.assign(url);
584
+ }
585
+ }
586
+ function showStorefrontToast(toast) {
587
+ const filtered = applyFilters(HOOKS2.toast, toast);
588
+ if (null === filtered || "object" !== typeof filtered) {
589
+ return null;
590
+ }
591
+ const shown = filtered;
592
+ const action = shown.action;
593
+ return getStorefrontToaster().create({
594
+ id: shown.id,
595
+ title: shown.title,
596
+ description: shown.description ?? void 0,
597
+ color: shown.color,
598
+ variant: shown.variant,
599
+ icon: shown.icon,
600
+ duration: void 0 === action ? TOAST_DURATION : Number.POSITIVE_INFINITY,
601
+ action: void 0 === action ? void 0 : { label: action.label, onClick: () => runToastAction(action) }
602
+ });
603
+ }
604
+ function showResponseToasts(body) {
605
+ const list = null !== body && "object" === typeof body ? body.toasts : null;
606
+ if (!Array.isArray(list)) {
607
+ return;
608
+ }
609
+ for (const toast of list) {
610
+ if (null !== toast && "object" === typeof toast && "string" === typeof toast.title) {
611
+ showStorefrontToast(toast);
612
+ }
613
+ }
614
+ }
615
+ function resetStorefrontToaster() {
616
+ toaster = null;
617
+ }
618
+
619
+ // src/components/EmptyState.tsx
620
+ import { Card, EmptyState as ApuiEmptyState } from "@artisanpack-ui/react";
621
+ import { jsx as jsx7 } from "react/jsx-runtime";
622
+ function EmptyState({
623
+ title,
624
+ description = null,
625
+ icon = "inbox",
626
+ size = "md",
627
+ headingLevel = 2,
628
+ card = false,
629
+ live = false,
630
+ children,
631
+ className,
632
+ ...rest
633
+ }) {
634
+ const body = /* @__PURE__ */ jsx7(
635
+ ApuiEmptyState,
636
+ {
637
+ ...card ? {} : rest,
638
+ className: cx("ec-empty-state", className),
639
+ role: live ? "status" : void 0,
640
+ "data-empty-state": "",
641
+ icon,
642
+ title,
643
+ description: filled(description) ? description : void 0,
644
+ size: "sm" === size ? "sm" : "md",
645
+ headingLevel,
646
+ actions: children
647
+ }
648
+ );
649
+ return card ? /* @__PURE__ */ jsx7(Card, { ...rest, className: "ec-empty-state-card", "data-empty-state-card": "", children: body }) : body;
650
+ }
651
+
652
+ // src/components/Money.tsx
653
+ import { MINUS, __ as __4 } from "@artisanpack-ui/ecommerce-storefront-core";
654
+ import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
655
+ function Money({ money, className, ...rest }) {
656
+ if (null === money || null === money.formatted) {
657
+ return /* @__PURE__ */ jsxs4("span", { ...rest, className: cx("ec-money", className), "data-tone": "muted", "data-money": "", children: [
658
+ /* @__PURE__ */ jsx8("span", { "aria-hidden": "true", children: "\u2014" }),
659
+ /* @__PURE__ */ jsx8("span", { className: "apui-sr-only", children: __4("No amount") })
660
+ ] });
661
+ }
662
+ return /* @__PURE__ */ jsxs4(
663
+ "span",
664
+ {
665
+ ...rest,
666
+ className: cx("ec-money", className),
667
+ "data-money": "",
668
+ "data-currency": money.currency,
669
+ children: [
670
+ /* @__PURE__ */ jsxs4("bdi", { dir: "ltr", children: [
671
+ money.negative ? /* @__PURE__ */ jsxs4(Fragment3, { children: [
672
+ /* @__PURE__ */ jsx8("span", { "aria-hidden": "true", children: MINUS }),
673
+ /* @__PURE__ */ jsxs4("span", { className: "apui-sr-only", children: [
674
+ __4("Minus"),
675
+ " "
676
+ ] })
677
+ ] }) : null,
678
+ money.magnitude ?? money.formatted
679
+ ] }),
680
+ null !== money.equivalent ? /* @__PURE__ */ jsxs4("span", { className: "ec-money__equivalent", "data-money-equivalent": "", children: [
681
+ /* @__PURE__ */ jsx8("span", { "aria-hidden": "true", children: "\u2248 " }),
682
+ /* @__PURE__ */ jsxs4("span", { className: "apui-sr-only", children: [
683
+ __4("approximately"),
684
+ " "
685
+ ] }),
686
+ /* @__PURE__ */ jsx8("bdi", { dir: "ltr", children: money.equivalent })
687
+ ] }) : null
688
+ ]
689
+ }
690
+ );
691
+ }
692
+
693
+ // src/cart/LineControls.tsx
694
+ import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
695
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
696
+ var QUANTITY_COMMIT_DELAY = 500;
697
+ function LineControls({
698
+ id,
699
+ itemName,
700
+ size,
701
+ quantity,
702
+ max,
703
+ error,
704
+ disabled = false,
705
+ onCommit,
706
+ children
707
+ }) {
708
+ const [value, setValue] = useState2(quantity);
709
+ const [shown, setShown] = useState2(quantity);
710
+ const timer = useRef2(null);
711
+ const pending = useRef2(null);
712
+ if (shown !== quantity) {
713
+ setShown(quantity);
714
+ setValue(quantity);
715
+ }
716
+ const flush = () => {
717
+ if (null !== timer.current) {
718
+ clearTimeout(timer.current);
719
+ timer.current = null;
720
+ }
721
+ const next = pending.current;
722
+ pending.current = null;
723
+ if (null !== next && next !== quantity) {
724
+ onCommit(next);
725
+ }
726
+ };
727
+ useEffect2(
728
+ () => () => {
729
+ if (null !== timer.current) {
730
+ clearTimeout(timer.current);
731
+ }
732
+ },
733
+ []
734
+ );
735
+ return /* @__PURE__ */ jsxs5(
736
+ "div",
737
+ {
738
+ className: "ec-cart-line__controls",
739
+ onBlur: (event) => {
740
+ if (!event.currentTarget.contains(event.relatedTarget)) {
741
+ flush();
742
+ }
743
+ },
744
+ children: [
745
+ /* @__PURE__ */ jsx9(
746
+ Quantity,
747
+ {
748
+ id,
749
+ itemName,
750
+ size,
751
+ min: 1,
752
+ max,
753
+ error,
754
+ disabled,
755
+ value,
756
+ onValueChange: (next) => {
757
+ setValue(next);
758
+ if (null === next || next < 1) {
759
+ pending.current = null;
760
+ return;
761
+ }
762
+ pending.current = Math.min(next, max);
763
+ if (null !== timer.current) {
764
+ clearTimeout(timer.current);
765
+ }
766
+ timer.current = setTimeout(flush, QUANTITY_COMMIT_DELAY);
767
+ }
768
+ }
769
+ ),
770
+ children
771
+ ]
772
+ }
773
+ );
774
+ }
775
+
776
+ // src/cart/useFocusAfterChange.ts
777
+ import { useEffect as useEffect3, useRef as useRef3 } from "react";
778
+ function focusLost() {
779
+ return null === document.activeElement || document.activeElement === document.body;
780
+ }
781
+ function useFocusAfterChange(root, feedback, fallback) {
782
+ const handled2 = useRef3(null);
783
+ useEffect3(() => {
784
+ if (null === feedback || handled2.current === feedback || null === feedback.removedLine && null === feedback.restoredLineId) {
785
+ return;
786
+ }
787
+ handled2.current = feedback;
788
+ const timer = setTimeout(() => {
789
+ if (!focusLost()) {
790
+ return;
791
+ }
792
+ const scope = root.current ?? document;
793
+ const target = (null === feedback.restoredLineId ? null : scope.querySelector(
794
+ `[data-cart-line="${feedback.restoredLineId}"] [data-cart-line-remove]`
795
+ )) ?? scope.querySelector("[data-cart-undo-button]") ?? scope.querySelector(fallback) ?? document.querySelector(fallback);
796
+ target?.focus();
797
+ });
798
+ return () => clearTimeout(timer);
799
+ }, [feedback, root, fallback]);
800
+ }
801
+
802
+ // src/cart/CartDrawer.tsx
803
+ import {
804
+ __ as __5,
805
+ trans_choice as trans_choice2
806
+ } from "@artisanpack-ui/ecommerce-storefront-core";
807
+ import { Badge as Badge3, Button as Button3, Drawer, Icon as Icon2, Progress } from "@artisanpack-ui/react";
808
+ import { router as router3 } from "@inertiajs/react";
809
+ import { useEffect as useEffect4, useRef as useRef4, useState as useState3 } from "react";
810
+ import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
811
+ var CART_DRAWER_CONTENT_ID = "ecommerce-cart-drawer-content";
812
+ function DrawerLine({ line, cartUrl, error, removing, onRemove }) {
813
+ const writeOnly = cartWriteOnly(useStorefrontPage().component);
814
+ const remove = /* @__PURE__ */ jsx10(
815
+ Button3,
816
+ {
817
+ variant: "link",
818
+ color: "neutral",
819
+ size: "sm",
820
+ "aria-label": __5("Remove :name", { name: line.name }),
821
+ disabled: removing,
822
+ onClick: () => onRemove(line),
823
+ "data-cart-line-remove": "",
824
+ children: __5("Remove")
825
+ }
826
+ );
827
+ return /* @__PURE__ */ jsxs6("li", { className: "ec-cart-line", "data-cart-line": line.id, children: [
828
+ /* @__PURE__ */ jsx10("span", { className: "ec-cart-line__thumb", children: null !== line.image ? /* @__PURE__ */ jsx10(
829
+ "img",
830
+ {
831
+ src: line.image.url,
832
+ ...null !== line.image.srcset ? { srcSet: line.image.srcset, sizes: "64px" } : {},
833
+ width: 64,
834
+ height: 64,
835
+ alt: "",
836
+ loading: "lazy",
837
+ decoding: "async"
838
+ }
839
+ ) : null }),
840
+ /* @__PURE__ */ jsxs6("div", { className: "ec-cart-line__body", children: [
841
+ /* @__PURE__ */ jsxs6("div", { className: "ec-cart-line__head", children: [
842
+ /* @__PURE__ */ jsx10("h3", { className: "ec-cart-line__name", children: null !== line.url ? /* @__PURE__ */ jsx10("a", { href: line.url, children: line.name }) : line.name }),
843
+ line.free ? /* @__PURE__ */ jsx10("span", { className: "ec-cart-line__total", "data-cart-line-total": "", children: __5("Free") }) : /* @__PURE__ */ jsx10(Money, { money: line.total, className: "ec-cart-line__total", "data-cart-line-total": "" })
844
+ ] }),
845
+ line.options.length > 0 ? /* @__PURE__ */ jsx10("p", { className: "ec-cart-line__options", children: line.options.join(" \xB7 ") }) : null,
846
+ null !== line.unsellable ? /* @__PURE__ */ jsx10(
847
+ "p",
848
+ {
849
+ className: "ec-cart-line__problem",
850
+ "data-cart-line-unsellable": "",
851
+ ...line.short ? { "data-cart-line-short": "" } : {},
852
+ children: line.unsellable
853
+ }
854
+ ) : null,
855
+ line.free ? /* @__PURE__ */ jsx10(Badge3, { variant: "soft", color: "success", size: "sm", leadingIcon: "gift", "data-cart-line-free": "", children: __5("Free gift") }) : null === line.unsellable || line.short ? /* @__PURE__ */ jsx10(
856
+ LineControls,
857
+ {
858
+ id: `ec-drawer-quantity-${line.id}`,
859
+ itemName: line.name,
860
+ size: "xs",
861
+ quantity: line.quantity,
862
+ max: line.maxQuantity,
863
+ error,
864
+ onCommit: (quantity) => {
865
+ if (null === cartUrl) {
866
+ return;
867
+ }
868
+ router3.patch(
869
+ cartActionUrl(cartUrl, `lines/${line.id}`),
870
+ { quantity },
871
+ { only: writeOnly, preserveScroll: true, preserveState: true }
872
+ );
873
+ },
874
+ children: remove
875
+ }
876
+ ) : /* @__PURE__ */ jsx10("div", { className: "ec-cart-line__controls", children: remove })
877
+ ] })
878
+ ] });
879
+ }
880
+ function DrawerFooter({ cart }) {
881
+ const blocked = cart.checkoutBlocked;
882
+ return /* @__PURE__ */ jsxs6("div", { className: "ec-cart-drawer__footer", children: [
883
+ /* @__PURE__ */ jsxs6("div", { className: "ec-cart-drawer__subtotal", children: [
884
+ /* @__PURE__ */ jsx10("span", { children: __5("Subtotal") }),
885
+ /* @__PURE__ */ jsx10(Money, { money: cart.totals?.subtotal ?? null, "data-cart-subtotal": "" })
886
+ ] }),
887
+ /* @__PURE__ */ jsx10("p", { className: "ec-cart-drawer__note", children: __5("Shipping and tax are calculated at checkout.") }),
888
+ null !== blocked ? /* @__PURE__ */ jsx10("p", { className: "ec-cart-drawer__blocked", "data-cart-drawer-blocked": "", children: "short" === blocked ? __5("Lower the quantities marked to check out.") : __5("Remove the items that can't be bought to check out.") }) : null,
889
+ /* @__PURE__ */ jsxs6("div", { className: "ec-cart-drawer__actions", children: [
890
+ null !== cart.urls.cart ? /* @__PURE__ */ jsx10(Button3, { variant: "outline", color: "neutral", href: cart.urls.cart, "data-cart-drawer-view": "", children: __5("View cart") }) : null,
891
+ null === blocked && null !== cart.urls.checkout ? /* @__PURE__ */ jsx10(Button3, { href: cart.urls.checkout, color: "primary", "data-cart-drawer-checkout": "", children: __5("Checkout") }) : null
892
+ ] })
893
+ ] });
894
+ }
895
+ function CartDrawer() {
896
+ useRegisterCartDrawer();
897
+ const shared = useStorefront();
898
+ const cart = useStorefrontCart();
899
+ const errors = usePageErrors();
900
+ const { open, setOpen, opener: openerRef } = useCartDrawer();
901
+ const panel = useRef4(null);
902
+ const returnTo = useRef4(null);
903
+ const [removing, setRemoving] = useState3(null);
904
+ const [undoing, setUndoing] = useState3(false);
905
+ const count = null === cart ? shared.cart.count : cart.count;
906
+ const cartUrl = cart?.urls.cart ?? shared.cart.url;
907
+ const catalogUrl = cart?.urls.catalog ?? shared.routes.storefront.base;
908
+ const feedback = cart?.feedback ?? null;
909
+ const writeOnly = cartWriteOnly(useStorefrontPage().component);
910
+ useFocusAfterChange(panel, feedback, `#${CART_DRAWER_CONTENT_ID}`);
911
+ useEffect4(() => {
912
+ if (open && null === cart) {
913
+ router3.reload({ only: CART_DRAWER_ONLY });
914
+ }
915
+ }, [open, cart]);
916
+ useEffect4(() => {
917
+ const remember = (event) => {
918
+ const target = event.target;
919
+ if (target instanceof HTMLElement && !document.getElementById(CART_DRAWER_CONTENT_ID)?.contains(target)) {
920
+ returnTo.current = target;
921
+ }
922
+ };
923
+ window.addEventListener("focusin", remember);
924
+ return () => window.removeEventListener("focusin", remember);
925
+ }, []);
926
+ const close = () => {
927
+ setOpen(false);
928
+ const target = openerRef.current ?? returnTo.current;
929
+ openerRef.current = null;
930
+ setTimeout(() => {
931
+ if (null !== target && target.isConnected && (null === document.activeElement || document.activeElement === document.body || document.getElementById(CART_DRAWER_CONTENT_ID)?.contains(document.activeElement))) {
932
+ target.focus();
933
+ }
934
+ }, 50);
935
+ };
936
+ const onRemove = (line) => {
937
+ if (null === cartUrl) {
938
+ return;
939
+ }
940
+ setRemoving(line.id);
941
+ router3.delete(cartActionUrl(cartUrl, `lines/${line.id}`), {
942
+ only: writeOnly,
943
+ preserveScroll: true,
944
+ preserveState: true,
945
+ onFinish: () => setRemoving(null)
946
+ });
947
+ };
948
+ const undo = () => {
949
+ if (null === cartUrl) {
950
+ return;
951
+ }
952
+ setUndoing(true);
953
+ router3.post(
954
+ cartActionUrl(cartUrl, "undo"),
955
+ {},
956
+ {
957
+ only: writeOnly,
958
+ preserveScroll: true,
959
+ preserveState: true,
960
+ onFinish: () => setUndoing(false)
961
+ }
962
+ );
963
+ };
964
+ const lines = cart?.lines ?? [];
965
+ const loaded = null !== cart;
966
+ let body;
967
+ if (!loaded && count > 0) {
968
+ body = /* @__PURE__ */ jsx10("div", { className: "ec-cart-drawer__loading", "aria-busy": "true", "data-cart-loading": "", children: /* @__PURE__ */ jsx10("p", { children: __5("Loading\u2026") }) });
969
+ } else if (0 === lines.length) {
970
+ body = /* @__PURE__ */ jsx10(
971
+ EmptyState,
972
+ {
973
+ icon: "shopping-bag",
974
+ title: __5("Your cart is empty"),
975
+ size: "sm",
976
+ headingLevel: 3,
977
+ className: "ec-cart-drawer__empty",
978
+ live: true,
979
+ "data-cart-empty": "",
980
+ children: null !== catalogUrl ? /* @__PURE__ */ jsx10(Button3, { variant: "outline", color: "neutral", size: "sm", href: catalogUrl, children: __5("Continue shopping") }) : null
981
+ }
982
+ );
983
+ } else {
984
+ body = /* @__PURE__ */ jsxs6(Fragment4, { children: [
985
+ null !== cart && null !== cart.freeShipping ? /* @__PURE__ */ jsxs6(
986
+ "div",
987
+ {
988
+ className: "ec-cart-drawer__shipping",
989
+ "data-cart-free-shipping": "",
990
+ ...cart.freeShipping.unlocked ? { "data-unlocked": "" } : {},
991
+ children: [
992
+ /* @__PURE__ */ jsxs6("p", { id: "ecommerce-cart-drawer-shipping", className: "ec-cart-drawer__shipping-text", children: [
993
+ /* @__PURE__ */ jsx10(Icon2, { name: "truck" }),
994
+ /* @__PURE__ */ jsx10("span", { children: cart.freeShipping.unlocked ? __5("You've unlocked free shipping") : __5("Add :amount more for free shipping", {
995
+ amount: cart.freeShipping.remaining ?? ""
996
+ }) })
997
+ ] }),
998
+ /* @__PURE__ */ jsx10(
999
+ Progress,
1000
+ {
1001
+ value: cart.freeShipping.percent,
1002
+ color: "success",
1003
+ size: "sm",
1004
+ "aria-labelledby": "ecommerce-cart-drawer-shipping"
1005
+ }
1006
+ )
1007
+ ]
1008
+ }
1009
+ ) : null,
1010
+ /* @__PURE__ */ jsx10("ul", { className: "ec-cart-drawer__lines", "data-cart-lines": "", children: lines.map((line) => /* @__PURE__ */ jsx10(
1011
+ DrawerLine,
1012
+ {
1013
+ line,
1014
+ cartUrl,
1015
+ error: errors[`quantities.${line.id}`] ?? null,
1016
+ removing: removing === line.id,
1017
+ onRemove
1018
+ },
1019
+ line.id
1020
+ )) })
1021
+ ] });
1022
+ }
1023
+ return /* @__PURE__ */ jsx10("div", { "data-ecommerce-cart-drawer": "", children: /* @__PURE__ */ jsx10(
1024
+ Drawer,
1025
+ {
1026
+ id: CART_DRAWER_CONTENT_ID,
1027
+ side: "end",
1028
+ className: "ec-cart-drawer",
1029
+ title: __5("Your cart"),
1030
+ description: trans_choice2(":count item|:count items", count, { count }),
1031
+ closeLabel: __5("Close cart"),
1032
+ open,
1033
+ onOpenChange: (next) => next ? setOpen(true) : close(),
1034
+ footer: loaded && lines.length > 0 && null !== cart ? /* @__PURE__ */ jsx10(DrawerFooter, { cart }) : void 0,
1035
+ children: /* @__PURE__ */ jsxs6("div", { id: "ecommerce-cart-drawer-panel", className: "ec-cart-drawer__panel", ref: panel, children: [
1036
+ /* @__PURE__ */ jsx10("p", { className: "apui-sr-only", role: "status", "aria-live": "polite", "aria-atomic": "true", children: feedback?.announcement ?? "" }),
1037
+ null !== feedback && null !== feedback.removedLine && feedback.removedLine.undoable ? /* @__PURE__ */ jsxs6("div", { className: "ec-cart-drawer__undo", "data-cart-undo": "", children: [
1038
+ /* @__PURE__ */ jsx10("span", { children: __5(":name was removed from your cart.", { name: feedback.removedLine.name }) }),
1039
+ /* @__PURE__ */ jsx10(
1040
+ Button3,
1041
+ {
1042
+ variant: "outline",
1043
+ color: "neutral",
1044
+ size: "sm",
1045
+ disabled: undoing,
1046
+ onClick: undo,
1047
+ "data-cart-undo-button": "",
1048
+ children: __5("Undo")
1049
+ }
1050
+ )
1051
+ ] }) : null,
1052
+ body
1053
+ ] })
1054
+ }
1055
+ ) });
1056
+ }
1057
+
1058
+ // src/cart/MergePrompt.tsx
1059
+ import { __ as __6 } from "@artisanpack-ui/ecommerce-storefront-core";
1060
+ import { Button as Button4, Dialog } from "@artisanpack-ui/react";
1061
+ import { router as router4 } from "@inertiajs/react";
1062
+ import { useEffect as useEffect5, useState as useState4 } from "react";
1063
+ import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
1064
+ var MERGE_PRIMARY_ID = "ecommerce-cart-merge-primary";
1065
+ function MergePrompt() {
1066
+ const { cartMerge } = useStorefront();
1067
+ const [pending, setPending] = useState4(false);
1068
+ const open = null !== cartMerge && void 0 !== cartMerge;
1069
+ useEffect5(() => {
1070
+ if (!open) {
1071
+ return;
1072
+ }
1073
+ const timer = setTimeout(() => document.getElementById(MERGE_PRIMARY_ID)?.focus(), 80);
1074
+ return () => clearTimeout(timer);
1075
+ }, [open]);
1076
+ useEffect5(() => {
1077
+ if (!open) {
1078
+ return;
1079
+ }
1080
+ const swallow = (event) => {
1081
+ if ("Escape" === event.key) {
1082
+ event.stopPropagation();
1083
+ event.preventDefault();
1084
+ }
1085
+ };
1086
+ window.addEventListener("keydown", swallow, true);
1087
+ return () => window.removeEventListener("keydown", swallow, true);
1088
+ }, [open]);
1089
+ const resolve = (resolution) => {
1090
+ if (!open) {
1091
+ return;
1092
+ }
1093
+ setPending(true);
1094
+ router4.post(
1095
+ cartMerge.url,
1096
+ { resolution },
1097
+ { preserveScroll: true, onFinish: () => setPending(false) }
1098
+ );
1099
+ };
1100
+ return /* @__PURE__ */ jsx11("div", { "data-ecommerce-cart-merge-prompt": "", children: open ? /* @__PURE__ */ jsx11(
1101
+ Dialog,
1102
+ {
1103
+ id: "ecommerce-cart-merge",
1104
+ open: true,
1105
+ role: "alertdialog",
1106
+ color: "primary",
1107
+ icon: "shopping-bag",
1108
+ hideClose: true,
1109
+ className: "ec-merge-prompt",
1110
+ title: __6("Combine your carts?"),
1111
+ description: __6(
1112
+ "The cart you filled before signing in is in :guest, but the cart saved to your account is in :account.",
1113
+ { guest: cartMerge.guestCurrency, account: cartMerge.accountCurrency }
1114
+ ),
1115
+ footer: cartMerge.choices.map((choice) => /* @__PURE__ */ jsx11(
1116
+ Button4,
1117
+ {
1118
+ variant: choice.variant,
1119
+ color: "solid" === choice.variant ? "primary" : "neutral",
1120
+ id: "solid" === choice.variant ? MERGE_PRIMARY_ID : void 0,
1121
+ disabled: pending,
1122
+ onClick: () => resolve(choice.value),
1123
+ "data-merge-choice": choice.value,
1124
+ children: choice.label
1125
+ },
1126
+ choice.value
1127
+ )),
1128
+ children: /* @__PURE__ */ jsxs7("div", { id: "ecommerce-cart-merge-details", className: "ec-merge-prompt__details", children: [
1129
+ /* @__PURE__ */ jsx11("p", { children: __6(
1130
+ "Choose the currency for your combined cart. Prices are worked out again in that currency."
1131
+ ) }),
1132
+ /* @__PURE__ */ jsx11("p", { className: "ec-merge-prompt__note", children: __6(
1133
+ "Don't merge keeps your saved cart and discards the items added before signing in."
1134
+ ) })
1135
+ ] })
1136
+ }
1137
+ ) : null });
1138
+ }
1139
+
1140
+ // src/search/HeaderSearch.tsx
1141
+ import {
1142
+ __ as __7,
1143
+ trans_choice as trans_choice3
1144
+ } from "@artisanpack-ui/ecommerce-storefront-core";
1145
+ import { Icon as Icon3, Input as Input2, Kbd } from "@artisanpack-ui/react";
1146
+ import {
1147
+ useEffect as useEffect6,
1148
+ useRef as useRef5,
1149
+ useState as useState5
1150
+ } from "react";
1151
+ import { Fragment as Fragment5, jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
1152
+ var MIN_LENGTH = 2;
1153
+ var TYPING_TARGETS = "input, textarea, select, iframe, [contenteditable]:not([contenteditable=false]), [role=textbox], [role=searchbox], [role=combobox], [role=listbox], [role=grid], [role=menu], [role=slider], [role=spinbutton]";
1154
+ function suggestionsUrl(searchUrl) {
1155
+ const [path = "", query] = searchUrl.split("?", 2);
1156
+ return `${path.replace(/\/+$/, "")}/suggest${void 0 === query ? "" : `?${query}`}`;
1157
+ }
1158
+ function idle(term, searchUrl) {
1159
+ return {
1160
+ term,
1161
+ state: "idle",
1162
+ error: null,
1163
+ products: [],
1164
+ categories: [],
1165
+ total: 0,
1166
+ searchUrl,
1167
+ allUrl: null
1168
+ };
1169
+ }
1170
+ function marked(parts) {
1171
+ return parts.map(
1172
+ (part, index) => part.match ? /* @__PURE__ */ jsx12("mark", { className: "ec-search__match", children: part.text }, index) : part.text
1173
+ );
1174
+ }
1175
+ function HeaderSearch({
1176
+ inputId = "ecommerce-header-search",
1177
+ debounce = 300,
1178
+ defaultQuery = "",
1179
+ defaultResults,
1180
+ defaultOpen = false,
1181
+ defaultLoading = false
1182
+ }) {
1183
+ const { search } = useStorefront();
1184
+ const searchUrl = search.url;
1185
+ const shortcut = search.shortcut;
1186
+ const listboxId = `${inputId}-results`;
1187
+ const [q, setQ] = useState5(defaultQuery);
1188
+ const [open, setOpen] = useState5(defaultOpen);
1189
+ const [active, setActive] = useState5(-1);
1190
+ const [loading, setLoading] = useState5(defaultLoading);
1191
+ const [results, setResults] = useState5(
1192
+ () => defaultResults ?? idle(defaultQuery, searchUrl)
1193
+ );
1194
+ const root = useRef5(null);
1195
+ const listbox = useRef5(null);
1196
+ const timer = useRef5(void 0);
1197
+ const request = useRef5(null);
1198
+ useEffect6(
1199
+ () => () => {
1200
+ clearTimeout(timer.current);
1201
+ request.current?.abort();
1202
+ },
1203
+ []
1204
+ );
1205
+ useEffect6(() => {
1206
+ if (!shortcut) {
1207
+ return void 0;
1208
+ }
1209
+ const onKeyDown2 = (event) => {
1210
+ if ("/" !== event.key || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
1211
+ return;
1212
+ }
1213
+ if (null !== document.querySelector("[aria-modal=true]:not([hidden])")) {
1214
+ return;
1215
+ }
1216
+ const target = event.target;
1217
+ if (target instanceof Element && null !== target.closest(TYPING_TARGETS)) {
1218
+ return;
1219
+ }
1220
+ const input = root.current?.querySelector("input[role=combobox]");
1221
+ if (void 0 !== input && null !== input && null !== input.offsetParent) {
1222
+ event.preventDefault();
1223
+ input.focus();
1224
+ }
1225
+ };
1226
+ window.addEventListener("keydown", onKeyDown2);
1227
+ return () => window.removeEventListener("keydown", onKeyDown2);
1228
+ }, [shortcut]);
1229
+ useEffect6(() => {
1230
+ const onPointerDown = (event) => {
1231
+ if (null !== root.current && !root.current.contains(event.target)) {
1232
+ setOpen(false);
1233
+ setActive(-1);
1234
+ }
1235
+ };
1236
+ document.addEventListener("mousedown", onPointerDown);
1237
+ return () => document.removeEventListener("mousedown", onPointerDown);
1238
+ }, []);
1239
+ const lookUp = (term) => {
1240
+ clearTimeout(timer.current);
1241
+ request.current?.abort();
1242
+ const trimmed = term.trim();
1243
+ if (trimmed.length < MIN_LENGTH || null === searchUrl) {
1244
+ setLoading(false);
1245
+ setResults(idle(trimmed, searchUrl));
1246
+ return;
1247
+ }
1248
+ timer.current = setTimeout(() => {
1249
+ const controller = new AbortController();
1250
+ const url = suggestionsUrl(searchUrl);
1251
+ request.current = controller;
1252
+ setLoading(true);
1253
+ fetch(`${url}${url.includes("?") ? "&" : "?"}q=${encodeURIComponent(trimmed)}`, {
1254
+ headers: { Accept: "application/json", "X-Requested-With": "XMLHttpRequest" },
1255
+ credentials: "same-origin",
1256
+ signal: controller.signal
1257
+ }).then(async (response) => {
1258
+ if (!response.ok) {
1259
+ throw new Error(`Suggestions answered ${response.status}.`);
1260
+ }
1261
+ return await response.json();
1262
+ }).then((answer) => {
1263
+ setResults(answer);
1264
+ setActive(-1);
1265
+ }).catch((error) => {
1266
+ if (error instanceof DOMException && "AbortError" === error.name) {
1267
+ return;
1268
+ }
1269
+ setResults({ ...idle(trimmed, searchUrl), state: "failed" });
1270
+ }).finally(() => {
1271
+ if (request.current === controller) {
1272
+ request.current = null;
1273
+ setLoading(false);
1274
+ }
1275
+ });
1276
+ }, debounce);
1277
+ };
1278
+ const options = () => null !== listbox.current ? Array.from(listbox.current.querySelectorAll("[role=option]")) : [];
1279
+ const move = (step) => {
1280
+ const list = options();
1281
+ setOpen(true);
1282
+ if (0 === list.length) {
1283
+ setActive(-1);
1284
+ return;
1285
+ }
1286
+ const next = active < 0 && step < 0 ? list.length - 1 : (active + step + list.length) % list.length;
1287
+ setActive(next);
1288
+ list[next]?.scrollIntoView?.({ block: "nearest" });
1289
+ };
1290
+ const close = () => {
1291
+ setOpen(false);
1292
+ setActive(-1);
1293
+ };
1294
+ const onKeyDown = (event) => {
1295
+ if ("ArrowDown" === event.key) {
1296
+ event.preventDefault();
1297
+ move(1);
1298
+ } else if ("ArrowUp" === event.key) {
1299
+ event.preventDefault();
1300
+ move(-1);
1301
+ } else if ("Escape" === event.key && open) {
1302
+ event.preventDefault();
1303
+ close();
1304
+ }
1305
+ };
1306
+ const onSubmit = (event) => {
1307
+ const option2 = open ? options()[active] : void 0;
1308
+ const href = option2?.getAttribute("href");
1309
+ if (void 0 !== option2 && null !== href && void 0 !== href) {
1310
+ event.preventDefault();
1311
+ window.location.assign(href);
1312
+ }
1313
+ };
1314
+ const state = results.state;
1315
+ const products = results.products.filter((product) => null !== product.url);
1316
+ const categories = results.categories.filter((category) => null !== category.url);
1317
+ const suggestionCount = products.length + categories.length;
1318
+ const optionCount = suggestionCount + (null === results.allUrl ? 0 : 1);
1319
+ const expanded = open && (optionCount > 0 || "idle" !== state);
1320
+ const activeId = open && active >= 0 && active < optionCount ? `${listboxId}-option-${active}` : void 0;
1321
+ let index = 0;
1322
+ const option = (href, className, data, children) => {
1323
+ const current = index++;
1324
+ return /* @__PURE__ */ jsx12(
1325
+ "a",
1326
+ {
1327
+ id: `${listboxId}-option-${current}`,
1328
+ href,
1329
+ role: "option",
1330
+ tabIndex: -1,
1331
+ className,
1332
+ "data-scope": "dropdown-menu",
1333
+ "data-part": "item",
1334
+ "data-highlighted": active === current ? "" : void 0,
1335
+ "aria-selected": active === current ? "true" : "false",
1336
+ onMouseEnter: () => setActive(current),
1337
+ ...data,
1338
+ children
1339
+ },
1340
+ `${listboxId}-option-${current}`
1341
+ );
1342
+ };
1343
+ return /* @__PURE__ */ jsxs8(
1344
+ "div",
1345
+ {
1346
+ ref: root,
1347
+ className: "ec-search",
1348
+ onBlur: (event) => {
1349
+ if (null === root.current || !root.current.contains(event.relatedTarget)) {
1350
+ close();
1351
+ }
1352
+ },
1353
+ "data-header-search": "",
1354
+ children: [
1355
+ /* @__PURE__ */ jsx12(
1356
+ "form",
1357
+ {
1358
+ method: "GET",
1359
+ action: searchUrl ?? void 0,
1360
+ role: "search",
1361
+ onSubmit,
1362
+ "data-header-search-form": "",
1363
+ children: /* @__PURE__ */ jsx12(
1364
+ Input2,
1365
+ {
1366
+ id: inputId,
1367
+ type: "search",
1368
+ name: "q",
1369
+ placeholder: __7("Search products"),
1370
+ "aria-label": __7("Search products"),
1371
+ leadingIcon: "search",
1372
+ value: q,
1373
+ onValueChange: (value) => {
1374
+ setQ(value);
1375
+ setOpen(true);
1376
+ setActive(-1);
1377
+ lookUp(value);
1378
+ },
1379
+ autoComplete: "off",
1380
+ enterKeyHint: "search",
1381
+ "aria-keyshortcuts": shortcut ? "/" : void 0,
1382
+ role: "combobox",
1383
+ "aria-autocomplete": "list",
1384
+ "aria-controls": listboxId,
1385
+ "aria-haspopup": "listbox",
1386
+ "aria-expanded": expanded ? "true" : "false",
1387
+ "aria-activedescendant": activeId,
1388
+ onFocus: () => setOpen(true),
1389
+ onKeyDown,
1390
+ className: "ec-search__field",
1391
+ iconEnd: shortcut ? /* @__PURE__ */ jsx12(Kbd, { size: "sm", className: "ec-search__hint", children: "/" }) : void 0
1392
+ }
1393
+ )
1394
+ }
1395
+ ),
1396
+ /* @__PURE__ */ jsx12(
1397
+ "p",
1398
+ {
1399
+ className: "apui-sr-only",
1400
+ role: "status",
1401
+ "aria-live": "polite",
1402
+ "aria-atomic": "true",
1403
+ "data-header-search-status": "",
1404
+ children: "results" === state ? trans_choice3(":count suggestion|:count suggestions", suggestionCount, {
1405
+ count: suggestionCount
1406
+ }) : "throttled" === state ? __7("Too many searches. Press Enter to see all results.") : "failed" === state ? __7("Suggestions aren't available right now. Press Enter to search.") : null
1407
+ }
1408
+ ),
1409
+ /* @__PURE__ */ jsxs8(
1410
+ "div",
1411
+ {
1412
+ className: "apui-dropdown-menu ec-search__popover",
1413
+ "data-surface": "overlay",
1414
+ hidden: "idle" === state,
1415
+ style: open ? void 0 : { display: "none" },
1416
+ "data-loading": loading ? "" : void 0,
1417
+ "data-header-search-popover": "",
1418
+ children: [
1419
+ "throttled" === state ? /* @__PURE__ */ jsx12("p", { className: "ec-search__message", "data-header-search-throttled": "", children: __7("Too many searches. Press Enter to see all results.") }) : "failed" === state ? /* @__PURE__ */ jsx12("p", { className: "ec-search__message", "data-header-search-failed": "", children: __7("Suggestions aren't available right now. Press Enter to search.") }) : "results" === state && 0 === optionCount ? /* @__PURE__ */ jsx12("p", { className: "ec-search__message", "data-header-search-empty": "", children: __7('No matches for ":term".', { term: results.term }) }) : null,
1420
+ /* @__PURE__ */ jsxs8(
1421
+ "div",
1422
+ {
1423
+ id: listboxId,
1424
+ ref: listbox,
1425
+ role: "listbox",
1426
+ "aria-label": __7("Search suggestions"),
1427
+ className: "ec-search__results",
1428
+ "data-header-search-results": "",
1429
+ children: [
1430
+ products.length > 0 ? /* @__PURE__ */ jsxs8("div", { role: "group", "aria-labelledby": `${listboxId}-products`, children: [
1431
+ /* @__PURE__ */ jsx12(
1432
+ "p",
1433
+ {
1434
+ id: `${listboxId}-products`,
1435
+ role: "presentation",
1436
+ "data-scope": "dropdown-menu",
1437
+ "data-part": "item-group-label",
1438
+ children: __7("Products")
1439
+ }
1440
+ ),
1441
+ products.map(
1442
+ (product) => option(
1443
+ product.url,
1444
+ "ec-search__option ec-search__option--product",
1445
+ { "data-header-search-product": String(product.id) },
1446
+ /* @__PURE__ */ jsxs8(Fragment5, { children: [
1447
+ /* @__PURE__ */ jsx12("span", { className: "ec-search__thumb", "aria-hidden": "true", children: null !== product.image ? /* @__PURE__ */ jsx12(
1448
+ "img",
1449
+ {
1450
+ src: product.image.url,
1451
+ srcSet: product.image.srcset ?? void 0,
1452
+ sizes: null !== product.image.srcset ? "36px" : void 0,
1453
+ width: 36,
1454
+ height: 36,
1455
+ alt: "",
1456
+ loading: "lazy",
1457
+ decoding: "async"
1458
+ }
1459
+ ) : null }),
1460
+ /* @__PURE__ */ jsxs8("span", { className: "ec-search__text", children: [
1461
+ /* @__PURE__ */ jsx12("span", { className: "ec-search__name", children: marked(product.parts) }),
1462
+ null !== product.category ? /* @__PURE__ */ jsx12("span", { className: "ec-search__meta", "data-header-search-category-name": "", children: product.category }) : null
1463
+ ] }),
1464
+ null !== product.price ? /* @__PURE__ */ jsx12(Price, { price: product.price, size: "sm", className: "ec-search__price" }) : null
1465
+ ] })
1466
+ )
1467
+ )
1468
+ ] }) : null,
1469
+ categories.length > 0 ? /* @__PURE__ */ jsxs8("div", { role: "group", "aria-labelledby": `${listboxId}-categories`, children: [
1470
+ /* @__PURE__ */ jsx12(
1471
+ "p",
1472
+ {
1473
+ id: `${listboxId}-categories`,
1474
+ role: "presentation",
1475
+ "data-scope": "dropdown-menu",
1476
+ "data-part": "item-group-label",
1477
+ children: __7("Categories")
1478
+ }
1479
+ ),
1480
+ categories.map(
1481
+ (category) => option(
1482
+ category.url,
1483
+ "ec-search__option",
1484
+ { "data-header-search-category": String(category.id) },
1485
+ /* @__PURE__ */ jsxs8(Fragment5, { children: [
1486
+ /* @__PURE__ */ jsx12(Icon3, { name: "folder", className: "ec-search__icon" }),
1487
+ /* @__PURE__ */ jsx12("span", { className: "ec-search__name", children: marked(category.parts) })
1488
+ ] })
1489
+ )
1490
+ )
1491
+ ] }) : null,
1492
+ null !== results.allUrl ? option(
1493
+ results.allUrl,
1494
+ "ec-search__option ec-search__option--all",
1495
+ { "data-header-search-all": "" },
1496
+ /* @__PURE__ */ jsxs8(Fragment5, { children: [
1497
+ /* @__PURE__ */ jsx12(Icon3, { name: "search", className: "ec-search__icon" }),
1498
+ /* @__PURE__ */ jsx12("span", { className: "ec-search__name", children: trans_choice3(
1499
+ 'See all :count result for ":term"|See all :count results for ":term"',
1500
+ results.total,
1501
+ { count: results.total, term: results.term }
1502
+ ) }),
1503
+ /* @__PURE__ */ jsx12(Icon3, { name: "arrow-right", className: "ec-search__icon" })
1504
+ ] })
1505
+ ) : null
1506
+ ]
1507
+ }
1508
+ )
1509
+ ]
1510
+ }
1511
+ )
1512
+ ]
1513
+ }
1514
+ );
1515
+ }
1516
+
1517
+ // src/components/SearchBox.tsx
1518
+ import { jsx as jsx13 } from "react/jsx-runtime";
1519
+ function SearchBox({
1520
+ inputId = "ecommerce-header-search",
1521
+ className
1522
+ }) {
1523
+ return /* @__PURE__ */ jsx13("div", { className: cx("ec-search-box", className), "data-search-box": "", children: /* @__PURE__ */ jsx13(HeaderSearch, { inputId }) });
1524
+ }
1525
+
1526
+ // src/components/Toaster.tsx
1527
+ import { TOASTER_PLACEMENTS, __ as __8 } from "@artisanpack-ui/ecommerce-storefront-core";
1528
+ import { Toaster as ApuiToaster } from "@artisanpack-ui/react";
1529
+ import { useSyncExternalStore } from "react";
1530
+ import { jsx as jsx14 } from "react/jsx-runtime";
1531
+ function placement() {
1532
+ if ("function" !== typeof window.matchMedia) {
1533
+ return TOASTER_PLACEMENTS.desktop;
1534
+ }
1535
+ return window.matchMedia(TOASTER_PLACEMENTS.desktopQuery).matches ? TOASTER_PLACEMENTS.desktop : TOASTER_PLACEMENTS.mobile;
1536
+ }
1537
+ function subscribeToNothing() {
1538
+ return () => void 0;
1539
+ }
1540
+ function Toaster() {
1541
+ const where = useSyncExternalStore(
1542
+ subscribeToNothing,
1543
+ placement,
1544
+ () => TOASTER_PLACEMENTS.desktop
1545
+ );
1546
+ return /* @__PURE__ */ jsx14(
1547
+ ApuiToaster,
1548
+ {
1549
+ toaster: getStorefrontToaster(),
1550
+ placement: where,
1551
+ max: 5,
1552
+ gap: 8,
1553
+ duration: TOAST_DURATION,
1554
+ label: __8("Notifications"),
1555
+ closeLabel: __8("Dismiss notification")
1556
+ }
1557
+ );
1558
+ }
1559
+
1560
+ // src/layout/StorefrontLayout.tsx
1561
+ import { __ as __9, seoDocumentTitle, seoHeadTags } from "@artisanpack-ui/ecommerce-storefront-core";
1562
+ import { Button as Button5, Drawer as Drawer2, Icon as Icon4, Link, Navbar, NavbarItem, ThemeToggle } from "@artisanpack-ui/react";
1563
+ import { Head } from "@inertiajs/react";
1564
+ import { useEffect as useEffect7, useRef as useRef6, useState as useState6 } from "react";
1565
+
1566
+ // src/layout/sharedPropsArrival.ts
1567
+ var handled = /* @__PURE__ */ new WeakSet();
1568
+ var restoring = false;
1569
+ var listening = false;
1570
+ function startListening() {
1571
+ if (listening || "undefined" === typeof window) {
1572
+ return;
1573
+ }
1574
+ listening = true;
1575
+ const entry = window.performance?.getEntriesByType?.("navigation")[0];
1576
+ restoring = "back_forward" === entry?.type && null !== window.history.state;
1577
+ window.addEventListener(
1578
+ "popstate",
1579
+ (event) => {
1580
+ if (null !== event.state) {
1581
+ restoring = true;
1582
+ }
1583
+ },
1584
+ { capture: true }
1585
+ );
1586
+ document.addEventListener("inertia:start", () => {
1587
+ restoring = false;
1588
+ });
1589
+ }
1590
+ function takeFreshSharedProps(shared) {
1591
+ startListening();
1592
+ if (handled.has(shared)) {
1593
+ return false;
1594
+ }
1595
+ handled.add(shared);
1596
+ return !restoring;
1597
+ }
1598
+
1599
+ // src/layout/StorefrontLayout.tsx
1600
+ import { Fragment as Fragment6, jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
1601
+ registerHeaderActionBuiltIns();
1602
+ registerStorefrontIcons();
1603
+ function SharedPropsEffects() {
1604
+ const shared = useStorefront();
1605
+ const { setOpen } = useCartDrawer();
1606
+ useEffect7(() => {
1607
+ if (!takeFreshSharedProps(shared)) {
1608
+ return;
1609
+ }
1610
+ if (Array.isArray(shared.toasts)) {
1611
+ shared.toasts.forEach((toast) => showStorefrontToast(toast));
1612
+ }
1613
+ if (true === shared.cart?.open) {
1614
+ setOpen(true);
1615
+ }
1616
+ }, [shared, setOpen]);
1617
+ return null;
1618
+ }
1619
+ function Brand({ attributes = {} }) {
1620
+ const { store } = useStorefront();
1621
+ return /* @__PURE__ */ jsxs9("a", { href: store.url, className: "ec-brand", ...attributes, children: [
1622
+ /* @__PURE__ */ jsx15("span", { className: "ec-brand__mark", "aria-hidden": "true", children: store.mark }),
1623
+ /* @__PURE__ */ jsx15("span", { className: "ec-brand__name", children: store.name })
1624
+ ] });
1625
+ }
1626
+ function StorefrontHead() {
1627
+ const { seo } = useStorefront();
1628
+ return /* @__PURE__ */ jsx15(Head, { title: seoDocumentTitle(seo), children: seoHeadTags(seo).map(
1629
+ (tag) => "script" === tag.tag ? /* @__PURE__ */ jsx15(
1630
+ "script",
1631
+ {
1632
+ "head-key": tag.key,
1633
+ ...tag.attributes,
1634
+ dangerouslySetInnerHTML: { __html: tag.content ?? "" }
1635
+ },
1636
+ tag.key
1637
+ ) : "link" === tag.tag ? /* @__PURE__ */ jsx15("link", { "head-key": tag.key, ...tag.attributes }, tag.key) : /* @__PURE__ */ jsx15("meta", { "head-key": tag.key, ...tag.attributes }, tag.key)
1638
+ ) });
1639
+ }
1640
+ function HeaderActions() {
1641
+ const { headerActions } = useStorefront();
1642
+ const registry = getRegistries().headerActions;
1643
+ return /* @__PURE__ */ jsx15(Fragment6, { children: headerActions.map((action) => {
1644
+ const Action = registry.get(action.component)?.component;
1645
+ return void 0 === Action ? null : /* @__PURE__ */ jsx15(Action, { action }, action.key);
1646
+ }) });
1647
+ }
1648
+ function StoreHeader() {
1649
+ const { navigation, search, store } = useStorefront();
1650
+ const [menuOpen, setMenuOpen] = useState6(false);
1651
+ const menuButton = useRef6(null);
1652
+ const hasNavigation = navigation.length > 0;
1653
+ return /* @__PURE__ */ jsxs9(Fragment6, { children: [
1654
+ /* @__PURE__ */ jsx15(
1655
+ Navbar,
1656
+ {
1657
+ sticky: true,
1658
+ label: __9("Store"),
1659
+ className: "ec-header",
1660
+ "data-storefront-header": "",
1661
+ brand: /* @__PURE__ */ jsxs9(Fragment6, { children: [
1662
+ hasNavigation ? /* @__PURE__ */ jsx15("span", { className: "ec-header__menu", children: /* @__PURE__ */ jsx15(
1663
+ Button5,
1664
+ {
1665
+ ref: menuButton,
1666
+ variant: "ghost",
1667
+ color: "neutral",
1668
+ size: "sm",
1669
+ iconOnly: true,
1670
+ leadingIcon: "menu",
1671
+ "aria-label": __9("Menu"),
1672
+ "aria-haspopup": "dialog",
1673
+ "aria-controls": "ecommerce-storefront-menu-content",
1674
+ onClick: () => setMenuOpen(true),
1675
+ "data-storefront-menu-open": ""
1676
+ }
1677
+ ) }) : null,
1678
+ /* @__PURE__ */ jsx15(Brand, { attributes: { "data-storefront-brand": "" } })
1679
+ ] }),
1680
+ search: null !== search.url ? /* @__PURE__ */ jsx15(SearchBox, { className: "ec-header-search" }) : void 0,
1681
+ actions: /* @__PURE__ */ jsxs9(Fragment6, { children: [
1682
+ null !== search.url ? /* @__PURE__ */ jsx15(
1683
+ Button5,
1684
+ {
1685
+ variant: "ghost",
1686
+ color: "neutral",
1687
+ size: "sm",
1688
+ iconOnly: true,
1689
+ leadingIcon: "search",
1690
+ href: search.url,
1691
+ className: "ec-header-search-link",
1692
+ "aria-label": __9("Search"),
1693
+ "data-header-search-link": ""
1694
+ }
1695
+ ) : null,
1696
+ /* @__PURE__ */ jsx15(HeaderActions, {})
1697
+ ] }),
1698
+ children: navigation.map((link) => /* @__PURE__ */ jsx15(
1699
+ NavbarItem,
1700
+ {
1701
+ href: link.url,
1702
+ current: link.current,
1703
+ "data-storefront-nav-link": "",
1704
+ children: link.label
1705
+ },
1706
+ link.url
1707
+ ))
1708
+ }
1709
+ ),
1710
+ hasNavigation ? /* @__PURE__ */ jsx15(
1711
+ Drawer2,
1712
+ {
1713
+ side: "start",
1714
+ id: "ecommerce-storefront-menu-content",
1715
+ size: "sm",
1716
+ title: store.name,
1717
+ closeLabel: __9("Close menu"),
1718
+ open: menuOpen,
1719
+ onOpenChange: (open) => {
1720
+ setMenuOpen(open);
1721
+ if (!open) {
1722
+ menuButton.current?.focus();
1723
+ }
1724
+ },
1725
+ "data-storefront-menu": "",
1726
+ children: /* @__PURE__ */ jsx15("nav", { "aria-label": __9("Store"), children: /* @__PURE__ */ jsx15("ul", { role: "list", className: "ec-menu-list", children: navigation.map((link) => /* @__PURE__ */ jsx15("li", { children: /* @__PURE__ */ jsx15(
1727
+ "a",
1728
+ {
1729
+ href: link.url,
1730
+ className: "ec-menu-list__link",
1731
+ "aria-current": link.current ? "page" : void 0,
1732
+ children: link.label
1733
+ }
1734
+ ) }, link.url)) }) })
1735
+ }
1736
+ ) : null
1737
+ ] });
1738
+ }
1739
+ function CheckoutHeader() {
1740
+ const { cart } = useStorefront();
1741
+ return /* @__PURE__ */ jsx15("header", { className: "ec-checkout-header", "data-checkout-header": "", children: /* @__PURE__ */ jsxs9("div", { className: "ec-checkout-header__inner", children: [
1742
+ /* @__PURE__ */ jsx15(Brand, {}),
1743
+ /* @__PURE__ */ jsxs9("span", { className: "ec-checkout-header__secure", children: [
1744
+ /* @__PURE__ */ jsx15(Icon4, { name: "lock", "aria-hidden": "true" }),
1745
+ /* @__PURE__ */ jsx15("span", { children: __9("Secure checkout") })
1746
+ ] }),
1747
+ null !== cart.url ? /* @__PURE__ */ jsx15(
1748
+ Link,
1749
+ {
1750
+ href: cart.url,
1751
+ tone: "muted",
1752
+ standalone: true,
1753
+ leadingIcon: "arrow-left",
1754
+ className: "ec-checkout-header__back",
1755
+ "data-checkout-back-to-cart": "",
1756
+ children: __9("Back to cart")
1757
+ }
1758
+ ) : null
1759
+ ] }) });
1760
+ }
1761
+ function Footer() {
1762
+ const { store, footer } = useStorefront();
1763
+ return /* @__PURE__ */ jsx15("footer", { className: "ec-footer", "data-storefront-footer": "", children: /* @__PURE__ */ jsxs9("div", { className: "ec-footer__inner", children: [
1764
+ /* @__PURE__ */ jsxs9("div", { className: "ec-footer__top", children: [
1765
+ /* @__PURE__ */ jsxs9("div", { className: "ec-footer__about", children: [
1766
+ /* @__PURE__ */ jsx15(Brand, {}),
1767
+ null !== store.tagline && "" !== store.tagline.trim() ? /* @__PURE__ */ jsx15("p", { className: "ec-footer__tagline", "data-storefront-tagline": "", children: store.tagline }) : null
1768
+ ] }),
1769
+ footer.length > 0 ? /* @__PURE__ */ jsx15("nav", { className: "ec-footer__nav", "aria-label": __9("Footer"), children: footer.map((column) => /* @__PURE__ */ jsxs9("div", { className: "ec-footer__column", "data-footer-column": column.key, children: [
1770
+ /* @__PURE__ */ jsx15("h2", { id: `ec-footer-${column.key}`, className: "ec-footer__title", children: column.title }),
1771
+ /* @__PURE__ */ jsx15(
1772
+ "ul",
1773
+ {
1774
+ role: "list",
1775
+ className: "ec-footer__links",
1776
+ "aria-labelledby": `ec-footer-${column.key}`,
1777
+ children: column.links.map((link) => /* @__PURE__ */ jsx15("li", { children: /* @__PURE__ */ jsx15("a", { href: link.url, className: "ec-footer__link", children: link.label }) }, `${link.url}-${link.label}`))
1778
+ }
1779
+ )
1780
+ ] }, column.key)) }) : null
1781
+ ] }),
1782
+ /* @__PURE__ */ jsxs9("div", { className: "ec-footer__bottom", children: [
1783
+ /* @__PURE__ */ jsxs9("p", { className: "ec-footer__copyright", suppressHydrationWarning: true, children: [
1784
+ "\xA9 ",
1785
+ (/* @__PURE__ */ new Date()).getFullYear(),
1786
+ " ",
1787
+ store.name
1788
+ ] }),
1789
+ /* @__PURE__ */ jsxs9("div", { className: "ec-footer__settings", children: [
1790
+ /* @__PURE__ */ jsx15(CurrencySwitcher, { placement: "footer" }),
1791
+ /* @__PURE__ */ jsx15(ThemeToggle, { variant: "icon" })
1792
+ ] })
1793
+ ] })
1794
+ ] }) });
1795
+ }
1796
+ function StorefrontLayout({
1797
+ children,
1798
+ chrome = "default"
1799
+ }) {
1800
+ const checkout = "checkout" === chrome;
1801
+ const skipLink = useRef6(null);
1802
+ useEffect7(() => {
1803
+ document.body.classList.add("ec-storefront");
1804
+ const root = skipLink.current?.parentElement;
1805
+ if (null !== root && void 0 !== root && document.body !== root) {
1806
+ root.style.display = "contents";
1807
+ }
1808
+ if (checkout) {
1809
+ document.body.setAttribute("data-storefront-chrome", "checkout");
1810
+ } else {
1811
+ document.body.removeAttribute("data-storefront-chrome");
1812
+ }
1813
+ }, [checkout]);
1814
+ return /* @__PURE__ */ jsxs9(CartDrawerProvider, { children: [
1815
+ /* @__PURE__ */ jsx15(SharedPropsEffects, {}),
1816
+ /* @__PURE__ */ jsx15(StorefrontHead, {}),
1817
+ /* @__PURE__ */ jsx15(
1818
+ "a",
1819
+ {
1820
+ ref: skipLink,
1821
+ href: "#ecommerce-storefront-content",
1822
+ className: "apui-button ec-skip-link",
1823
+ "data-variant": "solid",
1824
+ "data-color": "primary",
1825
+ "data-size": "sm",
1826
+ "data-skip-link": "",
1827
+ children: __9("Skip to content")
1828
+ }
1829
+ ),
1830
+ checkout ? /* @__PURE__ */ jsx15(CheckoutHeader, {}) : /* @__PURE__ */ jsx15(StoreHeader, {}),
1831
+ /* @__PURE__ */ jsx15("main", { className: "ec-main", children: /* @__PURE__ */ jsx15("div", { id: "ecommerce-storefront-content", tabIndex: -1, className: "ec-main__content", children }) }),
1832
+ checkout ? null : /* @__PURE__ */ jsx15(Footer, {}),
1833
+ /* @__PURE__ */ jsxs9("div", { "data-ecommerce-storefront-global": "", children: [
1834
+ /* @__PURE__ */ jsx15(Toaster, {}),
1835
+ /* @__PURE__ */ jsx15(CartDrawer, {}),
1836
+ /* @__PURE__ */ jsx15(MergePrompt, {})
1837
+ ] })
1838
+ ] });
1839
+ }
1840
+ var storefrontLayout = (page) => /* @__PURE__ */ jsx15(StorefrontLayout, { children: page });
1841
+ var checkoutLayout = (page) => /* @__PURE__ */ jsx15(StorefrontLayout, { chrome: "checkout", children: page });
1842
+
1843
+ export {
1844
+ isSameOrigin,
1845
+ CART_DRAWER_ONLY,
1846
+ cartWriteOnly,
1847
+ cartActionUrl,
1848
+ csrfHeaders,
1849
+ postJson,
1850
+ StorefrontPageContext,
1851
+ StorefrontBlockHostContext,
1852
+ cx,
1853
+ idFragment,
1854
+ filled,
1855
+ STOREFRONT_ICONS,
1856
+ registerStorefrontIcons,
1857
+ addBuiltInRegistration,
1858
+ getRegistries,
1859
+ resetRegistries,
1860
+ Price,
1861
+ useStorefrontPage,
1862
+ useStorefront,
1863
+ usePageErrors,
1864
+ useStorefrontCart,
1865
+ useStorefrontTemplate,
1866
+ CartDrawerProvider,
1867
+ useCartDrawer,
1868
+ useRegisterCartDrawer,
1869
+ CartHeaderButton,
1870
+ CurrencySwitcher,
1871
+ AccountAction,
1872
+ CurrencyAction,
1873
+ registerHeaderActions,
1874
+ registerHeaderActionBuiltIns,
1875
+ Quantity,
1876
+ getStorefrontToaster,
1877
+ runToastAction,
1878
+ showStorefrontToast,
1879
+ showResponseToasts,
1880
+ resetStorefrontToaster,
1881
+ EmptyState,
1882
+ Money,
1883
+ QUANTITY_COMMIT_DELAY,
1884
+ LineControls,
1885
+ useFocusAfterChange,
1886
+ CART_DRAWER_CONTENT_ID,
1887
+ CartDrawer,
1888
+ MERGE_PRIMARY_ID,
1889
+ MergePrompt,
1890
+ suggestionsUrl,
1891
+ HeaderSearch,
1892
+ SearchBox,
1893
+ Toaster,
1894
+ StorefrontLayout,
1895
+ storefrontLayout,
1896
+ checkoutLayout
1897
+ };
1898
+ //# sourceMappingURL=chunk-VX5TEJNU.mjs.map