import{Au as e,Cd as t,Dd as n,Eu as r,Pd as i,n as a,ql as o,r as s,zd as c}from"./index-Q5R6-AeA.js";var l=c(i(),1),u=r(),d=2,f=750,p=new Map,m=new Map;function h(e){if(e instanceof Error)return e;let t=Error(`Unknown authentication error`);if(typeof e==`object`&&e){let n=e;typeof n.error==`string`&&(t.error=n.error),typeof n.message==`string`&&n.message.length>0&&(t.message=n.message)}return t}function g(e){return new Promise(t=>{setTimeout(t,e)})}function _(e,t){let n=p.get(e);if(n)return n;let r=v(t);return p.set(e,r),r}async function v(e,{maxAttempts:t=d,retryDelayMs:n=f}={}){let r;for(let i=0;i<=t;i+=1)try{return await e()}catch(e){if(r=h(e),!s(r)||i>=t)throw r;await g(n*(i+1))}throw r}function y(){let{handleRedirectCallback:r,isLoading:i,error:s,isAuthenticated:c,loginWithRedirect:d}=t(),f=n(),[p,g]=(0,l.useState)(null),v=typeof window>`u`?``:window.location.origin,y=typeof window>`u`?``:window.location.search,b=typeof window>`u`?null:new URLSearchParams(window.location.search),x=b?.has(`code`)&&b?.has(`state`);(0,l.useEffect)(()=>{if(c&&!x){let t=sessionStorage.getItem(`auth:invitationReturnTo`),n=sessionStorage.getItem(`auth:returnTo`),r=sessionStorage.getItem(`auth:lastResolvedReturnTo`),i=t??n??r??e.CHARGES.ROOT;sessionStorage.removeItem(`auth:invitationReturnTo`),sessionStorage.removeItem(`auth:returnTo`),sessionStorage.removeItem(`auth:lastResolvedReturnTo`),f(i,{replace:!0});return}if(s){g(h(s));return}if(i)return;let t=!1;return(async()=>{try{let n=await _(y,r);if(t)return;let i=m.get(y);if(i){sessionStorage.removeItem(`auth:invitationReturnTo`),sessionStorage.removeItem(`auth:returnTo`),sessionStorage.removeItem(`auth:lastResolvedReturnTo`),f(i,{replace:!0});return}let a=n,o=sessionStorage.getItem(`auth:invitationReturnTo`),s=sessionStorage.getItem(`auth:returnTo`),c=o??a.appState?.returnTo??s??e.HOME;m.set(y,c),sessionStorage.setItem(`auth:lastResolvedReturnTo`,c),sessionStorage.removeItem(`auth:invitationReturnTo`),sessionStorage.removeItem(`auth:returnTo`),f(c,{replace:!0})}catch(e){t||g(h(e))}})(),()=>{t=!0}},[c,x,y,i,s,r,f]);let S=p??(s?h(s):null);if(S){let t=a(S);return(0,u.jsx)(`div`,{className:`flex items-center justify-center h-screen`,children:(0,u.jsxs)(`div`,{className:`text-center max-w-sm space-y-4`,children:[(0,u.jsx)(`h1`,{className:`text-2xl font-bold`,children:`Login Failed`}),(0,u.jsx)(`p`,{className:`text-muted-foreground`,children:t}),(0,u.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,u.jsx)(o,{onClick:()=>{let t=sessionStorage.getItem(`auth:returnTo`);return d({authorizationParams:{audience:void 0,scope:`openid profile email offline_access`,redirect_uri:`${v}${e.AUTH_CALLBACK}`},appState:{returnTo:t??e.HOME}})},children:`Try Again`}),(0,u.jsx)(o,{variant:`outline`,onClick:()=>f(e.LOGIN),children:`Back to Login`})]})]})})}return(0,u.jsx)(`div`,{children:`Processing authentication...`})}export{y as AuthCallbackPage};