@openchamber/web 2.0.0 → 2.0.1

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 (162) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-hJbl3JX4.js → CodeMirrorCommentWidgets-zm3C1FvM.js} +1 -1
  2. package/dist/assets/DiffView-DNExNi1z.js +4 -0
  3. package/dist/assets/FilesView-DUCLmHBi.js +17 -0
  4. package/dist/assets/{GitView-DY4pelsO.js → GitView-Bz9z6gZA.js} +4 -4
  5. package/dist/assets/{GuestAttachDialog-D6mHDTB2.js → GuestAttachDialog-UGp4KDlK.js} +1 -1
  6. package/dist/assets/GuestSurfacePane-B3pdB_2u.js +1 -0
  7. package/dist/assets/{JsonTreeView-DEXI2NvJ.js → JsonTreeView-7lVecnZl.js} +1 -1
  8. package/dist/assets/{LinearIssuesView-BTNc-4dN.js → LinearIssuesView-CTGRS9Vq.js} +1 -1
  9. package/dist/assets/{MarkdownImageGallery-wcUUcf8l.js → MarkdownImageGallery-DQk5adUs.js} +1 -1
  10. package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +12 -0
  11. package/dist/assets/{OnboardingScreen-FJUreEgI.js → OnboardingScreen-CBx6cXPP.js} +1 -1
  12. package/dist/assets/{PatchDiff-C0oOkKnO.js → PatchDiff-D7VVpR_l.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-asuSQAsf.js → PierreDiffViewer-Gbfks1pk.js} +3 -3
  14. package/dist/assets/{PlanView-DGbasNHP.js → PlanView-CPSK0x97.js} +4 -4
  15. package/dist/assets/PluginPane-BIGsUx69.js +3 -0
  16. package/dist/assets/SettingsView-Dql7z6Ww.js +30 -0
  17. package/dist/assets/{SettingsWindow-By4cqnqy.js → SettingsWindow-D6oi-UmV.js} +1 -1
  18. package/dist/assets/{SubmoduleDiffSummary-C0P2tXLU.js → SubmoduleDiffSummary-BXA0FAWj.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-Cayc-yIM.js → ToolOutputDialog-BQJsSbDm.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-B0jmpPQz.js → ToolPartDiffPreview-FY9w0TVT.js} +2 -2
  21. package/dist/assets/{VirtualizedFileDiff-DsOpvWZD.js → VirtualizedFileDiff-B9YhAya5.js} +1 -1
  22. package/dist/assets/{WalkthroughView-CCakjyn9.js → WalkthroughView-CmFgOUFN.js} +2 -2
  23. package/dist/assets/{appThemeRegistry-Bw5oTm41.js → appThemeRegistry-BebxalUt.js} +1 -1
  24. package/dist/assets/changesTree-CePHbFcj.js +1 -0
  25. package/dist/assets/commitAndPush-Wfxng_IK.js +1 -0
  26. package/dist/assets/{computeVirtualFileMetrics-B-4aLf4A.js → computeVirtualFileMetrics-BCOqgixN.js} +2 -2
  27. package/dist/assets/de-CMA45TC-.js +10 -0
  28. package/dist/assets/es-DPL4fBtl.js +16 -0
  29. package/dist/assets/fr-OHBKBseP.js +14 -0
  30. package/dist/assets/{index-B6r0Kv-B.js → index-3TiDNtfN.js} +1 -1
  31. package/dist/assets/index-BLUZa5u0.js +41 -0
  32. package/dist/assets/index-Cm2rrq69.css +1 -0
  33. package/dist/assets/{isDiffPlainText-Ok-kgtJA.js → isDiffPlainText-DnDYQmWK.js} +1 -1
  34. package/dist/assets/{isFilePlainText-0dLnkYm8.js → isFilePlainText-BA_AHX7d.js} +1 -1
  35. package/dist/assets/ja-DvX4WSRf.js +16 -0
  36. package/dist/assets/ko-BUcLd8YZ.js +16 -0
  37. package/dist/assets/main-B_jri4i-.js +896 -0
  38. package/dist/assets/{main-CjXBM_Xe.js → main-DtUmJp9B.js} +2 -2
  39. package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
  40. package/dist/assets/markdownCore-BSnlUXBf.js +7 -0
  41. package/dist/assets/{miniChat-DZ3OAeLN.js → miniChat-BYfLUnDK.js} +2 -2
  42. package/dist/assets/{mobile-CH0LOIF-.js → mobile-DH3hI6gd.js} +2 -2
  43. package/dist/assets/patchFileDiff--L7lt_GZ.js +13 -0
  44. package/dist/assets/pl-BkI_xHqz.js +16 -0
  45. package/dist/assets/pt-BR-7wFtQlV9.js +16 -0
  46. package/dist/assets/{renderElectronMiniChatApp-CB1uLYvh.js → renderElectronMiniChatApp-C7kpNW_-.js} +2 -2
  47. package/dist/assets/renderMobileApp-i0nq7Dwy.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +27 -0
  49. package/dist/assets/scheduledTasksApi-Cy7uZCaI.js +1 -0
  50. package/dist/assets/{shikiHighlight-CocY80VR.js → shikiHighlight-D4vxipfr.js} +1 -1
  51. package/dist/assets/{textMateThemeFromAppTheme-CF77r8FA.js → textMateThemeFromAppTheme-BYAHtJwQ.js} +1 -1
  52. package/dist/assets/tr-TsD-AqEH.js +7 -0
  53. package/dist/assets/uk-B-qspCmD.js +16 -0
  54. package/dist/assets/{useAppFontEffects-Dc5nTHi8.js → useAppFontEffects-DHZ9-L30.js} +158 -157
  55. package/dist/assets/{useInlineCommentController-Dbza5c8l.js → useInlineCommentController-CvpOMK-R.js} +2 -2
  56. package/dist/assets/{useRootScrollLock-CSCLv396.js → useRootScrollLock-DzNFi-fn.js} +2 -2
  57. package/dist/assets/{vendor-codemirror-language-data-CkmYWcRI.js → vendor-codemirror-language-data-j3fhlwUM.js} +2 -2
  58. package/dist/assets/{vendor-opencode-client-_BAHQo4R.js → vendor-opencode-client-DYdsLbCM.js} +2 -2
  59. package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
  60. package/dist/assets/{web-components-nsStrYq9.js → web-components-BvHNFSEG.js} +1 -1
  61. package/dist/assets/zh-CN-DYuPJV5i.js +16 -0
  62. package/dist/assets/zh-TW-BX_2D_lV.js +16 -0
  63. package/dist/index.html +5 -5
  64. package/dist/mini-chat.html +5 -5
  65. package/dist/mobile.html +5 -5
  66. package/package.json +4 -4
  67. package/server/index.js +18 -0
  68. package/server/lib/agent-tool/DOCUMENTATION.md +5 -0
  69. package/server/lib/agent-tool/runtime.js +34 -6
  70. package/server/lib/agent-tool/runtime.test.js +15 -0
  71. package/server/lib/browser-control/DOCUMENTATION.md +14 -2
  72. package/server/lib/git/DOCUMENTATION.md +1 -1
  73. package/server/lib/git/service.js +22 -0
  74. package/server/lib/git/service.test.js +8 -0
  75. package/server/lib/guests/DOCUMENTATION.md +4 -3
  76. package/server/lib/guests/catalog.js +19 -1
  77. package/server/lib/guests/catalog.test.js +22 -0
  78. package/server/lib/guests/html-styles.js +5 -3
  79. package/server/lib/guests/html-styles.test.js +3 -1
  80. package/server/lib/guests/routes.js +11 -3
  81. package/server/lib/guests/service.js +5 -0
  82. package/server/lib/guests/surface.js +55 -9
  83. package/server/lib/guests/surface.test.js +56 -6
  84. package/server/lib/notifications/DOCUMENTATION.md +10 -0
  85. package/server/lib/notifications/emit-route.js +118 -0
  86. package/server/lib/notifications/emit-route.test.js +112 -0
  87. package/server/lib/openchamber-control/actions.js +16 -2
  88. package/server/lib/openchamber-control/service.js +23 -0
  89. package/server/lib/openchamber-control/service.test.js +31 -0
  90. package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
  91. package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
  92. package/server/lib/openchamber-sessions/routes.js +11 -0
  93. package/server/lib/openchamber-sessions/routes.test.js +18 -0
  94. package/server/lib/opencode/DOCUMENTATION.md +31 -22
  95. package/server/lib/opencode/bootstrap-runtime.js +12 -0
  96. package/server/lib/opencode/compatibility.js +6 -3
  97. package/server/lib/opencode/compatibility.test.js +8 -0
  98. package/server/lib/opencode/config-v2.d.ts +2 -0
  99. package/server/lib/opencode/config-v2.js +42 -0
  100. package/server/lib/opencode/config-v2.test.js +17 -0
  101. package/server/lib/opencode/core-routes.js +3 -0
  102. package/server/lib/opencode/core-routes.test.js +15 -0
  103. package/server/lib/opencode/env-runtime.js +1 -8
  104. package/server/lib/opencode/feature-routes-runtime.js +2 -1
  105. package/server/lib/opencode/lifecycle.js +30 -2
  106. package/server/lib/opencode/lifecycle.test.js +27 -0
  107. package/server/lib/opencode/managed-config-file.js +18 -6
  108. package/server/lib/opencode/managed-config-file.test.js +23 -7
  109. package/server/lib/opencode/openchamber-routes.js +29 -11
  110. package/server/lib/opencode/openchamber-routes.test.js +18 -0
  111. package/server/lib/opencode/provider-source-route.test.js +59 -0
  112. package/server/lib/opencode/providers.js +3 -0
  113. package/server/lib/opencode/providers.test.js +62 -0
  114. package/server/lib/opencode/routes-upgrade.test.js +1 -1
  115. package/server/lib/opencode/routes.js +18 -1
  116. package/server/lib/opencode/settings-helpers.js +7 -0
  117. package/server/lib/opencode/settings-helpers.test.js +2 -2
  118. package/server/lib/opencode/settings-registry.json +14 -0
  119. package/server/lib/opencode/settings-runtime.js +1 -0
  120. package/server/lib/opencode/shared.js +32 -2
  121. package/server/lib/opencode/shared.test.js +79 -1
  122. package/server/lib/opencode/skill-routes.js +28 -12
  123. package/server/lib/opencode/skill-routes.test.js +121 -1
  124. package/server/lib/opencode/upgrade-capability.js +0 -14
  125. package/server/lib/opencode/v1-migration-topup.js +21 -15
  126. package/server/lib/opencode/v1-migration-topup.test.js +14 -6
  127. package/server/lib/opencode/v2-install.d.ts +1 -0
  128. package/server/lib/opencode/v2-install.js +8 -7
  129. package/server/lib/opencode/v2-install.test.js +13 -4
  130. package/server/lib/opencode/websearch-config.js +13 -1
  131. package/server/lib/quota/providers/kimi.js +1 -1
  132. package/server/lib/session-assist/DOCUMENTATION.md +17 -5
  133. package/server/lib/session-assist/runtime.js +19 -2
  134. package/server/lib/session-assist/runtime.test.js +8 -0
  135. package/server/lib/session-goal/DOCUMENTATION.md +11 -0
  136. package/dist/assets/DiffView-BucGEJYa.js +0 -4
  137. package/dist/assets/FilesView-CQcaaAVP.js +0 -17
  138. package/dist/assets/GuestSurfacePane--DJ7rsmY.js +0 -1
  139. package/dist/assets/MarkdownRendererImpl-BPe2TVV2.js +0 -12
  140. package/dist/assets/PluginPane-DImv8hV2.js +0 -3
  141. package/dist/assets/SettingsView-DOjuOljf.js +0 -29
  142. package/dist/assets/commitAndPush-sGEelpjh.js +0 -1
  143. package/dist/assets/de-CD9utsNj.js +0 -10
  144. package/dist/assets/es-NNum2rX8.js +0 -16
  145. package/dist/assets/fr-CJLGmduQ.js +0 -14
  146. package/dist/assets/index-DjGPR5vW.js +0 -41
  147. package/dist/assets/index-fCXJ-8Qt.css +0 -1
  148. package/dist/assets/ja-BuddHNi6.js +0 -16
  149. package/dist/assets/ko-BrwMbHmf.js +0 -16
  150. package/dist/assets/main-CxVyUDU_.js +0 -896
  151. package/dist/assets/markdownCore-B6PpX409.js +0 -5
  152. package/dist/assets/patchFileDiff-BFRGKaGH.js +0 -13
  153. package/dist/assets/pl-BwN4TNlP.js +0 -16
  154. package/dist/assets/pt-BR-BhMtownO.js +0 -16
  155. package/dist/assets/renderMobileApp-nQ4sjQtb.js +0 -25
  156. package/dist/assets/runtimeEndpointReset-9ZGlXU4J.js +0 -27
  157. package/dist/assets/scheduledTasksApi-6DsL_SwM.js +0 -1
  158. package/dist/assets/tr-DRzvqMdi.js +0 -7
  159. package/dist/assets/uk-b2aYOSNh.js +0 -16
  160. package/dist/assets/vendor-zod-Gea9uBlY.js +0 -39
  161. package/dist/assets/zh-CN-DZeUThm_.js +0 -16
  162. package/dist/assets/zh-TW-2fRE7uc6.js +0 -16
