import{a as V}from"./chunk-SFW4HL5C.js";import{e as x}from"./chunk-XRN7CRXN.js";import{h as g,x as O}from"./chunk-FCHM4KKB.js";import{q as p,r as T,u as S,v as L}from"./chunk-Y4JXSDKI.js";import{c as A,d as D}from"./chunk-I6HXBYFU.js";import{F as d,k as v,la as I,od as b,q as l,qa as w,v as y,va as m}from"./chunk-HEIW4SFT.js";I();O();D();T();b();L();var R=(()=>{class o extends V{get model$(){return this._model$}get isEditMode(){return!this._isCreateMode&&A.isSet(this.model?.id)}setCreateMode(e){this._isCreateMode=e}constructor(e,s){super(),this.apiService=e,this.dialogService=s,this.model=null,this.modelS=new y(1),this._model$=this.modelS.asObservable(),this.selectedProductClassifications=[],this.currentView="",this.currentViewComponent=null,this._isCreateMode=!1}setCurrentView(e,s){this.currentView=e,this.currentViewComponent=s}saveCurrentView(){return this.currentView==="product-classifications-data"&&this.currentViewComponent?this.currentViewComponent.saveProductClassification():null}unset(){this.formGroup=void 0}unsetModel(){this.model=null,this.modelS.next(null)}fetch(e){this.apiService.get(p.productClassifications.getById(e)).subscribe({next:s=>{this.formGroup=new g([]);let i={id:s.id,name:s.name,vatCode:s.vatCode,type:s.type,isActive:s.isActive};this.model=i,this.modelS.next(i)}})}fetchDefaultData(){let e={id:"",name:"",vatCode:"",type:"O",isActive:!0};this.model=e,this.modelS.next(e)}saveProductClassification(e){return v(this,null,function*(){if(this._isCreateMode)try{let s={Id:e.id,Name:e.name,VATCode:e.vatCode||"",Type:e.type||"",IsActive:e.isActive},i=yield d(this.apiService.post(p.productClassifications.create,s)),t={id:i.id||i.Id,name:i.name||i.Name,vatCode:i.vatCode||i.VATCode,type:i.type||i.Type,isActive:i.isActive===!0||i.IsActive===!0};return this.model=t,this.modelS.next(t),this._isCreateMode=!1,t}catch(s){throw s}else{let s=e.name.replace(/^[^-]+\s*-\s*/,""),i={Id:e.id,Name:s,VATCode:e.vatCode||"",Type:e.type||"",IsActive:e.isActive},t=yield d(this.apiService.post(p.productClassifications.update,i)),n={id:t.id||t.Id,name:t.name||t.Name,vatCode:t.vatCode||t.VATCode,type:t.type||t.Type,isActive:t.isActive===!0||t.IsActive===!0};return this.model=n,this.modelS.next(n),n}})}fetchNeighbour(e,s){return new l(i=>{this.fetchList({}).subscribe({next:t=>{let n=t.items||[],a=n.findIndex(r=>r.id===e);if(a===-1){i.next(null),i.complete();return}let c=s?a-1:a+1;if(c<0||c>=n.length){i.next(null),i.complete();return}i.next(n[c]),i.complete()},error:t=>{i.error(t)}})})}fetchList(e){return new l(s=>{this.apiService.get(p.productClassifications.list).subscribe({next:i=>{let t=i.map(r=>({id:r.id,name:r.name,vatCode:r.vatCode,type:r.type,isActive:r.isActive}));if(e.search){let r=e.search.toLowerCase();t=t.filter(u=>u.id?.toLowerCase().includes(r)||u.name?.toLowerCase().includes(r)||u.type?.toLowerCase().includes(r))}e.type&&e.type!=="all"&&(t=t.filter(r=>e.type==="P"?r.type==="P":e.type==="S"?r.type==="S":e.type==="O"?r.type==="O":!0)),e.status&&e.status!=="all"&&(t=t.filter(r=>e.status==="active"?r.isActive===!0:e.status==="inactive"?r.isActive===!1:!0)),e.sortColumn&&e.sortOrder&&t.sort((r,u)=>{let h=r[e.sortColumn],C=u[e.sortColumn],f=e.sortOrder==="asc"?1:-1;return h<C?-1*f:h>C?1*f:0});let n=e.start||0,a=e.length&&e.length>=t.length?e.length:t.length,c=t.slice(n,n+a);s.next({items:c,totalItems:t.length}),s.complete()},error:i=>s.error(i)})})}showErrorDialog(e){this.dialogService.open({title:"Error",text:e||"GeneralError",contentStyleClass:"paw-offset"})}static{this.\u0275fac=function(s){return new(s||o)(m(S),m(x))}}static{this.\u0275prov=w({token:o,factory:o.\u0275fac,providedIn:"root"})}}return o})();export{R as a};
