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