import{LitElement as m,html as g}from"lit";import{appState as i}from"@digital-realty/ix-app-logic/state/app-state.js";import{g as h,P as d,a as u,u as a,c as S}from"./bootstrap.js";import"tslib";import"lit/decorators.js";import"@microsoft/applicationinsights-web";import"@digital-realty/ix-account-switcher";import"oidc-client-ts";import"@digital-realty/ix-app-logic/views/splash-screen.js";import"mobx";var p=Object.defineProperty,f=(r,e,t)=>e in r?p(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>f(r,typeof e!="symbol"?e+"":e,t);class c extends m{constructor(){super(...arguments),s(this,"isIdle",!1),s(this,"clearLocalStorageExcept",e=>{const t=new Set((typeof e=="string"?e.split(","):[]).map(o=>o.trim().toLowerCase())),n=[];Object.keys(window.localStorage).forEach(o=>{Array.from(t).some(l=>o.toLowerCase().includes(l))||n.push(o)}),n.forEach(o=>window.localStorage.removeItem(o))}),s(this,"clearGridSessionStorage",()=>{Object.keys(sessionStorage).filter(e=>e.startsWith("grid-")).forEach(e=>sessionStorage.removeItem(e))}),s(this,"logout",async()=>{i.lastActive=-1,await i.hydrateStore(),await i.getStoredData();const e=h();this.clearState(),this.clearLocalStorageExcept(d),this.clearGridSessionStorage(),sessionStorage.removeItem("accountSelection:lastAll"),sessionStorage.removeItem("accountSelection:lastFiltered"),this.unregisterServiceWorkers().then(async()=>{if(this.isIdle)try{u||await a.signoutSilent(e),window.location.href="/session-expired"}catch(t){window.location.href="/session-expired"}else{if(!e){await a.clearStaleState(),window.location.href="/authenticate";return}a.signoutRedirect(e)}})}),s(this,"unregisterServiceWorkers",async()=>{const e=await navigator.serviceWorker.getRegistrations();for(const t of e)t.unregister()}),s(this,"clearState",()=>{S()})}firstUpdated(){const{searchParams:e}=new URL(document.location.toString());this.isIdle=e.has("isIdle"),this.logout()}render(){return g` <splash-screen></splash-screen> `}}window.customElements.define("ixp-logout",c);export{c as Logout};
