import{a as f,b as _}from"./chunk-OCLYE42A.js";import{a as l}from"./chunk-HEWBVLHR.js";import{a as d,c as n}from"./chunk-WXQVX7WD.js";import{m}from"./chunk-OWZ5YAMH.js";import{a as p}from"./chunk-KXX3UDJ3.js";import{j as h}from"./chunk-GQAU5ACB.js";import{S as o,fa as c,k as S,la as a,pa as s}from"./chunk-ISMRT7VU.js";var w=(()=>{class r{constructor(e){this._http=e}getWarehouses(e=!1){return this._http.get(`/api/warehouse?viewArchive=${e}`)}getWarehouseAll(){return this._http.get("/api/warehouse/all")}createWarehouse(e){return this._http.post("/api/warehouse",e)}editWarehouse(e,i){return this._http.put(`/api/warehouse/${i}`,e)}syncWarehouse(){return this._http.post("/api/warehouse/sync",{},{headers:p})}getWarehouseRemains(e,i,A=!1){return A?this._http.post(`/api/warehouse/${e}/remains`,i,{headers:p}):this._http.post(`/api/warehouse/${e}/remains`,i)}static{this.\u0275fac=function(i){return new(i||r)(s(h))}}static{this.\u0275prov=a({token:r,factory:r.\u0275fac})}}return r})();var y=(()=>{class r{constructor(e){this._http=e}getStores(e){return this._http.get(`/api/store?viewArchive=${e}`)}createStore(e){return this._http.post("/api/store",e)}editStore(e,i){return this._http.put(`/api/store/${i}`,e)}lastSyncState(e){return this._http.get(`/api/store/${e}/last-sync-state`)}syncStore(){return this._http.post("/api/store/sync",{},{headers:p})}static{this.\u0275fac=function(i){return new(i||r)(s(h))}}static{this.\u0275prov=a({token:r,factory:r.\u0275fac})}}return r})();var u=class r{get selectedStore(){let t=this._stores.find(e=>e.id===this._selectedStoreId);return t||null}constructor(t,e,i){this._retailStoreServiceApi=t,this._warehouseServiceApi=e,this._store=i}getStores(t=!1){return this._retailStoreServiceApi.getStores(t).pipe(c(e=>this._store.dispatch(new d(e))),o(1))}createStore(t){return this._retailStoreServiceApi.createStore(this.toRequestModel(t)).pipe(c(()=>this.getStores().subscribe()),o(1))}editStore(t,e){return this._retailStoreServiceApi.editStore(this.toRequestModel(t),e).pipe(c(()=>{this.getStores().subscribe(),this._warehouseServiceApi.getWarehouses().pipe(o(1)).subscribe(i=>{this._store.dispatch(new f(i)),e===this._store.selectSnapshot(n.selectedStoreId)&&this._store.dispatch(new _(t.mainWarehouse))})}),o(1))}lastSyncState(t){return this._retailStoreServiceApi.lastSyncState(t).pipe(o(1))}syncStore(){return this._retailStoreServiceApi.syncStore().pipe(o(1))}toRequestModel(t){return{name:t.name,address:t.address,available:t.warehouseAccess.filter(e=>e.warehouse).map(e=>e.id),mainWarehouse:t.mainWarehouse,defaultPriceId:t.defaultPriceId,availablePriceIds:t.priceAccess.filter(e=>e.price).map(e=>e.id)}}static{this.\u0275fac=function(e){return new(e||r)(s(y),s(w),s(m))}}static{this.\u0275prov=a({token:r,factory:r.\u0275fac})}};S([l(n.stores)],u.prototype,"_stores",void 0);S([l(n.selectedStoreId)],u.prototype,"_selectedStoreId",void 0);export{y as a,w as b,u as c};
//# sourceMappingURL=chunk-5QUMV2KP.js.map
