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{l as u,p as d}from"./debug-otxXY3j-.js";import{n as f,r as p}from"./analytics-DqMQntaB.js";import{fC as m,lC as h,sS as g,uC as _,uS as v}from"./loadAgentsDir-C_wFhytF.js";import{t as y}from"./useKeybinding-DPOUuymz.js";import{a as b,t as x}from"./bridgeConfig-pjDV5Z2l.js";import{n as S,r as C,s as w,t as T}from"./bridgeEnabled-D9jI6X-w.js";import{a as E,i as D,n as O}from"./types-C0nqJFkV.js";import{t as k}from"./lib-Cf16LgKj.js";import{i as A,n as j}from"./envLessBridgeConfig-C9UUbQCo.js";import{n as M,r as N}from"./RemoteCallout-Bwe1ESr9.js";function P({onDone:e,name:t}){let n=m(),r=_(e=>e.replBridgeConnected),i=_(e=>e.replBridgeEnabled),a=_(e=>e.replBridgeOutboundOnly),[o,s]=(0,z.useState)(!1);return(0,z.useEffect)(()=>{if((r||i)&&!a){s(!0);return}let o=!1;return(async()=>{let r=await I();if(!o){if(r){p(`tengu_bridge_command`,{action:`preflight_failed`}),e(r,{display:`system`});return}if(N()){n(e=>e.showRemoteCallout?e:{...e,showRemoteCallout:!0,replBridgeInitialName:t}),e(``,{display:`system`});return}p(`tengu_bridge_command`,{action:`connect`}),n(e=>e.replBridgeEnabled&&!e.replBridgeOutboundOnly?e:{...e,replBridgeEnabled:!0,replBridgeExplicit:!0,replBridgeOutboundOnly:!1,replBridgeInitialName:t}),e(`Remote Control connecting…`,{display:`system`})}})(),()=>{o=!0}},[]),o?(0,B.jsx)(F,{onDone:e}):null}function F({onDone:e}){v(`bridge-disconnect-dialog`);let t=m(),n=_(e=>e.replBridgeSessionUrl),s=_(e=>e.replBridgeConnectUrl),l=_(e=>e.replBridgeSessionActive),[u,d]=(0,z.useState)(2),[f,h]=(0,z.useState)(!1),[g,y]=(0,z.useState)(``),b=l?n:s;(0,z.useEffect)(()=>{if(!f||!b){y(``);return}(0,R.toString)(b,{type:`utf8`,errorCorrectionLevel:`L`,small:!0}).then(y).catch(()=>y(``))},[f,b]);function x(){t(e=>e.replBridgeEnabled?{...e,replBridgeEnabled:!1,replBridgeExplicit:!1,replBridgeOutboundOnly:!1}:e),p(`tengu_bridge_command`,{action:`disconnect`}),e(D,{display:`system`})}function S(){h(e=>!e)}function C(){e(void 0,{display:`skip`})}o({"select:next":()=>d(e=>(e+1)%3),"select:previous":()=>d(e=>(e-1+3)%3),"select:accept":()=>{u===0?x():u===1?S():C()}},{context:`Select`});let w=g?g.split(`
`).filter(e=>e.length>0):[];return(0,B.jsx)(a,{title:`Remote Control`,onCancel:C,hideInputGuide:!0,children:(0,B.jsxs)(c,{flexDirection:`column`,gap:1,children:[(0,B.jsxs)(r,{children:[`This session is available via Remote Control`,b?` at ${b}`:``,`.`]}),f&&w.length>0&&(0,B.jsx)(c,{flexDirection:`column`,children:w.map((e,t)=>(0,B.jsx)(r,{children:e},t))}),(0,B.jsxs)(c,{flexDirection:`column`,children:[(0,B.jsx)(i,{isFocused:u===0,children:(0,B.jsx)(r,{children:`Disconnect this session`})}),(0,B.jsx)(i,{isFocused:u===1,children:(0,B.jsx)(r,{children:f?`Hide QR code`:`Show QR code`})}),(0,B.jsx)(i,{isFocused:u===2,children:(0,B.jsx)(r,{children:`Continue`})})]}),(0,B.jsx)(r,{dimColor:!0,children:`Enter to select · Esc to continue`})]})})}async function I(){let{waitForPolicyLimitsToLoad:e,isPolicyAllowed:t}=await import(`./policyLimits-Cdp3QwZ1.js`);if(await e(),!t(`allow_remote_control`))return`Remote Control is disabled by your organization's policy.`;let n=await S();if(n)return n;let r=w();if(r){let{isAssistantMode:e}=await import(`./assistant-BMviqf0l.js`);e()&&(r=!1)}return(r?await j():T())||(x()?(d(`[bridge] Prerequisites passed, enabling bridge`),null):O)}async function L(e,t,n){return(0,B.jsx)(P,{onDone:e,name:n.trim()||void 0})}var R,z,B;e((()=>{R=k(),n(),z=t(n(),1),b(),C(),A(),E(),s(),M(),g(),y(),f(),h(),u(),B=l()}))();export{L as call};