(function(){const a="sso_token",f="organization",S="user_profile";let c=null,i=!1;function _(){const e=window.location.hostname.split("."),n=[];for(let o=1;o<e.length-1;o++)n.push(`.${e.slice(o).join(".")}`);return n}function g(e){const o=`${e}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;try{document.cookie=o;for(const w of _())document.cookie=`${o}; domain=${w}`}catch{}}function O(){try{const e=window.localStorage.getItem(a);return e?{token:e,organization:window.localStorage.getItem(f)??void 0,userProfile:window.localStorage.getItem(S)??void 0}:null}catch{return null}}function s(e,n){try{chrome.runtime.sendMessage(e,()=>{i=!1,chrome.runtime.lastError||(c=n)})}catch{i=!1}}function t(){if(i)return;const e=O(),n=e?.token??null;n!==c&&(i=!0,n?s({type:"SSO/TOKEN_FROM_PAGE",token:n,organization:e?.organization,userProfile:e?.userProfile,origin:window.location.origin},n):s({type:"SSO/LOGGED_OUT_FROM_PAGE",origin:window.location.origin},null))}t();window.addEventListener("storage",e=>{(e.key===a||e.key===null)&&t()});let d=Date.now()+9e4,r=null;function l(){const e=Date.now()<d?600:4e3;r=setTimeout(()=>{t(),l()},e)}l();function u(){d=Date.now()+9e4,t(),r&&clearTimeout(r),l()}document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&u()});window.addEventListener("focus",u);window.addEventListener("pagehide",t);window.addEventListener("beforeunload",t);chrome.runtime.onMessage.addListener(e=>{if(!(e?.type!=="SSO/FORCE_LOGOUT"||!e.logoutUrl)){try{const n=window.localStorage.getItem("theme");window.localStorage.clear(),n&&window.localStorage.setItem("theme",n),window.sessionStorage.clear()}catch{}g(a),window.location.href=e.logoutUrl}});
//# sourceMappingURL=chunk-CRIjMFm_.js.map
})()