@@ -0,0 +1,25 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-DUCLmHBi.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-BLUZa5u0.js","assets/vendor-zod-BSoePkpP.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-opencode-client-DYdsLbCM.js","assets/index-Cm2rrq69.css","assets/useAppFontEffects-DHZ9-L30.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-CsXYnR5c.js","assets/vendor-floating-ui-utils-D6FqdtJt.js","assets/vendor-floating-ui-react-dom-DxYCWdHj.js","assets/vendor-floating-ui-dom-BTvzWks8.js","assets/vendor-floating-ui-core-PuGzNPnN.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-framer-motion-Bq3iTZ6r.js","assets/vendor-motion-dom-DcCgeG69.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-ClYN8CzB.js","assets/vendor-tanstack-virtual-core-BewVQryB.js","assets/contextPanelEmbeddedChat-CirXEPJq.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BgPj_McA.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-C9awkmn-.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-CiLROUVV.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-DzPz9Wgq.js","assets/vendor-codemirror-lang-json-CMBS2tG9.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-O0cZX78y.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CfgK872x.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-BPGOH9ye.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-j3fhlwUM.js","assets/vendor-codemirror-lang-python-HahnQaAS.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-B7H_j0iU.js","assets/vendor-legendapp-list-BuBPBC3R.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/runtimeEndpointReset-CfEYbcCc.js","assets/GuestAttachDialog-UGp4KDlK.js","assets/PluginPane-BIGsUx69.js","assets/shikiHighlight-D4vxipfr.js","assets/vendor-codemirror-search-BmS-GmcX.js","assets/vendor-replit-codemirror-vim-B2DJlAhT.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/JsonTreeView-7lVecnZl.js","assets/web-components-BvHNFSEG.js","assets/computeVirtualFileMetrics-BCOqgixN.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/Virtualizer-CZlLSacm.js","assets/isFilePlainText-BA_AHX7d.js","assets/appThemeRegistry-BebxalUt.js","assets/textMateThemeFromAppTheme-BYAHtJwQ.js","assets/Virtualizer-D_a8gKmg.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/scheduledTasksApi-Cy7uZCaI.js","assets/useInlineCommentController-CvpOMK-R.js","assets/CodeMirrorCommentWidgets-zm3C1FvM.js","assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-capacitor-push-notifications-KNe1zSBF.js"])))=>i.map(i=>d[i]);
2
+ import{f as le,r as bn,j as t,R as u,c as Lt,h as mo}from"./vendor-react-BUCujlKS.js";import"./vendor-katex-CHD9BdDO.js";import{u as it,a as Gt,b as ri,d as mr,i as Te,e as st,s as Dt,f as fs,h as Sn,j as po,k as ii,l as ho,p as go,m as bo,n as gt,o as xo,q as Rs,t as pr,G as hr,v as yo,x as gr,y as oi,z as br,A as xr,B as yr,M as Es,C as vo,D as wo}from"./index-BLUZa5u0.js";import{u as Nn,a as jo,b as We,c as ai,d as li,r as Cn,e as ko,f as me,t as fe,o as So,I as Z,B as ge,g as No,O as _t,h as Q,P as Co,i as Ro,j as Eo,k as Po,l as He,m as Ao,n as yt,p as Io,q as vr,s as To,v as Do,w as Rn,x as _o,y as Mo,z as Se,A as zo,C as En,D as Pn,E as An,F as Oo,S as Os,G as In,H as Bo,J as ci,K as Fe,L as ui,M as Lo,N as $o,Q as Fo,R as di,T as fi,U as mi,V as pi,W as hi,X as gi,Y as Wo,Z as Vo,_ as Tn,$ as Uo,a0 as Go,a1 as Ko,a2 as Ho,a3 as ss,a4 as Ps,a5 as qo,a6 as bi,a7 as Jo,a8 as Yo,a9 as Ks,aa as xi,ab as yi,ac as is,ad as Ot,ae as Qo,af as Xo,ag as Zo,ah as ea,ai as Dn,aj as ta,ak as sa,al as na,am as ra,an as ia,ao as oa,ap as aa,aq as la,ar as wr,as as ca,at as ua,au as da,av as fa,aw as ma,ax as As,ay as pa,az as ha,aA as vi,aB as Ve,aC as ga,aD as ba,aE as xa,aF as ya,aG as _n,aH as va,aI as wa,aJ as ja,aK as ka,aL as Sa,aM as Na,aN as Ca,aO as wi,aP as Ra,aQ as Ea,aR as Pa,aS as Aa,aT as Ia,aU as Ta,aV as Da,aW as _a,aX as Ma,aY as za,aZ as Oa,a_ as Ba,a$ as La,b0 as $a,b1 as Fa,b2 as Wa,b3 as Va,b4 as Ua,b5 as Ga,b6 as Ka,b7 as Ha,b8 as qa,b9 as Ja,ba as Ya,bb as Qa,bc as Xa,bd as Za,be as el,bf as tl,bg as sl}from"./useAppFontEffects-DHZ9-L30.js";import{u as Mt,S as Mn,h as nl,a as ji,s as rl,p as il,c as ol,r as al,b as ll,D as cl,N as ul,d as dl,e as fl,g as ml,f as pl,B as hl,i as gl,j as bl,k as xl,l as yl,m as vl,T as wl,P as jl,O as kl,n as Sl,o as Nl,q as Cl,t as Rl,A as El,v as Pl,C as Al,w as Il,x as Tl,U as Dl,y as _l}from"./runtimeEndpointReset-CfEYbcCc.js";import{_ as $t}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as Ml,A as zl}from"./SettingsView-Dql7z6Ww.js";import{PlanView as Ol}from"./PlanView-CPSK0x97.js";import{p as Bl}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as Ll}from"./vendor-capacitor-core-B4EWRrHz.js";import{k as xn,M as Bs,d as $l,J as yn,s as ki,a as zn,p as Fl,_ as jr,f as On,V as Wl,K as kr,P as Vl,b as Ul,c as Gl,U as Kl,Z as Hl,Q as ql,r as Jl}from"./vendor-remixicon-react-D6dZ0UwF.js";import{f as Bn,h as Ft,i as Ln,P as $n,D as Fn,j as Wn}from"./vendor-dnd-kit-core-BZknOX2w.js";import{s as Vn,S as Un,v as Gn,u as Kn}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as Hn}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{c as qn,p as Si}from"./vendor-zustand-BAGL70zf.js";import{toast as Yl}from"./vendor-sonner-DFyL3AvE.js";import{C as Ql,a as Xl,D as Zl,p as Sr}from"./commitAndPush-Wfxng_IK.js";import{u as ec,a as tc,b as sc,c as nc,i as rc,f as ic,B as oc,C as ac,P as Nr}from"./patchFileDiff--L7lt_GZ.js";import{u as lc,a as cc,i as uc,S as dc,b as fc}from"./SubmoduleDiffSummary-BXA0FAWj.js";import{P as mc}from"./PierreDiffViewer-Gbfks1pk.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-BSoePkpP.js";import"./vendor-opencode-client-DYdsLbCM.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-CsXYnR5c.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-ClYN8CzB.js";import"./vendor-tanstack-virtual-core-BewVQryB.js";import"./contextPanelEmbeddedChat-CirXEPJq.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-j3fhlwUM.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./GuestAttachDialog-UGp4KDlK.js";import"./PluginPane-BIGsUx69.js";import"./vendor-yaml-3778uTud.js";import"./shikiHighlight-D4vxipfr.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./appThemeRegistry-BebxalUt.js";import"./textMateThemeFromAppTheme-BYAHtJwQ.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-strip-json-comments-5dJlOkP1.js";import"./useInlineCommentController-CvpOMK-R.js";import"./CodeMirrorCommentWidgets-zm3C1FvM.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./changesTree-CePHbFcj.js";import"./VirtualizedFileDiff-B9YhAya5.js";import"./web-components-BvHNFSEG.js";import"./computeVirtualFileMetrics-BCOqgixN.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./isDiffPlainText-DnDYQmWK.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";let Ni=null,Cr=!1;const pc=new Promise(n=>{Ni=n});function hc(){Cr||(Cr=!0,Ni?.())}const gc=6,bc=n=>n.parentID??null,Rr=n=>{const e=n.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},xc=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),yc=(n,e)=>{if(!n)return"";let s=null,i=-1;for(const r of e){const o=xc(r.path);(n===o||n.startsWith(`${o}/`))&&o.length>i&&(s=r,i=o.length)}return s?s.label?.trim()||Rr(s.path):Rr(n)},vc=()=>{const n=Nn.getState().activeSessions,e=jo.getState().index.session.unseenCount,s=it.getState().notifyOnSubtasks,i=We.getState().projects,r=ai.getState().ids,o=li.getState().rankById;let a=0;const c=[];for(const d of n){const l=bc(d)!==null,g=(e[d.id]??0)>0&&(!l||s);g&&(a+=1),l||c.push({session:d,unread:g,project:yc(Cn(d),i)})}c.sort((d,l)=>ko(d.session,l.session,r,o));const f=c.slice(0,gc).map(({session:d,unread:l,project:p})=>({id:d.id,title:d.title??"",unread:l,project:p}));return{runtimeKey:Gt(),attentionCount:a,recentSessions:f}},wc="__OPENCHAMBER_WIDGET_SNAPSHOT__",jc=()=>{typeof window>"u"||(window[wc]=()=>{try{return JSON.stringify(vc())}catch{return null}})},cn="mobile-app-update-available",Er="mobile-app-update-toast-dismissed-version",kc=()=>{const n=le.c(8),{t:e}=me(),s=Mt(Sc),i=Mt(Nc),r=Mt(Cc),o=Mt(Rc);let a;n[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,n[0]=a):a=n[0];const c=bn.useRef(a);let f,d;return n[1]!==s||n[2]!==o||n[3]!==i||n[4]!==e||n[5]!==r?(f=()=>{if(ri()!=="android"||i!=="mobile"||!s||!r||!o){fe.dismiss(cn);return}mr().getItem(Er)!==r&&(c.current.has(r)||(c.current.add(r),fe.info(e("mobileUpdate.toast.available.title"),{id:cn,description:e("mobileUpdate.toast.available.description",{version:r}),duration:1/0,icon:t.jsx(Z,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{So(o)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{mr().setItem(Er,r),fe.dismiss(cn)}}})))},d=[s,o,i,e,r],n[1]=s,n[2]=o,n[3]=i,n[4]=e,n[5]=r,n[6]=f,n[7]=d):(f=n[6],d=n[7]),bn.useEffect(f,d),null};function Sc(n){return n.available}function Nc(n){return n.runtimeType}function Cc(n){return n.info?.version}function Rc(n){return n.info?.downloadUrl}const Pr=300,Ec="openchamber.mobile.connectLog.v1",zt=[];if(typeof window<"u")try{window.localStorage.removeItem(Ec)}catch{}const Jn=(n,e)=>{zt.push({at:Date.now(),step:n,detail:e}),zt.length>Pr&&zt.splice(0,zt.length-Pr)};typeof window<"u"&&Jn("app:launch","{}");const Pc=()=>[...zt],Ac=n=>{const e=new Date(n),s=(i,r=2)=>String(i).padStart(r,"0");return`${s(e.getHours())}:${s(e.getMinutes())}:${s(e.getSeconds())}.${s(e.getMilliseconds(),3)}`},Ci=n=>`${Ac(n.at)} ${n.step}${n.detail&&n.detail!=="{}"?` ${n.detail}`:""}`,Ic=()=>zt.map(Ci).join(`
3
+ `),Ri=(n,e)=>{const s=le.c(10),i=700,r=u.useRef(null),o=u.useRef(null),a=u.useRef(!1);let c;s[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{r.current!==null&&window.clearTimeout(r.current),r.current=null,o.current=null},s[0]=c):c=s[0];const f=c;let d,l;s[1]===Symbol.for("react.memo_cache_sentinel")?(d=()=>f,l=[f],s[1]=d,s[2]=l):(d=s[1],l=s[2]),u.useEffect(d,l);let p;s[3]!==i||s[4]!==n?(p=v=>{a.current=!1,o.current={x:v.clientX,y:v.clientY},r.current!==null&&window.clearTimeout(r.current),r.current=window.setTimeout(()=>{r.current=null,a.current=!0,n()},i)},s[3]=i,s[4]=n,s[5]=p):p=s[5];const g=p;let h;s[6]===Symbol.for("react.memo_cache_sentinel")?(h=v=>{const N=o.current;N&&(Math.abs(v.clientX-N.x)>10||Math.abs(v.clientY-N.y)>10)&&f()},s[6]=h):h=s[6];const b=h;let S;s[7]===Symbol.for("react.memo_cache_sentinel")?(S=v=>{a.current&&(a.current=!1,v.preventDefault(),v.stopPropagation())},s[7]=S):S=s[7];const x=S;let E;return s[8]!==g?(E={onPointerDown:g,onPointerMove:b,onPointerUp:f,onPointerCancel:f,onClickCapture:x},s[8]=g,s[9]=E):E=s[9],E},Ls="openchamber.mobile.connections.v1",Tc="openchamber.mobile.",Ar="openchamber.mobile.deviceId",Dc=()=>{try{const n=window.localStorage.getItem(Ar);if(n&&n.trim())return n.trim();const e=crypto.randomUUID();return window.localStorage.setItem(Ar,e),e}catch{return crypto.randomUUID()}},Ir=()=>`mobile:${Dc()}`,Tr=()=>{try{const n=Ll.getPlatform();return n==="ios"||n==="android"?n:void 0}catch{return}},Ei=12,Pi=8e3,_c=2500,Mc=3e3,$s=2500,zc=()=>{let n=0;return{begin:()=>(n+=1,n),cancel:()=>{n+=1},isCurrent:e=>e===n}},Kt=n=>{const e=n.trim();if(!e)return"";const s=/^https?:\/\//i.test(e)?e:`http://${e}`,i=new URL(s);return i.hash="",i.search="",i.pathname=i.pathname.replace(/\/+$/,""),i.toString().replace(/\/+$/,"")},_s=n=>{try{return new URL(n).host}catch{return n}},Wt=n=>{try{return Kt(n)}catch{return n.trim().replace(/\/+$/g,"")}},Ai=(n,e)=>Wt(n)===Wt(e),Ii=n=>`relay:${n.serverId}@${n.relayUrl.trim()}`,Oc=n=>`relay://${n.serverId}`,Hs=n=>n.candidates.filter(e=>e.kind==="direct"),jt=n=>{const e=n.candidates.find(s=>s.kind==="relay");return e&&e.kind==="relay"?e.relay:null},ct=n=>{const e=Hs(n)[0];if(e)return e.url;const s=jt(n);return s?Oc(s):""},Pe=n=>{const e=jt(n);if(e)return Ii(e);const s=Hs(n)[0];return s?Wt(s.url):""},Fs=(n,e)=>{const s=n.find(o=>o.kind==="relay"),i=s&&s.kind==="relay"?s.relay.serverId:null,r=new Set(n.filter(o=>o.kind==="direct").map(o=>Wt(o.url)));return e.some(o=>o.kind==="relay"?i!==null&&o.relay.serverId===i:r.has(Wt(o.url)))},Yn=n=>{const e=(()=>{try{return Kt(n)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},Dr=n=>{if(n.candidates&&n.candidates.length>0)return n.candidates;const e=[];return typeof n.url=="string"&&n.url.trim()&&!/^relay:\/\//i.test(n.url.trim())&&e.push(...Yn(n.url)),n.relay&&e.push({kind:"relay",relay:n.relay}),e},Qn=n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;const e=n;if(typeof e.relayUrl!="string"||!e.relayUrl.trim()||typeof e.serverId!="string"||!e.serverId.trim())return null;const s=e.hostEncPubJwk;if(!s||typeof s!="object"||Array.isArray(s))return null;const i=s;return i.kty!=="EC"||i.crv!=="P-256"||typeof i.x!="string"||!i.x||typeof i.y!="string"||!i.y?null:{relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:i.x,y:i.y}}},Ti=n=>{try{return JSON.stringify(n)}catch{return String(n)}},xe=(n,e={})=>{const s=Ti(e);console.info("[mobile-connect]",n,s),Jn(n,s)},ns=(n,e={})=>{xe(n,e)},Vt=(n,e={})=>{const s=Ti(e);console.info("[mobile-storage]",n,s),Jn(n,s)},Bc=n=>{if(typeof n!="string")return n;try{return JSON.parse(n)}catch{return n}},Lc=n=>{if(typeof n!="string")return n??void 0;try{return JSON.parse(n)}catch{return n}},$c=async(n,e)=>{if(!Te())return null;try{const{CapacitorHttp:s}=await $t(async()=>{const{CapacitorHttp:o}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:o}},[]),i=ho(n,new Headers(e?.headers)),r=await s.request({url:n,method:e?.method||"GET",headers:Object.fromEntries(i.entries()),data:Lc(e?.body)});return{ok:r.status>=200&&r.status<300,status:r.status,source:"native-http",json:async()=>Bc(r.data)}}catch(s){return xe("native-http:failed",{url:n,error:s instanceof Error?s.message:String(s)}),null}},Fc=async(n,e)=>{const s=await fetch(n,e).catch(i=>(xe("browser-fetch:failed",{url:n,error:i instanceof Error?i.message:String(i)}),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},bt=async(n,e,s)=>{let i;const r=new Promise(o=>{i=window.setTimeout(()=>{s?.(),o(null)},n)});try{return await Promise.race([e,r])}catch{return null}finally{i!==void 0&&window.clearTimeout(i)}},kt=async(n,e,s)=>{const i=s?.totalTimeoutMs??Pi,r=Date.now(),o=await bt(Math.min(_c,i),$c(n,e));if(o)return o;const a=new AbortController,c=Math.max(500,i-(Date.now()-r));return bt(c,Fc(n,{...e,signal:a.signal}),()=>a.abort())},qs=async n=>{if(!n)return null;const e=await n.json().catch(()=>null);if(!e||typeof e!="object")return null;const s=e;return{authenticated:typeof s.authenticated=="boolean"?s.authenticated:void 0,disabled:typeof s.disabled=="boolean"?s.disabled:void 0,scope:typeof s.scope=="string"?s.scope:void 0}},Ut=15e3,Wc=async(n,e,s,i=Ut,r)=>{const o=ii({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk}),a=c=>c==="ok"&&r?.keepTunnel?{outcome:c,tunnel:o}:(o.close(),{outcome:c});try{const c=e?{Authorization:`Bearer ${e}`}:void 0,f=await bt(i,o.fetch("/auth/session",{headers:c}).catch(()=>null));if(xe("relay:session",{ok:f?.ok===!0,status:f?.status??null,hasToken:!!e}),!f)return a("unreachable");if(f.status===401)return a(e?"auth-failed":"needs-login");if(!f.ok&&f.status!==404)return a("auth-failed");const d=await qs(f);return d&&d.disabled!==!0&&d.authenticated===!1?a(e?"auth-failed":"needs-login"):a("ok")}catch(c){throw o.close(),c}},Vc=(n,e,s,i,r)=>{const o=typeof window<"u"?window.location.origin:"",a={relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk,...s?{grant:s}:{}};r&&po(a,r),Dt({apiBaseUrl:o,clientToken:e,runtimeKey:i??Ii(n),relay:a})},Uc=n=>{if(!n||typeof n!="object")return null;const e=n;if(e.kind==="direct")return typeof e.url=="string"&&e.url.trim()?{kind:"direct",url:e.url}:null;if(e.kind==="relay"){const s=Qn(e.relay);return s?{kind:"relay",relay:s}:null}return null},Gc=n=>{if(n.mode==="relay"){const e=Qn(n.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof n.url=="string"?Yn(n.url):[]},St=()=>{if(typeof window>"u")return[];let n;try{n=JSON.parse(window.localStorage.getItem(Ls)||"[]")}catch{return[]}if(!Array.isArray(n))return[];const e=Te();return n.flatMap(s=>{if(!s||typeof s!="object")return[];const i=s;if(typeof i.id!="string")return[];const r=Array.isArray(i.candidates)?i.candidates.map(Uc).filter(f=>!!f):Gc(i);if(r.length===0)return[];const o=typeof i.clientToken=="string"&&i.clientToken.trim()?i.clientToken:void 0,a=typeof i.label=="string"&&i.label.trim()?i.label:_s(ct({candidates:r})),c={id:i.id,label:a,candidates:r,lastUsedAt:typeof i.lastUsedAt=="number"?i.lastUsedAt:0};return e?[{...c,hasToken:!!i.hasToken||!!o}]:[{...c,clientToken:o,hasToken:!!o}]}).sort((s,i)=>i.lastUsedAt-s.lastUsedAt)},vn=n=>n.kind==="relay"?{kind:"relay",relay:{relayUrl:n.relay.relayUrl,serverId:n.relay.serverId,hostEncPubJwk:n.relay.hostEncPubJwk}}:{kind:"direct",url:n.url},Xn=n=>{if(typeof window>"u")return;const e=Te(),s=n.slice(0,Ei).map(i=>{const r={id:i.id,label:i.label,candidates:i.candidates.map(vn),lastUsedAt:i.lastUsedAt};return e?{...r,hasToken:!!(i.hasToken||i.clientToken)}:{...r,clientToken:i.clientToken}});try{window.localStorage.setItem(Ls,JSON.stringify(s))}catch(i){console.warn("[mobile-storage] failed to persist connection metadata",i)}},Di=(n,e)=>{const s=n.find(o=>e.id&&o.id===e.id||Fs(o.candidates,e.candidates)),i=Te(),r={id:e.id||s?.id||crypto.randomUUID(),label:e.label,candidates:e.candidates,lastUsedAt:Date.now(),...i?{hasToken:e.hasToken??(!!e.clientToken||s?.hasToken||!1)}:{clientToken:e.clientToken??s?.clientToken,hasToken:!!(e.clientToken??s?.clientToken)}};return[r,...n.filter(o=>o.id!==r.id&&!Fs(o.candidates,e.candidates))].slice(0,Ei)},Zn=Bl,Kc=0,er=n=>`${Tc}token.${encodeURIComponent(n)}`,Hc=async(n,e)=>{let s;const i=new Promise(r=>{s=window.setTimeout(()=>r(e),Mc)});try{return await Promise.race([n.catch(()=>e),i])}finally{s!==void 0&&window.clearTimeout(s)}},tr=async(n,e,s)=>Te()?Hc(e().catch(i=>(console.warn(`[mobile-storage] ${n} failed`,i),s)),s):s,ms=async n=>{Vt("secure:read-start",{key:n});const e=await tr("secure:read",async()=>(await Zn.internalGetItem({prefixedKey:er(n),sync:!1})).data,null),s=typeof e=="string"&&e.trim()?e:void 0;return Vt("secure:read",{key:n,hasToken:!!s}),s},vt=async(n,e)=>{Vt("secure:write-start",{key:n});const s=await tr("secure:write",async()=>(await Zn.internalSetItem({prefixedKey:er(n),data:e,sync:!1,access:Kc}),!0),!1);return Vt("secure:write",{key:n,ok:s}),s},qc=async n=>{await tr("secure:delete",async()=>(await Zn.internalRemoveItem({prefixedKey:er(n),sync:!1}),!0),!1)},Jc=async(n,e)=>{let s=0,i=0;return{records:await Promise.all(n.map(async o=>{if(!o||typeof o!="object")return o;const a=o,c=typeof a.url=="string"?a.url:null,f=typeof a.clientToken=="string"?a.clientToken.trim():"";if(!c||!f)return o;if(!await e(c,f))return i+=1,o;s+=1;const{clientToken:d,...l}=a;return{...l,hasToken:!0}})),migrated:s,failed:i}},_i=async()=>{if(typeof window>"u"||!Te())return;let n;try{n=JSON.parse(window.localStorage.getItem(Ls)||"[]")}catch{return}if(!Array.isArray(n))return;const e=n.filter(i=>!!i&&typeof i=="object"&&typeof i.url=="string"&&typeof i.clientToken=="string"&&!!i.clientToken.trim());if(e.length===0)return;Vt("secure:migrate-start",{count:e.length});const s=await Jc(n,async(i,r)=>{const o=Wt(i);return await vt(o,r)?await ms(o)===r:!1});if(s.migrated>0)try{window.localStorage.setItem(Ls,JSON.stringify(s.records))}catch(i){console.warn("[mobile-storage] failed to finalize secure token migration",i);return}Vt("secure:migrate-done",{migrated:s.migrated,failed:s.failed})},Yc=async()=>(await _i(),St()),Ws=async n=>{const e=Di(St(),n);return Xn(e),Te()&&n.clientToken&&await vt(Pe({candidates:n.candidates}),n.clientToken),e},Qc=async n=>{const e=St(),s=e.find(r=>r.id===n)??null,i=e.filter(r=>r.id!==n);return Xn(i),s&&Te()&&await qc(Pe(s)),i},Xc=1500,Vs=async(n,e,s)=>{const i=s?.fast?{totalTimeoutMs:$s}:void 0,r=jt({candidates:n})?.serverId??null,o=n.find(d=>d.kind==="relay")??null,a=n.filter(d=>d.kind==="direct"),c=async()=>{for(const d of a){const l=Kt(d.url)||d.url,p=e?{Authorization:`Bearer ${e}`}:void 0,g=await kt(`${l}/health`,{method:"GET"},i);if(xe("probe:direct:health",{url:l,ok:g?.ok===!0,status:g?.status??null,source:g?.source??null}),!g?.ok)continue;if(r){const x=await g.json().catch(()=>null),E=x&&typeof x=="object"?x.serverId:null;if(typeof E=="string"&&E&&E!==r){xe("probe:server-id-mismatch",{url:l});continue}}const h=await kt(`${l}/auth/session`,{method:"GET",credentials:e?"omit":"include",headers:p},i);if(xe("probe:direct:session",{url:l,ok:h?.ok===!0,status:h?.status??null,source:h?.source??null,hasToken:!!e}),h?.status===401)return{status:"needs-login"};if(!h||!h.ok&&h.status!==404)continue;const b=await qs(h);if(b&&b.disabled!==!0&&b.authenticated===!1)return{status:"needs-login"};const S=b?.disabled===!0;return!e&&Te()&&!S&&b?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:l}}}return{status:"unreachable"}},f=async()=>{if(!o)return{status:"unreachable"};const{outcome:d,tunnel:l}=await Wc(o.relay,e,void 0,s?.fast?$s:Pi,{keepTunnel:!0});return d==="ok"?{status:"ok",transport:{kind:"relay",relay:o.relay,tunnel:l}}:d==="needs-login"||d==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return o?a.length===0?f():new Promise(d=>{let l=!1,p=!1,g,h=null,b=null;const S=v=>{v?.status==="ok"&&v.transport.kind==="relay"&&v.transport.tunnel?.close()},x=v=>{l||(l=!0,d(v))},E=()=>{p||l||(g!==void 0&&(window.clearTimeout(g),g=void 0),f().then(v=>{if(b=v,l||p){S(v);return}if(v.status==="ok"||v.status==="needs-login"){x(v);return}h&&x(h)}))};c().then(v=>{if(h=v,!l){if(v.status==="ok"||v.status==="needs-login"){p=!0,g!==void 0&&window.clearTimeout(g),S(b),x(v);return}if(b){x(b);return}E()}}),g=window.setTimeout(E,Xc)}):c()},wt=(n,e,s)=>{n.kind==="relay"?Vc(n.relay,e,s?.grant,s?.runtimeKey,n.tunnel):Dt({apiBaseUrl:n.url,clientToken:e,runtimeKey:s?.runtimeKey}),zi()},os=()=>{const n=St()[0];return n?.label?.trim()?n.label:null},rs=async n=>{const e=n?.fast!==!1;await _i();const s=St()[0];if(xe("auto-connect:start",{hasCandidate:!!s,fast:e}),!s)return{status:"no-candidate"};let i;if(Te()){if(s.hasToken&&(i=await ms(Pe(s)),!i))return{status:"no-candidate"}}else if(i=s.clientToken,!i&&s.hasToken)return{status:"no-candidate"};const r=await Vs(s.candidates,i,{fast:e});return xe("auto-connect:probe",{status:r.status,candidates:s.candidates.map(o=>o.kind)}),r.status==="needs-login"?{status:"needs-login",label:s.label}:r.status!=="ok"?{status:"unreachable",label:s.label}:n?.skipIfConnected&&st()?(r.transport.kind==="relay"&&r.transport.tunnel?.close(),xe("auto-connect:superseded",{}),{status:"no-candidate"}):(await Ws({id:s.id,label:s.label,candidates:s.candidates}),wt(r.transport,i??null,{runtimeKey:Pe(s)}),{status:"connected"})},Zc=async(n,e)=>{let s="";try{s=Kt(n.url)}catch{return!1}if(!s)return!1;const i=n.clientToken?.trim()||void 0,r=i?{Authorization:`Bearer ${i}`}:void 0,o=e?.fast?{totalTimeoutMs:$s}:void 0;if(!(await kt(`${s}/health`,{method:"GET",headers:r},o))?.ok)return!1;const c=await kt(`${s}/auth/session`,{method:"GET",credentials:i?"omit":"include",headers:r},o);if(!c||!c.ok&&c.status!==404)return!1;const f=await qs(c);return!(f&&f.disabled!==!0&&f.authenticated===!1)},eu=n=>[...n].sort((e,s)=>{const i=(e.priority??100)-(s.priority??100);if(i!==0)return i;const r=o=>o.type==="relay"?2:o.url.startsWith("https://")?0:1;return r(e)-r(s)}).flatMap(e=>{if(e.type==="relay"){const s=Qn({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return Yn(e.url)}),_r=async n=>{const e=jt({candidates:n})?.serverId??null;for(const s of n){if(s.kind==="relay"){const o=ii(s.relay),a=await bt(Ut,o.fetch("/health").catch(()=>null));if(xe("establish:relay:health",{ok:a?.ok===!0,status:a?.status??null}),a?.ok)return{kind:"relay",relay:s.relay,tunnel:o};o.close();continue}const i=Kt(s.url)||s.url,r=await kt(`${i}/health`,{method:"GET"});if(xe("establish:direct:health",{ok:r?.ok===!0,status:r?.status??null}),!!r?.ok){if(e){const o=await r.json().catch(()=>null),a=o&&typeof o=="object"?o.serverId:null;if(typeof a=="string"&&a&&a!==e){xe("establish:server-id-mismatch",{url:i});continue}}return{kind:"direct",url:i}}}return null},tu=async(n,e)=>{if(!fs())return Zc(n,e);const s=await bt(e?.fast?$s:Ut,Sn("/auth/session").then(r=>r).catch(()=>null));if(!s)return!0;if(s.status===401)return!1;if(!s.ok&&s.status!==404)return!0;const i=await qs(s);return!(i&&i.disabled!==!0&&i.authenticated===!1)},su=n=>n.kind==="relay"?fs():!fs()&&Ai(n.url,st()),Mi=()=>{const n=Gt();return n?St().find(e=>Pe(e)===n)??null:null},Mr=n=>{const e=Gt();return!!e&&Pe(n)===e},Ms=async n=>{const e=n?.fast!==!1,s=Mi();if(!s)return xe("reprobe:no-connection",{runtimeKey:!!Gt()}),"no-connection";let i;if(Te()?i=s.hasToken?await ms(Pe(s)):void 0:i=s.clientToken,!i&&s.hasToken)return xe("reprobe:no-token",{hasToken:!0}),"unreachable";xe("reprobe:start",{candidates:s.candidates.map(d=>d.kind),fast:e,hasToken:!!i});const r=s.candidates.findIndex(d=>su(d.kind==="relay"?{kind:"relay",relay:d.relay}:{kind:"direct",url:d.url})),o=r>=0?s.candidates.slice(0,r):s.candidates,a=await Vs(o,i,{fast:e});if(xe("reprobe:better",{status:a.status,probed:o.length}),a.status==="ok")return await Ws({id:s.id,label:s.label,candidates:s.candidates}),wt(a.transport,i??null,{runtimeKey:Pe(s)}),"switched";if(a.status==="needs-login")return"needs-login";if(r>=0){const d=await tu({url:st(),clientToken:i},{fast:e});if(xe("reprobe:current",{stillValid:d}),d)return zi(),"unchanged"}const c=r>=0?s.candidates.slice(r+1):[],f=await Vs(c,i,{fast:e});return xe("reprobe:fallback",{status:f.status,probed:c.length}),f.status==="ok"?(await Ws({id:s.id,label:s.label,candidates:s.candidates}),wt(f.transport,i??null,{runtimeKey:Pe(s)}),"switched"):f.status==="needs-login"?"needs-login":"unreachable"},nu=5e3;let un=!1;const ru=async()=>{if(un)return"skipped";const n=Mi();if(!n)return xe("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=jt(n);if(!e)return xe("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";un=!0;try{const s=await bt(Ut,Sn("/api/client-auth/connection/candidates").then(d=>d).catch(()=>null));if(!s?.ok)return xe("candidates:refresh-skip",{reason:"fetch-failed",status:s?.status??null}),"skipped";const i=await s.json().catch(()=>null);if(!i||i.serverId!==e.serverId)return xe("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const r=Array.isArray(i.candidates)?i.candidates:[],o=[];for(const d of r){if(!d||typeof d!="object")continue;const l=d;if(!(l.type!=="lan"||typeof l.url!="string"))try{const p=Kt(l.url);p&&!o.includes(p)&&o.push(p)}catch{}}if(o.length===0)return xe("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const a=Hs(n).filter(d=>d.url.startsWith("https://")),c=[...o.map(d=>({kind:"direct",url:d})),...a,{kind:"relay",relay:e}];return JSON.stringify(n.candidates.map(vn))===JSON.stringify(c.map(vn))?"unchanged":(xe("candidates:refreshed",{lanCount:o.length}),await Ws({id:n.id,label:n.label,candidates:c}),"updated")}finally{un=!1}},zi=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const n=await ru().catch(()=>"skipped");xe("candidates:refresh-result",{result:n}),n==="updated"&&fs()&&await Ms().catch(()=>null)})()},nu)},Oi=n=>{const{t:e}=me(),[s,i]=u.useState(()=>St()),[r,o]=u.useState(null),[a,c]=u.useState(null),[f,d]=u.useState(null),l=u.useRef(s),p=u.useRef(null),g=u.useRef(zc()),h=u.useCallback(C=>{l.current=C,i(C)},[]),b=u.useCallback(C=>{p.current=C,o(C)},[]),S=u.useCallback(C=>{p.current===C&&(p.current=null,o(null))},[]);u.useEffect(()=>{let C=!1;return Yc().then(R=>{C||h(R)}),()=>{C=!0}},[h]);const x=u.useCallback(C=>{const R=Di(l.current,C);return h(R),Xn(R),R},[h]),E=u.useCallback(async C=>{c(null),b("connect");try{const R=Dr(C);if(R.length===0){c(e("mobile.connect.error.urlRequired"));return}const k=C.id?l.current.find($=>$.id===C.id):l.current.find($=>Fs($.candidates,R)),z=C.label?.trim()||k?.label||_s(ct({candidates:R})),D=C.relayGrant;let M=C.clientToken?.trim()||void 0;const j=!!M;M||(Te()?k?.hasToken&&(M=await ms(Pe({candidates:R}))):M=k?.clientToken),xe("connect:start",{candidates:R.map($=>$.kind),hasToken:!!M});const I=await Vs(R,M);if(xe("connect:probe",{status:I.status}),I.status==="unreachable"){c(e("mobile.connect.error.unreachable"));return}if(I.status==="needs-login"){x({id:k?.id,label:z,candidates:R}),d({id:k?.id??crypto.randomUUID(),label:z,candidates:R,relay:jt({candidates:R})??void 0,relayGrant:D});return}M&&j&&Te()&&await vt(Pe({candidates:R}),M),x({id:k?.id,label:z,candidates:R,clientToken:M}),wt(I.transport,M??null,{runtimeKey:Pe({candidates:R}),grant:D}),n()}catch(R){console.warn("[mobile-connect] connect threw",R),c(e("mobile.connect.error.invalidUrl"))}finally{S("connect")}},[b,S,n,x,e]),v=u.useCallback(async C=>{if(p.current==="pairing")return;c(null),b("pairing");const R=eu(C.candidates);let k=null,z=!1;try{if(k=await _r(R),!k){c(e("mobile.connect.error.unreachable"));return}const D=JSON.stringify({pairingId:C.pairingId,secret:C.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:Tr(),dedupeKey:Ir()}),M={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:D},j=k.kind==="relay"?await bt(Ut,k.tunnel.fetch("/api/client-auth/pairing/redeem",M).catch(()=>null)):await kt(`${k.url}/api/client-auth/pairing/redeem`,M);if(!j?.ok){c(e("mobile.connect.error.authRequired"));return}const I=await j.json().catch(()=>null),$=typeof I?.clientToken=="string"?I.clientToken.trim():"";if(!$){c(e("mobile.connect.error.authRequired"));return}const w=typeof I?.server?.label=="string"?I.server.label:"",B=C.label||w||_s(ct({candidates:R}));if(Te()&&!await vt(Pe({candidates:R}),$)){c(e("mobile.connect.error.authRequired"));return}x({label:B,candidates:R,clientToken:$}),wt(k.kind==="relay"?{kind:"relay",relay:k.relay,tunnel:k.tunnel}:{kind:"direct",url:k.url},$,{runtimeKey:Pe({candidates:R})}),z=k.kind==="relay",n()}catch(D){console.warn("[mobile-connect] pairing threw",D),c(e("mobile.connect.error.authRequired"))}finally{!z&&k?.kind==="relay"&&k.tunnel.close(),S("pairing")}},[b,S,n,x,e]),N=u.useCallback(async C=>{if(!f||!C.trim()||p.current==="password")return;c(null),b("password");const R=g.current.begin(),k=()=>g.current.isCurrent(R),{id:z,label:D,candidates:M}=f;let j=null,I=!1;try{if(j=await _r(M),!k())return;if(!j){c(e("mobile.connect.error.unreachable"));return}const $={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:C,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile",clientKind:"mobile",devicePlatform:Tr(),dedupeKey:Ir()})};xe("password:start",{transport:j.kind});const w=j.kind==="relay"?await bt(Ut,j.tunnel.fetch("/auth/session",$).catch(()=>null)):await kt(`${j.url}/auth/session`,$);if(!k())return;if(xe("password:done",{ok:w?.ok===!0,status:w?.status??null}),!w?.ok){c(e("mobile.connect.error.passwordFailed"));return}const B=await w.json().catch(()=>null);if(!k())return;const U=typeof B?.clientToken=="string"?B.clientToken.trim():"";if(xe("password:token",{issued:!!U}),!U){if(j.kind==="direct"&&!Te()){x({id:z,label:D,candidates:M}),d(null),wt({kind:"direct",url:j.url},null,{runtimeKey:Pe({candidates:M})}),n();return}c(e("mobile.connect.error.authRequired"));return}if(Te()&&(!k()||(await vt(Pe({candidates:M}),U),!k()))||!k()||(x({id:z,label:D,candidates:M,clientToken:U}),d(null),wt(j.kind==="relay"?{kind:"relay",relay:j.relay,tunnel:j.tunnel}:{kind:"direct",url:j.url},U,{runtimeKey:Pe({candidates:M})}),I=j.kind==="relay",!k()))return;n()}catch($){if(!k())return;console.warn("[mobile-connect] password threw",$),c(e("mobile.connect.error.passwordFailed"))}finally{!I&&j?.kind==="relay"&&j.tunnel.close(),k()&&S("password")}},[b,S,n,f,x,e]),A=u.useCallback(()=>{g.current.cancel(),S("password"),d(null),c(null)},[S]),y=u.useCallback(async C=>{c(null);let R=Dr(C);const k=C.id?l.current.find(j=>j.id===C.id)??null:null;if(k){const j=R.filter(w=>w.kind==="direct"),I=Hs(k).filter(w=>w.url.startsWith("https://")&&!j.some(B=>Ai(B.url,w.url))),$=jt(k);R=[...j,...I,...$?[{kind:"relay",relay:$}]:[]]}if(R.length===0)return c(e("mobile.connect.error.urlRequired")),null;const z=C.clientToken?.trim()||void 0,D=C.label?.trim()||_s(ct({candidates:R}));if(Te()){const j=Pe({candidates:R});if(z)await vt(j,z);else if(k?.hasToken){const I=Pe(k);if(I&&j&&I!==j){const $=await ms(I);$&&await vt(j,$)}}}return x({id:C.id,label:D,candidates:R,clientToken:z}).find(j=>Fs(j.candidates,R))??null},[x,e]),P=u.useCallback(async C=>{const R=l.current.find(z=>z.id===C)??null,k=await Qc(C);return h(k),R},[h]);return{connections:s,isBusy:r!==null,isPasswordBusy:r==="password",error:a,pendingConnection:f,connect:E,redeemPairingConnection:v,submitPassword:N,cancelPassword:A,saveConnection:y,removeConnection:P,setError:c}},Bi=n=>{const e=le.c(31),{onClose:s}=n,{t:i}=me(),[r,o]=u.useState(!1);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=Pc(),e[0]=a):a=e[0];const c=a;let f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{No(Ic()).then(C=>{C.ok&&(o(!0),window.setTimeout(()=>o(!1),2e3))})},e[1]=f):f=e[1];const d=f;let l;e[2]!==i?(l=i("mobile.connectionDebug.title"),e[2]=i,e[3]=l):l=e[3];let p;e[4]!==l?(p=t.jsx("h2",{className:"min-w-0 truncate typography-ui-label text-foreground",children:l}),e[4]=l,e[5]=p):p=e[5];const g=r?"check":"file-copy";let h;e[6]!==g?(h=t.jsx(Z,{name:g,className:"size-4"}),e[6]=g,e[7]=h):h=e[7];let b;e[8]!==r||e[9]!==i?(b=i(r?"mobile.connectionDebug.copied":"mobile.connectionDebug.copy"),e[8]=r,e[9]=i,e[10]=b):b=e[10];let S;e[11]!==h||e[12]!==b?(S=t.jsxs(ge,{type:"button",variant:"outline",size:"sm",onClick:d,disabled:c.length===0,children:[h,b]}),e[11]=h,e[12]=b,e[13]=S):S=e[13];let x;e[14]!==i?(x=i("mobile.connectionDebug.close"),e[14]=i,e[15]=x):x=e[15];let E;e[16]===Symbol.for("react.memo_cache_sentinel")?(E=t.jsx(Z,{name:"close",className:"size-[18px]"}),e[16]=E):E=e[16];let v;e[17]!==s||e[18]!==x?(v=t.jsx(ge,{type:"button",variant:"ghost",size:"icon","aria-label":x,onClick:s,children:E}),e[17]=s,e[18]=x,e[19]=v):v=e[19];let N;e[20]!==v||e[21]!==S?(N=t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[S,v]}),e[20]=v,e[21]=S,e[22]=N):N=e[22];let A;e[23]!==N||e[24]!==p?(A=t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border/70 px-4 py-2.5",children:[p,N]}),e[23]=N,e[24]=p,e[25]=A):A=e[25];let y;e[26]!==i?(y=t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-3",children:c.length===0?t.jsx("p",{className:"typography-small text-muted-foreground",children:i("mobile.connectionDebug.empty")}):t.jsx("pre",{className:"whitespace-pre-wrap break-words typography-code text-muted-foreground",children:c.map(Ci).join(`
4
+ `)})}),e[26]=i,e[27]=y):y=e[27];let P;return e[28]!==A||e[29]!==y?(P=t.jsxs("div",{className:"fixed inset-0 z-[70] flex flex-col bg-background pb-[var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))] pt-[var(--safe-area-inset-top,env(safe-area-inset-top,0px))] text-foreground",children:[A,y]}),e[28]=A,e[29]=y,e[30]=P):P=e[30],P},Li=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&(typeof e.scan=="function"||typeof e.startScan=="function")?e:null},iu=()=>window.Capacitor?.getPlatform?.()==="android",$i=n=>{const e=n.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e)){const s=go(e);return s?{pairing:s}:null}return/^https?:\/\//i.test(e)?{url:e}:null},Fi=(n,e)=>{const s=$i(n);if(!s&&e?.pairingStringFallback){const i=bo(n);if(i)return{status:"pairing",pairing:i}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},ou=async(n,e)=>{if(!n.startScan||!n.stopScan||!n.addListener)return{status:"unsupported"};if(e?.aborted)return{status:"cancelled"};let s,i,r=!1,o=()=>{};const a=new Promise(d=>{o=d}),c=d=>{r||(r=!0,o(d))},f=()=>c({status:"cancelled"});e?.addEventListener("abort",f,{once:!0});try{return(await Promise.allSettled([Promise.resolve(n.addListener("barcodesScanned",({barcodes:l})=>{const p=l?.[0],g=(p?.rawValue??p?.displayValue??"").trim();g&&c(Fi(g,{pairingStringFallback:!0}))})).then(l=>{s=l}),Promise.resolve(n.addListener("scanError",()=>c({status:"failed"}))).then(l=>{i=l})])).some(({status:l})=>l==="rejected")?c({status:"failed"}):r||n.startScan({formats:["QR_CODE"]}).catch(()=>c({status:"failed"})),await a}finally{e?.removeEventListener("abort",f),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(i?.remove()),n.stopScan()])}},wn=()=>Li()!==null,Wi=async n=>{const e=Li();if(!e)return{status:"unsupported"};try{if(e.requestPermissions){const a=(await e.requestPermissions())?.camera;if(a&&a!=="granted"&&a!=="limited")return{status:"permission-denied"}}if(n?.signal?.aborted)return{status:"cancelled"};if(iu())return ou(e,n?.signal);if(!e.scan)return{status:"unsupported"};const i=(await e.scan({formats:["QR_CODE"]}))?.barcodes?.[0],r=(i?.rawValue??i?.displayValue??"").trim();return r?Fi(r):{status:"cancelled"}}catch{return{status:"failed"}}},Bt={autoComplete:"off",autoCorrect:"off",spellCheck:!1},as="oc-surface-elevated h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-interactive-border-focus focus:ring-2 focus:ring-ring",Vi=n=>{const e=le.c(22),{onCancel:s}=n,{t:i}=me(),r=u.useRef(null);let o,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>{const E={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},v={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const N=new Map,A=P=>{!(P instanceof HTMLElement)||P===r.current||N.has(P)||(N.set(P,{opacity:P.style.opacity,pointerEvents:P.style.pointerEvents}),P.style.setProperty("opacity","0"),P.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(A);const y=new MutationObserver(P=>{P.forEach(C=>C.addedNodes.forEach(A))});return y.observe(document.body,{childList:!0}),()=>{y.disconnect(),N.forEach(au),E.value?document.documentElement.style.setProperty("background-color",E.value,E.priority):document.documentElement.style.removeProperty("background-color"),v.value?document.body.style.setProperty("background-color",v.value,v.priority):document.body.style.removeProperty("background-color")}},a=[],e[0]=o,e[1]=a):(o=e[0],a=e[1]),u.useLayoutEffect(o,a);let c,f;e[2]!==s?(c=()=>{const E=()=>{document.visibilityState==="hidden"&&s()};return document.addEventListener("visibilitychange",E),()=>document.removeEventListener("visibilitychange",E)},f=[s],e[2]=s,e[3]=c,e[4]=f):(c=e[3],f=e[4]),u.useEffect(c,f);let d;e[5]!==i?(d=i("mobile.connect.scanQr"),e[5]=i,e[6]=d):d=e[6];let l;e[7]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),e[7]=l):l=e[7];let p;e[8]!==i?(p=i("mobile.connect.welcome.scanHint"),e[8]=i,e[9]=p):p=e[9];let g;e[10]!==p?(g=t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[l,t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:p})]}),e[10]=p,e[11]=g):g=e[11];let h;e[12]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(Z,{name:"close",className:"size-[18px]"}),e[12]=h):h=e[12];let b;e[13]!==i?(b=i("mobile.instances.cancelEdit"),e[13]=i,e[14]=b):b=e[14];let S;e[15]!==s||e[16]!==b?(S=t.jsxs(ge,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:s,children:[h,b]}),e[15]=s,e[16]=b,e[17]=S):S=e[17];let x;return e[18]!==S||e[19]!==d||e[20]!==g?(x=Lt.createPortal(t.jsxs("div",{ref:r,role:"dialog","aria-modal":"true","aria-label":d,className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[g,S]}),document.body),e[18]=S,e[19]=d,e[20]=g,e[21]=x):x=e[21],x},Ui=()=>{const n=le.c(6),{t:e}=me();let s;n[0]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsx(_t,{width:96,height:96,isAnimated:!0}),n[0]=s):s=n[0];let i;n[1]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(Z,{name:"loader-4",className:"size-[18px] animate-spin"}),n[1]=i):i=n[1];let r;n[2]!==e?(r=e("mobile.connect.connecting"),n[2]=e,n[3]=r):r=n[3];let o;return n[4]!==r?(o=Lt.createPortal(t.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[s,t.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[i,t.jsx("span",{children:r})]})]}),document.body),n[4]=r,n[5]=o):o=n[5],o};function au(n,e){e.style.opacity=n.opacity,e.style.pointerEvents=n.pointerEvents}const lu=({onConnected:n,notice:e=null})=>{const{t:s}=me(),i=Oi(n),{connections:r,isBusy:o,isPasswordBusy:a,error:c,pendingConnection:f}=i,[d,l]=u.useState(""),[p,g]=u.useState(""),[h,b]=u.useState(""),[S,x]=u.useState(!1),[E,v]=u.useState(!1),N=u.useRef(null),A=u.useMemo(()=>wn(),[]),[y,P]=u.useState(()=>!wn()),[C,R]=u.useState(null),[k,z]=u.useState(""),[D,M]=u.useState(!1),j=Ri(u.useCallback(()=>M(!0),[])),I=u.useCallback(O=>{O.preventDefault(),i.connect({url:d,clientToken:h,label:p})},[h,i,p,d]),$=u.useCallback(O=>{if(/^openchamber:\/\//i.test(O.trim())){const L=$i(O);if(L){if("pairing"in L){i.redeemPairingConnection(L.pairing);return}l(L.url),L.label&&g(L.label),L.clientToken&&b(L.clientToken);return}}l(O)},[i]),w=u.useCallback(async()=>{if(N.current||o)return;i.setError(null),x(!0);const O=new AbortController;N.current=O;try{const L=await Wi({signal:O.signal});switch(N.current===O&&(N.current=null,x(!1)),L.status){case"ok":v(!0),l(L.url),L.label&&g(L.label),L.clientToken&&b(L.clientToken),await i.connect({url:L.url,clientToken:L.clientToken,label:L.label});break;case"pairing":v(!0),await i.redeemPairingConnection(L.pairing);break;case"permission-denied":i.setError(s("mobile.connect.scan.permissionDenied"));break;case"invalid":i.setError(s("mobile.connect.scan.invalid"));break;case"unsupported":i.setError(s("mobile.connect.scan.unsupported"));break;case"failed":i.setError(s("mobile.connect.scan.failed"));break;default:break}}finally{v(!1),N.current===O&&(N.current=null,x(!1))}},[i,o,s]);u.useEffect(()=>()=>N.current?.abort(),[]);const B=u.useCallback(O=>{O.preventDefault(),i.submitPassword(k)},[i,k]),U=u.useCallback(()=>{z(""),i.cancelPassword()},[i]);return t.jsxs(t.Fragment,{children:[S?t.jsx(Vi,{onCancel:()=>N.current?.abort()}):null,E?t.jsx(Ui,{}):null,D?t.jsx(Bi,{onClose:()=>M(!1)}):null,t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx("span",{...j,className:"select-none",style:{touchAction:"manipulation"},children:t.jsx(_t,{width:72,height:72,className:"size-[72px]"})}),t.jsx("h1",{className:"typography-h2 text-foreground",children:s("mobile.connect.welcome.title")})]}),e?t.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:t.jsx(Z,{name:e.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),t.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:e.kind==="auth-expired"?s("mobile.connect.notice.authExpired",{label:e.label}):s("mobile.connect.notice.unreachable",{label:e.label})})]}):null,f?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:B,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(Z,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:f.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:f.candidates.some(O=>O.kind==="direct")?ct(f):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...Bt,value:k,onChange:O=>z(O.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:as}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!k.trim(),children:s(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:U,children:s("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[A?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(ge,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{w()},disabled:S||o,children:[t.jsx(Z,{name:"scan-2",className:Q("size-[18px]",S&&"animate-pulse")}),s(o?"mobile.connect.connecting":"mobile.connect.scanQr")]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:s("mobile.connect.welcome.scanHint")})]}):null,c&&!y?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:s("mobile.connect.saved.title")}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(O=>{const L=C===O.id;return t.jsxs("button",{type:"button",disabled:o,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:opacity-70",onClick:()=>{R(O.id),i.connect({id:O.id,candidates:O.candidates,clientToken:O.clientToken,label:O.label}).finally(()=>R(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(Z,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:O.label}),t.jsx("span",{className:Q("block truncate typography-small",L?"text-foreground":"text-muted-foreground"),children:L?s("mobile.connect.connecting"):O.candidates.some(ie=>ie.kind==="direct")?ct(O):s("mobile.connect.relay.badge")})]}),L?t.jsx(Z,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(Z,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},O.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[A?t.jsxs("button",{type:"button",onClick:()=>P(O=>!O),"aria-expanded":y,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[t.jsx("span",{children:s("mobile.connect.manual.toggle")}),t.jsx(Z,{name:"arrow-down-s",className:Q("size-4 transition-transform duration-200",y&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:y?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:I,children:[t.jsx("input",{...Bt,value:d,onChange:O=>$(O.target.value),placeholder:s("mobile.connect.url.placeholder"),"aria-label":s("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:y?void 0:-1,className:Q(as,"text-center")}),t.jsx("input",{value:p,onChange:O=>g(O.target.value),placeholder:s("mobile.instances.label.placeholder"),"aria-label":s("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:y?void 0:-1,className:Q(as,"text-center")}),t.jsx("input",{...Bt,value:h,onChange:O=>b(O.target.value),placeholder:s("mobile.connect.token.placeholder"),"aria-label":s("mobile.connect.token.label"),tabIndex:y?void 0:-1,autoCapitalize:"none",className:Q(as,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",variant:A?"outline":"default",size:"lg",className:"h-12 w-full",disabled:o||S||!d.trim(),children:s(o?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})]})},cu=n=>{const e=n.usedPercent;return typeof e!="number"||!Number.isFinite(e)?"text-foreground":e>=80?"text-[var(--status-error)]":e>=50?"text-[var(--status-warning)]":"text-foreground"},uu=n=>{const e=le.c(12),{groups:s,displayMode:i,timeFormatPreference:r,className:o}=n;let a;e[0]!==o?(a=Q("space-y-1.5",o),e[0]=o,e[1]=a):a=e[1];let c;if(e[2]!==i||e[3]!==s||e[4]!==r){let d;e[6]!==i||e[7]!==r?(d=l=>t.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-2.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Co,{providerId:l.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:l.providerName}),l.planLabel?t.jsx("span",{className:"shrink-0 typography-micro capitalize text-muted-foreground",children:l.planLabel}):null,l.status&&l.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:l.status}):null]}),l.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:l.rows.map(p=>{const g=i==="remaining"?p.window.remainingPercent:p.window.usedPercent,h=Ro(p.window.valueLabel,g),b=Eo(p.window.resetAt,p.window.resetAfterFormatted??p.window.resetAtFormatted,r);return t.jsxs("div",{className:"flex min-w-0 items-baseline justify-between gap-3",children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-1.5",children:[t.jsx("span",{className:"shrink-0 truncate typography-ui-label text-muted-foreground",children:p.subtitle?`${p.subtitle} · ${p.label}`:p.label}),b?t.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground/70",children:b}):null]}),t.jsx("span",{className:Q("shrink-0 typography-ui-label font-semibold tabular-nums",cu(p.window)),children:h==="-"?"":h})]},p.key)})}):null,l.status&&l.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:l.status}):null]},l.providerId),e[6]=i,e[7]=r,e[8]=d):d=e[8],c=s.map(d),e[2]=i,e[3]=s,e[4]=r,e[5]=c}else c=e[5];let f;return e[9]!==a||e[10]!==c?(f=t.jsx("div",{className:a,children:c}),e[9]=a,e[10]=c,e[11]=f):f=e[11],f},zr=380,du=(n,e)=>{if(!n||typeof n!="object")return;const s=n[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},dn=n=>n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(n),fu="—",Gi=n=>{const e=le.c(20),{percentage:s}=n;let i,r,o,a,c,f,d;if(e[0]!==s){o=_o(s??0)??0;const h=Mo(s??0);r=h==="critical"?"var(--status-error)":h==="warn"?"var(--status-warning)":"var(--status-success)",i=2*Math.PI*7.5,a="0 0 18 18",c="size-[18px] -rotate-90",f="progressbar",d=s===null?void 0:Math.round(o),e[0]=s,e[1]=i,e[2]=r,e[3]=o,e[4]=a,e[5]=c,e[6]=f,e[7]=d}else i=e[1],r=e[2],o=e[3],a=e[4],c=e[5],f=e[6],d=e[7];let l;e[8]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=l):l=e[8];let p;e[9]!==i||e[10]!==s||e[11]!==r||e[12]!==o?(p=s===null?null:t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:r,strokeWidth:3,strokeLinecap:"round",strokeDasharray:i,strokeDashoffset:i*(1-o/100),className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=i,e[10]=s,e[11]=r,e[12]=o,e[13]=p):p=e[13];let g;return e[14]!==a||e[15]!==c||e[16]!==f||e[17]!==d||e[18]!==p?(g=t.jsxs("svg",{viewBox:a,className:c,role:f,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100,children:[l,p]}),e[14]=a,e[15]=c,e[16]=f,e[17]=d,e[18]=p,e[19]=g):g=e[19],g},mu=n=>{const e=le.c(13),{icon:s,iconNode:i,label:r,children:o}=n;let a;e[0]!==s||e[1]!==i?(a=i??(s?t.jsx(Z,{name:s,className:"size-[18px]"}):null),e[0]=s,e[1]=i,e[2]=a):a=e[2];let c;e[3]!==a?(c=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:a}),e[3]=a,e[4]=c):c=e[4];let f;e[5]!==r?(f=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:r}),e[5]=r,e[6]=f):f=e[6];let d;e[7]!==o?(d=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:o}),e[7]=o,e[8]=d):d=e[8];let l;return e[9]!==c||e[10]!==f||e[11]!==d?(l=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[c,f,d]}),e[9]=c,e[10]=f,e[11]=d,e[12]=l):l=e[12],l},pu=n=>{const e=le.c(57),{open:s,onClose:i,anchorRef:r,contextDisplay:o,usageGroups:a,usageDisplayMode:c,isUsageLoading:f,timeFormatPreference:d}=n,{t:l}=me(),p=u.useRef(null),[g,h]=u.useState(s),[b,S]=u.useState(!1),{enabled:x}=Rn(),E=u.useRef(null),[v,N]=u.useState(null);let A,y;e[0]!==r||e[1]!==x||e[2]!==s||e[3]!==g?(A=()=>{if(!s||!x||!g)return;const X=()=>{const ce=r.current?.getBoundingClientRect(),ue=E.current?.getBoundingClientRect();if(!ce||!ue){N(null);return}const q=ce.left-ue.left,oe=Math.min(Math.max(q,8),Math.max(8,ue.width-zr-8));N(oe)};X();const ne=E.current;if(typeof ResizeObserver>"u"||!ne)return;const re=new ResizeObserver(X);return re.observe(ne),()=>re.disconnect()},y=[r,x,s,g],e[0]=r,e[1]=x,e[2]=s,e[3]=g,e[4]=A,e[5]=y):(A=e[4],y=e[5]),u.useLayoutEffect(A,y);const P=x&&v!==null;let C,R;e[6]!==s||e[7]!==g?(C=()=>{if(s){h(!0),S(!1);return}if(!g)return;S(!0);const X=window.setTimeout(()=>{h(!1),S(!1)},140);return()=>window.clearTimeout(X)},R=[s,g],e[6]=s,e[7]=g,e[8]=C,e[9]=R):(C=e[8],R=e[9]),u.useEffect(C,R);let k,z;e[10]!==i||e[11]!==s?(k=()=>{if(!s)return;const X=ne=>{ne.key==="Escape"&&i()};return document.addEventListener("keydown",X),()=>document.removeEventListener("keydown",X)},z=[i,s],e[10]=i,e[11]=s,e[12]=k,e[13]=z):(k=e[12],z=e[13]),u.useEffect(k,z);let D,M;if(e[14]!==r||e[15]!==i||e[16]!==s?(D=()=>{if(!s)return;const X=ne=>{const re=ne.target;if(!(re instanceof Node)){i();return}p.current?.contains(re)||r.current?.contains(re)||i()};return document.addEventListener("pointerdown",X,!0),document.addEventListener("wheel",X,!0),()=>{document.removeEventListener("pointerdown",X,!0),document.removeEventListener("wheel",X,!0)}},M=[r,i,s],e[14]=r,e[15]=i,e[16]=s,e[17]=D,e[18]=M):(D=e[17],M=e[18]),u.useEffect(D,M),!g)return null;let j;e[19]!==l?(j=l("mobile.header.openMetadataAria"),e[19]=l,e[20]=j):j=e[20];const I=P?"absolute origin-top-left":"mx-3 mt-2",$=b?"pointer-events-none":"pointer-events-auto";let w;e[21]!==I||e[22]!==$?(w=Q("oc-surface-elevated overflow-y-auto overscroll-contain rounded-[20px] border border-border/70 bg-surface-elevated p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",I,$),e[21]=I,e[22]=$,e[23]=w):w=e[23];const B=`${b?"session-metadata-out":"session-metadata-in"} ${b?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let U;e[24]!==v||e[25]!==P?(U=P?{top:8,left:v??8,width:`min(${zr}px, calc(100% - 16px))`}:null,e[24]=v,e[25]=P,e[26]=U):U=e[26];let O;e[27]!==B||e[28]!==U?(O={animation:B,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...U},e[27]=B,e[28]=U,e[29]=O):O=e[29];let L;e[30]!==o||e[31]!==l?(L=o?t.jsx(mu,{iconNode:t.jsx(Gi,{percentage:o.state==="measured"?o.percentage:null}),label:l("mobile.header.metadata.context"),children:o.state==="pending"?null:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[o.state==="measured"?t.jsxs("span",{className:Q("font-semibold",o.colorClass),children:[o.percentage.toFixed(1),"%"]}):null,t.jsx("span",{className:"text-muted-foreground",children:o.tokens})]})}):null,e[30]=o,e[31]=l,e[32]=L):L=e[32];let ie;e[33]!==o?.state||e[34]!==l?(ie=o?.state==="compacted"?t.jsx("p",{className:"px-2.5 pb-1 typography-meta text-muted-foreground",children:l("contextUsage.compacted.description")}):null,e[33]=o?.state,e[34]=l,e[35]=ie):ie=e[35];let ee;e[36]!==o?.state||e[37]!==l?(ee=o?.state==="pending"?t.jsx("p",{className:"px-2.5 pb-1 typography-meta text-muted-foreground",children:l("mobile.header.metadata.contextPending")}):null,e[36]=o?.state,e[37]=l,e[38]=ee):ee=e[38];let W;e[39]!==f||e[40]!==d||e[41]!==c||e[42]!==a?(W=t.jsx(hu,{groups:a,displayMode:c,isLoading:f,timeFormatPreference:d}),e[39]=f,e[40]=d,e[41]=c,e[42]=a,e[43]=W):W=e[43];let _;e[44]!==L||e[45]!==ie||e[46]!==ee||e[47]!==W?(_=t.jsxs("div",{className:"space-y-1",children:[L,ie,ee,W]}),e[44]=L,e[45]=ie,e[46]=ee,e[47]=W,e[48]=_):_=e[48];let G;e[49]!==w||e[50]!==O||e[51]!==_||e[52]!==j?(G=t.jsx("div",{ref:p,role:"dialog","aria-label":j,className:w,style:O,children:_}),e[49]=w,e[50]=O,e[51]=_,e[52]=j,e[53]=G):G=e[53];let J;e[54]===Symbol.for("react.memo_cache_sentinel")?(J=t.jsx("style",{children:`
5
+ @keyframes session-metadata-in {
6
+ from { opacity: 0; transform: translateY(-8px) scale(0.985); }
7
+ to { opacity: 1; transform: translateY(0) scale(1); }
8
+ }
9
+ @keyframes session-metadata-out {
10
+ from { opacity: 1; transform: translateY(0) scale(1); }
11
+ to { opacity: 0; transform: translateY(-6px) scale(0.985); }
12
+ }
13
+ `}),e[54]=J):J=e[54];let H;return e[55]!==G?(H=t.jsxs("div",{ref:E,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[G,J]}),e[55]=G,e[56]=H):H=e[56],H},hu=n=>{const e=le.c(30),{groups:s,displayMode:i,isLoading:r,timeFormatPreference:o}=n,{t:a}=me();let c;e[0]!==i||e[1]!==a?(c=a(i==="remaining"?"header.services.remaining":"header.services.used"),e[0]=i,e[1]=a,e[2]=c):c=e[2];const f=c;if(s.length===0){if(!r)return null;let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(Z,{name:"loader-4",className:"size-4 animate-spin","aria-hidden":!0}),e[3]=v):v=e[3];let N;e[4]!==a?(N=a("common.loading"),e[4]=a,e[5]=N):N=e[5];let A;return e[6]!==N?(A=t.jsxs("div",{className:"flex items-center justify-center gap-2 px-2.5 py-6 text-muted-foreground",children:[v,t.jsx("span",{className:"typography-ui-label",children:N})]}),e[6]=N,e[7]=A):A=e[7],A}let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(Z,{name:"timer",className:"size-[18px]"})}),e[8]=d):d=e[8];let l;e[9]!==a?(l=a("mobile.header.metadata.usage"),e[9]=a,e[10]=l):l=e[10];let p;e[11]!==l?(p=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:l}),e[11]=l,e[12]=p):p=e[12];let g;e[13]!==r?(g=r?t.jsx(Z,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[13]=r,e[14]=g):g=e[14];let h;e[15]!==f?(h=t.jsx("span",{className:"truncate",children:f}),e[15]=f,e[16]=h):h=e[16];let b;e[17]!==g||e[18]!==h?(b=t.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center justify-end gap-1.5 typography-ui-label text-muted-foreground",children:[g,h]}),e[17]=g,e[18]=h,e[19]=b):b=e[19];let S;e[20]!==p||e[21]!==b?(S=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[d,p,b]}),e[20]=p,e[21]=b,e[22]=S):S=e[22];let x;e[23]!==i||e[24]!==s||e[25]!==o?(x=t.jsx(uu,{groups:s,displayMode:i,timeFormatPreference:o}),e[23]=i,e[24]=s,e[25]=o,e[26]=x):x=e[26];let E;return e[27]!==S||e[28]!==x?(E=t.jsxs("div",{className:"pt-2.5",children:[S,x]}),e[27]=S,e[28]=x,e[29]=E):E=e[29],E},gu=u.memo(function({open:e,onOpenChange:s,currentSessionId:i,effectiveDirectory:r,isNewSessionDraftOpen:o}){const{t:a}=me(),c=u.useRef(null),f=Po(i??"",r||void 0),d=He(w=>w.providers),l=He(w=>w.currentProviderId),p=He(w=>w.currentModelId),g=He(w=>w.getModelMetadata);He(w=>w.modelsMetadata.size);const h=Ao(u.useCallback(w=>i?w.sessionModelSelections.get(i)??null:null,[i])),b=yt(w=>w.results),S=yt(w=>w.refreshErrors),x=u.useRef(!1),E=yt(w=>w.loadSettings),v=yt(w=>w.fetchAllQuotas),N=yt(w=>w.isLoading),A=yt(w=>w.displayMode),y=yt(w=>w.dropdownProviderIds),P=it(w=>w.timeFormatPreference);Io(),u.useEffect(()=>{E()},[E]),u.useEffect(()=>{vr(y)},[y]),u.useEffect(()=>{if(!e){x.current=!1;return}x.current||N||!y.some(B=>!b.some(U=>U.providerId===B)||S[B])||(x.current=!0,v())},[y,v,N,e,b,S]);const R=u.useMemo(()=>{for(let w=f.length-1;w>=0;w-=1){const B=f[w];if(B.role!=="assistant")continue;const U=B.providerID.trim(),O=B.modelID.trim();if(U&&O)return{providerID:U,modelID:O}}return null},[f])??(h?{providerID:h.providerId,modelID:h.modelId}:null)??(l&&p?{providerID:l,modelID:p}:null),z=(R?d.find(w=>w.id===R.providerID):void 0)?.models.find(w=>w.id===R?.modelID),D=R?g(R.providerID,R.modelID):void 0,M=du(z?.limit,"context")??D?.limit?.context??0,j=u.useMemo(()=>To(f),[f]),I=u.useMemo(()=>{if(M<=0)return null;if(o||!j)return{state:"pending"};if(j.state==="compacted")return{state:"compacted",tokens:`${fu}/${dn(M)}`};const w=Math.min(j.totalTokens/M*100,999),B=w>=90?"text-[var(--status-error)]":w>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]";return{state:"measured",percentage:w,tokens:`${dn(j.totalTokens)}/${dn(M)}`,colorClass:B}},[j,M,o]),$=Do();return u.useEffect(()=>{!e||$.length===0||vr($.map(w=>w.providerId))},[e,$]),t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:c,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":a("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>s(w=>!w),style:{touchAction:"manipulation"},children:t.jsx(Gi,{percentage:I?.state==="measured"?I.percentage:I?.state==="compacted"?null:0})}),t.jsx(pu,{open:e,onClose:()=>s(!1),anchorRef:c,contextDisplay:I,usageGroups:$,usageDisplayMode:A,isUsageLoading:N,timeFormatPreference:P})]})}),bu=10,Or=380,xu=(n,e)=>n.title?.trim()||e,yu=n=>{const e=le.c(33),{session:s,meta:i,active:r,onSelect:o}=n,{t:a}=me(),c=En(s.id),f=Pn(s.id),d=!f&&c>0&&!r,l=An(s.id,f),p=(f||d)&&l,g=s.time?.updated??s.time?.created??0;let h;e[0]!==g?(h=Oo(g),e[0]=g,e[1]=h):h=e[1];const b=h,S=r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let x;e[2]!==S?(x=Q("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",S),e[2]=S,e[3]=x):x=e[3];let E;e[4]===Symbol.for("react.memo_cache_sentinel")?(E={touchAction:"manipulation"},e[4]=E):E=e[4];const v=r?"text-primary":"text-foreground";let N;e[5]!==v?(N=Q("block truncate typography-ui-label",v),e[5]=v,e[6]=N):N=e[6];let A;e[7]!==s||e[8]!==a?(A=xu(s,a("sessions.sidebar.session.untitled")),e[7]=s,e[8]=a,e[9]=A):A=e[9];let y;e[10]!==N||e[11]!==A?(y=t.jsx("span",{className:N,children:A}),e[10]=N,e[11]=A,e[12]=y):y=e[12];let P;e[13]!==i?(P=i?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:i}):null,e[13]=i,e[14]=P):P=e[14];let C;e[15]!==P||e[16]!==y?(C=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[y,P]}),e[15]=P,e[16]=y,e[17]=C):C=e[17];let R;e[18]!==f||e[19]!==d||e[20]!==a?(R=f||d?t.jsx(Os,{state:f?"running":"unread",label:a(f?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread")}):null,e[18]=f,e[19]=d,e[20]=a,e[21]=R):R=e[21];let k;e[22]!==f||e[23]!==s.id||e[24]!==p||e[25]!==b?(k=p?t.jsx(Mn,{sessionId:s.id,running:f,className:"typography-micro"}):b?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:b}):null,e[22]=f,e[23]=s.id,e[24]=p,e[25]=b,e[26]=k):k=e[26];let z;return e[27]!==o||e[28]!==C||e[29]!==R||e[30]!==k||e[31]!==x?(z=t.jsxs("button",{type:"button",className:x,onClick:o,style:E,children:[C,R,k]}),e[27]=o,e[28]=C,e[29]=R,e[30]=k,e[31]=x,e[32]=z):z=e[32],z},vu=n=>{const e=le.c(50),{open:s,onClose:i,anchorRef:r}=n,{t:o}=me(),a=u.useRef(null),[c,f]=u.useState(s),[d,l]=u.useState(!1),{enabled:p}=Rn(),g=u.useRef(null),[h,b]=u.useState(null);let S,x;e[0]!==r||e[1]!==p||e[2]!==s||e[3]!==c?(S=()=>{if(!s||!p||!c)return;const H=()=>{const re=r.current?.getBoundingClientRect(),ce=g.current?.getBoundingClientRect();if(!re||!ce){b(null);return}const ue=re.left-ce.left;b(Math.min(Math.max(ue,8),Math.max(8,ce.width-Or-8)))};H();const X=g.current;if(typeof ResizeObserver>"u"||!X)return;const ne=new ResizeObserver(H);return ne.observe(X),()=>ne.disconnect()},x=[r,p,s,c],e[0]=r,e[1]=p,e[2]=s,e[3]=c,e[4]=S,e[5]=x):(S=e[4],x=e[5]),u.useLayoutEffect(S,x);const E=p&&h!==null,v=Se(wu),N=Se(ju),A=We(ku);let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y={maxParents:bu},e[6]=y):y=e[6];const P=zo(s||c,y);let C,R;e[7]!==s||e[8]!==c?(C=()=>{if(s){In(),f(!0),l(!1);return}if(!c)return;l(!0);const H=window.setTimeout(()=>{f(!1),l(!1)},140);return()=>window.clearTimeout(H)},R=[s,c],e[7]=s,e[8]=c,e[9]=C,e[10]=R):(C=e[9],R=e[10]),u.useEffect(C,R);let k,z;e[11]!==i||e[12]!==s?(k=()=>{if(!s)return;const H=X=>{X.key==="Escape"&&i()};return document.addEventListener("keydown",H),()=>document.removeEventListener("keydown",H)},z=[i,s],e[11]=i,e[12]=s,e[13]=k,e[14]=z):(k=e[13],z=e[14]),u.useEffect(k,z);let D,M;e[15]!==r||e[16]!==i||e[17]!==s?(D=()=>{if(!s)return;const H=X=>{const ne=X.target;if(!(ne instanceof Node)){i();return}a.current?.contains(ne)||r.current?.contains(ne)||i()};return document.addEventListener("pointerdown",H,!0),()=>document.removeEventListener("pointerdown",H,!0)},M=[r,i,s],e[15]=r,e[16]=i,e[17]=s,e[18]=D,e[19]=M):(D=e[18],M=e[19]),u.useEffect(D,M);let j;e[20]!==i||e[21]!==N?(j=H=>{N(H.id,Cn(H)),i()},e[20]=i,e[21]=N,e[22]=j):j=e[22];const I=j;if(!c)return null;let $;e[23]!==o?($=o("sessions.switcher.openAria"),e[23]=o,e[24]=$):$=e[24];const w=E?"absolute origin-top-left":"mx-3 mt-2",B=d?"pointer-events-none":"pointer-events-auto";let U;e[25]!==w||e[26]!==B?(U=Q("oc-surface-elevated flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-surface-elevated p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",w,B),e[25]=w,e[26]=B,e[27]=U):U=e[27];const O=`${d?"session-switcher-out":"session-switcher-in"} ${d?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let L;e[28]!==h||e[29]!==E?(L=E?{top:8,left:h??8,width:`min(${Or}px, calc(100% - 16px))`}:null,e[28]=h,e[29]=E,e[30]=L):L=e[30];let ie;e[31]!==O||e[32]!==L?(ie={animation:O,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...L},e[31]=O,e[32]=L,e[33]=ie):ie=e[33];let ee;e[34]!==v||e[35]!==I||e[36]!==P||e[37]!==A||e[38]!==o?(ee=P.length===0?t.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:o("sessions.switcher.empty")}):P.map(H=>{const X=H.node.session,ne=[H.secondaryMeta?.projectLabel,H.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(yu,{session:X,meta:ne,active:X.id===v,onSelect:()=>{H.projectId&&A(H.projectId),I(X)}},X.id)}),e[34]=v,e[35]=I,e[36]=P,e[37]=A,e[38]=o,e[39]=ee):ee=e[39];let W;e[40]!==ee?(W=t.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:ee}),e[40]=ee,e[41]=W):W=e[41];let _;e[42]!==$||e[43]!==U||e[44]!==ie||e[45]!==W?(_=t.jsx("div",{ref:a,role:"dialog","aria-label":$,className:U,style:ie,children:W}),e[42]=$,e[43]=U,e[44]=ie,e[45]=W,e[46]=_):_=e[46];let G;e[47]===Symbol.for("react.memo_cache_sentinel")?(G=t.jsx("style",{children:`
14
+ @keyframes session-switcher-in {
15
+ from { opacity: 0; transform: translateY(-8px) scale(0.985); }
16
+ to { opacity: 1; transform: translateY(0) scale(1); }
17
+ }
18
+ @keyframes session-switcher-out {
19
+ from { opacity: 1; transform: translateY(0) scale(1); }
20
+ to { opacity: 0; transform: translateY(-6px) scale(0.985); }
21
+ }
22
+ `}),e[47]=G):G=e[47];let J;return e[48]!==_?(J=t.jsxs("div",{ref:g,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[_,G]}),e[48]=_,e[49]=J):J=e[49],J};function wu(n){return n.currentSessionId}function ju(n){return n.setCurrentSession}function ku(n){return n.setActiveProjectIdOnly}const Su=n=>{const e=le.c(78),{onOpenSessions:s,onOpenWorkspace:i,compactTitle:r}=n,o=r===void 0?!1:r,{t:a}=me(),[c,f]=u.useState(!1),[d,l]=u.useState(!1),p=u.useRef(null),g=gt(Nu),h=Se(Cu);let b;e[0]!==h?(b=De=>h?De.getDirectoryForSession(h):null,e[0]=h,e[1]=b):b=e[1];const x=Se(b)||g,E=Bo(h,x||void 0),v=Se(Ru),N=ci(x||null);let A;e[2]!==x||e[3]!==N?(A=De=>{if(!x||N!==!0)return!1;const Be=De.directories.get(x)?.status;return!!(Be&&!Be.isClean)},e[2]=x,e[3]=N,e[4]=A):A=e[4];const y=Fe(A);let P;e[5]!==E?.title?(P=E?.title?.trim(),e[5]=E?.title,e[6]=P):P=e[6];const C=P;let R;e[7]!==h||e[8]!==C||e[9]!==a?(R=C||a(h?"mobile.sessions.untitled":"sessions.switcher.draftTitle"),e[7]=h,e[8]=C,e[9]=a,e[10]=R):R=e[10];const k=R;let z;e[11]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{f(!1),l(!1)},e[11]=z):z=e[11];let D;e[12]!==h||e[13]!==x?(D=[h,x],e[12]=h,e[13]=x,e[14]=D):D=e[14],u.useEffect(z,D);let M;e[15]!==s?(M=()=>{f(!1),l(!1),s()},e[15]=s,e[16]=M):M=e[16];const j=M;let I;e[17]===Symbol.for("react.memo_cache_sentinel")?(I=De=>{f(Be=>{const Ne=typeof De=="function"?De(Be):De;return Ne&&l(!1),Ne})},e[17]=I):I=e[17];const $=I;let w;e[18]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{l(De=>{const Be=!De;return Be&&f(!1),Be})},e[18]=w):w=e[18];const B=w;let U;e[19]===Symbol.for("react.memo_cache_sentinel")?(U={paddingTop:"var(--oc-safe-area-top, 0px)"},e[19]=U):U=e[19];let O;e[20]!==a?(O=a("mobile.sessions.openSheetAria"),e[20]=a,e[21]=O):O=e[21];let L,ie;e[22]===Symbol.for("react.memo_cache_sentinel")?(L={touchAction:"manipulation"},ie=t.jsx(Z,{name:"list-unordered",className:"size-5"}),e[22]=L,e[23]=ie):(L=e[22],ie=e[23]);let ee;e[24]!==j||e[25]!==O?(ee=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":O,onClick:j,style:L,children:ie}),e[24]=j,e[25]=O,e[26]=ee):ee=e[26];const W=o?"shrink":"flex-1";let _;e[27]!==W?(_=Q("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",W),e[27]=W,e[28]=_):_=e[28];let G;e[29]!==a?(G=a("sessions.switcher.openAria"),e[29]=a,e[30]=G):G=e[30];let J;e[31]===Symbol.for("react.memo_cache_sentinel")?(J={touchAction:"manipulation"},e[31]=J):J=e[31];let H;e[32]!==k?(H=t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:k}),e[32]=k,e[33]=H):H=e[33];const X=d&&"rotate-180";let ne;e[34]!==X?(ne=Q("size-4 shrink-0 text-muted-foreground transition-transform duration-150",X),e[34]=X,e[35]=ne):ne=e[35];let re;e[36]!==ne?(re=t.jsx(Z,{name:"arrow-down-s",className:ne}),e[36]=ne,e[37]=re):re=e[37];let ce;e[38]!==H||e[39]!==re?(ce=t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[H,re]}),e[38]=H,e[39]=re,e[40]=ce):ce=e[40];let ue;e[41]!==d||e[42]!==_||e[43]!==G||e[44]!==ce?(ue=t.jsx("button",{ref:p,type:"button",className:_,"aria-label":G,"aria-haspopup":"dialog","aria-expanded":d,onClick:B,style:J,children:ce}),e[41]=d,e[42]=_,e[43]=G,e[44]=ce,e[45]=ue):ue=e[45];let q;e[46]!==o?(q=o?t.jsx("div",{className:"min-w-0 flex-1"}):null,e[46]=o,e[47]=q):q=e[47];let oe;e[48]!==h||e[49]!==x||e[50]!==v||e[51]!==c?(oe=t.jsx(gu,{open:c,onOpenChange:$,currentSessionId:h,effectiveDirectory:x,isNewSessionDraftOpen:v}),e[48]=h,e[49]=x,e[50]=v,e[51]=c,e[52]=oe):oe=e[52];let pe;e[53]!==y||e[54]!==a?(pe=a(y?"mobile.header.openWorkspaceWithChangesAria":"mobile.header.openWorkspaceAria"),e[53]=y,e[54]=a,e[55]=pe):pe=e[55];let ke;e[56]!==i?(ke=()=>{f(!1),l(!1),i()},e[56]=i,e[57]=ke):ke=e[57];let Y,de;e[58]===Symbol.for("react.memo_cache_sentinel")?(Y={touchAction:"manipulation"},de=t.jsx(Z,{name:"pencil-ruler-2",className:"size-5"}),e[58]=Y,e[59]=de):(Y=e[58],de=e[59]);let Ce;e[60]!==y?(Ce=y?t.jsx("span",{className:"absolute right-1.5 top-1.5 size-2.5 rounded-full border-2 border-[var(--background)] bg-[var(--status-warning)]","aria-hidden":!0}):null,e[60]=y,e[61]=Ce):Ce=e[61];let ze;e[62]!==pe||e[63]!==ke||e[64]!==Ce?(ze=t.jsxs("button",{type:"button",className:"relative flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":pe,onClick:ke,style:Y,children:[de,Ce]}),e[62]=pe,e[63]=ke,e[64]=Ce,e[65]=ze):ze=e[65];let Ae;e[66]!==ee||e[67]!==ue||e[68]!==q||e[69]!==oe||e[70]!==ze?(Ae=t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:U,children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[ee,ue,q,oe,ze]})}),e[66]=ee,e[67]=ue,e[68]=q,e[69]=oe,e[70]=ze,e[71]=Ae):Ae=e[71];let Je;e[72]===Symbol.for("react.memo_cache_sentinel")?(Je=()=>l(!1),e[72]=Je):Je=e[72];let Xe;e[73]!==d?(Xe=t.jsx(vu,{open:d,onClose:Je,anchorRef:p}),e[73]=d,e[74]=Xe):Xe=e[74];let dt;return e[75]!==Ae||e[76]!==Xe?(dt=t.jsxs(t.Fragment,{children:[Ae,Xe]}),e[75]=Ae,e[76]=Xe,e[77]=dt):dt=e[77],dt};function Nu(n){return n.currentDirectory}function Cu(n){return n.currentSessionId}function Ru(n){return!!n.newSessionDraft?.open}const Eu=({onActiveConnectionDeleted:n,onConnect:e})=>{const{t:s}=me(),i=Oi(e),{connections:r,isBusy:o,isPasswordBusy:a,error:c,pendingConnection:f,connect:d,submitPassword:l,cancelPassword:p,saveConnection:g,removeConnection:h,setError:b}=i,[S,x]=u.useState(null),E=S?r.find(q=>q.id===S)??null:null,[v,N]=u.useState(null),[A,y]=u.useState(""),[P,C]=u.useState(""),[R,k]=u.useState(""),[z,D]=u.useState(""),[M,j]=u.useState(!1),[I,$]=u.useState(!1),w=u.useRef(null),B=u.useMemo(()=>wn(),[]),[U,O]=u.useState(!1),[L,ie]=u.useState(null),[ee,W]=u.useState(!1),_=Ri(u.useCallback(()=>W(!0),[])),G=u.useCallback(()=>{x(null),y(""),C(""),k(""),b(null),O(!1)},[b]),J=u.useCallback(q=>{q.preventDefault(),g({id:S??void 0,url:A,label:P,clientToken:R}).then(oe=>{oe&&G()})},[R,S,P,G,g,A]),H=u.useCallback(async()=>{if(w.current)return;b(null),j(!0);const q=new AbortController;w.current=q;try{const oe=await Wi({signal:q.signal});switch(w.current===q&&(w.current=null,j(!1)),oe.status){case"ok":y(oe.url),oe.label&&C(oe.label),oe.clientToken&&k(oe.clientToken),O(!0);break;case"pairing":$(!0),await i.redeemPairingConnection(oe.pairing);break;case"permission-denied":b(s("mobile.connect.scan.permissionDenied"));break;case"invalid":b(s("mobile.connect.scan.invalid"));break;case"unsupported":b(s("mobile.connect.scan.unsupported"));break;case"failed":b(s("mobile.connect.scan.failed"));break;default:break}}finally{$(!1),w.current===q&&(w.current=null,j(!1))}},[i,b,s]);u.useEffect(()=>()=>w.current?.abort(),[]);const X=u.useCallback(q=>{q.preventDefault(),l(z)},[z,l]),ne=u.useCallback(()=>{D(""),p()},[p]),re=u.useCallback(q=>{N(oe=>oe===q?null:q)},[]),ce=u.useCallback(q=>{N(null),S===q&&G();const oe=r.length===1;h(q).then(pe=>{pe&&(oe||Mr(pe))&&n()})},[r.length,S,n,h,G]),ue=as;return f?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:X,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(Z,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:f.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:f.candidates.some(q=>q.kind==="direct")?ct(f):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...Bt,value:z,onChange:q=>D(q.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:ue}),c?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!z.trim(),children:s(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:ne,children:s("mobile.connect.cancelPassword")})]})})}):t.jsxs(t.Fragment,{children:[M?t.jsx(Vi,{onCancel:()=>w.current?.abort()}):null,I?t.jsx(Ui,{}):null,ee?t.jsx(Bi,{onClose:()=>W(!1)}):null,t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[r.length>0?t.jsx("div",{..._,className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(q=>{const oe=v===q.id,pe=Mr(q),ke=L===q.id,Y=ke?s("mobile.connect.connecting"):pe?fs()?s("mobile.instances.status.connectedRelay"):s("mobile.instances.status.connectedDirect"):q.candidates.some(de=>de.kind==="direct")?ct(q):s("mobile.connect.relay.badge");return t.jsxs("div",{className:Q("flex items-center border-b border-border/70 transition-colors last:border-b-0",oe&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:opacity-60",onClick:()=>{pe||(ie(q.id),d({id:q.id,candidates:q.candidates,clientToken:q.clientToken,label:q.label}).finally(()=>ie(null)))},disabled:o&&!ke||oe,children:[t.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[t.jsx(Z,{name:"server",className:"size-[18px]"}),pe?t.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:q.label}),t.jsx("span",{className:Q("block truncate typography-small",pe&&!ke?"text-[var(--status-success)]":"text-muted-foreground"),children:Y})]}),ke?t.jsx(Z,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[oe?t.jsxs("button",{type:"button","aria-label":s("mobile.instances.confirmDeleteAria",{label:q.label}),className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>ce(q.id),style:{touchAction:"manipulation"},children:[t.jsx(Z,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:s("mobile.instances.delete")})]}):q.candidates.some(de=>de.kind==="direct")?t.jsx("button",{type:"button","aria-label":s("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>{x(q.id),y(ct(q)),C(q.label),k(q.clientToken||""),b(null)},style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":oe?s("mobile.instances.cancelDeleteAria",{label:q.label}):s("mobile.instances.deleteAria",{label:q.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>re(q.id),style:{touchAction:"manipulation"},children:t.jsx(Z,{name:oe?"close":"delete-bin",className:"size-[18px]"})})]})]},q.id)})}):t.jsx("p",{..._,className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:s("mobile.connect.saved.empty")}),!U&&!E?t.jsxs("div",{className:"space-y-2",children:[B?t.jsxs(ge,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{H()},disabled:M,children:[t.jsx(Z,{name:"scan-2",className:Q("size-[18px]",M&&"animate-pulse")}),s("mobile.connect.scanQr")]}):null,t.jsxs(ge,{type:"button",variant:B?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{b(null),O(!0)},children:[t.jsx(Z,{name:"add",className:"size-[18px]"}),s("mobile.instances.addManual")]}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:J,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:s(E?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(ge,{type:"button",variant:"ghost",size:"xs",onClick:G,children:s("mobile.instances.cancelEdit")})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.url.label")}),t.jsx("input",{...Bt,value:A,onChange:q=>y(q.target.value),placeholder:s("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:ue})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.instances.label.label")}),t.jsx("input",{value:P,onChange:q=>C(q.target.value),placeholder:s("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:ue})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.token.label")}),t.jsx("input",{...Bt,value:R,onChange:q=>k(q.target.value),placeholder:s("mobile.connect.token.placeholder"),autoCapitalize:"none",className:ue}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")})]}),c?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:s(E?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})]})},Me=n=>xo(n)??"",fn=n=>{const e=Me(n);if(!e)return"";const s=e.split("/").filter(Boolean);return s[s.length-1]?.replace(/[-_]/g," ")||e},Br=qn(n=>({expandedParents:{},toggleParent:e=>n(s=>{const i={...s.expandedParents};return i[e]?delete i[e]:i[e]=!0,{expandedParents:i}})})),Is=qn()(Si(n=>({projectExpanded:{},worktreeExpanded:{},setProjectExpanded:(e,s)=>n(i=>({projectExpanded:{...i.projectExpanded,[e]:s}})),setWorktreeExpanded:(e,s)=>n(i=>({worktreeExpanded:{...i.worktreeExpanded,[e]:s}}))}),{name:"mobile-session-tree"})),jn=qn()(Si(n=>({orderByProject:{},setWorktreeOrder:(e,s)=>n(i=>({orderByProject:{...i.orderByProject,[e]:s}}))}),{name:"mobile-worktree-order"})),Lr=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Pu=(n,e)=>{if(!n||n.length===0)return e;const s=new Map(n.map((r,o)=>[Lr(r),o])),i=r=>s.get(Lr(r.path))??Number.MAX_SAFE_INTEGER;return e.map((r,o)=>({worktree:r,index:o})).sort((r,o)=>{const a=i(r.worktree)-i(o.worktree);return a!==0?a:r.index-o.index}).map(r=>r.worktree)},ls=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Au=n=>{const e=n;return ls(e.directory??e.project?.worktree??null)},Ki=({open:n,project:e,worktree:s,onClose:i,onDeleted:r})=>{const{t:o}=me(),a=ui(),c=Nn(k=>k.activeSessions),f=Se(k=>k.archiveSessions),d=gt(k=>k.currentDirectory),[l,p]=u.useState(!1),[g,h]=u.useState(!1),[b,S]=u.useState(!1),[x,E]=u.useState(!1),v=ls(s?.path),N=typeof s?.branch=="string"&&s.branch.trim().length>0,A=u.useMemo(()=>{if(!v)return[];const k=new Map;for(const z of[...c,...a])Au(z)===v&&k.set(z.id,z);return Array.from(k.values())},[c,a,v]);u.useEffect(()=>{if(!n){p(!1),h(!1),S(!1),E(!1);return}if(!s?.path)return;let k=!1;return Lo(s.path).then(z=>{k||S(!!z?.isDirty)}).catch(()=>{k||S(!!s.status?.isDirty)}),()=>{k=!0}},[n,s?.path,s?.status?.isDirty]);const y=u.useCallback((k,z)=>{const D=$o(k),M=fe.loading(o("sessions.sidebar.sessionDialogs.worktree.removingTitle",{name:D}));(async()=>{try{if(z.length>0){const{failedIds:j}=await f(z);if(j.length>0){fe.error(j.length===1?o("sessions.sidebar.bulkActions.failedArchiveSingle",{count:j.length}):o("sessions.sidebar.bulkActions.failedArchivePlural",{count:j.length}),{id:M,description:o("sessions.sidebar.dialogs.deleteResult.tryAgain")});return}}await Fo(e,k,{deleteRemoteBranch:N&&g,deleteLocalBranch:N&&l}),ls(d)===v&&ls(e.path)&&gt.getState().setDirectory(ls(e.path),{showOverlay:!1}),fe.success(o("sessions.sidebar.sessionDialogs.worktree.removedTitle",{name:D}),{id:M,description:o(N&&g?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),r?.()}catch(j){fe.error(o("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle",{name:D}),{id:M,description:j instanceof Error?j.message:o("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[f,d,l,g,N,r,e,o,v]),P=()=>{!s||x||(E(!0),y(s,A.map(k=>k.id)),i())};if(!s)return null;const C=s.branch||s.label||s.path,R=(k,z,D,M)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":k,disabled:M,onClick:()=>z(!k),className:Q("flex w-full items-center justify-between gap-3 rounded-xl border border-border/70 px-3.5 py-3 text-left transition-colors","hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",M&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:D}),t.jsx("span",{className:Q("relative h-6 w-10 shrink-0 rounded-full transition-colors",k?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:Q("absolute top-0.5 size-5 rounded-full bg-white transition-transform",k?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(di,{open:n,onClose:i,title:o("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ge,{variant:"ghost",className:"flex-1",onClick:i,disabled:x,children:o("projectEditDialog.actions.cancel")}),t.jsx(ge,{variant:"destructive",className:"flex-1",onClick:()=>{P()},disabled:x,children:o("mobile.projectEdit.deleteWorktreeConfirmButton")})]}),children:t.jsxs("div",{className:"flex flex-col gap-4 px-1 py-1",children:[t.jsx("p",{className:"typography-ui-body text-foreground",children:o("mobile.projectEdit.deleteWorktreeConfirm",{name:C})}),b?t.jsx("p",{className:"rounded-xl border border-[var(--warning)]/40 bg-[color-mix(in_srgb,var(--warning)_10%,transparent)] px-3.5 py-3 typography-meta text-foreground",children:o("mobile.projectEdit.deleteWorktreeDirty")}):null,A.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o("mobile.projectEdit.deleteWorktreeArchiveNote",{count:A.length})}):null,N?t.jsxs("div",{className:"flex flex-col gap-2",children:[R(l,p,o("mobile.projectEdit.deleteLocalBranch"),x),R(g,h,o("mobile.projectEdit.deleteRemoteBranch"),x)]}):null]})})},Us=n=>{const e=le.c(18),{project:s,size:i}=n,r=i===void 0?"md":i,{currentTheme:o}=fi(),a=s.icon?mi[s.icon]:null,c=s.color?pi[s.color]??null:null,f=r==="sm"?"size-6 rounded-md":"size-8 rounded-lg",d=r==="sm"?"size-3.5":"size-4";let l;e[0]!==a||e[1]!==c||e[2]!==d?(l=a?t.jsx(Z,{name:a,className:d,style:c?{color:c}:void 0}):t.jsx(xn,{className:d,style:c?{color:c}:void 0}),e[0]=a,e[1]=c,e[2]=d,e[3]=l):l=e[3];const p=l,g=r==="md"&&"bg-[var(--surface-muted)]";let h;e[4]!==f||e[5]!==g?(h=Q("flex shrink-0 items-center justify-center overflow-hidden text-muted-foreground",g,f),e[4]=f,e[5]=g,e[6]=h):h=e[6];let b;e[7]!==s.iconBackground?(b=s.iconBackground?{backgroundColor:s.iconBackground}:void 0,e[7]=s.iconBackground,e[8]=b):b=e[8];let S;e[9]!==o||e[10]!==p||e[11]!==s.iconImage||e[12]!==s.id?(S=s.iconImage?t.jsx(hi,{project:{id:s.id,iconImage:s.iconImage??null},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:p}):p,e[9]=o,e[10]=p,e[11]=s.iconImage,e[12]=s.id,e[13]=S):S=e[13];let x;return e[14]!==h||e[15]!==b||e[16]!==S?(x=t.jsx("span",{className:h,style:b,children:S}),e[14]=h,e[15]=b,e[16]=S,e[17]=x):x=e[17],x},Hi=n=>{const e=le.c(44),{initialTitle:s,indent:i,className:r,onSubmit:o,onCancel:a}=n,{t:c}=me(),[f,d]=u.useState(s),l=Iu;let p;e[0]!==s||e[1]!==a||e[2]!==o||e[3]!==f?(p=()=>{const $=f.trim();if(!$||$===s.trim()){a();return}o($)},e[0]=s,e[1]=a,e[2]=o,e[3]=f,e[4]=p):p=e[4];const g=p;let h;e[5]!==r?(h=Q("flex h-9 min-w-0 flex-1 items-center gap-2 pr-2",r),e[5]=r,e[6]=h):h=e[6];let b;e[7]!==i?(b={paddingLeft:i},e[7]=i,e[8]=b):b=e[8];let S;e[9]!==g?(S=$=>{$.preventDefault(),g()},e[9]=g,e[10]=S):S=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=$=>d($.target.value),e[11]=x):x=e[11];let E;e[12]!==a?(E=$=>nl($,a),e[12]=a,e[13]=E):E=e[13];let v;e[14]!==c?(v=c("sessions.sidebar.session.rename.save"),e[14]=c,e[15]=v):v=e[15];let N;e[16]!==c?(N=c("sessions.sidebar.session.menu.rename"),e[16]=c,e[17]=N):N=e[17];let A;e[18]===Symbol.for("react.memo_cache_sentinel")?(A={minHeight:0},e[18]=A):A=e[18];let y;e[19]!==E||e[20]!==v||e[21]!==N||e[22]!==f?(y=t.jsx("input",{ref:l,value:f,onChange:x,onKeyDown:E,"aria-label":v,placeholder:N,className:"min-w-0 flex-1 bg-transparent text-[16px] typography-ui-label text-foreground outline-none placeholder:text-muted-foreground",style:A,enterKeyHint:"done"}),e[19]=E,e[20]=v,e[21]=N,e[22]=f,e[23]=y):y=e[23];let P;e[24]!==c?(P=c("sessions.sidebar.session.rename.save"),e[24]=c,e[25]=P):P=e[25];let C,R;e[26]===Symbol.for("react.memo_cache_sentinel")?(C={touchAction:"manipulation",minHeight:0,minWidth:0},R=t.jsx(Z,{name:"check",className:"size-4"}),e[26]=C,e[27]=R):(C=e[26],R=e[27]);let k;e[28]!==P?(k=t.jsx("button",{type:"submit","aria-label":P,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:C,children:R}),e[28]=P,e[29]=k):k=e[29];let z;e[30]!==c?(z=c("sessions.sidebar.session.rename.cancel"),e[30]=c,e[31]=z):z=e[31];let D,M;e[32]===Symbol.for("react.memo_cache_sentinel")?(D={touchAction:"manipulation",minHeight:0,minWidth:0},M=t.jsx(Z,{name:"close",className:"size-4"}),e[32]=D,e[33]=M):(D=e[32],M=e[33]);let j;e[34]!==a||e[35]!==z?(j=t.jsx("button",{type:"button",onClick:a,"aria-label":z,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:D,children:M}),e[34]=a,e[35]=z,e[36]=j):j=e[36];let I;return e[37]!==y||e[38]!==k||e[39]!==j||e[40]!==h||e[41]!==b||e[42]!==S?(I=t.jsxs("form",{className:h,style:b,onSubmit:S,children:[y,k,j]}),e[37]=y,e[38]=k,e[39]=j,e[40]=h,e[41]=b,e[42]=S,e[43]=I):I=e[43],I};function Iu(n){n&&(n.focus(),n.select())}const qi=192,Tu=180,Gs=n=>{const e=le.c(27),{actionsWidth:s,actions:i,revealed:r,onRevealedChange:o,dataActiveSession:a,contentClassName:c,children:f}=n,d=c===void 0?"relative flex w-full items-center bg-background":c,l=u.useRef(null),p=u.useRef(null),g=u.useRef(!1),h=u.useRef(0),b=u.useRef(r);let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S=(w,B)=>{const U=l.current;U&&(U.style.transition=B?`transform ${Tu}ms ease-out`:"none",U.style.transform=w===0?"none":`translateX(${w}px)`,h.current=w)},e[0]=S):S=e[0];const x=S;let E,v;e[1]!==s||e[2]!==r?(E=()=>{b.current=r,x(r?s:0,!0)},v=[s,x,r],e[1]=s,e[2]=r,e[3]=E,e[4]=v):(E=e[3],v=e[4]),u.useEffect(E,v);let N;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=w=>{if(w.touches.length!==1)return;const B=w.touches[0];p.current={x:B.clientX,y:B.clientY},g.current=!1},e[5]=N):N=e[5];const A=N;let y;e[6]!==s?(y=w=>{if(!p.current)return;const B=w.touches[0],U=B.clientX-p.current.x,O=B.clientY-p.current.y;if(!g.current){if(Math.abs(U)<8||Math.abs(U)<=Math.abs(O))return;g.current=!0}const L=b.current?s:0;x(Math.max(0,Math.min(s,L+U)),!1)},e[6]=s,e[7]=y):y=e[7];const P=y;let C;e[8]!==s||e[9]!==o?(C=()=>{if(p.current=null,!g.current)return;g.current=!1;const w=h.current>s/2;x(w?s:0,!0),w!==b.current&&o(w)},e[8]=s,e[9]=o,e[10]=C):C=e[10];const R=C,k=a||void 0;let z;e[11]===Symbol.for("react.memo_cache_sentinel")?(z={touchAction:"pan-y"},e[11]=z):z=e[11];let D;e[12]!==s?(D={width:s},e[12]=s,e[13]=D):D=e[13];const M=!r;let j;e[14]!==i||e[15]!==D||e[16]!==M?(j=t.jsx("div",{className:"absolute inset-y-0 left-0 flex items-stretch",style:D,"aria-hidden":M,children:i}),e[14]=i,e[15]=D,e[16]=M,e[17]=j):j=e[17];let I;e[18]!==f||e[19]!==d?(I=t.jsx("div",{ref:l,className:d,children:f}),e[18]=f,e[19]=d,e[20]=I):I=e[20];let $;return e[21]!==R||e[22]!==P||e[23]!==j||e[24]!==I||e[25]!==k?($=t.jsxs("div",{"data-active-session":k,className:"relative overflow-hidden",onTouchStart:A,onTouchMove:P,onTouchEnd:R,onTouchCancel:R,style:z,children:[j,I]}),e[21]=R,e[22]=P,e[23]=j,e[24]=I,e[25]=k,e[26]=$):$=e[26],$},Ji=n=>{const e=le.c(52),{title:s,revealed:i,confirmingDelete:r,aiRename:o,onArchive:a,onRequestDelete:c,onConfirmDelete:f,onRequestRename:d,onRevealedChange:l}=n,{t:p}=me(),g=i?0:-1,h=r?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80";let b;e[0]!==h?(b=Q("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",h),e[0]=h,e[1]=b):b=e[1];let S;e[2]!==r||e[3]!==p||e[4]!==s?(S=r?p("mobile.sessions.confirmDeleteSessionAria",{title:s}):p("mobile.sessions.deleteSessionAria",{title:s}),e[2]=r,e[3]=p,e[4]=s,e[5]=S):S=e[5];const x=r?f:c;let E,v;e[6]===Symbol.for("react.memo_cache_sentinel")?(E={touchAction:"manipulation"},v=t.jsx(Bs,{className:"size-[18px]"}),e[6]=E,e[7]=v):(E=e[6],v=e[7]);let N;e[8]!==b||e[9]!==S||e[10]!==x||e[11]!==g?(N=t.jsx("button",{type:"button",tabIndex:g,className:b,"aria-label":S,onClick:x,style:E,children:v}),e[8]=b,e[9]=S,e[10]=x,e[11]=g,e[12]=N):N=e[12];let A;e[13]!==p||e[14]!==s?(A=p("mobile.sessions.archiveSessionAria",{title:s}),e[13]=p,e[14]=s,e[15]=A):A=e[15];let y,P;e[16]===Symbol.for("react.memo_cache_sentinel")?(P={touchAction:"manipulation"},y=t.jsx($l,{className:"size-[18px]"}),e[16]=y,e[17]=P):(y=e[16],P=e[17]);let C;e[18]!==a||e[19]!==A||e[20]!==g?(C=t.jsx("button",{type:"button",tabIndex:g,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":A,onClick:a,style:P,children:y}),e[18]=a,e[19]=A,e[20]=g,e[21]=C):C=e[21];let R;e[22]!==p||e[23]!==s?(R=p("mobile.sessions.renameSessionAria",{title:s}),e[22]=p,e[23]=s,e[24]=R):R=e[24];let k,z;e[25]===Symbol.for("react.memo_cache_sentinel")?(k={touchAction:"manipulation"},z=t.jsx(yn,{className:"size-[18px]"}),e[25]=k,e[26]=z):(k=e[25],z=e[26]);let D;e[27]!==d||e[28]!==R||e[29]!==g?(D=t.jsx("button",{type:"button",tabIndex:g,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":R,onClick:d,style:k,children:z}),e[27]=d,e[28]=R,e[29]=g,e[30]=D):D=e[30];const M=o.disabled;let j;e[31]!==p?(j=p("sessions.aiRename.action"),e[31]=p,e[32]=j):j=e[32];let I;e[33]!==o||e[34]!==l?(I=()=>{o.run(),l?.(!1)},e[33]=o,e[34]=l,e[35]=I):I=e[35];let $;e[36]===Symbol.for("react.memo_cache_sentinel")?($={touchAction:"manipulation"},e[36]=$):$=e[36];const w=o.pending?"loader-4":"ai-generate-2",B=o.pending?"size-[18px] animate-spin":"size-[18px]";let U;e[37]!==w||e[38]!==B?(U=t.jsx(Z,{name:w,className:B}),e[37]=w,e[38]=B,e[39]=U):U=e[39];let O;e[40]!==o.disabled||e[41]!==o.hint||e[42]!==j||e[43]!==I||e[44]!==U||e[45]!==g?(O=t.jsx(ge,{variant:"ghost",size:"icon",tabIndex:g,className:"flex-1 self-center text-muted-foreground",disabled:M,"aria-label":j,"aria-description":o.hint,title:o.hint,onClick:I,style:$,children:U}),e[40]=o.disabled,e[41]=o.hint,e[42]=j,e[43]=I,e[44]=U,e[45]=g,e[46]=O):O=e[46];let L;return e[47]!==C||e[48]!==D||e[49]!==O||e[50]!==N?(L=t.jsxs(t.Fragment,{children:[N,C,D,O]}),e[47]=C,e[48]=D,e[49]=O,e[50]=N,e[51]=L):L=e[51],L},ht=n=>n.parentID??null,kn=n=>{const e=n;return Me(e.directory??e.project?.worktree??null)},Yi=n=>{const e=n.time?.updated??n.time?.created,s=typeof e=="number"?e:Number(e);return Number.isFinite(s)&&s>0?s:0},Qi=n=>{if(n<=0)return"";const e=Date.now()-n;if(e<6e4)return"now";const s=Math.floor(e/6e4);if(s<60)return`${s}m`;const i=Math.floor(s/60);if(i<24)return`${i}h`;const r=Math.floor(i/24);return r<7?`${r}d`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(n))},$r=12,Du=n=>{const e=le.c(83),{entry:s,active:i,revealed:r,confirmingDelete:o,renaming:a,handlers:c}=n,{t:f}=me(),{session:d,project:l,branch:p}=s;let g;e[0]!==d.title||e[1]!==f?(g=d.title?.trim()||f("mobile.sessions.untitled"),e[0]=d.title,e[1]=f,e[2]=g):g=e[2];const h=g;let b;e[3]!==d?(b=Qi(Yi(d)),e[3]=d,e[4]=b):b=e[4];const S=b,x=ji(d.id,d.directory,r),E=En(d.id),v=Pn(d.id),N=!v&&E>0&&!i,A=An(d.id,v),y=(v||N)&&A;let P;e[5]!==c||e[6]!==d.id?(P=B=>c.onRevealedChange(d.id,B),e[5]=c,e[6]=d.id,e[7]=P):P=e[7];const C=i&&"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]";let R;e[8]!==C?(R=Q("relative flex w-full items-center bg-background transition-colors",C),e[8]=C,e[9]=R):R=e[9];let k;e[10]!==c||e[11]!==d?(k=()=>c.onArchive(d),e[10]=c,e[11]=d,e[12]=k):k=e[12];let z;e[13]!==c||e[14]!==d.id?(z=()=>c.onRequestDelete(d.id),e[13]=c,e[14]=d.id,e[15]=z):z=e[15];let D;e[16]!==c||e[17]!==d?(D=()=>c.onConfirmDelete(d),e[16]=c,e[17]=d,e[18]=D):D=e[18];let M,j;e[19]!==c||e[20]!==d.id?(j=()=>c.onRequestRename(d.id),M=B=>c.onRevealedChange(d.id,B),e[19]=c,e[20]=d.id,e[21]=M,e[22]=j):(M=e[21],j=e[22]);let I;e[23]!==x||e[24]!==o||e[25]!==r||e[26]!==M||e[27]!==k||e[28]!==z||e[29]!==D||e[30]!==j||e[31]!==h?(I=t.jsx(Ji,{title:h,revealed:r,confirmingDelete:o,aiRename:x,onArchive:k,onRequestDelete:z,onConfirmDelete:D,onRequestRename:j,onRevealedChange:M}),e[23]=x,e[24]=o,e[25]=r,e[26]=M,e[27]=k,e[28]=z,e[29]=D,e[30]=j,e[31]=h,e[32]=I):I=e[32];let $;e:{let B;e[33]!==l?(B=t.jsx(Us,{project:l,size:"sm"}),e[33]=l,e[34]=B):B=e[34];let U;e[35]!==l.label?(U=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-micro text-muted-foreground",children:l.label}),e[35]=l.label,e[36]=U):U=e[36];let O;e[37]!==x.pending||e[38]!==v||e[39]!==N||e[40]!==f?(O=x.pending?t.jsx(Z,{name:"loader-4",className:"size-3 shrink-0 animate-spin text-primary","aria-label":f("sessions.aiRename.generating")}):v||N?t.jsx(Os,{state:v?"running":"unread",label:f(v?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread")}):null,e[37]=x.pending,e[38]=v,e[39]=N,e[40]=f,e[41]=O):O=e[41];let L;e[42]!==v||e[43]!==d.id||e[44]!==y||e[45]!==S?(L=y?t.jsx(Mn,{sessionId:d.id,running:v,className:"shrink-0 typography-micro"}):S?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:S}):null,e[42]=v,e[43]=d.id,e[44]=y,e[45]=S,e[46]=L):L=e[46];let ie;e[47]!==B||e[48]!==U||e[49]!==O||e[50]!==L?(ie=t.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[B,U,O,L]}),e[47]=B,e[48]=U,e[49]=O,e[50]=L,e[51]=ie):ie=e[51];let ee;e[52]!==i||e[53]!==c||e[54]!==a||e[55]!==d.id||e[56]!==h?(ee=a?t.jsx(Hi,{initialTitle:h,indent:0,className:"h-[1lh] pr-0 typography-ui-label [&_button]:size-6 [&_button>svg]:size-3.5",onSubmit:re=>c.onSubmitRename(d.id,re),onCancel:c.onCancelRename}):t.jsx("span",{className:Q("block min-w-0 truncate typography-ui-label",i?"text-primary":"text-foreground"),children:h}),e[52]=i,e[53]=c,e[54]=a,e[55]=d.id,e[56]=h,e[57]=ee):ee=e[57];let W;e[58]!==p?(W=p?t.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[t.jsx(Z,{name:"git-branch",className:"size-3.5 shrink-0"}),t.jsx("span",{className:"block min-w-0 truncate typography-micro",children:p})]}):null,e[58]=p,e[59]=W):W=e[59];let _;e[60]!==ie||e[61]!==ee||e[62]!==W?(_=t.jsxs(t.Fragment,{children:[ie,ee,W]}),e[60]=ie,e[61]=ee,e[62]=W,e[63]=_):_=e[63];const G=_;if(a){let re;e[64]===Symbol.for("react.memo_cache_sentinel")?(re={paddingLeft:$r},e[64]=re):re=e[64];let ce;e[65]!==G?(ce=t.jsx("div",{className:"flex min-w-0 flex-1 flex-col gap-1 py-2.5 pr-3 text-left",style:re,children:G}),e[65]=G,e[66]=ce):ce=e[66],$=ce;break e}let J,H;e[67]===Symbol.for("react.memo_cache_sentinel")?(J=Q("flex min-w-0 flex-1 flex-col gap-1 py-2.5 pr-3 text-left","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"),H={paddingLeft:$r,touchAction:"manipulation"},e[67]=J,e[68]=H):(J=e[67],H=e[68]);let X;e[69]!==c||e[70]!==r||e[71]!==d?(X=()=>{if(r){c.onRevealedChange(d.id,!1);return}c.onSelect(d)},e[69]=c,e[70]=r,e[71]=d,e[72]=X):X=e[72];let ne;e[73]!==G||e[74]!==X?(ne=t.jsx("button",{type:"button",className:J,style:H,onClick:X,children:G}),e[73]=G,e[74]=X,e[75]=ne):ne=e[75],$=ne}let w;return e[76]!==i||e[77]!==r||e[78]!==I||e[79]!==$||e[80]!==P||e[81]!==R?(w=t.jsx(Gs,{actionsWidth:qi,revealed:r,onRevealedChange:P,dataActiveSession:i,contentClassName:R,actions:I,children:$}),e[76]=i,e[77]=r,e[78]=I,e[79]=$,e[80]=P,e[81]=R,e[82]=w):w=e[82],w},_u=n=>{const e=le.c(9),{scrollRootRef:s,visibleCount:i,onReachEnd:r}=n,o=u.useRef(null),a=u.useRef(r);let c,f;e[0]!==r?(c=()=>{a.current=r},f=[r],e[0]=r,e[1]=c,e[2]=f):(c=e[1],f=e[2]),u.useEffect(c,f);let d;e[3]!==s?(d=()=>{const g=o.current;if(!g)return;const h=new IntersectionObserver(b=>{b.some(zu)&&a.current()},{root:s.current??null,rootMargin:"400px 0px"});return h.observe(g),()=>h.disconnect()},e[3]=s,e[4]=d):d=e[4];let l;e[5]!==s||e[6]!==i?(l=[s,i],e[5]=s,e[6]=i,e[7]=l):l=e[7],u.useEffect(d,l);let p;return e[8]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx("div",{ref:o,"aria-hidden":!0,className:"h-px w-full"}),e[8]=p):p=e[8],p},Mu=n=>{const e=le.c(35),{entries:s,visibleCount:i,onRevealMore:r,scrollRootRef:o,handlers:a}=n,{t:c}=me();let f,d,l,p,g;if(e[0]!==s||e[1]!==a||e[2]!==c||e[3]!==i){g=s.slice(0,i),l="border-t border-border/70";let x;e[9]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:t.jsx(Z,{name:"folder-6",className:"size-4"})}),e[9]=x):x=e[9];let E;e[10]!==c?(E=c("mobile.sessions.section.projects"),e[10]=c,e[11]=E):E=e[11];let v;e[12]!==E?(v=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:E}),e[12]=E,e[13]=v):v=e[13];let N;e[14]!==s.length?(N=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:s.length}),e[14]=s.length,e[15]=N):N=e[15],e[16]!==v||e[17]!==N?(p=t.jsxs("div",{className:"flex min-h-12 w-full items-center gap-2 px-3 py-1.5",children:[x,v,N]}),e[16]=v,e[17]=N,e[18]=p):p=e[18],f="pb-2";let A;e[19]!==a?(A=y=>t.jsx(Du,{entry:y,active:a.currentSessionId===y.session.id,revealed:a.revealedSessionId===y.session.id,confirmingDelete:a.confirmingDeleteSessionId===y.session.id,renaming:a.renamingSessionId===y.session.id,handlers:a},y.session.id),e[19]=a,e[20]=A):A=e[20],d=g.map(A),e[0]=s,e[1]=a,e[2]=c,e[3]=i,e[4]=f,e[5]=d,e[6]=l,e[7]=p,e[8]=g}else f=e[4],d=e[5],l=e[6],p=e[7],g=e[8];let h;e[21]!==s.length||e[22]!==r||e[23]!==o||e[24]!==i||e[25]!==g.length?(h=g.length<s.length?t.jsx(_u,{scrollRootRef:o,visibleCount:i,onReachEnd:r}):null,e[21]=s.length,e[22]=r,e[23]=o,e[24]=i,e[25]=g.length,e[26]=h):h=e[26];let b;e[27]!==f||e[28]!==d||e[29]!==h?(b=t.jsxs("div",{className:f,children:[d,h]}),e[27]=f,e[28]=d,e[29]=h,e[30]=b):b=e[30];let S;return e[31]!==l||e[32]!==p||e[33]!==b?(S=t.jsxs("section",{className:l,children:[p,b]}),e[31]=l,e[32]=p,e[33]=b,e[34]=S):S=e[34],S};function zu(n){return n.isIntersecting}const zs=40,Ou=(n,e)=>Math.min(e,Math.max(n,0)+zs),Fr="mobile-surface-root",mn=16,Ts=200,Bu=()=>{if(typeof document>"u")return null;let n=document.getElementById(Fr);return n||(n=document.createElement("div"),n.id=Fr,document.body.appendChild(n)),n},Tt=({open:n,onClose:e,title:s,subtitle:i,trailing:r,disableEscapeDismiss:o=!1,headerless:a=!1,noHeaderBorder:c=!1,ariaLabel:f,variant:d="fullscreen",dialogAlign:l="chat",children:p})=>{const{t:g}=me(),h=u.useRef(null),[b,S]=u.useState(!1),[x,E]=u.useState(!1),v=u.useRef(null),N=u.useRef(null),A=u.useRef(e);if(u.useEffect(()=>{A.current=e},[e]),typeof document<"u"&&!h.current&&(h.current=Bu()),u.useEffect(()=>{if(!n){S(!1);return}const C=window.setTimeout(()=>S(!0),mn);return()=>window.clearTimeout(C)},[n]),u.useEffect(()=>{if(!n){E(!1);return}const C=window.setTimeout(()=>E(!0),mn+Ts+80);return()=>window.clearTimeout(C)},[n]),u.useEffect(()=>{if(!n)return;const C=document.body.style.overflow;N.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const R=()=>{const D=v.current;if(!D)return;(D.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??D).focus({preventScroll:!0})},k=window.setTimeout(R,mn),z=D=>{if(D.key==="Escape"&&!o){A.current();return}if(D.key!=="Tab")return;const M=v.current;if(!M)return;const j=Array.from(M.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(B=>!B.hasAttribute("disabled")&&B.getAttribute("aria-hidden")!=="true");if(j.length===0){D.preventDefault(),M.focus({preventScroll:!0});return}const I=j[0],$=j[j.length-1],w=document.activeElement;D.shiftKey&&w===I?(D.preventDefault(),$.focus({preventScroll:!0})):!D.shiftKey&&w===$&&(D.preventDefault(),I.focus({preventScroll:!0}))};return document.addEventListener("keydown",z),()=>{window.clearTimeout(k),document.body.style.overflow=C,document.removeEventListener("keydown",z),N.current?.focus?.({preventScroll:!0}),N.current=null}},[o,n]),!n||!h.current)return null;const y=d==="dialog",P=t.jsxs("section",{ref:v,role:"dialog","aria-modal":"true","aria-label":f,tabIndex:-1,className:Q("flex flex-col bg-background text-foreground",y?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50"),style:y?{opacity:b?1:0,transform:b?"none":"scale(0.97)",transition:`opacity ${Ts}ms ease-out, transform ${Ts}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:b?"none":"translateX(100%)",transition:`transform ${Ts}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:C=>{b&&C.target===C.currentTarget&&C.propertyName==="transform"&&E(!0)},children:[a?null:t.jsxs("header",{className:Q("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!c&&"border-b border-border/70"),children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":g("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"close",className:"size-5"})}),t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[s?typeof s=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:s}):s:null,i?typeof i=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:i}):i:null]}),r?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:r}):null]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:x?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:p}):null}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return y?Lt.createPortal(t.jsx("div",{className:"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:b?1:0,paddingLeft:l==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:l==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:e,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:C=>C.stopPropagation(),children:P})}),h.current):Lt.createPortal(P,h.current)},Lu=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),$u=n=>{const e=le.c(36),{worktree:s,onDelete:i}=n,{t:r}=me();let o;e[0]!==s.path?(o={id:s.path},e[0]=s.path,e[1]=o):o=e[1];const{attributes:a,listeners:c,setNodeRef:f,transform:d,transition:l,isDragging:p}=Kn(o);let g;e[2]!==d?(g=Hn.Transform.toString(d),e[2]=d,e[3]=g):g=e[3];const h=p?10:1;let b;e[4]!==g||e[5]!==h||e[6]!==l?(b={transform:g,transition:l,zIndex:h},e[4]=g,e[5]=h,e[6]=l,e[7]=b):b=e[7];const S=b,x=s.branch||s.label||s.path,E=p&&"shadow-lg shadow-black/20";let v;e[8]!==E?(v=Q("flex items-center gap-1 rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",E),e[8]=E,e[9]=v):v=e[9];let N;e[10]!==x||e[11]!==r?(N=r("mobile.projectEdit.dragWorktreeAria",{label:x}),e[10]=x,e[11]=r,e[12]=N):N=e[12];let A;e[13]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(zn,{className:"size-4"}),e[13]=A):A=e[13];let y;e[14]!==a||e[15]!==c||e[16]!==N?(y=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":N,...a,...c,children:A}),e[14]=a,e[15]=c,e[16]=N,e[17]=y):y=e[17];let P;e[18]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(Z,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=P):P=e[18];let C;e[19]!==x?(C=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:x}),e[19]=x,e[20]=C):C=e[20];let R;e[21]!==x||e[22]!==r?(R=r("mobile.projectEdit.deleteWorktreeAria",{label:x}),e[21]=x,e[22]=r,e[23]=R):R=e[23];let k,z;e[24]===Symbol.for("react.memo_cache_sentinel")?(k={touchAction:"manipulation"},z=t.jsx(Bs,{className:"size-4"}),e[24]=k,e[25]=z):(k=e[24],z=e[25]);let D;e[26]!==i||e[27]!==R?(D=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":R,onClick:i,style:k,children:z}),e[26]=i,e[27]=R,e[28]=D):D=e[28];let M;return e[29]!==f||e[30]!==S||e[31]!==C||e[32]!==D||e[33]!==v||e[34]!==y?(M=t.jsxs("div",{ref:f,style:S,className:v,children:[y,P,C,D]}),e[29]=f,e[30]=S,e[31]=C,e[32]=D,e[33]=v,e[34]=y,e[35]=M):M=e[35],M},Fu=({open:n,project:e,onClose:s,onWorktreesChanged:i})=>{const{t:r}=me(),{currentTheme:o}=fi(),a=We(w=>w.updateProjectMeta),c=We(w=>w.discoverProjectIcon),f=We(w=>w.removeProjectIcon),d=jn(w=>w.setWorktreeOrder),l=We(w=>e?w.projects.find(B=>B.id===e.id)?.iconImage??null:null),[p,g]=u.useState(""),[h,b]=u.useState(null),[S,x]=u.useState(null),[E,v]=u.useState(!1),[N,A]=u.useState([]),[y,P]=u.useState(null),C=e?.id??null;u.useEffect(()=>{!n||!e||(g(e.label),b(e.icon??null),x(e.color??null),A(e.worktrees))},[n,C]),u.useEffect(()=>{!n||!e||A(w=>{const B=e.worktrees.map(L=>L.path),U=w.map(L=>L.path);return B.length===U.length&&B.every(L=>U.includes(L))?w:e.worktrees})},[e?.worktrees]);const R=Bn(Ft($n,{activationConstraint:{distance:8}}),Ft(Ln,{coordinateGetter:Vn})),k=()=>{if(!e)return;const w=p.trim();a(e.id,{label:w||e.label,icon:h,color:S}),s()},z=()=>{!e||E||(v(!0),c(e.id).then(w=>{if(!w.ok){fe.error(w.error||r("projectEditDialog.toast.failedToDiscoverIcon"));return}if(w.skipped){fe.success(r("projectEditDialog.toast.customIconAlreadySet"));return}fe.success(r("projectEditDialog.toast.iconDiscovered"))}).finally(()=>v(!1)))},D=()=>{e&&f(e.id).then(w=>{if(!w.ok){fe.error(w.error||r("projectEditDialog.toast.failedToRemoveIcon"));return}fe.success(r("projectEditDialog.toast.iconRemoved"))})},M=w=>{const{active:B,over:U}=w;if(!U||B.id===U.id||!e)return;const O=N.findIndex(W=>W.path===B.id),L=N.findIndex(W=>W.path===U.id);if(O<0||L<0)return;const ie=[...N],[ee]=ie.splice(O,1);ie.splice(L,0,ee),A(ie),d(e.id,ie.map(W=>Lu(W.path)))},j=S?pi[S]??null:null,I=h?mi[h]:null,$=!!l;return t.jsxs(t.Fragment,{children:[t.jsx(Tt,{open:n,onClose:s,title:r("projectEditDialog.title"),ariaLabel:r("projectEditDialog.title"),noHeaderBorder:!0,trailing:t.jsxs(ge,{type:"button",variant:"default",size:"sm","aria-label":r("projectEditDialog.actions.save"),onClick:k,disabled:!p.trim(),style:{touchAction:"manipulation"},children:[t.jsx(ki,{className:"size-4"}),r("projectEditDialog.actions.save")]}),children:e?t.jsxs("div",{className:"h-full space-y-6 overflow-y-auto px-4 pb-8 pt-2",children:[t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx("span",{className:"flex size-16 items-center justify-center overflow-hidden rounded-2xl bg-[var(--surface-muted)] text-muted-foreground",style:e.iconBackground?{backgroundColor:e.iconBackground}:void 0,children:$?t.jsx(hi,{project:{id:e.id,iconImage:l},options:{themeVariant:o.metadata.variant,iconColor:o.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(xn,{className:"size-7"})}):I?t.jsx(Z,{name:I,className:"size-7",style:j?{color:j}:void 0}):t.jsx(xn,{className:"size-7",style:j?{color:j}:void 0})})}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.name")}),t.jsx(gi,{value:p,onChange:w=>g(w.target.value),placeholder:r("projectEditDialog.field.namePlaceholder"),className:"h-11"}),t.jsx("p",{className:"truncate typography-meta text-muted-foreground",title:e.path,children:e.path})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.color")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>x(null),"aria-label":r("projectEditDialog.option.none"),className:Q("flex size-9 items-center justify-center rounded-xl border-2 transition-all",S===null?"border-foreground":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),Wo.map(w=>t.jsx("button",{type:"button",onClick:()=>x(w.key),"aria-label":w.label,title:w.label,className:Q("size-9 rounded-xl border-2 transition-all",S===w.key?"border-foreground":"border-transparent hover:border-border/70"),style:{backgroundColor:w.cssVar,touchAction:"manipulation"}},w.key))]})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.icon")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>b(null),"aria-label":r("projectEditDialog.option.none"),className:Q("flex size-9 items-center justify-center rounded-xl border-2 transition-all",h===null?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),Vo.map(w=>t.jsx("button",{type:"button",onClick:()=>b(w.key),"aria-label":w.label,title:w.label,className:Q("flex size-9 items-center justify-center rounded-xl border-2 transition-all",h===w.key?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx(Z,{name:w.Icon,className:"size-4",style:j?{color:j}:void 0})},w.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(ge,{size:"sm",variant:"outline",onClick:z,disabled:E,children:r(E?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),$?t.jsx(ge,{size:"sm",variant:"outline",onClick:D,children:r("projectEditDialog.actions.removeProjectIcon")}):null]})]}),e.isGitRepo?t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("mobile.projectEdit.worktreesTitle")}),N.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.worktreesEmpty")}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.reorderHint")}),t.jsx(Fn,{sensors:R,collisionDetection:Wn,onDragEnd:M,children:t.jsx(Un,{items:N.map(w=>w.path),strategy:Gn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:N.map(w=>t.jsx($u,{worktree:w,onDelete:()=>P(w)},w.path))})})})]})]}):null]}):null}),e?t.jsx(Ki,{open:!!y,project:{id:e.id,path:e.path},worktree:y,onClose:()=>P(null),onDeleted:()=>{A(w=>w.filter(B=>B.path!==y?.path)),i?.()}}):null]})},Wu=32,Vu=80,Uu=64,Gu=.7,sr=(n,e)=>{const s=u.useRef(e);s.current=e;const i=e.enabled??!0;u.useEffect(()=>{if(!i)return;const r=n.current;if(!r)return;const a=window.Capacitor?.getPlatform?.()==="android"?Vu:Wu,c=r.ownerDocument;let f=!1,d=!1,l=0,p=0;const g=()=>c.getSelection()?.isCollapsed===!1,h=()=>{f=!1},b=()=>{f&&g()&&h()},S=E=>{if(E.touches.length!==1||g()){f=!1;return}const v=E.touches[0],N=r.clientWidth,A=v.clientX<=a,y=v.clientX>=N-a;f=A||y,d=A,l=v.clientX,p=v.clientY},x=E=>{if(!f||(f=!1,g()))return;const v=E.changedTouches[0];if(!v)return;const N=v.clientX-l,A=v.clientY-p;Math.abs(N)<Uu||Math.abs(A)>Math.abs(N)*Gu||d&&N<=0||!d&&N>=0||(d?s.current.onLeftEdgeSwipe?.():s.current.onRightEdgeSwipe?.())};return r.addEventListener("touchstart",S,{passive:!0}),r.addEventListener("touchend",x,{passive:!0}),r.addEventListener("touchcancel",h,{passive:!0}),r.addEventListener("selectstart",h),c.addEventListener("selectionchange",b),()=>{r.removeEventListener("touchstart",S),r.removeEventListener("touchend",x),r.removeEventListener("touchcancel",h),r.removeEventListener("selectstart",h),c.removeEventListener("selectionchange",b)}},[i,n])},Ku=new Set,Hu=[["manual","sessions.sidebar.header.projectSort.manual"],["a-z","sessions.sidebar.header.projectSort.aToZ"],["z-a","sessions.sidebar.header.projectSort.zToA"],["date-added","sessions.sidebar.header.projectSort.dateAdded"],["recent","sessions.sidebar.header.projectSort.recent"]],qu=[["projects","mobile.sessions.viewMode.projects"],["timeline","mobile.sessions.viewMode.timeline"]],Ju=7,Yu=3,Ds=40,Qu=12,Xu=16,Zu=(n,e)=>{const s=Me(n),i=Me(e),r=i.endsWith("/")?i:`${i}/`;return!!(s&&i&&(s===i||s.startsWith(r)))},pn=(n,e)=>n.worktrees.find(s=>Me(s.path)===e)??null,hn=(n,e,s)=>bi([n.title,n.id,kn(n),e],s),ed=n=>{const e=le.c(2),{ariaLabel:s}=n;let i;return e[0]!==s?(i=t.jsx("span",{className:"inline-block size-1.5 shrink-0 rounded-full bg-primary","aria-label":s}),e[0]=s,e[1]=i):i=e[1],i},Wr=n=>{const e=le.c(12),{onClick:s,className:i}=n,{t:r}=me();let o;e[0]!==r?(o=r("sessions.sidebar.project.actions.newWorktree"),e[0]=r,e[1]=o):o=e[1];const a=o;let c;e[2]!==i?(c=Q("flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",i),e[2]=i,e[3]=c):c=e[3];let f;e[4]!==s?(f=g=>{g.stopPropagation(),s()},e[4]=s,e[5]=f):f=e[5];let d,l;e[6]===Symbol.for("react.memo_cache_sentinel")?(d={touchAction:"manipulation"},l=t.jsx(Z,{name:"node-tree",className:"size-4"}),e[6]=d,e[7]=l):(d=e[6],l=e[7]);let p;return e[8]!==a||e[9]!==c||e[10]!==f?(p=t.jsx("button",{type:"button",className:c,"aria-label":a,title:a,onClick:f,style:d,children:l}),e[8]=a,e[9]=c,e[10]=f,e[11]=p):p=e[11],p},gn=n=>{const e=le.c(10),{label:s,onClick:i,className:r}=n;let o;e[0]!==r?(o=Q("flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",r),e[0]=r,e[1]=o):o=e[1];let a;e[2]!==i?(a=l=>{l.stopPropagation(),i()},e[2]=i,e[3]=a):a=e[3];let c,f;e[4]===Symbol.for("react.memo_cache_sentinel")?(c={touchAction:"manipulation"},f=t.jsx(Z,{name:"add",className:"size-4"}),e[4]=c,e[5]=f):(c=e[4],f=e[5]);let d;return e[6]!==s||e[7]!==o||e[8]!==a?(d=t.jsx("button",{type:"button",className:o,"aria-label":s,title:s,onClick:a,style:c,children:f}),e[6]=s,e[7]=o,e[8]=a,e[9]=d):d=e[9],d},Vr=n=>{const e=le.c(66),{session:s,active:i,indent:r,contextLabel:o,statusOnRight:a,hasChildren:c,expanded:f,onToggleChildren:d,onSelect:l,revealed:p,onRevealedChange:g,confirmingDelete:h,onArchive:b,onRequestDelete:S,onConfirmDelete:x,renaming:E,onRequestRename:v,onSubmitRename:N,onCancelRename:A}=n,y=a===void 0?!1:a,P=c===void 0?!1:c,C=f===void 0?!1:f,R=p===void 0?!1:p,k=h===void 0?!1:h,z=E===void 0?!1:E,{t:D}=me();let M;e[0]!==s?(M=Qi(Yi(s)),e[0]=s,e[1]=M):M=e[1];const j=M;let I;e[2]!==s.title||e[3]!==D?(I=s.title?.trim()||D("mobile.sessions.untitled"),e[2]=s.title,e[3]=D,e[4]=I):I=e[4];const $=I,w=!!(g&&b),B=ji(s.id,s.directory,w&&R),U=En(s.id),O=Pn(s.id),L=!O&&U>0&&!i,ie=An(s.id,O),ee=(O||L)&&ie;let W;e[5]!==B||e[6]!==C||e[7]!==P||e[8]!==r||e[9]!==O||e[10]!==d||e[11]!==L||e[12]!==y||e[13]!==D?(W=!y&&(B.pending||O||L||P&&d)?t.jsx("button",{type:"button",className:"absolute z-10 flex w-6 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:{left:Math.max(r-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":B.pending?D("sessions.aiRename.generating"):D(C?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),disabled:!P||!d,onClick:ue=>{ue.stopPropagation(),d?.()},children:B.pending?t.jsx(Z,{name:"loader-4",className:"size-3 animate-spin text-primary","aria-label":D("sessions.aiRename.generating")}):O||L?t.jsx(Os,{state:O?"running":"unread",label:D(O?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread")}):t.jsx(On,{className:Q("size-[18px] transition-transform duration-150",C?"rotate-0":"-rotate-90")})}):null,e[5]=B,e[6]=C,e[7]=P,e[8]=r,e[9]=O,e[10]=d,e[11]=L,e[12]=y,e[13]=D,e[14]=W):W=e[14];let _;e[15]!==i||e[16]!==B||e[17]!==o||e[18]!==r||e[19]!==O||e[20]!==A||e[21]!==g||e[22]!==l||e[23]!==N||e[24]!==z||e[25]!==R||e[26]!==s.id||e[27]!==ee||e[28]!==L||e[29]!==y||e[30]!==D||e[31]!==j||e[32]!==$?(_=z&&N&&A?t.jsx(Hi,{initialTitle:$,indent:r,onSubmit:N,onCancel:A}):t.jsx("button",{type:"button",className:Q("flex min-w-0 flex-1 items-center gap-2.5 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",o?"min-h-10 py-1":"h-9"),style:{paddingLeft:r,touchAction:"manipulation"},onClick:()=>{if(R){g?.(!1);return}l()},children:t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsxs("span",{className:"flex items-center gap-2.5",children:[t.jsx("span",{className:Q("block min-w-0 flex-1 truncate typography-ui-label",i?"text-primary":"text-foreground"),children:$}),y&&(B.pending||O||L)?B.pending?t.jsx(Z,{name:"loader-4",className:"size-3 shrink-0 animate-spin text-primary","aria-label":D("sessions.aiRename.generating")}):t.jsx(Os,{state:O?"running":"unread",label:D(O?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread")}):null,ee?t.jsx(Mn,{sessionId:s.id,running:O,className:"typography-micro"}):j?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:j}):null]}),o?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:o}):null]})}),e[15]=i,e[16]=B,e[17]=o,e[18]=r,e[19]=O,e[20]=A,e[21]=g,e[22]=l,e[23]=N,e[24]=z,e[25]=R,e[26]=s.id,e[27]=ee,e[28]=L,e[29]=y,e[30]=D,e[31]=j,e[32]=$,e[33]=_):_=e[33];let G;e[34]!==_||e[35]!==W?(G=t.jsxs(t.Fragment,{children:[W,_]}),e[34]=_,e[35]=W,e[36]=G):G=e[36];const J=G;if(!w){const ue=i||void 0,q=i&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let oe;e[37]!==q?(oe=Q("relative flex items-center gap-1 transition-colors",q),e[37]=q,e[38]=oe):oe=e[38];let pe;e[39]!==J||e[40]!==oe?(pe=t.jsx("div",{className:oe,children:J}),e[39]=J,e[40]=oe,e[41]=pe):pe=e[41];let ke;return e[42]!==ue||e[43]!==pe?(ke=t.jsx("div",{"data-active-session":ue,className:"relative overflow-hidden",children:pe}),e[42]=ue,e[43]=pe,e[44]=ke):ke=e[44],ke}let H;e[45]!==g?(H=ue=>g?.(ue),e[45]=g,e[46]=H):H=e[46];const X=i&&"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]";let ne;e[47]!==X?(ne=Q("relative flex w-full items-center gap-1 bg-background transition-colors",X),e[47]=X,e[48]=ne):ne=e[48];let re;e[49]!==B||e[50]!==k||e[51]!==b||e[52]!==x||e[53]!==S||e[54]!==v||e[55]!==g||e[56]!==R||e[57]!==$?(re=t.jsx(Ji,{title:$,revealed:R,confirmingDelete:k,aiRename:B,onArchive:b,onRequestDelete:S,onConfirmDelete:x,onRequestRename:v,onRevealedChange:g}),e[49]=B,e[50]=k,e[51]=b,e[52]=x,e[53]=S,e[54]=v,e[55]=g,e[56]=R,e[57]=$,e[58]=re):re=e[58];let ce;return e[59]!==i||e[60]!==R||e[61]!==J||e[62]!==H||e[63]!==ne||e[64]!==re?(ce=t.jsx(Gs,{actionsWidth:qi,revealed:R,onRevealedChange:H,dataActiveSession:i,contentClassName:ne,actions:re,children:J}),e[59]=i,e[60]=R,e[61]=J,e[62]=H,e[63]=ne,e[64]=re,e[65]=ce):ce=e[65],ce},td=n=>{const e=le.c(11),{indent:s,onClick:i}=n,{t:r}=me();let o;e[0]!==s?(o={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(On,{className:"size-4"}),e[2]=a):a=e[2];let c;e[3]!==r?(c=r("sessions.sidebar.group.showMore"),e[3]=r,e[4]=c):c=e[4];let f;e[5]!==c?(f=t.jsx("span",{className:"typography-micro",children:c}),e[5]=c,e[6]=f):f=e[6];let d;return e[7]!==i||e[8]!==o||e[9]!==f?(d=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",style:o,onClick:i,children:[a,f]}),e[7]=i,e[8]=o,e[9]=f,e[10]=d):d=e[10],d},sd=n=>{const e=le.c(11),{indent:s,onClick:i}=n,{t:r}=me();let o;e[0]!==s?(o={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(Wl,{className:"size-4"}),e[2]=a):a=e[2];let c;e[3]!==r?(c=r("sessions.sidebar.group.showFewer"),e[3]=r,e[4]=c):c=e[4];let f;e[5]!==c?(f=t.jsx("span",{className:"typography-micro",children:c}),e[5]=c,e[6]=f):f=e[6];let d;return e[7]!==i||e[8]!==o||e[9]!==f?(d=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",style:o,onClick:i,children:[a,f]}),e[7]=i,e[8]=o,e[9]=f,e[10]=d):d=e[10],d},nd=n=>{const e=le.c(29),{worktree:s}=n,{t:i}=me();let r;e[0]!==s.path?(r=Me(s.path),e[0]=s.path,e[1]=r):r=e[1];const o=r;let a;e[2]!==o?(a={id:o},e[2]=o,e[3]=a):a=e[3];const{attributes:c,listeners:f,setNodeRef:d,transform:l,transition:p,isDragging:g}=Kn(a),h=s.branch||s.label||s.path;let b;e[4]!==l?(b=Hn.Transform.toString(l),e[4]=l,e[5]=b):b=e[5];const S=g?10:1;let x;e[6]!==b||e[7]!==S||e[8]!==p?(x={transform:b,transition:p,zIndex:S},e[6]=b,e[7]=S,e[8]=p,e[9]=x):x=e[9];const E=g&&"shadow-lg shadow-black/20";let v;e[10]!==E?(v=Q("flex items-center gap-1 rounded-xl bg-background px-1 py-1",E),e[10]=E,e[11]=v):v=e[11];let N;e[12]!==h||e[13]!==i?(N=i("mobile.sessions.dragHandleAria",{label:h}),e[12]=h,e[13]=i,e[14]=N):N=e[14];let A;e[15]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(zn,{className:"size-4"}),e[15]=A):A=e[15];let y;e[16]!==c||e[17]!==f||e[18]!==N?(y=t.jsx("button",{type:"button",className:"flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-lg text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":N,...c,...f,children:A}),e[16]=c,e[17]=f,e[18]=N,e[19]=y):y=e[19];let P;e[20]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(Z,{name:"git-branch",className:"size-4 shrink-0 text-muted-foreground"}),e[20]=P):P=e[20];let C;e[21]!==h?(C=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-bold text-muted-foreground",children:h}),e[21]=h,e[22]=C):C=e[22];let R;return e[23]!==d||e[24]!==y||e[25]!==C||e[26]!==x||e[27]!==v?(R=t.jsxs("div",{ref:d,style:x,className:v,children:[y,P,C]}),e[23]=d,e[24]=y,e[25]=C,e[26]=x,e[27]=v,e[28]=R):R=e[28],R},rd=n=>{const e=le.c(61),{project:s,totalSessions:i,expanded:r,onToggleExpanded:o,onReorderWorktrees:a}=n,{t:c}=me();let f;e[0]!==s.id?(f={id:s.id},e[0]=s.id,e[1]=f):f=e[1];const{attributes:d,listeners:l,setNodeRef:p,transform:g,transition:h,isDragging:b}=Kn(f);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S={activationConstraint:{distance:8}},e[2]=S):S=e[2];let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x={coordinateGetter:Vn},e[3]=x):x=e[3];const E=Bn(Ft($n,S),Ft(Ln,x)),v=s.worktrees.length>0;let N;e[4]!==a||e[5]!==s.worktrees?(N=_=>{const{active:G,over:J}=_;if(!J||G.id===J.id)return;const H=s.worktrees.map(ld),X=H.indexOf(String(G.id)),ne=H.indexOf(String(J.id));if(X<0||ne<0)return;const re=[...H],[ce]=re.splice(X,1);re.splice(ne,0,ce),a(re)},e[4]=a,e[5]=s.worktrees,e[6]=N):N=e[6];const A=N;let y;e[7]!==g?(y=Hn.Transform.toString(g),e[7]=g,e[8]=y):y=e[8];const P=b?10:1;let C;e[9]!==y||e[10]!==P||e[11]!==h?(C={transform:y,transition:h,zIndex:P},e[9]=y,e[10]=P,e[11]=h,e[12]=C):C=e[12];const R=b&&"shadow-lg shadow-black/20";let k;e[13]!==R?(k=Q("rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",R),e[13]=R,e[14]=k):k=e[14];let z;e[15]!==s.label||e[16]!==c?(z=c("mobile.sessions.dragHandleAria",{label:s.label}),e[15]=s.label,e[16]=c,e[17]=z):z=e[17];let D;e[18]===Symbol.for("react.memo_cache_sentinel")?(D=t.jsx(zn,{className:"size-4"}),e[18]=D):D=e[18];let M;e[19]!==d||e[20]!==l||e[21]!==z?(M=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":z,...d,...l,children:D}),e[19]=d,e[20]=l,e[21]=z,e[22]=M):M=e[22];let j;e[23]!==r||e[24]!==s.label||e[25]!==c?(j=r?c("sessions.sidebar.group.collapseAria",{label:s.label}):c("sessions.sidebar.group.expandAria",{label:s.label}),e[23]=r,e[24]=s.label,e[25]=c,e[26]=j):j=e[26];const I=!v;let $;e[27]===Symbol.for("react.memo_cache_sentinel")?($={touchAction:"manipulation"},e[27]=$):$=e[27];let w;e[28]!==s?(w=t.jsx(Us,{project:s}),e[28]=s,e[29]=w):w=e[29];let B;e[30]!==s.label?(B=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s.label}),e[30]=s.label,e[31]=B):B=e[31];let U;e[32]!==i?(U=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:i}),e[32]=i,e[33]=U):U=e[33];let O;e[34]!==r||e[35]!==v?(O=v?t.jsx(On,{className:Q("size-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-180")}):null,e[34]=r,e[35]=v,e[36]=O):O=e[36];let L;e[37]!==r||e[38]!==o||e[39]!==j||e[40]!==I||e[41]!==w||e[42]!==B||e[43]!==U||e[44]!==O?(L=t.jsxs("button",{type:"button",className:"flex min-h-9 min-w-0 flex-1 items-center gap-2 rounded-xl px-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",onClick:o,"aria-expanded":r,"aria-label":j,disabled:I,style:$,children:[w,B,U,O]}),e[37]=r,e[38]=o,e[39]=j,e[40]=I,e[41]=w,e[42]=B,e[43]=U,e[44]=O,e[45]=L):L=e[45];let ie;e[46]!==M||e[47]!==L?(ie=t.jsxs("div",{className:"flex items-center gap-1",children:[M,L]}),e[46]=M,e[47]=L,e[48]=ie):ie=e[48];let ee;e[49]!==r||e[50]!==A||e[51]!==v||e[52]!==s.worktrees||e[53]!==E?(ee=r&&v?t.jsx(Fn,{sensors:E,collisionDetection:Wn,onDragEnd:A,children:t.jsx(Un,{items:s.worktrees.map(cd),strategy:Gn,children:t.jsx("div",{className:"mt-1 flex flex-col gap-0.5 pl-3",children:s.worktrees.map(ud)})})}):null,e[49]=r,e[50]=A,e[51]=v,e[52]=s.worktrees,e[53]=E,e[54]=ee):ee=e[54];let W;return e[55]!==p||e[56]!==ie||e[57]!==ee||e[58]!==C||e[59]!==k?(W=t.jsxs("div",{ref:p,style:C,className:k,children:[ie,ee]}),e[55]=p,e[56]=ie,e[57]=ee,e[58]=C,e[59]=k,e[60]=W):W=e[60],W},Ur=({open:n,onOpenChange:e,variant:s="drawer",footer:i})=>{const{t:r}=me(),{git:o}=Tn(),a=Fe(m=>m.ensureStatus),c=ui(),f=Nn(m=>m.activeSessions),d=n||s==="sidebar",l=u.useRef(Ku),p=ai(u.useCallback(m=>(d&&(l.current=m.ids),l.current),[d])),g=u.useRef(Uo),h=li(u.useCallback(m=>(d&&(g.current=m.rankById),g.current),[d])),b=We(m=>m.projects),S=Go(m=>m.projects),x=We(m=>m.activeProjectId),E=gt(m=>m.currentDirectory),v=Se(m=>m.currentSessionId),N=Se(m=>m.setCurrentSession),A=Se(m=>m.archiveSession),y=Se(m=>m.archiveSessions),P=Se(m=>m.deleteSession),C=Se(m=>m.deleteSessions),R=Se(m=>m.updateSessionTitle),k=Se(m=>m.openNewSessionDraft),z=We(m=>m.setActiveProject),D=We(m=>m.setActiveProjectIdOnly),M=We(m=>m.reorderProjects),j=We(m=>m.manualProjectOrder),I=Rs(m=>m.projectSortOrder),$=Rs(m=>m.setProjectSortOrder),w=Rs(m=>m.sidebarViewMode),B=Rs(m=>m.setSidebarViewMode),U=Ko(d&&w==="timeline"),O=We(m=>m.removeProject),L=Is(m=>m.projectExpanded),ie=Is(m=>m.worktreeExpanded),ee=Is(m=>m.setProjectExpanded),W=Is(m=>m.setWorktreeExpanded),_=jn(m=>m.orderByProject),G=jn(m=>m.setWorktreeOrder),J=Br(m=>m.expandedParents),H=Br(m=>m.toggleParent),[X,ne]=u.useState(""),[re,ce]=u.useState(null),[ue,q]=u.useState(null),[oe,pe]=u.useState(null),[ke,Y]=u.useState(null),[de,Ce]=u.useState(null),[ze,Ae]=u.useState(null),[Je,Xe]=u.useState(null),[dt,De]=u.useState(0),[Be,Ne]=u.useState(!1),[ps,Nt]=u.useState(!1),[hs,Ht]=u.useState(!1),[Js,Ue]=u.useState(null),[$e,ft]=u.useState(()=>new Map(Se.getState().availableWorktreesByProject)),[nt,mt]=u.useState(()=>{const m=new Set;for(const[V,K]of Se.getState().availableWorktreesByProject)K.length>0&&m.add(V);return m}),[Le,xt]=u.useState(!1),[je,Ct]=u.useState(new Set),[qt,Ye]=u.useState(new Map),[Ys,Jt]=u.useState(zs),gs=u.useRef(null);u.useEffect(()=>{if(!n){ne(""),xt(!1),Ct(new Set),Ye(new Map),Jt(zs),ce(null),q(null),pe(null),Y(null),Ce(null),Ae(null);return}In(c)},[n]),u.useEffect(()=>{Le||Ct(new Set)},[Le]),u.useEffect(()=>{Jt(zs)},[w]),u.useEffect(()=>{if(!n||b.length===0)return;let m=!1;return(async()=>{const K=await Promise.all(b.map(async he=>{const be=Me(he.path);if(!be)return null;const Ie=await o.checkIsGitRepository(be).catch(()=>!1),tt=Ie?await xi({id:he.id,path:be}).catch(()=>[]):[];return[be,tt,Ie]}));if(m)return;const se=new Map,ae=new Set;for(const he of K)he&&(se.set(he[0],he[1]),he[2]&&ae.add(he[0]));ft(yi(b,se)),mt(ae)})(),()=>{m=!0}},[o,n,b,dt]);const ye=u.useMemo(()=>rl(b.map(m=>({id:m.id,label:m.label?.trim()||fn(m.path),path:Me(m.path),icon:m.icon,color:m.color,iconImage:m.iconImage,iconBackground:m.iconBackground,isGitRepo:nt.has(Me(m.path)),worktrees:Pu(_[m.id],$e.get(Me(m.path))??[]),addedAt:m.addedAt,lastOpenedAt:m.lastOpenedAt})),I,j),[nt,j,I,b,_,$e]),Qe=u.useMemo(()=>{const m=new Map(c.map(se=>[se.id,se])),V=f.map(se=>{const ae=m.get(se.id);return ae?Ho(ae,se):se}),K=new Set(V.map(se=>se.id));for(const se of c)K.has(se.id)||V.push(se);return V.filter(se=>!se.time?.archived)},[f,c]),Ge=u.useMemo(()=>{const m=new Map;for(const V of Qe){const K=ht(V);if(!K)continue;const se=m.get(K)??[];se.push(V),m.set(K,se)}return m},[Qe]),{projectSessions:Re,chatSessions:ot}=u.useMemo(()=>il(Qe,!1),[Qe]),Oe=u.useMemo(()=>ol(Re,ye.map(m=>({id:m.id,normalizedPath:m.path})),new Map(ye.map(m=>[m.path,m.worktrees])),!1,[],S),[S,Re,ye]),bs=u.useMemo(()=>({key:ss,label:"",path:"",worktree:null,sessions:Ps(ot,p,h)}),[ot,p,h]),Qs=`${ss}::${ss}`,_e=u.useMemo(()=>ot.filter(m=>!ht(m)).length,[ot]),Ee=X.trim().toLowerCase(),xs=u.useRef(null);u.useEffect(()=>{if(!n)return;const m=window.requestAnimationFrame(()=>{const V=xs.current;if(!V)return;(V.querySelector('[data-active-session="true"]')??V.querySelector('[data-active-project="true"]'))?.scrollIntoView({block:"center"})});return()=>window.cancelAnimationFrame(m)},[n]);const at=u.useMemo(()=>{const m=ye.map(K=>({project:K,buckets:[],totalSessions:0,isActive:K.id===x})),V=(K,se,ae)=>{const he=Me(se)||K.project.path,be=he||"__root__";let Ie=K.buckets.find(tt=>tt.key===be);return Ie||(Ie={key:be,label:ae?.branch||fn(he),path:he,worktree:ae,sessions:[]},K.buckets.push(Ie)),Ie};for(const K of m){V(K,K.project.path,null);for(const se of K.project.worktrees)V(K,se.path,se)}for(const K of Re){const se=Oe.bySessionId.get(K.id);if(!se)continue;const ae=m.find(Ie=>Ie.project.id===se.projectId);if(!ae)continue;const he=pn(ae.project,se.scopeDirectory);(he?V(ae,he.path,he):V(ae,ae.project.path,null)).sessions.push(K)}for(const K of m)for(const se of K.buckets){se.sessions=Ps(se.sessions,p,h);for(const ae of se.sessions)ht(ae)||(K.totalSessions+=1)}return m},[x,p,Re,ye,h,Oe]),ys=Me(E),Xs=m=>m.isActive?ys===m.project.path?m.project.path:m.project.worktrees.find(K=>Zu(ys,K.path))?.path??m.project.path:null,Rt=m=>L[m.project.id]??!0,vs=(m,V)=>ie[`${m.project.id}::${V.key}`]??!0,pt=m=>{Ye(V=>{if(!V.has(m))return V;const K=new Map(V);return K.delete(m),K})},Yt=m=>{Ye(V=>{let K=!1;const se=new Map(V),ae=`${m}::`;for(const he of se.keys())he.startsWith(ae)&&(se.delete(he),K=!0);return K?se:V})},Qt=(m,V,K)=>{Ye(se=>{const ae=new Map(se);return ae.set(m,V+K),ae})},Et=(m,V,K,se)=>{const ae=se?.pageSize??Ju,he=se?.alwaysVisibleIds,be=new Set(V.sessions.map(ve=>ve.id)),Ie=new Map;for(const ve of V.sessions){const rt=ht(ve);if(rt&&be.has(rt)){const es=Ie.get(rt)??[];es.push(ve),Ie.set(rt,es)}}const tt=V.sessions.filter(ve=>{const rt=ht(ve);return!rt||!be.has(rt)}),rn=he?tt.filter(ve=>he.has(ve.id)):[],on=he?tt.filter(ve=>!he.has(ve.id)):tt,co=qt.get(m)??ae,an=on.slice(0,co),uo=[...rn,...an],ur=on.length-an.length,fo=on.length>ae&&ur===0,dr=(ve,rt)=>{const es=Ie.get(ve.id)??[],ln=es.length>0,fr=!!J[ve.id];return t.jsxs(u.Fragment,{children:[t.jsx(Vr,{session:ve,active:v===ve.id,indent:rt,hasChildren:ln,expanded:fr,onToggleChildren:ln?()=>H(ve.id):void 0,onSelect:()=>Pt(ve),statusOnRight:se?.statusOnRight,revealed:ue===ve.id,onRevealedChange:ts=>js(ve.id,ts),confirmingDelete:oe===ve.id,onArchive:()=>{Zt(ve)},onRequestDelete:()=>pe(ve.id),onConfirmDelete:()=>{ks(ve)},renaming:ke===ve.id,onRequestRename:()=>T(ve.id),onSubmitRename:ts=>{F(ve.id,ts)},onCancelRename:()=>Y(null)}),ln&&fr?es.map(ts=>dr(ts,rt+Xu)):null]},ve.id)};return t.jsxs("div",{children:[uo.map(ve=>dr(ve,K)),ur>0?t.jsx(td,{indent:K,onClick:()=>Qt(m,an.length,ae)}):null,fo?t.jsx(sd,{indent:K,onClick:()=>pt(m)}):null]})},ws=(m,V)=>{ee(m,!V),Yt(m)},Zs=(m,V,K)=>{W(`${m}::${V}`,!K),pt(`${m}::${V}`)},Pt=m=>{const V=kn(m)||null,K=Oe.bySessionId.get(m.id),se=K?ye.find(ae=>ae.id===K.projectId)??null:null;if(se){D(se.id),ee(se.id,!0);const ae=pn(se,K?.scopeDirectory??"");ae&&W(`${se.id}::${Me(ae.path)}`,!0)}N(m.id,V),e(!1)},js=(m,V)=>{q(V?m:null),pe(null),Ce(null),Ae(null)},lt=(m,V)=>{Ce(V?m:null),Ae(null),q(null),pe(null)},Xt=(m,V)=>(q(null),pe(null),dl(m,V,fl(V.id,ml(Ge,V.id),m==="delete"),{archiveSession:A,archiveSessions:y,deleteSession:P,deleteSessions:C},r)),Zt=m=>Xt("archive",m),ks=m=>Xt("delete",m),T=m=>{q(null),pe(null),Y(m)},F=async(m,V)=>{Y(null);try{await R(m,V)}catch{fe.error(r("mobile.sessions.renameError"))}},te=()=>{k(),e(!1)},we=m=>{Ue(m),D(m),Ht(!0)},Ze=Bn(Ft($n,{activationConstraint:{distance:8}}),Ft(Ln,{coordinateGetter:Vn})),en=m=>{$(m),pr({sidebarProjectSortOrder:m}),m!=="manual"&&xt(!1)},At=m=>{B(m),pr({sidebarViewMode:m}),m==="timeline"&&xt(!1)},tn=m=>{const{active:V,over:K}=m;if(!K||V.id===K.id)return;const se=ye.findIndex(he=>he.id===V.id),ae=ye.findIndex(he=>he.id===K.id);se<0||ae<0||M(se,ae)},to=m=>{Ct(V=>{const K=new Set(V);return K.has(m)?K.delete(m):K.add(m),K})},so=u.useCallback(m=>{const V=kn(m);if(qo(V))return r("mobile.sessions.section.chats");const K=Oe.bySessionId.get(m.id),se=K?ye.find(he=>he.id===K.projectId)??null:null;if(!se)return fn(V)||V;const ae=pn(se,K?.scopeDirectory??"");return ae?.branch?`${se.label} · ${ae.branch}`:se.label},[ye,Oe,r]),no=m=>{z(m.id),e(!1)},rr=m=>{D(m.id),k({selectedProjectId:m.id,directoryOverride:m.path}),e(!1)},ro=u.useMemo(()=>Ee?at.filter(m=>bi([m.project.label,m.project.path],Ee)?!0:m.buckets.some(V=>V.sessions.some(K=>hn(K,m.project.label,Ee)))):at,[Ee,at]),Ss=u.useMemo(()=>Ee?Ps(Qe.filter(m=>{if(ht(m))return!1;const V=Oe.bySessionId.get(m.id),K=V?ye.find(se=>se.id===V.projectId)??null:null;return hn(m,K?.label??"",Ee)}),p,h):[],[Ee,p,ye,h,Oe,Qe]),Ns=u.useMemo(()=>Ee?Jo(ye,Ee,m=>[m.label,m.path]):[],[Ee,ye]),et=w==="timeline"&&!Ee&&!Le;u.useEffect(()=>{if(!(!et||!o))for(const m of ye){const V=Me(m.path);V&&Yo(()=>a(V,o))}},[a,o,ye,et]);const sn=u.useMemo(()=>{const m=new Map;if(!et)return m;const V=al({sessions:Re,projects:ye.map(K=>({id:K.id,normalizedPath:K.path,label:K.label})),ownerBySessionId:Oe.bySessionId,availableWorktreesByProject:new Map(ye.map(K=>[K.path,K.worktrees])),gitBranches:U,homeDirectory:null,hideBranchMatchingProjectLabel:!1});for(const K of Re){if(ht(K))continue;const se=V.get(K.id),ae=se?ye.find(he=>he.id===se.projectId):null;!ae||!se||m.set(K.id,{project:ae,branch:se.branchLabel})}return m},[U,Re,ye,Oe,et]),nn=u.useMemo(()=>{if(!et)return[];const m=Re.filter(V=>!ht(V)&&sn.has(V.id));return Ps(m,p,h).flatMap(V=>{const K=sn.get(V.id);return K?[{session:V,project:K.project,branch:K.branch}]:[]})},[p,Re,h,et,sn]),io=u.useCallback(()=>{Jt(m=>Ou(m,nn.length))},[nn.length]),oo={currentSessionId:v,revealedSessionId:ue,confirmingDeleteSessionId:oe,renamingSessionId:ke,onSelect:Pt,onRevealedChange:js,onArchive:m=>{Zt(m)},onRequestDelete:pe,onConfirmDelete:m=>{ks(m)},onRequestRename:T,onSubmitRename:(m,V)=>{F(m,V)},onCancelRename:()=>Y(null)},ao=Ee&&Ss.length===0&&Ns.length===0,lo=!Ee&&!et&&ye.length>1&&I==="manual",ir=!Le&&!Ee&&ye.length>0?t.jsx(ge,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.displayMode.label"),title:r("sessions.sidebar.header.displayMode.label"),onClick:()=>Ne(!0),style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"equalizer-2",className:"size-4"})}):null,or=lo?t.jsx(ge,{type:"button",variant:"chip",size:"sm","aria-label":r(Le?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":Le,onClick:()=>xt(m=>!m),style:{touchAction:"manipulation"},children:Le?t.jsx(ki,{className:"size-4"}):t.jsx(yn,{className:"size-4"})}):null,ar=!Le&&ye.length>0?t.jsxs(ge,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:te,style:{touchAction:"manipulation"},children:[t.jsx(Fl,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,lr=Le?null:t.jsx(ge,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>Nt(!0),style:{touchAction:"manipulation"},children:t.jsx(jr,{className:"size-4"})}),Cs=ar||lr||ir||or?t.jsxs(t.Fragment,{children:[lr,ir,or,ar]}):null,cr=t.jsxs("div",{ref:xs,className:"flex min-h-0 flex-1 flex-col",children:[t.jsxs(Ks,{ref:gs,className:"min-h-0 flex-1 overflow-y-auto pb-4",children:[t.jsx("div",{className:Q("px-4 pb-2 pt-1",Le&&"hidden"),children:t.jsx(ll,{value:X,onSearch:ne,active:n||s==="sidebar",mobile:!0,placeholder:r("mobile.sessions.search.placeholder"),clearLabel:r("mobile.sessions.clearSearchAria")})}),ye.length===0&&ot.length===0?t.jsx(Hr,{title:r("mobile.sessions.empty.noProjectsTitle"),description:r("mobile.sessions.empty.noProjectsDescription"),action:t.jsxs("button",{type:"button",className:"flex items-center justify-center gap-2 rounded-2xl bg-primary px-5 py-3 typography-ui-label text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>Nt(!0),children:[t.jsx(jr,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):ao?t.jsx(Hr,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):Ee&&!Le?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[Ss.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.sessions")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Ss.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Ss.map((m,V)=>t.jsx("div",{className:Q(V>0&&"border-t border-border/70"),children:t.jsx(Vr,{session:m,active:v===m.id,indent:12,contextLabel:so(m),onSelect:()=>Pt(m)})},m.id))})]}):null,Ns.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.projects")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Ns.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Ns.map((m,V)=>t.jsxs("div",{className:Q("flex items-center",V>0&&"border-t border-border/70"),children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-3 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>no(m),style:{touchAction:"manipulation"},children:[t.jsx(Us,{project:m}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:m.label})]}),m.isGitRepo?t.jsx(Wr,{onClick:()=>we(m.id)}):null,t.jsx(gn,{className:"mr-2",label:r("mobile.sessions.newSessionInProjectAria",{label:m.label}),onClick:()=>rr(m)})]},m.id))})]}):null]}):Le?t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2",children:[t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:r("mobile.sessions.editOrderHint")}),t.jsx(Fn,{sensors:Ze,collisionDetection:Wn,onDragEnd:tn,children:t.jsx(Un,{items:ye.map(m=>m.id),strategy:Gn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:ye.map(m=>{const V=at.find(K=>K.project.id===m.id);return t.jsx(rd,{project:m,totalSessions:V?.totalSessions??0,expanded:je.has(m.id),onToggleExpanded:()=>to(m.id),onReorderWorktrees:K=>G(m.id,K)},m.id)})})})})]}):t.jsxs("div",{className:"flex flex-col",children:[(()=>{const m=L[ss]??!0,V=r("mobile.sessions.section.chats");return t.jsxs("section",{children:[t.jsxs("div",{className:"flex min-h-12 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(de){lt(de,!1);return}ws(ss,m)},"aria-expanded":m,"aria-label":m?r("sessions.sidebar.group.collapseAria",{label:V}):r("sessions.sidebar.group.expandAria",{label:V}),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-[var(--surface-muted)] text-muted-foreground",children:t.jsx(Z,{name:"chat-4",className:"size-4"})}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:V}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:_e})]}),Le?null:t.jsx(gn,{className:"mr-2",label:r("mobile.sessions.newChat"),onClick:te})]}),m?t.jsx("div",{className:"pb-2",children:bs.sessions.length>0?Et(Qs,bs,et?Qu:Ds,et?{pageSize:Yu,alwaysVisibleIds:p,statusOnRight:!0}:void 0):t.jsx("p",{className:"px-3 pb-1 typography-micro text-muted-foreground",style:{paddingLeft:Ds},children:r("sessions.sidebar.activity.chatsEmpty")})}):null]})})(),et?t.jsx(Mu,{entries:nn,visibleCount:Ys,onRevealMore:io,scrollRootRef:gs,handlers:oo}):null,et?null:ro.map(m=>{const V=Rt(m),K=Ee?m.buckets.filter(ae=>ae.sessions.some(he=>hn(he,m.project.label,Ee))):m.buckets,se=Xs(m);return t.jsxs("section",{className:"border-t border-border/70",children:[t.jsx(Gs,{actionsWidth:96,revealed:de===`project:${m.project.id}`,onRevealedChange:ae=>lt(`project:${m.project.id}`,ae),actions:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",tabIndex:de===`project:${m.project.id}`?0:-1,className:Q("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",ze===m.project.id?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":ze===m.project.id?r("mobile.sessions.confirmRemoveProjectAria",{label:m.project.label}):r("mobile.sessions.removeProjectAria",{label:m.project.label}),onClick:()=>{if(ze===m.project.id){Ce(null),Ae(null),O(m.project.id),fe.success(r("mobile.sessions.toast.projectRemoved",{label:m.project.label}));return}Ae(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(Bs,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:de===`project:${m.project.id}`?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":r("mobile.sessions.editProjectAria",{label:m.project.label}),onClick:()=>{Ce(null),ce(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(yn,{className:"size-[18px]"})})]}),children:t.jsxs("div",{"data-active-project":m.isActive||void 0,className:"flex min-h-12 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(de){lt(de,!1);return}ws(m.project.id,V)},"aria-expanded":V,"aria-label":V?r("sessions.sidebar.group.collapseAria",{label:m.project.label}):r("sessions.sidebar.group.expandAria",{label:m.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(Us,{project:m.project}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:m.project.label})]}),m.project.isGitRepo?t.jsx(Wr,{onClick:()=>we(m.project.id)}):null,t.jsx(gn,{className:"mr-2",label:r("mobile.sessions.newSessionInProjectAria",{label:m.project.label}),onClick:()=>rr(m.project)})]})}),V?t.jsx("div",{className:"pb-2",children:(()=>{const ae=K.find(be=>be.worktree===null),he=K.filter(be=>be.worktree!==null);return t.jsxs(t.Fragment,{children:[ae&&ae.sessions.length>0?Et(`${m.project.id}::${ae.key}`,ae,Ds):null,he.map(be=>{const Ie=vs(m,be),tt=se===be.path;return t.jsxs("div",{children:[t.jsx(Gs,{actionsWidth:48,revealed:de===`wt:${be.key}`,onRevealedChange:rn=>lt(`wt:${be.key}`,rn),actions:t.jsx("button",{type:"button",tabIndex:de===`wt:${be.key}`?0:-1,className:"flex flex-1 items-center justify-center text-[var(--status-error)] transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive","aria-label":r("mobile.projectEdit.deleteWorktreeAria",{label:be.label}),onClick:()=>{Ce(null),be.worktree&&Xe({project:m.project,worktree:be.worktree})},style:{touchAction:"manipulation"},children:t.jsx(Bs,{className:"size-[18px]"})}),children:t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 px-3 py-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(de){lt(de,!1);return}Zs(m.project.id,be.key,Ie)},"aria-expanded":Ie,"aria-label":Ie?r("sessions.sidebar.group.collapseAria",{label:be.label}):r("sessions.sidebar.group.expandAria",{label:be.label}),style:{touchAction:"manipulation"},children:[t.jsx(Z,{name:"git-branch",className:Q("size-4 shrink-0",tt?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Q("block min-w-0 flex-1 truncate typography-ui-label font-bold",tt?"text-foreground":"text-muted-foreground"),children:be.label}),tt?t.jsx(ed,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:be.sessions.length})]})}),Ie?Et(`${m.project.id}::${be.key}`,be,Ds):null]},be.key)})]})})()}):null]},m.project.id)})]})]}),i?t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/70 px-2 pt-1.5",style:{paddingBottom:"calc(0.375rem + var(--oc-safe-area-bottom, 0px))"},children:[i.instanceLabel&&i.onOpenInstances?t.jsxs(ge,{type:"button",variant:"info",size:"lg",className:"min-w-0 shrink justify-start",onClick:i.onOpenInstances,"aria-label":r("mobile.menu.instances"),style:{touchAction:"manipulation"},children:[t.jsx(Z,{name:"server",className:"size-[18px]"}),t.jsx("span",{className:"block min-w-0 truncate",children:i.instanceLabel})]}):t.jsx("div",{className:"min-w-0 flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[i.onOpenUpdate?t.jsxs(ge,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:i.onOpenUpdate,"aria-label":r("mobile.menu.update"),title:r("mobile.menu.update"),style:{touchAction:"manipulation"},children:[t.jsx(Z,{name:"download",className:"size-5"}),t.jsx("span",{className:"absolute right-2 top-2 inline-flex size-2 rounded-full bg-primary","aria-hidden":!0})]}):null,t.jsx(ge,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:i.onOpenUsage,"aria-label":r("usageStats.openAction"),title:r("usageStats.openAction"),style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"bar-chart",className:"size-5"})}),t.jsx(ge,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:i.onOpenSettings,"aria-label":r("mobile.menu.settings"),title:r("mobile.menu.settings"),style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"settings-3",className:"size-5"})})]})]}):null,t.jsx(cl,{open:ps,onOpenChange:Nt}),t.jsx(ul,{open:hs,onOpenChange:m=>{Ht(m),m||Ue(null)},onWorktreeCreated:(m,V)=>{V?.sessionId?N(V.sessionId,m):k({selectedProjectId:Js,directoryOverride:m,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(Fu,{open:re!==null,project:ye.find(m=>m.id===re)??null,onClose:()=>ce(null),onWorktreesChanged:()=>De(m=>m+1)}),t.jsx(di,{open:Be,onClose:()=>Ne(!1),title:r("sessions.sidebar.header.displayMode.label"),children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"px-3 pb-1 pt-1 typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.viewMode.label")}),qu.map(([m,V])=>t.jsxs("button",{type:"button",className:Q("flex min-h-11 w-full items-center justify-between rounded-lg px-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",w===m?"text-primary":"text-foreground"),onClick:()=>{At(m),Ne(!1)},style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label",children:r(V)}),w===m?t.jsx(Z,{name:"check",className:"size-4"}):null]},m)),w==="timeline"?null:t.jsx("span",{className:"px-3 pb-1 pt-3 typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("sessions.sidebar.header.actions.sortProjects")}),w==="timeline"?null:Hu.map(([m,V])=>t.jsxs("button",{type:"button",className:Q("flex min-h-11 w-full items-center justify-between rounded-lg px-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",I===m?"text-primary":"text-foreground"),onClick:()=>{en(m),Ne(!1)},style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label",children:r(V)}),I===m?t.jsx(Z,{name:"check",className:"size-4"}):null]},m))]})}),Je?t.jsx(Ki,{open:!0,project:{id:Je.project.id,path:Je.project.path},worktree:Je.worktree,onClose:()=>Xe(null),onDeleted:()=>De(m=>m+1)}):null]});return s==="sidebar"?n?t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center justify-between gap-2 border-b border-border/70 px-4",children:[t.jsx("h2",{className:"truncate typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Cs?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Cs}):null]}),cr]}):null:t.jsxs(ad,{open:n,onClose:()=>e(!1),onSwipeClose:()=>{if(ue||de){q(null),Ce(null),pe(null),Ae(null);return}e(!1)},ariaLabel:r("mobile.sessions.sheet.title"),children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":r("mobile.surface.closeAria"),onClick:()=>e(!1),style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"close",className:"size-5"})}),t.jsx("h2",{className:"min-w-0 flex-1 truncate px-1 typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Cs?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Cs}):null]}),cr]})},Gr="mobile-surface-root",id=16,Kr=320,od="cubic-bezier(0.22, 1, 0.36, 1)",ad=({open:n,onClose:e,onSwipeClose:s,ariaLabel:i,children:r})=>{const o=u.useRef(null),a=u.useRef(null),[c,f]=u.useState(!1),[d,l]=u.useState(n),p=u.useRef(e);u.useEffect(()=>{p.current=e},[e]);const g=u.useRef(s);if(u.useEffect(()=>{g.current=s},[s]),sr(a,{enabled:n,onRightEdgeSwipe:()=>(g.current??p.current)()}),typeof document<"u"&&!o.current){let h=document.getElementById(Gr);h||(h=document.createElement("div"),h.id=Gr,document.body.appendChild(h)),o.current=h}return u.useEffect(()=>{if(n){l(!0);const b=window.setTimeout(()=>f(!0),id);return()=>window.clearTimeout(b)}f(!1);const h=window.setTimeout(()=>l(!1),Kr+40);return()=>window.clearTimeout(h)},[n]),u.useEffect(()=>{if(!n)return;const h=document.body.style.overflow;document.body.style.overflow="hidden";const b=S=>{S.key==="Escape"&&p.current()};return document.addEventListener("keydown",b),()=>{document.body.style.overflow=h,document.removeEventListener("keydown",b)}},[n]),o.current?Lt.createPortal(t.jsx("section",{ref:a,role:"dialog","aria-modal":"true","aria-label":i,"aria-hidden":!n,className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:c?"none":"translateX(-100%)",transition:`transform ${Kr}ms ${od}`,visibility:d?"visible":"hidden",pointerEvents:n?"auto":"none"},children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r})}),o.current):null},Hr=n=>{const e=le.c(10),{title:s,description:i,action:r}=n;let o;e[0]!==s?(o=t.jsx("p",{className:"typography-ui-label text-foreground",children:s}),e[0]=s,e[1]=o):o=e[1];let a;e[2]!==i?(a=i?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i}):null,e[2]=i,e[3]=a):a=e[3];let c;e[4]!==r?(c=r?t.jsx("div",{className:"pt-2",children:r}):null,e[4]=r,e[5]=c):c=e[5];let f;return e[6]!==o||e[7]!==a||e[8]!==c?(f=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[o,a,c]}),e[6]=o,e[7]=a,e[8]=c,e[9]=f):f=e[9],f};function ld(n){return Me(n.path)}function cd(n){return Me(n.path)}function ud(n){return t.jsx(nd,{worktree:n},Me(n.path))}const dd=(n,e)=>{if(!n)return e("mcpDropdown.status.unknown");const s=n.status;switch(s.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:s.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");default:return s.status}},fd=n=>{switch(n?.status.status){case"connected":return"success";case"failed":return"error";case"needs_auth":return"warning";default:return"default"}},md=({active:n,className:e,headerAction:s,listClassName:i,hideHeader:r=!1,mobileListDensity:o=!1})=>{const{t:a}=me(),f=gt(y=>y.currentDirectory)??null,d=is(y=>y.getStatusForDirectory(f)),l=is(y=>y.refresh),p=is(y=>y.connect),g=is(y=>y.disconnect),h=Ot(y=>y.mcpServers),b=Ot(y=>y.loadMcpConfigs),[S,x]=u.useState(!1),[E,v]=u.useState(null);u.useEffect(()=>{l({directory:f,silent:!0})},[l,f]),u.useEffect(()=>{b({force:!0})},[b]),u.useEffect(()=>{n&&Promise.all([l({directory:f,silent:!0}),b({force:!0})])},[n,l,f,b]);const N=u.useMemo(()=>{const y=new Set(Object.keys(d));for(const P of h)P?.name&&y.add(P.name);return Array.from(y).sort((P,C)=>P.localeCompare(C))},[h,d]),A=u.useCallback(y=>{if(y?.preventDefault(),S)return;x(!0);const P=new Promise(C=>setTimeout(C,500));Promise.all([l({directory:f}),P]).finally(()=>{x(!1)})},[S,l,f]);return t.jsxs("div",{className:Q("w-full",e),children:[r?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:a("mcpDropdown.title")}),f&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:f.split("/").pop()||f})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",disabled:S,onClick:A,"aria-label":a("mcpDropdown.actions.refreshAria"),children:t.jsx(Z,{name:"refresh",className:Q("h-4 w-4",S&&"animate-spin")})})]})]})}),t.jsx("div",{className:Q("max-h-64 overflow-y-auto",o?"space-y-1 py-3":"px-3 py-2.5",i),children:t.jsxs("div",{className:Q(!o&&N.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[N.map(y=>{const P=d[y],C=fd(P),R=P?.status.status==="connected",k=E===y,z=dd(P,a);return t.jsxs("div",{className:Q("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",o?"gap-3 px-4 py-3":"gap-2 px-2.5 py-2"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(Qo,{children:[t.jsx(Xo,{asChild:!0,children:t.jsx("span",{className:Q("rounded-full flex-shrink-0",o?"h-2.5 w-2.5":"h-2 w-2",C==="success"&&"bg-status-success",C==="error"&&"bg-status-error",C==="warning"&&"bg-status-warning",C==="default"&&"bg-muted-foreground/40"),"aria-label":z})}),t.jsx(Zo,{side:"left",children:t.jsx("p",{children:z})})]}),t.jsx("span",{className:Q("truncate",o?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:y})]})}),t.jsx(ea,{checked:R,disabled:k,className:"data-[checked]:bg-status-info",onCheckedChange:async D=>{v(y);try{D?await p(y,f):await g(y,f)}catch(M){Yl.error(M instanceof Error?M.message:a("mcpDropdown.status.unknownError"))}finally{v(null)}}})]},y)}),N.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:a("mcpDropdown.empty.configureInConfig")})]})})]})},qr={status:"loading"},It={type:"list"},pd=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),hd=n=>{const e=n.index?.trim();return!!(e&&e!=="?")},gd=n=>{const e=n.working_dir?.trim(),s=n.index?.trim();return!!(e||s==="?")},Jr=(n,e)=>e?`${n}\0staged`:n,bd=n=>{const e=le.c(8),s=Dn()??null;let i;e[0]!==s?(i=pd(s),e[0]=s,e[1]=i):i=e[1];const r=i,o=n.visible??!0;let a;e[2]!==o?(a={enabled:o},e[2]=o,e[3]=a):a=e[3];const c=ta(r||null,a);let f;return e[4]!==n||e[5]!==c||e[6]!==r?(f=t.jsx(xd,{...n,rootDirectory:r,repository:c}),e[4]=n,e[5]=c,e[6]=r,e[7]=f):f=e[7],f},xd=({rootDirectory:n,repository:e,onClose:s,initialDiff:i,visible:r=!0})=>{const{t:o}=me(),{git:a}=Tn(),{rootIsGitRepo:c,gitDirectory:f,nestedRepos:d}=e,l=f??n,p=sa(l||null),g=na(l||null),h=ci(l||null),b=ra(l||null),S=Fe(T=>T.setActiveDirectory),x=Fe(T=>T.ensureAll),E=Fe(T=>T.ensureNestedRepos),v=Fe(T=>T.selectNestedRepo),N=Fe(T=>T.fetchStatus),A=Fe(T=>T.fetchBranches),y=Fe(T=>T.prefetchDiffs),P=Fe(T=>T.getDiff),C=Fe(T=>T.setDiff),R=Fe(T=>T.runtimeKey),k=JSON.stringify([R,l]),z=u.useRef(k);z.current=k;const[D,M]=u.useState(()=>({ownerKey:k,mode:"working",route:i?.path?{type:"diff",path:i.path,staged:i.staged}:It})),j=D.ownerKey===k?D.mode:"working",I=D.ownerKey===k?D.route:It,[$,w]=u.useState(!1),B=u.useCallback(T=>{M({ownerKey:k,mode:T,route:It}),w(!1)},[k]),U=u.useCallback(T=>{M(F=>({ownerKey:k,mode:F.ownerKey===k?F.mode:"working",route:T}))},[k]);u.useEffect(()=>{M(T=>T.ownerKey===k?T:{ownerKey:k,mode:"working",route:It}),w(!1)},[k]),u.useEffect(()=>{r||w(!1)},[r]),u.useEffect(()=>{i?.path&&M({ownerKey:z.current,mode:"working",route:{type:"diff",path:i.path,staged:i.staged}})},[i]);const[O,L]=u.useState(null),[ie,ee]=u.useState(null),[W,_]=u.useState(""),[G,J]=u.useState(new Set),[H,X]=u.useState(!1),[ne,re]=u.useState(!1),[ce,ue]=u.useState([]),[q,oe]=u.useState([]),[pe,ke]=u.useState([]),[Y,de]=u.useState(null),[Ce,ze]=u.useState(null),[Ae,Je]=u.useState(null),[Xe,dt]=u.useState(0),[De,Be]=u.useState(null),Ne=p?.current??null,ps=p?.tracking?.trim().split("/")[0],Nt=(ps&&g?.defaultBranches?.[ps])??g?.defaultBranches?.origin??null,hs=fc(Ne,Nt),Ht=h===!1||uc(Ne,Nt,p!==null,g!==null),Js=ec(T=>T.setOverride),Ue=tc(l||null,Ne,r&&j==="branch"&&hs),$e=sc(l||null,Ne,r&&j==="commit"&&h===!0),ft=$e.selectedCommit?.hash??null,nt=nc(l||null,Ne,r&&j==="pr"&&h===!0),mt=nt.selectedSource,Le=u.useMemo(()=>j==="pr"?mt:j==="branch"&&Ne&&Ue.base?{kind:"branch",baseRef:Ue.base,headRef:Ne}:j==="commit"&&ft?{kind:"commit",hash:ft}:null,[Ue.base,Ne,j,ft,mt]),xt=j==="branch"?Ue.revision:"",je=lc(l||null,Le,r&&h===!0,xt),{fetchDiff:Ct}=je,qt=u.useMemo(()=>je.files?[...je.files].sort((T,F)=>T.path.localeCompare(F.path)):null,[je.files]),Ye=I.type==="comparison"&&I.sourceKey===je.key?I.path:null,[Ys,Jt]=u.useState(0),gs=u.useCallback(async T=>{try{const{diff:F}=await Ct(T),te={original:"",modified:"",isBinary:rc(F)};return te.isBinary||(te.fileDiff=ic(T,F)),{status:"ready",diff:te}}catch(F){return{status:"error",message:F instanceof Error?F.message:o("diffView.state.failedToLoadDiff")}}},[Ct,o]),ye=cc(je.files?j==="pr"?JSON.stringify([je.key,je.revision]):je.key:null,r&&Ye?Ye:"",r?gs:null,qr,JSON.stringify([xt,j==="pr"?je.revision:0,Ys])),Qe=Ye?ye.get(Ye)??qr:null;u.useEffect(()=>{j==="branch"&&Ht&&B("working")},[Ht,B,j]),u.useEffect(()=>{M(T=>T.ownerKey===k&&T.route.type==="comparison"&&T.route.sourceKey!==je.key?{...T,route:It}:T)},[je.key,k]);const Ge=u.useMemo(()=>{const T=p?.files??[],F=new Map;for(const te of T)F.set(te.path,te);return Array.from(F.values()).sort((te,we)=>te.path.localeCompare(we.path))},[p?.files]),Re=u.useMemo(()=>Ge.filter(hd),[Ge]),ot=u.useMemo(()=>Ge.filter(gd),[Ge]),Oe=u.useMemo(()=>{if(pe.length>0)return pe;const T=p?.tracking?.includes("/")?p.tracking.split("/")[0]:null;return T||Y?[{name:T||"origin",fetchUrl:Y??"",pushUrl:Y??""}]:[]},[Y,pe,p?.tracking]),bs=Fe(u.useCallback(T=>!l||I.type!=="diff"?null:T.directories.get(l)?.diffCache.get(Jr(I.path,I.staged))??null,[l,I])),Qs=u.useMemo(()=>I.type!=="diff"?null:Ge.find(T=>T.path===I.path)??null,[Ge,I]),_e=u.useCallback(async(T=!0)=>{if(l)try{await Promise.all([N(l,a),A(l,a)])}catch(F){T&&fe.error(F instanceof Error?F.message:o("gitView.toast.refreshRepositoryFailed"))}},[l,A,N,a,o]),Ee=u.useMemo(()=>(g?.all??[]).filter(T=>!T.startsWith("remotes/")).sort(),[g]),xs=u.useMemo(()=>(g?.all??[]).filter(T=>T.startsWith("remotes/")).map(T=>T.replace(/^remotes\//,"")).sort(),[g]),at=u.useCallback(async T=>{if(!l)return;const F=T.replace(/^remotes\//,"");try{const te=await a.checkoutBranch(l,F);fe.success(o("gitView.toast.checkedOut",{name:te.branch||F})),await _e()}catch(te){fe.error(te instanceof Error?te.message:o("gitView.toast.checkoutFailed",{name:F}))}},[l,a,_e,o]),ys=u.useCallback(T=>{const F=T.replace(/^remotes\//,"");if((p?.files?.length??0)>0){Be(F);return}at(F)},[at,p?.files]),Xs=u.useCallback(async(T,F)=>{if(l)try{await a.createBranch(l,T,Ne??"HEAD"),await a.checkoutBranch(l,T),F&&await a.gitPush(l,{remote:F.name,branch:T,options:["--set-upstream"]}),await _e()}catch(te){throw fe.error(te instanceof Error?te.message:o("gitView.toast.createBranchFailed")),te}},[Ne,l,a,_e,o]),Rt=u.useCallback(async()=>{if(!l){ke([]),de(null);return}try{const[T,F]=await Promise.all([a.getRemotes(l).catch(()=>[]),a.getRemoteUrl?a.getRemoteUrl(l).catch(()=>null):Promise.resolve(null)]);ke(T),de(F)}catch{ke([]),de(null)}},[l,a]);u.useEffect(()=>{!l||!r||(S(l),x(l,a))},[l,x,a,S,r]),u.useEffect(()=>{r&&Rt()},[Rt,r]),u.useEffect(()=>{if(!r||j!=="working"||!l||Ge.length===0)return;const T=Array.from(new Set([...Re.map(te=>te.path),...q,...Ge.slice(0,20).map(te=>te.path)])).filter(Boolean);if(T.length===0)return;const F=window.setTimeout(()=>{y(l,a,T,{maxFiles:40})},120);return()=>window.clearTimeout(F)},[Ge,l,a,j,y,Re,q,r]),u.useEffect(()=>{if(!r)return;if(I.type!=="diff"){ze(null);return}const T=Jr(I.path,I.staged);if(Je(null),!l||P(l,T)){ze(null);return}let F=!1;const te=Gt();return ze(null),a.getGitFileDiff(l,{path:I.path,staged:I.staged||void 0}).then(we=>{F||C(l,T,{original:we.original??"",modified:we.modified??"",isBinary:we.isBinary,submodule:we.submodule},te)}).catch(we=>{if(!F){if(we instanceof hr&&we.reason!=="path_not_found"){Je({key:`${l}\0${I.path}`,reason:we.reason});return}we instanceof hr&&N(l,a,{force:!0,silent:!0}),ze(we instanceof Error?we.message:String(we))}}),()=>{F=!0}},[l,Xe,N,P,a,I,C,r]);const vs=async(T,F)=>{if(l){L(T);try{if(T==="fetch"){if(!F)throw new Error(o("mobile.changes.noRemote"));await a.gitFetch(l,{remote:F.name}),fe.success(o("gitView.toast.fetchedFromRemote",{name:F.name}))}else if(T==="sync"){if(!F)throw new Error(o("mobile.changes.noRemote"));let te=0;const we=await Sr({git:a,directory:l,remote:F,dirtyWorktreeError:o("gitView.toast.commitOrStashBeforeSync"),onPulled:Ze=>{te=Ze.files.length}});te>0&&fe.success(te===1?o("gitView.toast.pulledFilesSingle",{count:te,name:F.name}):o("gitView.toast.pulledFilesPlural",{count:te,name:F.name})),we.pushed.length>0?fe.success(o("gitView.toast.pushedToUpstream",{name:we.pushed[0].remote})):te===0&&fe.success(o("gitView.toast.alreadyUpToDate"))}await _e(!1),await Rt()}catch(te){fe.error(te instanceof Error?te.message:o("gitView.toast.syncActionFailed",{action:o("gitView.sync.syncChanges")}))}finally{L(null)}}},pt=u.useCallback(async(T,F)=>{if(!(!l||T.length===0))try{F==="stage"?T.length>1?await ia(l,T):await oa(l,T[0]):T.length>1?await aa(l,T):await la(l,T[0]),await _e(!1)}catch(te){fe.error(te instanceof Error?te.message:o(F==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[l,_e,o]),Yt=u.useCallback((T,F=!1)=>{U({type:"diff",path:T,staged:F})},[U]),Qt=u.useCallback(async T=>{if(l){J(F=>new Set(F).add(T));try{await a.revertGitFile(l,T),fe.success(o("gitView.toast.revertedFile",{path:T})),await _e(!1)}catch(F){fe.error(F instanceof Error?F.message:o("gitView.toast.revertFailed"))}finally{J(F=>{const te=new Set(F);return te.delete(T),te})}}},[l,a,_e,o]),Et=u.useCallback(async T=>{if(!l||T.length===0||H)return;const F=Array.from(new Set(T));X(!0),J(new Set(F));try{await Promise.all(F.map(te=>a.revertGitFile(l,te))),await _e(!1),fe.success(F.length===1?o("gitView.toast.revertedFilesSingle",{count:F.length}):o("gitView.toast.revertedFilesPlural",{count:F.length}))}catch(te){fe.error(te instanceof Error?te.message:o("gitView.toast.revertFailed"))}finally{J(new Set),X(!1)}},[l,a,H,_e,o]),ws=u.useCallback(T=>{const F=T.map(te=>te.trim()).filter(Boolean);if(F.length===0){ue([]);return}_(te=>`${te.trim()}${te.trim()?`
23
+
24
+ `:""}${F.join(`
25
+ `)}`.trim()),ue([])},[]),Zs=u.useCallback(async()=>{if(!l)return;const T=Re.map(F=>F.path).sort();if(T.length===0){fe.error(o("gitView.toast.selectFileToDescribe"));return}re(!0);try{const{message:F}=await wr(l,T);_(F.subject?.trim()??""),ue(Array.isArray(F.highlights)?F.highlights:[])}catch(F){fe.error(F instanceof Error?F.message:o("gitView.toast.generateCommitMessageFailed"))}finally{re(!1)}},[l,Re,o]),Pt=async(T={})=>{if(!l)return;if(!W.trim()){fe.error(o("gitView.toast.enterCommitMessage"));return}const F=Re.map(te=>te.path).sort();if(F.length===0){fe.error(o("gitView.toast.selectFileToCommit"));return}ee(T.pushAfter?"commitAndPush":"commit");try{if(await a.createGitCommit(l,W.trim(),{files:F}),fe.success(o("gitView.toast.commitCreated")),_(""),ue([]),T.pushAfter){const te=p?.tracking?.split("/")[0],we=Oe.find(Ze=>Ze.name===te)??Oe[0];if(!we)throw new Error(o("mobile.changes.noRemote"));L("sync"),await Sr({git:a,directory:l,remote:we,dirtyWorktreeError:o("gitView.toast.commitOrStashBeforeSync"),onPushed:Ze=>{fe.success(o("gitView.toast.pushedToUpstream",{name:Ze.pushed[0].remote}))}}),await _e(!1),await Rt()}else await _e(!1)}catch(te){fe.error(te instanceof Error?te.message:o("gitView.toast.createCommitFailed"))}finally{ee(null),T.pushAfter&&L(null)}},js=u.useMemo(()=>{const T=[];return Re.length>0&&T.push({id:"staged",title:o("gitView.changes.stagedTitle"),entries:Re,statsScope:"staged",actionSymbol:"-",actionAllLabel:o("gitView.changes.unstageAllAria"),getActionLabel:F=>o("gitView.changes.unstageFileAria",{path:F}),onActionFile:F=>{pt([F],"unstage")},onActionAll:F=>{pt(F,"unstage")},onViewDiff:F=>Yt(F,!0),onRevertFile:Qt,showRevertActions:!1,accent:!0}),ot.length>0&&T.push({id:"unstaged",title:o("gitView.changes.title"),entries:ot,statsScope:"working",actionSymbol:"+",actionAllLabel:o("gitView.changes.stageAllAria"),getActionLabel:F=>o("gitView.changes.stageFileAria",{path:F}),onActionFile:F=>{pt([F],"stage")},onActionAll:F=>{pt(F,"stage")},onViewDiff:F=>Yt(F,!1),onRevertFile:Qt}),T},[Qt,Yt,pt,Re,o,ot]),lt=T=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":o("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:o("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:p?.current||l||""})]}),c===!1&&Array.isArray(d)&&d.length>0?t.jsx(bl,{repositories:d,selectedRepository:f??null,onSelectRepository:F=>{n&&v(n,F)},repositoryRoot:n??void 0}):null]}),t.jsx("div",{className:"min-h-0 flex-1",children:T})]});if(!l)return lt(t.jsx(qe,{message:o("gitView.empty.selectSessionOrDirectory")}));if(c===!1&&h!==!0)return lt(t.jsx(xl,{rootIsGitRepo:c,resolvedIsGitRepo:h,nestedRepos:d,onRetryDiscovery:()=>{n&&E(n,{force:!0})}}));if(b&&h===null)return lt(t.jsx(qe,{loading:!0,message:o("gitView.loading.checkingRepository")}));if(I.type==="diff")return t.jsx(Yr,{path:I.path,diff:bs,staged:I.staged,fileExists:!!Qs,unavailableReason:Ae?.key===`${l}\0${I.path}`?Ae.reason:null,error:Ce,onBack:()=>U({type:"list"}),onRetry:()=>dt(T=>T+1)});const Xt=o(j==="pr"?"session.githubIntegration.tabs.pullRequests":j==="branch"?"diffView.scope.branch":j==="commit"?"commitComparison.mode":"mobile.nav.changes"),Zt=j==="branch"&&Ue.base?pl(Ue.base):j==="commit"?ft?.slice(0,8):j==="pr"&&mt?`#${mt.number}`:null;if(Ye&&Qe)return t.jsx(Yr,{path:Ye,subtitle:[Xt,Zt].filter(Boolean).join(" · "),diff:Qe.status==="ready"?Qe.diff:null,fileExists:!je.files||je.files.some(T=>T.path===Ye),error:je.error??(Qe.status==="error"?Qe.message:null),onBack:()=>U(It),onRetry:()=>{je.error&&je.refresh(),Jt(T=>T+1)}});const ks=()=>j==="pr"&&!mt?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx(qe,{loading:nt.loading,message:nt.error??(nt.loading?o("session.githubPrPicker.loading.pullRequests"):o("pullRequestComparison.select"))}),!nt.loading&&t.jsx(Nr,{mobile:!0,comparison:nt})]}):j==="branch"&&!Ue.base?t.jsx(qe,{loading:!Ue.resolved,message:Ue.resolved?o("gitView.pr.toast.baseBranchRequired"):o("diffView.branch.resolvingBase")}):j==="commit"&&!ft?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[$e.loading&&t.jsx(Z,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:$e.loading?o("diffView.state.loadingChanges"):$e.error??o("commitComparison.noCommits")}),$e.error&&t.jsx(ge,{variant:"outline",size:"lg",onClick:()=>{$e.refresh()},children:o("diffView.actions.retry")})]}):je.error?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx("p",{className:"typography-ui-label font-semibold",children:o("diffView.state.failedToLoadDiff")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:je.error}),t.jsx(ge,{variant:"outline",size:"lg",onClick:()=>{je.refresh()},children:o("diffView.actions.retry")})]}):qt?qt.length===0?t.jsx(qe,{icon:j==="branch",message:j==="pr"?o("walkthrough.blocked.emptyDiff.description"):j==="commit"?o("commitComparison.emptyDiff"):o("diffView.branch.empty",{base:Zt??""})}):t.jsx(yd,{files:qt,onSelect:T=>{je.key&&U({type:"comparison",path:T,sourceKey:je.key})}}):t.jsx(qe,{loading:!0,message:o("diffView.state.loadingChanges")});return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":o("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"close",className:"size-5"})}):null,t.jsxs(ca,{open:$,onOpenChange:w,children:[t.jsx(ua,{asChild:!0,children:t.jsxs(ge,{variant:"outline",className:da({size:"default"}),"data-mobile-comparison-trigger":!0,"aria-label":o("diffView.scope.selectorAria"),children:[t.jsx("span",{children:Xt}),t.jsx(Z,{name:"arrow-down-s",className:"size-4"})]})}),t.jsx(fa,{align:"start",children:t.jsxs(ma,{value:j,onValueChange:T=>{(T==="working"||T==="branch"||T==="commit"||T==="pr")&&B(T)},children:[t.jsx(As,{value:"working",className:"min-h-8 items-center",children:o("mobile.nav.changes")}),hs&&t.jsx(As,{value:"branch",className:"min-h-8 items-center",children:o("diffView.scope.branch")}),t.jsx(As,{value:"commit",className:"min-h-8 items-center",children:o("commitComparison.mode")}),t.jsx(As,{value:"pr",className:"min-h-8 items-center",children:o("session.githubIntegration.tabs.pullRequests")})]})})]}),r&&j==="branch"&&t.jsx(oc,{mobile:!0,branches:g?.all??[],currentBranch:Ne,base:Ue.base,onSelect:T=>{Ne&&Js(l,Ne,T)}},JSON.stringify([k,Ne])),r&&j==="commit"&&t.jsx(ac,{mobile:!0,commits:$e.commits,selectedHash:ft,loading:$e.loading,error:$e.error,onSelect:$e.select,onRefresh:()=>{$e.refresh()}},JSON.stringify([k,Ne])),r&&j==="pr"&&t.jsxs(t.Fragment,{children:[t.jsx(Nr,{mobile:!0,comparison:nt},JSON.stringify([k,Ne])),mt&&t.jsx(ge,{variant:"ghost",size:"sm",disabled:je.loading,"aria-label":o("session.githubIssuePicker.actions.refresh"),onClick:()=>{je.refresh()},children:t.jsx(Z,{name:"refresh",className:"size-4"})})]})]}),j==="working"&&t.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(hl,{currentBranch:p?.current,localBranches:Ee,remoteBranches:xs,branchInfo:g?.branches,currentBranchAhead:p?.ahead,onCheckout:T=>{ys(T)},onCreate:Xs,remotes:Oe,disabled:b,directory:l,switchBlockedNotice:(p?.files?.length??0)>0?o("gitView.branch.switchBlockedNotice"):null})}),t.jsx(gl,{syncAction:O,remotes:Oe,onFetch:T=>{vs("fetch",T)},onSync:T=>{vs("sync",T)},disabled:ie!==null||b,aheadCount:p?.ahead??0,behindCount:p?.behind??0,trackingRemoteName:p?.tracking?.split("/")[0],hasUncommittedChanges:Ge.length>0})]}),j!=="working"?t.jsx("div",{className:"min-h-0 flex-1",children:ks()}):Ge.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(Ql,{groups:js,diffStats:p?.diffStats,revertingPaths:G,onRevertAll:Et,isRevertingAll:H,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:oe})}),t.jsx("div",{className:"shrink-0 border-t border-border/70 px-4 pb-4 pt-3",children:t.jsx(Xl,{stagedCount:Re.length,commitMessage:W,onCommitMessageChange:_,generatedHighlights:ce,onInsertHighlights:ws,onGenerateMessage:Zs,isGeneratingMessage:ne,onCommit:()=>{Pt({pushAfter:!1})},onCommitAndPush:()=>{Pt({pushAfter:!0})},commitAction:ie,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(qe,{icon:!0,message:o("gitView.empty.cleanTitle"),description:o("mobile.changes.cleanDescription")})}),t.jsx(Zl,{open:De!==null,onOpenChange:T=>{T||Be(null)},targetBranch:De??"",changedFileCount:p?.files?.length??0,onCommitAndSwitch:async(T,F)=>{const te=De;if(!te||!l)return;const we=p?.current??null;await a.createGitCommit(l,T,{addAll:!0});let Ze=null;if(F){const en=p?.tracking?.split("/")[0],At=Oe.find(tn=>tn.name===en)??Oe[0];try{if(!At)throw new Error(o("mobile.changes.noRemote"));await a.gitPush(l,p?.tracking?{remote:At.name}:{remote:At.name,branch:we??void 0,options:["--set-upstream"]}),Ze=At.name}catch{fe.error(o("gitView.dirtySwitch.pushFailed")),await _e(),Be(null);return}}fe.success(we?Ze?o("gitView.toast.pushedToUpstream",{name:Ze}):o("gitView.dirtySwitch.committedNotPushed",{branch:we}):o("gitView.toast.commitCreated")),await _e(),Be(null),await at(te)},onGenerateMessage:async()=>{if(!l)return"";const T=(p?.files??[]).map(te=>te.path).sort(),{message:F}=await wr(l,T);return F.subject?.trim()??""},onRevertAndSwitch:async()=>{const T=De;if(!T||!l)return;await Et((p?.files??[]).map(te=>te.path));const F=await a.getGitStatus(l);if(!F.isClean&&(F.files?.length??0)>0){fe.error(o("gitView.dirtySwitch.revertIncomplete"));return}Be(null),await at(T)}})]})},qe=n=>{const e=le.c(13),{message:s,description:i,loading:r,icon:o}=n,a=r===void 0?!1:r,c=o===void 0?!1:o;let f;e[0]!==a?(f=a?t.jsx(Z,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=f):f=e[1];let d;e[2]!==c?(d=c?t.jsx(Z,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=c,e[3]=d):d=e[3];let l;e[4]!==s?(l=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[4]=s,e[5]=l):l=e[5];let p;e[6]!==i?(p=i?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i}):null,e[6]=i,e[7]=p):p=e[7];let g;return e[8]!==f||e[9]!==d||e[10]!==l||e[11]!==p?(g=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[f,d,l,p]})}),e[8]=f,e[9]=d,e[10]=l,e[11]=p,e[12]=g):g=e[12],g},Yr=n=>{const e=le.c(31),{path:s,subtitle:i,diff:r,staged:o,fileExists:a,unavailableReason:c,error:f,onBack:d,onRetry:l}=n,p=o===void 0?!1:o,g=c===void 0?null:c,{t:h}=me();let b;e[0]!==s?(b=pa(s)||"text",e[0]=s,e[1]=b):b=e[1];const S=b;let x;e[2]!==h?(x=h("header.actions.backAria"),e[2]=h,e[3]=x):x=e[3];let E;e[4]===Symbol.for("react.memo_cache_sentinel")?(E=t.jsx(Z,{name:"arrow-left",className:"size-5"}),e[4]=E):E=e[4];let v;e[5]!==d||e[6]!==x?(v=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":x,onClick:d,children:E}),e[5]=d,e[6]=x,e[7]=v):v=e[7];let N;e[8]!==s?(N=t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:s}),e[8]=s,e[9]=N):N=e[9];let A;e[10]!==i?(A=i&&t.jsx("p",{className:"truncate typography-meta text-muted-foreground",children:i}),e[10]=i,e[11]=A):A=e[11];let y;e[12]!==N||e[13]!==A?(y=t.jsxs("div",{className:"min-w-0 flex-1 px-2",children:[N,A]}),e[12]=N,e[13]=A,e[14]=y):y=e[14];let P;e[15]!==v||e[16]!==y?(P=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/70 px-3 text-foreground",children:[v,y]}),e[15]=v,e[16]=y,e[17]=P):P=e[17];let C;e[18]!==r||e[19]!==f||e[20]!==a||e[21]!==S||e[22]!==l||e[23]!==s||e[24]!==p||e[25]!==h||e[26]!==g?(C=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:a?g==="nested_repository"?t.jsx(qe,{icon:!0,message:h("diffView.unavailable.nestedRepositoryTitle"),description:h("diffView.unavailable.nestedRepositoryDescription")}):g==="untracked_directory"?t.jsx(qe,{icon:!0,message:h("diffView.unavailable.untrackedDirectoryTitle"),description:h("diffView.unavailable.untrackedDirectoryDescription")}):f?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:h("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:f}),t.jsx(ge,{type:"button",size:"sm",variant:"outline",onClick:l,children:h("diffView.actions.retry")})]})}):r?r.submodule?t.jsx("div",{className:"p-3",children:t.jsx(dc,{state:r.submodule,staged:p})}):r.isBinary?t.jsx(qe,{icon:!0,message:h("diffView.binary.unavailable")}):ha(s)&&!r.fileDiff?t.jsx(qe,{icon:!0,message:h("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(Ks,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(mc,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:S,fileName:s,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(qe,{loading:!0,message:h("diffView.state.loadingDiff")}):t.jsx(qe,{icon:!0,message:h("mobile.changes.diffDetail.missingTitle"),description:h("mobile.changes.diffDetail.missingDescription")})}),e[18]=r,e[19]=f,e[20]=a,e[21]=S,e[22]=l,e[23]=s,e[24]=p,e[25]=h,e[26]=g,e[27]=C):C=e[27];let R;return e[28]!==P||e[29]!==C?(R=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[P,C]}),e[28]=P,e[29]=C,e[30]=R):R=e[30],R},yd=n=>{const e=le.c(12),{files:s,onSelect:i}=n,{t:r}=me();let o;e[0]!==r?(o=r("gitView.changes.changedFilesAria"),e[0]=r,e[1]=o):o=e[1];let a;if(e[2]!==s||e[3]!==i||e[4]!==r){let f;e[6]!==i||e[7]!==r?(f=d=>{const l=d.status==="A"?r("diffView.change.new"):d.status==="D"?r("diffView.change.deleted"):d.status==="R"?r("diffView.change.renamed"):d.status==="C"?r("diffView.change.copied"):r("diffView.change.modified"),p=d.status==="A"?"var(--status-success)":d.status==="D"?"var(--status-error)":d.status==="R"||d.status==="C"?"var(--status-info)":"var(--status-warning)";return t.jsx("li",{children:t.jsxs(ge,{variant:"ghost",size:"lg",className:"w-full justify-start gap-2.5 text-left normal-case",onClick:()=>i(d.path),children:[t.jsx("span",{className:"w-4 shrink-0 text-center typography-meta font-semibold uppercase",style:{color:p},"aria-label":l,children:d.status}),t.jsx(vi,{filePath:d.path,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label",title:d.path,children:d.path}),(d.insertions>0||d.deletions>0)&&t.jsxs("span",{className:"shrink-0 typography-meta text-muted-foreground",children:["+",d.insertions," -",d.deletions]}),t.jsx(Z,{name:"arrow-right-s",className:"size-4 shrink-0 text-muted-foreground"})]})},d.path)},e[6]=i,e[7]=r,e[8]=f):f=e[8],a=s.map(f),e[2]=s,e[3]=i,e[4]=r,e[5]=a}else a=e[5];let c;return e[9]!==o||e[10]!==a?(c=t.jsx(Ks,{className:"h-full overflow-y-auto overflow-x-hidden px-3 py-2",children:t.jsx("ul",{"aria-label":o,className:"flex flex-col gap-1",children:a})}),e[9]=o,e[10]=a,e[11]=c):c=e[11],c},vd=u.lazy(()=>$t(()=>import("./FilesView-DUCLmHBi.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126])).then(n=>({default:n.FilesView}))),ut=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),us=n=>{const e=ut(n);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},wd=n=>{const e=ut(n);if(!e||e==="/")return null;const s=e.lastIndexOf("/");return s<=0?e.startsWith("/")?"/":null:e.slice(0,s)},jd=(n,e)=>{const s=ut(n),i=ut(e);return!i||s===i?us(s):s.startsWith(`${i}/`)?s.slice(i.length+1):s},kd=n=>{if(typeof n!="number"||!Number.isFinite(n)||n<0)return"";if(n<1024)return`${n} B`;const e=["KB","MB","GB"];let s=n/1024;for(const i of e){if(s<1024||i===e[e.length-1])return`${s.toFixed(s>=10?0:1)} ${i}`;s/=1024}return""},Sd=n=>{const e=le.c(5),{onClose:s}=n,i=Dn()??null;let r;e[0]!==i?(r=ut(i),e[0]=i,e[1]=r):r=e[1];const o=r;let a;return e[2]!==s||e[3]!==o?(a=t.jsx(Nd,{root:o,onClose:s},o),e[2]=s,e[3]=o,e[4]=a):a=e[4],a},Nd=({root:n,onClose:e})=>{const{t:s}=me(),{files:i}=Tn(),r=yo(W=>W.setSelectedPath),[o,a]=u.useState(()=>({type:"browser",directory:n})),[c,f]=u.useState([]),[d,l]=u.useState(!1),[p,g]=u.useState(null),[h,b]=u.useState(""),[S,x]=u.useState([]),[E,v]=u.useState(!1),N=u.useRef(0),A=o.type==="browser"?o.directory:o.returnDirectory,y=u.useRef(A);y.current=A;const P=u.useCallback(async W=>{if(!W)return;const _=N.current+1;N.current=_,l(!0),g(null);try{const G=await i.listDirectory(W);if(N.current!==_)return;f(G.entries.slice().sort((J,H)=>J.isDirectory!==H.isDirectory?J.isDirectory?-1:1:J.name.localeCompare(H.name)))}catch(G){if(N.current!==_)return;f([]),g(G instanceof Error?G.message:s("mobile.files.error.listFailed"))}finally{N.current===_&&l(!1)}},[i,s]);u.useEffect(()=>{o.type==="browser"&&P(o.directory)},[P,o]);const C=u.useCallback(async W=>{ut(W)===ut(y.current)&&await P(y.current)},[P]),{canUpload:R,uploadingDirectory:k,pickFiles:z,uploadElements:D}=yl({root:n,refreshDirectory:C}),M=k!==null;u.useEffect(()=>{if(o.type!=="browser")return;const W=h.trim();if(!W){x([]),v(!1);return}let _=!1;const G=window.setTimeout(()=>{v(!0),i.search({directory:o.directory,query:W,maxResults:40}).then(J=>{_||x(J)}).catch(()=>{_||x([])}).finally(()=>{_||v(!1)})},250);return()=>{_=!0,window.clearTimeout(G)}},[i,h,o]);const j=W=>{b(""),a({type:"browser",directory:W})},I=W=>{r(n,W),a({type:"file",path:W,returnDirectory:A||n})},$=it(W=>W.pendingFileFocusPath),w=it(W=>W.pendingFileNavigation);if(u.useEffect(()=>{const W=ut(w?.path??$??"");!W||!n||W!==n&&!W.startsWith(`${n}/`)||(r(n,W),a({type:"file",path:W,returnDirectory:n}),$&&it.getState().setPendingFileFocusPath(null))},[$,w,n,r]),!n)return t.jsx(ds,{message:s("mobile.files.empty.noDirectory")});if(o.type==="file")return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 border-b border-border/70 px-3 text-foreground",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":s("header.actions.backAria"),onClick:()=>a({type:"browser",directory:o.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(kr,{className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:us(o.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Ve,{children:t.jsx(u.Suspense,{fallback:t.jsx(ds,{loading:!0,message:s("filesView.state.loading")}),children:t.jsx(vd,{mode:"editor-only"})})})})]});const B=o.directory===n?s("mobile.files.rootDirectory"):us(o.directory),U=h.trim()?S:[],O=wd(o.directory),L=o.directory!==n&&O!==null&&(O===n||O.startsWith(`${n}/`)),ie=L&&!h.trim(),ee=L?O:null;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[D,t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[e?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":s("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Vl,{className:"size-5"})}):null,ie&&ee?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":s("mobile.files.backToParentAria",{name:us(ee)}),onClick:()=>j(ee),style:{touchAction:"manipulation"},children:t.jsx(kr,{className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:B})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":s("mobile.files.refreshAria"),onClick:()=>{P(o.directory)},style:{touchAction:"manipulation"},children:t.jsx(Ul,{className:Q("size-5",d&&"animate-spin")})}),R?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50","aria-label":s("sidebarFilesTree.actions.uploadFilesTitle"),onClick:()=>z(o.directory),disabled:M,style:{touchAction:"manipulation"},children:t.jsx(Z,{name:M?"loader-4":"upload-2",className:Q("size-5",M&&"animate-spin")})}):null]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(Gl,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(gi,{value:h,onChange:W=>b(W.target.value),placeholder:s("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(Ks,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:p?t.jsx(ds,{message:p}):h.trim()?t.jsx(Cd,{results:U,isSearching:E,onOpenFile:I}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:[c.length===0&&!d?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:s("mobile.files.empty.directory")}):null,c.map(W=>t.jsx(Xi,{name:W.name,path:W.path,directory:W.isDirectory,meta:W.isDirectory?void 0:kd(W.size),onClick:()=>W.isDirectory?j(W.path):I(W.path)},W.path))]})})]})},Xi=n=>{const e=le.c(16),{name:s,path:i,directory:r,meta:o,onClick:a}=n;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={touchAction:"manipulation"},e[0]=c):c=e[0];let f;e[1]!==r||e[2]!==i?(f=r?t.jsx(ql,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(vi,{filePath:i,className:"size-5 shrink-0"}),e[1]=r,e[2]=i,e[3]=f):f=e[3];let d;e[4]!==s?(d=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s}),e[4]=s,e[5]=d):d=e[5];let l;e[6]!==o?(l=o?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:o}):null,e[6]=o,e[7]=l):l=e[7];let p;e[8]!==r?(p=r?t.jsx(Jl,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=r,e[9]=p):p=e[9];let g;return e[10]!==a||e[11]!==f||e[12]!==d||e[13]!==l||e[14]!==p?(g=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:a,style:c,children:[f,d,l,p]}),e[10]=a,e[11]=f,e[12]=d,e[13]=l,e[14]=p,e[15]=g):g=e[15],g},Cd=n=>{const e=le.c(10),{results:s,isSearching:i,onOpenFile:r}=n,{t:o}=me(),a=ut(Dn()??null);if(i){let l;e[0]!==o?(l=o("common.loading"),e[0]=o,e[1]=l):l=e[1];let p;return e[2]!==l?(p=t.jsx(ds,{loading:!0,message:l}),e[2]=l,e[3]=p):p=e[3],p}if(s.length===0){let l;e[4]!==o?(l=o("mobile.files.search.empty"),e[4]=o,e[5]=l):l=e[5];let p;return e[6]!==l?(p=t.jsx(ds,{message:l}),e[6]=l,e[7]=p):p=e[7],p}const c="overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",f=s.map(l=>t.jsx(Xi,{name:us(l.path),path:l.path,directory:!1,meta:jd(l.path,a),onClick:()=>r(l.path)},l.path));let d;return e[8]!==f?(d=t.jsx("div",{className:c,children:f}),e[8]=f,e[9]=d):d=e[9],d},ds=n=>{const e=le.c(7),{message:s,loading:i}=n,r=i===void 0?!1:i;let o;e[0]!==r?(o=r?t.jsx(Kl,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(Hl,{className:"size-6 text-muted-foreground"}),e[0]=r,e[1]=o):o=e[1];let a;e[2]!==s?(a=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[2]=s,e[3]=a):a=e[3];let c;return e[4]!==o||e[5]!==a?(c=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[o,a]})}),e[4]=o,e[5]=a,e[6]=c):c=e[6],c},Qr="mobile-surface-root",Rd=16,Xr=320,Ed="cubic-bezier(0.22, 1, 0.36, 1)",Pd=n=>{const e=le.c(36),{onOpenMcpSettings:s}=n,{t:i}=me(),[r,o]=u.useState(!1),a=gt(Id),c=is(Td),f=Ot(Dd);let d;e[0]!==a||e[1]!==r||e[2]!==f||e[3]!==c?(d=()=>{if(r)return;o(!0);const z=new Promise(_d);Promise.all([c({directory:a||null,silent:!0}),f({force:!0}),z]).finally(()=>o(!1))},e[0]=a,e[1]=r,e[2]=f,e[3]=c,e[4]=d):d=e[4];const l=d;let p;e[5]!==i?(p=i("settings.mcp.sidebar.actions.addServerTitle"),e[5]=i,e[6]=p):p=e[6];let g;e[7]!==i?(g=i("settings.mcp.sidebar.actions.addServerTitle"),e[7]=i,e[8]=g):g=e[8];let h,b;e[9]===Symbol.for("react.memo_cache_sentinel")?(h={touchAction:"manipulation"},b=t.jsx(Z,{name:"add",className:"size-5"}),e[9]=h,e[10]=b):(h=e[9],b=e[10]);let S;e[11]!==s||e[12]!==p||e[13]!==g?(S=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:s,"aria-label":p,title:g,style:h,children:b}),e[11]=s,e[12]=p,e[13]=g,e[14]=S):S=e[14];let x;e[15]!==i?(x=i("mcpDropdown.actions.refreshAria"),e[15]=i,e[16]=x):x=e[16];let E;e[17]!==i?(E=i("mcpDropdown.actions.refreshAria"),e[17]=i,e[18]=E):E=e[18];let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v={touchAction:"manipulation"},e[19]=v):v=e[19];const N=r&&"animate-spin";let A;e[20]!==N?(A=Q("size-5",N),e[20]=N,e[21]=A):A=e[21];let y;e[22]!==A?(y=t.jsx(Z,{name:"refresh",className:A}),e[22]=A,e[23]=y):y=e[23];let P;e[24]!==r||e[25]!==l||e[26]!==y||e[27]!==x||e[28]!==E?(P=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:l,disabled:r,"aria-label":x,title:E,style:v,children:y}),e[24]=r,e[25]=l,e[26]=y,e[27]=x,e[28]=E,e[29]=P):P=e[29];let C;e[30]!==P||e[31]!==S?(C=t.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1 px-2 pt-1",children:[S,P]}),e[30]=P,e[31]=S,e[32]=C):C=e[32];let R;e[33]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(md,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})}),e[33]=R):R=e[33];let k;return e[34]!==C?(k=t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[C,R]}),e[34]=C,e[35]=k):k=e[35],k},Ad=({open:n,onClose:e,tab:s,onTabChange:i,pendingChangesDiff:r,onOpenPlan:o,onOpenMcpSettings:a,variant:c="drawer"})=>{const{t:f}=me(),d=u.useRef(null),l=u.useRef(null),[p,g]=u.useState(!1),[h,b]=u.useState(n),S=u.useRef(e);u.useEffect(()=>{S.current=e},[e]);const x=u.useRef(s);u.useEffect(()=>{x.current=s},[s]),sr(l,{enabled:c==="drawer"&&n,onLeftEdgeSwipe:()=>S.current()});const[E,v]=u.useState(()=>new Set);if(u.useEffect(()=>{n&&v(y=>{if(y.has(s))return y;const P=new Set(y);return P.add(s),P})},[n,s]),typeof document<"u"&&!d.current){let y=document.getElementById(Qr);y||(y=document.createElement("div"),y.id=Qr,document.body.appendChild(y)),d.current=y}if(u.useEffect(()=>{if(n){b(!0);const P=window.setTimeout(()=>g(!0),Rd);return()=>window.clearTimeout(P)}g(!1);const y=window.setTimeout(()=>b(!1),Xr+40);return()=>window.clearTimeout(y)},[n]),u.useEffect(()=>{if(!n)return;const y=document.body.style.overflow;c==="drawer"&&(document.body.style.overflow="hidden");const P=C=>{C.key!=="Escape"||x.current==="terminal"||ba(C.target)||S.current()};return document.addEventListener("keydown",P),()=>{c==="drawer"&&(document.body.style.overflow=y),document.removeEventListener("keydown",P)}},[n,c]),c==="drawer"&&!d.current)return null;const N=[{id:"changes",label:f("mobile.menu.changes"),icon:t.jsx(Z,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"files",label:f("mobile.menu.files"),icon:t.jsx(Z,{name:"file-text",className:"h-3.5 w-3.5"})},{id:"terminal",label:f("mobile.menu.terminal"),icon:t.jsx(Z,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"notes",label:f("contextRail.surface.notes"),icon:t.jsx(Z,{name:"sticky-note",className:"h-3.5 w-3.5"})},{id:"mcp",label:f("mobile.menu.mcp"),icon:t.jsx(ga,{className:"h-3.5 w-3.5"})}],A=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("div",{className:"flex h-9 min-w-0 flex-1 items-center",children:h?t.jsx(vl,{items:N,activeId:s,onSelect:y=>i(y),layoutMode:"fit",variant:"active-pill",nonCompositedIndicator:!0,inactiveTabsIconOnly:!0,className:"h-full"}):null}),t.jsx("button",{type:"button",className:"-mr-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":f("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(Z,{name:"close",className:"size-5"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[E.has("changes")?t.jsx("div",{className:Q("h-full",s!=="changes"&&"hidden"),children:t.jsx(Ve,{children:t.jsx(bd,{visible:n&&s==="changes",initialDiff:r})})},r?`changes:${r.path}:${r.staged}`:"changes"):null,E.has("files")?t.jsx("div",{className:Q("h-full",s!=="files"&&"hidden"),children:t.jsx(Ve,{children:t.jsx(Sd,{})})}):null,E.has("terminal")?t.jsx("div",{className:Q("h-full",s!=="terminal"&&"hidden"),children:t.jsx(Ve,{children:t.jsx(wl,{visible:n&&s==="terminal"})})}):null,E.has("notes")?t.jsx("div",{className:Q("h-full",s!=="notes"&&"hidden"),children:t.jsx(Ve,{children:t.jsx(jl,{onActionComplete:e,onOpenPlan:o})})}):null,E.has("mcp")?t.jsx("div",{className:Q("h-full",s!=="mcp"&&"hidden"),children:t.jsx(Ve,{children:t.jsx(Pd,{onOpenMcpSettings:a})})}):null]})]});return c==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:A}):Lt.createPortal(t.jsx("section",{ref:l,role:"dialog","aria-modal":"true","aria-label":f("mobile.header.openWorkspaceAria"),"aria-hidden":!n,className:"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:p?"none":"translateX(100%)",transition:`transform ${Xr}ms ${Ed}`,visibility:h?"visible":"hidden",pointerEvents:n?"auto":"none"},children:A}),d.current)};function Id(n){return n.currentDirectory}function Td(n){return n.refresh}function Dd(n){return n.loadMcpConfigs}function _d(n){return window.setTimeout(n,500)}function Md(n){const e=le.c(4),s=2500,{uiFont:i}=xa(),[r,o]=u.useState(!1);let a,c;return e[0]!==s||e[1]!==i?(a=()=>{let f=!1;const d=()=>{f||o(!0)},l=()=>{requestAnimationFrame(()=>requestAnimationFrame(d))},p=Promise.all([ya(i).catch($d),document.fonts?.ready?.then(Ld).catch(Bd)??Promise.resolve(),pc.catch(Od)]).then(zd),g=new Promise(h=>{window.setTimeout(h,s)});return Promise.race([p,g]).then(l),()=>{f=!0}},c=[i,s],e[0]=s,e[1]=i,e[2]=a,e[3]=c):(a=e[2],c=e[3]),u.useEffect(a,c),r}function zd(){}function Od(){}function Bd(){}function Ld(){}function $d(){}const Fd="openchamber",Wd=n=>n.replace(/^\/+|\/+$/g,""),Vd=n=>{const e=Wd(n.pathname).split("/").filter(Boolean);return n.host?[n.host,...e]:e};function Ud(n){if(typeof n!="string"||n.length===0)return null;let e;try{e=new URL(n)}catch{return null}if(e.protocol!==`${Fd}:`)return null;const s=Vd(e),i=(s[0]??"").toLowerCase(),r=s.slice(1),o=e.searchParams;switch(i){case"session":{const a=r[0]||o.get("id")||"";return a?{type:"session",sessionId:a,directory:o.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:o.get("dir")??void 0,projectId:o.get("project")??void 0,agent:o.get("agent")??void 0,model:o.get("model")??void 0};case"sessions":{const a=o.get("filter");return{type:"sessions",filter:a==="attention"||a==="recent"||a==="all"?a:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:r[0]||o.get("section")||void 0};case"changes":return{type:"changes",path:r.join("/")||o.get("path")||void 0,staged:o.get("staged")==="true"};case"view":{const a=(r[0]||"").toLowerCase();return a==="changes"?{type:"changes"}:a==="files"||a==="mcp"||a==="instances"||a==="update"?{type:"view",target:a}:null}default:return null}}let Ke={},Zi=!1,cs=null;const Gd=n=>{switch(n.type){case"session":return Se.getState().setCurrentSession(n.sessionId,n.directory??null),!0;case"new-session":{const e=Se.getState();return e.openNewSessionDraft(),(n.directory||n.projectId)&&e.setNewSessionDraftTarget({directoryOverride:n.directory??null,projectId:n.projectId??null,selectedProjectId:n.projectId??null}),!0}case"sessions":return Ke.openSessions?(Ke.openSessions(n.filter),!0):!1;case"status":return Ke.openSessions?(Ke.openSessions(),!0):!1;case"view":return Ke.openView?(Ke.openView(n.target),!0):!1;case"changes":return Ke.openChanges?(Ke.openChanges({path:n.path,staged:n.staged}),!0):!1;case"settings":return Ke.openSettings?(Ke.openSettings(n.section),!0):!1}},nr=()=>{if(!Zi||!cs)return;const n=cs;cs=null,Gd(n)||(cs=n)},eo=n=>{cs=n,nr()},Zr=n=>{const e=Ud(n);e&&eo(e)},Kd=n=>{Zi=n,nr()},Hd=n=>{const e=le.c(3);let s,i;e[0]!==n?(s=()=>(Ke=n,nr(),()=>{Ke===n&&(Ke={})}),i=[n],e[0]=n,e[1]=s,e[2]=i):(s=e[1],i=e[2]),u.useEffect(s,i)},qd=n=>{const{ready:e}=n;u.useEffect(()=>{Kd(e)},[e]),u.useEffect(()=>{if(!Te())return;let s=!1;const i=[];return $t(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([127,5,128])).then(async({App:r})=>{if(s)return;const o=await r.addListener("appUrlOpen",a=>{Zr(a?.url)});if(s){o.remove();return}i.push(()=>{o.remove()})}).catch(()=>{}),$t(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([129,128])).then(async({PushNotifications:r})=>{if(s)return;const o=await r.addListener("pushNotificationActionPerformed",a=>{const c=a?.notification?.data,f=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(f){Zr(f);return}const d=typeof c?.sessionId=="string"?c.sessionId:void 0;d&&eo({type:"session",sessionId:d})});if(s){o.remove();return}i.push(()=>{o.remove()})}).catch(()=>{}),()=>{s=!0,i.forEach(r=>r())}},[])},Jd=()=>{if(typeof window>"u")return;const n=window.__OPENCHAMBER_APNS_ENV__;if(n==="development")return"sandbox";if(n==="production")return"production"},Yd=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},Qd=n=>{const{enabled:e}=n,s=it(r=>r.nativeNotificationsEnabled),i=u.useRef(null);u.useEffect(()=>{if(!e||!s||!Yd())return;let r=!1;const o=[];return $t(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([129,128])).then(async({PushNotifications:a})=>{if(r)return;let c=await a.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await a.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const f=await a.addListener("registration",l=>{i.current=l.value,gr()?.push?.registerApnsToken?.({token:l.value,platform:ri(),environment:Jd()})}),d=await a.addListener("registrationError",l=>{console.warn("[Push] APNs registration error:",l)});if(await a.register().catch(()=>{}),r){f.remove(),d.remove();return}o.push(()=>{f.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{r=!0,o.forEach(a=>a())}},[e,s]),u.useEffect(()=>{if(s)return;const r=i.current;if(!r)return;i.current=null,gr()?.push?.unregisterApnsToken?.({token:r})},[s])},ei=n=>{const e=le.c(12),{side:s,isResizing:i,ariaLabel:r,handleProps:o}=n,a=s==="left"?"right-0":"left-0";let c;e[0]!==a?(c=Q("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",a),e[0]=a,e[1]=c):c=e[1];const f=s==="left"?"right-0":"left-0",d=i&&"bg-[var(--interactive-border)]";let l;e[2]!==f||e[3]!==d?(l=Q("absolute inset-y-0 w-[3px] transition-colors",f,d),e[2]=f,e[3]=d,e[4]=l):l=e[4];let p;e[5]!==l?(p=t.jsx("div",{className:l}),e[5]=l,e[6]=p):p=e[6];let g;return e[7]!==r||e[8]!==o||e[9]!==c||e[10]!==p?(g=t.jsx("div",{className:c,role:"separator","aria-orientation":"vertical","aria-label":r,...o,children:p}),e[7]=r,e[8]=o,e[9]=c,e[10]=p,e[11]=g):g=e[11],g},Xd=320,Zd=380,ti=280,ef=560,tf=900;function si(n,e,s,i){const r=le.c(23),o=i===void 0?ef:i,a=u.useRef(null);let c;r[0]!==s||r[1]!==o||r[2]!==e?(c=()=>{if(typeof window>"u")return s;const j=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(j)?Math.min(o,Math.max(ti,j)):s},r[0]=s,r[1]=o,r[2]=e,r[3]=c):c=r[3];const[f,d]=u.useState(c),[l,p]=u.useState(!1),g=u.useRef(0),h=u.useRef(f),b=u.useRef(null),S=u.useRef(null);let x;r[4]!==o?(x=j=>Math.min(o,Math.max(ti,Math.round(j))),r[4]=o,r[5]=x):x=r[5];const E=x;let v;r[6]===Symbol.for("react.memo_cache_sentinel")?(v=j=>{const I=a.current;I&&(I.style.width=`${j}px`,I.style.minWidth=`${j}px`,I.style.maxWidth=`${j}px`,I.style.setProperty("--oc-ipad-sidebar-width",`${j}px`))},r[6]=v):v=r[6];const N=v;let A;r[7]!==f?(A=j=>{try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}S.current=j.pointerId,g.current=j.clientX,h.current=f,b.current=f,p(!0),j.preventDefault()},r[7]=f,r[8]=A):A=r[8];const y=A;let P;r[9]!==E||r[10]!==n?(P=j=>{if(S.current!==j.pointerId)return;const I=j.clientX-g.current,$=E(h.current+(n==="left"?I:-I));b.current!==$&&(b.current=$,N($))},r[9]=E,r[10]=n,r[11]=P):P=r[11];const C=P;let R;r[12]!==E||r[13]!==e?(R=j=>{if(S.current!==j.pointerId)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const I=E(b.current??h.current);S.current=null,b.current=null,p(!1),d(I);try{window.localStorage.setItem(e,String(I))}catch{}},r[12]=E,r[13]=e,r[14]=R):R=r[14];const k=R;let z;r[15]!==y||r[16]!==k||r[17]!==C?(z={onPointerDown:y,onPointerMove:C,onPointerUp:k,onPointerCancel:k},r[15]=y,r[16]=k,r[17]=C,r[18]=z):z=r[18];const D=z;let M;return r[19]!==D||r[20]!==l||r[21]!==f?(M={asideRef:a,width:f,isResizing:l,handleProps:D},r[19]=D,r[20]=l,r[21]=f,r[22]=M):M=r[22],M}const sf=["general","appearance","chat","notifications","sessions","routing","git","magic-prompts","snippets","behavior","agents","commands","mcp","plugins","skills.installed","skills.catalog","providers","web-search","usage","voice","integrations","about"],nf=1e3,rf=({onActiveConnectionDeleted:n})=>{const{t:e}=me();Il();const[s,i]=u.useState(!1),[r,o]=u.useState(null),[a,c]=u.useState(!1),[f,d]=u.useState("changes"),[l,p]=u.useState(null),[g,h]=u.useState("nav"),[b,S]=u.useState(null),x=it(Y=>Y.setSettingsPage),E=it(Y=>Y.wideChatLayoutEnabled),v=Mt(Y=>Y.available),N=Mt(Y=>Y.runtimeType),A=u.useMemo(()=>_n(),[]),y=Ot(Y=>Y.mcpServers),P=Ot(Y=>Y.setMcpDraft),C=Ot(Y=>Y.setSelectedMcp),R=u.useCallback(()=>{o(null),p(null)},[]),k=u.useCallback(Y=>{o(Y)},[]),z=u.useCallback(()=>{c(!1)},[]),D=u.useCallback(Y=>{h(Y),k("settings")},[k]),{enabled:M,roomyForPanels:j}=Rn(),$=Fa()==="portrait",w=Wa(),[B,U]=u.useState(()=>Va().roomyForPanels),O=u.useCallback(()=>{U(Y=>!Y)},[]);u.useEffect(()=>{M||U(!1)},[M]);const L=u.useCallback(()=>{S(null),d("files"),c(!0)},[]);u.useEffect(()=>wi(Y=>{if(Y.type!=="file-open-request")return;const de=Y.directory??gt.getState().currentDirectory;de&&(it.getState().openContextFile(de,Y.path),L())}),[L]);const ie=u.useCallback((Y=null)=>{S(Y),d("changes"),c(!0)},[]),ee=si("left","openchamber.ipad.leftSidebarWidth",Xd),W=si("right","openchamber.ipad.rightSidebarWidth",Zd,tf),_=j,G=_&&a?W.width:0,J=M&&B?ee.width:0;u.useEffect(()=>{if(typeof document>"u")return;const Y=document.documentElement;return Y.style.setProperty("--oc-chat-inset-left",`${J}px`),Y.style.setProperty("--oc-chat-inset-right",`${G}px`),()=>{Y.style.removeProperty("--oc-chat-inset-left"),Y.style.removeProperty("--oc-chat-inset-right")}},[J,G]),u.useEffect(()=>{if(typeof document>"u")return;const Y=document.documentElement;return Y.classList.toggle("wide-chat-layout",E),()=>Y.classList.remove("wide-chat-layout")},[E]),u.useEffect(()=>{if(typeof document>"u")return;const Y=M&&($||w),de=document.documentElement;return de.classList.toggle("oc-keep-draft-starters",Y),()=>de.classList.remove("oc-keep-draft-starters")},[w,M,$]);const H=u.useMemo(()=>({openChanges:({diffPath:Y,staged:de}={})=>{ie(Y?{path:Y,staged:de===!0}:null)},openFiles:()=>L(),openSettings:()=>D("nav")}),[ie,L,D]),X=u.useMemo(()=>({openSessions:()=>{M?U(!0):i(!0)},openView:Y=>{if(Y==="files"){L();return}if(Y==="mcp"){d("mcp"),c(!0);return}k(Y)},openChanges:({path:Y,staged:de}={})=>{ie(Y?{path:Y,staged:de===!0}:null)},openSettings:Y=>{Y&&x(Y),D(Y?"page-content":"nav")}}),[M,ie,L,D,k,x]);Hd(X);const ne=u.useRef(null);sr(ne,{onLeftEdgeSwipe:()=>{M?U(!0):i(!0)},onRightEdgeSwipe:()=>c(!0)});const re=u.useRef(null),ce=u.useCallback(Y=>{re.current=Y},[]),ue=u.useCallback(()=>l?(p(null),!0):r==="settings"&&re.current?.()?!0:r?(R(),!0):a?(z(),!0):s?(i(!1),!0):!1,[r,R,z,l,s,a]);Ua(ue);const q=!A&&v&&(N==="desktop"||N==="web"),oe=M?"dialog":"fullscreen",pe=u.useMemo(()=>({instanceLabel:A?os():null,onOpenInstances:A?()=>k("instances"):void 0,onOpenSettings:()=>D("nav"),onOpenUsage:()=>k("usage"),onOpenUpdate:q?()=>k("update"):void 0}),[D,k,A,q]),ke=u.useCallback(()=>{const Y="new-mcp-server";let de=Y,Ce=1;for(;y.some(Ae=>Ae.name===de);)de=`${Y}-${Ce}`,Ce+=1;P({name:de,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",oauthCallbackPort:"",oauthAuthServerMetadataUrl:"",protocol:"legacy",timeoutStartup:"",timeoutCatalog:"",timeoutExecution:"",codemode:"default",disabled:!1}),C(de),x("mcp"),D("page-content")},[y,D,P,C,x]);return t.jsx(Ga,{actions:H,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[M?t.jsxs("aside",{ref:ee.asideRef,className:Q("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!B&&"border-r-0"),style:{width:B?ee.width:0,minWidth:B?ee.width:0,maxWidth:B?ee.width:0,"--oc-ipad-sidebar-width":`${ee.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ee.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!B,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:Q("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",ee.isResizing&&"pointer-events-none",!B&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Ve,{children:t.jsx(Ur,{open:!0,variant:"sidebar",onOpenChange:Y=>{!Y&&!j&&U(!1)},footer:pe})})}),B?t.jsx(ei,{side:"left",isResizing:ee.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:ee.handleProps}):null]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(Su,{onOpenSessions:()=>M?O():i(!0),onOpenWorkspace:()=>c(!0),compactTitle:M}),t.jsx("main",{ref:ne,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{className:"h-full w-full",children:t.jsx(Ve,{children:t.jsx(Tl,{})})})})]}),M?null:t.jsx(Ur,{open:s,onOpenChange:i,footer:pe}),t.jsxs("aside",{ref:W.asideRef,className:Q("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!G&&"border-l-0"),style:{width:G,minWidth:G,maxWidth:G,"--oc-ipad-sidebar-width":`${W.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:W.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!G,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:Q("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",W.isResizing&&"pointer-events-none",!G&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Ve,{children:t.jsx(Ad,{open:a,onClose:z,tab:f,onTabChange:d,pendingChangesDiff:b,onOpenPlan:p,onOpenMcpSettings:ke,variant:_?"panel":"drawer"})})}),G?t.jsx(ei,{side:"right",isResizing:W.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:W.handleProps}):null]}),l?t.jsx(Tt,{open:!0,variant:oe,onClose:()=>p(null),ariaLabel:l.title,title:l.title,children:t.jsx(Ve,{children:t.jsx(Ol,{savedProjectPlan:{projectRef:l.projectRef,planId:l.id},onNavigatedToChat:()=>{R(),z()}})})}):null,r==="instances"&&A?t.jsx(Tt,{open:!0,variant:oe,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(Eu,{onConnect:R,onActiveConnectionDeleted:n})}):null,r==="settings"?t.jsx(Tt,{open:!0,variant:oe,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Ve,{children:t.jsx(Ml,{forceMobile:!0,isWindowed:!0,initialMobileStage:g,registerBackHandler:ce,visiblePageSlugs:[...sf],onClose:R})})}):null,r==="usage"?t.jsx(Tt,{open:!0,variant:oe,dialogAlign:"app",onClose:R,ariaLabel:e("usageStats.title"),title:e("usageStats.title"),children:t.jsx(Ve,{children:t.jsx(Dl,{})})}):null,r==="update"?t.jsx(Tt,{open:!0,variant:oe,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Ve,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(zl,{initialUpdateDialogOpen:!0})})})}):null]})})};function ni({apis:n}){const{t:e}=me(),s=He(_=>_.initializeApp),i=He(_=>_.isInitialized),r=He(_=>_.isConnected),o=He(_=>_.connectionPhase),a=He(_=>_.providers.length),c=He(_=>_.agents.length),f=He(_=>_.loadProviders),d=He(_=>_.loadAgents),l=gt(_=>_.currentDirectory),p=Se(_=>_.error),g=Se(_=>_.clearError),h=it(_=>_.setIsMobile),b=va(_=>_.refreshStatus),S=wa(_=>_.refreshStatus),x=ja(_=>_.setPlanModeEnabled),E=We(_=>_.projects),[v,N]=u.useState(0),[A,y]=u.useState(0),[P,C]=u.useState(!1),[R,k]=u.useState("pending"),[z,D]=u.useState(null),M=u.useMemo(()=>os(),[]),[,j]=u.useReducer(_=>_+1,0),I=u.useMemo(()=>_n(),[]),$=u.useRef(0),w=u.useRef(0),B=u.useCallback(()=>{const _=st(),G=w.current+1;if(w.current=G,!_){ns("resume:auto-connect",{}),rs();return}ns("resume:reprobe",{});const J=()=>{s(),b(n.github,{force:!0}),S(n.linear,{force:!0}),a===0&&f({source:"mobileApp:nativeResume"}),c===0&&d({source:"mobileApp:nativeResume"})},H=ne=>{ns("resume:disconnect",{reason:ne}),Dt({apiBaseUrl:"",clientToken:null,runtimeKey:Es}),N(re=>re+1)};Ms().then(ne=>{if(w.current===G){if(ne==="no-connection"){H("no-connection");return}if(ne==="needs-login"){D({kind:"auth-expired",label:os()??""}),H("needs-login");return}if(ne==="unreachable"){const re=[4e3,1e4],ce=ue=>{window.setTimeout(()=>{if(w.current!==G)return;const q=ue===re.length-1;Ms({fast:!q}).then(oe=>{if(w.current===G&&oe!=="switched"){if(oe==="unchanged"){J();return}if(oe==="needs-login"){D({kind:"auth-expired",label:os()??""}),H("retry-needs-login");return}if(!q){ce(ue+1);return}H(`retry-${oe}`)}})},re[ue])};ce(0);return}ne!=="switched"&&J()}});const X=Date.now();X-$.current>=nf&&($.current=X,window.dispatchEvent(new Event("openchamber:system-resume")))},[c,n.github,n.linear,s,d,f,a,b,S]);ka(),Sa(B),u.useEffect(()=>{if(!I)return;let _;const G=()=>{window.clearTimeout(_),_=window.setTimeout(()=>B(),1500)};return window.addEventListener("online",G),()=>{window.removeEventListener("online",G),window.clearTimeout(_)}},[I,B]),u.useEffect(()=>{if(I)return br.subscribe((_,G)=>{_.state==="expired"&&G.state!=="expired"&&(B(),br.getState().markAuthenticated())})},[I,B]),u.useEffect(()=>(xr(n),()=>xr(null)),[n]),u.useEffect(()=>oi(_=>{if(ns("endpoint:changed",{runtimeKey:_.runtimeKey||"none",previousRuntimeKey:_.previousRuntimeKey||"none",connected:!!_.apiBaseUrl}),!!_.runtimeKey&&_.runtimeKey===_.previousRuntimeKey){Sl(),j();return}Nl(_),y(J=>J+1),N(J=>J+1)}),[]),u.useEffect(()=>{if(!I||r||st()){k("done");return}let _=!1;return k("attempting"),(async()=>{const G=await rs().catch(()=>({status:"no-candidate"}));_||(G.status==="unreachable"?D({kind:"unreachable",label:G.label}):G.status==="needs-login"&&D({kind:"auth-expired",label:G.label}),k("done"),G.status==="unreachable"&&rs({fast:!1,skipIfConnected:!0}).catch(()=>null))})(),()=>{_=!0}},[]),u.useEffect(()=>{if(!I||!st())return;let _=!1;const G=J=>{ns("cold-launch:drop",{kind:J?.kind??"unknown"}),J&&D(J),Dt({apiBaseUrl:"",clientToken:null,runtimeKey:Es}),N(H=>H+1)};return Ms().then(async J=>{if(_||J==="switched"||J==="unchanged")return;const H=os();if(J==="needs-login"){G({kind:"auth-expired",label:H??""});return}if(J==="unreachable"){G(H?{kind:"unreachable",label:H}:null),rs({fast:!1,skipIfConnected:!0}).catch(()=>null);return}const X=await rs().catch(()=>({status:"no-candidate"}));_||X.status==="connected"||(X.status==="needs-login"?G({kind:"auth-expired",label:X.label}):X.status==="unreachable"?G({kind:"unreachable",label:X.label}):G(null))}),()=>{_=!0}},[]),u.useEffect(()=>{h(!0)},[h]),u.useEffect(()=>{I&&!st()||s()},[v,s,I]),u.useEffect(()=>{r&&(a===0&&f({source:"mobileApp:recovery"}),c===0&&d({source:"mobileApp:recovery"}))},[c,r,d,f,a]);const U=u.useRef(!1),[O,L]=u.useState(I);u.useEffect(()=>{if(!I||!r||U.current)return;if(Se.getState().currentSessionId){U.current=!0,L(!1);return}const _=Gt(),G=Na(_);if(!G){U.current=!0,L(!1);return}let J=!1;const H=window.setTimeout(()=>L(!1),6e3);return(async()=>{const X=await In().catch(()=>null);if(J)return;if(!X){L(!1);return}U.current=!0;const ne=X.activeSessions.find(ce=>ce.id===G.sessionId);if(!ne){Ca(_),L(!1);return}const re=Se.getState();re.currentSessionId||re.setCurrentSession(ne.id,Cn(ne)??G.directory??void 0),L(!1)})(),()=>{J=!0,window.clearTimeout(H)}},[v,r,I]),u.useEffect(()=>{r&&yr.setDirectory(l)},[l,r]),u.useEffect(()=>{r&&(b(n.github,{force:!0}),S(n.linear,{force:!0}))},[n.github,n.linear,r,b,S]),u.useEffect(()=>{if(!r||E.length===0)return;let _=!1;return(async()=>{const J=new Map(Se.getState().availableWorktreesByProject);if(await Promise.all(E.map(async ne=>{const re=ne.path.replace(/\\/g,"/").replace(/\/+$/,"");if(re)try{if(!(Fe.getState().directories.get(re)?.isGitRepo??await $t(()=>import("./useAppFontEffects-DHZ9-L30.js").then(oe=>oe.lw),__vite__mapDeps([9,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(oe=>oe.checkIsGitRepository(re))))return;const q=await xi({id:ne.id,path:re});if(_)return;J.set(re,q)}catch{}})),_)return;const H=yi(E,J),X=Se.getState().availableWorktreesByProject;La(H,X)||Se.setState({availableWorktrees:[...H.values()].flat(),availableWorktreesByProject:H})})(),()=>{_=!0}},[r,E]),u.useEffect(()=>{if(!r)return;let _=!1;const G=wi(J=>{J.type==="worktree-changed"&&$a(E,J.directories,()=>_)});return()=>{_=!0,G()}},[r,E]),u.useEffect(()=>{let _=!1;return(async()=>{const J=await Sn("/health",{method:"GET"}).catch(()=>null);if(!J||!J.ok||_)return;const H=await J.json().catch(()=>null);if(!H||_)return;const X=H.planModeExperimentalEnabled;x(X===!0||X===1||X==="1"||X==="true")})(),()=>{_=!0}},[x]),u.useEffect(()=>{if(!p)return;const _=window.setTimeout(()=>g(),5e3);return()=>window.clearTimeout(_)},[g,p]),u.useEffect(()=>{if(!(!r&&(I?!!st():!0))){C(!1);return}const G=window.setTimeout(()=>{C(!0)},I?4e3:8e3);return()=>window.clearTimeout(G)},[r,I,v,A]),Ra(),Ea({enabled:!0}),Cl(),Pa(),Aa(),Rl(),Qd({enabled:I&&r}),qd({ready:I&&r&&i});const ie=Md(),ee=!r&&o==="reconnecting";if(!ie)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:t.jsx(_t,{width:120,height:120,isAnimated:!0,variant:"splash"})});const W=!!st();return I&&(!W||!r&&!ee)?W?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(_t,{width:120,height:120,isAnimated:!P,variant:"splash"}),P?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("mobile.connect.recovery.description")})]}),t.jsx(ge,{type:"button",variant:"outline",onClick:()=>{Dt({apiBaseUrl:"",clientToken:null,runtimeKey:Es}),N(_=>_+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):R!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:[t.jsx(_t,{width:120,height:120,isAnimated:!0,variant:"splash"}),M?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:e("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[M,t.jsx(Ia,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(lu,{onConnected:()=>N(_=>_+1),notice:z})}):!r&&!ee?P?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:t.jsx(_t,{width:120,height:120,isAnimated:!0,variant:"splash"})}):t.jsx(Ve,{children:t.jsx(Ta,{sdk:yr.getSdkClient(),directory:l||"",children:t.jsx(Da,{apis:n,children:t.jsx(_a,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(El,{ready:!I||!O,animated:!0}),t.jsx(Ma,{embeddedBackgroundWorkEnabled:i}),t.jsx(Pl,{}),t.jsx(kc,{}),t.jsx(rf,{onActiveConnectionDeleted:()=>{Dt({apiBaseUrl:"",clientToken:null,runtimeKey:Es}),N(_=>_+1)}}),t.jsx(za,{}),t.jsx(Oa,{}),t.jsx(Ba,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),i?t.jsx(Al,{}):null]})})})},A)})}function of(n){const e=le.c(4),s=u.useSyncExternalStore(af,st,st);if(_n()&&!s){let r;return e[0]!==n?(r=t.jsx(ni,{...n}),e[0]=n,e[1]=r):r=e[1],r}let i;return e[2]!==n?(i=t.jsx(kl,{children:t.jsx(ni,{...n})}),e[2]=n,e[3]=i):i=e[3],i}function af(n){return oi(()=>n())}const lf=()=>{Xa(),vo().then(()=>{Promise.all([wo(),Za()]).catch(n=>{console.error("[mobile-main] settings init failed:",n)}),el(),tl(),sl()}).catch(n=>{console.error("[mobile-main] appearance init failed:",n)}).finally(()=>{hc()})};function $p(n){window.__OPENCHAMBER_SURFACE__="mobile",Ka(),lf(),jc(),Ha();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const i=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",r=i?{...n,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:n,o=t.jsx(of,{apis:r});mo.createRoot(e).render(t.jsx(bn.StrictMode,{children:t.jsx(qa,{children:t.jsx(Ja,{children:t.jsx(Ya,{children:t.jsx(_l,{children:i?o:t.jsx(Qa,{children:o})})})})})}))}export{$p as renderMobileApp};