@openchamber/web 2.0.4 → 2.1.0

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 (264) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-C_zL-eri.js → CodeMirrorCommentWidgets-qlshRzAf.js} +1 -1
  2. package/dist/assets/{DiffView-BeN2_YYF.js → DiffView-BI_YgdKl.js} +3 -3
  3. package/dist/assets/FilesView-B_NJFLBH.js +17 -0
  4. package/dist/assets/{GitView-DLDazOo1.js → GitView-BWKg6TNS.js} +4 -4
  5. package/dist/assets/{GuestAttachDialog-C0xe_Lyy.js → GuestAttachDialog-DO4x4vIR.js} +1 -1
  6. package/dist/assets/{GuestSurfacePane-BdaurnDr.js → GuestSurfacePane-4PY11vEP.js} +1 -1
  7. package/dist/assets/JsonTreeView-u4yx65zn.js +1 -0
  8. package/dist/assets/{LinearIssuesView-BryoAHow.js → LinearIssuesView-C4gGBhU8.js} +1 -1
  9. package/dist/assets/{MarkdownImageGallery-DfuEoaGq.js → MarkdownImageGallery-fqVRCTdC.js} +1 -1
  10. package/dist/assets/MarkdownRendererImpl-Cfb5fTnq.js +39 -0
  11. package/dist/assets/OnboardingScreen-CiTV2_OT.js +1 -0
  12. package/dist/assets/PatchDiff-BrjhzXDM.js +1 -0
  13. package/dist/assets/{PierreDiffViewer-BC950e3F.js → PierreDiffViewer-CVx2e1cx.js} +5 -5
  14. package/dist/assets/{PlanView-B7Xgihqk.js → PlanView-DP9DOnI-.js} +4 -4
  15. package/dist/assets/{PluginPane-2C71F8uF.js → PluginPane-rZvoMQSi.js} +3 -3
  16. package/dist/assets/SettingsView-Dp9jubRs.js +30 -0
  17. package/dist/assets/SettingsWindow-Dst0yiV7.js +1 -0
  18. package/dist/assets/{SubmoduleDiffSummary-BSA9gnIO.js → SubmoduleDiffSummary-CixkM4fI.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-DprkVKcj.js → ToolOutputDialog-f0cS2DIf.js} +6 -6
  20. package/dist/assets/ToolPartDiffPreview-CFFIAFFY.js +8 -0
  21. package/dist/assets/{VirtualizedFileDiff-Kp8hKJdT.js → VirtualizedFileDiff-B-U_aQwV.js} +4 -4
  22. package/dist/assets/{WalkthroughView-DGnTzqIU.js → WalkthroughView-C1uB3Pl3.js} +2 -2
  23. package/dist/assets/{appThemeRegistry-BdEHBA4s.js → appThemeRegistry-DU-UKEHq.js} +1 -1
  24. package/dist/assets/{commitAndPush-LwtVa2Oc.js → commitAndPush-CtWGqrtW.js} +1 -1
  25. package/dist/assets/{computeVirtualFileMetrics-6V1xNpO9.js → computeVirtualFileMetrics-BmhViPMt.js} +1 -1
  26. package/dist/assets/de-D4hpTCNY.js +10 -0
  27. package/dist/assets/es-Bw9m3H62.js +16 -0
  28. package/dist/assets/fileTreeStatus-CvPnAWSi.js +1 -0
  29. package/dist/assets/fr-Bhll42P0.js +14 -0
  30. package/dist/assets/index-Btd2mmYT.js +42 -0
  31. package/dist/assets/index-C-7hQnEc.css +1 -0
  32. package/dist/assets/{index-CmNPYddV.js → index-DwtCnbiK.js} +1 -1
  33. package/dist/assets/{isDiffPlainText-1bXcWCrw.js → isDiffPlainText-CPDhzF1K.js} +1 -1
  34. package/dist/assets/{isFilePlainText-CBAppvy1.js → isFilePlainText-n8k0lMTZ.js} +1 -1
  35. package/dist/assets/ja-CsHoT43d.js +16 -0
  36. package/dist/assets/ko-BBNdtFa4.js +16 -0
  37. package/dist/assets/{main-CzjTMTfW.js → main-D6rlXjug.js} +2 -2
  38. package/dist/assets/main-kYkr_urz.js +1000 -0
  39. package/dist/assets/markdownCore-CHm8ycaW.js +7 -0
  40. package/dist/assets/{miniChat-CP68IL8Q.js → miniChat-2JY8K3Qw.js} +2 -2
  41. package/dist/assets/mobile-CviaXnnU.js +2 -0
  42. package/dist/assets/nl-DszyktfH.js +16 -0
  43. package/dist/assets/openSessionFromRoute-BIlcJIf3.js +1 -0
  44. package/dist/assets/{web-components-ngpHPEDU.js → parseDiffFromFile-DeZzEah8.js} +5 -5
  45. package/dist/assets/{patchFileDiff-pqRSHLHI.js → patchFileDiff-BnEHIdM2.js} +2 -2
  46. package/dist/assets/pl-Bk9_mUXc.js +16 -0
  47. package/dist/assets/pt-BR-BIXmm3Gw.js +16 -0
  48. package/dist/assets/{renderElectronMiniChatApp-DKIilR7N.js → renderElectronMiniChatApp-DvUphkjj.js} +2 -2
  49. package/dist/assets/renderMobileApp-Cdc49X8Y.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-Cu6RUve4.js +56 -0
  51. package/dist/assets/shikiHighlight-CcVzlYit.js +1 -0
  52. package/dist/assets/space-apply-CgJ5JYPK.js +1 -0
  53. package/dist/assets/space-close-C1tL-_0t.js +1 -0
  54. package/dist/assets/{textMateThemeFromAppTheme-BSUFChBY.js → textMateThemeFromAppTheme-CAOCeVjl.js} +1 -1
  55. package/dist/assets/tr-C_13w7CX.js +7 -0
  56. package/dist/assets/uk-BZTsG-q_.js +16 -0
  57. package/dist/assets/{useAppFontEffects-Dsl_sLrj.js → useAppFontEffects-CeMgbeVa.js} +185 -177
  58. package/dist/assets/{useInlineCommentController-d5vntsQ_.js → useInlineCommentController-U97JJifS.js} +2 -2
  59. package/dist/assets/useRootScrollLock-DMBY2aTT.js +2 -0
  60. package/dist/assets/{vendor-base-ui-DnNniUWp.js → vendor-base-ui-DWgyZK2k.js} +1 -1
  61. package/dist/assets/vendor-codemirror-autocomplete-DetzHhtC.js +1 -0
  62. package/dist/assets/{vendor-codemirror-commands-B7H_j0iU.js → vendor-codemirror-commands-ConqfjLn.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-angular-DEPs2M5t.js → vendor-codemirror-lang-angular-Dbpx8qe-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-cpp-DhkseaMo.js → vendor-codemirror-lang-cpp-TRtQWrpl.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-css-O0cZX78y.js → vendor-codemirror-lang-css-DY4CGDG2.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-go-fMdQYcON.js → vendor-codemirror-lang-go-CLKXh6B8.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-html-CfgK872x.js → vendor-codemirror-lang-html-CQnNjmg9.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-java-CQj4S3zl.js → vendor-codemirror-lang-java-CokZKqls.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-javascript-Cc2ZYbgX.js → vendor-codemirror-lang-javascript-Kgp6fZRE.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-jinja-BmZZv8g-.js → vendor-codemirror-lang-jinja-DZchyrN1.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-json-CMBS2tG9.js → vendor-codemirror-lang-json-CkdBRvqj.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-less-C6Eo8hVS.js → vendor-codemirror-lang-less-_k-GKz0A.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-liquid-DSTR47-H.js → vendor-codemirror-lang-liquid-DuHUMKoh.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-markdown-BPGOH9ye.js → vendor-codemirror-lang-markdown-CdG1RXm1.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-php-DD9udfPH.js → vendor-codemirror-lang-php-Ca15KQSA.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-python-HahnQaAS.js → vendor-codemirror-lang-python-B4MRHRva.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-rust-nLTovbjv.js → vendor-codemirror-lang-rust-8fLJdxQA.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-lang-sass-pL2Yc72v.js → vendor-codemirror-lang-sass-CASr_yQ1.js} +1 -1
  79. package/dist/assets/{vendor-codemirror-lang-sql-BVBnan19.js → vendor-codemirror-lang-sql-Dc4ER-re.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-lang-vue-BqGzJVm1.js → vendor-codemirror-lang-vue-fu2BqdK2.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-lang-wast-B0_m5DqU.js → vendor-codemirror-lang-wast-BkCOgSpV.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-xml-Dj3voadT.js → vendor-codemirror-lang-xml-7e-kPepH.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-yaml-yu-9Z5u7.js → vendor-codemirror-lang-yaml-Cq3p_9DI.js} +1 -1
  84. package/dist/assets/vendor-codemirror-language-CZcLdzDM.js +3 -0
  85. package/dist/assets/{vendor-codemirror-language-data-B1EetJur.js → vendor-codemirror-language-data-B8HKnqZy.js} +2 -2
  86. package/dist/assets/vendor-codemirror-search-BZNojiZO.js +2 -0
  87. package/dist/assets/{vendor-codemirror-state-C9awkmn-.js → vendor-codemirror-state--21VQleR.js} +1 -1
  88. package/dist/assets/vendor-codemirror-view-8PpN-8l4.js +4 -0
  89. package/dist/assets/vendor-opencode-client-Byb4ZSqI.js +12 -0
  90. package/dist/assets/vendor-remend-DcBOpbSu.js +24 -0
  91. package/dist/assets/{vendor-replit-codemirror-vim-B2DJlAhT.js → vendor-replit-codemirror-vim-EX7OnecQ.js} +1 -1
  92. package/dist/assets/zh-CN-C62wm2Tg.js +16 -0
  93. package/dist/assets/zh-TW-BgGTiQA6.js +16 -0
  94. package/dist/index.html +4 -4
  95. package/dist/mini-chat.html +4 -4
  96. package/dist/mobile.html +4 -4
  97. package/package.json +4 -4
  98. package/server/index.js +58 -1
  99. package/server/lib/browser-control/DOCUMENTATION.md +8 -1
  100. package/server/lib/dev-tunnel/DOCUMENTATION.md +6 -0
  101. package/server/lib/dev-tunnel/runtime.js +94 -38
  102. package/server/lib/dev-tunnel/tunnel.test.js +16 -2
  103. package/server/lib/dictation/DOCUMENTATION.md +23 -10
  104. package/server/lib/dictation/audio.js +28 -0
  105. package/server/lib/dictation/local/sherpa-recognizer.js +33 -7
  106. package/server/lib/dictation/local/sherpa-recognizer.test.js +94 -0
  107. package/server/lib/dictation/local/worker-client.js +28 -10
  108. package/server/lib/dictation/local/worker-process.js +25 -1
  109. package/server/lib/dictation/stream-manager.js +160 -53
  110. package/server/lib/dictation/stream-manager.test.js +108 -7
  111. package/server/lib/enterprise-mode.d.ts +2 -0
  112. package/server/lib/enterprise-mode.js +84 -9
  113. package/server/lib/enterprise-mode.test.js +115 -0
  114. package/server/lib/fs/DOCUMENTATION.md +3 -2
  115. package/server/lib/fs/routes.js +28 -1
  116. package/server/lib/fs/routes.test.js +31 -5
  117. package/server/lib/git/DOCUMENTATION.md +1 -1
  118. package/server/lib/git/service.js +61 -2
  119. package/server/lib/git/service.test.js +141 -0
  120. package/server/lib/github/DOCUMENTATION.md +18 -0
  121. package/server/lib/github/checks-summary.js +76 -0
  122. package/server/lib/github/pr-summaries.js +282 -0
  123. package/server/lib/github/pr-summaries.test.js +209 -0
  124. package/server/lib/github/routes.js +42 -77
  125. package/server/lib/github/routes.test.js +77 -0
  126. package/server/lib/inherited-env.js +51 -0
  127. package/server/lib/inherited-env.test.js +59 -0
  128. package/server/lib/message-search/DOCUMENTATION.md +83 -0
  129. package/server/lib/message-search/indexer.js +336 -0
  130. package/server/lib/message-search/indexer.test.js +341 -0
  131. package/server/lib/message-search/routes.js +92 -0
  132. package/server/lib/message-search/runtime.js +234 -0
  133. package/server/lib/message-search/runtime.test.js +108 -0
  134. package/server/lib/message-search/sqlite.js +74 -0
  135. package/server/lib/message-search/store.js +289 -0
  136. package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
  137. package/server/lib/openchamber-control/actions.js +1 -1
  138. package/server/lib/openchamber-control/service.js +21 -2
  139. package/server/lib/openchamber-control/service.test.js +50 -0
  140. package/server/lib/openchamber-sessions/routes.js +15 -0
  141. package/server/lib/openchamber-sessions/routes.test.js +31 -0
  142. package/server/lib/opencode/DOCUMENTATION.md +43 -38
  143. package/server/lib/opencode/auth.d.ts +24 -0
  144. package/server/lib/opencode/auth.js +130 -66
  145. package/server/lib/opencode/auth.test.js +114 -70
  146. package/server/lib/opencode/compatibility.js +4 -3
  147. package/server/lib/opencode/compatibility.test.js +10 -10
  148. package/server/lib/opencode/feature-routes-runtime.js +3 -0
  149. package/server/lib/opencode/lifecycle.js +21 -12
  150. package/server/lib/opencode/lifecycle.test.js +38 -5
  151. package/server/lib/opencode/provider-source-route.test.js +55 -2
  152. package/server/lib/opencode/routes.js +17 -4
  153. package/server/lib/opencode/settings-helpers.js +6 -0
  154. package/server/lib/opencode/settings-helpers.test.js +1 -1
  155. package/server/lib/opencode/settings-registry.json +16 -0
  156. package/server/lib/opencode/settings-runtime.js +9 -0
  157. package/server/lib/opencode/shutdown-runtime.js +2 -0
  158. package/server/lib/opencode/v1-migration-topup.js +13 -3
  159. package/server/lib/opencode/v2-install.test.js +13 -13
  160. package/server/lib/quota/DOCUMENTATION.md +11 -5
  161. package/server/lib/quota/providers/claude/auth.js +19 -6
  162. package/server/lib/quota/providers/claude/auth.test.js +22 -9
  163. package/server/lib/quota/providers/claude/index.js +3 -3
  164. package/server/lib/quota/providers/claude/index.test.js +3 -2
  165. package/server/lib/quota/providers/cline-pass.js +4 -4
  166. package/server/lib/quota/providers/codex.js +3 -4
  167. package/server/lib/quota/providers/codex.test.js +1 -1
  168. package/server/lib/quota/providers/copilot.js +4 -5
  169. package/server/lib/quota/providers/copilot.test.js +1 -1
  170. package/server/lib/quota/providers/deepseek.js +3 -4
  171. package/server/lib/quota/providers/deepseek.test.js +1 -1
  172. package/server/lib/quota/providers/google/auth.js +1 -3
  173. package/server/lib/quota/providers/google/index.js +3 -2
  174. package/server/lib/quota/providers/hyper.js +4 -4
  175. package/server/lib/quota/providers/index.js +9 -2
  176. package/server/lib/quota/providers/index.test.js +5 -3
  177. package/server/lib/quota/providers/kimi.js +16 -11
  178. package/server/lib/quota/providers/kimi.test.js +81 -38
  179. package/server/lib/quota/providers/minimax-shared.js +3 -4
  180. package/server/lib/quota/providers/nanogpt.js +3 -4
  181. package/server/lib/quota/providers/neuralwatt.js +3 -4
  182. package/server/lib/quota/providers/neuralwatt.test.js +1 -1
  183. package/server/lib/quota/providers/openai.js +2 -8
  184. package/server/lib/quota/providers/opencode-go.js +5 -5
  185. package/server/lib/quota/providers/opencode-go.test.js +1 -1
  186. package/server/lib/quota/providers/openrouter.js +30 -6
  187. package/server/lib/quota/providers/openrouter.test.js +122 -1
  188. package/server/lib/quota/providers/wafer.js +3 -4
  189. package/server/lib/quota/providers/xai.js +12 -12
  190. package/server/lib/quota/providers/zai.js +3 -4
  191. package/server/lib/quota/providers/zai.test.js +1 -1
  192. package/server/lib/quota/providers/zhipuai-coding-plan.js +5 -6
  193. package/server/lib/quota/providers/zhipuai-coding-plan.test.js +1 -1
  194. package/server/lib/quota/routes.js +1 -1
  195. package/server/lib/routing/DOCUMENTATION.md +4 -0
  196. package/server/lib/routing/runtime.js +45 -4
  197. package/server/lib/routing/runtime.test.js +35 -6
  198. package/server/lib/scheduled-tasks/DOCUMENTATION.md +27 -0
  199. package/server/lib/scheduled-tasks/chats-scope.js +50 -0
  200. package/server/lib/scheduled-tasks/runtime.js +57 -23
  201. package/server/lib/scheduled-tasks/runtime.test.js +103 -1
  202. package/server/lib/scheduled-tasks/service.js +37 -29
  203. package/server/lib/scheduled-tasks/service.test.js +39 -0
  204. package/server/lib/spaces/DOCUMENTATION.md +54 -9
  205. package/server/lib/spaces/host.js +24 -3
  206. package/server/lib/spaces/journey.js +111 -11
  207. package/server/lib/spaces/journey.test.js +189 -8
  208. package/server/lib/spaces/places/docker-disk.js +151 -0
  209. package/server/lib/spaces/places/docker-disk.test.js +167 -0
  210. package/server/lib/spaces/places/docker-tools.js +11 -1
  211. package/server/lib/spaces/places/docker.js +4 -2
  212. package/server/lib/spaces/places/fake-docker.js +36 -2
  213. package/server/lib/spaces/routes.js +21 -4
  214. package/server/lib/spaces/routes.test.js +6 -2
  215. package/server/lib/spaces/space-archive.js +275 -0
  216. package/server/lib/spaces/space-archive.test.js +194 -0
  217. package/server/lib/spaces/space-opencode.js +139 -6
  218. package/server/lib/spaces/space-opencode.test.js +82 -1
  219. package/server/lib/spaces/space-records.js +3 -0
  220. package/server/lib/spaces/space-setup.js +10 -5
  221. package/server/lib/spaces/space-setup.test.js +8 -2
  222. package/server/lib/terminal/DOCUMENTATION.md +1 -0
  223. package/server/lib/terminal/runtime.js +6 -1
  224. package/server/lib/terminal/runtime.test.js +19 -0
  225. package/server/lib/tts/routes.js +2 -2
  226. package/server/lib/tts/service.js +8 -8
  227. package/dist/assets/FilesView-CN34wm_N.js +0 -17
  228. package/dist/assets/JsonTreeView-B1Xq-k2t.js +0 -1
  229. package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +0 -12
  230. package/dist/assets/OnboardingScreen-C22bGmnP.js +0 -1
  231. package/dist/assets/PatchDiff-0xd6UeFB.js +0 -1
  232. package/dist/assets/SettingsView-m_zoFiaT.js +0 -30
  233. package/dist/assets/SettingsWindow-CofS020b.js +0 -1
  234. package/dist/assets/ToolPartDiffPreview-Dq0go_fX.js +0 -8
  235. package/dist/assets/de-DlgBHUAI.js +0 -10
  236. package/dist/assets/es-BC8G41U8.js +0 -16
  237. package/dist/assets/fr-I0z3vVjy.js +0 -14
  238. package/dist/assets/index-CgR5rJq_.js +0 -41
  239. package/dist/assets/index-adyy_sEk.css +0 -1
  240. package/dist/assets/ja-BIElEsY8.js +0 -16
  241. package/dist/assets/ko-DRnnHetA.js +0 -16
  242. package/dist/assets/main-DVX34beR.js +0 -886
  243. package/dist/assets/markdownCore-Cxbkn5NR.js +0 -7
  244. package/dist/assets/mobile-BrlBrNfZ.js +0 -2
  245. package/dist/assets/nl-DzUV-kwp.js +0 -16
  246. package/dist/assets/pl-Bb-cb7k7.js +0 -16
  247. package/dist/assets/pt-BR-CyIWrTcE.js +0 -16
  248. package/dist/assets/renderMobileApp-B0z6-x58.js +0 -25
  249. package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +0 -52
  250. package/dist/assets/scheduledTasksApi-BuzWT445.js +0 -1
  251. package/dist/assets/shikiHighlight-BWGrY5YU.js +0 -1
  252. package/dist/assets/tr-DXEDSoYO.js +0 -7
  253. package/dist/assets/uk-C8hN--q_.js +0 -16
  254. package/dist/assets/useRootScrollLock-2rd5Y6gR.js +0 -2
  255. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +0 -1
  256. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +0 -3
  257. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +0 -2
  258. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +0 -4
  259. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +0 -12
  260. package/dist/assets/vendor-remend-BWYYytN3.js +0 -22
  261. package/dist/assets/zh-CN-CtzXdjMZ.js +0 -16
  262. package/dist/assets/zh-TW-Ds0CADSz.js +0 -16
  263. package/server/lib/opencode/credential-db.js +0 -144
  264. package/server/lib/opencode/credential-db.test.js +0 -104
