@gomusdev/web-components 1.52.0 → 1.53.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.
@@ -11229,10 +11229,17 @@ function createCartItem(product, options) {
11229
11229
  return this.type + "-" + this.product.id + this.subUId;
11230
11230
  },
11231
11231
  get subUId() {
11232
+ const segments = [];
11233
+ if (this.time) {
11234
+ segments.push(`time: ${this.time}`);
11235
+ }
11232
11236
  if (isUIScaledPricesTicket(this.product)) {
11233
- return ` (scale_price: ${this.product.scale_price_id})`;
11237
+ segments.push(`scale_price: ${this.product.scale_price_id}`);
11234
11238
  }
11235
- return "";
11239
+ if (this.display?.discounted) {
11240
+ segments.push("discounted");
11241
+ }
11242
+ return segments.length > 0 ? ` (${segments.join(", ")})` : "";
11236
11243
  },
11237
11244
  toString() {
11238
11245
  return this.uuid + ":" + this.quantity;
@@ -11261,11 +11268,6 @@ function createCartItem(product, options) {
11261
11268
  }
11262
11269
  };
11263
11270
  }
11264
- function updateLocalStorage(cart) {
11265
- const content = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11266
- localStorage.setItem("go-cart", content);
11267
- return content;
11268
- }
11269
11271
  function generateCartItem(cartItem) {
11270
11272
  const type = cartItem.type;
11271
11273
  switch (type) {
@@ -11315,27 +11317,21 @@ function loadFromLocalStorage$1(cart) {
11315
11317
  }
11316
11318
  function syncCartToLocalStorage(cart) {
11317
11319
  loadFromLocalStorage$1(cart);
11318
- const storeCart = proxy(cart);
11320
+ let lastWritten = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11321
+ localStorage.setItem("go-cart", lastWritten);
11319
11322
  effect_root(() => {
11320
11323
  user_effect(() => {
11321
- updateLocalStorage(storeCart);
11324
+ const content = JSON.stringify({ items: cart.items || [], coupons: cart.coupons || [] });
11325
+ if (content === lastWritten) return;
11326
+ lastWritten = content;
11327
+ localStorage.setItem("go-cart", content);
11322
11328
  });
11323
11329
  });
11324
- let lastLS = "";
11325
- setInterval(
11326
- () => {
11327
- if (!localStorage) {
11328
- console.warn("(syncCartToLocalStorage) localStorage is not available");
11329
- return;
11330
- }
11331
- let newLS = localStorage.getItem("go-cart");
11332
- if (lastLS && lastLS !== newLS) {
11333
- loadFromLocalStorage$1(cart);
11334
- }
11335
- lastLS = newLS || "";
11336
- },
11337
- 1e3
11338
- );
11330
+ window.addEventListener("storage", (event2) => {
11331
+ if (event2.key !== "go-cart") return;
11332
+ lastWritten = localStorage.getItem("go-cart") ?? "";
11333
+ loadFromLocalStorage$1(cart);
11334
+ });
11339
11335
  }
11340
11336
  const inTheFuture = (time2) => {
11341
11337
  const now = /* @__PURE__ */ new Date();
@@ -12619,6 +12615,9 @@ class Shop {
12619
12615
  checkout(params) {
12620
12616
  return this.apiPost(`/api/v4/orders`, { body: params, requiredFields: ["items", "total"] });
12621
12617
  }
12618
+ createCart(params) {
12619
+ return this.apiPost(`/api/v4/cart`, { body: params, requiredFields: ["items"] });
12620
+ }
12622
12621
  order(token) {
12623
12622
  return this.fetchAndCache("/api/v4/orders/{id}", `order-${token}`, "order", { path: { id: token } });
12624
12623
  }
@@ -16492,6 +16491,9 @@ class FormDetails {
16492
16491
  const ret = Object.fromEntries(validFields.map((f) => [f.apiKey, coerce2(f.value)]));
16493
16492
  return ret;
16494
16493
  }
16494
+ fieldValue(key) {
16495
+ return this.fields.find((f) => f.key === key)?.value;
16496
+ }
16495
16497
  get apiErrors() {
16496
16498
  return get$2(this.#apiErrors);
16497
16499
  }
@@ -16941,39 +16943,66 @@ function generateQuantityOptions(from, to, options = { floor: 0 }) {
16941
16943
  function option(value) {
16942
16944
  return { value, label: value.toString() };
16943
16945
  }
16944
- var root_5$1 = /* @__PURE__ */ from_html(`<span> </span>`);
16945
- var root_7$3 = /* @__PURE__ */ from_html(`<option> </option>`);
16946
- var root_6$2 = /* @__PURE__ */ from_html(`<select></select>`);
16947
- var root_8$2 = /* @__PURE__ */ from_html(`<li class="go-cart-item-remove" data-go-cart-item-remove=""><button>⨉</button></li>`);
16948
- var root_1$i = /* @__PURE__ */ from_html(`<article><ul><li data-go-cart-item-title=""><!></li> <li class="go-cart-item-price" data-go-cart-item-price=""> </li> <li class="go-cart-item-count" data-go-cart-item-count=""><!></li> <!> <li class="go-cart-item-sum" data-go-cart-item-sum=""> </li></ul></article>`);
16946
+ var root_5$2 = /* @__PURE__ */ from_html(`<s class="go-cart-item-price-original"> </s> <span class="go-cart-item-price-discounted"> </span>`, 1);
16947
+ var root_6$3 = /* @__PURE__ */ from_html(`<span class="go-cart-item-price-discounted"> </span>`);
16948
+ var root_7$4 = /* @__PURE__ */ from_html(`<span> </span>`);
16949
+ var root_9$4 = /* @__PURE__ */ from_html(`<option> </option>`);
16950
+ var root_8$2 = /* @__PURE__ */ from_html(`<select class="go-cart-item-select"></select>`);
16951
+ var root_10$2 = /* @__PURE__ */ from_html(`<li class="go-cart-item-remove"><button>⨉</button></li>`);
16952
+ 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>`);
16949
16953
  function Item$1($$anchor, $$props) {
16950
16954
  push($$props, true);
16951
- let cartItem = prop($$props, "cartItem", 7), cart = prop($$props, "cart", 7), preview = prop($$props, "preview", 7);
16955
+ let displayItem = prop($$props, "displayItem", 7), displayCart = prop($$props, "displayCart", 7), mainCart = prop($$props, "mainCart", 7), preview = prop($$props, "preview", 7);
16952
16956
  let capacity = /* @__PURE__ */ state(void 0);
16957
+ const itemInMaincart = /* @__PURE__ */ user_derived(() => mainCart().items.find((item) => item.uuid === displayItem().display?.reference_uuid));
16953
16958
  const emptyCart = createCart();
16954
16959
  user_effect(() => {
16955
- cart().items.map((i) => i.quantity);
16960
+ mainCart().items.map((i) => i.quantity);
16956
16961
  untrack(() => {
16957
- set(capacity, shop.capacityManager.capacity(cart(), cartItem(), emptyCart), true);
16962
+ set(capacity, shop.capacityManager.capacity(displayCart(), displayItem(), emptyCart), true);
16958
16963
  });
16959
16964
  });
16960
- function update(ci, target) {
16965
+ function update(target) {
16961
16966
  const el = target;
16962
- ci.quantity = parseInt(el.value);
16967
+ if (!get$2(itemInMaincart)) {
16968
+ console.error("(CartItem) Could not find main item for line", displayItem());
16969
+ return;
16970
+ }
16971
+ const nextLineQuantity = parseInt(el.value, 10);
16972
+ get$2(itemInMaincart).quantity = Math.max(0, get$2(itemInMaincart).quantity - displayItem().quantity + nextLineQuantity);
16973
+ }
16974
+ function del() {
16975
+ if (!get$2(itemInMaincart)) {
16976
+ console.error("(CartItem) Could not find main item for line", displayItem());
16977
+ return;
16978
+ }
16979
+ const newQuantity = Math.max(0, get$2(itemInMaincart).quantity - displayItem().quantity);
16980
+ if (newQuantity === 0) {
16981
+ mainCart().deleteItem(get$2(itemInMaincart));
16982
+ } else {
16983
+ get$2(itemInMaincart).quantity = newQuantity;
16984
+ }
16963
16985
  }
16964
16986
  var $$exports = {
16965
- get cartItem() {
16966
- return cartItem();
16987
+ get displayItem() {
16988
+ return displayItem();
16967
16989
  },
16968
- set cartItem($$value) {
16969
- cartItem($$value);
16990
+ set displayItem($$value) {
16991
+ displayItem($$value);
16992
+ flushSync();
16993
+ },
16994
+ get displayCart() {
16995
+ return displayCart();
16996
+ },
16997
+ set displayCart($$value) {
16998
+ displayCart($$value);
16970
16999
  flushSync();
16971
17000
  },
16972
- get cart() {
16973
- return cart();
17001
+ get mainCart() {
17002
+ return mainCart();
16974
17003
  },
16975
- set cart($$value) {
16976
- cart($$value);
17004
+ set mainCart($$value) {
17005
+ mainCart($$value);
16977
17006
  flushSync();
16978
17007
  },
16979
17008
  get preview() {
@@ -16987,7 +17016,7 @@ function Item$1($$anchor, $$props) {
16987
17016
  var fragment = comment();
16988
17017
  var node = first_child(fragment);
16989
17018
  {
16990
- var consequent_4 = ($$anchor2) => {
17019
+ var consequent_5 = ($$anchor2) => {
16991
17020
  var article = root_1$i();
16992
17021
  var ul = child(article);
16993
17022
  var li = child(ul);
@@ -16996,7 +17025,7 @@ function Item$1($$anchor, $$props) {
16996
17025
  var consequent = ($$anchor3) => {
16997
17026
  Ticket($$anchor3, {
16998
17027
  get cartItem() {
16999
- return cartItem();
17028
+ return displayItem();
17000
17029
  }
17001
17030
  });
17002
17031
  };
@@ -17007,14 +17036,14 @@ function Item$1($$anchor, $$props) {
17007
17036
  var consequent_1 = ($$anchor4) => {
17008
17037
  Event$2($$anchor4, {
17009
17038
  get cartItem() {
17010
- return cartItem();
17039
+ return displayItem();
17011
17040
  }
17012
17041
  });
17013
17042
  };
17014
17043
  if_block(
17015
17044
  node_2,
17016
17045
  ($$render) => {
17017
- if (cartItem().product.product_type === "Event") $$render(consequent_1);
17046
+ if (displayItem().product.product_type === "Event") $$render(consequent_1);
17018
17047
  },
17019
17048
  true
17020
17049
  );
@@ -17022,35 +17051,68 @@ function Item$1($$anchor, $$props) {
17022
17051
  append($$anchor3, fragment_2);
17023
17052
  };
17024
17053
  if_block(node_1, ($$render) => {
17025
- if (cartItem().product.product_type === "Ticket") $$render(consequent);
17054
+ if (displayItem().product.product_type === "Ticket") $$render(consequent);
17026
17055
  else $$render(alternate, false);
17027
17056
  });
17028
17057
  }
17029
17058
  reset(li);
17030
17059
  var li_1 = sibling(li, 2);
17031
- var text2 = child(li_1, true);
17032
- reset(li_1);
17033
- var li_2 = sibling(li_1, 2);
17034
- var node_3 = child(li_2);
17060
+ var node_3 = child(li_1);
17035
17061
  {
17036
17062
  var consequent_2 = ($$anchor3) => {
17037
- var span = root_5$1();
17063
+ var fragment_4 = root_5$2();
17064
+ var s = first_child(fragment_4);
17065
+ var text2 = child(s, true);
17066
+ reset(s);
17067
+ var span = sibling(s, 2);
17038
17068
  var text_1 = child(span, true);
17039
17069
  reset(span);
17040
- template_effect(() => set_text(text_1, cartItem().quantity));
17041
- append($$anchor3, span);
17070
+ template_effect(
17071
+ ($0, $1) => {
17072
+ set_text(text2, $0);
17073
+ set_text(text_1, $1);
17074
+ },
17075
+ [
17076
+ () => formatCurrency(displayItem().display.originalPrice),
17077
+ () => formatCurrency(displayItem().final_price_cents)
17078
+ ]
17079
+ );
17080
+ append($$anchor3, fragment_4);
17042
17081
  };
17043
17082
  var alternate_1 = ($$anchor3) => {
17044
- var select = root_6$2();
17045
- select.__change = (e) => update(cartItem(), e.target);
17083
+ var span_1 = root_6$3();
17084
+ var text_2 = child(span_1, true);
17085
+ reset(span_1);
17086
+ template_effect(($0) => set_text(text_2, $0), [() => formatCurrency(displayItem().final_price_cents)]);
17087
+ append($$anchor3, span_1);
17088
+ };
17089
+ if_block(node_3, ($$render) => {
17090
+ if (displayItem().display?.discounted) $$render(consequent_2);
17091
+ else $$render(alternate_1, false);
17092
+ });
17093
+ }
17094
+ reset(li_1);
17095
+ var li_2 = sibling(li_1, 2);
17096
+ var node_4 = child(li_2);
17097
+ {
17098
+ var consequent_3 = ($$anchor3) => {
17099
+ var span_2 = root_7$4();
17100
+ var text_3 = child(span_2, true);
17101
+ reset(span_2);
17102
+ template_effect(() => set_text(text_3, displayItem().quantity));
17103
+ append($$anchor3, span_2);
17104
+ };
17105
+ var alternate_2 = ($$anchor3) => {
17106
+ var select = root_8$2();
17107
+ select.__change = (e) => update(e.target);
17046
17108
  each(select, 21, () => generateQuantityOptions(get$2(capacity).min, get$2(capacity).max, { floor: 1 }), (q) => q.value, ($$anchor4, q) => {
17047
- var option2 = root_7$3();
17048
- var text_2 = child(option2, true);
17109
+ var option2 = root_9$4();
17110
+ var text_4 = child(option2, true);
17049
17111
  reset(option2);
17050
17112
  var option_value = {};
17051
17113
  template_effect(() => {
17052
- set_selected(option2, cartItem().quantity === get$2(q).value);
17053
- set_text(text_2, get$2(q).label);
17114
+ set_selected(option2, displayItem().quantity === get$2(q).value);
17115
+ set_text(text_4, get$2(q).label);
17054
17116
  if (option_value !== (option_value = get$2(q).value)) {
17055
17117
  option2.value = (option2.__value = get$2(q).value) ?? "";
17056
17118
  }
@@ -17058,56 +17120,143 @@ function Item$1($$anchor, $$props) {
17058
17120
  append($$anchor4, option2);
17059
17121
  });
17060
17122
  reset(select);
17123
+ template_effect(($0) => set_attribute(select, "aria-label", $0), [() => shop.t("cart.content.table.edit")]);
17061
17124
  append($$anchor3, select);
17062
17125
  };
17063
- if_block(node_3, ($$render) => {
17064
- if (preview()) $$render(consequent_2);
17065
- else $$render(alternate_1, false);
17126
+ if_block(node_4, ($$render) => {
17127
+ if (preview()) $$render(consequent_3);
17128
+ else $$render(alternate_2, false);
17066
17129
  });
17067
17130
  }
17068
17131
  reset(li_2);
17069
- var node_4 = sibling(li_2, 2);
17132
+ var node_5 = sibling(li_2, 2);
17070
17133
  {
17071
- var consequent_3 = ($$anchor3) => {
17072
- var li_3 = root_8$2();
17134
+ var consequent_4 = ($$anchor3) => {
17135
+ var li_3 = root_10$2();
17073
17136
  var button = child(li_3);
17074
- button.__click = () => cart().deleteItem(cartItem());
17137
+ button.__click = del;
17075
17138
  reset(li_3);
17076
17139
  append($$anchor3, li_3);
17077
17140
  };
17078
- if_block(node_4, ($$render) => {
17079
- if (!preview()) $$render(consequent_3);
17141
+ if_block(node_5, ($$render) => {
17142
+ if (!preview()) $$render(consequent_4);
17080
17143
  });
17081
17144
  }
17082
- var li_4 = sibling(node_4, 2);
17083
- var text_3 = child(li_4, true);
17145
+ var li_4 = sibling(node_5, 2);
17146
+ var text_5 = child(li_4, true);
17084
17147
  reset(li_4);
17085
17148
  reset(ul);
17086
17149
  reset(article);
17087
- template_effect(() => {
17088
- set_attribute(article, "data-testid", cartItem().uuid);
17089
- set_text(text2, cartItem().final_price_formatted);
17090
- set_text(text_3, cartItem().total_price_formatted);
17091
- });
17150
+ template_effect(($0) => set_text(text_5, $0), [() => formatCurrency(displayItem().total_price_cents)]);
17092
17151
  append($$anchor2, article);
17093
17152
  };
17094
17153
  if_block(node, ($$render) => {
17095
- if (get$2(capacity)) $$render(consequent_4);
17154
+ if (get$2(capacity)) $$render(consequent_5);
17096
17155
  });
17097
17156
  }
17098
17157
  append($$anchor, fragment);
17099
17158
  return pop($$exports);
17100
17159
  }
17101
17160
  delegate(["change", "click"]);
17102
- create_custom_element(Item$1, { cartItem: {}, cart: {}, preview: {} }, [], [], { mode: "open" });
17103
- var root_2$p = /* @__PURE__ */ from_html(`<li class="go-cart-header-remove" data-go-cart-header-remove=""></li>`);
17104
- var root_3$8 = /* @__PURE__ */ from_html(`<li class="go-cart-item" data-go-cart-item=""><!></li>`);
17105
- var root_4$6 = /* @__PURE__ */ from_html(`<li class="go-cart-footer-remove" data-go-cart-footer-remove=""></li>`);
17106
- var root_1$h = /* @__PURE__ */ from_html(`<ol data-testid="cart"><li class="go-cart-header" data-go-cart-header="" data-testid="cart-header"><ul><li class="go-cart-header-title" data-go-cart-header-title=""> </li> <li class="go-cart-header-price" data-go-cart-header-price=""> </li> <li class="go-cart-header-count" data-go-cart-header-count=""> </li> <!> <li class="go-cart-header-sum" data-go-cart-header-sum=""> </li></ul></li> <!> <li class="go-cart-footer" data-go-cart-footer="" data-testid="cart-footer"><ul><li class="go-cart-footer-title" data-go-cart-footer-title=""></li> <li class="go-cart-footer-price" data-go-cart-footer-price=""></li> <li class="go-cart-footer-count" data-go-cart-footer-count=""></li> <!> <li class="go-cart-footer-sum" data-go-cart-footer-sum="" data-go-cart-sum=""> </li></ul></li></ol>`);
17161
+ create_custom_element(Item$1, { displayItem: {}, displayCart: {}, mainCart: {}, preview: {} }, [], [], { mode: "open" });
17162
+ function getQuantity(value, fallback) {
17163
+ if (typeof value === "number" && Number.isFinite(value)) return value;
17164
+ if (value && typeof value === "object") {
17165
+ const total = Object.values(value).reduce((sum2, num) => {
17166
+ return typeof num === "number" && Number.isFinite(num) ? sum2 + num : sum2;
17167
+ }, 0);
17168
+ if (total > 0) return total;
17169
+ }
17170
+ return fallback;
17171
+ }
17172
+ function createDisplayCart(baseCart, apiItems) {
17173
+ const displayCart = createCart();
17174
+ const appliedCoupons = /* @__PURE__ */ new Set();
17175
+ baseCart.coupons.forEach((coupon) => displayCart.addCoupon(coupon));
17176
+ apiItems.forEach((apiItem) => {
17177
+ const attrs = apiItem.attributes;
17178
+ const itemInBaseCart = baseCart.items.find(
17179
+ (i) => i.type.toLowerCase() === apiItem.type.toLowerCase() && i.product.id === attrs.id && (!attrs.time || i.time === attrs.time)
17180
+ );
17181
+ if (!itemInBaseCart) {
17182
+ console.error("(go-cart) Ignoring unmatched cart line", { type: apiItem.type, attrs });
17183
+ return [];
17184
+ }
17185
+ if (attrs.coupon) {
17186
+ displayCart.addCoupon(attrs.coupon);
17187
+ appliedCoupons.add(attrs.coupon);
17188
+ }
17189
+ displayCart.addItem(createDisplayCartItem(itemInBaseCart, attrs));
17190
+ });
17191
+ return { cart: displayCart, appliedCoupons };
17192
+ }
17193
+ function resolveApiQuantity(attrs) {
17194
+ const source2 = "quantity" in attrs && attrs.quantity !== void 0 ? attrs.quantity : attrs.quantities;
17195
+ return getQuantity(source2, 0);
17196
+ }
17197
+ function createDisplayCartItem(cartItem, attrs) {
17198
+ const quantity = resolveApiQuantity(attrs);
17199
+ const displayPrice = attrs.price_cents ?? cartItem.product.price_cents;
17200
+ const originalPrice = cartItem.product.price_cents;
17201
+ const discounted = displayPrice < originalPrice;
17202
+ const product = { ...cartItem.product, price_cents: displayPrice };
17203
+ return createCartItem(product, {
17204
+ quantity,
17205
+ time: cartItem.time,
17206
+ display: {
17207
+ discounted,
17208
+ reference_uuid: cartItem.uuid,
17209
+ originalPrice
17210
+ }
17211
+ });
17212
+ }
17213
+ var root_2$p = /* @__PURE__ */ from_html(`<li class="go-cart-header-remove"></li>`);
17214
+ var root_3$8 = /* @__PURE__ */ from_html(`<li class="go-cart-item"><!></li>`);
17215
+ var root_6$2 = /* @__PURE__ */ from_html(`<li class="go-cart-item-remove"><button>⨉</button></li>`);
17216
+ 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>`);
17217
+ var root_7$3 = /* @__PURE__ */ from_html(`<li class="go-cart-footer-remove"></li>`);
17218
+ 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>`);
17107
17219
  function Cart($$anchor, $$props) {
17108
17220
  push($$props, true);
17109
17221
  const preview = prop($$props, "preview", 7, false);
17110
17222
  let cart = /* @__PURE__ */ user_derived(() => shop.cart);
17223
+ let displayCart = /* @__PURE__ */ state(proxy(get$2(cart)));
17224
+ let appliedCoupons = /* @__PURE__ */ state(proxy(/* @__PURE__ */ new Set()));
17225
+ let requestId = 0;
17226
+ const displayTotalCents = /* @__PURE__ */ user_derived(() => get$2(displayCart)?.totalPriceCents ?? 0);
17227
+ user_effect(() => {
17228
+ if (!get$2(cart)) {
17229
+ return;
17230
+ }
17231
+ get$2(cart).items.map((i) => i.uuid + ":" + i.quantity + ":" + i.time);
17232
+ get$2(cart).coupons.join("|");
17233
+ const currentRequest = ++requestId;
17234
+ if (get$2(cart).items.length === 0) {
17235
+ set(displayCart, get$2(cart), true);
17236
+ return;
17237
+ }
17238
+ (async () => {
17239
+ try {
17240
+ const { items, coupons } = get$2(cart).orderData();
17241
+ const response = await shop.createCart({ items, coupons });
17242
+ if (currentRequest !== requestId || !get$2(cart)) return;
17243
+ if (!response || "error" in response) {
17244
+ if (response && "error" in response) {
17245
+ console.error("(go-cart) Unable to fetch discounted cart data", response.error);
17246
+ }
17247
+ set(displayCart, get$2(cart), true);
17248
+ return;
17249
+ }
17250
+ const result = createDisplayCart(get$2(cart), response.data.items ?? []);
17251
+ set(displayCart, result.cart, true);
17252
+ set(appliedCoupons, result.appliedCoupons, true);
17253
+ } catch (error) {
17254
+ console.error("(go-cart) Unable to fetch discounted cart data", error);
17255
+ if (currentRequest !== requestId || !get$2(cart)) return;
17256
+ set(displayCart, get$2(cart), true);
17257
+ }
17258
+ })();
17259
+ });
17111
17260
  var $$exports = {
17112
17261
  get preview() {
17113
17262
  return preview();
@@ -17120,7 +17269,7 @@ function Cart($$anchor, $$props) {
17120
17269
  var fragment = comment();
17121
17270
  var node = first_child(fragment);
17122
17271
  {
17123
- var consequent_2 = ($$anchor2) => {
17272
+ var consequent_4 = ($$anchor2) => {
17124
17273
  var ol = root_1$h();
17125
17274
  var li = child(ol);
17126
17275
  var ul = child(li);
@@ -17149,14 +17298,17 @@ function Cart($$anchor, $$props) {
17149
17298
  reset(ul);
17150
17299
  reset(li);
17151
17300
  var node_2 = sibling(li, 2);
17152
- each(node_2, 17, () => get$2(cart).items, (cartItem) => cartItem.uuid, ($$anchor3, cartItem) => {
17301
+ each(node_2, 17, () => get$2(displayCart).items, (item) => item.uuid, ($$anchor3, item) => {
17153
17302
  var li_6 = root_3$8();
17154
17303
  var node_3 = child(li_6);
17155
17304
  Item$1(node_3, {
17156
- get cartItem() {
17157
- return get$2(cartItem);
17305
+ get displayItem() {
17306
+ return get$2(item);
17158
17307
  },
17159
- get cart() {
17308
+ get displayCart() {
17309
+ return get$2(displayCart);
17310
+ },
17311
+ get mainCart() {
17160
17312
  return get$2(cart);
17161
17313
  },
17162
17314
  get preview() {
@@ -17166,48 +17318,99 @@ function Cart($$anchor, $$props) {
17166
17318
  reset(li_6);
17167
17319
  append($$anchor3, li_6);
17168
17320
  });
17169
- var li_7 = sibling(node_2, 2);
17170
- var ul_1 = child(li_7);
17171
- var node_4 = sibling(child(ul_1), 6);
17321
+ var node_4 = sibling(node_2, 2);
17172
17322
  {
17173
- var consequent_1 = ($$anchor3) => {
17174
- var li_8 = root_4$6();
17175
- append($$anchor3, li_8);
17323
+ var consequent_2 = ($$anchor3) => {
17324
+ var fragment_1 = comment();
17325
+ var node_5 = first_child(fragment_1);
17326
+ each(node_5, 16, () => get$2(displayCart).coupons, (coupon) => coupon, ($$anchor4, coupon) => {
17327
+ var li_7 = root_5$1();
17328
+ let classes;
17329
+ var article = child(li_7);
17330
+ var ul_1 = child(article);
17331
+ var li_8 = child(ul_1);
17332
+ var text_4 = child(li_8, true);
17333
+ reset(li_8);
17334
+ var node_6 = sibling(li_8, 6);
17335
+ {
17336
+ var consequent_1 = ($$anchor5) => {
17337
+ var li_9 = root_6$2();
17338
+ var button = child(li_9);
17339
+ button.__click = () => get$2(cart)?.removeCoupon(coupon);
17340
+ reset(li_9);
17341
+ append($$anchor5, li_9);
17342
+ };
17343
+ if_block(node_6, ($$render) => {
17344
+ if (!preview()) $$render(consequent_1);
17345
+ });
17346
+ }
17347
+ next(2);
17348
+ reset(ul_1);
17349
+ reset(article);
17350
+ reset(li_7);
17351
+ template_effect(
17352
+ ($0) => {
17353
+ classes = set_class(li_7, 1, "go-cart-item", null, classes, $0);
17354
+ set_text(text_4, coupon);
17355
+ },
17356
+ [
17357
+ () => ({
17358
+ "go-cart-coupon-inactive": !get$2(appliedCoupons).has(coupon)
17359
+ })
17360
+ ]
17361
+ );
17362
+ append($$anchor4, li_7);
17363
+ });
17364
+ append($$anchor3, fragment_1);
17176
17365
  };
17177
17366
  if_block(node_4, ($$render) => {
17178
- if (!preview()) $$render(consequent_1);
17367
+ if (get$2(displayCart).coupons.length > 0) $$render(consequent_2);
17179
17368
  });
17180
17369
  }
17181
- var li_9 = sibling(node_4, 2);
17182
- var text_4 = child(li_9, true);
17183
- reset(li_9);
17184
- reset(ul_1);
17185
- reset(li_7);
17370
+ var li_10 = sibling(node_4, 2);
17371
+ var ul_2 = child(li_10);
17372
+ var node_7 = sibling(child(ul_2), 6);
17373
+ {
17374
+ var consequent_3 = ($$anchor3) => {
17375
+ var li_11 = root_7$3();
17376
+ append($$anchor3, li_11);
17377
+ };
17378
+ if_block(node_7, ($$render) => {
17379
+ if (!preview()) $$render(consequent_3);
17380
+ });
17381
+ }
17382
+ var li_12 = sibling(node_7, 2);
17383
+ var text_5 = child(li_12, true);
17384
+ reset(li_12);
17385
+ reset(ul_2);
17386
+ reset(li_10);
17186
17387
  reset(ol);
17187
17388
  template_effect(
17188
- ($0, $1, $2, $3) => {
17389
+ ($0, $1, $2, $3, $4) => {
17189
17390
  set_text(text2, $0);
17190
17391
  set_text(text_1, $1);
17191
17392
  set_text(text_2, $2);
17192
17393
  set_text(text_3, $3);
17193
- set_text(text_4, get$2(cart).totalFormatted);
17394
+ set_text(text_5, $4);
17194
17395
  },
17195
17396
  [
17196
17397
  () => shop.t("cart.content.table.desc"),
17197
17398
  () => shop.t("cart.content.table.price"),
17198
17399
  () => shop.t("cart.content.table.quantity"),
17199
- () => shop.t("cart.content.table.total")
17400
+ () => shop.t("cart.content.table.total"),
17401
+ () => formatCurrency(get$2(displayTotalCents))
17200
17402
  ]
17201
17403
  );
17202
17404
  append($$anchor2, ol);
17203
17405
  };
17204
17406
  if_block(node, ($$render) => {
17205
- if (get$2(cart) && get$2(cart).items.length) $$render(consequent_2);
17407
+ if (get$2(displayCart) && get$2(displayCart).items.length) $$render(consequent_4);
17206
17408
  });
17207
17409
  }
17208
17410
  append($$anchor, fragment);
17209
17411
  return pop($$exports);
17210
17412
  }
17413
+ delegate(["click"]);
17211
17414
  customElements.define("go-cart", create_custom_element(Cart, { preview: {} }, [], []));
17212
17415
  function CartEmpty($$anchor, $$props) {
17213
17416
  push($$props, true);
@@ -17274,41 +17477,43 @@ function CheckoutForm($$anchor, $$props) {
17274
17477
  }
17275
17478
  customElements.define("go-checkout-form", create_custom_element(CheckoutForm, { custom: {} }, [], []));
17276
17479
  enable_legacy_mode_flag();
17277
- async function redeem(form) {
17278
- if (!form) {
17279
- throw new Error("(go-coupon-redemption): form not found");
17280
- }
17480
+ const APPLY_ORDER_DISCOUNT = "TokenActions::ApplyOrderDiscount";
17481
+ async function redeem(token) {
17281
17482
  if (!shop.cart) {
17282
17483
  throw new Error("(go-coupon-redemption): cart not found");
17283
17484
  }
17284
- const result = await shop.asyncFetch(() => shop.getCouponSaleByBarcode(form.details.formData.id));
17285
- if (result?.is_valid && result.is_voucher_for) {
17286
- const tickets = await shop.asyncFetch(
17287
- () => shop.tickets({
17288
- // @ts-ignore - api supports filter even if schema doesn't yet.
17289
- "by_ticket_ids[]": [result.is_voucher_for]
17290
- })
17291
- );
17292
- const ticket = tickets.find((t) => t.id === result.is_voucher_for);
17293
- if (!ticket) {
17294
- form.details.apiErrors ??= [];
17295
- form.details.apiErrors = [shop.t("cart.coupon.form.errors.error")];
17296
- return;
17297
- }
17298
- const voucherTicket = { ...ticket, price_cents: 0 };
17299
- shop.cart.addItem(createCartItem(createUITicket(voucherTicket), { quantity: 1 }));
17300
- const token = form.details.formData.id;
17485
+ const couponSale = await shop.asyncFetch(() => shop.getCouponSaleByBarcode(token));
17486
+ if (!couponSale?.is_valid) {
17487
+ return fail([shop.t("cart.coupon.form.errors.notValid")]);
17488
+ }
17489
+ if (couponSale.value_action === APPLY_ORDER_DISCOUNT) {
17301
17490
  shop.cart.addCoupon(token);
17302
- const tokenField = form.details.fields.find((f) => f.key === "token");
17303
- if (tokenField) {
17304
- tokenField.value = "";
17305
- form.dispatchEvent(new Event("go-success", { bubbles: true, composed: true }));
17306
- }
17491
+ return { success: true };
17492
+ } else if (couponSale.is_voucher_for) {
17493
+ return applyVoucher(token, couponSale);
17307
17494
  } else {
17308
- form.details.apiErrors ??= [];
17309
- form.details.apiErrors = [shop.t("cart.coupon.form.errors.notValid")];
17495
+ return fail([shop.t("cart.coupon.form.errors.notValid")]);
17310
17496
  }
17311
17497
  }
17498
+ async function applyVoucher(token, couponSale) {
17499
+ const tickets = await shop.asyncFetch(
17500
+ () => shop.tickets({
17501
+ // @ts-ignore - api supports filter even if schema doesn't yet.
17502
+ "by_ticket_ids[]": [couponSale.is_voucher_for]
17503
+ })
17504
+ );
17505
+ const ticket = tickets.find((t) => t.id === couponSale.is_voucher_for);
17506
+ if (!ticket) {
17507
+ return fail([shop.t("cart.coupon.form.errors.error")]);
17508
+ }
17509
+ const voucherTicket = { ...ticket, price_cents: 0 };
17510
+ shop.cart.addItem(createCartItem(createUITicket(voucherTicket), { quantity: 1 }));
17511
+ shop.cart.addCoupon(token);
17512
+ return { success: true };
17513
+ }
17514
+ function fail(errors2) {
17515
+ return { success: false, errors: errors2 };
17516
+ }
17312
17517
  var root$a = /* @__PURE__ */ from_html(`<go-form></go-form>`, 2);
17313
17518
  function CouponRedemption($$anchor, $$props) {
17314
17519
  push($$props, false);
@@ -17317,8 +17522,17 @@ function CouponRedemption($$anchor, $$props) {
17317
17522
  submitLabel: "cart.coupon.form.submit",
17318
17523
  fields: [{ key: "token", required: true }]
17319
17524
  });
17320
- async function redeem$1(e) {
17321
- await redeem(e.target);
17525
+ async function redeem$1(event2) {
17526
+ const form = event2.target;
17527
+ const field = form.details.fields.find((f) => f.key === "token");
17528
+ const token = form.details.fieldValue("token").trim();
17529
+ const result = await redeem(token);
17530
+ if (!result.success) {
17531
+ form.details.apiErrors = result.errors;
17532
+ return;
17533
+ }
17534
+ field.value = "";
17535
+ form.dispatchEvent(new Event("go-success", { bubbles: true, composed: true }));
17322
17536
  }
17323
17537
  init();
17324
17538
  var go_form = root$a();
@@ -33563,7 +33777,7 @@ function berlinNowISO() {
33563
33777
  }
33564
33778
  var root_1$3 = /* @__PURE__ */ from_html(`<span class="go-tickets-item-title-event-title"> </span> <span class="go-tickets-item-title-product-title"> </span>`, 1);
33565
33779
  var root_4 = /* @__PURE__ */ from_html(`<option> </option>`);
33566
- var root_3$1 = /* @__PURE__ */ from_html(`<li><article><ul><li class="go-tickets-item-title"><!></li> <li class="go-tickets-item-description" data-go-tickets-description=""><!></li> <li class="go-tickets-item-price" data-go-tickets-price=""> </li> <li class="go-tickets-item-quality" data-go-tickets-quality=""><select></select></li></ul></article></li>`);
33780
+ var root_3$1 = /* @__PURE__ */ from_html(`<li><article><ul><li class="go-tickets-item-title"><!></li> <li class="go-tickets-item-description" data-go-tickets-description=""><!></li> <li class="go-tickets-item-price" data-go-tickets-price=""> </li> <li class="go-tickets-item-quality" data-go-tickets-quality=""><select class="go-tickets-item-select"></select></li></ul></article></li>`);
33567
33781
  function Item($$anchor, $$props) {
33568
33782
  push($$props, true);
33569
33783
  const scaled_title = ($$anchor2) => {
@@ -33660,14 +33874,18 @@ function Item($$anchor, $$props) {
33660
33874
  reset(ul);
33661
33875
  reset(article);
33662
33876
  reset(li);
33663
- template_effect(() => {
33664
- set_class(article, 1, clsx([
33665
- "go-tickets-item",
33666
- get$2(capacity).bookedOut && "is-booked-out"
33667
- ]));
33668
- set_attribute(article, "data-testid", item().uuid);
33669
- set_text(text_3, item().price_formatted);
33670
- });
33877
+ template_effect(
33878
+ ($0) => {
33879
+ set_class(article, 1, clsx([
33880
+ "go-tickets-item",
33881
+ get$2(capacity).bookedOut && "is-booked-out"
33882
+ ]));
33883
+ set_attribute(article, "data-testid", item().uuid);
33884
+ set_text(text_3, item().price_formatted);
33885
+ set_attribute(select, "aria-label", $0);
33886
+ },
33887
+ [() => shop.t("cart.content.table.edit")]
33888
+ );
33671
33889
  append($$anchor2, li);
33672
33890
  };
33673
33891
  if_block(node, ($$render) => {
@@ -34223,7 +34441,6 @@ function Calendar_1($$anchor, $$props) {
34223
34441
  }
34224
34442
  });
34225
34443
  $$props.$$host.addEventListener("go-date-select", (e) => {
34226
- console.log("calendar selected date", e.detail.selected);
34227
34444
  if (get$2(ticketSelectionDetails)) {
34228
34445
  get$2(ticketSelectionDetails).selectedDate = e.detail.selected;
34229
34446
  get$2(ticketSelectionDetails).selectedTimeslot = void 0;