import{Qg as d,Rg as Vq}from"./cli-0.5.12-xdrtyw81.mjs";import{CP as l,cQ as Oq,wO as a,yO as yq}from"./cli-0.5.12-zc0qwdy2.mjs";import{NX as $,YX as Gq,_V as Zq,rX as T,tX as R}from"./cli-0.5.12-fqp5s15p.mjs";import{PY as t,RY as v,UY as e}from"./cli-0.5.12-ysy6e9rz.mjs";import{BZ as P,CZ as N,DZ as S}from"./cli-0.5.12-c6whkxmz.mjs";import{EZ as Yq}from"./cli-0.5.12-w3hy6c60.mjs";import{C4 as u,D4 as Aq}from"./cli-0.5.12-cbevkwg4.mjs";import{Q6 as G,R8 as s,S6 as o,v8 as j}from"./cli-0.5.12-g4wb8mj2.mjs";import{pea as w,qea as r}from"./cli-0.5.12-asbn3d19.mjs";import{fga as L,iga as n}from"./cli-0.5.12-p5ps8gf0.mjs";import{Gga as Xq,zga as c}from"./cli-0.5.12-tfdwzg37.mjs";import{Aia as f,rma as i}from"./cli-0.5.12-c8f4daey.mjs";import{Yna as I,aoa as h}from"./cli-0.5.12-xzeb7mtb.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",w()),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(L(`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();r();n();o();s();e();K=I(t(),1)});function Kq(){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=p.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")u(Kq()).catch(Rq),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];$(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(Pq,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(d,{message:b}),q[18]=b,q[19]=M;else M=q[19];return M}async function Pq(H){H("Session transferred to Claude Desktop",{display:"system"}),await a(0,"other")}function Rq(){}var p,A,D="https://clau.de/desktop";var Bq=h(()=>{Gq();Aq();k();Xq();yq();Oq();Vq();S();p=I(Zq(),1),A=I(Yq(),1)});
export{mq as Og,Bq as Pg};
