import{a as c,b as S}from"./chunk-HOI2FLSI.js";import{F as y,_a as i,cc as a,db as f,eb as m,ec as p,gc as u,k as s,q as h,t as l}from"./chunk-BYJPVSLE.js";import{f as g}from"./chunk-TSRGIXR5.js";var r=g(u());var j=(()=>{class d{constructor(t,e){this.http=t,this.platformId=e,this.url=a.apiBaseUrl+"cart/",this.carts=[],this.order=new S,this.qty=0,this.grandTotal=0}get(t={}){let e=new f;return t.customer_id&&(e=e.set("customer_id",t.customer_id)),t.restaurant_id&&(e=e.set("restaurant_id",t.restaurant_id)),t.nopaginate&&(e=e.set("nopaginate",t.nopaginate)),this.http.get(`${this.url}`,{params:e}).pipe(s(p.handleError))}show(t){return this.http.get(this.url+t).pipe(s(p.handleError))}create(t){return this.http.post(this.url,c.toFormData(t)).pipe(s(p.handleError))}update(t){return this.http.post(this.url+t.id,c.toFormData(t)).pipe(s(p.handleError))}delete(t){return this.http.delete(this.url+t).pipe(s(p.handleError))}cartBulk(t){return this.http.post(this.url+"cart-bulk",c.toBulformdata(t)).pipe(s(p.handleError))}saveOrderType(t){var e=r.enc.Utf8.parse(a.garble),o=r.enc.Utf8.parse(a.jumble),n=r.AES.encrypt(r.enc.Utf8.parse(t),e,{keySize:128/8,iv:o,mode:r.mode.CBC,padding:r.pad.Pkcs7});i(this.platformId)&&localStorage.setItem(a.order_type,n.toString())}getOrderType(){if(!i(this.platformId))return null;var t=r.enc.Utf8.parse(a.garble),e=r.enc.Utf8.parse(a.jumble),o=localStorage.getItem(a.order_type);if(!o){this.saveOrderType("delivery");var o=localStorage.getItem(a.order_type)}var n=r.AES.decrypt(o,t,{keySize:128/8,iv:e,mode:r.mode.CBC,padding:r.pad.Pkcs7});return n.toString(r.enc.Utf8)}saveOrder(t){let e=r.enc.Utf8.parse(a.garble),o=r.enc.Utf8.parse(a.jumble),n=r.AES.encrypt(r.enc.Utf8.parse(JSON.stringify(t)),e,{keySize:128/8,iv:o,mode:r.mode.CBC,padding:r.pad.Pkcs7});i(this.platformId)&&localStorage.setItem(a.order,n.toString())}getOrder(){if(!i(this.platformId))return null;let t=r.enc.Utf8.parse(a.garble),e=r.enc.Utf8.parse(a.jumble),o=localStorage.getItem(a.order);return o&&r.AES.decrypt(o,t,{keySize:16,iv:e,mode:r.mode.CBC,padding:r.pad.Pkcs7}).toString(r.enc.Utf8)}getCart(){if(!i(this.platformId))return[];if(typeof localStorage<"u"){let t=localStorage.getItem(a.cart),e=JSON.parse(t||"[]");return this.carts=e,this.qty=0,this.grandTotal=0,this.carts.length>0&&this.carts.forEach(o=>{this.qty=this.qty+o.quantity,this.grandTotal=this.grandTotal+o.total_price}),e}else return[]}saveCart(t){this.carts=t;let e=JSON.stringify(t);this.qty=0,this.grandTotal=0,this.carts.length>0&&this.carts.forEach(o=>{this.qty=this.qty+o.quantity,this.grandTotal=this.grandTotal+o.total_price}),typeof localStorage<"u"&&i(this.platformId)&&localStorage.setItem(a.cart,e.toString())}removeCart(){if(this.carts=[],this.qty=0,this.grandTotal=0,typeof localStorage<"u"&&i(this.platformId))return localStorage.removeItem(a.cart)}static{this.\u0275fac=function(e){return new(e||d)(l(m),l(y))}}static{this.\u0275prov=h({token:d,factory:d.\u0275fac,providedIn:"root"})}}return d})();export{j as a};
