import{n as e,o as t}from"./chunk-DR8-3Aex.js";import{Rn as n,b as r,d as i,f as a,nt as o,t as s,x as c}from"./src-Di342QoJ.js";import{t as l}from"./jsx-runtime-D-D469L8.js";import{K as u,Kn as d,cn as f}from"./state-sIHsFpDu.js";import{r as p,v as m}from"./git-C0IuvuIy.js";import{sS as h,uS as g}from"./loadAgentsDir-C_wFhytF.js";import{t as _}from"./useKeybinding-DPOUuymz.js";import{t as v}from"./Dialog-91X6ZGg9.js";import{t as y}from"./ListItem-DCQhApdJ.js";import{i as b,o as x,t as S}from"./cliLaunch-Citfs01Q.js";import{resolve as C}from"path";async function w(){let e=process.cwd();return p(e)||C(e)}function T({defaultDir:e,onInstalled:t,onCancel:n,onError:s}){g(`assistant-install-wizard`);let[l,u]=(0,D.useState)(0),[d,f]=(0,D.useState)(!1);o({"select:next":()=>u(e=>(e+1)%2),"select:previous":()=>u(e=>(e-1+2)%2),"select:accept":()=>{l===0?p():n()}},{context:`Select`});function p(){if(d)return;f(!0);let n=e||C(`.`);try{let e=x(S([`daemon`,`start`,`--dir=${n}`]),{cwd:n,stdio:`ignore`,detached:!0});e.unref(),e.on(`error`,e=>{s(`Failed to start daemon: ${e.message}`)}),setTimeout(()=>{t(n)},1500)}catch(e){s(`Failed to start daemon: ${e instanceof Error?e.message:String(e)}`)}}return d?(0,O.jsx)(a,{title:`Assistant Setup`,onCancel:n,hideInputGuide:!0,children:(0,O.jsxs)(r,{children:[`Starting daemon in `,e,`...`]})}):(0,O.jsx)(a,{title:`Assistant Setup`,onCancel:n,hideInputGuide:!0,children:(0,O.jsxs)(c,{flexDirection:`column`,gap:1,children:[(0,O.jsx)(r,{children:`No active assistant sessions found.`}),(0,O.jsxs)(r,{children:[`Start a daemon in `,(0,O.jsx)(r,{bold:!0,children:e||`.`}),` to create a cloud session?`]}),(0,O.jsxs)(c,{flexDirection:`column`,children:[(0,O.jsx)(i,{isFocused:l===0,children:(0,O.jsx)(r,{children:`Start assistant daemon`})}),(0,O.jsx)(i,{isFocused:l===1,children:(0,O.jsx)(r,{children:`Cancel`})})]}),(0,O.jsx)(r,{dimColor:!0,children:`Enter to select · Esc to cancel`})]})})}async function E(e,t,n){let{setAppState:r,getAppState:i}=t;return u()?(i().assistantPanelVisible?(r(e=>({...e,assistantPanelVisible:!1})),e(`Assistant panel hidden.`,{display:`system`})):(r(e=>({...e,assistantPanelVisible:!0})),e(`Assistant panel opened.`,{display:`system`})),null):(d(!0),r(e=>({...e,kairosEnabled:!0,assistantPanelVisible:!0})),e(`KAIROS assistant mode activated.`,{display:`system`}),null)}var D,O;e((()=>{n(),D=t(n(),1),s(),v(),y(),h(),_(),m(),b(),f(),O=l()}))();export{T as NewInstallWizard,E as call,w as computeDefaultInstallDir};