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