1(function(){"use strict";customElements.get("tea-tier-buybox")||customElements.define("tea-tier-buybox",class extends HTMLElement{connectedCallback(){if(!(this.ready||!window.TeaTierModel)){this.ready=!0,this.model=window.TeaTierModel,this.state=this.model.initial(),this.unitPrice=Number(this.dataset.unitPrice);try{const data=JSON.parse(document.getElementById(this.dataset.planDataId).textContent);String(data.product_id)===this.dataset.productId&&String(data.variant_id)===this.dataset.variantId&&(this.planData=data)}catch{}this.money=new Intl.NumberFormat(document.documentElement.lang||"en-US",{style:"currency",currency:this.dataset.currency||"USD"}),this.addEventListener("change",event=>{if(this.busy)return;this.status("");const input=event.target;input.matches(".tea-tiers__modes input")&&(this.state=this.model.select(this.state,"mode",input.value)),input.matches(".tea-tiers__options input")&&(this.state=this.model.select(this.state,"quantity",input.value)),input.matches("[data-cadence]")&&(this.state=this.model.select(this.state,"months",input.value)),input.matches("[data-quantity]")&&(this.state=this.model.select(this.state,"quantity",input.value)),this.render()}),this.addEventListener("click",event=>{const button=event.target.closest("button");if(button&&!this.busy){if(button.matches(".tea-tiers__buy")){this.addToCart();return}(button.hasAttribute("data-increment")||button.hasAttribute("data-decrement"))&&(this.status(""),this.state=this.model.select(this.state,"quantity",this.state.quantity+(button.hasAttribute("data-increment")?1:-1)),this.render())}}),this.render()}}format(cents){return this.money.format(cents/100)}text(selector,text){this.querySelector(selector).textContent=text}status(message){const status=this.querySelector("[data-cart-status]");status.textContent=message,status.hidden=!message}async addToCart(){const item=this.model.cartItem(this.state,this.planData);if(this.busy||!item||!window.TeaCartSession?.acquire())return;this.busy=!0,this.render(),this.status("Adding to cart\u2026");const root=window.Shopify?.routes?.root||"/",request=async(path,body)=>{const response=await fetch(root+path,{credentials:"same-origin",cache:"no-store",signal:AbortSignal.timeout(15e3),headers:{"Content-Type":"application/json",Accept:"application/json"},...body?{method:"POST",body:JSON.stringify(body)}:{}}),result=await response.json();if(!response.ok)throw new Error(typeof result.description=="string"?result.description:"Shopify could not update the cart.");return result};let added=!1;try{const model=window.TeaCartModel,data=model.productData(await request("products/"+encodeURIComponent(this.dataset.productHandle)+".js"),item.id);if(!data)throw new Error("The product plans could not be verified.");const before=await request("cart.js");if(this.state.mode==="subscription"){const total=item.quantity+model.group(before,{variant_id:item.id},data,this.state.months).reduce((sum,line)=>sum+line.quantity,0),plan=model.resolve(data,total,this.state.months);if(!plan)throw new Error("This subscription option is unavailable.");item.selling_plan=plan.id}await request("cart/add.js",{items:[item]}),added=!0,await model.normalize(await request("cart.js"),data,request);const smartCart=window.Rebuy?.SmartCart;smartCart&&typeof smartCart.setCart=="function"&&typeof smartCart.show=="function"?(await window.TeaCartSession.syncRebuy(),smartCart.show(),this.status("Added to cart.")):this.status("Added to cart. Open your cart to review it.")}catch{this.status(added?"Added, but the subscription update could not be completed. Review your cart before adding again.":"Could not confirm whether the item was added. Check your cart before trying again.");try{await window.TeaCartSession.syncRebuy(),window.Rebuy?.SmartCart?.show?.()}catch{}}finally{this.busy=!1,window.TeaCartSession.release(),this.render()}}render(){const{mode,quantity,months}=this.state,subscription=mode==="subscription",plan=subscription?this.model.resolvePlan(this.planData?.plans,quantity,months):null,price=subscription?plan?{total:plan.price*quantity,compare:(plan.compare_at_price??this.unitPrice)*quantity}:null:this.model.price(this.state,this.unitPrice);this.querySelectorAll("input, select, button").forEach(el=>{el.disabled=!!this.busy}),this.querySelector(".tea-tiers__buy").disabled=!!this.busy||!this.model.cartItem(this.state,this.planData),this.querySelector(".tea-tiers__buy").setAttribute("aria-busy",String(!!this.busy)),this.querySelector("[data-subscription]").hidden=!subscription,this.querySelectorAll("[data-onetime]").forEach(el=>{el.hidden=subscription}),this.querySelectorAll(".tea-tiers__modes input").forEach(el=>{el.checked=el.value===mode}),this.querySelectorAll(".tea-tiers__options input").forEach(el=>{el.checked=Number(el.value)===quantity}),this.querySelector("[data-quantity]").value=quantity,this.querySelector("[data-decrement]").disabled=!!this.busy||quantity<=1,this.querySelectorAll(".tea-tiers__option").forEach(option=>{const q=Number(option.querySelector("input").value),allocation=this.model.resolvePlan(this.planData?.plans,q,q===quantity&&subscription?months:q),compare=allocation?.compare_at_price??this.unitPrice;option.querySelector(".tea-tiers__prices strong").textContent=allocation?this.format(allocation.price*q):"Unavailable",option.querySelector(".tea-tiers__prices s").textContent=this.format(compare*q),option.querySelector(".tea-tiers__prices s").hidden=!allocation||compare<=allocation.price;const saving=option.querySelector(".tea-tiers__saving");saving.hidden=!allocation||compare<=allocation.price,allocation&&compare>0&&(saving.textContent=`Save ${Math.round((1-allocation.price/compare)*100)}%`)}),this.querySelectorAll("[data-cadence] option").forEach(option=>{const n=Number(option.value);option.textContent=`Every ${n} ${n===1?"month":"months"}`}),subscription&&(this.querySelector("[data-cadence]").value=months),this.text("[data-total]",price?this.format(price.total):"Unavailable"),this.text("[data-compare]",price?this.format(price.compare):""),this.querySelector("[data-compare]").hidden=!subscription||!price||price.compare<=price.total,this.text("[data-terms]",subscription?"Change, skip or cancel anytime":"Free shipping when purchasing 2+ boxes"),this.text("[data-announcement]",price?`${quantity} ${quantity===1?"box":"boxes"}, ${this.format(price.total)}${subscription?` every ${months} ${months===1?"month":"months"}`:", ships once"}.`:"This subscription option is unavailable.")}})})(); 2//# sourceMappingURL=/cdn/shop/t/46/assets/tea-tier-buybox.js.map?v=59636911484660078121789145802
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.