import{a as f,b as d}from"./chunk-65ZGL2UQ.js";import{a as m,c as h}from"./chunk-EZFUKPLV.js";import{a as S}from"./chunk-X73HYPLN.js";import{m as l}from"./chunk-ALPCJSJV.js";import{a as _}from"./chunk-E65DJUZB.js";import{f as c}from"./chunk-IQZCMWOL.js";import{$ as p,K as o,da as a,ja as s}from"./chunk-AO7NUUXN.js";import{d as u,n as A}from"./chunk-HE7HQ6LI.js";var w=(()=>{class r{constructor(t){this._http=t}getWarehouses(t=!1){return this._http.get(`/api/warehouse?viewArchive=${t}`)}getWarehouseAll(){return this._http.get("/api/warehouse/all")}createWarehouse(t){return this._http.post("/api/warehouse",t)}editWarehouse(t,i){return this._http.put(`/api/warehouse/${i}`,t)}getWarehouseRemains(t,i,b=!1){return b?this._http.post(`/api/warehouse/${t}/remains`,i,{headers:_}):this._http.post(`/api/warehouse/${t}/remains`,i)}static{this.\u0275fac=function(i){return new(i||r)(s(c))}}static{this.\u0275prov=a({token:r,factory:r.\u0275fac})}}return r})();A();var g=(()=>{class r{constructor(t){this._http=t}getStores(t){return this._http.get(`/api/store?viewArchive=${t}`)}createStore(t){return this._http.post("/api/store",t)}editStore(t,i){return this._http.put(`/api/store/${i}`,t)}lastSyncState(t){return this._http.get(`/api/store/${t}/last-sync-state`)}static{this.\u0275fac=function(i){return new(i||r)(s(c))}}static{this.\u0275prov=a({token:r,factory:r.\u0275fac})}}return r})();var n=class r{get selectedStore(){let e=this._stores.find(t=>t.id===this._selectedStoreId);return e||null}constructor(e,t,i){this._retailStoreServiceApi=e,this._warehouseServiceApi=t,this._store=i}getStores(e=!1){return this._retailStoreServiceApi.getStores(e).pipe(p(t=>this._store.dispatch(new m(t))),o(1))}createStore(e){return this._retailStoreServiceApi.createStore(this.toRequestModel(e)).pipe(p(()=>this.getStores().subscribe()),o(1))}editStore(e,t){return this._retailStoreServiceApi.editStore(this.toRequestModel(e),t).pipe(p(()=>{this.getStores().subscribe(),this._warehouseServiceApi.getWarehouses().pipe(o(1)).subscribe(i=>{this._store.dispatch(new f(i)),t===this._store.selectSnapshot(h.selectedStoreId)&&this._store.dispatch(new d(e.mainWarehouse))})}),o(1))}lastSyncState(e){return this._retailStoreServiceApi.lastSyncState(e).pipe(o(1))}toRequestModel(e){return{name:e.name,address:e.address,available:e.access.filter(t=>t.warehouse).map(t=>t.id),mainWarehouse:e.mainWarehouse}}static{this.\u0275fac=function(t){return new(t||r)(s(g),s(w),s(l))}}static{this.\u0275prov=a({token:r,factory:r.\u0275fac})}};u([S(h.stores)],n.prototype,"_stores",void 0);u([S(h.selectedStoreId)],n.prototype,"_selectedStoreId",void 0);export{g as a,w as b,n as c};
