import{Jf as p,Kf as Kq}from"./cli-0.5.3-hj2dsm82.mjs";import{CO as l,ai as $,cP as Oq,ci as Yq}from"./cli-0.5.3-jbzr8k4s.mjs";import{IW as T,KW as R,cX as u,nX as Aq,pV as Gq}from"./cli-0.5.3-842pf3t4.mjs";import{eY as t,gY as v,jY as e}from"./cli-0.5.3-g0svn6bx.mjs";import{NY as P,OY as N,PY as S}from"./cli-0.5.3-vqmxwet2.mjs";import{QY as Zq}from"./cli-0.5.3-rch86nhn.mjs";import{lZ as d,mZ as Vq}from"./cli-0.5.3-6163zevg.mjs";import{P6 as G,Q8 as s,R6 as o,u8 as j}from"./cli-0.5.3-t65dek0m.mjs";import{Xda as L,Yda as n}from"./cli-0.5.3-6j2jk6dt.mjs";import{Nfa as w,Qfa as r}from"./cli-0.5.3-n3cxyxpg.mjs";import{Ega as c,Lga as Xq}from"./cli-0.5.3-c8bcrqa4.mjs";import{gma as i,pia as f}from"./cli-0.5.3-qrvd6cmy.mjs";import{Tma as I,Xma as h}from"./cli-0.5.3-0df3r78b.mjs";import{readdir as qq}from"fs/promises";import{join as zq}from"path";function _(){let H=[process.argv[1]||"",process.execPath||""],q=["/build-ant/","/build-ant-native/","/build-external/","/build-external-native/"];return H.some((z)=>q.some((Q)=>z.includes(Q)))}function Jq(H){let q=_()?"claude-dev":"claude",z=new URL(`${q}://resume`);return z.searchParams.set("session",H),z.searchParams.set("cwd",L()),z.toString()}async function g(){if(_())return!0;let H=process.platform;if(H==="darwin")return j("/Applications/Claude.app");else if(H==="linux"){let{code:q,stdout:z}=await G("xdg-mime",["query","default","x-scheme-handler/claude"]);return q===0&&z.trim().length>0}else if(H==="win32"){let{code:q}=await G("reg",["query","HKEY_CLASSES_ROOT\\claude","/ve"]);return q===0}return!1}async function Qq(){let H=process.platform;if(H==="darwin"){let{code:q,stdout:z}=await G("defaults",["read","/Applications/Claude.app/Contents/Info.plist","CFBundleShortVersionString"]);if(q!==0)return null;let Q=z.trim();return Q.length>0?Q:null}else if(H==="win32"){let q=process.env.LOCALAPPDATA;if(!q)return null;let z=zq(q,"AnthropicClaude");try{let Y=(await qq(z)).filter((W)=>W.startsWith("app-")).map((W)=>W.slice(4)).filter((W)=>K.coerce(W)!==null).sort((W,B)=>{let V=K.coerce(W),y=K.coerce(B);return V.compare(y)});return Y.length>0?Y[Y.length-1]:null}catch{return null}}return null}async function x(){if(!await g())return{status:"not-installed"};let q;try{q=await Qq()}catch{return{status:"ready",version:"unknown"}}if(!q)return{status:"ready",version:"unknown"};let z=K.coerce(q);if(!z||!v(z.version,Hq))return{status:"version-too-old",version:q};return{status:"ready",version:q}}async function Wq(H){let q=process.platform;if(w(`Opening deep link: ${H}`),q==="darwin"){if(_()){let{code:Q}=await G("osascript",["-e",`tell application "Electron" to open location "${H}"`]);return Q===0}let{code:z}=await G("open",[H]);return z===0}else if(q==="linux"){let{code:z}=await G("xdg-open",[H]);return z===0}else if(q==="win32"){let{code:z}=await G("cmd",["/c","start","",H]);return z===0}return!1}async function m(){let H=f();if(!await g())return{success:!1,error:"Claude Desktop is not installed. Install it from https://claude.ai/download"};let z=Jq(H);if(!await Wq(z))return{success:!1,error:"Failed to open Claude Desktop. Please try opening it manually.",deepLinkUrl:z};return{success:!0,deepLinkUrl:z}}var K,Hq="1.1.2396";var k=h(()=>{i();n();r();o();s();e();K=I(t(),1)});function Pq(){switch(process.platform){case"win32":return"https://claude.ai/api/desktop/win32/x64/exe/latest/redirect";default:return"https://claude.ai/api/desktop/darwin/universal/dmg/latest/redirect"}}function mq(H){let q=a.c(20),{onDone:z}=H,[Q,Y]=A.useState("checking"),[W,B]=A.useState(null),[V,y]=A.useState(""),O;if(q[0]!==W||q[1]!==z||q[2]!==Q)O=(J)=>{if(Q==="error"){z(W??"Unknown error",{display:"system"});return}if(Q==="prompt-download"){if(J==="y"||J==="Y")d(Pq()).catch(Bq),z(`Starting download. Re-run /desktop once you’ve installed the app.
Learn more at ${D}`,{display:"system"});else if(J==="n"||J==="N")z(`The desktop app is required for /desktop. Learn more at ${D}`,{display:"system"})}},q[0]=W,q[1]=z,q[2]=Q,q[3]=O;else O=q[3];u(O);let E,F;if(q[4]!==z)E=()=>{(async function(){Y("checking");let X=await x();if(X.status==="not-installed"){y("Claude Desktop is not installed."),Y("prompt-download");return}if(X.status==="version-too-old"){y(`Claude Desktop needs to be updated (found v${X.version}, need v1.1.2396+).`),Y("prompt-download");return}Y("flushing"),await l(),Y("opening");let U=await m();if(!U.success){B(U.error??"Failed to open Claude Desktop"),Y("error");return}Y("success"),setTimeout(Rq,500,z)})().catch((Z)=>{B(c(Z)),Y("error")})},F=[z],q[4]=z,q[5]=E,q[6]=F;else E=q[5],F=q[6];if(A.useEffect(E,F),Q==="error"){let J;if(q[7]!==W)J=N(R,{color:"error",children:["Error: ",W]}),q[7]=W,q[8]=J;else J=q[8];let Z;if(q[9]===Symbol.for("react.memo_cache_sentinel"))Z=P(R,{dimColor:!0,children:"Press any key to continue…"}),q[9]=Z;else Z=q[9];let X;if(q[10]!==J)X=N(T,{flexDirection:"column",paddingX:2,children:[J,Z]}),q[10]=J,q[11]=X;else X=q[11];return X}if(Q==="prompt-download"){let J;if(q[12]!==V)J=P(R,{children:V}),q[12]=V,q[13]=J;else J=q[13];let Z;if(q[14]===Symbol.for("react.memo_cache_sentinel"))Z=P(R,{children:"Download now? (y/n)"}),q[14]=Z;else Z=q[14];let X;if(q[15]!==J)X=N(T,{flexDirection:"column",paddingX:2,children:[J,Z]}),q[15]=J,q[16]=X;else X=q[16];return X}let C;if(q[17]===Symbol.for("react.memo_cache_sentinel"))C={checking:"Checking for Claude Desktop…",flushing:"Saving session…",opening:"Opening Claude Desktop…",success:"Opening in Claude Desktop…"},q[17]=C;else C=q[17];let b=C[Q],M;if(q[18]!==b)M=P(p,{message:b}),q[18]=b,q[19]=M;else M=q[19];return M}async function Rq(H){H("Session transferred to Claude Desktop",{display:"system"}),await $(0,"other")}function Bq(){}var a,A,D="https://clau.de/desktop";var yq=h(()=>{Aq();Vq();k();Xq();Yq();Oq();Kq();S();a=I(Gq(),1),A=I(Zq(),1)});
export{mq as Hf,yq as If};
