1import{G as S}from"./global-events.CQo4HGo3.min.js";import{h as u,c as l,f as h}from"./fetch.C4dKww5L.min.js";import"./global-notice.CVb_C_1g.min.js";const a=class a extends EventTarget{constructor(){super(),this.cart=null,this.domParser=new DOMParser,this.cartSectionId="",this.handleStoreRegionSelected=async()=>{if(this.cart?.items?.length)try{await this.clearCart()}catch(t){u(t)}}}connectedCallback(){this.slideout=document.querySelector("cart-slideout"),this.cartPageSection=document.querySelector("[data-cart-page]"),this.cartSectionId=this.slideout?.id||"",this.getCart().catch(u),document.addEventListener(S.storeRegion.selected,this.handleStoreRegionSelected)}static getInstance(){return a.instance||(a.instance=new a,a.instance.connectedCallback()),a.instance}openSlideout(){document.dispatchEvent(new CustomEvent(S.cart.open,{bubbles:!0}))}getCartSectionsToBeRerendered(){const t=[this.cartSectionId];return this.cartPageSection?.id&&t.push(this.cartPageSection.id),t.filter(Boolean)}rerenderCartSections(t){this.getCartSectionsToBeRerendered().forEach(e=>{const r=t.sections[e];if(!r)return;const o=this.domParser.parseFromString(r,"text/html"),n=document.getElementById(e),c=o.getElementById(e);if(!n||!c){console.error(`Could not find element during rerenderCartSections for section ${e}`,{htmlString:r,newHtml:o,newElement:c,currentElement:n});return}e===this.cartSectionId&&n?.getAttribute("data-open")==="true"&&(c?.setAttribute("data-open","true"),c?.classList.remove("translate-x-full")),c&&n&&n.replaceWith(c);const i=c.querySelector(a.selectors.cartData);i?.dataset?.cartCount&&(document.querySelectorAll(a.selectors.cartCount).forEach(d=>{const C=d,f=(C.textContent||"").replace(/\d+/,i.dataset.cartCount||"0");C.textContent=f,C.setAttribute("data-cart-count",i.dataset.cartCount||"0")}),document.querySelectorAll(a.selectors.cartDot).forEach(d=>{d.setAttribute("data-cart-count",i.dataset.cartCount||"0")}))})}setCart(t){this.cart=t}async getCart(){const t=`${CHROMA.routes.cart_url}.js`,s=l("GET","text");return h(t,s).then(e=>(this.setCart(e),e)).catch(u)}async addToCart(t){const s=Array.isArray(t)?t:[t],e=this.getCartSectionsToBeRerendered(),r=`${CHROMA.routes.cart_add_url}.js`,o=l("POST","text",{items:s,sections:e});return h(r,o,{handleErrors:!1}).then(async n=>(this.rerenderCartSections(n),this.openSlideout(),this.getCart(),n)).catch(u)}async updateCart(t,s,e){const r=`${CHROMA.routes.cart_update_url}.js`,o=this.getCartSectionsToBeRerendered(),n=l("POST","json",{updates:t,note:s,attributes:e,sections:o});return h(r,n,{handleErrors:!1}).then(c=>(this.rerenderCartSections(c),this.setCart(c),c)).catch(u)}async changeCart(t,s,e,r){const o=`${CHROMA.routes.cart_change_url}.js`,n=this.getCartSectionsToBeRerendered(),c=l("POST","text",{id:t,quantity:s,...e&&{properties:e},...r&&{selling_plan:r},sections:n});return h(o,c,{returnText:!0}).then(i=>(this.rerenderCartSections(i),this.setCart(i),i)).catch(u)}async clearCart(){const t=`${CHROMA.routes.cart_clear_url}.js`,s=this.getCartSectionsToBeRerendered(),e=l("POST","text",{sections:s});return h(t,e).then(r=>(this.rerenderCartSections(r),this.setCart(r),r)).catch(u)}async getShippingRates(t){const s=`${CHROMA.routes.cart_url}/prepare_shipping_rates.json`,e=l("POST","text",t);await h(s,e,{returnText:!0}).catch(u);const r=async(o=10,n=500)=>{if(o===0)throw new Error("Shipping rates calculation timed out");const c=`${CHROMA.routes.cart_url}/async_shipping_rates.json`,i=l("GET","text"),d=await h(c,i,{returnText:!0}).catch(u);return d===null?(await new Promise(C=>setTimeout(C,n)),r(o-1,n)):d};return r()}async applyDiscount(t){const s=`${CHROMA.routes.cart_url}/update.js`,e=l("POST","text",{discount:t});return h(s,e,{returnText:!0}).then(r=>(this.setCart(r),r)).catch(u)}};a.selectors={cartCount:'[data-selector="cart-count"]',cartDot:'[data-selector="cart-dot"]',cartData:'[data-selector="cart-data"]'},a.dataAttributes={cartCount:"data-cart-count"},a.instance=null;let g=a;window.cartService||(window.cartService=g.getInstance());
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.