import{a as f,b as d}from"./chunk-65ZGL2UQ.js";import{a as m,c as h}from"./chunk-6GCD7JC6.js";import{a as l}from"./chunk-B7E4YH53.js";import{m as S}from"./chunk-A7R3CFJO.js";import{x as c}from"./chunk-OIJW4GMG.js";import{J as a,_ as p,ca as o,ia as s}from"./chunk-3FIHWXA5.js";import{b as u,i as b}from"./chunk-QOJKCMZT.js";b();var v=(()=>{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)}static{this.\u0275fac=function(i){return new(i||r)(s(c))}}static{this.\u0275prov=o({token:r,factory:r.\u0275fac})}}return r})();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)}getWarehouseRemains(e,i){return this._http.post(`/api/warehouse/${e}/remains`,i)}static{this.\u0275fac=function(i){return new(i||r)(s(c))}}static{this.\u0275prov=o({token:r,factory:r.\u0275fac})}}return r})();var n=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(p(e=>this._store.dispatch(new m(e))),a(1))}createStore(t){return this._retailStoreServiceApi.createStore(this.toRequestModel(t)).pipe(p(()=>this.getStores().subscribe()),a(1))}editStore(t,e){return this._retailStoreServiceApi.editStore(this.toRequestModel(t),e).pipe(p(()=>{this.getStores().subscribe(),this._warehouseServiceApi.getWarehouses().pipe(a(1)).subscribe(i=>{this._store.dispatch(new f(i)),e===this._store.selectSnapshot(h.selectedStoreId)&&this._store.dispatch(new d(t.mainWarehouse))})}),a(1))}toRequestModel(t){return{name:t.name,address:t.address,available:t.access.filter(e=>e.warehouse).map(e=>e.id),mainWarehouse:t.mainWarehouse}}static{this.\u0275fac=function(e){return new(e||r)(s(v),s(w),s(S))}}static{this.\u0275prov=o({token:r,factory:r.\u0275fac})}};u([l(h.stores)],n.prototype,"_stores",void 0);u([l(h.selectedStoreId)],n.prototype,"_selectedStoreId",void 0);export{v as a,w as b,n as c};
