import{c as I,d as C}from"./chunk-2PCDIQD3.js";import{a as v,b as P}from"./chunk-NGDHIM3M.js";import{a as f,b as D}from"./chunk-LK2BF24O.js";import{a as m,b as q}from"./chunk-TS62PHQY.js";import{Eb as n,Gd as y,J as c,Qb as u,Sb as p,b as l,ha as s,ia as o,ka as t,ma as b,na as g,r,x as d}from"./chunk-JSJB5BKT.js";import{e as S}from"./chunk-SZAW6ZBW.js";var E,O=S(()=>{g();b();q();y();P();C();D();E=(()=>{class a extends m{constructor(e,i,h){super(),this.editService=e,this.crudService=i,this.longOperationIndicatorService=h,this.displayDialog=!1}afterLoad(){return r(null)}afterCreate(){return r(null)}afterSave(){return r(null)}beforeDisplay(){return r(null)}beforeSave(){return r(null)}ngOnInit(){this.subscribeToEditRequest(),this.subscribeToCreateRequest()}save(){this.saveItem()}cancel(){this.callActionCancel()}saveItem(){this.longOperationIndicatorService.showIndicator(),this.beforeSave(),this.crudService.save(this.item).pipe(t(()=>this.longOperationIndicatorService.hideIndicator()),c(e=>!!e),o(this.destroyed$)).subscribe(e=>{this.item.id||(this.item.id=e),this.callActionAccept(),this.afterSave()},l,()=>this.longOperationIndicatorService.hideIndicator())}callActionAccept(e=!0){this.requestParams&&this.requestParams.accept&&(this.requestParams.accept(this.item),this.requestParams=null),e&&(this.displayDialog=!1)}callActionCancel(e=!0){this.requestParams&&this.requestParams.cancel&&(this.requestParams.cancel(),this.requestParams=null),e&&(this.displayDialog=!1)}subscribeToEditRequest(){let e=i=>this.crudService.get(i.id).pipe(d(h=>({request:i,item:h})),t(()=>this.longOperationIndicatorService.hideIndicator()));this.editService.editRequest.pipe(c(i=>i.key===this.key),t(()=>this.longOperationIndicatorService.showIndicator()),s(i=>e(i)),t(i=>this.requestParams=i.request),t(i=>this.item=i.item),s(()=>this.afterLoad()),s(()=>this.beforeDisplay()),o(this.destroyed$)).subscribe(()=>{this.displayDialog=!!this.item,this.isNew=!1},l,()=>this.longOperationIndicatorService.hideIndicator())}subscribeToCreateRequest(){this.editService.createRequest.pipe(c(e=>e.key===this.key),t(e=>this.requestParams=e),t(e=>this.item=this.crudService.create(e.data)),s(()=>this.afterCreate()),s(()=>this.beforeDisplay()),o(this.destroyed$)).subscribe(()=>{this.displayDialog=!0,this.isNew=!0})}static{this.\u0275fac=function(i){return new(i||a)(n(v),n(I),n(f))}}static{this.\u0275dir=u({type:a,features:[p]})}}return a})()});export{E as a,O as b};
