import{fz as B,qz as R}from"./cli-0.5.3-jbzr8k4s.mjs";import"./cli-0.5.3-me9jkw92.mjs";import"./cli-0.5.3-bqmztzjc.mjs";import"./cli-0.5.3-ytqxzjff.mjs";import"./cli-0.5.3-h6n812td.mjs";import"./cli-0.5.3-hg8c6qbh.mjs";import"./cli-0.5.3-39jr2yrx.mjs";import"./cli-0.5.3-42e2paz8.mjs";import"./cli-0.5.3-mn45xfck.mjs";import"./cli-0.5.3-m884a3pk.mjs";import"./cli-0.5.3-4f9xxrem.mjs";import"./cli-0.5.3-gr8nsa2k.mjs";import"./cli-0.5.3-yj9nbd9d.mjs";import"./cli-0.5.3-55kd38ff.mjs";import"./cli-0.5.3-e6bjcfwg.mjs";import"./cli-0.5.3-4dbxtwh3.mjs";import"./cli-0.5.3-m0kfmb79.mjs";import"./cli-0.5.3-8zq9vdtg.mjs";import"./cli-0.5.3-vmx7agj7.mjs";import"./cli-0.5.3-h8xs2818.mjs";import"./cli-0.5.3-wcx7cnw5.mjs";import"./cli-0.5.3-9zbakvbf.mjs";import"./cli-0.5.3-hx550gz2.mjs";import"./cli-0.5.3-842pf3t4.mjs";import"./cli-0.5.3-wxead1ct.mjs";import"./cli-0.5.3-s1hz35ye.mjs";import"./cli-0.5.3-g0svn6bx.mjs";import"./cli-0.5.3-sfdh3pkx.mjs";import"./cli-0.5.3-d8tjnxcj.mjs";import{AY as j,CY as h,yY as q,zY as O}from"./cli-0.5.3-6zfw1732.mjs";import"./cli-0.5.3-ptjdgcsy.mjs";import"./cli-0.5.3-tp3jye12.mjs";import"./cli-0.5.3-vqmxwet2.mjs";import"./cli-0.5.3-rch86nhn.mjs";import"./cli-0.5.3-zg2apr51.mjs";import"./cli-0.5.3-ngnshpb7.mjs";import"./cli-0.5.3-e58xste9.mjs";import"./cli-0.5.3-6163zevg.mjs";import"./cli-0.5.3-jmkkd5ph.mjs";import"./cli-0.5.3-1vt6twff.mjs";import"./cli-0.5.3-7017ez65.mjs";import"./cli-0.5.3-ea94acj4.mjs";import"./cli-0.5.3-3k22nqvy.mjs";import"./cli-0.5.3-63q4g3zt.mjs";import"./cli-0.5.3-dyhbm5kp.mjs";import"./cli-0.5.3-vpcrbd8n.mjs";import"./cli-0.5.3-jdw3ajfv.mjs";import"./cli-0.5.3-qg4a557t.mjs";import{P6 as M,R6 as U}from"./cli-0.5.3-t65dek0m.mjs";import"./cli-0.5.3-kavpx97n.mjs";import"./cli-0.5.3-9bdwhdys.mjs";import"./cli-0.5.3-ttc72eq3.mjs";import"./cli-0.5.3-g75gdzrp.mjs";import"./cli-0.5.3-1rg2r7n7.mjs";import"./cli-0.5.3-6j2jk6dt.mjs";import"./cli-0.5.3-66650sba.mjs";import"./cli-0.5.3-9vh3vpap.mjs";import{Nfa as G,Qfa as f}from"./cli-0.5.3-n3cxyxpg.mjs";import"./cli-0.5.3-kbvzmaax.mjs";import"./cli-0.5.3-7wdgps7z.mjs";import"./cli-0.5.3-c8bcrqa4.mjs";import"./cli-0.5.3-qrvd6cmy.mjs";import"./cli-0.5.3-2dk1sk8w.mjs";import{Xma as N}from"./cli-0.5.3-0df3r78b.mjs";function C(){let z,E=new Promise((H)=>{z=H}),K=_;return _=E,K.then(()=>z)}function $(z){return M(O,z)}function P(z){let E=z.match(/Created new pane:\s*(.+)/);if(E&&E[1])return E[1].trim();return""}function v(){let z=process.env.ITERM_SESSION_ID;if(!z)return null;let E=z.indexOf(":");if(E===-1)return null;return z.slice(E+1)}class w{type="iterm2";displayName="iTerm2";supportsHideShow=!1;async isAvailable(){let z=q();if(G(`[ITermBackend] isAvailable check: inITerm2=${z}`),!z)return G("[ITermBackend] isAvailable: false (not in iTerm2)"),!1;let E=await j();return G(`[ITermBackend] isAvailable: ${E} (it2 CLI ${E?"found":"not found"})`),E}async isRunningInside(){let z=q();return G(`[ITermBackend] isRunningInside: ${z}`),z}async createTeammatePaneInSwarmView(z,E){G(`[ITermBackend] createTeammatePaneInSwarmView called for ${z} with color ${E}`);let K=await C();try{while(!0){let H=!Z;G(`[ITermBackend] Creating pane: isFirstTeammate=${H}, existingPanes=${J.length}`);let Q,V;if(H){let W=v();if(W)Q=["session","split","-v","-s",W],G(`[ITermBackend] First split from leader session: ${W}`);else Q=["session","split","-v"],G("[ITermBackend] First split from active session (no leader ID)")}else if(V=J[J.length-1],V)Q=["session","split","-s",V],G(`[ITermBackend] Subsequent split from teammate session: ${V}`);else Q=["session","split"],G("[ITermBackend] Subsequent split from active session (no teammate ID)");let X=await $(Q);if(X.code!==0){if(V){let W=await $(["session","list"]);if(W.code===0&&!W.stdout.includes(V)){G(`[ITermBackend] Split failed targeting dead session ${V}, pruning and retrying: ${X.stderr}`);let y=J.indexOf(V);if(y!==-1)J.splice(y,1);if(J.length===0)Z=!1;continue}}throw Error(`Failed to create iTerm2 split pane: ${X.stderr}`)}if(H)Z=!0;let Y=P(X.stdout);if(!Y)throw Error(`Failed to parse session ID from split output: ${X.stdout}`);return G(`[ITermBackend] Created teammate pane for ${z}: ${Y}`),J.push(Y),{paneId:Y,isFirstTeammate:H}}}finally{K()}}async sendCommandToPane(z,E,K){let Q=await $(z?["session","run","-s",z,E]:["session","run",E]);if(Q.code!==0)throw Error(`Failed to send command to iTerm2 pane ${z}: ${Q.stderr}`)}async setPaneBorderColor(z,E,K){}async setPaneTitle(z,E,K,H){}async enablePaneBorderStatus(z,E){}async rebalancePanes(z,E){G("[ITermBackend] Pane rebalancing not implemented for iTerm2")}async killPane(z,E){let K=await $(["session","close","-f","-s",z]),H=J.indexOf(z);if(H!==-1)J.splice(H,1);if(J.length===0)Z=!1;return K.code===0}async hidePane(z,E){return G("[ITermBackend] hidePane not supported in iTerm2"),!1}async showPane(z,E,K){return G("[ITermBackend] showPane not supported in iTerm2"),!1}}var J,Z=!1,_;var L=N(()=>{f();U();h();R();J=[],_=Promise.resolve();B(w)});L();export{w as ITermBackend};
