1import{S as l}from"./swiper-slider.Dp9oLI2c.min.js";import{E as i}from"./events.CylfRtLc.min.js";class c extends HTMLElement{constructor(){super(),this.sliders=this.querySelectorAll("[data-slider]"),this.resetButtons=this.querySelectorAll("[data-reset-selection]"),this.categories=this.querySelectorAll(".build-a-bundle__category"),this.selectedProducts={},this.cartItems={},this.isCartUpdating=!1,this.init()}init(){this.initSliders(),this.addEventListeners()}initSliders(){this.sliders.length&&this.sliders.forEach(r=>{const s=r.getAttribute("data-slider"),t=this.querySelector(`[data-scrollbar="${s}"]`);new l(r,{slidesPerView:"auto",slidesPerGroup:1,watchSlidesProgress:!0,scrollbar:{el:t,draggable:!0,dragClass:"build-a-bundle__scrollbar-drag",dragSize:"auto"},breakpoints:{769:{slidesPerGroup:4,slidesPerView:4}}})})}addEventListeners(){this.resetButtons.forEach(r=>{r.addEventListener("click",this.handleResetCategory.bind(this))}),this.addEventListener(i.BUNDLE_ADD,this.handleBundleAdd.bind(this))}handleBundleAdd(r){if(this.isCartUpdating)return;const{productId:s,variantId:t,categoryId:e}=r.detail,d=r.target,a=this.querySelector(`.build-a-bundle__category[data-category="${e}"]`),o=this.querySelector(`[data-reset-selection="${e}"]`);!s||!t||!e||!a||!o||(d.setSelected(!0),this.selectedProducts[e]=s,a.classList.add("build-a-bundle__category--completed"),this.greyOutOtherProducts(e,s),o.style.display="block",this.addToCart(t,e))}greyOutOtherProducts(r,s){this.querySelectorAll(`bundle-product-card[data-category="${r}"]`).forEach(e=>{const d=e.getAttribute("data-product-id");e.setDisabled(d!==s)})}handleResetCategory(r){if(this.isCartUpdating)return;const s=r.currentTarget,t=s.getAttribute("data-reset-selection"),e=this.querySelector(`.build-a-bundle__category[data-category="${t}"]`);if(!t||!e)return;if(this.selectedProducts[t]){const a=this.querySelector(`bundle-product-card[data-product-id="${this.selectedProducts[t]}"][data-category="${t}"]`);a&&(a.setSelected(!1),a.setDisabled(!1)),this.cartItems[t]&&(this.removeFromCart(this.cartItems[t]),delete this.cartItems[t]),delete this.selectedProducts[t]}e.classList.remove("build-a-bundle__category--completed"),s.style.display="none",e.querySelectorAll("bundle-product-card").forEach(a=>{a.setDisabled(!1)})}addToCart(r,s){this.isCartUpdating=!0,fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{id:r,quantity:1,properties:{_bundle_category:s,_bundle_item:!0}}]})}).then(e=>{if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return e.json()}).then(e=>{const d=e.items&&e.items[0];d?(this.cartItems[s]=d.variant_id||r,document.dispatchEvent(new CustomEvent(i.CART_ADD,{detail:e,bubbles:!0}))):console.error("Unexpected response format from cart/add.js:",e),this.isCartUpdating=!1}).catch(e=>{console.error("Error adding product to cart:",e),this.isCartUpdating=!1})}removeFromCart(r){this.isCartUpdating=!0;const s={updates:{[r]:0}};fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).then(t=>{if(!t.ok)throw new Error(`HTTP error! Status: ${t.status}`);return t.json()}).then(t=>{document.dispatchEvent(new CustomEvent(i.CART_ADD,{detail:t,bubbles:!0})),this.isCartUpdating=!1}).catch(t=>{console.error("Error removing product from cart:",t),this.isCartUpdating=!1})}}const g=()=>{customElements.get("build-a-bundle")||customElements.define("build-a-bundle",c)};export{g as default};
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.