import{a as T}from"./chunk-CVN2SFTO.js";import{e as I}from"./chunk-HLN3LAM6.js";import{h as x,x as N}from"./chunk-6IEN3EM2.js";import{s as c,t as F,w as S,x as L}from"./chunk-MY54U2QA.js";import{c as C,d as D}from"./chunk-E7BKRPHP.js";import{F as y,k as f,la as v,nd as b,q as d,qa as V,v as g,va as w}from"./chunk-PGS4AHIT.js";N();v();D();F();b();L();var $=(()=>{class a extends T{get model$(){return this._model$}get isEditMode(){return!this._isCreateMode&&C.isSet(this.model?.id)}setCreateMode(e){this._isCreateMode=e}constructor(e,n){super(),this.apiService=e,this.dialogService=n,this.model=null,this.modelS=new g(1),this._model$=this.modelS.asObservable(),this.currentView="",this.currentViewComponent=null,this._isCreateMode=!1}setCurrentView(e,n){this.currentView=e,this.currentViewComponent=n}saveCurrentView(){return this.currentView==="accounting-types-data"&&this.currentViewComponent?this.currentViewComponent.saveAccountingType():null}unset(){this.formGroup=void 0}unsetModel(){this.model=null,this.modelS.next(null)}fetch(e){this.apiService.get(c.accountingTypes.getById(e)).subscribe({next:n=>{this.formGroup=new x([]);let t={id:n.id||n.Id,name:n.name||n.Name,type:n.type||n.Type,fullView:n.fullView||n.FullView};this.model=t,this.modelS.next(t)}})}fetchDefaultData(){let e={id:"",name:"",type:"P"};this.model=e,this.modelS.next(e)}saveAccountingType(e){return f(this,null,function*(){if(this._isCreateMode)try{let n={Id:e.id,Name:e.name,Type:e.type},t=yield y(this.apiService.post(c.accountingTypes.create,n)),r={id:t.id||t.Id,name:t.name||t.Name,type:t.type||t.Type,fullView:t.fullView||t.FullView};return this.model=r,this.modelS.next(r),this._isCreateMode=!1,r}catch(n){throw n}else{let n={Id:e.id,Name:e.name,Type:e.type},t=yield y(this.apiService.post(c.accountingTypes.update,n)),r={id:t.id||t.Id,name:t.name||t.Name,type:t.type||t.Type,fullView:t.fullView||t.FullView};return this.model=r,this.modelS.next(r),r}})}fetchNeighour(e,n){return new d(t=>{this.fetchList({}).subscribe({next:r=>{let o=r.items||[],u=o.findIndex(i=>i.id===e);if(u===-1){t.next(null),t.complete();return}let l=n?u-1:u+1;if(l<0||l>=o.length){t.next(null),t.complete();return}t.next(o[l]),t.complete()},error:r=>{t.error(r)}})})}fetchList(e){return new d(n=>{this.apiService.get(c.accountingTypes.list).subscribe({next:t=>{let r=t.map(i=>({id:i.id||i.Id,name:i.name||i.Name,type:i.type||i.Type,fullView:i.fullView||i.FullView}));if(e.search){let i=e.search.toLowerCase();r=r.filter(s=>s.id?.toLowerCase().includes(i)||s.name?.toLowerCase().includes(i)||s.type?.toLowerCase().includes(i))}e.sortColumn&&e.sortOrder&&r.sort((i,s)=>{let p=i[e.sortColumn],m=s[e.sortColumn],h=e.sortOrder==="asc"?1:-1;return p<m?-1*h:p>m?1*h:0}),e.type&&e.type!==""&&(r=r.filter(i=>i.type===e.type)),e.sortColumn&&e.sortOrder&&r.sort((i,s)=>{let p=i[e.sortColumn],m=s[e.sortColumn],h=e.sortOrder==="asc"?1:-1;return p<m?-1*h:p>m?1*h:0});let o=e.start||0,u=e.length&&e.length>=r.length?e.length:r.length,l=r.slice(o,o+u);n.next({items:l,totalItems:r.length}),n.complete()},error:t=>n.error(t)})})}deleteAccountingType(e){return this.apiService.post(c.accountingTypes.remove,{Id:e})}showErrorDialog(e){this.dialogService.open({title:"Error",text:e||"GeneralError",contentStyleClass:"paw-offset"})}static{this.\u0275fac=function(n){return new(n||a)(w(S),w(I))}}static{this.\u0275prov=V({token:a,factory:a.\u0275fac,providedIn:"root"})}}return a})();export{$ as a};
