import{o as e}from"./rolldown-runtime-iuO8RvI4.js";import{Eu as t,Ll as s}from"./shared-0-C4kdVF7Y.js";import{Mi as r,ki as a}from"./vendor-frame-CwiylG4Y.js";import{nn as i,rn as l}from"./vendor-all-2-BJdkbLSj.js";import{N as o,a as n,i as d,r as c}from"./c9d1ae78c-BC8J4HPL.js";var u=e(r()),f=a();function m(){const e=l(),r=t(),a=r.get("oauth2_flow_id"),m=r.get("error_code"),{activeOrganization:x,isLoading:h}=s(),g=x?.uuid,[j,p]=(0,u.useState)(null),{mutateAsync:_}=o();(0,u.useEffect)(()=>{if(h)return;let e,t,s=!1;const r=t=>{s||(p(t),c({credentialId:t.credential_id??null,profileId:t.agent_proxy_profile_id??null,errorCode:t.error_code||null,flowId:a}),e=setTimeout(()=>{window.close()},1500))},i=()=>r({error_code:m??"result_fetch_failed"});if(a&&g){const e=l=>{Promise.resolve().then(()=>s?void 0:_({oauth2_flow_id:a})).then(e=>e?r(e):i(),()=>{s||(l>0?t=setTimeout(()=>e(l-1),500):i())})};e(2)}else queueMicrotask(i);return()=>{s=!0,clearTimeout(e),clearTimeout(t)}},[h,g,a,m,_]);const w=j?.error_code||null,y=j?.credential_id??null,v=w?d(e,w)+n(e,a):null;return(0,f.jsx)("div",{className:"flex min-h-screen flex-col items-center justify-center bg-surface-0 text-center",children:(0,f.jsxs)("div",{className:"mx-auto flex max-w-md flex-col gap-md px-4",children:[(0,f.jsx)("h3",{className:"text-title text-primary",children:null===j?(0,f.jsx)(i,{defaultMessage:"Finishing up\u2026",id:"2m+pAldxBC"}):w?(0,f.jsx)(i,{defaultMessage:"Authorization failed",id:"iYbLlX7Zej"}):y?(0,f.jsx)(i,{defaultMessage:"Credential created",id:"goW6ZXHUgv"}):(0,f.jsx)(i,{defaultMessage:"Couldn\u2019t confirm the sign-in",id:"+frfaduPWt"})}),v&&(0,f.jsx)("p",{className:"text-body text-secondary",children:v}),null!==j&&(0,f.jsx)("p",{className:"text-body text-secondary",children:w||y?(0,f.jsx)(i,{defaultMessage:"You can now close this window.",id:"5LJhPKBayL"}):(0,f.jsx)(i,{defaultMessage:"Close this window and try again.",id:"YHXTfteCNG"})})]})})}export{m as AgentProxyOAuth2AuthorizationCodeCallbackPage};