import{a as O,b as A}from"./chunk-USSZFNJ4.js";import{P as v,Q as W}from"./chunk-JE2X3YFA.js";import{J as r,O as C,Rd as g,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-4HFZZ7HS.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){this.webClientSessionService.removeSession(s.openSessionLogId).pipe(c(1)).subscribe(),this.webClientSessionService.getWebSession(s.openSessionLogId).pipe(c(1)).subscribe(e=>{e&&this.activeClosures.delete(e.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,n=s.data.connectionId;e?.connectionClosedObserver&&e.connectionClosedObserver.pipe(r(t=>t!==null),r(t=>t.connectionId===n),c(1)).subscribe({next:t=>{if(e.currentStatus.showError){e.processOnErrorClosure(t);return}this.notifySessionClosed(e,t)},error:t=>{console.error("Error during connection close handling:",t)}})}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(n=>({component:s,connectionClosedInfo:e,session:n})))),r(Boolean),r(({session:s,connectionClosedInfo:e})=>this.isValidWebSessionSession(s,e))).subscribe(({component:s,connectionClosedInfo:e,session:n})=>{s.handlePostClosureActions(n,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};
