import{c as v}from"./chunk-ZL27GBK5.js";import{a as x}from"./chunk-SFW4HL5C.js";import{h as w,y as D}from"./chunk-WEQN5LYX.js";import{s as o,t as b,w as S,x as y}from"./chunk-EAEGBVDW.js";import{c as I,d as N}from"./chunk-FD5DZJ6H.js";import{F as d,G as C,k as h,la as V,od as g,q as l,qa as f,v as p,va as u}from"./chunk-HEIW4SFT.js";V();D();N();b();g();y();var E=(()=>{class m extends x{get model$(){return this._model$}get isEditMode(){return!this._isCreateMode&&I.isSet(this.model?.id)}setCreateMode(e){this._isCreateMode=e}constructor(e,i){super(),this.apiService=e,this.notificationService=i,this.model=null,this.modelS=new p(1),this._model$=this.modelS.asObservable(),this.currentView="",this.currentViewComponent=null,this._isCreateMode=!1}setCurrentView(e,i){this.currentView=e,this.currentViewComponent=i}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:i=>{this.formGroup=new w([]);let t={id:i.id||i.Id,name:i.name||i.Name,interCode:i.interCode||i.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 h(this,null,function*(){if(this._isCreateMode)try{let i={Id:e.id,Name:e.name,InterCode:e.interCode||""},t=yield d(this.apiService.post(o.measurementUnits.create,i)),r={id:t.id||t.Id,name:t.name||t.Name,interCode:t.interCode||t.InterCode||""};return this.model=r,this.modelS.next(r),this._isCreateMode=!1,r}catch(i){throw i}else{let i={Id:e.id,Name:e.name,InterCode:e.interCode||""},t=yield d(this.apiService.post(o.measurementUnits.update,i)),r={id:t.id||t.Id,name:t.name||t.Name,interCode:t.interCode||t.InterCode||""};return this.model=r,this.modelS.next(r),r}})}fetchNeighbour(e,i){return new l(t=>{this.fetchList({}).subscribe({next:r=>{let a=r.items||[],s=a.findIndex(c=>c.id===e);if(s===-1){t.next(null),t.complete();return}let n=i?s-1:s+1;if(n<0||n>=a.length){t.next(null),t.complete();return}t.next(a[n]),t.complete()},error:r=>{t.error(r)}})})}fetchList(e){let i={Start:e.start||0,Length:e.length||50};e.search&&(i.Keywords=e.search);let t={id:"AcUm",name:"AcName",interCode:"AcInterUm"};return e.sortColumn&&(i.SortColumn=t[e.sortColumn]||e.sortColumn),e.sortOrder&&(i.SortOrder=e.sortOrder.toUpperCase()),this.apiService.post(o.measurementUnits.list,i).pipe(C(r=>{let s=(r.Items||r.items||[]).map(n=>({id:n.id||n.Id,name:n.name||n.Name,interCode:n.interCode||n.InterCode||""})).filter(n=>{let c=(n.id||"").trim(),U=(n.name||"").trim();return c!==""||U!==""});return{items:s,totalItems:s.length}}))}deleteMeasurementUnit(e){return this.apiService.post(o.measurementUnits.remove,{Id:e})}showErrorNotification(e){this.notificationService.error(e||"GeneralError")}static{this.\u0275fac=function(i){return new(i||m)(u(S),u(v))}}static{this.\u0275prov=f({token:m,factory:m.\u0275fac,providedIn:"root"})}}return m})();export{E as a};
