@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,30 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-capacitor-core-B4EWRrHz.js"])))=>i.map(i=>d[i]);
2
+ import{R as l,j as s,f as _e,r as at}from"./vendor-react-BUCujlKS.js";import{f as Be,B as V,I as B,o as _s,bu as qn,t as U,O as ju,hV as ku,el as He,hW as Pt,g as Va,eM as Zc,b as hn,T as ba,h as Se,aE as wu,hX as Ko,hY as Su,cu as Jt,ct as Tt,cw as gt,cv as Et,cs as Dt,a1 as Ge,eT as Hn,hZ as Xc,h_ as Nu,ae as po,h$ as fi,i0 as va,cj as Ds,cd as _t,ce as $t,cf as Vt,cg as Ht,ch as qt,ci as as,i1 as Rr,aF as Gn,bs as xn,aD as Wn,aC as Jn,i2 as mr,i3 as Pn,an as Un,am as pn,fb as Gt,i4 as Xs,i5 as Or,i6 as ls,l as ct,i7 as hi,fs as _n,i8 as ed,fp as Ct,fm as Qt,i9 as Kt,cx as Rs,eV as ga,fo as Zs,fq as fn,ia as hs,gK as js,ib as ws,d3 as xt,ic as td,id as Cu,ie as Iu,ig as yi,ih as Pu,ii as rs,f5 as Es,ij as Js,h5 as Ja,hc as rn,ik as Ha,il as sd,im as Lr,eX as Fr,ar as fa,io as pr,af as sa,ip as gl,iq as Au,ir as fl,is as An,it as zt,fE as Kr,iu as zr,iv as la,iw as nd,ix as zn,cG as go,iy as hl,aI as Tu,cy as Eu,de as Du,U as Mu,V as Ru,W as Ou,a4 as Ur,iz as Lu,iA as Fu,cp as Ku,cz as gr,iB as ad,eZ as es,P as $n,iC as fr,iD as Ms,fr as id,iE as zu,n as ds,ez as so,y as od,x as Uu,i as _u,j as $u,eA as Bu,p as Vu,iF as Hu,iG as qu,iH as xl,gF as rd,iI as Gu,iJ as zo,iK as bl,iL as Wu,iM as Ju,iN as Qu,iO as Yu,iP as no,iQ as ys,iR as Cs,dv as ld,c8 as cd,dw as dd,c9 as Ks,iS as gn,iT as _r,aT as ta,aU as Fa,iU as ud,iV as Zu,iW as Qa,aK as Xu,iX as Fn,fn as em,eY as md,iY as pd,f4 as tm,f3 as sm,eK as nm,iZ as ca,i_ as zs,i$ as Qs,gY as da,j0 as Is,j1 as am,j2 as vl,j3 as gd,j4 as ua,j5 as im,j6 as om,R as fd,df as rm,dk as lm,dl as cm,cR as dm,e_ as um,dm as mm,dc as pm,bA as gm,j7 as fm,j8 as na,j9 as hm,ja as $r,fl as Ka,jb as yl,jc as za,jd as Ua,ca as xa,je as xm,jf as bm,jg as vm,jh as ym,ji as Uo,jj as jl,jk as jm,jl as km,jm as wm,jn as Sm,jo as kl,jp as Nm,z as Cm,m as wl,eU as Im,jq as Pm,jr as _o,ao as hd,ap as xd,aq as Am,eE as Tm,js as fo,jt as Em,ju as Dm,jv as Mm,jw as Rm,jx as Om,jy as $o,d4 as Lm,cb as bd,aL as Xn,aM as Fm}from"./useAppFontEffects-CeMgbeVa.js";import{h as It,i as Br,u as re,R as ms,ed as Km,ee as Sl,bk as zm,z as kt,aP as En,F as Ts,a as ln,J as us,U as Nl,d9 as Cl,dg as Il,Z as ai,p as Um,ef as _m,k as $m,d8 as $a,eg as Bm,aw as Vm,dd as Hm,eh as qm,ei as Gm,s as Wm,e as ki,de as Jm,K as wi,ej as vd,aO as os,a3 as Qm,ek as Ym,am as yd,el as jd,bv as kd,B as qa,bo as wd,aq as Zm,ar as Xm,b2 as Vr,em as ep,C as ho,a2 as tp,v as Pl,ba as Al,bz as zi,bb as sp,en as np,al as ha,eo as ap,ep as Tl,ec as El,eq as Dl,b8 as Ml,er as ip,es as op,et as rp,eu as lp,ev as Rl,b as cp,ew as dp,ex as up,ey as mp,ez as pp,eA as gp,eB as fp,aI as hp}from"./index-Btd2mmYT.js";import{u as xp,ag as Ol,aS as bp,aT as vp,aU as yp,al as Ya,an as Za,ao as Xa,ap as ei,av as ya,w as Hr,ah as bn,aj as vn,ai as yn,aV as ma,az as jp,_ as As,aW as hr,aX as kp,aO as wp,au as Sp,aY as xr,aZ as Ba,a_ as br,aw as Np,ax as Cp,ay as Ip}from"./runtimeEndpointReset-Cu6RUve4.js";import{u as $s,c as Pp}from"./vendor-zustand-BAGL70zf.js";import{o as Os,s as Rt,b as qr,l as Ap,r as Bn,c as vr,a as ja,_ as Gr,u as yr}from"./vendor-zod-CxRSdNoV.js";import{s as Tp,p as Ep}from"./vendor-yaml-3778uTud.js";import{c as Ll,s as Dp,C as Fl,P as Mp}from"./shikiHighlight-CcVzlYit.js";import{getResolvedShikiTheme as Rp}from"./appThemeRegistry-DU-UKEHq.js";import{E as Kl}from"./vendor-codemirror-view-8PpN-8l4.js";import{Q as Sd}from"./vendor-qrcode-DTJ12-WC.js";import{u as Bo,s as Op,d as Lp,b as Fp,A as Kp,c as zp,e as Up,f as _p,h as $p,i as xi,j as Bp}from"./PluginPane-rZvoMQSi.js";import{toast as Ga}from"./vendor-sonner-DFyL3AvE.js";import{s as Vp}from"./vendor-strip-json-comments-5dJlOkP1.js";import{Y as Hp,U as qp,X as Gp,W as Wp,V as Jp}from"./vendor-base-ui-DWgyZK2k.js";import{_ as Qp}from"./vendor-vite-runtime-DD1OZmLC.js";const zl=()=>{const{t}=Be(),[e,a]=l.useState(null);l.useEffect(()=>{let i=!1;const o=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const d=await It("/api/system/info",{signal:o?.signal,headers:{Accept:"application/json"}});if(!d.ok)return;const c=await d.json().catch(()=>null);if(!c||i)return;const g=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,p=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:g,tunnelUrl:p})}catch{}})(),()=>{i=!0,o?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(i=>s.jsxs(V,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{_s(i.url)},children:[s.jsx(B,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:i.url})]},i.key))})},Ul="https://github.com/openchamber/openchamber",Yp="https://discord.gg/ZYRSdnwwKA",_l="https://x.com/openchamber_dev",Zp=800,Xp={info:null,checking:!1,available:!1,error:null};function eg(t){const e=_e.c(5),[a,n]=l.useState(Xp);let i;e[0]!==t?(i=async()=>{if(t){n(tg);try{const d=await bp();n({info:d,checking:!1,available:d.available,error:null})}catch(d){const c=d;n({info:null,checking:!1,available:!1,error:c instanceof Error?c.message:String(c)})}}},e[0]=t,e[1]=i):i=e[1];const o=i;let r;return e[2]!==o||e[3]!==a?(r={...a,check:o},e[2]=o,e[3]=a,e[4]=r):r=e[4],r}function tg(t){return{...t,checking:!0,error:null}}function sg(t){const e=_e.c(11),[a,n]=l.useState(null);let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={kind:"idle"},e[0]=i):i=e[0];const[o,r]=l.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=async()=>{try{const b=await vp();return n(b),b}catch{return null}},e[1]=d):d=e[1];const c=d;let g,p;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{c()},p=[c],e[2]=g,e[3]=p):(g=e[2],p=e[3]),l.useEffect(g,p);let h;e[4]!==t?(h=async()=>{r({kind:"upgrading"});try{const b=await yp(t);r({kind:"installed",version:b})}catch(b){const k=b;r({kind:"failed",error:k instanceof Error?k.message:t})}},e[4]=t,e[5]=h):h=e[5];const f=h;let m;e[6]===Symbol.for("react.memo_cache_sentinel")?(m=async b=>{await b().catch(ng);const k=await c();k?.currentVersion&&r(u=>u.kind!=="installed"||u.version&&u.version.replace(/^v/,"")!==k.currentVersion?u:{kind:"idle"})},e[6]=m):m=e[6];const v=m;let C;return e[7]!==o||e[8]!==a||e[9]!==f?(C={status:a,phase:o,refresh:c,upgrade:f,reloadAfterUpgrade:v},e[7]=o,e[8]=a,e[9]=f,e[10]=C):C=e[10],C}function ng(){}function ag(t){const[e,a]=l.useState(null);return l.useEffect(()=>{if(!t)return;let n=!1;return Qp(async()=>{const{App:i}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:i}},__vite__mapDeps([0,1,2])).then(({App:i})=>i.getInfo()).then(i=>{n||a(i.version.trim()||null)}).catch(()=>{}),()=>{n=!0}},[t]),e}const Nd=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=Be(),[a,n]=l.useState(t),[i,o]=l.useState(!1),[r,d]=l.useState(null),c=xp($s(O=>({info:O.info,checking:O.checking,available:O.available,error:O.error,downloading:O.downloading,downloaded:O.downloaded,progress:O.progress,runtimeType:O.runtimeType,checkForUpdates:O.checkForUpdates,downloadUpdate:O.downloadUpdate,restartToUpdate:O.restartToUpdate}))),{isMobile:g}=qn(),p=l.useMemo(()=>Br(),[]),h=eg(p),f=ag(p),m=p?{info:h.info,checking:h.checking,available:h.available,error:h.error,checkForUpdates:h.check,runtimeType:"web"}:{info:c.info,checking:c.checking,available:c.available,error:c.error,checkForUpdates:c.checkForUpdates,runtimeType:c.runtimeType},v=r||m.info?.currentVersion||"unknown",C=sg(e("opencodeUpdate.toast.failed.description")),b=C.status?.currentVersion??null,k=C.phase.kind==="installed"?null:C.status?.availableVersion??null,[u,j]=l.useState(!1),N=(()=>{const O=m.info?.version||"";return p?m.info?.packageManager==="electron"?e("settings.openchamber.about.actions.updateDesktopToVersion",{version:O}):e("settings.openchamber.about.actions.updateServerToVersion",{version:O}):e("settings.openchamber.about.actions.updateOpenChamberToVersion",{version:O})})(),w=m.available&&m.info?.installBlocked==="service-manager",S=m.info?.updateCommand||"openchamber update",A=()=>{m.checkForUpdates(),C.refresh()},x=async()=>{(await Va(S)).ok&&(j(!0),setTimeout(()=>j(!1),2e3))},E=()=>{C.reloadAfterUpgrade(async()=>{await Zc({message:e("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})})},M=w?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.serviceManagerUpdate",{version:m.info?.version||""})}),s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-surface-elevated/50 p-1 pl-3",children:[s.jsx("code",{className:"flex-1 overflow-x-auto whitespace-nowrap font-mono text-sm text-foreground",children:S}),s.jsx(V,{type:"button",variant:"ghost",size:"icon",onClick:()=>{x()},"aria-label":e(u?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:s.jsx(B,{name:u?"check":"clipboard",className:"size-4"})})]})]}):null,T=(()=>{const{phase:O}=C;if(O.kind==="installed")return s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:O.version?e("settings.openchamber.about.openCode.installedVersion",{version:O.version}):e("settings.openchamber.about.openCode.installed")}),s.jsx(V,{type:"button",size:"sm",variant:"outline",onClick:E,children:e("opencodeUpdate.toast.actions.reload")})]});if(!k)return null;if(!C.status?.supported)return s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.openCode.manualUpdate",{version:k})});const I=O.kind==="upgrading";return s.jsxs("div",{className:"space-y-2",children:[s.jsxs(V,{type:"button",size:"sm",variant:"outline",onClick:()=>{C.upgrade()},disabled:I,children:[s.jsx(B,{name:I?"loader":"download",className:I?"size-4 animate-spin":"size-4"}),I?e("opencodeUpdate.toast.upgrading.title"):e("settings.openchamber.about.actions.updateOpenCodeToVersion",{version:k})]}),O.kind==="failed"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:O.error})]})})();l.useEffect(()=>{let O=!1;return(async()=>{try{const y=await It("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!y.ok)return;const L=await y.json().catch(()=>null),K=typeof L?.openchamberVersion=="string"&&L.openchamberVersion.trim().length>0?L.openchamberVersion.trim():null;O||d(K)}catch{O||d(null)}})(),()=>{O=!0}},[]);const D=l.useRef(!1);l.useEffect(()=>{if(m.checking)o(!0),D.current=!0;else if(i){const O=setTimeout(()=>{o(!1),D.current&&!m.available&&!m.error&&(U.success(e(p?"settings.openchamber.about.toast.serverLatestVersion":"settings.openchamber.about.toast.latestVersion")),D.current=!1)},Zp);return()=>clearTimeout(O)}},[e,p,m.checking,i,m.available,m.error]);const R=m.checking||i;return g?s.jsxs("div",{className:"w-full space-y-6 pb-2",children:[s.jsxs("div",{className:"flex flex-col items-center text-center",children:[s.jsx(ju,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${ku}`,children:"OpenChamber"}),s.jsx("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:p?s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenChamberVersion",{version:v})}),s.jsx("p",{children:e("settings.openchamber.about.native.serverOpenCodeVersion",{version:b||e("settings.openchamber.about.state.unknown")})}),f&&s.jsx("p",{children:e("settings.openchamber.about.native.appVersion",{version:f})})]}):s.jsxs(s.Fragment,{children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:v})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:b||e("settings.openchamber.about.state.unknown")})})]})}),s.jsx(zl,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&s.jsxs(V,{type:"button",variant:"outline",size:"sm",onClick:A,disabled:R,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[R?s.jsx(B,{name:"loader",className:"size-4 animate-spin"}):s.jsx(B,{name:"refresh",className:"size-4"}),e(R?"settings.openchamber.about.state.checking":p?"settings.openchamber.about.actions.checkServerForUpdates":"settings.openchamber.about.actions.checkForUpdates")]}),!R&&m.available&&!w&&s.jsxs(V,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(B,{name:"download",className:"size-4"}),N]})]}),M,T&&s.jsx("div",{className:"flex justify-center text-center",children:T}),m.error&&s.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:m.error}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:Ul,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(B,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Yp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(B,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:_l,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(B,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(Ol,{open:a,onOpenChange:n,info:m.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:m.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:m.runtimeType})]}):s.jsxs(He,{divider:!1,children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center justify-between gap-4 px-4 py-3 border-b border-border/40",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Pt,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:v})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Pt,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:b||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(B,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&!w&&s.jsxs(V,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(B,{name:"download",className:"h-4 w-4 mr-1"}),N]}),!m.checking&&!m.available&&!m.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(V,{size:"sm",variant:"outline",onClick:A,disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),M&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:M}),T&&s.jsx("div",{className:"px-4 py-3 border-b border-border/40",children:T}),m.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Pt,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(zl,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Ul,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(B,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:_l,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(B,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(Ol,{open:a,onOpenChange:n,info:m.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:m.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:m.runtimeType})]})},ig=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,en=()=>{const t=_e.c(4),e=re(og),a=hn(rg),n=hn(lg);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=ig(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function og(t){return t.settingsProjectPath}function rg(t){return t.projects}function lg(t){return t.activeProjectId}const cg=t=>[...t].sort((e,a)=>(e.label||e.path).localeCompare(a.label||a.path)),Si=t=>{const e=_e.c(75),{className:a}=t,{t:n}=Be(),{currentTheme:i}=ba(),o=re(dg),[r,d]=l.useState(!1),c=hn(ug),g=en(),p=re(mg),h=ms();let f;e[0]!==c?(f=cg(c),e[0]=c,e[1]=f):f=e[1];const m=f;let v;e[2]!==g||e[3]!==m?(v=m.find(R=>R.path===g)??m[0]??null,e[2]=g,e[3]=m,e[4]=v):v=e[4];const C=v;if(h||!C)return null;let b;e[5]!==p||e[6]!==m?(b=R=>{const O=m.find(I=>I.id===R);O&&p(O.path)},e[5]=p,e[6]=m,e[7]=b):b=e[7];const k=b;if(o){let R;e[8]!==a?(R=Se(a),e[8]=a,e[9]=R):R=e[9];let O;e[10]!==n?(O=n("settings.shared.projectSelector.switchProjectAria"),e[10]=n,e[11]=O):O=e[11];let I;e[12]!==n?(I=n("settings.shared.projectSelector.switchProjectTitle"),e[12]=n,e[13]=I):I=e[13];let y,L;e[14]===Symbol.for("react.memo_cache_sentinel")?(y=()=>d(!0),L=Se(wu({size:"touch"}),"w-full min-w-0"),e[14]=y,e[15]=L):(y=e[14],L=e[15]);let K;e[16]!==C||e[17]!==i?(K=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:s.jsx(Ko,{project:C,theme:i})}),e[16]=C,e[17]=i,e[18]=K):K=e[18];let H;e[19]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(B,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[19]=H):H=e[19];let G;e[20]!==r||e[21]!==O||e[22]!==I||e[23]!==L||e[24]!==K?(G=s.jsxs("button",{type:"button","aria-label":O,title:I,"aria-haspopup":"dialog","aria-expanded":r,onClick:y,className:L,children:[K,H]}),e[20]=r,e[21]=O,e[22]=I,e[23]=L,e[24]=K,e[25]=G):G=e[25];let W;e[26]!==G||e[27]!==R?(W=s.jsx("div",{className:R,children:G}),e[26]=G,e[27]=R,e[28]=W):W=e[28];let q;e[29]===Symbol.for("react.memo_cache_sentinel")?(q=()=>d(!1),e[29]=q):q=e[29];const z=C.id;let $;e[30]!==n?($=n("settings.shared.projectSelector.sheetTitle"),e[30]=n,e[31]=$):$=e[31];let Z;e[32]!==n?(Z=n("settings.shared.projectSelector.searchPlaceholder"),e[32]=n,e[33]=Z):Z=e[33];let _;e[34]!==C.id||e[35]!==i||e[36]!==k||e[37]!==r||e[38]!==m||e[39]!==$||e[40]!==Z?(_=s.jsx(Su,{open:r,onClose:q,projects:m,selectedProjectId:z,onSelectProject:k,theme:i,title:$,searchPlaceholder:Z}),e[34]=C.id,e[35]=i,e[36]=k,e[37]=r,e[38]=m,e[39]=$,e[40]=Z,e[41]=_):_=e[41];let ne;return e[42]!==W||e[43]!==_?(ne=s.jsxs(s.Fragment,{children:[W,_]}),e[42]=W,e[43]=_,e[44]=ne):ne=e[44],ne}let u;e[45]!==a?(u=Se(a),e[45]=a,e[46]=u):u=e[46];const j=C.id;let N;e[47]!==k?(N=R=>{R&&k(R)},e[47]=k,e[48]=N):N=e[48];let w;e[49]!==n?(w=n("settings.shared.projectSelector.switchProjectAria"),e[49]=n,e[50]=w):w=e[50];let S;e[51]!==n?(S=n("settings.shared.projectSelector.switchProjectTitle"),e[51]=n,e[52]=S):S=e[52];let A;e[53]!==C||e[54]!==i?(A=s.jsx(Jt,{children:s.jsx(Ko,{project:C,theme:i})}),e[53]=C,e[54]=i,e[55]=A):A=e[55];let x;e[56]!==w||e[57]!==S||e[58]!==A?(x=s.jsx(Tt,{size:"settings",className:"w-full","aria-label":w,title:S,children:A}),e[56]=w,e[57]=S,e[58]=A,e[59]=x):x=e[59];let E;if(e[60]!==i||e[61]!==m){let R;e[63]!==i?(R=O=>s.jsx(gt,{value:O.id,className:"max-w-[24rem] truncate",children:s.jsx(Ko,{project:O,theme:i})},O.id),e[63]=i,e[64]=R):R=e[64],E=m.map(R),e[60]=i,e[61]=m,e[62]=E}else E=e[62];let M;e[65]!==E?(M=s.jsx(Et,{fitContent:!0,children:E}),e[65]=E,e[66]=M):M=e[66];let T;e[67]!==C.id||e[68]!==x||e[69]!==M||e[70]!==N?(T=s.jsxs(Dt,{value:j,onValueChange:N,children:[x,M]}),e[67]=C.id,e[68]=x,e[69]=M,e[70]=N,e[71]=T):T=e[71];let D;return e[72]!==T||e[73]!==u?(D=s.jsx("div",{className:u,children:T}),e[72]=T,e[73]=u,e[74]=D):D=e[74],D};function dg(t){return t.isMobile}function ug(t){return t.projects}function mg(t){return t.setSettingsProjectPath}const Wr=t=>{const e=_e.c(16),{value:a,onChange:n}=t,{t:i}=Be();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(B,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground","aria-hidden":!0}),e[0]=o):o=e[0];let r;e[1]!==n?(r=h=>n(h.target.value),e[1]=n,e[2]=r):r=e[2];let d;e[3]!==n||e[4]!==a?(d=h=>{h.key==="Escape"&&a&&(h.preventDefault(),h.stopPropagation(),n(""))},e[3]=n,e[4]=a,e[5]=d):d=e[5];let c;e[6]!==i?(c=i("settings.common.sidebar.searchPlaceholder"),e[6]=i,e[7]=c):c=e[7];let g;e[8]!==i?(g=i("settings.common.sidebar.searchPlaceholder"),e[8]=i,e[9]=g):g=e[9];let p;return e[10]!==r||e[11]!==d||e[12]!==c||e[13]!==g||e[14]!==a?(p=s.jsxs("div",{className:"relative mt-3",children:[o,s.jsx(Ge,{value:a,onChange:r,onKeyDown:d,placeholder:c,"aria-label":g,className:"h-8 pl-7 typography-meta"})]}),e[10]=r,e[11]=d,e[12]=c,e[13]=g,e[14]=a,e[15]=p):p=e[15],p},Jr=t=>{const e=_e.c(5),{query:a}=t,{t:n}=Be();let i;e[0]!==a||e[1]!==n?(i=n("settings.common.sidebar.noMatches",{query:a.trim()}),e[0]=a,e[1]=n,e[2]=i):i=e[2];let o;return e[3]!==i?(o=s.jsx("p",{className:"px-2 py-6 text-center typography-meta text-muted-foreground",children:i}),e[3]=i,e[4]=o):o=e[4],o};function pg(t,e){return`opencode:sidebar-group:${t}:${e}`}const jr=t=>{const e=_e.c(33),{label:a,count:n,storageKey:i,defaultExpanded:o,children:r}=t,d=o===void 0?!0:o;let c;e[0]!==a||e[1]!==i?(c=pg(i,a),e[0]=a,e[1]=i,e[2]=c):c=e[2];const g=c,p=l.useId();let h;e[3]!==d||e[4]!==g?(h=()=>{try{const T=localStorage.getItem(g);if(T!==null)return T==="true"}catch{}return d},e[3]=d,e[4]=g,e[5]=h):h=e[5];const[f,m]=at.useState(h);let v,C;e[6]!==f||e[7]!==g?(v=()=>{try{localStorage.setItem(g,String(f))}catch{}},C=[g,f],e[6]=f,e[7]=g,e[8]=v,e[9]=C):(v=e[8],C=e[9]),at.useEffect(v,C);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>m(gg),e[10]=b):b=e[10];let k;e[11]===Symbol.for("react.memo_cache_sentinel")?(k=Se("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),e[11]=k):k=e[11];const u=!f&&"-rotate-90";let j;e[12]!==u?(j=Se("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",u),e[12]=u,e[13]=j):j=e[13];let N;e[14]!==j?(N=s.jsx(B,{name:"arrow-down-s",className:j}),e[14]=j,e[15]=N):N=e[15];let w;e[16]!==a?(w=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=w):w=e[17];let S;e[18]!==n?(S=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=S):S=e[19];let A;e[20]!==p||e[21]!==f||e[22]!==N||e[23]!==w||e[24]!==S?(A=s.jsxs("button",{type:"button",onClick:b,"aria-expanded":f,"aria-controls":p,className:k,children:[N,w,S]}),e[20]=p,e[21]=f,e[22]=N,e[23]=w,e[24]=S,e[25]=A):A=e[25];const x=!f;let E;e[26]!==r||e[27]!==p||e[28]!==x?(E=s.jsx("div",{id:p,hidden:x,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:r}),e[26]=r,e[27]=p,e[28]=x,e[29]=E):E=e[29];let M;return e[30]!==A||e[31]!==E?(M=s.jsxs("div",{children:[A,E]}),e[30]=A,e[31]=E,e[32]=M):M=e[32],M};function gg(t){return!t}const fg=({onItemSelect:t})=>{const{t:e}=Be(),[a,n]=l.useState(""),[i,o]=l.useState(null),[r,d]=l.useState(""),[c,g]=l.useState(null),[p,h]=l.useState(!1),[f,m]=l.useState(null),{selectedAgentName:v,setSelectedAgent:C,setAgentDraft:b,createAgent:k,deleteAgent:u,loadAgents:j,fetchAgentEntity:N}=Hn($s(q=>({selectedAgentName:q.selectedAgentName,setSelectedAgent:q.setSelectedAgent,setAgentDraft:q.setAgentDraft,createAgent:q.createAgent,deleteAgent:q.deleteAgent,loadAgents:q.loadAgents,fetchAgentEntity:q.fetchAgentEntity}))),w=en(),S=Hn(q=>Xc(q,w));l.useEffect(()=>{j(w)},[j,w]);const A="bg-background",x=()=>{const q="new-agent";let z=q,$=1;for(;S.some(Z=>Z.name===z);)z=`${q}-${$}`,$++;b({name:z,scope:"user"}),C(z),t?.()},E=async q=>{if(fi(q)){U.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}g(q)},M=()=>{g(null)},T=async()=>{if(c){h(!0);try{(await u(c.name,c.scope,w)).ok?(U.success(e("settings.agents.sidebar.toast.agentDeleted",{name:c.name})),M()):U.error(e("settings.agents.sidebar.toast.deleteFailed"))}catch(q){const z=q instanceof Error?q.message:"",$=/built-in|not deletable|not found/i.test(z);U.error(e($?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed"))}h(!1)}},D=async q=>{const z=q.name;let $=1,Z=`${z}-copy`;for(;S.some(te=>te.name===Z);)$++,Z=`${z}-copy-${$}`;const _=q,ne=await N(q.name,w);if(!ne){U.error(e("settings.agents.sidebar.toast.renameFailed"));return}const X=ne.config.request?.body;b({name:Z,scope:ne.scope??_.scope??"user",description:ne.config.description??void 0,model:ne.config.model??null,system:ne.config.system??void 0,steps:ne.config.steps??void 0,temperature:X?.temperature,top_p:X?.top_p,mode:ne.config.mode??_.mode,permissions:ne.config.permissions??void 0}),C(Z),t?.()},R=q=>{d(q.name),o(q)},O=async()=>{if(!i)return;const q=r.trim().replace(/\s+/g,"-");if(!q){U.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(q===i.name){o(null);return}if(S.some(_=>_.name===q)){U.error(e("settings.agents.sidebar.toast.agentExists"));return}const z=i,$=await N(i.name,w);if(!$){U.error(e("settings.agents.sidebar.toast.renameFailed"));return}(await k({...$.config,name:q,scope:$.scope??z.scope},w)).ok?(await u(i.name,z.scope,w)).ok?(U.success(e("settings.agents.sidebar.toast.agentRenamed",{name:q})),C(q)):U.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):U.error(e("settings.agents.sidebar.toast.renameFailed")),o(null)},I=q=>{switch(q){case"primary":return s.jsx(B,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(B,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(B,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},y=S.filter(q=>!Nu(q)),L=y.filter(q=>po([q.name,q.description],a)),K=L.filter(fi),H=L.filter(q=>!fi(q)),{groupedCustomAgents:G,ungroupedCustomAgents:W}=at.useMemo(()=>{const q={},z=[];for(const Z of H){const _=Z;_.group?(q[_.group]||(q[_.group]=[]),q[_.group].push(Z)):z.push(Z)}return{groupedCustomAgents:Object.keys(q).sort((Z,_)=>Z.localeCompare(_)).map(Z=>({name:Z,agents:q[Z]})),ungroupedCustomAgents:z}},[H]);return s.jsxs("div",{className:Se("flex h-full flex-col",A),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${va} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Si,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:y.length})}),s.jsx(V,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:x,children:s.jsx(B,{name:"add",className:"h-3.5 w-3.5"})})]}),y.length>0?s.jsx(Wr,{value:a,onChange:n}):null]}),s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:y.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(B,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):L.length===0?s.jsx(Jr,{query:a}):s.jsxs(s.Fragment,{children:[K.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),K.map(q=>s.jsx(Vo,{agent:q,isSelected:v===q.name,onSelect:()=>{C(q.name),t?.()},onDuplicate:()=>{D(q)},getAgentModeIcon:I,isMenuOpen:f===q.name,onMenuOpenChange:z=>m(z?q.name:null)},q.name))]}),H.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),G.map(({name:q,agents:z})=>s.jsx(jr,{label:q,count:z.length,storageKey:"agents",children:z.map($=>s.jsx(Vo,{agent:$,isSelected:v===$.name,onSelect:()=>{C($.name),t?.()},onRename:()=>R($),onDelete:()=>E($),onDuplicate:()=>{D($)},getAgentModeIcon:I,isMenuOpen:f===$.name,onMenuOpenChange:Z=>m(Z?$.name:null)},$.name))},q)),W.map(q=>s.jsx(Vo,{agent:q,isSelected:v===q.name,onSelect:()=>{C(q.name),t?.()},onRename:()=>R(q),onDelete:()=>E(q),onDuplicate:()=>{D(q)},getAgentModeIcon:I,isMenuOpen:f===q.name,onMenuOpenChange:z=>m(z?q.name:null)},q.name))]})]})}),s.jsx(_t,{open:c!==null,onOpenChange:q=>{!q&&!p&&M()},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:e("settings.agents.sidebar.dialog.deleteTitle")}),s.jsx(qt,{children:e("settings.agents.sidebar.dialog.deleteDescription",{name:c?.name??""})})]}),s.jsxs(as,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:M,disabled:p,children:e("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:T,disabled:p,children:e("settings.common.actions.delete")})]})]})}),s.jsx(_t,{open:i!==null,onOpenChange:q=>!q&&o(null),children:s.jsxs($t,{children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(qt,{children:e("settings.agents.sidebar.renameDialog.description",{name:i?.name??""})})]}),s.jsx(Ge,{value:r,onChange:q=>d(q.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:q=>{q.key==="Enter"&&O()}}),s.jsxs(as,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>o(null),children:e("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:O,children:e("settings.common.actions.rename")})]})]})})]})},Vo=t=>{const e=_e.c(51),{agent:a,isSelected:n,onSelect:i,onDelete:o,onRename:r,onDuplicate:d,getAgentModeIcon:c,isMenuOpen:g,onMenuOpenChange:p}=t,{t:h}=Be(),f=a;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=Rr(),e[0]=m):m=e[0];const v=m,[C,b]=l.useState(!1);let k;e[1]!==o||e[2]!==d||e[3]!==r||e[4]!==h?(k=W=>s.jsxs(s.Fragment,{children:[r&&s.jsxs(W,{onClick:q=>{q.stopPropagation(),r()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),h("settings.common.actions.rename")]}),s.jsxs(W,{onClick:q=>{q.stopPropagation(),d()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),h("settings.common.actions.duplicate")]}),o&&s.jsxs(W,{onClick:q=>{q.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]})]}),e[1]=o,e[2]=d,e[3]=r,e[4]=h,e[5]=k):k=e[5];const u=k,j=n?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[6]!==j?(N=Se("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j),e[6]=j,e[7]=N):N=e[7];let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=v?void 0:W=>{W.preventDefault(),b(!0)},e[8]=w):w=e[8];let S;e[9]!==N?(S=s.jsx("div",{className:N,onContextMenu:w}),e[9]=N,e[10]=S):S=e[10];let A;e[11]!==a.name?(A=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[11]=a.name,e[12]=A):A=e[12];let x;e[13]!==a.mode||e[14]!==c?(x=c(a.mode),e[13]=a.mode,e[14]=c,e[15]=x):x=e[15];let E;e[16]!==a||e[17]!==f.scope||e[18]!==h?(E=(f.scope||fi(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:fi(a)?h("settings.agents.sidebar.badge.system"):f.scope}),e[16]=a,e[17]=f.scope,e[18]=h,e[19]=E):E=e[19];let M;e[20]!==A||e[21]!==x||e[22]!==E?(M=s.jsxs("div",{className:"flex items-center gap-1.5",children:[A,x,E]}),e[20]=A,e[21]=x,e[22]=E,e[23]=M):M=e[23];let T;e[24]!==a.description?(T=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[24]=a.description,e[25]=T):T=e[25];let D;e[26]!==i||e[27]!==M||e[28]!==T?(D=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[M,T]}),e[26]=i,e[27]=M,e[28]=T,e[29]=D):D=e[29];let R;e[30]!==p?(R=W=>{W&&b(!1),p(W)},e[30]=p,e[31]=R):R=e[31];let O;e[32]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(Wn,{asChild:!0,children:s.jsx(V,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=O):O=e[32];let I;e[33]!==u?(I=s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:u(xn)}),e[33]=u,e[34]=I):I=e[34];let y;e[35]!==g||e[36]!==R||e[37]!==I?(y=s.jsxs(Jn,{open:g,onOpenChange:R,children:[O,I]}),e[35]=g,e[36]=R,e[37]=I,e[38]=y):y=e[38];let L;e[39]!==D||e[40]!==y?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,y]}),e[39]=D,e[40]=y,e[41]=L):L=e[41];let K;e[42]!==L||e[43]!==S?(K=s.jsx(Xa,{render:S,children:L}),e[42]=L,e[43]=S,e[44]=K):K=e[44];let H;e[45]!==u?(H=s.jsx(Ya,{className:"w-fit min-w-20",children:u(Za)}),e[45]=u,e[46]=H):H=e[46];let G;return e[47]!==C||e[48]!==K||e[49]!==H?(G=s.jsxs(ei,{open:C,onOpenChange:b,children:[K,H]}),e[47]=C,e[48]=K,e[49]=H,e[50]=G):G=e[50],G},ns=t=>{const e=_e.c(22),{children:a,className:n,outerClassName:i,title:o,titleLeading:r,titleAccessory:d,description:c,headerEnd:g,showSaveStatus:p,onBlurCapture:h}=t,f=p===void 0?!1:p,m=o!=null||c!=null||g!=null||f,v=typeof o=="string"||typeof o=="number",C=r!=null||d!=null;let b;e[0]!==i?(b=Se("h-full overlay-scrollbar-wrapper--stable-gutter",i),e[0]=i,e[1]=b):b=e[1];let k;e[2]!==n?(k=Se("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=k):k=e[3];let u;e[4]!==c||e[5]!==m||e[6]!==C||e[7]!==g||e[8]!==v||e[9]!==f||e[10]!==o||e[11]!==d||e[12]!==r?(u=m&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[o!=null?v?C?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[r,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Se(mr,"min-w-0 truncate"),children:o}),s.jsx("span",{className:"shrink-0",children:d})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:mr,children:o}):o:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:Pn,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[g,f&&s.jsx(xg,{})]})]}),e[4]=c,e[5]=m,e[6]=C,e[7]=g,e[8]=v,e[9]=f,e[10]=o,e[11]=d,e[12]=r,e[13]=u):u=e[13];let j;e[14]!==a||e[15]!==h||e[16]!==k||e[17]!==u?(j=s.jsxs("div",{className:k,onBlurCapture:h,children:[u,a]}),e[14]=a,e[15]=h,e[16]=k,e[17]=u,e[18]=j):j=e[18];let N;return e[19]!==b||e[20]!==j?(N=s.jsx(Ds,{outerClassName:b,className:"w-full @container",children:j}),e[19]=b,e[20]=j,e[21]=N):N=e[21],N},hg=500,xg=()=>{const t=_e.c(13),{t:e}=Be(),a=l.useSyncExternalStore(Km,Sl,Sl),[n,i]=l.useState(!1);let o,r;if(t[0]!==a?(o=()=>{if(a!=="saving"){i(!1);return}const p=setTimeout(()=>i(!0),hg);return()=>clearTimeout(p)},r=[a],t[0]=a,t[1]=o,t[2]=r):(o=t[1],r=t[2]),l.useEffect(o,r),a==="error"){let p;t[3]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(B,{name:"error-warning",className:"size-3.5"}),t[3]=p):p=t[3];let h;t[4]!==e?(h=e("settings.common.status.saveFailed"),t[4]=e,t[5]=h):h=t[5];let f;return t[6]!==h?(f=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[p,s.jsx("span",{children:h})]}),t[6]=h,t[7]=f):f=t[7],f}if(a!=="saving"||!n)return null;let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=d):d=t[8];let c;t[9]!==e?(c=e("settings.common.actions.saving"),t[9]=e,t[10]=c):c=t[10];let g;return t[11]!==c?(g=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[d,s.jsx("span",{children:c})]}),t[11]=c,t[12]=g):g=t[12],g},Us={ok:!0,changed:!1},Tn={ok:!0,changed:!0},xs=t=>({ok:!1,reason:t}),bg=t=>t instanceof HTMLElement?t.matches('input, textarea, [contenteditable="true"]'):!1,ti=t=>{const{t:e}=Be(),[a,n]=l.useState(0),i=l.useRef(t);i.current=t;const o=l.useRef(e);o.current=e;const r=l.useRef(!1),d=l.useRef(!1),c=l.useRef(!1),g=l.useCallback(()=>{n(f=>f+1)},[]),p=l.useCallback(f=>{bg(f.target)&&g()},[g]),h=l.useCallback(async()=>{r.current=!0;try{for(;;){d.current=!1;let f;try{f=await i.current()}catch(m){f={ok:!1,reason:m instanceof Error?m.message:String(m)}}if(!c.current)return;if(!d.current){f.ok||U.error(o.current("settings.common.status.saveFailedReason",{reason:f.reason}));return}}}finally{r.current=!1}},[]);return l.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]),l.useEffect(()=>{if(a!==0){if(r.current){d.current=!0;return}h()}},[a,h]),{requestSave:g,onBlurCapture:p}},vg=["allow","ask","deny"],yg=["shell","edit","read","glob","grep","patch","webfetch","websearch","skill","subagent","question","external_directory"],jg=["openchamber","openchamber_web","openchamber_memory","openchamber_notify"],kg=new Set(["bash","task","write","list","lsp","todowrite","todoread","multiedit","doom_loop","plan_enter","plan_exit"]),Cd=t=>kg.has(t),wg=[{action:"*",resource:"*",effect:"allow"},{action:"external_directory",resource:"*",effect:"ask"},{action:"read",resource:"*.env",effect:"ask"},{action:"read",resource:"*.env.*",effect:"ask"},{action:"read",resource:"*.env.example",effect:"allow"}],$l=()=>({global:null,keys:{},source:[]}),oa=t=>({global:t.global,source:t.source,keys:Object.fromEntries(Object.entries(t.keys).map(([e,a])=>[e,{effect:a.effect,patterns:a.patterns.map(n=>({...n}))}]))}),Sg=t=>{const e={global:null,keys:{},source:t.map(a=>({...a}))};for(const a of t){if(Cd(a.action))continue;if(a.action==="*"){a.resource==="*"&&(e.global=a.effect);continue}const n=e.keys[a.action]??{effect:null,patterns:[]};if(a.resource==="*")n.effect=a.effect;else{const i=n.patterns.findIndex(o=>o.pattern===a.resource);i>=0?n.patterns[i]={pattern:a.resource,effect:a.effect}:n.patterns.push({pattern:a.resource,effect:a.effect})}e.keys[a.action]=n}return e},Ng=t=>t.action!=="*"||t.resource==="*",pa=(t,e)=>`${t}\0${e}`,Cg=t=>{const e=new Map;t.global!==null&&e.set(pa("*","*"),t.global);for(const[a,n]of Object.entries(t.keys)){n.effect!==null&&e.set(pa(a,"*"),n.effect);for(const i of n.patterns){const o=i.pattern.trim();o.length!==0&&e.set(pa(a,o),i.effect)}}return e},kr=t=>{const e=Cg(t),a=new Set,n=[];for(const o of t.source){if(Cd(o.action))continue;if(!Ng(o)){n.push({...o});continue}const r=pa(o.action,o.resource),d=e.get(r);d!==void 0&&(n.push({action:o.action,resource:o.resource,effect:d}),a.add(r))}const i=pa("*","*");t.global!==null&&!a.has(i)&&n.unshift({action:"*",resource:"*",effect:t.global});for(const[o,r]of Object.entries(t.keys)){const d=pa(o,"*");if(r.effect!==null&&!a.has(d)){const c=n.findIndex(p=>p.action===o),g={action:o,resource:"*",effect:r.effect};c>=0?n.splice(c,0,g):n.push(g)}for(const c of r.patterns){const g=c.pattern.trim();if(g.length===0)continue;const p=pa(o,g),h=e.get(p);h===void 0||a.has(p)||(a.add(p),n.push({action:o,resource:g,effect:h}))}}return n},Ig=(t,e)=>JSON.stringify(kr(t))===JSON.stringify(kr(e)),Pg=(t,e)=>{const a=[...wg,...e.global,...e.agentGlobal?[{action:"*",resource:"*",effect:e.agentGlobal}]:[]];let n="ask";for(const i of a)i.resource==="*"&&(i.action==="*"||i.action===t)&&(n=i.effect);return n},Ag=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Tg=new Set(["shell","edit","read","glob","grep","patch","webfetch","skill","subagent","external_directory"]),Eg={effect:null,patterns:[]},Dg=t=>{const e=_e.c(163),{agent:a,registerSave:n,requestSave:i}=t,{t:o}=Be(),r=Hn(Mg),d=Hn(Rg);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],e[0]=c):c=e[0];const[g,p]=l.useState(c),[h,f]=l.useState($l),[m,v]=l.useState($l),[C,b]=l.useState(!0),[k,u]=l.useState(!1);let j;e[1]===Symbol.for("react.memo_cache_sentinel")?(j={},e[1]=j):j=e[1];const[N,w]=l.useState(j),[S,A]=l.useState(""),[x,E]=l.useState(0),M=a.name,T=en(),D=Un(Og);let R;e[2]!==T?(R=ze=>Or(ze,T),e[2]=T,e[3]=R):R=e[3];const O=Un(R);let I;e[4]!==T?(I=ze=>ze.getStatusForDirectory(T),e[4]=T,e[5]=I):I=e[5];const y=pn(I);let L,K;e[6]!==D||e[7]!==T?(L=()=>{D({directory:T})},K=[D,T],e[6]=D,e[7]=T,e[8]=L,e[9]=K):(L=e[8],K=e[9]),l.useEffect(L,K);let H;e[10]!==M||e[11]!==d||e[12]!==T?(H=()=>{let ze=!1;return b(!0),u(!1),(async()=>{const Ze=await d(M,T);if(ze)return;if(!Ze){u(!0),b(!1);return}const tt=Sg(Ze.agent);p(Ze.global),f(oa(tt)),v(tt),w({}),b(!1)})(),()=>{ze=!0}},e[10]=M,e[11]=d,e[12]=T,e[13]=H):H=e[13];let G;e[14]!==M||e[15]!==d||e[16]!==x||e[17]!==T?(G=[M,d,x,T],e[14]=M,e[15]=d,e[16]=x,e[17]=T,e[18]=G):G=e[18],l.useEffect(H,G);let W;e[19]!==M||e[20]!==h||e[21]!==m||e[22]!==T||e[23]!==o||e[24]!==r?(W=async()=>Ig(m,h)?Us:(await r(M,{permissions:kr(m)},T)).ok?(f(oa(m)),Tn):xs(o("settings.agents.page.permissionsEditor.toast.saveFailed")),e[19]=M,e[20]=h,e[21]=m,e[22]=T,e[23]=o,e[24]=r,e[25]=W):W=e[25];const q=W;let z,$;e[26]!==n||e[27]!==q?(z=()=>(n(q),()=>n(null)),$=[n,q],e[26]=n,e[27]=q,e[28]=z,e[29]=$):(z=e[28],$=e[29]),l.useEffect(z,$);let Z;e[30]!==O?(Z=O.map(Lg),e[30]=O,e[31]=Z):Z=e[31];const _=Z;let ne;if(e[32]!==_||e[33]!==m.keys){ne=[...yg,...jg];const ze=new Set(_.map(Fg));let Ze;e[35]!==m.keys?(Ze=Object.keys(m.keys),e[35]=m.keys,e[36]=Ze):Ze=e[36];for(const tt of Ze)!ne.includes(tt)&&!ze.has(tt)&&ne.push(tt);e[32]=_,e[33]=m.keys,e[34]=ne}else ne=e[34];const X=ne;let te;e[37]!==y||e[38]!==o?(te=ze=>{switch(y?.[ze]?.status.status){case"connected":return o("settings.mcp.page.status.label.connected");case"failed":return o("settings.mcp.page.status.label.failed");case"needs_auth":return o("settings.mcp.page.status.label.needsAuth");case"disabled":return o("settings.agents.page.permissionsEditor.mcpStatus.disabled");case"pending":return o("settings.agents.page.permissionsEditor.mcpStatus.pending");default:return null}},e[37]=y,e[38]=o,e[39]=te):te=e[39];const he=te;let je;e[40]!==g||e[41]!==m.global?(je=ze=>Pg(ze,{global:g,agentGlobal:m.global}),e[40]=g,e[41]=m.global,e[42]=je):je=e[42];const fe=je;let ke;e[43]!==i?(ke=ze=>{v(Ze=>({...Ze,global:ze})),i()},e[43]=i,e[44]=ke):ke=e[44];const be=ke;let De;e[45]!==i?(De=(ze,Ze)=>{v(tt=>{const lt=oa(tt),Q=lt.keys[ze]??{effect:null,patterns:[]};return Q.effect=Ze,Q.effect===null&&Q.patterns.length===0?delete lt.keys[ze]:lt.keys[ze]=Q,lt}),i()},e[45]=i,e[46]=De):De=e[46];const oe=De;let ee;e[47]!==i?(ee=(ze,Ze,tt,lt,Q)=>{v(nt=>{const ot=oa(nt),it=ot.keys[ze]??{effect:null,patterns:[]};return it.patterns[Ze]={pattern:tt,effect:lt},ot.keys[ze]=it,ot}),Q&&i()},e[47]=i,e[48]=ee):ee=e[48];const ce=ee;let ue;e[49]===Symbol.for("react.memo_cache_sentinel")?(ue=ze=>{v(Ze=>{const tt=oa(Ze),lt=tt.keys[ze]??{effect:null,patterns:[]};return lt.patterns.push({pattern:"",effect:"allow"}),tt.keys[ze]=lt,tt}),w(Ze=>({...Ze,[ze]:!0}))},e[49]=ue):ue=e[49];const Ie=ue;let ve;e[50]!==i?(ve=(ze,Ze)=>{v(tt=>{const lt=oa(tt),Q=lt.keys[ze];return Q?(Q.patterns.splice(Ze,1),Q.effect===null&&Q.patterns.length===0&&delete lt.keys[ze],lt):tt}),i()},e[50]=i,e[51]=ve):ve=e[51];const Re=ve;let Me;e[52]!==S||e[53]!==i?(Me=()=>{const ze=S.trim();!ze||ze==="*"||(v(Ze=>{if(Ze.keys[ze])return Ze;const tt=oa(Ze);return tt.keys[ze]={effect:"ask",patterns:[]},tt}),A(""),i())},e[52]=S,e[53]=i,e[54]=Me):Me=e[54];const me=Me;let Te;e[55]!==o?(Te=ze=>o(ze==="allow"?"settings.agents.page.permissionsEditor.action.allow":ze==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),e[55]=o,e[56]=Te):Te=e[56];const Oe=Te;let pe,xe,ae,ie,ge,Ee,Ke,Le,Ne;if(e[57]!==Oe||e[58]!==fe||e[59]!==N||e[60]!==C||e[61]!==k||e[62]!==_||e[63]!==he||e[64]!==m.global||e[65]!==m.keys||e[66]!==Re||e[67]!==be||e[68]!==oe||e[69]!==ce||e[70]!==o||e[71]!==X){Ne=Symbol.for("react.early_return_sentinel");e:{const ze=o("settings.agents.page.permissionsEditor.action.inherit"),Ze=o("settings.agents.page.permissionsEditor.action.default");let tt;e[81]!==Oe?(tt=Xe=>[...Xe?[{value:"inherit",label:Xe}]:[],...vg.map(mt=>({value:mt,label:Oe(mt)}))],e[81]=Oe,e[82]=tt):tt=e[82];const lt=tt,Q=(Xe,mt,Fe,J)=>{const ye=J===void 0?ze:J;return s.jsx(Xs,{value:Xe??"inherit",options:lt(ye),onChange:Ae=>mt(Ae==="inherit"?null:Ae),"aria-label":Fe})};if(C){let Xe;e[83]!==o?(Xe=o("settings.agents.page.section.toolPermissions"),e[83]=o,e[84]=Xe):Xe=e[84];let mt;e[85]!==o?(mt=o("common.loading"),e[85]=o,e[86]=mt):mt=e[86];let Fe;e[87]!==mt?(Fe=s.jsx("p",{className:ls,children:mt}),e[87]=mt,e[88]=Fe):Fe=e[88];let J;e[89]!==Xe||e[90]!==Fe?(J=s.jsx(He,{title:Xe,children:Fe}),e[89]=Xe,e[90]=Fe,e[91]=J):J=e[91],Ne=J;break e}if(k){let Xe;e[92]!==o?(Xe=o("settings.agents.page.section.toolPermissions"),e[92]=o,e[93]=Xe):Xe=e[93];let mt;e[94]!==o?(mt=o("settings.agents.page.permissionsEditor.state.loadFailed"),e[94]=o,e[95]=mt):mt=e[95];let Fe;e[96]!==mt?(Fe=s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:mt}),e[96]=mt,e[97]=Fe):Fe=e[97];let J;e[98]===Symbol.for("react.memo_cache_sentinel")?(J=()=>E(Kg),e[98]=J):J=e[98];let ye;e[99]!==o?(ye=o("settings.agents.page.permissionsEditor.actions.retry"),e[99]=o,e[100]=ye):ye=e[100];let Ae;e[101]!==ye?(Ae=s.jsx(V,{variant:"outline",size:"xs",onClick:J,children:ye}),e[101]=ye,e[102]=Ae):Ae=e[102];let Y;e[103]!==Fe||e[104]!==Ae?(Y=s.jsxs("div",{className:"flex items-center gap-3",children:[Fe,Ae]}),e[103]=Fe,e[104]=Ae,e[105]=Y):Y=e[105];let Pe;e[106]!==Xe||e[107]!==Y?(Pe=s.jsx(He,{title:Xe,children:Y}),e[106]=Xe,e[107]=Y,e[108]=Pe):Pe=e[108],Ne=Pe;break e}const nt=(Xe,mt,Fe)=>{const J=m.keys[Xe]??Eg,ye=Tg.has(Xe)||J.patterns.length>0,Ae=N[Xe]===!0;return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:ye?()=>w(Y=>({...Y,[Xe]:!Ae})):void 0,className:Se("flex min-w-0 items-center gap-1.5 text-left",!ye&&"cursor-default"),"aria-expanded":ye?Ae:void 0,children:[s.jsx(B,{name:Ae&&ye?"arrow-down-s":"arrow-right-s",className:Se("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ye&&"opacity-0")}),s.jsx("span",{className:Pt,children:mt}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:Xe}),Fe&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:Fe}),J.effect===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.agents.page.permissionsEditor.effectiveHint",{action:Oe(fe(Xe))})}),J.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:o("settings.agents.page.permissionsEditor.ruleCount",{count:String(J.patterns.length)})})]}),Q(J.effect,Y=>oe(Xe,Y),o("settings.agents.page.permissionsEditor.keyAria",{key:Xe}))]}),Ae&&ye&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[J.patterns.map((Y,Pe)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(Ge,{value:Y.pattern,onChange:Je=>ce(Xe,Pe,Je.target.value,Y.effect,!1),placeholder:o("settings.agents.page.permissionsEditor.patternPlaceholder"),"aria-label":o("settings.agents.page.permissionsEditor.patternActionAria",{key:Xe}),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(Xs,{value:Y.effect,options:lt(),onChange:Je=>ce(Xe,Pe,Y.pattern,Je,!0),"aria-label":o("settings.agents.page.permissionsEditor.patternActionAria",{key:Xe})}),s.jsx(V,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>Re(Xe,Pe),"aria-label":o("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]},Pe)),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie(Xe),children:[s.jsx(B,{name:"add",className:"mr-1 h-3.5 w-3.5"}),o("settings.agents.page.permissionsEditor.actions.addRule")]})]})]},Xe)};pe=He,e[109]!==o?(xe=o("settings.agents.page.section.toolPermissions"),e[109]=o,e[110]=xe):xe=e[110],ae="agents.permissions",e[111]!==o?(ie=o("settings.agents.page.permissionsEditor.sectionInfo"),e[111]=o,e[112]=ie):ie=e[112],ge="space-y-4";let ot;e[113]!==o?(ot=o("settings.agents.page.permissionsEditor.defaultLabel"),e[113]=o,e[114]=ot):ot=e[114];let it;e[115]!==ot?(it=s.jsx("span",{className:Pt,children:ot}),e[115]=ot,e[116]=it):it=e[116];let ft;e[117]!==o?(ft=o("settings.agents.page.permissionsEditor.defaultInfo"),e[117]=o,e[118]=ft):ft=e[118];let bt;e[119]!==ft?(bt=s.jsx(Gt,{children:ft}),e[119]=ft,e[120]=bt):bt=e[120];let ht;e[121]!==Oe||e[122]!==fe||e[123]!==m.global||e[124]!==o?(ht=m.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.agents.page.permissionsEditor.effectiveHint",{action:Oe(fe("*"))})}),e[121]=Oe,e[122]=fe,e[123]=m.global,e[124]=o,e[125]=ht):ht=e[125];let Nt;e[126]!==it||e[127]!==bt||e[128]!==ht?(Nt=s.jsxs("div",{className:"flex items-center gap-1.5",children:[it,bt,ht]}),e[126]=it,e[127]=bt,e[128]=ht,e[129]=Nt):Nt=e[129];const At=m.global;let $e;e[130]!==o?($e=o("settings.agents.page.permissionsEditor.defaultAria"),e[130]=o,e[131]=$e):$e=e[131],Ee=s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[Nt,Q(At,be,$e,Ze)]}),Ke=s.jsx("div",{children:X.map(Xe=>nt(Xe,Ag(Xe),null))}),Le=_.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-t border-border/40 pt-3 pb-1",children:[s.jsx("span",{className:Pt,children:o("settings.agents.page.permissionsEditor.mcpTitle")}),s.jsx(Gt,{children:o("settings.agents.page.permissionsEditor.mcpInfo")})]}),_.map(Xe=>nt(Xe.key,Xe.server,he(Xe.server)))]})}e[57]=Oe,e[58]=fe,e[59]=N,e[60]=C,e[61]=k,e[62]=_,e[63]=he,e[64]=m.global,e[65]=m.keys,e[66]=Re,e[67]=be,e[68]=oe,e[69]=ce,e[70]=o,e[71]=X,e[72]=pe,e[73]=xe,e[74]=ae,e[75]=ie,e[76]=ge,e[77]=Ee,e[78]=Ke,e[79]=Le,e[80]=Ne}else pe=e[72],xe=e[73],ae=e[74],ie=e[75],ge=e[76],Ee=e[77],Ke=e[78],Le=e[79],Ne=e[80];if(Ne!==Symbol.for("react.early_return_sentinel"))return Ne;let Ve;e[132]===Symbol.for("react.memo_cache_sentinel")?(Ve=ze=>A(ze.target.value),e[132]=Ve):Ve=e[132];let Ye;e[133]!==me?(Ye=ze=>{ze.key==="Enter"&&(ze.preventDefault(),me())},e[133]=me,e[134]=Ye):Ye=e[134];let pt;e[135]!==o?(pt=o("settings.agents.page.permissionsEditor.customKeyPlaceholder"),e[135]=o,e[136]=pt):pt=e[136];let vt;e[137]!==S||e[138]!==Ye||e[139]!==pt?(vt=s.jsx(Ge,{value:S,onChange:Ve,onKeyDown:Ye,placeholder:pt,className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),e[137]=S,e[138]=Ye,e[139]=pt,e[140]=vt):vt=e[140];let wt;e[141]!==S?(wt=S.trim(),e[141]=S,e[142]=wt):wt=e[142];const yt=!wt;let st;e[143]===Symbol.for("react.memo_cache_sentinel")?(st=s.jsx(B,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e[143]=st):st=e[143];let rt;e[144]!==o?(rt=o("settings.agents.page.permissionsEditor.actions.addKey"),e[144]=o,e[145]=rt):rt=e[145];let de;e[146]!==me||e[147]!==yt||e[148]!==rt?(de=s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:me,disabled:yt,children:[st,rt]}),e[146]=me,e[147]=yt,e[148]=rt,e[149]=de):de=e[149];let Ue;e[150]!==vt||e[151]!==de?(Ue=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[vt,de]}),e[150]=vt,e[151]=de,e[152]=Ue):Ue=e[152];let et;return e[153]!==pe||e[154]!==xe||e[155]!==ae||e[156]!==ie||e[157]!==ge||e[158]!==Ee||e[159]!==Ke||e[160]!==Le||e[161]!==Ue?(et=s.jsxs(pe,{title:xe,settingsItem:ae,info:ie,contentClassName:ge,children:[Ee,Ke,Le,Ue]}),e[153]=pe,e[154]=xe,e[155]=ae,e[156]=ie,e[157]=ge,e[158]=Ee,e[159]=Ke,e[160]=Le,e[161]=Ue,e[162]=et):et=e[162],et};function Mg(t){return t.updateAgent}function Rg(t){return t.fetchAgentPermissions}function Og(t){return t.loadMcpConfigs}function Lg(t){return{key:`${t.name}_*`,server:t.name}}function Fg(t){return t.key}function Kg(t){return t+1}const Qr=t=>{const e=_e.c(11),{legacy:a,path:n,className:i}=t,{t:o}=Be();if(!a)return null;let r;e[0]!==i?(r=Se("mb-4 flex items-start gap-1.5",ls,i),e[0]=i,e[1]=r):r=e[1];const d=n??void 0;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(B,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),e[2]=c):c=e[2];let g;e[3]!==o?(g=o("settings.common.legacyFormat.note"),e[3]=o,e[4]=g):g=e[4];let p;e[5]!==g?(p=s.jsx("span",{children:g}),e[5]=g,e[6]=p):p=e[6];let h;return e[7]!==r||e[8]!==d||e[9]!==p?(h=s.jsxs("p",{className:r,title:d,children:[c,p]}),e[7]=r,e[8]=d,e[9]=p,e[10]=h):h=e[10],h},zg=(t,e)=>{const a=_n(e);if(!a)return[];const n=t.find(o=>o.id===a.providerId);return zm(n?.models,a.modelId)?.variants.map(o=>o.id)??[]},Ug=()=>{const{t}=Be(),e=ct(me=>me.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:o,fetchAgentEntity:r,agentDraft:d,setAgentDraft:c,setSelectedAgent:g}=Hn($s(me=>({selectedAgentName:me.selectedAgentName,getAgentByName:me.getAgentByName,createAgent:me.createAgent,updateAgent:me.updateAgent,fetchAgentEntity:me.fetchAgentEntity,agentDraft:me.agentDraft,setAgentDraft:me.setAgentDraft,setSelectedAgent:me.setSelectedAgent}))),p=en(),h=Hn(me=>Xc(me,p)),f=a?n(a,p):null,m=!!(d&&d.name===a&&!f),v=m?"":f?.description?.trim()??"",C=m?"":f?.system?.trim()??"",[b,k]=l.useState(""),[u,j]=l.useState("user"),[N,w]=l.useState(""),[S,A]=l.useState("subagent"),[x,E]=l.useState(""),[M,T]=l.useState(""),[D,R]=l.useState(void 0),[O,I]=l.useState(void 0),[y,L]=l.useState(void 0),[K,H]=l.useState(""),[G,W]=l.useState(!1),[q,z]=l.useState(null),$=l.useRef({}),Z=l.useRef(null),_=l.useCallback(me=>{Z.current=me},[]),ne=l.useRef(null),X=JSON.stringify([a,p,m]),te=l.useRef(X);te.current=X;const he=l.useRef(null),je={description:N,mode:S,model:x,variant:M,steps:D,temperature:O,topP:y,system:K},fe=l.useRef(je);fe.current=je;const ke=l.useMemo(()=>zg(e,x),[x,e]),be=ke.length>0,De=M||"__default",oe=be,ee=l.useMemo(()=>M&&!ke.includes(M)?[M,...ke]:ke,[M,ke]);l.useEffect(()=>{if(!m||!d)return;he.current=null;const me=hi(d.model),Te=d.name||"",Oe=d.scope||"user",pe=d.description||"",xe=d.mode||"subagent",ae=me?`${me.providerID}/${me.modelID}`:"",ie=me?.variant||"",ge=d.steps??void 0,Ee=d.temperature??void 0,Ke=d.top_p??void 0,Le=d.system||"";$.current={},z(null),k(Te),j(Oe),w(pe),A(xe),E(ae),T(ie),R(ge),I(Ee),L(Ke),H(Le),ne.current={draftName:Te,draftScope:Oe,description:pe,mode:xe,model:ae,variant:ie,steps:ge,temperature:Ee,topP:Ke,system:Le}},[d,m]),l.useEffect(()=>{if(m||!a)return;let me=!1;return(async()=>{const Te=await r(a,p);if(me||te.current!==X||!Te)return;const Oe=Te.config;$.current=Oe;const pe=hi(Oe.model),xe=Oe.request?.body,ae={draftName:"",draftScope:"user",description:Oe.description||"",mode:Oe.mode||f?.mode||"subagent",model:pe?`${pe.providerID}/${pe.modelID}`:"",variant:pe?.variant||"",steps:Oe.steps??void 0,temperature:xe?.temperature,topP:xe?.top_p,system:Oe.system||""},ie=ne.current,ge=fe.current,Ee=ie!==null&&(ge.description!==ie.description||ge.mode!==ie.mode||ge.model!==ie.model||ge.variant!==ie.variant||ge.steps!==ie.steps||ge.temperature!==ie.temperature||ge.topP!==ie.topP||ge.system!==ie.system);z({legacy:Te.legacy===!0,path:Te.path,source:Te.source}),!(he.current===X&&Ee)&&(he.current=X,w(ae.description),A(ae.mode),E(ae.model),T(ae.variant),R(ae.steps),I(ae.temperature),L(ae.topP),H(ae.system),ne.current=ae)})(),()=>{me=!0}},[r,m,f,a,p,X]);const ce=l.useCallback(me=>{const Te=_n(x.trim()),Oe=Te?ed({providerID:Te.providerId,modelID:Te.modelId,variant:M.trim()||void 0}):null,pe=$.current.request,xe={...pe?.body};O===void 0?delete xe.temperature:xe.temperature=O,y===void 0?delete xe.top_p:xe.top_p=y;const ae=pe?.headers,ie={};ae&&Object.keys(ae).length>0&&(ie.headers=ae),Object.keys(xe).length>0&&(ie.body=xe);const ge=N.trim(),Ee=K.trim(),Ke={name:me,mode:S,model:Oe,steps:D??null,system:Ee||(m?void 0:null),request:Object.keys(ie).length>0?ie:null};return ge&&(Ke.description=ge),m&&u&&(Ke.scope=u),m&&d?.permissions?.length&&(Ke.permissions=d.permissions),Ke},[d,N,u,m,S,x,D,K,O,y,M]),ue=l.useCallback(async()=>{const me=ne.current,Te=a?.trim();if(m||!me||!Te)return Us;const Oe=Z.current?await Z.current():Us;if(N===me.description&&S===me.mode&&x===me.model&&M===me.variant&&D===me.steps&&O===me.temperature&&y===me.topP&&K===me.system||!Oe.ok)return Oe;const xe=ce(Te);return(await o(Te,xe,p)).ok?(te.current!==X||($.current={...$.current,model:xe.model,system:xe.system??void 0,steps:xe.steps,request:xe.request??void 0},ne.current={...me,description:N,mode:S,model:x,variant:M,steps:D,temperature:O,topP:y,system:K}),Tn):xs(t("settings.agents.page.toast.updateFailed"))},[ce,N,m,S,x,a,X,p,D,K,t,O,y,o,M]),Ie=ti(ue),{requestSave:ve}=Ie,Re=async()=>{const me=b.trim().replace(/\s+/g,"-");if(!me){U.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(h.some(Te=>Te.name===me)){U.error(t("settings.agents.sidebar.toast.agentExists"));return}W(!0);try{(await i(ce(me),p)).ok?(c(null),U.success(t("settings.agents.page.toast.created"))):U.error(t("settings.agents.page.toast.createFailed"))}catch(Te){console.error("Error creating agent:",Te);const Oe=Te instanceof Error&&Te.message?Te.message:t("settings.agents.page.toast.saveUnexpectedError");U.error(Oe)}finally{W(!1)}},Me=()=>{c(null),g(null)};return a?s.jsxs(ns,{title:m?t("settings.agents.page.title.new"):a,description:t(m?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),onBlurCapture:Ie.onBlurCapture,children:[!m&&q&&s.jsx(Qr,{legacy:q.legacy,path:q.path}),!m&&q?.source==="none"&&s.jsxs("p",{className:`mb-4 flex items-start gap-1.5 ${ls}`,children:[s.jsx(B,{name:"information",className:"mt-[0.2em] h-3.5 w-3.5 shrink-0 opacity-70"}),s.jsx("span",{children:t("settings.agents.page.runtimeProvided.note")})]}),s.jsxs(He,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[m&&s.jsxs(Ct,{settingsItem:"agents.name",label:t("settings.agents.page.field.agentName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(Ge,{value:b,onChange:me=>k(me.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Dt,{value:u,onValueChange:me=>j(me),children:[s.jsx(Tt,{size:Qt,className:"w-fit min-w-[100px]",children:s.jsx(Jt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Et,{align:"end",children:[s.jsx(gt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(gt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Kt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Rs,{value:N,onChange:me=>w(me.target.value),placeholder:v||t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Kt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Xs,{"aria-label":t("settings.agents.page.field.mode"),value:S,onChange:me=>{A(me),ve()},options:[{value:"primary",label:t("settings.agents.page.mode.primary")},{value:"subagent",label:t("settings.agents.page.mode.subagent")},{value:"all",label:t("settings.agents.page.mode.all")}]})})]}),s.jsxs(He,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Ct,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ga,{providerId:_n(x)?.providerId??"",modelId:_n(x)?.modelId??"",onChange:(me,Te)=>{E(me&&Te?`${me}/${Te}`:""),T(""),ve()},className:Zs})}),s.jsx(Ct,{settingsItem:"agents.variant",label:t("settings.agents.page.field.variant"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.variantTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.variantHint")})]}),children:oe?s.jsxs(Dt,{value:De,onValueChange:me=>{T(me==="__default"?"":me),ve()},children:[s.jsx(Tt,{size:Qt,className:fn,children:s.jsx(Jt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:me=>me==="__default"?t("chat.modelControls.default"):me})}),s.jsxs(Et,{children:[s.jsx(gt,{value:"__default",children:t("chat.modelControls.default")}),ee.map(me=>s.jsx(gt,{value:me,children:me},me))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Ge,{value:M,onChange:me=>T(me.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!x&&!M,className:"h-8 w-40 rounded-md px-3"}),M&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{T(""),ve()},className:hs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Ct,{settingsItem:"agents.temperature",label:t("settings.agents.page.field.temperature"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.temperatureTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.temperatureRange")})]}),children:[s.jsx(js,{value:O,fallbackValue:.7,onValueChange:I,onClear:()=>{I(void 0),ve()},min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:ws}),O!==void 0&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{I(void 0),ve()},className:hs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ct,{settingsItem:"agents.top-p",label:t("settings.agents.page.field.topP"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.topPTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.topPRange")})]}),children:[s.jsx(js,{value:y,fallbackValue:.9,onValueChange:L,onClear:()=>{L(void 0),ve()},min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:ws}),y!==void 0&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{L(void 0),ve()},className:hs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ct,{settingsItem:"agents.steps",label:t("settings.agents.page.field.steps"),info:t("settings.agents.page.field.stepsTooltip"),children:[s.jsx(js,{value:D,fallbackValue:20,onValueChange:R,onClear:()=>{R(void 0),ve()},min:1,max:1e3,step:1,inputMode:"numeric",placeholder:"—",emptyLabel:"—",className:ws}),D!==void 0&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{R(void 0),ve()},className:hs,"aria-label":t("settings.agents.page.field.clearStepsAria"),title:t("settings.common.actions.clear"),children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(He,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Rs,{value:K,onChange:me=>H(me.target.value),placeholder:C||t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent"})}),!m&&f&&s.jsx(Dg,{agent:f,registerSave:_,requestSave:ve}),m&&s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(V,{onClick:()=>{Re()},disabled:G||!b.trim(),size:"xs",className:"!font-normal",children:t(G?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(V,{variant:"ghost",onClick:Me,disabled:G,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(B,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})};function _g(t,e){return t.kind==="file"?t.content:e??""}const Bl=Os({content:Rt(),exists:qr(),path:Rt().min(1).optional()}),$g=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Bg=t=>t.length>0&&!t.endsWith(`
3
+ `)?`${t}
4
+ `:t,Ui={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Vg=(t,e)=>t==="custom"?e:Iu(t),Hg=t=>t==="custom"?"custom":td(t)?t:"concise",Vl={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},qg=()=>{const{t}=Be(),[e,a]=l.useState(""),[n,i]=l.useState("AGENTS.md"),[o,r]=l.useState(Ui.responseStyleEnabled),[d,c]=l.useState(Ui.responseStylePreset),[g,p]=l.useState(Ui.responseStyleCustomInstructions),[h,f]=l.useState(!0),m=l.useRef(null),v=l.useRef(null);l.useEffect(()=>{const N=new AbortController;return(async()=>{try{const[S,A]=await Promise.all([En(),It("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:N.signal})]);let x=Ui,E;S&&(x={...x,responseStyleEnabled:S.responseStyleEnabled===!0,responseStylePreset:Hg(S.responseStylePreset),responseStyleCustomInstructions:S.responseStyleCustomInstructions??""},S.globalBehaviorPrompt!==void 0&&(E=S.globalBehaviorPrompt));let M={kind:"missing"};if(A.ok){const T=Bl.parse(await A.json());if(N.signal.aborted)return;i(T.path??"AGENTS.md"),v.current=T.exists?T.content:null,T.exists&&(M={kind:"file",content:T.content})}x={...x,prompt:_g(M,E)},a(x.prompt),r(x.responseStyleEnabled),c(x.responseStylePreset),p(x.responseStyleCustomInstructions),m.current=x}catch(S){S.name!=="AbortError"&&console.warn("Failed to load behavior settings:",S)}finally{f(!1)}})(),()=>N.abort()},[]);const C=l.useRef(e);C.current=e,l.useEffect(()=>{let N=null;const w=async()=>{if(document.visibilityState!=="visible"||!m.current)return;N?.abort();const A=new AbortController;N=A;try{const x=await It("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:A.signal});if(!x.ok)return;const E=Bl.parse(await x.json()),M=m.current;if(A.signal.aborted||!M||!E.exists||E.content===v.current||C.current!==M.prompt)return;v.current=E.content,m.current={...M,prompt:E.content},a(E.content)}catch(x){x instanceof DOMException&&x.name==="AbortError"||console.warn("Failed to refresh AGENTS.md:",x)}},S=()=>{w()};return window.addEventListener("focus",S),document.addEventListener("visibilitychange",S),()=>{N?.abort(),window.removeEventListener("focus",S),document.removeEventListener("visibilitychange",S)}},[]);const b=l.useCallback(async()=>{const N=m.current;if(!N||h)return Us;const w=e!==N.prompt,S=o!==N.responseStyleEnabled||d!==N.responseStylePreset||g!==N.responseStyleCustomInstructions;if(!w&&!S)return Us;const A=w?Bg(e):N.prompt;if(w){const E=await It("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:A,expectedContent:v.current})});if(E.status===409)return xs(t("settings.behavior.page.toast.agentsMdChangedOnDisk"));if(!E.ok)return xs(await $g(E,t("settings.behavior.page.toast.saveFailed")));v.current=A,a(M=>M===e?A:M)}return(await kt({...w?{globalBehaviorPrompt:A}:{},responseStyleEnabled:o,responseStylePreset:d,responseStyleCustomInstructions:g})).ok?(m.current={prompt:A,responseStyleEnabled:o,responseStylePreset:d,responseStyleCustomInstructions:g},Tn):xs(t("settings.behavior.page.toast.saveFailed"))},[h,e,g,o,d,t]),k=ti(b),{requestSave:u}=k,j=Vg(d,g);return s.jsxs(ns,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),onBlurCapture:k.onBlurCapture,children:[s.jsx(He,{title:t("settings.behavior.page.section.systemPrompt"),divider:!1,info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:n})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:s.jsx(Rs,{value:e,onChange:N=>a(N.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:h,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"})}),s.jsxs(He,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(xt,{checked:o,onChange:N=>{r(N),u()},disabled:h,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Ct,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Dt,{value:d,onValueChange:N=>{c(N),u()},disabled:h||!o,children:[s.jsx(Tt,{size:Qt,className:fn,children:s.jsx(Jt,{children:N=>N==="custom"?t("settings.behavior.page.responseStyle.option.custom"):td(N)?t(Vl[N]):null})}),s.jsxs(Et,{children:[Cu.map(N=>s.jsx(gt,{value:N,children:t(Vl[N])},N)),s.jsx(gt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Rs,{value:j,onChange:N=>p(N.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:h||!o||d!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Gg=(t,e)=>t.kind===e.kind&&(t.kind!=="provider"||e.kind==="provider"&&t.id===e.id),Wg=t=>{const e=_e.c(73),{snapshot:a}=t,{t:n}=Be(),i=yi(Zg),o=a.selection,r=a.projectOverride!==null;let d;e[0]!==r||e[1]!==o||e[2]!==i||e[3]!==n?(d=O=>{r||Gg(O,o)||i(O).then(I=>{I||U.error(n("settings.webSearch.toast.saveFailed"))})},e[0]=r,e[1]=o,e[2]=i,e[3]=n,e[4]=d):d=e[4];const c=d,g=o.kind==="provider"&&!a.providers.some(O=>O.id===o.id)?o.id:null;let p;e[5]!==n?(p=n("settings.webSearch.section.provider"),e[5]=n,e[6]=p):p=e[6];let h;e[7]!==n?(h=n("settings.webSearch.section.providerInfo"),e[7]=n,e[8]=h):h=e[8];let f;e[9]!==n?(f=n("settings.webSearch.section.provider"),e[9]=n,e[10]=f):f=e[10];const m=o.kind==="default";let v;e[11]!==c?(v=()=>c({kind:"default"}),e[11]=c,e[12]=v):v=e[12];let C;e[13]!==n?(C=n("settings.webSearch.option.default"),e[13]=n,e[14]=C):C=e[14];let b;e[15]!==n?(b=n("settings.webSearch.option.defaultDescription"),e[15]=n,e[16]=b):b=e[16];let k;e[17]!==r||e[18]!==m||e[19]!==v||e[20]!==C||e[21]!==b?(k=s.jsx(rs,{selected:m,onSelect:v,disabled:r,label:C,description:b}),e[17]=r,e[18]=m,e[19]=v,e[20]=C,e[21]=b,e[22]=k):k=e[22];let u;e[23]!==c||e[24]!==r||e[25]!==o.kind||e[26]!==a.providers.length||e[27]!==n?(u=a.providers.length>0?s.jsx(rs,{selected:o.kind==="random",onSelect:()=>c({kind:"random"}),disabled:r,label:n("settings.webSearch.option.random"),description:n("settings.webSearch.option.randomDescription")}):null,e[23]=c,e[24]=r,e[25]=o.kind,e[26]=a.providers.length,e[27]=n,e[28]=u):u=e[28];let j;if(e[29]!==c||e[30]!==r||e[31]!==o.id||e[32]!==o.kind||e[33]!==a.providers){let O;e[35]!==c||e[36]!==r||e[37]!==o.id||e[38]!==o.kind?(O=I=>s.jsx(rs,{selected:o.kind==="provider"&&o.id===I.id,onSelect:()=>c({kind:"provider",id:I.id}),disabled:r,label:I.name},I.id),e[35]=c,e[36]=r,e[37]=o.id,e[38]=o.kind,e[39]=O):O=e[39],j=a.providers.map(O),e[29]=c,e[30]=r,e[31]=o.id,e[32]=o.kind,e[33]=a.providers,e[34]=j}else j=e[34];let N;e[40]!==g||e[41]!==n?(N=g?s.jsx(rs,{selected:!0,onSelect:Xg,label:g,description:n("settings.webSearch.option.missing")}):null,e[40]=g,e[41]=n,e[42]=N):N=e[42];const w=o.kind==="off";let S;e[43]!==c?(S=()=>c({kind:"off"}),e[43]=c,e[44]=S):S=e[44];let A;e[45]!==n?(A=n("settings.webSearch.option.off"),e[45]=n,e[46]=A):A=e[46];let x;e[47]!==r||e[48]!==w||e[49]!==S||e[50]!==A?(x=s.jsx(rs,{selected:w,onSelect:S,disabled:r,label:A}),e[47]=r,e[48]=w,e[49]=S,e[50]=A,e[51]=x):x=e[51];let E;e[52]!==u||e[53]!==j||e[54]!==N||e[55]!==x||e[56]!==f||e[57]!==k?(E=s.jsxs(Js,{"aria-label":f,children:[k,u,j,N,x]}),e[52]=u,e[53]=j,e[54]=N,e[55]=x,e[56]=f,e[57]=k,e[58]=E):E=e[58];let M;e[59]!==a.projectOverride||e[60]!==n?(M=a.projectOverride?s.jsx("p",{className:`${ls} mt-2 break-all`,children:n("settings.webSearch.state.projectOverride",{path:a.projectOverride})}):null,e[59]=a.projectOverride,e[60]=n,e[61]=M):M=e[61];let T;e[62]!==a.providers.length||e[63]!==n?(T=a.providers.length===0?s.jsx("p",{className:`${ls} mt-2`,children:n("settings.webSearch.state.noProviders")}):null,e[62]=a.providers.length,e[63]=n,e[64]=T):T=e[64];let D;e[65]!==E||e[66]!==M||e[67]!==T?(D=s.jsxs("div",{children:[E,M,T]}),e[65]=E,e[66]=M,e[67]=T,e[68]=D):D=e[68];let R;return e[69]!==p||e[70]!==D||e[71]!==h?(R=s.jsx(He,{title:p,info:h,divider:!1,settingsItem:"web-search.provider",children:D}),e[69]=p,e[70]=D,e[71]=h,e[72]=R):R=e[72],R},Jg=t=>{const e=_e.c(27),{provider:a,access:n,locked:i}=t,{t:o}=Be(),r=yi(ef),d=yi(tf),[c,g]=l.useState(""),[p,h]=l.useState(!1);let f;e[0]!==n.envNames||e[1]!==o?(f=n.envNames.length>0?o("settings.webSearch.keys.envHint",{names:n.envNames.join(", ")}):void 0,e[0]=n.envNames,e[1]=o,e[2]=f):f=e[2];const m=f;let v;e[3]!==c||e[4]!==a.id||e[5]!==a.name||e[6]!==r||e[7]!==o?(v=async()=>{const w=c.trim();if(!w)return;h(!0);const S=await r(a.id,w);h(!1),S?(g(""),U.success(o("settings.webSearch.toast.keySaved",{provider:a.name}))):U.error(o("settings.webSearch.toast.keySaveFailed"))},e[3]=c,e[4]=a.id,e[5]=a.name,e[6]=r,e[7]=o,e[8]=v):v=e[8];const C=v;let b;e[9]!==a.id||e[10]!==d||e[11]!==o?(b=async()=>{h(!0);const w=await d(a.id);h(!1),w||U.error(o("settings.webSearch.toast.keyRemoveFailed"))},e[9]=a.id,e[10]=d,e[11]=o,e[12]=b):b=e[12];const k=b,u=n.key;let j;e[13]!==p||e[14]!==c||e[15]!==k||e[16]!==C||e[17]!==i||e[18]!==a.name||e[19]!==u.kind||e[20]!==u.name||e[21]!==o?(j=u.kind==="stored"?s.jsxs("div",{className:`${Es} flex items-center justify-end gap-2`,children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:o("settings.webSearch.keys.saved")}),s.jsx(V,{variant:"outline",size:"xs",disabled:p,onClick:()=>{k()},children:o("settings.webSearch.keys.remove")})]}):u.kind==="env"?s.jsx("span",{className:"typography-meta text-muted-foreground",children:o("settings.webSearch.keys.fromEnv",{name:u.name})}):i?null:s.jsxs("div",{className:`${Es} flex items-center gap-2`,children:[s.jsx(Ge,{type:"password",value:c,onChange:w=>g(w.target.value),onKeyDown:w=>{w.key==="Enter"&&C()},placeholder:o("settings.webSearch.keys.placeholder"),"aria-label":o("settings.webSearch.keys.inputAria",{provider:a.name}),className:"h-8 min-w-0 flex-1 rounded-md px-3 font-mono text-xs"}),s.jsx(V,{size:"xs",disabled:p||c.trim().length===0,onClick:()=>{C()},children:o("settings.webSearch.keys.save")})]}),e[13]=p,e[14]=c,e[15]=k,e[16]=C,e[17]=i,e[18]=a.name,e[19]=u.kind,e[20]=u.name,e[21]=o,e[22]=j):j=e[22];let N;return e[23]!==m||e[24]!==a.name||e[25]!==j?(N=s.jsx(Ct,{label:a.name,info:m,children:j}),e[23]=m,e[24]=a.name,e[25]=j,e[26]=N):N=e[26],N},Qg=t=>{const e=_e.c(29),{snapshot:a}=t,{t:n}=Be(),i=ya(),o=a.access;let r,d,c,g,p,h,f,m;if(e[0]!==o||e[1]!==i||e[2]!==a.providers||e[3]!==n){m=Symbol.for("react.early_return_sentinel");e:{const b=o?a.providers.flatMap(k=>{const u=o[k.id];return u&&u.key.kind!=="unsupported"?[{provider:k,access:u}]:[]}):[];if(o&&b.length===0){m=null;break e}r=He,e[12]!==n?(p=n("settings.webSearch.section.keys"),e[12]=n,e[13]=p):p=e[13],e[14]!==n?(h=n("settings.webSearch.section.keysInfo"),e[14]=n,e[15]=h):h=e[15],f="web-search.keys",d="space-y-4",e[16]!==i||e[17]!==n?(c=i?s.jsx("p",{className:ls,children:n("settings.webSearch.keys.enterpriseMode")}):null,e[16]=i,e[17]=n,e[18]=c):c=e[18],g=o===null?s.jsx("p",{className:ls,children:n("settings.webSearch.state.keysUnavailable")}):b.map(k=>{const{provider:u,access:j}=k;return s.jsx(Jg,{provider:u,access:j,locked:i},u.id)})}e[0]=o,e[1]=i,e[2]=a.providers,e[3]=n,e[4]=r,e[5]=d,e[6]=c,e[7]=g,e[8]=p,e[9]=h,e[10]=f,e[11]=m}else r=e[4],d=e[5],c=e[6],g=e[7],p=e[8],h=e[9],f=e[10],m=e[11];if(m!==Symbol.for("react.early_return_sentinel"))return m;let v;e[19]!==d||e[20]!==c||e[21]!==g?(v=s.jsxs("div",{className:d,children:[c,g]}),e[19]=d,e[20]=c,e[21]=g,e[22]=v):v=e[22];let C;return e[23]!==r||e[24]!==p||e[25]!==h||e[26]!==f||e[27]!==v?(C=s.jsx(r,{title:p,info:h,settingsItem:f,children:v}),e[23]=r,e[24]=p,e[25]=h,e[26]=f,e[27]=v,e[28]=C):C=e[28],C},Yg=()=>{const t=_e.c(17),{t:e}=Be(),a=yi(sf),n=yi(nf);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=Pu(),t[0]=i):i=t[0];const o=i;let r,d;t[1]!==n?(r=()=>{n()},d=[n,o],t[1]=n,t[2]=r,t[3]=d):(r=t[2],d=t[3]),l.useEffect(r,d);const c=a.kind==="ready"&&a.snapshot.scope===o?a.snapshot:null;let g;t[4]!==e?(g=e("settings.page.webSearch.title"),t[4]=e,t[5]=g):g=t[5];let p;t[6]!==e?(p=e("settings.page.webSearch.description"),t[6]=e,t[7]=p):p=t[7];let h;t[8]!==n||t[9]!==c||t[10]!==a.kind||t[11]!==e?(h=c?s.jsxs(s.Fragment,{children:[s.jsx(Wg,{snapshot:c}),s.jsx(Qg,{snapshot:c})]}):a.kind==="failed"?s.jsx(He,{divider:!1,children:s.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.webSearch.state.loadFailed")}),s.jsx(V,{variant:"outline",size:"xs",onClick:()=>{n()},children:e("settings.webSearch.actions.retry")})]})}):s.jsx(He,{divider:!1,children:s.jsx("p",{className:ls,children:e("settings.webSearch.state.loading")})}),t[8]=n,t[9]=c,t[10]=a.kind,t[11]=e,t[12]=h):h=t[12];let f;return t[13]!==g||t[14]!==p||t[15]!==h?(f=s.jsx(ns,{title:g,description:p,showSaveStatus:!0,children:h}),t[13]=g,t[14]=p,t[15]=h,t[16]=f):f=t[16],f};function Zg(t){return t.setSelection}function Xg(){}function ef(t){return t.saveKey}function tf(t){return t.removeKey}function sf(t){return t.state}function nf(t){return t.load}const af=t=>{const e=_e.c(183),{onItemSelect:a}=t,{t:n}=Be(),[i,o]=l.useState(""),[r,d]=l.useState(null),[c,g]=l.useState(""),[p,h]=l.useState(null),[f,m]=l.useState(null),[v,C]=l.useState(!1),[b,k]=l.useState(null),{selectedCommandName:u,setSelectedCommand:j,setCommandDraft:N,createCommand:w,deleteCommand:S,loadCommands:A}=Ja($s(of)),x=en();let E;e[0]!==x?(E=$e=>sd($e,x),e[0]=x,e[1]=E):E=e[1];const M=Ja(E);let T;e[2]!==x?(T=$e=>Lr($e,x),e[2]=x,e[3]=T):T=e[3];const D=rn(T),R=rn(rf);let O,I;e[4]!==A||e[5]!==R||e[6]!==x?(O=()=>{A(x),R(x)},I=[A,R,x],e[4]=A,e[5]=R,e[6]=x,e[7]=O,e[8]=I):(O=e[7],I=e[8]),l.useEffect(O,I);let y;e[9]!==D?(y=new Set(D.map(lf)),e[9]=D,e[10]=y):y=e[10];const L=y;let K;if(e[11]!==M||e[12]!==L){let $e;e[14]!==L?($e=Xe=>!L.has(Xe.name),e[14]=L,e[15]=$e):$e=e[15],K=M.filter($e),e[11]=M,e[12]=L,e[13]=K}else K=e[13];const H=K;let G,W;e[16]!==u||e[17]!==j||e[18]!==L?(G=()=>{u&&L.has(u)&&j(null)},W=[u,j,L],e[16]=u,e[17]=j,e[18]=L,e[19]=G,e[20]=W):(G=e[19],W=e[20]),l.useEffect(G,W);let q;e[21]!==M||e[22]!==a||e[23]!==N||e[24]!==j?(q=()=>{let $e="new-command",Xe=1;for(;M.some(mt=>mt.name===$e);)$e=`new-command-${Xe}`,Xe++;N({name:$e,scope:"user"}),j($e),a?.()},e[21]=M,e[22]=a,e[23]=N,e[24]=j,e[25]=q):q=e[25];const z=q;let $;e[26]!==n?($=async $e=>{if(Ha($e)){U.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}h($e),m("delete")},e[26]=n,e[27]=$):$=e[27];const Z=$;let _;e[28]===Symbol.for("react.memo_cache_sentinel")?(_=async $e=>{Ha($e)&&(h($e),m("reset"))},e[28]=_):_=e[28];const ne=_;let X;e[29]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{h(null),m(null)},e[29]=X):X=e[29];const te=X;let he;e[30]!==p||e[31]!==f||e[32]!==S||e[33]!==x||e[34]!==n?(he=async()=>{if(!p||!f)return;C(!0),await S(p.name,x)?(f==="delete"?U.success(n("settings.commands.sidebar.toast.commandDeleted",{name:p.name})):U.success(n("settings.commands.sidebar.toast.commandReset",{name:p.name})),te()):f==="delete"?U.error(n("settings.commands.sidebar.toast.deleteFailed")):U.error(n("settings.commands.sidebar.toast.resetFailed")),C(!1)},e[30]=p,e[31]=f,e[32]=S,e[33]=x,e[34]=n,e[35]=he):he=e[35];const je=he;let fe;e[36]!==M||e[37]!==N||e[38]!==j?(fe=$e=>{const Xe=$e.name;let mt=1,Fe=`${Xe}-copy`;for(;M.some(J=>J.name===Fe);)mt++,Fe=`${Xe}-copy-${mt}`;N({name:Fe,scope:$e.scope||"user",description:$e.description,template:$e.template,agent:$e.agent,model:$e.model,subagent:$e.subagent}),j(Fe)},e[36]=M,e[37]=N,e[38]=j,e[39]=fe):fe=e[39];const ke=fe;let be;e[40]===Symbol.for("react.memo_cache_sentinel")?(be=$e=>{g($e.name),d($e)},e[40]=be):be=e[40];const De=be;let oe;e[41]!==M||e[42]!==w||e[43]!==S||e[44]!==r||e[45]!==c||e[46]!==j||e[47]!==x||e[48]!==n?(oe=async()=>{if(!r)return;const $e=c.trim().replace(/\s+/g,"-");if(!$e){U.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if($e===r.name){d(null);return}if(M.some(mt=>mt.name===$e)){U.error(n("settings.commands.sidebar.toast.commandExists"));return}await w({name:$e,description:r.description,template:r.template,agent:r.agent,model:r.model,subagent:r.subagent,scope:r.scope},x)?await S(r.name,x)?(U.success(`Command renamed to "${$e}"`),j($e)):U.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):U.error(n("settings.commands.sidebar.toast.renameFailed")),d(null)},e[41]=M,e[42]=w,e[43]=S,e[44]=r,e[45]=c,e[46]=j,e[47]=x,e[48]=n,e[49]=oe):oe=e[49];const ee=oe;let ce,ue,Ie,ve,Re,Me;if(e[50]!==H||e[51]!==z||e[52]!==Z||e[53]!==ke||e[54]!==a||e[55]!==b||e[56]!==i||e[57]!==u||e[58]!==j||e[59]!==n){let $e;e[66]!==i?($e=Ce=>po([Ce.name,Ce.description],i),e[66]=i,e[67]=$e):$e=e[67];const Xe=H.filter($e),mt=Xe.filter(Ha),Fe=Xe.filter(cf);e[68]===Symbol.for("react.memo_cache_sentinel")?(Re=Se("flex h-full flex-col","bg-background"),e[68]=Re):Re=e[68];let J;e[69]!==n?(J=n("settings.commands.sidebar.title"),e[69]=n,e[70]=J):J=e[70];let ye;e[71]!==J?(ye=s.jsx("h2",{className:`${va} mb-3`,children:J}),e[71]=J,e[72]=ye):ye=e[72];let Ae;e[73]===Symbol.for("react.memo_cache_sentinel")?(Ae=s.jsx(Si,{className:"mb-3"}),e[73]=Ae):Ae=e[73];let Y;e[74]!==H.length||e[75]!==n?(Y=n("settings.commands.sidebar.total",{count:H.length}),e[74]=H.length,e[75]=n,e[76]=Y):Y=e[76];let Pe;e[77]!==Y?(Pe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Y}),e[77]=Y,e[78]=Pe):Pe=e[78];let Je;e[79]===Symbol.for("react.memo_cache_sentinel")?(Je=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[79]=Je):Je=e[79];let se;e[80]!==z?(se=s.jsx(V,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:z,children:Je}),e[80]=z,e[81]=se):se=e[81];let We;e[82]!==Pe||e[83]!==se?(We=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Pe,se]}),e[82]=Pe,e[83]=se,e[84]=We):We=e[84];let ut;e[85]!==H.length||e[86]!==i?(ut=H.length>0?s.jsx(Wr,{value:i,onChange:o}):null,e[85]=H.length,e[86]=i,e[87]=ut):ut=e[87],e[88]!==ye||e[89]!==We||e[90]!==ut?(Me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ye,Ae,We,ut]}),e[88]=ye,e[89]=We,e[90]=ut,e[91]=Me):Me=e[91],ce=Ds,ue="flex-1 min-h-0",Ie="space-y-1 px-3 py-2",ve=H.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(B,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):Xe.length===0?s.jsx(Jr,{query:i}):s.jsxs(s.Fragment,{children:[mt.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...mt].sort(df).map(Ce=>s.jsx(Hl,{command:Ce,isSelected:u===Ce.name,onSelect:()=>{j(Ce.name),a?.()},onReset:()=>ne(Ce),onDuplicate:()=>ke(Ce),isMenuOpen:b===Ce.name,onMenuOpenChange:qe=>k(qe?Ce.name:null)},Ce.name))]}),Fe.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.custom")}),[...Fe].sort(uf).map(Ce=>s.jsx(Hl,{command:Ce,isSelected:u===Ce.name,onSelect:()=>{j(Ce.name),a?.()},onRename:()=>De(Ce),onDelete:()=>Z(Ce),onDuplicate:()=>ke(Ce),isMenuOpen:b===Ce.name,onMenuOpenChange:qe=>k(qe?Ce.name:null)},Ce.name))]})]}),e[50]=H,e[51]=z,e[52]=Z,e[53]=ke,e[54]=a,e[55]=b,e[56]=i,e[57]=u,e[58]=j,e[59]=n,e[60]=ce,e[61]=ue,e[62]=Ie,e[63]=ve,e[64]=Re,e[65]=Me}else ce=e[60],ue=e[61],Ie=e[62],ve=e[63],Re=e[64],Me=e[65];let me;e[92]!==ce||e[93]!==ue||e[94]!==Ie||e[95]!==ve?(me=s.jsx(ce,{outerClassName:ue,className:Ie,children:ve}),e[92]=ce,e[93]=ue,e[94]=Ie,e[95]=ve,e[96]=me):me=e[96];const Te=p!==null&&f!==null;let Oe;e[97]!==v?(Oe=$e=>{!$e&&!v&&te()},e[97]=v,e[98]=Oe):Oe=e[98];let pe;e[99]!==f||e[100]!==n?(pe=n(f==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[99]=f,e[100]=n,e[101]=pe):pe=e[101];let xe;e[102]!==pe?(xe=s.jsx(Ht,{children:pe}),e[102]=pe,e[103]=xe):xe=e[103];let ae;e[104]!==p?.name||e[105]!==f||e[106]!==n?(ae=f==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:p?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:p?.name??""}),e[104]=p?.name,e[105]=f,e[106]=n,e[107]=ae):ae=e[107];let ie;e[108]!==ae?(ie=s.jsx(qt,{children:ae}),e[108]=ae,e[109]=ie):ie=e[109];let ge;e[110]!==xe||e[111]!==ie?(ge=s.jsxs(Vt,{children:[xe,ie]}),e[110]=xe,e[111]=ie,e[112]=ge):ge=e[112];let Ee;e[113]!==n?(Ee=n("settings.common.actions.cancel"),e[113]=n,e[114]=Ee):Ee=e[114];let Ke;e[115]!==v||e[116]!==Ee?(Ke=s.jsx(V,{size:"sm",variant:"ghost",onClick:te,disabled:v,children:Ee}),e[115]=v,e[116]=Ee,e[117]=Ke):Ke=e[117];let Le;e[118]!==f||e[119]!==n?(Le=n(f==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[118]=f,e[119]=n,e[120]=Le):Le=e[120];let Ne;e[121]!==je||e[122]!==v||e[123]!==Le?(Ne=s.jsx(V,{size:"sm",onClick:je,disabled:v,children:Le}),e[121]=je,e[122]=v,e[123]=Le,e[124]=Ne):Ne=e[124];let Ve;e[125]!==Ke||e[126]!==Ne?(Ve=s.jsxs(as,{children:[Ke,Ne]}),e[125]=Ke,e[126]=Ne,e[127]=Ve):Ve=e[127];let Ye;e[128]!==ge||e[129]!==Ve?(Ye=s.jsxs($t,{className:"max-w-md",children:[ge,Ve]}),e[128]=ge,e[129]=Ve,e[130]=Ye):Ye=e[130];let pt;e[131]!==Te||e[132]!==Oe||e[133]!==Ye?(pt=s.jsx(_t,{open:Te,onOpenChange:Oe,children:Ye}),e[131]=Te,e[132]=Oe,e[133]=Ye,e[134]=pt):pt=e[134];const vt=r!==null;let wt;e[135]===Symbol.for("react.memo_cache_sentinel")?(wt=$e=>!$e&&d(null),e[135]=wt):wt=e[135];let yt;e[136]!==n?(yt=n("settings.commands.sidebar.renameDialog.title"),e[136]=n,e[137]=yt):yt=e[137];let st;e[138]!==yt?(st=s.jsx(Ht,{children:yt}),e[138]=yt,e[139]=st):st=e[139];const rt=r?.name??"";let de;e[140]!==n||e[141]!==rt?(de=n("settings.commands.sidebar.renameDialog.description",{name:rt}),e[140]=n,e[141]=rt,e[142]=de):de=e[142];let Ue;e[143]!==de?(Ue=s.jsx(qt,{children:de}),e[143]=de,e[144]=Ue):Ue=e[144];let et;e[145]!==st||e[146]!==Ue?(et=s.jsxs(Vt,{children:[st,Ue]}),e[145]=st,e[146]=Ue,e[147]=et):et=e[147];let ze;e[148]===Symbol.for("react.memo_cache_sentinel")?(ze=$e=>g($e.target.value),e[148]=ze):ze=e[148];let Ze;e[149]!==n?(Ze=n("settings.commands.sidebar.renameDialog.placeholder"),e[149]=n,e[150]=Ze):Ze=e[150];let tt;e[151]!==ee?(tt=$e=>{$e.key==="Enter"&&ee()},e[151]=ee,e[152]=tt):tt=e[152];let lt;e[153]!==c||e[154]!==Ze||e[155]!==tt?(lt=s.jsx(Ge,{value:c,onChange:ze,placeholder:Ze,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:tt}),e[153]=c,e[154]=Ze,e[155]=tt,e[156]=lt):lt=e[156];let Q;e[157]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>d(null),e[157]=Q):Q=e[157];let nt;e[158]!==n?(nt=n("settings.common.actions.cancel"),e[158]=n,e[159]=nt):nt=e[159];let ot;e[160]!==nt?(ot=s.jsx(V,{size:"sm",variant:"ghost",onClick:Q,children:nt}),e[160]=nt,e[161]=ot):ot=e[161];let it;e[162]!==n?(it=n("settings.common.actions.rename"),e[162]=n,e[163]=it):it=e[163];let ft;e[164]!==ee||e[165]!==it?(ft=s.jsx(V,{size:"sm",onClick:ee,children:it}),e[164]=ee,e[165]=it,e[166]=ft):ft=e[166];let bt;e[167]!==ot||e[168]!==ft?(bt=s.jsxs(as,{children:[ot,ft]}),e[167]=ot,e[168]=ft,e[169]=bt):bt=e[169];let ht;e[170]!==et||e[171]!==lt||e[172]!==bt?(ht=s.jsxs($t,{children:[et,lt,bt]}),e[170]=et,e[171]=lt,e[172]=bt,e[173]=ht):ht=e[173];let Nt;e[174]!==vt||e[175]!==ht?(Nt=s.jsx(_t,{open:vt,onOpenChange:wt,children:ht}),e[174]=vt,e[175]=ht,e[176]=Nt):Nt=e[176];let At;return e[177]!==Re||e[178]!==Me||e[179]!==me||e[180]!==pt||e[181]!==Nt?(At=s.jsxs("div",{className:Re,children:[Me,me,pt,Nt]}),e[177]=Re,e[178]=Me,e[179]=me,e[180]=pt,e[181]=Nt,e[182]=At):At=e[182],At},Hl=t=>{const e=_e.c(47),{command:a,isSelected:n,onSelect:i,onDelete:o,onReset:r,onRename:d,onDuplicate:c,isMenuOpen:g,onMenuOpenChange:p}=t,{t:h}=Be();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Rr(),e[0]=f):f=e[0];const m=f,[v,C]=l.useState(!1);let b;e[1]!==o||e[2]!==c||e[3]!==d||e[4]!==r||e[5]!==h?(b=H=>s.jsxs(s.Fragment,{children:[d&&s.jsxs(H,{onClick:G=>{G.stopPropagation(),d()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),h("settings.common.actions.rename")]}),s.jsxs(H,{onClick:G=>{G.stopPropagation(),c()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),h("settings.common.actions.duplicate")]}),r&&s.jsxs(H,{onClick:G=>{G.stopPropagation(),r()},children:[s.jsx(B,{name:"restart",className:"h-4 w-4 mr-px"}),h("settings.common.actions.reset")]}),o&&s.jsxs(H,{onClick:G=>{G.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]})]}),e[1]=o,e[2]=c,e[3]=d,e[4]=r,e[5]=h,e[6]=b):b=e[6];const k=b,u=n?"bg-interactive-selection":"hover:bg-interactive-hover";let j;e[7]!==u?(j=Se("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",u),e[7]=u,e[8]=j):j=e[8];let N;e[9]===Symbol.for("react.memo_cache_sentinel")?(N=m?void 0:H=>{H.preventDefault(),C(!0)},e[9]=N):N=e[9];let w;e[10]!==j?(w=s.jsx("div",{className:j,onContextMenu:N}),e[10]=j,e[11]=w):w=e[11];let S;e[12]!==a.name?(S=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=S):S=e[13];let A;e[14]!==a||e[15]!==h?(A=(a.scope||Ha(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Ha(a)?h("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=h,e[16]=A):A=e[16];let x;e[17]!==S||e[18]!==A?(x=s.jsxs("div",{className:"flex items-center gap-2",children:[S,A]}),e[17]=S,e[18]=A,e[19]=x):x=e[19];let E;e[20]!==a.description?(E=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=E):E=e[21];let M;e[22]!==i||e[23]!==E||e[24]!==x?(M=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[x,E]}),e[22]=i,e[23]=E,e[24]=x,e[25]=M):M=e[25];let T;e[26]!==p?(T=H=>{H&&C(!1),p(H)},e[26]=p,e[27]=T):T=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(Wn,{asChild:!0,children:s.jsx(V,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=D):D=e[28];let R;e[29]!==k?(R=s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:k(xn)}),e[29]=k,e[30]=R):R=e[30];let O;e[31]!==g||e[32]!==T||e[33]!==R?(O=s.jsxs(Jn,{open:g,onOpenChange:T,children:[D,R]}),e[31]=g,e[32]=T,e[33]=R,e[34]=O):O=e[34];let I;e[35]!==M||e[36]!==O?(I=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[M,O]}),e[35]=M,e[36]=O,e[37]=I):I=e[37];let y;e[38]!==I||e[39]!==w?(y=s.jsx(Xa,{render:w,children:I}),e[38]=I,e[39]=w,e[40]=y):y=e[40];let L;e[41]!==k?(L=s.jsx(Ya,{className:"w-fit min-w-20",children:k(Za)}),e[41]=k,e[42]=L):L=e[42];let K;return e[43]!==v||e[44]!==y||e[45]!==L?(K=s.jsxs(ei,{open:v,onOpenChange:C,children:[y,L]}),e[43]=v,e[44]=y,e[45]=L,e[46]=K):K=e[46],K};function of(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function rf(t){return t.loadSkills}function lf(t){return t.name}function cf(t){return!Ha(t)}function df(t,e){return t.name.localeCompare(e.name)}function uf(t,e){return t.name.localeCompare(e.name)}const mf=()=>{const{t}=Be(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:o,setCommandDraft:r,setSelectedCommand:d}=Ja($s($=>({selectedCommandName:$.selectedCommandName,getCommandByName:$.getCommandByName,createCommand:$.createCommand,updateCommand:$.updateCommand,commandDraft:$.commandDraft,setCommandDraft:$.setCommandDraft,setSelectedCommand:$.setSelectedCommand}))),c=en(),g=Ja($=>sd($,c)),p=e?a(e,c):null,h=!!(o&&o.name===e&&!p),[f,m]=l.useState(""),[v,C]=l.useState("user"),[b,k]=l.useState(""),[u,j]=l.useState(""),[N,w]=l.useState(""),[S,A]=l.useState(""),[x,E]=l.useState(!1),[M,T]=l.useState(""),[D,R]=l.useState(!1),O=l.useRef(null),I=JSON.stringify([c,e]),y=l.useRef(null),L=l.useRef(null);l.useEffect(()=>{const $=y.current===I;if(y.current=I,h&&o){const Z=o.name||"",_=o.scope||"user",ne=o.description||"",X=o.agent||"",te=hi(o.model),he=te?`${te.providerID}/${te.modelID}`:"",je=te?.variant||"",fe=o.subagent===!0,ke=o.template||"";m(Z),C(_),k(ne),j(X),w(he),A(je),E(fe),T(ke),O.current={draftName:Z,draftScope:_,description:ne,agent:X,model:he,variant:je,subagent:fe,template:ke}}else if(p){const Z=p.description||"",_=p.agent||"",ne=hi(p.model),X=ne?`${ne.providerID}/${ne.modelID}`:"",te=ne?.variant||"",he=p.subagent===!0,je=p.template||"",fe=L.current,ke=[O.current,fe?.identity===I?fe.form:null];if($&&ke.some(be=>be&&be.description===Z&&be.agent===_&&be.model===X&&be.variant===te&&be.subagent===he&&be.template===je))return;k(Z),j(_),w(X),A(te),E(he),T(je),O.current={draftName:"",draftScope:"user",description:Z,agent:_,model:X,variant:te,subagent:he,template:je}}},[p,h,e,g,o,I]);const K=l.useCallback($=>{const Z=u.trim(),_=_n(N.trim()),ne=_?ed({providerID:_.providerId,modelID:_.modelId,variant:S.trim()||void 0}):null;return{name:$,description:b.trim()||void 0,agent:Z===""?null:Z,model:ne,subagent:x,template:M.trim(),scope:h?v:void 0}},[u,b,v,h,N,x,M,S]),H=l.useCallback(async()=>{const $=O.current,Z=e?.trim();if(h||!$||!Z||b.trim()===$.description.trim()&&u.trim()===$.agent.trim()&&N.trim()===$.model.trim()&&S.trim()===$.variant.trim()&&x===$.subagent&&M.trim()===$.template.trim())return Us;if(!M.trim())return xs(t("settings.commands.page.toast.templateRequired"));const ne=K(Z),X=hi(ne.model),te={identity:I,form:{...$,description:ne.description||"",agent:ne.agent||"",model:X?`${X.providerID}/${X.modelID}`:"",variant:X?.variant||"",subagent:ne.subagent===!0,template:ne.template||""}};L.current=te;try{return await i(Z,ne,c)?(y.current===I&&(O.current=te.form),Tn):xs(t("settings.commands.page.toast.updateFailed"))}finally{L.current===te&&(L.current=null)}},[u,K,b,I,h,N,e,c,x,t,M,i,S]),G=ti(H),{requestSave:W}=G,q=async()=>{const $=f.trim().replace(/\s+/g,"-");if(!$){U.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!M.trim()){U.error(t("settings.commands.page.toast.templateRequired"));return}if(g.some(Z=>Z.name===$)){U.error(t("settings.commands.sidebar.toast.commandExists"));return}R(!0);try{await n(K($),c)?(r(null),U.success(t("settings.commands.page.toast.created"))):U.error(t("settings.commands.page.toast.createFailed"))}catch(Z){console.error("Error creating command:",Z),U.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{R(!1)}},z=()=>{r(null),d(null)};return e?s.jsxs(ns,{title:h?t("settings.commands.page.title.new"):`/${e}`,description:t(h?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),onBlurCapture:G.onBlurCapture,children:[!h&&p&&s.jsx(Qr,{legacy:p.legacy===!0,path:p.path}),s.jsxs(He,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[h&&s.jsxs(Ct,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(Ge,{value:f,onChange:$=>m($.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Dt,{value:v,onValueChange:$=>C($),children:[s.jsx(Tt,{size:Qt,className:"w-fit min-w-[100px]",children:s.jsx(Jt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Et,{align:"end",children:[s.jsx(gt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(gt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(Rs,{value:b,onChange:$=>k($.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(He,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Ct,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(Fr,{agentName:u,onChange:$=>{j($),W()},className:Zs})}),s.jsx(Ct,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ga,{providerId:_n(N)?.providerId??"",modelId:_n(N)?.modelId??"",onChange:($,Z)=>{w($&&Z?`${$}/${Z}`:""),W()},className:Zs})}),s.jsx(Ct,{settingsItem:"commands.variant",label:t("settings.agents.page.field.variant"),info:t("settings.agents.page.field.variantTooltip"),children:s.jsx(Ge,{value:S,onChange:$=>A($.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!N&&!S,className:"h-8 w-40 rounded-md px-3"})}),s.jsx(Ct,{settingsItem:"commands.subagent",label:t("settings.commands.page.field.subagent"),info:t("settings.commands.page.field.subagentTooltip"),children:s.jsx(fa,{checked:x,onCheckedChange:$=>{E($),W()},"aria-label":t("settings.commands.page.field.subagent")})})]}),s.jsxs(He,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Rs,{value:M,onChange:$=>T($.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),h&&s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(V,{onClick:()=>{q()},disabled:D||!f.trim()||!M.trim(),size:"xs",className:"!font-normal",children:t(D?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(V,{variant:"ghost",onClick:z,disabled:D,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(B,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})};function Ys(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ii(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Cn(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function _i(t,e,a){const n=gf(a),i=typeof a.url=="string"?a.url.trim():"",o=ql(a,"env","environment"),r=ql(a,"headers"),d=Ys(a.oauth)?a.oauth:null,c=oi(d,"client_id","clientId"),g=oi(d,"client_secret","clientSecret"),p=oi(d,"scope"),h=oi(d,"redirect_uri","redirectUri"),f=pf(d,"callback_port","callbackPort"),m=oi(d,"auth_server_metadata_url","authServerMetadataUrl"),v=a.oauth===!1||a.oauth===null||a.oauth===void 0?!1:!!d&&!!(c||g||p||h||f||m),C=ff(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:o,headers:r,oauthEnabled:v,oauthClientId:c,oauthClientSecret:g,oauthScope:p,oauthRedirectUri:h,oauthCallbackPort:f,oauthAuthServerMetadataUrl:m,timeoutStartup:C.startup,timeoutCatalog:C.catalog,timeoutExecution:C.execution,codemode:a.codemode===!0?"on":a.codemode===!1?"off":"default",disabled:hf(a),protocol:pr.find(b=>b===a.protocol)??"legacy"}}function oi(t,...e){if(!t)return"";for(const a of e){const n=t[a];if(typeof n=="string"&&n.trim())return n.trim()}return""}function pf(t,...e){if(!t)return"";for(const a of e){const n=pi(t[a]);if(n)return n}return""}function pi(t){if(typeof t=="number"&&Number.isFinite(t)&&t>0)return String(Math.floor(t));if(typeof t=="string"&&t.trim()){const e=Number(t);if(Number.isFinite(e)&&e>0)return String(Math.floor(e))}return""}function gf(t){const e=t.command,a=t.args;if(ii(e)&&ii(a))return[...e,...a];if(ii(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return ii(a)?[...n,...a]:n}return ii(a)?a:[]}function ql(t,...e){for(const a of e){const n=t[a];if(!Ys(n))continue;const i=Object.entries(n).filter(([o,r])=>o&&typeof r=="string");if(i.length>0)return i.map(([o,r])=>({key:o,value:String(r)}))}return[]}function ff(t){return Ys(t.timeout)?{startup:pi(t.timeout.startup),catalog:pi(t.timeout.catalog),execution:pi(t.timeout.execution)}:{startup:"",catalog:"",execution:pi(t.timeout)}}function hf(t){return t.disabled===!0?!0:t.disabled===!1?!1:"enabled"in t?!t.enabled:!1}function xf(t){const e=t.mcpServers;if(Ys(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],o=e[i];if(Ys(o))return{name:i,entry:o}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const i=t[n];return n!=="mcpServers"&&Ys(i)});if(a.length===1){const n=a[0],i=t[n];if(Id(i))return{name:n,entry:i}}return null}function Id(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function bf(t,e){let a;try{const c=t.trim();if(!c)return Cn("No JSON content provided");a=JSON.parse(c)}catch(c){return Cn(c instanceof Error?`Invalid JSON: ${c.message}`:"Invalid JSON")}if(!Ys(a))return Cn("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(Ys(i)){const c=Object.keys(i);if(c.length===0)return Cn("mcpServers object is empty",a);if(c.length>1)return Cn("Paste one server at a time. Found "+c.length+" servers in mcpServers",a);const g=c[0],p=i[g];return Ys(p)?_i(g,$i(p),p):Cn("Server entry is not a valid object",a)}const o=n.mcp,r=Ys(o)&&Ys(o.servers)?o.servers:o;if(Ys(r)){const c=Object.keys(r);if(c.length===0)return Cn("mcp object is empty",a);if(c.length>1)return Cn("Paste one server at a time. Found "+c.length+" servers in mcp",a);const g=c[0],p=r[g];return Ys(p)?_i(g,$i(p),p):Cn("Server entry in mcp is not a valid object",a)}const d=xf(n);if(d)return _i(d.name,$i(d.entry),d.entry);if(Id(n)){const c=$i(n),g=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return _i(g,c,n)}return Cn("No recognizable MCP server configuration found in JSON",a)}function $i(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function vf(t,e,a){const n=a?.isNewServer??!1,i=t.name,o=n&&i?i:e.name??"";return{...e,name:o,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",oauthCallbackPort:t.type==="remote"?t.oauthCallbackPort:"",oauthAuthServerMetadataUrl:t.type==="remote"?t.oauthAuthServerMetadataUrl:"",timeoutStartup:t.type==="local"?t.timeoutStartup:"",timeoutCatalog:t.timeoutCatalog,timeoutExecution:t.timeoutExecution,codemode:t.codemode,disabled:t.disabled,protocol:t.protocol}}const yf=(t,e)=>!!e&&t!=="claude-code",jf=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,kf=t=>jf.exec(t)?.[0]??void 0,Ni=t=>t.type!=="external",Bi=t=>t.title??t.key,wf=(t,e)=>{if(e===void 0)return!1;const a=String(e),n=String(t.value);return t.op==="eq"?a===n:a!==n},Sf=(t,e)=>Ni(t)?(t.when??[]).every(a=>wf(a,e[a.key])):!0,Yr=(t,e)=>{const a={},n=[];for(const i of t){if(!Sf(i,a))continue;n.push(i);const o=e[i.key];Ni(i)&&o!==void 0&&(a[i.key]=o)}return n},Nf=t=>{const e={};for(const a of t)switch(a.type){case"external":break;case"boolean":e[a.key]=a.default??!1;break;case"number":case"integer":typeof a.default=="number"&&(e[a.key]=a.default);break;case"multiselect":e[a.key]=a.default??[];break;case"string":e[a.key]=a.default??a.options?.[0]?.value??"";break}return e},Pd=t=>t===void 0?!0:typeof t=="string"?t.trim().length===0:Array.isArray(t)?t.length===0:!1,Cf=(t,e)=>Yr(t,e).find(a=>Ni(a)&&a.required===!0&&Pd(e[a.key]))??null,If=(t,e)=>{const a={};for(const n of Yr(t,e)){if(!Ni(n))continue;const i=e[n.key];Pd(i)||i===void 0||(a[n.key]=typeof i=="string"?i.trim():i)}return a},Gl=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Wl=t=>typeof t=="string"&&t.length>0?t:void 0,Pf=(t,e,a)=>{const n=Gl(t)?t:{},i=Gl(n.data)?n.data:{};switch(n.name){case"IntegrationOauthAttemptMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"IntegrationOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"IntegrationOauthFailed":return e("settings.providers.page.auth.oauth.error.declined");case"IntegrationValidationFailed":return Wl(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return Wl(n.message)??e(a)}},Ho={phase:"idle"},Af=1500,wr=({integrationId:t,methods:e,onConnected:a,directory:n,className:i})=>{const{t:o}=Be(),r=l.useCallback(()=>n?Ts.getScopedSdkClient(n):Ts.getSdkClient(),[n]),[d,c]=l.useState(Ho),[g,p]=l.useState({}),[h,f]=l.useState(""),m=l.useRef(null),v=l.useCallback(D=>{m.current=null,r().integration.oauth.cancel({integrationID:t,attemptID:D}).catch(()=>{})},[t,r]);l.useEffect(()=>()=>{const D=m.current;D&&v(D)},[v]);const C=d.phase==="idle"?null:d.methodID,b=d.phase==="connecting"||d.phase==="waiting"||d.phase==="awaitingCode"&&d.submitting,k=async(D,R,O)=>{const I=await Va(D);if(I.ok){U.success(o(R));return}console.error("Failed to copy OAuth value:",I.error),U.error(o(O))},u=async()=>{m.current=null,c(Ho),U.success(o("settings.providers.page.toast.oauthCompleted")),await a()},j=(D,R,O)=>{m.current=null,console.error("OAuth flow failed:",R),c({phase:"failed",methodID:D,message:Pf(R,o,O)})},N=async(D,R)=>{const O=r();for(;m.current===R;){if(await new Promise(I=>setTimeout(I,Af)),m.current!==R)return;try{const{data:I}=await O.integration.oauth.status({integrationID:t,attemptID:R});if(m.current!==R)return;if(I.status==="complete"){await u();return}if(I.status==="failed"){c({phase:"failed",methodID:D,message:I.message}),m.current=null;return}}catch(I){if(m.current!==R)return;j(D,I,"settings.providers.page.toast.oauthCompleteFailed");return}}},w=async(D,R)=>{c({phase:"connecting",methodID:D.id});let O;try{const{data:I}=await r().integration.oauth.connect({integrationID:t,methodID:D.id,...Object.keys(R).length>0?{answer:R}:{}});O={attemptID:I.attemptID,mode:I.mode,url:I.url,instructions:I.instructions}}catch(I){j(D.id,I,"settings.providers.page.toast.oauthStartFailed");return}if(m.current=O.attemptID,yf(t,O.url)&&_s(O.url),O.mode==="code"){f(""),c({phase:"awaitingCode",methodID:D.id,attempt:O,submitting:!1});return}c({phase:"waiting",methodID:D.id,attempt:O}),await N(D.id,O.attemptID)},S=D=>{const R=(D.form??[]).filter(Ni);if(R.length===0){w(D,{});return}p(Nf(R)),c({phase:"prompting",methodID:D.id,fields:R,error:null})},A=D=>{if(d.phase!=="prompting")return;const R=Cf(d.fields,g);if(R){c({...d,error:o("settings.providers.page.auth.oauth.promptRequired",{field:Bi(R)})});return}w(D,If(d.fields,g))},x=async()=>{if(d.phase!=="awaitingCode")return;const D=h.trim();if(!D)return;const{methodID:R,attempt:O}=d;c({...d,submitting:!0});try{await r().integration.oauth.complete({integrationID:t,attemptID:O.attemptID,code:D}),await u()}catch(I){j(R,I,"settings.providers.page.toast.oauthCompleteFailed")}},E=()=>{(d.phase==="waiting"||d.phase==="awaitingCode")&&v(d.attempt.attemptID),c(Ho)},M=D=>{if(D.type==="external")return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:Bi(D)}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_s(D.url)},children:o("settings.providers.page.actions.open")})]},D.key);const R=g[D.key],O=typeof R=="string"?R:"",I=L=>p(K=>({...K,[D.key]:L})),y=D.type==="string"||D.type==="multiselect"?D.options??[]:[];return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:Bi(D)}),D.description&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:D.description}),y.length>0?s.jsxs(Dt,{value:O,onValueChange:I,children:[s.jsx(Tt,{size:Qt,className:fn,children:s.jsx(Jt,{children:L=>y.find(K=>K.value===L)?.label??null})}),s.jsx(Et,{children:y.map(L=>s.jsx(gt,{value:L.value,children:L.description?`${L.label} · ${L.description}`:L.label},L.value))})]}):D.type==="boolean"?s.jsx("input",{type:"checkbox",checked:R===!0,onChange:L=>I(L.target.checked),"aria-label":Bi(D)}):s.jsx(Ge,{value:O,onChange:L=>I(L.target.value),placeholder:D.type==="string"?D.placeholder:void 0,className:"max-w-[24rem] text-xs"})]},D.key)},T=D=>{const R=kf(D.instructions);return s.jsxs(s.Fragment,{children:[D.instructions&&s.jsx("p",{className:"typography-meta text-[var(--status-info-text)] bg-[var(--status-info-background)] px-2 py-1.5 rounded",children:D.instructions}),R&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ge,{value:R,readOnly:!0,"aria-label":o("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{k(R,"settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:o("settings.providers.page.actions.copyCode")})]}),D.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ge,{value:D.url,readOnly:!0,"aria-label":o("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_s(D.url)},children:o("settings.providers.page.actions.open")}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{k(D.url,"settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:o("settings.providers.page.actions.copy")})]})]})]})};return s.jsx("div",{className:Se("space-y-4",i),children:e.map(D=>{const R=C===D.id;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:D.label}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>S(D),disabled:b,children:o("settings.providers.page.actions.connect")})]}),R&&d.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Yr(d.fields,g).map(M),d.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:d.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{size:"xs",className:"!font-normal",onClick:()=>A(D),children:o("settings.providers.page.actions.continue")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:E,children:o("settings.providers.page.actions.cancel")})]})]}),R&&d.phase==="connecting"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(B,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),o("settings.providers.page.auth.oauth.starting")]}),R&&d.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[T(d.attempt),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(B,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),o("settings.providers.page.auth.oauth.waiting")]}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:E,children:o("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:o("settings.providers.page.auth.oauth.waitingHint")})]}),R&&d.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[T(d.attempt),s.jsx("p",{className:"typography-meta text-muted-foreground",children:o("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ge,{value:h,onChange:O=>f(O.target.value),placeholder:o("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:d.submitting}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:()=>{x()},disabled:d.submitting||h.trim().length===0,children:d.submitting?o("settings.providers.page.actions.saving"):o("settings.providers.page.actions.complete")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:E,disabled:d.submitting,children:o("settings.providers.page.actions.cancel")})]})]}),R&&d.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:d.message}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>S(D),children:o("settings.providers.page.actions.tryAgain")})]})]},D.id)})})},Tf=(t,e)=>t.find(a=>a.id.startsWith("mcp_")&&a.metadata?.source==="mcp"&&a.name===e),Ef=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),Df=({serverName:t,directory:e,onConnected:a})=>{const[n,i]=l.useState(null);l.useEffect(()=>{let r=!1;i(null);const d=e?Ts.getScopedSdkClient(e):Ts.getSdkClient();return(async()=>{try{const{data:g}=await d.integration.list();r||i(Tf(g,t)??null)}catch(g){console.error("Failed to load MCP integrations:",g)}})(),()=>{r=!0}},[e,t]);const o=Ef(n??void 0);return!n||o.length===0?null:s.jsx(wr,{integrationId:n.id,methods:o,directory:e,onConnected:a},n.id)},ao={oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:""},Mf=t=>t===!1?{...ao,oauthEnabled:!1}:t?{oauthEnabled:!0,oauthClientId:t.client_id??"",oauthClientSecret:t.client_secret??"",oauthScope:t.scope??"",oauthRedirectUri:t.redirect_uri??"",oauthCallbackPort:t.callback_port===void 0?"":String(t.callback_port)}:ao,Zr="grid grid-cols-1 gap-3 @xl:grid-cols-2 @3xl:grid-cols-3",Sr=Se("group flex min-h-[132px] flex-col rounded-xl border p-4 text-left transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]"),Rf={success:"bg-[var(--status-success)]/15 text-[var(--status-success)]",warning:"bg-[var(--status-warning)]/15 text-[var(--status-warning)]",error:"bg-[var(--status-error)]/15 text-[var(--status-error)]",info:"bg-[var(--status-info)]/15 text-[var(--status-info)]",neutral:"bg-[var(--surface-muted)] text-muted-foreground"},In=t=>{const e=_e.c(5),{tone:a,children:n}=t,i=Rf[a];let o;e[0]!==i?(o=Se("max-w-40 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",i),e[0]=i,e[1]=o):o=e[1];let r;return e[2]!==n||e[3]!==o?(r=s.jsx("span",{className:o,children:n}),e[2]=n,e[3]=o,e[4]=r):r=e[4],r},io=t=>{const e=_e.c(2),{children:a}=t;let n;return e[0]!==a?(n=s.jsx("span",{className:"shrink-0 rounded-full border border-[var(--interactive-border)] px-2 py-px text-[10px] font-medium",children:a}),e[0]=a,e[1]=n):n=e[1],n},Ad=t=>{const e=_e.c(5),{action:a}=t;let n;e[0]!==a.icon?(n=a.icon?s.jsx(B,{name:a.icon,className:"size-4"}):null,e[0]=a.icon,e[1]=n):n=e[1];let i;return e[2]!==a.label||e[3]!==n?(i=s.jsxs(s.Fragment,{children:[n,a.label]}),e[2]=a.label,e[3]=n,e[4]=i):i=e[4],i},ji=t=>{const e=_e.c(57),{icon:a,title:n,subtitle:i,badges:o,footer:r,muted:d,onOpen:c,actions:g,actionsLabel:p}=t,h=(g?.length??0)>0,f=d&&"opacity-60";let m;e[0]!==f?(m=Se("flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",f),e[0]=f,e[1]=m):m=e[1];let v;e[2]!==a||e[3]!==m?(v=s.jsx("span",{className:m,children:a}),e[2]=a,e[3]=m,e[4]=v):v=e[4];let C;e[5]!==o?(C=o?s.jsx("span",{className:"flex min-w-0 flex-wrap justify-end gap-1",children:o}):null,e[5]=o,e[6]=C):C=e[6];let b;e[7]!==v||e[8]!==C?(b=s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[v,C]}),e[7]=v,e[8]=C,e[9]=b):b=e[9];const k=d&&"opacity-60";let u;e[10]!==k?(u=Se("mt-3 min-w-0",k),e[10]=k,e[11]=u):u=e[11];let j;e[12]!==n?(j=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",title:n,children:n}),e[12]=n,e[13]=j):j=e[13];let N;e[14]!==i?(N=i?s.jsx("div",{className:"mt-0.5 truncate font-mono typography-micro text-muted-foreground",title:i,children:i}):null,e[14]=i,e[15]=N):N=e[15];let w;e[16]!==u||e[17]!==j||e[18]!==N?(w=s.jsxs("div",{className:u,children:[j,N]}),e[16]=u,e[17]=j,e[18]=N,e[19]=w):w=e[19];const S=h&&"pr-8";let A;e[20]!==S?(A=Se("mt-auto flex min-w-0 items-center gap-2 pt-3 typography-micro text-muted-foreground",S),e[20]=S,e[21]=A):A=e[21];let x;e[22]!==h||e[23]!==c?(x=c&&!h?s.jsx(B,{name:"arrow-right-s",className:"ml-auto size-4 shrink-0 opacity-0 transition-opacity duration-150 group-hover:opacity-70 group-focus-visible:opacity-70","aria-hidden":!0}):null,e[22]=h,e[23]=c,e[24]=x):x=e[24];let E;e[25]!==r||e[26]!==A||e[27]!==x?(E=s.jsxs("div",{className:A,children:[r,x]}),e[25]=r,e[26]=A,e[27]=x,e[28]=E):E=e[28];let M;e[29]!==w||e[30]!==E||e[31]!==b?(M=s.jsxs(s.Fragment,{children:[b,w,E]}),e[29]=w,e[30]=E,e[31]=b,e[32]=M):M=e[32];const T=M;let D;e[33]!==T||e[34]!==c?(D=c?s.jsx("button",{type:"button",onClick:c,className:Se(Sr,"h-full w-full border-[var(--interactive-border)] bg-[var(--surface-elevated)] hover:border-[var(--interactive-border-hover)] hover:bg-[var(--interactive-hover)]/50"),children:T}):s.jsx("div",{className:Se(Sr,"h-full border-[var(--interactive-border)] bg-[var(--surface-elevated)]"),children:T}),e[33]=T,e[34]=c,e[35]=D):D=e[35];const R=D;if(!h||!g)return R;let O;e[36]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx("div",{className:"group relative"}),e[36]=O):O=e[36];let I;e[37]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(B,{name:"more-2",className:"size-4"}),e[37]=I):I=e[37];let y;e[38]!==p?(y=s.jsx(Wn,{asChild:!0,children:s.jsx(V,{variant:"ghost",size:"icon",className:"absolute bottom-3 right-3 h-7 w-7 text-muted-foreground opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100 md:focus-visible:opacity-100 data-[state=open]:opacity-100","aria-label":p,title:p,children:I})}),e[38]=p,e[39]=y):y=e[39];let L;e[40]!==g?(L=g.map(Of),e[40]=g,e[41]=L):L=e[41];let K;e[42]!==L?(K=s.jsx(Gn,{align:"end",className:"w-fit min-w-32",children:L}),e[42]=L,e[43]=K):K=e[43];let H;e[44]!==y||e[45]!==K?(H=s.jsxs(Jn,{children:[y,K]}),e[44]=y,e[45]=K,e[46]=H):H=e[46];let G;e[47]!==R||e[48]!==H?(G=s.jsxs(Xa,{render:O,children:[R,H]}),e[47]=R,e[48]=H,e[49]=G):G=e[49];let W;e[50]!==g?(W=g.map(Lf),e[50]=g,e[51]=W):W=e[51];let q;e[52]!==W?(q=s.jsx(Ya,{className:"w-fit min-w-32",children:W}),e[52]=W,e[53]=q):q=e[53];let z;return e[54]!==G||e[55]!==q?(z=s.jsxs(ei,{children:[G,q]}),e[54]=G,e[55]=q,e[56]=z):z=e[56],z},Xr=t=>{const e=_e.c(11),{label:a,hint:n,onClick:i,settingsItem:o}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=Se(Sr,"items-center justify-center gap-2 border-dashed border-[var(--interactive-border)] text-muted-foreground hover:bg-[var(--interactive-hover)]/50 hover:text-foreground"),e[0]=r):r=e[0];let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx("span",{className:"flex size-10 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(B,{name:"add",className:"size-5"})}),e[1]=d):d=e[1];let c;e[2]!==a?(c=s.jsx("span",{className:"typography-ui-label font-medium",children:a}),e[2]=a,e[3]=c):c=e[3];let g;e[4]!==n?(g=n?s.jsx("span",{className:"typography-micro",children:n}):null,e[4]=n,e[5]=g):g=e[5];let p;return e[6]!==i||e[7]!==o||e[8]!==c||e[9]!==g?(p=s.jsxs("button",{type:"button",onClick:i,"data-settings-item":o,className:r,children:[d,c,g]}),e[6]=i,e[7]=o,e[8]=c,e[9]=g,e[10]=p):p=e[10],p},el=t=>{const e=_e.c(7),{value:a,onChange:n,placeholder:i}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(B,{name:"search",className:"pointer-events-none absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground","aria-hidden":!0}),e[0]=o):o=e[0];let r;e[1]!==n?(r=c=>n(c.target.value),e[1]=n,e[2]=r):r=e[2];let d;return e[3]!==i||e[4]!==r||e[5]!==a?(d=s.jsxs("div",{className:"relative mb-4 max-w-[24rem]",children:[o,s.jsx(Ge,{value:a,onChange:r,placeholder:i,"aria-label":i,className:"h-9 pl-8"})]}),e[3]=i,e[4]=r,e[5]=a,e[6]=d):d=e[6],d},tl=t=>{const e=_e.c(4),{label:a,onClick:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(B,{name:"arrow-left-s",className:"size-4"}),e[0]=i):i=e[0];let o;return e[1]!==a||e[2]!==n?(o=s.jsx(V,{variant:"ghost",size:"icon",className:"-ml-2 h-7 w-7 shrink-0",onClick:n,"aria-label":a,title:a,children:i}),e[1]=a,e[2]=n,e[3]=o):o=e[3],o},Nr=t=>{const e=_e.c(2),{name:a}=t;let n;return e[0]!==a?(n=s.jsx(B,{name:a,className:"size-5 text-muted-foreground"}),e[0]=a,e[1]=n):n=e[1],n};function Of(t){return s.jsx(xn,{variant:t.destructive?"destructive":"default",onClick:t.onSelect,children:s.jsx(Ad,{action:t})},t.label)}function Lf(t){return s.jsx(Za,{className:Se(t.destructive&&"text-destructive focus:text-destructive"),onClick:t.onSelect,children:s.jsx(Ad,{action:t})},t.label)}const Ff=t=>{const e="new-mcp-server";let a=e,n=1;for(;t.some(i=>i.name===a);)a=`${e}-${n}`,n+=1;return a},Kf=t=>{const e=_e.c(9),{status:a,enabled:n}=t,{t:i}=Be();if(!n){let c;e[0]!==i?(c=i("settings.mcp.grid.status.disabled"),e[0]=i,e[1]=c):c=e[1];let g;return e[2]!==c?(g=s.jsx(In,{tone:"neutral",children:c}),e[2]=c,e[3]=g):g=e[3],g}let o;e[4]!==a||e[5]!==i?(o=a==="connected"?{tone:"success",label:i("settings.mcp.page.status.label.connected")}:a==="failed"?{tone:"error",label:i("settings.mcp.page.status.label.failed")}:a==="needs_auth"?{tone:"warning",label:i("settings.mcp.page.status.label.needsAuth")}:a==="pending"?{tone:"neutral",label:i("settings.mcp.grid.status.pending")}:null,e[4]=a,e[5]=i,e[6]=o):o=e[6];const r=o;let d;return e[7]!==r?(d=r?s.jsx(In,{tone:r.tone,children:r.label}):null,e[7]=r,e[8]=d):d=e[8],d},zf=()=>{const t=_e.c(130),{t:e}=Be(),a=en(),{setSelectedMcp:n,setMcpDraft:i,loadMcpConfigs:o,deleteMcp:r}=Un($s(Uf)),[d,c]=l.useState(null),[g,p]=l.useState(!1);let h;t[0]!==a?(h=Me=>Or(Me,a),t[0]=a,t[1]=h):h=t[1];const f=Un(h);let m;t[2]!==a?(m=Me=>Me.getStatusForDirectory(a),t[2]=a,t[3]=m):m=t[3];const v=pn(m),C=pn(_f),b=pn($f),[k,u]=l.useState(!1),[j,N]=l.useState("");let w,S;t[4]!==o||t[5]!==a?(w=()=>{o({directory:a})},S=[o,a],t[4]=o,t[5]=a,t[6]=w,t[7]=S):(w=t[6],S=t[7]),l.useEffect(w,S);let A;t[8]!==b||t[9]!==k||t[10]!==C||t[11]!==a?(A=()=>{if(k)return;u(!0);const Me=new Promise(Bf);Promise.all([C({directory:a,silent:!0}),Me]).then(()=>{const me=b(a);me&&U.error(me)}).finally(()=>u(!1))},t[8]=b,t[9]=k,t[10]=C,t[11]=a,t[12]=A):A=t[12];const x=A;let E;t[13]!==f||t[14]!==i||t[15]!==n?(E=()=>{const Me=Ff(f),me={name:Me,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],...ao,oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1};i(me),n(Me)},t[13]=f,t[14]=i,t[15]=n,t[16]=E):E=t[16];const M=E;let T;t[17]!==r||t[18]!==d||t[19]!==a||t[20]!==e?(T=async()=>{if(!d)return;const Me=d;p(!0);const me=await r(Me,a);me.ok?(me.reloadFailed?U.warning(me.message||e("settings.mcp.page.toast.serverDeletedReloadFailed",{name:Me}),{description:me.warning||e("settings.mcp.page.toast.refreshListIfStale")}):U.success(me.message||e("settings.mcp.page.toast.serverDeleted",{name:Me})),c(null)):U.error(e("settings.mcp.page.toast.deleteFailed")),p(!1)},t[17]=r,t[18]=d,t[19]=a,t[20]=e,t[21]=T):T=t[21];const D=T;let R,O,I,y,L,K,H,G,W;if(t[22]!==M||t[23]!==x||t[24]!==k||t[25]!==v||t[26]!==j||t[27]!==f||t[28]!==i||t[29]!==n||t[30]!==e){const Me=sa([...f],j,Vf);let me;t[40]!==j?(me=j.trim(),t[40]=j,t[41]=me):me=t[41];const Te=me.length>0;R=ns,t[42]!==e?(O=e("settings.page.mcp.title"),t[42]=e,t[43]=O):O=t[43],t[44]!==e?(I=e("settings.mcp.grid.description"),t[44]=e,t[45]=I):I=t[45];let Oe;t[46]===Symbol.for("react.memo_cache_sentinel")?(Oe=s.jsx(Si,{className:"min-w-0 flex-1 @xl:w-56 @xl:flex-none"}),t[46]=Oe):Oe=t[46];let pe;t[47]!==e?(pe=e("settings.mcp.sidebar.actions.refreshStatusAria"),t[47]=e,t[48]=pe):pe=t[48];let xe;t[49]!==e?(xe=e("settings.mcp.sidebar.actions.refreshStatusTitle"),t[49]=e,t[50]=xe):xe=t[50];const ae=k&&"animate-spin";let ie;t[51]!==ae?(ie=Se("size-4",ae),t[51]=ae,t[52]=ie):ie=t[52];let ge;t[53]!==ie?(ge=s.jsx(B,{name:"refresh",className:ie}),t[53]=ie,t[54]=ge):ge=t[54],t[55]!==x||t[56]!==k||t[57]!==pe||t[58]!==xe||t[59]!==ge?(y=s.jsxs("div",{className:"flex w-full items-center gap-2 @xl:w-auto",children:[Oe,s.jsx(V,{variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0 text-muted-foreground",disabled:k,onClick:x,"aria-label":pe,title:xe,children:ge})]}),t[55]=x,t[56]=k,t[57]=pe,t[58]=xe,t[59]=ge,t[60]=y):y=t[60],t[61]!==j||t[62]!==f.length||t[63]!==e?(L=f.length>0?s.jsx(el,{value:j,onChange:N,placeholder:e("settings.mcp.grid.searchPlaceholder")}):null,t[61]=j,t[62]=f.length,t[63]=e,t[64]=L):L=t[64],K=f.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:e("settings.mcp.grid.empty")}):Me.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:e("settings.mcp.grid.noMatches",{query:j.trim()})}):null,H=Zr,t[65]!==M||t[66]!==Te||t[67]!==e?(G=Te?null:s.jsx(Xr,{label:e("settings.mcp.sidebar.actions.addServerTitle"),hint:e("settings.mcp.grid.addHint"),onClick:M,settingsItem:"mcp.create"}),t[65]=M,t[66]=Te,t[67]=e,t[68]=G):G=t[68];let Ee;t[69]!==v||t[70]!==i||t[71]!==n||t[72]!==e?(Ee=Ke=>{const Le=Ke.disabled!==!0,Ne=Ke.type==="local"?Ke.command?.join(" "):Ke.url;return s.jsx(ji,{icon:s.jsx(Nr,{name:Ke.type==="local"?"server":"global"}),title:Ke.name,subtitle:Ne||void 0,badges:s.jsx(Kf,{status:v[Ke.name]?.status.status,enabled:Le}),muted:!Le,footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Ke.type==="local"?e("settings.mcp.sidebar.serverType.localTitle"):e("settings.mcp.sidebar.serverType.remoteTitle")}),Ke.scope==="project"?s.jsx(io,{children:e("settings.mcp.grid.scope.project")}):null]}),onOpen:()=>{i(null),n(Ke.name)},actionsLabel:e("settings.mcp.grid.actionsAria",{name:Ke.name}),actions:[{label:e("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>c(Ke.name)}]},Ke.name)},t[69]=v,t[70]=i,t[71]=n,t[72]=e,t[73]=Ee):Ee=t[73],W=Me.map(Ee),t[22]=M,t[23]=x,t[24]=k,t[25]=v,t[26]=j,t[27]=f,t[28]=i,t[29]=n,t[30]=e,t[31]=R,t[32]=O,t[33]=I,t[34]=y,t[35]=L,t[36]=K,t[37]=H,t[38]=G,t[39]=W}else R=t[31],O=t[32],I=t[33],y=t[34],L=t[35],K=t[36],H=t[37],G=t[38],W=t[39];let q;t[74]!==H||t[75]!==G||t[76]!==W?(q=s.jsxs("div",{className:H,children:[G,W]}),t[74]=H,t[75]=G,t[76]=W,t[77]=q):q=t[77];const z=d!==null;let $;t[78]!==g?($=Me=>{!Me&&!g&&c(null)},t[78]=g,t[79]=$):$=t[79];const Z=d??"";let _;t[80]!==e||t[81]!==Z?(_=e("settings.mcp.page.deleteDialog.title",{name:Z}),t[80]=e,t[81]=Z,t[82]=_):_=t[82];let ne;t[83]!==_?(ne=s.jsx(Ht,{children:_}),t[83]=_,t[84]=ne):ne=t[84];let X;t[85]!==e?(X=e("settings.mcp.page.deleteDialog.descriptionPrefix"),t[85]=e,t[86]=X):X=t[86];let te;t[87]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),t[87]=te):te=t[87];let he;t[88]!==e?(he=e("settings.mcp.page.deleteDialog.descriptionSuffix"),t[88]=e,t[89]=he):he=t[89];let je;t[90]!==X||t[91]!==he?(je=s.jsxs(qt,{children:[X," ",te,"."," ",he]}),t[90]=X,t[91]=he,t[92]=je):je=t[92];let fe;t[93]!==ne||t[94]!==je?(fe=s.jsxs(Vt,{children:[ne,je]}),t[93]=ne,t[94]=je,t[95]=fe):fe=t[95];let ke;t[96]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>c(null),t[96]=ke):ke=t[96];let be;t[97]!==e?(be=e("settings.common.actions.cancel"),t[97]=e,t[98]=be):be=t[98];let De;t[99]!==g||t[100]!==be?(De=s.jsx(V,{variant:"outline",size:"sm",onClick:ke,disabled:g,children:be}),t[99]=g,t[100]=be,t[101]=De):De=t[101];let oe;t[102]!==D?(oe=()=>{D()},t[102]=D,t[103]=oe):oe=t[103];let ee;t[104]!==g||t[105]!==e?(ee=e(g?"settings.mcp.page.actions.deleting":"settings.common.actions.delete"),t[104]=g,t[105]=e,t[106]=ee):ee=t[106];let ce;t[107]!==g||t[108]!==oe||t[109]!==ee?(ce=s.jsx(V,{variant:"destructive",size:"sm",onClick:oe,disabled:g,children:ee}),t[107]=g,t[108]=oe,t[109]=ee,t[110]=ce):ce=t[110];let ue;t[111]!==De||t[112]!==ce?(ue=s.jsxs(as,{children:[De,ce]}),t[111]=De,t[112]=ce,t[113]=ue):ue=t[113];let Ie;t[114]!==fe||t[115]!==ue?(Ie=s.jsxs($t,{className:"max-w-md",children:[fe,ue]}),t[114]=fe,t[115]=ue,t[116]=Ie):Ie=t[116];let ve;t[117]!==z||t[118]!==$||t[119]!==Ie?(ve=s.jsx(_t,{open:z,onOpenChange:$,children:Ie}),t[117]=z,t[118]=$,t[119]=Ie,t[120]=ve):ve=t[120];let Re;return t[121]!==R||t[122]!==O||t[123]!==I||t[124]!==y||t[125]!==L||t[126]!==K||t[127]!==q||t[128]!==ve?(Re=s.jsxs(R,{title:O,description:I,headerEnd:y,children:[L,K,q,ve]}),t[121]=R,t[122]=O,t[123]=I,t[124]=y,t[125]=L,t[126]=K,t[127]=q,t[128]=ve,t[129]=Re):Re=t[129],Re};function Uf(t){return{setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function _f(t){return t.refresh}function $f(t){return t.getErrorForDirectory}function Bf(t){return setTimeout(t,500)}function Vf(t){return[t.name,t.type==="local"?t.command?.join(" ")??"":t.url??""]}const qo=t=>t===void 0?"":String(t),Go=t=>{const e=t.trim();if(!e)return null;const a=Number(e);return!Number.isFinite(a)||a<=0?null:a%1e3===0?`${a/1e3}s`:`${a}ms`},Wo={legacy:"settings.mcp.page.advanced.protocolOption.legacy",auto:"settings.mcp.page.advanced.protocolOption.auto","2026-07-28":"settings.mcp.page.advanced.protocolOption.revision20260728"},Jl={default:"settings.mcp.page.advanced.codemodeOption.default",on:"settings.mcp.page.advanced.codemodeOption.on",off:"settings.mcp.page.advanced.codemodeOption.off"},Hf=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},ri=t=>t?.status.status,Jo=t=>t?.status.status==="failed"||t?.status.status==="needs_auth"?t.status.error:void 0;function Td(t){const e=[];let a="",n=!1,i=!1;for(let o=0;o<t.length;o++){const r=t[o];if(r==="'"&&!i){n=!n;continue}if(r==='"'&&!n){i=!i;continue}if((r===" "||r===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=r}return a&&e.push(a),e}const qf=t=>{const e=_e.c(27),{value:a,onChange:n,preview:i,onDetectUrl:o}=t;let r;e[0]!==a?(r=()=>a.join(`
5
+ `),e[0]=a,e[1]=r):r=e[1];const[d,c]=l.useState(r),g=l.useRef(a);let p,h;e[2]!==a?(p=()=>{JSON.stringify(g.current)!==JSON.stringify(a)&&(g.current=a,c(a.join(`
6
+ `)))},h=[a],e[2]=a,e[3]=p,e[4]=h):(p=e[3],h=e[4]),l.useEffect(p,h);let f;e[5]!==n||e[6]!==o?(f=S=>{const A=S.split(`
7
+ `).filter(Xf);if(o&&A.length===1&&/^https?:\/\/\S+$/i.test(A[0].trim())){o(A[0].trim());return}n(A)},e[5]=n,e[6]=o,e[7]=f):f=e[7];const m=f;let v;e[8]!==n?(v=S=>{const x=S.clipboardData.getData("text").trim();if(!x||x.includes(`
8
+ `)||!/\s/.test(x))return;const E=S.currentTarget;if(E.selectionStart!==0||E.selectionEnd!==E.value.length)return;S.preventDefault();const M=Td(x);c(M.join(`
9
+ `)),n(M)},e[8]=n,e[9]=v):v=e[9];const C=v;let b;e[10]!==m?(b=S=>{c(S.target.value),m(S.target.value)},e[10]=m,e[11]=b):b=e[11];let k;e[12]!==m||e[13]!==d?(k=()=>{const S=d.split(`
10
+ `).map(eh).join(`
11
+ `);c(S),m(S)},e[12]=m,e[13]=d,e[14]=k):k=e[14];const u=Math.max(4,a.length+1);let j;e[15]!==C||e[16]!==b||e[17]!==k||e[18]!==u||e[19]!==d?(j=s.jsx(Rs,{onPaste:C,value:d,onChange:b,onBlur:k,placeholder:`npx
12
+ -y
13
+ @modelcontextprotocol/server-postgres
14
+ postgresql://user:pass@host/db`,rows:u,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=C,e[16]=b,e[17]=k,e[18]=u,e[19]=d,e[20]=j):j=e[20];let N;e[21]!==i||e[22]!==a?(N=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(th)})})]}),e[21]=i,e[22]=a,e[23]=N):N=e[23];let w;return e[24]!==N||e[25]!==j?(w=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[j,N]}),e[24]=N,e[25]=j,e[26]=w):w=e[26],w},Gf=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Ql=({value:t,onChange:e,onCommit:a,keyTransform:n=Gf,keyPlaceholder:i="API_KEY",keyInputClassName:o="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:d="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:g,clipboardReadFailed:p,keyLabel:h,valueLabel:f,valuePlaceholder:m,hideValueTitle:v,showValueTitle:C,addVariable:b,plainTextWarning:k,removeVariableAria:u})=>{const[j,N]=l.useState(new Set),w=()=>e([...t,{key:"",value:""}]),S=T=>{e(t.filter((D,R)=>R!==T)),a?.(),N(D=>{const R=new Set(D);return R.delete(T),R})},A=(T,D,R)=>{const O=[...t];O[T]={...O[T],[D]:R},e(O)},x=T=>{N(D=>{const R=new Set(D);return R.has(T)?R.delete(T):R.add(T),R})},E=async()=>{try{const T=await navigator.clipboard.readText(),D=[];for(const O of T.split(`
15
+ `)){const I=O.trim();if(!I||I.startsWith("#"))continue;const y=I.indexOf("=");if(y===-1)continue;const L=I.slice(0,y).trim();let K=I.slice(y+1).trim();(K.startsWith('"')&&K.endsWith('"')||K.startsWith("'")&&K.endsWith("'"))&&(K=K.slice(1,-1)),L&&D.push({key:L,value:K})}if(D.length===0){U.error(c);return}const R=[...t];for(const O of D){const I=R.findIndex(y=>y.key===O.key);I!==-1?R[I]=O:R.push(O)}e(R),a?.(),U.success(g(D.length))}catch{U.error(p)}},M=t.some(T=>T.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:h}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:f})]}),s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:E,type:"button",title:d,children:[s.jsx(B,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((T,D)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ge,{value:T.key,onChange:R=>A(D,"key",n(R.target.value)),placeholder:i,className:o,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Ge,{type:j.has(D)?"text":"password",value:T.value,onChange:R=>A(D,"value",R.target.value),placeholder:m,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>x(D),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:j.has(D)?v:C,children:j.has(D)?s.jsx(B,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>S(D),"aria-label":u,children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},D))}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:w,type:"button",children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),b]}),M&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:k})]})},Yl=t=>{const e=_e.c(14),{status:a,enabled:n,getStatusLabel:i,variant:o}=t,r=o===void 0?"compact":o;if(!n||!a)return null;let d,c;if(e[0]!==i||e[1]!==a||e[2]!==r){c=Symbol.for("react.early_return_sentinel");e:{const f={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(r==="pill"){const m=Se("typography-micro font-medium rounded-full px-2 py-0.5",f.text,f.bg);let v;e[5]!==i||e[6]!==a?(v=i(a),e[5]=i,e[6]=a,e[7]=v):v=e[7],c=s.jsxs("span",{className:m,children:["● ",v]});break e}d=Se("typography-micro font-medium",f.text)}e[0]=i,e[1]=a,e[2]=r,e[3]=d,e[4]=c}else d=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let g;e[8]!==i||e[9]!==a?(g=i(a),e[8]=i,e[9]=a,e[10]=g):g=e[10];let p;return e[11]!==d||e[12]!==g?(p=s.jsxs("span",{className:d,children:["● ",g]}),e[11]=d,e[12]=g,e[13]=p):p=e[13],p},Wf=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return a?.trim()||e("settings.mcp.page.status.description.needsAuth");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},Jf=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Qf=t=>t==="failed"||t==="needs_auth",Yf=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},Zf=()=>{const{t}=Be(),e=l.useCallback((Y,Pe)=>t(Y,Pe),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:o,getMcpByName:r,createMcp:d,updateMcp:c,deleteMcp:g}=Un($s(Y=>({selectedMcpName:Y.selectedMcpName,mcpDraft:Y.mcpDraft,setMcpDraft:Y.setMcpDraft,setSelectedMcp:Y.setSelectedMcp,getMcpByName:Y.getMcpByName,createMcp:Y.createMcp,updateMcp:Y.updateMcp,deleteMcp:Y.deleteMcp}))),p=en();l.useEffect(()=>()=>{const Y=Un.getState();Y.setSelectedMcp(null),Y.setMcpDraft(null)},[]);const h=pn(Y=>Y.getStatusForDirectory(p)),f=pn(Y=>Y.getDiagnosticForDirectory(p)),m=pn(Y=>Y.refresh),v=pn(Y=>Y.connect),C=pn(Y=>Y.disconnect),b=pn(Y=>Y.testConnection),k=Un(Y=>Or(Y,p)),u=a?r(a,p):null,j=!!(n&&n.name===a&&!u),[N,w]=l.useState(""),[S,A]=l.useState("user"),[x,E]=l.useState("local"),[M,T]=l.useState([]),[D,R]=l.useState(""),[O,I]=l.useState([]),[y,L]=l.useState([]),[K,H]=l.useState(""),[G,W]=l.useState(""),[q,z]=l.useState(""),[$,Z]=l.useState("default"),[_,ne]=l.useState("legacy"),[X,te]=l.useState(""),[he,je]=l.useState(ao),[fe,ke]=l.useState(!0),[be,De]=l.useState(!1),[oe,ee]=l.useState(!1),[ce,ue]=l.useState(!1),[Ie,ve]=l.useState(!1),[Re,Me]=l.useState(!1),[me,Te]=l.useState(!1),[Oe,pe]=l.useState(!1),[xe,ae]=l.useState(""),[ie,ge]=l.useState(null),Ee=l.useMemo(()=>Yf(a,p),[p,a]),Ke=l.useRef(Ee),Le=l.useRef(null),Ne=JSON.stringify([a,p,j]),Ve=l.useRef(Ne);Ve.current=Ne;const Ye=l.useRef(null),pt={mcpType:x,command:M,url:D,envEntries:O,headerEntries:y,timeoutStartup:K,timeoutCatalog:G,timeoutExecution:q,codemode:$,protocol:_,oauthAuthServerMetadataUrl:x==="remote"?X:"",enabled:fe},vt=l.useRef(pt);vt.current=pt;const wt=l.useCallback(()=>{ae(""),ge(null),pe(!0)},[]),yt=l.useCallback(async()=>{try{const Y=await navigator.clipboard.readText();ae(Y),ge(null)}catch{U.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),st=l.useCallback(()=>{const Y=bf(xe,{fallbackName:N});if(!Y.ok){ge(Y.error);return}const Je=vf(Y,{name:N,scope:S,type:x,command:M,url:D,environment:O,headers:y,timeoutStartup:K,timeoutCatalog:G,timeoutExecution:q,codemode:$,disabled:!fe,protocol:_,oauthAuthServerMetadataUrl:X},{isNewServer:j});w(Je.name),E(Je.type),T(Je.command??[]),R(Je.url??""),I(Je.environment??[]),L(Je.headers??[]),H(Je.timeoutStartup??""),W(Je.timeoutCatalog??""),z(Je.timeoutExecution??""),Z(Je.codemode??"default"),ke(Je.disabled!==!0),ne(Je.protocol??"legacy"),te(Je.oauthAuthServerMetadataUrl??""),pe(!1),ae(""),ge(null),U.success(t("settings.mcp.page.toast.configImported"))},[xe,N,S,x,M,D,O,y,_,X,K,G,q,$,fe,j,t]);l.useEffect(()=>{if(j&&n){Ye.current=null,w(n.name),A(n.scope||"user"),E(n.type),T(n.command),R(n.url),I(n.environment),L(n.headers),H(n.timeoutStartup),W(n.timeoutCatalog),z(n.timeoutExecution),Z(n.codemode),ne(n.protocol),te(n.oauthAuthServerMetadataUrl),je({oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,oauthCallbackPort:n.oauthCallbackPort}),ke(!n.disabled),Te(!1),Le.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,timeoutStartup:n.timeoutStartup,timeoutCatalog:n.timeoutCatalog,timeoutExecution:n.timeoutExecution,codemode:n.codemode,protocol:n.protocol,oauthAuthServerMetadataUrl:n.oauthAuthServerMetadataUrl,enabled:!n.disabled};return}if(u){A(u.scope==="project"?"project":"user");const Y=gl(u.environment),Pe=u.type==="remote"?u:null,Je=gl(Pe?.headers),se=u.type,We=se==="local"?u.command??[]:[],ut=Pe?.url??"",Ce=qo(u.timeout?.startup),qe=qo(u.timeout?.catalog),jt=qo(u.timeout?.execution),Ot=Au(u.codemode),Yt=u.protocol??"legacy",Zt=Mf(Pe?.oauth),Ft=Pe&&Pe.oauth?Pe.oauth.auth_server_metadata_url??"":"",ps=u.disabled!==!0;je(Zt);const gs=Le.current!==null&&JSON.stringify(Le.current)!==JSON.stringify(vt.current);if(Ye.current===Ne&&gs)return;Ye.current=Ne,E(se),T(We),R(ut),I(Y),L(Je),H(Ce),W(qe),z(jt),Z(Ot),ne(Yt),te(Ft),ke(ps),Te(!1),Le.current={mcpType:se,command:We,url:ut,envEntries:Y,headerEntries:Je,timeoutStartup:Ce,timeoutCatalog:qe,timeoutExecution:jt,codemode:Ot,protocol:Yt,oauthAuthServerMetadataUrl:Ft,enabled:ps}}},[u,a,p,j,n,Ne]);const rt=l.useMemo(()=>{const Y=X.trim();return!Y||Hf(Y)?null:t("settings.mcp.page.advanced.oauthMetadataUrlInvalid")},[X,t]),de=l.useMemo(()=>{const Y=[];x==="remote"&&y.length>0&&Y.push(`${y.length} ${t("settings.mcp.page.advanced.headers")}`);const Pe=x==="local"?Go(K):null;Pe&&Y.push(t("settings.mcp.page.advanced.summary.startup",{value:Pe}));const Je=Go(G);Je&&Y.push(t("settings.mcp.page.advanced.summary.catalog",{value:Je}));const se=Go(q);return se&&Y.push(t("settings.mcp.page.advanced.summary.execution",{value:se})),$==="on"&&Y.push(t("settings.mcp.page.advanced.summary.codemodeOn")),$==="off"&&Y.push(t("settings.mcp.page.advanced.summary.codemodeOff")),_!=="legacy"&&Y.push(t(Wo[_])),Y.join(" · ")},[$,y.length,x,_,t,G,q,K]),Ue=l.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(B,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(B,{name:"global",className:"h-3.5 w-3.5"})}],[t]),et=l.useCallback(Y=>{E("remote"),R(Y),T([])},[]),ze=l.useCallback(Y=>{R(Y);const Pe=Y.trim();Pe&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(Pe)&&/\s/.test(Pe)&&(E("local"),T(Td(Pe)),R(""))},[]),Ze=Y=>({name:Y,scope:S,type:x,command:M,url:D,environment:O,headers:y,...he,oauthAuthServerMetadataUrl:x==="remote"?X:"",protocol:_,timeoutStartup:K,timeoutCatalog:G,timeoutExecution:q,codemode:$,disabled:!fe}),lt=ti(async()=>{const Y=Le.current;if(j||!Y||!a||JSON.stringify(Y)===JSON.stringify({mcpType:x,command:M,url:D,envEntries:O,headerEntries:y,timeoutStartup:K,timeoutCatalog:G,timeoutExecution:q,codemode:$,protocol:_,oauthAuthServerMetadataUrl:x==="remote"?X:"",enabled:fe}))return Us;if(x==="local"&&M.filter(Boolean).length===0)return xs(t("settings.mcp.page.toast.localCommandRequired"));if(x==="remote"&&!D.trim())return xs(t("settings.mcp.page.toast.remoteUrlRequired"));if(x==="remote"&&rt)return xs(rt);const Pe=await c(a,Ze(a),p);return Pe.ok?Ve.current!==Ne?Tn:(Le.current={mcpType:x,command:M,url:D,envEntries:O,headerEntries:y,timeoutStartup:K,timeoutCatalog:G,timeoutExecution:q,codemode:$,protocol:_,oauthAuthServerMetadataUrl:x==="remote"?X:"",enabled:fe},await m({directory:p,silent:!0}),Pe.reloadFailed?xs(Pe.warning||Pe.message||t("settings.mcp.page.toast.savedReloadFailed")):Tn):xs(t("settings.mcp.page.toast.saveFailed"))}),{requestSave:Q}=lt,nt=async()=>{const Y=N.trim();if(!Y){U.error(t("settings.mcp.page.toast.nameRequired"));return}if(k.some(Pe=>Pe.name===Y)){U.error(t("settings.mcp.page.toast.serverNameExists"));return}if(x==="local"&&M.filter(Boolean).length===0){U.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(x==="remote"&&!D.trim()){U.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}if(x==="remote"&&rt){U.error(rt);return}De(!0);try{const Pe=await d(Ze(Y),p);Pe.ok?(i(null),o(Y),await m({directory:p,silent:!0}),Pe.reloadFailed?U.warning(Pe.message||t("settings.mcp.page.toast.serverCreatedReloadFailed"),{description:Pe.warning||t("settings.mcp.page.toast.retryRefreshHint")}):U.success(Pe.message||t("settings.mcp.page.toast.serverCreatedReloading"))):U.error(t("settings.mcp.page.toast.saveFailed"))}catch(Pe){U.error(Pe instanceof Error?Pe.message:t("settings.mcp.page.toast.unexpectedError"))}finally{De(!1)}},ot=()=>{i(null),o(null)},it=async()=>{if(!a)return;ue(!0);const Y=await g(a,p);Y.ok?(Y.reloadFailed?U.warning(Y.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:Y.warning||t("settings.mcp.page.toast.refreshListIfStale")}):U.success(Y.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),ee(!1)):U.error(t("settings.mcp.page.toast.deleteFailed")),ue(!1)},ft=async()=>{if(a)try{await v(a,p),U.success(t("settings.mcp.page.toast.connected"))}catch(Y){U.error(Y instanceof Error?Y.message:t("settings.mcp.page.toast.connectionTestFailed"))}},bt=async()=>{if(a){ve(!0);try{if(ri(h[a])==="connected")await C(a,p),U.success(t("settings.mcp.page.toast.disconnected"));else{await v(a,p),await m({directory:p,silent:!0});const Pe=pn.getState().getStatusForDirectory(p)[a],Je=ri(Pe);Je==="connected"?U.success(t("settings.mcp.page.toast.connected")):Je==="needs_auth"?U.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Je==="failed"?U.error(Jo(Pe)||t("settings.mcp.page.toast.connectionFailed")):U.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await m({directory:p,silent:!0})}catch(Y){U.error(Y instanceof Error?Y.message:t("settings.mcp.page.toast.connectionFailed"))}finally{ve(!1)}}},ht=l.useCallback(()=>j?(U.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):!0,[j,t]),Nt=l.useCallback(async(Y=!1)=>{try{await m({directory:p,silent:Y})}catch(Pe){Y||U.error(Pe instanceof Error?Pe.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[p,m,t]);l.useEffect(()=>{Nt(!0)},[Nt]),l.useEffect(()=>{Ke.current=Ee,ve(!1),Me(!1)},[Ee]);const At=l.useCallback(async()=>{if(!(!a||!ht())){if(!fe){U.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Me(!0);try{const Y=await b(a,p),Pe=ri(Y.status);Y.warning?U.warning(Y.warning):Pe==="connected"?U.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Pe==="needs_auth"?U.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Pe==="failed"?U.error(Jo(Y.status)||Y.error||t("settings.mcp.page.toast.connectionTestFailed")):Y.error?U.error(Y.error):U.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Y){U.error(Y instanceof Error?Y.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Me(!1)}}},[p,fe,ht,a,t,b]);if(!a)return s.jsx(zf,{});const $e=h[a],Xe=a?f[a]:void 0,mt=$e?ri($e):Xe?.status,Fe=$e?Jo($e):Xe?.error,J=ri($e)==="connected",ye=Wf(mt,e,Fe),Ae=Y=>{switch(Y){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");default:return Y}};return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:j?t("settings.mcp.page.header.newServer"):a,titleLeading:s.jsx(tl,{label:t("settings.mcp.page.back"),onClick:()=>{i(null),o(null)}}),titleAccessory:j?void 0:s.jsx(Yl,{status:mt,enabled:fe,getStatusLabel:Ae,variant:"pill"}),description:j?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(x==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:j?void 0:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(V,{variant:J?"outline":"default",size:"xs",className:"!font-normal",onClick:bt,disabled:Ie||!fe,children:t(Ie?"settings.mcp.page.actions.working":J?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),J&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{At()},disabled:Re||!fe,children:t(Re?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}),onBlurCapture:lt.onBlurCapture,children:[!j&&u&&s.jsx(Qr,{legacy:u.legacy===!0,path:u.path}),!j&&Qf(mt)&&s.jsx(He,{divider:!1,children:s.jsx("div",{className:Se("rounded-lg border p-3",Jf(mt)),children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Yl,{status:mt,enabled:fe,getStatusLabel:Ae})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ye}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:S==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:p??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),mt==="needs_auth"&&a&&s.jsx(Df,{serverName:a,directory:p,onConnected:ft}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!J&&s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{At()},disabled:Re||!fe,children:t(Re?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})})]})})}),s.jsxs(He,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:j?s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:wt,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(B,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[j&&s.jsxs(Ct,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(Ge,{value:N,onChange:Y=>w(Y.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(Dt,{value:S,onValueChange:Y=>A(Y),children:[s.jsxs(Tt,{size:Qt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(B,{name:S==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(S==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Et,{align:"end",children:[s.jsx(gt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(gt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(xt,{checked:fe,onChange:Y=>{ke(Y),Q()},label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(He,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(Hr,{items:Ue,activeId:x,onSelect:Y=>{E(Y),Q()},layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),x==="local"?s.jsx(qf,{value:M,onChange:T,preview:Y=>t("settings.mcp.page.connection.previewArgs",{count:Y}),onDetectUrl:et}):s.jsx(Ge,{value:D,onChange:Y=>ze(Y.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(x==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),s.jsx(He,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(bn,{open:me,onOpenChange:Te,children:[s.jsxs(vn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),de&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",de,")"]})]}),me?s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(B,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(yn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.protocol")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.protocolHint")})]}),s.jsxs(Dt,{value:_,onValueChange:Y=>{const Pe=pr.find(Je=>Je===Y);Pe&&(ne(Pe),Q())},children:[s.jsx(Tt,{size:Qt,className:"!h-7 w-full max-w-[16rem] px-2","aria-label":t("settings.mcp.page.advanced.protocol"),children:s.jsx("span",{className:"truncate",children:t(Wo[_])})}),s.jsx(Et,{children:pr.map(Y=>s.jsx(gt,{value:Y,children:t(Wo[Y])},Y))})]})]}),s.jsxs("div",{className:"space-y-2",children:[x==="local"&&s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.timeoutStartupMs")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.timeoutStartupHint")})]}),s.jsx(Ge,{type:"number",min:"1",step:"1",value:K,onChange:Y=>H(Y.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.timeoutCatalogMs")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.timeoutCatalogHint")})]}),s.jsx(Ge,{type:"number",min:"1",step:"1",value:G,onChange:Y=>W(Y.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.timeoutExecutionMs")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.timeoutExecutionHint")})]}),s.jsx(Ge,{type:"number",min:"1",step:"1",value:q,onChange:Y=>z(Y.target.value),placeholder:"30000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})]})]}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.codemode")}),s.jsxs(Gt,{children:[t("settings.mcp.page.advanced.codemodeHint")," ",t("settings.mcp.page.advanced.codemodeDefaultHint")]})]}),s.jsxs(Dt,{value:$,onValueChange:Y=>{const Pe=fl.find(Je=>Je===Y);Pe&&(Z(Pe),Q())},children:[s.jsx(Tt,{size:Qt,className:"!h-7 w-full max-w-[16rem] px-2","aria-label":t("settings.mcp.page.advanced.codemode"),children:s.jsx("span",{className:"truncate",children:t(Jl[$])})}),s.jsx(Et,{children:fl.map(Y=>s.jsx(gt,{value:Y,children:t(Jl[Y])},Y))})]})]}),x==="remote"&&s.jsxs("div",{children:[s.jsxs(An,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),y.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",y.length,")"]})]}),s.jsx(Ql,{value:y,onChange:L,onCommit:Q,keyTransform:Y=>Y.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Y=>t("settings.mcp.page.toast.importedVariablesCount",{count:Y}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]}),x==="remote"&&s.jsxs("div",{children:[s.jsx(An,{as:"div",className:"mb-2",children:t("settings.mcp.page.advanced.oauth")}),s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Pt,children:t("settings.mcp.page.advanced.oauthMetadataUrl")}),s.jsx(Gt,{children:t("settings.mcp.page.advanced.oauthMetadataUrlHint")})]}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx(Ge,{type:"url",value:X,onChange:Y=>te(Y.target.value),placeholder:t("settings.mcp.page.advanced.oauthMetadataUrlPlaceholder"),"aria-label":t("settings.mcp.page.advanced.oauthMetadataUrl"),"aria-invalid":rt?!0:void 0,className:"h-7 w-full max-w-[24rem] font-mono typography-meta px-2","data-bwignore":"true","data-1p-ignore":"true"}),rt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:rt})]})]})]})]})})]})}),s.jsx(He,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:O.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",O.length,")"]}):null,settingsItem:"mcp.environment",children:O.length===0?s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>I([{key:"",value:""}]),children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Ql,{value:O,onChange:I,onCommit:Q,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Y=>t("settings.mcp.page.toast.importedVariablesCount",{count:Y}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[j&&s.jsxs(s.Fragment,{children:[s.jsx(V,{onClick:()=>{nt()},disabled:be||!N.trim(),size:"xs",className:"!font-normal",children:t(be?"settings.common.actions.saving":"settings.common.actions.create")}),s.jsx(V,{variant:"ghost",onClick:ot,disabled:be,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]}),!j&&s.jsx(V,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ee(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(_t,{open:Oe,onOpenChange:Y=>{Y||(pe(!1),ae(""),ge(null))},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(qt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Rs,{value:xe,onChange:Y=>{ae(Y.target.value),ge(null)},placeholder:`{
16
+ "mcpServers": {
17
+ "postgres": {
18
+ "command": "npx",
19
+ "args": ["-y", "@modelcontextprotocol/server-postgres"]
20
+ }
21
+ }
22
+ }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),ie&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:ie}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:yt,type:"button",children:[s.jsx(B,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(as,{children:[s.jsx(V,{variant:"outline",onClick:()=>{pe(!1),ae(""),ge(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(V,{onClick:st,disabled:!xe.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(_t,{open:oe,onOpenChange:Y=>{!Y&&!ce&&ee(!1)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(qt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(as,{children:[s.jsx(V,{variant:"outline",onClick:()=>ee(!1),disabled:ce,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(V,{variant:"destructive",size:"sm",onClick:it,disabled:ce,children:t(ce?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Xf(t){return t.trim().length>0}function eh(t){return t.trimEnd()}function th(t,e){return s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",e,"]"]}),t]},e)}const sh=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function nh(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}const ah=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=Be(),i=zt(I=>I.createEntry),o=zt(I=>I.createFile),[r,d]=l.useState("npm"),[c,g]=l.useState(""),[p,h]=l.useState(""),[f,m]=l.useState(""),[v,C]=l.useState(""),[b,k]=l.useState(a),[u,j]=l.useState(!1),N=l.useCallback(()=>{g(""),h(""),m(""),C(""),k(a)},[a]);l.useEffect(()=>{t&&(d("npm"),N())},[t,N]);const w=I=>{I!==r&&(d(I),N())},S=l.useMemo(()=>nh(p),[p]),A=!S.ok,x=r==="file"&&f.trim()!==""&&!sh.test(f.trim()),E=(r==="npm"||r==="path")&&c.trim()==="",M=r==="file"&&v.trim()==="",T=r==="file"&&f.trim()==="",D=u||A||r==="npm"&&E||r==="path"&&E||r==="file"&&(T||x||M),R=async()=>{if(!D){j(!0);try{let I;r==="file"?I=await o({fileName:f.trim(),content:v,scope:b}):I=await i({spec:c.trim(),options:S.ok?S.value:void 0,scope:b}),I.ok?(U.success(I.message||n("settings.plugins.toast.created")),I.reloadFailed&&U.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):U.error(I.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{j(!1)}}},O=l.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(_t,{open:t,onOpenChange:I=>{!I&&u||e(I)},children:s.jsxs($t,{className:"max-w-xl",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:n("settings.plugins.dialog.add.title")}),s.jsx(qt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(Hr,{items:O,activeId:r,onSelect:I=>w(I),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(r==="npm"||r==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(Ge,{id:"plugin-spec",value:c,onChange:I=>g(I.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":E?!1:void 0,disabled:u}),E&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.options")}),s.jsx(Rs,{id:"plugin-options",value:p,onChange:I=>h(I.target.value),rows:5,className:"font-mono",hasError:A,disabled:u}),A&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),r==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(Ge,{id:"plugin-filename",value:f,onChange:I=>m(I.target.value),placeholder:"my-plugin.ts","aria-invalid":x||void 0,disabled:u}),x&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(Rs,{id:"plugin-content",value:v,onChange:I=>C(I.target.value),rows:16,className:"font-mono",disabled:u})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(I=>{const y=b===I,L=n(I==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>k(I),disabled:u,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(Kr,{checked:y,onChange:()=>k(I),ariaLabel:L}),s.jsx("span",{className:Se("typography-ui-label font-normal",y?"text-foreground":"text-foreground/60"),children:L})]},I)})})]})]}),s.jsxs(as,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:u,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(V,{size:"sm",onClick:()=>{R()},disabled:D,children:[u?s.jsx(B,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},ih=t=>t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t),Wa=t=>{const e=t.replace(/\\/g,"/"),a=[],[n,...i]=e.split("/");for(const r of i)if(!(r===""||r===".")){if(r===".."){a.pop();continue}a.push(r)}return`${/^[A-Za-z]:$/.test(n)?`${n.toUpperCase()}/`:"/"}${a.join("/")}`},oh=t=>Wa(`${t.replace(/\\/g,"/")}/..`),rh=t=>{try{const e=decodeURIComponent(new URL(t).pathname);return/^\/[A-Za-z]:\//.test(e)?e.slice(1):e}catch{return null}};function Ed(t,e){if(t.startsWith("file://")){const a=rh(t);return a?{kind:"local",path:Wa(a)}:null}return t.startsWith("./")||t.startsWith("../")?e?{kind:"local",path:Wa(`${oh(e)}/${t}`)}:null:ih(t)?{kind:"local",path:Wa(t)}:{kind:"package",target:t}}function Dd(t){return t?{kind:"local",path:Wa(t)}:null}const lh=(t,e)=>{if(t.kind==="package")return e.source.kind==="package"&&e.source.target===t.target;if(e.source.kind!=="local")return!1;const a=Wa(e.source.path);return a===t.path||a.startsWith(`${t.path}/`)};function Md(t,e){return e.filter(a=>lh(t,a))}function ch(t){const e=t.find(n=>n.state.kind==="failed");if(e&&e.state.kind==="failed")return{kind:"failed",error:e.state.error,ref:e.state.ref};const a=t[0];return a?{kind:"active",version:a.source.kind==="package"?a.source.version:null}:{kind:"notReported"}}function Rd(t){const e=t.flatMap(a=>a.source.kind==="package"?[a.source]:[]);return e.some(a=>a.updating)?"updating":e.some(a=>a.outdated)?"available":"none"}function Od(t){const e=_e.c(12),a=zt(dh),n=zr(la());let i;e:{if(a.kind==="idle"||a.scope!==n){let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={kind:"loading"},e[0]=g):g=e[0],i=g;break e}if(a.kind==="failed"||!t){let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g={kind:"unknown"},e[1]=g):g=e[1],i=g;break e}let o,r,d;if(e[2]!==a.plugins||e[3]!==t){const g=Md(t,a.plugins);o="known",r=ch(g),d=Rd(g),e[2]=a.plugins,e[3]=t,e[4]=o,e[5]=r,e[6]=d}else o=e[4],r=e[5],d=e[6];let c;e[7]!==o||e[8]!==r||e[9]!==d||e[10]!==t?(c={kind:o,load:r,update:d,target:t},e[7]=o,e[8]=r,e[9]=d,e[10]=t,e[11]=c):c=e[11],i=c}return i}function dh(t){return t.runtime}function Ld(t){const e=_e.c(4);let a;if(e[0]!==t){const o=zr(la());a=t?.kind==="package"?nd(o,t.target):null,e[0]=t,e[1]=a}else a=e[1];const n=a;let i;return e[2]!==n?(i=o=>n?o.packageUpdates[n]??null:null,e[2]=n,e[3]=i):i=e[3],zt(i)}const Zl=t=>{const e=_e.c(18),{target:a,spec:n}=t,{t:i}=Be(),o=Od(a),r=Ld(a);let d;e[0]!==n?(d=b=>n?b.registryInfo[n]:void 0,e[0]=n,e[1]=d):d=e[1];const c=zt(d),g=c?.kind==="npm-missing-package"||c?.kind==="npm-missing-version"||c?.kind==="npm-malformed"||c?.kind==="path-missing"||c?.kind==="path-unreadable",p=o.kind==="known"&&(o.update==="updating"||r?.kind==="running"),h=!p&&(c?.kind==="npm-ok"&&c.hasUpdate||o.kind==="known"&&o.update==="available");let f;e[2]!==g||e[3]!==i?(f=g?s.jsx(In,{tone:"error",children:i("settings.plugins.registry.banner.invalid.title")}):null,e[2]=g,e[3]=i,e[4]=f):f=e[4];let m;e[5]!==g||e[6]!==o.kind||e[7]!==o.load||e[8]!==i||e[9]!==p?(m=o.kind==="known"&&!g?p?s.jsx(In,{tone:"neutral",children:i("settings.plugins.update.running")}):o.load.kind==="failed"?s.jsx(In,{tone:"error",children:i("settings.plugins.status.failed.title")}):o.load.kind==="notReported"?s.jsx(In,{tone:"neutral",children:i("settings.plugins.status.notReported.title")}):s.jsx(In,{tone:"success",children:i("settings.plugins.status.loaded")}):null,e[5]=g,e[6]=o.kind,e[7]=o.load,e[8]=i,e[9]=p,e[10]=m):m=e[10];let v;e[11]!==i||e[12]!==h?(v=h?s.jsx(In,{tone:"info",children:i("settings.plugins.update.available.title")}):null,e[11]=i,e[12]=h,e[13]=v):v=e[13];let C;return e[14]!==f||e[15]!==m||e[16]!==v?(C=s.jsxs(s.Fragment,{children:[f,m,v]}),e[14]=f,e[15]=m,e[16]=v,e[17]=C):C=e[17],C},uh=t=>{const e=_e.c(54),{onAdd:a,onDelete:n}=t,{t:i}=Be(),{entries:o,files:r,setSelected:d,loadPlugins:c}=zt($s(mh)),g=zt(ph),p=zt(gh),h=zt(fh),f=zt(hh),m=zt(xh),v=zt(bh),C=zt(vh),b=zt(yh),k=zt(jh),u=zr(la()),j=m.kind==="failed"&&m.scope===u,N=m.kind==="ready"&&m.scope===u?m.plugins:null,[w,S]=l.useState("");let A,x;e[0]!==c?(A=()=>{c()},x=[c],e[0]=c,e[1]=A,e[2]=x):(A=e[1],x=e[2]),l.useEffect(A,x);let E;e[3]!==f||e[4]!==p||e[5]!==i?(E=async()=>{U.info(i("settings.plugins.toast.refreshing"));const[ue,Ie]=await Promise.all([p({force:!0}),f()]);ue||U.error(i("settings.plugins.toast.refreshFailed")),Ie||U.error(i("settings.plugins.toast.checkFailed"))},e[3]=f,e[4]=p,e[5]=i,e[6]=E):E=e[6];const M=E;let T;if(e[7]!==o||e[8]!==r){T=new Map;for(const ue of o)T.set(ue.id,Ed(ue.spec,ue.sourcePath));for(const ue of r)T.set(ue.id,Dd(ue.absolutePath));e[7]=o,e[8]=r,e[9]=T}else T=e[9];const D=T,R=ue=>{const Ie=D.get(ue);return!N||Ie?.kind!=="package"||C[nd(u,Ie.target)]?.kind==="running"?null:Rd(Md(Ie,N))==="available"?Ie.target:null},O=ue=>{const Ie=[],ve=v[ue.spec],Re=R(ue.id);if(ve?.kind==="npm-ok"&&ve.hasUpdate&&ve.latestVersion){const Me=ve.latestVersion;Ie.push({label:i("settings.plugins.registry.banner.updateAvailable.action",{latest:Me}),icon:"arrow-up-s",onSelect:()=>{b(ue.id).then(me=>{me.ok?U.success(i("settings.plugins.toast.updatedToLatest",{version:Me})):U.error(i("settings.plugins.toast.refreshFailed"))})}})}else Re&&Ie.push({label:i("settings.plugins.update.action"),icon:"arrow-up-s",onSelect:()=>{k(Re).then(Me=>{Me?U.success(i("settings.plugins.update.toast.done",{name:ue.spec})):U.error(i("settings.plugins.update.toast.failed",{name:ue.spec}))})}});return Ie.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>n({kind:"entry",id:ue.id,label:ue.spec})}),Ie},I=[...o.map(kh),...r.map(wh)],y=sa(I,w,Sh);let L;e[10]!==w?(L=w.trim(),e[10]=w,e[11]=L):L=e[11];const K=L.length>0,H=g||h,G=ns;let W;e[12]!==i?(W=i("settings.page.plugins.title"),e[12]=i,e[13]=W):W=e[13];let q;e[14]!==i?(q=i("settings.plugins.grid.description"),e[14]=i,e[15]=q):q=e[15];let z;e[16]!==j||e[17]!==i?(z=j?s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsx(B,{name:"question",className:"size-3.5"}),i("settings.plugins.status.sidebar.unavailable")]}):null,e[16]=j,e[17]=i,e[18]=z):z=e[18];let $;e[19]!==M?($=()=>{M()},e[19]=M,e[20]=$):$=e[20];let Z;e[21]!==i?(Z=i("settings.plugins.sidebar.actions.refresh"),e[21]=i,e[22]=Z):Z=e[22];let _;e[23]!==i?(_=i("settings.plugins.sidebar.actions.refresh"),e[23]=i,e[24]=_):_=e[24];const ne=H&&"animate-spin";let X;e[25]!==ne?(X=Se("size-4",ne),e[25]=ne,e[26]=X):X=e[26];let te;e[27]!==X?(te=s.jsx(B,{name:"refresh",className:X}),e[27]=X,e[28]=te):te=e[28];let he;e[29]!==H||e[30]!==_||e[31]!==te||e[32]!==$||e[33]!==Z?(he=s.jsx(V,{variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0 text-muted-foreground",onClick:$,disabled:H,"aria-label":Z,title:_,children:te}),e[29]=H,e[30]=_,e[31]=te,e[32]=$,e[33]=Z,e[34]=he):he=e[34];let je;e[35]!==he||e[36]!==z?(je=s.jsxs("div",{className:"flex items-center gap-2",children:[z,he]}),e[35]=he,e[36]=z,e[37]=je):je=e[37];const fe=I.length>0?s.jsx(el,{value:w,onChange:S,placeholder:i("settings.plugins.grid.searchPlaceholder")}):null,ke=I.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:i("settings.plugins.grid.empty")}):y.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:i("settings.plugins.grid.noMatches",{query:w.trim()})}):null,be=Zr;let De;e[38]!==K||e[39]!==a||e[40]!==i?(De=K?null:s.jsx(Xr,{label:i("settings.plugins.sidebar.actions.addTitle"),hint:i("settings.plugins.grid.addHint"),onClick:a,settingsItem:"plugins.create"}),e[38]=K,e[39]=a,e[40]=i,e[41]=De):De=e[41];const oe=y.map(ue=>{if(ue.kind==="entry"){const{entry:Re}=ue;return s.jsx(ji,{icon:s.jsx(Nr,{name:Re.parsedKind==="npm"?"code-box":"folder"}),title:Re.spec,badges:s.jsx(Zl,{target:D.get(Re.id)??null,spec:Re.spec}),footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Re.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path")}),Re.scope==="project"?s.jsx(io,{children:i("settings.plugins.grid.scope.project")}):null]}),onOpen:()=>d(Re.id),actionsLabel:i("settings.plugins.grid.actionsAria",{name:Re.spec}),actions:O(Re)},Re.id)}const{file:Ie}=ue,ve=Ie.kind==="package";return s.jsx(ji,{icon:s.jsx(Nr,{name:ve?"folder":"file-text"}),title:Ie.fileName,badges:s.jsx(Zl,{target:D.get(Ie.id)??null}),footer:s.jsxs(s.Fragment,{children:[s.jsx("span",{children:i(ve?"settings.plugins.sidebar.kind.package":"settings.plugins.sidebar.kind.file")}),Ie.scope==="project"?s.jsx(io,{children:i("settings.plugins.grid.scope.project")}):null]}),onOpen:ve?void 0:()=>d(Ie.id),actionsLabel:i("settings.plugins.grid.actionsAria",{name:Ie.fileName}),actions:ve?void 0:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onSelect:()=>n({kind:"file",id:Ie.id,label:Ie.fileName})}]},Ie.id)});let ee;e[42]!==be||e[43]!==De||e[44]!==oe?(ee=s.jsxs("div",{className:be,children:[De,oe]}),e[42]=be,e[43]=De,e[44]=oe,e[45]=ee):ee=e[45];let ce;return e[46]!==G||e[47]!==je||e[48]!==fe||e[49]!==ke||e[50]!==ee||e[51]!==W||e[52]!==q?(ce=s.jsxs(G,{title:W,description:q,headerEnd:je,children:[fe,ke,ee]}),e[46]=G,e[47]=je,e[48]=fe,e[49]=ke,e[50]=ee,e[51]=W,e[52]=q,e[53]=ce):ce=e[53],ce};function mh(t){return{entries:t.entries,files:t.files,setSelected:t.setSelected,loadPlugins:t.loadPlugins}}function ph(t){return t.isLoadingRegistry}function gh(t){return t.loadRegistryInfo}function fh(t){return t.isCheckingUpdates}function hh(t){return t.checkUpdates}function xh(t){return t.runtime}function bh(t){return t.registryInfo}function vh(t){return t.packageUpdates}function yh(t){return t.updateToLatest}function jh(t){return t.updatePackage}function kh(t){return{kind:"entry",entry:t}}function wh(t){return{kind:"file",file:t}}function Sh(t){return t.kind==="entry"?[t.entry.spec]:[t.file.fileName,t.file.absolutePath??""]}const Nh=({entryId:t,spec:e})=>{const{t:a}=Be(),n=zt(h=>h.registryInfo[e]),i=zt(h=>h.updateToLatest),[o,r]=l.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const h=n.latestVersion,f=n.currentVersion??"",m=async()=>{r(!0);try{(await i(t)).ok?U.success(a("settings.plugins.toast.updatedToLatest",{version:h})):U.error(a("settings.plugins.toast.refreshFailed"))}finally{r(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(B,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:f,latest:h})})]}),s.jsx(V,{variant:"default",size:"sm",onClick:()=>{m()},disabled:o,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:h})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(B,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const d=n.kind==="path-unreadable",c=d?"var(--status-warning)":"var(--status-error)",g=d?"alert":"error-warning",p=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(B,{name:g,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:c},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:p})]})]})},Xl=t=>{const e=_e.c(68),{target:a,name:n}=t,{t:i}=Be(),o=Od(a),r=Ld(a),d=zt(Ch),c=zt(Ih);if(o.kind==="loading")return null;if(o.kind==="unknown"){let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(B,{name:"question",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[0]=N):N=e[0];let w;e[1]!==i?(w=i("settings.plugins.status.unknown.title"),e[1]=i,e[2]=w):w=e[2];let S;e[3]!==w?(S=s.jsx("p",{className:"typography-label text-foreground",children:w}),e[3]=w,e[4]=S):S=e[4];let A;e[5]!==i?(A=i("settings.plugins.status.unknown.description"),e[5]=i,e[6]=A):A=e[6];let x;e[7]!==A?(x=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:A}),e[7]=A,e[8]=x):x=e[8];let E;e[9]!==S||e[10]!==x?(E=s.jsxs("div",{className:"flex-1 min-w-0",children:[S,x]}),e[9]=S,e[10]=x,e[11]=E):E=e[11];let M;e[12]!==d?(M=()=>{d()},e[12]=d,e[13]=M):M=e[13];let T;e[14]!==i?(T=i("settings.plugins.status.retry"),e[14]=i,e[15]=T):T=e[15];let D;e[16]!==M||e[17]!==T?(D=s.jsx(V,{variant:"outline",size:"sm",onClick:M,children:T}),e[16]=M,e[17]=T,e[18]=D):D=e[18];let R;return e[19]!==E||e[20]!==D?(R=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[N,E,D]}),e[19]=E,e[20]=D,e[21]=R):R=e[21],R}const{load:g,update:p}=o,h=o.target.kind==="package"?o.target.target:null,f=p==="updating"||r?.kind==="running";let m;e[22]!==n||e[23]!==h||e[24]!==i||e[25]!==c?(m=async()=>{if(!h)return;await c(h)?U.success(i("settings.plugins.update.toast.done",{name:n})):U.error(i("settings.plugins.update.toast.failed",{name:n}))},e[22]=n,e[23]=h,e[24]=i,e[25]=c,e[26]=m):m=e[26];const v=m;let C;e:{switch(g.kind){case"active":{let N;e[27]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(B,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]"}),e[27]=N):N=e[27];let w;e[28]!==g.version||e[29]!==i?(w=g.version?i("settings.plugins.status.loadedVersion",{version:g.version}):i("settings.plugins.status.loaded"),e[28]=g.version,e[29]=i,e[30]=w):w=e[30];let S;e[31]!==w?(S=s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-muted-foreground",children:[N,w]}),e[31]=w,e[32]=S):S=e[32],C=S;break e}case"notReported":{let N;e[33]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(B,{name:"time",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),e[33]=N):N=e[33];let w;e[34]!==i?(w=i("settings.plugins.status.notReported.title"),e[34]=i,e[35]=w):w=e[35];let S;e[36]!==w?(S=s.jsx("p",{className:"typography-label text-foreground",children:w}),e[36]=w,e[37]=S):S=e[37];let A;e[38]!==i?(A=i("settings.plugins.status.notReported.description"),e[38]=i,e[39]=A):A=e[39];let x;e[40]!==A?(x=s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:A}),e[40]=A,e[41]=x):x=e[41];let E;e[42]!==S||e[43]!==x?(E=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[N,s.jsxs("div",{className:"flex-1 min-w-0",children:[S,x]})]}),e[42]=S,e[43]=x,e[44]=E):E=e[44],C=E;break e}case"failed":{let N;e[45]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(B,{name:"error-warning",className:"h-5 w-5 text-[var(--status-error)] shrink-0 mt-0.5"}),e[45]=N):N=e[45];let w;e[46]!==i?(w=i("settings.plugins.status.failed.title"),e[46]=i,e[47]=w):w=e[47];let S;e[48]!==w?(S=s.jsx("p",{className:"typography-label text-[var(--status-error)]",children:w}),e[48]=w,e[49]=S):S=e[49];let A;e[50]!==g.error?(A=s.jsx("p",{className:"typography-micro font-mono text-foreground mt-1 whitespace-pre-wrap break-words",children:g.error}),e[50]=g.error,e[51]=A):A=e[51];let x;e[52]!==g.ref||e[53]!==i?(x=g.ref?s.jsx("p",{className:"typography-micro text-muted-foreground mt-1",children:i("settings.plugins.status.failed.ref",{ref:g.ref})}):null,e[52]=g.ref,e[53]=i,e[54]=x):x=e[54];let E;e[55]!==S||e[56]!==A||e[57]!==x?(E=s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[N,s.jsxs("div",{className:"flex-1 min-w-0",children:[S,A,x]})]}),e[55]=S,e[56]=A,e[57]=x,e[58]=E):E=e[58],C=E;break e}}C=void 0}const b=C,k=h!==null&&(p!=="none"||r!==null);let u;e[59]!==v||e[60]!==f||e[61]!==r||e[62]!==k||e[63]!==i?(u=k?s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(B,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:i("settings.plugins.update.available.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:i("settings.plugins.update.available.description")}),r?.kind==="failed"?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-micro text-[var(--status-error)] mt-2",children:i("settings.plugins.update.failed.title")}),s.jsx("p",{className:"typography-micro font-mono text-foreground mt-0.5 whitespace-pre-wrap break-words",children:r.error})]}):null]}),s.jsx(V,{variant:"default",size:"sm",onClick:()=>{v()},disabled:f,children:f?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"loader-4",className:"size-4 animate-spin"}),i("settings.plugins.update.running")]}):i("settings.plugins.update.action")})]}):null,e[59]=v,e[60]=f,e[61]=r,e[62]=k,e[63]=i,e[64]=u):u=e[64];let j;return e[65]!==b||e[66]!==u?(j=s.jsxs("div",{className:"flex flex-col gap-3",children:[b,u]}),e[65]=b,e[66]=u,e[67]=j):j=e[67],j};function Ch(t){return t.loadRuntime}function Ih(t){return t.updatePackage}function oo(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}function ro(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function ec(t,e){if(t.trim()===e.trim())return!0;const a=oo(t),n=oo(e);return a.ok&&n.ok&&ro(a.value)===ro(n.value)}function Ph(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:ro(t.options),fileName:"",content:""}}function Ah(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const tc=t=>{const e=_e.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=Se("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let o;return e[1]!==n||e[2]!==a?(o=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=o):o=e[3],o},Th=()=>{const t=_e.c(229),{t:e}=Be(),n=hn(Eh)?.trim()||la(),i=zt(Dh),o=zt(Mh),r=i===n&&o===ln(),d=zt(Rh),c=zt(Oh),g=zt(Lh),p=zt(Fh),h=zt(Kh),f=zt(zh),m=zt(Uh),v=zt(_h),C=zt($h),b=zt(Bh),k=zt(Vh),[u,j]=l.useState(!1),[N,w]=l.useState(null),[S,A]=l.useState(!1);let x;t[0]!==j?(x=()=>{const st=()=>j(!0);return window.addEventListener("openchamber:settings-open-plugin-add",st),()=>window.removeEventListener("openchamber:settings-open-plugin-add",st)},t[0]=j,t[1]=x):x=t[1];let E;t[2]===Symbol.for("react.memo_cache_sentinel")?(E=[],t[2]=E):E=t[2],l.useEffect(x,E);let M;t[3]===Symbol.for("react.memo_cache_sentinel")?(M=[],t[3]=M):M=t[3],l.useEffect(qh,M);let T;t[4]!==c||t[5]!==d?(T=d?c.find(st=>st.id===d)??null:null,t[4]=c,t[5]=d,t[6]=T):T=t[6];const D=T;let R;t[7]!==g||t[8]!==d?(R=d?g.find(st=>st.id===d)??null:null,t[7]=g,t[8]=d,t[9]=R):R=t[9];const O=R;let I;t[10]!==D?(I=D?Ed(D.spec,D.sourcePath):null,t[10]=D,t[11]=I):I=t[11];const y=I;let L;t[12]!==O?(L=O?Dd(O.absolutePath):null,t[12]=O,t[13]=L):L=t[13];const K=L,[H,G]=l.useState(!1);let W;t[14]===Symbol.for("react.memo_cache_sentinel")?(W=new Map,t[14]=W):W=t[14];const q=l.useRef(W),z=l.useRef(null),$=JSON.stringify([n,d]);let Z;t[15]!==r||t[16]!==n||t[17]!==$||t[18]!==v||t[19]!==D||t[20]!==O||t[21]!==h||t[22]!==G?(Z=()=>{let st=!1;if(!r){z.current=null,h(null);return}const rt=(de,Ue)=>{if(zt.getState().selectedId!==de||la()!==n)return;const et=z.current,ze=zt.getState().draft,Ze=et?.id===de&&et.directory===n&&ze!==null&&(ze.spec!==et.value.spec||!ec(ze.optionsJson,et.value.optionsJson)||ze.content!==et.value.content);z.current={id:de,directory:n,value:Ue},Ze||h(Ue)};return D?(rt(D.id,Ph(D)),()=>{st=!0}):O?(G(z.current?.id!==O.id||z.current.directory!==n),(async()=>{const de=await v(O.id);if(st||la()!==n)return;G(!1);const Ue=de?.content??"";q.current.set($,Ue),rt(O.id,Ah(O,Ue))})(),()=>{st=!0}):(z.current=null,h(null),()=>{st=!0})},t[15]=r,t[16]=n,t[17]=$,t[18]=v,t[19]=D,t[20]=O,t[21]=h,t[22]=G,t[23]=Z):Z=t[23];let _;t[24]!==r||t[25]!==n||t[26]!==$||t[27]!==v||t[28]!==D||t[29]!==O||t[30]!==h?(_=[D,O,v,h,r,n,$],t[24]=r,t[25]=n,t[26]=$,t[27]=v,t[28]=D,t[29]=O,t[30]=h,t[31]=_):_=t[31],l.useEffect(Z,_);let ne;t[32]!==r||t[33]!==n||t[34]!==p||t[35]!==$||t[36]!==D||t[37]!==O||t[38]!==e||t[39]!==f||t[40]!==m?(ne=async()=>{if(!p||!r||la()!==n)return Us;if(D&&p.mode==="entry"){const st=p.spec.trim();if(st===D.spec&&ec(p.optionsJson,ro(D.options)))return Us;if(!st)return xs(e("settings.plugins.validation.specRequired"));const de=oo(p.optionsJson);if(!de.ok)return xs(e("settings.plugins.page.field.options.invalidJson"));const Ue=await f(D.id,{spec:st,options:de.value});return Ue.ok?Ue.reloadFailed?xs(Ue.warning||Ue.message||e("settings.plugins.toast.reloadFailed")):Tn:xs(Ue.message||e("settings.plugins.toast.reloadFailed"))}if(O&&p.mode==="file"){const st=q.current.get($)??"";if(p.content===st)return Us;const rt=await m(O.id,{content:p.content});return rt.ok?(q.current.set($,p.content),rt.reloadFailed?xs(rt.warning||rt.message||e("settings.plugins.toast.reloadFailed")):Tn):xs(rt.message||e("settings.plugins.toast.reloadFailed"))}return Us},t[32]=r,t[33]=n,t[34]=p,t[35]=$,t[36]=D,t[37]=O,t[38]=e,t[39]=f,t[40]=m,t[41]=ne):ne=t[41];const te=ti(ne);let he;t[42]!==b||t[43]!==k||t[44]!==N||t[45]!==w||t[46]!==A||t[47]!==e?(he=async()=>{if(!N)return;A(!0);const st=N.kind==="entry"?await b(N.id):await k(N.id);st.ok?U.success(st.message||e("settings.plugins.sidebar.toast.deleted",{name:N.label})):U.error(e("settings.plugins.sidebar.toast.deleteFailed")),w(null),A(!1)},t[42]=b,t[43]=k,t[44]=N,t[45]=w,t[46]=A,t[47]=e,t[48]=he):he=t[48];const je=he;let fe;t[49]!==u||t[50]!==j?(fe=s.jsx(ah,{open:u,onOpenChange:j}),t[49]=u,t[50]=j,t[51]=fe):fe=t[51];const ke=N!==null;let be;t[52]!==S||t[53]!==w?(be=st=>{!st&&!S&&w(null)},t[52]=S,t[53]=w,t[54]=be):be=t[54];let De;t[55]!==e?(De=e("settings.plugins.sidebar.deleteDialog.title"),t[55]=e,t[56]=De):De=t[56];let oe;t[57]!==De?(oe=s.jsx(Ht,{children:De}),t[57]=De,t[58]=oe):oe=t[58];const ee=N?.label??"";let ce;t[59]!==e||t[60]!==ee?(ce=e("settings.plugins.sidebar.deleteDialog.description",{name:ee}),t[59]=e,t[60]=ee,t[61]=ce):ce=t[61];let ue;t[62]!==ce?(ue=s.jsx(qt,{children:ce}),t[62]=ce,t[63]=ue):ue=t[63];let Ie;t[64]!==oe||t[65]!==ue?(Ie=s.jsxs(Vt,{children:[oe,ue]}),t[64]=oe,t[65]=ue,t[66]=Ie):Ie=t[66];let ve;t[67]!==w?(ve=()=>w(null),t[67]=w,t[68]=ve):ve=t[68];let Re;t[69]!==e?(Re=e("settings.common.actions.cancel"),t[69]=e,t[70]=Re):Re=t[70];let Me;t[71]!==S||t[72]!==ve||t[73]!==Re?(Me=s.jsx(V,{size:"sm",variant:"ghost",onClick:ve,disabled:S,children:Re}),t[71]=S,t[72]=ve,t[73]=Re,t[74]=Me):Me=t[74];let me;t[75]!==je?(me=()=>{je()},t[75]=je,t[76]=me):me=t[76];let Te;t[77]!==S||t[78]!==e?(Te=e(S?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),t[77]=S,t[78]=e,t[79]=Te):Te=t[79];let Oe;t[80]!==S||t[81]!==me||t[82]!==Te?(Oe=s.jsx(V,{size:"sm",variant:"destructive",onClick:me,disabled:S,children:Te}),t[80]=S,t[81]=me,t[82]=Te,t[83]=Oe):Oe=t[83];let pe;t[84]!==Me||t[85]!==Oe?(pe=s.jsxs(as,{children:[Me,Oe]}),t[84]=Me,t[85]=Oe,t[86]=pe):pe=t[86];let xe;t[87]!==Ie||t[88]!==pe?(xe=s.jsxs($t,{className:"max-w-md",children:[Ie,pe]}),t[87]=Ie,t[88]=pe,t[89]=xe):xe=t[89];let ae;t[90]!==ke||t[91]!==be||t[92]!==xe?(ae=s.jsx(_t,{open:ke,onOpenChange:be,children:xe}),t[90]=ke,t[91]=be,t[92]=xe,t[93]=ae):ae=t[93];let ie;t[94]!==fe||t[95]!==ae?(ie=s.jsxs(s.Fragment,{children:[fe,ae]}),t[94]=fe,t[95]=ae,t[96]=ie):ie=t[96];const ge=ie;if(!d){let st;t[97]!==j?(st=()=>j(!0),t[97]=j,t[98]=st):st=t[98];let rt;t[99]!==w||t[100]!==st?(rt=s.jsx(uh,{onAdd:st,onDelete:w}),t[99]=w,t[100]=st,t[101]=rt):rt=t[101];let de;return t[102]!==ge||t[103]!==rt?(de=s.jsxs(s.Fragment,{children:[rt,ge]}),t[102]=ge,t[103]=rt,t[104]=de):de=t[104],de}let Ee;t[105]!==e?(Ee=e("settings.plugins.page.back"),t[105]=e,t[106]=Ee):Ee=t[106];let Ke;t[107]!==C?(Ke=()=>C(null),t[107]=C,t[108]=Ke):Ke=t[108];let Le;t[109]!==Ee||t[110]!==Ke?(Le=s.jsx(tl,{label:Ee,onClick:Ke}),t[109]=Ee,t[110]=Ke,t[111]=Le):Le=t[111];const Ne=Le;let Ve;t[112]!==D||t[113]!==O||t[114]!==w?(Ve=()=>{D?w({kind:"entry",id:D.id,label:D.spec}):O&&w({kind:"file",id:O.id,label:O.fileName})},t[112]=D,t[113]=O,t[114]=w,t[115]=Ve):Ve=t[115];let Ye;t[116]===Symbol.for("react.memo_cache_sentinel")?(Ye=s.jsx(B,{name:"delete-bin",className:"size-3.5"}),t[116]=Ye):Ye=t[116];let pt;t[117]!==e?(pt=e("settings.common.actions.delete"),t[117]=e,t[118]=pt):pt=t[118];let vt;t[119]!==Ve||t[120]!==pt?(vt=s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:Ve,children:[Ye,pt]}),t[119]=Ve,t[120]=pt,t[121]=vt):vt=t[121];const wt=vt;if(D&&p&&p.mode==="entry"){let st;t[122]!==p.optionsJson?(st=oo(p.optionsJson),t[122]=p.optionsJson,t[123]=st):st=t[123];const de=st.ok;let Ue;t[124]!==e?(Ue=e("settings.plugins.page.header.entry"),t[124]=e,t[125]=Ue):Ue=t[125];let et;t[126]!==D.scope||t[127]!==e?(et=D.scope==="project"?e("settings.plugins.sidebar.group.projectEntries"):e("settings.plugins.sidebar.group.userEntries"),t[126]=D.scope,t[127]=e,t[128]=et):et=t[128];let ze;t[129]!==D.scope||t[130]!==et?(ze=s.jsx(tc,{scope:D.scope,label:et}),t[129]=D.scope,t[130]=et,t[131]=ze):ze=t[131];const Ze=te.onBlurCapture;let tt;t[132]!==D.spec||t[133]!==y?(tt=s.jsx(Xl,{target:y,name:D.spec}),t[132]=D.spec,t[133]=y,t[134]=tt):tt=t[134];let lt;t[135]!==D.id||t[136]!==D.spec?(lt=s.jsx(Nh,{entryId:D.id,spec:D.spec}),t[135]=D.id,t[136]=D.spec,t[137]=lt):lt=t[137];let Q;t[138]!==tt||t[139]!==lt?(Q=s.jsx(He,{divider:!1,children:s.jsxs("div",{className:"flex flex-col gap-3",children:[tt,lt]})}),t[138]=tt,t[139]=lt,t[140]=Q):Q=t[140];let nt;t[141]!==e?(nt=e("settings.plugins.page.field.spec"),t[141]=e,t[142]=nt):nt=t[142];const ot=p.spec;let it;t[143]!==p||t[144]!==h?(it=Pe=>h({...p,spec:Pe.target.value}),t[143]=p,t[144]=h,t[145]=it):it=t[145];let ft;t[146]!==e?(ft=e("settings.plugins.page.field.spec.placeholder"),t[146]=e,t[147]=ft):ft=t[147];let bt;t[148]!==p.spec||t[149]!==it||t[150]!==ft?(bt=s.jsx(Ge,{value:ot,onChange:it,placeholder:ft,className:"font-mono typography-meta",spellCheck:!1}),t[148]=p.spec,t[149]=it,t[150]=ft,t[151]=bt):bt=t[151];let ht;t[152]!==nt||t[153]!==bt?(ht=s.jsx(He,{title:nt,settingsItem:"plugins.spec",children:bt}),t[152]=nt,t[153]=bt,t[154]=ht):ht=t[154];let Nt;t[155]!==e?(Nt=e("settings.plugins.page.field.options"),t[155]=e,t[156]=Nt):Nt=t[156];const At=p.optionsJson;let $e;t[157]!==p||t[158]!==h?($e=Pe=>h({...p,optionsJson:Pe.target.value}),t[157]=p,t[158]=h,t[159]=$e):$e=t[159];const Xe=!de&&"border-[var(--status-error-border)]";let mt;t[160]!==Xe?(mt=Se("font-mono typography-meta min-h-[200px]",Xe),t[160]=Xe,t[161]=mt):mt=t[161];let Fe;t[162]!==p.optionsJson||t[163]!==$e||t[164]!==mt?(Fe=s.jsx(Rs,{value:At,onChange:$e,rows:10,className:mt,spellCheck:!1,placeholder:"{ }"}),t[162]=p.optionsJson,t[163]=$e,t[164]=mt,t[165]=Fe):Fe=t[165];let J;t[166]!==de||t[167]!==e?(J=!de&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:e("settings.plugins.page.field.options.invalidJson")}),t[166]=de,t[167]=e,t[168]=J):J=t[168];let ye;t[169]!==Nt||t[170]!==Fe||t[171]!==J?(ye=s.jsxs(He,{title:Nt,settingsItem:"plugins.options",children:[Fe,J]}),t[169]=Nt,t[170]=Fe,t[171]=J,t[172]=ye):ye=t[172];let Ae;t[173]!==te.onBlurCapture||t[174]!==Ne||t[175]!==wt||t[176]!==Ue||t[177]!==ze||t[178]!==Q||t[179]!==ht||t[180]!==ye?(Ae=s.jsxs(ns,{title:Ue,titleLeading:Ne,headerEnd:wt,titleAccessory:ze,onBlurCapture:Ze,children:[Q,ht,ye]}),t[173]=te.onBlurCapture,t[174]=Ne,t[175]=wt,t[176]=Ue,t[177]=ze,t[178]=Q,t[179]=ht,t[180]=ye,t[181]=Ae):Ae=t[181];let Y;return t[182]!==ge||t[183]!==Ae?(Y=s.jsxs(s.Fragment,{children:[Ae,ge]}),t[182]=ge,t[183]=Ae,t[184]=Y):Y=t[184],Y}if(O&&p&&p.mode==="file"){let st;t[185]!==e?(st=e("settings.plugins.page.header.file"),t[185]=e,t[186]=st):st=t[186];let rt;t[187]!==O.scope||t[188]!==e?(rt=O.scope==="project"?e("settings.plugins.sidebar.group.projectFiles"):e("settings.plugins.sidebar.group.userFiles"),t[187]=O.scope,t[188]=e,t[189]=rt):rt=t[189];let de;t[190]!==O.scope||t[191]!==rt?(de=s.jsx(tc,{scope:O.scope,label:rt}),t[190]=O.scope,t[191]=rt,t[192]=de):de=t[192];let Ue;t[193]===Symbol.for("react.memo_cache_sentinel")?(Ue=Se("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),t[193]=Ue):Ue=t[193];let et;t[194]!==O.fileName?(et=s.jsx("span",{className:Ue,children:O.fileName}),t[194]=O.fileName,t[195]=et):et=t[195];let ze;t[196]!==de||t[197]!==et?(ze=s.jsxs(s.Fragment,{children:[de,et]}),t[196]=de,t[197]=et,t[198]=ze):ze=t[198];const Ze=te.onBlurCapture;let tt;t[199]!==O.fileName||t[200]!==K?(tt=s.jsx(He,{divider:!1,children:s.jsx(Xl,{target:K,name:O.fileName})}),t[199]=O.fileName,t[200]=K,t[201]=tt):tt=t[201];let lt;t[202]!==e?(lt=e("settings.plugins.page.field.content"),t[202]=e,t[203]=lt):lt=t[203];let Q;t[204]!==p||t[205]!==h?(Q=ht=>h({...p,content:ht.target.value}),t[204]=p,t[205]=h,t[206]=Q):Q=t[206];let nt;t[207]!==te?(nt=ht=>{ht.key==="Enter"&&(ht.metaKey||ht.ctrlKey)&&(ht.preventDefault(),te.requestSave())},t[207]=te,t[208]=nt):nt=t[208];let ot;t[209]!==p.content||t[210]!==H||t[211]!==Q||t[212]!==nt?(ot=s.jsx(Rs,{value:p.content,onChange:Q,onKeyDown:nt,rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:H}),t[209]=p.content,t[210]=H,t[211]=Q,t[212]=nt,t[213]=ot):ot=t[213];let it;t[214]!==lt||t[215]!==ot?(it=s.jsx(He,{title:lt,settingsItem:"plugins.content",children:ot}),t[214]=lt,t[215]=ot,t[216]=it):it=t[216];let ft;t[217]!==te.onBlurCapture||t[218]!==Ne||t[219]!==wt||t[220]!==st||t[221]!==ze||t[222]!==tt||t[223]!==it?(ft=s.jsxs(ns,{title:st,titleLeading:Ne,headerEnd:wt,titleAccessory:ze,onBlurCapture:Ze,children:[tt,it]}),t[217]=te.onBlurCapture,t[218]=Ne,t[219]=wt,t[220]=st,t[221]=ze,t[222]=tt,t[223]=it,t[224]=ft):ft=t[224];let bt;return t[225]!==ge||t[226]!==ft?(bt=s.jsxs(s.Fragment,{children:[ft,ge]}),t[225]=ge,t[226]=ft,t[227]=bt):bt=t[227],bt}let yt;return t[228]===Symbol.for("react.memo_cache_sentinel")?(yt=s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(B,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})}),t[228]=yt):yt=t[228],yt};function Eh(t){return t.getActiveProject()?.path}function Dh(t){return t.loadedDirectory}function Mh(t){return t.loadedRuntimeKey}function Rh(t){return t.selectedId}function Oh(t){return t.entries}function Lh(t){return t.files}function Fh(t){return t.draft}function Kh(t){return t.setDraft}function zh(t){return t.updateEntry}function Uh(t){return t.updateFile}function _h(t){return t.readFile}function $h(t){return t.setSelected}function Bh(t){return t.deleteEntry}function Vh(t){return t.deleteFile}function Hh(){zt.getState().setSelected(null)}function qh(){return Hh}const Gh="<built-in>",bi=t=>t?.path===Gh,Cr=t=>!!t&&!bi(t)&&t.renamable===!0,Wh=t=>{const e=_e.c(166),{onItemSelect:a}=t,{t:n}=Be(),[i,o]=l.useState(""),[r,d]=l.useState(null),[c,g]=l.useState(""),[p,h]=l.useState(null),[f,m]=l.useState(!1),[v,C]=l.useState(null),{selectedSkillName:b,setSelectedSkill:k,setSkillDraft:u,deleteSkill:j,renameSkill:N,getSkillDetail:w}=rn($s(Jh)),S=en();let A;e[0]!==S?(A=Fe=>Lr(Fe,S),e[0]=S,e[1]=A):A=e[1];const x=rn(A),E=rn(Qh);let M,T;e[2]!==E||e[3]!==S?(M=()=>{E(S)},T=[E,S],e[2]=E,e[3]=S,e[4]=M,e[5]=T):(M=e[4],T=e[5]),l.useEffect(M,T);let D;e[6]!==a||e[7]!==k||e[8]!==u||e[9]!==x?(D=()=>{let Fe="new-skill",J=1;for(;x.some(ye=>ye.name===Fe);)Fe=`new-skill-${J}`,J++;u({name:Fe,scope:"user",source:"opencode",description:""}),k(Fe),a?.()},e[6]=a,e[7]=k,e[8]=u,e[9]=x,e[10]=D):D=e[10];const R=D;let O;e[11]===Symbol.for("react.memo_cache_sentinel")?(O=async Fe=>{bi(Fe)||h(Fe)},e[11]=O):O=e[11];const I=O;let y;e[12]!==p||e[13]!==j||e[14]!==S||e[15]!==n?(y=async()=>{if(!p)return;if(bi(p)){h(null);return}m(!0),await j(p.name,S)?(U.success(n("settings.skills.sidebar.toast.skillDeleted",{name:p.name})),h(null)):U.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),m(!1)},e[12]=p,e[13]=j,e[14]=S,e[15]=n,e[16]=y):y=e[16];const L=y;let K;e[17]!==w||e[18]!==k||e[19]!==u||e[20]!==S||e[21]!==x||e[22]!==n?(K=async Fe=>{if(bi(Fe))return;const J=Fe.name;let ye=1,Ae=`${J}-copy`;for(;x.some(Pe=>Pe.name===Ae);)ye++,Ae=`${J}-copy-${ye}`;const Y=await w(Fe.name,S);if(!Y){U.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}u({name:Ae,scope:Fe.scope||"user",source:Fe.source||"opencode",description:(Y.sources.md.fields.includes("description"),""),instructions:""}),k(Ae)},e[17]=w,e[18]=k,e[19]=u,e[20]=S,e[21]=x,e[22]=n,e[23]=K):K=e[23];const H=K;let G;e[24]===Symbol.for("react.memo_cache_sentinel")?(G=Fe=>{Cr(Fe)&&(g(Fe.name),d(Fe))},e[24]=G):G=e[24];const W=G;let q;e[25]!==r||e[26]!==c||e[27]!==N||e[28]!==k||e[29]!==S||e[30]!==x||e[31]!==n?(q=async()=>{if(!r)return;if(!Cr(r)){d(null);return}const Fe=c.trim().replace(/\s+/g,"-").toLowerCase();if(!Fe){U.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Fe===r.name){d(null);return}if(x.some(ye=>ye.name===Fe)){U.error(n("settings.skills.page.toast.skillExists"));return}await N(r.name,Fe,S)?(U.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Fe})),k(Fe)):U.error(n("settings.skills.sidebar.toast.renameFailed")),d(null)},e[25]=r,e[26]=c,e[27]=N,e[28]=k,e[29]=S,e[30]=x,e[31]=n,e[32]=q):q=e[32];const z=q;let $,Z,_;if(e[33]!==i||e[34]!==x){let Fe;e[38]!==i?(Fe=J=>po([J.name,J.description],i),e[38]=i,e[39]=Fe):Fe=e[39],Z=x.filter(Fe),$=Z.filter(Yh),_=Z.filter(Zh),e[33]=i,e[34]=x,e[35]=$,e[36]=Z,e[37]=_}else $=e[35],Z=e[36],_=e[37];const ne=_;let X;e[40]===Symbol.for("react.memo_cache_sentinel")?(X=function(J){const ye={},Ae=[];for(const Pe of J)Pe.group?(ye[Pe.group]||(ye[Pe.group]=[]),ye[Pe.group].push(Pe)):Ae.push(Pe);const Y=Object.keys(ye).sort(Xh).map(Pe=>({name:Pe,skills:[...ye[Pe]].sort(ex)}));return Ae.sort(tx),{sortedGroups:Y,ungrouped:Ae}},e[40]=X):X=e[40];const te=X;let he;e[41]!==$?(he=te($),e[41]=$,e[42]=he):he=e[42];const je=he;let fe;e[43]!==ne?(fe=te(ne),e[43]=ne,e[44]=fe):fe=e[44];const ke=fe;let be;e[45]===Symbol.for("react.memo_cache_sentinel")?(be=Se("flex h-full flex-col","bg-background"),e[45]=be):be=e[45];let De;e[46]!==n?(De=n("settings.skills.sidebar.title"),e[46]=n,e[47]=De):De=e[47];let oe;e[48]!==De?(oe=s.jsx("h2",{className:`${va} mb-3`,children:De}),e[48]=De,e[49]=oe):oe=e[49];let ee;e[50]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx(Si,{className:"mb-3"}),e[50]=ee):ee=e[50];let ce;e[51]!==x.length||e[52]!==n?(ce=n("settings.skills.sidebar.total",{count:x.length}),e[51]=x.length,e[52]=n,e[53]=ce):ce=e[53];let ue;e[54]!==ce?(ue=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ce}),e[54]=ce,e[55]=ue):ue=e[55];let Ie;e[56]===Symbol.for("react.memo_cache_sentinel")?(Ie=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[56]=Ie):Ie=e[56];let ve;e[57]!==R?(ve=s.jsx(V,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:R,children:Ie}),e[57]=R,e[58]=ve):ve=e[58];let Re;e[59]!==ue||e[60]!==ve?(Re=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ue,ve]}),e[59]=ue,e[60]=ve,e[61]=Re):Re=e[61];let Me;e[62]!==i||e[63]!==x.length?(Me=x.length>0?s.jsx(Wr,{value:i,onChange:o}):null,e[62]=i,e[63]=x.length,e[64]=Me):Me=e[64];let me;e[65]!==oe||e[66]!==Re||e[67]!==Me?(me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[oe,ee,Re,Me]}),e[65]=oe,e[66]=Re,e[67]=Me,e[68]=me):me=e[68];let Te;e[69]!==je||e[70]!==ke||e[71]!==H||e[72]!==a||e[73]!==v||e[74]!==$||e[75]!==i||e[76]!==b||e[77]!==k||e[78]!==Z||e[79]!==x.length||e[80]!==n||e[81]!==ne?(Te=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:x.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(B,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):Z.length===0?s.jsx(Jr,{query:i}):s.jsxs(s.Fragment,{children:[$.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.project")}),je.sortedGroups.map(Fe=>{const{name:J,skills:ye}=Fe;return s.jsx(jr,{label:J,count:ye.length,storageKey:"project-skills",children:ye.map(Ae=>s.jsx(Vi,{skill:Ae,isSelected:b===Ae.name,onSelect:()=>{k(Ae.name),a?.()},onRename:()=>W(Ae),onDelete:()=>I(Ae),onDuplicate:()=>H(Ae),isMenuOpen:v===Ae.name,onMenuOpenChange:Y=>C(Y?Ae.name:null)},Ae.name))},J)}),je.ungrouped.map(Fe=>s.jsx(Vi,{skill:Fe,isSelected:b===Fe.name,onSelect:()=>{k(Fe.name),a?.()},onRename:()=>W(Fe),onDelete:()=>I(Fe),onDuplicate:()=>H(Fe),isMenuOpen:v===Fe.name,onMenuOpenChange:J=>C(J?Fe.name:null)},Fe.name))]}),ne.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),ke.sortedGroups.map(Fe=>{const{name:J,skills:ye}=Fe;return s.jsx(jr,{label:J,count:ye.length,storageKey:"user-skills",children:ye.map(Ae=>s.jsx(Vi,{skill:Ae,isSelected:b===Ae.name,onSelect:()=>{k(Ae.name),a?.()},onRename:()=>W(Ae),onDelete:()=>I(Ae),onDuplicate:()=>H(Ae),isMenuOpen:v===Ae.name,onMenuOpenChange:Y=>C(Y?Ae.name:null)},Ae.name))},J)}),ke.ungrouped.map(Fe=>s.jsx(Vi,{skill:Fe,isSelected:b===Fe.name,onSelect:()=>{k(Fe.name),a?.()},onRename:()=>W(Fe),onDelete:()=>I(Fe),onDuplicate:()=>H(Fe),isMenuOpen:v===Fe.name,onMenuOpenChange:J=>C(J?Fe.name:null)},Fe.name))]})]})}),e[69]=je,e[70]=ke,e[71]=H,e[72]=a,e[73]=v,e[74]=$,e[75]=i,e[76]=b,e[77]=k,e[78]=Z,e[79]=x.length,e[80]=n,e[81]=ne,e[82]=Te):Te=e[82];const Oe=p!==null;let pe;e[83]!==f?(pe=Fe=>{!Fe&&!f&&h(null)},e[83]=f,e[84]=pe):pe=e[84];let xe;e[85]!==n?(xe=n("settings.skills.sidebar.deleteDialog.title"),e[85]=n,e[86]=xe):xe=e[86];let ae;e[87]!==xe?(ae=s.jsx(Ht,{children:xe}),e[87]=xe,e[88]=ae):ae=e[88];const ie=p?.name??"";let ge;e[89]!==n||e[90]!==ie?(ge=n("settings.skills.sidebar.deleteDialog.description",{name:ie}),e[89]=n,e[90]=ie,e[91]=ge):ge=e[91];let Ee;e[92]!==ge?(Ee=s.jsx(qt,{children:ge}),e[92]=ge,e[93]=Ee):Ee=e[93];let Ke;e[94]!==ae||e[95]!==Ee?(Ke=s.jsxs(Vt,{children:[ae,Ee]}),e[94]=ae,e[95]=Ee,e[96]=Ke):Ke=e[96];let Le;e[97]===Symbol.for("react.memo_cache_sentinel")?(Le=()=>h(null),e[97]=Le):Le=e[97];let Ne;e[98]!==n?(Ne=n("settings.common.actions.cancel"),e[98]=n,e[99]=Ne):Ne=e[99];let Ve;e[100]!==f||e[101]!==Ne?(Ve=s.jsx(V,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Le,disabled:f,children:Ne}),e[100]=f,e[101]=Ne,e[102]=Ve):Ve=e[102];let Ye;e[103]!==n?(Ye=n("settings.common.actions.delete"),e[103]=n,e[104]=Ye):Ye=e[104];let pt;e[105]!==L||e[106]!==f||e[107]!==Ye?(pt=s.jsx(V,{size:"sm",onClick:L,disabled:f,children:Ye}),e[105]=L,e[106]=f,e[107]=Ye,e[108]=pt):pt=e[108];let vt;e[109]!==Ve||e[110]!==pt?(vt=s.jsxs(as,{children:[Ve,pt]}),e[109]=Ve,e[110]=pt,e[111]=vt):vt=e[111];let wt;e[112]!==Ke||e[113]!==vt?(wt=s.jsxs($t,{className:"max-w-md",children:[Ke,vt]}),e[112]=Ke,e[113]=vt,e[114]=wt):wt=e[114];let yt;e[115]!==Oe||e[116]!==pe||e[117]!==wt?(yt=s.jsx(_t,{open:Oe,onOpenChange:pe,children:wt}),e[115]=Oe,e[116]=pe,e[117]=wt,e[118]=yt):yt=e[118];const st=r!==null;let rt;e[119]===Symbol.for("react.memo_cache_sentinel")?(rt=Fe=>!Fe&&d(null),e[119]=rt):rt=e[119];let de;e[120]!==n?(de=n("settings.skills.sidebar.renameDialog.title"),e[120]=n,e[121]=de):de=e[121];let Ue;e[122]!==de?(Ue=s.jsx(Ht,{children:de}),e[122]=de,e[123]=Ue):Ue=e[123];const et=r?.name??"";let ze;e[124]!==n||e[125]!==et?(ze=n("settings.skills.sidebar.renameDialog.description",{name:et}),e[124]=n,e[125]=et,e[126]=ze):ze=e[126];let Ze;e[127]!==ze?(Ze=s.jsx(qt,{children:ze}),e[127]=ze,e[128]=Ze):Ze=e[128];let tt;e[129]!==Ue||e[130]!==Ze?(tt=s.jsxs(Vt,{children:[Ue,Ze]}),e[129]=Ue,e[130]=Ze,e[131]=tt):tt=e[131];let lt;e[132]===Symbol.for("react.memo_cache_sentinel")?(lt=Fe=>g(Fe.target.value),e[132]=lt):lt=e[132];let Q;e[133]!==n?(Q=n("settings.skills.sidebar.renameDialog.placeholder"),e[133]=n,e[134]=Q):Q=e[134];let nt;e[135]!==z?(nt=Fe=>{Fe.key==="Enter"&&z()},e[135]=z,e[136]=nt):nt=e[136];let ot;e[137]!==c||e[138]!==Q||e[139]!==nt?(ot=s.jsx(Ge,{value:c,onChange:lt,placeholder:Q,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:nt}),e[137]=c,e[138]=Q,e[139]=nt,e[140]=ot):ot=e[140];let it;e[141]===Symbol.for("react.memo_cache_sentinel")?(it=()=>d(null),e[141]=it):it=e[141];let ft;e[142]!==n?(ft=n("settings.common.actions.cancel"),e[142]=n,e[143]=ft):ft=e[143];let bt;e[144]!==ft?(bt=s.jsx(V,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:it,children:ft}),e[144]=ft,e[145]=bt):bt=e[145];let ht;e[146]!==n?(ht=n("settings.common.actions.rename"),e[146]=n,e[147]=ht):ht=e[147];let Nt;e[148]!==z||e[149]!==ht?(Nt=s.jsx(V,{size:"sm",onClick:z,children:ht}),e[148]=z,e[149]=ht,e[150]=Nt):Nt=e[150];let At;e[151]!==bt||e[152]!==Nt?(At=s.jsxs(as,{children:[bt,Nt]}),e[151]=bt,e[152]=Nt,e[153]=At):At=e[153];let $e;e[154]!==tt||e[155]!==ot||e[156]!==At?($e=s.jsxs($t,{children:[tt,ot,At]}),e[154]=tt,e[155]=ot,e[156]=At,e[157]=$e):$e=e[157];let Xe;e[158]!==st||e[159]!==$e?(Xe=s.jsx(_t,{open:st,onOpenChange:rt,children:$e}),e[158]=st,e[159]=$e,e[160]=Xe):Xe=e[160];let mt;return e[161]!==me||e[162]!==Te||e[163]!==yt||e[164]!==Xe?(mt=s.jsxs("div",{className:be,children:[me,Te,yt,Xe]}),e[161]=me,e[162]=Te,e[163]=yt,e[164]=Xe,e[165]=mt):mt=e[165],mt},Vi=t=>{const e=_e.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:o,onRename:r,onDuplicate:d,isMenuOpen:c,onMenuOpenChange:g}=t,{t:p}=Be();let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Rr(),e[0]=h):h=e[0];const f=h;let m;e[1]!==a?(m=bi(a),e[1]=a,e[2]=m):m=e[2];const v=m;let C;e[3]!==a?(C=Cr(a),e[3]=a,e[4]=C):C=e[4];const b=C,[k,u]=l.useState(!1);let j;e[5]!==b||e[6]!==o||e[7]!==d||e[8]!==r||e[9]!==p?(j=L=>s.jsxs(s.Fragment,{children:[b?s.jsxs(L,{onClick:K=>{K.stopPropagation(),r()},children:[s.jsx(B,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}):null,s.jsxs(L,{onClick:K=>{K.stopPropagation(),d()},children:[s.jsx(B,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),s.jsxs(L,{onClick:K=>{K.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[5]=b,e[6]=o,e[7]=d,e[8]=r,e[9]=p,e[10]=j):j=e[10];const N=j,w=!v&&k,S=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[11]!==S?(A=Se("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",S),e[11]=S,e[12]=A):A=e[12];let x;e[13]!==v?(x=!f&&!v?L=>{L.preventDefault(),u(!0)}:void 0,e[13]=v,e[14]=x):x=e[14];let E;e[15]!==A||e[16]!==x?(E=s.jsx("div",{className:A,onContextMenu:x}),e[15]=A,e[16]=x,e[17]=E):E=e[17];let M;e[18]!==a.name?(M=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name})}),e[18]=a.name,e[19]=M):M=e[19];let T;e[20]!==i||e[21]!==M?(T=s.jsx("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:M}),e[20]=i,e[21]=M,e[22]=T):T=e[22];let D;e[23]!==v||e[24]!==c||e[25]!==g||e[26]!==N?(D=v?null:s.jsxs(Jn,{open:c,onOpenChange:L=>{L&&u(!1),g(L)},children:[s.jsx(Wn,{asChild:!0,children:s.jsx(V,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:N(xn)})]}),e[23]=v,e[24]=c,e[25]=g,e[26]=N,e[27]=D):D=e[27];let R;e[28]!==T||e[29]!==D?(R=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[T,D]}),e[28]=T,e[29]=D,e[30]=R):R=e[30];let O;e[31]!==R||e[32]!==E?(O=s.jsx(Xa,{render:E,children:R}),e[31]=R,e[32]=E,e[33]=O):O=e[33];let I;e[34]!==v||e[35]!==N?(I=v?null:s.jsx(Ya,{className:"w-fit min-w-20",children:N(Za)}),e[34]=v,e[35]=N,e[36]=I):I=e[36];let y;return e[37]!==O||e[38]!==I||e[39]!==w?(y=s.jsxs(ei,{open:w,onOpenChange:u,children:[O,I]}),e[37]=O,e[38]=I,e[39]=w,e[40]=y):y=e[40],y};function Jh(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Qh(t){return t.loadSkills}function Yh(t){return t.scope==="project"}function Zh(t){return t.scope==="user"}function Xh(t,e){return t.localeCompare(e)}function ex(t,e){return t.name.localeCompare(e.name)}function tx(t,e){return t.name.localeCompare(e.name)}const sx=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,nx=t=>{const e=t.trim(),a=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(a==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(a==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const n=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return n?`${n[1]}/${n[2].replace(/\.git$/i,"")}`:e},ax=({open:t,onOpenChange:e})=>{const{t:a}=Be(),n=zn(I=>I.scanRepo),i=zn(I=>I.loadCatalog),o=zn(I=>I.loadSource),r=zn(I=>I.setSelectedSource),d=zn(I=>I.isScanning),c=ma(I=>I.defaultGitIdentityId),g=ma(I=>I.loadDefaultGitIdentityId),[p,h]=l.useState(""),[f,m]=l.useState(""),[v,C]=l.useState(""),[b,k]=l.useState(null),[u,j]=l.useState(null),[N,w]=l.useState(!1),[S,A]=l.useState([]),[x,E]=l.useState(null),M=l.useRef(0),T=l.useCallback(I=>{M.current+=1,w(!1),j(null),I?.clearIdentity&&(A([]),E(null))},[]);l.useEffect(()=>{t&&(M.current+=1,h(""),m(""),C(""),j(null),w(!1),A([]),E(null),g(),k(null),(async()=>{const I=await En();k(I?I.skillCatalogs??[]:null)})())},[t,g]);const D=l.useMemo(()=>{const I=f.trim(),y=v.trim();return(b??[]).some(L=>{const K=(L.source||"").trim(),H=(L.subpath||"").trim();return K===I&&H===y})},[b,f,v]),R=async()=>{const I=f.trim();if(!I){U.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}p.trim()||h(nx(I)),w(!1),j(null);const y=M.current+1;M.current=y;const L=await n({source:I,subpath:v.trim()||void 0,gitIdentityId:x||void 0});if(M.current!==y)return;if(!L.ok){if(L.error?.kind==="authRequired"){if(ms()){U.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const H=L.error.identities||[];if(A(H),!x&&H.length>0){const G=c&&c!=="global"&&H.some(W=>W.id===c)?c:H[0].id;E(G)}U.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}U.error(L.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const K=L.items?.length||0;if(j(K),K===0){U.error(a("settings.skills.catalog.add.toast.noSkillsFound")),w(!1);return}A([]),w(!0),U.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:K}))},O=async()=>{const I=p.trim(),y=f.trim(),L=v.trim();if(!I){U.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!y){U.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!N){U.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(D){U.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const K={id:sx(),label:I,source:y,...L?{subpath:L}:{},...x?{gitIdentityId:x}:{}};if(b===null){U.error(a("settings.skills.catalog.add.toast.saveFailed"));return}const H=[...b,K];try{if(!(await kt({skillCatalogs:H})).ok)throw new Error(a("settings.skills.catalog.add.toast.saveFailed"));k(H),U.success(a("settings.skills.catalog.add.toast.catalogAdded")),await i({refresh:!0}),await o(K.id,{refresh:!0}),r(K.id),e(!1)}catch(G){U.error(G instanceof Error?G.message:a("settings.skills.catalog.add.toast.saveFailed"))}};return s.jsx(_t,{open:t,onOpenChange:e,children:s.jsxs($t,{className:"max-w-xl",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:a("settings.skills.catalog.add.title")}),s.jsxs(qt,{children:[a("settings.skills.catalog.add.descriptionPrefix")," ",s.jsx("code",{className:"font-mono",children:"SKILL.md"}),a("settings.skills.catalog.add.descriptionSuffix")]})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.catalogName")}),s.jsx(Ge,{value:p,onChange:I=>h(I.target.value),placeholder:a("settings.skills.catalog.add.field.catalogNamePlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.repository")}),s.jsx(Gt,{children:a("settings.skills.catalog.add.field.repositoryHint")})]}),s.jsx(Ge,{value:f,onChange:I=>{m(I.target.value),T({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.repositoryPlaceholder")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.skills.catalog.add.field.optionalSubpath")}),s.jsx(Ge,{value:v,onChange:I=>{C(I.target.value),T({clearIdentity:!0})},placeholder:a("settings.skills.catalog.shared.field.subpathPlaceholder")})]}),S.length>0&&!ms()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")}),s.jsx(Gt,{className:"ml-1",children:a("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Dt,{value:x||"",onValueChange:I=>{E(I),T()},children:[s.jsx(Tt,{className:"w-fit",children:s.jsx("span",{children:S.find(I=>I.id===x)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Et,{align:"start",children:S.map(I=>s.jsx(gt,{value:I.id,children:I.name},I.id))})]})]}):null,u!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:u})}):null,D?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null]}),s.jsxs(as,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>e(!1),children:a("settings.common.actions.cancel")}),s.jsxs(V,{size:"sm",className:"gap-2",variant:"ghost",onClick:()=>{R()},disabled:d||!f.trim(),children:[s.jsx(B,{name:"git-repository",className:"h-4 w-4"}),a(d?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan")]}),s.jsx(V,{size:"sm",onClick:()=>{O()},disabled:!N||D||b===null||!p.trim()||!f.trim(),children:a("settings.skills.catalog.add.actions.addCatalog")})]})]})})},ix=t=>{const e=_e.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:o}=t,{t:r}=Be();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];const[c,g]=l.useState(d);let p,h;e[1]!==i||e[2]!==a?(p=()=>{if(!a)return;const X={};for(const te of i)X[te.skillName]="skip";g(X)},h=[a,i],e[1]=i,e[2]=a,e[3]=p,e[4]=h):(p=e[3],h=e[4]),l.useEffect(p,h);let f;e[5]!==i?(f=X=>{const te={};for(const he of i)te[he.skillName]=X;g(te)},e[5]=i,e[6]=f):f=e[6];const m=f;let v;e[7]!==i||e[8]!==c?(v=i.length>0&&i.every(X=>c[X.skillName]),e[7]=i,e[8]=c,e[9]=v):v=e[9];const C=v;let b;e[10]!==r?(b=r("settings.skills.catalog.conflicts.title"),e[10]=r,e[11]=b):b=e[11];let k;e[12]!==b?(k=s.jsx(Ht,{children:b}),e[12]=b,e[13]=k):k=e[13];let u;e[14]!==r?(u=r("settings.skills.catalog.conflicts.description"),e[14]=r,e[15]=u):u=e[15];let j;e[16]!==u?(j=s.jsx(qt,{children:u}),e[16]=u,e[17]=j):j=e[17];let N;e[18]!==k||e[19]!==j?(N=s.jsxs(Vt,{children:[k,j]}),e[18]=k,e[19]=j,e[20]=N):N=e[20];let w;e[21]!==i.length||e[22]!==r?(w=r("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=r,e[23]=w):w=e[23];let S;e[24]!==w?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:w}),e[24]=w,e[25]=S):S=e[25];let A;e[26]!==m?(A=()=>m("skip"),e[26]=m,e[27]=A):A=e[27];let x;e[28]!==r?(x=r("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=r,e[29]=x):x=e[29];let E;e[30]!==A||e[31]!==x?(E=s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:A,children:x}),e[30]=A,e[31]=x,e[32]=E):E=e[32];let M;e[33]!==m?(M=()=>m("overwrite"),e[33]=m,e[34]=M):M=e[34];let T;e[35]!==r?(T=r("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=r,e[36]=T):T=e[36];let D;e[37]!==M||e[38]!==T?(D=s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:M,children:T}),e[37]=M,e[38]=T,e[39]=D):D=e[39];let R;e[40]!==E||e[41]!==D?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[E,D]}),e[40]=E,e[41]=D,e[42]=R):R=e[42];let O;e[43]!==S||e[44]!==R?(O=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,R]}),e[43]=S,e[44]=R,e[45]=O):O=e[45];let I;if(e[46]!==i||e[47]!==c||e[48]!==r){let X;e[50]!==c||e[51]!==r?(X=te=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:te.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("settings.skills.catalog.conflicts.installedIn",{scope:te.scope==="project"?r("settings.skills.catalog.conflicts.scope.project"):r("settings.skills.catalog.conflicts.scope.user"),source:te.source==="agents"?r("settings.skills.catalog.conflicts.source.agents"):r("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Dt,{value:c[te.skillName]||"skip",onValueChange:he=>g(je=>({...je,[te.skillName]:he})),children:[s.jsx(Tt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[te.skillName]||"skip")==="overwrite"?r("settings.skills.catalog.conflicts.decision.overwrite"):r("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Et,{align:"end",children:[s.jsx(gt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:r("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(gt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:r("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},te.skillName),e[50]=c,e[51]=r,e[52]=X):X=e[52],I=i.map(X),e[46]=i,e[47]=c,e[48]=r,e[49]=I}else I=e[49];let y;e[53]!==I?(y=s.jsx("div",{className:"space-y-2",children:I}),e[53]=I,e[54]=y):y=e[54];let L;e[55]!==O||e[56]!==y?(L=s.jsxs("div",{className:"space-y-3",children:[O,y]}),e[55]=O,e[56]=y,e[57]=L):L=e[57];let K;e[58]!==n?(K=()=>n(!1),e[58]=n,e[59]=K):K=e[59];let H;e[60]!==r?(H=r("settings.common.actions.cancel"),e[60]=r,e[61]=H):H=e[61];let G;e[62]!==K||e[63]!==H?(G=s.jsx(V,{size:"sm",variant:"ghost",onClick:K,children:H}),e[62]=K,e[63]=H,e[64]=G):G=e[64];let W;e[65]!==c||e[66]!==o?(W=()=>o(c),e[65]=c,e[66]=o,e[67]=W):W=e[67];const q=!C;let z;e[68]!==r?(z=r("settings.skills.catalog.conflicts.actions.continue"),e[68]=r,e[69]=z):z=e[69];let $;e[70]!==W||e[71]!==q||e[72]!==z?($=s.jsx(V,{size:"sm",onClick:W,disabled:q,children:z}),e[70]=W,e[71]=q,e[72]=z,e[73]=$):$=e[73];let Z;e[74]!==G||e[75]!==$?(Z=s.jsxs(as,{children:[G,$]}),e[74]=G,e[75]=$,e[76]=Z):Z=e[76];let _;e[77]!==N||e[78]!==L||e[79]!==Z?(_=s.jsxs($t,{className:"max-w-2xl",children:[N,L,Z]}),e[77]=N,e[78]=L,e[79]=Z,e[80]=_):_=e[80];let ne;return e[81]!==n||e[82]!==a||e[83]!==_?(ne=s.jsx(_t,{open:a,onOpenChange:n,children:_}),e[81]=n,e[82]=a,e[83]=_,e[84]=ne):ne=e[84],ne},sl=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function vi(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Fd(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=sl.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const ox=t=>{const e=_e.c(124),{open:a,onOpenChange:n,item:i}=t,{t:o}=Be(),r=zn(rx),d=zn(lx),[c,g]=l.useState("user"),[p,h]=l.useState("opencode"),f=hn(cx),m=hn(dx),[v,C]=l.useState(null),[b,k]=l.useState(!1);let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[j,N]=l.useState(u),[w,S]=l.useState(null);let A,x;e[1]!==m||e[2]!==a?(A=()=>{a&&(g("user"),h("opencode"),C(m),k(!1),N([]),S(null))},x=[a,m],e[1]=m,e[2]=a,e[3]=A,e[4]=x):(A=e[3],x=e[4]),l.useEffect(A,x);let E;e[5]!==o?(E=Ne=>{switch(Ne){case"project-opencode":return o("settings.skills.location.option.projectOpencode.label");case"user-agents":return o("settings.skills.location.option.userAgents.label");case"project-agents":return o("settings.skills.location.option.projectAgents.label");default:return o("settings.skills.location.option.userOpencode.label")}},e[5]=o,e[6]=E):E=e[6];const M=E;let T;e[7]!==o?(T=Ne=>{switch(Ne){case"project-opencode":return o("settings.skills.location.option.projectOpencode.description");case"user-agents":return o("settings.skills.location.option.userAgents.description");case"project-agents":return o("settings.skills.location.option.projectAgents.description");default:return o("settings.skills.location.option.userOpencode.description")}},e[7]=o,e[8]=T):T=e[8];const D=T;let R;e:{if(f.length===0){R=null;break e}if(v&&f.some(Ne=>Ne.id===v)){R=v;break e}if(m&&f.some(Ne=>Ne.id===m)){R=m;break e}R=f[0]?.id??null}const O=R;let I;e:{if(c!=="project"){I=null;break e}const Ne=O;if(!Ne){I=null;break e}let Ve;if(e[9]!==Ne||e[10]!==f){let pt;e[12]!==Ne?(pt=vt=>vt.id===Ne,e[12]=Ne,e[13]=pt):pt=e[13],Ve=f.find(pt),e[9]=Ne,e[10]=f,e[11]=Ve}else Ve=e[11];I=Ve?.path??null}const y=I;let L;e[14]!==r||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==o?(L=async Ne=>{const Ve=await r({source:Ne.source,subpath:Ne.subpath,gitIdentityId:i?.gitIdentityId,scope:Ne.scope,targetSource:Ne.targetSource,selections:[{skillDir:Ne.skillDir}],conflictPolicy:"prompt",conflictDecisions:Ne.conflictDecisions},{directory:Ne.directoryOverride??null});if(Ve.ok){U.success(o("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ve.error?.kind==="conflicts"){S({source:Ne.source,subpath:Ne.subpath,scope:Ne.scope,targetSource:Ne.targetSource,skillDir:Ne.skillDir,directoryOverride:Ne.directoryOverride??null}),N(Ve.error.conflicts),k(!0);return}if(Ve.error?.kind==="authRequired"){U.error(Ve.error.message||o("settings.skills.catalog.installSkill.toast.authRequired"));return}U.error(Ve.error?.message||o("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=r,e[15]=i?.gitIdentityId,e[16]=n,e[17]=o,e[18]=L):L=e[18];const K=L;if(!i)return null;let H;e[19]!==o?(H=o("settings.skills.catalog.installSkill.title"),e[19]=o,e[20]=H):H=e[20];let G;e[21]!==H?(G=s.jsx(Ht,{children:H}),e[21]=H,e[22]=G):G=e[22];let W;e[23]!==o?(W=o("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=o,e[24]=W):W=e[24];let q;e[25]!==i.skillName?(q=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=q):q=e[26];let z;e[27]!==o?(z=o("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=o,e[28]=z):z=e[28];let $;e[29]!==W||e[30]!==q||e[31]!==z?($=s.jsxs(qt,{children:[W," ",q," ",z]}),e[29]=W,e[30]=q,e[31]=z,e[32]=$):$=e[32];let Z;e[33]!==G||e[34]!==$?(Z=s.jsxs(Vt,{children:[G,$]}),e[33]=G,e[34]=$,e[35]=Z):Z=e[35];let _;e[36]!==o?(_=o("settings.skills.catalog.installSkill.field.destination"),e[36]=o,e[37]=_):_=e[37];let ne;e[38]!==_?(ne=s.jsx("span",{className:"typography-ui-label text-foreground",children:_}),e[38]=_,e[39]=ne):ne=e[39];let X;e[40]!==c||e[41]!==p?(X=vi(c,p),e[40]=c,e[41]=p,e[42]=X):X=e[42];let te;e[43]===Symbol.for("react.memo_cache_sentinel")?(te=Ne=>{const Ve=Fd(Ne);g(Ve.scope),h(Ve.source==="agents"?"agents":"opencode")},e[43]=te):te=e[43];let he;e[44]!==c?(he=c==="user"?s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=he):he=e[45];let je;e[46]!==p?(je=p==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=p,e[47]=je):je=e[47];let fe;e[48]!==M||e[49]!==c||e[50]!==p?(fe=M(vi(c,p)),e[48]=M,e[49]=c,e[50]=p,e[51]=fe):fe=e[51];let ke;e[52]!==fe?(ke=s.jsx("span",{children:fe}),e[52]=fe,e[53]=ke):ke=e[53];let be;e[54]!==he||e[55]!==je||e[56]!==ke?(be=s.jsxs(Tt,{className:"w-fit gap-1.5",children:[he,je,ke]}),e[54]=he,e[55]=je,e[56]=ke,e[57]=be):be=e[57];let De;e[58]!==D||e[59]!==M?(De=sl.map(Ne=>s.jsx(gt,{value:Ne.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Ne.scope==="user"?s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),Ne.source==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:M(Ne.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:D(Ne.value)})]})},Ne.value)),e[58]=D,e[59]=M,e[60]=De):De=e[60];let oe;e[61]!==De?(oe=s.jsx(Et,{align:"start",children:De}),e[61]=De,e[62]=oe):oe=e[62];let ee;e[63]!==X||e[64]!==be||e[65]!==oe?(ee=s.jsxs(Dt,{value:X,onValueChange:te,children:[be,oe]}),e[63]=X,e[64]=be,e[65]=oe,e[66]=ee):ee=e[66];let ce;e[67]!==ne||e[68]!==ee?(ce=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ne,ee]}),e[67]=ne,e[68]=ee,e[69]=ce):ce=e[69];let ue;e[70]!==f||e[71]!==O||e[72]!==c||e[73]!==o?(ue=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:o("settings.skills.catalog.installSkill.field.project")}),f.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:o("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Dt,{value:O??"",onValueChange:Ne=>C(Ne),disabled:f.length===1,children:[s.jsx(Tt,{className:"w-fit",children:s.jsx(Jt,{placeholder:o("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Et,{align:"start",children:f.map(ux)})]})]}),e[70]=f,e[71]=O,e[72]=c,e[73]=o,e[74]=ue):ue=e[74];let Ie;e[75]!==i.warnings?(Ie=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=Ie):Ie=e[76];let ve;e[77]!==ce||e[78]!==ue||e[79]!==Ie?(ve=s.jsxs("div",{className:"mt-2 space-y-3",children:[ce,ue,Ie]}),e[77]=ce,e[78]=ue,e[79]=Ie,e[80]=ve):ve=e[80];let Re;e[81]!==n?(Re=()=>n(!1),e[81]=n,e[82]=Re):Re=e[82];let Me;e[83]!==o?(Me=o("settings.common.actions.cancel"),e[83]=o,e[84]=Me):Me=e[84];let me;e[85]!==Re||e[86]!==Me?(me=s.jsx(V,{size:"sm",variant:"ghost",onClick:Re,children:Me}),e[85]=Re,e[86]=Me,e[87]=me):me=e[87];const Te=d||!i.installable||c==="project"&&!y;let Oe;e[88]!==y||e[89]!==K||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==c||e[94]!==p?(Oe=()=>{K({source:i.repoSource,subpath:i.repoSubpath,scope:c,targetSource:p,skillDir:i.skillDir,directoryOverride:y})},e[88]=y,e[89]=K,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=c,e[94]=p,e[95]=Oe):Oe=e[95];let pe;e[96]!==d||e[97]!==o?(pe=o(d?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=d,e[97]=o,e[98]=pe):pe=e[98];let xe;e[99]!==Te||e[100]!==Oe||e[101]!==pe?(xe=s.jsx(V,{size:"sm",disabled:Te,onClick:Oe,children:pe}),e[99]=Te,e[100]=Oe,e[101]=pe,e[102]=xe):xe=e[102];let ae;e[103]!==me||e[104]!==xe?(ae=s.jsxs(as,{children:[me,xe]}),e[103]=me,e[104]=xe,e[105]=ae):ae=e[105];let ie;e[106]!==Z||e[107]!==ve||e[108]!==ae?(ie=s.jsxs($t,{className:"max-w-md",children:[Z,ve,ae]}),e[106]=Z,e[107]=ve,e[108]=ae,e[109]=ie):ie=e[109];let ge;e[110]!==n||e[111]!==a||e[112]!==ie?(ge=s.jsx(_t,{open:a,onOpenChange:n,children:ie}),e[110]=n,e[111]=a,e[112]=ie,e[113]=ge):ge=e[113];let Ee;e[114]!==w||e[115]!==K?(Ee=Ne=>{w&&(K({source:w.source,subpath:w.subpath,scope:w.scope,targetSource:w.targetSource,skillDir:w.skillDir,conflictDecisions:Ne,directoryOverride:w.directoryOverride??null}),k(!1))},e[114]=w,e[115]=K,e[116]=Ee):Ee=e[116];let Ke;e[117]!==j||e[118]!==b||e[119]!==Ee?(Ke=s.jsx(ix,{open:b,onOpenChange:k,conflicts:j,onConfirm:Ee}),e[117]=j,e[118]=b,e[119]=Ee,e[120]=Ke):Ke=e[120];let Le;return e[121]!==ge||e[122]!==Ke?(Le=s.jsxs(s.Fragment,{children:[ge,Ke]}),e[121]=ge,e[122]=Ke,e[123]=Le):Le=e[123],Le};function rx(t){return t.installSkills}function lx(t){return t.isInstalling}function cx(t){return t.projects}function dx(t){return t.activeProjectId}function ux(t){return s.jsx(gt,{value:t.id,children:t.label||t.path},t.id)}const mx=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,px=t=>{const e=t.trim();return mx.test(e)?`https://github.com/${e}`:null},gx=t=>{const e=px(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Hi=null;const fx=t=>{const e=go();return(!Hi||Hi.locale!==e)&&(Hi={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Hi.formatter.format(t)},hx=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const a=Date.now()-e;if(a<6e4)return{key:"common.relative.justNow",count:0};const n=Math.floor(a/6e4);if(n<60)return{key:"common.relative.minutesAgoShort",count:n};const i=Math.floor(n/60);if(i<24)return{key:"common.relative.hoursAgoShort",count:i};const o=Math.floor(i/24);if(o<7)return{key:"common.relative.daysAgoShort",count:o};const r=Math.floor(o/7);return r<52?{key:"common.relative.weeksAgoShort",count:r}:{key:"common.relative.yearsAgoShort",count:Math.floor(o/365)}},xx=t=>{const e=_e.c(50),{source:a,isActive:n,isLoading:i,skillsCount:o,onSelect:r,t:d}=t,c=a.stars??null;let g,p,h,f,m,v,C,b,k,u;if(e[0]!==n||e[1]!==i||e[2]!==r||e[3]!==o||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==c||e[8]!==d){const S=a.repoUpdatedAt?hx(a.repoUpdatedAt):null;b="button",k=r,u=n;const A=n?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-interactive-border-hover";e[19]!==A?(p=Se("oc-surface-elevated w-full min-h-24 text-left rounded-lg border bg-surface-elevated p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",A),e[19]=A,e[20]=p):p=e[20],m="min-w-0 flex-1 block";let x;e[21]!==a.label?(x=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=x):x=e[22];let E;e[23]!==i||e[24]!==o||e[25]!==d?(E=i?s.jsx(B,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):o!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:d("settings.skills.catalog.page.source.skillsCount",{count:o})}),e[23]=i,e[24]=o,e[25]=d,e[26]=E):E=e[26],e[27]!==x||e[28]!==E?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[x,E]}),e[27]=x,e[28]=E,e[29]=v):v=e[29],e[30]!==a.source?(C=s.jsx("span",{className:"typography-micro font-mono text-muted-foreground block mt-0.5 truncate",children:a.source}),e[30]=a.source,e[31]=C):C=e[31],g="flex items-center gap-3 mt-1",e[32]!==c||e[33]!==d?(h=c!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:d("settings.skills.catalog.page.source.stars",{count:c}),children:[s.jsx(B,{name:"star",className:"h-3 w-3"}),fx(c)]}),e[32]=c,e[33]=d,e[34]=h):h=e[34],f=S&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:S.key==="common.relative.justNow"?d(S.key):d("settings.skills.catalog.page.source.updated",{time:d(S.key,{count:S.count})})}),e[0]=n,e[1]=i,e[2]=r,e[3]=o,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=c,e[8]=d,e[9]=g,e[10]=p,e[11]=h,e[12]=f,e[13]=m,e[14]=v,e[15]=C,e[16]=b,e[17]=k,e[18]=u}else g=e[9],p=e[10],h=e[11],f=e[12],m=e[13],v=e[14],C=e[15],b=e[16],k=e[17],u=e[18];let j;e[35]!==g||e[36]!==h||e[37]!==f?(j=s.jsxs("span",{className:g,children:[h,f]}),e[35]=g,e[36]=h,e[37]=f,e[38]=j):j=e[38];let N;e[39]!==j||e[40]!==m||e[41]!==v||e[42]!==C?(N=s.jsxs("span",{className:m,children:[v,C,j]}),e[39]=j,e[40]=m,e[41]=v,e[42]=C,e[43]=N):N=e[43];let w;return e[44]!==p||e[45]!==N||e[46]!==b||e[47]!==k||e[48]!==u?(w=s.jsx("button",{type:b,onClick:k,"aria-pressed":u,className:p,children:N}),e[44]=p,e[45]=N,e[46]=b,e[47]=k,e[48]=u,e[49]=w):w=e[49],w},bx=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=Be(),{sources:i,itemsBySource:o,selectedSourceId:r,setSelectedSource:d,loadCatalog:c,loadSource:g,isLoadingCatalog:p,isLoadingSource:h,loadedSourceIds:f,lastCatalogError:m}=zn($s(K=>({sources:K.sources,itemsBySource:K.itemsBySource,selectedSourceId:K.selectedSourceId,setSelectedSource:K.setSelectedSource,loadCatalog:K.loadCatalog,loadSource:K.loadSource,isLoadingCatalog:K.isLoadingCatalog,isLoadingSource:K.isLoadingSource,loadedSourceIds:K.loadedSourceIds,lastCatalogError:K.lastCatalogError}))),[v,C]=l.useState(""),[b,k]=l.useState(!1),[u,j]=l.useState(!1),[N,w]=l.useState(null),[S,A]=l.useState(!1),[x,E]=l.useState(!1),M=l.useRef(null);l.useEffect(()=>{c()},[c]),l.useEffect(()=>{const K=i.filter(W=>!f[W.id]);if(K.length===0)return;let H=!1;return(async()=>{for(const W of K){if(H)return;await g(W.id)}})(),()=>{H=!0}},[i,f,g]),l.useEffect(()=>{!r||f[r]||g(r)},[r,f,g]),l.useEffect(()=>{const K=H=>{(H.metaKey||H.ctrlKey)&&H.key.toLowerCase()==="k"&&(H.preventDefault(),M.current?.focus())};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[]);const T=v.trim().length>0,D=l.useMemo(()=>T?sa(i.flatMap(K=>o[K.id]||[]),v,K=>[K.skillName,K.frontmatterName,K.description]):r?o[r]||[]:[],[i,o,r,v,T]),R=l.useMemo(()=>i.find(K=>K.id===r)||null,[i,r]),O=!!(r&&r.startsWith("custom:")),I=async()=>{if(!(!r||!O)){A(!0);try{const K=await En();if(!K)return;const G=(K.skillCatalogs??[]).filter(W=>W.id!==r);await kt({skillCatalogs:G}),await c({refresh:!0}),E(!1)}finally{A(!1)}}},y=T?n("settings.skills.catalog.page.list.searchTitle"):R?.label??"",L=!T&&r!==null&&!f[r]&&(h||p);return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:n("settings.skills.catalog.page.title"),showSaveStatus:!1,children:[a&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(Hr,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:K=>e(K),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:n("settings.skills.catalog.page.subtitle")}),s.jsx("div",{"data-settings-item":"skills.catalog.search",className:"mb-5",children:s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(B,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Ge,{ref:M,value:v,onChange:K=>C(K.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:Se("h-8 pl-8 w-full",v&&"pr-8")}),v&&s.jsx("button",{type:"button",onClick:()=>{C(""),M.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center h-4 w-4 rounded text-muted-foreground hover:text-foreground transition-colors",title:n("settings.skills.catalog.page.search.clear"),children:s.jsx(B,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(He,{title:n("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[i.map(K=>s.jsx(xx,{source:K,isActive:K.id===r,isLoading:h&&!f[K.id],skillsCount:f[K.id]?(o[K.id]||[]).length:null,onSelect:()=>d(K.id),t:n},K.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>k(!0),className:"min-h-24 text-left rounded-lg border border-dashed border-[var(--interactive-border)] hover:border-[var(--interactive-border-hover)] hover:bg-[var(--surface-muted)] p-3.5 flex gap-3 items-start transition-colors",children:[s.jsx("span",{className:"flex items-center justify-center rounded-md bg-transparent text-muted-foreground w-8 h-8 shrink-0",children:s.jsx(B,{name:"add",className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground block",children:n("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:n("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),m&&s.jsx(He,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:n("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:m.message})]})}),s.jsxs(He,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-micro font-medium uppercase tracking-wide text-muted-foreground truncate",children:y}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:D.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{r&&!T?g(r,{refresh:!0}):c({refresh:!0})},disabled:p||h,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(B,{name:"refresh",className:Se("h-3.5 w-3.5",(p||h)&&"animate-spin")})}),O&&!T&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>E(!0),disabled:S,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),L||h&&D.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(B,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):D.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:D.map(K=>{const H=K.installed?.isInstalled,G=K.installed?.scope,W=gx(K);return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:K.skillName}),H&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:G||n("settings.skills.catalog.page.badge.unknown")})}),!K.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.notInstallable")})]}),K.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:K.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80 mt-1 flex items-center gap-2 min-w-0",children:[W?s.jsxs("a",{href:W,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline truncate inline-flex items-center gap-1",title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:[s.jsx(B,{name:"github",className:"h-3 w-3 shrink-0"}),K.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:K.repoSource}),K.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:K.skillDir})]})]}),K.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:K.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[W&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(W,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"})}),H?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:n("settings.skills.catalog.page.badge.installed",{scope:G||""}),children:s.jsx(B,{name:"check",className:"h-4 w-4"})}):s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",disabled:!K.installable,onClick:()=>{w(K),j(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${K.sourceId}:${K.skillDir}`)})})]})]}),s.jsx(ax,{open:b,onOpenChange:k}),s.jsx(ox,{open:u,onOpenChange:j,item:N}),s.jsx(_t,{open:x,onOpenChange:K=>{S||E(K)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(qt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(as,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>E(!1),disabled:S,children:n("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:()=>{I()},disabled:S,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},vx=()=>{const t=_e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(bx,{mode:"external",onModeChange:Nx,showModeTabs:!1}),t[0]=e):e=t[0],e},yx="SKILL.md",jx="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",Zi=(t,e)=>{const a=Tp({description:t}).trimEnd(),n=e.trimStart();return`---
23
+ ${a}
24
+ ---${n?`
25
+
26
+ ${n}`:`
27
+ `}`},kx=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Kd=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let a=null;try{const n=Ep(e[1]);if(kx(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},wx=(t,e)=>{const a=Kd(t);return Zi(e,a.instructions)},Sx=()=>{const{t}=Be(),{currentTheme:e}=ba(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:o,updateSkill:r,skillDraft:d,setSkillDraft:c,setSelectedSkill:g}=rn($s(de=>({selectedSkillName:de.selectedSkillName,getSkillByName:de.getSkillByName,getSkillDetail:de.getSkillDetail,createSkill:de.createSkill,updateSkill:de.updateSkill,skillDraft:de.skillDraft,setSkillDraft:de.setSkillDraft,setSelectedSkill:de.setSelectedSkill}))),p=en(),h=rn(de=>Lr(de,p)),f=a?n(a,p):null,m=!!(d&&d.name===a&&!f),v=!!(a&&!f&&!d),C=f?.path==="<built-in>";l.useEffect(()=>{v&&g(null)},[v,g]);const[b,k]=l.useState(""),[u,j]=l.useState("user"),[N,w]=l.useState("opencode"),[S,A]=l.useState(""),[x,E]=l.useState(""),[M,T]=l.useState(()=>Zi("","")),[D,R]=l.useState("edit"),[O,I]=l.useState([]),[y,L]=l.useState([]),[K,H]=l.useState(!1),[G,W]=l.useState(!1),[q,z]=l.useState(""),[$,Z]=l.useState(""),[_,ne]=l.useState(!1),[X,te]=l.useState(""),[he,je]=l.useState(""),[fe,ke]=l.useState(null),[be,De]=l.useState(!1),[oe,ee]=l.useState(""),[ce,ue]=l.useState(null),[Ie,ve]=l.useState(!1),Re=fe?he!==oe:X.trim()!=="",Me=l.useCallback(de=>{switch(de){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),me=l.useCallback(de=>{switch(de){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]),Te=JSON.stringify([p,a,f?.path,m]),Oe=l.useRef(null),pe=l.useRef({key:Te,markdown:M});pe.current={key:Te,markdown:M};const xe=l.useRef("");l.useEffect(()=>{let de=!1;const Ue=(ze,Ze)=>{if(pe.current.key!==Te)return;const tt=Zi(ze,Ze),lt=Oe.current===Te&&pe.current.markdown!==xe.current;Oe.current=Te,xe.current=tt,lt||(A(ze),E(Ze),T(tt))};return(async()=>{if(m&&d){W(!1);const ze=d.description||"",Ze=d.instructions||"";k(d.name||""),j(d.scope||"user"),w(d.source==="agents"?"agents":"opencode"),Ue(ze,Ze),z(""),Z(""),I([]),L(d.pendingFiles||[])}else if(a&&f){W(Oe.current!==Te);try{const ze=await i(a,p);if(!de&&pe.current.key===Te&&ze){const Ze=ze.sources.md,tt=Ze.description||"",lt=Ze.instructions||"";Ue(tt,lt),z(tt),Z(lt),I(Ze.supportingFiles||[])}}catch(ze){console.error("Failed to load skill details:",ze)}finally{de||W(!1)}}})(),()=>{de=!0}},[f,m,a,p,h,d,i,Te]);const ae=re(de=>de.editorFontSize),ie=l.useMemo(()=>{const de=[Ll(e,{fontSize:ae})],Ue=hl(yx);return Ue&&de.push(Ue),de.push(Kl.lineWrapping),de},[e,ae]),ge=l.useMemo(()=>{const de=X.trim()||"supporting-file.md",Ue=Tu(de),et=!!Ue&&Ue!=="markdown",ze=[Ll(e,et?{syntaxColors:!1,fontSize:ae}:{fontSize:ae})],Ze=hl(de);return Ze&&ze.push(Ze),et&&Ue&&ze.push(Dp({language:Ue,themeName:e.metadata.id,theme:Rp(e)})),ze.push(Kl.lineWrapping),ze},[e,X,ae]),Ee=l.useCallback(de=>{A(de),T(Ue=>wx(Ue,de))},[]),Ke=l.useCallback(de=>{T(de);const Ue=Kd(de);A(Ue.description??""),E(Ue.instructions)},[]),Le=de=>de?!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(de)||de.length>64?t("settings.skills.page.toast.invalidSkillName"):null:t("settings.skills.page.toast.skillNameRequired"),Ne=l.useCallback(async()=>{const de=a?.trim();return m||C||!de||S===q&&x===$?Us:S.trim()?await r(de,{name:de,description:S.trim(),instructions:x.trim()||void 0,targetPath:f?.path},p)?(pe.current.key===Te&&(xe.current=Zi(S,x),z(S),Z(x)),Tn):xs(t("settings.skills.page.toast.updateSkillFailed")):xs(t("settings.skills.page.toast.descriptionRequired"))},[S,x,m,C,q,$,f?.path,a,p,Te,t,r]),Ve=ti(Ne),Ye=async()=>{const de=b.trim().replace(/\s+/g,"-").toLowerCase(),Ue=Le(de);if(Ue){U.error(Ue);return}if(!S.trim()){U.error(t("settings.skills.page.toast.descriptionRequired"));return}if(h.some(et=>et.name===de)){U.error(t("settings.skills.page.toast.skillExists"));return}H(!0);try{const et={name:de,description:S.trim(),instructions:x.trim()||void 0,scope:u,source:N,supportingFiles:y.length>0?y:void 0};await o(et,p)?(c(null),L([]),g(de),U.success(t("settings.skills.page.toast.skillCreated"))):U.error(t("settings.skills.page.toast.createSkillFailed"))}catch(et){console.error("Error creating skill:",et),U.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{H(!1)}},pt=()=>{c(null),g(null)},vt=()=>{ke(null),te(""),je(""),ee(""),ne(!0)},wt=async de=>{if(ke(de),te(de),m){const et=y.find(ze=>ze.path===de)?.content||"";je(et),ee(et),ne(!0);return}if(a){De(!0),ne(!0);try{const{readSupportingFile:Ue}=rn.getState(),et=await Ue(a,de,p);je(et||""),ee(et||"")}catch{U.error(t("settings.skills.page.toast.loadFileContentFailed")),je(""),ee("")}finally{De(!1)}}},yt=async()=>{if(!X.trim()){U.error(t("settings.skills.page.toast.fileNameRequired"));return}const de=X.trim(),Ue=fe!==null;if(m){if(Ue)L(Ze=>Ze.map(tt=>tt.path===fe?{path:de,content:he}:tt)),U.success(t("settings.skills.page.toast.fileUpdated",{path:de}));else{if(y.some(Ze=>Ze.path===de)){U.error(t("settings.skills.page.toast.fileExists"));return}L(Ze=>[...Ze,{path:de,content:he}]),U.success(t("settings.skills.page.toast.fileAdded",{path:de}))}ne(!1),ke(null);return}if(!a){U.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:et}=rn.getState();if(await et(a,de,he,p)){U.success(Ue?t("settings.skills.page.toast.fileUpdated",{path:de}):t("settings.skills.page.toast.fileCreated",{path:de})),ne(!1),ke(null);const Ze=await i(a,p);Ze&&I(Ze.sources.md.supportingFiles||[])}else U.error(t(Ue?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},st=de=>{if(m){L(Ue=>Ue.filter(et=>et.path!==de)),U.success(t("settings.skills.page.toast.fileRemoved",{path:de}));return}a&&ue(de)},rt=async()=>{if(!ce||!a)return;ve(!0);const{deleteSupportingFile:de}=rn.getState();if(await de(a,ce,p)){U.success(t("settings.skills.page.toast.fileDeleted",{path:ce}));const et=await i(a,p);et&&I(et.sources.md.supportingFiles||[]),ue(null)}else U.error(t("settings.skills.page.toast.deleteFileFailed"));ve(!1)};return!a&&!d||v?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(B,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):G?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:m?t("settings.skills.page.title.newSkill"):a,description:f?t("settings.skills.page.subtitle.skillLocation",{location:Me(vi(f.scope,f.source))}):t("settings.skills.page.subtitle.newSkill"),onBlurCapture:Ve.onBlurCapture,children:[s.jsxs(He,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[m&&s.jsxs(Ct,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(Ge,{value:b,onChange:de=>k(de.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Dt,{value:vi(u,N),onValueChange:de=>{const Ue=Fd(de);j(Ue.scope),w(Ue.source==="agents"?"agents":"opencode")},children:[s.jsxs(Tt,{size:Qt,className:"w-fit gap-1.5",children:[u==="user"?s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),N==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Me(vi(u,N))})]}),s.jsx(Et,{align:"start",children:sl.map(de=>s.jsx(gt,{value:de.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[de.scope==="user"?s.jsx(B,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"folder",className:"h-3.5 w-3.5"}),de.source==="agents"?s.jsx(B,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Me(de.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:me(de.value)})]})},de.value))})]})]}),s.jsx(Kt,{label:s.jsxs(s.Fragment,{children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),info:t("settings.skills.page.field.descriptionHint"),controlClassName:"w-full max-w-none",children:s.jsx(Rs,{value:S,onChange:de=>Ee(de.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:C})})]}),s.jsx(He,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Mp,{currentMode:D==="preview"?"preview":"edit",onToggle:()=>R(de=>de==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:Se("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",jx),onKeyDown:de=>{de.key==="Enter"&&(de.metaKey||de.ctrlKey)&&(de.preventDefault(),Ve.requestSave())},children:D==="preview"?s.jsx(Ds,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Eu,{content:M,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(Fl,{value:M,onChange:Ke,readOnly:C,extensions:ie,className:"h-full",enableSearch:!0})})}),s.jsx(He,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:vt,disabled:C,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const de=m?y:O;return de.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:de.map(Ue=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>wt(Ue.path),children:[s.jsx(B,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Ue.path}),m&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!C&&s.jsx(V,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:et=>{et.stopPropagation(),st(Ue.path)},children:s.jsx(B,{name:"delete-bin",className:"h-3 w-3"})})]},Ue.path))})})()}),m&&s.jsx(He,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{onClick:()=>{Ye()},disabled:K||!b.trim()||!S.trim(),size:"xs",className:"!font-normal",children:t(K?"settings.common.actions.saving":"settings.skills.page.actions.createSkill")}),s.jsx(V,{variant:"ghost",onClick:pt,disabled:K,size:"xs",className:"!font-normal",children:t("settings.common.actions.cancel")})]})})]}),s.jsx(_t,{open:ce!==null,onOpenChange:de=>{!de&&!Ie&&ue(null)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(qt,{children:t("settings.skills.page.deleteFileDialog.description",{path:ce??""})})]}),s.jsxs(as,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>ue(null),disabled:Ie,children:t("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:rt,disabled:Ie,children:t("settings.common.actions.delete")})]})]})}),s.jsx(_t,{open:_,onOpenChange:de=>{if(de){ne(!0);return}if(fe!==null&&he!==oe){yt();return}ne(!1),ke(null)},children:s.jsxs($t,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Vt,{className:"flex-shrink-0",children:[s.jsx(Ht,{children:t(fe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(qt,{children:t(fe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),be?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Pt,children:t("settings.skills.page.fileDialog.field.filePath")}),!fe&&s.jsx(Gt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(Ge,{value:X,onChange:de=>te(de.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-ring",disabled:fe!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Pt} flex-shrink-0`,children:t("settings.skills.page.fileDialog.field.content")}),s.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(Fl,{value:he,onChange:je,extensions:ge,className:"h-full",enableSearch:!0})})]})]}),s.jsx(as,{className:"mt-4",children:fe?s.jsx(V,{size:"sm",onClick:()=>{yt()},disabled:be,children:t("settings.common.actions.close")}):s.jsxs(s.Fragment,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>{ne(!1),ke(null)},children:t("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:()=>{yt()},disabled:be||!Re,children:t("settings.skills.page.actions.createFile")})]})})]})})]})},sc=t=>{const e=_e.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(vx,{}):s.jsx(Sx,{}),e[0]=n,e[1]=i):i=e[1],i};function Nx(){}const Cx=t=>{const e=_e.c(26),{header:a,footer:n,children:i,className:o,variant:r}=t,d=r===void 0?"sidebar":r,c=ms(),g=l.useRef(null),[p,h]=l.useState(!1),[f,m]=l.useState(!1),v=d==="background"||c?"bg-background":"bg-sidebar",C=v==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const D=g.current;if(!D){h(!1),m(!1);return}if(!(D.scrollHeight>D.clientHeight+1)){h(!1),m(!1);return}h(D.scrollTop>1),m(D.scrollTop+D.clientHeight<D.scrollHeight-1)},e[0]=b):b=e[0];const k=b;let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{k()},e[1]=u):u=e[1];let j;e[2]!==i?(j=[i,k],e[2]=i,e[3]=j):j=e[3],l.useEffect(u,j);let N,w;e[4]===Symbol.for("react.memo_cache_sentinel")?(N=()=>{const D=g.current;if(!D)return;const R=()=>k();return D.addEventListener("scroll",R,{passive:!0}),()=>D.removeEventListener("scroll",R)},w=[k],e[4]=N,e[5]=w):(N=e[4],w=e[5]),l.useEffect(N,w);let S;e[6]!==v||e[7]!==o?(S=Se("flex h-full flex-col",v,o),e[6]=v,e[7]=o,e[8]=S):S=e[8];let A;e[9]!==i?(A=s.jsx(Ds,{ref:g,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=A):A=e[10];let x;e[11]!==C||e[12]!==p?(x=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${C} 0%, transparent 100%)`}}),e[11]=C,e[12]=p,e[13]=x):x=e[13];let E;e[14]!==C||e[15]!==f?(E=f&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${C} 0%, transparent 100%)`}}),e[14]=C,e[15]=f,e[16]=E):E=e[16];let M;e[17]!==E||e[18]!==A||e[19]!==x?(M=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[A,x,E]}),e[17]=E,e[18]=A,e[19]=x,e[20]=M):M=e[20];let T;return e[21]!==n||e[22]!==a||e[23]!==M||e[24]!==S?(T=s.jsxs("div",{className:S,children:[a,M,n]}),e[21]=n,e[22]=a,e[23]=M,e[24]=S,e[25]=T):T=e[25],T},Ix=t=>{const e=_e.c(23),{title:a,metadata:n,selected:i,onSelect:o,icon:r,actions:d,className:c}=t,g=i===void 0?!1:i,p=d&&d.length>0,h=g?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==c||e[1]!==h?(f=Se("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",h,c),e[0]=c,e[1]=h,e[2]=f):f=e[2];let m;e[3]!==a?(m=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=m):m=e[4];let v;e[5]!==r||e[6]!==m?(v=s.jsxs("div",{className:"flex items-center gap-1.5",children:[r,m]}),e[5]=r,e[6]=m,e[7]=v):v=e[7];let C;e[8]!==n?(C=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=C):C=e[9];let b;e[10]!==o||e[11]!==v||e[12]!==C?(b=s.jsxs("button",{onClick:o,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,children:[v,C]}),e[10]=o,e[11]=v,e[12]=C,e[13]=b):b=e[13];let k;e[14]!==d||e[15]!==p?(k=p&&s.jsxs(Jn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsx(V,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:d.map(Px)})]}),e[14]=d,e[15]=p,e[16]=k):k=e[16];let u;e[17]!==b||e[18]!==k?(u=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[b,k]}),e[17]=b,e[18]=k,e[19]=u):u=e[19];let j;return e[20]!==f||e[21]!==u?(j=s.jsx("div",{className:f,children:u}),e[20]=f,e[21]=u,e[22]=j):j=e[22],j};function Px(t){const e=t.icon;return s.jsxs(xn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:Se(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(B,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Ax=t=>{const e=_e.c(38),{onItemSelect:a}=t,{t:n}=Be(),i=hn(Tx),o=re(Ex),r=re(Dx),{currentTheme:d}=ba();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=ms(),e[0]=c):c=e[0];const g=c,p=Mx;let h,f;e[1]!==i||e[2]!==o||e[3]!==r?(h=()=>{if(i.length===0){o!==null&&r(null);return}o&&i.some(A=>A.id===o)||r(i[0].id)},f=[i,o,r],e[1]=i,e[2]=o,e[3]=r,e[4]=h,e[5]=f):(h=e[4],f=e[5]),l.useEffect(h,f);let m;e[6]===Symbol.for("react.memo_cache_sentinel")?(m=Se("border-b px-3","pt-4 pb-3"),e[6]=m):m=e[6];let v;e[7]!==n?(v=n("settings.page.projects.title"),e[7]=n,e[8]=v):v=e[8];let C;e[9]!==v?(C=s.jsx("h2",{className:`${va} mb-3`,children:v}),e[9]=v,e[10]=C):C=e[10];let b;e[11]!==i.length||e[12]!==n?(b=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=b):b=e[13];let k;e[14]!==b?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:b}),e[14]=b,e[15]=k):k=e[15];let u;e[16]!==n?(u=!g&&s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:p,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(B,{name:"add",className:"size-4"})}),e[16]=n,e[17]=u):u=e[17];let j;e[18]!==k||e[19]!==u?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,u]}),e[18]=k,e[19]=u,e[20]=j):j=e[20];let N;e[21]!==j||e[22]!==C?(N=s.jsxs("div",{className:m,children:[C,j]}),e[21]=j,e[22]=C,e[23]=N):N=e[23];let w;if(e[24]!==d||e[25]!==a||e[26]!==i||e[27]!==o||e[28]!==r){let A;e[30]!==d||e[31]!==a||e[32]!==o||e[33]!==r?(A=x=>{const E=x.id===o,M=x.icon?Mu[x.icon]:null,T=x.color?Ru[x.color]??null:null,D=M?s.jsx(B,{name:M,className:Se("h-4 w-4",E?"text-foreground":"text-muted-foreground/70"),style:T?{color:T}:void 0}):s.jsx(B,{name:"folder",className:Se("h-4 w-4",E?"text-foreground":"text-muted-foreground/70"),style:T?{color:T}:void 0}),R=x.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:x.iconBackground?{backgroundColor:x.iconBackground}:void 0,children:s.jsx(Ou,{project:x,options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:D})}):D;return s.jsx(Ix,{title:x.label||x.path,icon:R,selected:E,onSelect:()=>{r(x.id),a?.()}},x.id)},e[30]=d,e[31]=a,e[32]=o,e[33]=r,e[34]=A):A=e[34],w=i.map(A),e[24]=d,e[25]=a,e[26]=i,e[27]=o,e[28]=r,e[29]=w}else w=e[29];let S;return e[35]!==N||e[36]!==w?(S=s.jsx(Cx,{variant:"background",header:N,children:w}),e[35]=N,e[36]=w,e[37]=S):S=e[37],S};function Tx(t){return t.projects}function Ex(t){return t.settingsProjectsSelectedId}function Dx(t){return t.setSettingsProjectsSelectedId}function Mx(){Du.requestDirectoryDialog()}const Rx=()=>{const t=_e.c(30),{t:e}=Be(),a=hn(Ox),n=hn(Lx),i=re(Fx),o=re(Kx);let r;e:{if(!i){r=null;break e}let b;t[0]!==a||t[1]!==i?(b=a.find(k=>k.id===i)??null,t[0]=a,t[1]=i,t[2]=b):b=t[2],r=b}const d=r;let c,g;t[3]!==a||t[4]!==i||t[5]!==o?(c=()=>{if(a.length===0){o(null);return}i&&a.some(b=>b.id===i)||o(a[0].id)},g=[a,i,o],t[3]=a,t[4]=i,t[5]=o,t[6]=c,t[7]=g):(c=t[6],g=t[7]),l.useEffect(c,g);let p;t[8]!==d||t[9]!==n?(p=async b=>{d&&n(d.id,{label:b.label,icon:b.icon,color:b.color,iconBackground:b.iconBackground,defaultAgent:b.defaultAgent??null,defaultModel:b.defaultModel??null,defaultVariant:b.defaultVariant??null})},t[8]=d,t[9]=n,t[10]=p):p=t[10];const h=p;if(!d){let b;t[11]!==e?(b=e("settings.page.projects.title"),t[11]=e,t[12]=b):b=t[12];let k;t[13]!==e?(k=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=k):k=t[14];let u;t[15]!==k?(u=s.jsx("p",{className:"typography-meta text-muted-foreground",children:k}),t[15]=k,t[16]=u):u=t[16];let j;return t[17]!==b||t[18]!==u?(j=s.jsx(ns,{title:b,showSaveStatus:!0,children:u}),t[17]=b,t[18]=u,t[19]=j):j=t[19],j}let f;t[20]!==d.label||t[21]!==e?(f=d.label??e("settings.projects.page.title.default"),t[20]=d.label,t[21]=e,t[22]=f):f=t[22];const m=f;let v;t[23]!==h||t[24]!==d?(v=s.jsx(jp,{project:d,onIdentitySave:h}),t[23]=h,t[24]=d,t[25]=v):v=t[25];let C;return t[26]!==m||t[27]!==d.path||t[28]!==v?(C=s.jsx(ns,{title:m,description:d.path,showSaveStatus:!0,outerClassName:"bg-background",children:v}),t[26]=m,t[27]=d.path,t[28]=v,t[29]=C):C=t[29],C};function Ox(t){return t.projects}function Lx(t){return t.updateProjectMeta}function Fx(t){return t.settingsProjectsSelectedId}function Kx(t){return t.setSettingsProjectsSelectedId}const zx=Os({clientToken:Rt().trim().min(1)}),Ux=Os({error:Ap("Invalid or expired pairing session")}),_x=async t=>{const e=await t.json().catch(()=>null);if(!t.ok)return t.status===400&&Ux.safeParse(e).success?{kind:"rejected"}:{kind:"http-error",status:t.status};const a=zx.safeParse(e);return a.success?{kind:"success",token:a.data.clientToken}:{kind:"invalid-response"}};function $x(t){const e=_e.c(42),{t:a}=Be(),[n,i]=at.useState(null),o=at.useRef(null),r=at.useRef(null);let d,c;e[0]!==t?(d=()=>(r.current=t,i(null),()=>{r.current=null;const I=o.current;o.current=null,I?.(null)}),c=[t],e[0]=t,e[1]=d,e[2]=c):(d=e[1],c=e[2]),at.useEffect(d,c);let g;e[3]!==t?(g=(I,y)=>{const L=y===void 0?"settings.common.actions.saveChanges":y;return!t||r.current!==t||o.current?Promise.resolve(null):new Promise(K=>{o.current=K,i({messageKey:I,actionKey:L})})},e[3]=t,e[4]=g):g=e[4];const p=g;let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=I=>{const y=o.current;o.current=null,i(null),y?.(I)},e[5]=h):h=e[5];const f=h,m=n!==null;let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=I=>{I||f(!1)},e[6]=v):v=e[6];let C;e[7]!==a?(C=a("settings.remoteInstances.page.title"),e[7]=a,e[8]=C):C=e[8];let b;e[9]!==C?(b=s.jsx(Ht,{children:C}),e[9]=C,e[10]=b):b=e[10];let k;e[11]!==n||e[12]!==a?(k=n?a(n.messageKey):null,e[11]=n,e[12]=a,e[13]=k):k=e[13];let u;e[14]!==k?(u=s.jsx(qt,{children:k}),e[14]=k,e[15]=u):u=e[15];let j;e[16]!==b||e[17]!==u?(j=s.jsxs(Vt,{children:[b,u]}),e[16]=b,e[17]=u,e[18]=j):j=e[18];let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=()=>f(!1),e[19]=N):N=e[19];let w;e[20]!==a?(w=a("settings.common.actions.cancel"),e[20]=a,e[21]=w):w=e[21];let S;e[22]!==w?(S=s.jsx(V,{variant:"outline",autoFocus:!0,onClick:N,children:w}),e[22]=w,e[23]=S):S=e[23];let A;e[24]===Symbol.for("react.memo_cache_sentinel")?(A=()=>f(!0),e[24]=A):A=e[24];let x;e[25]!==n||e[26]!==a?(x=n?a(n.actionKey):null,e[25]=n,e[26]=a,e[27]=x):x=e[27];let E;e[28]!==x?(E=s.jsx(V,{onClick:A,children:x}),e[28]=x,e[29]=E):E=e[29];let M;e[30]!==S||e[31]!==E?(M=s.jsxs(as,{children:[S,E]}),e[30]=S,e[31]=E,e[32]=M):M=e[32];let T;e[33]!==j||e[34]!==M?(T=s.jsxs($t,{children:[j,M]}),e[33]=j,e[34]=M,e[35]=T):T=e[35];let D;e[36]!==T||e[37]!==m?(D=s.jsx(_t,{open:m,onOpenChange:v,children:T}),e[36]=T,e[37]=m,e[38]=D):D=e[38];const R=D;let O;return e[39]!==p||e[40]!==R?(O={confirm:p,dialog:R},e[39]=p,e[40]=R,e[41]=O):O=e[41],O}const Xi=()=>Math.floor(2e4+Math.random()*3e4),Bx=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},Vx=()=>{if(typeof navigator>"u")return;const t=(navigator.userAgent||"").toLowerCase();if(t.includes("mac"))return"macos";if(t.includes("win"))return"windows";if(t.includes("linux"))return"linux"},nc=t=>{switch((t||"").toLowerCase()){case"ios":return"iOS";case"android":return"Android";case"macos":case"darwin":return"macOS";case"windows":case"win32":return"Windows";case"linux":return"Linux";default:return null}},ac=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},Hx=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),nl=t=>!!(t&&Hx.has(t)),ic=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||nl(t)?"connecting":"idle",oc=t=>{switch(t){case"ready":return"settings.remoteInstances.page.state.ready";case"connecting":return"settings.remoteInstances.page.state.connecting";case"error":return"settings.remoteInstances.page.state.problem";default:return"settings.remoteInstances.page.state.notConnected"}},qx=t=>{const e=(t||"").toLowerCase();return e?e.includes("ui authentication")||e.includes("ui password")?"uiPassword":e.includes("already in use")||e.includes("eaddrinuse")?"localPort":e.includes("neither bun nor npm")?"noRuntime":e.includes("opencode cli is not installed")?"noOpencode":e.includes("requires a ui password")?"uiPassword":e.includes("preferred remote openchamber port")?"externalPort":null:null},rc={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Gx=t=>t==="noRuntime"?rc.noRuntime:t==="noOpencode"?rc.noOpencode:null,lc=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||nl(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Wx=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,Jx=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Xi(),remoteHost:"127.0.0.1",remotePort:80}),Qx=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",on=t=>{const e=_e.c(7),{label:a,hint:n}=t;let i;e[0]!==a?(i=s.jsx("span",{children:a}),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==n?(o=s.jsx(Gt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=o):o=e[3];let r;return e[4]!==i||e[5]!==o?(r=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Pt}`,children:[i,o]}),e[4]=i,e[5]=o,e[6]=r):r=e[6],r},Yx=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},cc=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Zx=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Xx=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),o=e[3]||"";return`[${n}] [${i}] ${o}`},Ir=(t="",e="")=>({id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`header-${Date.now()}-${Math.random().toString(16).slice(2)}`,name:t,value:e}),eb=t=>t.trim().toLowerCase()==="authorization",Qo=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!eb(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},tb=t=>Object.entries(t||{}).map(([e,a])=>Ir(e,a)),zd=()=>{if(typeof window>"u")return null;const e=ki()||window.location.href;try{const a=Number(new URL(e).port||window.location.port);return Number.isFinite(a)&&a>0?a:null}catch{const a=Number(window.location.port);return Number.isFinite(a)&&a>0?a:null}},dc=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},sb=async()=>{const t=$a(ki())||window.location.origin;if(!us()||!wi()||(await En())?.desktopLanAccessActive!==!0)return t;const a=await vd(),n=zd();return!a||!n?t:`http://${a}:${n}`},qi=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},nb=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},ab=()=>{const{t}=Be(),e=re(F=>F.timeFormatPreference),{clientAuth:a}=Ur(),n=us(),i=As(F=>F.instances),o=As(F=>F.statusesById),r=As(F=>F.importCandidates),d=As(F=>F.isLoading),c=As(F=>F.isImportsLoading),g=As(F=>F.isSaving),p=As(F=>F.error),h=As(F=>F.load),f=As(F=>F.loadImports),m=As(F=>F.refreshStatuses),v=As(F=>F.upsertInstance),C=As(F=>F.createFromCommand),b=As(F=>F.removeInstance),k=As(F=>F.connect),u=As(F=>F.disconnect),j=As(F=>F.retry),N=re(F=>F.settingsRemoteInstancesSelectedId),w=re(F=>F.setSettingsRemoteInstancesSelectedId),{confirm:S,dialog:A}=$x(N),x=l.useMemo(()=>N&&i.find(F=>F.id===N)||null,[i,N]),[E,M]=l.useState(null),[T,D]=l.useState(!1),[R,O]=l.useState(!1),[I,y]=l.useState(null),[L,K]=l.useState([]),[H,G]=l.useState(null),[W,q]=l.useState(""),[z,$]=l.useState(!1),[Z,_]=l.useState({}),[ne,X]=l.useState(!1),[te,he]=l.useState(!1),[je,fe]=l.useState(()=>Date.now()),[ke,be]=l.useState([]),[De,oe]=l.useState({}),[ee,ce]=l.useState("local"),[ue,Ie]=l.useState(!1),[ve,Re]=l.useState(!1),[Me,me]=l.useState(""),[Te,Oe]=l.useState(""),[pe,xe]=l.useState(""),[ae,ie]=l.useState([]),[ge,Ee]=l.useState(""),[Ke,Le]=l.useState(null),[Ne,Ve]=l.useState(!1),[Ye,pt]=l.useState(!1),[vt,wt]=l.useState(!1),[yt,st]=l.useState(null),[rt,de]=l.useState(""),[Ue,et]=l.useState(""),[ze,Ze]=l.useState(""),[tt,lt]=l.useState([]),[Q,nt]=l.useState([]),[ot,it]=l.useState([]),[ft,bt]=l.useState(!1),[ht,Nt]=l.useState(""),[At,$e]=l.useState(null),[Xe,mt]=l.useState(null),[Fe,J]=l.useState(null),[ye,Ae]=l.useState(null),[Y,Pe]=l.useState(!1),[Je,se]=l.useState(!1),[We,ut]=l.useState("configure"),[Ce,qe]=l.useState(!1),[jt,Ot]=l.useState("relay"),[Yt,Zt]=l.useState(!0),[Ft,ps]=l.useState(null),gs=l.useMemo(()=>Q.filter(F=>!!F.revokedAt).length,[Q]),[tn,Bs]=l.useState(!1),[Vs,cn]=l.useState("saved"),[sn,nn]=l.useState(""),[Hs,Dn]=l.useState(""),[Lt,Xt]=l.useState(""),[Wt,Mt]=l.useState(!1);l.useEffect(()=>{h(),f()},[h,f]);const cs=l.useCallback(async()=>{Ie(!0),Le(null);try{const F=await Nl();be(F.hosts||[]),ce(F.defaultHostId||"local")}catch(F){Le(F instanceof Error?F.message:String(F))}finally{Ie(!1)}},[]);l.useEffect(()=>{cs()},[cs]);const is=l.useCallback(async(F,le=ee)=>{Re(!0),Le(null);try{return await Cl({hosts:F,defaultHostId:le,initialHostChoiceCompleted:!0}),be(F),ce(le),!0}catch(Qe){return Le(Qe instanceof Error?Qe.message:String(Qe)),!1}finally{Re(!1)}},[ee]),vo=l.useCallback(async()=>{const F=Il(Te);if(!F){Le(t("desktopHostSwitcher.error.invalidUrl"));return}const le=F.persistedUrl,dt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Me.trim()||ai(le),url:le,apiUrl:le,...pe.trim()?{clientToken:pe.trim()}:{},...Qo(ae)?{requestHeaders:Qo(ae)}:{}};await is([dt,...ke],ee)&&(me(""),Oe(""),xe(""),ie([]),Ve(!1),F.redeemUrl&&qi(F.redeemUrl))},[ee,ae,ke,Me,pe,Te,is,t]),yo=l.useCallback(async()=>{Le(null);const F=Um(ge);if(!F){Le(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const le=await _m().catch(()=>""),Qe=JSON.stringify({pairingId:F.pairingId,secret:F.secret,clientLabel:F.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Vx(),...le?{dedupeKey:`desktop:${le}`}:{}}),dt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Qe};let Ut=null;const ks=async ss=>{const Ps=await _x(ss);switch(Ps.kind){case"success":return Ps.token;case"rejected":Ut=t("desktopHostSwitcher.error.pairingRejected");break;case"http-error":Ut??=t("desktopHostSwitcher.error.pairingFailed",{status:Ps.status});break;case"invalid-response":Ut??=t("desktopHostSwitcher.error.pairingInvalidResponse");break}return null},an=[...F.candidates].sort((ss,Ps)=>(ss.type==="relay"?1:0)-(Ps.type==="relay"?1:0));let bs=null;for(const ss of an){if(ss.type==="relay"){const Ra=$m({relayUrl:ss.relayUrl,serverId:ss.serverId,hostEncPubJwk:ss.hostEncPubJwk,...ss.grant?{grant:ss.grant}:{}});try{const Oa=await Ra.fetch("/api/client-auth/pairing/redeem",{...dt,signal:AbortSignal.timeout(15e3)}),La=await ks(Oa);if(La){bs={kind:"relay",relay:{relayUrl:ss.relayUrl,serverId:ss.serverId,hostEncPubJwk:ss.hostEncPubJwk},token:La};break}}catch{}finally{Ra.close()}continue}const Ps=$a(ss.url);if(Ps)try{const Ra=await fetch(`${Ps}/api/client-auth/pairing/redeem`,{...dt,signal:AbortSignal.timeout(15e3)}),Oa=await ks(Ra);if(Oa){bs={kind:"direct",url:Ps,token:Oa};break}}catch{}}if(!bs){Le(Ut||t("mobile.connect.error.unreachable"));return}const qs=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Rn=F.candidates.find(ss=>ss.type==="relay"),wn=bs.kind==="relay"?bs.relay:Rn?{relayUrl:Rn.relayUrl,serverId:Rn.serverId,hostEncPubJwk:Rn.hostEncPubJwk}:void 0,Da=F.candidates.filter(ss=>ss.type!=="relay").map(ss=>$a(ss.url)).find(ss=>!!ss),Ma=bs.kind==="direct"?bs.url:Da,{token:Bt}=bs,ts=Ma||(wn?Bm(wn.serverId):null);if(!ts){Le(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const Sn={url:ts,apiUrl:Ma||void 0,clientToken:Bt,...wn?{relay:wn}:{}},mn=ke.find(ss=>wn?ss.relay?.serverId===wn.serverId:!ss.relay&&$a(ss.apiUrl||ss.url)===ts);if(mn){const ss=ke.map(Ps=>Ps.id===mn.id?{...Ps,label:F.label||Ps.label,...Sn}:Ps);if(!await is(ss,ee))return}else if(!await is([{id:qs(),label:F.label||ai(ts),...Sn},...ke],ee))return;Ee(""),Le(null),pt(!1)},[ge,ee,ke,is,t]),jo=l.useCallback(async F=>{const le=ke.filter(dt=>dt.id!==F);await is(le,ee===F?"local":ee)&&yt===F&&st(null)},[ee,yt,ke,is]),ko=l.useCallback(F=>{st(F.id),de(F.label),et(F.apiUrl||F.url),Ze(F.clientToken||""),lt(tb(F.requestHeaders)),Le(null)},[]),Ci=l.useCallback(async()=>{if(!yt)return;const F=Il(Ue);if(!F){Le(t("desktopHostSwitcher.error.invalidUrl"));return}const le=F.persistedUrl,Qe=ke.map(dt=>dt.id===yt?{...dt,label:rt.trim()||ai(le),url:le,apiUrl:le,clientToken:ze.trim()||void 0,requestHeaders:Qo(tt)}:dt);await is(Qe,ee)&&(st(null),F.redeemUrl&&qi(F.redeemUrl))},[ee,tt,rt,ze,Ue,yt,ke,is,t]),wo=l.useCallback(async()=>{const F=Hs.trim();if(!F){U.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const le=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await C(le,F,Lt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),w(le),Bs(!1),Dn(""),Xt(""),U.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Qe){U.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Qe instanceof Error?Qe.message:String(Qe)})}},[C,w,Hs,Lt,t]),Ii=l.useCallback(()=>{nn(""),cn(r.length>0?"saved":"manual"),Bs(!0)},[r.length]),So=l.useCallback(async F=>{await is(ke,F)},[ke,is]);l.useEffect(()=>{if(!n||ke.length===0)return;let F=!1;return Promise.all(ke.map(async le=>{const Qe=()=>Jm(le.relay,{clientToken:le.clientToken||null,requestHeaders:le.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(le.relay&&!le.apiUrl)return[le.id,await Qe()];const dt=$a(Vm(le));if(!dt)return[le.id,le.relay?await Qe():{status:"unreachable",latencyMs:0}];const Ut=await Hm(dt,{clientToken:le.clientToken||null,requestHeaders:le.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Ut.status==="unreachable"&&le.relay){const ks=await Qe();if(ks.status==="ok")return[le.id,ks]}return[le.id,Ut]})).then(le=>{F||oe(Object.fromEntries(le))}),()=>{F=!0}},[ke,n]);const Ws=l.useCallback(async F=>{if(a){F?.silent||bt(!0),F?.silent||$e(null);try{const[le,Qe]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);nt(le),Qe&&it(Qe)}catch(le){F?.silent||$e(le instanceof Error?le.message:String(le))}finally{F?.silent||bt(!1)}}},[a]),si=l.useRef(!1);l.useEffect(()=>{if(!(!Je||We!=="result"||!Fe)){if(ot.some(F=>F.id===Fe)){si.current=!0;return}si.current&&(J(null),se(!1),Q.some(F=>F.pairingId===Fe)&&U.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Je,We,Fe,ot,Q,t]);const Pi=l.useCallback(async F=>{if(a)try{await a.cancelPairing(F),it(le=>le.filter(Qe=>Qe.id!==F)),await Ws({silent:!0})}catch(le){$e(le instanceof Error?le.message:String(le))}},[a,Ws]);l.useEffect(()=>{if(!a)return;Ws();const F=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ws({silent:!0})},5e3);return()=>window.clearInterval(F)},[a,Ws]);const Ai=l.useCallback(async()=>{if(a?.getPairingTransports)try{const dt=await a.getPairingTransports();return{localUrl:dt.local,lanUrl:dt.lan,relayAvailable:dt.relayAvailable}}catch{}const F=zd(),le=F?`http://127.0.0.1:${F}`:dc(window.location.origin)?window.location.origin:null;let Qe=null;try{const dt=$a(await sb());Qe=dt&&!dc(dt)?dt:null}catch{}return{localUrl:le,lanUrl:Qe,relayAvailable:!0}},[a]),No=l.useCallback(async()=>{$e(null),mt(null),Ae(null),Pe(!1),J(null),ut("configure"),Zt(!0),se(!0);const F=await Ai();ps(F),Ot(F.relayAvailable?"relay":F.lanUrl?"lan":"local")},[Ai]),Co=l.useCallback(async()=>{if(!(!a?.createPairingSession||!Ft)){$e(null),qe(!0);try{const F=ht.trim()||void 0;let le,Qe,dt=!0;jt==="local"?(le=Ft.localUrl??void 0,Qe=!1):jt==="lan"?(le=Ft.lanUrl??void 0,Qe=Yt):Yt&&Ft.lanUrl?(le=Ft.lanUrl,Qe=!0):(dt=!1,Qe=!0);const{pairing:Ut,server:ks}=await a.createPairingSession({label:F,allowedClientKinds:["mobile","desktop"],serverUrl:le,includeRelay:Qe,includeDirect:dt}),an=qm({pairingId:Ut.id,secret:Ut.secret,label:ks.label,fingerprint:Ut.fingerprint??void 0,expiresAt:Ut.expiresAt,candidates:ks.candidates}),bs=Gm(an);mt(bs),Ae(await Sd.toDataURL(bs,{width:1024,margin:2,errorCorrectionLevel:"L"})),Pe(!1),si.current=!1,J(Ut.id),ut("result"),await Ws({silent:!0})}catch(F){$e(F instanceof Error?F.message:String(F))}finally{qe(!1)}}},[a,Ft,jt,Yt,ht,Ws]),Ti=l.useCallback(()=>{Xe&&Va(Xe).then(F=>{F.ok&&(Pe(!0),window.setTimeout(()=>Pe(!1),2e3))})},[Xe]),Io=l.useCallback(async F=>{if(!a)return;const le=F.clientKind==="desktop-local";$e(null);try{if(await a.revokeClient(F.id),le&&us()){const Qe=await Nl();await Cl({hosts:Qe.hosts,defaultHostId:Qe.defaultHostId,initialHostChoiceCompleted:Qe.initialHostChoiceCompleted,localClientToken:null}),nt(dt=>dt.map(Ut=>Ut.id===F.id?{...Ut,revokedAt:new Date().toISOString()}:Ut)),Wm({apiBaseUrl:ki(),clientToken:null,runtimeKey:"local"});return}await Ws()}catch(Qe){$e(Qe instanceof Error?Qe.message:String(Qe))}},[a,Ws]),Po=l.useCallback(async()=>{if(a){$e(null);try{await a.purgeRevokedClients(),await Ws()}catch(F){$e(F instanceof Error?F.message:String(F))}}},[a,Ws]);l.useEffect(()=>{M(x)},[x]),l.useEffect(()=>{Mt(!1)},[N]),l.useEffect(()=>{if(!N)return;const F=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||m()},2e3);return()=>{window.clearInterval(F)}},[m,N]),l.useEffect(()=>{let F=null,le=Date.now();const Qe=()=>{const Ut=Date.now();Ut-le>=1e3&&(fe(Ut),le=Ut),F=requestAnimationFrame(Qe)};(typeof document>"u"||document.visibilityState==="visible")&&(F=requestAnimationFrame(Qe));const dt=()=>{document.visibilityState==="visible"&&F===null?F=requestAnimationFrame(Qe):document.visibilityState!=="visible"&&F!==null&&(cancelAnimationFrame(F),F=null)};return document.addEventListener("visibilitychange",dt),()=>{document.removeEventListener("visibilitychange",dt),F!==null&&cancelAnimationFrame(F)}},[]);const Ss=N?o[N]:null,dn=Ss?.phase,ka=dn==="ready",Mn=dn==="degraded",Qn=nl(dn),un=ka||(Qn||Mn),Ao=Ss?Math.max(0,je-Ss.updatedAtMs):0,wa=Mn&&Ao>12e3,Sa=ic(dn),aa=Sa==="error"?qx(Ss?.detail):null,ni=Gx(aa),To=l.useMemo(()=>!E||!x?!1:JSON.stringify(E)!==JSON.stringify(x),[E,x]),fs=l.useCallback(F=>{M(le=>le&&F(le))},[]),Eo=l.useCallback(async()=>{if(!E)return;const F=nb(E);if(!F.sshCommand.trim()){U.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(F.remoteOpenchamber.mode==="external"&&!F.remoteOpenchamber.preferredPort){U.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Mt(!0);return}if(F.remoteOpenchamber.mode==="managed"&&F.remoteOpenchamber.bindHost==="0.0.0.0"&&!F.auth.openchamberPassword?.value?.trim()){U.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Mt(!0),window.setTimeout(()=>Ia.current?.focus(),0);return}if(!(F.localForward.bindHost==="0.0.0.0"&&!await S("settings.remoteInstances.page.confirm.bindAllInterfaces"))){if(F.auth.sshPassword?.enabled&&F.auth.sshPassword.value?.trim()&&F.auth.sshPassword.store!=="settings"){const le=await S("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext");if(le===null)return;F.auth.sshPassword.store=le?"settings":"never",le||(F.auth.sshPassword.value=void 0)}if(F.auth.openchamberPassword?.enabled&&F.auth.openchamberPassword.value?.trim()&&F.auth.openchamberPassword.store!=="settings"){const le=await S("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext");if(le===null)return;F.auth.openchamberPassword.store=le?"settings":"never",le||(F.auth.openchamberPassword.value=void 0)}try{await v(F),U.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(le){U.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:le instanceof Error?le.message:String(le)})}}},[S,E,t,v]),Na=l.useCallback(async(F,le)=>{const Qe=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await C(Qe,`ssh ${le}`,F),w(Qe),U.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(dt){return U.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:dt instanceof Error?dt.message:String(dt)}),!1}},[C,w,t]),Ca=l.useCallback(()=>{z||(G(null),q(""))},[z]),Do=l.useCallback((F,le)=>{if(Bs(!1),le){G(F),q(Qx(F));return}Na(F,F)},[Na]),Ei=l.useMemo(()=>sa(r,sn,F=>[F.host,F.sshCommand]),[r,sn]),Mo=l.useCallback(F=>{const le=(F||"").trim();if(!le){U.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}qi(le)},[t]),Yn=l.useCallback(async()=>{const F=H,le=W.trim();if(F){if(!le){U.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}$(!0);try{await Na(F,le)&&(G(null),q(""))}finally{$(!1)}}},[Na,W,H,t]),jn=l.useCallback(async()=>{if(x)try{await k(x.id);return}catch(F){if(!Bx(F)||!await S("settings.remoteInstances.sidebar.confirm.localPortInUseRetry","settings.remoteInstances.sidebar.actions.retry"))throw F;const Qe={...x,localForward:{...x.localForward,preferredLocalPort:Xi()}};await v(Qe),await k(Qe.id),U.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[S,k,x,t,v]),Ia=l.useRef(null),Di=l.useRef(null),Pa=l.useCallback(async F=>{if(x){if(F==="localPort"){const le={...x,localForward:{...x.localForward,preferredLocalPort:Xi()}};try{await v(le),await k(le.id),U.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Qe){U.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Qe instanceof Error?Qe.message:String(Qe)})}return}Mt(!0),window.setTimeout(()=>{if(F==="uiPassword"){Ia.current?.focus();return}Di.current?.scrollIntoView({block:"center"})},0)}},[k,x,t,v]),Aa=l.useCallback(async F=>(await Lu(F,600)).map(Qe=>Xx(Qe)),[]),Ro=l.useCallback(async()=>{if(E){D(!0),O(!0),y(null);try{const F=await Aa(E.id);K(F)}catch(F){K([]),y(F instanceof Error?F.message:String(F))}finally{O(!1)}}},[E,Aa]);l.useEffect(()=>{if(!T||!E)return;let F=!1;const le=async()=>{try{const dt=await Aa(E.id);F||(K(dt),y(null))}catch(dt){F||y(dt instanceof Error?dt.message:String(dt))}};le();const Qe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||le()},1e3);return()=>{F=!0,window.clearInterval(Qe)}},[E,T,Aa]);const we=l.useMemo(()=>L.join(`
28
+ `),[L]),Ns=l.useCallback(()=>{if(!we.trim()){U.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Va(we).then(F=>{F.ok&&U.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[we,t]),Ta=l.useCallback(async()=>{if(E)try{await Fu(E.id),K([]),U.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(F){U.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:F instanceof Error?F.message:String(F)})}},[E,t]),Mi=l.useCallback(async()=>{if(!Ss?.localUrl){U.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const F=Ss.localUrl.trim();if(!F){U.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}qi(F)},[Ss?.localUrl,t]),Ri=l.useCallback(()=>{if(!E)return;if(!un&&E.remoteOpenchamber.mode==="external"&&!E.remoteOpenchamber.preferredPort){U.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Mt(!0);return}if(!un&&E.remoteOpenchamber.mode==="managed"&&E.remoteOpenchamber.bindHost==="0.0.0.0"&&!E.auth.openchamberPassword?.value?.trim()){U.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Mt(!0),window.setTimeout(()=>Ia.current?.focus(),0);return}X(!0),(un?u(E.id):jn()).catch(le=>{const Qe=un?ka?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";U.error(t(Qe),{description:le instanceof Error?le.message:String(le)})}).finally(()=>{X(!1)})},[un,jn,u,E,ka,t]),Oi=l.useCallback(()=>{if(!E||Qn)return;he(!0),(Mn?u(E.id).then(()=>jn()):j(E.id)).catch(le=>{U.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:le instanceof Error?le.message:String(le)})}).finally(()=>{he(!1)})},[jn,u,E,Qn,Mn,j,t]),Li=t(Qn?"settings.remoteInstances.page.actions.connecting":Mn?wa?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Fi=!ne&&!te&&(dn==="error"||dn==="idle"||!dn||Mn&&wa)&&!Qn,Oo=t(ka?"settings.remoteInstances.sidebar.actions.disconnect":un?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!E)return s.jsxs(ns,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(He,{title:t("settings.remoteInstances.clientAuth.title"),info:t("settings.remoteInstances.clientAuth.description"),divider:!1,settingsItem:"remote-instances.client-auth",contentClassName:"space-y-3",children:[s.jsx("div",{children:s.jsxs(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{No()},children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[gs>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Po()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,ft&&Q.length===0&&ot.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):Q.length===0&&ot.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[ot.map(F=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:F.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),F.usesRelay?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:t("settings.remoteInstances.clientAuth.state.pending")})]}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Pi(F.id)},children:t("settings.common.actions.cancel")})]},`pending-${F.id}`)),Q.map(F=>{const le=F.clientKind==="desktop-local",Qe=F.lastUsedAt?Date.parse(F.lastUsedAt):Number.NaN,dt=!F.revokedAt&&(le||Number.isFinite(Qe)&&Date.now()-Qe<9e4),Ut=F.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):dt?F.lastTransport==="relay"&&!le?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Qe)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Ku(Qe,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:Se("h-2 w-2 shrink-0 rounded-full",F.revokedAt?"bg-muted-foreground/20":dt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:F.label}),nc(F.devicePlatform)?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:nc(F.devicePlatform)}):null,le?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:Se("typography-micro truncate",dt&&!F.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Ut})]})}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Io(F)},disabled:!!F.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},F.id)})]})]}),At?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:At}):null]}):null,n?s.jsxs(He,{title:t("settings.remoteInstances.direct.title"),info:t("settings.remoteInstances.direct.description"),settingsItem:"remote-instances.direct-hosts",contentClassName:"space-y-4",headerAction:s.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s.jsx(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Le(null),pt(!0)},disabled:ve,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Le(null),Ve(!0)},disabled:ve,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:ue?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):ke.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):ke.map(F=>{const le=De[F.id],Qe=le?le.status==="ok"?"desktopHostSwitcher.status.connected":le.status==="auth"?"desktopHostSwitcher.status.authRequired":le.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":le.status==="incompatible"?"desktopHostSwitcher.status.incompatible":le.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",dt=le?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Se("h-2 w-2 shrink-0 rounded-full",le?dt?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:ai(F.label)}),ee===F.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:Se("typography-micro shrink-0",dt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Qe),dt&&typeof le?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(le.latencyMs))}):""]})]}),s.jsx("p",{className:Se("typography-micro text-muted-foreground truncate",F.apiUrl&&"font-mono"),children:F.relay&&!F.apiUrl?t("mobile.connect.relay.badge"):ai(F.apiUrl||F.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{So(F.id)},disabled:ve||ee===F.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ee===F.id?s.jsx(B,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"star",className:"h-3.5 w-3.5"})}),F.relay&&!F.apiUrl?null:s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ko(F),disabled:ve,children:[s.jsx(B,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{jo(F.id)},disabled:ve,children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},F.id)})}),Ke&&!Ye&&!Ne&&!yt?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ke}):null]}):null,n?s.jsx(_t,{open:Ne,onOpenChange:Ve,children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),vo()},children:[s.jsx(Ge,{className:"h-8",value:Me,onChange:F=>me(F.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ve}),s.jsx(Ge,{className:"h-8",value:Te,onChange:F=>Oe(F.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ve,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Ge,{className:"h-8",value:pe,onChange:F=>xe(F.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ve}),s.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:t("settings.remoteInstances.direct.note")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(An,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Gt,{children:t("settings.remoteInstances.direct.headers.description")})]}),ae.map(F=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Ge,{className:"h-8 font-mono text-xs",value:F.name,onChange:le=>ie(Qe=>Qe.map(dt=>dt.id===F.id?{...dt,name:le.target.value}:dt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ve}),s.jsx(Ge,{className:"h-8 font-mono text-xs",value:F.value,onChange:le=>ie(Qe=>Qe.map(dt=>dt.id===F.id?{...dt,value:le.target.value}:dt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ve}),s.jsx("button",{type:"button",onClick:()=>ie(le=>le.filter(Qe=>Qe.id!==F.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:ve,children:s.jsx(B,{name:"close",className:"h-4 w-4"})})]},F.id)),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ie(F=>[...F,Ir()]),disabled:ve,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ve(!1),disabled:ve,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:ve||!Te.trim(),children:t("settings.remoteInstances.direct.actions.add")})]}),Ke?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:Ke}):null]})]})}):null,n?s.jsx(_t,{open:!!yt,onOpenChange:F=>{F||st(null)},children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),Ci()},children:[s.jsx(Ge,{className:"h-8",value:rt,onChange:F=>de(F.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:ve}),s.jsx(Ge,{className:"h-8",value:Ue,onChange:F=>et(F.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:ve,autoFocus:!0}),s.jsx(Ge,{className:"h-8",value:ze,onChange:F=>Ze(F.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:ve}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(An,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Gt,{children:t("settings.remoteInstances.direct.headers.description")})]}),tt.map(F=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Ge,{className:"h-8 font-mono text-xs",value:F.name,onChange:le=>lt(Qe=>Qe.map(dt=>dt.id===F.id?{...dt,name:le.target.value}:dt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:ve}),s.jsx(Ge,{className:"h-8 font-mono text-xs",value:F.value,onChange:le=>lt(Qe=>Qe.map(dt=>dt.id===F.id?{...dt,value:le.target.value}:dt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:ve}),s.jsx("button",{type:"button",onClick:()=>lt(le=>le.filter(Qe=>Qe.id!==F.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:ve,children:s.jsx(B,{name:"close",className:"h-4 w-4"})})]},F.id)),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>lt(F=>[...F,Ir()]),disabled:ve,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>st(null),disabled:ve,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:ve,children:t("settings.common.actions.saveChanges")})]}),Ke?s.jsx("p",{role:"alert",className:"typography-meta text-[var(--status-error)]",children:Ke}):null]})]})}):null,n?s.jsx(_t,{open:Ye,onOpenChange:F=>{vt||pt(F)},children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(qt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3","aria-busy":vt,onSubmit:async F=>{if(F.preventDefault(),!(vt||ve)){wt(!0);try{await yo()}catch{Le(t("mobile.connect.error.unreachable"))}finally{wt(!1)}}},children:[s.jsx(Ge,{className:"h-8",value:ge,onChange:F=>{Ee(F.target.value),Le(null)},placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:ve||vt,"aria-describedby":Ke?"direct-import-error":void 0,autoFocus:!0}),Ke?s.jsx("p",{id:"direct-import-error",role:"alert",className:"typography-meta text-[var(--status-error)]",children:Ke}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>pt(!1),disabled:ve||vt,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:ve||vt||!ge.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(_t,{open:Je,onOpenChange:se,children:s.jsxs($t,{className:We==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t(We==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(qt,{children:t(We==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),We==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:F=>{F.preventDefault(),Co()},children:[s.jsx(Ge,{className:"h-8",value:ht,onChange:F=>Nt(F.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!Ft?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Ft?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Ft?.localUrl}].map(F=>{const le=jt===F.key;return s.jsxs("div",{className:Se("flex items-start gap-2 py-0.5",F.available?"cursor-pointer":"opacity-45"),onClick:()=>{F.available&&Ot(F.key)},role:"presentation",children:[s.jsx(Kr,{checked:le,disabled:!F.available,onChange:()=>Ot(F.key),ariaLabel:F.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:Se("typography-ui-label font-normal",le?"text-foreground":"text-foreground/70"),children:F.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:F.hint})]})]},F.key)})}),jt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(gr,{checked:Yt,onChange:Zt,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,jt==="relay"&&Ft?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(gr,{checked:Yt,onChange:Zt,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),At?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:At}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>se(!1),disabled:Ce,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:Ce||!Ft,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[ye?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:ye,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,Xe?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[s.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:Xe}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ti,children:[s.jsx(B,{name:Y?"check":"file-copy",className:Se("h-3.5 w-3.5",Y&&"text-[var(--status-success)]")}),t(Y?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>se(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(He,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(V,{type:"button",size:"xs",className:"!font-normal",onClick:Ii,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:d?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:r.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):r.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:r.length}):t("settings.remoteInstances.page.empty.noInstances")}):i.map(F=>{const le=o[F.id],Qe=F.nickname?.trim()||F.sshParsed?.destination||F.id,dt=le?.phase,Ut=dt==="ready",ks=ic(dt),an=ks==="error"?le?.detail:void 0;return s.jsxs("div",{className:"space-y-1.5 py-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${lc(dt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Qe})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(oc(ks)),ks==="connecting"?` · ${t(ac(dt))}`:"",Ut&&le?.localUrl?` · ${le.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ut?s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Mo(le?.localUrl),children:[s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Ut?u(F.id):k(F.id)).catch(qs=>U.error(t(Ut?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:qs instanceof Error?qs.message:String(qs)}))},children:[Ut?s.jsx(B,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Ut?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>w(F.id),children:[s.jsx(B,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(F.id).catch(qs=>U.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:qs instanceof Error?qs.message:String(qs)}))},children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),an?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:an}):null]},F.id)})}):null,n?s.jsx(_t,{open:tn,onOpenChange:Bs,children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(qt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Xs,{value:Vs,onChange:cn,"aria-label":t("settings.remoteInstances.page.addDialog.sourceLabel"),options:[{value:"saved",label:t("settings.remoteInstances.page.addDialog.tab.saved")},{value:"manual",label:t("settings.remoteInstances.page.addDialog.tab.manual")}]}),Vs==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ge,{className:"h-8",value:sn,onChange:F=>nn(F.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):r.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):Ei.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.searchEmpty")}):s.jsx("div",{className:"max-h-[45vh] overflow-auto",children:Ei.map(F=>s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-2.5 last:border-b-0",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label font-medium text-foreground truncate",children:[F.host,F.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:F.sshCommand})]}),s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Do(F.host,F.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${F.source}:${F.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),wo()},children:[s.jsx(Ge,{className:"h-8",value:Lt,onChange:F=>Xt(F.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:g}),s.jsx(Ge,{className:"h-8",value:Hs,onChange:F=>Dn(F.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:g,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Bs(!1),disabled:g,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:g||!Hs.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(_t,{open:!!H,onOpenChange:F=>{F||Ca()},children:s.jsxs($t,{className:"sm:max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(qt,{children:H?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:H}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),Yn()},children:[s.jsx(Ge,{value:W,onChange:F=>q(F.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ca,disabled:z,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:z,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const kn=E.remoteOpenchamber.mode==="managed",Zn=kn&&E.remoteOpenchamber.bindHost==="0.0.0.0",Ea=Zn&&!E.auth.openchamberPassword?.value?.trim(),Lo=E.nickname?.trim()||E.sshParsed?.destination||E.id;return s.jsx(_t,{open:!!E,onOpenChange:F=>{F||w(null)},children:s.jsxs($t,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${mr} truncate`,children:Lo}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${lc(dn)}`}),s.jsx("span",{className:"text-foreground",children:t(oc(Sa))}),Sa==="connecting"?s.jsx("span",{children:t(ac(dn))}):null,Ss?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:Ss.localUrl}):null,wa?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(He,{title:t("settings.remoteInstances.page.section.actions"),info:t("settings.remoteInstances.page.section.actionsDescription"),divider:!1,contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(V,{type:"button",variant:un?"outline":"default",size:"xs",className:"!font-normal",onClick:Ri,disabled:ne||te,children:[un?s.jsx(B,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"plug-2",className:"h-3.5 w-3.5"}),Oo]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Oi,disabled:!Fi,children:[s.jsx(B,{name:"refresh",className:`h-3.5 w-3.5 ${Qn||Mn&&!wa?"animate-spin":""}`}),Li]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ro()},children:[s.jsx(B,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&b(E.id).then(()=>{w(null),U.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(le=>{U.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:le instanceof Error?le.message:String(le)})})},children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),Sa==="error"&&Ss?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:Ss.detail}),ni?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(ni)}):null,aa&&!ni?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Pa(aa)},children:t(aa==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":aa==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,Ss?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:Ss.localUrl})]}):null]}),s.jsxs(He,{title:t("settings.remoteInstances.page.section.instance"),info:t("settings.remoteInstances.page.section.instanceDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(Ge,{className:"h-7 md:max-w-xl",value:E.sshCommand,onChange:F=>fs(le=>({...le,sshCommand:F.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(Ge,{className:"h-7 md:max-w-sm",value:E.nickname||"",onChange:F=>fs(le=>({...le,nickname:F.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Dt,{value:E.remoteOpenchamber.mode,onValueChange:F=>fs(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,mode:F==="external"?"external":"managed"}})),children:[s.jsx(Tt,{size:Qt,className:"w-fit min-w-[140px]",children:s.jsx(Jt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Et,{children:[s.jsx(gt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(gt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(bn,{open:Wt,onOpenChange:Mt,children:[s.jsxs(vn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:ad,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(B,{name:Wt?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(yn,{children:[s.jsx("p",{className:"px-2 pb-2 typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.section.advancedHint")}),s.jsxs("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(js,{containerClassName:"w-fit",min:5,max:240,step:1,className:Se(ws,"tabular-nums"),value:E.connectionTimeoutSec,onValueChange:F=>{fs(le=>({...le,connectionTimeoutSec:Number.isFinite(F)?F:le.connectionTimeoutSec}))}})]}),s.jsxs(He,{title:t("settings.remoteInstances.page.section.remoteServer"),info:t("settings.remoteInstances.page.section.remoteServerDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",ref:Di,children:s.jsx(on,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(js,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Se(ws,"tabular-nums"),value:E.remoteOpenchamber.preferredPort,onValueChange:F=>{fs(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,preferredPort:Number.isFinite(F)&&F>0?F:void 0}}))},onClear:()=>{fs(F=>({...F,remoteOpenchamber:{...F.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),kn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Dt,{value:E.remoteOpenchamber.installMethod,onValueChange:F=>fs(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,installMethod:F==="npm"||F==="bun"?F:"auto"}})),children:[s.jsx(Tt,{size:Qt,className:"w-fit min-w-[140px]",children:s.jsx(Jt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Et,{children:[s.jsx(gt,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(gt,{value:"bun",children:"bun"}),s.jsx(gt,{value:"npm",children:"npm"})]})]})]}):null,kn?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(fa,{checked:Zn,onCheckedChange:F=>fs(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,bindHost:F?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),Zn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,kn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(fa,{checked:E.remoteOpenchamber.keepRunning,onCheckedChange:F=>fs(le=>({...le,remoteOpenchamber:{...le.remoteOpenchamber,keepRunning:F}}))})})]}):null]}),s.jsxs(He,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Dt,{value:E.localForward.bindHost,onValueChange:F=>{F==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||fs(le=>({...le,localForward:{...le.localForward,bindHost:F==="localhost"||F==="0.0.0.0"?F:"127.0.0.1"}}))},children:[s.jsx(Tt,{size:Qt,className:"w-fit min-w-[240px]",children:s.jsx(Jt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Et,{children:[s.jsx(gt,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(gt,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(gt,{value:"0.0.0.0",children:t("settings.remoteInstances.page.field.bindHostOption.lan")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(js,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Se(ws,"tabular-nums"),value:E.localForward.preferredLocalPort,onValueChange:F=>{fs(le=>({...le,localForward:{...le.localForward,preferredLocalPort:Number.isFinite(F)&&F>0?F:void 0}}))},onClear:()=>{fs(F=>({...F,localForward:{...F.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>fs(F=>({...F,localForward:{...F.localForward,preferredLocalPort:Xi()}})),children:s.jsx(B,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.tunnelPreview.caption")}),s.jsx("p",{className:"typography-micro font-mono text-foreground/80 break-all",children:`${E.localForward.bindHost}:${E.localForward.preferredLocalPort||"auto"} → ${E.sshParsed?.destination||E.nickname||"remote"}:${E.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(He,{title:t("settings.remoteInstances.page.section.authentication"),info:t("settings.remoteInstances.page.section.authenticationDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(Ge,{className:"h-7 md:max-w-sm",type:"password",value:E.auth.sshPassword?.value||"",onChange:F=>fs(le=>({...le,auth:{...le.auth,sshPassword:{enabled:F.target.value.trim().length>0,value:F.target.value,store:le.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t(Zn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(kn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(Ge,{className:Se("h-7 md:max-w-sm",Ea&&"border-[var(--status-error)]"),type:"password",ref:Ia,"aria-invalid":Ea,value:E.auth.openchamberPassword?.value||"",onChange:F=>fs(le=>({...le,auth:{...le.auth,openchamberPassword:{enabled:F.target.value.trim().length>0,value:F.target.value,store:le.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),Ea?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(He,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[E.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,E.portForwards.map((F,le)=>{const Qe=Bt=>{fs(ts=>({...ts,portForwards:ts.portForwards.map((Sn,mn)=>mn===le?Bt(Sn):Sn)}))},dt=F.type==="remote"?"Local target":"Local listen",Ut=F.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",ks=F.type==="remote"?"Remote listen":"Remote target",an=F.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",bs=cc(F.localHost||"localhost",F.localPort),qs=cc(F.remoteHost||"localhost",F.remotePort),Rn=F.type==="local"&&typeof F.localPort=="number"&&F.localPort>0,wn=Rn?`http://${Zx(F.localHost)}:${F.localPort}`:"",Da=!!Z[F.id],Ma=F.type==="local"?t("settings.remoteInstances.page.forwardType.local"):F.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(bn,{open:Da,onOpenChange:Bt=>{_(ts=>({...ts,[F.id]:Bt}))},className:`${le>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(vn,{className:"flex items-center gap-2 group",children:[s.jsx(B,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Da?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Wx(F)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Ma})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(fa,{checked:F.enabled,onCheckedChange:Bt=>Qe(ts=>({...ts,enabled:Bt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>fs(Bt=>({...Bt,portForwards:Bt.portForwards.filter(ts=>ts.id!==F.id)})),children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(yn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(Yx(F.type))})]})})}),s.jsxs(Dt,{value:F.type,onValueChange:Bt=>Qe(ts=>({...ts,type:Bt==="dynamic"||Bt==="remote"?Bt:"local"})),children:[s.jsx(Tt,{size:Qt,className:"w-fit min-w-[140px]",children:s.jsx(Jt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Et,{children:[s.jsx(gt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(gt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(gt,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:dt,hint:Ut})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ge,{className:"h-7 w-32",value:F.localHost||"127.0.0.1",onChange:Bt=>Qe(ts=>({...ts,localHost:Bt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(js,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Se(ws,"tabular-nums"),value:F.localPort,onValueChange:Bt=>{Qe(ts=>({...ts,localPort:Number.isFinite(Bt)&&Bt>0?Bt:void 0}))},onClear:()=>{Qe(Bt=>({...Bt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),F.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(on,{label:ks,hint:an})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ge,{className:"h-7 w-32",value:F.remoteHost||"",onChange:Bt=>Qe(ts=>({...ts,remoteHost:Bt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(js,{containerClassName:"w-fit",min:1,max:65535,step:1,className:Se(ws,"tabular-nums"),value:F.remotePort,onValueChange:Bt=>{Qe(ts=>({...ts,remotePort:Number.isFinite(Bt)&&Bt>0?Bt:void 0}))},onClear:()=>{Qe(Bt=>({...Bt,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:F.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:bs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):F.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:qs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(B,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(B,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:bs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:bs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(B,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(B,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:qs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Rn?s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_s(wn).then(Bt=>{Bt||U.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},F.id)}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const F=Jx();fs(le=>({...le,portForwards:[...le.portForwards,F]})),_(le=>({...le,[F.id]:!0}))},children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]})]})]}),s.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{Eo()},disabled:!To||g,children:t("settings.common.actions.saveChanges")}),Ss?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Va(Ss.localUrl||"").then(F=>{F.ok&&U.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(B,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Mi()},children:[s.jsx(B,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,p?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:p}):null]})}),A,s.jsx(_t,{open:T,onOpenChange:D,children:s.jsxs($t,{className:"sm:max-w-2xl",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(qt,{children:E?.nickname?.trim()||E?.sshParsed?.destination||E?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ns,disabled:R||!we.trim(),children:[s.jsx(B,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ta()},disabled:R,children:[s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),R?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):I?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:I}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:L.length>0?L.join(`
29
+ `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(_t,{open:!!H,onOpenChange:F=>{F||Ca()},children:s.jsxs($t,{className:"sm:max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(qt,{children:H?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:H}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:F=>{F.preventDefault(),Yn()},children:[s.jsx(Ge,{value:W,onChange:F=>q(F.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ca,disabled:z,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:z,children:t("settings.common.actions.create")})]})]})]})})]})})},ib=t=>t,ob=(t,e,a)=>t&&!e&&!a,rb=Rt(),Pr=t=>rb.safeParse(t?.settings?.apiKey).data??null,Kn=(t,e)=>t.find(a=>a.id===e),gi=t=>t==="opencode-go"?"opencode":t,eo=(t,e)=>{const a=Kn(t,e)?.connections,n=gi(e);if(n===e)return a;const i=Kn(t,n)?.connections;if(!(!a&&!i))return[...a??[],...i??[]]},uc=t=>(t?.methods??[]).filter(e=>e.type==="oauth"),lb=t=>(t?.methods??[]).find(e=>e.type==="key"),mc=t=>t===void 0||lb(t)!==void 0,pc=t=>(t?.connections??[]).filter(e=>e.type==="credential"),gc=t=>(t.connections?.length??0)>0?!0:typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0,al=t=>t.status?.status==="needs_auth",cb=t=>{if(t.integrations===null)return null;const e=eo(t.integrations,t.providerId);if((e??[]).some(al))return{kind:"reauthNeeded"};const a=(e??[]).filter(n=>n.type==="credential").length;return a>1?{kind:"accounts",count:a}:a===1||(t.optionsApiKey?.trim().length??0)>0?{kind:"connected"}:(e??[]).some(n=>n.type==="env")?{kind:"environment"}:e===void 0?null:{kind:"signInNeeded"}},db=t=>t.modelCount>0&&(!t.integrationsLoaded||t.hasCredentials||!!t.isEditableCustomProvider),ub=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,il=t=>{const e=_e.c(12),{t:a}=Be();if(t==="zen-promo"){let n;return e[0]!==a?(n=a("settings.classification.source.zenPromo.name"),e[0]=a,e[1]=n):n=e[1],n}if(t==="zen-key"){let n;return e[2]!==a?(n=a("settings.classification.source.zenKey.name"),e[2]=a,e[3]=n):n=e[3],n}if(t==="openrouter"){let n;return e[4]!==a?(n=a("settings.classification.source.openrouter.name"),e[4]=a,e[5]=n):n=e[5],n}if(t==="vercel"){let n;return e[6]!==a?(n=a("settings.classification.source.vercel.name"),e[6]=a,e[7]=n):n=e[7],n}if(t==="typesafe"){let n;return e[8]!==a?(n=a("settings.classification.source.typesafe.name"),e[8]=a,e[9]=n):n=e[9],n}if(t==="custom"){let n;return e[10]!==a?(n=a("settings.classification.source.custom.name"),e[10]=a,e[11]=n):n=e[11],n}return null},lo=()=>{const t=re.getState();t.setSettingsProvidersClassificationRequested(!0),t.requestSettingsJump("providers","providers.classification")},Vn=t=>{const e=_e.c(3),{onClick:a,children:n}=t;let i;return e[0]!==n||e[1]!==a?(i=s.jsx("button",{type:"button",onClick:a,className:"cursor-pointer text-[var(--primary-text)] underline-offset-4 hover:underline focus-visible:underline focus-visible:outline-none",children:n}),e[0]=n,e[1]=a,e[2]=i):i=e[2],i},xo=()=>{const t=_e.c(16),{t:e}=Be(),a=es(mb),n=es(pb),i=es(gb),o=il(i),r=ya();if(!a)return null;if(r&&!n){let h;t[0]!==e?(h=e("settings.jevAccess.enterprise"),t[0]=e,t[1]=h):h=t[1];let f;return t[2]!==h?(f=s.jsx("p",{className:ls,children:h}),t[2]=h,t[3]=f):f=t[3],f}let d;t[4]!==n||t[5]!==o||t[6]!==e?(d=n&&o?e("settings.jevAccess.via",{provider:o}):e("settings.jevAccess.missing"),t[4]=n,t[5]=o,t[6]=e,t[7]=d):d=t[7];let c;t[8]!==n||t[9]!==e?(c=e(n?"settings.jevAccess.manage":"settings.jevAccess.setUp"),t[8]=n,t[9]=e,t[10]=c):c=t[10];let g;t[11]!==c?(g=s.jsx(Vn,{onClick:lo,children:c}),t[11]=c,t[12]=g):g=t[12];let p;return t[13]!==d||t[14]!==g?(p=s.jsxs("p",{className:ls,children:[d," ",g]}),t[13]=d,t[14]=g,t[15]=p):p=t[15],p};function mb(t){return t.available}function pb(t){return t.jevAvailable}function gb(t){return t.classifier?.effective??null}const fb="https://opencode.ai/v2/docs/policies/",hb=t=>{const e=_e.c(3),[a,n]=l.useState(null);let i,o;return e[0]!==t?(i=()=>{let r=!1;return n(null),Ts.configDeniesAnyProvider(t).then(d=>{r||n(d)}).catch(d=>{console.warn("[providers] could not read OpenCode provider policies:",d instanceof Error?d.message:String(d)),r||n(null)}),()=>{r=!0}},o=[t],e[0]=t,e[1]=i,e[2]=o):(i=e[1],o=e[2]),l.useEffect(i,o),a},xb=t=>{const e=_e.c(44),{directory:a,integrations:n}=t,{t:i}=Be(),o=hb(a),r=hr(kb),d=hr(wb),c=n===null?null:(Kn(n,"opencode")?.connections?.length??0)>0,g=o!==!1||c===null?null:c?"console":"open",p=g==="open";let h;e[0]!==i?(h=i("settings.providers.enterprisePolicyLink"),e[0]=i,e[1]=h):h=e[1];let f;e[2]!==h?(f=s.jsx(Vn,{onClick:Sb,children:h}),e[2]=h,e[3]=f):f=e[3];const m=f,v=p?"border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5":"border-[var(--status-info-border)] bg-[var(--status-info-background)]/30";let C;e[4]!==v?(C=Se("mb-4 flex items-start gap-2 rounded-lg border p-3",v),e[4]=v,e[5]=C):C=e[5];const b=p?"error-warning":"information",k=p?"text-[var(--status-warning)]":"text-[var(--status-info)]";let u;e[6]!==k?(u=Se("mt-0.5 size-4 shrink-0",k),e[6]=k,e[7]=u):u=e[7];let j;e[8]!==b||e[9]!==u?(j=s.jsx(B,{name:b,className:u}),e[8]=b,e[9]=u,e[10]=j):j=e[10];let N;e[11]!==i?(N=i("settings.providers.enterpriseTitle"),e[11]=i,e[12]=N):N=e[12];let w;e[13]!==N?(w=s.jsx("p",{className:fr,children:N}),e[13]=N,e[14]=w):w=e[14];let S;e[15]!==r||e[16]!==i?(S=r?s.jsx("p",{className:"typography-meta text-foreground",children:i("settings.providers.enterpriseManagedBy",{organization:r})}):null,e[15]=r,e[16]=i,e[17]=S):S=e[17];let A;e[18]!==d||e[19]!==i?(A=d?s.jsx("p",{className:"typography-meta text-foreground",children:i("settings.providers.enterprisePolicyUnreadable")}):null,e[18]=d,e[19]=i,e[20]=A):A=e[20];let x;e[21]!==i?(x=i("settings.providers.enterpriseMode"),e[21]=i,e[22]=x):x=e[22];let E;e[23]!==x?(E=s.jsx("p",{className:"typography-meta text-muted-foreground",children:x}),e[23]=x,e[24]=E):E=e[24];let M;e[25]!==g||e[26]!==m||e[27]!==i?(M=g==="open"?s.jsxs("p",{className:"typography-meta text-foreground",children:[i("settings.providers.enterprisePolicyMissing")," ",m]}):null,e[25]=g,e[26]=m,e[27]=i,e[28]=M):M=e[28];let T;e[29]!==g||e[30]!==m||e[31]!==i?(T=g==="console"?s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[i("settings.providers.enterprisePolicyConsole")," ",m]}):null,e[29]=g,e[30]=m,e[31]=i,e[32]=T):T=e[32];let D;e[33]!==w||e[34]!==S||e[35]!==A||e[36]!==E||e[37]!==M||e[38]!==T?(D=s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[w,S,A,E,M,T]}),e[33]=w,e[34]=S,e[35]=A,e[36]=E,e[37]=M,e[38]=T,e[39]=D):D=e[39];let R;return e[40]!==D||e[41]!==C||e[42]!==j?(R=s.jsxs("div",{className:C,children:[j,D]}),e[40]=D,e[41]=C,e[42]=j,e[43]=R):R=e[43],R},bb=t=>{const e=_e.c(19),{onOpen:a}=t,{t:n}=Be(),i=es(Nb),o=es(Cb),r=es(Ib);if(!i)return null;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx($n,{providerId:"typesafe",className:"size-5"}),e[0]=d):d=e[0];let c;e[1]!==n?(c=n("settings.classification.page.title"),e[1]=n,e[2]=c):c=e[2];const g=o?"success":r?"neutral":"warning";let p;e[3]!==o||e[4]!==r||e[5]!==n?(p=n(o?"settings.classification.card.ready":r?"settings.classification.card.off":"settings.classification.card.notSetUp"),e[3]=o,e[4]=r,e[5]=n,e[6]=p):p=e[6];let h;e[7]!==g||e[8]!==p?(h=s.jsx(In,{tone:g,children:p}),e[7]=g,e[8]=p,e[9]=h):h=e[9];let f;e[10]!==n?(f=n("settings.classification.card.usedFor"),e[10]=n,e[11]=f):f=e[11];let m;e[12]!==f?(m=s.jsx("span",{className:"min-w-0 truncate",children:f}),e[12]=f,e[13]=m):m=e[13];let v;return e[14]!==a||e[15]!==c||e[16]!==h||e[17]!==m?(v=s.jsx(ji,{icon:d,title:c,subtitle:"jev",badges:h,footer:m,onOpen:a}),e[14]=a,e[15]=c,e[16]=h,e[17]=m,e[18]=v):v=e[18],v},vb=(t,e)=>{const[a,n]=l.useState(()=>new Set);return l.useEffect(()=>{let i=!1;const o=e?`?directory=${encodeURIComponent(e)}`:"";return Promise.all(t.map(async r=>{try{const d=await It(`/api/provider/${encodeURIComponent(r.id)}/source${o}`,{method:"GET",headers:{Accept:"application/json"}});if(!d.ok)return null;const c=await d.json().catch(()=>null);return(c?.sources??c?.data?.sources)?.project?.exists===!0?r.id:null}catch{return null}})).then(r=>{i||n(new Set(r.filter(d=>d!==null)))}),()=>{i=!0}},[e,t]),a},yb=t=>{const e=_e.c(14),{status:a}=t,{t:n}=Be();let i;e:switch(a.kind){case"reauthNeeded":{let d;e[0]!==n?(d=n("settings.providers.card.status.reauthNeeded"),e[0]=n,e[1]=d):d=e[1],i=d;break e}case"accounts":{let d;e[2]!==a.count||e[3]!==n?(d=n("settings.providers.card.status.accounts",{count:a.count}),e[2]=a.count,e[3]=n,e[4]=d):d=e[4],i=d;break e}case"connected":{let d;e[5]!==n?(d=n("settings.providers.card.status.connected"),e[5]=n,e[6]=d):d=e[6],i=d;break e}case"environment":{let d;e[7]!==n?(d=n("settings.providers.card.status.environment"),e[7]=n,e[8]=d):d=e[8],i=d;break e}case"signInNeeded":{let d;e[9]!==n?(d=n("settings.providers.card.status.signInNeeded"),e[9]=n,e[10]=d):d=e[10],i=d}}const o=a.kind==="signInNeeded"||a.kind==="reauthNeeded"?"warning":a.kind==="environment"?"neutral":"success";let r;return e[11]!==i||e[12]!==o?(r=s.jsx(In,{tone:o,children:i}),e[11]=i,e[12]=o,e[13]=r):r=e[13],r},jb=t=>{const e=_e.c(42),{providers:a,integrations:n,directory:i,onSelect:o,onConnect:r,onOpenClassification:d}=t,{t:c}=Be(),[g,p]=l.useState(""),h=vb(a,i),f=sa([...a],g,Pb);let m;e[0]!==g?(m=g.trim(),e[0]=g,e[1]=m):m=e[1];const v=m.length>0,C=ya(),b=ns;let k;e[2]!==c?(k=c("settings.page.providers.title"),e[2]=c,e[3]=k):k=e[3];let u;e[4]!==c?(u=c("settings.providers.grid.description"),e[4]=c,e[5]=u):u=e[5];let j;e[6]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Si,{className:"w-full min-w-0 @xl:w-56"}),e[6]=j):j=e[6];let N;e[7]!==i||e[8]!==n||e[9]!==C?(N=C?s.jsx(xb,{directory:i,integrations:n}):null,e[7]=i,e[8]=n,e[9]=C,e[10]=N):N=e[10];let w;e[11]!==a.length||e[12]!==g||e[13]!==c?(w=a.length>0?s.jsx(el,{value:g,onChange:p,placeholder:c("settings.providers.grid.searchPlaceholder")}):null,e[11]=a.length,e[12]=g,e[13]=c,e[14]=w):w=e[14];const S=a.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:c("settings.providers.grid.empty")}):f.length===0?s.jsx("p",{className:"py-6 typography-meta text-muted-foreground",children:c("settings.providers.grid.noMatches",{query:g.trim()})}):null,A=Zr;let x;e[15]!==v||e[16]!==C||e[17]!==r||e[18]!==c?(x=v||C?null:s.jsx(Xr,{label:c("settings.providers.grid.connect"),hint:c("settings.providers.grid.connectHint"),onClick:r}),e[15]=v,e[16]=C,e[17]=r,e[18]=c,e[19]=x):x=e[19];let E;e[20]!==v||e[21]!==d?(E=v?null:s.jsx(bb,{onOpen:d}),e[20]=v,e[21]=d,e[22]=E):E=e[22];let M;e[23]!==n||e[24]!==o||e[25]!==h||e[26]!==c?(M=O=>{const I=cb({integrations:n,providerId:O.id,optionsApiKey:Pr(O)});return s.jsx(ji,{icon:s.jsx($n,{providerId:O.id,className:"size-5"}),title:O.name||O.id,subtitle:O.id,badges:I?s.jsx(yb,{status:I}):null,footer:s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"inline-flex items-center gap-1","aria-label":c("settings.providers.card.models",{count:O.models.length}),children:[s.jsx(B,{name:"stack",className:"size-3.5 opacity-70","aria-hidden":!0}),s.jsx("span",{className:"tabular-nums",children:O.models.length})]}),h.has(O.id)?s.jsx(io,{children:c("settings.providers.card.source.project")}):null]}),onOpen:()=>o(O.id)},O.id)},e[23]=n,e[24]=o,e[25]=h,e[26]=c,e[27]=M):M=e[27];const T=f.map(M);let D;e[28]!==E||e[29]!==T||e[30]!==A||e[31]!==x?(D=s.jsxs("div",{className:A,children:[x,E,T]}),e[28]=E,e[29]=T,e[30]=A,e[31]=x,e[32]=D):D=e[32];let R;return e[33]!==b||e[34]!==D||e[35]!==k||e[36]!==u||e[37]!==j||e[38]!==N||e[39]!==w||e[40]!==S?(R=s.jsxs(b,{title:k,description:u,headerEnd:j,children:[N,w,S,D]}),e[33]=b,e[34]=D,e[35]=k,e[36]=u,e[37]=j,e[38]=N,e[39]=w,e[40]=S,e[41]=R):R=e[41],R};function kb(t){return t.organization}function wb(t){return t.policyError!==null}function Sb(){_s(fb)}function Nb(t){return t.available}function Cb(t){return t.jevAvailable}function Ib(t){return t.classifier?.selected==="off"}function Pb(t){return[t.name||t.id,t.id]}const Yo="flex w-full min-w-0 items-center gap-2",Zo="h-8 rounded-md px-3 min-w-0 flex-1",Ab=()=>{const{t}=Be(),e=es(u=>u.customEndpoint),a=es(u=>u.setCustomEndpoint),n=es(u=>u.clearCustomEndpoint),[i,o]=l.useState(e?.url??""),[r,d]=l.useState(e?.model??""),[c,g]=l.useState(""),[p,h]=l.useState(!1),[f,m]=l.useState(null);l.useEffect(()=>{o(e?.url??""),d(e?.model??"")},[e?.url,e?.model]);const v=async u=>{h(!0),m(null);try{await u(),g("")}catch(j){m(j instanceof Error?j.message:String(j))}finally{h(!1)}},C=i.trim().length>0&&r.trim().length>0,b=()=>{if(!C)return;const u={url:i.trim(),model:r.trim()},j=c.trim();j&&(u.key=j),v(()=>a(u))},k=u=>{u.key==="Enter"&&b()};return e?.pinned?s.jsx(He,{title:t("settings.classification.custom.title"),info:t("settings.classification.custom.info"),children:s.jsx("p",{className:Pn,children:t("settings.classification.custom.pinned",{url:e.url,model:e.model})})}):s.jsx(He,{title:t("settings.classification.custom.title"),info:t("settings.classification.custom.info"),children:s.jsxs("div",{className:Ms,children:[s.jsx(Ct,{label:t("settings.classification.custom.url.label"),info:t("settings.classification.custom.url.info"),children:s.jsx("div",{className:Yo,children:s.jsx(Ge,{type:"url",autoComplete:"off",spellCheck:!1,value:i,onChange:u=>o(u.target.value),onKeyDown:k,placeholder:"https://example.com/v1","aria-label":t("settings.classification.custom.url.label"),className:Zo,disabled:p})})}),s.jsx(Ct,{label:t("settings.classification.custom.model.label"),children:s.jsx("div",{className:Yo,children:s.jsx(Ge,{autoComplete:"off",spellCheck:!1,value:r,onChange:u=>d(u.target.value),onKeyDown:k,placeholder:"jev-latest","aria-label":t("settings.classification.custom.model.label"),className:Zo,disabled:p})})}),s.jsx(Ct,{label:t("settings.classification.custom.key.label"),info:t("settings.classification.custom.key.info"),children:s.jsx("div",{className:Yo,children:s.jsx(Ge,{type:"password",autoComplete:"off",value:c,onChange:u=>g(u.target.value),onKeyDown:k,placeholder:e?.keyPresent?t("settings.classification.custom.key.replacePlaceholder"):t("settings.classification.custom.key.placeholder"),"aria-label":t("settings.classification.custom.key.label"),className:Zo,disabled:p})})}),s.jsxs(Ct,{label:null,children:[s.jsx(V,{size:"sm",variant:"outline",onClick:b,disabled:p||!C,children:t("settings.classification.custom.save")}),e?s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>{v(n)},disabled:p,children:t("settings.classification.custom.remove")}):null]}),f?s.jsx("p",{className:Pn,children:f}):null]})})},Tb="https://docs.openchamber.dev/classification-providers/",Xo=t=>{const e=_e.c(6),{text:a,linkLabel:n,onOpen:i}=t;let o;e[0]!==n||e[1]!==i?(o=s.jsx("span",{onClick:Db,onKeyDown:Mb,children:s.jsx(Vn,{onClick:i,children:n})}),e[0]=n,e[1]=i,e[2]=o):o=e[2];let r;return e[3]!==o||e[4]!==a?(r=s.jsxs(s.Fragment,{children:[a," ",o]}),e[3]=o,e[4]=a,e[5]=r):r=e[5],r},Eb=({titleLeading:t,onOpenProvider:e})=>{const{t:a}=Be(),n=es(I=>I.available),i=es(I=>I.loaded),o=es(I=>I.loadError),r=es(I=>I.classifier),d=es(I=>I.tokenPresent),c=es(I=>I.customEndpoint),g=es(I=>I.enterpriseMode),p=es(I=>I.load),h=es(I=>I.setClassifierSource),f=es(I=>I.setToken),m=es(I=>I.clearToken),v=il(r?.effective??null),[C,b]=l.useState(""),[k,u]=l.useState(!1),[j,N]=l.useState(null);l.useEffect(()=>{p()},[p]);const w=I=>r?.sources.find(y=>y.id===I)?.usable===!0,S=async I=>{os("saving");try{await h(I),os("saved")}catch{os("error")}},A=async()=>{const I=C.trim();if(I){u(!0),N(null);try{await f(I),b("")}catch(y){N(y instanceof Error?y.message:String(y))}finally{u(!1)}}},x=async()=>{u(!0),N(null);try{await m()}catch(I){N(I instanceof Error?I.message:String(I))}finally{u(!1)}},E=g?c?.pinned?a("settings.classification.status.enterprisePinned"):a("settings.classification.status.enterprise"):!r||r.selected==="off"?null:r.effective===null?a("settings.classification.status.none"):r.effective!==r.selected&&v?a("settings.classification.status.fallback",{provider:v}):null,M=w("zen-promo"),T=w("zen-key"),D=w("openrouter"),R=w("vercel"),O=w("custom");return s.jsxs(ns,{title:a("settings.classification.page.title"),titleLeading:t,description:s.jsxs("p",{className:Pn,children:[a("settings.classification.page.description")," ",s.jsx(Vn,{onClick:()=>{_s(Tb)},children:a("settings.classification.page.docsLink")})]}),showSaveStatus:!0,children:[o?s.jsx("p",{className:Pn,children:a("settings.routing.loadError",{error:o})}):null,i?!n||!r?s.jsx("p",{className:Pn,children:a("settings.classification.unavailable")}):s.jsxs(s.Fragment,{children:[s.jsx(He,{title:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx($n,{providerId:"typesafe",className:"size-4 shrink-0"}),a("settings.classification.jev.title")]}),info:a("settings.classification.jev.info"),divider:!1,settingsItem:"providers.classification",children:s.jsxs("div",{className:Ms,children:[E?s.jsx("p",{className:ls,children:E}):null,s.jsxs(Js,{"aria-label":a("settings.classification.jev.title"),children:[s.jsx(rs,{selected:r.selected==="off",onSelect:()=>{S("off")},label:a("settings.classification.source.off.name"),description:a("settings.classification.source.off.description")}),g?null:s.jsxs(s.Fragment,{children:[M||r.selected==="zen-promo"?s.jsx(rs,{selected:r.selected==="zen-promo",onSelect:()=>{S("zen-promo")},disabled:!M,label:a("settings.classification.source.zenPromo.name"),description:a(M?"settings.classification.source.zenPromo.description":"settings.classification.source.zenPromo.ended")}):null,s.jsx(rs,{selected:r.selected==="zen-key",onSelect:()=>{S("zen-key")},disabled:!T,label:a("settings.classification.source.zenKey.name"),description:T?a("settings.classification.source.zenKey.description"):s.jsx(Xo,{text:a("settings.classification.source.zenKey.missing"),linkLabel:a("settings.classification.source.openProvider",{provider:"OpenCode Zen"}),onOpen:()=>e("opencode")})}),s.jsx(rs,{selected:r.selected==="openrouter",onSelect:()=>{S("openrouter")},disabled:!D,label:a("settings.classification.source.openrouter.name"),description:D?a("settings.classification.source.openrouter.description"):s.jsx(Xo,{text:a("settings.classification.source.openrouter.missing"),linkLabel:a("settings.classification.source.openProvider",{provider:"OpenRouter"}),onOpen:()=>e("openrouter")})}),s.jsx(rs,{selected:r.selected==="vercel",onSelect:()=>{S("vercel")},disabled:!R,label:a("settings.classification.source.vercel.name"),description:R?a("settings.classification.source.vercel.description"):s.jsx(Xo,{text:a("settings.classification.source.vercel.missing"),linkLabel:a("settings.classification.source.openProvider",{provider:"Vercel AI Gateway"}),onOpen:()=>e("vercel")})}),s.jsx(rs,{selected:r.selected==="typesafe",onSelect:()=>{S("typesafe")},disabled:!d,label:a("settings.classification.source.typesafe.name"),description:a(d?"settings.classification.source.typesafe.description":"settings.classification.source.typesafe.missing")})]}),!g||c?.pinned?s.jsx(rs,{selected:r.selected==="custom",onSelect:()=>{S("custom")},disabled:!O,label:a("settings.classification.source.custom.name"),description:c&&O?a("settings.classification.source.custom.description",{url:c.url}):a("settings.classification.source.custom.missing")}):null]}),g?null:s.jsx(Ct,{label:a("settings.routing.token.label"),info:a("settings.routing.token.info"),children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(Ge,{type:"password",autoComplete:"off",value:C,onChange:I=>b(I.target.value),onKeyDown:I=>{I.key==="Enter"&&A()},placeholder:a(d?"settings.routing.token.replacePlaceholder":"settings.routing.token.placeholder"),"aria-label":a("settings.routing.token.label"),className:"h-8 rounded-md px-3 min-w-0 flex-1",disabled:k}),s.jsx(V,{size:"sm",variant:"outline",onClick:()=>{A()},disabled:k||C.trim().length===0,children:a("settings.routing.token.save")}),d?s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>{x()},disabled:k,children:a("settings.routing.token.remove")}):null]})}),j?s.jsx("p",{className:Pn,children:j}):null]})}),!g||c?.pinned?s.jsx(Ab,{}):null]}):null]})};function Db(t){return t.stopPropagation()}function Mb(t){return t.stopPropagation()}const fc=t=>{const e=_e.c(2),{icon:a}=t;let n;return e[0]!==a?(n=s.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:s.jsx(B,{name:a,className:"size-4"})}),e[0]=a,e[1]=n):n=e[1],n},hc=t=>{const e=_e.c(3),{connection:a,fallback:n}=t;let i;return e[0]!==a||e[1]!==n?(i=al(a)&&a.status?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] break-words",children:a.status.message}):s.jsx("div",{className:"typography-micro text-muted-foreground",children:n}),e[0]=a,e[1]=n,e[2]=i):i=e[2],i},xc=t=>{const e=_e.c(11),{connection:a,account:n}=t,{t:i}=Be(),o=al(a)?a.status?.url:void 0;if(!o)return null;let r;e[0]!==o?(r=()=>{_s(o)},e[0]=o,e[1]=r):r=e[1];let d;e[2]!==n||e[3]!==i?(d=i("settings.providers.accounts.signInAria",{account:n}),e[2]=n,e[3]=i,e[4]=d):d=e[4];let c;e[5]!==i?(c=i("settings.providers.accounts.signIn"),e[5]=i,e[6]=c):c=e[6];let g;return e[7]!==r||e[8]!==d||e[9]!==c?(g=s.jsx(V,{variant:"outline",size:"xs",onClick:r,"aria-label":d,children:c}),e[7]=r,e[8]=d,e[9]=c,e[10]=g):g=e[10],g},Rb=t=>{const e=_e.c(32),{initial:a,onSave:n,onCancel:i}=t,{t:o}=Be(),[r,d]=l.useState(a);let c;e[0]!==r?(c=r.trim(),e[0]=r,e[1]=c):c=e[1];const g=c;let p;e[2]!==a||e[3]!==i||e[4]!==n||e[5]!==g?(p=()=>{if(g.length===0||g===a){i();return}n(g)},e[2]=a,e[3]=i,e[4]=n,e[5]=g,e[6]=p):p=e[6];const h=p;let f;e[7]!==h?(f=S=>{S.preventDefault(),h()},e[7]=h,e[8]=f):f=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=S=>d(S.target.value),e[9]=m):m=e[9];let v;e[10]!==i?(v=S=>{S.key==="Escape"&&(S.preventDefault(),S.stopPropagation(),i())},e[10]=i,e[11]=v):v=e[11];let C;e[12]!==o?(C=o("settings.providers.accounts.nameAria"),e[12]=o,e[13]=C):C=e[13];let b;e[14]!==v||e[15]!==C||e[16]!==r?(b=s.jsx(Ge,{autoFocus:!0,value:r,onChange:m,onKeyDown:v,"aria-label":C,className:"h-8 max-w-[18rem]"}),e[14]=v,e[15]=C,e[16]=r,e[17]=b):b=e[17];let k;e[18]!==o?(k=o("settings.providers.accounts.save"),e[18]=o,e[19]=k):k=e[19];let u;e[20]!==k?(u=s.jsx(V,{type:"submit",size:"xs",children:k}),e[20]=k,e[21]=u):u=e[21];let j;e[22]!==o?(j=o("settings.providers.page.actions.cancel"),e[22]=o,e[23]=j):j=e[23];let N;e[24]!==i||e[25]!==j?(N=s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:i,children:j}),e[24]=i,e[25]=j,e[26]=N):N=e[26];let w;return e[27]!==N||e[28]!==f||e[29]!==b||e[30]!==u?(w=s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-2",onSubmit:f,children:[b,u,N]}),e[27]=N,e[28]=f,e[29]=b,e[30]=u,e[31]=w):w=e[31],w},Ob=t=>{const e=_e.c(32),{connections:a,activeId:n,unusedIds:i,busyId:o,onActivate:r,onRename:d,onRemove:c}=t,{t:g}=Be(),[p,h]=l.useState(null);let f;if(e[0]!==a||e[1]!==i){let j;e[3]!==i?(j=N=>N.type==="credential"&&!i.has(N.id),e[3]=i,e[4]=j):j=e[4],f=a.filter(j),e[0]=a,e[1]=i,e[2]=f}else f=e[2];const v=f.length>1;let C;e[5]!==a?(C=a.filter(Lb),e[5]=a,e[6]=C):C=e[6];const b=C.length>1;let k;if(e[7]!==n||e[8]!==o||e[9]!==v||e[10]!==a||e[11]!==r||e[12]!==c||e[13]!==d||e[14]!==p||e[15]!==b||e[16]!==g||e[17]!==i){let j;e[19]!==n||e[20]!==o||e[21]!==v||e[22]!==r||e[23]!==c||e[24]!==d||e[25]!==p||e[26]!==b||e[27]!==g||e[28]!==i?(j=N=>{if(N.type==="env")return s.jsxs("div",{className:"flex min-w-0 items-center gap-3 py-2.5",children:[s.jsx(fc,{icon:"terminal-box"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate font-mono typography-ui-label text-foreground",children:N.name}),s.jsx(hc,{connection:N,fallback:g("settings.providers.accounts.environment")})]}),s.jsx(xc,{connection:N,account:N.name})]},`env:${N.name}`);const w=N.id===n,S=i.has(N.id),A=o!==null,x=N.method==="oauth"?g(S?"settings.providers.accounts.method.oauthUnused":"settings.providers.accounts.method.oauth"):g(S?"settings.providers.accounts.method.keyUnused":"settings.providers.accounts.method.key");return s.jsxs("div",{className:Se("flex min-w-0 items-center gap-3 py-2.5",S&&"opacity-60"),children:[s.jsx(fc,{icon:N.method==="oauth"?"user-3":"key"}),p===N.id?s.jsx(Rb,{initial:N.label,onCancel:()=>h(null),onSave:E=>{h(null),d(N,E)}}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:N.label}),b&&w?s.jsx("span",{className:"shrink-0 rounded-full bg-[var(--interactive-selection)] px-2 py-px text-[10px] font-medium text-[var(--interactive-selection-foreground)]",children:g("settings.providers.accounts.active")}):null]}),s.jsx(hc,{connection:N,fallback:x})]}),s.jsx(xc,{connection:N,account:N.label}),v&&!w&&!S?s.jsxs(V,{variant:"outline",size:"xs",disabled:A,onClick:()=>r(N),"aria-label":g("settings.providers.accounts.useAria",{account:N.label}),children:[o===N.id?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):null,g("settings.providers.accounts.use")]}):null,s.jsxs(Jn,{children:[s.jsx(Wn,{asChild:!0,children:s.jsx(V,{variant:"ghost",size:"icon",disabled:A,className:Se(hs,"shrink-0"),"aria-label":g("settings.providers.accounts.menuAria",{account:N.label}),children:s.jsx(B,{name:"more-2",className:"size-4"})})}),s.jsxs(Gn,{align:"end",children:[s.jsxs(xn,{onSelect:()=>h(N.id),children:[s.jsx(B,{name:"pencil",className:"size-4"}),g("settings.providers.accounts.rename")]}),s.jsxs(xn,{variant:"destructive",onSelect:()=>c(N),children:[s.jsx(B,{name:"delete-bin",className:"size-4"}),g("settings.providers.accounts.remove")]})]})]})]})]},N.id)},e[19]=n,e[20]=o,e[21]=v,e[22]=r,e[23]=c,e[24]=d,e[25]=p,e[26]=b,e[27]=g,e[28]=i,e[29]=j):j=e[29],k=a.map(j),e[7]=n,e[8]=o,e[9]=v,e[10]=a,e[11]=r,e[12]=c,e[13]=d,e[14]=p,e[15]=b,e[16]=g,e[17]=i,e[18]=k}else k=e[18];let u;return e[30]!==k?(u=s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:k}),e[30]=k,e[31]=u):u=e[31],u};function Lb(t){return t.type==="credential"}const ol={"openai-chat":"aisdk:@ai-sdk/openai-compatible","openai-responses":"aisdk:@ai-sdk/openai","anthropic-messages":"aisdk:@ai-sdk/anthropic"},ra="__custom_provider__",Fb=/^[a-z0-9][a-z0-9-_]*$/,Ud=/^https?:\/\//,Kb=/^\{env:([^}]+)\}$/,co=t=>{if(!t)return;if(typeof t.package=="string"&&t.package)return t.package;const e=t.api?.npm;return typeof e=="string"&&e?`aisdk:${e}`:void 0},_d=t=>t.settings&&typeof t.settings=="object"?t.settings:t.options&&typeof t.options=="object"?t.options:{};let zb=0;const uo=()=>`row-${zb++}`,rl=()=>({row:uo(),id:"",name:"",variants:""});function Ub(t,e){switch(t){case"openai-chat":return{settings:{reasoningEffort:e}};case"openai-responses":return{settings:{reasoningEffort:e,reasoningSummary:"auto",include:["reasoning.encrypted_content"]}};case"anthropic-messages":return{settings:{thinking:{type:"adaptive",display:"summarized"},effort:e}}}}function _b(t){const e=t.split(/[,\s]+/).map(a=>a.trim()).filter(Boolean);return e.filter((a,n)=>e.indexOf(a)===n)}function $b(t){return Object.fromEntries((t??[]).map(({id:e,...a})=>[e,a]))}const ll=()=>({row:uo(),key:"",value:""}),Bb=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[rl()],headers:[ll()]}),$d={"@opencode/ai/providers/openai-compatible":"openai-chat","@opencode/ai/providers/openai":"openai-responses","@opencode/ai/providers/anthropic":"anthropic-messages"};function Vb(t){const e=t?$d[t]:void 0;if(e)return e;switch(t){case"aisdk:@ai-sdk/openai":case"@ai-sdk/openai":return"openai-responses";case"aisdk:@ai-sdk/anthropic":case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function Hb(t){const e=t.trim();if(!e)return{};const n=e.match(Kb)?.[1]?.trim();return n?{env:n}:{key:e}}function qb(t){const e=_d(t),a=typeof e.baseURL=="string"?e.baseURL.trim():"";if(a&&Ud.test(a))return!0;const n=new Set([...Object.values(ol),...Object.keys($d)]);return n.has(co(t)??"")?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(o=>!o||typeof o!="object"?!1:n.has(co(o)??""))}function bc(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&qb(t):!1}function vc(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function yc(t){const e=_d(t),a=typeof e.baseURL=="string"?e.baseURL:"",n=t.headers&&typeof t.headers=="object"?t.headers:e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(n).filter(g=>typeof g[0]=="string"&&typeof g[1]=="string").map(([g,p])=>({row:uo(),key:g,value:p})),o=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([g,p])=>{const h=p&&typeof p=="object"?p:{};return{id:g,modelID:typeof h.modelID=="string"?h.modelID:g,name:typeof h.name=="string"?h.name:g,package:typeof h.package=="string"?h.package:void 0,variants:Bd.safeParse(h.variants).data}}):[],r=o.length>0?o.map(g=>{const p=typeof g?.modelID=="string"&&g.modelID?g.modelID:typeof g?.id=="string"?g.id:"",h=$b(g?.variants);return{row:uo(),id:p,name:typeof g?.name=="string"?g.name:p,variants:Object.keys(h).join(", "),savedVariants:h}}):[rl()],d=Array.isArray(t.env)?t.env.find(g=>typeof g=="string"&&g.trim().length>0)?.trim():void 0,c=o.map(g=>co(g)).find(g=>!!g);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:Vb(co(t)??c),baseURL:a,apiKey:d?`{env:${d}}`:"",models:r,headers:i.length>0?i:[ll()]}}const Bd=ja(Os({id:Rt(),settings:Bn(Rt(),vr()).optional(),headers:Bn(Rt(),Rt()).optional(),body:Bn(Rt(),vr()).optional()})),Gb=Os({name:Rt().optional(),package:Rt().optional(),env:ja(Rt()).optional(),settings:Bn(Rt(),vr()).optional(),headers:Bn(Rt(),Rt()).optional(),models:Bn(Rt(),Os({modelID:Rt().optional(),name:Rt().optional(),package:Rt().optional(),variants:Bd.optional()})).optional()});function Wb(t,e){const a=Array.isArray(t.models)?t.models.map(o=>({...o,variants:void 0})):t.models,n=yc({...t,models:a});if(!e)return{...n,models:n.models.map(o=>({...o,savedVariants:void 0}))};const i=yc({...e,id:t.id});return{providerID:t.id,name:e.name?.trim()?i.name:n.name,protocol:e.package?i.protocol:n.protocol,baseURL:i.baseURL||n.baseURL,apiKey:i.apiKey,models:e.models&&Object.keys(e.models).length>0?i.models:n.models.map(o=>({...o,savedVariants:void 0})),headers:i.headers}}function Jb(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:o}=Hb(t.form.apiKey),r=t.disabledProviders??[],d=t.editingProviderID?.trim(),c=e?Fb.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),g=a?void 0:t.t("settings.providers.page.custom.error.name.required"),p=n?Ud.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),f=!!(i||o||d&&t.allowExistingAuth&&d===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),m=r.includes(e),C=c||!!(d&&d===e)?void 0:t.existingProviderIDs.has(e)&&!m?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,b=new Set,k=t.form.models.map(M=>{const T=M.id.trim(),D=T?b.has(T)?t.t("settings.providers.page.custom.error.duplicate"):void b.add(T):t.t("settings.providers.page.custom.error.required"),R=M.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:D,name:R}}),u=k.every(M=>!M.id&&!M.name),j=Object.fromEntries(t.form.models.map(M=>{const T=M.id.trim(),D={modelID:T,name:M.name.trim()},R=_b(M.variants);return(R.length>0||M.savedVariants!==void 0)&&(D.variants=R.map(O=>({id:O,...M.savedVariants?.[O]??Ub(t.form.protocol,O)}))),[T,D]})),N=new Set,w=t.form.headers.map(M=>{const T=M.key.trim(),D=M.value.trim();if(!T&&!D)return{};const R=T?N.has(T.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void N.add(T.toLowerCase()):t.t("settings.providers.page.custom.error.required"),O=D?void 0:t.t("settings.providers.page.custom.error.required");return{key:R,value:O}}),S=w.every(M=>!M.key&&!M.value),A=Object.fromEntries(t.form.headers.map(M=>({key:M.key.trim(),value:M.value.trim()})).filter(M=>M.key&&M.value).map(M=>[M.key,M.value])),x={providerID:c??C,name:g,baseURL:p,apiKey:f};return!c&&!C&&!g&&!p&&!f&&u&&S?{err:x,models:k,headers:w,result:{providerID:e,name:a,apiKey:o,...!i&&!o?{keepsStoredCredential:!0}:{},config:Qb({protocol:t.form.protocol,name:a,env:i,baseURL:n,headers:A,models:j})}}:{err:x,models:k,headers:w}}function Qb(t){const e={package:ol[t.protocol],name:t.name,settings:{baseURL:t.baseURL},models:t.models};return t.env&&(e.env=[t.env]),Object.keys(t.headers).length>0&&(e.headers=t.headers),e}function Yb(t){return t.apiKey?{integrationID:t.providerID,key:t.apiKey}:null}function Zb(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user",hasCredential:!!(t.apiKey||t.keepsStoredCredential)}}const Xb=[250,500,1e3,2e3];async function ev(t,e=a=>new Promise(n=>setTimeout(n,a))){for(let a=0;;a+=1)try{await t();return}catch(n){const i=Xb[a];if(!(n instanceof Error&&/not found/i.test(n.message))||i===void 0)throw n;await e(i)}}const jc=t=>{const e=_e.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:o,initialValues:r,allowExistingAuth:d,authFailureHint:c,onSubmit:g,onCancel:p,onDisconnect:h}=t;let f;e[0]!==n?(f=n===void 0?[]:n,e[0]=n,e[1]=f):f=e[1];const m=f,v=i===void 0?!1:i,C=o===void 0?"create":o,b=d===void 0?!1:d,k=c===void 0?null:c,{t:u}=Be(),j=C==="edit";let N;e[2]!==r?(N=()=>r??Bb(),e[2]=r,e[3]=N):N=e[3];const[w,S]=l.useState(N);let A;e[4]===Symbol.for("react.memo_cache_sentinel")?(A={},e[4]=A):A=e[4];const[x,E]=l.useState(A);let M;e[5]===Symbol.for("react.memo_cache_sentinel")?(M=[],e[5]=M):M=e[5];const[T,D]=l.useState(M);let R;e[6]===Symbol.for("react.memo_cache_sentinel")?(R=[],e[6]=R):R=e[6];const[O,I]=l.useState(R),y=l.useRef(null);let L,K;e[7]!==r||e[8]!==j?(L=()=>{r&&(j&&y.current===r.providerID||(y.current=j?r.providerID:null,S(r),E({}),D([]),I([])))},K=[r,j],e[7]=r,e[8]=j,e[9]=L,e[10]=K):(L=e[9],K=e[10]),l.useEffect(L,K);let H;e[11]===Symbol.for("react.memo_cache_sentinel")?(H=(Lt,Xt)=>{S(Wt=>({...Wt,[Lt]:Xt})),E(Wt=>({...Wt,[Lt]:void 0}))},e[11]=H):H=e[11];const G=H;let W;e[12]===Symbol.for("react.memo_cache_sentinel")?(W=(Lt,Xt,Wt)=>{S(Mt=>({...Mt,models:Mt.models.map((cs,is)=>is===Lt?{...cs,[Xt]:Wt}:cs)})),D(Mt=>{const cs=[...Mt];return cs[Lt]={...cs[Lt]??{},[Xt]:void 0},cs})},e[12]=W):W=e[12];const q=W;let z;e[13]===Symbol.for("react.memo_cache_sentinel")?(z=(Lt,Xt,Wt)=>{S(Mt=>({...Mt,headers:Mt.headers.map((cs,is)=>is===Lt?{...cs,[Xt]:Wt}:cs)})),I(Mt=>{const cs=[...Mt];return cs[Lt]={...cs[Lt]??{},[Xt]:void 0},cs})},e[13]=z):z=e[13];const $=z;let Z;e[14]!==b||e[15]!==v||e[16]!==m||e[17]!==a||e[18]!==w||e[19]!==j||e[20]!==g||e[21]!==u?(Z=async Lt=>{if(Lt.preventDefault(),v)return;const Xt=Jb({form:w,t:((Wt,Mt)=>u(Wt,Mt)),existingProviderIDs:a,disabledProviders:m,editingProviderID:j?w.providerID:void 0,allowExistingAuth:j&&b});E(Xt.err),D(Xt.models),I(Xt.headers),Xt.result&&await g(Xt.result)},e[14]=b,e[15]=v,e[16]=m,e[17]=a,e[18]=w,e[19]=j,e[20]=g,e[21]=u,e[22]=Z):Z=e[22];const _=Z;let ne;e[23]!==j||e[24]!==u?(ne=u(j?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=j,e[24]=u,e[25]=ne):ne=e[25];let X;e[26]!==u?(X=u("settings.providers.page.custom.description"),e[26]=u,e[27]=X):X=e[27];let te;e[28]!==X?(te=s.jsx("p",{className:ls,children:X}),e[28]=X,e[29]=te):te=e[29];let he;e[30]!==k?(he=k?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:k}):null,e[30]=k,e[31]=he):he=e[31];let je;e[32]!==u?(je=u("settings.providers.page.custom.field.providerID.label"),e[32]=u,e[33]=je):je=e[33];let fe;e[34]!==u?(fe=u("settings.providers.page.custom.field.providerID.info"),e[34]=u,e[35]=fe):fe=e[35];const ke=w.providerID;let be;e[36]===Symbol.for("react.memo_cache_sentinel")?(be=Lt=>G("providerID",Lt.target.value),e[36]=be):be=e[36];let De;e[37]!==u?(De=u("settings.providers.page.custom.field.providerID.placeholder"),e[37]=u,e[38]=De):De=e[38];const oe=!j,ee=j||v,ce=!!x.providerID;let ue;e[39]!==u?(ue=u("settings.providers.page.custom.field.providerID.label"),e[39]=u,e[40]=ue):ue=e[40];let Ie;e[41]!==w.providerID||e[42]!==De||e[43]!==oe||e[44]!==ee||e[45]!==ce||e[46]!==ue?(Ie=s.jsx(Ge,{value:ke,onChange:be,placeholder:De,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:oe,disabled:ee,"aria-invalid":ce,"aria-label":ue}),e[41]=w.providerID,e[42]=De,e[43]=oe,e[44]=ee,e[45]=ce,e[46]=ue,e[47]=Ie):Ie=e[47];let ve;e[48]!==x.providerID?(ve=x.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.providerID}):null,e[48]=x.providerID,e[49]=ve):ve=e[49];let Re;e[50]!==je||e[51]!==fe||e[52]!==Ie||e[53]!==ve?(Re=s.jsxs(Kt,{label:je,info:fe,children:[Ie,ve]}),e[50]=je,e[51]=fe,e[52]=Ie,e[53]=ve,e[54]=Re):Re=e[54];let Me;e[55]!==u?(Me=u("settings.providers.page.custom.field.protocol.label"),e[55]=u,e[56]=Me):Me=e[56];let me;e[57]!==u?(me=u("settings.providers.page.custom.field.protocol.info"),e[57]=u,e[58]=me):me=e[58];const Te=w.protocol;let Oe;e[59]===Symbol.for("react.memo_cache_sentinel")?(Oe=Lt=>{Lt in ol&&S(Xt=>({...Xt,protocol:Lt,models:Xt.models.map(tv)}))},e[59]=Oe):Oe=e[59];let pe;e[60]!==u?(pe=u("settings.providers.page.custom.field.protocol.label"),e[60]=u,e[61]=pe):pe=e[61];let xe;e[62]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx(Jt,{}),e[62]=xe):xe=e[62];let ae;e[63]!==pe?(ae=s.jsx(Tt,{"aria-label":pe,className:"w-full",children:xe}),e[63]=pe,e[64]=ae):ae=e[64];let ie;e[65]!==u?(ie=u("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=u,e[66]=ie):ie=e[66];let ge;e[67]!==ie?(ge=s.jsx(gt,{value:"openai-chat",children:ie}),e[67]=ie,e[68]=ge):ge=e[68];let Ee;e[69]!==u?(Ee=u("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=u,e[70]=Ee):Ee=e[70];let Ke;e[71]!==Ee?(Ke=s.jsx(gt,{value:"openai-responses",children:Ee}),e[71]=Ee,e[72]=Ke):Ke=e[72];let Le;e[73]!==u?(Le=u("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=u,e[74]=Le):Le=e[74];let Ne;e[75]!==Le?(Ne=s.jsx(gt,{value:"anthropic-messages",children:Le}),e[75]=Le,e[76]=Ne):Ne=e[76];let Ve;e[77]!==ge||e[78]!==Ke||e[79]!==Ne?(Ve=s.jsxs(Et,{children:[ge,Ke,Ne]}),e[77]=ge,e[78]=Ke,e[79]=Ne,e[80]=Ve):Ve=e[80];let Ye;e[81]!==v||e[82]!==w.protocol||e[83]!==ae||e[84]!==Ve?(Ye=s.jsxs(Dt,{value:Te,onValueChange:Oe,disabled:v,children:[ae,Ve]}),e[81]=v,e[82]=w.protocol,e[83]=ae,e[84]=Ve,e[85]=Ye):Ye=e[85];let pt;e[86]!==Me||e[87]!==me||e[88]!==Ye?(pt=s.jsx(Kt,{label:Me,info:me,children:Ye}),e[86]=Me,e[87]=me,e[88]=Ye,e[89]=pt):pt=e[89];let vt;e[90]!==u?(vt=u("settings.providers.page.custom.field.name.label"),e[90]=u,e[91]=vt):vt=e[91];let wt;e[92]!==u?(wt=u("settings.providers.page.custom.field.name.info"),e[92]=u,e[93]=wt):wt=e[93];const yt=w.name;let st;e[94]===Symbol.for("react.memo_cache_sentinel")?(st=Lt=>G("name",Lt.target.value),e[94]=st):st=e[94];let rt;e[95]!==u?(rt=u("settings.providers.page.custom.field.name.placeholder"),e[95]=u,e[96]=rt):rt=e[96];const de=!!x.name;let Ue;e[97]!==u?(Ue=u("settings.providers.page.custom.field.name.label"),e[97]=u,e[98]=Ue):Ue=e[98];let et;e[99]!==w.name||e[100]!==rt||e[101]!==de||e[102]!==Ue?(et=s.jsx(Ge,{value:yt,onChange:st,placeholder:rt,className:"h-8 rounded-md px-3","aria-invalid":de,"aria-label":Ue}),e[99]=w.name,e[100]=rt,e[101]=de,e[102]=Ue,e[103]=et):et=e[103];let ze;e[104]!==x.name?(ze=x.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.name}):null,e[104]=x.name,e[105]=ze):ze=e[105];let Ze;e[106]!==vt||e[107]!==wt||e[108]!==et||e[109]!==ze?(Ze=s.jsxs(Kt,{label:vt,info:wt,children:[et,ze]}),e[106]=vt,e[107]=wt,e[108]=et,e[109]=ze,e[110]=Ze):Ze=e[110];let tt;e[111]!==u?(tt=u("settings.providers.page.custom.field.baseURL.label"),e[111]=u,e[112]=tt):tt=e[112];let lt;e[113]!==u?(lt=u("settings.providers.page.custom.field.baseURL.info"),e[113]=u,e[114]=lt):lt=e[114];const Q=w.baseURL;let nt;e[115]===Symbol.for("react.memo_cache_sentinel")?(nt=Lt=>G("baseURL",Lt.target.value),e[115]=nt):nt=e[115];let ot;e[116]!==u?(ot=u("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=u,e[117]=ot):ot=e[117];const it=!!x.baseURL;let ft;e[118]!==u?(ft=u("settings.providers.page.custom.field.baseURL.label"),e[118]=u,e[119]=ft):ft=e[119];let bt;e[120]!==w.baseURL||e[121]!==ot||e[122]!==it||e[123]!==ft?(bt=s.jsx(Ge,{value:Q,onChange:nt,placeholder:ot,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":it,"aria-label":ft}),e[120]=w.baseURL,e[121]=ot,e[122]=it,e[123]=ft,e[124]=bt):bt=e[124];let ht;e[125]!==x.baseURL?(ht=x.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.baseURL}):null,e[125]=x.baseURL,e[126]=ht):ht=e[126];let Nt;e[127]!==tt||e[128]!==lt||e[129]!==bt||e[130]!==ht?(Nt=s.jsxs(Kt,{label:tt,info:lt,children:[bt,ht]}),e[127]=tt,e[128]=lt,e[129]=bt,e[130]=ht,e[131]=Nt):Nt=e[131];let At;e[132]!==u?(At=u("settings.providers.page.custom.field.apiKey.label"),e[132]=u,e[133]=At):At=e[133];let $e;e[134]!==b||e[135]!==j||e[136]!==u?($e=u(j&&b?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=b,e[135]=j,e[136]=u,e[137]=$e):$e=e[137];const Xe=w.apiKey;let mt;e[138]===Symbol.for("react.memo_cache_sentinel")?(mt=Lt=>G("apiKey",Lt.target.value),e[138]=mt):mt=e[138];let Fe;e[139]!==b||e[140]!==j||e[141]!==u?(Fe=u(j&&b?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=b,e[140]=j,e[141]=u,e[142]=Fe):Fe=e[142];const J=!!x.apiKey;let ye;e[143]!==u?(ye=u("settings.providers.page.custom.field.apiKey.label"),e[143]=u,e[144]=ye):ye=e[144];let Ae;e[145]!==w.apiKey||e[146]!==Fe||e[147]!==J||e[148]!==ye?(Ae=s.jsx(Ge,{type:"password",value:Xe,onChange:mt,placeholder:Fe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":J,"aria-label":ye}),e[145]=w.apiKey,e[146]=Fe,e[147]=J,e[148]=ye,e[149]=Ae):Ae=e[149];let Y;e[150]!==x.apiKey?(Y=x.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:x.apiKey}):null,e[150]=x.apiKey,e[151]=Y):Y=e[151];let Pe;e[152]!==At||e[153]!==$e||e[154]!==Ae||e[155]!==Y?(Pe=s.jsxs(Kt,{label:At,info:$e,children:[Ae,Y]}),e[152]=At,e[153]=$e,e[154]=Ae,e[155]=Y,e[156]=Pe):Pe=e[156];let Je;e[157]!==ne||e[158]!==te||e[159]!==he||e[160]!==Re||e[161]!==pt||e[162]!==Ze||e[163]!==Nt||e[164]!==Pe?(Je=s.jsxs(He,{title:ne,divider:!1,settingsItem:"providers.custom",contentClassName:Ms,children:[te,he,Re,pt,Ze,Nt,Pe]}),e[157]=ne,e[158]=te,e[159]=he,e[160]=Re,e[161]=pt,e[162]=Ze,e[163]=Nt,e[164]=Pe,e[165]=Je):Je=e[165];let se;e[166]!==u?(se=u("settings.providers.page.custom.models.title"),e[166]=u,e[167]=se):se=e[167];let We;if(e[168]!==w.models||e[169]!==T||e[170]!==u){let Lt;e[172]!==w.models.length||e[173]!==T||e[174]!==u?(Lt=(Xt,Wt)=>s.jsx("div",{className:`${Es} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.models.idLabel")}),s.jsx(Ge,{value:Xt.id,onChange:Mt=>q(Wt,"id",Mt.target.value),placeholder:u("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.models.idLabel")}),T[Wt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:T[Wt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.models.nameLabel")}),s.jsx(Ge,{value:Xt.name,onChange:Mt=>q(Wt,"name",Mt.target.value),placeholder:u("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":u("settings.providers.page.custom.models.nameLabel")}),T[Wt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:T[Wt]?.name}):null]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.models.variantsLabel")}),s.jsx(Gt,{children:u("settings.providers.page.custom.models.variantsInfo")})]}),s.jsx(Ge,{value:Xt.variants,onChange:Mt=>q(Wt,"variants",Mt.target.value),placeholder:u("settings.providers.page.custom.models.variantsPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.models.variantsLabel")})]})]}),s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:w.models.length<=1,onClick:()=>{w.models.length<=1||(S(Mt=>({...Mt,models:Mt.models.filter((cs,is)=>is!==Wt)})),D(Mt=>Mt.filter((cs,is)=>is!==Wt)))},"aria-label":u("settings.providers.page.custom.models.remove"),children:s.jsx(B,{name:"delete-bin",className:"size-4"})})]})},Xt.row),e[172]=w.models.length,e[173]=T,e[174]=u,e[175]=Lt):Lt=e[175],We=w.models.map(Lt),e[168]=w.models,e[169]=T,e[170]=u,e[171]=We}else We=e[171];let ut;e[176]===Symbol.for("react.memo_cache_sentinel")?(ut=()=>{S(sv),D(nv)},e[176]=ut):ut=e[176];let Ce;e[177]!==u?(Ce=u("settings.providers.page.custom.models.add"),e[177]=u,e[178]=Ce):Ce=e[178];let qe;e[179]!==Ce?(qe=s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ut,children:Ce}),e[179]=Ce,e[180]=qe):qe=e[180];let jt;e[181]!==se||e[182]!==We||e[183]!==qe?(jt=s.jsxs(He,{title:se,contentClassName:Ms,children:[We,qe]}),e[181]=se,e[182]=We,e[183]=qe,e[184]=jt):jt=e[184];let Ot;e[185]!==u?(Ot=u("settings.providers.page.custom.headers.title"),e[185]=u,e[186]=Ot):Ot=e[186];let Yt;e[187]!==u?(Yt=u("settings.providers.page.custom.headers.description"),e[187]=u,e[188]=Yt):Yt=e[188];let Zt;e[189]!==Yt?(Zt=s.jsx("p",{className:ls,children:Yt}),e[189]=Yt,e[190]=Zt):Zt=e[190];let Ft;if(e[191]!==w.headers||e[192]!==O||e[193]!==u){let Lt;e[195]!==w.headers.length||e[196]!==O||e[197]!==u?(Lt=(Xt,Wt)=>s.jsx("div",{className:`${Es} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.headers.keyLabel")}),s.jsx(Ge,{value:Xt.key,onChange:Mt=>$(Wt,"key",Mt.target.value),placeholder:u("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.keyLabel")}),O[Wt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:O[Wt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Pt,children:u("settings.providers.page.custom.headers.valueLabel")}),s.jsx(Ge,{value:Xt.value,onChange:Mt=>$(Wt,"value",Mt.target.value),placeholder:u("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.valueLabel")}),O[Wt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:O[Wt]?.value}):null]})]}),s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:w.headers.length<=1,onClick:()=>{w.headers.length<=1||(S(Mt=>({...Mt,headers:Mt.headers.filter((cs,is)=>is!==Wt)})),I(Mt=>Mt.filter((cs,is)=>is!==Wt)))},"aria-label":u("settings.providers.page.custom.headers.remove"),children:s.jsx(B,{name:"delete-bin",className:"size-4"})})]})},Xt.row),e[195]=w.headers.length,e[196]=O,e[197]=u,e[198]=Lt):Lt=e[198],Ft=w.headers.map(Lt),e[191]=w.headers,e[192]=O,e[193]=u,e[194]=Ft}else Ft=e[194];let ps;e[199]===Symbol.for("react.memo_cache_sentinel")?(ps=()=>{S(av),I(iv)},e[199]=ps):ps=e[199];let gs;e[200]!==u?(gs=u("settings.providers.page.custom.headers.add"),e[200]=u,e[201]=gs):gs=e[201];let tn;e[202]!==gs?(tn=s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ps,children:gs}),e[202]=gs,e[203]=tn):tn=e[203];let Bs;e[204]!==Ot||e[205]!==Zt||e[206]!==Ft||e[207]!==tn?(Bs=s.jsxs(He,{title:Ot,contentClassName:Ms,children:[Zt,Ft,tn]}),e[204]=Ot,e[205]=Zt,e[206]=Ft,e[207]=tn,e[208]=Bs):Bs=e[208];let Vs;e[209]!==v||e[210]!==p||e[211]!==u?(Vs=p?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:p,disabled:v,children:u("settings.providers.page.custom.actions.back")}):null,e[209]=v,e[210]=p,e[211]=u,e[212]=Vs):Vs=e[212];let cn;e[213]!==v||e[214]!==h||e[215]!==u?(cn=h?s.jsx(V,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{h()},disabled:v,children:u("settings.providers.page.actions.disconnect")}):null,e[213]=v,e[214]=h,e[215]=u,e[216]=cn):cn=e[216];let sn;e[217]!==v||e[218]!==j||e[219]!==u?(sn=u(v?"settings.providers.page.actions.saving":j?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=v,e[218]=j,e[219]=u,e[220]=sn):sn=e[220];let nn;e[221]!==v||e[222]!==sn?(nn=s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:v,children:sn}),e[221]=v,e[222]=sn,e[223]=nn):nn=e[223];let Hs;e[224]!==Vs||e[225]!==cn||e[226]!==nn?(Hs=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Vs,cn,nn]}),e[224]=Vs,e[225]=cn,e[226]=nn,e[227]=Hs):Hs=e[227];let Dn;return e[228]!==_||e[229]!==Je||e[230]!==jt||e[231]!==Bs||e[232]!==Hs?(Dn=s.jsxs("form",{onSubmit:_,className:"space-y-0",children:[Je,jt,Bs,Hs]}),e[228]=_,e[229]=Je,e[230]=jt,e[231]=Bs,e[232]=Hs,e[233]=Dn):Dn=e[233],Dn};function tv(t){return t.savedVariants?{...t,savedVariants:{}}:t}function sv(t){return{...t,models:[...t.models,rl()]}}function nv(t){return[...t,{}]}function av(t){return{...t,headers:[...t.headers,ll()]}}function iv(t){return[...t,{}]}const ov=t=>new Intl.NumberFormat(go(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),kc=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=ov(t);return e.endsWith(".0")?e.slice(0,-2):e},On="__add_provider__",_a="__classification__",Vd=t=>typeof t=="object"&&t!==null,rv=t=>{if(typeof t=="string")return{id:t};if(!Vd(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const a=typeof t.name=="string"?t.name:void 0;return{id:e,name:a}},lv=t=>{let e=[];Array.isArray(t)?e=t:Vd(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>rv(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},cv=()=>{const{t}=Be(),{isMobile:e}=qn(),a=en(),n=ct(se=>id(se,a)),i=re(se=>se.settingsProvidersConnectRequested),o=re(se=>se.setSettingsProvidersConnectRequested),r=re(se=>se.settingsProvidersClassificationRequested),d=re(se=>se.setSettingsProvidersClassificationRequested),c=re(se=>se.settingsProvidersOpenRequested),g=re(se=>se.setSettingsProvidersOpenRequested),[p,h]=l.useState(()=>i?On:r?_a:c??"");l.useEffect(()=>{i&&(h(On),o(!1))},[i,o]),l.useEffect(()=>{r&&(h(_a),d(!1))},[r,d]),l.useEffect(()=>{c&&(h(c),g(null))},[c,g]);const f=ct(se=>se.getModelMetadata),m=re(se=>se.hiddenModels),v=re(se=>se.toggleHiddenModel),C=re(se=>se.hideAllModels),b=re(se=>se.showAllModels),k=ct(se=>se.loadProviders);l.useEffect(()=>{a&&k({directory:a,source:"settings:providers"})},[k,a]);const[u,j]=l.useState(null),[N,w]=l.useState(!1),[S,A]=l.useState({}),[x,E]=l.useState(null),[M,T]=l.useState(null),[D,R]=l.useState(""),[O,I]=l.useState([]),[y,L]=l.useState(!1),[K,H]=l.useState(null),[G,W]=l.useState(""),[q,z]=l.useState(""),[$,Z]=l.useState(!1),[_,ne]=l.useState({}),[X,te]=l.useState({}),[he,je]=l.useState(0),[fe,ke]=l.useState(0),[be,De]=l.useState(!1),oe=ya(),[ee,ce]=l.useState(null),[ue,Ie]=l.useState(null),[ve,Re]=l.useState(null),[Me,me]=l.useState(null),[Te,Oe]=l.useState(null),[pe,xe]=l.useState(null),ae=p===On,ie=ae&&G===ra,ge=!!(ue&&p&&ue===p&&!ae);l.useEffect(()=>{let se=!0;return(async()=>{w(!0);try{const{data:ut}=await Ts.getSdkClient().integration.list();if(!se)return;j(ut)}catch(ut){if(!se)return;console.error("Failed to load provider integrations:",ut),U.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{se&&w(!1)}})(),()=>{se=!1}},[fe,t]),l.useEffect(()=>{if(!ib(ae))return;let se=!0;return(async()=>{L(!0),H(null);try{const[{data:ut},Ce]=await Promise.all([Ts.getSdkClient().integration.list(),zu(Ts.getDirectory()??null).catch(()=>null)]);if(!se)return;const qe=new Set((Ce??[]).map(jt=>jt.id));I(lv(ut.filter(jt=>!jt.id.startsWith("mcp_")&&!qe.has(jt.id)&&jt.connections.length===0)))}catch(ut){if(!se)return;console.error("Failed to load available providers:",ut),H(t("settings.providers.page.state.unableToLoadProviderList"))}finally{se&&L(!1)}})(),()=>{se=!1}},[ae,t]);const Ee=l.useMemo(()=>new Set(n.map(se=>se.id)),[n]),Ke=l.useMemo(()=>O.filter(se=>!Ee.has(se.id)).sort((se,We)=>{const ut=(se.name||se.id).toLowerCase(),Ce=(We.name||We.id).toLowerCase();return ut.localeCompare(Ce)}),[O,Ee]);l.useEffect(()=>{p!==On||y||O.length===0||G&&G!==ra&&!Ke.some(se=>se.id===G)&&W("")},[p,G,Ke,y,O.length]),l.useEffect(()=>{if(p===On){De(!0),ce(null),Ie(null),Re(null),me(null),Oe(null);return}De(!1),ce(null),ue&&ue!==p&&(Ie(null),Re(null),me(null),Oe(null))},[p,ue]),l.useEffect(()=>{if(!p||p===On||p===_a)return;const se=_[p];if(!se||u===null)return;const We=n.find(qe=>qe.id===p),ut=gc({connections:eo(u,p),optionsApiKey:Pr(We)}),Ce=!!(We&&bc(We,se));ub({hasCredentials:ut,userDismissed:ee===p,isEditableCustomProvider:Ce})&&De(!0)},[p,_,n,u,ee]),l.useEffect(()=>{if(!p||p===On||p===_a)return;let se=!1;return(async()=>{try{const ut=a?`?directory=${encodeURIComponent(a)}`:"",Ce=await It(`/api/provider/${encodeURIComponent(p)}/source${ut}`,{method:"GET",headers:{Accept:"application/json"}}),qe=await Ce.json().catch(()=>null);if(!Ce.ok)throw new Error(qe?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const jt=qe?.sources??qe?.data?.sources;!se&&jt&&(ne(Ot=>({...Ot,[p]:jt})),te(Ot=>({...Ot,[p]:Gb.safeParse(qe?.config??qe?.data?.config).data??null})))}catch(ut){se||console.error("Failed to load provider sources:",ut)}})(),()=>{se=!0}},[p,he,a,t]);const Le=l.useCallback(()=>{je(se=>se+1)},[]),Ne=l.useCallback(()=>{ke(se=>se+1)},[]),Ve=l.useCallback(se=>{j(We=>(We??[]).map(ut=>ut.id===se&&ut.connections.length===0?{...ut,connections:[{type:"credential",id:`pending:${se}`,label:se,method:"key"}]}:ut)),ce(null),De(!1),h(se),Le(),Ne()},[Ne,Le,h]),Ye=n.find(se=>se.id===p),pt=p?_[p]:void 0,vt=async se=>{const We=S[se]?.trim()??"";if(!We){U.error(t("settings.providers.page.toast.apiKeyRequired"));return}const ut=`api:${se}`;E(ut);try{await Ts.getSdkClient().integration.connect.key({integrationID:se,key:We}),U.success(t("settings.providers.page.toast.apiKeySaved")),A(Ce=>({...Ce,[se]:""})),Ve(se)}catch(Ce){console.error("Failed to save API key:",Ce),U.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{E(null)}},wt=async se=>{const We=`custom:${se.providerID}`;E(We),xe(se.providerID),Oe(null);try{const ut=Yb(se),Ce=Zb(se,{scope:ue?Me??vc(_[ue]):"user"}),qe=await It(`/api/provider${a?`?directory=${encodeURIComponent(a)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Ce)}),jt=await qe.json().catch(()=>null);if(!qe.ok)throw new Error(jt?.error||t("settings.providers.page.toast.customProviderSaveFailed"));if(ut)try{await ev(()=>Ts.getSdkClient().integration.connect.key(ut))}catch(Ot){throw Oe(t("settings.providers.page.custom.authFailure.keyAfterConfig")),Ot}U.success(t("settings.providers.page.toast.customProviderSaved",{provider:se.name})),W(""),Ie(null),Re(null),me(null),Oe(null),xe(null),Ve(se.providerID)}catch(ut){console.error("Failed to save custom provider:",ut),U.error(ut instanceof Error&&ut.message?ut.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{E(null)}},yt=se=>{De(!1),Ve(se)},st=async se=>{const We=`disconnect:${se}`;E(We);try{const ut=pc(Kn(u??[],se)),Ce=Ts.getSdkClient();for(const qe of ut)await Ce.credential.remove({credentialID:qe.id});U.success(t("settings.providers.page.toast.providerDisconnected")),ce(null),Le(),Ne()}catch(ut){console.error("Failed to disconnect provider:",ut),U.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{E(null)}},rt=async se=>{se&&(await st(se),Ie(null),Re(null),me(null),Oe(null),xe(null),W(""))},de=async(se,We,ut)=>{T(se.id);try{await We(),ut.success&&U.success(ut.success)}catch(Ce){console.error("Provider account action failed:",Ce),U.error(ut.failure)}finally{T(null),Ne()}},Ue=se=>de(se,async()=>{await Ts.getSdkClient().credential.activate({credentialID:se.id})},{success:t("settings.providers.accounts.toast.switched",{account:se.label}),failure:t("settings.providers.accounts.toast.switchFailed")}),et=(se,We)=>de(se,async()=>{await Ts.getSdkClient().credential.update({credentialID:se.id,label:We})},{failure:t("settings.providers.accounts.toast.renameFailed")}),ze=se=>de(se,async()=>{await Ts.getSdkClient().credential.remove({credentialID:se.id}),Le()},{success:t("settings.providers.accounts.toast.removed"),failure:t("settings.providers.accounts.toast.removeFailed")}),Ze=()=>h(""),tt=s.jsx(tl,{label:t("settings.providers.page.back"),onClick:Ze}),lt=se=>{if(n.some(We=>We.id===se)){h(se);return}W(se),h(On)};if(p===_a)return s.jsx(Eb,{titleLeading:tt,onOpenProvider:lt});if(ae&&!oe)return s.jsxs(ns,{title:t("settings.providers.page.connect.title"),titleLeading:tt,showSaveStatus:!1,children:[s.jsx(He,{title:t("settings.providers.page.connect.selectProviderTitle"),divider:!1,settingsItem:"providers.connect",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),y?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):K?s.jsx("p",{className:"typography-meta text-muted-foreground",children:K}):s.jsxs(Jn,{open:$,onOpenChange:se=>{Z(se),se||z("")},children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{type:"button",className:Zs,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[G&&G!==ra?s.jsx($n,{providerId:G,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:Se("truncate typography-ui-label font-normal",G?"text-foreground":"text-muted-foreground"),children:G===ra?t("settings.providers.page.custom.optionLabel"):G?Ke.find(se=>se.id===G)?.name||G:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Gn,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:se=>se.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:se=>se.stopPropagation(),children:[s.jsx(B,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:q,onChange:se=>z(se.target.value),onKeyDown:se=>se.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Ds,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const se=t("settings.providers.page.custom.optionLabel"),We=po([se,"other","custom"],q),ut=sa(Ke,q,Ce=>[Ce.name||Ce.id,Ce.id]);return ut.length===0&&!We?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):s.jsxs(s.Fragment,{children:[ut.map(Ce=>s.jsxs(xn,{onSelect:()=>{W(Ce.id),Z(!1),z("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx($n,{providerId:Ce.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Ce.name||Ce.id})]}),G===Ce.id&&s.jsx(B,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Ce.id)),We?s.jsxs(xn,{onSelect:()=>{W(ra),Z(!1),z("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(B,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:se})]}),G===ra&&s.jsx(B,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ra):null]})})()})]})]})]})}),ie?s.jsx(jc,{mode:"create",existingProviderIDs:Ee,busy:x?.startsWith("custom:")??!1,authFailureHint:Te,onCancel:()=>{W(""),Oe(null),xe(null)},onDisconnect:Te&&pe?()=>{rt(pe)}:void 0,onSubmit:wt}):G?s.jsx(He,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:N?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const se=Kn(u??[],G),We=uc(Kn(u??[],gi(G))),ut=mc(se);return s.jsxs(s.Fragment,{children:[ut?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Gt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(Ge,{type:"password",value:S[G]??"",onChange:Ce=>A(qe=>({...qe,[G]:Ce.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:()=>vt(G),disabled:x===`api:${G}`,children:x===`api:${G}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,We.length>0?s.jsx(wr,{integrationId:gi(G),methods:We,onConnected:()=>yt(G),className:Se(ut&&"border-t border-[var(--surface-subtle)] pt-2")},G):null]})})()})}):null]});if(!Ye)return s.jsx(jb,{providers:n,integrations:u,directory:a,onSelect:h,onConnect:()=>h(On),onOpenClassification:()=>h(_a)});const Q=Array.isArray(Ye.models)?Ye.models:[],nt=Kn(u??[],Ye.id),ot=uc(Kn(u??[],gi(Ye.id))),it=mc(nt),ft=u!==null,bt=!!pt,ht=bt&&bc(Ye,pt),Nt=gc({connections:eo(u??[],Ye.id),optionsApiKey:Pr(Ye)}),At=ob(ft,Nt,ht),$e=db({modelCount:Q.length,integrationsLoaded:ft,hasCredentials:Nt,isEditableCustomProvider:ht}),Xe=eo(u??[],Ye.id)??[],mt=Ye.integrationID??Ye.id,Fe=pc(Kn(u??[],mt)),J=Fe[0]?.id??null,ye=new Set(Xe.flatMap(se=>se.type==="credential"&&!Fe.some(We=>We.id===se.id)?[se.id]:[])),Ae=[pt?.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,pt?.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,pt?.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(se=>se!==null),Y=s.jsxs("span",{className:"flex items-center gap-2",children:[tt,s.jsx($n,{providerId:Ye.id,className:"h-5 w-5 shrink-0"})]}),Pe=s.jsxs("span",{className:"typography-settings-description text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:Ye.id}),Ae.length>0?s.jsxs(s.Fragment,{children:[" · ",t("settings.providers.page.configuredIn",{sources:Ae.join(", ")})]}):null]}),Je=sa(Q,D,se=>[typeof se?.name=="string"?se.name:"",typeof se?.id=="string"?se.id:""]);return ge&&ht&&ve?s.jsx(ns,{title:Ye.name||Ye.id,titleLeading:Y,description:Pe,showSaveStatus:!1,children:s.jsx(jc,{mode:"edit",existingProviderIDs:Ee,initialValues:ve,allowExistingAuth:Nt||!bt,busy:x?.startsWith("custom:")??!1,authFailureHint:Te,onCancel:()=>{Ie(null),Re(null),me(null),Oe(null),xe(null)},onDisconnect:()=>{rt(Ye.id)},onSubmit:wt})}):s.jsxs(ns,{title:Ye.name||Ye.id,titleLeading:Y,description:Pe,showSaveStatus:!1,children:[s.jsxs(He,{title:t("settings.providers.accounts.title"),info:t("settings.providers.accounts.info"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[ht&&!oe?s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Oe(null),Re(Wb(Ye,X[Ye.id]??null)),me(vc(pt)),Ie(Ye.id)},children:t("settings.providers.page.actions.edit")}):null,oe?null:s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const se=!be;De(se),ce(se?null:Ye.id)},children:be?t("settings.providers.page.actions.cancel"):s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"add",className:"size-3.5"}),Xe.length>0?t("settings.providers.accounts.add"):t("settings.providers.page.actions.connect")]})})]}),settingsItem:"providers.auth",contentClassName:"space-y-4",children:[Xe.length>0?s.jsx(Ob,{connections:Xe,activeId:J,unusedIds:ye,busyId:M,onActivate:se=>{Ue(se)},onRename:(se,We)=>{et(se,We)},onRemove:se=>{ze(se)}}):!be&&At?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(B,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),it?s.jsx(Gt,{children:t("settings.providers.page.auth.incompleteHint")}):null]}):null,oe?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.enterpriseMode")}):null,!be||oe?null:N?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:Se("space-y-4",Xe.length>0&&"rounded-xl border border-[var(--interactive-border)] p-4"),children:[it?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Gt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(Ge,{type:"password",value:S[Ye.id]??"",onChange:se=>A(We=>({...We,[Ye.id]:se.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:()=>vt(Ye.id),disabled:x===`api:${Ye.id}`,children:x===`api:${Ye.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ot.length>0&&s.jsx(wr,{integrationId:gi(Ye.id),methods:ot,onConnected:()=>yt(Ye.id),className:Se(it&&"border-t border-[var(--surface-subtle)] pt-2")},Ye.id)]})]}),$e?s.jsxs(He,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",Q.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const se=Q.map(We=>typeof We?.id=="string"?We.id:"").filter(We=>We.length>0);C(Ye.id,se)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>b(Ye.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(B,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Ge,{value:D,onChange:se=>R(se.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Je.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Je.map(se=>{const We=typeof se?.id=="string"?se.id:"",ut=typeof se?.name=="string"?se.name:We,Ce=We?f(Ye.id,We):void 0,qe=m.some(Ft=>Ft.providerID===Ye.id&&Ft.modelID===We),jt=kc(Ce?.limit?.context),Ot=kc(Ce?.limit?.output),Yt=[jt?`${jt} ${t("settings.providers.page.models.tokenBadge.context")}`:null,Ot?`${Ot} ${t("settings.providers.page.models.tokenBadge.output")}`:null].filter(Boolean).join(" · "),Zt=[];return Ce?.tool_call&&Zt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ce?.reasoning&&Zt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ce?.attachment&&Zt.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:Se("flex items-center gap-3",qe&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ut}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e?Yt||Zt.length>0?s.jsx(Gt,{className:"h-6 w-6",children:s.jsxs("div",{className:"space-y-1.5",children:[Yt?s.jsx("div",{className:"font-medium",children:Yt}):null,Zt.map(({key:Ft,icon:ps,label:gs})=>s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(B,{name:ps,className:"h-3.5 w-3.5"}),gs]},Ft))]})}):null:s.jsxs(s.Fragment,{children:[Yt?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:Yt}):null,Zt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Zt.map(({key:Ft,icon:ps,label:gs})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:gs,"aria-label":gs,children:s.jsx(B,{name:ps,className:"h-3 w-3"})},Ft))})]}),s.jsx("button",{type:"button",onClick:()=>v(Ye.id,We),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(qe?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(qe?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:qe?s.jsx(B,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(B,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},We)})})]}):null]})},dv=t=>{const e=t?.windows??{},a=Object.values(e).map(n=>n.usedPercent).filter(n=>typeof n=="number");return a.length===0?null:Math.max(...a)},uv=t=>{const e=_e.c(75),{onItemSelect:a}=t,{t:n}=Be(),i=ds(mv),o=ds(pv),r=ds(gv),d=ds(fv),c=ds(hv),g=ds(xv),p=ds(bv),h=ds(vv);let f,m;e[0]!==h?(f=()=>{h()},m=[h],e[0]=h,e[1]=f,e[2]=m):(f=e[1],m=e[2]),l.useEffect(f,m);const v=yv;let C;e[3]!==p?(C=te=>{te!=="usage"&&te!=="remaining"||(p(te),v({usageDisplayMode:te}))},e[3]=p,e[4]=C):C=e[4];const b=C;let k;e[5]===Symbol.for("react.memo_cache_sentinel")?(k=Se("flex h-full flex-col","bg-background"),e[5]=k):k=e[5];let u;e[6]!==n?(u=n("settings.usage.sidebar.title"),e[6]=n,e[7]=u):u=e[7];let j;e[8]!==u?(j=s.jsx("h2",{className:`${va} mb-3`,children:u}),e[8]=u,e[9]=j):j=e[9];let N;e[10]!==n?(N=n("settings.usage.sidebar.total",{count:so.length}),e[10]=n,e[11]=N):N=e[11];let w;e[12]!==N?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[12]=N,e[13]=w):w=e[13];let S;e[14]!==d?(S=()=>d(),e[14]=d,e[15]=S):S=e[15];let A;e[16]!==n?(A=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=A):A=e[17];let x;e[18]!==n?(x=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=x):x=e[19];const E=c&&"animate-spin";let M;e[20]!==E?(M=Se("h-3.5 w-3.5",E),e[20]=E,e[21]=M):M=e[21];let T;e[22]!==M?(T=s.jsx(B,{name:"refresh",className:M}),e[22]=M,e[23]=T):T=e[23];let D;e[24]!==c||e[25]!==A||e[26]!==x||e[27]!==T||e[28]!==S?(D=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:S,"aria-label":A,title:x,disabled:c,children:T})}),e[24]=c,e[25]=A,e[26]=x,e[27]=T,e[28]=S,e[29]=D):D=e[29];let R;e[30]!==D||e[31]!==w?(R=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,D]}),e[30]=D,e[31]=w,e[32]=R):R=e[32];let O;e[33]!==n?(O=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=O):O=e[34];let I;e[35]!==O?(I=s.jsx("span",{className:"typography-micro text-muted-foreground",children:O}),e[35]=O,e[36]=I):I=e[36];let y;e[37]!==n?(y=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=y):y=e[38];let L;e[39]!==y?(L=s.jsx(Tt,{className:"w-fit",children:s.jsx(Jt,{placeholder:y})}),e[39]=y,e[40]=L):L=e[40];let K;e[41]!==n?(K=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=K):K=e[42];let H;e[43]!==K?(H=s.jsx(gt,{value:"usage",children:K}),e[43]=K,e[44]=H):H=e[44];let G;e[45]!==n?(G=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=G):G=e[46];let W;e[47]!==G?(W=s.jsx(gt,{value:"remaining",children:G}),e[47]=G,e[48]=W):W=e[48];let q;e[49]!==H||e[50]!==W?(q=s.jsxs(Et,{children:[H,W]}),e[49]=H,e[50]=W,e[51]=q):q=e[51];let z;e[52]!==b||e[53]!==L||e[54]!==q||e[55]!==g?(z=s.jsxs(Dt,{value:g,onValueChange:b,children:[L,q]}),e[52]=b,e[53]=L,e[54]=q,e[55]=g,e[56]=z):z=e[56];let $;e[57]!==I||e[58]!==z?($=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[I,z]}),e[57]=I,e[58]=z,e[59]=$):$=e[59];let Z;e[60]!==R||e[61]!==$||e[62]!==j?(Z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[j,R,$]}),e[60]=R,e[61]=$,e[62]=j,e[63]=Z):Z=e[63];let _;e[64]!==a||e[65]!==i||e[66]!==o||e[67]!==r||e[68]!==n?(_=so.map(te=>{const he=i.find(oe=>oe.providerId===te.id),je=dv(he?.usage),fe=od(je),ke=te.id===o,be=he?.configured,De=be?fe==="critical"?{backgroundColor:"var(--status-error)"}:fe==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:Se("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ke?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{r(te.id),a?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:De}),s.jsx($n,{providerId:te.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:te.name}),be===!1&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},te.id)}),e[64]=a,e[65]=i,e[66]=o,e[67]=r,e[68]=n,e[69]=_):_=e[69];let ne;e[70]!==_?(ne=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:_}),e[70]=_,e[71]=ne):ne=e[71];let X;return e[72]!==Z||e[73]!==ne?(X=s.jsxs("div",{className:k,children:[Z,ne]}),e[72]=Z,e[73]=ne,e[74]=X):X=e[74],X};function mv(t){return t.results}function pv(t){return t.selectedProviderId}function gv(t){return t.setSelectedProvider}function fv(t){return t.fetchAllQuotas}function hv(t){return t.isLoading}function xv(t){return t.displayMode}function bv(t){return t.setDisplayMode}function vv(t){return t.loadSettings}async function yv(t){try{await kt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const jv=t=>{const e=_e.c(17),{percent:a,tonePercent:n,className:i}=t;let o;e[0]!==a?(o=Uu(a)??0,e[0]=a,e[1]=o):o=e[1];const r=o,d=n??a;let c;e[2]!==d?(c=od(d),e[2]=d,e[3]=c):c=e[3];const g=c;let p;e[4]!==g?(p=g==="critical"?{backgroundColor:"var(--status-error)"}:g==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=g,e[5]=p):p=e[5];const h=p;let f;e[6]!==i?(f=Se("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=f):f=e[7];const m=`${r}%`;let v;e[8]!==h||e[9]!==m?(v={...h,width:m},e[8]=h,e[9]=m,e[10]=v):v=e[10];let C;e[11]!==r||e[12]!==v?(C=s.jsx("div",{className:"h-full transition-all duration-300",style:v,role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100}),e[11]=r,e[12]=v,e[13]=C):C=e[13];let b;return e[14]!==f||e[15]!==C?(b=s.jsx("div",{className:f,children:C}),e[14]=f,e[15]=C,e[16]=b):b=e[16],b},er=t=>{const e=_e.c(37),{title:a,window:n,subtitle:i,showToggle:o,toggleEnabled:r,onToggle:d}=t,c=o===void 0?!1:o,g=r===void 0?!1:r,p=ds(kv),h=re(wv),f=p==="remaining"?n.remainingPercent:n.usedPercent,m=f!==null,v=p==="remaining"?"remaining":"used";let C;e[0]!==f||e[1]!==n.valueLabel?(C=_u(n.valueLabel,f),e[0]=f,e[1]=n.valueLabel,e[2]=C):C=e[2];const b=C,k=n.resetAfterFormatted??n.resetAtFormatted;let u;e[3]!==k||e[4]!==h||e[5]!==n.resetAt?(u=$u(n.resetAt,k,h),e[3]=k,e[4]=h,e[5]=n.resetAt,e[6]=u):u=e[6];const j=u,N=j?`Resets ${j}`:"";let w;e[7]!==a?(w=Bu(a),e[7]=a,e[8]=w):w=e[8];const S=w;let A;e[9]!==d||e[10]!==c||e[11]!==g?(A=c&&s.jsx(gr,{checked:g,onChange:L=>d?.(L),ariaLabel:"Show in dropdown"}),e[9]=d,e[10]=c,e[11]=g,e[12]=A):A=e[12];let x;e[13]!==S?(x=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:S}),e[13]=S,e[14]=x):x=e[14];let E;e[15]!==i?(E=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=E):E=e[16];let M;e[17]!==x||e[18]!==E?(M=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[x,E]}),e[17]=x,e[18]=E,e[19]=M):M=e[19];let T;e[20]!==M||e[21]!==A?(T=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[A,M]}),e[20]=M,e[21]=A,e[22]=T):T=e[22];const D=b==="-"?"":b;let R;e[23]!==D?(R=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:D}),e[23]=D,e[24]=R):R=e[24];let O;e[25]!==T||e[26]!==R?(O=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[T,R]}),e[25]=T,e[26]=R,e[27]=O):O=e[27];let I;e[28]!==v||e[29]!==f||e[30]!==m||e[31]!==N||e[32]!==n.usedPercent?(I=m?s.jsxs("div",{className:"mt-2.5",children:[s.jsx(jv,{percent:f,tonePercent:n.usedPercent,className:"h-1.5"}),s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:N}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:v})]})]}):N?s.jsx("div",{className:"mt-1 typography-micro text-muted-foreground",children:N}):null,e[28]=v,e[29]=f,e[30]=m,e[31]=N,e[32]=n.usedPercent,e[33]=I):I=e[33];let y;return e[34]!==O||e[35]!==I?(y=s.jsxs("div",{className:"py-3",children:[O,I]}),e[34]=O,e[35]=I,e[36]=y):y=e[36],y};function kv(t){return t.displayMode}function wv(t){return t.timeFormatPreference}const Sv=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,Nv=({providerId:t,providerName:e})=>{const{t:a}=Be(),[n,i]=l.useState(null),[o,r]=l.useState({}),[d,c]=l.useState(!1),g=`/api/quota/credentials/${t}`;l.useEffect(()=>{It(g).then(async f=>{if(!f.ok)throw new Error;const m=await f.json();i(m),r({})}).catch(()=>i({configured:!1}))},[g]);const p=async(f,m,v)=>{c(!0);try{const C=await It(f,{method:m,headers:v?{"Content-Type":"application/json"}:void 0,body:v?JSON.stringify(v):void 0}),b=await C.json().catch(()=>null);if(!C.ok)throw new Error(b?.error);b?.configured!==void 0&&i(b),r({}),U.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(C){U.error(C instanceof Error&&C.message?C.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},h=(f,m,v)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[m,s.jsx(Ge,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:o[f]??"",onChange:C=>r(b=>({...b,[f]:C.target.value})),placeholder:n?.secretMasked??v})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="exe-dev"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.exeDevTokenInstructions")}),s.jsx("code",{className:"typography-code block whitespace-pre-wrap break-all rounded bg-muted/50 px-2 py-1.5 text-xs text-foreground",children:Sv})]}),t==="ollama-cloud"&&h("cookie",a("settings.providers.page.openCodeGo.authCookie"),"aid=...; __Secure-session=..."),t==="exe-dev"&&h("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&h("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&h("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(V,{size:"xs",disabled:d,onClick:()=>p(g,"PUT",o),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(V,{variant:"outline",size:"xs",disabled:d,onClick:()=>p(`${g}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(V,{variant:"outline",size:"xs",disabled:d,onClick:()=>p(`${g}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(V,{variant:"destructive",size:"xs",disabled:d,onClick:()=>p(g,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},wc=(t,e)=>{if(!t)return"-";try{return rd(t,e,{fallback:"-"})}catch{return"-"}},Cv=()=>{const{t}=Be(),e=re(y=>y.timeFormatPreference),a=ds(y=>y.results),n=ds(y=>y.selectedProviderId),i=ds(y=>y.setSelectedProvider),o=ds(y=>y.loadSettings),r=ds(y=>y.fetchAllQuotas),d=ds(y=>y.isLoading),c=ds(y=>y.lastUpdated),g=ds(y=>y.refreshErrors),p=ds(y=>y.dropdownProviderIds),h=ds(y=>y.setDropdownProviderIds),f=ds(y=>y.selectedModels),m=ds(y=>y.toggleModelSelected),v=ds(y=>y.applyDefaultSelections);Vu(),l.useEffect(()=>{o(),r()},[o,r]),l.useEffect(()=>{if(n||a.length===0)return;const y=a.find(L=>L.configured)?.providerId;i(y??so[0]?.id??null)},[a,n,i]);const C=a.find(y=>y.providerId===n)??null,k=so.find(y=>y.id===n)?.name??n??t("settings.usage.sidebar.title"),u=C?.usage,j=n?g[n]:void 0,N=j?u?t("header.services.usageRefreshFailedStale",{error:j}):j:C?.configured&&!C.ok?C.error:null,w=n?p.includes(n):!1,S=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",A=l.useCallback(y=>{if(!n)return;const L=y?Array.from(new Set([...p,n])):p.filter(K=>K!==n);h(L),kt({usageDropdownProviders:L})},[p,n,h]),x=l.useMemo(()=>u?.models?Object.entries(u.models).map(([y,L])=>({name:y,windows:L})).filter(y=>Object.keys(y.windows.windows).length>0):[],[u?.models]);l.useEffect(()=>{n&&x.length>0&&v(n,x.map(y=>y.name))},[n,x,v]);const E=l.useMemo(()=>!n||x.length===0?new Map:Hu(x,y=>y.name,n),[x,n]),M=l.useMemo(()=>{if(!n)return[];const y=Gu(n);return qu(y)},[n]),[T,D]=l.useState(()=>({})),R=l.useCallback(y=>{D(L=>({...L,[y]:!L[y]}))},[]),O=l.useCallback(y=>{if(!n)return;m(n,y);const L=f[n]??[],H=L.includes(y)?L.filter(W=>W!==y):[...L,y],G={...f,[n]:H};kt({usageSelectedModels:G})},[n,f,m]),I=n?f[n]??[]:[];return n?s.jsxs(ns,{title:t("settings.usage.page.header.providerUsage",{provider:k}),titleLeading:s.jsx($n,{providerId:n,className:"h-5 w-5 shrink-0"}),description:d?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):C?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:C.planLabel,time:wc(c,e)}):t("settings.usage.page.header.lastUpdated",{time:wc(c,e)}),showSaveStatus:!0,children:[s.jsx(He,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(xt,{checked:w,onChange:A,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!C&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),N&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:N})]}),C&&!C.configured&&!S&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="exe-dev"||n==="ollama-cloud"||n==="cursor")&&s.jsx(Nv,{providerId:n,providerName:k}),u?.windows&&Object.keys(u.windows).length>0&&s.jsx(He,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(u.windows).map(([y,L])=>s.jsx(er,{title:y,window:L},y))})}),x.length>0&&s.jsxs(He,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[M.map(y=>{const L=E.get(y.id)??[];if(L.length===0)return null;const K=T[y.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(bn,{open:!K,onOpenChange:()=>R(y.id),children:[s.jsxs(vn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:y.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",L.length,")"]})]}),K?s.jsx(B,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(yn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:L.map(H=>{const G=Object.entries(H.windows.windows);if(G.length===0)return null;const[W,q]=G[0],z=I.includes(H.name);return s.jsx(er,{title:W,subtitle:xl(H.name),window:q,showToggle:!0,toggleEnabled:z,onToggle:()=>O(H.name)},H.name)})})})]})},y.id)}),(()=>{const y=E.get(null)??[];if(y.length===0)return null;const L=T.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(bn,{open:!L,onOpenChange:()=>R("other"),children:[s.jsxs(vn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",y.length,")"]})]}),L?s.jsx(B,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(yn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:y.map(K=>{const H=Object.entries(K.windows.windows);if(H.length===0)return null;const[G,W]=H[0],q=I.includes(K.name);return s.jsx(er,{title:G,subtitle:xl(K.name),window:W,showToggle:!0,toggleEnabled:q,onToggle:()=>O(K.name)},K.name)})})})]})})})()]}),C?.configured&&u&&Object.keys(u.windows??{}).length===0&&x.length===0&&s.jsxs("div",{className:"pb-8",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},Iv="git.commit.generate",Ar=Pp(t=>({selectedPromptId:Iv,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Pv=t=>{const e=_e.c(24),{onItemSelect:a}=t,{t:n}=Be(),i=Ar(Av),o=Ar(Tv);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=r):r=e[0];let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=d):d=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=c):c=e[2];let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[3]=g):g=e[3];let p;e[4]===Symbol.for("react.memo_cache_sentinel")?(p=[r,d,c,g,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[4]=p):p=e[4];const h=p;let f;e[5]!==n?(f=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=f):f=e[6];let m;e[7]!==f?(m=s.jsx("h2",{className:va,children:f}),e[7]=f,e[8]=m):m=e[8];let v;e[9]!==n?(v=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=v):v=e[10];let C;e[11]!==v?(C=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:v}),e[11]=v,e[12]=C):C=e[12];let b;e[13]!==m||e[14]!==C?(b=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[m,C]}),e[13]=m,e[14]=C,e[15]=b):b=e[15];let k;e[16]!==a||e[17]!==i||e[18]!==o||e[19]!==n?(k=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:h.map(j=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(j.groupKey)}),j.items.map(N=>{const w=i===N.id;return s.jsx("button",{type:"button",onClick:()=>{o(N.id),a?.()},className:Se("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",w?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(N.titleKey)})},N.id)})]},j.groupKey))}),e[16]=a,e[17]=i,e[18]=o,e[19]=n,e[20]=k):k=e[20];let u;return e[21]!==b||e[22]!==k?(u=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[b,k]}),e[21]=b,e[22]=k,e[23]=u):u=e[23],u};function Av(t){return t.selectedPromptId}function Tv(t){return t.setSelectedPromptId}const Sc={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"},{id:"session.fusion.codeInstructions",titleKey:"settings.magicPrompts.page.block.codeFusionInstructions"}]}},Nc=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),tr=t=>t.endsWith(".visible"),Ev=()=>{const{t}=Be(),e=l.useCallback(S=>t(S),[t]),a=Ar(S=>S.selectedPromptId),[n,i]=l.useState(!0),[o,r]=l.useState({}),[d,c]=l.useState({}),[g,p]=l.useState({}),[h,f]=l.useState({}),[m,v]=l.useState(!1);l.useEffect(()=>{let S=!0;return(async()=>{i(!0);try{const x=await Yu();if(!S)return;r(x)}catch(x){console.warn("Failed to load magic prompts:",x),U.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{S&&i(!1)}})(),()=>{S=!1}},[t]);const C=Sc[a]??Sc["git.commit.generate"],b=l.useCallback(S=>Nc(o,S)?o[S]:zo(S),[o]),k=l.useCallback(S=>d[S]??b(S),[d,b]),u=l.useCallback((S,A)=>{c(x=>x[S]===A?x:{...x,[S]:A})},[]),j=l.useCallback(async S=>{const A=k(S);if(tr(S)&&A.trim().length===0){U.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}p(x=>({...x,[S]:!0}));try{const x=A===zo(S)?await bl(S):await Wu(S,A);r(x.overrides),U.success(t("settings.magicPrompts.page.toast.saved"))}catch(x){const E=x instanceof Error?x.message:String(x);U.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:E})}finally{p(x=>({...x,[S]:!1}))}},[k,t]),N=l.useCallback(async S=>{f(A=>({...A,[S]:!0}));try{const A=await bl(S);r(A.overrides),c(x=>({...x,[S]:zo(S)})),U.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(A){const x=A instanceof Error?A.message:String(A);U.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:x})}finally{f(A=>({...A,[S]:!1}))}},[t]),w=l.useCallback(async()=>{v(!0);try{const S=await Ju();r(S.overrides),c({}),U.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(S){const A=S instanceof Error?S.message:String(S);U.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:A})}finally{v(!1)}},[t]);return n?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx(ns,{title:e(C.titleKey),titleAccessory:s.jsx(Gt,{contentClassName:"max-w-xs",children:e(C.descriptionKey)}),headerEnd:s.jsx(V,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{w()},disabled:m||Object.keys(o).length===0,children:t(m?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:C.blocks.map((S,A)=>{const x=Qu(S.id),E=b(S.id),M=k(S.id),T=Nc(o,S.id),D=M!==E,R=tr(S.id)&&M.trim().length===0,O=g[S.id]===!0,I=h[S.id]===!0;return s.jsxs(He,{title:e(S.titleKey),info:x.description,description:x.placeholders&&x.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${x.placeholders.map(y=>`{{${y.key}}}`).join(", ")}`:void 0,divider:A>0,settingsItem:tr(S.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Rs,{value:M,onChange:y=>u(S.id,y.target.value),className:"min-h-[220px] font-mono text-sm"}),R&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(D?"settings.magicPrompts.page.status.unsavedChanges":T?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{variant:"outline",size:"sm",onClick:()=>{N(S.id)},disabled:!T||O||I,children:t(I?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(V,{size:"sm",onClick:()=>{j(S.id)},disabled:!D||O||I||R,children:t(O?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},S.id)})})},Dv=t=>{const e=_e.c(89),{onItemSelect:a}=t,{t:n}=Be(),[i,o]=l.useState(null),[r,d]=l.useState(null),[c,g]=l.useState(null),{selectedSnippetName:p,snippets:h,setSelectedSnippet:f,setSnippetDraft:m,deleteSnippet:v,loadSnippets:C}=no($s(Mv));let b,k;e[0]!==C?(b=()=>{C()},k=[C],e[0]=C,e[1]=b,e[2]=k):(b=e[1],k=e[2]),l.useEffect(b,k);let u;e[3]!==a||e[4]!==f||e[5]!==m||e[6]!==h?(u=async()=>{const ee=new Set(h.map(Rv));let ce="new-snippet",ue=1;for(;ee.has(ce);)ce=`new-snippet-${ue++}`;m({name:ce,scope:"global"}),f(ce),a?.()},e[3]=a,e[4]=f,e[5]=m,e[6]=h,e[7]=u):u=e[7];const j=u;let N;e[8]!==i||e[9]!==v||e[10]!==n?(N=async()=>{if(!i)return;await v(i.name)?(U.success(n("settings.snippets.sidebar.toast.deleted")),o(null)):U.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=v,e[10]=n,e[11]=N):N=e[11];const w=N;let S;e[12]!==h?(S=[...h].sort(Ov),e[12]=h,e[13]=S):S=e[13];const A=S;let x;e[14]===Symbol.for("react.memo_cache_sentinel")?(x=Se("flex h-full flex-col","bg-background"),e[14]=x):x=e[14];let E;e[15]!==n?(E=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=E):E=e[16];let M;e[17]!==E?(M=s.jsx("h2",{className:`${va} mb-3`,children:E}),e[17]=E,e[18]=M):M=e[18];let T;e[19]!==h.length||e[20]!==n?(T=n("settings.snippets.sidebar.total",{count:h.length}),e[19]=h.length,e[20]=n,e[21]=T):T=e[21];let D;e[22]!==T?(D=s.jsx("span",{className:"typography-meta text-muted-foreground",children:T}),e[22]=T,e[23]=D):D=e[23];let R;e[24]!==n?(R=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=R):R=e[25];let O;e[26]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),e[26]=O):O=e[26];let I;e[27]!==j||e[28]!==R?(I=s.jsx(V,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,"aria-label":R,children:O}),e[27]=j,e[28]=R,e[29]=I):I=e[29];let y;e[30]!==D||e[31]!==I?(y=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,I]}),e[30]=D,e[31]=I,e[32]=y):y=e[32];let L;e[33]!==y||e[34]!==M?(L=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[M,y]}),e[33]=y,e[34]=M,e[35]=L):L=e[35];let K;if(e[36]!==a||e[37]!==r||e[38]!==c||e[39]!==p||e[40]!==f||e[41]!==A||e[42]!==n){let ee;e[44]!==a||e[45]!==r||e[46]!==c||e[47]!==p||e[48]!==f||e[49]!==n?(ee=ce=>s.jsxs(ei,{open:c===ce.name,onOpenChange:ue=>g(ue?ce.name:null),children:[s.jsxs(Xa,{render:s.jsx("div",{className:Se("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",p===ce.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:ue=>{ue.preventDefault(),g(ce.name)}}),children:[s.jsxs("button",{onClick:()=>{f(ce.name),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",ce.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n(`snippets.source.${ce.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:ce.description||ce.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(Jn,{open:r===ce.name,onOpenChange:ue=>{ue&&g(null),d(ue?ce.name:null)},children:[s.jsx(Wn,{asChild:!0,children:s.jsx(V,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":n("settings.snippets.sidebar.actions.more",{name:ce.name}),children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Gn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(xn,{onClick:ue=>{ue.stopPropagation(),o(ce)},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Ya,{className:"w-fit min-w-20",children:s.jsxs(Za,{onClick:ue=>{ue.stopPropagation(),o(ce)},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${ce.source}:${ce.filePath}`),e[44]=a,e[45]=r,e[46]=c,e[47]=p,e[48]=f,e[49]=n,e[50]=ee):ee=e[50],K=A.map(ee),e[36]=a,e[37]=r,e[38]=c,e[39]=p,e[40]=f,e[41]=A,e[42]=n,e[43]=K}else K=e[43];let H;e[51]!==K?(H=s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:K}),e[51]=K,e[52]=H):H=e[52];const G=i!==null;let W;e[53]===Symbol.for("react.memo_cache_sentinel")?(W=ee=>{ee||o(null)},e[53]=W):W=e[53];let q;e[54]!==n?(q=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=q):q=e[55];let z;e[56]!==q?(z=s.jsx(Ht,{children:q}),e[56]=q,e[57]=z):z=e[57];const $=i?.name??"";let Z;e[58]!==n||e[59]!==$?(Z=n("settings.snippets.sidebar.dialog.deleteDescription",{name:$}),e[58]=n,e[59]=$,e[60]=Z):Z=e[60];let _;e[61]!==Z?(_=s.jsx(qt,{children:Z}),e[61]=Z,e[62]=_):_=e[62];let ne;e[63]!==z||e[64]!==_?(ne=s.jsxs(Vt,{children:[z,_]}),e[63]=z,e[64]=_,e[65]=ne):ne=e[65];let X;e[66]===Symbol.for("react.memo_cache_sentinel")?(X=()=>o(null),e[66]=X):X=e[66];let te;e[67]!==n?(te=n("settings.common.actions.cancel"),e[67]=n,e[68]=te):te=e[68];let he;e[69]!==te?(he=s.jsx(V,{size:"sm",variant:"ghost",onClick:X,children:te}),e[69]=te,e[70]=he):he=e[70];let je;e[71]!==n?(je=n("settings.common.actions.delete"),e[71]=n,e[72]=je):je=e[72];let fe;e[73]!==w||e[74]!==je?(fe=s.jsx(V,{size:"sm",onClick:w,children:je}),e[73]=w,e[74]=je,e[75]=fe):fe=e[75];let ke;e[76]!==he||e[77]!==fe?(ke=s.jsxs(as,{children:[he,fe]}),e[76]=he,e[77]=fe,e[78]=ke):ke=e[78];let be;e[79]!==ne||e[80]!==ke?(be=s.jsxs($t,{className:"max-w-md",children:[ne,ke]}),e[79]=ne,e[80]=ke,e[81]=be):be=e[81];let De;e[82]!==G||e[83]!==be?(De=s.jsx(_t,{open:G,onOpenChange:W,children:be}),e[82]=G,e[83]=be,e[84]=De):De=e[84];let oe;return e[85]!==L||e[86]!==H||e[87]!==De?(oe=s.jsxs("div",{className:x,children:[L,H,De]}),e[85]=L,e[86]=H,e[87]=De,e[88]=oe):oe=e[88],oe};function Mv(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function Rv(t){return t.name}function Ov(t,e){return t.name.localeCompare(e.name)}const Lv=()=>{const{t}=Be(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:o,createSnippet:r}=no($s(x=>({selectedSnippetName:x.selectedSnippetName,snippets:x.snippets,snippetDraft:x.snippetDraft,setSnippetDraft:x.setSnippetDraft,updateSnippet:x.updateSnippet,createSnippet:x.createSnippet}))),d=l.useMemo(()=>e?a.find(x=>x.name===e||x.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!d),[g,p]=l.useState(""),[h,f]=l.useState("global"),[m,v]=l.useState(""),[C,b]=l.useState(""),[k,u]=l.useState(""),[j,N]=l.useState(!1),w=l.useRef(null);l.useEffect(()=>{if(c&&n){const x={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};p(x.draftName),f(x.draftScope),v(x.description),b(x.aliases),u(x.content),w.current=x}else if(d){const x={draftName:"",draftScope:"global",description:d.description??"",aliases:d.aliases.join(", "),content:d.content};v(x.description),b(x.aliases),u(x.content),w.current=x}},[d,c,e,n]);const S=l.useMemo(()=>{const x=w.current;return x?c&&g!==x.draftName||c&&h!==x.draftScope?!0:m!==x.description||C!==x.aliases||k!==x.content:!1},[C,k,m,g,h,c]),A=async()=>{const x=c?g.trim().replace(/\s+/g,"-"):e?.trim();if(!x){U.error(t("settings.snippets.page.toast.nameRequired"));return}if(!k.trim()){U.error(t("settings.snippets.page.toast.contentRequired"));return}const E=C.split(",").map(M=>M.trim()).filter(Boolean);N(!0);try{if(!(c?await r(x,k,{aliases:E,description:m,scope:h}):await o(x,{content:k,aliases:E,description:m}))){U.error(t("settings.snippets.page.toast.saveFailed"));return}U.success(t("settings.snippets.page.toast.saved")),c&&i(null)}finally{N(!1)}};return e?s.jsxs(ns,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:d?d.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(He,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(Ct,{label:"#",children:[s.jsx(Ge,{value:g,onChange:x=>p(x.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Dt,{value:h,onValueChange:x=>f(x),children:[s.jsx(Tt,{size:Qt,className:"w-fit min-w-[100px]",children:s.jsx(Jt,{})}),s.jsxs(Et,{align:"end",children:[s.jsx(gt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(gt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Kt,{label:t("settings.common.field.description"),children:s.jsx(Ge,{value:m,onChange:x=>v(x.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Kt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(Ge,{value:C,onChange:x=>b(x.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(He,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Gt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Rs,{value:k,onChange:x=>u(x.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("div",{className:"pt-3",children:s.jsx(V,{onClick:A,disabled:j||!S,size:"xs",className:"!font-normal",children:t(j?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(B,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},Hd=()=>{const{t}=Be(),e=ct(h=>h.settingsGitmojiEnabled),a=ct(h=>h.setSettingsGitmojiEnabled),n=Qm(),i=re(h=>h.gitChangesViewMode),o=re(h=>h.setGitChangesViewMode),[r,d]=l.useState(!0),c=l.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);l.useEffect(()=>{(async()=>{try{const f=await En();f&&(f.gitmojiEnabled!==void 0&&a(f.gitmojiEnabled),f.gitChangesViewMode!==void 0&&o(f.gitChangesViewMode))}catch(f){console.warn("Failed to load git settings:",f)}finally{d(!1)}})()},[o,a]);const g=l.useCallback(async h=>{a(h);try{await kt({gitmojiEnabled:h})}catch(f){console.warn("Failed to save gitmoji setting:",f)}},[a]),p=l.useCallback(h=>{h!==i&&(o(h),kt({gitChangesViewMode:h}))},[i,o]);return r?null:s.jsx(He,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:ys,children:[s.jsx(Cs,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(Js,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(h=>s.jsx(rs,{selected:i===h.id,onSelect:()=>{p(h.id)},label:h.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:h.label})},h.id))})}),s.jsx(xt,{settingsItem:"git.gitmoji",checked:e,onChange:h=>{g(h)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(xt,{settingsItem:"git.gitignored-files",checked:n,onChange:Ym,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Cc=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],Fv=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],Kv=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=Be(),o=ma(_=>_.getProfileById),r=ma(_=>_.createProfile),d=ma(_=>_.updateProfile),c=ma(_=>_.deleteProfile),g=l.useMemo(()=>a&&a!=="new"&&!n?o(a):null,[a,o,n]),p=a==="new"||n!=null,h=a==="global",[f,m]=l.useState(""),[v,C]=l.useState(""),[b,k]=l.useState(""),[u,j]=l.useState("ssh"),[N,w]=l.useState(""),[S,A]=l.useState(!1),[x,E]=l.useState(""),[M,T]=l.useState(""),[D,R]=l.useState("keyword"),[O,I]=l.useState("branch"),[y,L]=l.useState(!1),[K,H]=l.useState(!1),[G,W]=l.useState(!1);l.useEffect(()=>{if(t){if(n){const _=n.host.split("/"),ne=_.length>=3?_[_.length-1]:n.host;m(ne),C(n.username),k(""),j("token"),w(""),A(!1),E(""),T(n.host),R("string"),I("code")}else if(p)m(""),C(""),k(""),j("ssh"),w(""),A(!1),E(""),T(""),R("keyword"),I("branch");else if(g)m(g.name),C(g.userName),k(g.userEmail),j(g.authType||"ssh"),w(g.sshKey||""),A(g.signCommits===!0),E(g.signingKey||""),T(g.host||""),R(g.color||"keyword"),I(g.icon||"branch");else if(h){const _=o("global");_&&(m(_.name),C(_.userName),k(_.userEmail),j(_.authType||"ssh"),w(_.sshKey||""),A(!1),E(""),T(_.host||""),R(_.color||"keyword"),I(_.icon||"branch"))}}},[t,a,g,p,n,h,o]);const q=async()=>{if(!v.trim()||!b.trim()){U.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(u==="token"&&!M.trim()){U.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(S&&!x.trim()){U.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}L(!0);try{const _={name:f.trim()||v.trim(),userName:v.trim(),userEmail:b.trim(),authType:u,sshKey:u==="ssh"&&N.trim()||null,signCommits:S,signingKey:x.trim()||null,host:u==="token"&&M.trim()||null,color:D,icon:O};let ne;if(p)ne=await r(_);else if(a)ne=await d(a,_);else return;ne?(U.success(i(p?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):U.error(i(p?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(_){console.error("Error saving profile:",_),U.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{L(!1)}},z=async()=>{if(!(!a||p)){W(!0);try{await c(a)?(U.success(i("settings.gitIdentities.editor.toast.profileDeleted")),H(!1),e(!1)):U.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(_){console.error("Error deleting profile:",_),U.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{W(!1)}}},$=l.useMemo(()=>Cc.find(ne=>ne.key===D)?.cssVar||"var(--syntax-keyword)",[D]),Z=n?i("settings.gitIdentities.editor.title.importCredential"):p?i("settings.gitIdentities.editor.title.newIdentity"):h?i("settings.gitIdentities.editor.title.globalIdentity"):g?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(_t,{open:t,onOpenChange:e,children:s.jsxs($t,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:Z}),s.jsx(qt,{children:i(h?"settings.gitIdentities.editor.description.globalReadOnly":p?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!h&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Pt} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Ge,{value:f,onChange:_=>m(_.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:Cc.map(_=>s.jsx("button",{type:"button",onClick:()=>R(_.key),className:Se("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",D===_.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:_.cssVar},title:_.label},_.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:Fv.map(_=>{const ne=_.Icon;return s.jsx("button",{type:"button",onClick:()=>I(_.key),className:Se("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",O===_.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:_.label,children:s.jsx(B,{name:ne,className:"w-3.5 h-3.5",style:{color:O===_.key?$:"var(--surface-muted-foreground)"}})},_.key)})})]})]}),!h&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Pt,children:i("settings.gitIdentities.editor.field.userName")}),!h&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Gt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(Ge,{value:v,onChange:_=>C(_.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!h,readOnly:h,disabled:h,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Pt,children:i("settings.gitIdentities.editor.field.emailAddress")}),!h&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Gt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(Ge,{type:"email",value:b,onChange:_=>k(_.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!h,readOnly:h,disabled:h,className:"h-8"})]})]}),!h&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(V,{size:"sm",type:"button",variant:"chip","aria-pressed":u==="ssh",onClick:()=>j("ssh"),children:[s.jsx(B,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(V,{size:"sm",type:"button",variant:"chip","aria-pressed":u==="token",onClick:()=>j("token"),children:[s.jsx(B,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),u==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Pt,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Gt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(Ge,{value:N,onChange:_=>w(_.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(xt,{checked:S,onChange:A,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Pt,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(Ge,{value:x,onChange:_=>E(_.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!S,className:"h-8 font-mono text-xs"})]})]}),u==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Pt,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Gt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(Ge,{value:M,onChange:_=>T(_.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(as,{className:"gap-2",children:[!h&&!p&&s.jsxs(V,{variant:"outline",size:"sm",onClick:()=>H(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(B,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(h?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!h&&s.jsx(V,{size:"sm",onClick:q,disabled:y,children:i(y?"settings.common.actions.saving":p?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(_t,{open:K,onOpenChange:_=>{G||H(_)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(qt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:g?.name||f})})]}),s.jsxs(as,{children:[s.jsx(V,{variant:"ghost",onClick:()=>H(!1),disabled:G,children:i("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:()=>{z()},disabled:G,children:i("settings.common.actions.delete")})]})]})})]})},zv={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},Uv={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},_v=()=>{const t=_e.c(112),{t:e}=Be(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:o,loadProfiles:r,loadGlobalIdentity:d,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:g,setDefaultGitIdentityId:p,getUnimportedCredentials:h}=ma($s(Bv)),[f,m]=l.useState(!1),[v,C]=l.useState(null),[b,k]=l.useState(null),[u,j]=l.useState(null),[N,w]=l.useState(!1);let S,A;t[0]!==g||t[1]!==c||t[2]!==d||t[3]!==r?(S=()=>{r(),d(),c(),g()},A=[r,d,c,g],t[0]=g,t[1]=c,t[2]=d,t[3]=r,t[4]=S,t[5]=A):(S=t[4],A=t[5]),l.useEffect(S,A);let x,E,M,T,D,R,O,I,y,L,K,H,G,W;if(t[6]!==i||t[7]!==u||t[8]!==o||t[9]!==h||t[10]!==n||t[11]!==a||t[12]!==p||t[13]!==e){const Te=h();let Oe;t[28]===Symbol.for("react.memo_cache_sentinel")?(Oe=(Le,Ne)=>{C(Le),k(Ne??null),m(!0)},t[28]=Oe):Oe=t[28];const pe=Oe;let xe;t[29]!==i||t[30]!==p||t[31]!==e?(xe=async Le=>{const Ne=i===Le?null:Le;if(!await p(Ne)){U.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}U.success(e(Ne?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=p,t[31]=e,t[32]=xe):xe=t[32];const ae=xe;let ie;t[33]!==u||t[34]!==o||t[35]!==e?(ie=async()=>{if(!u)return;w(!0),await o(u.id)?(U.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:u.name})),j(null)):U.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),w(!1)},t[33]=u,t[34]=o,t[35]=e,t[36]=ie):ie=t[36],M=ie,E=ns,t[37]!==e?(D=e("settings.page.git.title"),t[37]=e,t[38]=D):D=t[38],R=!0,x=He,t[39]!==e?(H=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=H):H=t[40],G=!1;let ge,Ee;t[41]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>pe("new"),Ee=s.jsx(B,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=ge,t[42]=Ee):(ge=t[41],Ee=t[42]);let Ke;t[43]!==e?(Ke=e("settings.common.badge.new"),t[43]=e,t[44]=Ke):Ke=t[44],t[45]!==Ke?(W=s.jsxs(V,{size:"sm",variant:"outline",onClick:ge,children:[Ee," ",Ke]}),t[45]=Ke,t[46]=W):W=t[46],T="git.identities",O="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",I=n&&s.jsx(Ic,{profile:n,isDefault:i==="global",onEdit:()=>pe("global"),onToggleDefault:()=>ae("global"),isReadOnly:!0,hasBorder:a.length>0||Te.length>0}),y=a.map((Le,Ne)=>s.jsx(Ic,{profile:Le,isDefault:i===Le.id,onEdit:()=>pe(Le.id),onToggleDefault:()=>ae(Le.id),onDelete:()=>j(Le),hasBorder:Ne<a.length-1||Te.length>0},Le.id)),L=!n&&a.length===0&&Te.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(B,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),K=Te.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),Te.map((Le,Ne)=>s.jsx($v,{credential:Le,onImport:()=>pe("new",{host:Le.host,username:Le.username}),hasBorder:Ne<Te.length-1},`${Le.host}-${Le.username}`))]}),t[6]=i,t[7]=u,t[8]=o,t[9]=h,t[10]=n,t[11]=a,t[12]=p,t[13]=e,t[14]=x,t[15]=E,t[16]=M,t[17]=T,t[18]=D,t[19]=R,t[20]=O,t[21]=I,t[22]=y,t[23]=L,t[24]=K,t[25]=H,t[26]=G,t[27]=W}else x=t[14],E=t[15],M=t[16],T=t[17],D=t[18],R=t[19],O=t[20],I=t[21],y=t[22],L=t[23],K=t[24],H=t[25],G=t[26],W=t[27];let q;t[47]!==O||t[48]!==I||t[49]!==y||t[50]!==L||t[51]!==K?(q=s.jsxs("div",{className:O,children:[I,y,L,K]}),t[47]=O,t[48]=I,t[49]=y,t[50]=L,t[51]=K,t[52]=q):q=t[52];let z;t[53]!==x||t[54]!==T||t[55]!==q||t[56]!==H||t[57]!==G||t[58]!==W?(z=s.jsx(x,{title:H,divider:G,headerAction:W,settingsItem:T,children:q}),t[53]=x,t[54]=T,t[55]=q,t[56]=H,t[57]=G,t[58]=W,t[59]=z):z=t[59];let $;t[60]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(Hd,{}),t[60]=$):$=t[60];let Z;t[61]!==E||t[62]!==D||t[63]!==R||t[64]!==z?(Z=s.jsxs(E,{title:D,showSaveStatus:R,children:[z,$]}),t[61]=E,t[62]=D,t[63]=R,t[64]=z,t[65]=Z):Z=t[65];let _;t[66]!==b||t[67]!==f||t[68]!==v?(_=s.jsx(Kv,{open:f,onOpenChange:m,profileId:v,importData:b}),t[66]=b,t[67]=f,t[68]=v,t[69]=_):_=t[69];const ne=u!==null;let X;t[70]!==N?(X=Te=>{N||Te||j(null)},t[70]=N,t[71]=X):X=t[71];let te;t[72]!==e?(te=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=te):te=t[73];let he;t[74]!==te?(he=s.jsx(Ht,{children:te}),t[74]=te,t[75]=he):he=t[75];const je=u?.name??"";let fe;t[76]!==e||t[77]!==je?(fe=e("settings.gitIdentities.page.deleteDialog.description",{name:je}),t[76]=e,t[77]=je,t[78]=fe):fe=t[78];let ke;t[79]!==fe?(ke=s.jsx(qt,{children:fe}),t[79]=fe,t[80]=ke):ke=t[80];let be;t[81]!==he||t[82]!==ke?(be=s.jsxs(Vt,{children:[he,ke]}),t[81]=he,t[82]=ke,t[83]=be):be=t[83];let De;t[84]===Symbol.for("react.memo_cache_sentinel")?(De=()=>j(null),t[84]=De):De=t[84];let oe;t[85]!==e?(oe=e("settings.common.actions.cancel"),t[85]=e,t[86]=oe):oe=t[86];let ee;t[87]!==N||t[88]!==oe?(ee=s.jsx(V,{variant:"ghost",onClick:De,disabled:N,children:oe}),t[87]=N,t[88]=oe,t[89]=ee):ee=t[89];let ce;t[90]!==M?(ce=()=>{M()},t[90]=M,t[91]=ce):ce=t[91];let ue;t[92]!==e?(ue=e("settings.common.actions.delete"),t[92]=e,t[93]=ue):ue=t[93];let Ie;t[94]!==N||t[95]!==ce||t[96]!==ue?(Ie=s.jsx(V,{size:"sm",variant:"destructive",onClick:ce,disabled:N,children:ue}),t[94]=N,t[95]=ce,t[96]=ue,t[97]=Ie):Ie=t[97];let ve;t[98]!==ee||t[99]!==Ie?(ve=s.jsxs(as,{children:[ee,Ie]}),t[98]=ee,t[99]=Ie,t[100]=ve):ve=t[100];let Re;t[101]!==be||t[102]!==ve?(Re=s.jsxs($t,{className:"max-w-md",children:[be,ve]}),t[101]=be,t[102]=ve,t[103]=Re):Re=t[103];let Me;t[104]!==ne||t[105]!==X||t[106]!==Re?(Me=s.jsx(_t,{open:ne,onOpenChange:X,children:Re}),t[104]=ne,t[105]=X,t[106]=Re,t[107]=Me):Me=t[107];let me;return t[108]!==Z||t[109]!==_||t[110]!==Me?(me=s.jsxs(s.Fragment,{children:[Z,_,Me]}),t[108]=Z,t[109]=_,t[110]=Me,t[111]=me):me=t[111],me},Ic=t=>{const e=_e.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:o,onDelete:r,isReadOnly:d,hasBorder:c}=t,{t:g}=Be(),[p,h]=l.useState(!1),f=zv[a.icon||"branch"]||"git-branch",m=Uv[a.color||""],v=a.authType||"ssh";let C;e[0]!==i?(C=z=>{z.currentTarget===z.target&&(z.key!=="Enter"&&z.key!==" "||(z.preventDefault(),i()))},e[0]=i,e[1]=C):C=e[1];const b=C;let k;e[2]!==n||e[3]!==d||e[4]!==r||e[5]!==o||e[6]!==g?(k=z=>s.jsxs(s.Fragment,{children:[s.jsx(z,{onClick:$=>{$.stopPropagation(),o()},children:g(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!d&&r&&s.jsxs(z,{onClick:$=>{$.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(B,{name:"delete-bin",className:"h-4 w-4 mr-px"}),g("settings.common.actions.delete")]})]}),e[2]=n,e[3]=d,e[4]=r,e[5]=o,e[6]=g,e[7]=k):k=e[7];const u=k,j=c&&"border-b border-[var(--surface-subtle)]";let N;e[8]!==j?(N=Se("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",j),e[8]=j,e[9]=N):N=e[9];let w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w=z=>{z.preventDefault(),h(!0)},e[10]=w):w=e[10];let S;e[11]!==b||e[12]!==i||e[13]!==N?(S=s.jsx("div",{className:N,onClick:i,role:"button",tabIndex:0,onKeyDown:b,onContextMenu:w}),e[11]=b,e[12]=i,e[13]=N,e[14]=S):S=e[14];let A;e[15]!==m?(A={color:m},e[15]=m,e[16]=A):A=e[16];let x;e[17]!==f||e[18]!==A?(x=s.jsx(B,{name:f,className:"w-4 h-4 shrink-0",style:A}),e[17]=f,e[18]=A,e[19]=x):x=e[19];let E;e[20]!==a.name?(E=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=E):E=e[21];let M;e[22]!==v?(M=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:v}),e[22]=v,e[23]=M):M=e[23];let T;e[24]!==n||e[25]!==g?(T=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:g("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=g,e[26]=T):T=e[26];let D;e[27]!==d||e[28]!==g?(D=d&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:g("settings.agents.sidebar.badge.system")}),e[27]=d,e[28]=g,e[29]=D):D=e[29];let R;e[30]!==M||e[31]!==T||e[32]!==D||e[33]!==E?(R=s.jsxs("div",{className:"flex items-center gap-1.5",children:[E,M,T,D]}),e[30]=M,e[31]=T,e[32]=D,e[33]=E,e[34]=R):R=e[34];const O=v==="token"&&a.host?a.host:a.userEmail;let I;e[35]!==O?(I=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:O}),e[35]=O,e[36]=I):I=e[36];let y;e[37]!==R||e[38]!==I?(y=s.jsxs("div",{className:"min-w-0",children:[R,I]}),e[37]=R,e[38]=I,e[39]=y):y=e[39];let L;e[40]!==y||e[41]!==x?(L=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[x,y]}),e[40]=y,e[41]=x,e[42]=L):L=e[42];let K;e[43]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(Wn,{asChild:!0,children:s.jsx(V,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:Vv,children:s.jsx(B,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=K):K=e[43];let H;e[44]!==u?(H=s.jsxs(Jn,{children:[K,s.jsx(Gn,{align:"end",className:"w-fit min-w-28",children:u(xn)})]}),e[44]=u,e[45]=H):H=e[45];let G;e[46]!==L||e[47]!==H||e[48]!==S?(G=s.jsxs(Xa,{render:S,children:[L,H]}),e[46]=L,e[47]=H,e[48]=S,e[49]=G):G=e[49];let W;e[50]!==u?(W=s.jsx(Ya,{className:"w-fit min-w-28",children:u(Za)}),e[50]=u,e[51]=W):W=e[51];let q;return e[52]!==p||e[53]!==G||e[54]!==W?(q=s.jsxs(ei,{open:p,onOpenChange:h,children:[G,W]}),e[52]=p,e[53]=G,e[54]=W,e[55]=q):q=e[55],q},$v=t=>{const e=_e.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:o}=Be();let r;e[0]!==a.host?(r=a.host.split("/"),e[0]=a.host,e[1]=r):r=e[1];const d=r,c=d.length>=3?d[d.length-1]:a.host,g=a.host.includes("/"),p=i&&"border-b border-[var(--surface-subtle)]";let h;e[2]!==p?(h=Se("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",p),e[2]=p,e[3]=h):h=e[3];let f;e[4]!==c?(f=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=f):f=e[5];const m=g?a.host:a.username;let v;e[6]!==m?(v=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:m}),e[6]=m,e[7]=v):v=e[7];let C;e[8]!==f||e[9]!==v?(C=s.jsxs("div",{className:"min-w-0",children:[f,v]}),e[8]=f,e[9]=v,e[10]=C):C=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(B,{name:"download",className:"h-3 w-3"}),e[11]=b):b=e[11];let k;e[12]!==o?(k=o("settings.gitIdentities.page.actions.import"),e[12]=o,e[13]=k):k=e[13];let u;e[14]!==n||e[15]!==k?(u=s.jsxs(V,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[b,k]}),e[14]=n,e[15]=k,e[16]=u):u=e[16];let j;return e[17]!==u||e[18]!==h||e[19]!==C?(j=s.jsxs("div",{className:h,children:[C,u]}),e[17]=u,e[18]=h,e[19]=C,e[20]=j):j=e[20],j};function Bv(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function Vv(t){return t.stopPropagation()}const qd=({guest:t})=>{const{t:e}=Be(),a=t.integration,n=Bo(X=>X.byId[t.id]),i=Bo(X=>X.setStatus),o=l.useMemo(()=>ld(t.id,t.icon,yd().authenticatedAsset),[t.id,t.icon]),r=Bo(X=>X.refresh),[d,c]=l.useState(!1),[g,p]=l.useState(!1),[h,f]=l.useState(!1),[m,v]=l.useState(""),[C,b]=l.useState(""),[k,u]=l.useState(""),[j,N]=l.useState(""),[w,S]=l.useState({}),[A,x]=l.useState(!1),E=l.useRef(null),[M]=l.useState(ln),T=l.useRef(!0),D=()=>T.current&&ln()===M,R=l.useCallback(()=>{E.current!=null&&(window.clearInterval(E.current),E.current=null),f(!1)},[]);if(l.useEffect(()=>(T.current=!0,r(t.id),()=>{T.current=!1,R()}),[t.id,r,R]),l.useEffect(()=>{n&&S(n.settings)},[n]),!a)return null;const O=a.auth,I=O==="token"&&a.token?.scheme==="basic",y=!!n?.connection.connected,L=n?.connection.account.trim()||"",K=h?e("settings.integrations.guests.status.waiting"):y?L||e("settings.integrations.guests.status.connected"):e("settings.integrations.guests.status.notConnected"),H=h?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":y?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",G=h||d,W=a.name,q=async()=>{if(!D())return!1;const X=m.trim();if(!X)return n?.hasClient?!0:(U.error(e("settings.integrations.guests.toast.clientRequired")),!1);os("saving");const te=await $p(t.id,X,C.trim()||void 0);return D()?te?(i(t.id,te),b(""),os("saved"),!0):(os("error"),U.error(e("settings.integrations.guests.toast.saveFailed",{name:W})),!1):!1},z=async(X=w)=>{if(!D())return!1;const te=n?.settings??{};if((a.settings??[]).every(ke=>(X[ke.id]??"").trim()===(te[ke.id]??"")))return!0;os("saving");const fe=await Op(t.id,X);return D()?fe?(i(t.id,fe),os("saved"),!0):(os("error"),U.error(e("settings.integrations.guests.toast.saveFailed",{name:W})),!1):!1},$=async()=>{if(!D())return!1;const X=k.trim();if(!X)return y?!0:(U.error(e("settings.integrations.guests.toast.tokenRequired")),!1);const te=j.trim();if(I&&!te)return U.error(e("settings.integrations.guests.toast.usernameRequired")),!1;os("saving");const he=await _p(t.id,X,I?te:void 0);return D()?he?(i(t.id,he),u(""),N(""),os("saved"),!0):(os("error"),U.error(e("settings.integrations.guests.toast.tokenInvalid")),!1):!1},Z=async()=>{if(!D())return;R(),p(!0);const X=n?.connection??{connected:!1,account:""};try{if(O==="token"){if(await $()){if((a.settings??[]).length>0&&!await z()||!D())return;U.success(e("settings.integrations.guests.toast.connected",{name:W}))}return}if(O==="oauth"&&!n?.hasClient&&!await q())return;const te=await Fp(t.id);if(!D())return;if(!te){U.error(e("settings.integrations.guests.toast.startFailed",{name:W}));return}f(!0),c(!0),_s(te);const he=Date.now()+Kp;E.current=window.setInterval(()=>{(async()=>{if(!D()){R();return}if(Date.now()>he){R(),U.error(e("settings.integrations.guests.toast.authorizationFailed",{name:W}));return}const je=await r(t.id);D()&&je&&zp(X,je.connection)&&(R(),U.success(e("settings.integrations.guests.toast.connected",{name:W})),us()&&jd())})()},Up)}catch(te){if(!D())return;console.error("Failed to start guest connect:",te),U.error(e("settings.integrations.guests.toast.startFailed",{name:W})),R()}finally{D()&&p(!1)}},_=async()=>{if(D()){p(!0);try{R();const X=await Lp(t.id);if(!D())return;if(!X){U.error(e("settings.integrations.guests.toast.disconnectFailed",{name:W}));return}i(t.id,X),U.success(e("settings.integrations.guests.toast.disconnected",{name:W}))}catch(X){if(!D())return;console.error("Failed to disconnect guest:",X),U.error(e("settings.integrations.guests.toast.disconnectFailed",{name:W}))}finally{D()&&p(!1)}}},ne=async()=>{const X=n?.redirectUri??"";!X||!(await Va(X)).ok||(x(!0),window.setTimeout(()=>x(!1),1500))};return s.jsx(bn,{open:G,onOpenChange:X=>{if(h){c(!0);return}c(X)},children:s.jsxs("div",{className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(vn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(cd,{icon:dd(t.icon),iconSrc:o,className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:W}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:a.description})]}),s.jsx("span",{"aria-live":"polite",className:Se("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",H),children:K}),s.jsx(B,{name:"arrow-down-s",className:Se("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",G&&"rotate-180")})]}),s.jsx(yn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[O==="oauth"?s.jsxs(s.Fragment,{children:[s.jsx(Kt,{label:e("settings.integrations.guests.field.clientId"),controlClassName:"w-full max-w-none",children:s.jsx(Ge,{value:m,onChange:X=>v(X.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:g})}),s.jsx(Kt,{label:e("settings.integrations.guests.field.clientSecret"),controlClassName:"w-full max-w-none",children:s.jsx(Ge,{type:"password",value:C,onChange:X=>b(X.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:g})})]}):null,I?s.jsx(Kt,{label:a.token?.usernameLabel??e("settings.integrations.guests.field.username"),controlClassName:"w-full max-w-none",children:s.jsx(Ge,{value:j,onChange:X=>N(X.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:g})}):null,O==="token"?s.jsx(Kt,{label:e("settings.integrations.guests.field.token"),info:e("settings.integrations.guests.field.token.info"),controlClassName:"w-full max-w-none",children:s.jsx(Ge,{type:"password",value:k,onChange:X=>u(X.target.value),autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:g})}):null,(a.settings??[]).map(X=>s.jsx(Kt,{label:X.label,controlClassName:"w-full max-w-none",children:s.jsx(Ge,{value:w[X.id]??"",onChange:te=>{S(he=>({...he,[X.id]:te.target.value}))},onBlur:()=>{z()},autoComplete:"off",spellCheck:!1,className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:g})},X.id)),O==="oauth"?s.jsxs(Kt,{label:e("settings.integrations.guests.field.redirectUri"),info:e("settings.integrations.guests.field.redirectUri.info"),controlClassName:"w-full max-w-none",children:[s.jsx(Ge,{value:n?.redirectUri??"",readOnly:!0,className:"h-8 min-w-0 flex-1 rounded-md px-3"}),s.jsx(V,{type:"button",size:"sm",variant:"outline",disabled:!n?.redirectUri,onClick:()=>{ne()},children:e(A?"settings.integrations.guests.actions.copied":"settings.integrations.guests.actions.copyRedirect")})]}):null,s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:y?s.jsx(V,{type:"button",size:"sm",variant:"destructive",disabled:g,onClick:()=>{_()},children:e("settings.integrations.guests.actions.disconnect")}):s.jsxs(V,{type:"button",size:"sm",disabled:g||h,onClick:()=>{Z()},children:[g?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):null,e("settings.integrations.guests.actions.connect")]})})]})})]})})},Hv=t=>{const e=_e.c(27),{divider:a}=t,n=a===void 0?!0:a,{t:i}=Be(),o=Ks(qv),r=Ks(Gv);let d;if(e[0]===Symbol.for("react.memo_cache_sentinel")?(d=[],e[0]=d):d=e[0],l.useEffect(Wv,d),ms()||kd())return null;let c,g,p,h,f,m,v,C;if(e[1]!==n||e[2]!==o||e[3]!==r||e[4]!==i){C=Symbol.for("react.early_return_sentinel");e:{const k=o.filter(Jv);if(k.length===0){C=null;break e}c=He,e[13]!==i?(g=i("settings.integrations.guests.title"),e[13]=i,e[14]=g):g=e[14],e[15]!==i?(p=i("settings.integrations.guests.info"),e[15]=i,e[16]=p):p=e[16],h=n,f="integrations.guests",m="space-y-3";let u;e[17]!==r?(u=j=>s.jsx(qd,{guest:j},`${r}:${j.id}`),e[17]=r,e[18]=u):u=e[18],v=k.map(u)}e[1]=n,e[2]=o,e[3]=r,e[4]=i,e[5]=c,e[6]=g,e[7]=p,e[8]=h,e[9]=f,e[10]=m,e[11]=v,e[12]=C}else c=e[5],g=e[6],p=e[7],h=e[8],f=e[9],m=e[10],v=e[11],C=e[12];if(C!==Symbol.for("react.early_return_sentinel"))return C;let b;return e[19]!==c||e[20]!==g||e[21]!==p||e[22]!==h||e[23]!==f||e[24]!==m||e[25]!==v?(b=s.jsx(c,{title:g,info:p,divider:h,settingsItem:f,contentClassName:m,children:v}),e[19]=c,e[20]=g,e[21]=p,e[22]=h,e[23]=f,e[24]=m,e[25]=v,e[26]=b):b=e[26],b};function qv(t){return t.guests}function Gv(t){return t.runtimeKey}function Wv(){gn()}function Jv(t){return t.source!=="bundled"&&t.integration&&_r(t)}const Qv=({embedded:t=!1})=>{const{t:e}=Be(),{isMobile:a}=qn(),n=qa()?.github,i=ta(I=>I.status),o=ta(I=>I.isLoading),r=ta(I=>I.hasChecked),d=ta(I=>I.refreshStatus),c=ta(I=>I.setStatus),g=l.useCallback(async I=>{await _s(I)},[]),[p,h]=l.useState(!1),[f,m]=l.useState(null),[v,C]=l.useState(null),b=l.useRef(null),k=l.useCallback(()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null),C(null)},[]);l.useEffect(()=>((async()=>{try{r||await d(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{k()}),[r,d,n,k]);const u=l.useCallback(async()=>{h(!0);try{const I=n?await n.authStart():await(async()=>{const L=await It("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),K=await L.json().catch(()=>null);if(!L.ok||!K||!("deviceCode"in K))throw new Error(K?.error||L.statusText);return K})();m(I),C(Math.max(1,I.interval)*1e3);const y=I.verificationUriComplete||I.verificationUri;g(y)}catch(I){console.error("Failed to start GitHub connect:",I),U.error(e("settings.github.page.toast.startConnectFailed"))}finally{h(!1)}},[g,n,e]),j=l.useCallback(async I=>{if(n)return n.authComplete(I);const y=await It("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:I})}),L=await y.json().catch(()=>null);if(!y.ok||!L)throw new Error(L?.error||y.statusText);return L},[n]);l.useEffect(()=>{if(!(!f?.deviceCode||!v)&&b.current==null)return b.current=window.setInterval(()=>{(async()=>{try{const I=await j(f.deviceCode);if(I.connected){U.success(e("settings.github.page.toast.connected")),m(null),k(),await d(n,{force:!0});return}I.status==="slow_down"&&C(y=>y?y+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(U.error(I.error||e("settings.github.page.toast.authorizationFailed")),m(null),k())}catch(I){console.warn("GitHub polling failed:",I)}})()},v),()=>{b.current!=null&&(window.clearInterval(b.current),b.current=null)}},[f,v,j,d,n,k,e]);const N=l.useCallback(async I=>{h(!0);try{if(n)await n.authSetGhCliDisabled(I);else{const y=await It("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:I})}),L=await y.json().catch(()=>null);if(!y.ok)throw new Error(L?.error||y.statusText)}U.success(e(I?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await d(n,{force:!0})}catch(y){console.error("Failed to update gh CLI setting:",y),U.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{h(!1)}},[d,n,e]),w=l.useCallback(async()=>{h(!0);try{if(k(),m(null),n)await n.authDisconnect();else{const I=await It("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!I.ok)throw new Error(I.statusText)}U.success(e("settings.github.page.toast.disconnected")),await d(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),U.error(e("settings.github.page.toast.disconnectFailed"))}finally{h(!1)}},[d,n,k,e]),S=l.useCallback(async I=>{if(I){h(!0);try{const y=n?await n.authActivate(I):await(async()=>{const L=await It("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:I})}),K=await L.json().catch(()=>null);if(!L.ok||!K)throw new Error(K?.error||L.statusText);return K})();c(y),U.success(e("settings.github.page.toast.accountSwitched"))}catch(y){console.error("Failed to switch GitHub account:",y),U.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{h(!1)}}},[n,c,e]);if(o&&!r)return null;const A=!!i?.connected,x=i?.user,M=(i?.accounts??[]).filter(I=>!I.current),T=i?.ghCli??null,D=T?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),R=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[A?s.jsxs("div",{className:Se("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:Se("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[x?.avatarUrl?s.jsx("img",{src:x.avatarUrl,alt:x.login?e("settings.github.page.avatarAlt.withLogin",{login:x.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:x?.name?.trim()||x?.login||"GitHub"}),s.jsxs("div",{className:Se("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(B,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:x?.login||e("settings.github.page.label.unknownUser")}),x?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),x?.email&&s.jsx("span",{children:x.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:D})]}),i?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:i.scope})}),T?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),T?.active?s.jsx(V,{size:"sm",variant:"outline",onClick:()=>N(!0),disabled:p,className:Se(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(V,{size:"sm",variant:"outline",onClick:w,disabled:p,className:Se("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.github.page.status.notConnected")})}),s.jsx(V,{size:"sm",variant:"default",onClick:u,disabled:p,children:e("settings.github.page.actions.connect")})]}),M.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:M.map(I=>{const y=I.user,L=I.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[y?.avatarUrl?s.jsx("img",{src:y.avatarUrl,alt:y.login?e("settings.github.page.avatarAlt.withLogin",{login:y.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(B,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:y?.name?.trim()||y?.login||"GitHub"}),y?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:y.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:L})]})]})]}),s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>S(I.id),disabled:p,children:e("settings.github.page.actions.switchTo")})]},I.id)})})]})]}),A&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(V,{size:"sm",variant:"outline",onClick:u,disabled:p,className:Se(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),f&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(An,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:f.userCode}),s.jsx(V,{size:"sm",asChild:!0,children:s.jsx("a",{href:f.verificationUriComplete||f.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:e("settings.github.page.flow.waiting")}),s.jsx(V,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{k(),m(null)},children:e("settings.common.actions.cancel")})]})]})]}),O=T?.available&&!T?.active&&(!T.user||T.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:Se("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:Se("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[T.user?.avatarUrl?s.jsx("img",{src:T.user.avatarUrl,alt:T.user.login?e("settings.github.page.avatarAlt.withLogin",{login:T.user.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(B,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!T.disabled&&T.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:T.user.name?.trim()||T.user.login||"GitHub"}),!T.disabled&&T.user?.login&&s.jsxs("div",{className:Se("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(B,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:T.user.login}),T.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),T.user.email&&s.jsx("span",{children:T.user.email})]}),s.jsx("div",{className:Se("typography-meta text-muted-foreground",T.disabled?"opacity-60":void 0),children:T.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(V,{size:"sm",variant:"outline",onClick:()=>N(!T.disabled),disabled:p,className:Se(a?"w-full":void 0),children:T.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[R,O?s.jsxs("div",{className:"space-y-2",children:[s.jsx(An,{children:e("settings.github.page.ghCli.title")}),O]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:R}),O?s.jsx(He,{title:e("settings.github.page.ghCli.title"),children:O}):null]})},Yv=()=>{const t=_e.c(37),{t:e}=Be(),a=ta(Zv),n=ta(Xv),i=ta(ey),[o,r]=l.useState(!1),d=a?.connected===!0;let c;t[0]!==d||t[1]!==i||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(c=n&&!i?e("common.loading"):d?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=d,t[1]=i,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=c):c=t[5];const g=c,p=d?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let h;t[6]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(B,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=h):h=t[6];let f;t[7]!==e?(f=e("settings.integrations.github.title"),t[7]=e,t[8]=f):f=t[8];let m;t[9]!==f?(m=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:f}),t[9]=f,t[10]=m):m=t[10];let v;t[11]!==e?(v=e("settings.integrations.github.description"),t[11]=e,t[12]=v):v=t[12];let C;t[13]!==v?(C=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:v}),t[13]=v,t[14]=C):C=t[14];let b;t[15]!==m||t[16]!==C?(b=s.jsxs("div",{className:"min-w-0 flex-1",children:[m,C]}),t[15]=m,t[16]=C,t[17]=b):b=t[17];let k;t[18]!==p?(k=Se("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",p),t[18]=p,t[19]=k):k=t[19];let u;t[20]!==g||t[21]!==k?(u=s.jsx("span",{"aria-live":"polite",className:k,children:g}),t[20]=g,t[21]=k,t[22]=u):u=t[22];const j=o&&"rotate-180";let N;t[23]!==j?(N=Se("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",j),t[23]=j,t[24]=N):N=t[24];let w;t[25]!==N?(w=s.jsx(B,{name:"arrow-down-s",className:N}),t[25]=N,t[26]=w):w=t[26];let S;t[27]!==w||t[28]!==b||t[29]!==u?(S=s.jsxs(vn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[h,b,u,w]}),t[27]=w,t[28]=b,t[29]=u,t[30]=S):S=t[30];let A;t[31]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(yn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(Qv,{embedded:!0})}),t[31]=A):A=t[31];let x;t[32]!==S?(x=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[S,A]}),t[32]=S,t[33]=x):x=t[33];let E;return t[34]!==o||t[35]!==x?(E=s.jsx(bn,{open:o,onOpenChange:r,children:x}),t[34]=o,t[35]=x,t[36]=E):E=t[36],E};function Zv(t){return t.status}function Xv(t){return t.isLoading}function ey(t){return t.hasChecked}const Gi="__none__",Wi="__inherit__";function ty({linear:t,connected:e,organizationId:a}){const{t:n}=Be(),i=hn(b=>b.projects),[o,r]=l.useState(null),[d,c]=l.useState(!1),[g,p]=l.useState(!1),h=l.useCallback(async()=>{if(!e){r(null),c(!1);return}try{const b=await t.mappingGet();if(b.connected===!1){r(null),c(!1);return}r(b),c(!1)}catch(b){console.error("Failed to load Linear mapping:",b),c(!0)}},[e,t]);l.useEffect(()=>{h()},[h,a]);const f=l.useCallback(async b=>{const k={};for(const u of b.teams??[])u.projectPath&&(k[u.id]=u.projectPath);p(!0),os("saving");try{const u=await t.mappingSet({defaultProjectPath:b.defaultProjectPath??null,teamProjectPaths:k});if(u.connected===!1){r(null),os("error");return}r(u),c(!1),os("saved")}catch(u){console.error("Failed to save Linear mapping:",u),os("error")}finally{p(!1)}},[t]);if(!e)return null;if(d&&!o)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!o)return null;const m=b=>i.find(u=>u.path===b)?.label?.trim()||b,v=b=>!b||b===Gi?n("settings.integrations.linear.mapping.defaultProject.placeholder"):m(b),C=b=>!b||b===Wi?n("settings.integrations.linear.mapping.teams.useDefault"):m(b);return s.jsxs("div",{className:Ms,children:[i.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Ct,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Dt,{value:o.defaultProjectPath||Gi,disabled:g||i.length===0,onValueChange:b=>{f({...o,defaultProjectPath:b===Gi?null:b})},children:[s.jsx(Tt,{size:Qt,className:fn,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Jt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:v})}),s.jsxs(Et,{children:[s.jsx(gt,{value:Gi,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),o.defaultProjectPath&&!i.some(b=>b.path===o.defaultProjectPath)?s.jsx(gt,{value:o.defaultProjectPath,children:o.defaultProjectPath}):null,i.map(b=>s.jsx(gt,{value:b.path,children:m(b.path)},b.id))]})]})}),s.jsx(Cs,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(o.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:Ms,children:(o.teams??[]).map(b=>s.jsx(Ct,{label:`${b.key} · ${b.name}`,children:s.jsxs(Dt,{value:b.projectPath||Wi,disabled:g||i.length===0,onValueChange:k=>{f({...o,teams:(o.teams??[]).map(u=>u.id===b.id?{...u,projectPath:k===Wi?null:k}:u)})},children:[s.jsx(Tt,{size:Qt,className:fn,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:b.key}),children:s.jsx(Jt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:C})}),s.jsxs(Et,{children:[s.jsx(gt,{value:Wi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),b.projectPath&&!i.some(k=>k.path===b.projectPath)?s.jsx(gt,{value:b.projectPath,children:b.projectPath}):null,i.map(k=>s.jsx(gt,{value:k.path,children:m(k.path)},k.id))]})]})},b.id))})})]})}function sy({linear:t,connected:e}){const{t:a}=Be(),[n,i]=l.useState(null),[o,r]=l.useState(!1),[d,c]=l.useState(!1);l.useEffect(()=>{if(!e){i(null),r(!1);return}let p=!1;return t.preferencesGet().then(h=>{p||(i(h.sessionComments),r(!1))}).catch(()=>{p||r(!0)}),()=>{p=!0}},[e,t]);const g=l.useCallback(async p=>{const h=n;i(p),c(!0);try{const f=await t.preferencesSet({sessionComments:p});i(f.sessionComments),os("saved")}catch{i(h),os("error")}finally{c(!1)}},[n,t]);return e?o?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:Ms,children:s.jsx(Ct,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(fa,{checked:n===!0,disabled:n===null||d,onCheckedChange:p=>{g(p)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const ny=3*6e4,ay=1500;function Pc(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function iy(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const oy=()=>{const{t}=Be(),e=qa()?.linear,a=Fa(T=>T.status),n=Fa(T=>T.isLoading),i=Fa(T=>T.hasChecked),o=Fa(T=>T.refreshStatus),r=Fa(T=>T.setStatus),[d,c]=l.useState(!1),[g,p]=l.useState(!1),[h,f]=l.useState(!1),m=l.useRef(null),v=l.useCallback(()=>{m.current!=null&&(window.clearInterval(m.current),m.current=null),p(!1)},[]);l.useEffect(()=>{if(e)return i||o(e),()=>{v()}},[i,o,e,v]);const C=l.useCallback(async()=>{if(!e)return;v(),c(!0);const T=Pc(Fa.getState().status);try{const D=await e.authStart(us()?"desktop":"web");p(!0),f(!0),_s(D.authorizationUrl);const R=Date.now()+ny;m.current=window.setInterval(()=>{(async()=>{if(Date.now()>R){v(),U.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const O=await o(e,{force:!0});iy(T,Pc(O))&&(v(),U.success(t("settings.integrations.linear.toast.connected")),jd())})()},ay)}catch(D){console.error("Failed to start Linear connect:",D),U.error(t("settings.integrations.linear.toast.startConnectFailed")),v()}finally{c(!1)}},[o,e,v,t]),b=l.useCallback(async T=>{if(!(!e||!T)){c(!0);try{const D=await e.authActivate(T);r(D),U.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(D){console.error("Failed to switch Linear workspace:",D),U.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{c(!1)}}},[e,r,t]),k=l.useCallback(async()=>{if(e){c(!0);try{v(),await e.authDisconnect(),U.success(t("settings.integrations.linear.toast.disconnected")),await o(e,{force:!0})}catch(T){console.error("Failed to disconnect Linear:",T),U.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{c(!1)}}},[o,e,v,t]);if(!e)return null;const u=!!a?.connected,j=a?.user,N=a?.organization,S=(a?.workspaces??[]).filter(T=>!T.current),A=j?.displayName?.trim()||j?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),x=g?t("settings.integrations.linear.status.waiting"):n&&!i?t("common.loading"):u?N?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),E=g?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":u?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",M=g||h;return s.jsx(bn,{open:M,onOpenChange:T=>{if(g){f(!0);return}f(T)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(vn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(B,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:Se("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",E),children:x}),s.jsx(B,{name:"arrow-down-s",className:Se("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",M&&"rotate-180")})]}),s.jsx(yn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[u?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:A}),className:"size-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(B,{name:"linear",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:A}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[N?.name,j?.email].filter(Boolean).join(" · ")})]})]}):g?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,u?s.jsxs(s.Fragment,{children:[s.jsx(ty,{linear:e,connected:u,organizationId:N?.id??null}),s.jsx(sy,{linear:e,connected:u}),S.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:S.map(T=>{const D=T.user,R=T.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:R}),D?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:D.email}):null]}),s.jsx(V,{type:"button",size:"sm",variant:"ghost",onClick:()=>{b(T.id)},disabled:d,children:t("settings.integrations.linear.actions.switchTo")})]},T.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(V,{type:"button",size:"sm",variant:"outline",onClick:()=>{C()},disabled:d||g,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(V,{type:"button",size:"sm",variant:"destructive",onClick:()=>{k()},disabled:d,children:t("settings.integrations.linear.actions.disconnect")})]})]}):g?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(V,{type:"button",size:"sm",variant:"ghost",disabled:d,onClick:v,children:t("settings.common.actions.cancel")})]}):s.jsxs(V,{type:"button",size:"sm",variant:"default",onClick:()=>{C()},disabled:d||n&&!i,children:[d?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},sr=[{id:"opencode-claude",packageName:"@openchamber/opencode-claude",providerId:"claude-code",nameKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",homepage:"https://github.com/openchamber/opencode-claude"}],ry=(t,e)=>t===e||t.startsWith(`${e}@`);function nr(t,e,a){const n=t.filter(c=>ry(c.spec,e)),i=n.filter(c=>c.scope==="user"),o=n.filter(c=>c.scope==="project"),r=i.length===1?i[0]:null,d=a[r?.spec??e]??a[e]??null;return{userEntry:r,userEntryIsAmbiguous:i.length>1,projectEntries:o,registry:d}}function Tr(t,e){return e?.kind!=="npm-ok"||e.name!==t||!e.latestVersion?null:`${t}@${e.latestVersion}`}function Ac(t,e){if(t.userEntryIsAmbiguous)return"manage";if(!t.userEntry)return"install";const a=Tr(e,t.registry);return a&&a!==t.userEntry.spec?"update":"setup"}function ly(t,e={}){const a=t.registry?.kind==="npm-ok"?t.registry.latestVersion:null;return t.userEntryIsAmbiguous?{status:"ambiguous",latestVersion:a}:e.restartRequired?{status:"restart-required",latestVersion:a}:e.providerUnavailable?{status:"provider-unavailable",latestVersion:a}:e.registryUnavailable?{status:"registry-unavailable",latestVersion:a}:t.userEntry?t.registry?.kind==="npm-ok"&&t.registry.currentVersion===t.registry.latestVersion?{status:"installed-version",latestVersion:a}:t.registry?.kind==="npm-ok"&&t.registry.currentVersion===null?{status:"unpinned",latestVersion:a}:t.registry?.kind==="npm-ok"&&a?{status:"update-available",latestVersion:a}:{status:"installed",latestVersion:a}:{status:"not-installed",latestVersion:a}}const cy={success:"bg-[var(--status-success)]/15 text-[var(--status-success)]",warning:"bg-[var(--status-warning)]/15 text-[var(--status-warning)]",neutral:"bg-[var(--surface-muted)] text-muted-foreground"},Gd=t=>{const e=_e.c(33),{settingsItem:a,logo:n,name:i,description:o,status:r,statusTone:d,open:c,onOpenChange:g,children:p}=t;let h;e[0]!==n?(h=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:n}),e[0]=n,e[1]=h):h=e[1];let f;e[2]!==i?(f=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:i}),e[2]=i,e[3]=f):f=e[3];let m;e[4]!==o?(m=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:o}),e[4]=o,e[5]=m):m=e[5];let v;e[6]!==f||e[7]!==m?(v=s.jsxs("div",{className:"min-w-0 flex-1",children:[f,m]}),e[6]=f,e[7]=m,e[8]=v):v=e[8];const C=cy[d];let b;e[9]!==C?(b=Se("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",C),e[9]=C,e[10]=b):b=e[10];let k;e[11]!==r||e[12]!==b?(k=s.jsx("span",{"aria-live":"polite",className:b,children:r}),e[11]=r,e[12]=b,e[13]=k):k=e[13];const u=c&&"rotate-180";let j;e[14]!==u?(j=Se("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",u),e[14]=u,e[15]=j):j=e[15];let N;e[16]!==j?(N=s.jsx(B,{name:"arrow-down-s",className:j}),e[16]=j,e[17]=N):N=e[17];let w;e[18]!==h||e[19]!==N||e[20]!==v||e[21]!==k?(w=s.jsxs(vn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[h,v,k,N]}),e[18]=h,e[19]=N,e[20]=v,e[21]=k,e[22]=w):w=e[22];let S;e[23]!==p?(S=s.jsx(yn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:p}),e[23]=p,e[24]=S):S=e[24];let A;e[25]!==a||e[26]!==w||e[27]!==S?(A=s.jsxs("div",{"data-settings-item":a,className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[w,S]}),e[25]=a,e[26]=w,e[27]=S,e[28]=A):A=e[28];let x;return e[29]!==g||e[30]!==c||e[31]!==A?(x=s.jsx(bn,{open:c,onOpenChange:g,children:A}),e[29]=g,e[30]=c,e[31]=A,e[32]=x):x=e[32],x},dy=t=>t.requiresManualRestart===!0||t.reloadFailed===!0,uy=({divider:t=!0})=>{const{t:e}=Be(),a=en(),n=l.useCallback(()=>{re.getState().requestSettingsJump("plugins")},[]),i=l.useCallback(async y=>{if(await ct.getState().loadProviders({directory:a,source:"settings:third-party-provider-setup"}),!id(ct.getState(),a).some(H=>H.id===y))return!1;const K=re.getState();return K.setSettingsProvidersOpenRequested(y),K.requestSettingsJump("providers"),!0},[a]),{entries:o,registryInfo:r,loadPlugins:d,loadRegistryInfo:c,createEntry:g,updateEntry:p,deleteEntry:h}=zt($s(y=>({entries:y.entries,registryInfo:y.registryInfo,loadPlugins:y.loadPlugins,loadRegistryInfo:y.loadRegistryInfo,createEntry:y.createEntry,updateEntry:y.updateEntry,deleteEntry:y.deleteEntry}))),[f,m]=l.useState(!1),[v,C]=l.useState(null),[b,k]=l.useState(()=>new Set),[u,j]=l.useState(()=>new Set),[N,w]=l.useState(null),[S,A]=l.useState(()=>new Set),x=l.useCallback(async()=>{if(!await d({force:!0})){m(!0);return}const L=zt.getState().entries,K=new Set(sr.map(G=>G.packageName));for(const G of L)sr.some(W=>G.spec===W.packageName||G.spec.startsWith(`${W.packageName}@`))&&K.add(G.spec);const H=await c({specs:[...K],force:!0});m(!H)},[d,c]);l.useEffect(()=>{x()},[x]);const E=l.useCallback((y,L)=>{k(K=>{const H=new Set(K);return L?H.add(y):H.delete(y),H})},[]),M=l.useCallback((y,L)=>{j(K=>{const H=new Set(K);return L?H.add(y):H.delete(y),H})},[]),T=l.useCallback(async(y,L,K)=>{C({pluginId:y.id,action:L});try{const H=await K();if(!H.ok){U.error(e("settings.integrations.thirdParty.toast.actionFailed"));return}M(y.id,!1);const G=dy(H);E(y.id,G);const W=G?{description:e("settings.integrations.thirdParty.toast.restartRequired")}:void 0;L==="install"?U.success(e("settings.integrations.thirdParty.toast.installed",{name:e(y.nameKey)}),W):L==="update"?U.success(e("settings.integrations.thirdParty.toast.updated",{name:e(y.nameKey)}),W):U.success(e("settings.integrations.thirdParty.toast.removed",{name:e(y.nameKey)}),W),await x()}finally{C(null)}},[x,M,E,e]),D=l.useCallback(async y=>{const L=nr(o,y.packageName,r),K=Ac(L,y.packageName);if(K==="manage"){n();return}if(K==="setup"){C({pluginId:y.id,action:K});try{const G=await i(y.providerId);M(y.id,!G),G?E(y.id,!1):U.error(e("settings.integrations.thirdParty.toast.providerUnavailable"))}finally{C(null)}return}const H=Tr(y.packageName,L.registry);if(!H){m(!0);return}if(K==="install"){await T(y,"install",()=>g({spec:H,scope:"user"}));return}L.userEntry&&await T(y,"update",()=>p(L.userEntry.id,{spec:H}))},[g,o,n,i,r,T,M,E,e,p]),R=l.useCallback(async()=>{const y=N;if(!y)return;const L=nr(o,y.packageName,r);if(!L.userEntry||L.userEntryIsAmbiguous){w(null),n();return}w(null),await T(y,"remove",()=>h(L.userEntry.id))},[h,o,n,r,N,T]),O=l.useCallback((y,L)=>{A(K=>{const H=new Set(K);return L?H.add(y):H.delete(y),H})},[]),I=y=>{const L=nr(o,y.packageName,r),K=Ac(L,y.packageName),H=Tr(y.packageName,L.registry),G=v?.pluginId===y.id,W=b.has(y.id),q=u.has(y.id),z=f||L.registry?.kind==="npm-network",$=G||W&&K!=="setup"||(K==="install"||K==="update")&&(z||!H),Z=ly(L,{registryUnavailable:z,restartRequired:W,providerUnavailable:q});let _;switch(Z.status){case"installed-version":_=Z.latestVersion?e("settings.integrations.thirdParty.status.installedVersion",{version:Z.latestVersion}):e("settings.integrations.thirdParty.status.installed");break;case"update-available":_=Z.latestVersion?e("settings.integrations.thirdParty.status.updateAvailable",{version:Z.latestVersion}):e("settings.integrations.thirdParty.status.unpinned");break;case"not-installed":_=e("settings.integrations.thirdParty.status.notInstalled");break;case"installed":_=e("settings.integrations.thirdParty.status.installed");break;case"unpinned":_=e("settings.integrations.thirdParty.status.unpinned");break;case"ambiguous":_=e("settings.integrations.thirdParty.status.ambiguous");break;case"restart-required":_=e("settings.integrations.thirdParty.status.restartRequired");break;case"registry-unavailable":_=e("settings.integrations.thirdParty.status.registryUnavailable");break;case"provider-unavailable":_=e("settings.integrations.thirdParty.status.providerUnavailable");break}const ne=Z.status==="installed-version"?"success":Z.status==="update-available"||Z.status==="ambiguous"||Z.status==="restart-required"||Z.status==="registry-unavailable"||Z.status==="provider-unavailable"?"warning":"neutral",X={install:e("settings.integrations.thirdParty.actions.install"),update:e("settings.integrations.thirdParty.actions.update"),setup:e("settings.integrations.thirdParty.actions.setup"),manage:e("settings.integrations.thirdParty.actions.managePlugins")}[K],te=S.has(y.id);return s.jsx(Gd,{settingsItem:`integrations.third-party.${y.id}`,logo:s.jsx($n,{providerId:y.providerId,alt:"",className:"size-5"}),name:e(y.nameKey),description:e(y.descriptionKey),status:_,statusTone:ne,open:te,onOpenChange:he=>O(y.id,he),children:s.jsxs("div",{className:"space-y-3",children:[L.projectEntries.length>0?s.jsx("p",{className:"text-xs text-muted-foreground",children:e("settings.integrations.thirdParty.status.projectInstalled")}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(V,{type:"button",size:"sm",variant:K==="manage"?"outline":"default",onClick:()=>{D(y)},disabled:$,children:[G?s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}):K==="setup"?s.jsx(B,{name:"plug-2",className:"size-3.5"}):null,X]}),s.jsxs(V,{type:"button",size:"sm",variant:"secondary",onClick:()=>{_s(y.homepage)},children:[s.jsx(B,{name:"external-link",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.docs")]}),L.userEntry&&!L.userEntryIsAmbiguous?s.jsxs(V,{type:"button",size:"sm",variant:"destructive",onClick:()=>w(y),disabled:G,children:[s.jsx(B,{name:"delete-bin",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.remove")]}):null]})]})},y.id)};return s.jsxs(s.Fragment,{children:[s.jsx(He,{title:e("settings.integrations.thirdParty.title"),info:e("settings.integrations.thirdParty.info"),divider:t,settingsItem:"integrations.third-party",contentClassName:"space-y-3",children:sr.map(I)}),s.jsx(_t,{open:N!==null,onOpenChange:y=>!y&&w(null),children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:e("settings.integrations.thirdParty.dialog.remove.title")}),s.jsx(qt,{children:e("settings.integrations.thirdParty.dialog.remove.description",{name:N?e(N.nameKey):""})})]}),s.jsxs(as,{children:[s.jsx(V,{type:"button",size:"sm",variant:"ghost",onClick:()=>w(null),children:e("settings.common.actions.cancel")}),s.jsx(V,{type:"button",size:"sm",variant:"destructive",onClick:()=>{R()},children:e("settings.integrations.thirdParty.actions.remove")})]})]})})]})},Wd=t=>t==="invalid-path"?"settings.extensions.toast.invalidPath":t==="invalid-url"?"settings.extensions.toast.invalidUrl":t==="not-found"?"settings.extensions.toast.notFound":t==="invalid-manifest"?"settings.extensions.toast.invalidManifest":t==="reserved-id"?"settings.extensions.toast.reservedId":t==="id-taken"?"settings.extensions.toast.idTaken":t==="already-installed"?"settings.extensions.toast.alreadyInstalled":t==="missing-build"?"settings.extensions.toast.missingBuild":t==="host-too-old"?"settings.extensions.toast.hostTooOld":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="extract-failed"?"settings.extensions.toast.extractFailed":t==="too-large"?"settings.extensions.toast.zipTooLarge":t==="enterprise-mode"?"settings.extensions.toast.enterpriseMode":"settings.extensions.toast.failed",Jd=t=>t==="not-git"?"settings.extensions.toast.notGit":t==="enterprise-mode"?"settings.extensions.toast.enterpriseUpdate":t==="clone-failed"?"settings.extensions.toast.cloneFailed":t==="invalid-manifest"?"settings.extensions.toast.invalidManifest":t==="missing-build"?"settings.extensions.toast.missingBuild":t==="swap-failed"?"settings.extensions.toast.swapFailed":t==="not-found"?"settings.extensions.toast.notFound":"settings.extensions.toast.updateFailed",my=Os({error:Gr(["invalid-path","invalid-url","not-found","invalid-manifest","id-taken","already-installed","missing-build","host-too-old","bundled","reserved-id","clone-failed","extract-failed","too-large","enterprise-mode"]),required:Rt().trim().min(1).max(64).optional(),id:Rt().trim().min(1).max(128).optional()}),py=t=>{const e=t.trim();if(!e)return{ok:!1,code:"invalid-path"};if(e.slice(0,8).toLowerCase()==="https://")return{ok:!0,request:{url:e}};if(e.slice(0,6).toLowerCase()==="ssh://"||/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?[A-Za-z0-9][A-Za-z0-9.-]*\.[A-Za-z0-9.-]+:[^\s]+$/.test(e))return{ok:!0,request:{url:e}};const a=/^[a-zA-Z]:[\\/]/.test(e);return/^[a-z][a-z0-9+.-]*:/i.test(e)&&!a?{ok:!1,code:"invalid-url"}:e.startsWith("/")||a||e.startsWith("\\\\")?{ok:!0,request:{path:e}}:{ok:!1,code:"invalid-path"}},Qd=async t=>{try{const e=my.safeParse(JSON.parse(await t.text()));return e.success?e.data.error==="host-too-old"&&e.data.required&&e.data.id?{code:"host-too-old",required:e.data.required,id:e.data.id}:e.data.error==="host-too-old"&&e.data.required?{code:"host-too-old",required:e.data.required}:e.data.id?{code:e.data.error,id:e.data.id}:{code:e.data.error}:{code:"failed"}}catch{return{code:"failed"}}},Yd=async(t,e)=>{if(!t.ok)return{ok:!1,...await Qd(t),diagnostic:{method:"POST",path:e,kind:"http",status:t.status}};const a=await t.text().catch(()=>null),n=a===null?null:ud(a);return n?{ok:!0,guest:n,replaced:t.status===200}:{ok:!1,code:"failed",diagnostic:{method:"POST",path:e,kind:"invalid-response",status:t.status}}},Zd=async(t,e={})=>{const a=py(t);if(!a.ok)return a;const n={...a.request};e.replace&&(n.replace=!0),"url"in n&&e.gitIdentityId&&(n.gitIdentityId=e.gitIdentityId);try{const i=await It("/api/guests",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});return await Yd(i,"/api/guests")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests",kind:"network"}}}},gy=async(t,e={})=>{try{const a=await It("/api/guests/upload",{method:"POST",query:{replace:e.replace?"true":void 0,name:t.name||void 0},headers:{"Content-Type":"application/octet-stream",Accept:"application/json"},body:t});return await Yd(a,"/api/guests/upload")}catch{return{ok:!1,code:"failed",diagnostic:{method:"POST",path:"/api/guests/upload",kind:"network"}}}},Xd=async t=>{try{const e=await It(`/api/guests/${t}`,{method:"DELETE"});return e.status===204?{ok:!0}:{ok:!1,code:(await Qd(e)).code}}catch{return{ok:!1,code:"failed"}}},eu=async(t,e)=>{try{return(await It(`/api/guests/${t}/enabled`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:e})})).ok}catch{return!1}},fy=async(t,e)=>{try{return(await It(`/api/guests/${t}/capabilities`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({granted:e})})).ok}catch{return!1}},hy=Os({updates:Bn(Rt().min(1),Zu)}),xy=Os({error:Gr(["not-git","clone-failed","invalid-manifest","missing-build","host-too-old","swap-failed","not-found","enterprise-mode"]),required:Rt().trim().min(1).max(64).optional()}),Tc=async t=>{try{const e=await It("/api/guests/updates/check",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({force:t})});if(!e.ok)return{ok:!1};const a=hy.safeParse(JSON.parse(await e.text()));return a.success?{ok:!0,updates:a.data.updates}:{ok:!1}}catch{return{ok:!1}}},by=async t=>{try{const e=xy.safeParse(JSON.parse(await t.text()));return e.success?e.data.required?{code:e.data.error,required:e.data.required}:{code:e.data.error}:{code:"failed"}}catch{return{code:"failed"}}},tu=async t=>{try{const e=await It(`/api/guests/${t}/update`,{method:"POST",headers:{Accept:"application/json"}});if(!e.ok){const n=await by(e);return n.required?{ok:!1,code:n.code,required:n.required}:{ok:!1,code:n.code}}const a=ud(await e.text());return a?{ok:!0,guest:a}:{ok:!1,code:"failed"}}catch{return{ok:!1,code:"failed"}}},vy={guestId:"excalidraw",gitUrl:"https://github.com/openchamber/openchamber-excalidraw",homepage:"https://github.com/openchamber/openchamber-excalidraw",nameKey:"settings.integrations.extensionCatalog.excalidraw.name",descriptionKey:"settings.integrations.extensionCatalog.excalidraw.description",logoFileName:"drawing.excalidraw"},yy=[vy],jy=(t,e)=>{const a=t.find(n=>n.id===e.guestId);return a?a.enterpriseBlocked?.length?{kind:"blocked",guest:a}:Qa(a)?{kind:"needs-approval",guest:a}:a.enabled===!1?{kind:"paused",guest:a}:a.update?{kind:"update-available",guest:a,version:a.update.version}:{kind:"installed",guest:a}:{kind:"not-installed"}},ky=({divider:t=!0})=>{const{t:e}=Be(),a=Ks(u=>u.guests),n=Ks(u=>u.status),[i,o]=l.useState(null),[r,d]=l.useState(()=>new Set),[c,g]=l.useState(null);l.useEffect(()=>{gn()},[]);const p=l.useCallback(()=>{re.getState().requestSettingsJump("extensions")},[]),h=l.useCallback(async(u,j,N)=>{const w=ln();o({guestId:u.guestId,action:j});try{await N(),ln()===w&&await gn()}finally{o(null)}},[]),f=u=>h(u,"install",async()=>{const j=await Zd(u.gitUrl);if(!j.ok){U.error(j.code==="host-too-old"&&j.required?e("settings.extensions.toast.hostTooOld",{version:j.required}):e(Wd(j.code)));return}U.success(e("settings.integrations.thirdParty.toast.installed",{name:e(u.nameKey)})),Qa(j.guest)&&p()}),m=u=>h(u,"update",async()=>{const j=await tu(u.guestId);if(!j.ok){U.error(j.code==="host-too-old"&&j.required?e("settings.extensions.toast.hostTooOld",{version:j.required}):e(Jd(j.code)));return}xi(u.guestId),U.success(e("settings.integrations.thirdParty.toast.updated",{name:e(u.nameKey)})),Qa(j.guest)&&p()}),v=u=>h(u,"enable",async()=>{if(!await eu(u.guestId,!0)){U.error(e("settings.integrations.extensionCatalog.toast.enableFailed",{name:e(u.nameKey)}));return}U.success(e("settings.integrations.extensionCatalog.toast.enabled",{name:e(u.nameKey)}))}),C=async()=>{const u=c;u&&(g(null),await h(u,"remove",async()=>{if(!(await Xd(u.guestId)).ok){U.error(e("settings.integrations.thirdParty.toast.actionFailed"));return}xi(u.guestId),U.success(e("settings.integrations.thirdParty.toast.removed",{name:e(u.nameKey)}))}))},b=u=>{switch(u.kind){case"not-installed":return{status:e("settings.integrations.thirdParty.status.notInstalled"),tone:"neutral"};case"blocked":return{status:e("settings.extensions.status.enterpriseBlocked"),tone:"warning"};case"needs-approval":return{status:e("settings.integrations.extensionCatalog.status.needsApproval"),tone:"warning"};case"paused":return{status:e("settings.integrations.extensionCatalog.status.paused"),tone:"neutral"};case"update-available":return{status:e("settings.integrations.thirdParty.status.updateAvailable",{version:u.version}),tone:"warning"};case"installed":return{status:u.guest.version?e("settings.integrations.thirdParty.status.installedVersion",{version:u.guest.version}):e("settings.integrations.thirdParty.status.installed"),tone:"success"}}},k=u=>{const j=jy(a,u),N=n==="idle"||n==="loading",{status:w,tone:S}=N?{status:e("common.loading"),tone:"neutral"}:b(j),A=i?.guestId===u.guestId||N,x=r.has(u.guestId),E=s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"}),M=j.kind==="not-installed"?{label:e("settings.integrations.thirdParty.actions.install"),onClick:()=>{f(u)},variant:"default"}:j.kind==="update-available"?{label:e("settings.integrations.thirdParty.actions.update"),onClick:()=>{m(u)},variant:"default"}:j.kind==="paused"?{label:e("settings.integrations.extensionCatalog.actions.enable"),onClick:()=>{v(u)},variant:"default"}:j.kind==="needs-approval"||j.kind==="blocked"?{label:e("settings.integrations.extensionCatalog.actions.manage"),onClick:p,variant:"outline"}:null;return s.jsx(Gd,{settingsItem:`integrations.extensions.${u.guestId}`,logo:s.jsx(Xu,{filePath:u.logoFileName,className:"size-5"}),name:e(u.nameKey),description:e(u.descriptionKey),status:w,statusTone:S,open:x,onOpenChange:T=>d(D=>{const R=new Set(D);return T?R.add(u.guestId):R.delete(u.guestId),R}),children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[M?s.jsxs(V,{type:"button",size:"sm",variant:M.variant,onClick:M.onClick,disabled:A,children:[A?E:null,M.label]}):null,s.jsxs(V,{type:"button",size:"sm",variant:"secondary",onClick:()=>{_s(u.homepage)},children:[s.jsx(B,{name:"external-link",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.docs")]}),j.kind!=="not-installed"?s.jsxs(V,{type:"button",size:"sm",variant:"destructive",onClick:()=>g(u),disabled:A,children:[s.jsx(B,{name:"delete-bin",className:"size-3.5"}),e("settings.integrations.thirdParty.actions.remove")]}):null]})},u.guestId)};return n==="unsupported"?null:s.jsxs(s.Fragment,{children:[s.jsx(He,{title:e("settings.integrations.extensionCatalog.title"),info:e("settings.integrations.extensionCatalog.info"),divider:t,settingsItem:"integrations.extensions",contentClassName:"space-y-3",children:yy.map(k)}),s.jsx(_t,{open:c!==null,onOpenChange:u=>!u&&g(null),children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Vt,{children:[s.jsx(Ht,{children:e("settings.integrations.extensionCatalog.dialog.remove.title")}),s.jsx(qt,{children:e("settings.integrations.extensionCatalog.dialog.remove.description",{name:c?e(c.nameKey):""})})]}),s.jsxs(as,{children:[s.jsx(V,{type:"button",size:"sm",variant:"ghost",onClick:()=>g(null),children:e("settings.common.actions.cancel")}),s.jsx(V,{type:"button",size:"sm",variant:"destructive",onClick:()=>{C()},children:e("settings.integrations.thirdParty.actions.remove")})]})]})})]})},wy=()=>{const t=_e.c(25),{t:e}=Be();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=ms(),t[0]=a):a=t[0];const n=!a,i=!!qa()?.linear,o=Ks(Sy),r=Ks(Ny);let d,c,g,p,h,f;if(t[1]!==o||t[2]!==r||t[3]!==e){const k=!ms()&&!kd()?o.filter(Cy):[];c=n||i||k.length>0,d=ns,t[10]!==e?(g=e("settings.page.integrations.title"),t[10]=e,t[11]=g):g=t[11],t[12]!==e?(p=e("settings.page.integrations.description"),t[12]=e,t[13]=p):p=t[13],h=!0,f=c?s.jsxs(He,{title:e("settings.integrations.firstParty.title"),info:e("settings.integrations.firstParty.info"),divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[n?s.jsx(Yv,{}):null,i?s.jsx(oy,{}):null,k.map(u=>s.jsx(qd,{guest:u},`${r}:${u.id}`))]}):null,t[1]=o,t[2]=r,t[3]=e,t[4]=d,t[5]=c,t[6]=g,t[7]=p,t[8]=h,t[9]=f}else d=t[4],c=t[5],g=t[6],p=t[7],h=t[8],f=t[9];let m;t[14]!==c?(m=s.jsx(uy,{divider:c}),t[14]=c,t[15]=m):m=t[15];let v,C;t[16]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(ky,{}),C=s.jsx(Hv,{}),t[16]=v,t[17]=C):(v=t[16],C=t[17]);let b;return t[18]!==d||t[19]!==g||t[20]!==p||t[21]!==h||t[22]!==f||t[23]!==m?(b=s.jsxs(d,{title:g,description:p,showSaveStatus:h,children:[f,m,v,C]}),t[18]=d,t[19]=g,t[20]=p,t[21]=h,t[22]=f,t[23]=m,t[24]=b):b=t[24],b};function Sy(t){return t.guests}function Ny(t){return t.runtimeKey}function Cy(t){return t.source==="bundled"&&t.integration&&_r(t)}const li="__default__",Iy=500,Py=(t,e)=>{const a=n=>JSON.stringify({...n,categories:n.categories.map(i=>({...i,name:i.name.trim(),description:i.description.trim()}))});return a(t)===a(e)},Ay=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,64),su=(t,e)=>{const a=_e.c(7),n=ct(Dy);let i;e:{if(!t||!e){let r;a[0]===Symbol.for("react.memo_cache_sentinel")?(r=[],a[0]=r):r=a[0],i=r;break e}let o;if(a[1]!==e||a[2]!==t||a[3]!==n){let r;a[5]!==t?(r=g=>g.id===t,a[5]=t,a[6]=r):r=a[6];const c=n.find(r)?.models.find(g=>g.id===e);o=em(c),a[1]=e,a[2]=t,a[3]=n,a[4]=o}else o=a[4];i=o}return i},nu=(t,e)=>t&&(e.length===0||e.includes(t))?t:null,au=t=>{const e=_e.c(51),{providerID:a,modelID:n,value:i,onChange:o,ariaLabel:r,className:d}=t,{t:c}=Be(),g=su(a,n);let p,h,f,m,v,C,b,k,u,j,N;if(e[0]!==r||e[1]!==d||e[2]!==o||e[3]!==c||e[4]!==i||e[5]!==g){const D=nu(i,g)??li;let R;e[17]!==c?(R=O=>O===li?c("settings.routing.thinking.default"):O.charAt(0).toUpperCase()+O.slice(1),e[17]=c,e[18]=R):R=e[18],m=R,f=Dt,u=D,e[19]!==o?(j=O=>o(O===li?null:O),e[19]=o,e[20]=j):j=e[20],N=g.length===0,h=Tt,C=Qt,e[21]!==d?(b=Se(fn,d),e[21]=d,e[22]=b):b=e[22],k=r,p=Jt,v=m(D),e[0]=r,e[1]=d,e[2]=o,e[3]=c,e[4]=i,e[5]=g,e[6]=p,e[7]=h,e[8]=f,e[9]=m,e[10]=v,e[11]=C,e[12]=b,e[13]=k,e[14]=u,e[15]=j,e[16]=N}else p=e[6],h=e[7],f=e[8],m=e[9],v=e[10],C=e[11],b=e[12],k=e[13],u=e[14],j=e[15],N=e[16];let w;e[23]!==p||e[24]!==v?(w=s.jsx(p,{children:v}),e[23]=p,e[24]=v,e[25]=w):w=e[25];let S;e[26]!==h||e[27]!==C||e[28]!==b||e[29]!==k||e[30]!==w?(S=s.jsx(h,{size:C,className:b,"aria-label":k,children:w}),e[26]=h,e[27]=C,e[28]=b,e[29]=k,e[30]=w,e[31]=S):S=e[31];let A;e[32]!==m?(A=m(li),e[32]=m,e[33]=A):A=e[33];let x;e[34]!==A?(x=s.jsx(gt,{value:li,children:A}),e[34]=A,e[35]=x):x=e[35];let E;if(e[36]!==m||e[37]!==g){let D;e[39]!==m?(D=R=>s.jsx(gt,{value:R,children:m(R)},R),e[39]=m,e[40]=D):D=e[40],E=g.map(D),e[36]=m,e[37]=g,e[38]=E}else E=e[38];let M;e[41]!==x||e[42]!==E?(M=s.jsxs(Et,{children:[x,E]}),e[41]=x,e[42]=E,e[43]=M):M=e[43];let T;return e[44]!==f||e[45]!==M||e[46]!==u||e[47]!==j||e[48]!==N||e[49]!==S?(T=s.jsxs(f,{value:u,onValueChange:j,disabled:N,children:[S,M]}),e[44]=f,e[45]=M,e[46]=u,e[47]=j,e[48]=N,e[49]=S,e[50]=T):T=e[50],T},Ty=t=>{const e=_e.c(52),{category:a,expanded:n,onToggle:i,onChange:o,onReset:r,onRemove:d}=t,{t:c}=Be(),g=su(a.model?.providerID,a.model?.modelID);let p;e[0]!==a.variant||e[1]!==g?(p=nu(a.variant,g),e[0]=a.variant,e[1]=g,e[2]=p):p=e[2];const h=p;let f;e[3]!==a.model||e[4]!==h||e[5]!==c?(f=a.model?`${a.model.modelID}${h?` / ${h}`:""}`:c("settings.routing.model.useFallback"),e[3]=a.model,e[4]=h,e[5]=c,e[6]=f):f=e[6];const m=f;let v;e[7]!==a.agent||e[8]!==m?(v=[m,a.agent].filter(Boolean),e[7]=a.agent,e[8]=m,e[9]=v):v=e[9];const C=v.join(" · "),b=!a.enabled&&"opacity-60";let k;e[10]!==b?(k=Se("py-1",b),e[10]=b,e[11]=k):k=e[11];const u=n?"arrow-down-s":"arrow-right-s";let j;e[12]!==u?(j=s.jsx(B,{name:u,className:"size-4 flex-shrink-0 text-muted-foreground"}),e[12]=u,e[13]=j):j=e[13];const N=a.name||a.id;let w;e[14]!==N?(w=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:N}),e[14]=N,e[15]=w):w=e[15];let S;e[16]!==C?(S=s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:C}),e[16]=C,e[17]=S):S=e[17];let A;e[18]!==n||e[19]!==i||e[20]!==S||e[21]!==j||e[22]!==w?(A=s.jsxs("button",{type:"button",onClick:i,"aria-expanded":n,className:"flex min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-1.5 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[j,w,S]}),e[18]=n,e[19]=i,e[20]=S,e[21]=j,e[22]=w,e[23]=A):A=e[23];const x=a.enabled;let E;e[24]!==o?(E=I=>o({enabled:I}),e[24]=o,e[25]=E):E=e[25];let M;e[26]!==a.name||e[27]!==c?(M=c("settings.routing.category.enabledAria",{name:a.name}),e[26]=a.name,e[27]=c,e[28]=M):M=e[28];let T;e[29]!==a.enabled||e[30]!==E||e[31]!==M?(T=s.jsx(fa,{checked:x,onCheckedChange:E,"aria-label":M}),e[29]=a.enabled,e[30]=E,e[31]=M,e[32]=T):T=e[32];let D;e[33]!==A||e[34]!==T?(D=s.jsxs("div",{className:"flex items-center gap-2",children:[A,T]}),e[33]=A,e[34]=T,e[35]=D):D=e[35];let R;e[36]!==a.agent||e[37]!==a.description||e[38]!==a.model?.modelID||e[39]!==a.model?.providerID||e[40]!==a.name||e[41]!==a.variant||e[42]!==n||e[43]!==o||e[44]!==d||e[45]!==r||e[46]!==c?(R=n?s.jsxs("div",{className:"space-y-4 px-1 pb-4 pt-2",children:[s.jsxs(Fn,{children:[s.jsx(Kt,{label:c("settings.routing.category.name"),controlClassName:"max-w-none",children:s.jsx(Ge,{value:a.name,onChange:I=>o({name:I.target.value}),"aria-label":c("settings.routing.category.name"),className:"h-8 w-full rounded-md px-3",maxLength:60})}),s.jsx(Kt,{label:c("settings.routing.category.agent"),info:c("settings.routing.category.agentInfo"),controlClassName:"max-w-none",children:s.jsx(Fr,{agentName:a.agent??"",onChange:I=>o({agent:I||null}),filter:My,className:Se(Zs,"w-full")})}),s.jsx(Kt,{label:c("settings.routing.category.model"),info:c("settings.routing.category.modelInfo"),controlClassName:"max-w-none",children:s.jsx(ga,{providerId:a.model?.providerID??"",modelId:a.model?.modelID??"",onChange:(I,y)=>o({model:{providerID:I,modelID:y},variant:null}),className:Se(Zs,"w-full"),placeholder:c("settings.routing.model.useFallback")})}),s.jsx(Kt,{label:c("settings.routing.category.thinking"),controlClassName:"max-w-none",children:s.jsx(au,{providerID:a.model?.providerID,modelID:a.model?.modelID,value:a.variant,onChange:I=>o({variant:I}),ariaLabel:c("settings.routing.category.thinking"),className:"w-full"})})]}),s.jsx(Kt,{label:c("settings.routing.category.description"),info:c("settings.routing.category.descriptionInfo"),controlClassName:"max-w-none",children:s.jsx(Rs,{value:a.description,onChange:I=>o({description:I.target.value}),"aria-label":c("settings.routing.category.description"),rows:5,maxLength:2e3,className:"w-full"})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r?s.jsx(V,{size:"sm",variant:"outline",onClick:r,children:c("settings.routing.category.reset")}):null,s.jsx(V,{size:"sm",variant:"ghost",onClick:d,children:c("settings.routing.category.remove")})]})]}):null,e[36]=a.agent,e[37]=a.description,e[38]=a.model?.modelID,e[39]=a.model?.providerID,e[40]=a.name,e[41]=a.variant,e[42]=n,e[43]=o,e[44]=d,e[45]=r,e[46]=c,e[47]=R):R=e[47];let O;return e[48]!==D||e[49]!==R||e[50]!==k?(O=s.jsxs("div",{className:k,children:[D,R]}),e[48]=D,e[49]=R,e[50]=k,e[51]=O):O=e[51],O},Ey=()=>{const{t}=Be(),e=es(y=>y.available),a=es(y=>y.autoReady),n=es(y=>y.config),i=es(y=>y.builtins),o=es(y=>y.loaded),r=es(y=>y.loadError),d=es(y=>y.load),c=es(y=>y.saveConfig),[g,p]=l.useState(n),[h,f]=l.useState(""),[m,v]=l.useState(null),C=l.useRef(null),b=l.useRef(null),k=l.useRef(Promise.resolve()),u=l.useRef(0);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{C.current||u.current>0||p(y=>y&&n&&Py(n,y)?y:n)},[n]);const j=l.useCallback(()=>{const y=C.current;if(!y||(C.current=null,y.runtimeKey!==ln()))return k.current;u.current+=1,os("saving");const L=k.current.then(async()=>{try{if(y.runtimeKey!==ln()){os("saved");return}await c(y.config),os("saved")}catch{os("error")}finally{u.current-=1}});return k.current=L,L},[c]);l.useEffect(()=>()=>{b.current&&clearTimeout(b.current),j()},[j]);const N=ct(y=>y.settingsDefaultModel),w=ct(y=>y.settingsDefaultVariant),S=l.useRef(!1);l.useEffect(()=>{if(S.current||!o||!n||n.fallback)return;const y=_n(N);!y||wd(y.providerId,y.modelId)||(S.current=!0,A(L=>L.fallback?L:{...L,fallback:{model:{providerID:y.providerId,modelID:y.modelId},variant:w??null}}))},[o,n,N,w]);const A=l.useCallback(y=>{p(L=>{if(!L)return L;const K=y(L);return C.current={config:K,runtimeKey:ln()},b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{b.current=null,j()},Iy),K})},[j]),x=l.useCallback((y,L)=>{A(K=>({...K,categories:K.categories.map(H=>H.id===y?{...H,...L}:H)}))},[A]),E=()=>{const y=h.trim();if(!y||!g)return;const L=Ay(y)||`category-${Date.now()}`;let K=L,H=2;for(;g.categories.some(G=>G.id===K);)K=`${L}-${H++}`;A(G=>({...G,categories:[...G.categories,{id:K,builtin:!1,enabled:!0,name:y,description:"",model:null,variant:null,agent:null}]})),f(""),v(K)},M=y=>{const L=i.find(K=>K.id===y);L&&x(y,{name:L.name,description:L.description,model:null,variant:null,agent:null,enabled:!0})},T=y=>{const L=i.find(K=>K.id===y);L&&A(K=>({...K,categories:[...K.categories,{id:y,builtin:!0,enabled:!0,name:L.name,description:L.description,model:null,variant:null,agent:null}]}))},D=y=>{A(L=>({...L,categories:L.categories.filter(K=>K.id!==y)}))},R=g?.categories.filter(y=>y.enabled).length??0,O=i.filter(y=>!g?.categories.some(L=>L.id===y.id)),I=g?.enabled?g.fallback?R<2?t("settings.routing.status.tooFewCategories"):t(a?"settings.routing.status.ready":"settings.routing.status.notReady"):t("settings.routing.status.noFallback"):t("settings.routing.status.disabled");return s.jsxs(ns,{title:t("settings.page.routing.title"),description:t("settings.page.routing.description"),showSaveStatus:!0,children:[r?s.jsx("p",{className:Pn,children:t("settings.routing.loadError",{error:r})}):null,!o||!g?null:e?s.jsxs(s.Fragment,{children:[s.jsx(He,{title:t("settings.routing.auto.title"),divider:!1,children:s.jsxs("div",{className:Ms,children:[s.jsx(xo,{}),s.jsx("div",{className:ys,children:s.jsx(xt,{settingsItem:"routing.enabled",checked:g.enabled,onChange:y=>A(L=>({...L,enabled:y})),label:t("settings.routing.auto.enable"),ariaLabel:t("settings.routing.auto.enable"),info:t("settings.routing.auto.enableInfo")})}),s.jsx("p",{className:ls,children:I}),s.jsx(Ct,{settingsItem:"routing.fallback-model",label:t("settings.routing.auto.fallbackModel"),info:t("settings.routing.auto.fallbackModelInfo"),children:s.jsx(ga,{providerId:g.fallback?.model.providerID??"",modelId:g.fallback?.model.modelID??"",onChange:(y,L)=>A(K=>({...K,fallback:{model:{providerID:y,modelID:L},variant:null}})),className:Zs,placeholder:t("settings.routing.model.placeholder")})}),s.jsx(Ct,{settingsItem:"routing.fallback-thinking",label:t("settings.routing.auto.fallbackThinking"),info:t("settings.routing.auto.fallbackThinkingInfo"),children:s.jsx(au,{providerID:g.fallback?.model.providerID,modelID:g.fallback?.model.modelID,value:g.fallback?.variant??null,onChange:y=>A(L=>L.fallback?{...L,fallback:{...L.fallback,variant:y}}:L),ariaLabel:t("settings.routing.auto.fallbackThinking")})})]})}),s.jsx(He,{title:t("settings.routing.categories.title"),children:s.jsxs("div",{className:Ms,children:[s.jsx("p",{className:ls,children:t("settings.routing.categories.description")}),s.jsx("div",{className:"divide-y divide-border/40 border-y border-border/40",children:g.categories.map(y=>s.jsx(Ty,{category:y,expanded:m===y.id,onToggle:()=>v(L=>L===y.id?null:y.id),onChange:L=>x(y.id,L),onReset:y.builtin?()=>M(y.id):null,onRemove:()=>D(y.id)},y.id))}),O.length>0?s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:O.map(y=>s.jsx(V,{size:"sm",variant:"outline",onClick:()=>T(y.id),children:t("settings.routing.category.restore",{name:y.name})},y.id))}):null,s.jsx(Ct,{label:t("settings.routing.categories.addLabel"),settingsItem:"routing.add-category",children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(Ge,{value:h,onChange:y=>f(y.target.value),onKeyDown:y=>{y.key==="Enter"&&E()},placeholder:t("settings.routing.categories.addPlaceholder"),"aria-label":t("settings.routing.categories.addLabel"),className:"h-8 rounded-md px-3 min-w-0 flex-1",maxLength:60}),s.jsx(V,{size:"sm",variant:"outline",onClick:E,disabled:h.trim().length===0,children:t("settings.routing.categories.add")})]})})]})})]}):s.jsx("p",{className:Pn,children:t("settings.routing.unavailable")})]})};function Dy(t){return t.providers}function My(t){return md(t.mode)}const Ry={prompt:{icon:"chat-1",titleKey:"settings.extensions.capability.prompt",detailKey:"settings.extensions.capability.prompt.detail"},sessions:{icon:"git-branch",titleKey:"settings.extensions.capability.sessions",detailKey:"settings.extensions.capability.sessions.detail"},files:{icon:"file-text",titleKey:"settings.extensions.capability.files",detailKey:"settings.extensions.capability.files.detail"},model:{icon:"sparkling",titleKey:"settings.extensions.capability.model",detailKey:"settings.extensions.capability.model.detail"},conversation:{icon:"chat-history",titleKey:"settings.extensions.capability.conversation",detailKey:"settings.extensions.capability.conversation.detail"},filesystem:{icon:"hard-drive-2",titleKey:"settings.extensions.capability.filesystem",detailKey:"settings.extensions.capability.filesystem.detail"},service:{icon:"terminal",titleKey:"settings.extensions.capability.service",detailKey:"settings.extensions.capability.service.detail"},network:{icon:"plug",titleKey:"settings.extensions.capability.network",detailKey:"settings.extensions.capability.network.detail"},origins:{icon:"global",titleKey:"settings.extensions.capability.origins",detailKey:"settings.extensions.capability.origins.detail"}},Oy=t=>{const e=_e.c(77),{guest:a,busy:n,onApprove:i,onDecline:o,onDismiss:r}=t,{t:d}=Be();let c;e[0]!==a?.capabilities.requested?(c=a?.capabilities.requested??[],e[0]=a?.capabilities.requested,e[1]=c):c=e[1];const g=c;let p;e[2]!==a?.filesystem?(p=a?.filesystem??[],e[2]=a?.filesystem,e[3]=p):p=e[3];const h=p;let f;e[4]!==a?.origins?(f=a?.origins??[],e[4]=a?.origins,e[5]=f):f=e[5];const m=f;let v;e[6]!==a?.service?.permissions?.exec?(v=a?.service?.permissions?.exec??[],e[6]=a?.service?.permissions?.exec,e[7]=v):v=e[7];const C=v;let b;e[8]!==a?.service?.permissions?.sockets?(b=a?.service?.permissions?.sockets??[],e[8]=a?.service?.permissions?.sockets,e[9]=b):b=e[9];const k=b,u=a?.service;let j;e[10]!==u?(j=pd(u,"browser"),e[10]=u,e[11]=j):j=e[11];const N=j,w=a?.integration?.apiOrigin??null,S=a!==null;let A;e[12]!==n||e[13]!==r?(A=ne=>{!ne&&!n&&r()},e[12]=n,e[13]=r,e[14]=A):A=e[14];const x=a?.name??"";let E;e[15]!==d||e[16]!==x?(E=d("settings.extensions.dialog.approveTitle",{name:x}),e[15]=d,e[16]=x,e[17]=E):E=e[17];let M;e[18]!==E?(M=s.jsx(Ht,{children:E}),e[18]=E,e[19]=M):M=e[19];const T=a?.name??"",D=a?.version?`v${a.version}`:"";let R;e[20]!==d||e[21]!==T||e[22]!==D?(R=d("settings.extensions.dialog.approveDescription",{name:T,version:D}),e[20]=d,e[21]=T,e[22]=D,e[23]=R):R=e[23];let O;e[24]!==R?(O=s.jsx(qt,{children:R}),e[24]=R,e[25]=O):O=e[25];let I;e[26]!==M||e[27]!==O?(I=s.jsxs(Vt,{children:[M,O]}),e[26]=M,e[27]=O,e[28]=I):I=e[28];let y;if(e[29]!==w||e[30]!==h||e[31]!==m||e[32]!==N||e[33]!==g||e[34]!==C||e[35]!==k||e[36]!==d){let ne;e[38]!==w||e[39]!==h||e[40]!==m||e[41]!==N||e[42]!==C||e[43]!==k||e[44]!==d?(ne=X=>{const te=Ry[X];return s.jsxs("li",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-md bg-[var(--surface-muted)]",children:s.jsx(B,{name:te.icon,className:"size-4 text-foreground"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:d(te.titleKey)}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:d(te.detailKey)}),X==="filesystem"&&h.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:h.map(Ly)}):null,X==="origins"&&m.length>0?s.jsx("ul",{className:"mt-1 space-y-0.5",children:m.map(Fy)}):null,X==="network"&&w?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[d("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:w})]}):null,X==="service"&&C.length>0?s.jsxs("p",{className:"typography-meta mt-1 text-foreground",children:[d("settings.extensions.capability.service.runs")," ",s.jsx("span",{className:"break-all font-mono",children:C.join(", ")})]}):null,X==="service"&&k.length>0?s.jsxs("p",{className:"typography-meta mt-0.5 text-foreground",children:[d("settings.extensions.capability.service.sockets")," ",s.jsx("span",{className:"break-all font-mono",children:k.join(", ")})]}):null,X==="service"&&N?s.jsx("p",{className:"typography-meta mt-0.5 text-foreground",children:d("settings.extensions.capability.service.providesBrowser")}):null]})]},X)},e[38]=w,e[39]=h,e[40]=m,e[41]=N,e[42]=C,e[43]=k,e[44]=d,e[45]=ne):ne=e[45],y=g.map(ne),e[29]=w,e[30]=h,e[31]=m,e[32]=N,e[33]=g,e[34]=C,e[35]=k,e[36]=d,e[37]=y}else y=e[37];let L;e[46]!==y?(L=s.jsx("ul",{className:"space-y-3",children:y}),e[46]=y,e[47]=L):L=e[47];let K;e[48]!==a||e[49]!==o?(K=()=>a&&o(a),e[48]=a,e[49]=o,e[50]=K):K=e[50];let H;e[51]!==d?(H=d("settings.extensions.dialog.decline"),e[51]=d,e[52]=H):H=e[52];let G;e[53]!==n||e[54]!==K||e[55]!==H?(G=s.jsx(V,{size:"sm",variant:"ghost",disabled:n,onClick:K,children:H}),e[53]=n,e[54]=K,e[55]=H,e[56]=G):G=e[56];let W;e[57]!==a||e[58]!==i?(W=()=>a&&i(a),e[57]=a,e[58]=i,e[59]=W):W=e[59];let q;e[60]!==d?(q=d("settings.extensions.dialog.approve"),e[60]=d,e[61]=q):q=e[61];let z;e[62]!==n||e[63]!==W||e[64]!==q?(z=s.jsx(V,{size:"sm",disabled:n,onClick:W,children:q}),e[62]=n,e[63]=W,e[64]=q,e[65]=z):z=e[65];let $;e[66]!==G||e[67]!==z?($=s.jsxs(as,{children:[G,z]}),e[66]=G,e[67]=z,e[68]=$):$=e[68];let Z;e[69]!==I||e[70]!==L||e[71]!==$?(Z=s.jsxs($t,{className:"max-w-md",children:[I,L,$]}),e[69]=I,e[70]=L,e[71]=$,e[72]=Z):Z=e[72];let _;return e[73]!==Z||e[74]!==S||e[75]!==A?(_=s.jsx(_t,{open:S,onOpenChange:A,children:Z}),e[73]=Z,e[74]=S,e[75]=A,e[76]=_):_=e[76],_};function Ly(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}function Fy(t){return s.jsx("li",{className:"typography-meta break-all font-mono text-foreground",children:t},t)}const Ky=t=>{if(t.source!=="git"||!t.origin?.url)return null;const e=t.origin.url.trim(),a=/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?([A-Za-z0-9][A-Za-z0-9.-]*\.[A-Za-z0-9.-]+):([^\s]+)$/.exec(e);try{const n=new URL(a?`ssh://${a[1]}/${a[2]}`:e);if(n.protocol!=="https:"&&n.protocol!=="ssh:")return null;const i=n.protocol==="ssh:"?new URL(`https://${n.hostname}${n.pathname}`):n;return i.username="",i.password="",i.search="",i.hash="",i.pathname=i.pathname.replace(/\/+$/,"").replace(/\.git$/i,""),i.pathname==="/"?null:i.href}catch{return null}},ar=(t,e)=>{const a=`${t.method} ${t.path}`;return t.kind==="network"?`${a}: ${e("settings.extensions.request.noResponse")}`:t.kind==="invalid-response"?`${a}: ${e("settings.extensions.request.invalidResponse",{status:t.status})}`:`${a}: HTTP ${t.status}`},Ec=t=>t.name.toLowerCase().endsWith(".zip"),zy=t=>t==="path"?"settings.extensions.source.path":t==="zip"?"settings.extensions.source.zip":t==="git"?"settings.extensions.source.git":"settings.extensions.source.bundled",Uy=t=>{const e=(t.service?.socketBindings??[]).map(i=>i.resolved?`${i.id}=${i.resolved}`:`${i.id}?`),a=(t.service?.permissions?.sockets??[]).filter(i=>!(t.service?.socketBindings??[]).some(o=>o.id===i));return[...e,...a,...t.service?.permissions?.exec??[]].join(", ")},_y=t=>{const e=_e.c(27),{guest:a,binding:n,busy:i,onSaved:o}=t,{t:r}=Be(),[d,c]=l.useState(n.override??n.resolved??""),[g,p]=l.useState(!1),[h,f]=l.useState(!n.resolved);let m;e[0]!==n.override||e[1]!==n.resolved?(m=()=>{c(n.override??n.resolved??""),n.resolved||f(!0)},e[0]=n.override,e[1]=n.resolved,e[2]=m):m=e[2];let v;e[3]!==n.id||e[4]!==n.override||e[5]!==n.resolved?(v=[n.id,n.override,n.resolved],e[3]=n.id,e[4]=n.override,e[5]=n.resolved,e[6]=v):v=e[6],l.useEffect(m,v);let C;e[7]!==n.id||e[8]!==a.id||e[9]!==a.name||e[10]!==o||e[11]!==r?(C=async N=>{p(!0);const w=await Bp(a.id,n.id,N);if(p(!1),!w){U.error(r("settings.extensions.toast.socketSaveFailed"));return}U.success(r("settings.extensions.toast.socketSaved",{name:a.name})),f(!1),await o()},e[7]=n.id,e[8]=a.id,e[9]=a.name,e[10]=o,e[11]=r,e[12]=C):C=e[12];const b=C;let k;e[13]!==n.override||e[14]!==n.resolved?(k=()=>{c(n.override??n.resolved??""),n.resolved&&f(!1)},e[13]=n.override,e[14]=n.resolved,e[15]=k):k=e[15];const u=k;let j;return e[16]!==n.id||e[17]!==n.override||e[18]!==n.resolved||e[19]!==i||e[20]!==u||e[21]!==h||e[22]!==b||e[23]!==g||e[24]!==r||e[25]!==d?(j=s.jsx("div",{className:"space-y-1",children:h?s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx(Ge,{value:d,onChange:N=>c(N.target.value),placeholder:r("settings.extensions.service.socket.path",{id:n.id}),"aria-label":r("settings.extensions.service.socket.path.aria",{id:n.id}),className:"h-8 min-w-0 flex-1 rounded-md px-3",disabled:i||g,autoFocus:!0}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",disabled:i||g,"aria-label":r("settings.extensions.service.socket.save.aria",{id:n.id}),onClick:()=>{b(d.trim()||null)},children:r("settings.extensions.service.socket.save")}),n.override?s.jsx(V,{type:"button",variant:"ghost",size:"xs",disabled:i||g,"aria-label":r("settings.extensions.service.socket.clear.aria",{id:n.id}),onClick:()=>{b(null)},children:r("settings.extensions.service.socket.clear")}):null,n.resolved?s.jsx(V,{type:"button",variant:"ghost",size:"xs",disabled:i||g,"aria-label":r("settings.extensions.service.socket.cancel.aria",{id:n.id}),onClick:u,children:r("settings.extensions.service.socket.cancel")}):null]}):s.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[s.jsx("div",{className:"typography-meta min-w-0 flex-1 truncate text-muted-foreground",children:n.resolved?r("settings.extensions.service.socket.resolved",{path:n.resolved}):r("settings.extensions.service.socket.unresolved")}),s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:i||g,"aria-label":r("settings.extensions.service.socket.edit.aria",{id:n.id}),onClick:()=>f(!0),children:s.jsx(B,{name:"pencil",className:"h-3.5 w-3.5"})})]})}),e[16]=n.id,e[17]=n.override,e[18]=n.resolved,e[19]=i,e[20]=u,e[21]=h,e[22]=b,e[23]=g,e[24]=r,e[25]=d,e[26]=j):j=e[26],j},$y=t=>{const e=_e.c(151),{guest:a,busy:n,onReview:i,onRemove:o,onSetEnabled:r,onUpdate:d}=t,{t:c}=Be(),[g,p]=l.useState(!1),h=a.enabled!==!1,f=(a.enterpriseBlocked?.length??0)>0;let m;e[0]!==f||e[1]!==a?(m=!f&&Qa(a),e[0]=f,e[1]=a,e[2]=m):m=e[2];const v=m;let C,b,k,u,j,N,w,S,A,x,E,M,T,D,R;if(e[3]!==h||e[4]!==f||e[5]!==a||e[6]!==v||e[7]!==g||e[8]!==c){const _=Uy(a);k=!!(a.source&&a.source!=="bundled");const ne=a.source==="bundled";let X;e[24]!==a?(X=Ky(a),e[24]=a,e[25]=X):X=e[25],u=X,R=a.source==="git"?a.update:void 0;let te;e[26]!==a.icon||e[27]!==a.id?(te=ld(a.id,a.icon,yd().authenticatedAsset),e[26]=a.icon,e[27]=a.id,e[28]=te):te=e[28];const he=te;let je;e[29]!==ne||e[30]!==a.source||e[31]!==c?(je=ne?null:c(zy(a.source)),e[29]=ne,e[30]=a.source,e[31]=c,e[32]=je):je=e[32];const fe=a.version?`v${a.version}`:null;let ke;e[33]!==a.entry||e[34]!==c?(ke=a.entry?null:c("settings.extensions.source.noPanel"),e[33]=a.entry,e[34]=c,e[35]=ke):ke=e[35];let be;e[36]!==je||e[37]!==fe||e[38]!==ke?(be=[je,fe,ke].filter(Boolean),e[36]=je,e[37]=fe,e[38]=ke,e[39]=be):be=e[39];const De=be.join(" · "),oe=a.path||a.id;let ee;e[40]!==h||e[41]!==f||e[42]!==v||e[43]!==c?(ee=c(f?"settings.extensions.status.enterpriseBlocked":v?"settings.extensions.status.needsApproval":h?"settings.extensions.status.enabled":"settings.extensions.status.disabled"),e[40]=h,e[41]=f,e[42]=v,e[43]=c,e[44]=ee):ee=e[44];const ce=ee,ue=f||v?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":h?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";b=bn,j=g,N=p,T="overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]";let Ie;e[45]!==a.icon?(Ie=dd(a.icon),e[45]=a.icon,e[46]=Ie):Ie=e[46];let ve;e[47]!==he||e[48]!==Ie?(ve=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(cd,{icon:Ie,iconSrc:he,className:"size-5 text-foreground"})}),e[47]=he,e[48]=Ie,e[49]=ve):ve=e[49];let Re;e[50]!==a.name?(Re=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:a.name}),e[50]=a.name,e[51]=Re):Re=e[51];let Me;e[52]!==De?(Me=s.jsx("p",{className:"mt-0.5 truncate text-xs leading-snug text-muted-foreground",children:De}),e[52]=De,e[53]=Me):Me=e[53];let me;e[54]!==Re||e[55]!==Me?(me=s.jsxs("div",{className:"min-w-0 flex-1",children:[Re,Me]}),e[54]=Re,e[55]=Me,e[56]=me):me=e[56];let Te;e[57]!==ne||e[58]!==c?(Te=ne?s.jsx("span",{className:"shrink-0 rounded-full border border-[var(--interactive-border)] px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:c("settings.extensions.source.bundled")}):null,e[57]=ne,e[58]=c,e[59]=Te):Te=e[59];let Oe;e[60]!==c||e[61]!==R?(Oe=R?s.jsx("span",{className:"max-w-40 shrink-0 truncate rounded-full bg-[var(--status-info)]/15 px-2 py-0.5 text-[10px] font-medium text-[var(--status-info)]",children:c("settings.extensions.update.badge",{version:R.version})}):null,e[60]=c,e[61]=R,e[62]=Oe):Oe=e[62];let pe;e[63]!==ue?(pe=Se("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ue),e[63]=ue,e[64]=pe):pe=e[64];let xe;e[65]!==ce||e[66]!==pe?(xe=s.jsx("span",{"aria-live":"polite",className:pe,children:ce}),e[65]=ce,e[66]=pe,e[67]=xe):xe=e[67];const ae=g&&"rotate-180";let ie;e[68]!==ae?(ie=Se("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",ae),e[68]=ae,e[69]=ie):ie=e[69];let ge;e[70]!==ie?(ge=s.jsx(B,{name:"arrow-down-s",className:ie}),e[70]=ie,e[71]=ge):ge=e[71],e[72]!==ve||e[73]!==me||e[74]!==Te||e[75]!==Oe||e[76]!==xe||e[77]!==ge?(D=s.jsxs(vn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[ve,me,Te,Oe,xe,ge]}),e[72]=ve,e[73]=me,e[74]=Te,e[75]=Oe,e[76]=xe,e[77]=ge,e[78]=D):D=e[78],C=yn,M="border-t border-[var(--interactive-border)] px-4 py-4",w="space-y-3",e[79]!==oe?(S=s.jsx("p",{className:"typography-meta truncate font-mono text-muted-foreground",title:oe,children:oe}),e[79]=oe,e[80]=S):S=e[80],e[81]!==f||e[82]!==c?(A=f?s.jsx("p",{className:"typography-meta text-foreground",children:c("settings.extensions.enterpriseBlocked")}):null,e[81]=f,e[82]=c,e[83]=A):A=e[83],e[84]!==ne||e[85]!==c?(x=ne?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.builtIn.info")}):null,e[84]=ne,e[85]=c,e[86]=x):x=e[86],E=_?s.jsx("p",{className:"typography-meta truncate text-muted-foreground",children:c("settings.extensions.service.permissions",{list:_})}):null,e[3]=h,e[4]=f,e[5]=a,e[6]=v,e[7]=g,e[8]=c,e[9]=C,e[10]=b,e[11]=k,e[12]=u,e[13]=j,e[14]=N,e[15]=w,e[16]=S,e[17]=A,e[18]=x,e[19]=E,e[20]=M,e[21]=T,e[22]=D,e[23]=R}else C=e[9],b=e[10],k=e[11],u=e[12],j=e[13],N=e[14],w=e[15],S=e[16],A=e[17],x=e[18],E=e[19],M=e[20],T=e[21],D=e[22],R=e[23];let O;e[87]!==a.service||e[88]!==c?(O=a.service?s.jsx("p",{className:"typography-meta text-muted-foreground",children:c("settings.extensions.service.warning")}):null,e[87]=a.service,e[88]=c,e[89]=O):O=e[89];let I;e[90]!==n||e[91]!==h||e[92]!==a?(I=h?(a.service?.socketBindings??[]).map(_=>s.jsx(_y,{guest:a,binding:_,busy:n,onSaved:gn},_.id)):null,e[90]=n,e[91]=h,e[92]=a,e[93]=I):I=e[93];let y;e[94]!==n||e[95]!==a||e[96]!==d||e[97]!==c||e[98]!==R?(y=R?s.jsx(V,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.update.action.aria",{name:a.name,version:R.version}),onClick:()=>{d(a)},children:c("settings.extensions.update.action")}):null,e[94]=n,e[95]=a,e[96]=d,e[97]=c,e[98]=R,e[99]=y):y=e[99];let L;e[100]!==n||e[101]!==a||e[102]!==v||e[103]!==i||e[104]!==c?(L=v?s.jsx(V,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.review.aria",{name:a.name}),onClick:()=>i(a),children:c("settings.extensions.review")}):null,e[100]=n,e[101]=a,e[102]=v,e[103]=i,e[104]=c,e[105]=L):L=e[105];let K;e[106]!==n||e[107]!==h||e[108]!==a.id||e[109]!==a.name||e[110]!==r||e[111]!==c?(K=h?s.jsx(V,{type:"button",size:"sm",variant:"outline",disabled:n,"aria-label":c("settings.extensions.actions.disable.aria",{name:a.name}),onClick:()=>{r(a.id,a.name,!1)},children:c("settings.extensions.actions.disable")}):s.jsx(V,{type:"button",size:"sm",disabled:n,"aria-label":c("settings.extensions.actions.enable.aria",{name:a.name}),onClick:()=>{r(a.id,a.name,!0)},children:c("settings.extensions.actions.enable")}),e[106]=n,e[107]=h,e[108]=a.id,e[109]=a.name,e[110]=r,e[111]=c,e[112]=K):K=e[112];let H;e[113]!==n||e[114]!==k||e[115]!==a.id||e[116]!==a.name||e[117]!==o||e[118]!==c?(H=k?s.jsx(V,{type:"button",size:"sm",variant:"destructive",disabled:n,"aria-label":c("settings.extensions.remove.aria",{name:a.name}),onClick:()=>{o(a.id,a.name)},children:c("settings.extensions.remove")}):null,e[113]=n,e[114]=k,e[115]=a.id,e[116]=a.name,e[117]=o,e[118]=c,e[119]=H):H=e[119];let G;e[120]!==u||e[121]!==c?(G=u?s.jsxs(V,{type:"button",size:"sm",variant:"outline",className:"ml-auto",onClick:()=>{_s(u)},children:[s.jsx(B,{name:"external-link",className:"size-4"}),c("settings.extensions.actions.openSource")]}):null,e[120]=u,e[121]=c,e[122]=G):G=e[122];let W;e[123]!==y||e[124]!==L||e[125]!==K||e[126]!==H||e[127]!==G?(W=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[y,L,K,H,G]}),e[123]=y,e[124]=L,e[125]=K,e[126]=H,e[127]=G,e[128]=W):W=e[128];let q;e[129]!==O||e[130]!==I||e[131]!==W||e[132]!==w||e[133]!==S||e[134]!==A||e[135]!==x||e[136]!==E?(q=s.jsxs("div",{className:w,children:[S,A,x,E,O,I,W]}),e[129]=O,e[130]=I,e[131]=W,e[132]=w,e[133]=S,e[134]=A,e[135]=x,e[136]=E,e[137]=q):q=e[137];let z;e[138]!==C||e[139]!==q||e[140]!==M?(z=s.jsx(C,{className:M,children:q}),e[138]=C,e[139]=q,e[140]=M,e[141]=z):z=e[141];let $;e[142]!==z||e[143]!==T||e[144]!==D?($=s.jsxs("div",{className:T,children:[D,z]}),e[142]=z,e[143]=T,e[144]=D,e[145]=$):$=e[145];let Z;return e[146]!==b||e[147]!==j||e[148]!==N||e[149]!==$?(Z=s.jsx(b,{open:j,onOpenChange:N,children:$}),e[146]=b,e[147]=j,e[148]=N,e[149]=$,e[150]=Z):Z=e[150],Z},By=()=>{const t=_e.c(175),{t:e}=Be(),a=Ks(Vy),n=Ks(Hy),i=Ks(qy),o=Ks(Gy),[r,d]=l.useState(null),[c,g]=l.useState(!1),[p,h]=l.useState("global"),f=n==="unsupported",[m,v]=l.useState(""),C=ya(),[b,k]=l.useState(!1),[u,j]=l.useState(!1),N=l.useRef(!1),[w,S]=l.useState(null),[A,x]=l.useState(null),[E,M]=l.useState(!1),T=l.useRef(0),D=l.useRef(null);let R;t[0]===Symbol.for("react.memo_cache_sentinel")?(R=Zm(),t[0]=R):R=t[0];const O=R;let I;t[1]===Symbol.for("react.memo_cache_sentinel")?(I=[],t[1]=I):I=t[1],l.useEffect(Wy,I);let y,L;t[2]!==o||t[3]!==f?(y=()=>{let Ce=!1;if(d(null),g(!1),h("global"),S(null),x(null),N.current=!1,!f)return Promise.all([tm(),sm()]).then(qe=>{const[jt,Ot]=qe;Ce||d({runtimeKey:o,profiles:jt,global:Ot})}).catch(()=>{Ce||g(!0)}),()=>{Ce=!0}},L=[o,f],t[2]=o,t[3]=f,t[4]=y,t[5]=L):(y=t[4],L=t[5]),l.useEffect(y,L);const K=r?.runtimeKey===o?r:null;let H;t[6]!==e?(H=e("settings.gitIdentities.editor.title.globalIdentity"),t[6]=e,t[7]=H):H=t[7];const G=K?.global?.userName??"",W=K?.global?.userEmail??"";let q;t[8]!==H||t[9]!==G||t[10]!==W?(q={id:"global",name:H,userName:G,userEmail:W,icon:"fingerprint",color:"info"},t[8]=H,t[9]=G,t[10]=W,t[11]=q):q=t[11];let z;t[12]!==K?.profiles||t[13]!==q?(z=[q,...K?.profiles.filter(Jy)??[]],t[12]=K?.profiles,t[13]=q,t[14]=z):z=t[14];const $=z;let Z;t[15]!==$||t[16]!==p?(Z=$.find(Ce=>Ce.id===p)??$[0],t[15]=$,t[16]=p,t[17]=Z):Z=t[17];const _=Z;let ne,X;t[18]!==n?(ne=()=>{if(n!=="ready"||N.current)return;N.current=!0;const Ce=Ks.getState().runtimeKey;Tc(!1).then(qe=>{qe.ok&&Ks.getState().applyUpdates(qe.updates,Ce)})},X=[n],t[18]=n,t[19]=ne,t[20]=X):(ne=t[19],X=t[20]),l.useEffect(ne,X);let te;t[21]!==e?(te=async()=>{j(!0);const Ce=Ks.getState().runtimeKey,qe=await Tc(!0);if(j(!1),!qe.ok){U.error(e("settings.extensions.toast.checkFailed"));return}Ks.getState().applyUpdates(qe.updates,Ce),Object.keys(qe.updates).length===0&&U.success(e("settings.extensions.toast.upToDate"))},t[21]=e,t[22]=te):te=t[22];const he=te;let je;t[23]!==e?(je=async Ce=>{k(!0);const qe=await tu(Ce.id);if(k(!1),!qe.ok){U.error(qe.code==="host-too-old"&&qe.required?e("settings.extensions.toast.hostTooOld",{version:qe.required}):e(Jd(qe.code)));return}xi(Ce.id),U.success(e("settings.extensions.toast.updated",{name:qe.guest.name,version:qe.guest.version??""})),await gn(),Qa(qe.guest)&&x(qe.guest)},t[23]=e,t[24]=je):je=t[24];const fe=je;let ke;if(t[25]!==a||t[26]!==e){const Ce=async(qe,jt,Ot)=>{const Yt=Ot===void 0?{}:Ot;if(!qe.ok){if(Yt.allowConflictDialog!==!1&&(qe.code==="id-taken"||qe.code==="already-installed")){const Zt=qe.id?a.find(Ft=>Ft.id===qe.id):void 0;return S({source:jt,name:Zt?.name??qe.id??(jt.kind==="file"?jt.file.name:jt.input)}),!1}return qe.code==="host-too-old"?U.error(qe.required?e("settings.extensions.toast.hostTooOld",{version:qe.required}):e("settings.extensions.toast.failed"),{description:qe.diagnostic?ar(qe.diagnostic,e):void 0}):U.error(e(Wd(qe.code)),{description:qe.diagnostic?ar(qe.diagnostic,e):void 0}),!1}return v(""),S(null),U.success(qe.replaced?e("settings.extensions.toast.reinstalled",{name:qe.guest.name}):e("settings.extensions.toast.added",{name:qe.guest.name})),await gn(),Qa(qe.guest)&&x(qe.guest),!0};ke=async(qe,jt)=>{const Ot=jt===void 0?{}:jt,Yt=ln();qe.kind==="input"&&v(qe.input),k(!0);const Zt=qe.kind==="file"?await gy(qe.file,Ot):await Zd(qe.input,{...Ot,gitIdentityId:qe.gitIdentityId});k(!1),ln()===Yt&&await Ce(Zt,qe,{allowConflictDialog:!Ot.replace})},t[25]=a,t[26]=e,t[27]=ke}else ke=t[27];const be=ke;let De;t[28]!==m||t[29]!==be||t[30]!==_||t[31]!==e?(De=async()=>{const Ce=m.trim();if(!Ce){U.error(e("settings.extensions.toast.invalidPath"));return}await be({kind:"input",input:Ce,gitIdentityId:_.id})},t[28]=m,t[29]=be,t[30]=_,t[31]=e,t[32]=De):De=t[32];const oe=De;let ee;t[33]!==be?(ee=async()=>{if(!O)return;const Ce=await Xm("");Ce.success&&Ce.path&&await be({kind:"input",input:Ce.path})},t[33]=be,t[34]=ee):ee=t[34];const ce=ee;let ue;t[35]!==be?(ue=async()=>{if(!O){D.current?.click();return}const Ce=await Vr({filters:[{name:"ZIP Archive",extensions:["zip"]}]});Ce.success&&Ce.path&&await be({kind:"input",input:Ce.path})},t[35]=be,t[36]=ue):ue=t[36];const Ie=ue;let ve;t[37]!==be||t[38]!==e?(ve=async Ce=>{const qe=Ce.target.files?.[0]??null;if(Ce.target.value="",!!qe){if(!Ec(qe)){U.error(e("settings.extensions.toast.invalidPath"));return}await be({kind:"file",file:qe})}},t[37]=be,t[38]=e,t[39]=ve):ve=t[39];const Re=ve;let Me;t[40]!==b?(Me=Ce=>{b||(Ce.preventDefault(),T.current=T.current+1,M(!0))},t[40]=b,t[41]=Me):Me=t[41];const me=Me;let Te;t[42]!==b?(Te=Ce=>{b||(Ce.preventDefault(),Ce.dataTransfer.dropEffect="copy")},t[42]=b,t[43]=Te):Te=t[43];const Oe=Te;let pe;t[44]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>{T.current=Math.max(0,T.current-1),T.current===0&&M(!1)},t[44]=pe):pe=t[44];const xe=pe;let ae;t[45]!==b||t[46]!==be||t[47]!==e?(ae=async Ce=>{if(Ce.preventDefault(),T.current=0,M(!1),b)return;const qe=Ce.dataTransfer.items[0],jt=qe?.getAsFile()??null,Yt=(qe?.webkitGetAsEntry()??null)?.isDirectory===!0,Zt=jt!==null&&!Yt&&Ec(jt),Ft=jt&&O?ep(jt):null;if(Ft&&(Yt||Zt)){await be({kind:"input",input:Ft});return}if(Yt){U.error(e(O?"settings.extensions.toast.invalidPath":"settings.extensions.toast.folderNeedsZip"));return}if(!jt||!Zt){U.error(e("settings.extensions.toast.invalidPath"));return}await be({kind:"file",file:jt})},t[45]=b,t[46]=be,t[47]=e,t[48]=ae):ae=t[48];const ie=ae;let ge;t[49]!==w||t[50]!==be?(ge=async()=>{w&&await be(w.source,{replace:!0})},t[49]=w,t[50]=be,t[51]=ge):ge=t[51];const Ee=ge;let Ke;t[52]!==e?(Ke=async(Ce,qe)=>{k(!0);const jt=await Xd(Ce);if(k(!1),!jt.ok){U.error(e("settings.extensions.toast.removeFailed"));return}xi(Ce),U.success(e("settings.extensions.toast.removed",{name:qe})),await gn()},t[52]=e,t[53]=Ke):Ke=t[53];const Le=Ke;let Ne;t[54]!==e?(Ne=async Ce=>{k(!0);const qe=await fy(Ce.id,Ce.capabilities.requested);if(k(!1),!qe){U.error(e("settings.extensions.toast.approveFailed"));return}x(null),U.success(e("settings.extensions.toast.approved",{name:Ce.name})),await gn()},t[54]=e,t[55]=Ne):Ne=t[55];const Ve=Ne;let Ye;t[56]!==Le?(Ye=async Ce=>{x(null),await Le(Ce.id,Ce.name)},t[56]=Le,t[57]=Ye):Ye=t[57];const pt=Ye;let vt;t[58]!==e?(vt=async(Ce,qe,jt)=>{k(!0);const Ot=await eu(Ce,jt);if(k(!1),!Ot){U.error(e("settings.extensions.toast.enabledFailed"));return}jt||xi(Ce),U.success(jt?e("settings.extensions.toast.enabled",{name:qe}):e("settings.extensions.toast.disabled",{name:qe})),await gn()},t[58]=e,t[59]=vt):vt=t[59];const wt=vt;let yt;t[60]!==e?(yt=e("settings.page.extensions.title"),t[60]=e,t[61]=yt):yt=t[61];let st;t[62]!==e?(st=e("settings.page.extensions.description"),t[62]=e,t[63]=st):st=t[63];let rt;t[64]!==oe||t[65]!==ce||t[66]!==Ie||t[67]!==b||t[68]!==E||t[69]!==C||t[70]!==$||t[71]!==r||t[72]!==c||t[73]!==m||t[74]!==me||t[75]!==Oe||t[76]!==ie||t[77]!==Re||t[78]!==_||t[79]!==e||t[80]!==f?(rt=f?null:s.jsxs(He,{title:e("settings.extensions.add.action"),info:C?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block",children:e("settings.extensions.add.enterpriseRule")}),s.jsx("span",{className:"mt-2 block",children:e("settings.extensions.add.info")})]}):e("settings.extensions.add.info"),children:[s.jsx(Kt,{label:e("settings.extensions.add.label"),info:e(O?"settings.extensions.add.drop":"settings.extensions.add.drop.zipOnly"),settingsItem:"extensions.add",controlClassName:"w-full max-w-none",children:s.jsxs("div",{className:Se("relative -m-1 flex min-w-0 flex-1 items-center gap-2 rounded-md border border-dashed border-transparent p-1 transition-colors",E&&"border-primary bg-primary/5"),onDragEnter:me,onDragOver:Oe,onDragLeave:xe,onDrop:Ce=>{ie(Ce)},children:[E?s.jsx("span",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-md bg-background/80 typography-ui-label text-primary",children:e("settings.extensions.add.drop.active")}):null,s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center",children:[s.jsx(Ge,{value:m,onChange:Ce=>v(Ce.target.value),onKeyDown:Ce=>{Ce.key==="Enter"&&(Ce.preventDefault(),oe())},placeholder:e("settings.extensions.add.placeholder"),"aria-label":e("settings.extensions.add.label"),className:Se("h-8 min-w-0 flex-1 rounded-md pl-3",O?"pr-14":"pr-8"),disabled:b}),s.jsx("input",{ref:D,type:"file",accept:".zip,application/zip",className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:Ce=>{Re(Ce)}}),s.jsxs("div",{className:"absolute right-1 top-1/2 flex -translate-y-1/2 items-center gap-0.5",children:[O?s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseFolder"),"aria-label":e("settings.extensions.add.browseFolder.aria"),disabled:b,onClick:()=>{ce()},children:s.jsx(B,{name:"folder",className:"h-4 w-4"})}):null,s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",title:e("settings.extensions.add.browseZip"),"aria-label":e("settings.extensions.add.browseZip.aria"),disabled:b,onClick:()=>{Ie()},children:s.jsx(B,{name:"archive",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"shrink-0","data-settings-item":"extensions.gitIdentity",children:s.jsx(kp,{activeProfile:_,identities:$,onSelect:Ce=>h(Ce.id),isApplying:b||!r&&!c,iconOnly:!0})}),s.jsxs(V,{type:"button",size:"sm",disabled:b,"aria-label":e("settings.extensions.add.aria"),onClick:()=>{oe()},children:[s.jsx(B,{name:"add",className:"h-4 w-4"}),e("settings.extensions.add.action")]})]})}),c?s.jsx("p",{className:"typography-meta text-destructive",children:e("settings.extensions.identity.loadFailed")}):null]}),t[64]=oe,t[65]=ce,t[66]=Ie,t[67]=b,t[68]=E,t[69]=C,t[70]=$,t[71]=r,t[72]=c,t[73]=m,t[74]=me,t[75]=Oe,t[76]=ie,t[77]=Re,t[78]=_,t[79]=e,t[80]=f,t[81]=rt):rt=t[81];let de;t[82]!==e?(de=e("settings.extensions.section.installed"),t[82]=e,t[83]=de):de=t[83];let Ue;t[84]!==b||t[85]!==he||t[86]!==u||t[87]!==n||t[88]!==e||t[89]!==f?(Ue=f?null:s.jsxs(V,{type:"button",variant:"ghost",size:"sm","data-settings-item":"extensions.updates.check",disabled:b||u||n!=="ready","aria-label":e("settings.extensions.updates.check.aria"),onClick:()=>{he()},children:[s.jsx(B,{name:"refresh",className:Se("h-4 w-4",u&&"animate-spin")}),e("settings.extensions.updates.check")]}),t[84]=b,t[85]=he,t[86]=u,t[87]=n,t[88]=e,t[89]=f,t[90]=Ue):Ue=t[90];let et;t[91]!==i||t[92]!==n||t[93]!==e?(et=n==="error"||i?s.jsxs("p",{className:"typography-meta whitespace-pre-line text-destructive",children:[e("settings.extensions.toast.loadFailed"),i?`
30
+ ${ar(i,e)}`:""]}):null,t[91]=i,t[92]=n,t[93]=e,t[94]=et):et=t[94];let ze;t[95]!==e||t[96]!==f?(ze=f?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.unsupported")}):null,t[95]=e,t[96]=f,t[97]=ze):ze=t[97];let Ze;t[98]!==a.length||t[99]!==n||t[100]!==e?(Ze=n==="ready"&&a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.extensions.empty")}):null,t[98]=a.length,t[99]=n,t[100]=e,t[101]=Ze):Ze=t[101];let tt;if(t[102]!==b||t[103]!==a||t[104]!==Le||t[105]!==wt||t[106]!==fe){let Ce;t[108]!==b||t[109]!==Le||t[110]!==wt||t[111]!==fe?(Ce=qe=>s.jsx($y,{guest:qe,busy:b,onReview:x,onRemove:Le,onSetEnabled:wt,onUpdate:fe},qe.id),t[108]=b,t[109]=Le,t[110]=wt,t[111]=fe,t[112]=Ce):Ce=t[112],tt=a.map(Ce),t[102]=b,t[103]=a,t[104]=Le,t[105]=wt,t[106]=fe,t[107]=tt}else tt=t[107];let lt;t[113]!==de||t[114]!==Ue||t[115]!==et||t[116]!==ze||t[117]!==Ze||t[118]!==tt?(lt=s.jsxs(He,{title:de,contentClassName:"space-y-3",headerAction:Ue,children:[et,ze,Ze,tt]}),t[113]=de,t[114]=Ue,t[115]=et,t[116]=ze,t[117]=Ze,t[118]=tt,t[119]=lt):lt=t[119];let Q;t[120]!==Ve?(Q=Ce=>{Ve(Ce)},t[120]=Ve,t[121]=Q):Q=t[121];let nt;t[122]!==pt?(nt=Ce=>{pt(Ce)},t[122]=pt,t[123]=nt):nt=t[123];let ot;t[124]===Symbol.for("react.memo_cache_sentinel")?(ot=()=>x(null),t[124]=ot):ot=t[124];let it;t[125]!==A||t[126]!==b||t[127]!==Q||t[128]!==nt?(it=s.jsx(Oy,{guest:A,busy:b,onApprove:Q,onDecline:nt,onDismiss:ot}),t[125]=A,t[126]=b,t[127]=Q,t[128]=nt,t[129]=it):it=t[129];const ft=w!==null;let bt;t[130]!==b?(bt=Ce=>{!Ce&&!b&&S(null)},t[130]=b,t[131]=bt):bt=t[131];let ht;t[132]!==e?(ht=e("settings.extensions.dialog.reinstallTitle"),t[132]=e,t[133]=ht):ht=t[133];let Nt;t[134]!==ht?(Nt=s.jsx(Ht,{children:ht}),t[134]=ht,t[135]=Nt):Nt=t[135];const At=w?.name??"";let $e;t[136]!==e||t[137]!==At?($e=e("settings.extensions.dialog.reinstallDescription",{name:At}),t[136]=e,t[137]=At,t[138]=$e):$e=t[138];let Xe;t[139]!==$e?(Xe=s.jsx(qt,{children:$e}),t[139]=$e,t[140]=Xe):Xe=t[140];let mt;t[141]!==Nt||t[142]!==Xe?(mt=s.jsxs(Vt,{children:[Nt,Xe]}),t[141]=Nt,t[142]=Xe,t[143]=mt):mt=t[143];let Fe;t[144]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>S(null),t[144]=Fe):Fe=t[144];let J;t[145]!==e?(J=e("settings.common.actions.cancel"),t[145]=e,t[146]=J):J=t[146];let ye;t[147]!==b||t[148]!==J?(ye=s.jsx(V,{size:"sm",variant:"ghost",disabled:b,onClick:Fe,children:J}),t[147]=b,t[148]=J,t[149]=ye):ye=t[149];let Ae;t[150]!==Ee?(Ae=()=>{Ee()},t[150]=Ee,t[151]=Ae):Ae=t[151];let Y;t[152]!==e?(Y=e("settings.extensions.dialog.reinstall"),t[152]=e,t[153]=Y):Y=t[153];let Pe;t[154]!==b||t[155]!==Ae||t[156]!==Y?(Pe=s.jsx(V,{size:"sm",disabled:b,onClick:Ae,children:Y}),t[154]=b,t[155]=Ae,t[156]=Y,t[157]=Pe):Pe=t[157];let Je;t[158]!==ye||t[159]!==Pe?(Je=s.jsxs(as,{children:[ye,Pe]}),t[158]=ye,t[159]=Pe,t[160]=Je):Je=t[160];let se;t[161]!==mt||t[162]!==Je?(se=s.jsxs($t,{className:"max-w-md",children:[mt,Je]}),t[161]=mt,t[162]=Je,t[163]=se):se=t[163];let We;t[164]!==ft||t[165]!==bt||t[166]!==se?(We=s.jsx(_t,{open:ft,onOpenChange:bt,children:se}),t[164]=ft,t[165]=bt,t[166]=se,t[167]=We):We=t[167];let ut;return t[168]!==yt||t[169]!==st||t[170]!==rt||t[171]!==lt||t[172]!==it||t[173]!==We?(ut=s.jsxs(ns,{title:yt,description:st,children:[rt,lt,it,We]}),t[168]=yt,t[169]=st,t[170]=rt,t[171]=lt,t[172]=it,t[173]=We,t[174]=ut):ut=t[174],ut};function Vy(t){return t.guests}function Hy(t){return t.status}function qy(t){return t.failure}function Gy(t){return t.runtimeKey}function Wy(){gn()}function Jy(t){return t.id!=="global"}const Gs=da,Qy=t=>{const e=t.kind==="dark"||t.kind==="high-contrast",a=nm(e),n=(ue,Ie)=>t.colors[ue]??Ie,i=ue=>ue!=="transparent"&&(Qs(ue,"#000000")!==1||Qs(ue,"#ffffff")!==1),o=(ue,Ie)=>{const ve=n(ue,Ie);return i(ve)?ve:Ie},r=n("chat.list.background",n("editor.background",a.colors.surface.background)),d=n("interactive-session.foreground",n("foreground",n("editor.foreground",a.colors.surface.foreground))),g=[["editorWidget.background","editorWidget.foreground"],["dropdown.background","dropdown.foreground"],["input.background","input.foreground"]].find(([ue])=>t.colors[ue]),p=g?n(g[0],a.colors.surface.elevated):a.colors.surface.elevated,h=ca(d,p,r),f=g?n(g[1],h):h,m=n("sideBar.background",n("panel.background",a.colors.surface.muted)),v=n("descriptionForeground",n("input.placeholderForeground",a.colors.surface.mutedForeground)),C=n("textBlockQuote.background",m),b=a.colors.surface.overlay,k=n("button.background",n("textLink.foreground",a.colors.primary.base)),u=n("button.hoverBackground",k),j=t.colors["button.background"]?n("button.foreground",zs(k,r)):zs(k,r),N=Gs(k,.5),S=[t.kind==="high-contrast"?n("contrastBorder",""):"",n("widget.border",""),n("input.border",""),n("panel.border",""),n("sideBar.border",""),n("editorWidget.border",""),n("contrastBorder","")].find(ue=>ue&&i(ue))||Gs(d,e?.25:.2),A=n("toolbar.hoverBackground",n("list.hoverBackground",a.colors.interactive.hover)),x=n("toolbar.activeBackground",A),M=[["list.activeSelectionBackground","list.activeSelectionForeground"],["menu.selectionBackground","menu.selectionForeground"],["editor.selectionBackground","editor.selectionForeground"]].filter(([ue])=>t.colors[ue]),T=M.find(([ue])=>[r,m,p].every(Ie=>{const ve=Qs(n(ue,""),Ie,r);return ve===null||ve>1.01}))??M[0],D=T?n(T[0],a.colors.interactive.selection):a.colors.interactive.selection,R=T?n(T[1],d):d,O=n("focusBorder",n("inputOption.activeBorder",k)),I=O,y=n("editorCursor.foreground",a.colors.interactive.cursor),L=n("editorError.foreground",n("testing.iconFailed",a.colors.status.error)),K=o("editorError.background",Gs(L,e?.16:.12)),H=n("problemsWarningIcon.foreground",n("notificationsWarningIcon.foreground",n("editorWarning.foreground",a.colors.status.warning))),G=o("editorWarning.background",Gs(H,e?.16:.12)),W=n("testing.iconPassed",n("gitDecoration.addedResourceForeground",a.colors.status.success)),q=Gs(W,e?.16:.12),z=n("problemsInfoIcon.foreground",n("editorInfo.foreground",a.colors.status.info)),$=o("editorInfo.background",Gs(z,e?.16:.12)),Z=n("editorLineNumber.foreground",v),_=n("textPreformat.foreground",n("terminal.ansiGreen",a.colors.syntax.base.string)),ne=n("terminal.ansiBlue",k),X=n("terminal.ansiYellow",a.colors.syntax.base.number),te=n("terminal.ansiCyan",a.colors.syntax.base.function),he=n("terminal.ansiMagenta",d),je=n("terminal.ansiYellow",a.colors.syntax.base.type),fe=n("chat.requestBorder",S),ke=n("diffEditor.insertedLineBackground",n("diffEditor.insertedTextBackground",q)),be=n("diffEditor.removedLineBackground",n("diffEditor.removedTextBackground",K)),De=n("chat.linesAddedForeground",n("gitDecoration.addedResourceForeground",W)),oe=n("chat.linesRemovedForeground",n("gitDecoration.deletedResourceForeground",L)),ee=n("gitDecoration.modifiedResourceForeground",z),ce=n("chat.requestBubbleBackground",n("chat.requestBackground",p));return{...a,metadata:{...a.metadata,id:"vscode-auto",name:"VS Code Theme",description:"Mirrors your current VS Code color theme",author:"VS Code",version:"1.0.0",variant:e?"dark":"light",tags:["vscode","auto"]},colors:{...a.colors,primary:{base:k,hover:u,active:u,foreground:j,muted:N},surface:{background:r,foreground:d,muted:m,mutedForeground:v,elevated:p,elevatedForeground:f,overlay:b,subtle:C},interactive:{border:S,borderHover:n("toolbar.hoverOutline",S),borderFocus:O,selection:D,selectionForeground:R,focus:O,focusRing:I,cursor:y,hover:A,active:x},status:{error:L,errorForeground:zs(L,r),errorBackground:K,errorBorder:Gs(L,e?.45:.35),warning:H,warningForeground:zs(H,r),warningBackground:G,warningBorder:Gs(H,e?.45:.35),success:W,successForeground:zs(W,r),successBackground:q,successBorder:Gs(W,e?.45:.35),info:z,infoForeground:zs(z,r),infoBackground:$,infoBorder:Gs(z,e?.45:.35)},syntax:{tokens:{},highlights:{diffAdded:De,diffAddedBackground:ke,diffRemoved:oe,diffRemovedBackground:be,diffModified:ee,diffModifiedBackground:Gs(ee,e?.16:.12),lineNumber:n("editorLineNumber.foreground",v),lineNumberActive:n("editorLineNumber.activeForeground",d)},base:{background:n("editor.background",r),foreground:n("editor.foreground",d),comment:Z,keyword:ne,string:_,number:X,function:te,variable:he,type:je,operator:k}},tools:{border:fe,icon:n("icon.foreground",v),title:d,description:Gs(v,.8),edit:{added:De,addedBackground:ke,removed:oe,removedBackground:be,modified:ee,modifiedBackground:Gs(ee,e?.16:.12),lineNumber:Z}},chat:{background:r,userMessage:d,userMessageBackground:ce,assistantMessage:d,assistantMessageBackground:r,timestamp:v,divider:S,typing:n("chat.thinkingShimmer",v),avatarBackground:n("chat.avatarBackground",r),avatarForeground:n("chat.avatarForeground",d),slashCommandBackground:n("chat.slashCommandBackground",k),slashCommandForeground:n("chat.slashCommandForeground",j),inputWorkingBorderColor1:n("chat.inputWorkingBorderColor1",k),inputWorkingBorderColor2:n("chat.inputWorkingBorderColor2",u),inputWorkingBorderColor3:n("chat.inputWorkingBorderColor3",N)},markdown:{link:n("textLink.foreground",k),linkHover:n("textLink.activeForeground",u),inlineCode:n("textPreformat.foreground",_),inlineCodeBackground:n("textPreformat.background",n("editor.background",r)),blockquote:d,blockquoteBackground:n("textBlockQuote.background","transparent"),blockquoteBorder:n("textBlockQuote.border",S),listMarker:Gs(k,.6)}}}},ir=.075;function Yy(t,e,a){const{surface:n,primary:i,status:o,interactive:r}=t.colors,d=n.background,c=t.metadata.variant==="dark",g=zs(n.muted,d),p=[d,n.muted,n.elevated,Is(r.selection,n.muted,1,d)].filter(k=>zs(k,d)===g),h=k=>p.reduce((u,j)=>ca(u,j,d),k),f=k=>[d,n.muted].every(u=>(Qs(k,u,d)??0)>=3),m=[e["button.background"],e["textLink.foreground"],e["activityBarBadge.background"],e["list.highlightForeground"],e.focusBorder,e["inputOption.activeBorder"],a.function,a.keyword].filter(k=>k!==void 0),v=h(m.find(f)??i.base);v!==i.base&&(i.base=v,i.foreground=zs(v,d),i.hover=Is(n.foreground,v,.08,d),i.active=Is(n.foreground,v,.16,d),i.muted=da(v,.5),!e.focusBorder&&!e["inputOption.activeBorder"]&&(r.focus=v,r.focusRing=v,r.borderFocus=v),t.colors.markdown&&(e["textLink.foreground"]||(t.colors.markdown.link=v),e["textLink.activeForeground"]||(t.colors.markdown.linkHover=i.hover),t.colors.markdown.listMarker=da(v,.6))),p.some(k=>(Qs(r.focusRing,k,d)??0)<1.1)&&(r.focus=i.base,r.focusRing=i.base,r.borderFocus=i.base);const C=(k,u,j)=>p.every(N=>(vl(k,u,N,d)??0)>=j);let b=h(o.info);if(!C(b,i.base,ir)){const k=N=>C(N,i.base,ir)&&[o.error,o.warning,o.success].every(w=>C(N,w,.1));let j=[e["notificationsInfoIcon.foreground"],e["editorInfo.foreground"],e["terminal.ansiCyan"],e["terminal.ansiBlue"],e["terminal.ansiMagenta"],e["textLink.foreground"],a.function,a.type].filter(N=>N!==void 0).map(h).find(k);if(!j){const N=Is(b,d,1,d),S=[N,h(Is(N,d,.5,d))].flatMap(A=>[.12,.18].flatMap(x=>[0,60,-60,90,-90,120,-120,180].map(E=>h(am(A,E,x)))));if(j=S.find(k),!j){const A=x=>Math.min(...[o.error,o.warning,o.success].map(E=>vl(x,E,n.muted,d)??0));j=S.filter(x=>C(x,i.base,ir)).sort((x,E)=>A(E)-A(x))[0]}}j&&(b=j)}if(b!==o.info&&(o.info=b,o.infoForeground=zs(b,d),o.infoBackground=da(b,c?.16:.12),o.infoBorder=da(b,c?.45:.35)),t.colors.chat){const k=t.colors.chat.userMessageBackground??n.elevated;if((Qs(k,d,d)??1)<1.1){const u=Is(k,d,1,d);let N=(Qs(u,"#000000")??1)<(Qs(d,"#000000")??1)?"#000000":"#ffffff",w=u;((Qs(N,d,d)??1)<1.1||(Qs(u,d,d)??1)<1.01)&&(w=d,N=n.foreground);let S=0,A=1;for(let E=0;E<16;E++){const M=(S+A)/2,T=Is(N,w,M,d);(Qs(T,d,d)??1)>=1.1?A=M:S=M}const x=Is(N,w,A,d);(Qs(n.foreground,x,d)??0)>=4.5&&(t.colors.chat.userMessageBackground=x)}}}const mo=Rt().regex(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i),cl=Os({foreground:mo.optional()}),iu=Os({scope:yr([Rt(),ja(Rt())]).optional(),settings:cl}),Zy=Os({name:Rt().trim().min(1).max(160).optional(),author:Rt().max(160).optional(),description:Rt().max(1024).optional(),type:Gr(["light","dark","hc","hc-black","hc-light"]).optional(),include:Rt().optional(),colors:Bn(Rt(),mo.nullable()).default({}),tokenColors:yr([ja(iu),Rt()]).optional(),semanticHighlighting:qr().optional(),semanticTokenColors:Bn(Rt(),yr([mo,cl])).optional()});function Xy(t){return t.flatMap(e=>(Array.isArray(e.scope)?e.scope:[e.scope??""]).flatMap(n=>n.split(",").map(i=>({scope:i.trim(),color:e.settings.foreground}))))}function e1(t,e){for(const a of e){let n,i=-1;for(const o of t)!o.color||!o.scope||(a===o.scope||a.startsWith(`${o.scope}.`))&&o.scope.length>=i&&(n=o.color,i=o.scope.length);if(n)return n}}function t1(t,e){for(const a of e.length?[...e,"*"]:e){const n=t[a];if(n===void 0)continue;const i=mo.safeParse(n);if(i.success)return i.data;const o=cl.safeParse(n);if(o.success&&o.data.foreground)return o.data.foreground}}function s1(t){return/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/.test(t)?t.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):t}function n1(t,e,a,n){const i=zs(a,a);if(e.some(c=>zs(c,a)!==i))return t;let o=t;for(const c of e)o=ca(o,c,a);let r=0,d=1;for(let c=0;c<16;c++){const g=(r+d)/2,p=da(o,g);e.every(h=>(Qs(p,h,a)??0)>=n)?d=g:r=g}return da(o,d)}function ou(t,e){if(new TextEncoder().encode(t).byteLength>gd)throw new ua("size");let a;try{a=Zy.parse(JSON.parse(Vp(t.replace(/^\uFEFF/,""),{trailingCommas:!0})))}catch{throw new ua("invalid")}const n=ja(iu).safeParse(a.tokenColors??[]);if(a.include||!n.success)throw new ua("include");const i={};for(const[E,M]of Object.entries(a.colors))M!==null&&(i[E]=M);const o={...i},r=i["editor.background"];if(!r)throw new ua("background");const d=a.type?["dark","hc","hc-black"].includes(a.type):zs(r,"#ffffff")==="#ffffff",c=d?"dark":"light",g=Is(r,d?"#000000":"#ffffff",1),p=Xy(n.data),h=n.data.filter(E=>!E.scope&&E.settings.foreground).at(-1)?.settings.foreground,f=i["editor.foreground"]??h??i.foreground??zs(g,g),m=i["chat.list.background"]??g,v=i["interactive-session.foreground"]??i.foreground??f;i["editor.background"]=g,i["editor.foreground"]=f,i.foreground??=v,i["sideBar.background"]??=i["panel.background"]??Is(v,m,.03,m),!i["editorWidget.background"]&&!i["dropdown.background"]&&!i["input.background"]&&(i["editorWidget.background"]=Is(v,m,.04,m),i["editorWidget.foreground"]=ca(v,i["editorWidget.background"],m)),i.descriptionForeground??=ca(Is(v,m,.6,m),m),i["widget.border"]??=i["input.border"]??i["panel.border"]??Is(v,m,.15,m),i["toolbar.hoverBackground"]??=i["list.hoverBackground"]??Is(v,m,.08,m),i["toolbar.activeBackground"]??=Is(v,m,.12,m),!i["list.activeSelectionBackground"]&&!i["editor.selectionBackground"]&&(i["list.activeSelectionBackground"]=Is(v,m,.16,m),i["list.activeSelectionForeground"]=ca(v,i["list.activeSelectionBackground"],m)),i["button.background"]||(i["button.background"]=i["textLink.foreground"]??i.focusBorder??v,i["button.foreground"]=zs(i["button.background"],m)),i.focusBorder??=i["button.background"],i["editorCursor.foreground"]??=f;const C=a.type?.startsWith("hc")??!1;C&&i.contrastBorder&&(i["widget.border"]=i.contrastBorder);const k=Qy({kind:d&&C?"high-contrast":c,colors:i});if(C)k.colors.interactive.focusRing=i.focusBorder;else{const{surface:E,interactive:M}=k.colors,T=n1(M.border,[E.background,E.muted,E.elevated],E.background,d?1.15:1.2);M.border=T,i["toolbar.hoverOutline"]||(M.borderHover=T),k.colors.tools&&!i["chat.requestBorder"]&&(k.colors.tools.border=T),k.colors.chat&&(k.colors.chat.divider=T),k.colors.markdown&&!i["textBlockQuote.border"]&&(k.colors.markdown.blockquoteBorder=T)}const u=a.semanticHighlighting===!1?{}:a.semanticTokenColors??{},j=(E,M,T)=>t1(u,E)??e1(p,M)??T,N={background:g,foreground:f,comment:j(["comment"],["comment","comment.line","comment.block"],ca(Is(f,g,.6,g),g)),keyword:j(["keyword"],["keyword","storage","keyword.control","storage.type"],f),string:j(["string"],["string","string.quoted","string.template"],f),number:j(["number"],["constant.numeric"],f),function:j(["function"],["entity.name.function","support.function"],f),variable:j(["variable"],["variable.other.readwrite","variable"],f),type:j(["type"],["entity.name.type","support.type","support.class"],f),operator:j(["operator"],["keyword.operator"],f)},w=j(["class"],["entity.name.type.class","entity.name.class"],N.type),S=j(["property"],["variable.other.property","support.type.property-name"],N.variable),A={base:N,tokens:{className:w,interface:j(["interface"],["entity.name.type.interface"],N.type),enum:j(["enum"],["entity.name.type.enum"],w),method:j(["method"],["entity.name.function.method"],N.function),variableProperty:S,parameter:j(["parameter"],["variable.parameter"],N.variable),constant:j(["variable.readonly","*.readonly","enumMember"],["variable.other.constant","constant.other"],N.number),boolean:j([],["constant.language.boolean","constant.language"],N.number),punctuation:j([],["punctuation","punctuation.separator"],N.operator),stringEscape:j([],["constant.character.escape"],N.string),commentDoc:j([],["comment.block.documentation","comment.documentation"],N.comment),keywordImport:j([],["keyword.control.import","keyword.import"],N.keyword),tag:j([],["entity.name.tag"],N.keyword),tagAttribute:j([],["entity.other.attribute-name"],S)},highlights:k.colors.syntax.highlights},x=s1(a.name??(e.replace(/\.(jsonc?|code-theme)$/i,"").replace(/[-_]color[-_]theme$/i,"").trim().slice(0,160)||"VS Code"));return Yy(k,o,N),im({metadata:{id:`vscode-import-${c}`,name:x,variant:c,author:a.author,description:a.description??"",version:"1.0.0",tags:["imported","vscode"]},colors:{...k.colors,syntax:A,pr:{open:k.colors.status.success,draft:k.colors.surface.mutedForeground,blocked:k.colors.status.warning,merged:w,closed:k.colors.status.error}}})}const a1=Os({namespace:Rt(),name:Rt(),version:Rt(),label:Rt(),icon:Rt().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&["open-vsx.org","openvsx.eclipsecontent.org"].includes(e.hostname)}).nullable()});async function i1(t,e){const a=await It("/api/config/themes/catalog/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t}),signal:e});if(!a.ok)throw new Error("catalog");return Os({items:ja(a1).max(24)}).parse(await a.json()).items}async function o1(t,e){const a=await It("/api/config/themes/catalog/package",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:e});if(!a.ok)throw new Error("catalog");const{items:n}=Os({items:ja(Os({path:Rt(),name:Rt(),text:Rt(),error:qr()})).max(40)}).parse(await a.json());return n.map((i,o)=>{const r=`${o}:${i.path}`;try{if(i.error)throw new Error("invalid");const d=ou(i.text,i.path);return d.metadata.name=i.name,d.metadata.author=t.namespace,{status:"ready",key:r,name:i.name,definition:d,theme:om(d)}}catch{return{status:"invalid",key:r,name:i.name}}})}function r1(t){const e=_e.c(3),{extension:a}=t,[n,i]=l.useState(!1);let o;return e[0]!==a.icon||e[1]!==n?(o=a.icon&&!n?s.jsx("img",{src:a.icon,alt:"",referrerPolicy:"no-referrer",loading:"lazy",className:"size-9 shrink-0 rounded object-contain",onError:()=>i(!0)}):s.jsx(B,{name:"palette",className:"size-9 shrink-0 text-muted-foreground"}),e[0]=a.icon,e[1]=n,e[2]=o):o=e[2],o}function l1(t){const e=_e.c(93),{pickFile:a,fileBusy:n,onClose:i}=t,{t:o}=Be(),r=re(u1),{isMobile:d}=qn(),c=r||d,{importTheme:g}=ba(),[p,h]=l.useState("");let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f={step:"search",status:"idle",results:[]},e[0]=f):f=e[0];const[m,v]=l.useState(f);let C;e[1]===Symbol.for("react.memo_cache_sentinel")?(C=new Set,e[1]=C):C=e[1];const[b,k]=l.useState(C);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=new Set,e[2]=u):u=e[2];const[j,N]=l.useState(u),[w,S]=l.useState(!1),[A,x]=l.useState(null),E=l.useRef(null);let M,T;e[3]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{const _=new AbortController;E.current=_;const ne=ho(()=>_.abort());return()=>{ne(),_.abort()}},T=[],e[3]=M,e[4]=T):(M=e[3],T=e[4]),l.useEffect(M,T);let D,R;e[5]!==p||e[6]!==m.step?(D=()=>{if(m.step!=="search")return;const _=new AbortController,ne=p.trim(),X=setTimeout(async()=>{if(!ne){v({step:"search",status:"idle",results:[]});return}v({step:"search",status:"loading",results:[]});try{const te=await i1(ne,_.signal);_.signal.aborted||v({step:"search",status:"ready",results:te})}catch{_.signal.aborted||v({step:"search",status:"error",results:[]})}},350);return()=>{clearTimeout(X),_.abort()}},R=[p,m.step],e[5]=p,e[6]=m.step,e[7]=D,e[8]=R):(D=e[7],R=e[8]),l.useEffect(D,R);let O,I;if(e[9]!==n||e[10]!==g||e[11]!==c||e[12]!==a||e[13]!==p||e[14]!==A||e[15]!==j||e[16]!==w||e[17]!==b||e[18]!==m.extension||e[19]!==m.results||e[20]!==m.status||e[21]!==m.step||e[22]!==m.variants||e[23]!==o){const _=async ee=>{const ce=E.current?.signal;if(ce){v({step:"package",status:"loading",extension:ee}),N(new Set),x(null),k(new Set);try{const ue=await o1(ee,ce);ce.aborted||v({step:"variants",extension:ee,variants:ue})}catch{ce.aborted||v({step:"package",status:"error",extension:ee})}}};let ne;e[26]!==g||e[27]!==j||e[28]!==w||e[29]!==b||e[30]!==m.step||e[31]!==m.variants||e[32]!==o?(ne=async()=>{if(m.step!=="variants"||w)return;const ee=E.current?.signal;if(!ee)return;S(!0),x(null);let ce=!1;for(const ue of m.variants){if(ee.aborted)break;if(!(ue.status!=="ready"||!b.has(ue.key)||j.has(ue.key)))try{if(await g(ue.definition,{activate:!1}),ee.aborted)break;N(Ie=>new Set(Ie).add(ue.key)),k(Ie=>{const ve=new Set(Ie);return ve.delete(ue.key),ve})}catch{ce=!0}}ee.aborted||(S(!1),x(ce?"partial":null),ce?Ga.error(o("settings.themeImport.partialError")):Ga.success(o("settings.themeImport.complete")))},e[26]=g,e[27]=j,e[28]=w,e[29]=b,e[30]=m.step,e[31]=m.variants,e[32]=o,e[33]=ne):ne=e[33];const X=ne;let te,he;e[34]!==j||e[35]!==b||e[36]!==m.step||e[37]!==m.variants?(te=m.step==="variants"?m.variants.filter(ee=>ee.status==="ready"&&!j.has(ee.key)):[],he=te.length>0&&te.every(ee=>b.has(ee.key)),e[34]=j,e[35]=b,e[36]=m.step,e[37]=m.variants,e[38]=te,e[39]=he):(te=e[38],he=e[39]);const je=he;let fe;e[40]!==n||e[41]!==X||e[42]!==w||e[43]!==b||e[44]!==m.step||e[45]!==o?(fe=m.step==="variants"&&s.jsx(V,{disabled:!b.size||w||n,onClick:()=>{X()},children:o(w?"settings.themeImport.busy":"settings.themeImport.importSelected")}),e[40]=n,e[41]=X,e[42]=w,e[43]=b,e[44]=m.step,e[45]=o,e[46]=fe):fe=e[46];const ke=w||n;let be;e[47]!==o?(be=o("settings.themeImport.chooseFile"),e[47]=o,e[48]=be):be=e[48];let De;e[49]!==a||e[50]!==ke||e[51]!==be?(De=s.jsx(V,{variant:"outline",className:"self-start",disabled:ke,onClick:a,children:be}),e[49]=a,e[50]=ke,e[51]=be,e[52]=De):De=e[52];let oe;e[53]!==fe||e[54]!==De?(oe=s.jsxs(s.Fragment,{children:[fe,De]}),e[53]=fe,e[54]=De,e[55]=oe):oe=e[55],O=oe,I=s.jsx(s.Fragment,{children:m.step==="search"?s.jsxs(s.Fragment,{children:[s.jsx(Ge,{autoFocus:!0,"aria-label":o("settings.themeImport.search"),placeholder:o("settings.themeImport.search"),value:p,maxLength:160,onChange:ee=>h(ee.target.value)}),s.jsxs("div",{className:c?"space-y-1":"max-h-[45dvh] overflow-y-auto space-y-1","aria-live":"polite",children:[m.status==="loading"&&s.jsx("p",{className:"text-muted-foreground",children:o("common.loading")}),m.status==="error"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:o("settings.themeImport.catalogError")}),m.status==="ready"&&!m.results.length&&s.jsx("p",{className:"text-muted-foreground",children:o("settings.themeImport.empty")}),m.results.map(ee=>s.jsxs(V,{variant:"ghost",className:"h-auto w-full justify-start py-2 text-left",onClick:()=>{_(ee)},children:[s.jsx(r1,{extension:ee}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate",children:ee.label}),s.jsx("span",{className:"block truncate typography-meta text-muted-foreground",children:ee.namespace})]})]},`${ee.namespace}.${ee.name}`))]})]}):s.jsxs(s.Fragment,{children:[s.jsxs(V,{variant:"ghost",size:"sm",className:"justify-start",disabled:w||m.step==="package"&&m.status==="loading",onClick:()=>v({step:"search",status:"idle",results:[]}),children:[s.jsx(B,{name:"arrow-left",className:"size-4"}),o("settings.themeImport.back")]}),s.jsx("p",{className:"typography-ui-label",children:m.extension.label}),A==="partial"&&s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:o("settings.themeImport.partialError")}),m.step==="package"?m.status==="loading"?s.jsx("p",{role:"status",children:o("common.loading")}):s.jsx("p",{role:"alert",className:"text-[var(--status-error-text)]",children:o("settings.themeImport.catalogError")}):s.jsxs(s.Fragment,{children:[m.variants.length>1&&s.jsx(V,{variant:"ghost",size:"sm",className:"self-start",disabled:w||n||!te.length,onClick:()=>k(je?new Set:new Set(te.map(d1))),children:o(je?"settings.themeImport.deselectAll":"settings.themeImport.selectAll")}),s.jsx("div",{className:c?"space-y-2":"max-h-[45dvh] overflow-y-auto space-y-2",children:m.variants.map(ee=>s.jsxs("div",{className:"flex items-center gap-3",children:[ee.status==="ready"&&s.jsxs("div",{"aria-hidden":"true",className:"flex w-20 shrink-0 items-center gap-2 rounded px-2 py-3",style:{backgroundColor:ee.theme.colors.surface.background,color:ee.theme.colors.surface.foreground},children:[s.jsx("span",{children:"Aa"}),s.jsx("span",{className:"space-y-1",children:[ee.theme.colors.syntax.base.keyword,ee.theme.colors.syntax.base.string,ee.theme.colors.syntax.base.function].map(c1)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[j.has(ee.key)?s.jsxs("div",{className:"flex items-center gap-2 py-1",children:[s.jsx(B,{name:"check",className:"size-4 shrink-0 text-[var(--status-success-text)]"}),s.jsx("span",{className:"typography-ui-label",children:ee.name})]}):s.jsx(xt,{checked:b.has(ee.key),disabled:ee.status!=="ready"||w||n,label:ee.name,onChange:ce=>k(ue=>{const Ie=new Set(ue);return ce?Ie.add(ee.key):Ie.delete(ee.key),Ie})}),s.jsx("p",{className:j.has(ee.key)?"typography-meta font-medium text-[var(--status-success-text)]":"typography-meta text-muted-foreground",children:ee.status!=="ready"?o("settings.themeImport.error.invalid"):j.has(ee.key)?o("settings.themeImport.installed"):o(ee.theme.metadata.variant==="dark"?"settings.openchamber.visual.option.themeMode.dark":"settings.openchamber.visual.option.themeMode.light")})]})]},ee.key))})]})]})}),e[9]=n,e[10]=g,e[11]=c,e[12]=a,e[13]=p,e[14]=A,e[15]=j,e[16]=w,e[17]=b,e[18]=m.extension,e[19]=m.results,e[20]=m.status,e[21]=m.step,e[22]=m.variants,e[23]=o,e[24]=O,e[25]=I}else O=e[24],I=e[25];const y=I;if(c){let _;e[56]!==o?(_=o("settings.themeImport.catalogTitle"),e[56]=o,e[57]=_):_=e[57];let ne;e[58]!==O?(ne=s.jsx("div",{className:"flex flex-col gap-2",children:O}),e[58]=O,e[59]=ne):ne=e[59];let X;e[60]!==o?(X=o("settings.themeImport.catalogHint"),e[60]=o,e[61]=X):X=e[61];let te;e[62]!==X?(te=s.jsx("p",{className:"typography-meta text-muted-foreground",children:X}),e[62]=X,e[63]=te):te=e[63];let he;e[64]!==y||e[65]!==te?(he=s.jsxs("div",{className:"flex flex-col gap-4 px-1",children:[te,y]}),e[64]=y,e[65]=te,e[66]=he):he=e[66];let je;return e[67]!==i||e[68]!==ne||e[69]!==he||e[70]!==_?(je=s.jsx(fd,{open:!0,title:_,onClose:i,footer:ne,children:he}),e[67]=i,e[68]=ne,e[69]=he,e[70]=_,e[71]=je):je=e[71],je}let L;e[72]!==i?(L=_=>{_||i()},e[72]=i,e[73]=L):L=e[73];let K;e[74]===Symbol.for("react.memo_cache_sentinel")?(K={forceRender:!0},e[74]=K):K=e[74];let H;e[75]!==o?(H=o("settings.themeImport.catalogTitle"),e[75]=o,e[76]=H):H=e[76];let G;e[77]!==H?(G=s.jsx(Ht,{children:H}),e[77]=H,e[78]=G):G=e[78];let W;e[79]!==o?(W=o("settings.themeImport.catalogHint"),e[79]=o,e[80]=W):W=e[80];let q;e[81]!==W?(q=s.jsx(qt,{children:W}),e[81]=W,e[82]=q):q=e[82];let z;e[83]!==G||e[84]!==q?(z=s.jsxs(Vt,{children:[G,q]}),e[83]=G,e[84]=q,e[85]=z):z=e[85];let $;e[86]!==O||e[87]!==y||e[88]!==z?($=s.jsxs($t,{className:"max-w-lg",backdropProps:K,children:[z,y,O]}),e[86]=O,e[87]=y,e[88]=z,e[89]=$):$=e[89];let Z;return e[90]!==$||e[91]!==L?(Z=s.jsx(_t,{open:!0,onOpenChange:L,children:$}),e[90]=$,e[91]=L,e[92]=Z):Z=e[92],Z}function c1(t,e){return s.jsx("span",{className:"block h-1 w-5 rounded",style:{backgroundColor:t}},e)}function d1(t){return t.key}function u1(t){return t.isMobile}function m1(){const{t}=Be(),{importTheme:e,customThemesLoading:a}=ba(),n=Ur(),[i,o]=l.useState(!1),r=l.useCallback(()=>o(!1),[]),d=l.useRef(null),c=l.useRef(0),g=l.useRef(null),[p,h]=l.useState(!1);l.useEffect(()=>ho(()=>{c.current+=1,o(!1)}),[]);const f=async(C,b)=>{h(!0);try{if(C.size>gd)throw new ua("size");const k=await C.text();if(b.key!==ln()||b.generation!==c.current)throw new ua("connection");const u=await e(ou(k,C.name));Ga.success(t("settings.themeImport.success",{name:u.metadata.name})),o(!1)}catch(k){const u=k instanceof ua?k.code:"invalid";Ga.error(t(`settings.themeImport.error.${u}`))}finally{h(!1)}},m=async()=>{if(p)return;const C={key:ln(),generation:c.current};if(g.current=C,!n.themeFiles){d.current?.click();return}h(!0);try{const b=await n.themeFiles.pick();if(b?.status==="picked"){if(b.file){const k=b.file;await f({name:k.name,size:k.size,text:async()=>k.text},C)}return}d.current?.click()}catch{Ga.error(t("settings.themeImport.error.invalid"))}finally{h(!1)}},v=async C=>{const b=C.target.files?.[0];C.target.value="",b&&!p&&g.current&&await f(b,g.current)};return s.jsxs("div",{className:"flex items-center gap-2","data-settings-item":"appearance.import-theme",children:[s.jsxs(V,{variant:"outline",size:"sm",disabled:p||a,onClick:()=>o(!0),children:[s.jsx(B,{name:p?"loader":"add",className:p?"size-3.5 animate-spin":"size-3.5"}),t(p?"settings.themeImport.busy":"settings.themeImport.action")]}),s.jsx(Gt,{children:t("settings.themeImport.catalogHint")}),s.jsx("input",{ref:d,type:"file",accept:".json,.jsonc",className:"hidden","aria-label":t("settings.themeImport.action"),onChange:v}),i&&s.jsx(l1,{pickFile:()=>{m()},fileBusy:p,onClose:r})]})}const Dc=(t,e,a)=>{const n=t?.querySelector("[cmdk-list]"),i=t?.querySelector(`[cmdk-item][data-value="${CSS.escape(e)}"]`);if(!n||!i)return;const o=n.getBoundingClientRect(),r=n.offsetHeight>0?o.height/n.offsetHeight:1;if(r<=0)return;const d=i.getBoundingClientRect(),c=(d.top-o.top)/r+n.scrollTop,g=d.height/r;a?.onlyIfHidden&&c>=n.scrollTop&&c+g<=n.scrollTop+n.clientHeight||(n.scrollTop=Math.max(0,c-(n.clientHeight-g)/2))};function Mc({options:t,value:e,onValueChange:a,placeholder:n,ariaLabel:i}){const{t:o}=Be(),{deleteImportedTheme:r,customThemeIds:d}=ba(),{isMobile:c}=qn(),[g,p]=l.useState(!1),[h,f]=l.useState(""),[m,v]=l.useState(void 0),[C,b]=l.useState(null),k=l.useRef(null),u=l.useRef(null),[j,N]=l.useState(null),[w,S]=l.useState(null),A=l.useCallback(y=>{const L=y instanceof HTMLElement?y:null,K=L?.closest('[data-slot="dialog-content"], [role="dialog"]');N(K instanceof HTMLElement?K:null),S(L?.closest("main")??null)},[]);l.useEffect(()=>{if(g)return rm.suspend()},[g]);const x=l.useRef(e);x.current=e;const E=l.useCallback(y=>{y&&Dc(y,x.current)},[]),M=t.find(y=>y.id===e),T=l.useMemo(()=>g?sa(t,h,y=>[y.label]):t,[g,t,h]),D=y=>{a(y),p(!1)},R=async y=>{if(!C){b(y.id);try{await r(y.id),k.current?.focus()}catch{Ga.error(o("settings.themeImport.deleteError"))}finally{b(null)}}},O=y=>{if(!d.includes(y.id))return null;const L=C===y.id;return s.jsx(V,{variant:"ghost",size:"icon",className:"size-6 shrink-0",disabled:L,"aria-label":o("settings.themeImport.delete",{name:y.label}),onPointerDown:K=>K.stopPropagation(),onClick:K=>{K.stopPropagation(),R(y)},children:s.jsx(B,{name:L?"loader":"delete-bin",className:L?"size-4 animate-spin":"size-4"})})},I=s.jsx("div",{role:"status",className:"px-3 py-6 text-center typography-ui-label text-muted-foreground",children:o("settings.openchamber.visual.field.noThemesFound")});return c?s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button","aria-label":i,"aria-haspopup":"dialog",className:Se(Zs,!M&&"text-muted-foreground"),onClick:()=>{f(""),p(!0)},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:M?.label??n}),s.jsx(B,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(fd,{open:g,title:i,onClose:()=>p(!1),children:s.jsxs("div",{className:"flex flex-col gap-2 px-3 pb-4 pt-1",children:[s.jsx(Ge,{value:h,onChange:y=>f(y.target.value),placeholder:o("settings.openchamber.visual.field.searchThemes"),"aria-label":o("settings.openchamber.visual.field.searchThemes"),className:"h-9"}),s.jsx("div",{className:"flex flex-col",role:"listbox","aria-label":i,children:T.length===0?I:T.map(y=>s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("button",{type:"button",role:"option","aria-selected":y.id===e,className:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]",onClick:()=>D(y.id),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:y.label}),y.id===e?s.jsx(B,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null]}),O(y)]},y.id))})]})})]}):s.jsxs(Hp,{open:g,onOpenChange:y=>{f(""),v(y?e:void 0),p(y)},onOpenChangeComplete:y=>{if(!y){u.current?.focus();return}k.current?.focus(),Dc(k.current?.closest('[data-slot="command"]'),e,{onlyIfHidden:!0})},children:[s.jsxs(qp,{ref:u,"aria-label":i,"aria-haspopup":"dialog",className:Se(Zs,!M&&"text-muted-foreground"),onPointerDownCapture:y=>A(y.currentTarget),onFocusCapture:y=>A(y.currentTarget),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:M?.label??n}),s.jsx(B,{name:"arrow-down-s",className:"size-4 opacity-50"})]}),s.jsx(Gp,{container:j??void 0,children:s.jsx(Wp,{side:"bottom",align:"start",sideOffset:4,collisionAvoidance:{side:"none"},collisionBoundary:w??void 0,className:"z-[120]",children:s.jsx(Jp,{role:"dialog","aria-label":i,className:Se(gm,"flex w-[var(--anchor-width)] min-w-[16rem] max-w-[calc(100vw-2rem)] flex-col p-0"),initialFocus:!1,finalFocus:!1,children:s.jsxs(lm,{ref:E,className:"min-h-0 flex-1",shouldFilter:!1,value:m,onValueChange:v,children:[s.jsx(cm,{ref:k,"aria-label":o("settings.openchamber.visual.field.searchThemes"),placeholder:o("settings.openchamber.visual.field.searchThemes"),value:h,onValueChange:f,onKeyDown:y=>{if(dm(y)){y.stopPropagation();return}um(y,L=>{y.currentTarget.dispatchEvent(new KeyboardEvent("keydown",{key:L,bubbles:!0,cancelable:!0}))})}}),s.jsx(mm,{label:i,className:"max-h-[20rem] p-1",children:T.length===0?I:T.map(y=>s.jsxs(pm,{value:y.id,onSelect:D,"aria-current":y.id===e?!0:void 0,className:"max-w-full typography-ui-label",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:y.label}),y.id===e?s.jsx(B,{name:"check",className:"size-4 shrink-0 text-muted-foreground"}):null,O(y)]},y.id))})]})})})})]})}const p1=2e3,g1=3,f1=(t,e)=>t.state==="unsupported"||t.state==="failed"?!0:e?t.state==="on"&&t.index?.backfill.state!=="running":t.state==="off",h1=t=>{const e=t/1e6;return new Intl.NumberFormat(go(),{style:"unit",unit:"megabyte",maximumFractionDigits:e<10?1:0}).format(e)},x1=()=>{const t=_e.c(70),{t:e}=Be(),a=re(b1),n=re(v1),i=re(y1),o=re(j1);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={kind:"loading"},t[0]=r):r=t[0];const[d,c]=l.useState(r),[g,p]=l.useState(!1),h=l.useRef(i);let f,m;t[1]!==a||t[2]!==i?(f=()=>{const G=a&&i&&!h.current;h.current=i;const W=new AbortController;let q,z=G?g1:0;const $=()=>{hm(W.signal).then(Z=>{if(W.signal.aborted)return;c({kind:"ready",status:Z}),Z.index?.backfill.state==="running"&&(z=0);const _=z>0;z=z-1,(!f1(Z,a)||_)&&(q=setTimeout($,p1))}).catch(()=>{W.signal.aborted||c({kind:"error"})})};return $(),()=>{W.abort(),clearTimeout(q)}},m=[a,i],t[1]=a,t[2]=i,t[3]=f,t[4]=m):(f=t[3],m=t[4]),l.useEffect(f,m);let v;t[5]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{p(!0),fm().then(G=>c({kind:"ready",status:G})).catch(()=>c({kind:"error"})).finally(()=>p(!1))},t[5]=v):v=t[5];const C=v,b=d.kind==="ready"?d.status:null,k=b?.state==="unsupported";let u;if(t[6]!==a||t[7]!==b?.sizeBytes||t[8]!==e||t[9]!==d.kind||t[10]!==d.status){const G=h1(b?.sizeBytes??0);if(d.kind==="loading"){let W;t[12]!==e?(W=e("settings.openchamber.messageSearch.status.loading"),t[12]=e,t[13]=W):W=t[13],u=W}else if(d.kind==="error"){let W;t[14]!==e?(W=e("settings.openchamber.messageSearch.status.error"),t[14]=e,t[15]=W):W=t[15],u=W}else if(d.status.state==="unsupported"){let W;t[16]!==e?(W=e("settings.openchamber.messageSearch.status.unsupported"),t[16]=e,t[17]=W):W=t[17],u=W}else if(!a)u=d.status.sizeBytes>0?e("settings.openchamber.messageSearch.status.offWithFile",{size:G}):e("settings.openchamber.messageSearch.status.off");else if(d.status.state==="failed"){let W;t[18]!==e?(W=e("settings.openchamber.messageSearch.status.failed"),t[18]=e,t[19]=W):W=t[19],u=W}else if(d.status.state==="on"&&d.status.index?.backfill.state==="running")u=e("settings.openchamber.messageSearch.status.indexing",{done:d.status.index.backfill.done,total:d.status.index.backfill.total,size:G});else if(d.status.state==="on"&&d.status.index)u=e("settings.openchamber.messageSearch.status.ready",{sessions:d.status.index.sessions,messages:d.status.index.messages,size:G});else{let W;t[20]!==e?(W=e("settings.openchamber.messageSearch.status.loading"),t[20]=e,t[21]=W):W=t[21],u=W}t[6]=a,t[7]=b?.sizeBytes,t[8]=e,t[9]=d.kind,t[10]=d.status,t[11]=u}else u=t[11];let j;t[22]!==e?(j=e("settings.openchamber.messageSearch.title"),t[22]=e,t[23]=j):j=t[23];let N;t[24]!==e?(N=e("settings.openchamber.messageSearch.field.enabled"),t[24]=e,t[25]=N):N=t[25];let w;t[26]!==e?(w=e("settings.openchamber.messageSearch.field.enabled"),t[26]=e,t[27]=w):w=t[27];let S;t[28]!==e?(S=e("settings.openchamber.messageSearch.field.enabledInfo"),t[28]=e,t[29]=S):S=t[29];let A;t[30]!==a||t[31]!==n||t[32]!==N||t[33]!==w||t[34]!==S||t[35]!==k?(A=s.jsx(xt,{settingsItem:"chat.message-search-enabled",checked:a,onChange:n,disabled:k,label:N,ariaLabel:w,info:S}),t[30]=a,t[31]=n,t[32]=N,t[33]=w,t[34]=S,t[35]=k,t[36]=A):A=t[36];const x=a&&i,E=!a||k;let M;t[37]!==e?(M=e("settings.openchamber.messageSearch.field.reasoning"),t[37]=e,t[38]=M):M=t[38];let T;t[39]!==e?(T=e("settings.openchamber.messageSearch.field.reasoning"),t[39]=e,t[40]=T):T=t[40];let D;t[41]!==e?(D=e("settings.openchamber.messageSearch.field.reasoningInfo"),t[41]=e,t[42]=D):D=t[42];let R;t[43]!==o||t[44]!==E||t[45]!==M||t[46]!==T||t[47]!==D||t[48]!==x?(R=s.jsx(xt,{settingsItem:"chat.message-search-reasoning",checked:x,onChange:o,disabled:E,label:M,ariaLabel:T,info:D}),t[43]=o,t[44]=E,t[45]=M,t[46]=T,t[47]=D,t[48]=x,t[49]=R):R=t[49];let O;t[50]!==e?(O=e("settings.openchamber.messageSearch.field.index"),t[50]=e,t[51]=O):O=t[51];let I;t[52]!==a||t[53]!==b||t[54]!==e||t[55]!==g?(I=a?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:C,disabled:g||b?.state!=="on"&&b?.state!=="failed",children:e(g?"settings.openchamber.messageSearch.actions.working":"settings.openchamber.messageSearch.actions.rebuild")}):s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:C,disabled:g||!b||b.state==="on"||b.sizeBytes===0,children:e(g?"settings.openchamber.messageSearch.actions.working":"settings.openchamber.messageSearch.actions.delete")}),t[52]=a,t[53]=b,t[54]=e,t[55]=g,t[56]=I):I=t[56];let y;t[57]!==O||t[58]!==I?(y=s.jsx(Ct,{label:O,children:I}),t[57]=O,t[58]=I,t[59]=y):y=t[59];let L;t[60]!==u?(L=s.jsx("p",{className:ls,"aria-live":"polite",children:u}),t[60]=u,t[61]=L):L=t[61];let K;t[62]!==R||t[63]!==y||t[64]!==L?(K=s.jsxs(na,{children:[R,y,L]}),t[62]=R,t[63]=y,t[64]=L,t[65]=K):K=t[65];let H;return t[66]!==K||t[67]!==j||t[68]!==A?(H=s.jsxs(He,{title:j,settingsItem:"chat.message-search",children:[A,K]}),t[66]=K,t[67]=j,t[68]=A,t[69]=H):H=t[69],H};function b1(t){return t.messageSearchEnabled}function v1(t){return t.setMessageSearchEnabled}function y1(t){return t.messageSearchReasoningEnabled}function j1(t){return t.setMessageSearchReasoningEnabled}const k1=()=>{re.getState().requestSettingsJump("sessions","sessions.small-model")},w1=t=>{const e=_e.c(33),{disabled:a}=t,n=a===void 0?!1:a,{t:i}=Be(),o=re(S1),r=re(N1),d=es($r),c=!ya(),g=d?o:"small-model";let p;e[0]!==i?(p=i("settings.openchamber.visual.goal.checkerLabel"),e[0]=i,e[1]=p):p=e[1];let h;e[2]!==i?(h=i("settings.openchamber.visual.goal.checkerInfo"),e[2]=i,e[3]=h):h=e[3];let f;e[4]!==i?(f=i("settings.openchamber.visual.goal.checkerLabel"),e[4]=i,e[5]=f):f=e[5];const m=n||!d;let v;e[6]!==m?(v={value:"classifier",label:"Jev",disabled:m},e[6]=m,e[7]=v):v=e[7];let C;e[8]!==i?(C=i("settings.openchamber.visual.goal.checker.smallModel"),e[8]=i,e[9]=C):C=e[9];let b;e[10]!==n||e[11]!==C?(b={value:"small-model",label:C,disabled:n},e[10]=n,e[11]=C,e[12]=b):b=e[12];let k;e[13]!==v||e[14]!==b?(k=[v,b],e[13]=v,e[14]=b,e[15]=k):k=e[15];let u;e[16]!==r||e[17]!==g||e[18]!==f||e[19]!==k?(u=s.jsx(Xs,{"aria-label":f,value:g,onChange:r,options:k}),e[16]=r,e[17]=g,e[18]=f,e[19]=k,e[20]=u):u=e[20];let j;e[21]!==u||e[22]!==p||e[23]!==h?(j=s.jsx(Ct,{settingsItem:"chat.session-goal-checker",label:p,info:h,children:u}),e[21]=u,e[22]=p,e[23]=h,e[24]=j):j=e[24];let N;e[25]!==c||e[26]!==d||e[27]!==g||e[28]!==i?(N=g==="classifier"?s.jsx(xo,{}):s.jsxs("p",{className:ls,children:[i(d?"settings.openchamber.visual.goal.checker.viaSmallModel":"settings.openchamber.visual.goal.checker.jevMissing")," ",s.jsx(Vn,{onClick:k1,children:i("settings.openchamber.visual.goal.checker.smallModelLink")}),d||!c?null:s.jsxs(s.Fragment,{children:[" · ",s.jsx(Vn,{onClick:lo,children:i("settings.jevAccess.setUp")})]})]}),e[25]=c,e[26]=d,e[27]=g,e[28]=i,e[29]=N):N=e[29];let w;return e[30]!==j||e[31]!==N?(w=s.jsxs("div",{className:"space-y-1",children:[j,N]}),e[30]=j,e[31]=N,e[32]=w):w=e[32],w};function S1(t){return t.sessionGoalChecker}function N1(t){return t.setSessionGoalChecker}const C1=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system",descriptionKey:"settings.openchamber.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light",descriptionKey:"settings.openchamber.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark",descriptionKey:"settings.openchamber.visual.option.themeMode.dark.description"}],I1=[{id:"dynamic",labelKey:"settings.openchamber.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.openchamber.visual.option.diffLayout.inline.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.openchamber.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.sideBySide.description"}],P1=[{id:"svg",labelKey:"settings.openchamber.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.openchamber.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.ascii.description"}],ci="OpenChamber - AI Coding Assistant",Rc=[{id:"system",labelKey:"settings.openchamber.visual.option.pwaOrientation.system.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.openchamber.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.openchamber.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.landscape.description"}],Oc=[{id:"native",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.description"}],or=t=>t==="portrait"||t==="landscape"?t:"system",A1=[{id:"markdown",labelKey:"settings.openchamber.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.openchamber.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.plain.description"}],T1=[{id:"sorted",labelKey:"settings.openchamber.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.openchamber.visual.option.chatRenderMode.live.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.live.description"}],Lc=[{id:"auto",labelKey:"settings.openchamber.visual.option.messageTransport.auto.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.openchamber.visual.option.messageTransport.ws.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.openchamber.visual.option.messageTransport.sse.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.sse.description"}],E1=[{id:"collapsed",labelKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.openchamber.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.summary.description"}],Fc=[{id:"auto",labelKey:"settings.openchamber.visual.option.timeFormat.auto.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.openchamber.visual.option.timeFormat.24h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.openchamber.visual.option.timeFormat.12h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.12h.description"}],Kc=[{id:"auto",labelKey:"settings.openchamber.visual.option.weekStart.auto.label",descriptionKey:"settings.openchamber.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.openchamber.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.openchamber.visual.option.weekStart.sunday.label"}],D1=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],M1=[{id:"ask",labelKey:"settings.openchamber.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.openchamber.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.openchamber.visual.option.largeTextPaste.inline.label"}],R1=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],O1=t=>t==="markdown"?"markdown":"plain",L1=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],F1=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],bo=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:o}=Be(),r=l.useCallback(P=>o(P),[o]),{isMobile:d}=qn(),{terminal:c}=Ur(),{browserTab:g}=wp(),p=tp(),h=re(P=>P.showReasoningTraces),f=re(P=>P.sessionRecapEnabled),m=re(P=>P.sessionSuggestionEnabled),v=re(P=>P.setSessionRecapEnabled),C=re(P=>P.setSessionSuggestionEnabled),b=re(P=>P.sessionGoalEnabled),k=re(P=>P.setSessionGoalEnabled),u=re(P=>P.sessionGoalDefaultBudgetEnabled),j=re(P=>P.setSessionGoalDefaultBudgetEnabled),N=re(P=>P.sessionGoalDefaultBudget),w=re(P=>P.setSessionGoalDefaultBudget),S=re(P=>P.setShowReasoningTraces),A=re(P=>P.streamingAutoFollowEnabled),x=re(P=>P.setStreamingAutoFollowEnabled),E=re(P=>P.collapsibleThinkingBlocks),M=re(P=>P.setCollapsibleThinkingBlocks),T=Pl(P=>P.animatedActivityIndicators),D=Pl(P=>P.setAnimatedActivityIndicators),R=re(P=>P.mermaidRenderingMode),O=re(P=>P.setMermaidRenderingMode),I=re(P=>P.userMessageRenderingMode),y=re(P=>P.setUserMessageRenderingMode),L=re(P=>P.collapsibleUserMessages),K=re(P=>P.setCollapsibleUserMessages),H=re(P=>P.stickyUserHeader),G=re(P=>P.promptNavigatorEnabled),W=re(P=>P.setStickyUserHeader),q=re(P=>P.setPromptNavigatorEnabled),z=re(P=>P.autoSaveEnabled),$=re(P=>P.setAutoSaveEnabled),Z=re(P=>P.wideChatLayoutEnabled),_=re(P=>P.setWideChatLayoutEnabled),ne=re(P=>P.codeBlockLineWrap),X=re(P=>P.setCodeBlockLineWrap),te=re(P=>P.chatRenderMode),he=re(P=>P.setChatRenderMode),je=re(P=>P.activityRenderMode),fe=re(P=>P.setActivityRenderMode),ke=re(P=>P.fontSize),be=re(P=>P.setFontSize),De=re(P=>P.terminalFontSize),oe=re(P=>P.setTerminalFontSize),ee=re(P=>P.terminalShell),ce=re(P=>P.setTerminalShell),ue=re(P=>P.terminalLoginShells),Ie=re(P=>P.setTerminalLoginShells),ve=re(P=>P.editorFontSize),Re=re(P=>P.setEditorFontSize),Me=re(P=>P.uiFont),me=re(P=>P.setUiFont),Te=re(P=>P.monoFont),Oe=re(P=>P.setMonoFont),pe=re(P=>P.padding),xe=re(P=>P.setPadding),ae=re(P=>P.inputBarOffset),ie=re(P=>P.setInputBarOffset),ge=re(P=>P.mobileKeyboardMode),Ee=re(P=>P.setMobileKeyboardMode),Ke=re(P=>P.diffLayoutPreference),Le=re(P=>P.setDiffLayoutPreference),Ne=re(P=>P.showTerminalQuickKeysOnDesktop),Ve=re(P=>P.sessionTabsEnabled),Ye=re(P=>P.setSessionTabsEnabled),pt=re(P=>P.setShowTerminalQuickKeysOnDesktop),vt=re(P=>P.fileEditorKeymap),wt=re(P=>P.setFileEditorKeymap),yt=Al(P=>P.followUpBehavior),st=Al(P=>P.setFollowUpBehavior),rt=zi(P=>P.scope),de=zi(P=>P.entryLimit),Ue=zi(P=>P.applyScope),et=zi(P=>P.applyEntryLimit),ze=re(P=>P.persistChatDraft),Ze=re(P=>P.setPersistChatDraft),tt=re(P=>P.inputSpellcheckEnabled),lt=re(P=>P.setInputSpellcheckEnabled),Q=re(P=>P.largeTextPasteBehavior),nt=re(P=>P.setLargeTextPasteBehavior),ot=re(P=>P.enterToSend),it=re(P=>P.setEnterToSend),ft=re(P=>P.enterToSendConfigured),bt=re(P=>P.setEnterToSendConfigured),ht=ft?ot:!d,Nt=re(P=>P.showToolFileIcons),At=re(P=>P.setShowToolFileIcons),$e=re(P=>P.showTurnChangedFiles),Xe=re(P=>P.setShowTurnChangedFiles),mt=re(P=>P.showExpandedBashTools),Fe=re(P=>P.setShowExpandedBashTools),J=re(P=>P.showExpandedEditTools),ye=re(P=>P.setShowExpandedEditTools),Ae=re(P=>P.timeFormatPreference),Y=re(P=>P.setTimeFormatPreference),Pe=re(P=>P.weekStartPreference),Je=re(P=>P.setWeekStartPreference),se=re(P=>P.showSplitAssistantMessageActions),We=re(P=>P.setShowSplitAssistantMessageActions),ut=re(P=>P.allowPromptingSubagentSessions),Ce=re(P=>P.setAllowPromptingSubagentSessions),qe=re(P=>P.draftStartersVisible),jt=re(P=>P.setDraftStartersVisible),Ot=ct(P=>P.settingsMessageStreamTransport),Yt=ct(P=>P.setSettingsMessageStreamTransport),Zt=Ot,Ft=ct(P=>P.settingsDefaultFileViewerPreview),ps=ct(P=>P.setSettingsDefaultFileViewerPreview),gs=re(P=>P.isSettingsDialogOpen),{themeMode:tn,setThemeMode:Bs,availableThemes:Vs,customThemesLoading:cn,reloadCustomThemes:sn,lightThemeId:nn,darkThemeId:Hs,setLightThemePreference:Dn,setDarkThemePreference:Lt}=ba(),[Xt,Wt]=l.useState(!1),Mt=l.useMemo(()=>us()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),cs=re(P=>P.dockBadgeEnabled),is=re(P=>P.setDockBadgeEnabled),vo=re(P=>P.alwaysShowScrollbars===!0),yo=re(P=>P.setAlwaysShowScrollbars),jo=sp(),ko=re(P=>P.desktopWindowControlsPosition),Ci=re(P=>P.setDesktopWindowControlsPosition),wo=re(P=>P.desktopWindowControlsStyle),Ii=re(P=>P.setDesktopWindowControlsStyle),[So,Ws]=l.useState(0),si=re(P=>P.reportUsage),Pi=re(P=>P.setReportUsage),Ai=l.useCallback(P=>{Pi(P),kt({reportUsage:P})},[Pi]),No=l.useCallback(P=>{Ci(P),kt({desktopWindowControlsPosition:P})},[Ci]),Co=l.useCallback(P=>{Ii(P),kt({desktopWindowControlsStyle:P})},[Ii]),Ti=(gs||d||ms())&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!Ti)return;let P=null,St=Date.now();const vs=()=>{const Nn=Date.now();Nn-St>=420&&(Ws(ia=>(ia+1)%24),St=Nn),P=requestAnimationFrame(vs)};(typeof document>"u"||document.visibilityState==="visible")&&(P=requestAnimationFrame(vs));const Ls=()=>{document.visibilityState==="visible"&&P===null?P=requestAnimationFrame(vs):document.visibilityState!=="visible"&&P!==null&&(cancelAnimationFrame(P),P=null)};return document.addEventListener("visibilitychange",Ls),()=>{document.removeEventListener("visibilitychange",Ls),P!==null&&cancelAnimationFrame(P)}},[Ti]);const Io=l.useCallback(P=>{y(P),kt({userMessageRenderingMode:P})},[y]),Po=l.useCallback(P=>{W(P),kt({stickyUserHeader:P})},[W]),Ss=l.useCallback(P=>{q(P),kt({promptNavigatorEnabled:P})},[q]),dn=l.useCallback(P=>{jt(P),kt({draftStartersVisible:P})},[jt]),ka=l.useCallback(P=>{K(P),kt({collapsibleUserMessages:P})},[K]),Mn=l.useCallback(P=>{_(P),kt({wideChatLayoutEnabled:P})},[_]),Qn=l.useCallback(P=>{We(P),kt({showSplitAssistantMessageActions:P})},[We]),ml=l.useCallback(P=>{lt(P),kt({inputSpellcheckEnabled:P})},[lt]),un=l.useCallback(P=>{it(P),bt(!0),kt({enterToSend:P,enterToSendConfigured:!0})},[it,bt]),Ao=l.useCallback(P=>{he(P),kt({chatRenderMode:P})},[he]),wa=l.useCallback(P=>{Yt(P),kt({messageStreamTransport:P})},[Yt]),Sa=l.useCallback(P=>{Ue(P),kt({inputHistoryScope:P})},[Ue]),aa=l.useCallback(P=>{const St=Math.round(P);np(St)&&(et(St),kt({inputHistoryLimit:St}))},[et]),ni=l.useCallback(P=>{fe(P),kt({activityRenderMode:P})},[fe]),To=l.useCallback(P=>{O(P),kt({mermaidRenderingMode:P})},[O]),fs=l.useCallback(P=>{At(P),kt({showToolFileIcons:P})},[At]),Eo=l.useCallback(P=>{Xe(P),kt({showTurnChangedFiles:P})},[Xe]),Na=l.useCallback(P=>{ps(P),kt({defaultFileViewerPreview:P}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:P}}))},[ps]),Ca=l.useCallback(P=>{Fe(P),kt({showExpandedBashTools:P})},[Fe]),Do=l.useCallback(P=>{ye(P),kt({showExpandedEditTools:P})},[ye]),Ei=l.useCallback(P=>{Y(P),kt({timeFormatPreference:P})},[Y]),Mo=l.useCallback(P=>{Je(P),kt({weekStartPreference:P})},[Je]),Yn=l.useMemo(()=>Vs.filter(P=>P.metadata.variant==="light").sort((P,St)=>P.metadata.name.localeCompare(St.metadata.name)),[Vs]),jn=l.useMemo(()=>Vs.filter(P=>P.metadata.variant==="dark").sort((P,St)=>P.metadata.name.localeCompare(St.metadata.name)),[Vs]),Ia=l.useMemo(()=>Yn.find(P=>P.metadata.id===nn)??Yn[0],[Yn,nn]),Di=l.useMemo(()=>jn.find(P=>P.metadata.id===Hs)??jn[0],[jn,Hs]),Pa=l.useCallback((P,St)=>{const vs=St==="dark"?" Dark":" Light";return P.endsWith(vs)?P.slice(0,-vs.length):P},[]),Aa=l.useMemo(()=>Yn.map(P=>({id:P.metadata.id,label:Pa(P.metadata.name,"light")})),[Yn,Pa]),Ro=l.useMemo(()=>jn.map(P=>({id:P.metadata.id,label:Pa(P.metadata.name,"dark")})),[jn,Pa]),we=P=>P==="enterToSend"&&d?!1:t?t.includes(P):!0,Ns=ms(),Ta=we("theme")&&!Ns,Mi=we("windowControlsPosition")&&jo,Ri=we("theme")||we("timeFormat")||we("weekStart"),Oi=Ns?Ri:we("theme")||Mi||we("pwaInstallName")||we("pwaOrientation")||we("timeFormat")||we("weekStart"),Li=we("fontSize")||we("terminalFontSize")||we("editorFontSize")||we("spacing")||we("scrollbars")&&!Ta||we("inputBarOffset")&&d,Fi=we("terminalQuickKeys")&&!d||(we("terminalShell")||we("terminalLoginShell"))&&!Ns||we("fileEditorKeymap")||we("autoSaveEnabled")||we("sessionTabs")&&!Ns&&!d,Oo=we("mermaidRendering")||we("sessionGoal")&&!Ns||we("userMessageRendering")||we("chatRenderMode")||we("messageTransport")||we("activityRenderMode")||we("collapsibleUserMessages")||we("stickyUserHeader")||we("promptNavigatorEnabled")||we("wideChatLayout")||we("codeBlockLineWrap")||we("splitAssistantMessageActions")||we("subagentReadOnlyBanner")||we("diffLayout")||we("dotfiles")||we("fileViewerPreview")||we("reasoning")||we("followUpBehavior")||we("inputHistoryScope")||we("inputHistoryLimit")||we("persistDraft")||we("largeTextPaste")||we("showToolFileIcons")||we("expandedTools")||!d&&we("inputSpellcheck")||we("enterToSend"),kn=we("chatRenderMode")||we("activityRenderMode"),Zn=we("messageTransport"),Ea=we("userMessageRendering")||we("mermaidRendering")||we("diffLayout")&&!Ns||we("followUpBehavior")||we("inputHistoryScope")||we("inputHistoryLimit"),Lo=we("sessionAssist")||we("sessionGoal")&&!Ns||we("subagentReadOnlyBanner")||we("collapsibleUserMessages")||we("stickyUserHeader")||we("promptNavigatorEnabled")||we("wideChatLayout")||we("codeBlockLineWrap")||we("splitAssistantMessageActions")||we("dotfiles")||we("fileViewerPreview")||we("persistDraft")||we("largeTextPaste")||we("showToolFileIcons")||we("showTurnChangedFiles")||!d&&we("inputSpellcheck")||we("enterToSend")||we("reasoning")||we("expandedTools"),F=Oi||Li||Fi,le=we("pwaInstallName")&&ha()&&g&&!us()&&!Ns,Qe=we("pwaOrientation")&&ha()&&!us()&&!Ns,dt=we("mobileKeyboardMode")&&ha()&&!us()&&!Ns&&ap(),Ut=(we("terminalShell")||we("terminalLoginShell"))&&!Ns,[ks,an]=l.useState([]),[bs,qs]=l.useState(0);l.useEffect(()=>ho(()=>{an([]),qs(P=>P+1)}),[]),l.useEffect(()=>{let P=!1;if(!(!Ut||!c.listShells))return c.listShells().then(St=>{P||an(St)}).catch(()=>{P||an([])}),()=>{P=!0}},[Ut,c,bs]);const Rn=l.useMemo(()=>{const P=ks.filter(St=>St.id!=="auto");return ee==="auto"||P.some(St=>St.id===ee)?P:[{id:ee,name:ee,supportsLogin:!1},...P]},[ks,ee]),wn=ks.find(P=>P.id===ee)?.supportsLogin===!0,Da=ue.includes(ee),Ma=P=>{Ie(P?[...ue.filter(St=>St!==ee),ee]:ue.filter(St=>St!==ee))},[Bt,ts]=l.useState(""),[Sn,mn]=l.useState("system"),ss=l.useMemo(()=>{const P=Fc.find(St=>St.id===Ae);return r(P?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Ae,r]),Ps=l.useMemo(()=>{const P=Kc.find(St=>St.id===Pe);return r(P?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[Pe,r]),Ra=l.useMemo(()=>{const P=Rc.find(St=>St.id===Sn);return P?r(P.labelKey):void 0},[Sn,r]),Oa=l.useMemo(()=>{const P=Oc.find(St=>St.id===ge);return P?r(P.labelKey):void 0},[ge,r]),La=l.useCallback(async P=>{if(typeof window>"u")return;const St=window,Ls=P.trim().replace(/\s+/g," ").slice(0,64);if(await kt({pwaAppName:Ls}),typeof St.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const Nn=St.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Ls);ts(Nn);return}ts(Ls||ci),St.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),pl=l.useCallback(async P=>{if(typeof window>"u")return;const St=window,vs=or(P);if(await kt({pwaOrientation:vs}),typeof St.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Ls=St.__OPENCHAMBER_SET_PWA_ORIENTATION__(vs);mn(Ls);return}mn(vs),St.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);l.useEffect(()=>{if(typeof window>"u"||!le&&!Qe&&!dt)return;let P=!1;return(async()=>{try{const vs=await En();if(!vs){P||ts(ci);return}const Nn=(vs.pwaAppName??"").trim().replace(/\s+/g," ").slice(0,64),ia=or(vs.pwaOrientation),Ki=Rl(vs.mobileKeyboardMode);P||(le&&ts(Nn||ci),Qe&&mn(ia),dt&&Ee(Ki))}catch{P||(le&&ts(ci),Qe&&mn("system"),dt&&Ee("native"))}})(),()=>{P=!0}},[Ee,dt,le,Qe]);const Fo=we("scrollbars")?s.jsx(xt,{checked:vo,onChange:yo,label:o("settings.openchamber.visual.field.alwaysShowScrollbars"),info:o("settings.openchamber.visual.field.alwaysShowScrollbarsHint"),settingsItem:"appearance.scrollbars"}):null;return s.jsxs("div",{className:"space-y-0",children:[Oi&&s.jsxs("div",{className:"space-y-0",children:[Ta&&s.jsxs(He,{title:o("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Fn,{children:[s.jsx("div",{className:Ms,children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.section.colorMode"),children:C1.map(P=>s.jsx(rs,{selected:tn===P.value,onSelect:()=>Bs(P.value),label:r(P.labelKey),ariaLabel:r(P.labelKey)},P.value))})}),s.jsxs("div",{className:Ms,children:[s.jsx(Kt,{label:o("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsx(Mc,{options:Aa,value:Ia?.metadata.id??"",onValueChange:Dn,placeholder:o("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:o("settings.openchamber.visual.field.selectLightThemeAria")})}),s.jsx(Kt,{label:o("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsx(Mc,{options:Ro,value:Di?.metadata.id??"",onValueChange:Lt,placeholder:o("settings.openchamber.visual.field.selectThemePlaceholder"),ariaLabel:o("settings.openchamber.visual.field.selectDarkThemeAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:cn||Xt,onClick:()=>{const P=Date.now();Wt(!0),sn().finally(()=>{const St=Date.now()-P;if(St<500){window.setTimeout(()=>{Wt(!1)},500-St);return}Wt(!1)})},className:"typography-settings-link inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:[s.jsx(B,{name:"restart",className:Se("h-3.5 w-3.5",Xt&&"animate-spin")}),o(Xt?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Gt,{children:o("settings.openchamber.visual.field.themeImportInfoTooltip")})]}),s.jsx(m1,{})]})]}),Mt&&s.jsx(na,{settingsItem:"appearance.dock-badge",children:s.jsx(xt,{checked:cs,onChange:is,label:o("settings.openchamber.visual.field.dockBadge"),info:o("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:o("settings.openchamber.visual.field.dockBadge")})}),Fo&&s.jsx(na,{children:Fo})]}),Mi&&s.jsx(He,{title:o("settings.openchamber.desktopNetwork.field.windowControls"),info:o("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Ta,children:s.jsxs(Fn,{children:[s.jsx(Kt,{label:o("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Xs,{value:ko,options:L1.map(P=>({value:P.id,label:r(P.labelKey)})),onChange:No,"aria-label":o("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Kt,{label:o("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Xs,{value:wo,options:F1.map(P=>({value:P.id,label:r(P.labelKey)})),onChange:Co,"aria-label":o("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Ri&&s.jsx(He,{title:o("settings.openchamber.visual.section.localization"),children:s.jsxs(Fn,{children:[s.jsx(Kt,{label:o("settings.appearance.language.label"),info:o("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Dt,{value:e,onValueChange:P=>n(P),children:[s.jsx(Tt,{"aria-label":o("settings.appearance.language.select"),size:Qt,className:Ka,children:s.jsx(Jt,{children:i(e)})}),s.jsx(Et,{children:a.map(P=>s.jsx(gt,{value:P,children:i(P)},P))})]})}),(we("timeFormat")||we("weekStart"))&&s.jsxs("div",{className:Ms,children:[we("timeFormat")&&s.jsx(Kt,{label:o("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Dt,{value:Ae,onValueChange:P=>Ei(P),children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.selectTimeFormatAria"),size:Qt,className:Ka,children:s.jsx(Jt,{children:ss})}),s.jsx(Et,{children:Fc.map(P=>s.jsx(gt,{value:P.id,children:r(P.labelKey)},P.id))})]})}),we("weekStart")&&s.jsx(Kt,{label:o("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Dt,{value:Pe,onValueChange:P=>Mo(P),children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.selectWeekStartAria"),size:Qt,className:Ka,children:s.jsx(Jt,{children:Ps})}),s.jsx(Et,{children:Kc.map(P=>s.jsx(gt,{value:P.id,children:r(P.labelKey)},P.id))})]})})]})]})}),(le||Qe||dt)&&s.jsxs(He,{title:o("settings.openchamber.visual.section.appInstall"),contentClassName:Ms,children:[le&&s.jsxs(Ct,{label:o("settings.openchamber.visual.field.installAppName"),info:o("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Es,children:[s.jsx(Ge,{value:Bt,onChange:P=>{ts(P.target.value)},onBlur:()=>{La(Bt)},onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),La(Bt))},className:"min-w-0 flex-1",maxLength:64,"aria-label":o("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ts(ci),La("")},className:hs,"aria-label":o("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),Qe&&s.jsxs(Ct,{label:o("settings.openchamber.visual.field.installOrientation"),description:o("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Es,children:[s.jsxs(Dt,{value:Sn,onValueChange:P=>{const St=or(P);mn(St),pl(St)},children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Qt,className:yl,children:s.jsx(Jt,{placeholder:o("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Ra})}),s.jsx(Et,{children:Rc.map(P=>s.jsx(gt,{value:P.id,children:r(P.labelKey)},P.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{mn("system"),pl("system")},disabled:Sn==="system",className:hs,"aria-label":o("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),dt&&s.jsxs(Ct,{label:o("settings.openchamber.visual.field.mobileKeyboardMode"),info:o("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Es,children:[s.jsxs(Dt,{value:ge,onValueChange:P=>{const St=Rl(P);Ee(St),kt({mobileKeyboardMode:St})},children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Qt,className:yl,children:s.jsx(Jt,{placeholder:o("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Oa})}),s.jsx(Et,{children:Oc.map(P=>s.jsx(gt,{value:P.id,children:r(P.labelKey)},P.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Ee("native"),kt({mobileKeyboardMode:"native"})},disabled:ge==="native",className:hs,"aria-label":o("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),Li&&s.jsxs(He,{title:o("settings.openchamber.visual.section.densityAndType"),contentClassName:Ms,children:[we("fontSize")&&!d||we("terminalFontSize")?s.jsxs(Fn,{children:[we("fontSize")&&!d&&s.jsxs(Kt,{label:o("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Dt,{value:Me,onValueChange:P=>me(P),children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Qt,className:Ka,children:s.jsx(Jt,{children:Tl.find(P=>P.id===Me)?.label})}),s.jsx(Et,{children:Tl.map(P=>s.jsx(gt,{value:P.id,children:s.jsx("span",{style:{fontFamily:P.stack},children:P.label})},P.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>me(El),disabled:Me===El,className:hs,"aria-label":o("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]}),we("terminalFontSize")&&s.jsxs(Kt,{label:o("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Dt,{value:Te,onValueChange:P=>Oe(P),children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.selectCodeFontAria"),size:Qt,className:Ka,children:s.jsx(Jt,{children:Dl.find(P=>P.id===Te)?.label})}),s.jsx(Et,{children:Dl.map(P=>s.jsx(gt,{value:P.id,children:s.jsx("span",{style:{fontFamily:P.stack},children:P.label})},P.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>Oe(Ml),disabled:Te===Ml,className:hs,"aria-label":o("settings.openchamber.visual.actions.resetCodeFontAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,we("fontSize")&&!d||we("terminalFontSize")||we("editorFontSize")?s.jsxs(Fn,{children:[we("fontSize")&&!d&&s.jsx(Kt,{label:o("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:za,children:[s.jsx(js,{value:ke,onValueChange:be,min:50,max:200,step:5,className:ws,"aria-label":o("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:Ua,children:"%"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>be(100),disabled:ke===100,className:hs,"aria-label":o("settings.openchamber.visual.actions.resetFontSizeAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),we("terminalFontSize")&&s.jsx(Kt,{label:o("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:za,children:[s.jsx(js,{value:De,onValueChange:oe,min:9,max:52,step:1,className:ws}),s.jsx("span",{className:Ua,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>oe(13),disabled:De===13,className:hs,"aria-label":o("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),we("editorFontSize")&&s.jsx(Kt,{label:o("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:za,children:[s.jsx(js,{value:ve,onValueChange:Re,min:9,max:32,step:1,className:ws}),s.jsx("span",{className:Ua,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>Re(13),disabled:ve===13,className:hs,"aria-label":o("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,we("spacing")||we("inputBarOffset")&&d?s.jsxs(Fn,{children:[we("spacing")&&s.jsx(Kt,{label:o("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:za,children:[s.jsx(js,{value:pe,onValueChange:xe,min:50,max:200,step:5,className:ws}),s.jsx("span",{className:Ua,children:"%"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>xe(100),disabled:pe===100,className:hs,"aria-label":o("settings.openchamber.visual.actions.resetSpacingAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})}),we("inputBarOffset")&&d&&s.jsx(Kt,{label:o("settings.openchamber.visual.field.inputBarOffset"),info:o("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:za,children:[s.jsx(js,{value:ae,onValueChange:ie,min:0,max:100,step:5,className:ws}),s.jsx("span",{className:Ua,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>ie(0),disabled:ae===0,className:hs,"aria-label":o("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:o("settings.common.actions.reset"),children:s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,!Ta&&Fo]}),we("animatedActivityIndicators")&&s.jsx(He,{title:o("settings.openchamber.visual.section.sessionActivity"),settingsItem:"appearance.session-activity",contentClassName:ys,children:s.jsx(xt,{checked:T,onChange:D,label:o("settings.openchamber.visual.field.animatedActivityIndicators"),ariaLabel:o("settings.openchamber.visual.field.animatedActivityIndicatorsAria"),info:o("settings.openchamber.visual.field.animatedActivityIndicatorsInfo"),settingsItem:"appearance.animated-activity-indicators"})}),Fi&&s.jsxs(He,{title:o("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[we("fileEditorKeymap")&&s.jsx(Cs,{title:o("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(P=>s.jsx(rs,{selected:vt===P,onSelect:()=>wt(P),label:o(`settings.openchamber.visual.option.fileEditorKeymap.${P}`),ariaLabel:o(`settings.openchamber.visual.option.fileEditorKeymap.${P}`)},P))})}),s.jsxs("div",{className:ys,children:[we("autoSaveEnabled")&&s.jsx(xt,{checked:z,onChange:$,label:o("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:o("settings.openchamber.visual.field.autoSaveEnabledAria"),info:o("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),Ut&&s.jsx(Kt,{label:o("settings.openchamber.visual.field.terminalShell"),info:o("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Dt,{value:ee,onValueChange:P=>{ip(P)&&ce(P)},children:[s.jsx(Tt,{"aria-label":o("settings.openchamber.visual.field.terminalShellAria"),size:Qt,className:Ka,children:s.jsx(Jt,{})}),s.jsxs(Et,{children:[s.jsx(gt,{value:"auto",children:o("settings.openchamber.visual.option.terminalShell.auto")}),Rn.map(P=>s.jsx(gt,{value:P.id,children:P.name},P.id))]})]})}),Ut&&wn&&s.jsx(xt,{checked:Da,onChange:Ma,label:o("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:o("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),we("terminalQuickKeys")&&!d&&s.jsx(xt,{checked:Ne,onChange:pt,label:o("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:o("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:o("settings.openchamber.visual.field.terminalQuickKeysTooltip",{control:xa("ctrl"),alt:xa("alt")})})]}),we("sessionTabs")&&!Ns&&!d&&s.jsx(Cs,{title:o("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(xt,{checked:Ve,onChange:Ye,label:o("settings.openchamber.visual.field.sessionTabs"),ariaLabel:o("settings.openchamber.visual.field.sessionTabsAria"),info:o("settings.openchamber.visual.field.sessionTabsInfo")})})]}),Oo&&s.jsxs(s.Fragment,{children:[kn&&s.jsxs(He,{title:o("settings.openchamber.visual.section.chatDisplay"),divider:F,contentClassName:"space-y-6",children:[we("chatRenderMode")&&s.jsx(Cs,{title:o("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":o("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:T1.map(P=>{const St=te===P.id,vs=So%12;return s.jsxs("button",{type:"button",onClick:()=>Ao(P.id),"aria-pressed":St,className:Se("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",St?"border-border bg-interactive-selection text-interactive-selection-foreground":"border-border hover:border-border/80 hover:bg-interactive-hover"),children:[s.jsx("span",{className:Se("typography-ui-label",St?"text-inherit":"text-muted-foreground"),children:r(P.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:P.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ls=>{const Nn=Ls*3+1,ia=vs-Nn+1,Ki=ia<=0?0:ia===1?42:ia===2?68:92,yu=Ki>0;return s.jsxs("div",{className:Se("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",yu?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${Ki}%`}})]},Ls)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Ls=>{const Nn=vs>=(Ls+1)*3;return s.jsxs("div",{className:Se("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Nn?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},Ls)})})})]},P.id)})})}),we("activityRenderMode")&&s.jsx(Cs,{title:o("settings.openchamber.visual.section.activityDefault"),settingsItem:"chat.activity-default",children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.section.activityDefaultAria"),children:E1.map(P=>s.jsx(rs,{selected:je===P.id,onSelect:()=>ni(P.id),label:r(P.labelKey),ariaLabel:o("settings.openchamber.visual.field.activityDefaultModeAria",{option:r(P.labelKey)})},P.id))})})]}),Zn&&s.jsxs(He,{title:o("settings.openchamber.visual.section.messageStreamTransport"),divider:kn||F,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Xs,{value:Zt,options:Lc.map(P=>({value:P.id,label:r(P.labelKey)})),onChange:wa,"aria-label":o("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const P=Lc.find(St=>St.id===Zt);return P?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r(P.descriptionKey)}):null})()]}),Ea&&s.jsx(He,{title:o("settings.openchamber.visual.section.chatMessageOptions"),divider:kn||Zn||F,children:s.jsxs(Fn,{className:"lg:gap-y-6",children:[we("userMessageRendering")&&s.jsx(Cs,{title:o("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.section.userMessageRenderingAria"),children:A1.map(P=>s.jsx(rs,{selected:O1(I)===P.id,onSelect:()=>Io(P.id),label:r(P.labelKey),ariaLabel:o("settings.openchamber.visual.field.userMessageRenderingAria",{option:r(P.labelKey)})},P.id))})}),we("mermaidRendering")&&s.jsx(Cs,{title:o("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.section.mermaidRenderingAria"),children:P1.map(P=>s.jsx(rs,{selected:R===P.id,onSelect:()=>To(P.id),label:r(P.labelKey),ariaLabel:o("settings.openchamber.visual.field.mermaidRenderingAria",{option:r(P.labelKey)})},P.id))})}),we("diffLayout")&&!Ns&&s.jsx(Cs,{title:o("settings.openchamber.visual.section.diffLayout"),children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.section.diffLayoutAria"),children:I1.map(P=>s.jsx(rs,{selected:Ke===P.id,onSelect:()=>Le(P.id),label:r(P.labelKey),ariaLabel:o("settings.openchamber.visual.field.diffLayoutAria",{option:r(P.labelKey)})},P.id))})}),we("followUpBehavior")&&s.jsx(Cs,{title:o("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.section.followUpBehaviorAria"),children:D1.map(P=>s.jsx(rs,{selected:yt===P.id,onSelect:()=>st(P.id),label:r(P.labelKey),ariaLabel:o("settings.openchamber.visual.field.followUpBehaviorAria",{option:r(P.labelKey)})},P.id))})}),we("inputHistoryScope")&&s.jsx(Cs,{title:o("settings.openchamber.visual.field.inputHistoryScope"),info:o("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.section.inputHistoryScopeAria"),children:R1.map(P=>s.jsx(rs,{selected:rt===P.id,onSelect:()=>Sa(P.id),label:r(P.labelKey),ariaLabel:r(P.labelKey)},P.id))})}),we("inputHistoryLimit")&&s.jsx(Cs,{title:o("settings.openchamber.visual.field.inputHistoryLimit"),description:o("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:Es,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:za,children:[s.jsx(js,{value:de,onValueChange:aa,min:rp,max:op,step:1,className:ws,deferExternalValueWhileFocused:!0,"aria-label":o("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:Ua,children:o("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),we("messageSearch")&&!Ns&&s.jsx(x1,{}),Lo&&s.jsxs(s.Fragment,{children:[we("expandedTools")&&s.jsxs(He,{title:o("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:kn||Zn||Ea||F,contentClassName:ys,children:[s.jsx(xt,{checked:mt,onChange:Ca,label:o("settings.openchamber.visual.field.bash"),ariaLabel:o("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(xt,{checked:J,onChange:Do,label:o("settings.openchamber.visual.field.editTools"),ariaLabel:o("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(He,{title:o("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:ys,children:[s.jsx(xt,{checked:qe,onChange:dn,label:o("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:o("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),we("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(xt,{checked:f,onChange:v,label:o("settings.openchamber.visual.field.sessionRecap"),ariaLabel:o("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(xt,{checked:m,onChange:C,label:o("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:o("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),we("subagentReadOnlyBanner")&&s.jsx(xt,{checked:ut,onChange:Ce,label:o("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:o("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),we("sessionGoal")&&!Ns&&s.jsxs(He,{title:o("settings.openchamber.visual.goal.sectionTitle"),info:o("settings.openchamber.visual.goal.description"),contentClassName:ys,children:[s.jsx(xt,{checked:b,onChange:k,label:o("settings.openchamber.visual.field.sessionGoal"),ariaLabel:o("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsx(w1,{disabled:!b}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(xt,{checked:u,onChange:j,disabled:!b,label:o("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:o("settings.openchamber.visual.goal.budgetAria")}),b&&u?s.jsx(js,{value:N,onValueChange:P=>{typeof P=="number"&&Number.isFinite(P)&&P>0&&w(Math.floor(P))},min:1e3,max:1e8,step:5e4}):null]})]}),we("reasoning")&&s.jsxs(He,{title:o("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:ys,children:[s.jsx(xt,{checked:h,onChange:S,label:o("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:o("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),h&&s.jsx(xt,{checked:E,onChange:M,label:o("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:o("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(He,{title:o("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:ys,children:s.jsx(xt,{checked:A,onChange:x,label:o("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:o("settings.openchamber.visual.field.streamingAutoFollowAria"),info:o("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(we("collapsibleUserMessages")||we("stickyUserHeader")||we("promptNavigatorEnabled")||we("wideChatLayout")||we("splitAssistantMessageActions")||we("codeBlockLineWrap"))&&s.jsxs(He,{title:o("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:ys,children:[we("collapsibleUserMessages")&&s.jsx(xt,{checked:L,onChange:ka,label:o("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:o("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),we("stickyUserHeader")&&s.jsx(xt,{checked:H,onChange:Po,label:o("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:o("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),we("promptNavigatorEnabled")&&s.jsx(xt,{checked:G,onChange:Ss,label:o("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:o("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),we("wideChatLayout")&&s.jsx(xt,{checked:Z,onChange:Mn,label:o("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:o("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),we("splitAssistantMessageActions")&&s.jsx(xt,{checked:se,onChange:Qn,label:o("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:o("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:o("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),we("codeBlockLineWrap")&&s.jsx(xt,{checked:ne,onChange:X,label:o("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:o("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(we("showToolFileIcons")||we("showTurnChangedFiles")||we("dotfiles")&&!ms()||we("fileViewerPreview"))&&s.jsxs(He,{title:o("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:ys,children:[we("showToolFileIcons")&&s.jsx(xt,{checked:Nt,onChange:fs,label:o("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:o("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),we("showTurnChangedFiles")&&s.jsx(xt,{checked:$e,onChange:Eo,label:o("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:o("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),we("dotfiles")&&!ms()&&s.jsx(xt,{checked:p,onChange:lp,label:o("settings.openchamber.visual.field.showDotfiles"),ariaLabel:o("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),we("fileViewerPreview")&&s.jsx(xt,{checked:Ft,onChange:Na,label:o("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:o("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(we("persistDraft")||we("largeTextPaste")||!d&&we("inputSpellcheck")||we("enterToSend"))&&s.jsxs(He,{title:o("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:"space-y-6",children:[(we("persistDraft")||!d&&we("inputSpellcheck"))&&s.jsxs("div",{className:ys,children:[we("persistDraft")&&s.jsx(xt,{checked:ze,onChange:Ze,label:o("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:o("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!d&&we("inputSpellcheck")&&s.jsx(xt,{checked:tt,onChange:ml,label:o("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:o("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]}),we("largeTextPaste")&&s.jsx(Cs,{title:o("settings.openchamber.visual.field.largeTextPaste"),info:o("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(Js,{"aria-label":o("settings.openchamber.visual.field.largeTextPasteAria"),children:M1.map(P=>s.jsx(rs,{selected:Q===P.id,onSelect:()=>nt(P.id),label:r(P.labelKey),ariaLabel:o("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:r(P.labelKey)})},P.id))})}),we("enterToSend")&&s.jsx(Cs,{title:o("settings.openchamber.visual.field.enterToSend"),info:o("settings.openchamber.visual.field.enterToSendHint"),settingsItem:"chat.enter-to-send",children:s.jsxs(Js,{"aria-label":o("settings.openchamber.visual.field.enterToSend"),children:[s.jsx(rs,{selected:ht,onSelect:()=>un(!0),label:o("settings.openchamber.visual.option.enterToSend.enter.label"),ariaLabel:o("settings.openchamber.visual.option.enterToSend.enter.label")}),s.jsx(rs,{selected:!ht,onSelect:()=>un(!1),label:o("settings.openchamber.visual.option.enterToSend.modifier.label"),ariaLabel:o("settings.openchamber.visual.option.enterToSend.modifier.label")})]})})]})]})]}),we("reportUsage")&&s.jsx(He,{title:o("settings.openchamber.visual.section.privacy"),children:s.jsx(xt,{checked:si,onChange:Ai,label:o("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:o("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:o("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},K1=1,z1=365,zc=30,U1=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],ru=()=>{const t=_e.c(105),{t:e}=Be(),a=re(_1),n=re($1),i=re(B1),o=re(V1),r=re(H1),d=re(q1),c=re(G1);let g;t[0]===Symbol.for("react.memo_cache_sentinel")?(g={autoRun:!1},t[0]=g):g=t[0];const{candidates:p,isRunning:h,runCleanup:f,action:m,status:v}=xm(g),C=p.length;let b;t[1]!==f||t[2]!==e?(b=async()=>{const ce=await f({force:!0}).catch(()=>(U.error(e("sessions.sidebar.group.empty.loadFailed")),null));if(!(!ce||ce.skippedReason&&ce.skippedReason!=="no-candidates")){if(ce.completedIds.length===0&&ce.failedIds.length===0){U.message(ce.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ce.completedIds.length>0&&U.success(ce.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ce.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ce.completedIds.length})),ce.failedIds.length>0&&U.error(ce.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ce.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ce.failedIds.length}))}},t[1]=f,t[2]=e,t[3]=b):b=t[3];const k=b;let u;t[4]!==e?(u=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=u):u=t[5];const j=i?"settings.openchamber.sessionRetention.archivedTooltip":"settings.openchamber.sessionRetention.tooltip";let N;t[6]!==e||t[7]!==j?(N=e(j),t[6]=e,t[7]=j,t[8]=N):N=t[8];let w;t[9]!==e?(w=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[9]=e,t[10]=w):w=t[10];let S;t[11]!==e?(S=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[11]=e,t[12]=S):S=t[12];let A;t[13]!==a||t[14]!==o||t[15]!==w||t[16]!==S?(A=s.jsx(xt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:o,label:w,ariaLabel:S}),t[13]=a,t[14]=o,t[15]=w,t[16]=S,t[17]=A):A=t[17];let x;t[18]!==e?(x=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[18]=e,t[19]=x):x=t[19];let E;t[20]!==e?(E=e("settings.openchamber.sessionRetention.field.onlyArchived"),t[20]=e,t[21]=E):E=t[21];let M;t[22]!==e?(M=e("settings.openchamber.sessionRetention.field.onlyArchivedDescription"),t[22]=e,t[23]=M):M=t[23];let T;t[24]!==h||t[25]!==i||t[26]!==c||t[27]!==M||t[28]!==x||t[29]!==E?(T=s.jsx(xt,{settingsItem:"sessions.retention-only-archived",checked:i,onChange:c,disabled:h,label:x,ariaLabel:E,info:M}),t[24]=h,t[25]=i,t[26]=c,t[27]=M,t[28]=x,t[29]=E,t[30]=T):T=t[30];let D;t[31]!==e?(D=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[31]=e,t[32]=D):D=t[32];let R;t[33]!==e?(R=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[33]=e,t[34]=R):R=t[34];let O;t[35]===Symbol.for("react.memo_cache_sentinel")?(O=Se(ws,"tabular-nums"),t[35]=O):O=t[35];let I;t[36]!==n||t[37]!==r||t[38]!==R?(I=s.jsx(js,{value:n,onValueChange:r,min:K1,max:z1,step:1,"aria-label":R,className:O}),t[36]=n,t[37]=r,t[38]=R,t[39]=I):I=t[39];let y;t[40]!==e?(y=e("settings.openchamber.sessionRetention.field.days"),t[40]=e,t[41]=y):y=t[41];let L;t[42]!==y?(L=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:y}),t[42]=y,t[43]=L):L=t[43];let K;t[44]!==r?(K=()=>r(zc),t[44]=r,t[45]=K):K=t[45];const H=n===zc;let G;t[46]!==e?(G=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[46]=e,t[47]=G):G=t[47];let W;t[48]!==e?(W=e("settings.common.actions.reset"),t[48]=e,t[49]=W):W=t[49];let q;t[50]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(B,{name:"restart",className:"h-3.5 w-3.5"}),t[50]=q):q=t[50];let z;t[51]!==K||t[52]!==H||t[53]!==G||t[54]!==W?(z=s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:K,disabled:H,className:hs,"aria-label":G,title:W,children:q}),t[51]=K,t[52]=H,t[53]=G,t[54]=W,t[55]=z):z=t[55];let $;t[56]!==D||t[57]!==I||t[58]!==L||t[59]!==z?($=s.jsxs(Ct,{settingsItem:"sessions.retention-period",label:D,children:[I,L,z]}),t[56]=D,t[57]=I,t[58]=L,t[59]=z,t[60]=$):$=t[60];let Z;t[61]!==e?(Z=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[61]=e,t[62]=Z):Z=t[62];let _;t[63]!==i||t[64]!==e?(_=U1.map(ce=>({value:ce.value,label:e(ce.labelKey),disabled:i&&ce.value==="archive"})),t[63]=i,t[64]=e,t[65]=_):_=t[65];let ne;t[66]!==m||t[67]!==d||t[68]!==_?(ne=s.jsx(Xs,{value:m,onChange:d,options:_}),t[66]=m,t[67]=d,t[68]=_,t[69]=ne):ne=t[69];let X;t[70]!==Z||t[71]!==ne?(X=s.jsx(Ct,{settingsItem:"sessions.retention-action",label:Z,children:ne}),t[70]=Z,t[71]=ne,t[72]=X):X=t[72];let te;t[73]!==T||t[74]!==$||t[75]!==X?(te=s.jsxs(na,{className:"space-y-0",children:[T,$,X]}),t[73]=T,t[74]=$,t[75]=X,t[76]=te):te=t[76];let he;t[77]!==e?(he=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[77]=e,t[78]=he):he=t[78];let je;t[79]!==h||t[80]!==e?(je=e(h?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[79]=h,t[80]=e,t[81]=je):je=t[81];let fe;t[82]!==k||t[83]!==h||t[84]!==je?(fe=s.jsx(V,{type:"button",variant:"outline",size:"xs",onClick:k,disabled:h,className:"!font-normal",children:je}),t[82]=k,t[83]=h,t[84]=je,t[85]=fe):fe=t[85];let ke;t[86]!==he||t[87]!==fe?(ke=s.jsx(Ct,{label:he,children:fe}),t[86]=he,t[87]=fe,t[88]=ke):ke=t[88];let be;t[89]!==m||t[90]!==C||t[91]!==v||t[92]!==e?(be=v==="error"?e("sessions.sidebar.group.empty.loadFailed"):v!=="ready"?e("sessions.sidebar.group.empty.loadingSessions"):m==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:C}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:C}),t[89]=m,t[90]=C,t[91]=v,t[92]=e,t[93]=be):be=t[93];let De;t[94]!==be?(De=s.jsx("p",{className:"typography-meta text-muted-foreground",children:be}),t[94]=be,t[95]=De):De=t[95];let oe;t[96]!==ke||t[97]!==De?(oe=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[ke,De]}),t[96]=ke,t[97]=De,t[98]=oe):oe=t[98];let ee;return t[99]!==u||t[100]!==te||t[101]!==oe||t[102]!==N||t[103]!==A?(ee=s.jsxs(He,{title:u,info:N,children:[A,te,oe]}),t[99]=u,t[100]=te,t[101]=oe,t[102]=N,t[103]=A,t[104]=ee):ee=t[104],ee};function _1(t){return t.autoDeleteEnabled}function $1(t){return t.autoDeleteAfterDays}function B1(t){return t.sessionRetentionOnlyArchived}function V1(t){return t.setAutoDeleteEnabled}function H1(t){return t.setAutoDeleteAfterDays}function q1(t){return t.setSessionRetentionAction}function G1(t){return t.setSessionRetentionOnlyArchived}const lu=()=>{const t=_e.c(25),{t:e}=Be();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=ms(),t[0]=a):a=t[0];const n=a,i=re(W1),o=re(J1),r=re(Q1),d=re(Y1),c=es($r);let g;t[1]!==e?(g=e("settings.openchamber.sessionWork.title"),t[1]=e,t[2]=g):g=t[2];let p;t[3]!==e?(p=e("settings.openchamber.sessionWork.info"),t[3]=e,t[4]=p):p=t[4];let h;t[5]!==e?(h=e("settings.openchamber.sessionWork.field.enabled"),t[5]=e,t[6]=h):h=t[6];let f;t[7]!==e?(f=e("settings.openchamber.sessionWork.field.enabled"),t[7]=e,t[8]=f):f=t[8];let m;t[9]!==i||t[10]!==r||t[11]!==h||t[12]!==f?(m=s.jsx(xt,{settingsItem:"sessions.work-enabled",checked:i,onChange:r,label:h,ariaLabel:f}),t[9]=i,t[10]=r,t[11]=h,t[12]=f,t[13]=m):m=t[13];let v;t[14]!==o||t[15]!==i||t[16]!==c||t[17]!==d||t[18]!==e?(v=n?null:s.jsxs(na,{className:"space-y-0",children:[s.jsx(xt,{settingsItem:"sessions.work-auto-open",checked:i&&c&&o,onChange:d,disabled:!i||!c,label:e("settings.openchamber.sessionWork.field.autoOpen"),ariaLabel:e("settings.openchamber.sessionWork.field.autoOpen"),info:e("settings.openchamber.sessionWork.field.autoOpenInfo")}),s.jsx(xo,{})]}),t[14]=o,t[15]=i,t[16]=c,t[17]=d,t[18]=e,t[19]=v):v=t[19];let C;return t[20]!==g||t[21]!==p||t[22]!==m||t[23]!==v?(C=s.jsxs(He,{title:g,info:p,settingsItem:"sessions.work",children:[m,v]}),t[20]=g,t[21]=p,t[22]=m,t[23]=v,t[24]=C):C=t[24],C};function W1(t){return t.sessionWorkEnabled}function J1(t){return t.sessionWorkAutoOpen}function Q1(t){return t.setSessionWorkEnabled}function Y1(t){return t.setSessionWorkAutoOpen}const Uc=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(go(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),cu=()=>{const{t}=Be(),e=re(A=>A.timeFormatPreference),[a,n]=l.useState(!1),[i,o]=l.useState(!0),[r,d]=l.useState(!1),[c,g]=l.useState(null),[p,h]=l.useState(!1),[f,m]=l.useState([]),[v,C]=l.useState(bm),[b,k]=l.useState(""),u=l.useMemo(()=>vm(),[]),j=l.useCallback(async()=>{o(!0),k("");try{const A=await ym();m(A)}catch(A){const x=A instanceof Error?A.message:t("settings.openchamber.passkeys.toast.loadFailed");k(x)}finally{o(!1)}},[t]);l.useEffect(()=>{let A=!1;return(async()=>{try{if(!u.supported){A||(n(!1),o(!1));return}A||n(!0)}catch{A||n(!1)}if(!A){const x=await Uo();if(C(x),!x.enabled){m([]),o(!1);return}await j()}})(),()=>{A=!0,jl()}},[j,u.supported]);const N=l.useCallback(async()=>{if(!v.enabled){const A=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");k(A),U.message(A);return}if(!a){k(u.reason),U.message(u.reason);return}if(r){jl(),d(!1);return}k(""),d(!0);try{await jm(),C(await Uo()),await j(),U.success(t("settings.openchamber.passkeys.toast.added"))}catch(A){if(km(A)){U.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const x=A instanceof Error?A.message:t("settings.openchamber.passkeys.toast.addFailed");k(x),U.error(x)}finally{d(!1)}},[r,j,v.enabled,u.reason,a,t]),w=l.useCallback(async A=>{g(A),k("");try{await wm(A),C(await Uo()),await j(),U.success(t("settings.openchamber.passkeys.toast.removed"))}catch(x){const E=x instanceof Error?x.message:t("settings.openchamber.passkeys.toast.removeFailed");k(E),U.error(E)}finally{g(null)}},[j,t]),S=l.useCallback(async()=>{h(!0),k("");try{await Sm(),window.location.reload()}catch(A){const x=A instanceof Error?A.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");k(x),U.error(x),h(!1)}},[t]);return s.jsxs(He,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Ct,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(V,{type:"button",variant:r?"secondary":"outline",size:"xs",onClick:()=>{N()},disabled:i||p,className:"!font-normal",children:t(r?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>{S()},disabled:i||r||p,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(p?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!v.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),v.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:u.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):f.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:f.map(A=>s.jsxs(Ct,{label:s.jsx("span",{title:A.label,children:A.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:A.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Uc(A.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:Uc(A.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>{w(A.id)},disabled:c===A.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===A.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},A.id))})]}),b&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:b})})]})},du=()=>{const t=_e.c(14),{t:e}=Be(),a=kl(Z1),n=kl(X1);let i;t[0]!==e?(i=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=i):i=t[1];let o;t[2]!==e?(o=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=o):o=t[3];let r;t[4]!==n||t[5]!==e||t[6]!==a?(r=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.appLinks.empty")}):a.map(g=>s.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-[13px]",children:`${g}://`}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(g),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${g}://`}),children:e("settings.common.actions.delete")})]},g)),t[4]=n,t[5]=e,t[6]=a,t[7]=r):r=t[7];let d;t[8]!==r?(d=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:r}),t[8]=r,t[9]=d):d=t[9];let c;return t[10]!==i||t[11]!==o||t[12]!==d?(c=s.jsx(He,{title:i,description:o,children:d}),t[10]=i,t[11]=o,t[12]=d,t[13]=c):c=t[13],c};function Z1(t){return t.trustedSchemes}function X1(t){return t.removeTrustedScheme}const ej=()=>{const{t}=Be(),[e,a]=l.useState(null),n=l.useRef(0);l.useEffect(()=>{let o=!1;return Ts.getConfig(null).then(r=>{!o&&n.current===0&&a(!!r.warming)},r=>console.warn("[session-warming] failed to read config",r)),()=>{o=!0}},[]);const i=l.useCallback(async o=>{const r=e,d=++n.current;a(o),os("saving");try{const c=await It("/api/config/warming",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({enabled:o})});if(!c.ok)throw new Error(`HTTP ${c.status}`);os("saved"),Ts.clearConfigCache()}catch(c){console.warn("[session-warming] failed to save",c),os("error"),d===n.current&&a(r)}},[e]);return s.jsx(xt,{settingsItem:"sessions.warming",checked:e??!1,disabled:e===null,onChange:o=>{i(o)},label:t("settings.openchamber.defaults.field.sessionWarming"),info:t("settings.openchamber.defaults.field.sessionWarmingInfo")})},tj={ask:{icon:"shield-user",color:void 0},safety:{icon:"shield-star",color:"var(--status-success)"},auto:{icon:"shield-check",color:"var(--status-info)"}},sj=t=>{const e=_e.c(42),{agentName:a}=t,{t:n}=Be(),i=re(nj),o=re(aj),r=es($r),d=il(es(ij));let c;e[0]!==i||e[1]!==r?(c=Nm(i,r),e[0]=i,e[1]=r,e[2]=c):c=e[2];const g=c;let p;e[3]!==o?(p=T=>{o(T),kt({permissionDefaultMode:T})},e[3]=o,e[4]=p):p=e[4];const h=p;let f;e[5]!==a?(f=()=>{const T=a??ct.getState().currentAgentName;T&&Hn.getState().setSelectedAgent(T),re.getState().requestSettingsJump("agents","agents.permissions")},e[5]=a,e[6]=f):f=e[6];const m=f;let v;e[7]!==m||e[8]!==d||e[9]!==r||e[10]!==n?(v=T=>T==="safety"&&!r?s.jsxs(s.Fragment,{children:[n("settings.sessions.permissions.explain.safetyUnavailable")," ",s.jsx(Vn,{onClick:lo,children:n("settings.jevAccess.setUp")})]}):T==="safety"?s.jsxs(s.Fragment,{children:[d?n("settings.sessions.permissions.explain.safetyVia",{provider:d}):n("settings.sessions.permissions.explain.safety")," ",s.jsx(Vn,{onClick:lo,children:n("settings.jevAccess.manage")})]}):s.jsxs(s.Fragment,{children:[n(T==="auto"?"settings.sessions.permissions.explain.auto":"settings.sessions.permissions.explain.ask")," ",s.jsx(Vn,{onClick:m,children:n("settings.sessions.permissions.agentPermissionsLink")})]}),e[7]=m,e[8]=d,e[9]=r,e[10]=n,e[11]=v):v=e[11];const C=v;let b;e[12]!==C||e[13]!==r?(b=(T,D)=>{const{icon:R,color:O}=tj[T];return{value:T,label:s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(B,{name:R,className:"size-3.5",style:O?{color:O}:void 0}),D]}),tooltip:C(T),disabled:T==="safety"&&!r}},e[12]=C,e[13]=r,e[14]=b):b=e[14];const k=b;let u;e[15]!==n?(u=n("settings.sessions.permissions.defaultMode"),e[15]=n,e[16]=u):u=e[16];let j;e[17]!==n?(j=n("settings.sessions.permissions.defaultModeInfo"),e[17]=n,e[18]=j):j=e[18];let N;e[19]!==n?(N=n("settings.sessions.permissions.defaultMode"),e[19]=n,e[20]=N):N=e[20];let w;e[21]!==k||e[22]!==n?(w=[k("ask",n("settings.sessions.permissions.mode.ask")),k("safety",n("settings.sessions.permissions.mode.safety")),k("auto",n("settings.sessions.permissions.mode.auto"))],e[21]=k,e[22]=n,e[23]=w):w=e[23];let S;e[24]!==h||e[25]!==g||e[26]!==N||e[27]!==w?(S=s.jsx(Xs,{"aria-label":N,value:g,onChange:h,options:w}),e[24]=h,e[25]=g,e[26]=N,e[27]=w,e[28]=S):S=e[28];let A;e[29]!==S||e[30]!==u||e[31]!==j?(A=s.jsx(Ct,{settingsItem:"sessions.permission-default",label:u,info:j,children:S}),e[29]=S,e[30]=u,e[31]=j,e[32]=A):A=e[32];let x;e[33]!==C||e[34]!==g?(x=s.jsx("p",{className:ls,children:C(g)}),e[33]=C,e[34]=g,e[35]=x):x=e[35];let E;e[36]!==r?(E=r?null:s.jsx(xo,{}),e[36]=r,e[37]=E):E=e[37];let M;return e[38]!==A||e[39]!==x||e[40]!==E?(M=s.jsxs("div",{className:"space-y-1",children:[A,x,E]}),e[38]=A,e[39]=x,e[40]=E,e[41]=M):M=e[41],M};function nj(t){return t.permissionDefaultMode}function aj(t){return t.setPermissionDefaultMode}function ij(t){return t.classifier?.effective??null}const rr=t=>{const e=_n(t);return e||{providerId:"",modelId:""}},uu=()=>{const{t}=Be(),e=ct(oe=>oe.setProvider),a=ct(oe=>oe.setModel),n=ct(oe=>oe.setAgent),i=ct(oe=>oe.setCurrentVariant),o=ct(oe=>oe.setCurrentVariantOverride),r=ct(oe=>oe.setSettingsDefaultModel),d=ct(oe=>oe.setSettingsDefaultVariant),c=ct(oe=>oe.setSettingsDefaultAgent),g=ct(oe=>oe.selectionSource==="manual"),p=Cm(oe=>oe.currentSessionId),h=wl(oe=>oe.getSessionModelSelection),f=wl(oe=>oe.getSessionAgentSelection),m=ct(oe=>oe.agentSelectionSource==="manual"),C=!!(ct(oe=>{if(oe.agentSelectionSource!=="manual")return!1;const ee=oe.agents.find(ce=>ce.name===oe.currentAgentName);return!!(ee?.model?.providerID&&ee.model.id)})||g&&p&&h(p)),b=!!(m&&p&&f(p)),k=l.useMemo(()=>ms(),[]),u=re(oe=>oe.showDeletionDialog),j=re(oe=>oe.setShowDeletionDialog),N=ct(oe=>oe.providers),w=ct(oe=>oe.modelsMetadata),[S,A]=l.useState(),[x,E]=l.useState(),[M,T]=l.useState(),[D,R]=l.useState(!0),[O,I]=l.useState(),[y,L]=l.useState([]),[K,H]=l.useState(),[G,W]=l.useState(!0),q=l.useMemo(()=>rr(S),[S]);l.useEffect(()=>{(async()=>{try{const ee=await En();if(ee){const ce=ee.defaultModel?.trim()||void 0,ue=ee.defaultVariant?.trim()||void 0,Ie=ee.defaultAgent?.trim()||void 0;ce!==void 0&&A(ce),ue!==void 0&&E(ue),Ie!==void 0&&T(Ie),ee.smallModelUseDefault!==void 0&&R(ee.smallModelUseDefault);const ve=ee.smallModelOverride?.trim();ve&&I(ve);const Re=ee.walkthroughModelOverride?.trim();Re&&H(Re)}}catch(ee){console.warn("Failed to load defaults settings:",ee)}finally{W(!1)}})()},[]);const z=l.useCallback(async(oe,ee)=>{const ce=oe&&ee?`${oe}/${ee}`:void 0;A(ce),E(void 0),d(void 0),r(ce),C||(i(void 0),oe&&ee&&(N.find(Ie=>Ie.id===oe)||wd(oe,ee))&&(e(oe),a(ee)));try{await kt({defaultModel:ce??"",defaultVariant:""})}catch(ue){console.warn("Failed to save default model:",ue)}},[C,N,i,a,e,r,d]),$="__default__",Z=l.useCallback(oe=>oe===$?t("settings.openchamber.defaults.option.default"):oe.charAt(0).toUpperCase()+oe.slice(1),[t]),_=l.useCallback(async oe=>{const ee=oe===$?void 0:oe||void 0;E(ee),d(ee),C||o(ee??null,ee);try{await kt({defaultVariant:ee??""})}catch(ce){console.warn("Failed to save default variant:",ce)}},[C,o,d]),ne=l.useCallback(async oe=>{const ee=oe||void 0;T(ee),c(ee),oe&&!b&&n(oe);try{await kt({defaultAgent:ee??""})}catch(ce){console.warn("Failed to save default agent:",ce)}},[b,n,c]),X=l.useCallback(async oe=>{R(oe);try{await kt({smallModelUseDefault:oe})}catch(ee){console.warn("Failed to save small model preference:",ee)}},[]),te=l.useCallback(async(oe,ee)=>{const ce=oe&&ee?`${oe}/${ee}`:void 0;I(ce);try{await kt({smallModelOverride:ce??""})}catch(ue){console.warn("Failed to save small model override:",ue)}},[]),he=l.useCallback(async(oe,ee)=>{const ce=oe&&ee?`${oe}/${ee}`:void 0;H(ce);try{await kt({walkthroughModelOverride:ce??""})}catch(ue){console.warn("Failed to save walkthrough model override:",ue)}},[]),je=l.useCallback((oe,ee)=>w.get(`${oe}/${ee}`)?.structured_output!==!1,[w]),fe=l.useMemo(()=>rr(O),[O]),ke=l.useMemo(()=>rr(K),[K]);l.useEffect(()=>{let oe=!1;return(async()=>{try{const ee=await It("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!ee.ok)return;const ce=await ee.json().catch(()=>null);!oe&&Array.isArray(ce?.authenticatedProviders)&&L(ce.authenticatedProviders.filter(ue=>typeof ue=="string"))}catch{}})(),()=>{oe=!0}},[]);const be=l.useMemo(()=>{if(!q.providerId||!q.modelId)return[];const ee=N.find(ce=>ce.id===q.providerId)?.models.find(ce=>ce.id===q.modelId);return Im(ee?.variants)},[q.modelId,q.providerId,N]),De=be.length>0;return G?null:s.jsx(s.Fragment,{children:s.jsx(He,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-4 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",q.providerId?s.jsxs("span",{className:"text-foreground",children:[q.providerId,"/",q.modelId,De?` (${x??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),M&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:M})]})]}),s.jsxs("div",{className:Ms,children:[s.jsx(Ct,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(ga,{providerId:q.providerId,modelId:q.modelId,onChange:z,className:Zs,offerAuto:!0})}),s.jsx(Ct,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Dt,{value:x??$,onValueChange:_,disabled:!De,children:[s.jsx(Tt,{size:Qt,className:fn,children:s.jsx(Jt,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:Z(x??$)})}),s.jsxs(Et,{children:[s.jsx(gt,{value:$,children:t("settings.openchamber.defaults.option.default")}),be.map(oe=>s.jsx(gt,{value:oe,children:Z(oe)},oe))]})]})}),s.jsx(Ct,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(Fr,{agentName:M||"",onChange:ne,filter:oe=>md(oe.mode),className:Zs})}),k?null:s.jsx(sj,{agentName:M})]}),s.jsxs(na,{className:ys,children:[s.jsx(xt,{settingsItem:"sessions.deletion-dialog",checked:u,onChange:j,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx(ej,{})]}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(An,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Gt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(xt,{settingsItem:"sessions.small-model",checked:D,onChange:oe=>{X(oe)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),D?null:s.jsx(Ct,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(ga,{providerId:fe.providerId,modelId:fe.modelId,onChange:te,allowedProviderIds:y,className:Zs})}),s.jsxs(na,{className:ys,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(An,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Gt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Ct,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(ga,{providerId:ke.providerId,modelId:ke.modelId,onChange:he,allowedProviderIds:y,isModelAllowed:je,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:Zs})})]})]})]})})})},_c={completion:{titleKey:"settings.notifications.page.template.defaults.completion.title",messageKey:"settings.notifications.page.template.defaults.completion.message"},error:{titleKey:"settings.notifications.page.template.defaults.error.title",messageKey:"settings.notifications.page.template.defaults.error.message"},question:{titleKey:"settings.notifications.page.template.defaults.question.title",messageKey:"settings.notifications.page.template.defaults.question.message"},subtask:{titleKey:"settings.notifications.page.template.defaults.subtask.title",messageKey:"settings.notifications.page.template.defaults.subtask.message"}},oj={completion:"settings.notifications.page.template.event.completion",subtask:"settings.notifications.page.template.event.subtask",error:"settings.notifications.page.template.event.error",question:"settings.notifications.page.template.event.question"},rj=()=>{const{t}=Be(),e=l.useMemo(()=>us(),[]),a=l.useMemo(()=>ms(),[]),n=l.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,o=re(z=>z.nativeNotificationsEnabled),r=re(z=>z.setNativeNotificationsEnabled),d=re(z=>z.notificationMode),c=re(z=>z.setNotificationMode),g=re(z=>z.notifyOnSubtasks),p=re(z=>z.setNotifyOnSubtasks),h=re(z=>z.notifyOnCompletion),f=re(z=>z.setNotifyOnCompletion),m=re(z=>z.notifyOnError),v=re(z=>z.setNotifyOnError),C=re(z=>z.notifyOnQuestion),b=re(z=>z.setNotifyOnQuestion),k=re(z=>z.notificationTemplates),u=re(z=>z.setNotificationTemplates),[j,N]=l.useState("default"),[w,S]=l.useState(!1),[A,x]=l.useState(!1),[E,M]=l.useState(!1);l.useEffect(()=>{if(!i){S(!1),x(!1);return}typeof Notification<"u"&&N(Notification.permission);const z=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;S(z),(async()=>{if(!z){x(!1);return}try{const Z=await navigator.serviceWorker.getRegistration();if(!Z){x(!1);return}const _=await Z.pushManager.getSubscription();x(!!_)}catch{x(!1)}})()},[i]);const T=async z=>{if(e){r(z);return}if(!i){r(z);return}if(z&&typeof Notification<"u"&&Notification.permission==="default")try{const $=await Notification.requestPermission();N($),$==="granted"?r(!0):U.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch($){console.error("Failed to request notification permission:",$),U.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else r(!!(z&&j==="granted"))},D=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",R=(z,$,Z)=>{u(_=>({..._,[z]:{..._[z],[$]:Z}}))},O=z=>{const $="=".repeat((4-z.length%4)%4),Z=(z+$).replace(/-/g,"+").replace(/_/g,"/"),_=atob(Z),ne=new Uint8Array(_.length);for(let X=0;X<_.length;X+=1)ne[X]=_.charCodeAt(X);return ne},I=async(z,$,Z)=>{let _=null;const ne=new Promise((X,te)=>{_=setTimeout(()=>{te(new Error(Z))},$)});try{return await Promise.race([z,ne])}finally{_&&clearTimeout(_)}},y=async z=>{if(z.active)return;const $=z.installing||z.waiting;$&&$.state!=="activated"&&await I(new Promise(Z=>{const _=()=>{$.state==="activated"&&($.removeEventListener("statechange",_),Z())};$.addEventListener("statechange",_),_()}),15e3,"Service worker activation timed out")},L=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const z=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let $=null;for(const Z of z)try{const _=Z.opts?navigator.serviceWorker.register("/sw.js",Z.opts):navigator.serviceWorker.register("/sw.js");return await I(_,1e4,`Service worker registration timed out (${Z.label})`)}catch(_){$=_}throw $ instanceof Error?$:new Error("Service worker registration failed")},K=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const z=await navigator.serviceWorker.getRegistration();if(z)return z;const $=await L();try{await $.update()}catch{}return await y($),$},H=z=>{const $=z,Z=[`type=${typeof z}`,`toString=${String(z)}`,`name=${String($?.name??"")}`,`message=${String($?.message??"")}`];let _="";try{_=JSON.stringify(z)}catch{}return{summary:Z.filter(Boolean).join(" | "),json:_,stack:typeof $?.stack=="string"?$.stack:""}},G=async()=>{const z=qa();if(!z?.notifications){U.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await z.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?U.success(t("settings.notifications.page.toast.testNotificationSent")):U.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch($){console.error("Test notification failed:",$),U.error(t("settings.notifications.page.toast.testNotificationFailed"))}},W=async()=>{if(!w){U.error(t("settings.notifications.page.toast.pushUnsupported"));return}const z=qa();if(!z?.push){U.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}M(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const je=await Notification.requestPermission();if(N(je),je!=="granted"){U.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){U.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const $=await z.push.getVapidPublicKey();if(!$?.publicKey){U.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Z=await K();await y(Z);const _=await Z.pushManager.getSubscription();if(!("pushManager"in Z)||!Z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const X=(_??await I(Z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:O($.publicKey)}),15e3,"Push subscription timed out")).toJSON(),te=X.keys;if(!X.endpoint||!te?.p256dh||!te.auth)throw new Error("Push subscription missing keys");if(!(await I(z.push.subscribe({endpoint:X.endpoint,keys:{p256dh:te.p256dh,auth:te.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:cp()}),15e3,"Push subscribe request timed out"))?.ok){U.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}x(!0),U.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch($){console.error("[Push] Enable failed:",$);const Z=H($);U.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Z.summary})}finally{M(!1)}},q=async()=>{if(!w){x(!1);return}const z=qa();if(!z?.push){U.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}M(!0);try{const Z=await(await K()).pushManager.getSubscription();if(!Z){x(!1);return}const _=Z.endpoint;await Z.unsubscribe(),await z.push.unsubscribe({endpoint:_}),x(!1),U.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{M(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(He,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:ys,children:[s.jsx(xt,{checked:o&&D,onChange:z=>{T(z)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),o&&D&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(xt,{checked:d==="always",onChange:z=>c(z?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(V,{type:"button",variant:"outline",size:"sm",onClick:()=>{G()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[j==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),j==="granted"&&!o&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),o&&D&&s.jsxs(s.Fragment,{children:[s.jsx(He,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:ys,children:[s.jsx(xt,{checked:h,onChange:f,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(xt,{checked:g,onChange:p,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(xt,{checked:m,onChange:v,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(xt,{checked:C,onChange:b,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(He,{title:t("settings.notifications.page.template.title"),description:s.jsxs(s.Fragment,{children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--syntax-variable)]",children:"{last_message}"})]}),children:s.jsx(Fn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(z=>s.jsxs("section",{className:"p-2",children:[s.jsx(An,{className:"capitalize",children:t(oj[z])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(Ge,{value:k[z].title,onChange:$=>R(z,"title",$.target.value),className:"h-7",placeholder:t(_c[z].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(Ge,{value:k[z].message,onChange:$=>R(z,"message",$.target.value),className:"h-7",placeholder:t(_c[z].messageKey)})]})]})]},z))})})]}),i&&s.jsx(He,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(xt,{checked:w?A:!1,disabled:!w||E,onChange:z=>{z?W():q()},label:t("settings.notifications.page.push.enableLabel"),description:w?void 0:t("settings.notifications.page.push.unsupportedHint"),info:w?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:E?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Fs=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Ln="oc-surface-elevated w-full h-7 rounded-lg border border-input bg-surface-elevated px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring focus:border-interactive-border-focus",lj=[{id:"parakeet-tdt-0.6b-v2-int8",labelKey:"settings.voice.page.stt.model.parakeetV2",badgeKey:"settings.voice.page.stt.badge.bestForEnglish",accuracy:5,speed:5,size:"460 MB"},{id:"parakeet-tdt-0.6b-v3-int8",labelKey:"settings.voice.page.stt.model.parakeetV3",badgeKey:"settings.voice.page.stt.badge.bestForMultilingual",accuracy:5,speed:4,size:"465 MB"},{id:"whisper-base-int8",labelKey:"settings.voice.page.stt.model.whisperBase",badgeKey:null,accuracy:3,speed:3,size:"200 MB"},{id:"whisper-tiny-int8",labelKey:"settings.voice.page.stt.model.whisperTiny",badgeKey:null,accuracy:2,speed:4,size:"115 MB"}],$c=t=>{const e=_e.c(8),{value:a,label:n}=t,i=`${n}: ${a}/5`,o=`${a/5*100}%`;let r;e[0]!==o?(r=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:o}})}),e[0]=o,e[1]=r):r=e[1];let d;e[2]!==n?(d=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=d):d=e[3];let c;return e[4]!==i||e[5]!==r||e[6]!==d?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[r,d]}),e[4]=i,e[5]=r,e[6]=d,e[7]=c):c=e[7],c},cj=({selectedModelId:t,onSelect:e})=>{const{t:a}=Be(),n=at.useCallback(f=>a(f),[a]),[i,o]=at.useState(new Map),[r,d]=at.useState(null),c=at.useCallback(async()=>{try{const f=await It("/api/dictation/status",{query:{provider:"local"}});if(!f.ok)return;const m=await f.json();Array.isArray(m?.models)&&o(new Map(m.models.map(v=>[v.id,v])))}catch{}},[]);at.useEffect(()=>{c()},[c]);const g=Array.from(i.values()).some(f=>f.downloading);at.useEffect(()=>{if(!g)return;const f=setInterval(()=>{c()},2e3);return()=>clearInterval(f)},[g,c]);const p=async f=>{d(f);try{await It(`/api/dictation/models/${encodeURIComponent(f)}/download`,{method:"POST"}),await c()}catch{}finally{d(null)}},h=async f=>{d(f);try{await It(`/api/dictation/models/${encodeURIComponent(f)}`,{method:"DELETE"}),await c()}catch{}finally{d(null)}};return s.jsx("div",{role:"radiogroup","aria-label":a("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:lj.map(f=>{const m=t===f.id,v=i.get(f.id)??null;return s.jsx("div",{className:Se("rounded-lg border border-[var(--interactive-border)] p-3",m&&"border-border bg-interactive-selection text-interactive-selection-foreground"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(f.id),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),e(f.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(Kr,{checked:m,onChange:()=>e(f.id),ariaLabel:n(f.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:Se("typography-ui-label font-normal",m?"text-foreground":"text-foreground/50"),children:n(f.labelKey)}),f.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(f.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx($c,{value:f.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx($c,{value:f.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:f.size})]}),v?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:v?.installed?s.jsxs(s.Fragment,{children:[s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:r===f.id,onClick:()=>{h(f.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(B,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(B,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):v?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(B,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof v.downloadProgress=="number"?`${v.downloadProgress}%`:""})]}):s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:r===f.id,onClick:()=>{p(f.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(B,{name:"download",className:"h-4 w-4"})})})]})},f.id)})})},dj=[{id:0,label:"Alloy (af)"},{id:1,label:"Bella (af)"},{id:2,label:"Nicole (af)"},{id:3,label:"Sarah (af)"},{id:4,label:"Sky (af)"},{id:5,label:"Adam (am)"},{id:6,label:"Michael (am)"},{id:7,label:"Emma (bf)"},{id:8,label:"Isabella (bf)"},{id:9,label:"George (bm)"},{id:10,label:"Lewis (bm)"}],Er="kokoro-en-v0_19",uj="kokoro-multi-lang-v1_1",mj=[{id:0,label:"Maple (af)"},{id:1,label:"Sol (af)"},{id:2,label:"Vale (bf)"},{id:3,label:"Xiaoxiao (zf)"},{id:58,label:"Yunxi (zm)"}],di=(t,e)=>`${t}:${e}`,pj=()=>{const[t,e]=at.useState([]),[a,n]=at.useState(null),i=at.useCallback(async()=>{try{const d=await It("/api/dictation/status",{query:{provider:"local"}});if(!d.ok)return;const c=await d.json();Array.isArray(c?.ttsModels)&&e(c.ttsModels)}catch{}},[]);at.useEffect(()=>{i()},[i]);const o=t.some(d=>d.downloading);at.useEffect(()=>{if(!o)return;const d=setInterval(()=>{i()},2e3);return()=>clearInterval(d)},[o,i]);const r=at.useCallback(async(d,c)=>{n(d);try{const g=c==="POST"?`/api/dictation/models/${d}/download`:`/api/dictation/models/${d}`;await It(g,{method:c}),await i()}catch{}finally{n(null)}},[i]);return{models:t,requestingId:a,request:r,refresh:i}},gj=t=>{const e=dj.map(a=>({modelId:Er,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===Er||!a.installed)){if(a.id===uj){for(const n of mj)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},fj=t=>{const e=_e.c(14),{models:a,requestingId:n,request:i}=t,{t:o}=Be();let r,d,c;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==o){c=Symbol.for("react.early_return_sentinel");e:{const p=a.filter(bj);if(p.length===0){c=null;break e}r="flex flex-col";let h;e[7]!==i||e[8]!==n||e[9]!==o?(h=f=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:f.description??f.id}),f.installed?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":o("settings.voice.page.stt.modelInstalled")}),s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n!==null,onClick:()=>{i(f.id,"DELETE")},title:o("settings.voice.page.stt.modelDelete"),"aria-label":o("settings.voice.page.stt.modelDelete"),children:s.jsx(B,{name:"delete-bin",className:"h-4 w-4"})})]}):f.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(B,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof f.downloadProgress=="number"?`${f.downloadProgress}%`:""})]}):s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{i(f.id,"POST")},title:o("settings.voice.page.stt.modelDownload"),"aria-label":o("settings.voice.page.stt.modelDownload"),children:s.jsx(B,{name:"download",className:"h-4 w-4"})}),f.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:f.downloadError}):null]},f.id),e[7]=i,e[8]=n,e[9]=o,e[10]=h):h=e[10],d=p.map(h)}e[0]=a,e[1]=i,e[2]=n,e[3]=o,e[4]=r,e[5]=d,e[6]=c}else r=e[4],d=e[5],c=e[6];if(c!==Symbol.for("react.early_return_sentinel"))return c;let g;return e[11]!==r||e[12]!==d?(g=s.jsx("div",{className:r,children:d}),e[11]=r,e[12]=d,e[13]=g):g=e[13],g},hj=[{value:"alloy",label:"Alloy"},{value:"ash",label:"Ash"},{value:"ballad",label:"Ballad"},{value:"coral",label:"Coral"},{value:"echo",label:"Echo"},{value:"fable",label:"Fable"},{value:"nova",label:"Nova"},{value:"onyx",label:"Onyx"},{value:"sage",label:"Sage"},{value:"shimmer",label:"Shimmer"},{value:"verse",label:"Verse"},{value:"marin",label:"Marin"},{value:"cedar",label:"Cedar"}],xj=()=>{const{t}=Be(),{isMobile:e}=qn(),a=ct(Q=>Q.voiceProvider),n=ct(Q=>Q.setVoiceProvider),i=ct(Q=>Q.speechRate),o=ct(Q=>Q.setSpeechRate),r=ct(Q=>Q.speechPitch),d=ct(Q=>Q.setSpeechPitch),c=ct(Q=>Q.speechVolume),g=ct(Q=>Q.setSpeechVolume),p=ct(Q=>Q.sayVoice),h=ct(Q=>Q.setSayVoice),f=ct(Q=>Q.localTtsVoiceId),m=ct(Q=>Q.localTtsModelId),v=ct(Q=>Q.setLocalTtsModelId),C=pj(),b=at.useMemo(()=>gj(C.models),[C.models]),k=ct(Q=>Q.ttsFollowTextLanguage),u=ct(Q=>Q.setTtsFollowTextLanguage),j=ct(Q=>Q.setLocalTtsVoiceId),{speak:N,stop:w,isPlaying:S,error:A}=Pm(),x=at.useCallback(()=>{if(S){w();return}const Q=b.find(nt=>nt.modelId===m&&nt.speakerId===f)?.label??String(f);N(t("settings.voice.page.preview.voiceLine",{voiceName:Q}),{model:m,speakerId:f,speed:ct.getState().speechRate})},[S,m,f,b,N,w,t]),E=ct(Q=>Q.browserVoice),M=ct(Q=>Q.setBrowserVoice),T=ct(Q=>Q.openaiVoice),D=ct(Q=>Q.setOpenaiVoice),R=ct(Q=>Q.openaiApiKey),O=ct(Q=>Q.setOpenaiApiKey),I=ct(Q=>Q.openaiCompatibleUrl),y=ct(Q=>Q.setOpenaiCompatibleUrl),L=ct(Q=>Q.openaiCompatibleApiKey),K=ct(Q=>Q.setOpenaiCompatibleApiKey),H=ct(Q=>Q.openaiCompatibleVoice),G=ct(Q=>Q.setOpenaiCompatibleVoice),W=ct(Q=>Q.openaiCompatibleTtsModel),q=ct(Q=>Q.setOpenaiCompatibleTtsModel),z=ct(Q=>Q.showMessageTTSButtons),$=ct(Q=>Q.ttsInputMode),Z=ct(Q=>Q.setTtsInputMode),_=ct(Q=>Q.sttProvider),ne=ct(Q=>Q.setSttProvider),X=ct(Q=>Q.sttServerUrl),te=ct(Q=>Q.setSttServerUrl),he=ct(Q=>Q.sttApiKey),je=ct(Q=>Q.setSttApiKey),fe=ct(Q=>Q.sttModel),ke=ct(Q=>Q.setSttModel),be=ct(Q=>Q.sttLocalModel),De=ct(Q=>Q.setSttLocalModel),oe=ct(Q=>Q.sttLanguage),ee=ct(Q=>Q.setSttLanguage),ce=ct(Q=>Q.setShowMessageTTSButtons),ue=ct(Q=>Q.dictationEnabled),Ie=ct(Q=>Q.setDictationEnabled),[ve,Re]=at.useState(!1),[Me,me]=at.useState([]),[Te,Oe]=at.useState(!1),[pe,xe]=at.useState(null),[ae,ie]=at.useState(!1),[ge,Ee]=at.useState(!1),[Ke,Le]=at.useState(!1),[Ne,Ve]=at.useState(null),[Ye,pt]=at.useState(!1),[vt,wt]=at.useState(null),[yt,st]=at.useState([]),[rt,de]=at.useState(!1);at.useEffect(()=>((async()=>{const nt=await _o.waitForVoices();st(nt)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{st(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ue=at.useMemo(()=>yt.filter(Q=>Q.lang).sort((Q,nt)=>{const ot=Q.lang.startsWith("en"),it=nt.lang.startsWith("en");if(ot&&!it)return-1;if(!ot&&it)return 1;const ft=Q.lang.localeCompare(nt.lang);return ft!==0?ft:Q.name.localeCompare(nt.name)}),[yt]),et=at.useCallback(()=>{if(rt){_o.cancelSpeech(),de(!1);return}const Q=yt.find(ft=>ft.name===E),nt=Q?.name??t("settings.voice.page.preview.browserVoiceFallback"),ot=t("settings.voice.page.preview.voiceLine",{voiceName:nt});de(!0);const it=new SpeechSynthesisUtterance(ot);it.rate=i,it.pitch=r,it.volume=c,Q&&(it.voice=Q,it.lang=Q.lang),it.onend=()=>de(!1),it.onerror=()=>de(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(it)},[E,yt,i,r,c,rt,t]);at.useEffect(()=>()=>{rt&&_o.cancelSpeech()},[rt]),at.useEffect(()=>{if(!z||a!=="openai"&&a!=="openai-compatible"){ie(R.trim().length>0);return}(async()=>{try{const ot=await(await It("/api/tts/status")).json(),it=ot.available,ft=R.trim().length>0,bt=ot.enterpriseMode===!0;Ee(bt),ie(!bt&&(it||ft))}catch{ie(R.trim().length>0)}})()},[R,z,a]),at.useEffect(()=>{if(!z){Re(!1),me([]);return}It("/api/tts/say/status").then(Q=>Q.json()).then(Q=>{if(Re(Q.available),Q.voices){const nt=Q.voices.filter((ot,it,ft)=>ft.findIndex(bt=>bt.name===ot.name)===it).sort((ot,it)=>ot.name.localeCompare(it.name));me(nt)}}).catch(()=>{Re(!1)})},[z]);const ze=at.useCallback(async()=>{if(pe){Fs(pe),xe(null),Oe(!1);return}Oe(!0);let Q=null;try{const nt=await It("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:p}),voice:p,rate:Math.round(100+(i-.5)*200)})});if(!nt.ok)throw new Error("Preview failed");const ot=await nt.blob(),it=URL.createObjectURL(ot);Q=new Audio(it),Q.onended=()=>{Fs(Q),xe(null),Oe(!1)},Q.onerror=()=>{Fs(Q),xe(null),Oe(!1)},xe(Q),await Q.play()}catch{Fs(Q),xe(null),Oe(!1)}},[p,i,pe,t]);at.useEffect(()=>()=>{Fs(pe)},[pe]);const Ze=at.useCallback(async()=>{if(Ne){Fs(Ne),Ve(null),Le(!1);return}Le(!0);let Q=null;try{const nt=await It("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:T}),voice:T,speed:i,apiKey:R||void 0})});if(!nt.ok){const ft=await nt.json().catch(()=>({error:"Unknown error"}));throw new Error(ft.error||`HTTP ${nt.status}`)}const ot=await nt.blob(),it=URL.createObjectURL(ot);Q=new Audio(it),Q.onended=()=>{Fs(Q),Ve(null),Le(!1)},Q.onerror=()=>{Fs(Q),Ve(null),Le(!1)},Ve(Q),await Q.play()}catch{Fs(Q),Ve(null),Le(!1)}},[T,i,Ne,R,t]);at.useEffect(()=>()=>{Fs(Ne)},[Ne]);const tt=at.useCallback(async()=>{if(vt){Fs(vt),wt(null),pt(!1);return}if(!I.trim())return;pt(!0);let Q=null;try{const nt=await It("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:H,model:W||void 0,speed:i,baseURL:I,apiKey:L||void 0})});if(!nt.ok){const ft=await nt.json().catch(()=>({error:"Unknown error"}));throw new Error(ft.error||`HTTP ${nt.status}`)}const ot=await nt.blob(),it=URL.createObjectURL(ot);Q=new Audio(it),Q.onended=()=>{Fs(Q),wt(null),pt(!1)},Q.onerror=()=>{Fs(Q),wt(null),pt(!1)},wt(Q),await Q.play()}catch{Fs(Q),wt(null),pt(!1)}},[I,H,W,L,i,vt,t]);at.useEffect(()=>()=>{Fs(vt)},[vt]);const lt="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs(s.Fragment,{children:[s.jsxs(He,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(xt,{checked:z,onChange:ce,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),z&&s.jsxs(s.Fragment,{children:[s.jsx(Cs,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.localTts")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.openai")})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]}),children:s.jsx(Xs,{value:a,onChange:n,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"browser",label:t("settings.voice.page.provider.browser")},{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai",label:t("settings.voice.page.provider.openai")},{value:"openai-compatible",label:t("settings.voice.page.provider.custom")},...ve?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),ge&&(a==="openai"||a==="openai-compatible")&&s.jsx("p",{className:ls,children:t("settings.voice.page.enterpriseMode")}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Se(Pt,!ae&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:Se(ls,!ae&&"text-[var(--status-error)]/80"),children:t(ae&&!R?"settings.voice.page.field.apiKeyHintUsingConfig":ae?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:Se("relative",Es),children:[s.jsx("input",{type:"password",value:R,onChange:Q=>O(Q.target.value),placeholder:"sk-...",className:Ln}),R&&s.jsx("button",{type:"button",onClick:()=>O(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Se(Pt,!I.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Gt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:Se("relative",Es),children:[s.jsx("input",{type:"text",value:I,onChange:Q=>y(Q.target.value),placeholder:"http://localhost:8880/v1",className:Ln}),I&&s.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:"API Key"}),s.jsx("span",{className:ls,children:"Optional"}),s.jsxs("div",{className:Se("relative",Es),children:[s.jsx("input",{type:"password",value:L,onChange:Q=>K(Q.target.value),placeholder:"sk-...",className:Ln}),L&&s.jsx("button",{type:"button",onClick:()=>K(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Se("relative",Es),children:s.jsx("input",{type:"text",value:W,onChange:Q=>q(Q.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:Ln})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.voice")}),s.jsx(Gt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:Se("flex items-center gap-2",Es),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:H,onChange:Q=>G(Q.target.value),placeholder:"af_sky",className:Ln})}),s.jsx(V,{size:"xs",variant:"ghost",onClick:tt,title:t("settings.voice.page.actions.preview"),disabled:!I.trim(),children:Ye?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(fj,{...C}),(a==="local"||a==="say")&&s.jsx(xt,{checked:k,onChange:u,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Ct,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:di(m,f),onValueChange:Q=>{const nt=b.find(ot=>di(ot.modelId,ot.speakerId)===Q);nt&&(v(nt.modelId),j(nt.speakerId))},children:[s.jsx(Tt,{size:Qt,className:fn,children:s.jsx(Jt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:Q=>b.find(nt=>di(nt.modelId,nt.speakerId)===Q)?.label??Q})}),s.jsx(Et,{children:b.map(Q=>s.jsx(gt,{value:di(Q.modelId,Q.speakerId),children:Q.label},di(Q.modelId,Q.speakerId)))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:x,title:t("settings.voice.page.actions.preview"),children:S?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})}),A?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:A}):null]}),a==="openai"&&ae&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:T,onValueChange:D,children:[s.jsx(Tt,{size:Qt,className:fn,children:s.jsx(Jt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Et,{children:hj.map(Q=>s.jsx(gt,{value:Q.value,children:Q.label},Q.value))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:Ze,title:t("settings.voice.page.actions.preview"),children:Ke?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:ls,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&ve&&Me.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:p,onValueChange:h,children:[s.jsx(Tt,{size:Qt,className:fn,children:s.jsx(Jt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Et,{children:Me.map(Q=>s.jsx(gt,{value:Q.name,children:Q.name},Q.name))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:ze,title:t("settings.voice.page.actions.preview"),children:Te?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Ue.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Dt,{value:E||"$auto",onValueChange:Q=>M(Q==="$auto"?"":Q),children:[s.jsx(Tt,{size:Qt,className:fn,children:s.jsx(Jt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Et,{children:[s.jsx(gt,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ue.map(Q=>s.jsxs(gt,{value:Q.name,children:[Q.name," (",Q.lang,")"]},Q.name))]})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:et,title:t("settings.voice.page.actions.preview"),children:rt?s.jsx(B,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(B,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:Q=>o(Number(Q.target.value)),className:lt}),s.jsx(js,{value:i,onValueChange:o,min:.5,max:2,step:.1,className:Se(ws,"tabular-nums")})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:r,onChange:Q=>d(Number(Q.target.value)),className:lt}),s.jsx(js,{value:r,onValueChange:d,min:.5,max:2,step:.1,className:Se(ws,"tabular-nums")})]}),s.jsxs(Ct,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:Q=>g(Number(Q.target.value)),className:lt}),e?s.jsx(js,{value:Math.round(c*100),onValueChange:Q=>g(Q/100),min:0,max:100,step:10,className:Se(ws,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]}),s.jsx(Cs,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Xs,{value:$,onChange:Z,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs(He,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(xt,{checked:ue,onChange:Ie,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),ue&&s.jsxs(s.Fragment,{children:[s.jsx(Cs,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.sttLocal")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]}),children:s.jsx(Xs,{value:_,onChange:ne,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai-compatible",label:t("settings.voice.page.provider.server")}]})}),_==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.model")}),s.jsx(cj,{selectedModelId:be,onSelect:De})]}),_==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Se(Pt,!X.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Gt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:Se("relative",Es),children:[s.jsx("input",{type:"text",value:X,onChange:Q=>te(Q.target.value),placeholder:"http://localhost:8001/v1",className:Ln}),X&&s.jsx("button",{type:"button",onClick:()=>te(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:"API Key"}),s.jsx("span",{className:ls,children:"Optional"}),s.jsxs("div",{className:Se("relative",Es),children:[s.jsx("input",{type:"password",value:he,onChange:Q=>je(Q.target.value),placeholder:"sk-...",className:Ln}),he&&s.jsx("button",{type:"button",onClick:()=>je(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(B,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:Se("relative",Es),children:s.jsx("input",{type:"text",value:fe,onChange:Q=>ke(Q.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:Ln})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Pt,children:t("settings.voice.page.field.language")}),s.jsx(Gt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:oe,onChange:Q=>ee(Q.target.value),placeholder:"auto",className:Ln})})]})]})]})]})]})};function bj(t){return t.id===Er||t.installed||t.downloading}const Ji=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],Qi=[{value:"3600000",label:"1h",ms:3600*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"43200000",label:"12h",ms:720*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3},{value:"604800000",label:"1w",ms:10080*60*1e3},{value:"2592000000",label:"30d",ms:720*60*60*1e3}],vj="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",yj="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",lr=[{value:"quick",labelKey:"settings.openchamber.tunnel.option.mode.quick.label",tooltipKey:"settings.openchamber.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.openchamber.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.openchamber.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedLocal.tooltip"}],jj=[".yml",".yaml",".json"],kj="settings.openchamber.tunnel.error.invalidConfigExtension",ui=t=>{const e=t.trim().toLowerCase();return jj.some(a=>e.endsWith(a))},wj=t=>t==="ngrok"?"ngrok":"cloudflared",mu=()=>{if(typeof window<"u"&&typeof window.__OPENCHAMBER_PLATFORM__=="string"){const e=window.__OPENCHAMBER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const t=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return t.includes("win")?"win32":t.includes("mac")?"darwin":"linux"},Sj=(t,e=mu())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/",cr=(t,e)=>{const a=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():t,n=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():wj(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():mu(),o=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Sj(a,i);return{provider:a,dependency:n,installCommand:o}},pu=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,Bc=t=>{const e=_e.c(11),{provider:a}=t;let n;e[0]!==a?(n=pu(a),e[0]=a,e[1]=n):n=e[1];const i=n,d=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==d?(c=Se("size-4 shrink-0",d),e[2]=d,e[3]=c):c=e[3];let g;e[4]!==c?(g=s.jsx(B,{name:"cloud",className:c}),e[4]=c,e[5]=g):g=e[5];let p;e[6]!==i?(p=s.jsx("span",{children:i}),e[6]=i,e[7]=p):p=e[7];let h;return e[8]!==g||e[9]!==p?(h=s.jsxs("span",{className:"flex items-center gap-2",children:[g,p]}),e[8]=g,e[9]=p,e[10]=h):h=e[10],h},ea=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Dr=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,Vc=(t,e,a)=>{const n=Dr(t,e,a);return t.find(i=>i.value===n)?.label||n},Hc=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),i=Math.floor(a%3600/60),o=a%60;return n>0?`${n}h ${i}m`:i>0?`${i}m ${o}s`:`${o}s`},Nj=(t,e)=>rd(t,e,{hour:"2-digit",precision:"second"}),to=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},Cj=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const i of t){if(!i||typeof i!="object")continue;const o=i,r=typeof o.id=="string"?o.id.trim():"",d=typeof o.name=="string"?o.name.trim():"",c=to(typeof o.hostname=="string"?o.hostname:"");!r||!d||!c||e.has(r)||a.has(c)||(e.add(r),a.add(c),n.push({id:r,name:d,hostname:c}))}return n},Ij=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Pj=()=>{const{t}=Be(),e=re(J=>J.timeFormatPreference),a=l.useCallback(J=>t(J),[t]),[n,i]=l.useState("checking"),[o,r]=l.useState(!1),[d,c]=l.useState(null),[g,p]=l.useState(null),[h,f]=l.useState(null),[m,v]=l.useState(null),[C,b]=l.useState(null),[k,u]=l.useState(!1),[j,N]=l.useState(!1),[w,S]=l.useState(!1),[A,x]=l.useState("cloudflare"),[E,M]=l.useState(()=>cr("cloudflare")),[T,D]=l.useState([]),[R,O]=l.useState("quick"),[I,y]=l.useState(null),[L,K]=l.useState([]),[H,G]=l.useState({}),[W,q]=l.useState(""),[z,$]=l.useState({}),[Z,_]=l.useState(new Set),[ne,X]=l.useState(!1),[te,he]=l.useState(""),[je,fe]=l.useState(""),[ke,be]=l.useState(""),[De,oe]=l.useState(1800*1e3),[ee,ce]=l.useState(480*60*1e3),[ue,Ie]=l.useState(""),[ve,Re]=l.useState([]),[Me,me]=l.useState(()=>Date.now()),[Te,Oe]=l.useState(null),pe=t(kj),xe=l.useRef(null),ae=l.useMemo(()=>I?!ui(I):!1,[I]),ie=l.useMemo(()=>L.find(J=>J.id===W)||L[0]||null,[L,W]),ge=l.useMemo(()=>ve.map(J=>{const ye=J.expiresAt<=Me,Ae=J.status==="active"&&!ye,Y=Ae?Hc(J.expiresAt-Me):J.inactiveReason==="expired"||ye?"expired":"inactive",Pe=Y==="expired"?t("settings.openchamber.tunnel.state.expired"):J.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),Je=ea(J.mode);return{...J,isActive:Ae,mode:Je,remainingTextForSession:Y,inactiveLabel:Pe}}),[Me,ve,t]),Ee=l.useMemo(()=>d?.connectUrl?d.bootstrapExpiresAt===null?!0:d.bootstrapExpiresAt>Me:!1,[Me,d?.bootstrapExpiresAt,d?.connectUrl]),Ke=l.useMemo(()=>!d||n!=="active"&&n!=="stopping"?!1:g===R,[g,n,d,R]),Le=l.useMemo(()=>!d||n!=="active"||!g?!1:g!==R,[g,n,d,R]),Ne=l.useMemo(()=>{if(typeof Te=="number"&&Number.isFinite(Te)&&Te>0)return Te;if(typeof window>"u")return null;const ye=ki()||window.location.href;let Ae=0;try{Ae=Number(new URL(ye).port)}catch{Ae=Number(window.location.port)}return Number.isFinite(Ae)&&Ae>0?Ae:null},[Te]),Ve=l.useMemo(()=>T.find(J=>J.provider===A)??null,[T,A]),Ye=l.useMemo(()=>{const J=new Set(Ve?.modes?.map(ye=>ye.key).filter(ye=>ye==="quick"||ye==="managed-remote"||ye==="managed-local"));return J.size===0?lr:lr.filter(ye=>J.has(ye.value))},[Ve]),pt=l.useMemo(()=>Ye.some(J=>J.value==="managed-remote"||J.value==="managed-local"),[Ye]),vt=l.useMemo(()=>E.provider===A?E:cr(A),[E,A]),wt=l.useCallback(async J=>{await _s(J)},[]),yt=l.useCallback((J,ye)=>(M(cr(ye,J)),J.available===!0),[]),st=l.useCallback(async(J,ye)=>{try{const Ae=await It("/api/openchamber/tunnel/check",{query:{provider:J},...ye?{signal:ye}:{}});if(!Ae.ok)return null;const Y=await Ae.json();if(ye?.aborted)return null;const Pe=yt(Y,J);return i(Je=>Je==="checking"||Je==="starting"||Je==="active"||Je==="stopping"?Je:Pe?"idle":"not-available"),Pe}catch{return null}},[yt]),rt=l.useCallback(async J=>{try{const[ye,Ae,Y,Pe]=await Promise.all([It("/api/openchamber/tunnel/check",{signal:J}),It("/api/openchamber/tunnel/status",{signal:J}),En(),It("/api/openchamber/tunnel/providers",{signal:J})]),Je=await ye.json(),se=await Ae.json(),We=Y??{},ut=Pe.ok?await Pe.json():{},Ce=se.ttlConfig?.bootstrapTtlMs??(We.tunnelBootstrapTtlMs===void 0?1800*1e3:We.tunnelBootstrapTtlMs),qe=typeof se.ttlConfig?.sessionTtlMs=="number"?se.ttlConfig.sessionTtlMs:We.tunnelSessionTtlMs??480*60*1e3,jt=ea(se.mode??We.tunnelMode),Ot=We.tunnelProvider??"cloudflare",Yt=We.managedLocalTunnelConfigPath??null,Zt=yt(Je,Ot),Ft=Cj(se?.managedRemoteTunnelPresets),ps=typeof se.managedRemoteTunnelHostname=="string"?se.managedRemoteTunnelHostname:"",gs=Ft.length>0?Ft:ps?[{id:`legacy-${to(ps)}`,name:ps,hostname:to(ps)}]:[],tn=gs[0]?.id||"";if(r(se.enterpriseMode===!0),oe(Ce),ce(qe),x(Ot),D(Array.isArray(ut?.providers)?ut.providers:[]),O(jt),y(Yt),K(gs),q(tn),Re(Array.isArray(se.activeSessions)?se.activeSessions:[]),p(se.activeTunnelMode?ea(se.activeTunnelMode):se.active&&se.mode?ea(se.mode):null),_(new Set(Array.isArray(se.managedRemoteTunnelTokenPresetIds)?se.managedRemoteTunnelTokenPresetIds:[])),Oe(typeof se.localPort=="number"?se.localPort:null),se.active&&se.url){c({url:se.url,connectUrl:null,bootstrapExpiresAt:typeof se.bootstrapExpiresAt=="number"?se.bootstrapExpiresAt:null}),i("active");return}i(Zt?"idle":"not-available")}catch{J.aborted||(i("error"),v(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[yt,t]);l.useEffect(()=>{const J=new AbortController;return rt(J.signal),()=>J.abort()},[rt]),l.useEffect(()=>{if(!d?.connectUrl){f(null);return}let J=!1;return Sd.toDataURL(d.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(ye=>{J||f(ye)}).catch(()=>{J||f(null)}),()=>{J=!0}},[d?.connectUrl]),l.useEffect(()=>{if(!d?.bootstrapExpiresAt){Ie(t("settings.openchamber.tunnel.state.noExpiry"));return}let J=null,ye=Date.now();const Ae=()=>{const Je=d.bootstrapExpiresAt?d.bootstrapExpiresAt-Date.now():0;Je<=0?Ie(t("settings.openchamber.tunnel.state.expired")):Ie(Hc(Je))},Y=()=>{const Je=Date.now();Je-ye>=1e3&&(Ae(),ye=Je),J=requestAnimationFrame(Y)};Ae(),(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Y));const Pe=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Y):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",Pe),()=>{document.removeEventListener("visibilitychange",Pe),J!==null&&cancelAnimationFrame(J)}},[t,d?.bootstrapExpiresAt]),l.useEffect(()=>{let J=null,ye=Date.now();const Ae=()=>{const Pe=Date.now();Pe-ye>=1e3&&(me(Pe),ye=Pe),J=requestAnimationFrame(Ae)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Ae));const Y=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Ae):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",Y),()=>{document.removeEventListener("visibilitychange",Y),J!==null&&cancelAnimationFrame(J)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let J=!1;const ye=async()=>{try{const Y=await It("/api/openchamber/tunnel/status");if(!Y.ok||J)return;const Pe=await Y.json();if(J)return;Re(Array.isArray(Pe.activeSessions)?Pe.activeSessions:[]),_(new Set(Array.isArray(Pe.managedRemoteTunnelTokenPresetIds)?Pe.managedRemoteTunnelTokenPresetIds:[])),Oe(typeof Pe.localPort=="number"?Pe.localPort:null)}catch{}},Ae=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ye()},5e3);return()=>{J=!0,window.clearInterval(Ae)}},[n]);const de=l.useCallback(async J=>{S(!0);try{await kt(J),Object.prototype.hasOwnProperty.call(J,"tunnelMode")&&J.tunnelMode&&O(J.tunnelMode),Object.prototype.hasOwnProperty.call(J,"tunnelProvider")&&typeof J.tunnelProvider=="string"&&x(J.tunnelProvider),Object.prototype.hasOwnProperty.call(J,"managedLocalTunnelConfigPath")&&y(J.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(J,"managedRemoteTunnelPresets")&&J.managedRemoteTunnelPresets&&K(J.managedRemoteTunnelPresets)}catch{U.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{S(!1)}},[t]),Ue=l.useCallback(async(J,ye)=>{N(!0);try{await kt({tunnelBootstrapTtlMs:J,tunnelSessionTtlMs:ye})}catch{U.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{N(!1)}},[t]),et=l.useCallback(async J=>{const ye=J.token.trim();if(ye)try{const Ae={...z,[J.presetId]:ye};await kt({managedRemoteTunnelPresetTokens:Ae}),_(Y=>{const Pe=new Set(Y);return Pe.add(J.presetId),Pe})}catch{U.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[z,t]),ze=l.useCallback(async J=>{b(null),v(null);const ye=T.find(Y=>Y.provider===J),Ae=ye?.modes?.some(Y=>Y.key===R)?R:ea(ye?.modes?.[0]?.key);await de({tunnelProvider:J,tunnelMode:Ae}),st(J)},[T,st,de,R]),Ze=l.useCallback(async()=>{const J=await Vr({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(J.success&&typeof J.path=="string"&&J.path.trim().length>0){const ye=J.path.trim();if(!ui(ye)){U.error(pe);return}y(ye),await de({managedLocalTunnelConfigPath:ye});return}xe.current?.click()},[pe,de]),tt=l.useCallback(J=>{const ye=J.trim();y(ye.length>0?ye:null)},[]),lt=l.useCallback(async()=>{if(I&&!ui(I)){U.error(pe);return}await de({managedLocalTunnelConfigPath:I})},[pe,I,de]),Q=l.useCallback(async()=>{y(null),await de({managedLocalTunnelConfigPath:null})},[de]),nt=l.useCallback(async J=>{const ye=J.target.files?.[0];if(!ye)return;const Ae=ye.name.trim();if(Ae.length!==0){if(!ui(Ae)){U.error(pe);return}y(Ae),await de({managedLocalTunnelConfigPath:Ae}),J.target.value=""}},[pe,de]),ot=l.useCallback(async()=>{if(v(null),b(null),R==="managed-local"&&I&&!ui(I)){v(pe),U.error(pe);return}i("starting");try{let J="",ye="";if(R==="managed-remote"){if(!ie){i("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),U.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}J=ie.hostname,ye=(z[ie.id]||"").trim(),await de({tunnelMode:"managed-remote",managedRemoteTunnelPresets:L})}const Ae=await It("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:A,mode:R,...R==="managed-remote"&&ie?{managedRemoteTunnelPresetId:ie.id,managedRemoteTunnelPresetName:ie.name}:{},...R==="managed-remote"&&J?{managedRemoteTunnelHostname:J}:{},...R==="managed-remote"&&ye?{managedRemoteTunnelToken:ye}:{},...R==="managed-local"&&I?{configPath:I}:{}})}),Y=await Ae.json();if(!Ae.ok||!Y.ok){if(R==="managed-remote"&&typeof Y.error=="string"&&Y.error.includes("Managed remote tunnel token is required")){i("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),U.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),v(Y.error||t("settings.openchamber.tunnel.toast.startFailed")),U.error(Y.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const Pe=typeof Y.url=="string"?Y.url:"";if(!Pe){i("error"),v(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),U.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(c({url:Pe,connectUrl:typeof Y.connectUrl=="string"?Y.connectUrl:null,bootstrapExpiresAt:typeof Y.bootstrapExpiresAt=="number"?Y.bootstrapExpiresAt:null}),p(Y.activeTunnelMode?ea(Y.activeTunnelMode):Y.mode?ea(Y.mode):R),Re(Array.isArray(Y.activeSessions)?Y.activeSessions:[]),Array.isArray(Y.managedRemoteTunnelTokenPresetIds)&&_(new Set(Y.managedRemoteTunnelTokenPresetIds)),typeof Y.localPort=="number"&&Oe(Y.localPort),typeof Y.mode=="string"&&O(ea(Y.mode)),i("active"),Y.replacedTunnel){const Je=typeof Y.revokedBootstrapCount=="number"?Y.revokedBootstrapCount:0,se=typeof Y.invalidatedSessionCount=="number"?Y.invalidatedSessionCount:0;Je===1&&se===1?U.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):Je===1?U.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:se})):se===1?U.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:Je})):U.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:Je,invalidatedSessionCount:se}))}else U.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),v(t("settings.openchamber.tunnel.toast.startFailed")),U.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[pe,L,de,ie,z,t,A,R,I]),it=l.useCallback(async()=>{i("stopping");try{await It("/api/openchamber/tunnel/stop",{method:"POST"});const J=await It("/api/openchamber/tunnel/status");if(J.ok){const ye=await J.json();Re(Array.isArray(ye.activeSessions)?ye.activeSessions:[]),_(new Set(Array.isArray(ye.managedRemoteTunnelTokenPresetIds)?ye.managedRemoteTunnelTokenPresetIds:[])),Oe(typeof ye.localPort=="number"?ye.localPort:null)}c(null),p(null),f(null),i("idle"),U.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),v(t("settings.openchamber.tunnel.toast.stopFailed")),U.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),ft=l.useCallback(async()=>{if(d?.connectUrl)try{await navigator.clipboard.writeText(d.connectUrl),u(!0),U.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>u(!1),2e3)}catch{U.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,d?.connectUrl]),bt=l.useCallback(async J=>{const ye=Ji.find(Ae=>Ae.value===J);ye&&(oe(ye.ms),await Ue(ye.ms,ee))},[Ue,ee]),ht=l.useCallback(async J=>{const ye=Qi.find(Ae=>Ae.value===J);!ye||ye.ms===null||(ce(ye.ms),await Ue(De,ye.ms))},[De,Ue]),Nt=l.useCallback(async J=>{b(null),v(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await de({tunnelMode:J,managedRemoteTunnelPresets:L})},[L,de,n]),At=l.useCallback(async(J,ye)=>{try{await kt({managedRemoteTunnelPresets:ye})}catch{U.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),$e=l.useCallback(J=>{const ye=L.find(Ae=>Ae.id===J);ye&&(q(ye.id),b(null),At(ye,L))},[L,At]),Xe=l.useCallback(async()=>{const J=te.trim(),ye=to(je),Ae=ke.trim();if(!J){U.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!ye){U.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Ae){U.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(L.some(Je=>Je.hostname===ye)){U.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Y={id:Ij(),name:J,hostname:ye},Pe=[...L,Y];K(Pe),q(Y.id),G(Je=>({...Je,[Y.id]:!0})),$(Je=>({...Je,[Y.id]:Ae})),b(null),X(!1),he(""),fe(""),be(""),await de({tunnelMode:"managed-remote",managedRemoteTunnelPresets:Pe,managedRemoteTunnelPresetTokens:{...z,[Y.id]:Ae}}),await et({presetId:Y.id,presetName:Y.name,hostname:Y.hostname,token:Ae}),U.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[L,je,te,ke,et,de,z,t]),mt=l.useCallback(async J=>{const ye=L.find(se=>se.id===J);if(!ye)return;const Ae=L.filter(se=>se.id!==ye.id),Y=Ae[0]?.id||"",Pe=W===ye.id?Y:W,Je=Object.fromEntries(Object.entries(z).filter(([se,We])=>se!==ye.id&&We.trim().length>0));K(Ae),q(Pe),G(se=>{const We={...se};return delete We[ye.id],We}),$(se=>{const We={...se};return delete We[ye.id],We}),_(se=>{const We=new Set(se);return We.delete(ye.id),We}),b(null),await de({managedRemoteTunnelPresets:Ae,managedRemoteTunnelPresetTokens:Je}),U.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[L,de,W,z,t]),Fe="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.openchamber.tunnel.state.loading")})}):o?s.jsx(He,{title:t("settings.openchamber.tunnel.title"),divider:!1,children:s.jsx("p",{className:Pn,children:t("settings.openchamber.tunnel.enterpriseMode")})}):s.jsx(He,{title:t("settings.openchamber.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.openchamber.tunnel.description")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[ge.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(B,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:fr,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ge.map(J=>{const ye=J.mode==="quick",Ae=J.mode==="managed-remote",Y=ye?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Ae?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",Pe=J.isActive?ye?"text-[var(--status-warning)]":Ae?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",Je=t(ye?"settings.openchamber.tunnel.badge.quick":Ae?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(B,{name:"checkbox-blank-circle-fill",className:Se("size-2.5 shrink-0",Pe)}),s.jsx("span",{className:Se("typography-micro rounded border px-1.5 py-0.5 uppercase",Y),children:Je}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:Nj(J.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:J.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:J.remainingTextForSession}):J.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:J.inactiveLabel})})]},J.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(B,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:fr,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:vt.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:vt.installCommand})]})]})}),s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[s.jsx("p",{className:Pt,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Dt,{value:A,onValueChange:J=>{ze(J)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(Tt,{size:Qt,className:"max-w-[16rem]",children:s.jsx(Jt,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:pu(A)})}),s.jsxs(Et,{children:[T.length>0?T.map(J=>s.jsx(gt,{value:J.provider,children:s.jsx(Bc,{provider:J.provider})},J.provider)):s.jsx(gt,{value:"cloudflare",children:s.jsx(Bc,{provider:"cloudflare"})}),s.jsx(gt,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Pt,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Ye.map(J=>s.jsxs(hd,{children:[s.jsx(xd,{asChild:!0,children:s.jsx(V,{variant:"chip",size:"xs","aria-pressed":R===J.value,className:"!font-normal",onClick:()=>{Nt(J.value)},disabled:w||n==="starting"||n==="stopping",children:a(J.labelKey)})}),s.jsx(Am,{sideOffset:8,className:"max-w-xs",children:a(J.tooltipKey)})]},J.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Se(Pt,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Dt,{value:Dr(Ji,De,"1800000"),onValueChange:J=>{bt(J)},disabled:j||w||n==="starting"||n==="stopping",children:[s.jsx(Tt,{size:Qt,className:"max-w-[11rem] min-w-0",children:s.jsx(Jt,{className:"truncate",children:Vc(Ji,De,"1800000")})}),s.jsx(Et,{children:Ji.map(J=>s.jsx(gt,{value:J.value,children:J.label},J.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:Se(Pt,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Dt,{value:Dr(Qi,ee,"28800000"),onValueChange:J=>{ht(J)},disabled:j||w||n==="starting"||n==="stopping",children:[s.jsx(Tt,{size:Qt,className:"max-w-[11rem] min-w-0",children:s.jsx(Jt,{className:"truncate",children:Vc(Qi,ee,"28800000")})}),s.jsx(Et,{children:Qi.map(J=>s.jsx(gt,{value:J.value,children:J.label},J.value))})]})]})]}),R==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(B,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),pt&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),R==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Ne=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Ne]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(An,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>X(J=>!J),disabled:n==="starting"||n==="stopping"||w,children:[s.jsx(B,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),L.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:L.map((J,ye)=>{const Ae=z[J.id]||"",Y=Z.has(J.id),Pe=H[J.id]??!1;return s.jsx("div",{className:Se(ye<L.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(bn,{open:Pe,onOpenChange:Je=>{G(se=>({...se,[J.id]:Je})),Je&&$e(J.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(vn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||w,children:[Pe?s.jsx(B,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(B,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:J.name})]}),s.jsx(V,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:J.name}),onClick:()=>{mt(J.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(B,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(yn,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:J.hostname})]}),s.jsx(Ge,{type:"password",value:Ae,onChange:Je=>{const se=Je.target.value;b(null),$(We=>({...We,[J.id]:se}))},onBlur:Je=>{const se=Je.currentTarget.value.trim();se&&et({presetId:J.id,presetName:J.name,hostname:J.hostname,token:se})},placeholder:t(Y?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Ae.trim().length===0,onClick:()=>{et({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Ae})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},J.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),ne&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Ge,{value:te,onChange:J=>he(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Ge,{value:je,onChange:J=>fe(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Ge,{type:"password",value:ke,onChange:J=>be(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Ne=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ne]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Xe()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{X(!1),he(""),fe(""),be("")},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Gt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!ie&&C&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:C})]}),R==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Pt,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:xe,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:J=>{nt(J)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ge,{value:I||"",onChange:J=>{tt(J.target.value)},onBlur:()=>{lt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(V,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Ze()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(B,{name:"folder",className:"size-3.5"})}),I&&s.jsx(V,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Q()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(B,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(I?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),ae&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:pe})]})}),!Ke&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(B,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[R==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{wt(vj)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(B,{name:"external-link",className:"size-3.5"})]})]}),R==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{wt(yj)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(B,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:a(lr.find(J=>J.value===R)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),R==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Pt,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Dt,{value:W||(L[0]?.id??""),onValueChange:J=>{$e(J)},disabled:w||n==="starting"||n==="stopping"||L.length<=1,children:[s.jsx(Tt,{size:Qt,children:s.jsx(Jt,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:ie?.name})}),s.jsx(Et,{fitContent:!0,children:L.map(J=>s.jsx(gt,{value:J.id,children:J.name},J.id))})]})]}),Le&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(B,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(V,{size:"sm",variant:"outline",onClick:ot,disabled:n==="starting"||w||R==="managed-remote"&&!ie||R==="managed-local"&&ae,className:Se(Fe,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ke&&d&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:d.url})]}),Ee&&d.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:d.connectUrl}),s.jsxs(V,{size:"sm",variant:"ghost",onClick:ft,className:"shrink-0 gap-1.5",children:[k?s.jsx(B,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(B,{name:"file-copy",className:"size-3.5"}),t(k?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",d.bootstrapExpiresAt?ue:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[h?s.jsx("img",{src:h,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(V,{size:"sm",variant:"outline",onClick:ot,disabled:n==="stopping"||w||R==="managed-local"&&ae,className:Fe,children:[s.jsx(B,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(V,{size:"sm",variant:"ghost",onClick:it,disabled:n==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(B,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&m&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m}),s.jsx(V,{size:"sm",variant:"ghost",onClick:ot,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},gu=()=>{const{t}=Be(),[e,a]=at.useState(""),[n,i]=at.useState(!0),[o,r]=at.useState(!1),d=re(m=>m.showOpenCodeUpdateNotifications),c=re(m=>m.setShowOpenCodeUpdateNotifications);at.useEffect(()=>{let m=!1;return(async()=>{try{const v=await En();if(m||!v)return;a(v.opencodeBinary??"")}catch{}finally{m||i(!1)}})(),()=>{m=!0}},[]);const g=at.useCallback(async()=>{if(!(typeof window>"u")&&us())try{const m=await Vr();m.success&&m.path&&m.path.trim().length>0&&a(m.path.trim())}catch{}},[]),p=at.useCallback(async()=>{r(!0);try{const m=e.trim(),v=m.length>=2&&(m.startsWith('"')&&m.endsWith('"')||m.startsWith("'")&&m.endsWith("'"))?m.slice(1,-1).trim():m;await kt({opencodeBinary:v}),await Zc({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}catch(m){if(m?.requiresManualRestart){U.warning(t("settings.openchamber.opencodeCli.restart.manualRequired"));return}U.error(t("settings.openchamber.opencodeCli.restart.failed"))}finally{r(!1)}},[t,e]),h=at.useCallback(async()=>{r(!0);try{await Sp(t)}finally{r(!1)}},[t]),f=at.useCallback(m=>{c(m),kt({showOpenCodeUpdateNotifications:m})},[c]);return s.jsx(He,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Ct,{settingsItem:"sessions.opencode-binary",label:t("settings.openchamber.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(Ge,{value:e,onChange:m=>a(m.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:n||o,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(V,{type:"button",variant:"outline",size:"xs",onClick:g,disabled:n||o||!us(),className:hs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(B,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(na,{className:ys,children:[s.jsx(xt,{settingsItem:"sessions.opencode-update-notifications",checked:d,onChange:f,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsxs("div",{className:"flex flex-wrap justify-start gap-2 py-1.5","data-settings-item":"sessions.opencode-restart",children:[s.jsx(V,{type:"button",size:"xs",onClick:p,disabled:n||o,className:"shrink-0 !font-normal",children:t(o?"settings.openchamber.opencodeCli.actions.restartingOpenCode":"settings.openchamber.opencodeCli.actions.saveAndReload")}),s.jsx(V,{type:"button",variant:"outline",size:"xs",onClick:h,disabled:n||o,className:"shrink-0 !font-normal",children:t("settings.openchamber.opencodeCli.actions.restart")})]})]})]})})},dr="builtin",Aj=t=>t.filter(e=>_r(e)&&pd(e.service,"browser")),Tj="pl-[3.75rem]",Yi=t=>{const e=_e.c(31),{icon:a,title:n,summary:i,info:o,ariaLabel:r,checked:d,onChange:c,settingsItem:g}=t,p=!d&&"opacity-50";let h;e[0]!==p?(h=Se("flex size-8 shrink-0 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-foreground transition-opacity",p),e[0]=p,e[1]=h):h=e[1];let f;e[2]!==a?(f=s.jsx(B,{name:a,className:"size-4"}),e[2]=a,e[3]=f):f=e[3];let m;e[4]!==h||e[5]!==f?(m=s.jsx("span",{className:h,children:f}),e[4]=h,e[5]=f,e[6]=m):m=e[6];const v=!d&&"opacity-60";let C;e[7]!==v?(C=Se("min-w-0 flex-1 transition-opacity",v),e[7]=v,e[8]=C):C=e[8];let b;e[9]!==n?(b=s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:n}),e[9]=n,e[10]=b):b=e[10];let k;e[11]!==o?(k=s.jsx(Gt,{children:o}),e[11]=o,e[12]=k):k=e[12];let u;e[13]!==b||e[14]!==k?(u=s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[b,k]}),e[13]=b,e[14]=k,e[15]=u):u=e[15];let j;e[16]!==i?(j=s.jsx("p",{className:"typography-meta text-muted-foreground",children:i}),e[16]=i,e[17]=j):j=e[17];let N;e[18]!==j||e[19]!==C||e[20]!==u?(N=s.jsxs("div",{className:C,children:[u,j]}),e[18]=j,e[19]=C,e[20]=u,e[21]=N):N=e[21];let w;e[22]!==r||e[23]!==d||e[24]!==c?(w=s.jsx(fa,{checked:d,onCheckedChange:c,"aria-label":r}),e[22]=r,e[23]=d,e[24]=c,e[25]=w):w=e[25];let S;return e[26]!==g||e[27]!==N||e[28]!==w||e[29]!==m?(S=s.jsxs("div",{"data-settings-item":g,className:"flex items-center gap-3 px-4 py-3",children:[m,N,w]}),e[26]=g,e[27]=N,e[28]=w,e[29]=m,e[30]=S):S=e[30],S},fu=()=>{const t=_e.c(130),{t:e}=Be(),a=re(Ej),n=re(Dj),i=re(Mj),o=re(Rj),r=re(Oj),d=re(Lj),c=Ks(Fj),g=re(Kj),p=re(zj),h=re(Uj),f=re(_j),m=re($j),v=re(Bj),C=re(Vj);let b;t[0]!==n?(b=Ve=>{n(Ve),kt({agentControlToolEnabled:Ve})},t[0]=n,t[1]=b):b=t[1];const k=b;let u;t[2]!==o?(u=Ve=>{o(Ve),kt({agentWebToolEnabled:Ve})},t[2]=o,t[3]=u):u=t[3];const j=u;let N;t[4]!==m?(N=Ve=>{m(Ve),kt({agentNotifyToolEnabled:Ve})},t[4]=m,t[5]=N):N=t[5];const w=N;let S;t[6]!==C?(S=Ve=>{C(Ve),kt({agentToolsCodeMode:Ve})},t[6]=C,t[7]=S):S=t[7];const A=S;let x;t[8]===Symbol.for("react.memo_cache_sentinel")?(x=[],t[8]=x):x=t[8],at.useEffect(Hj,x);let E;t[9]!==c?(E=Aj(c),t[9]=c,t[10]=E):E=t[10];const M=E;let T;t[11]!==r||t[12]!==M?(T=M.some(Ve=>Ve.id===r)?r:dr,t[11]=r,t[12]=M,t[13]=T):T=t[13];const D=T;let R;t[14]!==d?(R=Ve=>{d(Ve),kt({browserProvider:Ve})},t[14]=d,t[15]=R):R=t[15];const O=R;let I;t[16]!==h?(I=Ve=>{h(Ve),kt({agentMemoryToolEnabled:Ve}).finally(()=>{Ve&&Tm.getState().refresh()})},t[16]=h,t[17]=I):I=t[17];const y=I;let L;t[18]!==e?(L=e("settings.openchamber.tools.title"),t[18]=e,t[19]=L):L=t[19];let K;t[20]!==e?(K=e("settings.openchamber.tools.field.agentControlTool"),t[20]=e,t[21]=K):K=t[21];let H;t[22]!==e?(H=e("settings.openchamber.tools.field.agentControlToolSummary"),t[22]=e,t[23]=H):H=t[23];let G;t[24]!==e?(G=e("settings.openchamber.tools.field.agentControlToolInfo"),t[24]=e,t[25]=G):G=t[25];let W;t[26]!==e?(W=e("settings.openchamber.tools.field.agentControlToolAria"),t[26]=e,t[27]=W):W=t[27];let q;t[28]!==a||t[29]!==k||t[30]!==K||t[31]!==H||t[32]!==G||t[33]!==W?(q=s.jsx(Yi,{icon:"node-tree",settingsItem:"sessions.agent-control-tool",checked:a,onChange:k,title:K,summary:H,info:G,ariaLabel:W}),t[28]=a,t[29]=k,t[30]=K,t[31]=H,t[32]=G,t[33]=W,t[34]=q):q=t[34];let z;t[35]!==e?(z=e("settings.openchamber.tools.field.agentWebTool"),t[35]=e,t[36]=z):z=t[36];let $;t[37]!==e?($=e("settings.openchamber.tools.field.agentWebToolSummary"),t[37]=e,t[38]=$):$=t[38];let Z;t[39]!==e?(Z=e("settings.openchamber.tools.field.agentWebToolInfo"),t[39]=e,t[40]=Z):Z=t[40];let _;t[41]!==e?(_=e("settings.openchamber.tools.field.agentWebToolAria"),t[41]=e,t[42]=_):_=t[42];let ne;t[43]!==i||t[44]!==j||t[45]!==z||t[46]!==$||t[47]!==Z||t[48]!==_?(ne=s.jsx(Yi,{icon:"global",settingsItem:"sessions.agent-web-tool",checked:i,onChange:j,title:z,summary:$,info:Z,ariaLabel:_}),t[43]=i,t[44]=j,t[45]=z,t[46]=$,t[47]=Z,t[48]=_,t[49]=ne):ne=t[49];let X;t[50]===Symbol.for("react.memo_cache_sentinel")?(X=Se("flex min-w-0 items-center gap-2 pb-3 pr-4",Tj),t[50]=X):X=t[50];let te;t[51]!==e?(te=e("settings.openchamber.tools.browserProvider.label"),t[51]=e,t[52]=te):te=t[52];let he;t[53]!==te?(he=s.jsx("span",{className:"truncate typography-meta text-muted-foreground",children:te}),t[53]=te,t[54]=he):he=t[54];let je;t[55]!==e?(je=e("settings.openchamber.tools.browserProvider.info"),t[55]=e,t[56]=je):je=t[56];let fe;t[57]!==je?(fe=s.jsx(Gt,{children:je}),t[57]=je,t[58]=fe):fe=t[58];const ke=!i||M.length===0;let be;t[59]!==e?(be=e("settings.openchamber.tools.browserProvider.aria"),t[59]=e,t[60]=be):be=t[60];let De;t[61]!==M||t[62]!==e?(De=s.jsx(Jt,{children:Ve=>Ve===dr?e("settings.openchamber.tools.browserProvider.option.builtin"):M.find(Ye=>Ye.id===Ve)?.name??null}),t[61]=M,t[62]=e,t[63]=De):De=t[63];let oe;t[64]!==be||t[65]!==De?(oe=s.jsx(Tt,{size:Qt,className:"ml-auto w-auto min-w-0 max-w-[14rem]","aria-label":be,children:De}),t[64]=be,t[65]=De,t[66]=oe):oe=t[66];let ee;t[67]!==e?(ee=e("settings.openchamber.tools.browserProvider.option.builtin"),t[67]=e,t[68]=ee):ee=t[68];let ce;t[69]!==ee?(ce=s.jsx(gt,{value:dr,children:ee}),t[69]=ee,t[70]=ce):ce=t[70];let ue;t[71]!==M?(ue=M.map(qj),t[71]=M,t[72]=ue):ue=t[72];let Ie;t[73]!==ce||t[74]!==ue?(Ie=s.jsxs(Et,{children:[ce,ue]}),t[73]=ce,t[74]=ue,t[75]=Ie):Ie=t[75];let ve;t[76]!==O||t[77]!==D||t[78]!==ke||t[79]!==oe||t[80]!==Ie?(ve=s.jsxs(Dt,{value:D,onValueChange:O,disabled:ke,children:[oe,Ie]}),t[76]=O,t[77]=D,t[78]=ke,t[79]=oe,t[80]=Ie,t[81]=ve):ve=t[81];let Re;t[82]!==he||t[83]!==fe||t[84]!==ve?(Re=s.jsxs("div",{"data-settings-item":"sessions.browser-provider",className:X,children:[he,fe,ve]}),t[82]=he,t[83]=fe,t[84]=ve,t[85]=Re):Re=t[85];let Me;t[86]!==ne||t[87]!==Re?(Me=s.jsxs("div",{children:[ne,Re]}),t[86]=ne,t[87]=Re,t[88]=Me):Me=t[88];let me;t[89]!==e?(me=e("settings.openchamber.tools.field.agentNotifyTool"),t[89]=e,t[90]=me):me=t[90];let Te;t[91]!==e?(Te=e("settings.openchamber.tools.field.agentNotifyToolSummary"),t[91]=e,t[92]=Te):Te=t[92];let Oe;t[93]!==e?(Oe=e("settings.openchamber.tools.field.agentNotifyToolInfo"),t[93]=e,t[94]=Oe):Oe=t[94];let pe;t[95]!==e?(pe=e("settings.openchamber.tools.field.agentNotifyToolAria"),t[95]=e,t[96]=pe):pe=t[96];let xe;t[97]!==f||t[98]!==w||t[99]!==me||t[100]!==Te||t[101]!==Oe||t[102]!==pe?(xe=s.jsx(Yi,{icon:"notification-3",settingsItem:"sessions.agent-notify-tool",checked:f,onChange:w,title:me,summary:Te,info:Oe,ariaLabel:pe}),t[97]=f,t[98]=w,t[99]=me,t[100]=Te,t[101]=Oe,t[102]=pe,t[103]=xe):xe=t[103];let ae;t[104]!==p||t[105]!==g||t[106]!==y||t[107]!==e?(ae=p?s.jsx(Yi,{icon:"brain",settingsItem:"sessions.agent-memory-tool",checked:g,onChange:y,title:e("settings.openchamber.tools.field.agentMemoryTool"),summary:e("settings.openchamber.tools.field.agentMemoryToolSummary"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria")}):null,t[104]=p,t[105]=g,t[106]=y,t[107]=e,t[108]=ae):ae=t[108];let ie;t[109]!==q||t[110]!==Me||t[111]!==xe||t[112]!==ae?(ie=s.jsxs("div",{className:"max-w-[44rem] divide-y divide-[var(--interactive-border)] rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[q,Me,xe,ae]}),t[109]=q,t[110]=Me,t[111]=xe,t[112]=ae,t[113]=ie):ie=t[113];let ge;t[114]!==e?(ge=e("settings.openchamber.tools.field.agentToolsCodeMode"),t[114]=e,t[115]=ge):ge=t[115];let Ee;t[116]!==e?(Ee=e("settings.openchamber.tools.field.agentToolsCodeModeAria"),t[116]=e,t[117]=Ee):Ee=t[117];let Ke;t[118]!==e?(Ke=e("settings.openchamber.tools.field.agentToolsCodeModeInfo"),t[118]=e,t[119]=Ke):Ke=t[119];let Le;t[120]!==v||t[121]!==A||t[122]!==ge||t[123]!==Ee||t[124]!==Ke?(Le=s.jsx(xt,{className:"mt-4",settingsItem:"sessions.agent-tools-code-mode",checked:v,onChange:A,label:ge,ariaLabel:Ee,info:Ke}),t[120]=v,t[121]=A,t[122]=ge,t[123]=Ee,t[124]=Ke,t[125]=Le):Le=t[125];let Ne;return t[126]!==ie||t[127]!==Le||t[128]!==L?(Ne=s.jsxs(He,{title:L,children:[ie,Le]}),t[126]=ie,t[127]=Le,t[128]=L,t[129]=Ne):Ne=t[129],Ne};function Ej(t){return t.agentControlToolEnabled}function Dj(t){return t.setAgentControlToolEnabled}function Mj(t){return t.agentWebToolEnabled}function Rj(t){return t.setAgentWebToolEnabled}function Oj(t){return t.browserProvider}function Lj(t){return t.setBrowserProvider}function Fj(t){return t.guests}function Kj(t){return t.agentMemoryToolEnabled}function zj(t){return t.agentMemoryFeatureAvailable}function Uj(t){return t.setAgentMemoryToolEnabled}function _j(t){return t.agentNotifyToolEnabled}function $j(t){return t.setAgentNotifyToolEnabled}function Bj(t){return t.agentToolsCodeMode}function Vj(t){return t.setAgentToolsCodeMode}function Hj(){gn()}function qj(t){return s.jsx(gt,{value:t.id,children:t.name},t.id)}const hu=()=>{const{t}=Be(),e=us()&&wi(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=at.useState(!1),[o,r]=at.useState(!1),[d,c]=at.useState(!1),[g,p]=at.useState(""),[h,f]=at.useState(!1),[m,v]=at.useState(!1),[C,b]=at.useState(null),[k,u]=at.useState(!0),[j,N]=at.useState(!1),[w,S]=at.useState(!1),[A,x]=at.useState(!1),[E,M]=at.useState(!1),[T,D]=at.useState(!1),[R,O]=at.useState(!1),[I,y]=at.useState(!1),[L,K]=at.useState(!0),[H,G]=at.useState(!0),[W,q]=at.useState(!1),[z,$]=at.useState(!1),[Z,_]=at.useState(!1),[ne,X]=at.useState(null),[te,he]=at.useState(null);at.useEffect(()=>{if(!e){u(!1);return}let pe=!1;return(async()=>{try{const xe=await En();if(!xe)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));if(pe)return;const ae=xe.desktopLanAccessEnabled===!0;i(ae),r(ae),c(xe.hasDesktopUiPassword===!0),p(""),f(!1),v(xe.desktopLanAccessActive===!0),b(xe.desktopLanAccessBlockedReason??null);const ie=xe.desktopMacMenuBarEnabled!==!1;K(ie),G(ie),X(null)}catch(xe){pe||X(xe instanceof Error?xe.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{pe||u(!1)}})(),()=>{pe=!0}},[e,t]),at.useEffect(()=>{if(!e){S(!1);return}let pe=!1;return(async()=>{const xe=await dp();pe||(S(xe?.supported===!0),x(xe?.enabled===!0))})(),()=>{pe=!0}},[e]),at.useEffect(()=>{if(!e){D(!1);return}let pe=!1;return(async()=>{const xe=await up();pe||(D(xe?.supported===!0),O(xe?.enabled===!0))})(),()=>{pe=!0}},[e]),at.useEffect(()=>{if(!e){q(!1);return}let pe=!1;return(async()=>{const xe=await mp();pe||(q(xe?.supported===!0),$(xe?.enabled===!0))})(),()=>{pe=!0}},[e]),at.useEffect(()=>{if(!e||!o){he(null);return}let pe=!1;return(async()=>{const xe=await vd();pe||he(xe)})(),()=>{pe=!0}},[o,e]);const je=g.trim(),fe=je.length>0||h,ke=o!==n||fe||H!==L,be=at.useMemo(()=>{if(typeof window>"u")return null;const xe=ki()||window.location.href;let ae=0;try{ae=Number(new URL(xe).port)}catch{ae=Number(window.location.port)}return Number.isFinite(ae)&&ae>0?ae:null},[]),De=o&&m&&te&&be?`http://${te}:${be}`:null,oe=je.length>0||d&&!h,ee=o&&!oe,ce=n&&!m&&C==="missing-password",ue=hr(pe=>pe.networkAccessBlocked)||C==="enterprise-mode",Ie=k||j||!ke||ee,ve=at.useCallback(pe=>{p(pe),pe.trim()&&f(!1)},[]),Re=at.useCallback(()=>{p(""),f(!0),r(!1)},[]),Me=at.useCallback(async()=>{if(!w||E)return;const pe=!A;x(pe),M(!0),X(null);try{const xe=await pp(pe);if(!xe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));x(xe.enabled)}catch(xe){x(!pe),X(xe instanceof Error?xe.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{M(!1)}},[E,A,w,t]),me=at.useCallback(async()=>{if(!T||I)return;const pe=!R;O(pe),y(!0),X(null);try{const xe=await gp(pe);if(!xe)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!xe.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));O(xe.enabled)}catch(xe){O(!pe),X(xe instanceof Error?xe.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{y(!1)}},[I,R,T,t]),Te=at.useCallback(async()=>{if(!W||Z)return;const pe=!z;$(pe),_(!0),X(null);try{const xe=await fp(pe);if(!xe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));$(xe.enabled)}catch(xe){$(!pe),X(xe instanceof Error?xe.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{_(!1)}},[Z,z,W,t]),Oe=at.useCallback(async()=>{if(ke){N(!0),X(null);try{if(!(await kt({desktopLanAccessEnabled:o,...je?{desktopUiPassword:je}:h?{desktopUiPassword:""}:{},desktopMacMenuBarEnabled:H})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(o),je?c(!0):h&&c(!1),p(""),f(!1),K(H),!await hp())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(pe){X(pe instanceof Error?pe.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),N(!1)}}},[H,o,ke,je,h,t]);return e?s.jsx(He,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[w||a||T||W?s.jsxs("div",{className:ys,children:[w?s.jsx(xt,{settingsItem:"sessions.desktop-launch-at-login",checked:A,onChange:pe=>{pe!==A&&Me()},disabled:E,label:t("settings.openchamber.desktopNetwork.field.launchAtLogin"),info:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(xt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:H,onChange:G,disabled:k||j,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,T?s.jsx(xt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:R,onChange:pe=>{pe!==R&&me()},disabled:I,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,W?s.jsx(xt,{settingsItem:"sessions.desktop-keep-awake",checked:z,onChange:pe=>{pe!==z&&Te()},disabled:Z,label:t("settings.openchamber.desktopNetwork.field.keepAwake"),info:t("settings.openchamber.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(Kt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),info:t("settings.openchamber.desktopPassword.field.passwordDescription"),children:[s.jsx(Ge,{id:"desktop-ui-password",type:"password",className:"h-8 min-w-0 flex-1",value:g,onChange:pe=>ve(pe.target.value),placeholder:t(d&&!h?"settings.openchamber.desktopPassword.field.passwordSetPlaceholder":"settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:k||j,required:o&&!oe,"aria-invalid":ee}),d&&!h?s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:Re,disabled:k||j,className:"shrink-0 !font-normal",children:t("settings.openchamber.desktopPassword.actions.removePassword")}):null]}),s.jsx("div",{className:ys,children:s.jsx(xt,{settingsItem:"sessions.desktop-lan-access",checked:o&&!ue,onChange:r,disabled:k||j||ue,label:t("settings.openchamber.desktopNetwork.field.allowLanAccess"),info:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription"),description:ue?s.jsx("span",{className:"block",children:t("settings.openchamber.desktopNetwork.field.enterpriseBlocked")}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")}),ee||ce?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria")})}),ne?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:ne}):null,De&&!ue?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(ke&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:De})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(V,{type:"button",size:"xs",onClick:Oe,disabled:Ie,className:"shrink-0 !font-normal",children:t(j?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},xu=new Set(["shift","control","alt","meta"]),dl=3,Gj=3e3;function ul(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Wj(t){return t.action.customizable}function qc(t){if(ul(t)>dl)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?fo(e.join("+")):null}function Jj(t){if(xu.has(t.key.toLowerCase())||ul(t,!0)>dl)return null;const e=Mm(Rm(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),fo(a.join("+"))}function Qj(t){const e=t.key.toLowerCase();if(!xu.has(e)||ul(t,!0)>dl)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?fo(a.join("+")):null}function Gc(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Yj(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:qc(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Jj(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const i=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:i,livePreview:null,settled:i.length===2}}return{...t,livePreview:qc(e)}}const Zj=t=>{const e=_e.c(117),{action:a,overrides:n,onSave:i,onOpenChange:o}=t,{t:r}=Be();let d;e[0]!==r?(d=be=>r(be.settingsLabelKey),e[0]=r,e[1]=d):d=e[1];const c=d;let g;e[2]!==c?(g=be=>be.action.customizable?c(be.action):xa(be.action.defaultBinding),e[2]=c,e[3]=g):g=e[3];const p=g;let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={chords:[],livePreview:null,settled:!1},e[4]=h):h=e[4];const[f,m]=l.useState(h),v=l.useRef(null);let C,b;e[5]!==a?(C=()=>{a&&(m({chords:[],livePreview:null,settled:!1}),v.current?.focus())},b=[a],e[5]=a,e[6]=C,e[7]=b):(C=e[6],b=e[7]),l.useEffect(C,b);const k=f.chords.length===1&&!f.settled;let u,j;e[8]!==k?(u=()=>{if(!k)return;const be=window.setTimeout(()=>m(Gc),Gj);return()=>window.clearTimeout(be)},j=[k],e[8]=k,e[9]=u,e[10]=j):(u=e[9],j=e[10]),l.useEffect(u,j);let N;e[11]!==f.chords?(N=fo(f.chords.join(" ")),e[11]=f.chords,e[12]=N):N=e[12];const w=N;let S;e[13]!==a||e[14]!==w||e[15]!==n?(S=a&&w?Em(a.id,w,n):[],e[13]=a,e[14]=w,e[15]=n,e[16]=S):S=e[16];const A=S;let x;e[17]!==A?(x=A.find(Xj),e[17]=A,e[18]=x):x=e[18];const E=x;let M,T,D,R,O,I,y,L,K,H,G,W,q,z,$;if(e[19]!==a||e[20]!==c||e[21]!==w||e[22]!==p||e[23]!==A||e[24]!==o||e[25]!==i||e[26]!==E||e[27]!==f||e[28]!==r){const be=A.filter(Wj);O=be.find(ek);const De=be.find(tk),oe=A.find(sk);let ee;e[44]!==o?(ee=()=>o(!1),e[44]=o,e[45]=ee):ee=e[45],D=ee,R=()=>{f.settled||m(Gc),!(!a||!w||E||O)&&(i(a.id,w,De?.action.id),D())};let ce;e[46]!==a||e[47]!==f?(ce=(ge,Ee)=>{ge.preventDefault(),ge.stopPropagation();const Ke=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Ee==="keyup"&&Ke&&f.chords.length===0){const Ne=Qj(ge);if(Ne){m({chords:[Ne],livePreview:null,settled:!0});return}}const Le=Yj(f,{altKey:ge.altKey,code:ge.nativeEvent.code,ctrlKey:ge.ctrlKey,isComposing:ge.nativeEvent.isComposing,key:ge.key,metaKey:ge.metaKey,repeat:ge.repeat,shiftKey:ge.shiftKey},Ee);m(Ke&&Le.chords.length>1?f:Le)},e[46]=a,e[47]=f,e[48]=ce):ce=e[48];const ue=ce;T=_t,z=a!==null,$=nk,M=$t,I="max-w-md",y=v,L=!1;let Ie;e[49]!==a||e[50]!==c||e[51]!==r?(Ie=a?r("settings.openchamber.keyboardShortcuts.dialog.title",{action:c(a)}):"",e[49]=a,e[50]=c,e[51]=r,e[52]=Ie):Ie=e[52];let ve;e[53]!==Ie?(ve=s.jsx(Ht,{children:Ie}),e[53]=Ie,e[54]=ve):ve=e[54];let Re;e[55]!==r?(Re=r("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=r,e[56]=Re):Re=e[56];let Me;e[57]!==Re?(Me=s.jsx(qt,{children:Re}),e[57]=Re,e[58]=Me):Me=e[58],e[59]!==ve||e[60]!==Me?(K=s.jsxs(Vt,{children:[ve,Me]}),e[59]=ve,e[60]=Me,e[61]=K):K=e[61];let me,Te;e[62]!==ue?(me=ge=>ue(ge,"keydown"),Te=ge=>ue(ge,"keyup"),e[62]=ue,e[63]=me,e[64]=Te):(me=e[63],Te=e[64]);let Oe;e[65]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>m(ak),e[65]=Oe):Oe=e[65];let pe;e[66]!==f.chords?(pe=f.chords.map(ik),e[66]=f.chords,e[67]=pe):pe=e[67];let xe;e[68]!==f.livePreview?(xe=f.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:xa(f.livePreview)}):null,e[68]=f.livePreview,e[69]=xe):xe=e[69];let ae;e[70]!==f.chords.length||e[71]!==f.livePreview||e[72]!==r?(ae=f.chords.length===0&&!f.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:r("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=f.chords.length,e[71]=f.livePreview,e[72]=r,e[73]=ae):ae=e[73];let ie;e[74]!==pe||e[75]!==xe||e[76]!==ae?(ie=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[pe,xe,ae]}),e[74]=pe,e[75]=xe,e[76]=ae,e[77]=ie):ie=e[77],e[78]!==me||e[79]!==Te||e[80]!==ie?(H=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:v,onKeyDown:me,onKeyUp:Te,onBlur:Oe,children:ie}),e[78]=me,e[79]=Te,e[80]=ie,e[81]=H):H=e[81],G=f.settled&&E?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r("settings.openchamber.keyboardShortcuts.error.internalConflict")}):f.settled&&O?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:c(O.action)})}):null,W=f.settled&&De&&!E&&!O?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:r("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:c(De.action)})}):null,q=f.settled&&oe&&!E&&!O?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:r("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:p(oe)})}):null,e[19]=a,e[20]=c,e[21]=w,e[22]=p,e[23]=A,e[24]=o,e[25]=i,e[26]=E,e[27]=f,e[28]=r,e[29]=M,e[30]=T,e[31]=D,e[32]=R,e[33]=O,e[34]=I,e[35]=y,e[36]=L,e[37]=K,e[38]=H,e[39]=G,e[40]=W,e[41]=q,e[42]=z,e[43]=$}else M=e[29],T=e[30],D=e[31],R=e[32],O=e[33],I=e[34],y=e[35],L=e[36],K=e[37],H=e[38],G=e[39],W=e[40],q=e[41],z=e[42],$=e[43];let Z;e[82]!==w||e[83]!==f.settled||e[84]!==r?(Z=f.settled&&w&&Dm(w)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:r("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=w,e[83]=f.settled,e[84]=r,e[85]=Z):Z=e[85];let _;e[86]!==r?(_=r("settings.common.actions.cancel"),e[86]=r,e[87]=_):_=e[87];let ne;e[88]!==D||e[89]!==_?(ne=s.jsx(V,{type:"button",variant:"ghost",size:"sm",onClick:D,children:_}),e[88]=D,e[89]=_,e[90]=ne):ne=e[90];const X=!w||f.settled&&(!!E||!!O);let te;e[91]!==r?(te=r("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=r,e[92]=te):te=e[92];let he;e[93]!==R||e[94]!==X||e[95]!==te?(he=s.jsx(V,{type:"button",size:"sm",disabled:X,onClick:R,children:te}),e[93]=R,e[94]=X,e[95]=te,e[96]=he):he=e[96];let je;e[97]!==ne||e[98]!==he?(je=s.jsxs(as,{children:[ne,he]}),e[97]=ne,e[98]=he,e[99]=je):je=e[99];let fe;e[100]!==M||e[101]!==I||e[102]!==y||e[103]!==L||e[104]!==K||e[105]!==H||e[106]!==G||e[107]!==W||e[108]!==q||e[109]!==Z||e[110]!==je?(fe=s.jsxs(M,{className:I,initialFocus:y,showCloseButton:L,children:[K,H,G,W,q,Z,je]}),e[100]=M,e[101]=I,e[102]=y,e[103]=L,e[104]=K,e[105]=H,e[106]=G,e[107]=W,e[108]=q,e[109]=Z,e[110]=je,e[111]=fe):fe=e[111];let ke;return e[112]!==T||e[113]!==z||e[114]!==$||e[115]!==fe?(ke=s.jsx(T,{open:z,onOpenChange:$,children:fe}),e[112]=T,e[113]=z,e[114]=$,e[115]=fe,e[116]=ke):ke=e[116],ke};function Xj(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function ek(t){return t.kind==="prefix"}function tk(t){return t.kind==="exact"}function sk(t){return t.kind==="contextual-prefix"}function nk(t,e){t||e.cancel()}function ak(t){return{...t,livePreview:null}}function ik(t,e){return s.jsx("kbd",{className:"rounded-md border border-border bg-muted px-3 py-2 typography-ui-label font-mono text-foreground",children:xa(t)},`${t}-${e}`)}const ok=["session","models","panels","navigation","application"],rk=()=>{const t=_e.c(24),{t:e}=Be(),a=re(lk),n=re(ck),i=re(dk),o=re(uk),[r,d]=l.useState(null);let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c=Om(),t[0]=c):c=t[0];const g=c,p=mk;let h;t[1]!==n||t[2]!==a?(h=(w,S,A)=>{const x={...a,[w]:S};A&&(x[A]=$o),n(w,S),A&&n(A,$o),p(x)},t[1]=n,t[2]=a,t[3]=h):h=t[3];const f=h;let m;t[4]!==i||t[5]!==a?(m=w=>{const S={...a};delete S[w],i(w),p(S)},t[4]=i,t[5]=a,t[6]=m):m=t[6];const v=m;let C;t[7]!==a||t[8]!==e?(C=w=>{const S="prefixStyle"in w&&w.prefixStyle,A=S?Lm(w.id,a):bd(w.id,a),x=xa(A,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!S||!A||A===$o)return x;const E=w.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${x}${E}`},t[7]=a,t[8]=e,t[9]=C):C=t[9];const b=C;let k;t[10]!==o||t[11]!==v||t[12]!==b||t[13]!==a||t[14]!==e?(k=ok.map((w,S)=>{const A=g.filter(x=>x.category===w);return A.length===0?null:s.jsx(He,{settingsItem:S===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${w}`),divider:S!==0,info:S===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:S===0?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{o(),p({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:A.map(x=>s.jsxs(Ct,{label:e(x.settingsLabelKey),children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:b(x)}),s.jsx(V,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>d(x),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),x.id in a?s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>v(x.id),children:e("settings.common.actions.reset")}):null]},x.id))})},w)}),t[10]=o,t[11]=v,t[12]=b,t[13]=a,t[14]=e,t[15]=k):k=t[15];let u;t[16]===Symbol.for("react.memo_cache_sentinel")?(u=w=>{w||d(null)},t[16]=u):u=t[16];let j;t[17]!==r||t[18]!==f||t[19]!==a?(j=s.jsx(Zj,{action:r,overrides:a,onSave:f,onOpenChange:u}),t[17]=r,t[18]=f,t[19]=a,t[20]=j):j=t[20];let N;return t[21]!==k||t[22]!==j?(N=s.jsxs(s.Fragment,{children:[k,j]}),t[21]=k,t[22]=j,t[23]=N):N=t[23],N};function lk(t){return t.shortcutOverrides}function ck(t){return t.setShortcutOverride}function dk(t){return t.clearShortcutOverride}function uk(t){return t.resetAllShortcutOverrides}function mk(t){kt({shortcutOverrides:t})}const bu=()=>{const t=_e.c(2),[e,a]=l.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>ho(()=>a(Sk)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),l.useEffect(n,i),e},pk=t=>{const e=_e.c(87),{section:a}=t,{t:n}=Be(),{isMobile:i}=qn(),o=bu();let r;e[0]!==i?(r=i&&ha(),e[0]=i,e[1]=r):r=e[1];const d=r;let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=ms(),e[2]=c):c=e[2];const g=c;let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=us()&&wi(),e[3]=p):p=e[3];const h=p;if(!a){let z;e[4]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(bo,{}),e[4]=z):z=e[4];let $;e[5]!==o?($=s.jsx(uu,{},o),e[5]=o,e[6]=$):$=e[6];let Z,_,ne,X,te,he,je;e[7]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(lu,{}),te=h&&s.jsx(hu,{}),he=!g&&s.jsx(gu,{}),je=!g&&s.jsx(fu,{}),Z=s.jsx(ru,{}),_=s.jsx(du,{}),ne=ha()&&!us()&&!g&&!Br()&&s.jsx(cu,{}),e[7]=Z,e[8]=_,e[9]=ne,e[10]=X,e[11]=te,e[12]=he,e[13]=je):(Z=e[7],_=e[8],ne=e[9],X=e[10],te=e[11],he=e[12],je=e[13]);let fe;e[14]!==d?(fe=d&&s.jsx(Nd,{}),e[14]=d,e[15]=fe):fe=e[15];let ke;return e[16]!==fe||e[17]!==$?(ke=s.jsxs(ns,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[z,$,X,te,he,je,Z,_,ne,fe]}),e[16]=fe,e[17]=$,e[18]=ke):ke=e[18],ke}let f;e[19]!==o||e[20]!==a?(f=()=>{switch(a){case"general":return s.jsx(fk,{});case"visual":return s.jsx(hk,{});case"chat":return s.jsx(xk,{});case"sessions":return s.jsx(bk,{runtimeEndpointEpoch:o});case"shortcuts":return s.jsx(gk,{});case"git":return s.jsx(vk,{});case"notifications":return s.jsx(yk,{});case"voice":return s.jsx(jk,{});case"tunnel":return s.jsx(wk,{});case"spaces":return s.jsx(kk,{});default:return null}},e[19]=o,e[20]=a,e[21]=f):f=e[21];const m=f;let v;e[22]!==n?(v=n("settings.page.general.title"),e[22]=n,e[23]=v):v=e[23];let C;e[24]!==n?(C=n("settings.page.appearance.title"),e[24]=n,e[25]=C):C=e[25];let b;e[26]!==n?(b=n("settings.page.chat.title"),e[26]=n,e[27]=b):b=e[27];let k;e[28]!==n?(k=n("settings.page.sessions.title"),e[28]=n,e[29]=k):k=e[29];let u;e[30]!==n?(u=n("settings.page.shortcuts.title"),e[30]=n,e[31]=u):u=e[31];let j;e[32]!==n?(j=n("settings.page.git.title"),e[32]=n,e[33]=j):j=e[33];let N;e[34]!==n?(N=n("settings.page.git.title"),e[34]=n,e[35]=N):N=e[35];let w;e[36]!==n?(w=n("settings.page.notifications.title"),e[36]=n,e[37]=w):w=e[37];let S;e[38]!==n?(S=n("settings.page.voice.title"),e[38]=n,e[39]=S):S=e[39];let A;e[40]!==n?(A=n("settings.page.tunnel.title"),e[40]=n,e[41]=A):A=e[41];let x;e[42]!==n?(x=n("settings.openchamber.spaces.title"),e[42]=n,e[43]=x):x=e[43];let E;e[44]!==j||e[45]!==N||e[46]!==w||e[47]!==S||e[48]!==A||e[49]!==x||e[50]!==v||e[51]!==C||e[52]!==b||e[53]!==k||e[54]!==u?(E={general:v,visual:C,chat:b,sessions:k,shortcuts:u,git:j,github:N,notifications:w,voice:S,tunnel:A,spaces:x},e[44]=j,e[45]=N,e[46]=w,e[47]=S,e[48]=A,e[49]=x,e[50]=v,e[51]=C,e[52]=b,e[53]=k,e[54]=u,e[55]=E):E=e[55];const M=E[a];let T;e[56]!==n?(T=n("settings.page.general.description"),e[56]=n,e[57]=T):T=e[57];let D;e[58]!==n?(D=n("settings.page.appearance.description"),e[58]=n,e[59]=D):D=e[59];let R;e[60]!==n?(R=n("settings.page.chat.description"),e[60]=n,e[61]=R):R=e[61];let O;e[62]!==n?(O=n("settings.page.sessions.description"),e[62]=n,e[63]=O):O=e[63];let I;e[64]!==n?(I=n("settings.page.shortcuts.description"),e[64]=n,e[65]=I):I=e[65];let y;e[66]!==n?(y=n("settings.page.notifications.description"),e[66]=n,e[67]=y):y=e[67];let L;e[68]!==n?(L=n("settings.page.voice.description"),e[68]=n,e[69]=L):L=e[69];let K;e[70]!==n?(K=n("settings.page.tunnel.description"),e[70]=n,e[71]=K):K=e[71];let H;e[72]!==T||e[73]!==D||e[74]!==R||e[75]!==O||e[76]!==I||e[77]!==y||e[78]!==L||e[79]!==K?(H={general:T,visual:D,chat:R,sessions:O,shortcuts:I,git:void 0,github:void 0,notifications:y,voice:L,tunnel:K,spaces:void 0},e[72]=T,e[73]=D,e[74]=R,e[75]=O,e[76]=I,e[77]=y,e[78]=L,e[79]=K,e[80]=H):H=e[80];const G=H[a];let W;e[81]!==m?(W=m(),e[81]=m,e[82]=W):W=e[82];let q;return e[83]!==G||e[84]!==M||e[85]!==W?(q=s.jsx(ns,{title:M,description:G,showSaveStatus:!0,className:"openchamber-page-body",children:W}),e[83]=G,e[84]=M,e[85]=W,e[86]=q):q=e[86],q},gk=()=>{const t=_e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(rk,{}),t[0]=e):e=t[0],e},fk=()=>{const t=_e.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ms(),t[0]=e):e=t[0];const a=e;bu();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=us()&&wi(),t[1]=n):n=t[1];const i=n;let o;t[2]===Symbol.for("react.memo_cache_sentinel")?(o=ha()&&!us()&&!a&&!Br(),t[2]=o):o=t[2];const r=o;let d,c,g,p,h;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=i&&s.jsx(hu,{}),c=r&&s.jsx(cu,{}),g=s.jsx(du,{}),p=!a&&s.jsx(gu,{}),h=!a&&s.jsx(fu,{}),t[3]=d,t[4]=c,t[5]=g,t[6]=p,t[7]=h):(d=t[3],c=t[4],g=t[5],p=t[6],h=t[7]);let f;t[8]===Symbol.for("react.memo_cache_sentinel")?(f=a?[]:["sessionTabs"],t[8]=f):f=t[8];let m;return t[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsxs(s.Fragment,{children:[d,c,g,p,h,s.jsx(bo,{visibleSettings:["fileEditorKeymap",...f,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=m):m=t[9],m},hk=()=>{const t=_e.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ms(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(bo,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","scrollbars","inputBarOffset","animatedActivityIndicators"]}),t[1]=n):n=t[1],n},xk=()=>{const t=_e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(bo,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader","promptNavigatorEnabled","wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","messageSearch","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[0]=e):e=t[0],e},bk=t=>{const e=_e.c(6),{runtimeEndpointEpoch:a}=t;let n;e[0]!==a?(n=s.jsx(uu,{},a),e[0]=a,e[1]=n):n=e[1];let i,o;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(lu,{}),o=s.jsx(ru,{}),e[2]=i,e[3]=o):(i=e[2],o=e[3]);let r;return e[4]!==n?(r=s.jsxs(s.Fragment,{children:[n,i,o]}),e[4]=n,e[5]=r):r=e[5],r},vk=()=>{const t=_e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Hd,{}),t[0]=e):e=t[0],e},yk=()=>{const t=_e.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(rj,{}),t[0]=e):e=t[0],e},jk=()=>{const t=_e.c(1);if(ms())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(xj,{}),t[0]=e):e=t[0],e},kk=()=>{if(_e.c(1),ms()||!xr)return null},wk=()=>{const t=_e.c(1);if(ms())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Pj,{}),t[0]=e):e=t[0],e};function Sk(t){return t+1}const Nk=[{id:"chat.activity-default",page:"chat",titleKey:"settings.openchamber.visual.section.activityDefault",keywords:["activity","collapsed","expanded","live","tools","history"]},{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.import-theme",page:"appearance",titleKey:"settings.themeImport.action",descriptionKey:"settings.themeImport.catalogHint",keywords:["theme","import","vscode","open vsx","openvsx","json","jsonc","syntax","palette"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.scrollbars",page:"appearance",titleKey:"settings.openchamber.visual.field.alwaysShowScrollbars",descriptionKey:"settings.openchamber.visual.field.alwaysShowScrollbarsHint",keywords:["scrollbar","scrollbars","scroll","mouse","wheel","accessibility","always visible"]},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.animated-activity-indicators",page:"appearance",titleKey:"settings.openchamber.visual.field.animatedActivityIndicators",descriptionKey:"settings.openchamber.visual.field.animatedActivityIndicatorsInfo",keywords:["spinner","animation","session","activity","motion","running","indicator"]},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.openchamber.visual.field.sessionTabsGroup",descriptionKey:"settings.openchamber.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.openchamber.appLinks.title",descriptionKey:"settings.openchamber.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-checker",page:"chat",titleKey:"settings.openchamber.visual.goal.checkerLabel",keywords:["goal","progress","check","jev","classification","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.openchamber.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.openchamber.visual.field.streamingAutoFollow",descriptionKey:"settings.openchamber.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"]},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.input-history-scope",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryScope",descriptionKey:"settings.openchamber.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryLimit",descriptionKey:"settings.openchamber.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{id:"chat.message-search",page:"chat",titleKey:"settings.openchamber.messageSearch.title",keywords:["search","find","index","messages","history","full text"],isAvailable:t=>!t.isVSCode},{id:"chat.message-search-enabled",page:"chat",titleKey:"settings.openchamber.messageSearch.field.enabled",keywords:["search","find","index","messages"],isAvailable:t=>!t.isVSCode},{id:"chat.message-search-reasoning",page:"chat",titleKey:"settings.openchamber.messageSearch.field.reasoning",keywords:["search","reasoning","thinking","index"],isAvailable:t=>!t.isVSCode},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.openchamber.visual.field.largeTextPaste",descriptionKey:"settings.openchamber.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.openchamber.visual.field.enterToSend",descriptionKey:"settings.openchamber.visual.field.enterToSendHint",keywords:["enter","shift enter","ctrl enter","cmd enter","mod enter","send","newline"],isAvailable:t=>!t.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.warming",page:"sessions",titleKey:"settings.openchamber.defaults.field.sessionWarming",descriptionKey:"settings.openchamber.defaults.field.sessionWarmingInfo",keywords:["warming","warm","cache","prompt cache","keep-alive","idle"]},{id:"sessions.permission-default",page:"sessions",titleKey:"settings.sessions.permissions.defaultMode",descriptionKey:"settings.sessions.permissions.defaultModeInfo",keywords:["permissions","auto-accept","accept","safety net","ask","shield","approval","new session"],isAvailable:t=>!t.isVSCode},{id:"sessions.work",page:"sessions",titleKey:"settings.openchamber.sessionWork.title",descriptionKey:"settings.openchamber.sessionWork.info",keywords:["in work","in progress","track","done","inbox","sidebar","jev"]},{id:"sessions.work-enabled",page:"sessions",titleKey:"settings.openchamber.sessionWork.field.enabled",keywords:["in work","in progress","track","done","sidebar"]},{id:"sessions.work-auto-open",page:"sessions",titleKey:"settings.openchamber.sessionWork.field.autoOpen",descriptionKey:"settings.openchamber.sessionWork.field.autoOpenInfo",keywords:["in work","automatic","jev","classification","track"],isAvailable:t=>!t.isVSCode},{id:"sessions.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.openchamber.defaults.walkthroughModel.title",descriptionKey:"settings.openchamber.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-only-archived",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.onlyArchived",descriptionKey:"settings.openchamber.sessionRetention.field.onlyArchivedDescription",keywords:["archive","archived","only","delete","cleanup","retention"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.openchamber.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.macMenuBar",descriptionKey:"settings.openchamber.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-restart",page:"general",titleKey:"settings.openchamber.opencodeCli.actions.restart",keywords:["opencode","restart","reload","plugin"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"sessions.browser-provider",page:"general",titleKey:"settings.openchamber.tools.browserProvider.label",descriptionKey:"settings.openchamber.tools.browserProvider.info",keywords:["agent","browser","provider","extension","chrome","server","headless"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-notify-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentNotifyTool",descriptionKey:"settings.openchamber.tools.field.agentNotifyToolInfo",keywords:["agent","tool","notify","notification","alert","ping","openchamber"],isAvailable:t=>!t.isVSCode},{id:"general.isolated-spaces",page:"isolated-spaces",titleKey:"settings.openchamber.spaces.field.enabled",descriptionKey:"settings.openchamber.spaces.field.enabledInfo",keywords:["isolated","space","spaces","container","docker","sandbox","agent"],isAvailable:t=>!t.isVSCode&&xr},{id:"general.isolated-spaces-idle-stop",page:"isolated-spaces",titleKey:"settings.openchamber.spaces.idleStop.enabled",descriptionKey:"settings.openchamber.spaces.idleStop.enabledInfo",keywords:["idle","stop","space","spaces","container","hours","timeout","sleep"],isAvailable:t=>!t.isVSCode&&xr&&re.getState().isolatedSpacesEnabled},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentMemoryTool",descriptionKey:"settings.openchamber.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","openchamber"],isAvailable:t=>!t.isVSCode&&re.getState().agentMemoryFeatureAvailable},{id:"sessions.agent-tools-code-mode",page:"general",titleKey:"settings.openchamber.tools.field.agentToolsCodeMode",descriptionKey:"settings.openchamber.tools.field.agentToolsCodeModeInfo",keywords:["agent","tool","code mode","codemode","execute","openchamber"],isAvailable:t=>!t.isVSCode},{id:"routing.enabled",page:"routing",titleKey:"settings.routing.auto.enable",descriptionKey:"settings.routing.auto.enableInfo",keywords:["auto","routing","model","jev","automatic"],isAvailable:t=>!t.isVSCode&&t.routingAvailable&&!t.jevBlockedByEnterprise},{id:"routing.fallback-model",page:"routing",titleKey:"settings.routing.auto.fallbackModel",descriptionKey:"settings.routing.auto.fallbackModelInfo",keywords:["fallback","default","model","routing"],isAvailable:t=>!t.isVSCode&&t.routingAvailable&&!t.jevBlockedByEnterprise},{id:"routing.add-category",page:"routing",titleKey:"settings.routing.categories.title",descriptionKey:"settings.routing.categories.description",keywords:["category","categories","task type","routing"],isAvailable:t=>!t.isVSCode&&t.routingAvailable&&!t.jevBlockedByEnterprise},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.openchamber.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.openchamber.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.openchamber.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.default-agent",page:"projects",titleKey:"settings.projects.page.field.projectAgent",keywords:["agent","default","new chat","project metadata"]},{id:"projects.default-model",page:"projects",titleKey:"settings.projects.page.field.projectModel",keywords:["model","default","new chat","project metadata"]},{id:"projects.default-thinking",page:"projects",titleKey:"settings.projects.page.field.projectThinking",keywords:["thinking","variant","reasoning","effort","model","project metadata"]},{id:"projects.accent-color",page:"projects",titleKey:"settings.projects.page.field.accentColor",keywords:["color","appearance","project metadata"]},{id:"projects.icon",page:"projects",titleKey:"settings.projects.page.field.projectIcon",keywords:["icon","favicon","upload","project metadata"]},{id:"projects.worktree",page:"projects",titleKey:"settings.projects.page.section.worktree",keywords:["worktree","branch","repository"]},{id:"projects.worktree.setup.wait",page:"projects",titleKey:"settings.openchamber.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"projects.worktree.setup.replace",page:"projects",titleKey:"settings.projects.shared.replaceMode",keywords:["worktree","setup commands","shared","team","only mine"]},{id:"projects.shared",page:"projects",titleKey:"settings.projects.shared.title",descriptionKey:"settings.projects.shared.description",keywords:["shared","team","repository",".openchamber","project.json","trust"]},{id:"projects.shared.plansDir",page:"projects",titleKey:"settings.projects.shared.plansDir",descriptionKey:"settings.projects.shared.plansDirInfo",keywords:["plans","folder","shared","team","docs"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access","relay","devices","connect from anywhere"],isAvailable:t=>!t.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher","additional headers","request headers","cloudflare access","service token"],isAvailable:t=>t.isDesktop},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.steps",page:"agents",titleKey:"settings.agents.page.field.steps",descriptionKey:"settings.agents.page.field.stepsTooltip",keywords:["steps","loop","tool calls"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","rules","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.variant",page:"commands",titleKey:"settings.agents.page.field.variant",keywords:["variant","reasoning","thinking"]},{id:"commands.subagent",page:"commands",titleKey:"settings.commands.page.field.subagent",descriptionKey:"settings.commands.page.field.subagentTooltip",keywords:["subagent","background","child session"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout","code mode","codemode"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.classification",page:"providers",titleKey:"settings.classification.page.title",descriptionKey:"settings.classification.page.description",keywords:["jev","typesafe","zen","api key","token","safety net","auto","routing","classification","promotion","off","disable","privacy","custom endpoint","base url","openai-compatible","system one","self-hosted","proxy"],isAvailable:t=>!t.isVSCode&&t.routingAvailable},{id:"providers.custom",page:"providers",titleKey:"settings.providers.page.custom.title",descriptionKey:"settings.providers.page.custom.description",keywords:["other","custom","openai-compatible","base url","api key"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.accounts.title",keywords:["api key","oauth","credentials","accounts","switch account","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"web-search.provider",page:"web-search",titleKey:"settings.webSearch.section.provider",descriptionKey:"settings.webSearch.section.providerInfo",keywords:["web search","websearch","internet","default provider","disable","off","random"]},{id:"web-search.keys",page:"web-search",titleKey:"settings.webSearch.section.keys",keywords:["api key","exa","tavily","firecrawl","parallel","tinyfish","credentials"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode&&!t.enterpriseMode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode&&!t.enterpriseMode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode&&!t.enterpriseMode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode&&!t.enterpriseMode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode&&!t.enterpriseMode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode&&!t.enterpriseMode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode},{id:"integrations.third-party",page:"integrations",titleKey:"settings.integrations.thirdParty.title",descriptionKey:"settings.integrations.thirdParty.info",keywords:["plugin","provider","install","update","remove","subscription"],isAvailable:t=>!t.isVSCode},{id:"integrations.third-party.opencode-claude",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",keywords:["claude","anthropic","claude code","pro","max","agent sdk","@openchamber/opencode-claude"],isAvailable:t=>!t.isVSCode},{id:"integrations.extensions",page:"integrations",titleKey:"settings.integrations.extensionCatalog.title",descriptionKey:"settings.integrations.extensionCatalog.info",keywords:["extension","install","update","remove","openchamber"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"integrations.extensions.excalidraw",page:"integrations",titleKey:"settings.integrations.extensionCatalog.excalidraw.name",descriptionKey:"settings.integrations.extensionCatalog.excalidraw.description",keywords:["excalidraw","drawing","diagram","canvas","whiteboard","obsidian","sketch"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"integrations.guests",page:"integrations",titleKey:"settings.integrations.guests.title",descriptionKey:"settings.integrations.guests.info",keywords:["guest","extension","oauth","clickup","gitlab","panel","connect"],isAvailable:t=>!t.isVSCode},{id:"extensions.add",page:"extensions",titleKey:"settings.extensions.add.label",descriptionKey:"settings.extensions.add.info",keywords:["folder","path","zip","git","url","install","guest","panel"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"extensions.gitIdentity",page:"extensions",titleKey:"settings.extensions.identity.title",descriptionKey:"settings.extensions.add.info",keywords:["ssh","key","identity","git","private","clone","extension"],isAvailable:t=>!t.isVSCode&&!t.isMobile},{id:"extensions.updates.check",page:"extensions",titleKey:"settings.extensions.updates.check",keywords:["update","upgrade","version","git","extension","guest","refresh"],isAvailable:t=>!t.isVSCode&&!t.isMobile}];function Wc(t){return t.trim().toLocaleLowerCase()}function Ck({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const o=Wc(t);if(!o)return[];const r=a?new Set(a):null,d=o.split(/\s+/).filter(Boolean);return Nk.flatMap(c=>{if(r&&!r.has(c.page))return[];const g=Ba(c.page);if(!g||g.isAvailable&&!g.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const p=n(c.titleKey),h=c.descriptionKey?n(c.descriptionKey):null,f=Wc([p,h,i(c.page),...c.keywords??[]].filter(Boolean).join(" "));return d.every(m=>f.includes(m))?[{...c,title:p,description:h,pageTitle:i(c.page)}]:[]})}const Jc=256,Qc=280,vu="__openchamberSettingsDetail",Ik=30,Pk=["general","appearance","chat","notifications","sessions","routing","shortcuts","voice","integrations","extensions","usage","about","projects","remote-instances","tunnel","git","isolated-spaces","providers","web-search","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],Ak=["general","projects","opencode","content"];function Tk(t,e,a,n,i){const o=ms(),r=!t&&ha();return{isVSCode:o,isWeb:r,isDesktop:t,isMobile:e,routingAvailable:a,enterpriseMode:n,jevBlockedByEnterprise:i}}function Yc(t,e){return t.isAvailable?t.isAvailable(e):!0}function Mr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function mi(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function ur(t){if(!Mr(t))return null;const e=t[vu];if(!Mr(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:br(a),stage:n}}function Ek(){return typeof window>"u"||!Mr(window.history.state)?{}:window.history.state}const Wk=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:i="nav",registerBackHandler:o})=>{const{t:r}=Be(),d=qn(),c=e??d.isMobile,g=re(ae=>ae.settingsPage),p=re(ae=>ae.isSettingsDialogOpen),h=re(ae=>ae.setSettingsPage),f=re(ae=>ae.shortcutOverrides.open_settings),m=br(g),[v,C]=l.useState(i),b=l.useRef(i==="nav"?m:null);l.useEffect(()=>{!c&&m==="home"&&h("general")},[c,h,m]);const[k,u]=l.useState(""),[j,N]=l.useState(null),[w,S]=l.useState(0),A=l.useRef(null),x=l.useRef(!1),E=l.useRef([]),M=l.useRef(0),T=l.useRef(!1),D=l.useMemo(()=>us(),[]),R=l.useMemo(()=>us()&&wi(),[]),O=l.useMemo(()=>us()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),I=l.useMemo(()=>us()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),y=l.useMemo(()=>us()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),L=re(ae=>ae.routingFeatureAvailable),K=ya(),H=Np(),G=l.useMemo(()=>Tk(D,c,L,K,H),[D,c,L,K,H]),W=l.useMemo(()=>{const ae=n?new Set(n):null;return Cp.filter(ie=>ie.slug!=="home").filter(ie=>!ae||ae.has(ie.slug)).filter(ie=>Yc(ie,G)).filter(ie=>!(G.isVSCode&&ie.slug==="projects")).filter(ie=>!(c&&ie.slug==="shortcuts"))},[G,c,n]),q=l.useMemo(()=>{const ae=new Map(Pk.map((ie,ge)=>[ie,ge]));return W.slice().sort((ie,ge)=>(ae.get(ie.slug)??999)-(ae.get(ge.slug)??999))},[W]),z=hn(ae=>ae.activeProjectId),$=en();l.useEffect(()=>{if(!(!p&&!G.isVSCode&&!a)){if(m==="agents"){Hn.getState().loadAgents($);return}if(m==="commands"){Ja.getState().loadCommands($);return}if(m==="mcp"){Un.getState().loadMcpConfigs({directory:$});return}if(m==="plugins"){zt.getState().loadPlugins();return}(m==="skills.installed"||m==="skills.catalog")&&(rn.getState().loadSkills($),zn.getState().loadCatalog()),m==="snippets"&&no.getState().loadSnippets()}},[z,p,a,G.isVSCode,$,m]);const Z=l.useCallback(ae=>{if(h(ae),b.current=ae,!c)return;const ie=Ba(ae);if(!ie||ie.slug==="home"){C("nav");return}C(ie.kind==="split"?"page-sidebar":"page-content")},[c,h]),_=l.useMemo(()=>Ba(m),[m]),ne=l.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel","isolated-spaces":"spaces"}),[]),X=l.useCallback(ae=>{switch(ae){case"general":return r("settings.page.general.title");case"projects":return r("settings.page.projects.title");case"remote-instances":return r("settings.page.remoteInstances.title");case"providers":return r("settings.page.providers.title");case"web-search":return r("settings.page.webSearch.title");case"usage":return r("settings.page.usage.title");case"agents":return r("settings.page.agents.title");case"behavior":return r("settings.page.behavior.title");case"commands":return r("settings.page.commands.title");case"mcp":return r("settings.page.mcp.title");case"plugins":return r("settings.page.plugins.title");case"skills.installed":return r("settings.page.skills.title");case"skills.catalog":return r("settings.page.skillsCatalog.title");case"git":return r("settings.page.git.title");case"integrations":return r("settings.page.integrations.title");case"extensions":return r("settings.page.extensions.title");case"appearance":return r("settings.page.appearance.title");case"chat":return r("settings.page.chat.title");case"shortcuts":return r("settings.page.shortcuts.title");case"sessions":return r("settings.page.sessions.title");case"routing":return r("settings.page.routing.title");case"magic-prompts":return r("settings.page.magicPrompts.title");case"snippets":return r("settings.page.snippets.title");case"notifications":return r("settings.page.notifications.title");case"voice":return r("settings.page.voice.title");case"tunnel":return r("settings.page.tunnel.title");case"isolated-spaces":return r("settings.openchamber.spaces.title");case"about":return r("settings.page.about.title");default:return r("settings.view.home.title")}},[r]),te=l.useMemo(()=>Ck({query:k,runtimeCtx:{...G,isDesktopLocalOrigin:R,isMac:O,isWindows:I,isLinux:y},visiblePageSlugs:n,t:r,getPageTitle:X}),[X,R,O,I,y,G,k,r,n]),he=l.useCallback(ae=>{if(ae.id.startsWith("agents.")){const ie=Hn.getState(),ge=mi("new-agent",ie.agents.map(Ee=>Ee.name));return ie.setAgentDraft({name:ge,scope:"user"}),ie.setSelectedAgent(ge),ae.id==="agents.create"?"agents.name":ae.id}if(ae.id.startsWith("commands.")){const ie=Ja.getState(),ge=mi("new-command",ie.commands.map(Ee=>Ee.name));return ie.setCommandDraft({name:ge,scope:"user"}),ie.setSelectedCommand(ge),ae.id==="commands.create"?"commands.name":ae.id}if(ae.id.startsWith("mcp.")){const ie=Un.getState(),ge=mi("new-mcp-server",ie.mcpServers.map(Ee=>Ee.name));return ie.setMcpDraft({name:ge,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}),ie.setSelectedMcp(ge),ae.id==="mcp.create"?"mcp.server":ae.id}if(ae.id.startsWith("snippets.")){const ie=no.getState(),ge=mi("new-snippet",ie.snippets.map(Ee=>Ee.name));return ie.setSnippetDraft({name:ge,scope:"global"}),ie.setSelectedSnippet(ge),ae.id==="snippets.create"?"snippets.content":ae.id}if(ae.id.startsWith("skills.")){const ie=rn.getState(),ge=mi("new-skill",ie.skills.map(Ee=>Ee.name));return ie.setSkillDraft({name:ge,scope:"user",source:"opencode",description:"",instructions:""}),ie.setSelectedSkill(ge),ae.id==="skills.create"?"skills.basic-information":ae.id}return ae.id==="providers.connect"&&re.getState().setSettingsProvidersConnectRequested(!0),ae.id==="providers.classification"&&re.getState().setSettingsProvidersClassificationRequested(!0),ae.id==="plugins.create"?"plugins.spec":ae.id},[]),je=l.useMemo(()=>{const ae=[],ie=new Map;for(const ge of te){let Ee=ie.get(ge.page);Ee||(Ee={page:ge.page,pageTitle:ge.pageTitle,results:[]},ie.set(ge.page,Ee),ae.push(Ee)),Ee.results.push(ge)}return ae},[te]);l.useEffect(()=>{S(0),M.current=0,T.current=!1},[k]),l.useEffect(()=>{M.current=w},[w]),l.useEffect(()=>{E.current[w]?.scrollIntoView({block:"nearest"})},[w]),l.useEffect(()=>{w>=te.length&&S(Math.max(0,te.length-1)),E.current.length=te.length},[w,te.length]);const fe=l.useCallback(ae=>{const ie=he(ae);N(ie),Z(ae.page),c&&C("page-content"),ae.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[c,Z,he]),ke=l.useCallback(ae=>{if(k.trim()){if(ae.key==="Escape"){ae.preventDefault(),u("");return}if(te.length!==0){if(ae.key==="ArrowDown"){ae.preventDefault(),T.current=!0,S(ie=>(ie+1)%te.length);return}if(ae.key==="ArrowUp"){ae.preventDefault(),T.current=!0,S(ie=>(ie-1+te.length)%te.length);return}if(ae.key==="Enter"){ae.preventDefault();const ie=(M.current%te.length+te.length)%te.length,ge=te[ie]??te[0];ge&&fe(ge)}}}},[fe,k,te]),be=re(ae=>ae.settingsJumpRequest);l.useEffect(()=>{be&&(re.getState().clearSettingsJumpRequest(),N(be.itemId),Z(br(be.page)),c&&C("page-content"))},[c,Z,be]),l.useEffect(()=>{const ae=j;if(!ae)return;let ie=!1,ge=0,Ee=0;const Ke=()=>{if(ie)return;const Le=typeof CSS<"u"&&CSS.escape?CSS.escape(ae):ae.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Ne=A.current?.querySelector(`[data-settings-item="${Le}"]`);if(!Ne){ge+=1,ge<Ik&&(Ee=window.requestAnimationFrame(Ke));return}N(null),Ne.scrollIntoView({block:"center",behavior:"smooth"}),Ne.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Ne.removeAttribute("data-settings-search-highlight")},1600)};return Ee=window.requestAnimationFrame(Ke),()=>{ie=!0,window.cancelAnimationFrame(Ee)}},[j,m]);const De=l.useCallback(()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:ad,children:r("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:r("settings.view.unavailable.description")})]})}),[r]),oe=l.useCallback((ae,ie)=>{switch(ae){case"projects":return s.jsx(Ax,{onItemSelect:ie.onItemSelect});case"agents":return s.jsx(fg,{onItemSelect:ie.onItemSelect});case"commands":return s.jsx(af,{onItemSelect:ie.onItemSelect});case"skills.installed":return s.jsx(Wh,{onItemSelect:ie.onItemSelect});case"usage":return s.jsx(uv,{onItemSelect:ie.onItemSelect});case"magic-prompts":return s.jsx(Pv,{onItemSelect:ie.onItemSelect});case"snippets":return s.jsx(Dv,{onItemSelect:ie.onItemSelect});default:return null}},[]),ee=l.useCallback(ae=>{const ie=Ba(ae);if(ie&&!Yc(ie,G))return De();switch(ae){case"projects":return s.jsx(Rx,{});case"remote-instances":return s.jsx(ab,{});case"agents":return s.jsx(Ug,{});case"behavior":return s.jsx(qg,{});case"commands":return s.jsx(mf,{});case"mcp":return s.jsx(Zf,{});case"plugins":return s.jsx(Th,{});case"skills.installed":return s.jsx(sc,{view:"installed"});case"skills.catalog":return s.jsx(sc,{view:"catalog"});case"providers":return s.jsx(cv,{});case"web-search":return s.jsx(Yg,{});case"usage":return s.jsx(Cv,{});case"about":return s.jsx(ns,{title:r("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Nd,{})});case"magic-prompts":return s.jsx(Ev,{});case"snippets":return s.jsx(Lv,{});case"git":return s.jsx(_v,{});case"integrations":return s.jsx(wy,{});case"routing":return s.jsx(Ey,{});case"extensions":return s.jsx(By,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":case"isolated-spaces":{const ge=ne[ae]??"visual";return s.jsx(pk,{section:ge})}default:return null}},[ne,De,G,r]);l.useEffect(()=>{if(!c||v!=="nav"||m==="home"||b.current===m)return;const ae=Ba(m);!ae||ae.slug==="home"||(b.current=m,C(ae.kind==="split"?"page-sidebar":"page-content"))},[c,v,m]);const ce=c&&v!=="nav",ue=c&&v==="page-content"&&_?.kind==="split",Ie=r(ue?"settings.view.actions.back":ce?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),ve=bd("open_settings",f===void 0?void 0:{open_settings:f}),Re=ve?r("settings.view.actions.closeSettingsWithShortcut",{shortcut:xa(ve)}):r("settings.view.actions.closeSettings"),Me=l.useCallback(ae=>{if(typeof window>"u"||G.isVSCode)return;const ie=ur(window.history.state);ie?.page===ae&&ie.stage==="page-content"||window.history.pushState({...Ek(),[vu]:{page:ae,stage:"page-content"}},"",window.location.href)},[G.isVSCode]),me=l.useCallback(()=>{x.current=!0,C("page-content"),Me(m)},[Me,m]);l.useEffect(()=>{if(!c||v!=="page-content"||!x.current)return;x.current=!1;const ae=window.requestAnimationFrame(()=>{A.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(ae)}},[c,v,m]);const Te=l.useCallback(()=>{if(ue){if((typeof window<"u"?ur(window.history.state):null)?.page===m&&!G.isVSCode){window.history.back();return}C("page-sidebar");return}C("nav")},[ue,G.isVSCode,m]);l.useEffect(()=>{if(o)return o(()=>!c||v==="nav"?!1:(Te(),!0)),()=>o(null)},[Te,c,v,o]),l.useEffect(()=>{if(!c||G.isVSCode)return;const ae=ie=>{if(Ba(m)?.kind!=="split")return;if(ur(ie.state)?.page===m){C("page-content");return}C(Ee=>Ee==="page-content"?"page-sidebar":Ee)};return window.addEventListener("popstate",ae),()=>{window.removeEventListener("popstate",ae)}},[c,G.isVSCode,m]);const Oe=()=>{const ae=k.trim().length>0;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"px-4 pt-3",children:s.jsxs("div",{className:"oc-surface-elevated flex h-10 items-center gap-1.5 rounded-md border border-border bg-surface-elevated/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-ring sm:h-8",children:[s.jsx(B,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:k,onChange:ie=>u(ie.target.value),onKeyDown:ke,placeholder:r("settings.view.search.placeholder"),"aria-label":r("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),ae&&s.jsx("button",{type:"button",onClick:()=>u(""),"aria-label":r("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:s.jsx(B,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx(Ds,{outerClassName:"flex-1 min-h-0",disableHorizontal:!0,children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:ae?te.length>0?(()=>{let ie=0;return je.map(ge=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:"px-2 pb-0.5 pt-2 typography-micro font-medium text-muted-foreground/70",children:ge.pageTitle}),ge.results.map(Ee=>{const Ke=ie;ie+=1;const Le=Ke===w,Ne=!!Ee.description;return s.jsxs("button",{type:"button",ref:Ve=>{E.current[Ke]=Ve},onMouseMove:()=>{T.current=!1,S(Ke)},onClick:()=>fe(Ee),className:Se("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",Ne?"min-h-11 py-1.5":"py-2",Le?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Ee.title}),Ne&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Ee.description})]},Ee.id)})]},ge.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:r("settings.view.search.noResults")}):(()=>{const ie=new Map;for(const Ee of q){const Ke=Ee.group,Le=ie.get(Ke);Le?Le.push(Ee):ie.set(Ke,[Ee])}return Ak.map(Ee=>({group:Ee,pages:ie.get(Ee)??[]})).filter(Ee=>Ee.pages.length>0).map(({group:Ee,pages:Ke},Le)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:Se("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Le===0?"pt-1":"pt-4 sm:pt-3"),children:r(`settings.view.nav.group.${Ee}`)}),Ke.map(Ne=>{const Ve=m===Ne.slug&&!(c&&v==="nav"),Ye=Ip(Ne.slug);return!Ye&&Ne.slug!=="mcp"?null:s.jsx(hd,{children:s.jsx(xd,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>Z(Ne.slug),"aria-current":Ve?"page":void 0,className:Se("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",Ve?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Ne.slug==="mcp"?s.jsx(Fm,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(B,{name:Ye,className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:X(Ne.slug)}),Ne.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:r("settings.view.badge.beta")})]})]})})},Ne.slug)})]},Ee))})()})})]})},pe=()=>{if(v==="nav")return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Xn,{children:Oe()})})});if(!_)return s.jsx("div",{className:"flex-1 bg-background"});if(v==="page-sidebar"){if(_.kind!=="split"){const ie=ee(m);return s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Xn,{children:ie})})}return s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Xn,{children:oe(m,{onItemSelect:me})})})}const ae=ee(m);return s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Xn,{children:ae})})},xe=()=>!_||m==="home"?null:_.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:Se("border-r",G.isVSCode?"bg-background":"bg-sidebar"),style:{width:Qc,minWidth:Qc,borderColor:"var(--interactive-border)"},children:s.jsx(Xn,{children:oe(m,{})})}),s.jsx(Ds,{outerClassName:"flex-1 min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Xn,{children:ee(m)})})]}):s.jsx(Ds,{outerClassName:"h-full min-h-0",className:"bg-background",disableHorizontal:!0,children:s.jsx(Xn,{children:ee(m)})});return s.jsxs("div",{ref:A,"data-settings-view":"true",className:Se("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[c?s.jsxs("div",{className:Se("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",v!=="nav"&&"border-b","bg-background"),style:v!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[ce?s.jsx("button",{type:"button",onClick:Te,"aria-label":Ie,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(B,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:v==="nav"?r("settings.view.home.title"):_?X(_.slug):r("settings.view.home.title")}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Re,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(B,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ce&&s.jsx("div",{className:Se("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Te,"aria-label":r("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(B,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:Se("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Re,className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:s.jsx(B,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?pe():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:Se("relative flex h-full min-h-0 flex-col overflow-hidden border-r",D?"bg-sidebar":G.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${Jc}px`,minWidth:`${Jc}px`,borderColor:"var(--interactive-border)"},children:s.jsx(Xn,{children:Oe()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:xe()})]})})]})};export{Nd as A,Wk as S};