import{P as o,br as n,c as i,m as l,A as c}from"./index.cf09daef.js";const u=o.getItem("cart")||[],d=n("shop",{state:()=>({orders:[],cart:u}),getters:{columns:t=>[{name:"title",align:"left",label:t.$t("label.title"),field:"title",style:"width: 40px",sortable:!0},{name:"price",align:"left",label:t.$t("label.price"),field:"price",format:r=>i.money(r),style:"width: 40px",sortable:!0}],toolbar:t=>[{title:t.$t("label.sort"),action:"request",component:"base-select",dense:!0,outlined:!0,key:"sortBy",placeholder:t.$t("placeholder.select"),optionsDense:!0,style:"width: 150px",mapOptions:!0,emitValue:!0,options:[{label:t.$t("label.priceHigh"),value:"PRICE_DESC"},{label:t.$t("label.priceLow"),value:"PRICE_ASC"},{label:t.$t("label.oldest"),value:"CREATED_AT_ASC"},{label:t.$t("label.latest"),value:"CREATED_AT_DESC"}],prefix:t.$t("prefix.sort"),deleted:"all"}],cartTotal(t){return l.exports.sumBy(t.cart,r=>r.price*r.quantity)},cartCount(t){return l.exports.sumBy(t.cart,r=>parseInt(r.quantity))},lineItems(t){return t.cart.map(r=>({title:r.title,price:r.price,product_id:r.id,variant_id:r.variant_id,quantity:r.quantity}))}},actions:{orders(t){return new Promise((r,a)=>{c.get("member/shop/orders",t).then(e=>{this.orders=e.data,r(e)}).catch(e=>{a(e)})})},createOrder(t){return new Promise((r,a)=>{c.post("member/shop/orders/store",t).then(e=>{r(e)}).catch(e=>{a(e)})})},showOrder(t){return new Promise((r,a)=>{c.get(`member/shop/orders/${t}`).then(e=>{r(e)}).catch(e=>{a(e)})})},products(t){return new Promise((r,a)=>{c.get("member/shop/products",t).then(e=>{this.setRows(e.data),r(e)}).catch(e=>{a(e)})})},product(t){return new Promise((r,a)=>{c.get(`member/shop/products/${t}`).then(e=>{r(e)}).catch(e=>{a(e)})})},addToCart(t){return new Promise((r,a)=>{try{const e=this.cart.find(s=>s.id===t.id&&s.variant_id===t.variant_id);e?e.quantity<1?this.cart=this.cart.filter(s=>s.id!==t.id):e.quantity=t.quantity||e.quantity++:this.cart.push({...t,quantity:1}),o.set("cart",this.cart),i.success("Product has been added to cart."),r(this.cart)}catch(e){i.error(e),a(e)}})},removeFromCart({rowIndex:t}){return new Promise((r,a)=>{try{this.cart.splice(t,1),o.set("cart",this.cart),i.success("Product has been remove from cart."),r(this.cart)}catch(e){i.error(e),a(e)}})},updateCart({rowIndex:t,row:r}){return console.func("stores/shop:actions.updateCart()",arguments),new Promise((a,e)=>{try{this.cart[t].quantity=r.quantity,o.set("cart",this.cart),a(this.cart)}catch(s){i.error(s),e(s)}})},clearCart(){this.cart=[],o.set("cart",this.cart)}}});export{d as u};
