9remote 3.0.43 → 3.0.47

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 (280) hide show
  1. package/dist/cli.cjs +3 -3
  2. package/dist/server.cjs +254 -255
  3. package/dist/ui/assets/index-BNIwtLEB.js +8 -0
  4. package/dist/ui/assets/index-DvsANh5-.css +1 -0
  5. package/dist/ui/index.html +2 -2
  6. package/dist/web/404.html +1 -1
  7. package/dist/web/__next.__PAGE__.txt +2 -2
  8. package/dist/web/__next._full.txt +9 -9
  9. package/dist/web/__next._head.txt +1 -1
  10. package/dist/web/__next._index.txt +12 -10
  11. package/dist/web/__next._tree.txt +2 -2
  12. package/dist/web/_next/static/JqEpEzbDmfkGn0nekxxy5/_buildManifest.js +1 -0
  13. package/dist/web/_next/static/chunks/1772-46c2fa68cf486d14.js +1 -0
  14. package/dist/web/_next/static/chunks/1920-64e4610715fd991d.js +1 -0
  15. package/dist/web/_next/static/chunks/1968-90d80a8543ed4f21.js +32 -0
  16. package/dist/web/_next/static/chunks/556-1dec70a3f28ddbe8.js +1 -0
  17. package/dist/web/_next/static/chunks/5587-b8f18d331fdde617.js +1 -0
  18. package/dist/web/_next/static/chunks/6153.189180c190f90b2f.js +1 -0
  19. package/dist/web/_next/static/chunks/6221-2be9b41ee97fc1e6.js +11 -0
  20. package/dist/web/_next/static/chunks/7489.c1e8656da3738df7.js +1 -0
  21. package/dist/web/_next/static/chunks/8126-5be4c3eccbdb4c66.js +1 -0
  22. package/dist/web/_next/static/chunks/820-c1bd7547f2433453.js +1 -0
  23. package/dist/web/_next/static/chunks/8534.189180c190f90b2f.js +1 -0
  24. package/dist/web/_next/static/chunks/9121-cf1e65bb26b0908b.js +1 -0
  25. package/dist/web/_next/static/chunks/{9491-6dc334192080d071.js → 9491-970597f510e71615.js} +1 -1
  26. package/dist/web/_next/static/chunks/app/_global-error/page-e60883b219ccba1a.js +1 -0
  27. package/dist/web/_next/static/chunks/app/_not-found/page-bfa58c699e86fa7c.js +1 -0
  28. package/dist/web/_next/static/chunks/app/admin/access/page-79e70c584b6e2150.js +5 -0
  29. package/dist/web/_next/static/chunks/app/admin/login/page-4a768b6df8ed5259.js +1 -0
  30. package/dist/web/_next/static/chunks/app/admin/ota/page-e4d26a8db9968a98.js +5 -0
  31. package/dist/web/_next/static/chunks/app/admin/page-1c13a4c1567ed18e.js +5 -0
  32. package/dist/web/_next/static/chunks/app/admin/turn/page-dbd8be78d0941005.js +5 -0
  33. package/dist/web/_next/static/chunks/app/download/page-e27de0a4170f4b73.js +1 -0
  34. package/dist/web/_next/static/chunks/app/layout-a65a70a4500177c7.js +1 -0
  35. package/dist/web/_next/static/chunks/app/login/page-8216ac4904ee3551.js +1 -0
  36. package/dist/web/_next/static/chunks/app/{page-1e67d8a5f3775276.js → page-fde2c88f21078fca.js} +2 -2
  37. package/dist/web/_next/static/chunks/app/workspace/browse/page-e60883b219ccba1a.js +1 -0
  38. package/dist/web/_next/static/chunks/app/workspace/editor/page-e60883b219ccba1a.js +1 -0
  39. package/dist/web/_next/static/chunks/app/workspace/files/page-e60883b219ccba1a.js +1 -0
  40. package/dist/web/_next/static/chunks/app/workspace/git/page-e60883b219ccba1a.js +1 -0
  41. package/dist/web/_next/static/chunks/app/workspace/layout-75bbd11623918276.js +23 -0
  42. package/dist/web/_next/static/chunks/app/workspace/mobile/page-e60883b219ccba1a.js +1 -0
  43. package/dist/web/_next/static/chunks/app/workspace/page-e60883b219ccba1a.js +1 -0
  44. package/dist/web/_next/static/chunks/app/workspace/pair/page-e60883b219ccba1a.js +1 -0
  45. package/dist/web/_next/static/chunks/app/workspace/remote/page-e60883b219ccba1a.js +1 -0
  46. package/dist/web/_next/static/chunks/app/workspace/settings/page-e60883b219ccba1a.js +1 -0
  47. package/dist/web/_next/static/chunks/app/workspace/terminal/[sessionId]/page-e60883b219ccba1a.js +1 -0
  48. package/dist/web/_next/static/chunks/app/workspace/welcome/page-e60883b219ccba1a.js +1 -0
  49. package/dist/web/_next/static/chunks/app/workspace/workspaces/page-e60883b219ccba1a.js +1 -0
  50. package/dist/web/_next/static/chunks/main-72206f0a3cb91ecb.js +5 -0
  51. package/dist/web/_next/static/chunks/next/dist/client/components/builtin/app-error-e60883b219ccba1a.js +1 -0
  52. package/dist/web/_next/static/chunks/next/dist/client/components/builtin/forbidden-e60883b219ccba1a.js +1 -0
  53. package/dist/web/_next/static/chunks/next/dist/client/components/builtin/not-found-e60883b219ccba1a.js +1 -0
  54. package/dist/web/_next/static/chunks/next/dist/client/components/builtin/unauthorized-e60883b219ccba1a.js +1 -0
  55. package/dist/web/_next/static/chunks/{webpack-dd1f7a5ae02e5d84.js → webpack-31691f9bc04b8076.js} +1 -1
  56. package/dist/web/_next/static/css/10234b0587e8a07a.css +1 -0
  57. package/dist/web/_next/static/css/{adc0ee53b89bee3c.css → 2072cba9849e7093.css} +1 -1
  58. package/dist/web/_not-found/__next._full.txt +20 -22
  59. package/dist/web/_not-found/__next._head.txt +1 -1
  60. package/dist/web/_not-found/__next._index.txt +7 -7
  61. package/dist/web/_not-found/__next._not-found.__PAGE__.txt +1 -1
  62. package/dist/web/_not-found/__next._not-found.txt +1 -1
  63. package/dist/web/_not-found/__next._tree.txt +2 -2
  64. package/dist/web/_not-found.html +1 -1
  65. package/dist/web/_not-found.txt +20 -22
  66. package/dist/web/admin/__next._full.txt +9 -9
  67. package/dist/web/admin/__next._head.txt +1 -1
  68. package/dist/web/admin/__next._index.txt +12 -10
  69. package/dist/web/admin/__next._tree.txt +2 -2
  70. package/dist/web/admin/__next.admin.__PAGE__.txt +2 -2
  71. package/dist/web/admin/__next.admin.txt +1 -1
  72. package/dist/web/admin/access/__next._full.txt +9 -9
  73. package/dist/web/admin/access/__next._head.txt +1 -1
  74. package/dist/web/admin/access/__next._index.txt +12 -10
  75. package/dist/web/admin/access/__next._tree.txt +2 -2
  76. package/dist/web/admin/access/__next.admin.access.__PAGE__.txt +2 -2
  77. package/dist/web/admin/access/__next.admin.access.txt +1 -1
  78. package/dist/web/admin/access/__next.admin.txt +1 -1
  79. package/dist/web/admin/access.html +1 -1
  80. package/dist/web/admin/access.txt +9 -9
  81. package/dist/web/admin/login/__next._full.txt +9 -9
  82. package/dist/web/admin/login/__next._head.txt +1 -1
  83. package/dist/web/admin/login/__next._index.txt +12 -10
  84. package/dist/web/admin/login/__next._tree.txt +2 -2
  85. package/dist/web/admin/login/__next.admin.login.__PAGE__.txt +2 -2
  86. package/dist/web/admin/login/__next.admin.login.txt +1 -1
  87. package/dist/web/admin/login/__next.admin.txt +1 -1
  88. package/dist/web/admin/login.html +1 -1
  89. package/dist/web/admin/login.txt +9 -9
  90. package/dist/web/admin/ota/__next._full.txt +9 -9
  91. package/dist/web/admin/ota/__next._head.txt +1 -1
  92. package/dist/web/admin/ota/__next._index.txt +12 -10
  93. package/dist/web/admin/ota/__next._tree.txt +2 -2
  94. package/dist/web/admin/ota/__next.admin.ota.__PAGE__.txt +2 -2
  95. package/dist/web/admin/ota/__next.admin.ota.txt +1 -1
  96. package/dist/web/admin/ota/__next.admin.txt +1 -1
  97. package/dist/web/admin/ota.html +1 -1
  98. package/dist/web/admin/ota.txt +9 -9
  99. package/dist/web/admin/turn/__next._full.txt +9 -9
  100. package/dist/web/admin/turn/__next._head.txt +1 -1
  101. package/dist/web/admin/turn/__next._index.txt +12 -10
  102. package/dist/web/admin/turn/__next._tree.txt +2 -2
  103. package/dist/web/admin/turn/__next.admin.turn.__PAGE__.txt +2 -2
  104. package/dist/web/admin/turn/__next.admin.turn.txt +1 -1
  105. package/dist/web/admin/turn/__next.admin.txt +1 -1
  106. package/dist/web/admin/turn.html +1 -1
  107. package/dist/web/admin/turn.txt +9 -9
  108. package/dist/web/admin.html +1 -1
  109. package/dist/web/admin.txt +9 -9
  110. package/dist/web/download/__next._full.txt +9 -9
  111. package/dist/web/download/__next._head.txt +1 -1
  112. package/dist/web/download/__next._index.txt +12 -10
  113. package/dist/web/download/__next._tree.txt +2 -2
  114. package/dist/web/download/__next.download.__PAGE__.txt +2 -2
  115. package/dist/web/download/__next.download.txt +1 -1
  116. package/dist/web/download.html +1 -1
  117. package/dist/web/download.txt +9 -9
  118. package/dist/web/index.html +1 -1
  119. package/dist/web/index.txt +9 -9
  120. package/dist/web/login/__next._full.txt +9 -9
  121. package/dist/web/login/__next._head.txt +1 -1
  122. package/dist/web/login/__next._index.txt +12 -10
  123. package/dist/web/login/__next._tree.txt +2 -2
  124. package/dist/web/login/__next.login.__PAGE__.txt +2 -2
  125. package/dist/web/login/__next.login.txt +1 -1
  126. package/dist/web/login.html +1 -1
  127. package/dist/web/login.txt +9 -9
  128. package/dist/web/workspace/__next._full.txt +11 -11
  129. package/dist/web/workspace/__next._head.txt +1 -1
  130. package/dist/web/workspace/__next._index.txt +12 -10
  131. package/dist/web/workspace/__next._tree.txt +3 -3
  132. package/dist/web/workspace/__next.workspace.__PAGE__.txt +1 -1
  133. package/dist/web/workspace/__next.workspace.txt +3 -3
  134. package/dist/web/workspace/browse/__next._full.txt +11 -11
  135. package/dist/web/workspace/browse/__next._head.txt +1 -1
  136. package/dist/web/workspace/browse/__next._index.txt +12 -10
  137. package/dist/web/workspace/browse/__next._tree.txt +3 -3
  138. package/dist/web/workspace/browse/__next.workspace.browse.__PAGE__.txt +1 -1
  139. package/dist/web/workspace/browse/__next.workspace.browse.txt +1 -1
  140. package/dist/web/workspace/browse/__next.workspace.txt +3 -3
  141. package/dist/web/workspace/browse.html +1 -1
  142. package/dist/web/workspace/browse.txt +11 -11
  143. package/dist/web/workspace/editor/__next._full.txt +11 -11
  144. package/dist/web/workspace/editor/__next._head.txt +1 -1
  145. package/dist/web/workspace/editor/__next._index.txt +12 -10
  146. package/dist/web/workspace/editor/__next._tree.txt +3 -3
  147. package/dist/web/workspace/editor/__next.workspace.editor.__PAGE__.txt +1 -1
  148. package/dist/web/workspace/editor/__next.workspace.editor.txt +1 -1
  149. package/dist/web/workspace/editor/__next.workspace.txt +3 -3
  150. package/dist/web/workspace/editor.html +1 -1
  151. package/dist/web/workspace/editor.txt +11 -11
  152. package/dist/web/workspace/files/__next._full.txt +11 -11
  153. package/dist/web/workspace/files/__next._head.txt +1 -1
  154. package/dist/web/workspace/files/__next._index.txt +12 -10
  155. package/dist/web/workspace/files/__next._tree.txt +3 -3
  156. package/dist/web/workspace/files/__next.workspace.files.__PAGE__.txt +1 -1
  157. package/dist/web/workspace/files/__next.workspace.files.txt +1 -1
  158. package/dist/web/workspace/files/__next.workspace.txt +3 -3
  159. package/dist/web/workspace/files.html +1 -1
  160. package/dist/web/workspace/files.txt +11 -11
  161. package/dist/web/workspace/git/__next._full.txt +11 -11
  162. package/dist/web/workspace/git/__next._head.txt +1 -1
  163. package/dist/web/workspace/git/__next._index.txt +12 -10
  164. package/dist/web/workspace/git/__next._tree.txt +3 -3
  165. package/dist/web/workspace/git/__next.workspace.git.__PAGE__.txt +1 -1
  166. package/dist/web/workspace/git/__next.workspace.git.txt +1 -1
  167. package/dist/web/workspace/git/__next.workspace.txt +3 -3
  168. package/dist/web/workspace/git.html +1 -1
  169. package/dist/web/workspace/git.txt +11 -11
  170. package/dist/web/workspace/mobile/__next._full.txt +11 -11
  171. package/dist/web/workspace/mobile/__next._head.txt +1 -1
  172. package/dist/web/workspace/mobile/__next._index.txt +12 -10
  173. package/dist/web/workspace/mobile/__next._tree.txt +3 -3
  174. package/dist/web/workspace/mobile/__next.workspace.mobile.__PAGE__.txt +1 -1
  175. package/dist/web/workspace/mobile/__next.workspace.mobile.txt +1 -1
  176. package/dist/web/workspace/mobile/__next.workspace.txt +3 -3
  177. package/dist/web/workspace/mobile.html +1 -1
  178. package/dist/web/workspace/mobile.txt +11 -11
  179. package/dist/web/workspace/pair/__next._full.txt +11 -11
  180. package/dist/web/workspace/pair/__next._head.txt +1 -1
  181. package/dist/web/workspace/pair/__next._index.txt +12 -10
  182. package/dist/web/workspace/pair/__next._tree.txt +3 -3
  183. package/dist/web/workspace/pair/__next.workspace.pair.__PAGE__.txt +1 -1
  184. package/dist/web/workspace/pair/__next.workspace.pair.txt +1 -1
  185. package/dist/web/workspace/pair/__next.workspace.txt +3 -3
  186. package/dist/web/workspace/pair.html +1 -1
  187. package/dist/web/workspace/pair.txt +11 -11
  188. package/dist/web/workspace/remote/__next._full.txt +11 -11
  189. package/dist/web/workspace/remote/__next._head.txt +1 -1
  190. package/dist/web/workspace/remote/__next._index.txt +12 -10
  191. package/dist/web/workspace/remote/__next._tree.txt +3 -3
  192. package/dist/web/workspace/remote/__next.workspace.remote.__PAGE__.txt +1 -1
  193. package/dist/web/workspace/remote/__next.workspace.remote.txt +1 -1
  194. package/dist/web/workspace/remote/__next.workspace.txt +3 -3
  195. package/dist/web/workspace/remote.html +1 -1
  196. package/dist/web/workspace/remote.txt +11 -11
  197. package/dist/web/workspace/settings/__next._full.txt +37 -0
  198. package/dist/web/workspace/settings/__next._head.txt +6 -0
  199. package/dist/web/workspace/settings/__next._index.txt +17 -0
  200. package/dist/web/workspace/settings/__next._tree.txt +7 -0
  201. package/dist/web/workspace/settings/__next.workspace.settings.__PAGE__.txt +5 -0
  202. package/dist/web/workspace/settings/__next.workspace.settings.txt +5 -0
  203. package/dist/web/workspace/settings/__next.workspace.txt +8 -0
  204. package/dist/web/workspace/settings.html +1 -0
  205. package/dist/web/workspace/settings.txt +37 -0
  206. package/dist/web/workspace/terminal/default/__next._full.txt +11 -11
  207. package/dist/web/workspace/terminal/default/__next._head.txt +1 -1
  208. package/dist/web/workspace/terminal/default/__next._index.txt +12 -10
  209. package/dist/web/workspace/terminal/default/__next._tree.txt +3 -3
  210. package/dist/web/workspace/terminal/default/__next.workspace.terminal.$d$sessionId.__PAGE__.txt +1 -1
  211. package/dist/web/workspace/terminal/default/__next.workspace.terminal.$d$sessionId.txt +1 -1
  212. package/dist/web/workspace/terminal/default/__next.workspace.terminal.txt +1 -1
  213. package/dist/web/workspace/terminal/default/__next.workspace.txt +3 -3
  214. package/dist/web/workspace/terminal/default.html +1 -1
  215. package/dist/web/workspace/terminal/default.txt +11 -11
  216. package/dist/web/workspace/welcome/__next._full.txt +11 -11
  217. package/dist/web/workspace/welcome/__next._head.txt +1 -1
  218. package/dist/web/workspace/welcome/__next._index.txt +12 -10
  219. package/dist/web/workspace/welcome/__next._tree.txt +3 -3
  220. package/dist/web/workspace/welcome/__next.workspace.txt +3 -3
  221. package/dist/web/workspace/welcome/__next.workspace.welcome.__PAGE__.txt +1 -1
  222. package/dist/web/workspace/welcome/__next.workspace.welcome.txt +1 -1
  223. package/dist/web/workspace/welcome.html +1 -1
  224. package/dist/web/workspace/welcome.txt +11 -11
  225. package/dist/web/workspace/workspaces/__next._full.txt +11 -11
  226. package/dist/web/workspace/workspaces/__next._head.txt +1 -1
  227. package/dist/web/workspace/workspaces/__next._index.txt +12 -10
  228. package/dist/web/workspace/workspaces/__next._tree.txt +3 -3
  229. package/dist/web/workspace/workspaces/__next.workspace.txt +3 -3
  230. package/dist/web/workspace/workspaces/__next.workspace.workspaces.__PAGE__.txt +1 -1
  231. package/dist/web/workspace/workspaces/__next.workspace.workspaces.txt +1 -1
  232. package/dist/web/workspace/workspaces.html +1 -1
  233. package/dist/web/workspace/workspaces.txt +11 -11
  234. package/dist/web/workspace.html +1 -1
  235. package/dist/web/workspace.txt +11 -11
  236. package/package.json +1 -1
  237. package/dist/ui/assets/index-DQvkcQ8W.js +0 -8
  238. package/dist/ui/assets/index-SHlsPzjb.css +0 -1
  239. package/dist/web/_next/static/AhLhl9t958vI0woNHnp3P/_buildManifest.js +0 -1
  240. package/dist/web/_next/static/chunks/1772-ef73c166e83f5eff.js +0 -1
  241. package/dist/web/_next/static/chunks/1920-5ead25286846df83.js +0 -1
  242. package/dist/web/_next/static/chunks/1968-4d2969f0b7112e0b.js +0 -32
  243. package/dist/web/_next/static/chunks/556-a8f04c41c5663ee8.js +0 -1
  244. package/dist/web/_next/static/chunks/5587-fc5af8c76df14222.js +0 -1
  245. package/dist/web/_next/static/chunks/6153.8c6b8930e22ceea0.js +0 -1
  246. package/dist/web/_next/static/chunks/6221-cf883148bf8a4c1e.js +0 -11
  247. package/dist/web/_next/static/chunks/7489.24938d89538cd03e.js +0 -1
  248. package/dist/web/_next/static/chunks/8126-8e53bfff5a06af4e.js +0 -1
  249. package/dist/web/_next/static/chunks/820-99036fb63c5462c8.js +0 -1
  250. package/dist/web/_next/static/chunks/8534.8c6b8930e22ceea0.js +0 -1
  251. package/dist/web/_next/static/chunks/9121-897f98b646fc2ac0.js +0 -1
  252. package/dist/web/_next/static/chunks/app/_global-error/page-2ece09c883187d82.js +0 -1
  253. package/dist/web/_next/static/chunks/app/_not-found/page-9f829d2c4beb1840.js +0 -1
  254. package/dist/web/_next/static/chunks/app/admin/access/page-45f45ad529e5b691.js +0 -5
  255. package/dist/web/_next/static/chunks/app/admin/login/page-382072b5b43d3c29.js +0 -1
  256. package/dist/web/_next/static/chunks/app/admin/ota/page-293c0743bd60f454.js +0 -5
  257. package/dist/web/_next/static/chunks/app/admin/page-fc676dae451dd646.js +0 -5
  258. package/dist/web/_next/static/chunks/app/admin/turn/page-2ab33033fc7f0919.js +0 -5
  259. package/dist/web/_next/static/chunks/app/download/page-a65d1c7fcf6397af.js +0 -1
  260. package/dist/web/_next/static/chunks/app/layout-f1429d22e935695f.js +0 -1
  261. package/dist/web/_next/static/chunks/app/login/page-a5dd37d1cbbb394e.js +0 -1
  262. package/dist/web/_next/static/chunks/app/workspace/browse/page-2ece09c883187d82.js +0 -1
  263. package/dist/web/_next/static/chunks/app/workspace/editor/page-2ece09c883187d82.js +0 -1
  264. package/dist/web/_next/static/chunks/app/workspace/files/page-2ece09c883187d82.js +0 -1
  265. package/dist/web/_next/static/chunks/app/workspace/git/page-2ece09c883187d82.js +0 -1
  266. package/dist/web/_next/static/chunks/app/workspace/layout-336820247249f65c.js +0 -20
  267. package/dist/web/_next/static/chunks/app/workspace/mobile/page-2ece09c883187d82.js +0 -1
  268. package/dist/web/_next/static/chunks/app/workspace/page-2ece09c883187d82.js +0 -1
  269. package/dist/web/_next/static/chunks/app/workspace/pair/page-2ece09c883187d82.js +0 -1
  270. package/dist/web/_next/static/chunks/app/workspace/remote/page-2ece09c883187d82.js +0 -1
  271. package/dist/web/_next/static/chunks/app/workspace/terminal/[sessionId]/page-2ece09c883187d82.js +0 -1
  272. package/dist/web/_next/static/chunks/app/workspace/welcome/page-2ece09c883187d82.js +0 -1
  273. package/dist/web/_next/static/chunks/app/workspace/workspaces/page-2ece09c883187d82.js +0 -1
  274. package/dist/web/_next/static/chunks/main-e10b0dbebb4de0a8.js +0 -5
  275. package/dist/web/_next/static/chunks/next/dist/client/components/builtin/app-error-2ece09c883187d82.js +0 -1
  276. package/dist/web/_next/static/chunks/next/dist/client/components/builtin/forbidden-2ece09c883187d82.js +0 -1
  277. package/dist/web/_next/static/chunks/next/dist/client/components/builtin/not-found-2ece09c883187d82.js +0 -1
  278. package/dist/web/_next/static/chunks/next/dist/client/components/builtin/unauthorized-2ece09c883187d82.js +0 -1
  279. package/dist/web/_next/static/css/7b03063e80720027.css +0 -1
  280. /package/dist/web/_next/static/{AhLhl9t958vI0woNHnp3P → JqEpEzbDmfkGn0nekxxy5}/_ssgManifest.js +0 -0
@@ -0,0 +1,23 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1807],{63455:()=>{},71049:(e,t,s)=>{"use strict";s.d(t,{CV:()=>n,E4:()=>p,Is:()=>m,JN:()=>a,Ji:()=>x,KC:()=>i,Kd:()=>h,UH:()=>c,UP:()=>d,Yu:()=>u,od:()=>l,rl:()=>o,uI:()=>f});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"}],m=(e,t)=>`${r}/releases/download/${e}/${t}`,x={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/,""),h=e=>[...e].sort((e,t)=>t.date.localeCompare(e.date)),f=[{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."}]},71632:(e,t,s)=>{"use strict";s.d(t,{w:()=>a});var n=s(7620),r=s(92673);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)}}},77442:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>xt});var n=s(54568),r=s(7620),l=s(79748),a=s(189);let i="9remote_deviceId";var o=s(42126),c=s(30068),d=s(55285),u=s(89228),m=s(96631),x=s(30562),p=s(69469),h=s(99022),f=s(23635),b=s(94245);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(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3e3,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(8454).then(s.bind(s,27938)),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 E(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 R(e,t,s){let n,r,l=E(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 M=(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 $(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 z=(0,b.v)((e,t)=>({enabled:!0,mode:"browser",preset:"gemini",geminiKeys:[],geminiModel:"",openrouterKey:"",openrouterModel:"",customEndpoint:"",customModel:"",customKey:"",opencodeModel:"",setEnabled:s=>{t().enabled!==s&&(M("enabled",s),e({enabled:s}),$(t()))},setMode:s=>{t().mode!==s&&(M("mode",s),e({mode:s}),$(t()))},setPreset:s=>{t().preset!==s&&(M("preset",s),e({preset:s}),$(t()))},setField:(s,n)=>{t()[s]!==n&&(M(s,n),e({[s]:n}),$(t()))},setEngine:(s,n)=>{let r=t();(r.mode!==s||r.preset!==n)&&(M("mode",s),M("preset",n),e({mode:s,preset:n}),$(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,M(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 m="string"==typeof t.customEndpoint?t.customEndpoint.trim():"";for(let s of(m&&!e.customEndpoint?.trim()&&r(!0,"customEndpoint",m),["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:()=>$(t()),pushToAgent:()=>$(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",M("preset",t.preset),r&&"custom"!==t.preset&&(t[`${t.preset}Model`]=r),t.geminiModel&&M("geminiModel",t.geminiModel),t.openrouterModel&&M("openrouterModel",t.openrouterModel),t.geminiKeys.length&&M("geminiKeys",t.geminiKeys),t.openrouterKey&&M("openrouterKey",t.openrouterKey),t.customEndpoint&&M("customEndpoint",t.customEndpoint),t.customModel&&M("customModel",t.customModel),t.customKey&&M("customKey",t.customKey)}z.setState(t)}catch{}var P=s(81353),A=s(81851),I=s(59506),D=s(18753),L=s(6134);let B=e=>{let t=P.rh.getState();t._patchHost(t.currentKey,e)};var F=s(35049);let O=(0,b.v)(e=>({isKeyboardOpen:!1,setKeyboardOpen:t=>{e({isKeyboardOpen:t}),"u">typeof document&&document.body.classList.toggle("keyboard-open",t)}}));var _=s(92571);function K(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 W={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",q=["V","D","I","W","E","F"],U={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 G{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 J(e){let{bus:t,protocolRef:s,targetDir:n,items:r,callbacks:l}=e,{onConflict:a,onProgress:i,onFileDone:o,onError:c}=l||{},d=new G;for(let{file:e,relativePath:l}of r)try{let r=await Y(t,s,n,e,l,d,a,i);o?.(e,r.status)}catch(t){c?.(e,t)}}async function Y(e,t,s,n,r,l,a,i){var o,c,d,u,m;let x=await X(e,"upload:start",{targetDir:s,relativePath:r,size:n.size,mtime:n.lastModified||0});if(!x.success)throw Error(x.error);let{uploadId:p,exists:h}=x;if(h){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,m=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,x=0,p=0,h=!1,f=e=>{let{uploadId:t,offset:s}=e;t===d&&(s>p&&(p=s,m?.(u,n?p/n:1)),p>=n&&!h?(h=!0,o.emit("upload:end",{uploadId:d})):w())},b=e=>{let{uploadId:s,error:n}=e;s===d&&(v(),t(Error(n)))},g=t=>{let{uploadId:s}=t;s===d&&(v(),e())};function v(){o.off("upload:ack",f),o.off("upload:error",b),o.off("upload:done",g)}o.on("upload:ack",f),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&&x-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++,x=e.offset+e.length}if(p>=n&&!h){h=!0,o.emit("upload:end",{uploadId:d});return}i<a.length&&x-p<l&&setTimeout(w,50)}w()})),{status:"done"}}let Z=e=>t=>{e((0,_.RV)(t))};function Q(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:()=>null,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;return{getSystemInfo:()=>new Promise(t=>{let s=e();if(!s)return t({success:!1,error:"Not connected"});s.emit("getSystemInfo",t)}),getFiles:function(t){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return 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:function(t){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(n=>{let r=e();if(!r)return n({success:!1,error:"Not connected"});r.emit("readMedia",{filePath:t,maxDim:s.maxDim},n)})},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:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"HEAD";return 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:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return 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:function(t,s,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[];return 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:function(t){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return 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:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return 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:function(t){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:50;return 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?J({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(e){let{bus:t,protocolRef:s,filePath:n,onSave:r,onProgress:l,onError:a}=e,i=null,o=null,c=null,d=null,u=null,m=e=>{let t;try{t=K(e)}catch{return}t.uploadId===i&&(u.set(t.offset,t.payload),d&&(d.mark(t.offset,t.payload.byteLength),l&&o&&l(d.watermark/o)))},x=e=>{let{downloadId:t}=e;if(t===i&&(!d||d.isComplete())){let e;h(),e=[...u.entries()].sort((e,t)=>e[0]-t[0]).map(e=>{let[,t]=e;return t}),r?.(new Blob(e),{size:o,fileName:c})}},p=e=>{let{downloadId:t,error:s}=e;t===i&&(h(),a?.(Error(s)))};function h(){t.off("file-bin",m),t.off("download:done",x),t.off("download:error",p)}X(t,"download:start",{filePath:n}).then(e=>{e.success?(i=e.downloadId,o=e.size,c=e.fileName,d=null!=o?new V(o):null,u=new Map,t.on("file-bin",m),t.on("download:done",x),t.on("download:error",p)):a?.(Error(e.error))}).catch(e=>a?.(e))}({bus:r,protocolRef:t(),filePath:s,...n}):(n?.onError?.(Error("Not connected")),Promise.resolve())},streamMedia:(t,s)=>{let n=e();return n?function(e){let{bus:t,filePath:s,onMeta:n,onChunk:r,onDone:l,onError:a}=e,i=null,o=new Map,c=0,d=()=>{for(;o.has(c);){let e=o.get(c);o.delete(c),r?.(e),c+=e.byteLength}},u=e=>{let t;if(null!=i){try{t=K(e)}catch{return}t.uploadId===i&&(o.set(t.offset,t.payload),d())}},m=e=>{let{downloadId:t}=e;t===i&&(p(),l?.())},x=e=>{let{downloadId:t,error:s}=e;t===i&&(p(),a?.(Error(s)))};function p(){t.off("file-bin",u),t.off("download:done",m),t.off("download:error",x)}return t.on("file-bin",u),t.on("download:done",m),t.on("download:error",x),X(t,"streamMedia:start",{filePath:s}).then(e=>{if(!e.success){p(),a?.(Error(e.error));return}i=e.streamId,n?.({mime:e.mime,size:e.size,width:e.width,height:e.height,scaled:e.scaled,originalWidth:e.originalWidth,originalHeight:e.originalHeight}),d()}).catch(e=>{p(),a?.(e)}),()=>{p(),null!=i&&t.emit("download:cancel",{downloadId:i})}}({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(96605);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,m]=(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}}),x=(0,r.useRef)({dragging:!1,startX:0,startY:0,origX:0,origY:0,moved:!1}),p=e=>{let s=x.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=()=>{x.current.dragging&&(x.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 h=o?s.filter(e=>e.category.includes(o)||e.msg.includes(o)):s,f=async()=>{let e=h.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=>{x.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=x.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;m({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:["(",h.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:f,className:"p-1 text-text-muted hover:text-text",title:`Copy ${h.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===h.length?(0,n.jsx)("p",{className:"text-text-muted text-center py-4",children:"No logs yet"}):h.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(23084),ed=s(14652),eu=s(9121);let em=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return`recentWorkspaces${e}`},ex=_.cv,ep=e=>{if(!e)return e;let t={...e};return"string"==typeof t.path&&(t.path=(0,_.kb)(t.path)),"string"==typeof t.lastPath&&(t.lastPath=(0,_.kb)(t.lastPath)),Array.isArray(t.openedFiles)&&(t.openedFiles=t.openedFiles.map(e=>e&&"object"==typeof e?{...e,path:(0,_.kb)(e.path)}:e)),"string"==typeof t.activeFile&&(t.activeFile=(0,_.kb)(t.activeFile)),t};function eh(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";try{return JSON.parse(localStorage.getItem(em(e))||"[]").map(ep)}catch{return[]}}function ef(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",s=(0,_.kb)(e),n=eh(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,ex);localStorage.setItem(em(t),JSON.stringify([...a,...i]))}function eb(e){let{onSelect:t,onBrowse:s,onBack:l,isCodespaces:a,systemInfo:i}=e,{t:o}=(0,eu.s)(),[c,d]=(0,r.useState)([]),[u,m]=(0,r.useState)({isOpen:!1,path:null,name:""});return(0,r.useEffect)(()=>{d(eh())},[]),(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)(),l()},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:o("files.selectWorkspace")})]}),(0,n.jsxs)("div",{className:"flex-1 p-4 overflow-auto modal-scrollable",children:[c.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:o("files.recentWorkspaces")}),(0,n.jsx)("div",{className:"space-y-2",children:c.map(e=>{var s;let r,l,a,i,c;return(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.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=e.path).split("/").pop()||r}),(0,n.jsx)("div",{className:"text-text-muted text-sm truncate",title:e.path,children:e.path.replace(/^\/Users\/[^/]+/,"~")}),(0,n.jsx)("div",{className:"text-text-muted text-xs mt-1",children:(s=e.lastOpened,a=Math.floor((l=Date.now()-s)/6e4),i=Math.floor(l/36e5),c=Math.floor(l/864e5),a<60?o("common.minutesAgo",{n:a}):i<24?o("common.hoursAgo",{n:i}):o("common.daysAgo",{n:c}))})]}),(0,n.jsx)("div",{onClick:t=>{(0,ed.e)(),t.stopPropagation(),m({isOpen:!0,path:e.path,name:e.path.split("/").pop()||e.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:o("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"})})]},e.path)})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-text-muted text-sm font-medium mb-3",children:o("files.selectWorkspace")}),(0,n.jsxs)("div",{className:"space-y-2",children:[i?.isWindows?(0,n.jsx)(n.Fragment,{children:i.drives?.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s(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:o("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)(),s("~")},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:o("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)(),s("/")},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:o("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"})})]})]}),a&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s("/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:o("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:u.isOpen,onClose:()=>m({isOpen:!1,path:null,name:""}),onConfirm:()=>{u.path&&(!function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",s=(0,_.kb)(e),n=eh(t).filter(e=>e.path!==s);localStorage.setItem(em(t),JSON.stringify(n))}(u.path),d(eh())),m({isOpen:!1,path:null,name:""})},title:o("files.removeTitle"),message:o("files.removeMessage",{name:u.name})})]})}var eg=s(36487);let ev=(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},ey=(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:function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"menu";e({isOpen:!0,activePanel:t}),window.innerWidth>=eg.jK||f.B.getState().selectTab({type:"settings"})},close:()=>{e({isOpen:!1,activePanel:"menu"});let{viewStack:t,selectTab:s}=f.B.getState();t[t.length-1]?.type==="settings"&&s({type:"list"})},setActivePanel:t=>e({activePanel:t}),setContext:t=>e(e=>{let s={...e.context,...t},n=!1;for(let t of Object.keys(s))if(!ev(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:()=>t().open("pwa"),openMenu:()=>t().open("menu")}));f.B.subscribe((e,t)=>{let s=e=>e[e.length-1]?.type==="settings",n=s(e.viewStack);n!==s(t.viewStack)&&ey.setState(n?{isOpen:!0}:{isOpen:!1,activePanel:"menu"})});let ew=(e,t)=>{let{[t]:s,...n}=e;return n},ej=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},ek=(0,b.v)((e,t)=>({notifications:{},handleStatusChange:function(){let{sessionId:t,state:s,tool:n,since:r}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};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:ej(t)?.tool,timestamp:r};(0,I.dI)(e.notifications[t],l)||(a={...e.notifications,[t]:l})}else t in e.notifications&&(a=ew(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=ej(s)?.state;if("blocked"===n||!t().notifications[s]&&"done"!==n)return;e(e=>({notifications:s in e.notifications?ew(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:{}})})),eN=(e,t)=>`${e}:${t}`,eC=e=>e?`@${e}`:"",eS=(e,t)=>"string"==typeof e&&e.startsWith(`${t}:`)?e.slice(t.length+1):null;function eT(e,t){let s=t||"main";return e.some(e=>e.key===s)?e:[{key:"main"},...e]}class eE{constructor(e){this.head=e||null,this._busRef={current:null},this._pmRef={current:null}}get scope(){return eC(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 eM(e){if(e&&e===P.rh.getState().currentKey)return eM(null);let t=e||"",s=eR.get(t);return s||(s=new eE(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 eM(s.key)}return eM(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"}let eP={},eA=[];function eI(){let e=(0,P.rh)((0,F.k)(e=>Object.values(e.hosts).map(e=>e.statusMap)));return(0,r.useMemo)(()=>{let t={};for(let s of e)Object.assign(t,s||eP);return t},[e])}function eD(){let e=(0,P.rh)((0,F.k)(e=>Object.values(e.hosts).map(e=>e.sessions)));return(0,r.useMemo)(()=>{let t=new Set;for(let s of e)for(let e of s||eA)t.add(e.id);return t},[e])}let eL={working:0,blocked:1,done:2,idle:3};function eB(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];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=>{let[t,s]=e;return{id:t,...s}})).sort((e,t)=>{let s=(eL[e.state]??9)-(eL[t.state]??9);return 0!==s?s:(t.since||0)-(e.since||0)})}function eF(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],s=eB(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 eO="9remote:push:userDisabled",e_="9Remote",eK="9Remote • ",eW=null,eH=0,eq=0,eU=null,eX=null;function eV(){!eX&&"u">typeof MutationObserver&&(eX=new MutationObserver(()=>{eU&&document.title!==eU&&eG(eU)})).observe(document.head,{childList:!0,subtree:!0,characterData:!0})}function eG(e){eU=e;let t=eX;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 eJ(){let e=eK.slice(eH)+eK.slice(0,eH);eG(`(${eq}) 🔔 ${e}`),eH=(eH+1)%eK.length}function eY(e,t){eq=e,e>0?(eV(),eW||(eH=0,eJ(),eW=setInterval(eJ,400))):(eW&&(clearInterval(eW),eW=null),eH=0,t?(eV(),eG(`${t} • ${e_}`)):(eX&&(eX.disconnect(),eX=null),eU=null,document.title=e_))}function eZ(e,t){let{startWidth:s,axis:n=1,onWidth:r,onEnd:l}=t;e.preventDefault();let a=e.clientX,i=a,o=null,c=()=>{o=null,r((e=>{let{startWidth:t,startX:s,x:n,axis:r=1}=e;return t+r*(n-s)})({startWidth:s,startX:a,x:i,axis:n}))},d=e=>{0===e.buttons?u():(i=e.clientX,null===o&&(o=requestAnimationFrame(c)))},u=()=>{document.removeEventListener("pointermove",d),document.removeEventListener("pointerup",u),document.removeEventListener("pointercancel",u),window.removeEventListener("blur",u),document.body.style.cursor="",document.body.style.userSelect="",null!==o&&(cancelAnimationFrame(o),c()),l?.()};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("pointermove",d),document.addEventListener("pointerup",u),document.addEventListener("pointercancel",u),window.addEventListener("blur",u)}let eQ=null,e0=(0,b.v)((e,t)=>({canInstall:!1,isInstalled:!1,setDeferredPrompt:t=>{eQ=t,e({canInstall:!!t})},setIsInstalled:t=>e({isInstalled:t}),install:async()=>{if(!eQ)return null;eQ.prompt();let t=await eQ.userChoice;return eQ=null,e({canInstall:!1}),t?.outcome??null}})),e1=!1,e2=e=>"function"==typeof getComputedStyle?getComputedStyle(e).overflowX:"";var e5=s(72627),e3=s(31856);let e4=new Set(["codex","aider","pi","omp"]),e6="rounded-[3px] pointer-events-none select-none";function e8(e){if(!e||"null"===e||"undefined"===e)return null;let t=e.replace(/-ui$/,"");return`/agent-icons/${t}.${e4.has(t)?"svg":"png"}`}function e9(e){return!!(e?.yolo||e?.yoloEnv)}function e7(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[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=>{let[t,s]=e;return`${t}=${s}`}).join(" ");return`${t} ${e.cmd}`}return e.cmd}function te(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=>{let[t,s]=e;return`${t}=${s}`}).join(" ");return`${s} ${t}`}return t}let tt="9remote.terminal.shellPref",ts="9remote.terminal.agentPref",tn="9remote.terminal.yoloPref2";function tr(e){try{return localStorage.getItem(e)||null}catch{return null}}function tl(e,t){try{localStorage.setItem(e,t)}catch{}}function ta(){return{agentId:tr(ts)||"",shellId:tr(tt),yolo:"0"!==tr(tn)}}function ti(e){let{onSelectSession:t=null,onSelectWorkspace:s=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},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,e3.x$)(e.full||e.key),s?.(t??"_");return}catch{}s?.(eN(e.key,t??"_"))},createSession:(s,n,l,a,i,o,c,d)=>{let u="string"==typeof i?null:i,m="string"==typeof i?i:i?.id||null,x=e7(u,o);(0,P.Nw)(e.key,i=>i.emit("createSession",{name:s,shellId:l,workspaceId:n,cwd:a,nameIsAuto:c,agent:m},i=>{i?.success&&i.sessionId&&(x&&f.B.getState().queueStartup(i.sessionId,x),m&&f.B.getState().setSessionAgent(i.sessionId,m),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:m}]),t?.(i.sessionId,eN(e.key,n??"_"))),d?.(i)}))},createWorkspace:function(t){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]: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},()=>{})}}}var to=s(30368);let tc=[{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+/"}],td={id:"sessionIndex",label:"Go to terminal 1–9",mac:"⌥1…9",pc:"Ctrl+Shift+1…9"},tu=[{id:"switchTerminal",label:"Switch terminal",mac:"⌥← / →",pc:"Ctrl+Shift+← / →"},td,{id:"switchWorkspace",label:"Switch workspace",mac:"⌥↑ / ↓",pc:"Ctrl+Shift+↑ / ↓"},tc.find(e=>"newTerminal"===e.id),tc.find(e=>"closeTerminal"===e.id),tc.find(e=>"fitPanes"===e.id),tc.find(e=>"toggleFocus"===e.id),tc.find(e=>"toggleSidebar"===e.id),tc.find(e=>"toggleRightPanel"===e.id),tc.find(e=>"palette"===e.id),tc.find(e=>"help"===e.id)].filter(Boolean),tm=/^Digit([1-9])$/,tx=null,tp=()=>{if(null!==tx)return tx;if("u"<typeof navigator)return!1;let e=navigator.userAgentData?.platform;if(e)return tx="macOS"===e;let t=navigator.userAgent||"",s=navigator.platform||"";return tx=/Macintosh|Mac OS X|MacIntel/i.test(t+" "+s)&&!/iPhone|iPod/.test(t)},th=e=>tp()?e.mac:e.pc,tf="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",tb=new Set(["⌘","⌥","⇧","⌃"]);function tg(e){let t=th(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&&tb.has(n[r]);)s.push(n[r]),r++;return r<n.length&&s.push(n.slice(r)),s}let tv=e=>!!e&&"function"==typeof e.closest&&!!(e.closest("[role=dialog]")||e.closest(".modal-overlay")||e.closest(".card-elev")),ty=e=>!(!e||"function"!=typeof e.closest||e.closest(".xterm"))&&(e.isContentEditable||"INPUT"===e.tagName||"TEXTAREA"===e.tagName);function tw(e,t){let s=tc.find(e=>e.id===t);return s?`${e} \xb7 ${th(s)}`:e}let tj=(0,b.v)(e=>({isOpen:!1,open:()=>e({isOpen:!0}),close:()=>e({isOpen:!1}),toggle:()=>e(e=>({isOpen:!e.isOpen}))}));function tk(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"main",s=t&&"main"!==t?t:P.rh.getState().currentKey||"main",n=(0,f.B)(e=>e.agentClisBy[s]?.list),l=(0,P.rh)(e=>e.hosts[s]?.status||null);return(0,r.useEffect)(()=>{let t=f.B.getState().agentClisBy[s];t&&Date.now()-t.at<eg.OM||e?.current?.emit("getAgentClis",e=>{let t=Array.isArray(e?.agents)?e.agents:Array.isArray(e)?e:null;t&&f.B.getState().setAgentClis(s,t)})},[e,s,l]),n}let tN=Object.freeze({Bash:"bash",BashOutput:"bash",KillShell:"bash",Monitor:"bash",Edit:"diff",Write:"diff",MultiEdit:"diff",NotebookEdit:"diff",Read:"file",NotebookRead:"file",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",TodoWrite:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",update_plan:"plan",enteredReviewMode:"review",exitedReviewMode:"review",EnteredReviewMode:"review",ExitedReviewMode:"review",AskUserQuestion:"question",Agent:"agent",Task:"agent",Workflow:"agent",SendMessage:"agent",WebSearch:"search",WebFetch:"search",Grep:"search",Glob:"search"}),tC=Object.freeze({inProgress:"in_progress",in_progress:"in_progress",pending:"pending",completed:"completed"}),tS=Object.freeze({ask:"Shield",edit:"Pencil",readonly:"Eye",bypass:"Sparkles"}),tT=Object.freeze([{id:"default",label:"Default",desc:"Ask before executing commands & editing files",icon:tS.ask},{id:"acceptEdits",label:"Accept Edits",desc:"Automatically approve file changes",icon:tS.edit},{id:"plan",label:"Plan Mode",desc:"Explore and plan without modifying code",icon:tS.readonly},{id:"bypassPermissions",label:"Bypass (YOLO)",desc:"Bypass all confirmation prompts",icon:tS.bypass}]),tE=Object.freeze([{id:"ag/gemini-3.8-flash-high",label:"ag/gemini-3.8-flash-high",short:"ag/gemini-3.8-flash-high",desc:"Fast hybrid reasoning custom model"},{id:"ag/claude-opus-4-6-thinking",label:"ag/claude-opus-4-6-thinking",short:"ag/claude-opus-4-6-thinking",desc:"Opus deep thinking custom model"},{id:"ollama/glm-5.3-flash:cloud",label:"ollama/glm-5.3-flash:cloud",short:"ollama/glm-5.3-flash:cloud",desc:"Sonnet cloud custom model"},{id:"glm/glm-5.3",label:"glm/glm-5.3",short:"glm/glm-5.3",desc:"GLM 5.3 custom model"},{id:"haiku",label:"Claude Haiku",short:"haiku",desc:"Claude Haiku CLI alias"},{id:"sonnet",label:"Claude Sonnet",short:"sonnet",desc:"Claude Sonnet CLI alias"},{id:"opus",label:"Claude Opus",short:"opus",desc:"Claude Opus CLI alias"}]),tR=Object.freeze({thinking:!0,planMode:!0,tasks:!0,skills:!0,mcp:!0,rewind:!0}),tM=Object.freeze([{value:"low",label:"low",desc:"Fastest, least reasoning"},{value:"medium",label:"medium",desc:"Balanced default"},{value:"high",label:"high",desc:"Deeper reasoning for hard tasks"}]),t$=Object.freeze([{value:"pragmatic",label:"Pragmatic",desc:"Concise, task-focused, and direct"},{value:"friendly",label:"Friendly",desc:"Warm, collaborative, and helpful"},{value:"none",label:"None",desc:"No personality instructions"}]),tz=Object.freeze([{value:"low",label:"low",desc:"Fastest, least reasoning"},{value:"medium",label:"medium",desc:"Balanced default"},{value:"high",label:"high",desc:"Greater reasoning depth"},{value:"xhigh",label:"xhigh",desc:"Extra-high reasoning"},{value:"max",label:"max",desc:"Maximum reasoning"},{value:"ultra",label:"ultra",desc:"Max reasoning + automatic task delegation"}]),tP=Object.freeze([{value:"none",label:"none",desc:"Thinking off"},{value:"minimal",label:"minimal",desc:"Barely think"},{value:"low",label:"low",desc:"Fastest reasoning"},{value:"medium",label:"medium",desc:"Balanced default"},{value:"high",label:"high",desc:"Deeper reasoning for hard tasks"},{value:"xhigh",label:"xhigh",desc:"Extra-high reasoning"},{value:"max",label:"max",desc:"Maximum reasoning"},{value:"ultra",label:"ultra",desc:"Highest reasoning"}]),tA=Object.freeze([{value:"low",label:"low",desc:"Fastest, least reasoning"},{value:"medium",label:"medium",desc:"Balanced default"},{value:"high",label:"high",desc:"Deeper reasoning for hard tasks"}]),tI=Object.freeze({tools:tN,models:tE,permissionModes:tT,defaultMode:"bypassPermissions",defaultEffort:"",features:tR,slashCommands:Object.freeze([{name:"/clear",description:"Clear conversation context and history",action:"clear"},{name:"/model",description:"Select or change active AI model",action:"modal:model"},{name:"/mcp",description:"List and manage MCP servers",action:"modal:mcp"},{name:"/skills",description:"List available agent skills",action:"modal:skills"},{name:"/tasks",description:"View background tasks and checklist",action:"modal:tasks"},{name:"/resume",description:"Resume a previous conversation in this project",action:"modal:sessions"},{name:"/rewind",description:"Go back to an earlier prompt in this conversation",action:"modal:rewind"},{name:"/config",description:"Adjust CLI runtime flags",action:"modal:config"},{name:"/doctor",description:"Check the CLI installation and environment",action:"modal:doctor"},{name:"/compact",description:"Compact the conversation context",action:"send"},{name:"/cost",description:"Show token usage and cost for this session",action:"send"},{name:"/context",description:"Show context window usage and loaded files",action:"send"},{name:"/effort",description:"Reasoning effort level (--effort)",action:"submenu",optionKey:"effort",subOptions:Object.freeze([...tM,{value:"xhigh",label:"xhigh",desc:"Extra-high reasoning"},{value:"max",label:"max",desc:"Maximum reasoning"},{value:"ultracode",label:"ultracode",desc:"Highest: max reasoning + dynamic workflows"}])},{name:"/fast",description:"Toggle fast response mode",action:"send"},{name:"/init",description:"Create or update the project guide file",action:"send"},{name:"/simplify",description:"Simplify and optimize recently changed code",action:"send"}]),notices:Object.freeze({}),suppressedNotices:Object.freeze([]),questionGate:!1,headlessQuestions:!1}),tD=Object.freeze([{value:"minimal",label:"minimal",desc:"Fastest, least reasoning"},{value:"medium",label:"medium",desc:"Balanced default"},{value:"high",label:"high",desc:"Deeper reasoning"},{value:"max",label:"max",desc:"Maximum reasoning"}]);class tL{constructor({meta:e,ui:t=null,overrides:s={}}){if(!e?.id)throw Error("AiEngine requires meta.id");this.meta=e,this.ui=t,this.overrides=s,this._config=null}get id(){return this.meta.id}get config(){if(this._config)return this._config;let e=this.overrides;return this._config=Object.freeze({tools:{...tI.tools,...e.tools||{}},models:e.models||tI.models,permissionModes:e.permissionModes||tI.permissionModes,defaultMode:e.defaultMode||tI.defaultMode,defaultEffort:e.defaultEffort||tI.defaultEffort,features:{...tI.features,...e.features||{}},slashCommands:e.slashCommands||tI.slashCommands,notices:e.notices||tI.notices,suppressedNotices:new Set(e.suppressedNotices||tI.suppressedNotices),questionGate:e.questionGate??tI.questionGate,headlessQuestions:e.headlessQuestions??tI.headlessQuestions}),this._config}getToolCategory(e){let t=Object.prototype.hasOwnProperty.call(this.config.tools,e)?this.config.tools[e]:null;return"string"==typeof t?t:"generic"}parseTaskEvent(e,t,s){return arguments.length>3&&void 0!==arguments[3]&&arguments[3],null}parseTaskResult(e,t,s){return null}_parseReplaceAllTodos(e,t){return Array.isArray(e?.todos)?{id:t,replaceAll:!0,todos:e.todos.filter(e=>e&&String(e.content||"").trim()).map((e,s)=>({id:`${t}-${s}`,taskId:String(s+1),subject:String(e.content).trim(),activeForm:e.activeForm||"",status:tC[e.status]||e.status||"pending"}))}:null}}class tB extends tL{constructor(){super({meta:{id:"claude",label:"Claude Code",desc:"Anthropic Claude Code CLI (stream-json)",badge:"Claude",icon:"Bot",color:"#d97706"},ui:{id:"claude-ui",label:"Claude UI",short:"Claude UI"},overrides:{questionGate:!0}})}parseTaskEvent(e,t,s){return(arguments.length>3&&void 0!==arguments[3]&&arguments[3],"TaskCreate"===e&&t?.subject)?{id:s,taskId:"",subject:String(t.subject).trim(),activeForm:t.activeForm||"",status:"pending"}:"TaskUpdate"===e&&t?{id:s,taskId:t.taskId?String(t.taskId):"",...t.status&&{status:t.status},...t.subject&&{subject:String(t.subject).trim()},...t.activeForm&&{activeForm:t.activeForm}}:"TodoWrite"===e?this._parseReplaceAllTodos(t,s):null}parseTaskResult(e,t,s){if("string"!=typeof t)return null;let n=/Task #(\d+) created/i.exec(t);return n?{id:s,taskId:n[1]}:null}}class tF extends tL{constructor(){super({meta:{id:"codex",label:"OpenAI Codex",desc:"OpenAI Codex CLI (exec --json)",badge:"Codex",icon:"Sparkles",color:"#10b981"},ui:{id:"codex-ui",label:"Codex UI",short:"Codex UI"},overrides:{suppressedNotices:["warning"],tools:{command_execution:"bash",command:"bash",file_change:"diff",shell:"bash",patch:"diff",apply:"diff",read_file:"file",read:"file",list_files:"file",view_image:"file",image_generation:"file",todo_list:"task",web_search:"search",search:"search",spawn_agent:"agent",wait:"agent",resume_agent:"agent",send_input:"agent",close_agent:"agent",send_message:"agent",followup_task:"agent",interrupt_agent:"agent",list_agents:"agent"},models:[{id:"gpt-5.6-sol",label:"GPT-5.6-Sol",short:"5.6 Sol",provider:"openai",desc:"Flagship reasoning model for complex engineering"},{id:"gpt-5.6-terra",label:"GPT-5.6-Terra",short:"5.6 Terra",provider:"openai",desc:"High-throughput balanced model"},{id:"gpt-5.6-luna",label:"GPT-5.6-Luna",short:"5.6 Luna",provider:"openai",desc:"Fast, lightweight reasoning model"},{id:"gpt-5.5",label:"GPT-5.5",short:"5.5",provider:"openai",desc:"Advanced reasoning and coding model"},{id:"gpt-5.3-codex",label:"GPT-5.3-Codex",short:"5.3 Codex",provider:"openai",desc:"Specialized code generation & editing model"},{id:"gpt-5.1-codex-max",label:"GPT-5.1-Codex-Max",short:"5.1 Max",provider:"openai",desc:"Large-context deep reasoning model"},{id:"gpt-5.1-codex-mini",label:"GPT-5.1-Codex-Mini",short:"5.1 Mini",provider:"openai",desc:"Fast, cost-effective coding model"},{id:"gpt-6-astra",label:"GPT-6-Astra",short:"6 Astra",provider:"openai",desc:"Preview high-capability reasoning model"}],permissionModes:[{id:"plan",label:"Plan",desc:"Explore and propose without changing anything",icon:tS.readonly},{id:"readOnly",label:"Read Only",desc:"Read the workspace; ask before editing",icon:tS.ask},{id:"default",label:"Default",desc:"Read and write the workspace",icon:tS.edit},{id:"fullAccess",label:"Full Access",desc:"Edit anywhere and reach the network, no prompts",icon:tS.bypass}],defaultMode:"fullAccess",defaultEffort:"xhigh",features:{thinking:!0,planMode:!0,tasks:!0,skills:!0,mcp:!0,rewind:!0},slashCommands:[{name:"/model",description:"Choose the Codex model and reasoning effort",action:"modal:model"},{name:"/effort",description:"Reasoning effort (model_reasoning_effort)",action:"submenu",optionKey:"effort",subOptions:tz},{name:"/plan",description:"Switch the session into plan mode",action:"setMode",mode:"plan"},{name:"/permissions",description:"Set what Codex may do without asking",action:"modal:mode"},{name:"/personality",description:"Assistant communication style",action:"submenu",optionKey:"personality",subOptions:t$},{name:"/diff",description:"Show the working tree diff",action:"send"},{name:"/review",description:"Review the working tree for bugs and missing tests",action:"send"},{name:"/status",description:"Show workspace status and configuration",action:"send"},{name:"/goal",description:"Set or view this thread's persistent goal",action:"send"},{name:"/rewind",description:"Go back to an earlier prompt in this conversation",action:"modal:rewind"},{name:"/clear",description:"Start a fresh Codex session",action:"clear"},{name:"/mcp",description:"View and manage Codex MCP servers",action:"modal:mcp"},{name:"/skills",description:"Browse installed Codex skills",action:"modal:skills"},{name:"/config",description:"Configure Codex execution flags",action:"modal:config"},{name:"/doctor",description:"Diagnose the Codex installation",action:"modal:doctor"},{name:"/tasks",description:"View the task checklist",action:"modal:tasks"},{name:"/resume",description:"Resume a previous Codex session",action:"modal:sessions"}]}})}parseTaskEvent(e,t,s){return"todo_list"===e?this._parseReplaceAllTodos(t,s):null}}class tO extends tL{constructor(){super({meta:{id:"opencode",label:"OpenCode",desc:"OpenCode CLI (json stream)",badge:"OpenCode",icon:"Zap",color:"#8b5cf6"},ui:{id:"opencode-ui",label:"OpenCode UI",short:"OpenCode UI"},overrides:{tools:{bash:"bash",edit:"diff",write:"diff",patch:"diff",apply_patch:"diff",read:"file",task:"agent",todowrite:"task",webfetch:"search",websearch:"search",glob:"search",grep:"search",list:"search",view:"file",skill:"generic",plan_enter:"plan",plan_exit:"plan"},models:[],permissionModes:[{id:"auto",label:"Auto",desc:"Full tool access (build agent)",icon:tS.bypass},{id:"plan",label:"Plan",desc:"Read-only planning (plan agent)",icon:tS.ask}],defaultMode:"auto",features:{thinking:!0,planMode:!0,tasks:!1,skills:!1,mcp:!1,rewind:!0},questionGate:!0,slashCommands:[{name:"/model",description:"Choose the OpenCode model",action:"modal:model"},{name:"/variant",description:"Model variant / reasoning effort",action:"submenu",optionKey:"variant",subOptions:tD},{name:"/mcp",description:"View and manage OpenCode MCP servers",action:"modal:mcp"},{name:"/resume",description:"Resume a previous OpenCode session",action:"modal:sessions"},{name:"/rewind",description:"Go back to an earlier prompt in this conversation",action:"modal:rewind"},{name:"/clear",description:"Start a fresh OpenCode session",action:"clear"},{name:"/help",description:"Show OpenCode help and usage",action:"send"},{name:"/doctor",description:"Check the OpenCode installation",action:"modal:doctor"},{name:"/tasks",description:"View the task checklist",action:"modal:tasks"}]}})}parseTaskEvent(e,t,s){return"todowrite"===e?this._parseReplaceAllTodos(t,s):null}}class t_ extends tL{constructor(){super({meta:{id:"omp",label:"OMP",desc:"oh-my-pi coding agent (rpc mode)",badge:"OMP",icon:"Zap",color:"#f59e0b"},ui:{id:"omp-ui",label:"OMP UI",short:"OMP UI"},overrides:{tools:{bash:"bash",eval:"bash",edit:"diff",write:"diff",ast_edit:"diff",memory_edit:"diff",read:"file",task:"agent",todo:"task",todowrite:"task",glob:"search",grep:"search",ast_grep:"search",web_search:"search",recall:"search",retain:"search",reflect:"search",learn:"search",ask:"question"},models:[],permissionModes:[{id:"default",label:"Default",desc:"Ask before risky tools",icon:tS.ask},{id:"auto",label:"Auto",desc:"Auto-approve everything",icon:tS.bypass}],defaultMode:"auto",features:{thinking:!0,planMode:!1,tasks:!0,skills:!1,mcp:!1,rewind:!0},questionGate:!0,slashCommands:[{name:"/model",description:"Choose the OMP model",action:"modal:model"},{name:"/effort",description:"Thinking level (set_thinking_level)",action:"submenu",optionKey:"effort",subOptions:tM},{name:"/resume",description:"Resume a previous OMP session",action:"modal:sessions"},{name:"/clear",description:"Start a fresh OMP session",action:"clear"},{name:"/doctor",description:"Check the OMP installation",action:"modal:doctor"},{name:"/rewind",description:"Go back to an earlier prompt in this conversation",action:"modal:rewind"}]}})}parseTaskEvent(e,t,s){return"todowrite"===e||"todo"===e?this._parseReplaceAllTodos(t,s):null}}let tK=Object.freeze([{value:"off",label:"off",desc:"Thinking off"},{value:"minimal",label:"minimal",desc:"Barely think"},{value:"low",label:"low",desc:"Fastest reasoning"},{value:"medium",label:"medium",desc:"Balanced default"},{value:"high",label:"high",desc:"Deeper reasoning for hard tasks"},{value:"xhigh",label:"xhigh",desc:"Extra-high reasoning"},{value:"max",label:"max",desc:"Maximum reasoning"}]);class tW extends tL{constructor(){super({meta:{id:"pi",label:"Pi",desc:"pi coding agent (rpc mode)",badge:"Pi",icon:"Pi",color:"#e11d48"},ui:{id:"pi-ui",label:"Pi UI",short:"Pi UI"},overrides:{tools:{bash:"bash",eval:"bash",edit:"diff",write:"diff",read:"file",glob:"search",grep:"search",web_search:"search",ask:"question"},models:[],permissionModes:[{id:"default",label:"Default",desc:"All built-in tools; extensions may still ask",icon:tS.ask},{id:"readOnly",label:"Read Only",desc:"read tool only — no bash, edits or writes",icon:tS.readonly}],defaultMode:"default",features:{thinking:!0,planMode:!1,tasks:!1,skills:!0,mcp:!1,rewind:!0},questionGate:!0,slashCommands:[{name:"/model",description:"Switch models",action:"modal:model"},{name:"/thinking",description:"Switch thinking level",action:"submenu",optionKey:"effort",subOptions:tK},{name:"/compact",description:"Manually compact context, optionally with instructions",action:"send"},{name:"/resume",description:"Pick from previous sessions",action:"modal:sessions"},{name:"/fork",description:"Continue from an earlier user message",action:"modal:rewind"},{name:"/clone",description:"Duplicate the current active branch into a new session",action:"send"},{name:"/new",description:"Start a new session",action:"clear"},{name:"/name",description:"Set session display name",action:"send"},{name:"/session",description:"Show session file, ID, messages, tokens, and cost",action:"send"},{name:"/skills",description:"Browse installed pi skills",action:"modal:skills"},{name:"/config",description:"Configure pi execution flags",action:"modal:config"},{name:"/doctor",description:"Check the pi installation",action:"modal:doctor"}]}})}}class tH extends tL{constructor(){super({meta:{id:"antigravity",label:"Antigravity",desc:"Google Antigravity CLI (agy, stream-json)",badge:"Antigravity",icon:"Globe",color:"#4285f4"},ui:{id:"antigravity-ui",label:"Antigravity UI",short:"Antigravity UI"},overrides:{tools:{run_command:"bash",command_status:"bash",send_command_input:"bash",view_file:"file",list_dir:"file",read_resource:"file",write_to_file:"diff",replace_file_content:"diff",multi_replace_file_content:"diff",sed_file:"diff",notebook_edit:"diff",notebook_execution:"diff",find_by_name:"search",grep_search:"search",search_web:"search",read_url_content:"search",open_browser_url:"search",browser_get_dom:"search",browser_get_network_request:"search",browser_list_network_requests:"search",browser_refresh_page:"search",browser_subagent:"agent",invoke_subagent:"agent",define_subagent:"agent",manage_subagents:"agent",manage_task:"task",manage_inbox:"task",schedule:"task",ask_question:"question",ask_permission:"question",ask_custom_permission:"question",call_mcp_tool:"generic",generate_image:"generic",execute_browser_javascript:"generic",browser_click_element:"generic",browser_input:"generic",browser_press_key:"generic",browser_scroll:"generic",browser_scroll_dom:"generic",browser_select_option:"generic",browser_resize_window:"generic",browser_move_mouse:"generic",browser_mouse_down:"generic",browser_mouse_up:"generic",browser_drag_pixel_to_pixel:"generic",click_browser_pixel:"generic",capture_browser_screenshot:"generic",capture_browser_console_logs:"generic",list_browser_pages:"generic",read_browser_page:"generic",delete_knowledge:"generic",list_permissions:"generic",list_resources:"generic",wait:"generic",wait_5_seconds:"generic",send_message:"generic",finish:"generic"},models:[{id:"gemini-3.8-flash-high",label:"Gemini 3.8 Flash (High)",short:"3.8 Flash H"},{id:"gemini-3.8-flash-medium",label:"Gemini 3.8 Flash (Medium)",short:"3.8 Flash M"},{id:"gemini-3.8-flash-low",label:"Gemini 3.8 Flash (Low)",short:"3.8 Flash L"},{id:"gemini-3.7-flash-high",label:"Gemini 3.7 Flash (High)",short:"3.7 Flash H"},{id:"gemini-3.7-flash-medium",label:"Gemini 3.7 Flash (Medium)",short:"3.7 Flash M"},{id:"gemini-3.7-flash-low",label:"Gemini 3.7 Flash (Low)",short:"3.7 Flash L"},{id:"gemini-3.6-flash-high",label:"Gemini 3.6 Flash (High)",short:"3.6 Flash H"},{id:"gemini-3.6-flash-medium",label:"Gemini 3.6 Flash (Medium)",short:"3.6 Flash M"},{id:"gemini-3.6-flash-low",label:"Gemini 3.6 Flash (Low)",short:"3.6 Flash L"},{id:"gemini-3.1-pro-high",label:"Gemini 3.1 Pro (High)",short:"3.1 Pro H"},{id:"gemini-3.1-pro-low",label:"Gemini 3.1 Pro (Low)",short:"3.1 Pro L"},{id:"claude-sonnet-4-6",label:"Claude Sonnet 4.6",short:"Sonnet 4.6"},{id:"claude-opus-4-6-thinking",label:"Claude Opus 4.6 (Thinking)",short:"Opus 4.6"},{id:"gpt-oss-120b-medium",label:"GPT-OSS 120B (Medium)",short:"GPT-OSS 120B"}],permissionModes:[{id:"plan",label:"Plan",desc:"Explore and plan without modifying code",icon:tS.readonly},{id:"accept-edits",label:"Accept Edits",desc:"Auto-approve every tool the agent calls",icon:tS.edit}],defaultMode:"accept-edits",features:{thinking:!0,planMode:!0,tasks:!1,skills:!1,mcp:!1,rewind:!1},headlessQuestions:!0,slashCommands:[{name:"/model",description:"Choose the Antigravity model",action:"modal:model"},{name:"/effort",description:"Reasoning effort (--effort)",action:"submenu",optionKey:"effort",subOptions:tA},{name:"/resume",description:"Resume a previous Antigravity conversation",action:"modal:sessions"},{name:"/clear",description:"Start a fresh Antigravity conversation",action:"clear"},{name:"/doctor",description:"Check the Antigravity CLI installation",action:"modal:doctor"},{name:"/plan",description:"Switch the session into read-only plan mode",action:"setMode",mode:"plan"}]}})}}class tq extends tL{constructor(){super({meta:{id:"devin",label:"Devin",desc:"Devin CLI agent (acp mode)",badge:"Devin",icon:"Compass",color:"#6d5dfc"},ui:{id:"devin-ui",label:"Devin UI",short:"Devin UI"},overrides:{tools:{exec:"bash",edit:"diff",write:"diff",read:"file",glob:"search",grep:"search",search:"search",web_search:"search",fetch:"search",list_dir:"search",think:"thought",todo:"task",ask:"question"},models:[{id:"swe-1-6-slow",label:"SWE-1.6 Slow",short:"SWE-1.6 Slow",desc:"Low cost balanced default",provider:"Devin"},{id:"swe-1-7",label:"SWE-1.7 Max",short:"SWE-1.7 Max",provider:"Devin"},{id:"swe-2-high",label:"SWE-2 High",short:"SWE-2 High",provider:"Devin"},{id:"claude-opus-5-medium",label:"Claude Opus 5 Medium",short:"Opus 5 M",provider:"Anthropic"},{id:"claude-sonnet-5-medium",label:"Claude Sonnet 5 Medium",short:"Sonnet 5 M",provider:"Anthropic"},{id:"claude-fable-5-1-medium",label:"Claude Fable 5.1 Medium",short:"Fable 5.1 M",provider:"Anthropic"},{id:"gpt-5-6-sol-medium",label:"GPT-5.6 Sol Medium Thinking",short:"5.6 Sol M",provider:"OpenAI"},{id:"gpt-6-astra-medium",label:"GPT-6 Astra Medium Thinking",short:"6 Astra M",provider:"OpenAI"}],permissionModes:[{id:"accept-edits",label:"Code",desc:"Auto-approve reads and edits (set in Devin)",icon:tS.edit}],defaultMode:"accept-edits",features:{thinking:!0,planMode:!1,tasks:!1,skills:!1,mcp:!1,rewind:!1},questionGate:!0,slashCommands:[{name:"/model",description:"Choose the Devin model",action:"modal:model"},{name:"/resume",description:"Resume a previous Devin session",action:"modal:sessions"},{name:"/clear",description:"Start a fresh Devin session",action:"clear"},{name:"/doctor",description:"Check the Devin installation",action:"modal:doctor"}]}})}}class tU extends tL{constructor(){super({meta:{id:"hermes",label:"Hermes",desc:"Hermes CLI agent (acp mode)",badge:"Hermes",icon:"Send",color:"#22d3ee"},ui:{id:"hermes-ui",label:"Hermes UI",short:"Hermes UI"},overrides:{tools:{terminal:"bash",process_manage:"bash",process:"bash",execute_code:"bash",read_file:"file",vision_analyze:"file",write_file:"diff",patch:"diff",search_files:"search",web_search:"search",web_extract:"search",session_search:"search",browser_navigate:"search",browser_snapshot:"file",browser_get_images:"file",browser_vision:"file",delegate_task:"agent",todo_list:"task",todo:"task"},models:[],permissionModes:[{id:"default",label:"Default",desc:"Ask before edits",icon:tS.ask},{id:"accept_edits",label:"Accept Edits",desc:"Auto-allow workspace edits, ask for sensitive paths",icon:tS.edit},{id:"dont_ask",label:"Don't Ask (full)",desc:"Spawn with --yolo: every approval bypassed except hermes' own deny floors",icon:tS.bypass}],defaultMode:"dont_ask",features:{thinking:!0,planMode:!1,tasks:!0,skills:!0,mcp:!1,rewind:!1},slashCommands:[{name:"/model",description:"Choose the Hermes model",action:"modal:model"},{name:"/effort",description:"Thinking level (config.yaml)",action:"submenu",optionKey:"effort",subOptions:tP},{name:"/resume",description:"Resume a previous Hermes session",action:"modal:sessions"},{name:"/clear",description:"Start a fresh Hermes session",action:"clear"},{name:"/doctor",description:"Check the Hermes installation",action:"modal:doctor"},{name:"/help",description:"List available commands",action:"send"},{name:"/tools",description:"List available tools with descriptions",action:"send"},{name:"/context",description:"Show conversation message counts by role",action:"send"},{name:"/compress",description:"Compress conversation context",action:"send"},{name:"/reset",description:"Clear conversation history",action:"send"},{name:"/version",description:"Show Hermes version",action:"send"}]}})}parseTaskEvent(e,t,s){return"todo_list"===e||"todo"===e?this._parseReplaceAllTodos(t,s):null}}let tX="claude",tV=new Map;function tG(e){if(!(e instanceof tL))throw Error("registerEngine expects an AiEngine");return tV.set(e.id,e),e}function tJ(e){return tV.get(e)||tV.get(tX)}function tY(){return[...tV.values()]}function tZ(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:tX;return tJ(e).config}function tQ(e,t){return tJ(e).getToolCategory(t)}function t0(e,t,s,n){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[];return tJ(e).parseTaskEvent(t,s,n,r)}function t1(e,t,s,n){return tJ(e).parseTaskResult(t,s,n)}tG(new tB),tG(new tF),tG(new tO),tG(new tH),tG(new t_),tG(new tW),tG(new tq),tG(new tU);let t2=Object.fromEntries(tY().map(e=>e.meta).map(e=>[e.id,e])),t5=tY().filter(e=>e.ui).map(e=>({...e.ui,isAiUi:!0,aiEngine:e.id})),t3={light:{base:"#F1EFEA",center:"#FBFAF7",edge:"#E7E3DC",glow:"radial-gradient(70% 55% at 18% 12%, rgba(230,138,110,0.06), transparent 62%), radial-gradient(60% 50% at 84% 86%, rgba(120,140,180,0.04), transparent 66%), ",glowSize:"100% 100%, 100% 100%, ",glowRepeat:"no-repeat, no-repeat, "},dark:{base:"#141414",center:"#1F1D1C",edge:"#0C0C0C",glow:"",glowSize:"",glowRepeat:""},poolSize:"95% 80%",poolAt:"46% 38%",poolFalloff:68,tiltDeg:105,bandStart:42,bandEnd:58};function t4(e){let t=t3["light"===e?"light":"dark"];return{backgroundColor:t.base,backgroundImage:`${t.glow}var(--ai-wallpaper), radial-gradient(${t3.poolSize} at ${t3.poolAt}, ${t.center}, transparent ${t3.poolFalloff}%), linear-gradient(${t3.tiltDeg}deg, ${t.edge}, ${t.base} ${t3.bandStart}%, ${t.base} ${t3.bandEnd}%, ${t.edge})`,backgroundSize:`${t.glowSize}var(--ai-wallpaper-size), 100% 100%, 100% 100%`,backgroundRepeat:`${t.glowRepeat}repeat, no-repeat, no-repeat`}}let t6=Object.freeze(["Explain this project's structure","What changed recently in this repo?","! git status"]),t8="deny",t9="User skipped this request";var t7=s(38118),se=s(97509),st=s(59055);let ss=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],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},sn=e=>(0,b.v)((0,st.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=ss(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=ss(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)}}})),sr=sn("terminal-command-history"),sl=sn("remote-input-history"),sa=sn("ai-command-history");function si(e){let{snippet:t,onSave:s,onClose:l}=e,{t:a}=(0,eu.s)(),[i,o]=(0,r.useState)(t?.alias??""),[c,d]=(0,r.useState)(t?.cmd??""),u=(0,r.useRef)(null);if((0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l]),!t)return null;let m=c.trim().length>0;return"u"<typeof document?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[70]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:l}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full my-auto flex flex-col pop-in",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.editSnippet")}),(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:"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:a("history.aliasLabel")}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>o(e.target.value),placeholder:a("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:a("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:a("history.commandLabel")}),(0,n.jsx)("textarea",{ref:u,value:c,onChange:e=>d(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:l,className:"px-4 py-2 text-sm bg-surface-3 hover:bg-surface text-text rounded-brand transition-colors",children:a("common.cancel")}),(0,n.jsxs)("button",{onClick:()=>{m&&((0,ed.e)(),s({cmd:c.trim(),alias:i.trim()}),l())},disabled:!m,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}),a("common.save")]})]})]})]})]}),document.body)}function so(e){let{isOpen:t,onSelect:s,onClose:l,store:a=sr}=e,{t:i}=(0,eu.s)(),o=a(e=>e.history),c=a(e=>e.pinned),d=a(e=>e.removeCommand),u=a(e=>e.clearHistory),m=a(e=>e.togglePin),x=a(e=>e.setSnippet),[p,h]=(0,r.useState)(null);if((0,r.useEffect)(()=>{if(!t)return;document.activeElement?.blur?.();let e=e=>{"Escape"!==e.key||p||l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,l,p]),!t||"u"<typeof document)return null;let f=e=>{(0,ed.e)(),s(e),l()};return(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[60]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in touch-none",onClick:l}),(0,n.jsxs)("div",{className:"relative card-elev max-w-lg w-full my-auto flex flex-col pop-in",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:i("history.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[o.length>0&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u()},className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":i("history.clearAll"),title:i("history.clearAll"),children:(0,n.jsx)(el.TB,{size:18})}),(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":i("common.close"),children:(0,n.jsx)(el.X,{size:20})})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 max-h-[70vh] overflow-y-auto modal-scrollable p-3",children:0===c.length&&0===o.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:i("history.empty")})]}):(0,n.jsxs)("div",{className:"flex flex-col gap-0",children:[c.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:i("history.snippets")}),c.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)(),h(e)},className:"flex-shrink-0 p-2 text-text-muted hover:text-text rounded-brand transition-colors","aria-label":i("history.editSnippet"),children:(0,n.jsx)(el.gH,{size:16})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m(e.cmd)},className:"flex-shrink-0 p-2 mr-1 text-brand-500 hover:text-brand-400 rounded-brand transition-colors","aria-label":i("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"})]}),o.length>0&&(0,n.jsxs)(n.Fragment,{children:[c.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:i("history.history")}),o.map(e=>{let t=c.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)(),m(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?i("history.unpin"):i("history.pin"),children:(0,n.jsx)(el.yU,{size:16,fill:t?"currentColor":"none"})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d(e)},className:"flex-shrink-0 p-2 mr-1 text-text-muted hover:text-text rounded-brand transition-colors","aria-label":i("common.delete"),children:(0,n.jsx)(el.X,{size:16})})]},e)})]})]})})]}),p&&(0,n.jsx)(si,{snippet:p,onSave:e=>x(p.cmd,e),onClose:()=>h(null)})]}),document.body)}let sc={pinned:2,history:4,common:4,total:8},sd={pinned:1,history:2,common:2,total:4},su=(e,t)=>{let s=e.indexOf(t);return s<0?null:1e3*(0!==s)+s+.1*e.length};function sm(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=su(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?sd:sc,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 sx(e){let{value:t,store:s,commonCommands:l=[],onSelect:a,isMobile:i=!1,disabled:o=!1,activeIndex:c=-1}=e,d=s(e=>e.history),u=s(e=>e.pinned),[m,x]=(0,r.useState)(""),p=(0,r.useMemo)(()=>o?[]:sm(t,d,u,l,i),[t,d,u,l,i,o]),h=(0,r.useRef)(null);return((0,r.useEffect)(()=>{let e=h.current;if(!e||c<0)return;let t=e.children[c];t&&t.scrollIntoView({block:"nearest"})},[c]),0===p.length||m===t)?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(t),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:h,className:"flex flex-col max-h-[25vh] overflow-y-auto modal-scrollable",children:p.map((e,t)=>{let s;return(0,n.jsxs)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),a(e.cmd)},className:`flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-2 transition-colors touch-none ${t===c?"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 sp={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"},sh=e=>sp[e]||e||"en-US",sf="voiceLang";function sb(e){let[t,s]=(0,r.useState)(e&&sp[e]?e:"auto");return(0,r.useEffect)(()=>{let e=localStorage.getItem(sf);("auto"===e||e&&sp[e])&&s(e)},[]),[t,(0,r.useCallback)(e=>{s(e);try{localStorage.setItem(sf,e)}catch{}},[])]}let sg=new Set(["not-allowed","service-not-allowed","audio-capture","language-not-supported"]);function sv(){return window.SpeechRecognition||window.webkitSpeechRecognition||null}function sy(){let{lang:e="en-US",onText:t,onError:s,onFinish:n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=z(e=>e.mode),a=z(e=>e.enabled),[i,o]=(0,r.useState)(!1),[c,d]=(0,r.useState)(!1),[u,m]=(0,r.useState)(0),[x,p]=(0,r.useState)(null),h=(0,r.useRef)(n);(0,r.useEffect)(()=>{h.current=n},[n]);let f=(0,r.useRef)(s);(0,r.useEffect)(()=>{f.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__),E="browser"===l&&(T||C||!k&&!sv())&&S?"ai":l,M="ai"===E?S:!k&&!!sv(),$=(0,r.useCallback)(async()=>{g.current=!1;let e=w.current;if(w.current=null,!e){o(!1),d(!1),m(0);return}clearInterval(e.timer),m(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 R(z.getState(),t,v.current),n=`${j.current}${s}`.replace(/\s+/g," ").trimStart();b.current?.(n),s?.trim()&&h.current?.(n)}catch(e){p("network"),f.current?.("network")}finally{o(!1),d(!1),m(0)}},[]),P=(0,r.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";j.current=e?e.replace(/\s*$/,"")+" ":"",p(null),g.current=!0,m(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},x=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),m(Math.min(1,Math.max(0,(t-2)/20)))},80);w.current={stream:n,rec:r,chunks:l,stopped:a,ctx:i,timer:x,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),f.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),m(0)},[]),I=(0,r.useCallback)(()=>{if(g.current=!1,"ai"===E)return void $();try{y.current?.stop()}catch{}},[E,$]),D=(0,r.useCallback)(function e(){let t=sv();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),m(0);let e=j.current.trim();e&&h.current?.(e)}},s.onerror=e=>{let t=e?.error||"error";"no-speech"!==t&&"aborted"!==t&&(p(t),f.current?.(t),sg.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)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";"ai"===E?P(e):!k&&sv()&&(j.current=e?e.replace(/\s*$/,"")+" ":"",p(null),g.current=!0,D())},[k,E,P,D]),B=(0,r.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";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:M,active:a&&M,listening:i,transcribing:c,volume:u,error:x,start:L,stop:I,cancel:A,toggle:B}}let sw="(pointer: fine) and (hover: hover)";function sj(){let[e,t]=(0,r.useState)(()=>window.matchMedia(sw).matches?"mouse":"touch");return(0,r.useEffect)(()=>{let e=window.matchMedia(sw),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}let sk=new Map;function sN(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)(()=>{let t=sk.get(e);return t||sk.set(e,t=new Set),t.add(n),()=>{t.delete(n),t.size||sk.delete(e)}},[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)}for(let t of sk.get(e)||[])t!==n&&t(s)},[e,s]);let i=(0,r.useCallback)(()=>n(t),[t]);return[s,n,i]}function sC(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"flat",l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],[a,i,o]=sN(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]),m=d&&l.some(e=>"grid"===n?u(e.flat(),d):u(e,d)),x=m?s:a,p=(0,r.useCallback)(e=>e.map(e=>c.get(e)).filter(Boolean),[c]),h="grid"===n&&Array.isArray(s)?s.length:1,f=(0,r.useMemo)(()=>"grid"===n?Array.isArray(x)&&x.length===h&&x.every(Array.isArray)?x:s:[Array.isArray(x)?x:[]],[x,n,s,h]),b=(0,r.useMemo)(()=>p(f.flat()),[f,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?x[e]||[]:x,[x,n]);(0,r.useEffect)(()=>{m&&i(s)},[m,s,i]);let y=(0,r.useCallback)(e=>{i(t=>"grid"===n?e(Array.isArray(t)&&t.length===h&&t.every(Array.isArray)?t.map(e=>[...e]):s.map(e=>[...e])):e([[...Array.isArray(t)?t:[]]])[0])},[i,n,s,h]),w=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]: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:f,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 sS="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]",sT="bg-brand-500 text-white";function sE(e){let{label:t,selected:s,onClick:r}=e;return(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),r()},className:`${sS} ${s?sT:"bg-surface-2 hover:bg-surface-3 text-text"}`,children:t})}function sR(e){let{selected:t,onClick:s}=e;return(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),s()},className:`${sS} ${t?sT:"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 sM(e){let{isOpen:t,onClose:s,title:l="Customize Keys",tabs:a}=e,[i,o]=(0,r.useState)(a?.[0]?.id),[c,d]=(0,r.useState)(null);if((0,r.useEffect)(()=>{t&&d(null)},[t]),(0,r.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&s()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,s]),(0,r.useEffect)(()=>{d(null)},[i]),!t||"u"<typeof document)return null;let u=a.find(e=>e.id===i)||a[0],{rows:m,available:x,replaceAt:p,swap:h,removeAt:f,reset:b}=u.hook,g=u.excludeIds||[],v=m.map(e=>e.map((e,t)=>({id:e,rawCol:t})).filter(e=>!g.includes(e.id))),y=v.map(e=>e.map(e=>e.id)),w=g.length?x.filter(e=>!g.includes(e.id)):x,j=(e,t)=>{let s=v[e]||[];return t>=s.length?(m[e]||[]).length:s[t].rawCol},k=(e,t)=>c&&c.row===e&&c.col===t,N=(e,t,s)=>{if(!s&&k(e,t))return void d(null);if(c&&!s&&!(c.col>=y[c.row].length)){h({row:c.row,col:j(c.row,c.col)},{row:e,col:j(e,t)}),d(null);return}d({row:e,col:t})},C=new Map;u.hook.keys?.forEach(e=>C.set(e.id,e)),w.forEach(e=>C.set(e.id,e));let S=c&&y[c.row]&&c.col<y[c.row].length;return"u"<typeof document?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-50",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:s}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-2xl my-auto flex flex-col pop-in",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:l}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s()},className:"text-text-muted hover:text-text",children:(0,n.jsx)(el.X,{size:18})})]}),a.length>1&&(0,n.jsx)("div",{className:"px-5 pt-1 flex gap-2 border-b border-border-subtle",children:a.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),o(e.id)},className:`px-3 py-2 -mb-px text-xs font-semibold border-b-2 transition-colors duration-150 ${i===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 min-h-0 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:c?"Click another to swap, or Remove below":"Click to select"}),S&&(0,n.jsxs)("button",{onClick:()=>{if(!c)return;let e=y[c.row]||[];c.col<e.length&&f(c.row,j(c.row,c.col)),d(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:y.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=C.get(e);return(0,n.jsx)(sE,{label:r?.label||e,selected:k(t,s),onClick:()=>N(t,s,!1)},e+s)}),(0,n.jsx)(sR,{selected:k(t,e.length),onClick:()=>N(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 ",c?S?"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===w.length&&(0,n.jsx)("div",{className:"text-xs text-text-muted italic",children:"All keys added."}),w.map(e=>(0,n.jsx)(sE,{label:e.label,onClick:()=>(e=>{if(c)p(c.row,j(c.row,c.col),e);else{let t=y.length>0?y.length-1:0;p(t,(m[t]||[]).length,e)}d(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)(),b(),d(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)(),s()},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"})]})]})]}),document.body)}function s$(e){let{bus:t,sessionId:s}=e,{t:n}=(0,eu.s)(),[l,a]=(0,r.useState)([]),i=(0,r.useRef)(0),o=(0,r.useCallback)(e=>new Promise(t=>{if(e.size>eg.Tb)return alert(n("mobileKeyboard.fileTooLarge")),t(null);let s=new FileReader;s.onload=()=>{let n=s.result.split(",")[1],r=e.type.startsWith("image/"),l=e.name||`paste_${i.current}.${r?e.type.split("/")[1]||"png":"bin"}`;t({id:++i.current,name:l,type:e.type,size:e.size,content:n,isImage:r})},s.onerror=()=>{alert(n("mobileKeyboard.readFileFailed")),t(null)},s.readAsDataURL(e)}),[n]),c=(0,r.useCallback)(async e=>{let t=eg.qQ-l.length;if(t<=0)return;let s=Array.from(e).slice(0,t),n=(await Promise.all(s.map(o))).filter(Boolean);n.length&&((0,ed.e)(),a(e=>[...e,...n]))},[l.length,o]),d=(0,r.useCallback)(e=>{a(t=>t.filter(t=>t.id!==e))},[]),u=(0,r.useCallback)(e=>new Promise(n=>{let r=!1,l=e=>{r||(r=!0,n(!!e))};if(!t)return l(!1);t.emit("clipboard-attach",{sessionId:s,filename:e.name,type:e.type,content:e.content},e=>l(e?.success!==!1)),setTimeout(()=>l(!1),eg.ll)}),[t,s]),m=(0,r.useCallback)(async e=>{(0,ed.e)();let t=e.target.files;t?.length&&await c(t),e.target.value=""},[c]),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(),c(s))},[c]);return{attachments:l,setAttachments:a,addFiles:c,removeAttachment:d,sendOneAttachment:u,handleFileUpload:m,handleAttachPaste:x}}function sz(e,t,s,n){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:setTimeout,l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:clearTimeout,a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,i=!1,o=!1,c=null,d=e=>{e?.ok&&!o&&(o=!0,a?.()),i||(i=!0,l(c),e?.ok||n(e?.error||"timeout"))};e(t,d),c=r(()=>d(null),s)}let sP={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~"},sA={ArrowUp:"\x1b[1;5A",ArrowDown:"\x1b[1;5B",ArrowRight:"\x1b[1;5C",ArrowLeft:"\x1b[1;5D"},sI={ArrowUp:"\x1b[1;2A",ArrowDown:"\x1b[1;2B",ArrowRight:"\x1b[1;2C",ArrowLeft:"\x1b[1;2D"},sD={"[":"\x1b","]":"\x1d","\\":"\x1c","@":"\0","?":""};var sL=s(26463),sB=s(2939);function sF(e){let{items:t,onSelect:s,activeIndex:l=-1}=e,a=(0,r.useRef)(null);return((0,r.useEffect)(()=>{let e=a.current;if(!e||l<0)return;let t=e.children[l];t&&t.scrollIntoView({block:"nearest"})},[l]),t?.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:a,className:"flex flex-col max-h-[25dvh] overflow-y-auto modal-scrollable",children:t.map((e,t)=>(0,n.jsxs)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),s(e.full)},className:`flex items-center gap-2 px-3 py-1.5 text-left hover:bg-surface-2 transition-colors touch-none ${t===l?"bg-brand-500/15":""}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:"folder"===e.type?(0,n.jsx)(sL.A,{size:13,className:"text-brand-500",fill:"currentColor"}):(0,n.jsx)(sB.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:(0,n.jsx)(sO,{text:e.label,positions:e.positions})})]},`${e.type}-${e.name}`))})}):null}function sO(e){let{text:t,positions:s}=e;if(!s?.length)return t;let r=new Set(s);return(0,n.jsx)(n.Fragment,{children:[...t].map((e,t)=>r.has(t)?(0,n.jsx)("span",{className:"text-accent font-semibold",children:e},t):(0,n.jsx)("span",{children:e},t))})}let s_=[.3,.6,.85,1,.75,.9,1,.65,.35],sK=[.4,.8,1,.7,.9,.5,.85,.35];function sW(e){let{code:t,className:s="",t:l}=e,[a,i]=(0,r.useState)(!1);return((0,r.useEffect)(()=>{let e=setTimeout(()=>i(!0),5e3);return()=>clearTimeout(e)},[]),a)?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 list-rise pointer-events-none ${s}`,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(t)?l("voice.denied"):"network"===t?l("voice.network"):"mic-timeout"===t?l("voice.micTimeout"):String(t)]})}let sH=(0,r.memo)(function(e){let{voice:t,onDone:s,onCancel:r,className:l=""}=e,{t:a}=(0,eu.s)(),i=!t?.listening&&t?.error?t.error:null;return t?.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 list-rise pointer-events-auto ${l}`,children:t.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:sK.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:()=>{r?r():t.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:s_.map((e,s)=>{let r=Math.max(3,Math.round(3+e*(t.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)(),s?s():t.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})})]})}):i?(0,n.jsx)(sW,{code:i,className:l,t:a},i):null}),sq=0,sU=null,sX=null,sV=null,sG=null;function sJ(e){return/[A-Z]/.test(e)}function sY(e,t){if(!e)return{score:0,positions:[]};if(!t||e.length>t.length)return null;let s=sJ(e),n=s?e:e.toLowerCase(),r=s?t:t.toLowerCase();if(!function(e,t){let s=0;for(let n=0;n<t.length&&s<e.length;n++)t[n]===e[s]&&s++;return s===e.length}(n,r))return null;let l=n.length,a=r.length,i=a+1,o=(l+1)*i;o>sq&&(sU=new Float64Array(o),sX=new Float64Array(o),sV=new Uint8Array(o),sq=o),(!sG||sG.length<a)&&(sG=new Float64Array(a)),sU.fill(-1e9,0,o),sX.fill(-1e9,0,o),sV.fill(0,0,o);for(let e=0;e<a;e++)sG[e]=function(e,t){if(0===t)return 10;let s=e[t-1];if("/"===s||"\\"===s)return 9;if(" "===s||" "===s)return 10;if("."===s||"-"===s||"_"===s)return 8;let n=e[t];return 7*(!!(s>="a")&&!!(s<="z")&&!!(n>="A")&&!!(n<="Z"))}(t,e);for(let e=0;e<=a;e++)sU[e]=0;for(let e=1;e<=l;e++){let t=n.charCodeAt(e-1),s=e*i,l=s-i,o=1===e;for(let n=e;n<=a;n++){let a=s+n,i=a-1,c=-1e9;if(r.charCodeAt(n-1)===t){let t=sU[l+n-1];if(t>-1e9/2){let s=e>1&&1===sV[l+n-1],r=sG[n-1];o&&(r*=2),s&&(r+=4),c=t+16+r}}let d=-1e9;sU[i]>-1e9/2&&(d=sU[i]+-3),sX[i]>-1e9/2&&(d=Math.max(d,sX[i]+-1)),sX[a]=d;let u=sU[i],m=0;c>u&&(u=c,m=1),d>u&&(u=d,m=2),sU[a]=u,sV[a]=m}}let c=sU[l*i+a];if(c<=-1e9/2)return null;let d=Array(l),u=l,m=a;for(;u>0;)1===sV[u*i+m]&&(d[u-1]=m-1,u--),m--;return{score:c,positions:d}}function sZ(e,t){let{isModified:s=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e)return null;let n=t.lastIndexOf("/"),r=-1===n?t:t.slice(n+1),l=n+1,a=sJ(e),i=a?e:e.toLowerCase(),o=a?r:r.toLowerCase(),c=a?t:t.toLowerCase(),d=null;if(i.includes("/"))d=sY(e,t);else{let s=sY(e,r);if(s)d={score:s.score+200,positions:s.positions.map(e=>e+l)};else{if(-1===(a?t.slice(0,l):t.slice(0,l).toLowerCase()).indexOf(i))return null;let s=sY(e,t);s&&(d={score:Math.round(.6*s.score),positions:s.positions})}}if(!d)return null;o===i?d.score+=120:o.startsWith(i)?d.score+=60:!i.includes("/")&&c.startsWith(i)&&(d.score+=80),s&&(d.score+=15);let u=(t.match(/\//g)||[]).length;return d.score-=Math.min(2*u,12),d}function sQ(e,t){if(e.isModified!==t.isModified)return e.isModified?-1:1;let s=e.path.split("/").length,n=t.path.split("/").length;return s!==n?s-n:e.path.localeCompare(t.path)}function s0(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10;if(!e)return[];let n=(t||"").trim();if(!n){let t;return(t=[...e.files.map(e=>({path:e.path,isDir:!1,isModified:!!e.isModified})),...e.dirs.map(e=>({path:e,isDir:!0,isModified:!1}))]).sort(sQ),t.slice(0,s).map(e=>({...e,positions:[]}))}let r=n.lastIndexOf("/");if(-1!==r){let t=function(e,t,s,n){let r=t.toLowerCase(),l=s.toLowerCase(),a=new Map,i=(e,t,s,n)=>{let r=a.get(e);r&&(r.isDir||!s)||a.set(e,{segment:e,target:t,isDir:s,isModified:n})};for(let s of e.dirs){if(!s.toLowerCase().startsWith(r))continue;let e=s.slice(t.length);if(!e)continue;let n=e.split("/")[0];i(n,`${t}${n}`,!0,!1)}for(let s of e.files){if(!s.path.toLowerCase().startsWith(r))continue;let e=s.path.slice(t.length);if(!e)continue;let n=e.indexOf("/");-1===n?i(e,s.path,!1,!!s.isModified):i(e.slice(0,n),`${t}${e.slice(0,n)}`,!0,!1)}let o=[];for(let e of a.values()){let n=sY(s,e.segment);if(!n)continue;let r=e.segment.toLowerCase()===l;o.push({path:e.target,isDir:e.isDir,isModified:e.isModified,score:n.score+200+120*!!r,positions:n.positions.map(e=>e+t.length)})}return o.length>0?(o.sort((e,t)=>t.score-e.score||Number(t.isDir)-Number(e.isDir)||e.path.length-t.path.length||e.path.localeCompare(t.path)),o.slice(0,n)):a.size>0?[]:null}(e,n.slice(0,r+1),n.slice(r+1),s);if(t)return t;let l=function(e,t,s){let n=[];for(let s of e.files){let e=sZ(t,s.path,{isModified:!!s.isModified});e&&n.push({path:s.path,isDir:!1,isModified:!!s.isModified,...e})}return 0===n.length?null:(n.sort((e,t)=>t.score-e.score||e.path.length-t.path.length||e.path.localeCompare(t.path)),n.slice(0,s))}(e,n.slice(r+1),s);if(l)return l}let l=[];for(let t of e.files){let e=sZ(n,t.path,{isModified:!!t.isModified});e&&l.push({path:t.path,isDir:!1,isModified:!!t.isModified,...e})}for(let t of e.dirs){let e=sZ(n,t.endsWith("/")?t:`${t}/`);e&&l.push({path:t,isDir:!0,isModified:!1,...e})}return l.sort((e,t)=>t.score-e.score||e.path.length-t.path.length||e.path.localeCompare(t.path)),l.slice(0,s)}let s1=/[\s([{"'`]/;function s2(e,t){if("string"!=typeof e)return null;let s=Math.max(0,Math.min(t??e.length,e.length)),n=s;for(;n>0;){let t=e[n-1];if(" "===t&&"\\"===e[n-2]){n-=2;continue}if(s1.test(t))break;n--}let r=e.slice(n,s);if(!r)return null;let l=r[0];return"@"!==l&&"/"!==l||"@"===l&&-1!==r.indexOf("@",1)?null:{trigger:l,token:r,query:r.slice(1).replace(/\\ /g," "),start:n,end:s}}function s5(e){return e.replace(/ /g,"\\ ")}let s3=RegExp(`^\\s*(${eg.RF.verbs.join("|")})\\s+(\\S*)$`,"i"),s4=/^[-=<>|&;]/,s6=/^(?:\.{1,2}\/|~\/|\/)/,s8=r.memo(e=>{let t,{bus:s,sessionId:l,onExpandChange:a,onRegisterTextApi:i,platform:o,onInput:c,onSwitchSession:d,onSwitchToIndex:u,onInputFocusChange:m,statusStrip:x=null,isDesktop:p=!1}=e,{t:h,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,f.B)(e=>e.drafts[l]??""),k=(0,f.B)(e=>e.setDraft),N=(0,r.useCallback)(e=>{k(l,"function"==typeof e?e(f.B.getState().drafts[l]??""):e)},[k,l]),[C,S]=(0,r.useState)(!1),[T,E]=(0,r.useState)(!1),[R,M]=(0,r.useState)(!1),[$,z]=(0,r.useState)(!1),P=sr(e=>e.addCommand),A=sr(e=>e.resolveAlias),I=sr(e=>e.history),D=sr(e=>e.pinned),L=(0,r.useRef)(null),B=(0,r.useRef)(null),F=(0,r.useRef)(!1),[O,_]=(0,r.useState)(!1),K=(0,r.useRef)(-1);(0,r.useRef)("");let W=(0,f.B)(e=>e.cwdBySession[l]),[H,q]=(0,r.useState)([]),[U,X]=(0,r.useState)(-1),[V,G]=(0,r.useState)(-1),J=(0,r.useMemo)(()=>H.length>0?[]:sm(j,I,D,eg.dt,C),[j,I,D,C,H]),Y=(e,t)=>e<0||!t?-1:(e%t+t)%t,Z=Y(U,H.length),Q=Y(V,J.length),ee=(0,r.useRef)(null);null==ee.current&&(ee.current=function(){let{ttlMs:e,maxDirs:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:eg.RF,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 et=(0,r.useRef)(s);(0,r.useEffect)(()=>{et.current=s},[s]);let es=er(et),{attachments:en,setAttachments:ea,addFiles:ei,removeAttachment:eo,sendOneAttachment:ec,handleFileUpload:em,handleAttachPaste:ex}=s$({bus:s,sessionId:l}),[ep]=sb(b),eh=sy({lang:sh(ep),onText:e=>{N(e);let t=L.current;t&&requestAnimationFrame(()=>{try{t.selectionStart=t.selectionEnd=t.value.length}catch{}t.scrollTop=t.scrollHeight})}}),ef="mouse"===sj();(0,r.useEffect)(()=>{let e=L.current;if(!e)return;e.style.height="auto";let t=ef?eg.hp:eg.bs;e.style.height=`${Math.min(e.scrollHeight,t)}px`},[j,ef]);let eb=(0,r.useRef)(0);(0,r.useEffect)(()=>{let e=function(e,t){var s,n;let r=s3.exec(e),l="",a="";if(r)l=`${r[1]} `,a=r[2]||"";else{let t=/(\S*)$/.exec(e),s=t?t[1]:"",n=e.length-s.length;if(!s||!s6.test(s)||s4.test(s)||n>0&&!/\s$/.test(e.slice(0,n)))return null;l=e.slice(0,n),a=s}let i=a.lastIndexOf("/");if(i<0)return{lead:l,dir:t||"",prefix:a,partial:a};let o=a.slice(0,i);return o?{lead:l,dir:(s=t,(n=o)?n.startsWith("/")||n.startsWith("~")||!s?n:s.replace(/\/+$/,"")+"/"+n:s||""),prefix:a.slice(i+1),partial:a}:{lead:l,dir:a.startsWith("~")?"~":"/",prefix:a.slice(i+1),partial:a}}(j,W),t=++eb.current,s=setTimeout(async()=>{if(t!==eb.current)return;if(!e)return void q([]);let s=Date.now(),n=ee.current.get(e.dir,s);if(null==n){let r=await es.getFiles(e.dir,!1);if(t!==eb.current)return;if(!r?.success)return void q([]);n=r.files,ee.current.set(e.dir,n,s)}q(function(e,t){let{partial:s,lead:n}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e?.length)return[];let r=s&&s.includes("/")?s.slice(0,s.lastIndexOf("/")+1):"",l=[];for(let s of e){let e=s.name+("folder"===s.type?"/":""),n=t?sY(t,e):{score:0,positions:[]};n&&l.push({entry:s,name:e,hit:n})}return l.sort((e,t)=>{let s=+("folder"!==e.entry.type),n=+("folder"!==t.entry.type);return s!==n?s-n:t.hit.score!==e.hit.score?t.hit.score-e.hit.score:e.entry.name.localeCompare(t.entry.name)}),l.slice(0,eg.RF.maxResults||8).map(e=>{let{entry:t,name:s,hit:l}=e;return{name:t.name,type:t.type,arg:r+s,label:s,positions:l.positions,full:`${n||""}${r}${s}`}})}(n,e.prefix,e))},eg.RF.debounceMs);return()=>clearTimeout(s)},[j,W,es]),(0,r.useEffect)(()=>{let e=setTimeout(()=>{ee.current?.clear(),q([])},0);return()=>clearTimeout(e)},[l]);let[ev,ey]=(0,r.useState)(!1),[ew,ej]=(0,r.useState)(!1),[ek,eN]=(0,r.useState)(!1),[eC,eS]=(0,r.useState)(!1),eT=sC("terminal.basicKeys",eg.y,eg.cK,"flat",[["esc","up","down","ctrlC","ctrl","opt","shift","tab"]]),eE=sC("terminal.extraKeys",eg.y,eg.Mg,"grid"),eR=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(e){let{ctrl:t=!1,alt:s=!1,shift:n=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t&&1===e.length){let t=e.toUpperCase().charCodeAt(0);return t>=65&&t<=90?String.fromCharCode(t-64):sD[e]??e}return s?sP[e]?"\x1b"+sP[e]:1===e.length?"\x1b"+e:sP[e]||e:t&&sP[e]?e.startsWith("Arrow")?sA[e]||sP[e]:"Home"===e?"\x1b[1;5H":"End"===e?"\x1b[1;5F":sP[e]:n&&sP[e]?"Tab"===e?"\x1b[Z":e.startsWith("Arrow")&&sI[e]||sP[e]:n&&1===e.length?e.toUpperCase():sP[e]||e}(e,{ctrl:t.ctrl||ev,alt:t.alt||ek,shift:t.shift||eC})},[ev,ek,eC]);(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)(()=>{a&&a(!0)},[ef]),(0,r.useEffect)(()=>{if(i)return i({openTextPanel:()=>{setTimeout(()=>L.current?.focus(),100)},focus:()=>{L.current?.focus({preventScroll:!0})}}),()=>i(null)},[i]);let eM=(0,r.useCallback)(()=>{E(!0),setTimeout(()=>B.current?.focus(),100)},[]);if((0,r.useEffect)(()=>{if(!C||!s||!l||!(ev||ew||ek||eC))return;let e=async e=>{if(!ev&&!ew&&!ek&&!eC||["Control","Alt","Shift","Meta"].includes(e.key))return;e.preventDefault(),e.stopPropagation();let t=e.key;if((ev||ew)&&"v"===t.toLowerCase()){eM(),ey(!1),ej(!1),eN(!1),eS(!1);return}"Backspace"===t?t="Backspace":"Enter"===t?t="Enter":"Tab"===t?t="Tab":"Escape"===t?t="Escape":"Delete"===t?t="Delete":t.startsWith("Arrow")?t=e.key:t.startsWith("F")&&t.length<=3&&(t=e.key);let n=eR(t,{ctrl:ev,alt:ek,shift:eC,meta:ew});c?.(l),s.emit("input",{sessionId:l,data:n}),ey(!1),ej(!1),eN(!1),eS(!1)};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[C,s,l,ev,ew,ek,eC,eR,eM]),!C&&!ef||!s||!l)return null;let e$=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,ed.e)();let n=t.ctrl||ev,r=t.meta||ew;if((n||r)&&"v"===e.toLowerCase()){eM(),ey(!1),ej(!1),eN(!1),eS(!1);return}let a=eR(e,t);c?.(l),s.emit("input",{sessionId:l,data:a}),"Ctrl"!==e&&"Meta"!==e&&"Alt"!==e&&"Shift"!==e&&(ey(!1),ej(!1),eN(!1),eS(!1))},ez=async()=>{if(F.current)return;if(F.current=!0,(0,ed.e)(15),eh.listening&&eh.stop(),!s||!l){F.current=!1;return}let e=document.activeElement===L.current;e&&L.current?.blur();let t=L.current?.value??j;L.current&&(L.current.value=""),N(""),_(!1),K.current=-1;let n=A(t);c?.(l),en.length&&ea([]);let r=[];for(let e of en)await ec(e)||r.push(e),await new Promise(e=>setTimeout(e,eg.am));r.length&&(ea(e=>[...r,...e]),_(!0)),""===n?en.length||s.emit("input",{sessionId:l,data:"\r"}):(et.current?.hostCaps?.inputAck?sz((e,t)=>s.emit("input",e,t),{sessionId:l,data:n},4e3,()=>{let e=L.current;e&&!e.value&&n&&(e.value=n,N(n)),_(!0)},setTimeout,clearTimeout,()=>{_(!1);let e=L.current;e&&n&&e.value===n&&(e.value="",N(""))}):s.emit("input",{sessionId:l,data:n}),setTimeout(()=>s.emit("input",{sessionId:l,data:"\r"}),eg.YS),P(n)),e&&L.current?.focus(),setTimeout(()=>{F.current=!1},150)},eP=eg._C.base,eA=`${eP} ${eg._C.normal}`,eI=`${eP} ${eg._C.arrow}`,eD=function(e,t){let s,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],l=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a="modifier"===e.type&&("ctrl"===(s=e.id)&&ev||"meta"===s&&ew||"opt"===s&&ek||"shift"===s&&eC)?`${eP} ${eg._C.modifierActive}`:l?`${eP} ${eg._C.pinned}`:"arrow"===e.type?eI:eA,i="ctrl"===e.type?"text-brand-400":"",o=e.label.length>1?eg._C.textSmall:eg._C.textNormal,c=r?eg._C.sizeLarge:eg._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?ey(!ev):"Meta"===t?ej(!ew):"Alt"===t||"Opt"===t?eN(!ek):"Shift"===t&&eS(!eC)}else"ctrl"===e.type?e$(e.key,{ctrl:!0}):e$(e.key)},className:`${a} ${i} ${o} whitespace-nowrap`,style:c,children:e.label},e.id+t)},eL=!!x&&!g&&!y&&!ef;return(0,n.jsxs)("div",{className:"flex flex-col w-full",children:[T&&(0,se.createPortal)((0,n.jsx)("div",{className:"modal-overlay z-[60] scrim",onClick:()=>E(!1),children:(0,n.jsx)("input",{ref:B,placeholder:h("mobileKeyboard.pasteHere"),onPaste:e=>{e.preventDefault();let t=e.clipboardData?.getData("text");t&&s&&(c?.(l),(0,ed.e)(),et.current?.hostCaps?.inputAck?sz((e,t)=>s.emit("input",e,t),{sessionId:l,data:t},4e3,()=>{E(!0),requestAnimationFrame(()=>{let e=B.current;e&&(e.value=t,e.focus())})}):s.emit("input",{sessionId:l,data:t})),E(!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"})}),document.body),(0,n.jsx)("div",{className:`transition-all duration-300 overflow-hidden bg-bg ${g&&!ef?"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:eE.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=eg.y.find(t=>t.id===e);return n?eD(n,100*t+s,!0):null})}),0===t&&(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),M(!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:h("remote.customizeKeys"),children:(0,n.jsx)(el.wB,{size:16})})]},t))})})}),eL&&x,(0,n.jsxs)("div",{className:"relative transition-all duration-300 overflow-visible opacity-100 flex-shrink-0",children:[(0,n.jsx)(sH,{voice:eh,className:`absolute left-1/2 -translate-x-1/2 z-30 ${eL?"bottom-[calc(100%+36px)]":"bottom-[calc(100%+18px)]"}`}),(0,n.jsxs)("div",{className:p?"flex w-full items-stretch":`${eL?"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 ${p?"rounded-none border-0 border-r":"rounded-xl border"}`,children:[O&&(0,n.jsx)("div",{className:"px-2 pt-1 text-[10px] text-danger truncate",children:h("common.inputNotSent")}),(0,n.jsx)(sF,{items:H,activeIndex:Z,onSelect:e=>{N(e),L.current?.focus()}}),(0,n.jsx)(sx,{value:j,store:sr,commonCommands:eg.dt,isMobile:C,disabled:H.length>0,activeIndex:Q,onSelect:e=>{N(e),L.current?.focus()}}),en.length>0&&(0,n.jsx)("div",{className:"flex gap-2 px-2 pt-2 overflow-x-auto scroll-thin-x",children:en.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:()=>eo(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:em,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,m?.(!0)},onBlur:()=>m?.(!1),onPaste:ex,onKeyDown:e=>{if(ef&&"Tab"===e.key){if(!e.ctrlKey&&!e.altKey&&!e.metaKey){if(H.length>0){e.preventDefault();let t=e.shiftKey?-1:1;X(e=>H.length?((e+t)%H.length+H.length)%H.length:-1);return}if(J.length>0){e.preventDefault();let t=e.shiftKey?-1:1;G(e=>J.length?((e+t)%J.length+J.length)%J.length:-1);return}}e.preventDefault();let t=eR("Tab",{ctrl:e.ctrlKey,alt:e.altKey,shift:e.shiftKey,meta:e.metaKey});c?.(l),s.emit("input",{sessionId:l,data:t});return}let t=/^Digit([1-9])$/.exec(e.code)||/^[1-9]$/.exec(e.key);if(ef&&(tp()?e.altKey&&!e.ctrlKey&&!e.metaKey:e.ctrlKey||e.metaKey)&&t){e.preventDefault(),u?.(Number(t[1])-1);return}if(ef&&"Enter"===e.key&&!e.shiftKey){if(e.nativeEvent?.isComposing||e.isComposing||229===e.keyCode)return;if(H.length>0&&Z>=0){e.preventDefault(),N(H[Z].full),X(-1),L.current?.focus();return}if(J.length>0&&Q>=0){e.preventDefault(),N(J[Q].cmd),G(-1),L.current?.focus();return}e.preventDefault(),ez();return}if(ef&&("ArrowUp"===e.key||"ArrowDown"===e.key)&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&!j){e.preventDefault(),c?.(l),s.emit("input",{sessionId:l,data:"ArrowUp"===e.key?"\x1b[A":"\x1b[B"});return}let n=eg.EE[e.key];if(n&&(!n.ctrl||e.ctrlKey)&&!e.metaKey&&!e.altKey){let t=e.target;if(n.requireNoSelection&&t.selectionStart!==t.selectionEnd)return;e.preventDefault(),c?.(l),s.emit("input",{sessionId:l,data:n.data})}},placeholder:ef?tp()?"Opt ←/→ \xb7 Opt 1…9 to switch tab":"Ctrl+Shift+←/→ \xb7 1…9 to switch tab":h("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:h("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:()=>z(!0),title:h("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})}),eh.active&&(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{eh.listening?eh.stop():(document.activeElement?.blur(),eh.start(j))},title:"not-allowed"===eh.error||"service-not-allowed"===eh.error?h("voice.denied"):h("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 ${eh.listening?"bg-red-500/90 text-white animate-pulse":eh.error?"text-red-400":"text-text-muted hover:text-text"}`,children:eh.listening?(0,n.jsx)(el.jj,{size:16}):(0,n.jsx)(el.GO,{size:16})})]}),(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:ez,disabled:!1,className:p?"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()||en.length?h("mobileKeyboard.send"):(0,n.jsx)(el.Lt,{size:16,strokeWidth:2.5})})]})]}),!ef&&(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:eT.keys.filter(e=>e.id!==eg.g$).map((e,t)=>eD(e,t))}),(t=eg.y.find(e=>e.id===eg.g$))?(0,n.jsx)("div",{className:"flex-shrink-0",children:eD(t,"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(),a&&setTimeout(()=>a(e),320)},className:`${eP} ${g?eg._C.modifierActive:eg._C.pinned} flex-shrink-0`,style:eg._C.size,title:h("mobileKeyboard.toggleExtraKeys"),children:g?(0,n.jsx)(el.X,{size:16}):(0,n.jsx)(el.a4,{size:16})})]})}),(0,n.jsx)(sM,{isOpen:R,onClose:()=>M(!1),title:h("mobileKeyboard.customizeTerminalKeys"),tabs:[{id:"basic",label:h("mobileKeyboard.mainBar"),hook:eT,excludeIds:[eg.g$]},{id:"extra",label:h("mobileKeyboard.extraPanel"),hook:eE}]}),(0,n.jsx)(so,{isOpen:$,onSelect:e=>{N(e),L.current?.focus()},onClose:()=>z(!1)})]})}),s9={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"}},s7=e=>s9[e]||s9.idle,ne=e=>{let t=s7(e);return`term-dot ${t.cls}${t.pulse?` pulse-${t.pulse}`:""}`},nt=["blocked","working","done"],ns=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return nt.map(t=>{let s=e.filter(e=>e===t).length;return s?{state:t,count:s}:null}).filter(Boolean)},nn={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"},nr=new Proxy({},{get:(e,t)=>"string"==typeof t&&t&&e8(t)||void 0}),nl=tc.find(e=>"attentionNext"===e.id);function na(e){let{sessions:t=[],allSessions:s=[],sessionStatus:l,onSwitchSession:a,workspaces:i=[]}=e,{t:o}=(0,eu.s)(),[c,d]=(0,r.useState)(!1),u=(0,r.useRef)(null),m=eI(),x=l||m,p=eB(x,s).filter(e=>"blocked"===e.state||"done"===e.state),{total:h}=eF(x,s),f=e=>s.find(t=>t.id===e)?.name||t.find(t=>t.id===e)?.name||e.slice(0,8),b=e=>s.find(t=>t.id===e)?.workspaceId??null,g=new Map(s.map((e,t)=>[e.id,t])),v=(()=>{let e=new Map;for(let t of p){let s=b(t.id);e.has(s)||e.set(s,[]),e.get(s).push(t)}let t=e=>[...e].sort((e,t)=>(g.has(e.id)?g.get(e.id):Number.MAX_SAFE_INTEGER)-(g.has(t.id)?g.get(t.id):Number.MAX_SAFE_INTEGER)),s=[];for(let n of i){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:o("workspaces.unassigned"),items:t(n)}),s})();(0,r.useEffect)(()=>{if(!c)return;let e=e=>{u.current&&!u.current.contains(e.target)&&d(!1)},t=e=>{"Escape"===e.key&&d(!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)}},[c]);let y=(0,r.useRef)(null),w=()=>{y.current&&(clearTimeout(y.current),y.current=null)};return(0,r.useEffect)(()=>()=>w(),[]),(0,n.jsxs)("div",{ref:u,className:"relative hidden sm:flex flex-shrink-0",onMouseEnter:()=>{w(),d(!0)},onMouseLeave:()=>{w(),y.current=setTimeout(()=>d(!1),150)},children:[(0,n.jsxs)("button",{onClick:()=>d(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:o("notifications.title"),children:[(0,n.jsx)(el.Ir,{size:16}),h>0&&(0,n.jsx)("span",{className:"badge-pop 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:h>9?"9+":h},h)]}),c&&(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 pop-in",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:o("notifications.title")}),(0,n.jsx)("button",{onClick:()=>d(!1),className:"p-1 text-text-muted hover:text-text rounded transition-colors",title:o("common.close"),children:(0,n.jsx)(el.X,{size:14})})]}),p.length?(0,n.jsx)("div",{className:"flex flex-col",children:v.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=s7(e.state),s=o(t.label);return(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.id,void(d(!1),a?.(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}}),nr[e.tool]?(0,n.jsx)("img",{src:nr[e.tool],alt:e.tool,draggable:!1,className:`w-5 h-5 flex-shrink-0 ${e6}`}):(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:[nn[e.tool]||o("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:o("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:[tg(nl).map(e=>(0,n.jsx)("kbd",{className:tf,children:e},e)),(0,n.jsx)("span",{className:"ml-1 text-[11px] text-text-muted",children:nl.label})]})]})})]})}function ni(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 no(e){let{sessionStatus:t,allSessions:s=[],onSwitchSession:r}=e,{t:l}=(0,eu.s)(),a=eI(),i=t||a,{blocked:o,done:c,total:d}=eF(i,s),u=ni(i,s,r);if(!d)return null;let m=[{key:"blocked",count:o,state:"blocked"},{key:"done",count:c,state:"done"}].filter(e=>e.count>0);return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u()},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:l("notifications.badgeTitle",{blocked:o,done:c}),children:m.map(e=>{let{key:t,count:s,state:r}=e,l=s7(r);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 ${l.cls}${l.pulse?` pulse-${l.pulse}`:""}`,style:{background:l.dot}}),(0,n.jsx)("span",{className:"text-xs font-semibold tabular-nums",children:s>9?"9+":s})]},t)})})}let nc=(0,b.v)((0,st.Zr)((e,t)=>({tabsByWorkspace:{},activeByWorkspace:{},agentTabs:[],setAgentTabs:t=>e({agentTabs:Array.isArray(t)?t:[]}),workspaceProfiles:{},workspaceWindows:{},viewportByWorkspace:{},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},tabsByWorkspace:{...e.tabsByWorkspace,[t||"default"]:[]},activeByWorkspace:{...e.activeByWorkspace,[t||"default"]:null}})),setWindowFor:(t,s)=>e(e=>({workspaceWindows:{...e.workspaceWindows,[t||"default"]:s||null}})),setViewportFor:(t,s)=>e(e=>({viewportByWorkspace:{...e.viewportByWorkspace,[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,viewportByWorkspace:e.viewportByWorkspace}),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{}}}}));var nd=s(13889);function nu(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 nm(e){return e?.path?e.path:e?.items?.find(e=>e.workspacePath)?.workspacePath||null}function nx(e,t){if(!e)return"";let s=e.slice(0,e.lastIndexOf("/"))||"/",n=t.replace(/[^\w.-]+/g,"-");return`${s}/${e.split("/").pop()}-${n}`}function np(e){let{workspacePath:t,workspaceName:s,fileBus:l,homeDir:a,value:i,onChange:o,onBrowse:c,staged:d=null}=e,{t:u}=(0,eu.s)(),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(null),[f,b]=(0,r.useState)(!1),g=(0,r.useRef)(null),v=(0,r.useCallback)(async()=>{if(!t||!l?.gitScanRepos)return h([]);b(!0);let e=await l.gitScanRepos(t),n=e?.success&&e.repos||[],r=await Promise.all(n.map(async e=>{let t=await l.gitWorktreeList?.(e.path),s=t?.success&&t.worktrees||[],n=s.length?s.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:n}}));r.some(e=>e.isRoot)||r.unshift({repoPath:t,name:s||u("terminal.workspaceRoot"),isRoot:!0,isRepo:!1,entries:[{path:t,branch:null,detached:!1}]}),h(r),b(!1)},[t,s,l,u]);(0,r.useEffect)(()=>{if(!m)return;let e=e=>{g.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)}},[m]);let y=(p?.length||0)>1,w=i?(p||[]).flatMap(e=>e.entries).find(e=>e.path===i):null,j=d?.branch||w?.branch||(i||t||"").split("/").filter(Boolean).pop()||s||u("terminal.workspaceRoot"),k=d?`${u("workspaces.newWorktree")} \xb7 ${nu(d.path,a)}`:"Pick a branch or worktree";return(0,n.jsxs)("div",{ref:g,className:"relative",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),null===p&&v(),x(e=>!e)},"aria-haspopup":"listbox","aria-expanded":m,title:d?.path||i||t||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:[d?(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:j}),(0,n.jsx)("span",{className:"text-[10px] text-text-subtle truncate leading-tight",title:d?.path,children:k})]}),(0,n.jsx)(el.yQ,{size:14,className:`text-text-muted shrink-0 transition-transform ${m?"rotate-180":""}`})]}),m&&(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&&p?.map(e=>(0,n.jsxs)("div",{children:[y&&(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=i===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)(),o?.(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?u("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))]}),c&&(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),c()},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:u("terminal.browseFolders")})]})})]})]})}function nh(e){let{size:t=14,className:s=""}=e;return(0,n.jsx)("span",{style:{width:t,height:t},className:`flex items-center justify-center rounded-[3px] bg-neutral-800 shrink-0 ${s}`,children:(0,n.jsx)(el.BK,{size:.85*t,className:"text-white"})})}function nf(e){let{agent:t=null,tool:s=null}=e,r="string"==typeof t?t:t?.id||null;return r?.endsWith("-ui")?(0,n.jsx)("img",{src:e8(r),alt:"",draggable:!1,className:`w-3.5 h-3.5 flex-shrink-0 object-contain ${e6}`}):nr[s]?(0,n.jsx)("img",{src:nr[s],alt:s,draggable:!1,className:`w-3.5 h-3.5 flex-shrink-0 object-contain ${e6}`}):(0,n.jsx)(nh,{size:14})}function nb(e,t){let{fireOnReturn:s=!0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},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 ng=new Map,nv=(e,t)=>e?`${e}|${t}`:t,ny=/[.*+?^${}()|[\]\\]/g;function nw(e){let{isOpen:t,onClose:s,busRef:l,cwd:a,scope:i="",onResume:o,onSelectSession:c,liveSessionIds:d,activeSessionId:u,connected:m=!0}=e,{t:x}=(0,eu.s)(),[p,h]=(0,r.useState)(""),[b,g]=(0,r.useState)("all"),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)([]),[k,N]=(0,r.useState)(""),[C,S]=(0,r.useState)(!1),[T,E]=(0,r.useState)(!1),R=i?`${i}|${a}`:a,M=(0,f.B)(e=>a?e.agentHistory[R]?.sessions:null),$=(0,r.useMemo)(()=>M||[],[M]),z=t&&m&&p.trim().length>=3;(0,r.useEffect)(()=>{if(!z)return;let e=p.trim(),t=!1,s=setTimeout(()=>{S(!0),l?.current?.emit("searchAgentSessions",{query:e},s=>{t||(S(!1),E(!!s?.truncated),j(Array.isArray(s?.sessions)?s.sessions:[]),N(e))})},350);return()=>{t=!0,clearTimeout(s)}},[p,z,l]),(0,r.useEffect)(()=>{if(!t)return;document.activeElement?.blur?.();let e=e=>{"Escape"!==e.key||v||s()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,s,v]);let P=(0,r.useMemo)(()=>{let e=new Set;for(let t of $)t.agent&&e.add(t.agent);return Array.from(e)},[$]),A=(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)},I=(0,r.useMemo)(()=>{let e=p.trim().toLowerCase(),t=[],s=new Set,n=new Map;for(let e of z?w:[])e.snippet&&n.set(`${e.agent}:${e.sessionId}`,e.snippet);for(let r of $)if(("all"===b||r.agent===b)&&(!e||A(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?w:[])s.has(`${e.agent}:${e.sessionId}`)||("all"===b||e.agent===b)&&t.push({...e,foreign:!0});return t.sort((e,t)=>(t.updatedAt||0)-(e.updatedAt||0))},[$,w,z,p,b]);return t?"u"<typeof document?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[60]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in touch-none",onClick:s}),(0,n.jsxs)("div",{className:"relative card-elev max-w-xl w-full my-auto flex flex-col pop-in 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:s,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:p,onChange:e=>h(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"}),p&&(0,n.jsx)("button",{onClick:()=>h(""),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&&(C?x("agentHistory.searchingAll"):T?x("agentHistory.searchTruncated"):null)}),P.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:()=>g("all"),className:`shrink-0 h-7 px-3.5 text-xs rounded-brand transition-colors whitespace-nowrap flex items-center justify-center ${"all"===b?"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")}),P.map(e=>(0,n.jsxs)("button",{onClick:()=>g(e),className:`shrink-0 h-7 px-3.5 text-xs rounded-brand transition-colors flex items-center gap-2 whitespace-nowrap capitalize ${b===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:e8(e),alt:"",className:`w-3.5 h-3.5 ${e6}`}),(0,n.jsx)("span",{children:e})]},e))]})]}),(0,n.jsx)("div",{className:"flex-1 basis-[45vh] min-h-0 overflow-y-auto modal-scrollable p-2 space-y-1",children:0===I.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:p?x("agentHistory.noResults"):x("agentHistory.empty")})]}):I.map(e=>{var t,r;let l=e.openSessionId&&d?.has(e.openSessionId)?e.openSessionId:null,i=e.title||x("agentHistory.untitled"),u=!!e.foreign;return(0,n.jsxs)("div",{onClick:()=>{(0,ed.e)(),l?c?.(l):o?.(e),s()},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:e8(e.agent),alt:e.agent,className:`w-5 h-5 flex-shrink-0 object-contain ${e6} ${l?"":"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 ${l?"text-text font-medium":"text-text-muted"}`,children:i}),l&&(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:(t=e.snippet,k?String(t).split(RegExp(`(${k.replace(ny,"\\$&")})`,"gi")).map((e,t)=>e.toLowerCase()===k.toLowerCase()?(0,n.jsx)("mark",{className:"bg-transparent text-text font-semibold px-0",children:e},t):e):t)}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mt-0.5 text-[11px] text-text-subtle min-w-0",children:[u&&e.cwd&&e.cwd!==a&&(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(),y(e)},disabled:!m||!!l||!!u,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 ${l||u?"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}`)})})]}),v&&(0,n.jsx)(ec.A,{isOpen:!0,onClose:()=>y(null),onConfirm:()=>{if(!v)return;let{agent:e,sessionId:t}=v;(0,ed.e)();let s=$.filter(s=>s.agent!==e||s.sessionId!==t);f.B.getState().setAgentHistory(R,s),l?.current?.emit("deleteAgentSession",{agent:e,sessionId:t,cwd:a},e=>{e?.success||l?.current?.emit("getAgentSessions",{cwd:a},e=>{Array.isArray(e?.sessions)&&f.B.getState().setAgentHistory(R,e.sessions)})}),y(null)},title:x("agentHistory.deleteTitle"),message:x("agentHistory.deleteMessage",{title:v.title||x("agentHistory.untitled")})})]}),document.body):null}function nj(e){let{busRef:t,scope:s="",cwd:l,onResume:a,onSelectSession:i,liveSessionIds:o,activeSessionId:c,connected:d=!0,variant:u="section"}=e,{t:m}=(0,eu.s)(),[x,p]=(0,r.useState)(!1),[h,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(null),y=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=t?nv(s,t):null,l=(0,f.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=nv(t,s),r=ng.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)&&f.B.getState().setAgentHistory(n,e.sessions)}))},o=nb(i,eg.fw),c={count:1,fetchNow:i,stop:()=>{clearTimeout(a),o()}};return ng.set(n,c),c}(e,s,t),r=f.B.getState().agentHistory[nv(s,t)];return(!r||Date.now()-r.at>=eg.fw)&&n.fetchNow(),()=>{let e;!(e=ng.get(nv(s,t)))||(e.count-=1,!(e.count>0)&&(e.stop(),ng.delete(nv(s,t))))}},[e,t,s,a]),l?.sessions||null}(t,l,s),w=s?`${s}|${l}`:l,j="list"===u;(0,r.useEffect)(()=>{if(j||!l)return;let e=e=>{let t=e.target?.tagName;"INPUT"===t||"TEXTAREA"===t||e.target?.isContentEditable||(tp()?!e.altKey||e.ctrlKey||e.metaKey:!e.ctrlKey||e.metaKey||e.altKey)||"h"!==e.key.toLowerCase()||(e.preventDefault(),b(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j,l]);let k=h&&(0,n.jsx)(nw,{isOpen:h,onClose:()=>b(!1),busRef:t,cwd:l,scope:s,onResume:a,onSelectSession:i,liveSessionIds:o,activeSessionId:c,connected:d});if(!l)return null;if(!y?.length)return j?(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:m("agentHistory.empty")}),k]}):k;let N=j?y:y.slice(0,40),C=!j&&y.length>40;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:j?"flex-1 min-h-0 flex flex-col":"flex-shrink-0 border-t border-border-subtle pt-1 flex flex-col",style:j?void 0:{maxHeight:x?void 0:eg.i5},children:[!j&&(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)(),p(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:m("agentHistory.title")}),(0,n.jsxs)("span",{className:"ml-1 text-[10px] tabular-nums opacity-60",children:["(",y.length,")"]})]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),b(!0)},className:"p-1 hover:text-text hover:bg-surface-2 rounded transition-colors text-text-subtle",title:m("agentHistory.manageHistory"),"aria-label":m("agentHistory.manageHistory"),children:(0,n.jsx)(el.Gr,{size:12})})]}),(j||!x)&&(0,n.jsxs)("div",{className:`overflow-y-auto modal-scrollable min-h-0 ${j?"flex-1 px-1.5 pb-2":""}`,children:[N.map(e=>{let t=e.openSessionId&&o?.has(e.openSessionId)?e.openSessionId:null,s=!!t&&t===c,r=e.title||m("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 ${j?"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?i?.(t):a?.(e)},disabled:!d,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 ${j?"gap-2.5":""} ${t?"text-text font-medium":"text-text-muted"}`,title:`${r} \xb7 ${e.agent}${t?` \xb7 ${m("agentHistory.openNow")}`:""}`,children:[(0,n.jsx)("img",{src:e8("ui"===e.mode?`${e.agent}-ui`:e.agent),alt:e.agent,className:`flex-shrink-0 ${e6} ${j?"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 ${j?"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 ${j?"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,m)})]}),j?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},disabled:!d||!!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?m("agentHistory.openNow"):m("agentHistory.delete"),"aria-label":m("agentHistory.delete"),children:(0,n.jsx)(el.TB,{size:14})}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},disabled:!d||!!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?m("agentHistory.openNow"):m("agentHistory.delete"),"aria-label":m("agentHistory.delete"),children:(0,n.jsx)(el.TB,{size:13})})]},`${e.agent}:${e.sessionId}`)}),C&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),b(!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:[m("agentHistory.showAll")," (",y.length,")"]})]})]})]}),k,g&&(0,n.jsx)(ec.A,{isOpen:!0,onClose:()=>v(null),onConfirm:()=>{if(!g)return;let{agent:e,sessionId:s}=g;(0,ed.e)();let n=(y||[]).filter(t=>t.agent!==e||t.sessionId!==s);f.B.getState().setAgentHistory(w,n),t?.current?.emit("deleteAgentSession",{agent:e,sessionId:s,cwd:l},e=>{e?.success||t?.current?.emit("getAgentSessions",{cwd:l},e=>{Array.isArray(e?.sessions)&&f.B.getState().setAgentHistory(w,e.sessions)})}),v(null)},title:m("agentHistory.deleteTitle"),message:m("agentHistory.deleteMessage",{title:g.title||m("agentHistory.untitled")})})]})}function nk(e){let{title:t,value:s,onChange:l,onSubmit:a,onClose:i,confirmLabel:o,cancelLabel:c,placeholder:d,hideCancel:u=!1}=e,{t:m}=(0,eu.s)();return((0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),i?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[i]),"u"<typeof document)?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[100]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:i}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:"relative card-elev w-full max-w-xs p-5 my-auto overflow-y-auto pop-in",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:t}),(0,n.jsx)("button",{onClick:i,"aria-label":m("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:s,placeholder:d,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a(),"Escape"===e.key&&i()},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:a,disabled:!s?.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:o??m("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})})]}),!u&&(0,n.jsxs)("button",{onClick:i,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:c??m("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 nN=new Map,nC=(e,t)=>{nN.set(e,null==t?null:(0,_.kb)(t))},nS=/^[A-Za-z]:\/?$/,nT=/^[A-Za-z]:\//,nE=e=>{if(!e||"/"===e||nS.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},nR=e=>e&&"/"!==e?e.split("/").filter(Boolean).pop()??null:null,nM=e=>{let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return -1===t?"":e.slice(0,t+1)},n$=(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 nz(e,t){let s=t.trim().toLowerCase();return s?e.filter(e=>e.name.toLowerCase().includes(s)):e}let nP=e=>e.includes("/")||e.includes("\\")||/^[A-Za-z]:$/.test(e)||"~"===e||"."===e||".."===e;function nA(e){let t,s,n;if(!nP(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(nT.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 nI(e){let{fileBus:t,initialPath:s,scope:l="",onSelect:a,onClose:i}=e,{t:o}=(0,eu.s)(),[c]=(0,r.useState)(()=>s||nN.get(l)||null||null),[d,u]=(0,r.useState)(c),[m,x]=(0,r.useState)([]),[p,h]=(0,r.useState)(!!c),[f,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(""),[y,w]=(0,r.useState)(0),[j,k]=(0,r.useState)(null),[N,C]=(0,r.useState)(null),[S]=(0,r.useState)(()=>eh(l)),T=(0,r.useRef)(null),E=(0,r.useRef)(!1),R=(0,r.useRef)(0),M=(0,r.useRef)(0),$=(0,r.useRef)(null),z=(0,r.useRef)(null),P=(0,r.useRef)(null),A=(0,r.useRef)(null),I=(0,r.useRef)(null),D=(0,r.useRef)(new Map),L=(0,r.useRef)(null),B=(0,r.useRef)(""),F=(0,r.useRef)(!1),O=(0,r.useCallback)(async e=>{let s=D.current.get(e);if(s)return s;let n=await t.getFiles(e,!1);if(!n?.success)throw Error(n?.error||o("workspaces.pathNotFolder"));let r={resolvedPath:(0,_.kb)(n.currentPath)||e,entries:(n.files||[]).filter(e=>"folder"===e.type)};return D.current.set(r.resolvedPath,r),e!==r.resolvedPath&&D.current.set(e,r),r},[t,o]),K=(0,r.useCallback)(async e=>{if(null==e){R.current++,u(null),x([]),h(!1),b(null);return}let t=++R.current;h(!0),b(null);try{let s=await O(e);if(t!==R.current)return;u(s.resolvedPath),x(s.entries),"~"===e&&(L.current=s.resolvedPath)}catch(e){if(t!==R.current)return;b(e.message||String(e)),x([])}finally{t===R.current&&h(!1)}},[O]);(0,r.useEffect)(()=>{if(!c)return;let e=setTimeout(()=>void K(c),0);return()=>clearTimeout(e)},[c,K]),(0,r.useEffect)(()=>{let e=!1;return t?.getSystemInfo?.().then(t=>{if(e||!t?.success)return;C(t);let s=(0,_.kb)(t.homedir);s&&(L.current=s,c||F.current||(F.current=!0,K(s)))}),()=>{e=!0}},[t,c,K]);let W=(0,r.useCallback)(e=>{(0,ed.e)(),nC(l,e),v(""),k(null),w(0),M.current++,B.current="",$.current&&(clearTimeout($.current),$.current=null),K(e)},[K,l]),H=(0,r.useCallback)(()=>{d&&W(nE(d))},[d,W]),q=(0,r.useCallback)(async e=>{let t,s=nA(e);if("path"!==s.mode)return;let n=++M.current;if(s.invalid)return void k({resolvedPath:d??"/",entries:[],filter:"",error:o("workspaces.invalidPath"),loading:!1});if("root"===s.base)t="/";else if("drive"===s.base)t=s.driveRoot;else if("home"===s.base){if(!L.current){k({resolvedPath:d??"/",entries:[],filter:"",error:null,loading:!0});try{let e=await O("~");if(n!==M.current)return;L.current=e.resolvedPath}catch(e){if(n!==M.current)return;k({resolvedPath:d??"/",entries:[],filter:"",error:e.message,loading:!1});return}}t=L.current}else t=d||"/";k(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 O(r);if(n!==M.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=nu(r,N?.homedir);k({resolvedPath:r,entries:t.entries,filter:"",error:s.multiple?o("workspaces.multipleDirMatches",{name:e,dir:n}):o("workspaces.notADirectory",{name:e,dir:n}),loading:!1});return}if("stay"===s.type){s.up&&(r=nE(r)||"/");continue}r=s.path}let t=await O(r);if(n!==M.current)return;B.current=nM(e),k({resolvedPath:t.resolvedPath,entries:t.entries,filter:s.trailingFilter,error:null,loading:!1})}catch(e){if(n!==M.current)return;k({resolvedPath:r,entries:[],filter:"",error:e.message,loading:!1})}},[d,O,N,o]),U=(0,r.useCallback)(e=>{if(v(e),w(0),e.length>2048||!nP(e)){j&&(k(null),M.current++),$.current&&(clearTimeout($.current),$.current=null);return}let t=nA(e);"path"!==t.mode||!j||j.error||t.invalid||nM(e)!==B.current?($.current&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null,q(e)},300)):k({...j,filter:t.trailingFilter})},[j,q]);(0,r.useEffect)(()=>()=>{for(let e of(R.current++,M.current++,[$,z,P]))e.current&&clearTimeout(e.current),e.current=null},[]);let X=(0,r.useMemo)(()=>nz(m,g),[m,g]),V=(0,r.useMemo)(()=>j?nz(j.entries,j.filter):[],[j]),G=j?V:X;(0,r.useEffect)(()=>{E.current=window.matchMedia("(min-width: 640px)").matches,E.current&&T.current?.focus()},[]),(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||g||i()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[g,i]);let[J,Y]=(0,r.useState)(null),Z=(0,r.useCallback)(async e=>{let s=(e||"").trim().replace(/[\\/:*?"<>|]/g,"");if(!s||!d)return;let n=N?.isWindows?"\\":"/",r=`${d.replace(/[\\/]+$/,"")}${n}${s}`,l=await t.createItem(r,"folder");l?.success&&(D.current.delete(d),Y(null),K(r))},[d,t,N,K]),Q=(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)}})(d),[d]);(0,r.useEffect)(()=>{A.current&&(A.current.scrollLeft=A.current.scrollWidth)},[d]);let ee=nR(d),et=N?(0,_.kb)(N.homedir):null,es=!!N?.isWindows,en=p||!!j&&""!==g;return"u"<typeof document?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[80] scrim fade-in",onClick:i,children:[(0,n.jsxs)("div",{ref:I,role:"dialog","aria-modal":"true","aria-label":o("workspaces.newWorkspace"),onKeyDown:e=>{if("Tab"!==e.key)return;let t=I.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] flex flex-col overflow-hidden pop-in",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:o("workspaces.newWorkspace")}),(0,n.jsx)("button",{onClick:i,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:H,disabled:p||!d||"/"===d,className:"shrink-0 p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] disabled:opacity-30 transition-colors",title:o("workspaces.parentFolder"),children:(0,n.jsx)(el.Do,{size:14})}),(0,n.jsx)("button",{onClick:()=>W(et||"/"),disabled:p,className:"shrink-0 p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-[3px] transition-colors",title:o("workspaces.homeFolder"),children:(0,n.jsx)(el.ww,{size:14})}),(0,n.jsxs)("div",{ref:A,className:"flex-1 flex items-center gap-0 text-[11px] text-text-muted ml-1 min-w-0 overflow-x-auto scrollbar-none",children:[es?(0,n.jsx)("button",{type:"button",onClick:()=>W(null),className:"shrink-0 px-0.5 hover:text-text transition-colors",title:o("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"===Q.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(Q.driveRoot),className:`truncate max-w-[120px] px-0.5 hover:text-text transition-colors ${0===Q.segments.length?"text-text font-medium":""}`,children:Q.driveRoot.replace(/\/$/,"")})]}),Q.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(n$(Q,t)),className:`truncate max-w-[120px] px-0.5 hover:text-text transition-colors ${t===Q.segments.length-1?"text-text font-medium":""}`,children:e})]},n$(Q,t)))]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),Y({value:""})},disabled:p||!d,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:o("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:T,value:g,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=T.current?.value??"";e.length<=2048&&nP(e)&&q(e)},0))},onKeyDown:e=>{if("Enter"===e.key){if(j){if(j.error||j.loading)return void e.preventDefault();let t=nA(g);if("path"===t.mode&&""===t.trailingFilter){e.preventDefault(),W(j.resolvedPath);return}return void(1===V.length?(e.preventDefault(),W(V[0].path)):e.preventDefault())}let t=1===X.length?X[0]:X[y];return void(t&&(e.preventDefault(),W(t.path)))}"ArrowDown"===e.key?(e.preventDefault(),w(e=>Math.min(e+1,Math.max(G.length-1,0)))):"ArrowUp"===e.key?(e.preventDefault(),w(e=>Math.max(e-1,0))):"Escape"===e.key&&g?(e.stopPropagation(),v(""),k(null),M.current++,$.current&&(clearTimeout($.current),$.current=null)):"Backspace"!==e.key||""!==g||j||(e.preventDefault(),H())},placeholder:o("workspaces.filterOrPath"),"aria-invalid":!!j?.error,className:"flex-1 min-w-0 bg-transparent text-sm text-text outline-none placeholder:text-text-subtle"}),j?.loading&&(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-text-subtle flex-shrink-0"}),!!g&&!j?.loading&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle tabular-nums flex-shrink-0",children:G.length})]}),j?.error&&(0,n.jsx)("p",{className:"pt-1 px-0.5 text-[11px] text-red-500",children:j.error})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[!g&&!j&&!!S.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:o("workspaces.recentFolders")}),(0,n.jsx)("div",{className:"flex gap-1.5 overflow-x-auto pb-0.5",children:S.slice(0,8).map(e=>{let t=(0,_.kb)(e.path);return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),nC(l,t),a(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:nR(t)||t}),(0,n.jsx)("span",{className:"block text-[10px] text-text-subtle truncate",children:nu(t,et)})]})]},e.path)})})]}),!g&&!j&&!d&&(0,n.jsx)("div",{className:"p-2 space-y-1",children:es?N?.drives?.map(e=>(0,n.jsx)(nD,{icon:(0,n.jsx)(el.ak,{size:15,className:"text-blue-500/70"}),label:(0,_.kb)(e.path),onClick:()=>W((0,_.kb)(e.path))},e.letter)):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(nD,{icon:(0,n.jsx)(el.ww,{size:15,className:"text-blue-500/70"}),label:et||"/",onClick:()=>W(et||"/")}),(0,n.jsx)(nD,{icon:(0,n.jsx)(el.ak,{size:15,className:"text-text-subtle"}),label:"/",onClick:()=>W("/")})]})}),p&&(0,n.jsx)("div",{className:"p-6 flex justify-center text-text-muted",children:(0,n.jsx)(el.kr,{size:18,className:"animate-spin"})}),!p&&f&&(0,n.jsx)("p",{className:"p-4 text-xs text-red-500",children:f}),!p&&!f&&(d||j)&&(0,n.jsxs)("div",{className:"p-1",children:[G.map((e,t)=>(0,n.jsxs)("button",{onClick:()=>{!j?.loading&&(P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{P.current=null,W(e.path)},220))},onDoubleClick:()=>{!j?.loading&&(P.current&&(clearTimeout(P.current),P.current=null),nC(l,e.path),a(e.path))},onMouseDown:e=>{E.current&&(e.preventDefault(),T.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 ${(g||j)&&t===y?"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)),!G.length&&(0,n.jsx)("p",{className:"px-3 py-4 text-xs text-text-subtle italic",children:(j?j.entries.length:m.length)?o("common.noResults"):o("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:j?j.resolvedPath:d||"",children:j?nu(j.resolvedPath,et):d?nu(d,et):o("workspaces.drives")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),Y({value:""})},disabled:!d,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:o("workspaces.createFolderTitle"),children:[(0,n.jsx)(el.JU,{size:14}),o("workspaces.createFolderTitle")]}),(0,n.jsx)("button",{onClick:()=>{d&&(nC(l,d),(0,ed.e)(),a(d))},disabled:!d||en,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:d||"",children:ee?o("workspaces.selectNamed",{name:ee}):o("workspaces.selectFolder")})]})]})]}),J&&(0,n.jsx)(nk,{title:o("workspaces.createFolderTitle"),confirmLabel:o("workspaces.createFolderTitle"),hideCancel:!0,placeholder:o("workspaces.newFolderName"),value:J.value,onChange:e=>Y({value:e}),onSubmit:()=>Z(J.value),onClose:()=>Y(null)})]}),document.body)}function nD(e){let{icon:t,label:s,onClick:r}=e;return(0,n.jsxs)("button",{onClick:r,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:t}),(0,n.jsx)("span",{className:"truncate",children:s})]})}let nL=["⌥","⇧","↵"],nB=["Ctrl","⇧","↵"],nF=[{id:"new",icon:el.BK,labelKey:"terminal.newTerminal"},{id:"history",icon:el.BZ,labelKey:"agentHistory.title"}];function nO(e){let{agent:t}=e,[s,l]=(0,r.useState)(!1);return t?s?(0,n.jsx)(el.cC,{size:16,className:"text-text-muted"}):(0,n.jsx)("img",{src:e8(t.id),alt:"",width:16,height:16,onError:()=>l(!0),className:`w-4 h-4 object-contain ${e6}`}):(0,n.jsx)(nh,{size:16})}function n_(e){let{onClose:t,onCreate:s,shells:l=[],suggestName:a="",busRef:i=null,workspacePath:o=null,workspaceName:c="",fileBus:d=null,homeDir:u=null,onResumeAgentSession:m=null,liveSessionIds:x=null,activeSessionId:p=null,onSelectSession:h=null,connected:b=!0,hostKey:g="main",onCreateBrowser:v,workspaceId:y=null}=e,{t:w}=(0,eu.s)(),j=eM("main"!==g?g:null),k=j.head?j.fileBus:d||j.fileBus,N=j.scope,C=tk(i,g),[S,T]=(0,r.useState)(()=>ta().agentId),[E,R]=(0,r.useState)(""),[M,$]=(0,r.useState)(null),[z,P]=(0,r.useState)(!1),[A,I]=(0,r.useState)(!1),[D,L]=(0,r.useState)(""),[B,F]=(0,r.useState)(null),[O,_]=(0,r.useState)(!1),[K,W]=(0,r.useState)(null),[H,q]=(0,r.useState)(null),U=(0,r.useRef)(null),[X,V]=(0,r.useState)(()=>ta().yolo),[G,J]=(0,r.useState)(()=>{let e=tr(tt);return e&&l.some(t=>t.id===e)?e:l[0]?.id||""}),[Y,Z]=(0,r.useState)("new"),Q=(0,r.useRef)(null),ee=(0,r.useRef)(null),et=(0,r.useRef)(!1);(0,r.useEffect)(()=>{window.matchMedia("(pointer: fine)").matches&&requestAnimationFrame(()=>Q.current?.focus())},[]);let es=tp()?nL:nB,en=(0,nd.A)(D.trim()).replace(/[^\w.-]+/g,"-").replace(/^-+|-+$/g,""),er=M||B||o,ea=en?{repo:er,branch:en,path:nx(er,en)}:null,ei=()=>{(0,ed.e)(),I(!1),L(""),W(null)},eo=()=>{ea&&((0,ed.e)(),W(null),I(!1))};(0,r.useEffect)(()=>{!et.current&&C?.length&&S&&(et.current=!0,ee.current?.querySelector("[data-picked=true]")?.scrollIntoView({block:"nearest"}))},[C,S]);let ec=(C||[]).flatMap(e=>{let t=t5.find(t=>t.aiEngine===e.id);return t?[e,t]:[e]}),em=new Map(t5.map(e=>[e.aiEngine,e])),ex=new Set(em.keys()),ep=ec.find(e=>"claude"===e.id),eh=ec.find(e=>"claude-ui"===e.id),ef=[],eb=new Set(["claude"]);for(let e of ec){let t=e.isAiUi?e.aiEngine:e.id;if(eb.has(t)||!ex.has(t))continue;eb.add(t);let s=ec.find(e=>!e.isAiUi&&e.id===t),n=em.get(t);s&&ef.push(s),n&&ef.push(n)}let eg=ec.filter(e=>!e.isAiUi&&!ex.has(e.id)&&"claude"!==e.id),ev=(0,f.B)(e=>e.pushView),ey=void 0!==v?v:b?()=>{let e=y??"default",t=nc.getState(),s=t.workspaceWindows[e]||null;i?.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=nc.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:""}])});let n=f.B.getState();j.head||(n.activeWorkspaceId??null)===y||n.setActiveWorkspaceId(y),ev({type:"browser"})}:null,ew=ey?{id:"browser",isBrowser:!0,label:w("sites.browserPaneIntroTitle")}:null,ej=S&&ec.find(e=>e.id===S)||("browser"===S?ew:null)||null,ek=[null,ew||{empty:!0},...ep?[ep]:[],...eh?[eh]:[],...ef,...eg],eN=!ej?.isAiUi&&e9(ej),eC=ej?.yolo||(ej?.yoloEnv?Object.entries(ej.yoloEnv).map(e=>{let[t,s]=e;return`${t}=${s}`}).join(" "):null),eS=e=>{(0,ed.e)(),T(e?.id||"")},eT=a.match(/\d+$/)?.[0],eE=ea?ea.branch:ej?`${ej.short||ej.label}${eT?` ${eT}`:""}`:a||w("terminal.defaultName"),eR=M||o,e$=!!m&&!!eR,ez=e$&&"history"===Y,eP=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ej;if((0,ed.e)(),e?.isBrowser){ey?.(),t?.();return}if(O)return;let n=n=>{!e&&G&&tl(tt,G),tl(ts,e?.id||""),tl(tn,X?"1":"0");let r=X&&e9(e),l=eT?` ${eT}`:"",a=E.trim(),i=a||(ea?ea.branch:e?`${e.short||e.label}${l}`:null);s?.(i,!e&&G||null,e,r,n,!a),t?.()};if(!ea)return n(M);if(!k?.gitWorktreeAdd){W("This agent version does not support worktrees"),I(!0);return}_(!0),W(null),k.gitWorktreeAdd(ea.repo,ea.path,ea.branch,!0).then(e=>{if(_(!1),!e?.success){W(e?.error||"Failed to create worktree"),I(!0);return}n(e.path||ea.path)})},eA=(0,r.useRef)(eP);return((0,r.useEffect)(()=>{eA.current=eP}),(0,r.useEffect)(()=>{let e=e=>{if(!z&&!e.target?.closest?.("[data-wt-form]")){if("Escape"===e.key)e.preventDefault(),e.stopPropagation(),t?.();else if("Enter"===e.key&&"new"===Y){if(e.target?.tagName==="BUTTON"){e.target?.getAttribute("role")==="radio"&&(e.preventDefault(),e.stopPropagation(),eA.current());return}if(e.target?.tagName==="SELECT")return;e.preventDefault(),e.stopPropagation(),eA.current()}}};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[z,Y,t]),"u"<typeof document)?null:(0,se.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"modal-overlay z-[60] scrim fade-in",onClick:t,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 pop-in",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:`px-4 pt-4 space-y-2.5 ${ez?"pb-0":"pb-3"}`,children:[(0,n.jsxs)("div",{className:`flex gap-2 ${e$?"items-stretch -mx-4 px-4 border-b border-border-subtle":"items-center"}`,children:[e$?(0,n.jsx)("div",{role:"tablist",className:"flex-1 min-w-0 flex items-stretch gap-3",children:nF.map(e=>{let{id:t,icon:s,labelKey:r}=e;return(0,n.jsxs)("button",{role:"tab","aria-selected":Y===t,onClick:()=>{(0,ed.e)(),Z(t)},className:`pb-2 -mb-px flex items-center gap-1.5 text-sm font-semibold border-b-2 transition-colors ${Y===t?"text-text border-brand-500":"text-text-muted border-transparent hover:text-text"}`,children:[(0,n.jsx)(s,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:w(r)})]},t)})}):(0,n.jsx)("h2",{id:"newTerminalTitle",className:"flex-1 text-sm font-semibold text-text",children:w("terminal.newTerminal")}),(0,n.jsx)("button",{onClick:t,"aria-label":w("common.cancel"),className:"text-text-muted hover:text-text shrink-0 self-center",children:(0,n.jsx)(el.X,{size:18})})]}),o&&!ez&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(np,{workspacePath:o,workspaceName:c,fileBus:k,homeDir:u,value:M,onChange:e=>$(e),onBrowse:()=>P(!0),staged:ea}),A?(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:D,disabled:O,onChange:e=>L(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),eo()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),ei())},placeholder:w("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"}),D&&!O&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),L(""),U.current?.focus()},"aria-label":w("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:eo,disabled:!ea||O,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":w("workspaces.addWorktree"),children:(0,n.jsx)(el.aJ,{size:12})}),(0,n.jsx)("button",{type:"button",onClick:ei,disabled:O,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:w("common.cancel")})]}),D.trim()&&!en&&(0,n.jsx)("p",{className:"text-[10px] text-red-500 leading-tight",children:w("workspaces.worktreeNameAscii")}),(0,n.jsx)("p",{className:"truncate text-[10px] text-text-subtle leading-tight",title:ea?.path,children:nu(nx(er,en||"…"),u)}),K&&(0,n.jsx)("p",{className:"text-[10px] text-red-500 break-words",children:K})]}):(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),W(null),I(!0),null===H&&k?.gitScanRepos&&k.gitScanRepos(o).then(e=>{let t=e?.success&&e.repos||[];q(t),F(e=>e||t.find(e=>!e.relPath)?.path||t[0]?.path||null)}),requestAnimationFrame(()=>U.current?.focus())},title:ea?ea.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"}),ea?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"truncate text-text font-medium",children:ea.branch}),(0,n.jsx)("span",{className:"truncate text-[10px] text-text-subtle",children:nu(ea.path,u)})]}):(0,n.jsx)("span",{className:"text-text-muted",children:w("workspaces.addWorktree")})]})]})]}),ez?(0,n.jsx)(nj,{variant:"list",busRef:i,scope:N,cwd:eR,onResume:e=>{m?.(e),t?.()},onSelectSession:e=>{h?.(e),t?.()},liveSessionIds:x,activeSessionId:p,connected:b}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:ee,role:"radiogroup","aria-label":w("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]),ee.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)(nO,{agent:e}),(0,n.jsx)("span",{className:"flex-1 text-sm font-medium truncate",children:e?e.label:w("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:es.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&&l.length>0&&(0,n.jsx)("select",{value:G,onChange:e=>J(e.target.value),"aria-label":w("terminal.shell"),className:"w-full px-3 py-2 bg-surface-2 rounded-brand text-sm text-text focus:outline-none",children:l.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&&X,disabled:!eN,onChange:e=>V(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:w("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:w("terminal.nameLabel")}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{id:"newTerminalName",type:"text",ref:Q,value:E,placeholder:eE,onInput:e=>R(e.target.value),onKeyDown:e=>{"ArrowUp"===e.key&&(e.preventDefault(),ee.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"}),E&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),R(""),Q.current?.focus()},"aria-label":w("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:t,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:w("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:O||A&&!ea,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:[O?(0,n.jsx)(el.kr,{size:14,className:"animate-spin"}):(0,n.jsx)("span",{children:w("common.create")}),!O&&(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)(nI,{fileBus:k,scope:N,initialPath:M||o,onSelect:e=>{P(!1),e&&$(e)},onClose:()=>P(!1)})]}),document.body)}function nK(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:8,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 nW(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1600,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.8,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 nH(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"))),eg.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}=f.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 nW(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 nq="none";function nU(e){let{sessionId:t,title:s,onClose:l,busRef:a}=e,{t:i}=(0,eu.s)(),o=(0,f.B)(e=>e.backgroundBySession[t]),c=(0,f.B)(e=>e.setSessionBackground),d=(0,f.B)(e=>e.customBackgrounds),u=(0,f.B)(e=>e.terminalBackgrounds),m=(0,f.B)(e=>e.setTerminalBackgrounds),x=(0,f.B)(e=>e.setTerminalBackgroundOpacity),p=(0,f.B)(e=>e.terminalBackgroundOpacity)??eg._z,[h,b]=(0,r.useState)(!1),{saving:g,error:v,fileInput:y,openPicker:w}=nH(a);if("u"<typeof document)return null;let j=(0,eg.IJ)(u,d),k=o??null,N=[{key:nq,label:eg.vk.none.label},...d.map(e=>({key:`custom:${e.id}`,label:i("menu.bgCustomLabel"),src:e.dataUrl})),...Object.entries(eg.vk).filter(e=>{let[t]=e;return t!==nq}).map(e=>{let[t,s]=e;return{key:t,label:s.label,src:s.src}})];return(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[70]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:l}),(0,n.jsxs)("div",{className:"relative w-full max-w-lg card-elev my-auto flex flex-col overflow-hidden pop-in",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:i("menu.terminalBackground")}),s&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted truncate",children:s})]})]}),(0,n.jsx)("button",{type:"button",onClick:l,className:"p-1 rounded-brand text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex-shrink-0","aria-label":i("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:N.map(e=>{let{key:s,label:r,src:a}=e,i=s===nq,o=i?-1:j.indexOf(s),d=h?i?0===j.length:-1!==o:k===s;return(0,n.jsxs)("button",{type:"button",onClick:()=>(e=>{if(!h){c(t,e),l?.();return}e===nq?m([]):m(j.includes(e)?j.filter(t=>t!==e):[...j,e])})(s),className:`relative block w-full aspect-[9/16] rounded-2xl overflow-hidden transition-transform duration-200 ease-out active:scale-[0.97] ${d?"":"hover:-translate-y-0.5"}`,children:[a?(0,n.jsx)("img",{src:a,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:i?eg.vk.none.label:r})]}),a&&(0,n.jsx)("span",{className:"pointer-events-none absolute inset-0",style:{background:`rgba(0,0,0,${eg.t})`}}),a&&(0,n.jsx)("span",{className:"absolute inset-x-0 bottom-0 h-1/3 bg-gradient-to-t from-black/70 to-transparent"}),a&&(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 ${d?"ring-1 ring-inset ring-brand-500 dark:ring-white/60":"ring-1 ring-inset ring-white/15"}`}),h&&d&&!i&&(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:o+1})]},s??"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:i("menu.bgDim")}),(0,n.jsx)("input",{type:"range",min:eg.DW.min,max:eg.DW.max,step:eg.DW.step,value:p,onChange:e=>x(Number(e.target.value)),className:"brand-range flex-1 min-w-0",style:{"--pct":`${(p-eg.DW.min)/(eg.DW.max-eg.DW.min)*100}%`},"aria-label":i("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums flex-shrink-0",children:[Math.round(100*p),"%"]})]}),(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:h,onChange:e=>b(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:i("menu.bgApplyAll")})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{type:"button",onClick:w,disabled:g,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:[g?(0,n.jsx)(el.kr,{size:13,className:"animate-spin"}):(0,n.jsx)(el.FW,{size:13}),i("menu.bgAdd")]})]}),v&&(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:v})})]}),y]}),document.body)}let nX={y:{pos:"clientY",start:"top",size:"height"},x:{pos:"clientX",start:"left",size:"width"}};function nV(e){let{axis:t="y",threshold:s=12,onCommit:n,onTap:l}=e,[a,i]=(0,r.useState)(null),o=(0,r.useRef)(new Map),c=(0,r.useRef)(!1),d=(0,r.useRef)(null),u=(0,r.useRef)(null),m=(0,r.useCallback)(e=>t=>{t?o.current.set(e,t):o.current.delete(e)},[]),x=(0,r.useCallback)(()=>{let e=c.current;return c.current=!1,d.current&&(clearTimeout(d.current),d.current=null),e},[]);return{dragId:a,registerEl:m,startDrag:(0,r.useCallback)((e,r,a)=>{if("mouse"===e.pointerType&&0!==e.button||(u.current?.(!1),c.current=!1,d.current&&(clearTimeout(d.current),d.current=null),!a||a.length<2))return;let m=a.indexOf(r);if(m<0)return;let x=nX[t],p=a.map(e=>{let t=o.current.get(e)?.getBoundingClientRect();return t?{start:t[x.start],size:t[x.size]}:null});if(p.some(e=>!e))return;c.current=!1,d.current&&(clearTimeout(d.current),d.current=null);let h=!!l&&"mouse"===e.pointerType&&!e.ctrlKey&&!e.target?.closest?.("button, a, input, textarea, select"),f=p[m],b=e[x.pos],g=m,v=null,y=e=>{if("mouse"===e.pointerType&&0===e.buttons)return void w(!0,!0);let n=e[x.pos]-b;if(!c.current){if(Math.abs(n)<s)return;c.current=!0,(0,ed.e)(),i(r)}let l=f.start+f.size/2+n,d=0;for(let e=0;e<p.length;e++)l>=p[e].start&&(d=e);g=d,v||(v=requestAnimationFrame(()=>{let e;return v=null,void((e=o.current.get(r))&&(e.style.transform=`translate${t.toUpperCase()}(${n}px)`),a.forEach((e,s)=>{if(e===r)return;let n=o.current.get(e);if(!n)return;let l=0;m<g&&s>m&&s<=g?l=-f.size:m>g&&s>=g&&s<m&&(l=f.size),n.style.transform=l?`translate${t.toUpperCase()}(${l}px)`:""}))}))},w=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(u.current!==w)return;for(let e of(window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",j),window.removeEventListener("mouseup",j),window.removeEventListener("pointercancel",j),window.removeEventListener("blur",j),u.current=null,v&&(cancelAnimationFrame(v),v=null),o.current.values()))e&&(e.style.transform="");if(e&&h&&t&&!c.current&&g===m){c.current=!0,d.current=setTimeout(()=>{d.current=null,c.current=!1},0),l(r);return}if(c.current&&i(null),!e||!c.current||(d.current=setTimeout(()=>{d.current=null,c.current=!1},0),g===m))return;let s=[...a];s.splice(g,0,s.splice(m,1)[0]),(0,ed.e)(),n?.(s)},j=e=>w(!0,e?.type==="pointerup"||e?.type==="mouseup");u.current=w,window.addEventListener("pointermove",y,{passive:!1}),window.addEventListener("pointerup",j),window.addEventListener("mouseup",j),window.addEventListener("pointercancel",j),window.addEventListener("blur",j)},[t,s,n,l]),consumeClick:x}}var nG=s(71632),nJ=s(92673);let nY="sm:h-8",nZ=(0,r.memo)(function(e){let{bus:t}=e,[s,l]=(0,r.useState)([]),[a,i]=(0,r.useState)(""),[o,c]=(0,r.useState)(!1),d=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!t?.emit)return;t.emit("jarvis:chatHistory",{},e=>{e?.ok&&l(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],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 e=e=>{e?.type==="assistant"&&c(!1),e?.type&&"user"!==e.type&&l(t=>[...t.slice(-160),e])};return t.on?.("jarvis:chat:event",e),()=>t.off?.("jarvis:chat:event",e)},[t]),(0,r.useEffect)(()=>{d.current?.scrollTo?.({top:d.current.scrollHeight})},[s]);let u=()=>{let e=a.trim();e&&!o&&t?.emit&&((0,ed.e)(),i(""),c(!0),t.emit("jarvis:chat",{text:e},e=>{c(!1),e?.error&&l(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:d,className:"flex-1 min-h-0 overflow-y-auto modal-scrollable px-3 py-3 flex flex-col gap-2.5",children:[0===s.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?”"})]}),s.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)),o&&(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:a,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),u())},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:u,disabled:o||!a.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:o?(0,n.jsx)(el.M6,{size:14}):(0,n.jsx)(el.Vn,{size:14})})]})]})}),nQ=["todo","in_progress","needs_input","done"],n0={enabled:!0,llmProvider:"gemini",llmBaseUrl:"",llmKey:"",agentModel:"gemini-3.8-flash",boardScope:"workspace",wakeOnDone:!0,liveKey:"",liveModel:"gemini-3.8-live",liveVoice:"Puck"},n1=[{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"]}],n2="jarvisSettings",n5=["Puck","Charon","Kore","Fenrir","Aoede","Leda"],n3={tasks:{}},n4=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=Object.fromEntries(nQ.map(e=>[e,[]]));for(let s of Object.values(e))(t[s.status]||t.todo).push(s);return t},n6=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",s={};for(let[n,r]of Object.entries(e))r?.workspace&&r.workspace!==t||(s[n]=r);return s},n8=(0,b.v)((e,t)=>({board:n3,sink:null,applyBoard:t=>e({board:t?.tasks?t:n3}),setSink:t=>e({sink:"function"==typeof t?t:null}),moveTask:(s,n)=>{let r=t().board.tasks[s];r&&nQ.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})}})),n9=(0,b.v)((e,t)=>({open:!1,settings:{...n0},setOpen:t=>e({open:!!t}),toggle:()=>e(e=>({open:!e.open})),hydrateSettings:()=>{let t;return e({settings:(!(t={...n0,...(()=>{try{let e=JSON.parse(localStorage.getItem(n2));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(n2,JSON.stringify(n))}catch{}e({settings:n})}}));n9.getState().hydrateSettings();let n7={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"}},re={needs_input:"border-amber-500/60 animate-pulse",done:"border-border-subtle/60 opacity-70"};function rt(e){let{task:t,prev:s,next:r,showWorkspace:l}=e,a=n8(e=>e.moveTask),i=n8(e=>e.deleteTask),o=l&&t.workspace?String(t.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 ${re[t.status]||""}`,children:[(0,n.jsx)("div",{className:"pr-4 font-medium text-text break-words",children:t.title}),(t.engine||t.branch||o)&&(0,n.jsxs)("div",{className:"mt-1 flex items-center gap-1.5 flex-wrap text-[10px] text-text-muted",children:[o&&(0,n.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-brand-500/10 text-brand-400 truncate max-w-[110px]",title:t.workspace,children:o}),t.engine&&(0,n.jsx)("span",{className:"px-1.5 py-0.5 rounded bg-surface-3/60 font-mono truncate max-w-[110px]",children:t.engine}),t.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:t.branch})]})]}),t.sessionId&&!t.auto&&(0,n.jsx)("div",{className:"mt-1 text-[9px] font-mono text-text-muted/70 truncate",children:t.sessionId}),t.question&&(0,n.jsx)("div",{className:"mt-1 text-[10px] leading-relaxed text-amber-400/90 line-clamp-3",children:t.question}),t.summary&&(0,n.jsx)("div",{className:"mt-1 text-[10px] leading-relaxed text-text-muted line-clamp-3",children:t.summary}),!t.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:[s&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),a(t.id,s)},"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})}),r&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),a(t.id,r)},"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)(),i(t.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 rs=(0,r.memo)(function(e){let{workspacePath:t=""}=e,s=n8(e=>e.board.tasks),l=n9(e=>e.settings.boardScope),a=n9(e=>e.setSettings),i="all"===l,o=(0,r.useMemo)(()=>i?s:n6(s,t),[s,t,i]),c=(0,r.useMemo)(()=>n4(o),[o]),d=Object.keys(o).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:[d," cards"]}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),a({boardScope:i?"workspace":"all"})},className:`ml-auto text-[10px] px-2 py-0.5 rounded-full border transition-colors ${i?"border-brand-500/50 text-brand-400 bg-brand-500/10":"border-border-subtle text-text-muted hover:text-text"}`,title:i?"Showing cards from every workspace":"Showing cards from this workspace only",children:i?"All workspaces":"This workspace"})]}),!i&&Object.keys(s).length>d&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),a({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(s).length-d," cards in other workspaces — tap to show all"]}),d?(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(${nQ.length}, minmax(0, 1fr))`},children:nQ.map(e=>{let t=n7[e]||{label:e,cls:"text-text-muted",dot:"bg-text-muted/60"},s=c[e]||[],r=nQ.indexOf(e),l=nQ[Math.max(0,r-1)],a=nQ[Math.min(nQ.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)(rt,{task:t,showWorkspace:i,prev:"todo"===e?null:l,next:"done"===e?null:a},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."})]})]})}),rn=(0,r.memo)(function(e){let{icon:t,iconClass:s="text-text",title:l,subtitle:a,maxWidth:i="max-w-lg",onClose:o,actions:c=null,children:d,footer:u=null}=e,m=(0,r.useRef)(null);return(0,r.useEffect)(()=>{m.current?.contains(document.activeElement)||m.current?.focus()},[]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),o?.())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o]),(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&&o?.()},children:(0,n.jsxs)("div",{ref:m,tabIndex:-1,className:`card-elev w-full ${i} 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:[t&&(s?(0,n.jsx)("div",{className:`w-6 h-6 rounded-full flex items-center justify-center shrink-0 ${s}`,children:t}):(0,n.jsx)("div",{className:"flex items-center justify-center shrink-0 text-text",children:t})),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-semibold text-text truncate",children:l}),a&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted truncate",children:a})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[c,(0,n.jsx)("button",{type:"button",onClick:o,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})})]})]}),d,u]})})}),rr="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",rl="text-[11px] text-text-muted px-1";function ra(e){let{title:t,summary:s,ok:r,open:l,onToggle:a,children:i}=e;return(0,n.jsxs)("div",{className:`rounded-brand border overflow-hidden transition-colors ${l?"border-brand-500/40":"border-border-subtle"} bg-surface-2/20`,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),a()},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 ${r?"bg-emerald-400":"bg-text-muted/40"}`}),(0,n.jsx)("span",{className:"text-sm text-text flex-1 min-w-0 truncate",children:t}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate max-w-[45%]",children:s}),(0,n.jsx)(el.yQ,{size:14,className:`text-text-muted flex-shrink-0 transition-transform ${l?"rotate-180":""}`})]}),l&&(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:i})]})}function ri(e){let{label:t,hint:s,value:r,onChange:l}=e;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),l(!r)},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:t}),(0,n.jsx)("span",{className:"block text-xs text-text-muted truncate",children:s})]}),(0,n.jsx)("span",{className:`shrink-0 relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${r?"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 ${r?"translate-x-4":"translate-x-0.5"}`})})]})}let ro=(0,r.memo)(function(e){let{busRef:t}=e,s=n9(e=>e.settings),l=n9(e=>e.setSettings),[a,i]=(0,r.useState)(""),o=n1.find(e=>e.id===s.llmProvider)||n1[0],c=e=>{l(e);let n={...s,...e};t?.current?.emit?.("jarvis:agentConfig",{provider:n.llmProvider,baseUrl:n.llmBaseUrl,apiKey:n.llmKey,model:n.agentModel,wake:n.wakeOnDone})};return(0,n.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,n.jsxs)(ra,{title:"Chat LLM",summary:`${o.label} \xb7 ${s.agentModel||""}`,ok:!!s.llmKey,open:"llm"===a,onToggle:()=>i("llm"===a?"":"llm"),children:[(0,n.jsx)("span",{className:rl,children:"Endpoint"}),(0,n.jsx)("input",{type:"text",value:s.llmBaseUrl||"",onChange:e=>c({llmBaseUrl:e.target.value}),placeholder:o.baseUrlHint,autoComplete:"off",spellCheck:!1,className:rr}),(0,n.jsx)("span",{className:rl,children:"API key"}),(0,n.jsx)("input",{type:"password",value:s.llmKey||"",onChange:e=>c({llmKey:e.target.value}),placeholder:"sk-…",autoComplete:"off",spellCheck:!1,className:rr}),(0,n.jsx)("span",{className:rl,children:"Model"}),(0,n.jsx)("input",{type:"text",value:s.agentModel||"",onChange:e=>c({agentModel:e.target.value}),placeholder:o.models[0],autoComplete:"off",spellCheck:!1,className:rr}),(0,n.jsx)("span",{className:rl,children:"Format — must match the endpoint above"}),(0,n.jsx)("select",{value:s.llmProvider,onChange:e=>{var t;(0,ed.e)(),(t=e.target.value)!==s.llmProvider&&c({llmProvider:t})},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:n1.map(e=>(0,n.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,n.jsxs)(ra,{title:"Live voice",summary:s.liveKey?`${s.liveModel||"gemini-3.8-live"} \xb7 ${s.liveVoice||"Puck"}`:"no key",ok:!!s.liveKey,open:"live"===a,onToggle:()=>i("live"===a?"":"live"),children:[(0,n.jsx)("input",{type:"password",value:s.liveKey||"",onChange:e=>l({liveKey:e.target.value}),placeholder:"Google AI API key",autoComplete:"off",spellCheck:!1,className:rr}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:s.liveModel||"",onChange:e=>l({liveModel:e.target.value}),placeholder:"gemini-3.8-live",autoComplete:"off",spellCheck:!1,className:`${rr} flex-1 min-w-0`}),(0,n.jsx)("select",{value:s.liveVoice||"Puck",onChange:e=>l({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:n5.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)(ri,{label:"Wake on worker done",hint:"Jarvis checks the fleet and updates the board",value:s.wakeOnDone,onChange:e=>c({wakeOnDone:e})})]})}),rc=(0,r.memo)(function(e){let{busRef:t,onClose:s}=e;return(0,n.jsx)(rn,{icon:(0,n.jsx)(el.wB,{size:14}),title:"Jarvis Settings",subtitle:"Coordinator harness and behavior",maxWidth:"max-w-sm",onClose:s,children:(0,n.jsx)("div",{className:"p-3",children:(0,n.jsx)(ro,{busRef:t})})})});function rd(e){let{busRef:t,fileBus:l=null,workspacePath:a="",onClose:i}=e,o=n9(e=>e.settings),c=n8(e=>e.applyBoard),d=n8(e=>e.setSink),[u,m]=(0,r.useState)(!1),[x,p]=(0,r.useState)(!0),[h,f]=(0,r.useState)(null);(0,r.useEffect)(()=>{f(t?.current??null)},[t]);let b=function(e){let{busRef:t,apiKey:n,voice:l,model:a}=e,[i,o]=(0,r.useState)("idle"),[c,d]=(0,r.useState)(""),[u,m]=(0,r.useState)([]),[x,p]=(0,r.useState)(0),h=(0,r.useCallback)((e,t)=>{t&&m(s=>[...s.slice(-40),{who:e,text:String(t).slice(0,400)}])},[]),f=(0,r.useRef)({}),b=(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{}o("idle")},[]);(0,r.useEffect)(()=>b,[b]);let g=(0,r.useCallback)(async()=>{if(!n){d("Add a Google AI key in Jarvis settings first"),o("error");return}b(),d(""),m([]),p(0),o("connecting");let e=(e,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{t.current?.emit?.(e,s,e=>{clearTimeout(a),l(e)})}catch(e){clearTimeout(a),l({ok:!1,error:e?.message||"bus unavailable"})}});try{let[{GoogleGenAI:t,Modality:i},c]=await Promise.all([Promise.all([s.e(152),s.e(9692)]).then(s.bind(s,75270)),e("jarvis:tools",{})]),u=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e.filter(e=>e?.name&&e?.description).map(e=>{let{name:t,description:s,inputSchema:n}=e;return{name:t,description:s,...n?{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}(n)}:{}}})}(c?.tools||[]);u.length||h("tool",`no coordinator tools (${c?.error||"empty manifest"}) — voice only; restart the agent to get tools`);let m=await navigator.mediaDevices.getUserMedia({audio:!0}),x=new AudioContext({sampleRate:16e3});await x.resume?.().catch?.(()=>{});let g=x.createMediaStreamSource(m),v=x.createScriptProcessor(1024,1,1),y=x.createGain();y.gain.value=0,g.connect(v),v.connect(y),y.connect(x.destination);let w=f.current;w.stream=m,w.inCtx=x,w.processor=v,w.mute=y,w.playing=[],w.maxLevel=0,w.levelProbe=setTimeout(()=>{f.current===w&&!w.speechSeen&&(0===w.maxLevel?h("tool","no mic signal — check microphone permission"):w.maxLevel<.03&&h("tool",`mic very quiet (peak ${w.maxLevel.toFixed(3)} < threshold 0.03) — speak up or move closer`))},3e3),w.levelProbe.unref?.();let j=new t({apiKey:n}),k=await j.live.connect({model:a||"gemini-3.8-live",callbacks:{onmessage:e=>(function(e){let t=f.current,s=e?.usageMetadata?.totalTokenCount;for(let t of(s>0&&p(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,l=e?.serverContent?.outputTranscription?.text;n&&h("user",n),l&&h("jarvis",l);let a=e?.toolCall?.functionCalls;a?.length&&f.current.session&&Promise.all(a.map(e=>({fc:e,p:r(e)})).map(e=>{let{fc:t,p:s}=e;return s.then(e=>({id:t.id,name:t.name,response:{result:e?.ok?e.result||"ok":`error: ${e?.error||"no answer"}`}}))})).then(e=>{try{f.current.session?.sendToolResponse({functionResponses:e})}catch{}})})(e),onerror:e=>{d(e?.message||"live connection error"),o("error")},onclose:()=>o(e=>"idle"===e?e:"idle")},config:{responseModalities:[i.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:l||"Puck"}}},tools:[{functionDeclarations:u}],contextWindowCompression:{triggerTokens:12e3,slidingWindow:{targetTokens:6e3}},inputAudioTranscription:{},outputAudioTranscription:{}}});if(w.session=k,!f.current.session)return b();let N=function(e){let{sendChunk:t,sendStreamEnd:s,now:n=()=>Date.now()}=e,r=[],l=!1,a=0,i=!0;return{onChunk(e,o){let c=n(),d=o>=.03;if(d&&(a=c),d&&!l)for(let e of(l=!0,i=!1,r))t(e);if(r.push(e),r.length>5&&r.shift(),l){if(c-a>=1e3){l=!1;return}if(!i&&c-a>=500){i=!0;try{s()}catch{}}t(e)}}}}({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)},o("live")}catch(e){b(),d(e?.message||String(e)),o("error")}async function r(t){h("tool",`${t.name}(${JSON.stringify(t.args||{})})`);let s=await e("jarvis:tool",{name:t.name,args:t.args||{}});return h("tool",`${t.name} → ${s?.ok?String(s.result).slice(0,200):s?.error}`),s}},[n,l,a,b,h,t]);return{status:i,error:c,entries:u,tokens:x,start:g,stop:b}}({busRef:t,apiKey:o.liveKey,voice:o.liveVoice,model:o.liveModel});return(0,r.useEffect)(()=>{let e=t?.current;if(!e?.emit||!e?.on)return;let s=()=>e.emit("jarvis:getState",{},e=>{e?.ok&&c(e.board)});s();let n=setInterval(s,5e3),r=e=>c(e);return e.on("jarvis:kanban",r),d(t=>e.emit("jarvis:kanban",{action:t})),()=>{clearInterval(n),e.off?.("jarvis:kanban",r),d(null)}},[t,c,d]),(0,r.useEffect)(()=>{h?.emit?.("jarvis:agentConfig",{provider:o.llmProvider,baseUrl:o.llmBaseUrl,apiKey:o.llmKey,model:o.agentModel,wake:o.wakeOnDone})},[h,o.llmProvider,o.llmBaseUrl,o.llmKey,o.agentModel,o.wakeOnDone]),(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||u||(e.preventDefault(),i?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[i,u]),(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"}),o.liveKey&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),"idle"===b.status||"error"===b.status?b.start():b.stop()},className:`relative p-1.5 rounded-brand transition-colors ${"live"===b.status?"text-red-500":"text-text-muted"} hover:text-text hover:bg-surface-2`,"aria-label":"Live voice",title:"live"===b.status?"End live voice":"Live voice — talk to delegate work (Gemini 3.8 Live)",children:[(0,n.jsx)(el.GO,{size:16}),"live"===b.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)(),p(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)(),m(!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)(),i?.()},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)(rs,{workspacePath:a})}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(nZ,{bus:h})})]}),u&&(0,n.jsx)(rc,{busRef:t,onClose:()=>m(!1)}),"idle"!==b.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"===b.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"===b.status?"— connecting…":"— listening"]}),b.tokens>0&&(0,n.jsxs)("span",{className:"text-[10px] text-text-muted font-mono",title:"Context tokens — the number the bill compounds on",children:[(b.tokens/1e3).toFixed(1),"k tok"]}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),b.stop()},className:"text-xs text-text-muted hover:text-text px-1.5 py-0.5 rounded-brand",children:"End"})]}),b.error&&(0,n.jsx)("p",{className:"text-[11px] text-red-400 px-0.5 pb-1",children:b.error}),(0,n.jsxs)("div",{className:"overflow-y-auto modal-scrollable flex flex-col gap-1 pr-0.5",children:[0===b.entries.length&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted",children:"Speak to delegate — e.g. “which sessions are free?”"}),b.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 ru=[],rm={},rx=new Set(["claude","codex","opencode","antigravity","omp","pi","devin","hermes"]),rp=new Set(["idle","done"]),rh=e=>!!e&&rx.has(e.endsWith("-ui")?e.slice(0,-3):e),rf=(0,r.memo)(function(e){let{sessions:t=[],allSessions:s=[],activeSessionId:l,connected:a,notifications:i,sessionStatus:o,onSwitchSession:c,onCreateSession:d,onBack:u,onOpenRemote:x,onOpenMobile:p,hostKey:h=null,onOpenRemoteHost:b=null,onOpenMobileHost:g=null,onOpenFiles:v,onLogout:y,tunnelUrl:w,apiKey:j,connectionMode:k,subscribeToPush:N,unsubscribeFromPush:C,hostVersion:S,agentVersion:T,busRef:E,carrier:R="ws",isActive:M=!0,shells:$=[],modalBusRef:z=null,modalHostKey:A="main",modalShells:I=null,workspaces:D=[],activeWorkspaceId:L=null,onRenameSession:B,onDeleteSession:F,onCreateNamedSession:O,onResumeAgentSession:_=null,onToggleSidebar:K=null,sidebarCollapsed:W=!1,onToggleRightPanel:H,onReorderSession:q,rightPanelOpen:U=!1,fileBus:X=null,homeDir:V=null,isDesktop:G=!0}=e,{t:J}=(0,eu.s)(),Y=L??"default",Z=nc(e=>e.workspaceProfiles[Y]||"default"),Q=nc(e=>e.workspaceWindows[Y]||null),ee=nc(e=>e.tabsByWorkspace[Y]??ru),et=nc(e=>e.activeByWorkspace[Y]||null),es=(0,f.B)(e=>{let t=e.viewStack;return!!(t&&t[t.length-1]?.type==="browser")}),en=nc(e=>e.setActive),er=nc(e=>e.agentTabs),ea=nc(e=>e.setProfileFor),ei=nc(e=>e.setWindowFor),eo=function(e,t){let{wsKey:s,profile:n,ownTabs:r}=t;return Array.isArray(e)?e.filter(e=>(!e.workspaceId||e.workspaceId===s)&&!(e.profile===n&&r.some(t=>t.id===e.id))):[]}(er,{wsKey:Y,profile:Z,ownTabs:ee}),em=e=>{ea(Y,e.profile),null!=e.windowId&&ei(Y,e.windowId),en(Y,e.id),ex({type:"browser"})};!function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"default",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"default";(0,r.useEffect)(()=>{let s=e?.current;if(!t||!s?.on)return;let n=e=>{nc.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;t&&r?.on&&null==n&&r.emit("browser:invoke",{action:"window.forWorkspace",payload:{profile:s,workspaceId:l}},e=>{let t=Number.isFinite(Number(e?.windowId))&&Number(e.windowId)>0?Number(e.windowId):null;e?.ok&&t&&nc.getState().setWindowFor(l,t)})},[e,t,s,n,l]),(0,r.useEffect)(()=>{let r=e?.current;if(!t||null==n||!r?.on)return;let a=new Set,i=!1,o=e=>{let t=nc.getState(),s=window.matchMedia?.("(max-width: 767px)").matches,n=i&&s?e.find(e=>e.openerId&&!a.has(e.id)):null;for(let t of(i=!0,e))a.add(t.id);let r=t.tabsByWorkspace[l]||[],o=new Map(e.map(e=>[e.id,e])),c=e.filter(e=>!r.some(t=>t.id===e.id)),d=new Set,u=Math.min(c.length,r.filter(e=>String(e.id).startsWith("boot_")).length);for(let e of r)u>0&&String(e.id).startsWith("boot_")&&(d.add(e.id),u-=1);let m=[...r.filter(e=>o.has(e.id)&&!d.has(e.id)).map(e=>o.get(e.id)),...c];t.setTabs(l,m);let x=t.activeByWorkspace[l];n?t.setActive(l,n.id):e.length&&!e.some(e=>e.id===x)&&t.setActive(l,(e.find(e=>e.active)||e[0]).id)},c=e=>{e?.profile&&e.profile!==s||(e?.windowId??null)===n&&o(Array.isArray(e?.tabs)?e.tabs:[])};return r.on("browser:tabs",c),r.emit("browser:tabs.watch",{on:!0,profile:s,workspaceId:l,windowId:n},e=>{if(!e?.ok)return;let t=Number.isFinite(Number(e.windowId))&&Number(e.windowId)>0?Number(e.windowId):null,s=nc.getState();t&&t!==n&&s.setWindowFor(l,t),t||(s.setWindowFor(l,null),s.setTabs(l,[]),s.setActive(l,null)),Array.isArray(e.tabs)&&e.tabs.length&&o(e.tabs)}),()=>{r.off?.("browser:tabs",c),r.emit?.("browser:tabs.watch",{on:!1,profile:s,workspaceId:l,windowId:n})}},[e,t,s,n,l])}(E,a,Z,Q,Y);let ex=(0,f.B)(e=>e.pushView),ep=(0,f.B)(e=>e.popView),eh=(0,f.B)(e=>e.agentBySession??rm),ef=(0,f.B)(e=>e.fullModes??rm)[L??e5.AD]??!1,eb=(0,f.B)(e=>e.toggleFullMode);ek(e=>e.notifications);let eg=eI(),ev=o||eg,{formattedStars:ew}=(0,nG.w)(),ej="mouse"===sj(),eN=(e,t)=>ej?tw(e,t):e,eC=(0,r.useRef)(null),eS=(0,r.useRef)(null),eT=(0,r.useRef)(null),[eE,eR]=(0,r.useState)({targetId:null,x:0,y:0}),ez=(0,r.useRef)(null),eP=nK(ez,eE.x,eE.y),[eA,eD]=(0,r.useState)({sessionId:null,x:0,y:0}),[eL,eB]=(0,r.useState)(null),eF=(0,r.useRef)(null),eO=nK(eF,eA.x,eA.y),e_=eh[eA.sessionId]||ev[eA.sessionId]?.tool||t.find(e=>e.id===eA.sessionId)?.agent,eK=e_?.endsWith("-ui"),eW=rh(e_),eH=eW&&rp.has(ev[eA.sessionId]?.state||"idle"),[eq,eU]=(0,r.useState)({isOpen:!1,sessionId:null,sessionName:""}),[eX,eV]=(0,r.useState)({sessionId:null,name:"",value:""}),[eG,eJ]=(0,r.useState)(!1),eY=n9(e=>e.open),eZ=n9(e=>e.toggle),eQ=n9(e=>!1),e0=n8(e=>Object.values(e.board.tasks).some(e=>"needs_input"===e.status));(0,r.useEffect)(()=>{if(!M||!eQ)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"j"===e.key.toLowerCase()&&(e.preventDefault(),eZ())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[M,eQ,eZ]);let e1=e=>{(0,ed.e)(),tt.includes(e)&&tn(e),c?.(e)},{dragId:e2,registerEl:e3,startDrag:e4,consumeClick:e9}=nV({axis:"x",threshold:12,onTap:e1,onCommit:q}),e7=(0,r.useMemo)(()=>new Set(s.map(e=>e.id)),[s]);(0,r.useEffect)(()=>{if(!M)return;let e=e=>{let s,n=document.activeElement;if(!n||"INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName||!e.ctrlKey||e.altKey||e.metaKey||e.shiftKey||t.length<2)return;let r=t.findIndex(e=>e.id===l);if("ArrowRight"===e.key)s=t[(r+1)%t.length];else if("ArrowLeft"===e.key)s=t[(r-1+t.length)%t.length];else{if(!(e.key>="1")||!(e.key<="9"))return;s=t[Math.min(e.key-1,t.length-1)]}e.preventDefault(),s&&s.id!==l&&c?.(s.id),requestAnimationFrame(()=>requestAnimationFrame(()=>n.focus()))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[M,t,l,c]);let te=(0,f.B)(e=>e.hiddenHeaderButtons),tt=(0,f.B)(e=>e.hiddenPaneSessionIds??ru),ts=(0,f.B)(e=>e.toggleHidePane),tn=(0,f.B)(e=>e.unhidePane),tr=(0,f.B)(e=>e.setFullMode),tl=(0,P.rh)(e=>e.currentKey),ta=h||tl,ti=(0,P.rh)(e=>e.hosts[ta]),to=ti?.mobileDeviceCount||0,tc=h?!!ti?.remoteAvailable:!!x,td=h?!!ti?.mobileAvailable:!!p;eM(h).busRef;let tu=ey(e=>e.setContext),tm=ey(e=>e.setCallbacks);(0,r.useEffect)(()=>{if(!M)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.altKey&&!e.shiftKey&&"t"===e.key.toLowerCase()&&(e.preventDefault(),eJ(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[M]),(0,r.useEffect)(()=>{if(!eA.sessionId)return;let e=e=>{eF.current&&!eF.current.contains(e.target)&&eD({sessionId:null,x:0,y:0})},t=e=>{"Escape"===e.key&&eD({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)}},[eA.sessionId]);let tx=(0,r.useRef)(null),tp=()=>{tx.current&&(clearTimeout(tx.current),tx.current=null)},th=e=>{eU({isOpen:!0,sessionId:e.id,sessionName:e?.name||J("terminal.defaultName")}),eD({sessionId:null,x:0,y:0})},tf=D.find(e=>e.id===L)||null,tb=e=>{let t=requestAnimationFrame(()=>{let t=eC.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)};(0,r.useEffect)(()=>tb(eS),[l,t.length]),(0,r.useEffect)(()=>tb(eT),[et,ee.length,es]);let tg=(0,r.useRef)(ee.length),tv=(0,r.useRef)(Z);return(0,r.useEffect)(()=>{let e=tg.current,t=tv.current!==Z;tg.current=ee.length,tv.current=Z,e>0&&0===ee.length&&es&&!t&&ep()},[ee.length,es,Z,ep]),(0,r.useEffect)(()=>{if(!eE.targetId)return;let e=e=>{ez.current&&!ez.current.contains(e.target)&&eR({targetId:null,x:0,y:0})},t=e=>{"Escape"===e.key&&eR({targetId:null,x:0,y:0})};return window.addEventListener("pointerdown",e),window.addEventListener("keydown",t),()=>{window.removeEventListener("pointerdown",e),window.removeEventListener("keydown",t)}},[eE.targetId]),(0,r.useEffect)(()=>{M&&(tu({connected:a,remoteAvailable:!!x,showTheme:!1,busRef:E,tunnelUrl:w,apiKey:j,connectionMode:k,subscribeToPush:N,unsubscribeFromPush:C,hostVersion:S||T,agentVersion:S||T,carrier:R}),tm({onRemote:x,onFiles:v,onLogout:y}))},[M,a,x,v,y,w,j,k,S,T,E,R,N,C,tu,tm]),(0,n.jsxs)("div",{className:`terminal-header-glass h-9 ${nY} px-2 sm:pl-0 sm:pr-2 flex items-stretch gap-0 flex-shrink-0 border-b border-border-subtle`,children:[K&&W&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),K()},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:eN(J("common.open"),"toggleSidebar"),children:(0,n.jsx)(el.e6,{size:16})}),u&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),u()},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:eC,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:[t.map(e=>{let s=e.id===l&&!es,r=tt.includes(e.id),i=ev[e.id]?.state||"idle",o=s7(i),d=e.name||J("terminal.defaultName"),u=e8(eh[e.id])||e8(eh[e.id]?.replace(/-ui$/,""));return(0,n.jsxs)("div",{role:"button",tabIndex:0,ref:t=>{e3(e.id)(t),s&&(eS.current=t)},onPointerDown:s=>{"mouse"===s.pointerType&&q&&a&&(tp(),e4(s,e.id,t.map(e=>e.id)))},onClick:()=>{e9()||e1(e.id)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),r&&tn(e.id),c?.(e.id))},onContextMenu:t=>{t.preventDefault(),(0,ed.e)(),eD({sessionId:e.id,x:t.clientX,y:t.clientY})},onTouchStart:t=>{let s;return s=t.touches[0],void(tx.current=setTimeout(()=>{(0,ed.e)(),eD({sessionId:e.id,x:s.clientX,y:s.clientY})},500))},onTouchMove:tp,onTouchEnd:tp,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 ${s?"term-tab-active":""} ${r?"opacity-75 hover:opacity-100":""} ${e2===e.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 ${e6} ${F?"sm:group-hover:hidden":""}`}):(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full term-dot ${o.cls}${o.pulse?` pulse-${o.pulse}`:""} ${F?"sm:group-hover:hidden":""}`,style:{background:o.dot},title:J(o.label)}),F&&(0,n.jsx)("button",{type:"button",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),(0,ed.e)(),th(e)},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:eN(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}),r&&(0,n.jsx)("button",{type:"button",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),(0,ed.e)(),tn(e.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})})]},e.id)}),ee.map(e=>{let t=es&&(et===e.id||!et&&e.active);return(0,n.jsxs)("div",{ref:t?eT:null,role:"button",tabIndex:0,onClick:()=>{(0,ed.e)(),en(Y,e.id),ex({type:"browser"})},onContextMenu:t=>{t.preventDefault(),eR({targetId:e.id,x:t.clientX,y:t.clientY})},onTouchStart:t=>{let s;return s=t.touches[0],void(tx.current=setTimeout(()=>{(0,ed.e)(),eR({targetId:e.id,x:s.clientX,y:s.clientY})},500))},onTouchMove:tp,onTouchEnd:tp,onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),en(Y,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)(),E?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:e.id,profile:Z}},()=>{});let s=nc.getState(),n=(s.tabsByWorkspace[Y]||[]).filter(t=>t.id!==e.id);s.setTabs(Y,n),s.activeByWorkspace[Y]===e.id&&s.setActive(Y,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":e.title||J("sites.browserTab"),children:e.title||J("sites.browserTab")})]},e.id)}),eo.map(e=>(0,n.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>{(0,ed.e)(),em(e)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),em(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":`${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)(),E?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:e.id,profile:e.profile}},()=>{}),nc.getState().setAgentTabs(nc.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: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}`)),d&&(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)(),eJ(!0)},disabled:!a,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:eN(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:[!te.includes("remote")&&tc&&(h||!(0,m.sP)())&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),(h?b:x)?.(h||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})}),!te.includes("mobile")&&td&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),(h?g:p)?.(h||void 0)},className:`hidden sm:block p-1.5 hover:bg-surface-2 rounded-brand transition duration-150 ease-out active:scale-[0.94] ${to>0?"text-green-400":"text-text hover:text-text"}`,title:to>0?J("mobile.deviceRunning",{count:to}):J("mobile.androidDevice"),children:(0,n.jsx)(el.wO,{size:16})}),eQ&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eZ()},disabled:!a,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 ${e0?"text-amber-400":"text-text hover:text-text"}`,title:"Jarvis coordinator (⌘J / Ctrl+J)",children:[(0,n.jsx)(el.cC,{size:16}),e0&&(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"})]}),!te.includes("notifications")&&(0,n.jsx)(no,{sessionStatus:ev,allSessions:s,onSwitchSession:c}),!te.includes("notifications")&&(0,n.jsx)(na,{sessions:t,allSessions:s,sessionStatus:ev,onSwitchSession:c,workspaces:D}),H&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),H()},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:eN(J("workspaces.tabFiles"),"toggleRightPanel"),children:(0,n.jsx)(el.jz,{size:16})})]}),eE.targetId&&(0,n.jsxs)("div",{ref:ez,className:"fixed z-[60] menu-popover p-1 min-w-[150px] pop-in",style:{left:eP.left,top:eP.top},children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)();let e=ee.find(e=>e.id===eE.targetId)?.url;e&&navigator.clipboard?.writeText?.(e).catch(()=>{}),eR({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)(),E?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:eE.targetId,profile:Z}},()=>{});let e=nc.getState(),t=(e.tabsByWorkspace[Y]||[]).filter(e=>e.id!==eE.targetId);e.setTabs(Y,t),e.activeByWorkspace[Y]===eE.targetId&&e.setActive(Y,t[0]?.id||null),eR({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"]})]}),eA.sessionId&&(0,n.jsxs)("div",{ref:eF,className:"fixed z-[60] menu-popover p-1 min-w-[140px] pop-in",style:{left:eO.left,top:eO.top},children:[ev[eA.sessionId]?.state==="done"&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ek.getState().clearNotification(eA.sessionId),eD({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 e;eV({sessionId:(e=t.find(e=>e.id===eA.sessionId)).id,name:e.name||"",value:e.name||""}),eD({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")]}),G&&(0,n.jsxs)("div",{className:"relative group/split",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),!ef&&eA.sessionId&&eA.sessionId!==l&&c?.(eA.sessionId),eb(L),eD({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 ${eO.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)(),!ef&&eA.sessionId&&eA.sessionId!==l&&c?.(eA.sessionId),eb(L),eD({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:[ef?(0,n.jsx)(el.xq,{size:12}):(0,n.jsx)(el.h1,{size:12}),(0,n.jsx)("span",{className:"whitespace-nowrap",children:ef?"Restore":"Maximize"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"100%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),ef&&tr(L,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:2}})),eD({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)(),ef&&tr(L,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:3}})),eD({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)(),ef&&tr(L,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:4}})),eD({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)(),ef&&tr(L,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:"auto"}})),eD({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)(),ts(eA.sessionId),eD({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:[tt.includes(eA.sessionId)?(0,n.jsx)(el.kU,{size:12}):(0,n.jsx)(el.X_,{size:12}),(0,n.jsx)("span",{children:tt.includes(eA.sessionId)?J("sessions.showPanel")||"Show":J("sessions.hidePanel")||"Hide"})]})})]})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eB(eA.sessionId),eD({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")]}),(eh[eA.sessionId]?.endsWith("-ui")||ev[eA.sessionId]?.conversationId)&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)();let e=eA.sessionId,t=e$(e).bus;eh[e]?.endsWith("-ui")?t?.emit("ai:restart",{sessionId:e}):t?.emit("session-resume",{sessionId:e}),eD({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})," ",eh[eA.sessionId]?.endsWith("-ui")?J("sessions.restartAi")||"Restart AI":J("sessions.resumeSession")]}),eW&&(0,n.jsxs)("button",{disabled:!eH,onClick:()=>{(0,ed.e)();let e=eA.sessionId;e$(e).bus?.emit("setSessionMode",{sessionId:e,mode:eK?"terminal":"ui"},e=>{e?.success||alert(e?.error||J("sessions.modeSwitchFailed"))}),eD({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 ${eH?"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:()=>th(t.find(e=>e.id===eA.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")]})]}),eL&&(0,n.jsx)(nU,{sessionId:eL,title:t.find(e=>e.id===eL)?.name,busRef:E,onClose:()=>eB(null)}),eX.sessionId&&(0,n.jsx)(nk,{title:J("sessions.editName"),placeholder:eX.name,value:eX.value,onChange:e=>eV({...eX,value:e}),onSubmit:()=>{let e=eX.value.trim();eX.sessionId&&e&&B?.(eX.sessionId,e),eV({sessionId:null,name:"",value:""})},onClose:()=>eV({sessionId:null,name:"",value:""})}),eG&&(0,n.jsx)(n_,{onClose:()=>eJ(!1),onCreate:(e,t,s,n,r,l)=>{O?O(e,L,t,r||null,s,n,l):d?.()},workspaceId:L,shells:I||$,busRef:z||E,hostKey:A,suggestName:`${J("terminal.defaultName")} ${t.filter(e=>(0,e5.xs)(e)===(L??null)).length+1}`,workspacePath:tf?.path||null,workspaceName:tf?.name||"",fileBus:X,homeDir:V,onResumeAgentSession:_,onSelectSession:c,liveSessionIds:e7,activeSessionId:l,connected:a}),(0,n.jsx)(ec.A,{isOpen:eq.isOpen,onClose:()=>eU({isOpen:!1,sessionId:null,sessionName:""}),onConfirm:()=>{eq.sessionId&&F?.(eq.sessionId)},title:J("sessions.deleteTitle"),message:J("sessions.deleteMessage",{name:eq.sessionName}),confirmText:J("common.delete")}),eY&&(0,n.jsx)(rd,{busRef:E,fileBus:X,workspacePath:tf?.path||"",onClose:()=>n9.getState().setOpen(!1)})]})});s(55162);let rb="js|jsx|ts|tsx|css|json|md|txt|html|xml|yaml|yml|sh|py|rb|go|java|c|cpp|h",rg={WEB_HTTP:/https?:\/\/[^\s]+/g,WEB_LOCALHOST:/localhost:\d+[^\s]*/g,FILE_ABSOLUTE:RegExp(`\\/[^\\s:]+\\.(${rb})\\b`,"g"),FILE_RELATIVE:RegExp(`(?:\\.{1,2}\\/)?[^\\s:/]+(?:\\/[^\\s:/]+)*\\.(${rb})\\b`,"g"),FILE_WITH_LINE:RegExp(`[^\\s]+\\.(${rb}):\\d+(?::\\d+)?`,"g"),GIT_MODIFIED:/modified:\s+[^\s]+/g};function rv(e){let{text:t,position:s,onOpenUrl:r,onCopy:l,onAddToNote:a,onClose:i}=e,{t:o}=(0,eu.s)(),c=function(e){let t=e.trim(),s=t.match(rg.WEB_HTTP);if(s)return{isUrl:!0,isFile:!1,match:s[0]};let n=t.match(rg.WEB_LOCALHOST);if(n)return{isUrl:!0,isFile:!1,match:`http://${n[0]}`};let r=t.match(rg.FILE_WITH_LINE);if(r)return{isUrl:!1,isFile:!0,match:r[0]};let l=t.match(rg.FILE_ABSOLUTE);if(l)return{isUrl:!1,isFile:!0,match:l[0]};let a=t.match(rg.FILE_RELATIVE);return a?{isUrl:!1,isFile:!0,match:a[0]}:{isUrl:!1,isFile:!1,match:t}}(t),d=e=>{if("openUrl"===e&&c.isUrl)r(c.match);else if("copy"===e)l(t);else if("addNote"===e&&a)return void a(t);i()};return(0,n.jsx)("div",{className:"fixed inset-0 scrim fade-in flex items-center justify-center z-[60]",onMouseDown:e=>{e.preventDefault(),i()},children:(0,n.jsxs)("div",{className:"menu-popover overflow-hidden min-w-[200px] pop-in",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: ",t.length>30?t.substring(0,30)+"...":t]})}),(0,n.jsxs)("div",{className:"p-2",children:[c.isUrl&&(0,n.jsxs)("button",{onClick:()=>d("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:()=>d("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"})]}),a&&(0,n.jsxs)("button",{onClick:()=>d("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:o("terminalPane.addToNote")})]}),(0,n.jsxs)("button",{onClick:i,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 ry=new Map,rw={count:0,perRepo:{}};function rj(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;e.refs<=0||e.fileBus?.gitWorkspaceChangedCount?.(t,void 0,s).then(r=>{var l;let a;if(!r?.success){n>0&&setTimeout(()=>rj(e,t,s,n-1),1500);return}let i=r.count||0,o=r.perRepo||{};e.state.count===i&&(l=e.state.perRepo,(a=Object.keys(l)).length===Object.keys(o).length&&a.every(e=>l[e]===o[e]))||(e.state={count:i,perRepo:o},e.subs.forEach(t=>t(e.state)))})}function rk(e,t){let{enabled:s=!0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},[n,l]=(0,r.useState)(rw);return(0,r.useEffect)(()=>{let n;if(!e||!t||!s)return;let r=((n=ry.get(e))?n.refs++:(n={state:rw,stop:null,refs:0,subs:new Set,fileBus:t,refreshNow:null,refreshTimer:null},ry.set(e,n),n.refs++,n.refreshNow=()=>{clearTimeout(n.refreshTimer),n.refreshTimer=setTimeout(()=>rj(n,e,!0),_.HF)},_.vb.forEach(e=>window.addEventListener(e,n.refreshNow)),rj(n,e),n.stop=nb(()=>rj(n,e),eg.KA)),n);return r.subs.add(l),l(e=>e===r.state?e:r.state),()=>{let t;r.subs.delete(l),(t=ry.get(e))&&(t.refs--,t.refs>0||(t.stop?.(),clearTimeout(t.refreshTimer),_.vb.forEach(e=>window.removeEventListener(e,t.refreshNow)),ry.delete(e)))}},[e,t,s]),n}var rN=s(65621),rC=s(32341),rS=s(76697),rT=s(39109),rE=s(94497),rR=s(42457),rM=s(86377);let r$={...rM.aC,default:rM.aC.dark};function rz(e){let{joinClaimed:t,joining:s,gapBusy:n}=e;return!!(t?.current||s?.current||n)}function rP(e){return e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e instanceof Uint8Array?e:new Uint8Array(e):"string"==typeof e?e:String(e)}let rA=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 rI(e,t,s,n,r){if(!e||e._core?._isDisposed)return;let l=rP(t);r?r.write(l):e.write(l),s&&(s.current.push(l),n.current+=rA(l))}let rD="stale",rL=()=>{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},rB=/^- \[([ xX])\] ?/;function rF(e){return e.map(e=>`- [${e.done?"x":" "}] ${e.text}`).join("\n")}let rO=new Map,r_=e=>{try{navigator.clipboard?.writeText(e).catch(()=>{})}catch{}};function rK(e){let{bus:t,sessionId:s,appendOnOpen:l,onClose:a,variant:i="modal",pinned:o=!1,onPin:c,rightSlot:d=null}=e,{t:u}=(0,eu.s)(),m=(0,f.B)(e=>e.noteChips),x=(0,f.B)(e=>e.addNoteChip),p=(0,f.B)(e=>e.removeNoteChip),[h,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(""),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(()=>new Set),[N,C]=(0,r.useState)(null),[S,T]=(0,r.useState)(""),[E,R]=(0,r.useState)(null),M=(0,r.useRef)(new Map),$=(0,r.useRef)(null),[z,P]=(0,r.useState)(!1),[A,I]=(0,r.useState)(""),D=(0,r.useRef)([]),L=(0,r.useRef)(null),B=(0,r.useRef)(0),F=(0,r.useRef)(null),O=(0,r.useRef)(l),[_]=(0,r.useState)(()=>Symbol("note")),K=(0,r.useRef)(c);(0,r.useEffect)(()=>{K.current=c});let W=e=>e.map(e=>({...e,id:++B.current})),H=()=>{let e=O.current;return(O.current=null,e)?e.split("\n").map(e=>e.trim()).filter(Boolean).map(e=>({done:!1,text:e})):[]},q=(0,r.useCallback)(e=>{t?.emit("saveNote",{sessionId:s,text:e},()=>{})},[t,s]),U=(0,r.useCallback)(e=>{let t=e(D.current||[]);D.current=t,rO.set(s,t),b(t),window.dispatchEvent(new CustomEvent(eg.aD,{detail:{sessionId:s,items:t,from:_}})),F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{F.current=null,q(rF(D.current))},500)},[q,s,_]);(0,r.useEffect)(()=>{if(!t||!s)return;let e=!1,n=rO.get(s),r=(e,t)=>{for(let t of e)t.id>B.current&&(B.current=t.id);D.current=e,rO.set(s,e),b(e),t&&q(rF(e))};if(n){let e=H();r(e.length?[...n,...W(e)]:n,e.length>0);return}return t.emit("getNote",{sessionId:s},t=>{if(e)return;let s=((t?.success?t.text:"")||"").split("\n").map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.match(rB);return t?{done:" "!==t[1],text:e.slice(t[0].length)}:{done:!1,text:e}}),n=H();n.length&&!s.length&&K.current?.(!0),r(W([...s,...n]),n.length>0)}),()=>{e=!0}},[t,s,q]),(0,r.useEffect)(()=>{let e=e=>{let t=e.detail;if(t&&t.sessionId===s&&t.from!==_&&null==$.current){for(let e of(F.current&&(clearTimeout(F.current),F.current=null),t.items))e.id>B.current&&(B.current=e.id);D.current=t.items,rO.set(s,t.items),b(t.items)}};return window.addEventListener(eg.aD,e),()=>window.removeEventListener(eg.aD,e)},[s,_]),(0,r.useEffect)(()=>()=>{F.current&&(clearTimeout(F.current),F.current=null,q(rF(D.current)))},[q]),(0,r.useEffect)(()=>{let e=L.current;if(!e)return;let t=window.innerWidth>=eg.jK?eg.hp:eg.bs;e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,t)}px`},[g]);let X=e=>{e.preventDefault();let t=g.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);t.length&&((0,ed.e)(),v(""),D.current.length||c?.(!0),U(e=>[...e,...W(t.map(e=>({done:!1,text:e})))]),L.current?.focus())},V=e=>{(0,ed.e)(),U(t=>t.map(t=>t.id===e?{...t,done:!t.done}:t))},G=()=>{let e=S.trim();e&&null!=N&&U(t=>t.map(t=>t.id===N?{...t,text:e}:t)),C(null)},J=()=>{let e=A.trim();e&&!ee.includes(e)&&x(e),I(""),P(!1)},Y=(h?.length||0)>0,Z=h?.filter(e=>e.done).length||0,Q=(h?.length||0)-Z,ee=[...eg.TM,...Array.isArray(m)?m:[]];if("pinned"===i){if(!Y)return null;let e=h.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:()=>V(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:u("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:u("note.allDone")}),(0,n.jsxs)("span",{className:"flex-shrink-0 text-text-subtle",children:[Z,"/",h.length]}),d]})}return"u"<typeof document?null:(0,se.createPortal)((0,n.jsx)("div",{className:"modal-overlay z-[60] scrim",onMouseDown:e=>{e.preventDefault(),a()},children:(0,n.jsxs)("div",{className:"card-elev w-full max-w-lg h-[55%] min-h-0 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 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:u("note.title")}),Y&&(0,n.jsxs)("span",{className:"text-xs text-text-subtle flex-shrink-0",children:[Z,"/",h.length]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[c&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),c(!o),o||a()},className:`p-2 hover:bg-surface-2 rounded-brand transition-colors ${o?"text-brand-500":"text-text"}`,title:o?u("note.unpin"):u("note.pin"),children:o?(0,n.jsx)(el.Ze,{size:16}):(0,n.jsx)(el.yU,{size:16})}),(0,n.jsx)("button",{onClick:()=>{let e=(h||[]).filter(e=>!e.done);e.length&&((0,ed.e)(),k(new Set(e.map(e=>e.id))),r_(e.map(e=>e.text).join("\n")),w(!0),setTimeout(()=>w(!1),1200))},disabled:!Q,className:"p-2 hover:bg-surface-2 text-text rounded-brand transition-colors disabled:opacity-40",title:u("note.copyTodo"),children:y?(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:!Z,className:"p-2 hover:bg-surface-2 text-red-400 rounded-brand transition-colors disabled:opacity-40",title:u("note.clearDone"),children:(0,n.jsx)(el.TB,{size:16})}),(0,n.jsx)("button",{onClick:a,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===h?null:Y?(0,n.jsx)("ul",{className:"py-1",children:h.map(e=>(0,n.jsxs)("li",{ref:t=>{t?M.current.set(e.id,t):M.current.delete(e.id)},className:`flex items-center gap-1.5 px-3 py-1.5 ${E===e.id?"relative z-10 bg-surface-2 shadow-elev select-none":null!=E?"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=(D.current||[]).map(e=>e.id),n=s.indexOf(t.id),r=M.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=M.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),M.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 ${E===e.id?"text-brand-500":"text-text-subtle/60 hover:text-text-subtle"}`,title:u("note.drag"),children:(0,n.jsx)(el.f2,{size:13})}),(0,n.jsx)("button",{onClick:()=>V(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"})}),N===e.id?(0,n.jsx)("input",{value:S,onChange:e=>T(e.target.value),onKeyDown:e=>{"Enter"===e.key&&G(),"Escape"===e.key&&C(null)},onBlur:G,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)(),C(e.id),T(e.text)},className:`flex-1 min-w-0 text-sm break-words cursor-text ${e.done?"text-text-subtle line-through":"text-text"}`,title:u("note.edit"),children:e.text}),(0,n.jsx)("button",{onClick:()=>{let t;return(0,ed.e)(),void((t=new Set(j)).has(e.id)?t.delete(e.id):t.add(e.id),k(t),r_((h||[]).filter(e=>t.has(e.id)).map(e=>e.text).join("\n")))},className:`p-1.5 rounded-brand transition-colors flex-shrink-0 ${j.has(e.id)?"text-brand-500 bg-brand-500/10":"text-text-subtle hover:text-text hover:bg-surface-2"}`,title:u("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:u("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:u("note.placeholder")})}),null!==h&&(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:[ee.map(e=>(0,n.jsxs)("div",{className:"flex items-center flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),t?.emit("input",{sessionId:s,data:`${e}
9
+ ${rF(h||[])}`}),setTimeout(()=>t?.emit("input",{sessionId:s,data:"\r"}),eg.YS),a()},disabled:!Y,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:u("note.sendHint"),children:e}),!eg.TM.includes(e)&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),p(e)},className:"p-1 text-text-subtle hover:text-red-400 transition-colors",title:u("note.removeChip"),children:(0,n.jsx)(el.X,{size:10})})]},e)),z?(0,n.jsx)("form",{onSubmit:e=>{e.preventDefault(),J()},className:"flex items-center flex-shrink-0",children:(0,n.jsx)("input",{value:A,onChange:e=>I(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(P(!1),I(""))},onBlur:J,placeholder:u("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)(),P(!0)},className:"p-1 text-text-subtle hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0",title:u("note.addChip"),children:(0,n.jsx)(el.FW,{size:14})})]}),null!==h&&(0,n.jsxs)("form",{onSubmit:X,className:"flex items-end gap-2 p-3 border-t border-border flex-shrink-0",children:[(0,n.jsx)("textarea",{ref:L,value:g,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&window.innerWidth>=eg.jK&&X(e)},rows:1,placeholder:u("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:!g.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:u("note.addLines"),children:(0,n.jsx)(el.FW,{size:16})})]})]})}),document.body)}function rW(e){let{onOpenRemote:t,onOpenMobile:s}=e,{t:r}=(0,eu.s)(),l=(0,f.B)(e=>e.hiddenHeaderButtons),a=(0,P.rh)(e=>e.hosts[e.currentKey]?.mobileDeviceCount)||0,i="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:[!l.includes("remote")&&t&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),t()},className:i,title:r("menu.remoteDesktop"),children:(0,n.jsx)(el.VA,{size:16})}),!l.includes("mobile")&&s&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),s()},className:`${i} ${a>0?"!text-green-400":""}`,title:a>0?r("mobile.deviceRunning",{count:a}):r("mobile.androidDevice"),children:(0,n.jsx)(el.wO,{size:16})})]})}function rH(e){let{isFocused:t,onActivate:s}=e,n=e=>(function(e,t){let{isFocused:s,onActivate:n}=t,r=e.target;if(r?.closest?.("button,a,label,select,[role='dialog'],[data-pane-control]")){e.preventDefault(),e.stopPropagation();return}"touchstart"!==e.type||r?.closest?.("input, textarea")||e.preventDefault(),s||n?.()})(e,{isFocused:t,onActivate:s});return{onMouseDown:n,onTouchStart:n}}let rq="p-2 sm:p-1.5 bg-surface-2/60 hover:bg-surface-3 text-text rounded-full transition-all duration-150 ease-out active:scale-[0.94] backdrop-blur-md ring-1 ring-[var(--lg-edge)] shadow-[inset_0_1px_0_var(--lg-rim),var(--lg-lift-chip)]",rU="sm:w-3.5 sm:h-3.5",rX=(0,r.memo)(function(e){let{bus:t,workspacePath:s,connected:l,sessionId:a,sessionName:i,sessionState:o,isVisible:c,isFocused:d,mountDelay:m=0,onActivate:x,onRegisterApi:p,onPasteFallback:h,showFocusBorder:b=!1,fileBus:g,bgIndex:v=0,onOpenArtifact:y,onOpenRemote:w,onOpenMobile:j}=e,{t:k}=(0,eu.s)(),{theme:N}=(0,t7.D)(),C=ez(a),S=o||C||"idle",T=(0,r.useRef)(null),E=(0,r.useRef)(null),R=(0,r.useRef)({width:0,height:null}),[M,$]=(0,r.useState)(null),[z,A]=(0,r.useState)(!1),[I,D]=(0,r.useState)(!1),[B,F]=(0,r.useState)(!1),[O,_]=(0,r.useState)(null),K=(0,f.B)(e=>e.setRightPanelTab),W=(0,f.B)(e=>e.openRightPanel),H=(0,f.B)(e=>e.setRightPanelRoot),q=(0,u.d)(e=>e.bus),U=void 0===t?q:t,X=(0,f.B)(e=>e.cwdBySession[a]),V=(0,f.B)(e=>e.terminalTheme),G=(0,f.B)(e=>e.terminalBackgroundOpacity),J=(0,f.B)(e=>e.customBackgrounds),Y=(0,f.B)(e=>e.terminalBackgrounds),Z=(0,f.B)(e=>e.backgroundBySession[a]),Q=(0,eg.$Z)(Z,Y,J,v),ee=(0,f.B)(e=>e.showFolderButton),et=(0,f.B)(e=>e.showNoteButton),es=(0,f.B)(e=>e.artifactsBySession[a]),en=(0,f.B)(e=>!!e.pinnedNotes?.[a]),er=(0,f.B)(e=>e.setNotePinned),ea=en&&et,ei=(0,r.useRef)(a);(0,r.useEffect)(()=>{ei.current=a},[a]);let[eo,ec]=(0,r.useState)(!1),[em,ex]=(0,r.useState)(null),ep=(0,r.useCallback)(()=>{ek.getState().clearNotification(a)},[a]),eh=(0,eg.RS)(Q,J),{termRef:ef,cwdRef:eb,cwd:ev,termReady:ey,joining:ew,doResize:ej,reload:eN,focus:eC,stopMomentum:eS,historyFetching:eT}=function(e){let{bus:t,sessionId:s,theme:n,terminalTheme:l,isVisible:a,isFocused:i,containerRef:o,mountDelay:c=0,bgKey:d="none",onInput:m,onSelectionMade:x}=e,p=(0,r.useCallback)(()=>{let e=P.rh.getState(),t=e$(s).head||e.currentKey;return!!e.hosts[t]?.updating},[s]),h=(0,u.d)(e=>e.bus),b=t||h,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),E=(0,r.useRef)(null),R=(0,r.useRef)(!1),M=(0,r.useRef)(!1),$=(0,r.useRef)(null),z=(0,r.useRef)(null),[A,I]=(0,r.useState)(null),D=(0,f.B)(e=>e.webglEnabled),B=(0,f.B)(e=>e.fontSize),F=(0,r.useRef)(x);(0,r.useEffect)(()=>{F.current=x},[x]);let O=(0,r.useRef)(!1),_=(0,r.useRef)(null),[K,W]=(0,r.useState)(!1),H=(0,r.useRef)(null),q=(0,r.useRef)([]),U=(0,r.useRef)(0),X=(0,r.useRef)(0),V=(0,r.useRef)(!1),G=(0,r.useRef)(0),J=(0,r.useRef)(0),Y=(0,r.useRef)(null),Z=(0,r.useRef)(null),Q=(0,r.useRef)(!1),ee=(0,r.useRef)(!1),et=(0,r.useRef)(null),[es,en]=(0,r.useState)(!1),er=(0,r.useRef)([]),el=(0,r.useRef)(0),ea=(0,r.useRef)(null),ei=(0,r.useRef)(null),eo=(0,r.useRef)(null),ec=(0,r.useRef)(a);(0,r.useEffect)(()=>{ec.current=a},[a]);let[eu,em]=(0,r.useState)(!1),ex=(0,r.useRef)(null),ep=(0,r.useRef)(!1),eh=(0,r.useRef)(null),ef=(0,r.useRef)(0),eb=(0,r.useRef)(0),ev=(0,r.useCallback)(()=>{let e=g.current;if(!e||!b)return;let{cols:t,rows:n}=e;t<eg.j4||n<eg.dU||(H.current={cols:t,rows:n},b.emit("resize",{sessionId:s,cols:t,rows:n}))},[b,s]),ey=(0,r.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=!0===e||e?.force===!0,n=!!e?.join;t&&(R.current=!0),n&&(M.current=!0),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{C.current=null;let e=g.current,t=v.current,n=o.current;if(!e||e._isDisposed||!t||!b||!n?.offsetWidth||!n?.offsetHeight)return;t.fit();let{cols:r,rows:l}=e;if(r<eg.j4||l<eg.dU)return;let a=H.current,i=R.current,c=M.current;if(R.current=!1,M.current=!1,!i&&a&&a.cols===r&&a.rows===l&&!c){ee.current=!1;return}H.current={cols:r,rows:l},b.emit("resize",{sessionId:s,cols:r,rows:l}),c&&!E.current&&(ee.current=!1),c&&E.current&&(ee.current=!0,e.reset(),E.current(r,l))},eg.BM)},[b,s,o]);(0,r.useEffect)(()=>{S.current=ey},[ey]),(0,r.useEffect)(()=>{let e,t,r,a;if(!o.current||!b||!s||g.current)return;ef.current=0,Z.current=null;let i=new rN.B({...eg.Pj,fontSize:(0,eg.ar)(B),allowTransparency:!0,theme:(0,eg.pt)((0,rM.In)(n,l)||r$.dark,"dark"===n?d:"none")}),m=new rC.Y;i.loadAddon(m),i.loadAddon(new rT.I),i.unicode.activeVersion="11",g.current=i,v.current=m,i.open(o.current);let x=function(e,t){if(!rL())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 m=e=>{e.target===s&&(c=e.key||"",o=(229===e.keyCode||229===e.which||"Process"===e.key)&&!e.isComposing)},x=e=>{e.target===s&&(229===e.keyCode||229===e.which)&&setTimeout(()=>{o=!1},50)},p=()=>{o=!1,d=""},h=e=>{e.data&&(d=e.data)},f=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",m,{capture:!0}),s.addEventListener("keyup",x,{capture:!0}),s.addEventListener("compositionstart",p,{capture:!0}),s.addEventListener("compositionupdate",h,{capture:!0}),s.addEventListener("compositionend",f,{capture:!0}),t&&(t.addEventListener("compositionupdate",h,{capture:!0}),t.addEventListener("compositionend",f,{capture:!0})),()=>{n._inputEvent=i,r&&(l&&(r._handleAnyTextareaChanges=l),a&&(r._finalizeComposition=a)),s.removeEventListener("keydown",m,{capture:!0}),s.removeEventListener("keyup",x,{capture:!0}),s.removeEventListener("compositionstart",p,{capture:!0}),s.removeEventListener("compositionupdate",h,{capture:!0}),s.removeEventListener("compositionend",f,{capture:!0}),t&&(t.removeEventListener("compositionupdate",h,{capture:!0}),t.removeEventListener("compositionend",f,{capture:!0}))}}(i,o.current),p=function(e){if(!rL()||!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)}}(o.current);e=[],t=0,r=null,y.current={write:s=>{let n=s instanceof Uint8Array||"string"==typeof s?s.length:String(s).length;n<=512&&0===t&&null===r?i.write(s instanceof Uint8Array||"string"==typeof s?s:String(s)):(e.push(s instanceof Uint8Array||"string"==typeof s?s:String(s)),t+=n,null===r&&(r=requestAnimationFrame(a)))},flush:a=()=>{if(r=null,e.length){if(1===e.length)i.write(e[0]);else if(e.every(e=>e instanceof Uint8Array)){let s=new Uint8Array(t),n=0;for(let t of e)s.set(t,n),n+=t.length;i.write(s)}else{let t="";for(let s of e)t+="string"==typeof s?s:new TextDecoder().decode(s);i.write(t)}e=[],t=0}},dispose:()=>{null!==r&&cancelAnimationFrame(r),r=null,e=[],t=0}},eg.M8.search&&(_.current=new rE.n,i.loadAddon(_.current));let h=o.current,R=e=>{i.options.smoothScrollDuration=0!==e.deltaMode||Math.abs(e.deltaY)>=50?eg.Gp.smoothScrollDuration:0};h.addEventListener("wheel",R,{passive:!0});let M=null,$=!1;j.current=()=>{if(!M&&!$&&"off"!==eg.Gp.gpuAcceleration)try{w.current=M=new rS.o,M.onContextLoss(()=>{M?.dispose(),M=null,w.current=null}),i.loadAddon(M),eg.M8.image&&i.loadAddon(new rR.W),m.fit()}catch(e){$=!0,M=null,console.warn("WebGL unavailable, using DOM renderer")}},k.current=()=>{w.current&&(w.current.dispose(),w.current=null,M=null,m.fit(),ev(),i.refresh(0,i.rows-1))};let P=0,A=()=>{P++;let e=o.current?.offsetWidth||0,t=o.current?.offsetHeight||0;P>50?W(!0):i.element&&e>=100&&t>=100?(m.fit(),ev(),W(!0)):setTimeout(A,50)};setTimeout(A,50);let D=new ResizeObserver(()=>S.current?.());D.observe(o.current);let F=function(e){let{fetchOlder:t,isAtTop:s,max:n,delayMs:r}=e,l=0,a=null,i=()=>{a&&(clearTimeout(a),a=null)};return{gesture(){i(),t(!1)&&(l=0)},settled(){if(!s()){l=0;return}l>=n||(l+=1,i(),a=setTimeout(()=>{a=null,t(!0)},r))},cancel:i}}({fetchOlder:function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=i.buffer.active;if(eg.iW.disabled||V.current||"alternate"===t.type||X.current<=0||X.current-U.current<eg.iW.minFetchBytes)return!1;let n=Date.now();if(!e&&n-G.current<eg.iW.guardMs)return!1;let r=t.viewportY<=eg.iW.topThresholdLines;return(!!e||!!ep.current)&&(r?!!u.d.getState().connected&&(V.current=!0,G.current=n,J.current=U.current,em(!0),b.emit("requestHistory",{sessionId:s,have:J.current},e=>{if(!e||!e.success){V.current=!1,em(!1);return}e.prefixLen||(V.current=!1,em(!1)),X.current=e.total||X.current}),!0):(e||(ep.current=!1),!1))},isAtTop:()=>(i.buffer.active.viewportY??0)<=eg.iW.topThresholdLines,max:eg.iW.chainMax,delayMs:eg.iW.chainDebounceMs});eh.current=()=>F.settled();let K=()=>F.gesture();ea.current=i.onScroll(()=>{(i.buffer.active.viewportY??0)>eg.iW.topThresholdLines&&(ep.current=!1)}),i.textarea?.addEventListener("keyup",K),ex.current=K;let H=null,es=null,ed=!1,eu=0,ey=function(e){let{emit:t,writeChunk:s,flush:n,onGapChunk:r,onFallback:l,log:a,getFromSeq:i}=e,o=null,c=e=>{clearTimeout(e.timer),e.timer=setTimeout(()=>u(e,"stalled"),eg.VE)},d=e=>{if(!e.settled&&o===e){for(let t of(e.settled=!0,clearTimeout(e.timer),e.timer=null,e.pending))s(t.data),null!=t.seq&&r(t.seq);n?.(),o=null,a(`gap recovered (${e.received}/${e.expected} chunks, ${e.pending.length} pending flushed)`)}},u=(e,t)=>{e.settled||o!==e||(e.settled=!0,clearTimeout(e.timer),e.timer=null,o=null,a(`gap ${t} (${e.fromSeq}..${e.toSeq}) → reset+rejoin`),l())};return{start:function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(o)return;let n=i();if(e<n)return;a(`seq gap (last=${n-1} → ${e+1}) → requestGap ${n}..${e}`);let r={pending:[...s],fromSeq:n,toSeq:e,settled:!1,timer:null,expected:null,received:0,seen:new Set};o=r,c(r),t({fromSeq:n,toSeq:e},e=>{if(!r.settled&&o===r){if(!e?.hit)return u(r,"miss");r.expected=e.count??0,r.received>=r.expected&&d(r)}})},queueLive:function(e,t){return!!o&&(o.pending.push({data:e,seq:t}),!0)},handleGapChunk:function(e,t){let n=o;return!!n&&null!=t&&!(t<n.fromSeq)&&!(t>n.toSeq)&&(!!n.seen.has(t)||(c(n),s(e),r(t),n.seen.add(t),n.received=n.seen.size,null!=n.expected&&n.received>=n.expected&&d(n),!0))},cancel:function(){o&&(clearTimeout(o.timer),o=null)},isBusy:()=>null!==o}}({emit:(e,t)=>b.emit("requestGap",{sessionId:s,...e},t),writeChunk:e=>{let t=y.current;rI(i,e,q,U,t),t?.flush()},flush:()=>y.current?.flush(),onGapChunk:e=>{Z.current=e},onFallback:()=>et.current?.("gap fallback"),log:e=>(0,L.Lq)("reconnect",e),getFromSeq:()=>(Z.current??0)+1}),ew=e=>{if(g.current){if(!u.d.getState().connected){ei.current=e;return}ei.current=null,(0,L.Lq)("reconnect",`reset+rejoin (${e})`),ee.current=!0,T.current?.(!0)}};et.current=ew;let ej=e=>{if(!ec.current||ed){ei.current=e;return}H&&clearTimeout(H),H=setTimeout(()=>(e=>{if(H=null,!ec.current||!u.d.getState().connected){ei.current=e;return}if(rz({joinClaimed:ee,joining:Q,gapBusy:ey.isBusy()}))return;if(null==Z.current)return ew(`${e}: no seq baseline`);let t=++eu;ed=!0,es=setTimeout(()=>{es=null,ed=!1,eu++,(0,L.Lq)("reconnect",`${e}: peekSeq timed out → retry`),ei.current=ei.current||e,eC()},eg.zm),b.emit("peekSeq",{sessionId:s},s=>{if(t!==eu)return;clearTimeout(es),es=null,ed=!1;let n=s?.seq;if(null==n)return ew(`${e}: agent has no seq`);let r=Z.current??0;return n<r?ew(`${e}: seq rewound ${r} → ${n}`):n===r?((0,L.Lq)("reconnect",`${e}: nothing missed (seq ${r})`),eC()):rz({joinClaimed:ee,joining:Q,gapBusy:ey.isBusy()})?eC():void((0,L.Lq)("reconnect",`${e}: peekSeq ${r} → ${n} → gapFetch`),ey.start(n))})})(e),eg.qw)};eo.current=ej;let ek=0,eN=setInterval(()=>{let e=ef.current;!e||ek===e||Date.now()-e<eg.sB||(ek=e,ej("quiet"))},eg.pl);function eC(){let e=ei.current;e&&(ei.current=null,ej(e))}let{handleOutput:eS}=function(e){let{sessionId:t,term:s,writeBatcherRef:n,gapFetch:r,refs:l,setHistoryFetching:a}=e,i=e=>{var t;let n,r=rP(e),i=s.buffer.active.viewportY,o=s.buffer.active.baseY;r=function(e,t){let{haveAtEmit:s,historyBytes:n}=t,r=Math.max(0,s>0?n-s:0);if(r<=0)return e;let l=Math.max(0,rA(e)-r);return"string"!=typeof e&&(l=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,l)),"string"==typeof e?e.slice(0,l):e.subarray(0,l)}(r,{haveAtEmit:l.historyHaveAtEmitRef.current,historyBytes:l.historyBytesRef.current}),l.historyHaveAtEmitRef.current=0;let c=rA(r);if(0===c){l.historyFetchingRef.current=!1,a(!1),l.onPrefixSettledRef?.current?.();return}l.historyMirrorRef.current.unshift(r),l.historyBytesRef.current+=c,s.reset(),s.write((t=l.historyMirrorRef.current,n=new TextDecoder,t.map(e=>"string"==typeof e?e:n.decode(e,{stream:!0})).join("")),()=>{requestAnimationFrame(()=>{let e=function(e){let{oldViewportY:t,baseYBefore:s,baseYAfter:n}=e;return Math.max(0,Math.min(t+Math.max(0,n-s),n))-n}({oldViewportY:i,baseYBefore:o,baseYAfter:s.buffer.active.baseY});e<0&&s.scrollLines(e),l.historyFetchingRef.current=!1,a(!1),l.onPrefixSettledRef?.current?.()})})};return{handleOutput:e=>{if(e.sessionId!==t)return;e.data instanceof ArrayBuffer&&(e={...e,data:new Uint8Array(e.data)}),l.lastOutputAtRef.current=Date.now();let a=e.data?.length||0;l.outputTotalRef.current+=a,(e.replay||e.isHistoryPrefix)&&(0,L.Lq)("recv",`len=${a} replay=${!!e.replay} prefix=${!!e.isHistoryPrefix} total=${l.outputTotalRef.current}`);let o=e.data;if("b64"===e.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(l.awaitingTuiOutputRef.current=!1,e.isHistoryPrefix){if(e.parts>1){let t=l.prefixFragsRef.current;if(0!==e.part&&t&&t.parts===e.parts||(t={parts:e.parts,chunks:[]},l.prefixFragsRef.current=t),t.chunks[e.part]=o,t.chunks.filter(Boolean).length<e.parts)return;l.prefixFragsRef.current=null,(0,L.Lq)("recv",`prefix reassembled from ${e.parts} parts (${t.chunks.reduce((e,t)=>e+t.length,0)}B)`);let s=new Uint8Array(t.chunks.reduce((e,t)=>e+t.length,0)),n=0;for(let e of t.chunks)s.set(e,n),n+=e.length;i(s);return}i(o);return}if(e.replay){let t=rP(o);n.current?.write(t),n.current?.flush(),null!=e.seq&&(l.lastSeqRef.current=e.seq);return}if(e.gap)return void r.handleGapChunk(o,e.seq);if(l.joiningRef.current)return void l.joinQueueRef.current.push({data:o,seq:e.seq});if(!r.queueLive(o,e.seq)){if(null!=e.seq){var c,d;let t=(c=l.lastSeqRef.current,d=e.seq,null==c?"init":d===c+1?"none":d>c+1?"gap":rD);if("gap"===t)return void r.start(e.seq-1,[{data:o,seq:e.seq}]);if(t===rD)return;l.lastSeqRef.current=e.seq}l.userAtTopRef.current=!1,rI(s,o,l.historyMirrorRef,l.historyBytesRef,n.current)}},replayWithPrefix:i}}({sessionId:s,term:i,writeBatcherRef:y,gapFetch:ey,refs:{joiningRef:Q,joinQueueRef:er,lastSeqRef:Z,lastOutputAtRef:ef,outputTotalRef:eb,awaitingTuiOutputRef:O,userAtTopRef:ep,historyFetchingRef:V,historyHaveAtEmitRef:J,historyMirrorRef:q,historyBytesRef:U,prefixFragsRef:Y,onPrefixSettledRef:eh},setHistoryFetching:em});b.on("output",eS);let eT=e=>{e&&e.sessionId===s&&e.cwd&&(z.current=e.cwd,I(e.cwd),f.B.getState().setCwd(s,e.cwd))};b.on("cwdChange",eT);let eE=function(e){let{bus:t,sessionId:s,term:n,fitAddon:r,writeBatcherRef:l,doResizeRef:a,fireJoinRef:i,refs:o,setCwd:c}=e,d=null,u=function(){arguments.length>0&&void 0!==arguments[0]&&arguments[0],o.historyMirrorRef.current=[],o.historyBytesRef.current=0,o.historyTotalRef.current=0,o.historyFetchingRef.current=!1,o.userAtTopRef.current=!1,requestAnimationFrame(()=>a.current?.({join:!0})),i.current=(e,a)=>{let i=f.B.getState().agentCaps?.joinSessionSize?{sessionId:s,cols:e,rows:a}:s;o.joiningRef.current=!0,o.setJoining(!0),o.joinQueueRef.current=[];let m=++o.joinGenRef.current;(0,L.Lq)("join",`emit gen=${m} sid=${String(s).slice(-8)} cols=${e} rows=${a}`),d&&clearTimeout(d),d=setTimeout(()=>{if(d=null,m!==o.joinGenRef.current)return;(0,L.Lq)("join",`ack timeout gen=${m} (${eg.eE}ms) → clear spinner`),o.joiningRef.current=!1,o.joinClaimedRef.current=!1,o.setJoining(!1);let e=o.joinQueueRef.current;o.joinQueueRef.current=[];let t=l.current;for(let s of e)rI(n,s&&"object"==typeof s&&"data"in s?s.data:s,o.historyMirrorRef,o.historyBytesRef,t);t?.flush()},eg.eE),t.emit("joinSession",i,e=>{if(d&&(clearTimeout(d),d=null),m!==o.joinGenRef.current)return void(0,L.Lq)("join",`stale ack gen=${m} (current=${o.joinGenRef.current})`);let a=e||{};if((0,L.Lq)("join",`ack gen=${m} sid=${String(s).slice(-8)} success=${!!a.success} total=${a.total} replaySize=${a.replaySize}`),a.success){setTimeout(()=>{if(m!==o.joinGenRef.current||n._core?._isDisposed)return;let e=o.joinQueueRef.current;o.joinQueueRef.current=[];let t=l.current,s=null;for(let r of e){let e=r&&"object"==typeof r&&"data"in r?r.data:r;r?.seq!=null&&(s=r.seq),rI(n,e,o.historyMirrorRef,o.historyBytesRef,t)}let r=a.seq??null;(null!=r||null!=s)&&(o.lastSeqRef.current=Math.max(r??-1,s??-1)),t?.flush(),o.joiningRef.current=!1,o.joinClaimedRef.current=!1,o.setJoining(!1)},0),o.historyTotalRef.current=a.total||0,a.cwd&&(o.cwdRef.current=a.cwd,c(a.cwd),f.B.getState().setCwd(s,a.cwd));let e=f.B.getState().consumeStartup(s);e&&((0,L.Lq)("join",`startup cmd queued (${e})`),setTimeout(()=>t.emit("input",{sessionId:s,data:`${e}\r`}),eg.YA)),setTimeout(()=>r.fit(),200)}else{if("rtc-closed"===a.error){(0,L.Lq)("join","rtc-closed during join ack → retry via fallback carrier"),u(!0);return}o.joiningRef.current=!1,o.joinClaimedRef.current=!1,o.setJoining(!1),o.joinQueueRef.current=[],n.write(`\r
10
+ \x1b[1;31mError: ${a.error||"Failed to join session"}\x1b[0m\r
11
+ `)}})}};return u}({bus:b,sessionId:s,term:i,fitAddon:m,writeBatcherRef:y,doResizeRef:S,fireJoinRef:E,refs:{historyMirrorRef:q,historyBytesRef:U,historyTotalRef:X,historyFetchingRef:V,userAtTopRef:ep,joiningRef:Q,joinClaimedRef:ee,joinQueueRef:er,joinGenRef:el,lastSeqRef:Z,cwdRef:z,setJoining:en},setCwd:I}),eR=c>0?setTimeout(eE,c):null;eR||eE(),T.current=eE;let eM=()=>{if(g.current){var e;(e={historyFetching:V,historyHaveAtEmit:J,awaitingTuiOutput:O,joining:Q,joinClaimed:ee,joinQueue:er,prefixFrags:Y}).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),ey.cancel(),F.cancel(),clearTimeout(es),es=null,ed=!1,eu++,em(!1),en(!1),ej("reconnect")}};b.on("connect",eM);let e$=()=>setTimeout(()=>{let e=g.current,t=v.current;e&&!e._isDisposed&&t&&(t.fit(),t.fit(),S.current?.({force:!0}))},eg.Uc);window.addEventListener("orientationchange",e$);let ez=()=>{!document.hidden&&g.current&&(g.current.refresh(0,g.current.rows-1),u.d.getState().connected&&ej("visible"))};return document.addEventListener("visibilitychange",ez),()=>{window.removeEventListener("orientationchange",e$),document.removeEventListener("visibilitychange",ez),D.disconnect(),h.removeEventListener("wheel",R),b.off("connect",eM),b.off("output",eS),b.off("cwdChange",eT),ea.current&&ea.current.dispose(),eh.current=null,i.textarea?.removeEventListener("keyup",K),N.current&&N.current.dispose(),C.current&&clearTimeout(C.current),ey.cancel(),eR&&clearTimeout(eR),H&&clearTimeout(H),es&&clearTimeout(es),clearInterval(eN),w.current&&w.current.dispose(),y.current&&y.current.dispose(),x(),p(),m.dispose(),i.dispose(),g.current=null,W(!1)}},[b,s]),(0,r.useEffect)(()=>{let e=g.current,t=v.current;e&&t&&b&&s&&(D?j.current?.():k.current?.())},[D,b,s]),(0,r.useEffect)(()=>{let e=g.current,t=v.current;e&&t&&b&&s&&null!=B&&(e.options.fontSize=B,t.fit(),ev(),e.refresh(0,e.rows-1))},[B,b,s,ev]),(0,r.useEffect)(()=>{g.current&&b&&s&&(N.current&&(N.current.dispose(),N.current=null),i&&(N.current=g.current.onData(e=>{(Q.current||V.current)&&(0,eg.Nz)(e)||p()||((0,eg.b9)(e)&&m?.(s),b.emit("input",{sessionId:s,data:e}))})))},[i,b,s,m,p]),(0,r.useEffect)(()=>{if(!g.current||!b||!s||i)return;let e=g.current.onData(e=>{!p()&&(e.startsWith("\x1b[<")||e.startsWith("\x1b[M"))&&b.emit("input",{sessionId:s,data:e})});return()=>e.dispose()},[i,b,s,p]),(0,r.useEffect)(()=>{if(!a||!v.current||!g.current)return;let e=setTimeout(()=>{if(ei.current){let e=ei.current;ei.current=null,(0,L.Lq)("reconnect",`deferred recover → fire (pane now visible, ${e})`),eo.current?.(e)}ey({force:!0}),requestAnimationFrame(()=>g.current?.refresh(0,g.current.rows-1))},100);return()=>clearTimeout(e)},[a,ey]),(0,r.useEffect)(()=>{if(!i)return;let e=window.innerWidth<760,t=setTimeout(()=>{ey(e?{force:!0}:void 0),requestAnimationFrame(()=>g.current?.refresh(0,g.current.rows-1))},100);return()=>clearTimeout(t)},[i,ey]),(0,r.useEffect)(()=>{let e=g.current;if(!e)return;let t="dark"===n?d:"none";e.options.theme=(0,eg.pt)((0,rM.In)(n,l)||r$.dark,t),e.refresh(0,e.rows-1)},[n,l,d]),function(e){let{termRef:t,termReady:s,isVisible:n,bus:l,sessionId:a,onSelectionMadeRef:i,awaitingTuiOutputRef:o,maybeFetchHistoryRef:c,userAtTopRef:d,stopMomentumRef:u}=e;(0,r.useEffect)(()=>{if(!s||!t.current)return;let e=t.current.element?.querySelector(".xterm-screen");if(!e)return;let n=0,r=0,m=0,x=null,p=0,h=0,f=eg.Il.sensitivity,b=eg.Il.lineHeight,g=eg.Il.friction,v=eg.Il.minVelocity,y=eg.Il.maxVelocity,w=eg.Il.tuiThrottleMs,j=eg.Il.momentumRenderCadenceMs,k=eg.Il.tuiBackpressureTimeoutMs,N=0,C=0,S=null,T=()=>{if(S=null,!C)return;let e=t.current;if(!e){C=0;return}let s=Math.max(1,Math.ceil(e.cols/2)),n=Math.max(1,Math.ceil(e.rows/2)),r=C>0?eg.Il.sgrDown(s,n):eg.Il.sgrUp(s,n),i=Math.min(Math.abs(C),eg.Il.wheelStepLines);for(let e=0;e<i;e++)l.emit("input",{sessionId:a,data:r});C=0,N=performance.now(),o.current=!0},E=e=>{let s=t.current;if(s)if("alternate"===s.buffer.active.type){if(o.current&&performance.now()-N<k)return;C+=e;let t=performance.now()-N;t>=w?T():S||(S=setTimeout(T,w-t))}else s.scrollLines(Math.max(-3,Math.min(3,e))),e<0&&s.buffer.active.viewportY<=eg.iW.topThresholdLines&&(d.current=!0,c.current?.())},R=()=>{x&&(cancelAnimationFrame(x),x=null),m=0},M=()=>{if(!t.current||Math.abs(m)<v){x=null;return}let e=t.current.buffer?.active?.type==="alternate",s=performance.now(),n=e&&o.current&&s-N<k,r=!e&&s-h>=j;if(!n&&(e||r)){m*=g;let e=Math.trunc((p+=m)/b);0!==e&&(E(e),p-=e*b,h=performance.now())}x=requestAnimationFrame(M)},$=null,z=!1,P=null,A=0,I=0,D=0,L=0,B=!1,F=null,O=(s,n)=>{let r=t.current,l=F||e.getBoundingClientRect(),a=l.width/r.cols,i=l.height/r.rows,o=Math.max(0,Math.min(r.cols-1,Math.floor((s-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}},_=s=>{R();let l=s.touches[0];n=l.clientY,A=D=l.clientX,I=L=l.clientY,r=Date.now(),m=0,p=0,z=!1,B=!1,t.current?.clearSelection(),$=setTimeout(()=>{!B&&t.current&&(z=!0,(0,ed.e)(),F=e.getBoundingClientRect(),(e=>{let{col:s,row:n}=e,r=t.current,l=r.buffer.active.getLine(n);if(!l)return;let a=l.translateToString(!1),i=e=>e&&eg.FC.wordChars.test(e);if(!i(a[s]))return r.select(s,n,1);let o=s,c=s;for(;o>0&&i(a[o-1]);)o--;for(;c<a.length-1&&i(a[c+1]);)c++;r.select(o,n,c-o+1)})(P=O(A,I)))},eg.FC.longPressMs)},K=s=>{if(!t.current)return;let l=s.touches[0];if(D=l.clientX,L=l.clientY,!B&&Math.hypot(D-A,L-I)>eg.FC.moveTolerance&&(B=!0,z||clearTimeout($)),z){s.preventDefault();var a=O(D,L);let e=t.current;if(a.row===P.row){let t=Math.min(a.col,P.col);e.select(t,a.row,Math.abs(a.col-P.col)+1)}else e.selectLines(Math.min(a.row,P.row),Math.max(a.row,P.row));return}let i=l.clientY,o=Date.now(),c=n-i,d=o-r||1,u=e.closest(".terminal-scroll.is-scrollable");if(u&&u.scrollHeight>u.clientHeight+1){let e=u.scrollHeight-u.clientHeight,t=u.scrollTop<=.5,l=u.scrollTop>=e-.5;if(!(c<0&&t||c>0&&l)){0!==c&&(s.preventDefault(),u.scrollTop=Math.max(0,Math.min(e,u.scrollTop+c))),n=i,r=o,m=0,p=0;return}}let x=c*f,h=Math.trunc((p+=x)/b);0!==h&&(s.preventDefault(),E(h),p-=h*b),m=Math.min(x/d*16,y),n=i,r=o},W=()=>{if(clearTimeout($),F=null,z){z=!1;let e=t.current?.getSelection();e&&e.trim()&&i.current?.(e,{x:D,y:L});return}Math.abs(m)>v&&(x=requestAnimationFrame(M))};u.current=R,e.addEventListener("touchstart",_,{passive:!0}),e.addEventListener("touchmove",K,{passive:!1}),e.addEventListener("touchend",W,{passive:!0});let H=e=>{let s=t.current;s&&e.deltaY<0&&s.buffer.active.viewportY<=eg.iW.topThresholdLines&&(d.current=!0,c.current?.())};return e.addEventListener("wheel",H,{passive:!0}),()=>{R(),u.current=null,clearTimeout($),e.removeEventListener("touchstart",_),e.removeEventListener("touchmove",K),e.removeEventListener("touchend",W),e.removeEventListener("wheel",H)}},[s,n,t,l,a,i,o,c,d,u])}({termRef:g,termReady:K,isVisible:a,bus:b,sessionId:s,onSelectionMadeRef:F,awaitingTuiOutputRef:O,maybeFetchHistoryRef:ex,userAtTopRef:ep,stopMomentumRef:$});let ew=(0,r.useCallback)(()=>{let e=g.current;e&&b&&((0,L.Lq)("join","manual reload (user refetch)"),T.current?.(!0),D?(k.current?.(),j.current?.()):e.refresh(0,e.rows-1))},[b,D]);return{termRef:g,cwdRef:z,cwd:A,searchAddonRef:_,termReady:K,joining:es,doResize:ey,reload:ew,focus:()=>g.current?.focus(),stopMomentum:()=>$.current?.(),historyFetching:eu}}({bus:U,sessionId:a,theme:N,terminalTheme:V,isVisible:c,isFocused:d,containerRef:T,mountDelay:m,bgKey:eh?Q:"none",onInput:ep,onSelectionMade:(e,t)=>_({text:e,x:t.x,y:t.y})}),eE=(0,r.useCallback)(()=>{let e=E.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=E.current;if(!e)return;let t=0,s=()=>{if(window.innerWidth>=eg.jK){R.current={width:0,height:null},t=0,$(null),A(!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,A(!1)):null!=r.height&&n<r.height&&n<t-8?(t=n,A(!0),requestAnimationFrame(eE)):t=n};s();let n=new ResizeObserver(s);return n.observe(e),window.addEventListener("orientationchange",s),()=>{n.disconnect(),window.removeEventListener("orientationchange",s)}},[eE]);let eR=(0,n.jsx)(rW,{onOpenRemote:w,onOpenMobile:j});(0,r.useEffect)(()=>{if(p)return p(a,{focus:eC,doResize:ej}),()=>p(a,null)},[a,eC,ej,p]);let eM=(0,rM.In)(N,V)||r$.dark;(0,r.useEffect)(()=>{if(!ey||!ef.current||!c)return;let e=ef.current,t=()=>{let t=E.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;D(s||r)},s=null,n=()=>{s||(s=requestAnimationFrame(()=>{s=null,t()}))};t();let r=e.onScroll(n),l=()=>n();return E.current?.addEventListener("scroll",l,{passive:!0}),()=>{s&&cancelAnimationFrame(s),r.dispose(),E.current?.removeEventListener("scroll",l),D(!1)}},[ef,ey,c]);let{count:eP}=rk(s||ev,g,{enabled:c}),eA=eP>eg.KN?`${eg.KN}+`:eP,eI=rH({isFocused:d,onActivate:()=>x?.(a)}),eD=[b&&d?"terminal-focus-glow":""].filter(Boolean).join(" "),eL=`rgba(${eg.c},${G??eg._z})`,eB=`rgba(${eg.pZ},${eg.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 ${eD}${eh?" terminal-has-bg":""}`,style:eh?{background:`linear-gradient(${eL},${eL}), linear-gradient(${eB},${eB}), center / cover no-repeat url("${eh}")`,backgroundBlendMode:"normal, screen, normal"}:{background:eM.background},onMouseDown:eI.onMouseDown,onTouchStart:eI.onTouchStart,children:[!ea&&(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/80 backdrop-blur-md text-[11px] select-none relative z-10",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${ne(S)}`,style:{background:s7(S).dot}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",children:i||k("terminal.defaultName")}),eR]}),ea&&(0,n.jsx)(rK,{bus:U,sessionId:a,variant:"pinned",rightSlot:eR}),(0,n.jsxs)("div",{ref:E,className:`terminal-wrapper terminal-scroll flex-1 min-h-0 relative ${z?" is-scrollable":""}`,children:[(0,n.jsx)("div",{ref:T,className:"xterm-screen w-full rounded-sm overflow-hidden",style:null!=M?{height:M,minHeight:M}:{height:"100%",minHeight:"100%"}}),(ew||!ey)&&(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"})}),eT&&(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…"]})}),O&&(0,n.jsx)(rv,{text:O.text,position:O,onOpenUrl:e=>window.open(e,"_blank"),onCopy:e=>{try{navigator.clipboard?.writeText(e)}catch{}},onAddToNote:e=>{_(null),ex(e),ec(!0)},onClose:()=>{ef.current?.clearSelection(),_(null)}})]}),I&&(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)(),eS(),t=E.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:k("terminalPane.scrollToBottom"),children:(0,n.jsx)(el.yQ,{size:20})}),d&&(0,n.jsxs)("div",{className:`absolute right-2 z-[2] flex flex-col items-end gap-2 pointer-events-auto touch-none ${ea?"top-9":"top-9 sm:top-2"}`,children:[(0,n.jsxs)("div",{className:"flex flex-row gap-2",children:[et&&(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),ec(!0)},className:rq,title:k("terminalPane.note"),children:(0,n.jsx)(el.y8,{size:16,className:rU})}),(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),B||((0,ed.e)(),F(!0),eN(),setTimeout(()=>F(!1),700))},className:rq,title:k("terminalPane.refresh"),children:(0,n.jsx)(el.e9,{size:16,className:`${rU} ${B?"animate-spin":""}`})})]}),ee&&(ev||s)&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,ed.e)(),H(s,X||s),window.innerWidth>=eg.jK?K("files",s):W()},className:`relative ${rq}`,title:k("terminalPane.openFolderHere"),children:[(0,n.jsx)(el.vd,{size:16,className:rU}),eP>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:eA})]}),y&&es?.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)(),y(a,es[0])},className:`relative ${rq}`,title:k("terminalPane.artifacts"),children:[(0,n.jsx)(el.sU,{size:16,className:rU}),(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:es.length})]})]}),eo&&et&&(0,n.jsx)(rK,{bus:t,sessionId:a,appendOnOpen:em,pinned:en,onPin:e=>er(a,e),onClose:()=>{ec(!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:k("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 rV(e){let{items:t,size:s=12,label:l="",revealCls:a="",className:i="",anchor:o=null,onClose:c}=e,d=t.filter(Boolean),[u,m]=(0,r.useState)(null),x=o??u,p=null!==x,h=(0,r.useRef)(null),f=nK(h,x?.left??0,x?.top??0),b=(0,r.useCallback)(()=>{m(null),c?.()},[c]);return((0,r.useEffect)(()=>{if(!p)return;let e=e=>{"Escape"===e.key&&(e.stopPropagation(),b())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[p,b]),d.length)?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:e=>{if(e.stopPropagation(),(0,ed.e)(),p)return void b();let t=e.currentTarget.getBoundingClientRect();m({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 ${a} ${i}`,title:l,"aria-label":l,"aria-haspopup":"menu",children:(0,n.jsx)(el.a4,{size:s})}),p&&"u">typeof document&&(0,se.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-[69]",onPointerDown:e=>{e.stopPropagation(),b()},onClick:e=>{e.stopPropagation(),b()},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),b()}}),(0,n.jsx)("div",{ref:h,role:"menu",className:"fixed z-[70] menu-popover p-1 min-w-[160px] pop-in shadow-xl",style:{left:f.left,top:f.top},children:d.map(e=>{let{icon:t,label:s,danger:r,amber:l,onClick:a}=e;return(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),b(),a?.()},className:`w-full text-left px-2.5 py-1.5 text-xs rounded-[6px] flex items-center gap-2 transition-colors ${r?"text-red-500 hover:bg-red-500/10":l?"text-amber-500 hover:bg-amber-500/10":"text-text hover:bg-surface-2/80"}`,children:[t&&(0,n.jsx)(t,{size:13,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:s})]},s)})})]}),document.body)]}):null}var rG=s(32763),rJ=s(70658),rY=s(44964),rZ=s(14757);function rQ(e){let{onClose:t}=e,{t:s}=(0,eu.s)(),{authenticateWithApiKey:l,authenticateWithToken:a}=(0,rJ.As)(),{saveKey:i}=(0,rY.u)(),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!0),[m,x]=(0,r.useState)(!1),[f,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(null);(0,r.useEffect)(()=>{window.matchMedia("(pointer: fine)").matches&&requestAnimationFrame(()=>y.current?.focus())},[]),(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 w=async e=>{if(!e||m)return!1;if((0,p.PF)(e))return b(s("login.legacyKeyError")),!1;(0,ed.e)(),x(!0),b("");let n=(0,rZ.k)(e),r=!!n?.tempKey;try{r&&(0,e3.U)(d);let o=r?await a(n.tempKey,!0,n.tail):await l(e,{persistSession:!1});if(!o?.success)return b(o?.error&&"wrong-key-tail"!==o.error?o.error:s("login.invalidKeyTail")),!1;if(r)return(0,e3.zm)(n,{remember:d,leavingHead:P.rh.getState().currentKey,navigate:!1}),t?.(),!0;let c=(0,p.Uo)(e),u=(0,p.Cj)(e);return u&&c&&(0,h.LG)(c,{tail:u}),d&&c&&(i(e,""),P.rh.getState().setAutoConnect(c,!0)),t?.(),!0}catch(e){return b(e?.message||s("login.invalidKeyTail")),!1}finally{x(!1)}};return"u"<typeof document?null:(0,se.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"modal-overlay z-[70] scrim fade-in",onClick:t,children:(0,n.jsxs)("form",{role:"dialog","aria-modal":"true","aria-label":s("hosts.addHost"),onSubmit:e=>{e?.preventDefault(),w(o.trim())},className:"card-elev w-[26rem] max-w-full overflow-hidden flex flex-col my-auto pop-in",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 flex-shrink-0",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:s("hosts.addHost")}),(0,n.jsx)("button",{type:"button",onClick:t,"aria-label":s("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 flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:y,type:"text",value:o,onChange:e=>{c(e.target.value),b("")},placeholder:s("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)(),v(!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":s("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:d,onChange:e=>u(e.target.checked),className:"w-4 h-4 accent-brand-500 cursor-pointer"}),s("login.rememberKey")]}),f&&(0,n.jsx)("p",{className:"text-xs text-red-400 px-0.5",children:f})]}),(0,n.jsxs)("div",{className:"px-4 pb-4 pt-3 flex gap-2 flex-shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:t,className:"flex-1 py-2 text-sm text-text-muted bg-surface-2 hover:bg-surface-3 rounded-brand transition-colors",children:s("common.cancel")}),(0,n.jsxs)("button",{type:"submit",disabled:!o.trim()||m,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:[m&&(0,n.jsx)(el.kr,{size:14,className:"animate-spin"}),s("login.connect")]})]})]})}),g&&(0,n.jsx)("div",{className:"fixed inset-0 z-[80]",children:(0,n.jsx)(rG.A,{isOpen:!0,onClose:()=>v(!1),onScan:e=>w(String(e||"").trim())})})]}),document.body)}function r0(e){let{hostKey:t=null,label:s="",connected:l=!0,collapsed:a=!1,onToggleCollapse:i=null,onRename:o=null,onDelete:c=null,onDisconnect:d=null,onAddWorkspace:u=null,meta:m=null,mutedOffline:x=!1,connecting:p=!1,onConnect:h=null,onRetry:b=null,showAdd:g=!0,hostUpdating:v=!1,onOpenRemote:y=null,onOpenMobile:w=null,mobile:j=!1,className:k=""}=e,{t:N}=(0,eu.s)(),C=(0,f.B)(e=>e.hiddenHeaderButtons),[S,T]=(0,r.useState)(null),[E,R]=(0,r.useState)(!1),[M,$]=(0,r.useState)(!1),[z,P]=(0,r.useState)(!1),[A,I]=(0,r.useState)(null),D=s||"Local";return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:`relative pr-2 ${j?"pt-3 pb-1":"py-1"} flex items-center gap-1.5 group group/host ${k}`,onContextMenu:e=>{e.preventDefault(),(0,ed.e)(),I({left:e.clientX,top:e.clientY})},children:[i?(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),i()},className:"text-text-subtle hover:text-text flex-shrink-0",tabIndex:-1,"aria-expanded":!a,"aria-label":D,children:(0,n.jsx)(el.c_,{size:j?18:12,className:`transition-transform duration-150 ${a?"":"rotate-90"}`})}):(0,n.jsx)("span",{className:"flex-shrink-0 invisible","aria-hidden":"true",children:(0,n.jsx)(el.c_,{size:j?18:12})}),(0,n.jsxs)("span",{className:"relative flex-shrink-0",children:[(0,n.jsx)(el.VA,{size:j?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 ${p?"bg-amber-400 animate-pulse":l?"bg-green-500":x?"bg-text-subtle":"bg-red-500 animate-pulse"}`})]}),(0,n.jsx)("button",{type:"button",onClick:()=>{i&&((0,ed.e)(),i())},className:"flex-1 min-w-0 py-0.5 pr-1 text-left",children:(0,n.jsx)("span",{className:`block font-medium uppercase truncate ${j?`text-[13px] tracking-wide ${l?"text-text":"text-text-muted"}`:`text-[12px] ${l?"text-text":"text-text-muted"}`}`,"data-tip":D,children:D})}),v&&(0,n.jsx)(el.kr,{size:j?14:12,className:"animate-spin text-brand-400 shrink-0","aria-label":N("menu.updating")}),m&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle truncate min-w-0 max-w-[45%] mr-1",children:m}),(0,n.jsxs)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center ${j?"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:[g&&!v&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),P(!0)},className:"p-0.5 text-text-subtle hover:text-text rounded-[2px] transition-colors",title:N("hosts.addHost"),children:(0,n.jsx)(el.kV,{size:13.5})}),(h||b)&&!l&&!p&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),(h||b)()},className:`${j?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors`,title:N("common.connect"),children:(0,n.jsx)(el.Fc,{size:j?16:13})}),u&&!v&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),u()},className:`${j?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors`,title:N("workspaces.newWorkspace"),children:(0,n.jsx)(el.vd,{size:j?18:13.5})}),(0,n.jsx)(rV,{size:j?18:13.5,label:N("sessions.sessionActions"),revealCls:"",anchor:A,onClose:()=>I(null),items:[o&&t&&{icon:el.gH,label:N("sessions.editName"),onClick:()=>T(D)},u&&!v&&{icon:el.vd,label:N("workspaces.newWorkspace"),onClick:()=>u()},{icon:el.kV,label:N("hosts.addHost"),onClick:()=>P(!0)},y&&!C.includes("remote")&&!v&&{icon:el.VA,label:N("menu.remoteDesktop"),onClick:()=>{I(null),(0,ed.e)(),y()}},w&&!C.includes("mobile")&&!v&&{icon:el.wO,label:N("mobile.androidDevice"),onClick:()=>{I(null),(0,ed.e)(),w()}},c&&t&&{icon:el.TB,label:N("hosts.removeHost"),danger:!0,onClick:()=>R(!0)},d&&{icon:el.Mr,label:N("common.disconnect"),danger:!0,onClick:()=>{I(null),$(!0)}}]})]})]}),z&&(0,n.jsx)(rQ,{onClose:()=>P(!1)}),null!==S&&(0,n.jsx)(nk,{title:N("sessions.editName"),placeholder:D,value:S,onChange:T,onSubmit:()=>{let e=S.trim();e&&t&&o?.(t,e),T(null)},onClose:()=>T(null)}),(0,n.jsx)(ec.A,{isOpen:E,onClose:()=>R(!1),onConfirm:()=>{R(!1),t&&c?.(t)},title:N("hosts.removeHost"),message:N("hosts.removeHostMessage",{name:D}),confirmText:N("common.delete")}),(0,n.jsx)(ec.A,{isOpen:M,onClose:()=>$(!1),onConfirm:()=>{$(!1),d?.()},title:N("common.disconnect"),message:N("hosts.disconnectMessage",{name:D}),confirmText:N("common.disconnect")})]})}let r1="9remote_tree_collapsed",r2="_root";function r5(){try{return JSON.parse(localStorage.getItem(r1))||{}}catch{return{}}}function r3(e){let{name:t,size:s=20,className:r=""}=e,l=("default"===t?"D":t).trim().charAt(0).toUpperCase();return(0,n.jsx)("span",{className:`shrink-0 rounded-full flex items-center justify-center text-white font-bold ${r}`,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%)`}(t),width:s,height:s,fontSize:Math.max(9,Math.round(s/2))},children:l})}let r4=new Map,r6={branch:null,dirty:!1,changedCount:0};async function r8(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 r9(e,t){let{enabled:s=!0}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},[n,l]=(0,r.useState)(r6),a=t||en.getState();return(0,r.useEffect)(()=>{let t;if(!e||!a||!s)return;let n=((t=r4.get(e))||(t={state:r6,stop:null,refs:0,subs:new Set,fileBus:a},r4.set(e,t),r8(t,e),t.stop=nb(()=>r8(t,e),eg.KA)),t.refs++,t);return n.subs.add(l),l(e=>e===n.state?e:n.state),()=>{let t;n.subs.delete(l),(t=r4.get(e))&&(t.refs--,t.refs>0||(t.stop?.(),r4.delete(e)))}},[e,a,s]),n}function r7(e){let{branch:t,dirty:s,size:r=10,className:l="",iconClassName:a=""}=e;return t?(0,n.jsxs)("span",{className:`inline-flex items-center gap-0.5 min-w-0 ${l}`,title:t,children:[(0,n.jsx)(el.Zr,{size:r,className:`flex-shrink-0 ${a||"opacity-70"}`}),(0,n.jsxs)("span",{className:"truncate",children:[t,s?"*":""]})]}):null}function le(e){let{workspace:t,isActive:s,connected:r,collapsed:l,fileBus:a,onToggleCollapse:i,onSelect:o,onNewTerminal:c,onDelete:d,onRename:u,onAddWorkspace:m=null,statusMap:x=null,mobile:p=!1}=e,{t:h}=(0,eu.s)(),{branch:f,dirty:b}=r9(nm(t),a,{enabled:!!a}),g=l?ns((t.items||[]).map(e=>x?.[e.id]?.state)):[],v=i?()=>{(0,ed.e)(),i()}:o;return(0,n.jsxs)("div",{onClick:v,className:`relative pr-2 flex items-center gap-1.5 group group/grp transition-colors ${p?"py-1 mt-1":"py-1.5"} ${v?"cursor-pointer hover:bg-text/[0.06]":""}`,children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),i?.()},className:"text-text-subtle hover:text-text flex-shrink-0",tabIndex:-1,children:(0,n.jsx)(el.c_,{size:p?18:12,className:`transition-transform duration-150 ${l?"":"rotate-90"}`})}),(0,n.jsx)(el.vd,{size:p?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.jsxs)("span",{className:`flex items-center gap-1.5 min-w-0 ${s?"text-text":"text-text-muted"}`,children:[(0,n.jsx)("span",{className:`font-medium uppercase truncate ${p?`text-[13px] tracking-wide ${s?"text-text":"text-text/90"}`:`text-[12px] ${s?"text-text":"text-text-muted"}`}`,"data-tip":t.name,children:t.name}),g.map(e=>{let{state:t,count:s}=e,r=s7(t);return(0,n.jsxs)("span",{className:"flex items-center gap-0.5 flex-shrink-0",title:`${h(r.label)}${s>1?` \xd7${s}`:""}`,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}}),s>1&&(0,n.jsx)("span",{className:"text-[10px] text-text-subtle leading-none",children:s})]},t)})]}),f&&!(0,eg.ok)(f)&&f!==t.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)(r7,{branch:f,dirty:b,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 ${p?"opacity-100":"px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100"} transition-opacity`,children:[c&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),c()},disabled:!r,className:`${p?"p-1.5":"p-0.5"} text-text-subtle hover:text-text rounded-[2px] transition-colors disabled:opacity-40`,title:h("terminal.newTerminal"),children:(0,n.jsx)(el.FW,{size:p?18:13.5})}),(0,n.jsx)(rV,{size:p?18:13.5,label:h("sessions.sessionActions"),revealCls:"",items:[c&&r&&{icon:el.FW,label:h("terminal.newTerminal"),onClick:()=>c()},m&&r&&{icon:el.vd,label:h("workspaces.newWorkspace"),onClick:()=>m()},u&&{icon:el.gH,label:h("workspaces.rename"),onClick:()=>u()},d&&r&&{icon:el.TB,label:h("workspaces.delete"),danger:!0,onClick:()=>d()}]})]})]})}let lt=function(e){let t,{fileBus:s,cwd:r,basePath:l,homeDir:a,mobile:i=!1}=e,{branch:o,dirty:c}=r9(r,s),d=!!o&&!(0,eg.ok)(o),u=d?null:r&&l&&r.startsWith(`${l}/`)?r.slice(l.length+1):r&&l&&r!==l?(t=nu(r,a)).split("/").length>2?`…/${t.split("/").slice(-2).join("/")}`:t:null;return d||u?(0,n.jsxs)("span",{className:`${i?"text-xs":"text-[10px]"} text-text-subtle truncate leading-tight flex items-center gap-1.5`,children:[d&&(0,n.jsx)(r7,{branch:o,dirty:c,className:"truncate italic"}),u&&(0,n.jsx)("span",{className:"truncate opacity-70","data-tip":u,children:u})]}):null},ls=new Set(["Agent","Task","Workflow","task","browser_subagent","invoke_subagent","spawn_agent"]),ln=e=>e?.input?.subagent_type||e?.input?.agent||e?.input?.description||"agent",lr=e=>e?.input?.description||e?.input?.command||"shell";function ll(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";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 la(e){let{includeAsync:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(e||[]).map(e=>{let s=e.children?la(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 li(e,t,s){let n=!1,r=(e||[]).map(e=>{if(t(e))return n=!0,s(e);let r=li(e.children,t,s);return r?(n=!0,{...e,children:r}):e});return n?r:null}let lo=e=>"string"==typeof e&&e.replace(/\\/g,"/").split("/").filter(Boolean).pop()||"",lc=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""},ld=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,lu=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=/^mcp__[^_]+(?:_[^_]+)*__(.+)$/.exec(e);return t?t[1]:e},lm=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e.url||e.query||e.pattern||e.name||lo(e.path)||lo(e.file_path)||""};function lx(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 lp=new Set(["Edit","Write","MultiEdit","NotebookEdit","edit","write","patch","apply","write_to_file","replace_file_content","multi_replace_file_content","sed_file","file_change"]),lh=e=>"string"==typeof e&&e?e.split("\n").length:0;function lf(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],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(!lp.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+=lh(s.old_string??s.oldString??s.old??s.target_content),e+=lh(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:lh(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:lh(l),removed:lh(r)}}(e);r&&(t+=r.added,s+=r.removed)}}return{added:t,removed:s}}let lb=/^\s*<(task-notification|environment_context|turn_aborted|persisted-output)>/,lg=e=>lb.test(String(e||""));function lv(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 ly=new Set(["completed","failed","killed","stopped"]),lw=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();return 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},lj=(e,t)=>t?.startedAt?null:{startedAt:Date.now()-(Number.isFinite(e)?Math.max(0,e):0)},lk=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];for(let t=e.length-1;t>=0;t--)if(e[t]?.compacting)return t;return -1},lN=new Set(["compacting"]);function lC(e,t,s,n){let r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;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 lS(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,...lj(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&&!ly.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,lj(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&&!ly.has(e.status)&&!t.has(e.taskId))&&(s=s.map(e=>!e.background||ly.has(e.status)||t.has(e.taskId)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()})),n?.tasks||[]))s=lS(s,e.task_id,{background:!0,status:"running",...e.description?{description:e.description}:null,...e.task_type?{taskType:e.task_type}:null,...lj(l,s.find(t=>t.taskId===e.task_id))});return s}default:return e}}function lS(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(lT(r,e[n]))return e;let l=e.slice();return l[n]=r,l}let lT=(e,t)=>{let s=Object.keys(e);return s.length===Object.keys(t).length&&s.every(s=>e[s]===t[s])};function lE(e,t){let s=[];for(let t of e||[])t&&(s=lC(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 lR=[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:""],lM=new Set(["tool_progress","thinking_tokens","hook_started","hook_progress","hook_response","control_response"]),l$=new Set(["info","suggestion","warning","error"]),lz={warning:"warning",guardianWarning:"warning",configWarning:"warning",deprecationNotice:"warning",notice:"warning"};function lP(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if(!t)return null;let n=tZ(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("system"===e&&("model_fallback"===t.subtype||"model_consent_fallback"===t.subtype)){let e=t.original_model&&t.fallback_model?`${t.original_model} → ${t.fallback_model}`:t.original_model||t.fallback_model||"model changed",s="string"==typeof t.content?t.content.trim():"";return{subtype:t.subtype,level:"warning",content:s?`Model fallback: ${e} — ${s}`:`Model fallback: ${e}`}}if("system"===e&&"api_retry"===t.subtype){let e=Math.round((Number(t.retry_delay_ms)||0)/1e3),s=null!=t.error_status?` ${t.error_status}`:"";return{subtype:"api_retry",level:"warning",retrying:!0,content:`API error${s} — retrying in ${e}s (attempt ${t.attempt??"?"}/${t.max_retries??"?"})`}}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?`${lx(n)} → ${lx(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(lN.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=lv(e.content);return t?{subtype:s,level:"info",content:t}:null}let n="queued_command"===s?e.prompt:"";if("string"!=typeof n||!n.trim()||lg(n))return null;let r=lv(n);return r?{subtype:s,level:"info",content:r}:null}if("system"===e){if(lg(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(lM.has(e))return null;for(let s of lR){let n=lv(s(t)).trim();if(!n||lg(n))continue;let r="error"===e&&t.willRetry?"warning":l$.has(t?.level)?t.level:Object.prototype.hasOwnProperty.call(lz,e)?lz[e]:/error|fail/i.test(e)?"error":/warn|retr/i.test(e)?"warning":"info";return{subtype:e,level:r,content:n}}return null}function lA(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0;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 lI=(0,st.KU)(()=>window.localStorage),lD=null,lL=lI&&{...lI,setItem:(e,t)=>{t!==lD&&(lD=t,lI.setItem(e,t))}},lB=0,lF=e=>`${e}-${Date.now()}-${++lB}`,lO={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:[]},l_=(e,t)=>({...lO,...e.bySession[t]});function lK(e,t){if(!t?.length)return null;let s=e.filter(e=>e.toolUseId&&ly.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=li(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 lW=(e,t)=>e.status!==(t.status||"done")||Object.keys(t).some(s=>e[s]!==t[s]),lH=(0,b.v)((0,st.Zr)((e,t)=>({bySession:{},initSession:s=>{s&&!t().bySession[s]&&e(e=>({bySession:{...e.bySession,[s]:{...lO}}}))},setTaskRecords:(t,s)=>{t&&Array.isArray(s)&&e(e=>{let n=l_(e,t),r=lE(s,[]),l=lK(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=l_(e,t),r=n.harnessTasks||[],l=r;for(let[e,t,n,r]of s)l=lC(l,e,t,n,r);let a=lK(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=l_(e,t);if(s?.compacting&&-1!==lk(r.messages))return e;if(s?.retrying){let s=r.messages.map(e=>e?.retrying).lastIndexOf(!0);if(-1!==s){let l=[...r.messages];return l[s]={...l[s],content:n},{bySession:{...e.bySession,[t]:{...r,messages:l}}}}}if(-1!==(s?.compactSettled?lk(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:lF("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:lF("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,...s.retrying?{retrying:!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=l_(e,t);return{bySession:{...e.bySession,[t]:{...n,permissionMode:s}}}})},setTurnRunning:(t,s)=>{e(e=>{let n=l_(e,t);return{bySession:{...e.bySession,[t]:{...n,isTurnRunning:s}}}})},ensureTurnLive:t=>{e(e=>{let s=l_(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=l_(e,t),r=Array.isArray(s)?s:[];return{bySession:{...e.bySession,[t]:{...n,queue:r}}}})},setMetadata:(t,s)=>{e(e=>{let n=l_(e,t);return{bySession:{...e.bySession,[t]:{...n,metadata:{...n.metadata,...s}}}}})},setStats:(t,s)=>{e(e=>{let n=l_(e,t);return{bySession:{...e.bySession,[t]:{...n,stats:{...n.stats,...s}}}}})},addUserMessage:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];e(e=>{let l=l_(e,t),a={id:lF("u"),role:"user",content:s,attachments:n||[]},i={id:lF("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=l_(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:lF("msg"),role:"assistant",content:s||"",isLive:!0,diffs:[],tools:[]}),{bySession:{...e.bySession,[t]:{...n,messages:r}}}})},appendThinking:(t,s)=>{e(e=>{let n=l_(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:lF("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=l_(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:lF("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=l_(e,t),r=[...n.messages],l=r[r.length-1];l&&"assistant"===l.role?(l={...l},r[r.length-1]=l):(l={id:lF("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=l_(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:lF("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:lF("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=l_(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(!lW(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=l_(e,t),r=[...n.messages];for(let e=r.length-1;e>=0;e--){let t=r[e],n=li(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=l_(e,t);for(let r=n.messages.length-1;r>=0;r--){let l=n.messages[r],a=li(l?.tools,e=>(e.children||[]).some(e=>e.id===s.id),e=>{let t=e.children.find(e=>e.id===s.id);return t&&!lW(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=l_(e,t);return{bySession:{...e.bySession,[t]:{...n,activePermission:s,gateError:!1}}}})},clearPermission:t=>{e(e=>{let s=l_(e,t);return{bySession:{...e.bySession,[t]:{...s,activePermission:null}}}})},setBlocked:(t,s)=>{e(e=>{let n=l_(e,t);return{bySession:{...e.bySession,[t]:{...n,activeBlocked:s}}}})},clearBlocked:t=>{e(e=>{let s=l_(e,t);return{bySession:{...e.bySession,[t]:{...s,activeBlocked:null}}}})},setPromptError:function(t,s,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;e(e=>{let i=l_(e,t),o=i.promptError,c=[...o?.attachments||[],...r||[]],d=o&&o.text!==s?`${o.text}
12
+
13
+ ${s}`:s;return{bySession:{...e.bySession,[t]:{...i,promptError:{text:d,reason:n,attachments:c.length?c:null,promptId:o?null:l,retries:o?0:a}}}}})},setPromptSending:(t,s)=>{e(e=>{let n=l_(e,t);return{bySession:{...e.bySession,[t]:{...n,promptSending:{text:s,at:Date.now()}}}}})},clearPromptSending:(t,s)=>{e(e=>{let n=l_(e,t);if(!n.promptSending||null!=s&&n.promptSending.text!==s)return e;let{promptSending:r,...l}=n;return{bySession:{...e.bySession,[t]:l}}})},setPromptErrorText:(t,s)=>{e(e=>{let n=l_(e,t);return n.promptError?{bySession:{...e.bySession,[t]:{...n,promptError:{...n.promptError,text:s}}}}:e})},clearPromptError:t=>{e(e=>{let s=l_(e,t);if(!s.promptError)return e;let{promptError:n,...r}=s;return{bySession:{...e.bySession,[t]:r}}})},setGateError:function(t,s){let n=!(arguments.length>2)||void 0===arguments[2]||arguments[2];e(e=>{let r=l_(e,t);return r.activePermission?.requestId!==s?e:{bySession:{...e.bySession,[t]:{...r,gateError:n}}}})},finishTurn:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];e(e=>{let l=l_(e,t),a=l.messages.map((e,t)=>{let s=e.tools?la(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=l_(e,t),n=s.harnessTasks||[],r=n.some(e=>!ly.has(e.status))?n.map(e=>ly.has(e.status)?e:{...e,status:"stopped",endedAt:e.endedAt||Date.now()}):n,l=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=!1,s=e.map(e=>{if(!e.tools)return e;let s=la(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=l_(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=l_(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=l_(e,t),r=lA(n.tasks,s);return r===n.tasks?e:{bySession:{...e.bySession,[t]:{...n,tasks:r}}}})},hydrateSession:(t,s)=>{let{messages:n=[],tasks:r=[],isTurnRunning:l=!1,metadata:a={},stats:i=null,permissionMode:o=null,activeBlocked:c=null,elapsedMs:d=0,lastTurnMs:u=0,harnessTasks:m=null,queue:x=null}=s;e(e=>{let s=l_(e,t),p=m?lK(m,n):null;return{bySession:{...e.bySession,[t]:{...s,activePermission:null,messages:p||n,tasks:r,isTurnRunning:l,...Array.isArray(x)?{queue:x}:{},turnStartedAt:l?Date.now()-(d||0):0,lastTurnMs:l?0:u||0,turnBaseline:l?{inputTokens:0,outputTokens:0}:{inputTokens:i?.inputTokens||0,outputTokens:i?.outputTokens||0},metadata:{...s.metadata,...a},stats:i?{...s.stats,...i}:s.stats,activeBlocked:c,...o?{permissionMode:o}:{},...m?{harnessTasks:m}:{}}}}})},prependMessages:(t,s)=>{s?.length&&e(e=>{let n=l_(e,t),r=lK(n.harnessTasks||[],s)||s,l=new Set(n.messages.map(e=>e.id)),a=r.map(e=>l.has(e.id)?{...e,id:lF(e.id.split("-")[0])}:(l.add(e.id),e));return{bySession:{...e.bySession,[t]:{...n,messages:[...a,...n.messages]}}}})},restoreTurnState:function(t){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(void 0===s.isTurnRunning)return;let{isTurnRunning:n,lastTurnMs:r=0,elapsedMs:l=0}=s;(n||r)&&e(e=>{let s=l_(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:lL,partialize:e=>({bySession:Object.fromEntries(Object.entries(e?.bySession||{}).map(e=>{let[t,s]=e;return[t,{permissionMode:s?.permissionMode??null,metadata:{model:s?.metadata?.model||"",effort:s?.metadata?.effort||""}}]}))})}));function lq(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 lU(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]: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+=lq(e[s]),a++,!(l>=t)||!(a>=n));s--);return r-a}async function lX(e){let{startSeq:t,fetchChunk:s,reduceChunk:n,maxChunks:r=8,pageBudget:l=131072,estimateBytes:a=()=>0}=e,i=t,o=[],c=0,d=!0,u=0,m=!1;for(;u<r;){let e=await s(i);if(u++,null==e)break;if(!e.success||!e.events?.length){d=!1;break}m=!0;let t=n(e.events,o.length);if(o=[...t,...o],c+=t.reduce((e,t)=>e+a(t),0),i=e.events[0].seq,!(d=!!e.hasMore)||c>=l)break}return{messages:o,before:i,hasMore:d,answered:m,chunks:u}}let lV=[1200,3e3,6e3];function lG(e,t){let{seq:s,epoch:n}=e,{appliedSeq:r,logEpoch:l}=t;return null!=n&&null==l?"adopt":null!=n&&null!=l&&n!==l?n>l?"resync":"stale":null==s?"apply":s<=r?"dup":null!=n&&n===l&&s>r+1?"gap":"apply"}function lJ(e){return`9remote_pendingPrompts_${e}`}function lY(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:globalThis.localStorage;if(!e||!t)return[];try{let s=JSON.parse(t.getItem(lJ(e))||"[]");return Array.isArray(s)?s.filter(e=>e&&"string"==typeof e.id&&"string"==typeof e.text):[]}catch{return[]}}function lZ(e,t,s){if(e&&s)try{t.length?s.setItem(lJ(e),JSON.stringify(t)):s.removeItem(lJ(e))}catch{}}function lQ(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage,n=lY(e,s),r=n.filter(e=>e.id!==t);r.length!==n.length&&lZ(e,r,s)}function l0(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage;if(!t)return;let n=lY(e,s),r=n.filter(e=>!t.includes(e.text));r.length!==n.length&&lZ(e,r,s)}let l1=e=>Array.isArray(e)?e.map(e=>"string"==typeof e?{id:e,name:e,description:""}:e):[],l2=Math.random().toString(36).slice(2,10);function l5(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 l3=/\u001b\[[0-9;?]*[A-Za-z]/g,l4=e=>String(e||"").replace(l3,"").trim(),l6=(e,t)=>{if(String(t||"").trim())return!1;let s=e[e.length-1];return!!(s&&"notice"===s.role&&"error"===s.level)},l8=e=>e?.text?`Not sent — ${e.reason||"the turn is still running"}: ${e.text}`:e?.reason||"Not sent";function l9(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"claude",s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,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,m=!1,x=!1,p=s;for(let s of e){let e=s?.event,h=s?.data;if(e)switch(e){case"user_message":o=!0,x=!1,d=null,n.push({id:`u-${++p}`,role:"user",content:h?.text||"",attachments:h?.attachments||[]}),n.push({id:`a-${++p}`,role:"assistant",content:"",thinking:"",diffs:[],tools:[],isLive:!0});break;case"init":{x=!1;let e=l1(h?.skills),t=e.length>0?e:a.skills,{model:s,...n}=h||{};a={...a,...n,skills:t,...s?{model:s}:{}};break}case"goal":a={...a,goal:h?.goal||null};break;case"cli_reset":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||"")+(h?.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||"")+(h?.text||"");break}case"diff":{if(!h)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===h.file);-1!==s?t[s]=h:t.push(h);break}case"tool_child":if(!h)break;for(let e=n.length-1;e>=0;e--){let t=li(n[e]?.tools,e=>e.id===h.parentToolUseId,e=>{let t=[...e.children||[]],s=t.findIndex(e=>e.id===h.id);return -1!==s?t[s]={...t[s],...h}:t.push({...h,status:h.status||"running"}),{...e,children:t}});if(t){n[e].tools=t;break}}break;case"tool_result_child":if(!h?.id)break;for(let e=n.length-1;e>=0;e--){let t=li(n[e]?.tools,e=>(e.children||[]).some(e=>e.id===h.id),e=>({...e,children:e.children.map(e=>e.id===h.id?{...e,...h,status:h.status||"done"}:e)}));if(t){n[e].tools=t;break}}break;case"tool_start":{if(!h)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:[{...h,status:h.status||"running"}]},n.push(e);else if(e&&"assistant"===e.role){let t=e.tools||(e.tools=[]),s=t.findIndex(e=>e.id===h.id);-1!==s?t[s]={...t[s],...h}:t.push({...h,status:h.status||"running"})}else e={id:`msg-${++p}`,role:"assistant",content:"",isLive:!0,diffs:[],tools:[{...h,status:h.status||"running"}]},n.push(e);if(h.name){let e=t0(t,h.name,h.input,h.id,r);e&&(r=lA(r,e))}break}case"tool_result":{if(!h?.id)break;for(let e=n.length-1;e>=0;e--){let t=n[e],s=t?.tools?.find(e=>e.id===h.id);if(s){Object.assign(s,h,{status:h.status||"done"});break}}let e=t1(t,h.name||"",h.output||"",h.id);e&&(r=lA(r,e));break}case"permission_request":c=h;break;case"permission_resolved":c=null;break;case"blocked":d=h;break;case"options_changed":h?.permissionMode&&(u=h.permissionMode),h?.model&&(a.model=h.model),h?.effort&&(a.effort=h.effort);break;case"turn_complete":m=!0,o=!1,c=null,h?.stats&&(i={...i,...h.stats}),n.length>0&&(n[n.length-1].isLive=!1),!h?.isError||l6(n,h.result)||l5(n,h.result)||n.push({id:`n-${++p}`,role:"notice",subtype:h.subtype||"",level:"error",content:h.result||"The turn ended in an error."});break;case"stats":h?.stats&&(i={...i,...h.stats});break;case"stopped":m=!0,o=!1,c=null;break;case"stall":for(let e of(m=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);break;case"exit":for(let e of(m=!0,x=!0,o=!1,c=null,n))e.isLive&&(e.isLive=!1);(h?.error||h?.code!=null&&0!==h.code)&&n.push({id:`n-${++p}`,role:"notice",subtype:"exit",level:"error",content:h.error||`The AI process exited (code ${h.code}).`});break;case"error":for(let e of(m=!0,o=!1,n))e.isLive&&(e.isLive=!1);n.push({id:`n-${++p}`,role:"notice",subtype:"error",level:"error",content:h?.message||"AI process failed"});break;case"prompt_refused":n.push({id:`n-${++p}`,role:"notice",subtype:"prompt_refused",level:"error",content:l8(h)});break;case"conversation_reset":n.length=0,r.length=0,l.length=0,o=!1,x=!1,c=null,d=null;break;case"cli_event":{let e=h?.type||"",s=h?.record||null;l.push([e,h?.subtype||"",s,h?.ageMs]);let r=lP(e,s,t);if(!r)break;let{compactSettled:a,...i}=r,o=a?lk(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=l4(h?.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(m||x)for(let e of n)e.tools&&(e.tools=la(e.tools,{includeAsync:x}));let h=[];for(let[e,t,s]of l)h=lC(h,e,t,s);return x&&(h=h.map(e=>ly.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:h}}function l7(e,t){if(!t)return!1;let s=[...lH.getState().bySession[e]?.messages||[]].reverse().find(e=>"user"===e.role);return!!s&&(s.content===t||String(t).endsWith("\n\n"+s.content))}function ae(e,t){let s=lH.getState().bySession[e]?.promptError;if(!s||!t)return;if(s.text===t)return void lH.getState().clearPromptError(e);let n=s.text.split("\n\n"),r=n.indexOf(t);if(-1===r)return;n.splice(r,1);let l=n.filter(Boolean).join("\n\n");l?lH.getState().setPromptErrorText(e,l):lH.getState().clearPromptError(e)}let at=e=>String(e).padStart(2,"0");function as(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 ${at(n)}m`:n>0?`${n}m ${at(r)}s`:`${r}s`}let an=(0,r.memo)(function(e){let{message:t,engine:s="claude",workspacePath:l="",onResolvePermission:a,onRewind:i,onPreviewRewind:o,onCutLocal:c,rewindIndex:d=null,canRewind:u=!1}=e,[m,x]=(0,r.useState)(!1),[p,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)(null);(0,f.B)(e=>e.openEditorFile);let{id:C,role:S,content:T,thinking:E,diffs:R=[],tools:M=[],permission:$=null,isLive:z=!1,attachments:P=[]}=t;if("user"===S){let e=async e=>{j(!0),N("preview");let t=await o?.(null,{index:d});(j(!1),N(null),t?.ok)?y({files:t.files||[],text:e}):y({error:t?.error||"The host could not preview this rewind.",text:e})},t=async()=>{let e=v?.text;y(null),j(!0),N("apply"),c?.(C,e);let t=await i?.(null,e,{index:d});(j(!1),N(null),t&&!t.ok)?y({error:t.error||"The rewind did not go through.",text:e}):h(!1)},s=(0,n.jsx)(ec.A,{isOpen:!!v,onClose:()=>y(null),onConfirm:v?.error?()=>y(null):t,title:v?.error?"Cannot rewind":"Rewind to this prompt?",message:v?.error?v.error:["This discards every turn after this prompt and re-sends your edited text.",v?.files?.length?`These ${v.files.length} file${1===v.files.length?"":"s"} go back to how they were:`:"No file changes to restore — this rewinds the conversation only.",...v?.files?.slice(0,8).map(e=>`\xb7 ${e.file}${e.status?` (${e.status})`:""}`)||[],v?.files?.length>8?`… and ${v.files.length-8} more`:"","Edits made by hand, or by shell commands, are NOT restored."].filter(Boolean).join("\n"),confirmText:v?.error?"OK":"Rewind"});if(p)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:b,onChange:e=>g(e.target.value),onBlur:()=>{w||v||h(!1)},onKeyDown:t=>{if("Enter"===t.key&&!t.shiftKey){if(t.nativeEvent.isComposing||229===t.keyCode||(t.preventDefault(),w||v))return;b.trim()&&e(b.trim())}"Escape"===t.key&&h(!1)},rows:Math.min(10,b.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:[w&&(0,n.jsx)(el.kr,{size:11,className:"animate-spin"}),(0,n.jsx)("span",{children:"apply"===k?"Rewinding...":"preview"===k?"Checking what this would change...":"Enter to rewind, Esc to cancel"})]})]})}),s]});let r=u&&!!i,l=()=>{(0,ed.e)(),g(T||""),h(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"group/msg flex flex-col items-end my-3 list-rise",children:[(0,n.jsxs)("div",{className:"max-w-[92%] @2xl:max-w-[768px] flex flex-col items-end gap-1.5",children:[P.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap justify-end gap-1.5",children:P.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}`))}),T&&(0,n.jsx)("div",{onClick:r?e=>{let t=window.getSelection();t&&!t.isCollapsed&&t.containsNode(e.currentTarget,!0)||l()}:void 0,className:`px-3.5 py-2 rounded-[16px] rounded-tr-[4px] bg-[var(--chat-bubble-mine)] text-[var(--chat-meta-on-mine)] text-sm whitespace-pre-wrap wrap-anywhere shadow-[0_1px_2px_rgba(0,0,0,0.08)] ${r?"cursor-pointer":""}`,children:T})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),T&&(navigator.clipboard.writeText(T),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:m?(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:w,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:w&&"preview"===k?(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 ar(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 al=(0,r.memo)(function(e){let{images:t=[],index:s=0,onClose:l,fileBus:a=null}=e,[i,o]=(0,r.useState)(s),[c,d]=(0,r.useState)(null),[u,m]=(0,r.useState)(!1),[x,p]=(0,r.useState)(1),[h,f]=(0,r.useState)({x:0,y:0}),b=(0,r.useRef)(null),g=(0,r.useRef)(null),v=(0,r.useRef)(null),y=(0,r.useRef)(null),w=t[i]||null;(0,r.useEffect)(()=>{if(d(null),m(!1),p(1),f({x:0,y:0}),!w?.path||!a?.readMedia)return;let e=!0;return a.readMedia(w.path).then(t=>{e&&(t?.success&&t.dataUrl?d(t.dataUrl):m(!0))}).catch(()=>{e&&m(!0)}),()=>{e=!1}},[w?.path,a]);let j=(0,r.useCallback)(e=>{o(s=>{let n=s+e;return n<0||n>=t.length?s:n})},[t.length]),k=(0,r.useCallback)((e,t)=>{let s=y.current;if(!s||t<=1)return{x:0,y:0};let n=s.clientWidth*(t-1)/2,r=s.clientHeight*(t-1)/2;return{x:Math.max(-n,Math.min(n,e.x)),y:Math.max(-r,Math.min(r,e.y))}},[]),N=(0,r.useCallback)(e=>{let t=Math.min(4,Math.max(1,e));p(t),1===t?f({x:0,y:0}):f(e=>k(e,t))},[k]);(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),l?.()):"ArrowLeft"===e.key?(e.preventDefault(),j(-1)):"ArrowRight"===e.key?(e.preventDefault(),j(1)):"0"===e.key&&(p(1),f({x:0,y:0}))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[l,j]);let C=e=>{let t=b.current;if(!t)return;if(t.pointers.size>1){t.pointers.delete(e.pointerId),t.pinch0=null;return}if(t.pointers.delete(e.pointerId),t.pointers.size>0)return;b.current=null;let s=t.movedX||0,n=g.current?.clientWidth||window.innerWidth;1===x&&Math.abs(s)>60&&Math.abs(s)>.18*n&&j(s<0?1:-1),1===x&&f({x:0,y:0}),!t.swiped&&t.startedOnBackdrop&&l?.()};return"u"<typeof document||!w?null:(0,se.createPortal)((0,n.jsx)("div",{ref:g,className:"scrim-lightbox fixed inset-0 z-[9999] flex items-center justify-center select-none",onPointerDown:e=>{let t=b.current;if(t){t.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.pinch0=null,t.swiped=!0;return}b.current={id:e.pointerId,x:e.clientX,y:e.clientY,movedX:0,zoom0:x,pan0:h,pinch0:null,startedOnBackdrop:e.target===g.current,pointers:new Map([[e.pointerId,{x:e.clientX,y:e.clientY}]])}},onPointerMove:e=>{let t=b.current;if(!t)return;if(t.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),2===t.pointers.size){let[e,s]=[...t.pointers.values()],n=Math.hypot(e.x-s.x,e.y-s.y);if(!t.pinch0){t.pinch0=n,t.zoom0=x;return}N(t.zoom0*(n/t.pinch0)),t.swiped=!0;return}let s=e.clientX-t.x,n=e.clientY-t.y;if(x>1){f(k({x:t.pan0.x+s,y:t.pan0.y+n},x)),t.swiped=!0;return}t.movedX=s,Math.abs(s)>8&&(t.swiped=!0),f({x:s,y:0})},onPointerUp:C,onPointerCancel:C,onWheel:e=>{(e.ctrlKey||e.metaKey)&&(e.preventDefault(),N(x-.002*e.deltaY))},onClick:e=>{e.target===g.current&&l?.()},children:(0,n.jsxs)("div",{ref:v,className:"lightbox-panel relative z-10 flex max-h-[min(88vh,calc(var(--app-height,100vh)-2rem))] w-[min(94vw,1100px)] flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-2.5 py-2",children:[(0,n.jsx)("span",{className:"min-w-0 truncate font-mono text-[11.5px] text-white/75",children:w.name}),t.length>1&&(0,n.jsxs)("span",{className:"shrink-0 rounded-full bg-white/10 px-2 py-0.5 font-mono text-[10.5px] text-white/60 tabular-nums",children:[i+1," / ",t.length]}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)("button",{type:"button",onClick:l,className:"shrink-0 rounded-full p-1.5 text-white/60 transition-colors hover:bg-white/15 hover:text-white",title:"Close",children:(0,n.jsx)(el.X,{size:16})})]}),(0,n.jsxs)("div",{className:"relative min-h-0 flex-1",children:[t.length>1&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>j(-1),disabled:0===i,className:"lightbox-arrow absolute left-2 top-1/2 z-10 -translate-y-1/2 rounded-full p-2 text-white/70 transition-colors hover:text-white disabled:opacity-20",title:"Previous",children:(0,n.jsx)(el.JG,{size:18})}),(0,n.jsx)("button",{type:"button",onClick:()=>j(1),disabled:i===t.length-1,className:"lightbox-arrow absolute right-2 top-1/2 z-10 -translate-y-1/2 rounded-full p-2 text-white/70 transition-colors hover:text-white disabled:opacity-20",title:"Next",children:(0,n.jsx)(el.c_,{size:18})})]}),c?(0,n.jsx)("img",{ref:y,src:c,alt:w.name,draggable:!1,className:"lightbox-image mx-auto block max-h-full max-w-full object-contain",style:{transform:`translate(${h.x}px, ${h.y}px) scale(${x})`,transition:b.current?"none":"transform 160ms ease-out",touchAction:"none"}}):u?(0,n.jsx)("span",{className:"flex h-full items-center justify-center font-mono text-xs text-white/55",children:"This image is no longer on the host."}):(0,n.jsx)("span",{className:"flex h-full items-center justify-center",children:(0,n.jsx)(el.kr,{size:22,className:"animate-spin text-white/60"})})]})]})}),document.body)}),aa=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,ai=(0,r.memo)(function(e){let{img:t,fileBus:s=null,images:l=null,index:a=0}=e,[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(!1),[u,m]=(0,r.useState)(!1);return((0,r.useEffect)(()=>{if(!t?.path||!s?.readMedia)return;let e=!0;return s.readMedia(t.path,{maxDim:320}).then(t=>{e&&(t?.success&&t.dataUrl?o(t.dataUrl):d(!0))}).catch(()=>{e&&d(!0)}),()=>{e=!1}},[t?.path,s]),!t?.path||c)?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>m(!0),className:"h-10 w-14 shrink-0 overflow-hidden rounded-brand border border-border-subtle/60 bg-surface-2/60 transition-opacity hover:opacity-90",title:`${t.name} — open in viewer`,children:i?(0,n.jsx)("img",{src:i,alt:t.name,className:"h-full w-full object-cover",draggable:!1}):(0,n.jsx)("span",{className:"block h-full w-full animate-pulse bg-surface-3/40"})}),u&&(0,n.jsx)(al,{images:l||[t],index:l?a:0,fileBus:s,onClose:()=>m(!1)})]})}),ao={file:el.kU};function ac(e){let{path:t,fileBus:s,onOpen:l}=e,[a,i]=(0,r.useState)(null);return((0,r.useEffect)(()=>{if(!t||!s?.readMedia)return;let e=!0;return s.readMedia(t).then(t=>{e&&t?.success&&t.dataUrl&&i(t.dataUrl)}).catch(()=>{}),()=>{e=!1}},[t,s]),a)?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),l()},className:"shrink-0 overflow-hidden rounded border border-border-subtle/60 hover:border-border-subtle transition-colors",title:"View full size",children:(0,n.jsx)("img",{src:a,alt:"",className:"h-7 w-10 object-cover",draggable:!1})}):null}let ad=(0,r.memo)(function e(t){let{id:s="",name:l="tool",command:a="",input:i=null,output:o="",error:c="",status:d="done",children:u=[],engine:m="claude",workspacePath:x="",fileBus:p=null}=t,h="running"===d,b=!!(c||"error"===d),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),j=(0,f.B)(e=>e.openEditorFile),k=!!a||"string"!=typeof i&&!!i?.command,N="string"==typeof i?"":i?.file_path||i?.notebook_path||i?.path||i?.file||"",C=a||N||("string"==typeof i?i:i?.command||i?.pattern||i?.query||""),S=!k&&N&&C===N?function(e,t){let{dir:s,name:n}=ar(e,t);return s?`${s}/${n}`:n}(C,x):C,T="string"==typeof i?i:i&&Object.keys(i).length?JSON.stringify(i,null,2):"",E=i?.file_path||i?.path||i?.file||"",R=aa.test(E),[M,$]=(0,r.useState)(!1),z=ao[tQ(m,l)]||el.Jl;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>v(!g),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:h?(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-accent"}):b?(0,n.jsx)(el.RI,{size:13,className:"text-danger"}):(0,n.jsx)(z,{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:l,children:l}),S&&(0,n.jsxs)(n.Fragment,{children:[" ",(0,n.jsx)("span",{className:"text-text-muted break-all",title:S,children:S})]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 self-center",children:g?(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 ${R?"":"opacity-0 group-hover/tool:opacity-100"}`,children:[R&&!h&&!b&&p&&(0,n.jsx)(ac,{path:E,fileBus:p,onOpen:()=>$(!0)}),E&&(0,n.jsx)("button",{type:"button",onClick:e=>{if(e.stopPropagation(),(0,ed.e)(),E){if(R)return void $(!0);j(E)}},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors flex items-center gap-1",title:R?"View image":"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=o||c||S;t&&(navigator.clipboard.writeText("string"==typeof t?t:JSON.stringify(t,null,2)),w(!0),setTimeout(()=>w(!1),2e3))},className:"p-0.5 text-text-muted hover:text-text rounded hover:bg-surface-3 transition-colors opacity-0 group-hover/tool:opacity-100",title:"Copy output",children:y?(0,n.jsx)(el.aJ,{size:11,className:"text-success"}):(0,n.jsx)(el.QR,{size:11})})]})]}),g&&(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:[T&&(0,n.jsx)("div",{className:"text-text-muted whitespace-pre-wrap break-all leading-relaxed mb-1.5",children:T}),c&&(0,n.jsx)("div",{className:"text-danger mb-1.5 whitespace-pre-wrap wrap-anywhere",children:c}),o?(0,n.jsx)("div",{className:"text-text whitespace-pre-wrap wrap-anywhere leading-relaxed",children:"string"==typeof o?o:JSON.stringify(o,null,2)}):c?null:(0,n.jsx)("div",{className:"text-text-muted italic",children:"Running or no output returned..."})]}),g&&u.length>0&&(0,n.jsx)("div",{className:"ml-3.5 pl-3 border-l-2 border-border-subtle/80",children:u.map(t=>(0,n.jsx)(e,{...t,engine:m,workspacePath:x,fileBus:p},t.id))}),M&&(0,n.jsx)(al,{images:[{path:E,name:E.split(/[/\\]/).pop()||E}],index:0,fileBus:p,onClose:()=>$(!1)})]})}),au=new Set(["TaskCreate","TaskUpdate","TodoWrite","todowrite"]),am=e=>!!tZ(e).questionGate,ax=new Set(["Edit","Write","MultiEdit","NotebookEdit","file_change","edit","write","write_to_file","replace_file_content"]),ap=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e.file_path||e.notebook_path||e.path||e.filePath||e.file||""},ah=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,af=["file_path","notebook_path","path","file"],ab=e=>"thought"===e.kind||"tool"===e.kind||"diff"===e.kind;function ag(e){let{total:t,windowSize:s=3,children:l}=e,[a,i]=(0,r.useState)(0),o=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=e-Math.max(0,s);return n>t+1?n-t:0}(t,s,a);return(0,n.jsxs)(n.Fragment,{children:[a>0?(0,n.jsx)("button",{type:"button",onClick:()=>i(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"}):o>0?(0,n.jsxs)("button",{type:"button",onClick:()=>i(e=>e+Math.min(12,Math.max(0,o))),className:"py-0.5 text-left font-mono text-[10.5px] text-text-subtle hover:text-text",children:["▲ ",o," more ",1===o?"step":"steps"]}):null,l(o)]})}function av(){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 ay=(0,r.memo)(function(e){let{file:t="",patch:s="",diff:l="",content:a="",workspacePath:i=""}=e,[o,c]=(0,r.useState)(!1),d=(0,f.B)(e=>e.openEditorFile),u=av(),m=s||l||(s||l||!a?"":String(a).split("\n").map(e=>`+${e}`).join("\n")),x=m?m.split("\n"):[],p=ar(t,i),h=x.filter(e=>e.startsWith("+")&&!e.startsWith("+++")).length,b=x.filter(e=>e.startsWith("-")&&!e.startsWith("---")).length;return(0,n.jsxs)("div",{className:"my-1 text-xs",children:[(0,n.jsxs)("div",{onClick:()=>c(!o),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:t,children:p.dir?`${p.dir}/${p.name}`:p.name||"diff"}),(h>0||b>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 font-mono text-[10px] shrink-0 text-text-muted",children:[h>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",h]}),b>0&&(0,n.jsxs)("span",{className:"text-danger",children:["-",b]})]}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0",children:o?(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 ${u?"opacity-100":"opacity-0 group-hover/tool:opacity-100"}`,children:t&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),(0,ed.e)(),t&&d(t)},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})})})]}),o&&(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)})})]})}),aw=/"((?:[^"\\]|\\.)*)"\s*=\s*"((?:[^"\\]|\\.)*)"/g,aj=e=>e.replace(/\\(.)/g,"$1"),ak=e=>[...e.matchAll(aw)].map(e=>[aj(e[1]),aj(e[2])]),aN=(0,r.createContext)({sessionId:"",isFocused:!0,activate:null}),aC=()=>(0,r.useContext)(aN),aS=(e,t,s)=>s?`ai-${e}-${t}-${s}`:void 0,aT=(0,r.memo)(function(e){let{requestId:t="",questions:s=[],answers:l=null,declined:a=!1,failed:i=!1,onResolve:o,engine:c=""}=e,{isFocused:d,activate:u}=aC(),[m,x]=(0,r.useState)({}),[p,h]=(0,r.useState)({}),[f,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(0),j=(0,r.useRef)(l);(0,r.useEffect)(()=>{j.current=l});let k=(0,r.useRef)(a);(0,r.useEffect)(()=>{k.current=a});let N=(0,r.useRef)(f);(0,r.useEffect)(()=>{N.current=f}),(0,r.useEffect)(()=>{i&&(N.current=!1,b(!1))},[i]);let C=s[Math.min(y,s.length-1)],S=y>=s.length-1,T=!!m[C?.question]||g,E=(0,r.useCallback)(()=>{j.current||k.current||N.current||s.every(e=>!!m[e.question])&&((0,ed.e)(),N.current=!0,b(!0),o?.(t,"allow","",m))},[s,m,t,o]),R=(0,r.useCallback)(()=>{N.current||k.current||!T||((0,ed.e)(),S?E():w(e=>e+1))},[T,S,E]),M=(0,r.useCallback)(()=>{0!==y&&((0,ed.e)(),w(e=>e-1))},[y]),$=(0,r.useCallback)(()=>{N.current||k.current||j.current||((0,ed.e)(),N.current=!0,b(!0),o?.(t,t8,t9))},[t,o]),z=(0,r.useCallback)((e,t,s)=>{if(!N.current){if((0,ed.e)(),!s){x(s=>({...s,[e]:t})),h(t=>t[e]?{...t,[e]:""}:t),S||w(e=>e+1);return}x(s=>{let n=s[e]?s[e].split(", "):[],r=n.indexOf(t);return r>-1?n.splice(r,1):n.push(t),{...s,[e]:n.join(", ")}})}},[S]),P=(0,r.useCallback)(()=>{d||u?.()},[d,u]);(0,r.useEffect)(()=>{if(!d||f||l||a||!C)return;let e=e=>{if(e.target?.tagName==="INPUT"||e.target?.tagName==="TEXTAREA")return;if("Enter"===e.key){e.preventDefault(),R();return}let t=parseInt(e.key,10);if(t>=1&&t<=9&&C.options?.[t-1]){let e=C.options[t-1];z(C.question,e.label,C.multiSelect)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[C,f,l,a,R,z,d]);let A=l?"string"==typeof l?function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],s=String(e||"");if(!t.length){let e=ak(s);return e.length?Object.fromEntries(e):null}let n={},r=0;for(let[e,l]of t.entries()){let a=s.indexOf(`"${l}"=`,r);if(-1===a)continue;let i=a+l.length+3,o=t[e+1]?s.indexOf(`"${t[e+1]}"=`,i):-1,c=s.slice(i,-1===o?void 0:o),d=c.lastIndexOf('"');d<=0||(n[l]=aj(c.slice(1,d)),r=i+d)}if(Object.keys(n).length)return n;let l=ak(s);return l.length?Object.fromEntries(l):null}(l,s.map(e=>e.question)):l:null;if(a)return(0,n.jsxs)("div",{className:"my-2 p-3 rounded-brand-lg bg-surface text-[14px] flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"text-text-muted font-medium",children:"Skipped"}),C&&(0,n.jsx)("span",{className:"text-text-muted/70 leading-snug",children:C.question}),!!tZ(c).headlessQuestions&&(0,n.jsx)("span",{className:"text-[12px] text-text-muted/60 leading-snug",children:"Headless Antigravity cannot wait for an answer — open it in a terminal (new terminal → Antigravity) to answer questions interactively."})]});if(l)return(0,n.jsxs)("div",{className:"my-2 p-3 rounded-brand-lg border border-success/30 bg-success/10 text-[14px] font-medium flex flex-col gap-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-success",children:[(0,n.jsx)(el.aJ,{size:14}),(0,n.jsx)("span",{children:"Answered"})]}),s.map((e,t)=>{let s=A?.[e.question];return s?(0,n.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"text-[12px] font-normal text-text-muted leading-snug",children:e.question}),(0,n.jsx)("span",{className:"font-mono text-text pl-2 border-l-2 border-success/40 wrap-anywhere",children:s})]},t):null}),!A&&(0,n.jsx)("span",{className:"font-mono text-text wrap-anywhere",children:String(l)})]});if(!C||!o)return null;let I=m[C.question]||"",D=C.multiSelect&&I?I.split(", "):[I];return(0,n.jsxs)("div",{onPointerDown:P,className:"my-2 p-3 rounded-brand-lg shadow-sm text-[14px] select-none border border-warning/30 bg-warning/[0.06]",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 text-warning font-medium",children:[(0,n.jsx)(el.mN,{size:16,className:"text-warning shrink-0"}),(0,n.jsx)("span",{children:"Question"}),s.length>1&&(0,n.jsxs)("span",{className:"font-mono text-[12px] px-1.5 py-0.5 rounded bg-surface-2 text-text-muted",children:[y+1,"/",s.length]}),C.multiSelect&&(0,n.jsx)("span",{className:"font-mono text-[12px] px-1.5 py-0.5 rounded bg-surface-2 text-text-muted uppercase",children:"multi"})]}),(0,n.jsx)("div",{className:"text-text leading-snug mb-1.5",children:C.question}),C.options?.length>0&&(0,n.jsx)("div",{className:"flex flex-col",children:C.options.map((e,t)=>{let s=D.includes(e.label);return(0,n.jsxs)("button",{type:"button",onClick:()=>z(C.question,e.label,C.multiSelect),className:`px-1.5 py-1 rounded text-left flex items-start gap-2 transition-colors text-[13px] ${s?"bg-brand-500/12":"text-text-muted hover:bg-surface-2 hover:text-text"}`,children:[(0,n.jsx)("span",{className:"font-mono text-[12px] text-text-muted/70 shrink-0 mt-0.5 w-2.5",children:t+1}),(0,n.jsxs)("span",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:`font-medium ${s?"text-brand-400":"text-text"}`,children:e.label}),e.description&&(0,n.jsx)("span",{className:"text-[12px] text-text-muted/70 leading-snug",children:e.description})]}),s&&(0,n.jsx)(el.aJ,{size:12,className:"text-brand-500 shrink-0 mt-0.5"})]},t)})}),(0,n.jsx)("input",{type:"text",value:p[C.question]||"",disabled:f,onFocus:()=>v(!0),onChange:e=>{var t,s;return t=C.question,s=e.target.value,void(h(e=>({...e,[t]:s})),x(e=>({...e,[t]:s})))},onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent?.isComposing||229===e.keyCode||(e.preventDefault(),R())},placeholder:"Type your answer...",className:`w-full px-1.5 py-1 rounded bg-bg border border-border-subtle text-[13px] text-text placeholder-text-muted/70 focus:outline-none focus:border-brand-500 disabled:opacity-40 ${C.options?.length?"mt-1.5":"mt-1"}`}),i&&(0,n.jsx)("div",{className:"mt-1.5 text-[13px] text-danger leading-snug",children:"Not sent — the host did not answer. Try again."}),(0,n.jsxs)("div",{className:"mt-2 flex items-center gap-1.5 justify-end",children:[(0,n.jsx)("button",{type:"button",onClick:$,disabled:f,className:"px-2 py-1 rounded text-[13px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Skip"}),y>0&&(0,n.jsxs)("button",{type:"button",onClick:M,className:"px-2 py-1 rounded text-[13px] text-text-muted hover:text-text hover:bg-surface-2 transition-colors flex items-center gap-0.5",children:[(0,n.jsx)(el.JG,{size:13}),(0,n.jsx)("span",{children:"Back"})]}),(0,n.jsxs)("button",{type:"button",onClick:R,disabled:f||!T,className:"px-2.5 py-1 rounded bg-brand-500 hover:bg-brand-600 text-white flex items-center gap-1 text-[13px] font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,n.jsx)("span",{children:S?f?"Sending…":"Submit":"Next"}),S?(0,n.jsx)(el.Lt,{size:11}):(0,n.jsx)(el.c_,{size:12})]})]})]})}),aE=(0,r.memo)(function(e){let{text:t="",isLive:s=!1,defaultOpen:l=!1}=e,[a,i]=(0,r.useState)(l);return t?.trim()?(0,n.jsxs)("div",{className:"my-1.5 text-xs select-none",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>i(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:s?"animate-pulse text-success":"text-success"}),(0,n.jsx)("span",{className:"italic",children:s?"Thinking...":"Thought process"}),(0,n.jsx)("span",{className:"text-text-muted/50 group-hover:text-text-muted",children:a?(0,n.jsx)(el.yQ,{size:12}):(0,n.jsx)(el.c_,{size:12})})]}),a&&(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:t})]}):null}),aR=/Command running in background with ID:\s*([^\s.]+)/,aM=(0,r.memo)(function(e){let t,{id:s="",name:l="Bash",input:a=null,output:i="",error:o="",status:c="done",defaultExpanded:d=!1}=e,{sessionId:u}=aC(),m=!!(o||"error"===c),[x,p]=(0,r.useState)(d),[h,f]=(0,r.useState)(!1),[b,g]=(0,r.useState)(!1),v=a?.command||"",y=a?.description||"",w=o||i||"",j="string"==typeof w?w:w?JSON.stringify(w,null,2):"",k=(t=aR.exec("string"==typeof i?i:""))?t[1]:"",N=!!(a?.run_in_background||k);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:aS(u,"shell",s),children:[(0,n.jsxs)("div",{onClick:()=>p(!x),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"===c?(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-accent"}):m?(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:`min-w-0 flex-1 text-[11px] leading-relaxed break-words ${y?"text-text":"font-mono text-text wrap-anywhere"}`,title:y||v,children:y||function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(!e)return"";let t=e.split(/\n/)[0].replace(/\s*<<-?\s*['"]?[A-Za-z_][A-Za-z0-9_]*['"]?.*$/," <<…");if((t=(t=t.replace(/\s*2?>\s*\/dev\/null/g,"").replace(/\s+/g," ").trim()).replace(/(['"])((?:\\.|(?!\1).){24,})\1/g,(e,t,s)=>s.length<=18?`${t}${s}${t}`:`${t}${s.slice(0,18)}…${t}`)).length>72){let e=t.slice(0,72),s=e.lastIndexOf(" ");t=`${(s>24?e.slice(0,s):e).trimEnd()}…`}return t}(v)||l}),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:x?(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),f(!0),setTimeout(()=>f(!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:h?(0,n.jsx)(el.aJ,{size:11,className:"text-success"}):(0,n.jsx)(el.QR,{size:11})})})]}),x&&(j||v)&&(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:[v&&(0,n.jsxs)("pre",{className:"p-2 pb-1 whitespace-pre-wrap wrap-anywhere leading-relaxed text-text-muted",children:[(0,n.jsx)("span",{className:"select-none opacity-60",children:"$ "}),v]}),j&&(0,n.jsx)("pre",{className:`p-2 whitespace-pre-wrap wrap-anywhere leading-relaxed ${m?"text-danger":"text-text"} ${v?"pt-0":""}`,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 a$(e){let t=String(e||"").split("\n")[0].trim();return t.length>140?`${t.slice(0,140)}…`:t}let az=(0,r.memo)(function(e){let{id:t="",name:s="Agent",input:l=null,output:a="",error:i="",status:o="done",children:c=[],engine:d="claude",workspacePath:u="",defaultExpanded:m=!1}=e,{sessionId:x}=aC(),p="running"===o,h=!!(i||"error"===o),f=c.filter(e=>"running"===e.status).length,[b,g]=(0,r.useState)(h||m);(0,r.useEffect)(()=>{h&&g(!0)},[h]);let v=ls.has(s),y=v?ln({input:l}):s||"agent",w=v?a$(l?.prompt??l?.description??l?.message):a$(l?.message??l?.prompt??l?.query);return(0,n.jsxs)("div",{className:"my-1 text-xs",id:aS(x,"agent",t),children:[(0,n.jsxs)("div",{onClick:()=>g(!b),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:p?(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-accent"}):h?(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:y}),w&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",title:w,children:w})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 shrink-0 ml-2",children:[c.length>0&&(0,n.jsxs)("span",{className:"font-mono text-[10px] text-text-subtle",title:`${c.length} sub-agent tool calls`,children:[p&&f>0?`${f}/${c.length}`:c.length," tools"]}),(0,n.jsx)("span",{className:"text-text-muted/50",children:b?(0,n.jsx)(el.yQ,{size:11}):(0,n.jsx)(el.c_,{size:11})})]})]}),b&&(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:[c.length>0?(0,n.jsx)(ag,{total:c.length,children:e=>(e>0?c.slice(e):c).map(e=>aL(d,e,{workspacePath:u})||(0,n.jsx)(ad,{...e,engine:d,workspacePath:u},e.id))}):(0,n.jsx)("div",{className:"text-text-muted italic py-0.5",children:p?"Sub-agent started…":"No tool calls reported."}),!p&&(a||i)&&(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 wrap-anywhere leading-relaxed ${h?"text-danger":"text-text-muted"}`,children:"string"==typeof(i||a)?i||a:JSON.stringify(i||a,null,2)})})]})]})}),aP=(0,r.memo)(function(e){let{toolName:t="EnterPlanMode",input:s={}}=e,r="string"==typeof s?.plan?s.plan.trim():"";if(r)return(0,n.jsx)(aA,{plan:r,explanation:s?.explanation||""});let l="EnterPlanMode"===t,a=s?.reason||(l?"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 ${l?"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:[l?(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:l?"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:t})]}),(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: "}),a]}),l&&(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."})]})}),aA=(0,r.memo)(function(e){let{plan:t,explanation:s=""}=e;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 wrap-anywhere pl-6 max-h-[320px] overflow-y-auto",children:t}),s&&(0,n.jsx)("div",{className:"text-[11px] text-text-muted pl-6 italic",children:s})]})}),aI=(0,r.memo)(function(e){let{toolName:t="enteredReviewMode",input:s={}}=e,r="enteredReviewMode"===t,l=String(s?.review||"").trim();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 gap-2 font-semibold",children:[r?(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:r?"Code review started":"Code review finished"})]}),l&&(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: "}),l]})]})}),aD={bash:(e,t,s)=>(0,n.jsx)(aM,{...e,deferred:t,defaultExpanded:s?.defaultExpanded},e.id),agent:(e,t,s)=>{let{engine:r,workspacePath:l,defaultExpanded:a}=s;return(0,n.jsx)(az,{...e,engine:r,workspacePath:l,defaultExpanded:a},e.id)},plan:e=>(0,n.jsx)(aP,{toolName:e.name,input:e.input},e.id),review:e=>(0,n.jsx)(aI,{toolName:e.name,input:e.input},e.id),question:(e,t,s)=>{if("running"===e.status||!e.output&&!e.error)return null;let r=!!tZ(s?.engine).headlessQuestions&&/user skipped/i.test(String(e.output||""));return(0,n.jsx)(aT,{engine:s?.engine,questions:e.input?.questions||[],answers:r||e.error?null:e.output||"",declined:r||!!e.error||"error"===e.status},e.id)}};function aL(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=aD[tQ(e,t.name)];return n?n(t,s.deferred,{...s,engine:e}):null}var aB=s(7601),aF=s(46118);function aO(e,t){let s=window.__TAURI__?.opener;s?.openUrl&&(e.preventDefault(),s.openUrl(t).catch(()=>{}))}let a_=(e,t)=>function(s){let{children:r,className:l,node:a,...i}=s;return(0,n.jsx)(e,{className:l?`${t} ${l}`:t,...i,children:r})},aK={h1:a_("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:a_("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:a_("h3","text-base sm:text-lg font-semibold mt-3.5 mb-2 text-text"),h4:a_("h4","text-sm sm:text-base font-semibold mt-3 mb-1.5 text-text"),h5:a_("h5","text-xs sm:text-sm font-semibold mt-2.5 mb-1 text-text"),h6:a_("h6","text-xs font-semibold mt-2 mb-1 text-text-muted"),p:a_("p","my-2 leading-relaxed text-text text-sm"),ul:a_("ul","list-disc pl-5 my-2 space-y-1 text-sm text-text"),ol:a_("ol","list-decimal pl-5 my-2 space-y-1 text-sm text-text"),li:a_("li","leading-relaxed"),blockquote:a_("blockquote","border-l-4 border-brand-500/40 pl-3.5 my-2.5 text-text-muted italic text-sm"),th:a_("th","border border-border-subtle bg-surface-2 px-3 py-1.5 font-semibold text-left text-text align-top wrap-anywhere min-w-[80px]"),td:a_("td","border border-border-subtle px-3 py-1.5 text-text align-top wrap-anywhere min-w-[80px]"),hr:a_("hr","border-t border-border-subtle my-4"),img:e=>{let{alt:t="",node:s,...r}=e;return(0,n.jsx)("img",{className:"max-w-full h-auto rounded my-2",alt:t,...r})},a:e=>{let{children:t,className:s,href:r,node:l,...a}=e;return(0,n.jsx)("a",{className:`text-brand-500 hover:underline wrap-anywhere${s?` ${s}`:""}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>aO(e,r),...a,children:t})},table:e=>{let{children:t,node:s,...r}=e;return(0,n.jsx)("div",{className:"my-3 overflow-x-auto custom-scrollbar",children:(0,n.jsx)("table",{className:"w-full table-auto border-collapse border border-border-subtle text-xs",...r,children:t})})},pre:function(e){let{children:t,node:s,...l}=e,[a,i]=(0,r.useState)(!1),o=(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=o.current?.innerText||"";try{navigator.clipboard.writeText(t)}catch{}i(!0),setTimeout(()=>i(!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:a?(0,n.jsx)(el.aJ,{size:13,className:"text-brand-500"}):(0,n.jsx)(el.QR,{size:13})}),(0,n.jsx)("pre",{ref:o,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",...l,children:t})]})},code:e=>{let{children:t,className:s,node:r,...l}=e,a=/language-/.test(s||"");return(0,n.jsx)("code",{className:`${a?"font-mono text-[12px] text-text":"font-mono text-[0.9em] text-accent wrap-anywhere"}${s?` ${s}`:""}`,...l,children:t})},input:e=>{let{type:t,checked:s,node:r,...l}=e;return"checkbox"===t?(0,n.jsx)("input",{type:"checkbox",checked:s,readOnly:!0,className:"mr-2 rounded accent-brand-500 cursor-default",...l}):(0,n.jsx)("input",{type:t,...l})}},aW=(0,r.memo)(function(e){let{content:t,components:s}=e;return(0,n.jsx)(aB.oz,{remarkPlugins:[aF.A],components:s?{...aK,...s}:aK,children:t})},(e,t)=>e.content===t.content);function aH(e){let{row:t,engine:s,workspacePath:r,deferred:l}=e;if("thought"===t.kind)return(0,n.jsx)(aE,{text:t.text,isLive:t.isLive});if("diff"===t.kind){let e=t.diff;return(0,n.jsx)(ay,{file:e.file,patch:e.patch,diff:e.diff,content:e.content,workspacePath:r})}let a=t.tool;return aL(s,a,{workspacePath:r,deferred:l})||(0,n.jsx)(ad,{...a,engine:s,workspacePath:r,deferred:l})}let aq={info:"text-text-muted",suggestion:"text-text-muted",warning:"text-warning",error:"text-danger"};function aU(e){let{notice:t}=e;if(!t?.content)return null;let s=`text-xs leading-relaxed py-1 px-2 my-0.5 rounded border-l-2 border-current/30 bg-surface-2/40 wrap-anywhere ${aq[t.level]||aq.info}`;return t.compacting?(0,n.jsxs)("div",{className:`${s} 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:t.content}),(0,n.jsx)(aV,{})]}):(0,n.jsxs)("div",{className:s,children:[t.content,t.compact?.detail&&(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",t.compact.detail]}),t.compact?.durationMs?(0,n.jsxs)("span",{className:"text-text-muted",children:[" \xb7 ",aX(t.compact.durationMs)]}):null]})}function aX(e){let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`}function aV(){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:aX(t-e)})}function aG(e){let{content:t,isLive:s,images:l=[],fileBus:a=null}=e,i=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}(t,s);return(0,n.jsx)("div",{className:"flex justify-start mb-3 mt-1",children:(0,n.jsxs)("div",{className:"max-w-[94%] @2xl:max-w-[768px] min-w-0 px-3.5 py-2 rounded-[16px] rounded-tl-[4px] bg-[var(--chat-bubble-theirs)] shadow-[0_1px_2px_rgba(0,0,0,0.08)] text-sm leading-relaxed text-[var(--chat-bubble-theirs-text)] wrap-anywhere",children:[(0,n.jsx)(aW,{content:i}),s&&(0,n.jsx)("span",{className:"inline-block w-1.5 h-3.5 bg-brand-500 animate-pulse ml-1 align-middle"}),l.length>0&&(0,n.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:l.map((e,t)=>(0,n.jsx)(ai,{img:e,fileBus:a,images:l,index:t},`${e.path}-${t}`))})]})})}let aJ=(0,r.memo)(function(e){let{messages:t=[],engine:s="claude",workspacePath:l="",onResolvePermission:a,isLive:i=!0,fileBus:o=null,showImages:c=!0}=e,d=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"claude",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,ax.has(t?.name)&&s&&((t.input?.paths||[]).includes(s)||ap(t.input)===s))})||"task"===tQ(e,t.name)&&au.has(t.name)))}(t,r.tools,r.diffs);for(let l=0;l<e.length;l++){let a=e[l];if("question"===tQ(t,a.name)&&"running"===a.status&&am(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})(t,s),[t,s]),u=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6,{deferred:s=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=[];for(let t of e)if(ab(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}})})(d,3,{deferred:!i}),[d,i]),m=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=[],s=new Set,n=e=>{let r=e?.input,l="string"==typeof r?"":af.map(e=>r?.[e]).find(e=>"string"==typeof e&&e);for(let r of(l&&ah.test(l)&&!s.has(l)&&(s.add(l),t.push({path:l,name:String(l).split(/[/\\]/).pop()||l,toolName:e?.name})),e?.children||[]))n(r)};for(let t of e)"tool"===t.kind&&n(t.tool);return t})(d),[d]),x=(0,r.useMemo)(()=>{for(let e=d.length-1;e>=0;e--)if("prose"===d[e].kind)return d[e].id;return null},[d]);return(0,n.jsx)("div",{className:"my-1",children:u.map(e=>{if("steps"!==e.type){if("prose"===e.row.kind){let t=e.row.id===x;return(0,n.jsx)(aG,{content:e.row.content,isLive:e.row.isLive,images:t&&c?m:[],fileBus:t&&c?o:null},e.key)}if("notice"===e.row.kind)return(0,n.jsx)(aU,{notice:e.row.notice},e.key);if("permission"===e.row.kind){let t=e.row.permission;return(0,n.jsx)(aT,{requestId:t.requestId,questions:t.input?.questions||[],onResolve:a},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)(ag,{total:e.rows.length,children:t=>(t>0?e.rows.slice(t):e.rows).map(e=>(0,n.jsx)(aH,{row:e,engine:s,workspacePath:l,deferred:!i},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.showImages===t.showImages&&e.onResolvePermission===t.onResolvePermission});function aY(e){let{background:t=!1,engine:s="claude",size:r=16,className:l=""}=e;if(t)return(0,n.jsx)(el.BK,{size:r,className:l||"text-text"});let a=e8(s);return a?(0,n.jsx)("img",{src:a,alt:s,draggable:!1,style:{width:r,height:r},className:`flex-shrink-0 object-contain ${e6} ${l}`}):(0,n.jsx)(el.cC,{size:r,className:l||"text-text"})}let aZ=(0,r.memo)(function(e){let{tasks:t=[],messages:s=[],engine:l="claude",sessionId:a="",onStopTask:i,onClose:o}=e,[c,d]=(0,r.useState)(()=>Date.now()),[u,m]=(0,r.useState)(null),x=lH(e=>e.bySession[a]?.harnessTasks);(0,r.useEffect)(()=>{let e=setInterval(()=>d(Date.now()),1e3);return()=>clearInterval(e)},[]);let p=(0,r.useMemo)(()=>t.map(e=>x?.find(t=>t.taskId===e.taskId)||e),[t,x]),h=p.find(e=>e.taskId===u)||p[0];if(!h)return null;let f=lw(h,c),b=!h.endedAt&&("running"===h.status||"paused"===h.status);return(0,n.jsxs)(rn,{icon:(0,n.jsx)(aY,{background:h.background,engine:l,size:16}),iconClass:"",title:h.description||h.subagentType||"Task",subtitle:b?`Running for ${as(f)}`:`Ended \xb7 ${as(f)}`,onClose:o,actions:b&&h.taskId&&i?(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),i(h.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:[p.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:p.map((e,t)=>{let s=e.taskId===h.taskId;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),m(e.taskId)},className:`shrink-0 flex items-center gap-1.5 px-2.5 py-1 rounded-brand text-xs transition-colors ${s?"bg-surface-2 text-text font-medium":"text-text-muted hover:text-text hover:bg-surface-2/40"}`,children:[(0,n.jsx)(aY,{background:e.background,engine:l,size:13,className:s?"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?as(lw(e,c)):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)(aQ,{task:h,messages:s,engine:l,running:b}),h.summary&&(0,n.jsx)("p",{className:"mt-3 text-[11px] text-text-muted leading-relaxed",children:h.summary}),h.outputFile&&(0,n.jsxs)("p",{className:"mt-3 font-mono text-[10px] text-text-subtle truncate",title:h.outputFile,children:["output \xb7 ",h.outputFile]})]})]})});function aQ(e){let{task:t,messages:s,engine:r,running:l}=e,a=ll(s,t.toolUseId);if(!a)return(0,n.jsx)("div",{className:"flex flex-col items-center justify-center gap-2.5 py-14 text-text-muted select-none",children:l?(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)(aY,{background:t.background,engine:r,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 i=a.children?.length?a.children:[a],o=a.input?.prompt||a.input?.description||"",c=a.error||a.output||"";return(0,n.jsxs)("div",{className:"flex flex-col",children:[o&&!a.async&&(0,n.jsx)(an,{message:{id:`${a.id}:p`,role:"user",content:o},engine:r}),i.map(e=>aL(r,e,{deferred:!l,workspacePath:""})||(0,n.jsx)(ad,{...e,engine:r,workspacePath:"",deferred:!l},e.id)),!l&&c&&(0,n.jsx)(aJ,{messages:[{id:`${a.id}:r`,role:"assistant",content:String(c),isLive:!1}],engine:r,isLive:!1})]})}let a0=[{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"}],a1=a0[a0.length-1];function a2(e){let{className:t=""}=e,{t:s}=(0,eu.s)(),[l,a]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>a((Date.now()-e)/1e3),500);return()=>clearInterval(t)},[]);let i=a0.find(e=>l<e.until)||a1,o=Math.min(1,Math.max(0,(l-i.start)/(i.until-i.start))),c=Math.round(i.pct[0]+(i.pct[1]-i.pct[0])*o);return(0,n.jsxs)("div",{className:`flex items-center gap-2 min-w-0 ${t}`,title:`${s(i.key)} — ${c}%`,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:`${c}%`}})})]})}function a5(e){let{hostKey:t,approval:s,onDeleteHost:r=null}=e,{t:l}=(0,eu.s)();if(!s)return null;let a="pending"===s;return(0,n.jsxs)("div",{className:`flex items-center gap-2 py-1.5 ${a?"":"text-red-400"}`,children:[a?(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:l(a?"connection.approvalHint":"connection.rejectedDescription"),children:l(a?"connection.waitingApproval":"connection.rejectedTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),P.rh.getState().connectHost(t)},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:l("common.retry")}),a?(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),P.rh.getState().disconnectHost(t)},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:l("common.cancel")}):r&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),r(t)},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:l("hosts.removeHost")})]})}let a3=[];function a4(e){let{host:t,actions:s={},busRef:l=null,activeSessionId:a=null,activeWorkspaceId:i=null,connected:o=!0,fileBus:c=null,homeDir:d=null,hiddenPaneSessionIds:u=[],onUnhidePane:m=null,onAddWorkspace:x=null,menuAddWorkspace:p=null,onOpenRemoteHost:h=null,onOpenMobileHost:f=null,onRowContextMenu:b=null,onRowTouch:g=null,onRowMenu:v=null,agentBySession:y=null,cwdBySession:w=null,treeCls:j="pl-3.5",mobile:k=!1,onResumeAgentSession:N=null,rowCls:C="hover:bg-text/5 hover:text-text"}=e,{t:S}=(0,eu.s)(),{isCollapsed:T,toggle:E}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",[t,s]=(0,r.useState)(()=>new Set(r5()[e]||[])),n=(0,r.useCallback)(t=>{s(s=>{let n=new Set(s);n.has(t)?n.delete(t):n.add(t);let r=r5();r[e]=[...n];try{localStorage.setItem(r1,JSON.stringify(r))}catch{}return n})},[e]);return{isCollapsed:(0,r.useCallback)(e=>t.has(e),[t]),toggle:n}}(t.key),R=!T(r2),[M,$]=(0,r.useState)(null),[z,A]=(0,r.useState)(null),[I,D]=(0,r.useState)(null),[L,B]=(0,r.useState)(null),[F,O]=(0,r.useState)(null),[_,K]=(0,r.useState)(!1),[W,H]=(0,r.useState)([]),[q,U]=(0,r.useState)(!1),X=t.status||"full",V="connecting"===X,G="full"===X||"online"===X,J="full"===X?o:G,Y="full"!==X?eM(t.key):null,Z=l||Y?.busRef||null;(0,r.useEffect)(()=>{null!==M&&Z?.current?.emit&&Z.current.emit("getShells",e=>H(e?.shells||[]))},[M,Z]);let Q=e=>{(0,ed.e)(),s.selectSession?.(e)},{dragId:ee,registerEl:et,startDrag:es,consumeClick:en}=nV({axis:"y",onTap:Q,onCommit:e=>s.reorderSession?.(e)}),er=(0,r.useRef)(null),ea=()=>{er.current&&(clearTimeout(er.current.timer),er.current=null)},ei=e=>{let t=er.current;t&&(Math.abs(e.clientX-t.start.x)>eg.Qe||Math.abs(e.clientY-t.start.y)>eg.Qe)&&ea()};(0,r.useEffect)(()=>{if(!ee)return;let e=e=>e.preventDefault();return window.addEventListener("touchmove",e,{passive:!1}),()=>window.removeEventListener("touchmove",e)},[ee]);let eo=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],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)}]:[]]}(t.sessions,t.workspaces),em=(0,r.useMemo)(()=>new Set((t.sessions||[]).map(e=>e.id)),[t.sessions]);return(0,n.jsxs)("div",{children:[(0,n.jsx)(r0,{mobile:k,hostKey:t.key,label:t.label,connected:G,connecting:V,mutedOffline:"full"!==X,collapsed:!R,meta:V?(0,n.jsx)(el.kr,{size:12,className:"animate-spin text-text-subtle"}):null,hostUpdating:!!t.updating,onOpenRemote:G&&t.remoteAvailable&&h?()=>h(t.key):null,onOpenMobile:G&&t.mobileAvailable&&f&&!t.updating?()=>f(t.key):null,onToggleCollapse:G?()=>{(0,ed.e)(),R||P.rh.getState().ensureHost(t.key),E(r2)}:null,onConnect:"offline"===X?t.onConnect||(()=>P.rh.getState().connectHost(t.key)):null,onDisconnect:t.onDisconnect,onAddWorkspace:J?p??("full"!==X?()=>K(!0):null):null,onRename:s.renameHost,onDelete:s.deleteHost,showAdd:!1}),t.updating?(0,n.jsx)("div",{className:`${j} py-2`,children:(0,n.jsx)(a2,{})}):t.approval?(0,n.jsx)("div",{className:j,children:(0,n.jsx)(a5,{hostKey:t.key,approval:t.approval,onDeleteHost:s.deleteHost})}):R&&G&&(0,n.jsxs)("div",{className:j,children:[t.updateAvailable&&t.canSelfUpdate&&!t.approval&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),U(!0)},title:S("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:[S("menu.updateNow"),t.updateAvailable?.version?` \xb7 ${t.updateAvailable.version}`:""]})]}),eo.map(e=>{let{workspace:o,sessions:x}=e,h=o?.id??null,f=h??"ungrouped",j=i===h;return(0,n.jsxs)("div",{className:`flex flex-col ${k?"":"mt-1 first:mt-0"}`,children:[(0,n.jsx)(le,{mobile:k,workspace:{id:h,name:o?.name||S("workspaces.ungrouped"),path:o?.path||null,items:x},isActive:j,connected:J,fileBus:c,statusMap:t.statusMap,collapsed:T(f),onToggleCollapse:()=>E(f),onSelect:s.selectWorkspace?()=>{(0,ed.e)(),s.selectWorkspace(h)}:null,onNewTerminal:s.createSession?()=>$(f):null,onAddWorkspace:p,onRename:s.renameWorkspace&&null!=h?()=>A({id:h,value:o.name}):null,onDelete:s.deleteWorkspace&&null!=h?()=>D({id:h,name:o.name}):null}),!T(f)&&x.map((e,l)=>{let i=t.statusMap?.[e.id]?.state||"idle",p=s7(i),j=a===e.id,N=ee===e.id,T=u.includes(e.id),E=e.name||S("terminal.defaultName");return(0,n.jsx)(r.Fragment,{children:(0,n.jsxs)("div",{ref:et(e.id),"data-sid":e.id,style:k?{"--i":String(Math.min(l,6))}:void 0,className:`group flex items-center gap-1.5 ${k?"pl-6 pr-9 list-rise":"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 ${j?"bg-brand-500/15 text-text":`text-text/85 active:bg-text/[0.06] ${C}`} ${N?"z-20 opacity-90 shadow-lg ring-1 ring-brand-500":"transition-colors"}`,onClick:()=>{en()||Q(e.id)},onPointerDown:t=>((e,t,s)=>{if(s.length<2||!J)return;if("mouse"===e.pointerType)return void es(e,t,s);if(g)return;let n={x:e.clientX,y:e.clientY};er.current={timer:setTimeout(()=>{ea(),(0,ed.e)(),es(e,t,s)},eg.A_),start:n}})(t,e.id,x.map(e=>e.id)),onPointerMove:ei,onPointerUp:ea,onPointerCancel:ea,onPointerLeave:ea,onContextMenu:b?t=>b(t,e.id,E):void 0,onTouchStart:g?.start,onTouchMove:g?.move,onTouchEnd:g?.end,children:[J&&(0,n.jsx)("button",{"data-gid":"ungrouped"===f?"":h,"data-sid":e.id,onPointerDown:t=>{t.stopPropagation(),es(t,e.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 ${p.cls}${p.pulse?` pulse-${p.pulse}`:""}`,style:{background:p.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 ${j?"font-medium":""}`,children:[(0,n.jsx)(nf,{agent:y?.[e.id]??e.agent,tool:t.statusMap?.[e.id]?.tool}),(0,n.jsx)("span",{className:`${k?"text-[17px]":"text-[11px]"} truncate`,"data-tip":E,children:E}),T&&m&&(0,n.jsx)("button",{type:"button",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),(0,ed.e)(),m(e.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:S("sessions.showPanel")||"Show panel",children:(0,n.jsx)(el.X_,{size:12})})]}),(0,n.jsx)(lt,{mobile:k,fileBus:c,cwd:w?.[e.id]??e.cwd??e.workspacePath,basePath:nm({path:o?.path||null,items:x}),homeDir:d})]}),(0,n.jsx)("div",{className:`absolute right-1 top-1/2 -translate-y-1/2 flex items-center ${k?"opacity-100":"px-1 rounded-[3px] bg-surface-2 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-60"} transition-opacity`,children:v?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)();let s=t.currentTarget.getBoundingClientRect();v(e.id,E,s)},className:"p-0.5 text-text-subtle hover:text-text rounded-[2px] transition-colors",title:S("sessions.sessionActions"),children:(0,n.jsx)(el.a4,{size:k?18:13.5})}):(0,n.jsx)(rV,{size:k?18:13.5,label:S("sessions.sessionActions"),revealCls:"",items:["done"===i&&{icon:el.aJ,label:S("sessions.markRead"),amber:!0,onClick:()=>ek.getState().clearNotification(e.id)},s.renameSession&&{icon:el.gH,label:S("sessions.editName"),onClick:()=>B({id:e.id,value:e.name||""})},s.backgroundSession&&{icon:el._V,label:S("menu.terminalBackground"),onClick:()=>s.backgroundSession(e)},s.deleteSession&&{icon:el.TB,label:S("sessions.deleteTitle"),danger:!0,onClick:()=>O({id:e.id,name:e.name||""})}]})})]})},e.id)}),!T(f)&&l&&(0,n.jsx)(a6,{busRef:l,storeKey:h??"default",workspaceId:h,mobile:k,rowCls:C,onSelectWorkspace:s.selectWorkspace?()=>s.selectWorkspace(h):null}),!T(f)&&(k?(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-[15px] text-text-muted hover:text-brand-500 transition-colors disabled:opacity-40",title:S("workspaces.addTerminal"),children:[(0,n.jsx)(el.FW,{size:15,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("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:S("workspaces.addTerminal"),children:[(0,n.jsx)(el.FW,{size:12,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("terminal.newTerminal")})]}):null)]},f)}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),x?x():K(!0)},disabled:!J,className:`w-full flex items-center gap-1.5 ${k?"text-[15px] text-text-muted":"text-[12px] mt-1 text-text-subtle"} py-1.5 text-left hover:text-brand-500 transition-colors disabled:opacity-40`,title:S("workspaces.newWorkspace"),children:[(0,n.jsx)(el.FW,{size:k?18:12,className:"flex-shrink-0"}),(0,n.jsx)("span",{children:S("workspaces.newWorkspace")})]})]}),null!==M&&(0,n.jsx)(n_,{onClose:()=>$(null),onCreate:(e,t,n,r,l,a)=>{s.createSession?.(e,"ungrouped"===M?null:M,t,l,n,r,a),$(null)},shells:W,busRef:Z,hostKey:t.key,onResumeAgentSession:N,onSelectSession:s.selectSession,liveSessionIds:em,connected:J,workspaceId:"ungrouped"===M?null:M,workspacePath:t.workspaces?.find(e=>e.id===("ungrouped"===M?null:M))?.path||null,workspaceName:"ungrouped"===M?S("workspaces.ungrouped"):t.workspaces?.find(e=>e.id===M)?.name||"",suggestName:`${S("terminal.defaultName")} ${(t.sessions?.length||0)+1}`}),_&&Y&&(0,n.jsx)(nI,{fileBus:Y.fileBus,scope:Y.scope,onSelect:e=>{if(K(!1),!e)return;let t=e.split("/").filter(Boolean).pop()||e;ef(e,Y.scope),s.createWorkspace?.(t,e,t=>{let n=t?.workspace||t?.group;t?.success&&n?.id&&s.createSession?.(null,n.id,null,e)})},onClose:()=>K(!1)}),null!==z&&(0,n.jsx)(nk,{title:S("workspaces.rename"),value:z.value,onChange:e=>A({...z,value:e}),onSubmit:()=>{let e=z.value.trim();e&&s.renameWorkspace?.(z.id,e),A(null)},onClose:()=>A(null)}),null!==I&&(0,n.jsx)(ec.A,{isOpen:!0,onClose:()=>D(null),onConfirm:()=>{s.deleteWorkspace?.(I.id),D(null)},title:S("workspaces.deleteTitle"),message:S("workspaces.deleteMessage",{name:I.name}),confirmText:S("common.delete")}),(0,n.jsx)(ec.A,{isOpen:q,onClose:()=>U(!1),onConfirm:()=>{U(!1),P.rh.getState().requestHostUpdate(t.key,"update")},title:S("menu.updateConfirmTitle"),message:S("menu.updateConfirmMessage")}),null!==L&&(0,n.jsx)(nk,{title:S("sessions.editName"),value:L.value,onChange:e=>B({...L,value:e}),onSubmit:()=>{let e=L.value.trim();e&&s.renameSession?.(L.id,e),B(null)},onClose:()=>B(null)}),null!==F&&(0,n.jsx)(ec.A,{isOpen:!0,onClose:()=>O(null),onConfirm:()=>{s.deleteSession?.(F.id),O(null)},title:S("sessions.deleteTitle"),message:S("sessions.deleteMessage",{name:F.name||""}),confirmText:S("common.delete")})]})}function a6(e){let{busRef:t,storeKey:s,workspaceId:r,mobile:l,rowCls:a,onSelectWorkspace:i}=e,o=nc(e=>e.workspaceProfiles[s]||"default"),c=nc(e=>e.tabsByWorkspace[s]??a3),d=nc(e=>e.activeByWorkspace[s]||null),u=(0,f.B)(e=>{let t=e.viewStack;return!!(t&&t[t.length-1]?.type==="browser")}),m=(0,f.B)(e=>e.pushView),x=(0,f.B)(e=>(e.activeWorkspaceId??null)===r),p=(0,f.B)(e=>e.setActiveWorkspaceId);return c.length?c.map(e=>{let c=u&&x&&e.id===d,h=e.title||"Browser";return(0,n.jsxs)("div",{className:`group flex items-center gap-1.5 ${l?"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 ${c?"bg-brand-500/15 text-text":`text-text-muted ${a}`}`,onClick:()=>{var t;return t=e.id,void((0,ed.e)(),!x&&(i?i():p(r)),nc.getState().setActive(s,t),m({type:"browser"}))},title:e.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)(r3,{name:o,size:14}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${l?"text-base":"text-[11px]"} ${c?"font-medium":""}`,"data-tip":h,children:h}),(0,n.jsx)("button",{onClick:n=>{n.stopPropagation(),(0,ed.e)(),t?.current?.emit?.("browser:invoke",{action:"close",payload:{targetId:e.id,profile:nc.getState().workspaceProfiles[s]||"default"}},()=>{});let r=nc.getState(),l=(r.tabsByWorkspace[s]||[]).filter(t=>t.id!==e.id);r.setTabs(s,l),r.activeByWorkspace[s]===e.id&&r.setActive(s,l[0]?.id||null)},className:`p-0.5 rounded text-text-muted hover:text-text hover:bg-surface-3 shrink-0 ${l?"flex":"opacity-0 group-hover:opacity-100"} transition-opacity`,title:"Close tab",children:(0,n.jsx)(el.X,{size:12})})]},e.id)}):null}let a8=(0,m.gJ)(),a9=(0,r.memo)(function(e){let{allSessions:t=[],mainSessions:s=null,workspaces:l=[],activeSessionId:a,activeWorkspaceId:i,sessionStatus:o,notifications:c,onSelectSession:d,onSelectWorkspace:u,onCreateNamedSession:x,onDeleteWorkspace:p,shells:h=[],onRenameSession:b,onDeleteSession:g,onReorderSession:v,onAddWorkspace:y,onRenameWorkspace:w=null,onOpenSettings:j,onOpenRemoteHost:k=null,onOpenMobileHost:N=null,onRenameHost:C=null,onDeleteHost:S=null,onMainDisconnect:T=null,onMainReconnect:E=null,busRef:R=null,fileBus:M,homeDir:$,cwdBySession:z={},connected:A=!0,width:I=eg.gH.default,onResize:D,onCollapse:L,onResumeAgentSession:B}=e,{t:F}=(0,eu.s)(),O=(0,f.B)(e=>e.agentBySession||{}),_=Object.values((0,P.rh)(e=>e.hosts)),K=(0,P.rh)(e=>e.currentKey),W=_.find(e=>e.key===K),[H,q]=(0,r.useState)(!1),U=eT(_,W?.key),X=(0,f.B)(e=>e.fullModes||{});(0,f.B)(e=>e.fullMode);let V=(0,f.B)(e=>e.toggleFullMode),G=(0,f.B)(e=>e.setFullMode),J=(0,f.B)(e=>e.pushView),Y=(0,f.B)(e=>e.viewStack),Z=(0,f.B)(e=>e.setViewStack),Q=Y[Y.length-1]?.type,ee=(0,f.B)(e=>e.hiddenPaneSessionIds||[]),et=(0,f.B)(e=>e.toggleHidePane),es=(0,f.B)(e=>e.unhidePane),en=eI(),er=o||en,ea="mouse"===sj()?tw(F("common.close"),"toggleSidebar"):F("common.close"),ei=(0,r.useMemo)(()=>new Set(t.map(e=>e.id)),[t]),eo=(0,r.useMemo)(()=>s||t.filter(e=>!e.hostKey),[s,t]),em=a?z[a]??t.find(e=>e.id===a)?.cwd??t.find(e=>e.id===a)?.workspacePath??null:null,ex=e$(a),ep=e0(e=>e.canInstall),eh=e0(e=>e.isInstalled),ef=e0(e=>e.install),eb=window.matchMedia("(display-mode: standalone)").matches||!!window.ReactNativeWebView,ev=ep&&!eb&&!eh&&!(0,m.gJ)(),[ey,ew]=(0,r.useState)(null),ej=(0,r.useRef)(null),eN=nK(ej,ey?.left??0,ey?.top??0),[eC,eE]=(0,r.useState)(null),eR=O[ey?.sessionId]||er[ey?.sessionId]?.tool||t.find(e=>e.id===ey?.sessionId)?.agent,eM=eR?.endsWith("-ui");er[ey?.sessionId]?.conversationId;let ez=rh(eR),eP=ez&&rp.has(er[ey?.sessionId]?.state||"idle"),eA=(0,e5.xs)(t.find(e=>e.id===ey?.sessionId))??e5.AD,eD=X[eA]??!1,[eL,eB]=(0,r.useState)({sessionId:null,name:"",value:""}),[eF,eO]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!ey)return;let e=e=>{ej.current&&!ej.current.contains(e.target)&&ew(null)},t=e=>{"Escape"===e.key&&ew(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)}},[ey]);let e_=e=>t.find(t=>t.id===e),eK=e=>{e.preventDefault(),e.stopPropagation();let t=e.currentTarget.dataset.sid,s=e_(t);ew({sessionId:t,left:e.clientX,top:e.clientY,name:s?.name||""})},eW=(0,r.useRef)(null),eH=()=>{eW.current&&(clearTimeout(eW.current),eW.current=null)},eq=e=>{let t,s;t=e.currentTarget.dataset.sid,s=e.touches[0],eW.current=setTimeout(()=>{(0,ed.e)();let e=e_(t);ew({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:I},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)(),Z([{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)(),q(!0)},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",title:F("hosts.addHost"),children:(0,n.jsx)(el.kV,{size:14})}),L&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),L()},className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",title:ea,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:[a8&&(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"===Q?"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)(a4,{host:{...W||{},key:W?.key||"main",label:W?.label||"",workspaces:l,sessions:eo,statusMap:er,onDisconnect:T,onConnect:E},busRef:R,actions:{selectSession:e=>{ee.includes(e)&&es(e),d?.(e)},selectWorkspace:e=>{(0,ed.e)(),u?.(e)},createSession:x,renameSession:b,deleteSession:g,reorderSession:v,renameWorkspace:w,deleteWorkspace:p,renameHost:C,deleteHost:S},activeSessionId:a,activeWorkspaceId:i,connected:A,fileBus:M,homeDir:$,cwdBySession:z,agentBySession:O,hiddenPaneSessionIds:ee,onUnhidePane:es,onAddWorkspace:y,menuAddWorkspace:y,onOpenRemoteHost:k,onOpenMobileHost:N,onRowContextMenu:eK,onRowTouch:{start:eq,move:eH,end:eH},onRowMenu:(e,t,s)=>ew({sessionId:e,left:s.left,top:s.bottom+2,name:t}),treeCls:"pl-3.5"}):(0,n.jsx)(a4,{host:{...e,onDisconnect:()=>P.rh.getState().disconnectHost(e.key)},actions:{...ti(e,{onSelectSession:d,onSelectWorkspace:u}),renameHost:C,deleteHost:S},activeSessionId:a,activeWorkspaceId:function(e,t){let s=eS(e,t);if(null!==s)return"_"===s?null:s}(i,e.key),connected:A,hiddenPaneSessionIds:ee,onOpenRemoteHost:k,onOpenMobileHost:N,onUnhidePane:es,treeCls:"pl-3.5"})},e.key))]}),B&&(0,n.jsx)(nj,{busRef:ex.busRef,scope:ex.scope,cwd:em,onResume:B,onSelectSession:d,liveSessionIds:ei,activeSessionId:a,connected:A}),(ev||j)&&(0,n.jsxs)("div",{className:"p-1.5 border-t border-border-subtle flex-shrink-0 relative z-10",children:[ev&&(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:F("menu.installApp"),children:[(0,n.jsx)(el.f5,{size:14}),(0,n.jsx)("span",{children:F("menu.installApp")})]}),j&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),j()},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:F("menu.settings"),children:[(0,n.jsx)(el.wB,{size:14}),(0,n.jsx)("span",{children:F("menu.settings")})]})]}),H&&(0,n.jsx)(rQ,{onClose:()=>q(!1)}),(0,n.jsx)("div",{onPointerDown:e=>{e.stopPropagation(),eZ(e,{startWidth:I,onWidth:e=>D?.(e)})},className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"}),ey&&(0,n.jsxs)("div",{ref:ej,className:"fixed z-[70] menu-popover p-1 min-w-[160px] pop-in",style:{left:eN.left,top:eN.top},children:[er[ey.sessionId]?.state==="done"&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ek.getState().clearNotification(ey.sessionId),ew(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})," ",F("sessions.markRead")]}),(0,n.jsxs)("button",{onClick:()=>{var e;let t;return e=ey.sessionId,t=e_(e)?.name||"",void(eB({sessionId:e,name:t,value:t}),ew(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})," ",F("sessions.editName")]}),(0,n.jsxs)("div",{className:"relative group/split",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)();let e=ey.sessionId;!eD&&e&&e!==a&&d?.(e),V(eA),ew(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:F("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 ${eN.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=ey.sessionId;!eD&&e&&e!==a&&d?.(e),V(eA),ew(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:[eD?(0,n.jsx)(el.xq,{size:12}):(0,n.jsx)(el.h1,{size:12}),(0,n.jsx)("span",{className:"whitespace-nowrap",children:eD?"Restore":"Maximize"})]}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"100%"})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),ey.sessionId&&ey.sessionId!==a&&d?.(ey.sessionId),eD&&G(eA,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:2}})),ew(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)(),ey.sessionId&&ey.sessionId!==a&&d?.(ey.sessionId),eD&&G(eA,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:3}})),ew(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)(),ey.sessionId&&ey.sessionId!==a&&d?.(ey.sessionId),eD&&G(eA,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:4}})),ew(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)(),ey.sessionId&&ey.sessionId!==a&&d?.(ey.sessionId),eD&&G(eA,!1),window.dispatchEvent(new CustomEvent("terminal:splitPreset",{detail:{fraction:"auto"}})),ew(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)(),et(ey.sessionId),ew(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:[ee.includes(ey.sessionId)?(0,n.jsx)(el.kU,{size:12}):(0,n.jsx)(el.X_,{size:12}),(0,n.jsx)("span",{children:ee.includes(ey.sessionId)?F("sessions.showPanel")||"Show":F("sessions.hidePanel")||"Hide"})]})})]})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eE(ey.sessionId),ew(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"})," ",F("menu.terminalBackground")]}),(O[ey.sessionId]?.endsWith("-ui")||er[ey.sessionId]?.conversationId)&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)();let e=ey.sessionId,t=e$(e).bus;O[e]?.endsWith("-ui")?t?.emit("ai:restart",{sessionId:e}):t?.emit("session-resume",{sessionId:e}),ew(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})," ",O[ey.sessionId]?.endsWith("-ui")?F("sessions.restartAi")||"Restart AI":F("sessions.resumeSession")]}),ez&&(0,n.jsxs)("button",{disabled:!eP,onClick:()=>{(0,ed.e)();let e=ey.sessionId;e$(e).bus?.emit("setSessionMode",{sessionId:e,mode:eM?"terminal":"ui"},e=>{e?.success||alert(e?.error||F("sessions.modeSwitchFailed"))}),ew(null)},className:`w-full text-left px-2.5 py-1.5 text-xs rounded-[6px] flex items-center gap-2 ${eP?"text-text hover:bg-surface-2/80":"text-text-subtle cursor-not-allowed"}`,children:[(0,n.jsx)(el.sU,{size:13})," ",eM?F("sessions.openAsTerminal"):F("sessions.openAsUi")]}),(0,n.jsx)("div",{className:"h-px bg-border-subtle my-1"}),(0,n.jsxs)("button",{onClick:()=>{eO({sessionId:ey.sessionId,name:ey.name}),ew(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})," ",F("sessions.deleteTitle")]})]}),eC&&(0,n.jsx)(nU,{sessionId:eC,title:e_(eC)?.name,busRef:R,onClose:()=>eE(null)}),eL.sessionId&&(0,n.jsx)(nk,{title:F("sessions.editName"),placeholder:eL.name,value:eL.value,onChange:e=>eB({...eL,value:e}),onSubmit:()=>{let e=eL.value.trim();eL.sessionId&&e&&b?.(eL.sessionId,e),eB({sessionId:null,name:"",value:""})},onClose:()=>eB({sessionId:null,name:"",value:""})}),(0,n.jsx)(ec.A,{isOpen:!!eF,onClose:()=>eO(null),onConfirm:()=>{eF?.sessionId&&g?.(eF.sessionId)},title:F("sessions.deleteTitle"),message:F("sessions.deleteMessage",{name:eF?.name||""}),confirmText:F("common.delete")})]})}),a7={claude:"Claude",codex:"Codex",kimi:"Kimi",grok:"Grok"};function ie(e){return e<60?"bg-text-muted/40":e<80?"bg-yellow-500":"bg-red-500"}function it(e){let{enabled:t=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[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=nb(r,6e4);return()=>{s=!0,l()}},[e,t]),s}let is=[["session","5h"],["weekly","wk"],["monthly","mo"]];function ir(e){let{usedPct:t}=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 ${ie(t)}`,style:{width:`${Math.min(100,Math.max(0,t))}%`}})})}function il(e){let{provider:t}=e,[s,l]=(0,r.useState)(!1);return s?(0,n.jsx)("span",{className:"text-text-subtle",children:a7[t]||t}):(0,n.jsx)("img",{src:e8(t),alt:"",width:14,height:14,onError:()=>l(!0),className:`w-3.5 h-3.5 object-contain ${e6}`})}function ia(e){let{label:t,window:s}=e;return s?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-16 truncate text-text-muted",children:t}),(0,n.jsxs)("span",{className:"w-9 text-right tabular-nums",children:[Math.round(s.usedPercent),"%"]}),(0,n.jsx)(ir,{usedPct:s.usedPercent}),s.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}`}(s.resetsAt)})]}):null}function ii(e){let{p:t,onClose:s}=e,l=(0,r.useRef)(null),{t:a}=(0,eu.s)();return(0,r.useEffect)(()=>{let e=e=>{l.current?.contains(e.target)||s()},t=e=>{"Escape"===e.key&&s()};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",t)}},[s]),(0,n.jsxs)("div",{ref:l,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:a7[t.provider]||t.provider}),is.map(e=>{let[s,r]=e;return(0,n.jsx)(ia,{label:r,window:t[s]},s)}),(t.buckets||[]).map(e=>(0,n.jsx)(ia,{label:e.name,window:e},e.name)),!t.session&&!t.weekly&&!t.monthly&&!(t.buckets||[]).length&&(0,n.jsx)("div",{className:"text-text-muted",children:t.error||a("terminal.quotaNoData")}),t.error&&(t.session||t.weekly||t.monthly)&&(0,n.jsx)("div",{className:"text-text-subtle border-t border-border-subtle pt-1.5",children:t.error})]})}function io(e){let{quota:t}=e,[s,l]=(0,r.useState)(null),{t:a}=(0,eu.s)();if(!t?.providers)return null;let i=Object.values(t.providers).filter(e=>e&&"ok"===e.status&&(e.session||e.weekly||e.monthly||e.buckets?.length));return i.length?(0,n.jsx)("span",{className:"relative flex items-center gap-1 flex-shrink-0",children:i.map(e=>{let t=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:()=>l(s===e.provider?null:e.provider),title:`${a7[e.provider]||e.provider} ${a("terminal.quotaUsageTitle")}`,children:[(0,n.jsx)(il,{provider:e.provider}),(0,n.jsx)(ir,{usedPct:t.usedPercent}),(0,n.jsxs)("span",{className:"tabular-nums",children:[Math.round(t.usedPercent),"%"]})]}),s===e.provider&&(0,n.jsx)(ii,{p:e,onClose:()=>l(null)})]},e.provider)})}):null}function ic(e){let{left:t,right:s,className:r="flex"}=e;return(0,n.jsxs)("div",{style:{height:26},className:`statusbar-glass items-center gap-3 px-3 flex-shrink-0 border-t border-border-subtle text-[11px] text-text-muted select-none ${r}`,children:[(0,n.jsx)("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:t}),(0,n.jsx)("div",{className:"flex items-center gap-3 flex-shrink-0",children:s})]})}let id="flex items-center gap-1.5 px-1.5 py-0.5 rounded-[2px] hover:bg-white/10 transition-colors cursor-pointer",iu="flex items-center gap-1.5 px-1.5 py-0.5",im={darwin:"mac",win32:"win",linux:"linux"};function ix(e){let{pages:t,activeKey:s}=e;return(0,n.jsx)("span",{className:"grid justify-items-end",children:t.map(e=>{let{key:t,node:r}=e;return(0,n.jsx)("span",{"aria-hidden":t!==s,className:"[grid-area:1/1] flex items-center min-w-0 motion-reduce:transition-none",style:{opacity:+(t===s),transform:t===s?"translateY(0)":"translateY(2px)",pointerEvents:t===s?"auto":"none",transition:`opacity ${eg.ZU}ms ease, transform ${eg.ZU}ms ease`},children:r},t)})})}let ip=(0,r.memo)(function(e){let t,s,l,{sessionId:a,fileBus:i,busRef:o,onReveal:c}=e,d=(0,f.B)(e=>e.cwdBySession[a])||"",{branch:u,changedCount:m}=r9(d,i,{enabled:!!d}),x=(s=it(o,{enabled:!!(t=(0,f.B)(e=>e.agentBySession[a])||"")}),(l=t?s?.providers?.[t]:null)&&"ok"===l.status&&l.session?{agentId:t,usedPct:l.session.usedPercent}:null),[p,h]=(0,r.useState)(!1),b=d?d.replace(/\\+|\/+$/g,"").split(/[\\/]/).filter(Boolean):[],g=b.length?b.slice(-2).join("/"):"";(0,r.useEffect)(()=>{if(!p)return;let e=setTimeout(()=>h(!1),eg.wu);return()=>clearTimeout(e)},[p]);let v=[];g&&v.push({key:"path",node:(0,n.jsxs)("button",{type:"button",onClick:c?()=>c(a,d):void 0,title:d,className:`flex items-center gap-1 min-w-0 font-mono ${c?"hover:text-text":""}`,children:[(0,n.jsx)(el.vd,{size:10,className:"opacity-70 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:g})]})}),x&&v.push({key:"quota",node:(0,n.jsxs)("button",{type:"button",onClick:()=>h(!0),className:"flex items-center gap-1.5 flex-shrink-0",children:[(0,n.jsx)("img",{src:e8(x.agentId),alt:"",width:11,height:11,draggable:!1,className:`w-[11px] h-[11px] object-contain ${e6}`}),(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 ${ie(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 y=x&&x.usedPct>=eg.W$?v.findIndex(e=>"quota"===e.key):-1,[w]=function(e){let{pinnedIndex:t=-1,paused:s=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[n,l]=(0,r.useState)(0);return((0,r.useEffect)(()=>{if(!(e<2)&&!s&&!(t>=0))return nb(()=>l(e=>e+1),eg.wu,{fireOnReturn:!1})},[e,s,t]),e)?[t>=0?t:n%e,l]:[0,l]}(v.length,{pinnedIndex:y,paused:p});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:[u&&(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:u,children:u}),m>0&&(0,n.jsx)("span",{className:"px-1 leading-tight bg-brand-500/15 text-brand-400 rounded-[2px] font-medium",children:m>eg.KN?`${eg.KN}+`:m})]}),v.length>0&&(0,n.jsx)(ix,{pages:v,activeKey:v[w]?.key})]})}),ih=(0,r.memo)(function(e){let{cwd:t,sessionId:s,hostKey:r=null,sessionState:l,sessionName:a="",hostVersion:i="",agentVersion:o="",platform:c="",homeDir:d=null}=e,{t:m}=(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}}(r),p=eM(r).busRef,h=eM(r).fileBus,b=(0,u.d)(e=>r?null:e.connectionMode),g=(0,u.d)(e=>r?"":e.endpoint),v=ez(s),y=x.connected,w=x.carrier,j=l||v||"idle",k=it(p),N=(0,f.B)(e=>(e.agentBySession||{})[s])||"",C=a||"—",S=N?e8(N):null,{branch:T,changedCount:E}=r9(t,h,{enabled:!!t}),R=s7(j),M=m("working"===j?"common.statusWorking":"blocked"===j?"common.statusBlocked":"done"===j?"common.statusDone":"sleep"===j?"common.statusSleep":"common.statusIdle"),$=t?nu(t.replace(/\\/g,"/"),d):"",z=E>eg.KN?`${eg.KN}+`:E;return(0,n.jsx)(ic,{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:[S?(0,n.jsx)("img",{src:S,alt:"",draggable:!1,className:`w-3.5 h-3.5 object-contain flex-shrink-0 ${e6}`}):(0,n.jsx)(nh,{size:14}),(0,n.jsx)("span",{className:"truncate font-medium text-text",title:C,children:C})]}),(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:t||"",children:$||m("common.loading")})]}),t&&T&&(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:T,children:T}),E>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)(io,{quota:k}),(x.platform||c)&&(0,n.jsx)("span",{className:"uppercase tracking-wide",children:im[x.platform||c]||x.platform||c}),(x.version||i||o)&&(0,n.jsxs)("span",{className:"text-text-subtle",children:["v",x.version||i||o]}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5",title:`${g||""}${w&&"ws"!==w?` (${w})`:""}`,children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full ${y?"local"===b?"bg-emerald-400":"bg-green-500":"bg-red-500 animate-pulse"}`}),(0,n.jsx)("span",{className:"uppercase tracking-wide",children:w&&"ws"!==w?"STUN":`WS${"local"===b?" \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:M})]})]})})}),ib=(e,t,s)=>Math.max(t,Math.min(s,e));function ig(e){let t=window.innerWidth-4*eg.qj.margin,s=window.innerHeight-3*eg.qj.margin;return{...e,x:ib(e.x,eg.qj.margin-e.w+4*eg.qj.margin,t),y:ib(e.y,eg.qj.margin,s)}}function iv(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 iy="VideoDecoder"in window&&"EncodedVideoChunk"in window,iw=/^(\d\d-\d\d \d\d:\d\d:\d\d\.\d+)\s+\d+\s+\d+\s+([VDIWEF])\s+([^:]*):\s?(.*)$/;function ij(e){let{state:t}=e;return(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${"running"===t?"bg-green-500 animate-pulse":"starting"===t||"stopping"===t?"bg-amber-400 animate-pulse":"bg-text-muted/40"}`})}function ik(e){let{devices:t,canManage:s,booting:l,stopping:a,loading:i,error:o,onOpen:c,onStop:d,onRefresh:u,lowPower:m,onLowPowerChange:x,onAddDevice:p,onDeleteAvd:h,onWipeAvd:f,sdkJob:b,onShowSetup:g}=e,{t:v}=(0,eu.s)(),[y,w]=(0,r.useState)(null),[j,k]=(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:v("mobile.pickDevice")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),p?.()},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:v("mobile.addDevice"),"aria-label":v("mobile.addDevice"),children:(0,n.jsx)(el.FW,{size:15})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u?.()},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:v("mobile.refreshDevices"),"aria-label":v("mobile.refreshDevices"),children:(0,n.jsx)(el.e9,{size:15})})]}),b&&"done"!==b.phase&&"error"!==b.phase&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),g?.()},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:v(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}`}(b))}),(0,n.jsx)("span",{className:"text-[10px] text-text-muted",children:"image"===b.kind||"image"===b.step?`${b.percent??0}%`:`${Math.round((b.received||0)/1024/1024)} MB${b.bytesPerSec?` \xb7 ${Math.round(b.bytesPerSec/1024/1024)} MB/s`:""}`})]})]}),0===t.length&&(0,n.jsx)("div",{className:"text-center py-8 space-y-2 fade-in",children:i?(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:v("mobile.noDevicesHint")})]})}),(0,n.jsx)("div",{className:"space-y-1.5",children:t.map((e,t)=>{let r=l?.avdName&&l.avdName===e.avdName,i=a?.has(e.serial),o="running"===e.state;return(0,n.jsxs)("div",{className:"bg-surface rounded-brand-lg overflow-hidden list-rise",style:{"--i":Math.min(t,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)(),c?.(e)},disabled:r||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:r?v(`mobile.phase${l.phase.charAt(0).toUpperCase()}${l.phase.slice(1)}`):i?v("mobile.stoppingDevice"):e.serial||v("mobile.stopped")})]}),(0,n.jsx)(ij,{state:r||i?"starting":e.state})]}),r?(0,n.jsx)(el.kr,{size:15,className:"text-brand-500 animate-spin flex-shrink-0"}):o&&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)(),d?.(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:v("mobile.stopDevice"),"aria-label":v("mobile.stopDevice"),children:(0,n.jsx)(el.M6,{size:14})}):o?null:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),c?.(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:v("mobile.startDevice"),"aria-label":v("mobile.startDevice"),children:(0,n.jsx)(el.jG,{size:14})}),s&&"emulator"===e.kind&&e.avdName&&!o&&!r&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),(0,ed.e)(),w(y===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":v("mobile.avdMenu"),children:(0,n.jsx)(el.Gv,{size:14})})]}),y===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)(),k({kind:"wipe",avdName:e.avdName,name:e.name}),w(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})," ",v("mobile.avdWipe")]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),k({kind:"delete",avdName:e.avdName,name:e.name}),w(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})," ",v("mobile.avdDelete")]})]})]},e.id)})}),s&&t.some(e=>"running"!==e.state)&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),x?.(!m)},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:m?"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:v("mobile.lowPower")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:v("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 ${m?"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 ${m?"translate-x-4 dark:bg-dark-800":"translate-x-0.5 dark:bg-white/50"}`})})]}),o&&(0,n.jsx)("p",{className:"text-red-400 text-xs text-center",children:o}),(0,n.jsx)(ec.A,{isOpen:!!j,onClose:()=>k(null),onConfirm:()=>{j&&("delete"===j.kind?h?.(j.avdName):f?.(j.avdName),k(null))},title:v(j?.kind==="delete"?"mobile.avdDeleteTitle":"mobile.avdWipeTitle"),message:v(j?.kind==="delete"?"mobile.avdDeleteMessage":"mobile.avdWipeMessage",{name:j?.name||""}),confirmText:v(j?.kind==="delete"?"common.delete":"mobile.avdWipe")})]})}function iN(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 iC(e){let{isOpen:t,onClose:s,presets:l,sdkJob:a,onProvision:i,onCancel:o}=e,{t:c}=(0,eu.s)(),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(null),p=a&&"done"!==a.phase&&"error"!==a.phase?a:null,h=a?.phase==="error"&&"cancelled"!==a.error?a.error:null,f=(0,r.useCallback)(()=>{u(null),x(null),s?.()},[s]);if((0,r.useEffect)(()=>{if(!t||p)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),f())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t,p,f]),!t||"u"<typeof document)return null;let b=async e=>{if(d||p)return;(0,ed.e)(),u(e.id),x(e);let t=await i?.(e.id);u(null),t&&f()};return(0,se.createPortal)((0,n.jsx)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 scrim fade-in",onClick:f,children:(0,n.jsxs)("div",{className:"card-elev w-full max-w-sm max-h-[80vh] flex flex-col pop-in",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:c("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:p||h?(0,n.jsx)("div",{className:"flex flex-col items-center gap-3 py-8 px-4 text-center",children:h?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-red-400 text-xs",children:h}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[m&&(0,n.jsx)("button",{onClick:()=>b(m),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:c("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:c("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:c(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}`}(p))}),(0,n.jsx)("p",{className:"text-text-muted text-xs",children:"image"===p.kind||"image"===p.step?`${p.percent??0}%`:`${iN(p.received)}${p.total?` / ${iN(p.total)}`:""}${p.bytesPerSec?` \xb7 ${iN(p.bytesPerSec)}/s`:""}`}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),o?.()},className:"px-3 py-1 text-[11px] text-text-muted hover:text-red-400 rounded-brand transition-colors",children:c("common.cancel")})]})}):(l||[]).map(e=>(0,n.jsxs)("button",{onClick:()=>b(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?c("mobile.presetReady"):c("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 iS(e){let{apps:t,foreground:s,busy:l,progress:a,error:i,onInstall:o,onLaunch:c,onStopApp:d,onClearData:u,onUninstall:m,onOpenLink:x,onRefresh:p}=e,{t:h}=(0,eu.s)(),f=(0,r.useRef)(null),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(""),w=(0,r.useCallback)(e=>{let t=[...e||[]].find(e=>e.name.toLowerCase().endsWith(".apk"));t&&o?.(t)},[o]),j=(0,r.useCallback)(e=>{e.preventDefault(),g(!1),w(e.dataTransfer?.files)},[w]),k="install"===l;return(0,n.jsxs)("div",{className:"h-full overflow-y-auto modal-scrollable p-3 space-y-3",onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:j,children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f.current?.click()},disabled:k,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 ${b?"border-brand-500 bg-brand-500/5":"border-border hover:border-brand-500/50"} disabled:opacity-60`,children:k?(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:h("mobile.installing")}),a>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*a)}%`}})})]}):(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:h("mobile.dropApk")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:h("mobile.dropApkHint")})]})}),(0,n.jsx)("input",{ref:f,type:"file",accept:".apk,application/vnd.android.package-archive",className:"hidden",onChange:e=>{w(e.target.files),e.target.value=""}}),(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault(),v.trim()&&(x?.(v.trim()),y(""))},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:v,onChange:e=>y(e.target.value),placeholder:h("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:!v.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:h("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:h("mobile.installedApps")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),p?.()},className:"p-1 text-text-muted hover:text-text rounded-brand transition-colors",title:h("common.refresh"),"aria-label":h("common.refresh"),children:(0,n.jsx)(el.e9,{size:13})})]}),0===t.length&&(0,n.jsx)("p",{className:"text-text-muted text-xs text-center py-4",children:h("mobile.noApps")}),(0,n.jsx)("div",{className:"space-y-1",children:t.map(e=>{let t=s?.packageName===e.packageName,r=l===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:t?"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}),r?(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)(),c?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-brand-500 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.launch"),"aria-label":h("mobile.launch"),children:(0,n.jsx)(el.jG,{size:13})}),t&&(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:h("mobile.forceStop"),"aria-label":h("mobile.forceStop"),children:(0,n.jsx)(el.M6,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-amber-400 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.clearData"),"aria-label":h("mobile.clearData"),children:(0,n.jsx)(el.e9,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m?.(e.packageName)},className:"p-1.5 text-text-muted hover:text-red-400 hover:bg-surface-2 rounded-brand transition-colors",title:h("mobile.uninstall"),"aria-label":h("mobile.uninstall"),children:(0,n.jsx)(el.TB,{size:13})})]})]},e.packageName)})}),i&&(0,n.jsx)("p",{className:"text-red-400 text-xs",children:i})]})}function iT(e){let{logcat:t,apps:s}=e,{lines:l,clear:a,minLevel:i,setMinLevel:o,search:c,setSearch:d,packageName:u,setPackageName:m,paused:x,setPaused:p,includeNoise:h,setIncludeNoise:f}=t,{t:b}=(0,eu.s)(),g=(0,r.useRef)(null),[v,y]=(0,r.useState)(!0),w=()=>{y(!0)};return(0,r.useLayoutEffect)(()=>{v&&g.current&&(g.current.scrollTop=g.current.scrollHeight)},[l,v]),(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:u||"",onChange:e=>{(0,ed.e)(),m(e.target.value||null),w()},className:"bg-surface-2 text-text text-xs rounded-brand px-1.5 py-1 focus:outline-none max-w-[40%]",title:b("mobile.filterByApp"),children:[(0,n.jsx)("option",{value:"",children:b("mobile.allApps")}),s.map(e=>(0,n.jsx)("option",{value:e.packageName,children:e.packageName},e.packageName))]}),(0,n.jsx)("select",{value:i,onChange:e=>{(0,ed.e)(),o(e.target.value),w()},className:"bg-surface-2 text-text text-xs rounded-brand px-1.5 py-1 focus:outline-none",title:b("mobile.minLevel"),children:q.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:c,onChange:e=>d(e.target.value),placeholder:b("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)(),p(!x)},className:`p-1.5 rounded-brand transition-colors ${x?"text-brand-500 bg-surface-2":"text-text-muted hover:text-text"}`,title:b(x?"mobile.resumeLog":"mobile.pauseLog"),"aria-label":b(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(!h),w()},className:`p-1.5 rounded-brand transition-colors ${h?"text-amber-400 bg-surface-2":"text-text-muted hover:text-text"}`,title:b(h?"mobile.hideNoise":"mobile.showNoise"),"aria-label":b(h?"mobile.hideNoise":"mobile.showNoise"),children:(0,n.jsx)(el.dJ,{size:13})}),(0,n.jsx)("button",{onClick:()=>{let e;(0,ed.e)(),e=l.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:b("common.clipboardCopy"),"aria-label":b("common.clipboardCopy"),children:(0,n.jsx)(el.QR,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),a()},className:"p-1.5 text-text-muted hover:text-red-400 rounded-brand transition-colors",title:b("mobile.clearLog"),"aria-label":b("mobile.clearLog"),children:(0,n.jsx)(el.TB,{size:13})})]}),(0,n.jsxs)("div",{ref:g,onScroll:()=>{let e=g.current;e&&y(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===l.length&&(0,n.jsx)("p",{className:"text-text-muted text-xs text-center py-6 font-sans",children:b("mobile.noLogs")}),l.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:U[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:U[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:b("mobile.logPaused")})]})}function iE(e){let{onClose:t,busRef:s,protocolRef:l,connected:a,variant:i="fullscreen"}=e,{t:o}=(0,eu.s)(),c=(0,r.useRef)(null),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),b=function(e){let{busRef:t,connected:s}=e,[n,l]=(0,r.useState)([]),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(()=>new Set),[m,x]=(0,r.useState)(null),[p,h]=(0,r.useState)(!1),[b,g]=(0,r.useState)(null),v=(0,f.B)(e=>e.mobileLowPower),y=(0,f.B)(e=>e.setMobileLowPower),w=(0,r.useCallback)(async()=>{let e=t?.current;if(!e||!s)return[];let n=await X(e,"mobile:list",{});if(!n?.success)return[];h(!0),i(!!n.canManageEmulators),n.env&&g(n.env.job||null);let r=Array.isArray(n.devices)?n.devices:[];return l(r),u(e=>{let t=new Set(r.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}),r},[t,s]);(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s)return;let n=e=>{let{avdName:t,phase:s}=e;return c({avdName:t,phase:s})};e.on("mobile:avdProgress",n);let r=e=>{g(e),("done"===e.phase||"error"===e.phase)&&w()};return e.on("mobile:sdkProgress",r),()=>{e.off("mobile:avdProgress",n),e.off("mobile:sdkProgress",r)}},[t,s,w]),(0,r.useEffect)(()=>{if(!s)return;w();let e=setInterval(w,5e3);return()=>clearInterval(e)},[s,w]);let j=(0,r.useCallback)(async e=>{x(null),c({avdName:e,phase:"launching"});let s=await X(t?.current,"mobile:avdStart",{avdName:e,lowPower:v});return(c(null),await w(),s?.success)?s.serial:(x(s?.error||"Could not start"),null)},[t,w,v]),k=(0,r.useCallback)(async e=>{if(!e)return!1;x(null),u(t=>new Set(t).add(e));let s=await X(t?.current,"mobile:avdStop",{serial:e});return await w(),u(t=>{let s=new Set(t);return s.delete(e),s}),s?.success||x(s?.error||"Could not stop"),s?.success},[t,w]),[N,C]=(0,r.useState)([]),S=(0,r.useCallback)(async()=>{let e=await X(t?.current,"mobile:provisionPresets",{});e?.success&&C(Array.isArray(e.presets)?e.presets:[])},[t]),T=(0,r.useCallback)(async e=>{x(null);let s=await X(t?.current,"mobile:provision",{presetId:e});return await Promise.all([w(),S()]),!!s?.success||(x(s?.error||"Could not create device"),!1)},[t,w,S]),E=(0,r.useCallback)(async()=>{await X(t?.current,"mobile:sdkCancel",{}),await w()},[t,w]),R=(0,r.useCallback)(async e=>{let s=await X(t?.current,"mobile:avdDelete",{avdName:e});return s?.success||x(s?.error||"Could not delete"),await w(),s?.success},[t,w]),M=(0,r.useCallback)(async e=>{let s=await X(t?.current,"mobile:avdWipe",{avdName:e});return s?.success||x(s?.error||"Could not wipe"),await w(),s?.success},[t,w]);return{devices:n,canManage:a,booting:o,error:m,setError:x,refresh:w,startAvd:j,stopAvd:k,stopping:d,lowPower:v,setLowPower:y,sdkJob:b,presets:N,refreshPresets:S,provision:T,cancelSetup:E,deleteAvd:R,wipeAvd:M,loaded:p}}({busRef:s,connected:a}),{devices:g,canManage:v,booting:y,refresh:w,startAvd:j,stopAvd:k,stopping:N,lowPower:C,setLowPower:S,sdkJob:T,presets:E,refreshPresets:R,provision:M,cancelSetup:$,deleteAvd:z,wipeAvd:P}=b,{serial:A,meta:I,starting:D,error:L,open:B,stop:F,cancel:O}=function(e){let{busRef:t,connected:s,devices:n,startAvd:l,stopAvd:a,stopping:i}=e,o=(0,f.B)(e=>e.mobileSession),c=(0,f.B)(e=>e.setMobileSession),d=o?.serial??null,u=o?.meta??null,[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(null),b=(0,r.useRef)(!1),g=(0,r.useRef)(!1),v=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{u&&(b.current=!0)},[u]);let y=(0,r.useCallback)(()=>{t?.current?.emit("mobile:stop"),b.current=!1,c(null)},[t,c]),w=(0,r.useCallback)(()=>{g.current=!0,y()},[y]),j=(0,r.useCallback)(async e=>{let s=Math.max(window.innerWidth,window.innerHeight),n=window.devicePixelRatio,r=await X(t?.current,"mobile:start",{serial:e,options:function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=W[e]||W[H],r=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,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 b.current=!0,c({serial:e,meta:r.meta}),r.meta},[t,c]),k=(0,r.useCallback)(async e=>{if(e){g.current=!1,x(!0),h(null),v.current.add(e.id);try{let t=e.serial||(e.avdName?await l(e.avdName):null);if(g.current){t&&a?.(t);return}if(!t)throw Error("Device did not start");await j(t),g.current&&(y(),t&&a?.(t))}catch(e){g.current||h(e.message)}finally{x(!1)}}},[l,j,a,y]);return(0,r.useEffect)(()=>{if(u||m||d)return;let e=n.filter(e=>"running"===e.state);if(1!==e.length||1!==n.length)return;let t=e[0];if(v.current.has(t.id)||i?.has(t.serial))return;let s=setTimeout(()=>k(t),0);return()=>clearTimeout(s)},[n,u,m,d,k,i]),(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s)return;let n=e=>{let{meta:t}=e;t&&c(e=>e?{...e,meta:t}:e)};return e.on("mobile:resized",n),()=>e.off("mobile:resized",n)},[t,s,c]),(0,r.useEffect)(()=>{!s&&b.current&&(b.current=!1,c(null))},[s,c]),{serial:d,meta:u,starting:m,error:p,setError:h,open:k,stop:y,cancel:w}}({busRef:s,connected:a,devices:g,startAvd:j,stopAvd:k,stopping:N}),{status:_,fps:K}=function(e){let{busRef:t,connected:s,canvasRef:n,meta:l}=e,[a,i]=(0,r.useState)("idle"),[o,c]=(0,r.useState)(0),d=(0,r.useRef)(null),u=(0,r.useCallback)(()=>{let e=d.current,s=performance.now();e&&s-e.lastKeyframeReq<1e3||(e&&(e.lastKeyframeReq=s),t?.current?.emit("mobile:keyframe"))},[t]);return(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!l||!iy)return;let r={decoder:null,pending:new Map,queue:[],raf:0,sawKey:!1,dropping:!1,lastKeyframeReq:0,ackedSeq:-1,config:null,frameCount:0,fpsAt:performance.now()};d.current=r,i("connecting");let a=()=>{if(r.decoder&&"closed"!==r.decoder.state)try{r.decoder.close()}catch{}for(let e of(r.decoder=null,r.sawKey=!1,r.queue))e.close();r.queue=[]},o=()=>{r.raf=0;let e=n.current;for(;r.queue.length>1;)r.queue.shift()?.close();let t=r.queue.shift();if(!t)return;let s=e?.getContext("2d",{alpha:!1,desynchronized:!0});s&&s.drawImage(t,0,0,e.width,e.height),t.close(),r.frameCount++;let l=performance.now();l-r.fpsAt>=1e3&&(c(Math.round(1e3*r.frameCount/(l-r.fpsAt))),r.frameCount=0,r.fpsAt=l),r.queue.length&&(r.raf=requestAnimationFrame(o))},m=()=>{a(),r.dropping=!0,u()},x=e=>{if(r.decoder?.state==="configured")return!0;a();let t=new VideoDecoder({output:e=>{r.decoder!==t?e.close():(r.queue.length>=3&&r.queue.shift()?.close(),r.queue.push(e),r.raf||(r.raf=requestAnimationFrame(o)))},error:()=>{r.decoder===t&&m()}});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}),r.decoder=t,!0}catch{try{t.close()}catch{}return i("decoder failed"),u(),!1}},p=e=>{let{data:t,isKey:s,isConfig:n,ptsMs:l}=e,a=t;if(n){r.config=a;let e=iv(a).spsBytes;e&&x(e);return}if(s&&r.decoder?.state!=="configured"){if(!r.config)return void u();let e=iv(r.config).spsBytes;if(!e||!x(e))return}if(s&&r.config){let e=new Uint8Array(r.config.byteLength+a.byteLength);e.set(r.config,0),e.set(a,r.config.byteLength),a=e}if(r.dropping){if(!s||r.decoder?.state!=="configured")return void u();r.dropping=!1}if(r.decoder?.state!=="configured"){s||u();return}if(r.decoder.decodeQueueSize>30)return void(r.dropping=!0,u());if(!r.sawKey){if(!s)return void u();r.sawKey=!0,i("streaming")}try{r.decoder.decode(new EncodedVideoChunk({type:s?"key":"delta",timestamp:1e3*l,data:a}))}catch{m()}},h=t=>{t<=r.ackedSeq||(r.ackedSeq=t,e.emit("mobile:ack",{seq:t}))},f=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){h(t.frameSeq),p({data:t.payload,isKey:t.isKey,isConfig:t.isConfig,ptsMs:t.ptsMs});return}let s=r.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},r.pending.set(t.frameSeq,s),r.pending.keys()))t.frameSeq-e>96&&r.pending.delete(e);if(s.chunks[t.chunkIdx]||(s.chunks[t.chunkIdx]=t.payload,s.received++,s.received!==s.count))return;r.pending.delete(t.frameSeq),h(t.frameSeq);let n=new Uint8Array(s.chunks.reduce((e,t)=>e+t.byteLength,0)),l=0;for(let e of s.chunks)n.set(e,l),l+=e.byteLength;p({data:n,isKey:s.isKey,isConfig:s.isConfig,ptsMs:s.ptsMs})},b=()=>i("ended");return e.on("mobile-bin",f),e.on("file-bin",f),e.on("mobile:ended",b),u(),()=>{e.off("mobile-bin",f),e.off("file-bin",f),e.off("mobile:ended",b),r.raf&&cancelAnimationFrame(r.raf),a(),r.pending.clear(),d.current=null}},[t,s,n,l,u]),(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!l)return;let n=()=>{let t=!document.hidden;e.emit("mobile:visible",{visible:t}),t&&u()};return document.addEventListener("visibilitychange",n),e.emit("mobile:visible",{visible:!document.hidden}),()=>document.removeEventListener("visibilitychange",n)},[t,s,l,u]),{status:iy?a:"unsupported",fps:o,requestKeyframe:u}}({busRef:s,connected:a,canvasRef:c,meta:I}),q=function(e){let{busRef:t,canvasRef:s}=e,n=(0,r.useRef)(null),l=(0,r.useRef)(null),a=(0,r.useRef)(0),i=(0,r.useCallback)(e=>{t?.current?.emit("mobile:input",e)},[t]),o=(0,r.useCallback)(()=>{a.current=0;let e=l.current;e&&(l.current=null,i({type:"touch",action:"move",...e}))},[i]),c=(0,r.useCallback)(e=>{let t=s.current;if(!t)return null;let n=t.getBoundingClientRect(),r=Math.min(n.width/t.width,n.height/t.height),l=t.width*r,a=t.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}},[s]),d=(0,r.useCallback)(e=>{let t=c(e);t&&(e.currentTarget.setPointerCapture?.(e.pointerId),n.current=t,i({type:"touch",action:"down",...t}))},[i,c]),u=(0,r.useCallback)(e=>{if(!n.current)return;let t=c(e);t&&(l.current=t,a.current||(a.current=requestAnimationFrame(o)))},[o,c]),m=(0,r.useCallback)(e=>{let t=c(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));i({type:"scroll",...t,hscroll:n(e.deltaX),vscroll:n(e.deltaY)})},[i,c]),x=(0,r.useCallback)(e=>{let t=n.current;t&&(n.current=null,l.current=null,a.current&&(cancelAnimationFrame(a.current),a.current=0),i({type:"touch",action:"up",...c(e)||{x:t.x,y:t.y}}))},[i,c]);return{onPointerDown:d,onPointerMove:u,onPointerUp:x,onPointerCancel:x,onWheel:m,sendKey:(0,r.useCallback)(e=>i({type:"key",name:e}),[i])}}({busRef:s,canvasRef:c}),U=function(e){let{busRef:t,protocolRef:s,serial:n,enabled:l}=e,[a,i]=(0,r.useState)([]),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(0),[p,h]=(0,r.useState)(null),f=(0,r.useCallback)(async()=>{if(!n||!l)return;let e=await X(t?.current,"mobile:apps",{serial:n});e?.success&&(i(e.apps||[]),c(e.foreground||null))},[t,n,l]);(0,r.useEffect)(()=>{f()},[f]);let b=(0,r.useCallback)(async(e,s,r)=>{u(s),h(null);let l=await X(t?.current,e,{serial:n,packageName:s});return(u(null),l?.success)?(r&&await f(),!0):(h(l?.error||"Failed"),!1)},[t,n,f]),g=(0,r.useCallback)(e=>b("mobile:launch",e),[b]),v=(0,r.useCallback)(e=>b("mobile:stopApp",e),[b]),y=(0,r.useCallback)(e=>b("mobile:clearApp",e),[b]),w=(0,r.useCallback)(e=>b("mobile:uninstall",e,!0),[b]),j=(0,r.useCallback)(async e=>{if(e&&n){u("install"),h(null),x(0);try{let r=await X(t?.current,"mobile:apkStage",{name:e.name,size:e.size});if(!r?.success)throw Error(r?.error||"Cannot stage APK");let l=null;if(await J({bus:t?.current,protocolRef:s,targetDir:r.targetDir,items:[{file:e,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(t?.current,"mobile:install",{serial:n,fileName:r.fileName,launch:!0});if(!a?.success)throw Error(a?.error||"Install failed");return await f(),a.packageName}catch(e){return h(e.message),null}finally{u(null),x(0)}}},[t,s,n,f]),k=(0,r.useCallback)(async e=>{h(null);let s=await X(t?.current,"mobile:openLink",{serial:n,url:e});return s?.success||h(s?.error||"Could not open link"),s?.success},[t,n]);return{apps:a,foreground:o,busy:d,progress:m,error:p,setError:h,refresh:f,install:j,launch:g,stopApp:v,clearData:y,uninstall:w,openLink:k}}({busRef:s,protocolRef:l,serial:A,enabled:!!I}),V=function(e){let{busRef:t,serial:s,active:n,foregroundPackage:l}=e,[a,i]=(0,r.useState)([]),[o,c]=(0,r.useState)("I"),[d,u]=(0,r.useState)(""),[m,x]=(0,r.useState)(null),p=(0,r.useRef)(!1);(0,r.useEffect)(()=>{!p.current&&l&&x(l)},[l]);let h=(0,r.useCallback)(e=>{p.current=!0,x(e)},[]),[f,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),y=(0,r.useRef)(0),w=(0,r.useRef)(!1);(0,r.useEffect)(()=>{w.current=f},[f]);let j=(0,r.useCallback)(()=>i([]),[]);return(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s||!n)return;i([]);let r=e=>{let{lines:t}=e;!w.current&&Array.isArray(t)&&i(e=>{let s=e.concat(t.map(e=>{var t;let s;return t=y.current++,(s=iw.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 e.on("mobile:logcat",r),X(e,"mobile:logcatStart",{serial:s,minLevel:o,search:d,includeNoise:g,...p.current||m?{packageName:m}:{}}),()=>{e.off("mobile:logcat",r),e.emit("mobile:logcatStop")}},[t,s,n]),(0,r.useEffect)(()=>{if(!n||!s)return;let e=setTimeout(()=>{t?.current?.emit("mobile:logcatFilter",{minLevel:o,search:d,packageName:m,includeNoise:g})},200);return()=>clearTimeout(e)},[o,d,m,g,n,s,t]),{lines:a,clear:j,minLevel:o,setMinLevel:c,search:d,setSearch:u,packageName:m,setPackageName:h,paused:f,setPaused:b,includeNoise:g,setIncludeNoise:v}}({busRef:s,serial:A,active:!!I&&"logs"===d,foregroundPackage:U.foreground?.packageName});(0,r.useEffect)(()=>{let e=c.current;e&&I&&(e.width=I.width,e.height=I.height)},[I]);let G="panel"===i,Y=g.find(e=>e.serial===A)||null,Z=(0,r.useCallback)(async()=>{x(!1),F(),A&&await k(A)},[A,F,k]),Q=(0,r.useCallback)(async e=>{e.serial===A&&F(),await k(e.serial)},[A,F,k]),ee=(0,r.useCallback)(()=>{G||F(),t?.()},[G,F,t]),et=(0,r.useCallback)(()=>{let e=g.find(e=>e.serial===A);e&&B(e)},[g,A,B]);if(!I){let e;return(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col bg-bg",children:[!G&&(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)(),ee()},className:"p-1.5 text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94]","aria-label":o("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:o("mobile.title")})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto modal-scrollable flex items-center justify-center",children:D||y?(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:y?(e=y.phase,o(`mobile.phase${e.charAt(0).toUpperCase()}${e.slice(1)}`)):o("mobile.starting")}),y&&(0,n.jsx)("p",{className:"text-text-muted text-xs",children:y.avdName}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),O()},className:"px-3 py-1.5 text-xs text-text-muted bg-surface hover:bg-surface-2 rounded-brand transition-colors",children:o("common.cancel")})]}):iy?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ik,{devices:g,canManage:v,booting:y,stopping:N,loading:!b.loaded,error:L||b.error,onOpen:B,onStop:Q,onRefresh:w,lowPower:C,onLowPowerChange:S,onAddDevice:()=>{R(),h(!0)},onDeleteAvd:z,onWipeAvd:P,sdkJob:T,onShowSetup:()=>h(!0)}),(0,n.jsx)(iC,{isOpen:p,onClose:()=>h(!1),presets:E,sdkJob:T,onProvision:M,onCancel:$})]}):(0,n.jsx)("p",{className:"text-text-muted text-sm max-w-xs text-center p-6",children:o("mobile.unsupportedBrowser")})})]})}return(0,n.jsxs)("div",{className:"absolute inset-0 flex bg-bg",children:[(0,n.jsx)(ec.A,{isOpen:m,onClose:()=>x(!1),onConfirm:Z,title:o("mobile.shutdownTitle"),message:o("mobile.shutdownMessage",{name:I.deviceName}),confirmText:o("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:c,onPointerDown:q.onPointerDown,onPointerMove:q.onPointerMove,onPointerUp:q.onPointerUp,onPointerCancel:q.onPointerCancel,onWheel:q.onWheel,className:"max-w-full max-h-full object-contain touch-none"}),("connecting"===_||"idle"===_)&&(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"===_||"decoder failed"===_)&&(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:o("ended"===_?"mobile.streamEnded":"mobile.streamFailed")}),Y?(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),et()},className:"px-3 py-1.5 text-xs text-brand-500 bg-surface hover:bg-surface-2 rounded-brand transition-colors",children:o("mobile.retry")}):(0,n.jsx)("p",{className:"text-text-muted text-xs",children:o("mobile.streamGone")})]}),"streaming"===_&&K>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:[K," fps"]}),d&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u(null)},className:"absolute inset-x-0 top-0 h-16 z-10 cursor-pointer","aria-label":o("mobile.backToScreen")}),d&&(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"===d?(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:o("apps"===d?"mobile.tabApps":"mobile.tabLogs")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u(null)},className:"p-1 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",title:o("mobile.backToScreen"),"aria-label":o("mobile.backToScreen"),children:(0,n.jsx)(el.X,{size:14})})]}),"apps"===d?(0,n.jsx)(iS,{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)(iT,{logcat:V,apps:U.apps})]},d)]}),(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)(iR,{icon:(0,n.jsx)(el.lM,{size:15,className:"-rotate-90"}),label:o("mobile.back"),onClick:()=>q.sendKey("back")}),(0,n.jsx)(iR,{icon:(0,n.jsx)(el.jl,{size:15}),label:o("mobile.home"),onClick:()=>q.sendKey("home")}),(0,n.jsx)(iR,{icon:(0,n.jsx)(el.M6,{size:14}),label:o("mobile.recents"),onClick:()=>q.sendKey("recents")}),(0,n.jsx)("div",{className:"w-5 h-px bg-border my-1"}),(0,n.jsx)(iR,{icon:(0,n.jsx)(el.LM,{size:15}),label:o("mobile.power"),onClick:()=>q.sendKey("power")}),(0,n.jsx)("div",{className:"w-5 h-px bg-border my-1"}),(0,n.jsx)(iR,{icon:(0,n.jsx)(el.lP,{size:15}),label:o("mobile.tabApps"),onClick:()=>u("apps"===d?null:"apps"),active:"apps"===d}),(0,n.jsx)(iR,{icon:(0,n.jsx)(el.iU,{size:15}),label:o("mobile.tabLogs"),onClick:()=>u("logs"===d?null:"logs"),active:"logs"===d}),(0,n.jsx)("div",{className:"flex-1 min-h-2"}),(0,n.jsx)(iR,{icon:(0,n.jsx)(el.wO,{size:15}),label:o("mobile.switchDevice"),onClick:F}),Y?.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:o("mobile.shutdownDevice"),"aria-label":o("mobile.shutdownDevice"),children:(0,n.jsx)(el.$o,{size:15})}),!G&&(0,n.jsx)(iR,{icon:(0,n.jsx)(el.X,{size:15}),label:o("common.close"),onClick:ee})]})]})}function iR(e){let{icon:t,label:s,onClick:r,active:l=!1}=e;return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),r?.()},className:`p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.94] flex-shrink-0 ${l?"text-brand-500 bg-surface-2":"text-text hover:bg-surface-2"}`,title:s,"aria-label":s,"aria-pressed":l,children:t})}let iM=[{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 i$(e){let{busRef:t,protocolRef:s,connected:l,pinSlot:a=null}=e,{t:i}=(0,eu.s)(),o=(0,f.B)(e=>e.mobileMode),c=(0,f.B)(e=>e.mobileFloatRect),d=(0,f.B)(e=>e.setMobileOpen),u=(0,f.B)(e=>e.setMobileSession),m=(0,f.B)(e=>e.setMobileMode),x=function(e){let{rect:t,onChange:s,enabled:n}=e,[l,a]=(0,r.useState)(()=>{let e,s;return t?ig(t):(e=eg.qj.width.default,s=Math.min(eg.qj.height.default,window.innerHeight-2*eg.qj.defaultOffset),{x:Math.max(eg.qj.margin,window.innerWidth-e-eg.qj.defaultOffset),y:Math.max(eg.qj.margin,window.innerHeight-s-eg.qj.defaultOffset),w:e,h:s})}),[i,o]=(0,r.useState)(!1),c=(0,r.useRef)(null),d=(0,r.useRef)(l),u=(0,r.useCallback)(e=>{d.current=e,a(e)},[]);(0,r.useEffect)(()=>{if(!n)return;let e=()=>{let e=d.current;if(!e)return;let t=Math.min(e.h,window.innerHeight-2*eg.qj.margin);u(ig({...e,h:t}))};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[n,u]);let m=(0,r.useCallback)((e,t)=>{(null==e.button||0===e.button)&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),c.current={mode:t,pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,origin:l},o(!0))},[l]),x=(0,r.useCallback)(e=>{let t=c.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void p(e);let s=e.clientX-t.startX,n=e.clientY-t.startY;if("move"===t.mode)return void u(ig({...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"),o=a||l.includes("e"),d=i||l.includes("s"),m=window.innerHeight-2*eg.qj.margin,x=i?r.y+r.h-eg.qj.margin:m,h=a?r.x+r.w-eg.qj.margin:eg.qj.width.max,f=o?ib(a?r.w-s:r.w+s,eg.qj.width.min,Math.min(eg.qj.width.max,h)):r.w,b=d?ib(i?r.h-n:r.h+n,eg.qj.height.min,Math.min(m,x)):r.h;u({x:a?r.x+(r.w-f):r.x,y:i?r.y+(r.h-b):r.y,w:f,h:b})},[u]),p=(0,r.useCallback)(e=>{let t=c.current;t&&t.pointerId===e.pointerId&&(c.current=null,o(!1),d.current&&s?.(d.current))},[s]);return(0,r.useEffect)(()=>{if(!i)return;let e=()=>{c.current=null,o(!1),d.current&&s?.(d.current)};return window.addEventListener("blur",e),()=>window.removeEventListener("blur",e)},[i,s]),{rect:l,dragging:i,onDragHandlePointerDown:e=>m(e,"move"),onResizeHandlePointerDown:e=>t=>m(t,e),onPointerMove:x,onPointerUp:p,onPointerCancel:p}}({rect:c,onChange:(0,f.B)(e=>e.setMobileFloatRect),enabled:"float"===o}),p=(0,r.useCallback)(()=>{t?.current?.emit("mobile:stop"),u(null),d(!1)},[t,u,d]),h="pin"===o,b=e=>(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 bg-surface flex-shrink-0",children:[(0,n.jsxs)("div",{className:`flex items-center gap-1 flex-1 min-w-0 ${e?"cursor-grab active:cursor-grabbing":""}`,onPointerDown:e?x.onDragHandlePointerDown:void 0,children:[e&&(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:i("mobile.title")})]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m(h?"float":"pin")},className:`p-1.5 rounded-brand transition-colors ${h?"text-brand-500 bg-surface-2":"text-text-muted hover:text-text hover:bg-surface-2"}`,title:h?i("mobile.modeFloat"):i("mobile.modePin"),"aria-label":h?i("mobile.modeFloat"):i("mobile.modePin"),"aria-pressed":h,children:(0,n.jsx)(el.jz,{size:13})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),p()},className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors",title:i("common.close"),"aria-label":i("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)(iE,{busRef:t,protocolRef:s,connected:l,variant:"panel",onClose:p})})]});if(h)return a?(0,se.createPortal)(b(!1),a):null;let g=x.rect;return g?(0,se.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:g.x,top:g.y,width:g.w,height:g.h},onPointerMove:x.onPointerMove,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerCancel,children:[b(!0),iM.map(e=>{let{edge:t,className:s,cursor:r}=e;return(0,n.jsx)("div",{onPointerDown:x.onResizeHandlePointerDown(t),className:`absolute ${s} ${r}`,"aria-label":i("mobile.resize")},t)})]}),document.body):null}let iz=e=>e?.error==="Not connected";async function iP(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:()=>!0,s=await e(),n=eg.Tk.retryBaseMs;for(;iz(s)&&t()&&n<=eg.Tk.retryMaxMs&&(await new Promise(e=>setTimeout(e,n)),t());)n*=2,s=await e();return s}let iA=e=>(e||"").split("/").filter(Boolean).pop()||e;function iI(e,t){return e?e.endsWith("/")?`${e}${t}`:`${e}/${t}`:t}function iD(e){let t=e.lastIndexOf("/");return t<=0?"/":e.slice(0,t)}function iL(e){if(!e)return"";let t=e.split("/").filter(Boolean);return t[t.length-1]||e}function iB(e){let{dirs:t,fileBus:s,onDirsChanged:n,enabled:l=!0,debounceMs:a=_.Jl.DEBOUNCE_MS}=e,i=(0,r.useRef)(new Set),o=(0,r.useRef)(n);(0,r.useEffect)(()=>{o.current=n},[n]);let{watchDir:c,unwatchDir:d,onFileChange:u}=s||{},m=t.join("\n");(0,r.useEffect)(()=>{if(!l||!c||!d)return;let e=!0,t=i.current,s=new Set,n=null,r=new Set([...m?m.split("\n"):[]].sort((e,t)=>t.split("/").length-e.split("/").length).slice(0,_.Jl.MAX_DIRS)),x=()=>{if(n=null,!e||!s.size)return;let t=[...s];s.clear(),o.current?.(t)},p=async()=>{for(let e of t)r.has(e)||(t.delete(e),d(e));for(let s of r){if(t.has(s))continue;t.add(s);let n=await c(s);e&&n?.watching!==!1||t.delete(s)}},h=u?.(e=>{let{type:t,path:l}=e;if(!l)return;let i="flooded"===t?l:l.slice(0,l.lastIndexOf("/"))||"/";r.has(i)&&(s.add(i),n||(n=setTimeout(x,a)))})||(()=>{});return p(),()=>{for(let s of(e=!1,clearTimeout(n),h(),t))d(s);t.clear()}},[m,l,a,c,d,u])}function iF(){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 iO(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";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 i_(e,t){let s=await e.gitStatus(t);if(s?.success)return{hasGit:!0,map:iO(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=iO(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 iK(){try{let e=window.localStorage.getItem(_.d5.expandedFolders),t=e?JSON.parse(e):{};return Array.isArray(t)?{legacy:t}:t}catch{return{}}}function iW(){try{let e=window.localStorage.getItem(_.d5.showHidden);if(null===e)return!0;return!1!==JSON.parse(e)}catch{return!0}}let iH={created:"fileExplorer:fileCreated",deleted:"fileExplorer:fileDeleted",renamed:"fileExplorer:fileRenamed"};function iq(e){window.dispatchEvent(new CustomEvent(iH[e]))}let{xT:iU,Qm:iX,Pv:iV}=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"}}'),iG="/icons/file-types",iJ="/icons/folder-types",iY=`${iG}/default.svg`,iZ=`${iJ}/default.svg`,iQ=`${iJ}/default-open.svg`;function i0(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=iV[(e||"").toLowerCase()];return s?{src:t?`${iJ}/${s}-open.svg`:`${iJ}/${s}.svg`,alt:s}:{src:t?iQ:iZ,alt:"folder"}}function i1(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:16,{src:s,alt:r}=function(e){if(!e)return{src:iY,alt:"file"};if("folder"===e.type)return i0(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(iX[t]){let e=iX[t];return{src:`${iG}/${e}.svg`,alt:e}}if(iU[s]){let e=iU[s];return{src:`${iG}/${e}.svg`,alt:e}}return{src:iY,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 i2=e=>e?_.xW.compact:_.xW.normal,i5=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=i2(t);return s.indentBase+e*s.indentStep};function i3(e){let{status:t}=e;return t?"folder-changed"===t?(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 ${_.vs[t]||"text-text-muted"}`,children:t}):null}function i4(e){let{depth:t,compact:s=!1}=e;return(0,n.jsx)("div",{className:"text-[11px] text-text-muted italic py-0.5 pr-2",style:{paddingLeft:i5(t,s)},children:"Showing first 300 entries — use search for the rest."})}let i6=(0,r.memo)(function(e){let{file:t,depth:s,isFolder:r,isExpanded:l,isLoading:a,isActive:i,isSelected:o,isRenaming:c,isDragOver:d,isCut:u,gitStatus:m,renameValue:x,renameInputRef:p,onRenameChange:h,onRenameSubmit:f,onRenameCancel:b,onToggleFolder:g,onClick:v,onContextMenu:y,onTouchStart:w,onTouchEnd:j,onDragStart:k,onDragOver:N,onDragLeave:C,onDrop:S,compact:T=!1,children:E}=e,R=i2(T);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{"data-path":t.path,draggable:!c,onDragStart:e=>k(e,t),onDragOver:e=>N(e,t),onDragLeave:()=>C(t),onDrop:e=>S(e,t),className:`group relative flex items-center gap-1 rounded-[3px] mx-0.5 pr-2 cursor-pointer select-none ${R.text} ${R.padY} ${u?"opacity-50":""} ${d?"bg-brand-500/30 ring-1 ring-brand-500":o?"bg-brand-500/25":i?"bg-brand-500/15":"hover:bg-surface-2"}`,style:{paddingLeft:i5(s,T)},onContextMenu:e=>y(e,t),onTouchStart:e=>w(e,t),onTouchEnd:j,onTouchMove:j,onClick:e=>!c&&v(t,e),children:[r?(0,n.jsx)("span",{onClick:e=>{e.stopPropagation(),g(t)},className:"flex items-center justify-center w-4 h-4 text-text-muted",children:a?(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 ${l?"rotate-90":""}`})}):(0,n.jsx)("span",{className:"w-4 h-4"}),(0,n.jsx)("span",{className:"shrink-0",children:r?function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:16,{src:r,alt:l}=i0(e,t);return(0,n.jsx)("img",{src:r,alt:l,width:s,height:s,className:"pointer-events-none select-none",draggable:"false"})}(t.name,l,R.icon):i1(t,R.icon)}),c?(0,n.jsx)("input",{ref:p,value:x,onChange:e=>h(e.target.value),onClick:e=>e.stopPropagation(),onBlur:f,onKeyDown:e=>{"Enter"===e.key?f():"Escape"===e.key&&b()},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 ${_.vs[m]||""}`,title:t.name,children:t.name}),!c&&(0,n.jsx)(i3,{status:m}),!c&&(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,_.mv)(m)},children:(0,n.jsx)("button",{onClick:e=>y(e,t),className:"p-0.5 text-text-muted hover:text-text",children:(0,n.jsx)(el.Ay,{name:"MoreHorizontal",size:R.chevron})})})]}),E]})});async function i8(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 i8(t,n,s)}}async function i9(e){let t=[],s=[...e.items||[]].map(e=>e.webkitGetAsEntry?.()).filter(Boolean);if(s.length)for(let e of s)await i8(e,"",t);else for(let s of e.files||[])t.push({file:s,relativePath:s.name});return t}let i7="modal-overlay z-50",oe="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",ot="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]",os="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 on(e){let{label:t,ratio:s}=e;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:t}),(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*(s||0))}%`}})})]})}function or(e){let{query:t,loading:s,onChange:r,onClose:l,compact:a=!1}=e,{t:i}=(0,eu.s)();return a?(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:t,onChange:e=>r(e.target.value),placeholder:i("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}),s?(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)(),l()},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:t,onChange:e=>r(e.target.value),placeholder:i("files.searchPlaceholder"),className:"flex-1 min-w-0 w-0 bg-transparent text-text placeholder-text-subtle focus:outline-none",autoFocus:!0}),s&&(0,n.jsx)(el.kr,{className:"animate-spin text-brand-500",size:16}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),l()},className:"p-1 text-text-muted hover:text-text transition-colors",children:(0,n.jsx)(el.X,{size:20})})]})}function ol(e){let{type:t,name:s,onTypeChange:l,onNameChange:a,onSubmit:i,onPickFile:o,onPickFolder:c,onClose:d}=e,{t:u}=(0,eu.s)(),[m]=(0,r.useState)(()=>"u">typeof document&&"webkitdirectory"in document.createElement("input")),x="upload"===t;return(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),d())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[d]),(0,se.createPortal)((0,n.jsxs)("div",{className:i7,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:d}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm my-auto overflow-y-auto pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:u("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)(),l("file")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${"file"===t?"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"})," ",u("files.file")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),l("folder")},className:`flex-1 py-2 rounded-brand transition flex items-center justify-center gap-2 ${"folder"===t?"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"})," ",u("files.folder")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),l("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"})," ",u("common.upload")]})]}),x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),o()},className:`${os} flex items-center justify-center gap-2`,children:[(0,n.jsx)(el.ZH,{size:16})," ",u("files.pickFile")]}),m&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),c()},className:`${ot} flex items-center justify-center gap-2`,children:[(0,n.jsx)(el.vd,{size:16})," ",u("files.pickFolder")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),d()},className:`${ot} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children: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"})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:s,onChange:e=>a(e.target.value),onKeyDown:e=>"Enter"===e.key&&i(),placeholder:u("file"===t?"files.placeholderFile":"files.placeholderFolder"),className:oe,autoFocus:!0}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),d()},className:`${ot} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children: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"})]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),i()},className:`${os} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:u("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})})]})]})]})]})]})]}),document.body)}function oa(e){let{value:t,onChange:s,onSubmit:l,onClose:a}=e,{t:i}=(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]),(0,se.createPortal)((0,n.jsxs)("div",{className:i7,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:a}),(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 pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:i("files.rename")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsx)("input",{type:"text",value:t,onChange:e=>s(e.target.value),onKeyDown:e=>"Enter"===e.key&&l(),className:oe,autoFocus:!0}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),a()},className:`${ot} flex items-center justify-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",{onClick:()=>{(0,ed.e)(),l()},className:`${os} flex items-center justify-center gap-1.5`,children:[(0,n.jsx)("span",{children:i("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})})]})]})]})]})]}),document.body)}function oi(e){let{name:t,onResolve:s}=e,{t:l}=(0,eu.s)();(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),s?.("skip"))};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[s]);let a=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s(e)},className:`py-2 rounded-brand text-sm flex items-center justify-center gap-1.5 ${t}`,children:[(0,n.jsx)("span",{children:l(`menu.${e}`)}),r&&(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,se.createPortal)((0,n.jsxs)("div",{className:i7,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:()=>s?.("skip")}),(0,n.jsxs)("div",{className:"relative card-elev w-full max-w-sm pop-in",children:[(0,n.jsx)("div",{className:"px-4 py-3",children:(0,n.jsx)("h3",{className:"text-text font-semibold",children:l("menu.conflictTitle")})}),(0,n.jsx)("div",{className:"px-4 pb-3 text-text-muted text-sm break-all",children:l("menu.conflictMessage",{name:t})}),(0,n.jsxs)("div",{className:"p-4 grid grid-cols-2 gap-2",children:[a("skip","bg-surface-2 text-text hover:bg-surface-3",!0),a("skipAll","bg-surface-2 text-text hover:bg-surface-3"),a("replace","bg-brand-500 text-white hover:bg-brand-600"),a("replaceAll","bg-brand-500 text-white hover:bg-brand-600")]})]})]}),document.body)}async function oo(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!e||!t||!s)return{success:!1};let r=iI(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}
14
+ `:`${i}
15
+ ${l}
16
+ `:`${l}
17
+ `;return await e.writeFile(r,d)}let oc="application/x-file-paths",od=()=>"u">typeof document&&"webkitdirectory"in document.createElement("input"),ou=e=>{let t=e.dataTransfer.getData(oc);if(!t)return null;try{return JSON.parse(t)}catch{return null}},om=e=>[...e.dataTransfer?.types||[]].includes("Files");function ox(e){let{workspace:t,fileBus:s,onOpenFile:l,activeFile:a,onSwitchWorkspace:i,onNewTerminal:o,onSearchFolder:c,compact:d=!1,onlyChanged:u=!1,onActions:m}=e,{t:x}=(0,eu.s)(),[p,h]=(0,r.useState)(null),f=(0,r.useRef)(null),b=nK(f,p?.x??0,p?.y??0),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)(""),[j,k]=(0,r.useState)(null),[N,C]=(0,r.useState)(""),[S,T]=(0,r.useState)(null),[E,R]=(0,r.useState)(()=>new Set),M=(0,r.useRef)(E);(0,r.useEffect)(()=>{M.current=E},[E]);let $=(0,r.useRef)(y);(0,r.useEffect)(()=>{$.current=y},[y]);let z=(0,r.useRef)(g);(0,r.useEffect)(()=>{z.current=g},[g]);let[P,A]=(0,r.useState)(null),[I,D]=(0,r.useState)(!1),[L,B]=(0,r.useState)(null),[F,O]=(0,r.useState)(null),[K,W]=(0,r.useState)(null),[H,q]=(0,r.useState)(null),U=(0,r.useRef)(null),X=(0,r.useRef)(null),V=(0,r.useRef)(null),G=(0,r.useRef)(null),[J]=(0,r.useState)(od),Y=(0,r.useRef)(null),Z=(0,r.useRef)(null),Q=(0,r.useRef)(null),ee=(0,r.useCallback)(e=>e&&t?e.replace(`${t}/`,""):e,[t]),{tree:et,expanded:es,loading:en,truncatedDirs:er,gitStatusMap:ea,showHidden:ei,setShowHidden:eo,loadDir:em,loadGitStatus:ex,toggleFolder:ep,expandDir:eh,collapseAll:ef,refreshAll:eb}=function(e){let{workspace:t,fileBus:s}=e,[n,l]=(0,r.useState)(()=>new Map),[a,i]=(0,r.useState)(()=>new Set),[o,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(()=>new Set),[m,x]=(0,r.useState)(()=>new Set),[p,h]=(0,r.useState)({}),[f,b]=(0,r.useState)(iW),g=(0,r.useCallback)(async e=>{u(t=>{let s=new Set(t);return s.add(e),s});let t=await s.getFiles(e,f);return(u(t=>{let s=new Set(t);return s.delete(e),s}),t?.success)?(l(s=>{let n=new Map(s);return n.set(e,t.files||[]),n}),x(s=>{let n=!!t.truncated;if(n===s.has(e))return s;let r=new Set(s);return n?r.add(e):r.delete(e),r}),t.files||[]):null},[s,f]),v=(0,r.useRef)(0),y=(0,r.useCallback)(async()=>{if(!t)return;let e=++v.current,{map:n}=await i_(s,t);e===v.current&&h(n)},[s,t]);(0,r.useEffect)(()=>{let e,s;if(!t)return;let n=!0,r=null,l=1e3,a=Array.isArray(s=(e=iK())[t])?s:Array.isArray(e.legacy)?e.legacy:[],o=new Set([t]),d=a.filter(e=>"string"==typeof e&&e.startsWith(t));for(let e of d)o.add(e);let u=async()=>{let[e]=await Promise.all([g(t),...d.map(e=>g(e))]);if(n){if(null==e&&l<=16e3){let e=l;l*=2,r=setTimeout(u,e);return}i(o),c(t),y()}};return u(),()=>{n=!1,clearTimeout(r)}},[t]),(0,r.useEffect)(()=>{let e=null,t=()=>{clearTimeout(e),e=setTimeout(y,_.HF)},s=["fileExplorer:fileSaved","fileExplorer:fileCreated","fileExplorer:fileDeleted","fileExplorer:fileRenamed",_.GW];return s.forEach(e=>window.addEventListener(e,t)),()=>{clearTimeout(e),s.forEach(e=>window.removeEventListener(e,t))}},[y]),(0,r.useEffect)(()=>{if(o===t&&t)try{let e=iK();delete e.legacy,e[t]=[...a],window.localStorage.setItem(_.d5.expandedFolders,JSON.stringify(e))}catch{}},[t,o,a]),(0,r.useEffect)(()=>{window.localStorage.setItem(_.d5.showHidden,JSON.stringify(f)),n.size>0&&Promise.all([...n.keys()].map(e=>g(e))).catch(()=>{})},[f]);let w=(0,r.useCallback)(async e=>{(0,ed.e)();let t=e.path;a.has(t)?i(e=>{let s=new Set(e);return s.delete(t),s}):(n.has(t)||await g(t),i(e=>{let s=new Set(e);return s.add(t),s}))},[a,n,g]),j=(0,r.useCallback)(e=>{i(t=>{let s=new Set(t);return s.add(e),s})},[]),k=(0,r.useCallback)(()=>{(0,ed.e)(),i(new Set)},[]),N=iF(),C=(0,r.useMemo)(()=>[...n.keys()].filter(e=>e===t||a.has(e)),[n,a,t]),S=(0,r.useCallback)(e=>{Promise.all(e.map(e=>g(e))).catch(()=>{}),window.dispatchEvent(new Event(_.GW))},[g]);iB({dirs:C,fileBus:s,onDirsChanged:S,enabled:N});let T=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=N&&!T.current;T.current=N,e&&n.size&&S([...n.keys()])},[N]);let E=(0,r.useCallback)(async()=>{(0,ed.e)();let e=[...n.keys()];await Promise.all(e.map(e=>g(e))),y()},[n,g,y]);return{tree:n,expanded:a,loading:d,truncatedDirs:m,gitStatusMap:p,showHidden:f,setShowHidden:b,loadDir:g,loadGitStatus:y,toggleFolder:w,expandDir:j,collapseAll:k,refreshAll:E}}({workspace:t,fileBus:s}),eg=(0,r.useMemo)(()=>{if(1!==E.size)return null;let[e]=E;return et.has(e)?e:null},[E,et]),{createItem:ev,renameItem:ey,deleteItem:ew,deleteMany:ej,duplicateItem:ek,moveTo:eN,pasteInto:eC}=function(e){let{fileBus:t,loadDir:s,loadGitStatus:n,expandDir:l,onOpenFile:a,onMoved:i}=e,o=(0,r.useCallback)(async(e,n,r)=>{let i=iI(e,n),o=await t.createItem(i,r);o?.success&&(iq("created"),await s(e),"folder"===r?l(e):a?.(i))},[t,s,l,a]),c=(0,r.useCallback)(async(e,n)=>{let r=iD(e.path),l=iI(r,n),a=await t.renameItem(e.path,l);a?.success&&(iq("renamed"),await s(r))},[t,s]),d=(0,r.useCallback)(async e=>{let n=iD(e.path),r=await t.deleteItem(e.path);r?.success&&(iq("deleted"),await s(n))},[t,s]),u=(0,r.useCallback)(async e=>{if(!e?.length)return;let r=new Set;for(let s of e){let e=await t.deleteItem(s.path);e?.success&&r.add(iD(s.path))}if(r.size){for(let e of(iq("deleted"),r))await s(e);n(),i?.()}},[t,s,n,i]),m=(0,r.useCallback)(async(e,s)=>{let n=iL(e),r=new Set(((await t.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 t.copyItem(e,iI(s,l))},[t]),x=(0,r.useCallback)(async e=>{let t=iD(e.path),r=await m(e.path,t);r?.success&&(iq("created"),await s(t),n())},[m,s,n]),p=(0,r.useCallback)(async(e,r)=>{if(e?.length&&r){for(let s of e){let e=iI(r,s.split("/").pop());s===e||e.startsWith(s+"/")||await t.renameItem(s,e)}for(let t of new Set([r,...e.map(e=>iD(e))]))await s(t);iq("renamed"),n(),i?.()}},[t,s,n,i]),h=(0,r.useCallback)(async(e,t,r)=>{if(!e?.length||!t)return;if("cut"===r)return p(e,t);let a=0;for(let s of e){if(t===s||t.startsWith(s+"/"))continue;let e=await m(s,t);e?.success&&a++}a&&(iq("created"),await s(t),l(t),n())},[m,p,s,l,n]);return{createItem:o,renameItem:c,deleteItem:d,deleteMany:u,duplicateItem:x,moveTo:p,pasteInto:h}}({fileBus:s,loadDir:em,loadGitStatus:ex,expandDir:eh,onOpenFile:l,onMoved:()=>R(new Set)});(0,r.useEffect)(()=>{if(!p)return;let e=()=>h(null);return window.addEventListener("click",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("click",e),window.removeEventListener("scroll",e,!0)}},[p]),(0,r.useEffect)(()=>{if(g&&Z.current){Z.current.focus();let e=Z.current.value.length;Z.current.setSelectionRange(e,e)}},[g]),(0,r.useEffect)(()=>{j&&Q.current&&Q.current.focus()},[j]);let eS=(0,r.useCallback)(()=>eg&&et.has(eg)?eg:t,[eg,et,t]),eT=(0,r.useCallback)(async e=>{let t=N.trim();if(!t)return;let s=j?.dir||eS();await ev(s,t,e),k(null),C("")},[N,j,eS,ev]),eE=(0,r.useCallback)(async()=>{let e=z.current;if(!e)return;let t=$.current.trim();t&&t!==e.name&&await ey(e,t),v(null)},[ey]),eR=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),eM=(0,r.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),(0,ed.e)(),R(e=>e.has(t.path)?e:new Set([t.path])),q(t.path),h({file:t,x:e.clientX,y:e.clientY})},[]),e$=(0,r.useCallback)((e,t)=>{let s=e.touches?.[0];if(!s)return;let n=s.clientX,r=s.clientY;Y.current=setTimeout(()=>{(0,ed.e)(),h({file:t,x:n,y:r})},500)},[]),ez=(0,r.useCallback)(()=>{Y.current&&(clearTimeout(Y.current),Y.current=null)},[]),eP=(0,r.useMemo)(()=>{if(!a)return null;if(!(0,_.pA)(a))return a;let{repoPath:e,filePath:s}=(0,_.qu)(a);return s?`${e||t}/${s}`:null},[a,t]),eA=e=>!u||!!ea[ee(e.path)],eI=(0,r.useMemo)(()=>{let e=[],s=(t,n)=>{for(let r of et.get(t)||[])(!u||ea[ee(r.path)])&&(e.push({file:r,depth:n}),"folder"===r.type&&es.has(r.path)&&s(r.path,n+1))};return s(t,0),e},[et,es,ea,u,t,ee]),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)(),U.current?.focus({preventScroll:!0}),t?.metaKey||t?.ctrlKey){R(t=>{let s=new Set(t);return s.has(e.path)?s.delete(e.path):s.add(e.path),s}),q(e.path),X.current=e.path;return}if(t?.shiftKey&&X.current){R(eB(X.current,e.path)),q(e.path);return}R(new Set([e.path])),q(e.path),X.current=e.path,"folder"===e.type?ep(e):l?.(e.path)},[ep,l,eB]),eO=(0,r.useCallback)(e=>e?"folder"===e.type?e.path:iD(e.path):t,[t]),e_=(0,r.useCallback)(e=>{let t=eL(e);t.length&&T({files:t})},[eL]),eK=(0,r.useCallback)(async()=>{let e=S?.files||[];T(null),1===e.length?await ew(e[0]):await ej(e),R(new Set)},[S,ew,ej]),eW=(0,r.useCallback)((e,t)=>{let s=eL(e).map(e=>e.path);s.length&&B({paths:s,mode:t})},[eL]),eH=(0,r.useCallback)(async e=>{L?.paths?.length&&(await eC(L.paths,eO(e),L.mode),"cut"===L.mode&&B(null))},[L,eC,eO]),eq=(0,r.useCallback)(async(e,t)=>{if(!e.length)return;let n=0;O({total:e.length,done:0,failed:0}),await s.uploadFiles(t,e,{onConflict:(e,t)=>new Promise(s=>W({name:t||e?.name,resolve:s})),onFileDone:()=>O(e=>e?{...e,done:e.done+1}:e),onError:()=>{n+=1,O(e=>e?{...e,done:e.done+1,failed:n}:e)}}),O(e=>e&&n?e:null),W(null),await em(t),eh(t),ex()},[s,em,eh,ex]),eU=(0,r.useCallback)(async(e,t)=>{eq(await i9(e),t)},[eq]),eX=(0,r.useCallback)(()=>v(null),[]),eV=(0,r.useCallback)((e,t)=>{let s=M.current,n=s.has(t.path)?[...s]:[t.path];e.dataTransfer.setData(oc,JSON.stringify(n)),e.dataTransfer.effectAllowed="move"},[]),eG=(0,r.useCallback)((e,t)=>{let s=om(e);("folder"===t.type||s)&&(e.preventDefault(),e.dataTransfer.dropEffect=s?"copy":"move","folder"===t.type&&A(t.path))},[]),eJ=(0,r.useCallback)(e=>{A(t=>t===e.path?null:t)},[]),eY=(0,r.useCallback)((e,t)=>{let s=om(e);if("folder"!==t.type&&!s)return;if(e.preventDefault(),e.stopPropagation(),A(null),D(!1),s)return void eU(e.dataTransfer,eO(t));let n=ou(e);n&&eN(n,t.path)},[eU,eO,eN]),eZ=(0,r.useCallback)(e=>{let t=j?.dir||eS(),s=[...e.target.files].map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}));e.target.value="",k(null),eq(s,t)},[j,eS,eq]),eQ=(0,r.useCallback)((e,t)=>{if(!eI.length)return;let s=eI.findIndex(e=>e.file.path===H),n=eI[Math.min(eI.length-1,Math.max(0,-1===s?0:s+e))];if(!n)return;let r=n.file.path;t&&X.current?R(eB(X.current,r)):(R(new Set([r])),X.current=r),q(r),U.current?.querySelector(`[data-path="${CSS.escape(r)}"]`)?.scrollIntoView({block:"nearest"})},[eI,H,eB]),e0=(0,r.useCallback)(e=>{if(g||j||S)return;let t=eD(H),s=e.metaKey||e.ctrlKey;if(s&&"a"===e.key.toLowerCase()){e.preventDefault(),R(new Set(eI.map(e=>e.file.path))),X.current=eI[0]?.file.path||null;return}if(s&&"c"===e.key.toLowerCase()){e.preventDefault(),eW(t,"copy");return}if(s&&"x"===e.key.toLowerCase()){e.preventDefault(),eW(t,"cut");return}if(s&&"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||es.has(t.path)?eQ(1,!1):ep(t);return;case"ArrowLeft":if(!t)return;e.preventDefault(),"folder"===t.type&&es.has(t.path)?ep(t):eQ(-1,!1);return;case"Enter":if(!t)return;e.preventDefault(),tp()?(v(t),w(t.name)):"folder"===t.type?ep(t):l?.(t.path);return;case"F2":if(!t)return;e.preventDefault(),v(t),w(t.name);return;case"Delete":case"Backspace":if(!t)return;e.preventDefault(),e_(t);return;case"Escape":R(new Set),B(null);return}},[g,j,S,H,eD,eI,es,ep,l,eQ,eW,eH,e_]),e1=(e,t)=>{if(!eA(e))return null;let s="folder"===e.type,r=s&&es.has(e.path),l=E.has(e.path);return(0,n.jsx)(i6,{file:e,depth:t,isFolder:s,isExpanded:r,isLoading:s&&en.has(e.path),isActive:eP===e.path,isSelected:l,isRenaming:g?.path===e.path,isDragOver:P===e.path&&s,isCut:L?.mode==="cut"&&L.paths.includes(e.path),gitStatus:ea[ee(e.path)],renameValue:g?.path===e.path?y:"",renameInputRef:Z,onRenameChange:w,onRenameSubmit:eE,onRenameCancel:eX,onToggleFolder:ep,onClick:eF,onContextMenu:eM,onTouchStart:e$,onTouchEnd:ez,onDragStart:eV,onDragOver:eG,onDragLeave:eJ,onDrop:eY,compact:d,children:s&&r&&(0,n.jsxs)("div",{children:[(et.get(e.path)||[]).map(e=>e1(e,t+1)),er.has(e.path)&&(0,n.jsx)(i4,{depth:t+1,compact:d})]})},e.path)},e2=(0,r.useMemo)(()=>et.get(t)||[],[et,t]);(0,r.useEffect)(()=>{if(!u)return;let e=!0;return(async()=>{for(let s of Object.keys(ea)){if("folder-changed"!==ea[s])continue;let n=`${t}/${s}`;if(!et.has(n)&&(await em(n),!e))return;eh(n)}})(),()=>{e=!1}},[u,ea,t]),(0,r.useEffect)(()=>{if(!eP||!U.current)return;let e=setTimeout(()=>{let e=U.current?.querySelector(`[data-path="${CSS.escape(eP)}"]`);e?.scrollIntoView({block:"nearest"})},0);return()=>clearTimeout(e)},[eP,et]);let e5=(0,r.useMemo)(()=>iL(t),[t]),e3=(e,t)=>{(0,ed.e)(),k({type:e,dir:t}),C("")};(0,r.useEffect)(()=>{if(m)return m({newFile:()=>e3("file",eS()),newFolder:()=>e3("folder",eS()),refresh:eb,collapseAll:ef,hasExpanded:es.size>0,showHidden:ei,toggleHidden:()=>eo(e=>!e)}),()=>m(null)},[m,ei,eb,ef,es.size,t]);let e4=(0,r.useCallback)(async e=>{if(!t||!s||!e?.path)return;let n=ee(e.path),r=await oo(s,t,n,"folder"===e.type);r?.success&&(ex(),window.dispatchEvent(new CustomEvent(_.GW)))},[t,s,ee,ex]),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:[!d&&(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)(),i?.()},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:eb,className:e6,title:"Refresh",children:(0,n.jsx)(el.Ay,{name:"RefreshCw",size:14})}),es.size>0&&(0,n.jsx)("button",{onClick:ef,className:e6,title:x("fileExplorer.collapseAll"),children:(0,n.jsx)(el.Ay,{name:"ChevronsDownUp",size:14})}),(0,n.jsx)("button",{onClick:()=>eo(e=>!e),className:`p-1 rounded hover:bg-surface-2 ${ei?"text-text":"text-text-muted hover:text-text"}`,title:ei?"Hide hidden files":"Show hidden files",children:(0,n.jsx)(el.Ay,{name:ei?"Eye":"EyeOff",size:14})})]}),(0,n.jsx)("div",{ref:U,tabIndex:0,onKeyDown:e0,className:`flex-1 overflow-auto py-1 outline-none ${I?"ring-2 ring-inset ring-brand-500/40 bg-brand-500/5":""}`,onDragOver:e=>{e.preventDefault();let t=om(e);e.dataTransfer.dropEffect=t?"copy":"move",t&&D(!0)},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||D(!1)},onClick:e=>{e.target===e.currentTarget&&R(new Set)},onDrop:e=>{if(e.preventDefault(),D(!1),om(e))return void eU(e.dataTransfer,t);let s=ou(e);s&&eN(s,t)},children:u&&!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||en.has(t)?(0,n.jsxs)(n.Fragment,{children:[e2.map(e=>e1(e,0)),er.has(t)&&(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"})}),p&&(0,n.jsx)("div",{ref:f,className:"fixed z-50 menu-popover p-1 min-w-[150px] pop-in",style:{left:b.left,top:b.top},onClick:e=>e.stopPropagation(),children:(e=>{if(!e)return[];let t="folder"===e.type,n=eL(e),r=n.length>1,a=[];return!r&&t?(o&&a.push({label:x("workspaces.openHere"),icon:"Terminal",action:()=>o(e.path)}),c&&a.push({label:"Search in Folder",icon:"Search",action:()=>c(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)})):!r&&(a.push({label:"Open",icon:"File",action:()=>l?.(e.path)}),(0,_.YO)(e.path)&&a.push({label:x("editor.preview"),icon:"Eye",action:()=>l?.(e.path,{preview:!0})})),a.push({label:"Cut",icon:"Scissors",action:()=>eW(e,"cut")}),a.push({label:"Copy",icon:"Copy",action:()=>eW(e,"copy")}),L?.paths?.length&&a.push({label:"Paste",icon:"ClipboardPaste",action:()=>eH(e)}),r||(a.push({label:"Reveal in OS",icon:"FolderOpen",action:()=>s.revealInOS(e.path)}),a.push({label:"Rename",icon:"Pencil",action:()=>{v(e),w(e.name)}}),a.push({label:"Duplicate",icon:"Copy",action:()=>ek(e)}),a.push({label:"Copy Path",icon:"Copy",action:()=>eR(e.path)}),a.push({label:"Copy Relative Path",icon:"Copy",action:()=>eR(ee(e.path))}),a.push({label:x("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:"EyeOff",action:()=>e4(e)})),a.push({label:r?`Delete ${n.length} items`:"Delete",icon:"Trash2",danger:!0,action:()=>e_(e)}),a})(p.file).map((e,t)=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),e.action(),h(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))}),j&&(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-50",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:()=>k(null)}),(0,n.jsxs)("div",{className:"relative card-elev p-4 w-full max-w-sm my-auto pop-in",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text mb-2",children:"folder"===j.type?"New Folder":"New File"}),(0,n.jsxs)("p",{className:"text-xs text-text-muted mb-2 truncate",children:["in ",ee(j.dir)||e5||"/"]}),(0,n.jsx)("input",{ref:Q,value:N,onChange:e=>C(e.target.value),onKeyDown:e=>{"Enter"===e.key?eT(j.type):"Escape"===e.key&&k(null)},placeholder:"folder"===j.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"===j.type&&J?G:V).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"===j.type&&J?"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)(),k(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(j.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:V,type:"file",multiple:!0,className:"hidden",onChange:eZ}),(0,n.jsx)("input",{ref:G,type:"file",webkitdirectory:"",className:"hidden",onChange:eZ})]}),document.body),F&&(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:F.failed?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-danger",children:x("fileExplorer.uploadFailedCount",{n:F.failed,total:F.total})}),(0,n.jsx)("button",{type:"button",onClick:()=>O(null),className:"ml-auto underline hover:text-text",children:x("common.close")})]}):(0,n.jsx)("span",{children:x("fileExplorer.uploadingCount",{n:Math.min(F.done+1,F.total),total:F.total})})}),K&&(0,n.jsx)(oi,{name:K.name,onResolve:e=>{K.resolve(e),W(null)}}),(0,n.jsx)(ec.A,{isOpen:!!S,onClose:()=>T(null),onConfirm:eK,title:"Delete",message:(S?.files?.length||0)>1?`Are you sure you want to delete these ${S.files.length} items?`:`Are you sure you want to delete "${S?.files?.[0]?.name}"?`,confirmText:"Delete",cancelText:"Cancel"})]})}function op(e){let{x:t,y:s,items:l,onClose:a}=e,i=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!i.current)return;let e=i.current.getBoundingClientRect(),n=Math.min(t,window.innerWidth-e.width-8),r=Math.min(s,window.innerHeight-e.height-8);i.current.style.left=`${Math.max(8,n)}px`,i.current.style.top=`${Math.max(8,r)}px`},[t,s]),(0,r.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&a()},t=e=>{"Escape"===e.key&&a()},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)}},[a]),(0,n.jsx)("div",{ref:i,className:"fixed z-50 min-w-[180px] py-1 rounded-lg border border-border bg-surface shadow-elev pop-in",style:{left:t,top:s},onContextMenu:e=>e.preventDefault(),children:l.filter(Boolean).map((e,t)=>(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:t=>{t.stopPropagation(),e.onClick?.(),a()},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 oh={Copy:el.QR,FileText:el.iU,ExternalLink:el.Gr,Undo2:el.bE,X:el.X,EyeOff:el.X_},of=(e,t)=>(e||"").split("\n").map(e=>e.trim()).find(t)||"",ob=(e,t)=>{let s=of(t,e=>/files? changed/.test(e));return e("git.commitSuccess")+(s?` \xb7 ${s}`:"")},og=(e,t)=>{if(/up.to.date/i.test(t||""))return e("git.upToDate");let s=of(t,e=>e.includes("->"));return e("git.pushSuccess")+(s?` \xb7 ${s}`:"")},ov="changes",oy="untracked";function ow(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}function oj(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(0,t):""}function ok(e,t){if(!e)return t;let s=e.endsWith("/")||e.endsWith("\\")?"":"/";return`${e}${s}${t}`}let oN=(0,r.memo)(function(e){let{file:t,workspace:s,isUntracked:r,t:l,isTouch:a,openDiff:i,onCtxMenu:o,onDiscard:c,onStage:d}=e,u=_.vs[t.status]||"text-text-muted";return ok(s,t.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:e=>o(t,e),onClick:()=>{(0,ed.e)(),i(t)},children:[(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:i1({name:ow(t.path),path:t.path,type:"file"},16)}),(0,n.jsx)("span",{className:"truncate text-xs text-text",title:t.path,children:ow(t.path)}),(0,n.jsx)("span",{className:"truncate text-[11px] text-text-muted flex-1",title:oj(t.path),children:oj(t.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 ${a?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:[(0,n.jsx)("button",{type:"button",title:l(r?"common.delete":"git.discard"),onClick:e=>{e.stopPropagation(),(0,ed.e)(),c(t)},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:l("git.stage"),onClick:e=>{e.stopPropagation(),(0,ed.e)(),d(t)},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 ${u}`,children:t.status})]})},(e,t)=>e.file.path===t.file.path&&e.file.status===t.file.status&&e.workspace===t.workspace&&e.isUntracked===t.isUntracked&&e.isTouch===t.isTouch&&e.t===t.t);function oC(e){let{workspace:t,fileBus:s,onOpenFile:l,tagDiffWithRepo:a=!1}=e,{t:i}=(0,eu.s)(),o=av(),[c,d]=(0,r.useState)(""),[u,m]=(0,r.useState)(null),[x,p]=(0,r.useState)(null),[h,f]=(0,r.useState)([]),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(null),[k,N]=(0,r.useState)(new Set([ov,oy])),[C,S]=(0,r.useState)({}),[T,E]=(0,r.useState)(!1),[R,M]=(0,r.useState)(!1),[$,z]=(0,r.useState)(null),[P,A]=(0,r.useState)(!1),[I,D]=(0,r.useState)(null),[L,B]=(0,r.useState)(null),F=(0,r.useCallback)(async()=>{if(!t||!s)return;y(!0);let[e,n]=await Promise.all([s.gitStatus?.(t),s.gitBranch?.(t)]);y(!1),e?.success&&f(e.files||[]),n?.success&&(d(n.branch||""),m(n.ahead??null),p(n.behind??null))},[t,s]);(0,r.useEffect)(()=>{F()},[F]),(0,r.useEffect)(()=>{let e=null,t=()=>{clearTimeout(e),e=setTimeout(F,_.HF)};return _.vb.forEach(e=>window.addEventListener(e,t)),()=>{clearTimeout(e),_.vb.forEach(e=>window.removeEventListener(e,t))}},[F]);let{changes:O,untracked:K}=(0,r.useMemo)(()=>{let e=[],t=[];for(let s of h)"?"===s.status?t.push(s):e.push(s);return{changes:e,untracked:t}},[h]),W=(0,r.useCallback)(e=>{N(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),H=(0,r.useCallback)(async e=>{t&&(await s.gitAdd?.(t,[e.path]),F())},[t,s,F]),q=(0,r.useCallback)(async()=>{t&&(await s.gitAdd?.(t,["."]),F())},[t,s,F]),U=(0,r.useCallback)(async e=>{t&&(await s.gitDiscard?.(t,e.path,e.status),F())},[t,s,F]),X=(0,r.useCallback)(e=>{z(e),M(!0)},[]),V=(0,r.useCallback)(e=>{l?.(a?(0,_.n2)(e.status,t,e.path):(0,_.Dk)(e.status,e.path))},[l,a,t]),G=(0,r.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];!b.trim()||h.length&&(A(e),E(!0))},[b,h]),J=(0,r.useCallback)(async()=>{if(!t)return;j(null);let e=await s.gitAdd?.(t,["."]);if(e&&!e.success)return void j({ok:!1,text:e.error||i("git.stageFailed")});let n=await s.gitCommit?.(t,b.trim());if(!n?.success){j({ok:!1,text:n?.output||n?.error||i("git.commitFailed")}),F();return}if(g(""),!P){j({ok:!0,text:ob(i,n.output)}),F();return}let r=await s.gitPush?.(t);j(r?.success?{ok:!0,text:`${ob(i,n.output)} \xb7 ${og(i,r.output)}`}:{ok:!1,text:r?.output||r?.error||i("git.pushFailed")}),F()},[t,s,b,P,F,i]),Y=(0,r.useCallback)(async()=>{if(!t)return;y(!0),j(null);let e=await s.gitPush?.(t);y(!1),j(e?.success?{ok:!0,text:og(i,e.output)}:{ok:!1,text:e?.output||e?.error||i("git.pushFailed")}),F()},[t,s,F,i]),Z=(0,r.useCallback)(async()=>{if(!t)return;y(!0),j(null);let e=await s.gitPull?.(t);y(!1),j(e?.success?{ok:!0,text:((e,t)=>{if(/already up to date|up.to.date/i.test(t||""))return e("git.upToDate");let s=of(t,e=>/files? changed|fast-forward/i.test(e));return e("git.pullSuccess")+(s?` \xb7 ${s}`:"")})(i,e.output)}:{ok:!1,text:e?.output||e?.error||i("git.pullFailed")}),F()},[t,s,F,i]),Q=(0,r.useCallback)((e,t)=>{e.stopPropagation(),(0,ed.e)();let s=e.currentTarget.getBoundingClientRect();t({x:s.right,y:s.bottom+4})},[]),[ee,et]=(0,r.useState)(null),es=(0,r.useCallback)(async e=>{try{await navigator.clipboard.writeText(e)}catch{}},[]),en=(0,r.useCallback)((e,t)=>{t.preventDefault(),t.stopPropagation(),(0,ed.e)(),et({file:e,x:t.clientX,y:t.clientY})},[]),er=(0,r.useCallback)(async e=>{if(!t||!s||!e?.path)return;let n=await oo(s,t,e.path);n?.success&&(window.dispatchEvent(new CustomEvent(_.GW)),F())},[t,s,F]),ea=(0,r.useCallback)(e=>{let s=ok(t,e.path);return[{key:"open",label:i("git.openFile"),icon:el.Gr,disabled:"D"===e.status,onClick:()=>l?.(s)},{key:"copyPath",label:i("files.copyPath",{defaultValue:"Copy Path"}),icon:el.Gr,onClick:()=>es(s)},{key:"copyRel",label:i("files.copyRelPath",{defaultValue:"Copy Relative Path"}),icon:el.Gr,onClick:()=>es(e.path)},{key:"copyName",label:i("files.copyName",{defaultValue:"Copy Filename"}),icon:el.Gr,onClick:()=>es(ow(e.path))},{key:"addToGitignore",label:i("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:el.X_,onClick:()=>er(e)}]},[t,l,es,er,i]),ei=(0,r.useCallback)(e=>{S(t=>({...t,[e]:(t[e]??_.Tf)+_.aB}))},[]),eo=(e,s,r,l)=>{let a=k.has(e),c=r.slice(0,C[e]??_.Tf),d=r.length-c.length;return(0,n.jsxs)("div",{className:"border-t border-border",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),W(e)},className:"w-full flex items-center gap-1 px-2 py-1 hover:bg-surface-2 text-left",children:[a?(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})]}),a&&(0,n.jsxs)(n.Fragment,{children:[c.map(e=>(0,n.jsx)(oN,{file:e,workspace:t,isUntracked:l,t:i,isTouch:o,openDiff:V,onCtxMenu:en,onDiscard:X,onStage:H},`${e.status}-${e.path}`)),d>0&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),ei(e)},className:"w-full px-2 py-1 text-[11px] text-brand-500 hover:bg-surface-2 text-left",children:i("git.showMore",{count:d})})]})]})};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:c||"—"}),u>0&&(0,n.jsxs)("span",{className:"text-[10px] font-medium px-1.5 rounded-brand bg-brand-500/15 text-brand-500",children:["↑",u]}),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:i("common.refresh"),onClick:()=>{(0,ed.e)(),window.dispatchEvent(new Event(_.GW))},className:"p-1 text-text-muted hover:text-text",children:(0,n.jsx)(el.e9,{size:12,className:v?"animate-spin":""})}),(0,n.jsx)("button",{type:"button",title:i("git.gitActions"),onClick:e=>Q(e,B),className:"p-1 text-text-muted hover:text-text",children:(0,n.jsx)(el.a4,{size:12})})]}),(0,n.jsx)("textarea",{value:b,onChange:e=>g(e.target.value),rows:2,placeholder:i("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 ${!b.trim()||!h.length?"opacity-40":""}`,children:[(0,n.jsx)("button",{type:"button",disabled:!b.trim()||!h.length,onClick:()=>{(0,ed.e)(),G(!1)},className:"flex-1 text-xs hover:bg-black/10 disabled:cursor-not-allowed transition-colors",children:i("git.commit")}),(0,n.jsx)("span",{className:"w-px my-1.5 bg-white/25"}),(0,n.jsx)("button",{type:"button",title:i("git.gitActions"),disabled:!b.trim()||!h.length,onClick:e=>Q(e,D),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})})]}),w&&(0,n.jsx)("div",{className:`text-[11px] leading-snug break-words rounded-brand px-2 py-1 ${w.ok?"text-[var(--success)] bg-[rgba(var(--success-rgb),0.1)]":"text-[var(--danger)] bg-[rgba(var(--danger-rgb),0.1)]"}`,children:w.text})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[eo(ov,i("git.changes"),O,!1),eo(oy,i("git.untracked"),K,!0)]}),(0,n.jsx)(ec.A,{isOpen:T,onClose:()=>E(!1),onConfirm:J,title:i("git.stageAllConfirmTitle"),message:i("git.stageAllConfirmMessage"),confirmText:i("git.stageAndCommit"),cancelText:i("common.cancel")}),(0,n.jsx)(ec.A,{isOpen:R,onClose:()=>{M(!1),z(null)},onConfirm:()=>{$&&U($),z(null)},title:i("git.discardConfirmTitle"),message:$?"?"===$.status?i("git.discardConfirmDelete",{name:ow($.path)}):i("git.discardConfirmDiscard",{name:ow($.path)}):"",confirmText:i("git.discard"),cancelText:i("common.cancel")}),ee&&(0,n.jsx)(op,{x:ee.x,y:ee.y,items:ea(ee.file),onClose:()=>et(null)}),I&&(0,n.jsx)(op,{x:I.x,y:I.y,items:[{key:"commitPush",label:i("git.commitAndPush"),icon:el.Do,disabled:!b.trim()||!h.length,onClick:()=>G(!0)}],onClose:()=>D(null)}),L&&(0,n.jsx)(op,{x:L.x,y:L.y,items:[{key:"push",label:i("git.push"),icon:el.Do,onClick:Y},{key:"pull",label:i("git.pull"),icon:el.yd,onClick:Z},{key:"stageAll",label:i("git.stageAll"),icon:el.FW,disabled:!h.length,onClick:q}],onClose:()=>B(null)})]})}let oS=[{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 oT(e){let{results:t,loading:s,query:l,searchDir:a,workspace:i,onOpen:o}=e,{t:c}=(0,eu.s)(),[d,u]=(0,r.useState)(()=>new Set);if(!l||l.length<2){let e=a?a.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}`:c("files.searchPlaceholder")})]})}if(s)return(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle text-center",children:c("files.searching")});if(!t.length)return(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle text-center",children:c("files.noFilesFound")});let m=t.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 sticky top-0 bg-surface/80 backdrop-blur-md z-[1]",children:[m," results in ",t.length," files"]}),t.map(e=>{let t=e.path.split("/").pop(),s=e.path.slice(0,e.path.length-t.length).replace(i,"").replace(/^\//,""),r=!d.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,u(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)(),o(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 oE(e){let{root:t,multiple:s,isOpen:r,onToggle:l,onRemove:a=null,removeLabel:i="",children:o}=e;return s?(0,n.jsxs)("div",{className:`flex flex-col min-h-0 ${r?"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 transition-colors",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),l()},className:"flex-1 min-w-0 flex items-center gap-1.5 hover:text-text transition-colors",title:t.path,children:[(0,n.jsx)(el.c_,{size:11,className:`flex-shrink-0 transition-transform duration-150 ${r?"rotate-90":""}`}),(0,n.jsx)("span",{className:"truncate flex-1 text-left",children:t.branch||t.name||t.path.split("/").pop()}),!t.isMain&&(0,n.jsx)(el.dx,{size:10,className:"flex-shrink-0 opacity-60"})]}),a&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),a()},title:i,className:"p-0.5 shrink-0 hover:text-red-500 transition-colors",children:(0,n.jsx)(el.TB,{size:11})})]}),r&&(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:o})]}):(0,n.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:o})}function oR(e){let{icon:t,label:s,onClick:r,active:l,disabled:a,spinning:i}=e;return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),r?.()},disabled:a,title:s,className:`p-2 sm:p-1 rounded-[3px] hover:bg-surface-2 transition-colors disabled:opacity-40 ${l?"text-brand-500":"text-text-muted hover:text-text"}`,children:(0,n.jsx)(t,{size:16,className:`sm:w-[13px] sm:h-[13px] ${i?"animate-spin":""}`})})}function oM(e){let{active:t,onClick:s,title:r,children:l}=e;return(0,n.jsx)("button",{type:"button",title:r,onClick:()=>{(0,ed.e)(),s()},className:`px-1 h-5 text-[10px] font-medium rounded-[3px] border transition-colors shrink-0 ${t?"bg-brand-500 text-white border-brand-500":"bg-transparent text-text-muted border-transparent hover:bg-surface-2"}`,children:l})}function o$(e){let{onClick:t,children:s}=e;return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),t()},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:s})}function oz(e){let{repo:t,changedCount:s=0,isOpen:r,onToggle:l,onHide:a,children:i}=e,{t:o}=(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)(),l()},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/80 backdrop-blur-md transition-colors",children:[(0,n.jsx)(el.c_,{size:11,className:`flex-shrink-0 transition-transform duration-150 ${r?"rotate-90":""}`}),(0,n.jsx)("span",{className:"truncate flex-1 text-left",title:t.relPath||t.name,children:t.relPath||t.name}),t.branch&&(0,n.jsx)("span",{className:"text-text-subtle normal-case tracking-normal truncate max-w-[45%]",title:t.branch,children:t.branch}),s>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:s}),a&&(0,n.jsx)("span",{role:"button",tabIndex:-1,onClick:e=>{e.stopPropagation(),(0,ed.e)(),a()},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:o("workspaces.hideRepo"),children:(0,n.jsx)(el.X_,{size:11})})]}),r&&i]})}let oP=(0,r.memo)(function(e){let{workspacePath:t,filesRoot:s=null,cwdHint:l=null,fileBus:a,activeFile:i,tab:o,onTabChange:c,width:d,onResize:u,onClose:m,onOpenFile:x,onNewTerminal:p,onAddWorkspace:h,onOpenFiles:f,homeDir:b,changedPerRepo:g={},hiddenRepos:v=[],onHiddenReposChange:y,isDesktop:w=!0}=e,{t:j}=(0,eu.s)(),k=a||en.getState(),N="trees"===o?"git":o,{repos:C,refresh:S,scanning:T,deep:E,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.useRef)(0),u=(0,r.useCallback)(async(t,s)=>{if(!e||!i?.gitScanRepos)return;let r=++d.current;a(!0),t&&await i.gitRefreshRepos?.(e);let l=s?eg.Tk.deepMaxDepth:eg.Tk.maxDepth,o=await iP(()=>i.gitScanRepos(e,l,t),()=>d.current===r);d.current===r&&(a(!1),n(o?.success&&o.repos||[]))},[e,i]);return(0,r.useEffect)(()=>{let e=setTimeout(()=>void u(!1,o),0);return()=>{clearTimeout(e),d.current++}},[u,o]),{repos:s,refresh:(0,r.useCallback)(()=>u(!0,o),[u,o]),scanning:l,deep:o,scanDeeper:(0,r.useCallback)(()=>c(!0),[])}}(t,k),M=s||t,{roots:$,refresh:z}=function(e,t){let[s,n]=(0,r.useState)([]),l=t||en.getState(),a=(0,r.useRef)(0),i=(0,r.useCallback)(async()=>{if(!e||!l?.gitWorktreeList)return n([]);let t=++a.current,s=await iP(()=>l.gitWorktreeList(e),()=>a.current===t);if(a.current===t){if(!s?.success||!s.worktrees?.length)return n([{path:e,branch:null,name:iA(e)}]);n(s.worktrees.map(e=>({path:e.path,branch:e.branch,name:iA(e.path),isMain:e.isMain})))}},[e,l]);return(0,r.useEffect)(()=>{let e=setTimeout(()=>void i(),0);return()=>{clearTimeout(e),a.current++}},[i]),{roots:s,refresh:i}}(M,k),P=()=>{S(),z()},{branch:A}=r9(t,k),I=(0,r.useRef)({path:null,branch:null});(0,r.useEffect)(()=>{let e=I.current;I.current={path:t,branch:A},e.path===t&&null!==e.branch&&e.branch!==A&&(S(),z(),window.dispatchEvent(new Event(_.GW)))},[A,t]);let[D,L]=(0,r.useState)({forWorkspace:t,showClean:!1,openRepo:null}),B=D.forWorkspace===t?D:{showClean:!1,openRepo:null},F=B.showClean,O=B.openRepo,K=e=>L({...B,forWorkspace:t,openRepo:e}),W=new Set(v),H=e=>g[e.path]??e.changedCount??0,q=e=>!e.relPath||e.path===t,U=C.filter(e=>!W.has(e.path)),X=U.filter(e=>H(e)>0).reduce((e,t)=>e+H(t),0),V=F?U:U.filter(e=>H(e)>0||q(e)),G=V.filter(q),J=V.filter(e=>!q(e)).sort((e,t)=>(H(t)>0)-(H(e)>0)||(e.relPath||e.path).localeCompare(t.relPath||t.path)),Y=F?0:U.length-V.length,Z=C.length-U.length,Q=eg.G.map(e=>V.find(t=>t.branch===e)).find(Boolean),ee=(Q||V.find(q)||V[0])?.path||null,et=(V.some(e=>e.path===O)?O:void 0)??(""===O?null:ee),es=e=>y?.([...v,e]),er=e=>!!y&&!q(e),ea=!w||d>=eg.Ds.min,[ei,eo]=(0,r.useState)(null),[em,ex]=(0,r.useState)(null),[ep,eh]=(0,r.useState)(null),[ef,eb]=(0,r.useState)(null),ev=$.find(e=>e.isMain)?.path||t,ey=async e=>{eh(null);let t=await k.gitWorktreeRemove(ev,e.path,{probe:!0,deleteBranch:e.branch||void 0});if(!t?.success)return eh(t?.error||"Probe failed");ex({root:e,sessions:t.sessions||[],branchMerged:t.branchMerged})},ew=async function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];eh(null),eb(null);let s=await k.gitWorktreeRemove(ev,e.path,{confirmed:!0,force:t,deleteBranch:e.branch||void 0});return!s?.success&&/use --force/i.test(s?.error||"")?ex({root:e,dirty:!0}):(ex(null),s?.success)?void(s.branchKept&&eb(e.branch),P()):eh(s?.error||"Remove failed")},ej=l||M,ek=(0,r.useMemo)(()=>{let e=$.filter(e=>ej===e.path||ej?.startsWith(`${e.path}/`));return e.length?e.sort((e,t)=>t.path.length-e.path.length)[0].path:($.find(e=>e.isMain)||$[0])?.path||M},[$,ej,M]),[eN,eC]=(0,r.useState)({forProbe:null,path:null}),eS=eN.forProbe===ej?eN.path:ek,[eT,eE]=(0,r.useState)({forRoot:null,searchDir:null,show:!1,query:"",results:[],loading:!1}),[eR,eM]=(0,r.useState)({caseSensitive:!1,wholeWord:!1,regex:!1}),e$=eT.forRoot===M?eT:{show:!1,searchDir:null,query:"",results:[],loading:!1},ez=(0,r.useRef)(null),eP=(0,r.useCallback)(()=>{eE({forRoot:null,searchDir:null,show:!1,query:"",results:[],loading:!1})},[]),eA=(0,r.useCallback)(e=>{eE({forRoot:M,searchDir:e,show:!0,query:"",results:[],loading:!1})},[M]),eI=(0,r.useCallback)(()=>{eE(e=>{let t={...e,searchDir:null};return e.query&&e.query.length>=2&&(t.loading=!0,k.searchInFiles(M,e.query,eR).then(e=>{eE(t=>t.loading?{...t,results:e.success?e.results:[],loading:!1}:t)})),t})},[k,M,eR]),eD=(0,r.useCallback)(e=>{if(eE(t=>({...t,query:e})),ez.current&&clearTimeout(ez.current),!e||e.length<2)return void eE(e=>({...e,results:[],loading:!1}));eE(e=>({...e,loading:!0}));let t=e$.searchDir||M;ez.current=setTimeout(async()=>{let s=await k.searchInFiles(t,e,eR);eE(t=>t.query===e&&t.loading?{...t,results:s.success?s.results:[],loading:!1}:t)},300)},[k,M,e$.searchDir,eR]),eL=(0,r.useCallback)(e=>{eE(t=>{if(!t.query||t.query.length<2)return t;let s={...t,loading:!0};return k.searchInFiles(t.searchDir||M,t.query,e).then(e=>{eE(t=>t.loading?{...t,results:e.success?e.results:[],loading:!1}:t)}),s})},[k,M]),eB=e=>{let t={...eR,[e]:!eR[e]};eM(t),eL(t)};return(0,r.useEffect)(()=>()=>{ez.current&&clearTimeout(ez.current)},[]),(0,n.jsxs)("div",{className:`h-full flex flex-col terminal-sidebar-bg border-l border-border-subtle relative shrink ${w?"":"pb-safe"}`,style:w?{width:d,flexBasis:d,minWidth:eg.Ds.min}:void 0,children:[(0,n.jsxs)("div",{className:`h-11 ${nY} pl-1 pr-0.5 flex items-stretch gap-0 border-b border-border-subtle flex-shrink-0`,children:[oS.map(e=>{let{key:t,icon:s,labelKey:r}=e;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),c(t)},className:`px-3 sm:px-2 flex items-center justify-center gap-1 text-[11px] border-b-2 -mb-px transition-colors ${N===t?"text-text border-brand-500":"text-text-muted border-transparent hover:text-text"}`,title:j(r),children:[(0,n.jsx)(s,{size:18,className:"sm:w-[15px] sm:h-[15px]"}),ea&&(0,n.jsx)("span",{children:j(r)}),"git"===t&&X>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:X>99?"99+":X})]},t)}),(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)(oR,{icon:el.e9,label:j("workspaces.refreshRepos"),onClick:()=>{let e;P(),ei?.refresh?.(),(e=ry.get(t))&&rj(e,t,!0),window.dispatchEvent(new Event(_.GW))},disabled:T,spinning:T}),m&&(0,n.jsx)(oR,{icon:el.X,label:j("common.close"),onClick:m})]})]}),"files"===N&&t&&(0,n.jsx)("div",{className:`${e$.show?"py-1":`h-11 ${nY}`} px-2 flex items-center gap-1.5 flex-shrink-0`,children:e$.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:e$.query,onChange:e=>eD(e.target.value),onKeyDown:e=>{"Escape"===e.key&&eP()},placeholder:e$.searchDir?`Search in ${e$.searchDir.split("/").pop()}…`:j("files.searchPlaceholder"),className:"flex-1 min-w-0 w-0 bg-transparent text-xs text-text placeholder-text-subtle focus:outline-none",autoFocus:!0}),e$.loading?(0,n.jsx)(el.kr,{size:13,className:"animate-spin text-brand-500 shrink-0"}):e$.query?(0,n.jsx)("button",{type:"button",onClick:()=>eD(""),className:"p-1 text-text-subtle hover:text-text",children:(0,n.jsx)(el.X,{size:12})}):null,(0,n.jsx)(oR,{icon:el.X,label:j("common.close"),onClick:eP})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 pl-0.5",children:[(0,n.jsx)(oM,{active:eR.caseSensitive,onClick:()=>eB("caseSensitive"),title:"Match Case",children:"Aa"}),(0,n.jsx)(oM,{active:eR.wholeWord,onClick:()=>eB("wholeWord"),title:"Whole Word",children:"ab"}),(0,n.jsx)(oM,{active:eR.regex,onClick:()=>eB("regex"),title:"Regex",children:".*"})]})]}):(0,n.jsxs)(n.Fragment,{children:[ei&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(oR,{icon:el.FW,label:j("files.newFile"),onClick:ei.newFile}),(0,n.jsx)(oR,{icon:el.JU,label:j("files.newFolder"),onClick:ei.newFolder})]}),(0,n.jsx)(oR,{icon:el.vj,label:j("files.searchFiles"),onClick:()=>{if(e$.show)return eP();eE({forRoot:M,searchDir:null,show:!0,query:"",results:[],loading:!1})},active:e$.show}),(0,n.jsx)("div",{className:"flex-1"}),ei?.hasExpanded&&(0,n.jsx)(oR,{icon:el.WE,label:j("fileExplorer.collapseAll"),onClick:ei.collapseAll}),ei&&(0,n.jsx)(oR,{icon:ei.showHidden?el.kU:el.X_,label:j("files.toggleHidden"),onClick:ei.toggleHidden,active:ei.showHidden}),f&&(0,n.jsx)(oR,{icon:el.Gr,label:j("workspaces.openFullFiles"),onClick:f})]})}),"files"===N&&t&&e$.show&&e$.searchDir&&(0,n.jsxs)("div",{className:"px-3 py-1 bg-surface-3/40 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:e$.searchDir,children:e$.searchDir.split("/").pop()})]}),(0,n.jsx)("button",{type:"button",onClick:eI,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:t?"files"===N?e$.show?(0,n.jsx)(oT,{results:e$.results,loading:e$.loading,query:e$.query,searchDir:e$.searchDir,workspace:M,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:[(ep||ef)&&(0,n.jsxs)("div",{className:"px-3 py-1.5 border-b border-border-subtle text-[11px]",children:[ep&&(0,n.jsx)("p",{className:"text-red-500 break-words whitespace-pre-wrap",children:ep}),ef&&(0,n.jsx)("p",{className:"text-text-muted break-words",children:j("workspaces.worktreeBranchKept",{branch:ef})})]}),$.map(e=>(0,n.jsx)(oE,{root:e,multiple:$.length>1,isOpen:1===$.length||eS===e.path,onToggle:()=>eC({forProbe:ej,path:eS===e.path?null:e.path}),onRemove:e.isMain?null:()=>{(0,ed.e)(),ey(e)},removeLabel:j("workspaces.removeWorktree"),children:(0,n.jsx)(ox,{workspace:e.path,fileBus:k,activeFile:i,onOpenFile:x,onNewTerminal:p,onSearchFolder:eA,compact:!0,onActions:e.path===eS||1===$.length?eo:void 0})},e.path))]}):"git"===N?(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col",children:[(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto modal-scrollable",children:[G.map(e=>(0,n.jsx)(oz,{repo:e,changedCount:H(e),isOpen:et===e.path,onToggle:()=>K(et===e.path?"":e.path),onHide:er(e)?()=>es(e.path):null,children:(0,n.jsx)(oC,{workspace:e.path,fileBus:k,onOpenFile:x,tagDiffWithRepo:!0})},e.path)),!V.length&&!T&&(0,n.jsx)("p",{className:"p-4 text-xs text-text-subtle italic",children:F?j("workspaces.emptyWorkspace"):j("git.noChanges")})]}),(J.length>0||Y>0||Z>0||!E)&&(0,n.jsxs)("div",{className:"flex-shrink-0 max-h-[45%] overflow-y-auto modal-scrollable border-t border-border-subtle bg-surface/40",children:[J.length>0&&(0,n.jsx)("p",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-text-subtle",children:j("workspaces.nestedRepos",{count:J.length})}),J.map(e=>(0,n.jsx)(oz,{repo:e,changedCount:H(e),isOpen:et===e.path,onToggle:()=>K(et===e.path?"":e.path),onHide:er(e)?()=>es(e.path):null,children:(0,n.jsx)(oC,{workspace:e.path,fileBus:k,onOpenFile:x,tagDiffWithRepo:!0})},e.path)),(Y>0||Z>0||!E)&&(0,n.jsxs)("div",{className:J.length>0?"border-t border-border-subtle":"",children:[Y>0&&(0,n.jsx)(o$,{onClick:()=>L({...B,forWorkspace:t,showClean:!0}),children:j("workspaces.showCleanRepos",{count:Y})}),Z>0&&(0,n.jsx)(o$,{onClick:()=>y?.([]),children:j("workspaces.showHiddenRepos",{count:Z})}),!E&&(0,n.jsx)(o$,{onClick:R,children:j("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:j("workspaces.emptyWorkspace")}),h&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),h()},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:j("workspaces.selectFolder")})]})}),(0,n.jsx)(ec.A,{isOpen:!!em,onClose:()=>ex(null),onConfirm:()=>{(0,ed.e)(),ew(em.root,!!em.dirty)},title:j("workspaces.removeWorktree"),message:em?em.dirty?j("workspaces.worktreeDirty"):[j("workspaces.removeWorktreeFolder",{path:em.root.path}),em.root.branch&&j(!0===em.branchMerged?"workspaces.removeWorktreeBranchDelete":!1===em.branchMerged?"workspaces.removeWorktreeBranchKeep":"workspaces.removeWorktreeBranch",{branch:em.root.branch}),em.sessions?.length?j("workspaces.removeWorktreeSessions",{count:em.sessions.length,names:em.sessions.map(e=>e.name).join(", ")}):null].filter(Boolean).join("\n"):""}),w&&(0,n.jsx)("div",{onPointerDown:e=>eZ(e,{startWidth:d,axis:-1,onWidth:e=>u?.(e)}),className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})]})});function oA(e){return e?e<1024?`${e}B`:e<1048576?`${(e/1024).toFixed(1)}KB`:`${(e/1048576).toFixed(1)}MB`:""}function oI(e){let{filePath:t,fileBus:s}=e,[l,a]=(0,r.useState)(""),[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(""),[u,m]=(0,r.useState)(!0),[x,p]=(0,r.useState)(1),[h,f]=(0,r.useState)({x:0,y:0}),[b,g]=(0,r.useState)(0),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)(0);(0,r.useEffect)(()=>{let e=!1,n=[],r="";m(!0),d(""),a(""),o(null),p(1),f({x:0,y:0}),g(0),w.current=null,j.current&&(URL.revokeObjectURL(j.current),j.current=null);let l=t.toLowerCase();if(l.endsWith(".tif")||l.endsWith(".tiff"))return s.readMedia(t).then(t=>{e||(t.success?(a(t.dataUrl),o({size:t.originalSize||t.size,width:t.width,height:t.height,scaled:t.scaled,originalWidth:t.originalWidth,originalHeight:t.originalHeight})):d(t.error||"Failed to load image"),m(!1))}),()=>{e=!0};let i=s.streamMedia(t,{onMeta:t=>{e||(r=t.mime||"image/*",o({size:t.size,width:t.width,height:t.height,scaled:t.scaled,originalWidth:t.originalWidth,originalHeight:t.originalHeight}))},onChunk:t=>{e||n.push(t)},onDone:()=>{if(e)return;let t=new Blob(n,{type:r});if(t.size>_.W5){w.current=t,g(t.size),m(!1);return}j.current=URL.createObjectURL(t),a(j.current),m(!1)},onError:t=>{e||(d(t.message||"Failed to load image"),m(!1))}});return()=>{e=!0,i?.()}},[t,s]),(0,r.useEffect)(()=>()=>{j.current&&URL.revokeObjectURL(j.current)},[]);let T=(0,r.useCallback)((e,t,s)=>{let n=y.current,r=v.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))}},[]),E=(0,r.useCallback)(()=>{p(1),f({x:0,y:0})},[]),R=(0,r.useCallback)((e,t,s)=>{p(n=>{let r=Math.max(.2,Math.min(8,n*e));if(r===n)return n;if(null!=t&&null!=s){let e=v.current;if(e){let l=e.clientWidth/2,a=e.clientHeight/2,i=t-l,o=s-a;f(e=>T((e.x-i)*(r/n)+i,(e.y-o)*(r/n)+o,r))}}else f(e=>T(e.x,e.y,r));return r})},[T]),M=(e,t)=>Math.hypot(e.clientX-t.clientX,e.clientY-t.clientY),$=(0,r.useCallback)(e=>{if(2===e.touches.length)N.current=null,k.current={dist:M(e.touches[0],e.touches[1]),scale:x,pos:h};else if(1===e.touches.length){let t=Date.now();if(t-S.current<300){x>1.01?E():(p(2),f({x:0,y:0})),S.current=0,N.current=null;return}S.current=t,x>1.01&&(N.current={x:e.touches[0].clientX,y:e.touches[0].clientY,pos:h})}},[x,h,E]),z=(0,r.useCallback)(e=>{if(2===e.touches.length&&k.current){e.preventDefault();let t=M(e.touches[0],e.touches[1]),s=Math.max(.2,Math.min(8,k.current.scale*(t/k.current.dist)));p(s),f(e=>T(e.x,e.y,s))}else if(1===e.touches.length&&N.current){e.preventDefault();let t=e.touches[0],s=t.clientX-N.current.x,n=t.clientY-N.current.y;f(T(N.current.pos.x+s,N.current.pos.y+n,x))}},[x,T]),P=(0,r.useCallback)(e=>{e.touches.length<2&&(k.current=null),0===e.touches.length&&(N.current=null)},[]),A=(0,r.useCallback)(e=>{"mouse"!==e.pointerType||0!==e.button||x<=1.01||(C.current={x:e.clientX,y:e.clientY,pos:h})},[x,h]),I=(0,r.useCallback)(e=>{let t=C.current;if(t){if(!(1&e.buttons)){C.current=null;return}f(T(t.pos.x+(e.clientX-t.x),t.pos.y+(e.clientY-t.y),x))}},[x,T]),D=(0,r.useCallback)(()=>{C.current=null},[]),L=(0,r.useCallback)(e=>{e.preventDefault();let t=e.deltaY<0?1.1:1/1.1,s=v.current?.getBoundingClientRect();R(t,s?e.clientX-s.left:null,s?e.clientY-s.top:null)},[R]);if(u)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(c)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:c});if(b)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:t,children:t.split("/").pop()}),(0,n.jsxs)("span",{className:"text-xs",children:[oA(b)," — decoding an image this large can crash mobile Safari."]}),(0,n.jsx)("button",{onClick:()=>{let e=w.current;e&&(j.current=URL.createObjectURL(e),a(j.current),g(0))},className:"px-3 py-1.5 rounded bg-surface-2 hover:bg-surface-3 text-text text-sm",children:"Open anyway"})]});let B=i?.width&&i?.height?`${i.width}\xd7${i.height}`:"",F=i?.scaled&&i?.originalWidth&&i?.originalWidth!==i?.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:t,children:t.split("/").pop()}),i?.size?(0,n.jsx)("span",{className:"text-text-subtle",children:oA(i.size)}):null,B?(0,n.jsxs)("span",{className:"text-text-subtle",children:[B,F?" ↓":""]}):null,(0,n.jsx)("button",{onClick:()=>R(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:()=>R(1.2),className:"px-2 hover:bg-surface-2 rounded",children:"+"}),(0,n.jsx)("button",{onClick:E,className:"px-2 hover:bg-surface-2 rounded",children:"Reset"})]}),(0,n.jsx)("div",{ref:v,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 ${x>1.01?"cursor-grab active:cursor-grabbing":""}`,onTouchStart:$,onTouchMove:z,onTouchEnd:P,onPointerDown:A,onPointerMove:I,onPointerUp:D,onPointerCancel:D,onWheel:L,children:(0,n.jsx)("img",{ref:y,src:l,alt:t,draggable:!1,onLoad:e=>o(t=>({...t,width:e.target.naturalWidth,height:e.target.naturalHeight})),style:{transform:`translate(${h.x}px, ${h.y}px) scale(${x})`,transformOrigin:"center",willChange:"transform"},className:"max-w-full max-h-full object-contain select-none"})})]})}function oD(e){let{filePath:t,fileBus:s}=e,[l,a]=(0,r.useState)(""),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(0),[u,m]=(0,r.useState)(""),[x,p]=(0,r.useState)(!0);if((0,r.useEffect)(()=>{let e=!1,n=null,r=null,l=null,i=null,c=[],u=!1;p(!0),m(""),a(""),o(""),d(0);let x=!1,h="",f=()=>{if(!e&&!x&&i&&!i.updating){if(c.length)return void i.appendBuffer(c.shift());if(u&&r&&"open"===r.readyState)try{r.endOfStream()}catch{}}};return n=s.streamMedia(t,{onMeta:t=>{let{mime:s,size:n}=t;if(!e){if(o(s),d(n),!("u">typeof MediaSource&&MediaSource.isTypeSupported(s))){x=!0,h=s;return}r=new MediaSource,a(l=URL.createObjectURL(r)),p(!1),r.addEventListener("sourceopen",()=>{e||((i=r.addSourceBuffer(s)).addEventListener("updateend",f),f())})}},onChunk:t=>{!e&&(c.push(t),x||f())},onDone:()=>{if(!e)if(x){let e=new Blob(c,{type:h||"application/octet-stream"});a(l=URL.createObjectURL(e)),p(!1)}else u=!0,f()},onError:t=>{e||(m(t.message||"Stream error"),p(!1))}}),()=>{e=!0,n?.(),l&&URL.revokeObjectURL(l);try{r&&"open"===r.readyState&&r.endOfStream()}catch{}}},[t,s]),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(u)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:u});let h=i.startsWith("video/"),f=t.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:t,children:f}),c?(0,n.jsx)("span",{className:"text-text-subtle",children:c?c<1024?`${c}B`:c<1048576?`${(c/1024).toFixed(1)}KB`:`${(c/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:h?(0,n.jsx)("video",{src:l,controls:!0,className:"max-h-full max-w-full"}):(0,n.jsx)("audio",{src:l,controls:!0,className:"w-full max-w-md"})})]})}function oL(e){let{filePath:t,fileBus:l}=e,[a,i]=(0,r.useState)(!0),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)([]),[m,x]=(0,r.useState)(0),[p,h]=(0,r.useState)([]),f=(0,r.useRef)(null),b=(0,r.useRef)(null),g=(0,r.useRef)(null);if((0,r.useEffect)(()=>{let e=!1,n=null,r=[],a=(0,_.$b)(t);i(!0),c(""),u([]),x(0),h([]),b.current=null,f.current&&(f.current.innerHTML="");let o=async t=>{try{if(a){let{renderAsync:n}=await s.e(5421).then(s.bind(s,25421));if(e||!f.current){e||i(!1);return}for(let e of(await n(new Blob([t]),f.current,void 0,{inWrapper:!0,renderAltChunks:!1}),f.current.querySelectorAll("a[href]"))){let t=e.getAttribute("href")||"";/^(https?:|mailto:|#)/i.test(t.trim())||e.removeAttribute("href")}e||i(!1)}else{let n=await Promise.all([s.e(2571),s.e(5198)]).then(s.bind(s,83390));if(e)return;g.current=n,b.current=n.read(t,{type:"array"}),u(b.current.SheetNames),x(0),(e=>{let t=b.current,s=g.current;if(!t||!s)return;let n=t.SheetNames[e];n&&(h(s.utils.sheet_to_json(t.Sheets[n],{header:1,defval:"",raw:!1})),i(!1))})(0)}}catch(t){e||(c(t.message||"Failed to render"),i(!1))}};return n=l.streamMedia(t,{onChunk:t=>{e||r.push(t)},onDone:()=>{if(e)return;let t=new Uint8Array(r.reduce((e,t)=>e+t.byteLength,0)),s=0;for(let e of r)t.set(e,s),s+=e.byteLength;o(t)},onError:t=>{e||(c(t.message||"Failed to load"),i(!1))}}),()=>{e=!0,n?.()}},[t,l]),(0,r.useEffect)(()=>{let e=b.current,t=g.current;if(!e||!t)return;let s=e.SheetNames[m];s&&h(t.utils.sheet_to_json(e.Sheets[s],{header:1,defval:"",raw:!1}))},[m]),o)return(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:o});let v=(0,_.$b)(t);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[a&&(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..."})]}),!v&&d.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:d.map((e,t)=>(0,n.jsx)("button",{onClick:()=>x(t),className:`px-2 py-1 text-xs rounded whitespace-nowrap transition-colors ${t===m?"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:v?(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:p.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 oB(e){let{filePath:t,fileBus:s}=e,[l,a]=(0,r.useState)(""),[i,o]=(0,r.useState)(""),[c,d]=(0,r.useState)(!0);return((0,r.useEffect)(()=>{let e=!1,n=null,r=[],l="application/pdf";d(!0),o(""),a("");let i=s.streamMedia(t,{onMeta:t=>{let{mime:s}=t;!e&&s&&(l=s)},onChunk:t=>{e||r.push(t)},onDone:()=>{if(e)return;let t=new Blob(r,{type:l}),s=URL.createObjectURL(t);n=s,a(s),d(!1)},onError:t=>{e||(o(t.message||"Failed to load PDF"),d(!1))}});return()=>{e=!0,i(),n&&URL.revokeObjectURL(n)}},[t,s]),c)?(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..."})]}):i?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-red-400 text-sm",children:i}):(0,n.jsx)("iframe",{src:l,title:"PDF preview",className:"h-full w-full bg-bg"})}let oF=e=>(0,_.u)(e)||(0,_.AE)(e)||(0,_.L8)(e)||(0,_.ZH)(e)||(0,_.$b)(e)||(0,_.iB)(e);function oO(e){let{filePath:t,fileBus:s}=e;return(0,_.ZH)(t)?(0,n.jsx)(oB,{filePath:t,fileBus:s},t):(0,_.$b)(t)||(0,_.iB)(t)?(0,n.jsx)(oL,{filePath:t,fileBus:s},t):(0,_.AE)(t)||(0,_.L8)(t)?(0,n.jsx)(oD,{filePath:t,fileBus:s},t):(0,n.jsx)(oI,{filePath:t,fileBus:s},t)}function o_(e){let{filePath:t,fileBus:s}=e,[n,l]=(0,r.useState)(!0),[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!1),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),f=(0,r.useRef)(""),b=(0,r.useRef)(null),g=(0,r.useRef)(null),[v,y]=(0,r.useState)(!1),w=(0,r.useCallback)(e=>{b.current=e},[]),j=(0,r.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>!1,n=await s.readFile(t);if(e())return{cancelled:!0};if(!n?.success)return{error:n?.error||""};let r=n.content;if(n.streamInstead)try{let n=[];if(await new Promise((e,r)=>{s.streamMedia(t,{onMeta:()=>{},onChunk:e=>n.push(e),onDone:e,onError:r})}),e())return{cancelled:!0};r=await new Blob(n).text()}catch(t){if(e())return{cancelled:!0};return{error:t?.message||""}}return{text:r}},[t,s]),k=(0,r.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>!1;l(!0),c(""),u(!1),y(!1);let{text:t,error:s}=await j(e);if(void 0===t){void 0!==s&&(c(s),l(!1));return}f.current=t,i(t),l(!1)},[j]);(0,r.useEffect)(()=>{let e=!1;if(!t){l(!1),i(null),u(!1),c(""),y(!1);return}return k(()=>e),()=>{e=!0}},[t,k]);let N=(0,r.useCallback)(async()=>{let{text:e}=await j();if(void 0===e||e===f.current)return;let t=b.current?.();null!=t&&t!==f.current?y(!0):(f.current=e,i(e))},[j]),C=(0,r.useCallback)(()=>{d?y(!0):N()},[d,N]);(0,r.useEffect)(()=>()=>clearTimeout(g.current),[]);let S=(0,r.useCallback)(e=>{u(e!==f.current)},[]),T=(0,r.useCallback)(async()=>{let e=b.current?.();if(null==e||m||e===f.current)return!0;x(!0);let n=await s.writeFile(t,e);return(x(!1),n?.success)?(f.current=e,u(!1),c(""),h(!0),clearTimeout(g.current),g.current=setTimeout(()=>h(!1),2e3),window.dispatchEvent(new CustomEvent("fileExplorer:fileSaved",{detail:{filePath:t}})),!0):(c(n?.error||""),!1)},[t,s,m]);return{loading:n,content:a,error:o,dirty:d,saving:m,justSaved:p,staleOnDisk:v,register:w,onTextChanged:S,save:T,discard:(0,r.useCallback)(()=>{u(!1),i(f.current)},[]),setError:c,reload:k,onChangedOnDisk:C}}function oK(e){let{dirty:t,onSave:s}=e,[n,l]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!t)return;let e=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[t]);let a=(0,r.useCallback)(e=>{if(!t)return e();l(()=>e)},[t]),i=(0,r.useCallback)(async()=>{await s()&&(l(null),n?.())},[s,n]),o=(0,r.useCallback)(()=>{l(null),n?.()},[n]);return{guard:a,asking:!!n,saveThenLeave:i,discardAndLeave:o,cancel:(0,r.useCallback)(()=>l(null),[])}}function oW(e){let{isOpen:t,fileName:s,onSave:l,onDiscard:a,onCancel:i}=e,{t:o}=(0,eu.s)(),c=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!t)return;let e=requestAnimationFrame(()=>{c.current?.focus()});return()=>cancelAnimationFrame(e)},[t]),(0,r.useEffect)(()=>{if(!t)return;let e=e=>{if("Escape"===e.key)e.preventDefault(),e.stopPropagation(),i?.();else if("Enter"===e.key){if(document.activeElement?.tagName==="BUTTON"&&document.activeElement!==c.current)return;e.preventDefault(),e.stopPropagation(),(0,ed.e)(),l?.()}else"d"!==e.key&&"D"!==e.key||e.metaKey||e.ctrlKey||e.altKey||(e.preventDefault(),e.stopPropagation(),(0,ed.e)(),a?.())};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[t,i,l,a]),t)?(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:i,children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in"}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:"relative card-elev w-full max-w-sm p-5 pop-in",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-[15px] font-semibold text-text mb-1.5",children:o("editor.unsavedTitle",{name:s||""})}),(0,n.jsx)("p",{className:"text-[13px] text-text-muted leading-snug mb-5",children:o("editor.unsavedBody")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),a?.()},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:o("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:i,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:o("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:c,onClick:()=>{(0,ed.e)(),l?.()},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:o("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 oH=s(7557),oq=s(80714),oU=s(35144),oX=s(69992),oV=s(26795),oG=s(67363),oJ=s(13831),oY=s(75910),oZ=s(71532),oQ=s(94001),o0=s(85293),o1=s(74975);let o2={javascript:(0,oX.Q2)(),html:(0,oV.qy)(),css:(0,oG.AH)(),json:(0,oJ.Pq)(),markdown:(0,oY.wD)()};function o5(e){let t,s,{filePath:l,content:a,onTextChanged:i,onRegisterView:o,onSave:c,onCursorChange:d,line:u,column:m,compact:x=!1,className:p=""}=e,{theme:h}=(0,t7.D)(),f=(0,r.useRef)(null),b=(0,r.useRef)(null),g=(0,r.useRef)(i),v=(0,r.useRef)(d),y=(0,r.useRef)(c);(0,r.useEffect)(()=>{g.current=i},[i]),(0,r.useEffect)(()=>{v.current=d},[d]),(0,r.useEffect)(()=>{y.current=c},[c]);let[w]=sN(_.d5.editorFontSize,_.A0),[j]=sN(_.d5.wordWrap,!0),k=window.innerWidth<eg.jK,N=x?Math.max(_.rL,w-_.xl):w+ +!!k,{extension:C}=(t="."+l.split(".").pop()?.toLowerCase(),{lang:s=_.so[t]||"plaintext",extension:o2[s]||[]});return(0,r.useEffect)(()=>{if(null==a||!f.current)return;let e=oU.$t.create({doc:a,extensions:[oH.oQ,..."dark"===h?[oZ.bM]:[],C,...j?[oq.Lz.lineWrapping]:[],(0,oQ.$P)(),(0,o0.yU)(),(0,o0.wm)(),oq.w4.of([{key:"Mod-s",preventDefault:!0,run:()=>(y.current?.(),!0)},...o0.Bc,...o0.OO,o1.Yc]),oq.Lz.updateListener.of(e=>{if(e.docChanged&&g.current?.(e.state.doc.toString()),e.selectionSet||e.docChanged){let t=e.state.selection.main.head,s=e.state.doc.lineAt(t);v.current?.({line:s.number,column:t-s.from+1})}}),oq.Lz.theme({"&":{height:"100%",fontSize:`${N}px`},".cm-scroller":{overflow:"auto",lineHeight:x?"1.35":""},".cm-content":{minHeight:"100%"},".cm-gutters":x?{fontSize:`${Math.max(8,N-1)}px`}:{}})]});return b.current?.destroy(),b.current=new oq.Lz({state:e,parent:f.current}),o?.(()=>b.current?.state.doc.toString()??null,b.current),()=>{b.current?.destroy(),b.current=null}},[a,l,h,j,N,x]),(0,r.useEffect)(()=>{let e=b.current;if(!e||!u)return;let t=e.state.doc,s=Math.max(1,Math.min(u,t.lines)),n=t.line(s),r=Math.min(n.from+Math.max(0,(m||1)-1),n.to);e.dispatch({selection:{anchor:r},effects:oq.Lz.scrollIntoView(r,{y:"center"})}),e.focus()},[u,m,a]),(0,n.jsx)("div",{ref:f,className:`h-full w-full overflow-hidden ${p}`})}let o3=null,o4=0;function o6(e){let t,l,{content:a,reloadKey:i=0}=e,{t:o}=(0,eu.s)(),{theme:c}=(0,t7.D)(),[d,u]=(0,r.useState)(""),[m,x]=(0,r.useState)(""),p=(0,r.useRef)(null),h=(l=(t=String(a||"").trim()).match(/^```(?:mermaid)?\s*([\s\S]*?)\s*```$/i))?l[1].trim():t,[f,b]=(0,r.useState)(h);return(f!==h&&(b(h),u(""),x("")),(0,r.useEffect)(()=>{let e=!1;if(h)return(!o3&&(o3=Promise.all([s.e(515),s.e(2269),s.e(8390)]).then(s.bind(s,74811)).then(e=>e.default)),o3).then(async t=>{if(!e){t.initialize({startOnLoad:!1,theme:"dark"===c?"dark":"default",securityLevel:A.Ic});try{let{svg:s}=await t.render(`mmd-${++o4}`,h);if(e)return;u(s),x("")}catch(t){if(e)return;u(""),x(t?.message||String(t))}}}).catch(t=>{e||x(t?.message||String(t))}),()=>{e=!0}},[h,c,i]),m)?(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:m}),(0,n.jsx)("pre",{className:"text-[11px] text-text-muted whitespace-pre-wrap break-words",children:h})]}):h?d?(0,n.jsx)("div",{ref:p,className:"h-full overflow-auto p-3 flex items-start justify-center [&_svg]:max-w-full [&_svg]:h-auto",dangerouslySetInnerHTML:{__html:d}}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:o("common.loading")}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:o("editor.mermaidEmpty")})}function o8(e){let{content:t}=e,{t:s}=(0,eu.s)();return t?.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)(aW,{content:t})})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:s("common.empty",{defaultValue:"Empty file"})})}function o9(e){let{kind:t,content:s,reloadKey:r=0}=e;return"mermaid"===t?(0,n.jsx)(o6,{content:s,reloadKey:r}):"markdown"===t?(0,n.jsx)(o8,{content:s}):null}var o7=s(17261);s(56649);let ce=["diff --git","index ","new file","deleted file","--- ","+++ "];function ct(e){let{diff:t,compact:s=!1,className:l=""}=e,[a,i]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(s)return;let e=window.matchMedia(`(min-width: ${_.gh}px)`),t=()=>i(e.matches);return t(),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[s]);let o=!s&&a,c=(0,r.useCallback)(e=>{if(e&&t&&o)try{new o7.LU(e,t,{drawFileList:!1,matching:"words",outputFormat:"side-by-side",renderNothingWhenEmpty:!1}).draw()}catch{e.replaceChildren(Object.assign(document.createElement("pre"),{className:"text-text-muted p-4",textContent:t}))}},[t,o]),d=(0,r.useMemo)(()=>o||!t?[]:function(e){let t=[],s=0,n=0;for(let r of e.split("\n")){if(ce.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}(t),[o,t]);return o?(0,n.jsx)("div",{ref:c,className:`diff-themed select-text ${s?"diff-themed-compact":"bg-surface rounded"} overflow-hidden text-sm ${l}`}):(0,n.jsx)("div",{className:`w-full max-w-full select-text overflow-hidden font-mono leading-[1.6] ${s?"text-[10px] leading-[1.45]":"rounded-lg border border-border bg-surface text-[12.5px]"} ${l}`,children:d.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 cs(e){var t;let s,r,{title:l,badge:a,badgeColor:i,img:o,loading:c,error:d,t:u}=e,m=[(s=o?.originalWidth||o?.width,r=o?.originalHeight||o?.height,s&&r?`${s} \xd7 ${r}`:""),!(t=o?.size||o?.originalSize)?"":t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(1)} KB`:`${(t/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:l}),a&&(0,n.jsx)("span",{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded-[3px] ${i}`,children:a})]}),m&&(0,n.jsx)("span",{className:"text-[11px] text-text-muted font-mono",children:m})]}),(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:c?(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:u("common.loading")})]}):d?(0,n.jsx)("div",{className:"text-xs text-text-muted text-center px-4 py-6",children:d}):o?.dataUrl?(0,n.jsx)("img",{src:o.dataUrl,alt:l,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:u("git.noChanges")})})]})}function cn(e){let{filePath:t,status:s,workspace:l,fileBus:a,compact:i=!1}=e,{t:o}=(0,eu.s)(),c="A"===s||"?"===s,d="D"===s,u=!c,m=!d,[x,p]=(0,r.useState)(null),[h,f]=(0,r.useState)(u),[b,g]=(0,r.useState)(""),[v,y]=(0,r.useState)(null),[w,j]=(0,r.useState)(m),[k,N]=(0,r.useState)(""),[C,S]=(0,r.useState)(t);C!==t&&(S(t),p(null),f(u),g(""),y(null),j(m),N("")),(0,r.useEffect)(()=>{let e=!1;if(!t||!a)return;let s=l&&!t.startsWith("/")?`${l}/${t}`:t,n=l&&t.startsWith(l)?t.slice(l.length).replace(/^\//,""):t,r=setTimeout(()=>{u&&(f(!0),g(""),a.gitShowMedia?.(l,n,"HEAD").then(t=>{e||(f(!1),t?.success?p(t):g(t?.error||o("git.noOldVersion",{defaultValue:"No previous version in HEAD"})))}).catch(t=>{e||(f(!1),g(t?.message||"Failed to load old version"))})),m&&(j(!0),N(""),a.readMedia?.(s).then(t=>{e||(j(!1),t?.success?y(t):N(t?.error||o("git.noNewVersion",{defaultValue:"Failed to load working image"})))}).catch(t=>{e||(j(!1),N(t?.message||"Failed to load new version"))}))},0);return()=>{e=!0,clearTimeout(r)}},[t,l,a,u,m,o]);let T=t?t.split("/").pop():"",E=d||u&&!b&&(h||!!x?.dataUrl),R=E&&m;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 ${!i&&R?"grid grid-cols-1 md:grid-cols-2 gap-3":"flex flex-col gap-3"}`,children:[E&&(0,n.jsx)(cs,{title:d?`${T} (Deleted)`:"Old (HEAD)",badge:d?"DELETED":"ORIGINAL",badgeColor:"bg-red-500/15 text-red-400",img:x,loading:h,error:b,t:o}),m&&(0,n.jsx)(cs,{title:c?`${T} (Added)`:"New (Working Tree)",badge:c?"NEW":"MODIFIED",badgeColor:"bg-green-500/15 text-green-400",img:v,loading:w,error:k,t:o})]})})}function cr(e){let{diffPath:t,workspace:s,fileBus:l,compact:a=!1}=e,{t:i}=(0,eu.s)(),{status:o,repoPath:c,filePath:d}=(0,_.qu)(t),u=c||s,m=(0,_.u)(d),[x,p]=(0,r.useState)(!m),[h,f]=(0,r.useState)(""),[b,g]=(0,r.useState)(""),v=(0,r.useRef)(0),y=(0,r.useCallback)(async()=>{let e=++v.current;p(!0),g("");let t=await l.gitDiff?.(u,d,o);e===v.current&&(t?.success?f(t.diff||""):g(t?.error||""),p(!1))},[l,u,d,o]);return((0,r.useEffect)(()=>{if(m)return;let e=setTimeout(y,0);return()=>clearTimeout(e)},[y,m]),(0,r.useEffect)(()=>{if(m)return;let e=()=>y();return _.vb.forEach(t=>window.addEventListener(t,e)),()=>_.vb.forEach(t=>window.removeEventListener(t,e))},[y,m]),m)?(0,n.jsx)(cn,{filePath:d,status:o,workspace:u,fileBus:l,compact:a}):(0,n.jsxs)("div",{className:`h-full overflow-auto ${a?"p-0":"p-2 sm:p-3"}`,children:[b&&(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:b}),x?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted text-sm",children:i("common.loading")}):h?(0,n.jsx)(ct,{diff:h,compact:a}):(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted text-sm",children:i("git.noChanges")})]})}let cl="browser:openUrl";async function ca(e,t){let s=await e.previewStart(t);return s?.success&&s?.localUrl?(window.dispatchEvent(new CustomEvent(cl,{detail:{url:s.localUrl}})),{ok:!0}):{ok:!1,error:s?.error||null}}function ci(e){let{filePath:t,workspace:s,fileBus:l,width:a,onResize:i,onClose:o,onOpenFull:c,onOpenFile:d,isDesktop:u=!0,previewSeq:m=0,artifactTitle:x=null,jump:p=null}=e,{t:h}=(0,eu.s)(),f=(0,_.pA)(t),b=f?(0,_.qu)(t):null,g=b?.repoPath||s,v=f?b.filePath:t,y=b?(0,_.Ez)(t,s):"",w=!!t&&!f&&!oF(t),j=o_({filePath:w?t:"",fileBus:l}),[k,N]=sN(_.d5.editorFontSize,_.A0),C=e=>N(t=>Math.max(_.xr,Math.min(_.bd,(t||_.A0)+e))),S=(0,r.useRef)(j);(0,r.useEffect)(()=>{S.current=j},[j]);let T=oK({dirty:w&&j.dirty,onSave:j.save}),E=w?(0,_.YO)(t):null,R="html"===E,M=f&&"D"!==b.status&&"html"===(0,_.YO)(b.filePath),$=m>0,[z,P]=(0,r.useState)($),[A,I]=(0,r.useState)(""),[D,L]=(0,r.useState)(0),[B,F]=(0,r.useState)(t),[O,K]=(0,r.useState)(!1),[W,H]=(0,r.useState)(m);(B!==t||W!==m)&&(F(t),H(m),P($),I("")),j.justSaved!==O&&(K(j.justSaved),j.justSaved&&L(e=>e+1));let q=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||q.current?.contains(e.target)&&T.guard(o)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[T,o]);let U=t&&!f?t.slice(0,t.lastIndexOf("/")):"",X=(0,r.useMemo)(()=>U?[U]:[],[U]),V=iF(),G=(0,r.useCallback)(()=>{L(e=>e+1),S.current?.onChangedOnDisk(),window.dispatchEvent(new Event(_.GW))},[]);iB({dirs:X,fileBus:l,enabled:!!U&&V,debounceMs:_.Jl.PREVIEW_DEBOUNCE_MS,onDirsChanged:G});let J=(0,r.useCallback)(e=>{ca(l,e).then(e=>{e.ok||I(e.error||h("editor.previewFailed"))})},[l,h]);if((0,r.useEffect)(()=>{if(!R||m<=0)return;let e=!1;return ca(l,t).then(t=>{e||t.ok||I(t.error||h("editor.previewFailed"))}),()=>{e=!0}},[R,m,l,t]),!t)return null;let Y=v.split("/").pop(),Z=s&&v.startsWith(s)?v.slice(s.length).replace(/^\//,""):v;return(0,n.jsxs)("div",{ref:q,className:"h-full flex flex-col bg-bg border-l border-border-subtle relative shrink min-w-0",style:u?{width:a,flexBasis:a,minWidth:eg.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:i1({name:Y,type:"file"},14)}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-[12px] text-text",title:Z,children:Y}),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:h("editor.artifact")}),f&&(0,n.jsx)("span",{className:`text-[10px] font-bold flex-shrink-0 ${_.vs[b.status]||"text-text-muted"}`,children:b.status}),M&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),J(y)},title:h("editor.previewInBrowser"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:(0,n.jsx)(el.qz,{size:13})}),E&&(R?(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),J(t)},title:h("editor.previewInBrowser"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:(0,n.jsx)(el.qz,{size:13})}):(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),P(e=>!e)},title:z?h("editor.editCode"):h("editor.preview"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:z?(0,n.jsx)(el.GD,{size:13}):(0,n.jsx)(el.kU,{size:13})})),w&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),j.save()},disabled:!j.dirty||j.saving,title:h("editor.save"),className:`p-1 rounded-[3px] transition-colors disabled:opacity-30 ${j.dirty?"text-brand-500 hover:bg-surface-2":"text-text-muted"}`,children:(0,n.jsx)(el.eM,{size:13})}),(f?!!d:c&&u)&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),f?d(y):T.guard(()=>c(t))},title:f?h("git.openFile"):h("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)(),T.guard(o)},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})})]}),j.error&&w&&(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:j.error}),A&&(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:A}),j.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:h("editor.changedOnDisk")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),j.reload()},className:"shrink-0 px-1.5 py-0.5 rounded-[3px] hover:bg-amber-500/20 font-medium transition-colors",children:h("editor.reloadFromDisk")})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:f?(0,n.jsx)(cr,{diffPath:(0,_.Dk)(b.status,b.filePath),workspace:g,fileBus:l,compact:!0}):oF(t)?(0,n.jsx)(oO,{filePath:t,fileBus:l}):z&&E&&!R?(0,n.jsx)(o9,{kind:E,filePath:t,fileBus:l,content:j.content,reloadKey:D}):j.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-xs",children:h("common.loading")}):(0,n.jsx)(o5,{filePath:t,content:j.content,onTextChanged:j.onTextChanged,onRegisterView:j.register,onSave:j.save,line:p?.line,column:p?.column,compact:!0})}),w&&(!z||R)&&(0,n.jsxs)("div",{className:"h-7 px-1.5 flex items-center justify-end gap-0.5 border-t border-border-subtle flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),C(-1)},className:"w-6 h-6 flex items-center justify-center text-[14px] leading-none text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:"−"}),(0,n.jsx)("span",{className:"min-w-[26px] text-center text-[10px] tabular-nums text-text-subtle",title:h("fileExplorer.fontSize"),children:k}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),C(1)},className:"w-6 h-6 flex items-center justify-center text-[14px] leading-none text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:"+"})]}),(0,n.jsx)(oW,{isOpen:T.asking,fileName:Y,onSave:T.saveThenLeave,onDiscard:T.discardAndLeave,onCancel:T.cancel}),u&&(0,n.jsx)("div",{onPointerDown:e=>eZ(e,{startWidth:a,axis:-1,onWidth:e=>i?.(e)}),className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})]})}function co(){let[e,t]=(0,r.useState)(null),s="mouse"!==sj();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+eg.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+eg.de.SLACK_PX}(r)&&t({text:e,...function(e){let{GAP_PX:t,EDGE_PX:s,MAX_WIDTH_PX:n,EST_HEIGHT_PX:r}=eg.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:eg.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,se.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 fade-in",style:{left:e.left,top:e.top,bottom:e.bottom,maxWidth:eg.de.MAX_WIDTH_PX},children:e.text}),document.body):null}let cc=(0,r.memo)(function(e){let{height:t=1,className:s=""}=e,l=(0,r.useRef)(null),[a,i]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=l.current;if(!e)return;let t=new ResizeObserver(t=>{let[s]=t,n=s?.contentRect?.width||e.offsetWidth;n>0&&i(Math.round(n))});return t.observe(e),()=>t.disconnect()},[]);let o=a||600,c=Math.max(1.8,(o+140)/250);return(0,n.jsx)("div",{ref:l,"aria-hidden":"true",className:`absolute inset-x-0 top-0 overflow-hidden pointer-events-none ${s}`,style:{height:t,"--pane-w":`${o}px`,"--beam-w":"140px","--beam-dur":`${c.toFixed(2)}s`,"--beam-delay":`${(c/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 cd(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,s=String(e).replace(/\/+$/,"").split("/");return s.length<=t?s.join("/"):`…/${s.slice(-t).join("/")}`}function cu(){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(e=>{let{icon:t,label:s}=e;return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)(t,{size:13,className:"shrink-0"}),s]},s)})})}let cm=["newTerminal","palette","help"];function cx(e){let{onAddWorkspace:t,onOpenRemote:s,recent:l=[],homeDir:a,onOpenRecent:i}=e,{t:o}=(0,eu.s)();(0,f.B)(e=>e.pushView);let[c,d]=(0,r.useState)(!1),u=[...cm.map(e=>tc.find(t=>t.id===e)).filter(Boolean),td];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)(),t?.()},disabled:!t,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"})," / ",o("workspaces.emptyTagVibe")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:o("workspaces.emptyWordVibe")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:o("workspaces.emptyMetaVibe")}}),(0,n.jsxs)("span",{className:"empty-go",children:[o("workspaces.emptyGoVibe"),(0,n.jsx)(el.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]}),!!l.length&&(0,n.jsx)("span",{className:"flex flex-wrap gap-1.5 mt-4 max-w-full",children:l.slice(0,4).map(e=>(0,n.jsx)("span",{role:"button",title:e.path,onClick:t=>{t.stopPropagation(),(0,ed.e)(),i?.(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:cd(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)(),d(!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"})," / ",o("workspaces.emptyTagPair")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:o("workspaces.emptyWordPair")}),(0,n.jsx)("span",{className:"empty-meta",children:(0,n.jsx)(cu,{})}),(0,n.jsxs)("span",{className:"empty-go",children:[o("workspaces.emptyGoPair"),(0,n.jsx)(el.Qp,{size:14,className:"text-brand-500",strokeWidth:2.2})]})]})]}),c&&(0,n.jsx)(rQ,{onClose:()=>d(!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:u.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[o(`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:th(e)})]},e.id))})]})}let cp=[],ch=(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}},cf=e=>String(e).padStart(2,"0");function cb(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 ${cf(r)}s`:n>0?`${n}m ${cf(r)}s`:`${r}s`}function cg(e){return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),lx(e)," tokens"]}):null}let cv=(0,r.memo)(function(e){let{engine:t="claude",failed:s=!1,onRetry:r}=e,l=t2[t]||t2.claude;return s?(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:l.label}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),r?.()},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:l.label})]})}),cy=(0,r.memo)(function(e){let{sessionId:t,engine:s="",hydrating:l=!1}=e,a=lH(e=>e.bySession[t]?.isTurnRunning),i=lH(e=>e.bySession[t]?.turnStartedAt),o=lH(e=>e.bySession[t]?.lastTurnMs),c=lH(e=>e.bySession[t]?.stats),d=lH(e=>e.bySession[t]?.turnBaseline),m=(0,u.d)(e=>e.connected),x=(0,u.d)(e=>e.retryStatus),p=lH(e=>e.bySession[t]?.messages)||cp,h=p[p.length-1]||null,f=Math.max(0,(c?.outputTokens||0)-(d?.outputTokens||0)),[b,g]=(0,r.useState)(Date.now());(0,r.useEffect)(()=>{if(!a)return;g(Date.now());let e=setInterval(()=>g(Date.now()),1e3);return()=>clearInterval(e)},[a]);let[v,y]=(0,r.useState)(null),w=(0,r.useRef)(a);(0,r.useEffect)(()=>{w.current&&!a&&i&&y({ms:o||Date.now()-i,outputTokens:f,changes:lf(p)}),a&&y(null),w.current=a},[a,i,o,f,p]);let j=(0,r.useMemo)(()=>v||a||!o?null:{ms:o,outputTokens:0,changes:lf(p)},[v,a,o,p]),k=v||j;if(!a&&!k)return null;if(!a)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:cb(k.ms)})]}),(0,n.jsxs)("span",{className:"shrink-0",children:[function(e){let{added:t,removed:s}=e;return t||s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),t>0&&(0,n.jsxs)("span",{className:"text-success",children:["+",t]}),t>0&&s>0&&" ",s>0&&(0,n.jsxs)("span",{className:"text-danger",children:["−",s]})]}):null}(k.changes),cg(k.outputTokens)]})]})]});let N=h?.tools?.find(e=>"running"===e.status),C=f+function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],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)}(p),S=function(){let{connected:e=!0,hydrating:t=!1,retryStatus:s=null,activeTool:n=null,engine:r="",lastMsg:l=null}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};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=tQ(r,e),l=lo(t.file_path||t.path);switch(s){case"bash":return{verb:"Running",detail:ld(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:ld(`${l}${n}`,60),tone:"wait"}}case"search":{let e=t.pattern?`"${t.pattern}"`:t.query||t.url||"",s=lo(t.path);return{verb:"Searching",detail:ld([e,s?`in ${s}`:""].filter(Boolean).join(" "),60),tone:"wait"}}case"diff":return{verb:/^(Write|write_to_file)$/i.test(e)?"Writing":"Editing",detail:ld(lo(t.file_path||t.filePath||t.file||t.path)||lm(t),60),tone:"wait"};case"agent":{let e=n.children?.length||0;return{verb:"Delegating",detail:ld([t.description||lm(t),e?`${e} steps`:""].filter(Boolean).join(" \xb7 "),60),tone:"wait"}}case"task":return{verb:"Updating tasks",detail:ld(t.activeForm||t.subject||"",60),tone:"wait"};case"plan":return{verb:"Planning",detail:ld(lo(t.path)||e,60),tone:"wait"};default:return{verb:"Calling",detail:ld([lu(e),lm(t)].filter(Boolean).join(" "),60),tone:"wait"}}}return l?.thinking?{verb:"Thinking",detail:ld(lc(l.thinking),60),tone:"wait"}:l?.content?{verb:"Writing",detail:ld(lc(l.content),60),tone:"wait"}:{verb:"Working",detail:"",tone:"wait"}}({connected:m,hydrating:l,retryStatus:x,activeTool:N,engine:s,lastMsg:h});return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 select-none text-xs text-text-muted",children:["alert"===S.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"===S.tone?" !text-danger":""}`,children:[S.verb,"…"]}),S.detail&&(0,n.jsxs)("span",{className:"text-text-subtle",children:[" ",S.detail]}),(0,n.jsx)("span",{className:"text-text-muted/60",children:" \xb7 "}),cb(b-(i||b))]}),(0,n.jsx)("span",{className:"shrink-0",children:cg(C)})]})]})}),cw=(0,r.memo)(function(e){let{engine:t,engineMeta:s,workspacePath:l,bus:a=null,fileBus:i,onSendPrompt:o,onOpenResume:c}=e,{t:d}=(0,eu.s)(),[u,m]=(0,r.useState)([]),[x,p]=(0,r.useState)(null),h=eD(),f=r9(l,i,{enabled:!!l});(0,r.useEffect)(()=>{if(!l)return;let e=!0;return i?.getSystemInfo?.().then(t=>{e&&t?.success&&p(t.homedir||null)}).catch(()=>{}),()=>{e=!1}},[i,l]),(0,r.useEffect)(()=>{if(!l)return;let e=!0;if(a?.emit)return a.emit("getAgentSessions",{cwd:l},s=>{e&&m((Array.isArray(s?.sessions)?s.sessions:[]).filter(e=>!t||e.agent===t).slice(0,8))}),()=>{e=!1}},[l,t]);let b=l?nu(l,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:`${s.color}15`},children:(0,n.jsx)("img",{src:e8(`${t}-ui`),alt:s.label,className:`w-7 h-7 object-contain ${e6}`})}),(0,n.jsx)("h3",{className:"text-base font-semibold text-text mb-1",children:s.label}),b&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-3 text-[11px] font-mono text-text-muted",title:l,children:[(0,n.jsx)("span",{className:"truncate max-w-[220px]",children:b}),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]})]})]}),u.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:u.map(e=>{let t=!!e.openSessionId&&h.has(e.openSessionId);return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),t?window.dispatchEvent(new CustomEvent(eg.vP,{detail:{sessionId:e.openSessionId}})):c?.(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?d("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}`)})}),u.length>=8&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),c?.()},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:t6.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>o?.(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))})]})}),cj=(0,r.memo)(function(e){let{sessionId:t,engine:s="claude",workspacePath:l="",bus:a=null,fileBus:i=null,onSendPrompt:o,onResolvePermission:c,hasOlder:d=!1,onLoadOlder:u,onRewind:m,onPreviewRewind:x,onCutLocal:p,onListRewindPoints:h,onOpenResume:f,hydrating:b=!1,synced:g=!0,hydrateFailed:v=!1,onReload:y}=e,w=(0,r.useRef)(null),j=(0,r.useRef)(null),k=(0,r.useRef)(!0),N=(0,r.useRef)(null),C=(0,r.useRef)(null),S=(0,r.useRef)(null),T=(0,r.useRef)(null),E=(0,r.useRef)(0),R=(0,r.useRef)({top:0,atBottom:!0,key:""}),M=(0,r.useRef)(""),$=(0,r.useRef)(!1),[z,P]=(0,r.useState)(!1),[A,I]=(0,r.useState)(131072),[D,B]=(0,r.useState)(null),F=(0,r.useRef)({sessionId:null,n:0}),O=lH(e=>e.bySession[t]?.messages)||cp,_=t2[s]||t2.claude;(0,r.useEffect)(()=>{I(131072),B(null),T.current=null},[t]);let{id:K,index:W}=(0,r.useMemo)(()=>(function(e,t,s){if(!t?.length)return{id:null,index:0};let n=lU(t,s,void 0),r=null!=e?t.findIndex(t=>t.id===e):-1,l=lU(t,Math.max(524288,s),void 0),a=r<0?n:Math.max(r,l);return{id:t[a].id,index:a}})(D,O,A),[D,O,A]);(0,r.useEffect)(()=>{B(K)},[K]);let H=W>0?O.slice(W):O,[q,U]=(0,r.useState)(null),X=(0,r.useRef)(0);(0,r.useEffect)(()=>{U(null),X.current=0},[t]);let V=(0,r.useMemo)(()=>O.filter(e=>"user"===e.role).length,[O]);(0,r.useEffect)(()=>{if(q?.ok||q?.supported===!1||X.current>=6)return;let e=!0;return h?.().then(t=>{e&&(X.current+=1,U(t))}).catch(()=>{}),()=>{e=!1}},[h,s,t,V,q?.ok,q?.supported]);let G=!!q?.ok,J=(0,r.useMemo)(()=>{let e=new Map,t=0;for(let s=O.length-1;s>=0;s--)"user"===O[s].role&&e.set(O[s].id,t++);return e},[O]),Y=(0,r.useMemo)(()=>{let e=[];for(let t of H)"user"===t.role||0===e.length?e.push({key:t.id,messages:[t]}):e[e.length-1].messages.push(t);return e},[H]),Z=Math.max(0,Y.length-5),Q=(0,r.useCallback)(async function(){let{auto:e=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=w.current,s=Date.now();if(!e&&s-E.current<300)return;E.current=s;let n=S.current,r=n?function(){let{scrollTop:e=0,scrollHeight:t=0,clientHeight:s=0,nodeTop:n=0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{nodeTop:n,scrollTop:e,atBottom:t-e-s<8}}(ch(t,n)):null,l=r?{...r,atBottom:e&&k.current,node:n}:null,a={hiddenCount:W,hasOlder:d,scrollTop:t?.scrollTop??0,scrollHeight:t?.scrollHeight??0},i=null;0===W&&d&&(i=await u?.()),(0,L.Lq)("ai-page","loadMore",{...a,fetched:i}),T.current=l,B(null),I(e=>e+131072)},[W,d,u]);(0,r.useLayoutEffect)(()=>{let e=w.current,t=T.current;if(!e||!t)return;T.current=null;let s=function(e){let{scrollHeight:t=0,clientHeight:s=0,nodeTop:n=0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e?e.atBottom?t:n<=e.nodeTop?null:Math.max(0,n-(e.nodeTop-e.scrollTop)):null}(t,ch(e,t.node)||{});null!=s&&(e.scrollTop=s);let n=e.scrollHeight-e.scrollTop-e.clientHeight;k.current=n<8,P(n>140)},[A,D]),(0,r.useEffect)(()=>{let e=F.current;if(e.sessionId!==t&&(e.sessionId=t,e.n=0),e.n>=40||b||!g||!k.current||!(d&&O?.length)||O[W]?.role==="user")return;let s=setTimeout(()=>{e.n+=1,Q({auto:!0})},0);return()=>clearTimeout(s)},[t,O,W,d,b,g,Q]);let ee=(0,r.useCallback)(()=>{N.current||(N.current=requestAnimationFrame(()=>{N.current=null;let e=w.current;if(!e||0===e.clientHeight||$.current)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight,s=t<80;k.current=s,P(!s&&t>140),R.current={top:e.scrollTop,atBottom:s,key:M.current},e.scrollTop<120&&(W>0||d)&&Q()}))},[Q,W,d]);(0,r.useEffect)(()=>{let e=w.current,t=j.current;if(!e||!t)return;let s=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&!k.current&&Q()},{root:e,rootMargin:"120px"});return s.observe(t),()=>s.disconnect()},[Q]);let et=(0,r.useMemo)(()=>O.map(e=>`${e.id}:${+!!e.thinking}:${+!!e.content}:${e.tools?.length||0}:${e.diffs?.length||0}:${+!!e.permission}`).join("|"),[O]);(0,r.useLayoutEffect)(()=>{M.current=et},[et]);let es=(0,r.useCallback)(e=>{S.current=e},[]),en=(0,r.useRef)({id:null,pinned:!0});(0,r.useEffect)(()=>{let e=w.current,t=en.current,s=et?et.split("|").pop().split(":")[0]:null;if(!s){en.current={id:null,pinned:t.pinned};return}let n=t.pinned&&(null==t.id||!et.includes(`${t.id}:`));en.current={id:s,pinned:n||k.current},!e||(n||k.current)&&(e.scrollTop=e.scrollHeight,n&&(k.current=!0,P(!1)))},[et]);let er=(0,r.useMemo)(()=>O.reduce((e,t)=>e+(t.content?.length||0),0),[O]);(0,r.useEffect)(()=>{!k.current||C.current||(C.current=setTimeout(()=>{C.current=null;let e=w.current;e&&k.current&&(e.scrollTop=e.scrollHeight)},150))},[er]),(0,r.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]),(0,r.useEffect)(()=>{let e=w.current;if(!e)return;let t=new ResizeObserver(()=>{if(0===e.clientHeight){$.current=!0;return}let t=R.current;if(t.top>8&&!t.atBottom&&0===e.scrollTop&&t.key===M.current){e.scrollTop=Math.min(t.top,e.scrollHeight-e.clientHeight);let s=e.scrollHeight-e.scrollTop-e.clientHeight;k.current=s<8,P(s>140)}$.current=!1,k.current&&(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>t.disconnect()},[]);let ea=(0,r.useCallback)(()=>{(0,ed.e)();let e=w.current;e&&(e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),k.current=!0,P(!1))},[]),ei=(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 @container",children:[(0,n.jsxs)("div",{ref:w,onScroll:ee,className:"ai-conversation flex-1 min-h-0 overflow-y-auto px-3 @2xl:px-6 py-4 space-y-4 custom-scrollbar relative",children:[(W>0||d)&&(0,n.jsx)("div",{ref:j,"aria-hidden":"true",className:"h-px"}),0===O.length?g?(0,n.jsx)(cw,{engine:s,engineMeta:_,workspacePath:l,bus:a,fileBus:i,onSendPrompt:o,onOpenResume:f}):(0,n.jsx)(cv,{engine:s,failed:v,onRetry:y}):(0,n.jsxs)(n.Fragment,{children:[(W>0||d)&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),Q()},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:W>0?`Load older \xb7 ${W} more`:"Load older turns"}),Y.map((e,t)=>{let[r,...a]=e.messages;return"user"!==r.role?(0,n.jsx)("div",{ref:0===t?es:void 0,children:(0,n.jsx)(aJ,{messages:e.messages,engine:s,workspacePath:l,onResolvePermission:c,isLive:ei(e),fileBus:i,showImages:t>=Z})},e.key):(0,n.jsxs)("div",{ref:0===t?es:void 0,children:[(0,n.jsx)(an,{message:r,engine:s,workspacePath:l,onResolvePermission:c,onRewind:m,onPreviewRewind:x,onCutLocal:p,rewindIndex:J.get(r.id),canRewind:G}),(0,n.jsx)(aJ,{messages:a,engine:s,workspacePath:l,onResolvePermission:c,isLive:ei(e),fileBus:i,showImages:t>=Z})]},e.key)}),(0,n.jsx)(cy,{sessionId:t,engine:s,hydrating:b})]})]}),z&&(0,n.jsx)("button",{type:"button",onClick:ea,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 ck(e){return e.provider?e.provider:e.id&&e.id.includes("/")?e.id.split("/")[0]:""}function cN(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=ck(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 cC=new Map,cS=new Map,cT=(e,t)=>new Promise(s=>{e.emit("ai:files",t,e=>s(e?.ok?e:null))});function cE(e){if(!e)return null;let t=new Set(e.modified||[]);return{files:(e.paths||[]).map((e,s)=>({path:e,isModified:t.has(s)})),dirs:e.dirs||[],truncated:!!e.truncated}}let cR=(0,r.memo)(function(e){let{item:t}=e,s=t.label.lastIndexOf("/"),r=-1===s?"":t.label.slice(0,s+1),l=-1===s?t.label:t.label.slice(s+1),a=new Set(t.positions||[]),i=(e,t)=>[...e].map((e,s)=>a.has(t+s)?(0,n.jsx)("span",{className:"text-accent font-semibold",children:e},t+s):(0,n.jsx)("span",{children:e},t+s));return(0,n.jsxs)("span",{className:"font-mono text-xs min-w-0 flex flex-1 items-baseline",children:[(0,n.jsx)("span",{className:"min-w-0 truncate text-text-muted",style:{direction:"rtl",unicodeBidi:"plaintext"},children:i(r,0)}),(0,n.jsxs)("span",{className:`shrink-0 ${t.isDir?"text-brand-500":"text-text"}`,children:[i(l,r.length),t.isDir?"/":""]})]})}),cM=[],c$=(0,r.memo)(function(e){let{sessionId:t="",engine:s="claude",bus:l=null,isTurnRunning:a=!1,isFocused:i=!1,onSend:o,onRemoveQueueItem:c,onClearQueue:d,onStop:u,onRunShell:m,onResolvePermission:x,onSelectModel:p,onModeChange:h,onOpenModal:f,onOptionChange:b,onActivate:g,workspacePath:v="",model:y="",modalOpen:w=!1}=e,{t:j,locale:k}=(0,eu.s)(),N="mouse"===sj(),C=tp()?"Opt ←/→ \xb7 Opt 1…9 to switch tab":"Ctrl+Shift+←/→ \xb7 1…9 to switch tab",S=tZ(s),T=S.permissionModes,E=S.slashCommands,R=lH(e=>e.bySession[t]?.isTurnRunning),M=lH(e=>e.bySession[t]?.metadata?.model),$=lH(e=>e.bySession[t]?.metadata?.modelOptions),z=$?.length?$:S.models,P=lH(e=>e.bySession[t]?.metadata?.skills)||cM,A=lH(e=>e.bySession[t]?.metadata?.commands)||cM,I=lH(e=>e.bySession[t]?.permissionMode),D=lH(e=>e.bySession[t]?.metadata?.effort||e.bySession[t]?.metadata?.variant),L=I||S.defaultMode,B=void 0!==R?R:a,F=void 0!==M?M:y,[O,_]=(0,r.useState)(""),K=lH(e=>e.bySession[t]?.queue)||cM,W=lH(e=>e.bySession[t]?.promptError)||null,H=lH(e=>e.bySession[t]?.promptSending)||null,[q,U]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(U(!1),!H)return;let e=setTimeout(()=>U(!0),1500);return()=>clearTimeout(e)},[H]);let[X,V]=(0,r.useState)(-1),G=(0,r.useRef)(""),[J,Y]=(0,r.useState)(!1),[Z,Q]=(0,r.useState)(null),[ee,et]=(0,r.useState)([]),[es,en]=(0,r.useState)(0),[er,ea]=(0,r.useState)(null),[ei,eo]=(0,r.useState)(-1),[ec,em]=(0,r.useState)(0),ex=sa(e=>e.addCommand),ep=sa(e=>e.resolveAlias),eh=sa(e=>e.history),ef=sa(e=>e.pinned),eb=(0,r.useMemo)(()=>J?[]:sm(O,eh,ef,[],!N),[O,eh,ef,N,J]),[eg,ev]=(0,r.useState)(!1),[ey,ew]=(0,r.useState)(""),[ej,ek]=(0,r.useState)(()=>new Set),[eN,eC]=(0,r.useState)(!1),[eS,eT]=(0,r.useState)(!1),eE=(0,r.useRef)(null),{attachments:eR,setAttachments:eM,removeAttachment:e$,handleFileUpload:ez,handleAttachPaste:eP}=s$({bus:l,sessionId:t}),[eA]=sb(k),eI=sy({lang:sh(eA),onText:e=>{_(e),eO.current&&(eO.current.value=e,eO.current.style.height="auto",eO.current.style.height=`${Math.min(eO.current.scrollHeight,120)}px`,eO.current.focus())}}),eD=(0,r.useCallback)(()=>{(0,ed.e)(),eI.stop()},[eI]),eL=(0,r.useCallback)(()=>{eI.cancel()},[eI]),eB=(0,r.useCallback)(()=>{eI.listening?eI.stop():(document.activeElement?.blur(),eI.start(O))},[eI,O]),eF=(0,r.useCallback)(()=>{(0,ed.e)(),_(""),eO.current&&(eO.current.value="",eO.current.style.height="26px");try{localStorage.removeItem(`9remote_draft_${t}`)}catch{}eO.current?.focus()},[t]),eO=(0,r.useRef)(null),e_=(0,r.useRef)(eR);(0,r.useEffect)(()=>{e_.current=eR},[eR]);let eK=(0,r.useRef)(null),eW=(0,r.useRef)(!1),eH=(0,r.useRef)(0),eq=(0,r.useRef)(0),eU=(0,r.useRef)(0),eX=(0,r.useRef)("");t2[s]||t2.claude,(0,r.useEffect)(()=>{i&&!w&&N&&eO.current?.focus({preventScroll:!0})},[i,w,N]),(0,r.useEffect)(()=>{let e=e=>{if(e.detail?.sessionId!==t)return;let s=String(e.detail.text||"");if(s&&(_(e=>e===s||e.includes(s)?e:e?`${e}
18
+ ${s}`:s),eO.current&&!eO.current.value.includes(s))){let e=eO.current.value?`${eO.current.value}
19
+ ${s}`:s;eO.current.value=e,eO.current.style.height="auto",eO.current.style.height=`${Math.min(eO.current.scrollHeight,120)}px`,eO.current.focus()}};return window.addEventListener("9r:ai-prompt",e),()=>window.removeEventListener("9r:ai-prompt",e)},[t]),(0,r.useEffect)(()=>{let e=e=>{eE.current&&!eE.current.contains(e.target)&&(ev(!1),eC(!1))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,r.useEffect)(()=>{B&&(ev(!1),eC(!1))},[B]),(0,r.useEffect)(()=>{let e=eO.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)},[O]),(0,r.useEffect)(()=>{if(!J||!eK.current)return;let e=eK.current.querySelectorAll("[data-menu-item]")[es];e&&e.scrollIntoView({block:"nearest"})},[es,J]),(0,r.useEffect)(()=>{if(t){eM([]);try{_(localStorage.getItem(`9remote_draft_${t}`)||"")}catch{}}},[t,eM]),(0,r.useEffect)(()=>{if(!t)return;let e=setTimeout(()=>{try{O?localStorage.setItem(`9remote_draft_${t}`,O):localStorage.removeItem(`9remote_draft_${t}`)}catch{}},300);return()=>clearTimeout(e)},[O,t]),(0,r.useEffect)(()=>{if(er){let e=er.name.replace(/[/@]/g,"\\$&");if(RegExp(`(?:^|\\s)${e}\\s*$`).test(O))return;ea(null)}let e=s2(O,ec);if(!e){Y(!1),Q(null);return}let{trigger:t,query:s}=e,n=s.toLowerCase();if(Q(t),en(0),"/"===t){let e=function(){let{staticCommands:e=[],liveCommands:t=[],skills:s=[],filter:n=""}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},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:E,liveCommands:A,skills:P,filter:n});et(e),Y(e.length>0);return}let r=!1,a=setTimeout(async()=>{var e;let t;if(!v){et([]),Y(!1);return}let n=await function(e,t){if(!e?.emit||!t)return Promise.resolve(null);let s=cC.get(t);if(s&&Date.now()-s.at<3e4)return Promise.resolve(s.index);let n=cS.get(t);if(n)return n;let r=cT(e,{workspace:t}).then(e=>{cS.delete(t);let s=cE(e);return s&&cC.set(t,{index:s,at:Date.now()}),s});return cS.set(t,r),r}(l,v);if(r)return;if(!n){et([]),Y(!1);return}let a=s0(n,s,10),i=a[0],o=i&&!i.isDir&&(-1===(t=(e=i.path).lastIndexOf("/"))?e:e.slice(t+1)).toLowerCase().startsWith(s.toLowerCase());if(n.truncated&&s.length>=2&&!o){let e=await (!l?.emit||!v||!s?Promise.resolve(null):cT(l,{workspace:v,query:s}).then(cE));if(r)return;if(e){let t=s0(e,s,10),n=new Set(a.map(e=>e.path));a=[...a,...t.filter(e=>!n.has(e.path))].sort((e,t)=>t.score-e.score||e.path.length-t.path.length).slice(0,10)}}et(a.map(e=>({name:e.path,label:e.path,isDir:e.isDir,isModified:e.isModified,positions:e.positions}))),Y(a.length>0)},100);return()=>{r=!0,clearTimeout(a)}},[O,ec,l,v,P,A,E,er]);let eV=(0,r.useCallback)(e=>{let s="string"==typeof e?e:eO.current?eO.current.value:O,n=ep((s||O).trim()),r=e_.current;if(!n&&0===r.length)return;let l=Date.now();if(l-eq.current<250)return;eq.current=l,eU.current=l,eX.current=(s||O).trim(),(0,ed.e)(),n&&!n.startsWith("!")&&ex(n),V(-1),_(""),eO.current&&(eO.current.value="",eO.current.style.height="26px");try{localStorage.removeItem(`9remote_draft_${t}`)}catch{}if(n.startsWith("!"))return void m?.(n.slice(1).trim());let a=lH.getState().bySession[t]?.activePermission;a&&x?.(a.requestId,t8,t9),r.length&&eM([]),o?.(n,{attachments:r.map(e=>{let{name:t,type:s,content:n}=e;return{filename:t,type:s,content:n}})})},[O,t,o,m,x,eM,ex,ep]),eG=e=>Date.now()-eU.current<200&&!!e?.trim()&&e.trim()===eX.current,eJ=(0,r.useCallback)(()=>{(0,ed.e)(),u?.()},[u]),eY=(0,r.useCallback)(()=>{let e=lH.getState().bySession[t]?.promptError;e&&((0,ed.e)(),lH.getState().clearPromptError(t),l0(t,e.text),o?.(e.text,{attachments:e.attachments||null,promptId:e.promptId||null}))},[t,o]),eZ=(0,r.useCallback)(()=>{let e=lH.getState().bySession[t]?.promptError;e&&(lH.getState().clearPromptError(t),l0(t,e.text),_(t=>t.trim()?`${e.text}
20
+ ${t}`:e.text),requestAnimationFrame(()=>eO.current?.focus()))},[t]),eQ=(0,r.useCallback)(()=>{let e=lH.getState().bySession[t]?.promptError;e&&l0(t,e.text),lH.getState().clearPromptError(t)},[t]),e0=(0,r.useCallback)(e=>{let t=e.action||"send",[s,n]=t.split(":");if("modal"===s){eO.current?.blur(),f?.(n);return}if("clear"===s){o?.("/clear",{force:!0}),_("");return}if("setMode"===s){h?.(e.mode),_("");return}if("send"===s||"send"===t){o?.(e.name),_("");return}eO.current?.focus()},[f,o,h]),e1=(0,r.useCallback)(e=>{let t;(0,ed.e)();let s=s2(O,ec);if(!s)return;let n=O.slice(0,s.start),r=O.slice(s.end),l="/"===Z&&e.action?.startsWith("modal:");if(t="@"===Z?e.isDir?`@${s5(e.name)}/`:`@${s5(e.name)} `:`${e.name} `,_(l?n+r:`${n}${t}${r}`),!l){let e=n.length+t.length;em(e),requestAnimationFrame(()=>{let t=eO.current;t&&t.setSelectionRange(e,e)})}(Y(!1),"/"!==Z)?eO.current?.focus():"submenu"===e.action&&Array.isArray(e.subOptions)&&e.subOptions.length>0?B&&("effort"===e.optionKey||"variant"===e.optionKey)?_(""):(ea(e),en(0),Y(!0)):e0(e)},[O,ec,Z,e0,B]),e2=(0,r.useCallback)(e=>{(0,ed.e)(),er&&(b?.(er.optionKey,e.value),ea(null),Y(!1),_(""),eO.current?.focus())},[er,b]),e5=(0,r.useCallback)(e=>{(0,ed.e)();let t=/(?:^|\s)(\S*)$/.exec(O),s=t?t[1]:"";_(O.slice(0,O.length-s.length)+e),eo(-1),eO.current?.focus()},[O]),e3=e=>String(e||"").toLowerCase().replace(/\[[^\]]*\]$/,""),e4=(0,r.useMemo)(()=>{if(!F)return null;let e=z||[],t=e3(F);return e.find(e=>e.id===F)||e.find(e=>e3(e.id)===t)||e.find(e=>e3(e.id).split("/").pop()===t.split("/").pop())||null},[F,z]),e9=e4?.short||e4?.label||F||"Model",e7=D||S.defaultEffort||"",te=(0,r.useMemo)(()=>{let e=[...z||[]];return F&&!e.some(e=>e.id===F)&&e.unshift({id:F,label:F,short:F}),e},[z,F]),tt=(0,r.useMemo)(()=>{if(te.length<=20)return te;let e=ey.trim().toLowerCase();return e?te.filter(t=>{let s=(t.id||"").toLowerCase();return(t.label||"").toLowerCase().includes(e)||s.includes(e)||(t.provider||"").toLowerCase().includes(e)}):te},[te,ey]),ts=(0,r.useMemo)(()=>te.length<=20?[{key:"all",title:"",items:te}]:cN(te,tt,F,ey.trim()),[te,tt,F,ey]),tn=(0,r.useMemo)(()=>(E||[]).find(e=>"submenu"===e.action&&("effort"===e.optionKey||"variant"===e.optionKey)),[E]),tr=(0,r.useMemo)(()=>{let e=(e4?.efforts||[]).map(e=>({value:e,label:e}));return e.length>0?e:tn?.subOptions||[]},[tn,e4]);return(0,n.jsxs)("div",{className:"relative px-3 py-1.5 bg-transparent select-none",children:[q&&H&&!W&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1 px-2.5 py-1.5 text-xs rounded-brand bg-brand-500/10 border border-brand-500/25",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand-500 animate-pulse shrink-0"}),(0,n.jsx)("span",{className:"shrink-0 font-medium text-brand-500",children:j("common.sending")}),(0,n.jsx)("span",{className:"truncate min-w-0 text-text-muted",children:H.text})]}),W&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1 px-2.5 py-1.5 text-xs bg-danger/10 border border-danger/30 rounded-brand",children:[(0,n.jsx)(el.RI,{size:13,className:"shrink-0 text-danger"}),(0,n.jsxs)("span",{className:"truncate min-w-0 text-text",title:W.text,children:["reload"===W.reason?j("common.promptRecovered"):`${j("common.promptNotSent")}${W.reason&&"timeout"!==W.reason?`: ${W.reason}`:""}`,W.text?(0,n.jsxs)("span",{className:"text-text-muted",children:[" — ",W.text]}):null]}),(0,n.jsxs)("button",{type:"button",onClick:eY,className:"shrink-0 inline-flex items-center gap-1 px-2 py-1 text-[11px] font-semibold text-white bg-brand-500 hover:bg-brand-600 rounded-brand transition-colors",children:[(0,n.jsx)(el.kt,{size:11}),j("common.resend")]}),(0,n.jsx)("button",{type:"button",onClick:eZ,className:"shrink-0 px-2 py-1 text-[11px] text-text-muted hover:text-text border border-border-subtle rounded-brand transition-colors",children:j("common.edit")}),(0,n.jsx)("button",{type:"button",onClick:eQ,className:"shrink-0 text-text-muted hover:text-text",children:(0,n.jsx)(el.X,{size:11})})]}),J&&er&&(0,n.jsxs)("div",{ref:eK,className:"absolute left-3 right-3 bottom-[calc(100%+6px)] max-h-52 menu-popover 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:[er.name," — ",er.optionKey]}),(0,n.jsx)("button",{type:"button",onClick:()=>{ea(null),Y(!1),_("")},className:"text-text-muted hover:text-text",children:(0,n.jsx)(el.X,{size:11})})]}),(er.subOptions||[]).map((e,t)=>(0,n.jsxs)("div",{"data-menu-item":"true",onClick:()=>e2(e),onMouseEnter:()=>en(t),className:`px-2 py-1 rounded-brand flex items-center justify-between text-xs cursor-pointer ${t===es?"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))]}),J&&!er&&ee.length>0&&(0,n.jsxs)("div",{ref:eK,className:"absolute left-3 right-3 bottom-[calc(100%+6px)] max-h-52 menu-popover 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:"/"===Z?"Slash Commands & Skills":"Files in repo (@)"}),ee.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:()=>e1(e),onMouseEnter:()=>en(t),className:`px-2 py-1 rounded-brand flex items-center justify-between text-xs ${s?"opacity-40 cursor-not-allowed":t===es?"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 min-w-0",children:[e.isSkill?(0,n.jsx)(el.Kq,{size:12,className:"text-warning shrink-0"}):"/"===Z?(0,n.jsx)(el.BK,{size:12,className:"text-accent shrink-0"}):e.isDir?(0,n.jsx)(el.vd,{size:12,className:"text-brand-500 shrink-0"}):(0,n.jsx)(el.GD,{size:12,className:"text-accent shrink-0"}),"@"!==Z||e.isSkill?(0,n.jsx)("span",{className:"font-mono text-xs text-text",children:e.name}):(0,n.jsx)(cR,{item:e}),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&&"@"!==Z&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted truncate ml-2 max-w-[50%]",children:e.description}),"@"===Z&&!e.isSkill&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[e.isModified&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-warning",title:"modified"}),e.isDir&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted font-mono",children:"/"})]})]},e.name)})]}),K.length>0&&(0,n.jsx)("div",{className:"mb-1 space-y-0.5",children:K.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)(),eJ()},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)(),c?.(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)(sH,{voice:eI,onDone:eD,onCancel:eL,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:[eR.length>0&&(0,n.jsx)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x pt-0.5",children:eR.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:()=>e$(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)(sx,{value:O,store:sa,isMobile:!N,activeIndex:ei,onSelect:e5}),(0,n.jsxs)("div",{className:"flex items-start gap-1",children:[(0,n.jsx)("textarea",{ref:eO,value:O,onPaste:eP,onChange:e=>{if(eG(e.target.value)){eO.current&&(eO.current.value="");return}_(e.target.value),em(e.target.selectionStart??e.target.value.length),eo(-1)},onFocus:()=>g?.(),onSelect:e=>em(e.currentTarget.selectionStart),onKeyUp:e=>{(e.key.startsWith("Arrow")||"Home"===e.key||"End"===e.key)&&em(e.currentTarget.selectionStart)},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&&h?.(n)}return}if((e.ctrlKey||e.metaKey)&&("c"===e.key||"C"===e.key)&&B){let t=eO.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),eJ();return}}if("Escape"===e.key){if(er){e.preventDefault(),ea(null),Y(!1),_("");return}if(J){e.preventDefault(),Y(!1);return}if(B){e.preventDefault(),eJ();return}if(K.length>0){e.preventDefault(),d?.();return}}if(er){let t=er.subOptions||[];if("ArrowDown"===e.key){e.preventDefault(),en(e=>(e+1)%t.length);return}if("ArrowUp"===e.key){e.preventDefault(),en(e=>(e-1+t.length)%t.length);return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),e2(t[es]);return}}if(J&&ee.length>0){if("ArrowDown"===e.key){e.preventDefault(),en(e=>(e+1)%ee.length);return}if("ArrowUp"===e.key){e.preventDefault(),en(e=>(e-1+ee.length)%ee.length);return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),e1(ee[es]);return}}if(eb.length>0){let t=ei<0?-1:(ei%eb.length+eb.length)%eb.length;if("Tab"===e.key&&!e.shiftKey){e.preventDefault(),eo(-1===t?0:(t+1)%eb.length);return}if(("Enter"===e.key||"Tab"===e.key)&&-1!==t){e.preventDefault(),e5(eb[t].cmd);return}}let t=eO.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&&!er&&!J&&r&&eh.length>0){if(e.preventDefault(),s>0)return void t?.setSelectionRange(0,0);-1===X&&(G.current=O);let n=Math.min(X+1,eh.length-1);return void(n===X||(V(n),_(eh[n])))}if("ArrowDown"===e.key&&!er&&!J&&l&&-1!==X){if(e.preventDefault(),s<n.length)return void t?.setSelectionRange(n.length,n.length);let r=X-1;return void(r<0?(V(-1),_(G.current)):(V(r),_(eh[r])))}if("Enter"===e.key&&(e.metaKey||e.ctrlKey)){e.preventDefault(),eV();return}"Enter"===e.key&&!e.shiftKey&&N&&(e.preventDefault(),eV())},onCompositionStart:()=>{eW.current=!0},onCompositionEnd:()=>{eW.current=!1,eH.current=Date.now(),eG(eO.current?.value)&&(eO.current&&(eO.current.value=""),_(""))},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]"}),O.trim().length>0?(0,n.jsx)("button",{type:"button",onClick:eF,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)(),eT(!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-1",children:[(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:(0,n.jsxs)("div",{ref:eE,className:"relative min-w-0 flex items-center gap-1",children:[(0,n.jsxs)("button",{type:"button",disabled:B,onClick:()=>{ev(!eg),eg||ew(""),eC(!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:e8(`${s}-ui`),alt:"",className:`w-3.5 h-3.5 object-contain shrink-0 ${e6}`}),(0,n.jsx)("span",{dir:"rtl",className:"truncate min-w-0",children:(0,n.jsx)("bdi",{children:e9})}),(0,n.jsx)(el.rX,{size:11,className:`text-text-muted shrink-0 transition-transform ${eg?"":"rotate-180"}`})]}),eg&&(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"}),te.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:ey,onChange:e=>ew(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===tt.length&&(0,n.jsxs)("div",{className:"px-2 py-2 text-[11px] text-text-muted",children:['No models match "',ey,'"']}),ts.map(e=>(0,n.jsxs)("div",{children:[ts.length>1&&(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.key,void ek(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},"aria-expanded":!ej.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:ej.has(e.key)?"▶":"▼"}),e.title]}),(0,n.jsx)("span",{className:"text-[9px] text-text-subtle",children:e.items.length})]}),!ej.has(e.key)&&e.items.map(e=>{let t=F===e.id;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),p?.(e.id),ev(!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))]}),tr.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",disabled:B,onClick:()=>{eC(e=>!e),ev(!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 ${tn?.optionKey||"effort"} while turn is running`:`Select ${tn?.optionKey||"effort"}`,children:e7||"—"}),eN&&(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:tn?.optionKey==="variant"?"Variant":"Reasoning effort"}),tr.map(e=>{let t=e7===e.value;return(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),b?.(tn?.optionKey||"effort",e.value),eC(!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:ez,className:"hidden",accept:"*/*"})]}),eI.active&&(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:eB,title:j("not-allowed"===eI.error||"service-not-allowed"===eI.error?"voice.denied":"voice.dictate"),"aria-label":j("voice.dictate"),className:`p-1.5 rounded flex items-center justify-center transition-colors ${eI.listening?"bg-red-500/90 text-white animate-pulse":eI.error?"text-red-400":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:eI.listening?(0,n.jsx)(el.jj,{size:15}):(0,n.jsx)(el.GO,{size:15})}),B?(0,n.jsxs)(n.Fragment,{children:[(O.trim()||eR.length>0)&&(0,n.jsxs)("button",{type:"button",onClick:eV,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:eJ,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:K.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:eV,disabled:!O.trim()&&0===eR.length,className:`px-2 py-1 rounded transition-colors flex items-center justify-center ${O.trim()||eR.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)(so,{isOpen:eS,store:sa,onSelect:e5,onClose:()=>eT(!1)})]})}),cz={Shield:"text-text-muted",Pencil:"text-accent",Eye:"text-accent",Sparkles:"text-warning"},cP=(0,r.memo)(function(e){let{sessionId:t="",sessionName:s="",engine:l="claude",workspacePath:a="",fileBus:i=null,isTurnRunning:o=!1,isDesktop:c=!0,onModeChange:d,onNewChat:u}=e,m=lH(e=>e.bySession[t]?.isTurnRunning),x=lH(e=>e.bySession[t]?.metadata),p=x?.goal,h=tZ(l).permissionModes||[],f=lH(e=>e.bySession[t]?.permissionMode)||tZ(l).defaultMode,{branch:b,dirty:g}=r9(a,i,{enabled:!!i&&!!a}),[v,y]=(0,r.useState)(!1),w=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=e=>{w.current&&!w.current.contains(e.target)&&y(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let j=h.find(e=>e.id===f)||h[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${c?"":" safe-area-bottom"}`,children:[(void 0!==m?m:o)&&(0,n.jsx)(cc,{className:"hidden sm:block"}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[j&&h.length>0&&(0,n.jsxs)("div",{ref:w,className:"relative",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),y(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:j.icon||"Shield",size:11,className:`${cz[j.icon]||"text-text-muted"} shrink-0`}),(0,n.jsx)("span",{children:j.label}),(0,n.jsx)(el.rX,{size:11,className:`text-text-muted transition-transform ${v?"":"rotate-180"}`})]}),v&&(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"}),h.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),d?.(e.id),y(!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:`${cz[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))]})]}),p?.objective&&(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",title:`Goal (${p.status}): ${p.objective}`,children:[(0,n.jsx)(el.We,{size:11,className:`shrink-0 ${"active"===p.status?"text-danger":"text-text-muted"}`}),(0,n.jsx)("span",{className:"truncate max-w-[22ch]",children:p.objective})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2.5 shrink-0",children:[b&&!(0,eg.ok)(b)&&(0,n.jsx)(r7,{branch:b,dirty:g,size:11,className:"text-text font-medium",iconClassName:"text-brand-500 opacity-100"}),(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),u?.(t)},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})})]})]})}),cA=(0,r.memo)(function(e){let{skills:t=[],onClose:s,onSelectSkill:l}=e,[a,i]=(0,r.useState)(""),o=t.filter(e=>{let t=a.toLowerCase();return(e.name||e.id||"").toLowerCase().includes(t)||(e.description||"").toLowerCase().includes(t)});return(0,n.jsxs)(rn,{icon:(0,n.jsx)(el.Kq,{size:14}),title:`Agent Skills (${t.length})`,subtitle:"Skills loaded from ~/.claude/skills and project directory",onClose:s,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:a,onChange:e=>i(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===o.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===t.length?"No skills discovered on host agent.":`No skills matching "${a}".`})]}):o.map(e=>(0,n.jsxs)("div",{onClick:()=>{(0,ed.e)(),l?.(e.name||e.id),s?.()},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))})]})}),cI=(0,r.memo)(function(e){let{mcpServers:t=[],onClose:s}=e;return(0,n.jsx)(rn,{icon:(0,n.jsx)(el.lP,{size:14}),title:`MCP Servers (${t.length})`,subtitle:"Model Context Protocol tools and integrations",onClose:s,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:0===t.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."})]}):t.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))})})}),cD=(0,r.memo)(function(e){let{currentModel:t="",currentEffort:s="",models:l=[],onClose:a,onSelectModel:i,onSelectEffort:o,isTurnRunning:c=!1}=e,[d,u]=(0,r.useState)(""),[m,x]=(0,r.useState)(t),[p,h]=(0,r.useState)(()=>new Set),f=(0,r.useMemo)(()=>{let e=[...l||[]];return t&&!e.some(e=>e.id===t)&&e.unshift({id:t,label:t,desc:"Active CLI model",recent:!0}),e},[l,t]),b=f.find(e=>e.id===m),g=b?.efforts||[],v=(0,r.useMemo)(()=>{let e=d.trim().toLowerCase();return e?f.filter(t=>{let s=(t.label||"").toLowerCase(),n=(t.id||"").toLowerCase(),r=(t.desc||"").toLowerCase(),l=ck(t).toLowerCase();return s.includes(e)||n.includes(e)||r.includes(e)||l.includes(e)}):f},[f,d]),y=(0,r.useMemo)(()=>cN(f,v,t,d.trim()),[f,v,t,d]);return(0,n.jsxs)(rn,{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:a,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:d,onChange:e=>u(e.target.value),placeholder:"Search models...",className:"w-full bg-transparent text-xs text-text placeholder-text-muted/70 focus:outline-none",autoFocus:!0}),d&&(0,n.jsx)("button",{type:"button",onClick:()=>u(""),className:"text-text-muted hover:text-text shrink-0 text-xs px-1","aria-label":"Clear search",children:"✕"})]})}),g.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:g.map(e=>(0,n.jsx)("button",{type:"button",disabled:c,onClick:()=>{(0,ed.e)(),o?.(e)},className:`px-2.5 py-1 rounded-brand text-[11px] font-mono border transition-colors ${s===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:c?"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===v.length?(0,n.jsxs)("div",{className:"py-8 text-center text-xs text-text-muted",children:['No models found matching "',d,'"']}):y.map(e=>(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 mb-2",children:[y.length>1&&(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.key,void h(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},"aria-expanded":!p.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:p.has(e.key)?"▶":"▼"}),e.title]}),(0,n.jsx)("span",{className:"text-text-subtle text-[9px]",children:e.items.length})]}),!p.has(e.key)&&e.items.map(t=>{var r;let l=m===t.id,a=ck(t),d=(r=t.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:c?void 0:()=>(e=>{(0,ed.e)(),i?.(e),x(e);let t=f.find(t=>t.id===e),n=t?.efforts||[];if(n.length>0&&!n.includes(s)){let e=t?.defaultEffort||n[0];e&&o?.(e)}})(t.id),"data-selected":l,className:`modal-row ml-2 ${c?"opacity-40 cursor-not-allowed pointer-events-none":""}`,title:c?"Cannot change model while turn is running":t.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:t.label||t.id}),"opencode"===a&&(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}),t.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"})]}),(t.desc||t.label!==t.id&&t.id)&&(0,n.jsx)("div",{className:"text-[10px] font-mono text-text-subtle truncate mt-0.5",children:t.desc||t.id})]}),l&&(0,n.jsx)(el.aJ,{size:14,className:"text-text shrink-0"})]},`${e.key}-${t.id}`)})]},e.key))})]})}),cL=(0,r.memo)(function(e){let{engine:t="claude",workspacePath:s="",bus:l=null,onClose:a,onResume:i}=e,[o,c]=(0,r.useState)([]),[d,u]=(0,r.useState)(!0),[m,x]=(0,r.useState)(""),p=eD(),h=(0,r.useCallback)(()=>{if(!l?.emit||!s){c([]),u(!1);return}u(!0),l.emit("getAgentSessions",{cwd:s},e=>{c(Array.isArray(e?.sessions)?e.sessions:[]),u(!1)})},[s]);(0,r.useEffect)(()=>{h()},[h]);let f=(0,r.useMemo)(()=>{let e=m.toLowerCase();return o.filter(e=>!t||e.agent===t).filter(t=>!e||(t.title||"").toLowerCase().includes(e)||(t.sessionId||"").toLowerCase().includes(e))},[o,t,m]);return(0,n.jsxs)(rn,{icon:(0,n.jsx)(el.BZ,{size:14}),title:"Resume a session",subtitle:`Past ${t} conversations in this project`,maxWidth:"max-w-xl",onClose:a,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:m,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:h,className:"hover:text-text shrink-0",title:"Refresh",children:(0,n.jsx)(el.e9,{size:13,className:d?"animate-spin":""})})]})}),(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:d?(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===o.length?"No past conversations found for this project.":`No sessions matching "${m}".`})]}):f.map(e=>{let t=!!e.openSessionId&&p.has(e.openSessionId);return(0,n.jsxs)("div",{onClick:()=>{if((0,ed.e)(),t){window.dispatchEvent(new CustomEvent(eg.vP,{detail:{sessionId:e.openSessionId}})),a?.();return}(0,ed.e)(),i?.(e),a?.()},className:"modal-row",title:e.sessionId,children:[(0,n.jsx)("img",{src:e8("ui"===e.mode?`${e.agent}-ui`:e.agent),alt:e.agent,className:`shrink-0 ${e6} ${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}`)})})]})}),cB={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"},...t$],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 cF(e){return cB[e]||{shape:"flat",items:[]}}let cO=(0,r.memo)(function(e){let{engine:t="claude",options:s,onClose:l,onApply:a}=e,{shape:i,items:o}=cF(t),[c,d]=(0,r.useState)(()=>{let e,n;return e=cF(t).items,n=s||{},Object.fromEntries(e.map(e=>[e.key,void 0!==n[e.key]?n[e.key]:e.default]))}),u=(e,t)=>d(s=>({...s,[e]:t}));return(0,n.jsx)(rn,{icon:(0,n.jsx)(el.wB,{size:14}),title:"Configuration",subtitle:`Runtime flags for ${t}`,maxWidth:"max-w-md",onClose:l,footer:o.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:l,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 o){let s=c[t.key];"list"===t.kind?e[t.key]=String(s||"").split(",").map(e=>e.trim()).filter(Boolean):e[t.key]=s}a?.("flags"===i?{flags:e}:e),l?.()},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===o.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 ",t,"."]})]}):o.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:!!c[e.key],onChange:()=>u(e.key,!c[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)(),u(e.key,t.value)},className:`px-2.5 py-1 rounded-brand text-[11px] border transition-colors ${c[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(c[e.key])?c[e.key].join(", "):c[e.key]||"",onChange:t=>u(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))})})}),c_={Shield:"text-text-muted",Pencil:"text-accent",Eye:"text-accent",Sparkles:"text-warning"},cK=(0,r.memo)(function(e){let{modes:t=[],currentMode:s="",onClose:r,onSelectMode:l}=e;return(0,n.jsx)(rn,{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:r,children:(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto flex flex-col gap-0.5 custom-scrollbar",children:t.map(e=>{let t=s===e.id;return(0,n.jsxs)("div",{onClick:()=>{var t;return t=e.id,void((0,ed.e)(),l?.(t),r?.())},"data-selected":t,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:`${c_[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})]})]}),t&&(0,n.jsx)(el.aJ,{size:14,className:"text-brand-500 shrink-0"})]},e.id)})})})}),cW=(0,r.memo)(function(e){let{engine:t="claude",workspacePath:s="",bus:l=null,onClose:a}=e,[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(!0),u=(0,r.useCallback)(()=>{if(!l?.emit){o({error:"Not connected to the host agent."}),d(!1);return}d(!0),l.emit("ai:doctor",{engine:t,cwd:s},e=>{o(e?.ok?{output:e.output||"",version:e.version||""}:{error:e?.error||"Doctor check failed."}),d(!1)})},[t,s]);return(0,r.useEffect)(()=>{u()},[u]),(0,n.jsxs)(rn,{icon:(0,n.jsx)(el.mN,{size:14}),title:"Diagnostics",subtitle:`Health check for the ${t} CLI`,onClose:a,children:[(0,n.jsx)("div",{className:"p-3 flex-1 overflow-y-auto custom-scrollbar",children:c?(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 ",t," doctor..."]})]}):i?.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:i.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:i?.version?`${t} ${i.version}`:`${t} 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:i?.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:u,disabled:c,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:c?"animate-spin":""}),(0,n.jsx)("span",{children:"Re-run"})]})})]})}),cH={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"}},cq=(0,r.memo)(function(e){let{tasks:t=[],onClose:s}=e,r=t.length,l=t.filter(e=>"completed"===e.status).length,a=t.filter(e=>"in_progress"===e.status).length,i=r-l-a;return(0,n.jsxs)(rn,{icon:(0,n.jsx)(el.y8,{size:14}),title:`Tasks (${r})`,subtitle:"Checklist the agent is working through",onClose:s,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:r,cls:"text-text"},{label:"RUNNING",value:a,cls:"text-sky-400"},{label:"DONE",value:l,cls:"text-emerald-400"},{label:"PENDING",value:i,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===r?(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."})]}):t.map((e,t)=>{let s=cH[e.status]||cH.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)})})]})}),cU=(0,r.memo)(function(e){let{sessionId:t="",onListPoints:s,onPreview:l,onApply:a,onClose:i}=e,[o,c]=(0,r.useState)([]),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(!0),[p,h]=(0,r.useState)(null),[f,b]=(0,r.useState)(null),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)("");(0,r.useEffect)(()=>{let e=!0;return s?.().then(t=>{e&&(t||w("The host did not answer. Try again."),c(t?.points||[]),u(t?.support||null),x(!1))}).catch(()=>{e&&(w("Could not read this conversation."),x(!1))}),()=>{e=!1}},[s]);let j=(0,r.useCallback)(async e=>{(0,ed.e)(),h(e),b(null),w("");let t=await l?.(e.messageId);t?.ok?b(t):w(t?.error||"The host could not preview this rewind.")},[l]),k=(0,r.useCallback)(async()=>{if(!p)return;(0,ed.e)(),v(!0),w("");let e=await a?.(p.messageId);(v(!1),e?.ok)?i?.():w(e?.error||"The rewind did not go through.")},[p,a,i]),N=d&&!d.conversation;return(0,n.jsx)(rn,{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:i,children:m?(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..."})]}):N?(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:d.how||"This engine cannot rewind a conversation."})]}):0===o.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:y||"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:[...o].reverse().map(e=>(0,n.jsxs)("div",{onClick:()=>j(e),className:`modal-row ${p?.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:p?.messageId===e.messageId?"Selected":"Pick"}),(0,n.jsx)(el.Lt,{size:11})]})]},e.messageId))}),y&&(0,n.jsx)("div",{className:"px-3 py-2 border-t border-border-subtle text-[11px] text-danger bg-danger/5",children:y}),(0,n.jsxs)("div",{className:"p-3 border-t border-border-subtle bg-bg shrink-0 flex flex-col gap-2",children:[p&&(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:k,disabled:!p||g||!f?.ok,className:`px-3 py-1.5 rounded-brand text-xs font-medium flex items-center justify-center gap-1.5 transition-colors ${p&&!g&&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:[g?(0,n.jsx)(el.kr,{size:13,className:"animate-spin"}):(0,n.jsx)(el.aJ,{size:13}),(0,n.jsx)("span",{children:g?"Rewinding...":"Rewind to this prompt"})]})]})]})})}),cX=(0,r.memo)(function(e){let{requestId:t="",tool:s="",input:l={},failed:a=!1,onResolve:i}=e,[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!1),m=function(e){if(e?.kind!=="permission_grant")return"";let t=[],s=String(e.reason||"").trim();return s&&t.push(s),t.push(...function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},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")}(l)||l?.command||l?.path||JSON.stringify(l||{});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:s,children:s||"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:m}),d&&(0,n.jsx)("div",{className:"mb-3",children:(0,n.jsx)("input",{type:"text",value:o,onChange:e=>c(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})}),a&&(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:[d?(0,n.jsx)("button",{type:"button",onClick:()=>u(!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:()=>u(!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)(),i?.(t,"deny",o||"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)(),i?.(t,"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"})]})]})]})}),cV=(0,r.memo)(function(e){let{engine:t="",message:s="",reason:r="",escalate:l=null,onEscalate:a,onDismiss:i}=e;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"}),t&&(0,n.jsx)("span",{className:"font-mono text-[10px] px-1.5 py-0.5 rounded bg-danger/15 text-danger uppercase",children:t})]}),(0,n.jsx)("div",{className:"p-2.5 rounded bg-bg text-[11px] text-text border border-border-subtle mb-3 whitespace-pre-wrap wrap-anywhere max-h-[160px] overflow-y-auto",children:s||r||"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)(),i?.()},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"})]}),l?.mode&&(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),a?.(l?.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 ",l.label||l.mode]})]})]})]})}),cG=[],cJ=(0,r.memo)(function(e){let{sessionId:t=""}=e,[s,l]=(0,r.useState)(!1),a=lH(e=>e.bySession[t]?.tasks),i=(0,r.useMemo)(()=>Array.isArray(a)?a.filter(e=>!!(e&&e.subject&&String(e.subject).trim().length>0)):cG,[a]);if(0===i.length)return null;let o=i.filter(e=>"completed"===e.status).length,c=i.find(e=>"in_progress"===e.status),d=o===i.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:()=>l(!s),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:[d?(0,n.jsx)(el.Jl,{size:13,className:"text-success shrink-0"}):c?(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:[o,"/",i.length]}),c&&(0,n.jsx)("span",{className:"text-[11px] text-brand-500 truncate min-w-0 font-medium",children:c.activeForm||c.subject}),(0,n.jsx)("span",{className:"text-text-muted/50 shrink-0 ml-auto",children:s?(0,n.jsx)(el.yQ,{size:11}):(0,n.jsx)(el.c_,{size:11})})]})}),s&&(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:i.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))})]})}),cY=[],cZ=(0,r.memo)(function(e){let{sessionId:t="",engine:s="claude",onStopTask:l}=e,a=lH(e=>e.bySession[t]?.messages)||cY,i=lH(e=>e.bySession[t]?.harnessTasks)||cY,o=(0,r.useMemo)(()=>(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return t.length>0?t.filter(e=>e?.status==="running").filter(t=>t.toolUseId&&ll(e,t.toolUseId)).map(e=>({kind:e.background?"shell":"agent",id:e.toolUseId,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(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=[],s=e=>{for(let n of e||[]){if(n?.status==="running"){let e=n.startedAt||n.timestamp,s=e?{startedAt:e}:null;ls.has(n?.name)?t.push({kind:"agent",id:n.id,toolUseId:n.id,label:ln(n),...s}):n?.async&&t.push({kind:"shell",id:n.id,toolUseId:n.id,label:lr(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)})(a,i),[a,i]),[c,d]=(0,r.useState)(null),[u,m]=(0,r.useState)(()=>Date.now()),[x,p]=(0,r.useState)(!1),h=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(0===o.length)return;let e=setInterval(()=>m(Date.now()),1e3);return()=>clearInterval(e)},[o.length]),(0,r.useEffect)(()=>()=>clearTimeout(h.current),[]);let f=(0,r.useCallback)(()=>{if(!x){p(!0),(0,ed.e)(),clearTimeout(h.current),h.current=setTimeout(()=>p(!1),3e3);return}for(let e of(clearTimeout(h.current),p(!1),(0,ed.e)(),o))e.taskId&&l(e.taskId)},[x,o,l]),b=o.some(e=>e.taskId&&l);if(0===o.length)return null;let g=o.filter(e=>"agent"===e.kind),v=o.filter(e=>"shell"===e.kind);return(0,n.jsxs)("div",{className:"px-3 @2xl:px-6 py-1 border-b border-border-subtle/40 bg-brand-500/[0.06] shrink-0 text-xs select-none",children:[g.length>0&&(0,n.jsx)(cQ,{icon:(0,n.jsx)(el.kr,{size:13,className:"text-brand-500 shrink-0 animate-spin"}),tag:"AGENTS",items:g,messages:a,engine:s,now:u,onOpen:d}),v.length>0&&(0,n.jsx)(cQ,{icon:(0,n.jsx)(el.kr,{size:13,className:"text-warning shrink-0 animate-spin"}),tag:"SHELLS",items:v,messages:a,engine:s,now:u,onOpen:d}),b&&o.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"})}),c&&(0,n.jsx)(aZ,{tasks:c,messages:a,engine:s,sessionId:t,onStopTask:l,onClose:()=>d(null)})]})});function cQ(e){let{icon:t,tag:s,items:r,messages:l,engine:a,now:i,onOpen:o}=e,c=r.map(e=>e.label).join(", "),d=lw(r.reduce((e,t)=>t.startedAt&&(!e?.startedAt||t.startedAt<e.startedAt)?t:e,null),i),u=r.map(e=>(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"claude";if(!e?.name)return"";let{name:s,input:n={}}=e,r=lo(n.file_path||n.path);switch(tQ(t,s)){case"bash":return ld(n.description||n.command||"shell",60);case"file":return ld(`${/^(list|list_dir|ls)$/i.test(s)?"Listing":"Reading"} ${r}`,60);case"search":return ld([n.pattern?`"${n.pattern}"`:n.query||n.url||"",r?`in ${r}`:""].filter(Boolean).join(" "),60);case"diff":return ld(`${/^(Write|write_to_file)$/i.test(s)?"Writing":"Editing"} ${lo(n.file_path||n.filePath||n.file||n.path)||lm(n)}`,60);case"agent":return ld(n.description||lm(n)||"sub-agent",60);case"plan":return ld(lo(n.path)||s,60);default:return ld([lu(s),lm(n)].filter(Boolean).join(" "),60)}})(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",s=ll(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}(l,e.toolUseId),a)).find(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 min-w-0",children:[t,(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:s}),(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),o(r)},title:c,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:[r.length," running"]}),d>0&&(0,n.jsx)("span",{className:"font-mono text-[11px] text-text shrink-0 tabular-nums",children:as(d)}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted truncate min-w-0",children:u||c})]})]})}let c0={model:"",skills:[],mcpServers:[]},c1=[],c2=(0,r.memo)(function(e){let{sessionId:t,engine:s="claude",workspacePath:l="",sessionName:a="",bus:i=null,fileBus:o=null,isVisible:c=!0,isFocused:d=!1,isDesktop:m=!0,bgIndex:x=0,onActivate:p=null,onOpenRemote:h=null,onOpenMobile:b=null,onOpenArtifact:g=null,onNewChat:v=null}=e,[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(!1),[N,C]=(0,r.useState)(!1),[S,T]=(0,r.useState)(!1),{t:E}=(0,eu.s)(),R=(0,r.useCallback)(()=>T(!0),[]),{sendPrompt:M,removeQueueItem:$,clearQueue:z,resolvePermission:A,stop:I,stopTask:D,runShell:B,rewindToMessage:F,previewRewind:O,listRewindPoints:_,escalateMode:K,dismissBlocked:W,hasOlder:H,loadOlder:q,reload:U,hydrating:X,synced:V,hydrateFailed:G}=function(e){let{sessionId:t,engine:s="claude",workspacePath:n="",bus:l=null,isVisible:a=!0}=e,i=(0,r.useRef)(l);(0,r.useEffect)(()=>{i.current=l},[l]);let o=lH(e=>e.initSession),c=lH(e=>e.setMetadata),d=lH(e=>e.appendDelta),m=lH(e=>e.appendThinking),x=lH(e=>e.appendDiff),p=lH(e=>e.appendTool),h=lH(e=>e.updateToolResult),f=lH(e=>e.nestTool),b=lH(e=>e.nestToolResult),g=lH(e=>e.upsertTask),v=lH(e=>e.setPermission),y=lH(e=>e.clearPermission),w=lH(e=>e.finishTurn),j=lH(e=>e.setTurnRunning),k=lH(e=>e.ensureTurnLive),N=lH(e=>e.addUserMessage),C=(0,u.d)(e=>e.connected),[S,T]=(0,r.useState)(!1),[E,R]=(0,r.useState)(!1),[M,$]=(0,r.useState)(!1),[z,A]=(0,r.useState)(!1),I=(0,r.useRef)(0),D=(0,r.useRef)(!1),B=(0,r.useCallback)((e,t,n)=>{switch(t){case"user_message":N(e,n.text,n.attachments||null,!!n?.replay),n?.replay||(!function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage,n=lY(e,s),r=n.findIndex(e=>e.text===t);-1!==r&&(n.splice(r,1),lZ(e,n,s))}(e,n.text),lH.getState().clearPromptSending(e,n.text)),ae(e,n.text);break;case"init":{let t=l1(lH.getState().bySession[e]?.metadata?.skills),s=new Map(t.map(e=>[e.id||e.name,e])),r=l1(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||{};c(e,{...i,skills:l,...a?{model:a}:{}});break}case"goal":c(e,{goal:n?.goal||null});break;case"delta":n?.replay||k(e),d(e,n.text);break;case"thinking":n?.replay||k(e),m(e,n.text);break;case"diff":x(e,n);break;case"tool_child":f(e,n);break;case"tool_result_child":b(e,n);break;case"tool_start":if(n?.replay||k(e),p(e,n),n&&n.name){let t=lH.getState().bySession[e]?.tasks||[],r=t0(s,n.name,n.input,n.id,t);r&&g(e,r)}break;case"tool_result":if(h(e,n),n&&n.id){let t=t1(s,n.name||"",n.output||"",n.id);t&&g(e,t)}break;case"permission_request":v(e,n);break;case"permission_resolved":y(e,n.requestId);break;case"blocked":lH.getState().setBlocked(e,n);break;case"options_changed":n?.permissionMode&&lH.getState().setPermissionMode(e,n.permissionMode),n?.model&&c(e,{model:n.model}),n?.effort&&c(e,{effort:n.effort});break;case"queue_update":lH.getState().setQueue(e,n?.queue||[]);break;case"turn_complete":w(e,n.stats,n.turnMs,!!n?.replay),!n?.isError||l6(lH.getState().bySession[e]?.messages,n.result)||l5(lH.getState().bySession[e]?.messages,n.result)||lH.getState().addNotice(e,{subtype:n.subtype||"",level:"error",content:n.result||"The turn ended in an error."});break;case"stats":n?.stats&&lH.getState().setStats(e,n.stats);break;case"stopped":case"exit":y(e),lH.getState().finishTurn(e,null,n?.turnMs),"exit"===t&&lH.getState().settleDeadTasks(e),"exit"===t&&(n?.error||n?.code!=null&&0!==n.code)&&lH.getState().addNotice(e,{subtype:"exit",level:"error",content:n.error||`The AI process exited (code ${n.code}).`});break;case"stall":j(e,!1),w(e,null,n?.turnMs);break;case"error":lH.getState().addNotice(e,{subtype:"error",level:"error",content:n?.message||"AI process failed"}),w(e,null,n?.turnMs);break;case"prompt_refused":lH.getState().addNotice(e,{subtype:"prompt_refused",level:"error",content:l8(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}),lH.getState().clearMessages(e),lH.getState().setTaskRecords(e,n?.taskRecords),lH.getState().restoreTurnState(e,n),Array.isArray(n?.queue)&&lH.getState().setQueue(e,n.queue);break;case"cli_event":{let t=n?.type||"",r=n?.record||null;lH.getState().applyTaskRecords(e,[[t,n?.subtype||"",r,n?.ageMs]]);let l=lP(t,r,s);l&&lH.getState().addNotice(e,l);break}case"ansi":{let t=l4(n?.chunk);t&&lH.getState().addNotice(e,{subtype:"ansi",level:"warning",content:t})}}},[s,N,c,d,m,x,p,h,f,b,g,v,y,w,j,k]),F=(0,r.useRef)(B);(0,r.useEffect)(()=>{F.current=B});let O=(0,r.useRef)(o);(0,r.useEffect)(()=>{O.current=o});let _=(0,r.useRef)(0),K=(0,r.useRef)(null),W=(0,r.useRef)(!1),H=(0,r.useRef)([]),q=(0,r.useRef)(0),U=(0,r.useRef)(null);null==U.current&&(U.current=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:lV,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 X=(0,r.useRef)(null),V=(0,r.useRef)(null),G=(0,r.useRef)(0),J=(0,r.useRef)(null),Y=(0,r.useRef)({}),Z=(0,r.useRef)(null),Q=(0,r.useRef)(null),ee=(0,r.useRef)(null),et=(0,r.useRef)(a);(0,r.useEffect)(()=>{et.current=a},[a]);let es=(0,r.useRef)(null),en=(0,r.useRef)(null),er=(0,r.useRef)(null),el=(0,r.useRef)([]),ea=(0,r.useRef)(!1),ei=(0,r.useRef)(0),eo=(0,r.useRef)(1e4),ec=(0,r.useRef)(!1),ed=(0,r.useRef)(0),eu=(0,r.useRef)(0),em=(0,r.useCallback)(()=>{X.current&&clearTimeout(X.current),X.current=null,U.current?.answered()},[]),ex=(0,r.useCallback)(()=>{let e=U.current?.schedule(u.d.getState().connected);A(!!U.current?.exhausted()),(0,L.Lq)("ai-hydrate","ladder",{delay:e??null,exhausted:U.current?.exhausted(),connected:u.d.getState().connected,armed:null!=X.current}),null!=e&&(X.current=setTimeout(()=>{X.current=null,U.current?.fired(),Y.current.request?.()},e))},[]),ep=(0,r.useCallback)(()=>{if(!t||!l)return;if(W.current){(0,L.Lq)("ai-hydrate","blocked (round in flight)",{gen:q.current}),ex();return}let e=++q.current,r=K.current;W.current=!0,R(!0),H.current=[],el.current=[],ea.current=!1,I.current=0;let a=Date.now();(0,L.Lq)("ai-hydrate","emit ai:create",{gen:e,sessionId:t,engine:s,cwd:n,carrier:u.d.getState().carrier,connected:u.d.getState().connected});let i=()=>{let e=H.current;H.current=[],W.current=!1,R(!1),(0,se.unstable_batchedUpdates)(()=>{for(let s of e){if("conversation_reset"===s.event){_.current=0,K.current=s.data?.epoch??(K.current??0)+1,I.current=s.data?.fromSeq??0,T(!!s.data?.hasMore),F.current(t,s.event,s.data);continue}if(null!=s.seq){if(s.seq<=_.current)continue;_.current=s.seq}F.current(t,s.event,s.data)}})},o=setTimeout(()=>{e===q.current&&W.current&&(i(),ex())},4e3);J.current=o,l.emit("ai:create",{sessionId:t,engine:s,cwd:n,options:{defaultMode:tZ(s).defaultMode,defaultEffort:tZ(s).defaultEffort}},n=>{if(!function(e){let{isNewest:t,snapshotSeq:s=0,appliedSeq:n=0,sameLog:r=!0}=e;return!!t||!!r&&(s||0)>(n||0)}({isNewest:e===q.current,snapshotSeq:n?.session?.seq,appliedSeq:_.current,sameLog:r===K.current}))return;let l=null,c=null,d=n?.session?.events;(0,L.Lq)("ai-hydrate","ack",{gen:e,stale:e!==q.current,ms:Date.now()-a,ok:n?.ok??null,error:n?.error??null,events:Array.isArray(d)?d.length:null,hasMore:n?.session?.hasMore??null});try{if(clearTimeout(o),!n?.ok||!Array.isArray(d))return void T(!1);let e=n.session.seq||0;if((0,L.Lq)("ai-status","hydrate ack",{sessionId:t,isTurnRunning:n.session.isTurnRunning,elapsedMs:n.session.elapsedMs,lastTurnMs:n.session.lastTurnMs,events:d.length,hasMore:n.session.hasMore}),n.session.asleep&&!n.session.isTurnRunning){let e=P.rh.getState();e.applyStatusChange(e$(t).head??e.currentKey,{sessionId:t,state:"sleep"})}if(I.current=d[0]?.seq??0,T(!!n.session.hasMore&&d.length>0),Array.isArray(n?.modelOptions)&&n.modelOptions.length>0&&lH.getState().setMetadata(t,{modelOptions:n.modelOptions}),d.length>0){let e=l9(d,s);lH.getState().hydrateSession(t,{messages:e.messages,tasks:e.tasks,metadata:{...lH.getState().bySession[t]?.metadata,...e.metadata,...Array.isArray(n?.modelOptions)?{modelOptions:n.modelOptions}:{},...n.session.effort?{effort:n.session.effort}:{}},stats:{...e.stats,...n.session.stats||{}},isTurnRunning:void 0!==n.session.isTurnRunning?!!n.session.isTurnRunning:e.isTurnRunning,elapsedMs:n.session.elapsedMs||0,lastTurnMs:n.session.lastTurnMs||0,permissionMode:n.session.permissionMode||e.permissionMode,activeBlocked:e.activeBlocked,harnessTasks:lE(n.session.taskRecords,e.harnessTasks),queue:n.session.queue||[]})}else j(t,!!n.session.isTurnRunning),lH.getState().setTaskRecords(t,n.session.taskRecords),n.session.permissionMode&&lH.getState().setPermissionMode(t,n.session.permissionMode),Array.isArray(n.session.queue)&&lH.getState().setQueue(t,n.session.queue),n.session.stats&&lH.getState().setStats(t,n.session.stats);n.session.asleep&&!n.session.isTurnRunning&&lH.getState().settleDeadTasks(t),l=n.session.activePermission||null,c=Array.isArray(n.session.queue)?n.session.queue:null,_.current=e,null!=n.session.epoch&&(K.current=n.session.epoch)}finally{if(clearTimeout(o),e===q.current&&i(),l&&e===q.current&&lH.getState().setPermission(t,l),c&&e===q.current&&lH.getState().setQueue(t,c),n?.ok&&void 0!==n.session.isTurnRunning&&lH.getState().restoreTurnState(t,{isTurnRunning:!!n.session.isTurnRunning,elapsedMs:n.session.elapsedMs||0,lastTurnMs:n.session.isTurnRunning?0:n.session.lastTurnMs||0}),n?.ok)for(let e of($(!0),A(!1),em(),G.current=Date.now(),(function(e){let{deliveredTexts:t=[],page:s="",minAgeMs:n=0,now:r=Date.now()}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage,a=lY(e,l);if(!a.length)return[];let i=new Set(t),o=[],c=[];for(let e of a){if(e.page===s||r-(e.at||0)<n){c.push(e);continue}i.has(e.text)||o.push(e)}return lZ(e,c,l),o})(t,{deliveredTexts:(n.session?.events||[]).filter(e=>"user_message"===e.event).map(e=>e.data?.text),page:l2,minAgeMs:5e3}).filter(e=>!l7(t,e.text))))lH.getState().setPromptError(t,e.text,"reload",null,e.id);else ex()}})},[t,s,n,l,j,ex,em]),eh=(0,r.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];!u.d.getState().connected||V.current||!e&&Date.now()-G.current<1500||(V.current=setTimeout(()=>{V.current=null,ep()},eg.qw))},[ep]),ef=(0,r.useCallback)(()=>{if(l&&t){if(!et.current){es.current="visible";return}!u.d.getState().connected||W.current||en.current||(en.current=setTimeout(()=>{if(en.current=null,!et.current||W.current)return;let e=!1,s=setTimeout(()=>{e||((0,L.Lq)("ai-hydrate","peekSeq: no ack → full hydrate"),eh())},eg.zm);er.current=s,l.emit("ai:peekSeq",{sessionId:t,haveSeq:_.current,epoch:K.current},n=>{if(e=!0,clearTimeout(s),er.current=null,!n?.ok||"number"!=typeof n.seq)return void eh();let r=_.current,l=!!lH.getState().bySession[t]?.isTurnRunning,a=lH.getState().bySession[t]?.queue?.length||0,i="number"==typeof n.queueLength?n.queueLength:a;if(n.seq===r&&!!n.isTurnRunning===l&&i===a)return void(0,L.Lq)("ai-hydrate","peekSeq: nothing missed",{seq:r});let o=null!=n.epoch&&n.epoch===K.current;if(!(n.seq>r&&o&&Z.current?.())){if(n.seq===r&&o&&i===a){(0,L.Lq)("ai-hydrate","peekSeq: turn-flag drift patched in place",{seq:r,turn:n.isTurnRunning}),lH.getState().setTurnRunning(t,!!n.isTurnRunning);return}(0,L.Lq)("ai-hydrate","peekSeq: state changed",{fromSeq:r,toSeq:n.seq,turn:n.isTurnRunning}),eh(!0)}})},eg.qw))}},[l,t,eh]),eb=(0,r.useCallback)(()=>{l?.kickWsZombie?.("refresh"),em(),ep()},[l,em,ep]);(0,r.useEffect)(()=>{Y.current={request:()=>eh(!0)}},[eh]),(0,r.useEffect)(()=>()=>{V.current&&clearTimeout(V.current),en.current&&clearTimeout(en.current),er.current&&clearTimeout(er.current),X.current&&clearTimeout(X.current),J.current&&clearTimeout(J.current),V.current=en.current=er.current=X.current=J.current=null,W.current=!1,H.current=[]},[]),(0,r.useEffect)(()=>{if(t)return ee.current!==t&&(ee.current=t,W.current=!1,em(),$(!1),A(!1),K.current=null,el.current=[],ea.current=!1,ei.current=0,ed.current=0,eu.current=0),O.current(t),ep()},[t,ep,em]),(0,r.useEffect)(()=>{if(!a)return;let e=es.current;e&&(es.current=null,"reconnect"===e?eh():ef())},[a,eh,ef]),(0,r.useEffect)(()=>{if(!l||!t)return;let e=()=>{document.hidden||ef()},s=()=>{if(Q.current?.(),!et.current){es.current="reconnect";return}eh()};return l.on("connect",s),document.addEventListener("visibilitychange",e),document.addEventListener("resume",e),()=>{l.off("connect",s),document.removeEventListener("visibilitychange",e),document.removeEventListener("resume",e)}},[l,t,ef,eh]);let ev=(0,r.useRef)(!0);(0,r.useEffect)(()=>{let e=ev.current;if(ev.current=C,C&&!e){if(Q.current?.(),!et.current){es.current="reconnect";return}eh()}},[C,eh]),(0,r.useEffect)(()=>{if(!l||!t)return;let e="",s="",n=null,r=[],a=!1,o=()=>{null!=n&&cancelAnimationFrame(n),n=null;let r=e,l=s;e="",s="",(r||l)&&lH.getState().appendStream(t,r,l)},c=()=>{a=!1;let e=r;r=[];let s=F.current;(0,se.unstable_batchedUpdates)(()=>{for(let n of e)n.stream?lH.getState().appendStream(t,n.data.text,n.data.thinking):s(t,n.event,n.data)})},d=(t,l)=>{if("cli_event"!==t&&(e||s)){let t={stream:!0,data:{text:e,thinking:s}};e="",s="",null!=n&&(cancelAnimationFrame(n),n=null),r.push(t)}r.push({event:t,data:l}),a||(a=!0,queueMicrotask(c))},m=e=>{if(!e||e.sessionId!==t)return;if(ei.current=Date.now(),eo.current=1e4,W.current)return void H.current.push(e);if("conversation_reset"===e.event){_.current=0,K.current=e.data?.epoch??(K.current??0)+1,I.current=e.data?.fromSeq??0,T(!!e.data?.hasMore),el.current=[],d(e.event,e.data);return}let s=lG(e,{appliedSeq:_.current,logEpoch:K.current});if("adopt"===s)K.current=e.epoch;else if("resync"===s){el.current=[],Y.current.request?.();return}else if("stale"===s||"dup"===s)return;else if("gap"===s){if(el.current.push(e),el.current.length>200){el.current=[],Y.current.request?.();return}p();return}null!=e.seq&&(_.current=e.seq),x(e.event,e.data)};function x(t,r){if("delta"===t||"thinking"===t){var l;return void((l=r?.text)&&("delta"===t?e+=l:s+=l,null==n&&(n=requestAnimationFrame(o))))}d(t,r)}let p=()=>{if(ea.current||W.current)return!0;if(!u.d.getState().connected)return!1;let e=i.current;if(!e)return!1;ea.current=!0;let s=_.current,n=K.current,r=!1,l=e=>{var t,s;let l;if(r||(r=!0,clearTimeout(a),ea.current=!1,W.current))return;let i=(t=e?.ok&&e.events||[],s=_.current,(l=t.filter(e=>null!=e.seq&&e.seq>s)).length?l[0].seq!==s+1||l.find(e=>("delta"===e.event||"thinking"===e.event)&&null!=e._fromSeq&&e._fromSeq<=s)?{safe:!1}:{safe:!0,apply:l}:{safe:!0,apply:[]});if(!e?.ok||e.resync||e.epoch!==n||e.hasMore||!i.safe){el.current=[],Y.current.request?.();return}for(let e of i.apply)_.current=e.seq,x(e.event,e.data);(()=>{let e=el.current;el.current=[];let t=!1;for(let s of e){if(t){el.current.push(s);continue}let e=lG(s,{appliedSeq:_.current,logEpoch:K.current});if("gap"===e){el.current.push(s),t=!0;continue}if("stale"!==e&&"dup"!==e){if("resync"===e){el.current=[],Y.current.request?.();return}"adopt"===e&&(K.current=s.epoch),null!=s.seq&&(_.current=s.seq),x(s.event,s.data)}}t&&p()})()},a=setTimeout(()=>l(null),3e3);return e.emit("aiSince",{sessionId:t,after:s,epoch:n},l),!0};Z.current=p;let h=()=>{if(ec.current||W.current||ea.current||!et.current||!u.d.getState().connected)return;ec.current=!0;let e=!1,s=t=>{if(!e){if(e=!0,clearTimeout(n),ec.current=!1,!(t?.ok&&(null!=t.epoch&&null!=K.current&&t.epoch!==K.current||"number"==typeof t.seq&&t.seq>_.current))){ed.current=0,eo.current=Math.min(2*eo.current,12e4);return}(ed.current++,1===ed.current)?setTimeout(h,1500):(ed.current=0,null!=t.epoch&&t.epoch===K.current?p():Y.current.request?.())}},n=setTimeout(()=>s(null),eg.zm);i.current?.emit("ai:peekSeq",{sessionId:t,haveSeq:_.current,epoch:K.current},s)},f=setInterval(()=>{let e=lH.getState().bySession[t],s=Date.now()-eu.current<15e3;if(!e?.isTurnRunning&&!s){ed.current=0;return}!ei.current||Date.now()-ei.current<eo.current||h()},5e3);return l.on("ai:event",m),()=>{l.off("ai:event",m),clearInterval(f),Z.current=null,o()}},[l,t,B]);let ey=(0,r.useCallback)(function(e){let{attachments:s=null,promptId:r=null,retries:l=0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e&&!s?.length)return;let a=r||`p-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;eu.current=Date.now();let o=i.current;ek.getState().clearNotification(t);let c=n=>{(lH.getState().clearPromptSending(t,e),l7(t,e))?lQ(t,a):lH.getState().setPromptError(t,e,n,s,a,l)};(e&&function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.localStorage;if(!t?.id||!t.text)return;let n=lY(e,s).filter(e=>e.id!==t.id);n.push({id:t.id,text:t.text,page:t.page||"",at:Number.isFinite(t.at)?t.at:Date.now()}),lZ(e,n,s)}(t,{id:a,text:e,page:l2}),o)?(e&&lH.getState().setPromptSending(t,e),sz((s,n)=>o.emit("ai:prompt",s,s=>{s?.ok&&(lQ(t,a),lH.getState().clearPromptSending(t,e)),n(s)}),{sessionId:t,message:e,cwd:n,promptId:a,...s?.length?{attachments:s}:{}},5e3,c,setTimeout,clearTimeout,()=>ae(t,e))):c("offline")},[t,n]),ew=(0,r.useCallback)(()=>{let e=lH.getState().bySession[t]?.promptError;if(!e?.text)return;if(l7(t,e.text)){(0,L.Lq)("ai-prompt","auto-resend skipped (already shown)",{text:String(e.text).slice(0,24)}),lH.getState().clearPromptError(t);return}if(!e.promptId||!i.current?.hostCaps?.promptDedupe)return;let s=(e.retries||0)+1;s>2||(lH.getState().clearPromptError(t),ey(e.text,{attachments:e.attachments||null,promptId:e.promptId,retries:s}))},[t,ey]);(0,r.useEffect)(()=>{Q.current=ew},[ew]);let ej=(0,r.useCallback)(e=>{let s=i.current;if(!s)return;let n=lH.getState().bySession[t]?.queue||[],r=n.findIndex(t=>t.id===e);if(-1===r)return;let l=n[r];lH.getState().setQueue(t,n.filter(t=>t.id!==e)),sz((e,t)=>s.emit("ai:queueRemove",e,t),{sessionId:t,id:e},5e3,()=>{let e=[...lH.getState().bySession[t]?.queue||[]];e.splice(Math.min(r,e.length),0,l),lH.getState().setQueue(t,e)})},[t]),eN=(0,r.useCallback)(()=>{let e=i.current,s=lH.getState().bySession[t]?.queue||[];e&&s.length&&(lH.getState().setQueue(t,[]),sz((t,s)=>e.emit("ai:queueClear",t,s),{sessionId:t},5e3,()=>lH.getState().setQueue(t,s)))},[t]),eC=(0,r.useCallback)(function(e,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=i.current;if(!l)return;let a=!1,o=null,c=n=>{if(!a){if(a=!0,clearTimeout(o),n?.ok||n?.reason==="stale")return void y(t,e);(0,L.Lq)("ai-gate","resolve failed",{requestId:e,behavior:s,res:n??"timeout"}),lH.getState().setGateError(t,e)}};r?l.emit("ai:question",{sessionId:t,requestId:e,answers:r},c):l.emit("ai:permission",{sessionId:t,requestId:e,behavior:s,message:n},c),o=setTimeout(()=>c(null),5e3)},[t,y]),eS=(0,r.useCallback)(()=>{let e=i.current;e?.emit("ai:stop",{sessionId:t})},[t]),eT=(0,r.useCallback)(e=>{if(!e)return;let s=i.current;s?.emit("ai:stopTask",{sessionId:t,taskId:e})},[t]),eE=(0,r.useCallback)(e=>{ey(`! ${e}`)},[ey]),eR=(0,r.useCallback)(async()=>{let e=i.current;if(!e)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);e.emit("ai:rewind",{sessionId:t,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},[t]),eM=(0,r.useCallback)(async function(e,s){let{files:r=!0,preview:l=!1,index:a=null}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=i.current;if(!o)return{ok:!1,error:"Not connected to the host."};let c=await new Promise(s=>{let n=!1,i=e=>{n||(n=!0,clearTimeout(c),s(e))},c=setTimeout(()=>i(null),l?4e3:13e4);o.emit("ai:rewind",{sessionId:t,action:l?"preview":"apply",messageId:e,index:a,files:r},i)});return(l||c&&c.ok||eb(),c)?(c.ok&&!l&&s&&o.emit("ai:prompt",{sessionId:t,message:s,cwd:n}),c):{ok:!1,error:"The host did not answer in time."}},[t,n,eb]),ez=(0,r.useCallback)(function(e){let{files:t=!0,index:s=null}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return eM(e,null,{files:t,preview:!0,index:s})},[eM]),eP=(0,r.useCallback)(e=>{if(!e)return;lH.getState().setPermissionMode(t,e),lH.getState().clearBlocked(t);let s=i.current;s?.emit("ai:options",{sessionId:t,options:{mode:e}})},[t]),eA=(0,r.useCallback)(()=>{lH.getState().clearBlocked(t)},[t]);return{hydrating:E,synced:M,hydrateFailed:z,hasOlder:S,loadOlder:(0,r.useCallback)(async()=>{if(D.current)return!1;let e=i.current;if(!e)return!1;D.current=!0;let n=I.current;try{let{messages:r,before:l,hasMore:a,answered:i}=await lX({startSeq:n,estimateBytes:lq,fetchChunk:s=>new Promise(n=>{let r=!1,l=e=>{r||(r=!0,clearTimeout(a),n(e))},a=setTimeout(()=>l(null),4e3);e.emit("aiHistory",{sessionId:t,before:s},l)}),reduceChunk:(e,n)=>{let r=lH.getState().bySession[t];return l9(e,s,(r?.messages?.length||0)+n+1).messages}});if(I.current!==n||!i||(I.current=l,T(a),!r.length))return!1;return lH.getState().prependMessages(t,r),!0}finally{D.current=!1}},[t,s]),reload:eb,sendPrompt:ey,removeQueueItem:ej,clearQueue:eN,resolvePermission:eC,stop:eS,stopTask:eT,runShell:eE,rewindToMessage:eM,previewRewind:ez,listRewindPoints:eR,escalateMode:eP,dismissBlocked:eA}}({sessionId:t,engine:s,workspacePath:l,bus:i,isVisible:c}),J=(0,r.useCallback)(()=>{(0,ed.e)(),k(!0),U(),setTimeout(()=>k(!1),700)},[U]),Y=lH(e=>e.bySession[t]?.activePermission),Z=!!lH(e=>e.bySession[t]?.isTurnRunning),Q=lH(e=>e.bySession[t]?.gateError),ee=lH(e=>e.bySession[t]?.activeBlocked),et=lH(e=>e.bySession[t]?.metadata)||c0,es=lH(e=>e.bySession[t]?.tasks)||c1,en=lH(e=>e.setPermissionMode),er=ez(t),ea=(0,f.B)(e=>e.terminalBackgroundOpacity),ei=(0,f.B)(e=>e.customBackgrounds),eo=(0,f.B)(e=>e.terminalBackgrounds),em=(0,f.B)(e=>e.backgroundBySession[t]),ex=(0,f.B)(e=>e.terminalTheme),ep=(0,f.B)(e=>e.fontSize),eh=(0,f.B)(e=>e.showFolderButton),ef=(0,f.B)(e=>e.showNoteButton),eb=(0,f.B)(e=>e.setRightPanelRoot),ev=(0,f.B)(e=>e.setRightPanelTab),ey=(0,f.B)(e=>e.openRightPanel),ew=(0,f.B)(e=>e.artifactsBySession[t]),{count:ej}=rk(l,o,{enabled:d&&eh}),{theme:eN}=(0,t7.D)(),eC=(0,r.useMemo)(()=>(0,rM.In)(eN,ex),[eN,ex]),eS=(0,r.useMemo)(()=>(0,eg.ar)(ep)+(m?1:2),[ep,m]),eT=(0,r.useMemo)(()=>{let e=(0,eg.$Z)(em,eo,ei,x),t="dark"===eN?(0,eg.RS)(e,ei):null;if(t){let e=`rgba(${eg.c},${ea??eg._z})`,s=`rgba(${eg.pZ},${eg.B$})`;return{backgroundColor:eC.background,backgroundImage:`linear-gradient(${e},${e}), linear-gradient(${s},${s}), url("${t}")`,backgroundSize:"100% 100%, 100% 100%, cover",backgroundPosition:"0 0, 0 0, center",backgroundRepeat:"no-repeat, no-repeat, no-repeat",backgroundBlendMode:"normal, screen, normal"}}return m?t4(eN):{backgroundColor:"transparent"}},[eo,em,ei,ea,eC,eN,x,m]),eE=et.skills||[],eR=et.mcpServers||[],eM=(0,r.useCallback)(e=>{M(`/${e}`)},[M]),eP=(0,r.useCallback)(e=>{i?.emit?.("ai:options",{sessionId:t,options:e})},[i,t]),eA=(0,r.useCallback)(e=>{lH.getState().setMetadata(t,{model:e}),eP({model:e})},[eP,t]),eI=(0,r.useCallback)(e=>{e?.sessionId&&eP({resume:e.sessionId})},[eP]),eD=(0,r.useCallback)(e=>{if(e)return eI(e);w("sessions")},[eI]),eL=(0,r.useCallback)((e,s)=>{e&&("effort"===e&&lH.getState().setMetadata(t,{effort:s}),eP({[e]:s}))},[eP,t]),eB=tZ(s),eF=(0,r.useCallback)(e=>{en(t,e),eP({mode:e})},[eP,t,en]),eO=(0,r.useCallback)((e,s)=>{lH.getState().rewindToMessage(t,e,s)},[t]),e_=(0,r.useCallback)(e=>{if(!y&&e.shiftKey&&"Tab"===e.key){e.preventDefault(),(0,ed.e)();let s=eB.permissionModes||[],n=lH.getState().bySession[t]?.permissionMode||eB.defaultMode,r=s.findIndex(e=>e.id===n),l=-1===r?0:(r+1)%s.length,a=s[l]?.id;a&&eF(a)}},[t,eB,eF,y]),eK=rH({isFocused:d,onActivate:()=>p?.(t)}),eW=(0,r.useRef)(p);(0,r.useEffect)(()=>{eW.current=p});let eH=(0,r.useCallback)(()=>eW.current?.(t),[t]),eq=(0,r.useMemo)(()=>({sessionId:t,isFocused:d,activate:eH}),[t,d,eH]);return(0,n.jsx)(aN.Provider,{value:eq,children:(0,n.jsxs)("div",{...eK,onKeyDown:e_,className:"ai-pane w-full h-full flex flex-col bg-bg overflow-hidden relative select-text",style:{...eT,"--color-text":eC.foreground,"--ai-fs":`${eS}px`},children:[(0,n.jsxs)("div",{style:{height:26},className:"sm:hidden flex items-center gap-2 px-2 bg-surface/80 backdrop-blur-md 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 ${ne(er)}`,style:{background:s7(er).dot}}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-text",children:a||t2[s]?.label||s}),(0,n.jsx)(rW,{onOpenRemote:h,onOpenMobile:b})]}),d&&(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:[ef&&(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,ed.e)(),C(!0)},className:rq,title:E("terminalPane.note"),children:(0,n.jsx)(el.y8,{size:16,className:rU})}),(0,n.jsx)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),J()},className:rq,title:E("terminalPane.refresh"),children:(0,n.jsx)(el.e9,{size:16,className:`${rU} ${j?"animate-spin":""}`})})]}),eh&&l&&(0,n.jsxs)("button",{onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation()},onClick:e=>{e.stopPropagation(),(0,ed.e)(),eb(l,l),window.innerWidth>=eg.jK?ev("files",l):ey()},className:`relative ${rq}`,title:E("terminalPane.openFolderHere"),children:[(0,n.jsx)(el.vd,{size:16,className:rU}),ej>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:ej>eg.KN?`${eg.KN}+`:ej})]}),g&&ew?.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)(),g(t,ew[0])},className:`relative ${rq}`,title:E("terminalPane.artifacts"),children:[(0,n.jsx)(el.sU,{size:16,className:rU}),(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:ew.length})]})]}),(0,n.jsx)(cJ,{sessionId:t}),(0,n.jsx)(cZ,{sessionId:t,engine:s,onStopTask:D}),(0,n.jsx)(cj,{bus:i,sessionId:t,engine:s,workspacePath:l,fileBus:o,onSendPrompt:M,onResolvePermission:A,onRewind:F,onPreviewRewind:O,onListRewindPoints:_,onCutLocal:eO,hasOlder:H,onLoadOlder:q,onOpenResume:eD,hydrating:X,synced:V,hydrateFailed:G,onReload:U}),ee&&!Y&&(0,n.jsx)("div",{className:"px-3 pb-2 select-none list-rise flex-shrink-0 z-30",children:(0,n.jsx)(cV,{engine:ee.engine||s,message:ee.message,escalate:ee.escalate,onEscalate:K,onDismiss:W})}),Y&&(0,n.jsx)("div",{className:"px-3 pb-2 select-none list-rise flex-shrink-0 z-30",children:"AskUserQuestion"===Y.tool?(0,n.jsx)(aT,{requestId:Y.requestId,questions:Y.input?.questions||[],failed:Q,onResolve:A}):(0,n.jsx)(cX,{requestId:Y.requestId,tool:Y.tool,input:Y.input,failed:Q,onResolve:A})}),(0,n.jsx)(c$,{bus:i,sessionId:t,engine:s,onSend:M,onRemoveQueueItem:$,onClearQueue:z,onStop:I,onRunShell:B,onResolvePermission:A,onSelectModel:eA,onModeChange:eF,onOpenModal:w,onOptionChange:eL,onActivate:eH,isFocused:d,workspacePath:l,modalOpen:null!==y}),(0,n.jsx)(cP,{sessionId:t,fileBus:o,sessionName:a,engine:s,workspacePath:l,isDesktop:m,onModeChange:eF,onNewChat:R}),"skills"===y&&(0,n.jsx)(cA,{skills:eE,onClose:()=>w(null),onSelectSkill:eM}),"mcp"===y&&(0,n.jsx)(cI,{mcpServers:eR,onClose:()=>w(null)}),"model"===y&&(0,n.jsx)(cD,{currentModel:et.model,currentEffort:et.effort||"",models:et.modelOptions?.length?et.modelOptions:eB.models,isTurnRunning:Z,onClose:()=>w(null),onSelectModel:eA,onSelectEffort:e=>eP({effort:e})}),"sessions"===y&&(0,n.jsx)(cL,{bus:i,engine:s,workspacePath:l,onClose:()=>w(null),onResume:eI}),"config"===y&&(0,n.jsx)(cO,{engine:s,options:lH.getState().bySession[t]?.metadata,onClose:()=>w(null),onApply:e=>eP(e)}),"mode"===y&&(0,n.jsx)(cK,{modes:eB.permissionModes||[],currentMode:lH.getState().bySession[t]?.permissionMode||eB.defaultMode,onClose:()=>w(null),onSelectMode:eF}),"doctor"===y&&(0,n.jsx)(cW,{bus:i,engine:s,workspacePath:l,onClose:()=>w(null)}),"tasks"===y&&(0,n.jsx)(cq,{tasks:es,onClose:()=>w(null)}),"rewind"===y&&(0,n.jsx)(cU,{sessionId:t,onListPoints:_,onPreview:O,onApply:e=>F(e),onClose:()=>w(null)}),N&&ef&&(0,n.jsx)(rK,{bus:i,sessionId:t,onClose:()=>C(!1)}),(0,n.jsx)(ec.A,{isOpen:S,onClose:()=>T(!1),onConfirm:()=>v?.(t),title:E("ai.newChatTitle"),message:E("ai.newChatMessage"),confirmText:E("ai.newChatConfirm")})]})})});class c5 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}}function c3(e){let t=(0,r.useRef)(e);return(0,r.useEffect)(()=>{t.current=e}),(0,r.useCallback)(function(){for(var e=arguments.length,s=Array(e),n=0;n<e;n++)s[n]=arguments[n];return t.current?.(...s)},[])}let c4=()=>{},c6=(0,r.memo)(function(e){let{children:t}=e;return(0,n.jsx)("div",{className:"absolute inset-x-0 top-0 bottom-[37px] overflow-hidden",children:t})}),c8=(0,r.memo)(function(e){let{sessionId:t}=e,s=ez(t);return"idle"===s?null:(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 z-20 h-[1px] pointer-events-none hidden sm:block",children:"working"===s?(0,n.jsx)(cc,{}):"done"===s?(0,n.jsx)("div",{className:"w-full h-full bg-[#f59e0b]",style:{boxShadow:"0 0 4px rgba(245,158,11,0.6)"}}):"blocked"===s?(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})}),c9=(0,r.memo)(function(e){let{sessionId:t,placeholder:s}=e,r=(0,f.B)(e=>e.drafts[t]??"").replace(/\s+/g," ").trim();return r?(0,n.jsx)("span",{className:"text-text",children:r}):(0,n.jsx)(n.Fragment,{children:s})}),c7=(0,r.memo)(function(e){let{bus:t,busRef:s,connected:l,carrier:a,platform:i,hostVersion:o,agentVersion:c,sessions:d,workspaces:m,activeSessionId:x,activeSession:p,activeWorkspaceId:h,openedSessions:b,livePanes:g,mountedWorkspaces:v,cwdBySession:y,sessionStatus:w,notifications:j,isDesktop:k,isTerminalView:N,slideClass:C,shells:S,pairDashboard:T=null,welcomeActive:E=!1,sidebarCollapsed:R,sidebarWidth:M,setSidebarWidth:$,toggleSidebar:z,paneWidth:A=null,setPaneWidth:I,paneRegistry:D,bindSwipeTab:L,nav:B,onBack:F,onOpenRemote:O,onOpenMobile:_,onOpenRemoteHost:K=null,onOpenMobileHost:W=null,onOpenFiles:H,onLogout:q,onRenameHost:U,onDeleteHost:X,onMainDisconnect:V,onDeleteWorkspace:G,onRenameWorkspace:J,onReorderSession:Y,onSetHiddenRepos:Z,atStackBottom:Q=!1,onAddWorkspace:ee,onOpenSettings:et,homeDir:es,recentWorkspaces:er,rightPanel:ea,editorPanel:ei,mobilePanel:eo,onOpenArtifact:ec,fileBus:em,browserPanel:ex=null,browserVisible:ep=!0,onCreateAnyHost:eh,onQuickCreateHostAware:ef,tunnelUrl:eb,apiKey:ev,connectionMode:ey,onResumeAgentSessionForeign:ew=null,subscribeToPush:ej,unsubscribeFromPush:eN}=e,{t:eC}=(0,eu.s)(),eS="mouse"===sj(),eT=(0,u.d)(e=>e.bus),eE=(0,u.d)(e=>e.busRef),eR=(0,u.d)(e=>e.connected),ez=(0,u.d)(e=>e.carrier),eP=t||eT,eA=s||eE,eI=(0,r.useMemo)(()=>d.filter(e=>!e.hostKey),[d]),eD=(0,r.useMemo)(()=>m.filter(e=>!e.hostKey),[m]),eL=(0,r.useCallback)(e=>{let t=e$(e);return t.head?t.bus:eP},[eP]),eB=l??eR,eF=em||en.getState(),eO=(0,r.useMemo)(()=>p?.hostKey?eM(p.hostKey).fileBus:eF,[p?.hostKey,eF]),{panesContainerRef:e_,registerPaneApi:eK,registerPaneElement:eW,registerKeyboardTextApi:eH,handlePasteFallback:eq,handleInputFocusChange:eU,focusKeyboardInput:eX,scrollPaneIntoView:eV}=D,[eG,eJ]=(0,r.useState)(null),{workspaceSessionIds:eY,workspaceOpenedSessions:eQ,renderedSessions:e0,mountedSet:e1,workspaceIndex:e2}=(0,r.useMemo)(()=>(0,e5.gk)({sessions:d,openedSessions:b,livePanes:g,mountedWorkspaces:v,activeWorkspaceId:h,isDesktop:k}),[d,b,g,v,h,k]),e3=(0,r.useMemo)(()=>d.filter(e=>(0,e5.xs)(e)===h),[d,h]),e4=(0,r.useMemo)(()=>new Map(e3.map((e,t)=>[e.id,t])),[e3]),e6=m.find(e=>e.id===h),e8=e6?.path||p?.workspacePath||null,e9=rk(e8,eO),e7=(0,f.B)(e=>e.rightPanelRoots),te=(0,f.B)(e=>e.agentBySession),tt=(0,f.B)(e=>e.fullModes||{})[h??e5.AD]??!1,ts=(0,f.B)(e=>e.hiddenPaneSessionIds||[]),tn=(0,f.B)(e=>e.setRightPanelRoot),tr=(0,f.B)(e=>e.openRightPanel),tl=(0,f.B)(e=>e.reorderOpenedSessions),ta=(0,r.useCallback)(e=>{tl(e),Y?.(e)},[tl,Y]),ti=(0,r.useCallback)(e=>{B.handleSelectSession(e)},[B]),to=!!d.find(e=>e.id===x)?.hostKey,tc=e6?.hostKey||null,td=eM(tc).busRef,[tu,tm]=(0,r.useState)([]),tx=(0,P.rh)(e=>tc&&e.hosts[tc]?.status||null),tp=(0,P.rh)(e=>e.hosts),th=(0,P.rh)(e=>e.currentKey);(0,r.useEffect)(()=>{tc&&eM(tc).bus?.emit("getShells",e=>tm(e?.shells||[]))},[tc,tx]);let tf=c3(e=>{let t=t5.find(t=>t.id===te[e]);if(!t)return;let s=d.filter(t=>t.id!==e&&(0,e5.xs)(t)===(h??null)).length+1;B.handleReplaceSession(e,`${t.short||t.label} ${s}`,t,!0)}),tb=e7[e8]||e8,tg=c3((e,t)=>{let s=d.find(t=>t.id===e)?.workspacePath;tn(s,t||s),tr()}),tv=(0,r.useCallback)(e=>ea?.onTabChange(e,e8??""),[ea,e8]),ty=(0,r.useCallback)(()=>H?.(tb),[H,tb]),tj=(0,r.useMemo)(()=>e6?.hiddenRepos||[],[e6?.hiddenRepos]),tk=(0,r.useCallback)(e=>{e6&&Z?.(e6.id,e)},[e6,Z]),tN=x&&(y[x]||d.find(e=>e.id===x)?.cwd)||null;(0,r.useEffect)(()=>{tn(e8,null)},[x,e8,tn]);let tC=!d.length,tS=(0,P.rh)(e=>Object.keys(e.hosts).length),tT=tC&&!m.length&&tS<=1&&!(ex&&ep),[tE,tR]=(0,r.useState)(!1);ea?.open&&!tE&&tR(!0);let[tM,t$]=(0,r.useState)(!1);!ea?.open&&tM&&t$(!1),(0,r.useEffect)(()=>{if(!ea?.open)return;let e=requestAnimationFrame(()=>t$(!0));return()=>cancelAnimationFrame(e)},[ea?.open]);let tz=!!ei?.filePath,[tP,tA]=(0,r.useState)(!1);tz&&!tP&&tA(!0);let[tI,tD]=(0,r.useState)(!1);!tz&&tI&&tD(!1);let[tL,tB]=(0,r.useState)(null);tz&&tL?.filePath!==ei.filePath&&tB({filePath:ei.filePath,artifactTitle:ei.artifactTitle,previewSeq:ei.previewSeq}),(0,r.useEffect)(()=>{if(!tz)return;let e=requestAnimationFrame(()=>tD(!0));return()=>cancelAnimationFrame(e)},[tz]);let[tF,tO]=(0,r.useState)(0),[t_,tK]=(0,r.useState)(!1),tW=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!k)return;let e=tW.current;if(!e)return;let t=new ResizeObserver(e=>tO(e[0].contentRect.width));return t.observe(e),()=>t.disconnect()},[k]),(0,r.useEffect)(()=>{if(!eB||!eP?.emit)return;let e=!1,t=()=>eP.emit("bg:get",{},t=>{!e&&t?.success&&t.dataUrl&&f.B.getState().setCustomBackgrounds([{id:"custom",dataUrl:t.dataUrl}])}),s=setTimeout(()=>{e||t()},eg._O);return eP.emit("bg:list",{},n=>{e||(clearTimeout(s),n?.success&&Array.isArray(n.items)?f.B.getState().setCustomBackgrounds(n.items):t())}),()=>{e=!0,clearTimeout(s)}},[eB,eP]);let tH=(0,r.useMemo)(()=>eQ.filter(e=>!ts.includes(e)),[eQ,ts]).length,tq=(ea?.open&&tM?ea.width:0)+(tz&&tI?ei.width:0)+(eo?.open&&"pin"===eo.mode?eo.width:0),tU=(0,e5.Jc)({rowWidth:tF,paneCount:tH,sidebarWidth:R?0:M,sidePx:tq,gapPx:eg.pS,paddingPx:eg.Jv,minWidth:eg.k9.min}),tX=A??tU,tV=(0,r.useRef)({editorFile:ei?.filePath,rightOpen:ea?.open});(0,r.useEffect)(()=>{if(!k||!x)return;let e=tV.current,t=e.editorFile!==ei?.filePath||e.rightOpen!==ea?.open;if(tV.current={editorFile:ei?.filePath,rightOpen:ea?.open},!t)return;let s=setTimeout(()=>{eV(x)},260);return()=>clearTimeout(s)},[ei?.filePath,ea?.open,x,k,eV]),(0,r.useEffect)(()=>{k&&tt&&e_.current&&(e_.current.scrollLeft=0)},[k,tt,e_]);let tG=e=>{let t=tX??e.currentTarget.parentElement?.offsetWidth??eg.k9.min;tK(!0),eZ(e,{startWidth:t,onWidth:e=>I?.(e),onEnd:()=>tK(!1)})},tJ=(0,r.useCallback)(()=>I?.(null),[I]),[tY,tZ]=(0,r.useState)(null),tQ=(0,r.useRef)(null),t0=nK(tQ,tY?.x??0,tY?.y??0),t1=(0,r.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),tZ({x:e.clientX,y:e.clientY})},[]),t2=(0,r.useCallback)(e=>{if("auto"===e)tJ();else{let t=e_.current?.clientWidth||tF-(R?0:M)-tq;if(t>0){let s=Math.max(eg.k9.min,Math.floor((t-(e-1)*eg.pS)/e));I?.(s)}}tZ(null)},[tJ,e_,tF,R,M,tq,I]);(0,r.useEffect)(()=>{if(!tY)return;let e=e=>{tQ.current&&!tQ.current.contains(e.target)&&tZ(null)},t=e=>{"Escape"===e.key&&tZ(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)}},[tY]),(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&&t2(e.detail.fraction)};return window.addEventListener("terminal:splitPreset",e),()=>window.removeEventListener("terminal:splitPreset",e)},[t2]);let t3=function(e,t,s){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,l=d.find(t=>t.id===e),a=l?.hostKey?eM(l.hostKey).fileBus:eF,i=te[e],o=t5.find(e=>e.id===i);return o?(0,n.jsx)(c5,{title:"AI Chat Pane",children:(0,n.jsx)(c2,{sessionId:e,engine:o.aiEngine,workspacePath:l?.cwd||l?.workspacePath||e6?.path,sessionName:l?.name,bus:eL(e),fileBus:a,isVisible:t,isFocused:s,isDesktop:k,bgIndex:r,onActivate:B.handleSelectSession,onNewChat:tf,onOpenRemote:O,onOpenMobile:_,onOpenArtifact:ec})},e):(0,n.jsx)(rX,{workspacePath:l?.workspacePath,sessionName:l?.name,bus:eL(e),fileBus:a,connected:eB,sessionId:e,isVisible:t,isFocused:s,onActivate:B.handleSelectSession,onRegisterApi:eK,onPasteFallback:eq,showFocusBorder:!1,mountDelay:(0,e5.Mt)(e,s,e2),bgIndex:r,onOpenArtifact:ec,onOpenRemote:O,onOpenMobile:_})},t4=e=>(0,n.jsx)(s8,{bus:eL(e),sessionId:e,onExpandChange:c4,onRegisterTextApi:eH,onInputFocusChange:eU,platform:i,onInput:ek.getState().clearNotification,onSwitchSession:B.switchSession,onSwitchToIndex:B.switchToIndex,isDesktop:k,statusStrip:(0,n.jsx)(ip,{sessionId:e,busRef:eA,onReveal:tg})}),t6=!!(T||E),t8=!!ex,t9=t8&&ep;return(0,n.jsxs)("div",{className:`absolute inset-0 flex flex-col ${N||t9||T||E?"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 ${k?"flex flex-row":"flex flex-col"}`,children:[k&&(0,n.jsx)("div",{className:"hidden sm:block overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out",style:{width:R?0:M},children:(0,n.jsx)(a9,{allSessions:d,mainSessions:eI,workspaces:eD,activeSessionId:x,activeWorkspaceId:h,onSelectSession:B.handleSelectSession,onSelectWorkspace:B.handleSelectWorkspace,onCreateNamedSession:B.handleCreateSession,onResumeAgentSession:to?ew:B.handleResumeAgentSession,shells:S,onRenameSession:B.handleRenameSession,onDeleteSession:B.handleDeleteSession,onReorderSession:ta,onDeleteWorkspace:G,onAddWorkspace:ee,onRenameWorkspace:J,onOpenSettings:et,onOpenRemoteHost:K,onOpenMobileHost:W,onLogout:q,onRenameHost:U,onMainDisconnect:V,onDeleteHost:X,busRef:eA,homeDir:es,cwdBySession:y,connected:eB,width:M,onResize:$,onCollapse:z})}),(0,n.jsxs)("div",{className:"relative flex-1 min-w-0 min-h-0 flex flex-col",children:[k&&R&&(T||E)&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),z()},title:tw(eC("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})}),T&&(0,n.jsx)("div",{className:"absolute inset-0 z-[60] overflow-hidden bg-bg",children:T}),E&&!T&&(0,n.jsx)("div",{className:"absolute inset-0 z-[60] overflow-y-auto bg-bg",children:(0,n.jsx)(cx,{onAddWorkspace:ee,onOpenRemote:O,recent:er,homeDir:es,onOpenRecent:e=>ee?.(e)})}),!t6&&(!tC||!k)&&(0,n.jsx)(rf,{sessions:e3,allSessions:d,activeSessionId:x,isActive:N,connected:eB,onSwitchSession:ti,onCreateSession:tc?ef:B.handleQuickCreateSession,onRenameSession:B.handleRenameSession,onDeleteSession:B.handleDeleteSession,onCreateNamedSession:eh,modalBusRef:td,modalHostKey:tc||"main",modalShells:tc?tu:null,onResumeAgentSession:to?ew:B.handleResumeAgentSession,onBack:k||Q?null:F,workspaces:m,activeWorkspaceId:h,onSelectWorkspace:B.handleSelectWorkspace,hasUngrouped:d.some(e=>!(0,e5.xs)(e)),onOpenRemote:O,onOpenMobile:_,onOpenRemoteHost:K,onOpenMobileHost:W,hostKey:tc,onOpenFiles:H,onLogout:q,tunnelUrl:eb,apiKey:ev,connectionMode:ey,subscribeToPush:ej,unsubscribeFromPush:eN,hostVersion:o||c,agentVersion:o||c,busRef:eA,carrier:a||ez,shells:S,onToggleSidebar:k?z:null,sidebarCollapsed:R,onReorderSession:ta,onToggleRightPanel:ea?.onToggle,rightPanelOpen:ea?.open,fileBus:eF,homeDir:es,isDesktop:k}),tT?(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(cx,{onAddWorkspace:ee,onOpenRemote:O,recent:er,homeDir:es,onOpenRecent:e=>ee?.(e)})}):(0,n.jsxs)("div",{ref:e_,className:`flex-1 min-h-0 ${t6?"hidden":""} ${k?`relative flex flex-row ${tt?"overflow-hidden":"overflow-x-auto"} overflow-y-hidden px-0 pb-0 scrollbar-none`:"relative"}`,...L({enabled:!k,sessionIds:eQ,activeSessionId:x,onSwitch:B.handleSelectSession}),children:[t8&&(0,n.jsx)("div",{className:`absolute inset-0 z-10 ${ep?"":"hidden"}`,children:ex}),e0.map(e=>{let t=eY.has(e),s=e===x,r=ts.includes(e),l=t&&!r&&(k&&!tt||s),a=!!tp[e$(e).head||th]?.updating,i=e4.get(e)??0;return(0,n.jsxs)("div",{ref:t=>eW(e,t),className:t9||!t||k&&tt&&!s||k&&r?"hidden":k?`h-full relative bg-bg ${a?"opacity-50 pointer-events-none":""} ${tt?"w-full flex-1":`border-r-2 border-border-subtle last:border-r-0 ${t_?"":"transition-[width] duration-200 ease-out"}`}`:`absolute inset-0 ${a?"opacity-50 pointer-events-none":s?`opacity-100 z-10 ${C}`:"opacity-0 z-0 pointer-events-none"}`,style:t&&k?tt?{width:"100%",flex:"1 1 0"}:null!=tX?{width:tX,flexShrink:0}:{flex:"1 1 0",minWidth:eg.k9.min}:void 0,children:[e1.has(e)?te[e]?.endsWith("-ui")?(0,n.jsx)("div",{onMouseDown:()=>{s||B.handleSelectSession(e)},onTouchStart:()=>{s||B.handleSelectSession(e)},className:"w-full h-full flex flex-col relative overflow-hidden",children:t3(e,l,s,i)}):k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(c6,{children:[t3(e,l,s,i),(0,n.jsx)(c8,{sessionId:e})]}),(0,n.jsx)("div",{className:"absolute inset-x-0 bottom-0 z-20 border-t border-border-subtle bg-surface",children:s?t4(e):(0,n.jsx)("button",{type:"button",tabIndex:-1,onClick:()=>{B.handleSelectSession(e),setTimeout(eX,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)(c9,{sessionId:e,placeholder:eC("mobileKeyboard.typeCommand")})})})})]}):t3(e,l,s,i):(0,n.jsx)("div",{className:"w-full h-full flex items-center justify-center text-text-muted text-xs"}),t&&k&&!tt&&!r&&(0,n.jsx)("div",{onPointerDown:tG,onDoubleClick:tJ,onContextMenu:t1,className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-30",title:eS?tw(eC("shortcuts.fitPanes")||"Auto-fit panes","fitPanes"):void 0})]},e)})]}),!k&&x&&!te[x]?.endsWith("-ui")&&t4(x)]}),(ei?.filePath||k&&tP)&&(0,n.jsx)("div",{className:k?"overflow-hidden flex-shrink-0 transition-[width] duration-200 ease-out":"absolute inset-0 z-40 sheet-rise",style:k?{width:tz&&tI?ei.width:0}:void 0,"aria-hidden":k&&!tz,children:(0,n.jsx)(ci,{filePath:tz?ei.filePath:tL?.filePath,artifactTitle:tz?ei.artifactTitle:tL?.artifactTitle,previewSeq:tz?ei.previewSeq:tL?.previewSeq,jump:tz?ei.jump:null,workspace:tb,fileBus:eO,width:ei.width,onResize:ei.onResize,onClose:ei.onClose,onOpenFull:ei.onOpenFull,onOpenFile:ei.onOpen,isDesktop:k})}),k&&eo?.open&&"pin"===eo.mode&&(0,n.jsx)("div",{ref:eJ,className:"relative overflow-hidden flex-shrink-0 border-l border-border",style:{width:eo.width},children:(0,n.jsx)("div",{onPointerDown:eo.onResizeStart,className:"absolute top-0 left-0 bottom-0 w-1 cursor-col-resize hover:bg-brand-500/40 transition-colors z-20"})}),k&&eo?.open&&(0,n.jsx)(i$,{busRef:eo.busRef||eA,protocolRef:eo.protocolRef,connected:eo.connected??eB,pinSlot:eG}),ea?.open&&!k&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 scrim fade-in",onClick:ea.onToggle}),(ea?.open||k&&tE)&&(0,n.jsx)("div",{className:k?"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 screen-in",style:k?{width:ea?.open&&tM?ea.width:0}:void 0,"aria-hidden":k&&!ea?.open,children:(0,n.jsx)(oP,{workspacePath:e8,filesRoot:tb,cwdHint:tN,activeFile:ei?.filePath,fileBus:eO,tab:ea.tabs?.[e8??""]||"files",onTabChange:tv,width:ea.width,onResize:ea.onResize,onClose:ea.onToggle,onOpenFiles:H?ty:null,onOpenFile:ei?.onOpen,onNewTerminal:ea.onNewTerminal,onAddWorkspace:ee,homeDir:es,hiddenRepos:tj,changedPerRepo:e9.perRepo,onHiddenReposChange:e6&&Z?tk:null,isDesktop:k})})]}),(0,n.jsx)(co,{}),k&&!tC&&(0,n.jsx)(ih,{cwd:x&&(y[x]||p?.cwd||e6?.path)||"",sessionId:x,hostKey:p?.hostKey||null,sessionName:p?p?.name:"",hostVersion:o||c,agentVersion:o||c,platform:i,homeDir:es}),tY&&(0,n.jsxs)("div",{ref:tQ,className:"fixed z-[70] menu-popover p-1 min-w-[130px] pop-in shadow-xl",style:{left:t0.left,top:t0.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)(),t2("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)(),t2(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)(),t2(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)(),t2(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 de=s(14337);function dt(e){let{label:t,inline:s=!1}=e,{t:l}=(0,eu.s)(),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=setTimeout(()=>i(!0),6e3);return()=>clearTimeout(e)},[]),(0,n.jsxs)("div",{className:`${s?"absolute inset-0 z-10":"fixed inset-0 z-40"} flex items-center justify-center fade-in`,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)(de.A,{size:"lg"}),(0,n.jsx)("p",{className:"text-sm text-text-muted",children:t||l("connection.retrying")}),a&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),c(!0);try{sessionStorage.setItem("9remote_manual_disconnect","1")}catch{}setTimeout(()=>window.location.reload(),150)},disabled:o,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 fade-in",children:[(0,n.jsx)(el.e9,{size:14,className:`text-brand-500 ${o?"animate-spin":""}`}),(0,n.jsx)("span",{children:l("menu.reloadWeb")||"Reload"})]})]})]})}var ds=s(39634);function dn(e){let t,{sessions:s,cwdBySession:l={},connected:a,onSelect:i,onCreate:o,onDelete:c,onRename:d,onLogout:x,onOpenRemote:p,tunnelUrl:h,apiKey:b,connectionMode:g="tunnel",isActive:v=!0,busRef:y,subscribeToPush:w,unsubscribeFromPush:j,onResumeAgentSession:k=null,notifications:N,sessionStatus:C,hostVersion:S,agentVersion:T,carrier:E,workspaces:R=[],onRenameWorkspace:M,onDeleteWorkspace:$,onAddWorkspace:z,onOpenRemoteHost:A=null,onOpenMobileHost:I=null,fileBus:D,homeDir:L,recentWorkspaces:B=[],shells:F=[],onReorderSession:O,onRenameHost:_=null,onDeleteHost:K=null,onMainDisconnect:W=null,onMainReconnect:H=null}=e,{t:q}=(0,eu.s)(),U=D||en.getState(),X=Object.values((0,P.rh)(e=>e.hosts)),V=(0,P.rh)(e=>e.currentKey),G=X.find(e=>e.key===V),J=(0,u.d)(e=>e.connected),Y=(0,u.d)(e=>e.carrier),Z=(0,u.d)(e=>e.busRef),Q=a??J,ee=E||Y||"ws",et=y||Z,es=ek(e=>e.notifications),er=eI(),ea=N||es,ei=C||er;ey(e=>e.open);let eo=ey(e=>e.setContext),ec=ey(e=>e.setCallbacks),em=(0,f.B)(e=>e.pushView),ex=(0,m.gJ)(),[ep,eh]=(0,r.useState)(null),[ef,eb]=(0,r.useState)(null),[eg,ev]=(0,r.useState)(!1),[ew,ej]=(0,r.useState)(!1),eN=eT(X,G?.key);(0,r.useEffect)(()=>{if(!v)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.altKey&&!e.shiftKey&&"t"===e.key.toLowerCase()&&(e.preventDefault(),eb({workspaceId:null}))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[v]),(0,r.useEffect)(()=>{v&&(eo({connected:Q,remoteAvailable:!!p,showTheme:!1,theme:"default",busRef:et,hideActions:["remote","files","sites"],tunnelUrl:h,apiKey:b,connectionMode:g,subscribeToPush:w,unsubscribeFromPush:j,notifications:ea,hostVersion:S||T,agentVersion:S||T,carrier:ee}),ec({onRemote:null,onFiles:null,onSelectSite:null,onRefreshSites:null,onLogout:x,onThemeChange:null}))},[v,Q,p,x,eo,ec,et,g,w,j,S,T,ee,h,b,ea]);let eC=new Set(s.map(e=>e.id)),eS=!X.some(e=>e.updating)&&!s.length&&!R.length&&X.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 pl-[28px] pr-4 py-3 flex items-center justify-between gap-2 flex-shrink-0",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:q("sessions.headerTitle")}),(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${Q?"bg-green-500":"bg-red-500 animate-pulse"}`,title:q(Q?"sessions.connected":"sessions.disconnected")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)(dr,{icon:el.e9,iconClass:ew?"animate-spin":"",label:q("menu.reload"),disabled:ew,onClick:()=>{ej(!0),setTimeout(()=>window.location.reload(),300)}}),(0,n.jsx)(dr,{icon:el.kV,label:q("hosts.addHost"),onClick:()=>{(0,ed.e)(),ev(!0)}}),ex&&(0,n.jsx)(dr,{icon:el.vW,label:q("connection.pairTab"),onClick:()=>{(0,ed.e)(),em({type:"pair"})}})]})]}),(0,n.jsx)("div",{className:"relative z-10 flex-1 overflow-auto modal-scrollable pt-2 pb-[calc(94px_+_var(--safe-bottom))]",style:{overflowAnchor:"none"},children:eS?(0,n.jsx)("div",{className:"absolute inset-0 z-10",children:(0,n.jsx)(dl,{onAddWorkspace:z,recent:B,homeDir:L,connected:Q})}):(0,n.jsx)(n.Fragment,{children:eN.map((e,t)=>(0,n.jsx)("div",{className:0===t?"pl-1 pr-3":"mt-3 border-t border-border-subtle pt-2 pl-1 pr-3",children:e.key===(G?.key||"main")&&G?(0,n.jsx)(a4,{mobile:!0,host:{...G,workspaces:R,sessions:s,statusMap:ei,onDisconnect:W,onConnect:H},busRef:et,onResumeAgentSession:k,actions:{selectSession:i,createSession:o,renameSession:d,deleteSession:c,backgroundSession:e=>eh(e),reorderSession:O,renameWorkspace:M,deleteWorkspace:$,renameHost:_,deleteHost:K},connected:Q,fileBus:U,homeDir:L,cwdBySession:l,onAddWorkspace:z,menuAddWorkspace:z,onOpenRemoteHost:A,onOpenMobileHost:I,treeCls:"pl-5",rowCls:"active:bg-surface-2 active:text-text"}):(0,n.jsx)(a4,{mobile:!0,host:{...e,onDisconnect:()=>P.rh.getState().disconnectHost(e.key)},actions:{...ti(e,{onSelectSession:i}),renameHost:_,deleteHost:K},connected:Q,onOpenRemoteHost:A,onOpenMobileHost:I,treeCls:"pl-5",rowCls:"active:bg-surface-2 active:text-text"})},e.key))})}),ep&&(0,n.jsx)(nU,{sessionId:ep.id,title:ep.name,busRef:et,onClose:()=>eh(null)}),ef&&(0,n.jsx)(n_,{onClose:()=>eb(null),onCreate:(e,t,s,n,r,l)=>{o?.(e,ef.workspaceId,t,r||null,s,n,l),eb(null)},shells:F,busRef:et,onResumeAgentSession:k,onSelectSession:i,liveSessionIds:eC,connected:Q,workspaceId:ef.workspaceId,workspacePath:R.find(e=>e.id===ef.workspaceId)?.path||null,workspaceName:R.find(e=>e.id===ef.workspaceId)?.name||"",fileBus:U,homeDir:L,suggestName:`${q("terminal.defaultName")} ${(t=ef.workspaceId,s.filter(e=>(0,e5.xs)(e)===t)).length+1}`}),eg&&(0,n.jsx)(rQ,{onClose:()=>ev(!1)})]})}function dr(e){let{icon:t,iconClass:s="",label:r,onClick:l,disabled:a,className:i=""}=e;return(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),l()},disabled:a,title:r,className:`p-2 rounded-brand transition-colors active:scale-[0.96] ${a?"text-text-subtle cursor-not-allowed":`text-text-muted hover:text-text hover:bg-surface-2 ${i}`}`,children:(0,n.jsx)(t,{className:`w-5 h-5 ${s}`})})}function dl(e){let{onAddWorkspace:t,recent:s,homeDir:l,connected:a}=e,{t:i}=(0,eu.s)();(0,f.B)(e=>e.pushView);let[o,c]=(0,r.useState)(!1);return(0,n.jsxs)("div",{className:"empty-stage w-full h-full fade-in",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),t?.()},disabled:!a,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"})," / ",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,3).map(e=>(0,n.jsx)("span",{role:"button",title:e.path,onClick:s=>{s.stopPropagation(),(0,ed.e)(),t?.(e.path)},className:"welcome-chip path-tail px-2 py-1 text-[11px] font-mono text-text-muted rounded-full truncate max-w-[46%]",children:cd(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 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"})," / ",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)(cu,{})}),(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)(rQ,{onClose:()=>c(!1)})]})}let da=(e,t,s)=>Math.max(t,Math.min(s,e));function di(e){let{clientX:t,clientY:s,containerRect:n,pan:r,totalScale:l}=e;return{x:(t-n.left-r.x)/l,y:(s-n.top-r.y)/l}}function dc(e,t){return{x:Math.min(0,e.width-t.width),y:Math.min(0,e.height-t.height)}}function dd(e,t){return{x:da(e.x,t.x,0),y:da(e.y,t.y,0)}}function du(e){let{prevZoom:t,prevPan:s,focal:n,nextZoomRaw:r,maxZoom:l,containerSize:a,displaySizeAt:i}=e,o=da(r,1,l),c=o/t,d=dc(a,i(o));return{zoom:o,pan:dd({x:n.x-(n.x-s.x)*c,y:n.y-(n.y-s.y)*c},d)}}function dm(e){let{accum:t,delta:s,threshold:n,multiplier:r}=e,l=t+s;if(Math.abs(l)<n)return{accum:l,scroll:null};let a=Math.max(1,Math.round(Math.abs(l)*r));return{accum:0,scroll:l>0?a:-a}}function dx(e){let{emits:t,streaming:s,hostPlatform:n,storagePrefix:l="remoteDesktop",defaultPointerMode:a=c.eR.pointerMode,hoverMove:i=!1,wheelMultiplier:o,intercept:d,interceptKey:u,stageLockRef:m}=e,x=e=>`${l}.${e}`,[p,h]=sN(x("showTextPanel"),!0),[f,b]=sN(x("keyboard"),!1),[g,v]=sN(x("controlsHidden"),!1),[y,w]=sN(x("pointerMode"),a),[j,k]=sN(x("handMode"),!1),N=sj(),C=c.eR.pcModeControls,[S,T]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=window.matchMedia("(orientation: landscape)"),t=()=>T(e.matches);return t(),e.addEventListener?.("change",t),()=>e.removeEventListener?.("change",t)},[]);let E=S&&Math.min(window.screen.width,window.screen.height)>=700;(0,r.useEffect)(()=>{"mouse"===N&&"direct"!==y&&w("direct")},[N,y,w]);let{emitRequestScreenWithHashes:R,emitMousePress:M,emitMouseRelease:$,emitMouseClick:z,emitMouseMove:P,emitMouseDragSelect:A,emitKeyPress:I,emitTypeText:D,emitScroll:L,emitBoostStream:B,emitSetFocus:F}=t,O={emitRequestScreenWithHashes:R,emitMousePress:M,emitMouseRelease:$,emitMouseClick:z,emitMouseMove:P,emitMouseDragSelect:A,emitKeyPress:I,emitTypeText:D,emitScroll:L,emitBoostStream:B},_=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{stageLockRef:t}=e,s=(0,r.useRef)(null),n=(0,r.useRef)(null),[l,a]=(0,r.useState)(1),[i,o]=(0,r.useState)({x:0,y:0}),[d,u]=(0,r.useState)(1),[m,x]=(0,r.useState)({width:0,height:0}),p=(0,r.useRef)({width:0,height:0}),h=(0,r.useRef)({x:0,y:0}),f=d*l,b=(0,r.useCallback)(()=>{let e=n.current;return e?{width:e.clientWidth,height:e.clientHeight}:null},[]),g=(0,r.useCallback)(e=>({width:m.width*e,height:m.height*e}),[m]),v=(0,r.useCallback)((e,t)=>{let r=s.current,a=n.current;return r&&a&&0!==r.width?function(e){let{canvasPoint:t,canvasWidth:s,canvasHeight:n}=e;return{percentX:da(t.x/s*100,0,100),percentY:da(t.y/n*100,0,100)}}({canvasPoint:di({clientX:e,clientY:t,containerRect:a.getBoundingClientRect(),pan:i,totalScale:d*l}),canvasWidth:r.width,canvasHeight:r.height}):{percentX:0,percentY:0}},[i,l,d]),y=(0,r.useCallback)((e,t)=>{let s=d*l;s<=0||(h.current={x:(e-i.x)/s,y:(t-i.y)/s})},[d,l,i]),w=(0,r.useCallback)(()=>{a(1),o({x:0,y:0})},[]),j=(0,r.useCallback)(()=>o({x:0,y:0}),[]),k=(0,r.useCallback)((e,t)=>{let s=b();if(!s)return;let n=d*l;if(n<=0)return;let r=t||h.current,a=dc(s,g(l));o(t=>{if(!e||l<=1&&a.y>=0)return dd(t,a);let{y:i}=function(e){let{focus:t,containerHeight:s,totalScale:n}=e;return{y:s/3-t.y*n}}({focus:r,containerHeight:s.height,totalScale:n});return dd({x:t.x,y:i},a)})},[b,g,d,l]),N=(0,r.useCallback)(()=>{let e=n.current,r=s.current,l=p.current;if(!e||!r||0===l.width||0===l.height)return;let a=t?.current,i=a?.kbShrunk&&a.height?a.height:e.clientHeight,o={width:e.clientWidth,height:i};if(0===o.width||0===o.height)return;let c=Math.min(o.width/l.width,o.height/l.height);u(c),x({width:l.width*c,height:l.height*c})},[t]);(0,r.useEffect)(()=>{let e=null,t=null,s=()=>{let e=n.current;if(!e)return void N();let s=e.clientWidth,r=e.clientHeight,l=0,a=0,i=()=>{let n=e.clientWidth,o=e.clientHeight;if(n===s&&o===r){if(++l>=c.eR.resizeStableFrames){t=null,N();return}}else l=0,s=n,r=o;if(a++>=c.eR.resizeMaxFrames){t=null,N();return}t=requestAnimationFrame(i)};t=requestAnimationFrame(i)},r=()=>{e&&clearTimeout(e),t&&(cancelAnimationFrame(t),t=null),e=setTimeout(s,c.eR.resizeDebounceMs)};return window.addEventListener("resize",r),window.addEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.addEventListener("resize",r),()=>{e&&clearTimeout(e),t&&cancelAnimationFrame(t),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.removeEventListener("resize",r)}},[N]),(0,r.useEffect)(()=>{o(e=>{let t=n.current;if(!t)return e;let s=dd(e,dc({width:t.clientWidth,height:t.clientHeight},{width:m.width*l,height:m.height*l}));return s.x===e.x&&s.y===e.y?e:s})},[m,l]);let C=(0,r.useCallback)((e,t)=>{p.current={width:e.width,height:e.height};let r=s.current,l=n.current;if(!r||!l)return!1;let a=r.width!==e.width||r.height!==e.height;r.width=e.width,r.height=e.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),t?.current&&t.current.clear()),N(),a},[N]);return{canvasRef:s,canvasContainerRef:n,canvasZoom:l,setCanvasZoom:a,canvasPan:i,setCanvasPan:o,fitScale:d,totalScale:f,baseCanvasSize:m,serverDimensionsRef:p,containerSize:b,displaySizeAt:g,getCanvasCoordinates:v,recordInteractPx:y,resetZoom:w,resetPan:j,panForKeyboard:k,handleCanvasDimensions:C,recalculateDisplaySize:N}}(t),{canvasRef:n,canvasContainerRef:l,canvasZoom:a,setCanvasZoom:i,canvasPan:o,setCanvasPan:d,fitScale:u,baseCanvasSize:m,containerSize:x,displaySizeAt:p,getCanvasCoordinates:h,recordInteractPx:f}=s,[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),w=(0,r.useRef)(0),j=(0,r.useRef)({x:0,y:0}),[k,N]=(0,r.useState)(!1),C=(0,r.useRef)(null),[S,T]=(0,r.useState)(null),E=(0,r.useRef)(null),R=(0,r.useRef)(!1),M=(0,r.useRef)({x:0,y:0}),$=(0,r.useRef)(0),z=(0,r.useRef)({x:0,y:0}),[P,A]=(0,r.useState)(!1),I=(0,r.useRef)({x:0,y:0}),D=(0,r.useRef)({x:0,y:0}),L=(0,r.useRef)(0),B=(0,r.useRef)(null),[F,O]=(0,r.useState)({x:0,y:0}),_=(0,r.useRef)(0),K=(0,r.useRef)(0),W=(0,r.useRef)(null),H=(0,r.useRef)({time:0,distance:0,centerX:0,centerY:0}),q=(0,r.useRef)(!1),U=(0,r.useRef)(0),X=(0,r.useRef)(!1),V=(0,r.useRef)(null),G=(0,r.useRef)(!1),[J,Y]=(0,r.useState)(!1),Z=(0,r.useRef)(null),Q=(0,r.useRef)(!1),[ee,et]=(0,r.useState)(!1),es=(0,r.useRef)(null),en=(0,r.useRef)({x:0,y:0}),er=(0,r.useRef)(!1),el=(0,r.useRef)(null),ea=(0,r.useRef)(0),ei=(0,r.useCallback)((e,t)=>{let s=l.current;if(!s)return;let n=s.getBoundingClientRect(),r=e-n.left,i=t-n.top,o=da(7.5*a,5,15);f(r,i),T({x:r,y:i,size:o}),setTimeout(()=>T(null),500)},[a,l,f]),eo=(0,r.useCallback)(()=>{E.current&&(clearTimeout(E.current),E.current=null)},[]),ec=(0,r.useCallback)((t,s,n,r)=>{eo(),R.current=!1,M.current={x:t,y:s},E.current=setTimeout(()=>{R.current=!0,ei(t,s),e?.emitMouseClick(n,r,"right")},c.eR.longPressDelay)},[eo,ei,e]),eu=(0,r.useCallback)((e,t)=>{let s=Date.now(),n=function(e){let{now:t,lastTime:s,lastPos:n,x:r,y:l,cfg:a}=e,i=Math.abs(r-n.x),o=Math.abs(l-n.y);return t-s<a.doubleClickDelay&&i<a.moveThreshold&&o<a.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},[]),em=(0,r.useCallback)(()=>{B.current&&(cancelAnimationFrame(B.current),B.current=null),D.current={x:0,y:0},I.current={x:0,y:0},A(!1)},[]),ex=(0,r.useCallback)(()=>{let t=()=>{var s,n;let r=(s=D.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 em();Math.abs(r.scrollY)>=1&&e?.emitScroll(r.scrollY>0?"up":"down",Math.abs(r.scrollY),!1),D.current=r.nextVelocity,B.current=requestAnimationFrame(t)};B.current=requestAnimationFrame(t)},[e,em]);(0,r.useEffect)(()=>()=>{eo(),em()},[eo,em]);let ep=(0,r.useCallback)(t=>{let{edgeScrollThreshold:s,edgeScrollMultiplier:n}=c.eR,r=dm({accum:I.current.y,delta:t,threshold:s,multiplier:n});I.current.y=r.accum,r.scroll&&e?.emitScroll(r.scroll>0?"up":"down",Math.abs(r.scroll),!1)},[e]),eh=(0,r.useCallback)(t=>{let{edgeScrollThreshold:s,edgeScrollMultiplier:n}=c.eR,r=dm({accum:I.current.x,delta:t,threshold:s,multiplier:n});I.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:da(e.x/t.width*100,0,100),percentY:da(e.y/t.height*100,0,100)}),[]),eb=(0,r.useCallback)(t=>{let s=n.current;if(!s||0===s.width)return;let{percentX:r,percentY:l}=ef(t,s);e?.emitMouseMove?.(r,l)},[e,n,ef]);(0,r.useEffect)(()=>{let t=t=>{if(null==es.current||t.pointerType&&"mouse"!==t.pointerType)return;let s=n.current,r=l.current;if(!s||!r)return;let{percentX:a,percentY:i}=h(t.clientX,t.clientY),o=es.current;es.current=null,e?.emitMouseRelease?.(a,i,o)};return window.addEventListener("pointerup",t),window.addEventListener("pointercancel",t),()=>{window.removeEventListener("pointerup",t),window.removeEventListener("pointercancel",t)}},[h,e,n,l]);let eg=(0,r.useCallback)((t,s,r)=>{let{streaming:m,pointerMode:f="direct"}=r;if(!m||!e)return;let S={canvasRef:n,canvasContainerRef:l,containerSize:x,displaySizeAt:p,getCanvasCoordinates:h,socketEmitFunctions:e,canvasZoom:a,fitScale:u,virtualCursor:F,canvasPan:o,setCanvasZoom:i,setCanvasPan:d,setVirtualCursor:O,isZooming:b,isPanning:v,isEdgeScrolling:P,recentZoomGesture:k,lastTouchDistanceRef:w,lastTouchCenterRef:j,setIsZooming:g,setIsPanning:y,setIsEdgeScrolling:A,setRecentZoomGesture:N,gestureLockRef:W,gestureStartRef:H,multiTouchLatchRef:q,twoFingerMaxMovedRef:U,touchOutsideRef:X,longPressTriggeredRef:R,touchStartPosRef:M,edgeScrollAccumRef:I,velocityRef:D,lastTouchTimeRef:L,touchStartTimeRef:_,touchTotalMoveRef:K,handLongPressTimerRef:V,handHoldingRef:G,setHandHolding:Y,scrollLongPressTimerRef:Z,scrollLockRef:Q,setScrollLock:et,mouseDownButtonRef:es,wheelAccumRef:en,wheelActiveRef:er,wheelEndTimerRef:el,wheelLastBoostRef:ea,zoomGestureTimeoutRef:C,showClickIndicator:ei,cancelLongPress:eo,startLongPress:ec,checkDoubleClick:eu,stopMomentum:em,startMomentumScroll:ex,emitScrollFromDelta:ep,emitHScrollFromDelta:eh,cursorPercent:ef,emitVirtualCursor:eb};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 m,x;let{percentX:s,percentY:a}=l(t.clientX,t.clientY),i=(m=t.deltaMode,x=c.eR,1===m?x.wheelLineHeight:2===m?x.wheelPageHeight:1),o=t.deltaY*i,d=t.deltaX*i;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},i=o>0?-1:1;e.setCanvasZoom(t=>{let s=da(t+i*c.eR.wheelZoomStep,1,4);return s===t?t:(e.setCanvasPan(n=>du({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,a),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 u=n.wheelMultiplier??c.eR.wheelScrollMultiplier;if(o&&e.emitScrollFromDelta(-o*u),d){let{edgeScrollThreshold:t,edgeScrollMultiplier:s}=c.eR,n=dm({accum:e.wheelAccumRef.current.x,delta:d*u,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:h}=l(t.clientX,t.clientY);if("pointerdown"===s){e.mouseDownButtonRef.current=u,a(t.clientX,t.clientY),r.emitMousePress?.(p,h,u);return}if("pointermove"===s){(null!=e.mouseDownButtonRef.current||n.hoverMove)&&r.emitMouseMove?.(p,h);return}if("pointerup"===s){let t=e.mouseDownButtonRef.current||u;e.mouseDownButtonRef.current=null,r.emitMouseRelease?.(p,h,t)}}(S,t,s,r);t.preventDefault(),t.type.startsWith("touch")&&t.touches?.length>=2&&(q.current=!0,Z.current&&(clearTimeout(Z.current),Z.current=null),Q.current&&(Q.current=!1,et(!1),I.current={x:0,y:0}),V.current&&(clearTimeout(V.current),V.current=null)),"trackpad"===f&&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:m=!1,onHandRelease:x}=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 m&&!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)),m||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(e){let{deltaX:t,deltaY:s,dt:n,cfg:r}=e,l=Math.sqrt(t*t+s*s)/n,a=1+Math.min(r.trackpadAcceleration,l*r.trackpadAcceleration);return r.trackpadSensitivity*a}({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,x=s*i/o;return l?e.setVirtualCursor(t=>{let s={x:da(t.x+d,0,r.width-1),y:da(t.y+x,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}):(m&&!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:da(t.x+d,0,r.width-1),y:da(t.y+x,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(),l={width:r.width*o,height:r.height*o};if(n&&(e.canvasZoom>1||l.height>n.height||l.width>n.width)){let t=dc(n,l);e.setCanvasPan(e=>{let r=function(e){let{cursor:t,pan:s,containerSize:n,displaySize:r,totalScale:l,marginRatio:a}=e,i=n.width*a,o=n.height*a,c=t.x*l+s.x,d=t.y*l+s.y,u={x:0,y:0};return c<i?u.x=i-c:c>n.width-i&&(u.x=-(c-(n.width-i))),d<o?u.y=o-d:d>n.height-o&&(u.y=-(d-(n.height-o))),u}({cursor:s,pan:e,containerSize:n,displaySize:l,totalScale:o,marginRatio:c.eR.trackpadEdgeMarginRatio});return dd({x:e.x+r.x,y:e.y+r.y},t)})}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(m){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),x?.()}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,s,r)||function(e,t,s,n){let r,l,{selectionMode:a,selectionStart:i,dragMode:o,isDragging:d,setIsDragging:u,setDragMode:m,isMobile:x,handleSelection:p,pointerMode:h="direct"}=n;if(t.type.startsWith("touch")&&t.touches?.length>=2&&!a){var f;let n,r,l,a=(n=(f=t.touches)[0].clientX-f[1].clientX,Math.sqrt(n*n+(r=f[0].clientY-f[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(e){let{elapsed:t,deltaDistance:s,deltaCentroid:n,cfg:r}=e,l=s>=r.gestureDistanceThreshold,a=n>=r.gestureCentroidThreshold;if(!l&&!a&&t<r.gestureLockDelay)return null;let i=n>.5?s/n:1/0;return i>=r.gestureDominanceRatio&&l?"zoom":i<=1/r.gestureDominanceRatio&&a?"scroll":l&&!a?"zoom":a&&!l?"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"===h&&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=>du({prevZoom:e.canvasZoom,prevPan:t,focal:r,nextZoomRaw:l,maxZoom:4,containerSize:n,displaySizeAt:e.displaySizeAt}).pan),e.setCanvasZoom(da(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=di({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))},i=e.containerSize()||{width:0,height:0},o=e.displaySizeAt(e.canvasZoom);if(!(o.width>i.width||o.height>i.height)&&1===e.canvasZoom){l&&a(s),e.lastTouchCenterRef.current={x:n.clientX,y:n.clientY};return}e.setIsPanning(!0),e.setCanvasPan(n=>{let r=function(e){let{prevPan:t,deltaX:s,deltaY:n,containerSize:r,displaySize:l}=e,a=dc(r,l),i=dd({x:t.x+s,y:t.y+n},a),o=Math.abs(i.y-t.y)>.5?0:t.y+n-i.y;return{pan:i,overflowY:o}}({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"===h&&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),m(!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),m(!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&&!x){if(a&&i)return p(r,l,"move");e.socketEmitFunctions.emitMouseMove(b,g)}}(S,t,s,r)},[b,v,P,a,k,u,F,o,h,ei,e,eo,ec,eu,em,ex,eb,ep,eh,n,l,x,p,d,i,ef]);(0,r.useEffect)(()=>{let e=n.current;e&&0!==e.width&&O(t=>0===t.x&&0===t.y?{x:e.width/2,y:e.height/2}:t)},[m,n]);let ev=(0,r.useCallback)(()=>{let e=n.current,t=x();if(!e||!t||0===e.width)return;let s=u*a;s<=0||O({x:da((t.width/2-o.x)/s,0,e.width-1),y:da((t.height/2-o.y)/s,0,e.height-1)})},[u,a,o,n,x]),ey=(0,r.useCallback)(()=>{let t=n.current;if(!t||0===t.width||G.current)return;V.current&&(clearTimeout(V.current),V.current=null);let{percentX:s,percentY:r}=ef(F,t);G.current=!0,Y(!0),(0,ed.e)(15),e?.emitBoostStream?.(),e?.emitMousePress?.(s,r,"left")},[F,e,n,ef]),ew=(0,r.useCallback)(()=>{if(!G.current)return;let t=n.current,s=t&&t.width>0?F.x/t.width*100:0,r=t&&t.height>0?F.y/t.height*100:0;e?.emitMouseRelease?.(s,r,"left"),G.current=!1,Y(!1)},[F,e,n]);return{canvasRef:n,canvasContainerRef:l,canvasZoom:a,canvasPan:o,fitScale:u,baseCanvasSize:m,zoomGestureTimeoutRef:C,clickIndicator:S,virtualCursor:F,handHolding:J,scrollLock:ee,getCanvasCoordinates:h,resetZoom:s.resetZoom,resetPan:s.resetPan,panForKeyboard:s.panForKeyboard,centerVirtualCursor:ev,startHandHold:ey,releaseHandHold:ew,handleCanvasInteraction:eg,handleCanvasDimensions:s.handleCanvasDimensions,serverDimensionsRef:s.serverDimensionsRef,recalculateDisplaySize:s.recalculateDisplaySize}}(O,{stageLockRef:m}),{canvasRef:K,canvasContainerRef:W,canvasZoom:H,canvasPan:q,fitScale:U,getCanvasCoordinates:X,centerVirtualCursor:V,startHandHold:G,releaseHandHold:J,handleCanvasInteraction:Y,baseCanvasSize:Z}=_,Q=(0,r.useCallback)(()=>{w(e=>{let t="trackpad"===e?"direct":"trackpad";return"trackpad"===t&&V(),t})},[V,w]),ee=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}),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(null),[f,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)(()=>{x(e=>!e),h(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]),E=(0,r.useCallback)(function(t,s){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];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]),R=(0,r.useCallback)(e=>E("up",e),[E]),M=(0,r.useCallback)(e=>E("down",e),[E]),$=(0,r.useCallback)(e=>E("left",e,!0),[E]),z=(0,r.useCallback)(e=>E("right",e,!0),[E]),P=(0,r.useCallback)(()=>{j.current&&(clearInterval(j.current),j.current=null)},[]),A=sl(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]),O=(0,r.useCallback)(e=>{e&&(F("backspace"),n&&o.current&&a&&o.current.focus())},[n,a,F]),_=(0,r.useCallback)((e,t)=>{t&&(F(e),n&&o.current&&a&&o.current.focus())},[n,a,F]),K=(0,r.useCallback)(e=>{e&&(F("escape"),n&&o.current&&a&&o.current.focus())},[n,a,F]),W=(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]),q=(0,r.useCallback)((t,s,n,r)=>{let{streaming:l,getCanvasCoordinates:a,baseCanvasSize:i,canvasZoom:o,canvasPan:c,percentOverride:d}=r;if(!m||!l||!e?.emitMouseDragSelect)return;let{percentX:u,percentY:f}=d||a(t,s);if("start"===n)h({x:u,y:f}),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,f)*t/100+c.y,width:Math.abs(u-p.x)*e/100,height:Math.abs(f-p.y)*t/100})}else"end"===n&&p&&(e.emitMouseDragSelect(p.x,p.y,u,f),setTimeout(()=>{h(null),x(!1),b(null)},500))},[m,p,e]),U=(0,r.useCallback)(function(n,r){let l=arguments.length>2&&void 0!==arguments[2]&&arguments[2];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,m=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 x=/^[a-z0-9]$/i.test(n.key);if((o||m)&&(!x||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:m,selectionStart:p,selectionRect:f,dragMode:g,isDragging:y,setIsDragging:w,setDragMode:v,toggleModifierKey:k,toggleSelectionMode:N,toggleDragMode:C,handleTextInputFocus:S,handleCanvasKeyPress:T,startScrollUp:R,startScrollDown:M,startScrollLeft:$,startScrollRight:z,stopScrolling:P,sendTextInput:I,sendBackspace:O,sendArrowKey:_,sendEscKey:K,sendTabKey:W,sendEnterKey:H,handleSelection:q,handleModifiedTextInput:U,handleDirectInputChange:B,emitKeyWithActiveModifiers:F}}(O),{textInputRef:et,selectionMode:es,selectionStart:en,dragMode:er,isDragging:el,setIsDragging:ea,setDragMode:ei,toggleSelectionMode:eo,handleCanvasKeyPress:ec,handleSelection:eu,emitKeyWithActiveModifiers:em}=ee,ex=function(e){let{streaming:t,keyboardOn:s,setKeyboardOn:n,showTextPanel:l,setShowTextPanel:a,textInputRef:i,canvasContainerRef:o,panForKeyboard:c,pointerMode:d,virtualCursor:u}=e,m=(0,r.useRef)(s);(0,r.useEffect)(()=>{m.current=s},[s]);let x=(0,r.useCallback)(()=>{let e=!s;m.current=e,n(e),e?i.current?.focus():i.current?.blur()},[s]),p=(0,r.useRef)(!1);(0,r.useEffect)(()=>{t&&!p.current&&m.current&&(p.current=!0,i.current?.focus())},[t]);let h=(0,r.useCallback)(()=>{let e=!l;!e&&s&&i.current?.focus(),a(e)},[l,s]),f=(0,r.useCallback)(()=>{m.current&&!l&&setTimeout(()=>i.current?.focus(),0)},[l]),b=(0,r.useRef)(null);return(0,r.useEffect)(()=>{b.current="trackpad"===d?u:null},[d,u]),(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=o.current;if(!r)return;let l=r.clientHeight;cancelAnimationFrame(s);let a=0,i=()=>{r.clientHeight!==l||a++>30?c(n,b.current):s=requestAnimationFrame(i)};s=requestAnimationFrame(i)};return e.addEventListener("resize",n),()=>{cancelAnimationFrame(s),e.removeEventListener("resize",n)}},[o,c]),{keyboardOnRef:m,toggleKeyboard:x,toggleTextPanel:h,handleTextInputBlur:f}}({streaming:s,keyboardOn:f,setKeyboardOn:b,showTextPanel:p,setShowTextPanel:h,textInputRef:et,canvasContainerRef:W,panForKeyboard:_.panForKeyboard,pointerMode:y,virtualCursor:_.virtualCursor}),ep=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];s&&(t.length>0?I(e,r&&"darwin"===n?t.map(e=>"control"===e?"command":e):t):em(e))},[s,n,I,em]),eh=(0,r.useCallback)(()=>{k(e=>{let t=!e;return t?(es&&eo(),G()):J(),t})},[k,es,eo,G,J]);(0,r.useEffect)(()=>{if(!s||!F)return;let e=setTimeout(()=>{let e=K.current,t=W.current;if(!e||!t||0===e.width)return;if(H<=1)return void F(null,1);let s=U*H;if(s<=0)return;let n=Math.max(0,-q.x/s),r=Math.max(0,-q.y/s),l=Math.min(e.width-n,t.clientWidth/s),a=Math.min(e.height-r,t.clientHeight/s);F({x:Math.floor(n),y:Math.floor(r),w:Math.ceil(l),h:Math.ceil(a)},H)},c.eR.focusDebounce);return()=>clearTimeout(e)},[s,H,q,U,K,W,F]);let ef=(0,r.useCallback)(()=>k(!1),[k]),eb=(0,r.useCallback)(()=>{j&&k(!1),eo()},[j,k,eo]);return{..._,...ee,...ex,streaming:s,inputMode:N,show:e=>"mouse"!==N||C?.[e],tallLandscape:E,pointerMode:y,handMode:j,keyboardOn:f,showTextPanel:p,controlsHidden:g,setControlsHidden:v,togglePointerMode:Q,toggleHandMode:eh,handleToggleSelection:eb,emitKeyDirect:ep,interactionHandler:e=>t=>{d?.(t,e)||Y(t,e,{streaming:s,selectionMode:es,selectionStart:en,dragMode:er,isDragging:el,setIsDragging:ea,setDragMode:ei,isMobile:e.includes("touch"),pointerMode:y,handMode:j,hoverMove:i,wheelMultiplier:o,onHandRelease:ef,handleSelection:(e,t,n,r)=>eu(e,t,n,{streaming:s,getCanvasCoordinates:X,baseCanvasSize:Z,canvasZoom:H,canvasPan:q,...r})})},onCanvasKeyDown:e=>{u?.(e)||ec(e,s)},emitRequestScreenWithHashes:R,recalculateDisplaySize:_.recalculateDisplaySize}}let dp=!!window.chrome,dh=e=>new Blob([e]),df=(e,t)=>()=>{e.current[t]=null},db=null,dg=0,dv=new Map;async function dy(e){if("u"<typeof createImageBitmap)return null;if(dp)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 dw(e,t,n){let{ackEvent:l="tile-ack",verifyEvent:a="request-screen-with-hashes",targetId:i=null,resetWorker:o=!0}=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},[d,u]=(0,r.useState)(126),[m,x]=(0,r.useState)(!1),p=(0,r.useRef)(new Set),h=(0,r.useRef)(new Map),f=(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),x(!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)(function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];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);x(!0)}catch(e){}},s.src=e.screen.imageBase64}catch(e){console.error("Full screen error:",e)}},[n,d]),E=(0,r.useCallback)(e=>{if(n?.current)try{if(n.current.getContext("2d"),g.current=Date.now(),e.currentHashes&&Array.isArray(e.currentHashes)&&(f.current=e.currentHashes,b.current=!1),!e.tiles?.length)return;let t=e.timestamp||Date.now();for(let s of e.tiles){let e=h.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&&(f.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=df(f,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}):dy(dh(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 h.current.delete(e.tileIndex);let s={cancelled:!1};h.current.set(e.tileIndex,{controller:s});let r=setTimeout(()=>{s.cancelled=!0,h.current.delete(e.tileIndex),f.current[e.tileIndex]=null},c.eR.tileLoadTimeout),l=df(f,e.tileIndex),a=a=>{s.cancelled||!n?.current?a?.close?.():(clearTimeout(r),h.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)dy(dh(e.imageBuffer)).then(a).catch(()=>{if(s.cancelled)return;let t=new Image,n=URL.createObjectURL(dh(e.imageBuffer));t.onload=()=>{a(t),URL.revokeObjectURL(n)},t.onerror=()=>{URL.revokeObjectURL(n),clearTimeout(r),h.current.delete(e.tileIndex),l()},t.src=n});else{let t=new Image;if(e.imageBuffer){let s=URL.createObjectURL(dh(e.imageBuffer));t.onload=()=>{a(t),URL.revokeObjectURL(s)},t.onerror=()=>{URL.revokeObjectURL(s),clearTimeout(r),h.current.delete(e.tileIndex),l()},t.src=s}else t.onload=()=>a(t),t.onerror=()=>{clearTimeout(r),h.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]),R=(0,r.useCallback)(function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"ws";if(!e)return;let r=e instanceof ArrayBuffer?e:e?.buffer;if(!r)return;let l=function(){if(!1===db)return null;if(db)return db;try{return(db=new Worker(s.tu(new URL(s.p+s.u(8534),s.b)))).onmessage=e=>{let{data:{tiles:t,timestamp:s,id:n,hasBitmap:r,error:l}}=e,a=dv.get(n);if(!a){if(t)for(let e of t)e.bitmap?.close?.();return}clearTimeout(a.timer),dv.delete(n),a.resolve(l?null:{tiles:t,timestamp:s,hasBitmap:r})},db}catch{return db=!1,null}}();if(!l)return;let a=r.byteLength,i=++dg;new Promise(e=>{let s=setTimeout(()=>{dv.has(i)&&(dv.delete(i),e(null))},c.eR.tileLoadTimeout),n=c.eR.decodeQueueCap;for(;dv.size>=n;){let e=dv.keys().next().value,t=dv.get(e);if(!t)break;clearTimeout(t.timer),dv.delete(e),t.resolve(null)}dv.set(i,{resolve:e,timer:s}),l.postMessage({buffer:r,id:i,v:t},[r])}).then(e=>{e&&(2===t&&(b.current=!1),E({tiles:e.tiles,timestamp:e.timestamp,hasBitmap:e.hasBitmap,bytes:a,transport:n}))})},[E]),M=(0,r.useCallback)(e=>R(e,1,"ws"),[R]),$=(0,r.useCallback)(e=>R(e,2,"ws"),[R]),z=(0,r.useCallback)(e=>{e&&(g.current=Date.now(),e.currentHashes&&Array.isArray(e.currentHashes)&&(f.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===f.current.length||Date.now()-g.current<c.eR.lastDataThreshold)return;b.current=!0;let t=i?{targetId:i,tileHashes:f.current}:{tileHashes:f.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 h.current.entries())e.controller&&(e.controller.cancelled=!0);h.current.clear(),f.current=[],p.current.clear(),w.current.clear(),g.current=0,b.current=!1,x(!1),o&&function(){if(db&&!1!==db)try{db.terminate()}catch{}for(let e of(db=null,dv.values()))try{e.resolve(null)}catch{}dv.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:m,handleFullScreenData:T,handleTilesData:E,handleTilesBinary:M,handleTilesBinaryV2:$,handleTilesMeta:z,startStreamingWithTiles:P,handleScreenDimensions:A,cleanupTiles:D,requestScreenWithHashes:I,clientTileHashesRef:f,tileTimestampRef:w}}let dj={fps:0,latency:0,tilesPerSec:0,bandwidthMBps:0,webrtcTiles:0,wsTiles:0,webrtcPercent:0};function dk(){let[e,t]=(0,r.useState)(""),[s,n]=(0,r.useState)(!1),l=(0,r.useRef)(null),a=(0,r.useCallback)((e,s)=>{s&&s===l.current||(l.current=s||null,t(e||""),n(!0))},[]);return(0,r.useEffect)(()=>{if(!s)return;let e=setTimeout(()=>n(!1),c.eR.clipboardBadgeTimeout);return()=>clearTimeout(e)},[s,e]),{text:e,isNew:s,setNew:n,push:a}}function dN(e){let{list:t,activeIndex:s,onSelect:r}=e;if(!Array.isArray(t)||t.length<=1)return null;let l=e=>e.stopPropagation();return(0,n.jsx)("div",{className:"absolute bottom-1.5 right-1.5 z-40 flex gap-1.5",children:t.map(e=>{let t=e.index===s,a=`${e.index+1}`;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),r?.(e.index)},onMouseDown:e=>e.preventDefault(),onPointerDown:l,onPointerUp:l,onPointerMove:l,onTouchStart:l,onTouchMove:l,onTouchEnd:l,onWheel:l,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 ${t?"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 dC(e){let{canvasRef:t,canvasContainerRef:s,canvasZoom:l,canvasPan:a,fitScale:i,streaming:o,hasFrame:d=!0,selectionRect:u,clickIndicator:m,pointerMode:x,selectionMode:p,handMode:h,handHolding:f,scrollLock:b,virtualCursor:g,cursorShape:v,inputMode:y,keyboardOn:w,monitors:j,activeMonitorIndex:k,onSelectMonitor:N,onPointerDown:C,onPointerMove:S,onPointerUp:T,onWheel:E,onContextMenu:R,onDoubleClick:M,onTouchStart:$,onTouchMove:z,onTouchEnd:P,onKeyDown:A,screenLocked:I,unlockReady:D,unlockResult:L,onUnlockSubmit:B,cursorOverride:F,children:O}=e,_=i*l,K="mouse"===y,{t:W}=(0,eu.s)(),[H,q]=(0,r.useState)(!1),[U,X]=(0,r.useState)(""),[V,G]=(0,r.useState)(!1),[J,Y]=(0,r.useState)(!1);(0,r.useEffect)(()=>{I||(X(""),G(!1))},[I]),(0,r.useEffect)(()=>{L&&G(!1)},[L]);let Z={ew:"cursor-ew-resize",ns:"cursor-ns-resize",nwse:"cursor-nwse-resize",nesw:"cursor-nesw-resize",all:"cursor-move"},Q=p?"cursor-crosshair":h?f?"cursor-grabbing":"cursor-grab":K&&H?"cursor-grabbing":K&&v&&Z[v]?Z[v]:"trackpad"===x?"cursor-grab active:cursor-grabbing":"cursor-default",ee=(0,r.useRef)(E);return(0,r.useEffect)(()=>{ee.current=E},[E]),(0,r.useEffect)(()=>{let e=t.current;if(!e)return;let s=e=>ee.current?.(e);return e.addEventListener("wheel",s,{passive:!1}),()=>e.removeEventListener("wheel",s)},[t]),(0,r.useEffect)(()=>{K&&o&&t.current?.focus()},[t,K,o]),(0,r.useEffect)(()=>{if(!H)return;let e=()=>q(!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)}},[H]),(0,n.jsxs)("div",{className:"w-full h-full overflow-hidden relative flex-1",children:[(0,n.jsxs)("div",{className:"absolute inset-0",ref:s,style:{touchAction:"none"},onTouchStart:$,onTouchMove:z,onTouchEnd:P,children:[(0,n.jsx)("canvas",{ref:t,className:`block ${Q} bg-black outline-none`,style:{touchAction:"none",cursor:F,transformOrigin:"top left",userSelect:"none",WebkitUserSelect:"none",WebkitTouchCallout:"none",WebkitTapHighlightColor:"transparent",transform:`translate3d(${a.x}px, ${a.y}px, 0) scale(${_})`,imageRendering:"auto",willChange:"transform"},onPointerDown:e=>{w&&"mouse"!==e.pointerType&&e.preventDefault();let s=document.activeElement;if(s?.name==="remote-batch-input")if(w){let e=document.querySelector('textarea[name="remote-keyboard-sink"]');e?.focus()}else s.blur();K&&(t.current?.focus(),"mouse"===e.pointerType&&q(!0)),C?.(e)},onPointerMove:S,onPointerUp:e=>{K&&"mouse"===e.pointerType&&q(!1),T?.(e)},onDoubleClick:M,onContextMenu:R,tabIndex:0,onKeyDown:A}),o&&!d&&!I&&(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"}),W("remote.receivingImage",{defaultValue:"Receiving screen…"})]})}),u&&(0,n.jsx)("div",{className:"absolute border-2 border-blue-400 bg-blue-400/20 z-10",style:{left:`${u.x}px`,top:`${u.y}px`,width:`${u.width}px`,height:`${u.height}px`}}),"trackpad"===x&&g&&(0,n.jsx)("div",{className:"absolute pointer-events-none z-30",style:{left:`${g.x*_+a.x}px`,top:`${g.y*_+a.y}px`,width:`${c.eR.trackpadCursorSize}px`,height:`${c.eR.trackpadCursorSize}px`,transform:v||h||b||p?"translate(-50%, -50%)":"translate(-2px, -2px)"},children:b?(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:"✥"}):p?(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"})}):h?(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?"✊":"✋"}):v?(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"===v?90:"nwse"===v?45:"nesw"===v?-45:0}deg)`},children:"all"===v?(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"})})}),m&&(0,n.jsxs)("div",{className:"absolute pointer-events-none z-20",style:{left:`${m.x-m.size/2}px`,top:`${m.y-m.size/2}px`,width:`${m.size}px`,height:`${m.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"})]})]}),O,(0,n.jsx)(dN,{list:j,activeIndex:k,onSelect:N}),I&&(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:D?(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:W("remote.lockTitle")}),(0,n.jsx)("p",{className:"text-xs text-center",style:{color:"rgba(220,225,245,0.7)"},children:W("remote.lockDesc")})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{type:J?"text":"password",value:U,autoFocus:!0,disabled:V,onChange:e=>X(e.target.value),onKeyDown:e=>{"Enter"===e.key&&U&&!V&&(G(!0),B?.(U))},placeholder:W("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:()=>Y(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":J?"Hide password":"Show password",children:J?(0,n.jsx)(el.X_,{size:18}):(0,n.jsx)(el.kU,{size:18})})]}),(0,n.jsx)("button",{type:"button",disabled:!U||V,onClick:()=>{G(!0),B?.(U)},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:W(V?"remote.unlocking":"remote.unlock")}),L&&!L.ok&&(0,n.jsx)("p",{className:"mt-3 text-xs text-center text-red-300",children:W("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:W("remote.lockTitle")}),(0,n.jsx)("p",{className:"text-xs",style:{color:"rgba(220,225,245,0.85)"},children:W("remote.lockGrantDesc")})]})})})]})}var dS=s(56156);function dT(e){let{active:t,primary:s,pinned:r,children:l,className:a="",onClick:i,...o}=e;return(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault(),onClick:i,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 ${t?"bg-brand-500 text-white shadow-sm transition-all duration-150 ease-out active:scale-[0.94]":r?"bg-brand-500/15 hover:bg-brand-500/25 text-brand-400 transition-all duration-150 ease-out active:scale-[0.94]":s?"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]"} ${a}`,style:{touchAction:"manipulation",WebkitTapHighlightColor:"transparent"},...o,children:l})}let dE=function(e){for(var t=arguments.length,s=Array(t>1?t-1:0),n=1;n<t;n++)s[n-1]=arguments[n];(0,ed.e)(),e?.(...s)};function dR(e){let t,s,l,a,{streaming:i,canvasZoom:o,clipboardNew:d,clipboardText:u,onOpenClipboard:m,selectionMode:x,pointerMode:p,handMode:h,inputMode:f,onToggleHandMode:b,onTogglePointerMode:g,modifierKeys:v,textInputValue:y,textInputRef:w,keyboardOn:j,showTextPanel:k,onResetZoom:N,onRefresh:C,onToggleSelection:S,onToggleModifier:T,onToggleKeyboard:E,onToggleTextPanel:R,onToggleHelp:M,onToggleDebug:$,debugOn:z,onEmitKey:P,onTextInputChange:A,onTextInputFocus:I,onTextInputBlur:D,onTextInputKeyDown:L,onDirectInputChange:B,onSendText:F,onClose:O,onDesktopSwitch:_,controlsHidden:K,onToggleControlsHidden:W,tallLandscape:H}=e,{t:q,locale:U}=(0,eu.s)(),X=(0,r.useRef)(null),[V]=sb(U),[G,J]=(0,r.useState)(!1),Y=sy({lang:sh(V),onText:e=>{A(e);let t=X.current;t&&requestAnimationFrame(()=>{try{t.selectionStart=t.selectionEnd=t.value.length}catch{}t.scrollTop=t.scrollHeight})}});(0,r.useEffect)(()=>{let e=X.current;e&&!window.matchMedia("(orientation: landscape)").matches&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,72)}px`)},[y]);let Z=()=>{Y.listening&&Y.stop(),dE(F,i)},Q=`flex gap-1.5 overflow-auto scroll-thin-x py-0.5 pr-2 ${H?"":"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`,[ee,et]=(0,r.useState)(!1),[es,en]=(0,r.useState)(!1),[er,ea]=(0,r.useState)(0);(0,r.useEffect)(()=>{if(!d)return void ea(0);ea(Math.ceil(c.eR.clipboardBadgeTimeout/1e3));let e=setInterval(()=>{ea(e=>e<=1?0:e-1)},1e3);return()=>clearInterval(e)},[d,u]);let ei=sC("remoteDesktop.bottomKeys",c.ij,c.D5,"flat"),eo=sC("remoteDesktop.extraKeys",c.ij,c.I9,"grid");(0,r.useEffect)(()=>{if(!k)return;let e=setTimeout(()=>X.current?.focus(),350);return()=>clearTimeout(e)},[k]);let ec=c.eR.pcModeControls,em=e=>"mouse"!==f||ec[e],ex=window.innerWidth<768,ep=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",l=e.label.length>1?"text-[11px]":"",a=`${r} ${l}`.trim();if("modifier"===e.type)return(0,n.jsx)(dT,{onClick:()=>dE(T,e.modifier),disabled:!i,active:v[e.modifier],pinned:s,className:a,children:e.label},e.id+t);if("desktop"===e.type){if(!_)return null;let r="prev"===e.direction?el.JG:"next"===e.direction?el.c_:el.FW;return(0,n.jsxs)(dT,{onClick:()=>dE(_,e.direction),disabled:!i,pinned:s,className:a,title:`${e.direction} desktop`,children:[(0,n.jsx)(el.VA,{size:12}),(0,n.jsx)(r,{size:"new"===e.direction?10:12,className:"-ml-0.5"})]},e.id+t)}return(0,n.jsx)(dT,{onClick:()=>dE(P,e.key,e.modifiers||[],e.osAdaptive),disabled:!i,primary:!s&&e.primary,pinned:s,className:a,children:e.label},e.id+t)};return(0,n.jsxs)("div",{className:`bg-bg select-none relative landscape:flex landscape:flex-col landscape:shrink-0 ${H||K?"":"landscape:h-full landscape:justify-end"} ${K?"landscape:w-12":H?"landscape:w-full landscape:pl-12":"landscape:w-64"}`,children:[(0,n.jsx)("textarea",{ref:w,rows:1,value:y,onChange:e=>{j?B?.(e.target.value):A(e.target.value)},onKeyDown:L,onFocus:I,onBlur:D,"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 ${K||H?"hidden":"hidden landscape:flex"}`,children:(0,n.jsx)(dT,{onClick:()=>{(0,ed.e)(),W?.(!0)},title:q("remote.hideControls"),children:(0,n.jsx)(el.X_,{size:14})})}),(0,n.jsxs)("div",{className:K?"landscape:hidden":"contents",children:[(0,n.jsxs)("div",{className:`${k?"flex":"hidden"} landscape:flex ${H?"":"landscape:flex-col"} relative z-30 px-2 py-1 gap-2 ${H?"landscape:px-0":"landscape:gap-1 landscape:order-last"}`,children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsx)(sx,{value:y,store:sl,isMobile:ex,onSelect:e=>{A(e),X.current?.focus()}}),(0,n.jsx)("textarea",{ref:X,rows:1,cols:1,value:y,onChange:e=>A(e.target.value),onFocus:I,onKeyDown:e=>{"mouse"===f&&"Enter"===e.key&&!e.shiftKey&&(e.preventDefault(),i&&Z())},placeholder:"mouse"===f?q("remoteControls.enterToSend"):q("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 ${H?"":"landscape:!h-16"}`,disabled:!i}),y?(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{A(""),X.current?.focus()},title:q("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:q("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:[Y.active&&(0,n.jsx)("div",{className:"relative shrink-0",children:(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{Y.listening?Y.stop():(document.activeElement?.blur(),Y.start(y))},disabled:!i,title:"not-allowed"===Y.error||"service-not-allowed"===Y.error?q("voice.denied"):q("voice.dictate"),className:`h-9 w-9 flex items-center justify-center rounded-full transition-all duration-150 ease-out disabled:opacity-40 ${Y.listening?"bg-red-500/90 text-white animate-pulse":Y.error?"bg-surface-2 text-red-400":"bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text"}`,children:Y.listening?(0,n.jsx)(el.jj,{size:18}):(0,n.jsx)(el.GO,{size:18})})}),(0,n.jsx)(dS.A,{variant:"primary",size:"sm",className:"!px-2.5 shrink-0",onMouseDown:e=>e.preventDefault(),onClick:Z,disabled:!i,children:y.trim()?q("remoteControls.send"):(0,n.jsx)(el.Lt,{size:16,strokeWidth:2.5})})]})]}),(0,n.jsx)("div",{className:`overflow-hidden transition-all duration-300 ${ee?"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:eo.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?ep(n,100*t+s):null})}),0===t&&(0,n.jsx)("button",{onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),en(!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:q("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:`${Q} flex-1 min-w-0 px-0 py-0 landscape:py-0`,children:[O&&(0,n.jsx)(dT,{onClick:()=>dE(O),title:q("remote.back"),pinned:!0,className:"landscape:hidden",children:(0,n.jsx)(el.JG,{size:16})}),d&&u?(0,n.jsxs)(dT,{onClick:()=>dE(m),className:"!text-red-500 landscape:hidden",title:q("common.clipboard"),children:[(0,n.jsx)(el.Ir,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"tabular-nums",children:er})]}):(0,n.jsxs)(dT,{onClick:()=>dE(N),disabled:!i,className:"text-text landscape:hidden",title:q("remote.resetZoom"),children:[Math.round(100*o),"%"]}),(0,n.jsx)(dT,{onClick:()=>dE(C),disabled:!i,title:q("remote.refresh"),className:"landscape:hidden",children:(0,n.jsx)(el.e9,{size:14})}),em("rectangleSelect")&&(0,n.jsx)(dT,{onClick:()=>dE(S),disabled:!i,active:x,title:q("remote.rectangleSelection"),className:"landscape:hidden",children:"□"}),em("pointerModeToggle")&&(0,n.jsx)(dT,{onClick:()=>dE(g),disabled:!i,active:"trackpad"===p,title:"trackpad"===p?q("remoteControls.trackpadMode"):q("remoteControls.directMode"),className:"landscape:hidden",children:(0,n.jsx)("span",{className:"text-base leading-none",children:"\uD83D\uDDB1️"})}),em("handMode")&&"trackpad"===p&&(0,n.jsx)(dT,{onClick:()=>dE(b),disabled:!i,active:h,title:q("remote.handMode"),className:"landscape:hidden",children:(0,n.jsx)(el.Ud,{size:14})}),em("keyboardToggle")&&(0,n.jsx)(dT,{onClick:()=>dE(E),disabled:!i,active:j,title:q("remote.toggleKeyboard"),className:"landscape:hidden",children:(0,n.jsx)(el.s3,{size:14})}),em("textPanel")&&(0,n.jsx)(dT,{onClick:()=>dE(R),disabled:!i,active:k,title:q("remote.textBatchInput"),className:"landscape:hidden",children:"Aa"}),em("help")&&(0,n.jsx)(dT,{onClick:()=>dE(M),title:q("remote.help"),className:"landscape:hidden",children:(0,n.jsx)(el.mN,{size:14})})]}),(0,n.jsx)(dT,{onClick:()=>{(0,ed.e)(),et(e=>!e)},active:ee,pinned:!0,className:"landscape:hidden shrink-0",title:q("remote.extraKeys"),children:ee?(0,n.jsx)(el.X,{size:16}):(0,n.jsx)(el.a4,{size:16})})]}),em("modifierRow")&&(t=ei.keys.filter(e=>e.id!==c.Ic),s=c.ij.find(e=>e.id===c.Ic),l=(0,n.jsx)(dT,{onClick:()=>{(0,ed.e)(),et(e=>!e)},active:ee,pinned:!0,title:q("remote.extraKeys"),children:ee?(0,n.jsx)(el.X,{size:16}):(0,n.jsx)(el.a4,{size:16})}),a=s?ep(s,"pinned",!0):null,(0,n.jsxs)("div",{className:`px-2 py-1 ${"mouse"===f?"":"safe-area-bottom"} ${H?"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:`${Q} flex-1 min-w-0`,children:t.map((e,t)=>ep(e,t))}),a]}),(0,n.jsxs)("div",{className:`${Q} hidden ${H?"landscape:flex":""}`,children:[t.map((e,t)=>ep(e,t)),l,a]}),(0,n.jsxs)("div",{className:`hidden ${H?"":"landscape:flex"} landscape:flex-col gap-1`,children:[(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[t.slice(0,5).map((e,t)=>ep(e,t)),l]}),(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[t.slice(5).map((e,t)=>ep(e,t)),a]})]})]}))]}),(0,n.jsxs)("div",{className:`flex-col gap-1.5 p-1.5 ${K?"hidden landscape:flex":"hidden"}`,children:[(0,n.jsx)(dT,{onClick:()=>{(0,ed.e)(),W?.(!1)},title:q("remote.showControls"),children:(0,n.jsx)(el.kU,{size:16})}),(0,n.jsx)(dT,{onClick:()=>dE(E),disabled:!i,active:j,title:q("remote.toggleKeyboard"),children:(0,n.jsx)(el.s3,{size:16})})]}),(0,n.jsx)(sM,{isOpen:es,onClose:()=>en(!1),title:q("remote.customizeRemoteKeys"),tabs:[{id:"bottom",label:q("remoteControls.bottomRow"),hook:ei,excludeIds:[c.Ic]},{id:"extra",label:q("remoteControls.extraPanel"),hook:eo}]}),(0,n.jsx)(so,{isOpen:G,store:sl,onSelect:e=>{A(e),X.current?.focus()},onClose:()=>J(!1)})]})}let dM="bg-surface-2 hover:bg-surface-3 text-text",d$="bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text",dz="bg-brand-500 text-white";function dP(e){let{onClick:t,title:s,disabled:r,className:l,children:a}=e;return(0,n.jsx)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),t()},disabled:r,title:s,className:`shrink-0 w-9 h-9 rounded-brand flex items-center justify-center transition-all duration-150 active:scale-[0.94] ${l} ${r?"disabled:opacity-50":""}`,children:a})}function dA(e){let{streaming:t,canvasZoom:s,pointerMode:r,handMode:l,keyboardOn:a,selectionMode:i,show:o,onBack:c,onRefresh:d,onResetZoom:u,onTogglePointerMode:m,onToggleHandMode:x,onToggleKeyboard:p,onShowHelp:h,onToggleSelection:f}=e,{t:b}=(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:[c&&(0,n.jsx)(dP,{onClick:c,title:b("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)(dP,{onClick:d,disabled:!t,title:b("remote.refresh"),className:d$,children:(0,n.jsx)(el.e9,{size:16})}),(0,n.jsxs)(dP,{onClick:u,disabled:!t,title:b("remote.resetZoom"),className:`text-[10px] font-semibold ${dM}`,children:[Math.round(100*s),"%"]}),o("pointerModeToggle")&&(0,n.jsx)(dP,{onClick:m,disabled:!t,title:b("trackpad"===r?"remoteControls.trackpadMode":"remoteControls.directMode"),className:`text-base leading-none ${"trackpad"===r?dz:dM}`,children:"\uD83D\uDDB1️"}),o("handMode")&&"trackpad"===r&&(0,n.jsx)(dP,{onClick:x,disabled:!t,title:b("remote.handMode"),className:l?dz:dM,children:(0,n.jsx)(el.Ud,{size:16})}),o("keyboardToggle")&&(0,n.jsx)(dP,{onClick:p,disabled:!t,title:b("remote.toggleKeyboard"),className:a?dz:d$,children:(0,n.jsx)(el.s3,{size:16})}),o("help")&&(0,n.jsx)(dP,{onClick:h,title:b("remote.help"),className:d$,children:(0,n.jsx)(el.mN,{size:16})}),o("rectangleSelect")&&(0,n.jsx)(dP,{onClick:f,disabled:!t,title:b("remote.rectangleSelection"),className:i?dz:dM,children:"□"})]})}function dI(e){let{onClose:t,inputMode:s="touch",pointerMode:l="direct"}=e,{t:a}=(0,eu.s)();(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 i="mouse"===s?[{title:a("remoteHelp.mouseTitle"),items:[{key:a("remoteHelp.mouseClickKey"),desc:a("remoteHelp.mouseClickDesc")},{key:a("remoteHelp.mouseRightKey"),desc:a("remoteHelp.mouseRightDesc")},{key:a("remoteHelp.mouseWheelKey"),desc:a("remoteHelp.mouseWheelDesc")},{key:a("remoteHelp.mouseDoubleKey"),desc:a("remoteHelp.mouseDoubleDesc")}]},{title:a("remoteHelp.keyboardTitle"),items:[{key:a("remoteHelp.keyPhysicalKey"),desc:a("remoteHelp.keyPhysicalDesc")},{key:a("remoteHelp.keyModifierKey"),desc:a("remoteHelp.keyModifierDesc")}]}]:"trackpad"===l?[{title:a("remoteHelp.gesturesTrackpadTitle"),items:[{key:a("remoteHelp.trackpadSwipeKey"),desc:a("remoteHelp.trackpadSwipeDesc")},{key:a("remoteHelp.trackpadScrollLockKey"),desc:a("remoteHelp.trackpadScrollLockDesc")},{key:a("remoteHelp.trackpadTapKey"),desc:a("remoteHelp.trackpadTapDesc")},{key:a("remoteHelp.trackpad2TapKey"),desc:a("remoteHelp.trackpad2TapDesc")},{key:a("remoteHelp.trackpad2SwipeKey"),desc:a("remoteHelp.trackpad2SwipeDesc")},{key:a("remoteHelp.trackpadPinchKey"),desc:a("remoteHelp.trackpadPinchDesc")}]},{title:a("remoteHelp.toolbarTitle"),items:[{key:"✋",desc:a("remoteHelp.toolbarHandDesc")},{key:"\uD83D\uDDB1️",desc:a("remoteHelp.toolbarMouseDirectDesc")},{key:"⌨️ / Aa",desc:a("remoteHelp.toolbarKeyboardDesc")}]}]:[{title:a("remoteHelp.gesturesDirectTitle"),items:[{key:a("remoteHelp.directTapKey"),desc:a("remoteHelp.directTapDesc")},{key:a("remoteHelp.directLongKey"),desc:a("remoteHelp.directLongDesc")},{key:a("remoteHelp.directDoubleKey"),desc:a("remoteHelp.directDoubleDesc")},{key:a("remoteHelp.directScrollKey"),desc:a("remoteHelp.directScrollDesc")},{key:a("remoteHelp.directPinchKey"),desc:a("remoteHelp.directPinchDesc")},{key:a("remoteHelp.directPanKey"),desc:a("remoteHelp.directPanDesc")}]},{title:a("remoteHelp.toolbarTitle"),items:[{key:"\uD83D\uDDB1️",desc:a("remoteHelp.toolbarMouseTrackpadDesc")},{key:"⌨️ / Aa",desc:a("remoteHelp.toolbarKeyboardDesc")},{key:"□",desc:a("remoteHelp.toolbarRectDesc")}]}],o=a("mouse"===s?"remoteHelp.modePc":"trackpad"===l?"remoteHelp.modeTrackpad":"remoteHelp.modeDirect");return(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 scrim 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 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 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:a("remote.help")}),(0,n.jsx)("span",{className:"text-brand-400 text-xs font-mono",children:o})]}),(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 space-y-4",children:i.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 dD(e){let{text:t,onClose:s}=e,[l,a]=(0,r.useState)(!1);(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]);let i=async()=>{try{await navigator.clipboard?.writeText(t),a(!0),setTimeout(()=>a(!1),1500)}catch{}};return(0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 scrim flex items-center justify-center p-4",onClick:s,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:s,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:t||""})}),(0,n.jsx)("div",{className:"flex justify-end gap-2 p-4 border-t border-border",children:(0,n.jsxs)("button",{onClick:i,disabled:!t,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:[l?(0,n.jsx)(el.aJ,{size:14}):(0,n.jsx)(el.m0,{size:14}),"Copy"]})})]})})}function dL(e){let{surface:t,connected:s=!0,clipboard:l,hasFrame:a=!0,canvasProps:i,controlsProps:o,Controls:c=dR,bottomLayout:d=!1,onBack:u,onRefresh:m,onClose:x,onDesktopSwitch:p,onToggleDebug:h,debugOn:f,placeholder:b,children:g}=e,[v,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(!1),k=()=>t.streaming&&m?.();return(0,n.jsxs)("div",{className:`bg-bg text-text flex flex-col h-full w-full ${!d&&!t.tallLandscape?"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:[s&&!d&&(0,n.jsx)(dA,{streaming:t.streaming,canvasZoom:t.canvasZoom,pointerMode:t.pointerMode,handMode:t.handMode,keyboardOn:t.keyboardOn,selectionMode:t.selectionMode,show:t.show,onBack:u,onRefresh:k,onResetZoom:t.resetZoom,onTogglePointerMode:t.togglePointerMode,onToggleHandMode:t.toggleHandMode,onToggleKeyboard:t.toggleKeyboard,onShowHelp:()=>y(!0),onToggleSelection:t.handleToggleSelection}),s?(0,n.jsx)(dC,{canvasRef:t.canvasRef,canvasContainerRef:t.canvasContainerRef,canvasZoom:t.canvasZoom,canvasPan:t.canvasPan,fitScale:t.fitScale,streaming:t.streaming,hasFrame:a,selectionRect:t.selectionRect,clickIndicator:t.clickIndicator,pointerMode:t.pointerMode,selectionMode:t.selectionMode,handMode:t.handMode,handHolding:t.handHolding,scrollLock:t.scrollLock,virtualCursor:t.virtualCursor,inputMode:t.inputMode,keyboardOn:t.keyboardOn,onPointerDown:t.interactionHandler("pointerdown"),onPointerMove:t.interactionHandler("pointermove"),onPointerUp:t.interactionHandler("pointerup"),onWheel:t.interactionHandler("wheel"),onContextMenu:t.interactionHandler("contextmenu"),onDoubleClick:t.interactionHandler("dblclick"),onTouchStart:t.interactionHandler("touch"),onTouchMove:t.interactionHandler("touchmove"),onTouchEnd:t.interactionHandler("touchend"),onKeyDown:t.onCanvasKeyDown,...i,children:g}):b]}),(0,n.jsx)(c,{streaming:t.streaming,canvasZoom:t.canvasZoom,clipboardNew:l.isNew,clipboardText:l.text,onOpenClipboard:()=>{l.setNew(!1),j(!0)},onDesktopSwitch:p,selectionMode:t.selectionMode,pointerMode:t.pointerMode,handMode:t.handMode,inputMode:t.inputMode,onToggleHandMode:t.toggleHandMode,onTogglePointerMode:t.togglePointerMode,modifierKeys:t.modifierKeys,textInputValue:t.textInputValue,textInputRef:t.textInputRef,keyboardOn:t.keyboardOn,showTextPanel:t.showTextPanel,onResetZoom:t.resetZoom,onRefresh:k,onToggleSelection:t.handleToggleSelection,onToggleModifier:t.toggleModifierKey,onToggleKeyboard:t.toggleKeyboard,onToggleTextPanel:t.toggleTextPanel,controlsHidden:t.controlsHidden,onToggleControlsHidden:t.setControlsHidden,tallLandscape:t.tallLandscape,onToggleHelp:()=>y(!0),onEmitKey:t.emitKeyDirect,onTextInputChange:t.setTextInputValue,onTextInputFocus:t.handleTextInputFocus,onTextInputBlur:t.handleTextInputBlur,onTextInputKeyDown:e=>t.handleModifiedTextInput(e,t.streaming,t.keyboardOn),onDirectInputChange:e=>t.handleDirectInputChange(e,t.streaming),onSendText:t.sendTextInput,onClose:x,onToggleDebug:h,debugOn:f,...o}),v&&(0,n.jsx)(dI,{inputMode:t.inputMode,pointerMode:t.pointerMode,onClose:()=>{y(!1),t.keyboardOn&&t.textInputRef.current?.focus()}}),w&&(0,n.jsx)(dD,{text:l.text,onClose:()=>j(!1)})]})}function dB(e){let{hostLabel:t,status:s=null,platform:r=null,hosts:l=[],onOpenHost:a,onBack:i}=e,{t:o}=(0,eu.s)(),c=t||o("agentSwitcher.unnamed"),d=[];return s?(s.capable||d.push(o("remote.unavailableNoCapture")),s.enabled||d.push(o("remote.unavailableDisabled",{host:c})),s.screenRecording||d.push(o("remote.unavailableScreenRecording",{host:c})),s.accessibility||d.push(o("remote.unavailableAccessibility",{host:c}))):d.push(o("remote.unavailableUnknown",{host:c})),d.length||d.push(o("remote.unavailableFailed",{host:c})),"darwin"!==r||!s||s.screenRecording&&s.accessibility||d.push(o("remote.unavailableMacRestart")),(0,n.jsxs)("div",{className:"flex h-full w-full flex-col bg-bg text-text",children:[(0,n.jsxs)("header",{className:"flex items-center gap-2 px-3 py-3 flex-shrink-0",style:{paddingTop:"calc(0.75rem + env(safe-area-inset-top, 0px))"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),i?.()},className:"grid place-items-center w-8 h-8 rounded-brand text-text-muted hover:text-text active:scale-90 transition-all","aria-label":o("remote.back"),children:(0,n.jsx)(el.JG,{size:20})}),(0,n.jsx)("h2",{className:"text-sm font-semibold truncate",children:o("remote.title")})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto modal-scrollable px-4 pb-[calc(24px+var(--safe-bottom))]",children:(0,n.jsxs)("div",{className:"mx-auto mt-4 max-w-md card-elev rounded-2xl p-5 fade-in",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"grid place-items-center w-10 h-10 rounded-full bg-surface-2 text-text-muted flex-shrink-0",children:(0,n.jsx)(el.VA,{size:18})}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text truncate",children:o("remote.unavailableTitle")}),(0,n.jsx)("p",{className:"text-xs text-text-muted truncate",children:c})]})]}),(0,n.jsx)("ul",{className:"mt-4 flex flex-col gap-2.5",children:d.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-2 text-[13px] leading-snug text-text-muted",children:[(0,n.jsx)(el.RI,{size:15,className:"mt-0.5 flex-shrink-0 text-amber-500"}),(0,n.jsx)("span",{children:e})]},e))}),l.length>0&&(0,n.jsxs)("div",{className:"mt-5",children:[(0,n.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-text-muted",children:o("remote.unavailableOtherHosts")}),(0,n.jsx)("div",{className:"mt-1.5 flex flex-col",children:l.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),a?.(e.key)},className:"flex items-center gap-2.5 px-1 py-2.5 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 flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm text-text",children:e.label||o("agentSwitcher.unnamed")}),(0,n.jsx)(el.c_,{size:16,className:"text-text-muted flex-shrink-0"})]},e.key))})]})]})})]})}function dF(e){var t,s;let l,{stats:a,mode:i,onReset:o,onClose:c,onCopy:d,onForceWsDisconnect:u,onToggleWsBlock:m,isWsBlocked:x}=e,{t:p}=(0,eu.s)(),[h,f]=(0,r.useState)(!1);return h?(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 ",p("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 ",p("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:p("remote.minimize"),children:"─"}),(0,n.jsx)("button",{onClick:c,className:"text-text-muted hover:text-text transition-colors",title:p("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"===i?"text-blue-400 font-semibold":"text-yellow-400 font-semibold",children:"rtc"===i?"RTC enabled":"WS only"})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[p("remote.transport"),":"]}),(0,n.jsx)("span",{className:a.webrtcPercent>50?"text-blue-400 font-semibold":"text-text-muted",children:a.webrtcPercent>50?"WebRTC ✅":"WebSocket"})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[p("remote.fps"),":"]}),(0,n.jsx)("span",{className:`font-semibold ${(t=a.fps)>=15?"text-green-400":t>=10?"text-yellow-400":"text-red-400"}`,children:a.fps})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[p("remote.latency"),":"]}),(0,n.jsx)("span",{className:`font-semibold ${(s=a.latency)<50?"text-green-400":s<100?"text-yellow-400":"text-red-400"}`,children:(l=a.latency,`${Math.round(l)}ms`)})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[p("remote.tilesPerSec"),":"]}),(0,n.jsx)("span",{className:"text-text font-semibold",children:a.tilesPerSec})]}),(0,n.jsxs)("div",{className:"flex justify-between items-center",children:[(0,n.jsxs)("span",{className:"text-text-muted",children:[p("remote.bandwidth"),":"]}),(0,n.jsxs)("span",{className:"text-text font-semibold",children:[a.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:[a.webrtcTiles.toLocaleString()," tiles (",a.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:[a.wsTiles.toLocaleString()," tiles (",100-a.webrtcPercent,"%)"]})]})]}),(0,n.jsxs)("div",{className:"flex gap-2 border-t border-border pt-3",children:[(0,n.jsx)("button",{onClick:o,className:"flex-1 bg-surface hover:bg-surface-2 text-text py-2 px-3 rounded transition-colors text-xs",children:p("remote.clearStats")}),(0,n.jsx)("button",{onClick:d,className:"flex-1 bg-surface hover:bg-surface-2 text-text py-2 px-3 rounded transition-colors text-xs",children:"Copy"})]}),(u||m)&&(0,n.jsxs)("div",{className:"flex gap-2 mt-2",children:[u&&(0,n.jsx)("button",{onClick:u,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"}),m&&(0,n.jsx)("button",{onClick:m,className:`flex-1 py-2 px-3 rounded transition-colors text-xs ${x?"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:x?"\uD83D\uDD12 WS Blocked":"\uD83D\uDEAB Block WS"})]})]})}function dO(e){let{onClose:t,busRef:s,protocolRef:l,connected:a,carrier:i,hostPlatform:o,hostLabel:u,remoteStatus:m=null,otherReadyHosts:x=[],onOpenHost:p}=e,{t:h}=(0,eu.s)(),[f,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(null),{stats:y,trackTilesReceived:w,resetStats:j}=function(){let[e,t]=(0,r.useState)(dj),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(dj)},[])}}(),[k,N]=(0,r.useState)(c.eR.debug?.panel??!1),[C,S]=(0,r.useState)(!1),T=c.eR.enableWebRTC?"rtc":"ws",E=(0,r.useCallback)(()=>{let e={mode:T,...y,ts:new Date().toISOString()};navigator.clipboard?.writeText(JSON.stringify(e,null,2)).catch(()=>{})},[y,T]),R=(0,r.useRef)(y);(0,r.useEffect)(()=>{R.current=y},[y]),(0,r.useEffect)(()=>{(0,d.c)("remote",`[stats] interval started, mode=${T}`);let e=setInterval(()=>{(0,d.c)("remote",`[stats][${T}]`,JSON.stringify(R.current))},5e3);return()=>{(0,d.c)("remote","[stats] interval stopped"),clearInterval(e)}},[T]);let M=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)(function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left";s&&l("mouse-press",{x:e,y:t,button:n})},[l,s]),i=(0,r.useCallback)(function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left";s&&l("mouse-release",{x:e,y:t,button:n})},[l,s]),o=(0,r.useCallback)(function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left",r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];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)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];s&&l("key-press",{key:e,modifier:t})},[l,s]),m=(0,r.useCallback)(e=>{s&&l("type-text",{text:e})},[l,s]),x=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];s&&l("scroll",{direction:e,amount:t,horizontal:n})},[l,s]),p=(0,r.useCallback)(()=>{s&&l("boost-stream")},[l,s]),h=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;s&&l("set-focus",{rect:e,zoom:t,viewerWidth:window.innerWidth,dpr:window.devicePixelRatio||1})},[l,s]),f=(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:f,emitMousePress:a,emitMouseRelease:i,emitMouseClick:o,emitMouseMove:c,emitMouseDragSelect:d,emitKeyPress:u,emitTypeText:m,emitScroll:x,emitBoostStream:p,emitSetFocus:h,emitDesktopSwitch:b}}(s,a),{streaming:$,emitRequestScreenWithHashes:z,emitDesktopSwitch:P}=M,A=dx({emits:M,streaming:$,hostPlatform:o}),{canvasRef:I,serverDimensionsRef:D,handleCanvasDimensions:L,resetPan:B,zoomGestureTimeoutRef:F,textInputRef:O,keyboardOn:_}=A,K=(0,r.useCallback)(()=>b(!0),[]);(0,r.useEffect)(()=>{i&&(0,d.c)("remote",`[remote] carrier: ${i}`)},[i]);let W=dw(s,$,I),{screenLocked:H,unlockReady:q,unlockResult:U,setUnlockResult:X,clipboard:V,monitors:G,activeMonitorIndex:J,cursorShape:Y}=function(e){let{busRef:t,connected:s,streaming:n,canvasRef:l,serverDimensionsRef:a,handleCanvasDimensions:i,resetPan:o,zoomGestureTimeoutRef:u,trackTilesReceived:m,tiles:x,onUnavailable:p}=e,[h,f]=(0,r.useState)(!1),[b,g]=(0,r.useState)(!1),[v,y]=(0,r.useState)(null),w=dk(),[j,k]=(0,r.useState)([]),[N,C]=(0,r.useState)(0),[S,T]=(0,r.useState)(null),E=(0,r.useRef)(null),{renderedTilesRef:R,handleFullScreenData:M,handleTilesData:$,handleTilesBinary:z,handleTilesBinaryV2:P,handleTilesMeta:A,handleScreenDimensions:I,cleanupTiles:D,requestScreenWithHashes:L}=x;return(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s)return;D();let n=e=>{I(e),i(e,R)},r=e=>M(e),l=e=>{let t=e.transport||"ws";t!==E.current&&(E.current=t,(0,d.c)("remote",`[remote] tiles via ${t}`)),m(e,t),$(e)},a=e=>console.error("Screen error:",e),c=()=>p?.(),x=function(){let{locked:e,ready:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};f(!!e),g(!!t),e&&y(null)},h=e=>y(e||null),b=(e,t)=>{"ws"!==E.current&&(E.current="ws",(0,d.c)("remote",`[remote] tiles via ws${t}`)),m(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now(),{tileCount:s,timestamp:n,bytes:r}=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now(),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")},v=e=>{b(e,""),z(e)},j=e=>A(e),N=e=>{b(e," v2"),P(e)},S=()=>{D(),e.emit("get-screen-dimensions"),e.emit("get-unlock-state"),e.emit("start-streaming")},L=()=>S(),B=e=>{let{text:t,hash:s}=e;return w.push(t,s)},F=e=>{let{list:t,activeIndex:s}=e;k(Array.isArray(t)?t:[]),"number"==typeof s&&C(s)},O=e=>{D(),o(),"number"==typeof e?.monitorIndex&&C(e.monitorIndex)};e.on("screen-dimensions",n),e.on("full-screen-data",r),e.on("tiles-data",l),e.on("tiles-data-binary",v),e.on("tiles-bin-v2",N),e.on("tiles-meta",j),e.on("screen-error",a),e.on("remote:unavailable",c),e.on("screen-locked",x),e.on("unlock-result",h),e.on("remote:ready",L),e.on("clipboard-update",B),e.on("monitors",F),e.on("frame_meta",O);let _=e=>T(e?.shape??null);return e.on("cursor-shape",_),S(),()=>{e.emit("stop-streaming"),e.off("screen-dimensions",n),e.off("full-screen-data",r),e.off("tiles-data",l),e.off("tiles-data-binary",v),e.off("tiles-bin-v2",N),e.off("tiles-meta",j),e.off("screen-error",a),e.off("remote:unavailable",c),e.off("screen-locked",x),e.off("unlock-result",h),e.off("remote:ready",L),e.off("clipboard-update",B),e.off("monitors",F),e.off("frame_meta",O),e.off("cursor-shape",_),D(),u.current&&clearTimeout(u.current)}},[s]),(0,r.useEffect)(()=>{if(!n||!s||!t?.current)return;let e=setInterval(()=>{0===R.current.size?t.current.emit("request-screen-with-hashes",{tileHashes:[]}):L()},c.eR.hashRequestInterval);return()=>clearInterval(e)},[n,s,t,L,R]),(0,r.useEffect)(()=>{if(!s)return;let e=()=>{let e=l.current;if(!e||e.width>0)return!0;let{width:s,height:n}=a.current||{};return s>0?i({width:s,height:n},R):t.current?.emit("get-screen-dimensions"),!1};if(e())return;let n=setInterval(()=>{e()&&clearInterval(n)},c.eR.restreamDelay);return()=>clearInterval(n)},[s,t,l,a,i,R]),(0,r.useEffect)(()=>{let e=t?.current;if(!e||!s)return;let n=()=>{document.hidden?e.emit("stop-streaming"):e.emit("start-streaming")};return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[s,t]),{screenLocked:h,unlockReady:b,unlockResult:v,setUnlockResult:y,clipboard:w,monitors:j,activeMonitorIndex:N,cursorShape:S}}({busRef:s,connected:a,streaming:$,canvasRef:I,serverDimensionsRef:D,handleCanvasDimensions:L,resetPan:B,zoomGestureTimeoutRef:F,trackTilesReceived:w,tiles:W,onUnavailable:()=>v(s)}),Z=(0,r.useCallback)(e=>{s?.current?.emit("select_monitor",{index:e})},[s]);return g&&g===s?(0,n.jsx)(dB,{hostLabel:u,status:m,platform:o,hosts:x,onOpenHost:p,onBack:t}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(dL,{surface:A,connected:a,clipboard:V,hasFrame:W.hasFrame,onBack:K,onClose:K,onRefresh:()=>z([]),onDesktopSwitch:P,onToggleDebug:()=>N(e=>!e),debugOn:k,canvasProps:{cursorShape:Y,monitors:G,activeMonitorIndex:J,onSelectMonitor:Z,screenLocked:H,unlockReady:q,unlockResult:U,onUnlockSubmit:e=>{X(null),s?.current?.emit("desktop-unlock",{text:e})}},placeholder:(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"})," / ",h("workspaces.emptyTagRemote")]}),(0,n.jsx)("span",{className:"empty-word login-hero-grad",children:h("workspaces.emptyWordRemote")}),(0,n.jsx)("span",{className:"empty-meta",dangerouslySetInnerHTML:{__html:h("workspaces.emptyMetaRemote")}}),(0,n.jsxs)("span",{className:"empty-go",children:[(0,n.jsx)(de.A,{size:"sm"}),h("remote.connecting")]})]})]})}),k&&(0,n.jsx)(dF,{onForceWsDisconnect:()=>s?.current?.disconnect(),onToggleWsBlock:()=>{let e=l?.current;if(!e)return;let t=!e.wsBlocked;e.setWsBlocked(t),S(t)},isWsBlocked:C,stats:y,mode:T,onReset:j,onCopy:E,onClose:()=>N(!1)}),(0,n.jsx)(ec.A,{isOpen:f,onClose:()=>{b(!1),_&&O.current?.focus()},onConfirm:()=>t?.(),title:h("remote.exitRemote"),message:h("remoteControls.exitConfirmMessage"),confirmText:h("connection.exit"),cancelText:h("common.cancel")})]})}let d_={darwin:"macOS",win32:"Windows",linux:"Linux"};function dK(e){let{hosts:t=[],onPick:s,onClose:r}=e,{t:l}=(0,eu.s)();return(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center scrim fade-in",onClick:r,children:(0,n.jsxs)("div",{className:"card-elev w-full sm:max-w-sm max-h-[70%] flex flex-col overflow-hidden rounded-t-3xl sm:rounded-3xl sheet-rise",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"sm:hidden mx-auto mt-2.5 h-1 w-9 rounded-full bg-text-subtle/40","aria-hidden":"true"}),(0,n.jsx)("h2",{className:"px-5 pt-3 pb-2 text-base font-semibold text-text",children:l("remote.title")}),(0,n.jsx)("div",{className:"px-2 overflow-auto modal-scrollable",style:{paddingBottom:"max(0.5rem, var(--safe-bottom))"},children:t.map(e=>{let t=[d_[e.platform],l("hosts.online")].filter(Boolean).join(" \xb7 ");return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),s?.(e.key)},className:"w-full flex items-center gap-3 px-3 py-2.5 text-left rounded-2xl hover:bg-surface-2 active:bg-surface-2 transition-colors",children:[(0,n.jsxs)("span",{className:"relative grid place-items-center w-10 h-10 rounded-xl bg-surface-2 text-text-muted shrink-0",children:[(0,n.jsx)(el.VA,{size:18}),(0,n.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-green-500 ring-2 ring-surface-2"})]}),(0,n.jsxs)("span",{className:"flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"block text-sm font-medium text-text truncate",children:e.label||l("agentSwitcher.unnamed")}),(0,n.jsx)("span",{className:"block text-[11px] text-text-muted truncate",children:t})]}),(0,n.jsx)(el.c_,{size:16,className:"text-text-subtle shrink-0"})]},e.key)})})]})})}function dW(e){return e?{scale:Math.min(1.25,window.devicePixelRatio||1),quality:85}:{}}let dH=new Set(["localhost","127.0.0.1","::1"]),dq=e=>"local"===e||dH.has(window.location.hostname);function dU(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";return(0,r.useCallback)(function(s){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return 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 dX(e){let{busRef:t,connected:s,targetId:n,onPainted:l,canvasRef:a,frameRef:i,applyDimensions:o}=e,d=(0,r.useRef)(null),u=a||d,[m,x]=(0,r.useState)(null),p=(0,r.useRef)(null),h=i||p,f=(0,r.useRef)(null),b=(0,r.useRef)(null),g=(0,r.useRef)(l);(0,r.useEffect)(()=>{g.current=l},[l]);let{hasFrame:v,handleTilesData:y,handleTilesBinaryV2:w,cleanupTiles:j,requestScreenWithHashes:k,handleScreenDimensions:N,renderedTilesRef:C}=dw(t,s&&!!n,u,{ackEvent:"browser:stream.ack",verifyEvent:"browser:request-tiles-hashes",targetId:n,resetWorker:!1});return(0,r.useEffect)(()=>{let e=t?.current;if(!s||!e?.on||!n)return;j();let r=!1;if(f.current!==n){f.current=n,b.current=null,h.current=null,x(null);let e=u.current;e?.width&&e.getContext("2d").clearRect(0,0,e.width,e.height)}let l=e=>{r||b.current===n&&(y(e),g.current?.({},e.bytes))},a=e=>{r||b.current===n&&(w(e),g.current?.({},e?.byteLength||0))},i=t=>{if(r||t?.targetId!==n||!t.frameW||!t.frameH)return;b.current=n;let s=h.current,l=!s||s.w!==t.frameW||s.h!==t.frameH,a=u.current,i=!!a&&(a.width!==t.frameW||a.height!==t.frameH),c={w:t.frameW,h:t.frameH,meta:{...s?.meta||{},deviceWidth:t.deviceWidth,deviceHeight:t.deviceHeight}};h.current=c,(l||i)&&(j(),N({tileCount:t.tileCount}),x(c),o?o({width:t.frameW,height:t.frameH},C):u.current&&(u.current.width=t.frameW,u.current.height=t.frameH),e.emit?.("browser:request-tiles-hashes",{targetId:n,tileHashes:[]}))};e.on?.("browser:tiles-data",l),e.on?.("browser:tiles-bin",a),e.on?.("browser:screen-dimensions",i);let d=setInterval(()=>{r||!("u"<typeof document)&&document.hidden||(0===C.current.size?e.emit?.("browser:request-tiles-hashes",{targetId:n,tileHashes:[]}):k())},c.eR.hashRequestInterval);return()=>{r=!0,e.off?.("browser:tiles-data",l),e.off?.("browser:tiles-bin",a),e.off?.("browser:screen-dimensions",i),clearInterval(d),j()}},[t,s,n,j,y,w,N,k,C,u,h,o]),{canvasRef:u,frame:v||m?m||{w:1280,h:720}:null,frameRef:h}}function dV(e){let{title:t,icon:s=null,onClose:l,children:a,footer:i=null,wide:o=!1}=e;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]),"u"<typeof document)?null:(0,se.createPortal)((0,n.jsx)("div",{className:"modal-overlay z-50 scrim fade-in",onClick:l,children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",className:`card-elev ${o?"max-w-lg":"max-w-md"} w-full my-auto overflow-hidden flex flex-col pop-in`,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:[s,(0,n.jsx)("span",{className:"truncate",children:t})]}),(0,n.jsx)("button",{onClick:l,"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:a}),i&&(0,n.jsx)("div",{className:"px-4 py-3 border-t border-border-subtle",children:i})]})}),document.body)}function dG(e){let{element:t,autoFocusNote:s=!1,at:l=null,onAddAnnotation:a,onClose:i}=e,[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!1),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),f=(0,r.useRef)(null);if((0,r.useEffect)(()=>{s&&f.current?.focus()},[s]),!t)return null;let b=t.selector||t.tag||"element",g=async()=>{(0,ed.e)(),await navigator.clipboard?.writeText(b),u(!0),setTimeout(()=>u(!1),2e3)},v=async()=>{(0,ed.e)();let e=[`### Target Element: \`<${t.tag}>\``,`- Selector: \`${b}\``,t.text?`- Text: "${t.text}"`:null,t.html?`- HTML: \`${t.html.slice(0,300)}\``:null,o?`- Instructions: ${o}`:null].filter(Boolean).join("\n");await navigator.clipboard?.writeText(e),x(!0),setTimeout(()=>x(!1),2e3)},y=()=>{(0,ed.e)(),a?.({id:Date.now().toString(),tag:t.tag,selector:b,text:t.text,html:t.html,note:o.trim()}),h(!0),setTimeout(()=>{h(!1),i()},800)},w=(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:t.tag}),(0,n.jsx)("span",{className:"font-mono text-xs text-text truncate",children:b})]}),j=(0,n.jsxs)(n.Fragment,{children:[!l&&(0,n.jsx)("div",{className:"pb-1",children:w}),t.text&&(0,n.jsx)("div",{className:"text-xs text-text-muted bg-surface-2 p-2 rounded-brand font-mono line-clamp-2",children:t.text}),t.styles&&(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-[11px] text-text-muted font-mono",children:[t.styles.display&&(0,n.jsxs)("span",{children:["display: ",t.styles.display]}),t.styles.fontSize&&(0,n.jsxs)("span",{children:["size: ",t.styles.fontSize]}),t.styles.color&&(0,n.jsxs)("span",{children:["color: ",t.styles.color]})]}),(0,n.jsx)("input",{ref:f,type:"text",value:o,onChange:e=>c(e.target.value),onKeyDown:e=>"Enter"===e.key&&y(),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"})]}),k=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:g,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:[d?(0,n.jsx)(el.aJ,{size:13,className:"text-emerald-500"}):(0,n.jsx)(el.QR,{size:13}),d?"Copied":"Copy Selector"]}),(0,n.jsxs)("button",{onClick:v,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:[m?(0,n.jsx)(el.aJ,{size:13}):(0,n.jsx)(el.sU,{size:13}),m?"Copied AI Prompt":"Copy for AI"]}),(0,n.jsxs)("button",{onClick:y,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:[p?(0,n.jsx)(el.aJ,{size:13,className:"text-emerald-500"}):(0,n.jsx)(el.Vn,{size:13}),p?"Saved":"Add Note"]})]});return l?(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 pop-in absolute w-[300px] max-w-[90%] max-h-[60%] rounded-xl",style:{left:`min(${l.x}px, calc(100% - 310px))`,top:`min(${l.y}px, calc(100% - 120px))`},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[w,(0,n.jsx)("button",{onClick:i,className:"p-1 text-text-muted hover:text-text rounded-brand shrink-0",title:"Close",children:(0,n.jsx)(el.X,{size:15})})]}),j,(0,n.jsx)("div",{className:"flex items-center gap-2 pt-1",children:k})]}):(0,n.jsx)(dV,{title:"Inspect Element",onClose:i,footer:(0,n.jsx)("div",{className:"flex items-center gap-2",children:k}),children:(0,n.jsx)("div",{className:"flex flex-col gap-2.5",children:j})})}function dJ(e){let{annotations:t=[],onDelete:s,onClear:l,onClose:a}=e,[i,o]=(0,r.useState)(!1),[c,d]=(0,r.useState)(!1),u=()=>[`## Design & Code Feedback (${t.length} items)`,...t.map((e,t)=>[`
21
+ ### ${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"),m=async()=>{t.length&&((0,ed.e)(),await navigator.clipboard?.writeText?.(u()),o(!0),setTimeout(()=>o(!1),2e3))};return(0,n.jsx)(dV,{title:`Collected Notes (${t.length})`,onClose:a,footer:t.length>0?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{if(!t.length)return;(0,ed.e)();let e=Object.entries(f.B.getState().agentBySession||{}).find(e=>{let[,t]=e;return t?.endsWith("-ui")});if(!e)return void m();let[s]=e,n=u();for(let e of(f.B.getState().popView(),window.dispatchEvent(new CustomEvent(eg.vP,{detail:{sessionId:s}})),[200,700]))setTimeout(()=>window.dispatchEvent(new CustomEvent("9r:ai-prompt",{detail:{sessionId:s,text:n}})),e);d(!0),setTimeout(()=>d(!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:[c?(0,n.jsx)(el.aJ,{size:13}):(0,n.jsx)(el.Vn,{size:13}),c?"Sent":"Send to AI"]}),(0,n.jsxs)("button",{onClick:m,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:[i?(0,n.jsx)(el.aJ,{size:13}):(0,n.jsx)(el.QR,{size:13}),i?"Copied":"Copy All"]}),(0,n.jsx)("button",{onClick: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})})]}):null,children:0===t.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:t.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-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:[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.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:()=>s?.(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||t))})})}function dY(e){let{frameImgSrc:t,onClose:s}=e,l=(0,r.useRef)(null),[a,i]=(0,r.useState)(!1),[o,c]=(0,r.useState)("#ef4444"),[d,u]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=l.current;if(!e)return;let s=e.getContext("2d"),n=new Image;n.src=t,n.onload=()=>{e.width=n.naturalWidth||800,e.height=n.naturalHeight||600,s.drawImage(n,0,0)}},[t]);let m=e=>{let t=l.current,s=t.getBoundingClientRect(),n=t.width/s.width,r=t.height/s.height;return{x:(e.clientX-s.left)*n,y:(e.clientY-s.top)*r}},x=()=>{i(!1)},p=async()=>{(0,ed.e)();let e=l.current;if(e)try{e.toBlob(async e=>{e&&(await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),u(!0),setTimeout(()=>u(!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:()=>c(e),className:`w-5 h-5 rounded-full border-2 transition-transform ${o===e?"scale-110 border-white":"border-transparent"}`,style:{backgroundColor:e}},e)),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)();let e=l.current,s=e.getContext("2d"),n=new Image;n.src=t,n.onload=()=>{s.clearRect(0,0,e.width,e.height),s.drawImage(n,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:p,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:[d?(0,n.jsx)(el.aJ,{size:13}):(0,n.jsx)(el.QR,{size:13}),d?"Copied":"Copy Image"]}),(0,n.jsx)("button",{onClick:s,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:l,onPointerDown:e=>{i(!0);let t=l.current.getContext("2d"),s=m(e);t.strokeStyle=o,t.lineWidth=4,t.lineCap="round",t.beginPath(),t.moveTo(s.x,s.y)},onPointerMove:e=>{if(!a)return;let t=l.current.getContext("2d"),s=m(e);t.lineTo(s.x,s.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 dZ(e){let{onEval:t,onClose:s}=e,[l,a]=(0,r.useState)(""),[i,o]=(0,r.useState)([]),[c,d]=(0,r.useState)(!1),u=async()=>{let e=l.trim();if(!e||c)return;(0,ed.e)(),d(!0);let s=await t?.(e);d(!1),o(t=>[...t,{code:e,result:s?.result!==void 0?s.result:s?.error||"undefined",ok:s?.ok!==!1}]),a("")};return(0,n.jsx)(dV,{wide:!0,title:"Console REPL",icon:(0,n.jsx)(el.BK,{size:14,className:"text-brand-500 shrink-0"}),onClose:s,footer:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:l,onChange:e=>a(e.target.value),onKeyDown:e=>"Enter"===e.key&&u(),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:u,disabled:!l.trim()||c,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===i.length&&(0,n.jsx)("span",{className:"text-text-muted",children:"Type a JS expression below to evaluate on the page."}),i.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 dQ(e){let{invoke:t,profile:s="default",onSelectProfile:l,targetId:a,url:i,initialSection:o=null,onCopyUrl:c,onClose:d}=e,u=e=>l?.(e||"default"),[m,x]=(0,r.useState)([]),[p,h]=(0,r.useState)([]),[f,b]=(0,r.useState)(!1),[g,v]=(0,r.useState)(""),[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(!1),[N,C]=(0,r.useState)(""),S=(0,r.useRef)(null),[T,E]=(0,r.useState)("cookies"===o),[R,M]=(0,r.useState)(""),[$,z]=(0,r.useState)(null),[P,A]=(0,r.useState)(null);(0,r.useEffect)(()=>{t?.("profiles.list")?.then(e=>{e?.ok&&Array.isArray(e.profiles)&&x(e.profiles)}),t?.("browsers.detect")?.then(e=>{e?.ok&&Array.isArray(e.browsers)&&h(e.browsers)})},[t]);let I=e=>{(0,ed.e)(),u(e),d?.()},D=async()=>{let e=g.trim();if(!e)return;(0,ed.e)();let s=await t?.("profiles.create",{name:e});if(s?.ok){b(!1),v("");let s=await t?.("profiles.list");s?.ok&&x(s.profiles),u(e)}},L=async()=>{if(!R.trim()||!a)return;(0,ed.e)(),z("Importing…");let e=await t?.("cookie.import",{targetId:a,content:R.trim()});e?.ok?(z(`Imported ${e.imported} cookies!`),setTimeout(()=>{z(null),E(!1),M("")},2e3)):z(e?.error||"Import failed")},B=async(e,s,n,r)=>{let l=`_${e}`,a=String(r).replace(/[^a-zA-Z0-9]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""),i=N.trim()||(a?a.slice(0,32-l.length)+l:e);(0,ed.e)(),k(!1),z(`Importing from ${n}…`);let o=await t?.("profiles.createFromBrowser",{family:e,profileDirectory:s,name:i});if(o?.ok){let e=await t?.("profiles.list");e?.ok&&x(e.profiles),z(null),I(o.profile||i)}else z(o?.error||"Import failed")},F=async e=>{(0,ed.e)();let n=await t?.("profiles.remove",{name:e});if(n?.ok){s===e&&u("default");let n=await t?.("profiles.list");n?.ok&&x(n.profiles)}};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(dV,{wide:!0,title:"Browser & Profiles",onClose:d,children:(0,n.jsxs)("div",{className:"flex flex-col gap-3",children:[$&&!j&&(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,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:[...m].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 ${s===e.name?"bg-surface-3 text-text font-medium":"hover:bg-surface-2 text-text-muted"}`,onClick:()=>I(e.name),children:[(0,n.jsx)(r3,{name:e.name}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),s===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(),w(e.name)},className:"p-1 rounded shrink-0 transition-colors text-text-muted hover:text-red-500 opacity-0 group-hover:opacity-100 focus:opacity-100 hover:bg-surface/60",title:"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:g,onChange:e=>v(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:()=>b(!1),className:"px-2 py-1 text-xs text-text-muted",children:"Cancel"}),(0,n.jsx)("button",{onClick:D,disabled:!g.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:()=>b(!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:()=>{C(""),k(!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:"Import Profile"})]})]})}),j&&(0,n.jsx)(dV,{wide:!0,title:"Import Profile",onClose:()=>k(!1),footer:(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("input",{ref:S,type:"text",value:N,onChange:e=>C(e.target.value),onKeyDown:e=>"Enter"===e.key&&p?.[0]?.profiles?.[0]&&B(p[0].family,p[0].profiles[0].directory,`${p[0].label} (${p[0].profiles[0].name})`,p[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===p.length?(0,n.jsx)("div",{className:"text-xs text-text-muted py-1",children:"No installed browsers detected on host."}):p.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:()=>B(e.family,t.directory,`${e.label} (${t.name})`,t.name),disabled:P===`${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:P===`${e.family}:${t.directory}`?"Importing…":"Import"})]},t.directory))]},e.family)),T&&(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=>M(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:L,disabled:!R.trim()||!a,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:()=>E(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 ${T?"rotate-180":""}`}),(0,n.jsx)("span",{children:"Paste cookies manually…"})]})]})}),(0,n.jsx)(ec.A,{isOpen:!!y,onClose:()=>w(null),onConfirm:()=>F(y),title:"Delete profile",message:`Delete profile "${y}" and its saved logins?`,confirmText:"Delete"})]})}function d0(e){let{menu:t,items:s,onClose:l}=e,a=(0,r.useRef)(null),i=nK(a,t?.x??0,t?.y??0);return((0,r.useEffect)(()=>{if(!t)return;let e=e=>{a.current&&!a.current.contains(e.target)&&l()},s=e=>{"Escape"===e.key&&l()};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",s),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",s)}},[t,l]),t)?(0,n.jsx)("div",{ref:a,className:"fixed z-[80] menu-popover p-1 min-w-[170px] pop-in shadow-xl",style:{left:i.left,top:i.top},children:s.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?.(),l()},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 d1(e){let{items:t,activeIdx:s,onPick:r,onHover:l}=e;return t?.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 pop-in",children:t.map((e,t)=>(0,n.jsxs)("button",{type:"button",onMouseEnter:()=>l?.(t),onClick:()=>r(e),className:`w-full text-left px-3 py-2 rounded-[6px] flex items-center gap-2 ${t===s?"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 d2={width:720,height:900};function d5(e){let{busRef:t,connected:s=!1,targetId:l,url:a,profile:i="default",onClose:o}=e,{t:c}=(0,eu.s)(),d=dU(t,i),m=dq((0,u.d)(e=>e.connectionMode)),x=(0,r.useRef)(null),p=(0,r.useRef)(null),h=(0,r.useRef)(null),f=(0,r.useRef)(null),b=(0,r.useRef)(null),g=(0,r.useRef)(new Map);(0,r.useEffect)(()=>{let e=t?.current;if(s&&e?.emit&&l)return e.emit("browser:stream.start",{targetId:l,...d2,...dW(m),profile:i,isPopup:!0}),()=>{e.emit("browser:stream.stop",{targetId:l})}},[t,s,l,m]);let{canvasRef:v,frame:y,frameRef:w}=dX({busRef:t,connected:s,targetId:l});(0,r.useEffect)(()=>()=>{h.current&&clearTimeout(h.current),f.current&&clearTimeout(f.current),b.current?.timer&&clearTimeout(b.current.timer)},[]);let j=(0,r.useCallback)(e=>{l&&e.length&&t?.current?.emit?.("browser:input",{targetId:l,events:e,profile:i})},[t,l]),k=(0,r.useCallback)((e,t)=>{let s=v.current,n=w.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))}},[]),N=(0,r.useCallback)(e=>k(e.clientX,e.clientY),[k]),C=e=>{if("touch"===e.pointerType){g.current.delete(e.pointerId),j([{t:"touch",type:"end"}]);return}if(!p.current||!w.current)return;p.current=null;let t=N(e),s=2===e.button?"right":1===e.button?"middle":"left";j([{t:"pointer",type:"release",x:t.x,y:t.y,button:s}])};return(0,r.useEffect)(()=>{let e=x.current;if(!e||!l)return;let t=e=>{if(!w.current)return;e.preventDefault();let t=k(e.clientX,e.clientY),s=b.current||(b.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,j([{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)},[l,j,k]),(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(w.current&&!(e.button>2)){if((0,ed.e)(),"touch"===e.pointerType){g.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),j([{t:"touch",type:"start",points:[N(e)]}]);return}p.current={sx:e.clientX,sy:e.clientY,moved:!1},j([{t:"pointer",type:"press",x:N(e).x,y:N(e).y,button:2===e.button?"right":1===e.button?"middle":"left"}])}},onPointerMove:e=>{if("touch"===e.pointerType){if(!g.current.has(e.pointerId)||(g.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),f.current))return;f.current=setTimeout(()=>{f.current=null,j([{t:"touch",type:"move",points:[N(e)]}])},16);return}if(p.current&&w.current){let t=p.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,j([{t:"pointer",type:"move",x:N(e).x,y:N(e).y,drag:!0}])},30));return}!w.current||h.current||(h.current=setTimeout(()=>{h.current=null,j([{t:"pointer",type:"move",x:N(e).x,y:N(e).y}])},80))},onPointerUp:C,onPointerCancel:C,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:a||"popup"}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d("close",{targetId:l}),o?.()},className:"p-1 rounded text-text-muted hover:text-text hover:bg-surface-2 transition-colors",title:c("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:v,width:y?.w||16,height:y?.h||16,className:`max-w-full max-h-full object-contain pointer-events-none ${y?"":"opacity-0"}`}),!y&&(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"})," ",c("sites.browserPaneLoading")]})]})]})})}function d3(e){let{picked:t=[],url:s=null,onRemoveItem:l,onClear:a,onClose:i}=e,[o,c]=(0,r.useState)("review"),[d,u]=(0,r.useState)(""),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(null),b=(0,P.rh)(e=>e.hosts),g=(0,P.rh)(e=>e.currentKey),v=(0,f.B)(e=>e.agentBySession||{}),y=eI(),w=(0,r.useMemo)(()=>(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]: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")})(t,s)+(d.trim()?`
22
+
23
+ ${d.trim()}`:""),[t,s,d]),j=(0,r.useMemo)(()=>Object.values(b||{}).sort((e,t)=>e.key===g?-1:+(t.key===g)).flatMap(e=>(e.sessions||[]).map(t=>({...t,hostLabel:e.key===g?null:e.label||e.key}))),[b,g]),k=async()=>{(0,ed.e)(),await navigator.clipboard?.writeText(w),x(!0),setTimeout(()=>x(!1),2e3)};return"sessions"===o?(0,n.jsx)(dV,{wide:!0,title:"Send to Session",icon:(0,n.jsx)(el.JG,{size:14,className:"text-text-muted shrink-0"}),onClose:i,children:(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[0===j.length&&(0,n.jsx)("div",{className:"py-6 text-center text-xs text-text-muted",children:"No running sessions."}),j.map(e=>{let t=s7(y[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:w}),f.B.getState().popView(),window.dispatchEvent(new CustomEvent(eg.vP,{detail:{sessionId:e.id}})),h(e.id),a?.(),setTimeout(i,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:[p===e.id?(0,n.jsx)(el.aJ,{size:14,className:"text-emerald-500"}):e8(v[e.id])?(0,n.jsx)("img",{src:e8(v[e.id]),alt:"",width:16,height:16,className:`w-4 h-4 object-contain ${e6}`}):(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-text-muted"}),p!==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)(dV,{wide:!0,title:`Picked Elements (${t.length})`,onClose:i,footer:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),c("sessions")},disabled:!t.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:k,disabled:!t.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:[m?(0,n.jsx)(el.aJ,{size:13,className:"text-emerald-500"}):(0,n.jsx)(el.QR,{size:13}),m?"Copied":"Copy"]}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),a?.()},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:[t.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)(),l?.(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:d,onChange:e=>u(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 d4(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 d6="right",d8=[{id:"ctrl",label:"Ctrl",modifier:"ctrl",type:"modifier"},{id:"alt",label:"Alt",modifier:"alt",type:"modifier"},{id:"shift",label:"Shift",modifier:"shift",type:"modifier"},{id:"cmd",label:"⌘",modifier:"cmd",type:"modifier"},{id:"esc",label:"Esc",key:"escape",type:"key"},{id:"tab",label:"Tab",key:"tab",type:"key"},{id:"enter",label:"↵",key:"enter",type:"key",primary:!0},{id:"backspace",label:"⌫",key:"backspace",type:"key"},{id:"undo",label:"Undo",key:"z",modifiers:["control"],type:"combo",osAdaptive:!0},{id:"redo",label:"Redo",key:"z",modifiers:["control","shift"],type:"combo",osAdaptive:!0},{id:"copy",label:"Copy",key:"c",modifiers:["control"],type:"combo",osAdaptive:!0},{id:"cut",label:"Cut",key:"x",modifiers:["control"],type:"combo",osAdaptive:!0},{id:"paste",label:"Paste",key:"v",modifiers:["control"],type:"combo",osAdaptive:!0},{id:"selectAll",label:"All",key:"a",modifiers:["control"],type:"combo",osAdaptive:!0},{id:"up",label:"↑",key:"up",type:"arrow"},{id:"down",label:"↓",key:"down",type:"arrow"},{id:"left",label:"←",key:"left",type:"arrow"},{id:"right",label:"→",key:"right",type:"arrow"},{id:"home",label:"Home",key:"home",type:"key"},{id:"end",label:"End",key:"end",type:"key"},{id:"pgup",label:"PgUp",key:"pageup",type:"key"},{id:"pgdn",label:"PgDown",key:"pagedown",type:"key"},{id:"del",label:"Del",key:"delete",type:"key"}],d9=["esc","undo","up","down","tab","ctrl","alt","shift","cmd","backspace"],d7="enter",ue=[["left","right","home","end","pgup","pgdn","del"],["copy","cut","paste","selectAll","redo"]],ut=function(e){for(var t=arguments.length,s=Array(t>1?t-1:0),n=1;n<t;n++)s[n-1]=arguments[n];(0,ed.e)(),e?.(...s)};function us(e){let t,s,l,a,{streaming:i,canvasZoom:o,clipboardNew:d,clipboardText:u,onOpenClipboard:m,selectionMode:x,pointerMode:p,handMode:h,inputMode:f,onToggleHandMode:b,onTogglePointerMode:g,modifierKeys:v,textInputValue:y,textInputRef:w,keyboardOn:j,showTextPanel:k,onResetZoom:N,onRefresh:C,onToggleSelection:S,onToggleModifier:T,onToggleKeyboard:E,onToggleTextPanel:R,onToggleHelp:M,onEmitKey:$,onTextInputChange:z,onTextInputFocus:P,onTextInputBlur:A,onTextInputKeyDown:I,onDirectInputChange:D,onSendText:L,onClose:B,onNavBack:F,onNavForward:O,onNavReload:_,onFocusAddress:K,controlsHidden:W,onToggleControlsHidden:H,tallLandscape:q}=e,{t:U,locale:X}=(0,eu.s)(),V=(0,r.useRef)(null),[G]=sb(X),[J,Y]=(0,r.useState)(!1),Z=sy({lang:sh(G),onText:e=>{z(e);let t=V.current;t&&requestAnimationFrame(()=>{try{t.selectionStart=t.selectionEnd=t.value.length}catch{}t.scrollTop=t.scrollHeight})}});(0,r.useEffect)(()=>{let e=V.current;e&&!window.matchMedia("(orientation: landscape)").matches&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,72)}px`)},[y]);let Q=()=>{Z.listening&&Z.stop(),ut(L,i)},ee=`flex gap-1.5 overflow-auto scroll-thin-x py-0.5 pr-2 ${q?"":"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`,[et,es]=(0,r.useState)(!1),[en,er]=(0,r.useState)(!1),[ea,ei]=(0,r.useState)(0);(0,r.useEffect)(()=>{if(!d)return void ei(0);ei(Math.ceil(c.eR.clipboardBadgeTimeout/1e3));let e=setInterval(()=>{ei(e=>e<=1?0:e-1)},1e3);return()=>clearInterval(e)},[d,u]);let eo=sC("remoteBrowser.bottomKeys",d8,d9,"flat"),ec=sC("remoteBrowser.extraKeys",d8,ue,"grid");(0,r.useEffect)(()=>{if(!k)return;let e=setTimeout(()=>V.current?.focus(),350);return()=>clearTimeout(e)},[k]);let em=c.eR.pcModeControls,ex=e=>"mouse"!==f||em[e],ep=window.innerWidth<768,eh=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",l=e.label.length>1?"text-[11px]":"",a=`${r} ${l}`.trim();return"modifier"===e.type?(0,n.jsx)(dT,{onClick:()=>ut(T,e.modifier),disabled:!i,active:v[e.modifier],pinned:s,className:a,children:e.label},e.id+t):(0,n.jsx)(dT,{onClick:()=>ut($,e.key,e.modifiers||[],e.osAdaptive),disabled:!i,primary:!s&&e.primary,pinned:s,className:a,children:e.label},e.id+t)};return(0,n.jsxs)("div",{className:`bg-bg select-none relative landscape:flex landscape:flex-col landscape:shrink-0 ${W?"landscape:w-12":"landscape:w-full"}`,children:[(0,n.jsx)("textarea",{ref:w,rows:1,value:y,onChange:e=>{j?D?.(e.target.value):z(e.target.value)},onKeyDown:I,onFocus:P,onBlur:A,"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 ${W||q?"hidden":"hidden landscape:flex"}`,children:(0,n.jsx)(dT,{onClick:()=>{(0,ed.e)(),H?.(!0)},title:U("remote.hideControls"),children:(0,n.jsx)(el.X_,{size:14})})}),(0,n.jsxs)("div",{className:W?"landscape:hidden":"contents",children:[(0,n.jsxs)("div",{className:`${k?"flex":"hidden"} landscape:flex ${q?"":"landscape:flex-col"} relative z-30 px-2 py-1 gap-2 ${q?"landscape:px-0":"landscape:gap-1"}`,children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsx)(sx,{value:y,store:sl,isMobile:ep,onSelect:e=>{z(e),V.current?.focus()}}),(0,n.jsx)("textarea",{ref:V,rows:1,cols:1,value:y,onChange:e=>z(e.target.value),onFocus:P,onKeyDown:e=>{"mouse"===f&&"Enter"===e.key&&!e.shiftKey&&(e.preventDefault(),i&&Q())},placeholder:"mouse"===f?U("remoteControls.enterToSend"):U("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 ${q?"":"landscape:!h-16"}`,disabled:!i}),y?(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault(),onClick:()=>{z(""),V.current?.focus()},title:U("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",onPointerDown:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault(),onClick:()=>Y(!0),title:U("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:[Z.active&&(0,n.jsx)("div",{className:"relative shrink-0",children:(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault(),onClick:()=>{Z.listening?Z.stop():(document.activeElement?.blur(),Z.start(y))},disabled:!i,title:"not-allowed"===Z.error||"service-not-allowed"===Z.error?U("voice.denied"):U("voice.dictate"),className:`h-9 w-9 flex items-center justify-center rounded-full transition-all duration-150 ease-out disabled:opacity-40 ${Z.listening?"bg-red-500/90 text-white animate-pulse":Z.error?"bg-surface-2 text-red-400":"bg-surface-2 hover:bg-surface-3 text-text-muted hover:text-text"}`,children:Z.listening?(0,n.jsx)(el.jj,{size:18}):(0,n.jsx)(el.GO,{size:18})})}),(0,n.jsx)(dS.A,{variant:"primary",size:"sm",className:"!px-2.5 shrink-0",onPointerDown:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault(),onClick:Q,disabled:!i,children:y.trim()?U("remoteControls.send"):(0,n.jsx)(el.Lt,{size:16,strokeWidth:2.5})})]})]}),(0,n.jsx)("div",{className:`overflow-hidden transition-all duration-300 ${et?"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: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=d8.find(t=>t.id===e);return n?eh(n,100*t+s):null})}),0===t&&(0,n.jsx)("button",{onPointerDown:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),er(!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:U("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:`${ee} flex-1 min-w-0 px-0 py-0`,children:[(0,n.jsx)(dT,{onClick:()=>ut(F),disabled:!i,title:U("sites.goBack"),className:"landscape:hidden",children:(0,n.jsx)(el.JG,{size:16})}),(0,n.jsx)(dT,{onClick:()=>ut(O),disabled:!i,title:U("sites.goForward"),className:"landscape:hidden",children:(0,n.jsx)(el.c_,{size:16})}),(0,n.jsx)(dT,{onClick:()=>ut(_),disabled:!i,title:U("editor.reload"),className:"landscape:hidden",children:(0,n.jsx)(el.kt,{size:14})}),(0,n.jsx)(dT,{onClick:()=>ut(K),disabled:!i,title:"Mod+L",className:"landscape:hidden",children:(0,n.jsx)(el.qz,{size:14})}),d&&u?(0,n.jsxs)(dT,{onClick:()=>ut(m),className:"!text-red-500 landscape:hidden",title:U("common.clipboard"),children:[(0,n.jsx)(el.Ir,{size:14,className:"shrink-0"}),(0,n.jsx)("span",{className:"tabular-nums",children:ea})]}):(0,n.jsxs)(dT,{onClick:()=>ut(N),disabled:!i,className:"text-text landscape:hidden",title:U("remote.resetZoom"),children:[Math.round(100*o),"%"]}),ex("rectangleSelect")&&(0,n.jsx)(dT,{onClick:()=>ut(S),disabled:!i,active:x,title:U("remote.rectangleSelection"),className:"landscape:hidden",children:"□"}),ex("pointerModeToggle")&&(0,n.jsx)(dT,{onClick:()=>ut(g),disabled:!i,active:"trackpad"===p,title:"trackpad"===p?U("remoteControls.trackpadMode"):U("remoteControls.directMode"),className:"landscape:hidden",children:(0,n.jsx)("span",{className:"text-base leading-none",children:"\uD83D\uDDB1️"})}),ex("handMode")&&"trackpad"===p&&(0,n.jsx)(dT,{onClick:()=>ut(b),disabled:!i,active:h,title:U("remote.handMode"),className:"landscape:hidden",children:(0,n.jsx)(el.Ud,{size:14})}),ex("keyboardToggle")&&(0,n.jsx)(dT,{onClick:()=>ut(E),disabled:!i,active:j,title:U("remote.toggleKeyboard"),className:"landscape:hidden",children:(0,n.jsx)(el.s3,{size:14})}),ex("textPanel")&&(0,n.jsx)(dT,{onClick:()=>ut(R),disabled:!i,active:k,title:U("remote.textBatchInput"),className:"landscape:hidden",children:"Aa"}),ex("help")&&(0,n.jsx)(dT,{onClick:()=>ut(M),title:U("remote.help"),className:"landscape:hidden",children:(0,n.jsx)(el.mN,{size:14})})]}),(0,n.jsx)(dT,{onClick:()=>{(0,ed.e)(),es(e=>!e)},active:et,pinned:!0,className:"landscape:hidden shrink-0",title:U("remote.extraKeys"),children:et?(0,n.jsx)(el.X,{size:16}):(0,n.jsx)(el.a4,{size:16})})]}),ex("modifierRow")&&(t=eo.keys.filter(e=>e.id!==d7),s=d8.find(e=>e.id===d7),l=(0,n.jsx)(dT,{onClick:()=>{(0,ed.e)(),es(e=>!e)},active:et,pinned:!0,title:U("remote.extraKeys"),children:et?(0,n.jsx)(el.X,{size:16}):(0,n.jsx)(el.a4,{size:16})}),a=s?eh(s,"pinned",!0):null,(0,n.jsxs)("div",{className:`px-2 py-1 ${"mouse"===f?"":"safe-area-bottom"} ${q?"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:`${ee} flex-1 min-w-0`,children:t.map((e,t)=>eh(e,t))}),a]}),(0,n.jsxs)("div",{className:`${ee} hidden ${q?"landscape:flex":""}`,children:[t.map((e,t)=>eh(e,t)),l,a]}),(0,n.jsxs)("div",{className:`hidden ${q?"":"landscape:flex"} landscape:flex-col gap-1`,children:[(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[t.slice(0,5).map((e,t)=>eh(e,t)),l]}),(0,n.jsxs)("div",{className:"flex gap-1.5 overflow-x-auto scroll-thin-x",children:[t.slice(5).map((e,t)=>eh(e,t)),a]})]})]}))]}),(0,n.jsxs)("div",{className:`flex-col gap-1.5 p-1.5 ${W?"hidden landscape:flex":"hidden"}`,children:[(0,n.jsx)(dT,{onClick:()=>{(0,ed.e)(),H?.(!1)},title:U("remote.showControls"),children:(0,n.jsx)(el.kU,{size:16})}),(0,n.jsx)(dT,{onClick:()=>ut(E),disabled:!i,active:j,title:U("remote.toggleKeyboard"),children:(0,n.jsx)(el.s3,{size:16})})]}),(0,n.jsx)(sM,{isOpen:en,onClose:()=>er(!1),title:U("remote.customizeRemoteKeys"),tabs:[{id:"bottom",label:U("remoteControls.bottomRow"),hook:eo,excludeIds:[d7]},{id:"extra",label:U("remoteControls.extraPanel"),hook:ec}]}),(0,n.jsx)(so,{isOpen:J,store:sl,onSelect:e=>{z(e),V.current?.focus()},onClose:()=>Y(!1)})]})}let un=[],ur=[{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}];function ul(e){let t,s,l,{busRef:a,connected:i=!1,visible:o=!0,onBack:d,profile:m="default",onProfileChange:p,workspaceId:h="default"}=e,{t:f}=(0,eu.s)(),b=dU(a,m),g=h||"default",v=nc(e=>e.tabsByWorkspace[g]??un),y=nc(e=>e.activeByWorkspace[g]||null),w=nc(e=>e.setActive),j=nc(e=>e.setWindowFor),k=dq((0,u.d)(e=>e.connectionMode)),[N,C]=(0,r.useState)(""),[S,T]=(0,r.useState)(0),[E,R]=(0,r.useState)(null),M=(0,r.useRef)(E);(0,r.useEffect)(()=>{M.current=E},[E]);let $=nc(e=>e.viewportByWorkspace[g]??null),[z,P]=(0,r.useState)(!1),[A,I]=(0,r.useState)(null),[D,L]=(0,r.useState)(null),[B,F]=(0,r.useState)([]),[O,_]=(0,r.useState)(!1),[K,W]=(0,r.useState)(!1),[H,q]=(0,r.useState)(null),[U,X]=(0,r.useState)(!1),[V,G]=(0,r.useState)(!1),[J,Y]=(0,r.useState)(null),[Z,Q]=(0,r.useState)({back:!1,forward:!1}),[ee,et]=(0,r.useState)("default"),[es,en]=(0,r.useState)(null),[er,ea]=(0,r.useState)(null),[ei,eo]=(0,r.useState)(null),[ec,em]=(0,r.useState)(!1),[ex,ep]=(0,r.useState)({open:!1,items:[],idx:-1}),[eh,ef]=(0,r.useState)(!1),[eb,eg]=(0,r.useState)(null),[ev,ey]=(0,r.useState)([]),[ew,ej]=(0,r.useState)(!1),[ek,eN]=(0,r.useState)(null),[eC,eS]=(0,r.useState)(null),[eT,eE]=(0,r.useState)(null),[eR,eM]=(0,r.useState)(null),e$=(0,r.useRef)(null),ez=(0,r.useRef)(null),eP=(0,r.useRef)(null),eA=(0,r.useRef)({bytes:0,mark:0,applied:0}),eI=(0,r.useRef)(null),eD=(0,r.useRef)(null),eL=(0,r.useRef)(null),eB=(0,r.useRef)(!1),eF=v.find(e=>e.id===y)||v.find(e=>e.active)||v[0]||null,eO=eF?.id||null,e_=(0,r.useRef)(null),eK=(0,r.useRef)({}),eW=dk(),eH=function(e){let{busRef:t,connected:s,targetId:n,profile:l,frameRef:a,getCanvas:i,onSecondaryClick:o,onClipboard:d}=e,u=!!s&&!!n,m=(0,r.useRef)({});(0,r.useEffect)(()=>{m.current={busRef:t,targetId:n,profile:l,frameRef:a,getCanvas:i,onSecondaryClick:o,onClipboard:d}});let[x]=(0,r.useState)(()=>{var e,t;let s,n,r,l,a,i;return e=()=>m.current,t={queue:[],timer:null,held:null,pos:{x:0,y:0},clickCount:1,lastPress:{at:0,x:0,y:0,count:0}},s=()=>{t.timer&&(clearTimeout(t.timer),t.timer=null);let{busRef:s,targetId:n,profile:r,onClipboard:l}=e();if(!t.queue.length||!n){t.queue.length=0;return}let a=t.queue.splice(0);s?.current?.emit?.("browser:input",{targetId:n,events:a,profile:r},e=>{e?.clipboard&&l?.(e.clipboard)})},n=function(e){let{lazy:n=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.queue[t.queue.length-1];if(n&&r&&r.t===e.t&&r.type===e.type&&!!r.drag==!!e.drag?("wheel"===e.t&&(e.deltaX+=r.deltaX,e.deltaY+=r.deltaY),t.queue[t.queue.length-1]=e):t.queue.push(e),!n)return s();t.timer||(t.timer=setTimeout(s,30))},r=(t,s)=>{let{frameRef:n,getCanvas:r}=e(),l=n?.current?.meta,a=r?.();return{x:Math.round(t/100*(l?.deviceWidth||a?.width||0)),y:Math.round(s/100*(l?.deviceHeight||a?.height||0))}},l=(e,s)=>{t.pos=r(e,s),n({t:"pointer",type:"move",...t.pos,...t.held?{drag:!0,button:t.held}:{}},{lazy:!0})},a=function(e,s){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left";if(l===d6)return;let a=t.pos=r(e,s),i=Date.now(),o=t.lastPress;t.clickCount=Math.abs(a.x-o.x)<c.eR.moveThreshold&&Math.abs(a.y-o.y)<c.eR.moveThreshold&&i-o.at<c.eR.doubleClickDelay?Math.min(o.count+1,3):1,t.lastPress={at:i,x:a.x,y:a.y,count:t.clickCount},t.held=l,n({t:"pointer",type:"press",...a,button:l,clickCount:t.clickCount})},{emitMouseMove:l,emitMousePress:a,emitMouseRelease:i=function(e,s){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left";if(l===d6)return;let a=t.pos=r(e,s);t.held=null,n({t:"pointer",type:"release",...a,button:l,clickCount:t.clickCount})},emitMouseClick:function(t,s){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"left";if(n===d6){let n=r(t,s);e().onSecondaryClick?.(n.x,n.y);return}a(t,s,n),i(t,s,n)},emitMouseDragSelect:(e,t,s,n)=>{a(e,t),l(s,n),i(s,n)},emitKeyPress:function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return n({t:"key",key:e,modifiers:t})},emitTypeText:e=>n({t:"text",text:e}),emitTouch:(e,t)=>n({t:"touch",type:e,points:Array.isArray(t)?t.slice(0,5):[]},{lazy:"move"===e}),emitScroll:function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],l=.67*s,a="down"===e||"right"===e?1:-1,i=r||"left"===e||"right"===e;n({t:"wheel",...t.pos,deltaX:i?a*l:0,deltaY:i?0:a*l},{lazy:!0})},emitBoostStream:()=>{},emitRequestScreenWithHashes:t=>{let{busRef:s,targetId:n}=e();n&&s?.current?.emit?.("browser:request-tiles-hashes",{targetId:n,tileHashes:t})}}});return(0,r.useMemo)(()=>{let e={streaming:u};for(let[t,s]of Object.entries(x))e[t]=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];u&&s(...t)};return e},[x,u])}({busRef:a,connected:i,targetId:eO,profile:m,frameRef:e_,getCanvas:()=>eK.current.canvas?.(),onSecondaryClick:(e,t)=>eK.current.openContextMenuAt?.(e,t),onClipboard:e=>eW.push(e)}),eq=(0,r.useRef)(null),eU=dx({emits:eH,streaming:eH.streaming,storagePrefix:"remoteBrowser",defaultPointerMode:"direct",hoverMove:!0,wheelMultiplier:1,stageLockRef:eq,intercept:(e,t)=>eK.current.intercept?.(e,t),interceptKey:e=>eK.current.interceptKey?.(e)}),eX=eU.canvasRef,eV=eU.canvasContainerRef,[eG,eJ]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=window.matchMedia("(max-width: 767px)"),t=()=>eJ(e.matches);return t(),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]);let eY=!eG&&eO&&v.find(e=>e.openerId===eO&&e.id!==eO)||null,[eZ,eQ]=(0,r.useState)(null);eZ!==eO&&(eQ(eO),C(eF?.url&&!/^about:blank$/.test(eF.url)?eF.url:""),ey([]));let e0=eF?.url&&!/^about:blank$/.test(eF.url)?eF.url:null;(0,r.useEffect)(()=>{e0&&document.activeElement!==eI.current&&C(e0)},[e0]);let e1=(0,r.useRef)(o);(0,r.useEffect)(()=>{e1.current=o},[o]),(0,r.useEffect)(()=>{let e,t,s=a?.current;if(!i||!o||!s?.emit||!eO||eY?.id)return;let n=!1,r=eV.current?.getBoundingClientRect(),l=0,c=eO;return ez.current=eO,e=dW(k),t={targetId:eO,profile:m,width:Math.round($?.width||r?.width||720),height:Math.round($?.height||r?.height||1280),mobile:!!$?.mobile||eG&&!$,scale:e.scale,quality:M.current||e.quality},s.emit("browser:stream.start",t,e=>{!n&&(e?.ok&&e.targetId&&(c=e.targetId,ez.current=e.targetId,e.targetId!==eO&&w(g,e.targetId)),e?.ok&&e.quality&&R(e.quality),e?.ok||n||!(l<3)||setTimeout(()=>{n||T(e=>e+1)},1500*(l+=1)))}),()=>{n=!0;let e=ez.current||c||eO;s.emit("browser:stream.stop",{targetId:e})}},[a,i,o,eO,S,$,m,eG,k,w,g,eY?.id]),(0,r.useEffect)(()=>{if(!o)return;let e=eU.serverDimensionsRef.current;e?.width&&eU.handleCanvasDimensions(e)},[o]);let{frame:e2}=dX({busRef:a,connected:i,targetId:eO,canvasRef:eX,frameRef:e_,applyDimensions:eU.handleCanvasDimensions,onPainted:(e,t)=>{eA.current.bytes+=t,em(!1)}});(0,r.useEffect)(()=>{K&&q(eX.current?.toDataURL("image/jpeg",.9)||null)},[K,eX,e2]),(0,r.useEffect)(()=>{let e=eA.current;e.mark=Date.now();let t=12e6*(k?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,R(e=>Math.max(55,(e??85)-15)))},3e3);return()=>clearInterval(s)},[k,eO]),(0,r.useEffect)(()=>{let e=()=>{document.hidden||!e1.current?a?.current?.emit?.("browser:stream.stop",{targetId:eO}):T(e=>e+1)};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[a,eO]),(0,r.useEffect)(()=>{i&&o&&b("warm")},[i,o,b]);let e5=!eF?.url||/^about:blank$/.test(eF.url||"");(0,r.useEffect)(()=>{if(!i||!(e5||!eO))return;let e=a?.current;e?.emit&&e.emit("getLocalSites",e=>{Array.isArray(e?.sites)&&eE(e.sites.filter(e=>e.port!==x._8))})},[a,i,e5,eO]),(0,r.useEffect)(()=>()=>{eL.current&&clearTimeout(eL.current),eD.current&&clearTimeout(eD.current)},[]),(0,r.useEffect)(()=>{let e=a?.current;if(!e?.on||!eO)return;let t=e=>{e?.targetId===eO&&et(e.cursor||"default")};return e.on?.("browser:cursor",t),()=>{e.off?.("browser:cursor",t),et("default")}},[a,eO]);let e3=(0,r.useCallback)((e,t)=>{let s=eX.current,n=e_.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))}},[eX,e_]),e4=(0,r.useCallback)(e=>e3(e.clientX,e.clientY),[e3]),e6=!!e2,{canvasZoom:e8,canvasPan:e9,fitScale:e7}=eU;(0,r.useLayoutEffect)(()=>{let e=()=>{let e=eX.current,t=eP.current;if(!e||!t)return eM(null);let s=e.getBoundingClientRect(),n=t.getBoundingClientRect();if(!s.width||!s.height)return eM(null);let r={left:s.left-n.left,top:s.top-n.top,width:s.width,height:s.height};eM(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 eP.current&&t.observe(eP.current),eX.current&&t.observe(eX.current),()=>t.disconnect()},[e6,eX,i,e8,e9.x,e9.y,e7]);let te=(0,r.useRef)(!1);(0,r.useEffect)(()=>{te.current=eG},[eG]);let tt=(0,r.useRef)(null),ts=eU.recalculateDisplaySize;(0,r.useEffect)(()=>{let e=eV.current;if(!e)return;let t=null,s=new ResizeObserver(()=>{if(!e1.current)return;let s={w:Math.round(e.clientWidth),h:Math.round(e.clientHeight)};if(!s.w||!s.h)return;let n=eq.current?.kbShrunk,r=te.current?function(e,t){let{w:s,h:n}=t;return e&&s===e.width?n>=e.height-2?{width:s,height:Math.max(n,e.height),lockedH:null,kbShrunk:!1}:n<e.height-8?{width:s,height:e.height,lockedH:e.height,kbShrunk:!0}:e:{width:s,height:n,lockedH:null,kbShrunk:!1}}(eq.current,s):{width:s.w,height:s.h,kbShrunk:!1};eq.current=r,r.kbShrunk!==n&&ts?.();let l={w:s.w,h:r.kbShrunk?r.height:s.h},a=tt.current;tt.current=l,a&&(clearTimeout(t),t=setTimeout(()=>{a&&l&&Math.abs(a.w-l.w)+Math.abs(a.h-l.h)>24&&T(e=>e+1)},300))});return s.observe(e),()=>{clearTimeout(t),s.disconnect()}},[i,eV,ts]);let tn=e=>e?.selector||e?.tag||"element",tr=(0,r.useRef)(!1);(0,r.useEffect)(()=>{!i||!eO||(ev.length||tr.current)&&(tr.current=ev.length>0,b("pick.mark",{targetId:eO,selectors:ev.map(e=>e.selector).filter(Boolean)}))},[ev,i,eO,b]),(0,r.useEffect)(()=>{if(i&&eO)return()=>{tr.current&&(tr.current=!1,b("pick.mark",{targetId:eO,selectors:[]}))}},[i,eO,b]);let tl=async(e,t)=>{let s=eX.current,n=e_.current?.meta,r=s?.getBoundingClientRect(),l=n?.deviceWidth||r?.width||1,a=n?.deviceHeight||r?.height||1,i=r?{x:r.left+e/l*r.width,y:r.top+t/a*r.height}:{x:0,y:0},o=await b("inspect",{targetId:eO,x:e,y:t});en({x:i.x,y:i.y,element:o?.ok?o.element:null})},ta=(0,r.useRef)(null),ti=(0,r.useRef)(0),to=e=>[...e.values()].map(e=>e3(e.x,e.y)),tc=(e,t)=>{if(!A)return!1;if(eG&&!$&&(t.startsWith("touch")||("pointerdown"===t||"pointermove"===t||"pointerup"===t)&&"touch"===e.pointerType||("dblclick"===t||"contextmenu"===t)&&Date.now()-ti.current<600))return((e,t)=>{if("dblclick"===t||"contextmenu"===t||!e_.current||!e.changedTouches)return;ti.current=Date.now();let s=ta.current||(ta.current=new Map);if("touch"===t){for(let t of e.changedTouches)s.set(t.identifier,{x:t.clientX,y:t.clientY});s.size&&eH.emitTouch("start",to(s));return}if("touchmove"===t){for(let t of e.changedTouches){let e=s.get(t.identifier);e&&(e.x=t.clientX,e.y=t.clientY)}s.size&&eH.emitTouch("move",to(s));return}for(let t of e.changedTouches)s.delete(t.identifier);eH.emitTouch(s.size?"move":"end",s.size?to(s):[])})(e,t),!0;if("wheel"===t||"contextmenu"===t)return!1;if(t.startsWith("touch")||"dblclick"===t||e.button>2)return!0;if("pointerdown"===t){if((0,ed.e)(),"pick"===A)return e$.current={sx:e.clientX,sy:e.clientY,moved:!1},!0;let t=e4(e),s={x:e.clientX,y:e.clientY};return b("inspect",{targetId:eO,x:t.x,y:t.y}).then(e=>{e?.ok&&e.element&&(ef("annotate"===A),eg("annotate"===A?s:null),L(e.element))}),!0}if("pointermove"===t){if("pick"!==A)return!0;let t=e$.current;if(t){!t.moved&&Math.abs(e.clientX-t.sx)+Math.abs(e.clientY-t.sy)>8&&(t.moved=!0);let s=eP.current?.getBoundingClientRect();return t.moved&&s&&eN({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)}),!0}if(eD.current)return!0;let s={clientX:e.clientX,clientY:e.clientY};return eD.current=setTimeout(()=>{eD.current=null;let e=e4(s);b("inspect",{targetId:eO,x:e.x,y:e.y}).then(e=>{let t=e?.ok&&e.element?e.element.rect:null;if(!t||!t.width)return eS(null);let s=e_.current?.meta||{},n=s.deviceWidth||0,r=s.deviceHeight||0;eS(n&&r&&t.width*t.height/(n*r)>.6?null:t)})},80),!0}if("pointerup"===t&&"pick"===A&&e$.current){let t=e$.current;if(e$.current=null,eN(null),t.moved){let s=e3(t.sx,t.sy),n=e4(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&&b("pick.rect",{targetId:eO,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&&ey(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=e4(e);b("inspect",{targetId:eO,x:t.x,y:t.y}).then(e=>{var t;e?.ok&&e.element&&(t=e.element)&&ey(e=>{let s=e.findIndex(e=>tn(e)===tn(t));return s>=0?e.filter((e,t)=>t!==s):[...e,t]})})}}return!0},td=e=>(e.metaKey||e.ctrlKey)&&"l"===e.key.toLowerCase()?(e.preventDefault(),eI.current?.focus(),!0):"Escape"===e.key&&A?(I(null),!0):!!A;(0,r.useEffect)(()=>{eK.current={canvas:()=>eX.current,openContextMenuAt:tl,intercept:tc,interceptKey:td}}),(0,r.useEffect)(()=>{let e=()=>{e$.current=null,eN(null)};return window.addEventListener("pointerup",e),()=>window.removeEventListener("pointerup",e)},[]);let tu=async e=>{let t=d4(String(e??N))?.url;if(t&&!eB.current){eB.current=!0;try{(0,ed.e)(),ep({open:!1,items:[],idx:-1}),eo(null),em(!0);let e=nc.getState().tabsByWorkspace[g]||[],s=eO&&e.some(e=>e.id===eO),n=s?null:`boot_${Date.now()}`;if(n){let e=nc.getState();e.setTabs(g,[...e.tabsByWorkspace[g]||[],{id:n,url:t,title:"",booting:!0}]),w(g,n)}let r=s?await b("go",{targetId:eO,url:t}):await b("open",{url:t,workspaceId:g});if(em(!1),n){let e=nc.getState(),t=(e.tabsByWorkspace[g]||[]).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(g,t),e.setActive(g,r?.ok&&r.id||t[t.length-1]?.id||null)}if(r?.ok&&r.id){w(g,r.id),null!=r.windowId&&j(g,r.windowId);let e=nc.getState().tabsByWorkspace[g]||[];e.some(e=>e.id===r.id)||nc.getState().setTabs(g,[...e,{id:r.id,url:r.url,title:""}])}r&&!r.ok?eo({url:t,error:r.error||"Navigation failed"}):r?.ok&&r.error&&eo({url:t,error:r.error}),tm()}finally{eB.current=!1}}},tm=(0,r.useCallback)(async()=>{if(!eO)return;let e=await b("nav",{targetId:eO});e?.ok&&Q({back:!!e.back,forward:!!e.forward})},[b,eO]);(0,r.useEffect)(()=>{let e=setTimeout(tm,0);return()=>clearTimeout(e)},[tm]);let tx=async()=>{eF?.url&&await navigator.clipboard?.writeText?.(eF.url).catch(()=>{})},tp=e=>{let t=e?"h-9 w-9 justify-center rounded-full":"h-8 gap-1.5 px-2 rounded-[6px]",s=e?"bg-white/15 text-white":"bg-brand-500 text-white hover:bg-brand-600",r=e?"text-white/60 hover:text-white":"text-text-muted hover:text-text hover:bg-surface-2";return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onPointerDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),I(e=>"pick"===e?null:"pick"),L(null),eS(null)},disabled:!e2,"aria-label":f("sites.browserPanePickTitle"),className:`${t} shrink-0 flex items-center text-xs font-medium transition-colors disabled:opacity-40 disabled:pointer-events-none ${"pick"===A?s:r}`,title:f("sites.browserPanePickTitle"),children:[(0,n.jsx)(el.We,{size:16}),!e&&(0,n.jsx)("span",{children:f("sites.browserPanePick")})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("button",{onPointerDown:e=>e.preventDefault(),onClick:()=>{(0,ed.e)(),P(e=>!e)},"aria-label":f("sites.browserPaneDeviceTitle"),className:`${t} shrink-0 flex items-center text-xs font-medium transition-colors ${$?s:r}`,title:f("sites.browserPaneDeviceTitle"),children:[(0,n.jsx)(el.wO,{size:16}),!e&&(0,n.jsx)("span",{children:$?`${$.width}\xd7${$.height}`:f("sites.browserPaneDevice")})]}),z&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-10",onClick:()=>P(!1)}),(0,n.jsx)("div",{className:`absolute z-20 flex flex-col p-1 menu-popover pop-in min-w-[170px] ${e?"bottom-12 left-0":"top-10 right-0"}`,children:ur.map(e=>(0,n.jsx)("button",{onPointerDown:e=>e.preventDefault(),onClick:()=>{let t;(0,ed.e)(),t=e.w?{width:e.w,height:e.h,mobile:!!e.mobile}:null,nc.getState().setViewportFor(g,t),e.w?b("viewport",{targetId:eO,width:e.w,height:e.h,mobile:!!e.mobile}):b("viewport",{targetId:eO,reset:!0}),T(e=>e+1),P(!1)},className:`text-left px-2.5 py-1.5 rounded-brand text-xs transition-colors ${(e.w?$?.width===e.w:!$)?"bg-surface-3 text-text font-medium":"text-text-muted hover:bg-surface-2 hover:text-text"}`,children:e.w?e.label:eG?"Natural (fit)":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 sheet-rise",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:()=>{tm(),b("back",{targetId:eO})},disabled:!Z.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:f("sites.goBack"),children:(0,n.jsx)(el.JG,{size:16})}),(0,n.jsx)("button",{onClick:()=>{tm(),b("forward",{targetId:eO})},disabled:!Z.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:f("sites.goForward"),children:(0,n.jsx)(el.c_,{size:16})}),(0,n.jsx)("button",{onClick:e=>{em(!0),tm(),b("reload",{targetId:eO,ignoreCache:e.shiftKey})},onContextMenu:e=>{e.preventDefault(),ea({x:e.clientX,y:e.clientY})},disabled:!eO,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:`${f("editor.reload")} \xb7 shift = hard`,children:ec?(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(),tu()},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:eI,type:"text",inputMode:"url",value:N,onFocus:e=>e.target.select(),onChange:e=>{var t;let s;C(e.target.value),t=e.target.value,eL.current&&clearTimeout(eL.current),(s=t.trim())?eL.current=setTimeout(async()=>{let e=await b("history.search",{q:s}),t=e?.ok&&Array.isArray(e.items)?e.items:[],n=d4(s),r=n?.isSearch?[{isSearch:!0,url:n.url,title:`${f("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}));ep({open:!0,items:[...r,...a],idx:0})},150):ep({open:!1,items:[],idx:-1})},onKeyDown:e=>{if(ex.open&&ex.items.length){if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();let t="ArrowDown"===e.key?1:-1;ep(e=>({...e,idx:(e.idx+t+e.items.length)%e.items.length}));return}if("Escape"===e.key)return void ep({open:!1,items:[],idx:-1});if("Enter"===e.key&&ex.idx>=0){e.preventDefault(),tu(ex.items[ex.idx].url);return}}"Enter"===e.key&&(e.preventDefault(),tu())},onBlur:()=>{setTimeout(()=>ep(e=>({...e,open:!1})),150);let e=eF?.url&&!/^about:blank$/.test(eF.url)?eF.url:"";setTimeout(()=>{e&&eI.current?.value!==e&&C(e)},200)},placeholder:f("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)(d1,{items:ex.open?ex.items:[],activeIdx:ex.idx,onHover:e=>ep(t=>({...t,idx:e})),onPick:e=>{C(e.url),tu(e.url)}})]}),!eG&&(0,n.jsx)("div",{className:"shrink-0 flex items-center gap-1 pl-2 border-l border-border-subtle",children:tp(!1)}),(0,n.jsxs)("button",{onPointerDown:e=>e.preventDefault(),onClick:()=>{Y(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:m,children:[(0,n.jsx)(r3,{name:m,size:16}),(0,n.jsx)("span",{className:"hidden md:inline text-[11px] font-medium max-w-[80px] truncate",children:m})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(dL,{surface:eU,connected:i,clipboard:eW,hasFrame:e6,onRefresh:()=>T(e=>e+1),Controls:us,bottomLayout:!0,controlsProps:{onNavBack:()=>{tm(),b("back",{targetId:eO})},onNavForward:()=>{tm(),b("forward",{targetId:eO})},onNavReload:()=>{em(!0),tm(),b("reload",{targetId:eO})},onFocusAddress:()=>eI.current?.focus()},canvasProps:{cursorOverride:A?"crosshair":"default"===ee?void 0:ee},placeholder:(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-text-muted bg-surface",children:f("sites.browserPaneNotConnected")}),children:(0,n.jsxs)("div",{ref:eP,className:"absolute inset-0 pointer-events-none",children:[eC&&"pick"===A&&e2&&eR&&(s=(t=e2.meta||{}).deviceWidth,l=t.deviceHeight,s&&l&&eC.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:eR.left+eC.x/s*eR.width,top:eR.top+eC.y/l*eR.height,width:eC.width/s*eR.width,height:eC.height/l*eR.height}}):null),ek&&(0,n.jsx)("div",{className:"absolute pointer-events-none border border-brand-400 bg-brand-500/15 rounded-[2px] z-[6]",style:{left:ek.left,top:ek.top,width:ek.width,height:ek.height}}),eG&&(0,n.jsx)("div",{className:"absolute bottom-[calc(var(--safe-bottom)+0.75rem)] left-3 z-10 pointer-events-auto flex items-center gap-0.5 rounded-full bg-black/70 backdrop-blur shadow-[0_2px_10px_rgba(0,0,0,0.4)] p-0.5",children:tp(!0)}),("pick"===A||ev.length>0)&&!ew&&(0,n.jsxs)("div",{className:"absolute bottom-[calc(var(--safe-bottom)+0.75rem)] right-3 z-10 pointer-events-auto flex items-center gap-1.5 rounded-full shadow-xl p-0.5",children:[ev.length>0?(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),ej(!0)},className:"flex items-center gap-1.5 px-2.5 py-1 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:`${ev.length} picked — Send`})]}):(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-black/70 text-white border border-white/10 text-xs font-medium backdrop-blur",children:[(0,n.jsx)(el.We,{size:13,className:"text-white"}),(0,n.jsx)("span",{children:"Pick elements"})]}),"pick"===A&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),I(null)},className:"w-6 h-6 flex items-center justify-center rounded-full bg-black/70 text-white/70 hover:text-white border border-white/10 backdrop-blur transition-colors",title:"Exit pick mode",children:(0,n.jsx)(el.X,{size:12})})]}),i&&(!eO||e5)&&(0,n.jsx)("div",{className:"absolute inset-0 z-[7] pointer-events-auto overflow-y-auto bg-surface",children:(0,n.jsxs)("div",{className:"pt-[10vh] pb-6 px-6 max-w-2xl mx-auto flex flex-col gap-6",children:[(0,n.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center",children:[(0,n.jsx)(el.qz,{size:28,className:"text-brand-500"}),(0,n.jsx)("h2",{className:"text-sm font-semibold text-text",children:f("sites.browserPaneIntroTitle")}),(0,n.jsx)("p",{className:"text-xs text-text-muted max-w-sm",children:f("sites.browserPaneIntroDesc")})]}),(0,n.jsxs)("p",{className:"flex items-start justify-center gap-2 text-xs text-text-muted text-center",children:[(0,n.jsx)(el.We,{size:14,className:"mt-px shrink-0 text-brand-500"}),(0,n.jsx)("span",{children:f("sites.browserPaneTipPick")})]}),eT?.length>0&&(0,n.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium uppercase tracking-wide text-text-muted text-center",children:f("sites.browserPaneLocalSites")}),(0,n.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:eT.map(e=>{let t=e.name&&!/^localhost:\d+$/.test(e.name)?e.name:"localhost";return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),tu(e.url)},className:"flex items-center gap-2.5 p-2 rounded-lg border border-border-subtle bg-surface-2/50 hover:bg-surface-2 hover:border-border transition-colors text-left min-w-0",title:e.url,children:[(0,n.jsx)("span",{className:"w-9 h-9 shrink-0 rounded-md flex items-center justify-center text-white text-[11px] 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:"min-w-0 flex flex-col",children:[(0,n.jsx)("span",{className:"text-xs text-text font-medium truncate",children:t}),(0,n.jsxs)("span",{className:"text-[10px] text-text-muted font-mono",children:[":",e.port]})]})]},e.port)})})]})]})}),i&&eO&&!e2&&!ei&&(0,n.jsxs)("button",{onClick:()=>T(e=>e+1),className:"absolute inset-0 pointer-events-auto 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"})," ",f("sites.browserPaneLoading")]}),ei&&(0,n.jsxs)("div",{className:"absolute inset-0 z-10 pointer-events-auto 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:f("sites.browserPaneLoadError")}),(0,n.jsx)("p",{className:"text-text-muted text-xs font-mono break-all max-w-md",children:ei.url}),(0,n.jsx)("p",{className:"text-text-muted text-[11px]",children:ei.error}),(0,n.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,n.jsx)("button",{onClick:()=>tu(ei.url),className:"px-3 py-1.5 bg-brand-500 hover:bg-brand-600 text-white rounded-brand text-xs font-medium",children:f("sites.browserPaneRetry")}),(0,n.jsx)("button",{onClick:()=>navigator.clipboard?.writeText?.(ei.url),className:"px-3 py-1.5 bg-surface-2 hover:bg-surface-3 text-text rounded-brand text-xs font-medium",children:f("sites.browserPaneCopyAddress")}),(0,n.jsx)("button",{onClick:()=>eo(null),className:"px-3 py-1.5 text-text-muted hover:text-text rounded-brand text-xs",children:f("common.close")})]})]})]})})}),ew&&(0,n.jsx)(d3,{picked:ev,url:eF?.url,invoke:b,targetId:eO,frameMeta:e2?.meta,onRemoveItem:e=>ey(t=>t.filter((t,s)=>s!==e)),onClear:()=>ey([]),onClose:()=>ej(!1)}),D&&(0,n.jsx)(dG,{element:D,autoFocusNote:eh,at:eb,onAddAnnotation:e=>{F(t=>[...t,e])},onClose:()=>L(null)}),O&&(0,n.jsx)(dJ,{annotations:B,onDelete:e=>F(t=>t.filter(t=>t.id!==e)),onClear:()=>F([]),onClose:()=>_(!1)}),K&&(0,n.jsx)(dY,{frameImgSrc:H,onClose:()=>W(!1)}),U&&(0,n.jsx)(dZ,{onEval:e=>b("eval",{targetId:eO,expression:e}),onClose:()=>X(!1)}),V&&(0,n.jsx)(dQ,{invoke:b,profile:m,onSelectProfile:p,targetId:eO,url:eF?.url,initialSection:J,onCopyUrl:tx,onClose:()=>G(!1)}),(0,n.jsx)(d0,{menu:es,items:[...es?.element?.href?[{label:f("sites.browserCtxOpenNewTab"),icon:(0,n.jsx)(el.Gr,{size:13}),onPick:()=>b("open",{url:es.element.href})},{label:f("sites.browserCtxCopyLink"),icon:(0,n.jsx)(el.vv,{size:13}),onPick:()=>navigator.clipboard?.writeText?.(es.element.href)}]:[],{label:f("sites.browserCtxCopyUrl"),icon:(0,n.jsx)(el.qz,{size:13}),onPick:()=>navigator.clipboard?.writeText?.(eF?.url||"")},{label:f("sites.browserCtxInspect"),icon:(0,n.jsx)(el.We,{size:13}),onPick:()=>es?.element&&L(es.element)},{divider:!0},{label:f("sites.goBack"),icon:(0,n.jsx)(el.JG,{size:13}),onPick:()=>b("back",{targetId:eO})},{label:f("sites.goForward"),icon:(0,n.jsx)(el.c_,{size:13}),onPick:()=>b("forward",{targetId:eO})},{label:f("editor.reload"),icon:(0,n.jsx)(el.kt,{size:13}),onPick:()=>b("reload",{targetId:eO})},{divider:!0},{label:f("sessions.deleteTitle")||"Close tab",icon:(0,n.jsx)(el.X,{size:13}),onPick:()=>b("close",{targetId:eO})}],onClose:()=>en(null)}),eY&&(0,n.jsx)(d5,{busRef:a,connected:i,profile:m,targetId:eY.id,url:eY.url,onClose:()=>b("close",{targetId:eY.id})}),(0,n.jsx)(d0,{menu:er,items:[{label:f("editor.reload"),icon:(0,n.jsx)(el.kt,{size:13}),onPick:()=>b("reload",{targetId:eO})},{label:f("sites.browserCtxHardReload"),icon:(0,n.jsx)(el.kt,{size:13}),onPick:()=>b("reload",{targetId:eO,ignoreCache:!0})}],onClose:()=>ea(null)})]})}let ua=(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 ui=s(71049);s(63455);let uo=`${x.fm}login`,uc=`${x.fm}download`,ud=(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 uu(e){let{on:t,onClick:s,title:r,disabled:l}=e;return(0,n.jsx)("button",{onClick:l?void 0:s,disabled:l,title:r,className:"flex-shrink-0 w-[46px] h-[26px] rounded-full transition-all relative",style:{background:t?"var(--accent)":"rgba(140,145,160,0.35)",border:t?"1px solid transparent":"1px solid rgba(140,145,160,0.55)",opacity:l?.5:1,cursor:l?"not-allowed":"pointer"},children:(0,n.jsx)("span",{className:"absolute top-0.5 w-5 h-5 rounded-full transition-all",style:{left:t?"calc(100% - 22px)":"2px",background:"var(--toggle-knob)",boxShadow:"0 2px 6px rgba(0,0,0,0.4)"}})})}let um={screenRecording:{label:"Screen Recording",icon:"screenshot_monitor"},accessibility:{label:"Accessibility",icon:"accessibility_new"}};function ux(e){let{granted:t,label:s,onRequest:r}=e;return(0,n.jsxs)("button",{onClick:t?void 0:r,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:t?"var(--success)":"var(--text-muted)",cursor:t?"default":"pointer"},title:t?"":"Click to grant permission",children:[t&&(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:15},children:"check_circle"}),s,!t&&(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:19,color:"var(--text-subtle)"},children:"toggle_off"})]})}function up(e){let{icon:t,onClick:s,title:r,danger:l,busy:a}=e;return(0,n.jsx)("button",{onClick:a?void 0:s,title:r,disabled:a,className:"glass-btn w-7 h-7 flex items-center justify-center flex-shrink-0",style:{...l?{color:"rgba(255,100,100,0.7)"}:{color:"var(--text-muted)"},...a?{opacity:.6,cursor:"default"}:null},children:(0,n.jsx)("span",{className:`material-symbols-outlined${a?" qr-spin":""}`,style:{fontSize:15},children:t})})}function uh(e){let{desktopEnabled:t,onDesktopToggle:s,permissions:r,onRequestPermission:l}=e,a=Object.entries(um),i=a.every(e=>{let[t]=e;return!!r?.[t]}),o=!i&&!t;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:i?t?"rgba(var(--accent-rgb),0.08)":"var(--row-bg)":"rgba(var(--warn-rgb),0.12)",border:`1px solid ${!i?"rgba(var(--warn-rgb),0.3)":t?"rgba(var(--accent-rgb),0.25)":"var(--border-subtle)"}`,color:i?t?"var(--accent)":"var(--text-muted)":"var(--warn)"},children:(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:18},children:i?"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"}),!i&&(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"})]}),a.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap items-center gap-2 mt-2.5",children:a.map(e=>{let[t,s]=e;return(0,n.jsx)(ux,{granted:!!r?.[t],label:s.label,onRequest:()=>l(t)},t)})})]}),(0,n.jsx)(uu,{on:t,onClick:s,disabled:o,title:o?"Grant permissions":""})]})}function uf(e){let{title:t,count:s,first:r,open:l=!0,onToggle:a,children:i}=e,o=a?"button":"div";return(0,n.jsxs)("div",{className:r?"":"mt-10",children:[(0,n.jsxs)(o,{onClick:a,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:[t,a&&(0,n.jsx)("span",{className:"material-symbols-outlined tracking-normal",style:{fontSize:16,color:"var(--text-muted)",transform:l?"rotate(180deg)":"none",transition:"transform 0.15s ease"},children:"expand_more"}),null!=s&&(0,n.jsx)("span",{className:"ml-auto tracking-normal",style:{color:"var(--text-muted)"},children:s})]}),l&&i]})}let ub={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 ug(e){let{version:t,isUpdating:s=!1}=e,[l,a]=(0,r.useState)(s?"updating":"idle"),[i,o]=(0,r.useState)(0),[c,d]=(0,r.useState)(s);if(c!==s&&(d(s),s&&a(e=>"restarting"===e||"ready"===e?e:"updating")),(0,r.useEffect)(()=>{let e;if("updating"!==l&&"restarting"!==l)return;let t=Date.now(),s=!1,n=setInterval(()=>o(Math.floor((Date.now()-t)/1e3)),1e3),r=setTimeout(()=>{e=setInterval(async()=>{if(Date.now()-t>9e4){a("timeout"),clearInterval(e);return}try{if(!(await fetch("/api/ui/state",{cache:"no-store"})).ok)throw Error();s&&(a("ready"),clearInterval(e),setTimeout(()=>window.location.reload(),600))}catch{s=!0,a("restarting")}},2e3)},3e3);return()=>{clearInterval(n),clearInterval(e),clearTimeout(r)}},[l]),!t&&!s&&"idle"===l)return null;let u=ub[l],m="updating"===l||"restarting"===l||"ready"===l,x="ready"===l?100:Math.min(1e3*i/9e4*100,95);return m?(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 ${u.spin?"qr-spin":""}`,style:{color:"var(--brand-400)"},children:u.icon}),(0,n.jsx)("div",{className:"text-sm font-semibold mt-3",style:{color:"var(--text-main)"},children:u.text(t,i)}),(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:[i,"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 ${u.spin?"qr-spin":""}`,style:{color:"var(--brand-400)"},children:u.icon}),(0,n.jsx)("span",{className:"text-xs flex-1",style:{color:"var(--brand-400)"},children:u.text(t,i)}),"idle"===l&&(0,n.jsx)("button",{onClick:()=>a("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"===l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{a("updating"),ud("/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:()=>a("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"===l&&(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 uv={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 uy(e){let{client:t,onRemove:s,onApprove:r,onLabel:l}=e,a=`${t.deviceId.slice(0,8)}...`,i=t.label||a,o=uv[t.status]||uv.offline,c="pending"===t.status,d="online"===t.status?`${t.ip?t.ip+" \xb7 ":""}connected ${t.connectedAt?new Date(t.connectedAt).toLocaleTimeString(void 0,{hour12:!1}):""}`:c?"Waiting for approval":t.approvedAt?`Approved ${new Date(t.approvedAt).toLocaleDateString()}`:"Offline";return(0,n.jsxs)("div",{className:`row-hover flex items-center gap-4 py-3 px-3 -mx-3 rounded-xl ${c?"border border-dashed":""}`,style:c?{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(i||"")?"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:i}),(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:o.bg,color:o.color},children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{background:"currentColor"}}),o.label]}),!c&&(0,n.jsx)("button",{onClick:()=>l?.(t),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 ${t.ip?"font-mono":""}`,style:{color:"var(--text-muted)"},children:d})]}),c?(0,n.jsx)("button",{onClick:()=>r?.(t),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:()=>s(t),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"===t.status?"Disconnect":"Remove"})]})}let uw=["Preparing","Connecting","Tunneling","Verifying","Ready"];function uj(e){let{step:t,stepDesc:s}=e,r=Math.min(Math.max(t-1,0),uw.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:uw.map((e,t)=>{let s=t<r,l=t===r;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:s||l?"var(--brand-500)":"var(--row-hover)",border:s||l?"none":"1px solid var(--border)",boxShadow:l?"0 0 8px rgba(var(--brand-rgb),0.7)":void 0}}),t<uw.length-1&&(0,n.jsx)("span",{className:"w-5 h-px",style:{background:s?"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:[uw[r],s?` — ${s}`:""]})]})}function uk(e){let t,l,{qrUrl:a,oneTimeKey:i,oneTimeKeyExpiresAt:o,permanentKey:c,onGenerateOneTimeKey:d,onRegenerateKey:u}=e,m=(0,r.useRef)(null),[x,p]=(0,r.useState)(()=>Date.now()),[h,f]=(0,r.useState)(null),[b,g]=(0,r.useState)(null),[v,y]=(0,r.useState)(null),w=null!=o?o-x:null,j=null!==w&&w<=0;(0,r.useEffect)(()=>{if(!o)return;let e=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(e)},[o]),(0,r.useEffect)(()=>{if(!a||j||!m.current)return;let e=!1;return s.e(1561).then(s.t.bind(s,61561,19)).then(t=>{let{default:s}=t;return!e&&s.toCanvas(m.current,a,{width:200,margin:1,color:{dark:"#0f1923",light:"#ffffff"}})}).catch(()=>{}),()=>{e=!0}},[a,j]);let[k,N]=(0,r.useState)(i),[C,S]=(0,r.useState)(c);k!==i&&(N(i),y(e=>"oneTime"===e?null:e)),C!==c&&(S(c),y(e=>"permanent"===e?null:e)),(0,r.useEffect)(()=>{if(!v)return;let e=setTimeout(()=>y(null),15e3);return()=>clearTimeout(e)},[v]);let T=(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"===b,onClose:()=>g(null),onConfirm:()=>{g(null),y("oneTime"),d?.()},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"===b,onClose:()=>g(null),onConfirm:()=>{g(null),y("permanent"),u?.()},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:a&&!j?(0,n.jsx)("canvas",{ref:m}):(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:uo,target:"_blank",rel:"noopener noreferrer",onClick:e=>aO(e,uo),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:uo.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:i&&!j?"var(--accent)":"var(--border)"},children:i&&!j?i:"• • • • • •"}),null!==w&&(0,n.jsx)("span",{className:`text-xs font-mono flex-shrink-0 ${w<=0?"text-red-400":""}`,style:w>0?{color:"var(--text-muted)"}:{},children:w<=0?"Expired":(l=Math.floor((t=Math.floor(w/1e3))/60),`${String(l).padStart(2,"0")}:${String(t%60).padStart(2,"0")}`)}),i&&!j&&(0,n.jsx)(up,{icon:"oneTime"===h?"check":"content_copy",onClick:()=>T(i,"oneTime"),title:"Copy one-time key"}),(0,n.jsx)(up,{icon:"refresh",onClick:()=>g("oneTime"),title:"New one-time key",busy:"oneTime"===v})]})]}),(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:c||"— not set —"}),c&&(0,n.jsx)(up,{icon:"permanent"===h?"check":"content_copy",onClick:()=>T(c,"permanent"),title:"Copy permanent key"}),(0,n.jsx)(up,{icon:"autorenew",onClick:()=>g("regen"),title:"Regenerate permanent key",danger:!0,busy:"permanent"===v})]})]})]})]})}function uN(e){let{icon:t,iconClass:s,title:r,sub:l,href:a}=e;return(0,n.jsxs)("a",{href:a,target:"_blank",rel:"noopener noreferrer",onClick:e=>aO(e,a),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 ${s}`,children:"string"==typeof t?(0,n.jsx)("span",{className:"material-symbols-outlined",style:{fontSize:18},children:t}):t}),(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:r}),l&&(0,n.jsx)("p",{className:"text-[11px] truncate",style:{color:"var(--text-muted)"},children:l})]}),(0,n.jsx)("span",{className:"material-symbols-outlined flex-shrink-0",style:{fontSize:15,color:"var(--text-subtle)"},children:"open_in_new"})]})}function uC(){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 uS(){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 uT(){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),[x,p]=(0,r.useState)(""),[h,f]=(0,r.useState)(!1),[b,g]=(0,r.useState)([]),[v,y]=(0,r.useState)([]),[w,j]=(0,r.useState)([]),k=ua(e=>e.pendingDevice);ua(e=>e.bump);let[N,C]=(0,r.useState)(!1),[S,T]=(0,r.useState)(!0),[E,R]=(0,r.useState)(!1),[M,$]=(0,r.useState)(null),[z,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,m.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?f(!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,ud("/api/key/one-time"))},[e.permanentKey,e.oneTimeKey,e.qrUrl,e.pairingUsed,e.step]);let O=async()=>{let e=!o;c(e),await ud("/api/desktop/toggle",{enabled:e})},_=async()=>{let e=await ud("/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}))},K=async()=>{let e=await ud("/api/key/regenerate");if(!e?.ok)return;let s=await e.json().catch(()=>null);s?.permanentKey&&t(e=>({...e,permanentKey:s.permanentKey}))},W=async e=>{let t="pending"===e.status?"/api/device/clear-rejected":"/api/device/remove";await ud(t,{deviceId:e.deviceId}),L()},H=async()=>{let e=!N;C(e);let t=await ud("/api/device/auto-approve",{enabled:e}),s=await t?.json().catch(()=>null);s&&"boolean"==typeof s.enabled&&C(s.enabled)},q=async e=>{await ud("/api/device/approve-rejected",{deviceId:e}),L()},U=async(e,t)=>{await ud("/api/device/label",{deviceId:e,label:t}),L()},X=async()=>{let e=!S;T(e);let t=await ud("/api/remote/enabled",{enabled:e}),s=await t?.json().catch(()=>null);"boolean"==typeof s?.enabled&&T(s.enabled)};if(!(0,m.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},G=a?.signaling==="connected"?{color:"var(--success)",label:`rtc ${a.rtcPeers||0}`}:{color:"var(--danger)",label:"rtc off"},J=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],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=J.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)(uj,{step:e.step,stepDesc:e.stepDesc}),(0,n.jsx)(uk,{qrUrl:e.qrUrl,oneTimeKey:e.oneTimeKey,oneTimeKeyExpiresAt:e.oneTimeKeyExpiresAt,permanentKey:e.permanentKey,onGenerateOneTimeKey:_,onRegenerateKey:K})]}):(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:()=>ud("/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:G.color}}),(0,n.jsx)("span",{className:"font-mono text-[11px] truncate",style:{color:"var(--text-muted)"},children:G.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)(uu,{on:S,onClick:()=>S?R(!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)(ug,{version:x,isUpdating:h}),(0,n.jsx)(uf,{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)(uN,{icon:(0,n.jsx)(uC,{}),iconClass:"ad-tile-apple",title:"iPhone & iPad",sub:"App Store",href:ui.od}),(0,n.jsx)(uN,{icon:(0,n.jsx)(uS,{}),iconClass:"ad-tile-play",title:"Android",sub:"Google Play",href:ui.JN}),(0,n.jsx)(uN,{icon:"computer",iconClass:"ad-tile-pc",title:"PC & Mac",sub:"All downloads",href:uc}),(0,n.jsx)(uN,{icon:"language",iconClass:"ad-tile-web",title:"Web",sub:"9remote.cc",href:uo})]})}),(0,n.jsx)(uf,{title:"Services",children:(0,n.jsx)(uh,{desktopEnabled:o,onDesktopToggle:O,permissions:s,onRequestPermission:e=>ud("/api/permissions/request",{type:e})})}),(0,n.jsxs)(uf,{title:"Clients",count:J.length>0?`${Y}/${J.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)(uu,{on:N,onClick:H,title:N?"Disable auto-approve":"Enable auto-approve"})]}),0===J.length?(0,n.jsx)("p",{className:"text-xs text-center py-4",style:{color:"var(--text-muted)"},children:"No clients yet"}):J.map(e=>(0,n.jsx)(uy,{client:e,onRemove:$,onApprove:e=>q(e.deviceId),onLabel:e=>P({...e,draft:e.label||""})},e.deviceId))]})]})]}),(0,n.jsx)(ec.A,{isOpen:E,onClose:()=>R(!1),onConfirm:()=>{R(!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:!!M,onClose:()=>$(null),onConfirm:()=>{W(M),$(null)},title:"Remove device?",message:M?"online"===M.status?`Disconnect and remove device ${M.deviceId.slice(0,8)}...? The client will be disconnected and need approval again next time.`:"pending"===M.status?`Remove pending device ${M.deviceId.slice(0,8)}...? It will need a fresh approval request to connect again.`:`Remove device ${M.deviceId.slice(0,8)}...? It will need approval again next time.`:"",confirmText:M?.status==="online"?"Disconnect & Remove":"Remove"}),z&&(0,n.jsx)(nk,{title:"Rename device",placeholder:`Name for device ${z.deviceId.slice(0,8)}...`,value:z.draft,onChange:e=>P(t=>t?{...t,draft:e}:t),onSubmit:()=>{U(z.deviceId,(z.draft||"").trim()),P(null)},onClose:()=>P(null)})]})}function uE(e){let{files:t,loading:s,onFileClick:r,onFolderClick:l,onMoreClick:a,selectedPath:i,gitStatusMap:o={},workspacePath:c}=e,{t:d}=(0,eu.s)();return s?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-text-muted",children:d("common.loading")})}):0===t.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-text-muted",children:d("files.emptyFolder")})}):(0,n.jsx)("div",{children:t.map((e,t)=>{var s;let u=o[s=e.path,!c?s:s.replace(c+"/","")],m="folder-changed"===u?"text-yellow-400":_.vs[u]||"";return(0,n.jsxs)("div",{className:`w-full px-4 py-1.5 flex items-center gap-2.5 hover:bg-surface-2 transition ${i===e.path?"bg-surface-2":""}`,children:[(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),"folder"===e.type?l(e):r(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:i1(e,18)}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:`truncate text-sm ${m||"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})]})]}),a&&(0,n.jsx)("button",{onClick:t=>{let s;(0,ed.e)(),t.stopPropagation(),s=t.currentTarget.getBoundingClientRect(),a?.(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:d("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)(),l(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 uR(e){let{workspace:t,initialPath:s,fileBus:l,onBack:a,onOpenFile:i,onOpenGit:o,onSetWorkspace:c,onSwitchWorkspace:d,onPathChange:u,isBrowsing:m=!1,hideSwitchWorkspace:x=!1,scope:p=""}=e,{t:h}=(0,eu.s)(),[f,b]=(0,r.useState)(s||t),[g,v]=(0,r.useState)([]),[y,w]=(0,r.useState)(!0),[j,k]=(0,r.useState)(""),[N,C]=(0,r.useState)(null),[S,T]=(0,r.useState)(!1),[E,R]=(0,r.useState)("file"),[M,$]=(0,r.useState)(""),[z,P]=(0,r.useState)({isOpen:!1}),[A,I]=(0,r.useState)(null),[D,L]=(0,r.useState)(!1),[B,F]=(0,r.useState)({}),[O,K]=(0,r.useState)(!1),[W,H]=(0,r.useState)(""),[q,U]=(0,r.useState)([]),[X,V]=(0,r.useState)(!1),G=(0,r.useRef)(null),[J]=(0,r.useState)(()=>window.innerWidth>=eg.jK),Y=(0,r.useCallback)(async e=>{if(m){L(!1),F({});return}let t=await i_(l,e);L(t.hasGit);let s=t.map;F(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,s)?s:e)},[l,m]),Z=(0,r.useCallback)(async e=>{w(!0),k("");let t=await l.getFiles(e,!0);if(t.success){let e=t.files;m&&(e=t.files.filter(e=>"folder"===e.type)),v(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}),b(t.currentPath)}else k(t.error),v([]);w(!1)},[l,m]),{transfer:Q,dragOver:ee,conflict:et,downloadState:es,startUpload:en,handleDrop:er,handleDragOver:ea,handleDragLeave:ei,handleDownload:eo,resolveConflict:em}=function(e){let{fileBus:t,currentPath:s,isBrowsing:n,onDone:l,onError:a}=e,[i,o]=(0,r.useState)(null),[c,d]=(0,r.useState)(!1),[u,m]=(0,r.useState)(null),[x,p]=(0,r.useState)(null),h=(0,r.useRef)(0),f=(0,r.useCallback)(async e=>{if(!e.length||!t.uploadFiles)return;let n=++h.current;o({total:e.length,done:0,current:e[0]?.file?.name||"",ratio:0}),await t.uploadFiles(s,e,{onConflict:(e,t)=>{let{file:s}=e;return new Promise(e=>{m({name:t||s.name,resolve:e})})},onProgress:(e,t)=>{n===h.current&&o(s=>s?{...s,current:e.name,ratio:t}:s)},onFileDone:e=>{n===h.current&&o(e=>e?{...e,done:e.done+1}:e)}}),n===h.current&&o(null),l?.(s)},[t,s,l]),b=(0,r.useCallback)(async e=>{if(e.preventDefault(),d(!1),n)return;let t=await i9(e.dataTransfer);t.length&&((0,ed.e)(),f(t))},[n,f]),g=(0,r.useCallback)(e=>{e.preventDefault(),n||d(!0)},[n]),v=(0,r.useCallback)(e=>{e.preventDefault(),d(!1)},[]);(0,r.useEffect)(()=>{if(n)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)},[n,f]);let y=(0,r.useRef)(0),w=(0,r.useCallback)(e=>{if(!t.downloadFile)return;let s=++y.current;p({name:e.name,ratio:0}),t.downloadFile(e.path,{onSave:(t,n)=>{let r=document.createElement("a");r.href=URL.createObjectURL(t),r.download=n?.fileName||e.name,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(r.href),s===y.current&&p(null)},onProgress:e=>{s===y.current&&p(t=>t?{...t,ratio:e}:t)},onError:e=>{a?.(e.message||"Download failed"),s===y.current&&p(null)}})},[t,a]),j=(0,r.useCallback)(e=>{u?.resolve(e),m(null)},[u]);return{transfer:i,dragOver:c,conflict:u,downloadState:x,startUpload:f,handleDrop:b,handleDragOver:g,handleDragLeave:v,handleDownload:w,resolveConflict:j}}({fileBus:l,currentPath:f,isBrowsing:m,onDone:Z,onError:k}),ex=(0,r.useCallback)(e=>{if(H(e),G.current&&clearTimeout(G.current),!e||e.length<2){U([]),V(!1);return}V(!0),G.current=setTimeout(async()=>{let s=await l.searchFiles(t,e);s.success&&U(s.files),V(!1)},300)},[t,l]),ep=(0,r.useCallback)(()=>{K(!1),H(""),U([])},[]);(0,r.useEffect)(()=>{Z(s||t),m||Y(t)},[t,s,m]),(0,r.useEffect)(()=>()=>{G.current&&clearTimeout(G.current)},[]),(0,r.useEffect)(()=>{!m&&u&&u(f)},[f,m,u]);let eh=e=>{Z(e.path)},eb=()=>C(null),ev=async()=>{if(!A||!A.newName.trim())return;let e=f+"/"+A.newName.trim(),t=await l.renameItem(A.file.path,e);t.success?Z(f):k(t.error),I(null)},ey=async()=>{if(!M.trim())return;let e=f+"/"+M.trim(),t=await l.createItem(e,E);t.success?(Z(f),T(!1),$("")):k(t.error)},ew=(0,r.useRef)(null),ej=(0,r.useRef)(null),ek=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}));T(!1),en(s)},eN=async e=>{if(!t||!l||!e?.path)return;eb();let s=e.path.startsWith(t)?e.path.slice(t.length).replace(/^\/+/,""):e.path,n=await oo(l,t,s,"folder"===e.type);n?.success&&(Y(t),window.dispatchEvent(new CustomEvent(_.GW)))},eC=f===t,eS="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)(),a()},className:eS,title:h("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\/[^/]+/,"~")})}),m&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),ef(f,p),c(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:h("files.setAsWorkspaceTitle"),children:h("files.setWorkspace")}),!m&&d&&!x&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d()},className:eS,title:h("files.switchWorkspace"),children:(0,n.jsx)(el.Bm,{className:"text-brand-500",size:20})}),!m&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),K(!0)},className:eS,title:h("files.searchFiles"),children:(0,n.jsx)(el.vj,{className:"text-brand-500",size:20})}),!m&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),o()},disabled:!D,className:`p-2 rounded-brand transition-all duration-150 ease-out active:scale-[0.96] ${D?"bg-surface-2 hover:bg-surface-3 text-text":"bg-surface-2/30 text-text-muted cursor-not-allowed"}`,title:D?h("git.title"):h("files.noGitRepo"),children:(0,n.jsx)(el.Zr,{className:D?"text-brand-500":"text-text-muted",size:20})})]}),O&&(0,n.jsx)(or,{query:W,loading:X,onChange:ex,onClose:ep}),j&&(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:j}),Q&&(0,n.jsx)(on,{label:`${h("files.copying")} ${Q.done+1}/${Q.total}: ${Q.current}`,ratio:Q.ratio}),es&&(0,n.jsx)(on,{label:`${h("files.downloading")}: ${es.name}`,ratio:es.ratio}),O&&W.length>=2?(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-auto",children:X?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:h("files.searching")}):0===q.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:h("files.noFilesFound")}):(0,n.jsx)("div",{children:q.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),i(e.path),ep()},className:"w-full px-4 py-3 flex items-center gap-3 hover:bg-surface transition-colors text-left",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:"binary"===e.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:e.name,children:e.name}),(0,n.jsx)("div",{className:"text-text-muted text-xs truncate",title:e.path,children:e.path.replace(t,"").replace(/^\//,"")})]}),e.sizeFormatted&&(0,n.jsx)("span",{className:"text-text-muted text-xs flex-shrink-0",children:e.sizeFormatted})]},e.path))})}):(0,n.jsxs)(n.Fragment,{children:["/"!==f&&!eC&&!O&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),Z(f.split("/").slice(0,-1).join("/")||"/")},className:"w-full px-4 py-3 flex items-center gap-3 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 ${!m?"pb-20":""} ${ee?"bg-brand-500/5 ring-2 ring-inset ring-brand-500/40":""}`,onDrop:er,onDragOver:ea,onDragLeave:ei,children:m?(0,n.jsx)("div",{className:"p-4",children:y?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:h("common.loading")}):0===g.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:h("files.emptyFolder")}):(0,n.jsx)("div",{className:"grid grid-cols-2 gap-3",children:g.map(e=>(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eh(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)(uE,{files:g,loading:y,onFileClick:e=>{if(!m){if("binary"===e.type){k(h("files.cannotOpenBinary")),setTimeout(()=>k(""),3e3);return}i?.(e.path,f)}},onFolderClick:eh,onMoreClick:(e,t)=>{C({file:e,x:t.x,y:t.y})},gitStatusMap:B,workspacePath:t})})]}),!m&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),T(!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})}),N&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 z-40",onClick:eb}),(0,n.jsxs)("div",{className:"fixed z-50 menu-popover overflow-hidden min-w-[140px] pop-in",style:{right:16,top:Math.min(N.y,window.innerHeight-160)},children:[(0,n.jsxs)("button",{onClick:()=>{var e;(0,ed.e)(),e=N.file,eb(),I({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}),h("files.rename")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),navigator.clipboard?.writeText(N.file.path).catch(()=>{}),eb()},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}),h("files.copyPath")]}),J&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eb(),eo(N.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}),h("files.download")]}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),eN(N.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}),h("git.addToGitignore",{defaultValue:"Add to .gitignore"})]}),(0,n.jsxs)("button",{onClick:()=>{var e;(0,ed.e)(),e=N.file,eb(),P({isOpen:!0,title:h("files.deleteConfirmTitle"),message:h("files.deleteConfirmMessage",{name:e.name}),onConfirm:async()=>{let t=await l.deleteItem(e.path);t.success?Z(f):k(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}),h("files.delete")]})]})]}),S&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ol,{type:E,name:M,onTypeChange:R,onNameChange:$,onSubmit:ey,onPickFile:()=>ew.current?.click(),onPickFolder:()=>ej.current?.click(),onClose:()=>T(!1)}),(0,n.jsx)("input",{ref:ew,type:"file",multiple:!0,className:"hidden",onChange:ek}),(0,n.jsx)("input",{ref:ej,type:"file",className:"hidden",webkitdirectory:"",onChange:ek})]}),A&&(0,n.jsx)(oa,{value:A.newName,onChange:e=>I({...A,newName:e}),onSubmit:ev,onClose:()=>I(null)}),(0,n.jsx)(ec.A,{isOpen:z.isOpen,onClose:()=>P({isOpen:!1}),onConfirm:z.onConfirm,title:z.title,message:z.message}),et&&(0,n.jsx)(oi,{name:et.name,onResolve:em})]})}let uM=[{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"}],u$=[{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 uz(e){let{viewRef:t}=e,{t:s}=(0,eu.s)(),[l,a]=(0,r.useState)(!1),[i,o]=(0,r.useState)(!1),[c,d]=(0,r.useState)(!1),[u,m]=(0,r.useState)(""),x=(0,r.useRef)(null),p=e=>{let s=t.current;if(!s)return;let{from:n,to:r}=s.state.selection.main;s.dispatch({changes:{from:n,to:r,insert:e},selection:{anchor:n+e.length}}),s.focus()},h=function(e){let{ctrl:s=!1,alt:n=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.current;r&&(r.contentDOM.dispatchEvent(new KeyboardEvent("keydown",{key:e,code:1===e.length?`Key${e.toUpperCase()}`:e,ctrlKey:s||l,altKey:n||i,metaKey:s||l,bubbles:!0,cancelable:!0})),r.focus(),a(!1),o(!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 ${c?"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:u,onChange:e=>m(e.target.value),placeholder:s("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)(),u.trim()&&(p(u),m("")),d(!1)},disabled:!u.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:s("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:uM.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),"ctrl"===e.modifier?(a(e=>!e),o(!1)):"alt"===e.modifier?(o(e=>!e),a(!1)):h(e.key)},className:f("ctrl"===e.modifier&&l||"alt"===e.modifier&&i),children:e.label},e.label))}),(0,n.jsx)("div",{className:"flex gap-1",children:u$.map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),e.toggleTextInput?(d(e=>!e),c||setTimeout(()=>x.current?.focus(),350)):e.text?p(e.text):e.key&&h(e.key,{ctrl:e.ctrl,alt:e.alt})},className:f(e.toggleTextInput&&c),children:e.label},e.label))})]})]})}function uP(e){let{filePath:t,fileBus:s,onBack:l,line:a,column:i,workspace:o,diffStatus:c,preview:d=!1}=e,{t:u}=(0,eu.s)(),m=oF(t),x=!!c,p=t.split("/").pop(),h=o_({filePath:x||m?"":t,fileBus:s}),f=oK({dirty:!x&&!m&&h.dirty,onSave:h.save}),b=(0,r.useRef)(null),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(null),[N,C]=(0,r.useState)(!1),S=x||m?null:(0,_.YO)(t),T="html"===S,[E,R]=(0,r.useState)(d&&!!S),[M,$]=(0,r.useState)(""),[z,P]=(0,r.useState)(0),[A,I]=(0,r.useState)(t),[D,L]=(0,r.useState)(!1);A!==t&&(I(t),R(d&&!!S),$("")),h.justSaved!==D&&(L(h.justSaved),h.justSaved&&P(e=>e+1));let B=(0,r.useCallback)(()=>{ca(s,t).then(e=>{e.ok||$(e.error||u("editor.previewFailed"))})},[s,t,u]);(0,r.useEffect)(()=>{if(!T||!d)return;let e=!1;return ca(s,t).then(t=>{e||t.ok||$(t.error||u("editor.previewFailed"))}),()=>{e=!0}},[T,d,s,t]);let F=(0,r.useCallback)((e,t)=>{b.current=t},[]);(0,r.useEffect)(()=>{if(x||!o||!t)return;let e=!1;return s.gitFileStatus(o,t).then(t=>{e||w(t?.success&&t.status?t:null)}),()=>{e=!0}},[t,o,s]);let O=async()=>{if(!y||!o)return;if((0,_.u)(t))return void k("image");C(!0);let e=await s.gitDiff(o,y.file,y.status);C(!1),e?.success&&k(e.diff||"")};(0,r.useEffect)(()=>{if(!c||!o||!t)return;let e=!1,n=setTimeout(async()=>{if((0,_.u)(t))return void k("image");C(!0);let n=await s.gitDiff(o,t,c);!e&&(C(!1),n?.success&&k(n.diff||""))},0);return()=>{e=!0,clearTimeout(n)}},[c,o,t,s]);let K=async()=>{let e=b.current?.state.doc.toString();if(null!=e)try{await navigator.clipboard.writeText(e),v(!0),setTimeout(()=>v(!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(l)},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:p}),h.dirty&&(0,n.jsx)("span",{className:"w-2 h-2 bg-yellow-400 rounded-full flex-shrink-0",title:u("editor.unsaved")}),h.justSaved&&(0,n.jsx)("span",{className:"text-green-400 text-xs flex-shrink-0",children:u("editor.saved")}),g&&(0,n.jsx)("span",{className:"text-green-400 text-xs flex-shrink-0",children:u("editor.copied",{defaultValue:"Copied"})})]}),y&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),O()},disabled:N,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:u("editor.gitDiff"),children:N?(0,n.jsx)(el.kr,{className:"animate-spin",size:16}):(0,n.jsx)(el.Zr,{size:16})}),S&&(T?(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),B()},title:u("editor.previewInBrowser"),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.qz,{size:16})}):(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),R(e=>!e)},title:E?u("editor.editCode"):u("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:E?(0,n.jsx)(el.GD,{size:16}):(0,n.jsx)(el.kU,{size:16})})),!m&&!x&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),K()},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:u("editor.copy",{defaultValue:"Copy"}),children:(0,n.jsx)(el.QR,{size:16})}),!m&&!x&&(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),h.save()},disabled:!h.dirty||h.saving,className:`px-3 py-2 rounded-brand transition-all duration-150 ease-out flex items-center gap-1 ${h.dirty&&!h.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:[h.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:u("editor.save")})]})]}),h.error&&!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 break-words",children:h.error}),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 break-words",children:M}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:x?(0,_.u)(t)?(0,n.jsx)(cn,{filePath:t,status:c,workspace:o,fileBus:s}):(0,n.jsx)("div",{className:"h-full overflow-auto p-2",children:N?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted",children:u("common.loading")}):j?(0,n.jsx)(ct,{diff:j}):(0,n.jsx)("div",{className:"h-32 flex items-center justify-center text-text-muted text-sm",children:u("git.noChanges")})}):m?(0,n.jsx)(oO,{filePath:t,fileBus:s}):E&&S&&!T?(0,n.jsx)(o9,{kind:S,filePath:t,fileBus:s,content:h.content,reloadKey:z}):h.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted",children:u("common.loading")}):(0,n.jsx)(o5,{filePath:t,content:h.content,onTextChanged:h.onTextChanged,onRegisterView:(e,t)=>{h.register(e),F(e,t)},onSave:h.save,line:a,column:i})}),!x&&null!==j&&(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:u("editor.gitDiff")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),k(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,_.u)(t)?(0,n.jsx)(cn,{filePath:t,status:y?.status,workspace:o,fileBus:s}):j?(0,n.jsx)(ct,{diff:j}):(0,n.jsx)("div",{className:"h-32 flex items-center justify-center text-text-muted text-sm",children:u("git.noChanges")})})]}),!m&&!x&&!h.loading&&!E&&(0,n.jsx)(uz,{viewRef:b}),(0,n.jsx)(oW,{isOpen:f.asking,fileName:p,onSave:f.saveThenLeave,onDiscard:f.discardAndLeave,onCancel:f.cancel})]})}function uA(e){let{workspace:t,fileBus:s,branch:l,changedCount:a,onDone:i,onClose:o}=e,{t:c}=(0,eu.s)(),[d,u]=(0,r.useState)(""),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=e=>{"Escape"!==e.key||m||o()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,m]);let f=d.trim().length>0&&!m,b=async()=>{let e=await s.gitAdd(t);if(!e.success)return{ok:!1,text:e.error||c("git.stageFailed")};let n=await s.gitCommit(t,d.trim());return n.success?{ok:!0,text:ob(c,n.output)}:{ok:!1,text:n.output||n.error||c("git.commitFailed")}},g=async()=>{if(!f)return;(0,ed.e)(),x(!0),h(null);let e=await b();x(!1),h(e),e.ok&&(u(""),i?.())},v=async()=>{if(m)return;(0,ed.e)(),x(!0),h(null);let e=await s.gitPush(t);x(!1),h({ok:e.success,text:e.success?og(c,e.output):e.output||e.error||c("git.pushFailed")}),e.success&&i?.()},y=async()=>{if(!f)return;(0,ed.e)(),x(!0),h(null);let e=await b();if(!e.ok){x(!1),h(e);return}u("");let n=await s.gitPush(t);x(!1),h({ok:n.success,text:n.success?og(c,n.output):n.output||n.error||c("git.pushFailed")}),i?.()};return"u"<typeof document?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[70]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:()=>!m&&o()}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full my-auto flex flex-col pop-in",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"}),c("git.title"),l?` \xb7 ${l}`:""]}),(0,n.jsx)("button",{onClick:()=>!m&&o(),className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":c("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:d,onChange:e=>u(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),y())},rows:2,placeholder:c("git.commitPlaceholder"),disabled:m,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:c("git.stageAllNote",{count:a})})]}),(0,n.jsxs)("button",{onClick:y,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:[m?(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:c("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:g,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}),c("git.commit")]}),(0,n.jsxs)("button",{onClick:v,disabled:m,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}),c("git.push")]})]}),p&&(0,n.jsx)("pre",{className:`text-xs whitespace-pre-wrap break-words px-3 py-2 rounded-brand max-h-32 overflow-y-auto ${p.ok?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:p.text})]})]})]}),document.body)}function uI(e){let{workspace:t,fileBus:s,onBack:l,onOpenFile:a}=e,{t:i}=(0,eu.s)(),[o,c]=(0,r.useState)("status"),[d,u]=(0,r.useState)(!0),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(""),[f,b]=(0,r.useState)([]),[g,v]=(0,r.useState)(null),[y,w]=(0,r.useState)(null),[j,k]=(0,r.useState)(""),[N,C]=(0,r.useState)(!1),[S,T]=(0,r.useState)({isOpen:!1}),[E,R]=(0,r.useState)(""),[M,$]=(0,r.useState)(null),[z,P]=(0,r.useState)(null),[A,I]=(0,r.useState)(!1),D=(0,r.useCallback)(async()=>{u(!0),h("");let e=await s.gitStatus(t);e.success?b(e.files):h(e.error),s.gitBranch(t).then(e=>{e?.success&&(R(e.branch),$(e.ahead??null),P(e.behind??null))}),u(!1)},[t,s]),L=(0,r.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(v(e),w(n),e&&(0,_.u)(e)){k("image"),C(!0),x(!1);return}x(!0),h("");let r=await s.gitDiff(t,e,n);r.success?(k(r.diff),C(!0)):h(r.error),x(!1)},[t,s]);(0,r.useEffect)(()=>{D()},[D]);let B=(0,r.useCallback)(()=>{if(c("diff"),!N&&f.length>0){let e=f[0];L(e.path,e.status)}},[N,L,f]),F=(0,r.useCallback)(()=>{g&&y&&O(g,y)},[g,y]),O=(0,r.useCallback)((e,n)=>{let r=e.split("/").pop(),l="?"===n;T({isOpen:!0,title:i("git.discardConfirmTitle"),message:l?i("git.discardConfirmDelete",{name:r}):i("git.discardConfirmDiscard",{name:r}),onConfirm:async()=>{let r=await s.gitDiscard(t,e,n);if(r.success){if(await D(),"diff"===o){let t=f.filter(t=>t.path!==e);t.length>0?L(t[0].path,t[0].status):(c("status"),v(null),k(""),C(!1))}}else h(r.error)}})},[s,t,D,L,f,o,i]),K=(0,r.useCallback)(e=>{let s=t.endsWith("/")?`${t}${e}`:`${t}/${e}`;a?.(s)},[t,a]),[W,H]=(0,r.useState)(null),q=(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)(),H({file:e,x:t.clientX,y:t.clientY})},[]),X=(0,r.useCallback)(async e=>{if(!t||!s||!e?.path)return;let n=await oo(s,t,e.path);n?.success&&(window.dispatchEvent(new CustomEvent(_.GW)),D())},[t,s,D]),V=(0,r.useCallback)(e=>{let s=t.endsWith("/")?`${t}${e.path}`:`${t}/${e.path}`;return[{key:"open",label:i("common.open",{defaultValue:"Open"}),icon:oh.ExternalLink,disabled:"D"===e.status,onClick:()=>K(e.path)},{key:"copyPath",label:i("files.copyPath",{defaultValue:"Copy Path"}),icon:oh.Copy,onClick:()=>q(s)},{key:"copyRel",label:i("files.copyRelPath",{defaultValue:"Copy Relative Path"}),icon:oh.FileText,onClick:()=>q(e.path)},{key:"copyName",label:i("files.copyName",{defaultValue:"Copy Filename"}),icon:oh.FileText,onClick:()=>q(e.path.split("/").pop())},{key:"addToGitignore",label:i("git.addToGitignore",{defaultValue:"Add to .gitignore"}),icon:oh.EyeOff,onClick:()=>X(e)},{key:"discard",label:i("git.discardChangesTitle",{defaultValue:"Discard Changes"}),icon:oh.Undo2,danger:!0,onClick:()=>O(e.path,e.status)}]},[t,i,K,q,X,O]),G={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:i1({name:t,path:e.path,type:"file"},18)}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),L(e.path,e.status),c("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:i("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)(),O(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:i("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 ${_.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)(),l()},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:[i("git.title"),E?(0,n.jsxs)("span",{className:"text-text-muted font-normal",children:[" \xb7 ",E]}):null,M>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:["↑",M]}),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)(),I(!0)},className:"ml-auto p-2 bg-surface-2 hover:bg-surface-3 text-text rounded-brand transition-all duration-200",title:i("git.gitActions"),children:(0,n.jsx)(el.Zr,{className:"w-5 h-5"})}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),"status"===o?D():L(g,y)},className:"p-2 bg-surface-2 hover:bg-surface-2 text-text rounded-brand transition-all duration-200",title:i("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)(),c("status")},className:`flex-1 py-3 text-center font-medium transition ${"status"===o?"text-text border-b-2 border-brand-500":"text-text-muted hover:text-text"}`,children:i("git.status")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),B()},className:`flex-1 py-3 text-center font-medium transition ${"diff"===o?"text-text border-b-2 border-brand-500":"text-text-muted hover:text-text"}`,children:i("git.diffTab")})]}),p&&(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:p}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden modal-scrollable",children:"status"===o?d?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:i("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:i("git.noChanges")}):(0,n.jsxs)(n.Fragment,{children:[G.modified.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[i("git.modified")," (",G.modified.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:G.modified.map(J)})]}),G.added.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[i("git.added")," (",G.added.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:G.added.map(J)})]}),G.deleted.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[i("git.deleted")," (",G.deleted.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:G.deleted.map(J)})]}),G.untracked.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{className:"text-text-muted text-sm mb-2",children:[i("git.untrackedTitle")," (",G.untracked.length,")"]}),(0,n.jsx)("div",{className:"space-y-1",children:G.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:g||"",onChange:e=>{(0,ed.e)();let t=f.find(t=>t.path===e.target.value);t&&L(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))}),g&&"D"!==y&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),(0,ed.e)(),K(g)},disabled:m,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:i("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)(),F()},disabled:!g||m,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:i("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"})})})]}),m?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:i("common.loading")}):g&&(0,_.u)(g)?(0,n.jsx)(cn,{filePath:g,status:y,workspace:t,fileBus:s}):j?(0,n.jsx)(ct,{diff:j}):(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-text-muted",children:i("git.noChanges")})]})}),(0,n.jsx)(ec.A,{isOpen:S.isOpen,onClose:()=>T({isOpen:!1}),onConfirm:S.onConfirm,title:S.title,message:S.message}),A&&(0,n.jsx)(uA,{workspace:t,fileBus:s,branch:E,changedCount:f.length,onDone:D,onClose:()=>I(!1)}),W&&(0,n.jsx)(op,{x:W.x,y:W.y,items:V(W.file),onClose:()=>H(null)})]})}let uD=[{id:_.Kr.explorer,Icon:el.sv,label:"Explorer"},{id:_.Kr.search,Icon:el.vj,label:"Search"},{id:_.Kr.scm,Icon:el.Zr,label:"Source Control"}];function uL(e){let{active:t,onClick:s,label:r,children:l}=e;return(0,n.jsx)("button",{type:"button",title:r,onClick:s,className:`relative w-10 h-10 flex items-center justify-center rounded-brand transition-all duration-150 ease-out active:scale-[0.96] ${t?"bg-surface-2 text-text border-l-2 border-brand-500":"text-text-muted hover:text-text hover:bg-surface-2"}`,children:l})}function uB(e){let{activePanel:t,onSelectPanel:s,onBack:r}=e,l=e=>{(0,ed.e)(10),s?.(e)};return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-between bg-surface border-r border-border py-2",style:{width:_.zT},children:[(0,n.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,n.jsx)(uL,{onClick:()=>{(0,ed.e)(10),r?.()},label:"Back",children:(0,n.jsx)(el.JG,{size:20})}),uD.map(e=>{let{id:s,Icon:r,label:a}=e;return(0,n.jsx)(uL,{active:t===s,onClick:()=>l(s),label:a,children:(0,n.jsx)(r,{size:20})},s)})]}),(0,n.jsx)("div",{className:"flex flex-col items-center gap-1",children:(0,n.jsx)(uL,{active:t===_.Kr.settings,onClick:()=>l(_.Kr.settings),label:"Settings",children:(0,n.jsx)(el.wB,{size:20})})})]})}function uF(e){let{active:t,onClick:s,title:r,children:l}=e;return(0,n.jsx)("button",{type:"button",title:r,onClick:()=>{(0,ed.e)(),s()},className:`px-2 h-6 text-xs rounded-brand border transition-colors ${t?"bg-brand-500 text-white border-brand-500":"bg-surface-2 text-text-muted border-border hover:bg-surface-3"}`,children:l})}function uO(e){let{workspace:t,fileBus:s,onOpenFile:l}=e,[a,i]=(0,r.useState)(""),[o,c]=(0,r.useState)(""),[d,u]=(0,r.useState)(!1),[m,x]=(0,r.useState)(!1),[p,h]=(0,r.useState)(!1),[f,b]=(0,r.useState)(""),[g,v]=(0,r.useState)(""),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(!1),[N,C]=(0,r.useState)([]),[S,T]=(0,r.useState)(!1),[E,R]=(0,r.useState)(!1),[M,$]=(0,r.useState)(new Set),[z,P]=(0,r.useState)(!1),A=(0,r.useRef)(null),I=(0,r.useCallback)(async()=>{if(!a||!t||!s?.searchInFiles){C([]),R(!1);return}T(!0);let e=await s.searchInFiles(t,a,{caseSensitive:d,wholeWord:m,regex:p,includeGlob:f,excludeGlob:g});if(T(!1),e?.success){R(!1);let t=e.results||[];C(t),$(new Set(t.map(e=>e.path)))}else R(!0),C([])},[a,t,s,d,m,p,f,g]);(0,r.useEffect)(()=>{if(A.current&&clearTimeout(A.current),!a){C([]),T(!1);return}return A.current=setTimeout(I,400),()=>clearTimeout(A.current)},[a,d,m,p,f,g,I]);let D=(0,r.useMemo)(()=>{let e=0;for(let t of N)e+=(t.matches||[]).length;return{files:N.length,matches:e}},[N]),L=(0,r.useCallback)(e=>{$(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),B=(0,r.useCallback)(async()=>{if(!a||!t||!s?.replaceInFiles||!N.length)return;let e=N.map(e=>e.path);T(!0),await s.replaceInFiles(t,a,o,{caseSensitive:d,wholeWord:m,regex:p,includeGlob:f,excludeGlob:g},e),T(!1),I()},[a,o,t,s,N,d,m,p,f,g,I]);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:a,onChange:e=>i(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"}),a&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),i("")},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)(uF,{active:d,onClick:()=>u(!d),title:"Match Case",children:"Aa"}),(0,n.jsx)(uF,{active:m,onClick:()=>x(!m),title:"Whole Word",children:"ab"}),(0,n.jsx)(uF,{active:p,onClick:()=>h(!p),title:"Regex",children:".*"}),(0,n.jsx)("span",{className:"flex-1"}),(0,n.jsx)(uF,{active:j,onClick:()=>k(!j),title:"Toggle Replace",children:"↔"}),(0,n.jsx)(uF,{active:y,onClick:()=>w(!y),title:"Filters",children:"…"})]}),j&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{value:o,onChange:e=>c(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:!a||!N.length,onClick:()=>{(0,ed.e)(),P(!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"})]}),y&&(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("input",{value:f,onChange:e=>b(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:g,onChange:e=>v(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] ${E?"text-danger":"text-text-muted"}`,children:S?"Searching...":E?"Search failed — try again":a?`${D.matches} results in ${D.files} files`:"Type to search"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:N.map(e=>{let t=M.has(e.path),s=function(e){if(!e)return"";let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}(e.path),r=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)(),L(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:s}),(0,n.jsx)("span",{className:"truncate text-[11px] text-text-muted flex-1",title:r,children:r}),(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,s)=>(0,n.jsxs)("button",{type:"button",onClick:()=>{(0,ed.e)(),l?.(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,s){let r,l,{caseSensitive:a,wholeWord:i,regex:o}=s;if(!t)return e;try{let e=o?t:t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");i&&!o&&(e=`\\b${e}\\b`),r=new RegExp(e,a?"g":"gi")}catch{return e}let c=[],d=0,u=0;for(;null!==(l=r.exec(e))&&u++<500;)l.index>d&&c.push(e.slice(d,l.index)),c.push((0,n.jsx)("span",{className:"bg-brand-500/30 text-text rounded-sm",children:l[0]},`${l.index}-${u}`)),d=l.index+l[0].length,l.index===r.lastIndex&&r.lastIndex++;return d<e.length&&c.push(e.slice(d)),c}(t.lineText||"",a,{caseSensitive:d,wholeWord:m,regex:p})]},`${e.path}-${s}`))})]},e.path)})}),(0,n.jsx)(ec.A,{isOpen:z,onClose:()=>P(!1),onConfirm:B,title:"Replace All",message:`Replace ${D.matches} matches in ${D.files} files?`,confirmText:"Replace All",cancelText:"Cancel"})]})}let u_="px-3 my-2 text-[11px] uppercase tracking-wider text-text-muted",uK="flex items-center justify-between px-3 py-2 hover:bg-surface-2";function uW(e){let{value:t,onChange:s}=e;return(0,n.jsx)("button",{type:"button",onClick:()=>{(0,ed.e)(),s(!t)},className:`relative w-9 h-5 rounded-full transition-colors ${t?"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 ${t?"translate-x-4":"translate-x-0.5"}`})})}function uH(){let[e,t]=sN(_.d5.editorFontSize,_.A0),[s,r]=sN(_.d5.wordWrap,!1),[l,a]=sN("fileExplorer.showHidden",!0),i=e=>{t(Math.max(_.xr,Math.min(_.bd,Number(e)||_.A0)))};return(0,n.jsxs)("div",{className:"flex flex-col h-full text-sm text-text overflow-auto",children:[(0,n.jsx)("div",{className:u_,children:"Editor"}),(0,n.jsxs)("div",{className:uK,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:_.xr,max:_.bd,value:e,onChange:e=>i(e.target.value),className:"w-24 accent-brand-500"}),(0,n.jsx)("input",{type:"number",min:_.xr,max:_.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:uK,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Word Wrap"}),(0,n.jsx)(uW,{value:s,onChange:r})]}),(0,n.jsx)("div",{className:u_,children:"Files"}),(0,n.jsxs)("div",{className:uK,children:[(0,n.jsx)("span",{className:"text-xs text-text",children:"Show Hidden Files"}),(0,n.jsx)(uW,{value:l,onChange:a})]}),(0,n.jsx)("div",{className:u_,children:"About"}),(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-text-muted",children:"VSCode-like File Explorer for 9remote"})]})}let uq={[_.Kr.explorer]:"Explorer",[_.Kr.search]:"Search",[_.Kr.scm]:"Source Control",[_.Kr.settings]:"Settings"};function uU(e){let{activePanel:t,workspace:s,fileBus:r,onOpenFile:l,onSwitchWorkspace:a,activeFile:i}=e,o=uq[t]||"",c=t===_.Kr.explorer;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[!c&&(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:o}),(0,n.jsx)("button",{type:"button",title:"Refresh",onClick:()=>{(0,ed.e)(10),r?.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(e){let{activePanel:t,workspace:s,fileBus:r,onOpenFile:l,onSwitchWorkspace:a,activeFile:i}=e;switch(t){case _.Kr.explorer:return(0,n.jsx)(ox,{workspace:s,fileBus:r,onOpenFile:l,activeFile:i,onSwitchWorkspace:a});case _.Kr.search:return(0,n.jsx)(uO,{workspace:s,fileBus:r,onOpenFile:l});case _.Kr.scm:return(0,n.jsx)(oC,{workspace:s,fileBus:r,onOpenFile:l});case _.Kr.settings:return(0,n.jsx)(uH,{});default:return null}}({activePanel:t,workspace:s,fileBus:r,onOpenFile:l,onSwitchWorkspace:a,activeFile:i})})]})}function uX(e){let{openedFiles:t,activeFile:s,dirtyFiles:l,onActivate:a,onClose:i,onCloseOthers:o,onCloseAll:c}=e,[d,u]=(0,r.useState)(null),m=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!d)return;let e=e=>{m.current&&!m.current.contains(e.target)&&u(null)};return window.addEventListener("mousedown",e),()=>window.removeEventListener("mousedown",e)},[d]),t?.length)?(0,n.jsxs)("div",{className:"flex overflow-x-auto bg-surface border-b border-border flex-shrink-0 relative",children:[t.map(e=>{let t=e===s,r=l?.has(e),o=(0,_.pA)(e),c=o?(0,_.Ax)(e).absPath:e,d=o?`${c.split("/").pop()} (diff)`:c.split("/").pop(),m=o?null:i1({name:c.split("/").pop()||c,type:"file",path:c},14);return(0,n.jsxs)("div",{onClick:()=>{(0,ed.e)(),a(e)},onMouseDown:t=>{1===t.button&&(t.preventDefault(),(0,ed.e)(),i(e))},onContextMenu:t=>{t.preventDefault(),u({path:e,x:t.clientX,y:t.clientY})},className:`group flex items-center gap-2 px-3 py-1.5 cursor-pointer text-sm flex-shrink-0 select-none ${t?"bg-bg text-text border-t-2 border-t-brand-500":"bg-surface text-text-muted hover:text-text"}`,children:[m?(0,n.jsx)("span",{className:"flex-shrink-0 flex items-center",children:m}):(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:d}),r?(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)(),i(e)},className:`p-0.5 rounded hover:bg-surface-3 transition-opacity ${t||r?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:(0,n.jsx)(el.X,{size:14})})]},e)}),d&&(0,n.jsx)("div",{ref:m,style:{top:d.y,left:d.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:()=>i(d.path)},{label:"Close Others",action:()=>o(d.path)},{label:"Close All",action:()=>c()}].map(e=>(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),e.action(),u(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 uV(e){let{workspace:t,filePath:s}=e;if(!s)return(0,n.jsx)("div",{className:"bg-bg border-b border-border px-3 py-1 text-xs text-text-muted h-7"});let l=t?t.split("/").filter(Boolean).pop():"",a=(t&&s.startsWith(t+"/")?s.slice(t.length+1):s).split("/").filter(Boolean),i=l?[l,...a]:a,o=i.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:i.map((e,t)=>(0,n.jsxs)(r.Fragment,{children:[(0,n.jsx)("span",{className:t===o?"text-text font-medium":"hover:text-text cursor-default",children:e}),t<o&&(0,n.jsx)(el.c_,{size:12,className:"flex-shrink-0"})]},t))})}function uG(e){let{filePath:t,workspace:s,fileBus:l,isActive:a,onCursorChange:i,onDirtyChange:o,onRegisterSaver:c,onOpenFile:d,previewSeq:u=0}=e,{t:m}=(0,eu.s)(),x=!(0,_.pA)(t)&&!oF(t),p=o_({filePath:x?t:"",fileBus:l}),h=x?(0,_.YO)(t):null,f="html"===h,[b,g]=(0,r.useState)(!!u&&!!h),[v,y]=(0,r.useState)(""),[w,j]=(0,r.useState)(0),[k,N]=(0,r.useState)(t),[C,S]=(0,r.useState)(!1),[T,E]=(0,r.useState)(u);k!==t?(N(t),g(!1),y("")):T!==u&&(E(u),u&&h&&g(!0)),p.justSaved!==C&&(S(p.justSaved),p.justSaved&&j(e=>e+1));let R=(0,r.useCallback)(e=>{ca(l,e).then(e=>{e.ok||y(e.error||m("editor.previewFailed"))})},[l,m]);if((0,r.useEffect)(()=>{if(!f||u<=0)return;let e=!1;return ca(l,t).then(t=>{e||t.ok||y(t.error||m("editor.previewFailed"))}),()=>{e=!0}},[f,u,l,t]),(0,r.useEffect)(()=>{o?.(t,x&&p.dirty)},[t,x,p.dirty,o]),(0,r.useEffect)(()=>{if(x)return c?.(t,p.save),()=>{c?.(t,null),o?.(t,!1)}},[t,x,p.save,c,o]),(0,r.useEffect)(()=>{if(!a||!x)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()&&(e.preventDefault(),p.save())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[a,x,p]),(0,_.pA)(t)){let e=(0,_.qu)(t),r=(0,_.Ez)(t,s),a="D"!==e.status,i=a&&"html"===(0,_.YO)(e.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[v&&(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:v}),(i||a&&d)&&(0,n.jsxs)("div",{className:"px-3 py-1.5 flex items-center justify-end bg-surface flex-shrink-0",children:[i&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),R(r)},title:m("editor.previewInBrowser"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:(0,n.jsx)(el.qz,{size:13})}),a&&d&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),d(r)},title:m("git.openFile"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:(0,n.jsx)(el.GD,{size:13})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(cr,{diffPath:t,workspace:s,fileBus:l})})]})}return oF(t)?(0,n.jsx)(oO,{filePath:t,fileBus:l}):(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[p.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:p.error}),v&&(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:v}),h&&(0,n.jsx)("div",{className:"px-3 py-1.5 flex items-center justify-end bg-surface flex-shrink-0",children:f?(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),R(t)},title:m("editor.previewInBrowser"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:(0,n.jsx)(el.qz,{size:13})}):(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),g(e=>!e)},title:b?m("editor.editCode"):m("editor.preview"),className:"p-1 text-text-muted hover:text-text rounded-[3px] hover:bg-surface-2 transition-colors",children:b?(0,n.jsx)(el.GD,{size:13}):(0,n.jsx)(el.kU,{size:13})})}),p.dirty&&(0,n.jsxs)("div",{className:"px-3 py-1.5 flex items-center gap-2 bg-surface flex-shrink-0",children:[(0,n.jsx)("span",{className:"flex-1 text-[11px] text-text-muted",children:m("editor.unsaved")}),(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),p.save()},disabled:p.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})," ",p.saving?m("editor.saving"):m("editor.save")]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:b&&h&&!f?(0,n.jsx)(o9,{kind:h,filePath:t,fileBus:l,content:p.content,reloadKey:w}):p.loading?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:m("common.loading")}):(0,n.jsx)(o5,{filePath:t,content:p.content,onTextChanged:p.onTextChanged,onRegisterView:p.register,onSave:p.save,onCursorChange:i})})]})}function uJ(e){let{workspace:t,fileBus:s,openedFiles:l,activeFile:a,onActivateFile:i,onCloseFile:o,onCloseOthers:c,onCloseAll:d,onOpenFile:u,onEditorStateChange:m,previewRequest:x}=e,[p,h]=(0,r.useState)(()=>new Set),[f,b]=(0,r.useState)(null),g=(0,r.useRef)(new Map);(0,r.useEffect)(()=>{if(!p.size)return;let e=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[p.size]);let v=(0,r.useCallback)((e,t)=>{h(s=>{if(s.has(e)===t)return s;let n=new Set(s);return t?n.add(e):n.delete(e),n})},[]),y=(0,r.useCallback)((e,t)=>{t?g.current.set(e,t):g.current.delete(e)},[]),w=(0,r.useCallback)(e=>{if(!p.has(e))return o?.(e);b(e)},[p,o]),j=(0,r.useCallback)(async e=>{for(let t of l.filter(t=>t!==e&&p.has(t)))if(!1===await g.current.get(t)?.())return;e?c?.(e):d?.()},[l,p,c,d]),k=(0,r.useCallback)(async()=>{!1!==await g.current.get(f)?.()&&(b(null),o?.(f))},[f,o]),N=(0,r.useCallback)(()=>{b(null),o?.(f)},[f,o]);return a?(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-bg min-h-0",children:[(0,n.jsx)(uX,{openedFiles:l,activeFile:a,dirtyFiles:p,onActivate:i,onClose:w,onCloseOthers:e=>j(e),onCloseAll:()=>j(null)}),(0,n.jsx)(uV,{workspace:t,filePath:a}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:l.map(e=>(0,n.jsx)("div",{className:e===a?"h-full":"hidden",children:(0,n.jsx)(uG,{filePath:e,workspace:t,fileBus:s,isActive:e===a,onCursorChange:m,onDirtyChange:v,onRegisterSaver:y,onOpenFile:u,previewSeq:x?.path===e?x.seq:0})},e))}),(0,n.jsx)(oW,{isOpen:!!f,fileName:f?.split("/").pop(),onSave:k,onDiscard:N,onCancel:()=>b(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 uY(e){let{gitBranch:t,line:s,column:r,language:l,encoding:a,activeFile:i,sidebarVisible:o,onToggleSidebar:c,bottomVisible:d,onTogglePanel:u}=e;return(0,n.jsx)(ic,{left:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),c?.()},className:id,title:o?"Hide Sidebar":"Show Sidebar",children:(0,n.jsx)(el.Ay,{name:o?"PanelLeftClose":"PanelLeftOpen",size:12})}),i&&(0,n.jsxs)("span",{className:iu,children:[(0,n.jsx)(el.Zr,{size:12,className:"opacity-60"}),t||"no branch"]})]}),right:(0,n.jsxs)(n.Fragment,{children:[u&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),u()},className:id,title:d?"Hide Terminal":"Show Terminal",children:(0,n.jsx)(el.Ay,{name:"Terminal",size:12})}),i&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:iu,children:`Ln ${s||1}, Col ${r||1}`}),(0,n.jsx)("span",{className:iu,children:l||"plaintext"}),(0,n.jsx)("span",{className:iu,children:a||"UTF-8"})]})]})})}let uZ=tp()?"⌘":"Ctrl+",uQ=[{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:`${uZ}B`},{id:"togglePanel",label:"View: Toggle Terminal Panel",icon:"Terminal",shortcut:`${uZ}J`},{id:"closeAll",label:"View: Close All Editors",icon:"X",shortcut:""},{id:"switchWorkspace",label:"Workspaces: Switch Workspace",icon:"Folder",shortcut:""}];function u0(e){let{mode:t="files",onSetMode:s,workspace:l,fileBus:a,onClose:i,onOpenFile:o,onAction:c}=e,[d,u]=(0,r.useState)(""),[m,x]=(0,r.useState)(0),[p,h]=(0,r.useState)([]),[f,b]=(0,r.useState)(!1),g=(0,r.useRef)(null),v=(0,r.useRef)(null),y=(0,r.useMemo)(()=>{let e=d.trim().toLowerCase();return e?uQ.filter(t=>t.label.toLowerCase().includes(e)):uQ},[d]),w="commands"===t?y:p;(0,r.useEffect)(()=>{x(0)},[t,d,p]),(0,r.useEffect)(()=>{if("files"!==t)return;let e=d.trim();if(!e||!a||!l){h([]),b(!1);return}return b(!0),v.current&&clearTimeout(v.current),v.current=setTimeout(async()=>{let t=await a.searchFiles(l,e);h(t?.success&&Array.isArray(t.files)?t.files:[]),b(!1)},200),()=>{v.current&&clearTimeout(v.current)}},[d,t,a,l]);let j=(0,r.useCallback)(e=>{let n=e.target.value;if("files"===t&&n.startsWith(">")){s?.("commands"),u(n.slice(1));return}u(n)},[t,s]),k=(0,r.useCallback)(e=>{let s=w[e];s&&((0,ed.e)(8),"commands"===t?c?.(s.id):o?.(s.path),i?.())},[w,t,c,o,i]),N=(0,r.useCallback)(e=>{if("Escape"===e.key){e.preventDefault(),i?.();return}if("ArrowDown"===e.key){e.preventDefault(),x(e=>Math.min(e+1,Math.max(w.length-1,0)));return}if("ArrowUp"===e.key){e.preventDefault(),x(e=>Math.max(e-1,0));return}"Enter"===e.key&&(e.preventDefault(),k(m))},[w.length,m,i,k]),C="files"===t?"Type `>` for commands":"Type `?` for help",S="files"===t?"Search files by name…":"Type a command…";return"u"<typeof document?null:(0,se.createPortal)((0,n.jsx)("div",{className:"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-50 flex justify-center pt-[12%] scrim",onMouseDown:i,children:(0,n.jsxs)("div",{className:"relative w-[640px] max-w-[90vw] max-h-[calc(var(--app-height,100dvh)-4rem)] card-elev overflow-hidden flex flex-col",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"===t?"Command":"Search",size:16,className:"text-text-muted"}),(0,n.jsx)("input",{ref:g,autoFocus:!0,type:"text",value:d,onChange:j,onKeyDown:N,placeholder:S,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:C})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 max-h-[400px] overflow-auto",children:0===w.length?"files"!==t||d.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:w.map((e,s)=>{let r=s===m;if("commands"===t)return(0,n.jsxs)("li",{onMouseEnter:()=>x(s),onClick:()=>k(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:e.icon,size:16}),(0,n.jsx)("span",{className:"flex-1 text-sm",children:e.label}),e.shortcut?(0,n.jsx)("kbd",{className:"text-xs text-text-muted px-1.5 py-0.5 bg-surface-2 rounded",children:e.shortcut}):null]},e.id);let l=e.name||(e.path?e.path.split(/[\\/]/).pop():""),a=e.relativePath||e.path||"";return(0,n.jsxs)("li",{onMouseEnter:()=>x(s),onClick:()=>k(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})]})]},e.path||s)})})})]})}),document.body)}function u1(e){let{height:t,onResize:s,onClose:l,bus:a,connected:i,sessions:o=[],onCreateSession:c,onDeleteSession:d,onRenameSession:u}=e,[m,x]=(0,r.useState)(o[0]?.id||null),p=(0,r.useRef)(null),h=(0,r.useRef)(!1);(0,r.useEffect)(()=>{0!==o.length&&(m&&o.find(e=>e.id===m)||x(o[0].id))},[o,m]),(0,r.useEffect)(()=>{0===o.length&&c&&!h.current&&(h.current=!0,c(e=>x(e))),o.length>0&&(h.current=!1)},[o.length,c]);let f=(0,r.useCallback)(()=>{(0,ed.e)(),c?.(e=>x(e))},[c]),b=(0,r.useCallback)((e,t)=>{e.stopPropagation(),(0,ed.e)(),d?.(t)},[d]),g=(0,r.useCallback)(e=>{e.preventDefault();let t=p.current?.parentElement;if(!t)return;let n=t.getBoundingClientRect(),r=e=>{if(0===e.buttons)return void l();let t=(n.bottom-e.clientY)/n.height*100;s(Math.max(_.kS,Math.min(_._C,t)))},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)},[s]);return(0,n.jsxs)("div",{ref:p,className:"bg-bg border-t border-border flex flex-col flex-shrink-0",style:{height:`${t}%`},children:[(0,n.jsx)("div",{onMouseDown:g,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"]}),o.map(e=>{let t=e.id===m;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=>b(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)(),l()},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:[o.map((e,t)=>(0,n.jsx)("div",{className:"absolute inset-0",style:{display:e.id===m?"block":"none"},children:(0,n.jsx)(rX,{bus:a,connected:i,sessionId:e.id,isVisible:e.id===m,isFocused:e.id===m,showFocusBorder:!1,bgIndex:t})},e.id)),0===o.length&&(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-text-muted text-sm",children:"Creating terminal session..."})]})]})}function u2(e){let{workspace:t,fileBus:s,onBack:l,onSwitchWorkspace:a,initialOpenedFiles:i,onOpenedFilesChange:o,bus:c,connected:d,sessions:u,onCreateTerminalSession:m,onDeleteTerminalSession:x,onRenameTerminalSession:p,initialActiveFile:h,viewType:f,openFileRef:b}=e,[g,v]=sN(_.d5.activityPanel,_.Kr.explorer);(0,r.useEffect)(()=>{"git"===f?v(_.Kr.scm):"files"===f&&v(_.Kr.explorer)},[f,v]);let[y,w]=sN(_.d5.sidebarVisible,!0),[j,k]=sN(_.d5.sidebarWidth,_.Qw),[N,C]=sN(_.d5.bottomPanelVisible,!1),[S,T]=sN(_.d5.bottomPanelHeight,_.LN),E=(0,r.useRef)(null),[R,M]=(0,r.useState)(!1),$=(0,r.useCallback)(e=>{e.preventDefault();let t=E.current;if(!t)return;let s=t.getBoundingClientRect();M(!0);let n=e=>{if(0===e.buttons)return void r();let t=(e.clientX-s.left)/s.width*100;k(Math.max(_.hh,Math.min(_.vd,t)))},r=()=>{window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",r),window.removeEventListener("blur",r),document.body.style.userSelect="",document.body.style.cursor="",M(!1)};document.body.style.userSelect="none",document.body.style.cursor="col-resize",window.addEventListener("mousemove",n),window.addEventListener("mouseup",r),window.addEventListener("blur",r)},[k]),[z,P]=(0,r.useState)(i||[]),[A,I]=(0,r.useState)(h||i?.[0]||null),[D,L]=(0,r.useState)({line:1,column:1,language:"",encoding:"UTF-8"}),[B,F]=(0,r.useState)(""),[O,K]=(0,r.useState)({path:null,seq:0}),[W,H]=(0,r.useState)(!1),[q,U]=(0,r.useState)("commands");(0,r.useEffect)(()=>{o?.(z,A)},[z,A,o]);let X=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};P(t=>[e,...t.filter(t=>t!==e)].slice(0,_.L0)),I(e),t.line&&L(e=>({...e,jumpLine:t.line,jumpColumn:t.column})),t.preview&&K(t=>({path:e,seq:t.seq+1}))},[]);(0,r.useEffect)(()=>{b&&(b.current=X)},[b,X]);let V=(0,r.useCallback)(e=>{P(t=>{let s=t.filter(t=>t!==e);return A===e&&I(s[0]||null),s})},[A]),G=(0,r.useCallback)(e=>{P([e]),I(e)},[]),J=(0,r.useCallback)(()=>{P([]),I(null)},[]);return(0,r.useEffect)(()=>{t&&s&&s.gitBranch?.(t).then(e=>{e?.success&&F(e.branch||"")}).catch(()=>{})},[t,s]),!function(){let{onToggleSidebar:e,onSave:t,onCloseTab:s,onCommandPalette:n,onQuickOpen:l,onTogglePanel:a}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},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:()=>w(e=>!e),onTogglePanel:()=>C(e=>!e),onSave:()=>{window.dispatchEvent(new CustomEvent("fileExplorer:save"))},onCloseTab:()=>A&&V(A),onCommandPalette:()=>{U("commands"),H(!0)},onQuickOpen:()=>{U("files"),H(!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)(uB,{activePanel:g,onSelectPanel:e=>{g===e&&y?w(!1):(v(e),w(!0))},onBack:l}),(0,n.jsxs)("div",{ref:E,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:y?`${j}%`:0},"aria-hidden":!y,children:(0,n.jsx)(uU,{activePanel:g,workspace:t,fileBus:s,onOpenFile:X,onSwitchWorkspace:a,activeFile:A})}),(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"} ${y?"w-1":"w-0"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 min-h-0 flex flex-col",children:[(0,n.jsx)(uJ,{workspace:t,fileBus:s,openedFiles:z,activeFile:A,onActivateFile:I,onCloseFile:V,onCloseOthers:G,onCloseAll:J,onOpenFile:X,onEditorStateChange:L,previewRequest:O}),N&&c&&(0,n.jsx)(u1,{height:S,onResize:T,onClose:()=>C(!1),bus:c,connected:d,sessions:u,onCreateSession:m,onDeleteSession:x,onRenameSession:p})]})]})]}),(0,n.jsx)(uY,{gitBranch:B,line:D.line,column:D.column,language:D.language,encoding:D.encoding,activeFile:A,sidebarVisible:y,onToggleSidebar:()=>w(e=>!e),bottomVisible:N,onTogglePanel:()=>C(e=>!e)}),W&&(0,n.jsx)(u0,{mode:q,workspace:t,fileBus:s,onClose:()=>H(!1),onOpenFile:X,onSetMode:U,onAction:e=>{H(!1),"toggleSidebar"===e?w(e=>!e):"togglePanel"===e?C(e=>!e):"closeAll"===e?J():"switchWorkspace"===e?a?.():"openExplorer"===e?(v(_.Kr.explorer),w(!0)):"openSearch"===e?(v(_.Kr.search),w(!0)):"openScm"===e?(v(_.Kr.scm),w(!0)):"openSettings"===e&&(v(_.Kr.settings),w(!0))}})]})}function u5(e){let{isOpen:t,onClose:s}=e,{t:l}=(0,eu.s)(),a=(0,r.useRef)(null);return((0,r.useEffect)(()=>{if(!t)return;document.activeElement?.blur?.();let e=requestAnimationFrame(()=>{a.current?.focus()}),n=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),s())};return window.addEventListener("keydown",n,!0),()=>{cancelAnimationFrame(e),window.removeEventListener("keydown",n,!0)}},[t,s]),!t||"u"<typeof document)?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[60]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:s}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",tabIndex:-1,className:"relative card-elev max-w-md w-full my-auto flex flex-col pop-in 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:l("shortcuts.title")}),(0,n.jsx)("button",{ref:a,onClick:s,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":l("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-5",children:(0,n.jsx)("ul",{className:"flex flex-col divide-y divide-border-subtle/40",children:tu.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:l(`shortcuts.${e.id}`)}),(0,n.jsx)("span",{className:"inline-flex items-center gap-1 flex-shrink-0",children:tg(e).map(e=>(0,n.jsx)("kbd",{className:tf,children:e},e))})]},e.id))})})]})]}),document.body)}function u3(e){let{retryStatus:t,approvalStatus:s,connected:r,hostOffline:l=!1,onLogout:a,onRetryNow:i,suppress:o=!1,firstConnect:c=!1}=e,{t:d}=(0,eu.s)(),u=s===A.J2.pending||s===A.J2.rejected;if(o&&!u&&!l)return null;let m=()=>{a?a():(sessionStorage.clear(),window.location.replace("/login"))};if(s===A.J2.pending)return(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center scrim fade-in",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4 pop-in",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(de.A,{size:"lg"}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:d("connection.waitingApproval")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:d("connection.approvalDescription")}),(0,n.jsx)("p",{className:"text-text-muted text-sm mt-1",children:d("connection.approvalHint")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m()},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:d("connection.cancel")})]})})});if(s===A.J2.rejected)return(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center scrim fade-in",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4 pop-in",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:d("connection.rejectedTitle")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:d("connection.rejectedDescription")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m()},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:d("connection.backToLogin")})]})})});if(l){let e=!!t?.isRetrying;return(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center scrim fade-in",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4 pop-in",children:(0,n.jsxs)("div",{className:"text-center",children:[e?(0,n.jsx)(de.A,{size:"lg"}):(0,n.jsx)("div",{className:"w-16 h-16 mx-auto bg-surface-3 rounded-full flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-8 h-8 text-text-muted",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M18.364 5.636a9 9 0 010 12.728m-12.728 0a9 9 0 010-12.728M5.056 5.056l13.888 13.888"})})}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:d(e?"connection.retrying":"connection.hostOfflineTitle")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:e?d("connection.attemptOf",{n:t.attempt,total:t.maxAttempts}):d("connection.hostOfflineDescription")}),i&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),i()},disabled:e,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-[.98] disabled:opacity-70 disabled:cursor-not-allowed disabled:active:scale-100",children:e?(0,n.jsxs)("span",{className:"inline-flex items-center justify-center gap-2",children:[(0,n.jsx)("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent"}),d("connection.retrying")]}):d("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m()},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-[.98] ${i?"mt-2":"mt-6"}`,children:d("connection.exit")})]})})})}return r||!t?.isRetrying&&!t?.failed||c&&!t?.failed||t?.isRetrying&&t.attempt<A.si?null:(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center scrim fade-in",children:(0,n.jsx)("div",{className:"card-elev p-6 max-w-sm w-full mx-4 pop-in",children:t.isRetrying?(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)(de.A,{size:"lg"}),(0,n.jsx)("h3",{className:"text-text text-lg font-semibold mt-4",children:d("connection.retrying")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:d("connection.attemptOf",{n:t.attempt,total:t.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:`${t.attempt/t.maxAttempts*100}%`}})}),i&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),i()},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:d("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m()},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:d("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:d("connection.failed")}),(0,n.jsx)("p",{className:"text-text-muted mt-2",children:d("connection.failedDescription",{n:t.maxAttempts})}),i&&(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),i()},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:d("connection.retry")}),(0,n.jsx)("button",{onClick:()=>{(0,ed.e)(),m()},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] ${i?"mt-2":"mt-6"}`,children:d("connection.backToLogin")})]})})})}let u4={remote:el.VA,mobile:el.wO,sites:el.qz,notifications:el.Ir,folder:el.Bm,note:el.y8},u6=e=>{let t={hiddenHeaderButtons:e.hiddenHeaderButtons,toggleHeaderButton:e.toggleHeaderButton};for(let s of eg.Fz)"pane"===s.group&&(t[s.storeKey]=e[s.storeKey],t[s.setterKey]=e[s.setterKey]);return t};function u8(){let e=(0,f.B)((0,F.k)(u6));return{buttons:eg.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])}}var u9=s(33879);function u7(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(eO)),[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 me(e,t){let s=(0,f.B)(e=>e.artifactEnabled),n=(0,f.B)(e=>e.setArtifactEnabled),l=!!(0,f.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}}let mt=u9.dI.filter(e=>sp[e.code]);function ms(e){let{isOpen:t,value:s,onSelect:l,onClose:a}=e,{t:i}=(0,eu.s)();return((0,r.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&a()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,a]),!t||"u"<typeof document)?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[70]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:a}),(0,n.jsxs)("div",{className:"relative card-elev max-w-lg w-full my-auto flex flex-col pop-in",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:i("voice.language")}),(0,n.jsx)("button",{onClick:a,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-all duration-150 ease-out","aria-label":i("common.close"),children:(0,n.jsx)(el.X,{size:20})})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 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:mt.map(e=>{let t=e.code===s;return(0,n.jsxs)("button",{onClick:()=>{var t;return t=e.code,void((0,ed.e)(),l(t),a())},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 ${t?"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}),t&&(0,n.jsx)(el.aJ,{size:14,className:"flex-shrink-0"})]},e.code)})})]})]})]}),document.body)}let mn="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",mr="px-3 py-1.5 rounded-brand text-xs font-medium transition-colors",ml=[{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 ma(e){let{active:t,onClick:s,children:r}=e;return(0,n.jsx)("button",{type:"button",onClick:s,className:`px-2.5 py-1 rounded-brand text-[11px] border transition-colors ${t?"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:r})}function mi(e){let{state:t}=e;if(!t)return null;let s=t.busy?"text-text-muted animate-pulse":t.ok?"text-green-500":"text-red-400";return(0,n.jsx)("p",{className:`text-[11px] leading-relaxed break-words ${s}`,children:t.msg})}function mo(){let e=z(),{mode:t,setMode:s,preset:l,setEngine:a,setField:i}=e,{locale:o}=(0,eu.s)(),[c,d]=sb(o),[u,m]=(0,r.useState)(!1),[x,p]=(0,r.useState)(null),[h,f]=(0,r.useState)(null),b=x?.busy||h?.busy,v=u9.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=E(z.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 f({ok:!1,msg:"Enter an API key first"});f({busy:!0,msg:"Recording…"});try{let e=await R(z.getState(),await C(),c);f({ok:!!e,msg:e||"(empty reply)"})}catch(e){f({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)(),m(!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:ml.map(e=>(0,n.jsx)(ma,{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:mn,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:mn,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:mn,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:mn,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:mn,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:mn,autoComplete:"off"})]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:S,disabled:b,className:`${mr} 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:`${mr} bg-surface-2/70 hover:bg-surface-2 text-text disabled:opacity-50`,children:"Test voice"})]}),x&&(0,n.jsx)(mi,{state:x}),h&&(0,n.jsx)(mi,{state:h})]}),u&&(0,n.jsx)(ms,{isOpen:u,value:c,onSelect:d,onClose:()=>m(!1)})]})}function mc(e){let{onClose:t}=e;return"u"<typeof document?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[60]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:t}),(0,n.jsxs)("div",{className:"relative card-elev max-w-md w-full my-auto flex flex-col pop-in",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:t,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 min-h-0 overflow-y-auto modal-scrollable px-5 pb-5",children:(0,n.jsx)(mo,{})})]})]}),document.body)}function md(e){let{dense:t=!1}=e,s=z(e=>e.enabled),l=z(e=>e.mode),a=z(e=>e.preset),i=z(e=>e.setEnabled),[o,c]=(0,r.useState)(!1),d="ai"===l?y[a]?.label||"AI":"Browser",u=()=>{(0,ed.e)(),c(!0)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:t?"w-full px-3.5 py-2 text-text flex items-center gap-3 cursor-pointer select-none transition-colors duration-150 ease-out active:bg-text/[0.06]":"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:u,children:[(0,n.jsx)("span",{className:`w-7 flex-shrink-0 flex items-center justify-center ${t?"text-text-muted":"text-brand-500 dark:text-white"}`,children:(0,n.jsx)(el.GO,{size:16,strokeWidth:2.2})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)("span",{className:`truncate ${t?"text-[15px] font-medium":""}`,children:"Voice input"}),(0,n.jsx)("span",{className:"text-[12px] leading-snug text-text-muted truncate",children:d})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),u()},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)(),i(!s)},"aria-label":"Toggle voice input",className:`shrink-0 relative inline-flex items-center rounded-full transition-colors duration-200 ${t?"h-6 w-11":"h-5 w-9"} ${s?t?"bg-[#34c759]":"bg-brand-500":t?"bg-text/15":"bg-surface-2"}`,children:(0,n.jsx)("span",{className:`inline-block transform rounded-full bg-white shadow-sm transition-transform duration-200 ease-out ${t?s?"h-5 w-5 translate-x-[22px]":"h-5 w-5 translate-x-0.5":s?"h-4 w-4 translate-x-4":"h-4 w-4 translate-x-0.5"}`})})]}),o&&(0,n.jsx)(mc,{onClose:()=>c(!1)})]})}function mu(e){let{open:t=!1,children:s,className:r="",durationMs:l=240}=e;return(0,n.jsx)("div",{className:`collapse ${t?"collapse-open":""} ${r}`,style:{transitionDuration:`${l}ms`},inert:!t,"aria-hidden":!t,children:(0,n.jsx)("div",{className:"min-h-0 overflow-hidden",children:s})})}function mm(e){let{children:t}=e;return(0,n.jsx)("p",{className:"mx-1 mt-4 mb-2 text-[11px] font-semibold uppercase tracking-[0.4px] text-text-subtle",children:t})}function mx(e){let{children:t,className:s="",i:r=0}=e;return(0,n.jsx)("div",{className:"card-rise",style:{"--i":r},children:(0,n.jsx)("div",{className:`glass-card rounded-[18px] overflow-hidden ${s}`,children:t})})}let mp="w-full px-3.5 py-3 text-left flex items-center gap-3 transition-colors duration-150 ease-out active:bg-text/[0.06] disabled:opacity-50";function mh(e){let{icon:t,tone:s="bg-brand-500",label:r,hint:l=null,tail:a=null,onClick:i,disabled:o=!1,danger:c=!1,flat:d=!1}=e;return(0,n.jsxs)("button",{type:"button",onClick:i,disabled:o,className:d?"w-full px-3.5 py-2 text-left flex items-center gap-3 transition-colors duration-150 ease-out active:bg-text/[0.06] disabled:opacity-50":mp,children:[d?(0,n.jsx)("span",{className:"w-7 flex-shrink-0 flex items-center justify-center text-text-muted",children:(0,n.jsx)(t,{size:16,strokeWidth:2.2})}):(0,n.jsx)("span",{className:`squircle-icon ${s}`,children:(0,n.jsx)(t,{size:16,strokeWidth:2.2})}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)("span",{className:`text-[15px] font-medium ${c?"text-danger":"text-text"}`,children:r}),l&&(0,n.jsx)("span",{className:"text-[12px] leading-snug text-text-muted",children:l})]}),a]})}function mf(e){let{icon:t,tone:s,label:r,open:l,onToggle:a,tail:i=null}=e;return(0,n.jsxs)("button",{type:"button",onClick:a,className:mp,"aria-expanded":l,children:[(0,n.jsx)("span",{className:`squircle-icon ${s}`,children:(0,n.jsx)(t,{size:16,strokeWidth:2.2})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 text-[15px] font-medium text-text",children:r}),i,(0,n.jsx)(el.yQ,{size:16,className:`text-text-muted transition-transform duration-200 ${l?"rotate-180":""}`})]})}function mb(){return(0,n.jsx)("div",{className:"ml-[54px] h-px bg-[var(--lg-hairline)]"})}function mg(e){let{on:t}=e;return(0,n.jsx)("span",{className:`shrink-0 relative inline-flex h-6 w-11 items-center rounded-full transition-colors duration-200 ${t?"bg-[#34c759]":"bg-text/15"}`,children:(0,n.jsx)("span",{className:`inline-block h-5 w-5 transform rounded-full bg-white shadow-sm transition-transform duration-200 ease-out ${t?"translate-x-[22px]":"translate-x-0.5"}`})})}function mv(e){let{onRemote:t,onFiles:s,onCommandNotes:l,onCommunity:a,onInstallApp:i,canInstall:o=!1,isInstalled:c=!1,onLogout:d,connected:u=!0,remoteAvailable:m=!1,showTheme:x=!1,theme:p="default",onThemeChange:h,hideActions:b=[],busRef:g=null,subscribeToPush:v=null,unsubscribeFromPush:y=null,onOpenBackgroundPicker:w,onOpenLanguage:j}=e,{t:k,locale:N}=(0,eu.s)(),C=u9.dI.find(e=>e.code===N),S=sj(),T=tj(e=>e.open),E=ey(e=>e.close),{connectionMode:R="tunnel",hostVersion:M,agentVersion:$}=ey(e=>e.context),z=u8(),P=e=>b.includes("headerButtons")?null:z.buttons.filter(t=>t.section===e&&"remote"!==t.id).map(e=>{let t=u4[e.id],s=z.isOn(e);return(0,n.jsx)(mh,{flat:!0,icon:t,label:k(e.labelKey),hint:e.descKey?k(e.descKey):null,onClick:()=>{(0,ed.e)(),z.toggle(e)},tail:(0,n.jsx)(mg,{on:s})},e.id)}),A=n9(e=>!1),I=(0,f.B)(e=>e.webglEnabled),D=(0,f.B)(e=>e.setWebglEnabled),L=(0,f.B)(e=>e.fontSize),B=(0,f.B)(e=>e.setFontSize),F=(0,f.B)(e=>e.terminalTheme),O=(0,f.B)(e=>e.setTerminalTheme),_=(0,f.B)(e=>e.terminalBackgrounds),{theme:K,toggleTheme:W}=(0,t7.D)(),[H,q]=(0,r.useState)(null),U=(0,r.useCallback)(e=>{(0,ed.e)(),q(t=>t===e?null:e)},[]),[X,V]=(0,r.useState)(!1),G=(0,r.useRef)(null);(0,r.useEffect)(()=>{if("terminal"!==H)return;let e=e=>{G.current&&!G.current.contains(e.target)&&q(null)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[H]);let[J,Y]=(0,r.useState)(!1);(0,r.useEffect)(()=>{Y(window.innerWidth<768)},[]);let Z=u7(v,y),Q=me(g,u),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:"px-3 pb-4",children:[(0,n.jsx)(mm,{children:k("menu.settingsAppearance")}),(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)(mx,{i:0,children:[(0,n.jsx)(mh,{icon:"dark"===K?el.AX:el.bd,tone:"bg-gradient-to-br from-amber-400 to-orange-500",label:k("menu.theme"),onClick:()=>{(0,ed.e)(),W()},tail:(0,n.jsx)(mg,{on:"dark"===K})}),(0,n.jsx)(mb,{}),(0,n.jsx)(mh,{icon:el.qz,tone:"bg-gradient-to-br from-blue-500 to-indigo-600",label:k("menu.language"),onClick:()=>{(0,ed.e)(),j?.()},tail:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-text-muted",children:[C&&(0,n.jsx)("img",{src:`https://flagcdn.com/w40/${C.country}.png`,alt:"",className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{className:"text-[13px] font-medium",children:C?.label||N.toUpperCase()})]}),(0,n.jsx)(el.c_,{size:15,className:"text-text-muted"})]})}),!et&&!c&&i||Z.supported?(0,n.jsx)(mb,{}):null,!et&&!c&&i&&(0,n.jsx)(mh,{icon:el.f5,label:k("menu.installApp"),onClick:()=>{(0,ed.e)(),i()},tail:o?(0,n.jsx)("span",{className:"flex-shrink-0 px-2 py-0.5 bg-brand-500 text-white text-[11px] font-semibold rounded-full",children:k("pwaGuide.installNow")}):null}),Z.supported&&(0,n.jsxs)(n.Fragment,{children:[et||c||!i?null:(0,n.jsx)(mb,{}),(0,n.jsx)(mh,{icon:el.Ir,label:k("menu.notifications"),hint:k("menu.notificationsHint"),disabled:Z.loading,onClick:Z.toggle,tail:Z.loading?(0,n.jsx)(el.kr,{size:16,className:"animate-spin text-text-muted"}):(0,n.jsx)(mg,{on:Z.enabled})})]})]}),(0,n.jsx)(mm,{children:k("menu.settingsTerminalTab")}),(0,n.jsxs)(mx,{i:1,children:[!b.includes("terminalSettings")&&(0,n.jsxs)("div",{ref:G,children:[(0,n.jsx)(mf,{icon:el.BK,tone:"bg-gradient-to-br from-slate-500 to-zinc-600",label:k("menu.terminalSettings"),open:"terminal"===H,onToggle:()=>U("terminal")}),(0,n.jsx)(mu,{open:"terminal"===H,children:(0,n.jsxs)("div",{className:"px-3.5 pb-3 space-y-1",children:[(0,n.jsx)(mh,{flat:!0,icon:el.VA,label:k("menu.webgl"),hint:k("menu.webglHint"),onClick:()=>{(0,ed.e)(),D(!I)},tail:(0,n.jsx)(mg,{on:I})}),(0,n.jsxs)("div",{className:"flex items-center gap-3 px-3.5 py-2",children:[(0,n.jsx)("span",{className:"w-7 flex-shrink-0 flex items-center justify-center text-text-muted",children:(0,n.jsx)(el.ZU,{size:16,strokeWidth:2.2})}),(0,n.jsx)("span",{className:"text-[15px] font-medium text-text",children:k("menu.fontSize")}),(0,n.jsx)("select",{value:L??(J?12:14),onChange:e=>{(0,ed.e)(),B(Number(e.target.value))},className:"ml-auto bg-text/[0.06] text-text text-[13px] rounded-[8px] px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-brand-500",children:Array.from({length:J?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-3 px-3.5 py-2",children:[(0,n.jsx)("span",{className:"w-7 flex-shrink-0 flex items-center justify-center text-text-muted",children:(0,n.jsx)(el.es,{size:16,strokeWidth:2.2})}),(0,n.jsx)("span",{className:"text-[15px] font-medium text-text",children:k("menu.terminalTheme")}),(0,n.jsxs)("select",{value:F,onChange:e=>{(0,ed.e)(),O(e.target.value)},className:"ml-auto bg-text/[0.06] text-text text-[12px] rounded-[8px] px-2 py-1 max-w-[55%] focus:outline-none focus:ring-1 focus:ring-brand-500",children:[(0,n.jsx)("option",{value:"default",children:"Vesper (Default)"}),rM.g4.filter(e=>e.mode===K).map(e=>(0,n.jsx)("option",{value:e.key,children:e.label},e.key))]})]}),P("terminal")]})})]}),!b.includes("terminalSettings")&&(0,n.jsx)(mb,{}),(0,n.jsxs)("div",{children:[(0,n.jsx)(mf,{icon:el.vv,tone:"bg-gradient-to-br from-emerald-500 to-teal-600",label:k("menu.settingsRemote"),open:"remote"===H,onToggle:()=>U("remote")}),(0,n.jsx)(mu,{open:"remote"===H,children:(0,n.jsx)("div",{className:"px-3.5 pb-3 space-y-1",children:P("remote")})})]}),(0,n.jsx)(mb,{}),(0,n.jsxs)("div",{children:[(0,n.jsx)(mf,{icon:el.Kq,tone:"bg-gradient-to-br from-amber-500 to-orange-600",label:k("menu.settingsMcp"),open:"mcp"===H,onToggle:()=>U("mcp")}),(0,n.jsx)(mu,{open:"mcp"===H,children:(0,n.jsxs)("div",{className:"px-3.5 pb-3 space-y-1",children:[(0,n.jsx)(md,{dense:!0}),Q.supported&&(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(mh,{flat:!0,icon:el.jz,label:k("menu.artifactPanel"),hint:k("menu.artifactHint"),disabled:Q.loading||!u,onClick:Q.toggle,tail:(0,n.jsx)(mg,{on:Q.enabled})})}),P("plugins")]})})]}),es&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mb,{}),(0,n.jsxs)("div",{children:[(0,n.jsx)(mf,{icon:el.kt,tone:"bg-gradient-to-br from-sky-500 to-blue-600",label:k("menu.orientation"),open:"orientation"===H,onToggle:()=>U("orientation")}),(0,n.jsx)(mu,{open:"orientation"===H,children:(0,n.jsx)("div",{className:"px-3.5 pb-3 space-y-1",children:[{id:"portrait",label:k("menu.orientationPortrait"),Icon:el.wO},{id:"auto",label:k("menu.orientationAuto"),Icon:el.kt}].map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>ea(e.id),className:"w-full px-3.5 py-2 text-text text-left flex items-center gap-3 rounded-[10px] transition-colors duration-150 ease-out active:bg-text/[0.06]",children:[(0,n.jsx)("span",{className:"w-7 flex-shrink-0 flex items-center justify-center text-text-muted",children:(0,n.jsx)(e.Icon,{size:16,strokeWidth:2.2})}),(0,n.jsx)("span",{className:"text-[15px] font-medium 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.jsx)(mm,{children:k("menu.settingsApplication")}),(0,n.jsxs)(mx,{i:2,children:["dark"===K&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mh,{icon:el.de,tone:"bg-gradient-to-br from-fuchsia-500 to-purple-600",label:k("menu.terminalBackground"),onClick:()=>{(0,ed.e)(),w?.()},tail:(0,n.jsx)("span",{className:"text-[12px] text-text-muted truncate max-w-[90px]",children:_.length>1?`${(0,eg.Pz)(_[0])} +${_.length-1}`:(0,eg.Pz)(_[0])})}),(0,n.jsx)(mb,{})]}),A&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mh,{icon:el.cC,label:"Jarvis",onClick:()=>{(0,ed.e)(),E(),n9.getState().toggle()}}),(0,n.jsx)(mb,{})]}),l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mh,{icon:el.iU,label:k("menu.commandNotes"),onClick:()=>{(0,ed.e)(),l()}}),(0,n.jsx)(mb,{})]}),"mouse"===S&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mh,{icon:el.s3,label:k("shortcuts.menuLabel"),onClick:()=>{(0,ed.e)(),E(),T()}}),(0,n.jsx)(mb,{})]}),a&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mh,{icon:el.zW,label:k("menu.community"),onClick:()=>{(0,ed.e)(),a()}}),(0,n.jsx)(mb,{})]}),ee&&window.DEVICE_INFO?.platform!=="ios"&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mh,{icon:el.FE,label:k("menu.rateApp"),onClick:ei}),(0,n.jsx)(mb,{})]}),(0,n.jsx)(mh,{icon:el.e9,label:k("menu.reload"),disabled:X,onClick:()=>{(0,ed.e)(),V(!0),setTimeout(()=>window.location.reload(),150)},tail:X?(0,n.jsx)(el.kr,{size:16,className:"animate-spin text-text-muted"}):null})]}),d&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mm,{children:k("menu.settingsAccount")}),(0,n.jsx)(mx,{i:3,children:(0,n.jsx)(mh,{icon:el.nU,tone:"bg-danger/15 !text-danger",label:k("menu.logout"),danger:!0,onClick:()=>{(0,ed.e)(),d()}})})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 mt-5 mr-1",children:["local"===R&&(0,n.jsx)("span",{className:"text-[11px] 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-[12px]",children:[k("menu.version")," ","2.4.0",M||$?` / 9Remote ${M||$}`:""]})]})]})}var my=s(75677);function mw(){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 mj(){let{t:e}=(0,eu.s)(),[t]=(0,r.useState)(mw),[s,l]=(0,r.useState)(!1),[a,i]=(0,r.useState)("idle"),o=ey(e=>e.context.apiKey),c=e0(e=>e.canInstall),d=e0(e=>e.isInstalled),u=e0(e=>e.install),m=async()=>{i("installing"),i("accepted"===await u()?"done":"idle")},x=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 x(o)&&(l(!0),setTimeout(()=>l(!1),2e3))},h=+!!o,f=()=>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,my.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+h}),(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:m,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:[f(),(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+h}),(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+h}),(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:[f(),(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+h}),(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+h}),(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:[f(),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+h}),(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+h}),(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+h}),(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 mk=[{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:mN,maxNotes:mC}={storageKey:"9remote_command_notes_v2",maxNotes:50};function mS(e){let{isOpen:t,onClose:s}=e,{t:l}=(0,eu.s)(),{notes:a,addNote:i,updateNote:o,deleteNote:c}=function(){let[e,t]=(0,r.useState)([]),s=(0,r.useCallback)(()=>{try{let e=localStorage.getItem(mN);if(e)return JSON.parse(e);let t=mk.map((e,t)=>({id:`default_${t}`,...e}));return localStorage.setItem(mN,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(mN,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,mC))},[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}}(),[d,u]=(0,r.useState)(null),[m,x]=(0,r.useState)(null),[p,h]=(0,r.useState)(""),f=(0,r.useRef)(null),[b,g]=(0,r.useState)(null);(0,r.useEffect)(()=>{t&&setTimeout(()=>f.current?.focus(),100)},[t,m]),(0,r.useEffect)(()=>{if(!t||!window.visualViewport)return;let e=window.visualViewport,s=()=>g(e.height);return s(),e.addEventListener("resize",s),e.addEventListener("scroll",s),()=>{e.removeEventListener("resize",s),e.removeEventListener("scroll",s)}},[t]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t&&s()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,s]);let v=(0,r.useCallback)((e,t)=>{(0,ed.e)(),navigator.clipboard?.writeText(t).catch(()=>{}),u(e),setTimeout(()=>u(null),2e3)},[]),y=(0,r.useCallback)(e=>{(0,ed.e)(),x(e.id),h(e.command)},[]),w=(0,r.useCallback)(()=>{p.trim()&&((0,ed.e)(),m?(o(m,p.trim()),x(null)):i(p.trim()),h(""))},[p,m,i,o]),j=(0,r.useCallback)(e=>{(0,ed.e)(),c(e),m===e&&(x(null),h(""))},[c,m]),k=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),w())},[w]);return!t||"u"<typeof document?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:s}),(0,n.jsxs)("div",{className:"absolute top-0 right-0 w-[85vw] sm:w-96 max-w-md glass-drawer border-l border-border shadow-2xl flex flex-col slide-in-right",style:{height:`${b??window.visualViewport?.height??window.innerHeight}px`},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:l("commandNotes.title")})]}),(0,n.jsx)("button",{onClick:s,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===a.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:l("commandNotes.noSavedCommands")}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-1",children:l("commandNotes.addFirstBelow")})]}),a.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:()=>v(e.id,e.command),title:l("commandNotes.clickToCopy"),children:[(0,n.jsx)("p",{className:"text-sm text-text font-mono break-all",children:e.command}),d===e.id&&(0,n.jsx)("span",{className:"text-xs text-green-400 mt-1 inline-block",children:l("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:()=>v(e.id,e.command),className:"p-1.5 text-text-muted hover:text-brand-400 rounded transition-colors",title:l("commandNotes.copy"),children:d===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:()=>y(e),className:"p-1.5 text-text-muted hover:text-brand-400 rounded transition-colors",title:l("commandNotes.edit"),children:(0,n.jsx)(el.gH,{size:14})}),(0,n.jsx)("button",{onClick:()=>j(e.id),className:"p-1.5 text-text-muted hover:text-red-400 rounded transition-colors",title:l("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:p,onChange:e=>h(e.target.value),onKeyDown:k,placeholder:m?l("commandNotes.editCommandPlaceholder"):l("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:w,disabled:!p.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:m?l("commandNotes.update"):l("commandNotes.add"),children:(0,n.jsx)(el.Vn,{size:18})})]})})]})]}),document.body)}let mT=[{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 mE(e){let{isOpen:t,onClose:s}=e,{t:l}=(0,eu.s)();return((0,r.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&s?.()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,s]),!t||"u"<typeof document)?null:(0,se.createPortal)((0,n.jsxs)("div",{className:"modal-overlay z-[60]",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:s}),(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:l("community.title")}),(0,n.jsx)("button",{onClick:s,className:"p-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors","aria-label":l("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:l("community.description")}),mT.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))]})]})]}),document.body)}var mR=s(18179);let mM=[{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"}],m$="browserUseConfig",mz={enabled:!1,preset:"free",endpoint:"",model:"",apiKey:"",minConfidence:.55,headless:!0,mode:"own",hostKeySet:!1};function mP(e){try{localStorage.setItem(m$,JSON.stringify({...e,apiKey:""}))}catch{}}let mA=(0,b.v)((e,t)=>({...function(){try{let e=localStorage.getItem(m$);return e?{...mz,...JSON.parse(e)}:{...mz}}catch{return{...mz}}}(),setConfig:s=>{let n={...t(),...s};e(n),mP(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),mP(n)}}));function mI(e){return(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])}let mD="chrome://inspect/#remote-debugging";function mL(e){let{value:t,showValue:s=!1}=e,[l,a]=(0,r.useState)(!1),i=async()=>{(0,ed.e)();try{await navigator.clipboard.writeText(t),a(!0),setTimeout(()=>a(!1),1500)}catch{}};return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 align-middle",children:[s&&(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-surface-2 rounded-brand text-[10.5px] text-text select-all break-all",children:t}),(0,n.jsx)("button",{onClick:i,title:"Copy",className:"p-0.5 text-text-muted hover:text-text",children:l?(0,n.jsx)(el.aJ,{size:12,className:"text-emerald-500"}):(0,n.jsx)(el.QR,{size:12})})]})}let mB=["Use the 9r-browser skill to open my latest Shopee order and tell me where the package is","Use the 9r-browser skill to compare iPhone 17 prices across the top 3 shopping sites","Use the 9r-browser skill to log into Netflix and download my latest invoice PDF","Use the 9r-browser skill to search LinkedIn for React jobs posted this week in Ho Chi Minh City","Use the 9r-browser skill to log into Facebook and list today's new posts in my groups"];function mF(e){let{busRef:t}=e,{t:s}=(0,eu.s)(),l=mI(t),[a,i]=(0,r.useState)(null);return(0,r.useEffect)(()=>{let e=!0,t=()=>l("ext.status",{}).then(t=>{e&&i(t)});t();let s=setInterval(t,3e3);return()=>{e=!1,clearInterval(s)}},[l]),(0,n.jsxs)("div",{className:"rounded-brand border border-border-subtle p-2.5 space-y-2",children:[(0,n.jsxs)("span",{className:`flex items-center gap-1.5 text-xs font-medium ${a?.connected?"text-emerald-500":"text-amber-500"}`,children:[(0,n.jsx)("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${a?.connected?"bg-emerald-500":"bg-amber-500"}`}),a?!1===a.ok?a.error||"Unavailable":a.connected?"Extension connected":"Extension not connected":"Checking…"]}),a?.ok&&!a.connected&&(0,n.jsxs)("ol",{className:"list-decimal ml-4 text-[11px] text-text-muted space-y-1",children:[(0,n.jsx)("li",{children:(0,n.jsxs)("span",{className:"flex items-center flex-wrap gap-1",children:[s("menu.extGuide1"),(0,n.jsx)(mL,{value:"chrome://extensions/",showValue:!0})]})}),(0,n.jsx)("li",{children:(0,n.jsxs)("span",{className:"flex items-center flex-wrap gap-1",children:[s("menu.extGuide2"),(0,n.jsx)(mL,{value:a.dir||"~/.9remote/browser-extension",showValue:!0})]})}),(0,n.jsx)("li",{children:s("menu.extGuide3")})]})]})}function mO(e){let{busRef:t}=e,s=mA(),l=mI(t),[a,i]=(0,r.useState)(null),[o,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(!1),[m,x]=(0,r.useState)(null);(0,r.useEffect)(()=>{l("config.get").then(e=>{e.ok&&e.config&&s.syncFromHost(e.config)})},[]);let p=async()=>{c(!0);let e=await l("attach.status",{});e.ok&&i(e),c(!1)},h=async()=>{try{await navigator.clipboard.writeText(mD),u(!0),setTimeout(()=>u(!1),1500)}catch{}};(0,r.useEffect)(()=>{if("attach"!==s.mode)return;let e=setTimeout(p,0);return()=>clearTimeout(e)},[s.mode]);let f=async e=>{(0,ed.e)();try{await navigator.clipboard.writeText(e),x(e),setTimeout(()=>x(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:s.mode||"own",onChange:e=>{var t;return t={mode:e.target.value},void(s.setConfig(t),l("config.set",t))},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 (default)"}),(0,n.jsx)("option",{value:"extension",children:"Real browser (extension)"})]})]}),"attach"===s.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 ${a?.available?"text-emerald-500":"text-amber-500"}`,children:[(0,n.jsx)("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${a?.available?"bg-emerald-500":"bg-amber-500"}`}),a?a.available?`Attached \xb7 port ${a.port}`:"Not attached":"Checking…"]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("button",{onClick:()=>l("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:o,className:"px-2 py-1 bg-surface-2 rounded-brand text-xs text-text-muted disabled:opacity-40",children:o?"…":"Recheck"})]})]}),a&&!a.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:mD}),(0,n.jsx)("button",{onClick:h,className:"shrink-0 px-2 py-1 bg-surface-2 rounded-brand text-xs text-text-muted",children:d?"Copied":"Copy"})]}),(0,n.jsx)("ol",{className:"list-decimal ml-4 text-[11px] text-text-muted space-y-0.5",children:(a.guide||[]).map((e,t)=>(0,n.jsx)("li",{children:e},t))})]})]}),"extension"===s.mode&&(0,n.jsx)(mF,{busRef: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:mB.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>f(e),className:"w-full text-left px-2.5 py-1.5 rounded hover:bg-surface-2/80 flex items-start justify-between gap-2 group transition-colors",children:[(0,n.jsx)("span",{className:"text-[11.5px] text-text break-words font-mono",children:e}),(0,n.jsx)("span",{className:"flex-shrink-0 text-text-muted group-hover:text-text",children:m===e?(0,n.jsx)(el.aJ,{size:13,className:"text-emerald-500"}):(0,n.jsx)(el.QR,{size:13})})]},e))})]})]})}function m_(e){let{isOpen:t,onClose:s,busRef:l,inline:a=!1}=e,{t:i}=(0,eu.s)(),o=(0,f.B)(e=>e.terminalBackgrounds);(0,f.B)(e=>e.setTerminalBackgrounds);let c=(0,f.B)(e=>e.terminalBackgroundOpacity),d=(0,f.B)(e=>e.setTerminalBackgroundOpacity),u=(0,f.B)(e=>e.customBackgrounds),{saving:m,error:x,setError:p,fileInput:h,openPicker:b}=nH(l),[g,v]=(0,r.useState)(()=>window.innerWidth>=eg.jK);(0,r.useEffect)(()=>{let e=()=>v(window.innerWidth>=eg.jK);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>{if(!t)return;let e=e=>{"Escape"===e.key&&(p(""),s())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,s,p]);let y=()=>{p(""),s()};if(!a&&!t)return null;let w=c??eg._z,{min:j,max:k,step:N}=eg.DW,C=`${(w-j)/(k-j)*100}%`,S=(0,eg.IJ)(o,u),T=(e,t,s)=>{let r="none"===e,l=r?-1:S.indexOf(e),a=r?0===S.length:-1!==l;return(0,n.jsxs)("button",{onClick:()=>(e=>{(0,ed.e)();let{terminalBackgrounds:t,setTerminalBackgrounds:s}=f.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,${eg.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})]})},E=(0,n.jsxs)("div",{className:a||g?"grid grid-cols-3 gap-3":"grid grid-cols-2 gap-3",children:[Object.entries(eg.vk).map(e=>{let[t,s]=e;return(0,n.jsx)("div",{children:T(t,s.label,s.src)},t)}),u.map(e=>(0,n.jsxs)("div",{className:"relative",children:[T(`custom:${e.id}`,i("menu.bgCustomLabel"),e.dataUrl),(0,n.jsx)("button",{onClick:()=>{var t;let s;return t=e.id,(0,ed.e)(),s=l?.current,void(s?.emit&&s.emit("bg:delete",{id:t},e=>{if(!e?.success)return void p(e?.error||i("menu.bgDeleteFailed"));let s=`custom:${t}`,{customBackgrounds:n,setCustomBackgrounds:r,terminalBackgrounds:l,setTerminalBackgrounds:a}=f.B.getState();r(n.filter(e=>e.id!==t)),a(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":i("common.delete"),children:(0,n.jsx)(el.X,{size:13})})]},`custom:${e.id}`)),(0,n.jsxs)("button",{onClick:b,disabled:m,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:[m?(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:i("menu.bgAdd")})]})]}),R=S.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:i("menu.bgDim")}),(0,n.jsx)("input",{type:"range",min:j,max:k,step:N,value:w,onChange:e=>d(Number(e.target.value)),className:"brand-range flex-1 min-w-0",style:{"--pct":C},"aria-label":i("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums flex-shrink-0",children:[Math.round(100*w),"%"]})]}),M=S.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:i("menu.bgDim")}),(0,n.jsxs)("span",{className:"text-xs text-text-muted tabular-nums",children:[Math.round(100*w),"%"]})]}),(0,n.jsx)("input",{type:"range",min:j,max:k,step:N,value:w,onChange:e=>d(Number(e.target.value)),className:"brand-range brand-range-lg",style:{"--pct":C},"aria-label":i("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 ${a?"":"flex-shrink-0 mx-5 mb-2"}`,children:x});return a?(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:[E,$]}),R,h]}):(0,se.createPortal)((0,n.jsxs)("div",{className:g?"modal-overlay z-[60]":"fixed inset-x-0 top-0 h-[var(--app-height,100dvh)] z-[60] flex flex-col justify-end",children:[(0,n.jsx)("div",{className:"absolute inset-0 scrim fade-in",onClick:y}),(0,n.jsxs)("div",{className:g?"relative w-full max-w-lg card-elev my-auto flex flex-col overflow-hidden pop-in":"relative rounded-t-3xl border-t border-border glass-drawer shadow-2xl max-h-[calc(var(--app-height,100dvh)-2rem)] flex flex-col sheet-rise",children:[!g&&(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 ${g?"pt-4":""}`,children:[(0,n.jsx)("h3",{className:"text-lg font-semibold text-text",children:i("menu.terminalBackground")}),(0,n.jsx)("button",{onClick:y,className:"p-2 -mr-2 text-text-muted hover:text-text hover:bg-surface-2 rounded-full transition-colors","aria-label":i("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:E}),$,M]}),h]}),document.body)}let mK=/^(\S+) (DEBUG|INFO|WARN|ERROR) \[([^\]]+)\] (.*)$/,mW=0,mH=null;function mq(e,t,s,n,r){return{id:++mW,ts:r||new Date().toISOString(),source:e,level:t,domain:s,msg:n}}function mU(e){let t=mK.exec(e);return t?mq("host",t[2].toLowerCase(),t[3],t[4],t[1]):mq("host","info","host",e)}let mX=(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,m.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(mU),...r].slice(-500)})}catch{}},startHostTail:()=>{(0,m.gJ)()&&!mH&&((mH=new EventSource("/api/ui/events")).onmessage=e=>{let s;try{s=JSON.parse(e.data)}catch{return}s?.type==="log"&&s.message&&t().push(mU(s.message))})},stopHostTail:()=>{mH?.close(),mH=null}}));if(!window.__logCapture){window.__logCapture=!0;let e=mX.getState().push,t=(t,s)=>{let n=console[t];console[t]=function(){for(var t=arguments.length,r=Array(t),l=0;l<t;l++)r[l]=arguments[l];try{e(mq("web",s,"web",r.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(...r)}};t("log","info"),t("info","info"),t("warn","warn"),t("error","error"),t("debug","debug"),window.addEventListener("error",t=>e(mq("web","error","web",t.message))),window.addEventListener("unhandledrejection",t=>e(mq("web","error","web",`Unhandled rejection: ${t.reason}`)))}let mV={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 mG(e){let{context:t,callbacks:s,canInstall:l,isInstalled:a,install:i,onClose:o}=e,{t:c,locale:d}=(0,eu.s)(),{theme:u,setTheme:x}=(0,t7.D)(),p=(0,m.gJ)(),[h,b]=(0,r.useState)(p?"system":"general"),[g,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),j=function(){let[e,t]=(0,r.useState)(null),[s,n]=(0,r.useState)(null),[l,a]=(0,r.useState)(null);(0,r.useEffect)(()=>{(0,m.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}}(),k=z(e=>e.enabled),N=mA(e=>e.enabled),C=z(e=>e.setEnabled),[S,T]=(0,r.useState)(!1),E=u9.dI.find(e=>e.code===d),R=(0,f.B)(e=>e.webglEnabled),M=(0,f.B)(e=>e.setWebglEnabled),$=(0,f.B)(e=>e.fontSize),P=(0,f.B)(e=>e.setFontSize),A=(0,f.B)(e=>e.terminalTheme),I=(0,f.B)(e=>e.setTerminalTheme),D=u8(),L=u7(t.subscribeToPush,t.unsubscribeFromPush),B=me(t.busRef,t.connected),F=n9(e=>!1),O=B.supported,_=t.hostVersion||t.agentVersion,K=(0,r.useMemo)(()=>t.hideActions||[],[t.hideActions]),W=!(window.matchMedia("(display-mode: standalone)").matches||window.ReactNativeWebView)&&!a,H=(0,r.useMemo)(()=>mM.filter(e=>"codespace"!==e.id&&("terminal"===e.id?!K.includes("terminalSettings"):"system"===e.id?p:"general"!==e.id||!p)),[K,p]),q=H.find(e=>e.id===h);(0,r.useEffect)(()=>{document.activeElement?.blur?.();let e=e=>{"Escape"!==e.key||S||y||(e.preventDefault(),e.stopPropagation(),o())};return window.addEventListener("keydown",e,!0),document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",e,!0),document.body.style.overflow=""}},[o,S,y]);let U=(e,t)=>(0,n.jsx)(mJ,{title:t,children:D.buttons.filter(t=>t.section===e).map(e=>(0,n.jsx)(mZ,{icon:u4[e.id],label:c(e.labelKey),hint:e.descKey?c(e.descKey):void 0,value:D.isOn(e),onChange:()=>D.toggle(e)},e.id))}),X=(0,r.useCallback)(e=>{(0,ed.e)(),o(),setTimeout(()=>e?.(),50)},[o]);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 scrim fade-in",onClick:o}),(0,n.jsxs)("div",{className:"relative w-full max-w-4xl h-[85vh] max-h-[640px] card-elev flex overflow-hidden pop-in",role:"dialog","aria-modal":"true","aria-label":c("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:c("menu.settings")})}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-0.5 modal-scrollable",children:H.map(e=>{let t=mV[e.icon],s=h===e.id;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),b(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:c(e.labelKey)})]},e.id)})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center gap-2",children:["local"===t.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:["2.4.0",_?` / ${_}`:""]})]})]}),(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"===h?(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),b("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}),c("pwa.title")]}):(0,n.jsx)("h3",{className:"text-sm font-medium text-text truncate",children:c(q?.labelKey||"menu.settings")}),(0,n.jsx)("button",{onClick:o,className:"p-1.5 text-text-muted hover:text-text hover:bg-surface-2 rounded-brand transition-colors flex-shrink-0","aria-label":c("common.close"),children:(0,n.jsx)(el.X,{size:18})})]}),(0,n.jsxs)("div",{className:"debug"===h?"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"===h?"py-4":"py-5"}`,children:["background"===h&&(0,n.jsx)(m_,{inline:!0,busRef:t.busRef}),"general"===h&&(0,n.jsxs)("div",{className:"space-y-6",children:[(L.supported||W)&&(0,n.jsxs)(mJ,{children:[L.supported&&(0,n.jsx)(mZ,{icon:el.Ir,label:c("menu.notifications"),hint:c("menu.notificationsHint"),value:L.enabled,loading:L.loading,onChange:L.toggle}),W&&(0,n.jsx)(mY,{icon:el.f5,label:c("menu.installApp"),badge:l?c("pwaGuide.installNow"):null,onClick:()=>l?X(i):b("install")})]}),(0,n.jsx)(mJ,{title:c("menu.reloadRestart"),children:(0,n.jsx)(mY,{icon:el.e9,iconClass:g?"animate-spin":"",label:c("menu.reload"),disabled:g,onClick:()=>{(0,ed.e)(),v(!0),setTimeout(()=>window.location.reload(),150)}})}),s.onLogout&&(0,n.jsx)(mJ,{title:c("menu.settingsAccount"),children:(0,n.jsx)(mY,{icon:el.nU,label:c("menu.logout"),danger:!0,onClick:()=>X(s.onLogout)})})]}),"appearance"===h&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(mJ,{title:c("menu.theme"),children:(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,n.jsx)(m0,{icon:el.bd,label:c("menu.themeLight"),active:"light"===u,onClick:()=>{(0,ed.e)(),x("light")}}),(0,n.jsx)(m0,{icon:el.AX,label:c("menu.themeDark"),active:"dark"===u,onClick:()=>{(0,ed.e)(),x("dark")}})]})}),(0,n.jsx)(mJ,{title:c("menu.language"),children:(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),T(!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:c("menu.language")}),E&&(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/${E.country}.png`,alt:"",className:"w-[17px] h-[12px] object-cover rounded-[2px]",loading:"lazy"}),(0,n.jsx)("span",{className:"text-xs",children:E.label})]}),(0,n.jsx)(el.c_,{size:15,className:"text-text-muted flex-shrink-0"})]})})]}),"terminal"===h&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)(mJ,{title:c("menu.terminalSettings"),children:[(0,n.jsx)(mQ,{icon:el.ZU,label:c("menu.fontSize"),children:(0,n.jsx)("select",{value:$??14,onChange:e=>{(0,ed.e)(),P(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)(mQ,{icon:el.es,label:c("menu.terminalTheme"),children:(0,n.jsxs)("select",{value:A,onChange:e=>{(0,ed.e)(),I(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)"}),rM.g4.filter(e=>e.mode===u).map(e=>(0,n.jsx)("option",{value:e.key,children:e.label},e.key))]})}),(0,n.jsx)(mZ,{icon:el.VA,label:c("menu.webgl"),hint:c("menu.webglHint"),value:R,onChange:M})]}),U("terminal",c("menu.showButtons"))]}),"voice"===h&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(mZ,{icon:el.GO,label:c("menu.voiceInput"),value:k,onChange:C}),(0,n.jsx)("div",{className:k?"":"pointer-events-none opacity-40 select-none",children:(0,n.jsx)(mo,{})})]}),"browser"===h&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(mZ,{icon:el.qz,label:c("menu.settingsBrowser"),value:N,onChange:e=>mA.getState().setConfig({enabled:e})}),(0,n.jsx)("div",{className:N?"":"pointer-events-none opacity-40 select-none",children:(0,n.jsx)(mO,{busRef:t.busRef})})]}),"remote"===h&&U("remote"),"mcp"===h&&(0,n.jsxs)("div",{className:"space-y-6",children:[O&&(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(mZ,{icon:el.jz,label:c("menu.artifactPanel"),hint:c("menu.artifactHint"),value:B.enabled,loading:B.loading,disabled:!t.connected,onChange:B.toggle})}),U("plugins")]}),"system"===h&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)(mJ,{title:c("menu.agentSystem"),children:[(0,n.jsx)(mZ,{icon:el.Mr,label:c("menu.agentAutoStart"),hint:c("menu.agentAutoStartHint"),value:!!j.autoStart,loading:null===j.autoStart,onChange:j.toggleAutoStart}),j.unlock?.supported&&(0,n.jsx)(mZ,{icon:el.LM,label:c("menu.agentUnlock"),hint:j.unlock.stale?c("menu.agentUnlockStale"):j.unlock.enabled?c("menu.agentUnlockReady"):c("menu.agentUnlockHint"),value:!!j.unlock.enabled,disabled:!!j.unlock.busy,onChange:j.toggleUnlock}),(0,n.jsx)(mQ,{icon:el.AX,label:c("menu.preventSleep"),children:(0,n.jsx)("select",{value:j.sleep?.mode||"never",disabled:!j.sleep,onChange:e=>{(0,ed.e)(),j.setSleepMode(e.target.value)},className:"bg-surface-2 text-text text-sm rounded-brand px-2 py-1 focus:outline-none",children:(j.sleep?.presets||[]).map(e=>(0,n.jsx)("option",{value:e,children:m1[e]||e},e))})})]}),(0,n.jsx)(mJ,{title:c("menu.agentPower"),children:(0,n.jsx)(mY,{icon:el.$o,label:c("menu.agentShutdown"),danger:!0,onClick:()=>w(!0)})})]}),"jarvis"===h&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(mZ,{icon:el.cC,label:c("menu.jarvisToggle"),hint:c("menu.jarvisToggleHint"),value:F,onChange:e=>{n9.getState().setSettings({enabled:e}),e||n9.getState().setOpen(!1)}}),O&&!B.enabled&&(0,n.jsx)("p",{className:"text-[11px] leading-relaxed text-amber-400",children:c("menu.jarvisMcpOff")}),(0,n.jsx)(ro,{busRef:t.busRef})]}),"debug"===h&&(0,n.jsx)(m5,{}),"shortcuts"===h&&(0,n.jsx)("ul",{className:"flex flex-col divide-y divide-border-subtle/40",children:tu.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:c(`shortcuts.${e.id}`)}),(0,n.jsx)("span",{className:"inline-flex items-center gap-1 flex-shrink-0",children:tg(e).map(e=>(0,n.jsx)("kbd",{className:tf,children:e},e))})]},e.id))}),"install"===h&&(0,n.jsx)(mj,{})]})]})]}),(0,n.jsx)(mR.A,{isOpen:S,onClose:()=>T(!1)}),(0,n.jsx)(ec.A,{isOpen:y,onClose:()=>w(!1),onConfirm:()=>{w(!1),X(j.shutdownHost)},title:c("menu.agentShutdownConfirmTitle"),message:c("menu.agentShutdownConfirmMsg")})]})}function mJ(e){let{title:t,children:s}=e;return(0,n.jsxs)("section",{children:[t&&(0,n.jsx)("h4",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-muted mb-2",children:t}),(0,n.jsx)("div",{className:"space-y-1",children:s})]})}function mY(e){let{icon:t,iconClass:s="",label:r,badge:l,danger:a,disabled:i,onClick:o}=e;return(0,n.jsxs)("button",{onClick:o,disabled:i,className:`w-full px-3 py-2 rounded-brand text-left flex items-center gap-2.5 text-sm transition-colors ${i?"text-text-muted cursor-not-allowed opacity-60":a?"text-text hover:bg-red-500/15 hover:text-red-400":"text-text hover:bg-surface-2"}`,children:[(0,n.jsx)(t,{size:16,className:`${a?"text-red-400":"text-brand-500 dark:text-white"} ${s}`}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:r}),l&&(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:l})]})}function mZ(e){let{icon:t,label:s,hint:r,value:l,loading:a,disabled:i,onChange:o}=e;return(0,n.jsxs)("button",{onClick:()=>{(0,ed.e)(),o(!l)},disabled:a||i,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)(t,{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:s}),r&&(0,n.jsx)("span",{className:"block text-xs text-text-muted truncate",children:r})]}),a?(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 ${l?"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 ${l?"translate-x-4 dark:bg-dark-800":"translate-x-0.5 dark:bg-white/50"}`})})]})}function mQ(e){let{icon:t,label:s,children:r}=e;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)(t,{size:16,className:"text-brand-500 dark:text-white flex-shrink-0"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:s}),r]})}function m0(e){let{icon:t,label:s,active:r,onClick:l}=e;return(0,n.jsxs)("button",{onClick:l,className:`px-3 py-3 rounded-brand flex items-center gap-2.5 text-sm border transition-colors ${r?"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)(t,{size:16}),(0,n.jsx)("span",{children:s})]})}let m1={"30m":"30 min","1h":"1 hour","2h":"2 hours","4h":"4 hours","24h":"24 hours",never:"Always",none:"Off"},m2={debug:"text-text-muted",info:"text-blue-400",warn:"text-amber-400",error:"text-red-400"};function m5(){let{t:e}=(0,eu.s)(),t=mX(e=>e.entries),[s,l]=(0,r.useState)("all"),[a,i]=(0,r.useState)("all"),o=(0,r.useRef)(null);(0,r.useEffect)(()=>(mX.getState().loadHostTail(),mX.getState().startHostTail(),()=>mX.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:()=>mX.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:()=>{mX.getState().clear(),(0,m.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 ${m2[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 m3(e){let{active:t=!1,dir:s="forward",className:l="",children:a}=e,[i,o]=(0,r.useState)(""),c=(0,r.useRef)(t),d=(0,r.useRef)(s);return(0,r.useEffect)(()=>{let e=t&&!c.current;c.current=t;let n=t&&d.current!==s;d.current=s,(e||n)&&o("back"===s?"tab-in-back":"tab-in-forward")},[t,s]),(0,n.jsx)("div",{className:`absolute inset-0 ${i} ${t?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none"} ${l}`,"aria-hidden":!t,inert:!t,onAnimationEnd:e=>{e.target===e.currentTarget&&o("")},children:a})}function m4(){let e,t,{t:s}=(0,eu.s)(),{formattedStars:l}=(0,nG.w)(),a=(0,f.B)(e=>{let t=e.viewStack[e.viewStack.length-1];return t?.type==="settings"}),i=ey(e=>e.isOpen)||a,o=(0,f.B)(e=>e.navDir),c=ey(e=>e.activePanel),d=ey(e=>e.context),m=ey(e=>e.callbacks),x=(0,u.d)(e=>e.carrier),p=ey(e=>e.close),h=ey(e=>e.setActivePanel);ey(e=>e.openMenu);let b=e0(e=>e.install),g=e0(e=>e.canInstall),v=e0(e=>e.isInstalled),[y,w]=(0,r.useState)(!1),[j,k]=(0,r.useState)(!1),[N,C]=(0,r.useState)(!1),[S,T]=(0,r.useState)(!1),[E,R]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=()=>R(window.innerWidth>=eg.jK);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,r.useEffect)(()=>(i?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[i]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&i&&p()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[i,p]);let M=(0,r.useCallback)(()=>h("pwa"),[h]),$=(0,r.useCallback)(()=>{(0,ed.e)(),h("menu")},[h]),z=(0,r.useCallback)(()=>{p(),m.onRemote?.()},[p,m]),P=(0,r.useCallback)(()=>{p(),m.onFiles?.()},[p,m]),A=(0,r.useCallback)(()=>{g?(p(),b()):M()},[g,p,b,M]),I=(0,r.useCallback)(()=>{p(),setTimeout(()=>{m.onLogout?.()},50)},[p,m]),D=(0,r.useCallback)(e=>{m.onThemeChange?.(e)},[m]);(0,r.useCallback)(()=>{p(),w(!0)},[p]);let L=(0,r.useCallback)(()=>{w(!1)},[]);(0,r.useCallback)(()=>{p(),k(!0)},[p]);let B=(0,r.useCallback)(()=>{k(!1)},[]),F=(0,r.useCallback)(()=>{p(),T(!0)},[p]),O=(0,r.useCallback)(()=>{T(!1)},[]),_=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mS,{isOpen:y,onClose:L}),(0,n.jsx)(mE,{isOpen:j,onClose:B}),(0,n.jsx)(m_,{isOpen:S,onClose:O,busRef:d.busRef})]});return E&&!i?_:E?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(mG,{context:d,callbacks:m,canInstall:g,isInstalled:v,install:b,onClose:p}),_]}):(0,n.jsxs)("div",{className:"fixed inset-0 z-30 flex pointer-events-none",children:[(0,n.jsx)(m3,{active:i,dir:o,className:"bg-bg z-30",children:(0,n.jsxs)("div",{className:"flex h-full w-full flex-col pt-[var(--safe-top)] pb-[var(--safe-bottom)]",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-4 pt-3 pb-2 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:["menu"!==c&&(0,n.jsx)("button",{onClick:$,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-[26px] font-bold tracking-[-0.4px] text-text truncate",children:(()=>{switch(c){case"pwa":return s("pwa.title");case"menu":return s("menu.settings");default:return s("menu.title")}})()})]}),"menu"===c&&(t=(e=x||d.carrier)&&"ws"!==e,(0,n.jsx)("span",{className:`shrink-0 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-1 overflow-y-auto modal-scrollable px-1 pt-1 pb-[94px]",children:["menu"===c&&(0,n.jsx)(mv,{onRemote:d.remoteAvailable?z:null,onFiles:P,onInstallApp:A,canInstall:g,isInstalled:v,onLogout:I,connected:d.connected,remoteAvailable:d.remoteAvailable,showTheme:d.showTheme,theme:d.theme,onThemeChange:D,hideActions:d.hideActions||[],busRef:d.busRef,subscribeToPush:d.subscribeToPush,unsubscribeFromPush:d.unsubscribeFromPush,onOpenBackgroundPicker:F,onOpenLanguage:()=>C(!0)}),"pwa"===c&&(0,n.jsx)(mj,{})]}),"menu"===c&&nJ.l7&&(0,n.jsx)("div",{className:"flex-shrink-0 flex justify-center px-3 pt-2",children:(0,n.jsxs)("a",{href:nJ.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"}),l&&(0,n.jsx)("span",{className:"font-mono text-[11px]",children:l})]})})]})}),(0,n.jsx)(mS,{isOpen:y,onClose:L}),(0,n.jsx)(mE,{isOpen:j,onClose:B}),(0,n.jsx)(m_,{isOpen:S,onClose:O,busRef:d.busRef}),(0,n.jsx)(mR.A,{isOpen:N,onClose:()=>C(!1)})]})}let m6={list:"sessions",remote:"remote",settings:"menu"};function m8(e){let{active:t="sessions",onSessions:s=null,onRemote:r=null,onMenu:l=null}=e,{t:a}=(0,eu.s)(),i=function(e,s,r,l){let a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],i=e===t;return(0,n.jsxs)("button",{type:"button",onClick:()=>{a||((0,ed.e)(),l?.())},disabled:a,className:`relative flex min-w-[68px] flex-col items-center gap-0.5 px-1.5 py-1 text-center text-[10px] font-medium transition-all duration-300 active:scale-90 disabled:opacity-40 ${i?"nav-tab-on -translate-y-0.5 font-bold text-[var(--nav-accent)]":"text-text-muted hover:text-[var(--nav-accent)]"}`,title:r,"aria-label":r,"aria-current":i?"page":void 0,children:[(0,n.jsx)("span",{className:"grid place-items-center",children:(0,n.jsx)(s,{size:21})}),(0,n.jsx)("span",{className:"whitespace-nowrap capitalize",children:r})]},e)};return(0,n.jsxs)("nav",{className:"glass-bar dock-rise fixed inset-x-0 bottom-[max(28px,calc(var(--safe-bottom)+16px))] z-40 mx-auto flex h-[54px] w-fit max-w-[calc(100vw-24px)] items-center justify-center gap-1 rounded-full px-4","aria-label":a("sessions.headerTitle"),children:[i("sessions",el.y8,a("hosts.sessions"),s),i("remote",el.VA,a("menu.remoteDesktop"),r,!r),i("menu",el.wB,a("menu.settings"),l)]})}function m9(){let e=ua(e=>e.pendingDevice),t=ua(e=>e.setPendingDevice),s=ua(e=>e.clearPendingDevice),l=ua(e=>e.touchBump),a=(0,r.useRef)(null);(0,r.useEffect)(()=>{a.current=e},[e]),(0,r.useEffect)(()=>{if(!(0,m.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 scrim fade-in",children:(0,n.jsxs)("div",{className:"card-elev p-5 flex flex-col gap-4 w-80 pop-in",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 m7=s(67841);function xe(e){let{hydrated:t,apiKey:s}=e;return!function(e){let t=(0,l.usePathname)(),s=(0,l.useSearchParams)(),n=(0,l.useRouter)(),{viewStack:a,pushView:i,setViewStack:o}=(0,f.B)((0,F.k)(e=>({viewStack:e.viewStack,pushView:e.pushView,setViewStack:e.setViewStack}))),c=a[a.length-1],d=to.yP.includes(c?.type)?a[a.length-2]:c,u=(0,r.useRef)(null),m=(0,r.useRef)(null),x=(0,r.useRef)(null),p=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!e)return;let n=(0,to.mn)(t,s);if(!n)return;let r=(0,to.O5)(n);if(r===u.current||(u.current=r,d&&(0,to.O5)(d)===r))return;p.current="url";let l=(0,to.dX)(a,n);l?o(l):i(n)},[e,t,s]),(0,r.useEffect)(()=>{if(!e)return;let r=f.B.getState().viewStack,l=r[r.length-1];if(!l||l!==c||to.yP.includes(l?.type))return;let a=(0,to.O5)(l);if(a===u.current)return;let i=(0,to.O5)((0,to.mn)(t,s)),o="url"===p.current;o&&(p.current=null);let d=m.current?.type==="terminal"&&l?.type==="terminal",h=to.x0.includes(l?.type)&&to.x0.includes(m.current?.type),b=l?.type==="list"&&1===r.length,g=r.length<x.current;p.current="store",u.current=a,m.current=l,x.current=r.length,o||a===i||(d||h||b||g?n.replace(a):n.push(a))},[e,c,t,s])}(t),(0,m7.H$)(s),null}function xt(e){let t,s,b,g,v,y,w,j,k,N,C,S,T,E,R,M,{children:$}=e,{t:K}=(0,eu.s)(),{theme:W}=(0,t7.D)(),[H,q]=(0,r.useState)(!1);(0,r.useEffect)(()=>{!function(){if(e1)return;e1=!0;let e=e0.getState();(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),e0.getState().setDeferredPrompt(e)}),window.addEventListener("appinstalled",()=>{e0.getState().setDeferredPrompt(null),e0.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:U,agentBySession:X,openedSessions:V,pushView:G,popView:J,setViewStack:Y,selectTab:Z,navDir:Q,addOpenedSession:ee,removeOpenedSession:et,reorderOpenedSessions:es,activeWorkspaceId:en,setActiveWorkspaceId:el,livePanes:ea,touchLivePane:ei,mountedWorkspaces:ed,markWorkspaceMounted:ex,reset:ep,cwdBySession:ev,sidebarCollapsed:ew,toggleSidebar:ej,sidebarWidth:eN,setSidebarWidth:eT,paneWidths:eE,setPaneWidth:eR,rightPanelOpen:e$,rightPanelTabs:ez,rightPanelWidth:eP,toggleRightPanel:eA,setRightPanelTab:eD,setRightPanelWidth:eL,editorFilePath:eB,editorJump:e_,editorPanelWidth:eK,setEditorPanelWidth:eW,openEditorFile:eH,closeEditorFile:eq,editorPreviewSeq:eU,mobileOpen:eX,mobileMode:eV,mobilePanelWidth:eG,setMobileOpen:eJ,setMobileMode:eQ,setMobilePanelWidth:e3,setMobileSession:e4,artifactTitle:e6,pushArtifact:e8,removeArtifact:e9}=(0,f.B)((0,F.k)(e=>({viewStack:e.viewStack,openedSessions:e.openedSessions,pushView:e.pushView,popView:e.popView,setViewStack:e.setViewStack,selectTab:e.selectTab,navDir:e.navDir,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,agentBySession:e.agentBySession}))),tt=(0,l.useRouter)(),{getAuth:ts,setAuth:tn,clearAuth:tr}=(0,a.Fo)(),[tl,tc]=(0,r.useState)(()=>ts()),tu=(0,u.d)(e=>e.authKey);(0,r.useEffect)(()=>{tu&&tc(ts())},[tu,ts]),(0,r.useEffect)(()=>{q(!0),!tl?.apiKey&&(0,m._r)()&&window.location.port===String(x._8)&&fetch(x.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,h.LG)(s,{tail:n});let r={apiKey:s,tunnelUrl:window.location.origin,mode:"local",tempKey:null,localIp:null};tn(r),tc(r)}}).catch(()=>{})},[tl,tn]),(0,r.useEffect)(()=>(function(){if(!function(){if("object"!=typeof navigator)return!1;let e=navigator.userAgent||"";return/Mac/.test(navigator.platform||e)&&e.includes("AppleWebKit")&&!e.includes("Chrome")}())return()=>{};let e=null,t=null,s=null,n=e=>"mouse"===e.pointerType&&0===e.button,r=(t,s)=>8>=Math.hypot(t-e.x,s-e.y),l=(e,t,s,n,r)=>{t.dispatchEvent(new MouseEvent(e,{bubbles:!0,cancelable:!0,composed:!0,clientX:n,clientY:r,button:0,detail:s}))},a=()=>{let{target:t,x:n,y:r}=e;e.clicked=!0;let a=performance.now(),i=s&&a-s.at<=500&&s.target===t;e.synth=!0,l("click",t,i?2:1,n,r),i?(l("dblclick",t,2,n,r),s=null):s={target:t,at:a},e.synth=!1},i=()=>{!e||e.clicked||e.moved||!e.up||e.target.isConnected&&a()},o=()=>{clearTimeout(e.timer),e.timer=setTimeout(i,0)},c=s=>{if(!n(s)){t=null;return}let r=t&&performance.now()-t.at<=100&&8>=Math.hypot(s.clientX-t.x,s.clientY-t.y);t=null,clearTimeout(e?.timer),e={target:s.target,x:s.clientX,y:s.clientY,moved:!1,up:!!r,clicked:!1,synth:!1,timer:null},r&&o()},d=t=>{e&&!e.moved&&Math.hypot(t.clientX-e.x,t.clientY-e.y)>8&&(e.moved=!0)},u=s=>{if(n(s)){if(!e||e.up||e.clicked){t={x:s.clientX,y:s.clientY,target:s.target,at:performance.now()};return}r(s.clientX,s.clientY)?(e.up=!0,o()):e.moved=!0}},m=t=>{if(0!==t.button||!e||e.synth)return;if(e.clicked){r(t.clientX,t.clientY)&&t.stopPropagation();return}if(e.moved||!r(t.clientX,t.clientY))return;let s=t.target;s===e.target||e.target.contains(s)?e.clicked=!0:s.contains(e.target)&&e.target.isConnected?(t.stopPropagation(),t.preventDefault(),a()):e.clicked=!0},x=()=>{clearTimeout(e?.timer),e=null,t=null};return window.addEventListener("pointerdown",c,!0),window.addEventListener("pointermove",d,!0),window.addEventListener("pointerup",u,!0),window.addEventListener("pointercancel",x,!0),window.addEventListener("click",m,!0),()=>{clearTimeout(e?.timer),window.removeEventListener("pointerdown",c,!0),window.removeEventListener("pointermove",d,!0),window.removeEventListener("pointerup",u,!0),window.removeEventListener("pointercancel",x,!0),window.removeEventListener("click",m,!0)}})(),[]),(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:tx,busRef:th,protocolRef:tf,disconnect:tb,reconnect:tg,connected:tw,connectionMode:tN,carrier:tC,remoteAvailable:tS,mobileAvailable:tT,platform:tE,hostVersion:tR,agentVersion:tM,retryStatus:t$,approvalStatus:tz,admitted:tP,hostOffline:tA,loadSessions:tI,createSession:tD,deleteSession:tL,renameSession:tB,createWorkspace:tF,renameWorkspace:tO,deleteWorkspace:t_,setWorkspaceHiddenRepos:tK,reorderSession:tW}=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),T=(0,u.d)(e=>e.hostOffline),{getAuth:E}=(0,a.Fo)(),R=(0,r.useCallback)(e=>{u.d.getState().applyApproval(e)},[]),M=(0,r.useCallback)(async()=>{let e=E();if(e?.tempKey)try{await fetch(`${x.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)}},[E]),$=(0,r.useRef)(null),F=(0,r.useRef)({sessions:!1,workspaces:!1}),O=e=>{F.current[e]=!0},_=(0,r.useCallback)(e=>{(0,L.Lq)("switch",`lists untrusted (${e}) → refetch`),F.current={sessions:!1,workspaces:!1}},[]),K=(0,r.useCallback)(e=>{if(!Array.isArray(e))return;for(let t of(O("sessions"),e))t?.id&&t?.agent&&f.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;O("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})},[]),H=(0,r.useRef)(0),q=(0,r.useRef)(0),U=(0,r.useRef)(null),X=(0,r.useRef)(0),V=(0,r.useCallback)(e=>{let t=++H.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===H.current&&K(e)})},[K]),G=(0,r.useCallback)(e=>{let t=++q.current;e.emit("getWorkspaces",e=>{t===q.current&&W(e)})},[W]),J=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e){if(t)clearTimeout(U.current);else if(U.current)return;else if(Date.now()-X.current<1e3)return;U.current=setTimeout(()=>{U.current=null,X.current=Date.now(),(0,L.Lq)("diag",`fetchLists FIRE (bus=${e?"ok":"null"} connected-already=${F.current.sessions}/${F.current.workspaces})`),G(e),V(e)},120)}},[V,G]),Y={fragOut:!0,binOut:!0,hb:1,env2:1,fragCtl:1,seqCtl:1},Z=e=>{(0,L.Lq)("switch",`caps → ${JSON.stringify(Y)} announced`),e.emit("caps",Y)},Q=(0,r.useRef)(null),{bus:ee,busRef:et,protocolRef:es,connected:en,connectionMode:er,carrier:el,retryStatus:ea,disconnect:ei,reconnect:eo}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{namespace:t="",socketOptions:s={},redirectOnNoAuth:n="/",onConnect:f,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,E]=(0,r.useState)("tunnel"),[R,M]=(0,r.useState)("ws"),[$,z]=(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(),C=(0,m._r)(),T=i?.apiKey&&i.tunnelUrl===window.location.origin;if(C&&window.location.port===String(x._8)&&(!P&&i?.tunnelUrl!==window.location.origin||T))try{let e=await fetch(x.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);(i?.apiKey!==s||(0,h.lz)(s)?.tail!==n)&&((0,h.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 R={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}),u.d.getState().setHostOffline(!1);let n=s||N.current?.connectionMode||"tunnel";S(!0),E(n),u.d.getState().setConnection({bus:t,connected:!0,connectionMode:n,endpoint:i.tunnelUrl}),(0,d.c)("transport","[transport] ws connected"),f?.(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,onHostOffline:()=>{e||((0,d.c)("transport","[transport] worker says host offline"),u.d.getState().setHostOffline(!0))},onRetryStatus:t=>{e||(z(t),u.d.getState().setRetryStatus(t))}},$=i.tunnelUrl===window.location.origin,I=c.eR.enableWebRTC&&!$?{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||(M(t),u.d.getState().setCarrier(t),(0,d.c)("transport",`[transport] active=${t}`))}}:null;N.current=r=new o.g(R,I),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:R,retryStatus:$,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{}u.d.getState().setHostOffline(!1),D(e=>e+1)}}}({namespace:"",redirectOnNoAuth:"/login",onConnect:(0,r.useCallback)((e,s)=>{(R(A.J2.reconnect),B({status:"full"}),_("pm-connect"),Q.current===e)?J(e):(Q.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,h.I8)(),M()}),e.on("terminal:ready",()=>{(0,d.c)("auth","[auth] terminal:ready (NOT an admission signal)"),J(e)}),e.on("connect",()=>{_("carrier-connect"),e.emit("device:clientReady"),Z(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=E();(0,h.cH)(t?.apiKey),(0,h.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,remoteStatus:e.remoteStatus||null,mobileAvailable:!!e.mobileAvailable}),g(e.remoteAvailable),y(!!e.mobileAvailable),j(e.platform),N(e.version||null),f.B.getState().setAgentCaps(e.caps||{}),f.B.getState().setArtifactEnabled(e.artifactEnabled),f.B.getState().setMcpClients(e.mcpClients),e.voiceConfig&&z.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)}),f.B.getState().closeSession(e)}),e.on("session-renamed",function(){let{sessionId:e,name:s}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};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",function(){let{sessionId:e,agent:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e&&t&&(f.B.getState().setSessionAgent(e,t),f.B.getState().invalidateAgentHistory())}),e.on("sessionsChanged",()=>J(e,!0)),e.on("workspacesChanged",()=>J(e)),Z(e),u.d.getState().setConnection({approvalStatus:null}),e.emit("device:clientReady"))},[M,J,R,E,_]),onDisconnect:()=>{let e=P.rh.getState();e.hosts[e.currentKey]?.status==="full"&&B({status:"connecting"})},onApproval:R});(0,r.useEffect)(()=>{$.current=ei},[ei]);let ec=(0,r.useCallback)(()=>J(et.current),[et,J]),ed=(0,r.useCallback)(()=>J(et.current,!0),[et,J]);(0,r.useEffect)(()=>()=>{U.current&&(clearTimeout(U.current),U.current=null)},[]),(0,r.useEffect)(()=>{if(!en)return;let e=setInterval(()=>{F.current.sessions&&F.current.workspaces||ec()},2e3);return()=>clearInterval(e)},[en,ec]),(0,r.useEffect)(()=>{if(!en)return;let e=()=>{"visible"===document.visibilityState&&ec()};return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[en,ec]);let eu=(0,r.useCallback)(function(e,n,r,l,a){let i=arguments.length>5&&void 0!==arguments[5]&&arguments[5],o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,c=arguments.length>7&&void 0!==arguments[7]?arguments[7]:null;if(!et.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;et.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&&f.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(),m=u.hosts[u.currentKey]?.sessions;m&&B({sessions:c(m)})}ed()}a?.(i)})},[et,ed,s]),em=(0,r.useCallback)((e,t,s)=>{"function"==typeof t&&(s=t,t=null),et.current?.emit("createWorkspace",{name:e,path:t},e=>{e?.success&&ed(),s?.(e)})},[et,ed]),ex=(0,r.useCallback)((e,t,s)=>{et.current?.emit("renameWorkspace",{workspaceId:e,name:t},e=>{e?.success&&ed(),s?.(e)})},[et,ed]),ep=(0,r.useCallback)((e,t)=>{et.current?.emit("deleteWorkspace",{workspaceId:e},e=>{e?.success&&ed(),t?.(e)})},[et,ed]),eh=(0,r.useCallback)((e,t,s)=>{et.current?.emit("setWorkspaceHiddenRepos",{workspaceId:e,paths:t},e=>{e?.success&&ed(),s?.(e)})},[et,ed]),ef=(0,r.useCallback)((e,t,s)=>{et.current?.emit("moveSession",{sessionId:e,workspaceId:t},e=>{e?.success&&ed(),s?.(e)})},[et,ed]),eb=(0,r.useCallback)((e,t)=>{et.current?.emit("reorderSession",{orderedIds:e},e=>{e?.success&&ed(),t?.(e)})},[et,ed]),eg=(0,r.useCallback)(e=>{et.current&&et.current.emit("getShells",t=>e?.(t))},[et]),ev=(0,r.useCallback)((e,t)=>{et.current&&et.current.emit("deleteSession",e,e=>{e.success&&ed(),t?.(e)})},[et,ed]),ey=(0,r.useCallback)((e,t,s)=>{et.current&&et.current.emit("renameSession",{sessionId:e,name:t},e=>{e.success&&ed(),s?.(e)})},[et,ed]);return{bus:ee,busRef:et,protocolRef:es,disconnect:ei,reconnect:eo,connected:en,connectionMode:er,carrier:el,retryStatus:ea,approvalStatus:C,admitted:S,hostOffline:T,sessions:e,remoteAvailable:b,mobileAvailable:v,platform:w,hostVersion:k,agentVersion:k,workspaces:s,loadSessions:ec,createSession:eu,getShells:eg,deleteSession:ev,renameSession:ey,createWorkspace:em,renameWorkspace:ex,deleteWorkspace:ep,setWorkspaceHiddenRepos:eh,moveSession:ef,reorderSession:eb}}(),{loadKeys:tH,saveKey:tq,renameKey:tU,removeKey:tX}=(0,rY.u)(),[tV,tG]=(0,r.useState)([]);(0,r.useEffect)(()=>{H&&tG(tH())},[H,tH]),(0,r.useEffect)(()=>{if(!H)return;let e=()=>tG(tH());return window.addEventListener(rY.N,e),()=>window.removeEventListener(rY.N,e)},[H,tH]);let tJ=tl?.apiKey?(0,p.Uo)(tl.apiKey):"",tY=eC(tJ||null);(0,r.useEffect)(()=>{if(H){if(!tJ)return void P.rh.getState().closeAll();P.rh.getState().sync(tV,tJ)}},[H,tV,tJ]);let tZ=(0,P.rh)(e=>e.hosts),tQ=tZ[tJ],t0=(0,r.useMemo)(()=>tQ?.sessions||[],[tQ]),t1=(0,r.useMemo)(()=>tQ?.workspaces||[],[tQ]),t2=(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(tZ),tJ),[tZ,tJ]),t3=(0,r.useMemo)(()=>[...t0,...t2.sessions],[t0,t2]),t6=(0,r.useMemo)(()=>[...t1,...t2.workspaces],[t1,t2]),t8=(0,r.useCallback)((e,t)=>{let s=tH().find(t=>(0,p.Uo)(t.key)===e);s?tU(s.id,t):tq(e,t)},[tH,tU,tq]),[t9,se]=(0,r.useState)([]),st=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}(),ss=(0,u.d)(e=>e.bus),sn=(0,u.d)(e=>e.deliberate),sr=(0,u.d)(e=>e.everConnected),sl=!!tQ?.updating,sa=(0,r.useRef)({armed:!1,version:null,dropped:!1});(0,r.useEffect)(()=>{if(!tQ||!tJ)return;let e=sa.current;if(!tQ.updating){e.armed=!1,e.dropped=!1;return}if(e.armed||(e.armed=!0,e.version=tQ.version||null),tw||(e.dropped=!0),e.dropped&&tw){let t=setTimeout(()=>{let t=P.rh.getState().hosts[tJ];t?.version&&e.version&&t.version!==e.version?window.location.reload():P.rh.getState()._patchHost(tJ,{updating:!1})},1500);return()=>clearTimeout(t)}},[tQ,sl,tw,tJ]);let[si,so]=(0,r.useState)({isOpen:!1,title:"",message:"",onConfirm:null,confirmText:null});(0,r.useEffect)(()=>{tw&&("win32"===tE?se([{id:"cmd",label:"Command Prompt"},{id:"powershell",label:"PowerShell"}]):se([]))},[tw,tE]);let sc=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=eM(t===e.currentKey?null:t).bus;if(!s)continue;let r=e=>{let{count:s}=e;return P.rh.getState()._patchHost(t,{mobileDeviceCount:Number(s)||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:sd,unsubscribeFromPush:su,notifications:sm}=(s=(0,r.useRef)(null),b=ek(e=>e.notifications),(0,f.B)(e=>e.getSelectedSession),(0,f.B)(e=>e.getCurrentView),g=(0,f.B)(e=>e.pushView),v=(0,f.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(th?.current&&e(th.current),Object.values(P.rh.getState().hosts))){if("online"!==t.status)continue;let s=(0,P.eJ)(t.key);s&&e(s)}},[th]),(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}}},[th,y,j]),k=(0,r.useCallback)(async()=>{if(th?.current){if(localStorage.removeItem(eO),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=>th.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)}}},[th,y]),(0,r.useEffect)(()=>{let e=th?.current;if(e&&tw&&"1"!==localStorage.getItem(eO)){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){}})()}},[th,tw,y]),(0,r.useEffect)(()=>{s.current&&"1"!==localStorage.getItem(eO)&&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=th?.current;if(!e||!tw)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(ek.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=>ek.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)}},[th,tw]),N=eI(),C=(0,r.useMemo)(()=>eF(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(eO,"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)}},[th,j]),notifications:b}),sx=O(e=>e.setKeyboardOpen),[sp,sh]=(0,r.useState)(()=>window.innerWidth>=eg.jK),sf=(S=(0,r.useRef)(null),(0,r.useCallback)(e=>{let{enabled:t,sessionIds:s,activeSessionId:n,onSwitch:r}=e;return{onTouchStart:e=>{if(!t||1!==e.touches.length||function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e2;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}(e.target))return S.current=null;let s=e.touches[0];S.current={x:s.clientX,y:s.clientY,time:performance.now()}},onTouchEnd:e=>{let l=S.current;if(S.current=null,!l||!t||s.length<2)return;let a=e.changedTouches[0],i=a.clientX-l.x,o=a.clientY-l.y;if(performance.now()-l.time>eg.bl.maxDuration||Math.abs(i)<eg.bl.minDistance||Math.abs(i)<Math.abs(o)*eg.bl.ratio)return;let c=s.indexOf(n);if(-1===c)return;let d=i<0?s[c+1]:s[c-1];d&&d!==n&&r?.(d)}}},[]));(0,r.useEffect)(()=>{let e=0,t=()=>{clearTimeout(e),e=setTimeout(()=>sh(window.innerWidth>=eg.jK),50)};return window.addEventListener("resize",t),()=>{clearTimeout(e),window.removeEventListener("resize",t)}},[]);let sb=U[U.length-1]||{type:"list"},sg=sb?.type==="terminal"||sp&&sb?.type==="list",sv=sb?.type==="browser",sy=en??"default",[sw,sj]=(0,r.useState)({}),sk=sb?.hostKey??null;(0,r.useEffect)(()=>{sv&&sj(e=>e[sy]===sk?e:{...e,[sy]:sk})},[sv,sy,sk]);let sN=void 0!==sw[sy],sC=sv?sk:sw[sy]??null,sS=tZ[sC],sT=nc(e=>e.workspaceProfiles[en??"default"]||"default"),sE=sb?.type==="terminal"?sb.sessionId:sg&&V[V.length-1]||null,sR=function(e){let{isDesktop:t,isTerminalView:s,activeSessionId:n,currentView:l,openedSessions:a}=e,i=(0,r.useRef)({}),o=(0,r.useRef)({}),c=(0,r.useRef)(null),d=(0,r.useRef)(null),u=(0,r.useRef)(!1),m=(0,r.useRef)(null),x=(0,r.useCallback)((e,s)=>{s?(i.current[e]=s,m.current===e&&t&&!u.current&&(m.current=null,setTimeout(()=>s.focus?.(),50))):delete i.current[e]},[t]),p=(0,r.useCallback)((e,t)=>{t?o.current[e]=t:delete o.current[e]},[]),h=(0,r.useCallback)(e=>{d.current=e,e&&m.current&&t&&u.current&&(m.current=null,setTimeout(()=>e.focus?.(),50))},[t]),b=(0,r.useCallback)(e=>{t&&(m.current=e,setTimeout(()=>{m.current===e&&(m.current=null,u.current&&d.current?.focus?d.current.focus():i.current[e]?.focus?.())},60))},[t]),g=(0,r.useCallback)(()=>{d.current?.openTextPanel?.()},[]),v=(0,r.useCallback)(e=>{u.current=e},[]),y=(0,r.useCallback)(e=>i.current[e]?.focus?.(),[]),w=(0,r.useCallback)(()=>{d.current?.focus?.()},[]),j=(0,r.useCallback)(e=>{u.current?i.current[e]?.focus?.():d.current?.focus?.()},[]),k=(0,r.useRef)(0),N=(0,r.useCallback)(e=>{if(!t)return;if(f.B.getState().fullMode){c.current&&(c.current.scrollLeft=0);return}cancelAnimationFrame(k.current),k.current=0;let s=c.current,n=(0,e5.g4)({container:s,pane:o.current[e]});if(null==n){k.current=requestAnimationFrame(()=>{k.current=0;let t=(0,e5.g4)({container:s,pane:o.current[e]});null!=t&&s.scrollTo({left:t,behavior:"smooth"})});return}s.scrollTo({left:n,behavior:"smooth"})},[t]),C=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!t||l?.type!=="terminal"||!l?.sessionId||C.current===l.sessionId)return;C.current=l.sessionId;let e=requestAnimationFrame(()=>N(l.sessionId));return()=>cancelAnimationFrame(e)},[l?.type,l?.sessionId,t,N]),(0,r.useEffect)(()=>{if(!t||!s||!n)return;let e=setTimeout(()=>{u.current?d.current?.focus?.():i.current[n]?.focus?.()},60);return()=>clearTimeout(e)},[n,t,s]),(0,r.useMemo)(()=>({panesContainerRef:c,registerPaneApi:x,registerPaneElement:p,registerKeyboardTextApi:h,handlePasteFallback:g,handleInputFocusChange:v,focusPane:y,focusKeyboardInput:w,toggleInputFocus:j,scrollPaneIntoView:N,requestFocus:b}),[x,p,h,g,v,y,w,j,N,b])}({isDesktop:sp,isTerminalView:sg,activeSessionId:sE,currentView:sb,openedSessions:V}),sM=function(e){let{sessions:t,currentView:s,viewStack:n,setViewStack:l,pushView:a,storePopView:i,activeWorkspaceId:o,setActiveWorkspaceId:c,activeSessionId:d,addOpenedSession:u,removeOpenedSession:m,touchLivePane:x,createSession:p,deleteSession:h,renameSession:b,busRef:g,isDesktop:v=!1,requestFocus:y=null}=e,{t:w}=(0,eu.s)(),j=(0,r.useCallback)(e=>{let t=[...n];t[t.length-1]={type:"terminal",sessionId:e},l(t)},[n,l]),k=(0,r.useCallback)(e=>t.filter(t=>(0,e5.xs)(t)===(e??null)).map(e=>e.id),[t]),N=(0,r.useCallback)(e=>alert(w("workspace.failedCreateSession",{error:e})),[w]),C=(0,r.useCallback)((e,n)=>{let r=t.find(t=>t.id===e);if(!r&&void 0===n)return;let l=r?(0,e5.xs)(r):n;c(l);let i=k(l);i.forEach(e=>u(e)),u(e),x([...i,e]),"terminal"===s.type?j(e):a({type:"terminal",sessionId:e}),r||y?.(e)},[t,k,u,x,c,s,a,j,y]);(0,r.useEffect)(()=>{let e=e=>{if(e.data?.type!=="NOTIFICATION_CLICK")return;let t=new URLSearchParams(new URL(e.data.url||"",location.origin).search).get("t");t&&C(t)},s=()=>{let e=Object.values(ek.getState().notifications||{}).filter(e=>"blocked"===e.type);if(!e.length)return;let s=e=>{let s=t.find(t=>t.id===e);return s&&(0,e5.xs)(s)===(o??null)},n=e.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&&C(n.sessionId)};return window.addEventListener("message",e),window.addEventListener("9remote:dock-click",s),()=>{window.removeEventListener("message",e),window.removeEventListener("9remote:dock-click",s)}},[C,t,o]),(0,r.useEffect)(()=>{let e=e=>{e.detail?.sessionId&&C(e.detail.sessionId)};return window.addEventListener(eg.vP,e),()=>window.removeEventListener(eg.vP,e)},[C]);let S=(0,r.useCallback)(e=>{let t=k(o);if(t.length<2)return;let s=t.indexOf(d);if(-1===s)return;let n="prev"===e?(s-1+t.length)%t.length:(s+1)%t.length;C(t[n])},[k,o,d,C]),T=(0,r.useCallback)(e=>{let t=k(o);e<0||e>=t.length||C(t[e])},[k,o,C]),E=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i=arguments.length>5&&void 0!==arguments[5]&&arguments[5],o=arguments.length>6&&void 0!==arguments[6]&&arguments[6];p(e,n,t,r||null,e=>{if(!e?.success)return N(e?.error);if(!e.sessionId)return;let n=e7(l,i);n&&f.B.getState().queueStartup(e.sessionId,n),l?.id&&f.B.getState().setSessionAgent(e.sessionId,l.id);let r=t??null;c(r);let o=k(r);o.forEach(e=>u(e)),u(e.sessionId),x([...o,e.sessionId]),"terminal"===s.type?j(e.sessionId):a({type:"terminal",sessionId:e.sessionId}),y?.(e.sessionId)},o,l)},[p,k,u,x,N,s,j,a,c,y]),R=(0,r.useCallback)(e=>{if(!e?.resume)return;let t="ui"===e.mode,n=P.rh.getState().currentKey||"main",r=f.B.getState().agentClisBy[n]?.list?.find(t=>t.id===e.agent)||null,l=t?null:te(r,e.resume);p(null,null,o,e.cwd||null,n=>{if(!n?.success)return N(n?.error);if(!n.sessionId)return;l&&f.B.getState().queueStartup(n.sessionId,l);let r=t?`${e.agent}-ui`:e.agent;r&&f.B.getState().setSessionAgent(n.sessionId,r),g?.current?.emit("claimAgentSession",{sessionId:n.sessionId,agent:r,conversationId:e.sessionId},()=>f.B.getState().invalidateAgentHistory()),u(n.sessionId),x(n.sessionId),"terminal"===s.type?j(n.sessionId):a({type:"terminal",sessionId:n.sessionId}),y?.(n.sessionId)})},[p,o,u,x,N,j,a,s,y,g]),M=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,l=arguments.length>4&&void 0!==arguments[4]&&arguments[4];p(r,e,o,null,e=>{if(!e?.success)return N(e?.error);if(!e.sessionId)return;let r=e7(t,n);r&&f.B.getState().queueStartup(e.sessionId,r),t?.id&&f.B.getState().setSessionAgent(e.sessionId,t.id),u(e.sessionId),x(e.sessionId),"terminal"===s.type?j(e.sessionId):a({type:"terminal",sessionId:e.sessionId}),y?.(e.sessionId)},l,t)},[p,o,u,x,N,j,a,s,y]),$=(0,r.useCallback)(function(e,n){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=arguments.length>3&&void 0!==arguments[3]&&arguments[3];p(n,null,o,t.find(t=>t.id===e)?.cwd||null,t=>{if(!t?.success)return N(t?.error);if(!t.sessionId)return;let n=t.replaced||e;r?.id&&f.B.getState().setSessionAgent(t.sessionId,r.id),n?f.B.getState().replaceOpenedSession(n,t.sessionId):u(t.sessionId),x(t.sessionId),"terminal"===s.type?j(t.sessionId):a({type:"terminal",sessionId:t.sessionId}),y?.(t.sessionId)},l,r,e)},[p,o,N,u,x,j,a,s,y,t]),z=(0,r.useCallback)(e=>{p(null,t=>{if(!t.success)return N(t.error);t.sessionId&&(u(t.sessionId),e?.(t.sessionId))})},[p,u,N]),A=(0,r.useCallback)(e=>{c(e);let s=t.filter(t=>(0,e5.xs)(t)===(e??null));s.forEach(e=>u(e.id)),x(s.map(e=>e.id));let n=s[0];n&&j(n.id)},[t,c,u,x,j]),I=(0,r.useCallback)(e=>{let n=t.find(t=>t.id===e),r=(0,e5.xs)(n),a=s?.type==="terminal"&&s.sessionId===e,o=()=>{m(e),f.B.getState().closeSession(e);let n=t.filter(t=>t.id!==e);if(!v&&!n.length&&to.yP.includes(s?.type))return void l([{type:"list"}]);if(!a)return;let o=n.filter(e=>(0,e5.xs)(e)===r)[0]||n[0];o?(j(o.id),x(o.id)):i()},c=n?.hostKey?P.rh.getState().hosts[n.hostKey]:null;if(c){ti(c).deleteSession(e),o();return}h(e,o)},[t,s,v,l,h,m,x,i,j]),D=(0,r.useCallback)((e,s)=>{let n=t.find(t=>t.id===e)?.hostKey;if(n){let t=P.rh.getState().hosts[n];t&&ti(t).renameSession(e,s);return}b(e,s,e=>{e.success||alert(w("workspace.failedRenameSession",{error:e.error}))})},[t,b,w]);return(0,r.useMemo)(()=>({handleSelectSession:C,handleSelectWorkspace:A,handleCreateSession:E,handleQuickCreateSession:M,handleReplaceSession:$,handleResumeAgentSession:R,handleCreateSessionInline:z,handleDeleteSession:I,handleRenameSession:D,switchSession:S,switchToIndex:T}),[C,A,E,M,$,R,z,I,D,S,T])}({sessions:t3,currentView:sb,viewStack:U,setViewStack:Y,pushView:G,storePopView:J,activeWorkspaceId:en,setActiveWorkspaceId:el,activeSessionId:sE,addOpenedSession:ee,removeOpenedSession:et,touchLivePane:ei,createSession:tD,deleteSession:tL,renameSession:tB,busRef:th,isDesktop:sp,requestFocus:sR.requestFocus}),{systemInfo:s$,mobileEditor:sz,setMobileEditor:sP,openFileRef:sA,handleOpenWorkspaceList:sI,handleOpenFiles:sD,handleSelectWorkspace:sL,handleBrowseFolder:sB,handlePathChange:sF,handleOpenFile:sO,handleOpenGit:s_,handleSetWorkspace:sK}=function(e){let{pushView:t,viewStack:s,setViewStack:n,currentView:l,cwdBySession:a,sessions:i=[],isDesktop:o,fileBus:c,scope:d=""}=e,[u,m]=(0,r.useState)(null),[x,p]=(0,r.useState)(null),h=(0,r.useRef)(null),f=(0,r.useCallback)(async()=>{if(!u){let e=await c.getSystemInfo();e.success&&m(e)}t({type:"workspaces"})},[t,c,u]),b=(0,r.useCallback)(async e=>{if(e){ef(e,d),t({type:"files",workspace:e,currentPath:e});return}if("terminal"===l.type){let e=l.sessionId&&(a[l.sessionId]||i.find(e=>e.id===l.sessionId)?.cwd)||null;if(e){ef(e,d),t({type:"files",workspace:e,currentPath:e});return}}let s=eh(d);if(s.length>0){let e=s[0];t({type:"files",workspace:e.path,currentPath:e.lastPath||e.path});return}f()},[t,f,l,a,i,d]),g=(0,r.useCallback)(e=>{ef(e,d),n([...s.filter(e=>"workspaces"!==e.type&&"files"!==e.type),{type:"files",workspace:e}])},[s,n]),v=(0,r.useCallback)(e=>{t({type:"browse",path:e})},[t]),y=(0,r.useCallback)((e,t)=>{!function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=(0,_.kb)(e),r=eh(s),l=r.findIndex(e=>e.path===n);-1!==l&&(r[l]={...r[l],lastPath:(0,_.kb)(t)},localStorage.setItem(em(s),JSON.stringify(r)))}(e,t,d)},[]),w=(0,r.useCallback)(function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};o?h.current?.(e,s):p({path:e,line:s.line,column:s.column,workspace:l.workspace})},[o,l.workspace]);return{systemInfo:u,mobileEditor:x,setMobileEditor:p,openFileRef:h,handleOpenWorkspaceList:f,handleOpenFiles:b,handleSelectWorkspace:g,handleBrowseFolder:v,handlePathChange:y,handleOpenFile:w,handleOpenGit:(0,r.useCallback)(()=>{let e=s.find(e=>"files"===e.type);e?.workspace&&t({type:"git",workspace:e.workspace})},[t,s]),handleSetWorkspace:(0,r.useCallback)(e=>{ef(e,d),n([...s.filter(e=>"browse"!==e.type&&"workspaces"!==e.type&&"files"!==e.type),{type:"files",workspace:e}])},[s,n])}}({pushView:G,viewStack:U,setViewStack:Y,currentView:sb,cwdBySession:ev,sessions:t0,isDesktop:sp,fileBus:sc,scope:tY}),[sW,sH]=(0,r.useState)(null),sq=ey(e=>e.open),sU=(0,r.useMemo)(()=>H?eh(tY):[],[H,t1,tY]),sX=(0,r.useCallback)(e=>{sH(null),e&&tF(e.split("/").filter(Boolean).pop()||e,e,t=>{let s=t?.workspace||t?.group;t?.success&&s?.id&&(ef(e,tY),el(s.id),sM.handleCreateSession(null,s.id,null,e))})},[tF,el,sM]),sV=(0,r.useCallback)(e=>{if(e)return sX(e);sH({initialPath:null})},[sX]),sG=(0,r.useCallback)((e,t,s,n,r,l,a)=>{let i=t6.find(e=>e.id===t)?.hostKey||Object.values(tZ).find(e=>"string"==typeof t&&t.startsWith(`${e.key}:`))?.key;if(i){let o=P.rh.getState().hosts[i];if(!o)return;ti(o,{onSelectSession:sM.handleSelectSession}).createSession(e,eS(t,i),s,n,r,l,a);return}sM.handleCreateSession(e,t,s,n,r,l,a)},[t6,tZ,sM]),sJ=(0,r.useCallback)(e=>{let t=t3.find(e=>e.id===sE)?.hostKey||t6.find(e=>e.id===en)?.hostKey;if(!t||!e?.resume)return;let s=P.rh.getState().hosts[t];if(!s)return;let n="ui"===e.mode,r=f.B.getState().agentClisBy[t]?.list?.find(t=>t.id===e.agent)||null,l=n?null:te(r,e.resume),a=n?`${e.agent}-ui`:e.agent,i=eS(en,t);ti(s,{onSelectSession:sM.handleSelectSession}).createSession(null,i&&"_"!==i?i:null,null,e.cwd||null,null,!1,!1,s=>{s?.success&&s.sessionId&&(l&&f.B.getState().queueStartup(s.sessionId,l),a&&f.B.getState().setSessionAgent(s.sessionId,a),(0,P.Nw)(t,t=>t.emit("claimAgentSession",{sessionId:s.sessionId,agent:a,conversationId:e.sessionId},()=>f.B.getState().invalidateAgentHistory())))})},[t3,t6,sE,en,sM]),sY=(0,r.useCallback)(e=>{sG(null,en,null,e)},[sG,en]),sZ=t6.find(e=>e.id===en)?.hostKey||null,sQ=sZ||tJ||"main",s0=tk(eM(sZ).busRef,sQ),s1=tj(e=>e.open),s2=tj(e=>e.isOpen),s5=tj(e=>e.close),[s3,s4]=(0,r.useState)(!1),s6=t1.find(e=>e.id===en)?.path||t0.find(e=>e.id===sE)?.workspacePath||null,s8=(0,r.useCallback)(()=>{let{agentId:e,shellId:t,yolo:s}=ta(),n=(s0||[]).flatMap(e=>{let t=t5.find(t=>t.aiEngine===e.id);return t?[e,t]:e}),r=e&&n.find(t=>t.id===e)||null,l=t3.filter(e=>(0,e5.xs)(e)===(en??null)).length+1;sG(r?`${r.short||r.label} ${l}`:null,en,r?null:t,null,r,s,!0)},[s0,t3,en,sG]),s9=(0,r.useCallback)(e=>{let t=t1.map(e=>e.id);if(t0.some(e=>null===(0,e5.xs)(e))&&t.push(null),t.length<2)return;let s=t.indexOf(en??null),n=-1===s?0:s,r="prev"===e?(n-1+t.length)%t.length:(n+1)%t.length;sM.handleSelectWorkspace(t[r])},[t1,t0,en,sM]);!function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1],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=tp();if(t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){let t=tm.exec(e.code)||(/^[1-9]$/.test(e.key)?[null,e.key]:null);return t?{id:td.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"}:tv(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(tv(e.target))return null;let t=ty(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)&&!tv(e.target))return{id:"toggleFocus"};if(!t&&e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){if(tv(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=tm.exec(e.code);if(t)return{id:td.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=ty(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:()=>sM.switchSession("prev"),sessionNext:()=>sM.switchSession("next"),workspacePrev:()=>s9("prev"),workspaceNext:()=>s9("next"),sessionIndex:e=>sM.switchToIndex(e),closeTerminal:(0,r.useCallback)(()=>{if(sb?.type!=="terminal"||!sb.sessionId)return;let e=t0.find(e=>e.id===sb.sessionId);e&&so({isOpen:!0,title:K("sessions.deleteTitle"),message:K("sessions.deleteMessage",{name:e.name||K("terminal.defaultName")}),confirmText:K("common.delete"),onConfirm:()=>sM.handleDeleteSession(e.id)})},[sb,t0,sM,K]),toggleFocus:()=>sR.toggleInputFocus(sE),fitPanes:()=>window.dispatchEvent(new CustomEvent("terminal:fitPanes")),newTerminal:s8,toggleSidebar:ej,toggleRightPanel:eA,palette:()=>{s6&&s4(!0)},attentionNext:ni(eI(),t3,sM.handleSelectSession),help:s1},sp&&sg);let s7=(0,r.useRef)(new Map),ne=(0,r.useRef)(en);(0,r.useEffect)(()=>{let e=ne.current;if(e===en)return;ne.current=en;let t=f.B.getState();t.editorFilePath?s7.current.set(e,{filePath:t.editorFilePath,preview:t.editorPreviewSeq>0,artifactTitle:t.artifactTitle,artifactSessionId:t.artifactSessionId,line:t.editorJump?.line,column:t.editorJump?.column}):s7.current.delete(e);let s=s7.current.get(en);if(s){let{filePath:e,...n}=s;t.openEditorFile(e,n)}else t.closeEditorFile()},[en]);let nt=(0,r.useCallback)(e=>{let t=t1.find(e=>e.id===en)?.path||t0.find(e=>e.id===sb.sessionId)?.workspacePath||null;eq(),G({type:"editor",path:e,workspace:t})},[t1,en,t0,sb,G,eq]),ns=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if((0,_.pA)(e)){let{status:t,repoPath:s,filePath:n}=(0,_.qu)(e);sP({path:s?`${s}/${n}`:n,workspace:s||void 0,diffStatus:t});return}sP({path:e,workspace:t1.find(e=>e.id===en)?.path,preview:!!t.preview,artifactSessionId:t.artifactSessionId||null})},[t1,en,sP]),nn=(0,r.useCallback)((e,t)=>{if(!t?.path)return;let s=t.title||t.path.split("/").pop();sp?eH(t.path,{preview:!0,artifactTitle:s,artifactSessionId:e}):ns(t.path,{preview:!0,artifactSessionId:e})},[sp,eH,ns]);(0,r.useEffect)(()=>{let e=th.current;if(!e)return;let t=function(){let{path:e,title:t,sessionId:s}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!e)return;let n={path:e,title:t||e.split("/").pop(),at:Date.now()};s&&e8(s,n),s&&s!==sE||nn(s,n)};return e.on("artifactOpen",t),()=>e.off("artifactOpen",t)},[th,tw,sE,e8,nn]),(0,r.useEffect)(()=>{let e=e=>{let t=e?.detail?.url;if("string"!=typeof t||!t.startsWith("http://127.0.0.1:")||!t.includes("/preview/"))return;let s=en??"default",n=nc.getState(),r=n.workspaceWindows[s]||null;th?.current?.emit?.("browser:invoke",{action:"open",payload:{url:t,profile:n.workspaceProfiles[s]||"default",newWindow:!r,windowId:r||void 0,workspaceId:s}},e=>{if(!e?.ok||!e.id)return;let n=nc.getState();e.windowId&&e.windowId!==n.workspaceWindows[s]&&n.setWindowFor(s,e.windowId),n.setActive(s,e.id);let r=n.tabsByWorkspace[s]||[];r.some(t=>t.id===e.id)||n.setTabs(s,[...r,{id:e.id,url:t,title:""}])}),G({type:"browser"})};return window.addEventListener(cl,e),()=>window.removeEventListener(cl,e)},[en,th,G]),(0,r.useEffect)(()=>{sg&&void 0!==en&&ex(en)},[sg,en,ex]);let nr=sE?t3.find(e=>e.id===sE):null,nl=nr?nr.name||K("terminal.defaultName"):null;(0,r.useEffect)(()=>(eY(Object.keys(sm).length,nl),()=>eY(0)),[sm,nl]);let[na,no]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if("terminal"!==sb.type)return no(!1);let e=requestAnimationFrame(()=>no(!0));return()=>cancelAnimationFrame(e)},[sb.type]);let nd=(0,r.useRef)(null),[nu,nm]=(0,r.useState)("");(0,r.useEffect)(()=>{let e="terminal"===sb.type?sb.sessionId:null,t=nd.current;if(nd.current=e,!na||!e||!t||e===t)return nm("");nm(V.indexOf(e)>V.indexOf(t)?"term-slide-right":"term-slide-left")},[sb,na,V]);let nx=(0,r.useCallback)(()=>{if(!sp&&sz){sz.artifactSessionId&&e9(sz.artifactSessionId,sz.path),sP(null);return}let e=Array.isArray(U)?U:[],t=e.length>1?e[e.length-2]:{type:"list"};J(),tt.replace((0,to.O5)(t))},[tt,J,sp,sz,sP,e9,U]),np=(0,r.useCallback)(()=>{if("terminal"!==sb.type)return nx();Y([{type:"list"}])},[sb,nx,Y]);(0,r.useEffect)(()=>{tx&&tI()},[tx,tI]),(0,r.useEffect)(()=>{if(0===t3.length||0===V.length)return;let e=setTimeout(()=>{let e=t3.map(e=>e.id);V.filter(t=>!e.includes(t)).forEach(e=>et(e))},500);return()=>clearTimeout(e)},[t3,V,et]),function(e){let{setKeyboardOpen:t}=e;(0,r.useEffect)(()=>{let e=!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;e!==o&&(e=o,t(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)}},[t]),(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:sx});let[nh,nf]=(0,r.useState)(null),[nb,ng]=(0,r.useState)(!1),[nv,ny]=(0,r.useState)(null),nw=eM(nh||tJ||null),nj=eM(nv||tJ||null),nk=tZ[nh||tJ],nN=tZ[nv||tJ],nC=e=>e?.status==="online"||e?.status==="full",nS=nh?nk:tQ,nT=(nh?nC(nk):tw)&&!nS?.remoteAvailable,nE=(0,r.useMemo)(()=>Object.values(tZ).filter(e=>e.key!==(nh||tJ)&&("online"===e.status||"full"===e.status)&&e.remoteAvailable),[tZ,nh,tJ]),nR=(0,r.useMemo)(()=>Object.values(tZ).filter(e=>nC(e)&&e.remoteAvailable),[tZ]),nM=(0,r.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;nf(e),G({type:"remote"})},[G]),n$=(0,r.useCallback)(()=>{nR.length>1?ng(!0):(nf(nR[0]?.key||null),Z({type:"remote"}))},[nR,Z]),nz=(0,r.useCallback)(e=>{ng(!1),nf(e),Z({type:"remote"})},[Z]),nP=(0,r.useCallback)(()=>{if(nf(null),U.length>1)return nx();Z({type:"list"})},[U,nx,Z]),nA=(0,r.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(!sp){ny(e),G({type:"mobile"});return}if(!eX){ny(e),eJ(!0);return}nj.busRef.current?.emit("mobile:stop"),e4(null),eJ(!1),ny(null)},[sp,eX,eJ,e4,nj,G]),nD=(0,r.useCallback)(e=>{eZ(e,{startWidth:eG,axis:-1,onWidth:e3})},[eG,e3]),nL=(0,r.useCallback)(()=>{tf.current?.retryNow()},[tf]),nB=(0,r.useCallback)(()=>{P.rh.getState().closeAll(),ep(),tr(),sessionStorage.setItem("9remote_manual_disconnect","1"),window.location.replace("/login")},[ep,tr]),nF=(0,r.useCallback)(()=>{so({isOpen:!0,title:K("workspace.logoutTitle"),message:K("workspace.logoutMessage"),onConfirm:nB})},[nB,K]),nO=(0,r.useCallback)(e=>{let t=tH().find(t=>(0,p.Uo)(t.key)===e);t&&tX(t.id),e===tJ&&nB()},[tH,tX,tJ,nB]),n_=(0,r.useCallback)(()=>{P.rh.getState().disconnectHost(tJ),tb()},[tJ,tb]),nK=(0,r.useCallback)(()=>{P.rh.getState()._patchHost(tJ,{status:"connecting"}),tg()},[tJ,tg]),nW=(0,r.useCallback)(()=>{so({isOpen:!1,title:"",message:"",onConfirm:null})},[]),nH=(0,r.useCallback)(e=>{es(e),tW(e)},[es,tW]),nq=(0,r.useCallback)(e=>{en&&eR(en,e)},[en,eR]),nU=(0,r.useMemo)(()=>({open:e$,tabs:ez,width:eP,onTabChange:eD,onResize:eL,onToggle:eA,onNewTerminal:sY}),[e$,ez,eP,eD,eL,eA,sY]),nX=(0,r.useMemo)(()=>({filePath:eB,previewSeq:eU,artifactTitle:e6,jump:e_,width:eK,onResize:eW,onOpen:sp?eH:ns,onClose:eq,onOpenFull:nt}),[eB,eU,e6,e_,eK,eW,sp,eH,ns,eq,nt]),nV=(0,r.useMemo)(()=>({open:eX,mode:eV,width:eG,busRef:nj.busRef,protocolRef:nj.pmRef,connected:nv?nC(nN):tw,onResizeStart:nD}),[eX,eV,eG,nj,nv,nN,tw,nD]);if(!H||!ss&&!sn)return(0,n.jsx)(dt,{label:K("workspace.loading")});let nG=(!tw||!tP)&&!sl&&!sn,nJ=tw&&tS?nM:null,nY=tw&&tT?nA:null,nZ=!sp&&("list"===sb.type||"terminal"===sb.type&&!!X?.[sb.sessionId]?.endsWith("-ui"));return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ds.A,{}),nZ&&(0,n.jsx)("div",{"aria-hidden":!0,className:"fixed inset-0 pointer-events-none",style:{...t4(W),zIndex:-9}}),(0,n.jsx)(r.Suspense,{fallback:null,children:(0,n.jsx)(xe,{hydrated:H,apiKey:tl?.apiKey})}),(0,n.jsxs)("div",{className:"terminal-container h-[var(--app-height,100vh)] fixed inset-0 overflow-hidden overscroll-none",children:[!sp&&(0,n.jsx)(m3,{active:"list"===sb.type,dir:Q,className:"z-10",children:(0,n.jsx)(dn,{sessions:t0,cwdBySession:ev,connected:tw,onSelect:sM.handleSelectSession,onCreate:sM.handleCreateSession,onDelete:sM.handleDeleteSession,onRename:sM.handleRenameSession,onResumeAgentSession:sM.handleResumeAgentSession,onLogout:nF,onOpenRemote:nJ,onOpenRemoteHost:nM,onOpenMobileHost:nA,tunnelUrl:tl?.tunnelUrl,apiKey:tl?.apiKey,connectionMode:tN,isActive:"list"===sb.type,busRef:th,subscribeToPush:sd,unsubscribeFromPush:su,hostVersion:tR||tM,agentVersion:tR||tM,carrier:tC,workspaces:t1,onAddWorkspace:sV,homeDir:s$?.homedir,onRenameWorkspace:tO,onDeleteWorkspace:t_,onReorderSession:nH,recentWorkspaces:sU,shells:t9,onRenameHost:t8,onDeleteHost:nO,onMainDisconnect:n_,onMainReconnect:nK})}),(sp||V.length>0||sN)&&(0,n.jsx)(c7,{platform:tE,hostVersion:tR||tM,agentVersion:tR||tM,sessions:t3,workspaces:t6,onCreateAnyHost:sG,onQuickCreateHostAware:s8,onResumeAgentSessionForeign:sJ,activeSessionId:sE,activeSession:nr,activeWorkspaceId:en,openedSessions:V,livePanes:ea,mountedWorkspaces:ed,cwdBySession:ev,isDesktop:sp,isTerminalView:sg,pairDashboard:sp&&sb?.type==="pair"?(0,n.jsx)(uT,{}):null,browserVisible:sv,browserPanel:sN?(0,n.jsx)(ul,{visible:sv,busRef:sC?eM(sC).busRef:th,connected:sC?nC(sS):tw,onBack:J,profile:sT,workspaceId:en,onProfileChange:e=>nc.getState().setProfileFor(en,e)},sy):null,welcomeActive:sb?.type==="welcome"||sp&&sb?.type==="list",slideClass:nu,shells:t9,sidebarCollapsed:ew,sidebarWidth:eN,setSidebarWidth:eT,paneWidth:en?eE[en]??null:null,setPaneWidth:en?nq:void 0,toggleSidebar:ej,paneRegistry:sR,bindSwipeTab:sf,nav:sM,onBack:np,atStackBottom:sp&&"list"===sb.type,onOpenRemote:nJ,onOpenMobile:nY,onOpenRemoteHost:nM,onOpenMobileHost:nA,onOpenFiles:sD,onLogout:nF,onDeleteWorkspace:t_,onReorderSession:tW,onAddWorkspace:sV,onSetHiddenRepos:tK,onOpenSettings:sq,onRenameHost:t8,onDeleteHost:nO,onMainDisconnect:n_,onMainReconnect:nK,homeDir:s$?.homedir,recentWorkspaces:sU,onOpenArtifact:nn,rightPanel:nU,editorPanel:nX,mobilePanel:nV,fileBus:sc,tunnelUrl:tl?.tunnelUrl,apiKey:tl?.apiKey,connectionMode:tN,subscribeToPush:sd,unsubscribeFromPush:su}),sW&&(0,n.jsx)(nI,{fileBus:sc,scope:tY,initialPath:sW.initialPath,onSelect:sX,onClose:()=>sH(null)}),!sp&&(0,n.jsx)(m3,{active:"remote"===sb.type,dir:Q,className:"z-20",children:"remote"===sb.type&&(nT?(0,n.jsx)(dB,{hostLabel:nS?.label,status:nS?.remoteStatus||null,platform:nS?.platform||tE,hosts:nE,onOpenHost:e=>nf(e),onBack:nP}):(0,n.jsx)(dO,{onClose:nP,busRef:nw.busRef,protocolRef:nw.pmRef,connected:nh?nC(nk):tw,carrier:nh?nk?.carrier||"ws":tC,hostPlatform:nk?.platform||tE,hostLabel:nS?.label,remoteStatus:nS?.remoteStatus||null,otherReadyHosts:nE,onOpenHost:e=>nf(e)},nh||tJ||"main"))}),sp&&"remote"===sb.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:nT?(0,n.jsx)(dB,{hostLabel:nS?.label,status:nS?.remoteStatus||null,platform:nS?.platform||tE,hosts:nE,onOpenHost:e=>nf(e),onBack:nP}):(0,n.jsx)(dO,{onClose:nP,busRef:nw.busRef,protocolRef:nw.pmRef,connected:nh?nC(nk):tw,carrier:nh?nk?.carrier||"ws":tC,hostPlatform:nk?.platform||tE,hostLabel:nS?.label,remoteStatus:nS?.remoteStatus||null,otherReadyHosts:nE,onOpenHost:e=>nf(e)},nh||tJ||"main")}),"mobile"===sb.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out",children:(0,n.jsx)(iE,{onClose:()=>{ny(null),nx()},busRef:nj.busRef,protocolRef:nj.pmRef,connected:nv?nC(nN):tw})}),!sp&&"pair"===sb.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out screen-in",children:(0,n.jsx)(uT,{})}),"workspaces"===sb.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out screen-in",children:(0,n.jsx)(eb,{onSelect:sL,onBrowse:sB,onBack:nx,isCodespaces:!!tQ?.isCodespaces,systemInfo:s$})}),"browse"===sb.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out screen-in",children:(0,n.jsx)(uR,{scope:tY,workspace:sb.path,fileBus:sc,onBack:nx,onSetWorkspace:sK,isBrowsing:!0})}),sp&&("files"===sb.type||"editor"===sb.type||"git"===sb.type)&&(T="files"===sb.type?sb:[...U].reverse().find(e=>"files"===e.type),E=T?.workspace||sb.workspace,R=eh(tY).find(e=>e.path===E),M="editor"===sb.type?sb.path:null,(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out screen-in",children:(0,n.jsx)(u2,{workspace:E,fileBus:sc,onBack:nx,onSwitchWorkspace:sI,initialOpenedFiles:M?[M]:R?.openedFiles||[],initialActiveFile:M||R?.activeFile||null,onOpenedFilesChange:(e,t)=>(function(e,t,s){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",r=(0,_.kb)(e),l=eh(n),a=l.findIndex(e=>e.path===r),i=Array.isArray(t)?t.map(e=>e&&"object"==typeof e?{...e,path:(0,_.kb)(e.path)}:e):t,o="string"==typeof s?(0,_.kb)(s):s;if(-1===a){l.unshift({path:r,lastOpened:Date.now(),openedFiles:i,activeFile:o}),localStorage.setItem(em(n),JSON.stringify(l));return}l[a]={...l[a],openedFiles:i,activeFile:o??null},localStorage.setItem(em(n),JSON.stringify(l))})(E,e,t,tY),bus:tx,connected:tw,sessions:t0,onCreateTerminalSession:sM.handleCreateSessionInline,onDeleteTerminalSession:sM.handleDeleteSession,onRenameTerminalSession:sM.handleRenameSession,viewType:sb.type,openFileRef:sA},E)})),!sp&&"files"===sb.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-20 transition-all duration-300 ease-out screen-in",children:(0,n.jsx)(uR,{scope:tY,workspace:sb.workspace,initialPath:sb.currentPath,fileBus:sc,onBack:nx,onOpenFile:sO,onOpenGit:s_,onSwitchWorkspace:sI,onPathChange:e=>sF(sb.workspace,e),hideSwitchWorkspace:sb.fromTerminal})}),!sp&&"git"===sb.type&&(0,n.jsx)("div",{className:"absolute inset-0 z-30 transition-all duration-300 ease-out screen-in",children:(0,n.jsx)(uI,{workspace:sb.workspace,fileBus:sc,onBack:nx,onOpenFile:sO})}),!sp&&sz&&(0,n.jsx)("div",{className:"absolute inset-0 z-40 transition-all duration-300 ease-out screen-in",children:(0,n.jsx)(uP,{filePath:sz.path,line:sz.line,column:sz.column,diffStatus:sz.diffStatus,preview:sz.preview,fileBus:sc,onBack:()=>{sz.artifactSessionId&&e9(sz.artifactSessionId,sz.path),sP(null)},workspace:sz.workspace||sb.workspace})}),nG&&(0,n.jsx)(dt,{}),!sl&&(0,n.jsx)(u3,{retryStatus:t$,approvalStatus:tz,connected:tw,hostOffline:tA,suppress:st,firstConnect:!sr,onLogout:nB,onRetryNow:nL}),(0,n.jsx)(m4,{}),!sp&&!nG&&("list"===sb.type||"settings"===sb.type)&&(0,n.jsx)(m8,{active:m6[sb.type]||"sessions",onSessions:()=>Z({type:"list"}),onRemote:n$,onMenu:sq}),nb&&(0,n.jsx)(dK,{hosts:nR,onPick:nz,onClose:()=>ng(!1)}),(0,n.jsx)(m9,{}),s3&&s6&&(0,n.jsx)(u0,{mode:"files",workspace:s6,fileBus:sc,onClose:()=>s4(!1),onOpenFile:e=>eH(e)}),(0,n.jsx)(u5,{isOpen:s2,onClose:s5}),(0,n.jsx)(ec.A,{isOpen:si.isOpen,onClose:nW,onConfirm:si.onConfirm,title:si.title,message:si.message,confirmText:si.confirmText})]}),(0,n.jsx)("div",{hidden:!0,children:(0,n.jsx)(r.Suspense,{fallback:null,children:$})}),(0,n.jsx)(eo,{})]})}},96484:(e,t,s)=>{Promise.resolve().then(s.bind(s,77442))}},e=>{e.O(0,[2031,3859,7401,820,6925,6141,9491,1772,9121,8126,587,1968,7358],()=>e(e.s=96484)),_N_E=e.O()}]);