import{a as y}from"./chunk-TC5W6XO4.js";import{a as f}from"./chunk-E65DJUZB.js";import{a as h,b as P}from"./chunk-CKUQY5IU.js";import{f as d}from"./chunk-IQZCMWOL.js";import{K as m,da as c,ja as s,r as u}from"./chunk-AO7NUUXN.js";import{d as l,n as _}from"./chunk-HE7HQ6LI.js";_();var I=(()=>{class i{constructor(e){this._http=e}getAllPrescripts(e){return this._http.post("/api/prescript/all",e,{headers:f})}getPrescriptsById(e){return this._http.get(`/api/prescript/${e}`)}createPrescript(e){return this._http.post("/api/prescript",e)}editPrescript(e,r){return this._http.put(`/api/prescript/${e}`,r)}deletePrescript(e){return this._http.delete(`/api/prescript/${e}`)}static{this.\u0275fac=function(r){return new(r||i)(s(d))}}static{this.\u0275prov=c({token:i,factory:i.\u0275fac})}}return i})();var v=class p{constructor(t,e){this._prescriptServiceApi=t,this._remainsService=e,this.selectedPrescriptId=null,this.activeFilters={filter:{isActualVersion:!0},search:{name:void 0}}}getPrescripts(t){return this._prescriptServiceApi.getAllPrescripts(t)}searchPrescripts(t){let e={search:{name:t},filter:{isActualVersion:!0}};return this._prescriptServiceApi.getAllPrescripts({criteria:e,take:50,skip:0,orderBy:"id",isAscending:!1})}changeSelectedId(t){this.selectedPrescriptId=t}createPrescript(t){let e=this._migrateFormToRequestModel(t);return this._prescriptServiceApi.createPrescript(e)}editPrescript(t,e){let r=this._migrateFormToRequestModel(e);return this._prescriptServiceApi.editPrescript(t,r)}getPrescriptById(t){return this._prescriptServiceApi.getPrescriptsById(t)}calculateTotalCost(t,e,r){let A={warehouseId:e,positions:t};return this._remainsService.getCalculatedProductsCost(A).pipe(P(this),u(S=>{let n=S.positions.reduce((o,a)=>o+=a.totalCost,0);return r.length&&(n+=r.reduce((o,a)=>o+=a.cost,0)),n}))}deletePrescript(t){return this._prescriptServiceApi.deletePrescript(t).pipe(m(1))}_migrateFormToRequestModel(t){return{name:t.name,resultsWarehouseId:t.resultForm.warehouseId,componentsWarehouseId:t.componentsForm.warehouseId,results:[{nomenclatureId:t.resultForm.nomenclatureId,quantity:t.resultForm.quantity}],components:t.componentsForm.products.map(e=>({nomenclatureId:e.nomenclatureId,quantity:e.quantity})),costs:t.costs.filter(e=>e.name),comment:t.comment}}static{this.\u0275fac=function(e){return new(e||p)(s(I),s(y))}}static{this.\u0275prov=c({token:p,factory:p.\u0275fac})}};v=l([h()],v);export{I as a,v as b};
