1import{c as l}from"./WithApiClient.BE3WhhYk.min.js";import{c as C,a as p}from"./cart-sections.WoVMkNAv.min.js";import{c}from"./consume.CHsRYPSi.min.js";import"./lit-element.D1QXZDXi.min.js";import{r as h}from"./state.DSBX3JYf.min.js";var u=Object.defineProperty,r=(i,s,n,e)=>{for(var t=void 0,a=i.length-1,o;a>=0;a--)(o=i[a])&&(t=o(s,n,t)||t);return t&&u(s,n,t),t};const d=new Set([]),m="cart-drawer-dialog",w={cart:!0,sections:!0},T=i=>{class s extends i{constructor(){super(...arguments),this.shopifyCartLoading=!1,this.shopifyCartError=null,this.loadingCartPromise=null,this.client=l({baseUrl:`${window.Shopify.routes.root}cart`,headers:{"Content-Type":"application/json"},defaultMethod:"POST",withQueue:!0,queueKey:"shopify-cart",onRequestStart:()=>{this.shopifyCartLoading=!0,this.classList.add("loading"),Array.from(this.querySelectorAll("button")).forEach(e=>{e.classList.add("disabled")})},onRequestEnd:()=>{this.shopifyCartLoading=!1,this.classList.remove("loading"),Array.from(this.querySelectorAll("button")).forEach(e=>{e.classList.remove("disabled")})}})}connectedCallback(){super.connectedCallback();const e=this.getAttribute("section-id");e&&typeof e=="string"&&d.add(e)}get sectionsToFetch(){return Array.from(d).slice(0,5).join(",")}async addItemToCart(e){try{const t=await this.client("/add.js",{body:{items:e,sections:this.sectionsToFetch,sections_url:window.location.pathname}});return await this._handleCartAdd([t.items],this),await this._handleCartChange(),t.sections&&this._handleCartSectionsChange(t.sections),t}catch(t){throw this._handleCartError(t),t}}async addItemToWithForm(e){try{e.append("sections",this.sectionsToFetch),e.append("sections_url",window.location.pathname);const t=await this.client("/add",{body:e,headers:{"X-Requested-With":"XMLHttpRequest",Accept:"application/json"}},{rawBody:!0,removeContentType:!0});return await this._handleCartAdd([t.items],this),await this._handleCartChange(),t.sections&&this._handleCartSectionsChange(t.sections),t}catch(t){throw console.error("ð addItemToWithForm: Error",t),this._handleCartError(t),t}}async updateQuantityToCart(e){try{const t=await this.client("/update.js",{body:{updates:e,sections:this.sectionsToFetch,sections_url:window.location.pathname}});await this._handleCartChange(t),t.sections&&this._handleCartSectionsChange(t.sections)}catch(t){throw this._handleCartError(t),t}}async updateCartNoteAndAttributes(e,t=w){const a=await this.client("/update.js",{body:{...e,sections:this.sectionsToFetch,sections_url:window.location.pathname}});await this._handleCartChange(a),t.sections&&a.sections&&this._handleCartSectionsChange(a.sections)}async removeItemFromCart(e){const t=await this.client("/update.js",{body:{updates:e.reduce((a,o)=>(a[o]=0,a),{}),sections:this.sectionsToFetch,sections_url:window.location.pathname}});await this._handleCartChange(t),t.sections&&this._handleCartSectionsChange(t.sections)}async changeItemToCart(e){const t=await this.client("/change.js",{body:{...e,sections:this.sectionsToFetch,sections_url:window.location.pathname}});await this._handleCartChange(t),t.sections&&this._handleCartSectionsChange(t.sections)}async clearCart(){const e=await this.client("/clear.js",{body:{sections:this.sectionsToFetch,sections_url:window.location.pathname}});await this._handleCartChange(e),e.sections&&this._handleCartSectionsChange(e.sections)}async getCart(e=!1){if(this.loadingCartPromise)return this.loadingCartPromise;this.loadingCartPromise=this.client(".js",{method:"GET"});try{const t=await this.loadingCartPromise;return e&&await this.getCartSections(),t}finally{this.loadingCartPromise=null}}async _handleCartChange(e){const t=e??await this.getCart();this.$emit("cart:updated",t)}async _handleCartAdd(e,t){this.$emit("cart:items-added",{items:e,target:t})}async getCartSections(){const e=await fetch(`${window.location.pathname}?sections=${this.sectionsToFetch}`);if(!e.ok){const a=new Error(`Failed to fetch cart sections: ${e.status}`);throw this._handleCartError(a),a}const t=await e.json();return this._handleCartSectionsChange(t),t}_handleCartSectionsChange(e){e&&this.$emit("cart:updated-sections",e)}_handleCartError(e){this.$emit("cart:error",e),this.shopifyCartError=e}getCartLinesForVariant(e){return this.cart.items.filter(t=>t.variant_id===e)}openCartDrawer(){this.$emit("modal-dialog::open",m)}}return r([c({context:C,subscribe:!0})],s.prototype,"cart"),r([c({context:p,subscribe:!0})],s.prototype,"cartSections"),r([h()],s.prototype,"shopifyCartLoading"),r([h()],s.prototype,"shopifyCartError"),s};export{T as 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.