import{a as w,b as y}from"./chunk-Y4KZVCMP.js";import{a as _,c as l}from"./chunk-BYOG7O4N.js";import{a as m}from"./chunk-4QCIIFWS.js";import{n as f}from"./chunk-DC6G5OHZ.js";import{a as h}from"./chunk-JUPKAJPM.js";import{i as u}from"./chunk-Z2AWIQRI.js";import{L as a,aa as n,ia as c,na as s}from"./chunk-C2QKZJOP.js";import{d,n as W}from"./chunk-INB5GR2I.js";var g=(()=>{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,A=!1){return A?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 y(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.access.filter(r=>r.warehouse).map(r=>r.id),mainWarehouse:t.mainWarehouse,defaultPriceId:t.defaultPriceId===0?null:t.defaultPriceId}}};p.\u0275fac=function(r){return new(r||p)(s(b),s(g),s(f))},p.\u0275prov=c({token:p,factory:p.\u0275fac});var S=p;d([m(l.stores)],S.prototype,"_stores",void 0);d([m(l.selectedStoreId)],S.prototype,"_selectedStoreId",void 0);export{b as a,g as b,S as c};
//# sourceMappingURL=chunk-4WBIDQ26.js.map
