import{c as D,d as V,i as O,j as G}from"./chunk-IZPKALVP.js";import{m as x,n as U}from"./chunk-SM7EQ7ST.js";import{Gk as T,Hk as L}from"./chunk-BPZQKZKD.js";import{Da as F,La as J}from"./chunk-5E3JCGAH.js";import{m as k,q as P}from"./chunk-HTXYTVN4.js";import{b as E,c as B}from"./chunk-YBNTOQCK.js";import{J as I,O as h,Sa as N,be as $,d as y,g as z,h as b,ha as A,ia as d,ka as m,l as w,na as H,r as c,ta as j,x as l,xa as s,ya as M}from"./chunk-WL5U2YIT.js";import{e as R}from"./chunk-ADEKKGI2.js";var oe,Y=R(()=>{$();P();H();N();V();$();J();B();G();U();L();oe=(()=>{let o=class o{constructor(e,t,n,i,a){this.messageService=e,this.translatorService=t,this.authenticationConfigurationService=n,this.serverInformationService=i,this.assetServices=a,this.destroyed$=new z,this.azureConfiguration=new b(new D),this.httpClient=M(k),this.azureConfiguration$=this.azureConfiguration.asObservable()}ngOnDestroy(){this.destroyed$.next()}fetchAzureConfiguration(){this.authenticationConfigurationService.getAzureAuthenticationConfiguration().pipe(d(this.destroyed$),m(e=>e.useClientIdForCache=e.usersRolesCacheClientId?.length>0)).subscribe(e=>this.azureConfiguration.next(e))}isCacheEnabled(){return this.assetServices.GetAzureAuthenticationIsCacheEnabled().pipe(l(e=>!!e.data))}save(e){return e.useClientIdForCache||(e.usersRolesCacheClientId=null),this.authenticationConfigurationService.saveAzureAuthenticationConfiguration(e).pipe(d(this.destroyed$),I(t=>t),m(()=>{this.fetchAzureConfiguration(),this.serverInformationService.update()}))}testConnection(e){e.useClientIdForCache||(e.usersRolesCacheClientId=null),this.authenticationConfigurationService.testAzureSync(e).pipe(d(this.destroyed$)).subscribe(t=>{t?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 t=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(t,null).pipe(A(i=>i?.data?n?(n.location.href=i.data,new y(a=>{let u=!1,g=r=>{u||r?.type!=="azure-connect-result"||(u=!0,f(),a.next({success:r.connectResult==="success",upn:r.connectUPN,error:r.connectError,errorDescription:r.connectErrorDescription,hintMismatch:r.connectHintMismatch===!0,configuredHint:r.connectConfiguredHint}),a.complete())},v=new BroadcastChannel("dvls-azure-connect");v.onmessage=r=>g(r.data);let C=r=>{if(!(r.key!=="dvls-azure-connect-result"||!r.newValue)){try{g(JSON.parse(r.newValue))}catch{}localStorage.removeItem("dvls-azure-connect-result")}};window.addEventListener("storage",C);let S=setInterval(()=>{try{n.closed&&!u&&(u=!0,f(),a.next({success:!1,error:"popup_closed"}),a.complete())}catch{clearInterval(S)}},1e3);function f(){v.close(),window.removeEventListener("storage",C),clearInterval(S)}return()=>f()})):(window.location.href=i.data,w):(n?.close(),c({success:!1,error:"no_auth_url",errorDescription:i?.errorMessage}))),h(i=>(n?.close(),this.messageService.add({key:"globalToast",severity:"error",summary:this.translatorService.translate("Failed"),detail:i?.error?.errorMessage||"Failed to initiate connection"}),c({success:!1,error:"api_error"}))))}disconnect(e){let t=e?`api/configuration/authentication/azure/disconnect?providerId=${e}`:"api/configuration/authentication/azure/disconnect";return this.httpClient.post(t,null).pipe(l(()=>!0),h(()=>c(!1)))}getDelegatedStatus(e){let t=e?`api/configuration/authentication/azure/delegated-status?providerId=${e}`:"api/configuration/authentication/azure/delegated-status",n={status:"not_configured"};return this.httpClient.get(t).pipe(l(i=>i?.data?JSON.parse(i.data):n),h(()=>c(n)))}};o.\u0275fac=function(t){return new(t||o)(s(F),s(E),s(O),s(x),s(T))},o.\u0275prov=j({token:o,factory:o.\u0275fac,providedIn:"root"});let p=o;return p})()});export{oe as a,Y as b};
