import{o as e}from"./rolldown-runtime-iuO8RvI4.js";import{Eu as t,L_ as a,bi as n,bs as i}from"./shared-0-C4kdVF7Y.js";import{Mi as s}from"./vendor-frame-CwiylG4Y.js";import{Ln as r}from"./vendor-all-6-BsAVZMtu.js";import{It as o,Nt as u,Rt as d}from"./shared-3-D-Ux4aGn.js";import{Ri as h,Wt as l,Zt as c,an as m,yt as p}from"./shared-2-CMUBhYOn.js";import{dt as g,ut as b}from"./shared-14-BNdP3DJt.js";import{u as f}from"./c8a5da52e-CzJ-ndTa.js";var v=e(s(),1),A=new Map([["bold",v.createElement(v.Fragment,null,v.createElement("path",{d:"M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Z"}))],["fill",v.createElement(v.Fragment,null,v.createElement("path",{d:"M232,128A104,104,0,1,1,128,24,104.13,104.13,0,0,1,232,128Z"}))],["regular",v.createElement(v.Fragment,null,v.createElement("path",{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Z"}))]]),E=v.forwardRef((e,t)=>v.createElement(r,{ref:t,...e,weights:A}));E.displayName="CircleIcon";var k=E,G=new Set(["github","github-app-setup","env-setup"]);function L({isLoading:e,isGithubAuthenticated:t,environments:a,isGithubAppInstalled:n,hasRunnerPools:i},s,r,o){return a&&a.some(e=>"bridge"!==e.kind)||i?null:r&&G.has(r)?r:e||void 0===t?"loading":!1===t?o?"env-setup":"github":void 0===n?"loading":s||!1!==n&&"indeterminate"!==n?"env-setup":"github-app-setup"}function _(){const{track:e}=n(),s=t().get("magic"),r=i(),[A,E]=(0,v.useState)(()=>"undefined"!=typeof window&&b()),k=r||A,G=(0,v.useCallback)(()=>{E(!0)},[]),[_,R]=(0,v.useState)(()=>"undefined"!=typeof window&&g()),w=(0,v.useCallback)(()=>{R(!0)},[]),y=c(),{isLoading:I}=h(),{isGithubAuthenticated:j,isLoading:F,checkIsGithubAuthenticated:S}=l({callerIdentifier:"code",fetchImmediately:!0}),Z=!(!I&&!y)&&j,{isLoading:M,isFetching:P,isError:C,data:N,refetch:x}=d(),D=N?.environments&&N.environments.length>0,W=a("claude_ai_tamarind"),{data:q,isLoading:z,isFetching:B,isError:H,refetch:J}=f({enabled:W}),K=W&&(q?.pools?.length??0)>0,O=!(!0!==Z||k||D||C||K||W&&z||W&&H),{isLoading:Q,isFetching:T,data:U,isError:V,refetch:X}=m({skipStatus:!1,enabled:O}),Y=p({isGithubAuthenticated:Z,isListGithubReposLoading:Q,githubReposData:U}),$=(0,v.useRef)(!1),ee=o({onSuccess:()=>{e({event_key:"claudeai.code.onboarding.env_setup.completed",option:"trusted_only",environment_name:u.name,auth_path:"oauth"})},onError:t=>{e({event_key:"claudeai.code.onboarding.env_setup.error",option:"trusted_only",error_message:t.message,auth_path:"oauth"})}}),te=r&&!0===Z&&!D&&!K&&!M&&!C&&!(W&&z)&&!(W&&H)&&!ee.isError;(0,v.useEffect)(()=>{te&&!$.current&&($.current=!0,ee.mutate(u))},[te,ee]);const ae=I||F||M||void 0===Z||te||W&&!D&&z||O&&(Q||void 0===Y),ne=P||T||W&&B,ie=C||O&&V||W&&!D&&H,se=(0,v.useCallback)(async()=>{await Promise.all([x(),X(),...W?[J()]:[]])},[x,X,J,W]);return{onboardingPage:L({isLoading:ae,isGithubAuthenticated:Z,isGithubAppInstalled:Y,environments:N?.environments,hasRunnerPools:K},k,s,_),isLoading:ae,isFetching:ne,hasError:ie,isGithubAuthenticated:Z,isGithubAppInstalled:Y,environments:N?.environments,hasRunnerPools:K,checkIsGithubAuthenticated:S,refetchGithubRepos:X,refetch:se,markGithubAppSkipped:G,markGithubAuthSkipped:w}}export{k as n,_ as t};