@gomusdev/web-components 2.1.1-next.1 → 3.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/README.md +936 -12
  2. package/dist-js/components/cart/components/CartCoupons.svelte.d.ts +1 -0
  3. package/dist-js/components/cart/components/CartDiscountedAmount.svelte.d.ts +1 -0
  4. package/dist-js/components/cart/components/CartItems.svelte.d.ts +1 -0
  5. package/dist-js/components/cart/components/CartSubtotalAmount.svelte.d.ts +1 -0
  6. package/dist-js/components/cart/components/CartTotalAmount.svelte.d.ts +1 -0
  7. package/dist-js/gomus-webcomponents.css +52 -15
  8. package/dist-js/gomus-webcomponents.iife.js +406 -272
  9. package/dist-js/gomus-webcomponents.js +406 -272
  10. package/dist-js/gomus-webcomponents.min.css +1 -1
  11. package/dist-js/gomus-webcomponents.min.iife.js +12 -12
  12. package/dist-js/gomus-webcomponents.min.js +7131 -7026
  13. package/dist-js/src/components/cart/components/CartCounter.spec.d.ts +1 -0
  14. package/dist-js/src/components/cart/components/CartCoupons.spec.d.ts +1 -0
  15. package/dist-js/src/components/cart/components/CartDetails.spec.d.ts +1 -0
  16. package/dist-js/src/components/cart/components/CartDetails.svelte.d.ts +15 -0
  17. package/dist-js/src/components/cart/components/CartDiscountedAmount.spec.d.ts +1 -0
  18. package/dist-js/src/components/cart/components/CartItems.spec.d.ts +1 -0
  19. package/dist-js/src/components/cart/components/CartSubtotalAmount.spec.d.ts +1 -0
  20. package/dist-js/src/components/cart/components/CartTotalAmount.spec.d.ts +1 -0
  21. package/dist-js/src/components/cart/components/Item.spec.d.ts +1 -0
  22. package/dist-js/src/components/cart/components/itemTitles/Event.spec.d.ts +1 -0
  23. package/dist-js/src/components/cart/components/itemTitles/Ticket.spec.d.ts +1 -0
  24. package/dist-js/src/components/cart/components/utils.spec.d.ts +1 -0
  25. package/dist-js/src/factories/CartItemFactories.d.ts +173 -0
  26. package/dist-js/src/test-helpers/resetShop.d.ts +1 -0
  27. package/package.json +4 -2
@@ -11453,17 +11453,17 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11453
11453
  console.warn(`Failed to remove from localStorage (${key}):`, e);
11454
11454
  }
11455
11455
  }
11456
- const KEY$5 = "go-capacity";
11456
+ const KEY$6 = "go-capacity";
11457
11457
  function saveCapacityToLocalStorage(allSeats, allQuotas) {
11458
- const existing = loadFromLocalStorage(KEY$5);
11458
+ const existing = loadFromLocalStorage(KEY$6);
11459
11459
  const merged = {
11460
11460
  allSeats: { ...existing?.allSeats || {}, ...allSeats },
11461
11461
  allQuotas: { ...existing?.allQuotas || {}, ...allQuotas }
11462
11462
  };
11463
- saveToLocalStorage(KEY$5, merged);
11463
+ saveToLocalStorage(KEY$6, merged);
11464
11464
  }
