import{e as T,r as E,q as w,G as P,a as B,j as s,B as I,K as z,o as A}from"./index-DjCrtoJM.js";import{c as K,e as Y,b as _,a as q,D as O}from"./dialog-B4Gk40Ec.js";import{S as R}from"./spinner-C_dp5faG.js";import{i as Q}from"./Check-CkY-NLLZ.js";import{a as $}from"./Eye-Co-ItdFE.js";import{u as F}from"./chat-context-Dd9y-6Y-.js";import{u as G}from"./studio-tools-C1zamUp1.js";const L="bunx decocms link",y={"claude-code":"Claude Code",codex:"Codex"};function S(i){return i.map(e=>y[e]).filter(e=>!!e)}function v(i){return Object.keys(y).filter(e=>!i.includes(e)).map(e=>y[e]).filter(e=>!!e)}function ee(i){const e=T.c(32),{open:f,onOpenChange:h}=i,t=F(),[g,D]=E.useState(!1),{org:j}=w(),C=P(),k=G();let n;e[0]!==k?(n=async()=>{await k.call("LINK_DISCONNECT",{})},e[0]=k,e[1]=n):n=e[1];let o;e[2]!==j||e[3]!==C?(o=()=>{C.invalidateQueries({queryKey:z.currentLink(j.id)})},e[2]=j,e[3]=C,e[4]=o):o=e[4];let p;e[5]!==n||e[6]!==o?(p={mutationFn:n,onSuccess:o,onError:H},e[5]=n,e[6]=o,e[7]=p):p=e[7];const u=B(p),b=t.online?"Desktop connected":"Connect your desktop";let a;e[8]!==b?(a=s.jsx(K,{children:b}),e[8]=b,e[9]=a):a=e[9];const N=t.online?"Your desktop is online. Pick a desktop agent in the chat to use it.":"Run this command in your desktop terminal. The dialog will close once your desktop is online.";let l;e[10]!==N?(l=s.jsx(Y,{children:N}),e[10]=N,e[11]=l):l=e[11];let c;e[12]!==a||e[13]!==l?(c=s.jsxs(_,{children:[a,l]}),e[12]=a,e[13]=l,e[14]=c):c=e[14];let r;e[15]!==g||e[16]!==t.online?(r=!t.online&&s.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted px-3 py-2 font-mono text-sm",children:[s.jsx("span",{className:"flex-1",children:L}),s.jsx(I,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>{navigator.clipboard.writeText(L),D(!0),setTimeout(()=>D(!1),1500)},children:g?s.jsx(Q,{size:14}):s.jsx($,{size:14})})]}),e[15]=g,e[16]=t.online,e[17]=r):r=e[17];let d;e[18]!==u||e[19]!==t.capabilities||e[20]!==t.hostname||e[21]!==t.machineId||e[22]!==t.online?(d=t.online?s.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[s.jsxs("p",{className:"text-foreground",children:[t.hostname??t.machineId??"Your desktop"," is linked."]}),S(t.capabilities).length>0&&s.jsxs("p",{className:"text-muted-foreground",children:["Available: ",S(t.capabilities).join(", ")]}),v(t.capabilities).length>0&&s.jsxs("p",{className:"text-muted-foreground",children:[v(t.capabilities).join(" and ")," ",v(t.capabilities).length>1?"were":"was"," ","not detected on this desktop. Install the CLI and sign in there — it appears here automatically within a minute."]}),s.jsx("div",{className:"flex justify-end pt-2",children:s.jsx(I,{type:"button",variant:"outline",size:"sm",disabled:u.isPending,onClick:()=>u.mutate(),className:"text-destructive hover:text-destructive",children:u.isPending?"Disconnecting…":"Disconnect desktop"})})]}):s.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[s.jsx(R,{size:"sm"}),"Waiting for desktop…"]}),e[18]=u,e[19]=t.capabilities,e[20]=t.hostname,e[21]=t.machineId,e[22]=t.online,e[23]=d):d=e[23];let m;e[24]!==d||e[25]!==c||e[26]!==r?(m=s.jsxs(q,{className:"sm:max-w-md",children:[c,r,d]}),e[24]=d,e[25]=c,e[26]=r,e[27]=m):m=e[27];let x;return e[28]!==h||e[29]!==f||e[30]!==m?(x=s.jsx(O,{open:f,onOpenChange:h,children:m}),e[28]=h,e[29]=f,e[30]=m,e[31]=x):x=e[31],x}function H(i){A.error(`Disconnect failed: ${i.message}`)}export{ee as C,S as v};
