import{c as e,d as t,p as n,r,u as i}from"./request.vQUh8Jtz.js";import{o as a}from"./cookie.CKmiw6pz.js";import{t as o}from"./encrypt.BFgl42jB.js";var s=`https://sso-siasn.bkn.go.id/auth`,c=`bkn-portal`,l=`public-siasn`,u=new Promise(e=>{setTimeout(()=>e(`timeout`),2e3)}),d=new n({clientId:c,realm:l,url:s}),f=()=>{r();let e=s;window.location.href=`${e}/realms/public-siasn/protocol/openid-connect/logout?redirect_uri=${window.location.origin}?action=logout-internal`},p=()=>{r();let e=s;window.location.href=`${e}/realms/internal-BKN/protocol/openid-connect/logout?redirect_uri=${window.location.origin}?action=logout-all`},m=()=>{window.location.href=`https://sso-siasn.bkn.go.id/logout.html?redirect=${window.location.origin}`},h=a(window.location.href),g=async()=>{i();let t=await Promise.race([_(),u]);t===`timeout`&&(console.warn(`Login check timed out`),e.push(`/`));let n=t;n&&v();let r=``;if(h?.menu&&n&&(r=`?menu=${h?.menu}`),h?.action==`login`){let e=window.location.hash.substring(1);new URLSearchParams(e).get(`code`)||await d.login({redirectUri:window.location.origin+r})}h?.action==`logout`&&f(),h?.action==`logout-internal`&&p(),h?.action==`logout-all`&&m(),e.push(`/`+r)},_=async()=>{let e=await d.init({onLoad:`check-sso`,silentCheckSsoRedirectUri:`${location.origin}/silent-check-sso.html`});if(e){let e=d.refreshToken,n=await t(e??``,!0);console.log(`check`,n)}return e},v=()=>{h?.redirect&&e.push(`run?app=${o(h?.redirect)}&isRedirect=true`),h?.app&&h?.realm&&h?.client_id&&e.push(`run?app=${o(h.app)}&realm=${h?.realm}&client_id=${h?.client_id}`);let t=``;h?.menu&&(t=`?menu=${h?.menu}`),e.push(`/${t}`)};g();