Alpine.data("CartItem",i=>({controller:null,product:i.product,item:i.variant||i.product,qty:i.qty,get productName(){return this.product.name},get productUrl(){let t=`/products/${this.product.slug}`;return this.hasAnyVariant&&(t+=`?variant=${this.item.uid}`),t},get unitPrice(){return i.unitPrice.inCurrentCurrency.amount},get hasAnyVariation(){return Object.keys(i.variations).length!==0},get variationsLength(){return Object.keys(i.variations).length},get hasAnyOption(){return Object.keys(i.options).length!==0},get optionsLength(){return Object.keys(i.options).length},get hasAnyVariant(){return this.product.variant!==null},get hasAnyMedia(){return this.item.media.length!==0},get hasBaseImage(){return this.hasAnyVariant?this.item.base_image.length!==0||this.product.base_image.length!==0:this.item.base_image.length!==0},get baseImage(){return this.hasBaseImage?this.item.base_image.path||this.product.base_image.path:`${window.location.origin}/build/assets/image-placeholder.png`},isQtyIncreaseDisabled(t){return this.maxQuantity(t)!==null&&t.qty>=t.item.qty},lineTotal(t){return t*i.unitPrice.inCurrentCurrency.amount},optionValues(t){let e=[];for(let n of t.values)e.push(n.label);return e.join(", ")},maxQuantity({item:t}){return t.is_in_stock&&t.does_manage_stock?t.qty:null},exceedsMaxStock({item:t,qty:e}){return t.does_manage_stock&&t.qty<e},changeQuantity(t,e){if(isNaN(e)||e<1){e=1,this.updateCart(t,e);return}if(t.qty=e,this.exceedsMaxStock(t)){e=t.item.qty,this.updateCart(t,e);return}this.updateCart(t,e)},updateQuantity(t,e){if(isNaN(e)||e<1){e=1,t.qty=1;return}if(t.qty=e,this.exceedsMaxStock(t)){t.qty=t.item.qty,this.updateCart(t,t.qty);return}this.updateCart(t,e)},async updateCart(t,e){this.controller&&this.controller.abort(),this.controller=new AbortController;try{const{data:n}=await axios.put(`/cart/items/${t.id}`,{qty:e||1},{signal:this.controller.signal});this.qty=n.items[t.id].qty,this.$store.cart.updateCart(n)}catch(n){n.code!=="ERR_CANCELED"&&(this.$store.cart.updateCartItemQty({id:t.id,qty:this.qty}),notify(trans("storefront::storefront.something_went_wrong")))}},removeCartItem(){this.$store.cart.removeCartItem(i.id),axios.delete(`/cart/items/${i.id}`).then(t=>{this.$store.cart.updateCart(t.data)})}}));
