@develemit/commerce-admin 0.3.0 → 0.4.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.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { a as e, c as t, d as n, f as r, i, l as a, o, r as s, s as c, u as l } from "./client-n_IYb4iK.js";
3
- import { createContext as u, useCallback as d, useContext as f, useEffect as p, useRef as m, useState as h } from "react";
4
- import { Fragment as g, jsx as _, jsxs as v } from "react/jsx-runtime";
5
- import { adminProductInputSchema as y, shippingRatesInputSchema as b } from "@develemit/commerce-contracts";
2
+ import { a as e, c as t, d as n, f as r, i, l as a, m as o, o as s, p as c, r as l, s as u, u as d } from "./client--_j5r8ag.js";
3
+ import { createContext as f, useCallback as p, useContext as m, useEffect as h, useRef as g, useState as _ } from "react";
4
+ import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
5
+ import { adminProductInputSchema as x, shippingRatesInputSchema as S } from "@develemit/commerce-contracts";
6
6
  // src/lib/order-labels.ts
7
- var x = {
7
+ var C = {
8
8
  title: "Orders",
9
9
  searchLabel: "Search orders",
10
10
  searchPlaceholder: "Search by email or order id",
@@ -104,7 +104,7 @@ var x = {
104
104
  resolved: "Order resolved.",
105
105
  restockThenResolve: "Restock, then resolve"
106
106
  }
107
- }, S = {
107
+ }, w = {
108
108
  title: "Shipping rates",
109
109
  loading: "Loading shipping rates…",
110
110
  empty: "No shipping rates yet. Add one so customers can check out.",
@@ -135,7 +135,70 @@ var x = {
135
135
  daysInvalid: "Use a whole number of days, or leave blank.",
136
136
  daysOrder: "Fastest cannot be more than slowest.",
137
137
  rowInvalid: "These details are not valid."
138
- }, C = {
138
+ }, T = {
139
+ title: "Discounts",
140
+ newDiscount: "New discount",
141
+ searchLabel: "Search discounts",
142
+ searchPlaceholder: "Search by code",
143
+ tabs: {
144
+ active: "Active",
145
+ scheduled: "Scheduled",
146
+ expired: "Expired",
147
+ inactive: "Inactive"
148
+ },
149
+ empty: {
150
+ active: "No active discounts.",
151
+ scheduled: "No scheduled discounts.",
152
+ expired: "No expired discounts.",
153
+ inactive: "No inactive discounts."
154
+ },
155
+ noMatches: "No discounts match your search.",
156
+ loadMore: "Load more",
157
+ columns: {
158
+ code: "Code",
159
+ value: "Discount",
160
+ status: "Status",
161
+ usage: "Used"
162
+ },
163
+ usage: "{used} / {max} used",
164
+ usageUnlimited: "{used} used",
165
+ createTitle: "New discount",
166
+ editTitle: "Edit discount",
167
+ saved: "Discount saved.",
168
+ fields: {
169
+ code: "Code",
170
+ type: "Type",
171
+ percentOff: "Percent off",
172
+ amountOff: "Amount off",
173
+ minSubtotal: "Minimum subtotal",
174
+ startsAt: "Starts",
175
+ endsAt: "Ends",
176
+ maxRedemptions: "Usage limit"
177
+ },
178
+ types: {
179
+ percent: "Percent",
180
+ fixed: "Fixed amount"
181
+ },
182
+ optionalHelp: "Optional",
183
+ lockedHelp: "Used on {count} orders; create a new code instead.",
184
+ deactivate: "Deactivate",
185
+ deactivateTitle: "Deactivate this discount?",
186
+ deactivateBody: "Buyers can no longer use this code. Past orders keep it. You can reactivate it later.",
187
+ reactivate: "Reactivate",
188
+ validation: {
189
+ code: "Use letters, numbers, dashes or underscores (up to 40).",
190
+ percentOff: "Enter a whole number from 1 to 100.",
191
+ amountOff: "Enter an amount greater than zero, like 5.00.",
192
+ minSubtotal: "Enter an amount greater than zero, like 25.00.",
193
+ maxRedemptions: "Enter a whole number greater than zero.",
194
+ maxRedemptionsBelowUsage: "The limit cannot be lower than the times used.",
195
+ endsBeforeStart: "The end must be after the start.",
196
+ date: "Enter a valid date and time.",
197
+ codeTaken: "That code is already in use.",
198
+ invalid: "This value is not valid."
199
+ },
200
+ orderRow: "Discount"
201
+ }, E = {
139
202
  title: "Products",
140
203
  newProduct: "New product",
141
204
  searchLabel: "Search products",
@@ -198,6 +261,9 @@ var x = {
198
261
  altWarning: "No description yet. Add one so everyone can enjoy this photo.",
199
262
  cover: "Cover",
200
263
  photoName: "Photo {n}",
264
+ editAlt: "Edit description",
265
+ saveAlt: "Save",
266
+ cancelAlt: "Cancel",
201
267
  moveEarlier: "Move earlier",
202
268
  moveLater: "Move later",
203
269
  remove: "Remove",
@@ -217,78 +283,57 @@ var x = {
217
283
  price: "Enter a price like 48 or 48.50.",
218
284
  quantity: "Enter a whole number, zero or more."
219
285
  }
220
- }, w = {
221
- renderLink: ({ href: e, children: t, className: n }) => /* @__PURE__ */ _("a", {
222
- href: e,
223
- className: n,
224
- children: t
225
- }),
226
- renderImage: ({ src: e, alt: t, sizes: n, className: r, priority: i }) => /* @__PURE__ */ _("img", {
227
- src: e,
228
- alt: t,
229
- sizes: n,
230
- className: r,
231
- loading: i ? "eager" : "lazy",
232
- decoding: "async",
233
- fetchPriority: i ? "high" : void 0
234
- }),
235
- locale: "en-US",
236
- currency: "USD",
237
- hrefs: {
238
- products: "/admin/products",
239
- product: (e) => `/admin/products/${e}`,
240
- newProduct: "/admin/products/new",
241
- orders: "/admin/orders",
242
- order: (e) => `/admin/orders/${e}`,
243
- shippingRates: "/admin/shipping-rates"
286
+ }, D = {
287
+ loading: "Loading…",
288
+ empty: "Nothing here yet.",
289
+ save: "Save",
290
+ cancel: "Cancel",
291
+ confirm: "Confirm",
292
+ dismiss: "Dismiss",
293
+ navLabel: "Admin",
294
+ nav: {
295
+ products: "Products",
296
+ orders: "Orders",
297
+ shippingRates: "Shipping rates"
244
298
  },
245
- client: null,
246
- labels: {
247
- loading: "Loading…",
248
- empty: "Nothing here yet.",
249
- save: "Save",
250
- cancel: "Cancel",
251
- confirm: "Confirm",
252
- dismiss: "Dismiss",
253
- navLabel: "Admin",
254
- nav: {
255
- products: "Products",
256
- orders: "Orders",
257
- shippingRates: "Shipping rates"
258
- },
259
- statuses: {
260
- draft: "Draft",
261
- active: "Active",
262
- archived: "Archived",
263
- pending: "Pending",
264
- paid: "Paid",
265
- shipped: "Shipped",
266
- cancelled: "Cancelled",
267
- expired: "Expired",
268
- needs_attention: "Needs attention",
269
- refunded: "Refunded",
270
- sold: "Sold"
271
- },
272
- errors: {
273
- unauthorized: "You are not signed in or not allowed to do this.",
274
- notFound: "We could not find that.",
275
- invalidInput: "Some of the details are not valid. Check them and try again.",
276
- invalidOrderState: "This order cannot be changed that way in its current state.",
277
- insufficientStock: "Not enough stock is available.",
278
- refundExceedsBalance: "The refund is more than the remaining balance.",
279
- refundGateway: "The payment provider rejected the refund. Try again shortly.",
280
- refundOutcomeUnknown: "Refund outcome unknown — retry with the same request.",
281
- imageInvalid: "That image could not be used. Try a different file.",
282
- imageTooLarge: "That image is too large. Choose a smaller one.",
283
- generic: "Something went wrong. Try again."
284
- },
285
- products: C,
286
- orders: x,
287
- shipping: S
288
- }
289
- }, T = u(w);
290
- function E(e) {
291
- let t = x;
299
+ statuses: {
300
+ draft: "Draft",
301
+ active: "Active",
302
+ archived: "Archived",
303
+ pending: "Pending",
304
+ paid: "Paid",
305
+ shipped: "Shipped",
306
+ cancelled: "Cancelled",
307
+ expired: "Expired",
308
+ needs_attention: "Needs attention",
309
+ refunded: "Refunded",
310
+ sold: "Sold",
311
+ scheduled: "Scheduled",
312
+ inactive: "Inactive"
313
+ },
314
+ errors: {
315
+ unauthorized: "You are not signed in or not allowed to do this.",
316
+ notFound: "We could not find that.",
317
+ invalidInput: "Some of the details are not valid. Check them and try again.",
318
+ invalidOrderState: "This order cannot be changed that way in its current state.",
319
+ insufficientStock: "Not enough stock is available.",
320
+ refundExceedsBalance: "The refund is more than the remaining balance.",
321
+ refundGateway: "The payment provider rejected the refund. Try again shortly.",
322
+ refundOutcomeUnknown: "Refund outcome unknown — retry with the same request.",
323
+ discountCodeTaken: "That discount code is already in use.",
324
+ discountInUse: "This code has been used, so that detail can no longer change. Create a new code instead.",
325
+ imageInvalid: "That image could not be used. Try a different file.",
326
+ imageTooLarge: "That image is too large. Choose a smaller one.",
327
+ generic: "Something went wrong. Try again."
328
+ },
329
+ products: E,
330
+ orders: C,
331
+ shipping: w,
332
+ discounts: T
333
+ };
334
+ // src/lib/merge-labels.ts
335
+ function O(e) {
336
+ let t = C;
292
337
  return {
293
338
  ...t,
294
339
  ...e,
@@ -326,8 +371,8 @@ function E(e) {
326
371
  }
327
372
  };
328
373
  }
329
- function D(e) {
330
- let t = C;
374
+ function k(e) {
375
+ let t = E;
331
376
  return {
332
377
  ...t,
333
378
  ...e,
@@ -357,62 +402,130 @@ function D(e) {
357
402
  }
358
403
  };
359
404
  }
360
- function O({ children: e, hrefs: t, labels: n, ...r }) {
405
+ function A(e) {
406
+ let t = T;
407
+ return {
408
+ ...t,
409
+ ...e,
410
+ tabs: {
411
+ ...t.tabs,
412
+ ...e?.tabs
413
+ },
414
+ empty: {
415
+ ...t.empty,
416
+ ...e?.empty
417
+ },
418
+ columns: {
419
+ ...t.columns,
420
+ ...e?.columns
421
+ },
422
+ fields: {
423
+ ...t.fields,
424
+ ...e?.fields
425
+ },
426
+ types: {
427
+ ...t.types,
428
+ ...e?.types
429
+ },
430
+ validation: {
431
+ ...t.validation,
432
+ ...e?.validation
433
+ }
434
+ };
435
+ }
436
+ function j(e) {
437
+ let t = D;
438
+ return {
439
+ ...t,
440
+ ...e,
441
+ nav: {
442
+ ...t.nav,
443
+ ...e?.nav
444
+ },
445
+ statuses: {
446
+ ...t.statuses,
447
+ ...e?.statuses
448
+ },
449
+ errors: {
450
+ ...t.errors,
451
+ ...e?.errors
452
+ },
453
+ products: k(e?.products),
454
+ orders: O(e?.orders),
455
+ shipping: {
456
+ ...w,
457
+ ...e?.shipping
458
+ },
459
+ discounts: A(e?.discounts)
460
+ };
461
+ }
462
+ // src/lib/provider.tsx
463
+ var M = {
464
+ renderLink: ({ href: e, children: t, className: n }) => /* @__PURE__ */ y("a", {
465
+ href: e,
466
+ className: n,
467
+ children: t
468
+ }),
469
+ renderImage: ({ src: e, alt: t, sizes: n, className: r, priority: i }) => /* @__PURE__ */ y("img", {
470
+ src: e,
471
+ alt: t,
472
+ sizes: n,
473
+ className: r,
474
+ loading: i ? "eager" : "lazy",
475
+ decoding: "async",
476
+ fetchPriority: i ? "high" : void 0
477
+ }),
478
+ locale: "en-US",
479
+ currency: "USD",
480
+ hrefs: {
481
+ products: "/admin/products",
482
+ product: (e) => `/admin/products/${e}`,
483
+ newProduct: "/admin/products/new",
484
+ orders: "/admin/orders",
485
+ order: (e) => `/admin/orders/${e}`,
486
+ shippingRates: "/admin/shipping-rates",
487
+ discounts: "/admin/discounts",
488
+ discount: (e) => `/admin/discounts/${e}`,
489
+ newDiscount: "/admin/discounts/new"
490
+ },
491
+ client: null,
492
+ labels: D
493
+ }, N = f(M);
494
+ function ee({ children: e, hrefs: t, labels: n, ...r }) {
361
495
  let i = {
362
- ...w,
496
+ ...M,
363
497
  ...r,
364
498
  hrefs: {
365
- ...w.hrefs,
499
+ ...M.hrefs,
366
500
  ...t
367
501
  },
368
- labels: {
369
- ...w.labels,
370
- ...n,
371
- nav: {
372
- ...w.labels.nav,
373
- ...n?.nav
374
- },
375
- statuses: {
376
- ...w.labels.statuses,
377
- ...n?.statuses
378
- },
379
- errors: {
380
- ...w.labels.errors,
381
- ...n?.errors
382
- },
383
- products: D(n?.products),
384
- orders: E(n?.orders),
385
- shipping: {
386
- ...S,
387
- ...n?.shipping
388
- }
389
- }
502
+ labels: j(n)
390
503
  };
391
- return /* @__PURE__ */ _(T.Provider, {
504
+ return /* @__PURE__ */ y(N.Provider, {
392
505
  value: i,
393
506
  children: e
394
507
  });
395
508
  }
396
- function k() {
397
- return f(T);
509
+ function P() {
510
+ return m(N);
398
511
  }
399
- function A() {
400
- let { client: e } = k();
512
+ function F() {
513
+ let { client: e } = P();
401
514
  if (!e) throw Error("AdminProvider needs a `client` to render this view.");
402
515
  return e;
403
516
  }
404
517
  // src/lib/use-admin-query.ts
405
- function j(e, t) {
406
- let n = m(t);
407
- p(() => {
518
+ function I(e, t) {
519
+ let n = g(t);
520
+ h(() => {
408
521
  n.current = t;
409
522
  });
410
- let [r, i] = h(0), [a, o] = h({
523
+ let [r, i] = _(0), [a, o] = _({
411
524
  request: "",
412
525
  data: void 0,
413
526
  error: void 0
414
527
  }), s = `${JSON.stringify(e)}#${r}`;
415
- p(() => {
528
+ h(() => {
416
529
  let e = new AbortController();
417
530
  return n.current(e.signal).then((t) => {
418
531
  e.signal.aborted || o({
@@ -428,7 +541,7 @@ function j(e, t) {
428
541
  }));
429
542
  }), () => e.abort();
430
543
  }, [s]);
431
- let c = d(() => i((e) => e + 1), []), l = a.request === s;
544
+ let c = p(() => i((e) => e + 1), []), l = a.request === s;
432
545
  return {
433
546
  data: a.data,
434
547
  error: l ? a.error : void 0,
@@ -437,14 +550,14 @@ function j(e, t) {
437
550
  };
438
551
  }
439
552
  // src/lib/use-admin-mutation.ts
440
- function M(e) {
441
- let t = m(e);
442
- p(() => {
553
+ function L(e) {
554
+ let t = g(e);
555
+ h(() => {
443
556
  t.current = e;
444
557
  });
445
- let [n, r] = h(!1), [i, a] = h(void 0);
558
+ let [n, r] = _(!1), [i, a] = _(void 0);
446
559
  return {
447
- run: d(async (...e) => {
560
+ run: p(async (...e) => {
448
561
  r(!0), a(void 0);
449
562
  try {
450
563
  return await t.current(...e);
@@ -457,12 +570,12 @@ function M(e) {
457
570
  }, []),
458
571
  pending: n,
459
572
  error: i,
460
- reset: d(() => a(void 0), [])
573
+ reset: p(() => a(void 0), [])
461
574
  };
462
575
  }
463
576
  // src/components/admin-layout/admin-layout.tsx
464
- function N({ children: e, extraNav: t = [], header: n, footer: r }) {
465
- let { hrefs: i, labels: a, renderLink: o } = k(), s = [
577
+ function te({ children: e, extraNav: t = [], header: n, footer: r }) {
578
+ let { hrefs: i, labels: a, renderLink: o } = P(), s = [
466
579
  {
467
580
  href: i.products,
468
581
  label: a.nav.products
@@ -480,27 +593,27 @@ function N({ children: e, extraNav: t = [], header: n, footer: r }) {
480
593
  ...s,
481
594
  ...t.filter((e) => e.position !== "start")
482
595
  ];
483
- return /* @__PURE__ */ v("div", {
596
+ return /* @__PURE__ */ b("div", {
484
597
  className: "sfa-root sfa-layout",
485
598
  children: [
486
- n ? /* @__PURE__ */ _("header", {
599
+ n ? /* @__PURE__ */ y("header", {
487
600
  className: "sfa-layout__header",
488
601
  children: n
489
602
  }) : null,
490
- /* @__PURE__ */ _("nav", {
603
+ /* @__PURE__ */ y("nav", {
491
604
  className: "sfa-nav",
492
605
  "aria-label": a.navLabel,
493
- children: /* @__PURE__ */ _("ul", { children: c.map((e) => /* @__PURE__ */ _("li", { children: o({
606
+ children: /* @__PURE__ */ y("ul", { children: c.map((e) => /* @__PURE__ */ y("li", { children: o({
494
607
  href: e.href,
495
608
  className: "sfa-nav__link",
496
609
  children: e.label
497
610
  }) }, e.href)) })
498
611
  }),
499
- /* @__PURE__ */ _("main", {
612
+ /* @__PURE__ */ y("main", {
500
613
  className: "sfa-layout__content",
501
614
  children: e
502
615
  }),
503
- r ? /* @__PURE__ */ _("footer", {
616
+ r ? /* @__PURE__ */ y("footer", {
504
617
  className: "sfa-layout__footer",
505
618
  children: r
506
619
  }) : null
@@ -508,20 +621,20 @@ function N({ children: e, extraNav: t = [], header: n, footer: r }) {
508
621
  });
509
622
  }
510
623
  // src/components/admin-table/admin-table.tsx
511
- function P({ columns: e, rows: t, rowKey: n, caption: r }) {
512
- let { labels: i } = k();
513
- return t.length === 0 ? /* @__PURE__ */ _("p", {
624
+ function R({ columns: e, rows: t, rowKey: n, caption: r }) {
625
+ let { labels: i } = P();
626
+ return t.length === 0 ? /* @__PURE__ */ y("p", {
514
627
  className: "sfa-empty",
515
628
  children: i.empty
516
- }) : /* @__PURE__ */ v("table", {
629
+ }) : /* @__PURE__ */ b("table", {
517
630
  className: "sfa-table sfa-table--stacked",
518
631
  children: [
519
- r ? /* @__PURE__ */ _("caption", { children: r }) : null,
520
- /* @__PURE__ */ _("thead", { children: /* @__PURE__ */ _("tr", { children: e.map((e) => /* @__PURE__ */ _("th", {
632
+ r ? /* @__PURE__ */ y("caption", { children: r }) : null,
633
+ /* @__PURE__ */ y("thead", { children: /* @__PURE__ */ y("tr", { children: e.map((e) => /* @__PURE__ */ y("th", {
521
634
  scope: "col",
522
635
  children: e.header
523
636
  }, e.key)) }) }),
524
- /* @__PURE__ */ _("tbody", { children: t.map((t) => /* @__PURE__ */ _("tr", { children: e.map((e) => /* @__PURE__ */ _("td", {
637
+ /* @__PURE__ */ y("tbody", { children: t.map((t) => /* @__PURE__ */ y("tr", { children: e.map((e) => /* @__PURE__ */ y("td", {
525
638
  "data-label": e.header,
526
639
  children: e.render(t)
527
640
  }, e.key)) }, n(t))) })
@@ -529,33 +642,33 @@ function P({ columns: e, rows: t, rowKey: n, caption: r }) {
529
642
  });
530
643
  }
531
644
  // src/components/status-badge/status-badge.tsx
532
- function F({ status: e }) {
533
- let { labels: t } = k();
534
- return /* @__PURE__ */ _("span", {
645
+ function z({ status: e }) {
646
+ let { labels: t } = P();
647
+ return /* @__PURE__ */ y("span", {
535
648
  className: `sfa-badge sfa-badge--${e.replace(/_/g, "-")}`,
536
649
  children: t.statuses[e] ?? e
537
650
  });
538
651
  }
539
652
  // src/components/money/money.tsx
540
- function I({ cents: e, currency: t }) {
541
- let { locale: n } = k(), r = new Intl.NumberFormat(n, {
653
+ function B({ cents: e, currency: t }) {
654
+ let { locale: n } = P(), r = new Intl.NumberFormat(n, {
542
655
  style: "currency",
543
656
  currency: t
544
657
  }).format(e / 100);
545
- return /* @__PURE__ */ _("span", {
658
+ return /* @__PURE__ */ y("span", {
546
659
  className: "sfa-money",
547
660
  children: r
548
661
  });
549
662
  }
550
663
  // src/components/confirm-dialog/confirm-dialog.tsx
551
- var L = "button:not([disabled]), [href], input:not([disabled]), select, textarea, [tabindex]:not([tabindex=\"-1\"])";
552
- function R({ open: e, title: t, children: n, confirmLabel: r, destructive: i = !1, pending: a = !1, onConfirm: o, onCancel: s }) {
553
- let { labels: c } = k(), l = m(null);
554
- return p(() => {
664
+ var ne = "button:not([disabled]), [href], input:not([disabled]), select, textarea, [tabindex]:not([tabindex=\"-1\"])";
665
+ function V({ open: e, title: t, children: n, confirmLabel: r, destructive: i = !1, pending: a = !1, onConfirm: o, onCancel: s }) {
666
+ let { labels: c } = P(), l = g(null);
667
+ return h(() => {
555
668
  if (!e) return;
556
669
  let t = document.activeElement;
557
- return l.current?.querySelector(L)?.focus(), () => t?.focus();
558
- }, [e]), e ? /* @__PURE__ */ _("div", {
670
+ return l.current?.querySelector(ne)?.focus(), () => t?.focus();
671
+ }, [e]), e ? /* @__PURE__ */ y("div", {
559
672
  className: "sfa-dialog-backdrop",
560
673
  onKeyDown: (e) => {
561
674
  if (e.key === "Escape") {
@@ -563,31 +676,31 @@ function R({ open: e, title: t, children: n, confirmLabel: r, destructive: i = !
563
676
  return;
564
677
  }
565
678
  if (e.key !== "Tab") return;
566
- let t = Array.from(l.current?.querySelectorAll(L) ?? []);
679
+ let t = Array.from(l.current?.querySelectorAll(ne) ?? []);
567
680
  if (t.length === 0) return;
568
681
  let n = t[0], r = t[t.length - 1];
569
682
  e.shiftKey && document.activeElement === n ? (e.preventDefault(), r.focus()) : !e.shiftKey && document.activeElement === r && (e.preventDefault(), n.focus());
570
683
  },
571
- children: /* @__PURE__ */ v("div", {
684
+ children: /* @__PURE__ */ b("div", {
572
685
  ref: l,
573
686
  role: "dialog",
574
687
  "aria-modal": "true",
575
688
  "aria-label": t,
576
689
  className: "sfa-dialog",
577
690
  children: [
578
- /* @__PURE__ */ _("h2", {
691
+ /* @__PURE__ */ y("h2", {
579
692
  className: "sfa-dialog__title",
580
693
  children: t
581
694
  }),
582
695
  n,
583
- /* @__PURE__ */ v("div", {
696
+ /* @__PURE__ */ b("div", {
584
697
  className: "sfa-dialog__actions",
585
- children: [/* @__PURE__ */ _("button", {
698
+ children: [/* @__PURE__ */ y("button", {
586
699
  type: "button",
587
700
  className: "sfa-btn",
588
701
  onClick: s,
589
702
  children: c.cancel
590
- }), /* @__PURE__ */ _("button", {
703
+ }), /* @__PURE__ */ y("button", {
591
704
  type: "button",
592
705
  className: `sfa-btn ${i ? "sfa-btn--danger" : "sfa-btn--primary"}`,
593
706
  disabled: a,
@@ -600,9 +713,9 @@ function R({ open: e, title: t, children: n, confirmLabel: r, destructive: i = !
600
713
  }) : null;
601
714
  }
602
715
  // src/components/notice/notice.tsx
603
- function z({ variant: e, children: t, toast: n = !1, duration: r = 4e3, onDismiss: i }) {
604
- let { labels: a } = k();
605
- p(() => {
716
+ function H({ variant: e, children: t, toast: n = !1, duration: r = 4e3, onDismiss: i }) {
717
+ let { labels: a } = P();
718
+ h(() => {
606
719
  if (!n || !i) return;
607
720
  let e = setTimeout(i, r);
608
721
  return () => clearTimeout(e);
@@ -612,13 +725,13 @@ function z({ variant: e, children: t, toast: n = !1, duration: r = 4e3, onDismis
612
725
  i
613
726
  ]);
614
727
  let o = e === "error" ? "alert" : "status", s = `sfa-notice sfa-notice--${e}${n ? " sfa-notice--toast" : ""}`;
615
- return /* @__PURE__ */ v("div", {
728
+ return /* @__PURE__ */ b("div", {
616
729
  role: o,
617
730
  className: s,
618
- children: [/* @__PURE__ */ _("span", {
731
+ children: [/* @__PURE__ */ y("span", {
619
732
  className: "sfa-notice__body",
620
733
  children: t
621
- }), i && !n ? /* @__PURE__ */ _("button", {
734
+ }), i && !n ? /* @__PURE__ */ y("button", {
622
735
  type: "button",
623
736
  className: "sfa-btn",
624
737
  onClick: i,
@@ -627,36 +740,38 @@ function z({ variant: e, children: t, toast: n = !1, duration: r = 4e3, onDismis
627
740
  });
628
741
  }
629
742
  // src/components/error-message/error-message.tsx
630
- var B = [
743
+ var re = [
631
744
  [e, "unauthorized"],
632
745
  [i, "notFound"],
633
- [s, "invalidInput"],
634
- [a, "invalidOrderState"],
635
- [c, "insufficientStock"],
636
- [l, "refundExceedsBalance"],
637
- [n, "refundGateway"],
638
- [r, "refundOutcomeUnknown"],
639
- [o, "imageTooLarge"],
640
- [t, "imageInvalid"]
746
+ [l, "invalidInput"],
747
+ [n, "invalidOrderState"],
748
+ [a, "insufficientStock"],
749
+ [r, "refundExceedsBalance"],
750
+ [c, "refundGateway"],
751
+ [o, "refundOutcomeUnknown"],
752
+ [s, "discountCodeTaken"],
753
+ [u, "discountInUse"],
754
+ [t, "imageTooLarge"],
755
+ [d, "imageInvalid"]
641
756
  ];
642
- function V(e) {
643
- return B.find(([t]) => e instanceof t)?.[1] ?? "generic";
757
+ function ie(e) {
758
+ return re.find(([t]) => e instanceof t)?.[1] ?? "generic";
644
759
  }
645
- function H({ error: e }) {
646
- let { labels: t } = k();
647
- return e ? /* @__PURE__ */ _(z, {
760
+ function U({ error: e }) {
761
+ let { labels: t } = P();
762
+ return e ? /* @__PURE__ */ y(H, {
648
763
  variant: "error",
649
- children: t.errors[V(e)]
764
+ children: t.errors[ie(e)]
650
765
  }) : null;
651
766
  }
652
767
  // src/lib/product-filter.ts
653
- function U(e) {
768
+ function ae(e) {
654
769
  return e.status === "active" && e.quantity === 0;
655
770
  }
656
- function ee(e) {
657
- return U(e) ? "sold" : e.status;
771
+ function oe(e) {
772
+ return ae(e) ? "sold" : e.status;
658
773
  }
659
- function te(e) {
774
+ function se(e) {
660
775
  switch (e) {
661
776
  case "live":
662
777
  case "sold": return "active";
@@ -665,21 +780,21 @@ function te(e) {
665
780
  case "all": return;
666
781
  }
667
782
  }
668
- function ne(e) {
783
+ function ce(e) {
669
784
  if (e === "live") return "in";
670
785
  if (e === "sold") return "sold";
671
786
  }
672
787
  // src/lib/use-debounced.ts
673
- function re(e, t) {
674
- let [n, r] = h(e);
675
- return p(() => {
788
+ function W(e, t) {
789
+ let [n, r] = _(e);
790
+ return h(() => {
676
791
  let n = setTimeout(() => r(e), t);
677
792
  return () => clearTimeout(n);
678
793
  }, [e, t]), n;
679
794
  }
680
795
  // src/lib/use-product-pages.ts
681
- function ie(e) {
682
- let t = A(), n = j(["admin-products", e], () => t.listProducts(e)), [r, i] = h(null), a = M(async (n, r) => {
796
+ function le(e) {
797
+ let t = F(), n = I(["admin-products", e], () => t.listProducts(e)), [r, i] = _(null), a = L(async (n, r) => {
683
798
  let a = await t.listProducts({
684
799
  ...e,
685
800
  cursor: n
@@ -704,33 +819,33 @@ function ie(e) {
704
819
  };
705
820
  }
706
821
  // src/views/products/admin-product-list.tsx
707
- var ae = [
822
+ var ue = [
708
823
  "all",
709
824
  "live",
710
825
  "sold",
711
826
  "draft",
712
827
  "archived"
713
828
  ];
714
- function oe() {
715
- let e = A(), { labels: t, hrefs: n, renderLink: r } = k(), i = t.products, [a, o] = h("all"), [s, c] = h(""), l = re(s.trim(), 300), u = te(a), d = ne(a), f = ie({
829
+ function de() {
830
+ let e = F(), { labels: t, hrefs: n, renderLink: r } = P(), i = t.products, [a, o] = _("all"), [s, c] = _(""), l = W(s.trim(), 300), u = se(a), d = ce(a), f = le({
716
831
  ...u ? { status: u } : {},
717
832
  ...d ? { stock: d } : {},
718
833
  ...l ? { q: l } : {}
719
- }), [p, m] = h(null), [g, y] = h(!1), b = M(({ kind: t, product: n }) => e.updateProduct(n.id, t === "sold" ? { sold: !0 } : { status: "archived" })), x = async () => {
834
+ }), [p, m] = _(null), [h, g] = _(!1), v = L(({ kind: t, product: n }) => e.updateProduct(n.id, t === "sold" ? { sold: !0 } : { status: "archived" })), x = async () => {
720
835
  if (!p) return;
721
- let e = await b.run(p);
722
- m(null), e && (y(!0), f.reload());
836
+ let e = await v.run(p);
837
+ m(null), e && (g(!0), f.reload());
723
838
  }, S = [
724
839
  {
725
840
  key: "image",
726
841
  header: i.columns.image,
727
- render: (e) => e.images[0] ? /* @__PURE__ */ _("img", {
842
+ render: (e) => e.images[0] ? /* @__PURE__ */ y("img", {
728
843
  className: "sfa-thumb",
729
844
  src: e.images[0].url,
730
845
  alt: e.images[0].alt,
731
846
  width: 48,
732
847
  height: 48
733
- }) : /* @__PURE__ */ _("span", {
848
+ }) : /* @__PURE__ */ y("span", {
734
849
  className: "sfa-thumb sfa-thumb--empty",
735
850
  children: i.noImage
736
851
  })
@@ -747,7 +862,7 @@ function oe() {
747
862
  {
748
863
  key: "price",
749
864
  header: i.columns.price,
750
- render: (e) => /* @__PURE__ */ _(I, {
865
+ render: (e) => /* @__PURE__ */ y(B, {
751
866
  cents: e.priceCents,
752
867
  currency: e.currency
753
868
  })
@@ -755,7 +870,7 @@ function oe() {
755
870
  {
756
871
  key: "status",
757
872
  header: i.columns.status,
758
- render: (e) => /* @__PURE__ */ _(F, { status: ee(e) })
873
+ render: (e) => /* @__PURE__ */ y(z, { status: oe(e) })
759
874
  },
760
875
  {
761
876
  key: "quantity",
@@ -765,7 +880,7 @@ function oe() {
765
880
  {
766
881
  key: "actions",
767
882
  header: i.columns.actions,
768
- render: (e) => /* @__PURE__ */ v("div", {
883
+ render: (e) => /* @__PURE__ */ b("div", {
769
884
  className: "sfa-row-actions",
770
885
  children: [
771
886
  e.status === "active" && n.storefrontProduct ? r({
@@ -773,7 +888,7 @@ function oe() {
773
888
  children: i.viewInShop,
774
889
  className: "sfa-btn"
775
890
  }) : null,
776
- e.status !== "archived" && e.quantity > 0 ? /* @__PURE__ */ _("button", {
891
+ e.status !== "archived" && e.quantity > 0 ? /* @__PURE__ */ y("button", {
777
892
  type: "button",
778
893
  className: "sfa-btn",
779
894
  onClick: () => m({
@@ -782,7 +897,7 @@ function oe() {
782
897
  }),
783
898
  children: i.markSold
784
899
  }) : null,
785
- e.status === "archived" ? null : /* @__PURE__ */ _("button", {
900
+ e.status === "archived" ? null : /* @__PURE__ */ y("button", {
786
901
  type: "button",
787
902
  className: "sfa-btn",
788
903
  onClick: () => m({
@@ -795,31 +910,31 @@ function oe() {
795
910
  })
796
911
  }
797
912
  ], C = f.items, w = l ? i.noMatches : i.empty[a];
798
- return /* @__PURE__ */ v("section", {
913
+ return /* @__PURE__ */ b("section", {
799
914
  className: "sfa-products",
800
915
  children: [
801
- /* @__PURE__ */ v("header", {
916
+ /* @__PURE__ */ b("header", {
802
917
  className: "sfa-products__header",
803
- children: [/* @__PURE__ */ _("h1", { children: i.title }), r({
918
+ children: [/* @__PURE__ */ y("h1", { children: i.title }), r({
804
919
  href: n.newProduct,
805
920
  children: i.newProduct,
806
921
  className: "sfa-btn sfa-btn--primary"
807
922
  })]
808
923
  }),
809
- /* @__PURE__ */ v("div", {
924
+ /* @__PURE__ */ b("div", {
810
925
  className: "sfa-products__toolbar",
811
- children: [/* @__PURE__ */ _("div", {
926
+ children: [/* @__PURE__ */ y("div", {
812
927
  role: "group",
813
928
  "aria-label": i.columns.status,
814
929
  className: "sfa-filter-group",
815
- children: ae.map((e) => /* @__PURE__ */ _("button", {
930
+ children: ue.map((e) => /* @__PURE__ */ y("button", {
816
931
  type: "button",
817
932
  className: "sfa-btn sfa-filter",
818
933
  "aria-pressed": a === e,
819
934
  onClick: () => o(e),
820
935
  children: i.filters[e]
821
936
  }, e))
822
- }), /* @__PURE__ */ _("input", {
937
+ }), /* @__PURE__ */ y("input", {
823
938
  type: "search",
824
939
  "aria-label": i.searchLabel,
825
940
  placeholder: i.searchPlaceholder,
@@ -827,57 +942,57 @@ function oe() {
827
942
  onChange: (e) => c(e.target.value)
828
943
  })]
829
944
  }),
830
- /* @__PURE__ */ _(H, { error: f.error ?? b.error }),
831
- f.loading && !f.loaded ? /* @__PURE__ */ _("p", { children: t.loading }) : C.length === 0 ? /* @__PURE__ */ _("p", {
945
+ /* @__PURE__ */ y(U, { error: f.error ?? v.error }),
946
+ f.loading && !f.loaded ? /* @__PURE__ */ y("p", { children: t.loading }) : C.length === 0 ? /* @__PURE__ */ y("p", {
832
947
  className: "sfa-empty",
833
948
  children: w
834
- }) : /* @__PURE__ */ _(P, {
949
+ }) : /* @__PURE__ */ y(R, {
835
950
  columns: S,
836
951
  rows: C,
837
952
  rowKey: (e) => e.id
838
953
  }),
839
- f.hasMore ? /* @__PURE__ */ _("button", {
954
+ f.hasMore ? /* @__PURE__ */ y("button", {
840
955
  type: "button",
841
956
  className: "sfa-btn sfa-products__more",
842
957
  disabled: f.loadingMore,
843
958
  onClick: f.loadMore,
844
959
  children: i.loadMore
845
960
  }) : null,
846
- /* @__PURE__ */ _(R, {
961
+ /* @__PURE__ */ y(V, {
847
962
  open: p !== null,
848
963
  title: p?.kind === "archive" ? i.archiveTitle : i.markSoldTitle,
849
964
  confirmLabel: p?.kind === "archive" ? i.archive : i.markSold,
850
- pending: b.pending,
965
+ pending: v.pending,
851
966
  onConfirm: x,
852
967
  onCancel: () => m(null),
853
- children: /* @__PURE__ */ v("p", { children: [
968
+ children: /* @__PURE__ */ b("p", { children: [
854
969
  p?.product.name,
855
970
  " — ",
856
971
  p?.kind === "archive" ? i.archiveBody : i.markSoldBody
857
972
  ] })
858
973
  }),
859
- g ? /* @__PURE__ */ _(z, {
974
+ h ? /* @__PURE__ */ y(H, {
860
975
  variant: "success",
861
976
  toast: !0,
862
- onDismiss: () => y(!1),
977
+ onDismiss: () => g(!1),
863
978
  children: i.updated
864
979
  }) : null
865
980
  ]
866
981
  });
867
982
  }
868
983
  // src/lib/money-input.ts
869
- var se = /^\$?\s*(\d+|\d{1,3}(?:,\d{3})+)?(?:\.(\d{1,2}))?$/;
870
- function W(e) {
871
- let t = e.trim(), n = se.exec(t);
984
+ var fe = /^\$?\s*(\d+|\d{1,3}(?:,\d{3})+)?(?:\.(\d{1,2}))?$/;
985
+ function G(e) {
986
+ let t = e.trim(), n = fe.exec(t);
872
987
  if (!n || !n[1] && !n[2]) return null;
873
988
  let r = Number((n[1] ?? "0").replace(/,/g, "")), i = Number((n[2] ?? "").padEnd(2, "0")), a = r * 100 + i;
874
989
  return Number.isSafeInteger(a) ? a : null;
875
990
  }
876
- function G(e) {
991
+ function K(e) {
877
992
  return `${Math.floor(e / 100)}.${String(e % 100).padStart(2, "0")}`;
878
993
  }
879
994
  // src/lib/product-form.ts
880
- var K = [
995
+ var pe = [
881
996
  "name",
882
997
  "category",
883
998
  "description",
@@ -887,7 +1002,7 @@ var K = [
887
1002
  "quantity",
888
1003
  "status",
889
1004
  "featured"
890
- ], ce = {
1005
+ ], me = {
891
1006
  name: "",
892
1007
  category: "",
893
1008
  description: "",
@@ -898,48 +1013,48 @@ var K = [
898
1013
  status: "draft",
899
1014
  featured: !1
900
1015
  };
901
- function q(e) {
1016
+ function he(e) {
902
1017
  return {
903
1018
  name: e.name,
904
1019
  category: e.category,
905
1020
  description: e.description,
906
1021
  materials: e.materials ?? "",
907
1022
  dimensions: e.dimensions ?? "",
908
- price: G(e.priceCents),
1023
+ price: K(e.priceCents),
909
1024
  quantity: String(e.quantity),
910
1025
  status: e.status,
911
1026
  featured: e.featured
912
1027
  };
913
1028
  }
914
- function le(e) {
1029
+ function ge(e) {
915
1030
  let t = String(Array.isArray(e) ? e[0] ?? "" : e ?? ""), n = t === "priceCents" ? "price" : t;
916
- return K.includes(n) ? n : void 0;
1031
+ return pe.includes(n) ? n : void 0;
917
1032
  }
918
- function ue(e) {
1033
+ function _e(e) {
919
1034
  let t = {};
920
1035
  for (let n of e) {
921
- let { path: e, message: r } = n ?? {}, i = le(e);
1036
+ let { path: e, message: r } = n ?? {}, i = ge(e);
922
1037
  i && !t[i] && (t[i] = typeof r == "string" ? r : "Invalid value.");
923
1038
  }
924
1039
  return t;
925
1040
  }
926
- function de(e) {
927
- return K.find((t) => e[t]);
1041
+ function ve(e) {
1042
+ return pe.find((t) => e[t]);
928
1043
  }
929
- function fe(e) {
1044
+ function ye(e) {
930
1045
  let t = e.trim();
931
1046
  return t === "" ? null : t;
932
1047
  }
933
- function pe(e, t, n) {
934
- let r = {}, i = W(e.price);
1048
+ function be(e, t, n) {
1049
+ let r = {}, i = G(e.price);
935
1050
  i === null && (r.price = t.validation.price);
936
1051
  let a = /^\d+$/.test(e.quantity.trim()) ? Number(e.quantity.trim()) : null;
937
1052
  a === null && (r.quantity = t.validation.quantity);
938
- let o = y.safeParse({
1053
+ let o = x.safeParse({
939
1054
  name: e.name,
940
1055
  description: e.description,
941
- materials: fe(e.materials),
942
- dimensions: fe(e.dimensions),
1056
+ materials: ye(e.materials),
1057
+ dimensions: ye(e.dimensions),
943
1058
  priceCents: i ?? 0,
944
1059
  ...n ? { currency: n } : {},
945
1060
  category: e.category,
@@ -948,7 +1063,7 @@ function pe(e, t, n) {
948
1063
  featured: e.featured
949
1064
  });
950
1065
  if (!o.success) for (let e of o.error.issues) {
951
- let n = le(e.path);
1066
+ let n = ge(e.path);
952
1067
  n && !r[n] && (r[n] = t.validation.required);
953
1068
  }
954
1069
  return !o.success || Object.keys(r).length > 0 ? {
@@ -959,7 +1074,7 @@ function pe(e, t, n) {
959
1074
  input: o.data
960
1075
  };
961
1076
  }
962
- var me = [
1077
+ var xe = [
963
1078
  "name",
964
1079
  "description",
965
1080
  "materials",
@@ -970,33 +1085,33 @@ var me = [
970
1085
  "status",
971
1086
  "featured"
972
1087
  ];
973
- function he(e, t) {
1088
+ function Se(e, t) {
974
1089
  let n = {};
975
- for (let r of me) (t[r] ?? null) !== e[r] && (n[r] = t[r]);
1090
+ for (let r of xe) (t[r] ?? null) !== e[r] && (n[r] = t[r]);
976
1091
  return n;
977
1092
  }
978
- var ge = [
1093
+ var Ce = [
979
1094
  "image/jpeg",
980
1095
  "image/png",
981
1096
  "image/webp",
982
1097
  "image/heic"
983
1098
  ];
984
- function J(e, t) {
1099
+ function q(e, t) {
985
1100
  return e.replace(/\{(\w+)\}/g, (e, n) => t[n] ?? "");
986
1101
  }
987
- function _e(e, t) {
988
- return ge.includes(e.type) ? e.size > 8388608 ? J(t.tooLarge, { name: e.name }) : null : J(t.wrongType, { name: e.name });
1102
+ function we(e, t) {
1103
+ return Ce.includes(e.type) ? e.size > 8388608 ? q(t.tooLarge, { name: e.name }) : null : q(t.wrongType, { name: e.name });
989
1104
  }
990
1105
  // src/lib/use-image-upload.ts
991
- function ve({ productId: e, onUploaded: t }) {
992
- let n = A(), { labels: r } = k(), [i, a] = h([]), o = m(0), s = m(Promise.resolve()), c = m(t);
993
- p(() => {
1106
+ function Te({ productId: e, onUploaded: t }) {
1107
+ let n = F(), { labels: r } = P(), [i, a] = _([]), o = g(0), s = g(Promise.resolve()), c = g(t);
1108
+ h(() => {
994
1109
  c.current = t;
995
1110
  });
996
1111
  let l = (e, t) => a((n) => n.map((n) => n.id === e ? {
997
1112
  ...n,
998
1113
  ...t
999
- } : n)), u = (e) => a((t) => t.filter((t) => t.id !== e)), f = async (t, r, i) => {
1114
+ } : n)), u = (e) => a((t) => t.filter((t) => t.id !== e)), d = async (t, r, i) => {
1000
1115
  l(t, { status: "uploading" });
1001
1116
  try {
1002
1117
  let a = await n.uploadProductImage(e, r, i);
@@ -1010,11 +1125,11 @@ function ve({ productId: e, onUploaded: t }) {
1010
1125
  };
1011
1126
  return {
1012
1127
  entries: i,
1013
- upload: d((e, t) => {
1128
+ upload: p((e, t) => {
1014
1129
  let n = e.map((e) => ({
1015
1130
  id: o.current++,
1016
1131
  file: e,
1017
- reason: _e(e, r.products.images)
1132
+ reason: we(e, r.products.images)
1018
1133
  }));
1019
1134
  a((e) => [...e, ...n.map(({ id: e, file: t, reason: n }) => ({
1020
1135
  id: e,
@@ -1022,7 +1137,7 @@ function ve({ productId: e, onUploaded: t }) {
1022
1137
  status: n ? "error" : "queued",
1023
1138
  reason: n ?? void 0
1024
1139
  }))]);
1025
- for (let { id: e, file: r, reason: i } of n) i || (s.current = s.current.then(() => f(e, r, t.trim())));
1140
+ for (let { id: e, file: r, reason: i } of n) i || (s.current = s.current.then(() => d(e, r, t.trim())));
1026
1141
  }, [
1027
1142
  n,
1028
1143
  e,
@@ -1031,47 +1146,108 @@ function ve({ productId: e, onUploaded: t }) {
1031
1146
  dismiss: u
1032
1147
  };
1033
1148
  }
1149
+ // src/views/products/image-alt-editor.tsx
1150
+ function Ee({ imageId: e, alt: t, name: n, labels: r, onSave: i }) {
1151
+ let [a, o] = _(null), [s, c] = _(!1), [l, u] = _(void 0), d = () => {
1152
+ o(null), u(void 0);
1153
+ };
1154
+ return a === null ? /* @__PURE__ */ y("button", {
1155
+ type: "button",
1156
+ className: "sfa-btn",
1157
+ "aria-label": `${r.editAlt}: ${n}`,
1158
+ onClick: () => o(t),
1159
+ children: r.editAlt
1160
+ }) : /* @__PURE__ */ b("form", {
1161
+ className: "sfa-image-tile__alt",
1162
+ onSubmit: async (e) => {
1163
+ if (e.preventDefault(), a !== null) {
1164
+ c(!0), u(void 0);
1165
+ try {
1166
+ await i(a), o(null);
1167
+ } catch (e) {
1168
+ u(e);
1169
+ } finally {
1170
+ c(!1);
1171
+ }
1172
+ }
1173
+ },
1174
+ children: [
1175
+ /* @__PURE__ */ y("input", {
1176
+ "aria-label": `${r.altLabel}: ${n}`,
1177
+ value: a,
1178
+ disabled: s,
1179
+ autoFocus: !0,
1180
+ onChange: (e) => o(e.target.value),
1181
+ onKeyDown: (e) => {
1182
+ e.key === "Escape" && d();
1183
+ }
1184
+ }),
1185
+ /* @__PURE__ */ y(U, { error: l }),
1186
+ /* @__PURE__ */ y("button", {
1187
+ type: "submit",
1188
+ className: "sfa-btn",
1189
+ "data-image-id": e,
1190
+ disabled: s,
1191
+ children: r.saveAlt
1192
+ }),
1193
+ /* @__PURE__ */ y("button", {
1194
+ type: "button",
1195
+ className: "sfa-btn",
1196
+ disabled: s,
1197
+ onClick: d,
1198
+ children: r.cancelAlt
1199
+ })
1200
+ ]
1201
+ });
1202
+ }
1034
1203
  // src/views/products/image-tile.tsx
1035
- function ye({ image: e, index: t, total: n, busy: r, labels: i, onMove: a, onRemove: o }) {
1036
- let { renderImage: s } = k(), c = e.alt || J(i.photoName, { n: String(t + 1) }), l = (t, n, r) => /* @__PURE__ */ _("button", {
1204
+ function De({ image: e, index: t, total: n, busy: r, labels: i, onMove: a, onRemove: o, onSaveAlt: s }) {
1205
+ let { renderImage: c } = P(), l = e.alt || q(i.photoName, { n: String(t + 1) }), u = (t, n, r) => /* @__PURE__ */ y("button", {
1037
1206
  type: "button",
1038
1207
  className: "sfa-btn",
1039
1208
  "data-image-id": e.id,
1040
1209
  "data-move": t,
1041
- "aria-label": `${n}: ${c}`,
1210
+ "aria-label": `${n}: ${l}`,
1042
1211
  disabled: r,
1043
1212
  onClick: () => a(t),
1044
1213
  children: n
1045
1214
  });
1046
- return /* @__PURE__ */ v("li", {
1215
+ return /* @__PURE__ */ b("li", {
1047
1216
  className: "sfa-image-tile",
1048
1217
  "aria-busy": r,
1049
1218
  "data-image-id": e.id,
1050
1219
  children: [
1051
- s({
1220
+ c({
1052
1221
  src: e.url,
1053
1222
  alt: e.alt,
1054
1223
  sizes: "160px",
1055
1224
  className: "sfa-image-tile__img"
1056
1225
  }),
1057
- t === 0 ? /* @__PURE__ */ _("span", {
1226
+ t === 0 ? /* @__PURE__ */ y("span", {
1058
1227
  className: "sfa-image-tile__cover",
1059
1228
  children: i.cover
1060
1229
  }) : null,
1061
- r ? /* @__PURE__ */ _("span", {
1230
+ r ? /* @__PURE__ */ y("span", {
1062
1231
  className: "sfa-spinner",
1063
1232
  role: "status",
1064
1233
  children: i.working
1065
1234
  }) : null,
1066
- /* @__PURE__ */ v("div", {
1235
+ /* @__PURE__ */ b("div", {
1067
1236
  className: "sfa-image-tile__actions",
1068
1237
  children: [
1069
- l("earlier", i.moveEarlier, t === 0),
1070
- l("later", i.moveLater, t === n - 1),
1071
- /* @__PURE__ */ _("button", {
1238
+ u("earlier", i.moveEarlier, t === 0),
1239
+ u("later", i.moveLater, t === n - 1),
1240
+ /* @__PURE__ */ y(Ee, {
1241
+ imageId: e.id,
1242
+ alt: e.alt,
1243
+ name: l,
1244
+ labels: i,
1245
+ onSave: s
1246
+ }),
1247
+ /* @__PURE__ */ y("button", {
1072
1248
  type: "button",
1073
1249
  className: "sfa-btn sfa-btn--danger",
1074
- "aria-label": `${i.remove}: ${c}`,
1250
+ "aria-label": `${i.remove}: ${l}`,
1075
1251
  onClick: o,
1076
1252
  children: i.remove
1077
1253
  })
@@ -1081,24 +1257,24 @@ function ye({ image: e, index: t, total: n, busy: r, labels: i, onMove: a, onRem
1081
1257
  });
1082
1258
  }
1083
1259
  // src/views/products/upload-picker.tsx
1084
- function be({ labels: e, onFiles: t }) {
1260
+ function Oe({ labels: e, onFiles: t }) {
1085
1261
  let n = (e) => {
1086
1262
  t(Array.from(e.target.files ?? [])), e.target.value = "";
1087
1263
  };
1088
- return /* @__PURE__ */ v("div", {
1264
+ return /* @__PURE__ */ b("div", {
1089
1265
  className: "sfa-image-picker",
1090
- children: [/* @__PURE__ */ v("label", {
1266
+ children: [/* @__PURE__ */ b("label", {
1091
1267
  className: "sfa-btn sfa-image-picker__btn",
1092
- children: [e.add, /* @__PURE__ */ _("input", {
1268
+ children: [e.add, /* @__PURE__ */ y("input", {
1093
1269
  type: "file",
1094
1270
  accept: "image/*",
1095
1271
  multiple: !0,
1096
1272
  className: "sfa-sr-only",
1097
1273
  onChange: n
1098
1274
  })]
1099
- }), /* @__PURE__ */ v("label", {
1275
+ }), /* @__PURE__ */ b("label", {
1100
1276
  className: "sfa-btn sfa-image-picker__btn",
1101
- children: [e.takePhoto, /* @__PURE__ */ _("input", {
1277
+ children: [e.takePhoto, /* @__PURE__ */ y("input", {
1102
1278
  type: "file",
1103
1279
  accept: "image/*",
1104
1280
  capture: "environment",
@@ -1109,61 +1285,76 @@ function be({ labels: e, onFiles: t }) {
1109
1285
  });
1110
1286
  }
1111
1287
  // src/views/products/admin-product-images.tsx
1112
- var Y = (e) => [...e].sort((e, t) => e.position - t.position);
1113
- function xe({ productId: e, images: t }) {
1114
- let n = A(), { labels: r } = k(), i = r.products.images, [a, o] = h(() => Y(t)), [s, c] = h(null), [l, u] = h(!1), [d, f] = h(""), [y, b] = h(void 0), [x, S] = h(!1), [C, w] = h(null), T = m(null), E = m(null), { entries: D, upload: O, dismiss: j } = ve({
1288
+ var J = (e) => [...e].sort((e, t) => e.position - t.position);
1289
+ function ke({ productId: e, images: t }) {
1290
+ let n = F(), { labels: r } = P(), i = r.products.images, [a, o] = _(() => J(t)), [s, c] = _(null), [l, u] = _(!1), [d, f] = _(""), [p, m] = _(void 0), [x, S] = _(!1), [C, w] = _(null), T = g(null), E = g(null), { entries: D, upload: O, dismiss: k } = Te({
1115
1291
  productId: e,
1116
- onUploaded: (e) => o(Y(e.images))
1292
+ onUploaded: (e) => o(J(e.images))
1117
1293
  });
1118
- p(() => {
1294
+ h(() => {
1119
1295
  let e = T.current;
1120
1296
  if (!e) return;
1121
1297
  T.current = null;
1122
1298
  let t = (t) => E.current?.querySelector(`[data-image-id="${e.id}"][data-move="${t}"]:not(:disabled)`), n = e.direction === "earlier" ? "later" : "earlier";
1123
1299
  (t(e.direction) ?? t(n))?.focus();
1124
1300
  }, [a]);
1125
- let M = async (t, r) => {
1301
+ let A = async (t, r) => {
1126
1302
  let i = r === "earlier" ? t - 1 : t + 1;
1127
1303
  if (l || i < 0 || i >= a.length) return;
1128
1304
  let s = a, d = [...a];
1129
1305
  [d[t], d[i]] = [d[i], d[t]], T.current = {
1130
1306
  id: a[t].id,
1131
1307
  direction: r
1132
- }, o(d), u(!0), c(a[t].id), b(void 0), S(!1);
1308
+ }, o(d), u(!0), c(a[t].id), m(void 0), S(!1);
1133
1309
  try {
1134
1310
  let t = await n.reorderProductImages(e, d.map((e) => e.id));
1135
- o(Y(t.images));
1311
+ o(J(t.images));
1136
1312
  } catch (e) {
1137
1313
  T.current = {
1138
1314
  id: a[t].id,
1139
1315
  direction: r
1140
- }, o(s), b(e), S(!0);
1316
+ }, o(s), m(e), S(!0);
1141
1317
  } finally {
1142
1318
  u(!1), c(null);
1143
1319
  }
1320
+ }, j = async () => {
1321
+ if (!C) return;
1322
+ let t = C;
1323
+ w(null), c(t.id), m(void 0), S(!1);
1324
+ try {
1325
+ let r = await n.deleteProductImage(e, t.id);
1326
+ o(J(r.images));
1327
+ } catch (e) {
1328
+ m(e);
1329
+ } finally {
1330
+ c(null);
1331
+ }
1332
+ }, M = async (t, r) => {
1333
+ let i = await n.updateProductImage(e, t, { alt: r });
1334
+ o(J(i.images));
1144
1335
  };
1145
- return /* @__PURE__ */ v("div", {
1336
+ return /* @__PURE__ */ b("div", {
1146
1337
  className: "sfa-images",
1147
1338
  onDragOver: (e) => e.preventDefault(),
1148
1339
  onDrop: (e) => {
1149
1340
  e.preventDefault(), O(Array.from(e.dataTransfer.files), d);
1150
1341
  },
1151
1342
  children: [
1152
- /* @__PURE__ */ _("h2", { children: i.title }),
1153
- x ? /* @__PURE__ */ _(z, {
1343
+ /* @__PURE__ */ y("h2", { children: i.title }),
1344
+ x ? /* @__PURE__ */ y(H, {
1154
1345
  variant: "error",
1155
1346
  onDismiss: () => S(!1),
1156
1347
  children: i.reorderFailed
1157
- }) : /* @__PURE__ */ _(H, { error: y }),
1158
- /* @__PURE__ */ v("div", {
1348
+ }) : /* @__PURE__ */ y(U, { error: p }),
1349
+ /* @__PURE__ */ b("div", {
1159
1350
  className: "sfa-field",
1160
1351
  children: [
1161
- /* @__PURE__ */ _("label", {
1352
+ /* @__PURE__ */ y("label", {
1162
1353
  className: "sfa-field__label",
1163
1354
  htmlFor: `${e}-image-alt`,
1164
1355
  children: i.altLabel
1165
1356
  }),
1166
- /* @__PURE__ */ _("input", {
1357
+ /* @__PURE__ */ y("input", {
1167
1358
  id: `${e}-image-alt`,
1168
1359
  value: d,
1169
1360
  onChange: (e) => f(e.target.value),
@@ -1171,85 +1362,74 @@ function xe({ productId: e, images: t }) {
1171
1362
  e.key === "Enter" && e.preventDefault();
1172
1363
  }
1173
1364
  }),
1174
- /* @__PURE__ */ _("p", {
1365
+ /* @__PURE__ */ y("p", {
1175
1366
  className: "sfa-field__help",
1176
1367
  children: i.altHelp
1177
1368
  }),
1178
- d.trim() === "" ? /* @__PURE__ */ _("p", {
1369
+ d.trim() === "" ? /* @__PURE__ */ y("p", {
1179
1370
  className: "sfa-field__error",
1180
1371
  children: i.altWarning
1181
1372
  }) : null
1182
1373
  ]
1183
1374
  }),
1184
- /* @__PURE__ */ _(be, {
1375
+ /* @__PURE__ */ y(Oe, {
1185
1376
  labels: i,
1186
1377
  onFiles: (e) => O(e, d)
1187
1378
  }),
1188
- /* @__PURE__ */ _("p", {
1379
+ /* @__PURE__ */ y("p", {
1189
1380
  className: "sfa-field__help",
1190
1381
  children: i.dropHint
1191
1382
  }),
1192
- a.length === 0 && D.length === 0 ? /* @__PURE__ */ _("p", { children: i.empty }) : null,
1193
- /* @__PURE__ */ v("ul", {
1383
+ a.length === 0 && D.length === 0 ? /* @__PURE__ */ y("p", { children: i.empty }) : null,
1384
+ /* @__PURE__ */ b("ul", {
1194
1385
  ref: E,
1195
1386
  className: "sfa-image-grid",
1196
- children: [a.map((e, t) => /* @__PURE__ */ _(ye, {
1387
+ children: [a.map((e, t) => /* @__PURE__ */ y(De, {
1197
1388
  image: e,
1198
1389
  index: t,
1199
1390
  total: a.length,
1200
1391
  busy: s === e.id,
1201
1392
  labels: i,
1202
- onMove: (e) => M(t, e),
1203
- onRemove: () => w(e)
1204
- }, e.id)), D.map((e) => /* @__PURE__ */ v("li", {
1393
+ onMove: (e) => A(t, e),
1394
+ onRemove: () => w(e),
1395
+ onSaveAlt: (t) => M(e.id, t)
1396
+ }, e.id)), D.map((e) => /* @__PURE__ */ b("li", {
1205
1397
  className: "sfa-image-tile",
1206
1398
  "aria-busy": e.status !== "error",
1207
- children: [/* @__PURE__ */ _("span", { children: e.name }), e.status === "error" ? /* @__PURE__ */ v(g, { children: [e.reason ? /* @__PURE__ */ _(z, {
1399
+ children: [/* @__PURE__ */ y("span", { children: e.name }), e.status === "error" ? /* @__PURE__ */ b(v, { children: [e.reason ? /* @__PURE__ */ y(H, {
1208
1400
  variant: "error",
1209
1401
  children: e.reason
1210
- }) : /* @__PURE__ */ _(H, { error: e.error }), /* @__PURE__ */ _("button", {
1402
+ }) : /* @__PURE__ */ y(U, { error: e.error }), /* @__PURE__ */ y("button", {
1211
1403
  type: "button",
1212
1404
  className: "sfa-btn",
1213
- onClick: () => j(e.id),
1405
+ onClick: () => k(e.id),
1214
1406
  children: i.dismiss
1215
- })] }) : /* @__PURE__ */ _("span", {
1407
+ })] }) : /* @__PURE__ */ y("span", {
1216
1408
  className: "sfa-spinner",
1217
1409
  role: "status",
1218
1410
  children: e.status === "uploading" ? i.uploading : i.working
1219
1411
  })]
1220
1412
  }, e.id))]
1221
1413
  }),
1222
- /* @__PURE__ */ _(R, {
1414
+ /* @__PURE__ */ y(V, {
1223
1415
  open: C !== null,
1224
1416
  title: i.removeTitle,
1225
1417
  destructive: !0,
1226
1418
  confirmLabel: i.remove,
1227
- onConfirm: async () => {
1228
- if (!C) return;
1229
- let t = C;
1230
- w(null), c(t.id), b(void 0), S(!1);
1231
- try {
1232
- let r = await n.deleteProductImage(e, t.id);
1233
- o(Y(r.images));
1234
- } catch (e) {
1235
- b(e);
1236
- } finally {
1237
- c(null);
1238
- }
1239
- },
1419
+ onConfirm: j,
1240
1420
  onCancel: () => w(null),
1241
- children: /* @__PURE__ */ _("p", { children: i.removeBody })
1421
+ children: /* @__PURE__ */ y("p", { children: i.removeBody })
1242
1422
  })
1243
1423
  ]
1244
1424
  });
1245
1425
  }
1246
1426
  // src/views/products/product-fields.tsx
1247
- function X({ name: e, label: t, error: n, help: r, children: i }) {
1427
+ function Y({ name: e, label: t, error: n, help: r, children: i }) {
1248
1428
  let a = `sfa-field-${e}`, o = [r ? `${a}-help` : "", n ? `${a}-error` : ""].filter(Boolean).join(" ");
1249
- return /* @__PURE__ */ v("div", {
1429
+ return /* @__PURE__ */ b("div", {
1250
1430
  className: "sfa-field",
1251
1431
  children: [
1252
- /* @__PURE__ */ _("label", {
1432
+ /* @__PURE__ */ y("label", {
1253
1433
  htmlFor: a,
1254
1434
  className: "sfa-field__label",
1255
1435
  children: t
@@ -1260,12 +1440,12 @@ function X({ name: e, label: t, error: n, help: r, children: i }) {
1260
1440
  "aria-invalid": !!n,
1261
1441
  "aria-describedby": o || void 0
1262
1442
  }),
1263
- r ? /* @__PURE__ */ _("p", {
1443
+ r ? /* @__PURE__ */ y("p", {
1264
1444
  id: `${a}-help`,
1265
1445
  className: "sfa-field__help",
1266
1446
  children: r
1267
1447
  }) : null,
1268
- n ? /* @__PURE__ */ _("p", {
1448
+ n ? /* @__PURE__ */ y("p", {
1269
1449
  id: `${a}-error`,
1270
1450
  className: "sfa-field__error",
1271
1451
  children: n
@@ -1273,32 +1453,32 @@ function X({ name: e, label: t, error: n, help: r, children: i }) {
1273
1453
  ]
1274
1454
  });
1275
1455
  }
1276
- var Se = "sfa-field-category-options";
1277
- function Ce({ form: e, errors: t, labels: n, categories: r, onChange: i }) {
1278
- let a = !!r?.length, o = (r) => /* @__PURE__ */ _(X, {
1456
+ var Ae = "sfa-field-category-options";
1457
+ function je({ form: e, errors: t, labels: n, categories: r, onChange: i }) {
1458
+ let a = !!r?.length, o = (r) => /* @__PURE__ */ y(Y, {
1279
1459
  name: r,
1280
1460
  label: n.fields[r],
1281
1461
  error: t[r],
1282
- children: (t) => /* @__PURE__ */ _("input", {
1462
+ children: (t) => /* @__PURE__ */ y("input", {
1283
1463
  ...t,
1284
1464
  type: "text",
1285
- list: r === "category" && a ? Se : void 0,
1465
+ list: r === "category" && a ? Ae : void 0,
1286
1466
  value: e[r],
1287
1467
  onChange: (e) => i(r, e.target.value)
1288
1468
  })
1289
1469
  });
1290
- return /* @__PURE__ */ v(g, { children: [
1470
+ return /* @__PURE__ */ b(v, { children: [
1291
1471
  o("name"),
1292
1472
  o("category"),
1293
- a ? /* @__PURE__ */ _("datalist", {
1294
- id: Se,
1295
- children: r?.map((e) => /* @__PURE__ */ _("option", { value: e }, e))
1473
+ a ? /* @__PURE__ */ y("datalist", {
1474
+ id: Ae,
1475
+ children: r?.map((e) => /* @__PURE__ */ y("option", { value: e }, e))
1296
1476
  }) : null,
1297
- /* @__PURE__ */ _(X, {
1477
+ /* @__PURE__ */ y(Y, {
1298
1478
  name: "description",
1299
1479
  label: n.fields.description,
1300
1480
  error: t.description,
1301
- children: (t) => /* @__PURE__ */ _("textarea", {
1481
+ children: (t) => /* @__PURE__ */ y("textarea", {
1302
1482
  ...t,
1303
1483
  rows: 5,
1304
1484
  value: e.description,
@@ -1309,19 +1489,19 @@ function Ce({ form: e, errors: t, labels: n, categories: r, onChange: i }) {
1309
1489
  o("dimensions")
1310
1490
  ] });
1311
1491
  }
1312
- var we = [
1492
+ var Me = [
1313
1493
  "draft",
1314
1494
  "active",
1315
1495
  "archived"
1316
1496
  ];
1317
- function Te({ form: e, errors: t, labels: n, statusLabels: r, onChange: i }) {
1318
- return /* @__PURE__ */ v(g, { children: [
1319
- /* @__PURE__ */ _(X, {
1497
+ function Ne({ form: e, errors: t, labels: n, statusLabels: r, onChange: i }) {
1498
+ return /* @__PURE__ */ b(v, { children: [
1499
+ /* @__PURE__ */ y(Y, {
1320
1500
  name: "price",
1321
1501
  label: n.fields.price,
1322
1502
  error: t.price,
1323
1503
  help: n.priceHelp,
1324
- children: (t) => /* @__PURE__ */ _("input", {
1504
+ children: (t) => /* @__PURE__ */ y("input", {
1325
1505
  ...t,
1326
1506
  type: "text",
1327
1507
  inputMode: "decimal",
@@ -1329,11 +1509,11 @@ function Te({ form: e, errors: t, labels: n, statusLabels: r, onChange: i }) {
1329
1509
  onChange: (e) => i("price", e.target.value)
1330
1510
  })
1331
1511
  }),
1332
- /* @__PURE__ */ _(X, {
1512
+ /* @__PURE__ */ y(Y, {
1333
1513
  name: "quantity",
1334
1514
  label: n.fields.quantity,
1335
1515
  error: t.quantity,
1336
- children: (t) => /* @__PURE__ */ _("input", {
1516
+ children: (t) => /* @__PURE__ */ y("input", {
1337
1517
  ...t,
1338
1518
  type: "text",
1339
1519
  inputMode: "numeric",
@@ -1341,75 +1521,75 @@ function Te({ form: e, errors: t, labels: n, statusLabels: r, onChange: i }) {
1341
1521
  onChange: (e) => i("quantity", e.target.value)
1342
1522
  })
1343
1523
  }),
1344
- /* @__PURE__ */ _(X, {
1524
+ /* @__PURE__ */ y(Y, {
1345
1525
  name: "status",
1346
1526
  label: n.fields.status,
1347
1527
  error: t.status,
1348
1528
  help: n.statusHelp,
1349
- children: (t) => /* @__PURE__ */ _("select", {
1529
+ children: (t) => /* @__PURE__ */ y("select", {
1350
1530
  ...t,
1351
1531
  value: e.status,
1352
1532
  onChange: (e) => i("status", e.target.value),
1353
- children: we.map((e) => /* @__PURE__ */ _("option", {
1533
+ children: Me.map((e) => /* @__PURE__ */ y("option", {
1354
1534
  value: e,
1355
1535
  children: r[e] ?? e
1356
1536
  }, e))
1357
1537
  })
1358
1538
  }),
1359
- /* @__PURE__ */ _("div", {
1539
+ /* @__PURE__ */ y("div", {
1360
1540
  className: "sfa-field",
1361
- children: /* @__PURE__ */ v("label", {
1541
+ children: /* @__PURE__ */ b("label", {
1362
1542
  className: "sfa-check",
1363
1543
  htmlFor: "sfa-field-featured",
1364
- children: [/* @__PURE__ */ _("input", {
1544
+ children: [/* @__PURE__ */ y("input", {
1365
1545
  id: "sfa-field-featured",
1366
1546
  name: "featured",
1367
1547
  type: "checkbox",
1368
1548
  checked: e.featured,
1369
1549
  onChange: (e) => i("featured", e.target.checked)
1370
- }), /* @__PURE__ */ _("span", { children: n.fields.featured })]
1550
+ }), /* @__PURE__ */ y("span", { children: n.fields.featured })]
1371
1551
  })
1372
1552
  })
1373
1553
  ] });
1374
1554
  }
1375
1555
  // src/views/products/admin-product-editor.tsx
1376
- function Ee({ productId: e, onSaved: t, imagesSlot: n, categories: r }) {
1377
- return e ? /* @__PURE__ */ _(De, {
1556
+ function Pe({ productId: e, onSaved: t, imagesSlot: n, categories: r }) {
1557
+ return e ? /* @__PURE__ */ y(Fe, {
1378
1558
  productId: e,
1379
1559
  onSaved: t,
1380
1560
  imagesSlot: n,
1381
1561
  categories: r
1382
- }) : /* @__PURE__ */ _(Oe, {
1562
+ }) : /* @__PURE__ */ y(Ie, {
1383
1563
  product: void 0,
1384
1564
  onSaved: t,
1385
1565
  imagesSlot: null,
1386
1566
  categories: r
1387
1567
  });
1388
1568
  }
1389
- function De({ productId: e, onSaved: t, imagesSlot: n, categories: r }) {
1390
- let i = A(), { labels: a } = k(), o = j(["admin-product", e], () => i.getProduct(e));
1391
- return o.error ? /* @__PURE__ */ _(H, { error: o.error }) : o.data ? /* @__PURE__ */ _(Oe, {
1569
+ function Fe({ productId: e, onSaved: t, imagesSlot: n, categories: r }) {
1570
+ let i = F(), { labels: a } = P(), o = I(["admin-product", e], () => i.getProduct(e));
1571
+ return o.error ? /* @__PURE__ */ y(U, { error: o.error }) : o.data ? /* @__PURE__ */ y(Ie, {
1392
1572
  product: o.data,
1393
1573
  onSaved: t,
1394
1574
  imagesSlot: n,
1395
1575
  categories: r
1396
- }, o.data.id) : /* @__PURE__ */ _("p", { children: a.loading });
1576
+ }, o.data.id) : /* @__PURE__ */ y("p", { children: a.loading });
1397
1577
  }
1398
- function Oe({ product: e, onSaved: t, imagesSlot: n, categories: r }) {
1399
- let i = A(), { labels: a } = k(), o = a.products, [c, l] = h(e), [u, d] = h(e ? q(e) : ce), [f, p] = h({}), [m, g] = h(!1), y = (e, t) => {
1578
+ function Ie({ product: e, onSaved: t, imagesSlot: n, categories: r }) {
1579
+ let i = F(), { labels: a } = P(), o = a.products, [s, c] = _(e), [u, d] = _(e ? he(e) : me), [f, p] = _({}), [m, h] = _(!1), g = (e, t) => {
1400
1580
  p(t);
1401
- let n = de(t);
1581
+ let n = ve(t);
1402
1582
  n && e.elements.namedItem(n)?.focus();
1403
- }, b = M(async (e) => {
1404
- let t = pe(u, o, c?.currency);
1405
- if (!t.ok) y(e, t.errors);
1583
+ }, v = L(async (e) => {
1584
+ let t = be(u, o, s?.currency);
1585
+ if (!t.ok) g(e, t.errors);
1406
1586
  else try {
1407
- if (!c) return await i.createProduct(t.input);
1408
- let e = he(c, t.input);
1409
- return Object.keys(e).length === 0 ? c : await i.updateProduct(c.id, e);
1587
+ if (!s) return await i.createProduct(t.input);
1588
+ let e = Se(s, t.input);
1589
+ return Object.keys(e).length === 0 ? s : await i.updateProduct(s.id, e);
1410
1590
  } catch (t) {
1411
- if (!(t instanceof s)) throw t;
1412
- y(e, ue(t.issues));
1591
+ if (!(t instanceof l)) throw t;
1592
+ g(e, _e(t.issues));
1413
1593
  return;
1414
1594
  }
1415
1595
  }), x = (e, t) => {
@@ -1421,10 +1601,10 @@ function Oe({ product: e, onSaved: t, imagesSlot: n, categories: r }) {
1421
1601
  [e]: void 0
1422
1602
  }));
1423
1603
  }, S = async (e) => {
1424
- e.preventDefault(), g(!1), p({}), b.reset();
1425
- let n = await b.run(e.currentTarget);
1426
- n && (l(n), d(q(n)), g(!0), t?.(n));
1427
- }, C = e ? n ?? /* @__PURE__ */ _(xe, {
1604
+ e.preventDefault(), h(!1), p({}), v.reset();
1605
+ let n = await v.run(e.currentTarget);
1606
+ n && (c(n), d(he(n)), h(!0), t?.(n));
1607
+ }, C = e ? n ?? /* @__PURE__ */ y(ke, {
1428
1608
  productId: e.id,
1429
1609
  images: e.images
1430
1610
  }) : null, w = {
@@ -1435,38 +1615,38 @@ function Oe({ product: e, onSaved: t, imagesSlot: n, categories: r }) {
1435
1615
  categories: r,
1436
1616
  onChange: x
1437
1617
  };
1438
- return /* @__PURE__ */ v("form", {
1618
+ return /* @__PURE__ */ b("form", {
1439
1619
  noValidate: !0,
1440
1620
  className: "sfa-form",
1441
1621
  onSubmit: S,
1442
1622
  children: [
1443
- /* @__PURE__ */ _("h1", { children: e ? o.editTitle : o.createTitle }),
1444
- /* @__PURE__ */ _(H, { error: b.error }),
1445
- /* @__PURE__ */ _(Ce, { ...w }),
1446
- /* @__PURE__ */ _(Te, { ...w }),
1447
- C ? /* @__PURE__ */ _("section", {
1623
+ /* @__PURE__ */ y("h1", { children: e ? o.editTitle : o.createTitle }),
1624
+ /* @__PURE__ */ y(U, { error: v.error }),
1625
+ /* @__PURE__ */ y(je, { ...w }),
1626
+ /* @__PURE__ */ y(Ne, { ...w }),
1627
+ C ? /* @__PURE__ */ y("section", {
1448
1628
  "data-slot": "images",
1449
1629
  className: "sfa-form__images",
1450
1630
  children: C
1451
1631
  }) : null,
1452
- /* @__PURE__ */ _("button", {
1632
+ /* @__PURE__ */ y("button", {
1453
1633
  type: "submit",
1454
1634
  className: "sfa-btn sfa-btn--primary",
1455
- disabled: b.pending,
1635
+ disabled: v.pending,
1456
1636
  children: a.save
1457
1637
  }),
1458
- m ? /* @__PURE__ */ _(z, {
1638
+ m ? /* @__PURE__ */ y(H, {
1459
1639
  variant: "success",
1460
1640
  toast: !0,
1461
- onDismiss: () => g(!1),
1641
+ onDismiss: () => h(!1),
1462
1642
  children: o.saved
1463
1643
  }) : null
1464
1644
  ]
1465
1645
  });
1466
1646
  }
1467
1647
  // src/lib/use-order-pages.ts
1468
- function ke(e) {
1469
- let t = A(), n = j(["admin-orders", e], () => t.listOrders(e)), [r, i] = h(null), a = M(async (n, r) => {
1648
+ function Le(e) {
1649
+ let t = F(), n = I(["admin-orders", e], () => t.listOrders(e)), [r, i] = _(null), a = L(async (n, r) => {
1470
1650
  let a = await t.listOrders({
1471
1651
  ...e,
1472
1652
  cursor: n
@@ -1489,19 +1669,19 @@ function ke(e) {
1489
1669
  };
1490
1670
  }
1491
1671
  // src/views/orders/admin-order-list.tsx
1492
- var Ae = [
1672
+ var Re = [
1493
1673
  "paid",
1494
1674
  "shipped",
1495
1675
  "needs_attention",
1496
1676
  "pending_refund",
1497
1677
  "all"
1498
1678
  ];
1499
- function je(e) {
1679
+ function ze(e) {
1500
1680
  return e === "pending_refund" ? { hasPendingRefund: !0 } : e === "all" ? {} : { status: e };
1501
1681
  }
1502
- function Me() {
1503
- let { labels: e, locale: t, hrefs: n, renderLink: r } = k(), i = e.orders, [a, o] = h("paid"), [s, c] = h(""), l = re(s.trim(), 300), u = ke({
1504
- ...je(a),
1682
+ function Be() {
1683
+ let { labels: e, locale: t, hrefs: n, renderLink: r } = P(), i = e.orders, [a, o] = _("paid"), [s, c] = _(""), l = W(s.trim(), 300), u = Le({
1684
+ ...ze(a),
1505
1685
  ...l ? { q: l } : {}
1506
1686
  }), d = new Intl.DateTimeFormat(t), f = [
1507
1687
  {
@@ -1516,7 +1696,7 @@ function Me() {
1516
1696
  {
1517
1697
  key: "status",
1518
1698
  header: i.columns.status,
1519
- render: (e) => /* @__PURE__ */ _(F, { status: e.status })
1699
+ render: (e) => /* @__PURE__ */ y(z, { status: e.status })
1520
1700
  },
1521
1701
  {
1522
1702
  key: "email",
@@ -1531,7 +1711,7 @@ function Me() {
1531
1711
  {
1532
1712
  key: "total",
1533
1713
  header: i.columns.total,
1534
- render: (e) => /* @__PURE__ */ _(I, {
1714
+ render: (e) => /* @__PURE__ */ y(B, {
1535
1715
  cents: e.totalCents,
1536
1716
  currency: e.currency
1537
1717
  })
@@ -1542,24 +1722,24 @@ function Me() {
1542
1722
  render: (e) => d.format(new Date(e.createdAt))
1543
1723
  }
1544
1724
  ];
1545
- return /* @__PURE__ */ v("section", {
1725
+ return /* @__PURE__ */ b("section", {
1546
1726
  className: "sfa-orders",
1547
1727
  children: [
1548
- /* @__PURE__ */ _("h1", { children: i.title }),
1549
- /* @__PURE__ */ v("div", {
1728
+ /* @__PURE__ */ y("h1", { children: i.title }),
1729
+ /* @__PURE__ */ b("div", {
1550
1730
  className: "sfa-orders__toolbar",
1551
- children: [/* @__PURE__ */ _("div", {
1731
+ children: [/* @__PURE__ */ y("div", {
1552
1732
  role: "group",
1553
1733
  "aria-label": i.columns.status,
1554
1734
  className: "sfa-filter-group",
1555
- children: Ae.map((e) => /* @__PURE__ */ _("button", {
1735
+ children: Re.map((e) => /* @__PURE__ */ y("button", {
1556
1736
  type: "button",
1557
1737
  className: "sfa-btn sfa-filter",
1558
1738
  "aria-pressed": a === e,
1559
1739
  onClick: () => o(e),
1560
1740
  children: i.tabs[e]
1561
1741
  }, e))
1562
- }), /* @__PURE__ */ _("input", {
1742
+ }), /* @__PURE__ */ y("input", {
1563
1743
  type: "search",
1564
1744
  "aria-label": i.searchLabel,
1565
1745
  placeholder: i.searchPlaceholder,
@@ -1567,16 +1747,16 @@ function Me() {
1567
1747
  onChange: (e) => c(e.target.value)
1568
1748
  })]
1569
1749
  }),
1570
- /* @__PURE__ */ _(H, { error: u.error }),
1571
- u.loading ? /* @__PURE__ */ _("p", { children: e.loading }) : u.items.length === 0 ? /* @__PURE__ */ _("p", {
1750
+ /* @__PURE__ */ y(U, { error: u.error }),
1751
+ u.loading ? /* @__PURE__ */ y("p", { children: e.loading }) : u.items.length === 0 ? /* @__PURE__ */ y("p", {
1572
1752
  className: "sfa-empty",
1573
1753
  children: l ? i.noMatches : i.empty[a]
1574
- }) : /* @__PURE__ */ _(P, {
1754
+ }) : /* @__PURE__ */ y(R, {
1575
1755
  columns: f,
1576
1756
  rows: u.items,
1577
1757
  rowKey: (e) => e.id
1578
1758
  }),
1579
- u.hasMore ? /* @__PURE__ */ _("button", {
1759
+ u.hasMore ? /* @__PURE__ */ y("button", {
1580
1760
  type: "button",
1581
1761
  className: "sfa-btn sfa-orders__more",
1582
1762
  disabled: u.loadingMore,
@@ -1587,75 +1767,75 @@ function Me() {
1587
1767
  });
1588
1768
  }
1589
1769
  // src/lib/refund-rules.ts
1590
- function Ne(e) {
1770
+ function Ve(e) {
1591
1771
  return e.refunds.filter((e) => e.status === "pending").reduce((e, t) => e + t.amountCents, 0);
1592
1772
  }
1593
- function Z(e) {
1594
- return e.totalCents - e.refundedCents - Ne(e);
1773
+ function X(e) {
1774
+ return e.totalCents - e.refundedCents - Ve(e);
1595
1775
  }
1596
- function Pe(e) {
1776
+ function He(e) {
1597
1777
  return e.refunds.some((e) => e.status === "pending");
1598
1778
  }
1599
- function Fe(e, t) {
1600
- return e.status !== "needs_attention" && t !== null && t === Z(e);
1779
+ function Ue(e, t) {
1780
+ return e.status !== "needs_attention" && t !== null && t === X(e);
1601
1781
  }
1602
- function Ie(e) {
1782
+ function We(e) {
1603
1783
  return e.status === "paid" || e.status === "shipped";
1604
1784
  }
1605
- function Le(e) {
1606
- return (Ie(e) || e.status === "needs_attention") && Z(e) > 0;
1785
+ function Ge(e) {
1786
+ return (We(e) || e.status === "needs_attention") && X(e) > 0;
1607
1787
  }
1608
1788
  // src/views/orders/refund-dialog.tsx
1609
- function Re({ order: e, onClose: t, onDone: i }) {
1610
- let a = A(), o = k().labels.orders.actions, s = m(crypto.randomUUID()), c = Z(e), [l, u] = h(G(c)), [d, f] = h(""), [p, g] = h(!1), [y, b] = h(!1), x = M(a.refundOrder), S = W(l), C = S !== null && S > 0 && S <= c, w = Fe(e, S), T = x.error instanceof n || x.error instanceof r;
1611
- return /* @__PURE__ */ v(R, {
1789
+ function Ke({ order: e, onClose: t, onDone: n }) {
1790
+ let r = F(), i = P().labels.orders.actions, a = g(crypto.randomUUID()), s = X(e), [l, u] = _(K(s)), [d, f] = _(""), [p, m] = _(!1), [h, v] = _(!1), x = L(r.refundOrder), S = G(l), C = S !== null && S > 0 && S <= s, w = Ue(e, S), T = x.error instanceof c || x.error instanceof o;
1791
+ return /* @__PURE__ */ b(V, {
1612
1792
  open: !0,
1613
- title: o.refundTitle,
1614
- confirmLabel: T ? o.refundRetry : o.refundSubmit,
1793
+ title: i.refundTitle,
1794
+ confirmLabel: T ? i.refundRetry : i.refundSubmit,
1615
1795
  destructive: !0,
1616
1796
  pending: x.pending,
1617
1797
  onConfirm: async () => {
1618
- C ? (b(!1), await x.run(e.id, {
1798
+ C ? (v(!1), await x.run(e.id, {
1619
1799
  amountCents: S,
1620
1800
  reason: d.trim() || void 0,
1621
1801
  restock: p && w
1622
- }, { idempotencyKey: s.current }) && i(o.refundDone)) : b(!0);
1802
+ }, { idempotencyKey: a.current }) && n(i.refundDone)) : v(!0);
1623
1803
  },
1624
1804
  onCancel: t,
1625
1805
  children: [
1626
- Pe(e) ? /* @__PURE__ */ _(z, {
1806
+ He(e) ? /* @__PURE__ */ y(H, {
1627
1807
  variant: "warning",
1628
- children: o.refundPending
1808
+ children: i.refundPending
1629
1809
  }) : null,
1630
- /* @__PURE__ */ v("div", {
1810
+ /* @__PURE__ */ b("div", {
1631
1811
  className: "sfa-field",
1632
1812
  children: [
1633
- /* @__PURE__ */ _("label", {
1813
+ /* @__PURE__ */ y("label", {
1634
1814
  htmlFor: "sfa-refund-amount",
1635
1815
  className: "sfa-field__label",
1636
- children: o.refundAmount
1816
+ children: i.refundAmount
1637
1817
  }),
1638
- /* @__PURE__ */ _("input", {
1818
+ /* @__PURE__ */ y("input", {
1639
1819
  id: "sfa-refund-amount",
1640
1820
  inputMode: "decimal",
1641
1821
  value: l,
1642
1822
  disabled: T,
1643
- "aria-invalid": y && !C,
1823
+ "aria-invalid": h && !C,
1644
1824
  onChange: (e) => u(e.target.value)
1645
1825
  }),
1646
- y && !C ? /* @__PURE__ */ _("p", {
1826
+ h && !C ? /* @__PURE__ */ y("p", {
1647
1827
  className: "sfa-field__error",
1648
- children: o.refundAmountInvalid
1828
+ children: i.refundAmountInvalid
1649
1829
  }) : null
1650
1830
  ]
1651
1831
  }),
1652
- /* @__PURE__ */ v("div", {
1832
+ /* @__PURE__ */ b("div", {
1653
1833
  className: "sfa-field",
1654
- children: [/* @__PURE__ */ _("label", {
1834
+ children: [/* @__PURE__ */ y("label", {
1655
1835
  htmlFor: "sfa-refund-reason",
1656
1836
  className: "sfa-field__label",
1657
- children: o.refundReason
1658
- }), /* @__PURE__ */ _("textarea", {
1837
+ children: i.refundReason
1838
+ }), /* @__PURE__ */ y("textarea", {
1659
1839
  id: "sfa-refund-reason",
1660
1840
  maxLength: 500,
1661
1841
  value: d,
@@ -1663,61 +1843,61 @@ function Re({ order: e, onClose: t, onDone: i }) {
1663
1843
  onChange: (e) => f(e.target.value)
1664
1844
  })]
1665
1845
  }),
1666
- w ? /* @__PURE__ */ v("div", {
1846
+ w ? /* @__PURE__ */ b("div", {
1667
1847
  className: "sfa-field",
1668
- children: [/* @__PURE__ */ v("label", { children: [
1669
- /* @__PURE__ */ _("input", {
1848
+ children: [/* @__PURE__ */ b("label", { children: [
1849
+ /* @__PURE__ */ y("input", {
1670
1850
  type: "checkbox",
1671
1851
  checked: p,
1672
1852
  disabled: T,
1673
- onChange: (e) => g(e.target.checked)
1853
+ onChange: (e) => m(e.target.checked)
1674
1854
  }),
1675
1855
  " ",
1676
- o.restock
1677
- ] }), /* @__PURE__ */ _("p", {
1856
+ i.restock
1857
+ ] }), /* @__PURE__ */ y("p", {
1678
1858
  className: "sfa-field__help",
1679
- children: o.restockWarning
1859
+ children: i.restockWarning
1680
1860
  })]
1681
1861
  }) : null,
1682
- x.error instanceof r ? /* @__PURE__ */ _(z, {
1862
+ x.error instanceof o ? /* @__PURE__ */ y(H, {
1683
1863
  variant: "warning",
1684
- children: o.refundUnknown
1685
- }) : x.error instanceof n ? /* @__PURE__ */ _(z, {
1864
+ children: i.refundUnknown
1865
+ }) : x.error instanceof c ? /* @__PURE__ */ y(H, {
1686
1866
  variant: "warning",
1687
- children: o.refundGateway
1688
- }) : /* @__PURE__ */ _(H, { error: x.error })
1867
+ children: i.refundGateway
1868
+ }) : /* @__PURE__ */ y(U, { error: x.error })
1689
1869
  ]
1690
1870
  });
1691
1871
  }
1692
1872
  // src/views/orders/resolve-button.tsx
1693
- function ze({ order: e, onDone: t }) {
1694
- let n = A(), { labels: r, hrefs: i, renderLink: a } = k(), o = r.orders.actions, s = M(n.resolveOrder), l = async () => {
1695
- await s.run(e.id) && t(o.resolved);
1696
- }, u = s.error instanceof c ? s.error : null, d = new Map(e.items.map((e) => [e.productId, e.name]));
1697
- return /* @__PURE__ */ v("div", {
1873
+ function qe({ order: e, onDone: t }) {
1874
+ let n = F(), { labels: r, hrefs: i, renderLink: o } = P(), s = r.orders.actions, c = L(n.resolveOrder), l = async () => {
1875
+ await c.run(e.id) && t(s.resolved);
1876
+ }, u = c.error instanceof a ? c.error : null, d = new Map(e.items.map((e) => [e.productId, e.name]));
1877
+ return /* @__PURE__ */ b("div", {
1698
1878
  className: "sfa-order__action",
1699
1879
  children: [
1700
- /* @__PURE__ */ _("p", { children: o.resolveHelp }),
1701
- u ? /* @__PURE__ */ v(z, {
1880
+ /* @__PURE__ */ y("p", { children: s.resolveHelp }),
1881
+ u ? /* @__PURE__ */ b(H, {
1702
1882
  variant: "error",
1703
- children: [r.errors.insufficientStock, /* @__PURE__ */ _("ul", { children: u.productIds.map((e) => /* @__PURE__ */ _("li", { children: a({
1883
+ children: [r.errors.insufficientStock, /* @__PURE__ */ y("ul", { children: u.productIds.map((e) => /* @__PURE__ */ y("li", { children: o({
1704
1884
  href: i.product(e),
1705
- children: `${o.restockThenResolve}: ${d.get(e) ?? e}`,
1885
+ children: `${s.restockThenResolve}: ${d.get(e) ?? e}`,
1706
1886
  className: "sfa-link--tap"
1707
1887
  }) }, e)) })]
1708
- }) : /* @__PURE__ */ _(H, { error: s.error }),
1709
- /* @__PURE__ */ _("button", {
1888
+ }) : /* @__PURE__ */ y(U, { error: c.error }),
1889
+ /* @__PURE__ */ y("button", {
1710
1890
  type: "button",
1711
1891
  className: "sfa-btn sfa-btn--primary",
1712
- disabled: s.pending,
1892
+ disabled: c.pending,
1713
1893
  onClick: l,
1714
- children: o.resolve
1894
+ children: s.resolve
1715
1895
  })
1716
1896
  ]
1717
1897
  });
1718
1898
  }
1719
1899
  // src/views/orders/ship-form.tsx
1720
- function Be(e) {
1900
+ function Je(e) {
1721
1901
  try {
1722
1902
  let { protocol: t } = new URL(e);
1723
1903
  return t === "http:" || t === "https:";
@@ -1725,69 +1905,69 @@ function Be(e) {
1725
1905
  return !1;
1726
1906
  }
1727
1907
  }
1728
- function Ve({ order: e, onDone: t }) {
1729
- let n = A(), r = k().labels.orders.actions, i = e.fulfillment, [a, o] = h(i?.carrier ?? ""), [s, c] = h(i?.trackingNumber ?? ""), [l, u] = h(i?.trackingUrl ?? ""), [d, f] = h(!1), p = M(n.shipOrder), m = e.status === "shipped";
1730
- return /* @__PURE__ */ v("form", {
1908
+ function Ye({ order: e, onDone: t }) {
1909
+ let n = F(), r = P().labels.orders.actions, i = e.fulfillment, [a, o] = _(i?.carrier ?? ""), [s, c] = _(i?.trackingNumber ?? ""), [l, u] = _(i?.trackingUrl ?? ""), [d, f] = _(!1), p = L(n.shipOrder), m = e.status === "shipped";
1910
+ return /* @__PURE__ */ b("form", {
1731
1911
  className: "sfa-order__action",
1732
1912
  onSubmit: async (n) => {
1733
1913
  n.preventDefault();
1734
1914
  let i = l.trim();
1735
- i && !Be(i) ? f(!0) : (f(!1), await p.run(e.id, {
1915
+ i && !Je(i) ? f(!0) : (f(!1), await p.run(e.id, {
1736
1916
  carrier: a.trim() || void 0,
1737
1917
  trackingNumber: s.trim() || void 0,
1738
1918
  trackingUrl: i || void 0
1739
1919
  }) && t(r.shipped));
1740
1920
  },
1741
1921
  children: [
1742
- /* @__PURE__ */ _("h3", { children: r.shipHeading }),
1743
- /* @__PURE__ */ v("div", {
1922
+ /* @__PURE__ */ y("h3", { children: r.shipHeading }),
1923
+ /* @__PURE__ */ b("div", {
1744
1924
  className: "sfa-field",
1745
- children: [/* @__PURE__ */ _("label", {
1925
+ children: [/* @__PURE__ */ y("label", {
1746
1926
  htmlFor: "sfa-ship-carrier",
1747
1927
  className: "sfa-field__label",
1748
1928
  children: r.carrier
1749
- }), /* @__PURE__ */ _("input", {
1929
+ }), /* @__PURE__ */ y("input", {
1750
1930
  id: "sfa-ship-carrier",
1751
1931
  value: a,
1752
1932
  onChange: (e) => o(e.target.value)
1753
1933
  })]
1754
1934
  }),
1755
- /* @__PURE__ */ v("div", {
1935
+ /* @__PURE__ */ b("div", {
1756
1936
  className: "sfa-field",
1757
- children: [/* @__PURE__ */ _("label", {
1937
+ children: [/* @__PURE__ */ y("label", {
1758
1938
  htmlFor: "sfa-ship-number",
1759
1939
  className: "sfa-field__label",
1760
1940
  children: r.trackingNumber
1761
- }), /* @__PURE__ */ _("input", {
1941
+ }), /* @__PURE__ */ y("input", {
1762
1942
  id: "sfa-ship-number",
1763
1943
  value: s,
1764
1944
  onChange: (e) => c(e.target.value)
1765
1945
  })]
1766
1946
  }),
1767
- /* @__PURE__ */ v("div", {
1947
+ /* @__PURE__ */ b("div", {
1768
1948
  className: "sfa-field",
1769
1949
  children: [
1770
- /* @__PURE__ */ _("label", {
1950
+ /* @__PURE__ */ y("label", {
1771
1951
  htmlFor: "sfa-ship-url",
1772
1952
  className: "sfa-field__label",
1773
1953
  children: r.trackingUrl
1774
1954
  }),
1775
- /* @__PURE__ */ _("input", {
1955
+ /* @__PURE__ */ y("input", {
1776
1956
  id: "sfa-ship-url",
1777
1957
  value: l,
1778
1958
  "aria-invalid": d,
1779
1959
  "aria-describedby": d ? "sfa-ship-url-error" : void 0,
1780
1960
  onChange: (e) => u(e.target.value)
1781
1961
  }),
1782
- d ? /* @__PURE__ */ _("p", {
1962
+ d ? /* @__PURE__ */ y("p", {
1783
1963
  id: "sfa-ship-url-error",
1784
1964
  className: "sfa-field__error",
1785
1965
  children: r.trackingUrlInvalid
1786
1966
  }) : null
1787
1967
  ]
1788
1968
  }),
1789
- /* @__PURE__ */ _(H, { error: p.error }),
1790
- /* @__PURE__ */ _("button", {
1969
+ /* @__PURE__ */ y(U, { error: p.error }),
1970
+ /* @__PURE__ */ y("button", {
1791
1971
  type: "submit",
1792
1972
  className: "sfa-btn sfa-btn--primary",
1793
1973
  disabled: p.pending,
@@ -1797,33 +1977,33 @@ function Ve({ order: e, onDone: t }) {
1797
1977
  });
1798
1978
  }
1799
1979
  // src/views/orders/order-actions.tsx
1800
- function He({ order: e, reload: t }) {
1801
- let n = k().labels.orders.actions, [r, i] = h(!1), [a, o] = h(null), s = (e) => {
1980
+ function Xe({ order: e, reload: t }) {
1981
+ let n = P().labels.orders.actions, [r, i] = _(!1), [a, o] = _(null), s = (e) => {
1802
1982
  i(!1), o(e), t();
1803
1983
  };
1804
- return /* @__PURE__ */ v("div", {
1984
+ return /* @__PURE__ */ b("div", {
1805
1985
  className: "sfa-order__actions",
1806
1986
  children: [
1807
- a ? /* @__PURE__ */ _(z, {
1987
+ a ? /* @__PURE__ */ y(H, {
1808
1988
  variant: "success",
1809
1989
  onDismiss: () => o(null),
1810
1990
  children: a
1811
1991
  }) : null,
1812
- Ie(e) ? /* @__PURE__ */ _(Ve, {
1992
+ We(e) ? /* @__PURE__ */ y(Ye, {
1813
1993
  order: e,
1814
1994
  onDone: s
1815
1995
  }) : null,
1816
- e.status === "needs_attention" ? /* @__PURE__ */ _(ze, {
1996
+ e.status === "needs_attention" ? /* @__PURE__ */ y(qe, {
1817
1997
  order: e,
1818
1998
  onDone: s
1819
1999
  }) : null,
1820
- Le(e) ? /* @__PURE__ */ _("button", {
2000
+ Ge(e) ? /* @__PURE__ */ y("button", {
1821
2001
  type: "button",
1822
2002
  className: "sfa-btn sfa-btn--danger",
1823
2003
  onClick: () => i(!0),
1824
2004
  children: n.refund
1825
2005
  }) : null,
1826
- r ? /* @__PURE__ */ _(Re, {
2006
+ r ? /* @__PURE__ */ y(Ke, {
1827
2007
  order: e,
1828
2008
  onClose: () => {
1829
2009
  i(!1), t();
@@ -1834,26 +2014,26 @@ function He({ order: e, reload: t }) {
1834
2014
  });
1835
2015
  }
1836
2016
  // src/views/orders/order-fulfillment.tsx
1837
- function Ue({ order: e }) {
1838
- let { labels: t, locale: n, renderLink: r } = k(), i = t.orders, a = e.fulfillment;
1839
- return /* @__PURE__ */ v("section", {
2017
+ function Ze({ order: e }) {
2018
+ let { labels: t, locale: n, renderLink: r } = P(), i = t.orders, a = e.fulfillment;
2019
+ return /* @__PURE__ */ b("section", {
1840
2020
  className: "sfa-order__section",
1841
- children: [/* @__PURE__ */ _("h2", { children: i.fulfillment }), a ? /* @__PURE__ */ v("dl", { children: [
1842
- /* @__PURE__ */ _("dt", { children: i.shippedOn }),
1843
- /* @__PURE__ */ _("dd", { children: new Intl.DateTimeFormat(n).format(new Date(a.shippedAt)) }),
1844
- a.carrier ? /* @__PURE__ */ v(g, { children: [/* @__PURE__ */ _("dt", { children: i.carrier }), /* @__PURE__ */ _("dd", { children: a.carrier })] }) : null,
1845
- a.trackingNumber ? /* @__PURE__ */ v(g, { children: [/* @__PURE__ */ _("dt", { children: i.tracking }), /* @__PURE__ */ _("dd", { children: a.trackingNumber })] }) : null,
1846
- a.trackingUrl ? /* @__PURE__ */ _("dd", { children: r({
2021
+ children: [/* @__PURE__ */ y("h2", { children: i.fulfillment }), a ? /* @__PURE__ */ b("dl", { children: [
2022
+ /* @__PURE__ */ y("dt", { children: i.shippedOn }),
2023
+ /* @__PURE__ */ y("dd", { children: new Intl.DateTimeFormat(n).format(new Date(a.shippedAt)) }),
2024
+ a.carrier ? /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y("dt", { children: i.carrier }), /* @__PURE__ */ y("dd", { children: a.carrier })] }) : null,
2025
+ a.trackingNumber ? /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y("dt", { children: i.tracking }), /* @__PURE__ */ y("dd", { children: a.trackingNumber })] }) : null,
2026
+ a.trackingUrl ? /* @__PURE__ */ y("dd", { children: r({
1847
2027
  href: a.trackingUrl,
1848
2028
  children: i.trackShipment,
1849
2029
  className: "sfa-link--tap"
1850
2030
  }) }) : null
1851
- ] }) : /* @__PURE__ */ _("p", { children: i.notShipped })]
2031
+ ] }) : /* @__PURE__ */ y("p", { children: i.notShipped })]
1852
2032
  });
1853
2033
  }
1854
2034
  // src/views/orders/order-items.tsx
1855
- function We({ order: e }) {
1856
- let { labels: t } = k(), n = t.orders, { currency: r } = e, i = [
2035
+ function Qe({ order: e }) {
2036
+ let { labels: t } = P(), n = t.orders, { currency: r } = e, i = [
1857
2037
  {
1858
2038
  key: "name",
1859
2039
  header: n.itemColumns.name,
@@ -1862,7 +2042,7 @@ function We({ order: e }) {
1862
2042
  {
1863
2043
  key: "price",
1864
2044
  header: n.itemColumns.price,
1865
- render: (e) => /* @__PURE__ */ _(I, {
2045
+ render: (e) => /* @__PURE__ */ y(B, {
1866
2046
  cents: e.priceCents,
1867
2047
  currency: r
1868
2048
  })
@@ -1875,36 +2055,40 @@ function We({ order: e }) {
1875
2055
  {
1876
2056
  key: "line",
1877
2057
  header: n.itemColumns.line,
1878
- render: (e) => /* @__PURE__ */ _(I, {
2058
+ render: (e) => /* @__PURE__ */ y(B, {
1879
2059
  cents: e.priceCents * e.quantity,
1880
2060
  currency: r
1881
2061
  })
1882
2062
  }
1883
2063
  ];
1884
- return /* @__PURE__ */ v("section", {
2064
+ return /* @__PURE__ */ b("section", {
1885
2065
  className: "sfa-order__section",
1886
2066
  children: [
1887
- /* @__PURE__ */ _("h2", { children: n.itemsHeading }),
1888
- /* @__PURE__ */ _(P, {
2067
+ /* @__PURE__ */ y("h2", { children: n.itemsHeading }),
2068
+ /* @__PURE__ */ y(R, {
1889
2069
  columns: i,
1890
2070
  rows: e.items,
1891
2071
  rowKey: (e) => e.productId
1892
2072
  }),
1893
- /* @__PURE__ */ v("dl", {
2073
+ /* @__PURE__ */ b("dl", {
1894
2074
  className: "sfa-order__totals",
1895
2075
  children: [
1896
- /* @__PURE__ */ _("dt", { children: n.subtotal }),
1897
- /* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
2076
+ /* @__PURE__ */ y("dt", { children: n.subtotal }),
2077
+ /* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
1898
2078
  cents: e.subtotalCents,
1899
2079
  currency: r
1900
2080
  }) }),
1901
- /* @__PURE__ */ _("dt", { children: e.shippingLabel ?? n.shipping }),
1902
- /* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
2081
+ e.discountCents > 0 ? /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ b("dt", { children: [t.discounts.orderRow, e.discountCode ? ` (${e.discountCode})` : ""] }), /* @__PURE__ */ b("dd", { children: ["−", /* @__PURE__ */ y(B, {
2082
+ cents: e.discountCents,
2083
+ currency: r
2084
+ })] })] }) : null,
2085
+ /* @__PURE__ */ y("dt", { children: e.shippingLabel ?? n.shipping }),
2086
+ /* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
1903
2087
  cents: e.shippingCents,
1904
2088
  currency: r
1905
2089
  }) }),
1906
- /* @__PURE__ */ _("dt", { children: n.total }),
1907
- /* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
2090
+ /* @__PURE__ */ y("dt", { children: n.total }),
2091
+ /* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
1908
2092
  cents: e.totalCents,
1909
2093
  currency: r
1910
2094
  }) })
@@ -1914,12 +2098,12 @@ function We({ order: e }) {
1914
2098
  });
1915
2099
  }
1916
2100
  // src/views/orders/order-refunds.tsx
1917
- function Ge({ order: e }) {
1918
- let { labels: t, locale: n } = k(), r = t.orders, { currency: i } = e, a = new Intl.DateTimeFormat(n), o = [
2101
+ function $e({ order: e }) {
2102
+ let { labels: t, locale: n } = P(), r = t.orders, { currency: i } = e, a = new Intl.DateTimeFormat(n), o = [
1919
2103
  {
1920
2104
  key: "amount",
1921
2105
  header: r.refundColumns.amount,
1922
- render: (e) => /* @__PURE__ */ _(I, {
2106
+ render: (e) => /* @__PURE__ */ y(B, {
1923
2107
  cents: e.amountCents,
1924
2108
  currency: i
1925
2109
  })
@@ -1937,7 +2121,7 @@ function Ge({ order: e }) {
1937
2121
  {
1938
2122
  key: "status",
1939
2123
  header: r.refundColumns.status,
1940
- render: (e) => /* @__PURE__ */ _("span", {
2124
+ render: (e) => /* @__PURE__ */ y("span", {
1941
2125
  className: `sfa-badge sfa-badge--refund-${e.status}`,
1942
2126
  "data-refund-status": e.status,
1943
2127
  children: r.refundStatuses[e.status]
@@ -1954,22 +2138,22 @@ function Ge({ order: e }) {
1954
2138
  render: (e) => a.format(new Date(e.createdAt))
1955
2139
  }
1956
2140
  ], s = e.totalCents - e.refundedCents;
1957
- return /* @__PURE__ */ v("section", {
2141
+ return /* @__PURE__ */ b("section", {
1958
2142
  className: "sfa-order__section",
1959
- children: [/* @__PURE__ */ _("h2", { children: r.refunds }), e.refunds.length === 0 ? /* @__PURE__ */ _("p", { children: r.noRefunds }) : /* @__PURE__ */ v(g, { children: [/* @__PURE__ */ _(P, {
2143
+ children: [/* @__PURE__ */ y("h2", { children: r.refunds }), e.refunds.length === 0 ? /* @__PURE__ */ y("p", { children: r.noRefunds }) : /* @__PURE__ */ b(v, { children: [/* @__PURE__ */ y(R, {
1960
2144
  columns: o,
1961
2145
  rows: e.refunds,
1962
2146
  rowKey: (e) => e.id
1963
- }), /* @__PURE__ */ v("dl", {
2147
+ }), /* @__PURE__ */ b("dl", {
1964
2148
  className: "sfa-order__totals",
1965
2149
  children: [
1966
- /* @__PURE__ */ _("dt", { children: r.refunded }),
1967
- /* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
2150
+ /* @__PURE__ */ y("dt", { children: r.refunded }),
2151
+ /* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
1968
2152
  cents: e.refundedCents,
1969
2153
  currency: i
1970
2154
  }) }),
1971
- /* @__PURE__ */ _("dt", { children: r.remaining }),
1972
- /* @__PURE__ */ _("dd", { children: /* @__PURE__ */ _(I, {
2155
+ /* @__PURE__ */ y("dt", { children: r.remaining }),
2156
+ /* @__PURE__ */ y("dd", { children: /* @__PURE__ */ y(B, {
1973
2157
  cents: s,
1974
2158
  currency: i
1975
2159
  }) })
@@ -1978,7 +2162,7 @@ function Ge({ order: e }) {
1978
2162
  });
1979
2163
  }
1980
2164
  // src/views/orders/admin-order-detail.tsx
1981
- function Ke(e) {
2165
+ function et(e) {
1982
2166
  let t = e.shippingAddress;
1983
2167
  if (!t) return [];
1984
2168
  let n = [
@@ -1994,13 +2178,13 @@ function Ke(e) {
1994
2178
  t.country
1995
2179
  ].filter((e) => !!e);
1996
2180
  }
1997
- function qe({ orderId: e, actions: t }) {
1998
- let n = A(), { labels: r, locale: i, hrefs: a, renderLink: o } = k(), s = r.orders, c = j(["admin-order", e], () => n.getOrder(e));
1999
- if (c.error) return /* @__PURE__ */ _(H, { error: c.error });
2181
+ function tt({ orderId: e, actions: t }) {
2182
+ let n = F(), { labels: r, locale: i, hrefs: a, renderLink: o } = P(), s = r.orders, c = I(["admin-order", e], () => n.getOrder(e));
2183
+ if (c.error) return /* @__PURE__ */ y(U, { error: c.error });
2000
2184
  let l = c.data;
2001
- if (!l) return /* @__PURE__ */ _("p", { children: r.loading });
2002
- let u = Ke(l);
2003
- return /* @__PURE__ */ v("article", {
2185
+ if (!l) return /* @__PURE__ */ y("p", { children: r.loading });
2186
+ let u = et(l);
2187
+ return /* @__PURE__ */ b("article", {
2004
2188
  className: "sfa-order",
2005
2189
  children: [
2006
2190
  o({
@@ -2008,46 +2192,46 @@ function qe({ orderId: e, actions: t }) {
2008
2192
  children: s.back,
2009
2193
  className: "sfa-link--tap"
2010
2194
  }),
2011
- /* @__PURE__ */ v("header", {
2195
+ /* @__PURE__ */ b("header", {
2012
2196
  className: "sfa-order__header",
2013
2197
  children: [
2014
- /* @__PURE__ */ v("h1", { children: [
2198
+ /* @__PURE__ */ b("h1", { children: [
2015
2199
  s.detailTitle,
2016
2200
  " ",
2017
2201
  l.id
2018
2202
  ] }),
2019
- /* @__PURE__ */ _(F, { status: l.status }),
2020
- /* @__PURE__ */ v("span", { children: [
2203
+ /* @__PURE__ */ y(z, { status: l.status }),
2204
+ /* @__PURE__ */ b("span", { children: [
2021
2205
  s.placed,
2022
2206
  " ",
2023
2207
  new Intl.DateTimeFormat(i).format(new Date(l.createdAt))
2024
2208
  ] }),
2025
- /* @__PURE__ */ _(I, {
2209
+ /* @__PURE__ */ y(B, {
2026
2210
  cents: l.totalCents,
2027
2211
  currency: l.currency
2028
2212
  })
2029
2213
  ]
2030
2214
  }),
2031
- /* @__PURE__ */ v("section", {
2215
+ /* @__PURE__ */ b("section", {
2032
2216
  className: "sfa-order__section",
2033
- children: [/* @__PURE__ */ _("h2", { children: s.buyer }), /* @__PURE__ */ _("p", { children: l.email ?? r.orders.noEmail })]
2217
+ children: [/* @__PURE__ */ y("h2", { children: s.buyer }), /* @__PURE__ */ y("p", { children: l.email ?? r.orders.noEmail })]
2034
2218
  }),
2035
- /* @__PURE__ */ _(We, { order: l }),
2036
- /* @__PURE__ */ v("section", {
2219
+ /* @__PURE__ */ y(Qe, { order: l }),
2220
+ /* @__PURE__ */ b("section", {
2037
2221
  className: "sfa-order__section",
2038
- children: [/* @__PURE__ */ _("h2", { children: s.shippingAddress }), u.length === 0 ? /* @__PURE__ */ _("p", { children: s.noAddress }) : /* @__PURE__ */ _("address", {
2222
+ children: [/* @__PURE__ */ y("h2", { children: s.shippingAddress }), u.length === 0 ? /* @__PURE__ */ y("p", { children: s.noAddress }) : /* @__PURE__ */ y("address", {
2039
2223
  className: "sfa-order__address",
2040
- children: u.map((e) => /* @__PURE__ */ _("div", { children: e }, e))
2224
+ children: u.map((e) => /* @__PURE__ */ y("div", { children: e }, e))
2041
2225
  })]
2042
2226
  }),
2043
- /* @__PURE__ */ _(Ue, { order: l }),
2044
- /* @__PURE__ */ _(Ge, { order: l }),
2045
- /* @__PURE__ */ _("section", {
2227
+ /* @__PURE__ */ y(Ze, { order: l }),
2228
+ /* @__PURE__ */ y($e, { order: l }),
2229
+ /* @__PURE__ */ y("section", {
2046
2230
  className: "sfa-order__section",
2047
2231
  children: t ? t({
2048
2232
  order: l,
2049
2233
  reload: c.reload
2050
- }) : /* @__PURE__ */ _(He, {
2234
+ }) : /* @__PURE__ */ y(Xe, {
2051
2235
  order: l,
2052
2236
  reload: c.reload
2053
2237
  })
@@ -2056,21 +2240,21 @@ function qe({ orderId: e, actions: t }) {
2056
2240
  });
2057
2241
  }
2058
2242
  // src/lib/shipping-rates.ts
2059
- var Je = 0, Ye = () => `rate-${++Je}`;
2060
- function Xe(e) {
2243
+ var nt = 0, rt = () => `rate-${++nt}`;
2244
+ function it(e) {
2061
2245
  return [...e].sort((e, t) => e.sort - t.sort).map((e) => ({
2062
- key: Ye(),
2246
+ key: rt(),
2063
2247
  label: e.label,
2064
- amount: G(e.amountCents),
2248
+ amount: K(e.amountCents),
2065
2249
  currency: e.currency,
2066
2250
  minDays: e.minDays == null ? "" : String(e.minDays),
2067
2251
  maxDays: e.maxDays == null ? "" : String(e.maxDays),
2068
2252
  active: e.active
2069
2253
  }));
2070
2254
  }
2071
- function Ze(e, t) {
2255
+ function at(e, t) {
2072
2256
  return {
2073
- key: Ye(),
2257
+ key: rt(),
2074
2258
  label: t,
2075
2259
  amount: "",
2076
2260
  currency: e,
@@ -2079,18 +2263,18 @@ function Ze(e, t) {
2079
2263
  active: !0
2080
2264
  };
2081
2265
  }
2082
- var Q = (e) => JSON.stringify(e.map(({ key: e, ...t }) => t));
2083
- function $(e) {
2266
+ var Z = (e) => JSON.stringify(e.map(({ key: e, ...t }) => t));
2267
+ function ot(e) {
2084
2268
  let t = e.trim();
2085
2269
  return t === "" ? null : /^\d+$/.test(t) ? Number(t) : void 0;
2086
2270
  }
2087
- function Qe(e, t) {
2271
+ function st(e, t) {
2088
2272
  let n = {}, r = [], i = /* @__PURE__ */ new Map();
2089
2273
  if (e.forEach((e) => {
2090
2274
  let t = e.label.trim();
2091
2275
  i.set(t, (i.get(t) ?? 0) + 1);
2092
2276
  }), e.forEach((e, a) => {
2093
- let o = {}, s = e.label.trim(), c = W(e.amount), l = $(e.minDays), u = $(e.maxDays);
2277
+ let o = {}, s = e.label.trim(), c = G(e.amount), l = ot(e.minDays), u = ot(e.maxDays);
2094
2278
  s === "" ? o.label = t.labelRequired : (i.get(s) ?? 0) > 1 && (o.label = t.labelDuplicate), /^[A-Z]{3}$/.test(e.currency) || (o.currency = t.currencyInvalid), c === null && (o.amount = t.amountInvalid), l === void 0 && (o.minDays = t.daysInvalid), u === void 0 && (o.maxDays = t.daysInvalid), typeof l == "number" && typeof u == "number" && l > u && (o.minDays = t.daysOrder), Object.keys(o).length > 0 && (n[e.key] = o), r.push({
2095
2279
  label: s,
2096
2280
  amountCents: c ?? 0,
@@ -2101,7 +2285,7 @@ function Qe(e, t) {
2101
2285
  sort: a
2102
2286
  });
2103
2287
  }), Object.keys(n).length === 0) {
2104
- let i = b.safeParse(r);
2288
+ let i = S.safeParse(r);
2105
2289
  if (!i.success) for (let r of i.error.issues) {
2106
2290
  let i = typeof r.path[0] == "number" ? e[r.path[0]]?.key : void 0;
2107
2291
  i && (n[i] = { row: t.rowInvalid });
@@ -2115,19 +2299,19 @@ function Qe(e, t) {
2115
2299
  valid: Object.keys(n).length === 0 && !a
2116
2300
  };
2117
2301
  }
2118
- var $e = {
2302
+ var ct = {
2119
2303
  label: "label",
2120
2304
  amountCents: "amount",
2121
2305
  currency: "currency",
2122
2306
  minDays: "minDays",
2123
2307
  maxDays: "maxDays"
2124
2308
  };
2125
- function et(e, t, n) {
2309
+ function lt(e, t, n) {
2126
2310
  let r = {};
2127
2311
  for (let i of e) {
2128
2312
  let e = i?.path ?? [], a = e.findIndex((e) => typeof e == "number"), o = a >= 0 ? t[e[a]]?.key : void 0;
2129
2313
  if (!o) continue;
2130
- let s = e[e.length - 1], c = e.length - 1 > a && typeof s == "string" ? $e[s] : void 0;
2314
+ let s = e[e.length - 1], c = e.length - 1 > a && typeof s == "string" ? ct[s] : void 0;
2131
2315
  r[o] = {
2132
2316
  ...r[o],
2133
2317
  [c ?? "row"]: n.rowInvalid
@@ -2136,18 +2320,18 @@ function et(e, t, n) {
2136
2320
  return r;
2137
2321
  }
2138
2322
  // src/views/shipping/shipping-rate-row.tsx
2139
- function tt({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, onChange: o, onMove: s, onRemove: c }) {
2140
- let l = e.label.trim() || J(a.rowName, { n: String(t + 1) }), u = (t, n, a, s, c) => {
2323
+ function ut({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, onChange: o, onMove: s, onRemove: c }) {
2324
+ let l = e.label.trim() || q(a.rowName, { n: String(t + 1) }), u = (t, n, a, s, c) => {
2141
2325
  let l = r[s], u = `${e.key}-${t}`;
2142
- return /* @__PURE__ */ v("div", {
2326
+ return /* @__PURE__ */ b("div", {
2143
2327
  className: "sfa-field",
2144
2328
  children: [
2145
- /* @__PURE__ */ _("label", {
2329
+ /* @__PURE__ */ y("label", {
2146
2330
  className: "sfa-field__label",
2147
2331
  htmlFor: u,
2148
2332
  children: n
2149
2333
  }),
2150
- /* @__PURE__ */ _("input", {
2334
+ /* @__PURE__ */ y("input", {
2151
2335
  id: u,
2152
2336
  value: a,
2153
2337
  inputMode: c,
@@ -2156,7 +2340,7 @@ function tt({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, o
2156
2340
  "aria-describedby": l ? `${u}-error` : void 0,
2157
2341
  onChange: (e) => o({ [s]: e.target.value })
2158
2342
  }),
2159
- l ? /* @__PURE__ */ _("p", {
2343
+ l ? /* @__PURE__ */ y("p", {
2160
2344
  id: `${u}-error`,
2161
2345
  className: "sfa-field__error",
2162
2346
  children: l
@@ -2164,25 +2348,25 @@ function tt({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, o
2164
2348
  ]
2165
2349
  });
2166
2350
  };
2167
- return /* @__PURE__ */ v("li", {
2351
+ return /* @__PURE__ */ b("li", {
2168
2352
  className: "sfa-rate",
2169
2353
  "data-rate-key": e.key,
2170
2354
  children: [
2171
2355
  u("label", a.label, e.label, "label"),
2172
2356
  u("amount", a.amount, e.amount, "amount", "decimal"),
2173
- /* @__PURE__ */ v("div", {
2357
+ /* @__PURE__ */ b("div", {
2174
2358
  className: "sfa-field",
2175
2359
  children: [
2176
- /* @__PURE__ */ _("span", {
2360
+ /* @__PURE__ */ y("span", {
2177
2361
  className: "sfa-field__label",
2178
2362
  children: a.currency
2179
2363
  }),
2180
- /* @__PURE__ */ _("span", {
2364
+ /* @__PURE__ */ y("span", {
2181
2365
  className: "sfa-rate__currency",
2182
2366
  "aria-invalid": !!r.currency,
2183
2367
  children: e.currency
2184
2368
  }),
2185
- r.currency ? /* @__PURE__ */ _("p", {
2369
+ r.currency ? /* @__PURE__ */ y("p", {
2186
2370
  className: "sfa-field__error",
2187
2371
  children: r.currency
2188
2372
  }) : null
@@ -2190,23 +2374,23 @@ function tt({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, o
2190
2374
  }),
2191
2375
  u("min", a.minDays, e.minDays, "minDays", "numeric"),
2192
2376
  u("max", a.maxDays, e.maxDays, "maxDays", "numeric"),
2193
- /* @__PURE__ */ v("label", {
2377
+ /* @__PURE__ */ b("label", {
2194
2378
  className: "sfa-rate__active",
2195
- children: [/* @__PURE__ */ _("input", {
2379
+ children: [/* @__PURE__ */ y("input", {
2196
2380
  type: "checkbox",
2197
2381
  checked: e.active,
2198
2382
  disabled: i,
2199
2383
  onChange: (e) => o({ active: e.target.checked })
2200
2384
  }), a.active]
2201
2385
  }),
2202
- r.row ? /* @__PURE__ */ _("p", {
2386
+ r.row ? /* @__PURE__ */ y("p", {
2203
2387
  className: "sfa-field__error",
2204
2388
  children: r.row
2205
2389
  }) : null,
2206
- /* @__PURE__ */ v("div", {
2390
+ /* @__PURE__ */ b("div", {
2207
2391
  className: "sfa-rate__actions",
2208
2392
  children: [
2209
- /* @__PURE__ */ _("button", {
2393
+ /* @__PURE__ */ y("button", {
2210
2394
  type: "button",
2211
2395
  className: "sfa-btn",
2212
2396
  "aria-label": `${a.moveEarlier}: ${l}`,
@@ -2214,7 +2398,7 @@ function tt({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, o
2214
2398
  onClick: () => s("earlier"),
2215
2399
  children: a.moveEarlier
2216
2400
  }),
2217
- /* @__PURE__ */ _("button", {
2401
+ /* @__PURE__ */ y("button", {
2218
2402
  type: "button",
2219
2403
  className: "sfa-btn",
2220
2404
  "aria-label": `${a.moveLater}: ${l}`,
@@ -2222,7 +2406,7 @@ function tt({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, o
2222
2406
  onClick: () => s("later"),
2223
2407
  children: a.moveLater
2224
2408
  }),
2225
- /* @__PURE__ */ _("button", {
2409
+ /* @__PURE__ */ y("button", {
2226
2410
  type: "button",
2227
2411
  className: "sfa-btn sfa-btn--danger",
2228
2412
  "aria-label": `${a.remove}: ${l}`,
@@ -2236,111 +2420,558 @@ function tt({ draft: e, index: t, total: n, errors: r, disabled: i, labels: a, o
2236
2420
  });
2237
2421
  }
2238
2422
  // src/views/shipping/admin-shipping-rates.tsx
2239
- function nt({ onDirtyChange: e }) {
2240
- let t = A(), { labels: n, currency: r } = k(), i = n.shipping, a = j(["shipping-rates"], () => t.listShippingRates()), [o, c] = h([]), [l, u] = h("[]"), [d, f] = h(void 0), [g, y] = h(null), [b, x] = h({}), [S, C] = h(!1), [w, T] = h(!1), [E, D] = h(!1), O = M((e) => t.replaceShippingRates(e)), N = m(void 0);
2423
+ function dt({ onDirtyChange: e }) {
2424
+ let t = F(), { labels: n, currency: r } = P(), i = n.shipping, a = I(["shipping-rates"], () => t.listShippingRates()), [o, s] = _([]), [c, u] = _("[]"), [d, f] = _(void 0), [p, m] = _(null), [v, x] = _({}), [S, C] = _(!1), [w, T] = _(!1), [E, D] = _(!1), O = L((e) => t.replaceShippingRates(e)), k = g(void 0);
2241
2425
  if (a.data && a.data !== d) {
2242
- let e = Xe(a.data);
2243
- f(a.data), c(e), u(Q(e));
2426
+ let e = it(a.data);
2427
+ f(a.data), s(e), u(Z(e));
2244
2428
  }
2245
- let P = d !== void 0 && Q(o) !== l;
2246
- p(() => {
2247
- N.current !== P && (N.current = P, e?.(P));
2248
- }, [P, e]);
2249
- let F = (e) => {
2250
- c(e), T(!1), C(!1);
2251
- }, I = (e, t) => {
2252
- F(o.map((n) => n.key === e ? {
2429
+ let A = d !== void 0 && Z(o) !== c;
2430
+ h(() => {
2431
+ k.current !== A && (k.current = A, e?.(A));
2432
+ }, [A, e]);
2433
+ let j = (e) => {
2434
+ s(e), T(!1), C(!1);
2435
+ }, M = (e, t) => {
2436
+ j(o.map((n) => n.key === e ? {
2253
2437
  ...n,
2254
2438
  ...t
2255
2439
  } : n)), x(({ [e]: t, ...n }) => n);
2256
- }, L = (e, t) => {
2440
+ }, N = (e, t) => {
2257
2441
  let n = t === "earlier" ? e - 1 : e + 1;
2258
2442
  if (n < 0 || n >= o.length) return;
2259
2443
  let r = [...o];
2260
- [r[e], r[n]] = [r[n], r[e]], F(r);
2261
- }, B = () => F([...o, Ze(r, i.newRateLabel)]), V = () => {
2262
- g && (F(o.filter((e) => e.key !== g.key)), D(!0), y(null));
2263
- }, U = async () => {
2264
- let e = Qe(o, i);
2444
+ [r[e], r[n]] = [r[n], r[e]], j(r);
2445
+ }, ee = () => j([...o, at(r, i.newRateLabel)]), te = () => {
2446
+ p && (j(o.filter((e) => e.key !== p.key)), D(!0), m(null));
2447
+ }, R = async () => {
2448
+ let e = st(o, i);
2265
2449
  if (x(e.rowErrors), C(e.noActive), !e.valid) return;
2266
2450
  let t = await O.run(e.rates);
2267
2451
  if (!t) return;
2268
- let n = Xe(t);
2269
- c(n), u(Q(n)), x({}), D(!1), T(!0);
2270
- }, ee = o.some((e) => e.currency !== r), te = O.error instanceof s ? et(O.error.issues, o, i) : {};
2271
- return a.loading && !a.data ? /* @__PURE__ */ _("p", {
2452
+ let n = it(t);
2453
+ s(n), u(Z(n)), x({}), D(!1), T(!0);
2454
+ }, z = o.some((e) => e.currency !== r), B = O.error instanceof l ? lt(O.error.issues, o, i) : {};
2455
+ return a.loading && !a.data ? /* @__PURE__ */ y("p", {
2272
2456
  role: "status",
2273
2457
  children: i.loading
2274
- }) : a.data ? /* @__PURE__ */ v("div", {
2458
+ }) : a.data ? /* @__PURE__ */ b("div", {
2275
2459
  className: "sfa-shipping",
2276
2460
  children: [
2277
- /* @__PURE__ */ _("h2", { children: i.title }),
2278
- E ? /* @__PURE__ */ _(z, {
2461
+ /* @__PURE__ */ y("h2", { children: i.title }),
2462
+ E ? /* @__PURE__ */ y(H, {
2279
2463
  variant: "warning",
2280
2464
  children: i.removalWarning
2281
2465
  }) : null,
2282
- ee ? /* @__PURE__ */ _(z, {
2466
+ z ? /* @__PURE__ */ y(H, {
2283
2467
  variant: "warning",
2284
- children: J(i.mixedCurrency, { currency: r })
2468
+ children: q(i.mixedCurrency, { currency: r })
2285
2469
  }) : null,
2286
- S ? /* @__PURE__ */ _(z, {
2470
+ S ? /* @__PURE__ */ y(H, {
2287
2471
  variant: "error",
2288
2472
  children: i.noActive
2289
2473
  }) : null,
2290
- /* @__PURE__ */ _(H, { error: O.error }),
2291
- w ? /* @__PURE__ */ _(z, {
2474
+ /* @__PURE__ */ y(U, { error: O.error }),
2475
+ w ? /* @__PURE__ */ y(H, {
2292
2476
  variant: "success",
2293
2477
  children: i.saved
2294
2478
  }) : null,
2295
- P ? /* @__PURE__ */ _("p", {
2479
+ A ? /* @__PURE__ */ y("p", {
2296
2480
  className: "sfa-field__help",
2297
2481
  children: i.unsaved
2298
2482
  }) : null,
2299
- o.length === 0 ? /* @__PURE__ */ _("p", { children: i.empty }) : null,
2300
- /* @__PURE__ */ _("ul", {
2483
+ o.length === 0 ? /* @__PURE__ */ y("p", { children: i.empty }) : null,
2484
+ /* @__PURE__ */ y("ul", {
2301
2485
  className: "sfa-rates",
2302
- children: o.map((e, t) => /* @__PURE__ */ _(tt, {
2486
+ children: o.map((e, t) => /* @__PURE__ */ y(ut, {
2303
2487
  draft: e,
2304
2488
  index: t,
2305
2489
  total: o.length,
2306
2490
  errors: {
2307
- ...te[e.key],
2308
- ...b[e.key]
2491
+ ...B[e.key],
2492
+ ...v[e.key]
2309
2493
  },
2310
2494
  disabled: O.pending,
2311
2495
  labels: i,
2312
- onChange: (t) => I(e.key, t),
2313
- onMove: (e) => L(t, e),
2314
- onRemove: () => y(e)
2496
+ onChange: (t) => M(e.key, t),
2497
+ onMove: (e) => N(t, e),
2498
+ onRemove: () => m(e)
2315
2499
  }, e.key))
2316
2500
  }),
2317
- /* @__PURE__ */ v("div", {
2501
+ /* @__PURE__ */ b("div", {
2318
2502
  className: "sfa-shipping__actions",
2319
- children: [/* @__PURE__ */ _("button", {
2503
+ children: [/* @__PURE__ */ y("button", {
2320
2504
  type: "button",
2321
2505
  className: "sfa-btn",
2322
- onClick: B,
2506
+ onClick: ee,
2323
2507
  children: i.add
2324
- }), /* @__PURE__ */ _("button", {
2508
+ }), /* @__PURE__ */ y("button", {
2325
2509
  type: "button",
2326
2510
  className: "sfa-btn sfa-btn--primary",
2327
2511
  disabled: O.pending,
2328
- onClick: U,
2512
+ onClick: R,
2329
2513
  children: i.save
2330
2514
  })]
2331
2515
  }),
2332
- /* @__PURE__ */ _(R, {
2333
- open: g !== null,
2516
+ /* @__PURE__ */ y(V, {
2517
+ open: p !== null,
2334
2518
  title: i.removeTitle,
2335
2519
  destructive: !0,
2336
2520
  confirmLabel: i.remove,
2337
- onConfirm: V,
2338
- onCancel: () => y(null),
2339
- children: /* @__PURE__ */ _("p", { children: i.removeBody })
2521
+ onConfirm: te,
2522
+ onCancel: () => m(null),
2523
+ children: /* @__PURE__ */ y("p", { children: i.removeBody })
2524
+ })
2525
+ ]
2526
+ }) : /* @__PURE__ */ y(U, { error: a.error });
2527
+ }
2528
+ // src/lib/discount-status.ts
2529
+ function ft(e, t = /* @__PURE__ */ new Date()) {
2530
+ return e.active ? e.startsAt && new Date(e.startsAt) > t ? "scheduled" : e.endsAt && new Date(e.endsAt) <= t ? "expired" : "active" : "inactive";
2531
+ }
2532
+ function Q(e, t) {
2533
+ return e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e);
2534
+ }
2535
+ // src/lib/use-discount-pages.ts
2536
+ function pt(e) {
2537
+ let t = F(), n = I(["admin-discounts", e], () => t.listDiscounts(e)), [r, i] = _(null), a = L(async (n, r) => {
2538
+ let a = await t.listDiscounts({
2539
+ ...e,
2540
+ cursor: n
2541
+ });
2542
+ i((e) => ({
2543
+ base: r,
2544
+ items: [...e?.base === r ? e.items : [], ...a.items],
2545
+ nextCursor: a.nextCursor
2546
+ }));
2547
+ }), o = n.data, s = r && r.base === o ? r : null, c = s ? s.nextCursor : o?.nextCursor ?? null;
2548
+ return {
2549
+ items: [...o?.items ?? [], ...s?.items ?? []],
2550
+ loaded: o !== void 0,
2551
+ loading: n.loading,
2552
+ error: n.error ?? a.error,
2553
+ hasMore: !n.loading && c !== null,
2554
+ loadingMore: a.pending,
2555
+ reload: n.reload,
2556
+ loadMore: () => {
2557
+ o && c && a.run(c, o);
2558
+ }
2559
+ };
2560
+ }
2561
+ // src/views/discounts/discount-value.tsx
2562
+ function mt({ discount: e }) {
2563
+ return e.type === "percent" ? /* @__PURE__ */ b("span", { children: [e.percentOff, "%"] }) : /* @__PURE__ */ y(B, {
2564
+ cents: e.amountOffCents ?? 0,
2565
+ currency: e.currency ?? "USD"
2566
+ });
2567
+ }
2568
+ // src/views/discounts/admin-discount-list.tsx
2569
+ var ht = [
2570
+ "active",
2571
+ "scheduled",
2572
+ "expired",
2573
+ "inactive"
2574
+ ];
2575
+ function gt() {
2576
+ let { labels: e, hrefs: t, renderLink: n } = P(), r = e.discounts, [i, a] = _("active"), [o, s] = _(""), c = W(o.trim(), 300), l = pt({
2577
+ status: i,
2578
+ ...c ? { q: c } : {}
2579
+ }), u = [
2580
+ {
2581
+ key: "code",
2582
+ header: r.columns.code,
2583
+ render: (e) => n({
2584
+ href: t.discount(e.id),
2585
+ children: e.code,
2586
+ className: "sfa-link--tap"
2340
2587
  })
2588
+ },
2589
+ {
2590
+ key: "value",
2591
+ header: r.columns.value,
2592
+ render: (e) => /* @__PURE__ */ y(mt, { discount: e })
2593
+ },
2594
+ {
2595
+ key: "status",
2596
+ header: r.columns.status,
2597
+ render: (e) => /* @__PURE__ */ y(z, { status: ft(e) })
2598
+ },
2599
+ {
2600
+ key: "usage",
2601
+ header: r.columns.usage,
2602
+ render: (e) => {
2603
+ let t = e.redeemedCount + e.reservedCount;
2604
+ return e.maxRedemptions ? Q(r.usage, {
2605
+ used: t,
2606
+ max: e.maxRedemptions
2607
+ }) : Q(r.usageUnlimited, { used: t });
2608
+ }
2609
+ }
2610
+ ];
2611
+ return /* @__PURE__ */ b("section", {
2612
+ className: "sfa-products",
2613
+ children: [
2614
+ /* @__PURE__ */ b("header", {
2615
+ className: "sfa-products__header",
2616
+ children: [/* @__PURE__ */ y("h1", { children: r.title }), n({
2617
+ href: t.newDiscount,
2618
+ children: r.newDiscount,
2619
+ className: "sfa-btn sfa-btn--primary"
2620
+ })]
2621
+ }),
2622
+ /* @__PURE__ */ b("div", {
2623
+ className: "sfa-products__toolbar",
2624
+ children: [/* @__PURE__ */ y("div", {
2625
+ role: "group",
2626
+ "aria-label": r.columns.status,
2627
+ className: "sfa-filter-group",
2628
+ children: ht.map((e) => /* @__PURE__ */ y("button", {
2629
+ type: "button",
2630
+ className: "sfa-btn sfa-filter",
2631
+ "aria-pressed": i === e,
2632
+ onClick: () => a(e),
2633
+ children: r.tabs[e]
2634
+ }, e))
2635
+ }), /* @__PURE__ */ y("input", {
2636
+ type: "search",
2637
+ "aria-label": r.searchLabel,
2638
+ placeholder: r.searchPlaceholder,
2639
+ value: o,
2640
+ onChange: (e) => s(e.target.value)
2641
+ })]
2642
+ }),
2643
+ /* @__PURE__ */ y(U, { error: l.error }),
2644
+ l.loading && !l.loaded ? /* @__PURE__ */ y("p", { children: e.loading }) : l.items.length === 0 ? /* @__PURE__ */ y("p", {
2645
+ className: "sfa-empty",
2646
+ children: c ? r.noMatches : r.empty[i]
2647
+ }) : /* @__PURE__ */ y(R, {
2648
+ columns: u,
2649
+ rows: l.items,
2650
+ rowKey: (e) => e.id
2651
+ }),
2652
+ l.hasMore ? /* @__PURE__ */ y("button", {
2653
+ type: "button",
2654
+ className: "sfa-btn sfa-products__more",
2655
+ disabled: l.loadingMore,
2656
+ onClick: l.loadMore,
2657
+ children: r.loadMore
2658
+ }) : null
2341
2659
  ]
2342
- }) : /* @__PURE__ */ _(H, { error: a.error });
2660
+ });
2661
+ }
2662
+ // src/lib/discount-form.ts
2663
+ var _t = {
2664
+ code: "",
2665
+ type: "percent",
2666
+ percentOff: "",
2667
+ amountOff: "",
2668
+ minSubtotal: "",
2669
+ startsAt: "",
2670
+ endsAt: "",
2671
+ maxRedemptions: ""
2672
+ }, $ = (e) => String(e).padStart(2, "0");
2673
+ function vt(e) {
2674
+ if (!e) return "";
2675
+ let t = new Date(e);
2676
+ return Number.isNaN(t.getTime()) ? "" : `${t.getFullYear()}-${$(t.getMonth() + 1)}-${$(t.getDate())}T${$(t.getHours())}:${$(t.getMinutes())}`;
2677
+ }
2678
+ function yt(e) {
2679
+ if (e.trim() === "") return null;
2680
+ let t = new Date(e);
2681
+ return Number.isNaN(t.getTime()) ? null : t.toISOString();
2682
+ }
2683
+ function bt(e) {
2684
+ return {
2685
+ code: e.code,
2686
+ type: e.type,
2687
+ percentOff: e.percentOff ? String(e.percentOff) : "",
2688
+ amountOff: e.amountOffCents ? K(e.amountOffCents) : "",
2689
+ minSubtotal: e.minSubtotalCents ? K(e.minSubtotalCents) : "",
2690
+ startsAt: vt(e.startsAt),
2691
+ endsAt: vt(e.endsAt),
2692
+ maxRedemptions: e.maxRedemptions ? String(e.maxRedemptions) : ""
2693
+ };
2694
+ }
2695
+ function xt(e) {
2696
+ return !!(e && e.redeemedCount + e.reservedCount > 0);
2697
+ }
2698
+ var St = (e) => /^\d+$/.test(e.trim()) && Number(e) > 0 ? Number(e) : null;
2699
+ function Ct(e, t, n, r = 0) {
2700
+ let i = t.validation, a = {}, o = e.code.trim().toUpperCase();
2701
+ /^[A-Z0-9_-]{1,40}$/.test(o) || (a.code = i.code);
2702
+ let s = St(e.percentOff), c = G(e.amountOff);
2703
+ e.type === "percent" && (s === null || s > 100) && (a.percentOff = i.percentOff), e.type === "fixed" && !c && (a.amountOff = i.amountOff);
2704
+ let l = e.minSubtotal.trim(), u = l === "" ? null : G(l);
2705
+ l !== "" && !u && (a.minSubtotal = i.minSubtotal);
2706
+ let d = e.maxRedemptions.trim(), f = d === "" ? null : St(d);
2707
+ d !== "" && f === null ? a.maxRedemptions = i.maxRedemptions : f !== null && f < r && (a.maxRedemptions = i.maxRedemptionsBelowUsage);
2708
+ let p = yt(e.startsAt), m = yt(e.endsAt);
2709
+ return e.startsAt.trim() !== "" && !p && (a.startsAt = i.date), e.endsAt.trim() !== "" && !m && (a.endsAt = i.date), p && m && new Date(m) <= new Date(p) && (a.endsAt = i.endsBeforeStart), Object.keys(a).length > 0 ? {
2710
+ ok: !1,
2711
+ errors: a
2712
+ } : {
2713
+ ok: !0,
2714
+ input: {
2715
+ code: o,
2716
+ type: e.type,
2717
+ percentOff: e.type === "percent" ? s : null,
2718
+ amountOffCents: e.type === "fixed" ? c : null,
2719
+ currency: e.type === "fixed" ? n : null,
2720
+ minSubtotalCents: u,
2721
+ startsAt: p,
2722
+ endsAt: m,
2723
+ maxRedemptions: f,
2724
+ active: !0
2725
+ }
2726
+ };
2727
+ }
2728
+ var wt = [
2729
+ "type",
2730
+ "percentOff",
2731
+ "amountOffCents",
2732
+ "currency"
2733
+ ], Tt = [
2734
+ "minSubtotalCents",
2735
+ "startsAt",
2736
+ "endsAt",
2737
+ "maxRedemptions"
2738
+ ];
2739
+ function Et(e, t, n) {
2740
+ let r = {}, i = t, a = e, o = (e) => (i[e] ?? null) !== (a[e] ?? null);
2741
+ for (let e of Tt) o(e) && (r[e] = i[e]);
2742
+ if (n) return r;
2743
+ if (o("code") && (r.code = t.code), wt.some(o)) for (let e of wt) r[e] = i[e];
2744
+ return r;
2745
+ }
2746
+ function Dt(e, t) {
2747
+ let n = {
2748
+ code: "code",
2749
+ percentOff: "percentOff",
2750
+ amountOffCents: "amountOff",
2751
+ minSubtotalCents: "minSubtotal",
2752
+ startsAt: "startsAt",
2753
+ endsAt: "endsAt",
2754
+ maxRedemptions: "maxRedemptions"
2755
+ }, r = {};
2756
+ for (let i of e) {
2757
+ let e = i?.path?.[0], a = typeof e == "string" ? n[e] : void 0;
2758
+ a && !r[a] && (r[a] = t);
2759
+ }
2760
+ return r;
2761
+ }
2762
+ // src/views/discounts/discount-fields.tsx
2763
+ function Ot({ name: e, label: t, error: n, help: r, disabled: i, children: a }) {
2764
+ let o = `sfa-field-${e}`, s = [r ? `${o}-help` : "", n ? `${o}-error` : ""].filter(Boolean).join(" ");
2765
+ return /* @__PURE__ */ b("div", {
2766
+ className: "sfa-field",
2767
+ children: [
2768
+ /* @__PURE__ */ y("label", {
2769
+ htmlFor: o,
2770
+ className: "sfa-field__label",
2771
+ children: t
2772
+ }),
2773
+ a({
2774
+ id: o,
2775
+ name: e,
2776
+ disabled: !!i,
2777
+ "aria-invalid": !!n,
2778
+ "aria-describedby": s || void 0
2779
+ }),
2780
+ r ? /* @__PURE__ */ y("p", {
2781
+ id: `${o}-help`,
2782
+ className: "sfa-field__help",
2783
+ children: r
2784
+ }) : null,
2785
+ n ? /* @__PURE__ */ y("p", {
2786
+ id: `${o}-error`,
2787
+ className: "sfa-field__error",
2788
+ children: n
2789
+ }) : null
2790
+ ]
2791
+ });
2792
+ }
2793
+ var kt = ["percent", "fixed"];
2794
+ function At({ form: e, errors: t, labels: n, usedCount: r, onChange: i }) {
2795
+ let a = r > 0, o = a ? Q(n.lockedHelp, { count: r }) : void 0, s = (n, r, a = {}) => /* @__PURE__ */ y(Ot, {
2796
+ name: n,
2797
+ label: r,
2798
+ error: t[n],
2799
+ help: a.help,
2800
+ disabled: a.locked,
2801
+ children: (t) => /* @__PURE__ */ y("input", {
2802
+ ...t,
2803
+ type: "text",
2804
+ inputMode: a.inputMode,
2805
+ value: e[n],
2806
+ onChange: (e) => i(n, e.target.value)
2807
+ })
2808
+ }), c = (r) => /* @__PURE__ */ y(Ot, {
2809
+ name: r,
2810
+ label: n.fields[r],
2811
+ error: t[r],
2812
+ help: n.optionalHelp,
2813
+ children: (t) => /* @__PURE__ */ y("input", {
2814
+ ...t,
2815
+ type: "datetime-local",
2816
+ value: e[r],
2817
+ onChange: (e) => i(r, e.target.value)
2818
+ })
2819
+ });
2820
+ return /* @__PURE__ */ b(v, { children: [
2821
+ s("code", n.fields.code, {
2822
+ help: o,
2823
+ locked: a
2824
+ }),
2825
+ /* @__PURE__ */ y(Ot, {
2826
+ name: "type",
2827
+ label: n.fields.type,
2828
+ disabled: a,
2829
+ children: (t) => /* @__PURE__ */ y("select", {
2830
+ ...t,
2831
+ value: e.type,
2832
+ onChange: (e) => i("type", e.target.value),
2833
+ children: kt.map((e) => /* @__PURE__ */ y("option", {
2834
+ value: e,
2835
+ children: n.types[e]
2836
+ }, e))
2837
+ })
2838
+ }),
2839
+ e.type === "percent" ? s("percentOff", n.fields.percentOff, {
2840
+ locked: a,
2841
+ inputMode: "numeric"
2842
+ }) : s("amountOff", n.fields.amountOff, {
2843
+ locked: a,
2844
+ inputMode: "decimal"
2845
+ }),
2846
+ s("minSubtotal", n.fields.minSubtotal, {
2847
+ help: n.optionalHelp,
2848
+ inputMode: "decimal"
2849
+ }),
2850
+ c("startsAt"),
2851
+ c("endsAt"),
2852
+ s("maxRedemptions", n.fields.maxRedemptions, {
2853
+ help: n.optionalHelp,
2854
+ inputMode: "numeric"
2855
+ })
2856
+ ] });
2857
+ }
2858
+ // src/views/discounts/admin-discount-editor.tsx
2859
+ function jt({ discountId: e, onSaved: t }) {
2860
+ return e ? /* @__PURE__ */ y(Mt, {
2861
+ discountId: e,
2862
+ onSaved: t
2863
+ }) : /* @__PURE__ */ y(Nt, {
2864
+ discount: void 0,
2865
+ onSaved: t
2866
+ });
2867
+ }
2868
+ function Mt({ discountId: e, onSaved: t }) {
2869
+ let n = F(), { labels: r } = P(), i = I(["admin-discount", e], () => n.getDiscount(e));
2870
+ return i.error ? /* @__PURE__ */ y(U, { error: i.error }) : i.data ? /* @__PURE__ */ y(Nt, {
2871
+ discount: i.data,
2872
+ onSaved: t
2873
+ }, i.data.id) : /* @__PURE__ */ y("p", { children: r.loading });
2874
+ }
2875
+ function Nt({ discount: e, onSaved: t }) {
2876
+ let n = F(), { labels: r, currency: i } = P(), a = r.discounts, [o, c] = _(e), [u, d] = _(e ? bt(e) : _t), [f, p] = _({}), [m, h] = _(!1), [g, v] = _(!1), x = o ? o.redeemedCount + o.reservedCount : 0, S = xt(o), C = (e, t) => {
2877
+ p(t);
2878
+ let n = Object.keys(t)[0];
2879
+ n && e.elements.namedItem(n)?.focus();
2880
+ }, w = L(async (e) => {
2881
+ let t = Ct(u, a, o?.currency ?? i, x);
2882
+ if (!t.ok) C(e, t.errors);
2883
+ else try {
2884
+ if (!o) return await n.createDiscount(t.input);
2885
+ let e = Et(o, t.input, S);
2886
+ return Object.keys(e).length === 0 ? o : await n.updateDiscount(o.id, e);
2887
+ } catch (t) {
2888
+ if (t instanceof s) {
2889
+ C(e, { code: a.validation.codeTaken });
2890
+ return;
2891
+ }
2892
+ if (!(t instanceof l)) throw t;
2893
+ C(e, Dt(t.issues, a.validation.invalid));
2894
+ return;
2895
+ }
2896
+ }), T = L((e) => {
2897
+ if (!o) throw Error("Discount has not been created yet.");
2898
+ return n.updateDiscount(o.id, { active: e });
2899
+ }), E = (e) => {
2900
+ c(e), d(bt(e)), h(!0), t?.(e);
2901
+ }, D = (e, t) => {
2902
+ d((n) => ({
2903
+ ...n,
2904
+ [e]: t
2905
+ })), p((t) => ({
2906
+ ...t,
2907
+ [e]: void 0
2908
+ }));
2909
+ }, O = async (e) => {
2910
+ e.preventDefault(), h(!1), p({}), w.reset();
2911
+ let t = await w.run(e.currentTarget);
2912
+ t && E(t);
2913
+ }, k = async (e) => {
2914
+ v(!1), h(!1);
2915
+ let t = await T.run(e);
2916
+ t && E(t);
2917
+ };
2918
+ return /* @__PURE__ */ b("form", {
2919
+ noValidate: !0,
2920
+ className: "sfa-form",
2921
+ onSubmit: O,
2922
+ children: [
2923
+ /* @__PURE__ */ y("h1", { children: o ? a.editTitle : a.createTitle }),
2924
+ /* @__PURE__ */ y(U, { error: w.error ?? T.error }),
2925
+ /* @__PURE__ */ y(At, {
2926
+ form: u,
2927
+ errors: f,
2928
+ labels: a,
2929
+ usedCount: x,
2930
+ onChange: D
2931
+ }),
2932
+ /* @__PURE__ */ b("div", {
2933
+ className: "sfa-row-actions",
2934
+ children: [
2935
+ /* @__PURE__ */ y("button", {
2936
+ type: "submit",
2937
+ className: "sfa-btn sfa-btn--primary",
2938
+ disabled: w.pending,
2939
+ children: r.save
2940
+ }),
2941
+ o?.active ? /* @__PURE__ */ y("button", {
2942
+ type: "button",
2943
+ className: "sfa-btn",
2944
+ onClick: () => v(!0),
2945
+ children: a.deactivate
2946
+ }) : null,
2947
+ o && !o.active ? /* @__PURE__ */ y("button", {
2948
+ type: "button",
2949
+ className: "sfa-btn",
2950
+ disabled: T.pending,
2951
+ onClick: () => k(!0),
2952
+ children: a.reactivate
2953
+ }) : null
2954
+ ]
2955
+ }),
2956
+ /* @__PURE__ */ y(V, {
2957
+ open: g,
2958
+ title: a.deactivateTitle,
2959
+ confirmLabel: a.deactivate,
2960
+ destructive: !0,
2961
+ pending: T.pending,
2962
+ onConfirm: () => k(!1),
2963
+ onCancel: () => v(!1),
2964
+ children: /* @__PURE__ */ y("p", { children: a.deactivateBody })
2965
+ }),
2966
+ m ? /* @__PURE__ */ y(H, {
2967
+ variant: "success",
2968
+ toast: !0,
2969
+ onDismiss: () => h(!1),
2970
+ children: a.saved
2971
+ }) : null
2972
+ ]
2973
+ });
2343
2974
  }
2344
- export { N as AdminLayout, qe as AdminOrderDetail, Me as AdminOrderList, Ee as AdminProductEditor, xe as AdminProductImages, oe as AdminProductList, O as AdminProvider, nt as AdminShippingRates, P as AdminTable, R as ConfirmDialog, H as ErrorMessage, I as Money, z as Notice, He as OrderActions, F as StatusBadge, V as errorKey, G as formatMoneyInput, W as parseMoneyInput, k as useAdmin, A as useAdminClient, M as useAdminMutation, j as useAdminQuery };
2975
+ export { jt as AdminDiscountEditor, gt as AdminDiscountList, te as AdminLayout, tt as AdminOrderDetail, Be as AdminOrderList, Pe as AdminProductEditor, ke as AdminProductImages, de as AdminProductList, ee as AdminProvider, dt as AdminShippingRates, R as AdminTable, V as ConfirmDialog, U as ErrorMessage, B as Money, H as Notice, Xe as OrderActions, z as StatusBadge, ie as errorKey, K as formatMoneyInput, G as parseMoneyInput, P as useAdmin, F as useAdminClient, L as useAdminMutation, I as useAdminQuery };
2345
2976
 
2346
2977
  //# sourceMappingURL=index.js.map