(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,871135,e=>{"use strict";var t=e.i(843476),i=e.i(502501),r=e.i(785242),l=e.i(936578),n=e.i(602869),s=e.i(846835),u=e.i(693569),a=e.i(557951),o=e.i(321836),c=e.i(571353),f=e.i(618566),d=e.i(271645);function m(){let{authLoading:e,token:m,userID:g,userRole:h,userEmail:p,accessToken:R,premiumUser:U,setUserRole:w,setUserEmail:E}=(0,a.useAuth)(),[A,S]=(0,d.useState)(null),[j,x]=(0,d.useState)([]),[T,y]=(0,d.useState)([]),C=(0,f.useRouter)(),b=(0,f.useSearchParams)(),[P,k]=(0,d.useState)(!1),z=b.get("invitation_id"),D=b.get("page"),G=D||"api-keys",I=(0,d.useRef)(!1),K=!1===e&&null===m&&null===z;(0,d.useEffect)(()=>{if(K){(0,o.storeReturnUrl)();let e=(n.proxyBaseUrl||"")+"/ui/login",t=(0,o.buildLoginUrlWithReturn)(e);window.location.replace(t)}},[K]);let v=null!==D&&D in c.MIGRATED_PAGES;return((0,d.useEffect)(()=>{!e&&v&&C.replace((0,c.migratedHref)(c.MIGRATED_PAGES[G]))},[e,v,G,C]),(0,d.useEffect)(()=>{if(e||!m||I.current)return;I.current=!0;let t=(0,o.consumeReturnUrl)();if(t&&(0,o.isValidReturnUrl)(t)){let e=new URL(t,window.location.origin);if(e.origin!==window.location.origin)return;let i=window.location.href;(0,o.normalizeUrlForCompare)(t)!==(0,o.normalizeUrlForCompare)(i)&&window.location.replace(e.href)}},[e,m]),(0,d.useEffect)(()=>{m||(I.current=!1)},[m]),(0,d.useEffect)(()=>{R&&g&&h&&(0,r.teamListCall)(R,1,100,{userID:"Admin"!==h&&"Admin Viewer"!==h?g:null}).then(e=>S(e.teams??[])).catch(console.error),R&&(0,s.fetchOrganizations)(R,y)},[R,g,h]),e||K||v)?(0,t.jsx)(l.default,{}):(0,t.jsx)(t.Fragment,{children:z?(0,t.jsx)(u.default,{userID:g,userRole:h,premiumUser:U,teams:A,keys:j,setUserRole:w,userEmail:p,setUserEmail:E,setTeams:S,setKeys:x,organizations:T,addKey:e=>{x(t=>t?[...t,e]:[e]),k(()=>!P)},createClicked:P}):(0,t.jsx)(i.default,{})})}e.s(["default",0,function(){return(0,t.jsx)(d.Suspense,{fallback:(0,t.jsx)(l.default,{}),children:(0,t.jsx)(m,{})})}])}]);