import{a as O,b as A}from"./chunk-W72U7V2U.js";import{P as v,Q as W}from"./chunk-ANSWGJBN.js";import{Gd as g,J as r,O as C,T as c,d as u,g as o,ma as x,na as I,r as S,sa as b,x as p,xa as m,ya as f,z as d}from"./chunk-JSJB5BKT.js";import{e as h}from"./chunk-SZAW6ZBW.js";function j(i){return new a(i)}var a,w=h(()=>{a=class{constructor(l){this.target=l}call(l){let s=this.target[l];return{withArgs:(...e)=>{if(typeof s=="function")return s.apply(this.target,e)}}}}});var V,y=h(()=>{g();x();I();A();w();g();W();V=(()=>{class i{constructor(s){this.currentUserService=s,this.activeClosures=new Set,this.remainingSessions=[],this.destroyed$=new o,this.webClientSessionService=f(O),this.isClosingAllSessions=!1,this.sessionCloseRequestSubject=new o,this.sessionCloseRequest$=this.sessionCloseRequestSubject.asObservable(),this.sessionClosedSubject=new o,this.sessionClosed$=this.sessionClosedSubject.asObservable(),this.postClosureCompletedSubject=new o,this.postClosureCompleted$=this.postClosureCompletedSubject.asObservable(),this.sessionCloseRequest$.subscribe(e=>{this.sendTerminateCommandToWebSession(e)}),this.postClosureCompleted$.subscribe(()=>{this.currentSessionObserver&&this.processNextSession(this.currentSessionObserver)}),this.monitorWebSessionClosure()}closeSession(s){return this.remainingSessions=[s],this.isClosingAllSessions=!1,new u(e=>{this.currentSessionObserver=e,this.processNextSession(e)})}closeAllSessions(s){return this.remainingSessions=[...s],this.isClosingAllSessions=!0,new u(e=>{this.currentSessionObserver=e,this.processNextSession(e)})}processNextSession(s){if(this.remainingSessions.length===0){this.cleanUpObserver(s);return}let e=this.remainingSessions.shift();if(!e){this.cleanUpObserver(s);return}if(this.activeClosures.has(e.sessionId)){this.processNextSession(s);return}this.activeClosures.add(e.sessionId),this.listenForConnectionClosed(e),this.sendTerminateCommandToWebSession(e)}notifySessionClosed(s,e){this.sessionClosedSubject.next({component:s,connectionClosedInfo:e})}sendTerminateCommandToWebSession(s){this.isWebSessionComponentRefValid(s)&&j(s.componentRef.instance).call("sendTerminateSessionCmd").withArgs(!0)}completeSessionClosure(s,e=!0){e&&this.webClientSessionService.removeSession(s.openSessionLogId).pipe(c(1)).subscribe(),this.webClientSessionService.getWebSession(s.openSessionLogId).pipe(c(1)).subscribe(t=>{t&&this.activeClosures.delete(t.sessionId)}),this.postClosureCompletedSubject.next(s)}cleanUpObserver(s){this.isClosingAllSessions&&(this.isClosingAllSessions=!1,this.activeClosures.clear()),s.next(),s.complete(),this.currentSessionObserver=void 0}listenForConnectionClosed(s){let e=s.componentRef?.instance,t=s.data.connectionId;e?.connectionClosedObserver&&e.connectionClosedObserver.pipe(r(n=>n!==null),r(n=>n.connectionId===t),c(1)).subscribe({next:n=>{if(e.currentStatus.showError){e.processOnErrorClosure(n);return}this.notifySessionClosed(e,n)},error:n=>{console.error("Error during connection close handling:",n)}})}isWebSessionComponentRefValid(s){return s&&s.componentRef}isValidWebSessionSession(s,e){return s!==null&&s.data.connectionId===e.connectionId}fetchSession(s){return this.webClientSessionService.getWebSession(s).pipe(C(e=>(console.error("Error fetching session:",e),S(null))))}monitorWebSessionClosure(){this.sessionClosed$.pipe(d(({component:s,connectionClosedInfo:e})=>this.fetchSession(e.openSessionLogId).pipe(p(t=>({component:s,connectionClosedInfo:e,session:t})))),r(Boolean),r(({session:s,connectionClosedInfo:e})=>this.isValidWebSessionSession(s,e))).subscribe(({component:s,connectionClosedInfo:e,session:t})=>{s.handlePostClosureActions(t,e)})}static{this.\u0275fac=function(e){return new(e||i)(m(v))}}static{this.\u0275prov=b({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})()});export{j as a,w as b,V as c,y as d};
