import{f as I,h as S}from"./chunk-ERPQLX3P.js";import{a as p}from"./chunk-H4HM5ZJD.js";import{D as m,R as v,w as f}from"./chunk-MLI5PH7P.js";import{G as d,c as a,ca as g,ha as n,p as l,t as u,u as h}from"./chunk-42LKD4JQ.js";import{i as o}from"./chunk-2AVGQ2MQ.js";var b=(()=>{class c{constructor(e,s,t,r,i,P){this.http=e,this.router=s,this.cookieService=t,this.configService=r,this.authService=i,this.PRODUCTS_FACTORY=P,this.envUrl="",this.isEnvUrlInitialized=!1,this.envDetails={},this.inclusionLicenses=[],this.exclusionLicenses=[]}initializeEnvUrl(){return o(this,null,function*(){yield this.configService.ready(),this.envUrl=this.configService.protocol+this.configService.baseFolder+"/paralite/cloud/"+this.configService.cloudName+"/envDetails/",this.isEnvUrlInitialized=!0})}checkLicense(){let e=this.initializeEnvUrl().then(()=>{let t;this.authService&&this.authService.Token?t=this.authService.Token:t="";let r=new f;return t&&(r=r.set("token",t)),this.http.get(this.envUrl,{headers:r,observe:"response"}).pipe(h(i=>(this.storeHeaders(i.headers),{status:i.status,headers:i.headers,body:i.body})),d(i=>(this.storeHeaders(i.headers),(i.status===400||i.status===403||i.status===404)&&this.router.navigate(["/404"]),l({status:i.status,headers:i.headers,error:i.error}))))}),s=new a(t=>{e.then(r=>{r.subscribe({next:i=>t.next(i),error:i=>t.error(i),complete:()=>t.complete()})}).catch(r=>t.error(r))});return this.API_promise=s,s}storeHeaders(e){let s={};this.inclusionLicenses=[],this.exclusionLicenses=[],e?.keys().forEach(t=>{s[t.toLowerCase()]=e.get(t)||"",e.get(t)==="true"?this.inclusionLicenses.push(t):e.get(t)==="false"&&this.exclusionLicenses.push(t)}),this.envDetails=s}getEnvDetails(){return this.envDetails}getInclusionLicenses(){return this.inclusionLicenses}getLicensedProductsDetails(){return o(this,null,function*(){let e=yield this.getInclusionLicensesNew();return this.PRODUCTS_FACTORY.filter(s=>e.includes(s.licenceKey))})}getInclusionLicensesNew(){return o(this,null,function*(){if(this.inclusionLicenses.length<=1&&this.API_promise==null)try{yield u(this.checkLicense())}catch(e){return console.error("Error fetching license info",e),[]}else this.inclusionLicenses.length<=1&&this.API_promise!==void 0&&(yield this.API_promise.toPromise());return this.inclusionLicenses})}getExclusionLicenses(){return this.exclusionLicenses}handleErrorByStatus(e){switch(e.status){case 0:return this.router.navigate(["/503"]),{errorMessage:"A specific error occurred. Please try again later."};case 416:return{licenseExpired:!0};case 434:case 450:return{errorMessage:"A specific error occurred. Please try again later."};case 435:return{clientId:e.error.identityProviderSettingsElement.clientId,tenentId:e.error.identityProviderSettingsElement.tenentId,portalRedirectURI:e.error.identityProviderSettingsElement.portalRedirectURI,loginMode:e.error.identityProviderSettingsElement.loginMode,errorMessage:"A specific error occurred. Please try again later."};case 503:return this.router.navigate(["/503"]),{errorMessage:"A specific error occurred. Please try again later."};default:return{clientId:e.error?.identityProviderSettingsElement?.clientId,tenentId:e.error?.identityProviderSettingsElement?.tenentId,portalRedirectURI:e.error?.identityProviderSettingsElement?.portalRedirectURI,loginMode:e.error?.identityProviderSettingsElement?.loginMode,errorMessage:"An error occurred. Please try again later."}}}static{this.\u0275fac=function(s){return new(s||c)(n(m),n(v),n(S),n(p),n(I),n("PRODUCTS_FACTORY"))}}static{this.\u0275prov=g({token:c,factory:c.\u0275fac,providedIn:"root"})}}return c})();export{b as a};