11465
11465
  function loadCapacityFromLocalStorage(manager) {
11466
- const data = loadFromLocalStorage(KEY$5);
11466
+ const data = loadFromLocalStorage(KEY$6);
11467
11467
  if (!data) return;
11468
11468
  if (data.allSeats) {
11469
11469
  for (const dateId in data.allSeats) {
@@ -11478,13 +11478,13 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
11478
11478
  function syncCapacityAcrossTabs(manager) {
11479
11479
  if (!isLocalStorageAvailable()) return;
11480
11480
  window.addEventListener("storage", (event2) => {
11481
- if (event2.key === KEY$5) {
11481
+ if (event2.key === KEY$6) {
11482
11482
  loadCapacityFromLocalStorage(manager);
11483
11483
  }
11484
11484
  if (event2.key === "go-cart") {
11485
11485
  const cart = loadFromLocalStorage("go-cart");
11486
11486
  const cartEmpty = !cart || !cart.items || cart.items.length === 0;
11487
- if (cartEmpty) removeFromLocalStorage(KEY$5);
11487
+ if (cartEmpty) removeFromLocalStorage(KEY$6);
11488
11488
  }
11489
11489
  });
11490
11490
  }
@@ -12610,21 +12610,13 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
12610
12610
  checkout(params) {
12611
12611
  return this.apiPost(`/api/v4/orders`, { body: params, requiredFields: ["items", "total"] });
12612
12612
  }
12613
- // Single-slot memo: dedupes identical /api/v4/cart projections across multiple
12614
- // <go-cart> instances and back-to-back effect runs so the endpoint's rate
12615
- // limit is not hit by a page that mounts several cart views.
12616
- #cartProjectionCache = null;
12617
- createCart(params) {
12613
+ #lastCart = null;
12614
+ async createCart(params) {
12618
12615
  const key = JSON.stringify({ items: params.items ?? [], coupons: params.coupons ?? [] });
12619
- if (this.#cartProjectionCache?.key === key) {
12620
- return this.#cartProjectionCache.promise;
12621
- }
12622
- const promise = this.apiPost(`/api/v4/cart`, { body: params, requiredFields: ["items"] }).catch((err2) => {
12623
- if (this.#cartProjectionCache?.key === key) this.#cartProjectionCache = null;
12624
- throw err2;
12625
- });
12626
- this.#cartProjectionCache = { key, promise };
12627
- return promise;
12616
+ if (this.#lastCart?.key === key) return this.#lastCart.result;
12617
+ const result = await this.apiPost(`/api/v4/cart`, { body: params, requiredFields: ["items"] });
12618
+ this.#lastCart = { key, result };
12619
+ return result;
12628
12620
  }
12629
12621
  order(token) {
12630
12622
  return this.fetchAndCache("/api/v4/orders/{id}", `order-${token}`, "order", { path: { id: token } });
@@ -12967,11 +12959,11 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
12967
12959
  }
12968
12960
  }
12969
12961
  }
12970
- const KEY$4 = "go-annual-ticket-personalization";
12971
- const setPersonalizationDetails = createSetDetails(KEY$4);
12972
- const getPersonalizationDetails = createGetDetails(KEY$4);
12973
- var root_3$9 = /* @__PURE__ */ from_html(`<li><a> </a></li>`);
12974
- var root_2$r = /* @__PURE__ */ from_html(`<ul class="go-annual-ticket"><li class="go-annual-ticket-title"> </li> <li class="go-annual-ticket-personalization-count"> </li> <!></ul>`);
12962
+ const KEY$5 = "go-annual-ticket-personalization";
12963
+ const setPersonalizationDetails = createSetDetails(KEY$5);
12964
+ const getPersonalizationDetails = createGetDetails(KEY$5);
12965
+ var root_3$a = /* @__PURE__ */ from_html(`<li><a> </a></li>`);
12966
+ var root_2$s = /* @__PURE__ */ from_html(`<ul class="go-annual-ticket"><li class="go-annual-ticket-title"> </li> <li class="go-annual-ticket-personalization-count"> </li> <!></ul>`);
12975
12967
  function AnnualTicketPersonalization($$anchor, $$props) {
12976
12968
  push($$props, true);
12977
12969
  let token = prop($$props, "token", 7);
@@ -12998,7 +12990,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
12998
12990
  var fragment_1 = comment();
12999
12991
  var node_1 = first_child(fragment_1);
13000
12992
  each(node_1, 17, () => get$2(order).ticket_sales, (ticketSale) => ticketSale.id, ($$anchor3, ticketSale) => {
13001
- var ul = root_2$r();
12993
+ var ul = root_2$s();
13002
12994
  var li = child(ul);
13003
12995
  var text2 = child(li, true);
13004
12996
  reset(li);
@@ -13008,7 +13000,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
13008
13000
  var node_2 = sibling(li_1, 2);
13009
13001
  {
13010
13002
  var consequent = ($$anchor4) => {
13011
- var li_2 = root_3$9();
13003
+ var li_2 = root_3$a();
13012
13004
  var a2 = child(li_2);
13013
13005
  var text_2 = child(a2, true);
13014
13006
  reset(a2);
@@ -16670,9 +16662,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16670
16662
  });
16671
16663
  }
16672
16664
  }
16673
- const KEY$3 = "go-form-details";
16674
- const setDetails$1 = createSetDetails(KEY$3);
16675
- const getDetails$1 = createGetDetails(KEY$3);
16665
+ const KEY$4 = "go-form-details";
16666
+ const setDetails$1 = createSetDetails(KEY$4);
16667
+ const getDetails$1 = createGetDetails(KEY$4);
16676
16668
  function wrapInElement(host, tag, props) {
16677
16669
  const first = host.firstElementChild || void 0;
16678
16670
  if (host.children?.length === 1 && first?.tagName.toLowerCase() === tag) {
@@ -16696,7 +16688,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16696
16688
  host.replaceChildren(element);
16697
16689
  return element;
16698
16690
  }
16699
- var root_1$l = /* @__PURE__ */ from_html(`<go-all-fields></go-all-fields> <go-form-feedback><go-errors-feedback></go-errors-feedback> <go-success-feedback></go-success-feedback></go-form-feedback> <go-submit> </go-submit>`, 3);
16691
+ var root_1$q = /* @__PURE__ */ from_html(`<go-all-fields></go-all-fields> <go-form-feedback><go-errors-feedback></go-errors-feedback> <go-success-feedback></go-success-feedback></go-form-feedback> <go-submit> </go-submit>`, 3);
16700
16692
  function Form($$anchor, $$props) {
16701
16693
  push($$props, true);
16702
16694
  let formId = prop($$props, "formId", 7), custom2 = prop($$props, "custom", 7);
@@ -16739,7 +16731,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16739
16731
  var node = first_child(fragment);
16740
16732
  {
16741
16733
  var consequent = ($$anchor2) => {
16742
- var fragment_1 = root_1$l();
16734
+ var fragment_1 = root_1$q();
16743
16735
  var go_all_fields = first_child(fragment_1);
16744
16736
  var go_form_feedback = sibling(go_all_fields, 2);
16745
16737
  var go_submit = sibling(go_form_feedback, 2);
@@ -16900,7 +16892,128 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16900
16892
  [],
16901
16893
  []
16902
16894
  ));
16903
- var root_1$k = /* @__PURE__ */ from_html(`<span class="go-cart-item-date" data-testid="cart-item-date"> </span><span class="go-cart-item-time" data-testid="cart-item-time"> </span>`, 1);
16895
+ function getQuantity(value, fallback) {
16896
+ if (typeof value === "number" && Number.isFinite(value)) return value;
16897
+ if (value && typeof value === "object") {
16898
+ const total = Object.values(value).reduce((sum2, num) => {
16899
+ return typeof num === "number" && Number.isFinite(num) ? sum2 + num : sum2;
16900
+ }, 0);
16901
+ if (total > 0) return total;
16902
+ }
16903
+ return fallback;
16904
+ }
16905
+ function resolveQuantitySource(attrs) {
16906
+ return "quantity" in attrs && attrs.quantity !== void 0 ? attrs.quantity : attrs.quantities;
16907
+ }
16908
+ function resolveApiQuantity(attrs) {
16909
+ return getQuantity(resolveQuantitySource(attrs), 0);
16910
+ }
16911
+ function getScalePriceId(attrs) {
16912
+ const source2 = resolveQuantitySource(attrs);
16913
+ if (source2 && typeof source2 === "object") {
16914
+ const keys = Object.keys(source2);
16915
+ if (keys.length > 0) return Number(keys[0]);
16916
+ }
16917
+ return void 0;
16918
+ }
16919
+ function createDisplayCart(baseCart, apiItems) {
16920
+ const displayCart = createCart();
16921
+ const appliedCoupons = /* @__PURE__ */ new Set();
16922
+ baseCart.coupons.forEach((coupon) => displayCart.addCoupon(coupon));
16923
+ apiItems.forEach((apiItem) => {
16924
+ const attrs = apiItem.attributes;
16925
+ const scalePriceId = getScalePriceId(attrs);
16926
+ const itemInBaseCart = baseCart.items.find(
16927
+ (i) => i.type.toLowerCase() === apiItem.type.toLowerCase() && i.product.id === attrs.id && (!attrs.time || i.time === attrs.time) && (scalePriceId === void 0 || isEventTicket(i.product) && i.product.scale_price_id === scalePriceId)
16928
+ );
16929
+ if (!itemInBaseCart) {
16930
+ console.error("(go-cart) Ignoring unmatched cart line", { type: apiItem.type, attrs });
16931
+ return;
16932
+ }
16933
+ if (attrs.coupon) {
16934
+ displayCart.addCoupon(attrs.coupon);
16935
+ appliedCoupons.add(attrs.coupon);
16936
+ }
16937
+ displayCart.addItem(createDisplayCartItem(itemInBaseCart, attrs));
16938
+ });
16939
+ return { cart: displayCart, appliedCoupons };
16940
+ }
16941
+ function createDisplayCartItem(cartItem, attrs) {
16942
+ const quantity = resolveApiQuantity(attrs);
16943
+ const displayPrice = attrs.price_cents ?? cartItem.product.price_cents;
16944
+ const originalPrice = cartItem.product.price_cents;
16945
+ const discounted = displayPrice < originalPrice;
16946
+ const product = { ...cartItem.product, price_cents: displayPrice };
16947
+ return createCartItem(product, {
16948
+ quantity,
16949
+ time: cartItem.time,
16950
+ display: {
16951
+ discounted,
16952
+ reference_uuid: cartItem.uuid,
16953
+ originalPrice
16954
+ }
16955
+ });
16956
+ }
16957
+ class CartDetails {
16958
+ #displayCart = /* @__PURE__ */ state();
16959
+ get displayCart() {
16960
+ return get$2(this.#displayCart);
16961
+ }
16962
+ set displayCart(value) {
16963
+ set(this.#displayCart, value, true);
16964
+ }
16965
+ #appliedCoupons = /* @__PURE__ */ state(proxy(/* @__PURE__ */ new Set()));
16966
+ get appliedCoupons() {
16967
+ return get$2(this.#appliedCoupons);
16968
+ }
16969
+ set appliedCoupons(value) {
16970
+ set(this.#appliedCoupons, value, true);
16971
+ }
16972
+ #preview = /* @__PURE__ */ state(false);
16973
+ get preview() {
16974
+ return get$2(this.#preview);
16975
+ }
16976
+ set preview(value) {
16977
+ set(this.#preview, value, true);
16978
+ }
16979
+ get totalPriceCents() {
16980
+ return this.displayCart?.totalPriceCents ?? 0;
16981
+ }
16982
+ get subtotalPriceCents() {
16983
+ return shop.cart?.totalPriceCents ?? 0;
16984
+ }
16985
+ get discountedAmountCents() {
16986
+ return Math.max(0, this.subtotalPriceCents - this.totalPriceCents);
16987
+ }
16988
+ get isDiscounted() {
16989
+ return this.discountedAmountCents > 0;
16990
+ }
16991
+ async calculateDisplayCart() {
16992
+ const mc = shop.cart;
16993
+ if (!mc) return;
16994
+ try {
16995
+ const { items, coupons } = mc.orderData();
16996
+ const response = await shop.createCart({ items, coupons });
16997
+ if (!response || "error" in response) {
16998
+ if (response && "error" in response) {
16999
+ console.error("(go-cart) Unable to fetch discounted cart data", response.error);
17000
+ }
17001
+ this.displayCart = mc;
17002
+ return;
17003
+ }
17004
+ const result = createDisplayCart(mc, response.data.items ?? []);
17005
+ this.displayCart = result.cart;
17006
+ this.appliedCoupons = result.appliedCoupons;
17007
+ } catch (error) {
17008
+ console.error("(go-cart) Unable to fetch discounted cart data", error);
17009
+ this.displayCart = mc;
17010
+ }
17011
+ }
17012
+ }
17013
+ const KEY$3 = "go-cart-details";
17014
+ const setCartDetails = createSetDetails(KEY$3);
17015
+ const getCartDetails = createGetDetails(KEY$3);
17016
+ var root_1$p = /* @__PURE__ */ from_html(`<span class="go-cart-item-date" data-testid="cart-item-date"> </span><span class="go-cart-item-time" data-testid="cart-item-time"> </span>`, 1);
16904
17017
  var root$c = /* @__PURE__ */ from_html(`<span class="go-cart-item-title" data-testid="cart-item-title"><span class="go-cart-item-title-event-title"> </span><span class="go-cart-item-title-ticket-title"> </span></span><!>`, 1);
16905
17018
  function Event$2($$anchor, $$props) {
16906
17019
  push($$props, true);
@@ -16928,7 +17041,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16928
17041
  var node = sibling(span);
16929
17042
  {
16930
17043
  var consequent = ($$anchor2) => {
16931
- var fragment_1 = root_1$k();
17044
+ var fragment_1 = root_1$p();
16932
17045
  var span_3 = first_child(fragment_1);
16933
17046
  var text_2 = child(span_3, true);
16934
17047
  reset(span_3);
@@ -16959,8 +17072,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16959
17072
  return pop($$exports);
16960
17073
  }
16961
17074
  create_custom_element(Event$2, { cartItem: {} }, [], [], { mode: "open" });
16962
- var root_2$q = /* @__PURE__ */ from_html(`<span class="go-cart-item-time" data-testid="cart-item-time"> </span>`);
16963
- var root_1$j = /* @__PURE__ */ from_html(`<span class="go-cart-item-date" data-testid="cart-item-date"> </span> <!>`, 1);
17075
+ var root_2$r = /* @__PURE__ */ from_html(`<span class="go-cart-item-time" data-testid="cart-item-time"> </span>`);
17076
+ var root_1$o = /* @__PURE__ */ from_html(`<span class="go-cart-item-date" data-testid="cart-item-date"> </span> <!>`, 1);
16964
17077
  var root$b = /* @__PURE__ */ from_html(`<span class="go-cart-item-title" data-testid="cart-item-title"> </span> <!>`, 1);
16965
17078
  function Ticket($$anchor, $$props) {
16966
17079
  push($$props, true);
@@ -16981,14 +17094,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16981
17094
  var node = sibling(span, 2);
16982
17095
  {
16983
17096
  var consequent_1 = ($$anchor2) => {
16984
- var fragment_1 = root_1$j();
17097
+ var fragment_1 = root_1$o();
16985
17098
  var span_1 = first_child(fragment_1);
16986
17099
  var text_1 = child(span_1, true);
16987
17100
  reset(span_1);
16988
17101
  var node_1 = sibling(span_1, 2);
16989
17102
  {
16990
17103
  var consequent = ($$anchor3) => {
16991
- var span_2 = root_2$q();
17104
+ var span_2 = root_2$r();
16992
17105
  var text_2 = child(span_2, true);
16993
17106
  reset(span_2);
16994
17107
  template_effect(($0) => set_text(text_2, $0), [() => formatTime(cartItem().time)]);
@@ -17031,21 +17144,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17031
17144
  function option(value) {
17032
17145
  return { value, label: value.toString() };
17033
17146
  }
17034
- var root_5$2 = /* @__PURE__ */ from_html(`<s class="go-cart-item-price-original"> </s> <span class="go-cart-item-price-discounted"> </span>`, 1);
17035
- var root_6$3 = /* @__PURE__ */ from_html(`<span class="go-cart-item-price-discounted"> </span>`);
17036
- var root_7$4 = /* @__PURE__ */ from_html(`<span> </span>`);
17147
+ var root_5$1 = /* @__PURE__ */ from_html(`<s class="go-cart-item-price-original"> </s> <span class="go-cart-item-price-discounted"> </span>`, 1);
17148
+ var root_6$2 = /* @__PURE__ */ from_html(`<span class="go-cart-item-price-discounted"> </span>`);
17149
+ var root_7$3 = /* @__PURE__ */ from_html(`<span> </span>`);
17037
17150
  var root_9$4 = /* @__PURE__ */ from_html(`<option> </option>`);
17038
17151
  var root_8$3 = /* @__PURE__ */ from_html(`<select class="go-cart-item-select"></select>`);
17039
- var root_10$1 = /* @__PURE__ */ from_html(`<li class="go-cart-item-remove"><button>⨉</button></li>`);
17040
- var root_1$i = /* @__PURE__ */ from_html(`<article class="go-cart-item-content"><ul><li class="go-cart-item-title-container"><!></li> <li class="go-cart-item-price"><!></li> <li class="go-cart-item-count"><!></li> <!> <li class="go-cart-item-sum"> </li></ul></article>`);
17152
+ var root_10$1 = /* @__PURE__ */ from_html(`<li class="go-cart-item-remove"><button class="go-cart-remove">⨉</button></li>`);
17153
+ var root_1$n = /* @__PURE__ */ from_html(`<article class="go-cart-item-content"><ul><li class="go-cart-item-title-container"><!></li> <li class="go-cart-item-price"><!></li> <li class="go-cart-item-count"><!></li> <!> <li class="go-cart-item-sum"> </li></ul></article>`);
17041
17154
  function Item$1($$anchor, $$props) {
17042
17155
  push($$props, true);
17043
- let displayItem = prop($$props, "displayItem", 7), displayCart = prop($$props, "displayCart", 7), mainCart = prop($$props, "mainCart", 7), preview = prop($$props, "preview", 7);
17156
+ let displayItem = prop($$props, "displayItem", 7), displayCart = prop($$props, "displayCart", 7), preview = prop($$props, "preview", 7);
17044
17157
  let capacity = /* @__PURE__ */ state(void 0);
17045
- const itemInMaincart = /* @__PURE__ */ user_derived(() => mainCart().items.find((item) => item.uuid === (displayItem().display?.reference_uuid ?? displayItem().uuid)));
17158
+ const itemInMaincart = /* @__PURE__ */ user_derived(() => shop.cart?.items.find((item) => item.uuid === (displayItem().display?.reference_uuid ?? displayItem().uuid)));
17046
17159
  const emptyCart = createCart();
17047
17160
  user_effect(() => {
17048
- mainCart().items.map((i) => i.quantity);
17161
+ shop.cart?.items.map((i) => i.quantity);
17049
17162
  untrack(() => {
17050
17163
  set(capacity, shop.capacityManager.capacity(displayCart(), displayItem(), emptyCart), true);
17051
17164
  });
@@ -17066,7 +17179,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17066
17179
  }
17067
17180
  const newQuantity = Math.max(0, get$2(itemInMaincart).quantity - displayItem().quantity);
17068
17181
  if (newQuantity === 0) {
17069
- mainCart().deleteItem(get$2(itemInMaincart));
17182
+ shop.cart?.deleteItem(get$2(itemInMaincart));
17070
17183
  } else {
17071
17184
  get$2(itemInMaincart).quantity = newQuantity;
17072
17185
  }
@@ -17086,13 +17199,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17086
17199
  displayCart($$value);
17087
17200
  flushSync();
17088
17201
  },
17089
- get mainCart() {
17090
- return mainCart();
17091
- },
17092
- set mainCart($$value) {
17093
- mainCart($$value);
17094
- flushSync();
17095
- },
17096
17202
  get preview() {
17097
17203
  return preview();
17098
17204
  },
@@ -17105,7 +17211,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17105
17211
  var node = first_child(fragment);
17106
17212
  {
17107
17213
  var consequent_5 = ($$anchor2) => {
17108
- var article = root_1$i();
17214
+ var article = root_1$n();
17109
17215
  var ul = child(article);
17110
17216
  var li = child(ul);
17111
17217
  var node_1 = child(li);
@@ -17148,7 +17254,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17148
17254
  var node_3 = child(li_1);
17149
17255
  {
17150
17256
  var consequent_2 = ($$anchor3) => {
17151
- var fragment_4 = root_5$2();
17257
+ var fragment_4 = root_5$1();
17152
17258
  var s = first_child(fragment_4);
17153
17259
  var text2 = child(s, true);
17154
17260
  reset(s);
@@ -17168,7 +17274,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17168
17274
  append($$anchor3, fragment_4);
17169
17275
  };
17170
17276
  var alternate_1 = ($$anchor3) => {
17171
- var span_1 = root_6$3();
17277
+ var span_1 = root_6$2();
17172
17278
  var text_2 = child(span_1, true);
17173
17279
  reset(span_1);
17174
17280
  template_effect(($0) => set_text(text_2, $0), [() => formatCurrency(displayItem().final_price_cents)]);
@@ -17184,7 +17290,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17184
17290
  var node_4 = child(li_2);
17185
17291
  {
17186
17292
  var consequent_3 = ($$anchor3) => {
17187
- var span_2 = root_7$4();
17293
+ var span_2 = root_7$3();
17188
17294
  var text_3 = child(span_2, true);
17189
17295
  reset(span_2);
17190
17296
  template_effect(() => set_text(text_3, displayItem().quantity));
@@ -17224,6 +17330,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17224
17330
  var button = child(li_3);
17225
17331
  button.__click = del;
17226
17332
  reset(li_3);
17333
+ template_effect(($0) => set_attribute(button, "aria-label", $0), [() => shop.t("cart.item.remove")]);
17227
17334
  append($$anchor3, li_3);
17228
17335
  };
17229
17336
  if_block(node_5, ($$render) => {
@@ -17246,131 +17353,19 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17246
17353
  return pop($$exports);
17247
17354
  }
17248
17355
  delegate(["change", "click"]);
17249
- create_custom_element(Item$1, { displayItem: {}, displayCart: {}, mainCart: {}, preview: {} }, [], [], { mode: "open" });
17250
- function getQuantity(value, fallback) {
17251
- if (typeof value === "number" && Number.isFinite(value)) return value;
17252
- if (value && typeof value === "object") {
17253
- const total = Object.values(value).reduce((sum2, num) => {
17254
- return typeof num === "number" && Number.isFinite(num) ? sum2 + num : sum2;
17255
- }, 0);
17256
- if (total > 0) return total;
17257
- }
17258
- return fallback;
17259
- }
17260
- function resolveQuantitySource(attrs) {
17261
- return "quantity" in attrs && attrs.quantity !== void 0 ? attrs.quantity : attrs.quantities;
17262
- }
17263
- function resolveApiQuantity(attrs) {
17264
- return getQuantity(resolveQuantitySource(attrs), 0);
17265
- }
17266
- function getScalePriceId(attrs) {
17267
- const source2 = resolveQuantitySource(attrs);
17268
- if (source2 && typeof source2 === "object") {
17269
- const keys = Object.keys(source2);
17270
- if (keys.length > 0) return Number(keys[0]);
17271
- }
17272
- return void 0;
17273
- }
17274
- function createDisplayCart(baseCart, apiItems) {
17275
- const displayCart = createCart();
17276
- const appliedCoupons = /* @__PURE__ */ new Set();
17277
- baseCart.coupons.forEach((coupon) => displayCart.addCoupon(coupon));
17278
- apiItems.forEach((apiItem) => {
17279
- const attrs = apiItem.attributes;
17280
- const scalePriceId = getScalePriceId(attrs);
17281
- const itemInBaseCart = baseCart.items.find(
17282
- (i) => i.type.toLowerCase() === apiItem.type.toLowerCase() && i.product.id === attrs.id && (!attrs.time || i.time === attrs.time) && (scalePriceId === void 0 || isEventTicket(i.product) && i.product.scale_price_id === scalePriceId)
17283
- );
17284
- if (!itemInBaseCart) {
17285
- console.error("(go-cart) Ignoring unmatched cart line", { type: apiItem.type, attrs });
17286
- return;
17287
- }
17288
- if (attrs.coupon) {
17289
- displayCart.addCoupon(attrs.coupon);
17290
- appliedCoupons.add(attrs.coupon);
17291
- }
17292
- displayCart.addItem(createDisplayCartItem(itemInBaseCart, attrs));
17293
- });
17294
- return { cart: displayCart, appliedCoupons };
17295
- }
17296
- function createDisplayCartItem(cartItem, attrs) {
17297
- const quantity = resolveApiQuantity(attrs);
17298
- const displayPrice = attrs.price_cents ?? cartItem.product.price_cents;
17299
- const originalPrice = cartItem.product.price_cents;
17300
- const discounted = displayPrice < originalPrice;
17301
- const product = { ...cartItem.product, price_cents: displayPrice };
17302
- return createCartItem(product, {
17303
- quantity,
17304
- time: cartItem.time,
17305
- display: {
17306
- discounted,
17307
- reference_uuid: cartItem.uuid,
17308
- originalPrice
17309
- }
17310
- });
17311
- }
17312
- var root_2$p = /* @__PURE__ */ from_html(`<li class="go-cart-header-remove"></li>`);
17313
- var root_3$8 = /* @__PURE__ */ from_html(`<li class="go-cart-item"><!></li>`);
17314
- var root_6$2 = /* @__PURE__ */ from_html(`<li class="go-cart-item-remove"><button>⨉</button></li>`);
17315
- var root_5$1 = /* @__PURE__ */ from_html(`<li><article class="go-cart-item-content"><ul><li class="go-cart-item-title"> </li> <li class="go-cart-item-price"></li> <li class="go-cart-item-count"></li> <!> <li class="go-cart-item-sum"></li></ul></article></li>`);
17316
- var root_7$3 = /* @__PURE__ */ from_html(`<li class="go-cart-footer-remove"></li>`);
17317
- var root_1$h = /* @__PURE__ */ from_html(`<ol data-testid="cart"><li class="go-cart-header"><ul><li class="go-cart-header-title"> </li> <li class="go-cart-header-price"> </li> <li class="go-cart-header-count"> </li> <!> <li class="go-cart-header-sum"> </li></ul></li> <!> <!> <li class="go-cart-footer"><ul><li class="go-cart-footer-title"></li> <li class="go-cart-footer-price"></li> <li class="go-cart-footer-count"></li> <!> <li class="go-cart-footer-sum"> </li></ul></li></ol>`);
17318
- function Cart($$anchor, $$props) {
17356
+ create_custom_element(Item$1, { displayItem: {}, displayCart: {}, preview: {} }, [], [], { mode: "open" });
17357
+ var root_2$q = /* @__PURE__ */ from_html(`<li class="go-cart-header-remove"></li>`);
17358
+ var root_3$9 = /* @__PURE__ */ from_html(`<li class="go-cart-item"><!></li>`);
17359
+ var root_1$m = /* @__PURE__ */ from_html(`<ol data-testid="cart-items"><li class="go-cart-header"><ul><li class="go-cart-header-title"> </li> <li class="go-cart-header-price"> </li> <li class="go-cart-header-count"> </li> <!> <li class="go-cart-header-sum"> </li></ul></li> <!></ol>`);
17360
+ function CartItems($$anchor, $$props) {
17319
17361
  push($$props, true);
17320
- const preview = prop($$props, "preview", 7, false);
17321
- let cart = /* @__PURE__ */ user_derived(() => shop.cart);
17322
- let displayCart = /* @__PURE__ */ state(proxy(get$2(cart)));
17323
- let appliedCoupons = /* @__PURE__ */ state(proxy(/* @__PURE__ */ new Set()));
17324
- let requestId = 0;
17325
- const displayTotalCents = /* @__PURE__ */ user_derived(() => get$2(displayCart)?.totalPriceCents ?? 0);
17326
- user_effect(() => {
17327
- if (!get$2(cart)) {
17328
- return;
17329
- }
17330
- get$2(cart).items.map((i) => i.uuid + ":" + i.quantity + ":" + i.time);
17331
- get$2(cart).coupons.join("|");
17332
- const currentRequest = ++requestId;
17333
- if (get$2(cart).items.length === 0 || get$2(cart).coupons.length === 0) {
17334
- set(displayCart, get$2(cart), true);
17335
- set(appliedCoupons, /* @__PURE__ */ new Set(), true);
17336
- return;
17337
- }
17338
- void (async () => {
17339
- try {
17340
- const { items, coupons } = get$2(cart).orderData();
17341
- const response = await shop.createCart({ items, coupons });
17342
- if (currentRequest !== requestId || !get$2(cart)) return;
17343
- if (!response || "error" in response) {
17344
- if (response && "error" in response) {
17345
- console.error("(go-cart) Unable to fetch discounted cart data", response.error);
17346
- }
17347
- set(displayCart, get$2(cart), true);
17348
- return;
17349
- }
17350
- const result = createDisplayCart(get$2(cart), response.data.items ?? []);
17351
- set(displayCart, result.cart, true);
17352
- set(appliedCoupons, result.appliedCoupons, true);
17353
- } catch (error) {
17354
- console.error("(go-cart) Unable to fetch discounted cart data", error);
17355
- if (currentRequest !== requestId || !get$2(cart)) return;
17356
- set(displayCart, get$2(cart), true);
17357
- }
17358
- })();
17359
- });
17360
- var $$exports = {
17361
- get preview() {
17362
- return preview();
17363
- },
17364
- set preview($$value = false) {
17365
- preview($$value);
17366
- flushSync();
17367
- }
17368
- };
17362
+ const _details = getCartDetails($$props.$$host);
17363
+ const details = /* @__PURE__ */ user_derived(() => _details.value);
17369
17364
  var fragment = comment();
17370
17365
  var node = first_child(fragment);
17371
17366
  {
17372
- var consequent_4 = ($$anchor2) => {
17373
- var ol = root_1$h();
17367
+ var consequent_1 = ($$anchor2) => {
17368
+ var ol = root_1$m();
17374
17369
  var li = child(ol);
17375
17370
  var ul = child(li);
17376
17371
  var li_1 = child(ul);
@@ -17385,11 +17380,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17385
17380
  var node_1 = sibling(li_3, 2);
17386
17381
  {
17387
17382
  var consequent = ($$anchor3) => {
17388
- var li_4 = root_2$p();
17383
+ var li_4 = root_2$q();
17389
17384
  append($$anchor3, li_4);
17390
17385
  };
17391
17386
  if_block(node_1, ($$render) => {
17392
- if (!preview()) $$render(consequent);
17387
+ if (!get$2(details).preview) $$render(consequent);
17393
17388
  });
17394
17389
  }
17395
17390
  var li_5 = sibling(node_1, 2);
@@ -17398,120 +17393,236 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17398
17393
  reset(ul);
17399
17394
  reset(li);
17400
17395
  var node_2 = sibling(li, 2);
17401
- each(node_2, 17, () => get$2(displayCart).items, (item) => item.uuid, ($$anchor3, item) => {
17402
- var li_6 = root_3$8();
17396
+ each(node_2, 17, () => get$2(details).displayCart.items, (item) => item.uuid, ($$anchor3, item) => {
17397
+ var li_6 = root_3$9();
17403
17398
  var node_3 = child(li_6);
17404
17399
  Item$1(node_3, {
17405
17400
  get displayItem() {
17406
17401
  return get$2(item);
17407
17402
  },
17408
17403
  get displayCart() {
17409
- return get$2(displayCart);
17410
- },
17411
- get mainCart() {
17412
- return get$2(cart);
17404
+ return get$2(details).displayCart;
17413
17405
  },
17414
17406
  get preview() {
17415
- return preview();
17407
+ return get$2(details).preview;
17416
17408
  }
17417
17409
  });
17418
17410
  reset(li_6);
17419
17411
  append($$anchor3, li_6);
17420
17412
  });
17421
- var node_4 = sibling(node_2, 2);
17422
- {
17423
- var consequent_2 = ($$anchor3) => {
17424
- var fragment_1 = comment();
17425
- var node_5 = first_child(fragment_1);
17426
- each(node_5, 16, () => get$2(displayCart).coupons, (coupon) => coupon, ($$anchor4, coupon) => {
17427
- var li_7 = root_5$1();
17428
- let classes;
17429
- var article = child(li_7);
17430
- var ul_1 = child(article);
17431
- var li_8 = child(ul_1);
17432
- var text_4 = child(li_8, true);
17433
- reset(li_8);
17434
- var node_6 = sibling(li_8, 6);
17435
- {
17436
- var consequent_1 = ($$anchor5) => {
17437
- var li_9 = root_6$2();
17438
- var button = child(li_9);
17439
- button.__click = () => get$2(cart)?.removeCoupon(coupon);
17440
- reset(li_9);
17441
- append($$anchor5, li_9);
17442
- };
17443
- if_block(node_6, ($$render) => {
17444
- if (!preview()) $$render(consequent_1);
17445
- });
17446
- }
17447
- next(2);
17448
- reset(ul_1);
17449
- reset(article);
17450
- reset(li_7);
17451
- template_effect(
17452
- ($0) => {
17453
- classes = set_class(li_7, 1, "go-cart-item", null, classes, $0);
17454
- set_text(text_4, coupon);
17455
- },
17456
- [
17457
- () => ({
17458
- "go-cart-coupon-inactive": !get$2(appliedCoupons).has(coupon)
17459
- })
17460
- ]
17461
- );
17462
- append($$anchor4, li_7);
17463
- });
17464
- append($$anchor3, fragment_1);
17465
- };
17466
- if_block(node_4, ($$render) => {
17467
- if (get$2(displayCart).coupons.length > 0) $$render(consequent_2);
17468
- });
17469
- }
17470
- var li_10 = sibling(node_4, 2);
17471
- var ul_2 = child(li_10);
17472
- var node_7 = sibling(child(ul_2), 6);
17473
- {
17474
- var consequent_3 = ($$anchor3) => {
17475
- var li_11 = root_7$3();
17476
- append($$anchor3, li_11);
17477
- };
17478
- if_block(node_7, ($$render) => {
17479
- if (!preview()) $$render(consequent_3);
17480
- });
17481
- }
17482
- var li_12 = sibling(node_7, 2);
17483
- var text_5 = child(li_12, true);
17484
- reset(li_12);
17485
- reset(ul_2);
17486
- reset(li_10);
17487
17413
  reset(ol);
17488
17414
  template_effect(
17489
- ($0, $1, $2, $3, $4) => {
17415
+ ($0, $1, $2, $3) => {
17490
17416
  set_text(text2, $0);
17491
17417
  set_text(text_1, $1);
17492
17418
  set_text(text_2, $2);
17493
17419
  set_text(text_3, $3);
17494
- set_text(text_5, $4);
17495
17420
  },
17496
17421
  [
17497
17422
  () => shop.t("cart.content.table.desc"),
17498
17423
  () => shop.t("cart.content.table.price"),
17499
17424
  () => shop.t("cart.content.table.quantity"),
17500
- () => shop.t("cart.content.table.total"),
17501
- () => formatCurrency(get$2(displayTotalCents))
17425
+ () => shop.t("cart.content.table.total")
17502
17426
  ]
17503
17427
  );
17504
17428
  append($$anchor2, ol);
17505
17429
  };
17506
17430
  if_block(node, ($$render) => {
17507
- if (get$2(displayCart) && get$2(displayCart).items.length) $$render(consequent_4);
17431
+ if (get$2(details) && get$2(details).displayCart && get$2(details).displayCart.items.length) $$render(consequent_1);
17508
17432
  });
17509
17433
  }
17510
17434
  append($$anchor, fragment);
17511
- return pop($$exports);
17435
+ pop();
17436
+ }
17437
+ customElements.define("go-cart-items", create_custom_element(CartItems, {}, [], []));
17438
+ var root_3$8 = /* @__PURE__ */ from_html(`<li class="go-cart-coupon-remove-cell"><button class="go-cart-remove go-cart-coupon-remove">⨉</button></li>`);
17439
+ var root_2$p = /* @__PURE__ */ from_html(`<li><article class="go-cart-coupon-content"><ul><li class="go-cart-coupon-code"> </li> <!></ul></article></li>`);
17440
+ var root_1$l = /* @__PURE__ */ from_html(`<ol data-testid="cart-coupons"></ol>`);
17441
+ function CartCoupons($$anchor, $$props) {
17442
+ push($$props, true);
17443
+ const _details = getCartDetails($$props.$$host);
17444
+ const details = /* @__PURE__ */ user_derived(() => _details.value);
17445
+ var fragment = comment();
17446
+ var node = first_child(fragment);
17447
+ {
17448
+ var consequent_1 = ($$anchor2) => {
17449
+ var ol = root_1$l();
17450
+ each(ol, 20, () => get$2(details).displayCart.coupons, (coupon) => coupon, ($$anchor3, coupon) => {
17451
+ var li = root_2$p();
17452
+ let classes;
17453
+ var article = child(li);
17454
+ var ul = child(article);
17455
+ var li_1 = child(ul);
17456
+ var text2 = child(li_1, true);
17457
+ reset(li_1);
17458
+ var node_1 = sibling(li_1, 2);
17459
+ {
17460
+ var consequent = ($$anchor4) => {
17461
+ var li_2 = root_3$8();
17462
+ var button = child(li_2);
17463
+ button.__click = () => shop.cart?.removeCoupon(coupon);
17464
+ reset(li_2);
17465
+ template_effect(($0) => set_attribute(button, "aria-label", $0), [() => shop.t("cart.coupons.remove")]);
17466
+ append($$anchor4, li_2);
17467
+ };
17468
+ if_block(node_1, ($$render) => {
17469
+ if (!get$2(details).preview) $$render(consequent);
17470
+ });
17471
+ }
17472
+ reset(ul);
17473
+ reset(article);
17474
+ reset(li);
17475
+ template_effect(
17476
+ ($0) => {
17477
+ classes = set_class(li, 1, "go-cart-coupon", null, classes, $0);
17478
+ set_text(text2, coupon);
17479
+ },
17480
+ [
17481
+ () => ({
17482
+ "go-cart-coupon-inactive": !get$2(details).appliedCoupons.has(coupon)
17483
+ })
17484
+ ]
17485
+ );
17486
+ append($$anchor3, li);
17487
+ });
17488
+ reset(ol);
17489
+ append($$anchor2, ol);
17490
+ };
17491
+ if_block(node, ($$render) => {
17492
+ if (get$2(details) && get$2(details).displayCart && get$2(details).displayCart.coupons.length > 0) $$render(consequent_1);
17493
+ });
17494
+ }
17495
+ append($$anchor, fragment);
17496
+ pop();
17512
17497
  }
17513
17498
  delegate(["click"]);
17514
- customElements.define("go-cart", create_custom_element(Cart, { preview: {} }, [], []));
17499
+ customElements.define("go-cart-coupons", create_custom_element(CartCoupons, {}, [], []));
17500
+ var root_1$k = /* @__PURE__ */ from_html(`<span class="go-cart-total-amount" data-testid="cart-total-amount"> </span>`);
17501
+ function CartTotalAmount($$anchor, $$props) {
17502
+ push($$props, true);
17503
+ const _details = getCartDetails($$props.$$host);
17504
+ const details = /* @__PURE__ */ user_derived(() => _details.value);
17505
+ var fragment = comment();
17506
+ var node = first_child(fragment);
17507
+ {
17508
+ var consequent = ($$anchor2) => {
17509
+ var span = root_1$k();
17510
+ var text2 = child(span, true);
17511
+ reset(span);
17512
+ template_effect(($0) => set_text(text2, $0), [() => formatCurrency(get$2(details).totalPriceCents)]);
17513
+ append($$anchor2, span);
17514
+ };
17515
+ if_block(node, ($$render) => {
17516
+ if (get$2(details) && get$2(details).displayCart && get$2(details).displayCart.items.length) $$render(consequent);
17517
+ });
17518
+ }
17519
+ append($$anchor, fragment);
17520
+ pop();
17521
+ }
17522
+ customElements.define("go-cart-total-amount", create_custom_element(CartTotalAmount, {}, [], []));
17523
+ var root_1$j = /* @__PURE__ */ from_html(`<go-cart-items></go-cart-items> <go-cart-coupons></go-cart-coupons> <go-cart-total-amount></go-cart-total-amount>`, 3);
17524
+ function Cart($$anchor, $$props) {
17525
+ push($$props, true);
17526
+ const preview = prop($$props, "preview", 7, false), useDefault = prop($$props, "default", 7, false);
17527
+ const details = new CartDetails();
17528
+ setCartDetails($$props.$$host, details);
17529
+ user_effect(() => {
17530
+ details.preview = preview();
17531
+ });
17532
+ user_effect(() => {
17533
+ if (!shop.cart) return;
17534
+ shop.cart.items.map((i) => i.uuid + ":" + i.quantity + ":" + i.time);
17535
+ shop.cart.coupons.join("|");
17536
+ untrack(() => details.calculateDisplayCart());
17537
+ });
17538
+ var $$exports = {
17539
+ get preview() {
17540
+ return preview();
17541
+ },
17542
+ set preview($$value = false) {
17543
+ preview($$value);
17544
+ flushSync();
17545
+ },
17546
+ get default() {
17547
+ return useDefault();
17548
+ },
17549
+ set default($$value = false) {
17550
+ useDefault($$value);
17551
+ flushSync();
17552
+ }
17553
+ };
17554
+ var fragment = comment();
17555
+ var node = first_child(fragment);
17556
+ {
17557
+ var consequent = ($$anchor2) => {
17558
+ var fragment_1 = root_1$j();
17559
+ var go_cart_items = first_child(fragment_1);
17560
+ var go_cart_coupons = sibling(go_cart_items, 2);
17561
+ sibling(go_cart_coupons, 2);
17562
+ append($$anchor2, fragment_1);
17563
+ };
17564
+ if_block(node, ($$render) => {
17565
+ if (useDefault()) $$render(consequent);
17566
+ });
17567
+ }
17568
+ append($$anchor, fragment);
17569
+ return pop($$exports);
17570
+ }
17571
+ customElements.define("go-cart", create_custom_element(
17572
+ Cart,
17573
+ {
17574
+ preview: { attribute: "preview", reflect: true, type: "Boolean" },
17575
+ default: { attribute: "default", reflect: true, type: "Boolean" }
17576
+ },
17577
+ [],
17578
+ []
17579
+ ));
17580
+ var root_1$i = /* @__PURE__ */ from_html(`<span class="go-cart-subtotal-amount" data-testid="cart-subtotal-amount"> </span>`);
17581
+ function CartSubtotalAmount($$anchor, $$props) {
17582
+ push($$props, true);
17583
+ const _details = getCartDetails($$props.$$host);
17584
+ const details = /* @__PURE__ */ user_derived(() => _details.value);
17585
+ var fragment = comment();
17586
+ var node = first_child(fragment);
17587
+ {
17588
+ var consequent = ($$anchor2) => {
17589
+ var span = root_1$i();
17590
+ var text2 = child(span, true);
17591
+ reset(span);
17592
+ template_effect(($0) => set_text(text2, $0), [() => formatCurrency(get$2(details).subtotalPriceCents)]);
17593
+ append($$anchor2, span);
17594
+ };
17595
+ if_block(node, ($$render) => {
17596
+ if (get$2(details) && shop.cart?.items.length) $$render(consequent);
17597
+ });
17598
+ }
17599
+ append($$anchor, fragment);
17600
+ pop();
17601
+ }
17602
+ customElements.define("go-cart-subtotal-amount", create_custom_element(CartSubtotalAmount, {}, [], []));
17603
+ var root_1$h = /* @__PURE__ */ from_html(`<span class="go-cart-discounted-amount" data-testid="cart-discounted-amount"><span class="go-cart-discounted-amount-sign">−</span> </span>`);
17604
+ function CartDiscountedAmount($$anchor, $$props) {
17605
+ push($$props, true);
17606
+ const _details = getCartDetails($$props.$$host);
17607
+ const details = /* @__PURE__ */ user_derived(() => _details.value);
17608
+ var fragment = comment();
17609
+ var node = first_child(fragment);
17610
+ {
17611
+ var consequent = ($$anchor2) => {
17612
+ var span = root_1$h();
17613
+ var text2 = sibling(child(span), 1, true);
17614
+ reset(span);
17615
+ template_effect(($0) => set_text(text2, $0), [() => formatCurrency(get$2(details).discountedAmountCents)]);
17616
+ append($$anchor2, span);
17617
+ };
17618
+ if_block(node, ($$render) => {
17619
+ if (get$2(details) && get$2(details).discountedAmountCents > 0) $$render(consequent);
17620
+ });
17621
+ }
17622
+ append($$anchor, fragment);
17623
+ pop();
17624
+ }
17625
+ customElements.define("go-cart-discounted-amount", create_custom_element(CartDiscountedAmount, {}, [], []));
17515
17626
  function CartEmpty($$anchor, $$props) {
17516
17627
  push($$props, true);
17517
17628
  wrapInElement($$props.$$host, "go-if", { when: "data.cart.items.length === 0" });
@@ -17545,9 +17656,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17545
17656
  ]
17546
17657
  });
17547
17658
  wrapInElement($$props.$$host, "go-form", { "form-id": "checkoutGuest", custom: custom2() });
17659
+ async function flushCoupons() {
17660
+ const couponEls = document.querySelectorAll("go-coupon-redemption");
17661
+ let allOk = true;
17662
+ for (const el of couponEls) {
17663
+ const result = await el.flush?.();
17664
+ if (result && !result.success) allOk = false;
17665
+ }
17666
+ return allOk;
17667
+ }
17668
+ $$props.$$host.addEventListener("go-after-validation", flushCoupons);
17548
17669
  $$props.$$host.addEventListener("submit", async (e) => {
17549
17670
  const form = e.target;
17550
17671
  if (!get$2(cart)) return;
17672
+ if (!await flushCoupons()) return;
17551
17673
  const auth = await shop.signUp(form.details.formData, true);
17552
17674
  if (auth.error) {
17553
17675
  form.details.apiErrors = auth.error.errors;
@@ -17579,7 +17701,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17579
17701
  return pop($$exports);
17580
17702
  }
17581
17703
  customElements.define("go-checkout-form", create_custom_element(CheckoutForm, { custom: {} }, [], []));
17582
- enable_legacy_mode_flag();
17583
17704
  const APPLY_ORDER_DISCOUNT = "TokenActions::ApplyOrderDiscount";
17584
17705
  async function redeem(token) {
17585
17706
  if (!shop.cart) {
@@ -17619,32 +17740,42 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17619
17740
  }
17620
17741
  var root$a = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
17621
17742
  function CouponRedemption($$anchor, $$props) {
17622
- push($$props, false);
17743
+ push($$props, true);
17623
17744
  Forms.defineForm({
17624
17745
  id: "couponRedemption",
17625
17746
  submitLabel: "cart.coupon.form.submit",
17626
17747
  fields: [{ key: "token", required: true }]
17627
17748
  });
17628
- async function redeem$1(event2) {
17629
- const form = event2.target;
17749
+ async function runRedeem(form) {
17630
17750
  const field = form.details.fields.find((f) => f.key === "token");
17631
- const token = form.details.fieldValue("token").trim();
17751
+ const token = (form.details.fieldValue("token") ?? "").trim();
17752
+ if (!token) return { success: true };
17632
17753
  const result = await redeem(token);
17633
17754
  if (!result.success) {
17634
17755
  form.details.apiErrors = result.errors;
17635
- return;
17756
+ return result;
17636
17757
  }
17637
- field.value = "";
17758
+ if (field) field.value = "";
17638
17759
  form.dispatchEvent(new Event("go-success", { bubbles: true, composed: true }));
17760
+ return result;
17639
17761
  }
17640
- init();
17762
+ async function redeem$1(event2) {
17763
+ await runRedeem(event2.target);
17764
+ }
17765
+ async function flush() {
17766
+ const form = $$props.$$host.querySelector("go-form");
17767
+ if (!form?.details) return { success: true };
17768
+ return runRedeem(form);
17769
+ }
17770
+ var $$exports = { flush };
17641
17771
  var go_form = root$a();
17642
17772
  set_custom_element_data(go_form, "formId", "couponRedemption");
17643
17773
  event("submit", go_form, redeem$1);
17644
17774
  append($$anchor, go_form);
17645
- pop();
17775
+ return pop($$exports);
17646
17776
  }
17647
- customElements.define("go-coupon-redemption", create_custom_element(CouponRedemption, {}, [], []));
17777
+ customElements.define("go-coupon-redemption", create_custom_element(CouponRedemption, {}, [], ["flush"]));
17778
+ enable_legacy_mode_flag();
17648
17779
  class GoDonation {
17649
17780
  #campaign = /* @__PURE__ */ state();
17650
17781
  get campaign() {
@@ -34582,11 +34713,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
34582
34713
  const personalizationDetails = /* @__PURE__ */ user_derived(() => _personalizationDetails.value);
34583
34714
  const _formDetails = getDetails$1($$props.$$host);
34584
34715
  const formDetails = /* @__PURE__ */ user_derived(() => _formDetails.value);
34716
+ const _cartView = getCartDetails($$props.$$host);
34717
+ const cartView = /* @__PURE__ */ user_derived(() => _cartView.value);
34585
34718
  let data = /* @__PURE__ */ user_derived(() => ({
34586
34719
  ticketSelection: get$2(ticketSelectionDetails),
34587
34720
  personalizationDetails: get$2(personalizationDetails),
34588
34721
  formData: get$2(formDetails)?.formData,
34589
- cart: shop.cart
34722
+ cart: shop.cart,
34723
+ cartView: get$2(cartView)
34590
34724
  }));
34591
34725
  const _setData = (_data) => {
34592
34726
  set(data, _data);