import{a as f,b as d}from"./chunk-65ZGL2UQ.js";import{a as m,c as h}from"./chunk-UIHP5NJO.js";import{a as S}from"./chunk-S77V5ZYX.js";import{m as l}from"./chunk-WMRP6X7F.js";import{e as c}from"./chunk-EMTGVP7F.js";import{$ as p,K as o,da as a,ja as s}from"./chunk-A4WWLITB.js";import{b as u,i as g}from"./chunk-QOJKCMZT.js";g();var v=(()=>{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 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){return 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})();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(v),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{v as a,w as b,n as c};
