import{a as T}from"./chunk-THKS2M3R.js";import{g as O}from"./chunk-RQCMKSAN.js";import{h as L}from"./chunk-NMMBNW5X.js";import{m as i,n as V}from"./chunk-GJIGZB63.js";import{b as x}from"./chunk-5VDVFGVW.js";import{B as m,a as p,g as w,ka as M,m as d,pa as f,q as b,r as C}from"./chunk-J476KISY.js";var $=(()=>{class h extends T{get model$(){return this._model$}get isEditMode(){return!this._isCreateMode&&x.isSet(this.model?.paymentMethod)}setCreateMode(e){this._isCreateMode=e}constructor(e,t){super(),this.apiService=e,this.dialogService=t,this.model=null,this.modelS=new C(1),this._model$=this.modelS.asObservable(),this.isLoadingS=new b(!1),this.isLoading$=this.isLoadingS.asObservable(),this.selectedPaymentMethods=[],this.currentView="",this.currentViewComponent=null,this._isCreateMode=!1}setCurrentView(e,t){this.currentView=e,this.currentViewComponent=t}saveCurrentView(){return this.currentView==="payment-methods-data"&&this.currentViewComponent?this.currentViewComponent.savePaymentMethod():null}unset(){this.formGroup=void 0}unsetModel(){this.model=null,this.modelS.next(null)}fetch(e){this.isLoadingS.next(!0),this.apiService.get(i.paymentMethods.getById(e)).subscribe({next:t=>{this.formGroup=new L([]),this.model=t,this.modelS.next(t),this.isLoadingS.next(!1)},error:t=>{this.isLoadingS.next(!1)}})}fetchDefaultData(){let e={paymentMethod:"",name:"",paymentType:"",active:!0,setOf:"",fiscalGroup:"",fiscalGroupMn:"",slipType:"",icon:null};this.model=e,this.modelS.next(e),this.isLoadingS.next(!1)}savePaymentMethod(e){return w(this,null,function*(){if(this._isCreateMode)try{let t={PaymentMethod:e.paymentMethod,Name:e.name,SetOf:e.setOf,PaymentType:e.paymentType,FiscalGroup:e.fiscalGroup,FiscalGroupMn:e.fiscalGroupMn||"",SlipType:e.slipType||"0",Active:e.active,Icon:e.icon||null},l=yield m(this.apiService.post(i.paymentMethods.create,t)),a=yield m(this.apiService.get(i.paymentMethods.getById(l)));return this.model=a,this.modelS.next(a),this._isCreateMode=!1,a}catch(t){throw t}else{let t=yield m(this.apiService.put(i.paymentMethods.update,e));return this.model=t,this.modelS.next(t),t}})}fetchNeighour(e,t){return this.apiService.get(i.paymentMethods.getNeighbour(e,t))}fetchList(e){let t={Start:0,Length:1e4},l=new URLSearchParams;Object.keys(t).forEach(s=>{t[s]!==null&&t[s]!==void 0&&l.append(s,t[s].toString())});let a=`${i.paymentMethods.list}?${l.toString()}`;return this.apiService.get(a).pipe(s=>new d(c=>{s.subscribe({next:r=>{let o=r.items||[];if(e.search){let n=e.search.toLowerCase();o=o.filter(u=>u.paymentMethod?.toLowerCase().includes(n)||u.name?.toLowerCase().includes(n)||u.designation?.toLowerCase().includes(n))}e.status&&e.status!=="all"&&(o=o.filter(n=>e.status==="active"?n.active===!0:e.status==="inactive"?n.active===!1:!0)),e.sortColumn&&e.sortOrder&&o.sort((n,u)=>{let g=n[e.sortColumn],v=u[e.sortColumn],y=e.sortOrder==="asc"?1:-1;return g<v?-1*y:g>v?1*y:0});let S=e.start||0,D=e.length&&e.length>=o.length?e.length:o.length,G=o.slice(S,S+D);c.next({items:G,totalItems:o.length}),c.complete()},error:r=>c.error(r)})}))}deletePaymentMethod(e){return this.apiService.post(i.paymentMethods.remove,{Id:e})}deleteMultiplePaymentMethods(e){let t={totalRequested:e.length,successfulDeletes:0,errors:[]};return new d(l=>{let a=s=>{if(s>=e.length){l.next(t),l.complete();return}let c=e[s];this.deletePaymentMethod(c).subscribe({next:r=>{r&&(r.isDeleted===!0||r.IsDeleted===!0||r.success===!0)?t.successfulDeletes++:t.errors.push({paymentMethodId:c,errorType:0,errorMessage:r?.error||r?.Error||r?.message||"UnknownError"}),a(s+1)},error:r=>{t.errors.push({paymentMethodId:c,errorType:1,errorMessage:r?.message||"NetworkError"}),a(s+1)}})};a(0)})}showErrorDialog(e){this.dialogService.open({title:"Error",text:e||"GeneralError",contentStyleClass:"paw-offset"})}saveForm(e){return this.isEditMode?this.apiService.put(i.paymentMethods.update,p({},e)):this.apiService.post(i.paymentMethods.create,p({},e))}create(e){return this.apiService.post(i.paymentMethods.create,p({},e))}static{this.\u0275fac=function(t){return new(t||h)(f(V),f(O))}}static{this.\u0275prov=M({token:h,factory:h.\u0275fac,providedIn:"root"})}}return h})();var R=[{value:"0",label:"Ni slipa"},{value:"1",label:"\u010Cek"},{value:"2",label:"Trajni nalog"},{value:"3",label:"Kartica"},{value:"T",label:"Turisti\u010Dki bon"}];export{$ as a,R as b};
