import{a as g}from"./chunk-CVN2SFTO.js";import{e as x}from"./chunk-KC3FDC76.js";import{h as w,x as N}from"./chunk-6IEN3EM2.js";import{s as o,t as y,w as S,x as D}from"./chunk-DLQQOPQN.js";import{c as I,d as b}from"./chunk-PBM4LEG7.js";import{F as c,G as C,k as l,la as U,nd as V,q as h,qa as f,v as p,va as u}from"./chunk-PGS4AHIT.js";U();N();b();y();V();D();var k=(()=>{class m extends g{get model$(){return this._model$}get isEditMode(){return!this._isCreateMode&&I.isSet(this.model?.id)}setCreateMode(e){this._isCreateMode=e}constructor(e,r){super(),this.apiService=e,this.dialogService=r,this.model=null,this.modelS=new p(1),this._model$=this.modelS.asObservable(),this.currentView="",this.currentViewComponent=null,this._isCreateMode=!1}setCurrentView(e,r){this.currentView=e,this.currentViewComponent=r}saveCurrentView(){return this.currentView==="measurement-units-data"&&this.currentViewComponent?this.currentViewComponent.saveMeasurementUnit():null}unset(){this.formGroup=void 0}unsetModel(){this.model=null,this.modelS.next(null)}fetch(e){this.apiService.get(o.measurementUnits.getById(e)).subscribe({next:r=>{this.formGroup=new w([]);let t={id:r.id||r.Id,name:r.name||r.Name,interCode:r.interCode||r.InterCode};this.model=t,this.modelS.next(t)}})}fetchDefaultData(){let e={id:"",name:"",interCode:"ACR"};this.model=e,this.modelS.next(e)}saveMeasurementUnit(e){return l(this,null,function*(){if(this._isCreateMode)try{let r={Id:e.id,Name:e.name,InterCode:e.interCode||""},t=yield c(this.apiService.post(o.measurementUnits.create,r)),i={id:t.id||t.Id,name:t.name||t.Name,interCode:t.interCode||t.InterCode||""};return this.model=i,this.modelS.next(i),this._isCreateMode=!1,i}catch(r){throw r}else{let r={Id:e.id,Name:e.name,InterCode:e.interCode||""},t=yield c(this.apiService.post(o.measurementUnits.update,r)),i={id:t.id||t.Id,name:t.name||t.Name,interCode:t.interCode||t.InterCode||""};return this.model=i,this.modelS.next(i),i}})}fetchNeighbour(e,r){return new h(t=>{this.fetchList({}).subscribe({next:i=>{let a=i.items||[],s=a.findIndex(d=>d.id===e);if(s===-1){t.next(null),t.complete();return}let n=r?s-1:s+1;if(n<0||n>=a.length){t.next(null),t.complete();return}t.next(a[n]),t.complete()},error:i=>{t.error(i)}})})}fetchList(e){let r={Start:e.start||0,Length:e.length||50};e.search&&(r.Keywords=e.search);let t={id:"AcUm",name:"AcName",interCode:"AcInterUm"};return e.sortColumn&&(r.SortColumn=t[e.sortColumn]||e.sortColumn),e.sortOrder&&(r.SortOrder=e.sortOrder.toUpperCase()),this.apiService.post(o.measurementUnits.list,r).pipe(C(i=>{let s=(i.Items||i.items||[]).map(n=>({id:n.id||n.Id,name:n.name||n.Name,interCode:n.interCode||n.InterCode||""})).filter(n=>{let d=(n.id||"").trim(),v=(n.name||"").trim();return d!==""||v!==""});return{items:s,totalItems:s.length}}))}deleteMeasurementUnit(e){return this.apiService.post(o.measurementUnits.remove,{Id:e})}showErrorDialog(e){this.dialogService.open({title:"Error",text:e||"GeneralError",contentStyleClass:"paw-offset"})}static{this.\u0275fac=function(r){return new(r||m)(u(S),u(x))}}static{this.\u0275prov=f({token:m,factory:m.\u0275fac,providedIn:"root"})}}return m})();export{k as a};
