1import{m as S,a as h,e as b,b as p,c as i,d as g}from"./vite-index-DWzVwJgR.js";const u="back-in-stock-pop-in",a={button:{back_in_stock:"[data-back-in-stock-button]"},cart:{items:"[data-section-cart-items]",footer:"[data-section-cart-footer]",free_products:"[data-section-free-products]"},product:{form_wrapper_error:".product-form__error-message-wrapper",form_message_error:".product-form__error-message",variant_id:".product-variant-id"}},d={open:`${u}:open`,close:`${u}:close`};function $(n){try{n()}catch(c){console.error("[Analytics] - Error pushing add to cart tracking:",c)}}function v(){var n,c,f,m,k,y;return{productId:((f=(c=(n=this==null?void 0:this.$refs)==null?void 0:n.addButton)==null?void 0:c.dataset)==null?void 0:f.productId)??null,showError:!1,openBackInStock:!1,notifyProductId:((y=(k=(m=this==null?void 0:this.$refs)==null?void 0:m.notifyButton)==null?void 0:k.dataset)==null?void 0:y.productId)??null,notifyEmail:"",notifyConsent:!1,notifySuccess:!1,notifyError:!1,isLoading:!1,timestamp:1,init(){this.checkStock(),this.bindEvents(),localStorage.getItem("openWaitlist")==="true"&&(localStorage.removeItem("openWaitlist"),setTimeout(()=>{this.openBackInStockPanel()},500))},destroy(){window.removeEventListener(d.open,this.openBackInStockPanel),window.removeEventListener(d.close,this.closeBackInStockPanel)},bindEvents(){window.addEventListener(d.open,this.openBackInStockPanel),window.addEventListener(d.close,this.closeBackInStockPanel)},async backInStock(e){if(this.$validate.submit(e),!this.$validate.isComplete(e.target))return!1;this.isLoading=!0;const t="https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=SCaTnK",o={method:"POST",headers:{accept:"application/json",revision:"2026-04-15","content-type":"application/json"},body:JSON.stringify({data:{type:"back-in-stock-subscription",attributes:{channels:["EMAIL"],profile:{data:{type:"profile",id:"",attributes:{email:this.notifyEmail}}}},relationships:{variant:{data:{type:"catalog-variant",id:`$shopify:::$default:::${this.notifyProductId}`}}}}})};try{const r=await fetch(t,o);if(this.$dispatch(i.add,"back-in-stock"),r.status!==202){const s=await r.json();console.error("Error:",s.errors[0].detail),this.notifySuccess=!1,this.notifyError=!0}else this.notifySuccess=!0,this.notifyError=!1}catch(r){console.error("Error:",r),this.notifySuccess=!1,this.notifyError=!0}finally{this.isLoading=!1,this.$dispatch(i.done,"back-in-stock")}},async onSubmit(){if(!this.productId)return this.showErrorMessage(window.productStrings.idNotFound),console.error(window.productStrings.idNotFound);this.timestamp=new Date().valueOf(),await this.$nextTick(),this.$dispatch(i.add,"add-to-cart");const e=this.createBody(this.$refs.buyForm);try{const t=fetch(`${window.routes.cart_add_url}.js`,{method:"POST",body:e});this.trackAddToCartIntent();const o=await t;if(o.status===400){const s=await o.text();throw this.$dispatch(i.done,"add-to-cart"),this.showErrorMessage(s),new Error(s)}const r=await o.json();this.updateSections(r.sections),this.$dispatch(p.mutations.setCart,r),await this.$nextTick(),this.$dispatch(i.done,"add-to-cart"),this.$dispatch(g.open)}catch(t){this.showErrorMessage(window.productStrings.errorAddingToCart),console.error("Error:",t)}finally{this.$dispatch(i.done,"add-to-cart")}this.checkStock()},trackAddToCartIntent(){$(()=>{var t;const e=window.addToCartTrackingHandler;typeof e=="function"&&e((t=this==null?void 0:this.$refs)==null?void 0:t.addButton)})},async canAddToCart(){var t;const e=this.$store.shop.cart;if(e.items.length===0)return!0;if(e.items.length!=0){const o=e.items.find(l=>l.id===parseInt(this.productId)),r=o?o.quantity:0,s=parseInt((t=document==null?void 0:document.querySelector(a.product.variant_id))==null?void 0:t.getAttribute("data-max"))||0;return r>=s?(this.disableButton(),this.showErrorMessage(window.productStrings.notEnoughStock),!1):r+1<=s}},async checkStock(){await this.canAddToCart()||this.disableButton()},openBackInStockPanel(){this.openBackInStock=!0,this.$dispatch(p.mutations.addUi,{id:u,disableScroll:!0})},closeBackInStockPanel(){this.openBackInStock=!1,this.notifySuccess=!1,this.notifyError=!1,this.$dispatch(p.mutations.removeUi,{id:u})},disableButton(){var e,t,o,r,s;(t=(e=this==null?void 0:this.$refs)==null?void 0:e.addButton)==null||t.setAttribute("disabled","disabled"),(s=(r=(o=this==null?void 0:this.$refs)==null?void 0:o.addButton)==null?void 0:r.classList)==null||s.add("is-disabled")},updateSections(e){for(const t in e){const o=document.querySelector(`#shopify-section-${t}`)??document.querySelector(`#${t}`);S.morph(o,e[t],{updating(r,s,l,w){if(r instanceof HTMLElement){if(r.hasAttribute(h.Alpine.morph.skip))return w();if(r.hasAttribute(h.Alpine.morph.children))return l()}},removing(r,s){if(r instanceof HTMLElement&&r.hasAttribute(h.Alpine.morph.skip))return s()},lookahead:!0}),this.$dispatch(b.newDOM,{detail:{node:o},bubbles:!0})}},showErrorMessage(e){const t=document.querySelector(a.product.form_message_error),o=document.querySelector(a.product.form_message_error);this.showError=!0,t instanceof HTMLElement&&o instanceof HTMLSpanElement&&(o.textContent=e)},createBody(e){const t=new FormData(e);return t.append("sections",this.sections.map(o=>o.id).filter(o=>o!==void 0)),t.append("sections_url",window.location.pathname),t},get sections(){var e,t,o;
1return[{id:((e=document.querySelector(a.cart.items))==null?void 0:e.id)??"main-cart-items"},{id:((t=document.querySelector(a.cart.footer))==null?void 0:t.id)??"main-cart-footer"},{id:(o=document.querySelector(a.cart.free_products))==null?void 0:o.id}]}}}export{v as data,d as events,a as selectors};
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.