1var g=(t,i,e)=>new Promise((o,n)=>{var c=r=>{try{s(e.next(r))}catch(u){n(u)}},a=r=>{try{s(e.throw(r))}catch(u){n(u)}},s=r=>r.done?o(r.value):Promise.resolve(r.value).then(c,a);s((e=e.apply(t,i)).next())});import{l as y}from"./logger-pamvzmAu.js";import I from"./custom-html-element-Cddc4xm8.js";import{A as p}from"./customer-portal-R96TstYq.js";import{g as _,a as b,f as C}from"./redirection-modal-CNuhsO_W.js";import"./exports-NHIMKJG4.js";import"./event-zU-Y6ZHH.js";const w=class extends I{constructor(){super(),this._debounceTimeout=null,this._isUpdating=!1,this._onCartRefresh=this._onCartRefresh.bind(this),this._onQuantityChanged=this._onQuantityChanged.bind(this),this._handleEnterKey=this._handleEnterKey.bind(this)}connectedCallback(){var t,i;this._removeButtonElements=Array.from(this.querySelectorAll(".js-remove-item")),this._quantitySelectorEl=this.querySelector("quantity-selector"),this._quantityInputEl=(t=this._quantitySelectorEl)==null?void 0:t.querySelector("[data-input]"),this.delegate.on("change","quantity-selector",this._onQuantityChanged.bind(this)),this.delegate.on("click",".js-remove-item",this._onRemoveItem.bind(this)),(i=this._quantityInputEl)==null||i.addEventListener("keydown",this._handleEnterKey),document.addEventListener("cart:refresh",this._onCartRefresh.bind(this))}disconnectedCallback(){this._debounceTimeout&&(clearTimeout(this._debounceTimeout),this._debounceTimeout=null),this._quantityInputEl&&this._handleEnterKey&&(this._quantityInputEl.removeEventListener("keydown",this._handleEnterKey),this._quantityInputEl=null),super.disconnectedCallback()}_handleEnterKey(t){t.key==="Enter"&&(t.preventDefault(),t.target.blur())}_onQuantityChanged(t,i){if(this._isUpdating){y.info("Cart update in progress, ignoring quantity change");return}const e=t.detail.value,o=i.getAttribute("data-line")||this.getAttribute("data-line"),n=i.getAttribute("data-key")||this.getAttribute("data-key");this._debounceTimeout&&clearTimeout(this._debounceTimeout),this._debounceTimeout=setTimeout(()=>{this._updateCartQuantity(o,n,e)},450)}_onRemoveItem(t,i){if(this._isUpdating){y.info("Cart update in progress, ignoring remove action");return}const e=i.getAttribute("data-line")||this.getAttribute("data-line"),o=i.getAttribute("data-key")||this.getAttribute("data-key");this._updateCartQuantity(e,o,0)}_updateCartQuantity(t,i,e){return g(this,null,function*(){var o,n;this._isUpdating=!0,this._showLoadingOnInteractiveElement(!0);try{const c=_("flyout-cart,main-cart"),a=yield fetch(`${window.themeVariables.routes.cartChangeUrl}.js`,{body:JSON.stringify({line:t,id:i,quantity:e,sections:[...c.split(",")]}),credentials:"same-origin",method:"POST",headers:{"Content-Type":"application/json"}}),s=yield a.json();if(a.ok){const r=yield this._removeIneligibleTieredFreeItems(s),u=r!=null?r:s;if(!r){let m={};if(e===0){const l=this.closest(".js-line-item");if(l){const h=((o=s.item_count)!=null?o:0)===0||!((n=s.items)!=null&&n.length);m={removedLineItem:l,isLastItem:h}}}b(s),document.documentElement.dispatchEvent(new CustomEvent("sections:updated",{bubbles:!0,detail:{sections:s.sections||{},animationData:m}}))}const d=document.activeElement,f=d&&d!==document.body;setTimeout(()=>{this._updateAllCartLineItemQuantities(u),setTimeout(()=>{const m=document.activeElement,l=m&&m!==document.body;if(f&&!l||e===0){const h=document.getElementById("flyout-cart-title")||document.getElementById("main-cart-title");h&&h.focus()}},50)},100)}else{const r=s.description||s.message||"Failed to update cart quantity",u=document.getElementById("cart-alerts-container");p.announce(r,{assertive:!0,clearAfter:-1,target:u})}}catch(c){const a=document.getElementById("cart-alerts-container");p.announce("Unable to update cart. Please try again.",{assertive:!0,clearAfter:-1,target:a}),y.error("Error updating cart:",c)}finally{this._isUpdating=!1,this._showLoadingOnInteractiveElement(!1)}})}_removeIneligibleTieredFreeItems(t){return g(this,null,function*(){var i,e,o;try{if(!t)return null;let n=null;if(Array.isArray(t.items)?n=t:t.cart&&Array.isArray((i=t.cart)==null?void 0:i.items)&&(n=t.cart),!n||!((e=n.items)!=null&&e.length))return null;const a=n.items.filter(l=>{var h;
1return l.properties&&((h=l.final_price)!=null?h:0)>0&&Object.entries(l.properties).some(([E,v])=>E==="__ucd"&&v==="Tiered Free Items")});if(!a.length)return null;const s=_("flyout-cart,main-cart"),r=Object.fromEntries(a.map(l=>[l.key,0])),u=yield fetch(`${window.themeVariables.routes.cartUpdateUrl}.js`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:r,sections:s})}),d=yield u.json();if(!u.ok)return y.error("Failed to remove Tiered Free Items from cart",d),null;const f=d.items!=null?d:yield C();b(f);const m=(o=d.sections)!=null?o:yield(yield fetch(`/?sections=${s}`)).json();return document.documentElement.dispatchEvent(new CustomEvent("sections:updated",{bubbles:!0,detail:{sections:m,animationData:{}}})),f}catch(n){return y.error("Error while trying to remove Tiered Free Items from cart",n),null}})}_updateAllCartLineItemQuantities(t){const i=document.querySelectorAll("cart-line-item-quantity");!t.items||!i.length||i.forEach(e=>{const o=e.getAttribute("data-line"),n=e.getAttribute("data-key");if(!o||!n)return;const c=t.items.find(a=>a.key.toString()===n.toString());if(c){const a=e.querySelector("quantity-selector");if(a){e._isUpdating=!0,a.setAttribute("value",c.quantity);const s=a.querySelector("[data-input]");s&&(s.value=c.quantity),setTimeout(()=>{e._isUpdating=!1,e._showLoadingOnInteractiveElement(!1)},50)}}})}_onCartRefresh(t){if(this._isUpdating){y.info("Cart update in progress, ignoring refresh event");return}const i=document.activeElement,e=i&&i!==document.body,o=t.detail.cart;setTimeout(()=>{this._updateAllCartLineItemQuantities(o),setTimeout(()=>{const n=document.activeElement,c=n&&n!==document.body;if(e&&!c){const a=document.getElementById("flyout-cart-title");a&&a.focus()}},50)},100)}_showLoadingOnInteractiveElement(t=!0){[this._quantitySelectorEl,...this._removeButtonElements].filter(Boolean).forEach(e=>{e.setAttribute("aria-busy",t?"true":"false")})}};window.customElements.get("cart-line-item-quantity")||window.customElements.define("cart-line-item-quantity",w);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.