import {P,Z,S,R as Re}from'./chunk-BDxusv17.js';import {J,c as tS,d5 as Aa,a6 as pi,a5 as fh,aZ as Dt,H as ul,aM as AD,ag as lp,bP as he,aG as br,L as w,d6 as Do,bE as ff,aJ as hf,ah as ot,aq as Sr,ay as df,a8 as x,bS as ke,al as Kv,ak as Jd,aa as ye,b6 as Yi,N as Sr$1,aN as r4,am as Dh,ad as ce}from'./main-WUGO6e7n.js';var oe,V=J(()=>{tS();Aa();pi();fh();P();tS();Dt();ul();Z();AD();lp();oe=(()=>{class s{constructor(e,r,n,i,o){this.messageService=e,this.translatorService=r,this.authenticationConfigurationService=n,this.serverInformationService=i,this.assetServices=o,this.destroyed$=new he,this.azureConfiguration=new br(new S),this.httpClient=w(Do),this.azureConfiguration$=this.azureConfiguration.asObservable();}ngOnDestroy(){this.destroyed$.next();}fetchAzureConfiguration(){this.authenticationConfigurationService.getAzureAuthenticationConfiguration().pipe(ff(this.destroyed$),hf(e=>e.useClientIdForCache=e.usersRolesCacheClientId?.length>0)).subscribe(e=>this.azureConfiguration.next(e));}isCacheEnabled(){return this.assetServices.GetAzureAuthenticationIsCacheEnabled().pipe(ot(e=>!!e.data))}save(e){return e.useClientIdForCache||(e.usersRolesCacheClientId=null),this.authenticationConfigurationService.saveAzureAuthenticationConfiguration(e).pipe(ff(this.destroyed$),Sr(r=>r),hf(()=>{this.fetchAzureConfiguration(),this.serverInformationService.update();}))}testConnection(e){e.useClientIdForCache||(e.usersRolesCacheClientId=null),this.authenticationConfigurationService.testAzureSync(e).pipe(ff(this.destroyed$)).subscribe(r=>{r?this.messageService.add({key:"globalToast",severity:"success",summary:this.translatorService.translate("Success"),detail:this.translatorService.translate("ConnectedSuccessfully")}):this.messageService.add({key:"globalToast",severity:"error",summary:this.translatorService.translate("Failed"),detail:this.translatorService.translate("ConnectionFailed")});});}connectToMicrosoft(e){let r=e?`api/configuration/authentication/azure/connect?providerId=${e}`:"api/configuration/authentication/azure/connect",n=window.open("about:blank","dvls-azure-connect","width=600,height=700,scrollbars=yes");return this.httpClient.post(r,null).pipe(df(i=>i?.data?n?(n.location.href=i.data,new x(o=>{let u=!1,m=t=>{u||t?.type!=="azure-connect-result"||(u=!0,p(),o.next({success:t.connectResult==="success",upn:t.connectUPN,error:t.connectError,errorDescription:t.connectErrorDescription,hintMismatch:t.connectHintMismatch===!0,configuredHint:t.connectConfiguredHint}),o.complete());},v=new BroadcastChannel("dvls-azure-connect");v.onmessage=t=>m(t.data);let g=t=>{if(!(t.key!=="dvls-azure-connect-result"||!t.newValue)){try{m(JSON.parse(t.newValue));}catch(G){}localStorage.removeItem("dvls-azure-connect-result");}};window.addEventListener("storage",g);let C=setInterval(()=>{try{n.closed&&!u&&(u=!0,p(),o.next({success:!1,error:"popup_closed"}),o.complete());}catch(t){clearInterval(C);}},1e3);function p(){v.close(),window.removeEventListener("storage",g),clearInterval(C);}return ()=>p()})):(window.location.href=i.data,ke):(n?.close(),Kv({success:!1,error:"no_auth_url",errorDescription:i?.errorMessage}))),Jd(i=>(n?.close(),this.messageService.add({key:"globalToast",severity:"error",summary:this.translatorService.translate("Failed"),detail:i?.error?.errorMessage||"Failed to initiate connection"}),Kv({success:!1,error:"api_error"}))))}disconnect(e){let r=e?`api/configuration/authentication/azure/disconnect?providerId=${e}`:"api/configuration/authentication/azure/disconnect";return this.httpClient.post(r,null).pipe(ot(()=>!0),Jd(()=>Kv(!1)))}getDelegatedStatus(e){let r=e?`api/configuration/authentication/azure/delegated-status?providerId=${e}`:"api/configuration/authentication/azure/delegated-status",n={status:"not_configured"};return this.httpClient.get(r).pipe(ot(i=>i?.data?JSON.parse(i.data):n),Jd(()=>Kv(n)))}static{this.\u0275fac=function(r){return new(r||s)(ye(Yi),ye(Sr$1),ye(Re),ye(r4),ye(Dh))};}static{this.\u0275prov=ce({token:s,factory:s.\u0275fac,providedIn:"root"});}}return s})();});export{V,oe as o};