@@ -0,0 +1,25 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-B_NJFLBH.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-Btd2mmYT.js","assets/vendor-zod-CxRSdNoV.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-opencode-client-Byb4ZSqI.js","assets/index-C-7hQnEc.css","assets/useAppFontEffects-CeMgbeVa.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-base-ui-DWgyZK2k.js","assets/vendor-floating-ui-utils-D6FqdtJt.js","assets/vendor-floating-ui-dom-BTvzWks8.js","assets/vendor-floating-ui-core-PuGzNPnN.js","assets/vendor-floating-ui-react-dom-DxYCWdHj.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-tanstack-react-virtual--0sBrLRh.js","assets/vendor-tanstack-virtual-core-BoA4iGMw.js","assets/vendor-framer-motion-Bq3iTZ6r.js","assets/vendor-motion-dom-DcCgeG69.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/contextPanelEmbeddedChat-CirXEPJq.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-CZcLdzDM.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state--21VQleR.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-8PpN-8l4.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Kgp6fZRE.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-DetzHhtC.js","assets/vendor-codemirror-lang-json-CkdBRvqj.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-DY4CGDG2.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CQnNjmg9.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-CdG1RXm1.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-B8HKnqZy.js","assets/vendor-codemirror-lang-python-B4MRHRva.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-ConqfjLn.js","assets/vendor-legendapp-list-BuBPBC3R.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/runtimeEndpointReset-Cu6RUve4.js","assets/space-apply-CgJ5JYPK.js","assets/openSessionFromRoute-BIlcJIf3.js","assets/GuestAttachDialog-DO4x4vIR.js","assets/PluginPane-rZvoMQSi.js","assets/vendor-cron-parser-CjvYVigk.js","assets/vendor-luxon-BZ0puJYg.js","assets/shikiHighlight-CcVzlYit.js","assets/vendor-codemirror-search-BZNojiZO.js","assets/vendor-replit-codemirror-vim-EX7OnecQ.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/fileTreeStatus-CvPnAWSi.js","assets/JsonTreeView-u4yx65zn.js","assets/parseDiffFromFile-DeZzEah8.js","assets/computeVirtualFileMetrics-BmhViPMt.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/vendor-diff-C3JhlQdm.js","assets/Virtualizer-CZlLSacm.js","assets/isFilePlainText-n8k0lMTZ.js","assets/appThemeRegistry-DU-UKEHq.js","assets/textMateThemeFromAppTheme-CAOCeVjl.js","assets/Virtualizer-D_a8gKmg.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/useInlineCommentController-U97JJifS.js","assets/CodeMirrorCommentWidgets-qlshRzAf.js","assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-capacitor-push-notifications-KNe1zSBF.js"])))=>i.map(i=>d[i]);
2
+ import{f as de,r as Pn,j as t,R as f,c as is,h as ha}from"./vendor-react-BUCujlKS.js";import"./vendor-katex-CHD9BdDO.js";import{u as Oe,a as Ps,b as zi,d as Wr,i as We,e as pt,s as Qt,f as Rs,h as Fn,j as ga,k as Oi,l as ba,p as xa,m as ya,n as Nt,o as va,q as wa,t as ja,v as Ht,x as ka,y as Vr,z as wn,G as Ur,A as Sa,B as Gr,C as Bi,D as Kr,E as qr,F as Hr,M as Ws,H as Na,I as Ca}from"./index-Btd2mmYT.js";import{u as ss,a as Ra,b as Ze,c as Tn,d as Li,r as $i,e as Ea,f as ge,t as we,o as Ia,I as J,B as Se,g as Fi,O as Zt,h as Q,P as Wi,i as Aa,j as Pa,k as Ta,l as it,m as Da,n as Pt,p as _a,q as Jr,s as Ma,v as za,w as Wn,x as Oa,y as Ba,z as _e,A as La,C as Vn,D as Un,E as Gn,F as $a,S as Ys,G as Vi,H as Fa,J as Ui,K as Qe,L as Gi,M as Wa,N as Va,Q as Ua,R as Ki,T as qi,U as Hi,V as Ji,W as Yi,X as Xi,Y as Ga,Z as Ka,_ as Yr,$ as Qi,a0 as Zi,a1 as eo,a2 as qa,a3 as Ha,a4 as Kn,a5 as Ja,a6 as Ya,a7 as Xa,a8 as Qa,a9 as jn,aa as Za,ab as hs,ac as Jt,ad as Xr,ae as to,af as el,ag as tl,ah as rn,ai as so,aj as no,ak as sl,al as nl,am as vs,an as ns,ao as rl,ap as il,aq as ol,ar as al,as as qn,at as ll,au as cl,av as ul,aw as dl,ax as fl,ay as ml,az as pl,aA as hl,aB as Qr,aC as gl,aD as bl,aE as xl,aF as yl,aG as vl,aH as Vs,aI as wl,aJ as jl,aK as ro,aL as Ge,aM as kl,aN as Sl,aO as Nl,aP as Cl,aQ as Rl,aR as El,aS as Hn,aT as Il,aU as Al,aV as Pl,aW as Tl,aX as Dl,aY as io,aZ as _l,a_ as Ml,a$ as zl,b0 as Ol,b1 as Bl,b2 as Ll,b3 as $l,b4 as Fl,b5 as Wl,b6 as Vl,b7 as Ul,b8 as Gl,b9 as Kl,ba as ql,bb as Hl,bc as Jl,bd as Yl,be as Xl,bf as Ql,bg as Zl,bh as ec,bi as tc,bj as sc,bk as nc,bl as rc,bm as ic,bn as oc,bo as ac,bp as lc,bq as cc,br as uc}from"./useAppFontEffects-CeMgbeVa.js";import{u as es,S as Jn,a as dc,b as fc,h as mc,c as oo,d as ao,C as lo,e as pc,s as hc,g as Us,p as gc,f as bc,i as xc,r as Zr,j as yc,k as vc,D as wc,N as jc,l as kc,m as Sc,n as Nc,B as Cc,o as Rc,q as Ec,t as Ic,v as Ac,w as Pc,T as Tc,P as Dc,O as _c,x as Mc,y as zc,z as Oc,A as Bc,E as Lc,F as $c,G as Fc,H as Wc,I as Vc,J as Uc,K as Gc,L as Kc,M as qc,Q as Hc,R as Jc,U as Yc,V as Xc,W as Qc,X as Zc,Y as eu,Z as tu}from"./runtimeEndpointReset-Cu6RUve4.js";import{_ as os}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as su,A as nu}from"./SettingsView-Dp9jubRs.js";import{PlanView as ru}from"./PlanView-DP9DOnI-.js";import{p as iu}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as ou}from"./vendor-capacitor-core-B4EWRrHz.js";import{k as Dn,d as au,M as Xs,J as _n,s as co,a as Yn,p as lu,_ as ei,f as Xn,V as cu,K as ti,P as uu,b as du,c as fu,U as mu,Z as pu,Q as hu,r as gu}from"./vendor-remixicon-react-D6dZ0UwF.js";import{f as Qn,h as as,i as Zn,P as er,D as tr,j as sr}from"./vendor-dnd-kit-core-BZknOX2w.js";import{s as nr,S as rr,v as ir,u as or}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as ar}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{c as lr,p as uo}from"./vendor-zustand-BAGL70zf.js";import{toast as Mn}from"./vendor-sonner-DFyL3AvE.js";import{C as bu,a as xu,D as yu,p as si}from"./commitAndPush-CtWGqrtW.js";import{u as vu,a as wu,b as ju,c as ku,i as Su,f as Nu,B as Cu,C as Ru,P as ni}from"./patchFileDiff-BnEHIdM2.js";import{u as Eu,a as Iu,i as Au,S as Pu,b as Tu}from"./SubmoduleDiffSummary-CixkM4fI.js";import{P as Du}from"./PierreDiffViewer-CVx2e1cx.js";import{o as _u}from"./openSessionFromRoute-BIlcJIf3.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-CxRSdNoV.js";import"./vendor-opencode-client-Byb4ZSqI.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-base-ui-DWgyZK2k.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-tanstack-react-virtual--0sBrLRh.js";import"./vendor-tanstack-virtual-core-BoA4iGMw.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./contextPanelEmbeddedChat-CirXEPJq.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-CZcLdzDM.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state--21VQleR.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-8PpN-8l4.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Kgp6fZRE.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DetzHhtC.js";import"./vendor-codemirror-lang-json-CkdBRvqj.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-DY4CGDG2.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CQnNjmg9.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-CdG1RXm1.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-B8HKnqZy.js";import"./vendor-codemirror-lang-python-B4MRHRva.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ConqfjLn.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./space-apply-CgJ5JYPK.js";import"./GuestAttachDialog-DO4x4vIR.js";import"./PluginPane-rZvoMQSi.js";import"./vendor-cron-parser-CjvYVigk.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-yaml-3778uTud.js";import"./shikiHighlight-CcVzlYit.js";import"./vendor-codemirror-search-BZNojiZO.js";import"./vendor-replit-codemirror-vim-EX7OnecQ.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./appThemeRegistry-DU-UKEHq.js";import"./textMateThemeFromAppTheme-CAOCeVjl.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-strip-json-comments-5dJlOkP1.js";import"./useInlineCommentController-U97JJifS.js";import"./CodeMirrorCommentWidgets-qlshRzAf.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./changesTree-CePHbFcj.js";import"./parseDiffFromFile-DeZzEah8.js";import"./computeVirtualFileMetrics-BmhViPMt.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./vendor-diff-C3JhlQdm.js";import"./VirtualizedFileDiff-B-U_aQwV.js";import"./isDiffPlainText-CPDhzF1K.js";import"./Virtualizer-D_a8gKmg.js";let fo=null,ri=!1;const Mu=new Promise(n=>{fo=n});function zu(){ri||(ri=!0,fo?.())}const Ou=6,Bu=n=>n.parentID??null,ii=n=>{const e=n.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},Lu=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),$u=(n,e)=>{if(!n)return"";let s=null,i=-1;for(const r of e){const o=Lu(r.path);(n===o||n.startsWith(`${o}/`))&&o.length>i&&(s=r,i=o.length)}return s?s.label?.trim()||ii(s.path):ii(n)},Fu=()=>{const n=ss.getState().activeSessions,e=Ra.getState().index.session.unseenCount,s=Oe.getState().notifyOnSubtasks,i=Ze.getState().projects,r=Tn.getState().ids,o=Li.getState().rankById;let c=0;const l=[];for(const a of n){const u=Bu(a)!==null,g=(e[a.id]??0)>0&&(!u||s);g&&(c+=1),u||l.push({session:a,unread:g,project:$u($i(a),i)})}l.sort((a,u)=>Ea(a.session,u.session,r,o));const m=l.slice(0,Ou).map(({session:a,unread:u,project:p})=>({id:a.id,title:a.title??"",unread:u,project:p}));return{runtimeKey:Ps(),attentionCount:c,recentSessions:m}},Wu="__OPENCHAMBER_WIDGET_SNAPSHOT__",Vu=()=>{typeof window>"u"||(window[Wu]=()=>{try{return JSON.stringify(Fu())}catch{return null}})},kn="mobile-app-update-available",oi="mobile-app-update-toast-dismissed-version",Uu=()=>{const n=de.c(8),{t:e}=ge(),s=es(Gu),i=es(Ku),r=es(qu),o=es(Hu);let c;n[0]===Symbol.for("react.memo_cache_sentinel")?(c=new Set,n[0]=c):c=n[0];const l=Pn.useRef(c);let m,a;return n[1]!==s||n[2]!==o||n[3]!==i||n[4]!==e||n[5]!==r?(m=()=>{if(zi()!=="android"||i!=="mobile"||!s||!r||!o){we.dismiss(kn);return}Wr().getItem(oi)!==r&&(l.current.has(r)||(l.current.add(r),we.info(e("mobileUpdate.toast.available.title"),{id:kn,description:e("mobileUpdate.toast.available.description",{version:r}),duration:1/0,icon:t.jsx(J,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{Ia(o)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{Wr().setItem(oi,r),we.dismiss(kn)}}})))},a=[s,o,i,e,r],n[1]=s,n[2]=o,n[3]=i,n[4]=e,n[5]=r,n[6]=m,n[7]=a):(m=n[6],a=n[7]),Pn.useEffect(m,a),null};function Gu(n){return n.available}function Ku(n){return n.runtimeType}function qu(n){return n.info?.version}function Hu(n){return n.info?.downloadUrl}const ai=300,Ju="openchamber.mobile.connectLog.v1",ts=[];if(typeof window<"u")try{window.localStorage.removeItem(Ju)}catch{}const cr=(n,e)=>{ts.push({at:Date.now(),step:n,detail:e}),ts.length>ai&&ts.splice(0,ts.length-ai)};typeof window<"u"&&cr("app:launch","{}");const Yu=()=>[...ts],Xu=n=>{const e=new Date(n),s=(i,r=2)=>String(i).padStart(r,"0");return`${s(e.getHours())}:${s(e.getMinutes())}:${s(e.getSeconds())}.${s(e.getMilliseconds(),3)}`},mo=n=>`${Xu(n.at)} ${n.step}${n.detail&&n.detail!=="{}"?` ${n.detail}`:""}`,Qu=()=>ts.map(mo).join(`
3
+ `),po=(n,e)=>{const s=de.c(10),i=700,r=f.useRef(null),o=f.useRef(null),c=f.useRef(!1);let l;s[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{r.current!==null&&window.clearTimeout(r.current),r.current=null,o.current=null},s[0]=l):l=s[0];const m=l;let a,u;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=()=>m,u=[m],s[1]=a,s[2]=u):(a=s[1],u=s[2]),f.useEffect(a,u);let p;s[3]!==i||s[4]!==n?(p=v=>{c.current=!1,o.current={x:v.clientX,y:v.clientY},r.current!==null&&window.clearTimeout(r.current),r.current=window.setTimeout(()=>{r.current=null,c.current=!0,n()},i)},s[3]=i,s[4]=n,s[5]=p):p=s[5];const g=p;let h;s[6]===Symbol.for("react.memo_cache_sentinel")?(h=v=>{const N=o.current;N&&(Math.abs(v.clientX-N.x)>10||Math.abs(v.clientY-N.y)>10)&&m()},s[6]=h):h=s[6];const b=h;let k;s[7]===Symbol.for("react.memo_cache_sentinel")?(k=v=>{c.current&&(c.current=!1,v.preventDefault(),v.stopPropagation())},s[7]=k):k=s[7];const y=k;let E;return s[8]!==g?(E={onPointerDown:g,onPointerMove:b,onPointerUp:m,onPointerCancel:m,onClickCapture:y},s[8]=g,s[9]=E):E=s[9],E},Qs="openchamber.mobile.connections.v1",Zu="openchamber.mobile.",li="openchamber.mobile.deviceId",ed=()=>{try{const n=window.localStorage.getItem(li);if(n&&n.trim())return n.trim();const e=crypto.randomUUID();return window.localStorage.setItem(li,e),e}catch{return crypto.randomUUID()}},ci=()=>`mobile:${ed()}`,ui=()=>{try{const n=ou.getPlatform();return n==="ios"||n==="android"?n:void 0}catch{return}},ho=12,go=8e3,td=2500,sd=3e3,Zs=2500,nd=()=>{let n=0;return{begin:()=>(n+=1,n),cancel:()=>{n+=1},isCurrent:e=>e===n}},ds=n=>{const e=n.trim();if(!e)return"";const s=/^https?:\/\//i.test(e)?e:`http://${e}`,i=new URL(s);return i.hash="",i.search="",i.pathname=i.pathname.replace(/\/+$/,""),i.toString().replace(/\/+$/,"")},qs=n=>{try{return new URL(n).host}catch{return n}},ls=n=>{try{return ds(n)}catch{return n.trim().replace(/\/+$/g,"")}},bo=(n,e)=>ls(n)===ls(e),xo=n=>`relay:${n.serverId}@${n.relayUrl.trim()}`,rd=n=>`relay://${n.serverId}`,on=n=>n.candidates.filter(e=>e.kind==="direct"),Mt=n=>{const e=n.candidates.find(s=>s.kind==="relay");return e&&e.kind==="relay"?e.relay:null},jt=n=>{const e=on(n)[0];if(e)return e.url;const s=Mt(n);return s?rd(s):""},Le=n=>{const e=Mt(n);if(e)return xo(e);const s=on(n)[0];return s?ls(s.url):""},en=(n,e)=>{const s=n.find(o=>o.kind==="relay"),i=s&&s.kind==="relay"?s.relay.serverId:null,r=new Set(n.filter(o=>o.kind==="direct").map(o=>ls(o.url)));return e.some(o=>o.kind==="relay"?i!==null&&o.relay.serverId===i:r.has(ls(o.url)))},ur=n=>{const e=(()=>{try{return ds(n)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},di=n=>{if(n.candidates&&n.candidates.length>0)return n.candidates;const e=[];return typeof n.url=="string"&&n.url.trim()&&!/^relay:\/\//i.test(n.url.trim())&&e.push(...ur(n.url)),n.relay&&e.push({kind:"relay",relay:n.relay}),e},dr=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;const e=n;if(typeof e.relayUrl!="string"||!e.relayUrl.trim()||typeof e.serverId!="string"||!e.serverId.trim())return null;const s=e.hostEncPubJwk;if(!s||typeof s!="object"||Array.isArray(s))return null;const i=s;return i.kty!=="EC"||i.crv!=="P-256"||typeof i.x!="string"||!i.x||typeof i.y!="string"||!i.y?null:{relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:i.x,y:i.y}}},yo=n=>{try{return JSON.stringify(n)}catch{return String(n)}},Ce=(n,e={})=>{const s=yo(e);console.info("[mobile-connect]",n,s),cr(n,s)},gs=(n,e={})=>{Ce(n,e)},cs=(n,e={})=>{const s=yo(e);console.info("[mobile-storage]",n,s),cr(n,s)},id=n=>{if(typeof n!="string")return n;try{return JSON.parse(n)}catch{return n}},od=n=>{if(typeof n!="string")return n??void 0;try{return JSON.parse(n)}catch{return n}},ad=async(n,e)=>{if(!We())return null;try{const{CapacitorHttp:s}=await os(async()=>{const{CapacitorHttp:o}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:o}},[]),i=ba(n,new Headers(e?.headers)),r=await s.request({url:n,method:e?.method||"GET",headers:Object.fromEntries(i.entries()),data:od(e?.body)});return{ok:r.status>=200&&r.status<300,status:r.status,source:"native-http",json:async()=>id(r.data)}}catch(s){return Ce("native-http:failed",{url:n,error:s instanceof Error?s.message:String(s)}),null}},ld=async(n,e)=>{const s=await fetch(n,e).catch(i=>(Ce("browser-fetch:failed",{url:n,error:i instanceof Error?i.message:String(i)}),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},Ct=async(n,e,s)=>{let i;const r=new Promise(o=>{i=window.setTimeout(()=>{s?.(),o(null)},n)});try{return await Promise.race([e,r])}catch{return null}finally{i!==void 0&&window.clearTimeout(i)}},zt=async(n,e,s)=>{const i=s?.totalTimeoutMs??go,r=Date.now(),o=await Ct(Math.min(td,i),ad(n,e));if(o)return o;const c=new AbortController,l=Math.max(500,i-(Date.now()-r));return Ct(l,ld(n,{...e,signal:c.signal}),()=>c.abort())},an=async n=>{if(!n)return null;const e=await n.json().catch(()=>null);if(!e||typeof e!="object")return null;const s=e;return{authenticated:typeof s.authenticated=="boolean"?s.authenticated:void 0,disabled:typeof s.disabled=="boolean"?s.disabled:void 0,scope:typeof s.scope=="string"?s.scope:void 0}},us=15e3,cd=async(n,e,s,i=us,r)=>{const o=Oi({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk}),c=l=>l==="ok"&&r?.keepTunnel?{outcome:l,tunnel:o}:(o.close(),{outcome:l});try{const l=e?{Authorization:`Bearer ${e}`}:void 0,m=await Ct(i,o.fetch("/auth/session",{headers:l}).catch(()=>null));if(Ce("relay:session",{ok:m?.ok===!0,status:m?.status??null,hasToken:!!e}),!m)return c("unreachable");if(m.status===401)return c(e?"auth-failed":"needs-login");if(!m.ok&&m.status!==404)return c("auth-failed");const a=await an(m);return a&&a.disabled!==!0&&a.authenticated===!1?c(e?"auth-failed":"needs-login"):c("ok")}catch(l){throw o.close(),l}},ud=(n,e,s,i,r)=>{const o=typeof window<"u"?window.location.origin:"",c={relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk,...s?{grant:s}:{}};r&&ga(c,r),Qt({apiBaseUrl:o,clientToken:e,runtimeKey:i??xo(n),relay:c})},dd=n=>{if(!n||typeof n!="object")return null;const e=n;if(e.kind==="direct")return typeof e.url=="string"&&e.url.trim()?{kind:"direct",url:e.url}:null;if(e.kind==="relay"){const s=dr(e.relay);return s?{kind:"relay",relay:s}:null}return null},fd=n=>{if(n.mode==="relay"){const e=dr(n.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof n.url=="string"?ur(n.url):[]},Ot=()=>{if(typeof window>"u")return[];let n;try{n=JSON.parse(window.localStorage.getItem(Qs)||"[]")}catch{return[]}if(!Array.isArray(n))return[];const e=We();return n.flatMap(s=>{if(!s||typeof s!="object")return[];const i=s;if(typeof i.id!="string")return[];const r=Array.isArray(i.candidates)?i.candidates.map(dd).filter(m=>!!m):fd(i);if(r.length===0)return[];const o=typeof i.clientToken=="string"&&i.clientToken.trim()?i.clientToken:void 0,c=typeof i.label=="string"&&i.label.trim()?i.label:qs(jt({candidates:r})),l={id:i.id,label:c,candidates:r,lastUsedAt:typeof i.lastUsedAt=="number"?i.lastUsedAt:0};return e?[{...l,hasToken:!!i.hasToken||!!o}]:[{...l,clientToken:o,hasToken:!!o}]}).sort((s,i)=>i.lastUsedAt-s.lastUsedAt)},zn=n=>n.kind==="relay"?{kind:"relay",relay:{relayUrl:n.relay.relayUrl,serverId:n.relay.serverId,hostEncPubJwk:n.relay.hostEncPubJwk}}:{kind:"direct",url:n.url},fr=n=>{if(typeof window>"u")return;const e=We(),s=n.slice(0,ho).map(i=>{const r={id:i.id,label:i.label,candidates:i.candidates.map(zn),lastUsedAt:i.lastUsedAt};return e?{...r,hasToken:!!(i.hasToken||i.clientToken)}:{...r,clientToken:i.clientToken}});try{window.localStorage.setItem(Qs,JSON.stringify(s))}catch(i){console.warn("[mobile-storage] failed to persist connection metadata",i)}},vo=(n,e)=>{const s=n.find(o=>e.id&&o.id===e.id||en(o.candidates,e.candidates)),i=We(),r={id:e.id||s?.id||crypto.randomUUID(),label:e.label,candidates:e.candidates,lastUsedAt:Date.now(),...i?{hasToken:e.hasToken??(!!e.clientToken||s?.hasToken||!1)}:{clientToken:e.clientToken??s?.clientToken,hasToken:!!(e.clientToken??s?.clientToken)}};return[r,...n.filter(o=>o.id!==r.id&&!en(o.candidates,e.candidates))].slice(0,ho)},mr=iu,md=0,pr=n=>`${Zu}token.${encodeURIComponent(n)}`,pd=async(n,e)=>{let s;const i=new Promise(r=>{s=window.setTimeout(()=>r(e),sd)});try{return await Promise.race([n.catch(()=>e),i])}finally{s!==void 0&&window.clearTimeout(s)}},hr=async(n,e,s)=>We()?pd(e().catch(i=>(console.warn(`[mobile-storage] ${n} failed`,i),s)),s):s,Es=async n=>{cs("secure:read-start",{key:n});const e=await hr("secure:read",async()=>(await mr.internalGetItem({prefixedKey:pr(n),sync:!1})).data,null),s=typeof e=="string"&&e.trim()?e:void 0;return cs("secure:read",{key:n,hasToken:!!s}),s},Dt=async(n,e)=>{cs("secure:write-start",{key:n});const s=await hr("secure:write",async()=>(await mr.internalSetItem({prefixedKey:pr(n),data:e,sync:!1,access:md}),!0),!1);return cs("secure:write",{key:n,ok:s}),s},hd=async n=>{await hr("secure:delete",async()=>(await mr.internalRemoveItem({prefixedKey:pr(n),sync:!1}),!0),!1)},gd=async(n,e)=>{let s=0,i=0;return{records:await Promise.all(n.map(async o=>{if(!o||typeof o!="object")return o;const c=o,l=typeof c.url=="string"?c.url:null,m=typeof c.clientToken=="string"?c.clientToken.trim():"";if(!l||!m)return o;if(!await e(l,m))return i+=1,o;s+=1;const{clientToken:a,...u}=c;return{...u,hasToken:!0}})),migrated:s,failed:i}},wo=async()=>{if(typeof window>"u"||!We())return;let n;try{n=JSON.parse(window.localStorage.getItem(Qs)||"[]")}catch{return}if(!Array.isArray(n))return;const e=n.filter(i=>!!i&&typeof i=="object"&&typeof i.url=="string"&&typeof i.clientToken=="string"&&!!i.clientToken.trim());if(e.length===0)return;cs("secure:migrate-start",{count:e.length});const s=await gd(n,async(i,r)=>{const o=ls(i);return await Dt(o,r)?await Es(o)===r:!1});if(s.migrated>0)try{window.localStorage.setItem(Qs,JSON.stringify(s.records))}catch(i){console.warn("[mobile-storage] failed to finalize secure token migration",i);return}cs("secure:migrate-done",{migrated:s.migrated,failed:s.failed})},bd=async()=>(await wo(),Ot()),tn=async n=>{const e=vo(Ot(),n);return fr(e),We()&&n.clientToken&&await Dt(Le({candidates:n.candidates}),n.clientToken),e},xd=async n=>{const e=Ot(),s=e.find(r=>r.id===n)??null,i=e.filter(r=>r.id!==n);return fr(i),s&&We()&&await hd(Le(s)),i},yd=1500,sn=async(n,e,s)=>{const i=s?.fast?{totalTimeoutMs:Zs}:void 0,r=Mt({candidates:n})?.serverId??null,o=n.find(a=>a.kind==="relay")??null,c=n.filter(a=>a.kind==="direct"),l=async()=>{for(const a of c){const u=ds(a.url)||a.url,p=e?{Authorization:`Bearer ${e}`}:void 0,g=await zt(`${u}/health`,{method:"GET"},i);if(Ce("probe:direct:health",{url:u,ok:g?.ok===!0,status:g?.status??null,source:g?.source??null}),!g?.ok)continue;if(r){const y=await g.json().catch(()=>null),E=y&&typeof y=="object"?y.serverId:null;if(typeof E=="string"&&E&&E!==r){Ce("probe:server-id-mismatch",{url:u});continue}}const h=await zt(`${u}/auth/session`,{method:"GET",credentials:e?"omit":"include",headers:p},i);if(Ce("probe:direct:session",{url:u,ok:h?.ok===!0,status:h?.status??null,source:h?.source??null,hasToken:!!e}),h?.status===401)return{status:"needs-login"};if(!h||!h.ok&&h.status!==404)continue;const b=await an(h);if(b&&b.disabled!==!0&&b.authenticated===!1)return{status:"needs-login"};const k=b?.disabled===!0;return!e&&We()&&!k&&b?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:u}}}return{status:"unreachable"}},m=async()=>{if(!o)return{status:"unreachable"};const{outcome:a,tunnel:u}=await cd(o.relay,e,void 0,s?.fast?Zs:go,{keepTunnel:!0});return a==="ok"?{status:"ok",transport:{kind:"relay",relay:o.relay,tunnel:u}}:a==="needs-login"||a==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return o?c.length===0?m():new Promise(a=>{let u=!1,p=!1,g,h=null,b=null;const k=v=>{v?.status==="ok"&&v.transport.kind==="relay"&&v.transport.tunnel?.close()},y=v=>{u||(u=!0,a(v))},E=()=>{p||u||(g!==void 0&&(window.clearTimeout(g),g=void 0),m().then(v=>{if(b=v,u||p){k(v);return}if(v.status==="ok"||v.status==="needs-login"){y(v);return}h&&y(h)}))};l().then(v=>{if(h=v,!u){if(v.status==="ok"||v.status==="needs-login"){p=!0,g!==void 0&&window.clearTimeout(g),k(b),y(v);return}if(b){y(b);return}E()}}),g=window.setTimeout(E,yd)}):l()},_t=(n,e,s)=>{n.kind==="relay"?ud(n.relay,e,s?.grant,s?.runtimeKey,n.tunnel):Qt({apiBaseUrl:n.url,clientToken:e,runtimeKey:s?.runtimeKey}),ko()},ws=()=>{const n=Ot()[0];return n?.label?.trim()?n.label:null},bs=async n=>{const e=n?.fast!==!1;await wo();const s=Ot()[0];if(Ce("auto-connect:start",{hasCandidate:!!s,fast:e}),!s)return{status:"no-candidate"};let i;if(We()){if(s.hasToken&&(i=await Es(Le(s)),!i))return{status:"no-candidate"}}else if(i=s.clientToken,!i&&s.hasToken)return{status:"no-candidate"};const r=await sn(s.candidates,i,{fast:e});return Ce("auto-connect:probe",{status:r.status,candidates:s.candidates.map(o=>o.kind)}),r.status==="needs-login"?{status:"needs-login",label:s.label}:r.status!=="ok"?{status:"unreachable",label:s.label}:n?.skipIfConnected&&pt()?(r.transport.kind==="relay"&&r.transport.tunnel?.close(),Ce("auto-connect:superseded",{}),{status:"no-candidate"}):(await tn({id:s.id,label:s.label,candidates:s.candidates}),_t(r.transport,i??null,{runtimeKey:Le(s)}),{status:"connected"})},vd=async(n,e)=>{let s="";try{s=ds(n.url)}catch{return!1}if(!s)return!1;const i=n.clientToken?.trim()||void 0,r=i?{Authorization:`Bearer ${i}`}:void 0,o=e?.fast?{totalTimeoutMs:Zs}:void 0;if(!(await zt(`${s}/health`,{method:"GET",headers:r},o))?.ok)return!1;const l=await zt(`${s}/auth/session`,{method:"GET",credentials:i?"omit":"include",headers:r},o);if(!l||!l.ok&&l.status!==404)return!1;const m=await an(l);return!(m&&m.disabled!==!0&&m.authenticated===!1)},wd=n=>[...n].sort((e,s)=>{const i=(e.priority??100)-(s.priority??100);if(i!==0)return i;const r=o=>o.type==="relay"?2:o.url.startsWith("https://")?0:1;return r(e)-r(s)}).flatMap(e=>{if(e.type==="relay"){const s=dr({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return ur(e.url)}),fi=async n=>{const e=Mt({candidates:n})?.serverId??null;for(const s of n){if(s.kind==="relay"){const o=Oi(s.relay),c=await Ct(us,o.fetch("/health").catch(()=>null));if(Ce("establish:relay:health",{ok:c?.ok===!0,status:c?.status??null}),c?.ok)return{kind:"relay",relay:s.relay,tunnel:o};o.close();continue}const i=ds(s.url)||s.url,r=await zt(`${i}/health`,{method:"GET"});if(Ce("establish:direct:health",{ok:r?.ok===!0,status:r?.status??null}),!!r?.ok){if(e){const o=await r.json().catch(()=>null),c=o&&typeof o=="object"?o.serverId:null;if(typeof c=="string"&&c&&c!==e){Ce("establish:server-id-mismatch",{url:i});continue}}return{kind:"direct",url:i}}}return null},jd=async(n,e)=>{if(!Rs())return vd(n,e);const s=await Ct(e?.fast?Zs:us,Fn("/auth/session").then(r=>r).catch(()=>null));if(!s)return!0;if(s.status===401)return!1;if(!s.ok&&s.status!==404)return!0;const i=await an(s);return!(i&&i.disabled!==!0&&i.authenticated===!1)},kd=n=>n.kind==="relay"?Rs():!Rs()&&bo(n.url,pt()),jo=()=>{const n=Ps();return n?Ot().find(e=>Le(e)===n)??null:null},mi=n=>{const e=Ps();return!!e&&Le(n)===e},Hs=async n=>{const e=n?.fast!==!1,s=jo();if(!s)return Ce("reprobe:no-connection",{runtimeKey:!!Ps()}),"no-connection";let i;if(We()?i=s.hasToken?await Es(Le(s)):void 0:i=s.clientToken,!i&&s.hasToken)return Ce("reprobe:no-token",{hasToken:!0}),"unreachable";Ce("reprobe:start",{candidates:s.candidates.map(a=>a.kind),fast:e,hasToken:!!i});const r=s.candidates.findIndex(a=>kd(a.kind==="relay"?{kind:"relay",relay:a.relay}:{kind:"direct",url:a.url})),o=r>=0?s.candidates.slice(0,r):s.candidates,c=await sn(o,i,{fast:e});if(Ce("reprobe:better",{status:c.status,probed:o.length}),c.status==="ok")return await tn({id:s.id,label:s.label,candidates:s.candidates}),_t(c.transport,i??null,{runtimeKey:Le(s)}),"switched";if(c.status==="needs-login")return"needs-login";if(r>=0){const a=await jd({url:pt(),clientToken:i},{fast:e});if(Ce("reprobe:current",{stillValid:a}),a)return ko(),"unchanged"}const l=r>=0?s.candidates.slice(r+1):[],m=await sn(l,i,{fast:e});return Ce("reprobe:fallback",{status:m.status,probed:l.length}),m.status==="ok"?(await tn({id:s.id,label:s.label,candidates:s.candidates}),_t(m.transport,i??null,{runtimeKey:Le(s)}),"switched"):m.status==="needs-login"?"needs-login":"unreachable"},Sd=5e3;let Sn=!1;const Nd=async()=>{if(Sn)return"skipped";const n=jo();if(!n)return Ce("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=Mt(n);if(!e)return Ce("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";Sn=!0;try{const s=await Ct(us,Fn("/api/client-auth/connection/candidates").then(a=>a).catch(()=>null));if(!s?.ok)return Ce("candidates:refresh-skip",{reason:"fetch-failed",status:s?.status??null}),"skipped";const i=await s.json().catch(()=>null);if(!i||i.serverId!==e.serverId)return Ce("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const r=Array.isArray(i.candidates)?i.candidates:[],o=[];for(const a of r){if(!a||typeof a!="object")continue;const u=a;if(!(u.type!=="lan"||typeof u.url!="string"))try{const p=ds(u.url);p&&!o.includes(p)&&o.push(p)}catch{}}if(o.length===0)return Ce("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const c=on(n).filter(a=>a.url.startsWith("https://")),l=[...o.map(a=>({kind:"direct",url:a})),...c,{kind:"relay",relay:e}];return JSON.stringify(n.candidates.map(zn))===JSON.stringify(l.map(zn))?"unchanged":(Ce("candidates:refreshed",{lanCount:o.length}),await tn({id:n.id,label:n.label,candidates:l}),"updated")}finally{Sn=!1}},ko=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const n=await Nd().catch(()=>"skipped");Ce("candidates:refresh-result",{result:n}),n==="updated"&&Rs()&&await Hs().catch(()=>null)})()},Sd)},So=n=>{const{t:e}=ge(),[s,i]=f.useState(()=>Ot()),[r,o]=f.useState(null),[c,l]=f.useState(null),[m,a]=f.useState(null),u=f.useRef(s),p=f.useRef(null),g=f.useRef(nd()),h=f.useCallback(S=>{u.current=S,i(S)},[]),b=f.useCallback(S=>{p.current=S,o(S)},[]),k=f.useCallback(S=>{p.current===S&&(p.current=null,o(null))},[]);f.useEffect(()=>{let S=!1;return bd().then(C=>{S||h(C)}),()=>{S=!0}},[h]);const y=f.useCallback(S=>{const C=vo(u.current,S);return h(C),fr(C),C},[h]),E=f.useCallback(async S=>{l(null),b("connect");try{const C=di(S);if(C.length===0){l(e("mobile.connect.error.urlRequired"));return}const w=S.id?u.current.find(V=>V.id===S.id):u.current.find(V=>en(V.candidates,C)),T=S.label?.trim()||w?.label||qs(jt({candidates:C})),M=S.relayGrant;let z=S.clientToken?.trim()||void 0;const j=!!z;z||(We()?w?.hasToken&&(z=await Es(Le({candidates:C}))):z=w?.clientToken),Ce("connect:start",{candidates:C.map(V=>V.kind),hasToken:!!z});const P=await sn(C,z);if(Ce("connect:probe",{status:P.status}),P.status==="unreachable"){l(e("mobile.connect.error.unreachable"));return}if(P.status==="needs-login"){y({id:w?.id,label:T,candidates:C}),a({id:w?.id??crypto.randomUUID(),label:T,candidates:C,relay:Mt({candidates:C})??void 0,relayGrant:M});return}z&&j&&We()&&await Dt(Le({candidates:C}),z),y({id:w?.id,label:T,candidates:C,clientToken:z}),_t(P.transport,z??null,{runtimeKey:Le({candidates:C}),grant:M}),n()}catch(C){console.warn("[mobile-connect] connect threw",C),l(e("mobile.connect.error.invalidUrl"))}finally{k("connect")}},[b,k,n,y,e]),v=f.useCallback(async S=>{if(p.current==="pairing")return;l(null),b("pairing");const C=wd(S.candidates);let w=null,T=!1;try{if(w=await fi(C),!w){l(e("mobile.connect.error.unreachable"));return}const M=JSON.stringify({pairingId:S.pairingId,secret:S.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:ui(),dedupeKey:ci()}),z={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:M},j=w.kind==="relay"?await Ct(us,w.tunnel.fetch("/api/client-auth/pairing/redeem",z).catch(()=>null)):await zt(`${w.url}/api/client-auth/pairing/redeem`,z);if(!j?.ok){l(e("mobile.connect.error.authRequired"));return}const P=await j.json().catch(()=>null),V=typeof P?.clientToken=="string"?P.clientToken.trim():"";if(!V){l(e("mobile.connect.error.authRequired"));return}const I=typeof P?.server?.label=="string"?P.server.label:"",D=S.label||I||qs(jt({candidates:C}));if(We()&&!await Dt(Le({candidates:C}),V)){l(e("mobile.connect.error.authRequired"));return}y({label:D,candidates:C,clientToken:V}),_t(w.kind==="relay"?{kind:"relay",relay:w.relay,tunnel:w.tunnel}:{kind:"direct",url:w.url},V,{runtimeKey:Le({candidates:C})}),T=w.kind==="relay",n()}catch(M){console.warn("[mobile-connect] pairing threw",M),l(e("mobile.connect.error.authRequired"))}finally{!T&&w?.kind==="relay"&&w.tunnel.close(),k("pairing")}},[b,k,n,y,e]),N=f.useCallback(async S=>{if(!m||!S.trim()||p.current==="password")return;l(null),b("password");const C=g.current.begin(),w=()=>g.current.isCurrent(C),{id:T,label:M,candidates:z}=m;let j=null,P=!1;try{if(j=await fi(z),!w())return;if(!j){l(e("mobile.connect.error.unreachable"));return}const V={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:S,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile",clientKind:"mobile",devicePlatform:ui(),dedupeKey:ci()})};Ce("password:start",{transport:j.kind});const I=j.kind==="relay"?await Ct(us,j.tunnel.fetch("/auth/session",V).catch(()=>null)):await zt(`${j.url}/auth/session`,V);if(!w())return;if(Ce("password:done",{ok:I?.ok===!0,status:I?.status??null}),!I?.ok){l(e("mobile.connect.error.passwordFailed"));return}const D=await I.json().catch(()=>null);if(!w())return;const F=typeof D?.clientToken=="string"?D.clientToken.trim():"";if(Ce("password:token",{issued:!!F}),!F){if(j.kind==="direct"&&!We()){y({id:T,label:M,candidates:z}),a(null),_t({kind:"direct",url:j.url},null,{runtimeKey:Le({candidates:z})}),n();return}l(e("mobile.connect.error.authRequired"));return}if(We()&&(!w()||(await Dt(Le({candidates:z}),F),!w()))||!w()||(y({id:T,label:M,candidates:z,clientToken:F}),a(null),_t(j.kind==="relay"?{kind:"relay",relay:j.relay,tunnel:j.tunnel}:{kind:"direct",url:j.url},F,{runtimeKey:Le({candidates:z})}),P=j.kind==="relay",!w()))return;n()}catch(V){if(!w())return;console.warn("[mobile-connect] password threw",V),l(e("mobile.connect.error.passwordFailed"))}finally{!P&&j?.kind==="relay"&&j.tunnel.close(),w()&&k("password")}},[b,k,n,m,y,e]),A=f.useCallback(()=>{g.current.cancel(),k("password"),a(null),l(null)},[k]),x=f.useCallback(async S=>{l(null);let C=di(S);const w=S.id?u.current.find(j=>j.id===S.id)??null:null;if(w){const j=C.filter(I=>I.kind==="direct"),P=on(w).filter(I=>I.url.startsWith("https://")&&!j.some(D=>bo(D.url,I.url))),V=Mt(w);C=[...j,...P,...V?[{kind:"relay",relay:V}]:[]]}if(C.length===0)return l(e("mobile.connect.error.urlRequired")),null;const T=S.clientToken?.trim()||void 0,M=S.label?.trim()||qs(jt({candidates:C}));if(We()){const j=Le({candidates:C});if(T)await Dt(j,T);else if(w?.hasToken){const P=Le(w);if(P&&j&&P!==j){const V=await Es(P);V&&await Dt(j,V)}}}return y({id:S.id,label:M,candidates:C,clientToken:T}).find(j=>en(j.candidates,C))??null},[y,e]),R=f.useCallback(async S=>{const C=u.current.find(T=>T.id===S)??null,w=await xd(S);return h(w),C},[h]);return{connections:s,isBusy:r!==null,isPasswordBusy:r==="password",error:c,pendingConnection:m,connect:E,redeemPairingConnection:v,submitPassword:N,cancelPassword:A,saveConnection:x,removeConnection:R,setError:l}},No=n=>{const e=de.c(31),{onClose:s}=n,{t:i}=ge(),[r,o]=f.useState(!1);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=Yu(),e[0]=c):c=e[0];const l=c;let m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{Fi(Qu()).then(S=>{S.ok&&(o(!0),window.setTimeout(()=>o(!1),2e3))})},e[1]=m):m=e[1];const a=m;let u;e[2]!==i?(u=i("mobile.connectionDebug.title"),e[2]=i,e[3]=u):u=e[3];let p;e[4]!==u?(p=t.jsx("h2",{className:"min-w-0 truncate typography-ui-label text-foreground",children:u}),e[4]=u,e[5]=p):p=e[5];const g=r?"check":"file-copy";let h;e[6]!==g?(h=t.jsx(J,{name:g,className:"size-4"}),e[6]=g,e[7]=h):h=e[7];let b;e[8]!==r||e[9]!==i?(b=i(r?"mobile.connectionDebug.copied":"mobile.connectionDebug.copy"),e[8]=r,e[9]=i,e[10]=b):b=e[10];let k;e[11]!==h||e[12]!==b?(k=t.jsxs(Se,{type:"button",variant:"outline",size:"sm",onClick:a,disabled:l.length===0,children:[h,b]}),e[11]=h,e[12]=b,e[13]=k):k=e[13];let y;e[14]!==i?(y=i("mobile.connectionDebug.close"),e[14]=i,e[15]=y):y=e[15];let E;e[16]===Symbol.for("react.memo_cache_sentinel")?(E=t.jsx(J,{name:"close",className:"size-[18px]"}),e[16]=E):E=e[16];let v;e[17]!==s||e[18]!==y?(v=t.jsx(Se,{type:"button",variant:"ghost",size:"icon","aria-label":y,onClick:s,children:E}),e[17]=s,e[18]=y,e[19]=v):v=e[19];let N;e[20]!==v||e[21]!==k?(N=t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[k,v]}),e[20]=v,e[21]=k,e[22]=N):N=e[22];let A;e[23]!==N||e[24]!==p?(A=t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border/70 px-4 py-2.5",children:[p,N]}),e[23]=N,e[24]=p,e[25]=A):A=e[25];let x;e[26]!==i?(x=t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-3",children:l.length===0?t.jsx("p",{className:"typography-small text-muted-foreground",children:i("mobile.connectionDebug.empty")}):t.jsx("pre",{className:"whitespace-pre-wrap break-words typography-code text-muted-foreground",children:l.map(mo).join(`
4
+ `)})}),e[26]=i,e[27]=x):x=e[27];let R;return e[28]!==A||e[29]!==x?(R=t.jsxs("div",{className:"fixed inset-0 z-[70] flex flex-col bg-background pb-[var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))] pt-[var(--safe-area-inset-top,env(safe-area-inset-top,0px))] text-foreground",children:[A,x]}),e[28]=A,e[29]=x,e[30]=R):R=e[30],R},Co=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&(typeof e.scan=="function"||typeof e.startScan=="function")?e:null},Cd=()=>window.Capacitor?.getPlatform?.()==="android",Ro=n=>{const e=n.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e)){const s=xa(e);return s?{pairing:s}:null}return/^https?:\/\//i.test(e)?{url:e}:null},Eo=(n,e)=>{const s=Ro(n);if(!s&&e?.pairingStringFallback){const i=ya(n);if(i)return{status:"pairing",pairing:i}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},Rd=async(n,e)=>{if(!n.startScan||!n.stopScan||!n.addListener)return{status:"unsupported"};if(e?.aborted)return{status:"cancelled"};let s,i,r=!1,o=()=>{};const c=new Promise(a=>{o=a}),l=a=>{r||(r=!0,o(a))},m=()=>l({status:"cancelled"});e?.addEventListener("abort",m,{once:!0});try{return(await Promise.allSettled([Promise.resolve(n.addListener("barcodesScanned",({barcodes:u})=>{const p=u?.[0],g=(p?.rawValue??p?.displayValue??"").trim();g&&l(Eo(g,{pairingStringFallback:!0}))})).then(u=>{s=u}),Promise.resolve(n.addListener("scanError",()=>l({status:"failed"}))).then(u=>{i=u})])).some(({status:u})=>u==="rejected")?l({status:"failed"}):r||n.startScan({formats:["QR_CODE"]}).catch(()=>l({status:"failed"})),await c}finally{e?.removeEventListener("abort",m),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(i?.remove()),n.stopScan()])}},On=()=>Co()!==null,Io=async n=>{const e=Co();if(!e)return{status:"unsupported"};try{if(e.requestPermissions){const c=(await e.requestPermissions())?.camera;if(c&&c!=="granted"&&c!=="limited")return{status:"permission-denied"}}if(n?.signal?.aborted)return{status:"cancelled"};if(Cd())return Rd(e,n?.signal);if(!e.scan)return{status:"unsupported"};const i=(await e.scan({formats:["QR_CODE"]}))?.barcodes?.[0],r=(i?.rawValue??i?.displayValue??"").trim();return r?Eo(r):{status:"cancelled"}}catch{return{status:"failed"}}},rs={autoComplete:"off",autoCorrect:"off",spellCheck:!1},js="oc-surface-elevated h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-interactive-border-focus focus:ring-2 focus:ring-ring",Ao=n=>{const e=de.c(22),{onCancel:s}=n,{t:i}=ge(),r=f.useRef(null);let o,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>{const E={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},v={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const N=new Map,A=R=>{!(R instanceof HTMLElement)||R===r.current||N.has(R)||(N.set(R,{opacity:R.style.opacity,pointerEvents:R.style.pointerEvents}),R.style.setProperty("opacity","0"),R.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(A);const x=new MutationObserver(R=>{R.forEach(S=>S.addedNodes.forEach(A))});return x.observe(document.body,{childList:!0}),()=>{x.disconnect(),N.forEach(Ed),E.value?document.documentElement.style.setProperty("background-color",E.value,E.priority):document.documentElement.style.removeProperty("background-color"),v.value?document.body.style.setProperty("background-color",v.value,v.priority):document.body.style.removeProperty("background-color")}},c=[],e[0]=o,e[1]=c):(o=e[0],c=e[1]),f.useLayoutEffect(o,c);let l,m;e[2]!==s?(l=()=>{const E=()=>{document.visibilityState==="hidden"&&s()};return document.addEventListener("visibilitychange",E),()=>document.removeEventListener("visibilitychange",E)},m=[s],e[2]=s,e[3]=l,e[4]=m):(l=e[3],m=e[4]),f.useEffect(l,m);let a;e[5]!==i?(a=i("mobile.connect.scanQr"),e[5]=i,e[6]=a):a=e[6];let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),e[7]=u):u=e[7];let p;e[8]!==i?(p=i("mobile.connect.welcome.scanHint"),e[8]=i,e[9]=p):p=e[9];let g;e[10]!==p?(g=t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[u,t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:p})]}),e[10]=p,e[11]=g):g=e[11];let h;e[12]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(J,{name:"close",className:"size-[18px]"}),e[12]=h):h=e[12];let b;e[13]!==i?(b=i("mobile.instances.cancelEdit"),e[13]=i,e[14]=b):b=e[14];let k;e[15]!==s||e[16]!==b?(k=t.jsxs(Se,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:s,children:[h,b]}),e[15]=s,e[16]=b,e[17]=k):k=e[17];let y;return e[18]!==k||e[19]!==a||e[20]!==g?(y=is.createPortal(t.jsxs("div",{ref:r,role:"dialog","aria-modal":"true","aria-label":a,className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[g,k]}),document.body),e[18]=k,e[19]=a,e[20]=g,e[21]=y):y=e[21],y},Po=()=>{const n=de.c(6),{t:e}=ge();let s;n[0]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsx(Zt,{width:96,height:96,isAnimated:!0}),n[0]=s):s=n[0];let i;n[1]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(J,{name:"loader-4",className:"size-[18px] animate-spin"}),n[1]=i):i=n[1];let r;n[2]!==e?(r=e("mobile.connect.connecting"),n[2]=e,n[3]=r):r=n[3];let o;return n[4]!==r?(o=is.createPortal(t.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[s,t.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[i,t.jsx("span",{children:r})]})]}),document.body),n[4]=r,n[5]=o):o=n[5],o};function Ed(n,e){e.style.opacity=n.opacity,e.style.pointerEvents=n.pointerEvents}const Id=({onConnected:n,notice:e=null})=>{const{t:s}=ge(),i=So(n),{connections:r,isBusy:o,isPasswordBusy:c,error:l,pendingConnection:m}=i,[a,u]=f.useState(""),[p,g]=f.useState(""),[h,b]=f.useState(""),[k,y]=f.useState(!1),[E,v]=f.useState(!1),N=f.useRef(null),A=f.useMemo(()=>On(),[]),[x,R]=f.useState(()=>!On()),[S,C]=f.useState(null),[w,T]=f.useState(""),[M,z]=f.useState(!1),j=po(f.useCallback(()=>z(!0),[])),P=f.useCallback(L=>{L.preventDefault(),i.connect({url:a,clientToken:h,label:p})},[h,i,p,a]),V=f.useCallback(L=>{if(/^openchamber:\/\//i.test(L.trim())){const q=Ro(L);if(q){if("pairing"in q){i.redeemPairingConnection(q.pairing);return}u(q.url),q.label&&g(q.label),q.clientToken&&b(q.clientToken);return}}u(L)},[i]),I=f.useCallback(async()=>{if(N.current||o)return;i.setError(null),y(!0);const L=new AbortController;N.current=L;try{const q=await Io({signal:L.signal});switch(N.current===L&&(N.current=null,y(!1)),q.status){case"ok":v(!0),u(q.url),q.label&&g(q.label),q.clientToken&&b(q.clientToken),await i.connect({url:q.url,clientToken:q.clientToken,label:q.label});break;case"pairing":v(!0),await i.redeemPairingConnection(q.pairing);break;case"permission-denied":i.setError(s("mobile.connect.scan.permissionDenied"));break;case"invalid":i.setError(s("mobile.connect.scan.invalid"));break;case"unsupported":i.setError(s("mobile.connect.scan.unsupported"));break;case"failed":i.setError(s("mobile.connect.scan.failed"));break;default:break}}finally{v(!1),N.current===L&&(N.current=null,y(!1))}},[i,o,s]);f.useEffect(()=>()=>N.current?.abort(),[]);const D=f.useCallback(L=>{L.preventDefault(),i.submitPassword(w)},[i,w]),F=f.useCallback(()=>{T(""),i.cancelPassword()},[i]);return t.jsxs(t.Fragment,{children:[k?t.jsx(Ao,{onCancel:()=>N.current?.abort()}):null,E?t.jsx(Po,{}):null,M?t.jsx(No,{onClose:()=>z(!1)}):null,t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx("span",{...j,className:"select-none",style:{touchAction:"manipulation"},children:t.jsx(Zt,{width:72,height:72,className:"size-[72px]"})}),t.jsx("h1",{className:"typography-h2 text-foreground",children:s("mobile.connect.welcome.title")})]}),e?t.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:t.jsx(J,{name:e.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),t.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:e.kind==="auth-expired"?s("mobile.connect.notice.authExpired",{label:e.label}):s("mobile.connect.notice.unreachable",{label:e.label})})]}):null,m?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:D,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(J,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:m.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:m.candidates.some(L=>L.kind==="direct")?jt(m):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...rs,value:w,onChange:L=>T(L.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:js}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,t.jsx(Se,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:c||!w.trim(),children:s(c?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(Se,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:F,children:s("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[A?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(Se,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{I()},disabled:k||o,children:[t.jsx(J,{name:"scan-2",className:Q("size-[18px]",k&&"animate-pulse")}),s(o?"mobile.connect.connecting":"mobile.connect.scanQr")]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:s("mobile.connect.welcome.scanHint")})]}):null,l&&!x?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:s("mobile.connect.saved.title")}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(L=>{const q=S===L.id;return t.jsxs("button",{type:"button",disabled:o,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:opacity-70",onClick:()=>{C(L.id),i.connect({id:L.id,candidates:L.candidates,clientToken:L.clientToken,label:L.label}).finally(()=>C(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(J,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:L.label}),t.jsx("span",{className:Q("block truncate typography-small",q?"text-foreground":"text-muted-foreground"),children:q?s("mobile.connect.connecting"):L.candidates.some(X=>X.kind==="direct")?jt(L):s("mobile.connect.relay.badge")})]}),q?t.jsx(J,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(J,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},L.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[A?t.jsxs("button",{type:"button",onClick:()=>R(L=>!L),"aria-expanded":x,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[t.jsx("span",{children:s("mobile.connect.manual.toggle")}),t.jsx(J,{name:"arrow-down-s",className:Q("size-4 transition-transform duration-200",x&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:x?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:P,children:[t.jsx("input",{...rs,value:a,onChange:L=>V(L.target.value),placeholder:s("mobile.connect.url.placeholder"),"aria-label":s("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:x?void 0:-1,className:Q(js,"text-center")}),t.jsx("input",{value:p,onChange:L=>g(L.target.value),placeholder:s("mobile.instances.label.placeholder"),"aria-label":s("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:x?void 0:-1,className:Q(js,"text-center")}),t.jsx("input",{...rs,value:h,onChange:L=>b(L.target.value),placeholder:s("mobile.connect.token.placeholder"),"aria-label":s("mobile.connect.token.label"),tabIndex:x?void 0:-1,autoCapitalize:"none",className:Q(js,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null,t.jsx(Se,{type:"submit",variant:A?"outline":"default",size:"lg",className:"h-12 w-full",disabled:o||k||!a.trim(),children:s(o?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})]})},Ad=n=>{const e=n.usedPercent;return typeof e!="number"||!Number.isFinite(e)?"text-foreground":e>=80?"text-[var(--status-error)]":e>=50?"text-[var(--status-warning)]":"text-foreground"},Pd=n=>{const e=de.c(12),{groups:s,displayMode:i,timeFormatPreference:r,className:o}=n;let c;e[0]!==o?(c=Q("space-y-1.5",o),e[0]=o,e[1]=c):c=e[1];let l;if(e[2]!==i||e[3]!==s||e[4]!==r){let a;e[6]!==i||e[7]!==r?(a=u=>t.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-2.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Wi,{providerId:u.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:u.providerName}),u.planLabel?t.jsx("span",{className:"shrink-0 typography-micro capitalize text-muted-foreground",children:u.planLabel}):null,u.status&&u.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:u.status}):null]}),u.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:u.rows.map(p=>{const g=i==="remaining"?p.window.remainingPercent:p.window.usedPercent,h=Aa(p.window.valueLabel,g),b=Pa(p.window.resetAt,p.window.resetAfterFormatted??p.window.resetAtFormatted,r);return t.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-3",children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-1.5",children:[t.jsx("span",{className:"shrink-0 truncate typography-ui-label text-muted-foreground",children:p.subtitle?`${p.subtitle} · ${p.label}`:p.label}),b?t.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground/70",children:b}):null]}),t.jsx("span",{className:Q("shrink-0 typography-ui-label font-semibold tabular-nums",Ad(p.window)),children:h==="-"?"":h})]},p.key)})}):null,u.status&&u.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:u.status}):null]},u.providerId),e[6]=i,e[7]=r,e[8]=a):a=e[8],l=s.map(a),e[2]=i,e[3]=s,e[4]=r,e[5]=l}else l=e[5];let m;return e[9]!==c||e[10]!==l?(m=t.jsx("div",{className:c,children:l}),e[9]=c,e[10]=l,e[11]=m):m=e[11],m},pi=380,Td=(n,e)=>{if(!n||typeof n!="object")return;const s=n[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},Nn=n=>n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(n),Dd="—",To=n=>{const e=de.c(20),{percentage:s}=n;let i,r,o,c,l,m,a;if(e[0]!==s){o=Oa(s??0)??0;const h=Ba(s??0);r=h==="critical"?"var(--status-error)":h==="warn"?"var(--status-warning)":"var(--status-success)",i=2*Math.PI*7.5,c="0 0 18 18",l="size-[18px] -rotate-90",m="progressbar",a=s===null?void 0:Math.round(o),e[0]=s,e[1]=i,e[2]=r,e[3]=o,e[4]=c,e[5]=l,e[6]=m,e[7]=a}else i=e[1],r=e[2],o=e[3],c=e[4],l=e[5],m=e[6],a=e[7];let u;e[8]===Symbol.for("react.memo_cache_sentinel")?(u=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=u):u=e[8];let p;e[9]!==i||e[10]!==s||e[11]!==r||e[12]!==o?(p=s===null?null:t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:r,strokeWidth:3,strokeLinecap:"round",strokeDasharray:i,strokeDashoffset:i*(1-o/100),className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=i,e[10]=s,e[11]=r,e[12]=o,e[13]=p):p=e[13];let g;return e[14]!==c||e[15]!==l||e[16]!==m||e[17]!==a||e[18]!==p?(g=t.jsxs("svg",{viewBox:c,className:l,role:m,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,children:[u,p]}),e[14]=c,e[15]=l,e[16]=m,e[17]=a,e[18]=p,e[19]=g):g=e[19],g},_d=n=>{const e=de.c(13),{icon:s,iconNode:i,label:r,children:o}=n;let c;e[0]!==s||e[1]!==i?(c=i??(s?t.jsx(J,{name:s,className:"size-[18px]"}):null),e[0]=s,e[1]=i,e[2]=c):c=e[2];let l;e[3]!==c?(l=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:c}),e[3]=c,e[4]=l):l=e[4];let m;e[5]!==r?(m=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:r}),e[5]=r,e[6]=m):m=e[6];let a;e[7]!==o?(a=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:o}),e[7]=o,e[8]=a):a=e[8];let u;return e[9]!==l||e[10]!==m||e[11]!==a?(u=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[l,m,a]}),e[9]=l,e[10]=m,e[11]=a,e[12]=u):u=e[12],u},Md=n=>{const e=de.c(57),{open:s,onClose:i,anchorRef:r,contextDisplay:o,usageGroups:c,usageDisplayMode:l,isUsageLoading:m,timeFormatPreference:a}=n,{t:u}=ge(),p=f.useRef(null),[g,h]=f.useState(s),[b,k]=f.useState(!1),{enabled:y}=Wn(),E=f.useRef(null),[v,N]=f.useState(null);let A,x;e[0]!==r||e[1]!==y||e[2]!==s||e[3]!==g?(A=()=>{if(!s||!y||!g)return;const le=()=>{const ne=r.current?.getBoundingClientRect(),ie=E.current?.getBoundingClientRect();if(!ne||!ie){N(null);return}const H=ne.left-ie.left,oe=Math.min(Math.max(H,8),Math.max(8,ie.width-pi-8));N(oe)};le();const B=E.current;if(typeof ResizeObserver>"u"||!B)return;const ee=new ResizeObserver(le);return ee.observe(B),()=>ee.disconnect()},x=[r,y,s,g],e[0]=r,e[1]=y,e[2]=s,e[3]=g,e[4]=A,e[5]=x):(A=e[4],x=e[5]),f.useLayoutEffect(A,x);const R=y&&v!==null;let S,C;e[6]!==s||e[7]!==g?(S=()=>{if(s){h(!0),k(!1);return}if(!g)return;k(!0);const le=window.setTimeout(()=>{h(!1),k(!1)},140);return()=>window.clearTimeout(le)},C=[s,g],e[6]=s,e[7]=g,e[8]=S,e[9]=C):(S=e[8],C=e[9]),f.useEffect(S,C);let w,T;e[10]!==i||e[11]!==s?(w=()=>{if(!s)return;const le=B=>{B.key==="Escape"&&i()};return document.addEventListener("keydown",le),()=>document.removeEventListener("keydown",le)},T=[i,s],e[10]=i,e[11]=s,e[12]=w,e[13]=T):(w=e[12],T=e[13]),f.useEffect(w,T);let M,z;if(e[14]!==r||e[15]!==i||e[16]!==s?(M=()=>{if(!s)return;const le=B=>{const ee=B.target;if(!(ee instanceof Node)){i();return}p.current?.contains(ee)||r.current?.contains(ee)||i()};return document.addEventListener("pointerdown",le,!0),document.addEventListener("wheel",le,!0),()=>{document.removeEventListener("pointerdown",le,!0),document.removeEventListener("wheel",le,!0)}},z=[r,i,s],e[14]=r,e[15]=i,e[16]=s,e[17]=M,e[18]=z):(M=e[17],z=e[18]),f.useEffect(M,z),!g)return null;let j;e[19]!==u?(j=u("mobile.header.openMetadataAria"),e[19]=u,e[20]=j):j=e[20];const P=R?"absolute origin-top-left":"mx-3 mt-2",V=b?"pointer-events-none":"pointer-events-auto";let I;e[21]!==P||e[22]!==V?(I=Q("oc-surface-elevated overflow-y-auto overscroll-contain rounded-[20px] border border-border/70 bg-surface-elevated p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",P,V),e[21]=P,e[22]=V,e[23]=I):I=e[23];const D=`${b?"session-metadata-out":"session-metadata-in"} ${b?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let F;e[24]!==v||e[25]!==R?(F=R?{top:8,left:v??8,width:`min(${pi}px, calc(100% - 16px))`}:null,e[24]=v,e[25]=R,e[26]=F):F=e[26];let L;e[27]!==D||e[28]!==F?(L={animation:D,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...F},e[27]=D,e[28]=F,e[29]=L):L=e[29];let q;e[30]!==o||e[31]!==u?(q=o?t.jsx(_d,{iconNode:t.jsx(To,{percentage:o.state==="measured"?o.percentage:null}),label:u("mobile.header.metadata.context"),children:o.state==="pending"?null:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[o.state==="measured"?t.jsxs("span",{className:Q("font-semibold",o.colorClass),children:[o.percentage.toFixed(1),"%"]}):null,t.jsx("span",{className:"text-muted-foreground",children:o.tokens})]})}):null,e[30]=o,e[31]=u,e[32]=q):q=e[32];let X;e[33]!==o?.state||e[34]!==u?(X=o?.state==="compacted"?t.jsx("p",{className:"px-2.5 pb-1 typography-meta text-muted-foreground",children:u("contextUsage.compacted.description")}):null,e[33]=o?.state,e[34]=u,e[35]=X):X=e[35];let Y;e[36]!==o?.state||e[37]!==u?(Y=o?.state==="pending"?t.jsx("p",{className:"px-2.5 pb-1 typography-meta text-muted-foreground",children:u("mobile.header.metadata.contextPending")}):null,e[36]=o?.state,e[37]=u,e[38]=Y):Y=e[38];let W;e[39]!==m||e[40]!==a||e[41]!==l||e[42]!==c?(W=t.jsx(zd,{groups:c,displayMode:l,isLoading:m,timeFormatPreference:a}),e[39]=m,e[40]=a,e[41]=l,e[42]=c,e[43]=W):W=e[43];let Z;e[44]!==q||e[45]!==X||e[46]!==Y||e[47]!==W?(Z=t.jsxs("div",{className:"space-y-1",children:[q,X,Y,W]}),e[44]=q,e[45]=X,e[46]=Y,e[47]=W,e[48]=Z):Z=e[48];let fe;e[49]!==I||e[50]!==L||e[51]!==Z||e[52]!==j?(fe=t.jsx("div",{ref:p,role:"dialog","aria-label":j,className:I,style:L,children:Z}),e[49]=I,e[50]=L,e[51]=Z,e[52]=j,e[53]=fe):fe=e[53];let ae;e[54]===Symbol.for("react.memo_cache_sentinel")?(ae=t.jsx("style",{children:`
5
+ @keyframes session-metadata-in {
6
+ from { opacity: 0; transform: translateY(-8px) scale(0.985); }
7
+ to { opacity: 1; transform: translateY(0) scale(1); }
8
+ }
9
+ @keyframes session-metadata-out {
10
+ from { opacity: 1; transform: translateY(0) scale(1); }
11
+ to { opacity: 0; transform: translateY(-6px) scale(0.985); }
12
+ }
13
+ `}),e[54]=ae):ae=e[54];let te;return e[55]!==fe?(te=t.jsxs("div",{ref:E,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[fe,ae]}),e[55]=fe,e[56]=te):te=e[56],te},zd=n=>{const e=de.c(30),{groups:s,displayMode:i,isLoading:r,timeFormatPreference:o}=n,{t:c}=ge();let l;e[0]!==i||e[1]!==c?(l=c(i==="remaining"?"header.services.remaining":"header.services.used"),e[0]=i,e[1]=c,e[2]=l):l=e[2];const m=l;if(s.length===0){if(!r)return null;let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(J,{name:"loader-4",className:"size-4 animate-spin","aria-hidden":!0}),e[3]=v):v=e[3];let N;e[4]!==c?(N=c("common.loading"),e[4]=c,e[5]=N):N=e[5];let A;return e[6]!==N?(A=t.jsxs("div",{className:"flex items-center justify-center gap-2 px-2.5 py-6 text-muted-foreground",children:[v,t.jsx("span",{className:"typography-ui-label",children:N})]}),e[6]=N,e[7]=A):A=e[7],A}let a;e[8]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(J,{name:"timer",className:"size-[18px]"})}),e[8]=a):a=e[8];let u;e[9]!==c?(u=c("mobile.header.metadata.usage"),e[9]=c,e[10]=u):u=e[10];let p;e[11]!==u?(p=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:u}),e[11]=u,e[12]=p):p=e[12];let g;e[13]!==r?(g=r?t.jsx(J,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[13]=r,e[14]=g):g=e[14];let h;e[15]!==m?(h=t.jsx("span",{className:"truncate",children:m}),e[15]=m,e[16]=h):h=e[16];let b;e[17]!==g||e[18]!==h?(b=t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center justify-end gap-1.5 typography-ui-label text-muted-foreground",children:[g,h]}),e[17]=g,e[18]=h,e[19]=b):b=e[19];let k;e[20]!==p||e[21]!==b?(k=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[a,p,b]}),e[20]=p,e[21]=b,e[22]=k):k=e[22];let y;e[23]!==i||e[24]!==s||e[25]!==o?(y=t.jsx(Pd,{groups:s,displayMode:i,timeFormatPreference:o}),e[23]=i,e[24]=s,e[25]=o,e[26]=y):y=e[26];let E;return e[27]!==k||e[28]!==y?(E=t.jsxs("div",{className:"pt-2.5",children:[k,y]}),e[27]=k,e[28]=y,e[29]=E):E=e[29],E},Od=f.memo(function({open:e,onOpenChange:s,currentSessionId:i,effectiveDirectory:r,isNewSessionDraftOpen:o}){const{t:c}=ge(),l=f.useRef(null),m=Ta(i??"",r||void 0),a=it(I=>I.providers),u=it(I=>I.currentProviderId),p=it(I=>I.currentModelId),g=it(I=>I.getModelMetadata);it(I=>I.modelsMetadata.size);const h=Da(f.useCallback(I=>i?I.sessionModelSelections.get(i)??null:null,[i])),b=Pt(I=>I.results),k=Pt(I=>I.refreshErrors),y=f.useRef(!1),E=Pt(I=>I.loadSettings),v=Pt(I=>I.fetchAllQuotas),N=Pt(I=>I.isLoading),A=Pt(I=>I.displayMode),x=Pt(I=>I.dropdownProviderIds),R=Oe(I=>I.timeFormatPreference);_a(),f.useEffect(()=>{E()},[E]),f.useEffect(()=>{Jr(x)},[x]),f.useEffect(()=>{if(!e){y.current=!1;return}y.current||N||!x.some(D=>!b.some(F=>F.providerId===D)||k[D])||(y.current=!0,v())},[x,v,N,e,b,k]);const C=f.useMemo(()=>{for(let I=m.length-1;I>=0;I-=1){const D=m[I];if(D.role!=="assistant")continue;const F=D.providerID.trim(),L=D.modelID.trim();if(F&&L)return{providerID:F,modelID:L}}return null},[m])??(h?{providerID:h.providerId,modelID:h.modelId}:null)??(u&&p?{providerID:u,modelID:p}:null),T=(C?a.find(I=>I.id===C.providerID):void 0)?.models.find(I=>I.id===C?.modelID),M=C?g(C.providerID,C.modelID):void 0,z=Td(T?.limit,"context")??M?.limit?.context??0,j=f.useMemo(()=>Ma(m),[m]),P=f.useMemo(()=>{if(z<=0)return null;if(o||!j)return{state:"pending"};if(j.state==="compacted")return{state:"compacted",tokens:`${Dd}/${Nn(z)}`};const I=Math.min(j.totalTokens/z*100,999),D=I>=90?"text-[var(--status-error)]":I>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]";return{state:"measured",percentage:I,tokens:`${Nn(j.totalTokens)}/${Nn(z)}`,colorClass:D}},[j,z,o]),V=za();return f.useEffect(()=>{!e||V.length===0||Jr(V.map(I=>I.providerId))},[e,V]),t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:l,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":c("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>s(I=>!I),style:{touchAction:"manipulation"},children:t.jsx(To,{percentage:P?.state==="measured"?P.percentage:P?.state==="compacted"?null:0})}),t.jsx(Md,{open:e,onClose:()=>s(!1),anchorRef:l,contextDisplay:P,usageGroups:V,usageDisplayMode:A,isUsageLoading:N,timeFormatPreference:R})]})}),Bd=10,hi=380,Ld=(n,e)=>n.title?.trim()||e,$d=n=>{const e=de.c(33),{session:s,meta:i,active:r,onSelect:o}=n,{t:c}=ge(),l=Vn(s.id),m=Un(s.id),a=m!==null,u=!a&&l>0&&!r,p=Gn(s.id,a),g=(a||u)&&p,h=s.time?.updated??s.time?.created??0;let b;e[0]!==h?(b=$a(h),e[0]=h,e[1]=b):b=e[1];const k=b,y=r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let E;e[2]!==y?(E=Q("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",y),e[2]=y,e[3]=E):E=e[3];let v;e[4]===Symbol.for("react.memo_cache_sentinel")?(v={touchAction:"manipulation"},e[4]=v):v=e[4];const N=r?"text-primary":"text-foreground";let A;e[5]!==N?(A=Q("block truncate typography-ui-label",N),e[5]=N,e[6]=A):A=e[6];let x;e[7]!==s||e[8]!==c?(x=Ld(s,c("sessions.sidebar.session.untitled")),e[7]=s,e[8]=c,e[9]=x):x=e[9];let R;e[10]!==A||e[11]!==x?(R=t.jsx("span",{className:A,children:x}),e[10]=A,e[11]=x,e[12]=R):R=e[12];let S;e[13]!==i?(S=i?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:i}):null,e[13]=i,e[14]=S):S=e[14];let C;e[15]!==S||e[16]!==R?(C=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[R,S]}),e[15]=S,e[16]=R,e[17]=C):C=e[17];let w;e[18]!==a||e[19]!==u||e[20]!==m?(w=a||u?t.jsx(Ys,{state:m??"unread"}):null,e[18]=a,e[19]=u,e[20]=m,e[21]=w):w=e[21];let T;e[22]!==a||e[23]!==s.id||e[24]!==g||e[25]!==k?(T=g?t.jsx(Jn,{sessionId:s.id,running:a,className:"typography-micro"}):k?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:k}):null,e[22]=a,e[23]=s.id,e[24]=g,e[25]=k,e[26]=T):T=e[26];let M;return e[27]!==o||e[28]!==C||e[29]!==w||e[30]!==T||e[31]!==E?(M=t.jsxs("button",{type:"button",className:E,onClick:o,style:v,children:[C,w,T]}),e[27]=o,e[28]=C,e[29]=w,e[30]=T,e[31]=E,e[32]=M):M=e[32],M},Fd=n=>{const e=de.c(50),{open:s,onClose:i,anchorRef:r}=n,{t:o}=ge(),c=f.useRef(null),[l,m]=f.useState(s),[a,u]=f.useState(!1),{enabled:p}=Wn(),g=f.useRef(null),[h,b]=f.useState(null);let k,y;e[0]!==r||e[1]!==p||e[2]!==s||e[3]!==l?(k=()=>{if(!s||!p||!l)return;const te=()=>{const ee=r.current?.getBoundingClientRect(),ne=g.current?.getBoundingClientRect();if(!ee||!ne){b(null);return}const ie=ee.left-ne.left;b(Math.min(Math.max(ie,8),Math.max(8,ne.width-hi-8)))};te();const le=g.current;if(typeof ResizeObserver>"u"||!le)return;const B=new ResizeObserver(te);return B.observe(le),()=>B.disconnect()},y=[r,p,s,l],e[0]=r,e[1]=p,e[2]=s,e[3]=l,e[4]=k,e[5]=y):(k=e[4],y=e[5]),f.useLayoutEffect(k,y);const E=p&&h!==null,v=_e(Wd),N=_e(Vd),A=Ze(Ud);let x;e[6]===Symbol.for("react.memo_cache_sentinel")?(x={maxParents:Bd},e[6]=x):x=e[6];const R=La(s||l,x);let S,C;e[7]!==s||e[8]!==l?(S=()=>{if(s){Vi(),m(!0),u(!1);return}if(!l)return;u(!0);const te=window.setTimeout(()=>{m(!1),u(!1)},140);return()=>window.clearTimeout(te)},C=[s,l],e[7]=s,e[8]=l,e[9]=S,e[10]=C):(S=e[9],C=e[10]),f.useEffect(S,C);let w,T;e[11]!==i||e[12]!==s?(w=()=>{if(!s)return;const te=le=>{le.key==="Escape"&&i()};return document.addEventListener("keydown",te),()=>document.removeEventListener("keydown",te)},T=[i,s],e[11]=i,e[12]=s,e[13]=w,e[14]=T):(w=e[13],T=e[14]),f.useEffect(w,T);let M,z;e[15]!==r||e[16]!==i||e[17]!==s?(M=()=>{if(!s)return;const te=le=>{const B=le.target;if(!(B instanceof Node)){i();return}c.current?.contains(B)||r.current?.contains(B)||i()};return document.addEventListener("pointerdown",te,!0),()=>document.removeEventListener("pointerdown",te,!0)},z=[r,i,s],e[15]=r,e[16]=i,e[17]=s,e[18]=M,e[19]=z):(M=e[18],z=e[19]),f.useEffect(M,z);let j;e[20]!==i||e[21]!==N?(j=te=>{N(te.id,$i(te)),i()},e[20]=i,e[21]=N,e[22]=j):j=e[22];const P=j;if(!l)return null;let V;e[23]!==o?(V=o("sessions.switcher.openAria"),e[23]=o,e[24]=V):V=e[24];const I=E?"absolute origin-top-left":"mx-3 mt-2",D=a?"pointer-events-none":"pointer-events-auto";let F;e[25]!==I||e[26]!==D?(F=Q("oc-surface-elevated flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-surface-elevated p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",I,D),e[25]=I,e[26]=D,e[27]=F):F=e[27];const L=`${a?"session-switcher-out":"session-switcher-in"} ${a?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let q;e[28]!==h||e[29]!==E?(q=E?{top:8,left:h??8,width:`min(${hi}px, calc(100% - 16px))`}:null,e[28]=h,e[29]=E,e[30]=q):q=e[30];let X;e[31]!==L||e[32]!==q?(X={animation:L,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...q},e[31]=L,e[32]=q,e[33]=X):X=e[33];let Y;e[34]!==v||e[35]!==P||e[36]!==R||e[37]!==A||e[38]!==o?(Y=R.length===0?t.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:o("sessions.switcher.empty")}):R.map(te=>{const le=te.node.session,B=[te.secondaryMeta?.projectLabel,te.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx($d,{session:le,meta:B,active:le.id===v,onSelect:()=>{te.projectId&&A(te.projectId),P(le)}},le.id)}),e[34]=v,e[35]=P,e[36]=R,e[37]=A,e[38]=o,e[39]=Y):Y=e[39];let W;e[40]!==Y?(W=t.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:Y}),e[40]=Y,e[41]=W):W=e[41];let Z;e[42]!==V||e[43]!==F||e[44]!==X||e[45]!==W?(Z=t.jsx("div",{ref:c,role:"dialog","aria-label":V,className:F,style:X,children:W}),e[42]=V,e[43]=F,e[44]=X,e[45]=W,e[46]=Z):Z=e[46];let fe;e[47]===Symbol.for("react.memo_cache_sentinel")?(fe=t.jsx("style",{children:`
14
+ @keyframes session-switcher-in {
15
+ from { opacity: 0; transform: translateY(-8px) scale(0.985); }
16
+ to { opacity: 1; transform: translateY(0) scale(1); }
17
+ }
18
+ @keyframes session-switcher-out {
19
+ from { opacity: 1; transform: translateY(0) scale(1); }
20
+ to { opacity: 0; transform: translateY(-6px) scale(0.985); }
21
+ }
22
+ `}),e[47]=fe):fe=e[47];let ae;return e[48]!==Z?(ae=t.jsxs("div",{ref:g,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[Z,fe]}),e[48]=Z,e[49]=ae):ae=e[49],ae};function Wd(n){return n.currentSessionId}function Vd(n){return n.setCurrentSession}function Ud(n){return n.setActiveProjectIdOnly}const Gd=n=>{const e=de.c(84),{onOpenSessions:s,onOpenWorkspace:i,compactTitle:r}=n,o=r===void 0?!1:r,{t:c}=ge(),[l,m]=f.useState(!1),[a,u]=f.useState(!1),p=f.useRef(null),g=Nt(Kd),h=_e(qd);let b;e[0]!==h?(b=Me=>h?Me.getDirectoryForSession(h):null,e[0]=h,e[1]=b):b=e[1];const y=_e(b)||g,E=Fa(h,y||void 0),v=_e(Hd),N=Ui(y||null);let A;e[2]!==y||e[3]!==N?(A=Me=>{if(!y||N!==!0)return!1;const $e=Me.directories.get(y)?.status;return!!($e&&!$e.isClean)},e[2]=y,e[3]=N,e[4]=A):A=e[4];const x=Qe(A),R=Oe(Jd),S=dc(R);let C;e[5]!==E?.title?(C=E?.title?.trim(),e[5]=E?.title,e[6]=C):C=e[6];const w=C;let T;e[7]!==h||e[8]!==R||e[9]!==S||e[10]!==w||e[11]!==c?(T=(R?S:null)||w||c(h?"mobile.sessions.untitled":"sessions.switcher.draftTitle"),e[7]=h,e[8]=R,e[9]=S,e[10]=w,e[11]=c,e[12]=T):T=e[12];const M=T;let z;e[13]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{m(!1),u(!1)},e[13]=z):z=e[13];let j;e[14]!==h||e[15]!==y?(j=[h,y],e[14]=h,e[15]=y,e[16]=j):j=e[16],f.useEffect(z,j);let P;e[17]!==s?(P=()=>{m(!1),u(!1),s()},e[17]=s,e[18]=P):P=e[18];const V=P;let I;e[19]===Symbol.for("react.memo_cache_sentinel")?(I=Me=>{m($e=>{const He=typeof Me=="function"?Me($e):Me;return He&&u(!1),He})},e[19]=I):I=e[19];const D=I;let F;e[20]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{u(Me=>{const $e=!Me;return $e&&m(!1),$e})},e[20]=F):F=e[20];const L=F;let q;e[21]===Symbol.for("react.memo_cache_sentinel")?(q={paddingTop:"var(--oc-safe-area-top, 0px)"},e[21]=q):q=e[21];let X;e[22]!==c?(X=c("mobile.sessions.openSheetAria"),e[22]=c,e[23]=X):X=e[23];let Y,W;e[24]===Symbol.for("react.memo_cache_sentinel")?(Y={touchAction:"manipulation"},W=t.jsx(J,{name:"list-unordered",className:"size-5"}),e[24]=Y,e[25]=W):(Y=e[24],W=e[25]);let Z;e[26]!==V||e[27]!==X?(Z=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":X,onClick:V,style:Y,children:W}),e[26]=V,e[27]=X,e[28]=Z):Z=e[28];const fe=o?"shrink":"flex-1";let ae;e[29]!==fe?(ae=Q("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",fe),e[29]=fe,e[30]=ae):ae=e[30];let te;e[31]!==c?(te=c("sessions.switcher.openAria"),e[31]=c,e[32]=te):te=e[32];let le;e[33]===Symbol.for("react.memo_cache_sentinel")?(le={touchAction:"manipulation"},e[33]=le):le=e[33];let B;e[34]!==M?(B=t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:M}),e[34]=M,e[35]=B):B=e[35];const ee=a&&"rotate-180";let ne;e[36]!==ee?(ne=Q("size-4 shrink-0 text-muted-foreground transition-transform duration-150",ee),e[36]=ee,e[37]=ne):ne=e[37];let ie;e[38]!==ne?(ie=t.jsx(J,{name:"arrow-down-s",className:ne}),e[38]=ne,e[39]=ie):ie=e[39];let H;e[40]!==B||e[41]!==ie?(H=t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[B,ie]}),e[40]=B,e[41]=ie,e[42]=H):H=e[42];let oe;e[43]!==a||e[44]!==ae||e[45]!==te||e[46]!==H?(oe=t.jsx("button",{ref:p,type:"button",className:ae,"aria-label":te,"aria-haspopup":"dialog","aria-expanded":a,onClick:L,style:le,children:H}),e[43]=a,e[44]=ae,e[45]=te,e[46]=H,e[47]=oe):oe=e[47];let ue;e[48]!==o?(ue=o?t.jsx("div",{className:"min-w-0 flex-1"}):null,e[48]=o,e[49]=ue):ue=e[49];let xe;e[50]!==h||e[51]!==y||e[52]!==v||e[53]!==l||e[54]!==R?(xe=R?null:t.jsx(Od,{open:l,onOpenChange:D,currentSessionId:h,effectiveDirectory:y,isNewSessionDraftOpen:v}),e[50]=h,e[51]=y,e[52]=v,e[53]=l,e[54]=R,e[55]=xe):xe=e[55];let ye;e[56]!==y?(ye=t.jsx(fc,{directory:y,className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",iconClassName:"size-5"}),e[56]=y,e[57]=ye):ye=e[57];let ke;e[58]!==x||e[59]!==c?(ke=c(x?"mobile.header.openWorkspaceWithChangesAria":"mobile.header.openWorkspaceAria"),e[58]=x,e[59]=c,e[60]=ke):ke=e[60];let U;e[61]!==i?(U=()=>{m(!1),u(!1),i()},e[61]=i,e[62]=U):U=e[62];let he,Ie;e[63]===Symbol.for("react.memo_cache_sentinel")?(he={touchAction:"manipulation"},Ie=t.jsx(J,{name:"pencil-ruler-2",className:"size-5"}),e[63]=he,e[64]=Ie):(he=e[63],Ie=e[64]);let pe;e[65]!==x?(pe=x?t.jsx("span",{className:"absolute right-1.5 top-1.5 size-2.5 rounded-full border-2 border-[var(--background)] bg-[var(--status-warning)]","aria-hidden":!0}):null,e[65]=x,e[66]=pe):pe=e[66];let Ne;e[67]!==ke||e[68]!==U||e[69]!==pe?(Ne=t.jsxs("button",{type:"button",className:"relative flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":ke,onClick:U,style:he,children:[Ie,pe]}),e[67]=ke,e[68]=U,e[69]=pe,e[70]=Ne):Ne=e[70];let De;e[71]!==Z||e[72]!==oe||e[73]!==ue||e[74]!==xe||e[75]!==ye||e[76]!==Ne?(De=t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:q,children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[Z,oe,ue,xe,ye,Ne]})}),e[71]=Z,e[72]=oe,e[73]=ue,e[74]=xe,e[75]=ye,e[76]=Ne,e[77]=De):De=e[77];let Re;e[78]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>u(!1),e[78]=Re):Re=e[78];let Ae;e[79]!==a?(Ae=t.jsx(Fd,{open:a,onClose:Re,anchorRef:p}),e[79]=a,e[80]=Ae):Ae=e[80];let Ee;return e[81]!==De||e[82]!==Ae?(Ee=t.jsxs(t.Fragment,{children:[De,Ae]}),e[81]=De,e[82]=Ae,e[83]=Ee):Ee=e[83],Ee};function Kd(n){return n.currentDirectory}function qd(n){return n.currentSessionId}function Hd(n){return!!n.newSessionDraft?.open}function Jd(n){return n.runOverviewKey}const Yd=({onActiveConnectionDeleted:n,onConnect:e})=>{const{t:s}=ge(),i=So(e),{connections:r,isBusy:o,isPasswordBusy:c,error:l,pendingConnection:m,connect:a,submitPassword:u,cancelPassword:p,saveConnection:g,removeConnection:h,setError:b}=i,[k,y]=f.useState(null),E=k?r.find(H=>H.id===k)??null:null,[v,N]=f.useState(null),[A,x]=f.useState(""),[R,S]=f.useState(""),[C,w]=f.useState(""),[T,M]=f.useState(""),[z,j]=f.useState(!1),[P,V]=f.useState(!1),I=f.useRef(null),D=f.useMemo(()=>On(),[]),[F,L]=f.useState(!1),[q,X]=f.useState(null),[Y,W]=f.useState(!1),Z=po(f.useCallback(()=>W(!0),[])),fe=f.useCallback(()=>{y(null),x(""),S(""),w(""),b(null),L(!1)},[b]),ae=f.useCallback(H=>{H.preventDefault(),g({id:k??void 0,url:A,label:R,clientToken:C}).then(oe=>{oe&&fe()})},[C,k,R,fe,g,A]),te=f.useCallback(async()=>{if(I.current)return;b(null),j(!0);const H=new AbortController;I.current=H;try{const oe=await Io({signal:H.signal});switch(I.current===H&&(I.current=null,j(!1)),oe.status){case"ok":x(oe.url),oe.label&&S(oe.label),oe.clientToken&&w(oe.clientToken),L(!0);break;case"pairing":V(!0),await i.redeemPairingConnection(oe.pairing);break;case"permission-denied":b(s("mobile.connect.scan.permissionDenied"));break;case"invalid":b(s("mobile.connect.scan.invalid"));break;case"unsupported":b(s("mobile.connect.scan.unsupported"));break;case"failed":b(s("mobile.connect.scan.failed"));break;default:break}}finally{V(!1),I.current===H&&(I.current=null,j(!1))}},[i,b,s]);f.useEffect(()=>()=>I.current?.abort(),[]);const le=f.useCallback(H=>{H.preventDefault(),u(T)},[T,u]),B=f.useCallback(()=>{M(""),p()},[p]),ee=f.useCallback(H=>{N(oe=>oe===H?null:H)},[]),ne=f.useCallback(H=>{N(null),k===H&&fe();const oe=r.length===1;h(H).then(ue=>{ue&&(oe||mi(ue))&&n()})},[r.length,k,n,h,fe]),ie=js;return m?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:le,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(J,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:m.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:m.candidates.some(H=>H.kind==="direct")?jt(m):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...rs,value:T,onChange:H=>M(H.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:ie}),l?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:l}):null,t.jsx(Se,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:c||!T.trim(),children:s(c?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(Se,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:B,children:s("mobile.connect.cancelPassword")})]})})}):t.jsxs(t.Fragment,{children:[z?t.jsx(Ao,{onCancel:()=>I.current?.abort()}):null,P?t.jsx(Po,{}):null,Y?t.jsx(No,{onClose:()=>W(!1)}):null,t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[r.length>0?t.jsx("div",{...Z,className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(H=>{const oe=v===H.id,ue=mi(H),xe=q===H.id,ye=xe?s("mobile.connect.connecting"):ue?Rs()?s("mobile.instances.status.connectedRelay"):s("mobile.instances.status.connectedDirect"):H.candidates.some(ke=>ke.kind==="direct")?jt(H):s("mobile.connect.relay.badge");return t.jsxs("div",{className:Q("flex items-center border-b border-border/70 transition-colors last:border-b-0",oe&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:opacity-60",onClick:()=>{ue||(X(H.id),a({id:H.id,candidates:H.candidates,clientToken:H.clientToken,label:H.label}).finally(()=>X(null)))},disabled:o&&!xe||oe,children:[t.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[t.jsx(J,{name:"server",className:"size-[18px]"}),ue?t.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:H.label}),t.jsx("span",{className:Q("block truncate typography-small",ue&&!xe?"text-[var(--status-success)]":"text-muted-foreground"),children:ye})]}),xe?t.jsx(J,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[oe?t.jsxs("button",{type:"button","aria-label":s("mobile.instances.confirmDeleteAria",{label:H.label}),className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>ne(H.id),style:{touchAction:"manipulation"},children:[t.jsx(J,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:s("mobile.instances.delete")})]}):H.candidates.some(ke=>ke.kind==="direct")?t.jsx("button",{type:"button","aria-label":s("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>{y(H.id),x(jt(H)),S(H.label),w(H.clientToken||""),b(null)},style:{touchAction:"manipulation"},children:t.jsx(J,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":oe?s("mobile.instances.cancelDeleteAria",{label:H.label}):s("mobile.instances.deleteAria",{label:H.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>ee(H.id),style:{touchAction:"manipulation"},children:t.jsx(J,{name:oe?"close":"delete-bin",className:"size-[18px]"})})]})]},H.id)})}):t.jsx("p",{...Z,className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:s("mobile.connect.saved.empty")}),!F&&!E?t.jsxs("div",{className:"space-y-2",children:[D?t.jsxs(Se,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{te()},disabled:z,children:[t.jsx(J,{name:"scan-2",className:Q("size-[18px]",z&&"animate-pulse")}),s("mobile.connect.scanQr")]}):null,t.jsxs(Se,{type:"button",variant:D?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{b(null),L(!0)},children:[t.jsx(J,{name:"add",className:"size-[18px]"}),s("mobile.instances.addManual")]}),l?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:l}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:ae,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:s(E?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(Se,{type:"button",variant:"ghost",size:"xs",onClick:fe,children:s("mobile.instances.cancelEdit")})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.url.label")}),t.jsx("input",{...rs,value:A,onChange:H=>x(H.target.value),placeholder:s("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:ie})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.instances.label.label")}),t.jsx("input",{value:R,onChange:H=>S(H.target.value),placeholder:s("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:ie})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.token.label")}),t.jsx("input",{...rs,value:C,onChange:H=>w(H.target.value),placeholder:s("mobile.connect.token.placeholder"),autoCapitalize:"none",className:ie}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")})]}),l?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:l}):null,t.jsx(Se,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:s(E?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})]})},ze=n=>va(n)??"",Cn=n=>{const e=ze(n);if(!e)return"";const s=e.split("/").filter(Boolean);return s[s.length-1]?.replace(/[-_]/g," ")||e},gi=lr(n=>({expandedParents:{},toggleParent:e=>n(s=>{const i={...s.expandedParents};return i[e]?delete i[e]:i[e]=!0,{expandedParents:i}})})),Gs=lr()(uo(n=>({projectExpanded:{},worktreeExpanded:{},setProjectExpanded:(e,s)=>n(i=>({projectExpanded:{...i.projectExpanded,[e]:s}})),setWorktreeExpanded:(e,s)=>n(i=>({worktreeExpanded:{...i.worktreeExpanded,[e]:s}}))}),{name:"mobile-session-tree"})),Bn=lr()(uo(n=>({orderByProject:{},setWorktreeOrder:(e,s)=>n(i=>({orderByProject:{...i.orderByProject,[e]:s}}))}),{name:"mobile-worktree-order"})),bi=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Xd=(n,e)=>{if(!n||n.length===0)return e;const s=new Map(n.map((r,o)=>[bi(r),o])),i=r=>s.get(bi(r.path))??Number.MAX_SAFE_INTEGER;return e.map((r,o)=>({worktree:r,index:o})).sort((r,o)=>{const c=i(r.worktree)-i(o.worktree);return c!==0?c:r.index-o.index}).map(r=>r.worktree)},ks=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Qd=n=>{const e=n;return ks(e.directory??e.project?.worktree??null)},Do=({open:n,project:e,worktree:s,onClose:i,onDeleted:r})=>{const{t:o}=ge(),c=Gi(),l=ss(w=>w.activeSessions),m=_e(w=>w.archiveSessions),a=Nt(w=>w.currentDirectory),[u,p]=f.useState(!1),[g,h]=f.useState(!1),[b,k]=f.useState(!1),[y,E]=f.useState(!1),v=ks(s?.path),N=typeof s?.branch=="string"&&s.branch.trim().length>0,A=f.useMemo(()=>{if(!v)return[];const w=new Map;for(const T of[...l,...c])Qd(T)===v&&w.set(T.id,T);return Array.from(w.values())},[l,c,v]);f.useEffect(()=>{if(!n){p(!1),h(!1),k(!1),E(!1);return}if(!s?.path)return;let w=!1;return Wa(s.path).then(T=>{w||k(!!T?.isDirty)}).catch(()=>{w||k(!!s.status?.isDirty)}),()=>{w=!0}},[n,s?.path,s?.status?.isDirty]);const x=f.useCallback((w,T)=>{const M=Va(w),z=we.loading(o("sessions.sidebar.sessionDialogs.worktree.removingTitle",{name:M}));(async()=>{try{if(T.length>0){const{failedIds:j}=await m(T);if(j.length>0){we.error(j.length===1?o("sessions.sidebar.bulkActions.failedArchiveSingle",{count:j.length}):o("sessions.sidebar.bulkActions.failedArchivePlural",{count:j.length}),{id:z,description:o("sessions.sidebar.dialogs.deleteResult.tryAgain")});return}}await Ua(e,w,{deleteRemoteBranch:N&&g,deleteLocalBranch:N&&u}),ks(a)===v&&ks(e.path)&&Nt.getState().setDirectory(ks(e.path),{showOverlay:!1}),we.success(o("sessions.sidebar.sessionDialogs.worktree.removedTitle",{name:M}),{id:z,description:o(N&&g?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),r?.()}catch(j){we.error(o("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle",{name:M}),{id:z,description:j instanceof Error?j.message:o("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[m,a,u,g,N,r,e,o,v]),R=()=>{!s||y||(E(!0),x(s,A.map(w=>w.id)),i())};if(!s)return null;const S=s.branch||s.label||s.path,C=(w,T,M,z)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":w,disabled:z,onClick:()=>T(!w),className:Q("flex w-full items-center justify-between gap-3 rounded-xl border border-border/70 px-3.5 py-3 text-left transition-colors","hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",z&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:M}),t.jsx("span",{className:Q("relative h-6 w-10 shrink-0 rounded-full transition-colors",w?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:Q("absolute top-0.5 size-5 rounded-full bg-white transition-transform",w?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(Ki,{open:n,onClose:i,title:o("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Se,{variant:"ghost",className:"flex-1",onClick:i,disabled:y,children:o("projectEditDialog.actions.cancel")}),t.jsx(Se,{variant:"destructive",className:"flex-1",onClick:()=>{R()},disabled:y,children:o("mobile.projectEdit.deleteWorktreeConfirmButton")})]}),children:t.jsxs("div",{className:"flex flex-col gap-4 px-1 py-1",children:[t.jsx("p",{className:"typography-ui-body text-foreground",children:o("mobile.projectEdit.deleteWorktreeConfirm",{name:S})}),b?t.jsx("p",{className:"rounded-xl border border-[var(--warning)]/40 bg-[color-mix(in_srgb,var(--warning)_10%,transparent)] px-3.5 py-3 typography-meta text-foreground",children:o("mobile.projectEdit.deleteWorktreeDirty")}):null,A.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o("mobile.projectEdit.deleteWorktreeArchiveNote",{count:A.length})}):null,N?t.jsxs("div",{className:"flex flex-col gap-2",children:[C(u,p,o("mobile.projectEdit.deleteLocalBranch"),y),C(g,h,o("mobile.projectEdit.deleteRemoteBranch"),y)]}):null]})})},Is=n=>{const e=de.c(18),{project:s,size:i}=n,r=i===void 0?"md":i,{currentTheme:o}=qi(),c=s.icon?Hi[s.icon]:null,l=s.color?Ji[s.color]??null:null,m=r==="sm"?"size-6 rounded-md":"size-8 rounded-lg",a=r==="sm"?"size-3.5":"size-4";let u;e[0]!==c||e[1]!==l||e[2]!==a?(u=c?t.jsx(J,{name:c,className:a,style:l?{color:l}:void 0}):t.jsx(Dn,{className:a,style:l?{color:l}:void 0}),e[0]=c,e[1]=l,e[2]=a,e[3]=u):u=e[3];const p=u,g=r==="md"&&"bg-[var(--surface-muted)]";let h;e[4]!==m||e[5]!==g?(h=Q("flex shrink-0 items-center justify-center overflow-hidden text-muted-foreground",g,m),e[4]=m,e[5]=g,e[6]=h):h=e[6];let b;e[7]!==s.iconBackground?(b=s.iconBackground?{backgroundColor:s.iconBackground}:void 0,e[7]=s.iconBackground,e[8]=b):b=e[8];let k;e[9]!==o||e[10]!==p||e[11]!==s.iconImage||e[12]!==s.id?(k=s.iconImage?t.jsx(Yi,{project:{id:s.id,iconImage:s.iconImage??null},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:p}):p,e[9]=o,e[10]=p,e[11]=s.iconImage,e[12]=s.id,e[13]=k):k=e[13];let y;return e[14]!==h||e[15]!==b||e[16]!==k?(y=t.jsx("span",{className:h,style:b,children:k}),e[14]=h,e[15]=b,e[16]=k,e[17]=y):y=e[17],y},_o=n=>{const e=de.c(57),{initialTitle:s,indent:i,className:r,aiRename:o,onSubmit:c,onCancel:l}=n,{t:m}=ge(),[a,u]=f.useState(s),p=Zd;let g;e[0]!==s||e[1]!==l||e[2]!==c||e[3]!==a?(g=()=>{const Y=a.trim();if(!Y||Y===s.trim()){l();return}c(Y)},e[0]=s,e[1]=l,e[2]=c,e[3]=a,e[4]=g):g=e[4];const h=g;let b;e[5]!==r?(b=Q("flex h-9 min-w-0 flex-1 items-center gap-2 pr-2",r),e[5]=r,e[6]=b):b=e[6];let k;e[7]!==i?(k={paddingLeft:i},e[7]=i,e[8]=k):k=e[8];let y;e[9]!==h?(y=Y=>{Y.preventDefault(),h()},e[9]=h,e[10]=y):y=e[10];let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=Y=>u(Y.target.value),e[11]=E):E=e[11];let v;e[12]!==l?(v=Y=>mc(Y,l),e[12]=l,e[13]=v):v=e[13];let N;e[14]!==m?(N=m("sessions.sidebar.session.rename.save"),e[14]=m,e[15]=N):N=e[15];let A;e[16]!==m?(A=m("sessions.sidebar.session.menu.rename"),e[16]=m,e[17]=A):A=e[17];let x;e[18]===Symbol.for("react.memo_cache_sentinel")?(x={minHeight:0},e[18]=x):x=e[18];let R;e[19]!==v||e[20]!==N||e[21]!==A||e[22]!==a?(R=t.jsx("input",{ref:p,value:a,onChange:E,onKeyDown:v,"aria-label":N,placeholder:A,className:"min-w-0 flex-1 bg-transparent text-[16px] typography-ui-label text-foreground outline-none placeholder:text-muted-foreground",style:x,enterKeyHint:"done"}),e[19]=v,e[20]=N,e[21]=A,e[22]=a,e[23]=R):R=e[23];const S=o.disabled;let C;e[24]!==o||e[25]!==l?(C=()=>{o.run(),l()},e[24]=o,e[25]=l,e[26]=C):C=e[26];let w;e[27]!==m?(w=m("sessions.aiRename.action"),e[27]=m,e[28]=w):w=e[28];let T,M;e[29]===Symbol.for("react.memo_cache_sentinel")?(T={touchAction:"manipulation",minHeight:0,minWidth:0},M=t.jsx(J,{name:"ai-generate-2",className:"size-4"}),e[29]=T,e[30]=M):(T=e[29],M=e[30]);let z;e[31]!==o.disabled||e[32]!==o.hint||e[33]!==C||e[34]!==w?(z=t.jsx("button",{type:"button",disabled:S,onClick:C,"aria-label":w,"aria-description":o.hint,title:o.hint,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:T,children:M}),e[31]=o.disabled,e[32]=o.hint,e[33]=C,e[34]=w,e[35]=z):z=e[35];let j;e[36]!==m?(j=m("sessions.sidebar.session.rename.save"),e[36]=m,e[37]=j):j=e[37];let P,V;e[38]===Symbol.for("react.memo_cache_sentinel")?(P={touchAction:"manipulation",minHeight:0,minWidth:0},V=t.jsx(J,{name:"check",className:"size-4"}),e[38]=P,e[39]=V):(P=e[38],V=e[39]);let I;e[40]!==j?(I=t.jsx("button",{type:"submit","aria-label":j,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:P,children:V}),e[40]=j,e[41]=I):I=e[41];let D;e[42]!==m?(D=m("sessions.sidebar.session.rename.cancel"),e[42]=m,e[43]=D):D=e[43];let F,L;e[44]===Symbol.for("react.memo_cache_sentinel")?(F={touchAction:"manipulation",minHeight:0,minWidth:0},L=t.jsx(J,{name:"close",className:"size-4"}),e[44]=F,e[45]=L):(F=e[44],L=e[45]);let q;e[46]!==l||e[47]!==D?(q=t.jsx("button",{type:"button",onClick:l,"aria-label":D,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:F,children:L}),e[46]=l,e[47]=D,e[48]=q):q=e[48];let X;return e[49]!==R||e[50]!==z||e[51]!==b||e[52]!==I||e[53]!==q||e[54]!==k||e[55]!==y?(X=t.jsxs("form",{className:b,style:k,onSubmit:y,children:[R,z,I,q]}),e[49]=R,e[50]=z,e[51]=b,e[52]=I,e[53]=q,e[54]=k,e[55]=y,e[56]=X):X=e[56],X};function Zd(n){n&&(n.focus(),n.select())}const As=48,Mo=4*As,ef=180,nn=n=>{const e=de.c(27),{actionsWidth:s,actions:i,revealed:r,onRevealedChange:o,dataActiveSession:c,contentClassName:l,children:m}=n,a=l===void 0?"relative flex w-full items-center bg-background":l,u=f.useRef(null),p=f.useRef(null),g=f.useRef(!1),h=f.useRef(0),b=f.useRef(r);let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k=(I,D)=>{const F=u.current;F&&(F.style.transition=D?`transform ${ef}ms ease-out`:"none",F.style.transform=I===0?"none":`translateX(${I}px)`,h.current=I)},e[0]=k):k=e[0];const y=k;let E,v;e[1]!==s||e[2]!==r?(E=()=>{b.current=r,y(r?s:0,!0)},v=[s,y,r],e[1]=s,e[2]=r,e[3]=E,e[4]=v):(E=e[3],v=e[4]),f.useEffect(E,v);let N;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=I=>{if(I.touches.length!==1)return;const D=I.touches[0];p.current={x:D.clientX,y:D.clientY},g.current=!1},e[5]=N):N=e[5];const A=N;let x;e[6]!==s?(x=I=>{if(!p.current)return;const D=I.touches[0],F=D.clientX-p.current.x,L=D.clientY-p.current.y;if(!g.current){if(Math.abs(F)<8||Math.abs(F)<=Math.abs(L))return;g.current=!0}const q=b.current?s:0;y(Math.max(0,Math.min(s,q+F)),!1)},e[6]=s,e[7]=x):x=e[7];const R=x;let S;e[8]!==s||e[9]!==o?(S=()=>{if(p.current=null,!g.current)return;g.current=!1;const I=h.current>s/2;y(I?s:0,!0),I!==b.current&&o(I)},e[8]=s,e[9]=o,e[10]=S):S=e[10];const C=S,w=c||void 0;let T;e[11]===Symbol.for("react.memo_cache_sentinel")?(T={touchAction:"pan-y"},e[11]=T):T=e[11];let M;e[12]!==s?(M={width:s},e[12]=s,e[13]=M):M=e[13];const z=!r;let j;e[14]!==i||e[15]!==M||e[16]!==z?(j=t.jsx("div",{className:"absolute inset-y-0 left-0 flex items-stretch",style:M,"aria-hidden":z,children:i}),e[14]=i,e[15]=M,e[16]=z,e[17]=j):j=e[17];let P;e[18]!==m||e[19]!==a?(P=t.jsx("div",{ref:u,className:a,children:m}),e[18]=m,e[19]=a,e[20]=P):P=e[20];let V;return e[21]!==C||e[22]!==R||e[23]!==j||e[24]!==P||e[25]!==w?(V=t.jsxs("div",{"data-active-session":w,className:"relative overflow-hidden",onTouchStart:A,onTouchMove:R,onTouchEnd:C,onTouchCancel:C,style:T,children:[j,P]}),e[21]=C,e[22]=R,e[23]=j,e[24]=P,e[25]=w,e[26]=V):V=e[26],V},zo=n=>{const e=de.c(62),{sessionId:s,title:i,revealed:r,confirmingDelete:o,onArchive:c,onRequestDelete:l,onConfirmDelete:m,onRequestRename:a,onRevealedChange:u,work:p,pin:g}=n,{t:h}=ge(),b=r?0:-1;let k;e[0]!==u||e[1]!==s||e[2]!==h?(k=async()=>{if(!(await Fi(s).catch(tf))?.ok){Mn.error(h("sessions.sidebar.session.copyId.error"));return}u?.(!1),Mn.success(h("sessions.sidebar.session.copyId.success"))},e[0]=u,e[1]=s,e[2]=h,e[3]=k):k=e[3];const y=k;let E;e[4]!==h||e[5]!==i?(E=h("mobile.sessions.archiveSessionAria",{title:i}),e[4]=h,e[5]=i,e[6]=E):E=e[6];let v,N;e[7]===Symbol.for("react.memo_cache_sentinel")?(v={touchAction:"manipulation"},N=t.jsx(au,{className:"size-[18px]"}),e[7]=v,e[8]=N):(v=e[7],N=e[8]);let A;e[9]!==c||e[10]!==E||e[11]!==b?(A=t.jsx("button",{type:"button",tabIndex:b,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":E,onClick:c,style:v,children:N}),e[9]=c,e[10]=E,e[11]=b,e[12]=A):A=e[12];let x;e[13]!==u||e[14]!==g||e[15]!==h||e[16]!==b?(x=g?t.jsx("button",{type:"button",tabIndex:b,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":g.pinned?h("sessions.sidebar.session.menu.unpin"):h("sessions.sidebar.session.menu.pin"),onClick:()=>{g.onToggle(),u?.(!1)},style:{touchAction:"manipulation"},children:t.jsx(J,{name:g.pinned?"unpin":"pushpin",className:"size-[18px]"})}):null,e[13]=u,e[14]=g,e[15]=h,e[16]=b,e[17]=x):x=e[17];let R;e[18]!==u||e[19]!==h||e[20]!==b||e[21]!==p?(R=p?t.jsx("button",{type:"button",tabIndex:b,className:Q("flex flex-1 items-center justify-center transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",p.inWork?"text-status-success":"text-muted-foreground active:text-foreground"),"aria-label":p.inWork?h("sessions.sidebar.session.work.markDone"):h("sessions.sidebar.session.work.track"),onClick:()=>{p.onToggle(),u?.(!1)},style:{touchAction:"manipulation"},children:t.jsx(J,{name:p.inWork?"check":"eye",className:p.inWork?"size-5":"size-[18px]"})}):null,e[18]=u,e[19]=h,e[20]=b,e[21]=p,e[22]=R):R=e[22];const S=o?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80";let C;e[23]!==S?(C=Q("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",S),e[23]=S,e[24]=C):C=e[24];let w;e[25]!==o||e[26]!==h||e[27]!==i?(w=o?h("mobile.sessions.confirmDeleteSessionAria",{title:i}):h("mobile.sessions.deleteSessionAria",{title:i}),e[25]=o,e[26]=h,e[27]=i,e[28]=w):w=e[28];const T=o?m:l;let M,z;e[29]===Symbol.for("react.memo_cache_sentinel")?(M={touchAction:"manipulation"},z=t.jsx(Xs,{className:"size-[18px]"}),e[29]=M,e[30]=z):(M=e[29],z=e[30]);let j;e[31]!==w||e[32]!==T||e[33]!==C||e[34]!==b?(j=t.jsx("button",{type:"button",tabIndex:b,className:C,"aria-label":w,onClick:T,style:M,children:z}),e[31]=w,e[32]=T,e[33]=C,e[34]=b,e[35]=j):j=e[35];let P;e[36]!==h||e[37]!==i?(P=h("mobile.sessions.renameSessionAria",{title:i}),e[36]=h,e[37]=i,e[38]=P):P=e[38];let V,I;e[39]===Symbol.for("react.memo_cache_sentinel")?(V={touchAction:"manipulation"},I=t.jsx(_n,{className:"size-[18px]"}),e[39]=V,e[40]=I):(V=e[39],I=e[40]);let D;e[41]!==a||e[42]!==P||e[43]!==b?(D=t.jsx("button",{type:"button",tabIndex:b,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":P,onClick:a,style:V,children:I}),e[41]=a,e[42]=P,e[43]=b,e[44]=D):D=e[44];let F;e[45]!==h?(F=h("sessions.sidebar.session.menu.copyId"),e[45]=h,e[46]=F):F=e[46];let L;e[47]!==y?(L=()=>{y()},e[47]=y,e[48]=L):L=e[48];let q,X;e[49]===Symbol.for("react.memo_cache_sentinel")?(q={touchAction:"manipulation"},X=t.jsx(J,{name:"file-copy",className:"size-[18px]"}),e[49]=q,e[50]=X):(q=e[49],X=e[50]);let Y;e[51]!==F||e[52]!==L||e[53]!==b?(Y=t.jsx("button",{type:"button",tabIndex:b,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":F,onClick:L,style:q,children:X}),e[51]=F,e[52]=L,e[53]=b,e[54]=Y):Y=e[54];let W;return e[55]!==j||e[56]!==D||e[57]!==Y||e[58]!==A||e[59]!==x||e[60]!==R?(W=t.jsxs(t.Fragment,{children:[A,x,R,j,D,Y]}),e[55]=j,e[56]=D,e[57]=Y,e[58]=A,e[59]=x,e[60]=R,e[61]=W):W=e[61],W};function tf(){return null}const ut=n=>n.parentID??null,mt=n=>{const e=n;return ze(e.directory??e.project?.worktree??null)},Oo=n=>{const e=n.time?.updated??n.time?.created,s=typeof e=="number"?e:Number(e);return Number.isFinite(s)&&s>0?s:0},ln=n=>{if(n<=0)return"";const e=Date.now()-n;if(e<6e4)return"now";const s=Math.floor(e/6e4);if(s<60)return`${s}m`;const i=Math.floor(s/60);if(i<24)return`${i}h`;const r=Math.floor(i/24);return r<7?`${r}d`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(n))},sf=4,Bo=n=>{const e=de.c(4),{providerIDs:s}=n;let i;e[0]!==s?(i=s.slice(0,sf).map(nf),e[0]=s,e[1]=i):i=e[1];let r;return e[2]!==i?(r=t.jsx("span",{className:"inline-flex shrink-0 items-center -space-x-1",children:i}),e[2]=i,e[3]=r):r=e[3],r};function nf(n){return t.jsx("span",{className:"inline-flex size-4 items-center justify-center rounded-full bg-background ring-1 ring-background",children:t.jsx(Wi,{providerId:n,className:"size-3 opacity-80"})},n)}const Lo=n=>{const e=de.c(8),{session:s}=n,{t:i}=ge(),r=Xi(s);if(!r)return null;const o=Ga[r.status];let c;e[0]!==i||e[1]!==o?(c=i(o),e[0]=i,e[1]=o,e[2]=c):c=e[2];const l=c,m=Ka[r.status];let a;e[3]!==m?(a={color:m},e[3]=m,e[4]=a):a=e[4];let u;return e[5]!==l||e[6]!==a?(u=t.jsx(J,{name:"target",className:"size-3.5 shrink-0",style:a,"aria-label":l}),e[5]=l,e[6]=a,e[7]=u):u=e[7],u},$o=n=>{const e=de.c(12),{permissionCount:s,formCount:i}=n,{t:r}=ge();if(s===0&&i===0)return null;let o;e[0]!==i||e[1]!==r?(o=i===1?r("sessions.sidebar.session.status.questionPendingSingle"):r("sessions.sidebar.session.status.questionPendingMany",{count:i}),e[0]=i,e[1]=r,e[2]=o):o=e[2];const c=o;let l;e[3]!==s||e[4]!==r?(l=s>0?t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive","aria-label":r("sessions.sidebar.session.status.permissionRequired"),children:[t.jsx(J,{name:"shield",className:"size-3"}),t.jsx("span",{className:"leading-none tabular-nums",children:s})]}):null,e[3]=s,e[4]=r,e[5]=l):l=e[5];let m;e[6]!==i||e[7]!==c?(m=i>0?t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded bg-status-info/10 px-1 py-0.5 text-[0.7rem] text-status-info","aria-label":c,children:[t.jsx(J,{name:"question",className:"size-3"}),t.jsx("span",{className:"leading-none tabular-nums",children:i})]}):null,e[6]=i,e[7]=c,e[8]=m):m=e[8];let a;return e[9]!==l||e[10]!==m?(a=t.jsxs(t.Fragment,{children:[l,m]}),e[9]=l,e[10]=m,e[11]=a):a=e[11],a},Fo=n=>{const e=de.c(7);let s;e[0]!==n?(s=l=>{let m=0;for(const a of n)m=m+(l.bySession.get(a)?.permissions.length??0);return m},e[0]=n,e[1]=s):s=e[1];const i=Yr(s);let r;e[2]!==n?(r=l=>{let m=0;for(const a of n)m=m+(l.bySession.get(a)?.forms.length??0);return m},e[2]=n,e[3]=r):r=e[3];const o=Yr(r);let c;return e[4]!==o||e[5]!==i?(c={permissionCount:i,formCount:o},e[4]=o,e[5]=i,e[6]=c):c=e[6],c},Ln=12,$n="flex min-w-0 flex-1 flex-col gap-1 py-2.5 pr-3 text-left",rf=n=>{const e=de.c(54),{entry:s}=n,{t:i}=ge(),{run:r,project:o}=s;let c;e[0]!==r.key?(c=L=>L.runOverviewKey===r.key,e[0]=r.key,e[1]=c):c=e[1];const l=Oe(c);let m;e[2]!==s.laneNodes?(m={nodes:s.laneNodes,includeUnreadSubtasks:!1},e[2]=s.laneNodes,e[3]=m):m=e[3];const a=oo(m);let u;e[4]!==r.lastActivity?(u=ln(r.lastActivity),e[4]=r.lastActivity,e[5]=u):u=e[5];const p=u,g=r.lanes.length,h=l||void 0,b=l&&"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]";let k;e[6]!==b?(k=Q("relative bg-background transition-colors",b),e[6]=b,e[7]=k):k=e[7];let y,E;e[8]===Symbol.for("react.memo_cache_sentinel")?(y=Q($n,"w-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"),E={paddingLeft:Ln,touchAction:"manipulation"},e[8]=y,e[9]=E):(y=e[8],E=e[9]);let v;e[10]!==r.key?(v=()=>Oe.getState().setRunOverviewKey(r.key),e[10]=r.key,e[11]=v):v=e[11];let N;e[12]!==r.title||e[13]!==i?(N=i("sessions.sidebar.run.openOverviewAria",{title:r.title}),e[12]=r.title,e[13]=i,e[14]=N):N=e[14];let A;e[15]!==o?(A=t.jsx(Is,{project:o,size:"sm"}),e[15]=o,e[16]=A):A=e[16];let x;e[17]!==o.label?(x=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-micro text-muted-foreground",children:o.label}),e[17]=o.label,e[18]=x):x=e[18];let R;e[19]!==a?(R=a?t.jsx(lo,{state:a}):null,e[19]=a,e[20]=R):R=e[20];let S;e[21]!==p?(S=p?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:p}):null,e[21]=p,e[22]=S):S=e[22];let C;e[23]!==A||e[24]!==x||e[25]!==R||e[26]!==S?(C=t.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[A,x,R,S]}),e[23]=A,e[24]=x,e[25]=R,e[26]=S,e[27]=C):C=e[27];const w=l?"text-primary":"text-foreground";let T;e[28]!==w?(T=Q("block min-w-0 truncate typography-ui-label",w),e[28]=w,e[29]=T):T=e[29];let M;e[30]!==r.title||e[31]!==T?(M=t.jsx("span",{className:T,children:r.title}),e[30]=r.title,e[31]=T,e[32]=M):M=e[32];let z;e[33]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx(Zi,{className:"size-3.5 shrink-0","aria-hidden":"true"}),e[33]=z):z=e[33];let j;e[34]!==g||e[35]!==i?(j=g===1?i("sessions.sidebar.run.laneCountSingle",{count:g}):i("sessions.sidebar.run.laneCountPlural",{count:g}),e[34]=g,e[35]=i,e[36]=j):j=e[36];let P;e[37]!==j?(P=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-micro",children:j}),e[37]=j,e[38]=P):P=e[38];let V;e[39]!==r.providerIDs?(V=t.jsx(Bo,{providerIDs:r.providerIDs}),e[39]=r.providerIDs,e[40]=V):V=e[40];let I;e[41]!==P||e[42]!==V?(I=t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[z,P,V]}),e[41]=P,e[42]=V,e[43]=I):I=e[43];let D;e[44]!==N||e[45]!==C||e[46]!==M||e[47]!==I||e[48]!==v?(D=t.jsxs("button",{type:"button",className:y,style:E,onClick:v,"aria-label":N,children:[C,M,I]}),e[44]=N,e[45]=C,e[46]=M,e[47]=I,e[48]=v,e[49]=D):D=e[49];let F;return e[50]!==D||e[51]!==h||e[52]!==k?(F=t.jsx("div",{"data-active-session":h,className:k,children:D}),e[50]=D,e[51]=h,e[52]=k,e[53]=F):F=e[53],F},of=n=>{const e=de.c(116),{entry:s,active:i,revealed:r,confirmingDelete:o,renaming:c,handlers:l}=n,{t:m}=ge(),{session:a,project:u,branch:p}=s;let g;e[0]!==a.title||e[1]!==m?(g=a.title?.trim()||m("mobile.sessions.untitled"),e[0]=a.title,e[1]=m,e[2]=g):g=e[2];const h=g;let b;e[3]!==a?(b=ln(Oo(a)),e[3]=a,e[4]=b):b=e[4];const k=b,y=ao(a.id,a.directory,r||c),E=Vn(a.id),v=Un(a.id),N=v!==null,A=!N&&E>0&&!i,x=Gn(a.id,N),R=(N||A)&&x,S=l.onToggleWork;let C;e[5]!==a?(C=Qi(a),e[5]=a,e[6]=C):C=e[6];const w=C;let T;e[7]!==w||e[8]!==S||e[9]!==a?(T=S?{inWork:w,onToggle:()=>S(a,w)}:void 0,e[7]=w,e[8]=S,e[9]=a,e[10]=T):T=e[10];const M=T;let z;e[11]!==l||e[12]!==a?(z=l.isPinned(a),e[11]=l,e[12]=a,e[13]=z):z=e[13];const j=z;let P;e[14]!==l||e[15]!==a?(P=()=>l.onTogglePin(a),e[14]=l,e[15]=a,e[16]=P):P=e[16];let V;e[17]!==j||e[18]!==P?(V={pinned:j,onToggle:P},e[17]=j,e[18]=P,e[19]=V):V=e[19];const I=V,{descendantIdsOf:D}=l;let F;e[20]!==D||e[21]!==a.id?(F=[a.id,...D(a.id)],e[20]=D,e[21]=a.id,e[22]=F):F=e[22];const q=Fo(F),X=q.permissionCount>0||q.formCount>0;let Y;e[23]!==a?(Y=Xi(a),e[23]=a,e[24]=Y):Y=e[24];const W=Y!==null,Z=Mo+As+(M?As:0);let fe;e[25]!==l||e[26]!==a.id?(fe=xe=>l.onRevealedChange(a.id,xe),e[25]=l,e[26]=a.id,e[27]=fe):fe=e[27];const ae=i&&"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]";let te;e[28]!==ae?(te=Q("relative flex w-full items-center bg-background transition-colors",ae),e[28]=ae,e[29]=te):te=e[29];let le;e[30]!==l||e[31]!==a?(le=()=>l.onArchive(a),e[30]=l,e[31]=a,e[32]=le):le=e[32];let B;e[33]!==l||e[34]!==a.id?(B=()=>l.onRequestDelete(a.id),e[33]=l,e[34]=a.id,e[35]=B):B=e[35];let ee;e[36]!==l||e[37]!==a?(ee=()=>l.onConfirmDelete(a),e[36]=l,e[37]=a,e[38]=ee):ee=e[38];let ne,ie;e[39]!==l||e[40]!==a.id?(ne=()=>l.onRequestRename(a.id),ie=xe=>l.onRevealedChange(a.id,xe),e[39]=l,e[40]=a.id,e[41]=ne,e[42]=ie):(ne=e[41],ie=e[42]);let H;e[43]!==o||e[44]!==I||e[45]!==r||e[46]!==a.id||e[47]!==le||e[48]!==B||e[49]!==ee||e[50]!==ne||e[51]!==ie||e[52]!==h||e[53]!==M?(H=t.jsx(zo,{sessionId:a.id,title:h,revealed:r,confirmingDelete:o,onArchive:le,onRequestDelete:B,onConfirmDelete:ee,onRequestRename:ne,onRevealedChange:ie,work:M,pin:I}),e[43]=o,e[44]=I,e[45]=r,e[46]=a.id,e[47]=le,e[48]=B,e[49]=ee,e[50]=ne,e[51]=ie,e[52]=h,e[53]=M,e[54]=H):H=e[54];let oe;e:{let xe;e[55]!==u?(xe=t.jsx(Is,{project:u,size:"sm"}),e[55]=u,e[56]=xe):xe=e[56];let ye;e[57]!==u.label?(ye=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-micro text-muted-foreground",children:u.label}),e[57]=u.label,e[58]=ye):ye=e[58];let ke;e[59]!==j||e[60]!==m?(ke=j?t.jsx(J,{name:"pushpin",className:"size-3 shrink-0 text-muted-foreground","aria-label":m("sessions.sidebar.session.status.pinned")}):null,e[59]=j,e[60]=m,e[61]=ke):ke=e[61];let U;e[62]!==y.pending||e[63]!==N||e[64]!==A||e[65]!==m||e[66]!==v?(U=y.pending?t.jsx(J,{name:"loader-4",className:"size-3 shrink-0 animate-spin text-primary","aria-label":m("sessions.aiRename.generating")}):N||A?t.jsx(Ys,{state:v??"unread"}):null,e[62]=y.pending,e[63]=N,e[64]=A,e[65]=m,e[66]=v,e[67]=U):U=e[67];let he;e[68]!==N||e[69]!==a.id||e[70]!==R||e[71]!==k?(he=R?t.jsx(Jn,{sessionId:a.id,running:N,className:"shrink-0 typography-micro"}):k?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:k}):null,e[68]=N,e[69]=a.id,e[70]=R,e[71]=k,e[72]=he):he=e[72];let Ie;e[73]!==xe||e[74]!==ye||e[75]!==ke||e[76]!==U||e[77]!==he?(Ie=t.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[xe,ye,ke,U,he]}),e[73]=xe,e[74]=ye,e[75]=ke,e[76]=U,e[77]=he,e[78]=Ie):Ie=e[78];let pe;e[79]!==i||e[80]!==y||e[81]!==l||e[82]!==c||e[83]!==a.id||e[84]!==h?(pe=c?t.jsx(_o,{initialTitle:h,indent:0,aiRename:y,className:"h-[1lh] pr-0 typography-ui-label [&_button]:size-6 [&_button>svg]:size-3.5",onSubmit:He=>l.onSubmitRename(a.id,He),onCancel:l.onCancelRename}):t.jsx("span",{className:Q("block min-w-0 truncate typography-ui-label",i?"text-primary":"text-foreground"),children:h}),e[79]=i,e[80]=y,e[81]=l,e[82]=c,e[83]=a.id,e[84]=h,e[85]=pe):pe=e[85];let Ne;e[86]!==p||e[87]!==W||e[88]!==X||e[89]!==q||e[90]!==a?(Ne=p||W||X?t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[p?t.jsxs(t.Fragment,{children:[t.jsx(J,{name:"git-branch",className:"size-3.5 shrink-0"}),t.jsx("span",{className:"block min-w-0 truncate typography-micro",children:p})]}):null,t.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[t.jsx(Lo,{session:a}),t.jsx($o,{...q})]})]}):null,e[86]=p,e[87]=W,e[88]=X,e[89]=q,e[90]=a,e[91]=Ne):Ne=e[91];let De;e[92]!==Ie||e[93]!==pe||e[94]!==Ne?(De=t.jsxs(t.Fragment,{children:[Ie,pe,Ne]}),e[92]=Ie,e[93]=pe,e[94]=Ne,e[95]=De):De=e[95];const Re=De;if(c){let He;e[96]===Symbol.for("react.memo_cache_sentinel")?(He={paddingLeft:Ln},e[96]=He):He=e[96];let et;e[97]!==Re?(et=t.jsx("div",{className:$n,style:He,children:Re}),e[97]=Re,e[98]=et):et=e[98],oe=et;break e}let Ae,Ee;e[99]===Symbol.for("react.memo_cache_sentinel")?(Ae=Q($n,"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"),Ee={paddingLeft:Ln,touchAction:"manipulation"},e[99]=Ae,e[100]=Ee):(Ae=e[99],Ee=e[100]);let Me;e[101]!==l||e[102]!==r||e[103]!==a?(Me=()=>{if(r){l.onRevealedChange(a.id,!1);return}l.onSelect(a)},e[101]=l,e[102]=r,e[103]=a,e[104]=Me):Me=e[104];let $e;e[105]!==Re||e[106]!==Me?($e=t.jsx("button",{type:"button",className:Ae,style:Ee,onClick:Me,children:Re}),e[105]=Re,e[106]=Me,e[107]=$e):$e=e[107],oe=$e}let ue;return e[108]!==i||e[109]!==r||e[110]!==Z||e[111]!==fe||e[112]!==te||e[113]!==H||e[114]!==oe?(ue=t.jsx(nn,{actionsWidth:Z,revealed:r,onRevealedChange:fe,dataActiveSession:i,contentClassName:te,actions:H,children:oe}),e[108]=i,e[109]=r,e[110]=Z,e[111]=fe,e[112]=te,e[113]=H,e[114]=oe,e[115]=ue):ue=e[115],ue},af=n=>{const e=de.c(9),{scrollRootRef:s,visibleCount:i,onReachEnd:r}=n,o=f.useRef(null),c=f.useRef(r);let l,m;e[0]!==r?(l=()=>{c.current=r},m=[r],e[0]=r,e[1]=l,e[2]=m):(l=e[1],m=e[2]),f.useEffect(l,m);let a;e[3]!==s?(a=()=>{const g=o.current;if(!g)return;const h=new IntersectionObserver(b=>{b.some(cf)&&c.current()},{root:s.current??null,rootMargin:"400px 0px"});return h.observe(g),()=>h.disconnect()},e[3]=s,e[4]=a):a=e[4];let u;e[5]!==s||e[6]!==i?(u=[s,i],e[5]=s,e[6]=i,e[7]=u):u=e[7],f.useEffect(a,u);let p;return e[8]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx("div",{ref:o,"aria-hidden":!0,className:"h-px w-full"}),e[8]=p):p=e[8],p},lf=n=>{const e=de.c(35),{entries:s,visibleCount:i,onRevealMore:r,scrollRootRef:o,handlers:c}=n,{t:l}=ge();let m,a,u,p,g;if(e[0]!==s||e[1]!==c||e[2]!==l||e[3]!==i){g=s.slice(0,i),u="border-t border-border/70";let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:t.jsx(J,{name:"folder-6",className:"size-4"})}),e[9]=y):y=e[9];let E;e[10]!==l?(E=l("mobile.sessions.section.projects"),e[10]=l,e[11]=E):E=e[11];let v;e[12]!==E?(v=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:E}),e[12]=E,e[13]=v):v=e[13];let N;e[14]!==s.length?(N=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:s.length}),e[14]=s.length,e[15]=N):N=e[15],e[16]!==v||e[17]!==N?(p=t.jsxs("div",{className:"flex min-h-12 w-full items-center gap-2 px-3 py-1.5",children:[y,v,N]}),e[16]=v,e[17]=N,e[18]=p):p=e[18],m="pb-2";let A;e[19]!==c?(A=x=>x.kind==="run"?t.jsx(rf,{entry:x},`run:${x.run.key}`):t.jsx(of,{entry:x,active:c.currentSessionId===x.session.id,revealed:c.revealedSessionId===x.session.id,confirmingDelete:c.confirmingDeleteSessionId===x.session.id,renaming:c.renamingSessionId===x.session.id,handlers:c},x.session.id),e[19]=c,e[20]=A):A=e[20],a=g.map(A),e[0]=s,e[1]=c,e[2]=l,e[3]=i,e[4]=m,e[5]=a,e[6]=u,e[7]=p,e[8]=g}else m=e[4],a=e[5],u=e[6],p=e[7],g=e[8];let h;e[21]!==s.length||e[22]!==r||e[23]!==o||e[24]!==i||e[25]!==g.length?(h=g.length<s.length?t.jsx(af,{scrollRootRef:o,visibleCount:i,onReachEnd:r}):null,e[21]=s.length,e[22]=r,e[23]=o,e[24]=i,e[25]=g.length,e[26]=h):h=e[26];let b;e[27]!==m||e[28]!==a||e[29]!==h?(b=t.jsxs("div",{className:m,children:[a,h]}),e[27]=m,e[28]=a,e[29]=h,e[30]=b):b=e[30];let k;return e[31]!==u||e[32]!==p||e[33]!==b?(k=t.jsxs("section",{className:u,children:[p,b]}),e[31]=u,e[32]=p,e[33]=b,e[34]=k):k=e[34],k};function cf(n){return n.isIntersecting}const Js=40,uf=(n,e)=>Math.min(e,Math.max(n,0)+Js),xi="mobile-surface-root",Rn=16,Ks=200,df=()=>{if(typeof document>"u")return null;let n=document.getElementById(xi);return n||(n=document.createElement("div"),n.id=xi,document.body.appendChild(n)),n},Tt=({open:n,onClose:e,title:s,subtitle:i,trailing:r,disableEscapeDismiss:o=!1,headerless:c=!1,noHeaderBorder:l=!1,ariaLabel:m,variant:a="fullscreen",dialogAlign:u="chat",children:p})=>{const{t:g}=ge(),h=f.useRef(null),[b,k]=f.useState(!1),[y,E]=f.useState(!1),v=f.useRef(null),N=f.useRef(null),A=f.useRef(e);if(f.useEffect(()=>{A.current=e},[e]),typeof document<"u"&&!h.current&&(h.current=df()),f.useEffect(()=>{if(!n){k(!1);return}const S=window.setTimeout(()=>k(!0),Rn);return()=>window.clearTimeout(S)},[n]),f.useEffect(()=>{if(!n){E(!1);return}const S=window.setTimeout(()=>E(!0),Rn+Ks+80);return()=>window.clearTimeout(S)},[n]),f.useEffect(()=>{if(!n)return;const S=document.body.style.overflow;N.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const C=()=>{const M=v.current;if(!M)return;(M.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??M).focus({preventScroll:!0})},w=window.setTimeout(C,Rn),T=M=>{if(M.key==="Escape"&&!o){A.current();return}if(M.key!=="Tab")return;const z=v.current;if(!z)return;const j=Array.from(z.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(D=>!D.hasAttribute("disabled")&&D.getAttribute("aria-hidden")!=="true");if(j.length===0){M.preventDefault(),z.focus({preventScroll:!0});return}const P=j[0],V=j[j.length-1],I=document.activeElement;M.shiftKey&&I===P?(M.preventDefault(),V.focus({preventScroll:!0})):!M.shiftKey&&I===V&&(M.preventDefault(),P.focus({preventScroll:!0}))};return document.addEventListener("keydown",T),()=>{window.clearTimeout(w),document.body.style.overflow=S,document.removeEventListener("keydown",T),N.current?.focus?.({preventScroll:!0}),N.current=null}},[o,n]),!n||!h.current)return null;const x=a==="dialog",R=t.jsxs("section",{ref:v,role:"dialog","aria-modal":"true","aria-label":m,tabIndex:-1,className:Q("flex flex-col bg-background text-foreground",x?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50"),style:x?{opacity:b?1:0,transform:b?"none":"scale(0.97)",transition:`opacity ${Ks}ms ease-out, transform ${Ks}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:b?"none":"translateX(100%)",transition:`transform ${Ks}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:S=>{b&&S.target===S.currentTarget&&S.propertyName==="transform"&&E(!0)},children:[c?null:t.jsxs("header",{className:Q("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!l&&"border-b border-border/70"),children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":g("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(J,{name:"close",className:"size-5"})}),t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[s?typeof s=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:s}):s:null,i?typeof i=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:i}):i:null]}),r?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:r}):null]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:y?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:p}):null}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return x?is.createPortal(t.jsx("div",{className:"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:b?1:0,paddingLeft:u==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:u==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:e,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:S=>S.stopPropagation(),children:R})}),h.current):is.createPortal(R,h.current)},ff=n=>{const e=de.c(8),{projectPath:s}=n,{t:i}=ge(),{journey:r}=wa();let o;if(e[0]!==r||e[1]!==s||e[2]!==i){const c=r?ja(r,s):[];let l;e[4]!==i?(l=i("mobile.projectEdit.spacesTitle"),e[4]=i,e[5]=l):l=e[5];let m;e[6]!==l?(m=t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:l}),e[6]=l,e[7]=m):m=e[7],o=t.jsxs("div",{className:"flex flex-col gap-2",children:[m,r!==null&&c.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("spaces.page.empty")}):null,c.map(gf)]}),e[0]=r,e[1]=s,e[2]=i,e[3]=o}else o=e[3];return o},mf=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),pf=n=>{const e=de.c(36),{worktree:s,onDelete:i}=n,{t:r}=ge();let o;e[0]!==s.path?(o={id:s.path},e[0]=s.path,e[1]=o):o=e[1];const{attributes:c,listeners:l,setNodeRef:m,transform:a,transition:u,isDragging:p}=or(o);let g;e[2]!==a?(g=ar.Transform.toString(a),e[2]=a,e[3]=g):g=e[3];const h=p?10:1;let b;e[4]!==g||e[5]!==h||e[6]!==u?(b={transform:g,transition:u,zIndex:h},e[4]=g,e[5]=h,e[6]=u,e[7]=b):b=e[7];const k=b,y=s.branch||s.label||s.path,E=p&&"shadow-lg shadow-black/20";let v;e[8]!==E?(v=Q("flex items-center gap-1 rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",E),e[8]=E,e[9]=v):v=e[9];let N;e[10]!==y||e[11]!==r?(N=r("mobile.projectEdit.dragWorktreeAria",{label:y}),e[10]=y,e[11]=r,e[12]=N):N=e[12];let A;e[13]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(Yn,{className:"size-4"}),e[13]=A):A=e[13];let x;e[14]!==c||e[15]!==l||e[16]!==N?(x=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":N,...c,...l,children:A}),e[14]=c,e[15]=l,e[16]=N,e[17]=x):x=e[17];let R;e[18]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx(J,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=R):R=e[18];let S;e[19]!==y?(S=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:y}),e[19]=y,e[20]=S):S=e[20];let C;e[21]!==y||e[22]!==r?(C=r("mobile.projectEdit.deleteWorktreeAria",{label:y}),e[21]=y,e[22]=r,e[23]=C):C=e[23];let w,T;e[24]===Symbol.for("react.memo_cache_sentinel")?(w={touchAction:"manipulation"},T=t.jsx(Xs,{className:"size-4"}),e[24]=w,e[25]=T):(w=e[24],T=e[25]);let M;e[26]!==i||e[27]!==C?(M=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":C,onClick:i,style:w,children:T}),e[26]=i,e[27]=C,e[28]=M):M=e[28];let z;return e[29]!==m||e[30]!==k||e[31]!==S||e[32]!==M||e[33]!==v||e[34]!==x?(z=t.jsxs("div",{ref:m,style:k,className:v,children:[x,R,S,M]}),e[29]=m,e[30]=k,e[31]=S,e[32]=M,e[33]=v,e[34]=x,e[35]=z):z=e[35],z},hf=({open:n,project:e,onClose:s,onWorktreesChanged:i})=>{const{t:r}=ge(),{currentTheme:o}=qi(),c=Oe(D=>D.isolatedSpacesEnabled),l=Ze(D=>D.updateProjectMeta),m=Ze(D=>D.discoverProjectIcon),a=Ze(D=>D.removeProjectIcon),u=Bn(D=>D.setWorktreeOrder),p=Ze(D=>e?D.projects.find(F=>F.id===e.id)?.iconImage??null:null),[g,h]=f.useState(""),[b,k]=f.useState(null),[y,E]=f.useState(null),[v,N]=f.useState(!1),[A,x]=f.useState([]),[R,S]=f.useState(null),C=e?.id??null;f.useEffect(()=>{!n||!e||(h(e.label),k(e.icon??null),E(e.color??null),x(e.worktrees))},[n,C]),f.useEffect(()=>{!n||!e||x(D=>{const F=e.worktrees.map(X=>X.path),L=D.map(X=>X.path);return F.length===L.length&&F.every(X=>L.includes(X))?D:e.worktrees})},[e?.worktrees]);const w=Qn(as(er,{activationConstraint:{distance:8}}),as(Zn,{coordinateGetter:nr})),T=()=>{if(!e)return;const D=g.trim();l(e.id,{label:D||e.label,icon:b,color:y}),s()},M=()=>{!e||v||(N(!0),m(e.id).then(D=>{if(!D.ok){we.error(D.error||r("projectEditDialog.toast.failedToDiscoverIcon"));return}if(D.skipped){we.success(r("projectEditDialog.toast.customIconAlreadySet"));return}we.success(r("projectEditDialog.toast.iconDiscovered"))}).finally(()=>N(!1)))},z=()=>{e&&a(e.id).then(D=>{if(!D.ok){we.error(D.error||r("projectEditDialog.toast.failedToRemoveIcon"));return}we.success(r("projectEditDialog.toast.iconRemoved"))})},j=D=>{const{active:F,over:L}=D;if(!L||F.id===L.id||!e)return;const q=A.findIndex(Z=>Z.path===F.id),X=A.findIndex(Z=>Z.path===L.id);if(q<0||X<0)return;const Y=[...A],[W]=Y.splice(q,1);Y.splice(X,0,W),x(Y),u(e.id,Y.map(Z=>mf(Z.path)))},P=y?Ji[y]??null:null,V=b?Hi[b]:null,I=!!p;return t.jsxs(t.Fragment,{children:[t.jsx(Tt,{open:n,onClose:s,title:r("projectEditDialog.title"),ariaLabel:r("projectEditDialog.title"),noHeaderBorder:!0,trailing:t.jsxs(Se,{type:"button",variant:"default",size:"sm","aria-label":r("projectEditDialog.actions.save"),onClick:T,disabled:!g.trim(),style:{touchAction:"manipulation"},children:[t.jsx(co,{className:"size-4"}),r("projectEditDialog.actions.save")]}),children:e?t.jsxs("div",{className:"h-full space-y-6 overflow-y-auto px-4 pb-8 pt-2",children:[t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx("span",{className:"flex size-16 items-center justify-center overflow-hidden rounded-2xl bg-[var(--surface-muted)] text-muted-foreground",style:e.iconBackground?{backgroundColor:e.iconBackground}:void 0,children:I?t.jsx(Yi,{project:{id:e.id,iconImage:p},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(Dn,{className:"size-7"})}):V?t.jsx(J,{name:V,className:"size-7",style:P?{color:P}:void 0}):t.jsx(Dn,{className:"size-7",style:P?{color:P}:void 0})})}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.name")}),t.jsx(eo,{value:g,onChange:D=>h(D.target.value),placeholder:r("projectEditDialog.field.namePlaceholder"),className:"h-11"}),t.jsx("p",{className:"truncate typography-meta text-muted-foreground",title:e.path,children:e.path})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.color")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>E(null),"aria-label":r("projectEditDialog.option.none"),className:Q("flex size-9 items-center justify-center rounded-xl border-2 transition-all",y===null?"border-foreground":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),qa.map(D=>t.jsx("button",{type:"button",onClick:()=>E(D.key),"aria-label":D.label,title:D.label,className:Q("size-9 rounded-xl border-2 transition-all",y===D.key?"border-foreground":"border-transparent hover:border-border/70"),style:{backgroundColor:D.cssVar,touchAction:"manipulation"}},D.key))]})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.icon")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>k(null),"aria-label":r("projectEditDialog.option.none"),className:Q("flex size-9 items-center justify-center rounded-xl border-2 transition-all",b===null?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),Ha.map(D=>t.jsx("button",{type:"button",onClick:()=>k(D.key),"aria-label":D.label,title:D.label,className:Q("flex size-9 items-center justify-center rounded-xl border-2 transition-all",b===D.key?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx(J,{name:D.Icon,className:"size-4",style:P?{color:P}:void 0})},D.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(Se,{size:"sm",variant:"outline",onClick:M,disabled:v,children:r(v?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),I?t.jsx(Se,{size:"sm",variant:"outline",onClick:z,children:r("projectEditDialog.actions.removeProjectIcon")}):null]})]}),e.isGitRepo?t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("mobile.projectEdit.worktreesTitle")}),A.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.worktreesEmpty")}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.reorderHint")}),t.jsx(tr,{sensors:w,collisionDetection:sr,onDragEnd:j,children:t.jsx(rr,{items:A.map(D=>D.path),strategy:ir,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:A.map(D=>t.jsx(pf,{worktree:D,onDelete:()=>S(D)},D.path))})})})]})]}):null,e.isGitRepo&&c?t.jsx(ff,{projectPath:e.path}):null]}):null}),e?t.jsx(Do,{open:!!R,project:{id:e.id,path:e.path},worktree:R,onClose:()=>S(null),onDeleted:()=>{x(D=>D.filter(F=>F.path!==R?.path)),i?.()}}):null]})};function gf(n){return t.jsx(pc,{entry:n,actions:"sheet"},n.id)}const bf=32,xf=80,yf=64,vf=.7,gr=(n,e)=>{const s=f.useRef(e);s.current=e;const i=e.enabled??!0;f.useEffect(()=>{if(!i)return;const r=n.current;if(!r)return;const c=window.Capacitor?.getPlatform?.()==="android"?xf:bf,l=r.ownerDocument;let m=!1,a=!1,u=0,p=0;const g=()=>l.getSelection()?.isCollapsed===!1,h=()=>{m=!1},b=()=>{m&&g()&&h()},k=E=>{if(E.touches.length!==1||g()){m=!1;return}const v=E.touches[0],N=r.clientWidth,A=v.clientX<=c,x=v.clientX>=N-c;m=A||x,a=A,u=v.clientX,p=v.clientY},y=E=>{if(!m||(m=!1,g()))return;const v=E.changedTouches[0];if(!v)return;const N=v.clientX-u,A=v.clientY-p;Math.abs(N)<yf||Math.abs(A)>Math.abs(N)*vf||a&&N<=0||!a&&N>=0||(a?s.current.onLeftEdgeSwipe?.():s.current.onRightEdgeSwipe?.())};return r.addEventListener("touchstart",k,{passive:!0}),r.addEventListener("touchend",y,{passive:!0}),r.addEventListener("touchcancel",h,{passive:!0}),r.addEventListener("selectstart",h),l.addEventListener("selectionchange",b),()=>{r.removeEventListener("touchstart",k),r.removeEventListener("touchend",y),r.removeEventListener("touchcancel",h),r.removeEventListener("selectstart",h),l.removeEventListener("selectionchange",b)}},[i,n])},wf=new Set,jf=[["manual","sessions.sidebar.header.projectSort.manual"],["a-z","sessions.sidebar.header.projectSort.aToZ"],["z-a","sessions.sidebar.header.projectSort.zToA"],["date-added","sessions.sidebar.header.projectSort.dateAdded"],["recent","sessions.sidebar.header.projectSort.recent"]],kf=[["projects","mobile.sessions.viewMode.projects"],["timeline","mobile.sessions.viewMode.timeline"]],Sf=7,Nf=3,Yt=40,xs="openchamber:work",ys="openchamber:recent",Cf=12,Rf=16,Ef=(n,e)=>{const s=ze(n),i=ze(e),r=i.endsWith("/")?i:`${i}/`;return!!(s&&i&&(s===i||s.startsWith(r)))},En=(n,e)=>n.worktrees.find(s=>ze(s.path)===e)??null,In=(n,e,s)=>to([n.title,n.id,mt(n),e],s),If=n=>{const e=de.c(2),{ariaLabel:s}=n;let i;return e[0]!==s?(i=t.jsx("span",{className:"inline-block size-1.5 shrink-0 rounded-full bg-primary","aria-label":s}),e[0]=s,e[1]=i):i=e[1],i},yi=n=>{const e=de.c(12),{onClick:s,className:i}=n,{t:r}=ge();let o;e[0]!==r?(o=r("sessions.sidebar.project.actions.newWorktree"),e[0]=r,e[1]=o):o=e[1];const c=o;let l;e[2]!==i?(l=Q("flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",i),e[2]=i,e[3]=l):l=e[3];let m;e[4]!==s?(m=g=>{g.stopPropagation(),s()},e[4]=s,e[5]=m):m=e[5];let a,u;e[6]===Symbol.for("react.memo_cache_sentinel")?(a={touchAction:"manipulation"},u=t.jsx(J,{name:"node-tree",className:"size-4"}),e[6]=a,e[7]=u):(a=e[6],u=e[7]);let p;return e[8]!==c||e[9]!==l||e[10]!==m?(p=t.jsx("button",{type:"button",className:l,"aria-label":c,title:c,onClick:m,style:a,children:u}),e[8]=c,e[9]=l,e[10]=m,e[11]=p):p=e[11],p},An=n=>{const e=de.c(10),{label:s,onClick:i,className:r}=n;let o;e[0]!==r?(o=Q("flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",r),e[0]=r,e[1]=o):o=e[1];let c;e[2]!==i?(c=u=>{u.stopPropagation(),i()},e[2]=i,e[3]=c):c=e[3];let l,m;e[4]===Symbol.for("react.memo_cache_sentinel")?(l={touchAction:"manipulation"},m=t.jsx(J,{name:"add",className:"size-4"}),e[4]=l,e[5]=m):(l=e[4],m=e[5]);let a;return e[6]!==s||e[7]!==o||e[8]!==c?(a=t.jsx("button",{type:"button",className:o,"aria-label":s,title:s,onClick:c,style:l,children:m}),e[6]=s,e[7]=o,e[8]=c,e[9]=a):a=e[9],a},vi=n=>{const e=de.c(83),{session:s,active:i,indent:r,contextLabel:o,statusOnRight:c,hasChildren:l,expanded:m,onToggleChildren:a,onSelect:u,revealed:p,onRevealedChange:g,confirmingDelete:h,onArchive:b,onRequestDelete:k,onConfirmDelete:y,renaming:E,onRequestRename:v,onSubmitRename:N,onCancelRename:A,work:x,pin:R,descendantIdsOf:S}=n,C=c===void 0?!1:c,w=l===void 0?!1:l,T=m===void 0?!1:m,M=p===void 0?!1:p,z=h===void 0?!1:h,j=E===void 0?!1:E,{t:P}=ge();let V;e[0]!==s?(V=ln(Oo(s)),e[0]=s,e[1]=V):V=e[1];const I=V;let D;e[2]!==s.title||e[3]!==P?(D=s.title?.trim()||P("mobile.sessions.untitled"),e[2]=s.title,e[3]=P,e[4]=D):D=e[4];const F=D,L=!!(g&&b),q=ao(s.id,s.directory,L&&(M||j)),X=Vn(s.id),Y=Un(s.id),W=Y!==null,Z=!W&&X>0&&!i,fe=Gn(s.id,W),ae=(W||Z)&&fe;let te;e[5]!==W||e[6]!==s||e[7]!==x?.inWork?(te=!!x?.inWork&&!W&&sl(s),e[5]=W,e[6]=s,e[7]=x?.inWork,e[8]=te):te=e[8];const le=te;let B;e[9]!==S||e[10]!==T||e[11]!==w||e[12]!==s.id?(B=S&&!(w&&T)?[s.id,...S(s.id)]:[s.id],e[9]=S,e[10]=T,e[11]=w,e[12]=s.id,e[13]=B):B=e[13];const ne=Fo(B);let ie;e[14]!==q||e[15]!==T||e[16]!==w||e[17]!==r||e[18]!==W||e[19]!==a||e[20]!==Z||e[21]!==C||e[22]!==P||e[23]!==Y?(ie=!C&&(q.pending||W||Z||w&&a)?t.jsx("button",{type:"button",className:"absolute z-10 flex w-6 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:{left:Math.max(r-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":q.pending?P("sessions.aiRename.generating"):P(T?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),disabled:!w||!a,onClick:pe=>{pe.stopPropagation(),a?.()},children:q.pending?t.jsx(J,{name:"loader-4",className:"size-3 animate-spin text-primary","aria-label":P("sessions.aiRename.generating")}):W||Z?t.jsx(Ys,{state:Y??"unread"}):t.jsx(Xn,{className:Q("size-[18px] transition-transform duration-150",T?"rotate-0":"-rotate-90")})}):null,e[14]=q,e[15]=T,e[16]=w,e[17]=r,e[18]=W,e[19]=a,e[20]=Z,e[21]=C,e[22]=P,e[23]=Y,e[24]=ie):ie=e[24];let H;e[25]!==i||e[26]!==q||e[27]!==o||e[28]!==r||e[29]!==W||e[30]!==A||e[31]!==g||e[32]!==u||e[33]!==N||e[34]!==ne||e[35]!==R?.pinned||e[36]!==j||e[37]!==M||e[38]!==s||e[39]!==ae||e[40]!==le||e[41]!==Z||e[42]!==C||e[43]!==P||e[44]!==I||e[45]!==F||e[46]!==Y?(H=j&&N&&A?t.jsx(_o,{initialTitle:F,indent:r,aiRename:q,onSubmit:N,onCancel:A}):t.jsx("button",{type:"button",className:Q("flex min-w-0 flex-1 items-center gap-2.5 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",o?"min-h-10 py-1":"h-9"),style:{paddingLeft:r,touchAction:"manipulation"},onClick:()=>{if(M){g?.(!1);return}u()},children:t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsxs("span",{className:"flex items-center gap-2.5",children:[t.jsx("span",{className:Q("block min-w-0 flex-1 truncate typography-ui-label",i?"text-primary":"text-foreground"),children:F}),R?.pinned?t.jsx(J,{name:"pushpin",className:"size-3 shrink-0 text-muted-foreground","aria-label":P("sessions.sidebar.session.status.pinned")}):null,C&&(q.pending||W||Z)?q.pending?t.jsx(J,{name:"loader-4",className:"size-3 shrink-0 animate-spin text-primary","aria-label":P("sessions.aiRename.generating")}):t.jsx(Ys,{state:Y??"unread"}):null,le?t.jsx(J,{name:"check",className:"size-3.5 shrink-0 text-muted-foreground","aria-label":P("sessions.sidebar.session.work.doneSuggested")}):null,t.jsx(Lo,{session:s}),t.jsx($o,{...ne}),ae?t.jsx(Jn,{sessionId:s.id,running:W,className:"typography-micro"}):I?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:I}):null]}),o?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:o}):null]})}),e[25]=i,e[26]=q,e[27]=o,e[28]=r,e[29]=W,e[30]=A,e[31]=g,e[32]=u,e[33]=N,e[34]=ne,e[35]=R?.pinned,e[36]=j,e[37]=M,e[38]=s,e[39]=ae,e[40]=le,e[41]=Z,e[42]=C,e[43]=P,e[44]=I,e[45]=F,e[46]=Y,e[47]=H):H=e[47];let oe;e[48]!==ie||e[49]!==H?(oe=t.jsxs(t.Fragment,{children:[ie,H]}),e[48]=ie,e[49]=H,e[50]=oe):oe=e[50];const ue=oe;if(!L){const pe=i||void 0,Ne=i&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let De;e[51]!==Ne?(De=Q("relative flex items-center gap-1 transition-colors",Ne),e[51]=Ne,e[52]=De):De=e[52];let Re;e[53]!==ue||e[54]!==De?(Re=t.jsx("div",{className:De,children:ue}),e[53]=ue,e[54]=De,e[55]=Re):Re=e[55];let Ae;return e[56]!==pe||e[57]!==Re?(Ae=t.jsx("div",{"data-active-session":pe,className:"relative overflow-hidden",children:Re}),e[56]=pe,e[57]=Re,e[58]=Ae):Ae=e[58],Ae}const xe=Mo+(x?As:0)+(R?As:0);let ye;e[59]!==g?(ye=pe=>g?.(pe),e[59]=g,e[60]=ye):ye=e[60];const ke=i&&"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]";let U;e[61]!==ke?(U=Q("relative flex w-full items-center gap-1 bg-background transition-colors",ke),e[61]=ke,e[62]=U):U=e[62];let he;e[63]!==z||e[64]!==b||e[65]!==y||e[66]!==k||e[67]!==v||e[68]!==g||e[69]!==R||e[70]!==M||e[71]!==s.id||e[72]!==F||e[73]!==x?(he=t.jsx(zo,{sessionId:s.id,title:F,revealed:M,confirmingDelete:z,onArchive:b,onRequestDelete:k,onConfirmDelete:y,onRequestRename:v,onRevealedChange:g,work:x,pin:R}),e[63]=z,e[64]=b,e[65]=y,e[66]=k,e[67]=v,e[68]=g,e[69]=R,e[70]=M,e[71]=s.id,e[72]=F,e[73]=x,e[74]=he):he=e[74];let Ie;return e[75]!==i||e[76]!==M||e[77]!==ue||e[78]!==xe||e[79]!==ye||e[80]!==U||e[81]!==he?(Ie=t.jsx(nn,{actionsWidth:xe,revealed:M,onRevealedChange:ye,dataActiveSession:i,contentClassName:U,actions:he,children:ue}),e[75]=i,e[76]=M,e[77]=ue,e[78]=xe,e[79]=ye,e[80]=U,e[81]=he,e[82]=Ie):Ie=e[82],Ie},wi=[],Af=n=>{const e=de.c(40),{run:s,laneNodes:i,indent:r}=n,{t:o}=ge();let c;e[0]!==s.key?(c=M=>M.runOverviewKey===s.key,e[0]=s.key,e[1]=c):c=e[1];const l=Oe(c);let m;e[2]!==i?(m={nodes:i,includeUnreadSubtasks:!1},e[2]=i,e[3]=m):m=e[3];const a=oo(m);let u;e[4]!==s.lastActivity?(u=ln(s.lastActivity),e[4]=s.lastActivity,e[5]=u):u=e[5];const p=u,g=l||void 0,h=l&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let b;e[6]!==h?(b=Q("relative flex items-center overflow-hidden transition-colors",h),e[6]=h,e[7]=b):b=e[7];let k;e[8]!==a||e[9]!==r?(k=a?t.jsx("span",{className:"absolute flex w-6 items-center justify-center",style:{left:Math.max(r-32,2),top:0,bottom:0},children:t.jsx(lo,{state:a})}):null,e[8]=a,e[9]=r,e[10]=k):k=e[10];let y;e[11]!==r?(y={paddingLeft:r,touchAction:"manipulation"},e[11]=r,e[12]=y):y=e[12];let E;e[13]!==s.key?(E=()=>Oe.getState().setRunOverviewKey(s.key),e[13]=s.key,e[14]=E):E=e[14];let v;e[15]!==s.title||e[16]!==o?(v=o("sessions.sidebar.run.openOverviewAria",{title:s.title}),e[15]=s.title,e[16]=o,e[17]=v):v=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(Zi,{className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),e[18]=N):N=e[18];const A=l?"text-primary":"text-foreground";let x;e[19]!==A?(x=Q("block min-w-0 flex-1 truncate typography-ui-label",A),e[19]=A,e[20]=x):x=e[20];let R;e[21]!==s.title||e[22]!==x?(R=t.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[N,t.jsx("span",{className:x,children:s.title})]}),e[21]=s.title,e[22]=x,e[23]=R):R=e[23];let S;e[24]!==s.providerIDs?(S=t.jsx(Bo,{providerIDs:s.providerIDs}),e[24]=s.providerIDs,e[25]=S):S=e[25];let C;e[26]!==p?(C=p?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:p}):null,e[26]=p,e[27]=C):C=e[27];let w;e[28]!==v||e[29]!==R||e[30]!==S||e[31]!==C||e[32]!==y||e[33]!==E?(w=t.jsxs("button",{type:"button",className:"flex h-9 w-full min-w-0 items-center gap-2.5 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",style:y,onClick:E,"aria-label":v,children:[R,S,C]}),e[28]=v,e[29]=R,e[30]=S,e[31]=C,e[32]=y,e[33]=E,e[34]=w):w=e[34];let T;return e[35]!==w||e[36]!==g||e[37]!==b||e[38]!==k?(T=t.jsxs("div",{"data-active-session":g,className:b,children:[k,w]}),e[35]=w,e[36]=g,e[37]=b,e[38]=k,e[39]=T):T=e[39],T},Pf=n=>{const e=de.c(11),{indent:s,onClick:i}=n,{t:r}=ge();let o;e[0]!==s?(o={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=o):o=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx(Xn,{className:"size-4"}),e[2]=c):c=e[2];let l;e[3]!==r?(l=r("sessions.sidebar.group.showMore"),e[3]=r,e[4]=l):l=e[4];let m;e[5]!==l?(m=t.jsx("span",{className:"typography-micro",children:l}),e[5]=l,e[6]=m):m=e[6];let a;return e[7]!==i||e[8]!==o||e[9]!==m?(a=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",style:o,onClick:i,children:[c,m]}),e[7]=i,e[8]=o,e[9]=m,e[10]=a):a=e[10],a},Tf=n=>{const e=de.c(11),{indent:s,onClick:i}=n,{t:r}=ge();let o;e[0]!==s?(o={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=o):o=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=t.jsx(cu,{className:"size-4"}),e[2]=c):c=e[2];let l;e[3]!==r?(l=r("sessions.sidebar.group.showFewer"),e[3]=r,e[4]=l):l=e[4];let m;e[5]!==l?(m=t.jsx("span",{className:"typography-micro",children:l}),e[5]=l,e[6]=m):m=e[6];let a;return e[7]!==i||e[8]!==o||e[9]!==m?(a=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",style:o,onClick:i,children:[c,m]}),e[7]=i,e[8]=o,e[9]=m,e[10]=a):a=e[10],a},Df=n=>{const e=de.c(29),{worktree:s}=n,{t:i}=ge();let r;e[0]!==s.path?(r=ze(s.path),e[0]=s.path,e[1]=r):r=e[1];const o=r;let c;e[2]!==o?(c={id:o},e[2]=o,e[3]=c):c=e[3];const{attributes:l,listeners:m,setNodeRef:a,transform:u,transition:p,isDragging:g}=or(c),h=s.branch||s.label||s.path;let b;e[4]!==u?(b=ar.Transform.toString(u),e[4]=u,e[5]=b):b=e[5];const k=g?10:1;let y;e[6]!==b||e[7]!==k||e[8]!==p?(y={transform:b,transition:p,zIndex:k},e[6]=b,e[7]=k,e[8]=p,e[9]=y):y=e[9];const E=g&&"shadow-lg shadow-black/20";let v;e[10]!==E?(v=Q("flex items-center gap-1 rounded-xl bg-background px-1 py-1",E),e[10]=E,e[11]=v):v=e[11];let N;e[12]!==h||e[13]!==i?(N=i("mobile.sessions.dragHandleAria",{label:h}),e[12]=h,e[13]=i,e[14]=N):N=e[14];let A;e[15]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(Yn,{className:"size-4"}),e[15]=A):A=e[15];let x;e[16]!==l||e[17]!==m||e[18]!==N?(x=t.jsx("button",{type:"button",className:"flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-lg text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":N,...l,...m,children:A}),e[16]=l,e[17]=m,e[18]=N,e[19]=x):x=e[19];let R;e[20]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx(J,{name:"git-branch",className:"size-4 shrink-0 text-muted-foreground"}),e[20]=R):R=e[20];let S;e[21]!==h?(S=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-bold text-muted-foreground",children:h}),e[21]=h,e[22]=S):S=e[22];let C;return e[23]!==a||e[24]!==x||e[25]!==S||e[26]!==y||e[27]!==v?(C=t.jsxs("div",{ref:a,style:y,className:v,children:[x,R,S]}),e[23]=a,e[24]=x,e[25]=S,e[26]=y,e[27]=v,e[28]=C):C=e[28],C},_f=n=>{const e=de.c(61),{project:s,totalSessions:i,expanded:r,onToggleExpanded:o,onReorderWorktrees:c}=n,{t:l}=ge();let m;e[0]!==s.id?(m={id:s.id},e[0]=s.id,e[1]=m):m=e[1];const{attributes:a,listeners:u,setNodeRef:p,transform:g,transition:h,isDragging:b}=or(m);let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k={activationConstraint:{distance:8}},e[2]=k):k=e[2];let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y={coordinateGetter:nr},e[3]=y):y=e[3];const E=Qn(as(er,k),as(Zn,y)),v=s.worktrees.length>0;let N;e[4]!==c||e[5]!==s.worktrees?(N=Z=>{const{active:fe,over:ae}=Z;if(!ae||fe.id===ae.id)return;const te=s.worktrees.map(Bf),le=te.indexOf(String(fe.id)),B=te.indexOf(String(ae.id));if(le<0||B<0)return;const ee=[...te],[ne]=ee.splice(le,1);ee.splice(B,0,ne),c(ee)},e[4]=c,e[5]=s.worktrees,e[6]=N):N=e[6];const A=N;let x;e[7]!==g?(x=ar.Transform.toString(g),e[7]=g,e[8]=x):x=e[8];const R=b?10:1;let S;e[9]!==x||e[10]!==R||e[11]!==h?(S={transform:x,transition:h,zIndex:R},e[9]=x,e[10]=R,e[11]=h,e[12]=S):S=e[12];const C=b&&"shadow-lg shadow-black/20";let w;e[13]!==C?(w=Q("rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",C),e[13]=C,e[14]=w):w=e[14];let T;e[15]!==s.label||e[16]!==l?(T=l("mobile.sessions.dragHandleAria",{label:s.label}),e[15]=s.label,e[16]=l,e[17]=T):T=e[17];let M;e[18]===Symbol.for("react.memo_cache_sentinel")?(M=t.jsx(Yn,{className:"size-4"}),e[18]=M):M=e[18];let z;e[19]!==a||e[20]!==u||e[21]!==T?(z=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":T,...a,...u,children:M}),e[19]=a,e[20]=u,e[21]=T,e[22]=z):z=e[22];let j;e[23]!==r||e[24]!==s.label||e[25]!==l?(j=r?l("sessions.sidebar.group.collapseAria",{label:s.label}):l("sessions.sidebar.group.expandAria",{label:s.label}),e[23]=r,e[24]=s.label,e[25]=l,e[26]=j):j=e[26];const P=!v;let V;e[27]===Symbol.for("react.memo_cache_sentinel")?(V={touchAction:"manipulation"},e[27]=V):V=e[27];let I;e[28]!==s?(I=t.jsx(Is,{project:s}),e[28]=s,e[29]=I):I=e[29];let D;e[30]!==s.label?(D=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s.label}),e[30]=s.label,e[31]=D):D=e[31];let F;e[32]!==i?(F=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:i}),e[32]=i,e[33]=F):F=e[33];let L;e[34]!==r||e[35]!==v?(L=v?t.jsx(Xn,{className:Q("size-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-180")}):null,e[34]=r,e[35]=v,e[36]=L):L=e[36];let q;e[37]!==r||e[38]!==o||e[39]!==j||e[40]!==P||e[41]!==I||e[42]!==D||e[43]!==F||e[44]!==L?(q=t.jsxs("button",{type:"button",className:"flex min-h-9 min-w-0 flex-1 items-center gap-2 rounded-xl px-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",onClick:o,"aria-expanded":r,"aria-label":j,disabled:P,style:V,children:[I,D,F,L]}),e[37]=r,e[38]=o,e[39]=j,e[40]=P,e[41]=I,e[42]=D,e[43]=F,e[44]=L,e[45]=q):q=e[45];let X;e[46]!==z||e[47]!==q?(X=t.jsxs("div",{className:"flex items-center gap-1",children:[z,q]}),e[46]=z,e[47]=q,e[48]=X):X=e[48];let Y;e[49]!==r||e[50]!==A||e[51]!==v||e[52]!==s.worktrees||e[53]!==E?(Y=r&&v?t.jsx(tr,{sensors:E,collisionDetection:sr,onDragEnd:A,children:t.jsx(rr,{items:s.worktrees.map(Lf),strategy:ir,children:t.jsx("div",{className:"mt-1 flex flex-col gap-0.5 pl-3",children:s.worktrees.map($f)})})}):null,e[49]=r,e[50]=A,e[51]=v,e[52]=s.worktrees,e[53]=E,e[54]=Y):Y=e[54];let W;return e[55]!==p||e[56]!==X||e[57]!==Y||e[58]!==S||e[59]!==w?(W=t.jsxs("div",{ref:p,style:S,className:w,children:[X,Y]}),e[55]=p,e[56]=X,e[57]=Y,e[58]=S,e[59]=w,e[60]=W):W=e[60],W},ji=({open:n,onOpenChange:e,variant:s="drawer",footer:i})=>{const{t:r}=ge(),{git:o}=Kn(),c=Qe(d=>d.ensureStatus),l=Gi(),m=ss(d=>d.activeSessions),a=n||s==="sidebar",u=f.useRef(wf),p=Tn(f.useCallback(d=>(a&&(u.current=d.ids),u.current),[a])),g=f.useRef(Ja),h=Li(f.useCallback(d=>(a&&(g.current=d.rankById),g.current),[a])),b=Ze(d=>d.projects),k=Ya(d=>d.projects),y=Ze(d=>d.activeProjectId),E=Nt(d=>d.currentDirectory),v=_e(d=>d.currentSessionId),N=_e(d=>d.setCurrentSession),A=_e(d=>d.archiveSession),x=_e(d=>d.archiveSessions),R=_e(d=>d.deleteSession),S=_e(d=>d.deleteSessions),C=_e(d=>d.updateSessionTitle),w=_e(d=>d.openNewSessionDraft),T=Ze(d=>d.setActiveProject),M=Ze(d=>d.setActiveProjectIdOnly),z=Ze(d=>d.reorderProjects),j=Ze(d=>d.manualProjectOrder),P=Ht(d=>d.projectSortOrder),V=Ht(d=>d.setProjectSortOrder),I=Ht(d=>d.sidebarViewMode),D=Ht(d=>d.setSidebarViewMode),F=Ht(d=>d.showRecentSection),L=Ht(d=>d.setShowRecentSection),q=Tn(d=>d.toggle),X=I==="projects"&&F,Y=Xa(a&&(I==="timeline"||X)),W=Ze(d=>d.removeProject),Z=Gs(d=>d.projectExpanded),fe=Gs(d=>d.worktreeExpanded),ae=Gs(d=>d.setProjectExpanded),te=Gs(d=>d.setWorktreeExpanded),le=Bn(d=>d.orderByProject),B=Bn(d=>d.setWorktreeOrder),ee=gi(d=>d.expandedParents),ne=gi(d=>d.toggleParent),[ie,H]=f.useState(""),[oe,ue]=f.useState(null),[xe,ye]=f.useState(null),[ke,U]=f.useState(null),[he,Ie]=f.useState(null),[pe,Ne]=f.useState(null),[De,Re]=f.useState(null),[Ae,Ee]=f.useState(null),[Me,$e]=f.useState(0),[He,et]=f.useState(!1),[cn,Je]=f.useState(!1),[tt,bt]=f.useState(!1),[xt,yt]=f.useState(null),[Ts,Ds]=f.useState(()=>new Map(_e.getState().availableWorktreesByProject)),[Pe,_s]=f.useState(()=>{const d=new Set;for(const[O,$]of _e.getState().availableWorktreesByProject)$.length>0&&d.add(O);return d}),[Ve,at]=f.useState(!1),[un,fs]=f.useState(new Set),[dn,Bt]=f.useState(new Map),[Rt,Ke]=f.useState(Js),lt=f.useRef(null);f.useEffect(()=>{if(!n){H(""),at(!1),fs(new Set),Bt(new Map),Ke(Js),ue(null),ye(null),U(null),Ie(null),Ne(null),Re(null);return}Vi(l)},[n]),f.useEffect(()=>{Ve||fs(new Set)},[Ve]),f.useEffect(()=>{Ke(Js)},[I]),f.useEffect(()=>{if(!n||b.length===0)return;let d=!1;return(async()=>{const $=await Promise.all(b.map(async K=>{const re=ze(K.path);if(!re)return null;const me=await o.checkIsGitRepository(re).catch(()=>null),ce=me?await so({id:K.id,path:re}).catch(()=>null):[];return[re,ce,me]}));d||(Ds(K=>{const re=new Map;for(const me of $){if(!me)continue;const[ce,Fe,Ye]=me,St=Ye===null||Fe===null;re.set(ce,St?K.get(ce)??[]:Fe)}return no(b,re)}),_s(K=>{const re=new Set;for(const me of $){if(!me)continue;const[ce,,Fe]=me;(Fe===null?K.has(ce):Fe)&&re.add(ce)}return re}))})(),()=>{d=!0}},[o,n,b,Me]);const je=f.useMemo(()=>hc(b.map(d=>({id:d.id,label:d.label?.trim()||Cn(d.path),path:ze(d.path),icon:d.icon,color:d.color,iconImage:d.iconImage,iconBackground:d.iconBackground,isGitRepo:Pe.has(ze(d.path)),worktrees:Xd(le[d.id],Ts.get(ze(d.path))??[]),addedAt:d.addedAt,lastOpenedAt:d.lastOpenedAt})),P,j),[Pe,j,P,b,le,Ts]),Be=f.useMemo(()=>{const d=new Map(l.map(K=>[K.id,K])),O=m.map(K=>{const re=d.get(K.id);return re?Qa(re,K):K}),$=new Set(O.map(K=>K.id));for(const K of l)$.has(K.id)||O.push(K);return O.filter(K=>!K.time?.archived)},[m,l]),dt=f.useMemo(()=>{const d=new Map;for(const O of Be){const $=ut(O);if(!$)continue;const K=d.get($)??[];K.push(O),d.set($,K)}return d},[Be]),Ms=f.useCallback(d=>Us(dt,d),[dt]),{projectSessions:Te,chatSessions:Lt}=f.useMemo(()=>gc(Be,!1),[Be]),$t=Oe(d=>d.sessionWorkEnabled),qe=f.useMemo(()=>{const d=new Set;if(!$t)return d;for(const O of Be)if(!(ut(O)||jn(mt(O))||!Qi(O))){d.add(O.id);for(const $ of Us(dt,O.id))d.add($)}return d},[dt,$t,Be]),vt=f.useMemo(()=>qe.size>0?Te.filter(d=>!qe.has(d.id)):Te,[Te,qe]),Ft=f.useMemo(()=>qe.size>0?Lt.filter(d=>!qe.has(d.id)):Lt,[Lt,qe]),st=ka(),Et=f.useMemo(()=>new Map(st.map(d=>[d.id,d])),[st]),ht=f.useMemo(()=>new Map(st.map(d=>[d.id,d.name||r("sessions.sidebar.grouping.spaceUnnamed")])),[st,r]),Ue=f.useMemo(()=>bc(Te,je.map(d=>({id:d.id,normalizedPath:d.path})),new Map(je.map(d=>[d.path,d.worktrees])),!1,[],k,st),[k,Te,je,st]),nt=f.useMemo(()=>Za(Te,d=>{const O=Ue.bySessionId.get(d.id);return(O?je.find(K=>K.id===O.projectId):void 0)?.path||ze(mt(d))||null}),[Te,je,Ue]),Wt=f.useMemo(()=>{const d=new Map(Be.map(K=>[K.id,K])),O=K=>({session:K,children:(dt.get(K.id)??[]).map(O),worktree:null}),$=new Map;for(const K of nt.runs.values())$.set(K.key,K.memberIds.flatMap(re=>{const me=d.get(re);return me?[O(me)]:[]}));return $},[dt,nt,Be]),Vt=f.useMemo(()=>({key:hs,label:"",path:"",worktree:null,space:null,sessions:Jt(Ft,p,h)}),[p,Ft,h]),fn=f.useMemo(()=>new Set(Vt.sessions.filter(d=>Xr(p,mt(d)||null,d.id)).map(d=>d.id)),[Vt,p]),Ut=f.useMemo(()=>({key:xs,label:"",path:"",worktree:null,space:null,sessions:qe.size>0?Jt(Be.filter(d=>qe.has(d.id)),p,h):[]}),[p,h,Be,qe]),Gt=xc({enabled:a&&X,isVSCode:!1,pinnedSessionIds:p,sessionOrderRanks:h,sessions:vt}),[Kt,zs]=f.useState(Gt);a&&Kt!==Gt&&zs(Gt);const wt=a?Gt:Kt,Os=f.useMemo(()=>{const d=new Set;for(const O of wt){d.add(O.id);for(const $ of Us(dt,O.id))d.add($)}return{key:ys,label:"",path:"",worktree:null,space:null,sessions:d.size>0?Jt(vt.filter(O=>d.has(O.id)),p,h):[]}},[dt,p,wt,vt,h]),_=f.useMemo(()=>{const d=new Map;if(wt.length===0)return d;const O=Zr({sessions:wt,projects:je.map($=>({id:$.id,normalizedPath:$.path,label:$.label})),ownerBySessionId:Ue.bySessionId,availableWorktreesByProject:new Map(je.map($=>[$.path,$.worktrees])),gitBranches:Y,homeDirectory:null,hideBranchMatchingProjectLabel:!0,spaceLabelById:ht});for(const[$,K]of O)K.projectLabel&&d.set($,K.branchLabel?`${K.projectLabel} · ${K.branchLabel}`:K.projectLabel);return d},[Y,je,wt,Ue,ht]),G=`${hs}::${hs}`,se=f.useMemo(()=>Ft.filter(d=>!ut(d)).length,[Ft]),be=ie.trim().toLowerCase(),ct=f.useRef(null);f.useEffect(()=>{if(!n)return;const d=window.requestAnimationFrame(()=>{const O=ct.current;if(!O)return;(O.querySelector('[data-active-session="true"]')??O.querySelector('[data-active-project="true"]'))?.scrollIntoView({block:"center"})});return()=>window.cancelAnimationFrame(d)},[n]);const qt=f.useMemo(()=>{const d=je.map($=>({project:$,buckets:[],totalSessions:0,isActive:$.id===y})),O=($,K,re,me=null)=>{const ce=ze(K)||$.project.path,Fe=ce||"__root__";let Ye=$.buckets.find(St=>St.key===Fe);return Ye||(Ye={key:Fe,label:(me?me.name||r("sessions.sidebar.grouping.spaceUnnamed"):null)||re?.branch||Cn(ce),path:ce,worktree:re,space:me,sessions:[]},$.buckets.push(Ye)),Ye};for(const $ of d){O($,$.project.path,null);for(const K of $.project.worktrees)O($,K.path,K);for(const K of st)K.directory&&ze(K.projectDirectory)===ze($.project.path)&&O($,K.directory,null,K)}for(const $ of vt){const K=Ue.bySessionId.get($.id);if(!K)continue;const re=d.find(Ye=>Ye.project.id===K.projectId);if(!re)continue;const me=En(re.project,K.scopeDirectory),ce=K.kind==="space"&&K.spaceId?Et.get(K.spaceId)??null:null;(ce?O(re,K.scopeDirectory,null,ce):me&&!nt.runKeyBySessionId.has($.id)?O(re,me.path,me):O(re,re.project.path,null)).sessions.push($)}for(const $ of d)for(const K of $.buckets){K.sessions=Jt(K.sessions,p,h);for(const re of K.sessions)ut(re)||($.totalSessions+=1)}return d},[y,p,je,nt,vt,h,Ue,st,Et,r]),It=ze(E),mn=d=>d.isActive?It===d.project.path?d.project.path:d.project.worktrees.find($=>Ef(It,$.path))?.path??d.project.path:null,Go=d=>Z[d.project.id]??!0,Ko=(d,O)=>fe[`${d.project.id}::${O.key}`]??!0,xr=d=>{Bt(O=>{if(!O.has(d))return O;const $=new Map(O);return $.delete(d),$})},qo=d=>{Bt(O=>{let $=!1;const K=new Map(O),re=`${d}::`;for(const me of K.keys())me.startsWith(re)&&(K.delete(me),$=!0);return $?K:O})},Ho=(d,O,$)=>{Bt(K=>{const re=new Map(K);return re.set(d,O+$),re})},ms=(d,O,$,K)=>{const re=K?.pageSize??Sf,me=K?.alwaysVisibleIds,ce=new Set(O.sessions.map(ve=>ve.id)),Fe=new Map;for(const ve of O.sessions){const Xe=ut(ve);if(Xe&&ce.has(Xe)){const gt=Fe.get(Xe)??[];gt.push(ve),Fe.set(Xe,gt)}}const Ye=O.sessions.filter(ve=>{const Xe=ut(ve);return!Xe||!ce.has(Xe)}),St=new Set,bn=Ye.flatMap(ve=>{const Xe=nt.runKeyBySessionId.get(ve.id),gt=Xe?nt.runs.get(Xe):void 0;return gt?St.has(gt.key)?[]:(St.add(gt.key),[{kind:"run",run:gt}]):[{kind:"session",session:ve}]}),Br=ve=>ve.kind==="session"&&!!me?.has(ve.session.id),ua=me?bn.filter(Br):[],xn=me?bn.filter(ve=>!Br(ve)):bn,da=dn.get(d)??re,yn=xn.slice(0,da),fa=[...ua,...yn],Lr=xn.length-yn.length,ma=xn.length>re&&Lr===0,$r=(ve,Xe)=>{const gt=Fe.get(ve.id)??[],vn=gt.length>0,Fr=!!ee[ve.id],pa=Xe===$;return t.jsxs(f.Fragment,{children:[t.jsx(vi,{session:ve,active:v===ve.id,indent:Xe,contextLabel:pa?K?.rootContextLabel?.(ve):void 0,hasChildren:vn,expanded:Fr,onToggleChildren:vn?()=>ne(ve.id):void 0,onSelect:()=>pn(ve),statusOnRight:K?.statusOnRight,revealed:xe===ve.id,onRevealedChange:ps=>yr(ve.id,ps),confirmingDelete:ke===ve.id,onArchive:()=>{wr(ve)},onRequestDelete:()=>U(ve.id),onConfirmDelete:()=>{Nr(ve)},renaming:he===ve.id,onRequestRename:()=>Cr(ve.id),onSubmitRename:ps=>{Rr(ve.id,ps)},onCancelRename:()=>Ie(null),work:Yo(ve),pin:Xo(ve),descendantIdsOf:Ms}),vn&&Fr?gt.map(ps=>$r(ps,Xe+Rf)):null]},ve.id)};return t.jsxs("div",{children:[fa.map(ve=>ve.kind==="run"?t.jsx(Af,{run:ve.run,laneNodes:Wt.get(ve.run.key)??wi,indent:$},`run:${ve.run.key}`):$r(ve.session,$)),Lr>0?t.jsx(Pf,{indent:$,onClick:()=>Ho(d,yn.length,re)}):null,ma?t.jsx(Tf,{indent:$,onClick:()=>xr(d)}):null]})},Bs=(d,O)=>{ae(d,!O),qo(d)},Jo=(d,O,$)=>{te(`${d}::${O}`,!$),xr(`${d}::${O}`)},pn=d=>{const O=mt(d)||null,$=Ue.bySessionId.get(d.id),K=$?je.find(re=>re.id===$.projectId)??null:null;if(K){M(K.id),ae(K.id,!0);const re=En(K,$?.scopeDirectory??"");re&&te(`${K.id}::${ze(re.path)}`,!0)}N(d.id,O),e(!1)},yr=(d,O)=>{ye(O?d:null),U(null),Ne(null),Re(null)},At=(d,O)=>{Ne(O?d:null),Re(null),ye(null),U(null)},vr=(d,O)=>(ye(null),U(null),kc(d,O,Sc(O.id,Us(dt,O.id),d==="delete"),{archiveSession:A,archiveSessions:x,deleteSession:R,deleteSessions:S},r)),wr=d=>vr("archive",d),jr=async(d,O)=>{try{await nl(d.id,mt(d)||null,O?"done":"open")}catch{we.error(r("sessions.sidebar.session.work.updateFailed"))}},Yo=d=>{if(!$t||ut(d)||jn(mt(d)))return;const O=qe.has(d.id);return{inWork:O,onToggle:()=>{jr(d,O)}}},kr=d=>Xr(p,mt(d)||null,d.id),Sr=d=>{const O=mt(d);O&&q({directory:O,sessionId:d.id})},Xo=d=>{if(!(ut(d)||!mt(d)))return{pinned:kr(d),onToggle:()=>Sr(d)}},Nr=d=>vr("delete",d),Cr=d=>{ye(null),U(null),Ie(d)},Rr=async(d,O)=>{Ie(null);try{await C(d,O)}catch{we.error(r("mobile.sessions.renameError"))}},Er=()=>{w(),e(!1)},Ir=d=>{yt(d),M(d),bt(!0)},Qo=Qn(as(er,{activationConstraint:{distance:8}}),as(Zn,{coordinateGetter:nr})),Zo=d=>{V(d),wn({sidebarProjectSortOrder:d}),d!=="manual"&&at(!1)},ea=d=>{D(d),wn({sidebarViewMode:d}),d==="timeline"&&at(!1)},ta=()=>{const d=!F;L(d),wn({sidebarShowRecentSection:d})},sa=d=>{const{active:O,over:$}=d;if(!$||O.id===$.id)return;const K=je.findIndex(me=>me.id===O.id),re=je.findIndex(me=>me.id===$.id);K<0||re<0||z(K,re)},na=d=>{fs(O=>{const $=new Set(O);return $.has(d)?$.delete(d):$.add(d),$})},Ar=f.useCallback(d=>{const O=mt(d);if(jn(O))return r("mobile.sessions.section.chats");const $=Ue.bySessionId.get(d.id),K=$?je.find(ce=>ce.id===$.projectId)??null:null;if(!K)return Cn(O)||O;const re=$?.kind==="space"&&$.spaceId?Et.get($.spaceId):void 0;if(re)return`${K.label} · ${re.name||r("sessions.sidebar.grouping.spaceUnnamed")}`;const me=En(K,$?.scopeDirectory??"");return me?.branch?`${K.label} · ${me.branch}`:K.label},[je,Ue,Et,r]),ra=d=>{T(d.id),e(!1)},Pr=d=>{M(d.id),w({selectedProjectId:d.id,directoryOverride:d.path}),e(!1)},ia=f.useMemo(()=>be?qt.filter(d=>to([d.project.label,d.project.path],be)?!0:d.buckets.some(O=>O.sessions.some($=>In($,d.project.label,be)))):qt,[be,qt]),Ls=f.useMemo(()=>be?Jt(Be.filter(d=>{if(ut(d))return!1;const O=Ue.bySessionId.get(d.id),$=O?je.find(K=>K.id===O.projectId)??null:null;return In(d,$?.label??"",be)}),p,h):[],[be,p,je,h,Ue,Be]),$s=f.useMemo(()=>be?el(je,be,d=>[d.label,d.path]):[],[be,je]),ft=I==="timeline"&&!be&&!Ve,Tr=ft||X;f.useEffect(()=>{if(!(!Tr||!o))for(const d of je){const O=ze(d.path);O&&tl(()=>c(O,o))}},[c,o,Tr,je]);const hn=f.useMemo(()=>{const d=new Map;if(!ft)return d;const O=Zr({sessions:Te,projects:je.map($=>({id:$.id,normalizedPath:$.path,label:$.label})),ownerBySessionId:Ue.bySessionId,availableWorktreesByProject:new Map(je.map($=>[$.path,$.worktrees])),gitBranches:Y,homeDirectory:null,hideBranchMatchingProjectLabel:!1,spaceLabelById:ht});for(const $ of Te){if(ut($))continue;const K=O.get($.id),re=K?je.find(me=>me.id===K.projectId):null;!re||!K||d.set($.id,{project:re,branch:K.branchLabel})}return d},[Y,Te,je,Ue,ht,ft]),gn=f.useMemo(()=>{if(!ft)return[];const d=vt.filter($=>!ut($)&&hn.has($.id)),O=new Set;return Jt(d,p,h).flatMap($=>{const K=hn.get($.id);if(!K)return[];const re=nt.runKeyBySessionId.get($.id),me=re?nt.runs.get(re):void 0;return me?O.has(me.key)?[]:(O.add(me.key),[{kind:"run",run:me,laneNodes:Wt.get(me.key)??wi,project:K.project}]):[{kind:"session",session:$,project:K.project,branch:K.branch}]})},[p,nt,Wt,vt,h,ft,hn]),oa=f.useCallback(()=>{Ke(d=>uf(d,gn.length))},[gn.length]),aa={currentSessionId:v,revealedSessionId:xe,confirmingDeleteSessionId:ke,renamingSessionId:he,onSelect:pn,onRevealedChange:yr,onArchive:d=>{wr(d)},onRequestDelete:U,onConfirmDelete:d=>{Nr(d)},onRequestRename:Cr,onSubmitRename:(d,O)=>{Rr(d,O)},onCancelRename:()=>Ie(null),onToggleWork:$t?(d,O)=>{jr(d,O)}:void 0,isPinned:kr,onTogglePin:Sr,descendantIdsOf:Ms},la=be&&Ls.length===0&&$s.length===0,ca=!be&&!ft&&je.length>1&&P==="manual",Dr=!Ve&&!be&&je.length>0?t.jsx(Se,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.displayMode.label"),title:r("sessions.sidebar.header.displayMode.label"),onClick:()=>et(!0),style:{touchAction:"manipulation"},children:t.jsx(J,{name:"equalizer-2",className:"size-4"})}):null,_r=ca?t.jsx(Se,{type:"button",variant:"chip",size:"sm","aria-label":r(Ve?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":Ve,onClick:()=>at(d=>!d),style:{touchAction:"manipulation"},children:Ve?t.jsx(co,{className:"size-4"}):t.jsx(_n,{className:"size-4"})}):null,Mr=!Ve&&je.length>0?t.jsxs(Se,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:Er,style:{touchAction:"manipulation"},children:[t.jsx(lu,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,zr=Ve?null:t.jsx(Se,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>Je(!0),style:{touchAction:"manipulation"},children:t.jsx(ei,{className:"size-4"})}),Fs=Mr||zr||Dr||_r?t.jsxs(t.Fragment,{children:[zr,Dr,_r,Mr]}):null,Or=t.jsxs("div",{ref:ct,className:"flex min-h-0 flex-1 flex-col",children:[t.jsxs(rn,{ref:lt,className:"min-h-0 flex-1 overflow-y-auto pb-4",children:[t.jsx("div",{className:Q("px-4 pb-2 pt-1",Ve&&"hidden"),children:t.jsx(yc,{value:ie,onSearch:H,active:n||s==="sidebar",mobile:!0,placeholder:r("mobile.sessions.search.placeholder"),clearLabel:r("mobile.sessions.clearSearchAria")})}),je.length===0&&Lt.length===0?t.jsx(Ni,{title:r("mobile.sessions.empty.noProjectsTitle"),description:r("mobile.sessions.empty.noProjectsDescription"),action:t.jsxs("button",{type:"button",className:"flex items-center justify-center gap-2 rounded-2xl bg-primary px-5 py-3 typography-ui-label text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>Je(!0),children:[t.jsx(ei,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):la?t.jsx(Ni,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):be&&!Ve?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[Ls.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.sessions")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Ls.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Ls.map((d,O)=>t.jsx("div",{className:Q(O>0&&"border-t border-border/70"),children:t.jsx(vi,{session:d,active:v===d.id,indent:12,contextLabel:Ar(d),onSelect:()=>pn(d)})},d.id))})]}):null,$s.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.projects")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:$s.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:$s.map((d,O)=>t.jsxs("div",{className:Q("flex items-center",O>0&&"border-t border-border/70"),children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-3 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>ra(d),style:{touchAction:"manipulation"},children:[t.jsx(Is,{project:d}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:d.label})]}),d.isGitRepo?t.jsx(yi,{onClick:()=>Ir(d.id)}):null,t.jsx(An,{className:"mr-2",label:r("mobile.sessions.newSessionInProjectAria",{label:d.label}),onClick:()=>Pr(d)})]},d.id))})]}):null]}):Ve?t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2",children:[t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:r("mobile.sessions.editOrderHint")}),t.jsx(tr,{sensors:Qo,collisionDetection:sr,onDragEnd:sa,children:t.jsx(rr,{items:je.map(d=>d.id),strategy:ir,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:je.map(d=>{const O=qt.find($=>$.project.id===d.id);return t.jsx(_f,{project:d,totalSessions:O?.totalSessions??0,expanded:un.has(d.id),onToggleExpanded:()=>na(d.id),onReorderWorktrees:$=>B(d.id,$)},d.id)})})})})]}):t.jsxs("div",{className:"flex flex-col",children:[(()=>{const d=Z[hs]??!0,O=r("mobile.sessions.section.chats");return t.jsxs("section",{children:[t.jsxs("div",{className:"flex min-h-12 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(pe){At(pe,!1);return}Bs(hs,d)},"aria-expanded":d,"aria-label":d?r("sessions.sidebar.group.collapseAria",{label:O}):r("sessions.sidebar.group.expandAria",{label:O}),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:t.jsx(J,{name:"chat-4",className:"size-4"})}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:O}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:se})]}),Ve?null:t.jsx(An,{className:"mr-2",label:r("mobile.sessions.newChat"),onClick:Er})]}),d?t.jsx("div",{className:"pb-2",children:Vt.sessions.length>0?ms(G,Vt,ft?Cf:Yt,ft?{pageSize:Nf,alwaysVisibleIds:fn,statusOnRight:!0}:void 0):t.jsx("p",{className:"px-3 pb-1 typography-micro text-muted-foreground",style:{paddingLeft:Yt},children:r("sessions.sidebar.activity.chatsEmpty")})}):null]})})(),Ut.sessions.length>0?(()=>{const d=Z[xs]??!0,O=r("sessions.sidebar.work.title");return t.jsxs("section",{children:[t.jsxs("button",{type:"button",className:"flex min-h-12 w-full min-w-0 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(pe){At(pe,!1);return}Bs(xs,d)},"aria-expanded":d,"aria-label":d?r("sessions.sidebar.group.collapseAria",{label:O}):r("sessions.sidebar.group.expandAria",{label:O}),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:t.jsx(J,{name:"eye",className:"size-4"})}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:O}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:Ut.sessions.filter($=>!ut($)).length})]}),d?t.jsx("div",{className:"pb-2",children:ms(`${xs}::${xs}`,Ut,Yt,{pageSize:Number.MAX_SAFE_INTEGER})}):null]})})():null,!ft&&Os.sessions.length>0?(()=>{const d=Z[ys]??!0,O=r("mobile.sessions.section.recent");return t.jsxs("section",{children:[t.jsxs("button",{type:"button",className:"flex min-h-12 w-full min-w-0 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(pe){At(pe,!1);return}Bs(ys,d)},"aria-expanded":d,"aria-label":d?r("sessions.sidebar.group.collapseAria",{label:O}):r("sessions.sidebar.group.expandAria",{label:O}),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:t.jsx(J,{name:"history",className:"size-4"})}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:O}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:wt.length})]}),d?t.jsx("div",{className:"pb-2",children:ms(`${ys}::${ys}`,Os,Yt,{rootContextLabel:$=>_.get($.id)??Ar($)})}):null]})})():null,ft?t.jsx(lf,{entries:gn,visibleCount:Rt,onRevealMore:oa,scrollRootRef:lt,handlers:aa}):null,ft?null:ia.map(d=>{const O=Go(d),$=be?d.buckets.filter(re=>re.sessions.some(me=>In(me,d.project.label,be))):d.buckets,K=mn(d);return t.jsxs("section",{className:"border-t border-border/70",children:[t.jsx(nn,{actionsWidth:96,revealed:pe===`project:${d.project.id}`,onRevealedChange:re=>At(`project:${d.project.id}`,re),actions:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",tabIndex:pe===`project:${d.project.id}`?0:-1,className:Q("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",De===d.project.id?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":De===d.project.id?r("mobile.sessions.confirmRemoveProjectAria",{label:d.project.label}):r("mobile.sessions.removeProjectAria",{label:d.project.label}),onClick:()=>{if(De===d.project.id){Ne(null),Re(null),W(d.project.id),we.success(r("mobile.sessions.toast.projectRemoved",{label:d.project.label}));return}Re(d.project.id)},style:{touchAction:"manipulation"},children:t.jsx(Xs,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:pe===`project:${d.project.id}`?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":r("mobile.sessions.editProjectAria",{label:d.project.label}),onClick:()=>{Ne(null),ue(d.project.id)},style:{touchAction:"manipulation"},children:t.jsx(_n,{className:"size-[18px]"})})]}),children:t.jsxs("div",{"data-active-project":d.isActive||void 0,className:"flex min-h-12 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(pe){At(pe,!1);return}Bs(d.project.id,O)},"aria-expanded":O,"aria-label":O?r("sessions.sidebar.group.collapseAria",{label:d.project.label}):r("sessions.sidebar.group.expandAria",{label:d.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(Is,{project:d.project}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:d.project.label})]}),d.project.isGitRepo?t.jsx(yi,{onClick:()=>Ir(d.project.id)}):null,t.jsx(An,{className:"mr-2",label:r("mobile.sessions.newSessionInProjectAria",{label:d.project.label}),onClick:()=>Pr(d.project)})]})}),O?t.jsx("div",{className:"pb-2",children:(()=>{const re=$.find(ce=>ce.worktree===null&&ce.space===null),me=$.filter(ce=>ce!==re);return t.jsxs(t.Fragment,{children:[re&&re.sessions.length>0?ms(`${d.project.id}::${re.key}`,re,Yt):null,me.map(ce=>{const Fe=Ko(d,ce),Ye=K===ce.path;return t.jsxs("div",{children:[t.jsx(nn,{actionsWidth:ce.space?96:48,revealed:pe===`wt:${ce.key}`,onRevealedChange:St=>At(`wt:${ce.key}`,St),actions:ce.space?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",tabIndex:pe===`wt:${ce.key}`?0:-1,className:"flex flex-1 items-center justify-center text-foreground transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":r("spaces.group.access.giveAria",{label:ce.label}),onClick:()=>{Ne(null),ce.space&&Vr.getState().openAccessDialog(ce.space.id)},style:{touchAction:"manipulation"},children:t.jsx(J,{name:"key",className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:pe===`wt:${ce.key}`?0:-1,className:"flex flex-1 items-center justify-center text-foreground transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":r("spaces.actions.menuAria",{label:ce.label}),onClick:()=>{Ne(null),ce.space&&Vr.getState().openActionsSheet(ce.space.id)},style:{touchAction:"manipulation"},children:t.jsx(J,{name:"more-2",className:"size-[18px]"})})]}):ce.worktree?t.jsx("button",{type:"button",tabIndex:pe===`wt:${ce.key}`?0:-1,className:"flex flex-1 items-center justify-center text-[var(--status-error)] transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive","aria-label":r("mobile.projectEdit.deleteWorktreeAria",{label:ce.label}),onClick:()=>{Ne(null),ce.worktree&&Ee({project:d.project,worktree:ce.worktree})},style:{touchAction:"manipulation"},children:t.jsx(Xs,{className:"size-[18px]"})}):null,children:t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 px-3 py-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(pe){At(pe,!1);return}Jo(d.project.id,ce.key,Fe)},"aria-expanded":Fe,"aria-label":Fe?r("sessions.sidebar.group.collapseAria",{label:ce.label}):r("sessions.sidebar.group.expandAria",{label:ce.label}),style:{touchAction:"manipulation"},children:[t.jsx(J,{name:ce.space?"box-3":"git-branch",className:Q("size-4 shrink-0",Ye?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Q("block min-w-0 flex-1 truncate typography-ui-label font-bold",Ye?"text-foreground":"text-muted-foreground"),children:ce.label}),Ye?t.jsx(If,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:ce.sessions.length})]})}),ce.space?t.jsx(vc,{spaceId:ce.space.id,className:"px-3 pb-1 pl-9"}):null,Fe?ms(`${d.project.id}::${ce.key}`,ce,Yt):null]},ce.key)})]})})()}):null]},d.project.id)})]})]}),i?t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/70 px-2 pt-1.5",style:{paddingBottom:"calc(0.375rem + var(--oc-safe-area-bottom, 0px))"},children:[i.instanceLabel&&i.onOpenInstances?t.jsxs(Se,{type:"button",variant:"info",size:"lg",className:"min-w-0 shrink justify-start",onClick:i.onOpenInstances,"aria-label":r("mobile.menu.instances"),style:{touchAction:"manipulation"},children:[t.jsx(J,{name:"server",className:"size-[18px]"}),t.jsx("span",{className:"block min-w-0 truncate",children:i.instanceLabel})]}):t.jsx("div",{className:"min-w-0 flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[i.onOpenUpdate?t.jsxs(Se,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:i.onOpenUpdate,"aria-label":r("mobile.menu.update"),title:r("mobile.menu.update"),style:{touchAction:"manipulation"},children:[t.jsx(J,{name:"download",className:"size-5"}),t.jsx("span",{className:"absolute right-2 top-2 inline-flex size-2 rounded-full bg-primary","aria-hidden":!0})]}):null,t.jsx(Se,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:i.onOpenScheduled,"aria-label":r("sessions.sidebar.header.actions.scheduledTasks"),title:r("sessions.sidebar.header.actions.scheduledTasks"),style:{touchAction:"manipulation"},children:t.jsx(J,{name:"calendar-schedule",className:"size-5"})}),t.jsx(Se,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:i.onOpenUsage,"aria-label":r("usageStats.openAction"),title:r("usageStats.openAction"),style:{touchAction:"manipulation"},children:t.jsx(J,{name:"bar-chart",className:"size-5"})}),t.jsx(Se,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:i.onOpenSettings,"aria-label":r("mobile.menu.settings"),title:r("mobile.menu.settings"),style:{touchAction:"manipulation"},children:t.jsx(J,{name:"settings-3",className:"size-5"})})]})]}):null,t.jsx(wc,{open:cn,onOpenChange:Je}),t.jsx(jc,{open:tt,onOpenChange:d=>{bt(d),d||yt(null)},onWorktreeCreated:(d,O)=>{O?.sessionId?N(O.sessionId,d):w({selectedProjectId:xt,directoryOverride:d,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(hf,{open:oe!==null,project:je.find(d=>d.id===oe)??null,onClose:()=>ue(null),onWorktreesChanged:()=>$e(d=>d+1)}),t.jsx(Ki,{open:He,onClose:()=>et(!1),title:r("sessions.sidebar.header.displayMode.label"),children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"px-3 pb-1 pt-1 typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.viewMode.label")}),kf.map(([d,O])=>t.jsxs("button",{type:"button",className:Q("flex min-h-11 w-full items-center justify-between rounded-lg px-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",I===d?"text-primary":"text-foreground"),onClick:()=>{ea(d),et(!1)},style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label",children:r(O)}),I===d?t.jsx(J,{name:"check",className:"size-4"}):null]},d)),I==="timeline"?null:t.jsx("span",{className:"px-3 pb-1 pt-3 typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("sessions.sidebar.header.actions.sortProjects")}),I==="timeline"?null:jf.map(([d,O])=>t.jsxs("button",{type:"button",className:Q("flex min-h-11 w-full items-center justify-between rounded-lg px-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",P===d?"text-primary":"text-foreground"),onClick:()=>{Zo(d),et(!1)},style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label",children:r(O)}),P===d?t.jsx(J,{name:"check",className:"size-4"}):null]},d)),I==="timeline"?null:t.jsxs("button",{type:"button","aria-pressed":F,className:Q("mt-2 flex min-h-11 w-full items-center justify-between rounded-lg px-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",F?"text-primary":"text-foreground"),onClick:()=>{ta(),et(!1)},style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label",children:r("sessions.sidebar.header.displayMode.showRecent")}),F?t.jsx(J,{name:"check",className:"size-4"}):null]})]})}),Ae?t.jsx(Do,{open:!0,project:{id:Ae.project.id,path:Ae.project.path},worktree:Ae.worktree,onClose:()=>Ee(null),onDeleted:()=>$e(d=>d+1)}):null]});return s==="sidebar"?n?t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center justify-between gap-2 border-b border-border/70 px-4",children:[t.jsx("h2",{className:"truncate typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Fs?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Fs}):null]}),Or]}):null:t.jsxs(Of,{open:n,onClose:()=>e(!1),onSwipeClose:()=>{if(xe||pe){ye(null),Ne(null),U(null),Re(null);return}e(!1)},ariaLabel:r("mobile.sessions.sheet.title"),children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":r("mobile.surface.closeAria"),onClick:()=>e(!1),style:{touchAction:"manipulation"},children:t.jsx(J,{name:"close",className:"size-5"})}),t.jsx("h2",{className:"min-w-0 flex-1 truncate px-1 typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Fs?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Fs}):null]}),Or]})},ki="mobile-surface-root",Mf=16,Si=320,zf="cubic-bezier(0.22, 1, 0.36, 1)",Of=({open:n,onClose:e,onSwipeClose:s,ariaLabel:i,children:r})=>{const o=f.useRef(null),c=f.useRef(null),[l,m]=f.useState(!1),[a,u]=f.useState(n),p=f.useRef(e);f.useEffect(()=>{p.current=e},[e]);const g=f.useRef(s);if(f.useEffect(()=>{g.current=s},[s]),gr(c,{enabled:n,onRightEdgeSwipe:()=>(g.current??p.current)()}),typeof document<"u"&&!o.current){let h=document.getElementById(ki);h||(h=document.createElement("div"),h.id=ki,document.body.appendChild(h)),o.current=h}return f.useEffect(()=>{if(n){u(!0);const b=window.setTimeout(()=>m(!0),Mf);return()=>window.clearTimeout(b)}m(!1);const h=window.setTimeout(()=>u(!1),Si+40);return()=>window.clearTimeout(h)},[n]),f.useEffect(()=>{if(!n)return;const h=document.body.style.overflow;document.body.style.overflow="hidden";const b=k=>{k.key==="Escape"&&p.current()};return document.addEventListener("keydown",b),()=>{document.body.style.overflow=h,document.removeEventListener("keydown",b)}},[n]),o.current?is.createPortal(t.jsx("section",{ref:c,role:"dialog","aria-modal":"true","aria-label":i,"aria-hidden":!n,className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:l?"none":"translateX(-100%)",transition:`transform ${Si}ms ${zf}`,visibility:a?"visible":"hidden",pointerEvents:n?"auto":"none"},children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r})}),o.current):null},Ni=n=>{const e=de.c(10),{title:s,description:i,action:r}=n;let o;e[0]!==s?(o=t.jsx("p",{className:"typography-ui-label text-foreground",children:s}),e[0]=s,e[1]=o):o=e[1];let c;e[2]!==i?(c=i?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i}):null,e[2]=i,e[3]=c):c=e[3];let l;e[4]!==r?(l=r?t.jsx("div",{className:"pt-2",children:r}):null,e[4]=r,e[5]=l):l=e[5];let m;return e[6]!==o||e[7]!==c||e[8]!==l?(m=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[o,c,l]}),e[6]=o,e[7]=c,e[8]=l,e[9]=m):m=e[9],m};function Bf(n){return ze(n.path)}function Lf(n){return ze(n.path)}function $f(n){return t.jsx(Df,{worktree:n},ze(n.path))}const Ff=(n,e)=>{if(!n)return e("mcpDropdown.status.unknown");const s=n.status;switch(s.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:s.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");default:return s.status}},Wf=n=>{switch(n?.status.status){case"connected":return"success";case"failed":return"error";case"needs_auth":return"warning";default:return"default"}},Vf=({active:n,className:e,headerAction:s,listClassName:i,hideHeader:r=!1,mobileListDensity:o=!1})=>{const{t:c}=ge(),m=Nt(x=>x.currentDirectory)??null,a=vs(x=>x.getStatusForDirectory(m)),u=vs(x=>x.refresh),p=vs(x=>x.connect),g=vs(x=>x.disconnect),h=ns(x=>x.mcpServers),b=ns(x=>x.loadMcpConfigs),[k,y]=f.useState(!1),[E,v]=f.useState(null);f.useEffect(()=>{u({directory:m,silent:!0})},[u,m]),f.useEffect(()=>{b({force:!0})},[b]),f.useEffect(()=>{n&&Promise.all([u({directory:m,silent:!0}),b({force:!0})])},[n,u,m,b]);const N=f.useMemo(()=>{const x=new Set(Object.keys(a));for(const R of h)R?.name&&x.add(R.name);return Array.from(x).sort((R,S)=>R.localeCompare(S))},[h,a]),A=f.useCallback(x=>{if(x?.preventDefault(),k)return;y(!0);const R=new Promise(S=>setTimeout(S,500));Promise.all([u({directory:m}),R]).finally(()=>{y(!1)})},[k,u,m]);return t.jsxs("div",{className:Q("w-full",e),children:[r?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("mcpDropdown.title")}),m&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:m.split("/").pop()||m})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",disabled:k,onClick:A,"aria-label":c("mcpDropdown.actions.refreshAria"),children:t.jsx(J,{name:"refresh",className:Q("h-4 w-4",k&&"animate-spin")})})]})]})}),t.jsx("div",{className:Q("max-h-64 overflow-y-auto",o?"space-y-1 py-3":"px-3 py-2.5",i),children:t.jsxs("div",{className:Q(!o&&N.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[N.map(x=>{const R=a[x],S=Wf(R),C=R?.status.status==="connected",w=E===x,T=Ff(R,c);return t.jsxs("div",{className:Q("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",o?"gap-3 px-4 py-3":"gap-2 px-2.5 py-2"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(rl,{children:[t.jsx(il,{asChild:!0,children:t.jsx("span",{className:Q("rounded-full flex-shrink-0",o?"h-2.5 w-2.5":"h-2 w-2",S==="success"&&"bg-status-success",S==="error"&&"bg-status-error",S==="warning"&&"bg-status-warning",S==="default"&&"bg-muted-foreground/40"),"aria-label":T})}),t.jsx(ol,{side:"left",children:t.jsx("p",{children:T})})]}),t.jsx("span",{className:Q("truncate",o?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:x})]})}),t.jsx(al,{checked:C,disabled:w,className:"data-[checked]:bg-status-info",onCheckedChange:async M=>{v(x);try{M?await p(x,m):await g(x,m)}catch(z){Mn.error(z instanceof Error?z.message:c("mcpDropdown.status.unknownError"))}finally{v(null)}}})]},x)}),N.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:c("mcpDropdown.empty.configureInConfig")})]})})]})},Ci={status:"loading"},Xt={type:"list"},Uf=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),Gf=n=>{const e=n.index?.trim();return!!(e&&e!=="?")},Kf=n=>{const e=n.working_dir?.trim(),s=n.index?.trim();return!!(e||s==="?")},Ri=(n,e)=>e?`${n}\0staged`:n,qf=n=>{const e=de.c(8),s=qn()??null;let i;e[0]!==s?(i=Uf(s),e[0]=s,e[1]=i):i=e[1];const r=i,o=n.visible??!0;let c;e[2]!==o?(c={enabled:o},e[2]=o,e[3]=c):c=e[3];const l=ll(r||null,c);let m;return e[4]!==n||e[5]!==l||e[6]!==r?(m=t.jsx(Hf,{...n,rootDirectory:r,repository:l}),e[4]=n,e[5]=l,e[6]=r,e[7]=m):m=e[7],m},Hf=({rootDirectory:n,repository:e,onClose:s,initialDiff:i,visible:r=!0})=>{const{t:o}=ge(),{git:c}=Kn(),{rootIsGitRepo:l,gitDirectory:m,nestedRepos:a}=e,u=m??n,p=cl(u||null),g=ul(u||null),h=Ui(u||null),b=dl(u||null),k=Qe(_=>_.setActiveDirectory),y=Qe(_=>_.ensureAll),E=Qe(_=>_.ensureNestedRepos),v=Qe(_=>_.selectNestedRepo),N=Qe(_=>_.fetchStatus),A=Qe(_=>_.fetchBranches),x=Qe(_=>_.prefetchDiffs),R=Qe(_=>_.getDiff),S=Qe(_=>_.setDiff),C=Qe(_=>_.runtimeKey),w=JSON.stringify([C,u]),T=f.useRef(w);T.current=w;const[M,z]=f.useState(()=>({ownerKey:w,mode:"working",route:i?.path?{type:"diff",path:i.path,staged:i.staged}:Xt})),j=M.ownerKey===w?M.mode:"working",P=M.ownerKey===w?M.route:Xt,[V,I]=f.useState(!1),D=f.useCallback(_=>{z({ownerKey:w,mode:_,route:Xt}),I(!1)},[w]),F=f.useCallback(_=>{z(G=>({ownerKey:w,mode:G.ownerKey===w?G.mode:"working",route:_}))},[w]);f.useEffect(()=>{z(_=>_.ownerKey===w?_:{ownerKey:w,mode:"working",route:Xt}),I(!1)},[w]),f.useEffect(()=>{r||I(!1)},[r]),f.useEffect(()=>{i?.path&&z({ownerKey:T.current,mode:"working",route:{type:"diff",path:i.path,staged:i.staged}})},[i]);const[L,q]=f.useState(null),[X,Y]=f.useState(null),[W,Z]=f.useState(""),[fe,ae]=f.useState(new Set),[te,le]=f.useState(!1),[B,ee]=f.useState(!1),[ne,ie]=f.useState([]),[H,oe]=f.useState([]),[ue,xe]=f.useState([]),[ye,ke]=f.useState(null),[U,he]=f.useState(null),[Ie,pe]=f.useState(null),[Ne,De]=f.useState(0),[Re,Ae]=f.useState(null),Ee=p?.current??null,Me=p?.tracking?.trim().split("/")[0],$e=(Me&&g?.defaultBranches?.[Me])??g?.defaultBranches?.origin??null,He=Tu(Ee,$e),et=h===!1||Au(Ee,$e,p!==null,g!==null),cn=vu(_=>_.setOverride),Je=wu(u||null,Ee,r&&j==="branch"&&He),tt=ju(u||null,Ee,r&&j==="commit"&&h===!0),bt=tt.selectedCommit?.hash??null,xt=ku(u||null,Ee,r&&j==="pr"&&h===!0),yt=xt.selectedSource,Ts=f.useMemo(()=>j==="pr"?yt:j==="branch"&&Ee&&Je.base?{kind:"branch",baseRef:Je.base,headRef:Ee}:j==="commit"&&bt?{kind:"commit",hash:bt}:null,[Je.base,Ee,j,bt,yt]),Ds=j==="branch"?Je.revision:"",Pe=Eu(u||null,Ts,r&&h===!0,Ds),{fetchDiff:_s}=Pe,Ve=f.useMemo(()=>Pe.files?[...Pe.files].sort((_,G)=>_.path.localeCompare(G.path)):null,[Pe.files]),at=P.type==="comparison"&&P.sourceKey===Pe.key?P.path:null,[un,fs]=f.useState(0),dn=f.useCallback(async _=>{try{const{diff:G}=await _s(_),se={original:"",modified:"",isBinary:Su(G)};return se.isBinary||(se.fileDiff=Nu(_,G)),{status:"ready",diff:se}}catch(G){return{status:"error",message:G instanceof Error?G.message:o("diffView.state.failedToLoadDiff")}}},[_s,o]),Bt=Iu(Pe.files?j==="pr"?JSON.stringify([Pe.key,Pe.revision]):Pe.key:null,r&&at?at:"",r?dn:null,Ci,JSON.stringify([Ds,j==="pr"?Pe.revision:0,un])),Rt=at?Bt.get(at)??Ci:null;f.useEffect(()=>{j==="branch"&&et&&D("working")},[et,D,j]),f.useEffect(()=>{z(_=>_.ownerKey===w&&_.route.type==="comparison"&&_.route.sourceKey!==Pe.key?{..._,route:Xt}:_)},[Pe.key,w]);const Ke=f.useMemo(()=>{const _=p?.files??[],G=new Map;for(const se of _)G.set(se.path,se);return Array.from(G.values()).sort((se,be)=>se.path.localeCompare(be.path))},[p?.files]),lt=f.useMemo(()=>Ke.filter(Gf),[Ke]),je=f.useMemo(()=>Ke.filter(Kf),[Ke]),Be=f.useMemo(()=>{if(ue.length>0)return ue;const _=p?.tracking?.includes("/")?p.tracking.split("/")[0]:null;return _||ye?[{name:_||"origin",fetchUrl:ye??"",pushUrl:ye??""}]:[]},[ye,ue,p?.tracking]),dt=Qe(f.useCallback(_=>!u||P.type!=="diff"?null:_.directories.get(u)?.diffCache.get(Ri(P.path,P.staged))??null,[u,P])),Ms=f.useMemo(()=>P.type!=="diff"?null:Ke.find(_=>_.path===P.path)??null,[Ke,P]),Te=f.useCallback(async(_=!0)=>{if(u)try{await Promise.all([N(u,c),A(u,c)])}catch(G){_&&we.error(G instanceof Error?G.message:o("gitView.toast.refreshRepositoryFailed"))}},[u,A,N,c,o]),Lt=f.useMemo(()=>(g?.all??[]).filter(_=>!_.startsWith("remotes/")).sort(),[g]),$t=f.useMemo(()=>(g?.all??[]).filter(_=>_.startsWith("remotes/")).map(_=>_.replace(/^remotes\//,"")).sort(),[g]),qe=f.useCallback(async _=>{if(!u)return;const G=_.replace(/^remotes\//,"");try{const se=await c.checkoutBranch(u,G);we.success(o("gitView.toast.checkedOut",{name:se.branch||G})),await Te()}catch(se){we.error(se instanceof Error?se.message:o("gitView.toast.checkoutFailed",{name:G}))}},[u,c,Te,o]),vt=f.useCallback(_=>{const G=_.replace(/^remotes\//,"");if((p?.files?.length??0)>0){Ae(G);return}qe(G)},[qe,p?.files]),Ft=f.useCallback(async(_,G)=>{if(u)try{await c.createBranch(u,_,Ee??"HEAD"),await c.checkoutBranch(u,_),G&&await c.gitPush(u,{remote:G.name,branch:_,options:["--set-upstream"]}),await Te()}catch(se){throw we.error(se instanceof Error?se.message:o("gitView.toast.createBranchFailed")),se}},[Ee,u,c,Te,o]),st=f.useCallback(async()=>{if(!u){xe([]),ke(null);return}try{const[_,G]=await Promise.all([c.getRemotes(u).catch(()=>[]),c.getRemoteUrl?c.getRemoteUrl(u).catch(()=>null):Promise.resolve(null)]);xe(_),ke(G)}catch{xe([]),ke(null)}},[u,c]);f.useEffect(()=>{!u||!r||(k(u),y(u,c))},[u,y,c,k,r]),f.useEffect(()=>{r&&st()},[st,r]),f.useEffect(()=>{if(!r||j!=="working"||!u||Ke.length===0)return;const _=Array.from(new Set([...lt.map(se=>se.path),...H,...Ke.slice(0,20).map(se=>se.path)])).filter(Boolean);if(_.length===0)return;const G=window.setTimeout(()=>{x(u,c,_,{maxFiles:40})},120);return()=>window.clearTimeout(G)},[Ke,u,c,j,x,lt,H,r]),f.useEffect(()=>{if(!r)return;if(P.type!=="diff"){he(null);return}const _=Ri(P.path,P.staged);if(pe(null),!u||R(u,_)){he(null);return}let G=!1;const se=Ps();return he(null),c.getGitFileDiff(u,{path:P.path,staged:P.staged||void 0}).then(be=>{G||S(u,_,{original:be.original??"",modified:be.modified??"",isBinary:be.isBinary,submodule:be.submodule},se)}).catch(be=>{if(!G){if(be instanceof Ur&&be.reason!=="path_not_found"){pe({key:`${u}\0${P.path}`,reason:be.reason});return}be instanceof Ur&&N(u,c,{force:!0,silent:!0}),he(be instanceof Error?be.message:String(be))}}),()=>{G=!0}},[u,Ne,N,R,c,P,S,r]);const Et=async(_,G)=>{if(u){q(_);try{if(_==="fetch"){if(!G)throw new Error(o("mobile.changes.noRemote"));await c.gitFetch(u,{remote:G.name}),we.success(o("gitView.toast.fetchedFromRemote",{name:G.name}))}else if(_==="sync"){if(!G)throw new Error(o("mobile.changes.noRemote"));let se=0;const be=await si({git:c,directory:u,remote:G,dirtyWorktreeError:o("gitView.toast.commitOrStashBeforeSync"),onPulled:ct=>{se=ct.files.length}});se>0&&we.success(se===1?o("gitView.toast.pulledFilesSingle",{count:se,name:G.name}):o("gitView.toast.pulledFilesPlural",{count:se,name:G.name})),be.pushed.length>0?we.success(o("gitView.toast.pushedToUpstream",{name:be.pushed[0].remote})):se===0&&we.success(o("gitView.toast.alreadyUpToDate"))}await Te(!1),await st()}catch(se){we.error(se instanceof Error?se.message:o("gitView.toast.syncActionFailed",{action:o("gitView.sync.syncChanges")}))}finally{q(null)}}},ht=f.useCallback(async(_,G)=>{if(!(!u||_.length===0))try{G==="stage"?_.length>1?await fl(u,_):await ml(u,_[0]):_.length>1?await pl(u,_):await hl(u,_[0]),await Te(!1)}catch(se){we.error(se instanceof Error?se.message:o(G==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[u,Te,o]),Ue=f.useCallback((_,G=!1)=>{F({type:"diff",path:_,staged:G})},[F]),nt=f.useCallback(async _=>{if(u){ae(G=>new Set(G).add(_));try{await c.revertGitFile(u,_),we.success(o("gitView.toast.revertedFile",{path:_})),await Te(!1)}catch(G){we.error(G instanceof Error?G.message:o("gitView.toast.revertFailed"))}finally{ae(G=>{const se=new Set(G);return se.delete(_),se})}}},[u,c,Te,o]),Wt=f.useCallback(async _=>{if(!u||_.length===0||te)return;const G=Array.from(new Set(_));le(!0),ae(new Set(G));try{await Promise.all(G.map(se=>c.revertGitFile(u,se))),await Te(!1),we.success(G.length===1?o("gitView.toast.revertedFilesSingle",{count:G.length}):o("gitView.toast.revertedFilesPlural",{count:G.length}))}catch(se){we.error(se instanceof Error?se.message:o("gitView.toast.revertFailed"))}finally{ae(new Set),le(!1)}},[u,c,te,Te,o]),Vt=f.useCallback(_=>{const G=_.map(se=>se.trim()).filter(Boolean);if(G.length===0){ie([]);return}Z(se=>`${se.trim()}${se.trim()?`
23
+
24
+ `:""}${G.join(`
25
+ `)}`.trim()),ie([])},[]),fn=f.useCallback(async()=>{if(!u)return;const _=lt.map(G=>G.path).sort();if(_.length===0){we.error(o("gitView.toast.selectFileToDescribe"));return}ee(!0);try{const{message:G}=await Qr(u,_);Z(G.subject?.trim()??""),ie(Array.isArray(G.highlights)?G.highlights:[])}catch(G){we.error(G instanceof Error?G.message:o("gitView.toast.generateCommitMessageFailed"))}finally{ee(!1)}},[u,lt,o]),Ut=async(_={})=>{if(!u)return;if(!W.trim()){we.error(o("gitView.toast.enterCommitMessage"));return}const G=lt.map(se=>se.path).sort();if(G.length===0){we.error(o("gitView.toast.selectFileToCommit"));return}Y(_.pushAfter?"commitAndPush":"commit");try{if(await c.createGitCommit(u,W.trim(),{files:G}),we.success(o("gitView.toast.commitCreated")),Z(""),ie([]),_.pushAfter){const se=p?.tracking?.split("/")[0],be=Be.find(ct=>ct.name===se)??Be[0];if(!be)throw new Error(o("mobile.changes.noRemote"));q("sync"),await si({git:c,directory:u,remote:be,dirtyWorktreeError:o("gitView.toast.commitOrStashBeforeSync"),onPushed:ct=>{we.success(o("gitView.toast.pushedToUpstream",{name:ct.pushed[0].remote}))}}),await Te(!1),await st()}else await Te(!1)}catch(se){we.error(se instanceof Error?se.message:o("gitView.toast.createCommitFailed"))}finally{Y(null),_.pushAfter&&q(null)}},Gt=f.useMemo(()=>{const _=[];return lt.length>0&&_.push({id:"staged",title:o("gitView.changes.stagedTitle"),entries:lt,statsScope:"staged",actionSymbol:"-",actionAllLabel:o("gitView.changes.unstageAllAria"),getActionLabel:G=>o("gitView.changes.unstageFileAria",{path:G}),onActionFile:G=>{ht([G],"unstage")},onActionAll:G=>{ht(G,"unstage")},onViewDiff:G=>Ue(G,!0),onRevertFile:nt,showRevertActions:!1,accent:!0}),je.length>0&&_.push({id:"unstaged",title:o("gitView.changes.title"),entries:je,statsScope:"working",actionSymbol:"+",actionAllLabel:o("gitView.changes.stageAllAria"),getActionLabel:G=>o("gitView.changes.stageFileAria",{path:G}),onActionFile:G=>{ht([G],"stage")},onActionAll:G=>{ht(G,"stage")},onViewDiff:G=>Ue(G,!1),onRevertFile:nt}),_},[nt,Ue,ht,lt,o,je]),Kt=_=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":o("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(J,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:o("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:p?.current||u||""})]}),l===!1&&Array.isArray(a)&&a.length>0?t.jsx(Ec,{repositories:a,selectedRepository:m??null,onSelectRepository:G=>{n&&v(n,G)},repositoryRoot:n??void 0}):null]}),t.jsx("div",{className:"min-h-0 flex-1",children:_})]});if(!u)return Kt(t.jsx(ot,{message:o("gitView.empty.selectSessionOrDirectory")}));if(l===!1&&h!==!0)return Kt(t.jsx(Ic,{rootIsGitRepo:l,resolvedIsGitRepo:h,nestedRepos:a,onRetryDiscovery:()=>{n&&E(n,{force:!0})}}));if(b&&h===null)return Kt(t.jsx(ot,{loading:!0,message:o("gitView.loading.checkingRepository")}));if(P.type==="diff")return t.jsx(Ei,{path:P.path,diff:dt,staged:P.staged,fileExists:!!Ms,unavailableReason:Ie?.key===`${u}\0${P.path}`?Ie.reason:null,error:U,onBack:()=>F({type:"list"}),onRetry:()=>De(_=>_+1)});const zs=o(j==="pr"?"session.githubIntegration.tabs.pullRequests":j==="branch"?"diffView.scope.branch":j==="commit"?"commitComparison.mode":"mobile.nav.changes"),wt=j==="branch"&&Je.base?Nc(Je.base):j==="commit"?bt?.slice(0,8):j==="pr"&&yt?`#${yt.number}`:null;if(at&&Rt)return t.jsx(Ei,{path:at,subtitle:[zs,wt].filter(Boolean).join(" · "),diff:Rt.status==="ready"?Rt.diff:null,fileExists:!Pe.files||Pe.files.some(_=>_.path===at),error:Pe.error??(Rt.status==="error"?Rt.message:null),onBack:()=>F(Xt),onRetry:()=>{Pe.error&&Pe.refresh(),fs(_=>_+1)}});const Os=()=>j==="pr"&&!yt?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx(ot,{loading:xt.loading,message:xt.error??(xt.loading?o("session.githubPrPicker.loading.pullRequests"):o("pullRequestComparison.select"))}),!xt.loading&&t.jsx(ni,{mobile:!0,comparison:xt})]}):j==="branch"&&!Je.base?t.jsx(ot,{loading:!Je.resolved,message:Je.resolved?o("gitView.pr.toast.baseBranchRequired"):o("diffView.branch.resolvingBase")}):j==="commit"&&!bt?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[tt.loading&&t.jsx(J,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:tt.loading?o("diffView.state.loadingChanges"):tt.error??o("commitComparison.noCommits")}),tt.error&&t.jsx(Se,{variant:"outline",size:"lg",onClick:()=>{tt.refresh()},children:o("diffView.actions.retry")})]}):Pe.error?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx("p",{className:"typography-ui-label font-semibold",children:o("diffView.state.failedToLoadDiff")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:Pe.error}),t.jsx(Se,{variant:"outline",size:"lg",onClick:()=>{Pe.refresh()},children:o("diffView.actions.retry")})]}):Ve?Ve.length===0?t.jsx(ot,{icon:j==="branch",message:j==="pr"?o("walkthrough.blocked.emptyDiff.description"):j==="commit"?o("commitComparison.emptyDiff"):o("diffView.branch.empty",{base:wt??""})}):t.jsx(Jf,{files:Ve,onSelect:_=>{Pe.key&&F({type:"comparison",path:_,sourceKey:Pe.key})}}):t.jsx(ot,{loading:!0,message:o("diffView.state.loadingChanges")});return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":o("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(J,{name:"close",className:"size-5"})}):null,t.jsxs(gl,{open:V,onOpenChange:I,children:[t.jsx(bl,{asChild:!0,children:t.jsxs(Se,{variant:"outline",className:xl({size:"default"}),"data-mobile-comparison-trigger":!0,"aria-label":o("diffView.scope.selectorAria"),children:[t.jsx("span",{children:zs}),t.jsx(J,{name:"arrow-down-s",className:"size-4"})]})}),t.jsx(yl,{align:"start",children:t.jsxs(vl,{value:j,onValueChange:_=>{(_==="working"||_==="branch"||_==="commit"||_==="pr")&&D(_)},children:[t.jsx(Vs,{value:"working",className:"min-h-8 items-center",children:o("mobile.nav.changes")}),He&&t.jsx(Vs,{value:"branch",className:"min-h-8 items-center",children:o("diffView.scope.branch")}),t.jsx(Vs,{value:"commit",className:"min-h-8 items-center",children:o("commitComparison.mode")}),t.jsx(Vs,{value:"pr",className:"min-h-8 items-center",children:o("session.githubIntegration.tabs.pullRequests")})]})})]}),r&&j==="branch"&&t.jsx(Cu,{mobile:!0,branches:g?.all??[],currentBranch:Ee,base:Je.base,onSelect:_=>{Ee&&cn(u,Ee,_)}},JSON.stringify([w,Ee])),r&&j==="commit"&&t.jsx(Ru,{mobile:!0,commits:tt.commits,selectedHash:bt,loading:tt.loading,error:tt.error,onSelect:tt.select,onRefresh:()=>{tt.refresh()}},JSON.stringify([w,Ee])),r&&j==="pr"&&t.jsxs(t.Fragment,{children:[t.jsx(ni,{mobile:!0,comparison:xt},JSON.stringify([w,Ee])),yt&&t.jsx(Se,{variant:"ghost",size:"sm",disabled:Pe.loading,"aria-label":o("session.githubIssuePicker.actions.refresh"),onClick:()=>{Pe.refresh()},children:t.jsx(J,{name:"refresh",className:"size-4"})})]})]}),j==="working"&&t.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(Cc,{currentBranch:p?.current,localBranches:Lt,remoteBranches:$t,branchInfo:g?.branches,currentBranchAhead:p?.ahead,onCheckout:_=>{vt(_)},onCreate:Ft,remotes:Be,disabled:b,directory:u,switchBlockedNotice:(p?.files?.length??0)>0?o("gitView.branch.switchBlockedNotice"):null})}),t.jsx(Rc,{syncAction:L,remotes:Be,onFetch:_=>{Et("fetch",_)},onSync:_=>{Et("sync",_)},disabled:X!==null||b,aheadCount:p?.ahead??0,behindCount:p?.behind??0,trackingRemoteName:p?.tracking?.split("/")[0],hasUncommittedChanges:Ke.length>0})]}),j!=="working"?t.jsx("div",{className:"min-h-0 flex-1",children:Os()}):Ke.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(bu,{groups:Gt,diffStats:p?.diffStats,revertingPaths:fe,onRevertAll:Wt,isRevertingAll:te,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:oe})}),t.jsx("div",{className:"shrink-0 border-t border-border/70 px-4 pb-4 pt-3",children:t.jsx(xu,{stagedCount:lt.length,commitMessage:W,onCommitMessageChange:Z,generatedHighlights:ne,onInsertHighlights:Vt,onGenerateMessage:fn,isGeneratingMessage:B,onCommit:()=>{Ut({pushAfter:!1})},onCommitAndPush:()=>{Ut({pushAfter:!0})},commitAction:X,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(ot,{icon:!0,message:o("gitView.empty.cleanTitle"),description:o("mobile.changes.cleanDescription")})}),t.jsx(yu,{open:Re!==null,onOpenChange:_=>{_||Ae(null)},targetBranch:Re??"",changedFileCount:p?.files?.length??0,onCommitAndSwitch:async(_,G)=>{const se=Re;if(!se||!u)return;const be=p?.current??null;await c.createGitCommit(u,_,{addAll:!0});let ct=null;if(G){const qt=p?.tracking?.split("/")[0],It=Be.find(mn=>mn.name===qt)??Be[0];try{if(!It)throw new Error(o("mobile.changes.noRemote"));await c.gitPush(u,p?.tracking?{remote:It.name}:{remote:It.name,branch:be??void 0,options:["--set-upstream"]}),ct=It.name}catch{we.error(o("gitView.dirtySwitch.pushFailed")),await Te(),Ae(null);return}}we.success(be?ct?o("gitView.toast.pushedToUpstream",{name:ct}):o("gitView.dirtySwitch.committedNotPushed",{branch:be}):o("gitView.toast.commitCreated")),await Te(),Ae(null),await qe(se)},onGenerateMessage:async()=>{if(!u)return"";const _=(p?.files??[]).map(se=>se.path).sort(),{message:G}=await Qr(u,_);return G.subject?.trim()??""},onRevertAndSwitch:async()=>{const _=Re;if(!_||!u)return;await Wt((p?.files??[]).map(se=>se.path));const G=await c.getGitStatus(u);if(!G.isClean&&(G.files?.length??0)>0){we.error(o("gitView.dirtySwitch.revertIncomplete"));return}Ae(null),await qe(_)}})]})},ot=n=>{const e=de.c(13),{message:s,description:i,loading:r,icon:o}=n,c=r===void 0?!1:r,l=o===void 0?!1:o;let m;e[0]!==c?(m=c?t.jsx(J,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=c,e[1]=m):m=e[1];let a;e[2]!==l?(a=l?t.jsx(J,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=l,e[3]=a):a=e[3];let u;e[4]!==s?(u=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[4]=s,e[5]=u):u=e[5];let p;e[6]!==i?(p=i?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i}):null,e[6]=i,e[7]=p):p=e[7];let g;return e[8]!==m||e[9]!==a||e[10]!==u||e[11]!==p?(g=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[m,a,u,p]})}),e[8]=m,e[9]=a,e[10]=u,e[11]=p,e[12]=g):g=e[12],g},Ei=n=>{const e=de.c(31),{path:s,subtitle:i,diff:r,staged:o,fileExists:c,unavailableReason:l,error:m,onBack:a,onRetry:u}=n,p=o===void 0?!1:o,g=l===void 0?null:l,{t:h}=ge();let b;e[0]!==s?(b=wl(s)||"text",e[0]=s,e[1]=b):b=e[1];const k=b;let y;e[2]!==h?(y=h("header.actions.backAria"),e[2]=h,e[3]=y):y=e[3];let E;e[4]===Symbol.for("react.memo_cache_sentinel")?(E=t.jsx(J,{name:"arrow-left",className:"size-5"}),e[4]=E):E=e[4];let v;e[5]!==a||e[6]!==y?(v=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":y,onClick:a,children:E}),e[5]=a,e[6]=y,e[7]=v):v=e[7];let N;e[8]!==s?(N=t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:s}),e[8]=s,e[9]=N):N=e[9];let A;e[10]!==i?(A=i&&t.jsx("p",{className:"truncate typography-meta text-muted-foreground",children:i}),e[10]=i,e[11]=A):A=e[11];let x;e[12]!==N||e[13]!==A?(x=t.jsxs("div",{className:"min-w-0 flex-1 px-2",children:[N,A]}),e[12]=N,e[13]=A,e[14]=x):x=e[14];let R;e[15]!==v||e[16]!==x?(R=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/70 px-3 text-foreground",children:[v,x]}),e[15]=v,e[16]=x,e[17]=R):R=e[17];let S;e[18]!==r||e[19]!==m||e[20]!==c||e[21]!==k||e[22]!==u||e[23]!==s||e[24]!==p||e[25]!==h||e[26]!==g?(S=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:c?g==="nested_repository"?t.jsx(ot,{icon:!0,message:h("diffView.unavailable.nestedRepositoryTitle"),description:h("diffView.unavailable.nestedRepositoryDescription")}):g==="untracked_directory"?t.jsx(ot,{icon:!0,message:h("diffView.unavailable.untrackedDirectoryTitle"),description:h("diffView.unavailable.untrackedDirectoryDescription")}):m?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:h("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:m}),t.jsx(Se,{type:"button",size:"sm",variant:"outline",onClick:u,children:h("diffView.actions.retry")})]})}):r?r.submodule?t.jsx("div",{className:"p-3",children:t.jsx(Pu,{state:r.submodule,staged:p})}):r.isBinary?t.jsx(ot,{icon:!0,message:h("diffView.binary.unavailable")}):jl(s)&&!r.fileDiff?t.jsx(ot,{icon:!0,message:h("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(rn,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(Du,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:k,fileName:s,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(ot,{loading:!0,message:h("diffView.state.loadingDiff")}):t.jsx(ot,{icon:!0,message:h("mobile.changes.diffDetail.missingTitle"),description:h("mobile.changes.diffDetail.missingDescription")})}),e[18]=r,e[19]=m,e[20]=c,e[21]=k,e[22]=u,e[23]=s,e[24]=p,e[25]=h,e[26]=g,e[27]=S):S=e[27];let C;return e[28]!==R||e[29]!==S?(C=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[R,S]}),e[28]=R,e[29]=S,e[30]=C):C=e[30],C},Jf=n=>{const e=de.c(12),{files:s,onSelect:i}=n,{t:r}=ge();let o;e[0]!==r?(o=r("gitView.changes.changedFilesAria"),e[0]=r,e[1]=o):o=e[1];let c;if(e[2]!==s||e[3]!==i||e[4]!==r){let m;e[6]!==i||e[7]!==r?(m=a=>{const u=a.status==="A"?r("diffView.change.new"):a.status==="D"?r("diffView.change.deleted"):a.status==="R"?r("diffView.change.renamed"):a.status==="C"?r("diffView.change.copied"):r("diffView.change.modified"),p=a.status==="A"?"var(--status-success)":a.status==="D"?"var(--status-error)":a.status==="R"||a.status==="C"?"var(--status-info)":"var(--status-warning)";return t.jsx("li",{children:t.jsxs(Se,{variant:"ghost",size:"lg",className:"w-full justify-start gap-2.5 text-left normal-case",onClick:()=>i(a.path),children:[t.jsx("span",{className:"w-4 shrink-0 text-center typography-meta font-semibold uppercase",style:{color:p},"aria-label":u,children:a.status}),t.jsx(ro,{filePath:a.path,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label",title:a.path,children:a.path}),(a.insertions>0||a.deletions>0)&&t.jsxs("span",{className:"shrink-0 typography-meta text-muted-foreground",children:["+",a.insertions," -",a.deletions]}),t.jsx(J,{name:"arrow-right-s",className:"size-4 shrink-0 text-muted-foreground"})]})},a.path)},e[6]=i,e[7]=r,e[8]=m):m=e[8],c=s.map(m),e[2]=s,e[3]=i,e[4]=r,e[5]=c}else c=e[5];let l;return e[9]!==o||e[10]!==c?(l=t.jsx(rn,{className:"h-full overflow-y-auto overflow-x-hidden px-3 py-2",children:t.jsx("ul",{"aria-label":o,className:"flex flex-col gap-1",children:c})}),e[9]=o,e[10]=c,e[11]=l):l=e[11],l},Yf=f.lazy(()=>os(()=>import("./FilesView-B_NJFLBH.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131])).then(n=>({default:n.FilesView}))),kt=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),Ns=n=>{const e=kt(n);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},Xf=n=>{const e=kt(n);if(!e||e==="/")return null;const s=e.lastIndexOf("/");return s<=0?e.startsWith("/")?"/":null:e.slice(0,s)},Qf=(n,e)=>{const s=kt(n),i=kt(e);return!i||s===i?Ns(s):s.startsWith(`${i}/`)?s.slice(i.length+1):s},Zf=n=>{if(typeof n!="number"||!Number.isFinite(n)||n<0)return"";if(n<1024)return`${n} B`;const e=["KB","MB","GB"];let s=n/1024;for(const i of e){if(s<1024||i===e[e.length-1])return`${s.toFixed(s>=10?0:1)} ${i}`;s/=1024}return""},em=n=>{const e=de.c(5),{onClose:s}=n,i=qn()??null;let r;e[0]!==i?(r=kt(i),e[0]=i,e[1]=r):r=e[1];const o=r;let c;return e[2]!==s||e[3]!==o?(c=t.jsx(tm,{root:o,onClose:s},o),e[2]=s,e[3]=o,e[4]=c):c=e[4],c},tm=({root:n,onClose:e})=>{const{t:s}=ge(),{files:i}=Kn(),r=Sa(W=>W.setSelectedPath),[o,c]=f.useState(()=>({type:"browser",directory:n})),[l,m]=f.useState([]),[a,u]=f.useState(!1),[p,g]=f.useState(null),[h,b]=f.useState(""),[k,y]=f.useState([]),[E,v]=f.useState(!1),N=f.useRef(0),A=o.type==="browser"?o.directory:o.returnDirectory,x=f.useRef(A);x.current=A;const R=f.useCallback(async W=>{if(!W)return;const Z=N.current+1;N.current=Z,u(!0),g(null);try{const fe=await i.listDirectory(W);if(N.current!==Z)return;m(fe.entries.slice().sort((ae,te)=>ae.isDirectory!==te.isDirectory?ae.isDirectory?-1:1:ae.name.localeCompare(te.name)))}catch(fe){if(N.current!==Z)return;m([]),g(fe instanceof Error?fe.message:s("mobile.files.error.listFailed"))}finally{N.current===Z&&u(!1)}},[i,s]);f.useEffect(()=>{o.type==="browser"&&R(o.directory)},[R,o]);const S=f.useCallback(async W=>{kt(W)===kt(x.current)&&await R(x.current)},[R]),{canUpload:C,uploadingDirectory:w,pickFiles:T,uploadElements:M}=Ac({root:n,refreshDirectory:S}),z=w!==null;f.useEffect(()=>{if(o.type!=="browser")return;const W=h.trim();if(!W){y([]),v(!1);return}let Z=!1;const fe=window.setTimeout(()=>{v(!0),i.search({directory:o.directory,query:W,maxResults:40}).then(ae=>{Z||y(ae)}).catch(()=>{Z||y([])}).finally(()=>{Z||v(!1)})},250);return()=>{Z=!0,window.clearTimeout(fe)}},[i,h,o]);const j=W=>{b(""),c({type:"browser",directory:W})},P=W=>{r(n,W),c({type:"file",path:W,returnDirectory:A||n})},V=Oe(W=>W.pendingFileFocusPath),I=Oe(W=>W.pendingFileNavigation);if(f.useEffect(()=>{const W=kt(I?.path??V??"");!W||!n||W!==n&&!W.startsWith(`${n}/`)||(r(n,W),c({type:"file",path:W,returnDirectory:n}),V&&Oe.getState().setPendingFileFocusPath(null))},[V,I,n,r]),!n)return t.jsx(Cs,{message:s("mobile.files.empty.noDirectory")});if(o.type==="file")return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 border-b border-border/70 px-3 text-foreground",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":s("header.actions.backAria"),onClick:()=>c({type:"browser",directory:o.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(ti,{className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:Ns(o.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Ge,{children:t.jsx(f.Suspense,{fallback:t.jsx(Cs,{loading:!0,message:s("filesView.state.loading")}),children:t.jsx(Yf,{mode:"editor-only"})})})})]});const D=o.directory===n?s("mobile.files.rootDirectory"):Ns(o.directory),F=h.trim()?k:[],L=Xf(o.directory),q=o.directory!==n&&L!==null&&(L===n||L.startsWith(`${n}/`)),X=q&&!h.trim(),Y=q?L:null;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[M,t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[e?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":s("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(uu,{className:"size-5"})}):null,X&&Y?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":s("mobile.files.backToParentAria",{name:Ns(Y)}),onClick:()=>j(Y),style:{touchAction:"manipulation"},children:t.jsx(ti,{className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:D})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":s("mobile.files.refreshAria"),onClick:()=>{R(o.directory)},style:{touchAction:"manipulation"},children:t.jsx(du,{className:Q("size-5",a&&"animate-spin")})}),C?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50","aria-label":s("sidebarFilesTree.actions.uploadFilesTitle"),onClick:()=>T(o.directory),disabled:z,style:{touchAction:"manipulation"},children:t.jsx(J,{name:z?"loader-4":"upload-2",className:Q("size-5",z&&"animate-spin")})}):null]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(fu,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(eo,{value:h,onChange:W=>b(W.target.value),placeholder:s("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(rn,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:p?t.jsx(Cs,{message:p}):h.trim()?t.jsx(sm,{results:F,isSearching:E,onOpenFile:P}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:[l.length===0&&!a?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:s("mobile.files.empty.directory")}):null,l.map(W=>t.jsx(Wo,{name:W.name,path:W.path,directory:W.isDirectory,meta:W.isDirectory?void 0:Zf(W.size),onClick:()=>W.isDirectory?j(W.path):P(W.path)},W.path))]})})]})},Wo=n=>{const e=de.c(16),{name:s,path:i,directory:r,meta:o,onClick:c}=n;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={touchAction:"manipulation"},e[0]=l):l=e[0];let m;e[1]!==r||e[2]!==i?(m=r?t.jsx(hu,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(ro,{filePath:i,className:"size-5 shrink-0"}),e[1]=r,e[2]=i,e[3]=m):m=e[3];let a;e[4]!==s?(a=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s}),e[4]=s,e[5]=a):a=e[5];let u;e[6]!==o?(u=o?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:o}):null,e[6]=o,e[7]=u):u=e[7];let p;e[8]!==r?(p=r?t.jsx(gu,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=r,e[9]=p):p=e[9];let g;return e[10]!==c||e[11]!==m||e[12]!==a||e[13]!==u||e[14]!==p?(g=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:c,style:l,children:[m,a,u,p]}),e[10]=c,e[11]=m,e[12]=a,e[13]=u,e[14]=p,e[15]=g):g=e[15],g},sm=n=>{const e=de.c(10),{results:s,isSearching:i,onOpenFile:r}=n,{t:o}=ge(),c=kt(qn()??null);if(i){let u;e[0]!==o?(u=o("common.loading"),e[0]=o,e[1]=u):u=e[1];let p;return e[2]!==u?(p=t.jsx(Cs,{loading:!0,message:u}),e[2]=u,e[3]=p):p=e[3],p}if(s.length===0){let u;e[4]!==o?(u=o("mobile.files.search.empty"),e[4]=o,e[5]=u):u=e[5];let p;return e[6]!==u?(p=t.jsx(Cs,{message:u}),e[6]=u,e[7]=p):p=e[7],p}const l="overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",m=s.map(u=>t.jsx(Wo,{name:Ns(u.path),path:u.path,directory:!1,meta:Qf(u.path,c),onClick:()=>r(u.path)},u.path));let a;return e[8]!==m?(a=t.jsx("div",{className:l,children:m}),e[8]=m,e[9]=a):a=e[9],a},Cs=n=>{const e=de.c(7),{message:s,loading:i}=n,r=i===void 0?!1:i;let o;e[0]!==r?(o=r?t.jsx(mu,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(pu,{className:"size-6 text-muted-foreground"}),e[0]=r,e[1]=o):o=e[1];let c;e[2]!==s?(c=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[2]=s,e[3]=c):c=e[3];let l;return e[4]!==o||e[5]!==c?(l=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[o,c]})}),e[4]=o,e[5]=c,e[6]=l):l=e[6],l},Ii="mobile-surface-root",nm=16,Ai=320,rm="cubic-bezier(0.22, 1, 0.36, 1)",im=n=>{const e=de.c(36),{onOpenMcpSettings:s}=n,{t:i}=ge(),[r,o]=f.useState(!1),c=Nt(am),l=vs(lm),m=ns(cm);let a;e[0]!==c||e[1]!==r||e[2]!==m||e[3]!==l?(a=()=>{if(r)return;o(!0);const T=new Promise(um);Promise.all([l({directory:c||null,silent:!0}),m({force:!0}),T]).finally(()=>o(!1))},e[0]=c,e[1]=r,e[2]=m,e[3]=l,e[4]=a):a=e[4];const u=a;let p;e[5]!==i?(p=i("settings.mcp.sidebar.actions.addServerTitle"),e[5]=i,e[6]=p):p=e[6];let g;e[7]!==i?(g=i("settings.mcp.sidebar.actions.addServerTitle"),e[7]=i,e[8]=g):g=e[8];let h,b;e[9]===Symbol.for("react.memo_cache_sentinel")?(h={touchAction:"manipulation"},b=t.jsx(J,{name:"add",className:"size-5"}),e[9]=h,e[10]=b):(h=e[9],b=e[10]);let k;e[11]!==s||e[12]!==p||e[13]!==g?(k=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:s,"aria-label":p,title:g,style:h,children:b}),e[11]=s,e[12]=p,e[13]=g,e[14]=k):k=e[14];let y;e[15]!==i?(y=i("mcpDropdown.actions.refreshAria"),e[15]=i,e[16]=y):y=e[16];let E;e[17]!==i?(E=i("mcpDropdown.actions.refreshAria"),e[17]=i,e[18]=E):E=e[18];let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v={touchAction:"manipulation"},e[19]=v):v=e[19];const N=r&&"animate-spin";let A;e[20]!==N?(A=Q("size-5",N),e[20]=N,e[21]=A):A=e[21];let x;e[22]!==A?(x=t.jsx(J,{name:"refresh",className:A}),e[22]=A,e[23]=x):x=e[23];let R;e[24]!==r||e[25]!==u||e[26]!==x||e[27]!==y||e[28]!==E?(R=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:u,disabled:r,"aria-label":y,title:E,style:v,children:x}),e[24]=r,e[25]=u,e[26]=x,e[27]=y,e[28]=E,e[29]=R):R=e[29];let S;e[30]!==R||e[31]!==k?(S=t.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1 px-2 pt-1",children:[k,R]}),e[30]=R,e[31]=k,e[32]=S):S=e[32];let C;e[33]===Symbol.for("react.memo_cache_sentinel")?(C=t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Vf,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})}),e[33]=C):C=e[33];let w;return e[34]!==S?(w=t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[S,C]}),e[34]=S,e[35]=w):w=e[35],w},om=({open:n,onClose:e,tab:s,onTabChange:i,pendingChangesDiff:r,onOpenPlan:o,onOpenMcpSettings:c,variant:l="drawer"})=>{const{t:m}=ge(),a=f.useRef(null),u=f.useRef(null),[p,g]=f.useState(!1),[h,b]=f.useState(n),k=f.useRef(e);f.useEffect(()=>{k.current=e},[e]);const y=f.useRef(s);f.useEffect(()=>{y.current=s},[s]),gr(u,{enabled:l==="drawer"&&n,onLeftEdgeSwipe:()=>k.current()});const[E,v]=f.useState(()=>new Set);if(f.useEffect(()=>{n&&v(x=>{if(x.has(s))return x;const R=new Set(x);return R.add(s),R})},[n,s]),typeof document<"u"&&!a.current){let x=document.getElementById(Ii);x||(x=document.createElement("div"),x.id=Ii,document.body.appendChild(x)),a.current=x}if(f.useEffect(()=>{if(n){b(!0);const R=window.setTimeout(()=>g(!0),nm);return()=>window.clearTimeout(R)}g(!1);const x=window.setTimeout(()=>b(!1),Ai+40);return()=>window.clearTimeout(x)},[n]),f.useEffect(()=>{if(!n)return;const x=document.body.style.overflow;l==="drawer"&&(document.body.style.overflow="hidden");const R=S=>{S.key!=="Escape"||y.current==="terminal"||Sl(S.target)||k.current()};return document.addEventListener("keydown",R),()=>{l==="drawer"&&(document.body.style.overflow=x),document.removeEventListener("keydown",R)}},[n,l]),l==="drawer"&&!a.current)return null;const N=[{id:"changes",label:m("mobile.menu.changes"),icon:t.jsx(J,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"files",label:m("mobile.menu.files"),icon:t.jsx(J,{name:"file-text",className:"h-3.5 w-3.5"})},{id:"terminal",label:m("mobile.menu.terminal"),icon:t.jsx(J,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"notes",label:m("contextRail.surface.notes"),icon:t.jsx(J,{name:"sticky-note",className:"h-3.5 w-3.5"})},{id:"mcp",label:m("mobile.menu.mcp"),icon:t.jsx(kl,{className:"h-3.5 w-3.5"})}],A=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("div",{className:"flex h-9 min-w-0 flex-1 items-center",children:h?t.jsx(Pc,{items:N,activeId:s,onSelect:x=>i(x),layoutMode:"fit",variant:"active-pill",nonCompositedIndicator:!0,inactiveTabsIconOnly:!0,className:"h-full"}):null}),t.jsx("button",{type:"button",className:"-mr-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":m("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(J,{name:"close",className:"size-5"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[E.has("changes")?t.jsx("div",{className:Q("h-full",s!=="changes"&&"hidden"),children:t.jsx(Ge,{children:t.jsx(qf,{visible:n&&s==="changes",initialDiff:r})})},r?`changes:${r.path}:${r.staged}`:"changes"):null,E.has("files")?t.jsx("div",{className:Q("h-full",s!=="files"&&"hidden"),children:t.jsx(Ge,{children:t.jsx(em,{})})}):null,E.has("terminal")?t.jsx("div",{className:Q("h-full",s!=="terminal"&&"hidden"),children:t.jsx(Ge,{children:t.jsx(Tc,{visible:n&&s==="terminal"})})}):null,E.has("notes")?t.jsx("div",{className:Q("h-full",s!=="notes"&&"hidden"),children:t.jsx(Ge,{children:t.jsx(Dc,{onActionComplete:e,onOpenPlan:o})})}):null,E.has("mcp")?t.jsx("div",{className:Q("h-full",s!=="mcp"&&"hidden"),children:t.jsx(Ge,{children:t.jsx(im,{onOpenMcpSettings:c})})}):null]})]});return l==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:A}):is.createPortal(t.jsx("section",{ref:u,role:"dialog","aria-modal":"true","aria-label":m("mobile.header.openWorkspaceAria"),"aria-hidden":!n,className:"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:p?"none":"translateX(100%)",transition:`transform ${Ai}ms ${rm}`,visibility:h?"visible":"hidden",pointerEvents:n?"auto":"none"},children:A}),a.current)};function am(n){return n.currentDirectory}function lm(n){return n.refresh}function cm(n){return n.loadMcpConfigs}function um(n){return window.setTimeout(n,500)}function dm(n){const e=de.c(4),s=2500,{uiFont:i}=Nl(),[r,o]=f.useState(!1);let c,l;return e[0]!==s||e[1]!==i?(c=()=>{let m=!1;const a=()=>{m||o(!0)},u=()=>{requestAnimationFrame(()=>requestAnimationFrame(a))},p=Promise.all([Cl(i).catch(gm),document.fonts?.ready?.then(hm).catch(pm)??Promise.resolve(),Mu.catch(mm)]).then(fm),g=new Promise(h=>{window.setTimeout(h,s)});return Promise.race([p,g]).then(u),()=>{m=!0}},l=[i,s],e[0]=s,e[1]=i,e[2]=c,e[3]=l):(c=e[2],l=e[3]),f.useEffect(c,l),r}function fm(){}function mm(){}function pm(){}function hm(){}function gm(){}const bm="openchamber",xm=n=>n.replace(/^\/+|\/+$/g,""),ym=n=>{const e=xm(n.pathname).split("/").filter(Boolean);return n.host?[n.host,...e]:e};function vm(n){if(typeof n!="string"||n.length===0)return null;let e;try{e=new URL(n)}catch{return null}if(e.protocol!==`${bm}:`)return null;const s=ym(e),i=(s[0]??"").toLowerCase(),r=s.slice(1),o=e.searchParams;switch(i){case"session":{const c=r[0]||o.get("id")||"";if(!c)return null;const l=o.get("message")?.trim()??"";return{type:"session",sessionId:c,directory:o.get("dir")??void 0,...Rl(l)?{messageId:l}:{}}}case"new":case"new-session":return{type:"new-session",directory:o.get("dir")??void 0,projectId:o.get("project")??void 0,agent:o.get("agent")??void 0,model:o.get("model")??void 0};case"sessions":{const c=o.get("filter");return{type:"sessions",filter:c==="attention"||c==="recent"||c==="all"?c:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:r[0]||o.get("section")||void 0};case"changes":return{type:"changes",path:r.join("/")||o.get("path")||void 0,staged:o.get("staged")==="true"};case"view":{const c=(r[0]||"").toLowerCase();return c==="changes"?{type:"changes"}:c==="files"||c==="mcp"||c==="instances"||c==="update"?{type:"view",target:c}:null}default:return null}}let rt={},Vo=!1,Ss=null;const wm=n=>{switch(n.type){case"session":return n.messageId&&!n.directory?(_u(n.sessionId,n.messageId),!0):(n.messageId&&El(n.sessionId,n.messageId),_e.getState().setCurrentSession(n.sessionId,n.directory??null),!0);case"new-session":{const e=_e.getState();return e.openNewSessionDraft(),(n.directory||n.projectId)&&e.setNewSessionDraftTarget({directoryOverride:n.directory??null,projectId:n.projectId??null,selectedProjectId:n.projectId??null}),!0}case"sessions":return rt.openSessions?(rt.openSessions(n.filter),!0):!1;case"status":return rt.openSessions?(rt.openSessions(),!0):!1;case"view":return rt.openView?(rt.openView(n.target),!0):!1;case"changes":return rt.openChanges?(rt.openChanges({path:n.path,staged:n.staged}),!0):!1;case"settings":return rt.openSettings?(rt.openSettings(n.section),!0):!1}},br=()=>{if(!Vo||!Ss)return;const n=Ss;Ss=null,wm(n)||(Ss=n)},Uo=n=>{Ss=n,br()},Pi=n=>{const e=vm(n);e&&Uo(e)},jm=n=>{Vo=n,br()},km=n=>{const e=de.c(3);let s,i;e[0]!==n?(s=()=>(rt=n,br(),()=>{rt===n&&(rt={})}),i=[n],e[0]=n,e[1]=s,e[2]=i):(s=e[1],i=e[2]),f.useEffect(s,i)},Sm=n=>{const{ready:e}=n;f.useEffect(()=>{jm(e)},[e]),f.useEffect(()=>{if(!We())return;let s=!1;const i=[];return os(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([132,5,133])).then(async({App:r})=>{if(s)return;const o=await r.addListener("appUrlOpen",c=>{Pi(c?.url)});if(s){o.remove();return}i.push(()=>{o.remove()})}).catch(()=>{}),os(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([134,133])).then(async({PushNotifications:r})=>{if(s)return;const o=await r.addListener("pushNotificationActionPerformed",c=>{const l=c?.notification?.data,m=typeof l?.url=="string"?l.url:typeof l?.deeplink=="string"?l.deeplink:void 0;if(m){Pi(m);return}const a=typeof l?.sessionId=="string"?l.sessionId:void 0;a&&Uo({type:"session",sessionId:a})});if(s){o.remove();return}i.push(()=>{o.remove()})}).catch(()=>{}),()=>{s=!0,i.forEach(r=>r())}},[])},Nm=()=>{if(typeof window>"u")return;const n=window.__OPENCHAMBER_APNS_ENV__;if(n==="development")return"sandbox";if(n==="production")return"production"},Cm=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},Rm=n=>{const{enabled:e}=n,s=Oe(r=>r.nativeNotificationsEnabled),i=f.useRef(null);f.useEffect(()=>{if(!e||!s||!Cm())return;let r=!1;const o=[];return os(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([134,133])).then(async({PushNotifications:c})=>{if(r)return;let l=await c.checkPermissions().catch(()=>null);if(l?.receive!=="granted"&&(l=await c.requestPermissions().catch(()=>null)),l?.receive!=="granted")return;const m=await c.addListener("registration",u=>{i.current=u.value,Gr()?.push?.registerApnsToken?.({token:u.value,platform:zi(),environment:Nm()})}),a=await c.addListener("registrationError",u=>{console.warn("[Push] APNs registration error:",u)});if(await c.register().catch(()=>{}),r){m.remove(),a.remove();return}o.push(()=>{m.remove()},()=>{a.remove()})}).catch(()=>{}),()=>{r=!0,o.forEach(c=>c())}},[e,s]),f.useEffect(()=>{if(s)return;const r=i.current;if(!r)return;i.current=null,Gr()?.push?.unregisterApnsToken?.({token:r})},[s])},Ti=n=>{const e=de.c(12),{side:s,isResizing:i,ariaLabel:r,handleProps:o}=n,c=s==="left"?"right-0":"left-0";let l;e[0]!==c?(l=Q("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",c),e[0]=c,e[1]=l):l=e[1];const m=s==="left"?"right-0":"left-0",a=i&&"bg-[var(--interactive-border)]";let u;e[2]!==m||e[3]!==a?(u=Q("absolute inset-y-0 w-[3px] transition-colors",m,a),e[2]=m,e[3]=a,e[4]=u):u=e[4];let p;e[5]!==u?(p=t.jsx("div",{className:u}),e[5]=u,e[6]=p):p=e[6];let g;return e[7]!==r||e[8]!==o||e[9]!==l||e[10]!==p?(g=t.jsx("div",{className:l,role:"separator","aria-orientation":"vertical","aria-label":r,...o,children:p}),e[7]=r,e[8]=o,e[9]=l,e[10]=p,e[11]=g):g=e[11],g},Em=320,Im=380,Di=280,Am=560,Pm=900;function _i(n,e,s,i){const r=de.c(23),o=i===void 0?Am:i,c=f.useRef(null);let l;r[0]!==s||r[1]!==o||r[2]!==e?(l=()=>{if(typeof window>"u")return s;const j=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(j)?Math.min(o,Math.max(Di,j)):s},r[0]=s,r[1]=o,r[2]=e,r[3]=l):l=r[3];const[m,a]=f.useState(l),[u,p]=f.useState(!1),g=f.useRef(0),h=f.useRef(m),b=f.useRef(null),k=f.useRef(null);let y;r[4]!==o?(y=j=>Math.min(o,Math.max(Di,Math.round(j))),r[4]=o,r[5]=y):y=r[5];const E=y;let v;r[6]===Symbol.for("react.memo_cache_sentinel")?(v=j=>{const P=c.current;P&&(P.style.width=`${j}px`,P.style.minWidth=`${j}px`,P.style.maxWidth=`${j}px`,P.style.setProperty("--oc-ipad-sidebar-width",`${j}px`))},r[6]=v):v=r[6];const N=v;let A;r[7]!==m?(A=j=>{try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}k.current=j.pointerId,g.current=j.clientX,h.current=m,b.current=m,p(!0),j.preventDefault()},r[7]=m,r[8]=A):A=r[8];const x=A;let R;r[9]!==E||r[10]!==n?(R=j=>{if(k.current!==j.pointerId)return;const P=j.clientX-g.current,V=E(h.current+(n==="left"?P:-P));b.current!==V&&(b.current=V,N(V))},r[9]=E,r[10]=n,r[11]=R):R=r[11];const S=R;let C;r[12]!==E||r[13]!==e?(C=j=>{if(k.current!==j.pointerId)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const P=E(b.current??h.current);k.current=null,b.current=null,p(!1),a(P);try{window.localStorage.setItem(e,String(P))}catch{}},r[12]=E,r[13]=e,r[14]=C):C=r[14];const w=C;let T;r[15]!==x||r[16]!==w||r[17]!==S?(T={onPointerDown:x,onPointerMove:S,onPointerUp:w,onPointerCancel:w},r[15]=x,r[16]=w,r[17]=S,r[18]=T):T=r[18];const M=T;let z;return r[19]!==M||r[20]!==u||r[21]!==m?(z={asideRef:c,width:m,isResizing:u,handleProps:M},r[19]=M,r[20]=u,r[21]=m,r[22]=z):z=r[22],z}const Tm=["general","isolated-spaces","appearance","chat","notifications","sessions","routing","git","magic-prompts","snippets","behavior","agents","commands","mcp","plugins","skills.installed","skills.catalog","providers","web-search","usage","voice","integrations","about"],Dm=1e3,_m=({onActiveConnectionDeleted:n})=>{const{t:e}=ge();Yc();const[s,i]=f.useState(!1);f.useEffect(()=>_e.subscribe((U,he)=>{U.currentSessionId&&U.currentSessionId!==he.currentSessionId&&Oe.getState().setRunOverviewKey(null)}),[]);const r=Oe(U=>U.runOverviewKey!==null);f.useEffect(()=>{r&&i(!1)},[r]);const[o,c]=f.useState(null),[l,m]=f.useState(!1),[a,u]=f.useState("changes"),[p,g]=f.useState(null),[h,b]=f.useState("nav"),[k,y]=f.useState(null),E=Oe(U=>U.setSettingsPage),v=Oe(U=>U.wideChatLayoutEnabled),N=es(U=>U.available),A=es(U=>U.runtimeType),x=f.useMemo(()=>Hn(),[]),R=ns(U=>U.mcpServers),S=ns(U=>U.setMcpDraft),C=ns(U=>U.setSelectedMcp),w=f.useCallback(()=>{c(null),g(null)},[]),T=f.useCallback(U=>{c(U)},[]),M=f.useCallback(()=>{m(!1)},[]),z=f.useCallback(U=>{b(U),T("settings")},[T]),{enabled:j,roomyForPanels:P}=Wn(),I=Hl()==="portrait",D=Jl(),[F,L]=f.useState(()=>Yl().roomyForPanels),q=f.useCallback(()=>{L(U=>!U)},[]);f.useEffect(()=>{j||L(!1)},[j]);const X=f.useCallback(()=>{y(null),u("files"),m(!0)},[]);f.useEffect(()=>io(U=>{if(U.type!=="file-open-request")return;const he=U.directory??Nt.getState().currentDirectory;he&&(Oe.getState().openContextFile(he,U.path),X())}),[X]);const Y=f.useCallback((U=null)=>{y(U),u("changes"),m(!0)},[]),W=_i("left","openchamber.ipad.leftSidebarWidth",Em),Z=_i("right","openchamber.ipad.rightSidebarWidth",Im,Pm),fe=P,ae=fe&&l?Z.width:0,te=j&&F?W.width:0;f.useEffect(()=>{if(typeof document>"u")return;const U=document.documentElement;return U.style.setProperty("--oc-chat-inset-left",`${te}px`),U.style.setProperty("--oc-chat-inset-right",`${ae}px`),()=>{U.style.removeProperty("--oc-chat-inset-left"),U.style.removeProperty("--oc-chat-inset-right")}},[te,ae]),f.useEffect(()=>{if(typeof document>"u")return;const U=document.documentElement;return U.classList.toggle("wide-chat-layout",v),()=>U.classList.remove("wide-chat-layout")},[v]),f.useEffect(()=>{if(typeof document>"u")return;const U=j&&(I||D),he=document.documentElement;return he.classList.toggle("oc-keep-draft-starters",U),()=>he.classList.remove("oc-keep-draft-starters")},[D,j,I]);const le=f.useMemo(()=>({openChanges:({diffPath:U,staged:he}={})=>{Y(U?{path:U,staged:he===!0}:null)},openFiles:()=>X(),openSettings:()=>z("nav")}),[Y,X,z]),B=f.useMemo(()=>({openSessions:()=>{j?L(!0):i(!0)},openView:U=>{if(U==="files"){X();return}if(U==="mcp"){u("mcp"),m(!0);return}T(U)},openChanges:({path:U,staged:he}={})=>{Y(U?{path:U,staged:he===!0}:null)},openSettings:U=>{U&&E(U),z(U?"page-content":"nav")}}),[j,Y,X,z,T,E]);km(B);const ee=f.useRef(null);gr(ee,{onLeftEdgeSwipe:()=>{j?L(!0):i(!0)},onRightEdgeSwipe:()=>m(!0)});const ne=f.useRef(null),ie=f.useCallback(U=>{ne.current=U},[]),H=f.useCallback(()=>Xl()?!0:p?(g(null),!0):o==="settings"&&ne.current?.()?!0:o?(w(),!0):l?(M(),!0):s?(i(!1),!0):!1,[o,w,M,p,s,l]);Ql(H);const oe=!x&&N&&(A==="desktop"||A==="web"),ue=j?"dialog":"fullscreen",xe=f.useMemo(()=>({instanceLabel:x?ws():null,onOpenInstances:x?()=>T("instances"):void 0,onOpenSettings:()=>z("nav"),onOpenUsage:()=>T("usage"),onOpenScheduled:()=>T("scheduled"),onOpenUpdate:oe?()=>T("update"):void 0}),[z,T,x,oe]),ye=f.useCallback(U=>{w(),i(!1),U==="file"&&X()},[w,X]),ke=f.useCallback(()=>{const U="new-mcp-server";let he=U,Ie=1;for(;R.some(Ne=>Ne.name===he);)he=`${U}-${Ie}`,Ie+=1;S({name:he,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:"",oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1}),C(he),E("mcp"),z("page-content")},[R,z,S,C,E]);return t.jsx(Zl,{actions:le,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[j?t.jsxs("aside",{ref:W.asideRef,className:Q("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!F&&"border-r-0"),style:{width:F?W.width:0,minWidth:F?W.width:0,maxWidth:F?W.width:0,"--oc-ipad-sidebar-width":`${W.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:W.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!F,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:Q("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",W.isResizing&&"pointer-events-none",!F&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Ge,{children:t.jsx(ji,{open:!0,variant:"sidebar",onOpenChange:U=>{!U&&!P&&L(!1)},footer:xe})})}),F?t.jsx(Ti,{side:"left",isResizing:W.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:W.handleProps}):null]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(Gd,{onOpenSessions:()=>j?q():i(!0),onOpenWorkspace:()=>m(!0),compactTitle:j}),t.jsxs("main",{ref:ee,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[t.jsx("div",{className:"h-full w-full",children:t.jsx(Ge,{children:t.jsx(Xc,{})})}),t.jsx(Ge,{children:t.jsx(Qc,{})})]})]}),j?null:t.jsx(ji,{open:s,onOpenChange:i,footer:xe}),t.jsxs("aside",{ref:Z.asideRef,className:Q("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!ae&&"border-l-0"),style:{width:ae,minWidth:ae,maxWidth:ae,"--oc-ipad-sidebar-width":`${Z.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:Z.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!ae,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:Q("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",Z.isResizing&&"pointer-events-none",!ae&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Ge,{children:t.jsx(om,{open:l,onClose:M,tab:a,onTabChange:u,pendingChangesDiff:k,onOpenPlan:g,onOpenMcpSettings:ke,variant:fe?"panel":"drawer"})})}),ae?t.jsx(Ti,{side:"right",isResizing:Z.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:Z.handleProps}):null]}),p?t.jsx(Tt,{open:!0,variant:ue,onClose:()=>g(null),ariaLabel:p.title,title:p.title,children:t.jsx(Ge,{children:t.jsx(ru,{savedProjectPlan:{projectRef:p.projectRef,planId:p.id},onNavigatedToChat:()=>{w(),M()}})})}):null,o==="instances"&&x?t.jsx(Tt,{open:!0,variant:ue,dialogAlign:"app",onClose:w,ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(Yd,{onConnect:w,onActiveConnectionDeleted:n})}):null,o==="settings"?t.jsx(Tt,{open:!0,variant:ue,dialogAlign:"app",onClose:w,ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Ge,{children:t.jsx(su,{forceMobile:!0,isWindowed:!0,initialMobileStage:h,registerBackHandler:ie,visiblePageSlugs:[...Tm],onClose:w})})}):null,o==="usage"?t.jsx(Tt,{open:!0,variant:ue,dialogAlign:"app",onClose:w,ariaLabel:e("usageStats.title"),title:e("usageStats.title"),children:t.jsx(Ge,{children:t.jsx(Zc,{})})}):null,o==="scheduled"?t.jsx(Tt,{open:!0,variant:ue,dialogAlign:"app",onClose:w,ariaLabel:e("sessions.scheduledTasks.dialog.title"),title:e("sessions.scheduledTasks.dialog.title"),children:t.jsx(Ge,{children:t.jsx(eu,{layout:"mobile",onLeave:ye})})}):null,o==="update"?t.jsx(Tt,{open:!0,variant:ue,dialogAlign:"app",onClose:w,ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Ge,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(nu,{initialUpdateDialogOpen:!0})})})}):null]})})};function Mi({apis:n}){const e=Oe(B=>B.isolatedSpacesEnabled),{t:s}=ge(),i=it(B=>B.initializeApp),r=it(B=>B.isInitialized),o=it(B=>B.isConnected),c=it(B=>B.connectionPhase),l=it(B=>B.providers.length),m=it(B=>B.agents.length),a=it(B=>B.loadProviders),u=it(B=>B.loadAgents),p=Nt(B=>B.currentDirectory),g=_e(B=>B.error),h=_e(B=>B.clearError),b=Oe(B=>B.setIsMobile),k=Il(B=>B.refreshStatus),y=Al(B=>B.refreshStatus),E=Pl(B=>B.setPlanModeEnabled),v=Ze(B=>B.projects),N=ss(B=>B.activeSessions),A=ss(B=>B.archivedSessions),x=ss(B=>B.status==="ready"),R=f.useMemo(()=>[...N,...A],[N,A]);Mc({hasAuthoritativeGlobalSessions:x,sessions:R});const[S,C]=f.useState(0),[w,T]=f.useState(0),[M,z]=f.useState(!1),[j,P]=f.useState("pending"),[V,I]=f.useState(null),D=f.useMemo(()=>ws(),[]),[,F]=f.useReducer(B=>B+1,0),L=f.useMemo(()=>Hn(),[]),q=f.useRef(0),X=f.useRef(0),Y=f.useCallback(()=>{const B=pt(),ee=X.current+1;if(X.current=ee,!B){gs("resume:auto-connect",{}),bs();return}gs("resume:reprobe",{});const ne=()=>{i(),k(n.github,{force:!0}),y(n.linear,{force:!0}),l===0&&a({source:"mobileApp:nativeResume"}),m===0&&u({source:"mobileApp:nativeResume"})},ie=oe=>{gs("resume:disconnect",{reason:oe}),Qt({apiBaseUrl:"",clientToken:null,runtimeKey:Ws}),C(ue=>ue+1)};Hs().then(oe=>{if(X.current===ee){if(oe==="no-connection"){ie("no-connection");return}if(oe==="needs-login"){I({kind:"auth-expired",label:ws()??""}),ie("needs-login");return}if(oe==="unreachable"){const ue=[4e3,1e4],xe=ye=>{window.setTimeout(()=>{if(X.current!==ee)return;const ke=ye===ue.length-1;Hs({fast:!ke}).then(U=>{if(X.current===ee&&U!=="switched"){if(U==="unchanged"){ne();return}if(U==="needs-login"){I({kind:"auth-expired",label:ws()??""}),ie("retry-needs-login");return}if(!ke){xe(ye+1);return}ie(`retry-${U}`)}})},ue[ye])};xe(0);return}oe!=="switched"&&ne()}});const H=Date.now();H-q.current>=Dm&&(q.current=H,window.dispatchEvent(new Event("openchamber:system-resume")))},[m,n.github,n.linear,i,u,a,l,k,y]);Tl(),Dl(Y),f.useEffect(()=>{if(!L)return;let B;const ee=()=>{window.clearTimeout(B),B=window.setTimeout(()=>Y(),1500)};return window.addEventListener("online",ee),()=>{window.removeEventListener("online",ee),window.clearTimeout(B)}},[L,Y]),f.useEffect(()=>{if(L)return Kr.subscribe((B,ee)=>{B.state==="expired"&&ee.state!=="expired"&&(Y(),Kr.getState().markAuthenticated())})},[L,Y]),f.useEffect(()=>(qr(n),()=>qr(null)),[n]),f.useEffect(()=>Bi(B=>{if(gs("endpoint:changed",{runtimeKey:B.runtimeKey||"none",previousRuntimeKey:B.previousRuntimeKey||"none",connected:!!B.apiBaseUrl}),!!B.runtimeKey&&B.runtimeKey===B.previousRuntimeKey){zc(),F();return}Oc(B),T(ne=>ne+1),C(ne=>ne+1)}),[]),f.useEffect(()=>{if(!L||o||pt()){P("done");return}let B=!1;return P("attempting"),(async()=>{const ee=await bs().catch(()=>({status:"no-candidate"}));B||(ee.status==="unreachable"?I({kind:"unreachable",label:ee.label}):ee.status==="needs-login"&&I({kind:"auth-expired",label:ee.label}),P("done"),ee.status==="unreachable"&&bs({fast:!1,skipIfConnected:!0}).catch(()=>null))})(),()=>{B=!0}},[]),f.useEffect(()=>{if(!L||!pt())return;let B=!1;const ee=ne=>{gs("cold-launch:drop",{kind:ne?.kind??"unknown"}),ne&&I(ne),Qt({apiBaseUrl:"",clientToken:null,runtimeKey:Ws}),C(ie=>ie+1)};return Hs().then(async ne=>{if(B||ne==="switched"||ne==="unchanged")return;const ie=ws();if(ne==="needs-login"){ee({kind:"auth-expired",label:ie??""});return}if(ne==="unreachable"){ee(ie?{kind:"unreachable",label:ie}:null),bs({fast:!1,skipIfConnected:!0}).catch(()=>null);return}const H=await bs().catch(()=>({status:"no-candidate"}));B||H.status==="connected"||(H.status==="needs-login"?ee({kind:"auth-expired",label:H.label}):H.status==="unreachable"?ee({kind:"unreachable",label:H.label}):ee(null))}),()=>{B=!0}},[]),f.useEffect(()=>{b(!0)},[b]),f.useEffect(()=>{L&&!pt()||i()},[S,i,L]),f.useEffect(()=>{o&&(l===0&&a({source:"mobileApp:recovery"}),m===0&&u({source:"mobileApp:recovery"}))},[m,o,u,a,l]);const W=f.useRef(!1),[Z,fe]=f.useState(L);f.useEffect(()=>{if(!L||!o||W.current)return;let B=!1;const ee=window.setTimeout(()=>fe(!1),6e3);return(async()=>{const ne=await Bc({refresh:!0});B||(ne!=="failed"&&(W.current=!0),fe(!1))})(),()=>{B=!0,window.clearTimeout(ee)}},[S,o,L]),f.useEffect(()=>{o&&Hr.setDirectory(p)},[p,o]),f.useEffect(()=>{o&&(k(n.github,{force:!0}),y(n.linear,{force:!0}))},[n.github,n.linear,o,k,y]),f.useEffect(()=>{if(!o||v.length===0)return;let B=!1;return(async()=>{const ne=new Map(_e.getState().availableWorktreesByProject);if(await Promise.all(v.map(async oe=>{const ue=oe.path.replace(/\\/g,"/").replace(/\/+$/,"");if(ue)try{if(!(Qe.getState().directories.get(ue)?.isGitRepo??await os(()=>import("./useAppFontEffects-CeMgbeVa.js").then(U=>U.mD),__vite__mapDeps([9,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(U=>U.checkIsGitRepository(ue))))return;const ke=await so({id:oe.id,path:ue});if(B)return;ne.set(ue,ke)}catch{}})),B)return;const ie=no(v,ne),H=_e.getState().availableWorktreesByProject;Kl(ie,H)||_e.setState({availableWorktrees:[...ie.values()].flat(),availableWorktreesByProject:ie})})(),()=>{B=!0}},[o,v]),f.useEffect(()=>{if(!o)return;let B=!1;const ee=io(ne=>{ne.type==="worktree-changed"&&ql(v,ne.directories,()=>B)});return()=>{B=!0,ee()}},[o,v]),f.useEffect(()=>{let B=!1;return(async()=>{const ne=await Fn("/health",{method:"GET"}).catch(()=>null);if(!ne||!ne.ok||B)return;const ie=await ne.json().catch(()=>null);if(!ie||B)return;const H=ie.planModeExperimentalEnabled;E(H===!0||H===1||H==="1"||H==="true")})(),()=>{B=!0}},[E]),f.useEffect(()=>{if(!g)return;const B=window.setTimeout(()=>h(),5e3);return()=>window.clearTimeout(B)},[h,g]),f.useEffect(()=>{if(!(!o&&(L?!!pt():!0))){z(!1);return}const ee=window.setTimeout(()=>{z(!0)},L?4e3:8e3);return()=>window.clearTimeout(ee)},[o,L,S,w]),_l(),Ml({enabled:!0}),Lc(),zl(),Ol(),$c(),Fc(),Rm({enabled:L&&o}),Sm({ready:L&&o&&r});const ae=dm(),te=!o&&c==="reconnecting";if(!ae)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:t.jsx(Zt,{width:120,height:120,isAnimated:!0,variant:"splash"})});const le=!!pt();return L&&(!le||!o&&!te)?le?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(Zt,{width:120,height:120,isAnimated:!M,variant:"splash"}),M?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:s("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:s("mobile.connect.recovery.description")})]}),t.jsx(Se,{type:"button",variant:"outline",onClick:()=>{Qt({apiBaseUrl:"",clientToken:null,runtimeKey:Ws}),C(B=>B+1)},children:s("mobile.connect.cancelPassword")})]}):null]})}):j!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:[t.jsx(Zt,{width:120,height:120,isAnimated:!0,variant:"splash"}),D?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:s("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[D,t.jsx(Bl,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(Id,{onConnected:()=>C(B=>B+1),notice:V})}):!o&&!te?M?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:s("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:s("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:t.jsx(Zt,{width:120,height:120,isAnimated:!0,variant:"splash"})}):t.jsx(Ge,{children:t.jsx(Ll,{sdk:Hr.getSdkClient(),directory:p||"",children:t.jsx($l,{apis:n,children:t.jsx(Fl,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(Wc,{ready:!L||!Z,animated:!0}),t.jsx(Wl,{embeddedBackgroundWorkEnabled:r}),t.jsx(Vc,{}),t.jsx(Uu,{}),t.jsx(_m,{onActiveConnectionDeleted:()=>{Qt({apiBaseUrl:"",clientToken:null,runtimeKey:Ws}),C(B=>B+1)}}),t.jsx(Vl,{}),t.jsx(Ul,{}),e?t.jsxs(t.Fragment,{children:[t.jsx(Uc,{}),t.jsx(Gc,{}),t.jsx(Kc,{}),t.jsx(qc,{}),t.jsx(Hc,{})]}):null,t.jsx(Gl,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),r?t.jsx(Jc,{}):null]})})})},w)})}function Mm(n){const e=de.c(4),s=f.useSyncExternalStore(zm,pt,pt);if(Hn()&&!s){let r;return e[0]!==n?(r=t.jsx(Mi,{...n}),e[0]=n,e[1]=r):r=e[1],r}let i;return e[2]!==n?(i=t.jsx(_c,{children:t.jsx(Mi,{...n})}),e[2]=n,e[3]=i):i=e[3],i}function zm(n){return Bi(()=>n())}const Om=()=>{oc(),Na().then(()=>{Promise.all([Ca(),ac()]).catch(n=>{console.error("[mobile-main] settings init failed:",n)}),lc(),cc(),uc()}).catch(n=>{console.error("[mobile-main] appearance init failed:",n)}).finally(()=>{zu()})};function yg(n){window.__OPENCHAMBER_SURFACE__="mobile",ec(),Om(),Vu(),tc();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const i=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",r=i?{...n,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:n,o=t.jsx(Mm,{apis:r});ha.createRoot(e).render(t.jsx(Pn.StrictMode,{children:t.jsx(sc,{children:t.jsx(nc,{children:t.jsx(rc,{children:t.jsx(tu,{children:i?o:t.jsx(ic,{children:o})})})})})}))}export{yg as renderMobileApp};