9remote 3.0.33 → 3.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/dist/cli.cjs +181 -163
  2. package/dist/extension/background.js +261 -0
  3. package/dist/extension/icons/icon128.png +0 -0
  4. package/dist/extension/icons/icon16.png +0 -0
  5. package/dist/extension/icons/icon48.png +0 -0
  6. package/dist/extension/manifest.json +11 -0
  7. package/dist/extension/popup.html +58 -0
  8. package/dist/extension/popup.js +23 -0
  9. package/dist/ptyDaemon.cjs +9 -9
  10. package/dist/server.cjs +843 -529
  11. package/dist/ui/assets/index-BKC13tXO.js +8 -0
  12. package/dist/ui/index.html +1 -1
  13. package/dist/web/404.html +1 -1
  14. package/dist/web/__next.__PAGE__.txt +2 -2
  15. package/dist/web/__next._full.txt +8 -8
  16. package/dist/web/__next._head.txt +1 -1
  17. package/dist/web/__next._index.txt +7 -7
  18. package/dist/web/__next._tree.txt +2 -2
  19. package/dist/web/_next/static/chunks/1222.16edfbb0beb9081f.js +1 -0
  20. package/dist/web/_next/static/chunks/1228.c4aa83586b3730b6.js +1 -0
  21. package/dist/web/_next/static/chunks/1243.3f23d89283c156ea.js +1 -0
  22. package/dist/web/_next/static/chunks/132.71f657e5a607b7d3.js +1 -0
  23. package/dist/web/_next/static/chunks/1750.ea89a41e86ac2790.js +1 -0
  24. package/dist/web/_next/static/chunks/2038.b77e2c3d38385a76.js +1 -0
  25. package/dist/web/_next/static/chunks/213.ae43f03862ad9cc1.js +1 -0
  26. package/dist/web/_next/static/chunks/2180.edcf5dc3d77ceee8.js +1 -0
  27. package/dist/web/_next/static/chunks/2849.d810c3fdb2054b14.js +1 -0
  28. package/dist/web/_next/static/chunks/3429.e69c6bd48e1207a9.js +1 -0
  29. package/dist/web/_next/static/chunks/3514.20bd03c8194dec25.js +1 -0
  30. package/dist/web/_next/static/chunks/{4300-07e861bf93bf7d91.js → 4300-a66b52c9e1a27db3.js} +1 -1
  31. package/dist/web/_next/static/chunks/4643.1e356e007756e19d.js +1 -0
  32. package/dist/web/_next/static/chunks/5788-f0c87f9c14fa0ff9.js +1 -0
  33. package/dist/web/_next/static/chunks/6419.34fdd4aa97c5cc5d.js +1 -0
  34. package/dist/web/_next/static/chunks/6739.22a05398bfd34922.js +1 -0
  35. package/dist/web/_next/static/chunks/674.b2f5d5fc3fb84c4a.js +1 -0
  36. package/dist/web/_next/static/chunks/6742.88fddf128fbeb43d.js +1 -0
  37. package/dist/web/_next/static/chunks/7507.77d9ac9eb03518f7.js +1 -0
  38. package/dist/web/_next/static/chunks/7960.2754ce9111bef59e.js +1 -0
  39. package/dist/web/_next/static/chunks/8467.c2c0273ac5e97e34.js +1 -0
  40. package/dist/web/_next/static/chunks/8638.f44546e4532d76e8.js +1 -0
  41. package/dist/web/_next/static/chunks/8762-e88a7f91d20d82bd.js +1 -0
  42. package/dist/web/_next/static/chunks/8922-4c589850b01d2e12.js +1 -0
  43. package/dist/web/_next/static/chunks/925.7cfb725e605559a0.js +1 -0
  44. package/dist/web/_next/static/chunks/9259.97e2f3306fc149c7.js +1 -0
  45. package/dist/web/_next/static/chunks/9299.e37149b455be7e9d.js +1 -0
  46. package/dist/web/_next/static/chunks/app/dev/question/page-c7128ddf798789f1.js +1 -0
  47. package/dist/web/_next/static/chunks/app/layout-a0e78c8427f97e4f.js +1 -0
  48. package/dist/web/_next/static/chunks/app/login/{page-df0619de376c5db8.js → page-2a046d10af50c87a.js} +1 -1
  49. package/dist/web/_next/static/chunks/app/{page-d0e1fb551728bb6f.js → page-8387dba850541259.js} +2 -2
  50. package/dist/web/_next/static/chunks/app/workspace/layout-9b28454945238595.js +20 -0
  51. package/dist/web/_next/static/chunks/webpack-beef15eb580fc66b.js +1 -0
  52. package/dist/web/_next/static/css/c48f9629be2a67b4.css +1 -0
  53. package/dist/web/_not-found/__next._full.txt +7 -7
  54. package/dist/web/_not-found/__next._head.txt +1 -1
  55. package/dist/web/_not-found/__next._index.txt +7 -7
  56. package/dist/web/_not-found/__next._not-found.__PAGE__.txt +1 -1
  57. package/dist/web/_not-found/__next._not-found.txt +1 -1
  58. package/dist/web/_not-found/__next._tree.txt +2 -2
  59. package/dist/web/_not-found.html +1 -1
  60. package/dist/web/_not-found.txt +7 -7
  61. package/dist/web/admin/__next._full.txt +8 -8
  62. package/dist/web/admin/__next._head.txt +1 -1
  63. package/dist/web/admin/__next._index.txt +7 -7
  64. package/dist/web/admin/__next._tree.txt +2 -2
  65. package/dist/web/admin/__next.admin.__PAGE__.txt +2 -2
  66. package/dist/web/admin/__next.admin.txt +1 -1
  67. package/dist/web/admin/access/__next._full.txt +8 -8
  68. package/dist/web/admin/access/__next._head.txt +1 -1
  69. package/dist/web/admin/access/__next._index.txt +7 -7
  70. package/dist/web/admin/access/__next._tree.txt +2 -2
  71. package/dist/web/admin/access/__next.admin.access.__PAGE__.txt +2 -2
  72. package/dist/web/admin/access/__next.admin.access.txt +1 -1
  73. package/dist/web/admin/access/__next.admin.txt +1 -1
  74. package/dist/web/admin/access.html +1 -1
  75. package/dist/web/admin/access.txt +8 -8
  76. package/dist/web/admin/login/__next._full.txt +8 -8
  77. package/dist/web/admin/login/__next._head.txt +1 -1
  78. package/dist/web/admin/login/__next._index.txt +7 -7
  79. package/dist/web/admin/login/__next._tree.txt +2 -2
  80. package/dist/web/admin/login/__next.admin.login.__PAGE__.txt +2 -2
  81. package/dist/web/admin/login/__next.admin.login.txt +1 -1
  82. package/dist/web/admin/login/__next.admin.txt +1 -1
  83. package/dist/web/admin/login.html +1 -1
  84. package/dist/web/admin/login.txt +8 -8
  85. package/dist/web/admin/ota/__next._full.txt +8 -8
  86. package/dist/web/admin/ota/__next._head.txt +1 -1
  87. package/dist/web/admin/ota/__next._index.txt +7 -7
  88. package/dist/web/admin/ota/__next._tree.txt +2 -2
  89. package/dist/web/admin/ota/__next.admin.ota.__PAGE__.txt +2 -2
  90. package/dist/web/admin/ota/__next.admin.ota.txt +1 -1
  91. package/dist/web/admin/ota/__next.admin.txt +1 -1
  92. package/dist/web/admin/ota.html +1 -1
  93. package/dist/web/admin/ota.txt +8 -8
  94. package/dist/web/admin/turn/__next._full.txt +8 -8
  95. package/dist/web/admin/turn/__next._head.txt +1 -1
  96. package/dist/web/admin/turn/__next._index.txt +7 -7
  97. package/dist/web/admin/turn/__next._tree.txt +2 -2
  98. package/dist/web/admin/turn/__next.admin.turn.__PAGE__.txt +2 -2
  99. package/dist/web/admin/turn/__next.admin.turn.txt +1 -1
  100. package/dist/web/admin/turn/__next.admin.txt +1 -1
  101. package/dist/web/admin/turn.html +1 -1
  102. package/dist/web/admin/turn.txt +8 -8
  103. package/dist/web/admin.html +1 -1
  104. package/dist/web/admin.txt +8 -8
  105. package/dist/web/dev/question/__next._full.txt +8 -8
  106. package/dist/web/dev/question/__next._head.txt +1 -1
  107. package/dist/web/dev/question/__next._index.txt +7 -7
  108. package/dist/web/dev/question/__next._tree.txt +2 -2
  109. package/dist/web/dev/question/__next.dev.question.__PAGE__.txt +2 -2
  110. package/dist/web/dev/question/__next.dev.question.txt +1 -1
  111. package/dist/web/dev/question/__next.dev.txt +1 -1
  112. package/dist/web/dev/question.html +1 -1
  113. package/dist/web/dev/question.txt +8 -8
  114. package/dist/web/download/__next._full.txt +8 -8
  115. package/dist/web/download/__next._head.txt +1 -1
  116. package/dist/web/download/__next._index.txt +7 -7
  117. package/dist/web/download/__next._tree.txt +2 -2
  118. package/dist/web/download/__next.download.__PAGE__.txt +2 -2
  119. package/dist/web/download/__next.download.txt +1 -1
  120. package/dist/web/download.html +1 -1
  121. package/dist/web/download.txt +8 -8
  122. package/dist/web/index.html +1 -1
  123. package/dist/web/index.txt +8 -8
  124. package/dist/web/login/__next._full.txt +8 -8
  125. package/dist/web/login/__next._head.txt +1 -1
  126. package/dist/web/login/__next._index.txt +7 -7
  127. package/dist/web/login/__next._tree.txt +2 -2
  128. package/dist/web/login/__next.login.__PAGE__.txt +2 -2
  129. package/dist/web/login/__next.login.txt +1 -1
  130. package/dist/web/login.html +1 -1
  131. package/dist/web/login.txt +8 -8
  132. package/dist/web/sw.js +2 -8
  133. package/dist/web/workspace/__next._full.txt +8 -8
  134. package/dist/web/workspace/__next._head.txt +1 -1
  135. package/dist/web/workspace/__next._index.txt +7 -7
  136. package/dist/web/workspace/__next._tree.txt +2 -2
  137. package/dist/web/workspace/__next.workspace.__PAGE__.txt +1 -1
  138. package/dist/web/workspace/__next.workspace.txt +2 -2
  139. package/dist/web/workspace/browse/__next._full.txt +8 -8
  140. package/dist/web/workspace/browse/__next._head.txt +1 -1
  141. package/dist/web/workspace/browse/__next._index.txt +7 -7
  142. package/dist/web/workspace/browse/__next._tree.txt +2 -2
  143. package/dist/web/workspace/browse/__next.workspace.browse.__PAGE__.txt +1 -1
  144. package/dist/web/workspace/browse/__next.workspace.browse.txt +1 -1
  145. package/dist/web/workspace/browse/__next.workspace.txt +2 -2
  146. package/dist/web/workspace/browse.html +1 -1
  147. package/dist/web/workspace/browse.txt +8 -8
  148. package/dist/web/workspace/editor/__next._full.txt +8 -8
  149. package/dist/web/workspace/editor/__next._head.txt +1 -1
  150. package/dist/web/workspace/editor/__next._index.txt +7 -7
  151. package/dist/web/workspace/editor/__next._tree.txt +2 -2
  152. package/dist/web/workspace/editor/__next.workspace.editor.__PAGE__.txt +1 -1
  153. package/dist/web/workspace/editor/__next.workspace.editor.txt +1 -1
  154. package/dist/web/workspace/editor/__next.workspace.txt +2 -2
  155. package/dist/web/workspace/editor.html +1 -1
  156. package/dist/web/workspace/editor.txt +8 -8
  157. package/dist/web/workspace/files/__next._full.txt +8 -8
  158. package/dist/web/workspace/files/__next._head.txt +1 -1
  159. package/dist/web/workspace/files/__next._index.txt +7 -7
  160. package/dist/web/workspace/files/__next._tree.txt +2 -2
  161. package/dist/web/workspace/files/__next.workspace.files.__PAGE__.txt +1 -1
  162. package/dist/web/workspace/files/__next.workspace.files.txt +1 -1
  163. package/dist/web/workspace/files/__next.workspace.txt +2 -2
  164. package/dist/web/workspace/files.html +1 -1
  165. package/dist/web/workspace/files.txt +8 -8
  166. package/dist/web/workspace/git/__next._full.txt +8 -8
  167. package/dist/web/workspace/git/__next._head.txt +1 -1
  168. package/dist/web/workspace/git/__next._index.txt +7 -7
  169. package/dist/web/workspace/git/__next._tree.txt +2 -2
  170. package/dist/web/workspace/git/__next.workspace.git.__PAGE__.txt +1 -1
  171. package/dist/web/workspace/git/__next.workspace.git.txt +1 -1
  172. package/dist/web/workspace/git/__next.workspace.txt +2 -2
  173. package/dist/web/workspace/git.html +1 -1
  174. package/dist/web/workspace/git.txt +8 -8
  175. package/dist/web/workspace/mobile/__next._full.txt +8 -8
  176. package/dist/web/workspace/mobile/__next._head.txt +1 -1
  177. package/dist/web/workspace/mobile/__next._index.txt +7 -7
  178. package/dist/web/workspace/mobile/__next._tree.txt +2 -2
  179. package/dist/web/workspace/mobile/__next.workspace.mobile.__PAGE__.txt +1 -1
  180. package/dist/web/workspace/mobile/__next.workspace.mobile.txt +1 -1
  181. package/dist/web/workspace/mobile/__next.workspace.txt +2 -2
  182. package/dist/web/workspace/mobile.html +1 -1
  183. package/dist/web/workspace/mobile.txt +8 -8
  184. package/dist/web/workspace/pair/__next._full.txt +8 -8
  185. package/dist/web/workspace/pair/__next._head.txt +1 -1
  186. package/dist/web/workspace/pair/__next._index.txt +7 -7
  187. package/dist/web/workspace/pair/__next._tree.txt +2 -2
  188. package/dist/web/workspace/pair/__next.workspace.pair.__PAGE__.txt +1 -1
  189. package/dist/web/workspace/pair/__next.workspace.pair.txt +1 -1
  190. package/dist/web/workspace/pair/__next.workspace.txt +2 -2
  191. package/dist/web/workspace/pair.html +1 -1
  192. package/dist/web/workspace/pair.txt +8 -8
  193. package/dist/web/workspace/remote/__next._full.txt +8 -8
  194. package/dist/web/workspace/remote/__next._head.txt +1 -1
  195. package/dist/web/workspace/remote/__next._index.txt +7 -7
  196. package/dist/web/workspace/remote/__next._tree.txt +2 -2
  197. package/dist/web/workspace/remote/__next.workspace.remote.__PAGE__.txt +1 -1
  198. package/dist/web/workspace/remote/__next.workspace.remote.txt +1 -1
  199. package/dist/web/workspace/remote/__next.workspace.txt +2 -2
  200. package/dist/web/workspace/remote.html +1 -1
  201. package/dist/web/workspace/remote.txt +8 -8
  202. package/dist/web/workspace/terminal/default/__next._full.txt +22 -21
  203. package/dist/web/workspace/terminal/default/__next._head.txt +1 -1
  204. package/dist/web/workspace/terminal/default/__next._index.txt +7 -7
  205. package/dist/web/workspace/terminal/default/__next._tree.txt +2 -2
  206. package/dist/web/workspace/terminal/default/__next.workspace.terminal.$d$sessionId.__PAGE__.txt +1 -1
  207. package/dist/web/workspace/terminal/default/__next.workspace.terminal.$d$sessionId.txt +1 -1
  208. package/dist/web/workspace/terminal/default/__next.workspace.terminal.txt +1 -1
  209. package/dist/web/workspace/terminal/default/__next.workspace.txt +2 -2
  210. package/dist/web/workspace/terminal/default.html +1 -1
  211. package/dist/web/workspace/terminal/default.txt +22 -21
  212. package/dist/web/workspace/welcome/__next._full.txt +8 -8
  213. package/dist/web/workspace/welcome/__next._head.txt +1 -1
  214. package/dist/web/workspace/welcome/__next._index.txt +7 -7
  215. package/dist/web/workspace/welcome/__next._tree.txt +2 -2
  216. package/dist/web/workspace/welcome/__next.workspace.txt +2 -2
  217. package/dist/web/workspace/welcome/__next.workspace.welcome.__PAGE__.txt +1 -1
  218. package/dist/web/workspace/welcome/__next.workspace.welcome.txt +1 -1
  219. package/dist/web/workspace/welcome.html +1 -1
  220. package/dist/web/workspace/welcome.txt +8 -8
  221. package/dist/web/workspace/workspaces/__next._full.txt +8 -8
  222. package/dist/web/workspace/workspaces/__next._head.txt +1 -1
  223. package/dist/web/workspace/workspaces/__next._index.txt +7 -7
  224. package/dist/web/workspace/workspaces/__next._tree.txt +2 -2
  225. package/dist/web/workspace/workspaces/__next.workspace.txt +2 -2
  226. package/dist/web/workspace/workspaces/__next.workspace.workspaces.__PAGE__.txt +1 -1
  227. package/dist/web/workspace/workspaces/__next.workspace.workspaces.txt +1 -1
  228. package/dist/web/workspace/workspaces.html +1 -1
  229. package/dist/web/workspace/workspaces.txt +8 -8
  230. package/dist/web/workspace.html +1 -1
  231. package/dist/web/workspace.txt +8 -8
  232. package/package.json +5 -2
  233. package/dist/ui/assets/index-DaXUWL4p.js +0 -8
  234. package/dist/web/_next/static/chunks/1222.a2ce7d7f04241e2a.js +0 -1
  235. package/dist/web/_next/static/chunks/1228.046ad5fd038f5192.js +0 -1
  236. package/dist/web/_next/static/chunks/1243.1d11020940b8a88b.js +0 -1
  237. package/dist/web/_next/static/chunks/132.1ed2fce3a4b6f7ee.js +0 -1
  238. package/dist/web/_next/static/chunks/1750.09ca4eade7a6e5d3.js +0 -1
  239. package/dist/web/_next/static/chunks/2038.b7c72b442a1b2d92.js +0 -1
  240. package/dist/web/_next/static/chunks/2081-e831caac4b77c71b.js +0 -1
  241. package/dist/web/_next/static/chunks/213.f07a816120a320ba.js +0 -1
  242. package/dist/web/_next/static/chunks/2180.23585bd3f3308f3a.js +0 -1
  243. package/dist/web/_next/static/chunks/2849.360e2c64521fa795.js +0 -1
  244. package/dist/web/_next/static/chunks/3429.98d7e79ff6d2a6ce.js +0 -1
  245. package/dist/web/_next/static/chunks/3514.9079bf49bb3e05c9.js +0 -1
  246. package/dist/web/_next/static/chunks/4643.ddf3ea3a760e73a5.js +0 -1
  247. package/dist/web/_next/static/chunks/5788-1564be0da354c064.js +0 -1
  248. package/dist/web/_next/static/chunks/6419.99aa173d83f20370.js +0 -1
  249. package/dist/web/_next/static/chunks/6739.82570eba0a02cb26.js +0 -1
  250. package/dist/web/_next/static/chunks/674.97a7237f011fb986.js +0 -1
  251. package/dist/web/_next/static/chunks/6742.bc3783b9784ead96.js +0 -1
  252. package/dist/web/_next/static/chunks/7507.28a3807b5d02a5c1.js +0 -1
  253. package/dist/web/_next/static/chunks/7960.026e07028dd25edb.js +0 -1
  254. package/dist/web/_next/static/chunks/8467.290e9bde34b58e7c.js +0 -1
  255. package/dist/web/_next/static/chunks/8638.237712645dcdcb8a.js +0 -1
  256. package/dist/web/_next/static/chunks/8922-6961d48ca52e1c93.js +0 -1
  257. package/dist/web/_next/static/chunks/925.fe600c6039a3201d.js +0 -1
  258. package/dist/web/_next/static/chunks/9259.c450f561db04037d.js +0 -1
  259. package/dist/web/_next/static/chunks/9299.83236781dfa74eb0.js +0 -1
  260. package/dist/web/_next/static/chunks/app/dev/question/page-4bb0cca12fac67eb.js +0 -1
  261. package/dist/web/_next/static/chunks/app/layout-db3ce810a0a58245.js +0 -1
  262. package/dist/web/_next/static/chunks/app/workspace/layout-962bdc55fd3688d7.js +0 -15
  263. package/dist/web/_next/static/chunks/webpack-d2ee6953aa988e78.js +0 -1
  264. package/dist/web/_next/static/css/68a0b2d972b421cb.css +0 -1
  265. package/dist/web/proxy.html +0 -179
  266. package/dist/web/sw-site.js +0 -283
  267. package/dist/web/swBridgeClaim.js +0 -57
  268. /package/dist/web/_next/static/{wQF273g4wNnUv72vtLjBT → hFRLMLaLieW6POo9cLvLQ}/_buildManifest.js +0 -0
  269. /package/dist/web/_next/static/{wQF273g4wNnUv72vtLjBT → hFRLMLaLieW6POo9cLvLQ}/_ssgManifest.js +0 -0
@@ -0,0 +1,20 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1807],{20033:()=>{},24317:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>ux});var n=s(73365),r=s(1521),l=s(29717),a=s(97711);let i="9remote_deviceId";var o=s(79453),c=s(7938),d=s(52159),u=s(94858),x=s(2805),m=s(90076),p=s(11155),f=s(90084),h=s(29091),b=s(2074);let g="https://openrouter.ai/api/v1",v={enabled:"voiceEnabled",mode:"voiceMode",endpoint:"voiceEndpoint",apiKey:"voiceApiKey",model:"voiceModel",preset:"voicePreset",geminiKeys:"voiceGeminiKeys",openrouterKey:"voiceOpenrouterKey",customEndpoint:"voiceCustomEndpoint",customModel:"voiceCustomModel",customKey:"voiceCustomKey",opencodeModel:"voiceOpencodeModel"},y={gemini:{label:"Gemini",endpoint:"https://generativelanguage.googleapis.com/v1beta/openai",model:"gemini-3.1-flash-lite",note:"Free tier \xb7 quota per project (AI Studio)"},openrouter:{label:"OpenRouter",endpoint:g,model:"google/gemini-3.5-flash-lite",note:"≈5,000 voice inputs per $1"},opencode:{label:"Free",endpoint:"https://opencode.ai/zen/v1",model:"mimo-v2.6-flash-free",note:"OpenCode free \xb7 no key \xb7 routed through the agent"},custom:{label:"Custom"}};async function w(e,t){let s=new AbortController,n=setTimeout(()=>s.abort(),15e3);try{if(!e.apiKey?.trim())throw Error("No API key set");let n=(e.endpoint?.trim()||g).replace(/\/+$/,""),r=await fetch(`${n}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},body:JSON.stringify({stream:!1,...t}),signal:s.signal}),l=await r.json().catch(()=>({}));if(!r.ok)throw Error(l?.error?.message||`HTTP ${r.status}`);return l}finally{clearTimeout(n)}}let j=e=>e?.name==="AbortError"?"Timed out":e?.message==="Failed to fetch"?"Network/CORS error":e?.message||"Failed",k=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus","audio/aac"];function N(e){let t=k.find(e=>MediaRecorder.isTypeSupported?.(e));return t?new MediaRecorder(e,{mimeType:t}):new MediaRecorder(e)}async function C(e=3e3){let t=await navigator.mediaDevices.getUserMedia({audio:!0}),s=N(t),n=[];s.ondataavailable=e=>{e.data.size&&n.push(e.data)};let r=new Promise(e=>{s.onstop=e});return s.start(),await new Promise(t=>setTimeout(t,e)),s.stop(),await r,t.getTracks().forEach(e=>e.stop()),new Blob(n,{type:s.mimeType||"audio/webm"})}async function S(e){let t=new OfflineAudioContext(1,1,16e3),n=await t.decodeAudioData(await e.arrayBuffer()),r=new OfflineAudioContext(1,Math.ceil(16e3*n.duration),16e3),l=r.createBufferSource();l.buffer=n,l.connect(r.destination),l.start();let a=(await r.startRendering()).getChannelData(0);try{let e=await s.e(1984).then(s.bind(s,77557)),t=e.default||e;if("function"!=typeof t?.Mp3Encoder)throw Error("encoder missing");return{blob:function(e,t){let s=new e.Mp3Encoder(1,16e3,32),n=new Int16Array(t.length);for(let e=0;e<t.length;e++){let s=Math.max(-1,Math.min(1,t[e]));n[e]=s<0?32768*s:32767*s}let r=[];for(let e=0;e<n.length;e+=1152){let t=s.encodeBuffer(n.subarray(e,e+1152));t.length&&r.push(new Uint8Array(t))}let l=s.flush();return l.length&&r.push(new Uint8Array(l)),new Blob(r,{type:"audio/mp3"})}(t,a),format:"mp3"}}catch{return{blob:function(e){let t=new ArrayBuffer(44+2*e.length),s=new DataView(t),n=(e,t)=>{for(let n=0;n<t.length;n++)s.setUint8(e+n,t.charCodeAt(n))};n(0,"RIFF"),s.setUint32(4,36+2*e.length,!0),n(8,"WAVE"),n(12,"fmt "),s.setUint32(16,16,!0),s.setUint16(20,1,!0),s.setUint16(22,1,!0),s.setUint32(24,16e3,!0),s.setUint32(28,32e3,!0),s.setUint16(32,2,!0),s.setUint16(34,16,!0),n(36,"data"),s.setUint32(40,2*e.length,!0);let r=44;for(let t=0;t<e.length;t++,r+=2){let n=Math.max(-1,Math.min(1,e[t]));s.setInt16(r,n<0?32768*n:32767*n,!0)}return new Blob([t],{type:"audio/wav"})}(a),format:"wav"}}}let T=0;function R(e){let t="opencode"!==e.preset?e.preset:"gemini";if("opencode"===t)return{endpoint:y.opencode.endpoint,model:e.opencodeModel?.trim()||y.opencode.model,apiKey:"public"};if("gemini"===t||"openrouter"===t){let s=y[t],n=e[`${t}Model`]?.trim()||s.model;if("gemini"===t){let t=e.geminiKeys.map(e=>e.trim()).filter(Boolean);return{endpoint:s.endpoint,model:n,apiKey:t.length?t[T++%t.length]:""}}return{endpoint:s.endpoint,model:n,apiKey:e.openrouterKey}}return{endpoint:e.customEndpoint,model:e.customModel,apiKey:e.customKey}}async function E(e,t,s){let n,r,l=R(e),a=(r=(n=s&&"auto"!==s?function(e){try{return new Intl.DisplayNames(["en"],{type:"language"}).of(String(e).split("-")[0])}catch{return e}}(s):null)?`The audio is spoken ${n}. Transcribe it verbatim in ${n}.
2
+ - Do NOT translate to any other language.`:"Auto-detect spoken language; do NOT translate.",`Transcribe this audio accurately for a developer coding & terminal context.
3
+ - ${r}
4
+ - Keep English tech terms, code, and CLI commands in English (e.g. git, npm, docker, API, bug, log, deploy).
5
+ - Add natural punctuation. Omit filler sounds.
6
+ - Output ONLY the transcribed text.`),{blob:i,format:o}=await S(t),c=await new Promise(e=>{let t=new FileReader;t.onload=()=>e(String(t.result).split(",")[1]),t.readAsDataURL(i)});e.preset;let d=await w(l,{model:l.model,messages:[{role:"user",content:[{type:"text",text:a},{type:"input_audio",input_audio:{data:c,format:o}}]}]});return d?.choices?.[0]?.message?.content?.trim()||""}let $=(e,t)=>{try{let s=Array.isArray(t)?JSON.stringify(t):"boolean"==typeof t?t?"1":"0":t;localStorage.setItem(v[e],s)}catch{}};function z(e){try{let t=u.d.getState().bus;if(!t||"function"!=typeof t.emit)return;t.emit("setVoiceConfig",{voiceConfig:{enabled:e.enabled,mode:e.mode,preset:e.preset,geminiKeys:e.geminiKeys,geminiModel:e.geminiModel,openrouterKey:e.openrouterKey,openrouterModel:e.openrouterModel,customEndpoint:e.customEndpoint,customModel:e.customModel,customKey:e.customKey,opencodeModel:e.opencodeModel}})}catch{}}let M=(0,b.v)((e,t)=>({enabled:!0,mode:"browser",preset:"gemini",geminiKeys:[],geminiModel:"",openrouterKey:"",openrouterModel:"",customEndpoint:"",customModel:"",customKey:"",opencodeModel:"",setEnabled:s=>{t().enabled!==s&&($("enabled",s),e({enabled:s}),z(t()))},setMode:s=>{t().mode!==s&&($("mode",s),e({mode:s}),z(t()))},setPreset:s=>{t().preset!==s&&($("preset",s),e({preset:s}),z(t()))},setField:(s,n)=>{t()[s]!==n&&($(s,n),e({[s]:n}),z(t()))},setEngine:(s,n)=>{let r=t();(r.mode!==s||r.preset!==n)&&($("mode",s),$("preset",n),e({mode:s,preset:n}),z(t()))},syncFromHost:t=>{t&&"object"==typeof t&&e(e=>{let s={...e},n=!1,r=(e,t,r)=>{let l;!e||(l=s[t],Array.isArray(l)&&Array.isArray(r)?l.length===r.length&&l.every((e,t)=>e===r[t]):l===r)||(s[t]=r,n=!0,$(t,r))},l=Array.isArray(t.geminiKeys)?t.geminiKeys.filter(e=>"string"==typeof e&&e.trim()):[],a=Array.isArray(e.geminiKeys)&&e.geminiKeys.some(e=>"string"==typeof e&&e.trim()),i="string"==typeof t.openrouterKey?t.openrouterKey.trim():"",o=!!e.openrouterKey?.trim(),c="string"==typeof t.customKey?t.customKey.trim():"",d=!!e.customKey?.trim(),u=l.length>0||!!i||!!c;l.length>0&&!a&&r(!0,"geminiKeys",l),i&&!o&&r(!0,"openrouterKey",i),c&&!d&&r(!0,"customKey",c);let x="string"==typeof t.customEndpoint?t.customEndpoint.trim():"";for(let s of(x&&!e.customEndpoint?.trim()&&r(!0,"customEndpoint",x),["geminiModel","openrouterModel","customModel","opencodeModel"])){let n="string"==typeof t[s]?t[s].trim():"";n&&!e[s]?.trim()&&r(!0,s,n)}return!(a||o||d)&&u&&(r(!!t.mode,"mode",t.mode),r(!!t.preset,"preset",t.preset),r("boolean"==typeof t.enabled,"enabled",t.enabled)),n?s:e})},syncFromAgent:e=>t().syncFromHost(e),pushToHost:()=>z(t()),pushToAgent:()=>z(t())}));try{let e=e=>localStorage.getItem(v[e]),t={enabled:"0"!==e("enabled"),mode:"ai"===e("mode")?"ai":"browser",preset:["gemini","openrouter","opencode","custom"].includes(e("preset"))?e("preset"):null,geminiKeys:(e=>{try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}})(e("geminiKeys")),geminiModel:e("geminiModel")||"",openrouterKey:e("openrouterKey")||"",openrouterModel:e("openrouterModel")||"",customEndpoint:e("customEndpoint")||"",customModel:e("customModel")||"",customKey:e("customKey")||"",opencodeModel:e("opencodeModel")||""};if(!t.preset){let s=e("endpoint")||"",n=e("apiKey")||"",r=e("model")||"";s.includes("generativelanguage")?(t.preset="gemini",n&&(t.geminiKeys=[n])):s&&s!==g?(t.preset="custom",t.customEndpoint=s,t.customKey=n,t.customModel=r):n||r?(t.preset="openrouter",t.openrouterKey=n):t.preset="gemini",$("preset",t.preset),r&&"custom"!==t.preset&&(t[`${t.preset}Model`]=r),t.geminiModel&&$("geminiModel",t.geminiModel),t.openrouterModel&&$("openrouterModel",t.openrouterModel),t.geminiKeys.length&&$("geminiKeys",t.geminiKeys),t.openrouterKey&&$("openrouterKey",t.openrouterKey),t.customEndpoint&&$("customEndpoint",t.customEndpoint),t.customModel&&$("customModel",t.customModel),t.customKey&&$("customKey",t.customKey)}M.setState(t)}catch{}var P=s(98988),A=s(86129),I=s(31408),D=s(51627),L=s(27520);let B=e=>{let t=P.rh.getState();t._patchHost(t.currentKey,e)};var F=s(87670);let K=(0,b.v)(e=>({isKeyboardOpen:!1,setKeyboardOpen:t=>{e({isKeyboardOpen:t}),"u">typeof document&&document.body.classList.toggle("keyboard-open",t)}}));var O=s(79253);function W(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e,s=new DataView(t.buffer,t.byteOffset,t.byteLength);return{uploadId:s.getUint32(0,!0),offset:s.getUint32(4,!0),payload:t.slice(8)}}let _={balanced:{bitsPerPixel:.16,maxFps:30,edgeScale:.55,maxBitRate:4e6},quality:{bitsPerPixel:.2,maxFps:30,edgeScale:.8,maxBitRate:8e6},saver:{bitsPerPixel:.14,maxFps:24,edgeScale:.4,maxBitRate:2e6}},H="balanced",U=["V","D","I","W","E","F"],q={V:"text-text-muted",D:"text-text-muted",I:"text-text",W:"text-amber-400",E:"text-red-400",F:"text-red-500 font-semibold"};function X(e,t,s){return new Promise(n=>{e?e.emit(t,s,e=>n(e||{success:!1,error:"No response"})):n({success:!1,error:"Not connected"})})}class V{constructor(e){this.totalSize=e,this._contiguous=0,this._gaps=new Map,this.watermark=0}mark(e,t){if(0===this.totalSize||e<this._contiguous)return null;for(this._gaps.set(e,t);this._gaps.has(this._contiguous);){let e=this._gaps.get(this._contiguous);this._gaps.delete(this._contiguous),this._contiguous+=e}return this._contiguous>this.watermark?(this.watermark=this._contiguous,this.watermark):null}isComplete(){return this.watermark>=this.totalSize}}class J{constructor(){this.skipAll=!1,this.replaceAll=!1}resolve(e){return e?this.replaceAll?"replace":this.skipAll?"skip":"ask":"write"}record(e){"skipAll"===e?this.skipAll=!0:"replaceAll"===e&&(this.replaceAll=!0)}}async function G({bus:e,protocolRef:t,targetDir:s,items:n,callbacks:r}){let{onConflict:l,onProgress:a,onFileDone:i,onError:o}=r||{},c=new J;for(let{file:r,relativePath:d}of n)try{let n=await Y(e,t,s,r,d,c,l,a);i?.(r,n.status)}catch(e){o?.(r,e)}}async function Y(e,t,s,n,r,l,a,i){var o,c,d,u,x;let m=await X(e,"upload:start",{targetDir:s,relativePath:r,size:n.size,mtime:n.lastModified||0});if(!m.success)throw Error(m.error);let{uploadId:p,exists:f}=m;if(f){let t=l.resolve(!0);if("ask"===t){let e=await a?.(n,r);l.record(e),t=l.resolve(!0)}if("skip"===t)return e.emit("upload:cancel",{uploadId:p}),{status:"skipped"}}return await (o=e,c=t,d=p,u=n,x=i,new Promise(async(e,t)=>{let s,n=u.size,r=A.HE.chunkSize,l=r*A.HE.windowSize;try{s=new Uint8Array(await u.arrayBuffer())}catch(e){t(e);return}let a=function(e,t){if(e<=0)return[];let s=[],n=0;for(;n<e;){let r=Math.min(t,e-n);s.push({offset:n,length:r}),n+=r}return s}(n,r),i=0,m=0,p=0,f=!1,h=({uploadId:e,offset:t})=>{e===d&&(t>p&&(p=t,x?.(u,n?p/n:1)),p>=n&&!f?(f=!0,o.emit("upload:end",{uploadId:d})):w())},b=({uploadId:e,error:s})=>{e===d&&(v(),t(Error(s)))},g=({uploadId:t})=>{t===d&&(v(),e())};function v(){o.off("upload:ack",h),o.off("upload:error",b),o.off("upload:done",g)}o.on("upload:ack",h),o.on("upload:error",b),o.on("upload:done",g);let y=e=>{let t=c?.current;return t?.sendBinary?t.sendBinary(A.l_.file,e):(o.emit("file-bin",e),!0)};function w(){for(;i<a.length&&m-p<l;){let e=a[i];if(!y(function(e,t,s){let n=s instanceof ArrayBuffer?new Uint8Array(s):s,r=new Uint8Array(8+n.byteLength),l=new DataView(r.buffer);return l.setUint32(0,e>>>0,!0),l.setUint32(4,t>>>0,!0),r.set(n,8),r}(d,e.offset,s.subarray(e.offset,e.offset+e.length))))break;i++,m=e.offset+e.length}if(p>=n&&!f){f=!0,o.emit("upload:end",{uploadId:d});return}i<a.length&&m-p<l&&setTimeout(w,50)}w()})),{status:"done"}}let Z=e=>t=>{e((0,O.RV)(t))};function Q(e,t=()=>null,s=e){return{getSystemInfo:()=>new Promise(t=>{let s=e();if(!s)return t({success:!1,error:"Not connected"});s.emit("getSystemInfo",t)}),getFiles:(t,s=!1)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("getFiles",{dirPath:t,showHidden:s},Z(n))}),readFile:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("readFile",{filePath:t},s)}),readImage:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("readImage",{filePath:t},s)}),readMedia:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("readMedia",{filePath:t},s)}),writeFile:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("writeFile",{filePath:t,content:s},n)}),createItem:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("createItem",{itemPath:t,type:s},n)}),deleteItem:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("deleteItem",{itemPath:t},s)}),renameItem:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("renameItem",{oldPath:t,newPath:s},n)}),copyItem:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("copyItem",{srcPath:t,destPath:s},n)}),gitStatus:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("gitStatus",{repoPath:t},Z(s))}),gitChangedCount:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("gitChangedCount",{repoPath:t},s)}),gitFileStatus:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("gitFileStatus",{repoPath:t,filePath:s},Z(n))}),gitDiff:(t,s,n)=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});l.emit("gitDiff",{repoPath:t,file:s,status:n},r)}),gitShowMedia:(t,s,n="HEAD")=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});l.emit("gitShowMedia",{repoPath:t,file:s,ref:n},r)}),searchFiles:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("searchFiles",{workspace:t,query:s},Z(n))}),gitDiscard:(t,s,n)=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});l.emit("gitDiscard",{repoPath:t,file:s,status:n},r)}),searchInFiles:(t,s,n={})=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});let{caseSensitive:a=!1,wholeWord:i=!1,regex:o=!1,includeGlob:c="",excludeGlob:d=""}=n;l.emit("searchInFiles",{workspace:t,query:s,caseSensitive:a,wholeWord:i,regex:o,includeGlob:c,excludeGlob:d},Z(r))}),replaceInFiles:(t,s,n,r={},l=[])=>new Promise(a=>{let i=e();if(!i)return a({success:!1,error:"Not connected"});let{caseSensitive:o=!1,regex:c=!1,includeGlob:d="",excludeGlob:u=""}=r;i.emit("replaceInFiles",{workspace:t,query:s,replacement:n,caseSensitive:o,regex:c,includeGlob:d,excludeGlob:u,files:l},a)}),watchDir:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("watchDir",{dirPath:t},s)}),unwatchDir:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("unwatchDir",{dirPath:t},s)}),onFileChange:e=>{let t=s();return t?(t.on("fileChange",e),()=>t.off("fileChange",e)):()=>{}},revealInOS:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("revealInOS",{filePath:t},s)}),openInTerminal:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("openInTerminal",{dirPath:t},s)}),getFileTree:(t,s=1,n=!1)=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});l.emit("getFileTree",{dirPath:t,depth:s,showHidden:n},Z(r))}),gitBranch:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("gitBranch",{repoPath:t},s)}),gitScanRepos:(t,s,n)=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});l.emit("gitScanRepos",{rootPath:t,maxDepth:s,force:n},r)}),gitWorkspaceChangedCount:(t,s,n)=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});l.emit("gitWorkspaceChangedCount",{rootPath:t,maxDepth:s,force:n},r)}),gitRefreshRepos:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("gitRefreshRepos",{rootPath:t},s)}),gitWorktreeList:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("gitWorktreeList",{repoPath:t},s)}),gitWorktreeAdd:(t,s,n,r)=>new Promise(l=>{let a=e();if(!a)return l({success:!1,error:"Not connected"});a.emit("gitWorktreeAdd",{repoPath:t,worktreePath:s,branch:n,newBranch:r},l)}),gitWorktreeRemove:(t,s,n={})=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});l.emit("gitWorktreeRemove",{repoPath:t,worktreePath:s,...n},r)}),gitBranchList:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("gitBranchList",{repoPath:t},s)}),gitBranchCheckout:(t,s,n)=>new Promise(r=>{let l=e();if(!l)return r({success:!1,error:"Not connected"});l.emit("gitBranchCheckout",{repoPath:t,branch:s,create:n},r)}),gitAdd:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("gitAdd",{repoPath:t,files:s},n)}),gitReset:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("gitReset",{repoPath:t,files:s},n)}),gitCommit:(t,s)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("gitCommit",{repoPath:t,message:s},n)}),gitPush:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("gitPush",{repoPath:t},s)}),gitPull:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("gitPull",{repoPath:t},s)}),gitLog:(t,s=50)=>new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("gitLog",{repoPath:t,limit:s},Z(n))}),uploadFiles:(s,n,r)=>{let l=e();return l?G({bus:l,protocolRef:t(),targetDir:s,items:n,callbacks:r}):(r?.onError?.(null,Error("Not connected")),Promise.resolve())},downloadFile:(s,n)=>{let r=e();return r?function({bus:e,protocolRef:t,filePath:s,onSave:n,onProgress:r,onError:l}){let a=null,i=null,o=null,c=null,d=null,u=e=>{let t;try{t=W(e)}catch{return}t.uploadId===a&&(d.set(t.offset,t.payload),c&&(c.mark(t.offset,t.payload.byteLength),r&&i&&r(c.watermark/i)))},x=({downloadId:e})=>{if(e===a&&(!c||c.isComplete())){let e;p(),e=[...d.entries()].sort((e,t)=>e[0]-t[0]).map(([,e])=>e),n?.(new Blob(e),{size:i,fileName:o})}},m=({downloadId:e,error:t})=>{e===a&&(p(),l?.(Error(t)))};function p(){e.off("file-bin",u),e.off("download:done",x),e.off("download:error",m)}X(e,"download:start",{filePath:s}).then(t=>{t.success?(a=t.downloadId,i=t.size,o=t.fileName,c=null!=i?new V(i):null,d=new Map,e.on("file-bin",u),e.on("download:done",x),e.on("download:error",m)):l?.(Error(t.error))}).catch(e=>l?.(e))}({bus:r,protocolRef:t(),filePath:s,...n}):(n?.onError?.(Error("Not connected")),Promise.resolve())},streamMedia:(t,s)=>{let n=e();return n?function({bus:e,filePath:t,onMeta:s,onChunk:n,onDone:r,onError:l}){let a=null,i=new Map,o=0,c=()=>{for(;i.has(o);){let e=i.get(o);i.delete(o),n?.(e),o+=e.byteLength}},d=e=>{let t;if(null!=a){try{t=W(e)}catch{return}t.uploadId===a&&(i.set(t.offset,t.payload),c())}},u=({downloadId:e})=>{e===a&&(m(),r?.())},x=({downloadId:e,error:t})=>{e===a&&(m(),l?.(Error(t)))};function m(){e.off("file-bin",d),e.off("download:done",u),e.off("download:error",x)}return e.on("file-bin",d),e.on("download:done",u),e.on("download:error",x),X(e,"streamMedia:start",{filePath:t}).then(e=>{if(!e.success){m(),l?.(Error(e.error));return}a=e.streamId,s?.({mime:e.mime,size:e.size,width:e.width,height:e.height,scaled:e.scaled,originalWidth:e.originalWidth,originalHeight:e.originalHeight}),c()}).catch(e=>{m(),l?.(e)}),()=>{m(),null!=a&&e.emit("download:cancel",{downloadId:a})}}({bus:n,filePath:t,...s}):(s?.onError?.(Error("Not connected")),{cancel:()=>{}})},previewStart:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1,error:"Not connected"});n.emit("preview:start",{filePath:t},s)}),previewEnd:t=>new Promise(s=>{let n=e();if(!n)return s({success:!1});n.emit("preview:end",{sessionId:t},s)})}}let ee=()=>{let e=u.d.getState();return e.connected?e.busRef?.current||e.bus:null},et=()=>u.d.getState().protocolRef,es=()=>{let e=u.d.getState();return e.busRef?.current||e.bus},en=(0,b.v)(()=>Q(ee,et,es));function er(){return en.getState()}var el=s(64683);let ea={recv:"text-green-400",join:"text-blue-400",reconnect:"text-yellow-400",switch:"text-purple-400",resize:"text-cyan-400",send:"text-orange-400","ai-hydrate":"text-pink-400","ai-page":"text-amber-400","ai-gate":"text-red-400"};function ei(e){let t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}.${String(t.getMilliseconds()).padStart(3,"0")}`}function eo(){let[e,t]=(0,r.useState)(!1),[s,l]=(0,r.useState)(()=>(0,L.FQ)()),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(""),d=(0,r.useRef)(null),[u,x]=(0,r.useState)(()=>{try{let e=JSON.parse(localStorage.getItem("9remote:termLogBtn")||"null");if(e&&Number.isFinite(e.x)&&Number.isFinite(e.y))return e}catch{}return{x:8,y:8}}),m=(0,r.useRef)({dragging:!1,startX:0,startY:0,origX:0,origY:0,moved:!1}),p=e=>{let s=m.current;if(s.dragging){s.dragging=!1;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}if(s.moved)try{localStorage.setItem("9remote:termLogBtn",JSON.stringify(u))}catch{}else t(e=>!e)}};if((0,r.useEffect)(()=>{let e=()=>{m.current.dragging&&(m.current.dragging=!1)};return window.addEventListener("blur",e),()=>window.removeEventListener("blur",e)},[]),(0,r.useEffect)(()=>{if((0,L.UX)())return(0,L.yO)(()=>{a||l([...(0,L.FQ)()])})},[a]),(0,r.useEffect)(()=>{e&&d.current&&(d.current.scrollTop=d.current.scrollHeight)},[s,e]),!(0,L.UX)())return null;let f=o?s.filter(e=>e.category.includes(o)||e.msg.includes(o)):s,h=async()=>{let e=f.map(e=>`${ei(e.ts)} ${e.category} ${e.msg}`).join("\n");try{await navigator.clipboard?.writeText(e)}catch{}};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{style:{left:u.x,top:u.y},onPointerDown:e=>{m.current={dragging:!0,startX:e.clientX,startY:e.clientY,origX:u.x,origY:u.y,moved:!1};try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}},onPointerMove:e=>{let t=m.current;if(!t.dragging)return;if("mouse"===e.pointerType&&0===e.buttons)return void p(e);let s=e.clientX-t.startX,n=e.clientY-t.startY;(Math.abs(s)>4||Math.abs(n)>4)&&(t.moved=!0);let r=window.innerWidth,l=window.innerHeight;x({x:Math.max(4,Math.min(r-44,t.origX+s)),y:Math.max(4,Math.min(l-44,t.origY+n))})},onPointerUp:p,onPointerCancel:p,className:"fixed z-[80] px-1.5 py-1 rounded-full bg-surface-2/90 backdrop-blur-sm shadow-md text-text border border-border-subtle touch-none select-none cursor-grab active:cursor-grabbing",title:"Dev log (drag to move)",children:(0,n.jsx)("span",{className:"text-[10px] font-bold leading-none",children:s.length})}),e&&(0,n.jsx)("div",{className:"fixed inset-x-0 bottom-0 z-[79] flex flex-col pb-safe",style:{height:"55vh"},children:(0,n.jsxs)("div",{className:"bg-surface-2/95 backdrop-blur-sm border-t border-border-subtle rounded-t-xl shadow-2xl flex flex-col h-full overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-xs font-semibold text-text",children:"termLog"}),(0,n.jsxs)("span",{className:"text-[10px] text-text-muted",children:["(",f.length,"/",s.length,")"]}),(0,n.jsx)("input",{value:o,onChange:e=>c(e.target.value),placeholder:"filter…",className:"flex-1 min-w-0 text-[11px] bg-surface px-2 py-0.5 rounded border border-border-subtle text-text"}),(0,n.jsx)("button",{onClick:()=>i(e=>!e),className:"p-1 text-text-muted hover:text-text text-[10px]",title:a?"Resume":"Pause",children:a?"▶":"⏸"}),(0,n.jsx)("button",{onClick:h,className:"p-1 text-text-muted hover:text-text",title:`Copy ${f.length} rows`,children:(0,n.jsx)(el.QR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,L.k_)(),l([])},className:"p-1 text-text-muted hover:text-text",title:"Clear",children:(0,n.jsx)(el.TB,{size:13})}),(0,n.jsx)("button",{onClick:()=>t(!1),className:"p-1 text-text-muted hover:text-text",title:"Close",children:(0,n.jsx)(el.X,{size:14})})]}),(0,n.jsx)("div",{ref:d,className:"flex-1 overflow-y-auto overflow-x-auto px-2 py-1 font-mono text-[10px] leading-tight",children:0===f.length?(0,n.jsx)("p",{className:"text-text-muted text-center py-4",children:"No logs yet"}):f.map((e,t)=>(0,n.jsxs)("div",{className:"flex gap-1.5 py-0.5 hover:bg-surface rounded px-1",children:[(0,n.jsx)("span",{className:"text-text-muted flex-shrink-0",children:ei(e.ts)}),(0,n.jsx)("span",{className:`flex-shrink-0 font-bold ${ea[e.category]||"text-text"}`,children:e.category}),(0,n.jsx)("span",{className:"text-text break-all whitespace-pre-wrap",children:e.msg})]},t))})]})})]})}var ec=s(42174),ed=s(8910),eu=s(78762);let ex=(e="")=>`recentWorkspaces${e}`,em=O.cv,ep=e=>{if(!e)return e;let t={...e};return"string"==typeof t.path&&(t.path=(0,O.kb)(t.path)),"string"==typeof t.lastPath&&(t.lastPath=(0,O.kb)(t.lastPath)),Array.isArray(t.openedFiles)&&(t.openedFiles=t.openedFiles.map(e=>e&&"object"==typeof e?{...e,path:(0,O.kb)(e.path)}:e)),"string"==typeof t.activeFile&&(t.activeFile=(0,O.kb)(t.activeFile)),t};function ef(e=""){try{return JSON.parse(localStorage.getItem(ex(e))||"[]").map(ep)}catch{return[]}}function eh(e,t=""){let s=(0,O.kb)(e),n=ef(t),r=n.find(e=>e.path===s),l=n.filter(e=>e.path!==s);l.unshift({path:s,lastOpened:Date.now(),lastPath:r?.lastPath,name:r?.name,pinned:r?.pinned||!1,openedFiles:r?.openedFiles||[]});let a=l.filter(e=>e.pinned),i=l.filter(e=>!e.pinned).slice(0,em);localStorage.setItem(ex(t),JSON.stringify([...a,...i]))}function eb({onSelect:e,onBrowse:t,onBack:s,isCodespaces:l,systemInfo:a}){let{t:i}=(0,eu.s)(),[o,c]=(0,r.useState)([]),[d,u]=(0,r.useState)({isOpen:!1,path:null,name:""});return(0,r.useEffect)(()=>{c(ef())},[]),(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface px-4 py-3 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s()},className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}),(0,n.jsx)("h1",{className:"text-text text-lg font-semibold",children:i("files.selectWorkspace")})]}),(0,n.jsxs)("div",{className:"flex-1 p-4 overflow-auto modal-scrollable",children:[o.length>0&&(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsx)("h2",{className:"text-text-muted text-sm font-medium mb-3",children:i("files.recentWorkspaces")}),(0,n.jsx)("div",{className:"space-y-2",children:o.map(t=>{var s;let r,l,a,o,c;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),e(t.path)},className:"w-full bg-surface hover:bg-surface-2 rounded-brand-lg p-4 flex items-center gap-3 transition-all duration-150 ease-out active:scale-[0.99] text-left",children:[(0,n.jsx)(el.vd,{size:24,className:"text-text-subtle flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-text font-medium truncate",children:(r=t.path).split("/").pop()||r}),(0,n.jsx)("div",{className:"text-text-muted text-sm truncate",title:t.path,children:t.path.replace(/^\/Users\/[^/]+/,"~")}),(0,n.jsx)("div",{className:"text-text-muted text-xs mt-1",children:(s=t.lastOpened,a=Math.floor((l=Date.now()-s)/6e4),o=Math.floor(l/36e5),c=Math.floor(l/864e5),a<60?i("common.minutesAgo",{n:a}):o<24?i("common.hoursAgo",{n:o}):i("common.daysAgo",{n:c}))})]}),(0,n.jsx)("div",{onClick:e=>{(0,ed.e)(),e.stopPropagation(),u({isOpen:!0,path:t.path,name:t.path.split("/").pop()||t.path})},className:"p-2 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-all duration-200 flex-shrink-0",title:i("files.removeRecent"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})}),(0,n.jsx)("svg",{className:"w-5 h-5 text-text-muted flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]},t.path)})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-text-muted text-sm font-medium mb-3",children:i("files.selectWorkspace")}),(0,n.jsxs)("div",{className:"space-y-2",children:[a?.isWindows?(0,n.jsx)(n.Fragment,{children:a.drives?.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),t(e.path)},className:"w-full bg-surface hover:bg-surface-2 rounded-brand-lg p-4 flex items-center gap-3 transition-all duration-150 ease-out active:scale-[0.99] text-left",children:[(0,n.jsx)(el.ak,{size:24,className:"text-blue-500/70"}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("div",{className:"text-text font-medium",children:i("files.drive",{letter:e.letter})}),(0,n.jsx)("div",{className:"text-text-muted text-sm",children:e.path})]}),(0,n.jsx)("svg",{className:"w-5 h-5 text-text-muted",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]},e.letter))}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),t("~")},className:"w-full bg-surface hover:bg-surface-2 rounded-brand-lg p-4 flex items-center gap-3 transition-all duration-150 ease-out active:scale-[0.99] text-left",children:[(0,n.jsx)(el.ww,{size:24,className:"text-blue-500/70"}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("div",{className:"text-text font-medium",children:i("files.home")}),(0,n.jsx)("div",{className:"text-text-muted text-sm",children:"~/"})]}),(0,n.jsx)("svg",{className:"w-5 h-5 text-text-muted",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),t("/")},className:"w-full bg-surface hover:bg-surface-2 rounded-brand-lg p-4 flex items-center gap-3 transition-all duration-150 ease-out active:scale-[0.99] text-left",children:[(0,n.jsx)(el.ak,{size:24,className:"text-text-subtle"}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("div",{className:"text-text font-medium",children:i("files.root")}),(0,n.jsx)("div",{className:"text-text-muted text-sm",children:"/"})]}),(0,n.jsx)("svg",{className:"w-5 h-5 text-text-muted",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]})]}),l&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),t("/workspaces")},className:"w-full bg-purple-500/15 hover:bg-purple-500/25 rounded-brand-lg p-4 flex items-center gap-3 transition-all duration-150 ease-out active:scale-[0.99] text-left",children:[(0,n.jsx)(el.sU,{size:24,className:"text-purple-400"}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("div",{className:"text-text font-medium",children:i("files.codespaces")}),(0,n.jsx)("div",{className:"text-purple-400 text-sm",children:"/workspaces"})]}),(0,n.jsx)("svg",{className:"w-5 h-5 text-purple-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]})]})]})]}),(0,n.jsx)(ec.A,{isOpen:d.isOpen,onClose:()=>u({isOpen:!1,path:null,name:""}),onConfirm:()=>{d.path&&(!function(e,t=""){let s=(0,O.kb)(e),n=ef(t).filter(e=>e.path!==s);localStorage.setItem(ex(t),JSON.stringify(n))}(d.path),c(ef())),u({isOpen:!1,path:null,name:""})},title:i("files.removeTitle"),message:i("files.removeMessage",{name:d.name})})]})}let eg=(e,t)=>{if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;let s=Object.keys(e),n=Object.keys(t);if(s.length!==n.length)return!1;for(let n of s)if(e[n]!==t[n])return!1;return!0},ev=(0,b.v)((e,t)=>({isOpen:!1,activePanel:"menu",context:{connected:!1,remoteAvailable:!1,showTheme:!1,theme:"default",busRef:null,tunnelUrl:null,apiKey:null,hideActions:[],connectionMode:"tunnel",hostVersion:null,agentVersion:null,transport:"ws"},callbacks:{onRemote:null,onFiles:null,onLogout:null,onThemeChange:null,onUpdate:null,onRestart:null},cachedSites:[],currentSites:[],loadingSites:!1,open:(t="menu")=>e({isOpen:!0,activePanel:t}),close:()=>e({isOpen:!1,activePanel:"menu"}),setActivePanel:t=>e({activePanel:t}),setContext:t=>e(e=>{let s={...e.context,...t},n=!1;for(let t of Object.keys(s))if(!eg(e.context[t],s[t])){n=!0;break}return n?{context:s}:e}),setCallbacks:s=>{let n=t().callbacks,r=!1;for(let e of Object.keys(s))!!n[e]!=!!s[e]&&(r=!0),n[e]=s[e];r&&e({callbacks:{...n}})},setCachedSites:t=>e({cachedSites:t}),setCurrentSites:t=>e({currentSites:t}),setLoadingSites:t=>e({loadingSites:t}),openPwa:()=>e({isOpen:!0,activePanel:"pwa"}),openMenu:()=>e({isOpen:!0,activePanel:"menu"})})),ey=(e,t)=>{let{[t]:s,...n}=e;return n},ew=e=>{let{hosts:t}=P.rh.getState();for(let s of Object.values(t)){let t=s.statusMap?.[e];if(t)return t}return null},ej=(0,b.v)((e,t)=>({notifications:{},handleStatusChange:({sessionId:t,state:s,tool:n,since:r}={})=>{t&&e(e=>{let l="done"===s||"blocked"===s,a=e.notifications;if(l){let l={sessionId:t,type:s,tool:void 0!==n?n:ew(t)?.tool,timestamp:r};(0,I.dI)(e.notifications[t],l)||(a={...e.notifications,[t]:l})}else t in e.notifications&&(a=ey(e.notifications,t));return{notifications:a}})},handleNotificationState:t=>e(e=>{let s=t||{};return(0,I.h3)(e.notifications,s)?e:{notifications:s}}),clearNotification:s=>{if(!s)return;let n=ew(s)?.state;if("blocked"===n||!t().notifications[s]&&"done"!==n)return;e(e=>({notifications:s in e.notifications?ey(e.notifications,s):e.notifications}));let r=null,{hosts:l}=P.rh.getState();for(let e of Object.values(l))if(e.sessions?.some(e=>e.id===s)){r=(0,P.eJ)(e.key);break}r=r||u.d.getState().busRef?.current||u.d.getState().bus,r?.emit("clearStatus",s)},reset:()=>e({notifications:{}})})),ek=(e,t)=>`${e}:${t}`,eN=e=>e?`@${e}`:"",eC=(e,t)=>"string"==typeof e&&e.startsWith(`${t}:`)?e.slice(t.length+1):null;function eS(e,t){let s=t||"main";return e.some(e=>e.key===s)?e:[{key:"main"},...e]}class eT{constructor(e){this.head=e||null,this._busRef={current:null},this._pmRef={current:null}}get scope(){return eN(this.head||P.rh.getState().currentKey||null)}get bus(){if(!this.head){let e=u.d.getState();return e.connected?e.busRef?.current||e.bus:null}return(0,P.eJ)(this.head)}get busRef(){return this._busRef.current=this.bus,this._busRef}get pm(){return this.head?(0,P.d)(this.head):u.d.getState().protocolRef?.current||null}get pmRef(){return this._pmRef||(this._pmRef={current:null}),this._pmRef.current=this.pm,this._pmRef}get fileBus(){return this._fileBus||(this._fileBus=this.head?Q(()=>(0,P.eJ)(this.head)):en.getState()),this._fileBus}get carrier(){return this.head?P.rh.getState().hosts[this.head]?.carrier||"ws":u.d.getState().carrier||"ws"}get platform(){let e=P.rh.getState();return e.hosts[this.head||e.currentKey]?.platform||null}get version(){let e=P.rh.getState();return e.hosts[this.head||e.currentKey]?.version||null}}let eR=new Map;function eE(e){if(e&&e===P.rh.getState().currentKey)return eE(null);let t=e||"",s=eR.get(t);return s||(s=new eT(e),eR.set(t,s)),s}function e$(e){if(e){let{hosts:t}=P.rh.getState();for(let s of Object.values(t))if(s.sessions?.some(t=>t.id===e))return eE(s.key)}return eE(null)}function ez(e){let t=e?e$(e).head:null;return(0,P.rh)(s=>e?s.hosts[t||s.currentKey]?.statusMap?.[e]?.state:null)||"idle"}function eM(){let e=(0,P.rh)(e=>e.hosts);return(0,r.useMemo)(()=>{let t={};for(let s of Object.values(e))Object.assign(t,s.statusMap||{});return t},[e])}let eP={working:0,blocked:1,done:2,idle:3};function eA(e={},t=[]){return(t.length?t.map(t=>{let s=e[t.id];return{id:t.id,state:s?.state||"idle",tool:s?.tool,since:s?.since}}):Object.entries(e).map(([e,t])=>({id:e,...t}))).sort((e,t)=>{let s=(eP[e.state]??9)-(eP[t.state]??9);return 0!==s?s:(t.since||0)-(e.since||0)})}function eI(e={},t=[]){let s=eA(e,t),n=s.filter(e=>"blocked"===e.state),r=s.filter(e=>"done"===e.state);return{blocked:n.length,done:r.length,total:n.length+r.length,targetId:n[0]?.id||r[0]?.id||null}}let eD="9remote:push:userDisabled",eL="9Remote",eB="9Remote • ",eF=null,eK=0,eO=0,eW=null,e_=null;function eH(){!e_&&"u">typeof MutationObserver&&(e_=new MutationObserver(()=>{eW&&document.title!==eW&&eU(eW)})).observe(document.head,{childList:!0,subtree:!0,characterData:!0})}function eU(e){eW=e;let t=e_;t&&t.disconnect(),document.title=e;try{window.__TAURI__?.window?.getCurrentWindow?.().setTitle(e)?.catch?.(()=>{})}catch{}t&&t.observe(document.head,{childList:!0,subtree:!0,characterData:!0})}function eq(){let e=eB.slice(eK)+eB.slice(0,eK);eU(`(${eO}) 🔔 ${e}`),eK=(eK+1)%eB.length}function eX(e,t){eO=e,e>0?(eH(),eF||(eK=0,eq(),eF=setInterval(eq,400))):(eF&&(clearInterval(eF),eF=null),eK=0,t?(eH(),eU(`${t} • ${eL}`)):(e_&&(e_.disconnect(),e_=null),eW=null,document.title=eL))}function eV(e,{startWidth:t,axis:s=1,onWidth:n,onEnd:r}){e.preventDefault();let l=e.clientX,a=l,i=null,o=()=>{i=null,n((({startWidth:e,startX:t,x:s,axis:n=1})=>e+n*(s-t))({startWidth:t,startX:l,x:a,axis:s}))},c=e=>{0===e.buttons?d():(a=e.clientX,null===i&&(i=requestAnimationFrame(o)))},d=()=>{document.removeEventListener("pointermove",c),document.removeEventListener("pointerup",d),document.removeEventListener("pointercancel",d),window.removeEventListener("blur",d),document.body.style.cursor="",document.body.style.userSelect="",null!==i&&(cancelAnimationFrame(i),o()),r?.()};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("pointermove",c),document.addEventListener("pointerup",d),document.addEventListener("pointercancel",d),window.addEventListener("blur",d)}var eJ=s(34277);let eG=null,eY=(0,b.v)((e,t)=>({canInstall:!1,isInstalled:!1,setDeferredPrompt:t=>{eG=t,e({canInstall:!!t})},setIsInstalled:t=>e({isInstalled:t}),install:async()=>{if(!eG)return null;eG.prompt();let t=await eG.userChoice;return eG=null,e({canInstall:!1}),t?.outcome??null}})),eZ=!1;var eQ=s(33897),e0=s(73426);let e1=new Set(["codex","aider","pi","omp"]),e2="rounded-[3px] pointer-events-none select-none";function e5(e){if(!e||"null"===e||"undefined"===e)return null;let t=e.replace(/-ui$/,"");return`/agent-icons/${t}.${e1.has(t)?"svg":"png"}`}function e3(e){return!!(e?.yolo||e?.yoloEnv)}function e4(e,t=!1){if(!e?.cmd)return null;if(!t)return e.cmd;if(e.yolo)return`${e.cmd} ${e.yolo}`;if(e.yoloEnv){let t=Object.entries(e.yoloEnv).map(([e,t])=>`${e}=${t}`).join(" ");return`${t} ${e.cmd}`}return e.cmd}function e6(e,t){if(!e||!t)return t;if(e.yolo)return`${t} ${e.yolo}`;if(e.yoloEnv){let s=Object.entries(e.yoloEnv).map(([e,t])=>`${e}=${t}`).join(" ");return`${s} ${t}`}return t}let e8="9remote.terminal.shellPref",e9="9remote.terminal.agentPref",e7="9remote.terminal.yoloPref2";function te(e){try{return localStorage.getItem(e)||null}catch{return null}}function tt(e,t){try{localStorage.setItem(e,t)}catch{}}function ts(){return{agentId:te(e9)||"",shellId:te(e8),yolo:"0"!==te(e7)}}function tn(e,{onSelectSession:t=null,onSelectWorkspace:s=null}={}){let n=()=>(0,P.eJ)(e.key),r=t=>{let s=P.rh.getState(),n=s.hosts[e.key]?.sessions||[];s._patchHost(e.key,{sessions:t(n)})};return{selectSession:s=>{P.rh.getState().ensureHost(e.key),t?.(s)},selectWorkspace:async t=>{let n=P.rh.getState();if(e.key&&e.key!==n.currentKey)try{await (0,e0.x$)(e.full||e.key),s?.(t??"_");return}catch{}s?.(ek(e.key,t??"_"))},createSession:(s,n,l,a,i,o,c,d)=>{let u="string"==typeof i?null:i,x="string"==typeof i?i:i?.id||null,m=e4(u,o);(0,P.Nw)(e.key,i=>i.emit("createSession",{name:s,shellId:l,workspaceId:n,cwd:a,nameIsAuto:c,agent:x},i=>{i?.success&&i.sessionId&&(m&&h.B.getState().queueStartup(i.sessionId,m),x&&h.B.getState().setSessionAgent(i.sessionId,x),r(e=>e.some(e=>e.id===i.sessionId)?e:[...e,{id:i.sessionId,name:i.name||s||"",createdAt:Date.now(),cwd:i.cwd||a||null,workspaceId:n||null,shellId:i.shellId||l||null,agent:x}]),t?.(i.sessionId,ek(e.key,n??"_"))),d?.(i)}))},createWorkspace:(t,s=null,n=null)=>{(0,P.Nw)(e.key,e=>e.emit("createWorkspace",{name:t,path:s},e=>n?.(e)))},renameSession:(e,t)=>{n()?.emit("renameSession",{sessionId:e,name:t},()=>{}),r(s=>s.map(s=>s.id===e?{...s,name:t}:s))},deleteSession:e=>{n()?.emit("deleteSession",e,()=>{}),r(t=>t.filter(t=>t.id!==e))},reorderSession:e=>{n()?.emit("reorderSession",{orderedIds:e},()=>{});let t=new Map(e.map((e,t)=>[e,t]));r(e=>[...e].sort((e,s)=>(t.get(e.id)??1/0)-(t.get(s.id)??1/0)))},renameWorkspace:(e,t)=>{n()?.emit("renameWorkspace",{workspaceId:e,name:t},()=>{})},deleteWorkspace:e=>{n()?.emit("deleteWorkspace",{workspaceId:e},()=>{})}}}let tr=[{id:"sessionPrev",key:"ArrowLeft",label:"Previous terminal",mac:"⌥←",pc:"Ctrl+Shift+←"},{id:"sessionNext",key:"ArrowRight",label:"Next terminal",mac:"⌥→",pc:"Ctrl+Shift+→"},{id:"workspacePrev",key:"ArrowUp",label:"Previous workspace",mac:"⌥↑",pc:"Ctrl+Shift+↑"},{id:"workspaceNext",key:"ArrowDown",label:"Next workspace",mac:"⌥↓",pc:"Ctrl+Shift+↓"},{id:"attentionNext",code:"KeyA",label:"Next waiting terminal",mac:"⌥A",pc:"Alt+A"},{id:"closeTerminal",code:"KeyW",label:"Close terminal",mac:"⌥W",pc:"Alt+W"},{id:"fitPanes",key:"=",code:"Equal",label:"Auto-fit panes",mac:"⌥=",pc:"Ctrl+Shift+="},{id:"toggleFocus",code:"Backquote",label:"Toggle terminal / input focus",mac:"⌃`",pc:"Ctrl+`"},{id:"newTerminal",key:"Enter",label:"New terminal",mac:"⌥⇧↵",pc:"Ctrl+Shift+Enter"},{id:"palette",code:"KeyP",label:"Search files",mac:"⌥⇧P",pc:"Ctrl+Shift+P"},{id:"toggleSidebar",code:"KeyB",label:"Toggle sidebar",mac:"⌥⇧B",pc:"Ctrl+Shift+B"},{id:"toggleRightPanel",code:"KeyJ",label:"Toggle side panel",mac:"⌥⇧J",pc:"Ctrl+Shift+J"},{id:"help",code:"Slash",label:"Keyboard shortcuts",mac:"⌥⇧/",pc:"Ctrl+Shift+/"}],tl={id:"sessionIndex",label:"Go to terminal 1–9",mac:"⌥1…9",pc:"Ctrl+Shift+1…9"},ta=[{id:"switchTerminal",label:"Switch terminal",mac:"⌥← / →",pc:"Ctrl+Shift+← / →"},tl,{id:"switchWorkspace",label:"Switch workspace",mac:"⌥↑ / ↓",pc:"Ctrl+Shift+↑ / ↓"},tr.find(e=>"newTerminal"===e.id),tr.find(e=>"closeTerminal"===e.id),tr.find(e=>"fitPanes"===e.id),tr.find(e=>"toggleFocus"===e.id),tr.find(e=>"toggleSidebar"===e.id),tr.find(e=>"toggleRightPanel"===e.id),tr.find(e=>"palette"===e.id),tr.find(e=>"help"===e.id)].filter(Boolean),ti=/^Digit([1-9])$/,to=null,tc=()=>{if(null!==to)return to;if("u"<typeof navigator)return!1;let e=navigator.userAgentData?.platform;if(e)return to="macOS"===e;let t=navigator.userAgent||"",s=navigator.platform||"";return to=/Macintosh|Mac OS X|MacIntel/i.test(t+" "+s)&&!/iPhone|iPod/.test(t)},td=e=>tc()?e.mac:e.pc,tu="inline-flex h-6 min-w-6 items-center justify-center px-1.5 font-mono text-xs font-medium text-text leading-none select-none bg-surface-2 border border-border border-b-2 rounded-md shadow-[inset_0_-1px_0_rgba(0,0,0,0.08)] whitespace-nowrap",tx=new Set(["⌘","⌥","⇧","⌃"]);function tm(e){let t=td(e);if(t.includes("+"))return t.split("+");let s=[],n=t;n.startsWith("Opt ")&&(s.push("Opt"),n=n.slice(4));let r=0;for(;r<n.length&&tx.has(n[r]);)s.push(n[r]),r++;return r<n.length&&s.push(n.slice(r)),s}let tp=e=>!!e&&"function"==typeof e.closest&&!!(e.closest("[role=dialog]")||e.closest(".modal-overlay")||e.closest(".card-elev")),tf=e=>!(!e||"function"!=typeof e.closest||e.closest(".xterm"))&&(e.isContentEditable||"INPUT"===e.tagName||"TEXTAREA"===e.tagName);function th(e,t){let s=tr.find(e=>e.id===t);return s?`${e} \xb7 ${td(s)}`:e}let tb=(0,b.v)(e=>({isOpen:!1,open:()=>e({isOpen:!0}),close:()=>e({isOpen:!1}),toggle:()=>e(e=>({isOpen:!e.isOpen}))}));function tg(e,t="main"){let s=t&&"main"!==t?t:P.rh.getState().currentKey||"main",n=(0,h.B)(e=>e.agentClisBy[s]?.list),l=(0,P.rh)(e=>e.hosts[s]?.status||null);return(0,r.useEffect)(()=>{let t=h.B.getState().agentClisBy[s];t&&Date.now()-t.at<eJ.OM||e?.current?.emit("getAgentClis",e=>{let t=Array.isArray(e?.agents)?e.agents:Array.isArray(e)?e:null;t&&h.B.getState().setAgentClis(s,t)})},[e,s,l]),n}var tv=s(39096),ty=s(11472);let tw=(e,t=[])=>{let s=e.trim().split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toLowerCase().replace(/[^a-z0-9]/g,"");if(!s)return"";let n=s,r=2;for(;t.includes(n);)n=`${s}${r++}`;return n},tj=e=>(0,b.v)((0,ty.Zr)((e,t)=>({history:[],pinned:[],addCommand:t=>e(e=>{let s=t.trim();return!s||s.length>500||e.history[0]===s?e:{history:[s,...e.history.filter(e=>e!==s)].slice(0,100)}}),removeCommand:t=>e(e=>({history:e.history.filter(e=>e!==t)})),togglePin:t=>e(e=>{let s=t.trim();if(!s)return e;if(e.pinned.some(e=>e.cmd===s))return{pinned:e.pinned.filter(e=>e.cmd!==s)};let n=tw(s,e.pinned.map(e=>e.alias));return{pinned:[{cmd:s,alias:n},...e.pinned]}}),setSnippet:(t,s)=>e(e=>({pinned:e.pinned.map(e=>e.cmd===t?{cmd:(s.cmd??e.cmd).trim(),alias:(s.alias??e.alias).trim()}:e)})),resolveAlias:e=>{let s=e.trim(),n=t().pinned.find(e=>e.alias&&e.alias===s);return n?n.cmd:e},clearHistory:()=>e({history:[]})}),{name:e,version:1,migrate:(e,t)=>{if(t<1&&e?.pinned){let t=[];e.pinned=e.pinned.map(e=>{let s=tw(e,t);return t.push(s),{cmd:e,alias:s}})}return e},storage:{getItem:e=>{try{let t=localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}},setItem:(e,t)=>{try{localStorage.setItem(e,JSON.stringify(t))}catch{}},removeItem:e=>{localStorage.removeItem(e)}}})),tk=tj("terminal-command-history"),tN=tj("remote-input-history"),tC=tj("ai-command-history");function tS({snippet:e,onSave:t,onClose:s}){let{t:l}=(0,eu.s)(),[a,i]=(0,r.useState)(e?.alias??""),[o,c]=(0,r.useState)(e?.cmd??""),d=(0,r.useRef)(null);if((0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]),!e)return null;let u=o.trim().length>0;return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:s}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:l("history.editSnippet")}),(0,n.jsx)("button",{onClick:s,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":l("common.close"),children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsxs)("div",{className:"px-5 pb-5 flex flex-col gap-4",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)("label",{className:"text-xs font-semibold uppercase tracking-wide text-text-muted",children:l("history.aliasLabel")}),(0,n.jsx)("input",{type:"text",value:a,onChange:e=>i(e.target.value),placeholder:l("history.aliasPlaceholder"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:"w-full px-3 py-2 bg-surface-2 text-text font-mono text-sm rounded-brand outline-none focus:ring-1 focus:ring-brand-500"}),(0,n.jsx)("span",{className:"text-xs text-text-subtle",children:l("history.aliasHint")})]}),(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)("label",{className:"text-xs font-semibold uppercase tracking-wide text-text-muted",children:l("history.commandLabel")}),(0,n.jsx)("textarea",{ref:d,value:o,onChange:e=>c(e.target.value),rows:3,autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:"w-full px-3 py-2 bg-surface-2 text-text font-mono text-sm rounded-brand outline-none focus:ring-1 focus:ring-brand-500 resize-y min-h-[60px] max-h-[240px]"})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:s,className:"px-4 py-2 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand transition-colors",children:l("common.cancel")}),(0,n.jsxs)("button",{onClick:()=>{u&&((0,ed.e)(),t({cmd:o.trim(),alias:a.trim()}),s())},disabled:!u,className:"px-4 py-2 text-sm bg-brand-500 hover:bg-brand-500/80 text-white rounded-brand transition-colors flex items-center gap-1.5 disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)(el.aJ,{size:16}),l("common.save")]})]})]})]})]})}function tT({isOpen:e,onSelect:t,onClose:s,store:l=tk}){let{t:a}=(0,eu.s)(),i=l(e=>e.history),o=l(e=>e.pinned),c=l(e=>e.removeCommand),d=l(e=>e.clearHistory),u=l(e=>e.togglePin),x=l(e=>e.setSnippet),[m,p]=(0,r.useState)(null);if((0,r.useEffect)(()=>{if(!e)return;document.activeElement?.blur?.();let t=e=>{"Escape"!==e.key||m||s()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[e,s,m]),!e)return null;let f=e=>{(0,ed.e)(),t(e),s()};return(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200 touch-none",onClick:s}),(0,n.jsxs)("div",{className:"relative card-elev max-w-lg w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:a("history.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[i.length>0&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d()},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":a("history.clearAll"),title:a("history.clearAll"),children:(0,n.jsx)(el.TB,{size:18})}),(0,n.jsx)("button",{onClick:s,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":a("common.close"),children:(0,n.jsx)(el.X,{size:20})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable p-3",children:0===o.length&&0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(el.BZ,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:a("history.empty")})]}):(0,n.jsxs)("div",{className:"flex flex-col gap-0",children:[o.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 pt-1 pb-0.5 text-xs font-semibold uppercase tracking-wide text-text-muted",children:a("history.snippets")}),o.map(e=>(0,n.jsxs)("div",{className:"group flex items-center gap-2 rounded-brand hover:bg-surface-2 transition-all duration-150 ease-out",children:[(0,n.jsxs)("button",{onClick:()=>f(e.cmd),className:"flex-1 min-w-0 px-3 py-1 text-left flex items-center gap-2",children:[e.alias&&(0,n.jsx)("span",{className:"flex-shrink-0 px-1.5 py-0.5 text-xs font-mono font-semibold text-brand-500 bg-brand-500/10 rounded",children:e.alias}),(0,n.jsx)("span",{className:"min-w-0 text-sm text-text font-mono truncate",title:e.cmd,children:e.cmd})]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),p(e)},className:"flex-shrink-0 p-2 text-text-muted hover:text-text rounded-brand transition-colors","aria-label":a("history.editSnippet"),children:(0,n.jsx)(el.gH,{size:16})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u(e.cmd)},className:"flex-shrink-0 p-2 mr-1 text-brand-500 hover:text-brand-400 rounded-brand transition-colors","aria-label":a("history.unpin"),children:(0,n.jsx)(el.yU,{size:16,fill:"currentColor"})})]},`p-${e.cmd}`)),(0,n.jsx)("div",{className:"h-px bg-border/40 my-1"})]}),i.length>0&&(0,n.jsxs)(n.Fragment,{children:[o.length>0&&(0,n.jsx)("div",{className:"px-3 pt-0.5 pb-0.5 text-xs font-semibold uppercase tracking-wide text-text-muted",children:a("history.history")}),i.map(e=>{let t=o.some(t=>t.cmd===e);return(0,n.jsxs)("div",{className:"group flex items-center gap-2 rounded-brand hover:bg-surface-2 transition-all duration-150 ease-out",children:[(0,n.jsx)("button",{onClick:()=>f(e),className:"flex-1 min-w-0 px-3 py-1 text-left text-sm text-text font-mono truncate",title:e,children:e}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u(e)},className:`flex-shrink-0 p-2 rounded-brand transition-colors ${t?"text-brand-500 hover:text-brand-400":"text-text-muted hover:text-text"}`,"aria-label":t?a("history.unpin"):a("history.pin"),children:(0,n.jsx)(el.yU,{size:16,fill:t?"currentColor":"none"})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),c(e)},className:"flex-shrink-0 p-2 mr-1 text-text-muted hover:text-text rounded-brand transition-colors","aria-label":a("common.delete"),children:(0,n.jsx)(el.X,{size:16})})]},e)})]})]})})]}),m&&(0,n.jsx)(tS,{snippet:m,onSave:e=>x(m.cmd,e),onClose:()=>p(null)})]})}let tR={pinned:2,history:4,common:4,total:8},tE={pinned:1,history:2,common:2,total:4},t$=(e,t)=>{let s=e.indexOf(t);return s<0?null:1e3*(0!==s)+s+.1*e.length};function tz(e,t,s,n,r){let l=e.trim().toLowerCase();if(!l)return[];let a=new Set,i=(e,t,s)=>{let n=[];for(let r of e){let e=s(r),i=e.toLowerCase();if(!e||i===l||a.has(i))continue;let o=t$(i,l);null!==o&&(a.add(i),n.push({cmd:e,type:t,score:o}))}return n.sort((e,t)=>e.score-t.score)},o={pinned:i(s,"pinned",e=>e.cmd),history:i(t,"history",e=>e),common:i(n,"common",e=>e)},c=r?tE:tR,d=[...o.pinned.slice(0,c.pinned),...o.history.slice(0,c.history),...o.common.slice(0,c.common)];if(d.length<c.total){let e=new Set(d.map(e=>e.cmd)),t=[...o.pinned,...o.history,...o.common].filter(t=>!e.has(t.cmd)).sort((e,t)=>e.score-t.score).slice(0,c.total-d.length);d.push(...t)}return d.slice(0,c.total)}function tM({value:e,store:t,commonCommands:s=[],onSelect:l,isMobile:a=!1,disabled:i=!1,activeIndex:o=-1}){let c=t(e=>e.history),d=t(e=>e.pinned),[u,x]=(0,r.useState)(""),m=(0,r.useMemo)(()=>i?[]:tz(e,c,d,s,a),[e,c,d,s,a,i]),p=(0,r.useRef)(null);return((0,r.useEffect)(()=>{let e=p.current;if(!e||o<0)return;let t=e.children[o];t&&t.scrollIntoView({block:"nearest"})},[o]),0===m.length||u===e)?null:(0,n.jsxs)("div",{className:"absolute bottom-full left-0 right-0 mb-1 z-40 rounded-brand overflow-hidden bg-surface/95 backdrop-blur-xl shadow-xl ring-1 ring-border touch-none",children:[(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>x(e),className:"absolute right-1 top-1 z-10 w-5 h-5 flex items-center justify-center rounded-full bg-surface-2/80 text-text-muted hover:text-text transition-colors","aria-label":"Close",children:(0,n.jsx)(el.X,{size:12})}),(0,n.jsx)("div",{ref:p,className:"flex flex-col max-h-[25vh] overflow-y-auto modal-scrollable",children:m.map((e,t)=>{let s;return(0,n.jsxs)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),l(e.cmd)},className:`flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-2 transition-colors touch-none ${t===o?"bg-brand-500/15":""}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:"pinned"===(s=e.type)?(0,n.jsx)(el.yU,{size:13,className:"text-brand-500",fill:"currentColor"}):"common"===s?(0,n.jsx)(el.BK,{size:13,className:"text-text-muted"}):(0,n.jsx)(el.BZ,{size:13,className:"text-text-muted"})}),(0,n.jsx)("span",{className:"min-w-0 text-sm text-text font-mono truncate",title:e.cmd,children:e.cmd})]},`${e.type}-${e.cmd}`)})})]})}let tP={en:"en-US",vi:"vi-VN",zh:"zh-CN",ja:"ja-JP",ko:"ko-KR",es:"es-ES",fr:"fr-FR",de:"de-DE",pt:"pt-BR",ru:"ru-RU",ar:"ar-SA",hi:"hi-IN",id:"id-ID",th:"th-TH",tr:"tr-TR",it:"it-IT",nl:"nl-NL",pl:"pl-PL",uk:"uk-UA",fa:"fa-IR",ms:"ms-MY",sv:"sv-SE",he:"he-IL"},tA=e=>tP[e]||e||"en-US",tI="voiceLang";function tD(e){let[t,s]=(0,r.useState)(e&&tP[e]?e:"auto");return(0,r.useEffect)(()=>{let e=localStorage.getItem(tI);("auto"===e||e&&tP[e])&&s(e)},[]),[t,(0,r.useCallback)(e=>{s(e);try{localStorage.setItem(tI,e)}catch{}},[])]}let tL=new Set(["not-allowed","service-not-allowed","audio-capture","language-not-supported"]);function tB(){return window.SpeechRecognition||window.webkitSpeechRecognition||null}function tF({lang:e="en-US",onText:t,onError:s,onFinish:n}={}){let l=M(e=>e.mode),a=M(e=>e.enabled),[i,o]=(0,r.useState)(!1),[c,d]=(0,r.useState)(!1),[u,x]=(0,r.useState)(0),[m,p]=(0,r.useState)(null),f=(0,r.useRef)(n);(0,r.useEffect)(()=>{f.current=n},[n]);let h=(0,r.useRef)(s);(0,r.useEffect)(()=>{h.current=s},[s]);let b=(0,r.useRef)(t);(0,r.useEffect)(()=>{b.current=t},[t]);let g=(0,r.useRef)(!1),v=(0,r.useRef)(e);(0,r.useEffect)(()=>{if(v.current=e,g.current)try{y.current?.stop()}catch{}},[e]);let y=(0,r.useRef)(null),w=(0,r.useRef)(null),j=(0,r.useRef)(""),k=!!window.ReactNativeWebView||/9Remote-Mobile/i.test(navigator.userAgent),C=k&&/Android/i.test(navigator.userAgent),S=!!(navigator.mediaDevices?.getUserMedia&&window.MediaRecorder),T=!!(window.__TAURI__||window.__TAURI_INTERNALS__),R="browser"===l&&(T||C||!k&&!tB())&&S?"ai":l,$="ai"===R?S:!k&&!!tB(),z=(0,r.useCallback)(async()=>{g.current=!1;let e=w.current;if(w.current=null,!e){o(!1),d(!1),x(0);return}clearInterval(e.timer),x(0),d(!0);try{"inactive"!==e.rec.state&&e.rec.stop()}catch{}await e.stopped,e.stream.getTracks().forEach(e=>e.stop());try{e.ctx.close()}catch{}try{if(e.peak.v<3)return;let t=new Blob(e.chunks,{type:e.rec.mimeType||"audio/webm"}),s=await E(M.getState(),t,v.current),n=`${j.current}${s}`.replace(/\s+/g," ").trimStart();b.current?.(n),s?.trim()&&f.current?.(n)}catch(e){p("network"),h.current?.("network")}finally{o(!1),d(!1),x(0)}},[]),P=(0,r.useCallback)(async(e="")=>{j.current=e?e.replace(/\s*$/,"")+" ":"",p(null),g.current=!0,x(0),d(!1);let t=null;try{var s;let e;t=navigator.mediaDevices.getUserMedia({audio:!0});let n=await (s=t,Promise.race([s,new Promise((t,s)=>{e=setTimeout(()=>s({code:"mic-timeout"}),1e4)})]).finally(()=>clearTimeout(e))),r=N(n),l=[];r.ondataavailable=e=>{e.data.size&&l.push(e.data)};let a=new Promise(e=>{r.onstop=e}),i=new AudioContext;try{await i.resume()}catch{}let c=i.createAnalyser();c.fftSize=512,i.createMediaStreamSource(n).connect(c);let d=new Uint8Array(c.fftSize),u={v:0},m=setInterval(()=>{c.getByteTimeDomainData(d);let e=0;for(let t=0;t<d.length;t++)e+=Math.abs(d[t]-128);let t=e/d.length;t>u.v&&(u.v=t),x(Math.min(1,Math.max(0,(t-2)/20)))},80);w.current={stream:n,rec:r,chunks:l,stopped:a,ctx:i,timer:m,peak:u},r.start(),o(!0)}catch(s){g.current=!1,t&&t.then(e=>e.getTracks().forEach(e=>e.stop())).catch(()=>{});let e=s?.code==="mic-timeout"?"mic-timeout":s?.name==="NotAllowedError"||s?.name==="SecurityError"?"not-allowed":s?.name||"audio-capture";p(e),h.current?.(e)}},[]),A=(0,r.useCallback)(()=>{g.current=!1;let e=w.current;if(w.current=null,e){clearInterval(e.timer);try{"inactive"!==e.rec.state&&e.rec.stop()}catch{}e.stream.getTracks().forEach(e=>e.stop());try{e.ctx.close()}catch{}}try{y.current?.abort()}catch{}o(!1),d(!1),x(0)},[]),I=(0,r.useCallback)(()=>{if(g.current=!1,"ai"===R)return void z();try{y.current?.stop()}catch{}},[R,z]),D=(0,r.useCallback)(function e(){let t=tB();if(!t)return;let s=new t;s.lang="auto"===v.current?navigator.language||"en-US":v.current,s.continuous=!0,s.interimResults=!0,s.onresult=e=>{if(!g.current)return;let t="",s="";for(let n=e.resultIndex;n<e.results.length;n++){let r=e.results[n][0].transcript;e.results[n].isFinal?t+=r:s+=r}t&&(j.current=`${j.current}${t} `.replace(/\s+/g," "));let n=`${j.current}${s}`.replace(/\s+/g," ").trimStart();b.current?.(n)},s.onend=()=>{if(y.current=null,g.current)try{e()}catch{o(!1)}else{o(!1),x(0);let e=j.current.trim();e&&f.current?.(e)}},s.onerror=e=>{let t=e?.error||"error";"no-speech"!==t&&"aborted"!==t&&(p(t),h.current?.(t),tL.has(t)&&(g.current=!1,o(!1)))},y.current=s;try{s.start(),o(!0)}catch(e){console.warn("[voice] start failed:",e),y.current||(o(!1),g.current=!1)}},[]),L=(0,r.useCallback)((e="")=>{"ai"===R?P(e):!k&&tB()&&(j.current=e?e.replace(/\s*$/,"")+" ":"",p(null),g.current=!0,D())},[k,R,P,D]),B=(0,r.useCallback)((e="")=>{i?I():L(e)},[i,L,I]);return(0,r.useEffect)(()=>()=>{g.current=!1;try{y.current?.abort()}catch{}let e=w.current;if(e){w.current=null,clearInterval(e.timer);try{"inactive"!==e.rec.state&&e.rec.stop()}catch{}e.stream.getTracks().forEach(e=>e.stop());try{e.ctx.close()}catch{}}},[]),{supported:$,active:a&&$,listening:i,transcribing:c,volume:u,error:m,start:L,stop:I,cancel:A,toggle:B}}let tK="(pointer: fine) and (hover: hover)";function tO(){let[e,t]=(0,r.useState)(()=>window.matchMedia(tK).matches?"mouse":"touch");return(0,r.useEffect)(()=>{let e=window.matchMedia(tK),s=()=>{t(e.matches?"mouse":"touch")};return s(),e.addEventListener?e.addEventListener("change",s):e.addListener(s),()=>{e.removeEventListener?e.removeEventListener("change",s):e.removeListener(s)}},[]),e}function tW(e,t){let[s,n]=(0,r.useState)(t),l=(0,r.useRef)(!0),a=(0,r.useRef)(e);(0,r.useEffect)(()=>{a.current!==e&&(a.current=e,l.current=!0);try{let t=window.localStorage.getItem(e);null!==t&&n(JSON.parse(t))}catch(t){console.warn(`usePersistedState: failed to read "${e}"`,t)}},[e]),(0,r.useEffect)(()=>{if(l.current){l.current=!1;return}try{window.localStorage.setItem(e,JSON.stringify(s))}catch(t){console.warn(`usePersistedState: failed to write "${e}"`,t)}},[e,s]);let i=(0,r.useCallback)(()=>n(t),[t]);return[s,n,i]}function t_(e,t,s,n="flat",l=[]){let[a,i,o]=tW(e,s),c=(0,r.useMemo)(()=>new Map(t.map(e=>[e.id,e])),[t]),d="grid"===n?a?.flat?.():a,u=(e,t)=>Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,s)=>e===t[s]),x=d&&l.some(e=>"grid"===n?u(e.flat(),d):u(e,d)),m=x?s:a,p=(0,r.useCallback)(e=>e.map(e=>c.get(e)).filter(Boolean),[c]),f="grid"===n&&Array.isArray(s)?s.length:1,h=(0,r.useMemo)(()=>"grid"===n?Array.isArray(m)&&m.length===f&&m.every(Array.isArray)?m:s:[Array.isArray(m)?m:[]],[m,n,s,f]),b=(0,r.useMemo)(()=>p(h.flat()),[h,p]),g=(0,r.useMemo)(()=>{let e=new Set(b.map(e=>e.id));return t.filter(t=>!e.has(t.id))},[b,t]),v=(0,r.useCallback)(e=>"grid"===n?m[e]||[]:m,[m,n]);(0,r.useEffect)(()=>{x&&i(s)},[x,s,i]);let y=(0,r.useCallback)(e=>{i(t=>"grid"===n?e(Array.isArray(t)&&t.length===f&&t.every(Array.isArray)?t.map(e=>[...e]):s.map(e=>[...e])):e([[...Array.isArray(t)?t:[]]])[0])},[i,n,s,f]),w=(0,r.useCallback)((e,t=0)=>{y(s=>(s[t]||(s[t]=[]),s.flat().includes(e)||(s[t]=[...s[t],e]),s))},[y]),j=(0,r.useCallback)((e,t)=>{y(s=>(s[e]&&(s[e]=s[e].filter((e,s)=>s!==t)),s))},[y]);return{mode:n,rows:h,keys:b,available:g,getRow:v,add:w,removeAt:j,replaceAt:(0,r.useCallback)((e,t,s)=>{y(n=>{if(n[e]||(n[e]=[]),n.flat().indexOf(s)>=0)for(let e of n){let t=e.indexOf(s);t>=0&&e.splice(t,1)}return t>=n[e].length?n[e].push(s):n[e][t]=s,n})},[y]),swap:(0,r.useCallback)((e,t)=>{y(s=>{let n=s[e.row],r=s[t.row];if(!n||!r)return s;let l=n[e.col];return n[e.col]=r[t.col],r[t.col]=l,s})},[y]),reset:o}}let tH="min-w-[38px] h-9 px-2 flex items-center justify-center rounded-brand text-xs font-semibold select-none shrink-0 whitespace-nowrap transition-all duration-150 ease-out active:scale-[0.96]",tU="bg-brand-500 text-white";function tq({label:e,selected:t,onClick:s}){return(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),s()},className:`${tH} ${t?tU:"bg-surface-2 hover:bg-surface-3 text-text"}`,children:e})}function tX({selected:e,onClick:t}){return(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),t()},className:`${tH} ${e?tU:"border border-dashed border-border text-text-subtle hover:text-text hover:bg-surface-2"}`,title:"Select this slot, then pick a key below",children:(0,n.jsx)(el.FW,{size:16})})}function tV({isOpen:e,onClose:t,title:s="Customize Keys",tabs:l}){let[a,i]=(0,r.useState)(l?.[0]?.id),[o,c]=(0,r.useState)(null);if((0,r.useEffect)(()=>{e&&c(null)},[e]),(0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&t()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,t]),(0,r.useEffect)(()=>{c(null)},[a]),!e)return null;let d=l.find(e=>e.id===a)||l[0],{rows:u,available:x,replaceAt:m,swap:p,removeAt:f,reset:h}=d.hook,b=d.excludeIds||[],g=u.map(e=>e.map((e,t)=>({id:e,rawCol:t})).filter(e=>!b.includes(e.id))),v=g.map(e=>e.map(e=>e.id)),y=b.length?x.filter(e=>!b.includes(e.id)):x,w=(e,t)=>{let s=g[e]||[];return t>=s.length?(u[e]||[]).length:s[t].rawCol},j=(e,t)=>o&&o.row===e&&o.col===t,k=(e,t,s)=>{if(!s&&j(e,t))return void c(null);if(o&&!s&&!(o.col>=v[o.row].length)){p({row:o.row,col:w(o.row,o.col)},{row:e,col:w(e,t)}),c(null);return}c({row:e,col:t})},N=new Map;d.hook.keys?.forEach(e=>N.set(e.id,e)),y.forEach(e=>N.set(e.id,e));let C=o&&v[o.row]&&o.col<v[o.row].length;return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px]",onClick:t}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-2xl max-h-[85dvh] flex flex-col",children:[(0,n.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between",children:[(0,n.jsx)("h3",{className:"text-base font-semibold text-text",children:s}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),t()},className:"text-text-muted hover:text-text",children:(0,n.jsx)(el.X,{size:18})})]}),l.length>1&&(0,n.jsx)("div",{className:"px-5 pt-1 flex gap-2 border-b border-border-subtle",children:l.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),i(e.id)},className:`px-3 py-2 -mb-px text-xs font-semibold border-b-2 transition-colors duration-150 ${a===e.id?"text-brand-400 border-brand-500":"text-text-muted border-transparent hover:text-text"}`,children:e.label},e.id))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-5 space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("div",{className:"text-xs text-text-muted",children:o?"Click another to swap, or Remove below":"Click to select"}),C&&(0,n.jsxs)("button",{onClick:()=>{if(!o)return;let e=v[o.row]||[];o.col<e.length&&f(o.row,w(o.row,o.col)),c(null)},className:"flex items-center gap-1 px-2 py-1 text-xs text-red-400 hover:text-red-300",children:[(0,n.jsx)(el.TB,{size:14})," Remove"]})]}),(0,n.jsx)("div",{className:"space-y-1.5 p-2 rounded-brand bg-surface-2",children:v.map((e,t)=>(0,n.jsxs)("div",{className:"modal-scrollable flex items-center gap-1.5 overflow-x-auto pb-1",children:[e.map((e,s)=>{let r=N.get(e);return(0,n.jsx)(tq,{label:r?.label||e,selected:j(t,s),onClick:()=>k(t,s,!1)},e+s)}),(0,n.jsx)(tX,{selected:j(t,e.length),onClick:()=>k(t,e.length,!0)})]},t))})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"text-xs text-text-muted mb-2",children:["Available — click to ",o?C?"replace selected":"add to slot":"add"]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-1.5 p-2 rounded-brand bg-surface-2",children:[0===y.length&&(0,n.jsx)("div",{className:"text-xs text-text-muted italic",children:"All keys added."}),y.map(e=>(0,n.jsx)(tq,{label:e.label,onClick:()=>(e=>{if(o)m(o.row,w(o.row,o.col),e);else{let t=v.length>0?v.length-1:0;m(t,(u[t]||[]).length,e)}c(null)})(e.id)},e.id))]})]})]}),(0,n.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),h(),c(null)},className:"px-3 py-1.5 text-xs text-text-muted hover:text-text transition-colors",children:"↺ Reset to default"}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),t()},className:"px-4 py-1.5 bg-brand-500 hover:bg-brand-600 text-white text-sm font-semibold rounded-brand transition-all duration-150 ease-out active:scale-[0.97]",children:"Done"})]})]})]})}function tJ({bus:e,sessionId:t}){let{t:s}=(0,eu.s)(),[n,l]=(0,r.useState)([]),a=(0,r.useRef)(0),i=(0,r.useCallback)(e=>new Promise(t=>{if(e.size>eJ.Tb)return alert(s("mobileKeyboard.fileTooLarge")),t(null);let n=new FileReader;n.onload=()=>{let s=n.result.split(",")[1],r=e.type.startsWith("image/"),l=e.name||`paste_${a.current}.${r?e.type.split("/")[1]||"png":"bin"}`;t({id:++a.current,name:l,type:e.type,size:e.size,content:s,isImage:r})},n.onerror=()=>{alert(s("mobileKeyboard.readFileFailed")),t(null)},n.readAsDataURL(e)}),[s]),o=(0,r.useCallback)(async e=>{let t=eJ.qQ-n.length;if(t<=0)return;let s=Array.from(e).slice(0,t),r=(await Promise.all(s.map(i))).filter(Boolean);r.length&&((0,ed.e)(),l(e=>[...e,...r]))},[n.length,i]),c=(0,r.useCallback)(e=>{l(t=>t.filter(t=>t.id!==e))},[]),d=(0,r.useCallback)(s=>new Promise(n=>{let r=!1,l=()=>{r||(r=!0,n())};e?.emit("clipboard-attach",{sessionId:t,filename:s.name,type:s.type,content:s.content},l),setTimeout(l,eJ.ll)}),[e,t]),u=(0,r.useCallback)(async e=>{(0,ed.e)();let t=e.target.files;t?.length&&await o(t),e.target.value=""},[o]),x=(0,r.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let s=[];for(let e of t)if("file"===e.kind){let t=e.getAsFile();t&&s.push(t)}s.length&&(e.preventDefault(),o(s))},[o]);return{attachments:n,setAttachments:l,addFiles:o,removeAttachment:c,sendOneAttachment:d,handleFileUpload:u,handleAttachPaste:x}}let tG={ArrowUp:"\x1b[A",ArrowDown:"\x1b[B",ArrowRight:"\x1b[C",ArrowLeft:"\x1b[D",Escape:"\x1b",Tab:" ",Enter:"\r",Backspace:"",Delete:"\x1b[3~",Home:"\x1b[H",End:"\x1b[F",PageUp:"\x1b[5~",PageDown:"\x1b[6~",Insert:"\x1b[2~",F1:"\x1bOP",F2:"\x1bOQ",F3:"\x1bOR",F4:"\x1bOS",F5:"\x1b[15~",F6:"\x1b[17~",F7:"\x1b[18~",F8:"\x1b[19~",F9:"\x1b[20~",F10:"\x1b[21~",F11:"\x1b[23~",F12:"\x1b[24~"},tY={ArrowUp:"\x1b[1;5A",ArrowDown:"\x1b[1;5B",ArrowRight:"\x1b[1;5C",ArrowLeft:"\x1b[1;5D"},tZ={ArrowUp:"\x1b[1;2A",ArrowDown:"\x1b[1;2B",ArrowRight:"\x1b[1;2C",ArrowLeft:"\x1b[1;2D"},tQ={"[":"\x1b","]":"\x1d","\\":"\x1c","@":"\0","?":""};var t0=s(70362),t1=s(50068);function t2({items:e,onSelect:t,activeIndex:s=-1}){let l=(0,r.useRef)(null);return((0,r.useEffect)(()=>{let e=l.current;if(!e||s<0)return;let t=e.children[s];t&&t.scrollIntoView({block:"nearest"})},[s]),e?.length)?(0,n.jsx)("div",{className:"absolute bottom-full left-0 right-0 mb-1 z-40 rounded-brand overflow-hidden bg-surface/95 backdrop-blur-xl shadow-xl ring-1 ring-border touch-none",children:(0,n.jsx)("div",{ref:l,className:"flex flex-col max-h-[25dvh] overflow-y-auto modal-scrollable",children:e.map((e,r)=>(0,n.jsxs)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),t(e.full)},className:`flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-2 transition-colors touch-none ${r===s?"bg-brand-500/15":""}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:"folder"===e.type?(0,n.jsx)(t0.A,{size:13,className:"text-brand-500",fill:"currentColor"}):(0,n.jsx)(t1.A,{size:13,className:"text-text-muted"})}),(0,n.jsx)("span",{className:"min-w-0 text-xs text-text font-mono",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl",unicodeBidi:"plaintext"},title:e.full,children:e.label})]},`${e.type}-${e.name}`))})}):null}let t5=[.3,.6,.85,1,.75,.9,1,.65,.35],t3=[.4,.8,1,.7,.9,.5,.85,.35];function t4({code:e,className:t="",t:s}){let[l,a]=(0,r.useState)(!1);return((0,r.useEffect)(()=>{let e=setTimeout(()=>a(!0),5e3);return()=>clearTimeout(e)},[]),l)?null:(0,n.jsxs)("div",{className:`w-fit mx-auto flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-red-500/10 border border-red-500/30 shadow-md text-xs text-red-400 animate-in fade-in slide-in-from-bottom-1 duration-150 pointer-events-none ${t}`,children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-red-500 shrink-0"}),["not-allowed","service-not-allowed","audio-capture"].includes(e)?s("voice.denied"):"network"===e?s("voice.network"):"mic-timeout"===e?s("voice.micTimeout"):String(e)]})}let t6=(0,r.memo)(function({voice:e,onDone:t,onCancel:s,className:r=""}){let{t:l}=(0,eu.s)(),a=!e?.listening&&e?.error?e.error:null;return e?.listening?(0,n.jsx)("div",{className:`w-fit mx-auto flex items-center gap-2 px-2.5 py-1 rounded-full bg-surface-2/95 border border-border-subtle shadow-md backdrop-blur-md text-xs animate-in fade-in slide-in-from-bottom-1 duration-150 pointer-events-auto ${r}`,children:e.transcribing?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-1 py-0.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand-500 animate-ping shrink-0"}),(0,n.jsx)("div",{className:"flex items-center gap-[3px] h-3.5",children:t3.map((e,t)=>(0,n.jsx)("span",{className:"w-[2.5px] rounded-full bg-brand-500/85 animate-pulse transition-all",style:{height:`${Math.round(13*e)}px`,animationDelay:`${100*t}ms`,animationDuration:"800ms"}},t))})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>{s?s():e.cancel()},className:"text-text-muted hover:text-text p-1 rounded-full hover:bg-surface-3 transition-colors cursor-pointer shrink-0",title:"Cancel","aria-label":"Cancel",children:(0,n.jsx)(el.X,{size:12})}),(0,n.jsx)("div",{className:"h-3 w-px bg-border-subtle shrink-0"}),(0,n.jsxs)("span",{className:"relative flex h-2 w-2 shrink-0",children:[(0,n.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-red-400 opacity-75"}),(0,n.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-red-500"})]}),(0,n.jsx)("div",{className:"flex items-center gap-[2.5px] h-3.5 shrink-0 px-0.5",children:t5.map((t,s)=>{let r=Math.max(3,Math.round(3+t*(e.volume||.1)*11));return(0,n.jsx)("span",{className:"w-[2px] rounded-full bg-brand-500 transition-all duration-75",style:{height:`${r}px`}},s)})}),(0,n.jsx)("div",{className:"h-3 w-px bg-border-subtle shrink-0"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),t?t():e.stop()},className:"p-1 rounded-full bg-brand-500 hover:bg-brand-600 text-white transition-colors cursor-pointer shadow-xs flex items-center justify-center shrink-0",title:"Done","aria-label":"Done",children:(0,n.jsx)(el.aJ,{size:11})})]})}):a?(0,n.jsx)(t4,{code:a,className:r,t:l},a):null}),t8=RegExp(`^\\s*(${eJ.RF.verbs.join("|")})\\s+(\\S*)$`,"i"),t9=r.memo(({bus:e,sessionId:t,onExpandChange:s,onRefocus:l,onRegisterTextApi:a,platform:i,onInput:o,onSwitchSession:c,onSwitchToIndex:d,onInputFocusChange:u,statusStrip:x=null,isDesktop:m=!1})=>{let p,{t:f,locale:b}=(0,eu.s)(),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=()=>w(window.innerHeight-e.height>150);return e.addEventListener("resize",t),t(),()=>e.removeEventListener("resize",t)},[]);let j=(0,h.B)(e=>e.drafts[t]??""),k=(0,h.B)(e=>e.setDraft),N=(0,r.useCallback)(e=>{k(t,"function"==typeof e?e(h.B.getState().drafts[t]??""):e)},[k,t]),[C,S]=(0,r.useState)(!1),[T,R]=(0,r.useState)(!1),[E,$]=(0,r.useState)(!1),[z,M]=(0,r.useState)(!1),P=tk(e=>e.addCommand),A=tk(e=>e.resolveAlias),I=tk(e=>e.history),D=tk(e=>e.pinned),L=(0,r.useRef)(null),B=(0,r.useRef)(null),F=(0,r.useRef)(!1),K=(0,r.useRef)(-1);(0,r.useRef)("");let O=(0,h.B)(e=>e.cwdBySession[t]),[W,_]=(0,r.useState)([]),[H,U]=(0,r.useState)(-1),[q,X]=(0,r.useState)(-1),V=(0,r.useMemo)(()=>W.length>0?[]:tz(j,I,D,eJ.dt,C),[j,I,D,C,W]),J=(e,t)=>e<0||!t?-1:(e%t+t)%t,G=J(H,W.length),Y=J(q,V.length),Z=(0,r.useRef)(null);null==Z.current&&(Z.current=function({ttlMs:e,maxDirs:t}=eJ.RF){let s=new Map;return{get(e,t){let n=s.get(e);return n?n.expireAt<t?(s.delete(e),null):(s.delete(e),s.set(e,s.get(e)),n.entries):null},set(n,r,l){s.size>=t&&!s.has(n)&&s.delete(s.keys().next().value),s.set(n,{entries:r,expireAt:l+e})},clear(){s.clear()}}}());let Q=(0,r.useRef)(e);(0,r.useEffect)(()=>{Q.current=e},[e]);let ee=er(Q),{attachments:et,setAttachments:es,addFiles:en,removeAttachment:ea,sendOneAttachment:ei,handleFileUpload:eo,handleAttachPaste:ec}=tJ({bus:e,sessionId:t}),[ex]=tD(b),em=tF({lang:tA(ex),onText:e=>{N(e);let t=L.current;t&&requestAnimationFrame(()=>{try{t.selectionStart=t.selectionEnd=t.value.length}catch{}t.scrollTop=t.scrollHeight})}}),ep="mouse"===tO();(0,r.useEffect)(()=>{let e=L.current;if(!e)return;e.style.height="auto";let t=ep?eJ.hp:eJ.bs;e.style.height=`${Math.min(e.scrollHeight,t)}px`},[j,ep]);let ef=(0,r.useRef)(0);(0,r.useEffect)(()=>{let e=function(e,t){var s,n;let r=t8.exec(e);if(!r)return null;let l=r[1],a=r[2]||"",i=a.lastIndexOf("/");if(i<0)return{verb:l,dir:t||"",prefix:a,partial:a};let o=a.slice(0,i);return o?{verb:l,dir:(s=t,(n=o)?n.startsWith("/")||n.startsWith("~")||!s?n:s.replace(/\/+$/,"")+"/"+n:s||""),prefix:a.slice(i+1),partial:a}:{verb:l,dir:a.startsWith("~")?"~":"/",prefix:a.slice(i+1),partial:a}}(j,O),t=++ef.current,s=setTimeout(async()=>{if(t!==ef.current)return;if(!e)return void _([]);let s=Date.now(),n=Z.current.get(e.dir,s);if(null==n){let r=await ee.getFiles(e.dir,!1);if(t!==ef.current)return;if(!r?.success)return void _([]);n=r.files,Z.current.set(e.dir,n,s)}_(function(e,t,{partial:s,verb:n}={}){if(!e?.length)return[];let r=t.toLowerCase(),l=s&&s.includes("/")?s.slice(0,s.lastIndexOf("/")+1):"";return e.filter(e=>e.name.toLowerCase().startsWith(r)).map(e=>({name:e.name,type:e.type,arg:l+e.name+("folder"===e.type?"/":""),label:e.name+("folder"===e.type?"/":""),full:`${n} ${l}${e.name}${"folder"===e.type?"/":""}`})).sort((e,t)=>{let s=+("folder"!==e.type),n=+("folder"!==t.type);return s!==n?s-n:e.name.localeCompare(t.name)}).slice(0,eJ.RF.maxResults||8)}(n,e.prefix,e))},eJ.RF.debounceMs);return()=>clearTimeout(s)},[j,O,ee]),(0,r.useEffect)(()=>{let e=setTimeout(()=>{Z.current?.clear(),_([])},0);return()=>clearTimeout(e)},[t]);let[eh,eb]=(0,r.useState)(!1),[eg,ev]=(0,r.useState)(!1),[ey,ew]=(0,r.useState)(!1),[ej,ek]=(0,r.useState)(!1),eN=t_("terminal.basicKeys",eJ.y,eJ.cK,"flat",[["esc","up","down","ctrlC","ctrl","opt","shift","tab"]]),eC=t_("terminal.extraKeys",eJ.y,eJ.Mg,"grid"),eS=(0,r.useCallback)((e,t={})=>(function(e,{ctrl:t=!1,alt:s=!1,shift:n=!1}={}){if(t&&1===e.length){let t=e.toUpperCase().charCodeAt(0);return t>=65&&t<=90?String.fromCharCode(t-64):tQ[e]??e}return s?tG[e]?"\x1b"+tG[e]:1===e.length?"\x1b"+e:tG[e]||e:t&&tG[e]?e.startsWith("Arrow")?tY[e]||tG[e]:"Home"===e?"\x1b[1;5H":"End"===e?"\x1b[1;5F":tG[e]:n&&tG[e]?"Tab"===e?"\x1b[Z":e.startsWith("Arrow")&&tZ[e]||tG[e]:n&&1===e.length?e.toUpperCase():tG[e]||e})(e,{ctrl:t.ctrl||eh,alt:t.alt||ey,shift:t.shift||ej}),[eh,ey,ej]);(0,r.useEffect)(()=>{let e=()=>{S(window.innerWidth<768||"ontouchstart"in window||navigator.maxTouchPoints>0)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>{s&&s(!0)},[ep]),(0,r.useEffect)(()=>{if(a)return a({openTextPanel:()=>{setTimeout(()=>L.current?.focus(),100)},focus:()=>{L.current?.focus({preventScroll:!0})}}),()=>a(null)},[a]);let eT=(0,r.useCallback)(()=>{R(!0),setTimeout(()=>B.current?.focus(),100)},[]);if((0,r.useEffect)(()=>{if(!C||!e||!t||!(eh||eg||ey||ej))return;let s=async s=>{if(!eh&&!eg&&!ey&&!ej||["Control","Alt","Shift","Meta"].includes(s.key))return;s.preventDefault(),s.stopPropagation();let n=s.key;if((eh||eg)&&"v"===n.toLowerCase()){eT(),eb(!1),ev(!1),ew(!1),ek(!1);return}"Backspace"===n?n="Backspace":"Enter"===n?n="Enter":"Tab"===n?n="Tab":"Escape"===n?n="Escape":"Delete"===n?n="Delete":n.startsWith("Arrow")?n=s.key:n.startsWith("F")&&n.length<=3&&(n=s.key);let r=eS(n,{ctrl:eh,alt:ey,shift:ej,meta:eg});o?.(t),e.emit("input",{sessionId:t,data:r}),eb(!1),ev(!1),ew(!1),ek(!1)};return document.addEventListener("keydown",s,!0),()=>document.removeEventListener("keydown",s,!0)},[C,e,t,eh,eg,ey,ej,eS,eT]),!C&&!ep||!e||!t)return null;let eR=async(s,n={})=>{(0,ed.e)();let r=n.ctrl||eh,l=n.meta||eg;if((r||l)&&"v"===s.toLowerCase()){eT(),eb(!1),ev(!1),ew(!1),ek(!1);return}let a=eS(s,n);o?.(t),e.emit("input",{sessionId:t,data:a}),"Ctrl"!==s&&"Meta"!==s&&"Alt"!==s&&"Shift"!==s&&(eb(!1),ev(!1),ew(!1),ek(!1))},eE=async()=>{if(F.current)return;if(F.current=!0,(0,ed.e)(15),em.listening&&em.stop(),!e||!t){F.current=!1;return}let s=document.activeElement===L.current;s&&L.current?.blur();let n=L.current?.value??j;L.current&&(L.current.value=""),N(""),K.current=-1;let r=A(n);for(let e of(o?.(t),et.length&&es([]),et))await ei(e),await new Promise(e=>setTimeout(e,eJ.am));""===r?et.length||e.emit("input",{sessionId:t,data:"\r"}):(e.emit("input",{sessionId:t,data:r}),setTimeout(()=>e.emit("input",{sessionId:t,data:"\r"}),eJ.YS),P(r)),s&&L.current?.focus(),setTimeout(()=>{F.current=!1},150)},e$=eJ._C.base,ez=`${e$} ${eJ._C.normal}`,eM=`${e$} ${eJ._C.arrow}`,eP=(e,t,s=!1,r=!1)=>{let l,a="modifier"===e.type&&("ctrl"===(l=e.id)&&eh||"meta"===l&&eg||"opt"===l&&ey||"shift"===l&&ej)?`${e$} ${eJ._C.modifierActive}`:r?`${e$} ${eJ._C.pinned}`:"arrow"===e.type?eM:ez,i="ctrl"===e.type?"text-brand-400":"",o=e.label.length>1?eJ._C.textSmall:eJ._C.textNormal,c=s?eJ._C.sizeLarge:eJ._C.size;return(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{if("modifier"===e.type){var t;t=e.key,(0,ed.e)(),"Ctrl"===t?eb(!eh):"Meta"===t?ev(!eg):"Alt"===t||"Opt"===t?ew(!ey):"Shift"===t&&ek(!ej)}else"ctrl"===e.type?eR(e.key,{ctrl:!0}):eR(e.key)},className:`${a} ${i} ${o} whitespace-nowrap`,style:c,children:e.label},e.id+t)},eA=!!x&&!g&&!y&&!ep;return(0,n.jsxs)("div",{className:"flex flex-col w-full",children:[T&&(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-[2px] flex items-center justify-center z-[60]",onClick:()=>R(!1),children:(0,n.jsx)("input",{ref:B,placeholder:f("mobileKeyboard.pasteHere"),onPaste:s=>{s.preventDefault();let n=s.clipboardData?.getData("text");n&&e&&(o?.(t),e.emit("input",{sessionId:t,data:n}),(0,ed.e)()),R(!1)},onClick:e=>e.stopPropagation(),className:"px-6 py-3 bg-surface-2 text-text rounded-brand focus:ring-2 focus:ring-brand-500/40 font-medium transition-all duration-150 ease-out outline-none text-center w-64"})}),(0,n.jsx)("div",{className:`transition-all duration-300 overflow-hidden bg-bg ${g&&!ep?"max-h-64 opacity-100":"max-h-0 opacity-0"}`,children:(0,n.jsx)("div",{className:"p-2 max-w-2xl mx-auto",children:(0,n.jsx)("div",{className:"space-y-1",children:eC.rows.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0 flex gap-1.5 overflow-x-auto scroll-thin-x pr-3 rounded-lg",children:e.map((e,s)=>{let n=eJ.y.find(t=>t.id===e);return n?eP(n,100*t+s,!0):null})}),0===t&&(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),$(!0)},className:"shrink-0 h-8 w-8 flex items-center justify-center text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-all duration-150 ease-out",title:f("remote.customizeKeys"),children:(0,n.jsx)(el.wB,{size:16})})]},t))})})}),eA&&x,(0,n.jsxs)("div",{className:"relative transition-all duration-300 overflow-visible opacity-100 flex-shrink-0",children:[(0,n.jsx)(t6,{voice:em,className:`absolute left-1/2 -translate-x-1/2 z-30 ${eA?"bottom-[calc(100%+36px)]":"bottom-[calc(100%+18px)]"}`}),(0,n.jsxs)("div",{className:m?"flex w-full items-stretch":`${eA?"pt-0.5":"pt-2"} px-2 pb-2 flex gap-2 items-end`,children:[(0,n.jsxs)("div",{className:`relative flex-1 bg-surface-2 transition-all duration-150 ease-out input-focus-glow border-border-subtle ${m?"rounded-none border-0 border-r":"rounded-xl border"}`,children:[(0,n.jsx)(t2,{items:W,activeIndex:G,onSelect:e=>{N(e),L.current?.focus()}}),(0,n.jsx)(tM,{value:j,store:tk,commonCommands:eJ.dt,isMobile:C,disabled:W.length>0,activeIndex:Y,onSelect:e=>{N(e),L.current?.focus()}}),et.length>0&&(0,n.jsx)("div",{className:"flex gap-2 px-2 pt-2 overflow-x-auto scroll-thin-x",children:et.map(e=>(0,n.jsxs)("div",{className:"relative flex-shrink-0 group",children:[e.isImage?(0,n.jsx)("img",{src:`data:${e.type};base64,${e.content}`,alt:e.name,className:"w-10 h-10 object-cover rounded border border-border"}):(0,n.jsxs)("div",{className:"w-10 h-10 flex flex-col items-center justify-center rounded border border-border bg-surface-3 px-1",children:[(0,n.jsx)(el.xv,{size:14,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-[9px] text-text-muted truncate w-full text-center",children:e.name})]}),(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>ea(e.id),className:"absolute -top-1.5 -right-1.5 w-4 h-4 flex items-center justify-center bg-surface-3 rounded-full text-text-muted hover:text-text border border-border",children:(0,n.jsx)(el.X,{size:10})})]},e.id))}),(0,n.jsxs)("label",{className:"absolute left-1.5 top-1/2 -translate-y-1/2 w-6 h-6 flex items-center justify-center cursor-pointer text-orange-500/70 hover:text-orange-500 transition-colors touch-none",children:[(0,n.jsx)(el.xv,{size:16}),(0,n.jsx)("input",{type:"file",multiple:!0,onChange:eo,className:"hidden",accept:"*/*"})]}),(0,n.jsx)("textarea",{ref:L,value:j,onChange:e=>{N(e.target.value),K.current=-1},onFocus:e=>{let t=e.target.value.length;e.target.selectionStart=e.target.selectionEnd=t,u?.(!0)},onBlur:()=>u?.(!1),onPaste:ec,onKeyDown:s=>{if(ep&&"Tab"===s.key){if(!s.ctrlKey&&!s.altKey&&!s.metaKey){if(W.length>0){s.preventDefault();let e=s.shiftKey?-1:1;U(t=>W.length?((t+e)%W.length+W.length)%W.length:-1);return}if(V.length>0){s.preventDefault();let e=s.shiftKey?-1:1;X(t=>V.length?((t+e)%V.length+V.length)%V.length:-1);return}}s.preventDefault();let n=eS("Tab",{ctrl:s.ctrlKey,alt:s.altKey,shift:s.shiftKey,meta:s.metaKey});o?.(t),e.emit("input",{sessionId:t,data:n});return}let n=/^Digit([1-9])$/.exec(s.code)||/^[1-9]$/.exec(s.key);if(ep&&(tc()?s.altKey&&!s.ctrlKey&&!s.metaKey:s.ctrlKey||s.metaKey)&&n){s.preventDefault(),d?.(Number(n[1])-1);return}if(ep&&"Enter"===s.key&&!s.shiftKey){if(s.nativeEvent?.isComposing||s.isComposing||229===s.keyCode)return;if(W.length>0&&G>=0){s.preventDefault(),N(W[G].full),U(-1),L.current?.focus();return}if(V.length>0&&Y>=0){s.preventDefault(),N(V[Y].cmd),X(-1),L.current?.focus();return}s.preventDefault(),eE();return}if(ep&&("ArrowUp"===s.key||"ArrowDown"===s.key)&&!s.shiftKey&&!s.ctrlKey&&!s.metaKey&&!s.altKey&&!j){s.preventDefault(),o?.(t),e.emit("input",{sessionId:t,data:"ArrowUp"===s.key?"\x1b[A":"\x1b[B"});return}let r=eJ.EE[s.key];if(r&&(!r.ctrl||s.ctrlKey)&&!s.metaKey&&!s.altKey){let n=s.target;if(r.requireNoSelection&&n.selectionStart!==n.selectionEnd)return;s.preventDefault(),o?.(t),e.emit("input",{sessionId:t,data:r.data})}},placeholder:ep?tc()?"Opt ←/→ \xb7 Opt 1…9 to switch tab":"Ctrl+Shift+←/→ \xb7 1…9 to switch tab":f("mobileKeyboard.typeCommand"),rows:1,className:"block w-full pl-9 pr-16 py-2 bg-transparent text-text text-sm placeholder-text-muted placeholder:text-[11px] placeholder:leading-[20px] focus:outline-none resize-none overflow-y-auto touch-none"}),j?(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{N(""),L.current?.focus()},title:f("voice.clear"),className:"absolute right-10 top-1/2 -translate-y-1/2 w-5 h-5 flex items-center justify-center text-text-muted hover:text-text transition-colors touch-none",children:(0,n.jsx)(el.X,{size:14})}):(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>M(!0),title:f("history.title"),className:"absolute right-10 top-1/2 -translate-y-1/2 w-5 h-5 flex items-center justify-center text-text-muted hover:text-text transition-colors touch-none",children:(0,n.jsx)(el.BZ,{size:14})}),em.active&&(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{em.listening?em.stop():(document.activeElement?.blur(),em.start(j))},title:"not-allowed"===em.error||"service-not-allowed"===em.error?f("voice.denied"):f("voice.dictate"),className:`absolute right-1.5 top-1/2 -translate-y-1/2 w-7 h-7 flex items-center justify-center rounded-full transition-all duration-200 touch-none ${em.listening?"bg-red-500/90 text-white animate-pulse":em.error?"text-red-400":"text-text-muted hover:text-text"}`,children:em.listening?(0,n.jsx)(el.jj,{size:16}):(0,n.jsx)(el.GO,{size:16})})]}),(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:eE,disabled:!1,className:m?"px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-medium rounded-none transition-colors flex-shrink-0 flex items-center justify-center select-none":"px-3 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-medium rounded-xl transition-all duration-200 shadow-lg shadow-brand-500/20 flex-shrink-0 min-w-[56px] flex items-center justify-center",children:j.trim()||et.length?f("mobileKeyboard.send"):(0,n.jsx)(el.Lt,{size:16,strokeWidth:2.5})})]})]}),!ep&&(0,n.jsx)("div",{className:"overflow-x-auto overflow-y-hidden touch-pan-x px-1.5 pb-1.5 safe-area-bottom bg-bg",children:(0,n.jsxs)("div",{className:"flex items-center gap-1 max-w-4xl mx-auto",children:[(0,n.jsx)("div",{className:"flex gap-1 flex-1 overflow-x-auto scroll-thin-x touch-pan-x pr-2 rounded-lg",children:eN.keys.filter(e=>e.id!==eJ.g$).map((e,t)=>eP(e,t))}),(p=eJ.y.find(e=>e.id===eJ.g$))?(0,n.jsx)("div",{className:"flex-shrink-0",children:eP(p,"pinned",!1,!0)}):null,(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)();let e=!g;v(e),e&&document.activeElement?.blur(),s&&setTimeout(()=>s(e),320)},className:`${e$} ${g?eJ._C.modifierActive:eJ._C.pinned} flex-shrink-0`,style:eJ._C.size,title:f("mobileKeyboard.toggleExtraKeys"),children:g?(0,n.jsx)(el.X,{size:16}):(0,n.jsx)(el.a4,{size:16})})]})}),(0,n.jsx)(tV,{isOpen:E,onClose:()=>$(!1),title:f("mobileKeyboard.customizeTerminalKeys"),tabs:[{id:"basic",label:f("mobileKeyboard.mainBar"),hook:eN,excludeIds:[eJ.g$]},{id:"extra",label:f("mobileKeyboard.extraPanel"),hook:eC}]}),(0,n.jsx)(tT,{isOpen:z,onSelect:e=>{N(e),L.current?.focus()},onClose:()=>M(!1)})]})}),t7={idle:{dot:"#22c55e",cls:"st-idle",label:"common.statusIdle"},working:{dot:"#3b82f6",cls:"st-working",pulse:"soft",glow:"rgba(59,130,246,0.30)",label:"common.statusWorking"},blocked:{dot:"#ef4444",cls:"st-blocked",pulse:"strong",glow:"rgba(239,68,68,0.32)",label:"common.statusBlocked"},done:{dot:"#f59e0b",cls:"st-done",glow:"rgba(245,158,11,0.22)",label:"common.statusDone"},sleep:{dot:"#94a3b8",cls:"st-sleep",label:"common.statusSleep"}},se=e=>t7[e]||t7.idle,st=e=>{let t=se(e);return`term-dot ${t.cls}${t.pulse?` pulse-${t.pulse}`:""}`},ss={claude:"Claude",codex:"Codex",opencode:"OpenCode",grok:"Grok",cursor:"Cursor",antigravity:"Antigravity",kiro:"Kiro",copilot:"Copilot",codebuddy:"CodeBuddy",factory:"Factory",qoder:"Qoder",rovodev:"Rovo Dev",hermes:"Hermes",amp:"Amp",pi:"Pi","qwen-code":"Qwen",droid:"Droid",crush:"Crush"},sn=new Proxy({},{get:(e,t)=>"string"==typeof t&&t&&e5(t)||void 0}),sr=tr.find(e=>"attentionNext"===e.id);function sl({sessions:e=[],allSessions:t=[],sessionStatus:s,onSwitchSession:l,workspaces:a=[]}){let{t:i}=(0,eu.s)(),[o,c]=(0,r.useState)(!1),d=(0,r.useRef)(null),u=eM(),x=s||u,m=eA(x,t).filter(e=>"blocked"===e.state||"done"===e.state),{total:p}=eI(x,t),f=s=>t.find(e=>e.id===s)?.name||e.find(e=>e.id===s)?.name||s.slice(0,8),h=e=>t.find(t=>t.id===e)?.workspaceId??null,b=new Map(t.map((e,t)=>[e.id,t])),g=(()=>{let e=new Map;for(let t of m){let s=h(t.id);e.has(s)||e.set(s,[]),e.get(s).push(t)}let t=e=>[...e].sort((e,t)=>(b.has(e.id)?b.get(e.id):Number.MAX_SAFE_INTEGER)-(b.has(t.id)?b.get(t.id):Number.MAX_SAFE_INTEGER)),s=[];for(let n of a){let r=e.get(n.id);r?.length&&s.push({id:n.id,name:n.name,items:t(r)})}let n=e.get(null);return n?.length&&s.push({id:null,name:i("workspaces.unassigned"),items:t(n)}),s})();(0,r.useEffect)(()=>{if(!o)return;let e=e=>{d.current&&!d.current.contains(e.target)&&c(!1)},t=e=>{"Escape"===e.key&&c(!1)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",t)}},[o]);let v=(0,r.useRef)(null),y=()=>{v.current&&(clearTimeout(v.current),v.current=null)};return(0,r.useEffect)(()=>()=>y(),[]),(0,n.jsxs)("div",{ref:d,className:"relative hidden sm:flex flex-shrink-0",onMouseEnter:()=>{y(),c(!0)},onMouseLeave:()=>{y(),v.current=setTimeout(()=>c(!1),150)},children:[(0,n.jsxs)("button",{onClick:()=>c(e=>!e),className:"relative p-1.5 text-text hover:bg-surface-2 hover:text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.94]",title:i("notifications.title"),children:[(0,n.jsx)(el.Ir,{size:16}),p>0&&(0,n.jsx)("span",{className:"absolute top-0 -right-1 min-w-[16px] h-4 px-1 rounded-full bg-brand-500 text-white text-[10px] font-bold flex items-center justify-center",children:p>9?"9+":p})]}),o&&(0,n.jsx)("div",{className:"absolute right-0 top-full pt-2 z-[70] flex flex-col",children:(0,n.jsxs)("div",{className:"bg-surface-2 border border-border-subtle rounded-brand-lg shadow-lg w-72 max-h-[60vh] overflow-y-auto flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-semibold",children:i("notifications.title")}),(0,n.jsx)("button",{onClick:()=>c(!1),className:"p-1 text-text-muted hover:text-text rounded transition-colors",title:i("common.close"),children:(0,n.jsx)(el.X,{size:14})})]}),m.length?(0,n.jsx)("div",{className:"flex flex-col",children:g.map(e=>(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 pt-2 pb-1 text-[11px] font-semibold uppercase tracking-wider text-text-muted flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-1 h-1 rounded-full bg-text-muted"}),(0,n.jsx)("span",{className:"truncate",title:e.name,children:e.name})]}),e.items.map(e=>{let t=se(e.state),s=i(t.label);return(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.id,void(c(!1),l?.(t))},className:"w-full flex items-center gap-2 px-3 py-1 hover:bg-surface-3 text-left transition-colors",title:f(e.id),children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 term-dot ${t.cls}${t.pulse?` pulse-${t.pulse}`:""}`,style:{background:t.dot}}),sn[e.tool]?(0,n.jsx)("img",{src:sn[e.tool],alt:e.tool,draggable:!1,className:`w-5 h-5 flex-shrink-0 ${e2}`}):(0,n.jsx)(el.BK,{size:18,className:"text-text-muted flex-shrink-0"}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)("span",{className:"text-sm font-medium truncate",title:f(e.id),children:f(e.id)}),(0,n.jsxs)("span",{className:"text-xs text-text-muted truncate",children:[ss[e.tool]||i("notifications.agent")," \xb7 ",s]})]}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted flex-shrink-0",children:(e=>{if(!e||!Number.isFinite(e))return"";let t=Math.max(0,Math.floor((Date.now()-e)/1e3));return t<60?"now":t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:`${Math.floor(t/86400)}d`})(e.since)})]},e.id)})]},e.id??"unassigned"))}):(0,n.jsx)("p",{className:"px-3 py-6 text-center text-sm text-text-muted",children:i("notifications.empty")}),(0,n.jsxs)("div",{className:"flex items-center gap-1 px-3 py-2 border-t border-border-subtle flex-shrink-0",children:[tm(sr).map(e=>(0,n.jsx)("kbd",{className:tu,children:e},e)),(0,n.jsx)("span",{className:"ml-1 text-[11px] text-text-muted",children:sr.label})]})]})})]})}function sa(e,t,s){let n=(0,r.useRef)(null);return(0,r.useCallback)(()=>{let r=t.filter(t=>{let s=e[t.id]?.state;return"blocked"===s||"done"===s});if(!r.length)return null;let l=r.findIndex(e=>e.id===n.current),a=r[(l+1)%r.length];return n.current=a.id,s?.(a.id),a.id},[e,t,s])}function si({sessionStatus:e,allSessions:t=[],onSwitchSession:s}){let{t:r}=(0,eu.s)(),l=eM(),a=e||l,{blocked:i,done:o,total:c}=eI(a,t),d=sa(a,t,s);if(!c)return null;let u=[{key:"blocked",count:i,state:"blocked"},{key:"done",count:o,state:"done"}].filter(e=>e.count>0);return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d()},className:"sm:hidden flex items-center gap-1.5 px-2 py-1.5 rounded-brand bg-surface-2 text-text transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0",title:r("notifications.badgeTitle",{blocked:i,done:o}),children:u.map(({key:e,count:t,state:s})=>{let r=se(s);return(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full term-dot ${r.cls}${r.pulse?` pulse-${r.pulse}`:""}`,style:{background:r.dot}}),(0,n.jsx)("span",{className:"text-xs font-semibold tabular-nums",children:t>9?"9+":t})]},e)})})}let so=(0,b.v)((0,ty.Zr)((e,t)=>({tabsByWorkspace:{},activeByWorkspace:{},agentTabs:[],setAgentTabs:t=>e({agentTabs:Array.isArray(t)?t:[]}),workspaceProfiles:{},workspaceWindows:{},setTabs:(t,s)=>e(e=>({tabsByWorkspace:{...e.tabsByWorkspace,[t]:Array.isArray(s)?s:[]}})),setActive:(t,s)=>e(e=>({activeByWorkspace:{...e.activeByWorkspace,[t]:s}})),setProfileFor:(t,s)=>e(e=>({workspaceProfiles:{...e.workspaceProfiles,[t||"default"]:s||"default"},workspaceWindows:{...e.workspaceWindows,[t||"default"]:null}})),setWindowFor:(t,s)=>e(e=>({workspaceWindows:{...e.workspaceWindows,[t||"default"]:s||null}})),profileFor:e=>t().workspaceProfiles[e||"default"]||"default",windowFor:e=>t().workspaceWindows[e||"default"]||null}),{name:"browser-ui-state",partialize:e=>({workspaceProfiles:e.workspaceProfiles,workspaceWindows:e.workspaceWindows}),storage:{getItem:e=>{try{let t=localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}},setItem:(e,t)=>{try{localStorage.setItem(e,JSON.stringify(t))}catch{}},removeItem:e=>{try{localStorage.removeItem(e)}catch{}}}}));function sc(e){return String(e||"").replace(/^🚀\s*\[\d+\]\s*/,"").trim()}var sd=s(98196),su=s(62004);function sx(e,t){if(!e)return"";if(!t)return e;if(e===t)return"~";let s=t.endsWith("/")?t:`${t}/`;return e.startsWith(s)?`~/${e.slice(s.length)}`:e}function sm(e){return e?.path?e.path:e?.items?.find(e=>e.workspacePath)?.workspacePath||null}function sp(e,t){if(!e)return"";let s=e.slice(0,e.lastIndexOf("/"))||"/",n=t.replace(/[^\w.-]+/g,"-");return`${s}/${e.split("/").pop()}-${n}`}function sf({workspacePath:e,workspaceName:t,fileBus:s,homeDir:l,value:a,onChange:i,onBrowse:o,staged:c=null}){let{t:d}=(0,eu.s)(),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(null),[f,h]=(0,r.useState)(!1),b=(0,r.useRef)(null),g=(0,r.useCallback)(async()=>{if(!e||!s?.gitScanRepos)return p([]);h(!0);let n=await s.gitScanRepos(e),r=n?.success&&n.repos||[],l=await Promise.all(r.map(async e=>{let t=await s.gitWorktreeList?.(e.path),n=t?.success&&t.worktrees||[],r=n.length?n.map(e=>({path:e.path,branch:e.branch,detached:e.detached})):[{path:e.path,branch:e.branch,detached:!1}];return{repoPath:e.path,name:e.name,branch:e.branch,isRoot:!e.relPath,isRepo:!0,entries:r}}));l.some(e=>e.isRoot)||l.unshift({repoPath:e,name:t||d("terminal.workspaceRoot"),isRoot:!0,isRepo:!1,entries:[{path:e,branch:null,detached:!1}]}),p(l),h(!1)},[e,t,s,d]);(0,r.useEffect)(()=>{if(!u)return;let e=e=>{b.current?.contains(e.target)||x(!1)},t=e=>{"Escape"===e.key&&(e.stopPropagation(),x(!1))};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t,!0)}},[u]);let v=(m?.length||0)>1,y=a?(m||[]).flatMap(e=>e.entries).find(e=>e.path===a):null,w=c?.branch||y?.branch||(a||e||"").split("/").filter(Boolean).pop()||t||d("terminal.workspaceRoot"),j=c?`${d("workspaces.newWorktree")} \xb7 ${sx(c.path,l)}`:"Pick a branch or worktree";return(0,n.jsxs)("div",{ref:b,className:"relative",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),null===m&&g(),x(e=>!e)},"aria-haspopup":"listbox","aria-expanded":u,title:c?.path||a||e||void 0,className:"w-full flex items-center gap-2 px-2.5 py-1.5 rounded-brand text-left bg-surface-2 hover:bg-surface-3 transition-colors",children:[c?(0,n.jsx)(el.dx,{size:14,className:"text-brand-500 shrink-0"}):(0,n.jsx)(el.Zr,{size:14,className:"text-text-muted shrink-0"}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)("span",{className:"text-xs text-text truncate leading-tight",children:w}),(0,n.jsx)("span",{className:"text-[10px] text-text-subtle truncate leading-tight",title:c?.path,children:j})]}),(0,n.jsx)(el.yQ,{size:14,className:`text-text-muted shrink-0 transition-transform ${u?"rotate-180":""}`})]}),u&&(0,n.jsxs)("div",{role:"listbox",className:"absolute z-10 left-0 right-0 top-full mt-1 max-h-72 flex flex-col bg-surface-3 rounded-brand border border-border shadow-xl",children:[(0,n.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto scrollbar-thin py-1",children:[f&&(0,n.jsx)("div",{className:"flex items-center justify-center py-4 text-text-muted",children:(0,n.jsx)(el.kr,{size:15,className:"animate-spin"})}),!f&&m?.map(e=>(0,n.jsxs)("div",{children:[v&&(0,n.jsx)("p",{className:"px-3 pt-1.5 pb-0.5 text-[10px] font-medium uppercase tracking-wider text-text-subtle truncate",children:e.name}),e.entries.map(t=>{let s=a===t.path;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":s,onClick:()=>{var e;return e=t.path,void((0,ed.e)(),i?.(e),x(!1))},className:`w-full flex items-start gap-2 px-3 py-1.5 text-left transition-colors ${s?"bg-brand-500/15":"hover:bg-text/[0.06]"}`,children:[t.branch||t.detached?(0,n.jsx)(el.Zr,{size:12,className:"mt-[3px] shrink-0 text-text-subtle"}):(0,n.jsx)(el.vd,{size:12,className:"mt-[3px] shrink-0 text-text-subtle"}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:`truncate text-xs ${s?"text-text font-medium":"text-text"}`,title:t.branch||e.name,children:t.branch||(t.detached?d("terminal.detachedHead"):e.name)}),s&&(0,n.jsx)(el.aJ,{size:12,className:"text-brand-400 shrink-0"})]}),(0,n.jsx)("span",{className:"truncate text-[10px] text-text-subtle leading-tight",title:t.path,children:t.path.split("/").filter(Boolean).pop()||t.path})]})]},t.path)})]},e.repoPath))]}),o&&(0,n.jsx)("div",{className:"shrink-0 border-t border-border-subtle flex items-center gap-1 px-2 py-1.5",children:(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),x(!1),o()},className:"flex-1 min-w-0 flex items-center justify-center gap-1.5 px-2 py-1 rounded-brand text-xs text-text-muted hover:bg-text/[0.06] hover:text-text transition-colors",children:[(0,n.jsx)(el.Bm,{size:12,className:"shrink-0 opacity-70"}),(0,n.jsx)("span",{className:"truncate",children:d("terminal.browseFolders")})]})})]})]})}function sh({size:e=14,className:t=""}){return(0,n.jsx)("span",{style:{width:e,height:e},className:`flex items-center justify-center rounded-[3px] bg-neutral-800 shrink-0 ${t}`,children:(0,n.jsx)(el.BK,{size:.85*e,className:"text-white"})})}function sb({agent:e=null,tool:t=null}){let s="string"==typeof e?e:e?.id||null;return s?.endsWith("-ui")?(0,n.jsx)("img",{src:e5(s),alt:"",draggable:!1,className:`w-3.5 h-3.5 flex-shrink-0 object-contain ${e2}`}):sn[t]?(0,n.jsx)("img",{src:sn[t],alt:t,draggable:!1,className:`w-3.5 h-3.5 flex-shrink-0 object-contain ${e2}`}):(0,n.jsx)(sh,{size:14})}function sg(e,t,{fireOnReturn:s=!0}={}){let n=null,r=()=>{n||!("u"<typeof document)&&document.hidden||(n=setInterval(e,t))},l=()=>{n&&(clearInterval(n),n=null)},a=()=>{document.hidden?l():(s&&e(),r())};return"u">typeof document&&document.addEventListener("visibilitychange",a),r(),()=>{l(),"u">typeof document&&document.removeEventListener("visibilitychange",a)}}let sv=new Map,sy=(e,t)=>e?`${e}|${t}`:t,sw=/[.*+?^${}()|[\]\\]/g;function sj({isOpen:e,onClose:t,busRef:s,cwd:l,scope:a="",onResume:i,onSelectSession:o,liveSessionIds:c,activeSessionId:d,connected:u=!0}){let{t:x}=(0,eu.s)(),[m,p]=(0,r.useState)(""),[f,b]=(0,r.useState)("all"),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)([]),[j,k]=(0,r.useState)(""),[N,C]=(0,r.useState)(!1),[S,T]=(0,r.useState)(!1),R=a?`${a}|${l}`:l,E=(0,h.B)(e=>l?e.agentHistory[R]?.sessions:null),$=(0,r.useMemo)(()=>E||[],[E]),z=e&&u&&m.trim().length>=3;(0,r.useEffect)(()=>{if(!z)return;let e=m.trim(),t=!1,n=setTimeout(()=>{C(!0),s?.current?.emit("searchAgentSessions",{query:e},s=>{t||(C(!1),T(!!s?.truncated),w(Array.isArray(s?.sessions)?s.sessions:[]),k(e))})},350);return()=>{t=!0,clearTimeout(n)}},[m,z,s]),(0,r.useEffect)(()=>{if(!e)return;document.activeElement?.blur?.();let s=e=>{"Escape"!==e.key||g||t()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,t,g]);let M=(0,r.useMemo)(()=>{let e=new Set;for(let t of $)t.agent&&e.add(t.agent);return Array.from(e)},[$]),P=(e,t)=>{let s=(e.title||"").toLowerCase(),n=(e.sessionId||"").toLowerCase(),r=(e.agent||"").toLowerCase();return s.includes(t)||n.includes(t)||r.includes(t)},A=(0,r.useMemo)(()=>{let e=m.trim().toLowerCase(),t=[],s=new Set,n=new Map;for(let e of z?y:[])e.snippet&&n.set(`${e.agent}:${e.sessionId}`,e.snippet);for(let r of $)if(("all"===f||r.agent===f)&&(!e||P(r,e))){let e=n.get(`${r.agent}:${r.sessionId}`);t.push(e?{...r,snippet:e}:r),s.add(`${r.agent}:${r.sessionId}`)}for(let e of z?y:[])s.has(`${e.agent}:${e.sessionId}`)||("all"===f||e.agent===f)&&t.push({...e,foreign:!0});return t.sort((e,t)=>(t.updatedAt||0)-(e.updatedAt||0))},[$,y,z,m,f]);return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200 touch-none",onClick:t}),(0,n.jsxs)("div",{className:"relative card-elev max-w-xl w-full max-h-[85vh] flex flex-col animate-in zoom-in-95 duration-200 overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-5 py-3.5 border-b border-border-subtle flex items-center justify-between flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(el.BZ,{size:17,className:"text-text-muted"}),(0,n.jsx)("h3",{className:"text-base font-semibold text-text",children:x("agentHistory.title")}),(0,n.jsx)("span",{className:"px-2 py-0.5 text-xs rounded-full bg-surface-2 text-text-subtle font-mono",children:$.length})]}),(0,n.jsx)("button",{onClick:t,className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":x("common.close"),children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsxs)("div",{className:"p-3 border-b border-border-subtle flex flex-col gap-2.5 bg-surface-2/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"relative flex items-center",children:[(0,n.jsx)(el.vj,{size:15,className:"absolute left-3 text-text-muted pointer-events-none"}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>p(e.target.value),placeholder:x("agentHistory.searchPlaceholder"),className:"w-full pl-9 pr-8 py-1.5 text-xs bg-surface-2 border border-border-subtle rounded-brand text-text placeholder-text-muted outline-none focus:border-brand-500/50 focus:ring-1 focus:ring-brand-500/20 transition-all"}),m&&(0,n.jsx)("button",{onClick:()=>p(""),className:"absolute right-2.5 p-0.5 text-text-muted hover:text-text rounded transition-colors",children:(0,n.jsx)(el.X,{size:13})})]}),(0,n.jsx)("div",{className:"h-4 px-1 text-[11px] leading-4 text-text-subtle",children:z&&(N?x("agentHistory.searchingAll"):S?x("agentHistory.searchTruncated"):null)}),M.length>1&&(0,n.jsxs)("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1 scrollbar-none",children:[(0,n.jsx)("button",{onClick:()=>b("all"),className:`shrink-0 h-7 px-3.5 text-xs rounded-brand transition-colors whitespace-nowrap flex items-center justify-center ${"all"===f?"bg-surface-3 text-text font-medium border border-border-subtle shadow-sm":"bg-surface-2/60 text-text-muted hover:text-text hover:bg-surface-2 border border-transparent"}`,children:x("agentHistory.allAgents")}),M.map(e=>(0,n.jsxs)("button",{onClick:()=>b(e),className:`shrink-0 h-7 px-3.5 text-xs rounded-brand transition-colors flex items-center gap-2 whitespace-nowrap capitalize ${f===e?"bg-surface-3 text-text font-medium border border-border-subtle shadow-sm":"bg-surface-2/60 text-text-muted hover:text-text hover:bg-surface-2 border border-transparent"}`,children:[(0,n.jsx)("img",{src:e5(e),alt:"",className:`w-3.5 h-3.5 ${e2}`}),(0,n.jsx)("span",{children:e})]},e))]})]}),(0,n.jsx)("div",{className:"h-[55vh] min-h-0 overflow-y-auto modal-scrollable p-2 space-y-1",children:0===A.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-14 text-text-muted text-sm gap-2",children:[(0,n.jsx)(el.BZ,{size:32,className:"opacity-40"}),(0,n.jsx)("span",{children:m?x("agentHistory.noResults"):x("agentHistory.empty")})]}):A.map(e=>{var s,r;let a=e.openSessionId&&c?.has(e.openSessionId)?e.openSessionId:null,d=e.title||x("agentHistory.untitled"),m=!!e.foreign;return(0,n.jsxs)("div",{onClick:()=>{(0,ed.e)(),a?o?.(a):i?.(e),t()},className:"group flex items-center gap-2.5 px-3 py-2 rounded-brand cursor-pointer transition-colors hover:bg-surface-2",children:[(0,n.jsx)("img",{src:e5(e.agent),alt:e.agent,className:`w-5 h-5 flex-shrink-0 object-contain ${e2} ${a?"":"opacity-70"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:`text-xs truncate ${a?"text-text font-medium":"text-text-muted"}`,children:d}),a&&(0,n.jsx)("span",{className:"px-2 py-0.5 text-[10px] leading-none rounded bg-success/15 text-success border border-success/25 flex-shrink-0 font-medium",children:x("agentHistory.openNow")})]}),e.snippet&&(0,n.jsx)("div",{className:"mt-0.5 text-[11px] leading-snug text-text-subtle line-clamp-2",children:(s=e.snippet,j?String(s).split(RegExp(`(${j.replace(sw,"\\$&")})`,"gi")).map((e,t)=>e.toLowerCase()===j.toLowerCase()?(0,n.jsx)("mark",{className:"bg-transparent text-text font-semibold px-0",children:e},t):e):s)}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mt-0.5 text-[11px] text-text-subtle min-w-0",children:[m&&e.cwd&&e.cwd!==l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"truncate min-w-0 max-w-[45%] font-mono",title:e.cwd,children:e.cwd}),(0,n.jsx)("span",{children:"•"})]}),e.branch&&"main"!==e.branch&&"master"!==e.branch&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"flex items-center gap-0.5 min-w-0 max-w-[45%]",title:e.branch,children:[(0,n.jsx)(el.dx,{size:9,className:"text-brand-500 shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.branch})]}),(0,n.jsx)("span",{children:"•"})]}),(0,n.jsx)("span",{className:"capitalize",children:e.agent}),(0,n.jsx)("span",{children:"•"}),(0,n.jsx)("span",{className:"tabular-nums",children:function(e,t){let s=Math.round((Date.now()-e)/6e4);if(s<60)return t("agentHistory.minutesAgo",{n:Math.max(1,s)});let n=Math.round(s/60);return n<24?t("agentHistory.hoursAgo",{n:n}):t("agentHistory.daysAgo",{n:Math.round(n/24)})}(e.updatedAt,x)}),e.size>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"•"}),(0,n.jsx)("span",{className:"tabular-nums font-mono text-[10px] opacity-75",children:(r=e.size)&&!(r<=0)?r<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(0)} KB`:`${(r/1048576).toFixed(1)} MB`:""})]})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},disabled:!u||!!a||!!m,className:`p-1.5 text-text-muted hover:text-danger hover:bg-danger/10 rounded-brand transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100 ${a||m?"invisible pointer-events-none":""}`,title:x("agentHistory.delete"),"aria-label":x("agentHistory.delete"),children:(0,n.jsx)(el.TB,{size:14})})})]},`${e.agent}:${e.sessionId}`)})})]}),g&&(0,n.jsx)(ec.A,{isOpen:!0,onClose:()=>v(null),onConfirm:()=>{if(!g)return;let{agent:e,sessionId:t}=g;(0,ed.e)();let n=$.filter(s=>s.agent!==e||s.sessionId!==t);h.B.getState().setAgentHistory(R,n),s?.current?.emit("deleteAgentSession",{agent:e,sessionId:t,cwd:l},e=>{e?.success||s?.current?.emit("getAgentSessions",{cwd:l},e=>{Array.isArray(e?.sessions)&&h.B.getState().setAgentHistory(R,e.sessions)})}),v(null)},title:x("agentHistory.deleteTitle"),message:x("agentHistory.deleteMessage",{title:g.title||x("agentHistory.untitled")})})]}):null}function sk({busRef:e,scope:t="",cwd:s,onResume:l,onSelectSession:a,liveSessionIds:i,activeSessionId:o,connected:c=!0,variant:d="section"}){let{t:u}=(0,eu.s)(),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(!1),[b,g]=(0,r.useState)(null),v=function(e,t,s=""){let n=t?sy(s,t):null,l=(0,h.B)(e=>n?e.agentHistory[n]:null),a=l?.at??0;return(0,r.useEffect)(()=>{if(!t)return;let n=function(e,t,s){let n=sy(t,s),r=sv.get(n);if(r)return r.count+=1,r;let l=!1,a=null,i=()=>{let t=e?.current;if(!t){a=setTimeout(i,1e3);return}l||(l=!0,t.emit("getAgentSessions",{cwd:s},e=>{l=!1,Array.isArray(e?.sessions)&&h.B.getState().setAgentHistory(n,e.sessions)}))},o=sg(i,eJ.fw),c={count:1,fetchNow:i,stop:()=>{clearTimeout(a),o()}};return sv.set(n,c),c}(e,s,t),r=h.B.getState().agentHistory[sy(s,t)];return(!r||Date.now()-r.at>=eJ.fw)&&n.fetchNow(),()=>{let e;!(e=sv.get(sy(s,t)))||(e.count-=1,!(e.count>0)&&(e.stop(),sv.delete(sy(s,t))))}},[e,t,s,a]),l?.sessions||null}(e,s,t),y=t?`${t}|${s}`:s,w="list"===d;(0,r.useEffect)(()=>{if(w||!s)return;let e=e=>{let t=e.target?.tagName;"INPUT"===t||"TEXTAREA"===t||e.target?.isContentEditable||(tc()?!e.altKey||e.ctrlKey||e.metaKey:!e.ctrlKey||e.metaKey||e.altKey)||"h"!==e.key.toLowerCase()||(e.preventDefault(),f(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[w,s]);let j=p&&(0,n.jsx)(sj,{isOpen:p,onClose:()=>f(!1),busRef:e,cwd:s,scope:t,onResume:l,onSelectSession:a,liveSessionIds:i,activeSessionId:o,connected:c});if(!s)return null;if(!v?.length)return w?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex-1 min-h-0 flex items-center justify-center px-6 py-10 text-center text-sm text-text-muted",children:u("agentHistory.empty")}),j]}):j;let k=w?v:v.slice(0,40),N=!w&&v.length>40;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:w?"flex-1 min-h-0 flex flex-col":"flex-shrink-0 border-t border-border-subtle pt-1 flex flex-col",style:w?void 0:{maxHeight:x?void 0:eJ.i5},children:[!w&&(0,n.jsxs)("div",{className:"w-full pl-0 pr-1 py-0.5 flex items-center justify-between text-text-subtle",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),m(e=>!e)},className:"flex items-center gap-1.5 hover:text-text transition-colors flex-1 min-w-0",children:[(0,n.jsx)(el.c_,{size:12,className:`flex-shrink-0 transition-transform duration-150 ${x?"":"rotate-90"}`}),(0,n.jsx)(el.BZ,{size:11,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"text-[11px] font-medium uppercase truncate",children:u("agentHistory.title")}),(0,n.jsxs)("span",{className:"ml-1 text-[10px] tabular-nums opacity-60",children:["(",v.length,")"]})]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f(!0)},className:"p-1 hover:text-text hover:bg-surface-2 rounded transition-colors text-text-subtle",title:u("agentHistory.manageHistory"),"aria-label":u("agentHistory.manageHistory"),children:(0,n.jsx)(el.Gr,{size:12})})]}),(w||!x)&&(0,n.jsxs)("div",{className:`overflow-y-auto modal-scrollable min-h-0 ${w?"flex-1 px-1.5 pb-2":""}`,children:[k.map(e=>{let t=e.openSessionId&&i?.has(e.openSessionId)?e.openSessionId:null,s=!!t&&t===o,r=e.title||u("agentHistory.untitled");return(0,n.jsxs)("div",{className:`group relative w-full flex items-center gap-1 text-left transition-colors rounded-brand hover:bg-text/5 ${w?"gap-2 px-2.5 py-1.5":"pl-3 pr-1 py-px"} ${s?"bg-text/8":""}`,children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),t?a?.(t):l?.(e)},disabled:!c,className:`flex items-center gap-1.5 flex-1 min-w-0 text-left transition-colors disabled:opacity-40 hover:text-text touch-manipulation touch-pan-y ${w?"gap-2.5":""} ${t?"text-text font-medium":"text-text-muted"}`,title:`${r} \xb7 ${e.agent}${t?` \xb7 ${u("agentHistory.openNow")}`:""}`,children:[(0,n.jsx)("img",{src:e5("ui"===e.mode?`${e.agent}-ui`:e.agent),alt:e.agent,className:`flex-shrink-0 ${e2} ${w?"w-4 h-4":"w-2.5 h-2.5"} ${t?"":"opacity-70"}`}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)("span",{className:`truncate ${w?"text-sm":"text-[11px]"}`,"data-tip":r,children:r}),e.branch&&"main"!==e.branch&&"master"!==e.branch&&(0,n.jsxs)("span",{className:"flex items-center gap-0.5 min-w-0 text-[10px] leading-tight",children:[(0,n.jsx)(el.dx,{size:9,className:"text-brand-500 shrink-0"}),(0,n.jsx)("span",{className:"truncate text-text-subtle",children:e.branch})]})]}),(0,n.jsx)("span",{className:`text-[10px] text-text-subtle flex-shrink-0 opacity-70 tabular-nums whitespace-nowrap ${w?"mr-1":""}`,children:function(e,t){let s=Math.round((Date.now()-e)/6e4);if(s<60)return t("agentHistory.minutesAgo",{n:Math.max(1,s)});let n=Math.round(s/60);return n<24?t("agentHistory.hoursAgo",{n:n}):t("agentHistory.daysAgo",{n:Math.round(n/24)})}(e.updatedAt,u)})]}),w?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),g(e)},disabled:!c||!!t,className:`flex-shrink-0 p-1 rounded-[4px] text-text-subtle transition-colors hover:bg-danger/10 hover:text-danger opacity-60 hover:opacity-100 ${t?"invisible":""}`,title:t?u("agentHistory.openNow"):u("agentHistory.delete"),"aria-label":u("agentHistory.delete"),children:(0,n.jsx)(el.TB,{size:14})}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),g(e)},disabled:!c||!!t,className:`absolute right-1 top-1/2 -translate-y-1/2 pl-1.5 pr-0.5 rounded-[4px] bg-surface-2 text-text-subtle group-hover:text-danger hover:bg-danger/10 transition-colors opacity-0 group-hover:opacity-100 ${t?"invisible":""}`,title:t?u("agentHistory.openNow"):u("agentHistory.delete"),"aria-label":u("agentHistory.delete"),children:(0,n.jsx)(el.TB,{size:13})})]},`${e.agent}:${e.sessionId}`)}),N&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),f(!0)},className:"w-full py-1.5 px-2 mt-1 mb-0.5 flex items-center justify-center gap-1.5 text-[10px] font-medium text-text-subtle hover:text-text bg-surface-2/50 hover:bg-surface-2 border border-border-subtle/50 rounded transition-all",children:[(0,n.jsx)(el.BZ,{size:11,className:"opacity-60"}),(0,n.jsxs)("span",{children:[u("agentHistory.showAll")," (",v.length,")"]})]})]})]}),j,b&&(0,n.jsx)(ec.A,{isOpen:!0,onClose:()=>g(null),onConfirm:()=>{if(!b)return;let{agent:t,sessionId:n}=b;(0,ed.e)();let r=(v||[]).filter(e=>e.agent!==t||e.sessionId!==n);h.B.getState().setAgentHistory(y,r),e?.current?.emit("deleteAgentSession",{agent:t,sessionId:n,cwd:s},t=>{t?.success||e?.current?.emit("getAgentSessions",{cwd:s},e=>{Array.isArray(e?.sessions)&&h.B.getState().setAgentHistory(y,e.sessions)})}),g(null)},title:u("agentHistory.deleteTitle"),message:u("agentHistory.deleteMessage",{title:b.title||u("agentHistory.untitled")})})]})}function sN({title:e,value:t,onChange:s,onSubmit:l,onClose:a,confirmLabel:i,cancelLabel:o,placeholder:c,hideCancel:d=!1}){let{t:u}=(0,eu.s)();return((0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),a?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[a]),"u"<typeof document)?null:(0,sd.createPortal)((0,n.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center px-4",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-150",onClick:a}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:"relative card-elev w-full max-w-xs p-5 my-auto max-h-[min(85%,calc(var(--app-height,85vh)-2rem))] overflow-y-auto animate-in zoom-in-95 duration-150",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2 mb-3",children:[(0,n.jsx)("h3",{className:"text-[14px] font-semibold text-text",children:e}),(0,n.jsx)("button",{onClick:a,"aria-label":u("common.close"),className:"p-1 -mr-1 -mt-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors shrink-0",children:(0,n.jsx)(el.X,{size:14})})]}),(0,n.jsx)("input",{autoFocus:!0,value:t,placeholder:c,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&l(),"Escape"===e.key&&a()},className:"w-full bg-surface-2 border border-border-subtle rounded-brand px-3 py-2 text-sm text-text outline-none focus:border-brand-500"}),(0,n.jsxs)("div",{className:"flex gap-2 mt-4",children:[(0,n.jsxs)("button",{onClick:l,disabled:!t?.trim(),className:"flex-1 py-2 text-sm font-semibold text-white bg-brand-500 rounded-brand disabled:opacity-40 flex items-center justify-center gap-1.5",children:[(0,n.jsx)("span",{children:i??u("common.confirm")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(el.Lt,{size:10,strokeWidth:2.5})})]}),!d&&(0,n.jsxs)("button",{onClick:a,className:"flex-1 py-2 text-sm text-text-muted bg-surface-2 rounded-brand flex items-center justify-center gap-1.5",children:[(0,n.jsx)("span",{children:o??u("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]})]})]})]}),document.body)}let sC=new Map,sS=(e,t)=>{sC.set(e,null==t?null:(0,O.kb)(t))},sT=/^[A-Za-z]:\/?$/,sR=/^[A-Za-z]:\//,sE=e=>{if(!e||"/"===e||sT.test(e))return null;let t=e.lastIndexOf("/");if(t<=0)return"/";let s=e.slice(0,t);return/^[A-Za-z]:$/.test(s)?`${s}/`:s},s$=e=>e&&"/"!==e?e.split("/").filter(Boolean).pop()??null:null,sz=e=>{let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return -1===t?"":e.slice(0,t+1)},sM=(e,t)=>"drive"===e.kind?t<0?e.driveRoot:`${e.driveRoot}${e.segments.slice(0,t+1).join("/")}`:`/${e.segments.slice(0,t+1).join("/")}`;function sP(e,t){let s=t.trim().toLowerCase();return s?e.filter(e=>e.name.toLowerCase().includes(s)):e}let sA=e=>e.includes("/")||e.includes("\\")||/^[A-Za-z]:$/.test(e)||"~"===e||"."===e||".."===e;function sI(e){let t,s,n;if(!sA(e))return{mode:"filter",filter:e};let r=e.replace(/\\/g,"/");if("~"===r)return{mode:"path",base:"home",committedSegments:[],trailingFilter:""};if("."===r)return{mode:"path",base:"cwd",committedSegments:[],trailingFilter:""};if(".."===r)return{mode:"path",base:"cwd",committedSegments:[".."],trailingFilter:""};if(/^[A-Za-z]:$/.test(r))return{mode:"path",base:"drive",driveRoot:`${r[0].toUpperCase()}:/`,committedSegments:[],trailingFilter:""};if(sR.test(r)?(t="drive",s=`${r[0].toUpperCase()}:/`,n=r.slice(3)):r.startsWith("/")?(t="root",n=r.slice(1)):r.startsWith("~/")?(t="home",n=r.slice(2)):(t="cwd",n=r),n.includes("//")||/[\x00-\x1F]/.test(n))return{mode:"path",base:t,driveRoot:s,committedSegments:[],trailingFilter:"",invalid:!0};let l=""===n?[""]:n.split("/");return{mode:"path",base:t,driveRoot:s,committedSegments:l.slice(0,-1),trailingFilter:l[l.length-1]}}function sD({fileBus:e,initialPath:t,scope:s="",onSelect:l,onClose:a}){let{t:i}=(0,eu.s)(),[o]=(0,r.useState)(()=>t||sC.get(s)||null||null),[c,d]=(0,r.useState)(o),[u,x]=(0,r.useState)([]),[m,p]=(0,r.useState)(!!o),[f,h]=(0,r.useState)(null),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(0),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(null),[C]=(0,r.useState)(()=>ef(s)),S=(0,r.useRef)(null),T=(0,r.useRef)(!1),R=(0,r.useRef)(0),E=(0,r.useRef)(0),$=(0,r.useRef)(null),z=(0,r.useRef)(null),M=(0,r.useRef)(null),P=(0,r.useRef)(null),A=(0,r.useRef)(null),I=(0,r.useRef)(new Map),D=(0,r.useRef)(null),L=(0,r.useRef)(""),B=(0,r.useRef)(!1),F=(0,r.useCallback)(async t=>{let s=I.current.get(t);if(s)return s;let n=await e.getFiles(t,!1);if(!n?.success)throw Error(n?.error||i("workspaces.pathNotFolder"));let r={resolvedPath:(0,O.kb)(n.currentPath)||t,entries:(n.files||[]).filter(e=>"folder"===e.type)};return I.current.set(r.resolvedPath,r),t!==r.resolvedPath&&I.current.set(t,r),r},[e,i]),K=(0,r.useCallback)(async e=>{if(null==e){R.current++,d(null),x([]),p(!1),h(null);return}let t=++R.current;p(!0),h(null);try{let s=await F(e);if(t!==R.current)return;d(s.resolvedPath),x(s.entries),"~"===e&&(D.current=s.resolvedPath)}catch(e){if(t!==R.current)return;h(e.message||String(e)),x([])}finally{t===R.current&&p(!1)}},[F]);(0,r.useEffect)(()=>{if(!o)return;let e=setTimeout(()=>void K(o),0);return()=>clearTimeout(e)},[o,K]),(0,r.useEffect)(()=>{let t=!1;return e?.getSystemInfo?.().then(e=>{if(t||!e?.success)return;N(e);let s=(0,O.kb)(e.homedir);s&&(D.current=s,o||B.current||(B.current=!0,K(s)))}),()=>{t=!0}},[e,o,K]);let W=(0,r.useCallback)(e=>{(0,ed.e)(),sS(s,e),g(""),j(null),y(0),E.current++,L.current="",$.current&&(clearTimeout($.current),$.current=null),K(e)},[K,s]),_=(0,r.useCallback)(()=>{c&&W(sE(c))},[c,W]),H=(0,r.useCallback)(async e=>{let t,s=sI(e);if("path"!==s.mode)return;let n=++E.current;if(s.invalid)return void j({resolvedPath:c??"/",entries:[],filter:"",error:i("workspaces.invalidPath"),loading:!1});if("root"===s.base)t="/";else if("drive"===s.base)t=s.driveRoot;else if("home"===s.base){if(!D.current){j({resolvedPath:c??"/",entries:[],filter:"",error:null,loading:!0});try{let e=await F("~");if(n!==E.current)return;D.current=e.resolvedPath}catch(e){if(n!==E.current)return;j({resolvedPath:c??"/",entries:[],filter:"",error:e.message,loading:!1});return}}t=D.current}else t=c||"/";j(e=>e&&e.loading?e:{resolvedPath:t,entries:[],filter:"",error:null,loading:!0});let r=t;try{for(let e of s.committedSegments){let t=await F(r);if(n!==E.current)return;let s=function(e,t){if("."===e||".."===e)return{type:"stay",up:".."===e};let s=t.find(t=>t.name===e)||t.find(t=>t.name.toLowerCase()===e.toLowerCase());if(s)return"folder"===s.type?{type:"descend",path:s.path}:{type:"error",multiple:!1};let n=e.toLowerCase(),r=t.filter(e=>"folder"===e.type&&e.name.toLowerCase().startsWith(n));return 1===r.length?{type:"descend",path:r[0].path}:{type:"error",multiple:r.length>1}}(e,t.entries);if("error"===s.type){let n=sx(r,k?.homedir);j({resolvedPath:r,entries:t.entries,filter:"",error:s.multiple?i("workspaces.multipleDirMatches",{name:e,dir:n}):i("workspaces.notADirectory",{name:e,dir:n}),loading:!1});return}if("stay"===s.type){s.up&&(r=sE(r)||"/");continue}r=s.path}let t=await F(r);if(n!==E.current)return;L.current=sz(e),j({resolvedPath:t.resolvedPath,entries:t.entries,filter:s.trailingFilter,error:null,loading:!1})}catch(e){if(n!==E.current)return;j({resolvedPath:r,entries:[],filter:"",error:e.message,loading:!1})}},[c,F,k,i]),U=(0,r.useCallback)(e=>{if(g(e),y(0),e.length>2048||!sA(e)){w&&(j(null),E.current++),$.current&&(clearTimeout($.current),$.current=null);return}let t=sI(e);"path"!==t.mode||!w||w.error||t.invalid||sz(e)!==L.current?($.current&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null,H(e)},300)):j({...w,filter:t.trailingFilter})},[w,H]);(0,r.useEffect)(()=>()=>{for(let e of(R.current++,E.current++,[$,z,M]))e.current&&clearTimeout(e.current),e.current=null},[]);let q=(0,r.useMemo)(()=>sP(u,b),[u,b]),X=(0,r.useMemo)(()=>w?sP(w.entries,w.filter):[],[w]),V=w?X:q;(0,r.useEffect)(()=>{T.current=window.matchMedia("(min-width: 640px)").matches,T.current&&S.current?.focus()},[]),(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||b||a()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[b,a]);let[J,G]=(0,r.useState)(null),Y=(0,r.useCallback)(async t=>{let s=(t||"").trim().replace(/[\\/:*?"<>|]/g,"");if(!s||!c)return;let n=k?.isWindows?"\\":"/",r=`${c.replace(/[\\/]+$/,"")}${n}${s}`,l=await e.createItem(r,"folder");l?.success&&(I.current.delete(c),G(null),K(r))},[c,e,k,K]),Z=(0,r.useMemo)(()=>(function(e){if(!e)return{kind:"posix",segments:[]};let t=/^([A-Za-z]:)(\/.*)?$/.exec(e);return t?{kind:"drive",driveRoot:`${t[1]}/`,segments:(t[2]||"").split("/").filter(Boolean)}:{kind:"posix",segments:e.split("/").filter(Boolean)}})(c),[c]);(0,r.useEffect)(()=>{P.current&&(P.current.scrollLeft=P.current.scrollWidth)},[c]);let Q=s$(c),ee=k?(0,O.kb)(k.homedir):null,et=!!k?.isWindows,es=m||!!w&&""!==b;return"u"<typeof document?null:(0,sd.createPortal)((0,n.jsxs)("div",{className:"fixed inset-0 z-[80] flex items-center justify-center p-3 sm:p-4 bg-black/60 backdrop-blur-[2px]",onClick:a,children:[(0,n.jsxs)("div",{ref:A,role:"dialog","aria-modal":"true","aria-label":i("workspaces.newWorkspace"),onKeyDown:e=>{if("Tab"!==e.key)return;let t=A.current?.querySelectorAll("button:not([disabled]), input");if(!t?.length)return;let s=t[0],n=t[t.length-1];e.shiftKey&&document.activeElement===s?(e.preventDefault(),n.focus()):e.shiftKey||document.activeElement!==n||(e.preventDefault(),s.focus())},className:"card-elev w-full sm:w-[560px] sm:max-w-full h-[min(85%,calc(var(--app-height,85vh)-2rem))] sm:h-[70vh] sm:max-h-[560px] my-auto flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 h-11 flex items-center gap-2 border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text flex-1",children:i("workspaces.newWorkspace")}),(0,n.jsx)("button",{onClick:a,className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2",children:(0,n.jsx)(el.X,{size:16})})]}),(0,n.jsxs)("div",{className:"px-3 pt-2 flex items-center gap-0.5 min-h-[28px] flex-shrink-0",children:[(0,n.jsx)("button",{onClick:_,disabled:m||!c||"/"===c,className:"shrink-0 p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] disabled:opacity-30 transition-colors",title:i("workspaces.parentFolder"),children:(0,n.jsx)(el.Do,{size:14})}),(0,n.jsx)("button",{onClick:()=>W(ee||"/"),disabled:m,className:"shrink-0 p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors",title:i("workspaces.homeFolder"),children:(0,n.jsx)(el.ww,{size:14})}),(0,n.jsxs)("div",{ref:P,className:"flex-1 flex items-center gap-0 text-[11px] text-text-muted ml-1 min-w-0 overflow-x-auto scrollbar-none",children:[et?(0,n.jsx)("button",{type:"button",onClick:()=>W(null),className:"shrink-0 px-0.5 hover:text-text transition-colors",title:i("workspaces.drives"),children:(0,n.jsx)(el.ak,{size:12})}):(0,n.jsx)("button",{type:"button",onClick:()=>W("/"),className:"shrink-0 px-0.5 hover:text-text transition-colors",children:"/"}),"drive"===Z.kind&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el.c_,{size:11,className:"shrink-0 text-text-subtle"}),(0,n.jsx)("button",{type:"button",onClick:()=>W(Z.driveRoot),className:`truncate max-w-[120px] px-0.5 hover:text-text transition-colors ${0===Z.segments.length?"text-text font-medium":""}`,children:Z.driveRoot.replace(/\/$/,"")})]}),Z.segments.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-0 min-w-0",children:[(0,n.jsx)(el.c_,{size:11,className:"shrink-0 text-text-subtle"}),(0,n.jsx)("button",{type:"button",onClick:()=>W(sM(Z,t)),className:`truncate max-w-[120px] px-0.5 hover:text-text transition-colors ${t===Z.segments.length-1?"text-text font-medium":""}`,children:e})]},sM(Z,t)))]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),G({value:""})},disabled:m||!c,className:"ml-1 shrink-0 p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] disabled:opacity-30 transition-colors",title:i("workspaces.createFolderTitle"),children:(0,n.jsx)(el.JU,{size:14})})]}),(0,n.jsxs)("div",{className:"px-3 py-2 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 bg-surface-2 rounded-[3px] px-2 py-1.5 border border-border-subtle focus-within:border-brand-500 transition-colors",children:[(0,n.jsx)(el.vj,{size:13,className:"text-text-subtle flex-shrink-0"}),(0,n.jsx)("input",{ref:S,value:b,onChange:e=>U(e.target.value),onPaste:e=>{e.defaultPrevented||e.clipboardData.getData("text/plain").length>2048||(z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{z.current=null,$.current&&(clearTimeout($.current),$.current=null);let e=S.current?.value??"";e.length<=2048&&sA(e)&&H(e)},0))},onKeyDown:e=>{if("Enter"===e.key){if(w){if(w.error||w.loading)return void e.preventDefault();let t=sI(b);if("path"===t.mode&&""===t.trailingFilter){e.preventDefault(),W(w.resolvedPath);return}return void(1===X.length?(e.preventDefault(),W(X[0].path)):e.preventDefault())}let t=1===q.length?q[0]:q[v];return void(t&&(e.preventDefault(),W(t.path)))}"ArrowDown"===e.key?(e.preventDefault(),y(e=>Math.min(e+1,Math.max(V.length-1,0)))):"ArrowUp"===e.key?(e.preventDefault(),y(e=>Math.max(e-1,0))):"Escape"===e.key&&b?(e.stopPropagation(),g(""),j(null),E.current++,$.current&&(clearTimeout($.current),$.current=null)):"Backspace"!==e.key||""!==b||w||(e.preventDefault(),_())},placeholder:i("workspaces.filterOrPath"),"aria-invalid":!!w?.error,className:"flex-1 min-w-0 bg-transparent text-sm text-text outline-none placeholder:text-text-subtle"}),w?.loading&&(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-text-subtle flex-shrink-0"}),!!b&&!w?.loading&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle tabular-nums flex-shrink-0",children:V.length})]}),w?.error&&(0,n.jsx)("p",{className:"pt-1 px-0.5 text-[11px] text-red-500",children:w.error})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[!b&&!w&&!!C.length&&(0,n.jsxs)("div",{className:"p-2 pb-1",children:[(0,n.jsx)("p",{className:"px-1 pb-1.5 text-[10px] uppercase tracking-wider text-text-subtle",children:i("workspaces.recentFolders")}),(0,n.jsx)("div",{className:"flex gap-1.5 overflow-x-auto pb-0.5",children:C.slice(0,8).map(e=>{let t=(0,O.kb)(e.path);return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),sS(s,t),l(t)},className:"flex items-center gap-1.5 px-2 py-1.5 bg-surface-2 hover:bg-surface-3 rounded-[4px] border border-border-subtle text-left transition-colors w-[150px] shrink-0",title:t,children:[(0,n.jsx)(el.Bm,{size:13,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"block text-xs text-text truncate",children:s$(t)||t}),(0,n.jsx)("span",{className:"block text-[10px] text-text-subtle truncate",children:sx(t,ee)})]})]},e.path)})})]}),!b&&!w&&!c&&(0,n.jsx)("div",{className:"p-2 space-y-1",children:et?k?.drives?.map(e=>(0,n.jsx)(sL,{icon:(0,n.jsx)(el.ak,{size:15,className:"text-blue-500/70"}),label:(0,O.kb)(e.path),onClick:()=>W((0,O.kb)(e.path))},e.letter)):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(sL,{icon:(0,n.jsx)(el.ww,{size:15,className:"text-blue-500/70"}),label:ee||"/",onClick:()=>W(ee||"/")}),(0,n.jsx)(sL,{icon:(0,n.jsx)(el.ak,{size:15,className:"text-text-subtle"}),label:"/",onClick:()=>W("/")})]})}),m&&(0,n.jsx)("div",{className:"p-6 flex justify-center text-text-muted",children:(0,n.jsx)(el.kr,{size:18,className:"animate-spin"})}),!m&&f&&(0,n.jsx)("p",{className:"p-4 text-xs text-red-500",children:f}),!m&&!f&&(c||w)&&(0,n.jsxs)("div",{className:"p-1",children:[V.map((e,t)=>(0,n.jsxs)("button",{onClick:()=>{!w?.loading&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{M.current=null,W(e.path)},220))},onDoubleClick:()=>{!w?.loading&&(M.current&&(clearTimeout(M.current),M.current=null),sS(s,e.path),l(e.path))},onMouseDown:e=>{T.current&&(e.preventDefault(),S.current?.focus())},className:`group w-full flex items-center gap-2 pl-3 pr-2 py-2 text-sm text-text rounded-[3px] hover:bg-surface-2 active:bg-surface-2 transition-colors ${(b||w)&&t===v?"bg-surface-2 ring-1 ring-brand-500/40":""}`,children:[(0,n.jsx)(el.vd,{size:16,className:"text-text-subtle flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-left",title:e.name,children:e.name}),(0,n.jsx)(el.c_,{size:14,className:"text-text-subtle flex-shrink-0 opacity-0 group-hover:opacity-100"})]},e.path)),!V.length&&(0,n.jsx)("p",{className:"px-3 py-4 text-xs text-text-subtle italic",children:(w?w.entries.length:u.length)?i("common.noResults"):i("files.emptyFolder")})]})]}),(0,n.jsxs)("div",{className:"px-3 pt-2 pb-3 border-t border-border-subtle flex-shrink-0",children:[(0,n.jsx)("p",{className:"pb-2 text-[10px] text-text-subtle truncate",title:w?w.resolvedPath:c||"",children:w?sx(w.resolvedPath,ee):c?sx(c,ee):i("workspaces.drives")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),G({value:""})},disabled:!c,className:"flex items-center gap-1.5 px-4 py-2 text-sm text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-[3px] transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:i("workspaces.createFolderTitle"),children:[(0,n.jsx)(el.JU,{size:14}),i("workspaces.createFolderTitle")]}),(0,n.jsx)("button",{onClick:()=>{c&&(sS(s,c),(0,ed.e)(),l(c))},disabled:!c||es,className:"flex-1 py-2 text-sm font-semibold text-white bg-brand-500 hover:bg-brand-600 rounded-[3px] transition-colors disabled:opacity-40 disabled:cursor-not-allowed truncate",title:c||"",children:Q?i("workspaces.selectNamed",{name:Q}):i("workspaces.selectFolder")})]})]})]}),J&&(0,n.jsx)(sN,{title:i("workspaces.createFolderTitle"),confirmLabel:i("workspaces.createFolderTitle"),hideCancel:!0,placeholder:i("workspaces.newFolderName"),value:J.value,onChange:e=>G({value:e}),onSubmit:()=>Y(J.value),onClose:()=>G(null)})]}),document.body)}function sL({icon:e,label:t,onClick:s}){return(0,n.jsxs)("button",{onClick:s,className:"w-full flex items-center gap-2 px-2 py-1.5 text-xs text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors text-left",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:e}),(0,n.jsx)("span",{className:"truncate",children:t})]})}let sB=["⌥","⇧","↵"],sF=["Ctrl","⇧","↵"],sK=[{id:"new",icon:el.BK,labelKey:"terminal.newTerminal"},{id:"history",icon:el.BZ,labelKey:"agentHistory.title"}];function sO({agent:e}){let[t,s]=(0,r.useState)(!1);return e?t?(0,n.jsx)(el.cC,{size:16,className:"text-text-muted"}):(0,n.jsx)("img",{src:e5(e.id),alt:"",width:16,height:16,onError:()=>s(!0),className:`w-4 h-4 object-contain ${e2}`}):(0,n.jsx)(sh,{size:16})}function sW({onClose:e,onCreate:t,shells:s=[],suggestName:l="",busRef:a=null,workspacePath:i=null,workspaceName:o="",fileBus:c=null,homeDir:d=null,onResumeAgentSession:u=null,liveSessionIds:x=null,activeSessionId:m=null,onSelectSession:p=null,connected:f=!0,hostKey:b="main",onCreateBrowser:g,workspaceId:v=null}){let{t:y}=(0,eu.s)(),w=eE("main"!==b?b:null),j=w.head?w.fileBus:c||w.fileBus,k=w.scope,N=tg(a,b),[C,S]=(0,r.useState)(()=>ts().agentId),[T,R]=(0,r.useState)(""),[E,$]=(0,r.useState)(null),[z,M]=(0,r.useState)(!1),[P,A]=(0,r.useState)(!1),[I,D]=(0,r.useState)(""),[L,B]=(0,r.useState)(null),[F,K]=(0,r.useState)(!1),[O,W]=(0,r.useState)(null),[_,H]=(0,r.useState)(null),U=(0,r.useRef)(null),[q,X]=(0,r.useState)(()=>ts().yolo),[V,J]=(0,r.useState)(()=>{let e=te(e8);return e&&s.some(t=>t.id===e)?e:s[0]?.id||""}),[G,Y]=(0,r.useState)("new"),Z=(0,r.useRef)(null),Q=(0,r.useRef)(null),ee=(0,r.useRef)(!1);(0,r.useEffect)(()=>{window.matchMedia("(pointer: fine)").matches&&requestAnimationFrame(()=>Z.current?.focus())},[]);let et=tc()?sB:sF,es=(0,su.A)(I.trim()).replace(/[^\w.-]+/g,"-").replace(/^-+|-+$/g,""),en=E||L||i,er=es?{repo:en,branch:es,path:sp(en,es)}:null,ea=()=>{(0,ed.e)(),A(!1),D(""),W(null)},ei=()=>{er&&((0,ed.e)(),W(null),A(!1))};(0,r.useEffect)(()=>{!ee.current&&N?.length&&C&&(ee.current=!0,Q.current?.querySelector("[data-picked=true]")?.scrollIntoView({block:"nearest"}))},[N,C]);let eo=tv.H8,ec=(N||[]).flatMap(e=>{let t=eo.find(t=>t.aiEngine===e.id);return t?[e,t]:[e]}),ex=new Map(eo.map(e=>[e.aiEngine,e])),em=new Set(ex.keys()),ep=ec.find(e=>"claude"===e.id),ef=ec.find(e=>"claude-ui"===e.id),eh=[],eb=new Set(["claude"]);for(let e of ec){let t=e.isAiUi?e.aiEngine:e.id;if(eb.has(t)||!em.has(t))continue;eb.add(t);let s=ec.find(e=>!e.isAiUi&&e.id===t),n=ex.get(t);s&&eh.push(s),n&&eh.push(n)}let eg=ec.filter(e=>!e.isAiUi&&!em.has(e.id)&&"claude"!==e.id),ev=(0,h.B)(e=>e.pushView),ey=void 0!==g?g:f?()=>{let e=v??"default",t=so.getState(),s=t.workspaceWindows[e]||null;a?.current?.emit?.("browser:invoke",{action:"open",payload:{url:"about:blank",profile:t.workspaceProfiles[e]||"default",newWindow:!s,windowId:s||void 0}},t=>{if(!t?.ok||!t.id)return;let s=so.getState();t.windowId&&t.windowId!==s.workspaceWindows[e]&&s.setWindowFor(e,t.windowId),s.setActive(e,t.id);let n=s.tabsByWorkspace[e]||[];n.some(e=>e.id===t.id)||s.setTabs(e,[...n,{id:t.id,url:"about:blank",title:""}])}),ev({type:"browser"})}:null,ew=ey?{id:"browser",isBrowser:!0,label:y("sites.browserTab")}:null,ej=C&&ec.find(e=>e.id===C)||("browser"===C?ew:null)||null,ek=[null,ew||{empty:!0},...ep?[ep]:[],...ef?[ef]:[],...eh,...eg],eN=!ej?.isAiUi&&e3(ej),eC=ej?.yolo||(ej?.yoloEnv?Object.entries(ej.yoloEnv).map(([e,t])=>`${e}=${t}`).join(" "):null),eS=e=>{(0,ed.e)(),S(e?.id||"")},eT=l.match(/\d+$/)?.[0],eR=er?er.branch:ej?`${ej.short||ej.label}${eT?` ${eT}`:""}`:l||y("terminal.defaultName"),e$=E||i,ez=!!u&&!!e$,eM=ez&&"history"===G,eP=(s=ej)=>{if((0,ed.e)(),s?.isBrowser){ey?.(),e?.();return}if(F)return;let n=n=>{!s&&V&&tt(e8,V),tt(e9,s?.id||""),tt(e7,q?"1":"0");let r=q&&e3(s),l=eT?` ${eT}`:"",a=T.trim(),i=a||(er?er.branch:s?`${s.short||s.label}${l}`:null);t?.(i,!s&&V||null,s,r,n,!a),e?.()};if(!er)return n(E);if(!j?.gitWorktreeAdd){W("This agent version does not support worktrees"),A(!0);return}K(!0),W(null),j.gitWorktreeAdd(er.repo,er.path,er.branch,!0).then(e=>{if(K(!1),!e?.success){W(e?.error||"Failed to create worktree"),A(!0);return}n(e.path||er.path)})},eA=(0,r.useRef)(eP);return((0,r.useEffect)(()=>{eA.current=eP}),(0,r.useEffect)(()=>{let t=t=>{if(!z&&!t.target?.closest?.("[data-wt-form]")){if("Escape"===t.key)t.preventDefault(),t.stopPropagation(),e?.();else if("Enter"===t.key&&"new"===G){if(t.target?.tagName==="BUTTON"){t.target?.getAttribute("role")==="radio"&&(t.preventDefault(),t.stopPropagation(),eA.current());return}if(t.target?.tagName==="SELECT")return;t.preventDefault(),t.stopPropagation(),eA.current()}}};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[z,G,e]),"u"<typeof document)?null:(0,sd.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center px-4 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-150",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},onClick:e,children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-labelledby":"newTerminalTitle",className:"card-elev w-[26rem] max-w-full overflow-hidden flex flex-col my-auto max-h-[min(85%,calc(var(--app-height,85vh)-2rem))] animate-in zoom-in-95 duration-150",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:`px-4 pt-4 space-y-2.5 ${eM?"pb-0":"pb-3"}`,children:[(0,n.jsxs)("div",{className:`flex gap-2 ${ez?"items-stretch -mx-4 px-4 border-b border-border-subtle":"items-center"}`,children:[ez?(0,n.jsx)("div",{role:"tablist",className:"flex-1 min-w-0 flex items-stretch gap-3",children:sK.map(({id:e,icon:t,labelKey:s})=>(0,n.jsxs)("button",{role:"tab","aria-selected":G===e,onClick:()=>{(0,ed.e)(),Y(e)},className:`pb-2 -mb-px flex items-center gap-1.5 text-sm font-semibold border-b-2 transition-colors ${G===e?"text-text border-brand-500":"text-text-muted border-transparent hover:text-text"}`,children:[(0,n.jsx)(t,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:y(s)})]},e))}):(0,n.jsx)("h2",{id:"newTerminalTitle",className:"flex-1 text-sm font-semibold text-text",children:y("terminal.newTerminal")}),(0,n.jsx)("button",{onClick:e,"aria-label":y("common.cancel"),className:"text-text-muted hover:text-text shrink-0 self-center",children:(0,n.jsx)(el.X,{size:18})})]}),i&&!eM&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(sf,{workspacePath:i,workspaceName:o,fileBus:j,homeDir:d,value:E,onChange:e=>$(e),onBrowse:()=>M(!0),staged:er}),P?(0,n.jsxs)("div",{"data-wt-form":!0,className:"space-y-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsxs)("div",{className:"relative flex-1 min-w-0",children:[(0,n.jsx)("input",{type:"text",ref:U,value:I,disabled:F,onChange:e=>D(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),ei()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),ea())},placeholder:y("workspaces.worktreeName"),className:"w-full pl-2.5 pr-7 py-1.5 rounded-brand bg-surface-2 text-xs text-text placeholder-text-subtle border border-border-subtle focus:outline-none focus:border-brand-500"}),I&&!F&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),D(""),U.current?.focus()},"aria-label":y("common.clear"),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-text-subtle hover:text-text rounded transition-colors",children:(0,n.jsx)(el.X,{size:12})})]}),(0,n.jsx)("button",{type:"button",onClick:ei,disabled:!er||F,className:"p-1.5 rounded-brand bg-brand-500 hover:bg-brand-600 text-white transition-colors disabled:opacity-50 disabled:pointer-events-none shrink-0","aria-label":y("workspaces.addWorktree"),children:(0,n.jsx)(el.aJ,{size:12})}),(0,n.jsx)("button",{type:"button",onClick:ea,disabled:F,className:"px-2 py-1.5 rounded-brand text-xs text-text-muted hover:text-text hover:bg-surface-2 transition-colors disabled:opacity-50 shrink-0",children:y("common.cancel")})]}),I.trim()&&!es&&(0,n.jsx)("p",{className:"text-[10px] text-red-500 leading-tight",children:y("workspaces.worktreeNameAscii")}),(0,n.jsx)("p",{className:"truncate text-[10px] text-text-subtle leading-tight",title:er?.path,children:sx(sp(en,es||"…"),d)}),O&&(0,n.jsx)("p",{className:"text-[10px] text-red-500 break-words",children:O})]}):(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),W(null),A(!0),null===_&&j?.gitScanRepos&&j.gitScanRepos(i).then(e=>{let t=e?.success&&e.repos||[];H(t),B(e=>e||t.find(e=>!e.relPath)?.path||t[0]?.path||null)}),requestAnimationFrame(()=>U.current?.focus())},title:er?er.path:void 0,className:"w-full flex items-center gap-1.5 px-2.5 py-1 rounded-brand text-xs transition-colors hover:bg-surface-2",children:[(0,n.jsx)(el.FW,{size:13,className:"shrink-0 text-brand-500"}),er?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"truncate text-text font-medium",children:er.branch}),(0,n.jsx)("span",{className:"truncate text-[10px] text-text-subtle",children:sx(er.path,d)})]}):(0,n.jsx)("span",{className:"text-text-muted",children:y("workspaces.addWorktree")})]})]})]}),eM?(0,n.jsx)(sk,{variant:"list",busRef:a,scope:k,cwd:e$,onResume:t=>{u?.(t),e?.()},onSelectSession:t=>{p?.(t),e?.()},liveSessionIds:x,activeSessionId:m,connected:f}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:Q,role:"radiogroup","aria-label":y("terminal.newTerminal"),className:"flex-1 min-h-0 overflow-y-auto scrollbar-thin px-3 pb-1 grid grid-cols-2 gap-1.5 content-start",children:ek.map((e,t)=>{if(e?.empty)return(0,n.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none select-none"},"__empty_spacer");let s=(e?.id||"")===(ej?.id||"");return(0,n.jsxs)("button",{type:"button",role:"radio","aria-checked":s,tabIndex:s?0:-1,onClick:()=>eS(e),onDoubleClick:()=>eP(e),onKeyDown:e=>((e,t)=>{let s={ArrowRight:1,ArrowLeft:-1,ArrowDown:2,ArrowUp:-2}[e.key];if(void 0===s)return;e.preventDefault();let n=t+s;ek[n]?.empty&&(n+=s>0?1:-1),n=Math.max(0,Math.min(ek.length-1,n)),ek[n]?.empty||(eS(ek[n]),Q.current?.querySelector(`[data-index="${n}"]`)?.focus())})(e,t),"data-picked":s,"data-index":t,className:`modal-row text-left min-w-0 outline-none focus:outline-none focus:ring-0 ${s?"modal-row-active text-text":"text-text-muted hover:text-text"}`,children:[e?.isBrowser?(0,n.jsx)(el.qz,{size:16,className:"text-text"}):(0,n.jsx)(sO,{agent:e}),(0,n.jsx)("span",{className:"flex-1 text-sm font-medium truncate",children:e?e.label:y("terminal.plainShell")}),s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"hidden sm:inline-flex items-center gap-0.5 shrink-0 select-none",children:et.map(e=>(0,n.jsx)("kbd",{className:"inline-flex items-center justify-center px-1 py-0.5 text-[10px] font-mono leading-none rounded bg-surface-3 text-text-muted",children:e},e))}),(0,n.jsx)(el.aJ,{size:14,className:"text-brand-400 shrink-0 sm:hidden"})]})]},e?.id||"__plain")})}),(0,n.jsxs)("div",{className:"px-4 pt-3 pb-4 space-y-3",children:[!ej&&s.length>0&&(0,n.jsx)("select",{value:V,onChange:e=>J(e.target.value),"aria-label":y("terminal.shell"),className:"w-full px-3 py-2 bg-surface-2 rounded-brand text-sm text-text focus:outline-none",children:s.map(e=>(0,n.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,n.jsxs)("label",{className:`flex items-center gap-2 px-0.5 select-none ${eN?"cursor-pointer":"opacity-50 cursor-not-allowed"}`,children:[(0,n.jsx)("input",{type:"checkbox",checked:eN&&q,disabled:!eN,onChange:e=>X(e.target.checked),className:"w-4 h-4 accent-brand-500 cursor-pointer disabled:cursor-not-allowed"}),eC?(0,n.jsx)("code",{className:"min-w-0 text-xs font-mono text-text-muted truncate",children:eC}):(0,n.jsx)("span",{className:"text-xs text-text-muted",children:y("terminal.skipPermissions")})]}),(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("label",{htmlFor:"newTerminalName",className:"block text-[11px] font-medium text-text-muted px-0.5",children:y("terminal.nameLabel")}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{id:"newTerminalName",type:"text",ref:Z,value:T,placeholder:eR,onInput:e=>R(e.target.value),onKeyDown:e=>{"ArrowUp"===e.key&&(e.preventDefault(),Q.current?.querySelector("[data-picked=true]")?.focus())},className:"w-full pl-3 pr-8 py-2 bg-surface-2 rounded-brand text-sm text-text placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40"}),T&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),R(""),Z.current?.focus()},"aria-label":y("common.clear"),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 text-text-subtle hover:text-text rounded transition-colors",children:(0,n.jsx)(el.X,{size:13})})]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:e,className:"flex-1 py-2 text-sm text-text-muted bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors flex items-center justify-center gap-1.5",children:[(0,n.jsx)("span",{children:y("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{onClick:()=>eP(),disabled:F||P&&!er,className:"flex-1 py-2 text-sm font-semibold text-white bg-brand-500 hover:bg-brand-600 rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-60",children:[F?(0,n.jsx)(el.kr,{size:14,className:"animate-spin"}):(0,n.jsx)("span",{children:y("common.create")}),!F&&(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(el.Lt,{size:10,strokeWidth:2.5})})]})]})]})]})]})}),z&&(0,n.jsx)(sD,{fileBus:j,scope:k,initialPath:E||i,onSelect:e=>{M(!1),e&&$(e)},onClose:()=>M(!1)})]}),document.body)}function s_(e,t,s,n=8){let l=(e,t)=>{if(0===e&&0===t)return{left:e,top:t};let s=window.innerWidth,r=window.innerHeight;return{left:e+160>s-n?Math.max(n,e-160):e,top:t+120>r-n?Math.max(n,t-120):t}},[a,i]=(0,r.useState)(()=>l(t,s)),[o,c]=(0,r.useState)({x:t,y:s});return(o.x!==t||o.y!==s)&&(c({x:t,y:s}),i(l(t,s))),(0,r.useEffect)(()=>{let r=e?.current;if(!r||0===t&&0===s)return;let{width:l,height:a}=r.getBoundingClientRect(),o=window.innerWidth,c=window.innerHeight;i({left:t+l>o-n?Math.max(n,t-l):t,top:s+a>c-n?Math.max(n,s-a):s})},[e,t,s,n]),a}async function sH(e,t=1600,s=.8){let n=await createImageBitmap(e),r=Math.min(1,t/Math.max(n.width,n.height)),l=document.createElement("canvas");return l.width=Math.max(1,Math.round(n.width*r)),l.height=Math.max(1,Math.round(n.height*r)),l.getContext("2d").drawImage(n,0,0,l.width,l.height),n.close(),l.toDataURL("image/jpeg",s)}function sU(e){let{t}=(0,eu.s)(),[s,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)(""),o=(0,r.useRef)(null),c=async n=>{let r=n.target.files?.[0];if(n.target.value="",r&&!s)try{(s=>{let n=e?.current;if(!n?.emit)return i(t("menu.bgSaveFailed"));l(!0),i("");let r=!1,a=e=>{r||(r=!0,clearTimeout(o),l(!1),e())},o=setTimeout(()=>a(()=>i(t("menu.bgSaveFailed"))),eJ.Lo);n.emit("bg:save",{dataUrl:s},e=>{a(()=>{if(e?.success&&e.id&&e.dataUrl){let t=`custom:${e.id}`,{customBackgrounds:s,setCustomBackgrounds:n,terminalBackgrounds:r,setTerminalBackgrounds:l}=h.B.getState();n([...s,{id:e.id,dataUrl:e.dataUrl}]),r.includes(t)||l([...r,t]),(0,ed.e)()}else i(e?.error||t("menu.bgSaveFailed"))})})})(await sH(r))}catch{i(t("menu.bgSaveFailed"))}};return{saving:s,error:a,setError:i,fileInput:(0,n.jsx)("input",{ref:o,type:"file",accept:"image/*",className:"hidden",onChange:c}),openPicker:()=>{(0,ed.e)(),s||o.current?.click()}}}let sq="none";function sX({sessionId:e,title:t,onClose:s,busRef:l}){let{t:a}=(0,eu.s)(),i=(0,h.B)(t=>t.backgroundBySession[e]),o=(0,h.B)(e=>e.setSessionBackground),c=(0,h.B)(e=>e.customBackgrounds),d=(0,h.B)(e=>e.terminalBackgrounds),u=(0,h.B)(e=>e.setTerminalBackgrounds),x=(0,h.B)(e=>e.setTerminalBackgroundOpacity),m=(0,h.B)(e=>e.terminalBackgroundOpacity)??eJ._z,[p,f]=(0,r.useState)(!1),{saving:b,error:g,fileInput:v,openPicker:y}=sU(l);if("u"<typeof document)return null;let w=(0,eJ.IJ)(d,c),j=i??null,k=[{key:sq,label:eJ.vk.none.label},...c.map(e=>({key:`custom:${e.id}`,label:a("menu.bgCustomLabel"),src:e.dataUrl})),...Object.entries(eJ.vk).filter(([e])=>e!==sq).map(([e,t])=>({key:e,label:t.label,src:t.src}))];return(0,sd.createPortal)((0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:s}),(0,n.jsxs)("div",{className:"relative w-full max-w-lg max-h-[80vh] card-elev flex flex-col overflow-hidden animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between flex-shrink-0 border-b border-border-subtle",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"w-6 h-6 rounded-full flex items-center justify-center flex-shrink-0 bg-brand-500/15 text-brand-500 dark:bg-white/10 dark:text-white",children:(0,n.jsx)(el.P6,{size:13})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-semibold text-text truncate",children:a("menu.terminalBackground")}),t&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted truncate",children:t})]})]}),(0,n.jsx)("button",{type:"button",onClick:s,className:"p-1 rounded-brand text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex-shrink-0","aria-label":a("common.close"),children:(0,n.jsx)(el.X,{size:16})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable px-4 py-4",children:(0,n.jsx)("div",{className:"grid grid-cols-3 gap-3",children:k.map(({key:t,label:r,src:l})=>{let a=t===sq,i=a?-1:w.indexOf(t),c=p?a?0===w.length:-1!==i:j===t;return(0,n.jsxs)("button",{type:"button",onClick:()=>(t=>{if(!p){o(e,t),s?.();return}t===sq?u([]):u(w.includes(t)?w.filter(e=>e!==t):[...w,t])})(t),className:`relative block w-full aspect-[9/16] rounded-2xl overflow-hidden transition-transform duration-200 ease-out active:scale-[0.97] ${c?"":"hover:-translate-y-0.5"}`,children:[l?(0,n.jsx)("img",{src:l,alt:r,className:"absolute inset-0 h-full w-full object-cover",loading:"lazy"}):(0,n.jsxs)("span",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-surface-2 text-text-muted",children:[(0,n.jsx)(el.P6,{size:22,strokeWidth:1.75}),(0,n.jsx)("span",{className:"text-[11px] font-medium",children:a?eJ.vk.none.label:r})]}),l&&(0,n.jsx)("span",{className:"pointer-events-none absolute inset-0",style:{background:`rgba(0,0,0,${eJ.t})`}}),l&&(0,n.jsx)("span",{className:"absolute inset-x-0 bottom-0 h-1/3 bg-gradient-to-t from-black/70 to-transparent"}),l&&(0,n.jsx)("span",{className:"absolute bottom-1.5 inset-x-0 px-2 text-[11px] font-medium text-white truncate text-center",children:r}),(0,n.jsx)("span",{className:`pointer-events-none absolute inset-0 rounded-2xl ${c?"ring-1 ring-inset ring-brand-500 dark:ring-white/60":"ring-1 ring-inset ring-white/15"}`}),p&&c&&!a&&(0,n.jsx)("span",{className:"absolute top-1.5 right-1.5 flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[11px] font-semibold shadow-lg",children:i+1})]},t??"global")})})}),(0,n.jsxs)("div",{className:"flex-shrink-0 border-t border-border-subtle px-4 py-3 flex items-center gap-3",children:[(0,n.jsx)("span",{className:"text-xs text-text flex-shrink-0",children:a("menu.bgDim")}),(0,n.jsx)("input",{type:"range",min:eJ.DW.min,max:eJ.DW.max,step:eJ.DW.step,value:m,onChange:e=>x(Number(e.target.value)),className:"brand-range flex-1 min-w-0",style:{"--pct":`${(m-eJ.DW.min)/(eJ.DW.max-eJ.DW.min)*100}%`},"aria-label":a("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums flex-shrink-0",children:[Math.round(100*m),"%"]})]}),(0,n.jsxs)("div",{className:"flex-shrink-0 border-t border-border-subtle px-4 py-2.5 flex items-center gap-3",children:[(0,n.jsxs)("label",{className:"flex items-center gap-2.5 cursor-pointer min-w-0",children:[(0,n.jsx)("input",{type:"checkbox",checked:p,onChange:e=>f(e.target.checked),className:"accent-brand-500 w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs text-text truncate",children:a("menu.bgApplyAll")})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{type:"button",onClick:y,disabled:b,className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-brand border border-border-subtle text-xs text-text-muted hover:text-brand-500 hover:border-brand-500 transition-colors disabled:opacity-40 flex-shrink-0",children:[b?(0,n.jsx)(el.kr,{size:13,className:"animate-spin"}):(0,n.jsx)(el.FW,{size:13}),a("menu.bgAdd")]})]}),g&&(0,n.jsx)("div",{className:"flex-shrink-0 px-4 pb-3",children:(0,n.jsx)("div",{className:"px-3 py-2 rounded-brand bg-red-500/10 border border-red-500/30 text-red-500 text-xs break-all",children:g})})]}),v]}),document.body)}let sV={y:{pos:"clientY",start:"top",size:"height"},x:{pos:"clientX",start:"left",size:"width"}};function sJ({axis:e="y",threshold:t=12,onCommit:s}){let[n,l]=(0,r.useState)(null),a=(0,r.useRef)(new Map),i=(0,r.useRef)(!1),o=(0,r.useRef)(null),c=(0,r.useRef)(null),d=(0,r.useCallback)(e=>t=>{t?a.current.set(e,t):a.current.delete(e)},[]),u=(0,r.useCallback)(()=>{let e=i.current;return i.current=!1,o.current&&(clearTimeout(o.current),o.current=null),e},[]);return{dragId:n,registerEl:d,startDrag:(0,r.useCallback)((n,r,d)=>{if("mouse"===n.pointerType&&0!==n.button||(c.current?.(!1),i.current=!1,o.current&&(clearTimeout(o.current),o.current=null),!d||d.length<2))return;let u=d.indexOf(r);if(u<0)return;let x=sV[e],m=d.map(e=>{let t=a.current.get(e)?.getBoundingClientRect();return t?{start:t[x.start],size:t[x.size]}:null});if(m.some(e=>!e))return;i.current=!1,o.current&&(clearTimeout(o.current),o.current=null);let p=m[u],f=n[x.pos],h=u,b=null,g=s=>{if("mouse"===s.pointerType&&0===s.buttons)return void y();let n=s[x.pos]-f;if(!i.current){if(Math.abs(n)<t)return;i.current=!0,(0,ed.e)(),l(r)}let o=p.start+p.size/2+n,c=0;for(let e=0;e<m.length;e++)o>=m[e].start&&(c=e);h=c,b||(b=requestAnimationFrame(()=>{let t;return b=null,void((t=a.current.get(r))&&(t.style.transform=`translate${e.toUpperCase()}(${n}px)`),d.forEach((t,s)=>{if(t===r)return;let n=a.current.get(t);if(!n)return;let l=0;u<h&&s>u&&s<=h?l=-p.size:u>h&&s>=h&&s<u&&(l=p.size),n.style.transform=l?`translate${e.toUpperCase()}(${l}px)`:""}))}))},v=e=>{for(let e of(window.removeEventListener("pointermove",g),window.removeEventListener("pointerup",y),window.removeEventListener("pointercancel",y),window.removeEventListener("blur",y),c.current=null,b&&(cancelAnimationFrame(b),b=null),a.current.values()))e&&(e.style.transform="");if(l(null),!e||!i.current||(o.current=setTimeout(()=>{o.current=null,i.current=!1},0),h===u))return;let t=[...d];t.splice(h,0,t.splice(u,1)[0]),(0,ed.e)(),s?.(t)},y=()=>v(!0);c.current=v,window.addEventListener("pointermove",g,{passive:!1}),window.addEventListener("pointerup",y),window.addEventListener("pointercancel",y),window.addEventListener("blur",y)},[e,t,s]),consumeClick:u}}var sG=s(48310),sY=s(38415);let sZ="sm:h-8",sQ=(0,r.memo)(function({bus:e}){let[t,s]=(0,r.useState)([]),[l,a]=(0,r.useState)(""),[i,o]=(0,r.useState)(!1),c=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!e?.emit)return;e.emit("jarvis:chatHistory",{},e=>{e?.ok&&s(function(e=[]){let t=[];for(let s of e)for(let e of s?.parts||[])"string"==typeof e?.text&&e.text?t.push({type:"user"===s.role?"user":"assistant",text:e.text}):e?.functionCall?t.push({type:"tool",name:e.functionCall.name,args:e.functionCall.args||{}}):e?.functionResponse&&t.push({type:"toolResult",name:e.functionResponse.name,text:JSON.stringify(e.functionResponse.response||{}).slice(0,300)});return t.slice(-80)}(e.history))});let t=e=>{e?.type==="assistant"&&o(!1),e?.type&&"user"!==e.type&&s(t=>[...t.slice(-160),e])};return e.on?.("jarvis:chat:event",t),()=>e.off?.("jarvis:chat:event",t)},[e]),(0,r.useEffect)(()=>{c.current?.scrollTo?.({top:c.current.scrollHeight})},[t]);let d=()=>{let t=l.trim();t&&!i&&e?.emit&&((0,ed.e)(),a(""),o(!0),e.emit("jarvis:chat",{text:t},e=>{o(!1),e?.error&&s(t=>[...t,{type:"error",text:e.error}])}))};return(0,n.jsxs)("div",{className:"h-full flex flex-col min-h-0",children:[(0,n.jsxs)("div",{ref:c,className:"flex-1 min-h-0 overflow-y-auto modal-scrollable px-3 py-3 flex flex-col gap-2.5",children:[0===t.length&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-text-muted p-4",children:[(0,n.jsx)(el.cC,{size:28,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-xs text-center leading-relaxed",children:"Chat to coordinate — e.g. “create a demo task in 9router”, “who is free?”, “what is that worker doing?”"})]}),t.map((e,t)=>"user"===e.type?(0,n.jsx)("div",{className:"self-end max-w-[85%] px-3 py-1.5 rounded-brand-lg rounded-br-sm bg-brand-500/15 text-sm text-text whitespace-pre-wrap break-words",children:e.text},t):"assistant"===e.type?(0,n.jsx)("div",{className:"self-start max-w-[85%] px-3 py-1.5 rounded-brand-lg rounded-bl-sm bg-surface-2 text-sm text-text whitespace-pre-wrap break-words",children:e.text},t):"error"===e.type?(0,n.jsx)("div",{className:"self-start max-w-[85%] px-3 py-1.5 rounded-brand bg-red-500/10 text-xs text-red-400 break-words",children:e.text},t):(0,n.jsxs)("div",{className:"self-start max-w-[85%] px-2 py-1 rounded-brand bg-surface-2/50 border border-border-subtle/60 text-[10px] font-mono text-text-muted break-words",children:[(0,n.jsx)("span",{className:"text-brand-400",children:e.name}),"tool"===e.type?`(${JSON.stringify(e.args).slice(0,120)})`:` → ${String(e.text||"").slice(0,200)}`]},t)),i&&(0,n.jsx)("div",{className:"self-start px-3 text-[11px] text-text-muted animate-pulse",children:"Jarvis is thinking…"})]}),(0,n.jsxs)("div",{className:"flex-shrink-0 border-t border-border-subtle p-2 flex items-end gap-2",children:[(0,n.jsx)("textarea",{value:l,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),d())},rows:1,placeholder:"Delegate to Jarvis…",className:"flex-1 resize-none max-h-32 px-3 py-2 rounded-brand bg-surface-2/40 border border-border-subtle text-sm text-text placeholder:text-text-muted/60 outline-none focus:border-brand-500/60 transition-colors"}),(0,n.jsx)("button",{type:"button",onClick:d,disabled:i||!l.trim(),className:"p-2 rounded-brand bg-brand-500/15 text-brand-400 hover:bg-brand-500/25 disabled:opacity-40 disabled:cursor-not-allowed transition-colors","aria-label":"Send",children:i?(0,n.jsx)(el.M6,{size:14}):(0,n.jsx)(el.Vn,{size:14})})]})]})}),s0=["todo","in_progress","needs_input","done"],s1={enabled:!0,llmProvider:"gemini",llmBaseUrl:"",llmKey:"",agentModel:"gemini-3.8-flash",boardScope:"workspace",wakeOnDone:!0,liveKey:"",liveModel:"gemini-3.8-live",liveVoice:"Puck"},s2=[{id:"gemini",label:"Google Gemini",baseUrlHint:"https://generativelanguage.googleapis.com (default)",models:["gemini-3.8-flash","gemini-2.5-flash","gemini-2.5-pro"]},{id:"openai",label:"OpenAI-compatible",baseUrlHint:"https://openrouter.ai/api/v1 (default)",models:["openai/gpt-5","anthropic/claude-sonnet-5","google/gemini-3.8-flash"]},{id:"anthropic",label:"Anthropic",baseUrlHint:"https://api.anthropic.com (default)",models:["claude-sonnet-5","claude-haiku-4-5"]}],s5="jarvisSettings",s3=["Puck","Charon","Kore","Fenrir","Aoede","Leda"],s4={tasks:{}},s6=(0,b.v)((e,t)=>({board:s4,sink:null,applyBoard:t=>e({board:t?.tasks?t:s4}),setSink:t=>e({sink:"function"==typeof t?t:null}),moveTask:(s,n)=>{let r=t().board.tasks[s];r&&s0.includes(n)&&(e({board:{tasks:{...t().board.tasks,[s]:{...r,status:n,updatedAt:Date.now()}}}}),t().sink?.({type:"move",taskId:s,status:n}))},deleteTask:s=>{if(!t().board.tasks[s])return;let n={...t().board.tasks};delete n[s],e({board:{tasks:n}}),t().sink?.({type:"delete",taskId:s})}})),s8=(0,b.v)((e,t)=>({open:!1,settings:{...s1},setOpen:t=>e({open:!!t}),toggle:()=>e(e=>({open:!e.open})),hydrateSettings:()=>{let t;return e({settings:(!(t={...s1,...(()=>{try{let e=JSON.parse(localStorage.getItem(s5));return e&&"object"==typeof e?e:{}}catch{return{}}})()}).llmKey&&t.liveKey&&(t.llmKey=t.liveKey),t)})},setSettings:s=>{let n={...t().settings,...s&&"object"==typeof s?s:{}};try{localStorage.setItem(s5,JSON.stringify(n))}catch{}e({settings:n})}}));s8.getState().hydrateSettings();let s9={todo:{label:"Todo",cls:"text-text-muted",dot:"bg-text-muted/60"},in_progress:{label:"In Progress",cls:"text-sky-400",dot:"bg-sky-400"},needs_input:{label:"Needs Input",cls:"text-amber-400",dot:"bg-amber-400"},done:{label:"Done",cls:"text-emerald-400",dot:"bg-emerald-400"}},s7={needs_input:"border-amber-500/60 animate-pulse",done:"border-border-subtle/60 opacity-70"};function ne({task:e,prev:t,next:s,showWorkspace:r}){let l=s6(e=>e.moveTask),a=s6(e=>e.deleteTask),i=r&&e.workspace?String(e.workspace).split("/").filter(Boolean).pop():"";return(0,n.jsxs)("div",{className:`group relative p-2 rounded-brand border border-border-subtle/80 bg-surface-2/80 text-xs shadow-sm
7
+ transition-all duration-150 ease-out hover:bg-surface-3/60 hover:border-border/80 hover:-translate-y-px
8
+ animate-in fade-in slide-in-from-bottom-1 duration-150 ${s7[e.status]||""}`,children:[(0,n.jsx)("div",{className:"pr-4 font-medium text-text break-words",children:e.title}),(e.engine||e.branch||i)&&(0,n.jsxs)("div",{className:"mt-1 flex items-center gap-1.5 flex-wrap text-[10px] text-text-muted",children:[i&&(0,n.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-brand-500/10 text-brand-400 truncate max-w-[110px]",title:e.workspace,children:i}),e.engine&&(0,n.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-surface-3/60 font-mono truncate max-w-[110px]",children:e.engine}),e.branch&&(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 min-w-0",children:[(0,n.jsx)(el.Zr,{size:9,className:"shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.branch})]})]}),e.sessionId&&!e.auto&&(0,n.jsx)("div",{className:"mt-1 text-[9px] font-mono text-text-muted/70 truncate",children:e.sessionId}),e.question&&(0,n.jsx)("div",{className:"mt-1 text-[10px] leading-relaxed text-amber-400/90 line-clamp-3",children:e.question}),e.summary&&(0,n.jsx)("div",{className:"mt-1 text-[10px] leading-relaxed text-text-muted line-clamp-3",children:e.summary}),!e.auto&&(0,n.jsxs)("div",{className:"absolute top-1 right-1 flex items-center gap-0.5 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 sm:focus-within:opacity-100 transition-opacity",children:[t&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),l(e.id,t)},"aria-label":"Move left",className:"p-0.5 rounded text-text-muted hover:text-text hover:bg-surface-3",children:(0,n.jsx)(el.JG,{size:12})}),s&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),l(e.id,s)},"aria-label":"Move right",className:"p-0.5 rounded text-text-muted hover:text-text hover:bg-surface-3",children:(0,n.jsx)(el.c_,{size:12})}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),a(e.id)},"aria-label":"Delete task",className:"p-0.5 rounded text-text-muted hover:text-red-400 hover:bg-surface-3",children:(0,n.jsx)(el.X,{size:12})})]})]})}let nt=(0,r.memo)(function({workspacePath:e=""}){let t=s6(e=>e.board.tasks),s=s8(e=>e.settings.boardScope),l=s8(e=>e.setSettings),a="all"===s,i=(0,r.useMemo)(()=>a?t:((e={},t="")=>{let s={};for(let[n,r]of Object.entries(e))r?.workspace&&r.workspace!==t||(s[n]=r);return s})(t,e),[t,e,a]),o=(0,r.useMemo)(()=>((e={})=>{let t=Object.fromEntries(s0.map(e=>[e,[]]));for(let s of Object.values(e))(t[s.status]||t.todo).push(s);return t})(i),[i]),c=Object.keys(i).length;return(0,n.jsxs)("div",{className:"h-full flex flex-col min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-2 pt-2 pb-1 flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-[10px] font-mono uppercase tracking-wider text-text-muted",children:[c," cards"]}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),l({boardScope:a?"workspace":"all"})},className:`ml-auto text-[10px] px-2 py-0.5 rounded-full border transition-colors ${a?"border-brand-500/50 text-brand-400 bg-brand-500/10":"border-border-subtle text-text-muted hover:text-text"}`,title:a?"Showing cards from every workspace":"Showing cards from this workspace only",children:a?"All workspaces":"This workspace"})]}),!a&&Object.keys(t).length>c&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),l({boardScope:"all"})},className:"mx-2 mb-1 text-left text-[10px] text-text-muted/80 hover:text-text-muted flex-shrink-0",children:["+",Object.keys(t).length-c," cards in other workspaces — tap to show all"]}),c?(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-x-auto overflow-y-auto custom-scrollbar p-2 pt-1",children:(0,n.jsx)("div",{className:"min-w-[560px] h-full grid gap-2",style:{gridTemplateColumns:`repeat(${s0.length}, minmax(0, 1fr))`},children:s0.map(e=>{let t=s9[e]||{label:e,cls:"text-text-muted",dot:"bg-text-muted/60"},s=o[e]||[],r=s0.indexOf(e),l=s0[Math.max(0,r-1)],i=s0[Math.min(s0.length-1,r+1)];return(0,n.jsxs)("section",{className:"min-w-0 flex flex-col gap-1.5 bg-surface-2/30 rounded-brand-lg p-1.5","aria-label":`${t.label} column`,children:[(0,n.jsxs)("h4",{className:`flex items-center gap-1.5 px-1 pt-0.5 text-[10px] font-semibold uppercase tracking-wider ${t.cls}`,children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${t.dot}`}),(0,n.jsx)("span",{className:"truncate",children:t.label}),(0,n.jsx)("span",{className:"ml-auto px-1.5 py-px rounded-full bg-surface-3/60 text-[9px] font-mono text-text-muted",children:s.length})]}),(0,n.jsx)("div",{className:"flex-1 flex flex-col gap-1.5",children:s.map(t=>(0,n.jsx)(ne,{task:t,showWorkspace:a,prev:"todo"===e?null:l,next:"done"===e?null:i},t.id))})]},e)})})}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-text-muted p-6",children:[(0,n.jsx)(el.y8,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:"Nothing on the board."}),(0,n.jsx)("span",{className:"text-xs text-center leading-relaxed",children:"Open sessions land here automatically; ask Jarvis — “create 2 tasks: API login and UI login” — to add work."})]})]})}),ns=(0,r.memo)(function({icon:e,iconClass:t="text-text",title:s,subtitle:l,maxWidth:a="max-w-lg",onClose:i,actions:o=null,children:c,footer:d=null}){let u=(0,r.useRef)(null);return(0,r.useEffect)(()=>{u.current?.contains(document.activeElement)||u.current?.focus()},[]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),i?.())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i]),(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4 select-none",onClick:e=>{e.target===e.currentTarget&&i?.()},children:(0,n.jsxs)("div",{ref:u,tabIndex:-1,className:`card-elev w-full ${a} overflow-hidden flex flex-col max-h-[80%] animate-in fade-in zoom-in-95 duration-150 outline-none`,role:"dialog","aria-modal":"true",children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center justify-between shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 min-w-0",children:[e&&(t?(0,n.jsx)("div",{className:`w-6 h-6 rounded-full flex items-center justify-center shrink-0 ${t}`,children:e}):(0,n.jsx)("div",{className:"flex items-center justify-center shrink-0 text-text",children:e})),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-semibold text-text truncate",children:s}),l&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted truncate",children:l})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[o,(0,n.jsx)("button",{type:"button",onClick:i,className:"p-1 rounded-brand text-text-muted hover:text-text hover:bg-surface-2 transition-colors shrink-0",children:(0,n.jsx)(el.X,{size:16})})]})]}),c,d]})})}),nn="w-full px-3 py-2 rounded-brand bg-surface-2/40 border border-border-subtle text-sm text-text placeholder:text-text-muted/60 outline-none focus:border-brand-500 transition-colors",nr="text-[11px] text-text-muted px-1";function nl({title:e,summary:t,ok:s,open:r,onToggle:l,children:a}){return(0,n.jsxs)("div",{className:`rounded-brand border overflow-hidden transition-colors ${r?"border-brand-500/40":"border-border-subtle"} bg-surface-2/20`,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),l()},className:"w-full px-3 py-2.5 flex items-center gap-2 text-left",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${s?"bg-emerald-400":"bg-text-muted/40"}`}),(0,n.jsx)("span",{className:"text-sm text-text flex-1 min-w-0 truncate",children:e}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate max-w-[45%]",children:t}),(0,n.jsx)(el.yQ,{size:14,className:`text-text-muted flex-shrink-0 transition-transform ${r?"rotate-180":""}`})]}),r&&(0,n.jsx)("div",{className:"px-2.5 pb-2.5 pt-2 border-t border-border-subtle/60 flex flex-col gap-1.5",children:a})]})}function na({label:e,hint:t,value:s,onChange:r}){return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),r(!s)},className:"w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"block truncate",children:e}),(0,n.jsx)("span",{className:"block text-xs text-text-muted truncate",children:t})]}),(0,n.jsx)("span",{className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${s?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-0.5"}`})})]})}let ni=(0,r.memo)(function({busRef:e}){let t=s8(e=>e.settings),s=s8(e=>e.setSettings),[l,a]=(0,r.useState)(""),i=s2.find(e=>e.id===t.llmProvider)||s2[0],o=n=>{s(n);let r={...t,...n};e?.current?.emit?.("jarvis:agentConfig",{provider:r.llmProvider,baseUrl:r.llmBaseUrl,apiKey:r.llmKey,model:r.agentModel,wake:r.wakeOnDone})};return(0,n.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,n.jsxs)(nl,{title:"Chat LLM",summary:`${i.label} \xb7 ${t.agentModel||""}`,ok:!!t.llmKey,open:"llm"===l,onToggle:()=>a("llm"===l?"":"llm"),children:[(0,n.jsx)("span",{className:nr,children:"Endpoint"}),(0,n.jsx)("input",{type:"text",value:t.llmBaseUrl||"",onChange:e=>o({llmBaseUrl:e.target.value}),placeholder:i.baseUrlHint,autoComplete:"off",spellCheck:!1,className:nn}),(0,n.jsx)("span",{className:nr,children:"API key"}),(0,n.jsx)("input",{type:"password",value:t.llmKey||"",onChange:e=>o({llmKey:e.target.value}),placeholder:"sk-…",autoComplete:"off",spellCheck:!1,className:nn}),(0,n.jsx)("span",{className:nr,children:"Model"}),(0,n.jsx)("input",{type:"text",value:t.agentModel||"",onChange:e=>o({agentModel:e.target.value}),placeholder:i.models[0],autoComplete:"off",spellCheck:!1,className:nn}),(0,n.jsx)("span",{className:nr,children:"Format — must match the endpoint above"}),(0,n.jsx)("select",{value:t.llmProvider,onChange:e=>{var s;(0,ed.e)(),(s=e.target.value)!==t.llmProvider&&o({llmProvider:s})},className:"w-full px-3 py-2 rounded-brand bg-surface-2/40 border border-border-subtle text-sm text-text outline-none focus:border-brand-500",children:s2.map(e=>(0,n.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,n.jsxs)(nl,{title:"Live voice",summary:t.liveKey?`${t.liveModel||"gemini-3.8-live"} \xb7 ${t.liveVoice||"Puck"}`:"no key",ok:!!t.liveKey,open:"live"===l,onToggle:()=>a("live"===l?"":"live"),children:[(0,n.jsx)("input",{type:"password",value:t.liveKey||"",onChange:e=>s({liveKey:e.target.value}),placeholder:"Google AI API key",autoComplete:"off",spellCheck:!1,className:nn}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:t.liveModel||"",onChange:e=>s({liveModel:e.target.value}),placeholder:"gemini-3.8-live",autoComplete:"off",spellCheck:!1,className:`${nn} flex-1 min-w-0`}),(0,n.jsx)("select",{value:t.liveVoice||"Puck",onChange:e=>s({liveVoice:e.target.value}),className:"w-24 shrink-0 px-2 py-2 rounded-brand bg-surface-2/40 border border-border-subtle text-sm text-text outline-none focus:border-brand-500",children:s3.map(e=>(0,n.jsx)("option",{value:e,children:e},e))})]}),(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-text-muted px-1",children:"Talk to delegate work — billed per minute of audio."})]}),(0,n.jsx)(na,{label:"Wake on worker done",hint:"Jarvis checks the fleet and updates the board",value:t.wakeOnDone,onChange:e=>o({wakeOnDone:e})})]})}),no=(0,r.memo)(function({busRef:e,onClose:t}){return(0,n.jsx)(ns,{icon:(0,n.jsx)(el.wB,{size:14}),title:"Jarvis Settings",subtitle:"Coordinator harness and behavior",maxWidth:"max-w-sm",onClose:t,children:(0,n.jsx)("div",{className:"p-3",children:(0,n.jsx)(ni,{busRef:e})})})});function nc({busRef:e,fileBus:t=null,workspacePath:l="",onClose:a}){let i=s8(e=>e.settings),o=s6(e=>e.applyBoard),c=s6(e=>e.setSink),[d,u]=(0,r.useState)(!1),[x,m]=(0,r.useState)(!0),[p,f]=(0,r.useState)(null);(0,r.useEffect)(()=>{f(e?.current??null)},[e]);let h=function({busRef:e,apiKey:t,voice:n,model:l}){let[a,i]=(0,r.useState)("idle"),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)([]),[x,m]=(0,r.useState)(0),p=(0,r.useCallback)((e,t)=>{t&&u(s=>[...s.slice(-40),{who:e,text:String(t).slice(0,400)}])},[]),f=(0,r.useRef)({}),h=(0,r.useCallback)(()=>{let e=f.current;f.current={},e?.levelProbe&&clearTimeout(e.levelProbe);try{e.session?.close?.()}catch{}for(let t of e.playing||[])try{t.stop()}catch{}e.processor?.disconnect?.(),e.mute?.disconnect?.(),e.stream?.getTracks?.().forEach(e=>e.stop());try{e.inCtx?.close()}catch{}try{e.outCtx?.close()}catch{}i("idle")},[]);(0,r.useEffect)(()=>h,[h]);let b=(0,r.useCallback)(async()=>{if(!t){c("Add a Google AI key in Jarvis settings first"),i("error");return}h(),c(""),u([]),m(0),i("connecting");let r=(t,s)=>new Promise(n=>{let r=!1,l=e=>{r||(r=!0,n(e))},a=setTimeout(()=>l({ok:!1,error:"agent timeout — restart the agent?"}),5e3);try{e.current?.emit?.(t,s,e=>{clearTimeout(a),l(e)})}catch(e){clearTimeout(a),l({ok:!1,error:e?.message||"bus unavailable"})}});try{let[{GoogleGenAI:e,Modality:o},d]=await Promise.all([Promise.all([s.e(1226),s.e(2847)]).then(s.bind(s,10913)),r("jarvis:tools",{})]),u=function(e=[]){return e.filter(e=>e?.name&&e?.description).map(({name:e,description:t,inputSchema:s})=>({name:e,description:t,...s?{parameters:function e(t){if(Array.isArray(t))return t.map(e);if(t&&"object"==typeof t){let s={};for(let[n,r]of Object.entries(t))s[n]="type"===n&&"string"==typeof r?r.toUpperCase():e(r);return s}return t}(s)}:{}}))}(d?.tools||[]);u.length||p("tool",`no coordinator tools (${d?.error||"empty manifest"}) — voice only; restart the agent to get tools`);let x=await navigator.mediaDevices.getUserMedia({audio:!0}),b=new AudioContext({sampleRate:16e3});await b.resume?.().catch?.(()=>{});let g=b.createMediaStreamSource(x),v=b.createScriptProcessor(1024,1,1),y=b.createGain();y.gain.value=0,g.connect(v),v.connect(y),y.connect(b.destination);let w=f.current;w.stream=x,w.inCtx=b,w.processor=v,w.mute=y,w.playing=[],w.maxLevel=0,w.levelProbe=setTimeout(()=>{f.current===w&&!w.speechSeen&&(0===w.maxLevel?p("tool","no mic signal — check microphone permission"):w.maxLevel<.03&&p("tool",`mic very quiet (peak ${w.maxLevel.toFixed(3)} < threshold 0.03) — speak up or move closer`))},3e3),w.levelProbe.unref?.();let j=new e({apiKey:t}),k=await j.live.connect({model:l||"gemini-3.8-live",callbacks:{onmessage:e=>(function(e){let t=f.current,s=e?.usageMetadata?.totalTokenCount;for(let t of(s>0&&m(e=>Math.max(e,s)),e?.serverContent?.modelTurn?.parts||[])){let s=t?.inlineData?.data;s&&(e.serverContent.interrupted||function(e){let t=f.current;t.outCtx||(t.outCtx=new AudioContext({sampleRate:24e3}));let s=t.outCtx,n=atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);let l=new Int16Array(r.buffer),a=new Float32Array(l.length);for(let e=0;e<l.length;e++)a[e]=l[e]/32768;let i=s.createBuffer(1,a.length,24e3);i.copyToChannel(a,0);let o=s.createBufferSource();o.buffer=i;let c=Math.max(s.currentTime+.02,t.nextAt||0);t.nextAt=c+i.duration,o.onended=()=>{t.playing=(t.playing||[]).filter(e=>e!==o)},o.connect(s.destination),o.start(c),t.playing.push(o)}(s))}if(e.serverContent?.interrupted){for(let e of t.playing||[])try{e.stop()}catch{}t.playing=[]}let n=e?.serverContent?.inputTranscription?.text,r=e?.serverContent?.outputTranscription?.text;n&&p("user",n),r&&p("jarvis",r);let l=e?.toolCall?.functionCalls;l?.length&&f.current.session&&Promise.all(l.map(e=>({fc:e,p:a(e)})).map(({fc:e,p:t})=>t.then(t=>({id:e.id,name:e.name,response:{result:t?.ok?t.result||"ok":`error: ${t?.error||"no answer"}`}})))).then(e=>{try{f.current.session?.sendToolResponse({functionResponses:e})}catch{}})})(e),onerror:e=>{c(e?.message||"live connection error"),i("error")},onclose:()=>i(e=>"idle"===e?e:"idle")},config:{responseModalities:[o.AUDIO],systemInstruction:"You are Jarvis, the conductor coordinating AI agents (claude, codex, opencode) on the user's machine. The user talks to you to delegate work and ask about status. Rules: call list_fleet before delegating to see which session is free; delegate with dispatch_prompt to an existing session, or create_session to open a new one (pass the workspace taken from list_fleet's workspacePath); record every job on the board with manage_kanban; when an agent asks or requests permission, use resolve_gate per the user's intent; to see what a worker printed, read_terminal. Reply BRIEFLY in the user's language, natural spoken style — never read out raw JSON.",speechConfig:{voiceConfig:{prebuiltVoiceConfig:{voiceName:n||"Puck"}}},tools:[{functionDeclarations:u}],contextWindowCompression:{triggerTokens:12e3,slidingWindow:{targetTokens:6e3}},inputAudioTranscription:{},outputAudioTranscription:{}}});if(w.session=k,!f.current.session)return h();let N=function({sendChunk:e,sendStreamEnd:t,now:s=()=>Date.now()}){let n=[],r=!1,l=0,a=!0;return{onChunk(i,o){let c=s(),d=o>=.03;if(d&&(l=c),d&&!r)for(let t of(r=!0,a=!1,n))e(t);if(n.push(i),n.length>5&&n.shift(),r){if(c-l>=1e3){r=!1;return}if(!a&&c-l>=500){a=!0;try{t()}catch{}}e(i)}}}}({sendChunk:e=>{try{k.sendRealtimeInput({media:new Blob([e],{type:"audio/pcm;rate=16000"})})}catch{}},sendStreamEnd:()=>k.sendRealtimeInput({audioStreamEnd:!0})});v.onaudioprocess=e=>{if(f.current.session!==k)return;let t=e.inputBuffer.getChannelData(0),s=0,n=new Int16Array(t.length);for(let e=0;e<t.length;e++){let r=Math.max(-1,Math.min(1,t[e]));s+=Math.abs(r),n[e]=r<0?32768*r:32767*r}let r=s/t.length;r>(w.maxLevel||0)&&(w.maxLevel=r),r>=.03&&(w.speechSeen=!0),N.onChunk(n,r)},i("live")}catch(e){h(),c(e?.message||String(e)),i("error")}async function a(e){p("tool",`${e.name}(${JSON.stringify(e.args||{})})`);let t=await r("jarvis:tool",{name:e.name,args:e.args||{}});return p("tool",`${e.name} → ${t?.ok?String(t.result).slice(0,200):t?.error}`),t}},[t,n,l,h,p,e]);return{status:a,error:o,entries:d,tokens:x,start:b,stop:h}}({busRef:e,apiKey:i.liveKey,voice:i.liveVoice,model:i.liveModel});return(0,r.useEffect)(()=>{let t=e?.current;if(!t?.emit||!t?.on)return;let s=()=>t.emit("jarvis:getState",{},e=>{e?.ok&&o(e.board)});s();let n=setInterval(s,5e3),r=e=>o(e);return t.on("jarvis:kanban",r),c(e=>t.emit("jarvis:kanban",{action:e})),()=>{clearInterval(n),t.off?.("jarvis:kanban",r),c(null)}},[e,o,c]),(0,r.useEffect)(()=>{p?.emit?.("jarvis:agentConfig",{provider:i.llmProvider,baseUrl:i.llmBaseUrl,apiKey:i.llmKey,model:i.agentModel,wake:i.wakeOnDone})},[p,i.llmProvider,i.llmBaseUrl,i.llmKey,i.agentModel,i.wakeOnDone]),(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||d||(e.preventDefault(),a?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[a,d]),(0,n.jsxs)("div",{className:"fixed inset-0 z-50 bg-bg/95 backdrop-blur-sm flex flex-col animate-in fade-in duration-150",children:[(0,n.jsxs)("header",{className:"h-12 px-3 flex items-center gap-2 border-b border-border-subtle flex-shrink-0 bg-bg/80 backdrop-blur-sm",children:[(0,n.jsx)(el.cC,{size:18,className:"text-brand-500 shrink-0"}),(0,n.jsx)("h2",{className:"text-sm font-semibold text-text flex-1 min-w-0 truncate",children:"Jarvis Coordinator"}),i.liveKey&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),"idle"===h.status||"error"===h.status?h.start():h.stop()},className:`relative p-1.5 rounded-brand transition-colors ${"live"===h.status?"text-red-500":"text-text-muted"} hover:text-text hover:bg-surface-2`,"aria-label":"Live voice",title:"live"===h.status?"End live voice":"Live voice — talk to delegate work (Gemini 3.8 Live)",children:[(0,n.jsx)(el.GO,{size:16}),"live"===h.status&&(0,n.jsx)("span",{className:"absolute top-0.5 right-0.5 w-1.5 h-1.5 rounded-full bg-red-500 animate-pulse"})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),m(e=>!e)},className:`p-1.5 rounded-brand transition-colors ${x?"text-text":"text-text-muted"} hover:text-text hover:bg-surface-2`,"aria-label":x?"Hide board":"Show board",title:x?"Hide board":"Show board",children:x?(0,n.jsx)(el.ue,{size:16}):(0,n.jsx)(el.e6,{size:16})}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),u(!0)},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":"Jarvis settings",title:"Jarvis settings",children:(0,n.jsx)(el.wB,{size:16})}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),a?.()},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":"Close",children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col lg:flex-row",children:[x&&(0,n.jsx)("div",{className:"lg:w-[58%] h-[42%] lg:h-full min-h-0 bg-bg border-b lg:border-b-0 lg:border-r border-border-subtle lg:shadow-[6px_0_12px_-6px_rgba(0,0,0,0.15)] lg:relative lg:z-10 animate-in fade-in slide-in-from-left duration-200",children:(0,n.jsx)(nt,{workspacePath:l})}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(sQ,{bus:p})})]}),d&&(0,n.jsx)(no,{busRef:e,onClose:()=>u(!1)}),"idle"!==h.status&&(0,n.jsx)("div",{className:"absolute bottom-3 left-3 right-3 z-20 max-w-md ml-auto pointer-events-none",children:(0,n.jsxs)("div",{className:"pointer-events-auto rounded-brand-lg border border-border-subtle bg-surface/95 backdrop-blur-sm shadow-xl p-2.5 max-h-52 flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 pb-1.5 mb-1 border-b border-border-subtle/60",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full ${"live"===h.status?"bg-red-500 animate-pulse":"bg-amber-400 animate-pulse"}`}),(0,n.jsxs)("span",{className:"text-xs font-medium text-text flex-1",children:["Live ","connecting"===h.status?"— connecting…":"— listening"]}),h.tokens>0&&(0,n.jsxs)("span",{className:"text-[10px] text-text-muted font-mono",title:"Context tokens — the number the bill compounds on",children:[(h.tokens/1e3).toFixed(1),"k tok"]}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),h.stop()},className:"text-xs text-text-muted hover:text-text px-1.5 py-0.5 rounded-brand",children:"End"})]}),h.error&&(0,n.jsx)("p",{className:"text-[11px] text-red-400 px-0.5 pb-1",children:h.error}),(0,n.jsxs)("div",{className:"overflow-y-auto modal-scrollable flex flex-col gap-1 pr-0.5",children:[0===h.entries.length&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted",children:"Speak to delegate — e.g. “which sessions are free?”"}),h.entries.map((e,t)=>(0,n.jsxs)("p",{className:`text-[11px] leading-relaxed ${"user"===e.who?"text-text":"jarvis"===e.who?"text-brand-400":"text-text-muted font-mono"}`,children:["user"===e.who?"> ":"jarvis"===e.who?"Jarvis: ":"",e.text]},t))]})]})})]})}let nd=[],nu={},nx=new Set(["claude","codex","opencode","antigravity","omp","pi","devin","hermes"]),nm=new Set(["idle","done"]),np=e=>!!e&&nx.has(e.endsWith("-ui")?e.slice(0,-3):e),nf=(0,r.memo)(function({sessions:e=[],allSessions:t=[],activeSessionId:s,connected:l,notifications:a,sessionStatus:i,onSwitchSession:o,onCreateSession:c,onBack:d,onOpenRemote:u,onOpenMobile:m,hostKey:p=null,onOpenRemoteHost:f=null,onOpenMobileHost:b=null,onOpenFiles:g,onLogout:v,tunnelUrl:y,apiKey:w,connectionMode:j,subscribeToPush:k,unsubscribeFromPush:N,hostVersion:C,agentVersion:S,busRef:T,carrier:R="ws",isActive:E=!0,shells:$=[],modalBusRef:z=null,modalHostKey:M="main",modalShells:A=null,workspaces:I=[],activeWorkspaceId:D=null,onRenameSession:L,onDeleteSession:B,onCreateNamedSession:F,onResumeAgentSession:K=null,onToggleSidebar:O=null,sidebarCollapsed:W=!1,onToggleRightPanel:_,onReorderSession:H,rightPanelOpen:U=!1,fileBus:q=null,homeDir:X=null,isDesktop:V=!0}){let{t:J}=(0,eu.s)(),G=D??"default",Y=so(e=>e.workspaceProfiles[G]||"default"),Z=so(e=>e.workspaceWindows[G]||null),Q=so(e=>e.tabsByWorkspace[G]??nd),ee=so(e=>e.agentTabs),et=so(e=>e.setProfileFor),es=so(e=>e.setWindowFor),en=ee.filter(e=>!(e.profile===Y&&Q.some(t=>t.id===e.id))),er=e=>{et(G,e.profile),null!=e.windowId&&es(G,e.windowId),eo(G,e.id),ex({type:"browser"})},ea=so(e=>e.activeByWorkspace[G]||null),ei=(0,h.B)(e=>{let t=e.viewStack;return!!(t&&t[t.length-1]?.type==="browser")}),eo=so(e=>e.setActive);!function(e,t,s="default",n=null,l="default"){(0,r.useEffect)(()=>{let s=e?.current;if(!t||!s?.on)return;let n=e=>{so.getState().setAgentTabs(Array.isArray(e?.agentTabs)?e.agentTabs:[])};return s.on("browser:agentTabs",n),()=>{s.off?.("browser:agentTabs",n)}},[e,t]),(0,r.useEffect)(()=>{let r=e?.current;if(!t||null==n||!r?.on)return;let a=new Set,i=!1,o=e=>{if(e?.profile&&e.profile!==s||(e?.windowId??null)!==n)return;let t=Array.isArray(e?.tabs)?e.tabs:[],r=so.getState(),o=window.matchMedia?.("(max-width: 767px)").matches,c=i&&o?t.find(e=>e.openerId&&!a.has(e.id)):null;for(let e of(i=!0,t))a.add(e.id);let d=r.tabsByWorkspace[l]||[],u=new Map(t.map(e=>[e.id,e])),x=[...d.filter(e=>u.has(e.id)).map(e=>u.get(e.id)),...t.filter(e=>!d.some(t=>t.id===e.id))];r.setTabs(l,x);let m=r.activeByWorkspace[l];c?r.setActive(l,c.id):t.length&&!t.some(e=>e.id===m)&&r.setActive(l,(t.find(e=>e.active)||t[0]).id)};return r.on("browser:tabs",o),r.emit("browser:tabs.watch",{on:!0,profile:s,windowId:n}),()=>{r.off?.("browser:tabs",o),r.emit?.("browser:tabs.watch",{on:!1,profile:s,windowId:n})}},[e,t,s,n,l])}(T,l,Y,Z,G);let ex=(0,h.B)(e=>e.pushView),em=(0,h.B)(e=>e.agentBySession??nu),ep=(0,h.B)(e=>e.fullModes??nu)[D??eQ.AD]??!1,ef=(0,h.B)(e=>e.toggleFullMode);ej(e=>e.notifications);let eh=eM(),eb=i||eh,{formattedStars:eg}=(0,sG.w)(),ey="mouse"===tO(),ew=(e,t)=>ey?th(e,t):e,ek=(0,r.useRef)(null),eN=(0,r.useRef)(null),eC=(0,r.useRef)(null),[eS,eT]=(0,r.useState)({targetId:null,x:0,y:0}),eR=(0,r.useRef)(null),ez=s_(eR,eS.x,eS.y),[eP,eA]=(0,r.useState)({sessionId:null,x:0,y:0}),[eI,eD]=(0,r.useState)(null),eL=(0,r.useRef)(null),eB=s_(eL,eP.x,eP.y),eF=em[eP.sessionId]||eb[eP.sessionId]?.tool||e.find(e=>e.id===eP.sessionId)?.agent,eK=eF?.endsWith("-ui"),eO=np(eF),eW=eO&&nm.has(eb[eP.sessionId]?.state||"idle"),[e_,eH]=(0,r.useState)({isOpen:!1,sessionId:null,sessionName:""}),[eU,eq]=(0,r.useState)({sessionId:null,name:"",value:""}),[eX,eV]=(0,r.useState)(!1),eJ=s8(e=>e.open),eG=s8(e=>e.toggle),eY=s8(e=>!1),eZ=s6(e=>Object.values(e.board.tasks).some(e=>"needs_input"===e.status));(0,r.useEffect)(()=>{if(!E||!eY)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"j"===e.key.toLowerCase()&&(e.preventDefault(),eG())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[E,eY,eG]);let{dragId:e0,registerEl:e1,startDrag:e3,consumeClick:e4}=sJ({axis:"x",threshold:12,onCommit:H}),e6=(0,r.useMemo)(()=>new Set(t.map(e=>e.id)),[t]);(0,r.useEffect)(()=>{if(!E)return;let t=t=>{let n,r=document.activeElement;if(!r||"INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName||!t.ctrlKey||t.altKey||t.metaKey||t.shiftKey||e.length<2)return;let l=e.findIndex(e=>e.id===s);if("ArrowRight"===t.key)n=e[(l+1)%e.length];else if("ArrowLeft"===t.key)n=e[(l-1+e.length)%e.length];else{if(!(t.key>="1")||!(t.key<="9"))return;n=e[Math.min(t.key-1,e.length-1)]}t.preventDefault(),n&&n.id!==s&&o?.(n.id),requestAnimationFrame(()=>requestAnimationFrame(()=>r.focus()))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[E,e,s,o]);let e8=ev(e=>e.open),e9=(0,h.B)(e=>e.hiddenHeaderButtons),e7=(0,h.B)(e=>e.hiddenPaneSessionIds??nd),te=(0,h.B)(e=>e.toggleHidePane),tt=(0,h.B)(e=>e.unhidePane),ts=(0,h.B)(e=>e.setFullMode),tn=(0,P.rh)(e=>e.currentKey),tr=p||tn,tl=(0,P.rh)(e=>e.hosts[tr]),ta=tl?.mobileDeviceCount||0,ti=p?!!tl?.remoteAvailable:!!u,to=p?!!tl?.mobileAvailable:!!m;eE(p).busRef;let tc=ev(e=>e.setContext),td=ev(e=>e.setCallbacks);(0,r.useEffect)(()=>{if(!E)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.altKey&&!e.shiftKey&&"t"===e.key.toLowerCase()&&(e.preventDefault(),eV(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[E]),(0,r.useEffect)(()=>{if(!eP.sessionId)return;let e=e=>{eL.current&&!eL.current.contains(e.target)&&eA({sessionId:null,x:0,y:0})},t=e=>{"Escape"===e.key&&eA({sessionId:null,x:0,y:0})};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",t)}},[eP.sessionId]);let tu=(0,r.useRef)(null),tx=()=>{tu.current&&(clearTimeout(tu.current),tu.current=null)},tm=e=>{eH({isOpen:!0,sessionId:e.id,sessionName:e?.name||J("terminal.defaultName")}),eA({sessionId:null,x:0,y:0})},tp=I.find(e=>e.id===D)||null,tf=e=>{let t=requestAnimationFrame(()=>{let t=ek.current,s=e.current;if(!t||!s)return;let n=s.getBoundingClientRect().left-t.getBoundingClientRect().left,r=t.scrollLeft+n-(t.clientWidth-s.offsetWidth)/2,l=t.scrollWidth-t.clientWidth;t.scrollTo({left:Math.max(0,Math.min(r,l)),behavior:"smooth"})});return()=>cancelAnimationFrame(t)};return(0,r.useEffect)(()=>tf(eN),[s,e.length]),(0,r.useEffect)(()=>tf(eC),[ea,Q.length,ei]),(0,r.useEffect)(()=>{if(!eS.targetId)return;let e=e=>{eR.current&&!eR.current.contains(e.target)&&eT({targetId:null,x:0,y:0})},t=e=>{"Escape"===e.key&&eT({targetId:null,x:0,y:0})};return window.addEventListener("pointerdown",e),window.addEventListener("keydown",t),()=>{window.removeEventListener("pointerdown",e),window.removeEventListener("keydown",t)}},[eS.targetId]),(0,r.useEffect)(()=>{E&&(tc({connected:l,remoteAvailable:!!u,showTheme:!1,busRef:T,tunnelUrl:y,apiKey:w,connectionMode:j,subscribeToPush:k,unsubscribeFromPush:N,hostVersion:C||S,agentVersion:C||S,carrier:R}),td({onRemote:u,onFiles:g,onLogout:v}))},[E,l,u,g,v,y,w,j,C,S,T,R,k,N,tc,td]),(0,n.jsxs)("div",{className:`h-9 ${sZ} px-2 sm:pl-0 sm:pr-2 flex items-stretch gap-0 flex-shrink-0 bg-bg border-b border-border-subtle`,children:[O&&W&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),O()},className:"p-1.5 text-text hover:bg-surface-2 hover:text-text rounded-brand transition duration-150 ease-out active:scale-[0.94] flex-shrink-0 self-center",title:ew(J("common.open"),"toggleSidebar"),children:(0,n.jsx)(el.e6,{size:16})}),d&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),d()},className:"p-1 pl-1.5 pr-3.5 sm:p-1.5 text-text hover:bg-surface-2 hover:text-text rounded-brand transition duration-150 ease-out active:scale-[0.94] flex-shrink-0 self-center",title:J("common.back"),children:[(0,n.jsx)(el.JG,{size:20,className:"sm:hidden"}),(0,n.jsx)(el.JG,{size:16,className:"hidden sm:block"})]}),(0,n.jsx)("div",{ref:ek,className:"flex-1 overflow-auto overflow-x-auto overflow-y-hidden scrollbar-none h-full",children:(0,n.jsxs)("div",{className:"flex gap-0 min-w-max items-stretch h-full",children:[e.map(t=>{let r=t.id===s&&!ei,a=e7.includes(t.id),i=eb[t.id]?.state||"idle",c=se(i),d=t.name||J("terminal.defaultName"),u=e5(em[t.id])||e5(em[t.id]?.replace(/-ui$/,""));return(0,n.jsxs)("div",{role:"button",tabIndex:0,ref:e=>{e1(t.id)(e),r&&(eN.current=e)},onPointerDown:s=>{"mouse"===s.pointerType&&H&&l&&(tx(),e3(s,t.id,e.map(e=>e.id)))},onClick:()=>{e4()||((0,ed.e)(),a&&tt(t.id),o?.(t.id))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),a&&tt(t.id),o?.(t.id))},onContextMenu:e=>{e.preventDefault(),(0,ed.e)(),eA({sessionId:t.id,x:e.clientX,y:e.clientY})},onTouchStart:e=>{let s;return s=e.touches[0],void(tu.current=setTimeout(()=>{(0,ed.e)(),eA({sessionId:t.id,x:s.clientX,y:s.clientY})},500))},onTouchMove:tx,onTouchEnd:tx,className:`term-tab group relative px-1.5 sm:px-2.5 text-xs font-medium duration-150 ease-out flex items-center gap-1 sm:gap-2 whitespace-nowrap h-full cursor-pointer select-none touch-manipulation touch-pan-x ${r?"term-tab-active":""} ${a?"opacity-75 hover:opacity-100":""} ${e0===t.id?"z-20 opacity-90 shadow-lg":"transition"}`,children:[(0,n.jsxs)("div",{className:"w-3.5 h-3.5 flex items-center justify-center shrink-0",children:["idle"===i&&u?(0,n.jsx)("img",{src:u,alt:"",draggable:!1,className:`w-3.5 h-3.5 object-contain ${e2} ${B?"sm:group-hover:hidden":""}`}):(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full term-dot ${c.cls}${c.pulse?` pulse-${c.pulse}`:""} ${B?"sm:group-hover:hidden":""}`,style:{background:c.dot},title:J(c.label)}),B&&(0,n.jsx)("button",{type:"button",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),(0,ed.e)(),tm(t)},className:"hidden w-full h-full p-0.5 rounded text-text hover:bg-text/15 sm:group-hover:flex items-center justify-center transition-colors",title:ew(J("sessions.deleteTitle"),"closeTerminal"),children:(0,n.jsx)(el.X,{size:11,strokeWidth:2.4})})]}),(0,n.jsx)("span",{className:"truncate max-w-[90px] sm:max-w-[140px]","data-tip":d,children:d}),a&&(0,n.jsx)("button",{type:"button",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),(0,ed.e)(),tt(t.id)},className:"p-0.5 rounded text-amber-400 hover:text-amber-300 hover:bg-amber-400/20 transition-colors flex items-center justify-center shrink-0",title:J("sessions.showPanel")||"Show panel",children:(0,n.jsx)(el.X_,{size:13})})]},t.id)}),Q.map(e=>{let t=ei&&(ea===e.id||!ea&&e.active);return(0,n.jsxs)("div",{ref:t?eC:null,role:"button",tabIndex:0,onClick:()=>{(0,ed.e)(),eo(G,e.id),ex({type:"browser"})},onContextMenu:t=>{t.preventDefault(),eT({targetId:e.id,x:t.clientX,y:t.clientY})},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),eo(G,e.id),ex({type:"browser"}))},className:`term-tab group relative px-1.5 sm:px-2.5 text-xs font-medium flex items-center gap-1 sm:gap-2 whitespace-nowrap h-full cursor-pointer select-none touch-manipulation touch-pan-x ${t?"term-tab-active":""}`,children:[(0,n.jsxs)("div",{className:"w-3.5 h-3.5 flex items-center justify-center shrink-0",children:[e.booting?(0,n.jsx)(el.kr,{size:13,className:"w-3.5 h-3.5 animate-spin text-text-muted"}):(0,n.jsx)(el.qz,{size:13,className:"w-3.5 h-3.5 text-text sm:group-hover:hidden"}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),T?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:e.id,profile:Y}},()=>{});let s=so.getState(),n=(s.tabsByWorkspace[G]||[]).filter(t=>t.id!==e.id);s.setTabs(G,n),s.activeByWorkspace[G]===e.id&&s.setActive(G,n[0]?.id||null)},className:"hidden w-full h-full p-0.5 rounded text-text hover:bg-text/15 sm:group-hover:flex items-center justify-center transition-colors",title:J("common.close"),children:(0,n.jsx)(el.X,{size:11,strokeWidth:2.4})})]}),(0,n.jsx)("span",{className:"truncate max-w-[90px] sm:max-w-[140px]","data-tip":sc(e.title)||J("sites.browserTab"),children:sc(e.title)||J("sites.browserTab")})]},e.id)}),en.map(e=>(0,n.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>{(0,ed.e)(),er(e)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),er(e))},className:"term-tab group relative px-1.5 sm:px-2.5 text-xs font-medium flex items-center gap-1 sm:gap-2 whitespace-nowrap h-full cursor-pointer select-none touch-manipulation","data-tip":`${sc(e.title)||"Agent tab"} (${e.profile})`,children:[(0,n.jsxs)("div",{className:"w-3.5 h-3.5 flex items-center justify-center shrink-0",children:[(0,n.jsx)(el.cC,{size:13,className:"w-3.5 h-3.5 text-brand-500 sm:group-hover:hidden"}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),T?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:e.id,profile:e.profile}},()=>{}),so.getState().setAgentTabs(so.getState().agentTabs.filter(t=>t.id!==e.id))},className:"hidden w-full h-full p-0.5 rounded text-text hover:bg-text/15 sm:group-hover:flex items-center justify-center transition-colors",title:"Close",children:(0,n.jsx)(el.X,{size:11,strokeWidth:2.4})})]}),(0,n.jsx)(el.cC,{size:11,className:"w-3 h-3 text-brand-500 shrink-0 sm:hidden"}),(0,n.jsx)("span",{className:"truncate max-w-[70px] sm:max-w-[110px]",children:sc(e.title)||"Agent tab"}),(0,n.jsx)("span",{className:"hidden sm:inline text-[9px] text-text-muted shrink-0",children:e.profile})]},`ag-${e.profile}-${e.id}`)),c&&(0,n.jsx)("div",{className:"sticky right-0 z-10 ml-1 pl-1 flex items-center flex-shrink-0 bg-bg",children:(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),eV(!0)},disabled:!l,className:"p-1.5 text-text hover:bg-surface-2 hover:text-brand-500 transition duration-150 ease-out active:scale-[0.94] disabled:opacity-40 disabled:cursor-not-allowed rounded-brand",title:ew(J("terminal.newTerminal"),"newTerminal"),children:(0,n.jsx)(el.FW,{size:17,strokeWidth:2.4})})})]})}),(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0 self-center",children:[!e9.includes("remote")&&ti&&(p||!(0,x.sP)())&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),(p?f:u)?.(p||void 0)},className:"hidden sm:block p-1.5 text-text hover:bg-surface-2 hover:text-text rounded-brand transition duration-150 ease-out active:scale-[0.94]",title:J("menu.remoteDesktop"),children:(0,n.jsx)(el.VA,{size:16})}),!e9.includes("mobile")&&to&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),(p?b:m)?.(p||void 0)},className:`hidden sm:block p-1.5 hover:bg-surface-2 rounded-brand transition duration-150 ease-out active:scale-[0.94] ${ta>0?"text-green-400":"text-text hover:text-text"}`,title:ta>0?J("mobile.deviceRunning",{count:ta}):J("mobile.androidDevice"),children:(0,n.jsx)(el.wO,{size:16})}),eY&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eG()},disabled:!l,className:`relative p-1.5 hover:bg-surface-2 rounded-brand transition duration-150 ease-out active:scale-[0.94] disabled:opacity-40 disabled:cursor-not-allowed ${eZ?"text-amber-400":"text-text hover:text-text"}`,title:"Jarvis coordinator (⌘J / Ctrl+J)",children:[(0,n.jsx)(el.cC,{size:16}),eZ&&(0,n.jsx)("span",{className:"absolute top-0.5 right-0.5 w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse"})]}),!e9.includes("notifications")&&(0,n.jsx)(si,{sessionStatus:eb,allSessions:t,onSwitchSession:o}),!e9.includes("notifications")&&(0,n.jsx)(sl,{sessions:e,allSessions:t,sessionStatus:eb,onSwitchSession:o,workspaces:I}),_&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),_()},className:`hidden sm:block p-1.5 rounded-brand transition duration-150 ease-out active:scale-[0.94] hover:bg-surface-2 ${U?"text-brand-500":"text-text hover:text-text"}`,title:ew(J("workspaces.tabFiles"),"toggleRightPanel"),children:(0,n.jsx)(el.jz,{size:16})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),e8()},className:`p-1.5 text-text hover:bg-surface-2 hover:text-text rounded-brand transition duration-150 ease-out active:scale-[0.94] ${O?"sm:hidden":""}`,title:J("menu.title"),children:(0,n.jsx)(el.wB,{size:16})})]}),eS.targetId&&(0,n.jsxs)("div",{ref:eR,className:"fixed z-[60] menu-popover p-1 min-w-[150px] animate-in fade-in zoom-in-95 duration-100",style:{left:ez.left,top:ez.top},children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)();let e=Q.find(e=>e.id===eS.targetId)?.url;e&&navigator.clipboard?.writeText?.(e).catch(()=>{}),eT({targetId:null,x:0,y:0})},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.vv,{size:13})," Copy URL"]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),T?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:eS.targetId,profile:Y}},()=>{});let e=so.getState(),t=(e.tabsByWorkspace[G]||[]).filter(e=>e.id!==eS.targetId);e.setTabs(G,t),e.activeByWorkspace[G]===eS.targetId&&e.setActive(G,t[0]?.id||null),eT({targetId:null,x:0,y:0})},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.X,{size:13})," ",J("sessions.deleteTitle")||"Close tab"]})]}),eP.sessionId&&(0,n.jsxs)("div",{ref:eL,className:"fixed z-[60] menu-popover p-1 min-w-[140px] animate-in fade-in zoom-in-95 duration-100",style:{left:eB.left,top:eB.top},children:[eb[eP.sessionId]?.state==="done"&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ej.getState().clearNotification(eP.sessionId),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2.5 py-1.5 text-xs text-amber-500 hover:bg-amber-500/10 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.aJ,{size:13})," ",J("sessions.markRead")]}),(0,n.jsxs)("button",{onClick:()=>{var t;eq({sessionId:(t=e.find(e=>e.id===eP.sessionId)).id,name:t.name||"",value:t.name||""}),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.gH,{size:13})," ",J("sessions.editName")]}),V&&(0,n.jsxs)("div",{className:"relative group/split",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),!ep&&eP.sessionId&&eP.sessionId!==s&&o?.(eP.sessionId),ef(D),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)(el.Wn,{size:13}),(0,n.jsx)("span",{children:J("sessions.split")||"Split"})]}),(0,n.jsx)(el.c_,{size:12,className:"text-text-muted"})]}),(0,n.jsxs)("div",{className:`hidden group-hover/split:block absolute top-0 menu-popover p-1 min-w-[130px] shadow-xl z-20 ${eB.left>window.innerWidth-280?"right-full -mr-0.5":"left-full -ml-0.5"}`,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),!ep&&eP.sessionId&&eP.sessionId!==s&&o?.(eP.sessionId),ef(D),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[ep?(0,n.jsx)(el.xq,{size:12}):(0,n.jsx)(el.h1,{size:12}),(0,n.jsx)("span",{className:"whitespace-nowrap",children:ep?"Restore":"Maximize"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"100%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),ep&&ts(D,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:2}})),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/2"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"50%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),ep&&ts(D,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:3}})),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/3"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"33%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),ep&&ts(D,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:4}})),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/4"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"25%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),ep&&ts(D,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:"auto"}})),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Auto Fit"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"Auto"})]}),(0,n.jsx)("div",{className:"h-px bg-border-subtle my-1"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),te(eP.sessionId),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[e7.includes(eP.sessionId)?(0,n.jsx)(el.kU,{size:12}):(0,n.jsx)(el.X_,{size:12}),(0,n.jsx)("span",{children:e7.includes(eP.sessionId)?J("sessions.showPanel")||"Show":J("sessions.hidePanel")||"Hide"})]})})]})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eD(eP.sessionId),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el._V,{size:13,className:"flex-shrink-0"})," ",J("menu.terminalBackground")]}),(em[eP.sessionId]?.endsWith("-ui")||eb[eP.sessionId]?.conversationId)&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)();let e=eP.sessionId,t=e$(e).bus;em[e]?.endsWith("-ui")?t?.emit("ai:restart",{sessionId:e}):t?.emit("session-resume",{sessionId:e}),eA({sessionId:null,x:0,y:0})},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.kt,{size:13})," ",em[eP.sessionId]?.endsWith("-ui")?J("sessions.restartAi")||"Restart AI":J("sessions.resumeSession")]}),eO&&(0,n.jsxs)("button",{disabled:!eW,onClick:()=>{(0,ed.e)();let e=eP.sessionId;e$(e).bus?.emit("setSessionMode",{sessionId:e,mode:eK?"terminal":"ui"},e=>{e?.success||alert(e?.error||J("sessions.modeSwitchFailed"))}),eA({sessionId:null,x:0,y:0})},className:`w-full text-left px-2.5 py-1.5 text-xs rounded-[6px] flex items-center gap-2 ${eW?"text-text hover:bg-surface-2/80":"text-text-subtle cursor-not-allowed"}`,children:[(0,n.jsx)(el.sU,{size:13})," ",eK?J("sessions.openAsTerminal"):J("sessions.openAsUi")]}),(0,n.jsxs)("button",{onClick:()=>tm(e.find(e=>e.id===eP.sessionId)),className:"w-full text-left px-2.5 py-1.5 text-xs text-red-500 hover:bg-red-500/10 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.TB,{size:13})," ",J("sessions.deleteTitle")]})]}),eI&&(0,n.jsx)(sX,{sessionId:eI,title:e.find(e=>e.id===eI)?.name,busRef:T,onClose:()=>eD(null)}),eU.sessionId&&(0,n.jsx)(sN,{title:J("sessions.editName"),placeholder:eU.name,value:eU.value,onChange:e=>eq({...eU,value:e}),onSubmit:()=>{let e=eU.value.trim();eU.sessionId&&e&&L?.(eU.sessionId,e),eq({sessionId:null,name:"",value:""})},onClose:()=>eq({sessionId:null,name:"",value:""})}),eX&&(0,n.jsx)(sW,{onClose:()=>eV(!1),onCreate:(e,t,s,n,r,l)=>{F?F(e,D,t,r||null,s,n,l):c?.()},workspaceId:D,shells:A||$,busRef:z||T,hostKey:M,suggestName:`${J("terminal.defaultName")} ${e.filter(e=>(0,eQ.xs)(e)===(D??null)).length+1}`,workspacePath:tp?.path||null,workspaceName:tp?.name||"",fileBus:q,homeDir:X,onResumeAgentSession:K,onSelectSession:o,liveSessionIds:e6,activeSessionId:s,connected:l}),(0,n.jsx)(ec.A,{isOpen:e_.isOpen,onClose:()=>eH({isOpen:!1,sessionId:null,sessionName:""}),onConfirm:()=>{e_.sessionId&&B?.(e_.sessionId)},title:J("sessions.deleteTitle"),message:J("sessions.deleteMessage",{name:e_.sessionName}),confirmText:J("common.delete")}),eJ&&(0,n.jsx)(nc,{busRef:T,fileBus:q,workspacePath:tp?.path||"",onClose:()=>s8.getState().setOpen(!1)})]})});s(12401);let nh="js|jsx|ts|tsx|css|json|md|txt|html|xml|yaml|yml|sh|py|rb|go|java|c|cpp|h",nb={WEB_HTTP:/https?:\/\/[^\s]+/g,WEB_LOCALHOST:/localhost:\d+[^\s]*/g,FILE_ABSOLUTE:RegExp(`\\/[^\\s:]+\\.(${nh})\\b`,"g"),FILE_RELATIVE:RegExp(`(?:\\.{1,2}\\/)?[^\\s:/]+(?:\\/[^\\s:/]+)*\\.(${nh})\\b`,"g"),FILE_WITH_LINE:RegExp(`[^\\s]+\\.(${nh}):\\d+(?::\\d+)?`,"g"),GIT_MODIFIED:/modified:\s+[^\s]+/g};function ng({text:e,position:t,onOpenUrl:s,onCopy:r,onAddToNote:l,onClose:a}){let{t:i}=(0,eu.s)(),o=function(e){let t=e.trim(),s=t.match(nb.WEB_HTTP);if(s)return{isUrl:!0,isFile:!1,match:s[0]};let n=t.match(nb.WEB_LOCALHOST);if(n)return{isUrl:!0,isFile:!1,match:`http://${n[0]}`};let r=t.match(nb.FILE_WITH_LINE);if(r)return{isUrl:!1,isFile:!0,match:r[0]};let l=t.match(nb.FILE_ABSOLUTE);if(l)return{isUrl:!1,isFile:!0,match:l[0]};let a=t.match(nb.FILE_RELATIVE);return a?{isUrl:!1,isFile:!0,match:a[0]}:{isUrl:!1,isFile:!1,match:t}}(e),c=t=>{if("openUrl"===t&&o.isUrl)s(o.match);else if("copy"===t)r(e);else if("addNote"===t&&l)return void l(e);a()};return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-[2px] flex items-center justify-center z-[60]",onMouseDown:e=>{e.preventDefault(),a()},children:(0,n.jsxs)("div",{className:"card-elev overflow-hidden min-w-[200px]",onMouseDown:e=>{e.stopPropagation()},onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"px-4 py-3 border-b border-border bg-surface",children:(0,n.jsxs)("div",{className:"text-text text-sm font-medium",children:["Selected: ",e.length>30?e.substring(0,30)+"...":e]})}),(0,n.jsxs)("div",{className:"p-2",children:[o.isUrl&&(0,n.jsxs)("button",{onClick:()=>c("openUrl"),className:"w-full px-4 py-3 flex items-center gap-3 hover:bg-surface-2 text-text text-left rounded-brand transition-colors mb-1",children:[(0,n.jsx)(el.Gr,{size:20}),(0,n.jsx)("span",{children:"Open URL"})]}),(0,n.jsxs)("button",{onClick:()=>c("copy"),className:"w-full px-4 py-3 flex items-center gap-3 hover:bg-surface-2 text-text text-left rounded-brand transition-colors mb-1",children:[(0,n.jsx)(el.QR,{size:20}),(0,n.jsx)("span",{children:"Copy"})]}),l&&(0,n.jsxs)("button",{onClick:()=>c("addNote"),className:"w-full px-4 py-3 flex items-center gap-3 hover:bg-surface-2 text-text text-left rounded-brand transition-colors mb-1",children:[(0,n.jsx)(el.y8,{size:20}),(0,n.jsx)("span",{children:i("terminalPane.addToNote")})]}),(0,n.jsxs)("button",{onClick:a,className:"w-full px-4 py-3 flex items-center gap-3 hover:bg-surface-2 text-red-400 text-left rounded-brand transition-colors border-t border-border mt-2 pt-3",children:[(0,n.jsx)(el.X,{size:20}),(0,n.jsx)("span",{children:"Close"})]})]})]})})}let nv=new Map;function ny(e,t){e.fileBus?.gitChangedCount(t).then(t=>{t?.success&&(e.count=t.count||0,e.subs.forEach(t=>t(e.count)))})}function nw(e,t,{enabled:s=!0}={}){let[n,l]=(0,r.useState)(0),a=t||en.getState();return(0,r.useEffect)(()=>{let t;if(!e||!a||!s)return;let n=((t=nv.get(e))||(t={count:0,stop:null,refs:0,subs:new Set,fileBus:a},nv.set(e,t),ny(t,e),t.stop=sg(()=>ny(t,e),1e4)),t.refs++,t);return l(n.count),n.subs.add(l),()=>{let t;n.subs.delete(l),(t=nv.get(e))&&(t.refs--,t.refs<=0&&(t.stop?.(),nv.delete(e)))}},[e,a,s]),n}var nj=s(42970),nk=s(36890),nN=s(5262),nC=s(36834),nS=s(10358),nT=s(69070),nR=s(79063);let nE={...nR.aC,default:nR.aC.dark};function n$({joinClaimed:e,joining:t,gapBusy:s}){return!!(e?.current||t?.current||s)}function nz(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e instanceof Uint8Array?e:new Uint8Array(e):"string"==typeof e?e:String(e)}let nM=e=>"string"==typeof e?function(e){if(!e)return 0;let t=0,s=e.length;for(let n=0;n<s;n++){let s=e.charCodeAt(n);s<=127?t+=1:s<=2047?t+=2:s>=55296&&s<=56319?(t+=4,n++):t+=3}return t}(e):e.byteLength;function nP(e,t,s,n,r){if(!e||e._core?._isDisposed)return;let l=nz(t);r?r.write(l):e.write(l),s&&(s.current.push(l),n.current+=nM(l))}let nA="stale",nI=()=>{if("u"<typeof navigator)return!1;let e=/Macintosh|Mac OS X/i.test(navigator.userAgent)||"MacIntel"===navigator.platform,t=/AppleWebKit/i.test(navigator.userAgent)&&!/Chrome|Chromium|Edg/i.test(navigator.userAgent);return e&&t},nD=/^- \[([ xX])\] ?/;function nL(e){return e.map(e=>`- [${e.done?"x":" "}] ${e.text}`).join("\n")}let nB=new Map,nF=e=>{try{navigator.clipboard?.writeText(e).catch(()=>{})}catch{}};function nK({bus:e,sessionId:t,appendOnOpen:s,onClose:l,variant:a="modal",pinned:i=!1,onPin:o,rightSlot:c=null}){let{t:d}=(0,eu.s)(),u=(0,h.B)(e=>e.noteChips),x=(0,h.B)(e=>e.addNoteChip),m=(0,h.B)(e=>e.removeNoteChip),[p,f]=(0,r.useState)(null),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(()=>new Set),[k,N]=(0,r.useState)(null),[C,S]=(0,r.useState)(""),[T,R]=(0,r.useState)(null),E=(0,r.useRef)(new Map),$=(0,r.useRef)(null),[z,M]=(0,r.useState)(!1),[P,A]=(0,r.useState)(""),I=(0,r.useRef)([]),D=(0,r.useRef)(null),L=(0,r.useRef)(0),B=(0,r.useRef)(null),F=(0,r.useRef)(s),[K]=(0,r.useState)(()=>Symbol("note")),O=(0,r.useRef)(o);(0,r.useEffect)(()=>{O.current=o});let W=e=>e.map(e=>({...e,id:++L.current})),_=()=>{let e=F.current;return(F.current=null,e)?e.split("\n").map(e=>e.trim()).filter(Boolean).map(e=>({done:!1,text:e})):[]},H=(0,r.useCallback)(s=>{e?.emit("saveNote",{sessionId:t,text:s},()=>{})},[e,t]),U=(0,r.useCallback)(e=>{let s=e(I.current||[]);I.current=s,nB.set(t,s),f(s),window.dispatchEvent(new CustomEvent(eJ.aD,{detail:{sessionId:t,items:s,from:K}})),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{B.current=null,H(nL(I.current))},500)},[H,t,K]);(0,r.useEffect)(()=>{if(!e||!t)return;let s=!1,n=nB.get(t),r=(e,s)=>{for(let t of e)t.id>L.current&&(L.current=t.id);I.current=e,nB.set(t,e),f(e),s&&H(nL(e))};if(n){let e=_();r(e.length?[...n,...W(e)]:n,e.length>0);return}return e.emit("getNote",{sessionId:t},e=>{if(s)return;let t=((e?.success?e.text:"")||"").split("\n").map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.match(nD);return t?{done:" "!==t[1],text:e.slice(t[0].length)}:{done:!1,text:e}}),n=_();n.length&&!t.length&&O.current?.(!0),r(W([...t,...n]),n.length>0)}),()=>{s=!0}},[e,t,H]),(0,r.useEffect)(()=>{let e=e=>{let s=e.detail;if(s&&s.sessionId===t&&s.from!==K&&null==$.current){for(let e of(B.current&&(clearTimeout(B.current),B.current=null),s.items))e.id>L.current&&(L.current=e.id);I.current=s.items,nB.set(t,s.items),f(s.items)}};return window.addEventListener(eJ.aD,e),()=>window.removeEventListener(eJ.aD,e)},[t,K]),(0,r.useEffect)(()=>()=>{B.current&&(clearTimeout(B.current),B.current=null,H(nL(I.current)))},[H]),(0,r.useEffect)(()=>{let e=D.current;if(!e)return;let t=window.innerWidth>=eJ.jK?eJ.hp:eJ.bs;e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,t)}px`},[b]);let q=e=>{e.preventDefault();let t=b.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);t.length&&((0,ed.e)(),g(""),I.current.length||o?.(!0),U(e=>[...e,...W(t.map(e=>({done:!1,text:e})))]),D.current?.focus())},X=e=>{(0,ed.e)(),U(t=>t.map(t=>t.id===e?{...t,done:!t.done}:t))},V=()=>{let e=C.trim();e&&null!=k&&U(t=>t.map(t=>t.id===k?{...t,text:e}:t)),N(null)},J=()=>{let e=P.trim();e&&!Q.includes(e)&&x(e),A(""),M(!1)},G=(p?.length||0)>0,Y=p?.filter(e=>e.done).length||0,Z=(p?.length||0)-Y,Q=[...eJ.TM,...Array.isArray(u)?u:[]];if("pinned"===a){if(!G)return null;let e=p.find(e=>!e.done)||null;return(0,n.jsxs)("div",{style:{height:26},className:"flex items-center gap-2 px-2 -mt-1.5 -mx-1.5 mb-1.5 flex-shrink-0 bg-surface border-b border-border-subtle text-[11px] text-text-muted select-none relative z-10",onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),children:[e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>X(e.id),className:"w-3.5 h-3.5 flex-shrink-0 flex items-center justify-center rounded-[3px] border-2 border-border hover:border-brand-400 transition-colors",title:d("common.done")}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",title:e.text,children:e.text})]}):(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:d("note.allDone")}),(0,n.jsxs)("span",{className:"flex-shrink-0 text-text-subtle",children:[Y,"/",p.length]}),c]})}return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-[2px] flex items-center justify-center z-[60] p-4",onMouseDown:e=>{e.preventDefault(),l()},children:(0,n.jsxs)("div",{className:"card-elev w-full max-w-lg h-[55dvh] min-h-[300px] flex flex-col overflow-hidden",onMouseDown:e=>{e.stopPropagation()},onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between pl-4 pr-2 py-2 border-b border-border bg-surface flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"text-text text-sm font-medium truncate",children:d("note.title")}),G&&(0,n.jsxs)("span",{className:"text-xs text-text-subtle flex-shrink-0",children:[Y,"/",p.length]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[o&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),o(!i),i||l()},className:`p-2 hover:bg-surface-2 rounded-brand transition-colors ${i?"text-brand-500":"text-text"}`,title:i?d("note.unpin"):d("note.pin"),children:i?(0,n.jsx)(el.Ze,{size:16}):(0,n.jsx)(el.yU,{size:16})}),(0,n.jsx)("button",{onClick:()=>{let e=(p||[]).filter(e=>!e.done);e.length&&((0,ed.e)(),j(new Set(e.map(e=>e.id))),nF(e.map(e=>e.text).join("\n")),y(!0),setTimeout(()=>y(!1),1200))},disabled:!Z,className:"p-2 hover:bg-surface-2 text-text rounded-brand transition-colors disabled:opacity-40",title:d("note.copyTodo"),children:v?(0,n.jsx)(el.aJ,{size:16,className:"text-green-400"}):(0,n.jsx)(el.QR,{size:16})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),U(e=>e.filter(e=>!e.done))},disabled:!Y,className:"p-2 hover:bg-surface-2 text-red-400 rounded-brand transition-colors disabled:opacity-40",title:d("note.clearDone"),children:(0,n.jsx)(el.TB,{size:16})}),(0,n.jsx)("button",{onClick:l,className:"p-2 hover:bg-surface-2 text-text rounded-brand transition-colors",title:"Close",children:(0,n.jsx)(el.X,{size:16})})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:null===p?null:G?(0,n.jsx)("ul",{className:"py-1",children:p.map(e=>(0,n.jsxs)("li",{ref:t=>{t?E.current.set(e.id,t):E.current.delete(e.id)},className:`flex items-center gap-1.5 px-3 py-1.5 ${T===e.id?"relative z-10 bg-surface-2 shadow-elev select-none":null!=T?"transition-transform duration-150 ease-out":""}`,children:[(0,n.jsx)("span",{onPointerDown:t=>((e,t)=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),(0,ed.e)(),e.currentTarget.setPointerCapture?.(e.pointerId),$.current=t.id,R(t.id);let s=(I.current||[]).map(e=>e.id),n=s.indexOf(t.id),r=E.current.get(t.id),l=r?.getBoundingClientRect().height||0,a=e.clientY,i=n,o=null,c=e=>{if("mouse"===e.pointerType&&0===e.buttons)return void d();let c=e.clientY-a,u=l?Math.round(c/l):0;i=Math.max(0,Math.min(s.length-1,n+u)),o||(o=requestAnimationFrame(()=>{o=null,r&&(r.style.transform=`translateY(${c}px)`),s.forEach((e,s)=>{if(e===t.id)return;let r=E.current.get(e);if(!r)return;let a=0;n<i&&s>n&&s<=i?a=-l:n>i&&s>=i&&s<n&&(a=l),r.style.transform=a?`translateY(${a}px)`:""})}))},d=()=>{for(let e of(window.removeEventListener("pointermove",c),window.removeEventListener("pointerup",d),window.removeEventListener("pointercancel",d),window.removeEventListener("blur",d),o&&(cancelAnimationFrame(o),o=null),E.current.values()))e&&(e.style.transform="");$.current=null,R(null),i!==n&&U(e=>{let s=e.findIndex(e=>e.id===t.id);if(s<0)return e;let n=[...e];return n.splice(Math.min(i,n.length-1),0,n.splice(s,1)[0]),n})};window.addEventListener("pointermove",c),window.addEventListener("pointerup",d),window.addEventListener("pointercancel",d),window.addEventListener("blur",d)})(t,e),className:`p-1 -ml-1.5 flex-shrink-0 touch-none cursor-grab active:cursor-grabbing ${T===e.id?"text-brand-500":"text-text-subtle/60 hover:text-text-subtle"}`,title:d("note.drag"),children:(0,n.jsx)(el.f2,{size:13})}),(0,n.jsx)("button",{onClick:()=>X(e.id),className:`w-5 h-5 flex-shrink-0 flex items-center justify-center rounded border-2 transition-colors ${e.done?"bg-brand-500 border-brand-500":"border-border hover:border-brand-400"}`,children:e.done&&(0,n.jsx)(el.aJ,{size:13,className:"text-white"})}),k===e.id?(0,n.jsx)("input",{value:C,onChange:e=>S(e.target.value),onKeyDown:e=>{"Enter"===e.key&&V(),"Escape"===e.key&&N(null)},onBlur:V,autoFocus:!0,className:"flex-1 min-w-0 bg-surface-2 border border-brand-500 rounded-brand px-2 py-1 text-sm text-text outline-none"}):(0,n.jsx)("span",{onClick:()=>{(0,ed.e)(),N(e.id),S(e.text)},className:`flex-1 min-w-0 text-sm break-words cursor-text ${e.done?"text-text-subtle line-through":"text-text"}`,title:d("note.edit"),children:e.text}),(0,n.jsx)("button",{onClick:()=>{let t;return(0,ed.e)(),void((t=new Set(w)).has(e.id)?t.delete(e.id):t.add(e.id),j(t),nF((p||[]).filter(e=>t.has(e.id)).map(e=>e.text).join("\n")))},className:`p-1.5 rounded-brand transition-colors flex-shrink-0 ${w.has(e.id)?"text-brand-500 bg-brand-500/10":"text-text-subtle hover:text-text hover:bg-surface-2"}`,title:d("note.copyItem"),children:(0,n.jsx)(el.QR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{var t;return t=e.id,void((0,ed.e)(),U(e=>e.filter(e=>e.id!==t)))},className:"p-1.5 text-text-subtle hover:text-red-400 rounded-brand transition-colors flex-shrink-0",title:d("common.delete"),children:(0,n.jsx)(el.X,{size:13})})]},e.id))}):(0,n.jsx)("p",{className:"text-text-subtle text-sm px-4 py-6 text-center",children:d("note.placeholder")})}),null!==p&&(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-2 border-t border-border flex-shrink-0 overflow-x-auto scrollbar-thin",children:[Q.map(s=>(0,n.jsxs)("div",{className:"flex items-center flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),e?.emit("input",{sessionId:t,data:`${s}
9
+ ${nL(p||[])}`}),setTimeout(()=>e?.emit("input",{sessionId:t,data:"\r"}),eJ.YS),l()},disabled:!G,className:"px-2 py-1 text-[11px] text-text-secondary bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors disabled:opacity-40",title:d("note.sendHint"),children:s}),!eJ.TM.includes(s)&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m(s)},className:"p-1 text-text-subtle hover:text-red-400 transition-colors",title:d("note.removeChip"),children:(0,n.jsx)(el.X,{size:10})})]},s)),z?(0,n.jsx)("form",{onSubmit:e=>{e.preventDefault(),J()},className:"flex items-center flex-shrink-0",children:(0,n.jsx)("input",{value:P,onChange:e=>A(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(M(!1),A(""))},onBlur:J,placeholder:d("note.chipPlaceholder"),autoFocus:!0,className:"w-28 bg-surface-2 border border-border-subtle focus-within:border-brand-500 rounded-brand px-2 py-1 text-[11px] text-text outline-none placeholder:text-text-subtle"})}):(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),M(!0)},className:"p-1 text-text-subtle hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0",title:d("note.addChip"),children:(0,n.jsx)(el.FW,{size:14})})]}),null!==p&&(0,n.jsxs)("form",{onSubmit:q,className:"flex items-end gap-2 p-3 border-t border-border flex-shrink-0",children:[(0,n.jsx)("textarea",{ref:D,value:b,onChange:e=>g(e.target.value),onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&window.innerWidth>=eJ.jK&&q(e)},rows:1,placeholder:d("note.multilinePlaceholder"),className:"flex-1 min-w-0 resize-none bg-surface-2 border border-border-subtle focus-within:border-brand-500 rounded-brand px-3 py-2 text-sm text-text outline-none placeholder:text-text-subtle transition-colors"}),(0,n.jsx)("button",{type:"submit",disabled:!b.trim(),onMouseDown:e=>e.preventDefault(),className:"p-2 bg-brand-500 hover:bg-brand-600 text-white rounded-brand transition-colors disabled:opacity-40 flex-shrink-0",title:d("note.addLines"),children:(0,n.jsx)(el.FW,{size:16})})]})]})})}function nO({onOpenRemote:e,onOpenMobile:t}){let{t:s}=(0,eu.s)(),r=(0,h.B)(e=>e.hiddenHeaderButtons),l=(0,P.rh)(e=>e.hosts[e.currentKey]?.mobileDeviceCount)||0,a="p-1.5 -my-1 text-text hover:bg-surface-2 hover:text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0";return(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),children:[!r.includes("remote")&&e&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),e()},className:a,title:s("menu.remoteDesktop"),children:(0,n.jsx)(el.VA,{size:16})}),!r.includes("mobile")&&t&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),t()},className:`${a} ${l>0?"!text-green-400":""}`,title:l>0?s("mobile.deviceRunning",{count:l}):s("mobile.androidDevice"),children:(0,n.jsx)(el.wO,{size:16})})]})}var nW=s(44976);function n_({isFocused:e,onActivate:t}){let s=s=>(function(e,{isFocused:t,onActivate:s}){let n=e.target;if(n?.closest?.("button,a,label,select,[role='dialog'],[data-pane-control]")){e.preventDefault(),e.stopPropagation();return}"touchstart"!==e.type||n?.closest?.("input, textarea")||e.preventDefault(),t||s?.()})(s,{isFocused:e,onActivate:t});return{onMouseDown:s,onTouchStart:s}}let nH="p-2 sm:p-1.5 bg-surface-2/60 hover:bg-surface-3 text-text rounded-full shadow-md sm:shadow-sm transition-all duration-150 ease-out active:scale-[0.94]",nU="sm:w-3.5 sm:h-3.5",nq=(0,r.memo)(function({bus:e,workspacePath:t,connected:s,sessionId:l,sessionName:a,sessionState:i,isVisible:o,isFocused:c,mountDelay:d=0,onActivate:x,onRegisterApi:m,onPasteFallback:p,showFocusBorder:f=!1,fileBus:b,bgIndex:g=0,onOpenArtifact:v,onOpenRemote:y,onOpenMobile:w}){let{t:j}=(0,eu.s)(),{theme:k}=(0,nW.D)(),N=ez(l),C=i||N||"idle",S=(0,r.useRef)(null),T=(0,r.useRef)(null),R=(0,r.useRef)({width:0,height:null}),[E,$]=(0,r.useState)(null),[z,M]=(0,r.useState)(!1),[A,I]=(0,r.useState)(!1),[D,B]=(0,r.useState)(!1),[F,K]=(0,r.useState)(null),O=(0,h.B)(e=>e.setRightPanelTab),W=(0,h.B)(e=>e.openRightPanel),_=(0,h.B)(e=>e.setRightPanelRoot),H=(0,u.d)(e=>e.bus),U=void 0===e?H:e,q=(0,h.B)(e=>e.cwdBySession[l]),X=(0,h.B)(e=>e.terminalTheme),V=(0,h.B)(e=>e.terminalBackgroundOpacity),J=(0,h.B)(e=>e.customBackgrounds),G=(0,h.B)(e=>e.terminalBackgrounds),Y=(0,h.B)(e=>e.backgroundBySession[l]),Z=(0,eJ.$Z)(Y,G,J,g),Q=(0,h.B)(e=>e.showFolderButton),ee=(0,h.B)(e=>e.showNoteButton),et=(0,h.B)(e=>e.artifactsBySession[l]),es=(0,h.B)(e=>!!e.pinnedNotes?.[l]),en=(0,h.B)(e=>e.setNotePinned),er=es&&ee,ea=(0,r.useRef)(l);(0,r.useEffect)(()=>{ea.current=l},[l]);let[ei,eo]=(0,r.useState)(!1),[ec,ex]=(0,r.useState)(null),em=(0,r.useCallback)(()=>{ej.getState().clearNotification(l)},[l]),ep=(0,eJ.RS)(Z,J),{termRef:ef,cwdRef:eh,cwd:eb,termReady:eg,joining:ev,doResize:ey,reload:ew,focus:ek,stopMomentum:eN,historyFetching:eC}=function({bus:e,sessionId:t,theme:s,terminalTheme:n,isVisible:l,isFocused:a,containerRef:i,mountDelay:o=0,bgKey:c="none",onInput:d,onSelectionMade:x}){let m=(0,r.useCallback)(()=>{let e=P.rh.getState(),s=e$(t).head||e.currentKey;return!!e.hosts[s]?.updating},[t]),p=(0,u.d)(e=>e.bus),f=e||p,b=(0,r.useRef)(null),g=(0,r.useRef)(null),v=(0,r.useRef)(null),y=(0,r.useRef)(null),w=(0,r.useRef)(null),j=(0,r.useRef)(null),k=(0,r.useRef)(null),N=(0,r.useRef)(null),C=(0,r.useRef)(null),S=(0,r.useRef)(null),T=(0,r.useRef)(null),R=(0,r.useRef)(!1),E=(0,r.useRef)(!1),$=(0,r.useRef)(null),z=(0,r.useRef)(null),[M,A]=(0,r.useState)(null),I=(0,h.B)(e=>e.webglEnabled),D=(0,h.B)(e=>e.fontSize),B=(0,r.useRef)(x);(0,r.useEffect)(()=>{B.current=x},[x]);let F=(0,r.useRef)(!1),K=(0,r.useRef)(null),[O,W]=(0,r.useState)(!1),_=(0,r.useRef)(null),H=(0,r.useRef)([]),U=(0,r.useRef)(0),q=(0,r.useRef)(0),X=(0,r.useRef)(!1),V=(0,r.useRef)(0),J=(0,r.useRef)(0),G=(0,r.useRef)(null),Y=(0,r.useRef)(null),Z=(0,r.useRef)(!1),Q=(0,r.useRef)(!1),ee=(0,r.useRef)(null),[et,es]=(0,r.useState)(!1),en=(0,r.useRef)([]),er=(0,r.useRef)(0),el=(0,r.useRef)(null),ea=(0,r.useRef)(null),ei=(0,r.useRef)(null),eo=(0,r.useRef)(l);(0,r.useEffect)(()=>{eo.current=l},[l]);let[ec,eu]=(0,r.useState)(!1),ex=(0,r.useRef)(null),em=(0,r.useRef)(!1),ep=(0,r.useRef)(null),ef=(0,r.useRef)(0),eh=(0,r.useRef)(0),eb=(0,r.useCallback)(()=>{let e=b.current;if(!e||!f)return;let{cols:s,rows:n}=e;s<eJ.j4||n<eJ.dU||(_.current={cols:s,rows:n},f.emit("resize",{sessionId:t,cols:s,rows:n}))},[f,t]),eg=(0,r.useCallback)((e={})=>{let s=!0===e||e?.force===!0,n=!!e?.join;s&&(R.current=!0),n&&(E.current=!0),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{N.current=null;let e=b.current,s=g.current,n=i.current;if(!e||e._isDisposed||!s||!f||!n?.offsetWidth||!n?.offsetHeight)return;s.fit();let{cols:r,rows:l}=e;if(r<eJ.j4||l<eJ.dU)return;let a=_.current,o=R.current,c=E.current;if(R.current=!1,E.current=!1,!o&&a&&a.cols===r&&a.rows===l&&!c){Q.current=!1;return}_.current={cols:r,rows:l},f.emit("resize",{sessionId:t,cols:r,rows:l}),c&&!T.current&&(Q.current=!1),c&&T.current&&(Q.current=!0,e.reset(),T.current(r,l))},eJ.BM)},[f,t,i]);(0,r.useEffect)(()=>{C.current=eg},[eg]),(0,r.useEffect)(()=>{let e,r,l,a;if(!i.current||!f||!t||b.current)return;ef.current=0,Y.current=null;let d=new nj.B({...eJ.Pj,fontSize:(0,eJ.ar)(D),allowTransparency:!0,theme:(0,eJ.pt)((0,nR.In)(s,n)||nE.dark,"dark"===s?c:"none")}),x=new nk.Y;d.loadAddon(x),d.loadAddon(new nC.I),d.unicode.activeVersion="11",b.current=d,g.current=x,d.open(i.current);let m=function(e,t){if(!nI())return()=>{};let s=e?.textarea,n=e?._core,r=n?._compositionHelper;if(!s||!n)return()=>{};let l=r?._handleAnyTextareaChanges,a=r?._finalizeComposition,i=n._inputEvent,o=!1,c="",d="",u=/^[sfrxj12345]$/i;r&&(r._handleAnyTextareaChanges=()=>{},r._finalizeComposition=function(){this._compositionView?.classList.remove("active"),this._isComposing=!1,this._isSendingComposition=!1,d&&(this._coreService.triggerDataEvent(d,!0),d=""),this._textarea&&(this._textarea.value="")});let x=e=>{e.target===s&&(c=e.key||"",o=(229===e.keyCode||229===e.which||"Process"===e.key)&&!e.isComposing)},m=e=>{e.target===s&&(229===e.keyCode||229===e.which)&&setTimeout(()=>{o=!1},50)},p=()=>{o=!1,d=""},f=e=>{e.data&&(d=e.data)},h=e=>{o=!1,e.data&&(d=e.data)};return n._inputEvent=function(e){let t=(e.data||"").replace(/[​-‍ ]/g,""),s=o||t&&/[^\x00-\x7F]/.test(t)||"insertReplacementText"===e.inputType;return(o=!1,s&&t&&!r?._isComposing&&!this.optionsService.rawOptions.screenReaderMode)?(this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._keyDownSeen=!1,t.length>1&&!u.test(c)&&this.coreService.triggerDataEvent("",!0),this.coreService.triggerDataEvent(t,!0),this.cancel(e),this.textarea&&(this.textarea.value=""),!0):i.call(this,e)},s.addEventListener("keydown",x,{capture:!0}),s.addEventListener("keyup",m,{capture:!0}),s.addEventListener("compositionstart",p,{capture:!0}),s.addEventListener("compositionupdate",f,{capture:!0}),s.addEventListener("compositionend",h,{capture:!0}),t&&(t.addEventListener("compositionupdate",f,{capture:!0}),t.addEventListener("compositionend",h,{capture:!0})),()=>{n._inputEvent=i,r&&(l&&(r._handleAnyTextareaChanges=l),a&&(r._finalizeComposition=a)),s.removeEventListener("keydown",x,{capture:!0}),s.removeEventListener("keyup",m,{capture:!0}),s.removeEventListener("compositionstart",p,{capture:!0}),s.removeEventListener("compositionupdate",f,{capture:!0}),s.removeEventListener("compositionend",h,{capture:!0}),t&&(t.removeEventListener("compositionupdate",f,{capture:!0}),t.removeEventListener("compositionend",h,{capture:!0}))}}(d,i.current),p=function(e){if(!nI()||!e)return()=>{};let t=!1,s=e=>{0===e.button&&(t=!0)},n=e=>{0===e.button&&(t=!1)},r=e=>{if(!t||0!==e.buttons)return;t=!1,e.stopImmediatePropagation();let s=new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,button:0,buttons:0,clientX:e.clientX,clientY:e.clientY,screenX:e.screenX,screenY:e.screenY,ctrlKey:e.ctrlKey,metaKey:e.metaKey,altKey:e.altKey,shiftKey:e.shiftKey});document.dispatchEvent(s)},l=()=>{if(t){t=!1;let e=new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,button:0,buttons:0});document.dispatchEvent(e)}};return e.addEventListener("mousedown",s),e.addEventListener("mouseup",n),e.addEventListener("pointercancel",l),e.addEventListener("mouseleave",l),document.addEventListener("mousemove",r,!0),window.addEventListener("blur",l),()=>{e.removeEventListener("mousedown",s),e.removeEventListener("mouseup",n),e.removeEventListener("pointercancel",l),e.removeEventListener("mouseleave",l),document.removeEventListener("mousemove",r,!0),window.removeEventListener("blur",l)}}(i.current);e=[],r=0,l=null,v.current={write:t=>{let s=t instanceof Uint8Array||"string"==typeof t?t.length:String(t).length;s<=512&&0===r&&null===l?d.write(t instanceof Uint8Array||"string"==typeof t?t:String(t)):(e.push(t instanceof Uint8Array||"string"==typeof t?t:String(t)),r+=s,null===l&&(l=requestAnimationFrame(a)))},flush:a=()=>{if(l=null,e.length){if(1===e.length)d.write(e[0]);else if(e.every(e=>e instanceof Uint8Array)){let t=new Uint8Array(r),s=0;for(let n of e)t.set(n,s),s+=n.length;d.write(t)}else{let t="";for(let s of e)t+="string"==typeof s?s:new TextDecoder().decode(s);d.write(t)}e=[],r=0}},dispose:()=>{null!==l&&cancelAnimationFrame(l),l=null,e=[],r=0}},eJ.M8.search&&(K.current=new nS.n,d.loadAddon(K.current));let R=i.current,E=e=>{d.options.smoothScrollDuration=0!==e.deltaMode||Math.abs(e.deltaY)>=50?eJ.Gp.smoothScrollDuration:0};R.addEventListener("wheel",E,{passive:!0});let $=null,M=!1;w.current=()=>{if(!$&&!M&&"off"!==eJ.Gp.gpuAcceleration)try{y.current=$=new nN.o,$.onContextLoss(()=>{$?.dispose(),$=null,y.current=null}),d.loadAddon($),eJ.M8.image&&d.loadAddon(new nT.W),x.fit()}catch(e){M=!0,$=null,console.warn("WebGL unavailable, using DOM renderer")}},j.current=()=>{y.current&&(y.current.dispose(),y.current=null,$=null,x.fit(),eb(),d.refresh(0,d.rows-1))};let P=0,I=()=>{P++;let e=i.current?.offsetWidth||0,t=i.current?.offsetHeight||0;P>50?W(!0):d.element&&e>=100&&t>=100?(x.fit(),eb(),W(!0)):setTimeout(I,50)};setTimeout(I,50);let B=new ResizeObserver(()=>C.current?.());B.observe(i.current);let O=function({fetchOlder:e,isAtTop:t,max:s,delayMs:n}){let r=0,l=null,a=()=>{l&&(clearTimeout(l),l=null)};return{gesture(){a(),e(!1)&&(r=0)},settled(){if(!t()){r=0;return}r>=s||(r+=1,a(),l=setTimeout(()=>{l=null,e(!0)},n))},cancel:a}}({fetchOlder:(e=!1)=>{let s=d.buffer.active;if(eJ.iW.disabled||X.current||"alternate"===s.type||q.current<=0||q.current-U.current<eJ.iW.minFetchBytes)return!1;let n=Date.now();if(!e&&n-V.current<eJ.iW.guardMs)return!1;let r=s.viewportY<=eJ.iW.topThresholdLines;return(!!e||!!em.current)&&(r?!!u.d.getState().connected&&(X.current=!0,V.current=n,J.current=U.current,eu(!0),f.emit("requestHistory",{sessionId:t,have:J.current},e=>{if(!e||!e.success){X.current=!1,eu(!1);return}e.prefixLen||(X.current=!1,eu(!1)),q.current=e.total||q.current}),!0):(e||(em.current=!1),!1))},isAtTop:()=>(d.buffer.active.viewportY??0)<=eJ.iW.topThresholdLines,max:eJ.iW.chainMax,delayMs:eJ.iW.chainDebounceMs});ep.current=()=>O.settled();let _=()=>O.gesture();el.current=d.onScroll(()=>{(d.buffer.active.viewportY??0)>eJ.iW.topThresholdLines&&(em.current=!1)}),d.textarea?.addEventListener("keyup",_),ex.current=_;let et=null,ec=null,ed=!1,eg=0,ev=function({emit:e,writeChunk:t,flush:s,onGapChunk:n,onFallback:r,log:l,getFromSeq:a}){let i=null,o=e=>{clearTimeout(e.timer),e.timer=setTimeout(()=>d(e,"stalled"),eJ.VE)},c=e=>{if(!e.settled&&i===e){for(let s of(e.settled=!0,clearTimeout(e.timer),e.timer=null,e.pending))t(s.data),null!=s.seq&&n(s.seq);s?.(),i=null,l(`gap recovered (${e.received}/${e.expected} chunks, ${e.pending.length} pending flushed)`)}},d=(e,t)=>{e.settled||i!==e||(e.settled=!0,clearTimeout(e.timer),e.timer=null,i=null,l(`gap ${t} (${e.fromSeq}..${e.toSeq}) → reset+rejoin`),r())};return{start:function(t,s=[]){if(i)return;let n=a();if(t<n)return;l(`seq gap (last=${n-1} → ${t+1}) → requestGap ${n}..${t}`);let r={pending:[...s],fromSeq:n,toSeq:t,settled:!1,timer:null,expected:null,received:0,seen:new Set};i=r,o(r),e({fromSeq:n,toSeq:t},e=>{if(!r.settled&&i===r){if(!e?.hit)return d(r,"miss");r.expected=e.count??0,r.received>=r.expected&&c(r)}})},queueLive:function(e,t){return!!i&&(i.pending.push({data:e,seq:t}),!0)},handleGapChunk:function(e,s){let r=i;return!!r&&null!=s&&!(s<r.fromSeq)&&!(s>r.toSeq)&&(!!r.seen.has(s)||(o(r),t(e),n(s),r.seen.add(s),r.received=r.seen.size,null!=r.expected&&r.received>=r.expected&&c(r),!0))},cancel:function(){i&&(clearTimeout(i.timer),i=null)},isBusy:()=>null!==i}}({emit:(e,s)=>f.emit("requestGap",{sessionId:t,...e},s),writeChunk:e=>{let t=v.current;nP(d,e,H,U,t),t?.flush()},flush:()=>v.current?.flush(),onGapChunk:e=>{Y.current=e},onFallback:()=>ee.current?.("gap fallback"),log:e=>(0,L.Lq)("reconnect",e),getFromSeq:()=>(Y.current??0)+1}),ey=e=>{if(b.current){if(!u.d.getState().connected){ea.current=e;return}ea.current=null,(0,L.Lq)("reconnect",`reset+rejoin (${e})`),Q.current=!0,S.current?.(!0)}};ee.current=ey;let ew=e=>{if(!eo.current||ed){ea.current=e;return}et&&clearTimeout(et),et=setTimeout(()=>(e=>{if(et=null,!eo.current||!u.d.getState().connected){ea.current=e;return}if(n$({joinClaimed:Q,joining:Z,gapBusy:ev.isBusy()}))return;if(null==Y.current)return ey(`${e}: no seq baseline`);let s=++eg;ed=!0,ec=setTimeout(()=>{ec=null,ed=!1,eg++,(0,L.Lq)("reconnect",`${e}: peekSeq timed out → retry`),ea.current=ea.current||e,ej()},eJ.zm),f.emit("peekSeq",{sessionId:t},t=>{if(s!==eg)return;clearTimeout(ec),ec=null,ed=!1;let n=t?.seq;if(null==n)return ey(`${e}: agent has no seq`);let r=Y.current??0;return n<r?ey(`${e}: seq rewound ${r} → ${n}`):n===r?((0,L.Lq)("reconnect",`${e}: nothing missed (seq ${r})`),ej()):n$({joinClaimed:Q,joining:Z,gapBusy:ev.isBusy()})?ej():void((0,L.Lq)("reconnect",`${e}: peekSeq ${r} → ${n} → gapFetch`),ev.start(n))})})(e),eJ.qw)};function ej(){let e=ea.current;e&&(ea.current=null,ew(e))}ei.current=ew;let{handleOutput:ek}=function({sessionId:e,term:t,writeBatcherRef:s,gapFetch:n,refs:r,setHistoryFetching:l}){let a=e=>{var s;let n,a=nz(e),i=t.buffer.active.viewportY,o=t.buffer.active.baseY;a=function(e,{haveAtEmit:t,historyBytes:s}){let n=Math.max(0,t>0?s-t:0);if(n<=0)return e;let r=Math.max(0,nM(e)-n);return"string"!=typeof e&&(r=function(e,t){if(t<=0)return 0;if(t>=e.byteLength)return e.byteLength;for(let s=t;s>0&&t-s<512;s--)if(27===e[s])return s;return t}(e,r)),"string"==typeof e?e.slice(0,r):e.subarray(0,r)}(a,{haveAtEmit:r.historyHaveAtEmitRef.current,historyBytes:r.historyBytesRef.current}),r.historyHaveAtEmitRef.current=0;let c=nM(a);if(0===c){r.historyFetchingRef.current=!1,l(!1),r.onPrefixSettledRef?.current?.();return}r.historyMirrorRef.current.unshift(a),r.historyBytesRef.current+=c,t.reset(),t.write((s=r.historyMirrorRef.current,n=new TextDecoder,s.map(e=>"string"==typeof e?e:n.decode(e,{stream:!0})).join("")),()=>{requestAnimationFrame(()=>{let e=function({oldViewportY:e,baseYBefore:t,baseYAfter:s}){return Math.max(0,Math.min(e+Math.max(0,s-t),s))-s}({oldViewportY:i,baseYBefore:o,baseYAfter:t.buffer.active.baseY});e<0&&t.scrollLines(e),r.historyFetchingRef.current=!1,l(!1),r.onPrefixSettledRef?.current?.()})})};return{handleOutput:l=>{if(l.sessionId!==e)return;l.data instanceof ArrayBuffer&&(l={...l,data:new Uint8Array(l.data)}),r.lastOutputAtRef.current=Date.now();let i=l.data?.length||0;r.outputTotalRef.current+=i,(l.replay||l.isHistoryPrefix)&&(0,L.Lq)("recv",`len=${i} replay=${!!l.replay} prefix=${!!l.isHistoryPrefix} total=${r.outputTotalRef.current}`);let o=l.data;if("b64"===l.enc&&"string"==typeof o)if("function"==typeof Uint8Array.fromBase64)o=Uint8Array.fromBase64(o);else{let e=atob(o),t=new Uint8Array(e.length);for(let s=0;s<e.length;s++)t[s]=e.charCodeAt(s);o=t}if(r.awaitingTuiOutputRef.current=!1,l.isHistoryPrefix){if(l.parts>1){let e=r.prefixFragsRef.current;if(0!==l.part&&e&&e.parts===l.parts||(e={parts:l.parts,chunks:[]},r.prefixFragsRef.current=e),e.chunks[l.part]=o,e.chunks.filter(Boolean).length<l.parts)return;r.prefixFragsRef.current=null,(0,L.Lq)("recv",`prefix reassembled from ${l.parts} parts (${e.chunks.reduce((e,t)=>e+t.length,0)}B)`);let t=new Uint8Array(e.chunks.reduce((e,t)=>e+t.length,0)),s=0;for(let n of e.chunks)t.set(n,s),s+=n.length;a(t);return}a(o);return}if(l.replay){let e=nz(o);s.current?.write(e),s.current?.flush(),null!=l.seq&&(r.lastSeqRef.current=l.seq);return}if(l.gap)return void n.handleGapChunk(o,l.seq);if(r.joiningRef.current)return void r.joinQueueRef.current.push({data:o,seq:l.seq});if(!n.queueLive(o,l.seq)){if(null!=l.seq){var c,d;let e=(c=r.lastSeqRef.current,d=l.seq,null==c?"init":d===c+1?"none":d>c+1?"gap":nA);if("gap"===e)return void n.start(l.seq-1,[{data:o,seq:l.seq}]);if(e===nA)return;r.lastSeqRef.current=l.seq}r.userAtTopRef.current=!1,nP(t,o,r.historyMirrorRef,r.historyBytesRef,s.current)}},replayWithPrefix:a}}({sessionId:t,term:d,writeBatcherRef:v,gapFetch:ev,refs:{joiningRef:Z,joinQueueRef:en,lastSeqRef:Y,lastOutputAtRef:ef,outputTotalRef:eh,awaitingTuiOutputRef:F,userAtTopRef:em,historyFetchingRef:X,historyHaveAtEmitRef:J,historyMirrorRef:H,historyBytesRef:U,prefixFragsRef:G,onPrefixSettledRef:ep},setHistoryFetching:eu});f.on("output",ek);let eN=e=>{e&&e.sessionId===t&&e.cwd&&(z.current=e.cwd,A(e.cwd),h.B.getState().setCwd(t,e.cwd))};f.on("cwdChange",eN);let eC=function({bus:e,sessionId:t,term:s,fitAddon:n,writeBatcherRef:r,doResizeRef:l,fireJoinRef:a,refs:i,setCwd:o}){let c=null,d=(u=!1)=>{i.historyMirrorRef.current=[],i.historyBytesRef.current=0,i.historyTotalRef.current=0,i.historyFetchingRef.current=!1,i.userAtTopRef.current=!1,requestAnimationFrame(()=>l.current?.({join:!0})),a.current=(l,a)=>{let u=h.B.getState().agentCaps?.joinSessionSize?{sessionId:t,cols:l,rows:a}:t;i.joiningRef.current=!0,i.setJoining(!0),i.joinQueueRef.current=[];let x=++i.joinGenRef.current;(0,L.Lq)("join",`emit gen=${x} sid=${String(t).slice(-8)} cols=${l} rows=${a}`),c&&clearTimeout(c),c=setTimeout(()=>{if(c=null,x!==i.joinGenRef.current)return;(0,L.Lq)("join",`ack timeout gen=${x} (${eJ.eE}ms) → clear spinner`),i.joiningRef.current=!1,i.joinClaimedRef.current=!1,i.setJoining(!1);let e=i.joinQueueRef.current;i.joinQueueRef.current=[];let t=r.current;for(let n of e)nP(s,n&&"object"==typeof n&&"data"in n?n.data:n,i.historyMirrorRef,i.historyBytesRef,t);t?.flush()},eJ.eE),e.emit("joinSession",u,l=>{if(c&&(clearTimeout(c),c=null),x!==i.joinGenRef.current)return void(0,L.Lq)("join",`stale ack gen=${x} (current=${i.joinGenRef.current})`);let a=l||{};if((0,L.Lq)("join",`ack gen=${x} sid=${String(t).slice(-8)} success=${!!a.success} total=${a.total} replaySize=${a.replaySize}`),a.success){setTimeout(()=>{if(x!==i.joinGenRef.current||s._core?._isDisposed)return;let e=i.joinQueueRef.current;i.joinQueueRef.current=[];let t=r.current,n=null;for(let r of e){let e=r&&"object"==typeof r&&"data"in r?r.data:r;r?.seq!=null&&(n=r.seq),nP(s,e,i.historyMirrorRef,i.historyBytesRef,t)}let l=a.seq??null;(null!=l||null!=n)&&(i.lastSeqRef.current=Math.max(l??-1,n??-1)),t?.flush(),i.joiningRef.current=!1,i.joinClaimedRef.current=!1,i.setJoining(!1)},0),i.historyTotalRef.current=a.total||0,a.cwd&&(i.cwdRef.current=a.cwd,o(a.cwd),h.B.getState().setCwd(t,a.cwd));let l=h.B.getState().consumeStartup(t);l&&((0,L.Lq)("join",`startup cmd queued (${l})`),setTimeout(()=>e.emit("input",{sessionId:t,data:`${l}\r`}),eJ.YA)),setTimeout(()=>n.fit(),200)}else{if("rtc-closed"===a.error){(0,L.Lq)("join","rtc-closed during join ack → retry via fallback carrier"),d(!0);return}i.joiningRef.current=!1,i.joinClaimedRef.current=!1,i.setJoining(!1),i.joinQueueRef.current=[],s.write(`\r
10
+ \x1b[1;31mError: ${a.error||"Failed to join session"}\x1b[0m\r
11
+ `)}})}};return d}({bus:f,sessionId:t,term:d,fitAddon:x,writeBatcherRef:v,doResizeRef:C,fireJoinRef:T,refs:{historyMirrorRef:H,historyBytesRef:U,historyTotalRef:q,historyFetchingRef:X,userAtTopRef:em,joiningRef:Z,joinClaimedRef:Q,joinQueueRef:en,joinGenRef:er,lastSeqRef:Y,cwdRef:z,setJoining:es},setCwd:A}),eS=o>0?setTimeout(eC,o):null;eS||eC(),S.current=eC;let eT=()=>{if(b.current){var e;(e={historyFetching:X,historyHaveAtEmit:J,awaitingTuiOutput:F,joining:Z,joinClaimed:Q,joinQueue:en,prefixFrags:G}).historyFetching&&(e.historyFetching.current=!1),e.historyHaveAtEmit&&(e.historyHaveAtEmit.current=0),e.awaitingTuiOutput&&(e.awaitingTuiOutput.current=!1),e.joining&&(e.joining.current=!1),e.joinClaimed&&(e.joinClaimed.current=!1),e.joinQueue&&(e.joinQueue.current=[]),e.prefixFrags&&(e.prefixFrags.current=null),e.awaitingGap&&(e.awaitingGap.current?.timer&&clearTimeout(e.awaitingGap.current.timer),e.awaitingGap.current=null),ev.cancel(),O.cancel(),clearTimeout(ec),ec=null,ed=!1,eg++,eu(!1),es(!1),ew("reconnect")}};f.on("connect",eT);let eR=()=>setTimeout(()=>{let e=b.current,t=g.current;e&&!e._isDisposed&&t&&(t.fit(),t.fit(),C.current?.({force:!0}))},eJ.Uc);window.addEventListener("orientationchange",eR);let eE=()=>{!document.hidden&&b.current&&(b.current.refresh(0,b.current.rows-1),u.d.getState().connected&&ew("visible"))};return document.addEventListener("visibilitychange",eE),()=>{window.removeEventListener("orientationchange",eR),document.removeEventListener("visibilitychange",eE),B.disconnect(),R.removeEventListener("wheel",E),f.off("connect",eT),f.off("output",ek),f.off("cwdChange",eN),el.current&&el.current.dispose(),ep.current=null,d.textarea?.removeEventListener("keyup",_),k.current&&k.current.dispose(),N.current&&clearTimeout(N.current),ev.cancel(),eS&&clearTimeout(eS),et&&clearTimeout(et),ec&&clearTimeout(ec),y.current&&y.current.dispose(),v.current&&v.current.dispose(),m(),p(),x.dispose(),d.dispose(),b.current=null,W(!1)}},[f,t]),(0,r.useEffect)(()=>{let e=b.current,s=g.current;e&&s&&f&&t&&(I?w.current?.():j.current?.())},[I,f,t]),(0,r.useEffect)(()=>{let e=b.current,s=g.current;e&&s&&f&&t&&null!=D&&(e.options.fontSize=D,s.fit(),eb(),e.refresh(0,e.rows-1))},[D,f,t,eb]),(0,r.useEffect)(()=>{b.current&&f&&t&&(k.current&&(k.current.dispose(),k.current=null),a&&(k.current=b.current.onData(e=>{(Z.current||X.current)&&(0,eJ.Nz)(e)||m()||((0,eJ.b9)(e)&&d?.(t),f.emit("input",{sessionId:t,data:e}))})))},[a,f,t,d,m]),(0,r.useEffect)(()=>{if(!b.current||!f||!t||a)return;let e=b.current.onData(e=>{!m()&&(e.startsWith("\x1b[<")||e.startsWith("\x1b[M"))&&f.emit("input",{sessionId:t,data:e})});return()=>e.dispose()},[a,f,t,m]),(0,r.useEffect)(()=>{if(!l||!g.current||!b.current)return;let e=setTimeout(()=>{if(ea.current){let e=ea.current;ea.current=null,(0,L.Lq)("reconnect",`deferred recover → fire (pane now visible, ${e})`),ei.current?.(e)}eg({force:!0}),requestAnimationFrame(()=>b.current?.refresh(0,b.current.rows-1))},100);return()=>clearTimeout(e)},[l,eg]),(0,r.useEffect)(()=>{if(!a)return;let e=window.innerWidth<760,t=setTimeout(()=>{eg(e?{force:!0}:void 0),requestAnimationFrame(()=>b.current?.refresh(0,b.current.rows-1))},100);return()=>clearTimeout(t)},[a,eg]),(0,r.useEffect)(()=>{let e=b.current;if(!e)return;let t="dark"===s?c:"none";e.options.theme=(0,eJ.pt)((0,nR.In)(s,n)||nE.dark,t),e.refresh(0,e.rows-1)},[s,n,c]),function({termRef:e,termReady:t,isVisible:s,bus:n,sessionId:l,onSelectionMadeRef:a,awaitingTuiOutputRef:i,maybeFetchHistoryRef:o,userAtTopRef:c,stopMomentumRef:d}){(0,r.useEffect)(()=>{if(!t||!e.current)return;let s=e.current.element?.querySelector(".xterm-screen");if(!s)return;let r=0,u=0,x=0,m=null,p=0,f=0,h=eJ.Il.sensitivity,b=eJ.Il.lineHeight,g=eJ.Il.friction,v=eJ.Il.minVelocity,y=eJ.Il.maxVelocity,w=eJ.Il.tuiThrottleMs,j=eJ.Il.momentumRenderCadenceMs,k=eJ.Il.tuiBackpressureTimeoutMs,N=0,C=0,S=null,T=()=>{if(S=null,!C)return;let t=e.current;if(!t){C=0;return}let s=Math.max(1,Math.ceil(t.cols/2)),r=Math.max(1,Math.ceil(t.rows/2)),a=C>0?eJ.Il.sgrDown(s,r):eJ.Il.sgrUp(s,r),o=Math.min(Math.abs(C),eJ.Il.wheelStepLines);for(let e=0;e<o;e++)n.emit("input",{sessionId:l,data:a});C=0,N=performance.now(),i.current=!0},R=t=>{let s=e.current;if(s)if("alternate"===s.buffer.active.type){if(i.current&&performance.now()-N<k)return;C+=t;let e=performance.now()-N;e>=w?T():S||(S=setTimeout(T,w-e))}else s.scrollLines(Math.max(-3,Math.min(3,t))),t<0&&s.buffer.active.viewportY<=eJ.iW.topThresholdLines&&(c.current=!0,o.current?.())},E=()=>{m&&(cancelAnimationFrame(m),m=null),x=0},$=()=>{if(!e.current||Math.abs(x)<v){m=null;return}let t=e.current.buffer?.active?.type==="alternate",s=performance.now(),n=t&&i.current&&s-N<k,r=!t&&s-f>=j;if(!n&&(t||r)){x*=g;let e=Math.trunc((p+=x)/b);0!==e&&(R(e),p-=e*b,f=performance.now())}m=requestAnimationFrame($)},z=null,M=!1,P=null,A=0,I=0,D=0,L=0,B=!1,F=null,K=(t,n)=>{let r=e.current,l=F||s.getBoundingClientRect(),a=l.width/r.cols,i=l.height/r.rows,o=Math.max(0,Math.min(r.cols-1,Math.floor((t-l.left)/a))),c=Math.max(0,Math.min(r.rows-1,Math.floor((n-l.top)/i)));return{col:o,row:r.buffer.active.viewportY+c}},O=t=>{E();let n=t.touches[0];r=n.clientY,A=D=n.clientX,I=L=n.clientY,u=Date.now(),x=0,p=0,M=!1,B=!1,e.current?.clearSelection(),z=setTimeout(()=>{!B&&e.current&&(M=!0,(0,ed.e)(),F=s.getBoundingClientRect(),(({col:t,row:s})=>{let n=e.current,r=n.buffer.active.getLine(s);if(!r)return;let l=r.translateToString(!1),a=e=>e&&eJ.FC.wordChars.test(e);if(!a(l[t]))return n.select(t,s,1);let i=t,o=t;for(;i>0&&a(l[i-1]);)i--;for(;o<l.length-1&&a(l[o+1]);)o++;n.select(i,s,o-i+1)})(P=K(A,I)))},eJ.FC.longPressMs)},W=t=>{if(!e.current)return;let n=t.touches[0];if(D=n.clientX,L=n.clientY,!B&&Math.hypot(D-A,L-I)>eJ.FC.moveTolerance&&(B=!0,M||clearTimeout(z)),M){t.preventDefault();var l=K(D,L);let s=e.current;if(l.row===P.row){let e=Math.min(l.col,P.col);s.select(e,l.row,Math.abs(l.col-P.col)+1)}else s.selectLines(Math.min(l.row,P.row),Math.max(l.row,P.row));return}let a=n.clientY,i=Date.now(),o=r-a,c=i-u||1,d=s.closest(".terminal-scroll.is-scrollable");if(d&&d.scrollHeight>d.clientHeight+1){let e=d.scrollHeight-d.clientHeight,s=d.scrollTop<=.5,n=d.scrollTop>=e-.5;if(!(o<0&&s||o>0&&n)){0!==o&&(t.preventDefault(),d.scrollTop=Math.max(0,Math.min(e,d.scrollTop+o))),r=a,u=i,x=0,p=0;return}}let m=o*h,f=Math.trunc((p+=m)/b);0!==f&&(t.preventDefault(),R(f),p-=f*b),x=Math.min(m/c*16,y),r=a,u=i},_=()=>{if(clearTimeout(z),F=null,M){M=!1;let t=e.current?.getSelection();t&&t.trim()&&a.current?.(t,{x:D,y:L});return}Math.abs(x)>v&&(m=requestAnimationFrame($))};d.current=E,s.addEventListener("touchstart",O,{passive:!0}),s.addEventListener("touchmove",W,{passive:!1}),s.addEventListener("touchend",_,{passive:!0});let H=t=>{let s=e.current;s&&t.deltaY<0&&s.buffer.active.viewportY<=eJ.iW.topThresholdLines&&(c.current=!0,o.current?.())};return s.addEventListener("wheel",H,{passive:!0}),()=>{E(),d.current=null,clearTimeout(z),s.removeEventListener("touchstart",O),s.removeEventListener("touchmove",W),s.removeEventListener("touchend",_),s.removeEventListener("wheel",H)}},[t,s,e,n,l,a,i,o,c,d])}({termRef:b,termReady:O,isVisible:l,bus:f,sessionId:t,onSelectionMadeRef:B,awaitingTuiOutputRef:F,maybeFetchHistoryRef:ex,userAtTopRef:em,stopMomentumRef:$});let ev=(0,r.useCallback)(()=>{let e=b.current;e&&f&&((0,L.Lq)("join","manual reload (user refetch)"),S.current?.(!0),I?(j.current?.(),w.current?.()):e.refresh(0,e.rows-1))},[f,I]);return{termRef:b,cwdRef:z,cwd:M,searchAddonRef:K,termReady:O,joining:et,doResize:eg,reload:ev,focus:()=>b.current?.focus(),stopMomentum:()=>$.current?.(),historyFetching:ec}}({bus:U,sessionId:l,theme:k,terminalTheme:X,isVisible:o,isFocused:c,containerRef:S,mountDelay:d,bgKey:ep?Z:"none",onInput:em,onSelectionMade:(e,t)=>K({text:e,x:t.x,y:t.y})}),eS=(0,r.useCallback)(()=>{let e=T.current,t=ef.current;if(!e||!t)return;let s=R.current.height;if(null==s||e.clientHeight>=s-1)return;let n=t.buffer.active,r=n.baseY+n.cursorY,l=t.element?.querySelector(".xterm-screen")?.getBoundingClientRect()?.height?t.element.querySelector(".xterm-screen").getBoundingClientRect().height/t.rows:0;if(l<=0){e.scrollTop=e.scrollHeight;return}let a=e.clientHeight;if((n.baseY+t.rows)*l<=s){e.scrollTop=0;return}let i=Math.max(0,Math.min(r*l-a+2*l,e.scrollHeight-e.clientHeight));e.scrollTop=i},[ef]);(0,r.useEffect)(()=>{let e=T.current;if(!e)return;let t=0,s=()=>{if(window.innerWidth>=eJ.jK){R.current={width:0,height:null},t=0,$(null),M(!1);return}let s=e.clientWidth,n=e.clientHeight;if(n<=0)return;let r=R.current;s!==r.width||null==r.height||n>=r.height-2?(R.current={width:s,height:n},$(n),t=n,M(!1)):null!=r.height&&n<r.height&&n<t-8?(t=n,M(!0),requestAnimationFrame(eS)):t=n};s();let n=new ResizeObserver(s);return n.observe(e),window.addEventListener("orientationchange",s),()=>{n.disconnect(),window.removeEventListener("orientationchange",s)}},[eS]);let eT=(0,n.jsx)(nO,{onOpenRemote:y,onOpenMobile:w});(0,r.useEffect)(()=>{if(m)return m(l,{focus:ek,doResize:ey}),()=>m(l,null)},[l,ek,ey,m]);let eR=(0,nR.In)(k,X)||nE.dark;(0,r.useEffect)(()=>{if(!eg||!ef.current||!o)return;let e=ef.current,t=()=>{let t=T.current,s=!!t?.classList.contains("is-scrollable")&&t.scrollHeight>t.clientHeight+1&&t.scrollHeight-t.clientHeight-t.scrollTop>5,n=e.buffer.active,r=n.baseY-n.viewportY>5;I(s||r)},s=null,n=()=>{s||(s=requestAnimationFrame(()=>{s=null,t()}))};t();let r=e.onScroll(n),l=()=>n();return T.current?.addEventListener("scroll",l,{passive:!0}),()=>{s&&cancelAnimationFrame(s),r.dispose(),T.current?.removeEventListener("scroll",l),I(!1)}},[ef,eg,o]);let eE=nw(eb,b,{enabled:o}),eM=eE>eJ.KN?`${eJ.KN}+`:eE,eP=n_({isFocused:c,onActivate:()=>x?.(l)}),eA=[f&&c?"terminal-focus-glow":""].filter(Boolean).join(" "),eI=`rgba(${eJ.c},${V??eJ._z})`,eD=`rgba(${eJ.pZ},${eJ.B$})`;return U?(0,n.jsxs)("div",{className:`h-full w-full flex flex-col overflow-hidden relative touch-none px-1.5 py-1.5 ${eA}${ep?" terminal-has-bg":""}`,style:ep?{background:`linear-gradient(${eI},${eI}), linear-gradient(${eD},${eD}), center / cover no-repeat url("${ep}")`,backgroundBlendMode:"normal, screen, normal"}:{background:eR.background},onMouseDown:eP.onMouseDown,onTouchStart:eP.onTouchStart,children:[!er&&(0,n.jsxs)("div",{style:{height:26},className:"sm:hidden flex items-center gap-2 px-2 -mt-1.5 -mx-1.5 mb-1.5 flex-shrink-0 bg-surface border-b border-border-subtle text-[11px] select-none relative z-10",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${st(C)}`,style:{background:se(C).dot}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",children:a||j("terminal.defaultName")}),eT]}),er&&(0,n.jsx)(nK,{bus:U,sessionId:l,variant:"pinned",rightSlot:eT}),(0,n.jsxs)("div",{ref:T,className:`terminal-wrapper terminal-scroll flex-1 min-h-0 relative ${z?" is-scrollable":""}`,children:[(0,n.jsx)("div",{ref:S,className:"xterm-screen w-full rounded-sm overflow-hidden",style:null!=E?{height:E,minHeight:E}:{height:"100%",minHeight:"100%"}}),(ev||!eg)&&(0,n.jsx)("div",{className:"absolute inset-0 z-40 flex items-center justify-center pointer-events-none",children:(0,n.jsx)("span",{className:"w-6 h-6 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"})}),eC&&(0,n.jsx)("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-40 pointer-events-none",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-surface-2/80 backdrop-blur-sm shadow-md text-xs text-text-secondary",children:[(0,n.jsx)("span",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),"Loading history…"]})}),F&&(0,n.jsx)(ng,{text:F.text,position:F,onOpenUrl:e=>window.open(e,"_blank"),onCopy:e=>{try{navigator.clipboard?.writeText(e)}catch{}},onAddToNote:e=>{K(null),ex(e),eo(!0)},onClose:()=>{ef.current?.clearSelection(),K(null)}})]}),A&&(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{let t;e.stopPropagation(),(0,ed.e)(),eN(),t=T.current,t?.classList.contains("is-scrollable")&&t.scrollHeight>t.clientHeight+1&&(t.scrollTop=t.scrollHeight),ef.current?.scrollToBottom()},className:"absolute bottom-3 right-5 z-[2] p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-full shadow-md transition-all duration-150 ease-out active:scale-[0.94] touch-none",title:j("terminalPane.scrollToBottom"),children:(0,n.jsx)(el.yQ,{size:20})}),c&&(0,n.jsxs)("div",{className:`absolute right-2 z-[2] flex flex-col items-end gap-2 pointer-events-auto touch-none ${er?"top-9":"top-9 sm:top-2"}`,children:[(0,n.jsxs)("div",{className:"flex flex-row gap-2",children:[ee&&(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,ed.e)(),ex(null),eo(!0)},className:nH,title:j("terminalPane.note"),children:(0,n.jsx)(el.y8,{size:16,className:nU})}),(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),D||((0,ed.e)(),B(!0),ew(),setTimeout(()=>B(!1),700))},className:nH,title:j("terminalPane.refresh"),children:(0,n.jsx)(el.e9,{size:16,className:`${nU} ${D?"animate-spin":""}`})})]}),Q&&(eb||t)&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,ed.e)(),_(t,q||t),window.innerWidth>=eJ.jK?O("files",t):W()},className:`relative ${nH}`,title:j("terminalPane.openFolderHere"),children:[(0,n.jsx)(el.vd,{size:16,className:nU}),eE>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:eM})]}),v&&et?.length>0&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,ed.e)(),v(l,et[0])},className:`relative ${nH}`,title:j("terminalPane.artifacts"),children:[(0,n.jsx)(el.sU,{size:16,className:nU}),(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:et.length})]})]}),ei&&ee&&(0,n.jsx)(nK,{bus:e,sessionId:l,appendOnOpen:ec,pinned:es,onPin:e=>en(l,e),onClose:()=>{eo(!1),ex(null)}})]}):(0,n.jsxs)("div",{className:"h-full w-full flex items-center justify-center gap-2 text-text-muted text-xs",children:[(0,n.jsx)(el.kr,{size:13,className:"animate-spin"}),(0,n.jsx)("span",{children:j("hosts.connecting")})]})},(e,t)=>e.bus===t.bus&&e.sessionId===t.sessionId&&e.isVisible===t.isVisible&&e.isFocused===t.isFocused&&e.bgIndex===t.bgIndex&&e.connected===t.connected&&e.showFocusBorder===t.showFocusBorder&&e.sessionName===t.sessionName&&e.sessionState===t.sessionState&&e.onOpenArtifact===t.onOpenArtifact);function nX({items:e,size:t=12,label:s="",revealCls:l="",className:a="",anchor:i=null,onClose:o}){let c=e.filter(Boolean),[d,u]=(0,r.useState)(null),x=i??d,m=null!==x,p=(0,r.useRef)(null),f=s_(p,x?.left??0,x?.top??0),h=(0,r.useCallback)(()=>{u(null),o?.()},[o]);return((0,r.useEffect)(()=>{if(!m)return;let e=e=>{"Escape"===e.key&&(e.stopPropagation(),h())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[m,h]),c.length)?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:e=>{if(e.stopPropagation(),(0,ed.e)(),m)return void h();let t=e.currentTarget.getBoundingClientRect();u({left:t.left,top:t.bottom+2})},className:`p-0.5 text-text-subtle hover:text-text rounded-[2px] hover:bg-surface-2 transition-colors ${l} ${a}`,title:s,"aria-label":s,"aria-haspopup":"menu",children:(0,n.jsx)(el.a4,{size:t})}),m&&"u">typeof document&&(0,sd.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-[69]",onPointerDown:e=>{e.stopPropagation(),h()},onClick:e=>{e.stopPropagation(),h()},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),h()}}),(0,n.jsx)("div",{ref:p,role:"menu",className:"fixed z-[70] menu-popover p-1 min-w-[160px] animate-in fade-in zoom-in-95 duration-100 shadow-xl",style:{left:f.left,top:f.top},children:c.map(({icon:e,label:t,danger:s,amber:r,onClick:l})=>(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),h(),l?.()},className:`w-full text-left px-2.5 py-1.5 text-xs rounded-[6px] flex items-center gap-2 transition-colors ${s?"text-red-500 hover:bg-red-500/10":r?"text-amber-500 hover:bg-amber-500/10":"text-text hover:bg-surface-2/80"}`,children:[e&&(0,n.jsx)(e,{size:13,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:t})]},t))})]}),document.body)]}):null}var nV=s(11865),nJ=s(20464),nG=s(4018),nY=s(75687);function nZ({onClose:e}){let{t}=(0,eu.s)(),{authenticateWithApiKey:s,authenticateWithToken:l}=(0,nJ.As)(),{saveKey:a}=(0,nG.u)(),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!0),[u,x]=(0,r.useState)(!1),[m,h]=(0,r.useState)(""),[b,g]=(0,r.useState)(!1),v=(0,r.useRef)(null);(0,r.useEffect)(()=>{window.matchMedia("(pointer: fine)").matches&&requestAnimationFrame(()=>v.current?.focus())},[]),(0,r.useEffect)(()=>{let t=t=>{"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),e?.())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e]);let y=async n=>{if(!n||u)return!1;if((0,p.PF)(n))return h(t("login.legacyKeyError")),!1;(0,ed.e)(),x(!0),h("");let r=(0,nY.k)(n),i=!!r?.tempKey;try{i&&(0,e0.U)(c);let o=i?await l(r.tempKey,!0,r.tail):await s(n,{persistSession:!1});if(!o?.success)return h(o?.error&&"wrong-key-tail"!==o.error?o.error:t("login.invalidKeyTail")),!1;if(i)return(0,e0.zm)(r,{remember:c,leavingHead:P.rh.getState().currentKey,navigate:!1}),e?.(),!0;let d=(0,p.Uo)(n),u=(0,p.Cj)(n);return u&&d&&(0,f.LG)(d,{tail:u}),c&&d&&(a(n,""),P.rh.getState().setAutoConnect(d,!0)),e?.(),!0}catch(e){return h(e?.message||t("login.invalidKeyTail")),!1}finally{x(!1)}};return"u"<typeof document?null:(0,sd.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center px-4 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-150",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},onClick:e,children:(0,n.jsxs)("form",{role:"dialog","aria-modal":"true","aria-label":t("hosts.addHost"),onSubmit:e=>{e?.preventDefault(),y(i.trim())},className:"card-elev w-[26rem] max-w-full overflow-hidden flex flex-col my-auto animate-in zoom-in-95 duration-150",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 pt-4 pb-3 flex items-center gap-2.5 border-b border-border-subtle",children:[(0,n.jsx)("div",{className:"p-1.5 bg-brand-500/10 dark:bg-white/10 rounded-brand flex-shrink-0",children:(0,n.jsx)(el.kV,{className:"text-brand-500 dark:text-white w-4 h-4"})}),(0,n.jsx)("h2",{className:"flex-1 text-sm font-semibold text-text truncate",children:t("hosts.addHost")}),(0,n.jsx)("button",{type:"button",onClick:e,"aria-label":t("common.cancel"),className:"text-text-muted hover:text-text shrink-0",children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsxs)("div",{className:"px-4 py-4 space-y-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:v,type:"text",value:i,onChange:e=>{o(e.target.value),h("")},placeholder:t("login.placeholder"),spellCheck:!1,autoComplete:"off",className:"w-full pl-3 pr-11 py-2.5 bg-surface-2 border border-border-subtle rounded-[10px] font-mono text-sm text-text placeholder-text-subtle focus:outline-none focus:border-brand-500 focus:ring-2 focus:ring-brand-500/20 transition-all duration-150"}),(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),g(!0)},className:"absolute right-2 top-1/2 -translate-y-1/2 w-7 h-7 grid place-items-center rounded-[7px] text-text-subtle hover:bg-surface-3 hover:text-brand-500 transition-colors","aria-label":t("login.scanQr"),children:(0,n.jsx)(el.vW,{size:16})})]}),(0,n.jsxs)("label",{className:"flex items-center gap-2 px-0.5 text-xs text-text-muted cursor-pointer select-none",children:[(0,n.jsx)("input",{type:"checkbox",checked:c,onChange:e=>d(e.target.checked),className:"w-4 h-4 accent-brand-500 cursor-pointer"}),t("login.rememberKey")]}),m&&(0,n.jsx)("p",{className:"text-xs text-red-400 px-0.5",children:m})]}),(0,n.jsxs)("div",{className:"px-4 pb-4 flex gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:e,className:"flex-1 py-2 text-sm text-text-muted bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors",children:t("common.cancel")}),(0,n.jsxs)("button",{type:"submit",disabled:!i.trim()||u,className:"flex-1 py-2 text-sm font-semibold text-white bg-brand-500 hover:bg-brand-600 rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-50 disabled:cursor-not-allowed",children:[u&&(0,n.jsx)(el.kr,{size:14,className:"animate-spin"}),t("login.connect")]})]})]})}),b&&(0,n.jsx)("div",{className:"fixed inset-0 z-[80]",children:(0,n.jsx)(nV.A,{isOpen:!0,onClose:()=>g(!1),onScan:e=>y(String(e||"").trim())})})]}),document.body)}function nQ({hostKey:e=null,label:t="",connected:s=!0,collapsed:l=!1,onToggleCollapse:a=null,onRename:i=null,onDelete:o=null,onDisconnect:c=null,onAddWorkspace:d=null,meta:u=null,mutedOffline:x=!1,connecting:m=!1,onConnect:p=null,onRetry:f=null,showAdd:b=!0,hostUpdating:g=!1,onOpenRemote:v=null,onOpenMobile:y=null,mobile:w=!1,className:j=""}){let{t:k}=(0,eu.s)(),N=(0,h.B)(e=>e.hiddenHeaderButtons),[C,S]=(0,r.useState)(null),[T,R]=(0,r.useState)(!1),[E,$]=(0,r.useState)(!1),[z,M]=(0,r.useState)(!1),[P,A]=(0,r.useState)(null),I=t||"Local";return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:`relative pr-2 ${w?"py-1.5":"py-1"} flex items-center gap-1.5 group group/host ${j}`,onContextMenu:e=>{e.preventDefault(),(0,ed.e)(),A({left:e.clientX,top:e.clientY})},children:[a?(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),a()},className:"text-text-subtle hover:text-text flex-shrink-0",tabIndex:-1,"aria-expanded":!l,"aria-label":I,children:(0,n.jsx)(el.c_,{size:w?18:12,className:`transition-transform duration-150 ${l?"":"rotate-90"}`})}):(0,n.jsx)("span",{className:"flex-shrink-0 invisible","aria-hidden":"true",children:(0,n.jsx)(el.c_,{size:w?18:12})}),(0,n.jsxs)("span",{className:"relative flex-shrink-0",children:[(0,n.jsx)(el.VA,{size:w?16:15,className:"text-text-muted"}),(0,n.jsx)("span",{className:`absolute -bottom-0.5 -right-0.5 w-1.5 h-1.5 rounded-full ring-1 ring-surface ${m?"bg-amber-400 animate-pulse":s?"bg-green-500":x?"bg-text-subtle":"bg-red-500 animate-pulse"}`})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{a&&((0,ed.e)(),a())},className:"flex-1 min-w-0 py-0.5 pr-1 text-left",children:(0,n.jsx)("span",{className:`block ${w?"text-sm":"text-[12px]"} font-medium uppercase truncate ${s?"text-text":"text-text-muted"}`,"data-tip":I,children:I})}),g&&(0,n.jsx)(el.kr,{size:w?14:12,className:"animate-spin text-brand-400 shrink-0","aria-label":k("menu.updating")}),u&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle truncate min-w-0 max-w-[45%] mr-1",children:u}),(0,n.jsxs)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center ${w?"gap-1.5 opacity-100":"gap-1 sm:gap-1.5 px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100"} transition-opacity`,children:[b&&!g&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),M(!0)},className:"p-0.5 text-text-subtle hover:text-text rounded-[2px] transition-colors",title:k("hosts.addHost"),children:(0,n.jsx)(el.kV,{size:13.5})}),(p||f)&&!s&&!m&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),(p||f)()},className:`${w?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors`,title:k("common.connect"),children:(0,n.jsx)(el.Fc,{size:w?16:13})}),d&&!g&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),d()},className:`${w?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors`,title:k("workspaces.newWorkspace"),children:(0,n.jsx)(el.vd,{size:w?18:13.5})}),(0,n.jsx)(nX,{size:w?18:13.5,label:k("sessions.sessionActions"),revealCls:"",anchor:P,onClose:()=>A(null),items:[i&&e&&{icon:el.gH,label:k("sessions.editName"),onClick:()=>S(I)},d&&!g&&{icon:el.vd,label:k("workspaces.newWorkspace"),onClick:()=>d()},{icon:el.kV,label:k("hosts.addHost"),onClick:()=>M(!0)},v&&!N.includes("remote")&&!g&&{icon:el.VA,label:k("menu.remoteDesktop"),onClick:()=>{A(null),(0,ed.e)(),v()}},y&&!N.includes("mobile")&&!g&&{icon:el.wO,label:k("mobile.androidDevice"),onClick:()=>{A(null),(0,ed.e)(),y()}},o&&e&&{icon:el.TB,label:k("hosts.removeHost"),danger:!0,onClick:()=>R(!0)},c&&{icon:el.Mr,label:k("common.disconnect"),danger:!0,onClick:()=>{A(null),$(!0)}}]})]})]}),z&&(0,n.jsx)(nZ,{onClose:()=>M(!1)}),null!==C&&(0,n.jsx)(sN,{title:k("sessions.editName"),placeholder:I,value:C,onChange:S,onSubmit:()=>{let t=C.trim();t&&e&&i?.(e,t),S(null)},onClose:()=>S(null)}),(0,n.jsx)(ec.A,{isOpen:T,onClose:()=>R(!1),onConfirm:()=>{R(!1),e&&o?.(e)},title:k("hosts.removeHost"),message:k("hosts.removeHostMessage",{name:I}),confirmText:k("common.delete")}),(0,n.jsx)(ec.A,{isOpen:E,onClose:()=>$(!1),onConfirm:()=>{$(!1),c?.()},title:k("common.disconnect"),message:k("hosts.disconnectMessage",{name:I}),confirmText:k("common.disconnect")})]})}let n0="9remote_tree_collapsed",n1="_root";function n2(){try{return JSON.parse(localStorage.getItem(n0))||{}}catch{return{}}}function n5({name:e,size:t=20,className:s=""}){let r=("default"===e?"D":e).trim().charAt(0).toUpperCase();return(0,n.jsx)("span",{className:`shrink-0 rounded-full flex items-center justify-center text-white font-bold ${s}`,style:{backgroundColor:function(e){let t=0;for(let s of String(e))t=(31*t+s.charCodeAt(0))%360;return`hsl(${t} 62% 45%)`}(e),width:t,height:t,fontSize:Math.max(9,Math.round(t/2))},children:r})}let n3=new Map,n4={branch:null,dirty:!1,changedCount:0};async function n6(e,t){let[s,n]=await Promise.all([e.fileBus?.gitBranch?.(t),e.fileBus?.gitChangedCount?.(t)]),r=s?.success&&s.branch||null,l=n?.success&&n.count||0;(e.state.branch!==r||e.state.changedCount!==l)&&(e.state={branch:r,dirty:l>0,changedCount:l},e.subs.forEach(t=>t(e.state)))}function n8(e,t,{enabled:s=!0}={}){let[n,l]=(0,r.useState)(n4),a=t||en.getState();return(0,r.useEffect)(()=>{let t;if(!e||!a||!s)return;let n=((t=n3.get(e))||(t={state:n4,stop:null,refs:0,subs:new Set,fileBus:a},n3.set(e,t),n6(t,e),t.stop=sg(()=>n6(t,e),eJ.KA)),t.refs++,t);return n.subs.add(l),l(e=>e===n.state?e:n.state),()=>{let t;n.subs.delete(l),(t=n3.get(e))&&(t.refs--,t.refs>0||(t.stop?.(),n3.delete(e)))}},[e,a,s]),n}function n9({branch:e,dirty:t,size:s=10,className:r="",iconClassName:l=""}){return e?(0,n.jsxs)("span",{className:`inline-flex items-center gap-0.5 min-w-0 ${r}`,title:e,children:[(0,n.jsx)(el.Zr,{size:s,className:`flex-shrink-0 ${l||"opacity-70"}`}),(0,n.jsxs)("span",{className:"truncate",children:[e,t?"*":""]})]}):null}function n7({workspace:e,isActive:t,connected:s,collapsed:r,fileBus:l,onToggleCollapse:a,onSelect:i,onNewTerminal:o,onDelete:c,onRename:d,onAddWorkspace:u=null,mobile:x=!1}){let{t:m}=(0,eu.s)(),{branch:p,dirty:f}=n8(sm(e),l,{enabled:!!l}),h=i||(a?()=>{(0,ed.e)(),a()}:null);return(0,n.jsxs)("div",{onClick:h,className:`relative pr-2 py-1.5 flex items-center gap-1.5 group group/grp transition-colors ${h?"cursor-pointer hover:bg-text/[0.06]":""}`,children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),a?.()},className:"text-text-subtle hover:text-text flex-shrink-0",tabIndex:-1,children:(0,n.jsx)(el.c_,{size:x?18:12,className:`transition-transform duration-150 ${r?"":"rotate-90"}`})}),(0,n.jsx)(el.vd,{size:x?14:13.5,className:"text-text-muted flex-shrink-0"}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)("span",{className:`${x?"text-sm":"text-[12px]"} font-medium uppercase truncate ${t?"text-text":"text-text-muted"}`,"data-tip":e.name,children:e.name}),p&&!(0,eJ.ok)(p)&&p!==e.name&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle leading-tight flex items-center gap-1 min-w-0",children:(0,n.jsx)(n9,{branch:p,dirty:f,className:"truncate flex-shrink-0 max-w-[7rem]"})})]}),(0,n.jsxs)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-1.5 ${x?"opacity-100":"px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100"} transition-opacity`,children:[o&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),o()},disabled:!s,className:`${x?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors disabled:opacity-40`,title:m("terminal.newTerminal"),children:(0,n.jsx)(el.FW,{size:x?18:13.5})}),(0,n.jsx)(nX,{size:x?18:13.5,label:m("sessions.sessionActions"),revealCls:"",items:[o&&s&&{icon:el.FW,label:m("terminal.newTerminal"),onClick:()=>o()},u&&s&&{icon:el.vd,label:m("workspaces.newWorkspace"),onClick:()=>u()},d&&{icon:el.gH,label:m("workspaces.rename"),onClick:()=>d()},c&&s&&{icon:el.TB,label:m("workspaces.delete"),danger:!0,onClick:()=>c()}]})]})]})}let re=function({fileBus:e,cwd:t,basePath:s,homeDir:r,mobile:l=!1}){let a,{branch:i,dirty:o}=n8(t,e),c=!!i&&!(0,eJ.ok)(i),d=c?null:t&&s&&t.startsWith(`${s}/`)?t.slice(s.length+1):t&&s&&t!==s?(a=sx(t,r)).split("/").length>2?`…/${a.split("/").slice(-2).join("/")}`:a:null;return c||d?(0,n.jsxs)("span",{className:`${l?"text-xs":"text-[10px]"} text-text-subtle truncate leading-tight flex items-center gap-1.5`,children:[c&&(0,n.jsx)(n9,{branch:i,dirty:o,className:"truncate italic"}),d&&(0,n.jsx)("span",{className:"truncate opacity-70","data-tip":d,children:d})]}):null},rt=new Set(["Agent","Task","Workflow","task","browser_subagent","invoke_subagent","spawn_agent"]),rs=e=>e?.input?.subagent_type||e?.input?.agent||e?.input?.description||"agent",rn=e=>e?.input?.description||e?.input?.command||"shell";function rr(e=[],t=""){if(!t)return null;let s=null,n=e=>{for(let r of e||[]){if(r?.id===t)return s=r,!0;if(r?.children?.length&&n(r.children))return!0}return!1};for(let t=e.length-1;t>=0&&!s;t--)n(e[t]?.tools);return s}function rl(e,{includeAsync:t=!1}={}){return(e||[]).map(e=>{let s=e.children?rl(e.children,{includeAsync:t}):null;return"running"!==e.status||e.async&&!t?s?{...e,children:s}:e:{...e,status:"done",...s?{children:s}:null}})}function ra(e,t,s){let n=!1,r=(e||[]).map(e=>{if(t(e))return n=!0,s(e);let r=ra(e.children,t,s);return r?(n=!0,{...e,children:r}):e});return n?r:null}var ri=s(91524);let ro=e=>"string"==typeof e&&e.replace(/\\/g,"/").split("/").filter(Boolean).pop()||"",rc=e=>{if("string"!=typeof e)return"";let t=e.slice(-512).split("\n");for(let e=t.length-1;e>=0;e--){let s=t[e].trim();if(s)return s}return""},rd=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,ru=(e="")=>{let t=/^mcp__[^_]+(?:_[^_]+)*__(.+)$/.exec(e);return t?t[1]:e},rx=(e={})=>e.url||e.query||e.pattern||e.name||ro(e.path)||ro(e.file_path)||"";function rm(e){let t=Number(e)||0,s=t>=1e6?[1e6,"M"]:t>=1e3?[1e3,"k"]:null;if(!s)return String(t);let n=t/s[0];return`${n>=100?Math.round(n):n.toFixed(1).replace(/\.0$/,"")}${s[1]}`}let rp=new Set(["Edit","Write","MultiEdit","NotebookEdit","edit","write","patch","apply","write_to_file","replace_file_content","multi_replace_file_content","sed_file","file_change"]),rf=e=>"string"==typeof e&&e?e.split("\n").length:0;function rh(e=[]){let t=0,s=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if("user"===r.role)break;let l=r.diffs||[];for(let e of l)for(let n of(e.patch||e.diff||"").split("\n"))n.startsWith("+")&&!n.startsWith("+++")?t++:n.startsWith("-")&&!n.startsWith("---")&&s++;let a=new Set(l.map(e=>e.file).filter(Boolean));for(let e of r.tools||[]){if(!rp.has(e?.name))continue;let n=e.input?.file_path||e.input?.path||e.input?.file||"";if(n&&a.has(n))continue;let r=function(e){let t=e.input;if(!t||"string"==typeof t)return null;let s=t.file_path||t.path||t.file||"",n=Array.isArray(t.edits)?t.edits:Array.isArray(t.replacement_chunks)?t.replacement_chunks:Array.isArray(t.replacements)?t.replacements:null;if(n){let e=0,t=0;for(let s of n)t+=rf(s.old_string??s.oldString??s.old??s.target_content),e+=rf(s.new_string??s.newString??s.new??s.replacement_content);return{file:s,added:e,removed:t}}if("string"==typeof t.content&&t.content)return{file:s,added:rf(t.content),removed:0};let r=t.old_string??t.oldString??t.old_str??t.target_content??t.TargetContent,l=t.new_string??t.newString??t.new_str??t.replacement_content??t.ReplacementContent;return void 0===r&&void 0===l?null:{file:s,added:rf(l),removed:rf(r)}}(e);r&&(t+=r.added,s+=r.removed)}}return{added:t,removed:s}}let rb=/^\s*<(task-notification|environment_context|turn_aborted|persisted-output)>/,rg=e=>rb.test(String(e||""));function rv(e){let t=String(e||"").trim();if(!t)return"";if(!t.startsWith("<persisted-output>"))return t;let s=/saved to: (\S+)/.exec(t);return s?`saved to: ${s[1]}`:""}let ry=new Set(["completed","failed","killed","stopped"]),rw=(e,t=Date.now())=>e?.usage?.duration_ms>0?e.usage.duration_ms:e?.endedAt&&e?.startedAt?Math.max(0,e.endedAt-e.startedAt):e?.startedAt?Math.max(0,t-e.startedAt):0,rj=(e,t)=>t?.startedAt?null:{startedAt:Date.now()-(Number.isFinite(e)?Math.max(0,e):0)},rk=(e=[])=>{for(let t=e.length-1;t>=0;t--)if(e[t]?.compacting)return t;return -1},rN=new Set(["compacting"]);function rC(e,t,s,n,r){if("system"!==t)return e;let l=Number.isFinite(r)?r:n?.ageMs;switch(s){case"task_started":if(!n?.task_id)return e;return rS(e,n.task_id,{taskId:n.task_id,status:"running",background:!!n.is_backgrounded,...n.tool_use_id?{toolUseId:n.tool_use_id}:null,...n.description?{description:n.description}:null,...n.subagent_type?{subagentType:n.subagent_type}:null,...n.task_type?{taskType:n.task_type}:null,...rj(l,e.find(e=>e.taskId===n.task_id))});case"task_updated":{let t=e.findIndex(e=>e.taskId===n?.task_id);if(-1===t)return e;let s=n.patch||{},r=e.slice(),a=s.status&&!ry.has(s.status),i={...r[t],...s.status?{status:s.status}:null,...s.description?{description:s.description}:null,...s.end_time?{endedAt:s.end_time}:null};return a&&delete i.endedAt,a&&r[t].endedAt&&Object.assign(i,rj(l,null)),r[t]=i,r}case"task_notification":{let t=e.findIndex(e=>e.taskId===n?.task_id);if(-1===t)return e;let s=e.slice();return s[t]={...s[t],status:n.status||"completed",endedAt:s[t].endedAt||Date.now(),...n.output_file?{outputFile:n.output_file}:null,...n.summary?{summary:n.summary}:null,...n.usage?{usage:n.usage}:null},s}case"background_tasks_changed":{let t=new Set((n?.tasks||[]).map(e=>e.task_id)),s=e;for(let e of(s.some(e=>e.background&&!ry.has(e.status)&&!t.has(e.taskId))&&(s=s.map(e=>!e.background||ry.has(e.status)||t.has(e.taskId)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()})),n?.tasks||[]))s=rS(s,e.task_id,{background:!0,status:"running",...e.description?{description:e.description}:null,...e.task_type?{taskType:e.task_type}:null,...rj(l,s.find(t=>t.taskId===e.task_id))});return s}default:return e}}function rS(e,t,s){let n=e.findIndex(e=>e.taskId===t);if(-1===n)return[...e,{taskId:t,toolUseId:"",...s}];let r={...e[n],...s};if(rT(r,e[n]))return e;let l=e.slice();return l[n]=r,l}let rT=(e,t)=>{let s=Object.keys(e);return s.length===Object.keys(t).length&&s.every(s=>e[s]===t[s])};function rR(e,t){let s=[];for(let t of e||[])t&&(s=rC(s,t.type||"system",t.subtype||"",t.record||null,t.ageMs));let n=new Map(s.map(e=>[e.taskId,e]));for(let e of t||[])e?.taskId&&n.set(e.taskId,{...n.get(e.taskId),...e});return[...n.values()]}let rE=[e=>"string"==typeof e.content?e.content:"",e=>"string"==typeof e.message?e.message:"",e=>"string"==typeof e.error?.formatted?e.error.formatted:"",e=>"string"==typeof e.error?.message?e.error.message:"",e=>e.summary||e.details?[e.summary,e.details].filter(Boolean).join(" — "):"",e=>"string"==typeof e.reason?e.reason:""],r$=new Set(["tool_progress","thinking_tokens","hook_started","hook_progress","hook_response","control_response"]),rz=new Set(["info","suggestion","warning","error"]),rM={warning:"warning",guardianWarning:"warning",configWarning:"warning",deprecationNotice:"warning",notice:"warning"};function rP(e,t,s=null){if(!t)return null;let n=(0,ri.Tw)(s);if(n.suppressedNotices?.has?.(e))return null;let r=n.notices,l=r&&Object.prototype.hasOwnProperty.call(r,e)?r[e]:null;if(l){let s=String(l.text?.(t)||"").trim();if(s)return{subtype:e,level:l.level||"info",content:s}}if(e.startsWith("session.next.")){if("session.next.retried"===e)return{subtype:e,level:"warning",content:`Retrying (attempt ${t.attempt??"?"}): ${t.error?.message||""}`.trim()};if("session.next.compaction.started"===e)return{subtype:e,level:"info",content:"Compacting…",compacting:!0};if("session.next.compaction.ended"===e)return{subtype:e,level:"info",content:"Compacted",compactSettled:!0};if("session.next.revert.staged"===e)return{subtype:e,level:"info",content:"Rewind staged"};if("session.next.revert.committed"===e)return{subtype:e,level:"info",content:"Rewound the conversation"};if("session.next.agent.switched"===e)return{subtype:e,level:"info",content:`Agent: ${t.agent||""}`}}if("model/rerouted"===e)return{subtype:e,level:"warning",content:`Model rerouted: ${t.fromModel} → ${t.toModel}`};if("thread/compacted"===e)return{subtype:e,level:"info",content:"Compacted",compactSettled:!0};if("system"===e&&"compact_boundary"===t.subtype){let e=function(e){let t=e.compact_metadata||e.compactMetadata;if(!t||"object"!=typeof t)return null;let s=e=>Number.isFinite(e)?e:null,n=s(t.pre_tokens??t.preTokens),r=s(t.post_tokens??t.postTokens),l=null!=n&&null!=r?`${rm(n)} → ${rm(r)} tokens`:"";return{trigger:t.trigger||"auto",preTokens:n,postTokens:r,durationMs:s(t.duration_ms??t.durationMs),...l?{detail:l}:null}}(t),s="string"==typeof t.content?t.content.trim():"";return e||s?{subtype:"compact_boundary",level:t.level||"info",content:s||"Compacted",compactSettled:!0,...e?{compact:e}:null}:null}if("system"===e&&"status"===t.subtype){if(rN.has(t.status))return{subtype:"status",level:"info",content:"Compacting…",compacting:!0};if(null!=t.status&&!t.compact_result)return null;let e="failed"===t.compact_result;return{subtype:"status",level:e?"error":"info",content:e?String(t.compact_error||"").trim()||"Compaction failed":"",compactSettled:!0}}if("attachment"===e){let e=t.attachment||t,s=e.type||"";if("edited_text_file"===s)return null;if("hook_success"===s){if("SessionStart"!==e.hookEvent)return null;let t=rv(e.content);return t?{subtype:s,level:"info",content:t}:null}let n="queued_command"===s?e.prompt:"";if("string"!=typeof n||!n.trim()||rg(n))return null;let r=rv(n);return r?{subtype:s,level:"info",content:r}:null}if("system"===e){if(rg(t.content))return null;let e="string"==typeof t.content&&t.content.trim()?t.content.trim():"string"==typeof t.error?.formatted&&t.error.formatted.trim()?t.error.formatted.trim():"string"==typeof t.error?.message&&t.error.message.trim()?t.error.message.trim():"";return e?{subtype:t.subtype||"",level:t.level||"info",content:e}:null}if(r$.has(e))return null;for(let s of rE){let n=rv(s(t)).trim();if(!n||rg(n))continue;let r="error"===e&&t.willRetry?"warning":rz.has(t?.level)?t.level:Object.prototype.hasOwnProperty.call(rM,e)?rM[e]:/error|fail/i.test(e)?"error":/warn|retr/i.test(e)?"warning":"info";return{subtype:e,level:r,content:n}}return null}function rA(e=[],t){if(!t)return e||[];if(t.replaceAll)return t.todos||[];let s=e||[],n=t.taskId?String(t.taskId):"",r=t.id?String(t.id):"",l=s.findIndex(e=>n&&String(e.taskId)===n||r&&e.id&&String(e.id)===r);if("deleted"===t.status)return -1===l?s:[...s.slice(0,l),...s.slice(l+1)];if(-1===l)return t.subject?[...s,t]:s;let a=s.slice();return a[l]={...a[l],...t},a}let rI=(0,ty.KU)(()=>window.localStorage),rD=null,rL=rI&&{...rI,setItem:(e,t)=>{t!==rD&&(rD=t,rI.setItem(e,t))}},rB=0,rF=e=>`${e}-${Date.now()}-${++rB}`,rK={messages:[],isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null,gateError:!1,activeBlocked:null,permissionMode:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0},metadata:{model:"",skills:[],mcpServers:[]},tasks:[],harnessTasks:[],queue:[]},rO=(e,t)=>({...rK,...e.bySession[t]});function rW(e,t){if(!t?.length)return null;let s=e.filter(e=>e.toolUseId&&ry.has(e.status));if(!s.length)return null;let n=t;for(let e of s){let t="failed"===e.status?"error":"done",s=n.map(s=>{if(!s.tools)return s;let n=ra(s.tools,t=>t.id===e.toolUseId&&"running"===t.status,e=>({...e,status:t}));return n?{...s,tools:n}:s});s.some((e,t)=>e!==n[t])&&(n=s)}return n===t?null:n}let r_=(e,t)=>e.status!==(t.status||"done")||Object.keys(t).some(s=>e[s]!==t[s]),rH=(0,b.v)((0,ty.Zr)((e,t)=>({bySession:{},initSession:s=>{s&&!t().bySession[s]&&e(e=>({bySession:{...e.bySession,[s]:{...rK}}}))},setTaskRecords:(t,s)=>{t&&Array.isArray(s)&&e(e=>{let n=rO(e,t),r=rR(s,[]),l=rW(r,n.messages);return r!==n.harnessTasks||l?{bySession:{...e.bySession,[t]:{...n,harnessTasks:r,...l?{messages:l}:null}}}:e})},applyTaskRecords:(t,s)=>{t&&s?.length&&e(e=>{let n=rO(e,t),r=n.harnessTasks||[],l=r;for(let[e,t,n,r]of s)l=rC(l,e,t,n,r);let a=rW(l,n.messages);return l!==r||a?{bySession:{...e.bySession,[t]:{...n,harnessTasks:l,...a?{messages:a}:null}}}:e})},addNotice:(t,s)=>{let n="string"==typeof s?.content?s.content.trim():"";!t||(n||s?.compactSettled)&&e(e=>{let r=rO(e,t);if(s?.compacting&&-1!==rk(r.messages))return e;if(-1!==(s?.compactSettled?rk(r.messages):-1)){let l=r.messages.findIndex(e=>e?.compacting),a=r.messages.filter(e=>!e?.compacting);return n&&a.splice(l,0,{id:rF("n"),role:"notice",subtype:s.subtype||"",level:s.level||"info",content:n,...s.compact?{compact:s.compact}:null}),{bySession:{...e.bySession,[t]:{...r,messages:a}}}}if(!n)return e;let l={id:rF("n"),role:"notice",subtype:s.subtype||"",level:s.level||"info",content:n,...s.file?{file:s.file}:null,...s.compact?{compact:s.compact}:null,...s.compacting?{compacting:!0}:null},a=r.messages[r.messages.length-1],i=!a||"assistant"!==a.role||a.content||a.thinking||(a.tools||[]).length?[...r.messages,l]:[...r.messages.slice(0,-1),l];return{bySession:{...e.bySession,[t]:{...r,messages:i}}}})},setPermissionMode:(t,s)=>{e(e=>{let n=rO(e,t);return{bySession:{...e.bySession,[t]:{...n,permissionMode:s}}}})},setTurnRunning:(t,s)=>{e(e=>{let n=rO(e,t);return{bySession:{...e.bySession,[t]:{...n,isTurnRunning:s}}}})},ensureTurnLive:t=>{e(e=>{let s=rO(e,t);return s.isTurnRunning?e:{bySession:{...e.bySession,[t]:{...s,isTurnRunning:!0,turnStartedAt:Date.now(),lastTurnMs:0}}}})},setQueue:(t,s)=>{t&&e(e=>{let n=rO(e,t),r=Array.isArray(s)?s:[];return{bySession:{...e.bySession,[t]:{...n,queue:r}}}})},setMetadata:(t,s)=>{e(e=>{let n=rO(e,t);return{bySession:{...e.bySession,[t]:{...n,metadata:{...n.metadata,...s}}}}})},setStats:(t,s)=>{e(e=>{let n=rO(e,t);return{bySession:{...e.bySession,[t]:{...n,stats:{...n.stats,...s}}}}})},addUserMessage:(t,s,n=null,r=!1)=>{e(e=>{let l=rO(e,t),a={id:rF("u"),role:"user",content:s,attachments:n||[]},i={id:rF("a"),role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0};return{bySession:{...e.bySession,[t]:{...l,...r?null:{isTurnRunning:!0,turnStartedAt:Date.now(),lastTurnMs:0,turnBaseline:{inputTokens:l.stats.inputTokens||0,outputTokens:l.stats.outputTokens||0},activeBlocked:null},messages:[...l.messages,a,i]}}}})},appendDelta:(t,s)=>{e(e=>{let n=rO(e,t),r=[...n.messages],l=r[r.length-1];return l&&"assistant"===l.role&&l.isLive?r[r.length-1]={...l,content:(l.content||"")+(s||"")}:r.push({id:rF("msg"),role:"assistant",content:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendThinking:(t,s)=>{e(e=>{let n=rO(e,t),r=[...n.messages],l=r[r.length-1];return l&&"assistant"===l.role&&l.isLive?r[r.length-1]={...l,thinking:(l.thinking||"")+(s||"")}:r.push({id:rF("msg"),role:"assistant",content:"",thinking:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendStream:(t,s,n)=>{e(e=>{let r=rO(e,t),l=[...r.messages],a=l[l.length-1];return a&&"assistant"===a.role&&a.isLive?l[l.length-1]={...a,...s?{content:(a.content||"")+s}:null,...n?{thinking:(a.thinking||"")+n}:null}:l.push({id:rF("msg"),role:"assistant",content:s||"",thinking:n||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...r,messages:l}}}})},appendDiff:(t,s)=>{e(e=>{let n=rO(e,t),r=[...n.messages],l=r[r.length-1];l&&"assistant"===l.role?(l={...l},r[r.length-1]=l):(l={id:rF("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},r.push(l));let a=[...l.diffs||[]],i=a.findIndex(e=>e.file===s.file);return -1!==i?a[i]=s:a.push(s),l.diffs=a,{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendTool:(t,s)=>{e(e=>{let n=rO(e,t),r=[...n.messages],l=r[r.length-1];if(l&&"assistant"===l.role&&l.isLive&&(l.content||l.thinking||"").length>0)r[r.length-1]={...l,isLive:!1},r.push({id:rF("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...s,status:s.status||"running"}]});else if(l&&"assistant"===l.role){let e=[...l.tools||[]],t=e.findIndex(e=>e.id===s.id);-1!==t?e[t]={...e[t],...s}:e.push({...s,status:s.status||"running"}),r[r.length-1]={...l,tools:e}}else r.push({id:rF("msg"),role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...s,status:s.status||"running"}]});return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},updateToolResult:(t,s)=>{e(e=>{let n=rO(e,t);for(let r=n.messages.length-1;r>=0;r--){let l=n.messages[r];if(!l?.tools)continue;let a=l.tools.findIndex(e=>e.id===s.id);if(-1===a)continue;if(!r_(l.tools[a],s))break;let i=[...l.tools];i[a]={...i[a],...s,status:s.status||"done"};let o=[...n.messages];return o[r]={...l,tools:i},{bySession:{...e.bySession,[t]:{...n,messages:o}}}}return e})},nestTool:(t,s)=>{e(e=>{let n=rO(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e],n=ra(t?.tools,e=>e.id===s.parentToolUseId,e=>{let t=[...e.children||[]],n=t.findIndex(e=>e.id===s.id);return -1!==n?t[n]={...t[n],...s}:t.push({...s,status:s.status||"running"}),{...e,children:t}});if(n){r[e]={...t,tools:n};break}}return{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},nestToolResult:(t,s)=>{e(e=>{let n=rO(e,t);for(let r=n.messages.length-1;r>=0;r--){let l=n.messages[r],a=ra(l?.tools,e=>(e.children||[]).some(e=>e.id===s.id),e=>{let t=e.children.find(e=>e.id===s.id);return t&&!r_(t,s)?e:{...e,children:e.children.map(e=>e.id===s.id?{...e,...s,status:s.status||"done"}:e)}});if(!a)continue;if(a.every((e,t)=>e===l.tools[t]))break;let i=[...n.messages];return i[r]={...l,tools:a},{bySession:{...e.bySession,[t]:{...n,messages:i}}}}return e})},setPermission:(t,s)=>{e(e=>{let n=rO(e,t);return{bySession:{...e.bySession,[t]:{...n,activePermission:s,gateError:!1}}}})},clearPermission:t=>{e(e=>{let s=rO(e,t);return{bySession:{...e.bySession,[t]:{...s,activePermission:null}}}})},setBlocked:(t,s)=>{e(e=>{let n=rO(e,t);return{bySession:{...e.bySession,[t]:{...n,activeBlocked:s}}}})},clearBlocked:t=>{e(e=>{let s=rO(e,t);return{bySession:{...e.bySession,[t]:{...s,activeBlocked:null}}}})},setGateError:(t,s,n=!0)=>{e(e=>{let r=rO(e,t);return r.activePermission?.requestId!==s?e:{bySession:{...e.bySession,[t]:{...r,gateError:n}}}})},finishTurn:(t,s,n=0,r=!1)=>{e(e=>{let l=rO(e,t),a=l.messages.map((e,t)=>{let s=e.tools?rl(e.tools):null,n=!!s&&(s.length!==e.tools.length||s.some((t,s)=>t!==e.tools[s])),r=t===l.messages.length-1&&!1!==e.isLive;return n||r?{...e,...r?{isLive:!1}:null,...n?{tools:s}:null}:e});return{bySession:{...e.bySession,[t]:{...l,...r?{activePermission:null}:{isTurnRunning:!1,lastTurnMs:n||(l.turnStartedAt?Date.now()-l.turnStartedAt:l.lastTurnMs),activePermission:null,stats:s?{...l.stats,...s}:l.stats},messages:a}}}})},settleDeadTasks:t=>{t&&e(e=>{let s=rO(e,t),n=s.harnessTasks||[],r=n.some(e=>!ry.has(e.status))?n.map(e=>ry.has(e.status)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()}):n,l=function(e=[]){let t=!1,s=e.map(e=>{if(!e.tools)return e;let s=rl(e.tools,{includeAsync:!0}),n=s.length!==e.tools.length||s.some((t,s)=>t!==e.tools[s]);return n&&(t=!0),n?{...e,tools:s}:e});return t?s:null}(s.messages);return r!==n||l?{bySession:{...e.bySession,[t]:{...s,harnessTasks:r,...l?{messages:l}:null}}}:e})},clearMessages:t=>{e(e=>{let s=rO(e,t);return{bySession:{...e.bySession,[t]:{...s,messages:[],tasks:[],turnStartedAt:0,lastTurnMs:0,activePermission:null,activeBlocked:null,stats:{inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},turnBaseline:{inputTokens:0,outputTokens:0}}}}})},rewindToMessage:(t,s,n)=>{e(e=>{let r=rO(e,t),l=r.messages.findIndex(e=>e.id===s);if(-1===l)return e;let a=r.messages.slice(0,l+1);return n&&(a[l]={...a[l],content:n}),{bySession:{...e.bySession,[t]:{...r,messages:a,isTurnRunning:!1,turnStartedAt:0,lastTurnMs:0,activePermission:null}}}})},upsertTask:(t,s)=>{e(e=>{let n=rO(e,t),r=rA(n.tasks,s);return r===n.tasks?e:{bySession:{...e.bySession,[t]:{...n,tasks:r}}}})},hydrateSession:(t,{messages:s=[],tasks:n=[],isTurnRunning:r=!1,metadata:l={},stats:a=null,permissionMode:i=null,activeBlocked:o=null,elapsedMs:c=0,lastTurnMs:d=0,harnessTasks:u=null,queue:x=null})=>{e(e=>{let m=rO(e,t),p=u?rW(u,s):null;return{bySession:{...e.bySession,[t]:{...m,activePermission:null,messages:p||s,tasks:n,isTurnRunning:r,...Array.isArray(x)?{queue:x}:{},turnStartedAt:r?Date.now()-(c||0):0,lastTurnMs:r?0:d||0,turnBaseline:r?{inputTokens:0,outputTokens:0}:{inputTokens:a?.inputTokens||0,outputTokens:a?.outputTokens||0},metadata:{...m.metadata,...l},stats:a?{...m.stats,...a}:m.stats,activeBlocked:o,...i?{permissionMode:i}:{},...u?{harnessTasks:u}:{}}}}})},prependMessages:(t,s)=>{s?.length&&e(e=>{let n=rO(e,t),r=rW(n.harnessTasks||[],s)||s,l=new Set(n.messages.map(e=>e.id)),a=r.map(e=>l.has(e.id)?{...e,id:rF(e.id.split("-")[0])}:(l.add(e.id),e));return{bySession:{...e.bySession,[t]:{...n,messages:[...a,...n.messages]}}}})},restoreTurnState:(t,s={})=>{if(void 0===s.isTurnRunning)return;let{isTurnRunning:n,lastTurnMs:r=0,elapsedMs:l=0}=s;(n||r)&&e(e=>{let s=rO(e,t);return{bySession:{...e.bySession,[t]:{...s,isTurnRunning:n,lastTurnMs:r,turnStartedAt:n?Date.now()-(l||0):0}}}})},removeSession:t=>{e(e=>{let{[t]:s,...n}=e.bySession;return{bySession:n}})}}),{name:"9remote-ai-store",storage:rL,partialize:e=>({bySession:Object.fromEntries(Object.entries(e?.bySession||{}).map(([e,t])=>[e,{permissionMode:t?.permissionMode??null,metadata:{model:t?.metadata?.model||"",effort:t?.metadata?.effort||""}}]))})}));function rU(e){if(!e)return 0;let t=(e.content?.length||0)+(e.thinking?.length||0);if(Array.isArray(e.tools))for(let s of e.tools)t+=(s.command?.length||0)+(s.output?.length||0)+120;if(Array.isArray(e.diffs))for(let s of e.diffs)t+=(s.diff?.length||0)+(s.file?.length||0)+80;return Math.max(t,100)}function rq(e,t,s,n=2){if(!Array.isArray(e)||0===e.length)return 0;let r=Math.min(s??e.length,e.length),l=0,a=0;for(let s=r-1;s>=0&&(l+=rU(e[s]),a++,!(l>=t)||!(a>=n));s--);return r-a}async function rX({startSeq:e,fetchChunk:t,reduceChunk:s,maxChunks:n=8,pageBudget:r=131072,estimateBytes:l=()=>0}){let a=e,i=[],o=0,c=!0,d=0,u=!1;for(;d<n;){let e=await t(a);if(d++,null==e)break;if(!e.success||!e.events?.length){c=!1;break}u=!0;let n=s(e.events,i.length);if(i=[...n,...i],o+=n.reduce((e,t)=>e+l(t),0),a=e.events[0].seq,!(c=!!e.hasMore)||o>=r)break}return{messages:i,before:a,hasMore:c,answered:u,chunks:d}}let rV=[1200,3e3,6e3],rJ=e=>Array.isArray(e)?e.map(e=>"string"==typeof e?{id:e,name:e,description:""}:e):[];function rG(e,t){let s=String(t||"").trim();if(!s)return!1;let n=e[e.length-1];return!!(n&&"assistant"===n.role&&String(n.content||"").trim().endsWith(s))}let rY=/\u001b\[[0-9;?]*[A-Za-z]/g,rZ=e=>String(e||"").replace(rY,"").trim(),rQ=(e,t)=>{if(String(t||"").trim())return!1;let s=e[e.length-1];return!!(s&&"notice"===s.role&&"error"===s.level)},r0=e=>e?.text?`Not sent — ${e.reason||"the turn is still running"}: ${e.text}`:e?.reason||"Not sent";function r1(e=[],t="claude",s=0){let n=[],r=[],l=[],a={model:"",skills:[],mcpServers:[]},i={inputTokens:0,outputTokens:0,totalTurns:0,totalCost:0,reasoningTokens:0},o=!1,c=null,d=null,u=null,x=!1,m=!1,p=s;for(let s of e){let e=s?.event,f=s?.data;if(e)switch(e){case"user_message":o=!0,m=!1,d=null,n.push({id:`u-${++p}`,role:"user",content:f?.text||"",attachments:f?.attachments||[]}),n.push({id:`a-${++p}`,role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0});break;case"init":{m=!1;let e=rJ(f?.skills),t=e.length>0?e:a.skills,{model:s,...n}=f||{};a={...a,...n,skills:t,...s?{model:s}:{}};break}case"goal":a={...a,goal:f?.goal||null};break;case"delta":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.content=(e.content||"")+(f?.text||"");break}case"thinking":{let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",thinking:"",isLive:!0,diffs:[],tools:[]},n.push(e)),e.thinking=(e.thinking||"")+(f?.text||"");break}case"diff":{if(!f)break;let e=n[n.length-1];e&&"assistant"===e.role||(e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[]},n.push(e));let t=e.diffs||(e.diffs=[]),s=t.findIndex(e=>e.file===f.file);-1!==s?t[s]=f:t.push(f);break}case"tool_child":if(!f)break;for(let e=n.length-1;e>=0;e--){let t=ra(n[e]?.tools,e=>e.id===f.parentToolUseId,e=>{let t=[...e.children||[]],s=t.findIndex(e=>e.id===f.id);return -1!==s?t[s]={...t[s],...f}:t.push({...f,status:f.status||"running"}),{...e,children:t}});if(t){n[e].tools=t;break}}break;case"tool_result_child":if(!f?.id)break;for(let e=n.length-1;e>=0;e--){let t=ra(n[e]?.tools,e=>(e.children||[]).some(e=>e.id===f.id),e=>({...e,children:e.children.map(e=>e.id===f.id?{...e,...f,status:f.status||"done"}:e)}));if(t){n[e].tools=t;break}}break;case"tool_start":{if(!f)break;let e=n[n.length-1];if(e&&"assistant"===e.role&&e.isLive&&(e.content||e.thinking||"").length>0)e.isLive=!1,e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...f,status:f.status||"running"}]},n.push(e);else if(e&&"assistant"===e.role){let t=e.tools||(e.tools=[]),s=t.findIndex(e=>e.id===f.id);-1!==s?t[s]={...t[s],...f}:t.push({...f,status:f.status||"running"})}else e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...f,status:f.status||"running"}]},n.push(e);if(f.name){let e=(0,ri.Zm)(t,f.name,f.input,f.id,r);e&&(r=rA(r,e))}break}case"tool_result":{if(!f?.id)break;for(let e=n.length-1;e>=0;e--){let t=n[e],s=t?.tools?.find(e=>e.id===f.id);if(s){Object.assign(s,f,{status:f.status||"done"});break}}let e=(0,ri.in)(t,f.name||"",f.output||"",f.id);e&&(r=rA(r,e));break}case"permission_request":c=f;break;case"permission_resolved":c=null;break;case"blocked":d=f;break;case"options_changed":f?.permissionMode&&(u=f.permissionMode),f?.model&&(a.model=f.model),f?.effort&&(a.effort=f.effort);break;case"turn_complete":x=!0,o=!1,c=null,f?.stats&&(i={...i,...f.stats}),n.length>0&&(n[n.length-1].isLive=!1),!f?.isError||rQ(n,f.result)||rG(n,f.result)||n.push({id:`n-${++p}`,role:"notice",subtype:f.subtype||"",level:"error",content:f.result||"The turn ended in an error."});break;case"stats":f?.stats&&(i={...i,...f.stats});break;case"stopped":x=!0,o=!1,c=null;break;case"stall":for(let e of(x=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);break;case"exit":for(let e of(x=!0,m=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);(f?.error||f?.code!=null&&0!==f.code)&&n.push({id:`n-${++p}`,role:"notice",subtype:"exit",level:"error",content:f.error||`The AI process exited (code ${f.code}).`});break;case"error":for(let e of(x=!0,o=!1,n))e.isLive&&(e.isLive=!1);n.push({id:`n-${++p}`,role:"notice",subtype:"error",level:"error",content:f?.message||"AI process failed"});break;case"prompt_refused":n.push({id:`n-${++p}`,role:"notice",subtype:"prompt_refused",level:"error",content:r0(f)});break;case"conversation_reset":n.length=0,r.length=0,l.length=0,o=!1,m=!1,c=null,d=null;break;case"cli_event":{let e=f?.type||"",s=f?.record||null;l.push([e,f?.subtype||"",s,f?.ageMs]);let r=rP(e,s,t);if(!r)break;let{compactSettled:a,...i}=r,o=a?rk(n):-1;if(-1!==o){i.content?.trim()?n[o]={id:`n-${++p}`,role:"notice",...i}:n.splice(o,1);break}if(!i.content?.trim())break;let c=n[n.length-1];!c||"assistant"!==c.role||c.content||c.thinking||(c.tools||[]).length||n.pop(),n.push({id:`n-${++p}`,role:"notice",...i});break}case"ansi":{let e=rZ(f?.chunk);if(!e)break;let t=n[n.length-1];!t||"assistant"!==t.role||t.content||t.thinking||(t.tools||[]).length||n.pop(),n.push({id:`n-${++p}`,role:"notice",subtype:"ansi",level:"warning",content:e})}}}if(x||m)for(let e of n)e.tools&&(e.tools=rl(e.tools,{includeAsync:m}));let f=[];for(let[e,t,s]of l)f=rC(f,e,t,s);return m&&(f=f.map(e=>ry.has(e.status)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()})),{messages:n,tasks:r,metadata:a,stats:i,isTurnRunning:o,activePermission:c,activeBlocked:d,permissionMode:u,harnessRecords:l,harnessTasks:f}}let r2=e=>String(e).padStart(2,"0");function r5(e){let t=Math.max(0,Math.floor((Number(e)||0)/1e3)),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}h ${r2(n)}m`:n>0?`${n}m ${r2(r)}s`:`${r}s`}let r3=(0,r.memo)(function({message:e,engine:t="claude",workspacePath:s="",onResolvePermission:l,onRewind:a,onPreviewRewind:i,onCutLocal:o,rewindIndex:c=null,canRewind:d=!1}){let[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),[f,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(null);(0,h.B)(e=>e.openEditorFile);let{id:N,role:C,content:S,thinking:T,diffs:R=[],tools:E=[],permission:$=null,isLive:z=!1,attachments:M=[]}=e;if("user"===C){let e=async e=>{w(!0),k("preview");let t=await i?.(null,{index:c});(w(!1),k(null),t?.ok)?v({files:t.files||[],text:e}):v({error:t?.error||"The host could not preview this rewind.",text:e})},t=async()=>{let e=g?.text;v(null),w(!0),k("apply"),o?.(N,e);let t=await a?.(null,e,{index:c});(w(!1),k(null),t&&!t.ok)?v({error:t.error||"The rewind did not go through.",text:e}):p(!1)},s=(0,n.jsx)(ec.A,{isOpen:!!g,onClose:()=>v(null),onConfirm:g?.error?()=>v(null):t,title:g?.error?"Cannot rewind":"Rewind to this prompt?",message:g?.error?g.error:["This discards every turn after this prompt and re-sends your edited text.",g?.files?.length?`These ${g.files.length} file${1===g.files.length?"":"s"} go back to how they were:`:"No file changes to restore — this rewinds the conversation only.",...g?.files?.slice(0,8).map(e=>`\xb7 ${e.file}${e.status?` (${e.status})`:""}`)||[],g?.files?.length>8?`… and ${g.files.length-8} more`:"","Edits made by hand, or by shell commands, are NOT restored."].filter(Boolean).join("\n"),confirmText:g?.error?"OK":"Rewind"});if(m)return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex justify-end my-3",children:(0,n.jsxs)("div",{className:"max-w-[85%] sm:max-w-[75%] w-full",children:[(0,n.jsx)("textarea",{value:f,onChange:e=>b(e.target.value),onBlur:()=>{y||g||p(!1)},onKeyDown:t=>{if("Enter"===t.key&&!t.shiftKey){if(t.nativeEvent.isComposing||229===t.keyCode||(t.preventDefault(),y||g))return;f.trim()&&e(f.trim())}"Escape"===t.key&&p(!1)},rows:Math.min(10,f.split("\n").length+1),className:"w-full resize-none overflow-hidden rounded-brand-lg bg-surface-2 px-4 py-2.5 text-sm text-text focus:outline-none focus:ring-1 focus:ring-brand-500 leading-relaxed",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex justify-end items-center gap-1.5 mt-1.5 text-[11px] text-text-muted",children:[y&&(0,n.jsx)(el.kr,{size:11,className:"animate-spin"}),(0,n.jsx)("span",{children:"apply"===j?"Rewinding...":"preview"===j?"Checking what this would change...":"Enter to rewind, Esc to cancel"})]})]})}),s]});let r=d&&!!a,l=()=>{(0,ed.e)(),b(S||""),p(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"group/msg flex flex-col items-end my-3",children:[(0,n.jsxs)("div",{className:"max-w-[85%] sm:max-w-[75%] flex flex-col items-end gap-1.5",children:[M.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap justify-end gap-1.5",children:M.map((e,t)=>(0,n.jsxs)("span",{className:`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] ${e.isImage?"border-brand-500/40 bg-brand-500/10 text-brand-500":"border-border-subtle bg-surface-2 text-text-muted"}`,children:[e.isImage?(0,n.jsx)(el._V,{size:10}):(0,n.jsx)(el.xv,{size:10}),(0,n.jsx)("span",{className:"max-w-[160px] truncate",children:e.filename})]},`${e.filename}-${t}`))}),S&&(0,n.jsx)("div",{onClick:r?e=>{let t=window.getSelection();t&&!t.isCollapsed&&t.containsNode(e.currentTarget,!0)||l()}:void 0,className:`px-4 py-2.5 rounded-brand-lg bg-brand-500/15 border border-brand-500/25 text-text text-sm whitespace-pre-wrap wrap-anywhere ${r?"cursor-pointer":""}`,children:S})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),S&&(navigator.clipboard.writeText(S),x(!0),setTimeout(()=>x(!1),2e3))},className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors",title:"Copy this prompt",children:u?(0,n.jsx)(el.aJ,{size:11,className:"text-success"}):(0,n.jsx)(el.QR,{size:11})}),r&&(0,n.jsx)("button",{type:"button",disabled:y,onClick:l,className:"px-1.5 py-0.5 rounded text-[11px] text-text-muted hover:text-text hover:bg-surface-2 flex items-center gap-1 transition-colors disabled:opacity-40",title:"Edit & rewind to here",children:y&&"preview"===j?(0,n.jsx)(el.kr,{size:11,className:"animate-spin"}):(0,n.jsx)(el.gH,{size:11})})]})]}),s]})}return null},(e,t)=>e.message===t.message&&e.onResolvePermission===t.onResolvePermission&&e.rewindIndex===t.rewindIndex||!e.message.isLive&&!t.message.isLive&&e.message.id===t.message.id&&e.message.content===t.message.content&&e.message.thinking===t.message.thinking&&e.message.permission===t.message.permission&&e.message.tools===t.message.tools&&e.message.diffs===t.message.diffs&&e.canRewind===t.canRewind&&e.rewindIndex===t.rewindIndex&&e.onResolvePermission===t.onResolvePermission);function r4(e,t){if("string"!=typeof e||!e)return{dir:"",name:""};let s=e.replace(/\\/g,"/"),n=t?t.replace(/\\/g,"/").replace(/\/+$/,""):"",r=!!n&&s.startsWith(`${n}/`),l=r?5:4,a=(r?s.slice(n.length+1):s).split("/").filter(Boolean);a.length>l&&(a=["…",...a.slice(-l)]);let i=a.pop()||"";return{dir:a.join("/"),name:i}}let r6={file:el.kU},r8=(0,r.memo)(function e({id:t="",name:s="tool",command:l="",input:a=null,output:i="",error:o="",status:c="done",children:d=[],engine:u="claude",workspacePath:x="",deferred:m=!1}){let p=!!(o||"error"===c),[f,b]=(0,r.useState)(p&&!m),[g,v]=(0,r.useState)(!1),y=(0,h.B)(e=>e.openEditorFile);(0,r.useEffect)(()=>{p&&!m&&b(!0)},[p,m]);let w=!!l||"string"!=typeof a&&!!a?.command,j="string"==typeof a?"":a?.file_path||a?.notebook_path||a?.path||a?.file||"",k=l||j||("string"==typeof a?a:a?.command||a?.pattern||a?.query||""),N=!w&&j&&k===j?function(e,t){let{dir:s,name:n}=r4(e,t);return s?`${s}/${n}`:n}(k,x):k,C="string"==typeof a?a:a&&Object.keys(a).length?JSON.stringify(a,null,2):"",S=a?.file_path||a?.path||a?.file||"",T=r6[(0,ri.$Z)(u,s)]||el.Jl;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>b(!f),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:"running"===c?(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-accent"}):p?(0,n.jsx)(el.RI,{size:13,className:"text-danger"}):(0,n.jsx)(T,{size:13,className:"text-success"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1 font-mono text-[11px] leading-relaxed line-clamp-2",children:[(0,n.jsx)("span",{className:"text-[10px] font-semibold text-text uppercase tracking-wider break-all px-1 py-0.5 rounded bg-surface-2/80 [box-decoration-break:clone]",title:s,children:s}),N&&(0,n.jsxs)(n.Fragment,{children:[" ",(0,n.jsx)("span",{className:"text-text-muted break-all",title:N,children:N})]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 self-center",children:f?(0,n.jsx)(el.yQ,{size:11}):(0,n.jsx)(el.c_,{size:11})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0 ml-2 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:[S&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),S&&y(S)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1",title:"Open file in editor",children:(0,n.jsx)(el.Gr,{size:11})}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)();let t=i||o||N;t&&(navigator.clipboard.writeText("string"==typeof t?t:JSON.stringify(t,null,2)),v(!0),setTimeout(()=>v(!1),2e3))},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors",title:"Copy output",children:g?(0,n.jsx)(el.aJ,{size:11,className:"text-success"}):(0,n.jsx)(el.QR,{size:11})})]})]}),f&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text",children:[C&&(0,n.jsx)("div",{className:"text-text-muted whitespace-pre-wrap break-all leading-relaxed mb-1.5",children:C}),o&&(0,n.jsx)("div",{className:"text-danger mb-1.5 whitespace-pre-wrap",children:o}),i?(0,n.jsx)("div",{className:"text-text whitespace-pre-wrap leading-relaxed",children:"string"==typeof i?i:JSON.stringify(i,null,2)}):o?null:(0,n.jsx)("div",{className:"text-text-muted italic",children:"Running or no output returned..."})]}),f&&d.length>0&&(0,n.jsx)("div",{className:"ml-3.5 pl-3 border-l-2 border-border-subtle/80",children:d.map(t=>(0,n.jsx)(e,{...t,engine:u,workspacePath:x},t.id))})]})}),r9=new Set(["TaskCreate","TaskUpdate","TodoWrite","todowrite"]),r7=e=>!!(0,ri.Tw)(e).questionGate,le=new Set(["Edit","Write","MultiEdit","NotebookEdit","file_change","edit","write","write_to_file","replace_file_content"]),lt=e=>"thought"===e.kind||"tool"===e.kind||"diff"===e.kind;function ls({total:e,windowSize:t=3,children:s}){let[l,a]=(0,r.useState)(0),i=function(e,t,s=0){let n=e-Math.max(0,s);return n>t+1?n-t:0}(e,t,l);return(0,n.jsxs)(n.Fragment,{children:[l>0?(0,n.jsx)("button",{type:"button",onClick:()=>a(e=>e-Math.min(12,Math.max(0,e))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:"▼ show less"}):i>0?(0,n.jsxs)("button",{type:"button",onClick:()=>a(e=>e+Math.min(12,Math.max(0,i))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:["▲ ",i," more ",1===i?"step":"steps"]}):null,s(i)]})}function ln(){let[e,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=window.matchMedia("(hover: none), (pointer: coarse)"),s=()=>t(e.matches);return s(),e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[]),e}let lr=(0,r.memo)(function({file:e="",patch:t="",diff:s="",content:l="",workspacePath:a=""}){let[i,o]=(0,r.useState)(!1),c=(0,h.B)(e=>e.openEditorFile),d=ln(),u=t||s||(t||s||!l?"":String(l).split("\n").map(e=>`+${e}`).join("\n")),x=u?u.split("\n"):[],m=r4(e,a),p=x.filter(e=>e.startsWith("+")&&!e.startsWith("+++")).length,f=x.filter(e=>e.startsWith("-")&&!e.startsWith("---")).length;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>o(!i),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(el.GD,{size:13,className:"text-success shrink-0"}),(0,n.jsx)("span",{className:"min-w-0 font-mono font-medium text-text text-[11px] break-all",title:e,children:m.dir?`${m.dir}/${m.name}`:m.name||"diff"}),(p>0||f>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 font-mono text-[10px] shrink-0 text-text-muted",children:[p>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",p]}),f>0&&(0,n.jsxs)("span",{className:"text-danger",children:["-",f]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:i?(0,n.jsx)(el.yQ,{size:11}):(0,n.jsx)(el.c_,{size:11})})]}),(0,n.jsx)("div",{className:`flex items-center gap-1 shrink-0 ml-2 transition-opacity ${d?"opacity-100":"opacity-0 group-hover/tool:opacity-100"}`,children:e&&(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),(0,ed.e)(),e&&c(e)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1 text-[10px]",title:"Open file in editor",children:(0,n.jsx)(el.Gr,{size:11})})})]}),i&&(0,n.jsx)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand p-2 overflow-x-auto max-h-[300px] overflow-y-auto font-mono text-[11px] leading-relaxed select-text",children:0===x.length?(0,n.jsx)("div",{className:"text-text-muted italic py-1 px-2",children:"No changes"}):x.map((e,t)=>{let s=e.startsWith("+")&&!e.startsWith("+++"),r=e.startsWith("-")&&!e.startsWith("---"),l=e.startsWith("@@"),a="text-text",i="";return s?(a="text-success",i="bg-success/10"):r?(a="text-danger",i="bg-danger/10"):l&&(a="text-text-muted",i="bg-surface-2/40"),(0,n.jsx)("div",{className:`px-2 py-0.5 rounded-sm whitespace-pre ${a} ${i}`,children:e},t)})})]})});var ll=s(6552);let la=(0,r.memo)(function({text:e="",isLive:t=!1,defaultOpen:s=!1}){let[l,a]=(0,r.useState)(s);return e?.trim()?(0,n.jsxs)("div",{className:"my-1.5 text-xs select-none",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>a(e=>!e),className:"inline-flex items-center gap-1.5 text-[11px] text-text-muted hover:text-text py-0.5 transition-colors cursor-pointer group",children:[(0,n.jsx)(el.sU,{size:12,className:t?"animate-pulse text-success":"text-success"}),(0,n.jsx)("span",{className:"italic",children:t?"Thinking...":"Thought process"}),(0,n.jsx)("span",{className:"text-text-muted/50 group-hover:text-text-muted",children:l?(0,n.jsx)(el.yQ,{size:12}):(0,n.jsx)(el.c_,{size:12})})]}),l&&(0,n.jsx)("div",{className:"mt-1 pl-3.5 border-l-2 border-border-subtle/80 font-mono text-[11px] text-text-muted leading-relaxed whitespace-pre-wrap max-h-[260px] overflow-y-auto custom-scrollbar select-text py-1",children:e})]}):null}),li=/Command running in background with ID:\s*([^\s.]+)/;var lo=s(14890);let lc=(0,r.memo)(function({id:e="",name:t="Bash",input:s=null,output:l="",error:a="",status:i="done",deferred:o=!1,defaultExpanded:c=!1}){let d,{sessionId:u}=(0,lo.OO)(),x=!!(a||"error"===i),[m,p]=(0,r.useState)(x&&!o||c),[f,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(!1);(0,r.useEffect)(()=>{x&&!o&&p(!0)},[x,o]);let v=s?.command||"",y=s?.description||"",w=a||l||"",j="string"==typeof w?w:w?JSON.stringify(w,null,2):"",k=(d=li.exec("string"==typeof l?l:""))?d[1]:"",N=!!(s?.run_in_background||k);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:(0,lo.xo)(u,"shell",e),children:[(0,n.jsxs)("div",{onClick:()=>p(!m),className:"flex items-start justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0 mt-0.5",children:"running"===i?(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-accent"}):x?(0,n.jsx)(el.RI,{size:13,className:"text-danger"}):(0,n.jsx)(el.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:"text-text-muted select-none shrink-0 font-mono text-[11px] leading-relaxed",children:"$"}),(0,n.jsx)("span",{className:`font-mono text-[11px] leading-relaxed text-text min-w-0 ${m?"":"line-clamp-2"}`,title:v,children:v||t}),N&&(0,n.jsxs)("span",{className:"font-mono text-[10px] font-semibold text-warning shrink-0 px-1 py-0.5 rounded bg-warning/10",title:k?`Background shell ${k}`:"Running in the background",children:["BG",k?` ${k}`:""]}),j&&(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:m?(0,n.jsx)(el.yQ,{size:11}):(0,n.jsx)(el.c_,{size:11})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 shrink-0 ml-2 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:v&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),navigator.clipboard.writeText(v),h(!0),setTimeout(()=>h(!1),2e3)},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors text-[10px] flex items-center gap-0.5",title:"Copy command",children:f?(0,n.jsx)(el.aJ,{size:11,className:"text-success"}):(0,n.jsx)(el.QR,{size:11})})})]}),y&&!m&&(0,n.jsxs)("div",{className:"ml-7 text-[10px] text-text-muted/70 italic truncate",children:["# ",y]}),m&&j&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 bg-surface-2/20 rounded-r-brand overflow-x-auto max-h-[260px] overflow-y-auto font-mono text-[11px] select-text relative group/out",children:[y&&(0,n.jsxs)("div",{className:"px-2 pt-1.5 text-[10px] text-text-muted/70 italic",children:["# ",y]}),(0,n.jsx)("pre",{className:`p-2 whitespace-pre-wrap leading-relaxed ${x?"text-danger":"text-text"}`,children:j}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),navigator.clipboard.writeText(j),g(!0),setTimeout(()=>g(!1),2e3)},className:"absolute top-1.5 right-1.5 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-0 group-hover/out:opacity-100 transition-opacity text-[10px]",title:"Copy output",children:b?(0,n.jsx)(el.aJ,{size:10,className:"text-success"}):(0,n.jsx)(el.QR,{size:10})})]})]})});function ld(e){let t=String(e||"").split("\n")[0].trim();return t.length>140?`${t.slice(0,140)}…`:t}let lu=(0,r.memo)(function({id:e="",name:t="Agent",input:s=null,output:l="",error:a="",status:i="done",children:o=[],engine:c="claude",workspacePath:d="",defaultExpanded:u=!1}){let{sessionId:x}=(0,lo.OO)(),m="running"===i,p=!!(a||"error"===i),f=o.filter(e=>"running"===e.status).length,[h,b]=(0,r.useState)(p||u);(0,r.useEffect)(()=>{p&&b(!0)},[p]);let g=rt.has(t),v=g?rs({input:s}):t||"agent",y=g?ld(s?.prompt??s?.description??s?.message):ld(s?.message??s?.prompt??s?.query);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:(0,lo.xo)(x,"agent",e),children:[(0,n.jsxs)("div",{onClick:()=>b(!h),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control select-none transition-colors group/tool",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"shrink-0",children:m?(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-accent"}):p?(0,n.jsx)(el.RI,{size:13,className:"text-danger"}):(0,n.jsx)(el.Jl,{size:13,className:"text-success"})}),(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:"AGENT"}),(0,n.jsx)("span",{className:"font-mono text-[11px] font-semibold text-brand-500 shrink-0",children:v}),y&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",title:y,children:y})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 shrink-0 ml-2",children:[o.length>0&&(0,n.jsxs)("span",{className:"font-mono text-[10px] text-text-subtle",title:`${o.length} sub-agent tool calls`,children:[m&&f>0?`${f}/${o.length}`:o.length," tools"]}),(0,n.jsx)("span",{className:"text-text-muted/50",children:h?(0,n.jsx)(el.yQ,{size:11}):(0,n.jsx)(el.c_,{size:11})})]})]}),h&&(0,n.jsxs)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 py-1 space-y-0.5",children:[o.length>0?(0,n.jsx)(ls,{total:o.length,children:e=>(e>0?o.slice(e):o).map(e=>lh(c,e,{workspacePath:d})||(0,n.jsx)(r8,{...e,engine:c,workspacePath:d},e.id))}):(0,n.jsx)("div",{className:"text-text-muted italic py-0.5",children:m?"Sub-agent started…":"No tool calls reported."}),!m&&(l||a)&&(0,n.jsx)("div",{className:"mt-1 pl-3 border-l-2 border-border-subtle/60 font-mono text-[11px] max-h-[240px] overflow-y-auto select-text",children:(0,n.jsx)("div",{className:`whitespace-pre-wrap leading-relaxed ${p?"text-danger":"text-text-muted"}`,children:"string"==typeof(a||l)?a||l:JSON.stringify(a||l,null,2)})})]})]})}),lx=(0,r.memo)(function({toolName:e="EnterPlanMode",input:t={}}){let s="string"==typeof t?.plan?t.plan.trim():"";if(s)return(0,n.jsx)(lm,{plan:s,explanation:t?.explanation||""});let r="EnterPlanMode"===e,l=t?.reason||(r?"Exploring codebase and designing implementation approach":"Implementation plan finalized");return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${r?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between font-semibold",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[r?(0,n.jsx)(el.y8,{size:16,className:"text-brand-500"}):(0,n.jsx)(el.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:r?"Plan Mode Activated":"Plan Mode Completed"})]}),(0,n.jsx)("span",{className:"font-mono text-[10px] px-2 py-0.5 rounded bg-surface-2 text-text-muted",children:e})]}),(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reason: "}),l]}),r&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted/80 italic pl-6 select-none",children:"Plan mode reads files and drafts an approach — nothing is applied without your review, in whichever CLI this chat is running."})]})}),lm=(0,r.memo)(function({plan:e,explanation:t=""}){return(0,n.jsxs)("div",{className:"p-3.5 rounded-brand-lg border border-brand-500/30 bg-brand-500/10 text-text my-2 text-xs flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[(0,n.jsx)(el.y8,{size:16,className:"text-brand-500"}),(0,n.jsx)("span",{children:"Plan"})]}),(0,n.jsx)("pre",{className:"font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-words pl-6 max-h-[320px] overflow-y-auto",children:e}),t&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted pl-6 italic",children:t})]})}),lp=(0,r.memo)(function({toolName:e="enteredReviewMode",input:t={}}){let s="enteredReviewMode"===e,r=String(t?.review||"").trim();return(0,n.jsxs)("div",{className:`p-3.5 rounded-brand-lg border flex flex-col gap-2 my-2 text-xs ${s?"bg-brand-500/10 border-brand-500/30 text-text":"bg-success/10 border-success/30 text-success"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[s?(0,n.jsx)(el.kU,{size:16,className:"text-brand-500"}):(0,n.jsx)(el.Jl,{size:16,className:"text-success"}),(0,n.jsx)("span",{children:s?"Code review started":"Code review finished"})]}),r&&(0,n.jsxs)("div",{className:"text-xs text-text leading-relaxed font-sans pl-6",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Reviewing: "}),r]})]})}),lf={bash:(e,t,s)=>(0,n.jsx)(lc,{...e,deferred:t,defaultExpanded:s?.defaultExpanded},e.id),agent:(e,t,{engine:s,workspacePath:r,defaultExpanded:l})=>(0,n.jsx)(lu,{...e,engine:s,workspacePath:r,defaultExpanded:l},e.id),plan:e=>(0,n.jsx)(lx,{toolName:e.name,input:e.input},e.id),review:e=>(0,n.jsx)(lp,{toolName:e.name,input:e.input},e.id),question:(e,t,s)=>{if("running"===e.status||!e.output&&!e.error)return null;let r=!!(0,ri.Tw)(s?.engine).headlessQuestions&&/user skipped/i.test(String(e.output||""));return(0,n.jsx)(ll.J,{engine:s?.engine,questions:e.input?.questions||[],answers:r||e.error?null:e.output||"",declined:r||!!e.error||"error"===e.status},e.id)}};function lh(e,t,s={}){let n=lf[(0,ri.$Z)(e,t.name)];return n?n(t,s.deferred,{...s,engine:e}):null}var lb=s(49430),lg=s(93473);let lv=(e,t)=>function({children:s,className:r,node:l,...a}){return(0,n.jsx)(e,{className:r?`${t} ${r}`:t,...a,children:s})},ly={h1:lv("h1","text-xl sm:text-2xl font-bold border-b border-border-subtle pb-2 mt-5 mb-3 text-text first:mt-0"),h2:lv("h2","text-lg sm:text-xl font-bold border-b border-border-subtle pb-1.5 mt-4 mb-2.5 text-text first:mt-0"),h3:lv("h3","text-base sm:text-lg font-semibold mt-3.5 mb-2 text-text"),h4:lv("h4","text-sm sm:text-base font-semibold mt-3 mb-1.5 text-text"),h5:lv("h5","text-xs sm:text-sm font-semibold mt-2.5 mb-1 text-text"),h6:lv("h6","text-xs font-semibold mt-2 mb-1 text-text-muted"),p:lv("p","my-2 leading-relaxed text-text text-sm"),ul:lv("ul","list-disc pl-5 my-2 space-y-1 text-sm text-text"),ol:lv("ol","list-decimal pl-5 my-2 space-y-1 text-sm text-text"),li:lv("li","leading-relaxed"),blockquote:lv("blockquote","border-l-4 border-brand-500/40 pl-3.5 my-2.5 text-text-muted italic text-sm"),th:lv("th","border border-border-subtle bg-surface-2 px-3 py-1.5 font-semibold text-left text-text align-top whitespace-normal break-words"),td:lv("td","border border-border-subtle px-3 py-1.5 text-text align-top whitespace-normal break-words"),hr:lv("hr","border-t border-border-subtle my-4"),img:({alt:e="",node:t,...s})=>(0,n.jsx)("img",{className:"max-w-full h-auto rounded my-2",alt:e,...s}),a:({children:e,className:t,node:s,...r})=>(0,n.jsx)("a",{className:`text-brand-500 hover:underline wrap-anywhere${t?` ${t}`:""}`,target:"_blank",rel:"noopener noreferrer",...r,children:e}),table:({children:e,node:t,...s})=>(0,n.jsx)("table",{className:"w-full table-fixed border-collapse border border-border-subtle text-xs my-3",...s,children:e}),pre:function({children:e,node:t,...s}){let[l,a]=(0,r.useState)(!1),i=(0,r.useRef)(null);return(0,n.jsxs)("div",{className:"relative group/code my-2.5",children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)();let t=i.current?.innerText||"";try{navigator.clipboard.writeText(t)}catch{}a(!0),setTimeout(()=>a(!1),2e3)},className:"absolute top-2 right-2 p-1 rounded bg-surface-3/80 hover:bg-surface-3 text-text-muted hover:text-text opacity-100 sm:opacity-0 sm:group-hover/code:opacity-100 transition-opacity z-10",title:"Copy code",children:l?(0,n.jsx)(el.aJ,{size:13,className:"text-brand-500"}):(0,n.jsx)(el.QR,{size:13})}),(0,n.jsx)("pre",{ref:i,className:"p-3 rounded bg-surface-2 whitespace-pre-wrap break-words text-[12px] font-mono border border-border-subtle text-text [&_code]:bg-transparent [&_code]:p-0 [&_code]:border-0 [&_code]:text-text",...s,children:e})]})},code:({children:e,className:t,node:s,...r})=>{let l=/language-/.test(t||"");return(0,n.jsx)("code",{className:`${l?"font-mono text-[12px] text-text":"font-mono text-[0.9em] text-accent wrap-anywhere"}${t?` ${t}`:""}`,...r,children:e})},input:({type:e,checked:t,node:s,...r})=>"checkbox"===e?(0,n.jsx)("input",{type:"checkbox",checked:t,readOnly:!0,className:"mr-2 rounded accent-brand-500 cursor-default",...r}):(0,n.jsx)("input",{type:e,...r})},lw=(0,r.memo)(function({content:e,components:t}){return(0,n.jsx)(lb.oz,{remarkPlugins:[lg.A],components:t?{...ly,...t}:ly,children:e})},(e,t)=>e.content===t.content);function lj({row:e,engine:t,workspacePath:s,deferred:r}){if("thought"===e.kind)return(0,n.jsx)(la,{text:e.text,isLive:e.isLive});if("diff"===e.kind){let t=e.diff;return(0,n.jsx)(lr,{file:t.file,patch:t.patch,diff:t.diff,content:t.content,workspacePath:s})}let l=e.tool;return lh(t,l,{workspacePath:s,deferred:r})||(0,n.jsx)(r8,{...l,engine:t,workspacePath:s,deferred:r})}let lk={info:"text-text-muted",suggestion:"text-text-muted",warning:"text-warning",error:"text-danger"};function lN({notice:e}){if(!e?.content)return null;let t=`text-xs leading-relaxed py-1 px-2 my-0.5 rounded border-l-2 border-current/30 bg-surface-2/40 wrap-anywhere ${lk[e.level]||lk.info}`;return e.compacting?(0,n.jsxs)("div",{className:`${t} flex items-center gap-2`,children:[(0,n.jsx)(el.kr,{size:12,className:"animate-spin text-brand-500 shrink-0"}),(0,n.jsx)("span",{children:e.content}),(0,n.jsx)(lS,{})]}):(0,n.jsxs)("div",{className:t,children:[e.content,e.compact?.detail&&(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",e.compact.detail]}),e.compact?.durationMs?(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",lC(e.compact.durationMs)]}):null]})}function lC(e){let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`}function lS(){let[e]=(0,r.useState)(()=>Date.now()),[t,s]=(0,r.useState)(e);return(0,r.useEffect)(()=>{let e=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(e)},[]),(0,n.jsx)("span",{className:"text-text-muted/70 tabular-nums",children:lC(t-e)})}function lT({content:e,isLive:t}){let s=function(e,t){let[s,n]=(0,r.useState)(e),l=(0,r.useRef)(e);return(0,r.useEffect)(()=>{l.current=e},[e]),(0,r.useEffect)(()=>{if(!t)return;let e=setInterval(()=>{n(e=>e===l.current?e:l.current)},80);return()=>clearInterval(e)},[t]),t?s:e}(e,t);return(0,n.jsxs)("div",{className:"text-sm leading-relaxed text-text py-1.5 wrap-anywhere",children:[(0,n.jsx)(lw,{content:s}),t&&(0,n.jsx)("span",{className:"inline-block w-1.5 h-3.5 bg-brand-500 animate-pulse ml-1 align-middle"})]})}let lR=(0,r.memo)(function({messages:e=[],engine:t="claude",workspacePath:s="",onResolvePermission:l,isLive:a=!0}){let i=(0,r.useMemo)(()=>(function(e=[],t="claude"){let s=[],n=new Set;for(let r of e){if("notice"===r.role){s.push({kind:"notice",id:r.id,notice:{subtype:r.subtype,level:r.level,content:r.content,...r.compact?{compact:r.compact}:null,...r.compacting?{compacting:!0}:null}});continue}if("assistant"!==r.role)continue;r.thinking?.trim()&&s.push({kind:"thought",id:`${r.id}-th`,text:r.thinking});let e=function(e,t,s){return(t||[]).filter(t=>!(!t||!t.name||(s||[]).some(e=>{let s;return e.file&&(s=e.file,le.has(t?.name)&&s&&((t.input?.paths||[]).includes(s)||((e={})=>e.file_path||e.notebook_path||e.path||e.filePath||e.file||"")(t.input)===s))})||"task"===(0,ri.$Z)(e,t.name)&&r9.has(t.name)))}(t,r.tools,r.diffs);for(let l=0;l<e.length;l++){let a=e[l];if("question"===(0,ri.$Z)(t,a.name)&&"running"===a.status&&r7(t))continue;let i=a.id||`${r.id}-t${l}`;n.has(i)||(n.add(i),s.push({kind:"tool",id:i,tool:a,engine:t}))}for(let e=0;e<(r.diffs?.length||0);e++){let t=r.diffs[e];s.push({kind:"diff",id:`${r.id}-d${e}`,diff:t})}r.content&&s.push({kind:"prose",id:`${r.id}-p`,content:r.content,isLive:r.isLive}),r.permission&&s.push({kind:"permission",id:`${r.id}-perm`,permission:r.permission})}return s})(e,t),[e,t]),o=(0,r.useMemo)(()=>(function(e=[],t=6,{deferred:s=!1}={}){let n=[];for(let t of e)if(lt(t)){let e=n[n.length-1];e?.type==="steps"?e.rows.push(t):n.push({type:"steps",rows:[t]})}else n.push({type:"row",row:t});return n.map((e,n)=>{if("steps"!==e.type)return{...e,key:`r${n}`,deferred:s};let r=e.rows.length>t+1?e.rows.length-t:0;return{type:"steps",key:`s${n}`,rows:e.rows,hidden:r,deferred:s}})})(i,3,{deferred:!a}),[i,a]);return(0,n.jsx)("div",{className:"my-1",children:o.map(e=>{if("steps"!==e.type){if("prose"===e.row.kind)return(0,n.jsx)(lT,{content:e.row.content,isLive:e.row.isLive},e.key);if("notice"===e.row.kind)return(0,n.jsx)(lN,{notice:e.row.notice},e.key);if("permission"===e.row.kind){let t=e.row.permission;return(0,n.jsx)(ll.J,{requestId:t.requestId,questions:t.input?.questions||[],onResolve:l},e.key)}return null}return(0,n.jsx)("div",{className:"relative pl-2.5 border-l-2 border-border-subtle/50 my-1",children:(0,n.jsx)(ls,{total:e.rows.length,children:r=>(r>0?e.rows.slice(r):e.rows).map(e=>(0,n.jsx)(lj,{row:e,engine:t,workspacePath:s,deferred:!a},e.id))})},e.key)})})},(e,t)=>{if(e.messages.length!==t.messages.length)return!1;for(let s=0;s<e.messages.length;s++)if(e.messages[s]!==t.messages[s])return!1;return e.engine===t.engine&&e.workspacePath===t.workspacePath&&e.isLive===t.isLive&&e.onResolvePermission===t.onResolvePermission});function lE({background:e=!1,engine:t="claude",size:s=16,className:r=""}){if(e)return(0,n.jsx)(el.BK,{size:s,className:r||"text-text"});let l=e5(t);return l?(0,n.jsx)("img",{src:l,alt:t,draggable:!1,style:{width:s,height:s},className:`flex-shrink-0 object-contain ${e2} ${r}`}):(0,n.jsx)(el.cC,{size:s,className:r||"text-text"})}let l$=(0,r.memo)(function({tasks:e=[],messages:t=[],engine:s="claude",sessionId:l="",onStopTask:a,onClose:i}){let[o,c]=(0,r.useState)(()=>Date.now()),[d,u]=(0,r.useState)(null),x=rH(e=>e.bySession[l]?.harnessTasks);(0,r.useEffect)(()=>{let e=setInterval(()=>c(Date.now()),1e3);return()=>clearInterval(e)},[]);let m=(0,r.useMemo)(()=>e.map(e=>x?.find(t=>t.taskId===e.taskId)||e),[e,x]),p=m.find(e=>e.taskId===d)||m[0];if(!p)return null;let f=rw(p,o),h=!p.endedAt&&("running"===p.status||"paused"===p.status);return(0,n.jsxs)(ns,{icon:(0,n.jsx)(lE,{background:p.background,engine:s,size:16}),iconClass:"",title:p.description||p.subagentType||"Task",subtitle:h?`Running for ${r5(f)}`:`Ended \xb7 ${r5(f)}`,onClose:i,actions:h&&p.taskId&&a?(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),a(p.taskId)},className:"px-2.5 py-1 rounded-brand text-xs font-medium text-danger bg-danger/10 hover:bg-danger/20 transition-colors flex items-center gap-1.5",title:"Stop this task",children:[(0,n.jsx)(el.M6,{size:10,className:"fill-current"}),(0,n.jsx)("span",{children:"Stop"})]}):null,children:[m.length>1&&(0,n.jsx)("div",{className:"px-4 py-2 border-b border-border-subtle bg-bg flex items-center gap-1 overflow-x-auto custom-scrollbar shrink-0",children:m.map((e,t)=>{let r=e.taskId===p.taskId;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),u(e.taskId)},className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 rounded-brand text-xs transition-colors ${r?"bg-surface-2 text-text font-medium":"text-text-muted hover:text-text hover:bg-surface-2/40"}`,children:[(0,n.jsx)(lE,{background:e.background,engine:s,size:13,className:r?"opacity-100":"opacity-60"}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:e.description||e.subagentType||e.taskId}),(0,n.jsx)("span",{className:"font-mono text-[10px] opacity-60 tabular-nums",children:"running"===e.status?r5(rw(e,o)):e.status})]},e.taskId||e.id||t)})}),(0,n.jsxs)("div",{className:"p-3 flex-1 overflow-y-auto custom-scrollbar",children:[(0,n.jsx)(lz,{task:p,messages:t,engine:s,running:h}),p.summary&&(0,n.jsx)("p",{className:"mt-3 text-[11px] text-text-muted leading-relaxed",children:p.summary}),p.outputFile&&(0,n.jsxs)("p",{className:"mt-3 font-mono text-[10px] text-text-subtle truncate",title:p.outputFile,children:["output \xb7 ",p.outputFile]})]})]})});function lz({task:e,messages:t,engine:s,running:r}){let l=rr(t,e.toolUseId);if(!l)return(0,n.jsx)("div",{className:"flex flex-col items-center justify-center gap-2.5 py-14 text-text-muted select-none",children:r?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el.kr,{size:24,className:"animate-spin text-brand-500 opacity-80"}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-text",children:"Task is running..."}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle mt-0.5",children:"Waiting for task calls or tool events"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(lE,{background:e.background,engine:s,size:28,className:"opacity-40"}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-text",children:"No calls recorded"}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle mt-0.5",children:"This task ended without child tool calls"})]})]})});let a=l.children?.length?l.children:[l],i=l.input?.prompt||l.input?.description||"",o=l.error||l.output||"";return(0,n.jsxs)("div",{className:"flex flex-col",children:[i&&!l.async&&(0,n.jsx)(r3,{message:{id:`${l.id}:p`,role:"user",content:i},engine:s}),a.map(e=>lh(s,e,{deferred:!r,workspacePath:""})||(0,n.jsx)(r8,{...e,engine:s,workspacePath:"",deferred:!r},e.id)),!r&&o&&(0,n.jsx)(lR,{messages:[{id:`${l.id}:r`,role:"assistant",content:String(o),isLive:!1}],engine:s,isLive:!1})]})}let lM=[{start:0,until:50,pct:[0,70],key:"menu.updateInstalling"},{start:50,until:80,pct:[70,90],key:"menu.updateRestarting"},{start:80,until:95,pct:[90,99],key:"menu.updateReconnecting"}],lP=lM[lM.length-1];function lA({className:e=""}){let{t}=(0,eu.s)(),[s,l]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>l((Date.now()-e)/1e3),500);return()=>clearInterval(t)},[]);let a=lM.find(e=>s<e.until)||lP,i=Math.min(1,Math.max(0,(s-a.start)/(a.until-a.start))),o=Math.round(a.pct[0]+(a.pct[1]-a.pct[0])*i);return(0,n.jsxs)("div",{className:`flex items-center gap-2 min-w-0 ${e}`,title:`${t(a.key)} — ${o}%`,children:[(0,n.jsx)(el.kr,{size:12,className:"animate-spin text-brand-400 shrink-0"}),(0,n.jsx)("span",{className:"h-1 flex-1 min-w-[60px] rounded-full bg-surface-2 overflow-hidden",children:(0,n.jsx)("span",{className:"block h-full bg-brand-500 rounded-full transition-[width] duration-500 ease-out",style:{width:`${o}%`}})})]})}function lI({hostKey:e,approval:t,onDeleteHost:s=null}){let{t:r}=(0,eu.s)();if(!t)return null;let l="pending"===t;return(0,n.jsxs)("div",{className:`flex items-center gap-2 py-1.5 ${l?"":"text-red-400"}`,children:[l?(0,n.jsx)(el.kr,{size:14,className:"animate-spin text-text-subtle shrink-0"}):(0,n.jsx)(el.MA,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"text-[11px] truncate flex-1 min-w-0",title:r(l?"connection.approvalHint":"connection.rejectedDescription"),children:r(l?"connection.waitingApproval":"connection.rejectedTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),P.rh.getState().connectHost(e)},className:"px-2 py-0.5 text-[11px] text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors shrink-0",children:r("common.retry")}),l?(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),P.rh.getState().disconnectHost(e)},className:"px-2 py-0.5 text-[11px] text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors shrink-0",children:r("common.cancel")}):s&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),s(e)},className:"px-2 py-0.5 text-[11px] text-red-400 hover:text-red-300 bg-red-500/10 hover:bg-red-500/20 rounded-brand transition-colors shrink-0",children:r("hosts.removeHost")})]})}let lD=[];function lL({host:e,actions:t={},busRef:s=null,activeSessionId:l=null,activeWorkspaceId:a=null,connected:i=!0,fileBus:o=null,homeDir:c=null,hiddenPaneSessionIds:d=[],onUnhidePane:u=null,onAddWorkspace:x=null,menuAddWorkspace:m=null,onOpenRemoteHost:p=null,onOpenMobileHost:f=null,onRowContextMenu:h=null,onRowTouch:b=null,onRowMenu:g=null,agentBySession:v=null,cwdBySession:y=null,treeCls:w="pl-3.5",mobile:j=!1,onResumeAgentSession:k=null,rowCls:N="hover:bg-text/5 hover:text-text"}){let{t:C}=(0,eu.s)(),{isCollapsed:S,toggle:T}=function(e=""){let[t,s]=(0,r.useState)(()=>new Set(n2()[e]||[])),n=(0,r.useCallback)(t=>{s(s=>{let n=new Set(s);n.has(t)?n.delete(t):n.add(t);let r=n2();r[e]=[...n];try{localStorage.setItem(n0,JSON.stringify(r))}catch{}return n})},[e]);return{isCollapsed:(0,r.useCallback)(e=>t.has(e),[t]),toggle:n}}(e.key),R=!S(n1),[E,$]=(0,r.useState)(null),[z,M]=(0,r.useState)(null),[A,I]=(0,r.useState)(null),[D,L]=(0,r.useState)(null),[B,F]=(0,r.useState)(null),[K,O]=(0,r.useState)(!1),[W,_]=(0,r.useState)([]),[H,U]=(0,r.useState)(!1),q=e.status||"full",X="connecting"===q,V="full"===q||"online"===q,J="full"===q?i:V,G="full"!==q?eE(e.key):null,Y=s||G?.busRef||null;(0,r.useEffect)(()=>{null!==E&&Y?.current?.emit&&Y.current.emit("getShells",e=>_(e?.shells||[]))},[E,Y]);let{dragId:Z,registerEl:Q,startDrag:ee,consumeClick:et}=sJ({axis:"y",onCommit:e=>t.reorderSession?.(e)}),es=(0,r.useRef)(null),en=()=>{es.current&&(clearTimeout(es.current.timer),es.current=null)},er=e=>{let t=es.current;t&&(Math.abs(e.clientX-t.start.x)>eJ.Qe||Math.abs(e.clientY-t.start.y)>eJ.Qe)&&en()};(0,r.useEffect)(()=>{if(!Z)return;let e=e=>e.preventDefault();return window.addEventListener("touchmove",e,{passive:!1}),()=>window.removeEventListener("touchmove",e)},[Z]);let ea=function(e=[],t=[]){let s=new Set(t.map(e=>e.id)),n=new Map;for(let t of e){let e=s.has(t.workspaceId)?t.workspaceId:null;n.has(e)||n.set(e,[]),n.get(e).push(t)}return[...t.map(e=>({workspace:e,sessions:n.get(e.id)||[]})),...n.has(null)?[{workspace:null,sessions:n.get(null)}]:[]]}(e.sessions,e.workspaces),ei=(0,r.useMemo)(()=>new Set((e.sessions||[]).map(e=>e.id)),[e.sessions]);return(0,n.jsxs)("div",{children:[(0,n.jsx)(nQ,{mobile:j,hostKey:e.key,label:e.label,connected:V,connecting:X,mutedOffline:"full"!==q,collapsed:!R,meta:X?(0,n.jsx)(el.kr,{size:12,className:"animate-spin text-text-subtle"}):null,hostUpdating:!!e.updating,onOpenRemote:V&&e.remoteAvailable&&p?()=>p(e.key):null,onOpenMobile:V&&e.mobileAvailable&&f&&!e.updating?()=>f(e.key):null,onToggleCollapse:V?()=>{(0,ed.e)(),R||P.rh.getState().ensureHost(e.key),T(n1)}:null,onConnect:"offline"===q?e.onConnect||(()=>P.rh.getState().connectHost(e.key)):null,onDisconnect:e.onDisconnect,onAddWorkspace:J?m??("full"!==q?()=>O(!0):null):null,onRename:t.renameHost,onDelete:t.deleteHost,showAdd:!1}),e.updating?(0,n.jsx)("div",{className:`${w} py-2`,children:(0,n.jsx)(lA,{})}):e.approval?(0,n.jsx)("div",{className:w,children:(0,n.jsx)(lI,{hostKey:e.key,approval:e.approval,onDeleteHost:t.deleteHost})}):R&&V&&(0,n.jsxs)("div",{className:w,children:[e.updateAvailable&&e.canSelfUpdate&&!e.approval&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),U(!0)},title:C("menu.updateAvailableTitle"),className:"flex items-center gap-1.5 px-2 py-1 mb-1 max-w-full text-[11px] font-medium text-brand-400 hover:text-brand-300 bg-brand-500/10 hover:bg-brand-500/20 rounded-brand transition-colors",children:[(0,n.jsx)(el.f5,{size:12,className:"shrink-0"}),(0,n.jsxs)("span",{className:"truncate",children:[C("menu.updateNow"),e.updateAvailable?.version?` \xb7 ${e.updateAvailable.version}`:""]})]}),ea.map(({workspace:i,sessions:x})=>{let p=i?.id??null,f=p??"ungrouped",w=a===p;return(0,n.jsxs)("div",{className:`flex flex-col ${j?"":"mt-1 first:mt-0"}`,children:[(0,n.jsx)(n7,{mobile:j,workspace:{id:p,name:i?.name||C("workspaces.ungrouped"),path:i?.path||null,items:x},isActive:w,connected:J,fileBus:o,collapsed:S(f),onToggleCollapse:()=>T(f),onSelect:t.selectWorkspace?()=>{(0,ed.e)(),t.selectWorkspace(p)}:null,onNewTerminal:t.createSession?()=>$(f):null,onAddWorkspace:m,onRename:t.renameWorkspace&&null!=p?()=>M({id:p,value:i.name}):null,onDelete:t.deleteWorkspace&&null!=p?()=>I({id:p,name:i.name}):null}),!S(f)&&x.map(s=>{let a=e.statusMap?.[s.id]?.state||"idle",m=se(a),w=l===s.id,k=Z===s.id,S=d.includes(s.id),T=s.name||C("terminal.defaultName");return(0,n.jsx)(r.Fragment,{children:(0,n.jsxs)("div",{ref:Q(s.id),"data-sid":s.id,className:`group flex items-center gap-1.5 ${j?"pl-6":"pl-3.5"} pr-2 py-1.5 ml-0.5 rounded-[3px] text-left relative cursor-pointer select-none touch-manipulation touch-pan-y ${w?"bg-brand-500/15 text-text":`text-text-muted ${N}`} ${k?"z-20 opacity-90 shadow-lg ring-1 ring-brand-500":"transition-colors"}`,onClick:e=>{et()||((0,ed.e)(),t.selectSession?.(s.id))},onPointerDown:e=>((e,t,s)=>{if(s.length<2||!J)return;if("mouse"===e.pointerType)return void ee(e,t,s);if(b)return;let n={x:e.clientX,y:e.clientY};es.current={timer:setTimeout(()=>{en(),(0,ed.e)(),ee(e,t,s)},eJ.A_),start:n}})(e,s.id,x.map(e=>e.id)),onPointerMove:er,onPointerUp:en,onPointerCancel:en,onPointerLeave:en,onContextMenu:h?e=>h(e,s.id,T):void 0,onTouchStart:b?.start,onTouchMove:b?.move,onTouchEnd:b?.end,children:[J&&(0,n.jsx)("button",{"data-gid":"ungrouped"===f?"":p,"data-sid":s.id,onPointerDown:e=>{e.stopPropagation(),ee(e,s.id,x.map(e=>e.id))},disabled:x.length<2,className:"absolute left-0 top-1/2 -translate-y-1/2 z-10 p-0.5 text-text-subtle opacity-0 group-hover:opacity-100 cursor-grab active:cursor-grabbing touch-none disabled:opacity-0 disabled:cursor-default",tabIndex:-1,children:(0,n.jsx)(el.f2,{size:12})}),(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 term-dot ${m.cls}${m.pulse?` pulse-${m.pulse}`:""}`,style:{background:m.dot}}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("span",{className:`flex items-center gap-1.5 min-w-0 ${w?"font-medium":""}`,children:[(0,n.jsx)(sb,{agent:v?.[s.id]??s.agent,tool:e.statusMap?.[s.id]?.tool}),(0,n.jsx)("span",{className:`${j?"text-base":"text-[11px]"} truncate`,"data-tip":T,children:T}),S&&u&&(0,n.jsx)("button",{type:"button",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),(0,ed.e)(),u(s.id)},className:"p-0.5 rounded text-amber-400 hover:text-amber-300 hover:bg-amber-400/20 transition-colors flex items-center justify-center shrink-0 ml-1",title:C("sessions.showPanel")||"Show panel",children:(0,n.jsx)(el.X_,{size:12})})]}),(0,n.jsx)(re,{mobile:j,fileBus:o,cwd:y?.[s.id]??s.cwd??s.workspacePath,basePath:sm({path:i?.path||null,items:x}),homeDir:c})]}),(0,n.jsx)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center ${j?"opacity-100":"px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-60"} transition-opacity`,children:g?(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)();let t=e.currentTarget.getBoundingClientRect();g(s.id,T,t)},className:"p-0.5 text-text-subtle hover:text-text rounded-[2px] transition-colors",title:C("sessions.sessionActions"),children:(0,n.jsx)(el.a4,{size:j?18:13.5})}):(0,n.jsx)(nX,{size:j?18:13.5,label:C("sessions.sessionActions"),revealCls:"",items:["done"===a&&{icon:el.aJ,label:C("sessions.markRead"),amber:!0,onClick:()=>ej.getState().clearNotification(s.id)},t.renameSession&&{icon:el.gH,label:C("sessions.editName"),onClick:()=>L({id:s.id,value:s.name||""})},t.backgroundSession&&{icon:el._V,label:C("menu.terminalBackground"),onClick:()=>t.backgroundSession(s)},t.deleteSession&&{icon:el.TB,label:C("sessions.deleteTitle"),danger:!0,onClick:()=>F({id:s.id,name:s.name||""})}]})})]})},s.id)}),!S(f)&&s&&(0,n.jsx)(lB,{busRef:s,storeKey:p??"default",mobile:j,rowCls:N,activeWs:w,onSelectWorkspace:t.selectWorkspace?()=>t.selectWorkspace(p):null}),!S(f)&&(j?(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),$(f)},disabled:!J,className:"w-full flex items-center gap-1.5 pl-[38px] py-1.5 text-left text-sm text-text-subtle hover:text-brand-500 transition-colors disabled:opacity-40",title:C("workspaces.addTerminal"),children:[(0,n.jsx)(el.FW,{size:14,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:C("terminal.newTerminal")})]}):0===x.length?(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),$(f)},disabled:!J,className:"w-full flex items-center gap-1.5 pl-3.5 pr-2 py-1.5 text-left text-[12px] text-text-subtle hover:text-brand-500 transition-colors disabled:opacity-40",title:C("workspaces.addTerminal"),children:[(0,n.jsx)(el.FW,{size:12,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:C("terminal.newTerminal")})]}):null)]},f)}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),x?x():O(!0)},disabled:!J,className:`w-full flex items-center gap-1.5 ${j?"text-sm":"text-[12px] mt-1"} py-1.5 text-left text-text-subtle hover:text-brand-500 transition-colors disabled:opacity-40`,title:C("workspaces.newWorkspace"),children:[(0,n.jsx)(el.FW,{size:j?18:12,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:C("workspaces.newWorkspace")})]})]}),null!==E&&(0,n.jsx)(sW,{onClose:()=>$(null),onCreate:(e,s,n,r,l,a)=>{t.createSession?.(e,"ungrouped"===E?null:E,s,l,n,r,a),$(null)},shells:W,busRef:Y,hostKey:e.key,onResumeAgentSession:k,onSelectSession:t.selectSession,liveSessionIds:ei,connected:J,workspaceId:"ungrouped"===E?null:E,workspacePath:e.workspaces?.find(e=>e.id===("ungrouped"===E?null:E))?.path||null,workspaceName:"ungrouped"===E?C("workspaces.ungrouped"):e.workspaces?.find(e=>e.id===E)?.name||"",suggestName:`${C("terminal.defaultName")} ${(e.sessions?.length||0)+1}`}),K&&G&&(0,n.jsx)(sD,{fileBus:G.fileBus,scope:G.scope,onSelect:e=>{if(O(!1),!e)return;let s=e.split("/").filter(Boolean).pop()||e;eh(e,G.scope),t.createWorkspace?.(s,e,s=>{let n=s?.workspace||s?.group;s?.success&&n?.id&&t.createSession?.(null,n.id,null,e)})},onClose:()=>O(!1)}),null!==z&&(0,n.jsx)(sN,{title:C("workspaces.rename"),value:z.value,onChange:e=>M({...z,value:e}),onSubmit:()=>{let e=z.value.trim();e&&t.renameWorkspace?.(z.id,e),M(null)},onClose:()=>M(null)}),null!==A&&(0,n.jsx)(ec.A,{isOpen:!0,onClose:()=>I(null),onConfirm:()=>{t.deleteWorkspace?.(A.id),I(null)},title:C("workspaces.deleteTitle"),message:C("workspaces.deleteMessage",{name:A.name}),confirmText:C("common.delete")}),(0,n.jsx)(ec.A,{isOpen:H,onClose:()=>U(!1),onConfirm:()=>{U(!1),P.rh.getState().requestHostUpdate(e.key,"update")},title:C("menu.updateConfirmTitle"),message:C("menu.updateConfirmMessage")}),null!==D&&(0,n.jsx)(sN,{title:C("sessions.editName"),value:D.value,onChange:e=>L({...D,value:e}),onSubmit:()=>{let e=D.value.trim();e&&t.renameSession?.(D.id,e),L(null)},onClose:()=>L(null)}),null!==B&&(0,n.jsx)(ec.A,{isOpen:!0,onClose:()=>F(null),onConfirm:()=>{t.deleteSession?.(B.id),F(null)},title:C("sessions.deleteTitle"),message:C("sessions.deleteMessage",{name:B.name||""}),confirmText:C("common.delete")})]})}function lB({busRef:e,storeKey:t,mobile:s,rowCls:r,activeWs:l,onSelectWorkspace:a}){let i=so(e=>e.workspaceProfiles[t]||"default"),o=so(e=>e.tabsByWorkspace[t]??lD),c=so(e=>e.activeByWorkspace[t]||null),d=(0,h.B)(e=>{let t=e.viewStack;return!!(t&&t[t.length-1]?.type==="browser")}),u=(0,h.B)(e=>e.pushView);return o.length?o.map(o=>{let x=d&&l&&o.id===c,m=sc(o.title)||"Browser";return(0,n.jsxs)("div",{className:`group flex items-center gap-1.5 ${s?"pl-6":"pl-3.5"} pr-2 py-1.5 ml-0.5 rounded-[3px] text-left relative cursor-pointer select-none touch-manipulation touch-pan-y transition-colors ${x?"bg-brand-500/15 text-text":`text-text-muted ${r}`}`,onClick:()=>{var e;return e=o.id,void((0,ed.e)(),!l&&a?.(),so.getState().setActive(t,e),u({type:"browser"}))},title:o.url,children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 bg-white shadow-[0_0_4px_rgba(255,255,255,0.8)]"}),(0,n.jsx)(n5,{name:i,size:14}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${s?"text-base":"text-[11px]"} ${x?"font-medium":""}`,"data-tip":m,children:m}),(0,n.jsx)("button",{onClick:s=>{s.stopPropagation(),(0,ed.e)(),e?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:o.id,profile:so.getState().workspaceProfiles[t]||"default"}},()=>{});let n=so.getState(),r=(n.tabsByWorkspace[t]||[]).filter(e=>e.id!==o.id);n.setTabs(t,r),n.activeByWorkspace[t]===o.id&&n.setActive(t,r[0]?.id||null)},className:`p-0.5 rounded text-text-muted hover:text-text hover:bg-surface-3 shrink-0 ${s?"flex":"opacity-0 group-hover:opacity-100"} transition-opacity`,title:"Close tab",children:(0,n.jsx)(el.X,{size:12})})]},o.id)}):null}let lF=(0,x.gJ)(),lK=(0,r.memo)(function({allSessions:e=[],mainSessions:t=null,workspaces:s=[],activeSessionId:l,activeWorkspaceId:a,sessionStatus:i,notifications:o,onSelectSession:c,onSelectWorkspace:d,onCreateNamedSession:u,onDeleteWorkspace:m,shells:p=[],onRenameSession:f,onDeleteSession:b,onReorderSession:g,onAddWorkspace:v,onRenameWorkspace:y=null,onOpenSettings:w,onOpenRemoteHost:j=null,onOpenMobileHost:k=null,onRenameHost:N=null,onDeleteHost:C=null,onMainDisconnect:S=null,onMainReconnect:T=null,busRef:R=null,fileBus:E,homeDir:$,cwdBySession:z={},connected:M=!0,width:A=eJ.gH.default,onResize:I,onCollapse:D,onResumeAgentSession:L}){let{t:B}=(0,eu.s)(),F=(0,h.B)(e=>e.agentBySession||{}),K=Object.values((0,P.rh)(e=>e.hosts)),O=(0,P.rh)(e=>e.currentKey),W=K.find(e=>e.key===O),[_,H]=(0,r.useState)(!1),U=eS(K,W?.key),q=(0,h.B)(e=>e.fullModes||{});(0,h.B)(e=>e.fullMode);let X=(0,h.B)(e=>e.toggleFullMode),V=(0,h.B)(e=>e.setFullMode),J=(0,h.B)(e=>e.pushView),G=(0,h.B)(e=>e.viewStack),Y=(0,h.B)(e=>e.setViewStack),Z=G[G.length-1]?.type,Q=(0,h.B)(e=>e.hiddenPaneSessionIds||[]),ee=(0,h.B)(e=>e.toggleHidePane),et=(0,h.B)(e=>e.unhidePane),es=eM(),en=i||es,er="mouse"===tO()?th(B("common.close"),"toggleSidebar"):B("common.close"),ea=(0,r.useMemo)(()=>new Set(e.map(e=>e.id)),[e]),ei=(0,r.useMemo)(()=>t||e.filter(e=>!e.hostKey),[t,e]),eo=l?z[l]??e.find(e=>e.id===l)?.cwd??e.find(e=>e.id===l)?.workspacePath??null:null,ex=e$(l),em=eY(e=>e.canInstall),ep=eY(e=>e.isInstalled),ef=eY(e=>e.install),eh=window.matchMedia("(display-mode: standalone)").matches||!!window.ReactNativeWebView,eb=em&&!eh&&!ep&&!(0,x.gJ)(),[eg,ev]=(0,r.useState)(null),ey=(0,r.useRef)(null),ew=s_(ey,eg?.left??0,eg?.top??0),[ek,eN]=(0,r.useState)(null),eT=F[eg?.sessionId]||en[eg?.sessionId]?.tool||e.find(e=>e.id===eg?.sessionId)?.agent,eR=eT?.endsWith("-ui");en[eg?.sessionId]?.conversationId;let eE=np(eT),ez=eE&&nm.has(en[eg?.sessionId]?.state||"idle"),eP=(0,eQ.xs)(e.find(e=>e.id===eg?.sessionId))??eQ.AD,eA=q[eP]??!1,[eI,eD]=(0,r.useState)({sessionId:null,name:"",value:""}),[eL,eB]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!eg)return;let e=e=>{ey.current&&!ey.current.contains(e.target)&&ev(null)},t=e=>{"Escape"===e.key&&ev(null)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",t)}},[eg]);let eF=t=>e.find(e=>e.id===t),eK=e=>{e.preventDefault(),e.stopPropagation();let t=e.currentTarget.dataset.sid,s=eF(t);ev({sessionId:t,left:e.clientX,top:e.clientY,name:s?.name||""})},eO=(0,r.useRef)(null),eW=()=>{eO.current&&(clearTimeout(eO.current),eO.current=null)},e_=e=>{let t,s;t=e.currentTarget.dataset.sid,s=e.touches[0],eO.current=setTimeout(()=>{(0,ed.e)();let e=eF(t);ev({sessionId:t,left:s.clientX,top:s.clientY,name:e?.name||""})},500)};return(0,n.jsxs)("div",{className:"flex-shrink-0 h-full hidden sm:flex flex-col terminal-sidebar-bg border-r border-border-subtle relative",style:{width:A},children:[(0,n.jsxs)("div",{style:{height:32},className:"pl-[18px] pr-1 flex items-center justify-between flex-shrink-0 border-b border-border-subtle relative z-10",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),Y([{type:"list"}])},title:"9Remote",className:"flex items-center gap-2 min-w-0 flex-shrink-0",children:[(0,n.jsx)("img",{src:"/icon-192.png",alt:"9Remote",draggable:!1,className:"w-4 h-4 rounded-[4px] object-contain flex-shrink-0 pointer-events-none select-none"}),(0,n.jsx)("span",{className:"text-[13px] font-semibold text-text truncate",children:"9Remote"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),H(!0)},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",title:B("hosts.addHost"),children:(0,n.jsx)(el.kV,{size:14})}),D&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),D()},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",title:er,children:(0,n.jsx)(el.e6,{size:14})})]})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable pt-1.5 pl-3.5 relative z-10",children:[lF&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),J({type:"pair"})},"aria-label":"Pair Device",className:`-ml-3.5 w-[calc(100%+0.875rem)] flex items-center gap-2 pl-[17px] pr-3 py-1 rounded-[6px] text-left transition-colors duration-150 ${"pair"===Z?"bg-brand-500/10 text-brand-500":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:"Pair Device",children:[(0,n.jsx)(el.vW,{size:15,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs font-medium truncate",children:"Pair Device"})]}),U.map((e,t)=>(0,n.jsx)("div",{className:0===t?"-ml-3.5":"mt-1 -ml-3.5 border-t border-border-subtle pt-1",children:e.key===(W?.key||"main")?(0,n.jsx)(lL,{host:{...W||{},key:W?.key||"main",label:W?.label||"",workspaces:s,sessions:ei,statusMap:en,onDisconnect:S,onConnect:T},busRef:R,actions:{selectSession:e=>{Q.includes(e)&&et(e),c?.(e)},selectWorkspace:e=>{(0,ed.e)(),d?.(e)},createSession:u,renameSession:f,deleteSession:b,reorderSession:g,renameWorkspace:y,deleteWorkspace:m,renameHost:N,deleteHost:C},activeSessionId:l,activeWorkspaceId:a,connected:M,fileBus:E,homeDir:$,cwdBySession:z,agentBySession:F,hiddenPaneSessionIds:Q,onUnhidePane:et,onAddWorkspace:v,menuAddWorkspace:v,onOpenRemoteHost:j,onOpenMobileHost:k,onRowContextMenu:eK,onRowTouch:{start:e_,move:eW,end:eW},onRowMenu:(e,t,s)=>ev({sessionId:e,left:s.left,top:s.bottom+2,name:t}),treeCls:"pl-3.5"}):(0,n.jsx)(lL,{host:{...e,onDisconnect:()=>P.rh.getState().disconnectHost(e.key)},actions:{...tn(e,{onSelectSession:c,onSelectWorkspace:d}),renameHost:N,deleteHost:C},activeSessionId:l,activeWorkspaceId:function(e,t){let s=eC(e,t);if(null!==s)return"_"===s?null:s}(a,e.key),connected:M,hiddenPaneSessionIds:Q,onOpenRemoteHost:j,onOpenMobileHost:k,onUnhidePane:et,treeCls:"pl-3.5"})},e.key))]}),L&&(0,n.jsx)(sk,{busRef:ex.busRef,scope:ex.scope,cwd:eo,onResume:L,onSelectSession:c,liveSessionIds:ea,activeSessionId:l,connected:M}),(eb||w)&&(0,n.jsxs)("div",{className:"p-1.5 border-t border-border-subtle flex-shrink-0 relative z-10",children:[eb&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ef()},className:"w-full flex items-center gap-2 pl-3 pr-2 py-1.5 text-xs text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors",title:B("menu.installApp"),children:[(0,n.jsx)(el.f5,{size:14}),(0,n.jsx)("span",{children:B("menu.installApp")})]}),w&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),w()},className:"w-full flex items-center gap-2 pl-3 pr-2 py-1.5 text-xs text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors",title:B("menu.settings"),children:[(0,n.jsx)(el.wB,{size:14}),(0,n.jsx)("span",{children:B("menu.settings")})]})]}),_&&(0,n.jsx)(nZ,{onClose:()=>H(!1)}),(0,n.jsx)("div",{onPointerDown:e=>{e.stopPropagation(),eV(e,{startWidth:A,onWidth:e=>I?.(e)})},className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"}),eg&&(0,n.jsxs)("div",{ref:ey,className:"fixed z-[70] menu-popover p-1 min-w-[160px] animate-in fade-in zoom-in-95 duration-100",style:{left:ew.left,top:ew.top},children:[en[eg.sessionId]?.state==="done"&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ej.getState().clearNotification(eg.sessionId),ev(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-amber-500 hover:bg-amber-500/10 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.aJ,{size:13})," ",B("sessions.markRead")]}),(0,n.jsxs)("button",{onClick:()=>{var e;let t;return e=eg.sessionId,t=eF(e)?.name||"",void(eD({sessionId:e,name:t,value:t}),ev(null))},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.gH,{size:13})," ",B("sessions.editName")]}),(0,n.jsxs)("div",{className:"relative group/split",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)();let e=eg.sessionId;!eA&&e&&e!==l&&c?.(e),X(eP),ev(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)(el.Wn,{size:13}),(0,n.jsx)("span",{children:B("sessions.split")||"Split"})]}),(0,n.jsx)(el.c_,{size:12,className:"text-text-muted"})]}),(0,n.jsxs)("div",{className:`hidden group-hover/split:block absolute top-0 menu-popover p-1 min-w-[130px] shadow-xl z-20 ${ew.left>window.innerWidth-280?"right-full -mr-0.5":"left-full -ml-0.5"}`,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)();let e=eg.sessionId;!eA&&e&&e!==l&&c?.(e),X(eP),ev(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[eA?(0,n.jsx)(el.xq,{size:12}):(0,n.jsx)(el.h1,{size:12}),(0,n.jsx)("span",{className:"whitespace-nowrap",children:eA?"Restore":"Maximize"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"100%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),eg.sessionId&&eg.sessionId!==l&&c?.(eg.sessionId),eA&&V(eP,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:2}})),ev(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/2"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"50%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),eg.sessionId&&eg.sessionId!==l&&c?.(eg.sessionId),eA&&V(eP,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:3}})),ev(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/3"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"33%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),eg.sessionId&&eg.sessionId!==l&&c?.(eg.sessionId),eA&&V(eP,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:4}})),ev(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/4"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"25%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),eg.sessionId&&eg.sessionId!==l&&c?.(eg.sessionId),eA&&V(eP,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:"auto"}})),ev(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Auto Fit"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"Auto"})]}),(0,n.jsx)("div",{className:"h-px bg-border-subtle my-1"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),ee(eg.sessionId),ev(null)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[Q.includes(eg.sessionId)?(0,n.jsx)(el.kU,{size:12}):(0,n.jsx)(el.X_,{size:12}),(0,n.jsx)("span",{children:Q.includes(eg.sessionId)?B("sessions.showPanel")||"Show":B("sessions.hidePanel")||"Hide"})]})})]})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eN(eg.sessionId),ev(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el._V,{size:13,className:"flex-shrink-0"})," ",B("menu.terminalBackground")]}),(F[eg.sessionId]?.endsWith("-ui")||en[eg.sessionId]?.conversationId)&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)();let e=eg.sessionId,t=e$(e).bus;F[e]?.endsWith("-ui")?t?.emit("ai:restart",{sessionId:e}):t?.emit("session-resume",{sessionId:e}),ev(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.kt,{size:13})," ",F[eg.sessionId]?.endsWith("-ui")?B("sessions.restartAi")||"Restart AI":B("sessions.resumeSession")]}),eE&&(0,n.jsxs)("button",{disabled:!ez,onClick:()=>{(0,ed.e)();let e=eg.sessionId;e$(e).bus?.emit("setSessionMode",{sessionId:e,mode:eR?"terminal":"ui"},e=>{e?.success||alert(e?.error||B("sessions.modeSwitchFailed"))}),ev(null)},className:`w-full text-left px-2.5 py-1.5 text-xs rounded-[6px] flex items-center gap-2 ${ez?"text-text hover:bg-surface-2/80":"text-text-subtle cursor-not-allowed"}`,children:[(0,n.jsx)(el.sU,{size:13})," ",eR?B("sessions.openAsTerminal"):B("sessions.openAsUi")]}),(0,n.jsx)("div",{className:"h-px bg-border-subtle my-1"}),(0,n.jsxs)("button",{onClick:()=>{eB({sessionId:eg.sessionId,name:eg.name}),ev(null)},className:"w-full text-left px-2.5 py-1.5 text-xs text-red-500 hover:bg-red-500/10 rounded-[6px] flex items-center gap-2",children:[(0,n.jsx)(el.TB,{size:13})," ",B("sessions.deleteTitle")]})]}),ek&&(0,n.jsx)(sX,{sessionId:ek,title:eF(ek)?.name,busRef:R,onClose:()=>eN(null)}),eI.sessionId&&(0,n.jsx)(sN,{title:B("sessions.editName"),placeholder:eI.name,value:eI.value,onChange:e=>eD({...eI,value:e}),onSubmit:()=>{let e=eI.value.trim();eI.sessionId&&e&&f?.(eI.sessionId,e),eD({sessionId:null,name:"",value:""})},onClose:()=>eD({sessionId:null,name:"",value:""})}),(0,n.jsx)(ec.A,{isOpen:!!eL,onClose:()=>eB(null),onConfirm:()=>{eL?.sessionId&&b?.(eL.sessionId)},title:B("sessions.deleteTitle"),message:B("sessions.deleteMessage",{name:eL?.name||""}),confirmText:B("common.delete")})]})}),lO={claude:"Claude",codex:"Codex",kimi:"Kimi",grok:"Grok"};function lW(e){return e<60?"bg-text-muted/40":e<80?"bg-yellow-500":"bg-red-500"}function l_(e,{enabled:t=!0}={}){let[s,n]=(0,r.useState)(null);return(0,r.useEffect)(()=>{if(!t||!e)return;let s=!1,r=()=>{e.current&&e.current.emit("quota:get",{},e=>{!s&&e?.success&&e.providers&&n(e)})};r();let l=sg(r,6e4);return()=>{s=!0,l()}},[e,t]),s}let lH=[["session","5h"],["weekly","wk"],["monthly","mo"]];function lU({usedPct:e}){return(0,n.jsx)("span",{className:"w-10 h-[5px] rounded-full bg-text-muted/20 overflow-hidden flex-shrink-0",children:(0,n.jsx)("span",{className:`block h-full rounded-full transition-all duration-300 ${lW(e)}`,style:{width:`${Math.min(100,Math.max(0,e))}%`}})})}function lq({provider:e}){let[t,s]=(0,r.useState)(!1);return t?(0,n.jsx)("span",{className:"text-text-subtle",children:lO[e]||e}):(0,n.jsx)("img",{src:e5(e),alt:"",width:14,height:14,onError:()=>s(!0),className:`w-3.5 h-3.5 object-contain ${e2}`})}function lX({label:e,window:t}){return t?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-16 truncate text-text-muted",children:e}),(0,n.jsxs)("span",{className:"w-9 text-right tabular-nums",children:[Math.round(t.usedPercent),"%"]}),(0,n.jsx)(lU,{usedPct:t.usedPercent}),t.resetsAt&&(0,n.jsx)("span",{className:"text-text-subtle whitespace-nowrap",children:function(e){if(!e)return"";let t=new Date(e),s=t.toDateString()===new Date().toDateString(),n=t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"});return s?n:`${t.toLocaleDateString(void 0,{weekday:"short"})} ${n}`}(t.resetsAt)})]}):null}function lV({p:e,onClose:t}){let s=(0,r.useRef)(null),{t:l}=(0,eu.s)();return(0,r.useEffect)(()=>{let e=e=>{s.current?.contains(e.target)||t()},n=e=>{"Escape"===e.key&&t()};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",n)}},[t]),(0,n.jsxs)("div",{ref:s,className:"absolute bottom-full right-0 mb-2 z-50 w-64 p-3 rounded-brand-lg bg-surface-2 border border-border shadow-lg text-[11px] flex flex-col gap-2",children:[(0,n.jsx)("div",{className:"font-medium",children:lO[e.provider]||e.provider}),lH.map(([t,s])=>(0,n.jsx)(lX,{label:s,window:e[t]},t)),(e.buckets||[]).map(e=>(0,n.jsx)(lX,{label:e.name,window:e},e.name)),!e.session&&!e.weekly&&!e.monthly&&!(e.buckets||[]).length&&(0,n.jsx)("div",{className:"text-text-muted",children:e.error||l("terminal.quotaNoData")}),e.error&&(e.session||e.weekly||e.monthly)&&(0,n.jsx)("div",{className:"text-text-subtle border-t border-border-subtle pt-1.5",children:e.error})]})}function lJ({quota:e}){let[t,s]=(0,r.useState)(null),{t:l}=(0,eu.s)();if(!e?.providers)return null;let a=Object.values(e.providers).filter(e=>e&&"ok"===e.status&&(e.session||e.weekly||e.monthly||e.buckets?.length));return a.length?(0,n.jsx)("span",{className:"relative flex items-center gap-1 flex-shrink-0",children:a.map(e=>{let r=e.session||e.weekly||e.monthly||e.buckets[0];return(0,n.jsxs)("span",{className:"relative",children:[(0,n.jsxs)("button",{type:"button",className:"flex items-center gap-1.5 px-1.5 py-0.5 rounded-[2px] hover:bg-white/10 transition-colors",onClick:()=>s(t===e.provider?null:e.provider),title:`${lO[e.provider]||e.provider} ${l("terminal.quotaUsageTitle")}`,children:[(0,n.jsx)(lq,{provider:e.provider}),(0,n.jsx)(lU,{usedPct:r.usedPercent}),(0,n.jsxs)("span",{className:"tabular-nums",children:[Math.round(r.usedPercent),"%"]})]}),t===e.provider&&(0,n.jsx)(lV,{p:e,onClose:()=>s(null)})]},e.provider)})}):null}function lG({left:e,right:t,className:s="flex"}){return(0,n.jsxs)("div",{style:{height:26},className:`items-center gap-3 px-3 flex-shrink-0 bg-surface border-t border-border-subtle text-[11px] text-text-muted select-none ${s}`,children:[(0,n.jsx)("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:e}),(0,n.jsx)("div",{className:"flex items-center gap-3 flex-shrink-0",children:t})]})}let lY="flex items-center gap-1.5 px-1.5 py-0.5 rounded-[2px] hover:bg-white/10 transition-colors cursor-pointer",lZ="flex items-center gap-1.5 px-1.5 py-0.5",lQ={darwin:"mac",win32:"win",linux:"linux"};function l0({pages:e,activeKey:t}){return(0,n.jsx)("span",{className:"grid justify-items-end",children:e.map(({key:e,node:s})=>(0,n.jsx)("span",{"aria-hidden":e!==t,className:"[grid-area:1/1] flex items-center min-w-0 motion-reduce:transition-none",style:{opacity:+(e===t),transform:e===t?"translateY(0)":"translateY(2px)",pointerEvents:e===t?"auto":"none",transition:`opacity ${eJ.ZU}ms ease, transform ${eJ.ZU}ms ease`},children:s},e))})}let l1=(0,r.memo)(function({sessionId:e,fileBus:t,busRef:s,onReveal:l}){let a,i,o,c=(0,h.B)(t=>t.cwdBySession[e])||"",{branch:d,changedCount:u}=n8(c,t,{enabled:!!c}),x=(i=l_(s,{enabled:!!(a=(0,h.B)(t=>t.agentBySession[e])||"")}),(o=a?i?.providers?.[a]:null)&&"ok"===o.status&&o.session?{agentId:a,usedPct:o.session.usedPercent}:null),[m,p]=(0,r.useState)(!1),f=c?c.replace(/\\+|\/+$/g,"").split(/[\\/]/).filter(Boolean):[],b=f.length?f.slice(-2).join("/"):"";(0,r.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>p(!1),eJ.wu);return()=>clearTimeout(e)},[m]);let g=[];b&&g.push({key:"path",node:(0,n.jsxs)("button",{type:"button",onClick:l?()=>l(c):void 0,title:c,className:`flex items-center gap-1 min-w-0 font-mono ${l?"hover:text-text":""}`,children:[(0,n.jsx)(el.vd,{size:10,className:"opacity-70 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:b})]})}),x&&g.push({key:"quota",node:(0,n.jsxs)("button",{type:"button",onClick:()=>p(!0),className:"flex items-center gap-1.5 flex-shrink-0",children:[(0,n.jsx)("img",{src:e5(x.agentId),alt:"",width:11,height:11,draggable:!1,className:`w-[11px] h-[11px] object-contain ${e2}`}),(0,n.jsx)("span",{className:"w-8 h-[4px] rounded-full bg-text-muted/20 overflow-hidden",children:(0,n.jsx)("span",{className:`block h-full rounded-full transition-all duration-300 ${lW(x.usedPct)}`,style:{width:`${Math.min(100,Math.max(0,x.usedPct))}%`}})}),(0,n.jsxs)("span",{className:"tabular-nums text-text-muted",children:[Math.round(x.usedPct),"%"]})]})});let v=x&&x.usedPct>=eJ.W$?g.findIndex(e=>"quota"===e.key):-1,[y]=function(e,{pinnedIndex:t=-1,paused:s=!1}={}){let[n,l]=(0,r.useState)(0);return((0,r.useEffect)(()=>{if(!(e<2)&&!s&&!(t>=0))return sg(()=>l(e=>e+1),eJ.wu,{fireOnReturn:!1})},[e,s,t]),e)?[t>=0?t:n%e,l]:[0,l]}(g.length,{pinnedIndex:v,paused:m});return(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 h-6 border-t border-border-subtle text-[10px] text-text-subtle bg-bg flex-shrink-0",children:[d&&(0,n.jsxs)("span",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)(el.Zr,{size:10,className:"opacity-70"}),(0,n.jsx)("span",{className:"max-w-[90px] truncate text-text-muted",title:d,children:d}),u>0&&(0,n.jsx)("span",{className:"px-1 leading-tight bg-brand-500/15 text-brand-400 rounded-[2px] font-medium",children:u>eJ.KN?`${eJ.KN}+`:u})]}),g.length>0&&(0,n.jsx)(l0,{pages:g,activeKey:g[y]?.key})]})}),l2=(0,r.memo)(function({cwd:e,sessionId:t,hostKey:s=null,sessionState:r,sessionName:l="",hostVersion:a="",agentVersion:i="",platform:o="",homeDir:c=null}){let{t:d}=(0,eu.s)(),x=function(e){let t=e&&e===P.rh.getState().currentKey?null:e,s=(0,u.d)(e=>t?null:e.connected),n=(0,u.d)(e=>t?"ws":e.carrier),r=(0,P.rh)(e=>e.hosts[t||e.currentKey]);if(!t)return{head:null,connected:!!s,status:s?"full":"offline",carrier:n||"ws",platform:r?.platform||null,version:r?.version||null};let l=r?.status||"offline";return{head:t,connected:"online"===l,status:l,carrier:r?.carrier||"ws",platform:r?.platform||null,version:r?.version||null}}(s),m=eE(s).busRef,p=eE(s).fileBus,f=(0,u.d)(e=>s?null:e.connectionMode),b=(0,u.d)(e=>s?"":e.endpoint),g=ez(t),v=x.connected,y=x.carrier,w=r||g||"idle",j=l_(m),k=(0,h.B)(e=>(e.agentBySession||{})[t])||"",N=l||"—",C=k?e5(k):null,{branch:S,changedCount:T}=n8(e,p,{enabled:!!e}),R=se(w),E=d("working"===w?"common.statusWorking":"blocked"===w?"common.statusBlocked":"done"===w?"common.statusDone":"sleep"===w?"common.statusSleep":"common.statusIdle"),$=e?sx(e.replace(/\\/g,"/"),c):"",z=T>eJ.KN?`${eJ.KN}+`:T;return(0,n.jsx)(lG,{className:"hidden sm:flex",left:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 max-w-[200px]",children:[C?(0,n.jsx)("img",{src:C,alt:"",draggable:!1,className:`w-3.5 h-3.5 object-contain flex-shrink-0 ${e2}`}):(0,n.jsx)(sh,{size:14}),(0,n.jsx)("span",{className:"truncate font-medium text-text",title:N,children:N})]}),(0,n.jsx)("span",{className:"text-text-subtle flex-shrink-0",children:"›"}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0 flex-shrink",children:[(0,n.jsx)(el.vd,{size:12,className:"opacity-60 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",title:e||"",children:$||d("common.loading")})]}),e&&S&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0",children:[(0,n.jsx)(el.Zr,{size:12,className:"opacity-60 text-brand-500"}),(0,n.jsx)("span",{className:"truncate max-w-[160px]",title:S,children:S}),T>0&&(0,n.jsx)("span",{className:"px-1 leading-tight bg-brand-500/15 text-brand-400 rounded-[2px] font-medium",children:z})]})]}),right:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(lJ,{quota:j}),(x.platform||o)&&(0,n.jsx)("span",{className:"uppercase tracking-wide",children:lQ[x.platform||o]||x.platform||o}),(x.version||a||i)&&(0,n.jsxs)("span",{className:"text-text-subtle",children:["v",x.version||a||i]}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5",title:`${b||""}${y&&"ws"!==y?` (${y})`:""}`,children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full ${v?"local"===f?"bg-emerald-400":"bg-green-500":"bg-red-500 animate-pulse"}`}),(0,n.jsx)("span",{className:"uppercase tracking-wide",children:y&&"ws"!==y?"STUN":`WS${"local"===f?" \xb7 LOCAL":""}`})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full term-dot ${R.cls}${R.pulse?` pulse-${R.pulse}`:""}`,style:{background:R.dot}}),(0,n.jsx)("span",{children:E})]})]})})}),l5=(e,t,s)=>Math.max(t,Math.min(s,e));function l3(e){let t=window.innerWidth-4*eJ.qj.margin,s=window.innerHeight-3*eJ.qj.margin;return{...e,x:l5(e.x,eJ.qj.margin-e.w+4*eJ.qj.margin,t),y:l5(e.y,eJ.qj.margin,s)}}function l4(e){let t=!1,s=null,n=e.length,r=0;for(;r+2<n;){if(0===e[r]&&0===e[r+1]){let l=0;if(1===e[r+2]?l=3:r+3<n&&0===e[r+2]&&1===e[r+3]&&(l=4),l){let n=31&e[r+l];7!==n||s||(s=e.subarray(r+l)),5===n&&(t=!0),r+=l+1;continue}}r++}return{isKey:t,spsBytes:s}}let l6="VideoDecoder"in window&&"EncodedVideoChunk"in window,l8=/^(\d\d-\d\d \d\d:\d\d:\d\d\.\d+)\s+\d+\s+\d+\s+([VDIWEF])\s+([^:]*):\s?(.*)$/;function l9({state:e}){return(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${"running"===e?"bg-green-500 animate-pulse":"starting"===e||"stopping"===e?"bg-amber-400 animate-pulse":"bg-text-muted/40"}`})}function l7({devices:e,canManage:t,booting:s,stopping:l,loading:a,error:i,onOpen:o,onStop:c,onRefresh:d,lowPower:u,onLowPowerChange:x,onAddDevice:m,onDeleteAvd:p,onWipeAvd:f,sdkJob:h,onShowSetup:b}){let{t:g}=(0,eu.s)(),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(null);return(0,n.jsxs)("div",{className:"w-full max-w-sm mx-auto p-4 space-y-3 fade-in",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-text text-sm font-medium flex-1",children:g("mobile.pickDevice")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m?.()},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]",title:g("mobile.addDevice"),"aria-label":g("mobile.addDevice"),children:(0,n.jsx)(el.FW,{size:15})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d?.()},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]",title:g("mobile.refreshDevices"),"aria-label":g("mobile.refreshDevices"),children:(0,n.jsx)(el.e9,{size:15})})]}),h&&"done"!==h.phase&&"error"!==h.phase&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),b?.()},className:"w-full flex items-center gap-2.5 bg-surface rounded-brand-lg px-3 py-2.5 hover:bg-surface-2 transition-colors text-left",children:[(0,n.jsx)(el.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-xs text-text truncate",children:g(function(e){if(e?.step)return`mobile.provisionStep_${e.step}`;let t=e?.component||"";return t.startsWith("system-images;")?"mobile.provisionStep_image":`mobile.provisionStep_${t}`}(h))}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"image"===h.kind||"image"===h.step?`${h.percent??0}%`:`${Math.round((h.received||0)/1024/1024)} MB${h.bytesPerSec?` \xb7 ${Math.round(h.bytesPerSec/1024/1024)} MB/s`:""}`})]})]}),0===e.length&&(0,n.jsx)("div",{className:"text-center py-8 space-y-2 fade-in",children:a?(0,n.jsx)(el.kr,{size:20,className:"text-brand-500 animate-spin mx-auto"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el.wO,{size:26,className:"text-text-muted mx-auto"}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:g("mobile.noDevicesHint")})]})}),(0,n.jsx)("div",{className:"space-y-1.5",children:e.map((e,r)=>{let a=s?.avdName&&s.avdName===e.avdName,i=l?.has(e.serial),d="running"===e.state;return(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden list-rise",style:{"--i":Math.min(r,8)},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),o?.(e)},disabled:a||i,className:"flex items-center gap-2.5 flex-1 min-w-0 text-left disabled:opacity-60 transition-all duration-150 ease-out active:scale-[0.99]",children:["physical"===e.kind?(0,n.jsx)(el.wO,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}):(0,n.jsx)(el.VA,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text truncate",children:e.name}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:a?g(`mobile.phase${s.phase.charAt(0).toUpperCase()}${s.phase.slice(1)}`):i?g("mobile.stoppingDevice"):e.serial||g("mobile.stopped")})]}),(0,n.jsx)(l9,{state:a||i?"starting":e.state})]}),a?(0,n.jsx)(el.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}):d&&e.canStop?i?(0,n.jsx)(el.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),c?.(e)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0",title:g("mobile.stopDevice"),"aria-label":g("mobile.stopDevice"),children:(0,n.jsx)(el.M6,{size:14})}):d?null:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),o?.(e)},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0",title:g("mobile.startDevice"),"aria-label":g("mobile.startDevice"),children:(0,n.jsx)(el.jG,{size:14})}),t&&"emulator"===e.kind&&e.avdName&&!d&&!a&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),y(v===e.id?null:e.id)},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0","aria-label":g("mobile.avdMenu"),children:(0,n.jsx)(el.Gv,{size:14})})]}),v===e.id&&(0,n.jsxs)("div",{className:"flex items-center gap-1 px-3 py-1.5 border-t border-border bg-surface-2/50",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),j({kind:"wipe",avdName:e.avdName,name:e.name}),y(null)},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",children:[(0,n.jsx)(el.kt,{size:12})," ",g("mobile.avdWipe")]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),j({kind:"delete",avdName:e.avdName,name:e.name}),y(null)},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-colors",children:[(0,n.jsx)(el.TB,{size:12})," ",g("mobile.avdDelete")]})]})]},e.id)})}),t&&e.some(e=>"running"!==e.state)&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),x?.(!u)},className:"w-full bg-surface rounded-brand-lg px-3 py-2 flex items-center gap-2.5 text-left hover:bg-surface-2 transition-colors",children:[(0,n.jsx)(el.Kq,{size:15,className:u?"text-brand-500 dark:text-white flex-shrink-0":"text-text-muted flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text",children:g("mobile.lowPower")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:g("mobile.lowPowerHint")})]}),(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors border border-transparent flex-shrink-0 ${u?"bg-brand-500 dark:bg-white":"bg-surface-2 dark:border-white/15"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${u?"translate-x-4 dark:bg-dark-800":"translate-x-0.5 dark:bg-white/50"}`})})]}),i&&(0,n.jsx)("p",{className:"text-red-400 text-xs text-center",children:i}),(0,n.jsx)(ec.A,{isOpen:!!w,onClose:()=>j(null),onConfirm:()=>{w&&("delete"===w.kind?p?.(w.avdName):f?.(w.avdName),j(null))},title:g(w?.kind==="delete"?"mobile.avdDeleteTitle":"mobile.avdWipeTitle"),message:g(w?.kind==="delete"?"mobile.avdDeleteMessage":"mobile.avdWipeMessage",{name:w?.name||""}),confirmText:g(w?.kind==="delete"?"common.delete":"mobile.avdWipe")})]})}function ae(e){if(!Number.isFinite(e)||e<=0)return"";let t=["B","KB","MB","GB"],s=0,n=e;for(;n>=1024&&s<t.length-1;)n/=1024,s++;return`${n>=10?Math.round(n):n.toFixed(1)} ${t[s]}`}function at({isOpen:e,onClose:t,presets:s,sdkJob:l,onProvision:a,onCancel:i}){let{t:o}=(0,eu.s)(),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(null),m=l&&"done"!==l.phase&&"error"!==l.phase?l:null,p=l?.phase==="error"&&"cancelled"!==l.error?l.error:null,f=(0,r.useCallback)(()=>{d(null),x(null),t?.()},[t]);if((0,r.useEffect)(()=>{if(!e||m)return;let t=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),f())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e,m,f]),!e||"u"<typeof document)return null;let h=async e=>{if(c||m)return;(0,ed.e)(),d(e.id),x(e);let t=await a?.(e.id);d(null),t&&f()};return(0,sd.createPortal)((0,n.jsx)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px] fade-in",onClick:f,children:(0,n.jsxs)("div",{className:"card-elev w-full max-w-sm max-h-[80vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)(el.wO,{size:15,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text flex-1",children:o("mobile.addDevice")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f()},className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand",children:(0,n.jsx)(el.X,{size:15})})]}),(0,n.jsx)("div",{className:"p-3 space-y-1.5 overflow-y-auto modal-scrollable",children:m||p?(0,n.jsx)("div",{className:"flex flex-col items-center gap-3 py-8 px-4 text-center",children:p?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-red-400 text-xs",children:p}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[u&&(0,n.jsx)("button",{onClick:()=>h(u),className:"px-3 py-1.5 text-xs text-brand-500 bg-brand-500/10 dark:text-white dark:bg-white/10 rounded-brand",children:o("common.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f()},className:"px-3 py-1.5 text-xs text-text-muted hover:text-text rounded-brand",children:o("common.close")})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el.kr,{size:20,className:"text-brand-500 animate-spin"}),(0,n.jsx)("p",{className:"text-text text-sm",children:o(function(e){if(e?.step)return`mobile.provisionStep_${e.step}`;let t=e?.component||"";return t.startsWith("system-images;")?"mobile.provisionStep_image":`mobile.provisionStep_${t}`}(m))}),(0,n.jsx)("p",{className:"text-text-muted text-xs",children:"image"===m.kind||"image"===m.step?`${m.percent??0}%`:`${ae(m.received)}${m.total?` / ${ae(m.total)}`:""}${m.bytesPerSec?` \xb7 ${ae(m.bytesPerSec)}/s`:""}`}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),i?.()},className:"px-3 py-1 text-[11px] text-text-muted hover:text-red-400 rounded-brand transition-colors",children:o("common.cancel")})]})}):(s||[]).map(e=>(0,n.jsxs)("button",{onClick:()=>h(e),className:"w-full flex items-center gap-2.5 px-3 py-2.5 bg-surface rounded-brand-lg hover:bg-surface-2 transition-colors text-left",children:["tablet"===e.id?(0,n.jsx)(el.VA,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}):(0,n.jsx)(el.wO,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm text-text truncate",children:e.label}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:e.ready?o("mobile.presetReady"):o("mobile.presetDownload")})]}),e.ready?(0,n.jsx)(el.aJ,{size:13,className:"text-green-500 flex-shrink-0"}):(0,n.jsx)(el.f5,{size:13,className:"text-text-muted flex-shrink-0"})]},e.id))})]})}),document.body)}function as({apps:e,foreground:t,busy:s,progress:l,error:a,onInstall:i,onLaunch:o,onStopApp:c,onClearData:d,onUninstall:u,onOpenLink:x,onRefresh:m}){let{t:p}=(0,eu.s)(),f=(0,r.useRef)(null),[h,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(""),y=(0,r.useCallback)(e=>{let t=[...e||[]].find(e=>e.name.toLowerCase().endsWith(".apk"));t&&i?.(t)},[i]),w=(0,r.useCallback)(e=>{e.preventDefault(),b(!1),y(e.dataTransfer?.files)},[y]),j="install"===s;return(0,n.jsxs)("div",{className:"h-full overflow-y-auto modal-scrollable p-3 space-y-3",onDragOver:e=>{e.preventDefault(),b(!0)},onDragLeave:()=>b(!1),onDrop:w,children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f.current?.click()},disabled:j,className:`w-full rounded-brand-lg border border-dashed px-3 py-5 flex flex-col items-center gap-1.5 transition-colors duration-150 ${h?"border-brand-500 bg-brand-500/5":"border-border hover:border-brand-500/50"} disabled:opacity-60`,children:j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el.kr,{size:20,className:"text-brand-500 animate-spin"}),(0,n.jsx)("span",{className:"text-sm text-text",children:p("mobile.installing")}),l>0&&(0,n.jsx)("div",{className:"w-full max-w-[180px] h-1 bg-surface-2 rounded-full overflow-hidden mt-1",children:(0,n.jsx)("div",{className:"h-full bg-brand-500 transition-[width] duration-150",style:{width:`${Math.round(100*l)}%`}})})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el._O,{size:20,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-sm text-text",children:p("mobile.dropApk")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:p("mobile.dropApkHint")})]})}),(0,n.jsx)("input",{ref:f,type:"file",accept:".apk,application/vnd.android.package-archive",className:"hidden",onChange:e=>{y(e.target.files),e.target.value=""}}),(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault(),g.trim()&&(x?.(g.trim()),v(""))},className:"flex items-center gap-1.5",children:[(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 bg-surface rounded-brand px-2.5 py-1.5",children:[(0,n.jsx)(el.vv,{size:14,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("input",{value:g,onChange:e=>v(e.target.value),placeholder:p("mobile.deepLinkPlaceholder"),className:"flex-1 bg-transparent text-sm text-text placeholder:text-text-muted focus:outline-none min-w-0",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1})]}),(0,n.jsx)("button",{type:"submit",disabled:!g.trim(),className:"px-2.5 py-1.5 text-sm text-text bg-surface hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.97] disabled:opacity-40",children:p("common.open")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted flex-1",children:p("mobile.installedApps")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m?.()},className:"p-1 text-text-muted hover:text-text rounded-brand transition-colors",title:p("common.refresh"),"aria-label":p("common.refresh"),children:(0,n.jsx)(el.e9,{size:13})})]}),0===e.length&&(0,n.jsx)("p",{className:"text-text-muted text-xs text-center py-4",children:p("mobile.noApps")}),(0,n.jsx)("div",{className:"space-y-1",children:e.map(e=>{let r=t?.packageName===e.packageName,l=s===e.packageName;return(0,n.jsxs)("div",{className:"bg-surface rounded-brand px-2.5 py-2 flex items-center gap-2",children:[(0,n.jsx)(el.lP,{size:14,className:r?"text-brand-500 flex-shrink-0":"text-text-muted flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text truncate flex-1",title:e.packageName,children:e.packageName}),l?(0,n.jsx)(el.kr,{size:14,className:"text-brand-500 animate-spin flex-shrink-0"}):(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[e.launchable&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),o?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-colors",title:p("mobile.launch"),"aria-label":p("mobile.launch"),children:(0,n.jsx)(el.jG,{size:13})}),r&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),c?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-amber-400 hover:bg-surface-2 rounded-brand transition-colors",title:p("mobile.forceStop"),"aria-label":p("mobile.forceStop"),children:(0,n.jsx)(el.M6,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-amber-400 hover:bg-surface-2 rounded-brand transition-colors",title:p("mobile.clearData"),"aria-label":p("mobile.clearData"),children:(0,n.jsx)(el.e9,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-colors",title:p("mobile.uninstall"),"aria-label":p("mobile.uninstall"),children:(0,n.jsx)(el.TB,{size:13})})]})]},e.packageName)})}),a&&(0,n.jsx)("p",{className:"text-red-400 text-xs",children:a})]})}function an({logcat:e,apps:t}){let{lines:s,clear:l,minLevel:a,setMinLevel:i,search:o,setSearch:c,packageName:d,setPackageName:u,paused:x,setPaused:m,includeNoise:p,setIncludeNoise:f}=e,{t:h}=(0,eu.s)(),b=(0,r.useRef)(null),[g,v]=(0,r.useState)(!0),y=()=>{v(!0)};return(0,r.useLayoutEffect)(()=>{g&&b.current&&(b.current.scrollTop=b.current.scrollHeight)},[s,g]),(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border flex-shrink-0 flex-wrap",children:[(0,n.jsxs)("select",{value:d||"",onChange:e=>{(0,ed.e)(),u(e.target.value||null),y()},className:"bg-surface-2 text-text text-xs rounded-brand px-1.5 py-1 focus:outline-none max-w-[40%]",title:h("mobile.filterByApp"),children:[(0,n.jsx)("option",{value:"",children:h("mobile.allApps")}),t.map(e=>(0,n.jsx)("option",{value:e.packageName,children:e.packageName},e.packageName))]}),(0,n.jsx)("select",{value:a,onChange:e=>{(0,ed.e)(),i(e.target.value),y()},className:"bg-surface-2 text-text text-xs rounded-brand px-1.5 py-1 focus:outline-none",title:h("mobile.minLevel"),children:U.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}),(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-surface-2 rounded-brand px-1.5 py-1 flex-1 min-w-[90px]",children:[(0,n.jsx)(el.vj,{size:12,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("input",{value:o,onChange:e=>c(e.target.value),placeholder:h("common.search"),className:"bg-transparent text-xs text-text placeholder:text-text-muted focus:outline-none w-full min-w-0",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1})]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m(!x)},className:`p-1.5 rounded-brand transition-colors ${x?"text-brand-500 bg-surface-2":"text-text-muted hover:text-text"}`,title:h(x?"mobile.resumeLog":"mobile.pauseLog"),"aria-label":h(x?"mobile.resumeLog":"mobile.pauseLog"),children:x?(0,n.jsx)(el.jG,{size:13}):(0,n.jsx)(el.vR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f(!p),y()},className:`p-1.5 rounded-brand transition-colors ${p?"text-amber-400 bg-surface-2":"text-text-muted hover:text-text"}`,title:h(p?"mobile.hideNoise":"mobile.showNoise"),"aria-label":h(p?"mobile.hideNoise":"mobile.showNoise"),children:(0,n.jsx)(el.dJ,{size:13})}),(0,n.jsx)("button",{onClick:()=>{let e;(0,ed.e)(),e=s.map(e=>`${e.time} ${e.level} ${e.tag}: ${e.message}`).join("\n"),navigator.clipboard?.writeText(e)},className:"p-1.5 text-text-muted hover:text-text rounded-brand transition-colors",title:h("common.clipboardCopy"),"aria-label":h("common.clipboardCopy"),children:(0,n.jsx)(el.QR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),l()},className:"p-1.5 text-text-muted hover:text-red-400 rounded-brand transition-colors",title:h("mobile.clearLog"),"aria-label":h("mobile.clearLog"),children:(0,n.jsx)(el.TB,{size:13})})]}),(0,n.jsxs)("div",{ref:b,onScroll:()=>{let e=b.current;e&&v(e.scrollHeight-e.scrollTop-e.clientHeight<40)},className:"flex-1 overflow-auto modal-scrollable font-mono text-[11px] leading-[1.45] p-2",children:[0===s.length&&(0,n.jsx)("p",{className:"text-text-muted text-xs text-center py-6 font-sans",children:h("mobile.noLogs")}),s.map(e=>(0,n.jsxs)("div",{className:"whitespace-pre-wrap break-all",children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:e.time})," ",(0,n.jsx)("span",{className:q[e.level]||"text-text",children:e.level})," ",(0,n.jsx)("span",{className:"text-brand-500/70",children:e.tag}),e.tag?": ":"",(0,n.jsx)("span",{className:q[e.level]||"text-text",children:e.message})]},e.seq))]}),x&&(0,n.jsx)("div",{className:"px-2 py-1 text-[11px] text-amber-400 bg-amber-400/10 flex-shrink-0 text-center",children:h("mobile.logPaused")})]})}function ar({onClose:e,busRef:t,protocolRef:s,connected:l,variant:a="fullscreen"}){let{t:i}=(0,eu.s)(),o=(0,r.useRef)(null),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),f=function({busRef:e,connected:t}){let[s,n]=(0,r.useState)([]),[l,a]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(()=>new Set),[u,x]=(0,r.useState)(null),[m,p]=(0,r.useState)(!1),[f,b]=(0,r.useState)(null),g=(0,h.B)(e=>e.mobileLowPower),v=(0,h.B)(e=>e.setMobileLowPower),y=(0,r.useCallback)(async()=>{let s=e?.current;if(!s||!t)return[];let r=await X(s,"mobile:list",{});if(!r?.success)return[];p(!0),a(!!r.canManageEmulators),r.env&&b(r.env.job||null);let l=Array.isArray(r.devices)?r.devices:[];return n(l),d(e=>{let t=new Set(l.map(e=>e.serial).filter(Boolean));for(let s of e)if(t.has(s))return e;let s=new Set([...e].filter(e=>t.has(e)));return s.size===e.size?e:s}),l},[e,t]);(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t)return;let n=({avdName:e,phase:t})=>o({avdName:e,phase:t});s.on("mobile:avdProgress",n);let r=e=>{b(e),("done"===e.phase||"error"===e.phase)&&y()};return s.on("mobile:sdkProgress",r),()=>{s.off("mobile:avdProgress",n),s.off("mobile:sdkProgress",r)}},[e,t,y]),(0,r.useEffect)(()=>{if(!t)return;y();let e=setInterval(y,5e3);return()=>clearInterval(e)},[t,y]);let w=(0,r.useCallback)(async t=>{x(null),o({avdName:t,phase:"launching"});let s=await X(e?.current,"mobile:avdStart",{avdName:t,lowPower:g});return(o(null),await y(),s?.success)?s.serial:(x(s?.error||"Could not start"),null)},[e,y,g]),j=(0,r.useCallback)(async t=>{if(!t)return!1;x(null),d(e=>new Set(e).add(t));let s=await X(e?.current,"mobile:avdStop",{serial:t});return await y(),d(e=>{let s=new Set(e);return s.delete(t),s}),s?.success||x(s?.error||"Could not stop"),s?.success},[e,y]),[k,N]=(0,r.useState)([]),C=(0,r.useCallback)(async()=>{let t=await X(e?.current,"mobile:provisionPresets",{});t?.success&&N(Array.isArray(t.presets)?t.presets:[])},[e]),S=(0,r.useCallback)(async t=>{x(null);let s=await X(e?.current,"mobile:provision",{presetId:t});return await Promise.all([y(),C()]),!!s?.success||(x(s?.error||"Could not create device"),!1)},[e,y,C]),T=(0,r.useCallback)(async()=>{await X(e?.current,"mobile:sdkCancel",{}),await y()},[e,y]),R=(0,r.useCallback)(async t=>{let s=await X(e?.current,"mobile:avdDelete",{avdName:t});return s?.success||x(s?.error||"Could not delete"),await y(),s?.success},[e,y]),E=(0,r.useCallback)(async t=>{let s=await X(e?.current,"mobile:avdWipe",{avdName:t});return s?.success||x(s?.error||"Could not wipe"),await y(),s?.success},[e,y]);return{devices:s,canManage:l,booting:i,error:u,setError:x,refresh:y,startAvd:w,stopAvd:j,stopping:c,lowPower:g,setLowPower:v,sdkJob:f,presets:k,refreshPresets:C,provision:S,cancelSetup:T,deleteAvd:R,wipeAvd:E,loaded:m}}({busRef:t,connected:l}),{devices:b,canManage:g,booting:v,refresh:y,startAvd:w,stopAvd:j,stopping:k,lowPower:N,setLowPower:C,sdkJob:S,presets:T,refreshPresets:R,provision:E,cancelSetup:$,deleteAvd:z,wipeAvd:M}=f,{serial:P,meta:A,starting:I,error:D,open:L,stop:B,cancel:F}=function({busRef:e,connected:t,devices:s,startAvd:n,stopAvd:l,stopping:a}){let i=(0,h.B)(e=>e.mobileSession),o=(0,h.B)(e=>e.setMobileSession),c=i?.serial??null,d=i?.meta??null,[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(null),f=(0,r.useRef)(!1),b=(0,r.useRef)(!1),g=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{d&&(f.current=!0)},[d]);let v=(0,r.useCallback)(()=>{e?.current?.emit("mobile:stop"),f.current=!1,o(null)},[e,o]),y=(0,r.useCallback)(()=>{b.current=!0,v()},[v]),w=(0,r.useCallback)(async t=>{let s=Math.max(window.innerWidth,window.innerHeight),n=window.devicePixelRatio,r=await X(e?.current,"mobile:start",{serial:t,options:function(e,t,s=1){let n=_[e]||_[H],r=function(e,t=1,s=1){let n=Math.min(1600,Math.max(640,Math.round(e*Math.min(t||1,3)*s)));return n-n%8}(t,s,n.edgeScale),l=r*Math.round(.45*r);return{maxSize:r,bitRate:Math.min(n.maxBitRate,Math.round(l*n.maxFps*n.bitsPerPixel)),maxFps:n.maxFps}}(H,s,n)});if(!r?.success)throw Error(r?.error||"Failed to start");return f.current=!0,o({serial:t,meta:r.meta}),r.meta},[e,o]),j=(0,r.useCallback)(async e=>{if(e){b.current=!1,x(!0),p(null),g.current.add(e.id);try{let t=e.serial||(e.avdName?await n(e.avdName):null);if(b.current){t&&l?.(t);return}if(!t)throw Error("Device did not start");await w(t),b.current&&(v(),t&&l?.(t))}catch(e){b.current||p(e.message)}finally{x(!1)}}},[n,w,l,v]);return(0,r.useEffect)(()=>{if(d||u||c)return;let e=s.filter(e=>"running"===e.state);if(1!==e.length||1!==s.length)return;let t=e[0];if(g.current.has(t.id)||a?.has(t.serial))return;let n=setTimeout(()=>j(t),0);return()=>clearTimeout(n)},[s,d,u,c,j,a]),(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t)return;let n=({meta:e})=>{e&&o(t=>t?{...t,meta:e}:t)};return s.on("mobile:resized",n),()=>s.off("mobile:resized",n)},[e,t,o]),(0,r.useEffect)(()=>{!t&&f.current&&(f.current=!1,o(null))},[t,o]),{serial:c,meta:d,starting:u,error:m,setError:p,open:j,stop:v,cancel:y}}({busRef:t,connected:l,devices:b,startAvd:w,stopAvd:j,stopping:k}),{status:K,fps:O}=function({busRef:e,connected:t,canvasRef:s,meta:n}){let[l,a]=(0,r.useState)("idle"),[i,o]=(0,r.useState)(0),c=(0,r.useRef)(null),d=(0,r.useCallback)(()=>{let t=c.current,s=performance.now();t&&s-t.lastKeyframeReq<1e3||(t&&(t.lastKeyframeReq=s),e?.current?.emit("mobile:keyframe"))},[e]);return(0,r.useEffect)(()=>{let r=e?.current;if(!r||!t||!n||!l6)return;let l={decoder:null,pending:new Map,queue:[],raf:0,sawKey:!1,dropping:!1,lastKeyframeReq:0,ackedSeq:-1,config:null,frameCount:0,fpsAt:performance.now()};c.current=l,a("connecting");let i=()=>{if(l.decoder&&"closed"!==l.decoder.state)try{l.decoder.close()}catch{}for(let e of(l.decoder=null,l.sawKey=!1,l.queue))e.close();l.queue=[]},u=()=>{l.raf=0;let e=s.current;for(;l.queue.length>1;)l.queue.shift()?.close();let t=l.queue.shift();if(!t)return;let n=e?.getContext("2d",{alpha:!1,desynchronized:!0});n&&n.drawImage(t,0,0,e.width,e.height),t.close(),l.frameCount++;let r=performance.now();r-l.fpsAt>=1e3&&(o(Math.round(1e3*l.frameCount/(r-l.fpsAt))),l.frameCount=0,l.fpsAt=r),l.queue.length&&(l.raf=requestAnimationFrame(u))},x=()=>{i(),l.dropping=!0,d()},m=e=>{if(l.decoder?.state==="configured")return!0;i();let t=new VideoDecoder({output:e=>{l.decoder!==t?e.close():(l.queue.length>=3&&l.queue.shift()?.close(),l.queue.push(e),l.raf||(l.raf=requestAnimationFrame(u)))},error:()=>{l.decoder===t&&x()}});try{let s;return t.configure({codec:(s=e=>e.toString(16).padStart(2,"0"),`avc1.${s(e[1])}${s(e[2])}${s(e[3])}`),optimizeForLatency:!0}),l.decoder=t,!0}catch{try{t.close()}catch{}return a("decoder failed"),d(),!1}},p=({data:e,isKey:t,isConfig:s,ptsMs:n})=>{let r=e;if(s){l.config=r;let e=l4(r).spsBytes;e&&m(e);return}if(t&&l.decoder?.state!=="configured"){if(!l.config)return void d();let e=l4(l.config).spsBytes;if(!e||!m(e))return}if(t&&l.config){let e=new Uint8Array(l.config.byteLength+r.byteLength);e.set(l.config,0),e.set(r,l.config.byteLength),r=e}if(l.dropping){if(!t||l.decoder?.state!=="configured")return void d();l.dropping=!1}if(l.decoder?.state!=="configured"){t||d();return}if(l.decoder.decodeQueueSize>30)return void(l.dropping=!0,d());if(!l.sawKey){if(!t)return void d();l.sawKey=!0,a("streaming")}try{l.decoder.decode(new EncodedVideoChunk({type:t?"key":"delta",timestamp:1e3*n,data:r}))}catch{x()}},f=e=>{e<=l.ackedSeq||(l.ackedSeq=e,r.emit("mobile:ack",{seq:e}))},h=e=>{let t=function(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):e;if(t.byteLength<18)return null;let s=new DataView(t.buffer,t.byteOffset,t.byteLength);if(0xffffffff!==s.getUint32(0))return null;let n=s.getUint8(12);return{frameSeq:s.getUint32(4),chunkIdx:s.getUint16(8),chunkCount:s.getUint16(10),isKey:(1&n)!=0,isConfig:(2&n)!=0,ptsMs:s.getUint32(14),payload:t.slice(18)}}(e);if(!t)return;if(1===t.chunkCount){f(t.frameSeq),p({data:t.payload,isKey:t.isKey,isConfig:t.isConfig,ptsMs:t.ptsMs});return}let s=l.pending.get(t.frameSeq);if(!s)for(let e of(s={chunks:Array(t.chunkCount),received:0,count:t.chunkCount,isKey:t.isKey,isConfig:t.isConfig,ptsMs:t.ptsMs},l.pending.set(t.frameSeq,s),l.pending.keys()))t.frameSeq-e>96&&l.pending.delete(e);if(s.chunks[t.chunkIdx]||(s.chunks[t.chunkIdx]=t.payload,s.received++,s.received!==s.count))return;l.pending.delete(t.frameSeq),f(t.frameSeq);let n=new Uint8Array(s.chunks.reduce((e,t)=>e+t.byteLength,0)),r=0;for(let e of s.chunks)n.set(e,r),r+=e.byteLength;p({data:n,isKey:s.isKey,isConfig:s.isConfig,ptsMs:s.ptsMs})},b=()=>a("ended");return r.on("mobile-bin",h),r.on("file-bin",h),r.on("mobile:ended",b),d(),()=>{r.off("mobile-bin",h),r.off("file-bin",h),r.off("mobile:ended",b),l.raf&&cancelAnimationFrame(l.raf),i(),l.pending.clear(),c.current=null}},[e,t,s,n,d]),(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t||!n)return;let r=()=>{let e=!document.hidden;s.emit("mobile:visible",{visible:e}),e&&d()};return document.addEventListener("visibilitychange",r),s.emit("mobile:visible",{visible:!document.hidden}),()=>document.removeEventListener("visibilitychange",r)},[e,t,n,d]),{status:l6?l:"unsupported",fps:i,requestKeyframe:d}}({busRef:t,connected:l,canvasRef:o,meta:A}),W=function({busRef:e,canvasRef:t}){let s=(0,r.useRef)(null),n=(0,r.useRef)(null),l=(0,r.useRef)(0),a=(0,r.useCallback)(t=>{e?.current?.emit("mobile:input",t)},[e]),i=(0,r.useCallback)(()=>{l.current=0;let e=n.current;e&&(n.current=null,a({type:"touch",action:"move",...e}))},[a]),o=(0,r.useCallback)(e=>{let s=t.current;if(!s)return null;let n=s.getBoundingClientRect(),r=Math.min(n.width/s.width,n.height/s.height),l=s.width*r,a=s.height*r,i=n.left+(n.width-l)/2,o=n.top+(n.height-a)/2,c=(e.clientX-i)/l,d=(e.clientY-o)/a;return c<0||c>1||d<0||d>1?null:{x:c,y:d}},[t]),c=(0,r.useCallback)(e=>{let t=o(e);t&&(e.currentTarget.setPointerCapture?.(e.pointerId),s.current=t,a({type:"touch",action:"down",...t}))},[a,o]),d=(0,r.useCallback)(e=>{if(!s.current)return;let t=o(e);t&&(n.current=t,l.current||(l.current=requestAnimationFrame(i)))},[i,o]),u=(0,r.useCallback)(e=>{let t=o(e);if(!t)return;e.preventDefault();let s=1===e.deltaMode?16:2===e.deltaMode?400:1,n=e=>Math.max(-16,Math.min(16,-(e*s)/100));a({type:"scroll",...t,hscroll:n(e.deltaX),vscroll:n(e.deltaY)})},[a,o]),x=(0,r.useCallback)(e=>{let t=s.current;t&&(s.current=null,n.current=null,l.current&&(cancelAnimationFrame(l.current),l.current=0),a({type:"touch",action:"up",...o(e)||{x:t.x,y:t.y}}))},[a,o]);return{onPointerDown:c,onPointerMove:d,onPointerUp:x,onPointerCancel:x,onWheel:u,sendKey:(0,r.useCallback)(e=>a({type:"key",name:e}),[a])}}({busRef:t,canvasRef:o}),U=function({busRef:e,protocolRef:t,serial:s,enabled:n}){let[l,a]=(0,r.useState)([]),[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(0),[m,p]=(0,r.useState)(null),f=(0,r.useCallback)(async()=>{if(!s||!n)return;let t=await X(e?.current,"mobile:apps",{serial:s});t?.success&&(a(t.apps||[]),o(t.foreground||null))},[e,s,n]);(0,r.useEffect)(()=>{f()},[f]);let h=(0,r.useCallback)(async(t,n,r)=>{d(n),p(null);let l=await X(e?.current,t,{serial:s,packageName:n});return(d(null),l?.success)?(r&&await f(),!0):(p(l?.error||"Failed"),!1)},[e,s,f]),b=(0,r.useCallback)(e=>h("mobile:launch",e),[h]),g=(0,r.useCallback)(e=>h("mobile:stopApp",e),[h]),v=(0,r.useCallback)(e=>h("mobile:clearApp",e),[h]),y=(0,r.useCallback)(e=>h("mobile:uninstall",e,!0),[h]),w=(0,r.useCallback)(async n=>{if(n&&s){d("install"),p(null),x(0);try{let r=await X(e?.current,"mobile:apkStage",{name:n.name,size:n.size});if(!r?.success)throw Error(r?.error||"Cannot stage APK");let l=null;if(await G({bus:e?.current,protocolRef:t,targetDir:r.targetDir,items:[{file:n,relativePath:r.fileName}],callbacks:{onProgress:(e,t,s)=>x(s?t/s:0),onError:(e,t)=>{l=t}}}),l)throw l;let a=await X(e?.current,"mobile:install",{serial:s,fileName:r.fileName,launch:!0});if(!a?.success)throw Error(a?.error||"Install failed");return await f(),a.packageName}catch(e){return p(e.message),null}finally{d(null),x(0)}}},[e,t,s,f]),j=(0,r.useCallback)(async t=>{p(null);let n=await X(e?.current,"mobile:openLink",{serial:s,url:t});return n?.success||p(n?.error||"Could not open link"),n?.success},[e,s]);return{apps:l,foreground:i,busy:c,progress:u,error:m,setError:p,refresh:f,install:w,launch:b,stopApp:g,clearData:v,uninstall:y,openLink:j}}({busRef:t,protocolRef:s,serial:P,enabled:!!A}),q=function({busRef:e,serial:t,active:s,foregroundPackage:n}){let[l,a]=(0,r.useState)([]),[i,o]=(0,r.useState)("I"),[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(null),m=(0,r.useRef)(!1);(0,r.useEffect)(()=>{!m.current&&n&&x(n)},[n]);let p=(0,r.useCallback)(e=>{m.current=!0,x(e)},[]),[f,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(!1),v=(0,r.useRef)(0),y=(0,r.useRef)(!1);(0,r.useEffect)(()=>{y.current=f},[f]);let w=(0,r.useCallback)(()=>a([]),[]);return(0,r.useEffect)(()=>{let n=e?.current;if(!n||!t||!s)return;a([]);let r=({lines:e})=>{!y.current&&Array.isArray(e)&&a(t=>{let s=t.concat(e.map(e=>{var t;let s;return t=v.current++,(s=l8.exec(e))?{seq:t,time:s[1].slice(6),level:s[2],tag:s[3].trim(),message:s[4]}:{seq:t,time:"",level:"V",tag:"",message:e}}));return s.length>5e3?s.slice(s.length-5e3):s})};return n.on("mobile:logcat",r),X(n,"mobile:logcatStart",{serial:t,minLevel:i,search:c,includeNoise:b,...m.current||u?{packageName:u}:{}}),()=>{n.off("mobile:logcat",r),n.emit("mobile:logcatStop")}},[e,t,s]),(0,r.useEffect)(()=>{if(!s||!t)return;let n=setTimeout(()=>{e?.current?.emit("mobile:logcatFilter",{minLevel:i,search:c,packageName:u,includeNoise:b})},200);return()=>clearTimeout(n)},[i,c,u,b,s,t,e]),{lines:l,clear:w,minLevel:i,setMinLevel:o,search:c,setSearch:d,packageName:u,setPackageName:p,paused:f,setPaused:h,includeNoise:b,setIncludeNoise:g}}({busRef:t,serial:P,active:!!A&&"logs"===c,foregroundPackage:U.foreground?.packageName});(0,r.useEffect)(()=>{let e=o.current;e&&A&&(e.width=A.width,e.height=A.height)},[A]);let V="panel"===a,J=b.find(e=>e.serial===P)||null,Y=(0,r.useCallback)(async()=>{x(!1),B(),P&&await j(P)},[P,B,j]),Z=(0,r.useCallback)(async e=>{e.serial===P&&B(),await j(e.serial)},[P,B,j]),Q=(0,r.useCallback)(()=>{V||B(),e?.()},[V,B,e]),ee=(0,r.useCallback)(()=>{let e=b.find(e=>e.serial===P);e&&L(e)},[b,P,L]);if(!A){let e;return(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col bg-bg",children:[!V&&(0,n.jsxs)("header",{className:"flex items-center gap-2 px-2 py-1.5 border-b border-border flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),Q()},className:"p-1.5 text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]","aria-label":i("common.back"),children:(0,n.jsx)(el.JG,{size:18})}),(0,n.jsx)(el.wO,{size:16,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-text truncate",children:i("mobile.title")})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable flex items-center justify-center",children:I||v?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-3 p-6 text-center",children:[(0,n.jsx)(el.kr,{size:22,className:"text-brand-500 animate-spin"}),(0,n.jsx)("p",{className:"text-text text-sm",children:v?(e=v.phase,i(`mobile.phase${e.charAt(0).toUpperCase()}${e.slice(1)}`)):i("mobile.starting")}),v&&(0,n.jsx)("p",{className:"text-text-muted text-xs",children:v.avdName}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),F()},className:"px-3 py-1.5 text-xs text-text-muted bg-surface hover:bg-surface-2 rounded-brand transition-colors",children:i("common.cancel")})]}):l6?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l7,{devices:b,canManage:g,booting:v,stopping:k,loading:!f.loaded,error:D||f.error,onOpen:L,onStop:Z,onRefresh:y,lowPower:N,onLowPowerChange:C,onAddDevice:()=>{R(),p(!0)},onDeleteAvd:z,onWipeAvd:M,sdkJob:S,onShowSetup:()=>p(!0)}),(0,n.jsx)(at,{isOpen:m,onClose:()=>p(!1),presets:T,sdkJob:S,onProvision:E,onCancel:$})]}):(0,n.jsx)("p",{className:"text-text-muted text-sm max-w-xs text-center p-6",children:i("mobile.unsupportedBrowser")})})]})}return(0,n.jsxs)("div",{className:"absolute inset-0 flex bg-bg",children:[(0,n.jsx)(ec.A,{isOpen:u,onClose:()=>x(!1),onConfirm:Y,title:i("mobile.shutdownTitle"),message:i("mobile.shutdownMessage",{name:A.deviceName}),confirmText:i("mobile.shutdownConfirm")}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 relative flex items-center justify-center bg-black",children:[(0,n.jsx)("canvas",{ref:o,onPointerDown:W.onPointerDown,onPointerMove:W.onPointerMove,onPointerUp:W.onPointerUp,onPointerCancel:W.onPointerCancel,onWheel:W.onWheel,className:"max-w-full max-h-full object-contain touch-none"}),("connecting"===K||"idle"===K)&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:(0,n.jsx)(el.kr,{size:22,className:"text-brand-500 animate-spin"})}),("ended"===K||"decoder failed"===K)&&(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 px-6 text-center bg-black/40",children:[(0,n.jsx)("p",{className:"text-text text-sm",children:i("ended"===K?"mobile.streamEnded":"mobile.streamFailed")}),J?(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),ee()},className:"px-3 py-1.5 text-xs text-brand-500 bg-surface hover:bg-surface-2 rounded-brand transition-colors",children:i("mobile.retry")}):(0,n.jsx)("p",{className:"text-text-muted text-xs",children:i("mobile.streamGone")})]}),"streaming"===K&&O>0&&(0,n.jsxs)("span",{className:"absolute top-2 right-2 px-1.5 py-0.5 rounded bg-black/50 text-[10px] text-white/80 pointer-events-none",children:[O," fps"]}),c&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d(null)},className:"absolute inset-x-0 top-0 h-16 z-10 cursor-pointer","aria-label":i("mobile.backToScreen")}),c&&(0,n.jsxs)("div",{className:"absolute inset-x-0 bottom-0 top-16 bg-bg border-t border-border flex flex-col shadow-[0_-8px_24px_rgba(0,0,0,0.35)] sheet-rise",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-border flex-shrink-0",children:["apps"===c?(0,n.jsx)(el.lP,{size:14,className:"text-brand-500 flex-shrink-0"}):(0,n.jsx)(el.iU,{size:14,className:"text-brand-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs text-text flex-1 truncate",children:i("apps"===c?"mobile.tabApps":"mobile.tabLogs")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d(null)},className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",title:i("mobile.backToScreen"),"aria-label":i("mobile.backToScreen"),children:(0,n.jsx)(el.X,{size:14})})]}),"apps"===c?(0,n.jsx)(as,{apps:U.apps,foreground:U.foreground,busy:U.busy,progress:U.progress,error:U.error,onInstall:U.install,onLaunch:U.launch,onStopApp:U.stopApp,onClearData:U.clearData,onUninstall:U.uninstall,onOpenLink:U.openLink,onRefresh:U.refresh}):(0,n.jsx)(an,{logcat:q,apps:U.apps})]},c)]}),(0,n.jsxs)("div",{className:"flex flex-col items-center gap-0.5 px-1 py-1.5 pb-safe border-l border-border flex-shrink-0 overflow-y-auto modal-scrollable",children:[(0,n.jsx)(al,{icon:(0,n.jsx)(el.lM,{size:15,className:"-rotate-90"}),label:i("mobile.back"),onClick:()=>W.sendKey("back")}),(0,n.jsx)(al,{icon:(0,n.jsx)(el.jl,{size:15}),label:i("mobile.home"),onClick:()=>W.sendKey("home")}),(0,n.jsx)(al,{icon:(0,n.jsx)(el.M6,{size:14}),label:i("mobile.recents"),onClick:()=>W.sendKey("recents")}),(0,n.jsx)("div",{className:"w-5 h-px bg-border my-1"}),(0,n.jsx)(al,{icon:(0,n.jsx)(el.LM,{size:15}),label:i("mobile.power"),onClick:()=>W.sendKey("power")}),(0,n.jsx)("div",{className:"w-5 h-px bg-border my-1"}),(0,n.jsx)(al,{icon:(0,n.jsx)(el.lP,{size:15}),label:i("mobile.tabApps"),onClick:()=>d("apps"===c?null:"apps"),active:"apps"===c}),(0,n.jsx)(al,{icon:(0,n.jsx)(el.iU,{size:15}),label:i("mobile.tabLogs"),onClick:()=>d("logs"===c?null:"logs"),active:"logs"===c}),(0,n.jsx)("div",{className:"flex-1 min-h-2"}),(0,n.jsx)(al,{icon:(0,n.jsx)(el.wO,{size:15}),label:i("mobile.switchDevice"),onClick:B}),J?.canStop&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),x(!0)},className:"p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0 text-red-400 hover:bg-red-500/15",title:i("mobile.shutdownDevice"),"aria-label":i("mobile.shutdownDevice"),children:(0,n.jsx)(el.$o,{size:15})}),!V&&(0,n.jsx)(al,{icon:(0,n.jsx)(el.X,{size:15}),label:i("common.close"),onClick:Q})]})]})}function al({icon:e,label:t,onClick:s,active:r=!1}){return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s?.()},className:`p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0 ${r?"text-brand-500 bg-surface-2":"text-text hover:bg-surface-2"}`,title:t,"aria-label":t,"aria-pressed":r,children:e})}let aa=[{edge:"n",className:"top-0 left-3 right-3 h-1",cursor:"cursor-ns-resize"},{edge:"s",className:"bottom-0 left-3 right-3 h-1",cursor:"cursor-ns-resize"},{edge:"w",className:"top-3 bottom-3 left-0 w-1",cursor:"cursor-ew-resize"},{edge:"e",className:"top-3 bottom-3 right-0 w-1",cursor:"cursor-ew-resize"},{edge:"nw",className:"top-0 left-0 w-3 h-3",cursor:"cursor-nwse-resize"},{edge:"ne",className:"top-0 right-0 w-3 h-3",cursor:"cursor-nesw-resize"},{edge:"sw",className:"bottom-0 left-0 w-3 h-3",cursor:"cursor-nesw-resize"},{edge:"se",className:"bottom-0 right-0 w-3 h-3",cursor:"cursor-nwse-resize"}];function ai({busRef:e,protocolRef:t,connected:s,pinSlot:l=null}){let{t:a}=(0,eu.s)(),i=(0,h.B)(e=>e.mobileMode),o=(0,h.B)(e=>e.mobileFloatRect),c=(0,h.B)(e=>e.setMobileOpen),d=(0,h.B)(e=>e.setMobileSession),u=(0,h.B)(e=>e.setMobileMode),x=function({rect:e,onChange:t,enabled:s}){let[n,l]=(0,r.useState)(()=>{let t,s;return e?l3(e):(t=eJ.qj.width.default,s=Math.min(eJ.qj.height.default,window.innerHeight-2*eJ.qj.defaultOffset),{x:Math.max(eJ.qj.margin,window.innerWidth-t-eJ.qj.defaultOffset),y:Math.max(eJ.qj.margin,window.innerHeight-s-eJ.qj.defaultOffset),w:t,h:s})}),[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(null),c=(0,r.useRef)(n),d=(0,r.useCallback)(e=>{c.current=e,l(e)},[]);(0,r.useEffect)(()=>{if(!s)return;let e=()=>{let e=c.current;if(!e)return;let t=Math.min(e.h,window.innerHeight-2*eJ.qj.margin);d(l3({...e,h:t}))};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[s,d]);let u=(0,r.useCallback)((e,t)=>{(null==e.button||0===e.button)&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),o.current={mode:t,pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,origin:n},i(!0))},[n]),x=(0,r.useCallback)(e=>{let t=o.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void m(e);let s=e.clientX-t.startX,n=e.clientY-t.startY;if("move"===t.mode)return void d(l3({...t.origin,x:t.origin.x+s,y:t.origin.y+n}));let{origin:r,mode:l}=t,a=l.includes("w"),i=l.includes("n"),c=a||l.includes("e"),u=i||l.includes("s"),x=window.innerHeight-2*eJ.qj.margin,p=i?r.y+r.h-eJ.qj.margin:x,f=a?r.x+r.w-eJ.qj.margin:eJ.qj.width.max,h=c?l5(a?r.w-s:r.w+s,eJ.qj.width.min,Math.min(eJ.qj.width.max,f)):r.w,b=u?l5(i?r.h-n:r.h+n,eJ.qj.height.min,Math.min(x,p)):r.h;d({x:a?r.x+(r.w-h):r.x,y:i?r.y+(r.h-b):r.y,w:h,h:b})},[d]),m=(0,r.useCallback)(e=>{let s=o.current;s&&s.pointerId===e.pointerId&&(o.current=null,i(!1),c.current&&t?.(c.current))},[t]);return(0,r.useEffect)(()=>{if(!a)return;let e=()=>{o.current=null,i(!1),c.current&&t?.(c.current)};return window.addEventListener("blur",e),()=>window.removeEventListener("blur",e)},[a,t]),{rect:n,dragging:a,onDragHandlePointerDown:e=>u(e,"move"),onResizeHandlePointerDown:e=>t=>u(t,e),onPointerMove:x,onPointerUp:m,onPointerCancel:m}}({rect:o,onChange:(0,h.B)(e=>e.setMobileFloatRect),enabled:"float"===i}),m=(0,r.useCallback)(()=>{e?.current?.emit("mobile:stop"),d(null),c(!1)},[e,d,c]),p="pin"===i,f=r=>(0,n.jsxs)("div",{className:"flex flex-col h-full w-full bg-bg overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0.5 px-1.5 py-1 border-b border-border bg-surface flex-shrink-0",children:[(0,n.jsxs)("div",{className:`flex items-center gap-1 flex-1 min-w-0 ${r?"cursor-grab active:cursor-grabbing":""}`,onPointerDown:r?x.onDragHandlePointerDown:void 0,children:[r&&(0,n.jsx)(el.f2,{size:13,className:"text-text-muted flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs text-text-muted select-none truncate",children:a("mobile.title")})]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u(p?"float":"pin")},className:`p-1.5 rounded-brand transition-colors ${p?"text-brand-500 bg-surface-2":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:p?a("mobile.modeFloat"):a("mobile.modePin"),"aria-label":p?a("mobile.modeFloat"):a("mobile.modePin"),"aria-pressed":p,children:(0,n.jsx)(el.jz,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m()},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",title:a("common.close"),"aria-label":a("common.close"),children:(0,n.jsx)(el.X,{size:13})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 relative",children:(0,n.jsx)(ar,{busRef:e,protocolRef:t,connected:s,variant:"panel",onClose:m})})]});if(p)return l?(0,sd.createPortal)(f(!1),l):null;let b=x.rect;return b?(0,sd.createPortal)((0,n.jsxs)("div",{className:"fixed z-40 flex flex-col rounded-brand-lg overflow-hidden border border-border shadow-2xl bg-bg",style:{left:b.x,top:b.y,width:b.w,height:b.h},onPointerMove:x.onPointerMove,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerCancel,children:[f(!0),aa.map(({edge:e,className:t,cursor:s})=>(0,n.jsx)("div",{onPointerDown:x.onResizeHandlePointerDown(e),className:`absolute ${t} ${s}`,"aria-label":a("mobile.resize")},e))]}),document.body):null}let ao=e=>(e||"").split("/").filter(Boolean).pop()||e;function ac(e,t){return e?e.endsWith("/")?`${e}${t}`:`${e}/${t}`:t}function ad(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}function au(e){if(!e)return"";let t=e.split("/").filter(Boolean);return t[t.length-1]||e}function ax({dirs:e,fileBus:t,onDirsChanged:s,enabled:n=!0,debounceMs:l=O.Jl.DEBOUNCE_MS}){let a=(0,r.useRef)(new Set),i=(0,r.useRef)(s);(0,r.useEffect)(()=>{i.current=s},[s]);let{watchDir:o,unwatchDir:c,onFileChange:d}=t||{},u=e.join("\n");(0,r.useEffect)(()=>{if(!n||!o||!c)return;let e=!0,t=a.current,s=new Set,r=null,x=new Set([...u?u.split("\n"):[]].sort((e,t)=>t.split("/").length-e.split("/").length).slice(0,O.Jl.MAX_DIRS)),m=()=>{if(r=null,!e||!s.size)return;let t=[...s];s.clear(),i.current?.(t)},p=async()=>{for(let e of t)x.has(e)||(t.delete(e),c(e));for(let s of x){if(t.has(s))continue;t.add(s);let n=await o(s);e&&n?.watching!==!1||t.delete(s)}},f=d?.(({type:e,path:t})=>{if(!t)return;let n="flooded"===e?t:t.slice(0,t.lastIndexOf("/"))||"/";x.has(n)&&(s.add(n),r||(r=setTimeout(m,l)))})||(()=>{});return p(),()=>{for(let s of(e=!1,clearTimeout(r),f(),t))c(s);t.clear()}},[u,n,l,o,c,d])}function am(){let[e,t]=(0,r.useState)(()=>"u"<typeof document||!document.hidden);return(0,r.useEffect)(()=>{let e=()=>t(!document.hidden);return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[]),e}function ap(e,t=""){if(!e?.success)return{};let s=e.files||e.status||[],n={};for(let e of s){let s=e?.path||e?.file,r=e?.status||e?.code;if(!s||!r)continue;n[t+s]=r;let l=s.split("/");for(let e=1;e<l.length;e++){let s=t+l.slice(0,e).join("/");n[s]||(n[s]="folder-changed")}}return n}async function af(e,t){let s=await e.gitStatus(t);if(s?.success)return{hasGit:!0,map:ap(s)};let n=await e.gitScanRepos?.(t),r=(n?.success?n.repos:[])||[],l=await Promise.all(r.map(async t=>{let s=String(t.relPath||"").split("\\").join("/");if(!s)return null;let n=await e.gitStatus(t.path);if(!n?.success)return null;let r=ap(n,`${s}/`);return Object.keys(r).length&&(r[s]||="folder-changed"),r})),a=Object.assign({},...l.filter(Boolean));return{hasGit:l.some(Boolean),map:a}}function ah(){try{let e=window.localStorage.getItem(O.d5.expandedFolders),t=e?JSON.parse(e):{};return Array.isArray(t)?{legacy:t}:t}catch{return{}}}function ab(){try{let e=window.localStorage.getItem(O.d5.showHidden);if(null===e)return!0;return!1!==JSON.parse(e)}catch{return!0}}let ag={created:"fileExplorer:fileCreated",deleted:"fileExplorer:fileDeleted",renamed:"fileExplorer:fileRenamed"};function av(e){window.dispatchEvent(new CustomEvent(ag[e]))}let{xT:ay,Qm:aw,Pv:aj}=JSON.parse('{"xT":{"js":"js","mjs":"js","cjs":"js","jsx":"reactjs","ts":"typescript","tsx":"reactts","json":"json","json5":"json5","yml":"yaml","yaml":"yaml","toml":"toml","xml":"xml","ini":"ini","env":"dotenv","md":"markdown","markdown":"markdown","mdx":"mdx","pdf":"pdf","csv":"text","html":"html","css":"css","scss":"scss","sass":"sass","less":"less","styl":"stylus","vue":"vue","svelte":"svelte","astro":"astro","py":"python","pyw":"python","rb":"ruby","php":"php","go":"go","rs":"rust","java":"java","kt":"kotlin","swift":"swift","scala":"scala","cljs":"clojure","ex":"elixir","erl":"erlang","hs":"haskell","ml":"ocaml","dart":"dartlang","lua":"lua","r":"r","c":"c","h":"c","cpp":"cpp","hpp":"cpp","cs":"csharp","m":"objectivec","sh":"shell","bash":"shell","zsh":"shell","fish":"shell","ps1":"powershell","bat":"bat","sql":"sql","gql":"graphql","proto":"protobuf","png":"image","jpg":"image","jpeg":"image","gif":"image","webp":"image","ico":"image","bmp":"image","svg":"svg","avif":"image","tiff":"image","mp4":"video","m4v":"video","webm":"video","mov":"video","mkv":"video","avi":"video","mp3":"audio","wav":"audio","ogg":"audio","flac":"audio","m4a":"audio","aac":"audio","zip":"zip","tar":"zip","gz":"zip","tgz":"zip","rar":"zip","7z":"zip","bz2":"zip","xz":"zip","jar":"jar","log":"log","diff":"diff","patch":"diff","woff":"font","woff2":"font","ttf":"font","eot":"font","otf":"font","db":"datadog","sqlite":"sqlite","sqlite3":"sqlite","jsonc":"json","cfg":"ini","conf":"ini","txt":"text","htm":"html","kts":"kotlin","clj":"clojure","exs":"elixir","cc":"cpp","cxx":"cpp","graphql":"graphql","tif":"image"},"Qm":{".editorconfig":"editorconfig",".env":"dotenv",".gitattributes":"git",".gitignore":"git",".npmrc":"npm","docker-compose.yaml":"docker","docker-compose.yml":"docker","dockerfile":"docker","license":"license","makefile":"gnu","package-lock.json":"npm","package.json":"npm","tsconfig.json":"typescript"},"Pv":{"src":"src","source":"src","sources":"src","lib":"library","libs":"library","library":"library","app":"app","apps":"app","application":"app","component":"component","components":"component","page":"view","pages":"view","view":"view","views":"view","html":"view","model":"model","models":"model","controller":"controller","controllers":"controller","handler":"controller","handlers":"controller","route":"route","routes":"route","router":"route","routers":"route","public":"public","assets":"images","images":"images","image":"images","img":"images","icon":"images","icons":"images","font":"fonts","fonts":"fonts","style":"style","styles":"style","css":"style","docs":"docs","doc":"docs","test":"test","tests":"test","__tests__":"test","spec":"test","specs":"test","coverage":"test","util":"tools","utils":"tools","tool":"tools","tools":"tools","helpers":"tools","helper":"tools","script":"script","scripts":"script","config":"config","configs":"config","configuration":"config",".github":"github",".git":"git",".vscode":"vscode",".idea":"idea","node_modules":"node","bower_components":"bower","dist":"dist","out":"dist","export":"dist","exports":"dist","build":"dist","target":"dist","api":"api","apis":"api","server":"server","services":"server","service":"server","locale":"locale","locales":"locale","i18n":"locale","lang":"locale","languages":"locale","bin":"azurepipelines",".bin":"azurepipelines","middleware":"middleware","middlewares":"middleware","store":"redux","stores":"redux","hook":"hook","hooks":"hook","types":"typescript","typings":"typescript","@types":"typescript","interface":"interfaces","interfaces":"interfaces","theme":"theme","themes":"theme","layout":"view","layouts":"view","ios":"ios","static":"public","asset":"images","documentation":"docs","__specs__":"test","state":"redux","type":"typescript","constant":"tools","constants":"tools","core":"src","main":"src","android":"android"}}'),ak="/icons/file-types",aN="/icons/folder-types",aC=`${ak}/default.svg`,aS=`${aN}/default.svg`,aT=`${aN}/default-open.svg`;function aR(e,t=!1){let s=aj[(e||"").toLowerCase()];return s?{src:t?`${aN}/${s}-open.svg`:`${aN}/${s}.svg`,alt:s}:{src:t?aT:aS,alt:"folder"}}function aE(e,t=16){let{src:s,alt:r}=function(e){if(!e)return{src:aC,alt:"file"};if("folder"===e.type)return aR(e.name,!1);let t=(e.name||"").toLowerCase(),s=function(e){if(!e)return"";let t=e.toLowerCase(),s=t.lastIndexOf(".");return s<=0?t:t.slice(s+1)}(e.name);if(aw[t]){let e=aw[t];return{src:`${ak}/${e}.svg`,alt:e}}if(ay[s]){let e=ay[s];return{src:`${ak}/${e}.svg`,alt:e}}return{src:aC,alt:"file"}}(e);return(0,n.jsx)("img",{src:s,alt:r,width:t,height:t,className:"pointer-events-none select-none",draggable:"false"})}let a$=e=>e?O.xW.compact:O.xW.normal,az=(e,t=!1)=>{let s=a$(t);return s.indentBase+e*s.indentStep};function aM({status:e}){return e?"folder-changed"===e?(0,n.jsx)("span",{className:"ml-auto mr-2 w-1.5 h-1.5 rounded-full bg-blue-400/70"}):(0,n.jsx)("span",{className:`ml-auto mr-2 text-[10px] font-semibold ${O.vs[e]||"text-text-muted"}`,children:e}):null}function aP({depth:e,compact:t=!1}){return(0,n.jsx)("div",{className:"text-[11px] text-text-muted italic py-0.5 pr-2",style:{paddingLeft:az(e,t)},children:"Showing first 300 entries — use search for the rest."})}let aA=(0,r.memo)(function({file:e,depth:t,isFolder:s,isExpanded:r,isLoading:l,isActive:a,isSelected:i,isRenaming:o,isDragOver:c,isCut:d,gitStatus:u,renameValue:x,renameInputRef:m,onRenameChange:p,onRenameSubmit:f,onRenameCancel:h,onToggleFolder:b,onClick:g,onContextMenu:v,onTouchStart:y,onTouchEnd:w,onDragStart:j,onDragOver:k,onDragLeave:N,onDrop:C,compact:S=!1,children:T}){let R=a$(S);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{"data-path":e.path,draggable:!o,onDragStart:t=>j(t,e),onDragOver:t=>k(t,e),onDragLeave:()=>N(e),onDrop:t=>C(t,e),className:`group relative flex items-center gap-1 rounded-[3px] mx-0.5 pr-2 cursor-pointer select-none ${R.text} ${R.padY} ${d?"opacity-50":""} ${c?"bg-brand-500/30 ring-1 ring-brand-500":i?"bg-brand-500/25":a?"bg-brand-500/15":"hover:bg-surface-2"}`,style:{paddingLeft:az(t,S)},onContextMenu:t=>v(t,e),onTouchStart:t=>y(t,e),onTouchEnd:w,onTouchMove:w,onClick:t=>!o&&g(e,t),children:[s?(0,n.jsx)("span",{onClick:t=>{t.stopPropagation(),b(e)},className:"flex items-center justify-center w-4 h-4 text-text-muted",children:l?(0,n.jsx)(el.Ay,{name:"Loader2",size:R.chevron-2,className:"animate-spin"}):(0,n.jsx)(el.Ay,{name:"ChevronRight",size:R.chevron,className:`transition-transform duration-150 ${r?"rotate-90":""}`})}):(0,n.jsx)("span",{className:"w-4 h-4"}),(0,n.jsx)("span",{className:"shrink-0",children:s?function(e,t=!1,s=16){let{src:r,alt:l}=aR(e,t);return(0,n.jsx)("img",{src:r,alt:l,width:s,height:s,className:"pointer-events-none select-none",draggable:"false"})}(e.name,r,R.icon):aE(e,R.icon)}),o?(0,n.jsx)("input",{ref:m,value:x,onChange:e=>p(e.target.value),onClick:e=>e.stopPropagation(),onBlur:f,onKeyDown:e=>{"Enter"===e.key?f():"Escape"===e.key&&h()},className:`flex-1 bg-surface-3 text-text ${R.text} px-1 py-0.5 rounded outline-none border border-brand-500`}):(0,n.jsx)("span",{className:`flex-1 truncate text-text ${O.vs[u]||""}`,title:e.name,children:e.name}),!o&&(0,n.jsx)(aM,{status:u}),!o&&(0,n.jsx)("div",{className:"absolute top-1/2 -translate-y-1/2 flex items-center pl-2 pr-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 transition-opacity",style:{right:(0,O.mv)(u)},children:(0,n.jsx)("button",{onClick:t=>v(t,e),className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(el.Ay,{name:"MoreHorizontal",size:R.chevron})})})]}),T]})});async function aI(e,t,s){let n=t?`${t}/${e.name}`:e.name;if(e.isFile){let t=await new Promise((t,s)=>e.file(t,s));s.push({file:t,relativePath:n})}else if(e.isDirectory){var r;for(let t of(await (r=e.createReader(),new Promise(e=>{let t=[],s=()=>r.readEntries(n=>{n.length?(t.push(...n),s()):e(t)},()=>e(t));s()}))))await aI(t,n,s)}}async function aD(e){let t=[],s=[...e.items||[]].map(e=>e.webkitGetAsEntry?.()).filter(Boolean);if(s.length)for(let e of s)await aI(e,"",t);else for(let s of e.files||[])t.push({file:s,relativePath:s.name});return t}let aL="fixed inset-0 z-50 flex items-center justify-center p-4",aB="w-full px-3 py-2 bg-surface-2 rounded-brand text-text focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out",aF="flex-1 py-2 bg-surface-2 text-text rounded-brand hover:bg-surface-3 transition-all duration-150 ease-out active:scale-[0.98]",aK="flex-1 py-2 bg-brand-500 text-white rounded-brand hover:bg-brand-600 transition-all duration-150 ease-out active:scale-[0.98]";function aO({label:e,ratio:t}){return(0,n.jsxs)("div",{className:"bg-brand-500/10 border-b border-brand-500/30 px-4 py-2 text-text text-xs flex items-center gap-2",children:[(0,n.jsx)(el.kr,{className:"animate-spin flex-shrink-0",size:14}),(0,n.jsx)("span",{className:"truncate flex-1",children:e}),(0,n.jsx)("div",{className:"w-16 h-1.5 bg-surface-2 rounded-full overflow-hidden flex-shrink-0",children:(0,n.jsx)("div",{className:"h-full bg-brand-500 transition-all",style:{width:`${Math.round(100*(t||0))}%`}})})]})}function aW({query:e,loading:t,onChange:s,onClose:r,compact:l=!1}){let{t:a}=(0,eu.s)();return l?(0,n.jsx)("div",{className:"px-2 py-1.5 border-b border-border-subtle flex-shrink-0",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(el.vj,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-subtle pointer-events-none"}),(0,n.jsx)("input",{type:"text",value:e,onChange:e=>s(e.target.value),placeholder:a("files.searchPlaceholder"),className:"w-full min-w-0 bg-surface-2 border border-border rounded-brand pl-7 pr-7 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500",autoFocus:!0}),t?(0,n.jsx)(el.kr,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 animate-spin text-brand-500"}):(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),r()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(el.X,{size:14})})]})}):(0,n.jsxs)("div",{className:"bg-surface-2 px-4 py-2 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)(el.vj,{className:"text-text-muted flex-shrink-0",size:20}),(0,n.jsx)("input",{type:"text",value:e,onChange:e=>s(e.target.value),placeholder:a("files.searchPlaceholder"),className:"flex-1 min-w-0 w-0 bg-transparent text-text placeholder-text-subtle focus:outline-none",autoFocus:!0}),t&&(0,n.jsx)(el.kr,{className:"animate-spin text-brand-500",size:16}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),r()},className:"p-1 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(el.X,{size:20})})]})}function a_({type:e,name:t,onTypeChange:s,onNameChange:l,onSubmit:a,onPickFile:i,onPickFolder:o,onClose:c}){let{t:d}=(0,eu.s)(),[u]=(0,r.useState)(()=>"u">typeof document&&"webkitdirectory"in document.createElement("input")),x="upload"===e;return(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),c())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[c]),(0,n.jsxs)("div",{className:aL,children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px]",onClick:c}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm my-auto max-h-[min(85%,calc(var(--app-height,85vh)-2rem))] overflow-y-auto",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:d("files.createNew")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s("file")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${"file"===e?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(el.ZH,{size:16,className:"text-text-subtle"})," ",d("files.file")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s("folder")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${"folder"===e?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(el.vd,{size:16,className:"text-orange-500/70"})," ",d("files.folder")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s("upload")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${x?"bg-brand-500 text-white dark:bg-white dark:text-black":"bg-surface-2 text-text"}`,children:[(0,n.jsx)(el._O,{size:16,className:"text-brand-500"})," ",d("common.upload")]})]}),x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),i()},className:`${aK} flex items-center justify-center gap-2`,children:[(0,n.jsx)(el.ZH,{size:16})," ",d("files.pickFile")]}),u&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),o()},className:`${aF} flex items-center justify-center gap-2`,children:[(0,n.jsx)(el.vd,{size:16})," ",d("files.pickFolder")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),c()},className:`${aF} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:d("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:t,onChange:e=>l(e.target.value),onKeyDown:e=>"Enter"===e.key&&a(),placeholder:d("file"===e?"files.placeholderFile":"files.placeholderFolder"),className:aB,autoFocus:!0}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),c()},className:`${aF} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:d("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),a()},className:`${aK} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:d("common.create")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(el.Lt,{size:10,strokeWidth:2.5})})]})]})]})]})]})]})}function aH({value:e,onChange:t,onSubmit:s,onClose:l}){let{t:a}=(0,eu.s)();return(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[l]),(0,n.jsxs)("div",{className:aL,children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px]",onClick:l}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm my-auto max-h-[min(85%,calc(var(--app-height,85vh)-2rem))] overflow-y-auto",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:a("files.rename")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsx)("input",{type:"text",value:e,onChange:e=>t(e.target.value),onKeyDown:e=>"Enter"===e.key&&s(),className:aB,autoFocus:!0}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),l()},className:`${aF} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:a("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s()},className:`${aK} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:a("files.rename")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(el.Lt,{size:10,strokeWidth:2.5})})]})]})]})]})]})}function aU({name:e,onResolve:t}){let{t:s}=(0,eu.s)();(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t?.("skip"))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t]);let l=(e,r,l=!1)=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),t(e)},className:`py-2 rounded-brand text-sm flex items-center justify-center gap-1.5 ${r}`,children:[(0,n.jsx)("span",{children:s(`menu.${e}`)}),l&&(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]});return(0,n.jsxs)("div",{className:aL,children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px]",onClick:()=>t?.("skip")}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:s("menu.conflictTitle")})}),(0,n.jsx)("div",{className:"px-4 pb-3 text-text-muted text-sm break-all",children:s("menu.conflictMessage",{name:e})}),(0,n.jsxs)("div",{className:"p-4 grid grid-cols-2 gap-2",children:[l("skip","bg-surface-2 text-text hover:bg-surface-3",!0),l("skipAll","bg-surface-2 text-text hover:bg-surface-3"),l("replace","bg-brand-500 text-white hover:bg-brand-600"),l("replaceAll","bg-brand-500 text-white hover:bg-brand-600")]})]})]})}async function aq(e,t,s,n=!1){if(!e||!t||!s)return{success:!1};let r=ac(t,".gitignore"),l=s.replace(/^\/+/,"");n&&!l.endsWith("/")&&(l=`${l}/`);let a=await e.readFile(r),i=a?.success&&a.content||"",o=i.split(/\r?\n/),c=l.replace(/\/$/,"");if(o.includes(l)||o.includes(c)||o.includes(`/${l}`)||o.includes(`/${c}`))return{success:!0,alreadyIgnored:!0};let d=i?i.endsWith("\n")?`${i}${l}
12
+ `:`${i}
13
+ ${l}
14
+ `:`${l}
15
+ `;return await e.writeFile(r,d)}let aX="application/x-file-paths",aV=()=>"u">typeof document&&"webkitdirectory"in document.createElement("input"),aJ=e=>{let t=e.dataTransfer.getData(aX);if(!t)return null;try{return JSON.parse(t)}catch{return null}},aG=e=>[...e.dataTransfer?.types||[]].includes("Files");function aY({workspace:e,fileBus:t,onOpenFile:s,activeFile:l,onSwitchWorkspace:a,onNewTerminal:i,onSearchFolder:o,compact:c=!1,onlyChanged:d=!1,onActions:u}){let{t:x}=(0,eu.s)(),[m,p]=(0,r.useState)(null),f=(0,r.useRef)(null),h=s_(f,m?.x??0,m?.y??0),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(""),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(""),[C,S]=(0,r.useState)(null),[T,R]=(0,r.useState)(null),[E,$]=(0,r.useState)(()=>new Set),z=(0,r.useRef)(E);(0,r.useEffect)(()=>{z.current=E},[E]);let M=(0,r.useRef)(v);(0,r.useEffect)(()=>{M.current=v},[v]);let P=(0,r.useRef)(b);(0,r.useEffect)(()=>{P.current=b},[b]);let[A,I]=(0,r.useState)(null),[D,L]=(0,r.useState)(!1),[B,F]=(0,r.useState)(null),[K,W]=(0,r.useState)(null),[_,H]=(0,r.useState)(null),[U,q]=(0,r.useState)(null),X=(0,r.useRef)(null),V=(0,r.useRef)(null),J=(0,r.useRef)(null),G=(0,r.useRef)(null),[Y]=(0,r.useState)(aV),Z=(0,r.useRef)(null),Q=(0,r.useRef)(null),ee=(0,r.useRef)(null),et=(0,r.useCallback)(t=>t&&e?t.replace(`${e}/`,""):t,[e]),{tree:es,expanded:en,loading:er,truncatedDirs:ea,gitStatusMap:ei,showHidden:eo,setShowHidden:ex,loadDir:em,loadGitStatus:ep,toggleFolder:ef,expandDir:eh,collapseAll:eb,refreshAll:eg}=function({workspace:e,fileBus:t}){let[s,n]=(0,r.useState)(()=>new Map),[l,a]=(0,r.useState)(()=>new Set),[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(()=>new Set),[u,x]=(0,r.useState)(()=>new Set),[m,p]=(0,r.useState)({}),[f,h]=(0,r.useState)(ab),b=(0,r.useCallback)(async e=>{d(t=>{let s=new Set(t);return s.add(e),s});let s=await t.getFiles(e,f);return(d(t=>{let s=new Set(t);return s.delete(e),s}),s?.success)?(n(t=>{let n=new Map(t);return n.set(e,s.files||[]),n}),x(t=>{let n=!!s.truncated;if(n===t.has(e))return t;let r=new Set(t);return n?r.add(e):r.delete(e),r}),s.files||[]):null},[t,f]),g=(0,r.useRef)(0),v=(0,r.useCallback)(async()=>{if(!e)return;let s=++g.current,{map:n}=await af(t,e);s===g.current&&p(n)},[t,e]);(0,r.useEffect)(()=>{let t,s;if(!e)return;let n=!0,r=null,l=1e3,i=Array.isArray(s=(t=ah())[e])?s:Array.isArray(t.legacy)?t.legacy:[],c=new Set([e]),d=i.filter(t=>"string"==typeof t&&t.startsWith(e));for(let e of d)c.add(e);let u=async()=>{let[t]=await Promise.all([b(e),...d.map(e=>b(e))]);if(n){if(null==t&&l<=16e3){let e=l;l*=2,r=setTimeout(u,e);return}a(c),o(e),v()}};return u(),()=>{n=!1,clearTimeout(r)}},[e]),(0,r.useEffect)(()=>{let e=null,t=()=>{clearTimeout(e),e=setTimeout(v,300)},s=["fileExplorer:fileSaved","fileExplorer:fileCreated","fileExplorer:fileDeleted","fileExplorer:fileRenamed",O.GW];return s.forEach(e=>window.addEventListener(e,t)),()=>{clearTimeout(e),s.forEach(e=>window.removeEventListener(e,t))}},[v]),(0,r.useEffect)(()=>{if(i===e&&e)try{let t=ah();delete t.legacy,t[e]=[...l],window.localStorage.setItem(O.d5.expandedFolders,JSON.stringify(t))}catch{}},[e,i,l]),(0,r.useEffect)(()=>{window.localStorage.setItem(O.d5.showHidden,JSON.stringify(f)),s.size>0&&Promise.all([...s.keys()].map(e=>b(e))).catch(()=>{})},[f]);let y=(0,r.useCallback)(async e=>{(0,ed.e)();let t=e.path;l.has(t)?a(e=>{let s=new Set(e);return s.delete(t),s}):(s.has(t)||await b(t),a(e=>{let s=new Set(e);return s.add(t),s}))},[l,s,b]),w=(0,r.useCallback)(e=>{a(t=>{let s=new Set(t);return s.add(e),s})},[]),j=(0,r.useCallback)(()=>{(0,ed.e)(),a(new Set)},[]),k=am(),N=(0,r.useMemo)(()=>[...s.keys()].filter(t=>t===e||l.has(t)),[s,l,e]),C=(0,r.useCallback)(e=>{Promise.all(e.map(e=>b(e))).catch(()=>{}),v()},[b,v]);ax({dirs:N,fileBus:t,onDirsChanged:C,enabled:k});let S=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=k&&!S.current;S.current=k,e&&s.size&&C([...s.keys()])},[k]);let T=(0,r.useCallback)(async()=>{(0,ed.e)();let e=[...s.keys()];await Promise.all(e.map(e=>b(e))),v()},[s,b,v]);return{tree:s,expanded:l,loading:c,truncatedDirs:u,gitStatusMap:m,showHidden:f,setShowHidden:h,loadDir:b,loadGitStatus:v,toggleFolder:y,expandDir:w,collapseAll:j,refreshAll:T}}({workspace:e,fileBus:t}),{createItem:ev,renameItem:ey,deleteItem:ew,deleteMany:ej,duplicateItem:ek,moveTo:eN,pasteInto:eC}=function({fileBus:e,loadDir:t,loadGitStatus:s,expandDir:n,onOpenFile:l,onMoved:a}){let i=(0,r.useCallback)(async(s,r,a)=>{let i=ac(s,r),o=await e.createItem(i,a);o?.success&&(av("created"),await t(s),"folder"===a?n(s):l?.(i))},[e,t,n,l]),o=(0,r.useCallback)(async(s,n)=>{let r=ad(s.path),l=ac(r,n),a=await e.renameItem(s.path,l);a?.success&&(av("renamed"),await t(r))},[e,t]),c=(0,r.useCallback)(async s=>{let n=ad(s.path),r=await e.deleteItem(s.path);r?.success&&(av("deleted"),await t(n))},[e,t]),d=(0,r.useCallback)(async n=>{if(!n?.length)return;let r=new Set;for(let t of n){let s=await e.deleteItem(t.path);s?.success&&r.add(ad(t.path))}if(r.size){for(let e of(av("deleted"),r))await t(e);s(),a?.()}},[e,t,s,a]),u=(0,r.useCallback)(async(t,s)=>{let n=au(t),r=new Set(((await e.getFiles(s,!0))?.files||[]).map(e=>e.name)),l=n;if(r.has(l)){let e=n.lastIndexOf("."),t=e>0?n.slice(0,e):n,s=e>0?n.slice(e):"";l=`${t} copy${s}`;for(let e=2;r.has(l);e++)l=`${t} copy ${e}${s}`}return e.copyItem(t,ac(s,l))},[e]),x=(0,r.useCallback)(async e=>{let n=ad(e.path),r=await u(e.path,n);r?.success&&(av("created"),await t(n),s())},[u,t,s]),m=(0,r.useCallback)(async(n,r)=>{if(n?.length&&r){for(let t of n){let s=ac(r,t.split("/").pop());t===s||s.startsWith(t+"/")||await e.renameItem(t,s)}for(let e of new Set([r,...n.map(e=>ad(e))]))await t(e);av("renamed"),s(),a?.()}},[e,t,s,a]),p=(0,r.useCallback)(async(e,r,l)=>{if(!e?.length||!r)return;if("cut"===l)return m(e,r);let a=0;for(let t of e){if(r===t||r.startsWith(t+"/"))continue;let e=await u(t,r);e?.success&&a++}a&&(av("created"),await t(r),n(r),s())},[u,m,t,n,s]);return{createItem:i,renameItem:o,deleteItem:c,deleteMany:d,duplicateItem:x,moveTo:m,pasteInto:p}}({fileBus:t,loadDir:em,loadGitStatus:ep,expandDir:eh,onOpenFile:s,onMoved:()=>$(new Set)});(0,r.useEffect)(()=>{if(!m)return;let e=()=>p(null);return window.addEventListener("click",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("click",e),window.removeEventListener("scroll",e,!0)}},[m]),(0,r.useEffect)(()=>{if(b&&Q.current){Q.current.focus();let e=Q.current.value.length;Q.current.setSelectionRange(e,e)}},[b]),(0,r.useEffect)(()=>{w&&ee.current&&ee.current.focus()},[w]);let eS=(0,r.useCallback)(()=>T&&es.has(T)?T:e,[T,es,e]),eT=(0,r.useCallback)(async e=>{let t=k.trim();if(!t)return;let s=w?.dir||eS();await ev(s,t,e),j(null),N("")},[k,w,eS,ev]),eR=(0,r.useCallback)(async()=>{let e=P.current;if(!e)return;let t=M.current.trim();t&&t!==e.name&&await ey(e,t),g(null)},[ey]),eE=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),e$=(0,r.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),(0,ed.e)(),$(e=>e.has(t.path)?e:new Set([t.path])),q(t.path),p({file:t,x:e.clientX,y:e.clientY})},[]),ez=(0,r.useCallback)((e,t)=>{let s=e.touches?.[0];if(!s)return;let n=s.clientX,r=s.clientY;Z.current=setTimeout(()=>{(0,ed.e)(),p({file:t,x:n,y:r})},500)},[]),eM=(0,r.useCallback)(()=>{Z.current&&(clearTimeout(Z.current),Z.current=null)},[]),eP=(0,r.useMemo)(()=>{if(!l)return null;if(!(0,O.pA)(l))return l;let{repoPath:t,filePath:s}=(0,O.qu)(l);return s?`${t||e}/${s}`:null},[l,e]),eA=e=>!d||!!ei[et(e.path)],eI=(0,r.useMemo)(()=>{let t=[],s=(e,n)=>{for(let r of es.get(e)||[])(!d||ei[et(r.path)])&&(t.push({file:r,depth:n}),"folder"===r.type&&en.has(r.path)&&s(r.path,n+1))};return s(e,0),t},[es,en,ei,d,e,et]),eD=(0,r.useCallback)(e=>eI.find(t=>t.file.path===e)?.file||null,[eI]),eL=(0,r.useCallback)(e=>{let t=eI.filter(e=>E.has(e.file.path)).map(e=>e.file);return t.length?t:e?[e]:[]},[eI,E]),eB=(0,r.useCallback)((e,t)=>{let s=eI.findIndex(t=>t.file.path===e),n=eI.findIndex(e=>e.file.path===t);if(-1===s||-1===n)return new Set([t]);let[r,l]=s<=n?[s,n]:[n,s];return new Set(eI.slice(r,l+1).map(e=>e.file.path))},[eI]),eF=(0,r.useCallback)((e,t)=>{if((0,ed.e)(),X.current?.focus({preventScroll:!0}),t?.metaKey||t?.ctrlKey){$(t=>{let s=new Set(t);return s.has(e.path)?s.delete(e.path):s.add(e.path),s}),q(e.path),V.current=e.path;return}if(t?.shiftKey&&V.current){$(eB(V.current,e.path)),q(e.path);return}$(new Set([e.path])),q(e.path),V.current=e.path,"folder"===e.type?(R(e.path),ef(e)):s?.(e.path)},[ef,s,eB]),eK=(0,r.useCallback)(t=>t?"folder"===t.type?t.path:ad(t.path):e,[e]),eO=(0,r.useCallback)(e=>{let t=eL(e);t.length&&S({files:t})},[eL]),eW=(0,r.useCallback)(async()=>{let e=C?.files||[];S(null),1===e.length?await ew(e[0]):await ej(e),$(new Set)},[C,ew,ej]),e_=(0,r.useCallback)((e,t)=>{let s=eL(e).map(e=>e.path);s.length&&F({paths:s,mode:t})},[eL]),eH=(0,r.useCallback)(async e=>{B?.paths?.length&&(await eC(B.paths,eK(e),B.mode),"cut"===B.mode&&F(null))},[B,eC,eK]),eU=(0,r.useCallback)(async(e,s)=>{if(!e.length)return;let n=0;W({total:e.length,done:0,failed:0}),await t.uploadFiles(s,e,{onConflict:(e,t)=>new Promise(s=>H({name:t||e?.name,resolve:s})),onFileDone:()=>W(e=>e?{...e,done:e.done+1}:e),onError:()=>{n+=1,W(e=>e?{...e,done:e.done+1,failed:n}:e)}}),W(e=>e&&n?e:null),H(null),await em(s),eh(s),ep()},[t,em,eh,ep]),eq=(0,r.useCallback)(async(e,t)=>{eU(await aD(e),t)},[eU]),eX=(0,r.useCallback)(()=>g(null),[]),eV=(0,r.useCallback)((e,t)=>{let s=z.current,n=s.has(t.path)?[...s]:[t.path];e.dataTransfer.setData(aX,JSON.stringify(n)),e.dataTransfer.effectAllowed="move"},[]),eJ=(0,r.useCallback)((e,t)=>{let s=aG(e);("folder"===t.type||s)&&(e.preventDefault(),e.dataTransfer.dropEffect=s?"copy":"move","folder"===t.type&&I(t.path))},[]),eG=(0,r.useCallback)(e=>{I(t=>t===e.path?null:t)},[]),eY=(0,r.useCallback)((e,t)=>{let s=aG(e);if("folder"!==t.type&&!s)return;if(e.preventDefault(),e.stopPropagation(),I(null),L(!1),s)return void eq(e.dataTransfer,eK(t));let n=aJ(e);n&&eN(n,t.path)},[eq,eK,eN]),eZ=(0,r.useCallback)(e=>{let t=w?.dir||eS(),s=[...e.target.files].map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}));e.target.value="",j(null),eU(s,t)},[w,eS,eU]),eQ=(0,r.useCallback)((e,t)=>{if(!eI.length)return;let s=eI.findIndex(e=>e.file.path===U),n=eI[Math.min(eI.length-1,Math.max(0,-1===s?0:s+e))];if(!n)return;let r=n.file.path;t&&V.current?$(eB(V.current,r)):($(new Set([r])),V.current=r),q(r),X.current?.querySelector(`[data-path="${CSS.escape(r)}"]`)?.scrollIntoView({block:"nearest"})},[eI,U,eB]),e0=(0,r.useCallback)(e=>{if(b||w||C)return;let t=eD(U),n=e.metaKey||e.ctrlKey;if(n&&"a"===e.key.toLowerCase()){e.preventDefault(),$(new Set(eI.map(e=>e.file.path))),V.current=eI[0]?.file.path||null;return}if(n&&"c"===e.key.toLowerCase()){e.preventDefault(),e_(t,"copy");return}if(n&&"x"===e.key.toLowerCase()){e.preventDefault(),e_(t,"cut");return}if(n&&"v"===e.key.toLowerCase()){e.preventDefault(),eH(t);return}switch(e.key){case"ArrowDown":e.preventDefault(),eQ(1,e.shiftKey);return;case"ArrowUp":e.preventDefault(),eQ(-1,e.shiftKey);return;case"ArrowRight":if(!t)return;e.preventDefault(),"folder"!==t.type||en.has(t.path)?eQ(1,!1):ef(t);return;case"ArrowLeft":if(!t)return;e.preventDefault(),"folder"===t.type&&en.has(t.path)?ef(t):eQ(-1,!1);return;case"Enter":if(!t)return;e.preventDefault(),tc()?(g(t),y(t.name)):"folder"===t.type?ef(t):s?.(t.path);return;case"F2":if(!t)return;e.preventDefault(),g(t),y(t.name);return;case"Delete":case"Backspace":if(!t)return;e.preventDefault(),eO(t);return;case"Escape":$(new Set),F(null);return}},[b,w,C,U,eD,eI,en,ef,s,eQ,e_,eH,eO]),e1=(e,t)=>{if(!eA(e))return null;let s="folder"===e.type,r=s&&en.has(e.path),l=E.has(e.path);return(0,n.jsx)(aA,{file:e,depth:t,isFolder:s,isExpanded:r,isLoading:s&&er.has(e.path),isActive:eP===e.path,isSelected:l,isRenaming:b?.path===e.path,isDragOver:A===e.path&&s,isCut:B?.mode==="cut"&&B.paths.includes(e.path),gitStatus:ei[et(e.path)],renameValue:b?.path===e.path?v:"",renameInputRef:Q,onRenameChange:y,onRenameSubmit:eR,onRenameCancel:eX,onToggleFolder:ef,onClick:eF,onContextMenu:e$,onTouchStart:ez,onTouchEnd:eM,onDragStart:eV,onDragOver:eJ,onDragLeave:eG,onDrop:eY,compact:c,children:s&&r&&(0,n.jsxs)("div",{children:[(es.get(e.path)||[]).map(e=>e1(e,t+1)),ea.has(e.path)&&(0,n.jsx)(aP,{depth:t+1,compact:c})]})},e.path)},e2=(0,r.useMemo)(()=>es.get(e)||[],[es,e]);(0,r.useEffect)(()=>{if(!d)return;let t=!0;return(async()=>{for(let s of Object.keys(ei)){if("folder-changed"!==ei[s])continue;let n=`${e}/${s}`;if(!es.has(n)&&(await em(n),!t))return;eh(n)}})(),()=>{t=!1}},[d,ei,e]),(0,r.useEffect)(()=>{if(!eP||!X.current)return;let e=setTimeout(()=>{let e=X.current?.querySelector(`[data-path="${CSS.escape(eP)}"]`);e?.scrollIntoView({block:"nearest"})},0);return()=>clearTimeout(e)},[eP,es]);let e5=(0,r.useMemo)(()=>au(e),[e]),e3=(e,t)=>{(0,ed.e)(),j({type:e,dir:t}),N("")};(0,r.useEffect)(()=>{if(u)return u({newFile:()=>e3("file",eS()),newFolder:()=>e3("folder",eS()),refresh:eg,collapseAll:eb,hasExpanded:en.size>0,showHidden:eo,toggleHidden:()=>ex(e=>!e)}),()=>u(null)},[u,eo,eg,eb,en.size,e]);let e4=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=et(s.path),r=await aq(t,e,n,"folder"===s.type);r?.success&&(ep(),window.dispatchEvent(new CustomEvent(O.GW)))},[e,t,et,ep]),e6="text-text-muted hover:text-text p-1 rounded hover:bg-surface-2";return(0,n.jsxs)("div",{className:"relative flex flex-col flex-1 min-h-0 text-text overflow-hidden",children:[!c&&(0,n.jsxs)("div",{style:{height:32},className:"bg-surface border-b border-border flex items-center gap-2 sticky top-0 z-10 flex-shrink-0 px-3",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),a?.()},className:"flex items-center gap-1 flex-1 min-w-0 hover:text-text",children:[(0,n.jsx)("span",{className:"text-xs uppercase tracking-wider text-text-muted font-medium truncate",children:e5||"No Workspace"}),(0,n.jsx)(el.Ay,{name:"ChevronDown",size:12,className:"text-text-muted shrink-0"})]}),(0,n.jsx)("button",{onClick:()=>e3("file",eS()),className:e6,title:"New File",children:(0,n.jsx)(el.Ay,{name:"Plus",size:14})}),(0,n.jsx)("button",{onClick:()=>e3("folder",eS()),className:e6,title:"New Folder",children:(0,n.jsx)(el.Ay,{name:"FolderOpen",size:14})}),(0,n.jsx)("button",{onClick:eg,className:e6,title:"Refresh",children:(0,n.jsx)(el.Ay,{name:"RefreshCw",size:14})}),en.size>0&&(0,n.jsx)("button",{onClick:eb,className:e6,title:x("fileExplorer.collapseAll"),children:(0,n.jsx)(el.Ay,{name:"ChevronsDownUp",size:14})}),(0,n.jsx)("button",{onClick:()=>ex(e=>!e),className:`p-1 rounded hover:bg-surface-2 ${eo?"text-text":"text-text-muted hover:text-text"}`,title:eo?"Hide hidden files":"Show hidden files",children:(0,n.jsx)(el.Ay,{name:eo?"Eye":"EyeOff",size:14})})]}),(0,n.jsx)("div",{ref:X,tabIndex:0,onKeyDown:e0,className:`flex-1 overflow-auto py-1 outline-none ${D?"ring-2 ring-inset ring-brand-500/40 bg-brand-500/5":""}`,onDragOver:e=>{e.preventDefault();let t=aG(e);e.dataTransfer.dropEffect=t?"copy":"move",t&&L(!0)},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||L(!1)},onClick:e=>{e.target===e.currentTarget&&($(new Set),R(null))},onDrop:t=>{if(t.preventDefault(),L(!1),aG(t))return void eq(t.dataTransfer,e);let s=aJ(t);s&&eN(s,e)},children:d&&!e2.some(eA)?(0,n.jsx)("div",{className:"text-text-subtle text-xs px-3 py-4 text-center",children:x("git.noChanges")}):0!==e2.length||er.has(e)?(0,n.jsxs)(n.Fragment,{children:[e2.map(e=>e1(e,0)),ea.has(e)&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted italic py-0.5 px-3",children:"Showing first 300 entries — use search for the rest."})]}):(0,n.jsx)("div",{className:"text-text-subtle text-xs px-3 py-4 text-center",children:"Empty workspace"})}),m&&(0,n.jsx)("div",{ref:f,className:"fixed z-50 menu-popover p-1 min-w-[150px] animate-in fade-in zoom-in-95 duration-100",style:{left:h.left,top:h.top},onClick:e=>e.stopPropagation(),children:(e=>{if(!e)return[];let n="folder"===e.type,r=eL(e),l=r.length>1,a=[];return!l&&n?(i&&a.push({label:x("workspaces.openHere"),icon:"Terminal",action:()=>i(e.path)}),o&&a.push({label:"Search in Folder",icon:"Search",action:()=>o(e.path)}),a.push({label:"New File",icon:"Plus",action:()=>e3("file",e.path)}),a.push({label:"New Folder",icon:"FolderOpen",action:()=>e3("folder",e.path)})):!l&&(a.push({label:"Open",icon:"File",action:()=>s?.(e.path)}),(0,O.YO)(e.path)&&a.push({label:x("editor.preview"),icon:"Eye",action:()=>s?.(e.path,{preview:!0})})),a.push({label:"Cut",icon:"Scissors",action:()=>e_(e,"cut")}),a.push({label:"Copy",icon:"Copy",action:()=>e_(e,"copy")}),B?.paths?.length&&a.push({label:"Paste",icon:"ClipboardPaste",action:()=>eH(e)}),l||(a.push({label:"Reveal in OS",icon:"FolderOpen",action:()=>t.revealInOS(e.path)}),a.push({label:"Rename",icon:"Pencil",action:()=>{g(e),y(e.name)}}),a.push({label:"Duplicate",icon:"Copy",action:()=>ek(e)}),a.push({label:"Copy Path",icon:"Copy",action:()=>eE(e.path)}),a.push({label:"Copy Relative Path",icon:"Copy",action:()=>eE(et(e.path))}),a.push({label:x("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:"EyeOff",action:()=>e4(e)})),a.push({label:l?`Delete ${r.length} items`:"Delete",icon:"Trash2",danger:!0,action:()=>eO(e)}),a})(m.file).map((e,t)=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),e.action(),p(null)},className:`w-full flex items-center gap-1.5 px-2 py-1.5 text-xs text-left hover:bg-surface-2/80 rounded-[6px] transition-colors ${e.danger?"text-red-400":"text-text"}`,children:[(0,n.jsx)(el.Ay,{name:e.icon,size:13,className:"shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.label})]},t))}),w&&(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-150",onClick:()=>j(null)}),(0,n.jsxs)("div",{className:"relative card-elev p-4 w-full max-w-sm animate-in zoom-in-95 duration-150",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text mb-2",children:"folder"===w.type?"New Folder":"New File"}),(0,n.jsxs)("p",{className:"text-xs text-text-muted mb-2 truncate",children:["in ",et(w.dir)||e5||"/"]}),(0,n.jsx)("input",{ref:ee,value:k,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key?eT(w.type):"Escape"===e.key&&j(null)},placeholder:"folder"===w.type?"folder name":"file name",className:"w-full bg-surface-3 text-text text-sm px-2 py-1.5 rounded outline-none border border-border focus:border-brand-500"}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-3",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),("folder"===w.type&&Y?G:J).current?.click()},className:"flex items-center gap-1.5 px-2 py-1.5 text-xs text-text-muted hover:text-text rounded-brand hover:bg-surface-3",title:"folder"===w.type&&Y?"Upload a folder from this computer":"Upload files from this computer",children:[(0,n.jsx)(el.Ay,{name:"Upload",size:13}),"Upload"]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),j(null)},className:"px-3 py-1.5 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand",children:"Cancel"}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),eT(w.type)},className:"px-3 py-1.5 text-sm bg-brand-500 hover:bg-brand-500/80 text-white rounded-brand",children:"Create"})]})]}),(0,n.jsx)("input",{ref:J,type:"file",multiple:!0,className:"hidden",onChange:eZ}),(0,n.jsx)("input",{ref:G,type:"file",webkitdirectory:"",className:"hidden",onChange:eZ})]}),K&&(0,n.jsx)("div",{className:"absolute bottom-0 inset-x-0 bg-surface-2 border-t border-border px-3 py-1.5 pb-safe text-[11px] text-text-muted flex items-center gap-2",children:K.failed?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-danger",children:x("fileExplorer.uploadFailedCount",{n:K.failed,total:K.total})}),(0,n.jsx)("button",{type:"button",onClick:()=>W(null),className:"ml-auto underline hover:text-text",children:x("common.close")})]}):(0,n.jsx)("span",{children:x("fileExplorer.uploadingCount",{n:Math.min(K.done+1,K.total),total:K.total})})}),_&&(0,n.jsx)(aU,{name:_.name,onResolve:e=>{_.resolve(e),H(null)}}),(0,n.jsx)(ec.A,{isOpen:!!C,onClose:()=>S(null),onConfirm:eW,title:"Delete",message:(C?.files?.length||0)>1?`Are you sure you want to delete these ${C.files.length} items?`:`Are you sure you want to delete "${C?.files?.[0]?.name}"?`,confirmText:"Delete",cancelText:"Cancel"})]})}function aZ({x:e,y:t,items:s,onClose:l}){let a=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!a.current)return;let s=a.current.getBoundingClientRect(),n=Math.min(e,window.innerWidth-s.width-8),r=Math.min(t,window.innerHeight-s.height-8);a.current.style.left=`${Math.max(8,n)}px`,a.current.style.top=`${Math.max(8,r)}px`},[e,t]),(0,r.useEffect)(()=>{let e=e=>{a.current&&!a.current.contains(e.target)&&l()},t=e=>{"Escape"===e.key&&l()},s=setTimeout(()=>{document.addEventListener("mousedown",e),document.addEventListener("contextmenu",e,!0),document.addEventListener("keydown",t)},0);return()=>{clearTimeout(s),document.removeEventListener("mousedown",e),document.removeEventListener("contextmenu",e,!0),document.removeEventListener("keydown",t)}},[l]),(0,n.jsx)("div",{ref:a,className:"fixed z-50 min-w-[180px] py-1 rounded-lg border border-border bg-surface shadow-elev animate-in fade-in",style:{left:e,top:t},onContextMenu:e=>e.preventDefault(),children:s.filter(Boolean).map((e,t)=>(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:t=>{t.stopPropagation(),e.onClick?.(),l()},className:`w-full flex items-center gap-2.5 px-3 py-1.5 text-sm text-left transition-colors ${e.disabled?"text-text-subtle cursor-not-allowed":e.danger?"text-danger hover:bg-[rgba(var(--danger-rgb),0.12)]":"text-text hover:bg-surface-2"}`,children:[e.icon&&(0,n.jsx)(e.icon,{size:14,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 truncate",children:e.label})]},e.key+t))})}let aQ={Copy:el.QR,FileText:el.iU,ExternalLink:el.Gr,Undo2:el.bE,X:el.X,EyeOff:el.X_},a0=(e,t)=>(e||"").split("\n").map(e=>e.trim()).find(t)||"",a1=(e,t)=>{let s=a0(t,e=>/files? changed/.test(e));return e("git.commitSuccess")+(s?` \xb7 ${s}`:"")},a2=(e,t)=>{if(/up.to.date/i.test(t||""))return e("git.upToDate");let s=a0(t,e=>e.includes("->"));return e("git.pushSuccess")+(s?` \xb7 ${s}`:"")},a5="changes",a3="untracked";function a4(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}function a6(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(0,t):""}function a8(e,t){if(!e)return t;let s=e.endsWith("/")||e.endsWith("\\")?"":"/";return`${e}${s}${t}`}let a9=(0,r.memo)(function({file:e,workspace:t,isUntracked:s,t:r,isTouch:l,openDiff:a,onCtxMenu:i,onDiscard:o,onStage:c}){let d=O.vs[e.status]||"text-text-muted";return a8(t,e.path),(0,n.jsxs)("div",{className:"group relative flex items-center gap-1.5 px-2 py-1 hover:bg-surface-2 cursor-pointer",onContextMenu:t=>i(e,t),onClick:()=>{(0,ed.e)(),a(e)},children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:aE({name:a4(e.path),path:e.path,type:"file"},16)}),(0,n.jsx)("span",{className:"truncate text-xs text-text",title:e.path,children:a4(e.path)}),(0,n.jsx)("span",{className:"truncate text-[11px] text-text-muted flex-1",title:a6(e.path),children:a6(e.path)}),(0,n.jsxs)("div",{className:`absolute right-[22px] top-1/2 -translate-y-1/2 flex items-center gap-0.5 pl-2 pr-1 bg-surface-2 transition-opacity ${l?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:[(0,n.jsx)("button",{type:"button",title:r(s?"common.delete":"git.discard"),onClick:t=>{t.stopPropagation(),(0,ed.e)(),o(e)},className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(el.X,{size:12})}),(0,n.jsx)("button",{type:"button",title:r("git.stage"),onClick:t=>{t.stopPropagation(),(0,ed.e)(),c(e)},className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(el.FW,{size:12})})]}),(0,n.jsx)("span",{className:`flex-shrink-0 w-4 h-4 flex items-center justify-center text-[10px] font-mono rounded bg-surface-2 ${d}`,children:e.status})]})});function a7({workspace:e,fileBus:t,onOpenFile:s,tagDiffWithRepo:l=!1}){let{t:a}=(0,eu.s)(),i=ln(),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),[p,f]=(0,r.useState)([]),[h,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(new Set([a5,a3])),[N,C]=(0,r.useState)(!1),[S,T]=(0,r.useState)(!1),[R,E]=(0,r.useState)(null),[$,z]=(0,r.useState)(!1),[M,P]=(0,r.useState)(null),[A,I]=(0,r.useState)(null),D=(0,r.useCallback)(async()=>{if(!e||!t)return;v(!0);let[s,n]=await Promise.all([t.gitStatus?.(e),t.gitBranch?.(e)]);v(!1),s?.success&&f(s.files||[]),n?.success&&(c(n.branch||""),u(n.ahead??null),m(n.behind??null))},[e,t]);(0,r.useEffect)(()=>{D()},[D]),(0,r.useEffect)(()=>{let e=()=>D(),t=["fileExplorer:fileSaved","fileExplorer:fileCreated","fileExplorer:fileDeleted","fileExplorer:fileRenamed",O.GW];return t.forEach(t=>window.addEventListener(t,e)),()=>t.forEach(t=>window.removeEventListener(t,e))},[D]);let{changes:L,untracked:B}=(0,r.useMemo)(()=>{let e=[],t=[];for(let s of p)"?"===s.status?t.push(s):e.push(s);return{changes:e,untracked:t}},[p]),F=(0,r.useCallback)(e=>{k(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),K=(0,r.useCallback)(async s=>{e&&(await t.gitAdd?.(e,[s.path]),D())},[e,t,D]),W=(0,r.useCallback)(async()=>{e&&(await t.gitAdd?.(e,["."]),D())},[e,t,D]),_=(0,r.useCallback)(async s=>{e&&(await t.gitDiscard?.(e,s.path,s.status),D())},[e,t,D]),H=(0,r.useCallback)(e=>{E(e),T(!0)},[]),U=(0,r.useCallback)(t=>{s?.(l?(0,O.n2)(t.status,e,t.path):(0,O.Dk)(t.status,t.path))},[s,l,e]),q=(0,r.useCallback)((e=!1)=>{!h.trim()||p.length&&(z(e),C(!0))},[h,p]),X=(0,r.useCallback)(async()=>{if(!e)return;w(null);let s=await t.gitAdd?.(e,["."]);if(s&&!s.success)return void w({ok:!1,text:s.error||a("git.stageFailed")});let n=await t.gitCommit?.(e,h.trim());if(!n?.success){w({ok:!1,text:n?.output||n?.error||a("git.commitFailed")}),D();return}if(b(""),!$){w({ok:!0,text:a1(a,n.output)}),D();return}let r=await t.gitPush?.(e);w(r?.success?{ok:!0,text:`${a1(a,n.output)} \xb7 ${a2(a,r.output)}`}:{ok:!1,text:r?.output||r?.error||a("git.pushFailed")}),D()},[e,t,h,$,D,a]),V=(0,r.useCallback)(async()=>{if(!e)return;v(!0),w(null);let s=await t.gitPush?.(e);v(!1),w(s?.success?{ok:!0,text:a2(a,s.output)}:{ok:!1,text:s?.output||s?.error||a("git.pushFailed")}),D()},[e,t,D,a]),J=(0,r.useCallback)(async()=>{if(!e)return;v(!0),w(null);let s=await t.gitPull?.(e);v(!1),w(s?.success?{ok:!0,text:((e,t)=>{if(/already up to date|up.to.date/i.test(t||""))return e("git.upToDate");let s=a0(t,e=>/files? changed|fast-forward/i.test(e));return e("git.pullSuccess")+(s?` \xb7 ${s}`:"")})(a,s.output)}:{ok:!1,text:s?.output||s?.error||a("git.pullFailed")}),D()},[e,t,D,a]),G=(0,r.useCallback)((e,t)=>{e.stopPropagation(),(0,ed.e)();let s=e.currentTarget.getBoundingClientRect();t({x:s.right,y:s.bottom+4})},[]),[Y,Z]=(0,r.useState)(null),Q=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),ee=(0,r.useCallback)((e,t)=>{t.preventDefault(),t.stopPropagation(),(0,ed.e)(),Z({file:e,x:t.clientX,y:t.clientY})},[]),et=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=await aq(t,e,s.path);n?.success&&(window.dispatchEvent(new CustomEvent(O.GW)),D())},[e,t,D]),es=(0,r.useCallback)(t=>{let n=a8(e,t.path);return[{key:"open",label:a("git.openFile"),icon:el.Gr,disabled:"D"===t.status,onClick:()=>s?.(n)},{key:"copyPath",label:a("files.copyPath",{defaultValue:"Copy Path"}),icon:el.Gr,onClick:()=>Q(n)},{key:"copyRel",label:a("files.copyRelPath",{defaultValue:"Copy Relative Path"}),icon:el.Gr,onClick:()=>Q(t.path)},{key:"copyName",label:a("files.copyName",{defaultValue:"Copy Filename"}),icon:el.Gr,onClick:()=>Q(a4(t.path))},{key:"addToGitignore",label:a("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:el.X_,onClick:()=>et(t)}]},[e,s,Q,et,a]),en=(t,s,r,l)=>{let o=j.has(t);return(0,n.jsxs)("div",{className:"border-t border-border",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),F(t)},className:"w-full flex items-center gap-1 px-2 py-1 hover:bg-surface-2 text-left",children:[o?(0,n.jsx)(el.yQ,{size:12,className:"text-text-subtle"}):(0,n.jsx)(el.c_,{size:12,className:"text-text-subtle"}),(0,n.jsx)("span",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:s}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 ml-auto rounded-brand bg-surface-3 text-text-muted",children:r.length})]}),o&&r.map(t=>(0,n.jsx)(a9,{file:t,workspace:e,isUntracked:l,t:a,isTouch:i,openDiff:U,onCtxMenu:ee,onDiscard:H,onStage:K},`${t.status}-${t.path}`))]})};return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text",children:[(0,n.jsxs)("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(el.Zr,{size:14,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-xs text-text truncate flex-1",children:o||"—"}),d>0&&(0,n.jsxs)("span",{className:"text-[10px] font-medium px-1.5 rounded-brand bg-brand-500/15 text-brand-500",children:["↑",d]}),x>0&&(0,n.jsxs)("span",{className:"text-[10px] font-medium px-1.5 rounded-brand bg-surface-3 text-text-muted",children:["↓",x]}),(0,n.jsx)("button",{type:"button",title:a("common.refresh"),onClick:()=>{(0,ed.e)(),D()},className:"p-1 text-text-muted hover:text-text",children:(0,n.jsx)(el.e9,{size:12,className:g?"animate-spin":""})}),(0,n.jsx)("button",{type:"button",title:a("git.gitActions"),onClick:e=>G(e,I),className:"p-1 text-text-muted hover:text-text",children:(0,n.jsx)(el.a4,{size:12})})]}),(0,n.jsx)("textarea",{value:h,onChange:e=>b(e.target.value),rows:2,placeholder:a("git.commitPlaceholder"),className:"w-full bg-surface-2 border border-border rounded-brand px-2 py-1 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500 resize-none"}),(0,n.jsxs)("div",{className:`flex items-stretch h-7 rounded-brand overflow-hidden bg-brand-500 text-white transition-opacity ${!h.trim()||!p.length?"opacity-40":""}`,children:[(0,n.jsx)("button",{type:"button",disabled:!h.trim()||!p.length,onClick:()=>{(0,ed.e)(),q(!1)},className:"flex-1 text-xs hover:bg-black/10 disabled:cursor-not-allowed transition-colors",children:a("git.commit")}),(0,n.jsx)("span",{className:"w-px my-1.5 bg-white/25"}),(0,n.jsx)("button",{type:"button",title:a("git.gitActions"),disabled:!h.trim()||!p.length,onClick:e=>G(e,P),className:"px-1.5 flex items-center hover:bg-black/10 disabled:cursor-not-allowed transition-colors",children:(0,n.jsx)(el.yQ,{size:12})})]}),y&&(0,n.jsx)("div",{className:`text-[11px] leading-snug break-words rounded-brand px-2 py-1 ${y.ok?"text-[var(--success)] bg-[rgba(var(--success-rgb),0.1)]":"text-[var(--danger)] bg-[rgba(var(--danger-rgb),0.1)]"}`,children:y.text})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[en(a5,a("git.changes"),L,!1),en(a3,a("git.untracked"),B,!0)]}),(0,n.jsx)(ec.A,{isOpen:N,onClose:()=>C(!1),onConfirm:X,title:a("git.stageAllConfirmTitle"),message:a("git.stageAllConfirmMessage"),confirmText:a("git.stageAndCommit"),cancelText:a("common.cancel")}),(0,n.jsx)(ec.A,{isOpen:S,onClose:()=>{T(!1),E(null)},onConfirm:()=>{R&&_(R),E(null)},title:a("git.discardConfirmTitle"),message:R?"?"===R.status?a("git.discardConfirmDelete",{name:a4(R.path)}):a("git.discardConfirmDiscard",{name:a4(R.path)}):"",confirmText:a("git.discard"),cancelText:a("common.cancel")}),Y&&(0,n.jsx)(aZ,{x:Y.x,y:Y.y,items:es(Y.file),onClose:()=>Z(null)}),M&&(0,n.jsx)(aZ,{x:M.x,y:M.y,items:[{key:"commitPush",label:a("git.commitAndPush"),icon:el.Do,disabled:!h.trim()||!p.length,onClick:()=>q(!0)}],onClose:()=>P(null)}),A&&(0,n.jsx)(aZ,{x:A.x,y:A.y,items:[{key:"push",label:a("git.push"),icon:el.Do,onClick:V},{key:"pull",label:a("git.pull"),icon:el.yd,onClick:J},{key:"stageAll",label:a("git.stageAll"),icon:el.FW,disabled:!p.length,onClick:W}],onClose:()=>I(null)})]})}let ie=[{key:"files",icon:el.sv,labelKey:"workspaces.tabFiles"},{key:"git",icon:el.Zr,labelKey:"workspaces.tabGit"},{key:"trees",icon:el.dx,labelKey:"workspaces.tabTrees"}].filter(e=>"trees"!==e.key);function it({results:e,loading:t,query:s,searchDir:l,workspace:a,onOpen:i}){let{t:o}=(0,eu.s)(),[c,d]=(0,r.useState)(()=>new Set);if(!s||s.length<2){let e=l?l.split("/").pop():"";return(0,n.jsxs)("div",{className:"p-6 text-xs text-text-subtle text-center flex flex-col items-center gap-2",children:[(0,n.jsx)(el.vj,{size:20,className:"opacity-40"}),(0,n.jsx)("span",{children:e?`Type at least 2 characters to search in ${e}`:o("files.searchPlaceholder")})]})}if(t)return(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle text-center",children:o("files.searching")});if(!e.length)return(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle text-center",children:o("files.noFilesFound")});let u=e.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[(0,n.jsxs)("p",{className:"px-2 py-1 text-[10px] text-text-muted border-b border-border-subtle sticky top-0 bg-surface z-[1]",children:[u," results in ",e.length," files"]}),e.map(e=>{let t=e.path.split("/").pop(),s=e.path.slice(0,e.path.length-t.length).replace(a,"").replace(/^\//,""),r=!c.has(e.path);return(0,n.jsxs)("div",{className:"border-b border-border-subtle",children:[(0,n.jsxs)("button",{onClick:()=>{let t;(0,ed.e)(),t=e.path,d(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},className:"w-full px-2 py-1 flex items-center gap-1.5 hover:bg-surface-2 transition-colors text-left",title:e.path,children:[(0,n.jsx)(el.c_,{size:11,className:`flex-shrink-0 text-text-subtle transition-transform duration-150 ${r?"rotate-90":""}`}),(0,n.jsx)(el.ZH,{size:12,className:"text-text-subtle flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate text-xs text-text",children:t}),(0,n.jsx)("span",{className:"truncate text-[10px] text-text-subtle flex-1",children:s}),(0,n.jsx)("span",{className:"text-[9px] px-1 rounded-brand bg-surface-3 text-text-muted flex-shrink-0",children:e.matches.length})]}),r&&e.matches.map((t,s)=>{let r=Math.max(0,Math.min(t.column-1-(t.contextStart||0),t.lineText.length)),l=Math.min(t.lineText.length,r+(t.matchLength||0));return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),i(e.path,t)},className:"w-full px-2 pl-6 pr-2 py-0.5 flex items-baseline gap-2 hover:bg-surface-2 transition-colors text-left",title:t.lineText,children:[(0,n.jsx)("span",{className:"text-[10px] text-text-subtle font-mono flex-shrink-0",children:t.line}),(0,n.jsxs)("span",{className:"text-[11px] font-mono text-text-muted truncate",children:[t.lineText.slice(0,r),(0,n.jsx)("span",{className:"bg-brand-500/30 text-text rounded-sm",children:t.lineText.slice(r,l)}),t.lineText.slice(l)]})]},`${e.path}-${s}`)})]},e.path)})]})}function is({root:e,multiple:t,isOpen:s,onToggle:r,onRemove:l=null,removeLabel:a="",children:i}){return t?(0,n.jsxs)("div",{className:`flex flex-col min-h-0 ${s?"flex-1":"flex-shrink-0"}`,children:[(0,n.jsxs)("div",{className:"group px-2 py-1 flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-text-muted bg-surface-2/40 hover:bg-surface-2 border-b border-border-subtle transition-colors",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),r()},className:"flex-1 min-w-0 flex items-center gap-1.5 hover:text-text transition-colors",title:e.path,children:[(0,n.jsx)(el.c_,{size:11,className:`flex-shrink-0 transition-transform duration-150 ${s?"rotate-90":""}`}),(0,n.jsx)("span",{className:"truncate flex-1 text-left",children:e.branch||e.name||e.path.split("/").pop()}),!e.isMain&&(0,n.jsx)(el.dx,{size:10,className:"flex-shrink-0 opacity-60"})]}),l&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),l()},title:a,className:"p-0.5 shrink-0 hover:text-red-500 transition-colors",children:(0,n.jsx)(el.TB,{size:11})})]}),s&&(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:i})]}):(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:i})}function ir({icon:e,label:t,onClick:s,active:r,disabled:l,spinning:a}){return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s?.()},disabled:l,title:t,className:`p-2 sm:p-1 rounded-[3px] hover:bg-surface-2 transition-colors disabled:opacity-40 ${r?"text-brand-500":"text-text-muted hover:text-text"}`,children:(0,n.jsx)(e,{size:16,className:`sm:w-[13px] sm:h-[13px] ${a?"animate-spin":""}`})})}function il({active:e,onClick:t,title:s,children:r}){return(0,n.jsx)("button",{type:"button",title:s,onClick:()=>{(0,ed.e)(),t()},className:`px-1 h-5 text-[10px] font-medium rounded-[3px] border transition-colors shrink-0 ${e?"bg-brand-500 text-white border-brand-500":"bg-transparent text-text-muted border-transparent hover:bg-surface-2"}`,children:r})}function ia({onClick:e,children:t}){return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),e()},className:"w-full px-3 py-1.5 text-[11px] text-text-subtle hover:text-text hover:bg-surface-2 transition-colors text-left",children:t})}function ii({repo:e,changedCount:t=0,isOpen:s,onToggle:r,onHide:l,children:a}){let{t:i}=(0,eu.s)();return(0,n.jsxs)("div",{className:"border-b border-border-subtle last:border-0",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),r()},className:"group/repo w-full sticky top-0 z-10 px-2 py-1 flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-text-muted hover:text-text bg-surface-3 border-b border-border-subtle transition-colors",children:[(0,n.jsx)(el.c_,{size:11,className:`flex-shrink-0 transition-transform duration-150 ${s?"rotate-90":""}`}),(0,n.jsx)("span",{className:"truncate flex-1 text-left",title:e.relPath||e.name,children:e.relPath||e.name}),e.branch&&(0,n.jsx)("span",{className:"text-text-subtle normal-case tracking-normal truncate max-w-[45%]",title:e.branch,children:e.branch}),t>0&&(0,n.jsx)("span",{className:"px-1 rounded-[2px] bg-brand-500/15 text-brand-500 normal-case tracking-normal flex-shrink-0",children:t}),l&&(0,n.jsx)("span",{role:"button",tabIndex:-1,onClick:e=>{e.stopPropagation(),(0,ed.e)(),l()},className:"p-0.5 text-text-subtle hover:text-text flex-shrink-0 opacity-100 sm:opacity-0 sm:group-hover/repo:opacity-100 transition-opacity",title:i("workspaces.hideRepo"),children:(0,n.jsx)(el.X_,{size:11})})]}),s&&a]})}let io=(0,r.memo)(function({workspacePath:e,filesRoot:t=null,cwdHint:s=null,fileBus:l,activeFile:a,tab:i,onTabChange:o,width:c,onResize:d,onClose:u,onOpenFile:x,onNewTerminal:m,onAddWorkspace:p,onOpenFiles:f,homeDir:h,changedPerRepo:b={},hiddenRepos:g=[],onHiddenReposChange:v,isDesktop:y=!0}){let{t:w}=(0,eu.s)(),j=l||en.getState(),k="trees"===i?"git":i,{repos:N,refresh:C,scanning:S,deep:T,scanDeeper:R}=function(e,t){let[s,n]=(0,r.useState)([]),[l,a]=(0,r.useState)(!1),i=t||en.getState(),[o,c]=(0,r.useState)(!1),d=(0,r.useCallback)(async(t,s)=>{if(!e||!i?.gitScanRepos)return;a(!0),t&&await i.gitRefreshRepos?.(e);let r=s?eJ.Tk.deepMaxDepth:eJ.Tk.maxDepth,l=await i.gitScanRepos(e,r,t);a(!1),n(l?.success&&l.repos||[])},[e,i]);return(0,r.useEffect)(()=>{let e=setTimeout(()=>void d(!1,o),0);return()=>clearTimeout(e)},[d,o]),{repos:s,refresh:(0,r.useCallback)(()=>d(!0,o),[d,o]),scanning:l,deep:o,scanDeeper:(0,r.useCallback)(()=>c(!0),[])}}(e,j),E=t||e,{roots:$,refresh:z}=function(e,t){let[s,n]=(0,r.useState)([]),l=t||en.getState(),a=(0,r.useCallback)(async()=>{if(!e||!l?.gitWorktreeList)return n([]);let t=await l.gitWorktreeList(e);if(!t?.success||!t.worktrees?.length)return n([{path:e,branch:null,name:ao(e)}]);n(t.worktrees.map(e=>({path:e.path,branch:e.branch,name:ao(e.path),isMain:e.isMain})))},[e,l]);return(0,r.useEffect)(()=>{let e=setTimeout(()=>void a(),0);return()=>clearTimeout(e)},[a]),{roots:s,refresh:a}}(E,j),M=()=>{C(),z()},{branch:P}=n8(e,j),A=(0,r.useRef)({path:null,branch:null});(0,r.useEffect)(()=>{let t=A.current;A.current={path:e,branch:P},t.path===e&&null!==t.branch&&t.branch!==P&&(C(),z(),window.dispatchEvent(new Event(O.GW)))},[P,e]);let[I,D]=(0,r.useState)({forWorkspace:e,showClean:!1,openRepo:null}),L=I.forWorkspace===e?I:{showClean:!1,openRepo:null},B=L.showClean,F=L.openRepo,K=new Set(g),W=e=>b[e.path]??e.changedCount??0,_=t=>!t.relPath||t.path===e,H=N.filter(e=>!K.has(e.path)),U=H.filter(e=>W(e)>0).reduce((e,t)=>e+W(t),0),q=B?H:H.filter(e=>W(e)>0||_(e)),X=B?0:H.length-q.length,V=N.length-H.length,J=F??(1===q.length?q[0].path:null),G=!y||c>=eJ.Ds.min,[Y,Z]=(0,r.useState)(null),[Q,ee]=(0,r.useState)(null),[et,es]=(0,r.useState)(null),[er,ea]=(0,r.useState)(null),ei=$.find(e=>e.isMain)?.path||e,eo=async e=>{es(null);let t=await j.gitWorktreeRemove(ei,e.path,{probe:!0,deleteBranch:e.branch||void 0});if(!t?.success)return es(t?.error||"Probe failed");ee({root:e,sessions:t.sessions||[],branchMerged:t.branchMerged})},ex=async(e,t=!1)=>{es(null),ea(null);let s=await j.gitWorktreeRemove(ei,e.path,{confirmed:!0,force:t,deleteBranch:e.branch||void 0});return!s?.success&&/use --force/i.test(s?.error||"")?ee({root:e,dirty:!0}):(ee(null),s?.success)?void(s.branchKept&&ea(e.branch),M()):es(s?.error||"Remove failed")},em=s||E,ep=(0,r.useMemo)(()=>{let e=$.filter(e=>em===e.path||em?.startsWith(`${e.path}/`));return e.length?e.sort((e,t)=>t.path.length-e.path.length)[0].path:($.find(e=>e.isMain)||$[0])?.path||E},[$,em,E]),[ef,eh]=(0,r.useState)({forProbe:null,path:null}),eb=ef.forProbe===em?ef.path:ep,[eg,ev]=(0,r.useState)({forRoot:null,searchDir:null,show:!1,query:"",results:[],loading:!1}),[ey,ew]=(0,r.useState)({caseSensitive:!1,wholeWord:!1,regex:!1}),ej=eg.forRoot===E?eg:{show:!1,searchDir:null,query:"",results:[],loading:!1},ek=(0,r.useRef)(null),eN=(0,r.useCallback)(()=>{ev({forRoot:null,searchDir:null,show:!1,query:"",results:[],loading:!1})},[]),eC=(0,r.useCallback)(e=>{ev({forRoot:E,searchDir:e,show:!0,query:"",results:[],loading:!1})},[E]),eS=(0,r.useCallback)(()=>{ev(e=>{let t={...e,searchDir:null};return e.query&&e.query.length>=2&&(t.loading=!0,j.searchInFiles(E,e.query,ey).then(e=>{ev(t=>t.loading?{...t,results:e.success?e.results:[],loading:!1}:t)})),t})},[j,E,ey]),eT=(0,r.useCallback)(e=>{if(ev(t=>({...t,query:e})),ek.current&&clearTimeout(ek.current),!e||e.length<2)return void ev(e=>({...e,results:[],loading:!1}));ev(e=>({...e,loading:!0}));let t=ej.searchDir||E;ek.current=setTimeout(async()=>{let s=await j.searchInFiles(t,e,ey);ev(t=>t.query===e&&t.loading?{...t,results:s.success?s.results:[],loading:!1}:t)},300)},[j,E,ej.searchDir,ey]),eR=(0,r.useCallback)(e=>{ev(t=>{if(!t.query||t.query.length<2)return t;let s={...t,loading:!0};return j.searchInFiles(t.searchDir||E,t.query,e).then(e=>{ev(t=>t.loading?{...t,results:e.success?e.results:[],loading:!1}:t)}),s})},[j,E]),eE=e=>{let t={...ey,[e]:!ey[e]};ew(t),eR(t)};return(0,r.useEffect)(()=>()=>{ek.current&&clearTimeout(ek.current)},[]),(0,n.jsxs)("div",{className:`h-full flex flex-col terminal-sidebar-bg border-l border-border-subtle relative shrink ${y?"":"pb-safe"}`,style:y?{width:c,flexBasis:c,minWidth:eJ.Ds.min}:void 0,children:[(0,n.jsxs)("div",{className:`h-11 ${sZ} pl-1 pr-0.5 flex items-stretch gap-0 border-b border-border-subtle flex-shrink-0`,children:[ie.map(({key:e,icon:t,labelKey:s})=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),o(e)},className:`px-3 sm:px-2 flex items-center justify-center gap-1 text-[11px] border-b-2 -mb-px transition-colors ${k===e?"text-text border-brand-500":"text-text-muted border-transparent hover:text-text"}`,title:w(s),children:[(0,n.jsx)(t,{size:18,className:"sm:w-[15px] sm:h-[15px]"}),G&&(0,n.jsx)("span",{children:w(s)}),"git"===e&&U>0&&(0,n.jsx)("span",{className:"min-w-[14px] h-[14px] px-[4px] rounded-full bg-brand-500 text-white text-[9px] font-semibold flex items-center justify-center leading-none",children:U>99?"99+":U})]},e)),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 sm:gap-0.5",children:[(0,n.jsx)(ir,{icon:el.e9,label:w("workspaces.refreshRepos"),onClick:()=>{M(),Y?.refresh?.()},disabled:S,spinning:S}),u&&(0,n.jsx)(ir,{icon:el.X,label:w("common.close"),onClick:u})]})]}),"files"===k&&e&&(0,n.jsx)("div",{className:`${ej.show?"py-1":`h-11 ${sZ}`} px-2 flex items-center gap-1.5 border-b border-border-subtle flex-shrink-0`,children:ej.show?(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 gap-1 py-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)(el.vj,{size:14,className:"text-text-subtle shrink-0"}),(0,n.jsx)("input",{type:"text",value:ej.query,onChange:e=>eT(e.target.value),onKeyDown:e=>{"Escape"===e.key&&eN()},placeholder:ej.searchDir?`Search in ${ej.searchDir.split("/").pop()}…`:w("files.searchPlaceholder"),className:"flex-1 min-w-0 w-0 bg-transparent text-xs text-text placeholder-text-subtle focus:outline-none",autoFocus:!0}),ej.loading?(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-brand-500 shrink-0"}):ej.query?(0,n.jsx)("button",{type:"button",onClick:()=>eT(""),className:"p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(el.X,{size:12})}):null,(0,n.jsx)(ir,{icon:el.X,label:w("common.close"),onClick:eN})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 pl-0.5",children:[(0,n.jsx)(il,{active:ey.caseSensitive,onClick:()=>eE("caseSensitive"),title:"Match Case",children:"Aa"}),(0,n.jsx)(il,{active:ey.wholeWord,onClick:()=>eE("wholeWord"),title:"Whole Word",children:"ab"}),(0,n.jsx)(il,{active:ey.regex,onClick:()=>eE("regex"),title:"Regex",children:".*"})]})]}):(0,n.jsxs)(n.Fragment,{children:[Y&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ir,{icon:el.FW,label:w("files.newFile"),onClick:Y.newFile}),(0,n.jsx)(ir,{icon:el.JU,label:w("files.newFolder"),onClick:Y.newFolder})]}),(0,n.jsx)(ir,{icon:el.vj,label:w("files.searchFiles"),onClick:()=>{if(ej.show)return eN();ev({forRoot:E,searchDir:null,show:!0,query:"",results:[],loading:!1})},active:ej.show}),(0,n.jsx)("div",{className:"flex-1"}),Y?.hasExpanded&&(0,n.jsx)(ir,{icon:el.WE,label:w("fileExplorer.collapseAll"),onClick:Y.collapseAll}),Y&&(0,n.jsx)(ir,{icon:Y.showHidden?el.kU:el.X_,label:w("files.toggleHidden"),onClick:Y.toggleHidden,active:Y.showHidden}),f&&(0,n.jsx)(ir,{icon:el.Gr,label:w("workspaces.openFullFiles"),onClick:f})]})}),"files"===k&&e&&ej.show&&ej.searchDir&&(0,n.jsxs)("div",{className:"px-3 py-1 bg-surface-3/40 border-b border-border-subtle flex items-center justify-between text-[11px] text-text-muted flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)(el.vd,{size:12,className:"text-yellow-500/80 shrink-0"}),(0,n.jsx)("span",{className:"text-text-subtle shrink-0",children:"Folder:"}),(0,n.jsx)("span",{className:"font-medium text-text truncate max-w-[150px]",title:ej.searchDir,children:ej.searchDir.split("/").pop()})]}),(0,n.jsx)("button",{type:"button",onClick:eS,className:"text-brand-500 hover:text-brand-400 hover:underline shrink-0 text-[11px] ml-2",children:"Search all"})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:e?"files"===k?ej.show?(0,n.jsx)(it,{results:ej.results,loading:ej.loading,query:ej.query,searchDir:ej.searchDir,workspace:E,onOpen:(e,t)=>x?.(e,{line:t?.line,column:t?.column})}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(et||er)&&(0,n.jsxs)("div",{className:"px-3 py-1.5 border-b border-border-subtle text-[11px]",children:[et&&(0,n.jsx)("p",{className:"text-red-500 break-words whitespace-pre-wrap",children:et}),er&&(0,n.jsx)("p",{className:"text-text-muted break-words",children:w("workspaces.worktreeBranchKept",{branch:er})})]}),$.map(e=>(0,n.jsx)(is,{root:e,multiple:$.length>1,isOpen:1===$.length||eb===e.path,onToggle:()=>eh({forProbe:em,path:eb===e.path?null:e.path}),onRemove:e.isMain?null:()=>{(0,ed.e)(),eo(e)},removeLabel:w("workspaces.removeWorktree"),children:(0,n.jsx)(aY,{workspace:e.path,fileBus:j,activeFile:a,onOpenFile:x,onNewTerminal:m,onSearchFolder:eC,compact:!0,onActions:e.path===eb||1===$.length?Z:void 0})},e.path))]}):"git"===k?(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[q.map(t=>(0,n.jsx)(ii,{repo:t,changedCount:W(t),isOpen:J===t.path,onToggle:()=>{let s;return s=J===t.path?"":t.path,D({...L,forWorkspace:e,openRepo:s})},onHide:v&&!_(t)?()=>{let e;return e=t.path,v?.([...g,e])}:null,children:(0,n.jsx)(a7,{workspace:t.path,fileBus:j,onOpenFile:x,tagDiffWithRepo:!0})},t.path)),!q.length&&!S&&(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle italic",children:B?w("workspaces.emptyWorkspace"):w("git.noChanges")}),(X>0||V>0||!T)&&(0,n.jsxs)("div",{className:"border-t border-border-subtle mt-1",children:[X>0&&(0,n.jsx)(ia,{onClick:()=>D({...L,forWorkspace:e,showClean:!0}),children:w("workspaces.showCleanRepos",{count:X})}),V>0&&(0,n.jsx)(ia,{onClick:()=>v?.([]),children:w("workspaces.showHiddenRepos",{count:V})}),!T&&(0,n.jsx)(ia,{onClick:R,children:w("workspaces.scanDeeper")})]})]}):null:(0,n.jsxs)("div",{className:"p-4 flex flex-col items-center gap-2 text-center",children:[(0,n.jsx)(el.vd,{size:22,className:"text-text-subtle"}),(0,n.jsx)("p",{className:"text-xs text-text-subtle",children:w("workspaces.emptyWorkspace")}),p&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),p()},className:"mt-1 px-2 py-1 text-[11px] text-brand-500 bg-brand-500/10 hover:bg-brand-500/20 rounded-[3px] transition-colors",children:w("workspaces.selectFolder")})]})}),(0,n.jsx)(ec.A,{isOpen:!!Q,onClose:()=>ee(null),onConfirm:()=>{(0,ed.e)(),ex(Q.root,!!Q.dirty)},title:w("workspaces.removeWorktree"),message:Q?Q.dirty?w("workspaces.worktreeDirty"):[w("workspaces.removeWorktreeFolder",{path:Q.root.path}),Q.root.branch&&w(!0===Q.branchMerged?"workspaces.removeWorktreeBranchDelete":!1===Q.branchMerged?"workspaces.removeWorktreeBranchKeep":"workspaces.removeWorktreeBranch",{branch:Q.root.branch}),Q.sessions?.length?w("workspaces.removeWorktreeSessions",{count:Q.sessions.length,names:Q.sessions.map(e=>e.name).join(", ")}):null].filter(Boolean).join("\n"):""}),y&&(0,n.jsx)("div",{onPointerDown:e=>eV(e,{startWidth:c,axis:-1,onWidth:e=>d?.(e)}),className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})]})});function ic(e){return e?e<1024?`${e}B`:e<1048576?`${(e/1024).toFixed(1)}KB`:`${(e/1048576).toFixed(1)}MB`:""}function id({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!0),[x,m]=(0,r.useState)(1),[p,f]=(0,r.useState)({x:0,y:0}),[h,b]=(0,r.useState)(0),g=(0,r.useRef)(null),v=(0,r.useRef)(null),y=(0,r.useRef)(null),w=(0,r.useRef)(null),j=(0,r.useRef)(null),k=(0,r.useRef)(null),N=(0,r.useRef)(0);(0,r.useEffect)(()=>{let s=!1,n=[],r="";u(!0),c(""),l(""),i(null),m(1),f({x:0,y:0}),b(0),y.current=null,w.current&&(URL.revokeObjectURL(w.current),w.current=null);let a=e.toLowerCase();if(a.endsWith(".tif")||a.endsWith(".tiff"))return t.readMedia(e).then(e=>{s||(e.success?(l(e.dataUrl),i({size:e.originalSize||e.size,width:e.width,height:e.height,scaled:e.scaled,originalWidth:e.originalWidth,originalHeight:e.originalHeight})):c(e.error||"Failed to load image"),u(!1))}),()=>{s=!0};let o=t.streamMedia(e,{onMeta:e=>{s||(r=e.mime||"image/*",i({size:e.size,width:e.width,height:e.height,scaled:e.scaled,originalWidth:e.originalWidth,originalHeight:e.originalHeight}))},onChunk:e=>{s||n.push(e)},onDone:()=>{if(s)return;let e=new Blob(n,{type:r});if(e.size>O.W5){y.current=e,b(e.size),u(!1);return}w.current=URL.createObjectURL(e),l(w.current),u(!1)},onError:e=>{s||(c(e.message||"Failed to load image"),u(!1))}});return()=>{s=!0,o?.()}},[e,t]),(0,r.useEffect)(()=>()=>{w.current&&URL.revokeObjectURL(w.current)},[]);let C=(0,r.useCallback)((e,t,s)=>{let n=v.current,r=g.current;if(!n||!r)return{x:e,y:t};let l=r.clientWidth,a=r.clientHeight,i=n.clientWidth*s,o=n.clientHeight*s,c=Math.max(0,(i-l)/2),d=Math.max(0,(o-a)/2);return{x:Math.max(-c,Math.min(c,e)),y:Math.max(-d,Math.min(d,t))}},[]),S=(0,r.useCallback)(()=>{m(1),f({x:0,y:0})},[]),T=(0,r.useCallback)((e,t,s)=>{m(n=>{let r=Math.max(.2,Math.min(8,n*e));if(r===n)return n;if(null!=t&&null!=s){let e=g.current;if(e){let l=e.clientWidth/2,a=e.clientHeight/2,i=t-l,o=s-a;f(e=>C((e.x-i)*(r/n)+i,(e.y-o)*(r/n)+o,r))}}else f(e=>C(e.x,e.y,r));return r})},[C]),R=(e,t)=>Math.hypot(e.clientX-t.clientX,e.clientY-t.clientY),E=(0,r.useCallback)(e=>{if(2===e.touches.length)k.current=null,j.current={dist:R(e.touches[0],e.touches[1]),scale:x,pos:p};else if(1===e.touches.length){let t=Date.now();if(t-N.current<300){x>1.01?S():(m(2),f({x:0,y:0})),N.current=0,k.current=null;return}N.current=t,x>1.01&&(k.current={x:e.touches[0].clientX,y:e.touches[0].clientY,pos:p})}},[x,p,S]),$=(0,r.useCallback)(e=>{if(2===e.touches.length&&j.current){e.preventDefault();let t=R(e.touches[0],e.touches[1]),s=Math.max(.2,Math.min(8,j.current.scale*(t/j.current.dist)));m(s),f(e=>C(e.x,e.y,s))}else if(1===e.touches.length&&k.current){e.preventDefault();let t=e.touches[0],s=t.clientX-k.current.x,n=t.clientY-k.current.y;f(C(k.current.pos.x+s,k.current.pos.y+n,x))}},[x,C]),z=(0,r.useCallback)(e=>{e.touches.length<2&&(j.current=null),0===e.touches.length&&(k.current=null)},[]),M=(0,r.useCallback)(e=>{e.preventDefault();let t=e.deltaY<0?1.1:1/1.1,s=g.current?.getBoundingClientRect();T(t,s?e.clientX-s.left:null,s?e.clientY-s.top:null)},[T]);if(d)return(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(el.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading image..."})]});if(o)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:o});if(h)return(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-text-muted px-6 text-center",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-text truncate max-w-full",title:e,children:e.split("/").pop()}),(0,n.jsxs)("span",{className:"text-xs",children:[ic(h)," — decoding an image this large can crash mobile Safari."]}),(0,n.jsx)("button",{onClick:()=>{let e=y.current;e&&(w.current=URL.createObjectURL(e),l(w.current),b(0))},className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-surface-3 text-text text-sm",children:"Open anyway"})]});let P=a?.width&&a?.height?`${a.width}\xd7${a.height}`:"",A=a?.scaled&&a?.originalWidth&&a?.originalWidth!==a?.width;return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-3 py-1.5 flex items-center gap-2 text-xs text-text-muted",children:[(0,n.jsx)("span",{className:"truncate flex-1",title:e,children:e.split("/").pop()}),a?.size?(0,n.jsx)("span",{className:"text-text-subtle",children:ic(a.size)}):null,P?(0,n.jsxs)("span",{className:"text-text-subtle",children:[P,A?" ↓":""]}):null,(0,n.jsx)("button",{onClick:()=>T(1/1.2),className:"px-2 hover:bg-surface-2 rounded",children:"−"}),(0,n.jsxs)("span",{className:"w-12 text-center",children:[Math.round(100*x),"%"]}),(0,n.jsx)("button",{onClick:()=>T(1.2),className:"px-2 hover:bg-surface-2 rounded",children:"+"}),(0,n.jsx)("button",{onClick:S,className:"px-2 hover:bg-surface-2 rounded",children:"Reset"})]}),(0,n.jsx)("div",{ref:g,className:"flex-1 min-h-0 overflow-hidden flex items-center justify-center bg-[repeating-conic-gradient(#0001_0%_25%,transparent_0%_50%)] bg-[length:20px_20px] touch-none",onTouchStart:E,onTouchMove:$,onTouchEnd:z,onWheel:M,children:(0,n.jsx)("img",{ref:v,src:s,alt:e,draggable:!1,onLoad:e=>i(t=>({...t,width:e.target.naturalWidth,height:e.target.naturalHeight})),style:{transform:`translate(${p.x}px, ${p.y}px) scale(${x})`,transformOrigin:"center",willChange:"transform"},className:"max-w-full max-h-full object-contain select-none"})})]})}function iu({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(""),[o,c]=(0,r.useState)(0),[d,u]=(0,r.useState)(""),[x,m]=(0,r.useState)(!0);if((0,r.useEffect)(()=>{let s=!1,n=null,r=null,a=null,o=null,d=[],x=!1;m(!0),u(""),l(""),i(""),c(0);let p=!1,f="",h=()=>{if(!s&&!p&&o&&!o.updating){if(d.length)return void o.appendBuffer(d.shift());if(x&&r&&"open"===r.readyState)try{r.endOfStream()}catch{}}};return n=t.streamMedia(e,{onMeta:({mime:e,size:t})=>{if(!s){if(i(e),c(t),!("u">typeof MediaSource&&MediaSource.isTypeSupported(e))){p=!0,f=e;return}r=new MediaSource,l(a=URL.createObjectURL(r)),m(!1),r.addEventListener("sourceopen",()=>{s||((o=r.addSourceBuffer(e)).addEventListener("updateend",h),h())})}},onChunk:e=>{!s&&(d.push(e),p||h())},onDone:()=>{if(!s)if(p){let e=new Blob(d,{type:f||"application/octet-stream"});l(a=URL.createObjectURL(e)),m(!1)}else x=!0,h()},onError:e=>{s||(u(e.message||"Stream error"),m(!1))}}),()=>{s=!0,n?.(),a&&URL.revokeObjectURL(a);try{r&&"open"===r.readyState&&r.endOfStream()}catch{}}},[e,t]),x)return(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(el.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading media..."})]});if(d)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:d});let p=a.startsWith("video/"),f=e.split("/").pop();return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-3 py-1.5 flex items-center gap-2 text-xs text-text-muted",children:[(0,n.jsx)("span",{className:"truncate flex-1",title:e,children:f}),o?(0,n.jsx)("span",{className:"text-text-subtle",children:o?o<1024?`${o}B`:o<1048576?`${(o/1024).toFixed(1)}KB`:`${(o/1048576).toFixed(1)}MB`:""}):null]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto flex items-center justify-center bg-black/30",children:p?(0,n.jsx)("video",{src:s,controls:!0,className:"max-h-full max-w-full"}):(0,n.jsx)("audio",{src:s,controls:!0,className:"w-full max-w-md"})})]})}function ix({filePath:e,fileBus:t}){let[l,a]=(0,r.useState)(!0),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)([]),[u,x]=(0,r.useState)(0),[m,p]=(0,r.useState)([]),f=(0,r.useRef)(null),h=(0,r.useRef)(null),b=(0,r.useRef)(null);if((0,r.useEffect)(()=>{let n=!1,r=null,l=[],i=(0,O.$b)(e);a(!0),o(""),d([]),x(0),p([]),h.current=null,f.current&&(f.current.innerHTML="");let c=async e=>{try{if(i){let{renderAsync:t}=await s.e(910).then(s.bind(s,80910));if(n||!f.current){n||a(!1);return}for(let s of(await t(new Blob([e]),f.current,void 0,{inWrapper:!0,renderAltChunks:!1}),f.current.querySelectorAll("a[href]"))){let e=s.getAttribute("href")||"";/^(https?:|mailto:|#)/i.test(e.trim())||s.removeAttribute("href")}n||a(!1)}else{let t=await Promise.all([s.e(8874),s.e(4930)]).then(s.bind(s,19819));if(n)return;b.current=t,h.current=t.read(e,{type:"array"}),d(h.current.SheetNames),x(0),(()=>{let e=h.current,t=b.current;if(!e||!t)return;let s=e.SheetNames[0];s&&(p(t.utils.sheet_to_json(e.Sheets[s],{header:1,defval:"",raw:!1})),a(!1))})()}}catch(e){n||(o(e.message||"Failed to render"),a(!1))}};return r=t.streamMedia(e,{onChunk:e=>{n||l.push(e)},onDone:()=>{if(n)return;let e=new Uint8Array(l.reduce((e,t)=>e+t.byteLength,0)),t=0;for(let s of l)e.set(s,t),t+=s.byteLength;c(e)},onError:e=>{n||(o(e.message||"Failed to load"),a(!1))}}),()=>{n=!0,r?.()}},[e,t]),(0,r.useEffect)(()=>{let e=h.current,t=b.current;if(!e||!t)return;let s=e.SheetNames[u];s&&p(t.utils.sheet_to_json(e.Sheets[s],{header:1,defval:"",raw:!1}))},[u]),i)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:i});let g=(0,O.$b)(e);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[l&&(0,n.jsxs)("div",{className:"absolute inset-0 z-10 flex items-center justify-center gap-2 bg-surface text-text-muted",children:[(0,n.jsx)(el.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading document..."})]}),!g&&c.length>1&&(0,n.jsx)("div",{className:"flex gap-1 overflow-x-auto bg-surface border-b border-border px-2 py-1 flex-shrink-0",children:c.map((e,t)=>(0,n.jsx)("button",{onClick:()=>x(t),className:`px-2 py-1 text-xs rounded whitespace-nowrap transition-colors ${t===u?"bg-brand-500 text-white":"bg-surface-2 text-text-muted hover:text-text"}`,children:e},t))}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto bg-white text-black",children:g?(0,n.jsx)("div",{ref:f,className:"p-4"}):(0,n.jsx)("div",{className:"p-2",children:(0,n.jsx)("table",{className:"border-collapse",children:(0,n.jsx)("tbody",{children:m.map((e,t)=>(0,n.jsx)("tr",{children:e.map((e,t)=>(0,n.jsx)("td",{className:"border border-gray-300 px-2 py-1 whitespace-pre-wrap align-top",children:e},t))},t))})})})})]})}function im({filePath:e,fileBus:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)(""),[o,c]=(0,r.useState)(!0);return((0,r.useEffect)(()=>{let s=!1,n=null,r=[],a="application/pdf";c(!0),i(""),l("");let o=t.streamMedia(e,{onMeta:({mime:e})=>{!s&&e&&(a=e)},onChunk:e=>{s||r.push(e)},onDone:()=>{if(s)return;let e=new Blob(r,{type:a}),t=URL.createObjectURL(e);n=t,l(t),c(!1)},onError:e=>{s||(i(e.message||"Failed to load PDF"),c(!1))}});return()=>{s=!0,o(),n&&URL.revokeObjectURL(n)}},[e,t]),o)?(0,n.jsxs)("div",{className:"h-full flex items-center justify-center text-text-muted gap-2",children:[(0,n.jsx)(el.kr,{className:"animate-spin",size:20}),(0,n.jsx)("span",{children:"Loading PDF..."})]}):a?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:a}):(0,n.jsx)("iframe",{src:s,title:"PDF preview",className:"h-full w-full bg-bg"})}let ip=e=>(0,O.u)(e)||(0,O.AE)(e)||(0,O.L8)(e)||(0,O.ZH)(e)||(0,O.$b)(e)||(0,O.iB)(e);function ih({filePath:e,fileBus:t}){return(0,O.ZH)(e)?(0,n.jsx)(im,{filePath:e,fileBus:t},e):(0,O.$b)(e)||(0,O.iB)(e)?(0,n.jsx)(ix,{filePath:e,fileBus:t},e):(0,O.AE)(e)||(0,O.L8)(e)?(0,n.jsx)(iu,{filePath:e,fileBus:t},e):(0,n.jsx)(id,{filePath:e,fileBus:t},e)}function ib({filePath:e,fileBus:t}){let[s,n]=(0,r.useState)(!0),[l,a]=(0,r.useState)(null),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),f=(0,r.useRef)(""),h=(0,r.useRef)(null),b=(0,r.useRef)(null),[g,v]=(0,r.useState)(!1),y=(0,r.useCallback)(e=>{h.current=e},[]),w=(0,r.useCallback)(async(s=()=>!1)=>{n(!0),o(""),d(!1),v(!1);let r=await t.readFile(e);if(s())return;if(!r?.success){o(r?.error||""),n(!1);return}let l=r.content;if(r.streamInstead)try{let n=[];if(await new Promise((s,r)=>{t.streamMedia(e,{onMeta:()=>{},onChunk:e=>n.push(e),onDone:s,onError:r})}),s())return;l=await new Blob(n).text()}catch(e){if(s())return;o(e?.message||""),n(!1);return}f.current=l,a(l),n(!1)},[e,t]);(0,r.useEffect)(()=>{let t=!1;if(!e){n(!1),a(null),d(!1),o(""),v(!1);return}return w(()=>t),()=>{t=!0}},[e,w]);let j=(0,r.useCallback)(()=>{c?v(!0):w()},[c,w]);(0,r.useEffect)(()=>()=>clearTimeout(b.current),[]);let k=(0,r.useCallback)(e=>{d(e!==f.current)},[]),N=(0,r.useCallback)(async()=>{let s=h.current?.();if(null==s||u||s===f.current)return!0;x(!0);let n=await t.writeFile(e,s);return(x(!1),n?.success)?(f.current=s,d(!1),o(""),p(!0),clearTimeout(b.current),b.current=setTimeout(()=>p(!1),2e3),window.dispatchEvent(new CustomEvent("fileExplorer:fileSaved",{detail:{filePath:e}})),!0):(o(n?.error||""),!1)},[e,t,u]);return{loading:s,content:l,error:i,dirty:c,saving:u,justSaved:m,staleOnDisk:g,register:y,onTextChanged:k,save:N,discard:(0,r.useCallback)(()=>{d(!1),a(f.current)},[]),setError:o,reload:w,onChangedOnDisk:j}}function ig({dirty:e,onSave:t}){let[s,n]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!e)return;let t=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[e]);let l=(0,r.useCallback)(t=>{if(!e)return t();n(()=>t)},[e]),a=(0,r.useCallback)(async()=>{await t()&&(n(null),s?.())},[t,s]),i=(0,r.useCallback)(()=>{n(null),s?.()},[s]);return{guard:l,asking:!!s,saveThenLeave:a,discardAndLeave:i,cancel:(0,r.useCallback)(()=>n(null),[])}}function iv({isOpen:e,fileName:t,onSave:s,onDiscard:l,onCancel:a}){let{t:i}=(0,eu.s)(),o=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!e)return;let t=requestAnimationFrame(()=>{o.current?.focus()});return()=>cancelAnimationFrame(t)},[e]),(0,r.useEffect)(()=>{if(!e)return;let t=e=>{if("Escape"===e.key)e.preventDefault(),e.stopPropagation(),a?.();else if("Enter"===e.key){if(document.activeElement?.tagName==="BUTTON"&&document.activeElement!==o.current)return;e.preventDefault(),e.stopPropagation(),(0,ed.e)(),s?.()}else"d"!==e.key&&"D"!==e.key||e.metaKey||e.ctrlKey||e.altKey||(e.preventDefault(),e.stopPropagation(),(0,ed.e)(),l?.())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e,a,s,l]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[90] flex items-center justify-center px-4",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},onClick:a,children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px]"}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:"relative card-elev w-full max-w-sm p-5",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-[15px] font-semibold text-text mb-1.5",children:i("editor.unsavedTitle",{name:t||""})}),(0,n.jsx)("p",{className:"text-[13px] text-text-muted leading-snug mb-5",children:i("editor.unsavedBody")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),l?.()},className:"px-3 py-2 text-[13px] text-text-muted hover:text-red-500 transition-colors flex items-center gap-1",children:[(0,n.jsx)("span",{children:i("editor.discard")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"D"})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{onClick:a,className:"px-4 py-2 text-[13px] text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)("span",{children:i("common.cancel")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1 py-0.5 rounded bg-surface-3 text-text-muted leading-none",children:"Esc"})]}),(0,n.jsxs)("button",{ref:o,onClick:()=>{(0,ed.e)(),s?.()},autoFocus:!0,className:"px-4 py-2 text-[13px] font-semibold text-white bg-brand-500 hover:bg-brand-600 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)("span",{children:i("editor.save")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center justify-center w-4 h-4 rounded bg-white/20 text-white",children:(0,n.jsx)(el.Lt,{size:10,strokeWidth:2.5})})]})]})]})]}):null}var iy=s(70256),iw=s(39821),ij=s(48907),ik=s(74447),iN=s(15332),iC=s(9722),iS=s(97320),iT=s(99833),iR=s(50807),iE=s(57378),i$=s(41554),iz=s(42760);let iM={javascript:(0,ik.Q2)(),html:(0,iN.qy)(),css:(0,iC.AH)(),json:(0,iS.Pq)(),markdown:(0,iT.wD)()};function iP({filePath:e,content:t,onTextChanged:s,onRegisterView:l,onSave:a,onCursorChange:i,line:o,column:c,compact:d=!1,className:u=""}){let x,m,{theme:p}=(0,nW.D)(),f=(0,r.useRef)(null),h=(0,r.useRef)(null),b=(0,r.useRef)(s),g=(0,r.useRef)(i),v=(0,r.useRef)(a);(0,r.useEffect)(()=>{b.current=s},[s]),(0,r.useEffect)(()=>{g.current=i},[i]),(0,r.useEffect)(()=>{v.current=a},[a]);let[y]=tW(O.d5.editorFontSize,O.A0),[w]=tW(O.d5.wordWrap,!0),j=window.innerWidth<eJ.jK,k=d?Math.max(O.rL,y-O.xl):y+ +!!j,{extension:N}=(x="."+e.split(".").pop()?.toLowerCase(),{lang:m=O.so[x]||"plaintext",extension:iM[m]||[]});return(0,r.useEffect)(()=>{if(null==t||!f.current)return;let e=ij.$t.create({doc:t,extensions:[iy.oQ,..."dark"===p?[iR.bM]:[],N,...w?[iw.Lz.lineWrapping]:[],(0,iE.$P)(),(0,i$.yU)(),(0,i$.wm)(),iw.w4.of([{key:"Mod-s",preventDefault:!0,run:()=>(v.current?.(),!0)},...i$.Bc,...i$.OO,iz.Yc]),iw.Lz.updateListener.of(e=>{if(e.docChanged&&b.current?.(e.state.doc.toString()),e.selectionSet||e.docChanged){let t=e.state.selection.main.head,s=e.state.doc.lineAt(t);g.current?.({line:s.number,column:t-s.from+1})}}),iw.Lz.theme({"&":{height:"100%",fontSize:`${k}px`},".cm-scroller":{overflow:"auto",lineHeight:d?"1.35":""},".cm-content":{minHeight:"100%"},".cm-gutters":d?{fontSize:`${Math.max(8,k-1)}px`}:{}})]});return h.current?.destroy(),h.current=new iw.Lz({state:e,parent:f.current}),l?.(()=>h.current?.state.doc.toString()??null,h.current),()=>{h.current?.destroy(),h.current=null}},[t,e,p,w,k,d]),(0,r.useEffect)(()=>{let e=h.current;if(!e||!o)return;let t=e.state.doc,s=Math.max(1,Math.min(o,t.lines)),n=t.line(s),r=Math.min(n.from+Math.max(0,(c||1)-1),n.to);e.dispatch({selection:{anchor:r},effects:iw.Lz.scrollIntoView(r,{y:"center"})}),e.focus()},[o,c,t]),(0,n.jsx)("div",{ref:f,className:`h-full w-full overflow-hidden ${u}`})}function iA(e,t){return decodeURIComponent((t&&e.startsWith(t)?e.slice(t.length):e)||"/").replace(/^\//,"")||"/"}function iI({filePath:e,fileBus:t,reloadKey:s=0}){let{t:l}=(0,eu.s)(),{getAuth:i}=(0,a.Fo)(),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(""),[x,m]=(0,r.useState)(0),[p,f]=(0,r.useState)(e),[h,b]=(0,r.useState)({entries:[],index:-1}),g=(0,r.useRef)(null),v=(0,r.useRef)(!1);p!==e&&(f(e),c(null),u(""),b({entries:[],index:-1})),(0,r.useEffect)(()=>{let s=!1;return t.previewStart(e).then(e=>{var n;if(s){e.success&&t.previewEnd(e.sessionId);return}if(!e.success)return void u(e.error||l("editor.previewFailed"));let r=(n=i(),n?.localIp&&"https:"!==window.location.protocol?`http://${n.localIp}`:n?.tunnelUrl||null);if(!r){t.previewEnd(e.sessionId),u(l("editor.previewNoRoute"));return}let a=`/preview/${e.sessionId}`;g.current=e.sessionId,c({origin:r,root:a}),b({entries:[`${a}/${encodeURIComponent(e.entry)}`],index:0})}),()=>{s=!0,g.current&&t.previewEnd(g.current),g.current=null}},[e,t]);let y=o?.root;(0,r.useEffect)(()=>{if(!y)return;let e=e=>{if(e.data?.source!==O.fQ||"string"!=typeof e.data.path)return;let t=e.data.path;if(t.startsWith(y+"/")||t===y){if(v.current){v.current=!1;return}b(e=>{if(e.index>=0&&e.entries[e.index]===t)return e;let s=[...e.entries.slice(0,e.index+1),t];return{entries:s,index:s.length-1}})}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[y]);let w=(0,r.useCallback)(e=>{(0,ed.e)(),v.current=!0,b(t=>{let s=Math.max(0,Math.min(t.entries.length-1,t.index+e));return s===t.index?t:{...t,index:s}})},[]);if(d)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm px-6 text-center",children:d});if(!o)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:l("common.loading")});let j=h.entries[h.index]||o.root,k=`${o.origin}${j}`,N=h.index>0,C=h.index<h.entries.length-1,S="p-1 rounded-[3px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors disabled:opacity-30 disabled:hover:bg-transparent";return(0,n.jsxs)("div",{className:"h-full w-full flex flex-col bg-white",children:[(0,n.jsxs)("div",{className:"h-8 flex items-center gap-0.5 px-1.5 shrink-0 border-b border-border-subtle bg-surface",children:[(0,n.jsx)("button",{onClick:()=>w(-1),disabled:!N,title:l("editor.previewBack"),className:S,children:(0,n.jsx)(el.JG,{size:14})}),(0,n.jsx)("button",{onClick:()=>w(1),disabled:!C,title:l("editor.previewForward"),className:S,children:(0,n.jsx)(el.c_,{size:14})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m(e=>e+1)},title:l("editor.reload"),className:S,children:(0,n.jsx)(el.e9,{size:13})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate px-2 py-0.5 mx-1 rounded-[3px] bg-surface-2 text-[11px] text-text-muted",title:iA(j,o.root),children:iA(j,o.root)}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),window.open(k,"_blank","noopener")},title:l("editor.previewOpenTab"),className:S,children:(0,n.jsx)(el.Gr,{size:13})})]}),(0,n.jsx)("iframe",{src:k,sandbox:"allow-scripts allow-forms allow-popups",className:"flex-1 min-h-0 w-full border-0",title:"HTML preview"},`${k}|${h.index}|${s}|${x}`)]})}let iD=null,iL=0;function iB({content:e,reloadKey:t=0}){let l,a,{t:i}=(0,eu.s)(),{theme:o}=(0,nW.D)(),[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(""),m=(0,r.useRef)(null),p=(a=(l=String(e||"").trim()).match(/^```(?:mermaid)?\s*([\s\S]*?)\s*```$/i))?a[1].trim():l,[f,h]=(0,r.useState)(p);return(f!==p&&(h(p),d(""),x("")),(0,r.useEffect)(()=>{let e=!1;if(p)return(!iD&&(iD=Promise.all([s.e(3755),s.e(7162),s.e(3606)]).then(s.bind(s,86492)).then(e=>e.default)),iD).then(async t=>{if(!e){t.initialize({startOnLoad:!1,theme:"dark"===o?"dark":"default",securityLevel:A.Ic});try{let{svg:s}=await t.render(`mmd-${++iL}`,p);if(e)return;d(s),x("")}catch(t){if(e)return;d(""),x(t?.message||String(t))}}}).catch(t=>{e||x(t?.message||String(t))}),()=>{e=!0}},[p,o,t]),u)?(0,n.jsxs)("div",{className:"h-full overflow-auto p-3",children:[(0,n.jsx)("p",{className:"text-[11px] text-red-500 mb-2 break-words",children:u}),(0,n.jsx)("pre",{className:"text-[11px] text-text-muted whitespace-pre-wrap break-words",children:p})]}):p?c?(0,n.jsx)("div",{ref:m,className:"h-full overflow-auto p-3 flex items-start justify-center [&_svg]:max-w-full [&_svg]:h-auto",dangerouslySetInnerHTML:{__html:c}}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:i("common.loading")}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:i("editor.mermaidEmpty")})}function iF({content:e}){let{t}=(0,eu.s)();return e?.trim()?(0,n.jsx)("div",{className:"h-full overflow-auto p-4 sm:p-6 bg-bg select-text",children:(0,n.jsx)("div",{className:"max-w-4xl mx-auto",children:(0,n.jsx)(lw,{content:e})})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:t("common.empty",{defaultValue:"Empty file"})})}function iK({kind:e,filePath:t,fileBus:s,content:r,reloadKey:l=0}){return"html"===e?(0,n.jsx)(iI,{filePath:t,fileBus:s,reloadKey:l}):"mermaid"===e?(0,n.jsx)(iB,{content:r,reloadKey:l}):"markdown"===e?(0,n.jsx)(iF,{content:r}):null}var iO=s(23910);s(14876);let iW=["diff --git","index ","new file","deleted file","--- ","+++ "];function i_({diff:e,compact:t=!1,className:s=""}){let[l,a]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(t)return;let e=window.matchMedia(`(min-width: ${O.gh}px)`),s=()=>a(e.matches);return s(),e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[t]);let i=!t&&l,o=(0,r.useCallback)(t=>{if(t&&e&&i)try{new iO.LU(t,e,{drawFileList:!1,matching:"words",outputFormat:"side-by-side",renderNothingWhenEmpty:!1}).draw()}catch{t.replaceChildren(Object.assign(document.createElement("pre"),{className:"text-text-muted p-4",textContent:e}))}},[e,i]),c=(0,r.useMemo)(()=>i||!e?[]:function(e){let t=[],s=0,n=0;for(let r of e.split("\n")){if(iW.some(e=>r.startsWith(e))){r.startsWith("diff --git")&&t.push({type:"file",text:r.replace("diff --git a/","").split(" b/")[0]});continue}if(r.startsWith("@@")){let e=r.match(/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);e&&(s=parseInt(e[1],10),n=parseInt(e[2],10)),t.push({type:"hunk",text:r});continue}r.startsWith("+")?t.push({type:"add",text:r.slice(1),newLn:n++}):r.startsWith("-")?t.push({type:"del",text:r.slice(1),oldLn:s++}):t.push({type:"ctx",text:r.slice(1),oldLn:s++,newLn:n++})}return t}(e),[i,e]);return i?(0,n.jsx)("div",{ref:o,className:`diff-themed ${t?"diff-themed-compact":"bg-surface rounded"} overflow-hidden text-sm ${s}`}):(0,n.jsx)("div",{className:`w-full max-w-full overflow-hidden font-mono leading-[1.6] ${t?"text-[10px] leading-[1.45]":"rounded-lg border border-border bg-surface text-[12.5px]"} ${s}`,children:c.map((e,t)=>{if("file"===e.type)return(0,n.jsx)("div",{className:"px-3 py-2 bg-surface-2 text-text font-semibold break-all",children:e.text},t);if("hunk"===e.type)return(0,n.jsx)("div",{className:"px-3 py-1 bg-surface-2/60 text-text-muted select-none break-all",children:e.text},t);let s="add"===e.type?e.newLn:"del"===e.type?e.oldLn:e.newLn,r="add"===e.type?"bg-[rgba(var(--success-rgb),0.14)]":"del"===e.type?"bg-[rgba(var(--danger-rgb),0.14)]":"",l="add"===e.type?"text-[var(--success)]":"del"===e.type?"text-[var(--danger)]":"text-text-subtle",a="add"===e.type?"+":"del"===e.type?"-":" ";return(0,n.jsxs)("div",{className:`flex ${r}`,children:[(0,n.jsx)("span",{className:"shrink-0 w-9 px-1 text-right text-text-subtle bg-black/5 select-none",children:s}),(0,n.jsx)("span",{className:`shrink-0 w-4 text-center font-bold ${l} select-none`,children:a}),(0,n.jsx)("span",{className:"flex-1 min-w-0 pr-2 whitespace-pre-wrap break-words text-text",children:e.text||"\xa0"})]},t)})})}function iH({title:e,badge:t,badgeColor:s,img:r,loading:l,error:a,t:i}){var o;let c,d,u=[(c=r?.originalWidth||r?.width,d=r?.originalHeight||r?.height,c&&d?`${c} \xd7 ${d}`:""),!(o=r?.size||r?.originalSize)?"":o<1024?`${o} B`:o<1048576?`${(o/1024).toFixed(1)} KB`:`${(o/1048576).toFixed(1)} MB`].filter(Boolean).join(" \xb7 ");return(0,n.jsxs)("div",{className:"flex-1 flex flex-col rounded-brand border border-border-subtle bg-surface overflow-hidden min-h-[220px]",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border-subtle flex items-center justify-between bg-surface-2/60 shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-text",children:e}),t&&(0,n.jsx)("span",{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded-[3px] ${s}`,children:t})]}),u&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted font-mono",children:u})]}),(0,n.jsx)("div",{className:"flex-1 p-3 flex items-center justify-center bg-surface-2/20 min-h-[160px] overflow-hidden relative",children:l?(0,n.jsxs)("div",{className:"flex items-center gap-2 text-text-muted text-xs",children:[(0,n.jsx)(el.kr,{size:16,className:"animate-spin"}),(0,n.jsx)("span",{children:i("common.loading")})]}):a?(0,n.jsx)("div",{className:"text-xs text-text-muted text-center px-4 py-6",children:a}):r?.dataUrl?(0,n.jsx)("img",{src:r.dataUrl,alt:e,className:"max-h-[320px] max-w-full object-contain rounded drop-shadow-sm select-none"}):(0,n.jsx)("div",{className:"text-xs text-text-muted",children:i("git.noChanges")})})]})}function iU({filePath:e,status:t,workspace:s,fileBus:l,compact:a=!1}){let{t:i}=(0,eu.s)(),o="A"===t||"?"===t,c="D"===t,d=!o,u=!c,[x,m]=(0,r.useState)(null),[p,f]=(0,r.useState)(d),[h,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)(u),[j,k]=(0,r.useState)(""),[N,C]=(0,r.useState)(e);N!==e&&(C(e),m(null),f(d),b(""),v(null),w(u),k("")),(0,r.useEffect)(()=>{let t=!1;if(!e||!l)return;let n=s&&!e.startsWith("/")?`${s}/${e}`:e,r=s&&e.startsWith(s)?e.slice(s.length).replace(/^\//,""):e,a=setTimeout(()=>{d&&(f(!0),b(""),l.gitShowMedia?.(s,r,"HEAD").then(e=>{t||(f(!1),e?.success?m(e):b(e?.error||i("git.noOldVersion",{defaultValue:"No previous version in HEAD"})))}).catch(e=>{t||(f(!1),b(e?.message||"Failed to load old version"))})),u&&(w(!0),k(""),l.readMedia?.(n).then(e=>{t||(w(!1),e?.success?v(e):k(e?.error||i("git.noNewVersion",{defaultValue:"Failed to load working image"})))}).catch(e=>{t||(w(!1),k(e?.message||"Failed to load new version"))}))},0);return()=>{t=!0,clearTimeout(a)}},[e,s,l,d,u,i]);let S=e?e.split("/").pop():"",T=c||d&&!h&&(p||!!x?.dataUrl),R=T&&u;return(0,n.jsx)("div",{className:"h-full overflow-y-auto p-2 sm:p-3 flex flex-col gap-3",children:(0,n.jsxs)("div",{className:`flex-1 ${!a&&R?"grid grid-cols-1 md:grid-cols-2 gap-3":"flex flex-col gap-3"}`,children:[T&&(0,n.jsx)(iH,{title:c?`${S} (Deleted)`:"Old (HEAD)",badge:c?"DELETED":"ORIGINAL",badgeColor:"bg-red-500/15 text-red-400",img:x,loading:p,error:h,t:i}),u&&(0,n.jsx)(iH,{title:o?`${S} (Added)`:"New (Working Tree)",badge:o?"NEW":"MODIFIED",badgeColor:"bg-green-500/15 text-green-400",img:g,loading:y,error:j,t:i})]})})}function iq({diffPath:e,workspace:t,fileBus:s,compact:l=!1}){let{t:a}=(0,eu.s)(),{status:i,repoPath:o,filePath:c}=(0,O.qu)(e),d=o||t,u=(0,O.u)(c),[x,m]=(0,r.useState)(!u),[p,f]=(0,r.useState)(""),[h,b]=(0,r.useState)("");return((0,r.useEffect)(()=>{if(u)return;let e=!1,t=setTimeout(async()=>{m(!0),b("");let t=await s.gitDiff?.(d,c,i);e||(t?.success?f(t.diff||""):b(t?.error||""),m(!1))},0);return()=>{e=!0,clearTimeout(t)}},[d,c,i,s,u]),u)?(0,n.jsx)(iU,{filePath:c,status:i,workspace:d,fileBus:s,compact:l}):(0,n.jsxs)("div",{className:`h-full overflow-auto ${l?"p-0":"p-2 sm:p-3"}`,children:[h&&(0,n.jsx)("div",{className:"bg-red-500/20 border border-red-500/50 rounded px-4 py-2 text-red-400 text-sm mb-3",children:h}),x?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted text-sm",children:a("common.loading")}):p?(0,n.jsx)(i_,{diff:p,compact:l}):(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted text-sm",children:a("git.noChanges")})]})}function iX({filePath:e,workspace:t,fileBus:s,width:l,onResize:a,onClose:i,onOpenFull:o,onOpenFile:c,isDesktop:d=!0,previewSeq:u=0,artifactTitle:x=null,jump:m=null}){let{t:p}=(0,eu.s)(),f=(0,O.pA)(e),h=f?(0,O.qu)(e):null,b=h?.repoPath||t,g=f?h.filePath:e,v=h?h.repoPath?`${h.repoPath.replace(/\/$/,"")}/${h.filePath}`:h.filePath.startsWith("/")?h.filePath:`${t?.replace(/\/$/,"")||""}/${h.filePath}`:"",y=!!e&&!f&&!ip(e),w=ib({filePath:y?e:"",fileBus:s}),j=(0,r.useRef)(w);(0,r.useEffect)(()=>{j.current=w},[w]);let k=ig({dirty:y&&w.dirty,onSave:w.save}),N=y?(0,O.YO)(e):null,C=u>0,[S,T]=(0,r.useState)(C),[R,E]=(0,r.useState)(0),[$,z]=(0,r.useState)(e),[M,P]=(0,r.useState)(!1),[A,I]=(0,r.useState)(u);($!==e||A!==u)&&(z(e),I(u),T(C)),w.justSaved!==M&&(P(w.justSaved),w.justSaved&&E(e=>e+1)),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&k.guard(i)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[k,i]);let D=e&&!f?e.slice(0,e.lastIndexOf("/")):"",L=(0,r.useMemo)(()=>D?[D]:[],[D]),B=am(),F=(0,r.useCallback)(()=>{E(e=>e+1),j.current?.onChangedOnDisk()},[]);if(ax({dirs:L,fileBus:s,enabled:!!D&&B,debounceMs:O.Jl.PREVIEW_DEBOUNCE_MS,onDirsChanged:F}),!e)return null;let K=g.split("/").pop(),W=t&&g.startsWith(t)?g.slice(t.length).replace(/^\//,""):g;return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-bg border-l border-border-subtle relative shrink min-w-0",style:d?{width:l,flexBasis:l,minWidth:eJ.Ao.min}:void 0,children:[(0,n.jsxs)("div",{style:{height:32},className:"px-2 flex items-center gap-1.5 border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:aE({name:K,type:"file"},14)}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-[12px] text-text",title:W,children:K}),x&&(0,n.jsx)("span",{className:"flex-shrink-0 px-1.5 py-px rounded-[3px] text-[9px] font-medium uppercase tracking-wide bg-brand-500/15 text-brand-500",children:p("editor.artifact")}),f&&(0,n.jsx)("span",{className:`text-[10px] font-bold flex-shrink-0 ${O.vs[h.status]||"text-text-muted"}`,children:h.status}),N&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),T(e=>!e)},title:p(S?"editor.editCode":"editor.preview"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:S?(0,n.jsx)(el.GD,{size:13}):(0,n.jsx)(el.kU,{size:13})}),y&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),w.save()},disabled:!w.dirty||w.saving,title:p("editor.save"),className:`p-1 rounded-[3px] transition-colors disabled:opacity-30 ${w.dirty?"text-brand-500 hover:bg-surface-2":"text-text-muted"}`,children:(0,n.jsx)(el.eM,{size:13})}),(f?!!c:o&&d)&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f?c(v):o(e)},title:p(f?"git.openFile":"editor.openFull"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:f?(0,n.jsx)(el.GD,{size:13}):(0,n.jsx)(el.Gr,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),k.guard(i)},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:(0,n.jsx)(el.X,{size:13})})]}),w.error&&y&&(0,n.jsx)("div",{className:"px-3 py-1.5 text-[11px] text-red-500 bg-red-500/10 border-b border-border-subtle break-words",children:w.error}),w.staleOnDisk&&(0,n.jsxs)("div",{className:"px-3 py-1.5 flex items-center gap-2 text-[11px] text-amber-500 bg-amber-500/10 border-b border-border-subtle",children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:p("editor.changedOnDisk")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),w.reload()},className:"shrink-0 px-1.5 py-0.5 rounded-[3px] hover:bg-amber-500/20 font-medium transition-colors",children:p("editor.reloadFromDisk")})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:f?(0,n.jsx)(iq,{diffPath:(0,O.Dk)(h.status,h.filePath),workspace:b,fileBus:s,compact:!0}):ip(e)?(0,n.jsx)(ih,{filePath:e,fileBus:s}):S&&N?(0,n.jsx)(iK,{kind:N,filePath:e,fileBus:s,content:w.content,reloadKey:R}):w.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:p("common.loading")}):(0,n.jsx)(iP,{filePath:e,content:w.content,onTextChanged:w.onTextChanged,onRegisterView:w.register,onSave:w.save,line:m?.line,column:m?.column,compact:!0})}),(0,n.jsx)(iv,{isOpen:k.asking,fileName:K,onSave:k.saveThenLeave,onDiscard:k.discardAndLeave,onCancel:k.cancel}),d&&(0,n.jsx)("div",{onPointerDown:e=>eV(e,{startWidth:l,axis:-1,onWidth:e=>a?.(e)}),className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})]})}function iV(){let[e,t]=(0,r.useState)(null),s="mouse"!==tO();return((0,r.useEffect)(()=>{if(s)return;let e=null,n=null,r=()=>{clearTimeout(e),n=null,t(null)},l=s=>{let r=s.target?.closest?.("[data-tip]");if(r!==n){if(clearTimeout(e),n=r,!r)return t(null);e=setTimeout(()=>{let e;(e=r.getAttribute("data-tip"))&&function(e){let t=e.getBoundingClientRect();if(e.scrollHeight>e.clientHeight+eJ.de.SLACK_PX)return!0;let s=document.createRange();s.selectNodeContents(e);let n=s.getBoundingClientRect().width;s.detach();let r=getComputedStyle(e),l=parseFloat(r.paddingLeft)+parseFloat(r.paddingRight);return n>t.width-l+eJ.de.SLACK_PX}(r)&&t({text:e,...function(e){let{GAP_PX:t,EDGE_PX:s,MAX_WIDTH_PX:n,EST_HEIGHT_PX:r}=eJ.de,l=e.bottom+t,a=l+r>window.innerHeight-s;return{left:Math.min(Math.max(e.left,s),Math.max(s,window.innerWidth-n-s)),top:a?void 0:l,bottom:a?window.innerHeight-e.top+t:void 0}}(r.getBoundingClientRect())})},"focusin"===s.type?0:eJ.de.DELAY_MS)}},a=e=>{"Escape"===e.key&&r()};return document.addEventListener("mouseover",l,!0),document.addEventListener("focusin",l,!0),document.addEventListener("focusout",r,!0),document.documentElement.addEventListener("mouseleave",r),document.addEventListener("mousedown",r,!0),document.addEventListener("keydown",a,!0),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{clearTimeout(e),document.removeEventListener("mouseover",l,!0),document.removeEventListener("focusin",l,!0),document.removeEventListener("focusout",r,!0),document.documentElement.removeEventListener("mouseleave",r),document.removeEventListener("mousedown",r,!0),document.removeEventListener("keydown",a,!0),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[s]),e)?(0,sd.createPortal)((0,n.jsx)("div",{role:"tooltip",className:"fixed z-[90] pointer-events-none px-2 py-1 rounded-[3px] bg-surface-2 border border-border-subtle shadow-lg text-[11px] text-text break-words animate-in fade-in duration-100",style:{left:e.left,top:e.top,bottom:e.bottom,maxWidth:eJ.de.MAX_WIDTH_PX},children:e.text}),document.body):null}let iJ=(0,r.memo)(function({height:e=1,className:t=""}){let s=(0,r.useRef)(null),[l,a]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=s.current;if(!e)return;let t=new ResizeObserver(([t])=>{let s=t?.contentRect?.width||e.offsetWidth;s>0&&a(Math.round(s))});return t.observe(e),()=>t.disconnect()},[]);let i=l||600,o=Math.max(1.8,(i+140)/250);return(0,n.jsx)("div",{ref:s,"aria-hidden":"true",className:`absolute inset-x-0 top-0 overflow-hidden pointer-events-none ${t}`,style:{height:e,"--pane-w":`${i}px`,"--beam-w":"140px","--beam-dur":`${o.toFixed(2)}s`,"--beam-delay":`${(o/2).toFixed(2)}s`},children:(0,n.jsxs)("div",{className:"relative w-full h-full bg-blue-500/10",children:[(0,n.jsx)("div",{className:"pane-light-beam"}),(0,n.jsx)("div",{className:"pane-light-beam pane-light-beam-2"})]})})});function iG(e,t=2){let s=String(e).replace(/\/+$/,"").split("/");return s.length<=t?s.join("/"):`…/${s.slice(-t).join("/")}`}function iY(){let e=[{icon:el.BK,label:"Terminal"},{icon:el.VA,label:"Screen"},{icon:el.vd,label:"Files"},{icon:el.Zr,label:"Git"},{icon:el.wO,label:"Android"},{icon:el.qz,label:"Sites"}];return(0,n.jsx)("span",{className:"inline-flex flex-wrap items-center gap-x-3.5 gap-y-1.5",children:e.map(({icon:e,label:t})=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)(e,{size:13,className:"shrink-0"}),t]},t))})}let iZ=["newTerminal","palette","help"];function iQ({onAddWorkspace:e,onOpenRemote:t,recent:s=[],homeDir:l,onOpenRecent:a}){let{t:i}=(0,eu.s)();(0,h.B)(e=>e.pushView);let[o,c]=(0,r.useState)(!1),d=[...iZ.map(e=>tr.find(t=>t.id===e)).filter(Boolean),tl];return(0,n.jsxs)("div",{className:"h-full w-full empty-stage empty-stage-h",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),e?.()},disabled:!e,className:"empty-half text-left transition-all duration-150 enabled:hover:opacity-90 enabled:active:scale-[0.99] disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",i("workspaces.emptyTagVibe")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:i("workspaces.emptyWordVibe")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:i("workspaces.emptyMetaVibe")}}),(0,n.jsxs)("span",{className:"empty-go",children:[i("workspaces.emptyGoVibe"),(0,n.jsx)(el.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]}),!!s.length&&(0,n.jsx)("span",{className:"flex flex-wrap gap-1.5 mt-4 max-w-full",children:s.slice(0,4).map(e=>(0,n.jsx)("span",{role:"button",title:e.path,onClick:t=>{t.stopPropagation(),(0,ed.e)(),a?.(e.path)},className:"welcome-chip path-tail px-2 py-1 text-[11px] font-mono text-text-muted rounded-full truncate max-w-[180px]",children:iG(e.path)},e.path))})]}),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"empty-hairline","aria-hidden":!0}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),c(!0)},className:"empty-half text-left transition-all duration-150 enabled:hover:opacity-90 enabled:active:scale-[0.99] disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"02"})," / ",i("workspaces.emptyTagPair")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:i("workspaces.emptyWordPair")}),(0,n.jsx)("span",{className:"empty-meta",children:(0,n.jsx)(iY,{})}),(0,n.jsxs)("span",{className:"empty-go",children:[i("workspaces.emptyGoPair"),(0,n.jsx)(el.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]})]})]}),o&&(0,n.jsx)(nZ,{onClose:()=>c(!1)}),(0,n.jsx)("div",{className:"hidden lg:flex absolute bottom-0 inset-x-0 z-[2] flex-wrap items-center justify-center gap-x-5 gap-y-1.5 px-8 pb-6 font-mono text-[11px] text-text-subtle",children:d.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[i(`shortcuts.${e.id}`),(0,n.jsx)("kbd",{className:"px-1.5 py-0.5 rounded-[4px] bg-surface-2/60 text-text-muted whitespace-nowrap",children:td(e)})]},e.id))})]})}let i0=[],i1=(e,t)=>{if(!e||!t)return null;let s=e.getBoundingClientRect();return{scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight,nodeTop:t.getBoundingClientRect().top-s.top+e.scrollTop}},i2=e=>String(e).padStart(2,"0");function i5(e){let t=Math.max(0,Math.floor(e/1e3)),s=Math.floor(t/3600),n=Math.floor(t%3600/60),r=t%60;return s>0?`${s}h ${n}m ${i2(r)}s`:n>0?`${n}m ${i2(r)}s`:`${r}s`}function i3(e){return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),rm(e)," tokens"]}):null}let i4=(0,r.memo)(function({engine:e="claude",failed:t=!1,onRetry:s}){let r=tv.UB[e]||tv.UB.claude;return t?(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-center p-6 select-none",children:[(0,n.jsx)("span",{className:"font-mono text-[12px] text-danger",children:"Couldn't load this conversation"}),(0,n.jsx)("span",{className:"text-[11px] font-mono text-text-muted/70",children:r.label}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),s?.()},className:"px-3 py-1.5 rounded-brand text-[11px] font-mono text-text bg-surface-2 hover:bg-surface-3 transition-colors",children:"Retry"})]}):(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-center p-6 select-none",children:[(0,n.jsx)(el.kr,{size:20,className:"animate-spin text-brand-500"}),(0,n.jsx)("span",{className:"ai-sheen-text font-mono text-[12px] text-text-muted",children:"Syncing…"}),(0,n.jsx)("span",{className:"text-[11px] font-mono text-text-muted/70",children:r.label})]})}),i6=(0,r.memo)(function({sessionId:e,engine:t="",hydrating:s=!1}){let l=rH(t=>t.bySession[e]?.isTurnRunning),a=rH(t=>t.bySession[e]?.turnStartedAt),i=rH(t=>t.bySession[e]?.lastTurnMs),o=rH(t=>t.bySession[e]?.stats),c=rH(t=>t.bySession[e]?.turnBaseline),d=(0,u.d)(e=>e.connected),x=(0,u.d)(e=>e.retryStatus),m=rH(t=>t.bySession[e]?.messages)||i0,p=m[m.length-1]||null,f=Math.max(0,(o?.outputTokens||0)-(c?.outputTokens||0)),[h,b]=(0,r.useState)(Date.now());(0,r.useEffect)(()=>{if(!l)return;b(Date.now());let e=setInterval(()=>b(Date.now()),1e3);return()=>clearInterval(e)},[l]);let[g,v]=(0,r.useState)(null),y=(0,r.useRef)(l);(0,r.useEffect)(()=>{y.current&&!l&&a&&v({ms:i||Date.now()-a,outputTokens:f,changes:rh(m)}),l&&v(null),y.current=l},[l,a,i,f,m]);let w=(0,r.useMemo)(()=>g||l||!i?null:{ms:i,outputTokens:0,changes:rh(m)},[g,l,i,m]),j=g||w;if(!l&&!j)return null;if(!l)return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 select-none text-xs text-text-muted",children:[(0,n.jsx)(el.aJ,{size:14,className:"text-emerald-400 shrink-0"}),(0,n.jsxs)("span",{className:"flex items-center min-w-0 font-mono text-[11px]",children:[(0,n.jsxs)("span",{className:"truncate",children:["Worked for ",(0,n.jsx)("span",{className:"text-text",children:i5(j.ms)})]}),(0,n.jsxs)("span",{className:"shrink-0",children:[function({added:e,removed:t}){return e||t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),e>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",e]}),e>0&&t>0&&" ",t>0&&(0,n.jsxs)("span",{className:"text-danger",children:["−",t]})]}):null}(j.changes),i3(j.outputTokens)]})]})]});let k=p?.tools?.find(e=>"running"===e.status),N=f+function(e=[]){let t=0;for(let s=e.length-1;s>=0;s--){let n=e[s];if("user"===n.role)break;t+=(n.content?.length||0)+(n.thinking?.length||0)}return Math.round(t/4)}(m),C=function({connected:e=!0,hydrating:t=!1,retryStatus:s=null,activeTool:n=null,engine:r="",lastMsg:l=null}={}){if(!e){let e=s||{};return{verb:"Reconnecting",detail:e.isRetrying?`attempt ${e.attempt}/${e.maxAttempts}${e.failed?" \xb7 gave up":""}`:"",tone:"alert"}}if(t)return{verb:"Syncing",detail:"from host",tone:"wait"};if(n?.name){let{name:e,input:t={}}=n,s=(0,ri.$Z)(r,e),l=ro(t.file_path||t.path);switch(s){case"bash":return{verb:"Running",detail:rd(t.command||"",60),tone:"wait"};case"file":{let s=/^(list|list_dir|ls)$/i.test(e),n=t.offset?`:L${t.offset}`:"";return{verb:s?"Listing":"Reading",detail:rd(`${l}${n}`,60),tone:"wait"}}case"search":{let e=t.pattern?`"${t.pattern}"`:t.query||t.url||"",s=ro(t.path);return{verb:"Searching",detail:rd([e,s?`in ${s}`:""].filter(Boolean).join(" "),60),tone:"wait"}}case"diff":return{verb:/^(Write|write_to_file)$/i.test(e)?"Writing":"Editing",detail:rd(ro(t.file_path||t.filePath||t.file||t.path)||rx(t),60),tone:"wait"};case"agent":{let e=n.children?.length||0;return{verb:"Delegating",detail:rd([t.description||rx(t),e?`${e} steps`:""].filter(Boolean).join(" \xb7 "),60),tone:"wait"}}case"task":return{verb:"Updating tasks",detail:rd(t.activeForm||t.subject||"",60),tone:"wait"};case"plan":return{verb:"Planning",detail:rd(ro(t.path)||e,60),tone:"wait"};default:return{verb:"Calling",detail:rd([ru(e),rx(t)].filter(Boolean).join(" "),60),tone:"wait"}}}return l?.thinking?{verb:"Thinking",detail:rd(rc(l.thinking),60),tone:"wait"}:l?.content?{verb:"Writing",detail:rd(rc(l.content),60),tone:"wait"}:{verb:"Working",detail:"",tone:"wait"}}({connected:d,hydrating:s,retryStatus:x,activeTool:k,engine:t,lastMsg:p});return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 select-none text-xs text-text-muted",children:["alert"===C.tone?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-danger animate-pulse shrink-0"}):(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-brand-500 shrink-0"}),(0,n.jsxs)("span",{className:"flex items-center min-w-0 font-mono text-[11px]",children:[(0,n.jsxs)("span",{className:"truncate",children:[(0,n.jsxs)("span",{className:`ai-sheen-text${"alert"===C.tone?" !text-danger":""}`,children:[C.verb,"…"]}),C.detail&&(0,n.jsxs)("span",{className:"text-text-subtle",children:[" ",C.detail]}),(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),i5(h-(a||h))]}),(0,n.jsx)("span",{className:"shrink-0",children:i3(N)})]})]})}),i8=(0,r.memo)(function({engine:e,engineMeta:t,workspacePath:s,bus:l=null,fileBus:a,onSendPrompt:i,onOpenResume:o}){let{t:c}=(0,eu.s)(),[d,u]=(0,r.useState)([]),[x,m]=(0,r.useState)(null),p=eM(),f=n8(s,a,{enabled:!!s});(0,r.useEffect)(()=>{if(!s)return;let e=!0;return a?.getSystemInfo?.().then(t=>{e&&t?.success&&m(t.homedir||null)}).catch(()=>{}),()=>{e=!1}},[a,s]),(0,r.useEffect)(()=>{if(!s)return;let t=!0;if(l?.emit)return l.emit("getAgentSessions",{cwd:s},s=>{t&&u((Array.isArray(s?.sessions)?s.sessions:[]).filter(t=>!e||t.agent===e).slice(0,8))}),()=>{t=!1}},[s,e]);let h=s?sx(s,x):"";return(0,n.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-center p-6 select-none overflow-y-auto custom-scrollbar",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-2xl flex items-center justify-center mb-3 shadow-md border border-border-subtle/40 backdrop-blur-sm shrink-0",style:{backgroundColor:`${t.color}15`},children:(0,n.jsx)("img",{src:e5(`${e}-ui`),alt:t.label,className:`w-7 h-7 object-contain ${e2}`})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-text mb-1",children:t.label}),h&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-3 text-[11px] font-mono text-text-muted",title:s,children:[(0,n.jsx)("span",{className:"truncate max-w-[220px]",children:h}),f.branch&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/50",children:"\xb7"}),(0,n.jsx)("span",{className:"truncate max-w-[140px]",children:f.branch}),f.dirty&&(0,n.jsxs)("span",{className:"text-amber-400",title:`${f.changedCount} changed`,children:["●",f.changedCount]})]})]}),d.length>0&&(0,n.jsxs)("div",{className:"w-full max-w-md mb-4 text-left",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1.5 px-1 text-[10px] uppercase tracking-wide text-text-muted",children:[(0,n.jsx)(el.BZ,{size:11}),(0,n.jsx)("span",{children:"Recent in this project"})]}),(0,n.jsx)("div",{className:"max-h-[38vh] overflow-y-auto custom-scrollbar rounded-brand border border-border-subtle bg-surface-2/30",children:d.map(e=>{let t=!!e.openSessionId&&!!p[e.openSessionId];return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),t?window.dispatchEvent(new CustomEvent(eJ.vP,{detail:{sessionId:e.openSessionId}})):o?.(e)},className:"w-full flex items-center gap-2 px-2.5 py-1.5 text-left border-b border-border-subtle/50 last:border-b-0 hover:bg-surface-2 transition-colors",title:t?c("agentHistory.openNow"):void 0,children:[(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-[11px] ${t?"text-text font-medium":"text-text-muted"}`,children:e.title||"Untitled conversation"}),(0,n.jsx)("span",{className:"shrink-0 text-[10px] font-mono text-text-muted",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m`;let s=Math.round(t/60);return s<24?`${s}h`:`${Math.round(s/24)}d`}(e.updatedAt)})]},`${e.agent}:${e.sessionId}`)})}),d.length>=8&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),o?.()},className:"mt-1.5 px-1 text-[10px] font-mono text-text-muted hover:text-text transition-colors",children:"All conversations →"})]}),(0,n.jsx)("div",{className:"flex flex-wrap items-center justify-center gap-2 max-w-md shrink-0",children:tv.y2.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>i?.(e),className:"px-2.5 py-1 rounded-full bg-surface-2 hover:bg-surface-3 text-[11px] text-text font-mono border border-border-subtle transition-colors",children:e},e))})]})}),i9=(0,r.memo)(function({sessionId:e,engine:t="claude",workspacePath:s="",bus:l=null,fileBus:a=null,onSendPrompt:i,onResolvePermission:o,hasOlder:c=!1,onLoadOlder:d,onRewind:u,onPreviewRewind:x,onCutLocal:m,onListRewindPoints:p,onOpenResume:f,hydrating:h=!1,synced:b=!0,hydrateFailed:g=!1,onReload:v}){let y=(0,r.useRef)(null),w=(0,r.useRef)(null),j=(0,r.useRef)(!0),k=(0,r.useRef)(null),N=(0,r.useRef)(null),C=(0,r.useRef)(null),S=(0,r.useRef)(null),T=(0,r.useRef)(0),[R,E]=(0,r.useState)(!1),[$,z]=(0,r.useState)(131072),[M,P]=(0,r.useState)(null),A=(0,r.useRef)({sessionId:null,n:0}),I=rH(t=>t.bySession[e]?.messages)||i0,D=tv.UB[t]||tv.UB.claude;(0,r.useEffect)(()=>{z(131072),P(null),S.current=null},[e]);let{id:B,index:F}=(0,r.useMemo)(()=>(function(e,t,s){if(!t?.length)return{id:null,index:0};let n=rq(t,s,void 0),r=null!=e?t.findIndex(t=>t.id===e):-1,l=rq(t,Math.max(524288,s),void 0),a=r<0?n:Math.max(r,l);return{id:t[a].id,index:a}})(M,I,$),[M,I,$]);(0,r.useEffect)(()=>{P(B)},[B]);let K=F>0?I.slice(F):I,[O,W]=(0,r.useState)(null),_=(0,r.useRef)(0),H=(0,r.useMemo)(()=>I.filter(e=>"user"===e.role).length,[I]);(0,r.useEffect)(()=>{if(O?.ok||O?.supported===!1||_.current>=6)return;_.current+=1;let e=!0;return p?.().then(t=>{e&&W(t)}).catch(()=>{}),()=>{e=!1}},[p,t,e,H,O?.ok,O?.supported]);let U=!!O?.ok,q=(0,r.useMemo)(()=>{let e=new Map,t=0;for(let s=I.length-1;s>=0;s--)"user"===I[s].role&&e.set(I[s].id,t++);return e},[I]),X=(0,r.useMemo)(()=>{let e=[];for(let t of K)"user"===t.role||0===e.length?e.push({key:t.id,messages:[t]}):e[e.length-1].messages.push(t);return e},[K]),V=(0,r.useCallback)(async({auto:e=!1}={})=>{let t=y.current,s=Date.now();if(!e&&s-T.current<300)return;T.current=s;let n=C.current,r=n?function({scrollTop:e=0,scrollHeight:t=0,clientHeight:s=0,nodeTop:n=0}={}){return{nodeTop:n,scrollTop:e,atBottom:t-e-s<8}}(i1(t,n)):null,l=r?{...r,atBottom:e&&j.current,node:n}:null,a={hiddenCount:F,hasOlder:c,scrollTop:t?.scrollTop??0,scrollHeight:t?.scrollHeight??0},i=null;0===F&&c&&(i=await d?.()),(0,L.Lq)("ai-page","loadMore",{...a,fetched:i}),S.current=l,P(null),z(e=>e+131072)},[F,c,d]);(0,r.useLayoutEffect)(()=>{let e=y.current,t=S.current;if(!e||!t)return;S.current=null;let s=function(e,{scrollHeight:t=0,clientHeight:s=0,nodeTop:n=0}={}){return e?e.atBottom?t:n<=e.nodeTop?null:Math.max(0,n-(e.nodeTop-e.scrollTop)):null}(t,i1(e,t.node)||{});null!=s&&(e.scrollTop=s);let n=e.scrollHeight-e.scrollTop-e.clientHeight;j.current=n<8,E(n>140)},[$,M]),(0,r.useEffect)(()=>{let t=A.current;if(t.sessionId!==e&&(t.sessionId=e,t.n=0),t.n>=40||h||!b||!j.current||!(c&&I?.length)||I[F]?.role==="user")return;let s=setTimeout(()=>{t.n+=1,V({auto:!0})},0);return()=>clearTimeout(s)},[e,I,F,c,h,b,V]);let J=(0,r.useCallback)(()=>{k.current||(k.current=requestAnimationFrame(()=>{k.current=null;let e=y.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight,s=t<80;j.current=s,E(!s&&t>140),e.scrollTop<120&&(F>0||c)&&V()}))},[V,F,c]);(0,r.useEffect)(()=>{let e=y.current,t=w.current;if(!e||!t)return;let s=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&!j.current&&V()},{root:e,rootMargin:"120px"});return s.observe(t),()=>s.disconnect()},[V]);let G=(0,r.useMemo)(()=>I.map(e=>`${e.id}:${+!!e.thinking}:${+!!e.content}:${e.tools?.length||0}:${e.diffs?.length||0}:${+!!e.permission}`).join("|"),[I]),Y=(0,r.useCallback)(e=>{C.current=e},[]);(0,r.useEffect)(()=>{let e=y.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},[G]);let Z=(0,r.useMemo)(()=>I.reduce((e,t)=>e+(t.content?.length||0),0),[I]);(0,r.useEffect)(()=>{!j.current||N.current||(N.current=setTimeout(()=>{N.current=null;let e=y.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},150))},[Z]),(0,r.useEffect)(()=>()=>{N.current&&clearTimeout(N.current)},[]),(0,r.useEffect)(()=>{let e=y.current;if(!e)return;let t=new ResizeObserver(()=>{j.current&&(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>t.disconnect()},[]);let Q=(0,r.useCallback)(()=>{(0,ed.e)();let e=y.current;e&&(e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),j.current=!0,E(!1))},[]),ee=(0,r.useCallback)(e=>e.messages.some(e=>e.isLive),[]);return(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{ref:y,onScroll:J,className:"ai-conversation flex-1 min-h-0 overflow-y-auto px-4 sm:px-6 py-4 space-y-4 custom-scrollbar relative",children:[(F>0||c)&&(0,n.jsx)("div",{ref:w,"aria-hidden":"true",className:"h-px"}),0===I.length?b?(0,n.jsx)(i8,{engine:t,engineMeta:D,workspacePath:s,bus:l,fileBus:a,onSendPrompt:i,onOpenResume:f}):(0,n.jsx)(i4,{engine:t,failed:g,onRetry:v}):(0,n.jsxs)(n.Fragment,{children:[(F>0||c)&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),V()},className:"w-full py-1.5 text-[11px] font-mono text-text-muted hover:text-text bg-surface-2/50 hover:bg-surface-2 border border-border-subtle/60 rounded-brand transition-colors",children:F>0?`Load older \xb7 ${F} more`:"Load older turns"}),X.map((e,r)=>{let[l,...a]=e.messages;return"user"!==l.role?(0,n.jsx)("div",{ref:0===r?Y:void 0,children:(0,n.jsx)(lR,{messages:e.messages,engine:t,workspacePath:s,onResolvePermission:o,isLive:ee(e)})},e.key):(0,n.jsxs)("div",{ref:0===r?Y:void 0,children:[(0,n.jsx)(r3,{message:l,engine:t,workspacePath:s,onResolvePermission:o,onRewind:u,onPreviewRewind:x,onCutLocal:m,rewindIndex:q.get(l.id),canRewind:U}),(0,n.jsx)(lR,{messages:a,engine:t,workspacePath:s,onResolvePermission:o,isLive:ee(e)})]},e.key)}),(0,n.jsx)(i6,{sessionId:e,engine:t,hydrating:h})]})]}),R&&(0,n.jsx)("button",{type:"button",onClick:Q,className:"absolute bottom-4 right-6 p-2 rounded-full bg-surface-2 border border-border-subtle shadow-lg hover:bg-surface-3 text-text transition-all duration-150 z-30",title:"Scroll to bottom",children:(0,n.jsx)(el.yd,{size:16})})]})});function i7(e){return e.provider?e.provider:e.id&&e.id.includes("/")?e.id.split("/")[0]:""}function oe(e,t,s,n){let r=n?t:e,l=[],a=r.filter(e=>e.recent||e.id===s).sort((e,t)=>(e.recentRank??999)-(t.recentRank??999));a.length>0&&l.push({key:"recent",title:"Recent",items:a});let i=new Set(a.map(e=>e.id)),o=r.filter(e=>!i.has(e.id)),c=new Map;for(let e of o){let t=i7(e)||"other";c.has(t)||c.set(t,[]),c.get(t).push(e)}for(let e of[...c.keys()].sort((e,t)=>"profiles"===e||"codex-profiles"===e?-1:"profiles"===t||"codex-profiles"===t?1:"opencode-go"===e?-1:"opencode-go"===t?1:"opencode"===e?-1:"opencode"===t?1:e.localeCompare(t))){let t=c.get(e)||[];0!==t.length&&(t.sort((e,t)=>(e.label||e.id).localeCompare(t.label||t.id)),l.push({key:e,title:e?"profiles"===e||"codex-profiles"===e?"Custom Profiles":"opencode-go"===e?"OpenCode Go":"opencode"===e?"OpenCode Zen":"9router"===e?"9Router":"google-antigravity"===e?"Google Antigravity":"ollama-cloud"===e?"Ollama Cloud":"anthropic"===e?"Anthropic":"openai"===e?"OpenAI":"google"===e?"Google":e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):"Other Models",items:t}))}return l}let ot=[],os=(0,r.memo)(function({sessionId:e="",engine:t="claude",bus:s=null,isTurnRunning:l=!1,isFocused:a=!1,onSend:i,onRemoveQueueItem:o,onClearQueue:c,onStop:d,onRunShell:u,onResolvePermission:x,onSelectModel:m,onModeChange:p,onOpenModal:f,onOptionChange:h,onActivate:b,fileBus:g=null,workspacePath:v="",model:y="",modalOpen:w=!1}){let{t:j,locale:k}=(0,eu.s)(),N="mouse"===tO(),C=tc()?"Opt ←/→ \xb7 Opt 1…9 to switch tab":"Ctrl+Shift+←/→ \xb7 1…9 to switch tab",S=(0,ri.Tw)(t),T=S.permissionModes,R=S.slashCommands,E=rH(t=>t.bySession[e]?.isTurnRunning),$=rH(t=>t.bySession[e]?.metadata?.model),z=rH(t=>t.bySession[e]?.metadata?.modelOptions),M=z?.length?z:S.models,P=rH(t=>t.bySession[e]?.metadata?.skills)||ot,A=rH(t=>t.bySession[e]?.metadata?.commands)||ot,I=rH(t=>t.bySession[e]?.permissionMode),D=rH(t=>t.bySession[e]?.metadata?.effort||t.bySession[e]?.metadata?.variant),L=I||S.defaultMode,B=void 0!==E?E:l,F=void 0!==$?$:y,[K,O]=(0,r.useState)(""),W=rH(t=>t.bySession[e]?.queue)||ot,[_,H]=(0,r.useState)(-1),U=(0,r.useRef)(""),[q,X]=(0,r.useState)(!1),[V,J]=(0,r.useState)(null),[G,Y]=(0,r.useState)(""),[Z,Q]=(0,r.useState)([]),[ee,et]=(0,r.useState)(0),[es,en]=(0,r.useState)(null),[er,ea]=(0,r.useState)(-1),ei=tC(e=>e.addCommand),eo=tC(e=>e.resolveAlias),ec=tC(e=>e.history),ex=tC(e=>e.pinned),em=(0,r.useMemo)(()=>q?[]:tz(K,ec,ex,[],!N),[K,ec,ex,N,q]),[ep,ef]=(0,r.useState)(!1),[eh,eb]=(0,r.useState)(""),[eg,ev]=(0,r.useState)(()=>new Set),[ey,ew]=(0,r.useState)(!1),[ej,ek]=(0,r.useState)(!1),eN=(0,r.useRef)(null),{attachments:eC,setAttachments:eS,removeAttachment:eT,handleFileUpload:eR,handleAttachPaste:eE}=tJ({bus:s,sessionId:e}),[e$]=tD(k),ez=tF({lang:tA(e$),onText:e=>{O(e),eD.current&&(eD.current.value=e,eD.current.style.height="auto",eD.current.style.height=`${Math.min(eD.current.scrollHeight,120)}px`,eD.current.focus())}}),eM=(0,r.useCallback)(()=>{(0,ed.e)(),ez.stop()},[ez]),eP=(0,r.useCallback)(()=>{ez.cancel()},[ez]),eA=(0,r.useCallback)(()=>{ez.listening?ez.stop():(document.activeElement?.blur(),ez.start(K))},[ez,K]),eI=(0,r.useCallback)(()=>{(0,ed.e)(),O(""),eD.current&&(eD.current.value="",eD.current.style.height="26px");try{localStorage.removeItem(`9remote_draft_${e}`)}catch{}eD.current?.focus()},[e]),eD=(0,r.useRef)(null),eL=(0,r.useRef)(eC);(0,r.useEffect)(()=>{eL.current=eC},[eC]);let eB=(0,r.useRef)(null),eF=(0,r.useRef)(!1),eK=(0,r.useRef)(0),eO=(0,r.useRef)(0),eW=(0,r.useRef)(0);tv.UB[t]||tv.UB.claude,(0,r.useEffect)(()=>{a&&!w&&N&&eD.current?.focus({preventScroll:!0})},[a,w,N]),(0,r.useEffect)(()=>{let t=t=>{if(t.detail?.sessionId!==e)return;let s=String(t.detail.text||"");if(s&&(O(e=>e===s||e.includes(s)?e:e?`${e}
16
+ ${s}`:s),eD.current&&!eD.current.value.includes(s))){let e=eD.current.value?`${eD.current.value}
17
+ ${s}`:s;eD.current.value=e,eD.current.style.height="auto",eD.current.style.height=`${Math.min(eD.current.scrollHeight,120)}px`,eD.current.focus()}};return window.addEventListener("9r:ai-prompt",t),()=>window.removeEventListener("9r:ai-prompt",t)},[e]),(0,r.useEffect)(()=>{let e=e=>{eN.current&&!eN.current.contains(e.target)&&(ef(!1),ew(!1))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,r.useEffect)(()=>{B&&(ef(!1),ew(!1))},[B]),(0,r.useEffect)(()=>{let e=eD.current;if(!e)return;e.style.height="auto";let t=Math.min(e.scrollHeight,140);e.style.height=`${Math.max(t,26)}px`,e.selectionEnd===e.value.length&&(e.scrollTop=e.scrollHeight)},[K]),(0,r.useEffect)(()=>{if(!q||!eB.current)return;let e=eB.current.querySelectorAll("[data-menu-item]")[ee];e&&e.scrollIntoView({block:"nearest"})},[ee,q]),(0,r.useEffect)(()=>{if(e){eS([]);try{O(localStorage.getItem(`9remote_draft_${e}`)||"")}catch{}}},[e,eS]),(0,r.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{try{K?localStorage.setItem(`9remote_draft_${e}`,K):localStorage.removeItem(`9remote_draft_${e}`)}catch{}},300);return()=>clearTimeout(t)},[K,e]),(0,r.useEffect)(()=>{if(es){let e=es.name.replace(/[/@]/g,"\\$&");if(RegExp(`(?:^|\\s)${e}\\s*$`).test(K))return;en(null)}let e=/(?:^|\s)([/@][\w\d_.-]*)$/.exec(K);if(!e){X(!1),J(null),Y("");return}let t=e[1],n=t[0],r=t.slice(1).toLowerCase();if(J(n),Y(r),et(0),"/"===n){let e=function({staticCommands:e=[],liveCommands:t=[],skills:s=[],filter:n=""}={}){let r=(t||[]).map(e=>({name:`/${e.name}`,description:e.description||"",isCommand:!0})),l=(s||[]).map(e=>({name:`/${e.name||e.id}`,description:e.description||`Skill: ${e.name||e.id}`,isSkill:!0})),a=new Set,i=String(n||"").toLowerCase();return[...e||[],...r,...l].filter(e=>!a.has(e.name)&&!!e.name.toLowerCase().includes(i)&&(a.add(e.name),!0))}({staticCommands:R,liveCommands:A,skills:P,filter:r});Q(e),X(e.length>0)}else"@"===n&&(s?.emit?s.emit("ai:files",{workspace:v,query:r},e=>{e?.ok&&Array.isArray(e.files)&&(Q(e.files.map(e=>({name:e.path||e,description:e.isModified?`${e.dir?e.dir+" \xb7 ":""}modified`:e.dir||""}))),X(e.files.length>0))}):g?.searchFiles&&v?g.searchFiles(v,r).then(e=>{e?.success&&Array.isArray(e.files)&&(Q(e.files.slice(0,10).map(e=>({name:e.path||e,description:e.relPath||e}))),X(e.files.length>0))}):(Q([]),X(!1)))},[K,g,v,P,A,R,es]);let e_=(0,r.useCallback)(t=>{let s=eo((("string"==typeof t?t:eD.current?eD.current.value:K)||K).trim()),n=eL.current;if(!s&&0===n.length)return;let r=Date.now();if(r-eO.current<250)return;eO.current=r,eW.current=r,(0,ed.e)(),s&&!s.startsWith("!")&&ei(s),H(-1),O(""),eD.current&&(eD.current.value="",eD.current.style.height="26px");try{localStorage.removeItem(`9remote_draft_${e}`)}catch{}if(s.startsWith("!")){n.length||u?.(s.slice(1).trim());return}let l=rH.getState().bySession[e]?.activePermission;l&&x?.(l.requestId,tv.x6,tv.mX),n.length&&eS([]),i?.(s,{attachments:n.map(({name:e,type:t,content:s})=>({filename:e,type:t,content:s}))})},[K,e,i,u,x,eS,ei,eo]),eH=(0,r.useCallback)(()=>{(0,ed.e)(),d?.()},[d]),eU=(0,r.useCallback)(e=>{let t=e.action||"send",[s,n]=t.split(":");if("modal"===s){eD.current?.blur(),f?.(n);return}if("clear"===s){i?.("/clear",{force:!0}),O("");return}if("setMode"===s){p?.(e.mode),O("");return}if("send"===s||"send"===t){i?.(e.name),O("");return}eD.current?.focus()},[f,i,p]),eq=(0,r.useCallback)(e=>{(0,ed.e)();let t=/(?:^|\s)([/@][\w\d_.-]*)$/.exec(K);if(!t)return;let s=t[1],n=K.slice(0,K.length-s.length),r="/"===V&&e.action?.startsWith("modal:"),l="@"===V?`@${e.name} `:`${e.name} `;(O(r?n:`${n}${l}`),X(!1),"/"!==V)?eD.current?.focus():"submenu"===e.action&&Array.isArray(e.subOptions)&&e.subOptions.length>0?B&&("effort"===e.optionKey||"variant"===e.optionKey)?O(""):(en(e),et(0),X(!0)):eU(e)},[K,V,eU,B]),eX=(0,r.useCallback)(e=>{(0,ed.e)(),es&&(h?.(es.optionKey,e.value),en(null),X(!1),O(""),eD.current?.focus())},[es,h]),eV=(0,r.useCallback)(e=>{(0,ed.e)();let t=/(?:^|\s)(\S*)$/.exec(K),s=t?t[1]:"";O(K.slice(0,K.length-s.length)+e),ea(-1),eD.current?.focus()},[K]),eJ=e=>String(e||"").toLowerCase().replace(/\[[^\]]*\]$/,""),eG=(0,r.useMemo)(()=>{if(!F)return null;let e=M||[],t=eJ(F);return e.find(e=>e.id===F)||e.find(e=>eJ(e.id)===t)||e.find(e=>eJ(e.id).split("/").pop()===t.split("/").pop())||null},[F,M]),eY=eG?.short||eG?.label||F||"Model",eZ=D||S.defaultEffort||"",eQ=(0,r.useMemo)(()=>{let e=[...M||[]];return F&&!e.some(e=>e.id===F)&&e.unshift({id:F,label:F,short:F}),e},[M,F]),e0=(0,r.useMemo)(()=>{if(eQ.length<=20)return eQ;let e=eh.trim().toLowerCase();return e?eQ.filter(t=>{let s=(t.id||"").toLowerCase();return(t.label||"").toLowerCase().includes(e)||s.includes(e)||(t.provider||"").toLowerCase().includes(e)}):eQ},[eQ,eh]),e1=(0,r.useMemo)(()=>eQ.length<=20?[{key:"all",title:"",items:eQ}]:oe(eQ,e0,F,eh.trim()),[eQ,e0,F,eh]),e3=(0,r.useMemo)(()=>(R||[]).find(e=>"submenu"===e.action&&("effort"===e.optionKey||"variant"===e.optionKey)),[R]),e4=(0,r.useMemo)(()=>{let e=(eG?.efforts||[]).map(e=>({value:e,label:e}));return e.length>0?e:e3?.subOptions||[]},[e3,eG]);return(0,n.jsxs)("div",{className:"relative px-3 py-1.5 bg-transparent border-t border-border-subtle/40 select-none",children:[q&&es&&(0,n.jsxs)("div",{ref:eB,className:"absolute left-3 right-3 bottom-[calc(100%+6px)] max-h-52 bg-surface border border-border-subtle rounded-brand shadow-lg overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsxs)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1 flex items-center justify-between",children:[(0,n.jsxs)("span",{children:[es.name," — ",es.optionKey]}),(0,n.jsx)("button",{type:"button",onClick:()=>{en(null),X(!1),O("")},className:"text-text-muted hover:text-text",children:(0,n.jsx)(el.X,{size:11})})]}),(es.subOptions||[]).map((e,t)=>(0,n.jsxs)("div",{"data-menu-item":"true",onClick:()=>eX(e),onMouseEnter:()=>et(t),className:`px-2 py-1 rounded-brand flex items-center justify-between text-xs cursor-pointer ${t===ee?"bg-surface-2 text-text font-medium":"text-text-muted hover:text-text"}`,children:[(0,n.jsx)("span",{className:"font-mono text-xs text-text",children:e.label}),e.desc&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted truncate ml-2 max-w-[55%]",children:e.desc})]},e.value))]}),q&&!es&&Z.length>0&&(0,n.jsxs)("div",{ref:eB,className:"absolute left-3 right-3 bottom-[calc(100%+6px)] max-h-52 bg-surface border border-border-subtle rounded-brand shadow-lg overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"/"===V?"Slash Commands & Skills":"Files in repo (@)"}),Z.map((e,t)=>{let s=B&&("/model"===e.name||"submenu"===e.action&&("effort"===e.optionKey||"variant"===e.optionKey));return(0,n.jsxs)("div",{"data-menu-item":"true",onClick:s?void 0:()=>eq(e),onMouseEnter:()=>et(t),className:`px-2 py-1 rounded-brand flex items-center justify-between text-xs ${s?"opacity-40 cursor-not-allowed":t===ee?"bg-surface-2 text-text font-medium cursor-pointer":"text-text-muted hover:text-text cursor-pointer"}`,title:s?"Cannot change while turn is running":void 0,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 truncate",children:[e.isSkill?(0,n.jsx)(el.Kq,{size:12,className:"text-warning shrink-0"}):"/"===V?(0,n.jsx)(el.BK,{size:12,className:"text-accent shrink-0"}):(0,n.jsx)(el.GD,{size:12,className:"text-accent shrink-0"}),(0,n.jsx)("span",{className:"font-mono text-xs text-text",children:e.name}),e.isSkill&&(0,n.jsx)("span",{className:"text-[9px] px-1 rounded bg-warning/15 text-warning font-mono",children:"skill"}),"submenu"===e.action&&(0,n.jsx)(el.rX,{size:11,className:"text-text-muted shrink-0 rotate-90"})]}),e.description&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted truncate ml-2 max-w-[50%]",children:e.description})]},e.name)})]}),W.length>0&&(0,n.jsx)("div",{className:"mb-1 space-y-0.5",children:W.map((e,t)=>(0,n.jsxs)("div",{className:"px-2 py-0.5 rounded bg-brand-500/10 border border-brand-500/30 flex items-center justify-between text-xs animate-in fade-in duration-100",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-mono text-[9px] uppercase tracking-wider font-semibold px-1 rounded bg-brand-500/20 text-brand-400 shrink-0",children:0===t?"Next":`Queued ${t+1}`}),(0,n.jsx)("span",{className:"truncate text-text font-mono text-[11px]",children:e.text}),e.attachments?.length>0&&(0,n.jsxs)("span",{className:"shrink-0 text-text-muted flex items-center gap-0.5 font-mono text-[10px]",children:[(0,n.jsx)(el.xv,{size:10}),e.attachments.length]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 shrink-0 ml-2",children:[0===t&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),eH()},className:"text-text-muted hover:text-brand-400 p-1 rounded hover:bg-surface-2 transition-colors cursor-pointer",title:"Send now (stops the current turn)",children:(0,n.jsx)(el.Vn,{size:13})}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),o?.(e.id)},className:"text-text-muted hover:text-text p-1 rounded hover:bg-surface-2 transition-colors cursor-pointer",title:"Remove from queue",children:(0,n.jsx)(el.X,{size:14})})]})]},e.id))}),(0,n.jsx)(t6,{voice:ez,onDone:eM,onCancel:eP,className:"mb-1.5"}),(0,n.jsxs)("div",{className:"relative rounded-brand border border-border-subtle/80 bg-transparent focus-within:border-brand-500 transition-colors px-2.5 py-1 flex flex-col gap-1",children:[eC.length>0&&(0,n.jsx)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x pt-0.5",children:eC.map(e=>(0,n.jsxs)("div",{className:"relative flex-shrink-0 group",children:[e.isImage?(0,n.jsx)("img",{src:`data:${e.type};base64,${e.content}`,alt:e.name,className:"w-10 h-10 object-cover rounded border border-border-subtle"}):(0,n.jsxs)("div",{className:"w-10 h-10 flex flex-col items-center justify-center rounded border border-border-subtle bg-surface-2 px-1",children:[(0,n.jsx)(el.xv,{size:12,className:"text-text-muted"}),(0,n.jsx)("span",{className:"text-[8px] text-text-muted truncate w-full text-center",children:e.name})]}),(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>eT(e.id),className:"absolute -top-1.5 -right-1.5 w-4 h-4 flex items-center justify-center bg-surface-3 rounded-full text-text-muted hover:text-text border border-border-subtle","aria-label":"Remove attachment",children:(0,n.jsx)(el.X,{size:10})})]},e.id))}),(0,n.jsx)(tM,{value:K,store:tC,isMobile:!N,activeIndex:er,onSelect:eV}),(0,n.jsxs)("div",{className:"flex items-start gap-1",children:[(0,n.jsx)("textarea",{ref:eD,value:K,onPaste:eE,onChange:e=>{if(Date.now()-eW.current<200){eD.current&&(eD.current.value="");return}O(e.target.value),ea(-1)},onFocus:()=>b?.(),onKeyDown:e=>{if(w||e.nativeEvent?.isComposing||229===e.keyCode)return;if(e.shiftKey&&"Tab"===e.key){e.preventDefault(),e.stopPropagation(),(0,ed.e)();let t=T||[];if(t.length>0){let e=t.findIndex(e=>e.id===L),s=-1===e?0:(e+1)%t.length,n=t[s]?.id;n&&p?.(n)}return}if((e.ctrlKey||e.metaKey)&&("c"===e.key||"C"===e.key)&&B){let t=eD.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),eH();return}}if("Escape"===e.key){if(es){e.preventDefault(),en(null),X(!1),O("");return}if(q){e.preventDefault(),X(!1);return}if(B){e.preventDefault(),eH();return}if(W.length>0){e.preventDefault(),c?.();return}}if(es){let t=es.subOptions||[];if("ArrowDown"===e.key){e.preventDefault(),et(e=>(e+1)%t.length);return}if("ArrowUp"===e.key){e.preventDefault(),et(e=>(e-1+t.length)%t.length);return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),eX(t[ee]);return}}if(q&&Z.length>0){if("ArrowDown"===e.key){e.preventDefault(),et(e=>(e+1)%Z.length);return}if("ArrowUp"===e.key){e.preventDefault(),et(e=>(e-1+Z.length)%Z.length);return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),eq(Z[ee]);return}}if(em.length>0){let t=er<0?-1:(er%em.length+em.length)%em.length;if("Tab"===e.key&&!e.shiftKey){e.preventDefault(),ea(-1===t?0:(t+1)%em.length);return}if(("Enter"===e.key||"Tab"===e.key)&&-1!==t){e.preventDefault(),eV(em[t].cmd);return}}let t=eD.current,s=t?.selectionStart??0,n=t?.value??"",r=-1===n.lastIndexOf("\n",s-1),l=-1===n.indexOf("\n",s);if("ArrowUp"===e.key&&!es&&!q&&r&&ec.length>0){if(e.preventDefault(),s>0)return void t?.setSelectionRange(0,0);-1===_&&(U.current=K);let n=Math.min(_+1,ec.length-1);return void(n===_||(H(n),O(ec[n])))}if("ArrowDown"===e.key&&!es&&!q&&l&&-1!==_){if(e.preventDefault(),s<n.length)return void t?.setSelectionRange(n.length,n.length);let r=_-1;return void(r<0?(H(-1),O(U.current)):(H(r),O(ec[r])))}if("Enter"===e.key&&(e.metaKey||e.ctrlKey)){e.preventDefault(),e_();return}"Enter"===e.key&&!e.shiftKey&&N&&(e.preventDefault(),e_())},onCompositionStart:()=>{eF.current=!0},onCompositionEnd:()=>{eF.current=!1,eK.current=Date.now(),Date.now()-eW.current<200&&(eD.current&&(eD.current.value=""),O(""))},placeholder:B?N?"Type command \xb7 Enter to queue \xb7 Esc to stop":"Type command \xb7 Send to queue":N?`Type command \xb7 ${C}`:"Type command",rows:1,className:"ai-conversation ai-composer-input flex-1 min-w-0 bg-transparent resize-none text-xs text-text placeholder-text-muted focus:outline-none custom-scrollbar leading-snug min-h-[24px]"}),K.trim().length>0?(0,n.jsx)("button",{type:"button",onClick:eI,className:"shrink-0 mt-0.5 p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center justify-center",title:"Clear input",children:(0,n.jsx)(el.X,{size:16})}):(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),ek(!0)},className:"shrink-0 mt-0.5 p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center justify-center",title:j("history.title"),children:(0,n.jsx)(el.BZ,{size:16})})]}),(0,n.jsxs)("div",{className:"relative flex items-center justify-between text-xs pt-0.5 border-t border-border-subtle/30",children:[(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:(0,n.jsxs)("div",{ref:eN,className:"relative min-w-0 flex items-center gap-1",children:[(0,n.jsxs)("button",{type:"button",disabled:B,onClick:()=>{ef(!ep),ep||eb(""),ew(!1)},className:"min-w-0 px-1.5 py-0.5 rounded text-[11px] font-medium flex items-center gap-1 font-mono text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",title:B?"Cannot change model while turn is running":"Select model (/model)",children:[(0,n.jsx)("img",{src:e5(`${t}-ui`),alt:"",className:`w-3.5 h-3.5 object-contain shrink-0 ${e2}`}),(0,n.jsx)("span",{dir:"rtl",className:"truncate min-w-0",children:(0,n.jsx)("bdi",{children:eY})}),(0,n.jsx)(el.rX,{size:11,className:`text-text-muted shrink-0 transition-transform ${ep?"":"rotate-180"}`})]}),ep&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[260px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"Select Model"}),eQ.length>20&&(0,n.jsxs)("div",{className:"px-1.5 pb-1.5 mb-1 border-b border-border-subtle flex items-center gap-1.5 text-text-muted",children:[(0,n.jsx)(el.vj,{size:12,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:eh,onChange:e=>eb(e.target.value),placeholder:"Search models...",autoFocus:!0,className:"w-full bg-transparent text-[11px] text-text placeholder-text-muted/70 focus:outline-none py-0.5"})]}),0===e0.length&&(0,n.jsxs)("div",{className:"px-2 py-2 text-[11px] text-text-muted",children:['No models match "',eh,'"']}),e1.map(e=>(0,n.jsxs)("div",{children:[e1.length>1&&(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.key,void ev(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},"aria-expanded":!eg.has(e.key),className:"w-full px-2 py-0.5 text-[10px] font-mono uppercase tracking-wider font-semibold text-text flex items-center justify-between select-none border-b border-border-subtle mb-1 mt-1 first:mt-0",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-[8px]",children:eg.has(e.key)?"▶":"▼"}),e.title]}),(0,n.jsx)("span",{className:"text-[9px] text-text-subtle",children:e.items.length})]}),!eg.has(e.key)&&e.items.map(e=>{let t=F===e.id;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),m?.(e.id),ef(!1)},title:e.id,className:`w-full pl-4 pr-2 py-1.5 rounded text-left text-xs flex flex-col gap-0.5 transition-colors ${t?"bg-surface-2 text-text font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsxs)("span",{className:"w-full flex items-center justify-between",children:[(0,n.jsx)("span",{className:"truncate",children:e.label}),t&&(0,n.jsx)(el.aJ,{size:12,className:"text-text shrink-0 ml-1"})]}),e.label!==e.id&&(0,n.jsx)("span",{className:"truncate font-mono text-[10px] text-text-subtle",children:e.id})]},e.id)})]},e.key))]}),e4.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:B,onClick:()=>{ew(e=>!e),ef(!1)},className:"shrink-0 px-1 py-0.5 rounded text-[10px] uppercase tracking-wide font-mono text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",title:B?`Cannot change ${e3?.optionKey||"effort"} while turn is running`:`Select ${e3?.optionKey||"effort"}`,children:eZ||"—"}),ey&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[220px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:e3?.optionKey==="variant"?"Variant":"Reasoning effort"}),e4.map(e=>{let t=eZ===e.value;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),h?.(e3?.optionKey||"effort",e.value),ew(!1)},className:`w-full px-2 py-1.5 rounded text-left text-xs flex items-center justify-between gap-2 transition-colors ${t?"bg-brand-500/15 text-brand-400 font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),t&&(0,n.jsx)(el.aJ,{size:12,className:"text-brand-400 shrink-0"}),!t&&e.desc&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle truncate max-w-[55%]",children:e.desc})]},e.value)})]})]})]})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 pl-1.5",children:[(0,n.jsxs)("label",{className:"p-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors cursor-pointer flex items-center justify-center",title:"Attach file or image",children:[(0,n.jsx)(el.xv,{size:15}),(0,n.jsx)("input",{type:"file",multiple:!0,onChange:eR,className:"hidden",accept:"*/*"})]}),ez.active&&(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:eA,title:j("not-allowed"===ez.error||"service-not-allowed"===ez.error?"voice.denied":"voice.dictate"),"aria-label":j("voice.dictate"),className:`p-1.5 rounded flex items-center justify-center transition-colors ${ez.listening?"bg-red-500/90 text-white animate-pulse":ez.error?"text-red-400":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:ez.listening?(0,n.jsx)(el.jj,{size:15}):(0,n.jsx)(el.GO,{size:15})}),B?(0,n.jsxs)(n.Fragment,{children:[(K.trim()||eC.length>0)&&(0,n.jsxs)("button",{type:"button",onClick:e_,className:"px-2 py-0.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 text-[11px] font-medium transition-colors shadow-sm cursor-pointer",title:N?"Queue message (Enter)":"Queue message",children:[(0,n.jsx)(el.Vn,{size:13}),(0,n.jsx)("span",{children:"Queue"})]}),(0,n.jsx)("button",{type:"button",onClick:eH,className:"px-2 py-0.5 rounded bg-danger/20 hover:bg-danger/30 text-danger flex items-center gap-1 text-[11px] font-medium transition-colors cursor-pointer",title:W.length?"Stop & run the next queued message (Esc)":"Stop generation (Esc)",children:(0,n.jsx)(el.M6,{size:13,className:"fill-current"})})]}):(0,n.jsx)("button",{type:"button",onClick:e_,disabled:!K.trim()&&0===eC.length,className:`px-2 py-1 rounded transition-colors flex items-center justify-center ${K.trim()||eC.length>0?"bg-brand-500 hover:bg-brand-600 text-white shadow-sm cursor-pointer":"text-text-muted bg-surface-2 cursor-not-allowed opacity-40"}`,title:"Send (Enter)",children:(0,n.jsx)(el.Vn,{size:14})})]})]})]}),(0,n.jsx)(tT,{isOpen:ej,store:tC,onSelect:eV,onClose:()=>ek(!1)})]})}),on={Shield:"text-text-muted",Pencil:"text-accent",Eye:"text-accent",Sparkles:"text-warning"},or=(0,r.memo)(function({sessionId:e="",sessionName:t="",engine:s="claude",workspacePath:l="",fileBus:a=null,isTurnRunning:i=!1,isDesktop:o=!0,onModeChange:c,onNewChat:d}){let u=rH(t=>t.bySession[e]?.isTurnRunning),x=rH(t=>t.bySession[e]?.metadata),m=x?.goal,p=(0,ri.Tw)(s).permissionModes||[],f=rH(t=>t.bySession[e]?.permissionMode)||(0,ri.Tw)(s).defaultMode,{branch:h,dirty:b}=n8(l,a,{enabled:!!a&&!!l}),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=e=>{y.current&&!y.current.contains(e.target)&&v(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let w=p.find(e=>e.id===f)||p[0];return(0,n.jsxs)("div",{className:`relative min-h-6 px-3 bg-surface/50 border-t border-border-subtle/50 flex items-center text-[11px] font-mono text-text-muted select-none flex-shrink-0 z-20 gap-3${o?"":" safe-area-bottom"}`,children:[(void 0!==u?u:i)&&(0,n.jsx)(iJ,{className:"hidden sm:block"}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[w&&p.length>0&&(0,n.jsxs)("div",{ref:y,className:"relative",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),v(e=>!e)},className:"hover:text-text flex items-center gap-1 transition-colors",title:"Change permission mode (Shift+Tab)",children:[(0,n.jsx)(el.Ay,{name:w.icon||"Shield",size:11,className:`${on[w.icon]||"text-text-muted"} shrink-0`}),(0,n.jsx)("span",{children:w.label}),(0,n.jsx)(el.rX,{size:11,className:`text-text-muted transition-transform ${g?"":"rotate-180"}`})]}),g&&(0,n.jsxs)("div",{className:"absolute left-0 bottom-[calc(100%+6px)] min-w-[220px] max-h-56 bg-surface border border-border-subtle rounded-brand shadow-xl overflow-y-auto z-50 p-1 custom-scrollbar",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 text-[10px] text-text-muted font-mono uppercase tracking-wider border-b border-border-subtle mb-1",children:"Permission Mode"}),p.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),c?.(e.id),v(!1)},className:`w-full px-2 py-1.5 rounded text-left text-xs flex flex-col gap-0.5 transition-colors cursor-pointer ${f===e.id?"bg-brand-500/15 text-brand-400 font-semibold":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(el.Ay,{name:e.icon||"Shield",size:12,className:`${on[e.icon]||"text-text-muted"} shrink-0`}),(0,n.jsx)("span",{children:e.label})]}),f===e.id&&(0,n.jsx)(el.aJ,{size:12,className:"text-brand-400 shrink-0"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted/70 font-normal font-sans leading-tight",children:e.desc})]},e.id))]})]}),m?.objective&&(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",title:`Goal (${m.status}): ${m.objective}`,children:[(0,n.jsx)(el.We,{size:11,className:`shrink-0 ${"active"===m.status?"text-danger":"text-text-muted"}`}),(0,n.jsx)("span",{className:"truncate max-w-[22ch]",children:m.objective})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 shrink-0",children:[h&&!(0,eJ.ok)(h)&&(0,n.jsx)(n9,{branch:h,dirty:b,size:11,className:"text-text font-medium",iconClassName:"text-brand-500 opacity-100"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),d?.()},className:"hover:text-text flex items-center transition-colors p-0.5 rounded hover:bg-surface-2",title:"New chat",children:(0,n.jsx)(el.J4,{size:12})})]})]})}),ol=(0,r.memo)(function({skills:e=[],onClose:t,onSelectSkill:s}){let[l,a]=(0,r.useState)(""),i=e.filter(e=>{let t=l.toLowerCase();return(e.name||e.id||"").toLowerCase().includes(t)||(e.description||"").toLowerCase().includes(t)});return(0,n.jsxs)(ns,{icon:(0,n.jsx)(el.Kq,{size:14}),title:`Agent Skills (${e.length})`,subtitle:"Skills loaded from ~/.claude/skills and project directory",onClose:t,children:[(0,n.jsx)("div",{className:"p-3 border-b border-border-subtle bg-bg",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-brand bg-surface border border-border-subtle focus-within:border-brand-500",children:[(0,n.jsx)(el.vj,{size:14,className:"text-text-muted shrink-0"}),(0,n.jsx)("input",{type:"text",value:l,onChange:e=>a(e.target.value),placeholder:"Search skills (e.g. cloudflare, review, deploy)...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted focus:outline-none",autoFocus:!0})]})}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(el.Kq,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:0===e.length?"No skills discovered on host agent.":`No skills matching "${l}".`})]}):i.map(e=>(0,n.jsxs)("div",{onClick:()=>{(0,ed.e)(),s?.(e.name||e.id),t?.()},className:"modal-row items-start",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1 flex flex-col gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 font-mono text-xs font-semibold text-text",children:[(0,n.jsxs)("span",{children:["/",e.name||e.id]}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-3 text-text-muted font-normal",children:"skill"})]}),e.description&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted leading-relaxed line-clamp-2",children:e.description})]}),(0,n.jsxs)("span",{className:"modal-row-acts text-[11px] text-brand-500 items-center gap-1",children:[(0,n.jsx)("span",{children:"Use"}),(0,n.jsx)(el.Lt,{size:11})]})]},e.id||e.name))})]})}),oa=(0,r.memo)(function({mcpServers:e=[],onClose:t}){return(0,n.jsx)(ns,{icon:(0,n.jsx)(el.lP,{size:14}),title:`MCP Servers (${e.length})`,subtitle:"Model Context Protocol tools and integrations",onClose:t,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===e.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(el.lP,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:"No MCP servers configured yet."})]}):e.map((e,t)=>(0,n.jsxs)("div",{className:"modal-row",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"text-xs font-semibold text-text flex items-center gap-2",children:[(0,n.jsx)(el.Jl,{size:13,className:"text-emerald-400 shrink-0"}),(0,n.jsx)("span",{className:"font-mono",children:e.name||e.id})]}),e.command&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted font-mono break-all mt-1",children:e.command})]}),(0,n.jsx)("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-emerald-500/15 text-emerald-300 border border-emerald-500/30 uppercase shrink-0 ml-2",children:e.status||"active"})]},e.id||t))})})}),oi=(0,r.memo)(function({currentModel:e="",currentEffort:t="",models:s=[],onClose:l,onSelectModel:a,onSelectEffort:i,isTurnRunning:o=!1}){let[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(e),[m,p]=(0,r.useState)(()=>new Set),f=(0,r.useMemo)(()=>{let t=[...s||[]];return e&&!t.some(t=>t.id===e)&&t.unshift({id:e,label:e,desc:"Active CLI model",recent:!0}),t},[s,e]),h=f.find(e=>e.id===u),b=h?.efforts||[],g=(0,r.useMemo)(()=>{let e=c.trim().toLowerCase();return e?f.filter(t=>{let s=(t.label||"").toLowerCase(),n=(t.id||"").toLowerCase(),r=(t.desc||"").toLowerCase(),l=i7(t).toLowerCase();return s.includes(e)||n.includes(e)||r.includes(e)||l.includes(e)}):f},[f,c]),v=(0,r.useMemo)(()=>oe(f,g,e,c.trim()),[f,g,e,c]);return(0,n.jsxs)(ns,{icon:(0,n.jsx)(el.cC,{size:14}),title:"Switch AI Model",subtitle:"Select an active model for this session",maxWidth:"max-w-md",onClose:l,children:[(0,n.jsx)("div",{className:"px-4 py-2.5 border-b border-border-subtle shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 focus-within:text-text text-text-muted",children:[(0,n.jsx)(el.vj,{size:14,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Search models...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted/70 focus:outline-none",autoFocus:!0}),c&&(0,n.jsx)("button",{type:"button",onClick:()=>d(""),className:"text-text-muted hover:text-text shrink-0 text-xs px-1","aria-label":"Clear search",children:"✕"})]})}),b.length>0&&(0,n.jsxs)("div",{className:"px-3 pt-3 shrink-0",children:[(0,n.jsx)("div",{className:"text-[10px] font-mono uppercase tracking-wider text-text-muted mb-1.5",children:"Reasoning effort"}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:b.map(e=>(0,n.jsx)("button",{type:"button",disabled:o,onClick:()=>{(0,ed.e)(),i?.(e)},className:`px-2.5 py-1 rounded-brand text-[11px] font-mono border transition-colors ${t===e?"border-brand-500 bg-brand-500/10 text-brand-400":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"} disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent`,title:o?"Cannot change effort while turn is running":void 0,children:e},e))})]}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===g.length?(0,n.jsxs)("div",{className:"py-8 text-center text-xs text-text-muted",children:['No models found matching "',c,'"']}):v.map(e=>(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 mb-2",children:[v.length>1&&(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.key,void p(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},"aria-expanded":!m.has(e.key),className:"w-full text-left text-[10px] font-mono uppercase tracking-wider font-semibold text-text px-2 pt-2 pb-1 select-none flex items-center justify-between border-b border-border-subtle",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-[8px]",children:m.has(e.key)?"▶":"▼"}),e.title]}),(0,n.jsx)("span",{className:"text-text-subtle text-[9px]",children:e.items.length})]}),!m.has(e.key)&&e.items.map(s=>{var r;let l=u===s.id,c=i7(s),d=(r=s.contextWindow)&&!(r<=0)?r>=1e6?`${Math.round(r/1e5)/10}M`:r>=1e3?`${Math.round(r/1e3)}k`:`${r}`:null;return(0,n.jsxs)("div",{onClick:o?void 0:()=>(e=>{(0,ed.e)(),a?.(e),x(e);let s=f.find(t=>t.id===e),n=s?.efforts||[];if(n.length>0&&!n.includes(t)){let e=s?.defaultEffort||n[0];e&&i?.(e)}})(s.id),"data-selected":l,className:`modal-row ml-2 ${o?"opacity-40 cursor-not-allowed pointer-events-none":""}`,title:o?"Cannot change model while turn is running":s.id,children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:`text-xs flex items-center gap-1.5 flex-wrap ${l?"text-text font-semibold":"text-text-muted"}`,children:[(0,n.jsx)("span",{className:"truncate",children:s.label||s.id}),"opencode"===c&&(0,n.jsx)("span",{className:"text-[9px] px-1.5 py-0.2 rounded bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 font-mono shrink-0",children:"Free"}),d&&(0,n.jsx)("span",{className:"text-[9px] px-1 py-0.2 rounded bg-surface-2/60 text-text-subtle font-mono shrink-0",children:d}),s.efforts?.length>0&&(0,n.jsx)("span",{className:"text-[9px] px-1 py-0.2 rounded bg-brand-500/10 text-brand-400 font-mono shrink-0",children:"reasoning"})]}),(s.desc||s.label!==s.id&&s.id)&&(0,n.jsx)("div",{className:"text-[10px] font-mono text-text-subtle truncate mt-0.5",children:s.desc||s.id})]}),l&&(0,n.jsx)(el.aJ,{size:14,className:"text-text shrink-0"})]},`${e.key}-${s.id}`)})]},e.key))})]})}),oo=(0,r.memo)(function({engine:e="claude",workspacePath:t="",bus:s=null,onClose:l,onResume:a}){let[i,o]=(0,r.useState)([]),[c,d]=(0,r.useState)(!0),[u,x]=(0,r.useState)(""),m=eM(),p=(0,r.useCallback)(()=>{if(!s?.emit||!t){o([]),d(!1);return}d(!0),s.emit("getAgentSessions",{cwd:t},e=>{o(Array.isArray(e?.sessions)?e.sessions:[]),d(!1)})},[t]);(0,r.useEffect)(()=>{p()},[p]);let f=(0,r.useMemo)(()=>{let t=u.toLowerCase();return i.filter(t=>!e||t.agent===e).filter(e=>!t||(e.title||"").toLowerCase().includes(t)||(e.sessionId||"").toLowerCase().includes(t))},[i,e,u]);return(0,n.jsxs)(ns,{icon:(0,n.jsx)(el.BZ,{size:14}),title:"Resume a session",subtitle:`Past ${e} conversations in this project`,maxWidth:"max-w-xl",onClose:l,children:[(0,n.jsx)("div",{className:"px-4 py-2.5 border-b border-border-subtle shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 focus-within:text-text text-text-muted",children:[(0,n.jsx)(el.vj,{size:14,className:"shrink-0"}),(0,n.jsx)("input",{type:"text",value:u,onChange:e=>x(e.target.value),placeholder:"Search sessions...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted/70 focus:outline-none",autoFocus:!0}),(0,n.jsx)("button",{type:"button",onClick:p,className:"hover:text-text shrink-0",title:"Refresh",children:(0,n.jsx)(el.e9,{size:13,className:c?"animate-spin":""})})]})}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:c?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-text-muted",children:[(0,n.jsx)(el.kr,{size:14,className:"animate-spin"}),(0,n.jsx)("span",{children:"Scanning conversations..."})]}):0===f.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(el.BZ,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:0===i.length?"No past conversations found for this project.":`No sessions matching "${u}".`})]}):f.map(e=>{let t=!!e.openSessionId&&!!m[e.openSessionId];return(0,n.jsxs)("div",{onClick:()=>{if((0,ed.e)(),t){window.dispatchEvent(new CustomEvent(eJ.vP,{detail:{sessionId:e.openSessionId}})),l?.();return}(0,ed.e)(),a?.(e),l?.()},className:"modal-row",title:e.sessionId,children:[(0,n.jsx)("img",{src:e5("ui"===e.mode?`${e.agent}-ui`:e.agent),alt:e.agent,className:`shrink-0 ${e2} ${t?"":"opacity-50"}`,style:{width:14,height:14}}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-xs ${t?"text-text font-medium":"text-text-muted"}`,children:e.title||"Untitled conversation"}),e.updatedAt?(0,n.jsx)("span",{className:"shrink-0 text-[10px] font-mono text-text-subtle tabular-nums",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m ago`;let s=Math.round(t/60);return s<24?`${s}h ago`:`${Math.round(s/24)}d ago`}(e.updatedAt)}):null]},`${e.agent}:${e.sessionId}`)})})]})}),oc={claude:{shape:"flat",items:[]},codex:{shape:"flat",items:[{key:"personality",kind:"menu",label:"Personality",desc:"Communication style codex is instructed to use",choices:[{value:"",label:"Default"},...ri.Mm],default:""},{key:"networkAccess",kind:"bool",label:"Network access",desc:"Let sandboxed commands reach the network",default:!1},{key:"planEffort",kind:"menu",label:"Plan mode reasoning",desc:"Reasoning tier used while in plan mode",choices:[{value:"",label:"Default"},{value:"low",label:"low"},{value:"medium",label:"medium"},{value:"high",label:"high"},{value:"xhigh",label:"xhigh"}],default:""},{key:"addDirs",kind:"list",label:"Extra writable directories",desc:"Absolute paths, comma-separated",default:[]},{key:"enable",kind:"list",label:"Enable features",desc:"Feature names, comma-separated (see `codex features list`)",default:[]},{key:"disable",kind:"list",label:"Disable features",desc:"Feature names, comma-separated",default:[]},{key:"skipGitRepoCheck",kind:"bool",label:"Allow outside a git repo",desc:"Run in a directory without a repository",default:!1},{key:"ephemeral",kind:"bool",label:"Ephemeral run",desc:"Do not persist the session to disk",default:!1}]},opencode:{shape:"flags",items:[{key:"pure",kind:"bool",label:"Pure mode",desc:"Run without external plugins",default:!1},{key:"printLogs",kind:"bool",label:"Print logs",desc:"Show CLI logs on stderr",default:!1}]}};function od(e){return oc[e]||{shape:"flat",items:[]}}let ou=(0,r.memo)(function({engine:e="claude",options:t,onClose:s,onApply:l}){let{shape:a,items:i}=od(e),[o,c]=(0,r.useState)(()=>{let s,n;return s=od(e).items,n=t||{},Object.fromEntries(s.map(e=>[e.key,void 0!==n[e.key]?n[e.key]:e.default]))}),d=(e,t)=>c(s=>({...s,[e]:t}));return(0,n.jsx)(ns,{icon:(0,n.jsx)(el.wB,{size:14}),title:"Configuration",subtitle:`Runtime flags for ${e}`,maxWidth:"max-w-md",onClose:s,footer:i.length>0?(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border-subtle flex justify-end gap-2 shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"px-3 py-1.5 rounded-brand text-xs text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)();let e={};for(let t of i){let s=o[t.key];"list"===t.kind?e[t.key]=String(s||"").split(",").map(e=>e.trim()).filter(Boolean):e[t.key]=s}l?.("flags"===a?{flags:e}:e),s?.()},className:"px-3 py-1.5 rounded-brand text-xs bg-brand-500 hover:bg-brand-600 text-white font-medium transition-colors",children:"Apply"})]}):null,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-2 custom-scrollbar",children:0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(el.wB,{size:32,className:"opacity-50"}),(0,n.jsxs)("span",{className:"text-sm",children:["No runtime flags are configurable for ",e,"."]})]}):i.map(e=>(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-surface-2/50",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text",children:e.label}),(0,n.jsx)("div",{className:"text-[11px] text-text-muted",children:e.desc})]}),"bool"===e.kind&&(0,n.jsx)("input",{type:"checkbox",checked:!!o[e.key],onChange:()=>d(e.key,!o[e.key]),className:"w-4 h-4 accent-brand-500 rounded shrink-0"})]}),"menu"===e.kind&&(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-2",children:e.choices.map(t=>(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),d(e.key,t.value)},className:`px-2.5 py-1 rounded-brand text-[11px] border transition-colors ${o[e.key]===t.value?"border-brand-500 bg-brand-500/10 text-brand-400":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"}`,children:t.label},t.value))}),"list"===e.kind&&(0,n.jsx)("input",{type:"text",value:Array.isArray(o[e.key])?o[e.key].join(", "):o[e.key]||"",onChange:t=>d(e.key,t.target.value),placeholder:"/path/one, /path/two",className:"mt-2 w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs font-mono text-text placeholder-text-muted focus:outline-none focus:border-brand-500"})]},e.key))})})}),ox={Shield:"text-text-muted",Pencil:"text-accent",Eye:"text-accent",Sparkles:"text-warning"},om=(0,r.memo)(function({modes:e=[],currentMode:t="",onClose:s,onSelectMode:r}){return(0,n.jsx)(ns,{icon:(0,n.jsx)(el.Ay,{name:"Shield",size:14}),title:"Permissions",subtitle:"What the agent may do without asking",maxWidth:"max-w-md",onClose:s,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:e.map(e=>{let l=t===e.id;return(0,n.jsxs)("div",{onClick:()=>{var t;return t=e.id,void((0,ed.e)(),r?.(t),s?.())},"data-selected":l,className:"modal-row",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[(0,n.jsx)(el.Ay,{name:e.icon||"Shield",size:14,className:`${ox[e.icon]||"text-text-muted"} shrink-0`}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text",children:e.label}),(0,n.jsx)("div",{className:"text-[11px] text-text-subtle",children:e.desc})]})]}),l&&(0,n.jsx)(el.aJ,{size:14,className:"text-brand-500 shrink-0"})]},e.id)})})})}),op=(0,r.memo)(function({engine:e="claude",workspacePath:t="",bus:s=null,onClose:l}){let[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!0),d=(0,r.useCallback)(()=>{if(!s?.emit){i({error:"Not connected to the host agent."}),c(!1);return}c(!0),s.emit("ai:doctor",{engine:e,cwd:t},e=>{i(e?.ok?{output:e.output||"",version:e.version||""}:{error:e?.error||"Doctor check failed."}),c(!1)})},[e,t]);return(0,r.useEffect)(()=>{d()},[d]),(0,n.jsxs)(ns,{icon:(0,n.jsx)(el.mN,{size:14}),title:"Diagnostics",subtitle:`Health check for the ${e} CLI`,onClose:l,children:[(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto custom-scrollbar",children:o?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-8 text-xs text-text-muted",children:[(0,n.jsx)(el.kr,{size:14,className:"animate-spin"}),(0,n.jsxs)("span",{children:["Running ",e," doctor..."]})]}):a?.error?(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-danger/10 border border-danger/30 text-danger text-xs flex items-start gap-2",children:[(0,n.jsx)(el.RI,{size:14,className:"shrink-0 mt-0.5"}),(0,n.jsx)("span",{children:a.error})]}):(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"p-3 rounded-brand bg-emerald-500/10 border border-emerald-500/30 text-emerald-300 text-xs flex items-center gap-2",children:[(0,n.jsx)(el.Jl,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"font-medium",children:a?.version?`${e} ${a.version}`:`${e} environment report`})]}),(0,n.jsx)("pre",{className:"p-3 rounded-brand bg-bg border border-border-subtle text-[11px] font-mono text-text-muted whitespace-pre-wrap break-words leading-relaxed",children:a?.output||"No output."})]})}),(0,n.jsx)("div",{className:"px-4 py-3 border-t border-border-subtle flex justify-end shrink-0",children:(0,n.jsxs)("button",{type:"button",onClick:d,disabled:o,className:"px-3 py-1.5 rounded-brand text-xs text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-1.5 disabled:opacity-50",children:[(0,n.jsx)(el.e9,{size:12,className:o?"animate-spin":""}),(0,n.jsx)("span",{children:"Re-run"})]})})]})}),of={completed:{icon:el.Jl,cls:"text-emerald-400",line:"line-through text-text-muted"},in_progress:{icon:el.kr,cls:"text-sky-400 animate-spin",line:"text-sky-300 font-semibold"},pending:{icon:el.jl,cls:"text-text-muted",line:"text-text"}},oh=(0,r.memo)(function({tasks:e=[],onClose:t}){let s=e.length,r=e.filter(e=>"completed"===e.status).length,l=e.filter(e=>"in_progress"===e.status).length,a=s-r-l;return(0,n.jsxs)(ns,{icon:(0,n.jsx)(el.y8,{size:14}),title:`Tasks (${s})`,subtitle:"Checklist the agent is working through",onClose:t,children:[(0,n.jsx)("div",{className:"grid grid-cols-4 gap-2 px-4 py-3 border-b border-border-subtle bg-bg text-center shrink-0",children:[{label:"TOTAL",value:s,cls:"text-text"},{label:"RUNNING",value:l,cls:"text-sky-400"},{label:"DONE",value:r,cls:"text-emerald-400"},{label:"PENDING",value:a,cls:"text-text-muted"}].map(e=>(0,n.jsxs)("div",{className:"p-2 rounded-brand bg-surface-2/40",children:[(0,n.jsx)("div",{className:"text-[10px] text-text-muted font-mono",children:e.label}),(0,n.jsx)("div",{className:`text-base font-bold ${e.cls}`,children:e.value})]},e.label))}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===s?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(el.y8,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:"No tasks in this session yet."})]}):e.map((e,t)=>{let s=of[e.status]||of.pending,r=s.icon;return(0,n.jsxs)("div",{className:"modal-row items-start",children:[(0,n.jsx)(r,{size:14,className:`${s.cls} shrink-0 mt-0.5`}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:`text-xs ${s.line}`,children:e.subject||e.activeForm||"(untitled task)"}),e.activeForm&&"in_progress"===e.status&&(0,n.jsx)("div",{className:"text-[11px] text-sky-400/80 font-mono mt-0.5 truncate",children:e.activeForm})]}),e.taskId&&(0,n.jsxs)("span",{className:"text-[10px] font-mono text-text-muted shrink-0",children:["#",e.taskId]})]},e.id||t)})})]})}),ob=(0,r.memo)(function({sessionId:e="",onListPoints:t,onPreview:s,onApply:l,onClose:a}){let[i,o]=(0,r.useState)([]),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(!0),[m,p]=(0,r.useState)(null),[f,h]=(0,r.useState)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)("");(0,r.useEffect)(()=>{let e=!0;return t?.().then(t=>{e&&(t||y("The host did not answer. Try again."),o(t?.points||[]),d(t?.support||null),x(!1))}).catch(()=>{e&&(y("Could not read this conversation."),x(!1))}),()=>{e=!1}},[t]);let w=(0,r.useCallback)(async e=>{(0,ed.e)(),p(e),h(null),y("");let t=await s?.(e.messageId);t?.ok?h(t):y(t?.error||"The host could not preview this rewind.")},[s]),j=(0,r.useCallback)(async()=>{if(!m)return;(0,ed.e)(),g(!0),y("");let e=await l?.(m.messageId);(g(!1),e?.ok)?a?.():y(e?.error||"The rewind did not go through.")},[m,l,a]),k=c&&!c.conversation;return(0,n.jsx)(ns,{icon:(0,n.jsx)(el.BZ,{size:14}),title:"Rewind",subtitle:"Go back to an earlier prompt. Turns after it are discarded.",maxWidth:"max-w-xl",onClose:a,children:u?(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-12 text-xs text-text-muted",children:[(0,n.jsx)(el.kr,{size:14,className:"animate-spin"}),(0,n.jsx)("span",{children:"Reading this conversation..."})]}):k?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 py-12 px-6 text-center text-text-muted",children:[(0,n.jsx)(el.RI,{size:28,className:"opacity-60"}),(0,n.jsx)("span",{className:"text-sm",children:c.how||"This engine cannot rewind a conversation."})]}):0===i.length?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 py-12 text-text-muted",children:[(0,n.jsx)(el.BZ,{size:32,className:"opacity-50"}),(0,n.jsx)("span",{className:"text-sm",children:v||"Nothing to rewind to yet."})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar max-h-[45vh]",children:[...i].reverse().map(e=>(0,n.jsxs)("div",{onClick:()=>w(e),className:`modal-row ${m?.messageId===e.messageId?"modal-row-active":""}`,children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-xs text-text truncate",children:e.text||"Untitled prompt"}),e.createdAt&&(0,n.jsx)("div",{className:"mt-1 text-[10px] font-mono text-text-subtle",children:function(e){if(!e)return"";let t=Math.round((Date.now()-e)/6e4);if(t<60)return`${Math.max(1,t)}m ago`;let s=Math.round(t/60);return s<24?`${s}h ago`:`${Math.round(s/24)}d ago`}(Date.parse(e.createdAt))})]}),(0,n.jsxs)("span",{className:"modal-row-acts text-[11px] text-brand-500 items-center gap-1",children:[(0,n.jsx)("span",{children:m?.messageId===e.messageId?"Selected":"Pick"}),(0,n.jsx)(el.Lt,{size:11})]})]},e.messageId))}),v&&(0,n.jsx)("div",{className:"px-3 py-2 border-t border-border-subtle text-[11px] text-danger bg-danger/5",children:v}),(0,n.jsxs)("div",{className:"p-3 border-t border-border-subtle bg-bg shrink-0 flex flex-col gap-2",children:[m&&(0,n.jsx)("div",{className:"text-[11px] leading-relaxed text-text-muted",children:f?.files?.length>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text",children:f.files.length})," file",1===f.files.length?"":"s"," will be restored.",(0,n.jsxs)("ul",{className:"mt-1 flex flex-col gap-0.5",children:[f.files.slice(0,8).map(e=>(0,n.jsxs)("li",{className:"truncate font-mono text-[10px]",title:e.file,children:["\xb7 ",e.file,e.status?` (${e.status})`:""]},e.file)),f.files.length>8&&(0,n.jsxs)("li",{className:"text-[10px]",children:["… and ",f.files.length-8," more"]})]}),f.note&&(0,n.jsx)("span",{className:"block mt-1 text-text-subtle",children:f.note})]}):f?(0,n.jsx)("span",{className:"block text-text-subtle",children:f.note}):(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(el.kr,{size:11,className:"animate-spin"}),"Checking what this would change..."]})}),(0,n.jsxs)("button",{type:"button",onClick:j,disabled:!m||b||!f?.ok,className:`px-3 py-1.5 rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors ${m&&!b&&f?.ok?"bg-brand-500 hover:bg-brand-600 text-white cursor-pointer":"bg-surface-2 text-text-muted cursor-not-allowed opacity-50"}`,children:[b?(0,n.jsx)(el.kr,{size:13,className:"animate-spin"}):(0,n.jsx)(el.aJ,{size:13}),(0,n.jsx)("span",{children:b?"Rewinding...":"Rewind to this prompt"})]})]})]})})}),og=(0,r.memo)(function({requestId:e="",tool:t="",input:s={},failed:l=!1,onResolve:a}){let[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),u=function(e){if(e?.kind!=="permission_grant")return"";let t=[],s=String(e.reason||"").trim();return s&&t.push(s),t.push(...function(e={}){let t=[];e?.network?.enabled&&t.push("• network access");let s=e?.fileSystem||{};for(let e of s.read||[])t.push(`• read ${e}`);for(let e of s.write||[])t.push(`• write ${e}`);for(let e of s.entries||[]){var n;let s="string"==typeof(n=e?.path)?n:n?.path||n?.pattern||n?.value||"";s&&t.push(`• ${e.access||"access"} ${s}`)}return t}(e.permissions)),t.join("\n")}(s)||s?.command||s?.path||JSON.stringify(s||{});return(0,n.jsxs)("div",{className:"my-3 p-3 rounded-brand-lg border border-warning/30 bg-surface shadow-sm text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-warning font-medium",children:[(0,n.jsx)(el.ek,{size:16}),(0,n.jsx)("span",{children:"Permission Request"}),(0,n.jsx)("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-warning/15 text-warning uppercase min-w-0 break-all",title:t,children:t||"Action"})]}),(0,n.jsx)("div",{className:"p-2.5 rounded bg-bg font-mono text-[11px] text-text break-all border border-border-subtle mb-3 max-h-[140px] overflow-y-auto",children:u}),c&&(0,n.jsx)("div",{className:"mb-3",children:(0,n.jsx)("input",{type:"text",value:i,onChange:e=>o(e.target.value),placeholder:"Reason for denial or alternative instructions...",className:"w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs text-text placeholder-text-muted focus:outline-none focus:border-brand-500",autoFocus:!0})}),l&&(0,n.jsx)("div",{className:"mb-3 text-[11px] text-danger leading-snug",children:"Not sent — the host did not answer. Try again."}),(0,n.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[c?(0,n.jsx)("button",{type:"button",onClick:()=>d(!1),className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Hide note"}):(0,n.jsx)("button",{type:"button",onClick:()=>d(!0),className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors",children:"Add note"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),a?.(e,"deny",i||"User denied")},className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-danger/20 text-danger flex items-center gap-1 font-medium transition-colors",children:[(0,n.jsx)(el.X,{size:14}),(0,n.jsx)("span",{children:"Deny"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),a?.(e,"allow")},className:"px-3.5 py-1.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 font-medium transition-colors shadow-sm",children:[(0,n.jsx)(el.aJ,{size:14}),(0,n.jsx)("span",{children:"Allow"})]})]})]})}),ov=(0,r.memo)(function({engine:e="",message:t="",reason:s="",escalate:r=null,onEscalate:l,onDismiss:a}){return(0,n.jsxs)("div",{className:"my-3 p-3 rounded-brand-lg border border-danger/40 bg-surface shadow-sm text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-danger font-medium",children:[(0,n.jsx)(el.ek,{size:16}),(0,n.jsx)("span",{children:"Action blocked"}),e&&(0,n.jsx)("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-danger/15 text-danger uppercase",children:e})]}),(0,n.jsx)("div",{className:"p-2.5 rounded bg-bg text-[11px] text-text border border-border-subtle mb-3 whitespace-pre-wrap break-words max-h-[160px] overflow-y-auto",children:t||s||"The CLI refused this action under the current permission mode."}),(0,n.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),a?.()},className:"px-2.5 py-1.5 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-1",children:[(0,n.jsx)(el.X,{size:13}),(0,n.jsx)("span",{children:"Dismiss"})]}),r?.mode&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),l?.(r?.mode)},className:"px-3.5 py-1.5 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 font-medium transition-colors shadow-sm",children:[(0,n.jsx)(el.sU,{size:14}),(0,n.jsxs)("span",{children:["Switch to ",r.label||r.mode]})]})]})]})}),oy=[],ow=(0,r.memo)(function({sessionId:e=""}){let[t,s]=(0,r.useState)(!1),l=rH(t=>t.bySession[e]?.tasks),a=(0,r.useMemo)(()=>Array.isArray(l)?l.filter(e=>!!(e&&e.subject&&String(e.subject).trim().length>0)):oy,[l]);if(0===a.length)return null;let i=a.filter(e=>"completed"===e.status).length,o=a.find(e=>"in_progress"===e.status),c=i===a.length;return(0,n.jsxs)("div",{className:"px-4 sm:px-6 py-1 border-b border-border-subtle/40 bg-surface-2/20 shrink-0 text-xs select-none",children:[(0,n.jsx)("div",{onClick:()=>s(!t),className:"flex items-center justify-between py-1 px-0 hover:bg-surface-2/40 cursor-pointer data-pane-control transition-colors group",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[c?(0,n.jsx)(el.Jl,{size:13,className:"text-success shrink-0"}):o?(0,n.jsx)(el.y8,{size:13,className:"text-brand-500 shrink-0"}):(0,n.jsx)(el.y8,{size:13,className:"text-text-muted shrink-0"}),(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:"TASKS"}),(0,n.jsxs)("span",{className:"font-mono text-[11px] text-text-muted shrink-0",children:[i,"/",a.length]}),o&&(0,n.jsx)("span",{className:"text-[11px] text-brand-500 truncate min-w-0 font-medium",children:o.activeForm||o.subject}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 ml-auto",children:t?(0,n.jsx)(el.yQ,{size:11}):(0,n.jsx)(el.c_,{size:11})})]})}),t&&(0,n.jsx)("div",{className:"mt-1 ml-3.5 pl-3 border-l-2 border-border-subtle/80 py-1 space-y-0.5 animate-in fade-in duration-100",children:a.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-2 py-0.5",children:["completed"===e.status?(0,n.jsx)(el.Jl,{size:12,className:"text-success shrink-0"}):"in_progress"===e.status?(0,n.jsx)(el.jG,{size:10,className:"text-brand-500 fill-brand-500 shrink-0"}):(0,n.jsx)(el.jl,{size:12,className:"text-text-muted/50 shrink-0"}),(0,n.jsx)("span",{className:`text-[11px] truncate ${"completed"===e.status?"line-through text-text-muted/60":"in_progress"===e.status?"text-text font-medium":"text-text-muted"}`,children:e.subject})]},e.id||t))})]})}),oj=[],ok=(0,r.memo)(function({sessionId:e="",engine:t="claude",onStopTask:s}){let l=rH(t=>t.bySession[e]?.messages)||oj,a=rH(t=>t.bySession[e]?.harnessTasks)||oj,i=(0,r.useMemo)(()=>(function(e=[],t=[]){return t.length>0?t.filter(e=>e?.status==="running").map(e=>({kind:e.background?"shell":"agent",id:e.toolUseId||e.taskId,taskId:e.taskId,label:e.description||e.subagentType||"task",startedAt:e.startedAt,taskType:e.taskType,subagentType:e.subagentType,usage:e.usage,toolUseId:e.toolUseId})):function(e=[]){let t=[],s=e=>{for(let n of e||[]){if(n?.status==="running"){let e=n.startedAt||n.timestamp,s=e?{startedAt:e}:null;rt.has(n?.name)?t.push({kind:"agent",id:n.id,label:rs(n),...s}):n?.async&&t.push({kind:"shell",id:n.id,label:rn(n),...s})}n?.children?.length&&s(n.children)}};for(let n=e.length-1;n>=0&&(!e[n]?.tools?.length||(s(e[n].tools),!(t.length>0)));n--);return t}(e)})(l,a),[l,a]),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(()=>Date.now()),[x,m]=(0,r.useState)(!1),p=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(0===i.length)return;let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[i.length]),(0,r.useEffect)(()=>()=>clearTimeout(p.current),[]);let f=(0,r.useCallback)(()=>{if(!x){m(!0),(0,ed.e)(),clearTimeout(p.current),p.current=setTimeout(()=>m(!1),3e3);return}for(let e of(clearTimeout(p.current),m(!1),(0,ed.e)(),i))e.taskId&&s(e.taskId)},[x,i,s]),h=i.some(e=>e.taskId&&s);if(0===i.length)return null;let b=i.filter(e=>"agent"===e.kind),g=i.filter(e=>"shell"===e.kind);return(0,n.jsxs)("div",{className:"px-4 sm:px-6 py-1 border-b border-border-subtle/40 bg-brand-500/[0.06] shrink-0 text-xs select-none",children:[b.length>0&&(0,n.jsx)(oN,{icon:(0,n.jsx)(el.kr,{size:13,className:"text-brand-500 shrink-0 animate-spin"}),tag:"AGENTS",items:b,messages:l,engine:t,now:d,onOpen:c}),g.length>0&&(0,n.jsx)(oN,{icon:(0,n.jsx)(el.kr,{size:13,className:"text-warning shrink-0 animate-spin"}),tag:"SHELLS",items:g,messages:l,engine:t,now:d,onOpen:c}),h&&i.length>1&&(0,n.jsx)("div",{className:"flex justify-end pb-0.5",children:(0,n.jsx)("button",{type:"button",onClick:f,className:`text-[11px] px-2 py-0.5 rounded transition-colors ${x?"bg-danger/20 text-danger font-semibold":"text-text-muted hover:text-text"}`,children:x?"Press again to stop all":"Stop all"})}),o&&(0,n.jsx)(l$,{tasks:o,messages:l,engine:t,sessionId:e,onStopTask:s,onClose:()=>c(null)})]})});function oN({icon:e,tag:t,items:s,messages:r,engine:l,now:a,onOpen:i}){let o=s.map(e=>e.label).join(", "),c=rw(s.reduce((e,t)=>t.startedAt&&(!e?.startedAt||t.startedAt<e.startedAt)?t:e,null),a),d=s.map(e=>(function(e,t="claude"){if(!e?.name)return"";let{name:s,input:n={}}=e,r=ro(n.file_path||n.path);switch((0,ri.$Z)(t,s)){case"bash":return rd(n.description||n.command||"shell",60);case"file":return rd(`${/^(list|list_dir|ls)$/i.test(s)?"Listing":"Reading"} ${r}`,60);case"search":return rd([n.pattern?`"${n.pattern}"`:n.query||n.url||"",r?`in ${r}`:""].filter(Boolean).join(" "),60);case"diff":return rd(`${/^(Write|write_to_file)$/i.test(s)?"Writing":"Editing"} ${ro(n.file_path||n.filePath||n.file||n.path)||rx(n)}`,60);case"agent":return rd(n.description||rx(n)||"sub-agent",60);case"plan":return rd(ro(n.path)||s,60);default:return rd([ru(s),rx(n)].filter(Boolean).join(" "),60)}})(function(e=[],t=""){let s=rr(e,t);if(!s)return null;let n=s;for(;"running"===n.status;){let e=n.children||[],t=e.filter(e=>e?.status==="running").pop()||e[e.length-1];if(!t||t===n)break;n=t}return n}(r,e.toolUseId),l)).find(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 min-w-0",children:[e,(0,n.jsx)("span",{className:"font-mono text-[10px] font-semibold text-text uppercase tracking-wider shrink-0 px-1 py-0.5 rounded bg-surface-2/80",children:t}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),i(s)},title:o,className:"flex items-center gap-2 min-w-0 flex-1 text-left hover:bg-surface-2/40 rounded transition-colors px-1",children:[(0,n.jsxs)("span",{className:"font-mono text-[11px] text-brand-500 shrink-0 tabular-nums",children:[s.length," running"]}),c>0&&(0,n.jsx)("span",{className:"font-mono text-[11px] text-text shrink-0 tabular-nums",children:r5(c)}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",children:d||o})]})]})}let oC={model:"",skills:[],mcpServers:[]},oS=[],oT=(0,r.memo)(function({sessionId:e,engine:t="claude",workspacePath:s="",sessionName:l="",bus:a=null,fileBus:i=null,isVisible:o=!0,isFocused:c=!1,isDesktop:d=!0,bgIndex:x=0,onActivate:m=null,onOpenRemote:p=null,onOpenMobile:f=null,onOpenArtifact:b=null,onNewChat:g=null}){let[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(!1),{t:C}=(0,eu.s)(),{sendPrompt:S,removeQueueItem:T,clearQueue:R,resolvePermission:E,stop:$,stopTask:z,runShell:M,rewindToMessage:A,previewRewind:I,listRewindPoints:D,escalateMode:B,dismissBlocked:F,hasOlder:K,loadOlder:O,reload:W,hydrating:_,synced:H,hydrateFailed:U}=function({sessionId:e,engine:t="claude",workspacePath:s="",bus:n=null,isVisible:l=!0}){let a=(0,r.useRef)(n);(0,r.useEffect)(()=>{a.current=n},[n]);let i=rH(e=>e.initSession),o=rH(e=>e.setMetadata),c=rH(e=>e.appendDelta),d=rH(e=>e.appendThinking),x=rH(e=>e.appendDiff),m=rH(e=>e.appendTool),p=rH(e=>e.updateToolResult),f=rH(e=>e.nestTool),h=rH(e=>e.nestToolResult),b=rH(e=>e.upsertTask),g=rH(e=>e.setPermission),v=rH(e=>e.clearPermission),y=rH(e=>e.finishTurn),w=rH(e=>e.setTurnRunning),j=rH(e=>e.ensureTurnLive),k=rH(e=>e.addUserMessage),N=(0,u.d)(e=>e.connected),[C,S]=(0,r.useState)(!1),[T,R]=(0,r.useState)(!1),[E,$]=(0,r.useState)(!1),[z,M]=(0,r.useState)(!1),A=(0,r.useRef)(0),I=(0,r.useRef)(!1),D=(0,r.useCallback)((e,s,n)=>{switch(s){case"user_message":k(e,n.text,n.attachments||null,!!n?.replay);break;case"init":{let t=rJ(rH.getState().bySession[e]?.metadata?.skills),s=new Map(t.map(e=>[e.id||e.name,e])),r=rJ(n.skills),l=r.length>0?r.map(e=>{let t=s.get(e.id);return t?.description?{...e,description:t.description}:e}):t,{model:a,...i}=n||{};o(e,{...i,skills:l,...a?{model:a}:{}});break}case"goal":o(e,{goal:n?.goal||null});break;case"delta":n?.replay||j(e),c(e,n.text);break;case"thinking":n?.replay||j(e),d(e,n.text);break;case"diff":x(e,n);break;case"tool_child":f(e,n);break;case"tool_result_child":h(e,n);break;case"tool_start":if(n?.replay||j(e),m(e,n),n&&n.name){let s=rH.getState().bySession[e]?.tasks||[],r=(0,ri.Zm)(t,n.name,n.input,n.id,s);r&&b(e,r)}break;case"tool_result":if(p(e,n),n&&n.id){let s=(0,ri.in)(t,n.name||"",n.output||"",n.id);s&&b(e,s)}break;case"permission_request":g(e,n);break;case"permission_resolved":v(e,n.requestId);break;case"blocked":rH.getState().setBlocked(e,n);break;case"options_changed":n?.permissionMode&&rH.getState().setPermissionMode(e,n.permissionMode),n?.model&&o(e,{model:n.model}),n?.effort&&o(e,{effort:n.effort});break;case"queue_update":rH.getState().setQueue(e,n?.queue||[]);break;case"turn_complete":y(e,n.stats,n.turnMs,!!n?.replay),!n?.isError||rQ(rH.getState().bySession[e]?.messages,n.result)||rG(rH.getState().bySession[e]?.messages,n.result)||rH.getState().addNotice(e,{subtype:n.subtype||"",level:"error",content:n.result||"The turn ended in an error."});break;case"stats":n?.stats&&rH.getState().setStats(e,n.stats);break;case"stopped":case"exit":v(e),rH.getState().finishTurn(e,null,n?.turnMs),"exit"===s&&rH.getState().settleDeadTasks(e),"exit"===s&&(n?.error||n?.code!=null&&0!==n.code)&&rH.getState().addNotice(e,{subtype:"exit",level:"error",content:n.error||`The AI process exited (code ${n.code}).`});break;case"stall":w(e,!1),y(e,null,n?.turnMs);break;case"error":rH.getState().addNotice(e,{subtype:"error",level:"error",content:n?.message||"AI process failed"}),y(e,null,n?.turnMs);break;case"prompt_refused":rH.getState().addNotice(e,{subtype:"prompt_refused",level:"error",content:r0(n)});break;case"conversation_reset":(0,L.Lq)("ai-status","reset",{sessionId:e,isTurnRunning:n?.isTurnRunning,elapsedMs:n?.elapsedMs,lastTurnMs:n?.lastTurnMs,fromSeq:n?.fromSeq}),rH.getState().clearMessages(e),rH.getState().setTaskRecords(e,n?.taskRecords),rH.getState().restoreTurnState(e,n),Array.isArray(n?.queue)&&rH.getState().setQueue(e,n.queue);break;case"cli_event":{let s=n?.type||"",r=n?.record||null;rH.getState().applyTaskRecords(e,[[s,n?.subtype||"",r,n?.ageMs]]);let l=rP(s,r,t);l&&rH.getState().addNotice(e,l);break}case"ansi":{let t=rZ(n?.chunk);t&&rH.getState().addNotice(e,{subtype:"ansi",level:"warning",content:t})}}},[t,k,o,c,d,x,m,p,f,h,b,g,v,y,w,j]),B=(0,r.useRef)(D);(0,r.useEffect)(()=>{B.current=D});let F=(0,r.useRef)(i);(0,r.useEffect)(()=>{F.current=i});let K=(0,r.useRef)(0),O=(0,r.useRef)(0),W=(0,r.useRef)(!1),_=(0,r.useRef)([]),H=(0,r.useRef)(0),U=(0,r.useRef)(null);null==U.current&&(U.current=function(e=rV){let t=0,s=!1;return{schedule:n=>s||!n?null:(s=!0,e[Math.min(t++,e.length-1)]),fired(){s=!1},answered(){s=!1,t=0},exhausted:()=>t>=e.length}}());let q=(0,r.useRef)(null),X=(0,r.useRef)(null),V=(0,r.useRef)(null),J=(0,r.useRef)({}),G=(0,r.useRef)(null),Y=(0,r.useRef)(l);(0,r.useEffect)(()=>{Y.current=l},[l]);let Z=(0,r.useRef)(null),Q=(0,r.useRef)(null),ee=(0,r.useRef)(null),et=(0,r.useCallback)(()=>{q.current&&clearTimeout(q.current),q.current=null,U.current?.answered()},[]),es=(0,r.useCallback)(()=>{let e=U.current?.schedule(u.d.getState().connected);M(!!U.current?.exhausted()),(0,L.Lq)("ai-hydrate","ladder",{delay:e??null,exhausted:U.current?.exhausted(),connected:u.d.getState().connected,armed:null!=q.current}),null!=e&&(q.current=setTimeout(()=>{q.current=null,U.current?.fired(),J.current.request?.()},e))},[]),en=(0,r.useCallback)(()=>{if(!e||!n)return;if(W.current){(0,L.Lq)("ai-hydrate","blocked (round in flight)",{gen:H.current}),es();return}let r=++H.current,l=O.current;W.current=!0,R(!0),_.current=[],A.current=0;let a=Date.now();(0,L.Lq)("ai-hydrate","emit ai:create",{gen:r,sessionId:e,engine:t,cwd:s,carrier:u.d.getState().carrier,connected:u.d.getState().connected});let i=()=>{let t=_.current;_.current=[],W.current=!1,R(!1),(0,sd.unstable_batchedUpdates)(()=>{for(let s of t){if("conversation_reset"===s.event){K.current=0,O.current++,A.current=s.data?.fromSeq??0,S(!!s.data?.hasMore),B.current(e,s.event,s.data);continue}if(null!=s.seq){if(s.seq<=K.current)continue;K.current=s.seq}B.current(e,s.event,s.data)}})},o=setTimeout(()=>{r===H.current&&W.current&&(i(),es())},4e3);V.current=o,n.emit("ai:create",{sessionId:e,engine:t,cwd:s,options:{defaultMode:(0,ri.Tw)(t).defaultMode,defaultEffort:(0,ri.Tw)(t).defaultEffort}},s=>{if(!function({isNewest:e,snapshotSeq:t=0,appliedSeq:s=0,sameLog:n=!0}){return!!e||!!n&&(t||0)>(s||0)}({isNewest:r===H.current,snapshotSeq:s?.session?.seq,appliedSeq:K.current,sameLog:l===O.current}))return;let n=null,c=null,d=s?.session?.events;(0,L.Lq)("ai-hydrate","ack",{gen:r,stale:r!==H.current,ms:Date.now()-a,ok:s?.ok??null,error:s?.error??null,events:Array.isArray(d)?d.length:null,hasMore:s?.session?.hasMore??null});try{if(clearTimeout(o),!s?.ok||!Array.isArray(d))return void S(!1);let r=s.session.seq||0;if((0,L.Lq)("ai-status","hydrate ack",{sessionId:e,isTurnRunning:s.session.isTurnRunning,elapsedMs:s.session.elapsedMs,lastTurnMs:s.session.lastTurnMs,events:d.length,hasMore:s.session.hasMore}),s.session.asleep&&!s.session.isTurnRunning){let t=P.rh.getState();t.applyStatusChange(e$(e).head??t.currentKey,{sessionId:e,state:"sleep"})}if(A.current=d[0]?.seq??0,S(!!s.session.hasMore&&d.length>0),Array.isArray(s?.modelOptions)&&s.modelOptions.length>0&&rH.getState().setMetadata(e,{modelOptions:s.modelOptions}),d.length>0){let n=r1(d,t);rH.getState().hydrateSession(e,{messages:n.messages,tasks:n.tasks,metadata:{...rH.getState().bySession[e]?.metadata,...n.metadata,...Array.isArray(s?.modelOptions)?{modelOptions:s.modelOptions}:{},...s.session.effort?{effort:s.session.effort}:{}},stats:{...n.stats,...s.session.stats||{}},isTurnRunning:void 0!==s.session.isTurnRunning?!!s.session.isTurnRunning:n.isTurnRunning,elapsedMs:s.session.elapsedMs||0,lastTurnMs:s.session.lastTurnMs||0,permissionMode:s.session.permissionMode||n.permissionMode,activeBlocked:n.activeBlocked,harnessTasks:rR(s.session.taskRecords,n.harnessTasks),queue:s.session.queue||[]})}else w(e,!!s.session.isTurnRunning),rH.getState().setTaskRecords(e,s.session.taskRecords),s.session.permissionMode&&rH.getState().setPermissionMode(e,s.session.permissionMode),Array.isArray(s.session.queue)&&rH.getState().setQueue(e,s.session.queue),s.session.stats&&rH.getState().setStats(e,s.session.stats);s.session.asleep&&!s.session.isTurnRunning&&rH.getState().settleDeadTasks(e),n=s.session.activePermission||null,c=Array.isArray(s.session.queue)?s.session.queue:null,K.current=r}finally{clearTimeout(o),r===H.current&&i(),n&&r===H.current&&rH.getState().setPermission(e,n),c&&r===H.current&&rH.getState().setQueue(e,c),s?.ok&&void 0!==s.session.isTurnRunning&&rH.getState().restoreTurnState(e,{isTurnRunning:!!s.session.isTurnRunning,elapsedMs:s.session.elapsedMs||0,lastTurnMs:s.session.isTurnRunning?0:s.session.lastTurnMs||0}),s?.ok?($(!0),M(!1),et()):es()}})},[e,t,s,n,w,es,et]),er=(0,r.useCallback)(()=>{!u.d.getState().connected||X.current||(X.current=setTimeout(()=>{X.current=null,en()},eJ.qw))},[en]),el=(0,r.useCallback)(()=>{if(n&&e){if(!Y.current){Z.current="visible";return}!u.d.getState().connected||W.current||Q.current||(Q.current=setTimeout(()=>{if(Q.current=null,!Y.current||W.current)return;let t=!1,s=setTimeout(()=>{t||((0,L.Lq)("ai-hydrate","peekSeq: no ack → full hydrate"),er())},eJ.zm);ee.current=s,n.emit("ai:peekSeq",{sessionId:e},n=>{if(t=!0,clearTimeout(s),ee.current=null,!n?.ok||"number"!=typeof n.seq)return void er();let r=K.current,l=!!rH.getState().bySession[e]?.isTurnRunning,a=rH.getState().bySession[e]?.queue?.length||0,i="number"==typeof n.queueLength?n.queueLength:a;n.seq===r&&!!n.isTurnRunning===l&&i===a?(0,L.Lq)("ai-hydrate","peekSeq: nothing missed",{seq:r}):((0,L.Lq)("ai-hydrate","peekSeq: state changed",{fromSeq:r,toSeq:n.seq,turn:n.isTurnRunning}),er())})},eJ.qw))}},[n,e,er]),ea=(0,r.useCallback)(()=>{n?.kickWsZombie?.("refresh"),et(),en()},[n,et,en]);(0,r.useEffect)(()=>{J.current={request:er}},[er]),(0,r.useEffect)(()=>()=>{X.current&&clearTimeout(X.current),Q.current&&clearTimeout(Q.current),ee.current&&clearTimeout(ee.current),q.current&&clearTimeout(q.current),V.current&&clearTimeout(V.current),X.current=Q.current=ee.current=q.current=V.current=null,W.current=!1,_.current=[]},[]),(0,r.useEffect)(()=>{if(e)return G.current!==e&&(G.current=e,W.current=!1,et(),$(!1),M(!1)),F.current(e),en()},[e,en,et]),(0,r.useEffect)(()=>{if(!l)return;let e=Z.current;e&&(Z.current=null,"reconnect"===e?er():el())},[l,er,el]),(0,r.useEffect)(()=>{if(!n||!e)return;let t=()=>{document.hidden||el()},s=()=>{if(!Y.current){Z.current="reconnect";return}er()};return n.on("connect",s),document.addEventListener("visibilitychange",t),document.addEventListener("resume",t),()=>{n.off("connect",s),document.removeEventListener("visibilitychange",t),document.removeEventListener("resume",t)}},[n,e,el,er]);let ei=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=ei.current;if(ei.current=N,N&&!e){if(!Y.current){Z.current="reconnect";return}er()}},[N,er]),(0,r.useEffect)(()=>{if(!n||!e)return;let t="",s="",r=null,l=[],a=!1,i=()=>{null!=r&&cancelAnimationFrame(r),r=null;let n=t,l=s;t="",s="",(n||l)&&rH.getState().appendStream(e,n,l)},o=()=>{a=!1;let t=l;l=[];let s=B.current;(0,sd.unstable_batchedUpdates)(()=>{for(let n of t)n.stream?rH.getState().appendStream(e,n.data.text,n.data.thinking):s(e,n.event,n.data)})},c=(e,n)=>{if("cli_event"!==e&&(t||s)){let e={stream:!0,data:{text:t,thinking:s}};t="",s="",null!=r&&(cancelAnimationFrame(r),r=null),l.push(e)}l.push({event:e,data:n}),a||(a=!0,queueMicrotask(o))},d=n=>{var l,a,o,d;if(!n||n.sessionId!==e)return;if(W.current)return void _.current.push(n);let u="delta"===n.event||"thinking"===n.event;if("conversation_reset"===n.event){K.current=0,O.current++,A.current=n.data?.fromSeq??0,S(!!n.data?.hasMore),c(n.event,n.data);return}if(l=n.seq,a=K.current,null==l||!(l<=(a||0))){if(null!=n.seq&&(K.current=n.seq),u)return void(o=n.event,(d=n.data?.text)&&("delta"===o?t+=d:s+=d,null==r&&(r=requestAnimationFrame(i))));c(n.event,n.data)}};return n.on("ai:event",d),()=>{n.off("ai:event",d),i()}},[n,e,D]);let eo=(0,r.useCallback)((t,{attachments:n=null}={})=>{if(!t&&!n?.length)return;let r=a.current;ej.getState().clearNotification(e),r?.emit("ai:prompt",{sessionId:e,message:t,cwd:s,...n?.length?{attachments:n}:{}})},[e,s]),ec=(0,r.useCallback)(t=>{let s=rH.getState().bySession[e]?.queue||[];rH.getState().setQueue(e,s.filter(e=>e.id!==t));let n=a.current;n?.emit("ai:queueRemove",{sessionId:e,id:t})},[e]),ed=(0,r.useCallback)(()=>{rH.getState().setQueue(e,[]);let t=a.current;t?.emit("ai:queueClear",{sessionId:e})},[e]),eu=(0,r.useCallback)((t,s,n="",r=null)=>{let l=a.current;if(!l)return;let i=!1,o=null,c=n=>{if(!i){if(i=!0,clearTimeout(o),n?.ok||n?.reason==="stale")return void v(e,t);(0,L.Lq)("ai-gate","resolve failed",{requestId:t,behavior:s,res:n??"timeout"}),rH.getState().setGateError(e,t)}};r?l.emit("ai:question",{sessionId:e,requestId:t,answers:r},c):l.emit("ai:permission",{sessionId:e,requestId:t,behavior:s,message:n},c),o=setTimeout(()=>c(null),tv.GX)},[e,v]),ex=(0,r.useCallback)(()=>{let t=a.current;t?.emit("ai:stop",{sessionId:e})},[e]),em=(0,r.useCallback)(t=>{if(!t)return;let s=a.current;s?.emit("ai:stopTask",{sessionId:e,taskId:t})},[e]),ep=(0,r.useCallback)(e=>{eo(`! ${e}`)},[eo]),ef=(0,r.useCallback)(async()=>{let t=a.current;if(!t)return null;let s=await new Promise(s=>{let n=!1,r=e=>{n||(n=!0,clearTimeout(l),s(e))},l=setTimeout(()=>r(null),4e3);t.emit("ai:rewind",{sessionId:e,action:"list"},r)});return s?s.support?.conversation?s.ok?{supported:!0,ok:!0,points:s.points||[],support:s.support}:{supported:!0,ok:!1,points:[],support:s.support}:{supported:!1,ok:!1,points:[],support:s.support}:null},[e]),eh=(0,r.useCallback)(async(t,n,{files:r=!0,preview:l=!1,index:i=null}={})=>{let o=a.current;if(!o)return{ok:!1,error:"Not connected to the host."};let c=await new Promise(s=>{let n=!1,a=e=>{n||(n=!0,clearTimeout(c),s(e))},c=setTimeout(()=>a(null),l?4e3:13e4);o.emit("ai:rewind",{sessionId:e,action:l?"preview":"apply",messageId:t,index:i,files:r},a)});return(l||c&&c.ok||ea(),c)?(c.ok&&!l&&n&&o.emit("ai:prompt",{sessionId:e,message:n,cwd:s}),c):{ok:!1,error:"The host did not answer in time."}},[e,s,ea]),eb=(0,r.useCallback)((e,{files:t=!0,index:s=null}={})=>eh(e,null,{files:t,preview:!0,index:s}),[eh]),eg=(0,r.useCallback)(t=>{if(!t)return;rH.getState().setPermissionMode(e,t),rH.getState().clearBlocked(e);let s=a.current;s?.emit("ai:options",{sessionId:e,options:{mode:t}})},[e]),ev=(0,r.useCallback)(()=>{rH.getState().clearBlocked(e)},[e]);return{hydrating:T,synced:E,hydrateFailed:z,hasOlder:C,loadOlder:(0,r.useCallback)(async()=>{if(I.current)return!1;let s=a.current;if(!s)return!1;I.current=!0;let n=A.current;try{let{messages:r,before:l,hasMore:a,answered:i}=await rX({startSeq:n,estimateBytes:rU,fetchChunk:t=>new Promise(n=>{let r=!1,l=e=>{r||(r=!0,clearTimeout(a),n(e))},a=setTimeout(()=>l(null),4e3);s.emit("aiHistory",{sessionId:e,before:t},l)}),reduceChunk:(s,n)=>{let r=rH.getState().bySession[e];return r1(s,t,(r?.messages?.length||0)+n+1).messages}});if(A.current!==n||!i||(A.current=l,S(a),!r.length))return!1;return rH.getState().prependMessages(e,r),!0}finally{I.current=!1}},[e,t]),reload:ea,sendPrompt:eo,removeQueueItem:ec,clearQueue:ed,resolvePermission:eu,stop:ex,stopTask:em,runShell:ep,rewindToMessage:eh,previewRewind:eb,listRewindPoints:ef,escalateMode:eg,dismissBlocked:ev}}({sessionId:e,engine:t,workspacePath:s,bus:a,isVisible:o}),q=(0,r.useCallback)(()=>{(0,ed.e)(),j(!0),W(),setTimeout(()=>j(!1),700)},[W]),X=rH(t=>t.bySession[e]?.activePermission),V=!!rH(t=>t.bySession[e]?.isTurnRunning),J=rH(t=>t.bySession[e]?.gateError),G=rH(t=>t.bySession[e]?.activeBlocked),Y=rH(t=>t.bySession[e]?.metadata)||oC,Z=rH(t=>t.bySession[e]?.tasks)||oS,Q=rH(e=>e.setPermissionMode),ee=ez(e),et=(0,h.B)(e=>e.terminalBackgroundOpacity),es=(0,h.B)(e=>e.customBackgrounds),en=(0,h.B)(e=>e.terminalBackgrounds),er=(0,h.B)(t=>t.backgroundBySession[e]),ea=(0,h.B)(e=>e.terminalTheme),ei=(0,h.B)(e=>e.fontSize),eo=(0,h.B)(e=>e.showFolderButton),ec=(0,h.B)(e=>e.showNoteButton),ex=(0,h.B)(e=>e.setRightPanelRoot),em=(0,h.B)(e=>e.setRightPanelTab),ep=(0,h.B)(e=>e.openRightPanel),ef=(0,h.B)(t=>t.artifactsBySession[e]),eh=nw(s,i,{enabled:c&&eo}),{theme:eb}=(0,nW.D)(),eg=(0,r.useMemo)(()=>(0,nR.In)(eb,ea),[eb,ea]),ev=(0,r.useMemo)(()=>(0,eJ.ar)(ei)+(d?tv.TQ:tv.wM),[ei,d]),ey=(0,r.useMemo)(()=>{let{alpha:e,size:t}=tv.ii,s=`radial-gradient(color-mix(in srgb, ${eg.foreground} ${e}%, transparent) 1px, transparent 1px) 0 0 / ${t}px ${t}px`,n=(0,eJ.$Z)(er,en,es,x),r="dark"===eb?(0,eJ.RS)(n,es):null;if(r){let e=`rgba(${eJ.c},${et??eJ._z})`,t=`rgba(${eJ.pZ},${eJ.B$})`;return{background:`${s}, linear-gradient(${e},${e}), linear-gradient(${t},${t}), center / cover no-repeat url("${r}")`,backgroundBlendMode:"luminosity, normal, screen, normal"}}return{background:`${s}, ${eg.background}`}},[en,er,es,et,eg,eb,x]),ew=Y.skills||[],ek=Y.mcpServers||[],eN=(0,r.useCallback)(e=>{S(`/${e}`)},[S]),eC=(0,r.useCallback)(t=>{a?.emit?.("ai:options",{sessionId:e,options:t})},[a,e]),eS=(0,r.useCallback)(t=>{rH.getState().setMetadata(e,{model:t}),eC({model:t})},[eC,e]),eT=(0,r.useCallback)(e=>{e?.sessionId&&eC({resume:e.sessionId})},[eC]),eR=(0,r.useCallback)(e=>{if(e)return eT(e);y("sessions")},[eT]),eE=(0,r.useCallback)((t,s)=>{t&&("effort"===t&&rH.getState().setMetadata(e,{effort:s}),eC({[t]:s}))},[eC,e]),eM=(0,ri.Tw)(t),eP=(0,r.useCallback)(t=>{Q(e,t),eC({mode:t})},[eC,e,Q]),eA=(0,r.useCallback)((t,s)=>{rH.getState().rewindToMessage(e,t,s)},[e]),eI=(0,r.useCallback)(t=>{if(!v&&t.shiftKey&&"Tab"===t.key){t.preventDefault(),(0,ed.e)();let s=eM.permissionModes||[],n=rH.getState().bySession[e]?.permissionMode||eM.defaultMode,r=s.findIndex(e=>e.id===n),l=-1===r?0:(r+1)%s.length,a=s[l]?.id;a&&eP(a)}},[e,eM,eP,v]),eD=n_({isFocused:c,onActivate:()=>m?.()}),eL=(0,r.useRef)(m);(0,r.useEffect)(()=>{eL.current=m});let eB=(0,r.useCallback)(()=>eL.current?.(),[]),eF=(0,r.useMemo)(()=>({sessionId:e,isFocused:c,activate:eB}),[e,c,eB]);return(0,n.jsx)(lo.fe.Provider,{value:eF,children:(0,n.jsxs)("div",{...eD,onKeyDown:eI,className:"ai-pane w-full h-full flex flex-col bg-bg overflow-hidden relative select-text",style:{...ey,"--color-text":eg.foreground,"--ai-fs":`${ev}px`},children:[(0,n.jsxs)("div",{style:{height:26},className:"sm:hidden flex items-center gap-2 px-2 border-b border-border-subtle bg-surface/70 backdrop-blur-sm text-[11px] select-none shrink-0 relative z-10",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${st(ee)}`,style:{background:se(ee).dot}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",children:l||tv.UB[t]?.label||t}),(0,n.jsx)(nO,{onOpenRemote:p,onOpenMobile:f})]}),c&&(0,n.jsxs)("div",{className:"absolute right-2 z-[2] flex flex-col items-end gap-2 pointer-events-auto touch-none top-9 sm:top-2",children:[(0,n.jsxs)("div",{className:"flex flex-row gap-2",children:[ec&&(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,ed.e)(),N(!0)},className:nH,title:C("terminalPane.note"),children:(0,n.jsx)(el.y8,{size:16,className:nU})}),(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),q()},className:nH,title:C("terminalPane.refresh"),children:(0,n.jsx)(el.e9,{size:16,className:`${nU} ${w?"animate-spin":""}`})})]}),eo&&s&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,ed.e)(),ex(s,s),window.innerWidth>=eJ.jK?em("files",s):ep()},className:`relative ${nH}`,title:C("terminalPane.openFolderHere"),children:[(0,n.jsx)(el.vd,{size:16,className:nU}),eh>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:eh>eJ.KN?`${eJ.KN}+`:eh})]}),b&&ef?.length>0&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:t=>{t.stopPropagation(),(0,ed.e)(),b(e,ef[0])},className:`relative ${nH}`,title:C("terminalPane.artifacts"),children:[(0,n.jsx)(el.sU,{size:16,className:nU}),(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[10px] font-semibold text-white bg-brand-500 rounded-full",children:ef.length})]})]}),(0,n.jsx)(ow,{sessionId:e}),(0,n.jsx)(ok,{sessionId:e,engine:t,onStopTask:z}),(0,n.jsx)(i9,{bus:a,sessionId:e,engine:t,workspacePath:s,fileBus:i,onSendPrompt:S,onResolvePermission:E,onRewind:A,onPreviewRewind:I,onListRewindPoints:D,onCutLocal:eA,hasOlder:K,onLoadOlder:O,onOpenResume:eR,hydrating:_,synced:H,hydrateFailed:U,onReload:W}),G&&!X&&(0,n.jsx)("div",{className:"px-3 pb-2 select-none animate-in fade-in slide-in-from-bottom-2 duration-150 flex-shrink-0 z-30",children:(0,n.jsx)(ov,{engine:G.engine||t,message:G.message,escalate:G.escalate,onEscalate:B,onDismiss:F})}),X&&(0,n.jsx)("div",{className:"px-3 pb-2 select-none animate-in fade-in slide-in-from-bottom-2 duration-150 flex-shrink-0 z-30",children:"AskUserQuestion"===X.tool?(0,n.jsx)(ll.J,{requestId:X.requestId,questions:X.input?.questions||[],failed:J,onResolve:E}):(0,n.jsx)(og,{requestId:X.requestId,tool:X.tool,input:X.input,failed:J,onResolve:E})}),(0,n.jsx)(os,{bus:a,sessionId:e,engine:t,onSend:S,onRemoveQueueItem:T,onClearQueue:R,onStop:$,onRunShell:M,onResolvePermission:E,onSelectModel:eS,onModeChange:eP,onOpenModal:y,onOptionChange:eE,onActivate:m,isFocused:c,fileBus:i,workspacePath:s,modalOpen:null!==v}),(0,n.jsx)(or,{sessionId:e,fileBus:i,sessionName:l,engine:t,workspacePath:s,isDesktop:d,onModeChange:eP,onNewChat:g}),"skills"===v&&(0,n.jsx)(ol,{skills:ew,onClose:()=>y(null),onSelectSkill:eN}),"mcp"===v&&(0,n.jsx)(oa,{mcpServers:ek,onClose:()=>y(null)}),"model"===v&&(0,n.jsx)(oi,{currentModel:Y.model,currentEffort:Y.effort||"",models:Y.modelOptions?.length?Y.modelOptions:eM.models,isTurnRunning:V,onClose:()=>y(null),onSelectModel:eS,onSelectEffort:e=>eC({effort:e})}),"sessions"===v&&(0,n.jsx)(oo,{bus:a,engine:t,workspacePath:s,onClose:()=>y(null),onResume:eT}),"config"===v&&(0,n.jsx)(ou,{engine:t,options:rH.getState().bySession[e]?.metadata,onClose:()=>y(null),onApply:e=>eC(e)}),"mode"===v&&(0,n.jsx)(om,{modes:eM.permissionModes||[],currentMode:rH.getState().bySession[e]?.permissionMode||eM.defaultMode,onClose:()=>y(null),onSelectMode:eP}),"doctor"===v&&(0,n.jsx)(op,{bus:a,engine:t,workspacePath:s,onClose:()=>y(null)}),"tasks"===v&&(0,n.jsx)(oh,{tasks:Z,onClose:()=>y(null)}),"rewind"===v&&(0,n.jsx)(ob,{sessionId:e,onListPoints:D,onPreview:I,onApply:e=>A(e),onClose:()=>y(null)}),k&&ec&&(0,n.jsx)(nK,{bus:a,sessionId:e,onClose:()=>N(!1)})]})})});class oR extends r.Component{constructor(e){super(e),this.handleReset=()=>{this.setState({hasError:!1,error:null}),this.props.onReset?.()},this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("[ErrorBoundary caught error]:",e,t)}render(){return this.state.hasError?this.props.fallback?"function"==typeof this.props.fallback?this.props.fallback(this.state.error,this.handleReset):this.props.fallback:(0,n.jsxs)("div",{className:"w-full h-full min-h-[160px] flex flex-col items-center justify-center p-6 text-center select-none bg-surface/50 border border-border-subtle/40 rounded-brand m-2",children:[(0,n.jsx)(el.RI,{size:24,className:"text-danger mb-2"}),(0,n.jsx)("div",{className:"text-sm font-semibold text-text mb-1",children:this.props.title||"Something went wrong in this pane"}),(0,n.jsx)("div",{className:"text-xs text-text-muted font-mono max-w-md truncate mb-4",children:this.state.error?.message||"Render error"}),(0,n.jsxs)("button",{type:"button",onClick:this.handleReset,className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-surface-3 text-text text-xs flex items-center gap-1.5 font-medium transition-colors border border-border-subtle",children:[(0,n.jsx)(el.e9,{size:12}),(0,n.jsx)("span",{children:"Try again"})]})]}):this.props.children}}let oE=(0,r.memo)(function({children:e}){return(0,n.jsx)("div",{className:"absolute inset-x-0 top-0 bottom-[37px] overflow-hidden",children:e})}),o$=(0,r.memo)(function({sessionId:e}){let t=ez(e);return"idle"===t?null:(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 z-20 h-[1px] pointer-events-none hidden sm:block",children:"working"===t?(0,n.jsx)(iJ,{}):"done"===t?(0,n.jsx)("div",{className:"w-full h-full bg-[#f59e0b]",style:{boxShadow:"0 0 4px rgba(245,158,11,0.6)"}}):"blocked"===t?(0,n.jsx)("div",{className:"w-full h-full bg-[#ef4444] animate-pulse",style:{boxShadow:"0 0 4px rgba(239,68,68,0.7)"}}):null})}),oz=(0,r.memo)(function({sessionId:e,placeholder:t}){let s=(0,h.B)(t=>t.drafts[e]??"").replace(/\s+/g," ").trim();return s?(0,n.jsx)("span",{className:"text-text",children:s}):(0,n.jsx)(n.Fragment,{children:t})}),oM=(0,r.memo)(function({bus:e,busRef:t,connected:s,carrier:l,platform:a,hostVersion:i,agentVersion:o,sessions:c,workspaces:d,activeSessionId:x,activeSession:m,activeWorkspaceId:p,openedSessions:f,livePanes:b,mountedWorkspaces:g,cwdBySession:v,sessionStatus:y,notifications:w,isDesktop:j,isTerminalView:k,slideClass:N,shells:C,pairDashboard:S=null,welcomeActive:T=!1,sidebarCollapsed:R,sidebarWidth:E,setSidebarWidth:$,toggleSidebar:z,paneWidth:M=null,setPaneWidth:A,paneRegistry:I,bindSwipeTab:D,nav:L,onBack:B,onOpenRemote:F,onOpenMobile:K,onOpenRemoteHost:O=null,onOpenMobileHost:W=null,onOpenFiles:_,onLogout:H,onRenameHost:U,onDeleteHost:q,onMainDisconnect:X,onDeleteWorkspace:V,onRenameWorkspace:J,onReorderSession:G,onSetHiddenRepos:Y,atStackBottom:Z=!1,onAddWorkspace:Q,onOpenSettings:ee,homeDir:et,recentWorkspaces:es,rightPanel:er,editorPanel:ea,mobilePanel:ei,onOpenArtifact:eo,fileBus:ec,browserPanel:ex=null,onCreateAnyHost:em,onQuickCreateHostAware:ep,tunnelUrl:ef,apiKey:eh,connectionMode:eb,onResumeAgentSessionForeign:eg=null,subscribeToPush:ev,unsubscribeFromPush:ey}){let{t:ew}=(0,eu.s)(),ek="mouse"===tO(),eN=(0,u.d)(e=>e.bus),eC=(0,u.d)(e=>e.busRef),eS=(0,u.d)(e=>e.connected),eT=(0,u.d)(e=>e.carrier),eR=e||eN,ez=t||eC,eM=(0,r.useMemo)(()=>c.filter(e=>!e.hostKey),[c]),eP=(0,r.useMemo)(()=>d.filter(e=>!e.hostKey),[d]),eA=(0,r.useCallback)(e=>{let t=e$(e);return t.head?t.bus:eR},[eR]),eI=s??eS,eD=ec||en.getState(),eL=(0,r.useMemo)(()=>m?.hostKey?eE(m.hostKey).fileBus:eD,[m?.hostKey,eD]),{panesContainerRef:eB,registerPaneApi:eF,registerPaneElement:eK,registerKeyboardTextApi:eO,handlePasteFallback:eW,handleInputFocusChange:e_,focusPane:eH,focusKeyboardInput:eU,scrollPaneIntoView:eq}=I,[eX,eG]=(0,r.useState)(null),{workspaceSessionIds:eY,workspaceOpenedSessions:eZ,renderedSessions:e0,mountedSet:e1,workspaceIndex:e2}=(0,r.useMemo)(()=>(0,eQ.gk)({sessions:c,openedSessions:f,livePanes:b,mountedWorkspaces:g,activeWorkspaceId:p,isDesktop:j}),[c,f,b,g,p,j]),e5=(0,r.useMemo)(()=>c.filter(e=>(0,eQ.xs)(e)===p),[c,p]),e3=(0,r.useMemo)(()=>new Map(e5.map((e,t)=>[e.id,t])),[e5]),e4=d.find(e=>e.id===p),e6=e4?.path||m?.workspacePath||null,e8=(0,h.B)(e=>e.rightPanelRoots),e9=(0,h.B)(e=>e.agentBySession),e7=(0,h.B)(e=>e.fullModes||{})[p??eQ.AD]??!1,te=(0,h.B)(e=>e.hiddenPaneSessionIds||[]),tt=(0,h.B)(e=>e.setRightPanelRoot),ts=(0,h.B)(e=>e.openRightPanel),tn=(0,h.B)(e=>e.reorderOpenedSessions),tr=(0,r.useCallback)(e=>{tn(e),G?.(e)},[tn,G]),tl=(0,r.useCallback)(e=>{L.handleSelectSession(e)},[L]),ta=!!c.find(e=>e.id===x)?.hostKey,ti=e4?.hostKey||null,to=eE(ti).busRef,[tc,td]=(0,r.useState)([]),tu=(0,P.rh)(e=>ti&&e.hosts[ti]?.status||null),tx=(0,P.rh)(e=>e.hosts),tm=(0,P.rh)(e=>e.currentKey);(0,r.useEffect)(()=>{ti&&eE(ti).bus?.emit("getShells",e=>td(e?.shells||[]))},[ti,tu]);let tp=(0,r.useCallback)((e,t)=>{let s=c.filter(e=>e.id!==t&&(0,eQ.xs)(e)===(p??null)).length+1;L.handleReplaceSession(t,`${e.short||e.label} ${s}`,e,!0)},[L,c,p]),tf=e8[e6]||e6,tb=(0,r.useCallback)(e=>er?.onTabChange(e,e6??""),[er,e6]),tg=(0,r.useCallback)(()=>_?.(tf),[_,tf]),ty=(0,r.useMemo)(()=>e4?.hiddenRepos||[],[e4?.hiddenRepos]),tw=(0,r.useCallback)(e=>{e4&&Y?.(e4.id,e)},[e4,Y]),tj=x&&(v[x]||c.find(e=>e.id===x)?.cwd)||null;(0,r.useEffect)(()=>{tt(e6,null)},[x,e6,tt]);let tk=!c.length,tN=(0,P.rh)(e=>Object.keys(e.hosts).length),tC=tk&&!d.length&&tN<=1,[tS,tT]=(0,r.useState)(!1);er?.open&&!tS&&tT(!0);let[tR,tE]=(0,r.useState)(!1);!er?.open&&tR&&tE(!1),(0,r.useEffect)(()=>{if(!er?.open)return;let e=requestAnimationFrame(()=>tE(!0));return()=>cancelAnimationFrame(e)},[er?.open]);let t$=!!ea?.filePath,[tz,tM]=(0,r.useState)(!1);t$&&!tz&&tM(!0);let[tP,tA]=(0,r.useState)(!1);!t$&&tP&&tA(!1);let[tI,tD]=(0,r.useState)(null);t$&&tI?.filePath!==ea.filePath&&tD({filePath:ea.filePath,artifactTitle:ea.artifactTitle,previewSeq:ea.previewSeq}),(0,r.useEffect)(()=>{if(!t$)return;let e=requestAnimationFrame(()=>tA(!0));return()=>cancelAnimationFrame(e)},[t$]);let[tL,tB]=(0,r.useState)(0),[tF,tK]=(0,r.useState)(!1),tW=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!j)return;let e=tW.current;if(!e)return;let t=new ResizeObserver(e=>tB(e[0].contentRect.width));return t.observe(e),()=>t.disconnect()},[j]),(0,r.useEffect)(()=>{if(!eI||!eR?.emit)return;let e=!1,t=()=>eR.emit("bg:get",{},t=>{!e&&t?.success&&t.dataUrl&&h.B.getState().setCustomBackgrounds([{id:"custom",dataUrl:t.dataUrl}])}),s=setTimeout(()=>{e||t()},eJ._O);return eR.emit("bg:list",{},n=>{e||(clearTimeout(s),n?.success&&Array.isArray(n.items)?h.B.getState().setCustomBackgrounds(n.items):t())}),()=>{e=!0,clearTimeout(s)}},[eI,eR]);let t_=(0,r.useMemo)(()=>eZ.filter(e=>!te.includes(e)),[eZ,te]).length,tH=(er?.open&&tR?er.width:0)+(t$&&tP?ea.width:0)+(ei?.open&&"pin"===ei.mode?ei.width:0),tU=(0,eQ.Jc)({rowWidth:tL,paneCount:t_,sidebarWidth:R?0:E,sidePx:tH,gapPx:eJ.pS,paddingPx:eJ.Jv,minWidth:eJ.k9.min}),tq=M??tU,tX=(0,r.useRef)({editorFile:ea?.filePath,rightOpen:er?.open});(0,r.useEffect)(()=>{if(!j||!x)return;let e=tX.current,t=e.editorFile!==ea?.filePath||e.rightOpen!==er?.open;if(tX.current={editorFile:ea?.filePath,rightOpen:er?.open},!t)return;let s=setTimeout(()=>{eq(x)},260);return()=>clearTimeout(s)},[ea?.filePath,er?.open,x,j,eq]),(0,r.useEffect)(()=>{j&&e7&&eB.current&&(eB.current.scrollLeft=0)},[j,e7,eB]);let tV=e=>{let t=tq??e.currentTarget.parentElement?.offsetWidth??eJ.k9.min;tK(!0),eV(e,{startWidth:t,onWidth:e=>A?.(e),onEnd:()=>tK(!1)})},tJ=(0,r.useCallback)(()=>A?.(null),[A]),[tG,tY]=(0,r.useState)(null),tZ=(0,r.useRef)(null),tQ=s_(tZ,tG?.x??0,tG?.y??0),t0=(0,r.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),tY({x:e.clientX,y:e.clientY})},[]),t1=(0,r.useCallback)(e=>{if("auto"===e)tJ();else{let t=eB.current?.clientWidth||tL-(R?0:E)-tH;if(t>0){let s=Math.max(eJ.k9.min,Math.floor((t-(e-1)*eJ.pS)/e));A?.(s)}}tY(null)},[tJ,eB,tL,R,E,tH,A]);(0,r.useEffect)(()=>{if(!tG)return;let e=e=>{tZ.current&&!tZ.current.contains(e.target)&&tY(null)},t=e=>{"Escape"===e.key&&tY(null)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",t)}},[tG]),(0,r.useEffect)(()=>{let e=()=>tJ();return window.addEventListener("terminal:fitPanes",e),()=>window.removeEventListener("terminal:fitPanes",e)},[tJ]),(0,r.useEffect)(()=>{let e=e=>{e.detail?.fraction&&t1(e.detail.fraction)};return window.addEventListener("terminal:splitPreset",e),()=>window.removeEventListener("terminal:splitPreset",e)},[t1]);let t2=(e,t,s,r=0)=>{let l=c.find(t=>t.id===e),a=l?.hostKey?eE(l.hostKey).fileBus:eD,i=e9[e],o=tv.H8.find(e=>e.id===i);return o?(0,n.jsx)(oR,{title:"AI Chat Pane",children:(0,n.jsx)(oT,{sessionId:e,engine:o.aiEngine,workspacePath:l?.cwd||l?.workspacePath||e4?.path,sessionName:l?.name,bus:eA(e),fileBus:a,isVisible:t,isFocused:s,isDesktop:j,bgIndex:r,onActivate:()=>L.handleSelectSession(e),onNewChat:()=>tp(o,e),onOpenRemote:F,onOpenMobile:K,onOpenArtifact:eo})},e):(0,n.jsx)(nq,{workspacePath:l?.workspacePath,sessionName:l?.name,bus:eA(e),fileBus:a,connected:eI,sessionId:e,isVisible:t,isFocused:s,onActivate:L.handleSelectSession,onRegisterApi:eF,onPasteFallback:eW,showFocusBorder:!1,mountDelay:(0,eQ.Mt)(e,s,e2),bgIndex:r,onOpenArtifact:eo,onOpenRemote:F,onOpenMobile:K})},t5=e=>(0,n.jsx)(t9,{bus:eA(e),sessionId:e,onExpandChange:()=>{},onRefocus:()=>eH(e),onRegisterTextApi:eO,onInputFocusChange:e_,platform:a,onInput:ej.getState().clearNotification,onSwitchSession:L.switchSession,onSwitchToIndex:L.switchToIndex,isDesktop:j,statusStrip:(0,n.jsx)(l1,{sessionId:e,busRef:ez,onReveal:t=>{let s=c.find(t=>t.id===e)?.workspacePath;tt(s,t||s),ts()}})}),t3=!!(S||T),t4=!!ex;return(0,n.jsxs)("div",{className:`absolute inset-0 flex flex-col ${k||t4||S||T?"translate-x-0 opacity-100 z-10":"-translate-x-full opacity-0 z-0 pointer-events-none"}`,children:[(0,n.jsxs)("div",{ref:tW,className:`flex-1 min-h-0 relative ${j?"flex flex-row":"flex flex-col"}`,children:[j&&(0,n.jsx)("div",{className:"hidden sm:block overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out",style:{width:R?0:E},children:(0,n.jsx)(lK,{allSessions:c,mainSessions:eM,workspaces:eP,activeSessionId:x,activeWorkspaceId:p,onSelectSession:L.handleSelectSession,onSelectWorkspace:L.handleSelectWorkspace,onCreateNamedSession:L.handleCreateSession,onResumeAgentSession:ta?eg:L.handleResumeAgentSession,shells:C,onRenameSession:L.handleRenameSession,onDeleteSession:L.handleDeleteSession,onReorderSession:tr,onDeleteWorkspace:V,onAddWorkspace:Q,onRenameWorkspace:J,onOpenSettings:ee,onOpenRemoteHost:O,onOpenMobileHost:W,onLogout:H,onRenameHost:U,onMainDisconnect:X,onDeleteHost:q,busRef:ez,homeDir:et,cwdBySession:v,connected:eI,width:E,onResize:$,onCollapse:z})}),(0,n.jsxs)("div",{className:"relative flex-1 min-w-0 min-h-0 flex flex-col",children:[j&&R&&(S||T)&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),z()},title:th(ew("menu.toggleSidebar")||"Show sidebar","toggleSidebar"),"aria-label":"Show sidebar",className:"absolute top-2 left-2 z-[70] p-1.5 rounded-brand bg-surface/90 backdrop-blur border border-border-subtle text-text-muted hover:text-text shadow-md transition-colors",children:(0,n.jsx)(el.e6,{size:14})}),S&&(0,n.jsx)("div",{className:"absolute inset-0 z-[60] overflow-hidden bg-bg",children:S}),T&&!S&&(0,n.jsx)("div",{className:"absolute inset-0 z-[60] overflow-y-auto bg-bg",children:(0,n.jsx)(iQ,{onAddWorkspace:Q,onOpenRemote:F,recent:es,homeDir:et,onOpenRecent:e=>Q?.(e)})}),!t3&&(!tk||!j)&&(0,n.jsx)(nf,{sessions:e5,allSessions:c,activeSessionId:x,isActive:k,connected:eI,onSwitchSession:tl,onCreateSession:ti?ep:L.handleQuickCreateSession,onRenameSession:L.handleRenameSession,onDeleteSession:L.handleDeleteSession,onCreateNamedSession:em,modalBusRef:to,modalHostKey:ti||"main",modalShells:ti?tc:null,onResumeAgentSession:ta?eg:L.handleResumeAgentSession,onBack:j||Z?null:B,workspaces:d,activeWorkspaceId:p,onSelectWorkspace:L.handleSelectWorkspace,hasUngrouped:c.some(e=>!(0,eQ.xs)(e)),onOpenRemote:F,onOpenMobile:K,onOpenRemoteHost:O,onOpenMobileHost:W,hostKey:ti,onOpenFiles:_,onLogout:H,tunnelUrl:ef,apiKey:eh,connectionMode:eb,subscribeToPush:ev,unsubscribeFromPush:ey,hostVersion:i||o,agentVersion:i||o,busRef:ez,carrier:l||eT,shells:C,onToggleSidebar:j?z:null,sidebarCollapsed:R,onReorderSession:tr,onToggleRightPanel:er?.onToggle,rightPanelOpen:er?.open,fileBus:eD,homeDir:et,isDesktop:j}),tC?(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(iQ,{onAddWorkspace:Q,onOpenRemote:F,recent:es,homeDir:et,onOpenRecent:e=>Q?.(e)})}):(0,n.jsxs)("div",{ref:eB,className:`flex-1 min-h-0 ${t3?"hidden":""} ${j?`relative flex flex-row ${e7?"overflow-hidden":"overflow-x-auto"} overflow-y-hidden px-0 pb-0 scrollbar-none`:"relative"}`,...D({enabled:!j,sessionIds:eZ,activeSessionId:x,onSwitch:L.handleSelectSession}),children:[t4&&(0,n.jsx)("div",{className:"absolute inset-0 z-10",children:ex}),e0.map(e=>{let t=eY.has(e),s=e===x,r=te.includes(e),l=t&&!r&&(j&&!e7||s),a=!!tx[e$(e).head||tm]?.updating,i=e3.get(e)??0;return(0,n.jsxs)("div",{ref:t=>eK(e,t),className:t4||!t||j&&e7&&!s||j&&r?"hidden":j?`h-full relative bg-bg ${a?"opacity-50 pointer-events-none":""} ${e7?"w-full flex-1":`border-r-2 border-border-subtle last:border-r-0 ${tF?"":"transition-[width] duration-200 ease-out"}`}`:`absolute inset-0 ${a?"opacity-50 pointer-events-none":s?`opacity-100 z-10 ${N}`:"opacity-0 z-0 pointer-events-none"}`,style:t&&j?e7?{width:"100%",flex:"1 1 0"}:null!=tq?{width:tq,flexShrink:0}:{flex:"1 1 0",minWidth:eJ.k9.min}:void 0,children:[e1.has(e)?e9[e]?.endsWith("-ui")?(0,n.jsx)("div",{onMouseDown:()=>{s||L.handleSelectSession(e)},onTouchStart:()=>{s||L.handleSelectSession(e)},className:"w-full h-full flex flex-col relative overflow-hidden",children:t2(e,l,s,i)}):j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(oE,{children:[t2(e,l,s,i),(0,n.jsx)(o$,{sessionId:e})]}),(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 z-20 border-t border-border-subtle bg-surface",children:s?t5(e):(0,n.jsx)("button",{type:"button",tabIndex:-1,onClick:()=>{L.handleSelectSession(e),setTimeout(eU,60)},className:"group block w-full text-left","aria-label":"Focus this terminal input",children:(0,n.jsx)("span",{className:"block w-full pl-9 pr-16 py-2 text-sm text-text-muted/60 group-hover:bg-surface-2/70 group-hover:text-text-muted transition-colors truncate",children:(0,n.jsx)(oz,{sessionId:e,placeholder:ew("mobileKeyboard.typeCommand")})})})})]}):t2(e,l,s,i):(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center text-text-muted text-xs"}),t&&j&&!e7&&!r&&(0,n.jsx)("div",{onPointerDown:tV,onDoubleClick:tJ,onContextMenu:t0,className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-30",title:ek?th(ew("shortcuts.fitPanes")||"Auto-fit panes","fitPanes"):void 0})]},e)})]}),!j&&x&&!e9[x]?.endsWith("-ui")&&t5(x)]}),(ea?.filePath||j&&tz)&&(0,n.jsx)("div",{className:j?"overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out":"absolute inset-0 z-40 animate-in slide-in-from-bottom duration-200",style:j?{width:t$&&tP?ea.width:0}:void 0,"aria-hidden":j&&!t$,children:(0,n.jsx)(iX,{filePath:t$?ea.filePath:tI?.filePath,artifactTitle:t$?ea.artifactTitle:tI?.artifactTitle,previewSeq:t$?ea.previewSeq:tI?.previewSeq,jump:t$?ea.jump:null,workspace:tf,fileBus:eL,width:ea.width,onResize:ea.onResize,onClose:ea.onClose,onOpenFull:ea.onOpenFull,onOpenFile:ea.onOpen,isDesktop:j})}),j&&ei?.open&&"pin"===ei.mode&&(0,n.jsx)("div",{ref:eG,className:"relative overflow-hidden flex-shrink-0 border-l border-border",style:{width:ei.width},children:(0,n.jsx)("div",{onPointerDown:ei.onResizeStart,className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})}),j&&ei?.open&&(0,n.jsx)(ai,{busRef:ei.busRef||ez,protocolRef:ei.protocolRef,connected:ei.connected??eI,pinSlot:eX}),er?.open&&!j&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:er.onToggle}),(er?.open||j&&tS)&&(0,n.jsx)("div",{className:j?"overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out":"absolute inset-y-0 right-0 z-30 w-[85%] max-w-sm shadow-elev animate-in slide-in-from-right duration-200",style:j?{width:er?.open&&tR?er.width:0}:void 0,"aria-hidden":j&&!er?.open,children:(0,n.jsx)(io,{workspacePath:e6,filesRoot:tf,cwdHint:tj,activeFile:ea?.filePath,fileBus:eL,tab:er.tabs?.[e6??""]||"files",onTabChange:tb,width:er.width,onResize:er.onResize,onClose:er.onToggle,onOpenFiles:_?tg:null,onOpenFile:ea?.onOpen,onNewTerminal:er.onNewTerminal,onAddWorkspace:Q,homeDir:et,hiddenRepos:ty,onHiddenReposChange:e4&&Y?tw:null,isDesktop:j})})]}),(0,n.jsx)(iV,{}),j&&!tk&&(0,n.jsx)(l2,{cwd:x&&(v[x]||m?.cwd||e4?.path)||"",sessionId:x,hostKey:m?.hostKey||null,sessionName:m?m?.name:"",hostVersion:i||o,agentVersion:i||o,platform:a,homeDir:et}),tG&&(0,n.jsxs)("div",{ref:tZ,className:"fixed z-[70] menu-popover p-1 min-w-[130px] animate-in fade-in zoom-in-95 duration-100 shadow-xl",style:{left:tQ.left,top:tQ.top},children:[(0,n.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold text-text-subtle uppercase tracking-wider",children:"Split"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),t1("auto")},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Auto Fit"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"Auto"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),t1(2)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/2"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"50%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),t1(3)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/3"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"33%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),t1(4)},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center justify-between",children:[(0,n.jsx)("span",{children:"1/4"}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"25%"})]})]})]})});var oP=s(45111);function oA({label:e,inline:t=!1}){let{t:s}=(0,eu.s)(),[l,a]=(0,r.useState)(!1),[i,o]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=setTimeout(()=>a(!0),6e3);return()=>clearTimeout(e)},[]),(0,n.jsxs)("div",{className:`${t?"absolute inset-0 z-10":"fixed inset-0 z-40"} flex items-center justify-center animate-in fade-in duration-300`,children:[(0,n.jsx)("div",{className:"cine-bg","aria-hidden":!0,children:(0,n.jsx)("div",{className:"cine-grid"})}),(0,n.jsxs)("div",{className:"relative z-10 flex flex-col items-center gap-3 px-6 text-center",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-text animate-pulse-glow"}),(0,n.jsx)("span",{className:"text-[15px] font-semibold text-text tracking-wide",children:"9Remote"})]}),(0,n.jsx)(oP.A,{size:"lg"}),(0,n.jsx)("p",{className:"text-sm text-text-muted",children:e||s("connection.retrying")}),l&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),o(!0);try{sessionStorage.setItem("9remote_manual_disconnect","1")}catch{}setTimeout(()=>window.location.reload(),150)},disabled:i,className:"mt-2 px-4 py-2 bg-surface-2 hover:bg-surface-3 active:scale-[0.96] disabled:opacity-70 border border-border-subtle rounded-brand text-xs font-medium text-text transition-all duration-150 flex items-center gap-2 animate-in fade-in duration-300",children:[(0,n.jsx)(el.e9,{size:14,className:`text-brand-500 ${i?"animate-spin":""}`}),(0,n.jsx)("span",{children:s("menu.reloadWeb")||"Reload"})]})]})]})}var oI=s(30240);function oD({sessions:e,cwdBySession:t={},connected:s,onSelect:l,onCreate:a,onDelete:i,onRename:o,onLogout:c,onOpenRemote:d,tunnelUrl:m,apiKey:p,connectionMode:f="tunnel",isActive:b=!0,busRef:g,subscribeToPush:v,unsubscribeFromPush:y,onResumeAgentSession:w=null,notifications:j,sessionStatus:k,hostVersion:N,agentVersion:C,carrier:S,workspaces:T=[],onRenameWorkspace:R,onDeleteWorkspace:E,onAddWorkspace:$,onOpenRemoteHost:z=null,onOpenMobileHost:M=null,fileBus:A,homeDir:I,recentWorkspaces:D=[],shells:L=[],onReorderSession:B,onRenameHost:F=null,onDeleteHost:K=null,onMainDisconnect:O=null,onMainReconnect:W=null}){let _,{t:H}=(0,eu.s)(),U=A||en.getState(),q=Object.values((0,P.rh)(e=>e.hosts)),X=(0,P.rh)(e=>e.currentKey),V=q.find(e=>e.key===X),J=(0,u.d)(e=>e.connected),G=(0,u.d)(e=>e.carrier),Y=(0,u.d)(e=>e.busRef),Z=s??J,Q=S||G||"ws",ee=g||Y,et=ej(e=>e.notifications),es=eM(),er=j||et,ea=k||es,ei=ev(e=>e.open),eo=ev(e=>e.setContext),ec=ev(e=>e.setCallbacks),ex=(0,h.B)(e=>e.hiddenHeaderButtons),em=(0,h.B)(e=>e.pushView),ep=(0,x.gJ)(),[ef,eh]=(0,r.useState)(null),[eb,eg]=(0,r.useState)(null),[ey,ew]=(0,r.useState)(!1),[ek,eN]=(0,r.useState)(!1),eC=q.filter(e=>("full"===e.status||"online"===e.status)&&e.remoteAvailable),eT=eS(q,V?.key);(0,r.useEffect)(()=>{if(!b)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.altKey&&!e.shiftKey&&"t"===e.key.toLowerCase()&&(e.preventDefault(),eg({workspaceId:null}))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[b]),(0,r.useEffect)(()=>{b&&(eo({connected:Z,remoteAvailable:!!d,showTheme:!1,theme:"default",busRef:ee,hideActions:["remote","files","sites"],tunnelUrl:m,apiKey:p,connectionMode:f,subscribeToPush:v,unsubscribeFromPush:y,notifications:er,hostVersion:N||C,agentVersion:N||C,carrier:Q}),ec({onRemote:null,onFiles:null,onSelectSite:null,onRefreshSites:null,onLogout:c,onThemeChange:null}))},[b,Z,d,c,eo,ec,ee,f,v,y,N,C,Q,m,p,er]);let eR=new Set(e.map(e=>e.id)),eE=!q.some(e=>e.updating)&&!e.length&&!T.length&&q.length<=1;return(0,n.jsxs)("div",{className:"h-full flex flex-col overflow-hidden relative",children:[(0,n.jsxs)("header",{className:`relative z-10 bg-surface/80 backdrop-blur-md pl-[28px] pr-4 py-3 ${sZ} flex items-center justify-between gap-2 flex-shrink-0 border-b border-border-subtle`,style:{paddingTop:"calc(0.75rem + env(safe-area-inset-top, 0px))"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("img",{src:"/icon-192.png",alt:"9Remote",draggable:!1,className:"w-5 h-5 rounded-brand flex-shrink-0"}),(0,n.jsx)("h1",{className:"text-text text-lg font-semibold truncate",children:H("sessions.headerTitle")}),(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${Z?"bg-green-500":"bg-red-500 animate-pulse"}`,title:Z?H("sessions.connected"):H("sessions.disconnected")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[!ex.includes("remote")&&eC.length>0&&(0,n.jsx)(oL,{icon:el.VA,label:H("menu.remoteDesktop"),onClick:()=>{((0,ed.e)(),1===eC.length)?z?.(eC[0].key):eN(!0)},disabled:!Z}),ep&&(0,n.jsx)(oL,{icon:el.vW,label:H("connection.pairTab"),onClick:()=>{(0,ed.e)(),em({type:"pair"})}}),(0,n.jsx)(oL,{icon:el.kV,label:H("hosts.addHost"),onClick:()=>{(0,ed.e)(),ew(!0)}}),(0,n.jsx)(oL,{icon:el.wB,label:H("menu.title"),onClick:ei})]})]}),(0,n.jsx)("div",{className:"relative z-10 flex-1 overflow-auto modal-scrollable pt-2 pb-12",style:{overflowAnchor:"none"},children:eE?(0,n.jsx)("div",{className:"absolute inset-0 z-10",children:(0,n.jsx)(oB,{onAddWorkspace:$,recent:D,homeDir:I,connected:Z})}):(0,n.jsx)(n.Fragment,{children:eT.map((s,r)=>(0,n.jsx)("div",{className:0===r?"pl-1 pr-3":"mt-3 border-t border-border-subtle pt-2 pl-1 pr-3",children:s.key===(V?.key||"main")&&V?(0,n.jsx)(lL,{mobile:!0,host:{...V,workspaces:T,sessions:e,statusMap:ea,onDisconnect:O,onConnect:W},busRef:ee,onResumeAgentSession:w,actions:{selectSession:l,createSession:a,renameSession:o,deleteSession:i,backgroundSession:e=>eh(e),reorderSession:B,renameWorkspace:R,deleteWorkspace:E,renameHost:F,deleteHost:K},connected:Z,fileBus:U,homeDir:I,cwdBySession:t,onAddWorkspace:$,menuAddWorkspace:$,onOpenRemoteHost:z,onOpenMobileHost:M,treeCls:"pl-5",rowCls:"active:bg-surface-2 active:text-text"}):(0,n.jsx)(lL,{mobile:!0,host:{...s,onDisconnect:()=>P.rh.getState().disconnectHost(s.key)},actions:{...tn(s,{onSelectSession:l}),renameHost:F,deleteHost:K},connected:Z,onOpenRemoteHost:z,onOpenMobileHost:M,treeCls:"pl-5",rowCls:"active:bg-surface-2 active:text-text"})},s.key))})}),ef&&(0,n.jsx)(sX,{sessionId:ef.id,title:ef.name,busRef:ee,onClose:()=>eh(null)}),eb&&(0,n.jsx)(sW,{onClose:()=>eg(null),onCreate:(e,t,s,n,r,l)=>{a?.(e,eb.workspaceId,t,r||null,s,n,l),eg(null)},shells:L,busRef:ee,onResumeAgentSession:w,onSelectSession:l,liveSessionIds:eR,connected:Z,workspaceId:eb.workspaceId,workspacePath:T.find(e=>e.id===eb.workspaceId)?.path||null,workspaceName:T.find(e=>e.id===eb.workspaceId)?.name||"",fileBus:U,homeDir:I,suggestName:`${H("terminal.defaultName")} ${(_=eb.workspaceId,e.filter(e=>(0,eQ.xs)(e)===_)).length+1}`}),ey&&(0,n.jsx)(nZ,{onClose:()=>ew(!1)}),ek&&(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-150",onClick:()=>eN(null),children:(0,n.jsx)("div",{className:"card-elev w-full sm:max-w-sm max-h-[60%] overflow-auto modal-scrollable rounded-t-2xl sm:rounded-2xl p-2 animate-in slide-in-from-bottom-4 duration-150",onClick:e=>e.stopPropagation(),children:eC.map(e=>(0,n.jsxs)("button",{onClick:()=>{let t=e.key;eN(!1),z?.(t)},className:"w-full flex items-center gap-2.5 px-3 py-3 text-left rounded-brand hover:bg-surface-2 active:bg-surface-2 transition-colors",children:[(0,n.jsx)(el.VA,{size:16,className:"text-text-muted shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm text-text",children:e.label||H("agentSwitcher.unnamed")})]},e.key))})})]})}function oL({icon:e,label:t,onClick:s,disabled:r,className:l=""}){return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s()},disabled:r,title:t,className:`p-2 rounded-brand transition-colors active:scale-[0.96] ${r?"text-text-subtle cursor-not-allowed":`text-text-muted hover:text-text hover:bg-surface-2 ${l}`}`,children:(0,n.jsx)(e,{className:"w-5 h-5"})})}function oB({onAddWorkspace:e,recent:t,homeDir:s,connected:l}){let{t:a}=(0,eu.s)();(0,h.B)(e=>e.pushView);let[i,o]=(0,r.useState)(!1);return(0,n.jsxs)("div",{className:"empty-stage w-full h-full",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),e?.()},disabled:!l,className:"empty-half text-left active:opacity-80 enabled:active:scale-[0.99] transition-all duration-150 disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",a("workspaces.emptyTagVibe")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordVibe")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:a("workspaces.emptyMetaVibe")}}),(0,n.jsxs)("span",{className:"empty-go",children:[a("workspaces.emptyGoVibe"),(0,n.jsx)(el.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]}),!!t.length&&(0,n.jsx)("span",{className:"flex flex-wrap gap-1.5 mt-4 max-w-full",children:t.slice(0,3).map(t=>(0,n.jsx)("span",{role:"button",title:t.path,onClick:s=>{s.stopPropagation(),(0,ed.e)(),e?.(t.path)},className:"welcome-chip path-tail px-2 py-1 text-[11px] font-mono text-text-muted rounded-full truncate max-w-[46%]",children:iG(t.path)},t.path))})]}),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"empty-hairline","aria-hidden":!0}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),o(!0)},className:"empty-half text-left active:opacity-80 enabled:active:scale-[0.99] transition-all duration-150 disabled:opacity-40 disabled:saturate-50",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"02"})," / ",a("workspaces.emptyTagPair")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:a("workspaces.emptyWordPair")}),(0,n.jsx)("span",{className:"empty-meta",children:(0,n.jsx)(iY,{})}),(0,n.jsxs)("span",{className:"empty-go",children:[a("workspaces.emptyGoPair"),(0,n.jsx)(el.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]})]})]}),i&&(0,n.jsx)(nZ,{onClose:()=>o(!1)})]})}let oF=(e,t,s)=>Math.max(t,Math.min(s,e));function oK({clientX:e,clientY:t,containerRect:s,pan:n,totalScale:r}){return{x:(e-s.left-n.x)/r,y:(t-s.top-n.y)/r}}function oO(e,t){return{x:Math.min(0,e.width-t.width),y:Math.min(0,e.height-t.height)}}function oW(e,t){return{x:oF(e.x,t.x,0),y:oF(e.y,t.y,0)}}function o_({prevZoom:e,prevPan:t,focal:s,nextZoomRaw:n,maxZoom:r,containerSize:l,displaySizeAt:a}){let i=oF(n,1,r),o=i/e,c=oO(l,a(i));return{zoom:i,pan:oW({x:s.x-(s.x-t.x)*o,y:s.y-(s.y-t.y)*o},c)}}function oH({accum:e,delta:t,threshold:s,multiplier:n}){let r=e+t;if(Math.abs(r)<s)return{accum:r,scroll:null};let l=Math.max(1,Math.round(Math.abs(r)*n));return{accum:0,scroll:r>0?l:-l}}let oU=!!window.chrome,oq=e=>new Blob([e]),oX=(e,t)=>()=>{e.current[t]=null},oV=null,oJ=0,oG=new Map;async function oY(e){if("u"<typeof createImageBitmap)return null;if(oU)return createImageBitmap(e);let t=new Image,s=URL.createObjectURL(e);t.src=s,await t.decode();let n=await createImageBitmap(t);return URL.revokeObjectURL(s),n}function oZ(e,t,n,{ackEvent:l="tile-ack",verifyEvent:a="request-screen-with-hashes",targetId:i=null,resetWorker:o=!0}={}){let[d,u]=(0,r.useState)(126),[x,m]=(0,r.useState)(!1),p=(0,r.useRef)(new Set),f=(0,r.useRef)(new Map),h=(0,r.useRef)([]),b=(0,r.useRef)(!1),g=(0,r.useRef)(0),v=(0,r.useRef)(new Set),y=(0,r.useRef)(new Set),w=(0,r.useRef)(new Map),j=(0,r.useRef)(new Map),k=(0,r.useRef)(null),N=(0,r.useRef)(t);(0,r.useEffect)(()=>{N.current=t},[t]);let C=(0,r.useCallback)(()=>{k.current=null;let t=n?.current;if(!t)return void j.current.clear();let s=t.getContext("2d"),r=0;for(let[e,t]of j.current){let{bitmap:n,x:l,y:a,width:i,height:o,frameTs:c,invalidateTileHash:d}=t;if((w.current.get(e)??c)>c){n?.close?.();continue}try{s.drawImage(n,l,a,i,o),p.current.add(e),m(!0),c>r&&(r=c),n?.close?.()}catch{d()}}if(j.current.clear(),r>0){let t=i?{targetId:i,ts:r}:{ts:r};e?.current?.emit(l,t)}},[n,e,l,i]),S=(0,r.useCallback)((e=!1)=>{e&&k.current&&(cancelAnimationFrame(k.current),k.current=null),k.current||(k.current=requestAnimationFrame(C))},[C]),T=(0,r.useCallback)(e=>{if(n?.current)try{let t=n.current.getContext("2d");t.imageSmoothingEnabled=!1;let s=new Image;s.onload=()=>{if(n?.current)try{t.drawImage(s,0,0,e.screen.width,e.screen.height),p.current.clear();for(let e=0;e<d;e++)p.current.add(e);m(!0)}catch(e){}},s.src=e.screen.imageBase64}catch(e){console.error("Full screen error:",e)}},[n,d]),R=(0,r.useCallback)(e=>{if(n?.current)try{if(n.current.getContext("2d"),g.current=Date.now(),e.currentHashes&&Array.isArray(e.currentHashes)&&(h.current=e.currentHashes,b.current=!1),!e.tiles?.length)return;let t=e.timestamp||Date.now();for(let s of e.tiles){let e=f.current.get(s.tileIndex),n=w.current.get(s.tileIndex)??0;t>=n&&(e?.controller&&(e.controller.cancelled=!0),w.current.set(s.tileIndex,t),null!=s.hash&&(h.current[s.tileIndex]=s.hash))}if(void 0!==e.hasBitmap){for(let s of e.tiles){if(!s.bitmap&&!s.imageBuffer)continue;if((w.current.get(s.tileIndex)??t)>t){s.bitmap?.close?.();continue}let e=oX(h,s.tileIndex);s.bitmap?j.current.set(s.tileIndex,{bitmap:s.bitmap,x:s.x,y:s.y,width:s.width,height:s.height,frameTs:t,invalidateTileHash:e}):oY(oq(s.imageBuffer)).then(n=>{n&&(j.current.set(s.tileIndex,{bitmap:n,x:s.x,y:s.y,width:s.width,height:s.height,frameTs:t,invalidateTileHash:e}),S(!0))}).catch(()=>{e()})}S(!0);return}let s=[];for(let t=0;t<e.tiles.length;t+=c.eR.batchSize)s.push(e.tiles.slice(t,t+c.eR.batchSize));s.forEach((e,s)=>{let r=setTimeout(()=>{v.current.delete(r),e.forEach(e=>{if(!e.imageBuffer&&!e.imageBase64)return;if((w.current.get(e.tileIndex)??t)>t)return void f.current.delete(e.tileIndex);let s={cancelled:!1};f.current.set(e.tileIndex,{controller:s});let r=setTimeout(()=>{s.cancelled=!0,f.current.delete(e.tileIndex),h.current[e.tileIndex]=null},c.eR.tileLoadTimeout),l=oX(h,e.tileIndex),a=a=>{s.cancelled||!n?.current?a?.close?.():(clearTimeout(r),f.current.delete(e.tileIndex),j.current.set(e.tileIndex,{bitmap:a,x:e.x,y:e.y,width:e.width,height:e.height,frameTs:t,invalidateTileHash:l}),S())};if(e.imageBuffer&&"u">typeof createImageBitmap)oY(oq(e.imageBuffer)).then(a).catch(()=>{if(s.cancelled)return;let t=new Image,n=URL.createObjectURL(oq(e.imageBuffer));t.onload=()=>{a(t),URL.revokeObjectURL(n)},t.onerror=()=>{URL.revokeObjectURL(n),clearTimeout(r),f.current.delete(e.tileIndex),l()},t.src=n});else{let t=new Image;if(e.imageBuffer){let s=URL.createObjectURL(oq(e.imageBuffer));t.onload=()=>{a(t),URL.revokeObjectURL(s)},t.onerror=()=>{URL.revokeObjectURL(s),clearTimeout(r),f.current.delete(e.tileIndex),l()},t.src=s}else t.onload=()=>a(t),t.onerror=()=>{clearTimeout(r),f.current.delete(e.tileIndex),l()},t.src=`data:image/jpeg;base64,${e.imageBase64}`}})},s*c.eR.batchDelay);v.current.add(r)})}catch(e){console.error("Tiles data error:",e)}},[n,S]),E=(0,r.useCallback)((e,t,n="ws")=>{if(!e)return;let r=e instanceof ArrayBuffer?e:e?.buffer;if(!r)return;let l=function(){if(!1===oV)return null;if(oV)return oV;try{return(oV=new Worker(s.tu(new URL(s.p+s.u(1311),s.b)))).onmessage=({data:{tiles:e,timestamp:t,id:s,hasBitmap:n,error:r}})=>{let l=oG.get(s);if(!l){if(e)for(let t of e)t.bitmap?.close?.();return}clearTimeout(l.timer),oG.delete(s),l.resolve(r?null:{tiles:e,timestamp:t,hasBitmap:n})},oV}catch{return oV=!1,null}}();if(!l)return;let a=r.byteLength,i=++oJ;new Promise(e=>{let s=setTimeout(()=>{oG.has(i)&&(oG.delete(i),e(null))},c.eR.tileLoadTimeout),n=c.eR.decodeQueueCap;for(;oG.size>=n;){let e=oG.keys().next().value,t=oG.get(e);if(!t)break;clearTimeout(t.timer),oG.delete(e),t.resolve(null)}oG.set(i,{resolve:e,timer:s}),l.postMessage({buffer:r,id:i,v:t},[r])}).then(e=>{e&&(2===t&&(b.current=!1),R({tiles:e.tiles,timestamp:e.timestamp,hasBitmap:e.hasBitmap,bytes:a,transport:n}))})},[R]),$=(0,r.useCallback)(e=>E(e,1,"ws"),[E]),z=(0,r.useCallback)(e=>E(e,2,"ws"),[E]),M=(0,r.useCallback)(e=>{e&&(g.current=Date.now(),e.currentHashes&&Array.isArray(e.currentHashes)&&(h.current=e.currentHashes,b.current=!1))},[]),P=(0,r.useCallback)(e=>{e()},[]),A=(0,r.useCallback)(e=>{e.tileCount&&u(e.tileCount)},[]),I=(0,r.useCallback)(()=>{if(!e?.current||!N.current||b.current||0===h.current.length||Date.now()-g.current<c.eR.lastDataThreshold)return;b.current=!0;let t=i?{targetId:i,tileHashes:h.current}:{tileHashes:h.current};e.current.emit(a,t);let s=setTimeout(()=>{y.current.delete(s),b.current=!1},1e3);y.current.add(s)},[e,a,i]),D=(0,r.useCallback)(()=>{for(let[,e]of f.current.entries())e.controller&&(e.controller.cancelled=!0);f.current.clear(),h.current=[],p.current.clear(),w.current.clear(),g.current=0,b.current=!1,m(!1),o&&function(){if(oV&&!1!==oV)try{oV.terminate()}catch{}for(let e of(oV=null,oG.values()))try{e.resolve(null)}catch{}oG.clear()}(),k.current&&(cancelAnimationFrame(k.current),k.current=null),j.current.clear()},[o]);return(0,r.useEffect)(()=>{let e=v.current,t=y.current;return()=>{e.forEach(clearTimeout),e.clear(),t.forEach(clearTimeout),t.clear()}},[]),{renderedTilesRef:p,totalTileCount:d,hasFrame:x,handleFullScreenData:T,handleTilesData:R,handleTilesBinary:$,handleTilesBinaryV2:z,handleTilesMeta:M,startStreamingWithTiles:P,handleScreenDimensions:A,cleanupTiles:D,requestScreenWithHashes:I,clientTileHashesRef:h,tileTimestampRef:w}}let oQ={fps:0,latency:0,tilesPerSec:0,bandwidthMBps:0,webrtcTiles:0,wsTiles:0,webrtcPercent:0};function o0({list:e,activeIndex:t,onSelect:s}){if(!Array.isArray(e)||e.length<=1)return null;let r=e=>e.stopPropagation();return(0,n.jsx)("div",{className:"absolute bottom-1.5 right-1.5 z-40 flex gap-1.5",children:e.map(e=>{let l=e.index===t,a=`${e.index+1}`;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s?.(e.index)},onMouseDown:e=>e.preventDefault(),onPointerDown:r,onPointerUp:r,onPointerMove:r,onTouchStart:r,onTouchMove:r,onTouchEnd:r,onWheel:r,className:`px-1.5 py-0.5 rounded-md text-xs font-medium backdrop-blur-md border transition-colors inline-flex items-center gap-1 ${l?"bg-blue-500/70 text-white border-blue-400/70":"bg-black/30 text-white/80 border-white/10 hover:bg-black/50"}`,title:`${e.name} (${e.width}\xd7${e.height})`,children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]}),a]},e.index)})})}function o1({canvasRef:e,canvasContainerRef:t,canvasZoom:s,canvasPan:l,fitScale:a,streaming:i,hasFrame:o=!0,selectionRect:d,clickIndicator:u,pointerMode:x,selectionMode:m,handMode:p,handHolding:f,scrollLock:h,virtualCursor:b,cursorShape:g,inputMode:v,keyboardOn:y,monitors:w,activeMonitorIndex:j,onSelectMonitor:k,onPointerDown:N,onPointerMove:C,onPointerUp:S,onWheel:T,onContextMenu:R,onDoubleClick:E,onTouchStart:$,onTouchMove:z,onTouchEnd:M,onKeyDown:P,screenLocked:A,unlockReady:I,unlockResult:D,onUnlockSubmit:L}){let B=a*s,F="mouse"===v,{t:K}=(0,eu.s)(),[O,W]=(0,r.useState)(!1),[_,H]=(0,r.useState)(""),[U,q]=(0,r.useState)(!1),[X,V]=(0,r.useState)(!1);(0,r.useEffect)(()=>{A||(H(""),q(!1))},[A]),(0,r.useEffect)(()=>{D&&q(!1)},[D]);let J={ew:"cursor-ew-resize",ns:"cursor-ns-resize",nwse:"cursor-nwse-resize",nesw:"cursor-nesw-resize",all:"cursor-move"},G=m?"cursor-crosshair":p?f?"cursor-grabbing":"cursor-grab":F&&O?"cursor-grabbing":F&&g&&J[g]?J[g]:"trackpad"===x?"cursor-grab active:cursor-grabbing":"cursor-default",Y=(0,r.useRef)(T);return(0,r.useEffect)(()=>{Y.current=T},[T]),(0,r.useEffect)(()=>{let t=e.current;if(!t)return;let s=e=>Y.current?.(e);return t.addEventListener("wheel",s,{passive:!1}),()=>t.removeEventListener("wheel",s)},[e]),(0,r.useEffect)(()=>{F&&i&&e.current?.focus()},[e,F,i]),(0,r.useEffect)(()=>{if(!O)return;let e=()=>W(!1);return window.addEventListener("pointerup",e),window.addEventListener("pointercancel",e),window.addEventListener("blur",e),()=>{window.removeEventListener("pointerup",e),window.removeEventListener("pointercancel",e),window.removeEventListener("blur",e)}},[O]),(0,n.jsxs)("div",{className:"w-full h-full overflow-hidden relative flex-1",children:[(0,n.jsxs)("div",{className:"absolute inset-0",ref:t,style:{touchAction:"none"},onTouchStart:$,onTouchMove:z,onTouchEnd:M,children:[(0,n.jsx)("canvas",{ref:e,className:`block ${G} bg-black outline-none`,style:{touchAction:"none",transformOrigin:"top left",userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent",transform:`translate3d(${l.x}px, ${l.y}px, 0) scale(${B})`,imageRendering:"auto",willChange:"transform"},onPointerDown:t=>{let s=document.activeElement;if(s?.name==="remote-batch-input")if(y){let e=document.querySelector('textarea[name="remote-keyboard-sink"]');e?.focus()}else s.blur();F&&(e.current?.focus(),"mouse"===t.pointerType&&W(!0)),N?.(t)},onPointerMove:C,onPointerUp:e=>{F&&"mouse"===e.pointerType&&W(!1),S?.(e)},onDoubleClick:E,onContextMenu:R,tabIndex:0,onKeyDown:P}),i&&!o&&!A&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 flex items-center justify-center pointer-events-none",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-black/60 text-white/80 text-[11px] font-mono",children:[(0,n.jsx)(el.kr,{size:12,className:"animate-spin"}),K("remote.receivingImage",{defaultValue:"Receiving screen…"})]})}),d&&(0,n.jsx)("div",{className:"absolute border-2 border-blue-400 bg-blue-400/20 z-10",style:{left:`${d.x}px`,top:`${d.y}px`,width:`${d.width}px`,height:`${d.height}px`}}),"trackpad"===x&&b&&(0,n.jsx)("div",{className:"absolute pointer-events-none z-30",style:{left:`${b.x*B+l.x}px`,top:`${b.y*B+l.y}px`,width:`${c.eR.trackpadCursorSize}px`,height:`${c.eR.trackpadCursorSize}px`,transform:g||p||h||m?"translate(-50%, -50%)":"translate(-2px, -2px)"},children:h?(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center text-yellow-400 drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{fontSize:`${c.eR.trackpadCursorSize}px`,lineHeight:1},children:"✥"}):m?(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full text-yellow-400 drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",children:(0,n.jsx)("path",{d:"M12 3 V21 M3 12 H21",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})}):p?(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{fontSize:`${c.eR.trackpadCursorSize}px`,lineHeight:1},children:f?"✊":"✋"}):g?(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",style:{transform:`rotate(${"ns"===g?90:"nwse"===g?45:"nesw"===g?-45:0}deg)`},children:"all"===g?(0,n.jsx)("path",{d:"M12 3 V21 M3 12 H21 M8 6 L12 2 L16 6 M8 18 L12 22 L16 18 M6 8 L2 12 L6 16 M18 8 L22 12 L18 16",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"}):(0,n.jsx)("path",{d:"M3 12 H21 M7 8 L3 12 L7 16 M17 8 L21 12 L17 16",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)("svg",{viewBox:"0 0 24 24",className:"w-full h-full drop-shadow-[0_1px_2px_rgba(0,0,0,0.8)]",children:(0,n.jsx)("path",{d:"M4 2 L4 18 L8.5 14 L11 20 L14 18.5 L11.5 13 L18 12.5 Z",fill:"#ffffff",stroke:"#000000",strokeWidth:"1.2",strokeLinejoin:"round"})})}),u&&(0,n.jsxs)("div",{className:"absolute pointer-events-none z-20",style:{left:`${u.x-u.size/2}px`,top:`${u.y-u.size/2}px`,width:`${u.size}px`,height:`${u.size}px`},children:[(0,n.jsx)("div",{className:"w-full h-full rounded-full border-2 border-blue-400 bg-blue-400/30 animate-ping"}),(0,n.jsx)("div",{className:"absolute inset-0 w-full h-full rounded-full border-2 border-blue-400 bg-blue-400/50"})]})]}),(0,n.jsx)(o0,{list:w,activeIndex:j,onSelect:k}),A&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center",style:{background:"radial-gradient(circle at 50% 40%, rgba(40,60,140,0.55) 0%, rgba(10,12,30,0.92) 60%, rgba(0,0,0,0.96) 100%)"},children:(0,n.jsx)("div",{className:"w-full max-w-[300px] mx-4 rounded-2xl p-5 shadow-2xl backdrop-blur-md",style:{background:"rgba(20,22,40,0.85)",border:"1px solid rgba(120,140,220,0.25)"},children:I?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 mb-4",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center",style:{background:"rgba(120,140,220,0.18)"},children:(0,n.jsx)(el.LM,{size:26,color:"#a9b8ff"})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-white",children:K("remote.lockTitle")}),(0,n.jsx)("p",{className:"text-xs text-center",style:{color:"rgba(220,225,245,0.7)"},children:K("remote.lockDesc")})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{type:X?"text":"password",value:_,autoFocus:!0,disabled:U,onChange:e=>H(e.target.value),onKeyDown:e=>{"Enter"===e.key&&_&&!U&&(q(!0),L?.(_))},placeholder:K("remote.lockPlaceholder"),className:"w-full rounded-xl px-4 py-2 pr-11 text-sm text-white focus:outline-none focus:border-blue-400",style:{background:"rgba(255,255,255,0.08)",border:"1px solid rgba(120,140,220,0.35)"}}),(0,n.jsx)("button",{type:"button",onClick:()=>V(e=>!e),tabIndex:-1,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 rounded-lg",style:{color:"rgba(220,225,245,0.7)"},"aria-label":X?"Hide password":"Show password",children:X?(0,n.jsx)(el.X_,{size:18}):(0,n.jsx)(el.kU,{size:18})})]}),(0,n.jsx)("button",{type:"button",disabled:!_||U,onClick:()=>{q(!0),L?.(_)},className:"w-full mt-2.5 rounded-xl py-2.5 text-sm font-semibold text-white transition-opacity disabled:opacity-40",style:{background:"linear-gradient(135deg, #4a6cf7 0%, #6b8aff 100%)"},children:K(U?"remote.unlocking":"remote.unlock")}),D&&!D.ok&&(0,n.jsx)("p",{className:"mt-3 text-xs text-center text-red-300",children:K("remote.unlockFailed")})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center",style:{background:"rgba(120,140,220,0.18)"},children:(0,n.jsx)(el.LM,{size:26,color:"#a9b8ff"})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-white",children:K("remote.lockTitle")}),(0,n.jsx)("p",{className:"text-xs",style:{color:"rgba(220,225,245,0.85)"},children:K("remote.lockGrantDesc")})]})})})]})}var o2=s(80186);let o5=(e,...t)=>{(0,ed.e)(),e?.(...t)};function o3({active:e,primary:t,pinned:s,children:r,className:l="",onClick:a,...i}){return(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:a,className:`shrink-0 px-1 h-8 rounded-brand text-xs font-semibold shadow-sm disabled:opacity-50 disabled:cursor-not-allowed min-w-[34px] flex items-center justify-center ${e?"bg-brand-500 text-white shadow-sm transition-all duration-150 ease-out active:scale-[0.94]":s?"bg-brand-500/15 hover:bg-brand-500/25 text-brand-400 transition-all duration-150 ease-out active:scale-[0.94]":t?"bg-green-600 hover:bg-green-700 text-white shadow-sm transition-all duration-150 ease-out active:scale-[0.94]":"bg-surface-2 hover:bg-surface-3 text-text transition-all duration-150 ease-out active:scale-[0.94]"} ${l}`,style:{touchAction:"manipulation",WebkitTapHighlightColor:"transparent"},...i,children:r})}function o4({streaming:e,canvasZoom:t,clipboardNew:s,clipboardText:l,onOpenClipboard:a,selectionMode:i,pointerMode:o,handMode:d,inputMode:u,onToggleHandMode:x,onTogglePointerMode:m,modifierKeys:p,textInputValue:f,textInputRef:h,keyboardOn:b,showTextPanel:g,onResetZoom:v,onRefresh:y,onToggleSelection:w,onToggleModifier:j,onToggleKeyboard:k,onToggleTextPanel:N,onToggleHelp:C,onToggleDebug:S,debugOn:T,onEmitKey:R,onTextInputChange:E,onTextInputFocus:$,onTextInputBlur:z,onTextInputKeyDown:M,onDirectInputChange:P,onSendText:A,onClose:I,onDesktopSwitch:D,controlsHidden:L,onToggleControlsHidden:B,tallLandscape:F}){let K,O,W,_,{t:H,locale:U}=(0,eu.s)(),q=(0,r.useRef)(null),[X]=tD(U),[V,J]=(0,r.useState)(!1),G=tF({lang:tA(X),onText:e=>{E(e);let t=q.current;t&&requestAnimationFrame(()=>{try{t.selectionStart=t.selectionEnd=t.value.length}catch{}t.scrollTop=t.scrollHeight})}});(0,r.useEffect)(()=>{let e=q.current;e&&!window.matchMedia("(orientation: landscape)").matches&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,72)}px`)},[f]);let Y=()=>{G.listening&&G.stop(),o5(A,e)},Z=`flex gap-1.5 overflow-auto scroll-thin-x py-0.5 pr-2 ${F?"":"landscape:flex-wrap landscape:overflow-y-auto landscape:overflow-x-hidden landscape:py-2 landscape:pr-0 landscape:content-center landscape:justify-center"} rounded-lg`,[Q,ee]=(0,r.useState)(!1),[et,es]=(0,r.useState)(!1),[en,er]=(0,r.useState)(0);(0,r.useEffect)(()=>{if(!s)return void er(0);er(Math.ceil(c.eR.clipboardBadgeTimeout/1e3));let e=setInterval(()=>{er(e=>e<=1?0:e-1)},1e3);return()=>clearInterval(e)},[s,l]);let ea=t_("remoteDesktop.bottomKeys",c.ij,c.D5,"flat"),ei=t_("remoteDesktop.extraKeys",c.ij,c.I9,"grid");(0,r.useEffect)(()=>{if(!g)return;let e=setTimeout(()=>q.current?.focus(),350);return()=>clearTimeout(e)},[g]);let eo=c.eR.pcModeControls,ec=e=>"mouse"!==u||eo[e],ex=window.innerWidth<768,em=(t,s,r=!1,l="")=>{let a=t.label.length>1?"text-[11px]":"",i=`${l} ${a}`.trim();if("modifier"===t.type)return(0,n.jsx)(o3,{onClick:()=>o5(j,t.modifier),disabled:!e,active:p[t.modifier],pinned:r,className:i,children:t.label},t.id+s);if("desktop"===t.type){let l="prev"===t.direction?el.JG:"next"===t.direction?el.c_:el.FW;return(0,n.jsxs)(o3,{onClick:()=>o5(D,t.direction),disabled:!e,pinned:r,className:i,title:`${t.direction} desktop`,children:[(0,n.jsx)(el.VA,{size:12}),(0,n.jsx)(l,{size:"new"===t.direction?10:12,className:"-ml-0.5"})]},t.id+s)}return(0,n.jsx)(o3,{onClick:()=>o5(R,t.key,t.modifiers||[],t.osAdaptive),disabled:!e,primary:!r&&t.primary,pinned:r,className:i,children:t.label},t.id+s)};return(0,n.jsxs)("div",{className:`bg-bg select-none relative landscape:flex landscape:flex-col landscape:shrink-0 ${F||L?"":"landscape:h-full landscape:justify-end"} ${L?"landscape:w-12":F?"landscape:w-full landscape:pl-12":"landscape:w-64"}`,children:[(0,n.jsx)("textarea",{ref:h,rows:1,value:f,onChange:e=>{b?P?.(e.target.value):E(e.target.value)},onKeyDown:M,onFocus:$,onBlur:z,"aria-hidden":"true",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"data-lpignore":"true","data-1p-ignore":"true","data-form-type":"other",name:"remote-keyboard-sink",style:{position:"absolute",opacity:.01,width:1,height:1,border:0,padding:0,left:0,top:0,fontSize:16,resize:"none",pointerEvents:"none",zIndex:-1}}),(0,n.jsx)("div",{className:`absolute top-1 right-1 z-30 ${L||F?"hidden":"hidden landscape:flex"}`,children:(0,n.jsx)(o3,{onClick:()=>{(0,ed.e)(),B?.(!0)},title:H("remote.hideControls"),children:(0,n.jsx)(el.X_,{size:14})})}),(0,n.jsxs)("div",{className:L?"landscape:hidden":"contents",children:[(0,n.jsxs)("div",{className:`${g?"flex":"hidden"} landscape:flex ${F?"":"landscape:flex-col"} relative z-30 px-2 py-1 gap-2 ${F?"landscape:px-0":"landscape:gap-1 landscape:order-last"}`,children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsx)(tM,{value:f,store:tN,isMobile:ex,onSelect:e=>{E(e),q.current?.focus()}}),(0,n.jsx)("textarea",{ref:q,rows:1,cols:1,value:f,onChange:e=>E(e.target.value),onFocus:$,onKeyDown:t=>{"mouse"===u&&"Enter"===t.key&&!t.shiftKey&&(t.preventDefault(),e&&Y())},placeholder:"mouse"===u?H("remoteControls.enterToSend"):H("remoteControls.typeToSend"),autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"data-lpignore":"true","data-1p-ignore":"true","data-form-type":"other",name:"remote-batch-input",className:`block w-full px-3 py-2 pr-8 bg-surface-2 rounded text-text text-sm placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out resize-none overflow-y-auto ${F?"":"landscape:!h-16"}`,disabled:!e}),f?(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{E(""),q.current?.focus()},title:H("voice.clear"),className:"absolute right-1.5 top-1.5 w-5 h-5 flex items-center justify-center text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(el.X,{size:14})}):(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>J(!0),title:H("history.title"),className:"absolute right-1.5 top-1.5 w-5 h-5 flex items-center justify-center text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(el.BZ,{size:14})})]}),(0,n.jsxs)("div",{className:"flex gap-2 items-center justify-end",children:[G.active&&(0,n.jsx)("div",{className:"relative shrink-0",children:(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{G.listening?G.stop():(document.activeElement?.blur(),G.start(f))},disabled:!e,title:"not-allowed"===G.error||"service-not-allowed"===G.error?H("voice.denied"):H("voice.dictate"),className:`h-9 w-9 flex items-center justify-center rounded-full transition-all duration-150 ease-out disabled:opacity-40 ${G.listening?"bg-red-500/90 text-white animate-pulse":G.error?"bg-surface-2 text-red-400":"bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text"}`,children:G.listening?(0,n.jsx)(el.jj,{size:18}):(0,n.jsx)(el.GO,{size:18})})}),(0,n.jsx)(o2.A,{variant:"primary",size:"sm",className:"!px-2.5 shrink-0",onMouseDown:e=>e.preventDefault(),onClick:Y,disabled:!e,children:f.trim()?H("remoteControls.send"):(0,n.jsx)(el.Lt,{size:16,strokeWidth:2.5})})]})]}),(0,n.jsx)("div",{className:`overflow-hidden transition-all duration-300 ${Q?"max-h-56 opacity-100":"hidden"}`,children:(0,n.jsx)("div",{className:"px-2 py-1",children:(0,n.jsx)("div",{className:"space-y-1",children:ei.rows.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0 flex gap-1.5 overflow-x-auto scroll-thin-x pr-3 rounded-lg",children:e.map((e,s)=>{let n=c.ij.find(t=>t.id===e);return n?em(n,100*t+s):null})}),0===t&&(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),es(!0)},className:"shrink-0 h-10 w-10 flex items-center justify-center text-text-muted hover:text-text bg-surface-2 hover:bg-surface-3 rounded-brand transition-all duration-150 ease-out",title:H("remote.customizeKeys"),children:(0,n.jsx)(el.wB,{size:16})}),t>0&&(0,n.jsx)("div",{className:"shrink-0 h-10 w-10"})]},t))})})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 landscape:hidden",children:[(0,n.jsxs)("div",{className:`${Z} flex-1 min-w-0 px-0 py-0 landscape:py-0`,children:[(0,n.jsx)(o3,{onClick:()=>o5(I),title:H("remote.back"),pinned:!0,className:"landscape:hidden",children:(0,n.jsx)(el.JG,{size:16})}),s&&l?(0,n.jsxs)(o3,{onClick:()=>o5(a),className:"!text-red-500 landscape:hidden",title:H("common.clipboard"),children:[(0,n.jsx)(el.Ir,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"tabular-nums",children:en})]}):(0,n.jsxs)(o3,{onClick:()=>o5(v),disabled:!e,className:"text-text landscape:hidden",title:H("remote.resetZoom"),children:[Math.round(100*t),"%"]}),(0,n.jsx)(o3,{onClick:()=>o5(y),disabled:!e,title:H("remote.refresh"),className:"landscape:hidden",children:(0,n.jsx)(el.e9,{size:14})}),ec("rectangleSelect")&&(0,n.jsx)(o3,{onClick:()=>o5(w),disabled:!e,active:i,title:H("remote.rectangleSelection"),className:"landscape:hidden",children:"□"}),ec("pointerModeToggle")&&(0,n.jsx)(o3,{onClick:()=>o5(m),disabled:!e,active:"trackpad"===o,title:"trackpad"===o?H("remoteControls.trackpadMode"):H("remoteControls.directMode"),className:"landscape:hidden",children:(0,n.jsx)("span",{className:"text-base leading-none",children:"\uD83D\uDDB1️"})}),ec("handMode")&&"trackpad"===o&&(0,n.jsx)(o3,{onClick:()=>o5(x),disabled:!e,active:d,title:H("remote.handMode"),className:"landscape:hidden",children:(0,n.jsx)(el.Ud,{size:14})}),ec("keyboardToggle")&&(0,n.jsx)(o3,{onClick:()=>o5(k),disabled:!e,active:b,title:H("remote.toggleKeyboard"),className:"landscape:hidden",children:(0,n.jsx)(el.s3,{size:14})}),ec("textPanel")&&(0,n.jsx)(o3,{onClick:()=>o5(N),disabled:!e,active:g,title:H("remote.textBatchInput"),className:"landscape:hidden",children:"Aa"}),ec("help")&&(0,n.jsx)(o3,{onClick:()=>o5(C),title:H("remote.help"),className:"landscape:hidden",children:(0,n.jsx)(el.mN,{size:14})})]}),(0,n.jsx)(o3,{onClick:()=>{(0,ed.e)(),ee(e=>!e)},active:Q,pinned:!0,className:"landscape:hidden shrink-0",title:H("remote.extraKeys"),children:Q?(0,n.jsx)(el.X,{size:16}):(0,n.jsx)(el.a4,{size:16})})]}),ec("modifierRow")&&(K=ea.keys.filter(e=>e.id!==c.Ic),O=c.ij.find(e=>e.id===c.Ic),W=(0,n.jsx)(o3,{onClick:()=>{(0,ed.e)(),ee(e=>!e)},active:Q,pinned:!0,title:H("remote.extraKeys"),children:Q?(0,n.jsx)(el.X,{size:16}):(0,n.jsx)(el.a4,{size:16})}),_=O?em(O,"pinned",!0):null,(0,n.jsxs)("div",{className:`px-2 py-1 safe-area-bottom ${F?"landscape:px-0":"landscape:py-2"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 landscape:hidden",children:[(0,n.jsx)("div",{className:`${Z} flex-1 min-w-0`,children:K.map((e,t)=>em(e,t))}),_]}),(0,n.jsxs)("div",{className:`${Z} hidden ${F?"landscape:flex":""}`,children:[K.map((e,t)=>em(e,t)),W,_]}),(0,n.jsxs)("div",{className:`hidden ${F?"":"landscape:flex"} landscape:flex-col gap-1`,children:[(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[K.slice(0,5).map((e,t)=>em(e,t)),W]}),(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[K.slice(5).map((e,t)=>em(e,t)),_]})]})]}))]}),(0,n.jsxs)("div",{className:`flex-col gap-1.5 p-1.5 ${L?"hidden landscape:flex":"hidden"}`,children:[(0,n.jsx)(o3,{onClick:()=>{(0,ed.e)(),B?.(!1)},title:H("remote.showControls"),children:(0,n.jsx)(el.kU,{size:16})}),(0,n.jsx)(o3,{onClick:()=>o5(k),disabled:!e,active:b,title:H("remote.toggleKeyboard"),children:(0,n.jsx)(el.s3,{size:16})})]}),(0,n.jsx)(tV,{isOpen:et,onClose:()=>es(!1),title:H("remote.customizeRemoteKeys"),tabs:[{id:"bottom",label:H("remoteControls.bottomRow"),hook:ea,excludeIds:[c.Ic]},{id:"extra",label:H("remoteControls.extraPanel"),hook:ei}]}),(0,n.jsx)(tT,{isOpen:V,store:tN,onSelect:e=>{E(e),q.current?.focus()},onClose:()=>J(!1)})]})}let o6="bg-surface-2 hover:bg-surface-3 text-text",o8="bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text",o9="bg-brand-500 text-white";function o7({onClick:e,title:t,disabled:s,className:r,children:l}){return(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),e()},disabled:s,title:t,className:`shrink-0 w-9 h-9 rounded-brand flex items-center justify-center transition-all duration-150 active:scale-[0.94] ${r} ${s?"disabled:opacity-50":""}`,children:l})}function ce({streaming:e,canvasZoom:t,pointerMode:s,handMode:r,keyboardOn:l,selectionMode:a,show:i,onBack:o,onRefresh:c,onResetZoom:d,onTogglePointerMode:u,onToggleHandMode:x,onToggleKeyboard:m,onShowHelp:p,onToggleSelection:f}){let{t:h}=(0,eu.s)();return(0,n.jsxs)("div",{className:"hidden landscape:flex flex-col items-center gap-1.5 py-2 px-1 bg-bg shrink-0 landscape:w-12 z-20",children:[(0,n.jsx)(o7,{onClick:o,title:h("remote.back"),className:"bg-brand-500/15 hover:bg-brand-500/25 text-brand-400",children:(0,n.jsx)(el.JG,{size:18})}),(0,n.jsx)(o7,{onClick:c,disabled:!e,title:h("remote.refresh"),className:o8,children:(0,n.jsx)(el.e9,{size:16})}),(0,n.jsxs)(o7,{onClick:d,disabled:!e,title:h("remote.resetZoom"),className:`text-[10px] font-semibold ${o6}`,children:[Math.round(100*t),"%"]}),i("pointerModeToggle")&&(0,n.jsx)(o7,{onClick:u,disabled:!e,title:h("trackpad"===s?"remoteControls.trackpadMode":"remoteControls.directMode"),className:`text-base leading-none ${"trackpad"===s?o9:o6}`,children:"\uD83D\uDDB1️"}),i("handMode")&&"trackpad"===s&&(0,n.jsx)(o7,{onClick:x,disabled:!e,title:h("remote.handMode"),className:r?o9:o6,children:(0,n.jsx)(el.Ud,{size:16})}),i("keyboardToggle")&&(0,n.jsx)(o7,{onClick:m,disabled:!e,title:h("remote.toggleKeyboard"),className:l?o9:o8,children:(0,n.jsx)(el.s3,{size:16})}),i("help")&&(0,n.jsx)(o7,{onClick:p,title:h("remote.help"),className:o8,children:(0,n.jsx)(el.mN,{size:16})}),i("rectangleSelect")&&(0,n.jsx)(o7,{onClick:f,disabled:!e,title:h("remote.rectangleSelection"),className:a?o9:o6,children:"□"})]})}function ct({onClose:e,inputMode:t="touch",pointerMode:s="direct"}){let{t:l}=(0,eu.s)();(0,r.useEffect)(()=>{let t=t=>{"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),e?.())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e]);let a="mouse"===t?[{title:l("remoteHelp.mouseTitle"),items:[{key:l("remoteHelp.mouseClickKey"),desc:l("remoteHelp.mouseClickDesc")},{key:l("remoteHelp.mouseRightKey"),desc:l("remoteHelp.mouseRightDesc")},{key:l("remoteHelp.mouseWheelKey"),desc:l("remoteHelp.mouseWheelDesc")},{key:l("remoteHelp.mouseDoubleKey"),desc:l("remoteHelp.mouseDoubleDesc")}]},{title:l("remoteHelp.keyboardTitle"),items:[{key:l("remoteHelp.keyPhysicalKey"),desc:l("remoteHelp.keyPhysicalDesc")},{key:l("remoteHelp.keyModifierKey"),desc:l("remoteHelp.keyModifierDesc")}]}]:"trackpad"===s?[{title:l("remoteHelp.gesturesTrackpadTitle"),items:[{key:l("remoteHelp.trackpadSwipeKey"),desc:l("remoteHelp.trackpadSwipeDesc")},{key:l("remoteHelp.trackpadScrollLockKey"),desc:l("remoteHelp.trackpadScrollLockDesc")},{key:l("remoteHelp.trackpadTapKey"),desc:l("remoteHelp.trackpadTapDesc")},{key:l("remoteHelp.trackpad2TapKey"),desc:l("remoteHelp.trackpad2TapDesc")},{key:l("remoteHelp.trackpad2SwipeKey"),desc:l("remoteHelp.trackpad2SwipeDesc")},{key:l("remoteHelp.trackpadPinchKey"),desc:l("remoteHelp.trackpadPinchDesc")}]},{title:l("remoteHelp.toolbarTitle"),items:[{key:"✋",desc:l("remoteHelp.toolbarHandDesc")},{key:"\uD83D\uDDB1️",desc:l("remoteHelp.toolbarMouseDirectDesc")},{key:"⌨️ / Aa",desc:l("remoteHelp.toolbarKeyboardDesc")}]}]:[{title:l("remoteHelp.gesturesDirectTitle"),items:[{key:l("remoteHelp.directTapKey"),desc:l("remoteHelp.directTapDesc")},{key:l("remoteHelp.directLongKey"),desc:l("remoteHelp.directLongDesc")},{key:l("remoteHelp.directDoubleKey"),desc:l("remoteHelp.directDoubleDesc")},{key:l("remoteHelp.directScrollKey"),desc:l("remoteHelp.directScrollDesc")},{key:l("remoteHelp.directPinchKey"),desc:l("remoteHelp.directPinchDesc")},{key:l("remoteHelp.directPanKey"),desc:l("remoteHelp.directPanDesc")}]},{title:l("remoteHelp.toolbarTitle"),items:[{key:"\uD83D\uDDB1️",desc:l("remoteHelp.toolbarMouseTrackpadDesc")},{key:"⌨️ / Aa",desc:l("remoteHelp.toolbarKeyboardDesc")},{key:"□",desc:l("remoteHelp.toolbarRectDesc")}]}],i=l("mouse"===t?"remoteHelp.modePc":"trackpad"===s?"remoteHelp.modeTrackpad":"remoteHelp.modeDirect");return(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 bg-black/60 flex items-center justify-center p-4",onClick:e,children:(0,n.jsxs)("div",{className:"card-elev max-w-lg w-full max-h-full overflow-y-auto",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border sticky top-0 bg-surface z-10",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h2",{className:"text-text text-base font-semibold",children:l("remote.help")}),(0,n.jsx)("span",{className:"text-brand-400 text-xs font-mono",children:i})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-surface-2 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsx)("div",{className:"p-4 space-y-4",children:a.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-brand-400 text-xs font-semibold uppercase tracking-wider mb-2",children:e.title}),(0,n.jsx)("ul",{className:"space-y-1.5",children:e.items.map(e=>(0,n.jsxs)("li",{className:"flex gap-3 text-sm",children:[(0,n.jsx)("span",{className:"text-text font-mono bg-bg px-2 py-0.5 rounded text-xs shrink-0 min-w-[120px] text-center",children:e.key}),(0,n.jsx)("span",{className:"text-text-muted",children:e.desc})]},e.key))})]},e.title))})]})})}function cs({stats:e,mode:t,onReset:s,onClose:l,onCopy:a,onForceWsDisconnect:i,onToggleWsBlock:o,isWsBlocked:c}){var d,u;let x,{t:m}=(0,eu.s)(),[p,f]=(0,r.useState)(!1);return p?(0,n.jsx)("div",{className:"fixed top-4 right-4 z-50",children:(0,n.jsxs)("button",{onClick:()=>f(!1),className:"bg-surface-2 text-text px-4 py-2 rounded-lg shadow-md hover:bg-surface-3 transition-all duration-150 ease-out active:scale-[0.97]",children:["\uD83D\uDD0D ",m("remote.debug")]})}):(0,n.jsxs)("div",{className:"fixed top-4 right-4 z-50 card-elev p-4 min-w-[280px] text-sm",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3 pb-2 border-b border-border",children:[(0,n.jsxs)("h3",{className:"text-text font-semibold flex items-center gap-2",children:["\uD83D\uDD0D ",m("remote.debugTitle")]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>f(!0),className:"text-text-muted hover:text-text transition-colors",title:m("remote.minimize"),children:"─"}),(0,n.jsx)("button",{onClick:l,className:"text-text-muted hover:text-text transition-colors",title:m("common.close"),children:"✕"})]})]}),(0,n.jsxs)("div",{className:"space-y-2 mb-3",children:[(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"Mode:"}),(0,n.jsx)("span",{className:"rtc"===t?"text-blue-400 font-semibold":"text-yellow-400 font-semibold",children:"rtc"===t?"RTC enabled":"WS only"})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.transport"),":"]}),(0,n.jsx)("span",{className:e.webrtcPercent>50?"text-blue-400 font-semibold":"text-text-muted",children:e.webrtcPercent>50?"WebRTC ✅":"WebSocket"})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.fps"),":"]}),(0,n.jsx)("span",{className:`font-semibold ${(d=e.fps)>=15?"text-green-400":d>=10?"text-yellow-400":"text-red-400"}`,children:e.fps})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.latency"),":"]}),(0,n.jsx)("span",{className:`font-semibold ${(u=e.latency)<50?"text-green-400":u<100?"text-yellow-400":"text-red-400"}`,children:(x=e.latency,`${Math.round(x)}ms`)})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.tilesPerSec"),":"]}),(0,n.jsx)("span",{className:"text-text font-semibold",children:e.tilesPerSec})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[m("remote.bandwidth"),":"]}),(0,n.jsxs)("span",{className:"text-text font-semibold",children:[e.bandwidthMBps," MB/s"]})]})]}),(0,n.jsxs)("div",{className:"border-t border-border pt-3 mb-3 space-y-1",children:[(0,n.jsxs)("div",{className:"flex justify-between items-center text-xs",children:[(0,n.jsx)("span",{className:"text-blue-400",children:"WebRTC:"}),(0,n.jsxs)("span",{className:"text-text-muted",children:[e.webrtcTiles.toLocaleString()," tiles (",e.webrtcPercent,"%)"]})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center text-xs",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"WebSocket:"}),(0,n.jsxs)("span",{className:"text-text-muted",children:[e.wsTiles.toLocaleString()," tiles (",100-e.webrtcPercent,"%)"]})]})]}),(0,n.jsxs)("div",{className:"flex gap-2 border-t border-border pt-3",children:[(0,n.jsx)("button",{onClick:s,className:"flex-1 bg-surface hover:bg-surface-2 text-text py-2 px-3 rounded transition-colors text-xs",children:m("remote.clearStats")}),(0,n.jsx)("button",{onClick:a,className:"flex-1 bg-surface hover:bg-surface-2 text-text py-2 px-3 rounded transition-colors text-xs",children:"Copy"})]}),(i||o)&&(0,n.jsxs)("div",{className:"flex gap-2 mt-2",children:[i&&(0,n.jsx)("button",{onClick:i,className:"flex-1 bg-red-900/40 hover:bg-red-900/60 text-red-300 py-2 px-3 rounded transition-colors text-xs",title:"Disconnect WS once (auto-reconnect)",children:"⚡ Kill WS"}),o&&(0,n.jsx)("button",{onClick:o,className:`flex-1 py-2 px-3 rounded transition-colors text-xs ${c?"bg-yellow-900/60 hover:bg-yellow-900/80 text-yellow-200":"bg-surface hover:bg-surface-2 text-text"}`,title:"Block WS reconnect to test RTC standalone",children:c?"\uD83D\uDD12 WS Blocked":"\uD83D\uDEAB Block WS"})]})]})}function cn({text:e,onClose:t}){let[s,l]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t]);let a=async()=>{try{await navigator.clipboard?.writeText(e),l(!0),setTimeout(()=>l(!1),1500)}catch{}};return(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 bg-black/60 flex items-center justify-center p-4",onClick:t,children:(0,n.jsxs)("div",{className:"card-elev max-w-lg w-full max-h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(el.m0,{size:16,className:"text-brand-400"}),(0,n.jsx)("h2",{className:"text-text text-base font-semibold",children:"Clipboard"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-surface-2 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsx)("div",{className:"p-4 overflow-y-auto flex-1",children:(0,n.jsx)("pre",{className:"text-text text-sm whitespace-pre-wrap break-all bg-bg rounded p-3 font-mono min-h-[120px] max-h-[55dvh] overflow-y-auto scroll-thin",children:e||""})}),(0,n.jsx)("div",{className:"flex justify-end gap-2 p-4 border-t border-border",children:(0,n.jsxs)("button",{onClick:a,disabled:!e,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-brand bg-brand-500 hover:bg-brand-600 disabled:opacity-50 text-white text-sm font-semibold transition-colors",children:[s?(0,n.jsx)(el.aJ,{size:14}):(0,n.jsx)(el.m0,{size:14}),"Copy"]})})]})})}function cr({onClose:e,busRef:t,protocolRef:s,connected:l,carrier:a,hostPlatform:i}){let{t:o}=(0,eu.s)(),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),[f,h]=(0,r.useState)(!1),[b,g]=tW("remoteDesktop.showTextPanel",!0),[v,y]=tW("remoteDesktop.keyboard",!1),[w,j]=tW("remoteDesktop.controlsHidden",!1),[k,N]=tW("remoteDesktop.pointerMode",c.eR.pointerMode),[C,S]=tW("remoteDesktop.handMode",!1),T=tO(),R=c.eR.pcModeControls,[E,$]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=window.matchMedia("(orientation: landscape)"),t=()=>$(e.matches);return t(),e.addEventListener?.("change",t),()=>e.removeEventListener?.("change",t)},[]);let z=E&&Math.min(window.screen.width,window.screen.height)>=700;(0,r.useEffect)(()=>{"mouse"===T&&"direct"!==k&&N("direct")},[T,k,N]);let{stats:M,trackTilesReceived:P,resetStats:A}=function(){let[e,t]=(0,r.useState)(oQ),s=(0,r.useRef)({frameCount:0,lastFpsTime:Date.now(),tilesReceived:0,lastTilesTime:Date.now(),bytesReceived:0,lastBandwidthTime:Date.now(),latencies:[],webrtcTilesTotal:0,wsTilesTotal:0});return{stats:e,trackTilesReceived:(0,r.useCallback)((e,n)=>{let r=s.current,l=Date.now();r.frameCount++;let a=e.tiles?.length||0;r.tilesReceived+=a;let i="number"==typeof e.bytes?e.bytes:e.tiles?.reduce((e,t)=>e+(t.imageBuffer?.byteLength||t.imageBuffer?.length||0),0)||0;if(r.bytesReceived+=i,e.timestamp){let t=Date.now()-e.timestamp;r.latencies.push({value:t,time:l}),r.latencies=r.latencies.filter(e=>l-e.time<6e4)}if(n?.startsWith("dc")||"webrtc"===n?r.webrtcTilesTotal+=a:r.wsTilesTotal+=a,l-r.lastFpsTime>=500){let e=(l-r.lastFpsTime)/1e3,s=Math.round(r.frameCount/e),n=r.latencies.length>0?Math.round(r.latencies.reduce((e,t)=>e+t.value,0)/r.latencies.length):0,a=Math.round(r.tilesReceived/e),i=(r.bytesReceived/e/1024/1024).toFixed(2),o=r.webrtcTilesTotal+r.wsTilesTotal,c=o>0?Math.round(r.webrtcTilesTotal/o*100):0;t({fps:s,latency:n,tilesPerSec:a,bandwidthMBps:parseFloat(i),webrtcTiles:r.webrtcTilesTotal,wsTiles:r.wsTilesTotal,webrtcPercent:c}),r.frameCount=0,r.tilesReceived=0,r.bytesReceived=0,r.lastFpsTime=l}},[]),resetStats:(0,r.useCallback)(()=>{let e=s.current;e.frameCount=0,e.lastFpsTime=Date.now(),e.tilesReceived=0,e.lastTilesTime=Date.now(),e.bytesReceived=0,e.lastBandwidthTime=Date.now(),e.latencies=[],e.webrtcTilesTotal=0,e.wsTilesTotal=0,t(oQ)},[])}}(),[I,D]=(0,r.useState)(c.eR.debug?.panel??!1),[L,B]=(0,r.useState)(!1),F=c.eR.enableWebRTC?"rtc":"ws",K=(0,r.useCallback)(()=>{let e={mode:F,...M,ts:new Date().toISOString()};navigator.clipboard?.writeText(JSON.stringify(e,null,2)).catch(()=>{})},[M,F]),O=(0,r.useRef)(M);(0,r.useEffect)(()=>{O.current=M},[M]),(0,r.useEffect)(()=>{(0,d.c)("remote",`[stats] interval started, mode=${F}`);let e=setInterval(()=>{(0,d.c)("remote",`[stats][${F}]`,JSON.stringify(O.current))},5e3);return()=>{(0,d.c)("remote","[stats] interval stopped"),clearInterval(e)}},[F]);let{streaming:W,emitRequestScreenWithHashes:_,emitMousePress:H,emitMouseRelease:U,emitMouseClick:q,emitMouseMove:X,emitMouseDragSelect:V,emitKeyPress:J,emitTypeText:G,emitScroll:Y,emitBoostStream:Z,emitSetFocus:Q,emitDesktopSwitch:ee}=function(e,t){let[s,n]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(t&&e?.current)return n(!0),()=>n(!1)},[t,e]);let l=(0,r.useCallback)((t,s)=>{e?.current?.emit(t,s)},[e]),a=(0,r.useCallback)((e,t,n="left")=>{s&&l("mouse-press",{x:e,y:t,button:n})},[l,s]),i=(0,r.useCallback)((e,t,n="left")=>{s&&l("mouse-release",{x:e,y:t,button:n})},[l,s]),o=(0,r.useCallback)((e,t,n="left",r=!1)=>{s&&l("mouse-click",{x:e,y:t,button:n,double:r})},[l,s]),c=(0,r.useCallback)((e,t)=>{s&&l("mouse-move",{x:e,y:t})},[l,s]),d=(0,r.useCallback)((e,t,n,r)=>{s&&l("mouse-drag-select",{startX:e,startY:t,endX:n,endY:r})},[l,s]),u=(0,r.useCallback)((e,t=[])=>{s&&l("key-press",{key:e,modifier:t})},[l,s]),x=(0,r.useCallback)(e=>{s&&l("type-text",{text:e})},[l,s]),m=(0,r.useCallback)((e,t=20,n=!1)=>{s&&l("scroll",{direction:e,amount:t,horizontal:n})},[l,s]),p=(0,r.useCallback)(()=>{s&&l("boost-stream")},[l,s]),f=(0,r.useCallback)((e,t=1)=>{s&&l("set-focus",{rect:e,zoom:t,viewerWidth:window.innerWidth,dpr:window.devicePixelRatio||1})},[l,s]),h=(0,r.useCallback)(e=>{s&&l("request-screen-with-hashes",{tileHashes:e})},[l,s]),b=(0,r.useCallback)(e=>{s&&l("desktop-switch",{direction:e})},[l,s]);return{streaming:s,emitRequestScreenWithHashes:h,emitMousePress:a,emitMouseRelease:i,emitMouseClick:o,emitMouseMove:c,emitMouseDragSelect:d,emitKeyPress:u,emitTypeText:x,emitScroll:m,emitBoostStream:p,emitSetFocus:f,emitDesktopSwitch:b}}(t,l),et={emitRequestScreenWithHashes:_,emitMousePress:H,emitMouseRelease:U,emitMouseClick:q,emitMouseMove:X,emitMouseDragSelect:V,emitKeyPress:J,emitTypeText:G,emitScroll:Y,emitBoostStream:Z},es=(0,r.useCallback)(()=>{p(!0)},[]);(0,r.useEffect)(()=>{a&&(0,d.c)("remote",`[remote] carrier: ${a}`)},[a]);let{canvasRef:en,canvasContainerRef:er,canvasZoom:el,canvasPan:ea,fitScale:ei,baseCanvasSize:eo,zoomGestureTimeoutRef:ex,clickIndicator:em,virtualCursor:ep,handHolding:ef,scrollLock:eh,getCanvasCoordinates:eb,resetZoom:eg,resetPan:ev,panForKeyboard:ey,centerVirtualCursor:ew,startHandHold:ej,releaseHandHold:ek,handleCanvasInteraction:eN,handleCanvasDimensions:eC,serverDimensionsRef:eS}=function(e){let t=function(){let e=(0,r.useRef)(null),t=(0,r.useRef)(null),[s,n]=(0,r.useState)(1),[l,a]=(0,r.useState)({x:0,y:0}),[i,o]=(0,r.useState)(1),[d,u]=(0,r.useState)({width:0,height:0}),x=(0,r.useRef)({width:0,height:0}),m=(0,r.useRef)({x:0,y:0}),p=i*s,f=(0,r.useCallback)(()=>{let e=t.current;return e?{width:e.clientWidth,height:e.clientHeight}:null},[]),h=(0,r.useCallback)(e=>({width:d.width*e,height:d.height*e}),[d]),b=(0,r.useCallback)((n,r)=>{let a=e.current,o=t.current;return a&&o&&0!==a.width?function({canvasPoint:e,canvasWidth:t,canvasHeight:s}){return{percentX:oF(e.x/t*100,0,100),percentY:oF(e.y/s*100,0,100)}}({canvasPoint:oK({clientX:n,clientY:r,containerRect:o.getBoundingClientRect(),pan:l,totalScale:i*s}),canvasWidth:a.width,canvasHeight:a.height}):{percentX:0,percentY:0}},[l,s,i]),g=(0,r.useCallback)((e,t)=>{let n=i*s;n<=0||(m.current={x:(e-l.x)/n,y:(t-l.y)/n})},[i,s,l]),v=(0,r.useCallback)(()=>{n(1),a({x:0,y:0})},[]),y=(0,r.useCallback)(()=>a({x:0,y:0}),[]),w=(0,r.useCallback)((e,t)=>{let n=f();if(!n)return;let r=i*s;if(r<=0)return;let l=t||m.current,o=oO(n,h(s));a(t=>{if(!e||s<=1)return oW(t,o);let{y:a}=function({focus:e,containerHeight:t,totalScale:s}){return{y:t/3-e.y*s}}({focus:l,containerHeight:n.height,totalScale:r});return oW({x:t.x,y:a},o)})},[f,h,i,s]),j=(0,r.useCallback)(()=>{let s,n=t.current,r=e.current,l=x.current;if(!n||!r||0===l.width||0===l.height)return;let a=(s={width:n.clientWidth,height:n.clientHeight},Math.min(s.width/l.width,s.height/l.height));o(a),u({width:l.width*a,height:l.height*a})},[]);(0,r.useEffect)(()=>{let e=null,s=null,n=()=>{let e=t.current;if(!e)return void j();let n=e.clientWidth,r=e.clientHeight,l=0,a=0,i=()=>{let t=e.clientWidth,o=e.clientHeight;if(t===n&&o===r){if(++l>=c.eR.resizeStableFrames){s=null,j();return}}else l=0,n=t,r=o;if(a++>=c.eR.resizeMaxFrames){s=null,j();return}s=requestAnimationFrame(i)};s=requestAnimationFrame(i)},r=()=>{e&&clearTimeout(e),s&&(cancelAnimationFrame(s),s=null),e=setTimeout(n,c.eR.resizeDebounceMs)};return window.addEventListener("resize",r),window.addEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.addEventListener("resize",r),()=>{e&&clearTimeout(e),s&&cancelAnimationFrame(s),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.removeEventListener("resize",r)}},[j]),(0,r.useEffect)(()=>{a(e=>{let n=t.current;if(!n)return e;let r=oW(e,oO({width:n.clientWidth,height:n.clientHeight},{width:d.width*s,height:d.height*s}));return r.x===e.x&&r.y===e.y?e:r})},[d,s]);let k=(0,r.useCallback)((s,n)=>{x.current={width:s.width,height:s.height};let r=e.current,l=t.current;if(!r||!l)return!1;let a=r.width!==s.width||r.height!==s.height;r.width=s.width,r.height=s.height;let i=r.getContext("2d");return i.imageSmoothingEnabled=!1,a&&(i.clearRect(0,0,r.width,r.height),i.fillStyle="#2a2a2a",i.fillRect(0,0,r.width,r.height),n?.current&&n.current.clear()),j(),a},[j]);return{canvasRef:e,canvasContainerRef:t,canvasZoom:s,setCanvasZoom:n,canvasPan:l,setCanvasPan:a,fitScale:i,totalScale:p,baseCanvasSize:d,serverDimensionsRef:x,containerSize:f,displaySizeAt:h,getCanvasCoordinates:b,recordInteractPx:g,resetZoom:v,resetPan:y,panForKeyboard:w,handleCanvasDimensions:k}}(),{canvasRef:s,canvasContainerRef:n,canvasZoom:l,setCanvasZoom:a,canvasPan:i,setCanvasPan:o,fitScale:d,baseCanvasSize:u,containerSize:x,displaySizeAt:m,getCanvasCoordinates:p,recordInteractPx:f}=t,[h,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(0),w=(0,r.useRef)({x:0,y:0}),[j,k]=(0,r.useState)(!1),N=(0,r.useRef)(null),[C,S]=(0,r.useState)(null),T=(0,r.useRef)(null),R=(0,r.useRef)(!1),E=(0,r.useRef)({x:0,y:0}),$=(0,r.useRef)(0),z=(0,r.useRef)({x:0,y:0}),[M,P]=(0,r.useState)(!1),A=(0,r.useRef)({x:0,y:0}),I=(0,r.useRef)({x:0,y:0}),D=(0,r.useRef)(0),L=(0,r.useRef)(null),[B,F]=(0,r.useState)({x:0,y:0}),K=(0,r.useRef)(0),O=(0,r.useRef)(0),W=(0,r.useRef)(null),_=(0,r.useRef)({time:0,distance:0,centerX:0,centerY:0}),H=(0,r.useRef)(!1),U=(0,r.useRef)(0),q=(0,r.useRef)(!1),X=(0,r.useRef)(null),V=(0,r.useRef)(!1),[J,G]=(0,r.useState)(!1),Y=(0,r.useRef)(null),Z=(0,r.useRef)(!1),[Q,ee]=(0,r.useState)(!1),et=(0,r.useRef)(null),es=(0,r.useRef)({x:0,y:0}),en=(0,r.useRef)(!1),er=(0,r.useRef)(null),el=(0,r.useRef)(0),ea=(0,r.useCallback)((e,t)=>{let s=n.current;if(!s)return;let r=s.getBoundingClientRect(),a=e-r.left,i=t-r.top,o=oF(7.5*l,5,15);f(a,i),S({x:a,y:i,size:o}),setTimeout(()=>S(null),500)},[l,n,f]),ei=(0,r.useCallback)(()=>{T.current&&(clearTimeout(T.current),T.current=null)},[]),eo=(0,r.useCallback)((t,s,n,r)=>{ei(),R.current=!1,E.current={x:t,y:s},T.current=setTimeout(()=>{R.current=!0,ea(t,s),e?.emitMouseClick(n,r,"right")},c.eR.longPressDelay)},[ei,ea,e]),ec=(0,r.useCallback)((e,t)=>{let s=Date.now(),n=function({now:e,lastTime:t,lastPos:s,x:n,y:r,cfg:l}){let a=Math.abs(n-s.x),i=Math.abs(r-s.y);return e-t<l.doubleClickDelay&&a<l.moveThreshold&&i<l.moveThreshold}({now:s,lastTime:$.current,lastPos:z.current,x:e,y:t,cfg:c.eR});return $.current=s,z.current={x:e,y:t},n},[]),eu=(0,r.useCallback)(()=>{L.current&&(cancelAnimationFrame(L.current),L.current=null),I.current={x:0,y:0},A.current={x:0,y:0},P(!1)},[]),ex=(0,r.useCallback)(()=>{let t=()=>{var s,n;let r=(s=I.current,n=c.eR,Math.abs(s.y)<n.momentumMinVelocity?null:{scrollY:Math.round(s.y*n.edgeScrollMultiplier),nextVelocity:{x:s.x*n.momentumFriction,y:s.y*n.momentumFriction}});if(!r)return eu();Math.abs(r.scrollY)>=1&&e?.emitScroll(r.scrollY>0?"up":"down",Math.abs(r.scrollY),!1),I.current=r.nextVelocity,L.current=requestAnimationFrame(t)};L.current=requestAnimationFrame(t)},[e,eu]);(0,r.useEffect)(()=>()=>{ei(),eu()},[ei,eu]);let em=(0,r.useCallback)(t=>{let{edgeScrollThreshold:s,edgeScrollMultiplier:n}=c.eR,r=oH({accum:A.current.y,delta:t,threshold:s,multiplier:n});A.current.y=r.accum,r.scroll&&e?.emitScroll(r.scroll>0?"up":"down",Math.abs(r.scroll),!1)},[e]),ep=(0,r.useCallback)(t=>{let{edgeScrollThreshold:s,edgeScrollMultiplier:n}=c.eR,r=oH({accum:A.current.x,delta:t,threshold:s,multiplier:n});A.current.x=r.accum,r.scroll&&e?.emitScroll(r.scroll>0?"right":"left",Math.abs(r.scroll),!0)},[e]),ef=(0,r.useCallback)((e,t)=>({percentX:oF(e.x/t.width*100,0,100),percentY:oF(e.y/t.height*100,0,100)}),[]),eh=(0,r.useCallback)(t=>{let n=s.current;if(!n||0===n.width)return;let{percentX:r,percentY:l}=ef(t,n);e?.emitMouseMove?.(r,l)},[e,s,ef]);(0,r.useEffect)(()=>{let t=t=>{if(null==et.current||t.pointerType&&"mouse"!==t.pointerType)return;let r=s.current,l=n.current;if(!r||!l)return;let{percentX:a,percentY:i}=p(t.clientX,t.clientY),o=et.current;et.current=null,e?.emitMouseRelease?.(a,i,o)};return window.addEventListener("pointerup",t),window.addEventListener("pointercancel",t),()=>{window.removeEventListener("pointerup",t),window.removeEventListener("pointercancel",t)}},[p,e,s,n]);let eb=(0,r.useCallback)((t,r,u)=>{let{streaming:f,pointerMode:C="direct"}=u;if(!f||!e)return;let S={canvasRef:s,canvasContainerRef:n,containerSize:x,displaySizeAt:m,getCanvasCoordinates:p,socketEmitFunctions:e,canvasZoom:l,fitScale:d,virtualCursor:B,canvasPan:i,setCanvasZoom:a,setCanvasPan:o,setVirtualCursor:F,isZooming:h,isPanning:g,isEdgeScrolling:M,recentZoomGesture:j,lastTouchDistanceRef:y,lastTouchCenterRef:w,setIsZooming:b,setIsPanning:v,setIsEdgeScrolling:P,setRecentZoomGesture:k,gestureLockRef:W,gestureStartRef:_,multiTouchLatchRef:H,twoFingerMaxMovedRef:U,touchOutsideRef:q,longPressTriggeredRef:R,touchStartPosRef:E,edgeScrollAccumRef:A,velocityRef:I,lastTouchTimeRef:D,touchStartTimeRef:K,touchTotalMoveRef:O,handLongPressTimerRef:X,handHoldingRef:V,setHandHolding:G,scrollLongPressTimerRef:Y,scrollLockRef:Z,setScrollLock:ee,mouseDownButtonRef:et,wheelAccumRef:es,wheelActiveRef:en,wheelEndTimerRef:er,wheelLastBoostRef:el,zoomGestureTimeoutRef:N,showClickIndicator:ea,cancelLongPress:ei,startLongPress:eo,checkDoubleClick:ec,stopMomentum:eu,startMomentumScroll:ex,emitScrollFromDelta:em,emitHScrollFromDelta:ep,cursorPercent:ef,emitVirtualCursor:eh};if(t.nativeEvent?.pointerType==="mouse"||"wheel"===t.type||"contextmenu"===t.type||"dblclick"===t.type)return("wheel"===t.type||"contextmenu"===t.type)&&t.preventDefault(),function(e,t,s,n){let{socketEmitFunctions:r,getCanvasCoordinates:l,showClickIndicator:a}=e,{streaming:i,selectionMode:o,handleSelection:d}=n;if(!i||!r)return;let u=c.eR.mouseButtonMap[t.button]||"left";if("wheel"===s){var x,m;let{percentX:s,percentY:n}=l(t.clientX,t.clientY),a=(x=t.deltaMode,m=c.eR,1===x?m.wheelLineHeight:2===x?m.wheelPageHeight:1),i=t.deltaY*a,o=t.deltaX*a;if(t.ctrlKey||t.metaKey){let s=e.canvasContainerRef.current,n=e.canvasRef.current;if(!s||!n)return;let r=s.getBoundingClientRect(),l={x:t.clientX-r.left,y:t.clientY-r.top},a={width:s.clientWidth,height:s.clientHeight},o=i>0?-1:1;e.setCanvasZoom(t=>{let s=oF(t+o*c.eR.wheelZoomStep,1,4);return s===t?t:(e.setCanvasPan(n=>o_({prevZoom:t,prevPan:n,focal:l,nextZoomRaw:s,maxZoom:4,containerSize:a,displaySizeAt:e.displaySizeAt}).pan),s)});return}if(e.wheelActiveRef.current){let t=Date.now();t-e.wheelLastBoostRef.current>=c.eR.wheelBoostInterval&&(r.emitBoostStream?.(),e.wheelLastBoostRef.current=t)}else r.emitBoostStream?.(),r.emitMouseMove?.(s,n),e.wheelActiveRef.current=!0,e.wheelLastBoostRef.current=Date.now();e.wheelEndTimerRef.current&&clearTimeout(e.wheelEndTimerRef.current),e.wheelEndTimerRef.current=setTimeout(()=>{e.wheelActiveRef.current=!1,e.wheelAccumRef.current.x=0},150);let d=c.eR.wheelScrollMultiplier;if(i&&e.emitScrollFromDelta(-i*d),o){let{edgeScrollThreshold:t,edgeScrollMultiplier:s}=c.eR,n=oH({accum:e.wheelAccumRef.current.x,delta:o*d,threshold:t,multiplier:s});e.wheelAccumRef.current.x=n.accum,n.scroll&&r.emitScroll?.(n.scroll>0?"right":"left",Math.abs(n.scroll),!0)}return}if("contextmenu"===s){let{percentX:e,percentY:s}=l(t.clientX,t.clientY);a(t.clientX,t.clientY),r.emitMouseClick?.(e,s,"right");return}if("dblclick"===s)return;if(o){"pointerdown"===s?d?.(t.clientX,t.clientY,"start"):"pointermove"===s&&null!=e.mouseDownButtonRef.current?d?.(t.clientX,t.clientY,"move"):"pointerup"===s&&(d?.(t.clientX,t.clientY,"end"),e.mouseDownButtonRef.current=null),"pointerdown"===s&&(e.mouseDownButtonRef.current=u);return}let{percentX:p,percentY:f}=l(t.clientX,t.clientY);if("pointerdown"===s){e.mouseDownButtonRef.current=u,a(t.clientX,t.clientY),r.emitMousePress?.(p,f,u);return}if("pointermove"===s){null!=e.mouseDownButtonRef.current&&r.emitMouseMove?.(p,f);return}if("pointerup"===s){let t=e.mouseDownButtonRef.current||u;e.mouseDownButtonRef.current=null,r.emitMouseRelease?.(p,f,t)}}(S,t,r,u);t.preventDefault(),t.type.startsWith("touch")&&t.touches?.length>=2&&(H.current=!0,Y.current&&(clearTimeout(Y.current),Y.current=null),Z.current&&(Z.current=!1,ee(!1),A.current={x:0,y:0}),X.current&&(clearTimeout(X.current),X.current=null)),"trackpad"===C&&t.type.startsWith("touch")&&function(e,t,s,n){let r=e.canvasRef.current;if(!r||0===r.width)return!0;let{selectionMode:l,dragMode:a,isDragging:i,setIsDragging:o,setDragMode:d,handleSelection:u,handMode:x=!1,onHandRelease:m}=n;if(t.touches?.length>=2||!(!e.multiTouchLatchRef.current&&(t.touches?.length===1||"touchend"===s)))return!1;let p=t.touches?.[0]||t.changedTouches?.[0];if(!p)return!0;if("touch"===s){if(e.touchStartTimeRef.current=Date.now(),e.touchTotalMoveRef.current=0,e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=Date.now(),l){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);return u?.(0,0,"start",{...n,percentOverride:{percentX:t,percentY:s}}),!0}return x&&!e.handHoldingRef.current&&(e.handLongPressTimerRef.current&&clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=setTimeout(()=>{e.handLongPressTimerRef.current=null;let t=e.canvasRef.current;if(!t||0===t.width)return;let{percentX:s,percentY:n}=e.cursorPercent(e.virtualCursor,t);e.handHoldingRef.current=!0,e.setHandHolding(!0),(0,ed.e)(15),e.socketEmitFunctions.emitMousePress?.(s,n,"left")},c.eR.longPressDelay)),x||e.scrollLockRef.current||(e.scrollLongPressTimerRef.current&&clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=setTimeout(()=>{e.scrollLongPressTimerRef.current=null,e.scrollLockRef.current=!0,e.setScrollLock(!0),e.edgeScrollAccumRef.current={x:0,y:0},(0,ed.e)(15)},c.eR.longPressDelay)),!0}if("touchmove"===s){let t=p.clientX-e.lastTouchCenterRef.current.x,s=p.clientY-e.lastTouchCenterRef.current.y;if(e.touchTotalMoveRef.current+=Math.abs(t)+Math.abs(s),e.scrollLockRef.current)return e.emitScrollFromDelta(s),e.emitHScrollFromDelta(t),e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=Date.now(),!0;e.scrollLongPressTimerRef.current&&e.touchTotalMoveRef.current>c.eR.trackpadTapMaxMove&&(clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=null);let a=Date.now(),i=function({deltaX:e,deltaY:t,dt:s,cfg:n}){let r=Math.sqrt(e*e+t*t)/s,l=1+Math.min(n.trackpadAcceleration,r*n.trackpadAcceleration);return n.trackpadSensitivity*l}({deltaX:t,deltaY:s,dt:Math.max(1,a-e.lastTouchTimeRef.current),cfg:c.eR}),o=Math.max(1e-4,e.fitScale*e.canvasZoom),d=t*i/o,m=s*i/o;return l?e.setVirtualCursor(t=>{let s={x:oF(t.x+d,0,r.width-1),y:oF(t.y+m,0,r.height-1)},{percentX:l,percentY:a}=e.cursorPercent(s,r);return e.emitVirtualCursor(s),u?.(0,0,"move",{...n,percentOverride:{percentX:l,percentY:a}}),s}):(x&&!e.handHoldingRef.current&&e.handLongPressTimerRef.current&&e.touchTotalMoveRef.current>c.eR.trackpadTapMaxMove&&(clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=null),e.setVirtualCursor(t=>{let s={x:oF(t.x+d,0,r.width-1),y:oF(t.y+m,0,r.height-1)};if(e.emitVirtualCursor(s),e.handHoldingRef.current){let{percentX:t,percentY:n}=e.cursorPercent(s,r);e.socketEmitFunctions.emitMouseMove?.(t,n)}let n=e.containerSize();if(n&&e.canvasZoom>1){let t={width:r.width*o,height:r.height*o},l=oO(n,t);e.setCanvasPan(e=>{let r=function({cursor:e,pan:t,containerSize:s,displaySize:n,totalScale:r,marginRatio:l}){let a=s.width*l,i=s.height*l,o=e.x*r+t.x,c=e.y*r+t.y,d={x:0,y:0};return o<a?d.x=a-o:o>s.width-a&&(d.x=-(o-(s.width-a))),c<i?d.y=i-c:c>s.height-i&&(d.y=-(c-(s.height-i))),d}({cursor:s,pan:e,containerSize:n,displaySize:t,totalScale:o,marginRatio:c.eR.trackpadEdgeMarginRatio});return oW({x:e.x+r.x,y:e.y+r.y},l)})}return s})),e.lastTouchCenterRef.current={x:p.clientX,y:p.clientY},e.lastTouchTimeRef.current=a,!0}if("touchend"===s){if(l){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);return u?.(0,0,"end",{...n,percentOverride:{percentX:t,percentY:s}}),!0}if(x){if(e.handLongPressTimerRef.current&&(clearTimeout(e.handLongPressTimerRef.current),e.handLongPressTimerRef.current=null),e.handHoldingRef.current){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r);e.socketEmitFunctions.emitMouseRelease?.(t,s,"left"),e.handHoldingRef.current=!1,e.setHandHolding(!1),m?.()}return!0}if(e.scrollLongPressTimerRef.current&&(clearTimeout(e.scrollLongPressTimerRef.current),e.scrollLongPressTimerRef.current=null),e.scrollLockRef.current)return e.scrollLockRef.current=!1,e.setScrollLock(!1),e.edgeScrollAccumRef.current={x:0,y:0},!0;let t=Date.now()-e.touchStartTimeRef.current;if(e.touchTotalMoveRef.current<=c.eR.trackpadTapMaxMove&&t<=c.eR.trackpadTapMaxDuration){let{percentX:t,percentY:s}=e.cursorPercent(e.virtualCursor,r),n=e.checkDoubleClick(e.virtualCursor.x,e.virtualCursor.y);a?i?(o(!1),d(!1),e.socketEmitFunctions.emitMouseRelease(t,s,"left")):(o(!0),e.socketEmitFunctions.emitMousePress(t,s,"left")):e.socketEmitFunctions.emitMouseClick(t,s,"left",n)}return!0}return!1}(S,t,r,u)||function(e,t,s,n){let r,l,{selectionMode:a,selectionStart:i,dragMode:o,isDragging:d,setIsDragging:u,setDragMode:x,isMobile:m,handleSelection:p,pointerMode:f="direct"}=n;if(t.type.startsWith("touch")&&t.touches?.length>=2&&!a){var h;let n,r,l,a=(n=(h=t.touches)[0].clientX-h[1].clientX,Math.sqrt(n*n+(r=h[0].clientY-h[1].clientY)*r)),i={x:((l=t.touches)[0].clientX+l[1].clientX)/2,y:(l[0].clientY+l[1].clientY)/2};if("touch"===s){e.setIsZooming(!0),e.lastTouchDistanceRef.current=a,e.lastTouchCenterRef.current=i,e.gestureLockRef.current=null,e.gestureStartRef.current={time:Date.now(),distance:a,centerX:i.x,centerY:i.y},e.twoFingerMaxMovedRef.current=0;return}if("touchmove"===s&&e.isZooming){let t=e.canvasContainerRef.current;if(!t)return;if(null===e.gestureLockRef.current){let t=Date.now()-e.gestureStartRef.current.time,s=Math.abs(a-e.gestureStartRef.current.distance),n=Math.sqrt((i.x-e.gestureStartRef.current.centerX)**2+(i.y-e.gestureStartRef.current.centerY)**2);e.twoFingerMaxMovedRef.current=Math.max(e.twoFingerMaxMovedRef.current,s,n),e.gestureLockRef.current=function({elapsed:e,deltaDistance:t,deltaCentroid:s,cfg:n}){let r=t>=n.gestureDistanceThreshold,l=s>=n.gestureCentroidThreshold;if(!r&&!l&&e<n.gestureLockDelay)return null;let a=s>.5?t/s:1/0;return a>=n.gestureDominanceRatio&&r?"zoom":a<=1/n.gestureDominanceRatio&&l?"scroll":r&&!l?"zoom":l&&!r?"scroll":null}({elapsed:t,deltaDistance:s,deltaCentroid:n,cfg:c.eR})}if("scroll"===e.gestureLockRef.current){let t=i.y-e.lastTouchCenterRef.current.y;if(!e.isEdgeScrolling){let t=e.canvasRef.current,s="trackpad"===f&&t&&t.width>0?e.cursorPercent(e.virtualCursor,t):e.getCanvasCoordinates(i.x,i.y);e.socketEmitFunctions?.emitBoostStream?.(),e.socketEmitFunctions?.emitMouseMove?.(s.percentX,s.percentY),e.setIsEdgeScrolling(!0)}e.emitScrollFromDelta(t),e.lastTouchDistanceRef.current=a,e.lastTouchCenterRef.current=i;return}if("zoom"===e.gestureLockRef.current&&e.lastTouchDistanceRef.current>0){let s=t.getBoundingClientRect(),n={width:t.clientWidth,height:t.clientHeight},r={x:i.x-s.left,y:i.y-s.top},l=e.canvasZoom*(a/e.lastTouchDistanceRef.current);e.setCanvasPan(t=>o_({prevZoom:e.canvasZoom,prevPan:t,focal:r,nextZoomRaw:l,maxZoom:4,containerSize:n,displaySizeAt:e.displaySizeAt}).pan),e.setCanvasZoom(oF(l,1,4)),e.lastTouchDistanceRef.current=a}e.lastTouchCenterRef.current=i;return}}if(t.type.startsWith("touch")&&t.touches?.length===1){let n=t.touches[0];if(e.isZooming){e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY};return}if("touch"===s){if(e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY},e.lastTouchTimeRef.current=Date.now(),e.velocityRef.current={x:0,y:0},e.edgeScrollAccumRef.current={x:0,y:0},e.stopMomentum(),e.touchOutsideRef.current=!function(e,t,s){let n=e.canvasRef.current,r=e.canvasContainerRef.current;if(!n||!r||0===n.width)return!1;let l=oK({clientX:t,clientY:s,containerRect:r.getBoundingClientRect(),pan:e.canvasPan,totalScale:e.fitScale*e.canvasZoom});return l.x>=0&&l.x<=n.width&&l.y>=0&&l.y<=n.height}(e,n.clientX,n.clientY),a)p(n.clientX,n.clientY,"start");else if(!o&&!e.touchOutsideRef.current){let{percentX:t,percentY:s}=e.getCanvasCoordinates(n.clientX,n.clientY);e.startLongPress(n.clientX,n.clientY,t,s)}return}if("touchmove"===s){let t=Math.abs(n.clientX-e.touchStartPosRef.current.x),s=Math.abs(n.clientY-e.touchStartPosRef.current.y);if((t>c.eR.moveThreshold||s>c.eR.moveThreshold)&&e.cancelLongPress(),a&&i)return p(n.clientX,n.clientY,"move");if(!a&&!o){let t=n.clientX-e.lastTouchCenterRef.current.x,s=n.clientY-e.lastTouchCenterRef.current.y,r=Date.now(),l=r-e.lastTouchTimeRef.current;if(l>0&&(e.velocityRef.current={x:t/l*16,y:s/l*16},e.lastTouchTimeRef.current=r),Math.abs(t)>5||Math.abs(s)>5){e.cancelLongPress();let r=e.getCanvasCoordinates(n.clientX,n.clientY),l=Math.abs(s)>1.5*Math.abs(t),a=t=>{l&&(e.isEdgeScrolling||(e.socketEmitFunctions?.emitBoostStream?.(),e.socketEmitFunctions?.emitMouseMove?.(r.percentX,r.percentY),e.setIsEdgeScrolling(!0)),e.emitScrollFromDelta(t))};if(1===e.canvasZoom){l&&a(s),e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY};return}e.setIsPanning(!0);let i=e.containerSize()||{width:0,height:0},o=e.displaySizeAt(e.canvasZoom);e.setCanvasPan(n=>{let r=function({prevPan:e,deltaX:t,deltaY:s,containerSize:n,displaySize:r}){let l=oO(n,r),a=oW({x:e.x+t,y:e.y+s},l),i=Math.abs(a.y-e.y)>.5?0:e.y+s-a.y;return{pan:a,overflowY:i}}({prevPan:n,deltaX:t,deltaY:s,containerSize:i,displaySize:o});return Math.abs(r.overflowY)>0?a(r.overflowY):(e.edgeScrollAccumRef.current.y=0,e.setIsEdgeScrolling(!1)),r.pan}),e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY}}return}}}if("touchend"===s){if(e.cancelLongPress(),"trackpad"===f&&e.isZooming&&0===(t.touches?.length||0)&&null===e.gestureLockRef.current&&Date.now()-e.gestureStartRef.current.time<=c.eR.trackpadTapMaxDuration&&e.twoFingerMaxMovedRef.current<=c.eR.trackpadTapMaxMove){let t=e.canvasRef.current;if(t&&t.width>0&&e.socketEmitFunctions?.emitMouseClick){let{percentX:s,percentY:n}=e.cursorPercent(e.virtualCursor,t);e.socketEmitFunctions.emitMouseClick(s,n,"right"),(0,ed.e)(15)}}e.gestureLockRef.current=null,0===(t.touches?.length||0)&&(e.multiTouchLatchRef.current=!1);let s=e.isZooming,n=e.isPanning,r=e.isEdgeScrolling,l=e.longPressTriggeredRef.current;if(e.longPressTriggeredRef.current=!1,s&&(e.setRecentZoomGesture(!0),e.zoomGestureTimeoutRef.current&&clearTimeout(e.zoomGestureTimeoutRef.current),e.zoomGestureTimeoutRef.current=setTimeout(()=>e.setRecentZoomGesture(!1),200)),r&&(Math.abs(e.velocityRef.current.x)>c.eR.momentumMinVelocity||Math.abs(e.velocityRef.current.y)>c.eR.momentumMinVelocity)?e.startMomentumScroll():e.stopMomentum(),e.setIsZooming(!1),e.setIsPanning(!1),s||n||r||e.recentZoomGesture||l)return;if(t.type.startsWith("touch")){let s=t.changedTouches?.[0];if(s){if(a)p(s.clientX,s.clientY,"end");else if(!e.touchOutsideRef.current){let{percentX:t,percentY:n}=e.getCanvasCoordinates(s.clientX,s.clientY);if(e.showClickIndicator(s.clientX,s.clientY),o)d?(u(!1),x(!1),e.socketEmitFunctions.emitMouseRelease(t,n,"left")):(u(!0),e.socketEmitFunctions.emitMousePress(t,n,"left"));else{let r=e.checkDoubleClick(s.clientX,s.clientY);e.socketEmitFunctions.emitMouseClick(t,n,"left",r)}}}}return}if(e.isZooming||e.isPanning)return;if(t.type.startsWith("touch")){if(t.touches?.length!==1)return;r=t.touches[0].clientX,l=t.touches[0].clientY}else r=t.clientX,l=t.clientY;let{percentX:b,percentY:g}=e.getCanvasCoordinates(r,l);if("click"===s)if(a)p(r,l,i?"end":"start");else if(e.showClickIndicator(r,l),o)d?(u(!1),x(!1),e.socketEmitFunctions.emitMouseRelease(b,g,"left")):(u(!0),e.socketEmitFunctions.emitMousePress(b,g,"left"));else{let t=e.checkDoubleClick(r,l);e.socketEmitFunctions.emitMouseClick(b,g,"left",t)}else if("move"===s&&!m){if(a&&i)return p(r,l,"move");e.socketEmitFunctions.emitMouseMove(b,g)}}(S,t,r,u)},[h,g,M,l,j,d,B,i,p,ea,e,ei,eo,ec,eu,ex,eh,em,ep,s,n,x,m,o,a,ef]);(0,r.useEffect)(()=>{let e=s.current;e&&0!==e.width&&F(t=>0===t.x&&0===t.y?{x:e.width/2,y:e.height/2}:t)},[u,s]);let eg=(0,r.useCallback)(()=>{let e=s.current,t=x();if(!e||!t||0===e.width)return;let n=d*l;n<=0||F({x:oF((t.width/2-i.x)/n,0,e.width-1),y:oF((t.height/2-i.y)/n,0,e.height-1)})},[d,l,i,s,x]),ev=(0,r.useCallback)(()=>{let t=s.current;if(!t||0===t.width||V.current)return;X.current&&(clearTimeout(X.current),X.current=null);let{percentX:n,percentY:r}=ef(B,t);V.current=!0,G(!0),(0,ed.e)(15),e?.emitBoostStream?.(),e?.emitMousePress?.(n,r,"left")},[B,e,s,ef]),ey=(0,r.useCallback)(()=>{if(!V.current)return;let t=s.current,n=t&&t.width>0?B.x/t.width*100:0,r=t&&t.height>0?B.y/t.height*100:0;e?.emitMouseRelease?.(n,r,"left"),V.current=!1,G(!1)},[B,e,s]);return{canvasRef:s,canvasContainerRef:n,canvasZoom:l,canvasPan:i,fitScale:d,baseCanvasSize:u,zoomGestureTimeoutRef:N,clickIndicator:C,virtualCursor:B,handHolding:J,scrollLock:Q,getCanvasCoordinates:p,resetZoom:t.resetZoom,resetPan:t.resetPan,panForKeyboard:t.panForKeyboard,centerVirtualCursor:eg,startHandHold:ev,releaseHandHold:ey,handleCanvasInteraction:eb,handleCanvasDimensions:t.handleCanvasDimensions,serverDimensionsRef:t.serverDimensionsRef}}(et),eT=(0,r.useCallback)(()=>{N(e=>{let t="trackpad"===e?"direct":"trackpad";return"trackpad"===t&&ew(),t})},[ew,N]),{textInputValue:eR,setTextInputValue:eE,textInputRef:e$,modifierKeys:ez,selectionMode:eM,selectionStart:eP,selectionRect:eA,dragMode:eI,isDragging:eD,setIsDragging:eL,setDragMode:eB,toggleModifierKey:eF,toggleSelectionMode:eK,handleTextInputFocus:eO,handleCanvasKeyPress:eW,sendTextInput:e_,handleSelection:eH,handleModifiedTextInput:eU,handleDirectInputChange:eq,emitKeyWithActiveModifiers:eX}=function(e){let[t,s]=(0,r.useState)(""),[n,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(null),[d,u]=(0,r.useState)({ctrl:!1,cmd:!1,alt:!1,shift:!1}),[x,m]=(0,r.useState)(!1),[p,f]=(0,r.useState)(null),[h,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),j=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=()=>{let e=window.innerWidth<=768||/Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);return l(e),e},t=()=>{e()?i((window.visualViewport?.height||window.innerHeight)<.75*window.screen.height):i(!1)};return e(),window.addEventListener("resize",t),window.visualViewport&&window.visualViewport.addEventListener("resize",t),()=>{window.removeEventListener("resize",t),window.visualViewport&&window.visualViewport.removeEventListener("resize",t)}},[]),(0,r.useEffect)(()=>()=>{j.current&&clearInterval(j.current)},[]);let k=(0,r.useCallback)(e=>{u(t=>({...t,[e]:!t[e]})),n&&o.current&&o.current.focus()},[n]),N=(0,r.useCallback)(()=>{m(e=>!e),f(null),b(null)},[]),C=(0,r.useCallback)(()=>{v(e=>!e),y&&w(!1)},[y]),S=(0,r.useCallback)(()=>{},[]),T=(0,r.useCallback)((t,s)=>{if(!s||!e?.emitKeyPress)return;let n=t.key;if("Shift"===n||"Control"===n||"Meta"===n||"Alt"===n)return;"F12"!==n&&t.preventDefault();let r=[];t.ctrlKey&&r.push("control"),t.metaKey&&r.push("command"),t.altKey&&r.push("alt"),t.shiftKey&&r.push("shift");let l=Object.keys(d).filter(e=>d[e]);for(let e of l){let t=c.tC[e];t&&!r.includes(t)&&r.push(t)}let a=c.FO[n]??(1===n.length?n:n.toLowerCase());e.emitKeyPress(a,r),l.length>0&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1})},[d,e]),R=(0,r.useCallback)((t,s,r=!1)=>{s&&e?.emitScroll&&(j.current&&clearInterval(j.current),e.emitScroll(t,20,r),j.current=setInterval(()=>{e?.emitScroll&&s&&e.emitScroll(t,20,r)},c.eR.scrollInterval),n&&o.current&&a&&setTimeout(()=>o.current?.focus(),10))},[n,a,e]),E=(0,r.useCallback)(e=>R("up",e),[R]),$=(0,r.useCallback)(e=>R("down",e),[R]),z=(0,r.useCallback)(e=>R("left",e,!0),[R]),M=(0,r.useCallback)(e=>R("right",e,!0),[R]),P=(0,r.useCallback)(()=>{j.current&&(clearInterval(j.current),j.current=null)},[]),A=tN(e=>e.addCommand),I=(0,r.useCallback)(n=>{if(!n||!e?.emitTypeText)return;if(!t.trim())return void e.emitKeyPress?.("enter",[]);let r=document.activeElement===o.current;e.emitTypeText(t),A(t),s(""),r&&o.current?.focus()},[t,e,o,A]),D=(0,r.useRef)(""),L=(0,r.useRef)(null),B=(0,r.useCallback)((t,n)=>{n&&t&&e?.emitTypeText&&(D.current+=t,s(""),L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{let t=D.current;D.current="",L.current=null,t&&e.emitTypeText(t)},150))},[e]),F=(0,r.useCallback)(t=>{if(!e?.emitKeyPress)return;let s=Object.keys(d).filter(e=>d[e]),n=s.map(e=>c.tC[e]);e.emitKeyPress(t,n),s.length>0&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1})},[d,e]),K=(0,r.useCallback)(e=>{e&&(F("backspace"),n&&o.current&&a&&o.current.focus())},[n,a,F]),O=(0,r.useCallback)((e,t)=>{t&&(F(e),n&&o.current&&a&&o.current.focus())},[n,a,F]),W=(0,r.useCallback)(e=>{e&&(F("escape"),n&&o.current&&a&&o.current.focus())},[n,a,F]),_=(0,r.useCallback)(e=>{e&&(F("tab"),n&&o.current&&a&&o.current.focus())},[n,a,F]),H=(0,r.useCallback)((e,t)=>{t&&(F("enter"),e&&e.preventDefault(),n&&o.current&&a&&o.current.focus())},[n,a,F]),U=(0,r.useCallback)((t,s,n,r)=>{let{streaming:l,getCanvasCoordinates:a,baseCanvasSize:i,canvasZoom:o,canvasPan:c,percentOverride:d}=r;if(!x||!l||!e?.emitMouseDragSelect)return;let{percentX:u,percentY:h}=d||a(t,s);if("start"===n)f({x:u,y:h}),b(null);else if("move"===n&&p){let e=i.width*o,t=i.height*o;b({x:Math.min(p.x,u)*e/100+c.x,y:Math.min(p.y,h)*t/100+c.y,width:Math.abs(u-p.x)*e/100,height:Math.abs(h-p.y)*t/100})}else"end"===n&&p&&(e.emitMouseDragSelect(p.x,p.y,u,h),setTimeout(()=>{f(null),m(!1),b(null)},500))},[x,p,e]),q=(0,r.useCallback)((n,r,l=!1)=>{if(!r||!e?.emitTypeText||!e?.emitKeyPress)return;let a=n.key.toLowerCase();if(["shift","control","meta","alt"].includes(a)||"Unidentified"===n.key||229===n.keyCode)return;let i=Object.keys(d).filter(e=>d[e]),o=i.length>0,x=n.ctrlKey||n.metaKey||n.altKey||n.shiftKey;if(l){n.preventDefault();let t=i.map(e=>c.tC[e]);n.ctrlKey&&!t.includes("control")&&t.push("control"),n.metaKey&&!t.includes("command")&&t.push("command"),n.altKey&&!t.includes("alt")&&t.push("alt"),n.shiftKey&&!t.includes("shift")&&t.push("shift"),c.FO[a]?a=c.FO[a]:" "===a?a="space":1===n.key.length&&(a=n.key),e.emitKeyPress(a,t),o&&u({ctrl:!1,cmd:!1,alt:!1,shift:!1}),s("");return}if("Enter"===n.key){n.preventDefault(),t.trim()&&(e.emitTypeText(t),A(t),s(""));return}let m=/^[a-z0-9]$/i.test(n.key);if((o||x)&&(!m||o)){n.preventDefault();let t=i.map(e=>c.tC[e]);n.ctrlKey&&!t.includes("control")&&t.push("control"),n.metaKey&&!t.includes("command")&&t.push("command"),n.altKey&&!t.includes("alt")&&t.push("alt"),n.shiftKey&&!t.includes("shift")&&t.push("shift"),c.FO[a]?a=c.FO[a]:" "===a&&(a="space"),e.emitKeyPress(a,t),u({ctrl:!1,cmd:!1,alt:!1,shift:!1}),s("")}},[d,t,e,A]);return{textInputValue:t,setTextInputValue:s,textInputRef:o,keyboardVisible:a,modifierKeys:d,selectionMode:x,selectionStart:p,selectionRect:h,dragMode:g,isDragging:y,setIsDragging:w,setDragMode:v,toggleModifierKey:k,toggleSelectionMode:N,toggleDragMode:C,handleTextInputFocus:S,handleCanvasKeyPress:T,startScrollUp:E,startScrollDown:$,startScrollLeft:z,startScrollRight:M,stopScrolling:P,sendTextInput:I,sendBackspace:K,sendArrowKey:O,sendEscKey:W,sendTabKey:_,sendEnterKey:H,handleSelection:U,handleModifiedTextInput:q,handleDirectInputChange:B,emitKeyWithActiveModifiers:F}}(et),{keyboardOnRef:eV,toggleKeyboard:eJ,toggleTextPanel:eG,handleTextInputBlur:eY}=function({streaming:e,keyboardOn:t,setKeyboardOn:s,showTextPanel:n,setShowTextPanel:l,textInputRef:a,canvasContainerRef:i,panForKeyboard:o,pointerMode:c,virtualCursor:d}){let u=(0,r.useRef)(t);(0,r.useEffect)(()=>{u.current=t},[t]);let x=(0,r.useCallback)(()=>{let e=!t;u.current=e,s(e),e?a.current?.focus():a.current?.blur()},[t]),m=(0,r.useRef)(!1);(0,r.useEffect)(()=>{e&&!m.current&&u.current&&(m.current=!0,a.current?.focus())},[e]);let p=(0,r.useCallback)(()=>{let e=!n;!e&&t&&a.current?.focus(),l(e)},[n,t]),f=(0,r.useCallback)(()=>{u.current&&!n&&setTimeout(()=>a.current?.focus(),0)},[n]),h=(0,r.useRef)(null);return(0,r.useEffect)(()=>{h.current="trackpad"===c?d:null},[c,d]),(0,r.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=e.height,s=0,n=()=>{let n=e.height<t;t=e.height;let r=i.current;if(!r)return;let l=r.clientHeight;cancelAnimationFrame(s);let a=0,c=()=>{r.clientHeight!==l||a++>30?o(n,h.current):s=requestAnimationFrame(c)};s=requestAnimationFrame(c)};return e.addEventListener("resize",n),()=>{cancelAnimationFrame(s),e.removeEventListener("resize",n)}},[i,o]),{keyboardOnRef:u,toggleKeyboard:x,toggleTextPanel:p,handleTextInputBlur:f}}({streaming:W,keyboardOn:v,setKeyboardOn:y,showTextPanel:b,setShowTextPanel:g,textInputRef:e$,canvasContainerRef:er,panForKeyboard:ey,pointerMode:k,virtualCursor:ep}),eZ=(0,r.useCallback)((e,t=[],s=!1)=>{W&&(t.length>0?J(e,s&&"darwin"===i?t.map(e=>"control"===e?"command":e):t):eX(e))},[W,i,J,eX]),eQ=(0,r.useCallback)(()=>{S(e=>{let t=!e;return t?(eM&&eK(),ej()):ek(),t})},[S,eM,eK,ej,ek]),e0=oZ(t,W,en),{screenLocked:e1,unlockReady:e2,unlockResult:e5,setUnlockResult:e3,clipboardText:e4,clipboardNew:e6,setClipboardNew:e8,monitors:e9,activeMonitorIndex:e7,cursorShape:te}=function({busRef:e,connected:t,streaming:s,canvasRef:n,serverDimensionsRef:l,handleCanvasDimensions:a,resetPan:i,zoomGestureTimeoutRef:o,trackTilesReceived:u,tiles:x}){let[m,p]=(0,r.useState)(!1),[f,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(""),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)([]),[C,S]=(0,r.useState)(0),[T,R]=(0,r.useState)(null),E=(0,r.useRef)(null),{renderedTilesRef:$,handleFullScreenData:z,handleTilesData:M,handleTilesBinary:P,handleTilesBinaryV2:A,handleTilesMeta:I,handleScreenDimensions:D,cleanupTiles:L,requestScreenWithHashes:B}=x;return(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t)return;L();let n=e=>{D(e),a(e,$)},r=e=>z(e),l=e=>{let t=e.transport||"ws";t!==E.current&&(E.current=t,(0,d.c)("remote",`[remote] tiles via ${t}`)),u(e,t),M(e)},c=e=>console.error("Screen error:",e),x=({locked:e,ready:t}={})=>{p(!!e),h(!!t),e&&g(null)},m=e=>g(e||null),f=(e,t)=>{"ws"!==E.current&&(E.current="ws",(0,d.c)("remote",`[remote] tiles via ws${t}`)),u(function(e,t=Date.now()){let{tileCount:s,timestamp:n,bytes:r}=function(e,t=Date.now()){let s=e instanceof ArrayBuffer?e:e?.buffer,n=s?.byteLength||0,r=0,l=t;if(s&&s.byteLength>=12){let e=new DataView(s);r=e.getUint32(0,!0),l=e.getFloat64(4,!1)}return{tileCount:r,timestamp:l,bytes:n}}(e,t);return{tiles:Array(s),timestamp:n,bytes:r}}(e),"ws")},b=e=>{f(e,""),P(e)},v=e=>I(e),w=e=>{f(e," v2"),A(e)},k=()=>{L(),s.emit("get-screen-dimensions"),s.emit("get-unlock-state"),s.emit("start-streaming")},C=()=>k(),T=({text:e,hash:t})=>{y(s=>t&&t===T._lastHash?s:(T._lastHash=t||null,e||"")),j(!0)},B=({list:e,activeIndex:t})=>{N(Array.isArray(e)?e:[]),"number"==typeof t&&S(t)},F=e=>{L(),i(),"number"==typeof e?.monitorIndex&&S(e.monitorIndex)};s.on("screen-dimensions",n),s.on("full-screen-data",r),s.on("tiles-data",l),s.on("tiles-data-binary",b),s.on("tiles-bin-v2",w),s.on("tiles-meta",v),s.on("screen-error",c),s.on("screen-locked",x),s.on("unlock-result",m),s.on("remote:ready",C),s.on("clipboard-update",T),s.on("monitors",B),s.on("frame_meta",F);let K=e=>R(e?.shape??null);return s.on("cursor-shape",K),k(),()=>{s.emit("stop-streaming"),s.off("screen-dimensions",n),s.off("full-screen-data",r),s.off("tiles-data",l),s.off("tiles-data-binary",b),s.off("tiles-bin-v2",w),s.off("tiles-meta",v),s.off("screen-error",c),s.off("screen-locked",x),s.off("unlock-result",m),s.off("remote:ready",C),s.off("clipboard-update",T),s.off("monitors",B),s.off("frame_meta",F),s.off("cursor-shape",K),L(),o.current&&clearTimeout(o.current)}},[t]),(0,r.useEffect)(()=>{if(!s||!t||!e?.current)return;let n=setInterval(()=>{0===$.current.size?e.current.emit("request-screen-with-hashes",{tileHashes:[]}):B()},c.eR.hashRequestInterval);return()=>clearInterval(n)},[s,t,e,B,$]),(0,r.useEffect)(()=>{if(!t)return;let s=()=>{let t=n.current;if(!t||t.width>0)return!0;let{width:s,height:r}=l.current||{};return s>0?a({width:s,height:r},$):e.current?.emit("get-screen-dimensions"),!1};if(s())return;let r=setInterval(()=>{s()&&clearInterval(r)},c.eR.restreamDelay);return()=>clearInterval(r)},[t,e,n,l,a,$]),(0,r.useEffect)(()=>{let s=e?.current;if(!s||!t)return;let n=()=>{document.hidden?s.emit("stop-streaming"):s.emit("start-streaming")};return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[t,e]),{screenLocked:m,unlockReady:f,unlockResult:b,setUnlockResult:g,clipboardText:v,clipboardNew:w,setClipboardNew:j,monitors:k,activeMonitorIndex:C,cursorShape:T}}({busRef:t,connected:l,streaming:W,canvasRef:en,serverDimensionsRef:eS,handleCanvasDimensions:eC,resetPan:ev,zoomGestureTimeoutRef:ex,trackTilesReceived:P,tiles:e0});(0,r.useEffect)(()=>{if(!e6)return;let e=setTimeout(()=>e8(!1),c.eR.clipboardBadgeTimeout);return()=>clearTimeout(e)},[e6,e4,e8]),(0,r.useEffect)(()=>{if(!W)return;let e=setTimeout(()=>{let e=en.current,t=er.current;if(!e||!t||0===e.width)return;if(el<=1)return void Q(null,1);let s=ei*el;if(s<=0)return;let n=Math.max(0,-ea.x/s),r=Math.max(0,-ea.y/s),l=Math.min(e.width-n,t.clientWidth/s),a=Math.min(e.height-r,t.clientHeight/s);Q({x:Math.floor(n),y:Math.floor(r),w:Math.ceil(l),h:Math.ceil(a)},el)},c.eR.focusDebounce);return()=>clearTimeout(e)},[W,el,ea,ei,en,er,Q]);let tt=(0,r.useCallback)(()=>S(!1),[S]),ts=(0,r.useCallback)(e=>{t?.current?.emit("select_monitor",{index:e})},[t]),tn=(0,r.useCallback)(()=>{C&&S(!1),eK()},[C,S,eK]),tr=e=>t=>{eN(t,e,{streaming:W,selectionMode:eM,selectionStart:eP,dragMode:eI,isDragging:eD,setIsDragging:eL,setDragMode:eB,isMobile:e.includes("touch"),pointerMode:k,handMode:C,onHandRelease:tt,handleSelection:(e,t,s,n)=>eH(e,t,s,{streaming:W,getCanvasCoordinates:eb,baseCanvasSize:eo,canvasZoom:el,canvasPan:ea,...n})})};return(0,n.jsxs)("div",{className:`bg-bg text-text flex flex-col h-full w-full ${z?"":"landscape:flex-row"}`,style:{userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent"},onContextMenu:e=>e.preventDefault(),children:[(0,n.jsxs)("div",{className:"flex flex-row flex-1 min-h-0",children:[l&&(0,n.jsx)(ce,{streaming:W,canvasZoom:el,pointerMode:k,handMode:C,keyboardOn:v,selectionMode:eM,show:e=>"mouse"!==T||R?.[e],onBack:es,onRefresh:()=>{W&&_([])},onResetZoom:eg,onTogglePointerMode:eT,onToggleHandMode:eQ,onToggleKeyboard:eJ,onShowHelp:()=>x(!0),onToggleSelection:tn}),l?(0,n.jsx)(o1,{canvasRef:en,canvasContainerRef:er,canvasZoom:el,canvasPan:ea,fitScale:ei,streaming:W,hasFrame:e0.hasFrame,selectionRect:eA,clickIndicator:em,pointerMode:k,selectionMode:eM,handMode:C,handHolding:ef,scrollLock:eh,virtualCursor:ep,cursorShape:te,inputMode:T,keyboardOn:v,monitors:e9,activeMonitorIndex:e7,onSelectMonitor:ts,onPointerDown:tr("pointerdown"),onPointerMove:tr("pointermove"),onPointerUp:tr("pointerup"),onWheel:tr("wheel"),onContextMenu:tr("contextmenu"),onDoubleClick:tr("dblclick"),onTouchStart:tr("touch"),onTouchMove:tr("touchmove"),onTouchEnd:tr("touchend"),onKeyDown:e=>eW(e,W),screenLocked:e1,unlockReady:e2,unlockResult:e5,onUnlockSubmit:e=>{e3(null),t?.current?.emit("desktop-unlock",{text:e})}}):(0,n.jsxs)("div",{className:"flex-1 min-w-0 empty-stage",children:[(0,n.jsx)("div",{className:"empty-grid"}),(0,n.jsxs)("div",{className:"empty-half",children:[(0,n.jsxs)("span",{className:"empty-idx",children:[(0,n.jsx)("b",{children:"01"})," / ",o("workspaces.emptyTagRemote")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:o("workspaces.emptyWordRemote")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:o("workspaces.emptyMetaRemote")}}),(0,n.jsxs)("span",{className:"empty-go",children:[(0,n.jsx)(oP.A,{size:"sm"}),o("remote.connecting")]})]})]})]}),(0,n.jsx)(o4,{streaming:W,canvasZoom:el,clipboardNew:e6,clipboardText:e4,onOpenClipboard:()=>{e8(!1),h(!0)},onDesktopSwitch:ee,selectionMode:eM,pointerMode:k,handMode:C,inputMode:T,onToggleHandMode:eQ,onTogglePointerMode:eT,modifierKeys:ez,textInputValue:eR,textInputRef:e$,keyboardOn:v,showTextPanel:b,onResetZoom:eg,onRefresh:()=>W&&_([]),onToggleSelection:tn,onToggleModifier:eF,onToggleKeyboard:eJ,onToggleTextPanel:eG,controlsHidden:w,onToggleControlsHidden:j,tallLandscape:z,onToggleHelp:()=>x(!0),onEmitKey:eZ,onTextInputChange:eE,onTextInputFocus:eO,onTextInputBlur:eY,onTextInputKeyDown:e=>eU(e,W,v),onDirectInputChange:e=>eq(e,W),onSendText:e_,onClose:es,onToggleDebug:()=>D(e=>!e),debugOn:I}),I&&(0,n.jsx)(cs,{onForceWsDisconnect:()=>t?.current?.disconnect(),onToggleWsBlock:()=>{let e=s?.current;if(!e)return;let t=!e.wsBlocked;e.setWsBlocked(t),B(t)},isWsBlocked:L,stats:M,mode:F,onReset:A,onCopy:K,onClose:()=>D(!1)}),u&&(0,n.jsx)(ct,{inputMode:T,pointerMode:k,onClose:()=>{x(!1),v&&e$.current?.focus()}}),f&&(0,n.jsx)(cn,{text:e4,onClose:()=>h(!1)}),(0,n.jsx)(ec.A,{isOpen:m,onClose:()=>{p(!1),v&&e$.current?.focus()},onConfirm:()=>e?.(),title:o("remote.exitRemote"),message:o("remoteControls.exitConfirmMessage"),confirmText:o("connection.exit"),cancelText:o("common.cancel")})]})}function cl(e){return e?{scale:Math.min(1.25,window.devicePixelRatio||1),quality:85}:{}}let ca=new Set(["localhost","127.0.0.1","::1"]),ci=e=>"local"===e||ca.has(window.location.hostname);function co(e,t="default"){return(0,r.useCallback)((s,n={})=>new Promise(r=>{let l=e?.current;if(!l?.emit)return r({ok:!1,error:"Not connected"});let a={profile:t,...n},i=!1,o=setTimeout(()=>{i||(i=!0,r({ok:!1,error:"No reply from host — restart the host?"}))},12e3);l.emit("browser:invoke",{action:s,payload:a},e=>{i||(i=!0,clearTimeout(o),r(e||{ok:!1,error:"No reply from host"}))})}),[e,t])}function cc({busRef:e,connected:t,targetId:s,onPainted:n}){let l=(0,r.useRef)(null),[a,i]=(0,r.useState)(null),o=(0,r.useRef)(null),d=(0,r.useRef)(n);(0,r.useEffect)(()=>{d.current=n},[n]);let{hasFrame:u,handleTilesData:x,handleTilesBinaryV2:m,cleanupTiles:p,requestScreenWithHashes:f,handleScreenDimensions:h,renderedTilesRef:b}=oZ(e,t&&!!s,l,{ackEvent:"browser:stream.ack",verifyEvent:"browser:request-tiles-hashes",targetId:s,resetWorker:!1});return(0,r.useEffect)(()=>{let n=e?.current;if(!t||!n?.on||!s)return;p();let r=!1,a=e=>{r||(x(e),d.current?.({},e.bytes))},u=e=>{r||(m(e),d.current?.({},e?.byteLength||0))},g=e=>{if(r||e?.targetId!==s||!e.frameW||!e.frameH)return;let t=o.current,a=!t||t.w!==e.frameW||t.h!==e.frameH,c={w:e.frameW,h:e.frameH,meta:{...t?.meta||{},deviceWidth:e.deviceWidth,deviceHeight:e.deviceHeight}};o.current=c,a&&(p(),h({tileCount:e.tileCount}),i(c),l.current&&(l.current.width=e.frameW,l.current.height=e.frameH),n.emit?.("browser:request-tiles-hashes",{targetId:s,tileHashes:[]}))};n.on?.("browser:tiles-data",a),n.on?.("browser:tiles-bin",u),n.on?.("browser:screen-dimensions",g);let v=setInterval(()=>{r||!("u"<typeof document)&&document.hidden||(0===b.current.size?n.emit?.("browser:request-tiles-hashes",{targetId:s,tileHashes:[]}):f())},c.eR.hashRequestInterval);return()=>{r=!0,n.off?.("browser:tiles-data",a),n.off?.("browser:tiles-bin",u),n.off?.("browser:screen-dimensions",g),clearInterval(v),p()}},[e,t,s,p,x,m,h,f,b]),{canvasRef:l,frame:u||a?a||{w:1280,h:720}:null,frameRef:o}}function cd(e){let[t,s]=[...e.values()];return t&&s?Math.hypot(t.x-s.x,t.y-s.y):0}function cu({title:e,icon:t=null,onClose:s,children:l,footer:a=null,wide:i=!1}){return(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),s?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[s]),(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center px-4 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-150",style:{paddingTop:"max(1rem, env(safe-area-inset-top))",paddingBottom:"max(1rem, env(safe-area-inset-bottom))"},onClick:s,children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:`card-elev ${i?"max-w-lg":"max-w-md"} w-full my-auto max-h-[min(85%,calc(var(--app-height,85vh)-2rem))] overflow-hidden flex flex-col animate-in zoom-in-95 duration-150`,onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-4 pt-4 pb-3 border-b border-border-subtle",children:[(0,n.jsxs)("h2",{className:"flex items-center gap-1.5 text-sm font-semibold text-text min-w-0",children:[t,(0,n.jsx)("span",{className:"truncate",children:e})]}),(0,n.jsx)("button",{onClick:s,"aria-label":"Close",className:"shrink-0 text-text-muted hover:text-text",children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3",children:l}),a&&(0,n.jsx)("div",{className:"px-4 py-3 border-t border-border-subtle",children:a})]})})}function cx({element:e,autoFocusNote:t=!1,at:s=null,onAddAnnotation:l,onClose:a}){let[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),f=(0,r.useRef)(null);if((0,r.useEffect)(()=>{t&&f.current?.focus()},[t]),!e)return null;let h=e.selector||e.tag||"element",b=async()=>{(0,ed.e)(),await navigator.clipboard?.writeText(h),d(!0),setTimeout(()=>d(!1),2e3)},g=async()=>{(0,ed.e)();let t=[`### Target Element: \`<${e.tag}>\``,`- Selector: \`${h}\``,e.text?`- Text: "${e.text}"`:null,e.html?`- HTML: \`${e.html.slice(0,300)}\``:null,i?`- Instructions: ${i}`:null].filter(Boolean).join("\n");await navigator.clipboard?.writeText(t),x(!0),setTimeout(()=>x(!1),2e3)},v=()=>{(0,ed.e)(),l?.({id:Date.now().toString(),tag:e.tag,selector:h,text:e.text,html:e.html,note:i.trim()}),p(!0),setTimeout(()=>{p(!1),a()},800)},y=(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-brand-500/10 text-brand-500 font-mono text-xs font-semibold uppercase",children:e.tag}),(0,n.jsx)("span",{className:"font-mono text-xs text-text truncate",children:h})]}),w=(0,n.jsxs)(n.Fragment,{children:[!s&&(0,n.jsx)("div",{className:"pb-1",children:y}),e.text&&(0,n.jsx)("div",{className:"text-xs text-text-muted bg-surface-2 p-2 rounded-brand font-mono line-clamp-2",children:e.text}),e.styles&&(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-[11px] text-text-muted font-mono",children:[e.styles.display&&(0,n.jsxs)("span",{children:["display: ",e.styles.display]}),e.styles.fontSize&&(0,n.jsxs)("span",{children:["size: ",e.styles.fontSize]}),e.styles.color&&(0,n.jsxs)("span",{children:["color: ",e.styles.color]})]}),(0,n.jsx)("input",{ref:f,type:"text",value:i,onChange:e=>o(e.target.value),onKeyDown:e=>"Enter"===e.key&&v(),placeholder:"Note for AI (e.g. change color to dark, fix alignment...)",className:"w-full px-2.5 py-1.5 bg-surface-2 rounded-brand text-xs text-text placeholder-text-muted focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),j=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:b,className:"flex-1 py-1.5 bg-surface-2 hover:bg-surface-3 text-text rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors",children:[c?(0,n.jsx)(el.aJ,{size:13,className:"text-emerald-500"}):(0,n.jsx)(el.QR,{size:13}),c?"Copied":"Copy Selector"]}),(0,n.jsxs)("button",{onClick:g,className:"flex-1 py-1.5 bg-brand-500 hover:bg-brand-600 text-white rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors",children:[u?(0,n.jsx)(el.aJ,{size:13}):(0,n.jsx)(el.sU,{size:13}),u?"Copied AI Prompt":"Copy for AI"]}),(0,n.jsxs)("button",{onClick:v,className:"px-3 py-1.5 bg-surface-2 hover:bg-surface-3 rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors",children:[m?(0,n.jsx)(el.aJ,{size:13,className:"text-emerald-500"}):(0,n.jsx)(el.Vn,{size:13}),m?"Saved":"Add Note"]})]});return s?(0,n.jsxs)("div",{className:"z-30 bg-surface border border-border-subtle shadow-2xl p-3 flex flex-col gap-2.5 overflow-y-auto animate-in fade-in duration-150 absolute w-[300px] max-w-[90%] max-h-[60%] rounded-xl",style:{left:`min(${s.x}px, calc(100% - 310px))`,top:`min(${s.y}px, calc(100% - 120px))`},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[y,(0,n.jsx)("button",{onClick:a,className:"p-1 text-text-muted hover:text-text rounded-brand shrink-0",title:"Close",children:(0,n.jsx)(el.X,{size:15})})]}),w,(0,n.jsx)("div",{className:"flex items-center gap-2 pt-1",children:j})]}):(0,n.jsx)(cu,{title:"Inspect Element",onClose:a,footer:(0,n.jsx)("div",{className:"flex items-center gap-2",children:j}),children:(0,n.jsx)("div",{className:"flex flex-col gap-2.5",children:w})})}function cm({annotations:e=[],onDelete:t,onClear:s,onClose:l}){let[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(!1),d=()=>[`## Design & Code Feedback (${e.length} items)`,...e.map((e,t)=>[`
18
+ ### ${t+1}. Element: \`<${e.tag}>\``,`- Selector: \`${e.selector}\``,e.text?`- Text: "${e.text}"`:null,e.note?`- **Requested Change**: ${e.note}`:null].filter(Boolean).join("\n"))].join("\n"),u=async()=>{e.length&&((0,ed.e)(),await navigator.clipboard?.writeText?.(d()),i(!0),setTimeout(()=>i(!1),2e3))};return(0,n.jsx)(cu,{title:`Collected Notes (${e.length})`,onClose:l,footer:e.length>0?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{if(!e.length)return;(0,ed.e)();let t=Object.entries(h.B.getState().agentBySession||{}).find(([,e])=>e?.endsWith("-ui"));if(!t)return void u();let[s]=t,n=d();for(let e of(h.B.getState().popView(),window.dispatchEvent(new CustomEvent(eJ.vP,{detail:{sessionId:s}})),[200,700]))setTimeout(()=>window.dispatchEvent(new CustomEvent("9r:ai-prompt",{detail:{sessionId:s,text:n}})),e);c(!0),setTimeout(()=>c(!1),2e3)},className:"flex-1 py-1.5 bg-emerald-500 hover:bg-emerald-600 text-white rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors",title:"Send to the open AI chat",children:[o?(0,n.jsx)(el.aJ,{size:13}):(0,n.jsx)(el.Vn,{size:13}),o?"Sent":"Send to AI"]}),(0,n.jsxs)("button",{onClick:u,className:"flex-1 py-1.5 bg-brand-500 hover:bg-brand-600 text-white rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors",children:[a?(0,n.jsx)(el.aJ,{size:13}):(0,n.jsx)(el.QR,{size:13}),a?"Copied":"Copy All"]}),(0,n.jsx)("button",{onClick:s,className:"p-2 text-text-muted hover:text-red-500 rounded-brand transition-colors",title:"Clear all",children:(0,n.jsx)(el.TB,{size:14})})]}):null,children:0===e.length?(0,n.jsx)("div",{className:"py-6 text-center text-xs text-text-muted",children:"No annotations yet. Click the message icon on toolbar to annotate elements."}):(0,n.jsx)("div",{className:"flex flex-col gap-2",children:e.map((e,s)=>(0,n.jsxs)("div",{className:"p-2 rounded-brand bg-surface-2 border border-border-subtle flex items-start justify-between gap-2 text-xs",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1 min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsxs)("span",{className:"font-semibold text-text",children:[s+1,"."]}),(0,n.jsx)("span",{className:"font-mono text-brand-500 font-medium",children:e.tag}),(0,n.jsx)("span",{className:"font-mono text-text-muted truncate",children:e.selector})]}),e.note&&(0,n.jsx)("div",{className:"text-text font-medium bg-surface/50 p-1.5 rounded",children:e.note})]}),(0,n.jsx)("button",{onClick:()=>t?.(e.id),className:"p-1 text-text-muted hover:text-red-500 rounded shrink-0",title:"Delete",children:(0,n.jsx)(el.TB,{size:12})})]},e.id||s))})})}function cp({frameImgSrc:e,onClose:t}){let s=(0,r.useRef)(null),[l,a]=(0,r.useState)(!1),[i,o]=(0,r.useState)("#ef4444"),[c,d]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let t=s.current;if(!t)return;let n=t.getContext("2d"),r=new Image;r.src=e,r.onload=()=>{t.width=r.naturalWidth||800,t.height=r.naturalHeight||600,n.drawImage(r,0,0)}},[e]);let u=e=>{let t=s.current,n=t.getBoundingClientRect(),r=t.width/n.width,l=t.height/n.height;return{x:(e.clientX-n.left)*r,y:(e.clientY-n.top)*l}},x=()=>{a(!1)},m=async()=>{(0,ed.e)();let e=s.current;if(e)try{e.toBlob(async e=>{e&&(await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),d(!0),setTimeout(()=>d(!1),2e3))})}catch{}};return(0,n.jsxs)("div",{className:"absolute inset-0 z-40 bg-black/80 flex flex-col items-center justify-between p-3 select-none",children:[(0,n.jsxs)("div",{className:"w-full flex items-center justify-between bg-surface/90 backdrop-blur px-3 py-2 rounded-brand border border-border-subtle shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-text",children:"Markup"}),["#ef4444","#f59e0b","#10b981","#3b82f6"].map(e=>(0,n.jsx)("button",{onClick:()=>o(e),className:`w-5 h-5 rounded-full border-2 transition-transform ${i===e?"scale-110 border-white":"border-transparent"}`,style:{backgroundColor:e}},e)),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)();let t=s.current,n=t.getContext("2d"),r=new Image;r.src=e,r.onload=()=>{n.clearRect(0,0,t.width,t.height),n.drawImage(r,0,0)}},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand text-xs flex items-center gap-1",title:"Reset",children:(0,n.jsx)(el.kt,{size:13})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:m,className:"px-2.5 py-1 bg-brand-500 hover:bg-brand-600 text-white rounded-brand text-xs font-medium flex items-center gap-1.5",children:[c?(0,n.jsx)(el.aJ,{size:13}):(0,n.jsx)(el.QR,{size:13}),c?"Copied":"Copy Image"]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-text-muted hover:text-text rounded-brand",title:"Close",children:(0,n.jsx)(el.X,{size:16})})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 w-full flex items-center justify-center p-2 overflow-hidden",children:(0,n.jsx)("canvas",{ref:s,onPointerDown:e=>{a(!0);let t=s.current.getContext("2d"),n=u(e);t.strokeStyle=i,t.lineWidth=4,t.lineCap="round",t.beginPath(),t.moveTo(n.x,n.y)},onPointerMove:e=>{if(!l)return;let t=s.current.getContext("2d"),n=u(e);t.lineTo(n.x,n.y),t.stroke()},onPointerUp:x,onPointerCancel:x,className:"max-w-full max-h-full object-contain cursor-crosshair rounded border border-border-subtle shadow-2xl touch-none"})})]})}function cf({onEval:e,onClose:t}){let[s,l]=(0,r.useState)(""),[a,i]=(0,r.useState)([]),[o,c]=(0,r.useState)(!1),d=async()=>{let t=s.trim();if(!t||o)return;(0,ed.e)(),c(!0);let n=await e?.(t);c(!1),i(e=>[...e,{code:t,result:n?.result!==void 0?n.result:n?.error||"undefined",ok:n?.ok!==!1}]),l("")};return(0,n.jsx)(cu,{wide:!0,title:"Console REPL",icon:(0,n.jsx)(el.BK,{size:14,className:"text-brand-500 shrink-0"}),onClose:t,footer:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:s,onChange:e=>l(e.target.value),onKeyDown:e=>"Enter"===e.key&&d(),placeholder:"e.g. document.title, window.location.href",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:"flex-1 min-w-0 px-2.5 py-1.5 bg-surface-2 rounded-brand font-mono text-xs text-text placeholder-text-muted focus:outline-none"}),(0,n.jsx)("button",{onClick:d,disabled:!s.trim()||o,className:"px-3 py-1.5 bg-brand-500 hover:bg-brand-600 disabled:opacity-40 text-white rounded-brand text-xs font-medium transition-colors",children:"Run"})]}),children:(0,n.jsxs)("div",{className:"min-h-[160px] max-h-[40vh] overflow-y-auto font-mono text-[11px] space-y-1.5 p-2 bg-surface-2 rounded-brand",children:[0===a.length&&(0,n.jsx)("span",{className:"text-text-muted",children:"Type a JS expression below to evaluate on the page."}),a.map((e,t)=>(0,n.jsxs)("div",{className:"space-y-0.5",children:[(0,n.jsxs)("div",{className:"text-text-muted flex items-start gap-1",children:[(0,n.jsx)("span",{className:"text-brand-500",children:">"}),(0,n.jsx)("span",{className:"break-all",children:e.code})]}),(0,n.jsx)("div",{className:`pl-3 break-all whitespace-pre-wrap ${e.ok?"text-emerald-500":"text-red-500"}`,children:"object"==typeof e.result?JSON.stringify(e.result,null,2):String(e.result)})]},t))]})})}function ch({invoke:e,profile:t="default",onSelectProfile:s,targetId:l,url:a,initialSection:i=null,onCopyUrl:o,onClose:c}){let d=e=>s?.(e||"default"),[u,x]=(0,r.useState)([]),[m,p]=(0,r.useState)([]),[f,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(""),C=(0,r.useRef)(null),[S,T]=(0,r.useState)("cookies"===i),[R,E]=(0,r.useState)(""),[$,z]=(0,r.useState)(null),[M,P]=(0,r.useState)(null);(0,r.useEffect)(()=>{e?.("profiles.list")?.then(e=>{e?.ok&&Array.isArray(e.profiles)&&x(e.profiles)}),e?.("browsers.detect")?.then(e=>{e?.ok&&Array.isArray(e.browsers)&&p(e.browsers)})},[e]);let A=async()=>{let t=b.trim();if(!t)return;(0,ed.e)();let s=await e?.("profiles.create",{name:t});if(s?.ok){h(!1),g("");let s=await e?.("profiles.list");s?.ok&&x(s.profiles),d(t)}},I=async()=>{if(!R.trim()||!l)return;(0,ed.e)(),z("Importing…");let t=await e?.("cookie.import",{targetId:l,content:R.trim()});t?.ok?(z(`Imported ${t.imported} cookies!`),setTimeout(()=>{z(null),T(!1),E("")},2e3)):z(t?.error||"Import failed")},D=async(t,s,n,r)=>{let l=String(r||n).replace(/[^a-zA-Z0-9]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").slice(0,40)||t,a=k.trim()||l;(0,ed.e)(),z(`Importing from ${n}…`);let i=await e?.("profiles.createFromBrowser",{family:t,profileDirectory:s,name:a});if(i?.ok){let t=await e?.("profiles.list");t?.ok&&x(t.profiles),d(i.profile||a),j(!1),z(null)}else z(i?.error||"Import failed")},L=async s=>{if(v!==s)return void y(s);(0,ed.e)();let n=await e?.("profiles.remove",{name:s});if(y(null),n?.ok){t===s&&d("default");let n=await e?.("profiles.list");n?.ok&&x(n.profiles)}};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(cu,{wide:!0,title:"Browser & Profiles",onClose:c,children:(0,n.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-[11px] font-semibold text-text uppercase tracking-wider",children:"Profiles"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:[...u].sort((e,t)=>"default"===e.name?-1:+("default"===t.name)).map(e=>(0,n.jsxs)("div",{className:`group px-2 py-1.5 rounded-brand text-xs flex items-center gap-2 cursor-pointer transition-colors ${t===e.name?"bg-surface-3 text-text font-medium":"hover:bg-surface-2 text-text-muted"}`,onClick:()=>{var t;return t=e.name,void((0,ed.e)(),d(t))},children:[(0,n.jsx)(n5,{name:e.name}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),t===e.name&&(0,n.jsx)(el.aJ,{size:13,className:"text-brand-500 shrink-0"}),"default"!==e.name&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),L(e.name)},className:`p-1 rounded shrink-0 transition-colors ${v===e.name?"text-red-500 opacity-100":"text-text-muted hover:text-red-500 opacity-0 group-hover:opacity-100 focus:opacity-100"} hover:bg-surface/60`,title:v===e.name?"Click again to delete":"Delete profile",children:(0,n.jsx)(el.TB,{size:12})})]},e.name))}),f?(0,n.jsxs)("div",{className:"flex flex-col gap-2 p-2 bg-surface-2 rounded-brand mt-1",children:[(0,n.jsx)("input",{type:"text",value:b,onChange:e=>g(e.target.value),placeholder:"Profile name (e.g. work, personal)",className:"px-2 py-1 bg-surface text-xs rounded text-text placeholder-text-muted focus:outline-none"}),(0,n.jsxs)("div",{className:"flex justify-end gap-1.5",children:[(0,n.jsx)("button",{onClick:()=>h(!1),className:"px-2 py-1 text-xs text-text-muted",children:"Cancel"}),(0,n.jsx)("button",{onClick:A,disabled:!b.trim(),className:"px-2.5 py-1 bg-brand-500 text-white rounded text-xs font-medium disabled:opacity-40",children:"Create"})]})]}):(0,n.jsxs)("button",{onClick:()=>h(!0),className:"flex items-center gap-2 px-2 py-1.5 rounded-brand text-xs text-text-muted hover:bg-surface-2 hover:text-text transition-colors mt-0.5",children:[(0,n.jsx)("span",{className:"w-5 h-5 shrink-0 rounded-full border border-dashed border-border-subtle flex items-center justify-center",children:(0,n.jsx)(el.FW,{size:11})}),(0,n.jsx)("span",{children:"Create profile"})]})]}),(0,n.jsxs)("button",{onClick:()=>{N(""),j(!0)},className:"flex items-center gap-2 px-2 py-1.5 rounded-brand text-xs text-text-muted hover:bg-surface-2 hover:text-text transition-colors -mt-1",children:[(0,n.jsx)("span",{className:"w-5 h-5 shrink-0 rounded-full border border-dashed border-border-subtle flex items-center justify-center",children:(0,n.jsx)(el.FW,{size:11})}),(0,n.jsx)("span",{children:"Add profile"})]})]})}),w&&(0,n.jsx)(cu,{wide:!0,title:"Add profile",onClose:()=>j(!1),footer:(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("input",{ref:C,type:"text",value:k,onChange:e=>N(e.target.value),onKeyDown:e=>"Enter"===e.key&&m?.[0]?.profiles?.[0]&&D(m[0].family,m[0].profiles[0].directory,`${m[0].label} (${m[0].profiles[0].name})`,`${m[0].family}_${m[0].profiles[0].name}`),placeholder:"Custom profile name (optional, defaults to source)",className:"flex-1 px-3 py-1.5 bg-surface-2 border border-border-subtle rounded-brand text-xs text-text placeholder-text-muted focus:outline-none focus:border-brand-500"})}),children:(0,n.jsxs)("div",{className:"flex flex-col gap-2",children:[$&&(0,n.jsx)("div",{className:"p-2 rounded bg-brand-500/10 border border-brand-500/20 text-xs text-brand-500 font-medium",children:$}),0===m.length?(0,n.jsx)("div",{className:"text-xs text-text-muted py-1",children:"No installed browsers detected on host."}):m.map(e=>(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs font-semibold text-text",children:[(0,n.jsx)(el.qz,{size:13,className:"text-brand-500"}),(0,n.jsx)("span",{children:e.label})]}),e.profiles.map(t=>(0,n.jsxs)("button",{onClick:()=>D(e.family,t.directory,`${e.label} (${t.name})`,`${e.family}_${t.name}`),disabled:M===`${e.family}:${t.directory}`,className:"text-left px-2.5 py-1.5 rounded-brand text-xs text-text hover:bg-surface-2 disabled:opacity-40 flex items-center justify-between gap-2",children:[(0,n.jsx)("span",{className:"truncate font-medium",children:t.name}),(0,n.jsx)("span",{className:"px-2 py-0.5 rounded bg-brand-500/10 text-brand-500 text-[10px] font-semibold shrink-0",children:M===`${e.family}:${t.directory}`?"Importing…":"Import"})]},t.directory))]},e.family)),S&&(0,n.jsxs)("div",{className:"flex flex-col gap-2 p-2 bg-surface-2 rounded-brand mt-1",children:[(0,n.jsx)("textarea",{value:R,onChange:e=>E(e.target.value),placeholder:"Paste JSON array or Netscape format cookies",rows:3,className:"p-1.5 bg-surface text-xs font-mono rounded text-text placeholder-text-muted focus:outline-none"}),(0,n.jsx)("div",{className:"flex justify-end gap-1.5",children:(0,n.jsx)("button",{onClick:I,disabled:!R.trim()||!l,className:"px-2.5 py-1 bg-brand-500 text-white rounded text-xs font-medium disabled:opacity-40",children:"Import Pasted"})})]}),(0,n.jsxs)("button",{onClick:()=>T(e=>!e),className:"text-[11px] text-text-muted hover:text-text flex items-center gap-1 self-start",children:[(0,n.jsx)(el.yQ,{size:12,className:`transition-transform duration-150 ${S?"rotate-180":""}`}),(0,n.jsx)("span",{children:"Paste cookies manually…"})]})]})})]})}function cb({menu:e,items:t,onClose:s}){let l=(0,r.useRef)(null),a=s_(l,e?.x??0,e?.y??0);return((0,r.useEffect)(()=>{if(!e)return;let t=e=>{l.current&&!l.current.contains(e.target)&&s()},n=e=>{"Escape"===e.key&&s()};return document.addEventListener("pointerdown",t,!0),document.addEventListener("keydown",n),()=>{document.removeEventListener("pointerdown",t,!0),document.removeEventListener("keydown",n)}},[e,s]),e)?(0,n.jsx)("div",{ref:l,className:"fixed z-[80] menu-popover p-1 min-w-[170px] animate-in fade-in zoom-in-95 duration-100 shadow-xl",style:{left:a.left,top:a.top},children:t.map((e,t)=>e.divider?(0,n.jsx)("div",{className:"my-1 h-px bg-border-subtle"},`d${t}`):(0,n.jsxs)("button",{type:"button",onClick:()=>{e.onPick?.(),s()},className:"w-full text-left px-2 py-1.5 text-xs text-text hover:bg-surface-2/80 rounded-[6px] flex items-center gap-2",children:[e.icon,(0,n.jsx)("span",{className:"truncate",children:e.label})]},e.label))}):null}function cg({items:e,activeIdx:t,onPick:s,onHover:r}){return e?.length?(0,n.jsx)("div",{className:"absolute left-0 right-0 top-full mt-1 z-30 menu-popover p-1 max-h-64 overflow-y-auto shadow-xl animate-in fade-in duration-75",children:e.map((e,l)=>(0,n.jsxs)("button",{type:"button",onMouseEnter:()=>r?.(l),onClick:()=>s(e),className:`w-full text-left px-3 py-2 rounded-[6px] flex items-center gap-2 ${l===t?"bg-surface-2":"hover:bg-surface-2/60"}`,children:[e.isSearch?(0,n.jsx)(el.vj,{size:14,className:"shrink-0 text-text-muted"}):(0,n.jsx)(el.qz,{size:14,className:"shrink-0 text-text-muted"}),(0,n.jsxs)("span",{className:"flex min-w-0 flex-1 flex-col",children:[(0,n.jsx)("span",{className:"truncate text-sm text-text",children:e.title}),e.subtitle&&(0,n.jsx)("span",{className:"truncate text-xs text-text-muted font-mono",children:e.subtitle})]})]},e.url))}):null}let cv={width:720,height:900};function cy({busRef:e,connected:t=!1,targetId:s,url:l,profile:a="default",onClose:i}){let{t:o}=(0,eu.s)(),c=co(e,a),d=ci((0,u.d)(e=>e.connectionMode)),x=(0,r.useRef)(null),m=(0,r.useRef)(null),p=(0,r.useRef)(null),f=(0,r.useRef)(null),h=(0,r.useRef)(null),b=(0,r.useRef)(new Map);(0,r.useEffect)(()=>{let n=e?.current;if(t&&n?.emit&&s)return n.emit("browser:stream.start",{targetId:s,...cv,...cl(d),profile:a,isPopup:!0}),()=>{n.emit("browser:stream.stop",{targetId:s})}},[e,t,s,d]);let{canvasRef:g,frame:v,frameRef:y}=cc({busRef:e,connected:t,targetId:s});(0,r.useEffect)(()=>()=>{p.current&&clearTimeout(p.current),f.current&&clearTimeout(f.current),h.current?.timer&&clearTimeout(h.current.timer)},[]);let w=(0,r.useCallback)(t=>{s&&t.length&&e?.current?.emit?.("browser:input",{targetId:s,events:t,profile:a})},[e,s]),j=(0,r.useCallback)((e,t)=>{let s=g.current,n=y.current?.meta;if(!s)return{x:0,y:0};let r=s.getBoundingClientRect();if(!r.width||!r.height)return{x:0,y:0};let l=n?.deviceWidth||r.width,a=n?.deviceHeight||r.height,i=Math.round((e-r.left)/r.width*l),o=Math.round((t-r.top)/r.height*a);return{x:Math.max(0,Math.min(l,i)),y:Math.max(0,Math.min(a,o))}},[]),k=(0,r.useCallback)(e=>j(e.clientX,e.clientY),[j]),N=e=>{if("touch"===e.pointerType){b.current.delete(e.pointerId),w([{t:"touch",type:"end"}]);return}if(!m.current||!y.current)return;m.current=null;let t=k(e),s=2===e.button?"right":1===e.button?"middle":"left";w([{t:"pointer",type:"release",x:t.x,y:t.y,button:s}])};return(0,r.useEffect)(()=>{let e=x.current;if(!e||!s)return;let t=e=>{if(!y.current)return;e.preventDefault();let t=j(e.clientX,e.clientY),s=h.current||(h.current={x:t.x,y:t.y,deltaX:0,deltaY:0});s.x=t.x,s.y=t.y,s.deltaX+=e.deltaX,s.deltaY+=e.deltaY,s.timer||(s.timer=setTimeout(()=>{s.timer=null,w([{t:"wheel",x:s.x,y:s.y,deltaX:s.deltaX,deltaY:s.deltaY}]),s.deltaX=0,s.deltaY=0},50))};return e.addEventListener("wheel",t,{passive:!1}),()=>e.removeEventListener("wheel",t)},[s,w,j]),(0,n.jsx)("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-black/30",onContextMenu:e=>e.preventDefault(),children:(0,n.jsxs)("div",{ref:x,onPointerDown:e=>{if(y.current&&!(e.button>2)){if((0,ed.e)(),"touch"===e.pointerType){b.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),w([{t:"touch",type:"start",points:[k(e)]}]);return}m.current={sx:e.clientX,sy:e.clientY,moved:!1},w([{t:"pointer",type:"press",x:k(e).x,y:k(e).y,button:2===e.button?"right":1===e.button?"middle":"left"}])}},onPointerMove:e=>{if("touch"===e.pointerType){if(!b.current.has(e.pointerId)||(b.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),f.current))return;f.current=setTimeout(()=>{f.current=null,w([{t:"touch",type:"move",points:[k(e)]}])},16);return}if(m.current&&y.current){let t=m.current;Math.abs(e.clientX-t.sx)+Math.abs(e.clientY-t.sy)>8&&(t.moved=!0),t.moved&&!f.current&&(f.current=setTimeout(()=>{f.current=null,w([{t:"pointer",type:"move",x:k(e).x,y:k(e).y,drag:!0}])},30));return}!y.current||p.current||(p.current=setTimeout(()=>{p.current=null,w([{t:"pointer",type:"move",x:k(e).x,y:k(e).y}])},80))},onPointerUp:N,onPointerCancel:N,className:"w-[min(580px,94%)] h-[min(700px,92%)] rounded-xl overflow-hidden border border-border-subtle bg-white shadow-2xl flex flex-col",children:[(0,n.jsxs)("div",{className:"h-8 shrink-0 flex items-center gap-2 px-3 bg-surface border-b border-border-subtle cursor-default",children:[(0,n.jsx)(el.qz,{size:13,className:"text-text-muted shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-xs text-text-muted",children:l||"popup"}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),c("close",{targetId:s}),i?.()},className:"p-1 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors",title:o("common.close"),children:(0,n.jsx)(el.X,{size:13})})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-black relative flex items-center justify-center touch-none select-none outline-none",children:[(0,n.jsx)("canvas",{ref:g,width:v?.w||16,height:v?.h||16,className:`max-w-full max-h-full object-contain pointer-events-none ${v?"":"opacity-0"}`}),!v&&(0,n.jsxs)("div",{className:"absolute inset-0 flex items-center justify-center text-text-muted text-xs gap-2 bg-surface",children:[(0,n.jsx)(el.kr,{size:14,className:"animate-spin"})," ",o("sites.browserPaneLoading")]})]})]})})}function cw({picked:e=[],url:t=null,onRemoveItem:s,onClear:l,onClose:a}){let[i,o]=(0,r.useState)("review"),[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(null),f=(0,P.rh)(e=>e.hosts),b=(0,P.rh)(e=>e.currentKey),g=(0,h.B)(e=>e.agentBySession||{}),v=eM(),y=(0,r.useMemo)(()=>(function(e,t=null){return[`## Browser Elements (${e.length})`,t?`Page: ${t}`:null,"Selectors are unique CSS paths — reuse with document.querySelector() or a find/click-by-selector tool.","",...e.map((e,t)=>[`### ${t+1}. \`<${e.tag}>\``,`- Selector: \`${e.selector||e.tag}\``,e.text?`- Text: "${e.text}"`:null,e.href?`- Link: ${e.href}`:null,e.rect?`- Rect: ${e.rect.x},${e.rect.y} ${e.rect.width}\xd7${e.rect.height}`:null].filter(Boolean).join("\n"))].filter(Boolean).join("\n")})(e,t)+(c.trim()?`
19
+
20
+ ${c.trim()}`:""),[e,t,c]),w=(0,r.useMemo)(()=>Object.values(f||{}).sort((e,t)=>e.key===b?-1:+(t.key===b)).flatMap(e=>(e.sessions||[]).map(t=>({...t,hostLabel:e.key===b?null:e.label||e.key}))),[f,b]),j=async()=>{(0,ed.e)(),await navigator.clipboard?.writeText(y),x(!0),setTimeout(()=>x(!1),2e3)};return"sessions"===i?(0,n.jsx)(cu,{wide:!0,title:"Send to Session",icon:(0,n.jsx)(el.JG,{size:14,className:"text-text-muted shrink-0"}),onClose:a,children:(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[0===w.length&&(0,n.jsx)("div",{className:"py-6 text-center text-xs text-text-muted",children:"No running sessions."}),w.map(e=>{let t=se(v[e.id]?.state||"idle");return(0,n.jsxs)("button",{type:"button",onClick:()=>{let t;return(0,ed.e)(),t=e$(e.id),void(t?.busRef?.current?.emit?.("ai:prompt",{sessionId:e.id,message:y}),h.B.getState().popView(),window.dispatchEvent(new CustomEvent(eJ.vP,{detail:{sessionId:e.id}})),p(e.id),l?.(),setTimeout(a,500))},className:"w-full text-left px-2.5 py-2 rounded-brand text-xs flex items-center gap-2 hover:bg-surface-2 transition-colors",children:[(0,n.jsxs)("span",{className:"w-4 h-4 shrink-0 flex items-center justify-center relative",children:[m===e.id?(0,n.jsx)(el.aJ,{size:14,className:"text-emerald-500"}):e5(g[e.id])?(0,n.jsx)("img",{src:e5(g[e.id]),alt:"",width:16,height:16,className:`w-4 h-4 object-contain ${e2}`}):(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-text-muted"}),m!==e.id&&(0,n.jsx)("span",{className:`absolute -bottom-0.5 -right-0.5 w-1.5 h-1.5 rounded-full term-dot ${t.cls}${t.pulse?` pulse-${t.pulse}`:""}`,style:{background:t.dot}})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",children:e.name||"Terminal"}),e.hostLabel&&(0,n.jsx)("span",{className:"shrink-0 text-[10px] text-text-muted",children:e.hostLabel})]},e.id)})]})}):(0,n.jsx)(cu,{wide:!0,title:`Picked Elements (${e.length})`,onClose:a,footer:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),o("sessions")},disabled:!e.length,className:"flex-1 py-1.5 bg-brand-500 hover:bg-brand-600 disabled:opacity-40 disabled:pointer-events-none text-white rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors",children:[(0,n.jsx)(el.Vn,{size:13}),"Send"]}),(0,n.jsxs)("button",{onClick:j,disabled:!e.length,className:"flex-1 py-1.5 bg-surface-2 hover:bg-surface-3 disabled:opacity-40 disabled:pointer-events-none text-text rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors",children:[u?(0,n.jsx)(el.aJ,{size:13,className:"text-emerald-500"}):(0,n.jsx)(el.QR,{size:13}),u?"Copied":"Copy"]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),l?.()},className:"p-2 text-text-muted hover:text-red-500 rounded-brand transition-colors",title:"Clear all",children:(0,n.jsx)(el.TB,{size:14})})]}),children:(0,n.jsxs)("div",{className:"flex flex-col gap-2",children:[e.map((e,t)=>(0,n.jsxs)("div",{className:"p-2 rounded-brand bg-surface-2 border border-border-subtle flex items-start justify-between gap-2 text-xs",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsxs)("span",{className:"font-semibold text-text",children:[t+1,"."]}),(0,n.jsx)("span",{className:"font-mono text-brand-500 font-medium",children:e.tag}),(0,n.jsx)("span",{className:"font-mono text-text-muted truncate",children:e.selector||e.tag})]}),e.text&&(0,n.jsx)("div",{className:"text-text-muted truncate",children:e.text})]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s?.(t)},className:"p-1 text-text-muted hover:text-red-500 rounded shrink-0",title:"Remove",children:(0,n.jsx)(el.X,{size:12})})]},`${e.selector}-${t}`)),(0,n.jsx)("textarea",{value:c,onChange:e=>d(e.target.value),placeholder:"Add a prompt for the receiving session…",rows:2,className:"mt-1 p-2 bg-surface-2 border border-border-subtle rounded-brand text-xs text-text placeholder-text-muted focus:outline-none focus:border-brand-500 resize-none"})]})})}function cj(e){let t=String(e||"").trim();if(!t)return null;if(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(t)||/^(about|data|chrome|javascript|mailto|view-source):/i.test(t))return{url:t,isSearch:!1};let s=t.split(/[/?#\s]/)[0].replace(/:\d+$/,""),n=/^(\d{1,3}\.){3}\d{1,3}$/.test(s)||/^\[[0-9a-fA-F:]+\]$/.test(s);return s&&(n||"localhost"===s||/^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/.test(s))?{url:`https://${t}`,isSearch:!1}:{url:"https://www.google.com/search?q="+encodeURIComponent(t),isSearch:!0}}let ck=[],cN=[{label:"Fit (follow pane)",w:null,h:null},{label:"Mobile 375\xd7667",w:375,h:667,mobile:!0},{label:"Tablet 768\xd71024",w:768,h:1024},{label:"Desktop 1120\xd7780",w:1120,h:780}],cC=e=>e.stopPropagation(),cS={Enter:"enter",Tab:"tab",Escape:"escape",Backspace:"backspace",Delete:"delete",ArrowUp:"arrowup",ArrowDown:"arrowdown",ArrowLeft:"arrowleft",ArrowRight:"arrowright",Home:"home",End:"end",PageUp:"pageup",PageDown:"pagedown"};function cT({busRef:e,connected:t=!1,onBack:s,profile:l="default",onProfileChange:a,workspaceId:i="default"}){let o,c,d,{t:x}=(0,eu.s)(),m=co(e,l),p=i||"default",f=so(e=>e.tabsByWorkspace[p]??ck),h=so(e=>e.activeByWorkspace[p]||null),b=so(e=>e.setActive),g=so(e=>e.setWindowFor),v=ci((0,u.d)(e=>e.connectionMode)),[y,w]=(0,r.useState)(""),[j,k]=(0,r.useState)(!1),[N,C]=(0,r.useState)(""),[S,T]=(0,r.useState)(0),[R,E]=(0,r.useState)(null),$=(0,r.useRef)(R);(0,r.useEffect)(()=>{$.current=R},[R]);let[z,M]=(0,r.useState)(null),[P,A]=(0,r.useState)(!1),[I,D]=(0,r.useState)(null),[L,B]=(0,r.useState)(null),[F,K]=(0,r.useState)([]),[O,W]=(0,r.useState)(!1),[_,H]=(0,r.useState)(!1),[U,q]=(0,r.useState)(null),[X,V]=(0,r.useState)(!1),[J,G]=(0,r.useState)(!1),[Y,Z]=(0,r.useState)(null),[Q,ee]=(0,r.useState)({back:!1,forward:!1}),[et,es]=(0,r.useState)("default"),[en,er]=(0,r.useState)(null),[ea,ei]=(0,r.useState)(null),[eo,ec]=(0,r.useState)(null),[ex,em]=(0,r.useState)(!1),[ep,ef]=(0,r.useState)({open:!1,items:[],idx:-1}),[eh,eb]=(0,r.useState)(!1),[eg,ev]=(0,r.useState)(null),[ey,ew]=(0,r.useState)([]),[ej,ek]=(0,r.useState)(!1),[eN,eC]=(0,r.useState)(null),[eS,eT]=(0,r.useState)(null),[eR,eE]=(0,r.useState)(null),[e$,ez]=(0,r.useState)(null),eM=(0,r.useRef)(null),eP=(0,r.useRef)(null),eA=(0,r.useRef)(null),eI=(0,r.useRef)({bytes:0,mark:0,applied:0}),eD=(0,r.useRef)(null),eL=(0,r.useRef)(null),eB=(0,r.useRef)(null),eF=(0,r.useRef)(null),eK=(0,r.useRef)(!1),eO=(0,r.useRef)(null),eW=(0,r.useRef)(null),e_=(0,r.useRef)(null),eH=(0,r.useRef)(new Map),eU=(0,r.useRef)(null),eq=(0,r.useRef)(null),eX=(0,r.useRef)(!1),eV=f.find(e=>e.id===h)||f.find(e=>e.active)||f[0]||null,eJ=eV?.id||null,[eG,eY]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=window.matchMedia("(max-width: 767px)"),t=()=>eY(e.matches);return t(),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]);let eZ=!eG&&eJ&&f.find(e=>e.openerId===eJ&&e.id!==eJ)||null,eQ=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=eQ.current;eQ.current=eZ?.id||null,e&&e!==eZ?.id&&T(e=>e+1)},[eZ?.id]);let[e0,e1]=(0,r.useState)(null);e0!==eJ&&(e1(eJ),w(eV?.url&&!/^about:blank$/.test(eV.url)?eV.url:""),ew([]));let e2=eV?.url&&!/^about:blank$/.test(eV.url)?eV.url:null;(0,r.useEffect)(()=>{e2&&document.activeElement!==eD.current&&w(e2)},[e2]),(0,r.useEffect)(()=>{let s,n,r=e?.current;if(!t||!r?.emit||!eJ)return;let a=!1,i=eA.current?.getBoundingClientRect(),o=0,c=eJ;return eP.current=eJ,s=cl(v),n={targetId:eJ,profile:l,width:Math.round(z?.width||i?.width||720),height:Math.round(z?.height||i?.height||1280),mobile:!!z?.mobile,scale:s.scale,quality:$.current||s.quality},r.emit("browser:stream.start",n,e=>{e?.ok&&e.targetId&&(c=e.targetId,eP.current=e.targetId,e.targetId!==eJ&&b(p,e.targetId)),e?.ok&&e.quality&&E(e.quality),e?.ok||a||!(o<3)||setTimeout(()=>{a||T(e=>e+1)},1500*(o+=1))}),()=>{a=!0;let e=eP.current||c||eJ;r.emit("browser:stream.stop",{targetId:e})}},[e,t,eJ,S,z,l,v,b,p]);let{canvasRef:e5,frame:e3,frameRef:e4}=cc({busRef:e,connected:t,targetId:eJ,onPainted:(e,t)=>{eI.current.bytes+=t,em(!1)}});(0,r.useEffect)(()=>{_&&q(e5.current?.toDataURL("image/jpeg",.9)||null)},[_,e5,e3]),(0,r.useEffect)(()=>{let e=eI.current;e.mark=Date.now();let t=12e6*(v?2:1),s=setInterval(()=>{let s=Date.now(),n=e.bytes;e.bytes=0,e.mark=s,n>t&&s-e.applied>3e3&&(e.applied=s,E(e=>Math.max(55,(e??85)-15)))},3e3);return()=>clearInterval(s)},[v,eJ]),(0,r.useEffect)(()=>{let t=()=>{document.hidden?e?.current?.emit?.("browser:stream.stop",{targetId:eJ}):T(e=>e+1)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[e,eJ]),(0,r.useEffect)(()=>{t&&m("warm")},[t,m]);let e6=!eV?.url||/^about:blank$/.test(eV.url||"");(0,r.useEffect)(()=>{if(!t||!(e6||!eJ))return;let s=e?.current;s?.emit&&s.emit("getLocalSites",e=>{Array.isArray(e?.sites)&&eE(e.sites)})},[e,t,e6,eJ]),(0,r.useEffect)(()=>()=>{tt.current?.timer&&clearTimeout(tt.current.timer),eF.current&&clearTimeout(eF.current),eq.current&&clearTimeout(eq.current),eB.current&&clearTimeout(eB.current),eO.current&&clearTimeout(eO.current)},[]),(0,r.useEffect)(()=>{let t=e?.current;if(!t?.on||!eJ)return;let s=e=>{e?.targetId===eJ&&es(e.cursor||"default")};return t.on?.("browser:cursor",s),()=>{t.off?.("browser:cursor",s),es("default")}},[e,eJ]);let e8=(0,r.useCallback)(t=>{eJ&&t.length&&e?.current?.emit?.("browser:input",{targetId:eJ,events:t,profile:l})},[e,eJ]),e9=(0,r.useCallback)((e,t)=>{let s=e5.current,n=e4.current?.meta;if(!s)return{x:0,y:0};let r=s.getBoundingClientRect();if(!r.width||!r.height)return{x:0,y:0};let l=n?.deviceWidth||r.width,a=n?.deviceHeight||r.height,i=Math.round((e-r.left)/r.width*l),o=Math.round((t-r.top)/r.height*a);return{x:Math.max(0,Math.min(l,i)),y:Math.max(0,Math.min(a,o))}},[]),e7=(0,r.useCallback)(e=>e9(e.clientX,e.clientY),[e9]),te=!!e3;(0,r.useLayoutEffect)(()=>{let e=()=>{let e=e5.current,t=eA.current;if(!e||!t)return ez(null);let s=e.getBoundingClientRect(),n=t.getBoundingClientRect();if(!s.width||!s.height)return ez(null);let r={left:s.left-n.left,top:s.top-n.top,width:s.width,height:s.height};ez(e=>e&&.5>Math.abs(e.left-r.left)&&.5>Math.abs(e.top-r.top)&&.5>Math.abs(e.width-r.width)&&.5>Math.abs(e.height-r.height)?e:r)};e();let t=new ResizeObserver(e);return eA.current&&t.observe(eA.current),e5.current&&t.observe(e5.current),()=>t.disconnect()},[te]);let tt=(0,r.useRef)(null),ts=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=eA.current;if(!e)return;let t=null,s=new ResizeObserver(()=>{let s=e.getBoundingClientRect(),n=ts.current;ts.current={w:Math.round(s.width),h:Math.round(s.height)},n&&(clearTimeout(t),t=setTimeout(()=>{Math.abs(s.width-n.w)+Math.abs(s.height-n.h)>24&&T(e=>e+1)},300))});return s.observe(e),()=>{clearTimeout(t),s.disconnect()}},[]);let tn=e=>e?.selector||e?.tag||"element",tr=e=>{e&&ew(t=>{let s=t.findIndex(t=>tn(t)===tn(e));return s>=0?t.filter((e,t)=>t!==s):[...t,e]})},tl=(0,r.useRef)(!1);(0,r.useEffect)(()=>{!t||!eJ||(ey.length||tl.current)&&(tl.current=ey.length>0,m("pick.mark",{targetId:eJ,selectors:ey.map(e=>e.selector).filter(Boolean)}))},[ey,t,eJ,m]),(0,r.useEffect)(()=>{if(t&&eJ)return()=>{tl.current&&(tl.current=!1,m("pick.mark",{targetId:eJ,selectors:[]}))}},[t,eJ,m]);let ta=async(e,t)=>{let s=e9(e,t),n=await m("inspect",{targetId:eJ,x:s.x,y:s.y});er({x:e,y:t,element:n?.ok?n.element:null})},ti=()=>{eF.current&&(clearTimeout(eF.current),eF.current=null)},to=e=>{if("pick"===I&&eM.current){let t=eM.current;if(eM.current=null,eC(null),t.moved){let s=e9(t.sx,t.sy),n=e7(e),r=Math.min(s.x,n.x),l=Math.min(s.y,n.y),a=Math.abs(s.x-n.x),i=Math.abs(s.y-n.y);a>=4&&i>=4&&m("pick.rect",{targetId:eJ,x:r,y:l,width:a,height:i}).then(e=>{var t;e?.ok&&Array.isArray(e.elements)&&Array.isArray(t=e.elements)&&t.length&&ew(e=>{let s=new Set(e.map(tn)),n=t.filter(e=>e&&!s.has(tn(e)));return n.length?[...e,...n]:e})})}else{let t=e7(e);m("inspect",{targetId:eJ,x:t.x,y:t.y}).then(e=>{e?.ok&&e.element&&tr(e.element)})}return}if("touch"===e.pointerType){if(eH.current.delete(e.pointerId),eH.current.size<2&&eU.current&&(eU.current.timer&&clearTimeout(eU.current.timer),eU.current=null),ti(),!eK.current&&!eU.current){let t=e_.current;if(!t||t.streaming)e8([{t:"touch",type:"end"}]);else if("pick"===I&&"pointercancel"!==e.type){let t=e9(e.clientX,e.clientY);m("inspect",{targetId:eJ,x:t.x,y:t.y}).then(e=>{e?.ok&&e.element&&tr(e.element)})}}e_.current=null,eK.current=!1;return}if(ti(),I||!eL.current||!e4.current)return;eL.current=null;let t=e7(e),s=2===e.button?"right":1===e.button?"middle":"left",n=Date.now(),r=eW.current;if(eW.current={t:n,x:e.clientX,y:e.clientY},r&&n-r.t<350&&Math.abs(e.clientX-r.x)+Math.abs(e.clientY-r.y)<20){eW.current=null,e8([{t:"pointer",type:"press",x:t.x,y:t.y,button:s,clickCount:2},{t:"pointer",type:"release",x:t.x,y:t.y,button:s,clickCount:2}]);return}e8([{t:"pointer",type:"release",x:t.x,y:t.y,button:s}])};(0,r.useEffect)(()=>{let e=eA.current;if(!e||!eJ)return;let t=e=>{if(!e4.current)return;e.preventDefault();let t=e9(e.clientX,e.clientY),s=tt.current||(tt.current={x:t.x,y:t.y,deltaX:0,deltaY:0,ctrlKey:!1});s.x=t.x,s.y=t.y,s.deltaX+=e.deltaX,s.deltaY+=e.deltaY,s.ctrlKey=s.ctrlKey||e.ctrlKey,s.timer||(s.timer=setTimeout(()=>{s.timer=null,e8([{t:"wheel",x:s.x,y:s.y,deltaX:s.deltaX,deltaY:s.deltaY,ctrlKey:s.ctrlKey}]),s.deltaX=0,s.deltaY=0,s.ctrlKey=!1},50))};return e.addEventListener("wheel",t,{passive:!1}),()=>e.removeEventListener("wheel",t)},[eJ,I,e8,e9]);let tc=()=>{N&&(e8([{t:"text",text:N}]),C(""))},td=async e=>{let t=cj(String(e??y))?.url;if(t&&!eX.current){eX.current=!0;try{(0,ed.e)(),ef({open:!1,items:[],idx:-1}),ec(null),em(!0);let e=so.getState().tabsByWorkspace[p]||[],s=eJ&&e.some(e=>e.id===eJ),n=s?null:`boot_${Date.now()}`;if(n){let e=so.getState();e.setTabs(p,[...e.tabsByWorkspace[p]||[],{id:n,url:t,title:"",booting:!0}]),b(p,n)}let r=s?await m("go",{targetId:eJ,url:t}):await m("open",{url:t});if(em(!1),n){let e=so.getState(),t=(e.tabsByWorkspace[p]||[]).filter(e=>e.id!==n);r?.ok&&r.id&&!t.some(e=>e.id===r.id)&&t.push({id:r.id,url:r.url,title:""}),e.setTabs(p,t),e.setActive(p,r?.ok&&r.id||t[t.length-1]?.id||null)}if(r?.ok&&r.id){b(p,r.id),null!=r.windowId&&g(p,r.windowId);let e=so.getState().tabsByWorkspace[p]||[];e.some(e=>e.id===r.id)||so.getState().setTabs(p,[...e,{id:r.id,url:r.url,title:""}])}r&&!r.ok?ec({url:t,error:r.error||"Navigation failed"}):r?.ok&&r.error&&ec({url:t,error:r.error}),tu()}finally{eX.current=!1}}},tu=(0,r.useCallback)(async()=>{if(!eJ)return;let e=await m("nav",{targetId:eJ});e?.ok&&ee({back:!!e.back,forward:!!e.forward})},[m,eJ]);(0,r.useEffect)(()=>{let e=setTimeout(tu,0);return()=>clearTimeout(e)},[tu]);let tx=async()=>{eV?.url&&await navigator.clipboard?.writeText?.(eV.url).catch(()=>{})},tm=e=>(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),D(e=>"pick"===e?null:"pick"),B(null),eT(null)},disabled:!e3,className:`h-8 shrink-0 flex items-center gap-1.5 px-2 rounded-[6px] text-xs font-medium transition-colors disabled:opacity-40 disabled:pointer-events-none ${"pick"===I?"bg-brand-500 text-white hover:bg-brand-600":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:x("sites.browserPanePickTitle"),children:[(0,n.jsx)(el.We,{size:16}),(0,n.jsx)("span",{children:x("sites.browserPanePick")})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),A(e=>!e)},className:`h-8 shrink-0 flex items-center gap-1.5 px-2 rounded-[6px] text-xs font-medium transition-colors ${z?"bg-brand-500 text-white hover:bg-brand-600":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:x("sites.browserPaneDeviceTitle"),children:[(0,n.jsx)(el.wO,{size:16}),(0,n.jsx)("span",{children:z?`${z.width}\xd7${z.height}`:x("sites.browserPaneDevice")})]}),P&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-10",onClick:()=>A(!1)}),(0,n.jsx)("div",{className:`absolute z-20 flex flex-col p-1 rounded-xl card-elev animate-in fade-in duration-100 min-w-[170px] ${e?"bottom-10 right-0":"top-10 right-0"}`,children:cN.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),M(e.w?{width:e.w,height:e.h,mobile:!!e.mobile}:null),e.w?m("viewport",{targetId:eJ,width:e.w,height:e.h,mobile:!!e.mobile}):m("viewport",{targetId:eJ,reset:!0}),T(e=>e+1),A(!1)},className:`text-left px-2.5 py-1.5 rounded-brand text-xs transition-colors ${(e.w?z?.width===e.w:!z)?"bg-surface-3 text-text font-medium":"text-text-muted hover:bg-surface-2 hover:text-text"}`,children:e.label},e.label))})]})]})]});return(0,n.jsxs)("div",{className:"absolute inset-0 z-20 flex flex-col bg-surface text-text transition-all duration-300 ease-out animate-in slide-in-from-bottom",children:[(0,n.jsxs)("div",{className:"shrink-0 relative z-30 flex items-center gap-1 md:gap-2 border-b border-border-subtle bg-surface/95 px-2 md:px-3 py-1.5",children:[(0,n.jsx)("button",{onClick:()=>{tu(),m("back",{targetId:eJ})},disabled:!Q.back,className:"h-7 w-7 shrink-0 flex items-center justify-center rounded-[6px] text-text-muted hover:text-text hover:bg-surface-2 disabled:opacity-40 disabled:pointer-events-none transition-colors",title:x("sites.goBack"),children:(0,n.jsx)(el.JG,{size:16})}),(0,n.jsx)("button",{onClick:()=>{tu(),m("forward",{targetId:eJ})},disabled:!Q.forward,className:"h-7 w-7 shrink-0 flex items-center justify-center rounded-[6px] text-text-muted hover:text-text hover:bg-surface-2 disabled:opacity-40 disabled:pointer-events-none transition-colors",title:x("sites.goForward"),children:(0,n.jsx)(el.c_,{size:16})}),(0,n.jsx)("button",{onClick:e=>{em(!0),tu(),m("reload",{targetId:eJ,ignoreCache:e.shiftKey})},onContextMenu:e=>{e.preventDefault(),ei({x:e.clientX,y:e.clientY})},disabled:!eJ,className:"h-7 w-7 shrink-0 flex items-center justify-center rounded-[6px] text-text-muted hover:text-text hover:bg-surface-2 disabled:opacity-40 disabled:pointer-events-none transition-colors",title:`${x("editor.reload")} \xb7 shift = hard`,children:ex?(0,n.jsx)(el.kr,{size:16,className:"animate-spin"}):(0,n.jsx)(el.kt,{size:16})}),(0,n.jsxs)("form",{className:"relative flex min-w-0 flex-1 items-center",onSubmit:e=>{e.preventDefault(),td()},children:[(0,n.jsxs)("div",{className:"flex w-full items-center gap-2 rounded-xl border border-border-subtle bg-bg px-3 py-1 shadow-sm",children:[(0,n.jsx)(el.qz,{size:15,className:"shrink-0 text-text-muted"}),(0,n.jsx)("input",{ref:eD,type:"text",inputMode:"url",value:y,onFocus:e=>e.target.select(),onChange:e=>{var t;let s;w(e.target.value),t=e.target.value,eq.current&&clearTimeout(eq.current),(s=t.trim())?eq.current=setTimeout(async()=>{let e=await m("history.search",{q:s}),t=e?.ok&&Array.isArray(e.items)?e.items:[],n=cj(s),r=n?.isSearch?[{isSearch:!0,url:n.url,title:`${x("sites.browserPaneSearchFor")} "${s}"`}]:[],l=new Set(r.map(e=>e.url)),a=[];for(let e of t)l.has(e.url)||(l.add(e.url),a.push({url:e.url,title:e.title||e.url,subtitle:e.title?e.url:null}));ef({open:!0,items:[...r,...a],idx:0})},150):ef({open:!1,items:[],idx:-1})},onKeyDown:e=>{if(ep.open&&ep.items.length){if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();let t="ArrowDown"===e.key?1:-1;ef(e=>({...e,idx:(e.idx+t+e.items.length)%e.items.length}));return}if("Escape"===e.key)return void ef({open:!1,items:[],idx:-1});if("Enter"===e.key&&ep.idx>=0){e.preventDefault(),td(ep.items[ep.idx].url);return}}"Enter"===e.key&&(e.preventDefault(),td())},onBlur:()=>{setTimeout(()=>ef(e=>({...e,open:!1})),150);let e=eV?.url&&!/^about:blank$/.test(eV.url)?eV.url:"";setTimeout(()=>{e&&eD.current?.value!==e&&w(e)},200)},placeholder:x("sites.browserPaneSearchOrUrl"),spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",className:"w-full bg-transparent border-0 px-0 text-sm text-text placeholder-text-muted focus:outline-none focus:ring-0"})]}),(0,n.jsx)(cg,{items:ep.open?ep.items:[],activeIdx:ep.idx,onHover:e=>ef(t=>({...t,idx:e})),onPick:e=>{w(e.url),td(e.url)}})]}),!eG&&(0,n.jsx)("div",{className:"shrink-0 flex items-center gap-1 pl-2 border-l border-border-subtle",children:tm(!1)}),(0,n.jsxs)("button",{onClick:()=>{Z(null),G(!0)},className:"h-7 shrink-0 flex items-center gap-1.5 px-1.5 rounded-[6px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors",title:l,children:[(0,n.jsx)(n5,{name:l,size:16}),(0,n.jsx)("span",{className:"hidden md:inline text-[11px] font-medium max-w-[80px] truncate",children:l})]})]}),(0,n.jsxs)("div",{ref:eA,tabIndex:0,onKeyDown:e=>{if((e.metaKey||e.ctrlKey)&&"l"===e.key.toLowerCase()){e.preventDefault(),eD.current?.focus();return}if("Escape"===e.key&&I)return void D(null);if(!e4.current||I||e.ctrlKey||e.metaKey||e.altKey)return;let t=cS[e.key];t?(e.preventDefault(),e8([{t:"key",key:t}])):1===e.key.length&&(e.preventDefault(),e8([{t:"text",text:e.key}]))},onPointerDown:e=>{if(!e4.current||e.button>2)return;if((0,ed.e)(),"pick"===I&&"touch"!==e.pointerType){eM.current={sx:e.clientX,sy:e.clientY,moved:!1};return}if(I&&"pick"!==I){let t=e7(e),s={x:e.clientX,y:e.clientY};m("inspect",{targetId:eJ,x:t.x,y:t.y}).then(e=>{e?.ok&&e.element&&(eb("annotate"===I),ev("annotate"===I?s:null),B(e.element))});return}if("touch"===e.pointerType){if(eH.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),2===eH.current.size){ti(),eK.current=!0,e8([{t:"touch",type:"end"}]),eU.current={dist:cd(eH.current)};return}ti(),eK.current=!1;let t=e7(e);if(e_.current={x:e.clientX,y:e.clientY,page:t,streaming:"pick"!==I},"pick"===I)return;e8([{t:"touch",type:"start",points:[t]}]),eF.current=setTimeout(()=>{eF.current=null,eK.current=!0,e8([{t:"touch",type:"end"}]);let e=eH.current.values().next().value;e&&ta(e.x,e.y)},550);return}eL.current={sx:e.clientX,sy:e.clientY,moved:!1};let t=e7(e);e8([{t:"pointer",type:"press",x:t.x,y:t.y,button:2===e.button?"right":1===e.button?"middle":"left"}])},onPointerMove:e=>{if("pick"===I&&eM.current){let t=eM.current;if(!t.moved&&Math.abs(e.clientX-t.sx)+Math.abs(e.clientY-t.sy)>8&&(t.moved=!0),t.moved){let s=eA.current?.getBoundingClientRect();s&&eC({left:Math.min(t.sx,e.clientX)-s.left,top:Math.min(t.sy,e.clientY)-s.top,width:Math.abs(e.clientX-t.sx),height:Math.abs(e.clientY-t.sy)})}return}if("touch"===e.pointerType){if(!eH.current.has(e.pointerId))return;if(eH.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),eU.current&&eH.current.size>=2){let e=cd(eH.current),t=eU.current.dist-e;if(eU.current.dist=e,Math.abs(t)>1&&!eU.current.timer){let[e,s]=[...eH.current.values()],n=e9((e.x+s.x)/2,(e.y+s.y)/2);eU.current.timer=setTimeout(()=>{eU.current&&(eU.current.timer=null)},40),e8([{t:"wheel",x:n.x,y:n.y,deltaX:0,deltaY:Math.round(4*t),ctrlKey:!0}])}return}let t=e_.current,s=t&&Math.abs(e.clientX-t.x)+Math.abs(e.clientY-t.y)>10;if(s&&ti(),t&&!t.streaming){if(!s)return;t.streaming=!0,e8([{t:"touch",type:"start",points:[t.page]}])}e8([{t:"touch",type:"move",points:[e7(e)]}]);return}if(eL.current&&e4.current){let t=eL.current;Math.abs(e.clientX-t.sx)+Math.abs(e.clientY-t.sy)>8&&(t.moved=!0,ti()),t.moved&&!eB.current&&(eB.current=setTimeout(()=>{eB.current=null;let t=e7(e);e8([{t:"pointer",type:"move",x:t.x,y:t.y,drag:!0}])},30));return}!e4.current||eO.current||(eO.current=setTimeout(()=>{eO.current=null;let t=e7(e);"pick"===I?m("inspect",{targetId:eJ,x:t.x,y:t.y}).then(e=>{let t=e?.ok&&e.element?e.element.rect:null;if(!t||!t.width)return eT(null);let s=e4.current?.meta||{},n=s.deviceWidth||0,r=s.deviceHeight||0;eT(n&&r&&t.width*t.height/(n*r)>.6?null:t)}):I||e8([{t:"pointer",type:"move",x:t.x,y:t.y}])},80))},onPointerUp:to,onPointerCancel:to,onContextMenu:e=>{e.preventDefault(),ta(e.clientX,e.clientY)},onPointerLeave:()=>{eT(null),eO.current&&(clearTimeout(eO.current),eO.current=null)},style:{cursor:I?"crosshair":et},className:"flex-1 min-h-0 bg-black relative overflow-hidden outline-none touch-none select-none flex items-center justify-center",children:[(0,n.jsx)("canvas",{ref:e5,width:e3?.w||16,height:e3?.h||16,className:`max-w-full max-h-full object-contain pointer-events-none ${e3?"":"opacity-0"}`}),eS&&"pick"===I&&e3&&e$&&(c=(o=e3.meta||{}).deviceWidth,d=o.deviceHeight,c&&d&&eS.width?(0,n.jsx)("div",{className:"absolute pointer-events-none z-[6] rounded-[3px] border-2 border-amber-400 bg-amber-400/15 shadow-[0_0_0_1px_rgba(0,0,0,0.4)]",style:{left:e$.left+eS.x/c*e$.width,top:e$.top+eS.y/d*e$.height,width:eS.width/c*e$.width,height:eS.height/d*e$.height}}):null),eN&&(0,n.jsx)("div",{className:"absolute pointer-events-none border border-brand-400 bg-brand-500/15 rounded-[2px] z-[6]",style:{left:eN.left,top:eN.top,width:eN.width,height:eN.height}}),eG&&(0,n.jsx)("div",{className:"absolute bottom-3 left-3 z-10 flex items-center gap-0.5 rounded-full bg-surface/90 backdrop-blur shadow-[0_2px_10px_rgba(0,0,0,0.4)] p-0.5",onPointerDown:cC,onPointerMove:cC,onPointerUp:cC,onPointerCancel:cC,onContextMenu:cC,children:tm(!0)}),("pick"===I||ey.length>0)&&!ej&&(0,n.jsxs)("div",{className:"absolute bottom-3 right-3 z-10 flex items-center gap-1.5 rounded-full shadow-xl p-0.5",onPointerDown:cC,onPointerMove:cC,onPointerUp:cC,onPointerCancel:cC,onContextMenu:cC,children:[ey.length>0?(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ek(!0)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-brand-500 hover:bg-brand-600 text-white text-xs font-medium shadow-md transition-colors",children:[(0,n.jsx)(el.We,{size:13}),(0,n.jsx)("span",{children:`${ey.length} picked — Send`})]}):(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-surface/95 text-text border border-border-subtle text-xs font-medium backdrop-blur",children:[(0,n.jsx)(el.We,{size:13,className:"text-brand-500"}),(0,n.jsx)("span",{children:"Pick elements"})]}),"pick"===I&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),D(null)},className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface/90 hover:bg-surface text-text-muted hover:text-text border border-border-subtle transition-colors",title:"Exit pick mode",children:(0,n.jsx)(el.X,{size:12})})]}),!t&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center text-sm text-text-muted bg-surface",children:x("sites.browserPaneNotConnected")}),t&&(!eJ||e6)&&null!==eR&&eR.length>0&&(0,n.jsx)("div",{className:"absolute inset-0 z-[7] overflow-y-auto bg-surface",children:(0,n.jsx)("div",{className:"pt-[14vh] flex flex-wrap justify-center gap-x-1 gap-y-5 px-6 max-w-2xl mx-auto",children:eR.map(e=>{let t=e.name&&!/^localhost:\d+$/.test(e.name)?e.name:null;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),td(e.url)},className:"group flex w-[84px] flex-col items-center gap-1.5 p-2 rounded-lg hover:bg-surface-2/70 transition-colors",title:e.url,children:[(0,n.jsx)("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-white text-[13px] font-bold font-mono",style:{backgroundColor:(e=>{let t=0;for(let s of String(e))t=(31*t+s.charCodeAt(0))%360;return`hsl(${t} 55% 45%)`})(e.port)},children:e.port}),(0,n.jsxs)("span",{className:"text-xs text-text font-medium font-mono",children:[":",e.port]}),t&&(0,n.jsx)("span",{className:"w-full text-center text-[10px] text-text-muted truncate",children:t})]},e.port)})})}),t&&eJ&&!e3&&!eo&&(0,n.jsxs)("button",{onClick:()=>T(e=>e+1),className:"absolute inset-0 flex items-center justify-center bg-surface text-text-muted text-sm gap-2",children:[(0,n.jsx)(el.kr,{size:14,className:"animate-spin"})," ",x("sites.browserPaneLoading")]}),eo&&(0,n.jsxs)("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3 p-6 text-center bg-surface",children:[(0,n.jsx)(el.qz,{size:28,className:"text-red-500"}),(0,n.jsx)("p",{className:"text-text text-sm font-medium",children:x("sites.browserPaneLoadError")}),(0,n.jsx)("p",{className:"text-text-muted text-xs font-mono break-all max-w-md",children:eo.url}),(0,n.jsx)("p",{className:"text-text-muted text-[11px]",children:eo.error}),(0,n.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,n.jsx)("button",{onClick:()=>td(eo.url),className:"px-3 py-1.5 bg-brand-500 hover:bg-brand-600 text-white rounded-brand text-xs font-medium",children:x("sites.browserPaneRetry")}),(0,n.jsx)("button",{onClick:()=>navigator.clipboard?.writeText?.(eo.url),className:"px-3 py-1.5 bg-surface-2 hover:bg-surface-3 text-text rounded-brand text-xs font-medium",children:x("sites.browserPaneCopyAddress")}),(0,n.jsx)("button",{onClick:()=>ec(null),className:"px-3 py-1.5 text-text-muted hover:text-text rounded-brand text-xs",children:x("common.close")})]})]})]}),j&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-2 border-t border-border-subtle shrink-0 bg-surface",style:{paddingBottom:"max(0.5rem, env(safe-area-inset-bottom))"},children:[(0,n.jsx)("input",{type:"text",value:N,onChange:e=>C(e.target.value),onKeyDown:e=>"Enter"===e.key&&tc(),placeholder:x("sites.browserPaneSendText"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:"flex-1 px-3 py-1.5 bg-surface-2 rounded-brand text-sm text-text placeholder-text-muted focus:outline-none"}),(0,n.jsx)("button",{onClick:tc,className:"px-3 py-1.5 bg-brand-500 text-white rounded-brand text-sm",children:x("sites.open")})]}),ej&&(0,n.jsx)(cw,{picked:ey,url:eV?.url,invoke:m,targetId:eJ,frameMeta:e3?.meta,onRemoveItem:e=>ew(t=>t.filter((t,s)=>s!==e)),onClear:()=>ew([]),onClose:()=>ek(!1)}),L&&(0,n.jsx)(cx,{element:L,autoFocusNote:eh,at:eg,onAddAnnotation:e=>{K(t=>[...t,e])},onClose:()=>B(null)}),O&&(0,n.jsx)(cm,{annotations:F,onDelete:e=>K(t=>t.filter(t=>t.id!==e)),onClear:()=>K([]),onClose:()=>W(!1)}),_&&(0,n.jsx)(cp,{frameImgSrc:U,onClose:()=>H(!1)}),X&&(0,n.jsx)(cf,{onEval:e=>m("eval",{targetId:eJ,expression:e}),onClose:()=>V(!1)}),J&&(0,n.jsx)(ch,{invoke:m,profile:l,onSelectProfile:a,targetId:eJ,url:eV?.url,initialSection:Y,onCopyUrl:tx,onClose:()=>G(!1)}),(0,n.jsx)(cb,{menu:en,items:[...en?.element?.href?[{label:x("sites.browserCtxOpenNewTab"),icon:(0,n.jsx)(el.Gr,{size:13}),onPick:()=>m("open",{url:en.element.href})},{label:x("sites.browserCtxCopyLink"),icon:(0,n.jsx)(el.vv,{size:13}),onPick:()=>navigator.clipboard?.writeText?.(en.element.href)}]:[],{label:x("sites.browserCtxCopyUrl"),icon:(0,n.jsx)(el.qz,{size:13}),onPick:()=>navigator.clipboard?.writeText?.(eV?.url||"")},{label:x("sites.browserCtxInspect"),icon:(0,n.jsx)(el.We,{size:13}),onPick:()=>en?.element&&B(en.element)},{divider:!0},{label:x("sites.goBack"),icon:(0,n.jsx)(el.JG,{size:13}),onPick:()=>m("back",{targetId:eJ})},{label:x("sites.goForward"),icon:(0,n.jsx)(el.c_,{size:13}),onPick:()=>m("forward",{targetId:eJ})},{label:x("editor.reload"),icon:(0,n.jsx)(el.kt,{size:13}),onPick:()=>m("reload",{targetId:eJ})},{divider:!0},{label:x("sessions.deleteTitle")||"Close tab",icon:(0,n.jsx)(el.X,{size:13}),onPick:()=>m("close",{targetId:eJ})}],onClose:()=>er(null)}),eZ&&(0,n.jsx)(cy,{busRef:e,connected:t,profile:l,targetId:eZ.id,url:eZ.url,onClose:()=>m("close",{targetId:eZ.id})}),(0,n.jsx)(cb,{menu:ea,items:[{label:x("editor.reload"),icon:(0,n.jsx)(el.kt,{size:13}),onPick:()=>m("reload",{targetId:eJ})},{label:x("sites.browserCtxHardReload"),icon:(0,n.jsx)(el.kt,{size:13}),onPick:()=>m("reload",{targetId:eJ,ignoreCache:!0})}],onClose:()=>ei(null)})]})}let cR=(0,b.v)(e=>({pendingDevice:null,setPendingDevice:t=>e({pendingDevice:t}),clearPendingDevice:()=>e({pendingDevice:null}),bump:0,touchBump:()=>e(e=>({bump:e.bump+1}))}));var cE=s(59255);s(20033);let c$=`${m.fm}login`,cz=`${m.fm}download`,cM=(e,t)=>fetch(e,{method:"POST",headers:void 0===t?void 0:{"Content-Type":"application/json"},body:void 0===t?void 0:JSON.stringify(t)}).catch(()=>null);function cP({on:e,onClick:t,title:s,disabled:r}){return(0,n.jsx)("button",{onClick:r?void 0:t,disabled:r,title:s,className:"flex-shrink-0 w-[46px] h-[26px] rounded-full transition-all relative",style:{background:e?"var(--accent)":"rgba(140,145,160,0.35)",border:e?"1px solid transparent":"1px solid rgba(140,145,160,0.55)",opacity:r?.5:1,cursor:r?"not-allowed":"pointer"},children:(0,n.jsx)("span",{className:"absolute top-0.5 w-5 h-5 rounded-full transition-all",style:{left:e?"calc(100% - 22px)":"2px",background:"var(--toggle-knob)",boxShadow:"0 2px 6px rgba(0,0,0,0.4)"}})})}let cA={screenRecording:{label:"Screen Recording",icon:"screenshot_monitor"},accessibility:{label:"Accessibility",icon:"accessibility_new"}};function cI({granted:e,label:t,onRequest:s}){return(0,n.jsxs)("button",{onClick:e?void 0:s,className:"flex items-center gap-1.5 text-[11.5px] px-2.5 py-1 rounded-lg",style:{background:"var(--row-bg)",border:"1px solid var(--border-subtle)",color:e?"var(--success)":"var(--text-muted)",cursor:e?"default":"pointer"},title:e?"":"Click to grant permission",children:[e&&(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:15},children:"check_circle"}),t,!e&&(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:19,color:"var(--text-subtle)"},children:"toggle_off"})]})}function cD({icon:e,onClick:t,title:s,danger:r,busy:l}){return(0,n.jsx)("button",{onClick:l?void 0:t,title:s,disabled:l,className:"glass-btn w-7 h-7 flex items-center justify-center flex-shrink-0",style:{...r?{color:"rgba(255,100,100,0.7)"}:{color:"var(--text-muted)"},...l?{opacity:.6,cursor:"default"}:null},children:(0,n.jsx)("span",{className:`material-symbols-outlined${l?" qr-spin":""}`,style:{fontSize:15},children:e})})}function cL({desktopEnabled:e,onDesktopToggle:t,permissions:s,onRequestPermission:r}){let l=Object.entries(cA),a=l.every(([e])=>!!s?.[e]),i=!a&&!e;return(0,n.jsxs)("div",{className:"row-hover flex items-start gap-4 py-3.5 px-3 -mx-3 rounded-xl",children:[(0,n.jsx)("div",{className:"w-[34px] h-[34px] rounded-[9px] flex items-center justify-center flex-shrink-0 mt-0.5",style:{background:a?e?"rgba(var(--accent-rgb),0.08)":"var(--row-bg)":"rgba(var(--warn-rgb),0.12)",border:`1px solid ${!a?"rgba(var(--warn-rgb),0.3)":e?"rgba(var(--accent-rgb),0.25)":"var(--border-subtle)"}`,color:a?e?"var(--accent)":"var(--text-muted)":"var(--warn)"},children:(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:18},children:a?"desktop_windows":"warning"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("p",{className:"text-[13.5px] font-semibold",style:{color:"var(--text-main)"},children:"Remote Desktop"}),!a&&(0,n.jsx)("span",{className:"text-[10.5px] font-semibold px-2 py-0.5 rounded-full flex-shrink-0",style:{background:"rgba(var(--warn-rgb), 0.15)",color:"var(--warn)"},children:"Permission needed"})]}),l.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap items-center gap-2 mt-2.5",children:l.map(([e,t])=>(0,n.jsx)(cI,{granted:!!s?.[e],label:t.label,onRequest:()=>r(e)},e))})]}),(0,n.jsx)(cP,{on:e,onClick:t,disabled:i,title:i?"Grant permissions":""})]})}function cB({title:e,count:t,first:s,open:r=!0,onToggle:l,children:a}){let i=l?"button":"div";return(0,n.jsxs)("div",{className:s?"":"mt-10",children:[(0,n.jsxs)(i,{onClick:l,className:"w-full flex items-center gap-2.5 font-mono text-[11px] uppercase tracking-[0.12em] pb-2.5 mb-1 text-left",style:{color:"var(--text-subtle)",borderBottom:"1px solid var(--border-subtle)"},children:[e,l&&(0,n.jsx)("span",{className:"material-symbols-outlined tracking-normal",style:{fontSize:16,color:"var(--text-muted)",transform:r?"rotate(180deg)":"none",transition:"transform 0.15s ease"},children:"expand_more"}),null!=t&&(0,n.jsx)("span",{className:"ml-auto tracking-normal",style:{color:"var(--text-muted)"},children:t})]}),r&&a]})}let cF={idle:{icon:"system_update",spin:!1,text:e=>`Version ${e} available`},confirm:{icon:"system_update",spin:!1,text:()=>"Update 9remote? Restarts connection (~1 min)"},updating:{icon:"progress_activity",spin:!0,text:(e,t)=>`Updating… ${t}s`},restarting:{icon:"restart_alt",spin:!0,text:(e,t)=>`Updating 9remote… ${t}s`},ready:{icon:"check_circle",spin:!1,text:()=>"Updated! Reloading…"},timeout:{icon:"warning",spin:!1,text:()=>"Taking longer than expected"}};function cK({version:e,isUpdating:t=!1}){let[s,l]=(0,r.useState)(t?"updating":"idle"),[a,i]=(0,r.useState)(0),[o,c]=(0,r.useState)(t);if(o!==t&&(c(t),t&&l(e=>"restarting"===e||"ready"===e?e:"updating")),(0,r.useEffect)(()=>{let e;if("updating"!==s&&"restarting"!==s)return;let t=Date.now(),n=!1,r=setInterval(()=>i(Math.floor((Date.now()-t)/1e3)),1e3),a=setTimeout(()=>{e=setInterval(async()=>{if(Date.now()-t>9e4){l("timeout"),clearInterval(e);return}try{if(!(await fetch("/api/ui/state",{cache:"no-store"})).ok)throw Error();n&&(l("ready"),clearInterval(e),setTimeout(()=>window.location.reload(),600))}catch{n=!0,l("restarting")}},2e3)},3e3);return()=>{clearInterval(r),clearInterval(e),clearTimeout(a)}},[s]),!e&&!t&&"idle"===s)return null;let d=cF[s],u="updating"===s||"restarting"===s||"ready"===s,x="ready"===s?100:Math.min(1e3*a/9e4*100,95);return u?(0,n.jsx)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",style:{background:"var(--bg-body)"},children:(0,n.jsxs)("div",{className:"text-center mx-4",style:{maxWidth:320},children:[(0,n.jsx)("span",{className:`material-symbols-outlined text-4xl inline-block ${d.spin?"qr-spin":""}`,style:{color:"var(--brand-400)"},children:d.icon}),(0,n.jsx)("div",{className:"text-sm font-semibold mt-3",style:{color:"var(--text-main)"},children:d.text(e,a)}),(0,n.jsx)("div",{className:"mt-4 h-1.5 w-full rounded-full overflow-hidden",style:{background:"var(--surface-2)"},children:(0,n.jsx)("div",{className:"h-full rounded-full transition-all duration-1000 ease-linear",style:{width:`${x}%`,background:"var(--brand-400)"}})}),(0,n.jsxs)("div",{className:"text-xs mt-2",style:{color:"var(--text-subtle)"},children:[a,"s"]})]})}):(0,n.jsxs)("div",{className:"relative px-5 py-2 flex items-center gap-2 border-b",style:{background:"rgba(var(--brand-rgb),0.08)",borderColor:"rgba(var(--brand-rgb),0.2)"},children:[(0,n.jsx)("span",{className:`material-symbols-outlined text-sm flex-shrink-0 ${d.spin?"qr-spin":""}`,style:{color:"var(--brand-400)"},children:d.icon}),(0,n.jsx)("span",{className:"text-xs flex-1",style:{color:"var(--brand-400)"},children:d.text(e,a)}),"idle"===s&&(0,n.jsx)("button",{onClick:()=>l("confirm"),className:"flex-shrink-0 text-xs px-2 py-0.5 rounded font-medium",style:{background:"rgba(var(--brand-rgb),0.15)",color:"var(--brand-400)"},children:"Update"}),"confirm"===s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{l("updating"),cM("/api/update")},className:"flex-shrink-0 text-xs px-2 py-0.5 rounded font-medium",style:{background:"rgba(var(--brand-rgb),0.15)",color:"var(--brand-400)"},children:"Confirm"}),(0,n.jsx)("button",{onClick:()=>l("idle"),className:"flex-shrink-0 text-xs px-2 py-0.5 rounded font-medium",style:{background:"rgba(255,255,255,0.08)",color:"var(--text-muted)"},children:"Cancel"})]}),"timeout"===s&&(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"flex-shrink-0 text-xs px-2 py-0.5 rounded font-medium",style:{background:"rgba(var(--brand-rgb),0.15)",color:"var(--brand-400)"},children:"Reload"})]})}let cO={online:{color:"var(--success)",bg:"rgba(var(--success-rgb),0.14)",label:"Online"},offline:{color:"var(--text-subtle)",bg:"var(--row-bg)",label:"Offline"},pending:{color:"var(--warn)",bg:"rgba(var(--warn-rgb),0.14)",label:"Pending"}};function cW({client:e,onRemove:t,onApprove:s,onLabel:r}){let l=`${e.deviceId.slice(0,8)}...`,a=e.label||l,i=cO[e.status]||cO.offline,o="pending"===e.status,c="online"===e.status?`${e.ip?e.ip+" \xb7 ":""}connected ${e.connectedAt?new Date(e.connectedAt).toLocaleTimeString(void 0,{hour12:!1}):""}`:o?"Waiting for approval":e.approvedAt?`Approved ${new Date(e.approvedAt).toLocaleDateString()}`:"Offline";return(0,n.jsxs)("div",{className:`row-hover flex items-center gap-4 py-3 px-3 -mx-3 rounded-xl ${o?"border border-dashed":""}`,style:o?{borderColor:"rgba(var(--warn-rgb),0.35)"}:{},children:[(0,n.jsx)("div",{className:"w-[34px] h-[34px] rounded-[9px] flex items-center justify-center flex-shrink-0",style:{background:"var(--row-bg)",border:"1px solid var(--border-subtle)"},children:(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:18,color:"var(--text-muted)"},children:/mac|book|laptop|pc|windows|desktop|linux/i.test(a||"")?"laptop_mac":"smartphone"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"text-[13.5px] font-semibold flex items-center gap-2 min-w-0",style:{color:"var(--text-main)"},children:[(0,n.jsx)("span",{className:"truncate",children:a}),(0,n.jsxs)("span",{className:"flex items-center gap-1 text-[10.5px] font-semibold px-2 py-0.5 rounded-full flex-shrink-0",style:{background:i.bg,color:i.color},children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{background:"currentColor"}}),i.label]}),!o&&(0,n.jsx)("button",{onClick:()=>r?.(e),className:"material-symbols-outlined flex-shrink-0",style:{fontSize:14,color:"var(--text-muted)",cursor:"pointer"},title:"Rename this device",children:"edit"})]}),(0,n.jsx)("p",{className:`text-[11.5px] mt-0.5 truncate ${e.ip?"font-mono":""}`,style:{color:"var(--text-muted)"},children:c})]}),o?(0,n.jsx)("button",{onClick:()=>s?.(e),className:"flex-shrink-0 text-[12.5px] font-semibold px-3.5 py-2 rounded-lg btn-primary",title:"Approve this device",children:"Approve"}):(0,n.jsx)("button",{onClick:()=>t(e),className:"glass-btn flex-shrink-0 text-[12px] font-semibold px-3.5 py-2 rounded-lg",style:{color:"var(--text-muted)"},title:"Disconnect and remove this device",children:"online"===e.status?"Disconnect":"Remove"})]})}let c_=["Preparing","Connecting","Tunneling","Verifying","Ready"];function cH({step:e,stepDesc:t}){let s=Math.min(Math.max(e-1,0),c_.length-1);return(0,n.jsxs)("div",{className:"relative z-[1] flex flex-col items-center gap-2 mb-4",children:[(0,n.jsx)("div",{className:"flex items-center",children:c_.map((e,t)=>{let r=t<s,l=t===s;return(0,n.jsxs)("div",{className:"flex items-center",children:[(0,n.jsx)("span",{className:`w-[9px] h-[9px] rounded-full ${l?"chip-blink":""}`,style:{background:r||l?"var(--brand-500)":"var(--row-hover)",border:r||l?"none":"1px solid var(--border)",boxShadow:l?"0 0 8px rgba(var(--brand-rgb),0.7)":void 0}}),t<c_.length-1&&(0,n.jsx)("span",{className:"w-5 h-px",style:{background:r?"var(--brand-500)":"var(--border)"}})]},e)})}),(0,n.jsxs)("span",{className:"text-[11px] font-mono text-center max-w-full truncate",style:{color:"var(--text-subtle)"},children:[c_[s],t?` — ${t}`:""]})]})}function cU({qrUrl:e,oneTimeKey:t,oneTimeKeyExpiresAt:l,permanentKey:a,onGenerateOneTimeKey:i,onRegenerateKey:o}){let c,d,u=(0,r.useRef)(null),[x,m]=(0,r.useState)(()=>Date.now()),[p,f]=(0,r.useState)(null),[h,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(null),y=null!=l?l-x:null,w=null!==y&&y<=0;(0,r.useEffect)(()=>{if(!l)return;let e=setInterval(()=>m(Date.now()),1e3);return()=>clearInterval(e)},[l]),(0,r.useEffect)(()=>{if(!e||w||!u.current)return;let t=!1;return s.e(6276).then(s.t.bind(s,56276,19)).then(({default:s})=>!t&&s.toCanvas(u.current,e,{width:200,margin:1,color:{dark:"#0f1923",light:"#ffffff"}})).catch(()=>{}),()=>{t=!0}},[e,w]);let[j,k]=(0,r.useState)(t),[N,C]=(0,r.useState)(a);j!==t&&(k(t),v(e=>"oneTime"===e?null:e)),N!==a&&(C(a),v(e=>"permanent"===e?null:e)),(0,r.useEffect)(()=>{if(!g)return;let e=setTimeout(()=>v(null),15e3);return()=>clearTimeout(e)},[g]);let S=(e,t)=>{navigator.clipboard.writeText(e).catch(()=>{}),f(t),setTimeout(()=>f(null),2e3)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ec.A,{isOpen:"oneTime"===h,onClose:()=>b(null),onConfirm:()=>{b(null),v("oneTime"),i?.()},title:"New one-time key?",message:"Generate a new one-time key? The current one will expire immediately.",confirmText:"Generate"}),(0,n.jsx)(ec.A,{isOpen:"regen"===h,onClose:()=>b(null),onConfirm:()=>{b(null),v("permanent"),o?.()},title:"Regenerate permanent key?",message:"Regenerate permanent key? All existing sessions will be disconnected.",confirmText:"Regenerate"}),(0,n.jsxs)("div",{className:"relative z-[1] w-full max-w-[380px] flex flex-col items-center",children:[(0,n.jsx)("div",{className:"bg-white p-3.5 rounded-[14px] flex items-center justify-center flex-shrink-0",style:{boxShadow:"var(--qr-plate-shadow)"},children:e&&!w?(0,n.jsx)("canvas",{ref:u}):(0,n.jsx)("div",{className:"w-[200px] h-[200px] grid place-items-center",children:(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:72,color:"#d4d4d8"},children:"qr_code_2"})})}),(0,n.jsxs)("div",{className:"flex flex-col items-center gap-1 mt-4 mb-9",children:[(0,n.jsx)("span",{className:"text-[11.5px] leading-4",style:{color:"var(--text-muted)"},children:"Scan to sign in"}),(0,n.jsxs)("a",{href:c$,target:"_blank",rel:"noopener noreferrer",onClick:e=>cq(e,c$),className:"flex items-center gap-1.5 hover:underline transition-opacity",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-green-400 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm font-bold",style:{color:"var(--accent)"},children:c$.replace(/^https?:\/\//,"")}),(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:14,color:"var(--accent)"},children:"open_in_new"})]})]}),(0,n.jsxs)("div",{className:"w-full flex flex-col gap-1.5",children:[(0,n.jsx)("span",{className:"text-xs font-medium px-0.5",style:{color:"var(--text-muted)"},children:"One-Time Key"}),(0,n.jsxs)("div",{className:"w-full flex items-center gap-2 px-3 py-2.5 rounded-[10px]",style:{background:"var(--row-bg)",border:"1px solid var(--border-subtle)"},children:[(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:16,color:"var(--text-muted)"},children:"timer"}),(0,n.jsx)("span",{className:"flex-1 font-mono font-bold tracking-[0.18em] text-base truncate",style:{color:t&&!w?"var(--accent)":"var(--border)"},children:t&&!w?t:"• • • • • •"}),null!==y&&(0,n.jsx)("span",{className:`text-xs font-mono flex-shrink-0 ${y<=0?"text-red-400":""}`,style:y>0?{color:"var(--text-muted)"}:{},children:y<=0?"Expired":(d=Math.floor((c=Math.floor(y/1e3))/60),`${String(d).padStart(2,"0")}:${String(c%60).padStart(2,"0")}`)}),t&&!w&&(0,n.jsx)(cD,{icon:"oneTime"===p?"check":"content_copy",onClick:()=>S(t,"oneTime"),title:"Copy one-time key"}),(0,n.jsx)(cD,{icon:"refresh",onClick:()=>b("oneTime"),title:"New one-time key",busy:"oneTime"===g})]})]}),(0,n.jsxs)("div",{className:"w-full flex flex-col gap-1.5 mt-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium px-0.5",style:{color:"var(--text-muted)"},children:"Permanent Key"}),(0,n.jsxs)("div",{className:"w-full flex items-center gap-2 px-3 py-2.5 rounded-[10px]",style:{background:"var(--row-bg)",border:"1px solid var(--border-subtle)"},children:[(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:16,color:"var(--text-muted)"},children:"key"}),(0,n.jsx)("span",{className:"flex-1 font-mono text-xs truncate",style:{color:"var(--text-main)"},children:a||"— not set —"}),a&&(0,n.jsx)(cD,{icon:"permanent"===p?"check":"content_copy",onClick:()=>S(a,"permanent"),title:"Copy permanent key"}),(0,n.jsx)(cD,{icon:"autorenew",onClick:()=>b("regen"),title:"Regenerate permanent key",danger:!0,busy:"permanent"===g})]})]})]})]})}function cq(e,t){let s=window.__TAURI__?.opener;s?.openUrl&&(e.preventDefault(),s.openUrl(t).catch(()=>{}))}function cX({icon:e,iconClass:t,title:s,sub:r,href:l}){return(0,n.jsxs)("a",{href:l,target:"_blank",rel:"noopener noreferrer",onClick:e=>cq(e,l),className:"hero-card ad-connect-card",children:[(0,n.jsx)("div",{className:`w-[34px] h-[34px] rounded-[9px] flex items-center justify-center flex-shrink-0 ${t}`,children:"string"==typeof e?(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:18},children:e}):e}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-[13.5px] font-semibold truncate",style:{color:"var(--text-main)"},children:s}),r&&(0,n.jsx)("p",{className:"text-[11px] truncate",style:{color:"var(--text-muted)"},children:r})]}),(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:15,color:"var(--text-subtle)"},children:"open_in_new"})]})}function cV(){return(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.03 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701"})})}function cJ(){return(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M22.018 13.298l-3.919 2.218-3.515-3.493 3.543-3.521 3.891 2.202a1.49 1.49 0 0 1 0 2.594zM1.337.924a1.486 1.486 0 0 0-.112.568v21.017c0 .217.045.419.124.6l11.155-11.087L1.337.924zm12.207 10.065l3.258-3.238L3.45.195a1.661 1.661 0 0 0-.394-.109l10.688 10.803zm0 2.067l-10.83 10.776c.088-.018.172-.047.254-.09l13.317-7.54-2.741-3.146z"})})}function cG(){let[e,t]=(0,r.useState)({step:0,stepDesc:"",tunnelUrl:"",oneTimeKey:"",oneTimeKeyExpiresAt:null,pairingUsed:!1,permanentKey:"",qrUrl:"",tunnelHealth:{status:"unknown",checkedAt:null}}),[s,l]=(0,r.useState)({screenRecording:!1,accessibility:!1}),[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(!0),[m,p]=(0,r.useState)(""),[f,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)([]),[v,y]=(0,r.useState)([]),[w,j]=(0,r.useState)([]),k=cR(e=>e.pendingDevice);cR(e=>e.bump);let[N,C]=(0,r.useState)(!1),[S,T]=(0,r.useState)(!0),[R,E]=(0,r.useState)(!1),[$,z]=(0,r.useState)(null),[M,P]=(0,r.useState)(null),[A,I]=(0,r.useState)(!0),D=(0,r.useRef)(""),L=(0,r.useCallback)(async()=>{try{let[e,t]=await Promise.all([fetch("/api/device/approved"),fetch("/api/device/rejected")]);if(e.ok){let t=await e.json();y(t.devices||[])}if(t.ok){let e=await t.json();j(e.rejected||[])}}catch{}},[]),B=(0,r.useCallback)(()=>{fetch("/api/version",{cache:"no-store"}).then(e=>e.json()).then(e=>{let t=e.version??"";if(t){if(D.current&&D.current!==t)return void window.location.reload();D.current=t}}).catch(()=>{})},[]);(0,r.useEffect)(()=>{if(!(0,x.gJ)())return;let e=!0;fetch("/api/ui/state",{cache:"no-store"}).then(e=>e.json()).then(s=>{e&&s&&(u(!0),t({step:s.step??0,stepDesc:s.stepDesc??"",tunnelUrl:s.tunnelUrl??"",oneTimeKey:s.oneTimeKey??"",oneTimeKeyExpiresAt:s.oneTimeKeyExpiresAt??null,pairingUsed:s.pairingUsed??!1,permanentKey:s.permanentKey??"",qrUrl:s.qrUrl??"",tunnelHealth:s.tunnelHealth??{status:"unknown",checkedAt:null}}),l({screenRecording:s.screenRecording??!1,accessibility:s.accessibility??!1}),s.transport&&i(s.transport),void 0!==s.desktopEnabled&&c(s.desktopEnabled))}).catch(()=>e&&u(!1)),fetch("/api/connections",{cache:"no-store"}).then(e=>e.json()).then(t=>e&&g(t.connections??[])).catch(()=>{}),Promise.resolve().then(L),fetch("/api/device/auto-approve").then(e=>e.json()).then(t=>e&&C(!!t?.enabled)).catch(()=>{}),fetch("/api/remote/enabled").then(e=>e.json()).then(t=>e&&"boolean"==typeof t?.enabled&&T(t.enabled)).catch(()=>{});let s=new EventSource("/api/ui/events");return s.onmessage=e=>{let s;try{s=JSON.parse(e.data)}catch{return}u(!0),"state"===s.type?(B(),t({step:s.step??0,stepDesc:s.stepDesc??"",tunnelUrl:s.tunnelUrl??"",oneTimeKey:s.oneTimeKey??"",oneTimeKeyExpiresAt:s.oneTimeKeyExpiresAt??null,pairingUsed:s.pairingUsed??!1,permanentKey:s.permanentKey??"",qrUrl:s.qrUrl??"",tunnelHealth:s.tunnelHealth??{status:"unknown",checkedAt:null}})):"updateAvailable"===s.type?p(s.version):"updating"===s.type?h(!0):"permissions"===s.type?(l({screenRecording:s.screenRecording,accessibility:s.accessibility}),void 0!==s.desktopEnabled&&c(s.desktopEnabled)):"transport"===s.type?i({signaling:s.signaling,rtcPeers:s.rtcPeers,wsPeers:s.wsPeers,rtcDisabled:s.rtcDisabled}):"connections"===s.type?(g(s.connections??[]),L()):"deviceApproval"===s.type&&"refresh"===s.action?L():"autostart"===s.type||"remote"===s.type&&T(!!s.enabled)},s.onerror=()=>u(!1),s.onopen=()=>{u(!0),B()},()=>{e=!1,s.close()}},[L,B]);let F=(0,r.useRef)(!1);(0,r.useEffect)(()=>{F.current||!e.permanentKey||e.oneTimeKey||e.qrUrl||e.pairingUsed||5===e.step&&(F.current=!0,cM("/api/key/one-time"))},[e.permanentKey,e.oneTimeKey,e.qrUrl,e.pairingUsed,e.step]);let K=async()=>{let e=!o;c(e),await cM("/api/desktop/toggle",{enabled:e})},O=async()=>{let e=await cM("/api/key/one-time");if(!e?.ok)return;let s=await e.json().catch(()=>null);s?.oneTimeKey&&t(e=>({...e,oneTimeKey:s.oneTimeKey,oneTimeKeyExpiresAt:s.expiresAt,qrUrl:s.qrUrl??e.qrUrl}))},W=async()=>{let e=await cM("/api/key/regenerate");if(!e?.ok)return;let s=await e.json().catch(()=>null);s?.permanentKey&&t(e=>({...e,permanentKey:s.permanentKey}))},_=async e=>{let t="pending"===e.status?"/api/device/clear-rejected":"/api/device/remove";await cM(t,{deviceId:e.deviceId}),L()},H=async()=>{let e=!N;C(e);let t=await cM("/api/device/auto-approve",{enabled:e}),s=await t?.json().catch(()=>null);s&&"boolean"==typeof s.enabled&&C(s.enabled)},U=async e=>{await cM("/api/device/approve-rejected",{deviceId:e}),L()},q=async(e,t)=>{await cM("/api/device/label",{deviceId:e,label:t}),L()},X=async()=>{let e=!S;T(e);let t=await cM("/api/remote/enabled",{enabled:e}),s=await t?.json().catch(()=>null);"boolean"==typeof s?.enabled&&T(s.enabled)};if(!(0,x.gJ)())return(0,n.jsx)("div",{className:"h-full grid place-items-center p-6",children:(0,n.jsx)("p",{className:"text-sm text-text-muted text-center",children:"Device pairing is only available in the host's local view."})});let V=e.step>0&&e.step<5?{color:"var(--warn)",label:"connecting",blink:!0}:e.tunnelHealth?.status==="healthy"?{color:"var(--success)",label:"healthy"}:{color:"var(--danger)",label:"down",retry:!0},J=a?.signaling==="connected"?{color:"var(--success)",label:`rtc ${a.rtcPeers||0}`}:{color:"var(--danger)",label:"rtc off"},G=function(e,t,s=[]){let n=new Map;for(let e of t){if(!e.deviceId)continue;let t=n.get(e.deviceId);(!t||e.connectedAt&&e.connectedAt<t.connectedAt)&&n.set(e.deviceId,e)}let r=e.map(e=>{let t=n.get(e.deviceId);return{deviceId:e.deviceId,status:t?"online":"offline",ip:t?.ip||null,connectedAt:t?.connectedAt||null,approvedAt:e.approvedAt||null,label:e.label||""}}),l=s.map(e=>({deviceId:e.deviceId,status:"pending",ip:e.ip||null,connectedAt:null,approvedAt:null})),a={online:0,pending:1,offline:2};return[...r,...l].sort((e,t)=>a[e.status]-a[t.status])}(v,b,w),Y=G.filter(e=>"online"===e.status).length;return(0,n.jsxs)("div",{className:"agent-dashboard h-full w-full relative flex overflow-hidden isolate",style:{background:"var(--bg-body)"},children:[(0,n.jsx)("div",{className:"bg-sq-grid absolute inset-0 pointer-events-none z-[-3]","aria-hidden":"true"}),(0,n.jsx)("div",{className:"bg-light-drift absolute inset-0 pointer-events-none z-[-2]","aria-hidden":"true"}),(0,n.jsxs)("main",{className:"flex-1 min-w-0 grid grid-cols-1 lg:grid-cols-2 overflow-y-auto lg:overflow-hidden",children:[!d&&(0,n.jsx)("div",{className:"col-span-full px-4 py-2 text-center text-xs font-medium",style:{background:"var(--danger)",color:"#fff"},children:"Host unreachable — is the server still running?"}),(0,n.jsxs)("section",{className:"relative flex flex-col p-6 lg:p-10 min-w-0 lg:overflow-y-auto",children:[(0,n.jsx)("div",{className:"pane-hero-glow","aria-hidden":"true"}),(0,n.jsx)("div",{className:"relative z-[1] flex flex-col items-center my-auto",children:S?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("h1",{className:"brand-grad-text text-[30px] lg:text-[34px] font-bold tracking-[-0.03em] leading-[1.05] text-center mb-5",children:"Pair Device"}),e.step>0&&e.step<5&&(0,n.jsx)(cH,{step:e.step,stepDesc:e.stepDesc}),(0,n.jsx)(cU,{qrUrl:e.qrUrl,oneTimeKey:e.oneTimeKey,oneTimeKeyExpiresAt:e.oneTimeKeyExpiresAt,permanentKey:e.permanentKey,onGenerateOneTimeKey:O,onRegenerateKey:W})]}):(0,n.jsxs)("div",{className:"glass-card w-full max-w-[380px] flex flex-col items-center gap-2.5 py-10 px-6",children:[(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:40,color:"var(--text-subtle)"},children:"cloud_off"}),(0,n.jsx)("p",{className:"text-[13.5px] font-semibold text-center",style:{color:"var(--text-main)"},children:"Remote is off"}),(0,n.jsx)("p",{className:"text-xs leading-relaxed text-center",style:{color:"var(--text-muted)"},children:"Turn remote access back on to pair devices."})]})}),(0,n.jsxs)("div",{className:"relative z-[1] mt-5 self-center inline-flex items-center gap-2 px-3 py-1.5 rounded-full flex-shrink-0",style:{background:"var(--row-bg)",border:"1px solid var(--border-subtle)"},children:[S?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0",title:"Cloudflare tunnel",children:[(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:15,color:"var(--text-muted)"},children:"cloud"}),(0,n.jsx)("span",{className:`w-[6px] h-[6px] rounded-full flex-shrink-0${V.blink?" chip-blink":""}`,style:{background:V.color}}),(0,n.jsx)("span",{className:"font-mono text-[11px] truncate",style:{color:"var(--text-muted)"},children:V.label}),V.retry&&(0,n.jsx)("span",{role:"button",title:"Retry tunnel connection",onClick:()=>cM("/api/ui/start"),className:"material-symbols-outlined flex-shrink-0 cursor-pointer",style:{fontSize:14,color:"var(--text-muted)"},children:"refresh"})]}),(0,n.jsx)("span",{className:"w-px h-3.5 flex-shrink-0",style:{background:"var(--border-subtle)"}}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0",title:"WebRTC signaling",children:[(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:15,color:"var(--text-muted)"},children:"hub"}),(0,n.jsx)("span",{className:"w-[6px] h-[6px] rounded-full flex-shrink-0",style:{background:J.color}}),(0,n.jsx)("span",{className:"font-mono text-[11px] truncate",style:{color:"var(--text-muted)"},children:J.label})]})]}):(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:15,color:"var(--text-muted)"},children:"cloud_off"}),(0,n.jsx)("span",{className:"text-[11px] truncate",style:{color:"var(--text-muted)"},children:"Remote off"})]}),(0,n.jsx)(cP,{on:S,onClick:()=>S?E(!0):X(),title:S?"Turn off remote access":"Turn on remote access"})]})]}),(0,n.jsxs)("section",{className:`relative min-w-0 pt-10 pb-11 pr-8 pl-6 lg:pl-14 lg:pr-12 lg:overflow-y-auto transition-opacity duration-300 ${S?"":"opacity-40 pointer-events-none select-none"}`,style:{background:"var(--pane-right-bg)"},children:[(0,n.jsx)(cK,{version:m,isUpdating:f}),(0,n.jsx)(cB,{title:"Connect from",first:!0,children:(0,n.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2.5",children:[(0,n.jsx)(cX,{icon:(0,n.jsx)(cV,{}),iconClass:"ad-tile-apple",title:"iPhone & iPad",sub:"App Store",href:cE.od}),(0,n.jsx)(cX,{icon:(0,n.jsx)(cJ,{}),iconClass:"ad-tile-play",title:"Android",sub:"Google Play",href:cE.JN}),(0,n.jsx)(cX,{icon:"computer",iconClass:"ad-tile-pc",title:"PC & Mac",sub:"All downloads",href:cz}),(0,n.jsx)(cX,{icon:"language",iconClass:"ad-tile-web",title:"Web",sub:"9remote.cc",href:c$})]})}),(0,n.jsx)(cB,{title:"Services",children:(0,n.jsx)(cL,{desktopEnabled:o,onDesktopToggle:K,permissions:s,onRequestPermission:e=>cM("/api/permissions/request",{type:e})})}),(0,n.jsxs)(cB,{title:"Clients",count:G.length>0?`${Y}/${G.length}`:null,open:A||!!k,onToggle:()=>I(e=>!e),children:[(0,n.jsxs)("div",{className:"row-hover flex items-center gap-4 py-3 px-3 -mx-3 rounded-xl",children:[(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:19,color:N?"var(--accent)":"var(--text-muted)"},children:N?"lock_open":"lock"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("p",{className:"text-[13.5px] font-semibold",style:{color:"var(--text-main)"},children:"Auto-approve new devices"})}),(0,n.jsx)(cP,{on:N,onClick:H,title:N?"Disable auto-approve":"Enable auto-approve"})]}),0===G.length?(0,n.jsx)("p",{className:"text-xs text-center py-4",style:{color:"var(--text-muted)"},children:"No clients yet"}):G.map(e=>(0,n.jsx)(cW,{client:e,onRemove:z,onApprove:e=>U(e.deviceId),onLabel:e=>P({...e,draft:e.label||""})},e.deviceId))]})]})]}),(0,n.jsx)(ec.A,{isOpen:R,onClose:()=>E(!1),onConfirm:()=>{E(!1),X()},title:"Turn off remote access?",message:"Turn off remote access? Connected devices will be disconnected immediately.",confirmText:"Turn off"}),(0,n.jsx)(ec.A,{isOpen:!!$,onClose:()=>z(null),onConfirm:()=>{_($),z(null)},title:"Remove device?",message:$?"online"===$.status?`Disconnect and remove device ${$.deviceId.slice(0,8)}...? The client will be disconnected and need approval again next time.`:"pending"===$.status?`Remove pending device ${$.deviceId.slice(0,8)}...? It will need a fresh approval request to connect again.`:`Remove device ${$.deviceId.slice(0,8)}...? It will need approval again next time.`:"",confirmText:$?.status==="online"?"Disconnect & Remove":"Remove"}),M&&(0,n.jsx)(sN,{title:"Rename device",placeholder:`Name for device ${M.deviceId.slice(0,8)}...`,value:M.draft,onChange:e=>P(t=>t?{...t,draft:e}:t),onSubmit:()=>{q(M.deviceId,(M.draft||"").trim()),P(null)},onClose:()=>P(null)})]})}function cY({files:e,loading:t,onFileClick:s,onFolderClick:r,onMoreClick:l,selectedPath:a,gitStatusMap:i={},workspacePath:o}){let{t:c}=(0,eu.s)();return t?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-text-muted",children:c("common.loading")})}):0===e.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-text-muted",children:c("files.emptyFolder")})}):(0,n.jsx)("div",{children:e.map((e,t)=>{var d;let u=i[d=e.path,!o?d:d.replace(o+"/","")],x="folder-changed"===u?"text-yellow-400":O.vs[u]||"";return(0,n.jsxs)("div",{className:`w-full px-4 py-1.5 flex items-center gap-2.5 border-b border-border hover:bg-surface-2 transition ${a===e.path?"bg-surface-2":""}`,children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),"folder"===e.type?r(e):s(e)},className:"flex-1 flex items-center gap-2.5 text-left min-w-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:aE(e,18)}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:`truncate text-sm ${x||"text-text"}`,title:e.name,children:[e.name,u&&"folder-changed"!==u&&(0,n.jsxs)("span",{className:"ml-2 text-xs opacity-70",children:["[",u,"]"]})]}),"folder"!==e.type&&e.sizeFormatted&&(0,n.jsx)("div",{className:"text-text-subtle text-xs",children:e.sizeFormatted})]})]}),l&&(0,n.jsx)("button",{onClick:t=>{let s;(0,ed.e)(),t.stopPropagation(),s=t.currentTarget.getBoundingClientRect(),l?.(e,{x:s.right,y:s.top})},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded transition flex-shrink-0",title:c("menu.settings"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"19",r:"2"})]})}),"folder"===e.type&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),r(e)},className:"p-1 text-text-muted flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]},e.path)})})}function cZ({workspace:e,initialPath:t,fileBus:s,onBack:l,onOpenFile:a,onOpenGit:i,onSetWorkspace:o,onSwitchWorkspace:c,onPathChange:d,isBrowsing:u=!1,hideSwitchWorkspace:x=!1,scope:m=""}){let{t:p}=(0,eu.s)(),[f,h]=(0,r.useState)(t||e),[b,g]=(0,r.useState)([]),[v,y]=(0,r.useState)(!0),[w,j]=(0,r.useState)(""),[k,N]=(0,r.useState)(null),[C,S]=(0,r.useState)(!1),[T,R]=(0,r.useState)("file"),[E,$]=(0,r.useState)(""),[z,M]=(0,r.useState)({isOpen:!1}),[P,A]=(0,r.useState)(null),[I,D]=(0,r.useState)(!1),[L,B]=(0,r.useState)({}),[F,K]=(0,r.useState)(!1),[W,_]=(0,r.useState)(""),[H,U]=(0,r.useState)([]),[q,X]=(0,r.useState)(!1),V=(0,r.useRef)(null),[J]=(0,r.useState)(()=>window.innerWidth>=eJ.jK),G=(0,r.useCallback)(async e=>{if(u){D(!1),B({});return}let t=await af(s,e);D(t.hasGit);let n=t.map;B(e=>!function(e,t){let s=Object.keys(e||{}),n=Object.keys(t||{});if(s.length!==n.length)return!1;for(let s of n)if(e[s]!==t[s])return!1;return!0}(e,n)?n:e)},[s,u]),Y=(0,r.useCallback)(async e=>{y(!0),j("");let t=await s.getFiles(e,!0);if(t.success){let e=t.files;u&&(e=t.files.filter(e=>"folder"===e.type)),g(t=>{if(t.length!==e.length)return e;for(let s=0;s<e.length;s++)if(t[s]?.name!==e[s]?.name)return e;return t}),h(t.currentPath)}else j(t.error),g([]);y(!1)},[s,u]),{transfer:Z,dragOver:Q,conflict:ee,downloadState:et,startUpload:es,handleDrop:en,handleDragOver:er,handleDragLeave:ea,handleDownload:ei,resolveConflict:eo}=function({fileBus:e,currentPath:t,isBrowsing:s,onDone:n,onError:l}){let[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),p=(0,r.useRef)(0),f=(0,r.useCallback)(async s=>{if(!s.length||!e.uploadFiles)return;let r=++p.current;i({total:s.length,done:0,current:s[0]?.file?.name||"",ratio:0}),await e.uploadFiles(t,s,{onConflict:({file:e},t)=>new Promise(s=>{u({name:t||e.name,resolve:s})}),onProgress:(e,t)=>{r===p.current&&i(s=>s?{...s,current:e.name,ratio:t}:s)},onFileDone:e=>{r===p.current&&i(e=>e?{...e,done:e.done+1}:e)}}),r===p.current&&i(null),n?.(t)},[e,t,n]),h=(0,r.useCallback)(async e=>{if(e.preventDefault(),c(!1),s)return;let t=await aD(e.dataTransfer);t.length&&((0,ed.e)(),f(t))},[s,f]),b=(0,r.useCallback)(e=>{e.preventDefault(),s||c(!0)},[s]),g=(0,r.useCallback)(e=>{e.preventDefault(),c(!1)},[]);(0,r.useEffect)(()=>{if(s)return;let e=async e=>{let t=Array.from(e.clipboardData?.files||[]);if(!t.length)return;let s=t.map(e=>({file:e,relativePath:e.name}));(0,ed.e)(),f(s)};return window.addEventListener("paste",e),()=>window.removeEventListener("paste",e)},[s,f]);let v=(0,r.useRef)(0),y=(0,r.useCallback)(t=>{if(!e.downloadFile)return;let s=++v.current;m({name:t.name,ratio:0}),e.downloadFile(t.path,{onSave:(e,n)=>{let r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=n?.fileName||t.name,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(r.href),s===v.current&&m(null)},onProgress:e=>{s===v.current&&m(t=>t?{...t,ratio:e}:t)},onError:e=>{l?.(e.message||"Download failed"),s===v.current&&m(null)}})},[e,l]),w=(0,r.useCallback)(e=>{d?.resolve(e),u(null)},[d]);return{transfer:a,dragOver:o,conflict:d,downloadState:x,startUpload:f,handleDrop:h,handleDragOver:b,handleDragLeave:g,handleDownload:y,resolveConflict:w}}({fileBus:s,currentPath:f,isBrowsing:u,onDone:Y,onError:j}),ex=(0,r.useCallback)(t=>{if(_(t),V.current&&clearTimeout(V.current),!t||t.length<2){U([]),X(!1);return}X(!0),V.current=setTimeout(async()=>{let n=await s.searchFiles(e,t);n.success&&U(n.files),X(!1)},300)},[e,s]),em=(0,r.useCallback)(()=>{K(!1),_(""),U([])},[]);(0,r.useEffect)(()=>{Y(t||e),u||G(e)},[e,t,u]),(0,r.useEffect)(()=>()=>{V.current&&clearTimeout(V.current)},[]),(0,r.useEffect)(()=>{!u&&d&&d(f)},[f,u,d]);let ep=e=>{Y(e.path)},ef=()=>N(null),eb=async()=>{if(!P||!P.newName.trim())return;let e=f+"/"+P.newName.trim(),t=await s.renameItem(P.file.path,e);t.success?Y(f):j(t.error),A(null)},eg=async()=>{if(!E.trim())return;let e=f+"/"+E.trim(),t=await s.createItem(e,T);t.success?(Y(f),S(!1),$("")):j(t.error)},ev=(0,r.useRef)(null),ey=(0,r.useRef)(null),ew=e=>{let t=Array.from(e.target.files||[]);if(e.target.value="",!t.length)return;let s=t.map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}));S(!1),es(s)},ej=async t=>{if(!e||!s||!t?.path)return;ef();let n=t.path.startsWith(e)?t.path.slice(e.length).replace(/^\/+/,""):t.path,r=await aq(s,e,n,"folder"===t.type);r?.success&&(G(e),window.dispatchEvent(new CustomEvent(O.GW)))},ek=f===e,eN="p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]";return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface px-4 py-3 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),l()},className:eN,title:p("common.close"),children:(0,n.jsx)(el.X,{size:20})}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("div",{className:"text-text font-medium truncate text-sm",children:f.replace(/^\/Users\/[^/]+/,"~")})}),u&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),eh(f,m),o(f)},className:"px-3 py-2 bg-brand-500 hover:bg-brand-600 text-white text-xs rounded-brand transition-all duration-150 ease-out active:scale-[0.97] font-medium shadow-sm",title:p("files.setAsWorkspaceTitle"),children:p("files.setWorkspace")}),!u&&c&&!x&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),c()},className:eN,title:p("files.switchWorkspace"),children:(0,n.jsx)(el.Bm,{className:"text-brand-500",size:20})}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),K(!0)},className:eN,title:p("files.searchFiles"),children:(0,n.jsx)(el.vj,{className:"text-brand-500",size:20})}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),i()},disabled:!I,className:`p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.96] ${I?"bg-surface-2 hover:bg-surface-3 text-text":"bg-surface-2/30 text-text-muted cursor-not-allowed"}`,title:I?p("git.title"):p("files.noGitRepo"),children:(0,n.jsx)(el.Zr,{className:I?"text-brand-500":"text-text-muted",size:20})})]}),F&&(0,n.jsx)(aW,{query:W,loading:q,onChange:ex,onClose:em}),w&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm",children:w}),Z&&(0,n.jsx)(aO,{label:`${p("files.copying")} ${Z.done+1}/${Z.total}: ${Z.current}`,ratio:Z.ratio}),et&&(0,n.jsx)(aO,{label:`${p("files.downloading")}: ${et.name}`,ratio:et.ratio}),F&&W.length>=2?(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto",children:q?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.searching")}):0===H.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.noFilesFound")}):(0,n.jsx)("div",{children:H.map(t=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),a(t.path),em()},className:"w-full px-4 py-3 flex items-center gap-3 border-b border-border hover:bg-surface transition-colors text-left",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:"binary"===t.type?(0,n.jsx)(el.lP,{size:20,className:"text-red-500/70"}):(0,n.jsx)(el.ZH,{size:20,className:"text-text-subtle"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-text truncate",title:t.name,children:t.name}),(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",title:t.path,children:t.path.replace(e,"").replace(/^\//,"")})]}),t.sizeFormatted&&(0,n.jsx)("span",{className:"text-text-muted text-xs flex-shrink-0",children:t.sizeFormatted})]},t.path))})}):(0,n.jsxs)(n.Fragment,{children:["/"!==f&&!ek&&!F&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),Y(f.split("/").slice(0,-1).join("/")||"/")},className:"w-full px-4 py-3 flex items-center gap-3 border-b border-border hover:bg-surface transition-colors text-left flex-shrink-0",children:[(0,n.jsx)(el.JG,{className:"text-green-500",size:28}),(0,n.jsx)("span",{className:"text-green-500",children:f.split("/").pop()||"/"})]}),(0,n.jsx)("div",{className:`flex-1 min-h-0 overflow-auto ${!u?"pb-20":""} ${Q?"bg-brand-500/5 ring-2 ring-inset ring-brand-500/40":""}`,onDrop:en,onDragOver:er,onDragLeave:ea,children:u?(0,n.jsx)("div",{className:"p-4",children:v?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("common.loading")}):0===b.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:p("files.emptyFolder")}):(0,n.jsx)("div",{className:"grid grid-cols-2 gap-3",children:b.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ep(e)},className:"bg-surface hover:bg-surface-2 rounded-brand-lg p-2 flex flex-col items-center gap-1 transition-all duration-150 ease-out active:scale-[0.98] text-center",children:[(0,n.jsx)(el.vd,{size:48,className:"text-yellow-500/80"}),(0,n.jsx)("span",{className:"text-text text-xs font-medium truncate w-full",title:e.name,children:e.name})]},e.path))})}):(0,n.jsx)(cY,{files:b,loading:v,onFileClick:e=>{if(!u){if("binary"===e.type){j(p("files.cannotOpenBinary")),setTimeout(()=>j(""),3e3);return}a?.(e.path,f)}},onFolderClick:ep,onMoreClick:(e,t)=>{N({file:e,x:t.x,y:t.y})},gitStatusMap:L,workspacePath:e})})]}),!u&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),S(!0)},className:"absolute bottom-[max(1.5rem,calc(env(safe-area-inset-bottom)+0.5rem))] right-6 w-14 h-14 bg-brand-500 hover:bg-brand-600 text-white rounded-full shadow-lg shadow-brand-500/30 flex items-center justify-center transition-all duration-200",children:(0,n.jsx)(el.FW,{size:24})}),k&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-40",onClick:ef}),(0,n.jsxs)("div",{className:"fixed z-50 card-elev overflow-hidden min-w-[140px]",style:{right:16,top:Math.min(k.y,window.innerHeight-160)},children:[(0,n.jsxs)("button",{onClick:()=>{var e;(0,ed.e)(),e=k.file,ef(),A({file:e,newName:e.name})},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(el.gH,{size:16}),p("files.rename")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),navigator.clipboard?.writeText(k.file.path).catch(()=>{}),ef()},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(el.QR,{size:16}),p("files.copyPath")]}),J&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ef(),ei(k.file)},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(el.f5,{size:16}),p("files.download")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ej(k.file)},className:"w-full px-4 py-3 text-left text-text hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(el.X_,{size:16}),p("git.addToGitignore",{defaultValue:"Add to .gitignore"})]}),(0,n.jsxs)("button",{onClick:()=>{var e;(0,ed.e)(),e=k.file,ef(),M({isOpen:!0,title:p("files.deleteConfirmTitle"),message:p("files.deleteConfirmMessage",{name:e.name}),onConfirm:async()=>{let t=await s.deleteItem(e.path);t.success?Y(f):j(t.error)}})},className:"w-full px-4 py-3 text-left text-red-400 hover:bg-surface-2 flex items-center gap-3 transition-colors",children:[(0,n.jsx)(el.TB,{size:16}),p("files.delete")]})]})]}),C&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(a_,{type:T,name:E,onTypeChange:R,onNameChange:$,onSubmit:eg,onPickFile:()=>ev.current?.click(),onPickFolder:()=>ey.current?.click(),onClose:()=>S(!1)}),(0,n.jsx)("input",{ref:ev,type:"file",multiple:!0,className:"hidden",onChange:ew}),(0,n.jsx)("input",{ref:ey,type:"file",className:"hidden",webkitdirectory:"",onChange:ew})]}),P&&(0,n.jsx)(aH,{value:P.newName,onChange:e=>A({...P,newName:e}),onSubmit:eb,onClose:()=>A(null)}),(0,n.jsx)(ec.A,{isOpen:z.isOpen,onClose:()=>M({isOpen:!1}),onConfirm:z.onConfirm,title:z.title,message:z.message}),ee&&(0,n.jsx)(aU,{name:ee.name,onResolve:eo})]})}let cQ=[{label:"Esc",key:"Escape"},{label:"Tab",key:"Tab"},{label:"←",key:"ArrowLeft"},{label:"→",key:"ArrowRight"},{label:"↑",key:"ArrowUp"},{label:"↓",key:"ArrowDown"},{label:"Ctrl",modifier:"ctrl"},{label:"Opt",modifier:"alt"}],c0=[{label:"Undo",key:"z",ctrl:!0},{label:"Redo",key:"y",ctrl:!0},{label:"{}",text:"{}"},{label:"()",text:"()"},{label:"[]",text:"[]"},{label:'""',text:'""'},{label:"=>",text:" => "},{label:"Aa",toggleTextInput:!0}];function c1({viewRef:e}){let{t}=(0,eu.s)(),[s,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(""),x=(0,r.useRef)(null),m=t=>{let s=e.current;if(!s)return;let{from:n,to:r}=s.state.selection.main;s.dispatch({changes:{from:n,to:r,insert:t},selection:{anchor:n+t.length}}),s.focus()},p=(t,{ctrl:n=!1,alt:r=!1}={})=>{let o=e.current;o&&(o.contentDOM.dispatchEvent(new KeyboardEvent("keydown",{key:t,code:1===t.length?`Key${t.toUpperCase()}`:t,ctrlKey:n||s,altKey:r||a,metaKey:n||s,bubbles:!0,cancelable:!0})),o.focus(),l(!1),i(!1))},f=e=>`flex-1 py-2 text-text text-xs rounded-brand transition-all duration-200 border ${e?"bg-brand-500 border-brand-400 shadow-md shadow-brand-500/30":"bg-surface-2 hover:bg-surface-2 border-border hover:border-brand-500"}`;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:`bg-surface transition-all duration-300 overflow-hidden ${o?"max-h-24 opacity-100":"max-h-0 opacity-0"}`,children:(0,n.jsxs)("div",{className:"p-2 flex gap-2 items-center",children:[(0,n.jsx)("textarea",{ref:x,value:d,onChange:e=>u(e.target.value),placeholder:t("editor.typeText"),rows:1,className:"w-full px-3 py-2 bg-surface-2 rounded text-text text-base placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out resize-none"}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d.trim()&&(m(d),u("")),c(!1)},disabled:!d.trim(),className:"px-4 py-2 bg-brand-500 hover:bg-brand-600 disabled:bg-surface-2 disabled:opacity-50 text-white text-sm font-medium rounded transition-all duration-150 ease-out active:scale-[0.97] shadow-sm flex-shrink-0",children:t("editor.insert")})]})}),(0,n.jsxs)("div",{className:"bg-surface border-t border-border px-2 pt-2 pb-safe flex flex-col gap-1 flex-shrink-0",children:[(0,n.jsx)("div",{className:"flex gap-1",children:cQ.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),"ctrl"===e.modifier?(l(e=>!e),i(!1)):"alt"===e.modifier?(i(e=>!e),l(!1)):p(e.key)},className:f("ctrl"===e.modifier&&s||"alt"===e.modifier&&a),children:e.label},e.label))}),(0,n.jsx)("div",{className:"flex gap-1",children:c0.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),e.toggleTextInput?(c(e=>!e),o||setTimeout(()=>x.current?.focus(),350)):e.text?m(e.text):e.key&&p(e.key,{ctrl:e.ctrl,alt:e.alt})},className:f(e.toggleTextInput&&o),children:e.label},e.label))})]})]})}function c2({filePath:e,fileBus:t,onBack:s,line:l,column:a,workspace:i,diffStatus:o,preview:c=!1}){let{t:d}=(0,eu.s)(),u=ip(e),x=!!o,m=e.split("/").pop(),p=ib({filePath:x||u?"":e,fileBus:t}),f=ig({dirty:!x&&!u&&p.dirty,onSave:p.save}),h=(0,r.useRef)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(!1),C=x||u?null:(0,O.YO)(e),[S,T]=(0,r.useState)(c&&!!C),[R,E]=(0,r.useState)(0),[$,z]=(0,r.useState)(e),[M,P]=(0,r.useState)(!1);$!==e&&(z(e),T(c&&!!C)),p.justSaved!==M&&(P(p.justSaved),p.justSaved&&E(e=>e+1));let A=(0,r.useCallback)((e,t)=>{h.current=t},[]);(0,r.useEffect)(()=>{if(x||!i||!e)return;let s=!1;return t.gitFileStatus(i,e).then(e=>{s||y(e?.success&&e.status?e:null)}),()=>{s=!0}},[e,i,t]);let I=async()=>{if(!v||!i)return;if((0,O.u)(e))return void j("image");N(!0);let s=await t.gitDiff(i,v.file,v.status);N(!1),s?.success&&j(s.diff||"")};(0,r.useEffect)(()=>{if(!o||!i||!e)return;let s=!1,n=setTimeout(async()=>{if((0,O.u)(e))return void j("image");N(!0);let n=await t.gitDiff(i,e,o);!s&&(N(!1),n?.success&&j(n.diff||""))},0);return()=>{s=!0,clearTimeout(n)}},[o,i,e,t]);let D=async()=>{let e=h.current?.state.doc.toString();if(null!=e)try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),1500)}catch{}};return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface px-4 py-3 flex items-center gap-2 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f.guard(s)},className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",children:(0,n.jsx)(el.JG,{size:20})}),(0,n.jsxs)("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"text-text font-medium truncate",children:m}),p.dirty&&(0,n.jsx)("span",{className:"w-2 h-2 bg-yellow-400 rounded-full flex-shrink-0",title:d("editor.unsaved")}),p.justSaved&&(0,n.jsx)("span",{className:"text-green-400 text-xs flex-shrink-0",children:d("editor.saved")}),b&&(0,n.jsx)("span",{className:"text-green-400 text-xs flex-shrink-0",children:d("editor.copied",{defaultValue:"Copied"})})]}),v&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),I()},disabled:k,className:"p-2 bg-surface-2 hover:bg-surface-3 text-orange-400 rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",title:d("editor.gitDiff"),children:k?(0,n.jsx)(el.kr,{className:"animate-spin",size:16}):(0,n.jsx)(el.Zr,{size:16})}),C&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),T(e=>!e)},title:d(S?"editor.editCode":"editor.preview"),className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",children:S?(0,n.jsx)(el.GD,{size:16}):(0,n.jsx)(el.kU,{size:16})}),!u&&!x&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),D()},className:"p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-150 ease-out active:scale-[0.96]",title:d("editor.copy",{defaultValue:"Copy"}),children:(0,n.jsx)(el.QR,{size:16})}),!u&&!x&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),p.save()},disabled:!p.dirty||p.saving,className:`px-3 py-2 rounded-brand transition-all duration-150 ease-out flex items-center gap-1 ${p.dirty&&!p.saving?"bg-brand-500 hover:bg-brand-600 text-white shadow-sm active:scale-[0.97]":"bg-surface-2 text-text-muted cursor-not-allowed"}`,children:[p.saving?(0,n.jsx)(el.kr,{className:"animate-spin",size:16}):(0,n.jsx)(el.eM,{size:16}),(0,n.jsx)("span",{className:"hidden sm:inline",children:d("editor.save")})]})]}),p.error&&!u&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm break-words",children:p.error}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:x?(0,O.u)(e)?(0,n.jsx)(iU,{filePath:e,status:o,workspace:i,fileBus:t}):(0,n.jsx)("div",{className:"h-full overflow-auto p-2",children:k?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted",children:d("common.loading")}):w?(0,n.jsx)(i_,{diff:w}):(0,n.jsx)("div",{className:"h-32 flex items-center justify-center text-text-muted text-sm",children:d("git.noChanges")})}):u?(0,n.jsx)(ih,{filePath:e,fileBus:t}):S&&C?(0,n.jsx)(iK,{kind:C,filePath:e,fileBus:t,content:p.content,reloadKey:R}):p.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted",children:d("common.loading")}):(0,n.jsx)(iP,{filePath:e,content:p.content,onTextChanged:p.onTextChanged,onRegisterView:(e,t)=>{p.register(e),A(e,t)},onSave:p.save,line:l,column:a})}),!x&&null!==w&&(0,n.jsxs)("div",{className:"absolute inset-0 z-30 bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface-2 px-4 py-3 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-text font-medium truncate",children:d("editor.gitDiff")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),j(null)},className:"p-2 text-text-muted hover:text-text rounded-brand",children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto p-2",children:(0,O.u)(e)?(0,n.jsx)(iU,{filePath:e,status:v?.status,workspace:i,fileBus:t}):w?(0,n.jsx)(i_,{diff:w}):(0,n.jsx)("div",{className:"h-32 flex items-center justify-center text-text-muted text-sm",children:d("git.noChanges")})})]}),!u&&!x&&!p.loading&&!S&&(0,n.jsx)(c1,{viewRef:h}),(0,n.jsx)(iv,{isOpen:f.asking,fileName:m,onSave:f.saveThenLeave,onDiscard:f.discardAndLeave,onCancel:f.cancel})]})}function c5({workspace:e,fileBus:t,branch:s,changedCount:l,onDone:a,onClose:i}){let{t:o}=(0,eu.s)(),[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||u||i()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i,u]);let f=c.trim().length>0&&!u,h=async()=>{let s=await t.gitAdd(e);if(!s.success)return{ok:!1,text:s.error||o("git.stageFailed")};let n=await t.gitCommit(e,c.trim());return n.success?{ok:!0,text:a1(o,n.output)}:{ok:!1,text:n.output||n.error||o("git.commitFailed")}},b=async()=>{if(!f)return;(0,ed.e)(),x(!0),p(null);let e=await h();x(!1),p(e),e.ok&&(d(""),a?.())},g=async()=>{if(u)return;(0,ed.e)(),x(!0),p(null);let s=await t.gitPush(e);x(!1),p({ok:s.success,text:s.success?a2(o,s.output):s.output||s.error||o("git.pushFailed")}),s.success&&a?.()},v=async()=>{if(!f)return;(0,ed.e)(),x(!0),p(null);let s=await h();if(!s.ok){x(!1),p(s);return}d("");let n=await t.gitPush(e);x(!1),p({ok:n.success,text:n.success?a2(o,n.output):n.output||n.error||o("git.pushFailed")}),a?.()};return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:()=>!u&&i()}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsxs)("h3",{className:"text-lg font-semibold text-text flex items-center gap-2",children:[(0,n.jsx)(el.Zr,{size:18,className:"text-brand-500"}),o("git.title"),s?` \xb7 ${s}`:""]}),(0,n.jsx)("button",{onClick:()=>!u&&i(),className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":o("common.close"),children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsxs)("div",{className:"px-5 pb-5 flex flex-col gap-4",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,n.jsx)("textarea",{value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),v())},rows:2,placeholder:o("git.commitPlaceholder"),disabled:u,className:"w-full px-3 py-2 bg-surface-2 text-text text-sm rounded-brand outline-none focus:ring-1 focus:ring-brand-500 resize-y min-h-[54px] max-h-[200px] disabled:opacity-60"}),(0,n.jsx)("span",{className:"text-xs text-text-subtle",children:o("git.stageAllNote",{count:l})})]}),(0,n.jsxs)("button",{onClick:v,disabled:!f,className:"w-full px-4 py-2.5 text-sm bg-brand-500 hover:bg-brand-500/80 text-white font-medium rounded-brand transition-colors flex items-center justify-center gap-2 disabled:opacity-40 disabled:cursor-not-allowed",children:[u?(0,n.jsx)(el.kr,{size:16,className:"animate-spin"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el.aJ,{size:16}),(0,n.jsx)(el.Do,{size:16})]}),(0,n.jsx)("span",{children:o("git.commitAndPush")}),(0,n.jsx)("kbd",{className:"hidden sm:inline-flex items-center text-[10px] font-mono px-1.5 py-0.5 rounded bg-white/20 text-white leading-none",children:"⌘↵"})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:b,disabled:!f,className:"flex-1 px-4 py-2 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)(el.aJ,{size:16}),o("git.commit")]}),(0,n.jsxs)("button",{onClick:g,disabled:u,className:"flex-1 px-4 py-2 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand transition-colors flex items-center justify-center gap-1.5 disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)(el.Do,{size:16}),o("git.push")]})]}),m&&(0,n.jsx)("pre",{className:`text-xs whitespace-pre-wrap break-words px-3 py-2 rounded-brand max-h-32 overflow-y-auto ${m.ok?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:m.text})]})]})]})}function c3({workspace:e,fileBus:t,onBack:s,onOpenFile:l}){let{t:a}=(0,eu.s)(),[i,o]=(0,r.useState)("status"),[c,d]=(0,r.useState)(!0),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(""),[f,h]=(0,r.useState)([]),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(""),[k,N]=(0,r.useState)(!1),[C,S]=(0,r.useState)({isOpen:!1}),[T,R]=(0,r.useState)(""),[E,$]=(0,r.useState)(null),[z,M]=(0,r.useState)(null),[P,A]=(0,r.useState)(!1),I=(0,r.useCallback)(async()=>{d(!0),p("");let s=await t.gitStatus(e);s.success?h(s.files):p(s.error),t.gitBranch(e).then(e=>{e?.success&&(R(e.branch),$(e.ahead??null),M(e.behind??null))}),d(!1)},[e,t]),D=(0,r.useCallback)(async(s=null,n=null)=>{if(g(s),y(n),s&&(0,O.u)(s)){j("image"),N(!0),x(!1);return}x(!0),p("");let r=await t.gitDiff(e,s,n);r.success?(j(r.diff),N(!0)):p(r.error),x(!1)},[e,t]);(0,r.useEffect)(()=>{I()},[I]);let L=(0,r.useCallback)(()=>{if(o("diff"),!k&&f.length>0){let e=f[0];D(e.path,e.status)}},[k,D,f]),B=(0,r.useCallback)(()=>{b&&v&&F(b,v)},[b,v]),F=(0,r.useCallback)((s,n)=>{let r=s.split("/").pop(),l="?"===n;S({isOpen:!0,title:a("git.discardConfirmTitle"),message:l?a("git.discardConfirmDelete",{name:r}):a("git.discardConfirmDiscard",{name:r}),onConfirm:async()=>{let r=await t.gitDiscard(e,s,n);if(r.success){if(await I(),"diff"===i){let e=f.filter(e=>e.path!==s);e.length>0?D(e[0].path,e[0].status):(o("status"),g(null),j(""),N(!1))}}else p(r.error)}})},[t,e,I,D,f,i,a]),K=(0,r.useCallback)(t=>{let s=e.endsWith("/")?`${e}${t}`:`${e}/${t}`;l?.(s)},[e,l]),[W,_]=(0,r.useState)(null),H=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),U=(0,r.useCallback)((e,t)=>{t.preventDefault(),t.stopPropagation(),(0,ed.e)(),_({file:e,x:t.clientX,y:t.clientY})},[]),q=(0,r.useCallback)(async s=>{if(!e||!t||!s?.path)return;let n=await aq(t,e,s.path);n?.success&&(window.dispatchEvent(new CustomEvent(O.GW)),I())},[e,t,I]),X=(0,r.useCallback)(t=>{let s=e.endsWith("/")?`${e}${t.path}`:`${e}/${t.path}`;return[{key:"open",label:a("common.open",{defaultValue:"Open"}),icon:aQ.ExternalLink,disabled:"D"===t.status,onClick:()=>K(t.path)},{key:"copyPath",label:a("files.copyPath",{defaultValue:"Copy Path"}),icon:aQ.Copy,onClick:()=>H(s)},{key:"copyRel",label:a("files.copyRelPath",{defaultValue:"Copy Relative Path"}),icon:aQ.FileText,onClick:()=>H(t.path)},{key:"copyName",label:a("files.copyName",{defaultValue:"Copy Filename"}),icon:aQ.FileText,onClick:()=>H(t.path.split("/").pop())},{key:"addToGitignore",label:a("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:aQ.EyeOff,onClick:()=>q(t)},{key:"discard",label:a("git.discardChangesTitle",{defaultValue:"Discard Changes"}),icon:aQ.Undo2,danger:!0,onClick:()=>F(t.path,t.status)}]},[e,a,K,H,q,F]),V={modified:f.filter(e=>"M"===e.status),added:f.filter(e=>"A"===e.status),deleted:f.filter(e=>"D"===e.status),untracked:f.filter(e=>"?"===e.status)},J=e=>{let t=e.path.split("/").pop(),s=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")+1):"",r=e.added>0||e.deleted>0;return(0,n.jsx)("div",{className:"px-3 py-2 bg-surface rounded hover:bg-surface-2 transition",onContextMenu:t=>U(e,t),children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:aE({name:t,path:e.path,type:"file"},18)}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),D(e.path,e.status),o("diff")},className:"flex-1 min-w-0 text-left",children:[(0,n.jsx)("div",{className:"text-text font-medium truncate",title:e.path,children:t}),s&&(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",title:s,children:s})]}),r&&(0,n.jsxs)("div",{className:"flex items-center gap-1 text-xs flex-shrink-0",children:[e.added>0&&(0,n.jsxs)("span",{className:"text-[var(--success)]",children:["+",e.added]}),e.deleted>0&&(0,n.jsxs)("span",{className:"text-[var(--danger)]",children:["-",e.deleted]})]}),"D"!==e.status&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),K(e.path)},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-200 flex-shrink-0",title:a("git.openFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),F(e.path,e.status)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-all duration-200 flex-shrink-0",title:a("git.discardChangesTitle"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("span",{className:`font-mono font-bold w-5 h-5 flex items-center justify-center text-[11px] rounded flex-shrink-0 bg-surface-2 ${O.vs[e.status]}`,children:e.status})]})},e.path)};return(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"bg-surface border-b border-border px-4 py-3 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s()},className:"p-2 bg-surface-2 hover:bg-surface-2 text-text rounded-brand transition-all duration-200",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}),(0,n.jsxs)("h1",{className:"text-text text-lg font-semibold truncate flex items-center gap-2",children:[a("git.title"),T?(0,n.jsxs)("span",{className:"text-text-muted font-normal",children:[" \xb7 ",T]}):null,E>0&&(0,n.jsxs)("span",{className:"text-xs font-medium px-1.5 py-0.5 rounded-brand bg-brand-500/15 text-brand-500",children:["↑",E]}),z>0&&(0,n.jsxs)("span",{className:"text-xs font-medium px-1.5 py-0.5 rounded-brand bg-surface-3 text-text-muted",children:["↓",z]})]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),A(!0)},className:"ml-auto p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-200",title:a("git.gitActions"),children:(0,n.jsx)(el.Zr,{className:"w-5 h-5"})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),"status"===i?I():D(b,v)},className:"p-2 bg-surface-2 hover:bg-surface-2 text-text rounded-brand transition-all duration-200",title:a("common.refresh"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),(0,n.jsxs)("div",{className:"flex border-b border-border flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),o("status")},className:`flex-1 py-3 text-center font-medium transition ${"status"===i?"text-text border-b-2 border-brand-500":"text-text-muted hover:text-text"}`,children:a("git.status")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),L()},className:`flex-1 py-3 text-center font-medium transition ${"diff"===i?"text-text border-b-2 border-brand-500":"text-text-muted hover:text-text"}`,children:a("git.diffTab")})]}),m&&(0,n.jsx)("div",{className:"bg-red-500/20 border-b border-red-500/50 px-4 py-2 text-red-400 text-sm",children:m}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden modal-scrollable",children:"status"===i?c?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("common.loading")}):(0,n.jsx)("div",{className:"p-4 space-y-4",children:0===f.length?(0,n.jsx)("div",{className:"text-center text-text-muted py-8",children:a("git.noChanges")}):(0,n.jsxs)(n.Fragment,{children:[V.modified.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.modified")," (",V.modified.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:V.modified.map(J)})]}),V.added.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.added")," (",V.added.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:V.added.map(J)})]}),V.deleted.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.deleted")," (",V.deleted.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:V.deleted.map(J)})]}),V.untracked.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[a("git.untrackedTitle")," (",V.untracked.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:V.untracked.map(J)})]})]})}):(0,n.jsxs)("div",{className:"p-4 min-w-0",children:[f.length>0&&(0,n.jsxs)("div",{className:"flex gap-2 mb-4",children:[(0,n.jsx)("select",{value:b||"",onChange:e=>{(0,ed.e)();let t=f.find(t=>t.path===e.target.value);t&&D(t.path,t.status)},className:"flex-1 min-w-0 px-3 py-2 bg-surface-2 rounded-brand text-text focus:outline-none transition-all duration-150 ease-out",children:f.map(e=>(0,n.jsxs)("option",{value:e.path,children:["[",e.status,"] ",e.path]},e.path))}),b&&"D"!==v&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),K(b)},disabled:u,className:"h-9 w-9 flex-shrink-0 bg-surface-2 hover:bg-surface-3 disabled:cursor-not-allowed text-text rounded-brand transition-all duration-200 flex items-center justify-center",title:a("git.openFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),B()},disabled:!b||u,className:"h-9 w-9 flex-shrink-0 bg-red-500/10 hover:bg-red-500/20 disabled:bg-surface-2 disabled:cursor-not-allowed text-red-400 rounded-brand transition-all duration-200 flex items-center justify-center",title:a("git.discardChangesTitle"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})})]}),u?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("common.loading")}):b&&(0,O.u)(b)?(0,n.jsx)(iU,{filePath:b,status:v,workspace:e,fileBus:t}):w?(0,n.jsx)(i_,{diff:w}):(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:a("git.noChanges")})]})}),(0,n.jsx)(ec.A,{isOpen:C.isOpen,onClose:()=>S({isOpen:!1}),onConfirm:C.onConfirm,title:C.title,message:C.message}),P&&(0,n.jsx)(c5,{workspace:e,fileBus:t,branch:T,changedCount:f.length,onDone:I,onClose:()=>A(!1)}),W&&(0,n.jsx)(aZ,{x:W.x,y:W.y,items:X(W.file),onClose:()=>_(null)})]})}let c4=[{id:O.Kr.explorer,Icon:el.sv,label:"Explorer"},{id:O.Kr.search,Icon:el.vj,label:"Search"},{id:O.Kr.scm,Icon:el.Zr,label:"Source Control"}];function c6({active:e,onClick:t,label:s,children:r}){return(0,n.jsx)("button",{type:"button",title:s,onClick:t,className:`relative w-10 h-10 flex items-center justify-center rounded-brand transition-all duration-150 ease-out active:scale-[0.96] ${e?"bg-surface-2 text-text border-l-2 border-brand-500":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:r})}function c8({activePanel:e,onSelectPanel:t,onBack:s}){let r=e=>{(0,ed.e)(10),t?.(e)};return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-between bg-surface border-r border-border py-2",style:{width:O.zT},children:[(0,n.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,n.jsx)(c6,{onClick:()=>{(0,ed.e)(10),s?.()},label:"Back",children:(0,n.jsx)(el.JG,{size:20})}),c4.map(({id:t,Icon:s,label:l})=>(0,n.jsx)(c6,{active:e===t,onClick:()=>r(t),label:l,children:(0,n.jsx)(s,{size:20})},t))]}),(0,n.jsx)("div",{className:"flex flex-col items-center gap-1",children:(0,n.jsx)(c6,{active:e===O.Kr.settings,onClick:()=>r(O.Kr.settings),label:"Settings",children:(0,n.jsx)(el.wB,{size:20})})})]})}function c9({active:e,onClick:t,title:s,children:r}){return(0,n.jsx)("button",{type:"button",title:s,onClick:()=>{(0,ed.e)(),t()},className:`px-2 h-6 text-xs rounded-brand border transition-colors ${e?"bg-brand-500 text-white border-brand-500":"bg-surface-2 text-text-muted border-border hover:bg-surface-3"}`,children:r})}function c7({workspace:e,fileBus:t,onOpenFile:s}){let[l,a]=(0,r.useState)(""),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!1),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(!1),[f,h]=(0,r.useState)(""),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)([]),[C,S]=(0,r.useState)(!1),[T,R]=(0,r.useState)(!1),[E,$]=(0,r.useState)(new Set),[z,M]=(0,r.useState)(!1),P=(0,r.useRef)(null),A=(0,r.useCallback)(async()=>{if(!l||!e||!t?.searchInFiles){N([]),R(!1);return}S(!0);let s=await t.searchInFiles(e,l,{caseSensitive:c,wholeWord:u,regex:m,includeGlob:f,excludeGlob:b});if(S(!1),s?.success){R(!1);let e=s.results||[];N(e),$(new Set(e.map(e=>e.path)))}else R(!0),N([])},[l,e,t,c,u,m,f,b]);(0,r.useEffect)(()=>{if(P.current&&clearTimeout(P.current),!l){N([]),S(!1);return}return P.current=setTimeout(A,400),()=>clearTimeout(P.current)},[l,c,u,m,f,b,A]);let I=(0,r.useMemo)(()=>{let e=0;for(let t of k)e+=(t.matches||[]).length;return{files:k.length,matches:e}},[k]),D=(0,r.useCallback)(e=>{$(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),L=(0,r.useCallback)(async()=>{if(!l||!e||!t?.replaceInFiles||!k.length)return;let s=k.map(e=>e.path);S(!0),await t.replaceInFiles(e,l,i,{caseSensitive:c,wholeWord:u,regex:m,includeGlob:f,excludeGlob:b},s),S(!1),A()},[l,i,e,t,k,c,u,m,f,b,A]);return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text",children:[(0,n.jsxs)("div",{className:"px-3 pt-3 pb-2 space-y-2 border-b border-border",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(el.vj,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-subtle"}),(0,n.jsx)("input",{value:l,onChange:e=>a(e.target.value),placeholder:"Search",className:"w-full bg-surface-2 border border-border rounded-brand pl-7 pr-7 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),l&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),a("")},className:"absolute right-1 top-1/2 -translate-y-1/2 p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(el.X,{size:12})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,n.jsx)(c9,{active:c,onClick:()=>d(!c),title:"Match Case",children:"Aa"}),(0,n.jsx)(c9,{active:u,onClick:()=>x(!u),title:"Whole Word",children:"ab"}),(0,n.jsx)(c9,{active:m,onClick:()=>p(!m),title:"Regex",children:".*"}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)(c9,{active:w,onClick:()=>j(!w),title:"Toggle Replace",children:"↔"}),(0,n.jsx)(c9,{active:v,onClick:()=>y(!v),title:"Filters",children:"…"})]}),w&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{value:i,onChange:e=>o(e.target.value),placeholder:"Replace",className:"flex-1 bg-surface-2 border border-border rounded-brand px-2 h-8 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),(0,n.jsx)("button",{type:"button",disabled:!l||!k.length,onClick:()=>{(0,ed.e)(),M(!0)},className:"px-2 h-8 text-xs rounded-brand bg-brand-500 text-white hover:opacity-90 disabled:opacity-40 disabled:cursor-not-allowed",children:"Replace All"})]}),v&&(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("input",{value:f,onChange:e=>h(e.target.value),placeholder:"files to include",className:"w-full bg-surface-2 border border-border rounded-brand px-2 h-7 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"}),(0,n.jsx)("input",{value:b,onChange:e=>g(e.target.value),placeholder:"files to exclude",className:"w-full bg-surface-2 border border-border rounded-brand px-2 h-7 text-xs text-text placeholder-text-subtle focus:outline-none focus:border-brand-500"})]}),(0,n.jsx)("div",{className:`text-[11px] ${T?"text-danger":"text-text-muted"}`,children:C?"Searching...":T?"Search failed — try again":l?`${I.matches} results in ${I.files} files`:"Type to search"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:k.map(e=>{let t=E.has(e.path),r=function(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}(e.path),a=function(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(0,t):""}(e.path);return(0,n.jsxs)("div",{className:"border-b border-border/60",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),D(e.path)},className:"w-full flex items-center gap-1 px-2 py-1 hover:bg-surface-2 text-left",children:[t?(0,n.jsx)(el.yQ,{size:12,className:"text-text-subtle"}):(0,n.jsx)(el.c_,{size:12,className:"text-text-subtle"}),(0,n.jsx)("span",{className:"truncate text-xs text-text",title:e.path,children:r}),(0,n.jsx)("span",{className:"truncate text-[11px] text-text-muted flex-1",title:a,children:a}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 rounded-brand bg-surface-3 text-text-muted",children:e.matches?.length||0})]}),t&&(0,n.jsx)("div",{className:"pl-5",children:(e.matches||[]).map((t,r)=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),s?.(e.path,{line:t.line,column:t.column})},className:"w-full text-left px-2 py-0.5 text-[11px] text-text-muted hover:bg-surface-2 truncate font-mono",title:t.lineText,children:[(0,n.jsx)("span",{className:"text-text-subtle mr-2",children:t.line}),function(e,t,{caseSensitive:s,wholeWord:r,regex:l}){let a,i;if(!t)return e;try{let e=l?t:t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");r&&!l&&(e=`\\b${e}\\b`),a=new RegExp(e,s?"g":"gi")}catch{return e}let o=[],c=0,d=0;for(;null!==(i=a.exec(e))&&d++<500;)i.index>c&&o.push(e.slice(c,i.index)),o.push((0,n.jsx)("span",{className:"bg-brand-500/30 text-text rounded-sm",children:i[0]},`${i.index}-${d}`)),c=i.index+i[0].length,i.index===a.lastIndex&&a.lastIndex++;return c<e.length&&o.push(e.slice(c)),o}(t.lineText||"",l,{caseSensitive:c,wholeWord:u,regex:m})]},`${e.path}-${r}`))})]},e.path)})}),(0,n.jsx)(ec.A,{isOpen:z,onClose:()=>M(!1),onConfirm:L,title:"Replace All",message:`Replace ${I.matches} matches in ${I.files} files?`,confirmText:"Replace All",cancelText:"Cancel"})]})}let de="px-3 my-2 text-[11px] uppercase tracking-wider text-text-muted",dt="flex items-center justify-between px-3 py-2 hover:bg-surface-2";function ds({value:e,onChange:t}){return(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),t(!e)},className:`relative w-9 h-5 rounded-full transition-colors ${e?"bg-brand-500":"bg-surface-3"}`,children:(0,n.jsx)("span",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${e?"translate-x-4":"translate-x-0.5"}`})})}function dn(){let[e,t]=tW(O.d5.editorFontSize,O.A0),[s,r]=tW(O.d5.wordWrap,!1),[l,a]=tW("fileExplorer.showHidden",!0),i=e=>{t(Math.max(O.xr,Math.min(O.bd,Number(e)||O.A0)))};return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text overflow-auto",children:[(0,n.jsx)("div",{className:de,children:"Editor"}),(0,n.jsxs)("div",{className:dt,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Font Size"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"range",min:O.xr,max:O.bd,value:e,onChange:e=>i(e.target.value),className:"w-24 accent-brand-500"}),(0,n.jsx)("input",{type:"number",min:O.xr,max:O.bd,value:e,onChange:e=>i(e.target.value),className:"w-12 bg-surface-2 border border-border rounded-brand px-1 h-6 text-xs text-text text-center focus:outline-none focus:border-brand-500"})]})]}),(0,n.jsxs)("div",{className:dt,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Word Wrap"}),(0,n.jsx)(ds,{value:s,onChange:r})]}),(0,n.jsx)("div",{className:de,children:"Files"}),(0,n.jsxs)("div",{className:dt,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Show Hidden Files"}),(0,n.jsx)(ds,{value:l,onChange:a})]}),(0,n.jsx)("div",{className:de,children:"About"}),(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-text-muted",children:"VSCode-like File Explorer for 9remote"})]})}let dr={[O.Kr.explorer]:"Explorer",[O.Kr.search]:"Search",[O.Kr.scm]:"Source Control",[O.Kr.settings]:"Settings"};function dl({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a}){let i=dr[e]||"",o=e===O.Kr.explorer;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[!o&&(0,n.jsxs)("div",{style:{height:32},className:"bg-surface px-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"uppercase tracking-wider text-xs text-text-muted",children:i}),(0,n.jsx)("button",{type:"button",title:"Refresh",onClick:()=>{(0,ed.e)(10),s?.refresh?.()},className:"w-7 h-7 flex items-center justify-center rounded-brand text-text-muted hover:text-text hover:bg-surface-2 transition-all duration-150 ease-out active:scale-[0.96]",children:(0,n.jsx)(el.e9,{size:14})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:function({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a}){switch(e){case O.Kr.explorer:return(0,n.jsx)(aY,{workspace:t,fileBus:s,onOpenFile:r,activeFile:a,onSwitchWorkspace:l});case O.Kr.search:return(0,n.jsx)(c7,{workspace:t,fileBus:s,onOpenFile:r});case O.Kr.scm:return(0,n.jsx)(a7,{workspace:t,fileBus:s,onOpenFile:r});case O.Kr.settings:return(0,n.jsx)(dn,{});default:return null}}({activePanel:e,workspace:t,fileBus:s,onOpenFile:r,onSwitchWorkspace:l,activeFile:a})})]})}function da({openedFiles:e,activeFile:t,dirtyFiles:s,onActivate:l,onClose:a,onCloseOthers:i,onCloseAll:o}){let[c,d]=(0,r.useState)(null),u=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!c)return;let e=e=>{u.current&&!u.current.contains(e.target)&&d(null)};return window.addEventListener("mousedown",e),()=>window.removeEventListener("mousedown",e)},[c]),e?.length)?(0,n.jsxs)("div",{className:"flex overflow-x-auto bg-surface border-b border-border flex-shrink-0 relative",children:[e.map(e=>{let r=e===t,i=s?.has(e),o=(0,O.pA)(e),c=o?(0,O.Ax)(e).absPath:e,u=o?`${c.split("/").pop()} (diff)`:c.split("/").pop(),x=o?null:aE({name:c.split("/").pop()||c,type:"file",path:c},14);return(0,n.jsxs)("div",{onClick:()=>{(0,ed.e)(),l(e)},onMouseDown:t=>{1===t.button&&(t.preventDefault(),(0,ed.e)(),a(e))},onContextMenu:t=>{t.preventDefault(),d({path:e,x:t.clientX,y:t.clientY})},className:`group flex items-center gap-2 px-3 py-1.5 border-r border-border cursor-pointer text-sm flex-shrink-0 select-none ${r?"bg-bg text-text border-t-2 border-t-brand-500":"bg-surface text-text-muted hover:text-text"}`,children:[x?(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:x}):(0,n.jsx)(el.Ay,{name:"File",size:14,className:"text-text-muted"}),(0,n.jsx)("span",{className:"truncate max-w-[160px]",title:c,children:u}),i?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand-500 flex-shrink-0"}):null,(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),a(e)},className:`p-0.5 rounded hover:bg-surface-3 transition-opacity ${r||i?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:(0,n.jsx)(el.X,{size:14})})]},e)}),c&&(0,n.jsx)("div",{ref:u,style:{top:c.y,left:c.x},className:"fixed z-50 bg-surface-2 border border-border rounded-brand shadow-lg py-1 text-sm min-w-[160px]",children:[{label:"Close",action:()=>a(c.path)},{label:"Close Others",action:()=>i(c.path)},{label:"Close All",action:()=>o()}].map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),e.action(),d(null)},className:"w-full text-left px-3 py-1.5 text-text hover:bg-surface-3 transition-colors",children:e.label},e.label))})]}):null}function di({workspace:e,filePath:t}){if(!t)return(0,n.jsx)("div",{className:"bg-bg border-b border-border px-3 py-1 text-xs text-text-muted h-7"});let s=e?e.split("/").filter(Boolean).pop():"",l=(e&&t.startsWith(e+"/")?t.slice(e.length+1):t).split("/").filter(Boolean),a=s?[s,...l]:l,i=a.length-1;return(0,n.jsx)("div",{className:"bg-bg border-b border-border px-3 py-1 text-xs text-text-muted flex items-center gap-1 overflow-x-auto whitespace-nowrap",children:a.map((e,t)=>(0,n.jsxs)(r.Fragment,{children:[(0,n.jsx)("span",{className:t===i?"text-text font-medium":"hover:text-text cursor-default",children:e}),t<i&&(0,n.jsx)(el.c_,{size:12,className:"flex-shrink-0"})]},t))})}function dc({filePath:e,workspace:t,fileBus:s,isActive:l,onCursorChange:a,onDirtyChange:i,onRegisterSaver:o,previewSeq:c=0}){let{t:d}=(0,eu.s)(),u=!(0,O.pA)(e)&&!ip(e),x=ib({filePath:u?e:"",fileBus:s}),m=u?(0,O.YO)(e):null,[p,f]=(0,r.useState)(!!c&&!!m),[h,b]=(0,r.useState)(0),[g,v]=(0,r.useState)(e),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(c);return(g!==e?(v(e),f(!1)):j!==c&&(k(c),c&&m&&f(!0)),x.justSaved!==y&&(w(x.justSaved),x.justSaved&&b(e=>e+1)),(0,r.useEffect)(()=>{i?.(e,u&&x.dirty)},[e,u,x.dirty,i]),(0,r.useEffect)(()=>{if(u)return o?.(e,x.save),()=>{o?.(e,null),i?.(e,!1)}},[e,u,x.save,o,i]),(0,r.useEffect)(()=>{if(!l||!u)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()&&(e.preventDefault(),x.save())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l,u,x]),(0,O.pA)(e))?(0,n.jsx)(iq,{diffPath:e,workspace:t,fileBus:s}):ip(e)?(0,n.jsx)(ih,{filePath:e,fileBus:s}):(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[x.error&&(0,n.jsx)("div",{className:"px-4 py-2 text-sm text-red-400 bg-red-500/15 border-b border-red-500/40 break-words",children:x.error}),m&&(0,n.jsx)("div",{className:"px-3 py-1.5 flex items-center justify-end bg-surface border-b border-border-subtle flex-shrink-0",children:(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f(e=>!e)},title:d(p?"editor.editCode":"editor.preview"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:p?(0,n.jsx)(el.GD,{size:13}):(0,n.jsx)(el.kU,{size:13})})}),x.dirty&&(0,n.jsxs)("div",{className:"px-3 py-1.5 flex items-center gap-2 bg-surface border-b border-border-subtle flex-shrink-0",children:[(0,n.jsx)("span",{className:"flex-1 text-[11px] text-text-muted",children:d("editor.unsaved")}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),x.save()},disabled:x.saving,className:"px-2.5 py-1 flex items-center gap-1.5 text-[11px] font-medium text-white bg-brand-500 hover:bg-brand-600 rounded-brand disabled:opacity-50 transition-colors",children:[(0,n.jsx)(el.eM,{size:12})," ",d(x.saving?"editor.saving":"editor.save")]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:p&&m?(0,n.jsx)(iK,{kind:m,filePath:e,fileBus:s,content:x.content,reloadKey:h}):x.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:d("common.loading")}):(0,n.jsx)(iP,{filePath:e,content:x.content,onTextChanged:x.onTextChanged,onRegisterView:x.register,onSave:x.save,onCursorChange:a})})]})}function dd({workspace:e,fileBus:t,openedFiles:s,activeFile:l,onActivateFile:a,onCloseFile:i,onCloseOthers:o,onCloseAll:c,onOpenFile:d,onEditorStateChange:u,previewRequest:x}){let[m,p]=(0,r.useState)(()=>new Set),[f,h]=(0,r.useState)(null),b=(0,r.useRef)(new Map);(0,r.useEffect)(()=>{if(!m.size)return;let e=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[m.size]);let g=(0,r.useCallback)((e,t)=>{p(s=>{if(s.has(e)===t)return s;let n=new Set(s);return t?n.add(e):n.delete(e),n})},[]),v=(0,r.useCallback)((e,t)=>{t?b.current.set(e,t):b.current.delete(e)},[]),y=(0,r.useCallback)(e=>{if(!m.has(e))return i?.(e);h(e)},[m,i]),w=(0,r.useCallback)(async e=>{for(let t of s.filter(t=>t!==e&&m.has(t)))if(!1===await b.current.get(t)?.())return;e?o?.(e):c?.()},[s,m,o,c]),j=(0,r.useCallback)(async()=>{!1!==await b.current.get(f)?.()&&(h(null),i?.(f))},[f,i]),k=(0,r.useCallback)(()=>{h(null),i?.(f)},[f,i]);return l?(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-bg min-h-0",children:[(0,n.jsx)(da,{openedFiles:s,activeFile:l,dirtyFiles:m,onActivate:a,onClose:y,onCloseOthers:e=>w(e),onCloseAll:()=>w(null)}),(0,n.jsx)(di,{workspace:e,filePath:l}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.map(s=>(0,n.jsx)("div",{className:s===l?"h-full":"hidden",children:(0,n.jsx)(dc,{filePath:s,workspace:e,fileBus:t,isActive:s===l,onCursorChange:u,onDirtyChange:g,onRegisterSaver:v,previewSeq:x?.path===s?x.seq:0})},s))}),(0,n.jsx)(iv,{isOpen:!!f,fileName:f?.split("/").pop(),onSave:j,onDiscard:k,onCancel:()=>h(null)})]}):(0,n.jsx)("div",{className:"flex-1 flex flex-col bg-bg min-h-0",children:(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-text-muted gap-3 p-6",children:[(0,n.jsx)(el.Bm,{size:64,className:"opacity-40"}),(0,n.jsx)("div",{className:"text-sm",children:"Open a file from the Explorer to get started"}),(0,n.jsxs)("div",{className:"text-xs flex items-center gap-2",children:[(0,n.jsx)("kbd",{className:"px-2 py-0.5 bg-surface-2 border border-border rounded text-text-subtle font-mono",children:"Cmd/Ctrl+P"}),(0,n.jsx)("span",{children:"Quick Open"})]})]})})}function du({gitBranch:e,line:t,column:s,language:r,encoding:l,activeFile:a,sidebarVisible:i,onToggleSidebar:o,bottomVisible:c,onTogglePanel:d}){return(0,n.jsx)(lG,{left:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),o?.()},className:lY,title:i?"Hide Sidebar":"Show Sidebar",children:(0,n.jsx)(el.Ay,{name:i?"PanelLeftClose":"PanelLeftOpen",size:12})}),a&&(0,n.jsxs)("span",{className:lZ,children:[(0,n.jsx)(el.Zr,{size:12,className:"opacity-60"}),e||"no branch"]})]}),right:(0,n.jsxs)(n.Fragment,{children:[d&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d()},className:lY,title:c?"Hide Terminal":"Show Terminal",children:(0,n.jsx)(el.Ay,{name:"Terminal",size:12})}),a&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:lZ,children:`Ln ${t||1}, Col ${s||1}`}),(0,n.jsx)("span",{className:lZ,children:r||"plaintext"}),(0,n.jsx)("span",{className:lZ,children:l||"UTF-8"})]})]})})}let dx=tc()?"⌘":"Ctrl+",dm=[{id:"openExplorer",label:"View: Show Explorer",icon:"FolderOpen",shortcut:""},{id:"openSearch",label:"View: Show Search",icon:"Search",shortcut:""},{id:"openScm",label:"View: Show Source Control",icon:"GitBranch",shortcut:""},{id:"openSettings",label:"View: Show Settings",icon:"Settings",shortcut:""},{id:"toggleSidebar",label:"View: Toggle Sidebar Visibility",icon:"PanelLeft",shortcut:`${dx}B`},{id:"togglePanel",label:"View: Toggle Terminal Panel",icon:"Terminal",shortcut:`${dx}J`},{id:"closeAll",label:"View: Close All Editors",icon:"X",shortcut:""},{id:"switchWorkspace",label:"Workspaces: Switch Workspace",icon:"Folder",shortcut:""}];function dp({mode:e="files",onSetMode:t,workspace:s,fileBus:l,onClose:a,onOpenFile:i,onAction:o}){let[c,d]=(0,r.useState)(""),[u,x]=(0,r.useState)(0),[m,p]=(0,r.useState)([]),[f,h]=(0,r.useState)(!1),b=(0,r.useRef)(null),g=(0,r.useRef)(null),v=(0,r.useMemo)(()=>{let e=c.trim().toLowerCase();return e?dm.filter(t=>t.label.toLowerCase().includes(e)):dm},[c]),y="commands"===e?v:m;(0,r.useEffect)(()=>{x(0)},[e,c,m]),(0,r.useEffect)(()=>{if("files"!==e)return;let t=c.trim();if(!t||!l||!s){p([]),h(!1);return}return h(!0),g.current&&clearTimeout(g.current),g.current=setTimeout(async()=>{let e=await l.searchFiles(s,t);p(e?.success&&Array.isArray(e.files)?e.files:[]),h(!1)},200),()=>{g.current&&clearTimeout(g.current)}},[c,e,l,s]);let w=(0,r.useCallback)(s=>{let n=s.target.value;if("files"===e&&n.startsWith(">")){t?.("commands"),d(n.slice(1));return}d(n)},[e,t]),j=(0,r.useCallback)(t=>{let s=y[t];s&&((0,ed.e)(8),"commands"===e?o?.(s.id):i?.(s.path),a?.())},[y,e,o,i,a]),k=(0,r.useCallback)(e=>{if("Escape"===e.key){e.preventDefault(),a?.();return}if("ArrowDown"===e.key){e.preventDefault(),x(e=>Math.min(e+1,Math.max(y.length-1,0)));return}if("ArrowUp"===e.key){e.preventDefault(),x(e=>Math.max(e-1,0));return}"Enter"===e.key&&(e.preventDefault(),j(u))},[y.length,u,a,j]),N="files"===e?"Type `>` for commands":"Type `?` for help",C="files"===e?"Search files by name…":"Type a command…";return(0,n.jsx)("div",{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-[2px]",onMouseDown:a,children:(0,n.jsxs)("div",{className:"absolute top-20 left-1/2 -translate-x-1/2 w-[640px] max-w-[90vw] card-elev overflow-hidden",onMouseDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border",children:[(0,n.jsx)(el.Ay,{name:"commands"===e?"Command":"Search",size:16,className:"text-text-muted"}),(0,n.jsx)("input",{ref:b,autoFocus:!0,type:"text",value:c,onChange:w,onKeyDown:k,placeholder:C,className:"flex-1 bg-transparent outline-none border-0 text-text placeholder:text-text-muted text-sm"}),(0,n.jsx)("span",{className:"text-xs text-text-muted hidden sm:inline",children:N})]}),(0,n.jsx)("div",{className:"max-h-[400px] overflow-auto",children:0===y.length?"files"!==e||c.trim()?f?(0,n.jsxs)("div",{className:"px-4 py-6 text-center text-text-muted text-sm flex items-center justify-center gap-2",children:[(0,n.jsx)(el.Ay,{name:"Loader2",size:14,className:"animate-spin"}),"Searching…"]}):(0,n.jsx)("div",{className:"px-4 py-10 text-center text-text-muted text-sm",children:"No results"}):(0,n.jsx)("div",{className:"px-4 py-10 text-center text-text-muted text-sm",children:"Start typing to search files in workspace"}):(0,n.jsx)("ul",{className:"py-1",children:y.map((t,s)=>{let r=s===u;if("commands"===e)return(0,n.jsxs)("li",{onMouseEnter:()=>x(s),onClick:()=>j(s),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${r?"bg-brand-500/20 dark:bg-white/10 text-text":"text-text-muted hover:bg-surface-2"}`,children:[(0,n.jsx)(el.Ay,{name:t.icon,size:16}),(0,n.jsx)("span",{className:"flex-1 text-sm",children:t.label}),t.shortcut?(0,n.jsx)("kbd",{className:"text-xs text-text-muted px-1.5 py-0.5 bg-surface-2 rounded",children:t.shortcut}):null]},t.id);let l=t.name||(t.path?t.path.split(/[\\/]/).pop():""),a=t.relativePath||t.path||"";return(0,n.jsxs)("li",{onMouseEnter:()=>x(s),onClick:()=>j(s),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${r?"bg-brand-500/20 dark:bg-white/10 text-text":"text-text-muted hover:bg-surface-2"}`,children:[(0,n.jsx)(el.Ay,{name:"File",size:16}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-sm font-semibold text-text truncate",title:l,children:l}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",title:a,children:a})]})]},t.path||s)})})})]})})}function df({height:e,onResize:t,onClose:s,bus:l,connected:a,sessions:i=[],onCreateSession:o,onDeleteSession:c,onRenameSession:d}){let[u,x]=(0,r.useState)(i[0]?.id||null),m=(0,r.useRef)(null),p=(0,r.useRef)(!1);(0,r.useEffect)(()=>{0!==i.length&&(u&&i.find(e=>e.id===u)||x(i[0].id))},[i,u]),(0,r.useEffect)(()=>{0===i.length&&o&&!p.current&&(p.current=!0,o(e=>x(e))),i.length>0&&(p.current=!1)},[i.length,o]);let f=(0,r.useCallback)(()=>{(0,ed.e)(),o?.(e=>x(e))},[o]),h=(0,r.useCallback)((e,t)=>{e.stopPropagation(),(0,ed.e)(),c?.(t)},[c]),b=(0,r.useCallback)(e=>{e.preventDefault();let s=m.current?.parentElement;if(!s)return;let n=s.getBoundingClientRect(),r=e=>{if(0===e.buttons)return void l();let s=(n.bottom-e.clientY)/n.height*100;t(Math.max(O.kS,Math.min(O._C,s)))},l=()=>{window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",l),window.removeEventListener("blur",l),document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.body.style.cursor="row-resize",window.addEventListener("mousemove",r),window.addEventListener("mouseup",l),window.addEventListener("blur",l)},[t]);return(0,n.jsxs)("div",{ref:m,className:"bg-bg border-t border-border flex flex-col flex-shrink-0",style:{height:`${e}%`},children:[(0,n.jsx)("div",{onMouseDown:b,className:"h-1 cursor-row-resize bg-border hover:bg-surface-3 transition-colors -mt-1 relative z-10"}),(0,n.jsxs)("div",{className:"bg-surface border-b border-border flex items-center px-2 flex-shrink-0 overflow-x-auto",children:[(0,n.jsxs)("div",{className:"flex items-center text-text-muted text-xs uppercase tracking-wider px-2 py-1.5 mr-1",children:[(0,n.jsx)(el.BK,{size:12,className:"mr-1"}),"Terminal"]}),i.map(e=>{let t=e.id===u;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),x(e.id)},className:`group flex items-center gap-1.5 px-2 py-1.5 text-xs transition-colors max-w-[160px] ${t?"text-text bg-bg border-t-2 border-text-muted":"text-text-muted hover:text-text"}`,title:e.name,children:[(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)(el.X,{size:12,onClick:t=>h(t,e.id),className:"opacity-0 group-hover:opacity-100 hover:text-danger flex-shrink-0"})]},e.id)}),(0,n.jsx)("button",{onClick:f,className:"p-1 text-text-muted hover:text-text rounded hover:bg-surface-2 ml-1 flex-shrink-0",title:"New Terminal",children:(0,n.jsx)(el.FW,{size:14})}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s()},className:"p-1 text-text-muted hover:text-text rounded hover:bg-surface-2 ml-1 flex-shrink-0",title:"Close Panel",children:(0,n.jsx)(el.X,{size:14})})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[i.map((e,t)=>(0,n.jsx)("div",{className:"absolute inset-0",style:{display:e.id===u?"block":"none"},children:(0,n.jsx)(nq,{bus:l,connected:a,sessionId:e.id,isVisible:e.id===u,isFocused:e.id===u,showFocusBorder:!1,bgIndex:t})},e.id)),0===i.length&&(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:"Creating terminal session..."})]})]})}function dh({workspace:e,fileBus:t,onBack:s,onSwitchWorkspace:l,initialOpenedFiles:a,onOpenedFilesChange:i,bus:o,connected:c,sessions:d,onCreateTerminalSession:u,onDeleteTerminalSession:x,onRenameTerminalSession:m,initialActiveFile:p,viewType:f,openFileRef:h}){let[b,g]=tW(O.d5.activityPanel,O.Kr.explorer);(0,r.useEffect)(()=>{"git"===f?g(O.Kr.scm):"files"===f&&g(O.Kr.explorer)},[f,g]);let[v,y]=tW(O.d5.sidebarVisible,!0),[w,j]=tW(O.d5.sidebarWidth,O.Qw),[k,N]=tW(O.d5.bottomPanelVisible,!1),[C,S]=tW(O.d5.bottomPanelHeight,O.LN),T=(0,r.useRef)(null),[R,E]=(0,r.useState)(!1),$=(0,r.useCallback)(e=>{e.preventDefault();let t=T.current;if(!t)return;let s=t.getBoundingClientRect();E(!0);let n=e=>{if(0===e.buttons)return void r();let t=(e.clientX-s.left)/s.width*100;j(Math.max(O.hh,Math.min(O.vd,t)))},r=()=>{window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",r),window.removeEventListener("blur",r),document.body.style.userSelect="",document.body.style.cursor="",E(!1)};document.body.style.userSelect="none",document.body.style.cursor="col-resize",window.addEventListener("mousemove",n),window.addEventListener("mouseup",r),window.addEventListener("blur",r)},[j]),[z,M]=(0,r.useState)(a||[]),[P,A]=(0,r.useState)(p||a?.[0]||null),[I,D]=(0,r.useState)({line:1,column:1,language:"",encoding:"UTF-8"}),[L,B]=(0,r.useState)(""),[F,K]=(0,r.useState)({path:null,seq:0}),[W,_]=(0,r.useState)(!1),[H,U]=(0,r.useState)("commands");(0,r.useEffect)(()=>{i?.(z,P)},[z,P,i]);let q=(0,r.useCallback)((e,t={})=>{M(t=>[e,...t.filter(t=>t!==e)].slice(0,O.L0)),A(e),t.line&&D(e=>({...e,jumpLine:t.line,jumpColumn:t.column})),t.preview&&K(t=>({path:e,seq:t.seq+1}))},[]);(0,r.useEffect)(()=>{h&&(h.current=q)},[h,q]);let X=(0,r.useCallback)(e=>{M(t=>{let s=t.filter(t=>t!==e);return P===e&&A(s[0]||null),s})},[P]),V=(0,r.useCallback)(e=>{M([e]),A(e)},[]),J=(0,r.useCallback)(()=>{M([]),A(null)},[]);return(0,r.useEffect)(()=>{e&&t&&t.gitBranch?.(e).then(e=>{e?.success&&B(e.branch||"")}).catch(()=>{})},[e,t]),!function({onToggleSidebar:e,onSave:t,onCloseTab:s,onCommandPalette:n,onQuickOpen:l,onTogglePanel:a}={}){let i=(0,r.useRef)({});(0,r.useEffect)(()=>{i.current={onToggleSidebar:e,onSave:t,onCloseTab:s,onCommandPalette:n,onQuickOpen:l,onTogglePanel:a}}),(0,r.useEffect)(()=>{let e=e=>{let t=e.metaKey||e.ctrlKey,s=e.key.toLowerCase(),n=e.shiftKey,r=i.current;if(t&&n&&"p"===s||t&&!n&&"k"===s){e.preventDefault(),r.onCommandPalette?.();return}if(t&&!n&&"p"===s){e.preventDefault(),r.onQuickOpen?.();return}if(t&&!n&&"s"===s){e.preventDefault(),r.onSave?.();return}if(t&&!n&&"w"===s){e.preventDefault(),r.onCloseTab?.();return}if(t&&!n&&"b"===s){e.preventDefault(),r.onToggleSidebar?.();return}t&&!n&&"j"===s&&r.onTogglePanel&&(e.preventDefault(),r.onTogglePanel())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[])}({onToggleSidebar:()=>y(e=>!e),onTogglePanel:()=>N(e=>!e),onSave:()=>{window.dispatchEvent(new CustomEvent("fileExplorer:save"))},onCloseTab:()=>P&&X(P),onCommandPalette:()=>{U("commands"),_(!0)},onQuickOpen:()=>{U("files"),_(!0)}}),(0,n.jsxs)("div",{className:"h-full bg-bg flex flex-col",children:[(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)(c8,{activePanel:b,onSelectPanel:e=>{b===e&&v?y(!1):(g(e),y(!0))},onBack:s}),(0,n.jsxs)("div",{ref:T,className:"flex-1 min-w-0 min-h-0 flex relative",children:[(0,n.jsx)("div",{className:`bg-surface flex-shrink-0 overflow-hidden min-h-0 flex flex-col ${R?"":"transition-[width] duration-200 ease-out"}`,style:{width:v?`${w}%`:0},"aria-hidden":!v,children:(0,n.jsx)(dl,{activePanel:b,workspace:e,fileBus:t,onOpenFile:q,onSwitchWorkspace:l,activeFile:P})}),(0,n.jsx)("div",{onMouseDown:$,className:`cursor-col-resize bg-border hover:bg-brand-500/50 flex-shrink-0 ${R?"":"transition-[width,background-color] duration-200 ease-out"} ${v?"w-1":"w-0"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 min-h-0 flex flex-col",children:[(0,n.jsx)(dd,{workspace:e,fileBus:t,openedFiles:z,activeFile:P,onActivateFile:A,onCloseFile:X,onCloseOthers:V,onCloseAll:J,onOpenFile:q,onEditorStateChange:D,previewRequest:F}),k&&o&&(0,n.jsx)(df,{height:C,onResize:S,onClose:()=>N(!1),bus:o,connected:c,sessions:d,onCreateSession:u,onDeleteSession:x,onRenameSession:m})]})]})]}),(0,n.jsx)(du,{gitBranch:L,line:I.line,column:I.column,language:I.language,encoding:I.encoding,activeFile:P,sidebarVisible:v,onToggleSidebar:()=>y(e=>!e),bottomVisible:k,onTogglePanel:()=>N(e=>!e)}),W&&(0,n.jsx)(dp,{mode:H,workspace:e,fileBus:t,onClose:()=>_(!1),onOpenFile:q,onSetMode:U,onAction:e=>{_(!1),"toggleSidebar"===e?y(e=>!e):"togglePanel"===e?N(e=>!e):"closeAll"===e?J():"switchWorkspace"===e?l?.():"openExplorer"===e?(g(O.Kr.explorer),y(!0)):"openSearch"===e?(g(O.Kr.search),y(!0)):"openScm"===e?(g(O.Kr.scm),y(!0)):"openSettings"===e&&(g(O.Kr.settings),y(!0))}})]})}function db({isOpen:e,onClose:t}){let{t:s}=(0,eu.s)(),l=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!e)return;document.activeElement?.blur?.();let s=requestAnimationFrame(()=>{l.current?.focus()}),n=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),t())};return window.addEventListener("keydown",n,!0),()=>{cancelAnimationFrame(s),window.removeEventListener("keydown",n,!0)}},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:t}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",tabIndex:-1,className:"relative card-elev max-w-md w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200 outline-none",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:s("shortcuts.title")}),(0,n.jsx)("button",{ref:l,onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out focus:outline-none focus:ring-2 focus:ring-brand-500/40","aria-label":s("common.close"),children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable px-5 pb-5",children:(0,n.jsx)("ul",{className:"flex flex-col divide-y divide-border-subtle/40",children:ta.map(e=>(0,n.jsxs)("li",{className:"flex items-center justify-between gap-4 py-2 first:pt-1",children:[(0,n.jsx)("span",{className:"text-sm text-text min-w-0 truncate",children:s(`shortcuts.${e.id}`)}),(0,n.jsx)("span",{className:"inline-flex items-center gap-1 flex-shrink-0",children:tm(e).map(e=>(0,n.jsx)("kbd",{className:tu,children:e},e))})]},e.id))})})]})]}):null}function dg({retryStatus:e,approvalStatus:t,connected:s,onLogout:r,onRetryNow:l,suppress:a=!1,firstConnect:i=!1}){let{t:o}=(0,eu.s)(),c=t===A.J2.pending||t===A.J2.rejected;if(a&&!c)return null;let d=()=>{r?r():(sessionStorage.clear(),window.location.replace("/login"))};return t===A.J2.pending?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-[2px]",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(oP.A,{size:"lg"}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.waitingApproval")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.approvalDescription")}),(0,n.jsx)("p",{className:"text-text-muted text-sm mt-1",children:o("connection.approvalHint")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d()},className:"mt-4 w-full py-2 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.cancel")})]})})}):t===A.J2.rejected?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-[2px]",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto bg-red-500/20 rounded-full flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-8 h-8 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"})})}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.rejectedTitle")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.rejectedDescription")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d()},className:"mt-6 w-full py-3 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.backToLogin")})]})})}):s||!e?.isRetrying&&!e?.failed||i&&!e?.failed||e?.isRetrying&&e.attempt<A.si?null:(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-[2px]",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4",children:e.isRetrying?(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(oP.A,{size:"lg"}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.retrying")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.attemptOf",{n:e.attempt,total:e.maxAttempts})}),(0,n.jsx)("div",{className:"mt-4 w-full bg-surface-2 rounded-full h-2",children:(0,n.jsx)("div",{className:"bg-brand-500 h-2 rounded-full transition-all duration-300",style:{width:`${e.attempt/e.maxAttempts*100}%`}})}),l&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),l()},className:"mt-4 w-full py-2 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d()},className:"mt-2 w-full py-2 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.exit")})]}):(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto bg-red-500/20 rounded-full flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-8 h-8 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:o("connection.failed")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:o("connection.failedDescription",{n:e.maxAttempts})}),l&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),l()},className:"mt-6 w-full py-3 bg-brand-500 hover:bg-brand-600 text-white font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98]",children:o("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d()},className:`w-full py-3 bg-surface-2 hover:bg-surface-3 text-text font-medium rounded-brand transition-all duration-150 ease-out active:scale-[0.98] ${l?"mt-2":"mt-6"}`,children:o("connection.backToLogin")})]})})})}let dv={remote:el.VA,mobile:el.wO,sites:el.qz,notifications:el.Ir,folder:el.Bm,note:el.y8},dy=e=>{let t={hiddenHeaderButtons:e.hiddenHeaderButtons,toggleHeaderButton:e.toggleHeaderButton};for(let s of eJ.Fz)"pane"===s.group&&(t[s.storeKey]=e[s.storeKey],t[s.setterKey]=e[s.setterKey]);return t};function dw(){let e=(0,h.B)((0,F.k)(dy));return{buttons:eJ.Fz,isOn:t=>"header"===t.group?!e.hiddenHeaderButtons.includes(t.id):!!e[t.storeKey],toggle:t=>"header"===t.group?e.toggleHeaderButton(t.id):e[t.setterKey](!e[t.storeKey])}}function dj(e,t){let s=!!window.ReactNativeWebView,n=s||"u">typeof navigator&&"serviceWorker"in navigator&&"PushManager"in window,[l,a]=(0,r.useState)(()=>!!window.ReactNativeWebView&&"1"!==localStorage.getItem(eD)),[i,o]=(0,r.useState)(!1);(0,r.useEffect)(()=>{s||"serviceWorker"in navigator&&"PushManager"in window&&navigator.serviceWorker.ready.then(e=>e.pushManager?.getSubscription()).then(e=>a(!!e)).catch(()=>{})},[s]);let c=(0,r.useCallback)(async()=>{if(!i){if((0,ed.e)(),o(!0),l)await t?.(),a(!1);else{await e?.();let t=s;if(!s&&"serviceWorker"in navigator&&"PushManager"in window)try{let e=await navigator.serviceWorker.ready;t=!!await e.pushManager?.getSubscription()}catch{t=!1}a(t)}o(!1)}},[l,i,e,t,s]);return{supported:n,enabled:l,loading:i,toggle:c,isExpoWebView:s}}function dk(e,t){let s=(0,h.B)(e=>e.artifactEnabled),n=(0,h.B)(e=>e.setArtifactEnabled),l=!!(0,h.B)(e=>e.agentCaps?.artifact),[a,i]=(0,r.useState)(!1),o=(0,r.useRef)(!0);(0,r.useEffect)(()=>()=>{o.current=!1},[]),!t&&a&&i(!1);let c=(0,r.useCallback)(r=>{let l=e?.current;if(!l||!t||a)return;(0,ed.e)();let c="boolean"==typeof r?r:!s;i(!0),n(c),l.emit("setArtifactEnabled",{enabled:c},e=>{o.current&&(i(!1),e?.success||n(!c))})},[e,t,a,s,n]);return{supported:l,enabled:s,loading:a,toggle:c}}var dN=s(52345);let dC=dN.dI.filter(e=>tP[e.code]);function dS({isOpen:e,value:t,onSelect:s,onClose:l}){let{t:a}=(0,eu.s)();return((0,r.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[e,l]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:l}),(0,n.jsxs)("div",{className:"relative card-elev max-w-lg w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:a("voice.language")}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":a("common.close"),children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable p-3",children:[!1,(0,n.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:dC.map(e=>{let r=e.code===t;return(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.code,void((0,ed.e)(),s(t),l())},className:`px-2 py-2 rounded-brand flex items-center gap-2 transition-all duration-150 ease-out active:scale-[0.97] min-w-0 ${r?"bg-brand-500 text-white dark:bg-white dark:text-black":"text-text hover:bg-surface-2"}`,children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${e.country}.png`,alt:e.label,className:"w-[17px] h-[12px] object-cover rounded-[2px] flex-shrink-0",loading:"lazy"}),(0,n.jsx)("span",{className:"flex-1 text-sm font-medium truncate text-left",children:e.label}),r&&(0,n.jsx)(el.aJ,{size:14,className:"flex-shrink-0"})]},e.code)})})]})]})]}):null}let dT="w-full px-2.5 py-1.5 rounded bg-bg border border-border-subtle text-xs font-mono text-text placeholder-text-muted focus:outline-none focus:border-brand-500",dR="px-3 py-1.5 rounded-brand text-xs font-medium transition-colors",dE=[{id:"browser",mode:"browser",label:"Browser"},{id:"gemini",mode:"ai",label:y.gemini.label},{id:"openrouter",mode:"ai",label:y.openrouter.label},{id:"custom",mode:"ai",label:y.custom.label}];function d$({active:e,onClick:t,children:s}){return(0,n.jsx)("button",{type:"button",onClick:t,className:`px-2.5 py-1 rounded-brand text-[11px] border transition-colors ${e?"border-brand-500 bg-brand-500/10 text-brand-400 dark:border-white/30 dark:bg-white/10 dark:text-white":"border-border-subtle bg-surface-2/30 text-text-muted hover:text-text hover:bg-surface-2"}`,children:s})}function dz({state:e}){if(!e)return null;let t=e.busy?"text-text-muted animate-pulse":e.ok?"text-green-500":"text-red-400";return(0,n.jsx)("p",{className:`text-[11px] leading-relaxed break-words ${t}`,children:e.msg})}function dM(){let e=M(),{mode:t,setMode:s,preset:l,setEngine:a,setField:i}=e,{locale:o}=(0,eu.s)(),[c,d]=tD(o),[u,x]=(0,r.useState)(!1),[m,p]=(0,r.useState)(null),[f,h]=(0,r.useState)(null),b=m?.busy||f?.busy,v=dN.dI.find(e=>e.code===c),k="gemini"===l?e.geminiKeys.some(e=>e.trim()):"openrouter"===l?!!e.openrouterKey.trim():!!e.customKey.trim(),N="custom"===l?e.customModel:(e[`${l}Model`]||"").trim()||y[l].model,S=async()=>{(0,ed.e)(),p({busy:!0,msg:"Testing…"});try{let e=R(M.getState());await w(e,{model:e.model,messages:[{role:"user",content:"hi"}],max_tokens:1}),p({ok:!0,msg:"Key & model OK"})}catch(e){p({ok:!1,msg:j(e)})}},T=async()=>{if((0,ed.e)(),!k)return void h({ok:!1,msg:"Enter an API key first"});h({busy:!0,msg:"Recording…"});try{let e=await E(M.getState(),await C(),c);h({ok:!!e,msg:e||"(empty reply)"})}catch(e){h({ok:!1,msg:j(e)})}};return(0,n.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,n.jsx)("p",{className:"text-xs leading-relaxed text-text-muted",children:"Speak your prompts — much faster than typing. Gemini or OpenRouter is the most accurate."}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),x(!0)},className:"w-full px-3 py-2 rounded-brand bg-surface-2/50 text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors",children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:"Language"}),"auto"===c&&(0,n.jsx)("span",{className:"text-xs text-text-muted",children:"Auto"}),v&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 text-xs text-text-muted",children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${v.country}.png`,alt:"",className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{children:v.label})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:dE.map(e=>(0,n.jsx)(d$,{active:t===e.mode&&("browser"===e.mode||l===e.id),onClick:()=>{(0,ed.e)(),"browser"===e.mode?s("browser"):a("ai",e.id)},children:e.label},e.id))}),"browser"===t?(0,n.jsx)("p",{className:"text-xs leading-relaxed text-text-muted",children:"Uses the browser's built-in speech recognition (Chrome, Safari, Edge). Not available in Firefox."}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("p",{className:`text-[11px] leading-relaxed ${k?"text-text-muted":"text-amber-500"}`,children:["custom"===l?"Any OpenAI-compatible /chat/completions endpoint":`${y[l].note}`,!k&&" \xb7 No key yet"]}),"custom"!==l&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Model"}),(0,n.jsx)("input",{type:"text",value:e[`${l}Model`]||"",onChange:e=>i(`${l}Model`,e.target.value),placeholder:N,className:dT,autoComplete:"off"})]}),"gemini"===l&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-semibold text-text",children:"API keys"}),(0,n.jsxs)("a",{href:"https://aistudio.google.com/app/apikey",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-[11px] text-brand-500 hover:text-brand-400 hover:underline transition-colors",children:["AI Studio ",(0,n.jsx)(el.Gr,{size:10})]})]}),(0,n.jsxs)("div",{className:"flex flex-col gap-1.5",children:[e.geminiKeys.map((t,s)=>(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("input",{type:"password",value:t,onChange:t=>{let n=[...e.geminiKeys];n[s]=t.target.value,i("geminiKeys",n)},placeholder:`Key ${s+1}`,className:dT,autoComplete:"off"}),(0,n.jsx)("button",{type:"button",onClick:()=>i("geminiKeys",e.geminiKeys.filter((e,t)=>t!==s)),"aria-label":`Remove key ${s+1}`,className:"shrink-0 p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-colors",children:(0,n.jsx)(el.X,{size:14})})]},s)),(0,n.jsx)("button",{type:"button",onClick:()=>i("geminiKeys",[...e.geminiKeys,""]),className:"self-start text-[11px] text-brand-500 hover:text-brand-400 transition-colors",children:"+ Add key"})]})]}),"openrouter"===l&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-semibold text-text",children:"API key"}),(0,n.jsxs)("a",{href:"https://openrouter.ai/settings/keys",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-[11px] text-brand-500 hover:text-brand-400 hover:underline transition-colors",children:["OpenRouter ",(0,n.jsx)(el.Gr,{size:10})]})]}),(0,n.jsx)("input",{type:"password",value:e.openrouterKey,onChange:e=>i("openrouterKey",e.target.value),placeholder:"sk-or-…",className:dT,autoComplete:"off"})]}),"custom"===l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Endpoint"}),(0,n.jsx)("input",{type:"text",value:e.customEndpoint,onChange:e=>i("customEndpoint",e.target.value),placeholder:g,className:dT,autoComplete:"off"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"Model"}),(0,n.jsx)("input",{type:"text",value:e.customModel,onChange:e=>i("customModel",e.target.value),placeholder:"e.g. google/gemini-2.5-flash",className:dT,autoComplete:"off"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text mb-1",children:"API key"}),(0,n.jsx)("input",{type:"password",value:e.customKey,onChange:e=>i("customKey",e.target.value),placeholder:"sk-…",className:dT,autoComplete:"off"})]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:S,disabled:b,className:`${dR} bg-brand-500 hover:bg-brand-600 text-white disabled:opacity-50`,children:"Test key"}),(0,n.jsx)("button",{type:"button",onClick:T,disabled:b,className:`${dR} bg-surface-2/70 hover:bg-surface-2 text-text disabled:opacity-50`,children:"Test voice"})]}),m&&(0,n.jsx)(dz,{state:m}),f&&(0,n.jsx)(dz,{state:f})]}),u&&(0,n.jsx)(dS,{isOpen:u,value:c,onSelect:d,onClose:()=>x(!1)})]})}function dP({onClose:e}){return(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:e}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full max-h-[90dvh] flex flex-col animate-in zoom-in-95 duration-200",children:[(0,n.jsxs)("div",{className:"px-5 py-4 flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:"Voice input"}),(0,n.jsx)("button",{onClick:e,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":"Close",children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable px-5 pb-5 min-h-[320px]",children:(0,n.jsx)(dM,{})})]})]})}function dA({dense:e=!1}){let t=M(e=>e.enabled),s=M(e=>e.mode),l=M(e=>e.preset),a=M(e=>e.setEnabled),[i,o]=(0,r.useState)(!1),c="ai"===s?y[l]?.label||"AI":"Browser",d=()=>{(0,ed.e)(),o(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:e?"w-full py-1 text-sm text-text flex items-center gap-2.5 cursor-pointer select-none":"w-full px-3 py-2 rounded-brand flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 cursor-pointer select-none transition-colors",onClick:d,children:[(0,n.jsx)(el.GO,{size:16,className:`${e?"text-text":"text-brand-500 dark:text-white"} flex-shrink-0`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)("span",{className:"truncate",children:"Voice input"}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:c})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Voice configuration","aria-label":"Voice configuration",className:"shrink-0 px-2 h-7 flex items-center justify-center rounded-brand border border-border-subtle/60 hover:border-border hover:bg-surface-3/50 text-text-muted hover:text-text text-xs transition-colors",children:"Config"}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),a(!t)},"aria-label":"Toggle voice input",className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${t?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${t?"translate-x-4":"translate-x-0.5"}`})})]}),i&&(0,n.jsx)(dP,{onClose:()=>o(!1)})]})}function dI({onRemote:e,onFiles:t,onCommandNotes:s,onCommunity:l,onInstallApp:a,canInstall:i=!1,isInstalled:o=!1,onLogout:c,connected:d=!0,remoteAvailable:u=!1,showTheme:x=!1,theme:m="default",onThemeChange:p,hideActions:f=[],busRef:b=null,subscribeToPush:g=null,unsubscribeFromPush:v=null,onOpenBackgroundPicker:y}){let{t:w}=(0,eu.s)(),j=tO(),k=tb(e=>e.open),N=ev(e=>e.close),{connectionMode:C="tunnel",hostVersion:S,agentVersion:T}=ev(e=>e.context),R=dw(),E=e=>f.includes("headerButtons")?null:R.buttons.filter(t=>t.section===e&&"remote"!==t.id).map(e=>{let t=dv[e.id],s=R.isOn(e);return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),R.toggle(e)},className:"w-full py-1 hover:bg-surface-2 text-text rounded-brand text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(t,{className:"text-text shrink-0",size:16}),(0,n.jsxs)("div",{className:"flex flex-col flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm",children:w(e.labelKey)}),e.descKey&&(0,n.jsx)("span",{className:"text-xs text-text-muted",children:w(e.descKey)})]}),(0,n.jsx)("span",{className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${s?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-0.5"}`})})]},e.id)}),$=s8(e=>!1),z=(0,h.B)(e=>e.webglEnabled),M=(0,h.B)(e=>e.setWebglEnabled),P=(0,h.B)(e=>e.fontSize),A=(0,h.B)(e=>e.setFontSize),I=(0,h.B)(e=>e.terminalTheme),D=(0,h.B)(e=>e.setTerminalTheme),L=(0,h.B)(e=>e.terminalBackgrounds),{theme:B}=(0,nW.D)(),[F,K]=(0,r.useState)(!1),[O,W]=(0,r.useState)(!1),[_,H]=(0,r.useState)(!1),[U,q]=(0,r.useState)(!1),[X,V]=(0,r.useState)(!1),J=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!F)return;let e=e=>{J.current&&!J.current.contains(e.target)&&K(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[F]);let[G,Y]=(0,r.useState)(!1);(0,r.useEffect)(()=>{Y(window.innerWidth<768)},[]);let Z=dj(g,v),Q=dk(b,d),ee=Z.isExpoWebView||!!window.ReactNativeWebView||/9Remote-Mobile/i.test(navigator.userAgent),et=window.matchMedia("(display-mode: standalone)").matches||ee,es=ee&&!/iPad|iPhone|iPod/.test(navigator.userAgent),[en,er]=(0,r.useState)(()=>window.CURRENT_ORIENTATION||localStorage.getItem("expo_orientation")||"auto");(0,r.useEffect)(()=>{if(!es)return;let e=e=>{if(e){er(e);try{localStorage.setItem("expo_orientation",e)}catch{}}};window.handleScreenOrientationChange=e;try{let e=localStorage.getItem("expo_orientation");window.ReactNativeWebView?.postMessage(JSON.stringify(["portrait","auto"].includes(e)?{type:"SET_SCREEN_ORIENTATION",orientation:e}:{type:"GET_SCREEN_ORIENTATION"}))}catch{}return()=>{window.handleScreenOrientationChange===e&&(window.handleScreenOrientationChange=void 0)}},[es]);let ea=(0,r.useCallback)(e=>{(0,ed.e)(),er(e);try{localStorage.setItem("expo_orientation",e)}catch{}try{window.ReactNativeWebView?.postMessage(JSON.stringify({type:"SET_SCREEN_ORIENTATION",orientation:e}))}catch{}},[]),ei=(0,r.useCallback)(()=>{(0,ed.e)();try{window.ReactNativeWebView?.postMessage(JSON.stringify({type:"OPEN_RATING"}))}catch{}},[]);return(0,n.jsxs)("div",{className:"p-3 space-y-0.5",children:[!et&&!o&&a&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),a()},className:"w-full px-3 py-1.5 mb-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.f5,{className:"text-brand-500 flex-shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0 truncate",children:w("menu.installApp")}),i&&(0,n.jsx)("span",{className:"flex-shrink-0 px-2 py-0.5 bg-brand-500 text-white text-xs font-medium rounded-full",children:w("pwaGuide.installNow")})]}),Z.supported&&(0,n.jsxs)("button",{onClick:Z.toggle,disabled:Z.loading,className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 disabled:opacity-50 text-text rounded-brand-lg text-left flex items-center justify-between gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(el.Ir,{className:"text-brand-500",size:16}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsx)("span",{className:"text-sm",children:w("menu.notifications")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:w("menu.notificationsHint")})]})]}),Z.loading?(0,n.jsx)(el.kr,{className:"animate-spin text-text-muted",size:16}):(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Z.enabled?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${Z.enabled?"translate-x-4":"translate-x-0.5"}`})})]}),!f.includes("terminalSettings")&&(0,n.jsxs)("div",{ref:J,className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),K(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.BK,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.terminalSettings")}),(0,n.jsx)(el.yQ,{className:`text-text-muted transition-transform duration-200 ${F?"rotate-180":""}`,size:16})]}),F&&(0,n.jsxs)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),M(!z)},className:"w-full py-1 hover:bg-surface-2 text-text rounded-brand text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.VA,{className:"text-text",size:16}),(0,n.jsxs)("div",{className:"flex flex-col flex-1",children:[(0,n.jsx)("span",{className:"text-sm",children:w("menu.webgl")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:w("menu.webglHint")})]}),(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${z?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${z?"translate-x-4":"translate-x-0.5"}`})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 pt-1.5",children:[(0,n.jsx)(el.ZU,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.fontSize")}),(0,n.jsx)("select",{value:P??(G?12:14),onChange:e=>{(0,ed.e)(),A(Number(e.target.value))},className:"ml-auto bg-surface-2 text-text text-sm rounded-brand px-2 py-1 focus:outline-none",children:Array.from({length:G?7:9},(e,t)=>t+10).map(e=>(0,n.jsxs)("option",{value:e,children:[e,"px"]},e))})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(el.es,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.terminalTheme")}),(0,n.jsxs)("select",{value:I,onChange:e=>{(0,ed.e)(),D(e.target.value)},className:"ml-auto bg-surface-2 text-text text-xs rounded-brand px-2 py-1 max-w-[55%] focus:outline-none",children:[(0,n.jsx)("option",{value:"default",children:"Vesper (Default)"}),nR.g4.filter(e=>e.mode===B).map(e=>(0,n.jsx)("option",{value:e.key,children:e.label},e.key))]})]}),E("terminal")]})]}),(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),H(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.vv,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.settingsRemote")}),(0,n.jsx)(el.yQ,{className:`text-text-muted transition-transform duration-200 ${_?"rotate-180":""}`,size:16})]}),_&&(0,n.jsx)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:E("remote")})]}),(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),W(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.Kq,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.settingsMcp")}),(0,n.jsx)(el.yQ,{className:`text-text-muted transition-transform duration-200 ${O?"rotate-180":""}`,size:16})]}),O&&(0,n.jsxs)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:[(0,n.jsx)(dA,{dense:!0}),Q.supported&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)(el.jz,{className:"text-text shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0",children:w("menu.artifactPanel")}),(0,n.jsx)("button",{onClick:Q.toggle,disabled:Q.loading||!d,className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors disabled:opacity-60 ${Q.enabled?"bg-brand-500":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${Q.enabled?"translate-x-4":"translate-x-0.5"}`})})]}),(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-text-muted",children:w("menu.artifactHint")})]}),E("plugins")]})]}),"dark"===B&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),y?.()},className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.de,{className:"text-brand-500 flex-shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1 min-w-0",children:w("menu.terminalBackground")}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate max-w-[90px]","data-tip":L.length>1?`${(0,eJ.Pz)(L[0])} +${L.length-1}`:(0,eJ.Pz)(L[0]),children:L.length>1?`${(0,eJ.Pz)(L[0])} +${L.length-1}`:(0,eJ.Pz)(L[0])}),(0,n.jsx)(el.c_,{size:16,className:"text-text-muted flex-shrink-0"})]}),es&&(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),q(e=>!e)},className:"w-full px-3 py-1.5 hover:bg-surface-2 text-text text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.kt,{className:"text-brand-500 flex-shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:w("menu.orientation")}),(0,n.jsx)(el.yQ,{className:`text-text-muted transition-transform duration-200 ${U?"rotate-180":""}`,size:16})]}),U&&(0,n.jsx)("div",{className:"pl-6 pr-3 pb-1.5 space-y-1.5",children:[{id:"portrait",label:w("menu.orientationPortrait"),Icon:el.wO},{id:"auto",label:w("menu.orientationAuto"),Icon:el.kt}].map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>ea(e.id),className:"w-full py-1 hover:bg-surface-2 text-text rounded-brand text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(e.Icon,{className:"text-text",size:16}),(0,n.jsx)("span",{className:"text-sm flex-1",children:e.label}),en===e.id&&(0,n.jsx)(el.aJ,{size:16,className:"text-brand-500 flex-shrink-0"})]},e.id))})]}),$&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),N(),s8.getState().toggle()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(el.cC,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:"Jarvis"})]}),s&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(el.iU,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.commandNotes")})]}),"mouse"===j&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),N(),k()},className:"w-full px-3 py-1.5 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out bg-surface hover:bg-surface-2 text-text active:scale-[0.99]",children:[(0,n.jsx)(el.s3,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("shortcuts.menuLabel")})]}),l&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),l()},className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.zW,{className:"text-brand-500",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.community")})]}),ee&&window.DEVICE_INFO?.platform!=="ios"&&(0,n.jsxs)("button",{onClick:ei,className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.FE,{className:"text-brand-500 flex-shrink-0",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.rateApp")})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),V(!0),setTimeout(()=>window.location.reload(),150)},disabled:X,className:"w-full px-3 py-1.5 bg-surface hover:bg-surface-2 text-text rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99] disabled:opacity-70",children:[(0,n.jsx)(el.e9,{size:16,className:`text-brand-500 ${X?"animate-spin":""}`}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.reload")})]}),c&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),c()},className:"w-full px-3 py-1.5 bg-surface hover:bg-red-500/15 text-text hover:text-red-400 rounded-brand-lg text-left flex items-center gap-2.5 transition duration-150 ease-out active:scale-[0.99]",children:[(0,n.jsx)(el.nU,{className:"text-red-400",size:16}),(0,n.jsx)("span",{className:"text-sm",children:w("menu.logout")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 mt-4 mr-1",children:["local"===C&&(0,n.jsx)("span",{className:"text-xs font-semibold px-2 py-0.5 rounded-full bg-green-500/15 text-green-400",children:"LAN"}),(0,n.jsxs)("p",{className:"text-text-muted text-sm",children:[w("menu.version")," ","3.0.39",S||T?` / 9Remote ${S||T}`:""]})]})]})}var dD=s(2163);function dL(){if("u"<typeof navigator)return"unknown";let e=navigator.userAgent.toLowerCase();return/iphone|ipad|ipod/.test(e)?"ios":/android/.test(e)?"android":/mac/.test(e)?"macos":/win/.test(e)?"windows":"desktop"}function dB(){let{t:e}=(0,eu.s)(),[t]=(0,r.useState)(dL),[s,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)("idle"),o=ev(e=>e.context.apiKey),c=eY(e=>e.canInstall),d=eY(e=>e.isInstalled),u=eY(e=>e.install),x=async()=>{i("installing"),i("accepted"===await u()?"done":"idle")},m=async e=>{try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return!1}},p=async()=>{!o||await m(o)&&(l(!0),setTimeout(()=>l(!1),2e3))},f=+!!o,h=()=>o?(0,n.jsxs)("div",{className:"flex items-start gap-3 mb-4",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:"1"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-2",children:e("pwaGuide.copyYourKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm mb-2",children:e("pwaGuide.copyKeyHint")}),(0,n.jsxs)("div",{className:`w-full flex items-center justify-between gap-2 px-3 py-2.5 rounded-brand border transition-colors ${s?"bg-green-500/10 border-green-500/30":"bg-bg border-border hover:border-brand-500/50 focus-within:border-brand-500/50"}`,children:[(0,n.jsx)("button",{type:"button",onClick:p,className:"flex-1 min-w-0 text-left bg-transparent outline-none border-0 p-0 cursor-pointer","aria-label":e("pwaGuide.tapToCopyApiKey"),children:(0,n.jsx)("code",{className:"block text-sm text-text font-mono truncate",children:(0,dD.o)(o)})}),(0,n.jsx)("button",{type:"button",onClick:p,className:`flex items-center gap-1 text-sm flex-shrink-0 ${s?"text-green-400":"text-brand-500"}`,children:s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el.aJ,{size:14})," ",e("pwaGuide.copiedBang")]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(el.QR,{size:14})," ",e("pwaGuide.copy")]})})]})]})]}):null,b=()=>c?(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.installNow")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.installNowHint")})]}),(0,n.jsxs)("button",{type:"button",onClick:x,disabled:"installing"===a,className:"flex-shrink-0 flex items-center gap-1 px-3 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-medium rounded-brand transition-all duration-150 active:scale-[0.97] disabled:opacity-70 disabled:cursor-wait",children:[(0,n.jsx)(el.f5,{size:14}),"installing"===a?e("pwaGuide.installing"):e("pwaGuide.installNow")]})]}):null;return d?(0,n.jsx)("div",{className:"p-6",children:(0,n.jsxs)("div",{className:"text-center py-12",children:[(0,n.jsx)("div",{className:"inline-flex p-4 bg-green-500/10 rounded-brand-lg mb-4",children:(0,n.jsx)(el.aJ,{className:"text-green-500",size:48})}),(0,n.jsx)("p",{className:"text-text font-semibold mb-2",children:e("pwaGuide.alreadyInstalled")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.alreadyInstalledHint")})]})}):(0,n.jsxs)("div",{className:"p-6 space-y-6",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 pb-4 border-b border-border",children:[(0,n.jsx)("div",{className:"p-2 bg-brand-500/10 rounded-brand",children:(()=>{switch(t){case"ios":case"android":return(0,n.jsx)(el.wO,{className:"text-brand-500",size:24});default:return(0,n.jsx)(el.VA,{className:"text-brand-500",size:24})}})()}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-text font-medium",children:e("pwaGuide.installationGuide")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:(()=>{switch(t){case"ios":return e("pwaGuide.iosPlatform");case"android":return e("pwaGuide.androidPlatform");case"macos":return e("pwaGuide.macosPlatform");case"windows":return e("pwaGuide.windowsPlatform");default:return e("pwaGuide.desktopPlatform")}})()})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-text font-medium mb-4",children:e("pwaGuide.installationSteps")}),(()=>{switch(t){case"ios":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1.5",children:"Download 9Remote on App Store"}),(0,n.jsxs)("a",{href:"https://apps.apple.com/us/app/9remote/id6796664210",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-semibold rounded-brand transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.81-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M15.97 6.38c.62-.75 1.04-1.8 0.92-2.85-.9.04-2 .6-2.65 1.35-.58.66-1.09 1.73-.95 2.76.99.08 2.03-.51 2.68-1.26z"})}),"Get on App Store"]})]})]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]})]});case"android":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1.5",children:"Download 9Remote on Google Play"}),(0,n.jsxs)("a",{href:"https://play.google.com/store/apps/details?id=cc.remote9.app&pli=1",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-500 hover:bg-brand-600 text-white text-sm font-semibold rounded-brand transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M3.609 1.814L13.793 12 3.61 22.186a2.128 2.128 0 0 1-.22-.964V2.778c0-.36.08-.694.22-.964zm11.233 11.234l2.584 2.584-11.834 6.83 9.25-9.414zm0-2.096L5.592 1.538l11.834 6.83-2.584 2.584zm1.485 1.048l3.633 2.098a1.328 1.328 0 0 0 0-2.296l-3.633-2.098-1.048 1.048 1.048 1.048z"})}),"Get on Google Play"]})]})]}),c&&(0,n.jsxs)("div",{className:"pt-2 border-t border-border",children:[(0,n.jsx)("p",{className:"text-xs text-text-muted mb-2",children:"Or install directly as Web App (PWA):"}),b()]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]})]});case"macos":case"windows":case"desktop":return(0,n.jsxs)("div",{className:"space-y-4",children:[h(),b(),c&&(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.openAppPasteKey")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.openAppPasteKeyHint")})]})]}),!c&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:1+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.lookInstallIcon")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.lookInstallIconHint")})]})]}),(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-brand-500/10 rounded-brand flex items-center justify-center text-brand-500 font-semibold",children:2+f}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("p",{className:"text-text font-medium mb-1",children:e("pwaGuide.clickInstallPaste")}),(0,n.jsx)("p",{className:"text-text-muted text-sm",children:e("pwaGuide.clickInstallPasteHint")})]})]}),(0,n.jsx)("div",{className:"mt-6 p-3 bg-blue-500/10 rounded-brand",children:(0,n.jsxs)("p",{className:"text-blue-200 text-sm",children:["\uD83D\uDCA1 ",e("pwaGuide.alternativeHint")]})})]})]});default:return(0,n.jsx)("p",{className:"text-text-muted text-center py-8",children:e("pwaGuide.loadingPlatform")})}})()]})]})}let dF=[{command:"npm i 9router -g"},{command:"curl -fsSL https://claude.ai/install.sh | bash"},{command:"npm i -g @openai/codex"},{command:"curl -fsSL https://opencode.ai/install | bash"}],{storageKey:dK,maxNotes:dO}={storageKey:"9remote_command_notes_v2",maxNotes:50};function dW({isOpen:e,onClose:t}){let{t:s}=(0,eu.s)(),{notes:l,addNote:a,updateNote:i,deleteNote:o}=function(){let[e,t]=(0,r.useState)([]),s=(0,r.useCallback)(()=>{try{let e=localStorage.getItem(dK);if(e)return JSON.parse(e);let t=dF.map((e,t)=>({id:`default_${t}`,...e}));return localStorage.setItem(dK,JSON.stringify(t)),t}catch(e){return console.error("Failed to load command notes:",e),[]}},[]);(0,r.useEffect)(()=>{t(s())},[s]);let n=(0,r.useCallback)(e=>{try{localStorage.setItem(dK,JSON.stringify(e)),t(e)}catch(e){console.error("Failed to persist command notes:",e)}},[]),l=(0,r.useCallback)(t=>{n([{id:Date.now().toString(),command:t},...e].slice(0,dO))},[e,n]),a=(0,r.useCallback)((t,s)=>{n(e.map(e=>e.id===t?{...e,command:s}:e))},[e,n]),i=(0,r.useCallback)(t=>{n(e.filter(e=>e.id!==t))},[e,n]);return{notes:e,addNote:l,updateNote:a,deleteNote:i}}(),[c,d]=(0,r.useState)(null),[u,x]=(0,r.useState)(null),[m,p]=(0,r.useState)(""),f=(0,r.useRef)(null),[h,b]=(0,r.useState)(null);(0,r.useEffect)(()=>{e&&setTimeout(()=>f.current?.focus(),100)},[e,u]),(0,r.useEffect)(()=>{if(!e||!window.visualViewport)return;let t=window.visualViewport,s=()=>b(t.height);return s(),t.addEventListener("resize",s),t.addEventListener("scroll",s),()=>{t.removeEventListener("resize",s),t.removeEventListener("scroll",s)}},[e]),(0,r.useEffect)(()=>{let s=s=>{"Escape"===s.key&&e&&t()};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[e,t]);let g=(0,r.useCallback)((e,t)=>{(0,ed.e)(),navigator.clipboard?.writeText(t).catch(()=>{}),d(e),setTimeout(()=>d(null),2e3)},[]),v=(0,r.useCallback)(e=>{(0,ed.e)(),x(e.id),p(e.command)},[]),y=(0,r.useCallback)(()=>{m.trim()&&((0,ed.e)(),u?(i(u,m.trim()),x(null)):a(m.trim()),p(""))},[m,u,a,i]),w=(0,r.useCallback)(e=>{(0,ed.e)(),o(e),u===e&&(x(null),p(""))},[o,u]),j=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),y())},[y]);return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:t}),(0,n.jsxs)("div",{className:"absolute top-0 right-0 w-[85vw] sm:w-96 max-w-md bg-surface border-l border-border shadow-2xl flex flex-col slide-in-right",style:{height:h?`${h}px`:"100%"},onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0 safe-area-top",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(el.iU,{size:20,className:"text-brand-500"}),(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("commandNotes.title")})]}),(0,n.jsx)("button",{onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable",children:[0===l.length&&(0,n.jsxs)("div",{className:"text-center text-text-muted py-8",children:[(0,n.jsx)(el.iU,{size:32,className:"mx-auto mb-3 text-text-muted"}),(0,n.jsx)("p",{className:"text-sm",children:s("commandNotes.noSavedCommands")}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-1",children:s("commandNotes.addFirstBelow")})]}),l.map(e=>(0,n.jsx)("div",{className:"px-4 py-3 border-b border-border/50 hover:bg-surface-2/30 transition-colors group",children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>g(e.id,e.command),title:s("commandNotes.clickToCopy"),children:[(0,n.jsx)("p",{className:"text-sm text-text font-mono break-all",children:e.command}),c===e.id&&(0,n.jsx)("span",{className:"text-xs text-green-400 mt-1 inline-block",children:s("commandNotes.copiedBang")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:()=>g(e.id,e.command),className:"p-1.5 text-text-muted hover:text-brand-400 rounded transition-colors",title:s("commandNotes.copy"),children:c===e.id?(0,n.jsx)(el.aJ,{size:14,className:"text-green-400"}):(0,n.jsx)(el.QR,{size:14})}),(0,n.jsx)("button",{onClick:()=>v(e),className:"p-1.5 text-text-muted hover:text-brand-400 rounded transition-colors",title:s("commandNotes.edit"),children:(0,n.jsx)(el.gH,{size:14})}),(0,n.jsx)("button",{onClick:()=>w(e.id),className:"p-1.5 text-text-muted hover:text-red-400 rounded transition-colors",title:s("commandNotes.delete"),children:(0,n.jsx)(el.TB,{size:14})})]})]})},e.id))]}),(0,n.jsx)("div",{className:"px-3 py-3 border-t border-border flex-shrink-0 safe-area-bottom",children:(0,n.jsxs)("div",{className:"flex gap-2 items-end",children:[(0,n.jsx)("textarea",{ref:f,value:m,onChange:e=>p(e.target.value),onKeyDown:j,placeholder:u?s("commandNotes.editCommandPlaceholder"):s("commandNotes.addCommandPlaceholder"),rows:2,className:"flex-1 bg-surface-2 rounded-brand px-3 py-2 text-text text-sm placeholder-text-muted focus:outline-none focus:ring-2 focus:ring-brand-500/40 transition-all duration-150 ease-out font-mono resize-none"}),(0,n.jsx)("button",{onClick:y,disabled:!m.trim(),className:"p-2.5 bg-brand-600 hover:bg-brand-500 disabled:bg-surface-2 disabled:cursor-not-allowed text-text rounded-brand transition-colors flex-shrink-0",title:u?s("commandNotes.update"):s("commandNotes.add"),children:(0,n.jsx)(el.Vn,{size:18})})]})})]})]}):null}let d_=[{id:"facebook",label:"Facebook Group",description:"Report bugs & suggest features to 9Team community",url:"https://www.facebook.com/groups/9teamvn",icon:"Facebook",color:"#1877F2"},{id:"github",label:"GitHub",description:"Source code & issue tracker",url:"https://github.com/decolua/9remote",icon:"Github",color:"#ffffff"}];function dH({isOpen:e,onClose:t}){let{t:s}=(0,eu.s)();return((0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&t?.()};return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-md card-elev slide-in-top",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("community.title")}),(0,n.jsx)("button",{onClick:t,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("common.close"),children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-2",children:[(0,n.jsx)("p",{className:"text-text-muted text-sm px-1 mb-2",children:s("community.description")}),d_.map(e=>(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.url,void((0,ed.e)(),window.open(t,"_blank","noopener,noreferrer"))},className:"w-full px-4 py-3 bg-surface-2 hover:bg-surface-3 text-text rounded-brand-lg text-left flex items-center gap-3 transition-all duration-150 ease-out active:scale-[0.99] group",children:[(0,n.jsx)("span",{className:"flex items-center justify-center w-10 h-10 rounded-brand flex-shrink-0",style:{backgroundColor:`${e.color}1a`,color:e.color},children:(0,n.jsx)(el.Ay,{name:e.icon,size:22})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium truncate",children:e.label}),e.description&&(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",children:e.description})]}),(0,n.jsx)(el.Gr,{className:"text-text-muted group-hover:text-brand-500 flex-shrink-0",size:18})]},e.id))]})]})]}):null}var dU=s(18057);let dq=[{id:"general",labelKey:"menu.settingsGeneral",icon:"Settings"},{id:"system",labelKey:"menu.settingsSystem",icon:"Monitor"},{id:"appearance",labelKey:"menu.settingsAppearance",icon:"Palette"},{id:"terminal",labelKey:"menu.settingsTerminalTab",icon:"Terminal"},{id:"background",labelKey:"menu.terminalBackground",icon:"Image"},{id:"voice",labelKey:"menu.settingsVoice",icon:"Mic"},{id:"remote",labelKey:"menu.settingsRemote",icon:"Link2"},{id:"mcp",labelKey:"menu.settingsMcp",icon:"Zap"},{id:"debug",labelKey:"menu.settingsDebug",icon:"Bug"},{id:"shortcuts",labelKey:"shortcuts.menuLabel",icon:"Keyboard"}],dX="browserUseConfig",dV={enabled:!1,preset:"free",endpoint:"",model:"",apiKey:"",minConfidence:.55,headless:!0,mode:"own",hostKeySet:!1};function dJ(e){try{localStorage.setItem(dX,JSON.stringify({...e,apiKey:""}))}catch{}}let dG=(0,b.v)((e,t)=>({...function(){try{let e=localStorage.getItem(dX);return e?{...dV,...JSON.parse(e)}:{...dV}}catch{return{...dV}}}(),setConfig:s=>{let n={...t(),...s};e(n),dJ(n);try{let e=u.d.getState().bus;e?.emit?.("setBrowserUseConfig",{browserUseConfig:{enabled:n.enabled,preset:n.preset,endpoint:n.endpoint,model:n.model,apiKey:n.apiKey,minConfidence:n.minConfidence,headless:n.headless,mode:n.mode}})}catch{}},syncFromHost:s=>{let n={...t(),enabled:s.enabled??t().enabled,preset:s.preset??t().preset,endpoint:s.endpoint??"",model:s.model??"",minConfidence:"number"==typeof s.minConfidence?s.minConfidence:t().minConfidence,headless:s.headless??t().headless,mode:s.mode??t().mode,apiKey:"__SET__"===s.apiKey?t().apiKey:s.apiKey||"",hostKeySet:"__SET__"===s.apiKey};e(n),dJ(n)}})),dY="chrome://inspect/#remote-debugging",dZ=["Find flights from Tokyo to Paris next month and compare prices","Find today's top 3 trending AI repos on GitHub and summarize them","Open Hacker News and check today's 3 top tech stories","Log into the portal, go to Payments and download the latest PDF invoice"];function dQ({busRef:e}){let t=dG(),s=(0,r.useCallback)((t,s)=>new Promise(n=>{let r=e?.current||u.d.getState().bus;if(!r?.emit)return n({ok:!1,error:"no bus"});r.emit("browserUse:invoke",{action:t,payload:s},e=>n(e||{ok:!1,error:"no reply"}))}),[e]),[l,a]=(0,r.useState)(null),[i,o]=(0,r.useState)(!1),[c,d]=(0,r.useState)(!1),[x,m]=(0,r.useState)(null);(0,r.useEffect)(()=>{s("config.get").then(e=>{e.ok&&e.config&&t.syncFromHost(e.config)})},[]);let p=async()=>{o(!0);let e=await s("attach.status",{});e.ok&&a(e),o(!1)},f=async()=>{try{await navigator.clipboard.writeText(dY),d(!0),setTimeout(()=>d(!1),1500)}catch{}};(0,r.useEffect)(()=>{if("attach"!==t.mode)return;let e=setTimeout(p,0);return()=>clearTimeout(e)},[t.mode]);let h=async e=>{(0,ed.e)();try{await navigator.clipboard.writeText(e),m(e),setTimeout(()=>m(null),1500)}catch{}};return(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("label",{className:"block text-xs text-text-muted",children:["Browser mode",(0,n.jsxs)("select",{value:t.mode||"own",onChange:e=>{var n;return n={mode:e.target.value},void(t.setConfig(n),s("config.set",n))},className:"mt-1 w-full px-2 py-1.5 bg-surface-2 rounded-brand text-sm text-text",children:[(0,n.jsx)("option",{value:"own",children:"Own browser — isolated profile (default, safe)"}),(0,n.jsx)("option",{value:"attach",children:"Real browser — attach via debug mode"})]})]}),"attach"===t.mode&&(0,n.jsxs)("div",{className:"rounded-brand border border-border-subtle p-2.5 space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,n.jsxs)("span",{className:`flex items-center gap-1.5 text-xs font-medium ${l?.available?"text-emerald-500":"text-amber-500"}`,children:[(0,n.jsx)("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${l?.available?"bg-emerald-500":"bg-amber-500"}`}),l?l.available?`Attached \xb7 port ${l.port}`:"Not attached":"Checking…"]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("button",{onClick:()=>s("attach.open",{}),title:"Open the debug opt-in page in Chrome",className:"px-2 py-1 bg-brand-500 text-white rounded-brand text-xs",children:"Open debug page"}),(0,n.jsx)("button",{onClick:p,disabled:i,className:"px-2 py-1 bg-surface-2 rounded-brand text-xs text-text-muted disabled:opacity-40",children:i?"…":"Recheck"})]})]}),l&&!l.available&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 px-2 py-1 bg-surface-2 rounded-brand text-[11px] text-text truncate select-all",children:dY}),(0,n.jsx)("button",{onClick:f,className:"shrink-0 px-2 py-1 bg-surface-2 rounded-brand text-xs text-text-muted",children:c?"Copied":"Copy"})]}),(0,n.jsx)("ol",{className:"list-decimal ml-4 text-[11px] text-text-muted space-y-0.5",children:(l.guide||[]).map((e,t)=>(0,n.jsx)("li",{children:e},t))})]})]}),(0,n.jsxs)("div",{className:"space-y-1.5",children:[(0,n.jsx)("span",{className:"block text-xs font-medium text-text-muted",children:"Example prompts (click to copy)"}),(0,n.jsx)("div",{className:"rounded-brand border border-border-subtle p-1 space-y-0.5 bg-surface-2/30",children:dZ.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>h(e),className:"w-full text-left px-2.5 py-1.5 rounded hover:bg-surface-2/80 flex items-center justify-between gap-2 group transition-colors",children:[(0,n.jsx)("span",{className:"text-[11.5px] text-text truncate font-mono",children:e}),(0,n.jsx)("span",{className:"flex-shrink-0 text-text-muted group-hover:text-text",children:x===e?(0,n.jsx)(el.aJ,{size:13,className:"text-emerald-500"}):(0,n.jsx)(el.QR,{size:13})})]},e))})]})]})}function d0({isOpen:e,onClose:t,busRef:s,inline:l=!1}){let{t:a}=(0,eu.s)(),i=(0,h.B)(e=>e.terminalBackgrounds);(0,h.B)(e=>e.setTerminalBackgrounds);let o=(0,h.B)(e=>e.terminalBackgroundOpacity),c=(0,h.B)(e=>e.setTerminalBackgroundOpacity),d=(0,h.B)(e=>e.customBackgrounds),{saving:u,error:x,setError:m,fileInput:p,openPicker:f}=sU(s),[b,g]=(0,r.useState)(()=>window.innerWidth>=eJ.jK);(0,r.useEffect)(()=>{let e=()=>g(window.innerWidth>=eJ.jK);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>{if(!e)return;let s=e=>{"Escape"===e.key&&(m(""),t())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e,t,m]);let v=()=>{m(""),t()};if(!l&&!e)return null;let y=o??eJ._z,{min:w,max:j,step:k}=eJ.DW,N=`${(y-w)/(j-w)*100}%`,C=(0,eJ.IJ)(i,d),S=(e,t,s)=>{let r="none"===e,l=r?-1:C.indexOf(e),a=r?0===C.length:-1!==l;return(0,n.jsxs)("button",{onClick:()=>(e=>{(0,ed.e)();let{terminalBackgrounds:t,setTerminalBackgrounds:s}=h.B.getState();s("none"===e?[]:t.includes(e)?t.filter(t=>t!==e):[...t,e])})(e),className:"group relative block w-full aspect-[9/16] rounded-2xl overflow-hidden transition-transform duration-200 ease-out active:scale-[0.97] shadow-sm",children:[s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("img",{src:s,alt:t,className:"absolute inset-0 h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.03]",loading:"lazy"}),(0,n.jsx)("span",{className:"pointer-events-none absolute inset-0",style:{background:`rgba(0,0,0,${eJ.t})`}}),(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 h-1/4 bg-gradient-to-t from-black/75 to-transparent"}),(0,n.jsx)("span",{className:"absolute bottom-2 left-0 right-0 px-2 text-xs font-medium text-white truncate",children:t})]}):(0,n.jsxs)("span",{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 transition-colors ${a?"bg-brand-500/10 text-brand-500 dark:bg-white/10 dark:text-white":"bg-surface-2 text-text-muted group-hover:text-text"}`,children:[(0,n.jsx)(el.P6,{size:24,strokeWidth:1.75}),(0,n.jsx)("span",{className:"text-xs font-medium",children:t})]}),(0,n.jsx)("span",{className:`pointer-events-none absolute inset-0 rounded-2xl transition-shadow duration-200 ${a?"ring-1 ring-inset ring-brand-500 dark:ring-white/60":"ring-1 ring-inset ring-white/15 group-hover:ring-brand-500/60"}`}),a&&!r&&(0,n.jsx)("span",{className:"absolute top-2 right-2 flex items-center justify-center w-6 h-6 bg-brand-500 rounded-full shadow-lg text-white text-xs font-semibold",children:l+1})]})},T=(0,n.jsxs)("div",{className:l||b?"grid grid-cols-3 gap-3":"grid grid-cols-2 gap-3",children:[Object.entries(eJ.vk).map(([e,t])=>(0,n.jsx)("div",{children:S(e,t.label,t.src)},e)),d.map(e=>(0,n.jsxs)("div",{className:"relative",children:[S(`custom:${e.id}`,a("menu.bgCustomLabel"),e.dataUrl),(0,n.jsx)("button",{onClick:()=>{var t;let n;return t=e.id,(0,ed.e)(),n=s?.current,void(n?.emit&&n.emit("bg:delete",{id:t},e=>{if(!e?.success)return void m(e?.error||a("menu.bgDeleteFailed"));let s=`custom:${t}`,{customBackgrounds:n,setCustomBackgrounds:r,terminalBackgrounds:l,setTerminalBackgrounds:i}=h.B.getState();r(n.filter(e=>e.id!==t)),i(l.filter(e=>e!==s))}))},className:"absolute top-2 left-2 flex items-center justify-center w-7 h-7 rounded-full bg-black/55 text-white backdrop-blur-sm hover:bg-red-500/80 transition-colors","aria-label":a("common.delete"),children:(0,n.jsx)(el.X,{size:13})})]},`custom:${e.id}`)),(0,n.jsxs)("button",{onClick:f,disabled:u,className:"group relative block w-full aspect-[9/16] rounded-2xl overflow-hidden border-2 border-dashed border-border flex flex-col items-center justify-center gap-2 text-text-muted hover:border-brand-500 hover:text-brand-500 transition-colors disabled:opacity-40",children:[u?(0,n.jsx)(el.kr,{size:24,className:"animate-spin"}):(0,n.jsx)(el.FW,{size:24,strokeWidth:1.75}),(0,n.jsx)("span",{className:"text-xs font-medium",children:a("menu.bgAdd")})]})]}),R=C.length>0&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-3 px-1 pt-1",children:[(0,n.jsx)("span",{className:"text-xs text-text flex-shrink-0",children:a("menu.bgDim")}),(0,n.jsx)("input",{type:"range",min:w,max:j,step:k,value:y,onChange:e=>c(Number(e.target.value)),className:"brand-range flex-1 min-w-0",style:{"--pct":N},"aria-label":a("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums flex-shrink-0",children:[Math.round(100*y),"%"]})]}),E=C.length>0&&(0,n.jsxs)("div",{className:"flex-shrink-0 border-t border-border px-5 pt-3 pb-[max(1.25rem,env(safe-area-inset-bottom))]",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-sm text-text",children:a("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums",children:[Math.round(100*y),"%"]})]}),(0,n.jsx)("input",{type:"range",min:w,max:j,step:k,value:y,onChange:e=>c(Number(e.target.value)),className:"brand-range brand-range-lg",style:{"--pct":N},"aria-label":a("menu.bgDim")})]}),$=x&&(0,n.jsx)("div",{className:`px-3 py-2 rounded-brand bg-red-500/10 border border-red-500/30 text-red-500 text-xs break-all ${l?"":"flex-shrink-0 mx-5 mb-2"}`,children:x});return l?(0,n.jsxs)("div",{className:"h-full flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[T,$]}),R,p]}):(0,sd.createPortal)((0,n.jsxs)("div",{className:b?"fixed inset-0 z-[60] flex items-center justify-center p-4":"fixed inset-0 z-[60] flex flex-col justify-end",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] animate-in fade-in duration-200",onClick:v}),(0,n.jsxs)("div",{className:b?"relative w-full max-w-lg max-h-[80vh] card-elev flex flex-col overflow-hidden animate-in zoom-in-95 duration-200":"relative rounded-t-3xl border-t border-border bg-surface/95 backdrop-blur-xl shadow-2xl max-h-[88dvh] flex flex-col animate-in slide-in-from-bottom duration-300 ease-out",children:[!b&&(0,n.jsx)("div",{className:"pt-3 pb-1 flex justify-center flex-shrink-0",children:(0,n.jsx)("div",{className:"w-10 h-1 rounded-full bg-border"})}),(0,n.jsxs)("div",{className:`px-6 pb-3 flex items-center justify-between flex-shrink-0 ${b?"pt-4":""}`,children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:a("menu.terminalBackground")}),(0,n.jsx)("button",{onClick:v,className:"p-2 -mr-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-full transition-colors","aria-label":a("common.close"),children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable px-5 pb-4",children:T}),$,E]}),p]}),document.body)}let d1=/^(\S+) (DEBUG|INFO|WARN|ERROR) \[([^\]]+)\] (.*)$/,d2=0,d5=null;function d3(e,t,s,n,r){return{id:++d2,ts:r||new Date().toISOString(),source:e,level:t,domain:s,msg:n}}function d4(e){let t=d1.exec(e);return t?d3("host",t[2].toLowerCase(),t[3],t[4],t[1]):d3("host","info","host",e)}let d6=(0,b.v)((e,t)=>({entries:[],push:t=>e(e=>{let s=[...e.entries,t];return{entries:s.length>500?s.slice(-500):s}}),clear:()=>e({entries:[]}),loadHostTail:async()=>{if((0,x.gJ)())try{let s=await fetch("/api/logs?lines=200",{cache:"no-store"}),n=await s.json();if(!Array.isArray(n?.logs))return;let r=t().entries.filter(e=>"web"===e.source);e({entries:[...n.logs.map(d4),...r].slice(-500)})}catch{}},startHostTail:()=>{(0,x.gJ)()&&!d5&&((d5=new EventSource("/api/ui/events")).onmessage=e=>{let s;try{s=JSON.parse(e.data)}catch{return}s?.type==="log"&&s.message&&t().push(d4(s.message))})},stopHostTail:()=>{d5?.close(),d5=null}}));if(!window.__logCapture){window.__logCapture=!0;let e=d6.getState().push,t=(t,s)=>{let n=console[t];console[t]=(...t)=>{try{e(d3("web",s,"web",t.map(e=>{if(e instanceof Error)return e.stack||e.message;if("object"==typeof e)try{return JSON.stringify(e)}catch{}return String(e)}).join(" ")))}catch{}n(...t)}};t("log","info"),t("info","info"),t("warn","warn"),t("error","error"),t("debug","debug"),window.addEventListener("error",t=>e(d3("web","error","web",t.message))),window.addEventListener("unhandledrejection",t=>e(d3("web","error","web",`Unhandled rejection: ${t.reason}`)))}let d8={Settings:el.wB,Palette:el.es,Terminal:el.BK,Bell:el.Ir,Sparkles:el.sU,Keyboard:el.s3,Zap:el.Kq,PanelRight:el.jz,Image:el._V,Bot:el.cC,Monitor:el.VA,Mic:el.GO,Bug:el.zP,Globe:el.qz,Link2:el.vv};function d9({context:e,callbacks:t,canInstall:s,isInstalled:l,install:a,onClose:i}){let{t:o,locale:c}=(0,eu.s)(),{theme:d,setTheme:u}=(0,nW.D)(),m=(0,x.gJ)(),[p,f]=(0,r.useState)(m?"system":"general"),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),w=function(){let[e,t]=(0,r.useState)(null),[s,n]=(0,r.useState)(null),[l,a]=(0,r.useState)(null);(0,r.useEffect)(()=>{(0,x.gJ)()&&(fetch("/api/autostart",{cache:"no-store"}).then(e=>e.json()).then(e=>t(!!e?.enabled)).catch(()=>{}),fetch("/api/desktop-unlock",{cache:"no-store"}).then(e=>e.json()).then(e=>n(e)).catch(()=>{}),fetch("/api/sleep-inhibit",{cache:"no-store"}).then(e=>e.json()).then(e=>a({mode:e?.mode||"never",presets:Array.isArray(e?.presets)?e.presets:[]})).catch(()=>{}))},[]);let i=(0,r.useCallback)(()=>{fetch("/api/desktop-unlock",{cache:"no-store"}).then(e=>e.json()).then(e=>n(e)).catch(()=>{})},[]),o=(0,r.useCallback)(e=>{t(e),fetch("/api/autostart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})}).catch(()=>t(t=>t===e?!e:t))},[]),c=(0,r.useCallback)(()=>{let e=s?.enabled?"uninstall":"install";n(e=>e?{...e,busy:!0}:e),fetch(`/api/desktop-unlock/${e}`,{method:"POST"}).then(i).catch(i)},[s,i]),d=(0,r.useCallback)(()=>{fetch("/api/ui/stop",{method:"POST"}).catch(()=>{})},[]),u=(0,r.useCallback)(()=>{fetch("/api/ui/shutdown",{method:"POST"}).catch(()=>{})},[]);return{autoStart:e,unlock:s,sleep:l,toggleAutoStart:o,toggleUnlock:c,setSleepMode:(0,r.useCallback)(e=>{let t=null;a(s=>(t=s?.mode||null,s?{...s,mode:e}:s)),fetch("/api/sleep-inhibit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:e})}).then(e=>e.json()).then(e=>{e?.mode?a(t=>t?{...t,mode:e.mode}:t):t&&a(e=>e?{...e,mode:t}:e)}).catch(()=>{t&&a(e=>e?{...e,mode:t}:e)})},[]),stopHost:d,shutdownHost:u,stopAgent:d,shutdownAgent:u}}(),j=M(e=>e.enabled),k=dG(e=>e.enabled),N=M(e=>e.setEnabled),[C,S]=(0,r.useState)(!1),T=dN.dI.find(e=>e.code===c),R=(0,h.B)(e=>e.webglEnabled),E=(0,h.B)(e=>e.setWebglEnabled),$=(0,h.B)(e=>e.fontSize),z=(0,h.B)(e=>e.setFontSize),P=(0,h.B)(e=>e.terminalTheme),A=(0,h.B)(e=>e.setTerminalTheme),I=dw(),D=dj(e.subscribeToPush,e.unsubscribeFromPush),L=dk(e.busRef,e.connected),B=s8(e=>!1),F=L.supported,K=e.hostVersion||e.agentVersion,O=(0,r.useMemo)(()=>e.hideActions||[],[e.hideActions]),W=!(window.matchMedia("(display-mode: standalone)").matches||window.ReactNativeWebView)&&!l,_=(0,r.useMemo)(()=>dq.filter(e=>"codespace"!==e.id&&("terminal"===e.id?!O.includes("terminalSettings"):"system"===e.id?m:"general"!==e.id||!m)),[O,m]),H=_.find(e=>e.id===p);(0,r.useEffect)(()=>{document.activeElement?.blur?.();let e=e=>{"Escape"!==e.key||C||v||(e.preventDefault(),e.stopPropagation(),i())};return window.addEventListener("keydown",e,!0),document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",e,!0),document.body.style.overflow=""}},[i,C,v]);let U=(e,t)=>(0,n.jsx)(d7,{title:t,children:I.buttons.filter(t=>t.section===e).map(e=>(0,n.jsx)(ut,{icon:dv[e.id],label:o(e.labelKey),hint:e.descKey?o(e.descKey):void 0,value:I.isOn(e),onChange:()=>I.toggle(e)},e.id))}),q=(0,r.useCallback)(e=>{(0,ed.e)(),i(),setTimeout(()=>e?.(),50)},[i]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:i}),(0,n.jsxs)("div",{className:"relative w-full max-w-4xl h-[85vh] max-h-[640px] card-elev flex overflow-hidden",role:"dialog","aria-modal":"true","aria-label":o("menu.settings"),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsxs)("nav",{className:"w-52 flex-shrink-0 bg-bg/40 border-r border-border flex flex-col",children:[(0,n.jsx)("div",{className:"h-12 flex items-center px-4 border-b border-border",children:(0,n.jsx)("h2",{className:"text-base font-semibold text-text",children:o("menu.settings")})}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-0.5 modal-scrollable",children:_.map(e=>{let t=d8[e.icon],s=p===e.id;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),f(e.id)},className:`w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm transition-colors ${s?"bg-brand-500/15 text-brand-500 dark:bg-white/10 dark:text-white":"text-text-muted hover:bg-surface-2 hover:text-text"}`,children:[(0,n.jsx)(t,{size:16}),(0,n.jsx)("span",{children:o(e.labelKey)})]},e.id)})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center gap-2",children:["local"===e.connectionMode&&(0,n.jsx)("span",{className:"text-[10px] font-semibold px-1.5 py-0.5 rounded-full bg-green-500/15 text-green-400",children:"LAN"}),(0,n.jsxs)("p",{className:"text-text-muted text-xs truncate",children:["3.0.39",K?` / ${K}`:""]})]})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("div",{className:"h-12 flex items-center justify-between gap-2 pl-6 pr-3 border-b border-border",children:["install"===p?(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),f("general")},className:"-ml-2 px-2 py-1 text-sm font-medium text-text hover:bg-surface-2 rounded-brand transition-colors flex items-center gap-1.5",children:[(0,n.jsx)(el.JG,{size:16}),o("pwa.title")]}):(0,n.jsx)("h3",{className:"text-sm font-medium text-text truncate",children:o(H?.labelKey||"menu.settings")}),(0,n.jsx)("button",{onClick:i,className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0","aria-label":o("common.close"),children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsxs)("div",{className:"debug"===p?"flex-1 min-w-0 flex flex-col overflow-hidden px-6 py-4":`flex-1 min-w-0 flex flex-col overflow-y-auto modal-scrollable px-6 ${"background"===p?"py-4":"py-5"}`,children:["background"===p&&(0,n.jsx)(d0,{inline:!0,busRef:e.busRef}),"general"===p&&(0,n.jsxs)("div",{className:"space-y-6",children:[(D.supported||W)&&(0,n.jsxs)(d7,{children:[D.supported&&(0,n.jsx)(ut,{icon:el.Ir,label:o("menu.notifications"),hint:o("menu.notificationsHint"),value:D.enabled,loading:D.loading,onChange:D.toggle}),W&&(0,n.jsx)(ue,{icon:el.f5,label:o("menu.installApp"),badge:s?o("pwaGuide.installNow"):null,onClick:()=>s?q(a):f("install")})]}),(0,n.jsx)(d7,{title:o("menu.reloadRestart"),children:(0,n.jsx)(ue,{icon:el.e9,iconClass:b?"animate-spin":"",label:o("menu.reload"),disabled:b,onClick:()=>{(0,ed.e)(),g(!0),setTimeout(()=>window.location.reload(),150)}})}),t.onLogout&&(0,n.jsx)(d7,{title:o("menu.settingsAccount"),children:(0,n.jsx)(ue,{icon:el.nU,label:o("menu.logout"),danger:!0,onClick:()=>q(t.onLogout)})})]}),"appearance"===p&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(d7,{title:o("menu.theme"),children:(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,n.jsx)(un,{icon:el.bd,label:o("menu.themeLight"),active:"light"===d,onClick:()=>{(0,ed.e)(),u("light")}}),(0,n.jsx)(un,{icon:el.AX,label:o("menu.themeDark"),active:"dark"===d,onClick:()=>{(0,ed.e)(),u("dark")}})]})}),(0,n.jsx)(d7,{title:o("menu.language"),children:(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),S(!0)},className:"w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors",children:[(0,n.jsx)(el.qz,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:o("menu.language")}),T&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 flex-shrink-0 text-text-muted",children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${T.country}.png`,alt:"",className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{className:"text-xs",children:T.label})]}),(0,n.jsx)(el.c_,{size:15,className:"text-text-muted flex-shrink-0"})]})})]}),"terminal"===p&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)(d7,{title:o("menu.terminalSettings"),children:[(0,n.jsx)(us,{icon:el.ZU,label:o("menu.fontSize"),children:(0,n.jsx)("select",{value:$??14,onChange:e=>{(0,ed.e)(),z(Number(e.target.value))},className:"bg-surface-2 text-text text-sm rounded-brand px-2 py-1 focus:outline-none",children:Array.from({length:9},(e,t)=>t+10).map(e=>(0,n.jsxs)("option",{value:e,children:[e,"px"]},e))})}),(0,n.jsx)(us,{icon:el.es,label:o("menu.terminalTheme"),children:(0,n.jsxs)("select",{value:P,onChange:e=>{(0,ed.e)(),A(e.target.value)},className:"bg-surface-2 text-text text-sm rounded-brand px-2 py-1 max-w-[220px] focus:outline-none",children:[(0,n.jsx)("option",{value:"default",children:"Vesper (Default)"}),nR.g4.filter(e=>e.mode===d).map(e=>(0,n.jsx)("option",{value:e.key,children:e.label},e.key))]})}),(0,n.jsx)(ut,{icon:el.VA,label:o("menu.webgl"),hint:o("menu.webglHint"),value:R,onChange:E})]}),U("terminal",o("menu.showButtons"))]}),"voice"===p&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(ut,{icon:el.GO,label:o("menu.voiceInput"),value:j,onChange:N}),(0,n.jsx)("div",{className:j?"":"pointer-events-none opacity-40 select-none",children:(0,n.jsx)(dM,{})})]}),"browser"===p&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(ut,{icon:el.qz,label:o("menu.settingsBrowser"),value:k,onChange:e=>dG.getState().setConfig({enabled:e})}),(0,n.jsx)("div",{className:k?"":"pointer-events-none opacity-40 select-none",children:(0,n.jsx)(dQ,{busRef:e.busRef})})]}),"remote"===p&&U("remote"),"mcp"===p&&(0,n.jsxs)("div",{className:"space-y-6",children:[F&&(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(ut,{icon:el.jz,label:o("menu.artifactPanel"),hint:o("menu.artifactHint"),value:L.enabled,loading:L.loading,disabled:!e.connected,onChange:L.toggle})}),U("plugins")]}),"system"===p&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)(d7,{title:o("menu.agentSystem"),children:[(0,n.jsx)(ut,{icon:el.Mr,label:o("menu.agentAutoStart"),hint:o("menu.agentAutoStartHint"),value:!!w.autoStart,loading:null===w.autoStart,onChange:w.toggleAutoStart}),w.unlock?.supported&&(0,n.jsx)(ut,{icon:el.LM,label:o("menu.agentUnlock"),hint:w.unlock.stale?o("menu.agentUnlockStale"):w.unlock.enabled?o("menu.agentUnlockReady"):o("menu.agentUnlockHint"),value:!!w.unlock.enabled,disabled:!!w.unlock.busy,onChange:w.toggleUnlock}),(0,n.jsx)(us,{icon:el.AX,label:o("menu.preventSleep"),children:(0,n.jsx)("select",{value:w.sleep?.mode||"never",disabled:!w.sleep,onChange:e=>{(0,ed.e)(),w.setSleepMode(e.target.value)},className:"bg-surface-2 text-text text-sm rounded-brand px-2 py-1 focus:outline-none",children:(w.sleep?.presets||[]).map(e=>(0,n.jsx)("option",{value:e,children:ur[e]||e},e))})})]}),(0,n.jsx)(d7,{title:o("menu.agentPower"),children:(0,n.jsx)(ue,{icon:el.$o,label:o("menu.agentShutdown"),danger:!0,onClick:()=>y(!0)})})]}),"jarvis"===p&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(ut,{icon:el.cC,label:o("menu.jarvisToggle"),hint:o("menu.jarvisToggleHint"),value:B,onChange:e=>{s8.getState().setSettings({enabled:e}),e||s8.getState().setOpen(!1)}}),F&&!L.enabled&&(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-amber-400",children:o("menu.jarvisMcpOff")}),(0,n.jsx)(ni,{busRef:e.busRef})]}),"debug"===p&&(0,n.jsx)(ua,{}),"shortcuts"===p&&(0,n.jsx)("ul",{className:"flex flex-col divide-y divide-border-subtle/40",children:ta.map(e=>(0,n.jsxs)("li",{className:"flex items-center justify-between gap-4 px-3 py-2 rounded-brand hover:bg-surface-2 first:pt-1",children:[(0,n.jsx)("span",{className:"text-sm text-text min-w-0 truncate",children:o(`shortcuts.${e.id}`)}),(0,n.jsx)("span",{className:"inline-flex items-center gap-1 flex-shrink-0",children:tm(e).map(e=>(0,n.jsx)("kbd",{className:tu,children:e},e))})]},e.id))}),"install"===p&&(0,n.jsx)(dB,{})]})]})]}),(0,n.jsx)(dU.A,{isOpen:C,onClose:()=>S(!1)}),(0,n.jsx)(ec.A,{isOpen:v,onClose:()=>y(!1),onConfirm:()=>{y(!1),q(w.shutdownHost)},title:o("menu.agentShutdownConfirmTitle"),message:o("menu.agentShutdownConfirmMsg")})]})}function d7({title:e,children:t}){return(0,n.jsxs)("section",{children:[e&&(0,n.jsx)("h4",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-muted mb-2",children:e}),(0,n.jsx)("div",{className:"space-y-1",children:t})]})}function ue({icon:e,iconClass:t="",label:s,badge:r,danger:l,disabled:a,onClick:i}){return(0,n.jsxs)("button",{onClick:i,disabled:a,className:`w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm transition-colors ${a?"text-text-muted cursor-not-allowed opacity-60":l?"text-text hover:bg-red-500/15 hover:text-red-400":"text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(e,{size:16,className:`${l?"text-red-400":"text-brand-500 dark:text-white"} ${t}`}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:s}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 px-2 py-0.5 bg-brand-500 text-white text-xs font-medium rounded-full",children:r})]})}function ut({icon:e,label:t,hint:s,value:r,loading:l,disabled:a,onChange:i}){return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),i(!r)},disabled:l||a,className:"w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm text-text hover:bg-surface-2 transition-colors disabled:opacity-60",children:[(0,n.jsx)(e,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"block truncate",children:t}),s&&(0,n.jsx)("span",{className:"block text-xs text-text-muted truncate",children:s})]}),l?(0,n.jsx)(el.kr,{size:16,className:"animate-spin text-text-muted"}):(0,n.jsx)("span",{className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors border border-transparent flex-shrink-0 ${r?"bg-brand-500 dark:bg-white":"bg-surface-2 dark:border-white/15"}`,children:(0,n.jsx)("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${r?"translate-x-4 dark:bg-dark-800":"translate-x-0.5 dark:bg-white/50"}`})})]})}function us({icon:e,label:t,children:s}){return(0,n.jsxs)("div",{className:"w-full px-3 py-2 rounded-brand flex items-center gap-2.5 text-sm text-text",children:[(0,n.jsx)(e,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:t}),s]})}function un({icon:e,label:t,active:s,onClick:r}){return(0,n.jsxs)("button",{onClick:r,className:`px-3 py-3 rounded-brand flex items-center gap-2.5 text-sm border transition-colors ${s?"border-brand-500 bg-brand-500/10 text-brand-500 dark:border-white/30 dark:bg-white/10 dark:text-white":"border-border text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(e,{size:16}),(0,n.jsx)("span",{children:t})]})}let ur={"30m":"30 min","1h":"1 hour","2h":"2 hours","4h":"4 hours","24h":"24 hours",never:"Always",none:"Off"},ul={debug:"text-text-muted",info:"text-blue-400",warn:"text-amber-400",error:"text-red-400"};function ua(){let{t:e}=(0,eu.s)(),t=d6(e=>e.entries),[s,l]=(0,r.useState)("all"),[a,i]=(0,r.useState)("all"),o=(0,r.useRef)(null);(0,r.useEffect)(()=>(d6.getState().loadHostTail(),d6.getState().startHostTail(),()=>d6.getState().stopHostTail()),[]),(0,r.useEffect)(()=>{o.current&&(o.current.scrollTop=o.current.scrollHeight)},[t]);let c=t.filter(e=>("all"===s||e.source===s)&&("all"===a||e.level===a)),d="bg-surface-2 text-text text-xs rounded-brand px-2 py-1 focus:outline-none";return(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted",children:e("menu.debugSource")}),(0,n.jsxs)("select",{value:s,onChange:e=>l(e.target.value),className:d,"aria-label":e("menu.debugSource"),children:[(0,n.jsx)("option",{value:"all",children:e("menu.debugAll")}),(0,n.jsx)("option",{value:"host",children:e("menu.debugHost")}),(0,n.jsx)("option",{value:"web",children:e("menu.debugWeb")})]}),(0,n.jsx)("span",{className:"text-xs text-text-muted ml-2",children:e("menu.debugLevel")}),(0,n.jsxs)("select",{value:a,onChange:e=>i(e.target.value),className:d,"aria-label":e("menu.debugLevel"),children:[(0,n.jsx)("option",{value:"all",children:e("menu.debugAll")}),(0,n.jsx)("option",{value:"debug",children:"DEBUG"}),(0,n.jsx)("option",{value:"info",children:"INFO"}),(0,n.jsx)("option",{value:"warn",children:"WARN"}),(0,n.jsx)("option",{value:"error",children:"ERROR"})]}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>d6.getState().loadHostTail(),className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand","aria-label":e("menu.debugRefresh"),children:(0,n.jsx)(el.e9,{size:14})}),(0,n.jsx)("button",{onClick:()=>{let e=c.map(e=>`${e.ts} ${e.level.toUpperCase()} [${e.source}:${e.domain}] ${e.msg}`).join("\n");navigator.clipboard?.writeText(e)?.catch(()=>{})},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand","aria-label":e("menu.debugCopy"),children:(0,n.jsx)(el.QR,{size:14})}),(0,n.jsx)("button",{onClick:()=>{d6.getState().clear(),(0,x.gJ)()&&fetch("/api/logs/clear",{method:"POST"}).catch(()=>{})},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand","aria-label":e("menu.debugClear"),children:(0,n.jsx)(el.TB,{size:14})})]}),(0,n.jsx)("div",{ref:o,className:"flex-1 min-h-0 select-text overflow-y-auto rounded-brand px-3 py-2 modal-scrollable bg-surface-2 border border-border",children:0===c.length?(0,n.jsx)("p",{className:"text-xs text-center py-3 text-text-muted",children:e("menu.debugEmpty")}):c.map(e=>(0,n.jsxs)("p",{className:"font-mono text-[11px] leading-[1.7] whitespace-pre-wrap break-all",children:[(0,n.jsx)("span",{className:"text-text-muted",children:new Date(e.ts).toLocaleTimeString([],{hour12:!1})})," ",(0,n.jsx)("span",{className:`font-semibold ${ul[e.level]||""}`,children:e.level.toUpperCase()})," ",(0,n.jsxs)("span",{className:"text-text-muted",children:[e.source,":",e.domain]})," ",(0,n.jsx)("span",{className:"text-text",children:e.msg})]},e.id))})]})}function ui(){let e,t,{t:s,locale:l}=(0,eu.s)(),{formattedStars:a}=(0,sG.w)(),i=dN.dI.find(e=>e.code===l)||dN.dI[0],o=ev(e=>e.isOpen),c=ev(e=>e.activePanel),d=ev(e=>e.context),x=ev(e=>e.callbacks),m=(0,u.d)(e=>e.carrier),p=ev(e=>e.close),f=ev(e=>e.setActivePanel);ev(e=>e.openMenu);let h=eY(e=>e.install),b=eY(e=>e.canInstall),g=eY(e=>e.isInstalled),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(!1),[k,N]=(0,r.useState)(!1),[C,S]=(0,r.useState)(!1),{theme:T,toggleTheme:R}=(0,nW.D)(),[E,$]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=()=>$(window.innerWidth>=eJ.jK);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>(o?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[o]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o&&p()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[o,p]);let z=(0,r.useCallback)(()=>f("pwa"),[f]),M=(0,r.useCallback)(()=>{(0,ed.e)(),f("menu")},[f]),P=(0,r.useCallback)(()=>{p(),x.onRemote?.()},[p,x]),A=(0,r.useCallback)(()=>{p(),x.onFiles?.()},[p,x]),I=(0,r.useCallback)(()=>{b?(p(),h()):z()},[b,p,h,z]),D=(0,r.useCallback)(()=>{p(),setTimeout(()=>{x.onLogout?.()},50)},[p,x]),L=(0,r.useCallback)(e=>{x.onThemeChange?.(e)},[x]);(0,r.useCallback)(()=>{p(),y(!0)},[p]);let B=(0,r.useCallback)(()=>{y(!1)},[]);(0,r.useCallback)(()=>{p(),j(!0)},[p]);let F=(0,r.useCallback)(()=>{j(!1)},[]),K=(0,r.useCallback)(()=>{p(),S(!0)},[p]),O=(0,r.useCallback)(()=>{S(!1)},[]),W=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(dW,{isOpen:v,onClose:B}),(0,n.jsx)(dH,{isOpen:w,onClose:F}),(0,n.jsx)(d0,{isOpen:C,onClose:O,busRef:d.busRef})]});return o?E?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(d9,{context:d,callbacks:x,canInstall:b,isInstalled:g,install:h,onClose:p}),W]}):(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-[2px] fade-in",onClick:p}),(0,n.jsxs)("div",{className:`absolute top-0 right-0 bottom-0 w-[85vw] sm:w-96 max-w-md bg-surface border-l border-border shadow-2xl flex flex-col slide-in-right pt-[var(--safe-top)] ${"menu"===c?"":"pb-[var(--safe-bottom)]"}`,onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:["menu"!==c&&(0,n.jsx)("button",{onClick:M,className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors mr-1","aria-label":s("common.back"),children:(0,n.jsx)(el.JG,{size:20})}),(0,n.jsx)("h2",{className:"text-lg font-semibold text-text",children:s("pwa"===c?"pwa.title":"menu.title")}),"menu"===c&&(t=(e=m||d.carrier)&&"ws"!==e,(0,n.jsx)("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider ${t?"bg-blue-500/15 text-blue-400 border border-blue-500/30":"bg-yellow-500/15 text-yellow-500 border border-yellow-500/30"}`,title:`Carrier: ${t?`WebRTC (${e})`:"WebSocket"}`,children:t?"RTC":"WS"}))]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:["menu"===c&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),R()},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("menu.theme"),title:s("menu.theme"),children:"dark"===T?(0,n.jsx)(el.bd,{size:18}):(0,n.jsx)(el.AX,{size:18})}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),N(!0)},className:"px-2 py-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex items-center gap-1.5 text-sm font-medium","aria-label":s("menu.language"),title:s("menu.language"),children:[(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${i.country}.png`,alt:i.label,className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{className:"uppercase",children:i.code})]})]}),(0,n.jsx)("button",{onClick:p,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":s("common.close"),children:(0,n.jsx)(el.X,{size:20})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto modal-scrollable",children:["menu"===c&&(0,n.jsx)(dI,{onRemote:d.remoteAvailable?P:null,onFiles:A,onInstallApp:I,canInstall:b,isInstalled:g,onLogout:D,connected:d.connected,remoteAvailable:d.remoteAvailable,showTheme:d.showTheme,theme:d.theme,onThemeChange:L,hideActions:d.hideActions||[],busRef:d.busRef,subscribeToPush:d.subscribeToPush,unsubscribeFromPush:d.unsubscribeFromPush,onOpenBackgroundPicker:K}),"pwa"===c&&(0,n.jsx)(dB,{})]}),"menu"===c&&sY.l7&&(0,n.jsx)("div",{className:"flex-shrink-0 flex justify-center px-3 pt-2 pb-safe border-t border-border",children:(0,n.jsxs)("a",{href:sY.rl,target:"_blank",rel:"noopener noreferrer",onClick:ed.e,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-surface hover:bg-surface-2 border border-border text-xs text-text-muted hover:text-text transition-colors",title:"Star on GitHub","aria-label":"Star on GitHub",children:[(0,n.jsx)(el.Cp,{size:14}),(0,n.jsx)("span",{children:s("menu.starChip")}),(0,n.jsx)(el.FE,{size:12,className:"text-yellow-500 fill-yellow-500"}),a&&(0,n.jsx)("span",{className:"font-mono text-[11px]",children:a})]})})]}),(0,n.jsx)(dW,{isOpen:v,onClose:B}),(0,n.jsx)(dH,{isOpen:w,onClose:F}),(0,n.jsx)(d0,{isOpen:C,onClose:O,busRef:d.busRef}),(0,n.jsx)(dU.A,{isOpen:k,onClose:()=>N(!1)})]}):W}function uo(){let e=cR(e=>e.pendingDevice),t=cR(e=>e.setPendingDevice),s=cR(e=>e.clearPendingDevice),l=cR(e=>e.touchBump),a=(0,r.useRef)(null);(0,r.useEffect)(()=>{a.current=e},[e]),(0,r.useEffect)(()=>{if(!(0,x.gJ)())return;let e=new EventSource("/api/ui/events");e.onmessage=e=>{let s;try{s=JSON.parse(e.data)}catch{return}"deviceApproval"===s.type&&"pending"===s.action&&t({socketId:s.socketId,deviceId:s.deviceId,ip:s.ip})};let s=setInterval(async()=>{if(!a.current)try{let e=await fetch("/api/device/pending");if(!e.ok)return;let s=await e.json(),n=s?.pending?.[0];n&&t({socketId:n.socketId,deviceId:n.deviceId,ip:n.ip})}catch{}},3e3);return()=>{clearInterval(s),e.close()}},[t]);let i=(0,r.useCallback)(async e=>{a.current&&(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({socketId:a.current.socketId})}).catch(()=>null),s(),l())},[s,l]),o=(0,r.useCallback)(()=>i("/api/device/approve"),[i]),c=(0,r.useCallback)(()=>i("/api/device/reject"),[i]);return((0,r.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key?(e.preventDefault(),c()):"Enter"===e.key&&(e.preventDefault(),o())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)}),e)?(0,n.jsx)("div",{className:"agent-dashboard fixed inset-0 z-[70] flex items-center justify-center",style:{background:"rgba(0,0,0,0.6)"},children:(0,n.jsxs)("div",{className:"card-elev p-5 flex flex-col gap-4 w-80",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"material-symbols-outlined",style:{color:"var(--brand-500)",fontSize:24},children:"devices"}),(0,n.jsx)("span",{className:"text-sm font-semibold",style:{color:"var(--text-main)"},children:"New Device Connection"})]}),(0,n.jsxs)("div",{className:"flex flex-col gap-1 text-xs",style:{color:"var(--text-muted)"},children:[(0,n.jsxs)("span",{children:["Device: ",(0,n.jsxs)("span",{style:{color:"var(--text-main)"},children:[e.deviceId?.slice(0,8),"..."]})]}),(0,n.jsxs)("span",{children:["IP: ",(0,n.jsx)("span",{style:{color:"var(--text-main)"},children:e.ip})]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:c,className:"glass-btn flex-1 py-2 text-sm flex items-center justify-center gap-1.5",style:{color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:"Reject"}),(0,n.jsx)("kbd",{className:"text-[10px] font-mono px-1 py-0.5 rounded opacity-70 leading-none",style:{background:"var(--glass-bg)"},children:"Esc"})]}),(0,n.jsxs)("button",{onClick:o,className:"btn-primary flex-1 py-2 text-sm font-semibold rounded-lg flex items-center justify-center gap-1.5",children:[(0,n.jsx)("span",{children:"Approve"}),(0,n.jsx)("kbd",{className:"text-[10px] font-mono px-1 py-0.5 rounded bg-white/20 text-white leading-none",children:"↵"})]})]})]})}):null}var uc=s(61826),ud=s(31735);function uu({hydrated:e,apiKey:t}){return!function(e){let t=(0,l.usePathname)(),s=(0,l.useSearchParams)(),n=(0,l.useRouter)(),{viewStack:a,pushView:i,setViewStack:o}=(0,h.B)((0,F.k)(e=>({viewStack:e.viewStack,pushView:e.pushView,setViewStack:e.setViewStack}))),c=a[a.length-1],d=uc.yP.includes(c?.type)?a[a.length-2]:c,u=(0,r.useRef)(null),x=(0,r.useRef)(null),m=(0,r.useRef)(null),p=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!e)return;let n=(0,uc.mn)(t,s);if(!n)return;let r=(0,uc.O5)(n);if(r===u.current||(u.current=r,d&&(0,uc.O5)(d)===r))return;p.current="url";let l=(0,uc.dX)(a,n);l?o(l):i(n)},[e,t,s]),(0,r.useEffect)(()=>{if(!e)return;let r=h.B.getState().viewStack,l=r[r.length-1];if(!l||l!==c||uc.yP.includes(l?.type))return;let a=(0,uc.O5)(l);if(a===u.current)return;let i=(0,uc.O5)((0,uc.mn)(t,s)),o="url"===p.current;o&&(p.current=null);let d=x.current?.type==="terminal"&&l?.type==="terminal",f=l?.type==="list"&&1===r.length,b=r.length<m.current;p.current="store",u.current=a,x.current=l,m.current=r.length,o||a===i||(d||f||b?n.replace(a):n.push(a))},[e,c,t,s])}(e),(0,ud.H$)(t),null}function ux({children:e}){let t,s,b,g,v,y,w,j,k,N,C,S,T,R,E,$,{t:z}=(0,eu.s)(),[W,_]=(0,r.useState)(!1);(0,r.useEffect)(()=>{!function(){if(eZ)return;eZ=!0;let e=eY.getState();(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),eY.getState().setDeferredPrompt(e)}),window.addEventListener("appinstalled",()=>{eY.getState().setDeferredPrompt(null),eY.getState().setIsInstalled(!0)}),window.matchMedia("(display-mode: standalone)").matches)?e.setIsInstalled(!0):navigator.getInstalledRelatedApps&&navigator.getInstalledRelatedApps().then(t=>{t?.length&&e.setIsInstalled(!0)}).catch(()=>{})}()},[]);let{viewStack:H,openedSessions:U,pushView:q,popView:X,setViewStack:V,addOpenedSession:J,removeOpenedSession:G,reorderOpenedSessions:Y,activeWorkspaceId:Z,setActiveWorkspaceId:Q,livePanes:ee,touchLivePane:et,mountedWorkspaces:es,markWorkspaceMounted:en,reset:el,cwdBySession:ea,sidebarCollapsed:ei,toggleSidebar:ed,sidebarWidth:em,setSidebarWidth:ep,paneWidths:eg,setPaneWidth:ey,rightPanelOpen:ew,rightPanelTabs:ek,rightPanelWidth:eS,toggleRightPanel:eT,setRightPanelTab:eR,setRightPanelWidth:e$,editorFilePath:ez,editorJump:eP,editorPanelWidth:eA,setEditorPanelWidth:eL,openEditorFile:eB,closeEditorFile:eF,editorPreviewSeq:eK,mobileOpen:eO,mobileMode:eW,mobilePanelWidth:e_,setMobileOpen:eH,setMobileMode:eU,setMobilePanelWidth:eq,setMobileSession:eG,artifactTitle:e0,pushArtifact:e1,removeArtifact:e2}=(0,h.B)((0,F.k)(e=>({viewStack:e.viewStack,openedSessions:e.openedSessions,pushView:e.pushView,popView:e.popView,setViewStack:e.setViewStack,addOpenedSession:e.addOpenedSession,removeOpenedSession:e.removeOpenedSession,reorderOpenedSessions:e.reorderOpenedSessions,activeWorkspaceId:e.activeWorkspaceId,setActiveWorkspaceId:e.setActiveWorkspaceId,livePanes:e.livePanes,touchLivePane:e.touchLivePane,mountedWorkspaces:e.mountedWorkspaces,markWorkspaceMounted:e.markWorkspaceMounted,reset:e.reset,cwdBySession:e.cwdBySession,sidebarCollapsed:e.sidebarCollapsed,toggleSidebar:e.toggleSidebar,sidebarWidth:e.sidebarWidth,setSidebarWidth:e.setSidebarWidth,paneWidths:e.paneWidths,setPaneWidth:e.setPaneWidth,rightPanelOpen:e.rightPanelOpen,rightPanelTabs:e.rightPanelTabs,rightPanelWidth:e.rightPanelWidth,toggleRightPanel:e.toggleRightPanel,setRightPanelTab:e.setRightPanelTab,setRightPanelWidth:e.setRightPanelWidth,editorFilePath:e.editorFilePath,editorJump:e.editorJump,editorPanelWidth:e.editorPanelWidth,setEditorPanelWidth:e.setEditorPanelWidth,openEditorFile:e.openEditorFile,closeEditorFile:e.closeEditorFile,editorPreviewSeq:e.editorPreviewSeq,mobileOpen:e.mobileOpen,mobileMode:e.mobileMode,mobilePanelWidth:e.mobilePanelWidth,setMobileOpen:e.setMobileOpen,setMobileMode:e.setMobileMode,setMobilePanelWidth:e.setMobilePanelWidth,setMobileSession:e.setMobileSession,artifactTitle:e.artifactTitle,pushArtifact:e.pushArtifact,removeArtifact:e.removeArtifact}))),e5=(0,l.useRouter)(),{getAuth:e3,setAuth:e8,clearAuth:e9}=(0,a.Fo)(),[e7,te]=(0,r.useState)(()=>e3()),tt=(0,u.d)(e=>e.authKey);(0,r.useEffect)(()=>{tt&&te(e3())},[tt,e3]),(0,r.useEffect)(()=>{_(!0),!e7?.apiKey&&(0,x._r)()&&window.location.port===String(m._8)&&fetch(m.TR).then(e=>e.ok?e.json():null).then(e=>{if(e?.permanentKey){let t=e.permanentKey,s=(0,p.Uo)(t),n=(0,p.Cj)(t);(0,f.LG)(s,{tail:n});let r={apiKey:s,tunnelUrl:window.location.origin,mode:"local",tempKey:null,localIp:null};e8(r),te(r)}}).catch(()=>{})},[e7,e8]),(0,r.useEffect)(()=>{if(!window.__TAURI__)return;let e=e=>{("F5"===e.key||(e.metaKey||e.ctrlKey)&&"r"===e.key.toLowerCase())&&(e.preventDefault(),window.location.reload())},t=e=>{let t=e.target?.tagName;"INPUT"===t||"TEXTAREA"===t||e.target?.isContentEditable||e.preventDefault()};return window.addEventListener("keydown",e),window.addEventListener("contextmenu",t),()=>{window.removeEventListener("keydown",e),window.removeEventListener("contextmenu",t)}},[]);let{bus:tr,busRef:ta,protocolRef:to,disconnect:td,reconnect:tu,connected:tx,connectionMode:tm,carrier:th,remoteAvailable:ty,mobileAvailable:tw,platform:tj,hostVersion:tk,agentVersion:tN,retryStatus:tC,approvalStatus:tS,admitted:tT,loadSessions:tR,createSession:tE,deleteSession:t$,renameSession:tz,createWorkspace:tM,renameWorkspace:tP,deleteWorkspace:tA,setWorkspaceHiddenRepos:tI,reorderSession:tD}=function(){let[e,t]=(0,r.useState)([]),[s,n]=(0,r.useState)([]),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(null),C=(0,u.d)(e=>e.approvalStatus),S=(0,u.d)(e=>e.admitted),{getAuth:T}=(0,a.Fo)(),R=(0,r.useCallback)(e=>{u.d.getState().applyApproval(e)},[]),E=(0,r.useCallback)(async()=>{let e=T();if(e?.tempKey)try{await fetch(`${m.O}/api/temp-key/remove`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({tempKey:e.tempKey})}),sessionStorage.removeItem("tempKey")}catch(e){console.error("Failed to remove temp key:",e)}},[T]),$=(0,r.useRef)(null),z=(0,r.useRef)({sessions:!1,workspaces:!1}),F=e=>{z.current[e]=!0},K=(0,r.useCallback)(e=>{(0,L.Lq)("switch",`lists untrusted (${e}) → refetch`),z.current={sessions:!1,workspaces:!1}},[]),O=(0,r.useCallback)(e=>{if(!Array.isArray(e))return;for(let t of(F("sessions"),e))t?.id&&t?.agent&&h.B.getState().setSessionAgent(t.id,t.agent);t(t=>(0,I.nk)(t,e)?t:e);let s=P.rh.getState();(0,I.nk)(s.hosts[s.currentKey]?.sessions,e)||B({sessions:e})},[]),W=(0,r.useCallback)(e=>{if(!Array.isArray(e))return;F("workspaces"),n(t=>(0,I.nk)(t,e)?t:e);let t=P.rh.getState();(0,I.nk)(t.hosts[t.currentKey]?.workspaces,e)||B({workspaces:e})},[]),_=(0,r.useRef)(0),H=(0,r.useRef)(0),U=(0,r.useRef)(null),q=(0,r.useRef)(0),X=(0,r.useCallback)(e=>{let t=++_.current;e.emit("getSessions",e=>{(0,L.Lq)("diag",`getSessions ack seq=${t} type=${Array.isArray(e)?"list":typeof e} n=${Array.isArray(e)?e.length:"-"}`),t===_.current&&O(e)})},[O]),V=(0,r.useCallback)(e=>{let t=++H.current;e.emit("getWorkspaces",e=>{t===H.current&&W(e)})},[W]),J=(0,r.useCallback)((e,t=!1)=>{if(e){if(t)clearTimeout(U.current);else if(U.current)return;else if(Date.now()-q.current<1e3)return;U.current=setTimeout(()=>{U.current=null,q.current=Date.now(),(0,L.Lq)("diag",`fetchLists FIRE (bus=${e?"ok":"null"} connected-already=${z.current.sessions}/${z.current.workspaces})`),V(e),X(e)},120)}},[X,V]),G={fragOut:!0,binOut:!0,hb:1,env2:1,fragCtl:1},Y=e=>{(0,L.Lq)("switch",`caps → ${JSON.stringify(G)} announced`),e.emit("caps",G)},Z=(0,r.useRef)(null),{bus:Q,busRef:ee,protocolRef:et,connected:es,connectionMode:en,carrier:er,retryStatus:el,disconnect:ea,reconnect:ei}=function(e={}){let{namespace:t="",socketOptions:s={},redirectOnNoAuth:n="/",onConnect:h,onDisconnect:b,onApproval:g}=e,v=(0,l.useRouter)(),{getAuth:y,setAuth:w}=(0,a.Fo)(),j=function(){let[e]=(0,r.useState)(()=>{let e=localStorage.getItem(i);return e||(e=globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,localStorage.setItem(i,e)),e});return e}(),k=(0,r.useRef)(null),N=(0,r.useRef)(null),[C,S]=(0,r.useState)(!1),[T,R]=(0,r.useState)("tunnel"),[E,$]=(0,r.useState)("ws"),[z,M]=(0,r.useState)({isRetrying:!1,attempt:0,maxAttempts:10,failed:!1}),P=(0,u.d)(e=>e.authKey),A=(0,r.useRef)(!1),[I,D]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e=!1,r=null,l=!1,a=null;return(async()=>{let i=y();if((0,x._r)()&&window.location.port===String(m._8)&&!P&&i?.tunnelUrl!==window.location.origin)try{let e=await fetch(m.TR),t=e.ok?await e.json():null;if(e.ok&&t?.permanentKey){let e=t.permanentKey,s=(0,p.Uo)(e),n=(0,p.Cj)(e);(0,f.LG)(s,{tail:n}),i={apiKey:s,tunnelUrl:window.location.origin,mode:"local",tempKey:null,localIp:t.localIp||null},w(i)}}catch{}if(e)return;if(!i?.apiKey){u.d.getState().reset(),v.push(n);return}try{if("1"===sessionStorage.getItem("9remote_manual_disconnect"))return void u.d.getState().setConnection({deliberate:!0})}catch{}let C={tunnelUrl:i.tunnelUrl,localIp:i.localIp||null,namespace:t,socketOptions:{...s,auth:{apiKey:i.apiKey,tempKey:i.tempKey??null,deviceId:j,...s.auth}},apiKey:i.apiKey,deviceId:j,tempKey:i.tempKey??null,onConnect:(t,s)=>{if(e)return;l=!0,clearTimeout(a),A.current=!0,k.current=t,u.d.getState().setConnection({deliberate:!1,everConnected:!0});let n=s||N.current?.connectionMode||"tunnel";S(!0),R(n),u.d.getState().setConnection({bus:t,connected:!0,connectionMode:n,endpoint:i.tunnelUrl}),(0,d.c)("transport","[transport] ws connected"),h?.(t,i)},onDisconnect:t=>{e||((0,d.c)("transport",`[transport] ws disconnect reason=${t}`),k.current=null,S(!1),u.d.getState().setConnection({connected:!1}),b?.(t))},onApproval:g,onRetryStatus:t=>{e||(M(t),u.d.getState().setRetryStatus(t))}},T=i.tunnelUrl===window.location.origin,E=c.eR.enableWebRTC&&!T?{enableWebRTC:!0,enableTurn:c.eR.enableTurn,apiKey:i.apiKey,onUpgrade:e=>(0,d.c)("transport",`[transport] upgraded to ${e}`),onFallback:e=>(0,d.c)("transport",`[transport] fallback to ${e}`),onTransportChange:t=>{e||($(t),u.d.getState().setCarrier(t),(0,d.c)("transport",`[transport] active=${t}`))}}:null;N.current=r=new o.g(C,E),k.current=r.busRef.current,u.d.getState().setConnection({bus:k.current,busRef:k,protocolRef:N,deliberate:!1,...A.current?{}:{connected:!1,admitted:!1},connectionMode:"tunnel",carrier:"ws"}),r.connect(),A.current&&(a=setTimeout(()=>{e||l||(S(!1),u.d.getState().setConnection({connected:!1}))},15e3))})(),()=>{e=!0,clearTimeout(a),r?.disconnect(),N.current=null,k.current=null}},[P,I]),{bus:k.current,busRef:k,protocolRef:N,connected:C,connectionMode:T,carrier:E,retryStatus:z,disconnect:()=>{N.current?.disconnect(),N.current=null,k.current=null,S(!1),u.d.getState().reset(),u.d.getState().setConnection({deliberate:!0});try{sessionStorage.setItem("9remote_manual_disconnect","1")}catch{}},reconnect:()=>{try{sessionStorage.removeItem("9remote_manual_disconnect")}catch{}D(e=>e+1)}}}({namespace:"",redirectOnNoAuth:"/",onConnect:(0,r.useCallback)((e,s)=>{(R(A.J2.reconnect),B({status:"full"}),K("pm-connect"),Z.current===e)?J(e):(Z.current=e,e.on("device:pendingApproval",()=>{(0,L.Lq)("diag","EVENT device:pendingApproval arrived"),(0,d.c)("auth","[auth] agent says: waiting for host approval"),R(A.J2.pending)}),e.on("device:approved",()=>{(0,L.Lq)("diag","EVENT device:approved arrived → applying"),R(A.J2.approved),u.d.getState().setAdmitted(!0),(0,f.I8)(),E()}),e.on("terminal:ready",()=>{(0,d.c)("auth","[auth] terminal:ready (NOT an admission signal)"),J(e)}),e.on("connect",()=>{K("carrier-connect"),e.emit("device:clientReady"),Y(e),J(e)}),e.on("device:rejected",()=>{(0,L.Lq)("diag","EVENT device:rejected arrived → applying"),R(A.J2.rejected),$.current?.()}),e.on("device:tailRejected",e=>{if(e?.reason===A.ML.sealUnreadable)return;$.current?.();let t=T();(0,f.cH)(t?.apiKey),(0,f.cH)(t?.tempKey),sessionStorage.clear(),sessionStorage.setItem(A.Jd,e?.reason||A.ML.mismatch),window.location.replace("/login")}),e.on("serverInfo",e=>{let t=P.rh.getState(),s=!!t.hosts[t.currentKey]?.updating;B({platform:e.platform||null,version:e.version||null,isCodespaces:!!e.isCodespaces,updateAvailable:!s&&(0,D.U)(e.updateAvailable?.version,e.version)?e.updateAvailable:null,canSelfUpdate:!!e.canSelfUpdate,remoteAvailable:!!e.remoteAvailable,mobileAvailable:!!e.mobileAvailable}),g(e.remoteAvailable),y(!!e.mobileAvailable),j(e.platform),N(e.version||null),h.B.getState().setAgentCaps(e.caps||{}),h.B.getState().setArtifactEnabled(e.artifactEnabled),h.B.getState().setMcpClients(e.mcpClients),e.voiceConfig&&M.getState().syncFromHost(e.voiceConfig)}),e.on("sessionClosed",e=>{t(t=>t.filter(t=>t.id!==e));let s=P.rh.getState(),n=s.hosts[s.currentKey]?.sessions;n?.some(t=>t.id===e)&&B({sessions:n.filter(t=>t.id!==e)}),h.B.getState().closeSession(e)}),e.on("session-renamed",({sessionId:e,name:s}={})=>{if(!e)return;t(t=>t.map(t=>t.id===e?{...t,name:s}:t));let n=P.rh.getState(),r=n.hosts[n.currentKey]?.sessions;r?.some(t=>t.id===e)&&B({sessions:r.map(t=>t.id===e?{...t,name:s}:t)})}),e.on("sessionAgentChanged",({sessionId:e,agent:t}={})=>{e&&t&&(h.B.getState().setSessionAgent(e,t),h.B.getState().invalidateAgentHistory())}),e.on("sessionsChanged",()=>J(e,!0)),e.on("workspacesChanged",()=>J(e)),Y(e),u.d.getState().setConnection({approvalStatus:null}),e.emit("device:clientReady"))},[E,J,R,T,K]),onDisconnect:()=>{let e=P.rh.getState();e.hosts[e.currentKey]?.status==="full"&&B({status:"connecting"})},onApproval:R});(0,r.useEffect)(()=>{$.current=ea},[ea]);let eo=(0,r.useCallback)(()=>J(ee.current),[ee,J]),ec=(0,r.useCallback)(()=>J(ee.current,!0),[ee,J]);(0,r.useEffect)(()=>()=>{U.current&&(clearTimeout(U.current),U.current=null)},[]),(0,r.useEffect)(()=>{if(!es)return;let e=setInterval(()=>{z.current.sessions&&z.current.workspaces||eo()},2e3);return()=>clearInterval(e)},[es,eo]),(0,r.useEffect)(()=>{if(!es)return;let e=()=>{"visible"===document.visibilityState&&eo()};return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[es,eo]);let ed=(0,r.useCallback)((e,n,r,l,a,i=!1,o=null,c=null)=>{if(!ee.current)return;"function"==typeof n?(a=n,n=null,r=null,l=null):"function"==typeof r?(a=r,r=null,l=null):"function"==typeof l&&(a=l,l=null);let d="string"==typeof o?o:o?.id||null;ee.current.emit("createSession",{name:e,shellId:n,workspaceId:r,cwd:l,nameIsAuto:i,agent:d,replaces:c},i=>{if(i?.success){if(i.sessionId){d&&h.B.getState().setSessionAgent(i.sessionId,d);let a=s.find(e=>e.id===r)?.path||null,o={id:i.sessionId,name:i.name||e||"Terminal",createdAt:Date.now(),cwd:i.cwd||l||null,workspaceId:r||null,groupId:r||null,workspacePath:a,shellId:i.shellId||n||null,shellLabel:i.shellLabel||null,agent:d||null},c=e=>[...e.filter(e=>e.id!==i.sessionId&&e.id!==i.replaced),o];t(c);let u=P.rh.getState(),x=u.hosts[u.currentKey]?.sessions;x&&B({sessions:c(x)})}ec()}a?.(i)})},[ee,ec,s]),eu=(0,r.useCallback)((e,t,s)=>{"function"==typeof t&&(s=t,t=null),ee.current?.emit("createWorkspace",{name:e,path:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),ex=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("renameWorkspace",{workspaceId:e,name:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),em=(0,r.useCallback)((e,t)=>{ee.current?.emit("deleteWorkspace",{workspaceId:e},e=>{e?.success&&ec(),t?.(e)})},[ee,ec]),ep=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("setWorkspaceHiddenRepos",{workspaceId:e,paths:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),ef=(0,r.useCallback)((e,t,s)=>{ee.current?.emit("moveSession",{sessionId:e,workspaceId:t},e=>{e?.success&&ec(),s?.(e)})},[ee,ec]),eh=(0,r.useCallback)((e,t)=>{ee.current?.emit("reorderSession",{orderedIds:e},e=>{e?.success&&ec(),t?.(e)})},[ee,ec]),eb=(0,r.useCallback)(e=>{ee.current&&ee.current.emit("getShells",t=>e?.(t))},[ee]),eg=(0,r.useCallback)((e,t)=>{ee.current&&ee.current.emit("deleteSession",e,e=>{e.success&&ec(),t?.(e)})},[ee,ec]),ev=(0,r.useCallback)((e,t,s)=>{ee.current&&ee.current.emit("renameSession",{sessionId:e,name:t},e=>{e.success&&ec(),s?.(e)})},[ee,ec]);return{bus:Q,busRef:ee,protocolRef:et,disconnect:ea,reconnect:ei,connected:es,connectionMode:en,carrier:er,retryStatus:el,approvalStatus:C,admitted:S,sessions:e,remoteAvailable:b,mobileAvailable:v,platform:w,hostVersion:k,agentVersion:k,workspaces:s,loadSessions:eo,createSession:ed,getShells:eb,deleteSession:eg,renameSession:ev,createWorkspace:eu,renameWorkspace:ex,deleteWorkspace:em,setWorkspaceHiddenRepos:ep,moveSession:ef,reorderSession:eh}}(),{loadKeys:tL,saveKey:tB,renameKey:tF,removeKey:tK}=(0,nG.u)(),[tO,tW]=(0,r.useState)([]);(0,r.useEffect)(()=>{W&&tW(tL())},[W,tL]),(0,r.useEffect)(()=>{if(!W)return;let e=()=>tW(tL());return window.addEventListener(nG.N,e),()=>window.removeEventListener(nG.N,e)},[W,tL]);let t_=e7?.apiKey?(0,p.Uo)(e7.apiKey):"",tH=eN(t_||null);(0,r.useEffect)(()=>{if(W){if(!t_)return void P.rh.getState().closeAll();P.rh.getState().sync(tO,t_)}},[W,tO,t_]);let tU=(0,P.rh)(e=>e.hosts),tq=tU[t_],tX=(0,r.useMemo)(()=>tq?.sessions||[],[tq]),tV=(0,r.useMemo)(()=>tq?.workspaces||[],[tq]),tJ=(0,r.useMemo)(()=>(function(e,t){let s={sessions:[],workspaces:[]};if(!t)return s;for(let n of e){if(n.key===t)continue;let e=`${n.key}:`,r=`${e}_`,l=(n.sessions||[]).some(e=>null==e.workspaceId);for(let t of n.workspaces||[])s.workspaces.push({...t,id:e+t.id,hostKey:n.key});for(let t of(l&&s.workspaces.push({id:r,name:n.label||n.key,hostKey:n.key}),n.sessions||[]))s.sessions.push({...t,workspaceId:null!=t.workspaceId?e+t.workspaceId:r,hostKey:n.key})}return s})(Object.values(tU),t_),[tU,t_]),tG=(0,r.useMemo)(()=>[...tX,...tJ.sessions],[tX,tJ]),tY=(0,r.useMemo)(()=>[...tV,...tJ.workspaces],[tV,tJ]),tZ=(0,r.useCallback)((e,t)=>{let s=tL().find(t=>(0,p.Uo)(t.key)===e);s?tF(s.id,t):tB(e,t)},[tL,tF,tB]),[tQ,t0]=(0,r.useState)([]),t1=function(){let[e,t]=(0,r.useState)(!1),s=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let e=()=>{"visible"===document.visibilityState&&(t(!0),clearTimeout(s.current),s.current=setTimeout(()=>t(!1),4e3))};return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e),clearTimeout(s.current)}},[]),e}(),t2=(0,u.d)(e=>e.bus),t5=(0,u.d)(e=>e.deliberate),t3=(0,u.d)(e=>e.everConnected),t4=!!tq?.updating,t6=(0,r.useRef)({armed:!1,version:null,dropped:!1});(0,r.useEffect)(()=>{if(!tq||!t_)return;let e=t6.current;if(!tq.updating){e.armed=!1,e.dropped=!1;return}if(e.armed||(e.armed=!0,e.version=tq.version||null),tx||(e.dropped=!0),e.dropped&&tx){let t=setTimeout(()=>{let t=P.rh.getState().hosts[t_];t?.version&&e.version&&t.version!==e.version?window.location.reload():P.rh.getState()._patchHost(t_,{updating:!1})},1500);return()=>clearTimeout(t)}},[tq,t4,tx,t_]);let[t8,t9]=(0,r.useState)({isOpen:!1,title:"",message:"",onConfirm:null,confirmText:null});(0,r.useEffect)(()=>{tx&&("win32"===tj?t0([{id:"cmd",label:"Command Prompt"},{id:"powershell",label:"PowerShell"}]):t0([]))},[tx,tj]);let t7=er();t=(0,P.rh)(e=>`${e.currentKey}|`+Object.values(e.hosts).filter(e=>"online"===e.status||"full"===e.status).map(e=>e.key).join(",")),(0,r.useEffect)(()=>{let e=P.rh.getState(),s=t.slice(t.indexOf("|")+1),n=[];for(let t of s.split(",").filter(Boolean)){let s=eE(t===e.currentKey?null:t).bus;if(!s)continue;let r=({count:e})=>P.rh.getState()._patchHost(t,{mobileDeviceCount:Number(e)||0});s.on("mobile:devicesChanged",r),s.emit("mobile:deviceCount",{},e=>{e&&"number"==typeof e.count&&r(e)}),n.push(()=>s.off("mobile:devicesChanged",r))}return()=>{for(let e of n)e()}},[t]);let{subscribeToPush:se,unsubscribeFromPush:st,notifications:ss}=(s=(0,r.useRef)(null),b=ej(e=>e.notifications),(0,h.B)(e=>e.getSelectedSession),(0,h.B)(e=>e.getCurrentView),g=(0,h.B)(e=>e.pushView),v=(0,h.B)(e=>e.addOpenedSession),y=!!window.ReactNativeWebView,w=(0,P.rh)(e=>Object.values(e.hosts).filter(e=>"online"===e.status).map(e=>e.key).join(",")),j=(0,r.useCallback)(e=>{for(let t of(ta?.current&&e(ta.current),Object.values(P.rh.getState().hosts))){if("online"!==t.status)continue;let s=(0,P.eJ)(t.key);s&&e(s)}},[ta]),(0,r.useEffect)(()=>(window.handleNotificationTap=e=>{let t=e?.sessionId;t&&(v(t),g({type:"terminal",sessionId:t}))},()=>{try{delete window.handleNotificationTap}catch(e){window.handleNotificationTap=void 0}}),[g,v]),(0,r.useEffect)(()=>{if(y)return window.handleAppStateChange=e=>{j(t=>t.emit("visibilityChange",!!e)),document.dispatchEvent(new CustomEvent("app-visibility",{detail:{hidden:!!e}}))},()=>{try{delete window.handleAppStateChange}catch(e){window.handleAppStateChange=void 0}}},[ta,y,j]),k=(0,r.useCallback)(async()=>{if(ta?.current){if(localStorage.removeItem(eD),y){window.handleExpoPushToken=e=>{j(t=>t.emit("pushSubscribe",{type:"expo",token:e})),s.current={type:"expo",token:e}},window.ReactNativeWebView.postMessage(JSON.stringify({type:"REQUEST_PUSH_TOKEN"}));return}if(!("serviceWorker"in navigator)||!("PushManager"in window))return void console.warn("\uD83D\uDD15 Push not supported");try{let e=await Notification.requestPermission();if("granted"!==e)return;let t=await navigator.serviceWorker.ready;if(!t.pushManager)return;let n=await new Promise(e=>ta.current.emit("getVapidKey",e));if(!n)return;let r=await t.pushManager.getSubscription();r||(r=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n})),j(e=>{e.emit("pushSubscribe",r.toJSON()),e.emit("visibilityChange",document.hidden)}),s.current=r}catch(e){console.error("Push notification setup failed:",e)}}},[ta,y]),(0,r.useEffect)(()=>{let e=ta?.current;if(e&&tx&&"1"!==localStorage.getItem(eD)){if(y){window.handleExpoPushToken=t=>{e.emit("pushSubscribe",{type:"expo",token:t}),s.current={type:"expo",token:t}},window.ReactNativeWebView.postMessage(JSON.stringify({type:"REQUEST_PUSH_TOKEN"}));return}(async()=>{try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return;let t=await navigator.serviceWorker.ready;if(!t.pushManager)return;let s=await t.pushManager.getSubscription();if(!s&&"granted"===Notification.permission){let n=await new Promise(t=>e.emit("getVapidKey",t));n&&(s=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n}))}s&&(e.emit("pushSubscribe",s.toJSON()),e.emit("visibilityChange",document.hidden))}catch(e){}})()}},[ta,tx,y]),(0,r.useEffect)(()=>{s.current&&"1"!==localStorage.getItem(eD)&&j(e=>{let t;return e.emit("pushSubscribe",(t=s.current,t?.type==="expo"?{type:"expo",token:t.token}:t?.toJSON?.()||t))})},[w,j]),(0,r.useEffect)(()=>{let e=ta?.current;if(!e||!tx)return;let t=()=>{e.emit("getStatusState"),e.emit("getNotificationState"),e.emit("getSessionTasks",e=>P.rh.getState().applySessionTasksState(s(),e))},s=()=>P.rh.getState().currentKey,n=e=>P.rh.getState().applyStatusState(s(),e),r=e=>{if(ej.getState().handleStatusChange(e),P.rh.getState().applyStatusChange(s(),e),e&&("done"===e.state||"blocked"===e.state)){let t="done"===e.state,s=e.tool?e.tool.charAt(0).toUpperCase()+e.tool.slice(1):"Terminal",n=t?`${s} \xb7 your turn`:`${s} needs input`;window.__9R_DESKTOP__?.showNotification&&window.__9R_DESKTOP__.showNotification(n,t?"The agent finished its turn and is waiting for you":"Action required to proceed")}},l=e=>P.rh.getState().applyStatusCleared(s(),e),a=e=>ej.getState().handleNotificationState(e),i=()=>t(),o=()=>{e.emit("visibilityChange",document.hidden)},c=()=>t();e.on("notificationState",a),e.on("notificationCleared",i),e.on("statusState",n),e.on("statusChange",r),e.on("statusCleared",l);let d=e=>P.rh.getState().applySessionTasks(s(),e);return e.on("sessionTasks",d),e.on("connect",c),document.addEventListener("visibilitychange",o),t(),()=>{e.off("notificationState",a),e.off("notificationCleared",i),e.off("statusState",n),e.off("statusChange",r),e.off("statusCleared",l),e.off("sessionTasks",d),e.off("connect",c),document.removeEventListener("visibilitychange",o)}},[ta,tx]),N=eM(),C=(0,r.useMemo)(()=>eI(N).total,[N]),(0,r.useEffect)(()=>{window.__9R_DESKTOP__?.setBadge&&window.__9R_DESKTOP__.setBadge(C),"u">typeof navigator&&"setAppBadge"in navigator&&(C>0?navigator.setAppBadge(C).catch(()=>{}):navigator.clearAppBadge().catch(()=>{}))},[C]),{subscribeToPush:k,unsubscribeFromPush:(0,r.useCallback)(async()=>{localStorage.setItem(eD,"1");try{if(s.current?.type==="expo"){j(e=>e.emit("pushUnsubscribe",s.current.token)),s.current=null;return}if(s.current)await s.current.unsubscribe(),j(e=>e.emit("pushUnsubscribe",s.current.endpoint)),s.current=null;else{let e=await navigator.serviceWorker.ready,t=await e.pushManager.getSubscription();t&&(j(e=>e.emit("pushUnsubscribe",t.endpoint)),await t.unsubscribe())}}catch(e){console.error("Push unsubscribe failed:",e)}},[ta,j]),notifications:b}),sn=K(e=>e.setKeyboardOpen),[sr,sl]=(0,r.useState)(()=>window.innerWidth>=eJ.jK),si=(S=(0,r.useRef)(null),(0,r.useCallback)(({enabled:e,sessionIds:t,activeSessionId:s,onSwitch:n})=>({onTouchStart:t=>{if(!e||1!==t.touches.length||function(e,t=e=>"function"==typeof getComputedStyle?getComputedStyle(e).overflowX:""){for(let s=e;s&&1===s.nodeType;s=s.parentElement){let e=t(s);if(("auto"===e||"scroll"===e)&&s.scrollWidth>s.clientWidth)return!0}return!1}(t.target))return S.current=null;let s=t.touches[0];S.current={x:s.clientX,y:s.clientY,time:performance.now()}},onTouchEnd:r=>{let l=S.current;if(S.current=null,!l||!e||t.length<2)return;let a=r.changedTouches[0],i=a.clientX-l.x,o=a.clientY-l.y;if(performance.now()-l.time>eJ.bl.maxDuration||Math.abs(i)<eJ.bl.minDistance||Math.abs(i)<Math.abs(o)*eJ.bl.ratio)return;let c=t.indexOf(s);if(-1===c)return;let d=i<0?t[c+1]:t[c-1];d&&d!==s&&n?.(d)}}),[]));(0,r.useEffect)(()=>{let e=0,t=()=>{clearTimeout(e),e=setTimeout(()=>sl(window.innerWidth>=eJ.jK),50)};return window.addEventListener("resize",t),()=>{clearTimeout(e),window.removeEventListener("resize",t)}},[]);let sc=H[H.length-1]||{type:"list"},sd=sc?.type==="terminal"||sr&&sc?.type==="list",su=sc?.type==="browser",sx=so(e=>e.workspaceProfiles[Z??"default"]||"default"),sm=sc?.type==="terminal"?sc.sessionId:sd&&U[U.length-1]||null,sp=function({isDesktop:e,isTerminalView:t,activeSessionId:s,currentView:n,openedSessions:l}){let a=(0,r.useRef)({}),i=(0,r.useRef)({}),o=(0,r.useRef)(null),c=(0,r.useRef)(null),d=(0,r.useRef)(!1),u=(0,r.useRef)(null),x=(0,r.useCallback)((t,s)=>{s?(a.current[t]=s,u.current===t&&e&&!d.current&&(u.current=null,setTimeout(()=>s.focus?.(),50))):delete a.current[t]},[e]),m=(0,r.useCallback)((e,t)=>{t?i.current[e]=t:delete i.current[e]},[]),p=(0,r.useCallback)(t=>{c.current=t,t&&u.current&&e&&d.current&&(u.current=null,setTimeout(()=>t.focus?.(),50))},[e]),f=(0,r.useCallback)(t=>{e&&(u.current=t,setTimeout(()=>{u.current===t&&(u.current=null,d.current&&c.current?.focus?c.current.focus():a.current[t]?.focus?.())},60))},[e]),b=(0,r.useCallback)(()=>{c.current?.openTextPanel?.()},[]),g=(0,r.useCallback)(e=>{d.current=e},[]),v=(0,r.useCallback)(e=>a.current[e]?.focus?.(),[]),y=(0,r.useCallback)(()=>{c.current?.focus?.()},[]),w=(0,r.useCallback)(e=>{d.current?a.current[e]?.focus?.():c.current?.focus?.()},[]),j=(0,r.useRef)(0),k=(0,r.useCallback)(t=>{if(!e)return;if(h.B.getState().fullMode){o.current&&(o.current.scrollLeft=0);return}cancelAnimationFrame(j.current),j.current=0;let s=o.current,n=(0,eQ.g4)({container:s,pane:i.current[t]});if(null==n){j.current=requestAnimationFrame(()=>{j.current=0;let e=(0,eQ.g4)({container:s,pane:i.current[t]});null!=e&&s.scrollTo({left:e,behavior:"smooth"})});return}s.scrollTo({left:n,behavior:"smooth"})},[e]),N=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!e||n?.type!=="terminal"||!n?.sessionId||N.current===n.sessionId)return;N.current=n.sessionId;let t=requestAnimationFrame(()=>k(n.sessionId));return()=>cancelAnimationFrame(t)},[n?.type,n?.sessionId,e,k]),(0,r.useEffect)(()=>{if(!e||!t||!s)return;let n=setTimeout(()=>{d.current?c.current?.focus?.():a.current[s]?.focus?.()},60);return()=>clearTimeout(n)},[s,e,t]),(0,r.useMemo)(()=>({panesContainerRef:o,registerPaneApi:x,registerPaneElement:m,registerKeyboardTextApi:p,handlePasteFallback:b,handleInputFocusChange:g,focusPane:v,focusKeyboardInput:y,toggleInputFocus:w,scrollPaneIntoView:k,requestFocus:f}),[x,m,p,b,g,v,y,w,k,f])}({isDesktop:sr,isTerminalView:sd,activeSessionId:sm,currentView:sc,openedSessions:U}),sf=function({sessions:e,currentView:t,viewStack:s,setViewStack:n,pushView:l,storePopView:a,activeWorkspaceId:i,setActiveWorkspaceId:o,activeSessionId:c,addOpenedSession:d,removeOpenedSession:u,touchLivePane:x,createSession:m,deleteSession:p,renameSession:f,busRef:b,isDesktop:g=!1,requestFocus:v=null}){let{t:y}=(0,eu.s)(),w=(0,r.useCallback)(e=>{let t=[...s];t[t.length-1]={type:"terminal",sessionId:e},n(t)},[s,n]),j=(0,r.useCallback)(t=>e.filter(e=>(0,eQ.xs)(e)===(t??null)).map(e=>e.id),[e]),k=(0,r.useCallback)(e=>alert(y("workspace.failedCreateSession",{error:e})),[y]),N=(0,r.useCallback)((s,n)=>{let r=e.find(e=>e.id===s);if(!r&&void 0===n)return;let a=r?(0,eQ.xs)(r):n;o(a);let i=j(a);i.forEach(e=>d(e)),d(s),x([...i,s]),"terminal"===t.type?w(s):l({type:"terminal",sessionId:s}),r||v?.(s)},[e,j,d,x,o,t,l,w,v]);(0,r.useEffect)(()=>{let t=e=>{if(e.data?.type!=="NOTIFICATION_CLICK")return;let t=new URLSearchParams(new URL(e.data.url||"",location.origin).search).get("t");t&&N(t)},s=()=>{let t=Object.values(ej.getState().notifications||{}).filter(e=>"blocked"===e.type);if(!t.length)return;let s=t=>{let s=e.find(e=>e.id===t);return s&&(0,eQ.xs)(s)===(i??null)},n=t.sort((e,t)=>{let n=s(e.sessionId),r=s(t.sessionId);return n&&!r?-1:!n&&r?1:(t.timestamp||0)-(e.timestamp||0)})[0];n?.sessionId&&N(n.sessionId)};return window.addEventListener("message",t),window.addEventListener("9remote:dock-click",s),()=>{window.removeEventListener("message",t),window.removeEventListener("9remote:dock-click",s)}},[N,e,i]),(0,r.useEffect)(()=>{let e=e=>{e.detail?.sessionId&&N(e.detail.sessionId)};return window.addEventListener(eJ.vP,e),()=>window.removeEventListener(eJ.vP,e)},[N]);let C=(0,r.useCallback)(e=>{let t=j(i);if(t.length<2)return;let s=t.indexOf(c);if(-1===s)return;let n="prev"===e?(s-1+t.length)%t.length:(s+1)%t.length;N(t[n])},[j,i,c,N]),S=(0,r.useCallback)(e=>{let t=j(i);e<0||e>=t.length||N(t[e])},[j,i,N]),T=(0,r.useCallback)((e,s=null,n=null,r=null,a=null,i=!1,c=!1)=>{m(e,n,s,r||null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let n=e4(a,i);n&&h.B.getState().queueStartup(e.sessionId,n),a?.id&&h.B.getState().setSessionAgent(e.sessionId,a.id);let r=s??null;o(r);let c=j(r);c.forEach(e=>d(e)),d(e.sessionId),x([...c,e.sessionId]),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},c,a)},[m,j,d,x,k,t,w,l,o,v]),R=(0,r.useCallback)(e=>{if(!e?.resume)return;let s="ui"===e.mode,n=P.rh.getState().currentKey||"main",r=h.B.getState().agentClisBy[n]?.list?.find(t=>t.id===e.agent)||null,a=s?null:e6(r,e.resume);m(null,null,i,e.cwd||null,n=>{if(!n?.success)return k(n?.error);if(!n.sessionId)return;a&&h.B.getState().queueStartup(n.sessionId,a);let r=s?`${e.agent}-ui`:e.agent;r&&h.B.getState().setSessionAgent(n.sessionId,r),b?.current?.emit("claimAgentSession",{sessionId:n.sessionId,agent:r,conversationId:e.sessionId},()=>h.B.getState().invalidateAgentHistory()),d(n.sessionId),x(n.sessionId),"terminal"===t.type?w(n.sessionId):l({type:"terminal",sessionId:n.sessionId}),v?.(n.sessionId)})},[m,i,d,x,k,w,l,t,v,b]),E=(0,r.useCallback)((e,s=null,n=!1,r=null,a=!1)=>{m(r,e,i,null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let r=e4(s,n);r&&h.B.getState().queueStartup(e.sessionId,r),s?.id&&h.B.getState().setSessionAgent(e.sessionId,s.id),d(e.sessionId),x(e.sessionId),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},a,s)},[m,i,d,x,k,w,l,t,v]),$=(0,r.useCallback)((s,n,r=null,a=!1)=>{m(n,null,i,e.find(e=>e.id===s)?.cwd||null,e=>{if(!e?.success)return k(e?.error);if(!e.sessionId)return;let n=e.replaced||s;r?.id&&h.B.getState().setSessionAgent(e.sessionId,r.id),n?h.B.getState().replaceOpenedSession(n,e.sessionId):d(e.sessionId),x(e.sessionId),"terminal"===t.type?w(e.sessionId):l({type:"terminal",sessionId:e.sessionId}),v?.(e.sessionId)},a,r,s)},[m,i,k,d,x,w,l,t,v,e]),z=(0,r.useCallback)(e=>{m(null,t=>{if(!t.success)return k(t.error);t.sessionId&&(d(t.sessionId),e?.(t.sessionId))})},[m,d,k]),M=(0,r.useCallback)(t=>{o(t);let s=e.filter(e=>(0,eQ.xs)(e)===(t??null));s.forEach(e=>d(e.id)),x(s.map(e=>e.id));let n=s[0];n&&w(n.id)},[e,o,d,x,w]),A=(0,r.useCallback)(s=>{let n=e.find(e=>e.id===s),r=(0,eQ.xs)(n),l=t?.type==="terminal"&&t.sessionId===s,i=()=>{if(u(s),h.B.getState().closeSession(s),!l)return;let t=e.filter(e=>e.id!==s),n=t.filter(e=>(0,eQ.xs)(e)===r)[0]||t[0];n?(w(n.id),x(n.id)):a()},o=n?.hostKey?P.rh.getState().hosts[n.hostKey]:null;if(o){tn(o).deleteSession(s),i();return}p(s,i)},[e,t,p,u,x,a,w]),I=(0,r.useCallback)((t,s)=>{let n=e.find(e=>e.id===t)?.hostKey;if(n){let e=P.rh.getState().hosts[n];e&&tn(e).renameSession(t,s);return}f(t,s,e=>{e.success||alert(y("workspace.failedRenameSession",{error:e.error}))})},[e,f,y]);return(0,r.useMemo)(()=>({handleSelectSession:N,handleSelectWorkspace:M,handleCreateSession:T,handleQuickCreateSession:E,handleReplaceSession:$,handleResumeAgentSession:R,handleCreateSessionInline:z,handleDeleteSession:A,handleRenameSession:I,switchSession:C,switchToIndex:S}),[N,M,T,E,$,R,z,A,I,C,S])}({sessions:tG,currentView:sc,viewStack:H,setViewStack:V,pushView:q,storePopView:X,activeWorkspaceId:Z,setActiveWorkspaceId:Q,activeSessionId:sm,addOpenedSession:J,removeOpenedSession:G,touchLivePane:et,createSession:tE,deleteSession:t$,renameSession:tz,busRef:ta,requestFocus:sp.requestFocus}),{systemInfo:sh,mobileEditor:sb,setMobileEditor:sg,openFileRef:sv,handleOpenWorkspaceList:sy,handleOpenFiles:sw,handleSelectWorkspace:sj,handleBrowseFolder:sk,handlePathChange:sN,handleOpenFile:sC,handleOpenGit:sS,handleSetWorkspace:sT}=function({pushView:e,viewStack:t,setViewStack:s,currentView:n,cwdBySession:l,sessions:a=[],isDesktop:i,fileBus:o,scope:c=""}){let[d,u]=(0,r.useState)(null),[x,m]=(0,r.useState)(null),p=(0,r.useRef)(null),f=(0,r.useCallback)(async()=>{if(!d){let e=await o.getSystemInfo();e.success&&u(e)}e({type:"workspaces"})},[e,o,d]),h=(0,r.useCallback)(async t=>{if(t){eh(t,c),e({type:"files",workspace:t,currentPath:t});return}if("terminal"===n.type){let t=n.sessionId&&(l[n.sessionId]||a.find(e=>e.id===n.sessionId)?.cwd)||null;if(t){eh(t,c),e({type:"files",workspace:t,currentPath:t});return}}let s=ef(c);if(s.length>0){let t=s[0];e({type:"files",workspace:t.path,currentPath:t.lastPath||t.path});return}f()},[e,f,n,l,a,c]),b=(0,r.useCallback)(e=>{eh(e,c),s([...t.filter(e=>"workspaces"!==e.type&&"files"!==e.type),{type:"files",workspace:e}])},[t,s]),g=(0,r.useCallback)(t=>{e({type:"browse",path:t})},[e]),v=(0,r.useCallback)((e,t)=>{!function(e,t,s=""){let n=(0,O.kb)(e),r=ef(s),l=r.findIndex(e=>e.path===n);-1!==l&&(r[l]={...r[l],lastPath:(0,O.kb)(t)},localStorage.setItem(ex(s),JSON.stringify(r)))}(e,t,c)},[]),y=(0,r.useCallback)((e,t,s={})=>{i?p.current?.(e,s):m({path:e,line:s.line,column:s.column,workspace:n.workspace})},[i,n.workspace]);return{systemInfo:d,mobileEditor:x,setMobileEditor:m,openFileRef:p,handleOpenWorkspaceList:f,handleOpenFiles:h,handleSelectWorkspace:b,handleBrowseFolder:g,handlePathChange:v,handleOpenFile:y,handleOpenGit:(0,r.useCallback)(()=>{let s=t.find(e=>"files"===e.type);s?.workspace&&e({type:"git",workspace:s.workspace})},[e,t]),handleSetWorkspace:(0,r.useCallback)(e=>{eh(e,c),s([...t.filter(e=>"browse"!==e.type&&"workspaces"!==e.type&&"files"!==e.type),{type:"files",workspace:e}])},[t,s])}}({pushView:q,viewStack:H,setViewStack:V,currentView:sc,cwdBySession:ea,sessions:tX,isDesktop:sr,fileBus:t7,scope:tH}),[sR,sE]=(0,r.useState)(null),s$=ev(e=>e.open),sz=(0,r.useMemo)(()=>W?ef(tH):[],[W,tV,tH]),sM=(0,r.useCallback)(e=>{sE(null),e&&tM(e.split("/").filter(Boolean).pop()||e,e,t=>{let s=t?.workspace||t?.group;t?.success&&s?.id&&(eh(e,tH),Q(s.id),sf.handleCreateSession(null,s.id,null,e))})},[tM,Q,sf]),sP=(0,r.useCallback)(e=>{if(e)return sM(e);sE({initialPath:null})},[sM]),sA=(0,r.useCallback)((e,t,s,n,r,l,a)=>{let i=tY.find(e=>e.id===t)?.hostKey||Object.values(tU).find(e=>"string"==typeof t&&t.startsWith(`${e.key}:`))?.key;if(i){let o=P.rh.getState().hosts[i];if(!o)return;tn(o,{onSelectSession:sf.handleSelectSession}).createSession(e,eC(t,i),s,n,r,l,a);return}sf.handleCreateSession(e,t,s,n,r,l,a)},[tY,tU,sf]),sI=(0,r.useCallback)(e=>{let t=tG.find(e=>e.id===sm)?.hostKey||tY.find(e=>e.id===Z)?.hostKey;if(!t||!e?.resume)return;let s=P.rh.getState().hosts[t];if(!s)return;let n="ui"===e.mode,r=h.B.getState().agentClisBy[t]?.list?.find(t=>t.id===e.agent)||null,l=n?null:e6(r,e.resume),a=n?`${e.agent}-ui`:e.agent,i=eC(Z,t);tn(s,{onSelectSession:sf.handleSelectSession}).createSession(null,i&&"_"!==i?i:null,null,e.cwd||null,null,!1,!1,s=>{s?.success&&s.sessionId&&(l&&h.B.getState().queueStartup(s.sessionId,l),a&&h.B.getState().setSessionAgent(s.sessionId,a),(0,P.Nw)(t,t=>t.emit("claimAgentSession",{sessionId:s.sessionId,agent:a,conversationId:e.sessionId},()=>h.B.getState().invalidateAgentHistory())))})},[tG,tY,sm,Z,sf]),sL=(0,r.useCallback)(e=>{sA(null,Z,null,e)},[sA,Z]),sB=tY.find(e=>e.id===Z)?.hostKey||null,sF=sB||t_||"main",sK=tg(eE(sB).busRef,sF),sO=tb(e=>e.open),sW=tb(e=>e.isOpen),s_=tb(e=>e.close),[sH,sU]=(0,r.useState)(!1),sq=tV.find(e=>e.id===Z)?.path||tX.find(e=>e.id===sm)?.workspacePath||null,sX=(0,r.useCallback)(()=>{let{agentId:e,shellId:t,yolo:s}=ts(),n=(sK||[]).flatMap(e=>{let t=tv.H8.find(t=>t.aiEngine===e.id);return t?[e,t]:e}),r=e&&n.find(t=>t.id===e)||null,l=tG.filter(e=>(0,eQ.xs)(e)===(Z??null)).length+1;sA(r?`${r.short||r.label} ${l}`:null,Z,r?null:t,null,r,s,!0)},[sK,tG,Z,sA]),sV=(0,r.useCallback)(e=>{let t=tV.map(e=>e.id);if(tX.some(e=>null===(0,eQ.xs)(e))&&t.push(null),t.length<2)return;let s=t.indexOf(Z??null),n=-1===s?0:s,r="prev"===e?(n-1+t.length)%t.length:(n+1)%t.length;sf.handleSelectWorkspace(t[r])},[tV,tX,Z,sf]);!function(e,t=!0){let s=(0,r.useRef)(e);(0,r.useEffect)(()=>{s.current=e}),(0,r.useEffect)(()=>{if(!t)return;let e=e=>{if(document.querySelector('[role="dialog"], [aria-modal="true"], .modal-overlay'))return;let t=function(e){let t=tc();if(t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){let t=ti.exec(e.code)||(/^[1-9]$/.test(e.key)?[null,e.key]:null);return t?{id:tl.id,index:Number(t[1])-1}:"ArrowLeft"===e.key?{id:"sessionPrev"}:"ArrowRight"===e.key?{id:"sessionNext"}:"ArrowUp"===e.key?{id:"workspacePrev"}:"ArrowDown"===e.key?{id:"workspaceNext"}:tp(e.target)?null:"Backquote"===e.code||"`"===e.key?{id:"toggleFocus"}:"Equal"===e.code||"="===e.key||"≠"===e.key||"+"===e.key?{id:"fitPanes"}:"KeyW"===e.code||"∑"===e.key||e.key?.toLowerCase()==="w"?{id:"closeTerminal"}:"KeyA"===e.code||"\xe5"===e.key||e.key?.toLowerCase()==="a"?{id:"attentionNext"}:null}if(t&&e.altKey&&e.shiftKey&&!e.ctrlKey&&!e.metaKey){if(tp(e.target))return null;let t=tf(e.target);return"Enter"===e.key||"Enter"===e.code?{id:"newTerminal"}:t?null:"KeyP"===e.code||"π"===e.key||"∏"===e.key||e.key?.toLowerCase()==="p"?{id:"palette"}:"KeyB"===e.code||"ı"===e.key||"∫"===e.key||e.key?.toLowerCase()==="b"?{id:"toggleSidebar"}:"KeyJ"===e.code||"\xd4"===e.key||"∆"===e.key||e.key?.toLowerCase()==="j"?{id:"toggleRightPanel"}:"Slash"===e.code||"?"===e.key||"\xbf"===e.key||"/"===e.key?{id:"help"}:null}if(e.ctrlKey&&!e.shiftKey&&!e.metaKey&&!e.altKey&&("Backquote"===e.code||"`"===e.key)&&!tp(e.target))return{id:"toggleFocus"};if(!t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){if(tp(e.target))return null;if("Equal"===e.code||"="===e.key||"+"===e.key)return{id:"fitPanes"};if("KeyW"===e.code||e.key?.toLowerCase()==="w")return{id:"closeTerminal"};if("KeyA"===e.code||e.key?.toLowerCase()==="a")return{id:"attentionNext"}}if(!t&&e.ctrlKey&&e.shiftKey&&!e.altKey&&!e.metaKey){let t=ti.exec(e.code);if(t)return{id:tl.id,index:Number(t[1])-1};if("ArrowLeft"===e.key)return{id:"sessionPrev"};if("ArrowRight"===e.key)return{id:"sessionNext"};if("ArrowUp"===e.key)return{id:"workspacePrev"};if("ArrowDown"===e.key)return{id:"workspaceNext"};if("Equal"===e.code||"="===e.key||"+"===e.key)return{id:"fitPanes"};let s=tf(e.target);if("Enter"===e.key||"Enter"===e.code)return{id:"newTerminal"};if(s)return null;if("KeyP"===e.code||e.key?.toLowerCase()==="p")return{id:"palette"};if("KeyB"===e.code||e.key?.toLowerCase()==="b")return{id:"toggleSidebar"};if("KeyJ"===e.code||e.key?.toLowerCase()==="j")return{id:"toggleRightPanel"};if("Slash"===e.code||"/"===e.key||"?"===e.key)return{id:"help"}}return null}(e);if(!t)return;let n=s.current?.[t.id];n&&(e.preventDefault(),e.stopPropagation(),n(t.index))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[t])}({sessionPrev:()=>sf.switchSession("prev"),sessionNext:()=>sf.switchSession("next"),workspacePrev:()=>sV("prev"),workspaceNext:()=>sV("next"),sessionIndex:e=>sf.switchToIndex(e),closeTerminal:(0,r.useCallback)(()=>{if(sc?.type!=="terminal"||!sc.sessionId)return;let e=tX.find(e=>e.id===sc.sessionId);e&&t9({isOpen:!0,title:z("sessions.deleteTitle"),message:z("sessions.deleteMessage",{name:e.name||z("terminal.defaultName")}),confirmText:z("common.delete"),onConfirm:()=>sf.handleDeleteSession(e.id)})},[sc,tX,sf,z]),toggleFocus:()=>sp.toggleInputFocus(sm),fitPanes:()=>window.dispatchEvent(new CustomEvent("terminal:fitPanes")),newTerminal:sX,toggleSidebar:ed,toggleRightPanel:eT,palette:()=>{sq&&sU(!0)},attentionNext:sa(eM(),tG,sf.handleSelectSession),help:sO},sr&&sd);let sJ=(0,r.useCallback)(e=>{let t=tV.find(e=>e.id===Z)?.path||tX.find(e=>e.id===sc.sessionId)?.workspacePath||null;eF(),q({type:"editor",path:e,workspace:t})},[tV,Z,tX,sc,q,eF]),sG=(0,r.useCallback)((e,t={})=>{if((0,O.pA)(e)){let{status:t,repoPath:s,filePath:n}=(0,O.qu)(e);sg({path:s?`${s}/${n}`:n,workspace:s||void 0,diffStatus:t});return}sg({path:e,workspace:tV.find(e=>e.id===Z)?.path,preview:!!t.preview,artifactSessionId:t.artifactSessionId||null})},[tV,Z,sg]),sY=(0,r.useCallback)((e,t)=>{if(!t?.path)return;let s=t.title||t.path.split("/").pop();sr?eB(t.path,{preview:!0,artifactTitle:s,artifactSessionId:e}):sG(t.path,{preview:!0,artifactSessionId:e})},[sr,eB,sG]);(0,r.useEffect)(()=>{let e=ta.current;if(!e)return;let t=({path:e,title:t,sessionId:s}={})=>{if(!e)return;let n={path:e,title:t||e.split("/").pop(),at:Date.now()};s&&e1(s,n),s&&s!==sm||sY(s,n)};return e.on("artifactOpen",t),()=>e.off("artifactOpen",t)},[ta,tx,sm,e1,sY]),(0,r.useEffect)(()=>{sd&&void 0!==Z&&en(Z)},[sd,Z,en]);let sZ=sm?tG.find(e=>e.id===sm):null,sQ=sZ?sZ.name||z("terminal.defaultName"):null;(0,r.useEffect)(()=>(eX(Object.keys(ss).length,sQ),()=>eX(0)),[ss,sQ]);let[s0,s1]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if("terminal"!==sc.type)return s1(!1);let e=requestAnimationFrame(()=>s1(!0));return()=>cancelAnimationFrame(e)},[sc.type]);let s2=(0,r.useRef)(null),[s5,s3]=(0,r.useState)("");(0,r.useEffect)(()=>{let e="terminal"===sc.type?sc.sessionId:null,t=s2.current;if(s2.current=e,!s0||!e||!t||e===t)return s3("");s3(U.indexOf(e)>U.indexOf(t)?"term-slide-right":"term-slide-left")},[sc,s0,U]);let s4=(0,r.useCallback)(()=>{if(!sr&&sb){sb.artifactSessionId&&e2(sb.artifactSessionId,sb.path),sg(null);return}let e=Array.isArray(H)?H:[],t=e.length>1?e[e.length-2]:{type:"list"};X(),e5.replace((0,uc.O5)(t))},[e5,X,sr,sb,sg,e2,H]),s6=(0,r.useCallback)(()=>{if("terminal"!==sc.type)return s4();V([{type:"list"}])},[sc,s4,V]);(0,r.useEffect)(()=>{tr&&tR()},[tr,tR]),(0,r.useEffect)(()=>{if(0===tG.length||0===U.length)return;let e=setTimeout(()=>{let e=tG.map(e=>e.id);U.filter(t=>!e.includes(t)).forEach(e=>G(e))},500);return()=>clearTimeout(e)},[tG,U,G]),function({setKeyboardOpen:e}){(0,r.useEffect)(()=>{let t=!1,s=/iPhone|iPad|iPod/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,n={},r=()=>{let r=window.visualViewport,l=r?.height||window.innerHeight,a=r?.offsetTop||0,i=window.innerWidth;(void 0===n[i]||l>n[i])&&(n[i]=l);let o=l<window.innerHeight-100||l<n[i]-100;t!==o&&(t=o,e(o)),document.documentElement.style.setProperty("--app-height",`${l}px`),s&&!o&&a>0?document.documentElement.style.transform=`translateY(${-a}px)`:document.documentElement.style.transform="",window.scrollTo(0,0)};document.documentElement.classList.add("terminal-page");let l=0,a=()=>{clearTimeout(l),l=setTimeout(r,100)};window.visualViewport&&(window.visualViewport.addEventListener("resize",a),window.visualViewport.addEventListener("scroll",a)),window.addEventListener("resize",a),a();let i=window.ReactNativeWebView&&/Android/i.test(navigator.userAgent)?setInterval(a,250):0;return()=>{clearInterval(i),clearTimeout(l),document.documentElement.classList.remove("terminal-page"),document.documentElement.style.transform="",window.visualViewport&&(window.visualViewport.removeEventListener("resize",a),window.visualViewport.removeEventListener("scroll",a)),window.removeEventListener("resize",a)}},[e]),(0,r.useEffect)(()=>{let e=e=>{e.target.closest(".xterm-viewport,.xterm-screen,.terminal-scroll,.cm-scroller,.cm-content,.overflow-auto,.overflow-x-auto,.overflow-y-auto,.modal-scrollable,.brand-range")||e.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>document.removeEventListener("touchmove",e)},[]),(0,r.useEffect)(()=>{let e=e=>{e.target.matches("input, textarea")&&requestAnimationFrame(()=>window.scrollTo(0,0))};return document.addEventListener("focusin",e),()=>document.removeEventListener("focusin",e)},[]),(0,r.useEffect)(()=>{if(!window.ReactNativeWebView||!/Android/i.test(navigator.userAgent))return;let e=e=>{if(e.target.matches("input, textarea"))try{window.ReactNativeWebView.postMessage(JSON.stringify({type:"INPUT_FOCUS",focused:"focusin"===e.type}))}catch(e){}};return document.addEventListener("focusin",e),document.addEventListener("focusout",e),()=>{document.removeEventListener("focusin",e),document.removeEventListener("focusout",e)}},[])}({setKeyboardOpen:sn});let[s8,s9]=(0,r.useState)(null),[s7,ne]=(0,r.useState)(null),nt=eE(s8||t_||null),ns=eE(s7||t_||null),nn=tU[s8||t_],nr=tU[s7||t_],nl=e=>e?.status==="online"||e?.status==="full",na=(0,r.useCallback)((e=null)=>{s9(e),q({type:"remote"})},[q]),ni=(0,r.useCallback)((e=null)=>{if(!sr){ne(e),q({type:"mobile"});return}if(!eO){ne(e),eH(!0);return}ns.busRef.current?.emit("mobile:stop"),eG(null),eH(!1),ne(null)},[sr,eO,eH,eG,ns,q]),no=(0,r.useCallback)(e=>{eV(e,{startWidth:e_,axis:-1,onWidth:eq})},[e_,eq]),nc=(0,r.useCallback)(()=>{to.current?.retryNow()},[to]),nd=(0,r.useCallback)(()=>{P.rh.getState().closeAll(),el(),e9(),sessionStorage.setItem("9remote_manual_disconnect","1"),window.location.replace("/login")},[el,e9]),nu=(0,r.useCallback)(()=>{t9({isOpen:!0,title:z("workspace.logoutTitle"),message:z("workspace.logoutMessage"),onConfirm:nd})},[nd,z]),nx=(0,r.useCallback)(e=>{let t=tL().find(t=>(0,p.Uo)(t.key)===e);t&&tK(t.id),e===t_&&nd()},[tL,tK,t_,nd]),nm=(0,r.useCallback)(()=>{P.rh.getState().disconnectHost(t_),td()},[t_,td]),np=(0,r.useCallback)(()=>{P.rh.getState()._patchHost(t_,{status:"connecting"}),tu()},[t_,tu]),nf=(0,r.useCallback)(()=>{t9({isOpen:!1,title:"",message:"",onConfirm:null})},[]),nh=(0,r.useCallback)(e=>{Y(e),tD(e)},[Y,tD]),nb=(0,r.useCallback)(e=>{Z&&ey(Z,e)},[Z,ey]),ng=(0,r.useMemo)(()=>({open:ew,tabs:ek,width:eS,onTabChange:eR,onResize:e$,onToggle:eT,onNewTerminal:sL}),[ew,ek,eS,eR,e$,eT,sL]),nv=(0,r.useMemo)(()=>({filePath:ez,previewSeq:eK,artifactTitle:e0,jump:eP,width:eA,onResize:eL,onOpen:sr?eB:sG,onClose:eF,onOpenFull:sJ}),[ez,eK,e0,eP,eA,eL,sr,eB,sG,eF,sJ]),ny=(0,r.useMemo)(()=>({open:eO,mode:eW,width:e_,busRef:ns.busRef,protocolRef:ns.pmRef,connected:s7?nl(nr):tx,onResizeStart:no}),[eO,eW,e_,ns,s7,nr,tx,no]);if(!W||!t2&&!t5)return(0,n.jsx)(oA,{label:z("workspace.loading")});let nw=tx&&ty?na:null,nj=tx&&tw?ni:null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(oI.A,{}),(0,n.jsx)(r.Suspense,{fallback:null,children:(0,n.jsx)(uu,{hydrated:W,apiKey:e7?.apiKey})}),(0,n.jsxs)("div",{className:"terminal-container h-[var(--app-height,100vh)] fixed inset-0 overflow-hidden overscroll-none",children:[!sr&&(0,n.jsx)("div",{className:`absolute inset-0 transition-opacity duration-150 ease-out ${"list"===sc.type?"opacity-100 z-10":"opacity-0 z-0 pointer-events-none"}`,children:(0,n.jsx)(oD,{sessions:tX,cwdBySession:ea,connected:tx,onSelect:sf.handleSelectSession,onCreate:sf.handleCreateSession,onDelete:sf.handleDeleteSession,onRename:sf.handleRenameSession,onResumeAgentSession:sf.handleResumeAgentSession,onLogout:nu,onOpenRemote:nw,onOpenRemoteHost:na,onOpenMobileHost:ni,tunnelUrl:e7?.tunnelUrl,apiKey:e7?.apiKey,connectionMode:tm,isActive:"list"===sc.type,busRef:ta,subscribeToPush:se,unsubscribeFromPush:st,hostVersion:tk||tN,agentVersion:tk||tN,carrier:th,workspaces:tV,onAddWorkspace:sP,homeDir:sh?.homedir,onRenameWorkspace:tP,onDeleteWorkspace:tA,onReorderSession:nh,recentWorkspaces:sz,shells:tQ,onRenameHost:tZ,onDeleteHost:nx,onMainDisconnect:nm,onMainReconnect:np})}),(sr||U.length>0)&&(0,n.jsx)(oM,{platform:tj,hostVersion:tk||tN,agentVersion:tk||tN,sessions:tG,workspaces:tY,onCreateAnyHost:sA,onQuickCreateHostAware:sX,onResumeAgentSessionForeign:sI,activeSessionId:sm,activeSession:sZ,activeWorkspaceId:Z,openedSessions:U,livePanes:ee,mountedWorkspaces:es,cwdBySession:ea,isDesktop:sr,isTerminalView:sd,pairDashboard:sr&&sc?.type==="pair"?(0,n.jsx)(cG,{}):null,browserPanel:su?(0,n.jsx)(cT,{busRef:sc.hostKey?eE(sc.hostKey).busRef:ta,connected:sc.hostKey?nl(tU[sc.hostKey]):tx,onBack:X,profile:sx,workspaceId:Z,onProfileChange:e=>so.getState().setProfileFor(Z,e)}):null,welcomeActive:sc?.type==="welcome"||sr&&sc?.type==="list",slideClass:s5,shells:tQ,sidebarCollapsed:ei,sidebarWidth:em,setSidebarWidth:ep,paneWidth:Z?eg[Z]??null:null,setPaneWidth:Z?nb:void 0,toggleSidebar:ed,paneRegistry:sp,bindSwipeTab:si,nav:sf,onBack:s6,atStackBottom:sr&&"list"===sc.type,onOpenRemote:nw,onOpenMobile:nj,onOpenRemoteHost:na,onOpenMobileHost:ni,onOpenFiles:sw,onLogout:nu,onDeleteWorkspace:tA,onReorderSession:tD,onAddWorkspace:sP,onSetHiddenRepos:tI,onOpenSettings:s$,onRenameHost:tZ,onDeleteHost:nx,onMainDisconnect:nm,onMainReconnect:np,homeDir:sh?.homedir,recentWorkspaces:sz,onOpenArtifact:sY,rightPanel:ng,editorPanel:nv,mobilePanel:ny,fileBus:t7,tunnelUrl:e7?.tunnelUrl,apiKey:e7?.apiKey,connectionMode:tm,subscribeToPush:se,unsubscribeFromPush:st}),sR&&(0,n.jsx)(sD,{fileBus:t7,scope:tH,initialPath:sR.initialPath,onSelect:sM,onClose:()=>sE(null)}),"remote"===sc.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cr,{onClose:()=>{s9(null),s4()},busRef:nt.busRef,protocolRef:nt.pmRef,connected:s8?nl(nn):tx,carrier:s8?nn?.carrier||"ws":th,hostPlatform:nn?.platform||tj})}),"mobile"===sc.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(ar,{onClose:()=>{ne(null),s4()},busRef:ns.busRef,protocolRef:ns.pmRef,connected:s7?nl(nr):tx})}),!sr&&"pair"===sc.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cG,{})}),"workspaces"===sc.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(eb,{onSelect:sj,onBrowse:sk,onBack:s4,isCodespaces:!!tq?.isCodespaces,systemInfo:sh})}),"browse"===sc.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cZ,{scope:tH,workspace:sc.path,fileBus:t7,onBack:s4,onSetWorkspace:sT,isBrowsing:!0})}),sr&&("files"===sc.type||"editor"===sc.type||"git"===sc.type)&&(T="files"===sc.type?sc:[...H].reverse().find(e=>"files"===e.type),R=T?.workspace||sc.workspace,E=ef(tH).find(e=>e.path===R),$="editor"===sc.type?sc.path:null,(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(dh,{workspace:R,fileBus:t7,onBack:s4,onSwitchWorkspace:sy,initialOpenedFiles:$?[$]:E?.openedFiles||[],initialActiveFile:$||E?.activeFile||null,onOpenedFilesChange:(e,t)=>(function(e,t,s,n=""){let r=(0,O.kb)(e),l=ef(n),a=l.findIndex(e=>e.path===r),i=Array.isArray(t)?t.map(e=>e&&"object"==typeof e?{...e,path:(0,O.kb)(e.path)}:e):t,o="string"==typeof s?(0,O.kb)(s):s;if(-1===a){l.unshift({path:r,lastOpened:Date.now(),openedFiles:i,activeFile:o}),localStorage.setItem(ex(n),JSON.stringify(l));return}l[a]={...l[a],openedFiles:i,activeFile:o??null},localStorage.setItem(ex(n),JSON.stringify(l))})(R,e,t,tH),bus:tr,connected:tx,sessions:tX,onCreateTerminalSession:sf.handleCreateSessionInline,onDeleteTerminalSession:sf.handleDeleteSession,onRenameTerminalSession:sf.handleRenameSession,viewType:sc.type,openFileRef:sv},R)})),!sr&&"files"===sc.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(cZ,{scope:tH,workspace:sc.workspace,initialPath:sc.currentPath,fileBus:t7,onBack:s4,onOpenFile:sC,onOpenGit:sS,onSwitchWorkspace:sy,onPathChange:e=>sN(sc.workspace,e),hideSwitchWorkspace:sc.fromTerminal})}),!sr&&"git"===sc.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-30 transition-all duration-300 ease-out",children:(0,n.jsx)(c3,{workspace:sc.workspace,fileBus:t7,onBack:s4,onOpenFile:sC})}),!sr&&sb&&(0,n.jsx)("div",{className:"absolute inset-0 z-40 transition-all duration-300 ease-out",children:(0,n.jsx)(c2,{filePath:sb.path,line:sb.line,column:sb.column,diffStatus:sb.diffStatus,preview:sb.preview,fileBus:t7,onBack:()=>{sb.artifactSessionId&&e2(sb.artifactSessionId,sb.path),sg(null)},workspace:sb.workspace||sc.workspace})}),(!tx||!tT)&&!t4&&!t5&&(0,n.jsx)(oA,{}),!t4&&(0,n.jsx)(dg,{retryStatus:tC,approvalStatus:tS,connected:tx,suppress:t1,firstConnect:!t3,onLogout:nd,onRetryNow:nc}),(0,n.jsx)(ui,{}),(0,n.jsx)(uo,{}),sH&&sq&&(0,n.jsx)(dp,{mode:"files",workspace:sq,fileBus:t7,onClose:()=>sU(!1),onOpenFile:e=>eB(e)}),(0,n.jsx)(db,{isOpen:sW,onClose:s_}),(0,n.jsx)(ec.A,{isOpen:t8.isOpen,onClose:nf,onConfirm:t8.onConfirm,title:t8.title,message:t8.message,confirmText:t8.confirmText})]}),(0,n.jsx)("div",{hidden:!0,children:(0,n.jsx)(r.Suspense,{fallback:null,children:e})}),(0,n.jsx)(eo,{})]})}},36416:(e,t,s)=>{Promise.resolve().then(s.bind(s,24317))},48310:(e,t,s)=>{"use strict";s.d(t,{w:()=>a});var n=s(1521),r=s(38415);let l="9remote_github_stars";function a(){let[e,t]=(0,n.useState)(null);return(0,n.useEffect)(()=>{try{let e=localStorage.getItem(l);if(e){let{count:s,timestamp:n}=JSON.parse(e);if("number"==typeof s&&t(s),Date.now()-n<36e5)return}}catch{}let e=!0;return fetch(r.O8).then(e=>e.ok?e.json():null).then(s=>{if(!e||"number"!=typeof s?.stargazers_count)return;let n=s.stargazers_count;t(n);try{localStorage.setItem(l,JSON.stringify({count:n,timestamp:Date.now()}))}catch{}}).catch(()=>{}),()=>{e=!1}},[]),{stars:e,formattedStars:null==e?"":e>=1e3?(e/1e3).toFixed(1).replace(/\.0$/,"")+"k":String(e)}}},59255:(e,t,s)=>{"use strict";s.d(t,{CV:()=>n,E4:()=>p,Is:()=>x,JN:()=>a,Ji:()=>m,KC:()=>i,Kd:()=>f,UH:()=>c,UP:()=>d,Yu:()=>u,od:()=>l,rl:()=>o,uI:()=>h});let n={bg:"var(--color-bg)",bgElevated:"var(--color-surface)",bgPanel:"var(--color-surface-2)",border:"var(--color-border)",borderStrong:"var(--color-border)",borderAccent:"color-mix(in srgb, var(--color-accent) 35%, transparent)",text:"var(--color-text)",textDim:"var(--color-text-muted)",textMuted:"var(--color-text-subtle)",accent:"var(--color-accent)",accentGlow:"color-mix(in srgb, var(--color-accent) 40%, transparent)",accentSoft:"color-mix(in srgb, var(--color-accent) 12%, transparent)",success:"var(--color-success)",warn:"#F59E0B",err:"var(--color-danger)"},r="https://github.com/decolua/9remote",l="https://apps.apple.com/us/app/9remote/id6796664210",a="https://play.google.com/store/apps/details?id=cc.remote9.app&pli=1",i="/download",o=r;function c(){if("u"<typeof navigator)return"other";let e=navigator.userAgent;return/iPhone|iPad|iPod/.test(e)?"other":/Mac/.test(e)?"macos":/Win/.test(e)?"windows":"other"}let d=[{id:"dmg",os:"macOS",short:"macOS",label:"Universal \xb7 Intel + Apple silicon",ext:".dmg",asset:"9Remote-macos-universal.dmg"},{id:"setup",os:"Windows",short:"Win setup",label:"Installer \xb7 x64",ext:".exe",asset:"9Remote-windows-x64-setup.exe"},{id:"portable",os:"Windows",short:"Win portable",label:"Portable \xb7 no install",ext:".exe",asset:"9Remote-windows-x64-portable.exe"}],u=[{tag:"v3.0.31",date:"2026-09-28"},{tag:"v3.0.3",date:"2026-09-21"},{tag:"v3.0.0",date:"2026-09-20"},{tag:"v3.5.9",date:"2026-09-15"}],x=(e,t)=>`${r}/releases/download/${e}/${t}`,m={tag:"v3.0.31",assets:{dmg:`${r}/releases/download/v3.0.31/9Remote-macos-universal.dmg`,setup:`${r}/releases/download/v3.0.31/9Remote-windows-x64-setup.exe`,portable:`${r}/releases/download/v3.0.31/9Remote-windows-x64-portable.exe`,debAmd64:`${r}/releases/download/v3.0.30/9Remote-linux-amd64.deb`,debArm64:`${r}/releases/download/v3.0.30/9Remote-linux-arm64.deb`,appImageArm64:`${r}/releases/download/v3.0.30/9Remote-linux-arm64.AppImage`}},p=e=>e.replace(/^v/,""),f=e=>[...e].sort((e,t)=>t.date.localeCompare(e.date)),h=[{role:"Host",title:"On your machine",desc:"Serves your terminals, screen and files."},{role:"Client",title:"With you anywhere",desc:"Same session on any screen — nothing to sync."}]}},e=>{e.O(0,[5595,6189,6391,8207,1050,3348,4136,8922,8762,5788,6552,2347,5158,7358],()=>e(e.s=36416)),_N_E=e.O()}]);