import{a as w,b as v}from"./chunk-Y4KZVCMP.js";import{a as _,c as l}from"./chunk-UU4K5RCK.js";import{a as d}from"./chunk-F24KRXZV.js";import{p as f}from"./chunk-JBWPPKX4.js";import{a as h}from"./chunk-7N232KV6.js";import{i as u}from"./chunk-NDLDFKR2.js";import{$ as n,K as a,fa as c,ka as s}from"./chunk-PVUKHE45.js";import{d as m,n as W}from"./chunk-VD6R3735.js";var A=(()=>{let t=class t{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:h})}getWarehouseRemains(e,i,g=!1){return g?this._http.post(`/api/warehouse/${e}/remains`,i,{headers:h}):this._http.post(`/api/warehouse/${e}/remains`,i)}};t.\u0275fac=function(i){return new(i||t)(s(u))},t.\u0275prov=c({token:t,factory:t.\u0275fac});let o=t;return o})();W();var b=(()=>{let t=class t{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:h})}};t.\u0275fac=function(i){return new(i||t)(s(u))},t.\u0275prov=c({token:t,factory:t.\u0275fac});let o=t;return o})();var p=class p{get selectedStore(){let t=this._stores.find(r=>r.id===this._selectedStoreId);return t||null}constructor(t,r,e){this._retailStoreServiceApi=t,this._warehouseServiceApi=r,this._store=e}getStores(t=!1){return this._retailStoreServiceApi.getStores(t).pipe(n(r=>this._store.dispatch(new _(r))),a(1))}createStore(t){return this._retailStoreServiceApi.createStore(this.toRequestModel(t)).pipe(n(()=>this.getStores().subscribe()),a(1))}editStore(t,r){return this._retailStoreServiceApi.editStore(this.toRequestModel(t),r).pipe(n(()=>{this.getStores().subscribe(),this._warehouseServiceApi.getWarehouses().pipe(a(1)).subscribe(e=>{this._store.dispatch(new w(e)),r===this._store.selectSnapshot(l.selectedStoreId)&&this._store.dispatch(new v(t.mainWarehouse))})}),a(1))}lastSyncState(t){return this._retailStoreServiceApi.lastSyncState(t).pipe(a(1))}syncStore(){return this._retailStoreServiceApi.syncStore().pipe(a(1))}toRequestModel(t){return{name:t.name,address:t.address,available:t.warehouseAccess.filter(r=>r.warehouse).map(r=>r.id),mainWarehouse:t.mainWarehouse,defaultPriceId:t.defaultPriceId,availablePriceIds:t.priceAccess.filter(r=>r.price).map(r=>r.id)}}};p.\u0275fac=function(r){return new(r||p)(s(b),s(A),s(f))},p.\u0275prov=c({token:p,factory:p.\u0275fac});var S=p;m([d(l.stores)],S.prototype,"_stores",void 0);m([d(l.selectedStoreId)],S.prototype,"_selectedStoreId",void 0);export{b as a,A as b,S as c};
//# sourceMappingURL=chunk-Z6SX4HYB.js.map
