import{$ as e,L as t,P as n,Y as r,_ as i,a,d as o,h as s,i as c,j as l,m as u,t as d,y as f}from"./store-BWJsxMNk.js";import{a as p,n as m,r as h,t as g}from"./main-r2lQdoDP.js";import{t as _}from"./mitt-BMNuDRAJ.js";function v(){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(v,100))}var y={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(v,0)}await this.$store.dispatch(`configuration/load`),await this.$store.dispatch(`studies/initialLoad`),await this.$store.dispatch(`labels/refresh`),console.log(`App created`)}},b={class:`full-page`},x={class:`nav-side-layout`},S={class:`content`};function C(i,a,o,s,c,u){let d=e(`router-view`);return r(),n(`div`,b,[l(`div`,x,[t(d,{name:`SideBarView`})]),l(`div`,S,[t(d,{name:`ContentView`})])])}var w=i(y,[[`render`,C]]);u();var T=[`token`,`auth-token`,`authorization`];o.get(`../api/pre-login-configuration`).then(e=>{let t=f(w),n=_();t.use(h),t.use(d),t.use(s),t.use(p),t.component(`Datepicker`,g),t.config.globalProperties.messageBus=n;let r=null;if(e.data.Keycloak&&e.data.Keycloak!=null&&e.data.Keycloak.Enable){console.log(`Keycloak is enabled`),r=e.data.Keycloak;let n={url:r.Url,realm:r.Realm,clientId:r.ClientId,onLoad:`login-required`};window.keycloak=new m(n),window.keycloak.init({onLoad:n.onLoad}).then(async e=>{e?console.log(`Authenticated`):window.location.reload(),localStorage.setItem(`vue-token`,window.keycloak.token),localStorage.setItem(`vue-refresh-token`,window.keycloak.refreshToken),c.updateAuthHeader();{let e=window.location.href;e=e.replace(`/ui/app/#/`,`/ui/app/`);let t=new URL(e),n=`${t.pathname}${t.search}`;h.currentRoute.value.fullPath.split(`#`)[0]!==n&&await h.replace(n.replace(a,``))}t.mount(`#app`),console.log(`App mounted with keycloak`),setInterval(()=>{window.keycloak.updateToken(70).then(e=>{e?(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(e=>{console.log(`Could not connect to Keycloak`,e)})}else h.isReady().then(()=>{console.log(`opening OE2 with router=`,h.currentRoute.value);for(let e of T)if(e in h.currentRoute.value.query){let t=h.currentRoute.value.query[e];if(!t)continue;console.log(`found auth token in url: `,e,t),localStorage.setItem(e,t),c.updateAuthHeader(e)}t.mount(`#app`)})});