import{b as W,c as _}from"./chunk-UIN65BI3.js";import{b as g}from"./chunk-27YETXT3.js";import{a as v}from"./chunk-65ZGL2UQ.js";import{c as u}from"./chunk-3K5ADQHQ.js";import{a as m}from"./chunk-56NKV6FU.js";import{m as h}from"./chunk-SOETE4NY.js";import{a as d}from"./chunk-XVWHZ5TH.js";import{L as t,aa as a,ea as f,ka as s,la as l,r as S}from"./chunk-LEOKSAW2.js";import{d as o,n as y}from"./chunk-HE7HQ6LI.js";y();var n=class c{get warehouseOptions(){let e=this._stores.find(r=>r.id===this._storeId);return e?e.warehouses:[]}constructor(e,r,i,p){this._warehouseServiceApi=e,this._permissionService=r,this._retailStoreService=i,this._store=p,this._store$=l(h).select(u.selectedStoreId)}getWarehouses(e=!1){return this._warehouseServiceApi.getWarehouses(e).pipe(a(r=>this._store.dispatch(new v(r))),t(1))}getWarehouseAll(){return this._warehouseServiceApi.getWarehouseAll().pipe(t(1))}createWarehouse(e){return this._warehouseServiceApi.createWarehouse(e).pipe(a(()=>this.getWarehouses().subscribe()),t(1))}editWarehouse(e,r){return this._warehouseServiceApi.editWarehouse(e,r).pipe(a(()=>{this.getWarehouses().subscribe(),this._retailStoreService.getStores().subscribe()}),t(1))}getWarehouseRemains(e,r,i=!1){let p={criteria:{filter:{nomenclatureIds:r,viewArchived:!0},search:null},take:r.length??100,skip:0,isAscending:!0,orderBy:"id"};return this._warehouseServiceApi.getWarehouseRemains(e,p,i).pipe(S(w=>w.data),t(1))}getWarehouseOptionByPermission(e){let r=[];return this._store$.pipe(t(1)).subscribe(i=>{r=this.filterWarehousesByPermission(this.getStoreById(i).warehouses,e)}),r}getStoresWarehouses(e){return e?e.warehouses:[]}filterWarehousesByPermission(e,r){return r?e.filter(()=>this._permissionService.hasPermissions(r)):e}getStoreById(e){return this._stores.find(r=>r.id===e)}static{this.\u0275fac=function(r){return new(r||c)(s(W),s(g),s(_),s(h))}}static{this.\u0275prov=f({token:c,factory:c.\u0275fac})}};o([m(u.stores)],n.prototype,"_stores",void 0);o([m(u.selectedStoreId)],n.prototype,"_storeId",void 0);n=o([d()],n);export{n as a};
