import{a as x}from"./chunk-SFW4HL5C.js";import{e as S}from"./chunk-MNHXVU2U.js";import{h as b,y as P}from"./chunk-WEQN5LYX.js";import{s as a,t as F,w as v,x as G}from"./chunk-BYO7JUDG.js";import{c as V,d as D}from"./chunk-YADAVUVK.js";import{F as y,k as f,la as T,od as I,q as h,qa as C,v as g,va as w}from"./chunk-HEIW4SFT.js";P();T();D();F();I();G();var B=(()=>{class l extends x{get model$(){return this._model$}get isEditMode(){return!this._isCreateMode&&V.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(a.accountingTypes.getById(e)).subscribe({next:n=>{this.formGroup=new b([]);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(a.accountingTypes.create,n)),i={id:t.id||t.Id,name:t.name||t.Name,type:t.type||t.Type,fullView:t.fullView||t.FullView};return this.model=i,this.modelS.next(i),this._isCreateMode=!1,i}catch(n){throw n}else{let n={Id:e.id,Name:e.name,Type:e.type},t=yield y(this.apiService.post(a.accountingTypes.update,n)),i={id:t.id||t.Id,name:t.name||t.Name,type:t.type||t.Type,fullView:t.fullView||t.FullView};return this.model=i,this.modelS.next(i),i}})}fetchNeighour(e,n){return new h(t=>{this.fetchList({}).subscribe({next:i=>{let o=i.items||[],c=o.findIndex(s=>s.id===e);if(c===-1){t.next(null),t.complete();return}let u=n?c-1:c+1;if(u<0||u>=o.length){t.next(null),t.complete();return}t.next(o[u]),t.complete()},error:i=>{t.error(i)}})})}fetchList(e){return new h(n=>{this.apiService.get(a.accountingTypes.list).subscribe({next:t=>{let i=t.map(s=>({id:s.id||s.Id,name:s.name||s.Name,type:s.type||s.Type,fullView:s.fullView||s.FullView}));if(e.search){let s=e.search.toLowerCase();i=i.filter(r=>r.id?.toLowerCase().includes(s)||r.name?.toLowerCase().includes(s)||r.type?.toLowerCase().includes(s))}e.sortColumn&&e.sortOrder&&i.sort((s,r)=>{let p=s[e.sortColumn],m=r[e.sortColumn],d=e.sortOrder==="asc"?1:-1;return p<m?-1*d:p>m?1*d:0}),e.type&&e.type!==""&&(i=i.filter(s=>s.type===e.type)),e.sortColumn&&e.sortOrder&&i.sort((s,r)=>{let p=s[e.sortColumn],m=r[e.sortColumn],d=e.sortOrder==="asc"?1:-1;return p<m?-1*d:p>m?1*d:0});let o=e.start||0,c=e.length&&e.length>=i.length?e.length:i.length,u=i.slice(o,o+c);n.next({items:u,totalItems:i.length}),n.complete()},error:t=>n.error(t)})})}deleteAccountingType(e){return this.apiService.post(a.accountingTypes.remove,{Id:e})}static{this.\u0275fac=function(n){return new(n||l)(w(v),w(S))}}static{this.\u0275prov=C({token:l,factory:l.\u0275fac,providedIn:"root"})}}return l})();var U=[{value:"P",label:"ProductEnum"},{value:"B",label:"Goods"},{value:"C",label:"CompositeGoods"},{value:"K",label:"CommissionGoods"},{value:"A",label:"PackagedGoods"},{value:"M",label:"Material"},{value:"E",label:"Packaging"},{value:"S",label:"Service"},{value:"U",label:"CompiledService"},{value:"G",label:"CommodityPackage"},{value:"H",label:"ServicePackage"},{value:"F",label:"FixedAssets"},{value:"R",label:"Rent"}];export{B as a,U as b};
