import{_ as k,r as h,c as g,o as w,a as d,b as u,d as f,e as y,s as _,i as A,f as c}from"./index-DSUzCsG7.js";import{r as l,k as v,Q as S,K as T}from"./main-sXeeZcXT.js";import{m as b}from"./mitt-DJ65BbbF.js";import"./orthanc-DWezF2h9.js";function p(){let e=getComputedStyle(document.documentElement).getPropertyValue("--bootstrap-theme");console.log("-------------- Applying Bootstrap theme ...",e),e?document.documentElement.setAttribute("data-bs-theme",e):(console.warn("-------------- Applying Bootstrap theme not defined yet, retrying ..."),setTimeout(p,100))}const B={async created(){console.log("Creating App...");{console.log("Loading the defaults + custom CSS ...");let e=document.createElement("link");e.rel="stylesheet",e.type="text/css",e.href="customizable/custom.css",document.getElementsByTagName("HEAD")[0].appendChild(e),setTimeout(p,0)}await this.$store.dispatch("configuration/load"),await this.$store.dispatch("studies/initialLoad"),await this.$store.dispatch("labels/refresh"),console.log("App created")}},C={class:"full-page"},I={class:"nav-side-layout"},K={class:"content"};function E(e,o,r,n,s,a){const t=h("router-view");return w(),g("div",C,[d("div",I,[u(t,{name:"SideBarView"})]),d("div",K,[u(t,{name:"ContentView"})])])}const L=k(B,[["render",E]]),P=["token","auth-token","authorization"];f.get("../api/pre-login-configuration").then(e=>{const o=y(L),r=b();o.use(l),o.use(_),o.use(A),o.use(v),o.component("Datepicker",S),o.config.globalProperties.messageBus=r;let n=null;if(e.data.Keycloak&&e.data.Keycloak!=null&&e.data.Keycloak.Enable){console.log("Keycloak is enabled"),n=e.data.Keycloak;let s={url:n.Url,realm:n.Realm,clientId:n.ClientId,onLoad:"login-required"};window.keycloak=new T(s),window.keycloak.init({onLoad:s.onLoad}).then(async a=>{a?console.log("Authenticated"):window.location.reload(),localStorage.setItem("vue-token",window.keycloak.token),localStorage.setItem("vue-refresh-token",window.keycloak.refreshToken),c.updateAuthHeader(),o.mount("#app"),console.log("App mounted with keycloak, current route is ",l.currentRoute.value.fullPath);const t=new URLSearchParams(l.currentRoute.value.fullPath);t.delete("session_state"),t.delete("state"),t.delete("code"),t.delete("iss");const i=decodeURIComponent(t.toString()).replace(/=$/,"");console.log("App mounted, moving to cleaned route ",i),await l.push(i),setInterval(()=>{window.keycloak.updateToken(70).then(m=>{m?(console.log("Token refreshed"),localStorage.setItem("vue-token",window.keycloak.token),localStorage.setItem("vue-refresh-token",window.keycloak.refreshToken),c.updateAuthHeader()):console.log("Token not refreshed, still valid for "+Math.round(window.keycloak.tokenParsed.exp+window.keycloak.timeSkew-new Date().getTime()/1e3)+" seconds")}).catch(()=>{console.log("Failed to refresh token")})},6e4)}).catch(a=>{console.log("Could not connect to Keycloak",a)})}else{const s=new URLSearchParams(window.location.search);for(let a of P){const t=s.get(a);t&&(localStorage.setItem(a,t),c.updateAuthHeader(a))}o.mount("#app")}});
