import{n as e,s as t}from"./rolldown-runtime-BG2f4sTM.js";import{Dvt as n,Fht as r,G$ as i,H$ as a,I$ as o,IX as s,Jtt as c,L$ as l,Mft as u,Mlt as d,NX as f,N_t as p,Nlt as m,Nvt as h,O_t as g,PX as _,R$ as v,Rft as y,V$ as b,Vft as x,W$ as S,Wft as C,Ztt as w,cf as T,gut as E,hut as D,jft as O,npt as k,sf as A}from"./app-initial-BHB6SClA.js";import{i as j,n as M,o as N,r as P,t as F}from"./chatgpt-desktop-auth-url-BRuffm-N.js";function I({onClose:e,startLogin:t=N,workspaceId:n}){let i=p(O),c=_(),u=s(),d=C(),[f,h]=(0,L.useState)(null),g=f!=null;(0,L.useEffect)(()=>()=>{f?.abort()},[f]);let y=()=>{f?.abort(),e()},b=e=>{i.get(m).warning(d.formatMessage({id:`checkout.business.switchWorkspace.error`,defaultMessage:`Couldn’t switch workspaces: {error}`,description:`Toast shown when opening or completing the workspace selector after Business checkout fails`},{error:r(e)}))},T=async()=>{if(f!=null)return;let r=new AbortController,a=!1;h(r);try{let{authUrl:o,completion:s}=await t({signal:r.signal,useStreamlinedLogin:!0});o&&w({href:F({allowedWorkspaceId:n,authUrl:o,codexAppVersion:M(i),currentWorkspaceId:n,loginHint:c.email??void 0,useDesktopAuth:!1,useStreamlinedLoginUx:!0}),initiator:`open_in_browser_bridge`,openTarget:`external-browser`});let l=await s;if(!l.success){b(l.error??`Unknown error`);return}a=!0,e(),u()}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;b(e)}finally{!a&&!r.signal.aborted&&h(null)}};return(0,R.jsx)(a,{open:!0,onOpenChange:e=>{e||y()},size:`compact`,children:(0,R.jsxs)(o,{as:`form`,className:`gap-5 px-6 py-6`,onSubmit:e=>{e.preventDefault(),T()},children:[(0,R.jsx)(v,{icon:(0,R.jsx)(A,{className:`icon-sm`}),iconBackgroundClassName:`bg-token-foreground/10`,title:(0,R.jsx)(S,{asChild:!0,children:(0,R.jsx)(`span`,{children:(0,R.jsx)(x,{id:`checkout.business.switchWorkspace.title`,defaultMessage:`Switch to your new workspace?`,description:`Title of the modal shown after a user completes Business checkout and onboarding`})})}),subtitle:(0,R.jsx)(x,{id:`checkout.business.switchWorkspace.subtitle`,defaultMessage:`Your new workspace is ready. Do you want to switch over?`,description:`Subtitle of the modal shown after a user completes Business checkout and onboarding`})}),g?(0,R.jsx)(`p`,{className:`text-sm text-token-description-foreground`,children:(0,R.jsx)(x,{id:`checkout.business.switchWorkspace.waiting`,defaultMessage:`Waiting for workspace selection in your browser…`,description:`Status shown while the user is choosing a workspace in the browser after Business checkout`})}):null,(0,R.jsxs)(l,{className:`gap-2`,children:[(0,R.jsx)(D,{color:`ghost`,type:`button`,onClick:y,children:(0,R.jsx)(x,{id:`checkout.business.switchWorkspace.notNow`,defaultMessage:`Not now`,description:`Dismiss button in the workspace switch prompt shown after Business checkout`})}),(0,R.jsx)(D,{color:`primary`,loading:g,type:`submit`,children:(0,R.jsx)(x,{id:`checkout.business.switchWorkspace.confirm`,defaultMessage:`Switch workspace`,description:`Confirm button in the workspace switch prompt shown after Business checkout`})})]})]})})}var L,R;e((()=>{g(),k(),L=t(h(),1),y(),j(),f(),E(),i(),b(),c(),d(),T(),u(),P(),R=n()}))();export{I as BusinessCheckoutSwitchWorkspaceDialog};
//# sourceMappingURL=business-checkout-switch-workspace-dialog-BLpNplo9.js.map