@openchamber/web 1.21.0 → 1.21.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 (135) hide show
  1. package/bin/cli.test.js +35 -0
  2. package/bin/lib/DOCUMENTATION.md +12 -0
  3. package/bin/lib/cli-settings-accessors.js +111 -0
  4. package/bin/lib/cli-settings-accessors.test.js +189 -0
  5. package/bin/lib/cli-startup.js +29 -9
  6. package/bin/lib/commands-connect-url.js +12 -14
  7. package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-BGj8TJxW.js} +1 -1
  8. package/dist/assets/CommitSection-DwGiXyjf.js +1 -0
  9. package/dist/assets/{DiffView-D5cvbEPb.js → DiffView-Db6bjVv1.js} +3 -3
  10. package/dist/assets/FilesView-DQOa7Lgz.js +17 -0
  11. package/dist/assets/GitView-CHzJxTi0.js +6 -0
  12. package/dist/assets/{JsonTreeView-osju7J70.js → JsonTreeView-CggOsLot.js} +1 -1
  13. package/dist/assets/MarkdownImageGallery-DoZpaHev.js +1 -0
  14. package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +12 -0
  15. package/dist/assets/{OnboardingScreen-w2VG4fWY.js → OnboardingScreen-C98d69Fp.js} +1 -1
  16. package/dist/assets/{PatchDiff-Dan3mADn.js → PatchDiff-DJYMUiXA.js} +1 -1
  17. package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-CY2bx_SB.js} +3 -3
  18. package/dist/assets/PlanView-PkiOY_9H.js +5 -0
  19. package/dist/assets/SettingsView-D-K3ELCM.js +28 -0
  20. package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-oyOm2fHR.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-lKyeQTPL.js} +6 -6
  22. package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-C7kBQNAA.js} +2 -2
  23. package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-BP7ebDFF.js} +1 -1
  24. package/dist/assets/{WalkthroughView-D9Q4lr5x.js → WalkthroughView-MuJodAHD.js} +2 -2
  25. package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-CZ0xPeaT.js} +1 -1
  26. package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-C9abMBTb.js} +1 -1
  27. package/dist/assets/de-CEoCz3j6.js +9 -0
  28. package/dist/assets/es-DwyXCqaL.js +15 -0
  29. package/dist/assets/{fr-5qJM0nFS.js → fr-CS7Csln9.js} +5 -5
  30. package/dist/assets/index-CUKcHnUA.css +1 -0
  31. package/dist/assets/{index-Brm3X9rs.js → index-CaPAjwXQ.js} +1 -1
  32. package/dist/assets/index-DIvDEKE-.js +7 -0
  33. package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-ZBvDxhVB.js} +1 -1
  34. package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-DiLRrkJr.js} +1 -1
  35. package/dist/assets/ja-vnwqLcx6.js +15 -0
  36. package/dist/assets/ko-CXuSfZv5.js +15 -0
  37. package/dist/assets/{main-vUCh0VB0.js → main-D5RWr6sJ.js} +2 -2
  38. package/dist/assets/main-DLlfDjQ_.js +926 -0
  39. package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
  40. package/dist/assets/markdownCore-CcTcLsQF.js +3 -0
  41. package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-CqR3icsk.js} +2 -2
  42. package/dist/assets/{mobile-CkX6H-IT.js → mobile-RN_UTTlB.js} +2 -2
  43. package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-CjRR5ESs.js} +3 -3
  44. package/dist/assets/pl-BJxry0Mi.js +15 -0
  45. package/dist/assets/pt-BR-DxLmkhdv.js +15 -0
  46. package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.js → renderElectronMiniChatApp-1wC94fQK.js} +2 -2
  47. package/dist/assets/renderMobileApp-ltva2Plg.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +15 -0
  49. package/dist/assets/{scheduledTasksApi-CAGPh_gZ.js → scheduledTasksApi-mjMDet_H.js} +1 -1
  50. package/dist/assets/{shikiHighlight-BgTPSITe.js → shikiHighlight-fGmFkxAM.js} +1 -1
  51. package/dist/assets/tr-5Mk_hQ2Q.js +6 -0
  52. package/dist/assets/uk-ClgQjmlw.js +15 -0
  53. package/dist/assets/{useAppFontEffects-Cll4gnsh.js → useAppFontEffects-KP8_yiGW.js} +143 -141
  54. package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-HIjtuhxD.js} +2 -2
  55. package/dist/assets/useRootScrollLock-BSiQ5F75.js +1 -0
  56. package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-DrTPkHl4.js} +2 -2
  58. package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
  59. package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
  60. package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
  61. package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
  62. package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
  63. package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
  64. package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
  65. package/dist/assets/{web-components-DLnGY4fs.js → web-components-DOXvU-tB.js} +1 -1
  66. package/dist/assets/zh-CN-Ba6y8H-i.js +15 -0
  67. package/dist/assets/zh-TW-Dv8yyhN1.js +15 -0
  68. package/dist/index.html +5 -5
  69. package/dist/mini-chat.html +3 -3
  70. package/dist/mobile.html +3 -3
  71. package/dist/site.webmanifest +1 -1
  72. package/dist/sw.js +1 -1
  73. package/package.json +2 -2
  74. package/public/site.webmanifest +1 -1
  75. package/server/index.js +2 -2
  76. package/server/lib/cloudflare-tunnel.js +1 -1
  77. package/server/lib/fs/DOCUMENTATION.md +1 -0
  78. package/server/lib/fs/routes.js +21 -0
  79. package/server/lib/fs/routes.test.js +89 -3
  80. package/server/lib/git/DOCUMENTATION.md +4 -3
  81. package/server/lib/git/service.js +128 -6
  82. package/server/lib/git/service.test.js +191 -1
  83. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  84. package/server/lib/markdown-image-grants/routes.js +3 -1
  85. package/server/lib/markdown-image-grants/routes.test.js +14 -0
  86. package/server/lib/openchamber-sessions/routes.js +4 -1
  87. package/server/lib/openchamber-sessions/routes.test.js +23 -0
  88. package/server/lib/opencode/env-runtime.js +17 -1
  89. package/server/lib/opencode/env-runtime.test.js +56 -0
  90. package/server/lib/opencode/lifecycle.js +48 -9
  91. package/server/lib/opencode/lifecycle.test.js +125 -1
  92. package/server/lib/opencode/managed-process-registry.d.ts +13 -0
  93. package/server/lib/opencode/managed-process-registry.js +213 -163
  94. package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
  95. package/server/lib/opencode/project-directory-runtime.js +16 -11
  96. package/server/lib/opencode/project-directory-runtime.test.js +32 -12
  97. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  98. package/server/lib/opencode/routes-upgrade.test.js +96 -12
  99. package/server/lib/opencode/routes.js +53 -5
  100. package/server/lib/opencode/settings-helpers.js +3 -0
  101. package/server/lib/opencode/settings-helpers.test.js +10 -0
  102. package/server/lib/opencode/theme-runtime.js +1 -1
  103. package/server/lib/opencode/theme-runtime.test.js +129 -0
  104. package/server/lib/quota/DOCUMENTATION.md +19 -0
  105. package/server/lib/quota/providers/copilot.js +26 -10
  106. package/server/lib/quota/providers/copilot.test.js +78 -0
  107. package/server/lib/small-model/DOCUMENTATION.md +11 -5
  108. package/server/lib/small-model/call.js +64 -20
  109. package/server/lib/small-model/call.test.js +184 -2
  110. package/server/lib/tunnels/install-help.js +2 -2
  111. package/server/lib/tunnels/install-help.test.js +9 -0
  112. package/server/lib/walkthrough/languages.js +1 -0
  113. package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
  114. package/dist/assets/FilesView-DPU8aNPL.js +0 -17
  115. package/dist/assets/GitView-Ct6xWrVH.js +0 -6
  116. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
  117. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
  118. package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
  119. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
  120. package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
  121. package/dist/assets/de-B_LdJwEM.js +0 -9
  122. package/dist/assets/es-CubfsAYV.js +0 -15
  123. package/dist/assets/index-BW82eK5v.css +0 -1
  124. package/dist/assets/index-rlLjZUM5.js +0 -7
  125. package/dist/assets/ja-DJYIBUlH.js +0 -15
  126. package/dist/assets/ko-DcUBkB7y.js +0 -15
  127. package/dist/assets/main-DLBxKIoX.js +0 -926
  128. package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
  129. package/dist/assets/pl-rB6BLcio.js +0 -15
  130. package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
  131. package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
  132. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
  133. package/dist/assets/uk-INZlFD9A.js +0 -15
  134. package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
  135. package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
@@ -0,0 +1,25 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-DQOa7Lgz.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-DIvDEKE-.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-zod-BLfBSgBh.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/index-CUKcHnUA.css","assets/useAppFontEffects-KP8_yiGW.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BeMD8X_w.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/contextPanelEmbeddedChat-C9abMBTb.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-livSKyyV.js","assets/vendor-motion-dom-D_o3BTI3.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.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-DrTPkHl4.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-gg7YLRW7.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/runtimeEndpointReset-D6SmNZaP.js","assets/shikiHighlight-fGmFkxAM.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-CggOsLot.js","assets/web-components-DOXvU-tB.js","assets/computeVirtualFileMetrics-CZ0xPeaT.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-DiLRrkJr.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/Virtualizer-D_a8gKmg.js","assets/scheduledTasksApi-mjMDet_H.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/useInlineCommentController-HIjtuhxD.js","assets/CodeMirrorCommentWidgets-BGj8TJxW.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 ue,r as ms,j as t,R as l,c as mt,h as mo}from"./vendor-react-BUCujlKS.js";import{u as Ge,a as yt,b as Qn,d as dn,i as Re,e as Ve,s as lt,f as zt,r as ws,h as po,j as Zn,k as ho,p as go,l as bo,m as Qe,n as xo,o as fn,q as mn,t as pn,v as yo,w as hn,x as vo,y as wo}from"./index-DIvDEKE-.js";import{u as js,a as jo,b as ze,c as er,d as tr,r as ks,e as ko,f as me,t as ce,o as So,I as ee,B as ye,g as No,O as Ye,h as X,P as Co,i as Eo,j as Ro,k as Po,l as Me,m as To,n as nt,p as Ao,q as gn,s as Io,v as Ss,w as _o,x as Do,y as je,z as Mo,A as sr,C as nr,D as rr,E as zo,F as Ns,G as Oo,H as or,J as Lo,K as Bo,M as $o,L as ir,N as ar,Q as lr,R as cr,S as Cs,T as Fo,U as Wo,V as Es,W as Uo,X as Vo,Y as Nt,Z as os,_ as Go,$ as ur,a0 as Ko,a1 as Rs,a2 as dr,a3 as fr,a4 as Rt,a5 as dt,a6 as Ho,a7 as qo,a8 as Yo,a9 as Jo,aa as Xo,ab as Ps,ac as Qo,ad as Zo,ae as ei,af as Ue,ag as ti,ah as si,ai as ni,aj as ri,ak as oi,al as ii,am as ai,an as Oe,ao as li,ap as ci,aq as ui,ar as di,as as fi,at as mi,au as mr,av as pi,aw as hi,ax as gi,ay as bi,az as xi,aA as yi,aB as vi,aC as wi,aD as ji,aE as ki,aF as Si,aG as Ni,aH as Ci,aI as Ei,aJ as Ri,aK as Pi,aL as Ti,aM as Ai,aN as Ii,aO as _i,aP as Di,aQ as Mi,aR as zi,aS as Oi,aT as Li,aU as Bi,aV as $i,aW as Fi,aX as Wi,aY as Ui,aZ as Vi}from"./useAppFontEffects-KP8_yiGW.js";import{u as ct,S as pr,p as Gi,D as Ki,N as Hi,a as qi,b as Yi,T as Ji,P as Xi,r as Qi,c as Zi,d as ea,e as ta,O as sa,C as na,f as ra,g as oa}from"./runtimeEndpointReset-D6SmNZaP.js";import{_ as pt}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as ia,A as aa}from"./SettingsView-D-K3ELCM.js";import{PlanView as la}from"./PlanView-PkiOY_9H.js";import{p as ca}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as ua}from"./vendor-capacitor-core-B4EWRrHz.js";import{k as ps,s as hr,M as Ts,a as qt,J as hs,p as da,_ as bn,b as gr,P as br,d as fa,f as As,V as ma,K as xn,c as pa,Q as ha,r as ga,U as ba,Z as xa}from"./vendor-remixicon-react-Dil0zKKT.js";import{f as Is,h as ht,i as _s,P as Ds,D as Ms,j as zs}from"./vendor-dnd-kit-core-BZknOX2w.js";import{s as Os,S as Ls,v as Bs,u as $s}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as Fs}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{c as Ws,p as xr}from"./vendor-zustand-BAGL70zf.js";import{toast as yn}from"./vendor-sonner-DFyL3AvE.js";import{C as ya,a as va}from"./CommitSection-DwGiXyjf.js";import{P as wa}from"./PierreDiffViewer-CY2bx_SB.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.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"./contextPanelEmbeddedChat-C9abMBTb.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.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-DrTPkHl4.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-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-yaml-3778uTud.js";import"./shikiHighlight-fGmFkxAM.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-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.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"./useInlineCommentController-HIjtuhxD.js";import"./CodeMirrorCommentWidgets-BGj8TJxW.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./web-components-DOXvU-tB.js";import"./computeVirtualFileMetrics-CZ0xPeaT.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"./VirtualizedFileDiff-BP7ebDFF.js";import"./isDiffPlainText-ZBvDxhVB.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";let yr=null,vn=!1;const ja=new Promise(n=>{yr=n});function ka(){vn||(vn=!0,yr?.())}const Sa=6,Na=n=>n.parentID??null,wn=n=>{const e=n.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},Ca=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Ea=(n,e)=>{if(!n)return"";let s=null,o=-1;for(const r of e){const i=Ca(r.path);(n===i||n.startsWith(`${i}/`))&&i.length>o&&(s=r,o=i.length)}return s?s.label?.trim()||wn(s.path):wn(n)},Ra=()=>{const n=js.getState().activeSessions,e=jo.getState().index.session.unseenCount,s=Ge.getState().notifyOnSubtasks,o=ze.getState().projects,r=er.getState().ids,i=tr.getState().rankById;let a=0;const c=[];for(const f of n){const d=Na(f)!==null,g=(e[f.id]??0)>0&&(!d||s);g&&(a+=1),d||c.push({session:f,unread:g,project:Ea(ks(f),o)})}c.sort((f,d)=>ko(f.session,d.session,r,i));const u=c.slice(0,Sa).map(({session:f,unread:d,project:p})=>({id:f.id,title:f.title??"",unread:d,project:p}));return{runtimeKey:yt(),attentionCount:a,recentSessions:u}},Pa="__OPENCHAMBER_WIDGET_SNAPSHOT__",Ta=()=>{typeof window>"u"||(window[Pa]=()=>{try{return JSON.stringify(Ra())}catch{return null}})},is="mobile-app-update-available",jn="mobile-app-update-toast-dismissed-version",Aa=()=>{const n=ue.c(8),{t:e}=me(),s=ct(Ia),o=ct(_a),r=ct(Da),i=ct(Ma);let a;n[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,n[0]=a):a=n[0];const c=ms.useRef(a);let u,f;return n[1]!==s||n[2]!==i||n[3]!==o||n[4]!==e||n[5]!==r?(u=()=>{if(Qn()!=="android"||o!=="mobile"||!s||!r||!i){ce.dismiss(is);return}dn().getItem(jn)!==r&&(c.current.has(r)||(c.current.add(r),ce.info(e("mobileUpdate.toast.available.title"),{id:is,description:e("mobileUpdate.toast.available.description",{version:r}),duration:1/0,icon:t.jsx(ee,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{So(i)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{dn().setItem(jn,r),ce.dismiss(is)}}})))},f=[s,i,o,e,r],n[1]=s,n[2]=i,n[3]=o,n[4]=e,n[5]=r,n[6]=u,n[7]=f):(u=n[6],f=n[7]),ms.useEffect(u,f),null};function Ia(n){return n.available}function _a(n){return n.runtimeType}function Da(n){return n.info?.version}function Ma(n){return n.info?.downloadUrl}const kn=300,za="openchamber.mobile.connectLog.v1",ut=[];if(typeof window<"u")try{window.localStorage.removeItem(za)}catch{}const Us=(n,e)=>{ut.push({at:Date.now(),step:n,detail:e}),ut.length>kn&&ut.splice(0,ut.length-kn)};typeof window<"u"&&Us("app:launch","{}");const Oa=()=>[...ut],La=n=>{const e=new Date(n),s=(o,r=2)=>String(o).padStart(r,"0");return`${s(e.getHours())}:${s(e.getMinutes())}:${s(e.getSeconds())}.${s(e.getMilliseconds(),3)}`},vr=n=>`${La(n.at)} ${n.step}${n.detail&&n.detail!=="{}"?` ${n.detail}`:""}`,Ba=()=>ut.map(vr).join(`
3
+ `),wr=(n,e)=>{const s=ue.c(10),o=700,r=l.useRef(null),i=l.useRef(null),a=l.useRef(!1);let c;s[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{r.current!==null&&window.clearTimeout(r.current),r.current=null,i.current=null},s[0]=c):c=s[0];const u=c;let f,d;s[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>u,d=[u],s[1]=f,s[2]=d):(f=s[1],d=s[2]),l.useEffect(f,d);let p;s[3]!==o||s[4]!==n?(p=S=>{a.current=!1,i.current={x:S.clientX,y:S.clientY},r.current!==null&&window.clearTimeout(r.current),r.current=window.setTimeout(()=>{r.current=null,a.current=!0,n()},o)},s[3]=o,s[4]=n,s[5]=p):p=s[5];const g=p;let h;s[6]===Symbol.for("react.memo_cache_sentinel")?(h=S=>{const E=i.current;E&&(Math.abs(S.clientX-E.x)>10||Math.abs(S.clientY-E.y)>10)&&u()},s[6]=h):h=s[6];const x=h;let j;s[7]===Symbol.for("react.memo_cache_sentinel")?(j=S=>{a.current&&(a.current=!1,S.preventDefault(),S.stopPropagation())},s[7]=j):j=s[7];const b=j;let I;return s[8]!==g?(I={onPointerDown:g,onPointerMove:x,onPointerUp:u,onPointerCancel:u,onClickCapture:b},s[8]=g,s[9]=I):I=s[9],I},Yt="openchamber.mobile.connections.v1",$a="openchamber.mobile.",Sn="openchamber.mobile.deviceId",Fa=()=>{try{const n=window.localStorage.getItem(Sn);if(n&&n.trim())return n.trim();const e=crypto.randomUUID();return window.localStorage.setItem(Sn,e),e}catch{return crypto.randomUUID()}},Nn=()=>`mobile:${Fa()}`,Cn=()=>{try{const n=ua.getPlatform();return n==="ios"||n==="android"?n:void 0}catch{return}},jr=12,kr=8e3,Wa=2500,Ua=3e3,Jt=2500,Va=()=>{let n=0;return{begin:()=>(n+=1,n),cancel:()=>{n+=1},isCurrent:e=>e===n}},vt=n=>{const e=n.trim();if(!e)return"";const s=/^https?:\/\//i.test(e)?e:`http://${e}`,o=new URL(s);return o.hash="",o.search="",o.pathname=o.pathname.replace(/\/+$/,""),o.toString().replace(/\/+$/,"")},Gt=n=>{try{return new URL(n).host}catch{return n}},gt=n=>{try{return vt(n)}catch{return n.trim().replace(/\/+$/g,"")}},Sr=(n,e)=>gt(n)===gt(e),Nr=n=>`relay:${n.serverId}@${n.relayUrl.trim()}`,Ga=n=>`relay://${n.serverId}`,es=n=>n.candidates.filter(e=>e.kind==="direct"),Ze=n=>{const e=n.candidates.find(s=>s.kind==="relay");return e&&e.kind==="relay"?e.relay:null},Ke=n=>{const e=es(n)[0];if(e)return e.url;const s=Ze(n);return s?Ga(s):""},Ee=n=>{const e=Ze(n);if(e)return Nr(e);const s=es(n)[0];return s?gt(s.url):""},Xt=(n,e)=>{const s=n.find(i=>i.kind==="relay"),o=s&&s.kind==="relay"?s.relay.serverId:null,r=new Set(n.filter(i=>i.kind==="direct").map(i=>gt(i.url)));return e.some(i=>i.kind==="relay"?o!==null&&i.relay.serverId===o:r.has(gt(i.url)))},Vs=n=>{const e=(()=>{try{return vt(n)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},En=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(...Vs(n.url)),n.relay&&e.push({kind:"relay",relay:n.relay}),e},Gs=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 o=s;return o.kty!=="EC"||o.crv!=="P-256"||typeof o.x!="string"||!o.x||typeof o.y!="string"||!o.y?null:{relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:o.x,y:o.y}}},Cr=n=>{try{return JSON.stringify(n)}catch{return String(n)}},be=(n,e={})=>{const s=Cr(e);console.info("[mobile-connect]",n,s),Us(n,s)},Ct=(n,e={})=>{be(n,e)},bt=(n,e={})=>{const s=Cr(e);console.info("[mobile-storage]",n,s),Us(n,s)},Ka=n=>{if(typeof n!="string")return n;try{return JSON.parse(n)}catch{return n}},Ha=n=>{if(typeof n!="string")return n??void 0;try{return JSON.parse(n)}catch{return n}},qa=async(n,e)=>{if(!Re())return null;try{const{CapacitorHttp:s}=await pt(async()=>{const{CapacitorHttp:i}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:i}},[]),o=ho(n,new Headers(e?.headers)),r=await s.request({url:n,method:e?.method||"GET",headers:Object.fromEntries(o.entries()),data:Ha(e?.body)});return{ok:r.status>=200&&r.status<300,status:r.status,source:"native-http",json:async()=>Ka(r.data)}}catch(s){return be("native-http:failed",{url:n,error:s instanceof Error?s.message:String(s)}),null}},Ya=async(n,e)=>{const s=await fetch(n,e).catch(o=>(be("browser-fetch:failed",{url:n,error:o instanceof Error?o.message:String(o)}),null));return s?{ok:s.ok,status:s.status,source:"browser-fetch",json:()=>s.json()}:null},qe=async(n,e,s)=>{let o;const r=new Promise(i=>{o=window.setTimeout(()=>{s?.(),i(null)},n)});try{return await Promise.race([e,r])}catch{return null}finally{o!==void 0&&window.clearTimeout(o)}},et=async(n,e,s)=>{const o=s?.totalTimeoutMs??kr,r=Date.now(),i=await qe(Math.min(Wa,o),qa(n,e));if(i)return i;const a=new AbortController,c=Math.max(500,o-(Date.now()-r));return qe(c,Ya(n,{...e,signal:a.signal}),()=>a.abort())},ts=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}},xt=15e3,Ja=async(n,e,s,o=xt,r)=>{const i=Zn({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk}),a=c=>c==="ok"&&r?.keepTunnel?{outcome:c,tunnel:i}:(i.close(),{outcome:c});try{const c=e?{Authorization:`Bearer ${e}`}:void 0,u=await qe(o,i.fetch("/auth/session",{headers:c}).catch(()=>null));if(be("relay:session",{ok:u?.ok===!0,status:u?.status??null,hasToken:!!e}),!u)return a("unreachable");if(u.status===401)return a(e?"auth-failed":"needs-login");if(!u.ok&&u.status!==404)return a("auth-failed");const f=await ts(u);return f&&f.disabled!==!0&&f.authenticated===!1?a(e?"auth-failed":"needs-login"):a("ok")}catch(c){throw i.close(),c}},Xa=(n,e,s,o,r)=>{const i=typeof window<"u"?window.location.origin:"",a={relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk,...s?{grant:s}:{}};r&&po(a,r),lt({apiBaseUrl:i,clientToken:e,runtimeKey:o??Nr(n),relay:a})},Qa=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=Gs(e.relay);return s?{kind:"relay",relay:s}:null}return null},Za=n=>{if(n.mode==="relay"){const e=Gs(n.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof n.url=="string"?Vs(n.url):[]},st=()=>{if(typeof window>"u")return[];let n;try{n=JSON.parse(window.localStorage.getItem(Yt)||"[]")}catch{return[]}if(!Array.isArray(n))return[];const e=Re();return n.flatMap(s=>{if(!s||typeof s!="object")return[];const o=s;if(typeof o.id!="string")return[];const r=Array.isArray(o.candidates)?o.candidates.map(Qa).filter(u=>!!u):Za(o);if(r.length===0)return[];const i=typeof o.clientToken=="string"&&o.clientToken.trim()?o.clientToken:void 0,a=typeof o.label=="string"&&o.label.trim()?o.label:Gt(Ke({candidates:r})),c={id:o.id,label:a,candidates:r,lastUsedAt:typeof o.lastUsedAt=="number"?o.lastUsedAt:0};return e?[{...c,hasToken:!!o.hasToken||!!i}]:[{...c,clientToken:i,hasToken:!!i}]}).sort((s,o)=>o.lastUsedAt-s.lastUsedAt)},gs=n=>n.kind==="relay"?{kind:"relay",relay:{relayUrl:n.relay.relayUrl,serverId:n.relay.serverId,hostEncPubJwk:n.relay.hostEncPubJwk}}:{kind:"direct",url:n.url},Ks=n=>{if(typeof window>"u")return;const e=Re(),s=n.slice(0,jr).map(o=>{const r={id:o.id,label:o.label,candidates:o.candidates.map(gs),lastUsedAt:o.lastUsedAt};return e?{...r,hasToken:!!(o.hasToken||o.clientToken)}:{...r,clientToken:o.clientToken}});try{window.localStorage.setItem(Yt,JSON.stringify(s))}catch(o){console.warn("[mobile-storage] failed to persist connection metadata",o)}},Er=(n,e)=>{const s=n.find(i=>e.id&&i.id===e.id||Xt(i.candidates,e.candidates)),o=Re(),r={id:e.id||s?.id||crypto.randomUUID(),label:e.label,candidates:e.candidates,lastUsedAt:Date.now(),...o?{hasToken:e.hasToken??(!!e.clientToken||s?.hasToken||!1)}:{clientToken:e.clientToken??s?.clientToken,hasToken:!!(e.clientToken??s?.clientToken)}};return[r,...n.filter(i=>i.id!==r.id&&!Xt(i.candidates,e.candidates))].slice(0,jr)},Hs=ca,el=0,qs=n=>`${$a}token.${encodeURIComponent(n)}`,tl=async(n,e)=>{let s;const o=new Promise(r=>{s=window.setTimeout(()=>r(e),Ua)});try{return await Promise.race([n.catch(()=>e),o])}finally{s!==void 0&&window.clearTimeout(s)}},Ys=async(n,e,s)=>Re()?tl(e().catch(o=>(console.warn(`[mobile-storage] ${n} failed`,o),s)),s):s,Ot=async n=>{bt("secure:read-start",{key:n});const e=await Ys("secure:read",async()=>(await Hs.internalGetItem({prefixedKey:qs(n),sync:!1})).data,null),s=typeof e=="string"&&e.trim()?e:void 0;return bt("secure:read",{key:n,hasToken:!!s}),s},Je=async(n,e)=>{bt("secure:write-start",{key:n});const s=await Ys("secure:write",async()=>(await Hs.internalSetItem({prefixedKey:qs(n),data:e,sync:!1,access:el}),!0),!1);return bt("secure:write",{key:n,ok:s}),s},sl=async n=>{await Ys("secure:delete",async()=>(await Hs.internalRemoveItem({prefixedKey:qs(n),sync:!1}),!0),!1)},nl=async(n,e)=>{let s=0,o=0;return{records:await Promise.all(n.map(async i=>{if(!i||typeof i!="object")return i;const a=i,c=typeof a.url=="string"?a.url:null,u=typeof a.clientToken=="string"?a.clientToken.trim():"";if(!c||!u)return i;if(!await e(c,u))return o+=1,i;s+=1;const{clientToken:f,...d}=a;return{...d,hasToken:!0}})),migrated:s,failed:o}},Rr=async()=>{if(typeof window>"u"||!Re())return;let n;try{n=JSON.parse(window.localStorage.getItem(Yt)||"[]")}catch{return}if(!Array.isArray(n))return;const e=n.filter(o=>!!o&&typeof o=="object"&&typeof o.url=="string"&&typeof o.clientToken=="string"&&!!o.clientToken.trim());if(e.length===0)return;bt("secure:migrate-start",{count:e.length});const s=await nl(n,async(o,r)=>{const i=gt(o);return await Je(i,r)?await Ot(i)===r:!1});if(s.migrated>0)try{window.localStorage.setItem(Yt,JSON.stringify(s.records))}catch(o){console.warn("[mobile-storage] failed to finalize secure token migration",o);return}bt("secure:migrate-done",{migrated:s.migrated,failed:s.failed})},rl=async()=>(await Rr(),st()),Qt=async n=>{const e=Er(st(),n);return Ks(e),Re()&&n.clientToken&&await Je(Ee({candidates:n.candidates}),n.clientToken),e},ol=async n=>{const e=st(),s=e.find(r=>r.id===n)??null,o=e.filter(r=>r.id!==n);return Ks(o),s&&Re()&&await sl(Ee(s)),o},il=1500,Zt=async(n,e,s)=>{const o=s?.fast?{totalTimeoutMs:Jt}:void 0,r=Ze({candidates:n})?.serverId??null,i=n.find(f=>f.kind==="relay")??null,a=n.filter(f=>f.kind==="direct"),c=async()=>{for(const f of a){const d=vt(f.url)||f.url,p=e?{Authorization:`Bearer ${e}`}:void 0,g=await et(`${d}/health`,{method:"GET"},o);if(be("probe:direct:health",{url:d,ok:g?.ok===!0,status:g?.status??null,source:g?.source??null}),!g?.ok)continue;if(r){const b=await g.json().catch(()=>null),I=b&&typeof b=="object"?b.serverId:null;if(typeof I=="string"&&I&&I!==r){be("probe:server-id-mismatch",{url:d});continue}}const h=await et(`${d}/auth/session`,{method:"GET",credentials:e?"omit":"include",headers:p},o);if(be("probe:direct:session",{url:d,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 x=await ts(h);if(x&&x.disabled!==!0&&x.authenticated===!1)return{status:"needs-login"};const j=x?.disabled===!0;return!e&&Re()&&!j&&x?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:d}}}return{status:"unreachable"}},u=async()=>{if(!i)return{status:"unreachable"};const{outcome:f,tunnel:d}=await Ja(i.relay,e,void 0,s?.fast?Jt:kr,{keepTunnel:!0});return f==="ok"?{status:"ok",transport:{kind:"relay",relay:i.relay,tunnel:d}}:f==="needs-login"||f==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return i?a.length===0?u():new Promise(f=>{let d=!1,p=!1,g,h=null,x=null;const j=S=>{S?.status==="ok"&&S.transport.kind==="relay"&&S.transport.tunnel?.close()},b=S=>{d||(d=!0,f(S))},I=()=>{p||d||(g!==void 0&&(window.clearTimeout(g),g=void 0),u().then(S=>{if(x=S,d||p){j(S);return}if(S.status==="ok"||S.status==="needs-login"){b(S);return}h&&b(h)}))};c().then(S=>{if(h=S,!d){if(S.status==="ok"||S.status==="needs-login"){p=!0,g!==void 0&&window.clearTimeout(g),j(x),b(S);return}if(x){b(x);return}I()}}),g=window.setTimeout(I,il)}):c()},Xe=(n,e,s)=>{n.kind==="relay"?Xa(n.relay,e,s?.grant,s?.runtimeKey,n.tunnel):lt({apiBaseUrl:n.url,clientToken:e,runtimeKey:s?.runtimeKey}),Tr()},Pt=()=>{const n=st()[0];return n?.label?.trim()?n.label:null},Et=async n=>{const e=n?.fast!==!1;await Rr();const s=st()[0];if(be("auto-connect:start",{hasCandidate:!!s,fast:e}),!s)return{status:"no-candidate"};let o;if(Re()){if(s.hasToken&&(o=await Ot(Ee(s)),!o))return{status:"no-candidate"}}else if(o=s.clientToken,!o&&s.hasToken)return{status:"no-candidate"};const r=await Zt(s.candidates,o,{fast:e});return be("auto-connect:probe",{status:r.status,candidates:s.candidates.map(i=>i.kind)}),r.status==="needs-login"?{status:"needs-login",label:s.label}:r.status!=="ok"?{status:"unreachable",label:s.label}:n?.skipIfConnected&&Ve()?(r.transport.kind==="relay"&&r.transport.tunnel?.close(),be("auto-connect:superseded",{}),{status:"no-candidate"}):(await Qt({id:s.id,label:s.label,candidates:s.candidates}),Xe(r.transport,o??null,{runtimeKey:Ee(s)}),{status:"connected"})},al=async(n,e)=>{let s="";try{s=vt(n.url)}catch{return!1}if(!s)return!1;const o=n.clientToken?.trim()||void 0,r=o?{Authorization:`Bearer ${o}`}:void 0,i=e?.fast?{totalTimeoutMs:Jt}:void 0;if(!(await et(`${s}/health`,{method:"GET",headers:r},i))?.ok)return!1;const c=await et(`${s}/auth/session`,{method:"GET",credentials:o?"omit":"include",headers:r},i);if(!c||!c.ok&&c.status!==404)return!1;const u=await ts(c);return!(u&&u.disabled!==!0&&u.authenticated===!1)},ll=n=>[...n].sort((e,s)=>{const o=(e.priority??100)-(s.priority??100);if(o!==0)return o;const r=i=>i.type==="relay"?2:i.url.startsWith("https://")?0:1;return r(e)-r(s)}).flatMap(e=>{if(e.type==="relay"){const s=Gs({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return Vs(e.url)}),Rn=async n=>{const e=Ze({candidates:n})?.serverId??null;for(const s of n){if(s.kind==="relay"){const i=Zn(s.relay),a=await qe(xt,i.fetch("/health").catch(()=>null));if(be("establish:relay:health",{ok:a?.ok===!0,status:a?.status??null}),a?.ok)return{kind:"relay",relay:s.relay,tunnel:i};i.close();continue}const o=vt(s.url)||s.url,r=await et(`${o}/health`,{method:"GET"});if(be("establish:direct:health",{ok:r?.ok===!0,status:r?.status??null}),!!r?.ok){if(e){const i=await r.json().catch(()=>null),a=i&&typeof i=="object"?i.serverId:null;if(typeof a=="string"&&a&&a!==e){be("establish:server-id-mismatch",{url:o});continue}}return{kind:"direct",url:o}}}return null},cl=async(n,e)=>{if(!zt())return al(n,e);const s=await qe(e?.fast?Jt:xt,ws("/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 o=await ts(s);return!(o&&o.disabled!==!0&&o.authenticated===!1)},ul=n=>n.kind==="relay"?zt():!zt()&&Sr(n.url,Ve()),Pr=()=>{const n=yt();return n?st().find(e=>Ee(e)===n)??null:null},Pn=n=>{const e=yt();return!!e&&Ee(n)===e},Kt=async n=>{const e=n?.fast!==!1,s=Pr();if(!s)return be("reprobe:no-connection",{runtimeKey:!!yt()}),"no-connection";let o;if(Re()?o=s.hasToken?await Ot(Ee(s)):void 0:o=s.clientToken,!o&&s.hasToken)return be("reprobe:no-token",{hasToken:!0}),"unreachable";be("reprobe:start",{candidates:s.candidates.map(f=>f.kind),fast:e,hasToken:!!o});const r=s.candidates.findIndex(f=>ul(f.kind==="relay"?{kind:"relay",relay:f.relay}:{kind:"direct",url:f.url})),i=r>=0?s.candidates.slice(0,r):s.candidates,a=await Zt(i,o,{fast:e});if(be("reprobe:better",{status:a.status,probed:i.length}),a.status==="ok")return await Qt({id:s.id,label:s.label,candidates:s.candidates}),Xe(a.transport,o??null,{runtimeKey:Ee(s)}),"switched";if(a.status==="needs-login")return"needs-login";if(r>=0){const f=await cl({url:Ve(),clientToken:o},{fast:e});if(be("reprobe:current",{stillValid:f}),f)return Tr(),"unchanged"}const c=r>=0?s.candidates.slice(r+1):[],u=await Zt(c,o,{fast:e});return be("reprobe:fallback",{status:u.status,probed:c.length}),u.status==="ok"?(await Qt({id:s.id,label:s.label,candidates:s.candidates}),Xe(u.transport,o??null,{runtimeKey:Ee(s)}),"switched"):u.status==="needs-login"?"needs-login":"unreachable"},dl=5e3;let as=!1;const fl=async()=>{if(as)return"skipped";const n=Pr();if(!n)return be("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=Ze(n);if(!e)return be("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";as=!0;try{const s=await qe(xt,ws("/api/client-auth/connection/candidates").then(f=>f).catch(()=>null));if(!s?.ok)return be("candidates:refresh-skip",{reason:"fetch-failed",status:s?.status??null}),"skipped";const o=await s.json().catch(()=>null);if(!o||o.serverId!==e.serverId)return be("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const r=Array.isArray(o.candidates)?o.candidates:[],i=[];for(const f of r){if(!f||typeof f!="object")continue;const d=f;if(!(d.type!=="lan"||typeof d.url!="string"))try{const p=vt(d.url);p&&!i.includes(p)&&i.push(p)}catch{}}if(i.length===0)return be("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const a=es(n).filter(f=>f.url.startsWith("https://")),c=[...i.map(f=>({kind:"direct",url:f})),...a,{kind:"relay",relay:e}];return JSON.stringify(n.candidates.map(gs))===JSON.stringify(c.map(gs))?"unchanged":(be("candidates:refreshed",{lanCount:i.length}),await Qt({id:n.id,label:n.label,candidates:c}),"updated")}finally{as=!1}},Tr=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const n=await fl().catch(()=>"skipped");be("candidates:refresh-result",{result:n}),n==="updated"&&zt()&&await Kt().catch(()=>null)})()},dl)},Ar=n=>{const{t:e}=me(),[s,o]=l.useState(()=>st()),[r,i]=l.useState(null),[a,c]=l.useState(null),[u,f]=l.useState(null),d=l.useRef(s),p=l.useRef(null),g=l.useRef(Va()),h=l.useCallback(w=>{d.current=w,o(w)},[]),x=l.useCallback(w=>{p.current=w,i(w)},[]),j=l.useCallback(w=>{p.current===w&&(p.current=null,i(null))},[]);l.useEffect(()=>{let w=!1;return rl().then(R=>{w||h(R)}),()=>{w=!0}},[h]);const b=l.useCallback(w=>{const R=Er(d.current,w);return h(R),Ks(R),R},[h]),I=l.useCallback(async w=>{c(null),x("connect");try{const R=En(w);if(R.length===0){c(e("mobile.connect.error.urlRequired"));return}const y=w.id?d.current.find($=>$.id===w.id):d.current.find($=>Xt($.candidates,R)),A=w.label?.trim()||y?.label||Gt(Ke({candidates:R})),M=w.relayGrant;let C=w.clientToken?.trim()||void 0;const N=!!C;C||(Re()?y?.hasToken&&(C=await Ot(Ee({candidates:R}))):C=y?.clientToken),be("connect:start",{candidates:R.map($=>$.kind),hasToken:!!C});const q=await Zt(R,C);if(be("connect:probe",{status:q.status}),q.status==="unreachable"){c(e("mobile.connect.error.unreachable"));return}if(q.status==="needs-login"){b({id:y?.id,label:A,candidates:R}),f({id:y?.id??crypto.randomUUID(),label:A,candidates:R,relay:Ze({candidates:R})??void 0,relayGrant:M});return}C&&N&&Re()&&await Je(Ee({candidates:R}),C),b({id:y?.id,label:A,candidates:R,clientToken:C}),Xe(q.transport,C??null,{runtimeKey:Ee({candidates:R}),grant:M}),n()}catch(R){console.warn("[mobile-connect] connect threw",R),c(e("mobile.connect.error.invalidUrl"))}finally{j("connect")}},[x,j,n,b,e]),S=l.useCallback(async w=>{if(p.current==="pairing")return;c(null),x("pairing");const R=ll(w.candidates);let y=null,A=!1;try{if(y=await Rn(R),!y){c(e("mobile.connect.error.unreachable"));return}const M=JSON.stringify({pairingId:w.pairingId,secret:w.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:Cn(),dedupeKey:Nn()}),C={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:M},N=y.kind==="relay"?await qe(xt,y.tunnel.fetch("/api/client-auth/pairing/redeem",C).catch(()=>null)):await et(`${y.url}/api/client-auth/pairing/redeem`,C);if(!N?.ok){c(e("mobile.connect.error.authRequired"));return}const q=await N.json().catch(()=>null),$=typeof q?.clientToken=="string"?q.clientToken.trim():"";if(!$){c(e("mobile.connect.error.authRequired"));return}const v=typeof q?.server?.label=="string"?q.server.label:"",_=w.label||v||Gt(Ke({candidates:R}));if(Re()&&!await Je(Ee({candidates:R}),$)){c(e("mobile.connect.error.authRequired"));return}b({label:_,candidates:R,clientToken:$}),Xe(y.kind==="relay"?{kind:"relay",relay:y.relay,tunnel:y.tunnel}:{kind:"direct",url:y.url},$,{runtimeKey:Ee({candidates:R})}),A=y.kind==="relay",n()}catch(M){console.warn("[mobile-connect] pairing threw",M),c(e("mobile.connect.error.authRequired"))}finally{!A&&y?.kind==="relay"&&y.tunnel.close(),j("pairing")}},[x,j,n,b,e]),E=l.useCallback(async w=>{if(!u||!w.trim()||p.current==="password")return;c(null),x("password");const R=g.current.begin(),y=()=>g.current.isCurrent(R),{id:A,label:M,candidates:C}=u;let N=null,q=!1;try{if(N=await Rn(C),!y())return;if(!N){c(e("mobile.connect.error.unreachable"));return}const $={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:w,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile",clientKind:"mobile",devicePlatform:Cn(),dedupeKey:Nn()})};be("password:start",{transport:N.kind});const v=N.kind==="relay"?await qe(xt,N.tunnel.fetch("/auth/session",$).catch(()=>null)):await et(`${N.url}/auth/session`,$);if(!y())return;if(be("password:done",{ok:v?.ok===!0,status:v?.status??null}),!v?.ok){c(e("mobile.connect.error.passwordFailed"));return}const _=await v.json().catch(()=>null);if(!y())return;const O=typeof _?.clientToken=="string"?_.clientToken.trim():"";if(be("password:token",{issued:!!O}),!O){if(N.kind==="direct"&&!Re()){b({id:A,label:M,candidates:C}),f(null),Xe({kind:"direct",url:N.url},null,{runtimeKey:Ee({candidates:C})}),n();return}c(e("mobile.connect.error.authRequired"));return}if(Re()&&(!y()||(await Je(Ee({candidates:C}),O),!y()))||!y()||(b({id:A,label:M,candidates:C,clientToken:O}),f(null),Xe(N.kind==="relay"?{kind:"relay",relay:N.relay,tunnel:N.tunnel}:{kind:"direct",url:N.url},O,{runtimeKey:Ee({candidates:C})}),q=N.kind==="relay",!y()))return;n()}catch($){if(!y())return;console.warn("[mobile-connect] password threw",$),c(e("mobile.connect.error.passwordFailed"))}finally{!q&&N?.kind==="relay"&&N.tunnel.close(),y()&&j("password")}},[x,j,n,u,b,e]),T=l.useCallback(()=>{g.current.cancel(),j("password"),f(null),c(null)},[j]),k=l.useCallback(async w=>{c(null);let R=En(w);const y=w.id?d.current.find(N=>N.id===w.id)??null:null;if(y){const N=R.filter(v=>v.kind==="direct"),q=es(y).filter(v=>v.url.startsWith("https://")&&!N.some(_=>Sr(_.url,v.url))),$=Ze(y);R=[...N,...q,...$?[{kind:"relay",relay:$}]:[]]}if(R.length===0)return c(e("mobile.connect.error.urlRequired")),null;const A=w.clientToken?.trim()||void 0,M=w.label?.trim()||Gt(Ke({candidates:R}));if(Re()){const N=Ee({candidates:R});if(A)await Je(N,A);else if(y?.hasToken){const q=Ee(y);if(q&&N&&q!==N){const $=await Ot(q);$&&await Je(N,$)}}}return b({id:w.id,label:M,candidates:R,clientToken:A}).find(N=>Xt(N.candidates,R))??null},[b,e]),P=l.useCallback(async w=>{const R=d.current.find(A=>A.id===w)??null,y=await ol(w);return h(y),R},[h]);return{connections:s,isBusy:r!==null,isPasswordBusy:r==="password",error:a,pendingConnection:u,connect:I,redeemPairingConnection:S,submitPassword:E,cancelPassword:T,saveConnection:k,removeConnection:P,setError:c}},Ir=n=>{const e=ue.c(31),{onClose:s}=n,{t:o}=me(),[r,i]=l.useState(!1);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=Oa(),e[0]=a):a=e[0];const c=a;let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{No(Ba()).then(w=>{w.ok&&(i(!0),window.setTimeout(()=>i(!1),2e3))})},e[1]=u):u=e[1];const f=u;let d;e[2]!==o?(d=o("mobile.connectionDebug.title"),e[2]=o,e[3]=d):d=e[3];let p;e[4]!==d?(p=t.jsx("h2",{className:"min-w-0 truncate typography-ui-label text-foreground",children:d}),e[4]=d,e[5]=p):p=e[5];const g=r?"check":"file-copy";let h;e[6]!==g?(h=t.jsx(ee,{name:g,className:"size-4"}),e[6]=g,e[7]=h):h=e[7];let x;e[8]!==r||e[9]!==o?(x=o(r?"mobile.connectionDebug.copied":"mobile.connectionDebug.copy"),e[8]=r,e[9]=o,e[10]=x):x=e[10];let j;e[11]!==h||e[12]!==x?(j=t.jsxs(ye,{type:"button",variant:"outline",size:"sm",onClick:f,disabled:c.length===0,children:[h,x]}),e[11]=h,e[12]=x,e[13]=j):j=e[13];let b;e[14]!==o?(b=o("mobile.connectionDebug.close"),e[14]=o,e[15]=b):b=e[15];let I;e[16]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx(ee,{name:"close",className:"size-[18px]"}),e[16]=I):I=e[16];let S;e[17]!==s||e[18]!==b?(S=t.jsx(ye,{type:"button",variant:"ghost",size:"icon","aria-label":b,onClick:s,children:I}),e[17]=s,e[18]=b,e[19]=S):S=e[19];let E;e[20]!==S||e[21]!==j?(E=t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[j,S]}),e[20]=S,e[21]=j,e[22]=E):E=e[22];let T;e[23]!==E||e[24]!==p?(T=t.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border/70 px-4 py-2.5",children:[p,E]}),e[23]=E,e[24]=p,e[25]=T):T=e[25];let k;e[26]!==o?(k=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:o("mobile.connectionDebug.empty")}):t.jsx("pre",{className:"whitespace-pre-wrap break-words typography-code text-muted-foreground",children:c.map(vr).join(`
4
+ `)})}),e[26]=o,e[27]=k):k=e[27];let P;return e[28]!==T||e[29]!==k?(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:[T,k]}),e[28]=T,e[29]=k,e[30]=P):P=e[30],P},_r=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&(typeof e.scan=="function"||typeof e.startScan=="function")?e:null},ml=()=>window.Capacitor?.getPlatform?.()==="android",Dr=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},Mr=(n,e)=>{const s=Dr(n);if(!s&&e?.pairingStringFallback){const o=bo(n);if(o)return{status:"pairing",pairing:o}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},pl=async(n,e)=>{if(!n.startScan||!n.stopScan||!n.addListener)return{status:"unsupported"};if(e?.aborted)return{status:"cancelled"};let s,o,r=!1,i=()=>{};const a=new Promise(f=>{i=f}),c=f=>{r||(r=!0,i(f))},u=()=>c({status:"cancelled"});e?.addEventListener("abort",u,{once:!0});try{return(await Promise.allSettled([Promise.resolve(n.addListener("barcodesScanned",({barcodes:d})=>{const p=d?.[0],g=(p?.rawValue??p?.displayValue??"").trim();g&&c(Mr(g,{pairingStringFallback:!0}))})).then(d=>{s=d}),Promise.resolve(n.addListener("scanError",()=>c({status:"failed"}))).then(d=>{o=d})])).some(({status:d})=>d==="rejected")?c({status:"failed"}):r||n.startScan({formats:["QR_CODE"]}).catch(()=>c({status:"failed"})),await a}finally{e?.removeEventListener("abort",u),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(o?.remove()),n.stopScan()])}},bs=()=>_r()!==null,zr=async n=>{const e=_r();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(ml())return pl(e,n?.signal);if(!e.scan)return{status:"unsupported"};const o=(await e.scan({formats:["QR_CODE"]}))?.barcodes?.[0],r=(o?.rawValue??o?.displayValue??"").trim();return r?Mr(r):{status:"cancelled"}}catch{return{status:"failed"}}},ft={autoComplete:"off",autoCorrect:"off",spellCheck:!1},Tt="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-primary focus:ring-2 focus:ring-primary/20",Or=n=>{const e=ue.c(22),{onCancel:s}=n,{t:o}=me(),r=l.useRef(null);let i,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{const I={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},S={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 E=new Map,T=P=>{!(P instanceof HTMLElement)||P===r.current||E.has(P)||(E.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(T);const k=new MutationObserver(P=>{P.forEach(w=>w.addedNodes.forEach(T))});return k.observe(document.body,{childList:!0}),()=>{k.disconnect(),E.forEach(hl),I.value?document.documentElement.style.setProperty("background-color",I.value,I.priority):document.documentElement.style.removeProperty("background-color"),S.value?document.body.style.setProperty("background-color",S.value,S.priority):document.body.style.removeProperty("background-color")}},a=[],e[0]=i,e[1]=a):(i=e[0],a=e[1]),l.useLayoutEffect(i,a);let c,u;e[2]!==s?(c=()=>{const I=()=>{document.visibilityState==="hidden"&&s()};return document.addEventListener("visibilitychange",I),()=>document.removeEventListener("visibilitychange",I)},u=[s],e[2]=s,e[3]=c,e[4]=u):(c=e[3],u=e[4]),l.useEffect(c,u);let f;e[5]!==o?(f=o("mobile.connect.scanQr"),e[5]=o,e[6]=f):f=e[6];let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d=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]=d):d=e[7];let p;e[8]!==o?(p=o("mobile.connect.welcome.scanHint"),e[8]=o,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:[d,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(ee,{name:"close",className:"size-[18px]"}),e[12]=h):h=e[12];let x;e[13]!==o?(x=o("mobile.instances.cancelEdit"),e[13]=o,e[14]=x):x=e[14];let j;e[15]!==s||e[16]!==x?(j=t.jsxs(ye,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:s,children:[h,x]}),e[15]=s,e[16]=x,e[17]=j):j=e[17];let b;return e[18]!==j||e[19]!==f||e[20]!==g?(b=mt.createPortal(t.jsxs("div",{ref:r,role:"dialog","aria-modal":"true","aria-label":f,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,j]}),document.body),e[18]=j,e[19]=f,e[20]=g,e[21]=b):b=e[21],b},Lr=()=>{const n=ue.c(6),{t:e}=me();let s;n[0]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsx(Ye,{width:96,height:96,isAnimated:!0}),n[0]=s):s=n[0];let o;n[1]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx(ee,{name:"loader-4",className:"size-[18px] animate-spin"}),n[1]=o):o=n[1];let r;n[2]!==e?(r=e("mobile.connect.connecting"),n[2]=e,n[3]=r):r=n[3];let i;return n[4]!==r?(i=mt.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:[o,t.jsx("span",{children:r})]})]}),document.body),n[4]=r,n[5]=i):i=n[5],i};function hl(n,e){e.style.opacity=n.opacity,e.style.pointerEvents=n.pointerEvents}const gl=({onConnected:n,notice:e=null})=>{const{t:s}=me(),o=Ar(n),{connections:r,isBusy:i,isPasswordBusy:a,error:c,pendingConnection:u}=o,[f,d]=l.useState(""),[p,g]=l.useState(""),[h,x]=l.useState(""),[j,b]=l.useState(!1),[I,S]=l.useState(!1),E=l.useRef(null),T=l.useMemo(()=>bs(),[]),[k,P]=l.useState(()=>!bs()),[w,R]=l.useState(null),[y,A]=l.useState(""),[M,C]=l.useState(!1),N=wr(l.useCallback(()=>C(!0),[])),q=l.useCallback(z=>{z.preventDefault(),o.connect({url:f,clientToken:h,label:p})},[h,o,p,f]),$=l.useCallback(z=>{if(/^openchamber:\/\//i.test(z.trim())){const L=Dr(z);if(L){if("pairing"in L){o.redeemPairingConnection(L.pairing);return}d(L.url),L.label&&g(L.label),L.clientToken&&x(L.clientToken);return}}d(z)},[o]),v=l.useCallback(async()=>{if(E.current||i)return;o.setError(null),b(!0);const z=new AbortController;E.current=z;try{const L=await zr({signal:z.signal});switch(E.current===z&&(E.current=null,b(!1)),L.status){case"ok":S(!0),d(L.url),L.label&&g(L.label),L.clientToken&&x(L.clientToken),await o.connect({url:L.url,clientToken:L.clientToken,label:L.label});break;case"pairing":S(!0),await o.redeemPairingConnection(L.pairing);break;case"permission-denied":o.setError(s("mobile.connect.scan.permissionDenied"));break;case"invalid":o.setError(s("mobile.connect.scan.invalid"));break;case"unsupported":o.setError(s("mobile.connect.scan.unsupported"));break;case"failed":o.setError(s("mobile.connect.scan.failed"));break;default:break}}finally{S(!1),E.current===z&&(E.current=null,b(!1))}},[o,i,s]);l.useEffect(()=>()=>E.current?.abort(),[]);const _=l.useCallback(z=>{z.preventDefault(),o.submitPassword(y)},[o,y]),O=l.useCallback(()=>{A(""),o.cancelPassword()},[o]);return t.jsxs(t.Fragment,{children:[j?t.jsx(Or,{onCancel:()=>E.current?.abort()}):null,I?t.jsx(Lr,{}):null,M?t.jsx(Ir,{onClose:()=>C(!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",{...N,className:"select-none",style:{touchAction:"manipulation"},children:t.jsx(Ye,{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(ee,{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,u?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:_,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(ee,{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:u.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:u.candidates.some(z=>z.kind==="direct")?Ke(u):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...ft,value:y,onChange:z=>A(z.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:Tt}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ye,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!y.trim(),children:s(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ye,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:O,children:s("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[T?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(ye,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{v()},disabled:j||i,children:[t.jsx(ee,{name:"scan-2",className:X("size-[18px]",j&&"animate-pulse")}),s(i?"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&&!k?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(z=>{const L=w===z.id;return t.jsxs("button",{type:"button",disabled:i,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-primary disabled:opacity-70",onClick:()=>{R(z.id),o.connect({id:z.id,candidates:z.candidates,clientToken:z.clientToken,label:z.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(ee,{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:z.label}),t.jsx("span",{className:X("block truncate typography-small",L?"text-foreground":"text-muted-foreground"),children:L?s("mobile.connect.connecting"):z.candidates.some(te=>te.kind==="direct")?Ke(z):s("mobile.connect.relay.badge")})]}),L?t.jsx(ee,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(ee,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},z.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[T?t.jsxs("button",{type:"button",onClick:()=>P(z=>!z),"aria-expanded":k,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-primary",children:[t.jsx("span",{children:s("mobile.connect.manual.toggle")}),t.jsx(ee,{name:"arrow-down-s",className:X("size-4 transition-transform duration-200",k&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:k?"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:q,children:[t.jsx("input",{...ft,value:f,onChange:z=>$(z.target.value),placeholder:s("mobile.connect.url.placeholder"),"aria-label":s("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:k?void 0:-1,className:X(Tt,"text-center")}),t.jsx("input",{value:p,onChange:z=>g(z.target.value),placeholder:s("mobile.instances.label.placeholder"),"aria-label":s("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:k?void 0:-1,className:X(Tt,"text-center")}),t.jsx("input",{...ft,value:h,onChange:z=>x(z.target.value),placeholder:s("mobile.connect.token.placeholder"),"aria-label":s("mobile.connect.token.label"),tabIndex:k?void 0:-1,autoCapitalize:"none",className:X(Tt,"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(ye,{type:"submit",variant:T?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||j||!f.trim(),children:s(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})]})},bl=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"},xl=n=>{const e=ue.c(12),{groups:s,displayMode:o,timeFormatPreference:r,className:i}=n;let a;e[0]!==i?(a=X("space-y-1.5",i),e[0]=i,e[1]=a):a=e[1];let c;if(e[2]!==o||e[3]!==s||e[4]!==r){let f;e[6]!==o||e[7]!==r?(f=d=>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:d.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:d.providerName}),d.planLabel?t.jsx("span",{className:"shrink-0 typography-micro capitalize text-muted-foreground",children:d.planLabel}):null,d.status&&d.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:d.status}):null]}),d.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:d.rows.map(p=>{const g=o==="remaining"?p.window.remainingPercent:p.window.usedPercent,h=Eo(p.window.valueLabel,g),x=Ro(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}),x?t.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground/70",children:x}):null]}),t.jsx("span",{className:X("shrink-0 typography-ui-label font-semibold tabular-nums",bl(p.window)),children:h==="-"?"":h})]},p.key)})}):null,d.status&&d.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:d.status}):null]},d.providerId),e[6]=o,e[7]=r,e[8]=f):f=e[8],c=s.map(f),e[2]=o,e[3]=s,e[4]=r,e[5]=c}else c=e[5];let u;return e[9]!==a||e[10]!==c?(u=t.jsx("div",{className:a,children:c}),e[9]=a,e[10]=c,e[11]=u):u=e[11],u},Tn=380,yl=(n,e)=>{if(!n||typeof n!="object")return;const s=n[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},rt=n=>typeof n=="number"&&Number.isFinite(n)?n:0,An=n=>n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(n),Br=n=>{const e=ue.c(19),{percentage:s}=n;let o,r,i,a,c,u,f;if(e[0]!==s){i=_o(s)??0;const x=Do(s);r=x==="critical"?"var(--status-error)":x==="warn"?"var(--status-warning)":"var(--status-success)",o=2*Math.PI*7.5,a="0 0 18 18",c="size-[18px] -rotate-90",u="progressbar",f=Math.round(i),e[0]=s,e[1]=o,e[2]=r,e[3]=i,e[4]=a,e[5]=c,e[6]=u,e[7]=f}else o=e[1],r=e[2],i=e[3],a=e[4],c=e[5],u=e[6],f=e[7];let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=d):d=e[8];const p=o*(1-i/100);let g;e[9]!==o||e[10]!==r||e[11]!==p?(g=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:r,strokeWidth:3,strokeLinecap:"round",strokeDasharray:o,strokeDashoffset:p,className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=o,e[10]=r,e[11]=p,e[12]=g):g=e[12];let h;return e[13]!==a||e[14]!==c||e[15]!==u||e[16]!==f||e[17]!==g?(h=t.jsxs("svg",{viewBox:a,className:c,role:u,"aria-valuenow":f,"aria-valuemin":0,"aria-valuemax":100,children:[d,g]}),e[13]=a,e[14]=c,e[15]=u,e[16]=f,e[17]=g,e[18]=h):h=e[18],h},vl=n=>{const e=ue.c(13),{icon:s,iconNode:o,label:r,children:i}=n;let a;e[0]!==s||e[1]!==o?(a=o??(s?t.jsx(ee,{name:s,className:"size-[18px]"}):null),e[0]=s,e[1]=o,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 u;e[5]!==r?(u=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:r}),e[5]=r,e[6]=u):u=e[6];let f;e[7]!==i?(f=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:i}),e[7]=i,e[8]=f):f=e[8];let d;return e[9]!==c||e[10]!==u||e[11]!==f?(d=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[c,u,f]}),e[9]=c,e[10]=u,e[11]=f,e[12]=d):d=e[12],d},wl=n=>{const e=ue.c(49),{open:s,onClose:o,anchorRef:r,contextDisplay:i,usageGroups:a,usageDisplayMode:c,isUsageLoading:u,timeFormatPreference:f}=n,{t:d}=me(),p=l.useRef(null),[g,h]=l.useState(s),[x,j]=l.useState(!1),{enabled:b}=Ss(),I=l.useRef(null),[S,E]=l.useState(null);let T,k;e[0]!==r||e[1]!==b||e[2]!==s||e[3]!==g?(T=()=>{if(!s||!b||!g)return;const H=()=>{const se=r.current?.getBoundingClientRect(),ae=I.current?.getBoundingClientRect();if(!se||!ae){E(null);return}const he=se.left-ae.left,oe=Math.min(Math.max(he,8),Math.max(8,ae.width-Tn-8));E(oe)};H();const W=I.current;if(typeof ResizeObserver>"u"||!W)return;const Z=new ResizeObserver(H);return Z.observe(W),()=>Z.disconnect()},k=[r,b,s,g],e[0]=r,e[1]=b,e[2]=s,e[3]=g,e[4]=T,e[5]=k):(T=e[4],k=e[5]),l.useLayoutEffect(T,k);const P=b&&S!==null;let w,R;e[6]!==s||e[7]!==g?(w=()=>{if(s){h(!0),j(!1);return}if(!g)return;j(!0);const H=window.setTimeout(()=>{h(!1),j(!1)},140);return()=>window.clearTimeout(H)},R=[s,g],e[6]=s,e[7]=g,e[8]=w,e[9]=R):(w=e[8],R=e[9]),l.useEffect(w,R);let y,A;e[10]!==o||e[11]!==s?(y=()=>{if(!s)return;const H=W=>{W.key==="Escape"&&o()};return document.addEventListener("keydown",H),()=>document.removeEventListener("keydown",H)},A=[o,s],e[10]=o,e[11]=s,e[12]=y,e[13]=A):(y=e[12],A=e[13]),l.useEffect(y,A);let M,C;if(e[14]!==r||e[15]!==o||e[16]!==s?(M=()=>{if(!s)return;const H=W=>{const Z=W.target;if(!(Z instanceof Node)){o();return}p.current?.contains(Z)||r.current?.contains(Z)||o()};return document.addEventListener("pointerdown",H,!0),document.addEventListener("wheel",H,!0),()=>{document.removeEventListener("pointerdown",H,!0),document.removeEventListener("wheel",H,!0)}},C=[r,o,s],e[14]=r,e[15]=o,e[16]=s,e[17]=M,e[18]=C):(M=e[17],C=e[18]),l.useEffect(M,C),!g)return null;let N;e[19]!==d?(N=d("mobile.header.openMetadataAria"),e[19]=d,e[20]=N):N=e[20];const q=P?"absolute origin-top-left":"mx-3 mt-2",$=x?"pointer-events-none":"pointer-events-auto";let v;e[21]!==q||e[22]!==$?(v=X("overflow-y-auto overscroll-contain rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",q,$),e[21]=q,e[22]=$,e[23]=v):v=e[23];const _=`${x?"session-metadata-out":"session-metadata-in"} ${x?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let O;e[24]!==S||e[25]!==P?(O=P?{top:8,left:S??8,width:`min(${Tn}px, calc(100% - 16px))`}:null,e[24]=S,e[25]=P,e[26]=O):O=e[26];let z;e[27]!==_||e[28]!==O?(z={animation:_,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...O},e[27]=_,e[28]=O,e[29]=z):z=e[29];let L;e[30]!==i||e[31]!==d?(L=i?t.jsx(vl,{iconNode:t.jsx(Br,{percentage:i.percentage}),label:d("mobile.header.metadata.context"),children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:X("font-semibold",i.colorClass),children:[i.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:i.tokens})]})}):null,e[30]=i,e[31]=d,e[32]=L):L=e[32];let te;e[33]!==u||e[34]!==f||e[35]!==c||e[36]!==a?(te=t.jsx(jl,{groups:a,displayMode:c,isLoading:u,timeFormatPreference:f}),e[33]=u,e[34]=f,e[35]=c,e[36]=a,e[37]=te):te=e[37];let Q;e[38]!==L||e[39]!==te?(Q=t.jsxs("div",{className:"space-y-1",children:[L,te]}),e[38]=L,e[39]=te,e[40]=Q):Q=e[40];let D;e[41]!==v||e[42]!==z||e[43]!==Q||e[44]!==N?(D=t.jsx("div",{ref:p,role:"dialog","aria-label":N,className:v,style:z,children:Q}),e[41]=v,e[42]=z,e[43]=Q,e[44]=N,e[45]=D):D=e[45];let J;e[46]===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[46]=J):J=e[46];let K;return e[47]!==D?(K=t.jsxs("div",{ref:I,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:[D,J]}),e[47]=D,e[48]=K):K=e[48],K},jl=n=>{const e=ue.c(30),{groups:s,displayMode:o,isLoading:r,timeFormatPreference:i}=n,{t:a}=me();let c;e[0]!==o||e[1]!==a?(c=a(o==="remaining"?"header.services.remaining":"header.services.used"),e[0]=o,e[1]=a,e[2]=c):c=e[2];const u=c;if(s.length===0){if(!r)return null;let S;e[3]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx(ee,{name:"loader-4",className:"size-4 animate-spin","aria-hidden":!0}),e[3]=S):S=e[3];let E;e[4]!==a?(E=a("common.loading"),e[4]=a,e[5]=E):E=e[5];let T;return e[6]!==E?(T=t.jsxs("div",{className:"flex items-center justify-center gap-2 px-2.5 py-6 text-muted-foreground",children:[S,t.jsx("span",{className:"typography-ui-label",children:E})]}),e[6]=E,e[7]=T):T=e[7],T}let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:t.jsx(ee,{name:"timer",className:"size-[18px]"})}),e[8]=f):f=e[8];let d;e[9]!==a?(d=a("mobile.header.metadata.usage"),e[9]=a,e[10]=d):d=e[10];let p;e[11]!==d?(p=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:d}),e[11]=d,e[12]=p):p=e[12];let g;e[13]!==r?(g=r?t.jsx(ee,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[13]=r,e[14]=g):g=e[14];let h;e[15]!==u?(h=t.jsx("span",{className:"truncate",children:u}),e[15]=u,e[16]=h):h=e[16];let x;e[17]!==g||e[18]!==h?(x=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]=x):x=e[19];let j;e[20]!==p||e[21]!==x?(j=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[f,p,x]}),e[20]=p,e[21]=x,e[22]=j):j=e[22];let b;e[23]!==o||e[24]!==s||e[25]!==i?(b=t.jsx(xl,{groups:s,displayMode:o,timeFormatPreference:i}),e[23]=o,e[24]=s,e[25]=i,e[26]=b):b=e[26];let I;return e[27]!==j||e[28]!==b?(I=t.jsxs("div",{className:"pt-2.5",children:[j,b]}),e[27]=j,e[28]=b,e[29]=I):I=e[29],I},kl=l.memo(function({open:e,onOpenChange:s,currentSessionId:o,effectiveDirectory:r,isNewSessionDraftOpen:i}){const{t:a}=me(),c=l.useRef(null),u=Po(o??"",r||void 0),f=Me(_=>_.providers),d=Me(_=>_.currentProviderId),p=Me(_=>_.currentModelId),g=Me(_=>_.getModelMetadata);Me(_=>_.modelsMetadata.size);const h=To(l.useCallback(_=>o?_.sessionModelSelections.get(o)??null:null,[o])),x=nt(_=>_.results),j=nt(_=>_.loadSettings),b=nt(_=>_.fetchAllQuotas),I=nt(_=>_.isLoading),S=nt(_=>_.displayMode),E=nt(_=>_.dropdownProviderIds),T=Ge(_=>_.timeFormatPreference);Ao(),l.useEffect(()=>{j()},[j]),l.useEffect(()=>{gn(E)},[E]),l.useEffect(()=>{!e||I||!E.some(O=>!x.some(z=>z.providerId===O))||b()},[E,b,I,e,x]);const P=l.useMemo(()=>{for(let _=u.length-1;_>=0;_-=1){const O=u[_];if(O.role!=="user")continue;const z=typeof O.model?.providerID=="string"&&O.model.providerID.trim().length>0?O.model.providerID:void 0,L=typeof O.model?.modelID=="string"&&O.model.modelID.trim().length>0?O.model.modelID:void 0;if(z&&L)return{providerID:z,modelID:L}}return null},[u])??(h?{providerID:h.providerId,modelID:h.modelId}:null)??(d&&p?{providerID:d,modelID:p}:null),R=(P?f.find(_=>_.id===P.providerID):void 0)?.models.find(_=>_.id===P?.modelID),y=P?g(P.providerID,P.modelID):void 0,A=yl(R?.limit,"context")??y?.limit?.context??0,M=l.useMemo(()=>{for(let _=u.length-1;_>=0;_-=1){const O=u[_];if(O.role!=="assistant"||!O.tokens)continue;const z=rt(O.tokens.total);if(z>0)return z;const L=rt(O.tokens.input)+rt(O.tokens.output)+rt(O.tokens.reasoning)+rt(O.tokens.cache?.read)+rt(O.tokens.cache?.write);if(L>0)return L}return 0},[u]),C=!i&&M>0&&A>0?Math.min(M/A*100,999):null,N=C!==null?`${An(M)}/${An(A)}`:null,q=C===null?"":C>=90?"text-[var(--status-error)]":C>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]",$=C!==null&&N?{percentage:C,tokens:N,colorClass:q}:null,v=Io();return l.useEffect(()=>{!e||v.length===0||gn(v.map(_=>_.providerId))},[e,v]),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-primary","aria-label":a("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>s(_=>!_),style:{touchAction:"manipulation"},children:t.jsx(Br,{percentage:$?.percentage??0})}),t.jsx(wl,{open:e,onClose:()=>s(!1),anchorRef:c,contextDisplay:$,usageGroups:v,usageDisplayMode:S,isUsageLoading:I,timeFormatPreference:T})]})}),Sl=10,In=380,Nl=(n,e)=>n.title?.trim()||e,Cl=n=>{const e=ue.c(32),{session:s,meta:o,active:r,onSelect:i}=n,{t:a}=me(),c=sr(s.id),u=nr(s.id),f=c?.type??"idle",d=f==="busy"||f==="retry",p=!d&&u>0&&!r,g=rr(s.id,d),h=(d||p)&&g,x=s.time?.updated??s.time?.created??0;let j;e[0]!==x?(j=zo(x),e[0]=x,e[1]=j):j=e[1];const b=j,I=r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let S;e[2]!==I?(S=X("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",I),e[2]=I,e[3]=S):S=e[3];let E;e[4]===Symbol.for("react.memo_cache_sentinel")?(E={touchAction:"manipulation"},e[4]=E):E=e[4];const T=r?"text-primary":"text-foreground";let k;e[5]!==T?(k=X("block truncate typography-ui-label",T),e[5]=T,e[6]=k):k=e[6];let P;e[7]!==s||e[8]!==a?(P=Nl(s,a("sessions.sidebar.session.untitled")),e[7]=s,e[8]=a,e[9]=P):P=e[9];let w;e[10]!==k||e[11]!==P?(w=t.jsx("span",{className:k,children:P}),e[10]=k,e[11]=P,e[12]=w):w=e[12];let R;e[13]!==o?(R=o?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:o}):null,e[13]=o,e[14]=R):R=e[14];let y;e[15]!==R||e[16]!==w?(y=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[w,R]}),e[15]=R,e[16]=w,e[17]=y):y=e[17];let A;e[18]!==d||e[19]!==p?(A=d||p?t.jsx("span",{className:X("size-1.5 shrink-0 rounded-full",d?"bg-primary":"bg-[var(--status-info)]"),"aria-hidden":!0}):null,e[18]=d,e[19]=p,e[20]=A):A=e[20];let M;e[21]!==d||e[22]!==s.id||e[23]!==h||e[24]!==b?(M=h?t.jsx(pr,{sessionId:s.id,running:d,className:"typography-micro"}):b?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:b}):null,e[21]=d,e[22]=s.id,e[23]=h,e[24]=b,e[25]=M):M=e[25];let C;return e[26]!==i||e[27]!==y||e[28]!==A||e[29]!==M||e[30]!==S?(C=t.jsxs("button",{type:"button",className:S,onClick:i,style:E,children:[y,A,M]}),e[26]=i,e[27]=y,e[28]=A,e[29]=M,e[30]=S,e[31]=C):C=e[31],C},El=n=>{const e=ue.c(50),{open:s,onClose:o,anchorRef:r}=n,{t:i}=me(),a=l.useRef(null),[c,u]=l.useState(s),[f,d]=l.useState(!1),{enabled:p}=Ss(),g=l.useRef(null),[h,x]=l.useState(null);let j,b;e[0]!==r||e[1]!==p||e[2]!==s||e[3]!==c?(j=()=>{if(!s||!p||!c)return;const W=()=>{const ae=r.current?.getBoundingClientRect(),he=g.current?.getBoundingClientRect();if(!ae||!he){x(null);return}const oe=ae.left-he.left;x(Math.min(Math.max(oe,8),Math.max(8,he.width-In-8)))};W();const Z=g.current;if(typeof ResizeObserver>"u"||!Z)return;const se=new ResizeObserver(W);return se.observe(Z),()=>se.disconnect()},b=[r,p,s,c],e[0]=r,e[1]=p,e[2]=s,e[3]=c,e[4]=j,e[5]=b):(j=e[4],b=e[5]),l.useLayoutEffect(j,b);const I=p&&h!==null,S=je(Rl),E=je(Pl),T=ze(Tl);let k;e[6]===Symbol.for("react.memo_cache_sentinel")?(k={maxParents:Sl},e[6]=k):k=e[6];const P=Mo(s||c,k);let w,R;e[7]!==s||e[8]!==c?(w=()=>{if(s){Ns(),u(!0),d(!1);return}if(!c)return;d(!0);const W=window.setTimeout(()=>{u(!1),d(!1)},140);return()=>window.clearTimeout(W)},R=[s,c],e[7]=s,e[8]=c,e[9]=w,e[10]=R):(w=e[9],R=e[10]),l.useEffect(w,R);let y,A;e[11]!==o||e[12]!==s?(y=()=>{if(!s)return;const W=Z=>{Z.key==="Escape"&&o()};return document.addEventListener("keydown",W),()=>document.removeEventListener("keydown",W)},A=[o,s],e[11]=o,e[12]=s,e[13]=y,e[14]=A):(y=e[13],A=e[14]),l.useEffect(y,A);let M,C;e[15]!==r||e[16]!==o||e[17]!==s?(M=()=>{if(!s)return;const W=Z=>{const se=Z.target;if(!(se instanceof Node)){o();return}a.current?.contains(se)||r.current?.contains(se)||o()};return document.addEventListener("pointerdown",W,!0),()=>document.removeEventListener("pointerdown",W,!0)},C=[r,o,s],e[15]=r,e[16]=o,e[17]=s,e[18]=M,e[19]=C):(M=e[18],C=e[19]),l.useEffect(M,C);let N;e[20]!==o||e[21]!==E?(N=W=>{E(W.id,ks(W)),o()},e[20]=o,e[21]=E,e[22]=N):N=e[22];const q=N;if(!c)return null;let $;e[23]!==i?($=i("sessions.switcher.openAria"),e[23]=i,e[24]=$):$=e[24];const v=I?"absolute origin-top-left":"mx-3 mt-2",_=f?"pointer-events-none":"pointer-events-auto";let O;e[25]!==v||e[26]!==_?(O=X("flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",v,_),e[25]=v,e[26]=_,e[27]=O):O=e[27];const z=`${f?"session-switcher-out":"session-switcher-in"} ${f?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let L;e[28]!==h||e[29]!==I?(L=I?{top:8,left:h??8,width:`min(${In}px, calc(100% - 16px))`}:null,e[28]=h,e[29]=I,e[30]=L):L=e[30];let te;e[31]!==z||e[32]!==L?(te={animation:z,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...L},e[31]=z,e[32]=L,e[33]=te):te=e[33];let Q;e[34]!==S||e[35]!==q||e[36]!==P||e[37]!==T||e[38]!==i?(Q=P.length===0?t.jsx("p",{className:"px-3 py-6 text-center typography-small text-muted-foreground",children:i("sessions.switcher.empty")}):P.map(W=>{const Z=W.node.session,se=[W.secondaryMeta?.projectLabel,W.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(Cl,{session:Z,meta:se,active:Z.id===S,onSelect:()=>{W.projectId&&T(W.projectId),q(Z)}},Z.id)}),e[34]=S,e[35]=q,e[36]=P,e[37]=T,e[38]=i,e[39]=Q):Q=e[39];let D;e[40]!==Q?(D=t.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:Q}),e[40]=Q,e[41]=D):D=e[41];let J;e[42]!==$||e[43]!==O||e[44]!==te||e[45]!==D?(J=t.jsx("div",{ref:a,role:"dialog","aria-label":$,className:O,style:te,children:D}),e[42]=$,e[43]=O,e[44]=te,e[45]=D,e[46]=J):J=e[46];let K;e[47]===Symbol.for("react.memo_cache_sentinel")?(K=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]=K):K=e[47];let H;return e[48]!==J?(H=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:[J,K]}),e[48]=J,e[49]=H):H=e[49],H};function Rl(n){return n.currentSessionId}function Pl(n){return n.setCurrentSession}function Tl(n){return n.setActiveProjectIdOnly}const Al=n=>{const e=ue.c(71),{onOpenSessions:s,onOpenWorkspace:o,compactTitle:r}=n,i=r===void 0?!1:r,{t:a}=me(),[c,u]=l.useState(!1),[f,d]=l.useState(!1),p=l.useRef(null),g=Qe(Il),h=je(_l);let x;e[0]!==h?(x=Te=>h?Te.getDirectoryForSession(h):null,e[0]=h,e[1]=x):x=e[1];const b=je(x)||g,I=Oo(h,b||void 0),S=je(Dl);let E;e[2]!==I?.title?(E=I?.title?.trim(),e[2]=I?.title,e[3]=E):E=e[3];const T=E;let k;e[4]!==h||e[5]!==T||e[6]!==a?(k=T||a(h?"mobile.sessions.untitled":"sessions.switcher.draftTitle"),e[4]=h,e[5]=T,e[6]=a,e[7]=k):k=e[7];const P=k;let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{u(!1),d(!1)},e[8]=w):w=e[8];let R;e[9]!==h||e[10]!==b?(R=[h,b],e[9]=h,e[10]=b,e[11]=R):R=e[11],l.useEffect(w,R);let y;e[12]!==s?(y=()=>{u(!1),d(!1),s()},e[12]=s,e[13]=y):y=e[13];const A=y;let M;e[14]===Symbol.for("react.memo_cache_sentinel")?(M=Te=>{u(Ie=>{const we=typeof Te=="function"?Te(Ie):Te;return we&&d(!1),we})},e[14]=M):M=e[14];const C=M;let N;e[15]===Symbol.for("react.memo_cache_sentinel")?(N=()=>{d(Te=>{const Ie=!Te;return Ie&&u(!1),Ie})},e[15]=N):N=e[15];const q=N;let $;e[16]===Symbol.for("react.memo_cache_sentinel")?($={paddingTop:"var(--oc-safe-area-top, 0px)"},e[16]=$):$=e[16];let v;e[17]!==a?(v=a("mobile.sessions.openSheetAria"),e[17]=a,e[18]=v):v=e[18];let _,O;e[19]===Symbol.for("react.memo_cache_sentinel")?(_={touchAction:"manipulation"},O=t.jsx(ee,{name:"list-unordered",className:"size-5"}),e[19]=_,e[20]=O):(_=e[19],O=e[20]);let z;e[21]!==A||e[22]!==v?(z=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":v,onClick:A,style:_,children:O}),e[21]=A,e[22]=v,e[23]=z):z=e[23];const L=i?"shrink":"flex-1";let te;e[24]!==L?(te=X("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",L),e[24]=L,e[25]=te):te=e[25];let Q;e[26]!==a?(Q=a("sessions.switcher.openAria"),e[26]=a,e[27]=Q):Q=e[27];let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D={touchAction:"manipulation"},e[28]=D):D=e[28];let J;e[29]!==P?(J=t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:P}),e[29]=P,e[30]=J):J=e[30];const K=f&&"rotate-180";let H;e[31]!==K?(H=X("size-4 shrink-0 text-muted-foreground transition-transform duration-150",K),e[31]=K,e[32]=H):H=e[32];let W;e[33]!==H?(W=t.jsx(ee,{name:"arrow-down-s",className:H}),e[33]=H,e[34]=W):W=e[34];let Z;e[35]!==J||e[36]!==W?(Z=t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[J,W]}),e[35]=J,e[36]=W,e[37]=Z):Z=e[37];let se;e[38]!==f||e[39]!==te||e[40]!==Q||e[41]!==Z?(se=t.jsx("button",{ref:p,type:"button",className:te,"aria-label":Q,"aria-haspopup":"dialog","aria-expanded":f,onClick:q,style:D,children:Z}),e[38]=f,e[39]=te,e[40]=Q,e[41]=Z,e[42]=se):se=e[42];let ae;e[43]!==i?(ae=i?t.jsx("div",{className:"min-w-0 flex-1"}):null,e[43]=i,e[44]=ae):ae=e[44];let he;e[45]!==h||e[46]!==b||e[47]!==S||e[48]!==c?(he=t.jsx(kl,{open:c,onOpenChange:C,currentSessionId:h,effectiveDirectory:b,isNewSessionDraftOpen:S}),e[45]=h,e[46]=b,e[47]=S,e[48]=c,e[49]=he):he=e[49];let oe;e[50]!==a?(oe=a("mobile.header.openWorkspaceAria"),e[50]=a,e[51]=oe):oe=e[51];let U;e[52]!==o?(U=()=>{u(!1),d(!1),o()},e[52]=o,e[53]=U):U=e[53];let ie,V;e[54]===Symbol.for("react.memo_cache_sentinel")?(ie={touchAction:"manipulation"},V=t.jsx(ee,{name:"pencil-ruler-2",className:"size-5"}),e[54]=ie,e[55]=V):(ie=e[54],V=e[55]);let de;e[56]!==oe||e[57]!==U?(de=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-primary","aria-label":oe,onClick:U,style:ie,children:V}),e[56]=oe,e[57]=U,e[58]=de):de=e[58];let Ne;e[59]!==z||e[60]!==se||e[61]!==ae||e[62]!==he||e[63]!==de?(Ne=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:$,children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[z,se,ae,he,de]})}),e[59]=z,e[60]=se,e[61]=ae,e[62]=he,e[63]=de,e[64]=Ne):Ne=e[64];let ke;e[65]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>d(!1),e[65]=ke):ke=e[65];let Pe;e[66]!==f?(Pe=t.jsx(El,{open:f,onClose:ke,anchorRef:p}),e[66]=f,e[67]=Pe):Pe=e[67];let Le;return e[68]!==Ne||e[69]!==Pe?(Le=t.jsxs(t.Fragment,{children:[Ne,Pe]}),e[68]=Ne,e[69]=Pe,e[70]=Le):Le=e[70],Le};function Il(n){return n.currentDirectory}function _l(n){return n.currentSessionId}function Dl(n){return!!n.newSessionDraft?.open}const Ml=({onActiveConnectionDeleted:n,onConnect:e})=>{const{t:s}=me(),o=Ar(e),{connections:r,isBusy:i,isPasswordBusy:a,error:c,pendingConnection:u,connect:f,submitPassword:d,cancelPassword:p,saveConnection:g,removeConnection:h,setError:x}=o,[j,b]=l.useState(null),I=j?r.find(U=>U.id===j)??null:null,[S,E]=l.useState(null),[T,k]=l.useState(""),[P,w]=l.useState(""),[R,y]=l.useState(""),[A,M]=l.useState(""),[C,N]=l.useState(!1),[q,$]=l.useState(!1),v=l.useRef(null),_=l.useMemo(()=>bs(),[]),[O,z]=l.useState(!1),[L,te]=l.useState(null),[Q,D]=l.useState(!1),J=wr(l.useCallback(()=>D(!0),[])),K=l.useCallback(()=>{b(null),k(""),w(""),y(""),x(null),z(!1)},[x]),H=l.useCallback(U=>{U.preventDefault(),g({id:j??void 0,url:T,label:P,clientToken:R}).then(ie=>{ie&&K()})},[R,j,P,K,g,T]),W=l.useCallback(async()=>{if(v.current)return;x(null),N(!0);const U=new AbortController;v.current=U;try{const ie=await zr({signal:U.signal});switch(v.current===U&&(v.current=null,N(!1)),ie.status){case"ok":k(ie.url),ie.label&&w(ie.label),ie.clientToken&&y(ie.clientToken),z(!0);break;case"pairing":$(!0),await o.redeemPairingConnection(ie.pairing);break;case"permission-denied":x(s("mobile.connect.scan.permissionDenied"));break;case"invalid":x(s("mobile.connect.scan.invalid"));break;case"unsupported":x(s("mobile.connect.scan.unsupported"));break;case"failed":x(s("mobile.connect.scan.failed"));break;default:break}}finally{$(!1),v.current===U&&(v.current=null,N(!1))}},[o,x,s]);l.useEffect(()=>()=>v.current?.abort(),[]);const Z=l.useCallback(U=>{U.preventDefault(),d(A)},[A,d]),se=l.useCallback(()=>{M(""),p()},[p]),ae=l.useCallback(U=>{E(ie=>ie===U?null:U)},[]),he=l.useCallback(U=>{E(null),j===U&&K();const ie=r.length===1;h(U).then(V=>{V&&(ie||Pn(V))&&n()})},[r.length,j,n,h,K]),oe=Tt;return u?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:Z,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(ee,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:u.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:u.candidates.some(U=>U.kind==="direct")?Ke(u):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...ft,value:A,onChange:U=>M(U.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:oe}),c?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ye,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!A.trim(),children:s(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ye,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:se,children:s("mobile.connect.cancelPassword")})]})})}):t.jsxs(t.Fragment,{children:[C?t.jsx(Or,{onCancel:()=>v.current?.abort()}):null,q?t.jsx(Lr,{}):null,Q?t.jsx(Ir,{onClose:()=>D(!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",{...J,className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(U=>{const ie=S===U.id,V=Pn(U),de=L===U.id,Ne=de?s("mobile.connect.connecting"):V?zt()?s("mobile.instances.status.connectedRelay"):s("mobile.instances.status.connectedDirect"):U.candidates.some(ke=>ke.kind==="direct")?Ke(U):s("mobile.connect.relay.badge");return t.jsxs("div",{className:X("flex items-center border-b border-border/70 transition-colors last:border-b-0",ie&&"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-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-60",onClick:()=>{V||(te(U.id),f({id:U.id,candidates:U.candidates,clientToken:U.clientToken,label:U.label}).finally(()=>te(null)))},disabled:i&&!de||ie,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(ee,{name:"server",className:"size-[18px]"}),V?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:U.label}),t.jsx("span",{className:X("block truncate typography-small",V&&!de?"text-[var(--status-success)]":"text-muted-foreground"),children:Ne})]}),de?t.jsx(ee,{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:[ie?t.jsxs("button",{type:"button","aria-label":s("mobile.instances.confirmDeleteAria",{label:U.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:()=>he(U.id),style:{touchAction:"manipulation"},children:[t.jsx(ee,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:s("mobile.instances.delete")})]}):U.candidates.some(ke=>ke.kind==="direct")?t.jsx("button",{type:"button","aria-label":s("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>{b(U.id),k(Ke(U)),w(U.label),y(U.clientToken||""),x(null)},style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":ie?s("mobile.instances.cancelDeleteAria",{label:U.label}):s("mobile.instances.deleteAria",{label:U.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>ae(U.id),style:{touchAction:"manipulation"},children:t.jsx(ee,{name:ie?"close":"delete-bin",className:"size-[18px]"})})]})]},U.id)})}):t.jsx("p",{...J,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")}),!O&&!I?t.jsxs("div",{className:"space-y-2",children:[_?t.jsxs(ye,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{W()},disabled:C,children:[t.jsx(ee,{name:"scan-2",className:X("size-[18px]",C&&"animate-pulse")}),s("mobile.connect.scanQr")]}):null,t.jsxs(ye,{type:"button",variant:_?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{x(null),z(!0)},children:[t.jsx(ee,{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:H,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(I?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(ye,{type:"button",variant:"ghost",size:"xs",onClick:K,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",{...ft,value:T,onChange:U=>k(U.target.value),placeholder:s("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:oe})]}),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:U=>w(U.target.value),placeholder:s("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:oe})]}),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",{...ft,value:R,onChange:U=>y(U.target.value),placeholder:s("mobile.connect.token.placeholder"),autoCapitalize:"none",className:oe}),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(ye,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:s(I?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})]})},Se=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),ls=n=>{const e=Se(n);if(!e)return"";const s=e.split("/").filter(Boolean);return s[s.length-1]?.replace(/[-_]/g," ")||e},_n=Ws(n=>({expandedParents:{},toggleParent:e=>n(s=>{const o={...s.expandedParents};return o[e]?delete o[e]:o[e]=!0,{expandedParents:o}})})),Wt=Ws()(xr(n=>({projectExpanded:{},worktreeExpanded:{},setProjectExpanded:(e,s)=>n(o=>({projectExpanded:{...o.projectExpanded,[e]:s}})),setWorktreeExpanded:(e,s)=>n(o=>({worktreeExpanded:{...o.worktreeExpanded,[e]:s}}))}),{name:"mobile-session-tree"})),xs=Ws()(xr(n=>({orderByProject:{},setWorktreeOrder:(e,s)=>n(o=>({orderByProject:{...o.orderByProject,[e]:s}}))}),{name:"mobile-worktree-order"})),Dn=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),zl=(n,e)=>{if(!n||n.length===0)return e;const s=new Map(n.map((r,i)=>[Dn(r),i])),o=r=>s.get(Dn(r.path))??Number.MAX_SAFE_INTEGER;return e.map((r,i)=>({worktree:r,index:i})).sort((r,i)=>{const a=o(r.worktree)-o(i.worktree);return a!==0?a:r.index-i.index}).map(r=>r.worktree)},At=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Ol=n=>{const e=n;return At(e.directory??e.project?.worktree??null)},$r=({open:n,project:e,worktree:s,onClose:o,onDeleted:r})=>{const{t:i}=me(),a=or(),c=js(y=>y.activeSessions),u=je(y=>y.archiveSessions),f=Qe(y=>y.currentDirectory),[d,p]=l.useState(!1),[g,h]=l.useState(!1),[x,j]=l.useState(!1),[b,I]=l.useState(!1),S=At(s?.path),E=typeof s?.branch=="string"&&s.branch.trim().length>0,T=l.useMemo(()=>{if(!S)return[];const y=new Map;for(const A of[...c,...a])Ol(A)===S&&y.set(A.id,A);return Array.from(y.values())},[c,a,S]);l.useEffect(()=>{if(!n){p(!1),h(!1),j(!1),I(!1);return}if(!s?.path)return;let y=!1;return Lo(s.path).then(A=>{y||j(!!A?.isDirty)}).catch(()=>{y||j(!!s.status?.isDirty)}),()=>{y=!0}},[n,s?.path,s?.status?.isDirty]);const k=l.useCallback(y=>{(async()=>{try{await Bo(e,y,{deleteRemoteBranch:E&&g,deleteLocalBranch:E&&d}),At(f)===S&&At(e.path)&&Qe.getState().setDirectory(At(e.path),{showOverlay:!1}),ce.success(i("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:i(E&&g?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),r?.()}catch(A){ce.error(i("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:A instanceof Error?A.message:i("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[f,d,g,E,r,e,i,S]),P=async()=>{if(!(!s||b)){I(!0);try{if(T.length>0){const{archivedIds:y,failedIds:A}=await u(T.map(M=>M.id));if(A.length>0){y.length>0&&ce.success(y.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:y.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:y.length})),ce.error(A.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:A.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:A.length}),{description:i("sessions.sidebar.dialogs.deleteResult.tryAgain")}),I(!1);return}}k(s),o()}catch(y){ce.error(i("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:y instanceof Error?y.message:i("sessions.sidebar.dialogs.deleteResult.tryAgain")}),I(!1)}finally{n||I(!1)}}};if(!s)return null;const w=s.branch||s.label||s.path,R=(y,A,M,C)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":y,disabled:C,onClick:()=>A(!y),className:X("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-primary",C&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:M}),t.jsx("span",{className:X("relative h-6 w-10 shrink-0 rounded-full transition-colors",y?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:X("absolute top-0.5 size-5 rounded-full bg-white transition-transform",y?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx($o,{open:n,onClose:o,title:i("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ye,{variant:"ghost",className:"flex-1",onClick:o,disabled:b,children:i("projectEditDialog.actions.cancel")}),t.jsx(ye,{variant:"destructive",className:"flex-1",onClick:()=>{P()},disabled:b,children:i("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:i("mobile.projectEdit.deleteWorktreeConfirm",{name:w})}),x?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:i("mobile.projectEdit.deleteWorktreeDirty")}):null,T.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.deleteWorktreeArchiveNote",{count:T.length})}):null,E?t.jsxs("div",{className:"flex flex-col gap-2",children:[R(d,p,i("mobile.projectEdit.deleteLocalBranch"),b),R(g,h,i("mobile.projectEdit.deleteRemoteBranch"),b)]}):null]})})},Mn="mobile-surface-root",cs=16,Ut=200,Ll=()=>{if(typeof document>"u")return null;let n=document.getElementById(Mn);return n||(n=document.createElement("div"),n.id=Mn,document.body.appendChild(n)),n},It=({open:n,onClose:e,title:s,subtitle:o,trailing:r,disableEscapeDismiss:i=!1,headerless:a=!1,noHeaderBorder:c=!1,ariaLabel:u,variant:f="fullscreen",dialogAlign:d="chat",children:p})=>{const{t:g}=me(),h=l.useRef(null),[x,j]=l.useState(!1),[b,I]=l.useState(!1),S=l.useRef(null),E=l.useRef(null),T=l.useRef(e);if(l.useEffect(()=>{T.current=e},[e]),typeof document<"u"&&!h.current&&(h.current=Ll()),l.useEffect(()=>{if(!n){j(!1);return}const w=window.setTimeout(()=>j(!0),cs);return()=>window.clearTimeout(w)},[n]),l.useEffect(()=>{if(!n){I(!1);return}const w=window.setTimeout(()=>I(!0),cs+Ut+80);return()=>window.clearTimeout(w)},[n]),l.useEffect(()=>{if(!n)return;const w=document.body.style.overflow;E.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const R=()=>{const M=S.current;if(!M)return;(M.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??M).focus({preventScroll:!0})},y=window.setTimeout(R,cs),A=M=>{if(M.key==="Escape"&&!i){T.current();return}if(M.key!=="Tab")return;const C=S.current;if(!C)return;const N=Array.from(C.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(_=>!_.hasAttribute("disabled")&&_.getAttribute("aria-hidden")!=="true");if(N.length===0){M.preventDefault(),C.focus({preventScroll:!0});return}const q=N[0],$=N[N.length-1],v=document.activeElement;M.shiftKey&&v===q?(M.preventDefault(),$.focus({preventScroll:!0})):!M.shiftKey&&v===$&&(M.preventDefault(),q.focus({preventScroll:!0}))};return document.addEventListener("keydown",A),()=>{window.clearTimeout(y),document.body.style.overflow=w,document.removeEventListener("keydown",A),E.current?.focus?.({preventScroll:!0}),E.current=null}},[i,n]),!n||!h.current)return null;const k=f==="dialog",P=t.jsxs("section",{ref:S,role:"dialog","aria-modal":"true","aria-label":u,tabIndex:-1,className:X("flex flex-col bg-background text-foreground",k?"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 fixed inset-0 z-50"),style:k?{opacity:x?1:0,transform:x?"none":"scale(0.97)",transition:`opacity ${Ut}ms ease-out, transform ${Ut}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:x?"none":"translateX(100%)",transition:`transform ${Ut}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:w=>{x&&w.target===w.currentTarget&&w.propertyName==="transform"&&I(!0)},children:[a?null:t.jsxs("header",{className:X("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-primary","aria-label":g("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(ee,{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,o?typeof o=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:o}):o: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:b?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 k?mt.createPortal(t.jsx("div",{className:"oc-keyboard-inset-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:x?1:0,paddingLeft:d==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:d==="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:w=>w.stopPropagation(),children:P})}),h.current):mt.createPortal(P,h.current)},Bl=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),$l=n=>{const e=ue.c(36),{worktree:s,onDelete:o}=n,{t:r}=me();let i;e[0]!==s.path?(i={id:s.path},e[0]=s.path,e[1]=i):i=e[1];const{attributes:a,listeners:c,setNodeRef:u,transform:f,transition:d,isDragging:p}=$s(i);let g;e[2]!==f?(g=Fs.Transform.toString(f),e[2]=f,e[3]=g):g=e[3];const h=p?10:1;let x;e[4]!==g||e[5]!==h||e[6]!==d?(x={transform:g,transition:d,zIndex:h},e[4]=g,e[5]=h,e[6]=d,e[7]=x):x=e[7];const j=x,b=s.branch||s.label||s.path,I=p&&"shadow-lg shadow-black/20";let S;e[8]!==I?(S=X("flex items-center gap-1 rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",I),e[8]=I,e[9]=S):S=e[9];let E;e[10]!==b||e[11]!==r?(E=r("mobile.projectEdit.dragWorktreeAria",{label:b}),e[10]=b,e[11]=r,e[12]=E):E=e[12];let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Ts,{className:"size-4"}),e[13]=T):T=e[13];let k;e[14]!==a||e[15]!==c||e[16]!==E?(k=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":E,...a,...c,children:T}),e[14]=a,e[15]=c,e[16]=E,e[17]=k):k=e[17];let P;e[18]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(ee,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=P):P=e[18];let w;e[19]!==b?(w=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:b}),e[19]=b,e[20]=w):w=e[20];let R;e[21]!==b||e[22]!==r?(R=r("mobile.projectEdit.deleteWorktreeAria",{label:b}),e[21]=b,e[22]=r,e[23]=R):R=e[23];let y,A;e[24]===Symbol.for("react.memo_cache_sentinel")?(y={touchAction:"manipulation"},A=t.jsx(qt,{className:"size-4"}),e[24]=y,e[25]=A):(y=e[24],A=e[25]);let M;e[26]!==o||e[27]!==R?(M=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":R,onClick:o,style:y,children:A}),e[26]=o,e[27]=R,e[28]=M):M=e[28];let C;return e[29]!==u||e[30]!==j||e[31]!==w||e[32]!==M||e[33]!==S||e[34]!==k?(C=t.jsxs("div",{ref:u,style:j,className:S,children:[k,P,w,M]}),e[29]=u,e[30]=j,e[31]=w,e[32]=M,e[33]=S,e[34]=k,e[35]=C):C=e[35],C},Fl=({open:n,project:e,onClose:s,onWorktreesChanged:o})=>{const{t:r}=me(),{currentTheme:i}=ir(),a=ze(v=>v.updateProjectMeta),c=ze(v=>v.discoverProjectIcon),u=ze(v=>v.removeProjectIcon),f=xs(v=>v.setWorktreeOrder),d=ze(v=>e?v.projects.find(_=>_.id===e.id)?.iconImage??null:null),[p,g]=l.useState(""),[h,x]=l.useState(null),[j,b]=l.useState(null),[I,S]=l.useState(!1),[E,T]=l.useState([]),[k,P]=l.useState(null),w=e?.id??null;l.useEffect(()=>{!n||!e||(g(e.label),x(e.icon??null),b(e.color??null),T(e.worktrees))},[n,w]),l.useEffect(()=>{!n||!e||T(v=>{const _=e.worktrees.map(L=>L.path),O=v.map(L=>L.path);return _.length===O.length&&_.every(L=>O.includes(L))?v:e.worktrees})},[e?.worktrees]);const R=Is(ht(Ds,{activationConstraint:{distance:8}}),ht(_s,{coordinateGetter:Os})),y=()=>{if(!e)return;const v=p.trim();a(e.id,{label:v||e.label,icon:h,color:j}),s()},A=()=>{!e||I||(S(!0),c(e.id).then(v=>{if(!v.ok){ce.error(v.error||r("projectEditDialog.toast.failedToDiscoverIcon"));return}if(v.skipped){ce.success(r("projectEditDialog.toast.customIconAlreadySet"));return}ce.success(r("projectEditDialog.toast.iconDiscovered"))}).finally(()=>S(!1)))},M=()=>{e&&u(e.id).then(v=>{if(!v.ok){ce.error(v.error||r("projectEditDialog.toast.failedToRemoveIcon"));return}ce.success(r("projectEditDialog.toast.iconRemoved"))})},C=v=>{const{active:_,over:O}=v;if(!O||_.id===O.id||!e)return;const z=E.findIndex(D=>D.path===_.id),L=E.findIndex(D=>D.path===O.id);if(z<0||L<0)return;const te=[...E],[Q]=te.splice(z,1);te.splice(L,0,Q),T(te),f(e.id,te.map(D=>Bl(D.path)))},N=j?ar[j]??null:null,q=h?lr[h]:null,$=!!d;return t.jsxs(t.Fragment,{children:[t.jsx(It,{open:n,onClose:s,title:r("projectEditDialog.title"),ariaLabel:r("projectEditDialog.title"),noHeaderBorder:!0,trailing:t.jsxs(ye,{type:"button",variant:"default",size:"sm","aria-label":r("projectEditDialog.actions.save"),onClick:y,disabled:!p.trim(),style:{touchAction:"manipulation"},children:[t.jsx(hr,{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(cr,{project:{id:e.id,iconImage:d},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(ps,{className:"size-7"})}):q?t.jsx(ee,{name:q,className:"size-7",style:N?{color:N}:void 0}):t.jsx(ps,{className:"size-7",style:N?{color:N}: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(Cs,{value:p,onChange:v=>g(v.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:()=>b(null),"aria-label":r("projectEditDialog.option.none"),className:X("flex size-9 items-center justify-center rounded-xl border-2 transition-all",j===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"})}),Fo.map(v=>t.jsx("button",{type:"button",onClick:()=>b(v.key),"aria-label":v.label,title:v.label,className:X("size-9 rounded-xl border-2 transition-all",j===v.key?"border-foreground":"border-transparent hover:border-border/70"),style:{backgroundColor:v.cssVar,touchAction:"manipulation"}},v.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:()=>x(null),"aria-label":r("projectEditDialog.option.none"),className:X("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"})}),Wo.map(v=>t.jsx("button",{type:"button",onClick:()=>x(v.key),"aria-label":v.label,title:v.label,className:X("flex size-9 items-center justify-center rounded-xl border-2 transition-all",h===v.key?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx(ee,{name:v.Icon,className:"size-4",style:N?{color:N}:void 0})},v.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(ye,{size:"sm",variant:"outline",onClick:A,disabled:I,children:r(I?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),$?t.jsx(ye,{size:"sm",variant:"outline",onClick:M,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")}),E.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(Ms,{sensors:R,collisionDetection:zs,onDragEnd:C,children:t.jsx(Ls,{items:E.map(v=>v.path),strategy:Bs,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:E.map(v=>t.jsx($l,{worktree:v,onDelete:()=>P(v)},v.path))})})})]})]}):null]}):null}),e?t.jsx($r,{open:!!k,project:{id:e.id,path:e.path},worktree:k,onClose:()=>P(null),onDeleted:()=>{T(v=>v.filter(_=>_.path!==k?.path)),o?.()}}):null]})},Wl=new Set,us=7,Vt=40,Ul=16,ot=n=>n.parentID??null,at=n=>{const e=n;return Se(e.directory??e.project?.worktree??null)},Vl=n=>{const e=n.time?.updated??n.time?.created,s=typeof e=="number"?e:Number(e);return Number.isFinite(s)&&s>0?s:0},Gl=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 o=Math.floor(s/60);if(o<24)return`${o}h`;const r=Math.floor(o/24);return r<7?`${r}d`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(n))},Kl=(n,e)=>{const s=Se(n),o=Se(e);return!!(s&&o&&(s===o||s.startsWith(`${o}/`)))},Ht=(n,e)=>n.worktrees.find(s=>Se(s.path)===e)??null,ys=(n,e)=>e===n.path||!!Ht(n,e),ds=(n,e)=>{const s=Se(e);return s?n.find(o=>ys(o,s))??null:null},fs=(n,e,s)=>ur([n.title,n.id,at(n),e],s),vs=n=>{const e=ue.c(17),{project:s,size:o}=n,r=o===void 0?"md":o,{currentTheme:i}=ir(),a=s.icon?lr[s.icon]:null,c=s.color?ar[s.color]??null:null,u=r==="sm"?"size-6 rounded-md":"size-8 rounded-lg",f=r==="sm"?"size-3.5":"size-4";let d;e[0]!==a||e[1]!==c||e[2]!==f?(d=a?t.jsx(ee,{name:a,className:f,style:c?{color:c}:void 0}):t.jsx(ps,{className:f,style:c?{color:c}:void 0}),e[0]=a,e[1]=c,e[2]=f,e[3]=d):d=e[3];const p=d;let g;e[4]!==u?(g=X("flex shrink-0 items-center justify-center overflow-hidden bg-[var(--surface-muted)] text-muted-foreground",u),e[4]=u,e[5]=g):g=e[5];let h;e[6]!==s.iconBackground?(h=s.iconBackground?{backgroundColor:s.iconBackground}:void 0,e[6]=s.iconBackground,e[7]=h):h=e[7];let x;e[8]!==i||e[9]!==p||e[10]!==s.iconImage||e[11]!==s.id?(x=s.iconImage?t.jsx(cr,{project:{id:s.id,iconImage:s.iconImage??null},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:p}):p,e[8]=i,e[9]=p,e[10]=s.iconImage,e[11]=s.id,e[12]=x):x=e[12];let j;return e[13]!==g||e[14]!==h||e[15]!==x?(j=t.jsx("span",{className:g,style:h,children:x}),e[13]=g,e[14]=h,e[15]=x,e[16]=j):j=e[16],j},zn=n=>{const e=ue.c(2),{ariaLabel:s}=n;let o;return e[0]!==s?(o=t.jsx("span",{className:"inline-block size-1.5 shrink-0 rounded-full bg-primary","aria-label":s}),e[0]=s,e[1]=o):o=e[1],o},On=n=>{const e=ue.c(12),{onClick:s,className:o}=n,{t:r}=me();let i;e[0]!==r?(i=r("sessions.sidebar.project.actions.newWorktree"),e[0]=r,e[1]=i):i=e[1];const a=i;let c;e[2]!==o?(c=X("flex size-9 shrink-0 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] 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)]",o),e[2]=o,e[3]=c):c=e[3];let u;e[4]!==s?(u=g=>{g.stopPropagation(),s()},e[4]=s,e[5]=u):u=e[5];let f,d;e[6]===Symbol.for("react.memo_cache_sentinel")?(f={touchAction:"manipulation"},d=t.jsx(ee,{name:"node-tree",className:"size-4"}),e[6]=f,e[7]=d):(f=e[6],d=e[7]);let p;return e[8]!==a||e[9]!==c||e[10]!==u?(p=t.jsx("button",{type:"button",className:c,"aria-label":a,title:a,onClick:u,style:f,children:d}),e[8]=a,e[9]=c,e[10]=u,e[11]=p):p=e[11],p},it=144,Fr=180,Ln=n=>{const e=ue.c(25),{actionsWidth:s,actions:o,revealed:r,onRevealedChange:i,children:a}=n,c=l.useRef(null),u=l.useRef(null),f=l.useRef(!1),d=l.useRef(0),p=l.useRef(r);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=(C,N)=>{const q=c.current;q&&(q.style.transition=N?`transform ${Fr}ms ease-out`:"none",q.style.transform=C===0?"none":`translateX(${C}px)`,d.current=C)},e[0]=g):g=e[0];const h=g;let x,j;e[1]!==s||e[2]!==r?(x=()=>{p.current=r,h(r?-s:0,!0)},j=[s,h,r],e[1]=s,e[2]=r,e[3]=x,e[4]=j):(x=e[3],j=e[4]),l.useEffect(x,j);let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=C=>{if(C.touches.length!==1)return;const N=C.touches[0];u.current={x:N.clientX,y:N.clientY},f.current=!1},e[5]=b):b=e[5];const I=b;let S;e[6]!==s?(S=C=>{if(!u.current)return;const N=C.touches[0],q=N.clientX-u.current.x,$=N.clientY-u.current.y;if(!f.current){if(Math.abs(q)<8||Math.abs(q)<=Math.abs($))return;f.current=!0}const v=p.current?-s:0;h(Math.min(0,Math.max(-s,v+q)),!1)},e[6]=s,e[7]=S):S=e[7];const E=S;let T;e[8]!==s||e[9]!==i?(T=()=>{if(u.current=null,!f.current)return;f.current=!1;const C=d.current<-s/2;h(C?-s:0,!0),C!==p.current&&i(C)},e[8]=s,e[9]=i,e[10]=T):T=e[10];const k=T;let P;e[11]===Symbol.for("react.memo_cache_sentinel")?(P={touchAction:"pan-y"},e[11]=P):P=e[11];let w;e[12]!==s?(w={width:s},e[12]=s,e[13]=w):w=e[13];const R=!r;let y;e[14]!==o||e[15]!==w||e[16]!==R?(y=t.jsx("div",{className:"absolute inset-y-0 right-0 flex items-stretch",style:w,"aria-hidden":R,children:o}),e[14]=o,e[15]=w,e[16]=R,e[17]=y):y=e[17];let A;e[18]!==a?(A=t.jsx("div",{ref:c,className:"relative flex w-full items-center bg-background",children:a}),e[18]=a,e[19]=A):A=e[19];let M;return e[20]!==k||e[21]!==E||e[22]!==y||e[23]!==A?(M=t.jsxs("div",{className:"relative overflow-hidden",onTouchStart:I,onTouchMove:E,onTouchEnd:k,onTouchCancel:k,style:P,children:[y,A]}),e[20]=k,e[21]=E,e[22]=y,e[23]=A,e[24]=M):M=e[24],M},Hl=n=>{const e=ue.c(41),{initialTitle:s,indent:o,onSubmit:r,onCancel:i}=n,{t:a}=me(),[c,u]=l.useState(s);let f;e[0]!==s||e[1]!==i||e[2]!==r||e[3]!==c?(f=()=>{const C=c.trim();if(!C||C===s.trim()){i();return}r(C)},e[0]=s,e[1]=i,e[2]=r,e[3]=c,e[4]=f):f=e[4];const d=f;let p;e[5]!==o?(p={paddingLeft:o},e[5]=o,e[6]=p):p=e[6];let g;e[7]!==d?(g=C=>{C.preventDefault(),d()},e[7]=d,e[8]=g):g=e[8];let h;e[9]===Symbol.for("react.memo_cache_sentinel")?(h=C=>u(C.target.value),e[9]=h):h=e[9];let x;e[10]!==i?(x=C=>{C.stopPropagation(),C.key==="Escape"&&i()},e[10]=i,e[11]=x):x=e[11];let j;e[12]!==a?(j=a("sessions.sidebar.session.rename.save"),e[12]=a,e[13]=j):j=e[13];let b;e[14]!==a?(b=a("sessions.sidebar.session.menu.rename"),e[14]=a,e[15]=b):b=e[15];let I;e[16]===Symbol.for("react.memo_cache_sentinel")?(I={minHeight:0},e[16]=I):I=e[16];let S;e[17]!==x||e[18]!==j||e[19]!==b||e[20]!==c?(S=t.jsx("input",{autoFocus:!0,value:c,onChange:h,onKeyDown:x,"aria-label":j,placeholder:b,className:"min-w-0 flex-1 bg-transparent text-[16px] typography-ui-label text-foreground outline-none placeholder:text-muted-foreground",style:I,enterKeyHint:"done"}),e[17]=x,e[18]=j,e[19]=b,e[20]=c,e[21]=S):S=e[21];let E;e[22]!==a?(E=a("sessions.sidebar.session.rename.save"),e[22]=a,e[23]=E):E=e[23];let T,k;e[24]===Symbol.for("react.memo_cache_sentinel")?(T={touchAction:"manipulation",minHeight:0,minWidth:0},k=t.jsx(ee,{name:"check",className:"size-4"}),e[24]=T,e[25]=k):(T=e[24],k=e[25]);let P;e[26]!==E?(P=t.jsx("button",{type:"submit","aria-label":E,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-primary",style:T,children:k}),e[26]=E,e[27]=P):P=e[27];let w;e[28]!==a?(w=a("sessions.sidebar.session.rename.cancel"),e[28]=a,e[29]=w):w=e[29];let R,y;e[30]===Symbol.for("react.memo_cache_sentinel")?(R={touchAction:"manipulation",minHeight:0,minWidth:0},y=t.jsx(ee,{name:"close",className:"size-4"}),e[30]=R,e[31]=y):(R=e[30],y=e[31]);let A;e[32]!==i||e[33]!==w?(A=t.jsx("button",{type:"button",onClick:i,"aria-label":w,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-primary",style:R,children:y}),e[32]=i,e[33]=w,e[34]=A):A=e[34];let M;return e[35]!==P||e[36]!==A||e[37]!==p||e[38]!==g||e[39]!==S?(M=t.jsxs("form",{className:"flex h-9 min-w-0 flex-1 items-center gap-2 pr-2",style:p,onSubmit:g,children:[S,P,A]}),e[35]=P,e[36]=A,e[37]=p,e[38]=g,e[39]=S,e[40]=M):M=e[40],M},Bn=n=>{const e=ue.c(51),{session:s,active:o,indent:r,contextLabel:i,hasChildren:a,expanded:c,onToggleChildren:u,onSelect:f,revealed:d,onRevealedChange:p,confirmingDelete:g,onArchive:h,onRequestDelete:x,onConfirmDelete:j,renaming:b,onRequestRename:I,onSubmitRename:S,onCancelRename:E}=n,T=a===void 0?!1:a,k=c===void 0?!1:c,P=d===void 0?!1:d,w=g===void 0?!1:g,R=b===void 0?!1:b,{t:y}=me();let A;e[0]!==s?(A=Gl(Vl(s)),e[0]=s,e[1]=A):A=e[1];const M=A,C=s.title?.trim()||y("mobile.sessions.untitled"),N=!!(p&&h),q=sr(s.id),$=nr(s.id),v=q?.type??"idle",_=v==="busy"||v==="retry",O=!_&&$>0&&!o,z=rr(s.id,_),L=(_||O)&&z,te=l.useRef(null),Q=l.useRef(null),D=l.useRef(!1),J=l.useRef(0),K=l.useRef(P);let H;e[2]===Symbol.for("react.memo_cache_sentinel")?(H=(le,Ce)=>{const xe=te.current;xe&&(xe.style.transition=Ce?`transform ${Fr}ms ease-out`:"none",xe.style.transform=le===0?"none":`translateX(${le}px)`,J.current=le)},e[2]=H):H=e[2];const W=H;let Z,se;e[3]!==P?(Z=()=>{K.current=P,W(P?-it:0,!0)},se=[W,P],e[3]=P,e[4]=Z,e[5]=se):(Z=e[4],se=e[5]),l.useEffect(Z,se);let ae;e[6]!==N?(ae=le=>{if(!N||le.touches.length!==1)return;const Ce=le.touches[0];Q.current={x:Ce.clientX,y:Ce.clientY},D.current=!1},e[6]=N,e[7]=ae):ae=e[7];const he=ae;let oe;e[8]!==N?(oe=le=>{if(!N||!Q.current)return;const Ce=le.touches[0],xe=Ce.clientX-Q.current.x,Fe=Ce.clientY-Q.current.y;if(!D.current){if(Math.abs(xe)<8||Math.abs(xe)<=Math.abs(Fe))return;D.current=!0}const wt=K.current?-it:0,We=Math.min(0,Math.max(-it,wt+xe));W(We,!1)},e[8]=N,e[9]=oe):oe=e[9];const U=oe;let ie;e[10]!==p?(ie=()=>{if(Q.current=null,!D.current)return;D.current=!1;const le=J.current<-it/2;W(le?-it:0,!0),le!==K.current&&p?.(le)},e[10]=p,e[11]=ie):ie=e[11];const V=ie,de=o||void 0,Ne="relative overflow-hidden";let ke;e[12]!==N?(ke=N?{touchAction:"pan-y"}:void 0,e[12]=N,e[13]=ke):ke=e[13];const Pe=N?t.jsxs("div",{className:"absolute inset-y-0 right-0 flex items-stretch",style:{width:it},"aria-hidden":!P,children:[t.jsx("button",{type:"button",tabIndex:P?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-primary","aria-label":y("mobile.sessions.renameSessionAria",{title:C}),onClick:I,style:{touchAction:"manipulation"},children:t.jsx(hs,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:P?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-primary","aria-label":y("mobile.sessions.archiveSessionAria",{title:C}),onClick:h,style:{touchAction:"manipulation"},children:t.jsx(fa,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:P?0:-1,className:X("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",w?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":w?y("mobile.sessions.confirmDeleteSessionAria",{title:C}):y("mobile.sessions.deleteSessionAria",{title:C}),onClick:w?j:x,style:{touchAction:"manipulation"},children:t.jsx(qt,{className:"size-[18px]"})})]}):null,Le=N&&"bg-background",Te=o&&(N?"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]":"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]");let Ie;e[14]!==Le||e[15]!==Te?(Ie=X("relative flex items-center gap-1 transition-colors",Le,Te),e[14]=Le,e[15]=Te,e[16]=Ie):Ie=e[16];let we;e[17]!==k||e[18]!==T||e[19]!==r||e[20]!==_||e[21]!==u||e[22]!==O||e[23]!==y?(we=_||O||T&&u?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-primary",style:{left:Math.max(r-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":y(k?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),disabled:!T||!u,onClick:le=>{le.stopPropagation(),u?.()},children:_||O?t.jsx("span",{className:X("size-1.5 rounded-full",_?"bg-primary":"bg-[var(--status-info)]"),"aria-hidden":!0}):t.jsx(As,{className:X("size-[18px] transition-transform duration-150",k?"rotate-0":"-rotate-90")})}):null,e[17]=k,e[18]=T,e[19]=r,e[20]=_,e[21]=u,e[22]=O,e[23]=y,e[24]=we):we=e[24];let B;e[25]!==o||e[26]!==i||e[27]!==r||e[28]!==_||e[29]!==E||e[30]!==p||e[31]!==f||e[32]!==S||e[33]!==R||e[34]!==s.id||e[35]!==L||e[36]!==M||e[37]!==C?(B=R&&S&&E?t.jsx(Hl,{initialTitle:C,indent:r,onSubmit:S,onCancel:E}):t.jsx("button",{type:"button",className:X("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-primary focus-visible:ring-inset",i?"min-h-10 py-1":"h-9"),style:{paddingLeft:r,touchAction:"manipulation"},onClick:()=>{if(K.current){p?.(!1);return}f()},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:X("block min-w-0 flex-1 truncate typography-ui-label",o?"text-primary":"text-foreground"),children:C}),L?t.jsx(pr,{sessionId:s.id,running:_,className:"typography-micro"}):M?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:M}):null]}),i?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:i}):null]})}),e[25]=o,e[26]=i,e[27]=r,e[28]=_,e[29]=E,e[30]=p,e[31]=f,e[32]=S,e[33]=R,e[34]=s.id,e[35]=L,e[36]=M,e[37]=C,e[38]=B):B=e[38];let G;e[39]!==Ie||e[40]!==we||e[41]!==B?(G=t.jsxs("div",{ref:te,className:Ie,children:[we,B]}),e[39]=Ie,e[40]=we,e[41]=B,e[42]=G):G=e[42];let re;return e[43]!==V||e[44]!==U||e[45]!==he||e[46]!==de||e[47]!==ke||e[48]!==Pe||e[49]!==G?(re=t.jsxs("div",{"data-active-session":de,className:Ne,onTouchStart:he,onTouchMove:U,onTouchEnd:V,onTouchCancel:V,style:ke,children:[Pe,G]}),e[43]=V,e[44]=U,e[45]=he,e[46]=de,e[47]=ke,e[48]=Pe,e[49]=G,e[50]=re):re=e[50],re},ql=n=>{const e=ue.c(11),{indent:s,onClick:o}=n,{t:r}=me();let i;e[0]!==s?(i={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=i):i=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(As,{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 u;e[5]!==c?(u=t.jsx("span",{className:"typography-micro",children:c}),e[5]=c,e[6]=u):u=e[6];let f;return e[7]!==o||e[8]!==i||e[9]!==u?(f=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-primary focus-visible:ring-inset",style:i,onClick:o,children:[a,u]}),e[7]=o,e[8]=i,e[9]=u,e[10]=f):f=e[10],f},Yl=n=>{const e=ue.c(11),{indent:s,onClick:o}=n,{t:r}=me();let i;e[0]!==s?(i={paddingLeft:s,touchAction:"manipulation"},e[0]=s,e[1]=i):i=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(ma,{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 u;e[5]!==c?(u=t.jsx("span",{className:"typography-micro",children:c}),e[5]=c,e[6]=u):u=e[6];let f;return e[7]!==o||e[8]!==i||e[9]!==u?(f=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-primary focus-visible:ring-inset",style:i,onClick:o,children:[a,u]}),e[7]=o,e[8]=i,e[9]=u,e[10]=f):f=e[10],f},Jl=n=>{const e=ue.c(29),{worktree:s}=n,{t:o}=me();let r;e[0]!==s.path?(r=Se(s.path),e[0]=s.path,e[1]=r):r=e[1];const i=r;let a;e[2]!==i?(a={id:i},e[2]=i,e[3]=a):a=e[3];const{attributes:c,listeners:u,setNodeRef:f,transform:d,transition:p,isDragging:g}=$s(a),h=s.branch||s.label||s.path;let x;e[4]!==d?(x=Fs.Transform.toString(d),e[4]=d,e[5]=x):x=e[5];const j=g?10:1;let b;e[6]!==x||e[7]!==j||e[8]!==p?(b={transform:x,transition:p,zIndex:j},e[6]=x,e[7]=j,e[8]=p,e[9]=b):b=e[9];const I=g&&"shadow-lg shadow-black/20";let S;e[10]!==I?(S=X("flex items-center gap-1 rounded-xl bg-background px-1 py-1",I),e[10]=I,e[11]=S):S=e[11];let E;e[12]!==h||e[13]!==o?(E=o("mobile.sessions.dragHandleAria",{label:h}),e[12]=h,e[13]=o,e[14]=E):E=e[14];let T;e[15]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(Ts,{className:"size-4"}),e[15]=T):T=e[15];let k;e[16]!==c||e[17]!==u||e[18]!==E?(k=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":E,...c,...u,children:T}),e[16]=c,e[17]=u,e[18]=E,e[19]=k):k=e[19];let P;e[20]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(ee,{name:"git-branch",className:"size-4 shrink-0 text-muted-foreground"}),e[20]=P):P=e[20];let w;e[21]!==h?(w=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]=w):w=e[22];let R;return e[23]!==f||e[24]!==k||e[25]!==w||e[26]!==b||e[27]!==S?(R=t.jsxs("div",{ref:f,style:b,className:S,children:[k,P,w]}),e[23]=f,e[24]=k,e[25]=w,e[26]=b,e[27]=S,e[28]=R):R=e[28],R},Xl=n=>{const e=ue.c(61),{project:s,totalSessions:o,expanded:r,onToggleExpanded:i,onReorderWorktrees:a}=n,{t:c}=me();let u;e[0]!==s.id?(u={id:s.id},e[0]=s.id,e[1]=u):u=e[1];const{attributes:f,listeners:d,setNodeRef:p,transform:g,transition:h,isDragging:x}=$s(u);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j={activationConstraint:{distance:8}},e[2]=j):j=e[2];let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b={coordinateGetter:Os},e[3]=b):b=e[3];const I=Is(ht(Ds,j),ht(_s,b)),S=s.worktrees.length>0;let E;e[4]!==a||e[5]!==s.worktrees?(E=J=>{const{active:K,over:H}=J;if(!H||K.id===H.id)return;const W=s.worktrees.map(tc),Z=W.indexOf(String(K.id)),se=W.indexOf(String(H.id));if(Z<0||se<0)return;const ae=[...W],[he]=ae.splice(Z,1);ae.splice(se,0,he),a(ae)},e[4]=a,e[5]=s.worktrees,e[6]=E):E=e[6];const T=E;let k;e[7]!==g?(k=Fs.Transform.toString(g),e[7]=g,e[8]=k):k=e[8];const P=x?10:1;let w;e[9]!==k||e[10]!==P||e[11]!==h?(w={transform:k,transition:h,zIndex:P},e[9]=k,e[10]=P,e[11]=h,e[12]=w):w=e[12];const R=x&&"shadow-lg shadow-black/20";let y;e[13]!==R?(y=X("rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",R),e[13]=R,e[14]=y):y=e[14];let A;e[15]!==s.label||e[16]!==c?(A=c("mobile.sessions.dragHandleAria",{label:s.label}),e[15]=s.label,e[16]=c,e[17]=A):A=e[17];let M;e[18]===Symbol.for("react.memo_cache_sentinel")?(M=t.jsx(Ts,{className:"size-4"}),e[18]=M):M=e[18];let C;e[19]!==f||e[20]!==d||e[21]!==A?(C=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":A,...f,...d,children:M}),e[19]=f,e[20]=d,e[21]=A,e[22]=C):C=e[22];let N;e[23]!==r||e[24]!==s.label||e[25]!==c?(N=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]=N):N=e[26];const q=!S;let $;e[27]===Symbol.for("react.memo_cache_sentinel")?($={touchAction:"manipulation"},e[27]=$):$=e[27];let v;e[28]!==s?(v=t.jsx(vs,{project:s}),e[28]=s,e[29]=v):v=e[29];let _;e[30]!==s.label?(_=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]=_):_=e[31];let O;e[32]!==o?(O=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:o}),e[32]=o,e[33]=O):O=e[33];let z;e[34]!==r||e[35]!==S?(z=S?t.jsx(As,{className:X("size-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-180")}):null,e[34]=r,e[35]=S,e[36]=z):z=e[36];let L;e[37]!==r||e[38]!==i||e[39]!==N||e[40]!==q||e[41]!==v||e[42]!==_||e[43]!==O||e[44]!==z?(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-primary",onClick:i,"aria-expanded":r,"aria-label":N,disabled:q,style:$,children:[v,_,O,z]}),e[37]=r,e[38]=i,e[39]=N,e[40]=q,e[41]=v,e[42]=_,e[43]=O,e[44]=z,e[45]=L):L=e[45];let te;e[46]!==C||e[47]!==L?(te=t.jsxs("div",{className:"flex items-center gap-1",children:[C,L]}),e[46]=C,e[47]=L,e[48]=te):te=e[48];let Q;e[49]!==r||e[50]!==T||e[51]!==S||e[52]!==s.worktrees||e[53]!==I?(Q=r&&S?t.jsx(Ms,{sensors:I,collisionDetection:zs,onDragEnd:T,children:t.jsx(Ls,{items:s.worktrees.map(sc),strategy:Bs,children:t.jsx("div",{className:"mt-1 flex flex-col gap-0.5 pl-3",children:s.worktrees.map(nc)})})}):null,e[49]=r,e[50]=T,e[51]=S,e[52]=s.worktrees,e[53]=I,e[54]=Q):Q=e[54];let D;return e[55]!==p||e[56]!==te||e[57]!==Q||e[58]!==w||e[59]!==y?(D=t.jsxs("div",{ref:p,style:w,className:y,children:[te,Q]}),e[55]=p,e[56]=te,e[57]=Q,e[58]=w,e[59]=y,e[60]=D):D=e[60],D},$n=({open:n,onOpenChange:e,variant:s="drawer",footer:o})=>{const{t:r}=me(),{git:i}=Es(),a=or(),c=js(m=>m.activeSessions),u=er(l.useCallback(m=>n||s==="sidebar"?m.ids:Wl,[n,s])),f=tr(l.useCallback(m=>n||s==="sidebar"?m.rankById:Uo,[n,s])),d=ze(m=>m.projects),p=ze(m=>m.activeProjectId),g=Qe(m=>m.currentDirectory),h=je(m=>m.currentSessionId),x=je(m=>m.setCurrentSession),j=je(m=>m.archiveSession),b=je(m=>m.deleteSession),I=je(m=>m.updateSessionTitle),S=je(m=>m.openNewSessionDraft),E=ze(m=>m.setActiveProject),T=ze(m=>m.setActiveProjectIdOnly),k=ze(m=>m.reorderProjects),P=ze(m=>m.removeProject),w=Wt(m=>m.projectExpanded),R=Wt(m=>m.worktreeExpanded),y=Wt(m=>m.setProjectExpanded),A=Wt(m=>m.setWorktreeExpanded),M=xs(m=>m.orderByProject),C=xs(m=>m.setWorktreeOrder),N=_n(m=>m.expandedParents),q=_n(m=>m.toggleParent),[$,v]=l.useState(""),[_,O]=l.useState(null),[z,L]=l.useState(null),[te,Q]=l.useState(null),[D,J]=l.useState(null),[K,H]=l.useState(null),[W,Z]=l.useState(null),[se,ae]=l.useState(null),[he,oe]=l.useState(0),[U,ie]=l.useState(!1),[V,de]=l.useState(!1),[Ne,ke]=l.useState(null),[Pe,Le]=l.useState(()=>new Map(je.getState().availableWorktreesByProject)),[Te,Ie]=l.useState(()=>{const m=new Set;for(const[F,Y]of je.getState().availableWorktreesByProject)Y.length>0&&m.add(F);return m}),[we,B]=l.useState(!1),[G,re]=l.useState(new Set),[le,Ce]=l.useState(new Map);l.useEffect(()=>{if(!n){v(""),B(!1),re(new Set),Ce(new Map),O(null),L(null),Q(null),J(null),H(null),Z(null);return}Ns(a)},[n]),l.useEffect(()=>{we||re(new Set)},[we]),l.useEffect(()=>{if(!n||d.length===0)return;let m=!1;return(async()=>{const Y=await Promise.all(d.map(async pe=>{const fe=Se(pe.path);if(!fe)return null;const Ae=await i.checkIsGitRepository(fe).catch(()=>!1),Be=Ae?await dr({id:pe.id,path:fe}).catch(()=>[]):[];return[fe,Be,Ae]}));if(m)return;const ne=new Map,ge=new Set;for(const pe of Y)pe&&(ne.set(pe[0],pe[1]),pe[2]&&ge.add(pe[0]));Le(fr(d,ne)),Ie(ge)})(),()=>{m=!0}},[i,n,d,he]);const xe=l.useMemo(()=>d.map(m=>({id:m.id,label:m.label?.trim()||ls(m.path),path:Se(m.path),icon:m.icon,color:m.color,iconImage:m.iconImage,iconBackground:m.iconBackground,isGitRepo:Te.has(Se(m.path)),worktrees:zl(M[m.id],Pe.get(Se(m.path))??[])})),[Te,d,M,Pe]),Fe=l.useMemo(()=>{const m=new Map(a.map(ne=>[ne.id,ne])),F=c.map(ne=>{const ge=m.get(ne.id);return ge?Vo(ge,ne):ne}),Y=new Set(F.map(ne=>ne.id));for(const ne of a)Y.has(ne.id)||F.push(ne);return F.filter(ne=>!ne.time?.archived)},[c,a]),{projectSessions:wt,chatSessions:We}=l.useMemo(()=>Gi(Fe,!1),[Fe]),Xs=l.useMemo(()=>({key:Nt,label:"",path:"",worktree:null,sessions:os(We,u,f)}),[We,u,f]),Gr=`${Nt}::${Nt}`,Kr=l.useMemo(()=>We.filter(m=>!ot(m)).length,[We]),_e=$.trim().toLowerCase(),Qs=l.useRef(null);l.useEffect(()=>{if(!n)return;const m=window.requestAnimationFrame(()=>{const F=Qs.current;if(!F)return;(F.querySelector('[data-active-session="true"]')??F.querySelector('[data-active-project="true"]'))?.scrollIntoView({block:"center"})});return()=>window.cancelAnimationFrame(m)},[n]);const Lt=l.useMemo(()=>{const m=xe.map(Y=>({project:Y,buckets:[],totalSessions:0,isActive:Y.id===p})),F=(Y,ne,ge)=>{const pe=Se(ne)||Y.project.path,fe=pe||"__root__";let Ae=Y.buckets.find(Be=>Be.key===fe);return Ae||(Ae={key:fe,label:ge?.branch||ls(pe),path:pe,worktree:ge,sessions:[]},Y.buckets.push(Ae)),Ae};for(const Y of m){F(Y,Y.project.path,null);for(const ne of Y.project.worktrees)F(Y,ne.path,ne)}for(const Y of wt){const ne=at(Y);if(!ne)continue;const ge=Se(ne),pe=m.find(Be=>ys(Be.project,ge));if(!pe)continue;const fe=Ht(pe.project,ge);(fe?F(pe,fe.path,fe):F(pe,pe.project.path,null)).sessions.push(Y)}for(const Y of m)for(const ne of Y.buckets){ne.sessions=os(ne.sessions,u,f);for(const ge of ne.sessions)ot(ge)||(Y.totalSessions+=1)}return m},[p,u,wt,xe,f]),Zs=Se(g),Hr=m=>m.isActive?Zs===m.project.path?m.project.path:m.project.worktrees.find(Y=>Kl(Zs,Y.path))?.path??m.project.path:null,qr=m=>w[m.project.id]??!0,Yr=(m,F)=>R[`${m.project.id}::${F.key}`]??!0,en=m=>{Ce(F=>{if(!F.has(m))return F;const Y=new Map(F);return Y.delete(m),Y})},Jr=m=>{Ce(F=>{let Y=!1;const ne=new Map(F),ge=`${m}::`;for(const pe of ne.keys())pe.startsWith(ge)&&(ne.delete(pe),Y=!0);return Y?ne:F})},Xr=(m,F)=>{Ce(Y=>{const ne=new Map(Y);return ne.set(m,F+us),ne})},ss=(m,F,Y)=>{const ne=new Set(F.sessions.map(ve=>ve.id)),ge=new Map;for(const ve of F.sessions){const $e=ot(ve);if($e&&ne.has($e)){const kt=ge.get($e)??[];kt.push(ve),ge.set($e,kt)}}const pe=F.sessions.filter(ve=>{const $e=ot(ve);return!$e||!ne.has($e)}),fe=le.get(m)??us,Ae=pe.slice(0,fe),Be=pe.length-Ae.length,ns=pe.length>us&&Be===0,cn=(ve,$e)=>{const kt=ge.get(ve.id)??[],rs=kt.length>0,un=!!N[ve.id];return t.jsxs(l.Fragment,{children:[t.jsx(Bn,{session:ve,active:h===ve.id,indent:$e,hasChildren:rs,expanded:un,onToggleChildren:rs?()=>q(ve.id):void 0,onSelect:()=>sn(ve),revealed:z===ve.id,onRevealedChange:St=>Zr(ve.id,St),confirmingDelete:te===ve.id,onArchive:()=>{eo(ve)},onRequestDelete:()=>Q(ve.id),onConfirmDelete:()=>{to(ve)},renaming:D===ve.id,onRequestRename:()=>so(ve.id),onSubmitRename:St=>{no(ve.id,St)},onCancelRename:()=>J(null)}),rs&&un?kt.map(St=>cn(St,$e+Ul)):null]},ve.id)};return t.jsxs("div",{children:[Ae.map(ve=>cn(ve,Y)),Be>0?t.jsx(ql,{indent:Y,onClick:()=>Xr(m,Ae.length)}):null,ns?t.jsx(Yl,{indent:Y,onClick:()=>en(m)}):null]})},tn=(m,F)=>{y(m,!F),Jr(m)},Qr=(m,F,Y)=>{A(`${m}::${F}`,!Y),en(`${m}::${F}`)},sn=m=>{const F=at(m)||null,Y=ds(xe,F??"");if(Y){T(Y.id),y(Y.id,!0);const ne=Ht(Y,Se(F??""));ne&&A(`${Y.id}::${Se(ne.path)}`,!0)}x(m.id,F),e(!1)},Zr=(m,F)=>{L(F?m:null),Q(null),H(null),Z(null)},jt=(m,F)=>{H(F?m:null),Z(null),L(null),Q(null)},eo=async m=>{L(null),Q(null),await j(m.id)?ce.success(r("sessions.sidebar.session.archive.success")):ce.error(r("sessions.sidebar.session.archive.error"))},to=async m=>{L(null),Q(null),await b(m.id)?ce.success(r("sessions.sidebar.session.delete.success")):ce.error(r("sessions.sidebar.session.delete.error"))},so=m=>{L(null),Q(null),J(m)},no=async(m,F)=>{J(null);try{await I(m,F)}catch{ce.error(r("mobile.sessions.renameError"))}},ro=()=>{S(),e(!1)},nn=m=>{ke(m),T(m),de(!0)},oo=Is(ht(Ds,{activationConstraint:{distance:8}}),ht(_s,{coordinateGetter:Os})),io=m=>{const{active:F,over:Y}=m;if(!Y||F.id===Y.id)return;const ne=xe.findIndex(pe=>pe.id===F.id),ge=xe.findIndex(pe=>pe.id===Y.id);ne<0||ge<0||k(ne,ge)},ao=m=>{re(F=>{const Y=new Set(F);return Y.has(m)?Y.delete(m):Y.add(m),Y})},lo=l.useCallback(m=>{const F=at(m);if(Go(F))return r("mobile.sessions.section.chats");const Y=ds(xe,F);if(!Y)return ls(F)||F;const ne=Ht(Y,Se(F));return ne?.branch?`${Y.label} · ${ne.branch}`:Y.label},[xe,r]),co=m=>{E(m.id),e(!1)},uo=l.useMemo(()=>_e?Lt.filter(m=>ur([m.project.label,m.project.path],_e)?!0:m.buckets.some(F=>F.sessions.some(Y=>fs(Y,m.project.label,_e)))):Lt,[_e,Lt]),Bt=l.useMemo(()=>_e?os(Fe.filter(m=>{if(ot(m))return!1;const F=at(m),Y=ds(xe,F);return fs(m,Y?.label??"",_e)}),u,f):[],[_e,u,xe,f,Fe]),$t=l.useMemo(()=>_e?Ko(xe,_e,m=>[m.label,m.path]).map(m=>({...m,sessionCount:Fe.filter(F=>{if(ot(F))return!1;const Y=Se(at(F));return ys(m,Y)}).length})):[],[_e,xe,Fe]),fo=_e&&Bt.length===0&&$t.length===0,rn=!_e&&xe.length>1?t.jsx(ye,{type:"button",variant:"chip",size:"sm","aria-label":r(we?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":we,onClick:()=>B(m=>!m),style:{touchAction:"manipulation"},children:we?t.jsx(hr,{className:"size-4"}):t.jsx(hs,{className:"size-4"})}):null,on=!we&&xe.length>0?t.jsxs(ye,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:ro,style:{touchAction:"manipulation"},children:[t.jsx(da,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,an=we?null:t.jsx(ye,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>ie(!0),style:{touchAction:"manipulation"},children:t.jsx(bn,{className:"size-4"})}),Ft=on||an||rn?t.jsxs(t.Fragment,{children:[on,an,rn]}):null,ln=t.jsxs("div",{ref:Qs,className:"flex min-h-0 flex-1 flex-col",children:[t.jsxs(Rs,{className:"min-h-0 flex-1 overflow-y-auto pb-4",children:[t.jsx("div",{className:X("px-4 pb-2 pt-1",we&&"hidden"),children:t.jsxs("div",{className:"relative",children:[t.jsx(gr,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(Cs,{value:$,onChange:m=>v(m.target.value),placeholder:r("mobile.sessions.search.placeholder"),className:X("h-11 pl-9",$&&"pr-10")}),$?t.jsx("button",{type:"button",className:"absolute right-1.5 top-1/2 flex size-8 -translate-y-1/2 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-primary","aria-label":r("mobile.sessions.clearSearchAria"),onClick:()=>v(""),style:{touchAction:"manipulation"},children:t.jsx(br,{className:"size-4"})}):null]})}),xe.length===0&&We.length===0?t.jsx(Un,{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-primary",onClick:()=>ie(!0),children:[t.jsx(bn,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):fo?t.jsx(Un,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):_e&&!we?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[Bt.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:Bt.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Bt.map((m,F)=>t.jsx("div",{className:X(F>0&&"border-t border-border/70"),children:t.jsx(Bn,{session:m,active:h===m.id,indent:12,contextLabel:lo(m),onSelect:()=>sn(m)})},m.id))})]}):null,$t.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:$t.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:$t.map((m,F)=>t.jsxs("div",{className:X("flex items-center",F>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-primary focus-visible:ring-inset",onClick:()=>co(m),style:{touchAction:"manipulation"},children:[t.jsx(vs,{project:m}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:m.label}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:m.sessionCount})]}),m.isGitRepo?t.jsx(On,{className:"mr-2",onClick:()=>nn(m.id)}):null]},m.id))})]}):null]}):we?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(Ms,{sensors:oo,collisionDetection:zs,onDragEnd:io,children:t.jsx(Ls,{items:xe.map(m=>m.id),strategy:Bs,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:xe.map(m=>{const F=Lt.find(Y=>Y.project.id===m.id);return t.jsx(Xl,{project:m,totalSessions:F?.totalSessions??0,expanded:G.has(m.id),onToggleExpanded:()=>ao(m.id),onReorderWorktrees:Y=>C(m.id,Y)},m.id)})})})})]}):t.jsxs("div",{className:"flex flex-col",children:[(()=>{const m=w[Nt]??!0,F=r("mobile.sessions.section.chats");return t.jsxs("section",{children:[t.jsx("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-primary focus-visible:ring-inset",onClick:()=>{if(K){jt(K,!1);return}tn(Nt,m)},"aria-expanded":m,"aria-label":m?r("sessions.sidebar.group.collapseAria",{label:F}):r("sessions.sidebar.group.expandAria",{label:F}),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(ee,{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:F}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:Kr})]})}),m?t.jsx("div",{className:"pb-2",children:Xs.sessions.length>0?ss(Gr,Xs,Vt):t.jsx("p",{className:"px-3 pb-1 typography-micro text-muted-foreground",style:{paddingLeft:Vt},children:r("sessions.sidebar.activity.chatsEmpty")})}):null]})})(),uo.map(m=>{const F=qr(m),Y=_e?m.buckets.filter(ge=>ge.sessions.some(pe=>fs(pe,m.project.label,_e))):m.buckets,ne=Hr(m);return t.jsxs("section",{className:"border-t border-border/70",children:[t.jsx(Ln,{actionsWidth:96,revealed:K===`project:${m.project.id}`,onRevealedChange:ge=>jt(`project:${m.project.id}`,ge),actions:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",tabIndex:K===`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-primary","aria-label":r("mobile.sessions.editProjectAria",{label:m.project.label}),onClick:()=>{H(null),O(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(hs,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:K===`project:${m.project.id}`?0:-1,className:X("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",W===m.project.id?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":W===m.project.id?r("mobile.sessions.confirmRemoveProjectAria",{label:m.project.label}):r("mobile.sessions.removeProjectAria",{label:m.project.label}),onClick:()=>{if(W===m.project.id){H(null),Z(null),P(m.project.id),ce.success(r("mobile.sessions.toast.projectRemoved",{label:m.project.label}));return}Z(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(qt,{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-primary focus-visible:ring-inset",onClick:()=>{if(K){jt(K,!1);return}tn(m.project.id,F)},"aria-expanded":F,"aria-label":F?r("sessions.sidebar.group.collapseAria",{label:m.project.label}):r("sessions.sidebar.group.expandAria",{label:m.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(vs,{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.isActive?t.jsx(zn,{ariaLabel:r("mobile.sessions.activeProjectAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:m.totalSessions})]}),m.project.isGitRepo?t.jsx(On,{className:"mr-2",onClick:()=>nn(m.project.id)}):null]})}),F?t.jsx("div",{className:"pb-2",children:(()=>{const ge=Y.find(fe=>fe.worktree===null),pe=Y.filter(fe=>fe.worktree!==null);return t.jsxs(t.Fragment,{children:[ge&&ge.sessions.length>0?ss(`${m.project.id}::${ge.key}`,ge,Vt):null,pe.map(fe=>{const Ae=Yr(m,fe),Be=ne===fe.path;return t.jsxs("div",{children:[t.jsx(Ln,{actionsWidth:48,revealed:K===`wt:${fe.key}`,onRevealedChange:ns=>jt(`wt:${fe.key}`,ns),actions:t.jsx("button",{type:"button",tabIndex:K===`wt:${fe.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:fe.label}),onClick:()=>{H(null),fe.worktree&&ae({project:m.project,worktree:fe.worktree})},style:{touchAction:"manipulation"},children:t.jsx(qt,{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-primary focus-visible:ring-inset",onClick:()=>{if(K){jt(K,!1);return}Qr(m.project.id,fe.key,Ae)},"aria-expanded":Ae,"aria-label":Ae?r("sessions.sidebar.group.collapseAria",{label:fe.label}):r("sessions.sidebar.group.expandAria",{label:fe.label}),style:{touchAction:"manipulation"},children:[t.jsx(ee,{name:"git-branch",className:X("size-4 shrink-0",Be?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:X("block min-w-0 flex-1 truncate typography-ui-label font-bold",Be?"text-foreground":"text-muted-foreground"),children:fe.label}),Be?t.jsx(zn,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:fe.sessions.length})]})}),Ae?ss(`${m.project.id}::${fe.key}`,fe,Vt):null]},fe.key)})]})})()}):null]},m.project.id)})]})]}),o?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:[o.instanceLabel&&o.onOpenInstances?t.jsxs(ye,{type:"button",variant:"info",size:"lg",className:"min-w-0 shrink justify-start",onClick:o.onOpenInstances,"aria-label":r("mobile.menu.instances"),style:{touchAction:"manipulation"},children:[t.jsx(ee,{name:"server",className:"size-[18px]"}),t.jsx("span",{className:"block min-w-0 truncate",children:o.instanceLabel})]}):t.jsx("div",{className:"min-w-0 flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o.onOpenUpdate?t.jsxs(ye,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:o.onOpenUpdate,"aria-label":r("mobile.menu.update"),title:r("mobile.menu.update"),style:{touchAction:"manipulation"},children:[t.jsx(ee,{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(ye,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:o.onOpenSettings,"aria-label":r("mobile.menu.settings"),title:r("mobile.menu.settings"),style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"settings-3",className:"size-5"})})]})]}):null,t.jsx(Ki,{open:U,onOpenChange:ie}),t.jsx(Hi,{open:V,onOpenChange:m=>{de(m),m||ke(null)},onWorktreeCreated:(m,F)=>{F?.sessionId?x(F.sessionId,m):S({selectedProjectId:Ne,directoryOverride:m,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(Fl,{open:_!==null,project:xe.find(m=>m.id===_)??null,onClose:()=>O(null),onWorktreesChanged:()=>oe(m=>m+1)}),se?t.jsx($r,{open:!0,project:{id:se.project.id,path:se.project.path},worktree:se.worktree,onClose:()=>ae(null),onDeleted:()=>oe(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")}),Ft?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Ft}):null]}),ln]}):null:t.jsxs(ec,{open:n,onClose:()=>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-primary","aria-label":r("mobile.surface.closeAria"),onClick:()=>e(!1),style:{touchAction:"manipulation"},children:t.jsx(ee,{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")}),Ft?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Ft}):null]}),ln]})},Fn="mobile-surface-root",Ql=16,Wn=320,Zl="cubic-bezier(0.22, 1, 0.36, 1)",ec=({open:n,onClose:e,ariaLabel:s,children:o})=>{const r=l.useRef(null),[i,a]=l.useState(!1),[c,u]=l.useState(n),f=l.useRef(e);if(l.useEffect(()=>{f.current=e},[e]),typeof document<"u"&&!r.current){let d=document.getElementById(Fn);d||(d=document.createElement("div"),d.id=Fn,document.body.appendChild(d)),r.current=d}return l.useEffect(()=>{if(n){u(!0);const p=window.setTimeout(()=>a(!0),Ql);return()=>window.clearTimeout(p)}a(!1);const d=window.setTimeout(()=>u(!1),Wn+40);return()=>window.clearTimeout(d)},[n]),l.useEffect(()=>{if(!n)return;const d=document.body.style.overflow;document.body.style.overflow="hidden";const p=g=>{g.key==="Escape"&&f.current()};return document.addEventListener("keydown",p),()=>{document.body.style.overflow=d,document.removeEventListener("keydown",p)}},[n]),r.current?mt.createPortal(t.jsx("section",{role:"dialog","aria-modal":"true","aria-label":s,"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:i?"none":"translateX(-100%)",transition:`transform ${Wn}ms ${Zl}`,visibility:c?"visible":"hidden",pointerEvents:n?"auto":"none"},children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:o})}),r.current):null},Un=n=>{const e=ue.c(10),{title:s,description:o,action:r}=n;let i;e[0]!==s?(i=t.jsx("p",{className:"typography-ui-label text-foreground",children:s}),e[0]=s,e[1]=i):i=e[1];let a;e[2]!==o?(a=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[2]=o,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 u;return e[6]!==i||e[7]!==a||e[8]!==c?(u=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[i,a,c]}),e[6]=i,e[7]=a,e[8]=c,e[9]=u):u=e[9],u};function tc(n){return Se(n.path)}function sc(n){return Se(n.path)}function nc(n){return t.jsx(Jl,{worktree:n},Se(n.path))}const rc=(n,e)=>{if(!n)return e("mcpDropdown.status.unknown");switch(n.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:n.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:n.error||""});default:return n.status}},oc=n=>{switch(n?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},ic=({active:n,className:e,headerAction:s,listClassName:o,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:a}=me(),u=Qe(k=>k.currentDirectory)??null,f=Rt(k=>k.getStatusForDirectory(u)),d=Rt(k=>k.refresh),p=Rt(k=>k.connect),g=Rt(k=>k.disconnect),h=dt(k=>k.mcpServers),x=dt(k=>k.loadMcpConfigs),[j,b]=l.useState(!1),[I,S]=l.useState(null);l.useEffect(()=>{d({directory:u,silent:!0})},[d,u]),l.useEffect(()=>{x({force:!0})},[x]),l.useEffect(()=>{n&&Promise.all([d({directory:u,silent:!0}),x({force:!0})])},[n,d,u,x]);const E=l.useMemo(()=>{const k=new Set(Object.keys(f));for(const P of h)P?.name&&k.add(P.name);return Array.from(k).sort((P,w)=>P.localeCompare(w))},[h,f]),T=l.useCallback(k=>{if(k?.preventDefault(),j)return;b(!0);const P=new Promise(w=>setTimeout(w,500));Promise.all([d({directory:u}),P]).finally(()=>{b(!1)})},[j,d,u]);return t.jsxs("div",{className:X("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")}),u&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:u.split("/").pop()||u})]}),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-primary",disabled:j,onClick:T,"aria-label":a("mcpDropdown.actions.refreshAria"),children:t.jsx(ee,{name:"refresh",className:X("h-4 w-4",j&&"animate-spin")})})]})]})}),t.jsx("div",{className:X("max-h-64 overflow-y-auto",i?"space-y-1 py-3":"px-3 py-2.5",o),children:t.jsxs("div",{className:X(!i&&E.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[E.map(k=>{const P=f[k],w=oc(P),R=P?.status==="connected",y=I===k,A=rc(P,a);return t.jsxs("div",{className:X("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"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(Ho,{children:[t.jsx(qo,{asChild:!0,children:t.jsx("span",{className:X("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",w==="success"&&"bg-status-success",w==="error"&&"bg-status-error",w==="warning"&&"bg-status-warning",w==="default"&&"bg-muted-foreground/40"),"aria-label":A})}),t.jsx(Yo,{side:"left",children:t.jsx("p",{children:A})})]}),t.jsx("span",{className:X("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:k})]})}),t.jsx(Jo,{checked:R,disabled:y,className:"data-[checked]:bg-status-info",onCheckedChange:async M=>{S(k);try{if(!M){await g(k,u);return}const C=f?.[k]?.status;if(C==="needs_auth"||C==="needs_client_registration"){const{opened:N}=await Xo({name:k,directory:u});N||yn.error(a("mcpDropdown.toast.authorizeOpenFailed"));return}await p(k,u)}catch(C){yn.error(C instanceof Error?C.message:a("mcpDropdown.toast.authorizeFailed"))}finally{S(null)}}})]},k)}),E.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:a("mcpDropdown.empty.configureInConfig")})]})})]})},ac=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),lc=n=>{const e=n.index?.trim();return!!(e&&e!=="?")},cc=n=>{const e=n.working_dir?.trim(),s=n.index?.trim();return!!(e||s==="?")},Vn=(n,e)=>e?`${n}\0staged`:n,uc=({onClose:n,initialDiffPath:e,initialDiffStaged:s=!1})=>{const{t:o}=me(),{git:r}=Es(),i=ac(Ps()??null),a=Qo(i||null),c=Zo(i||null),u=ei(i||null),f=Ue(B=>B.setActiveDirectory),d=Ue(B=>B.ensureAll),p=Ue(B=>B.fetchStatus),g=Ue(B=>B.fetchBranches),h=Ue(B=>B.prefetchDiffs),x=Ue(B=>B.getDiff),j=Ue(B=>B.setDiff),[b,I]=l.useState(()=>e?{type:"diff",path:e,staged:s}:{type:"list"});l.useEffect(()=>{e&&I(B=>B.type==="diff"&&B.path===e&&B.staged===s?B:{type:"diff",path:e,staged:s})},[e,s]);const[S,E]=l.useState(null),[T,k]=l.useState(null),[P,w]=l.useState(""),[R,y]=l.useState(new Set),[A,M]=l.useState(!1),[C,N]=l.useState(!1),[q,$]=l.useState([]),[v,_]=l.useState([]),[O,z]=l.useState([]),[L,te]=l.useState(null),[Q,D]=l.useState(null),[J,K]=l.useState(0),H=l.useMemo(()=>{const B=a?.files??[],G=new Map;for(const re of B)G.set(re.path,re);return Array.from(G.values()).sort((re,le)=>re.path.localeCompare(le.path))},[a?.files]),W=l.useMemo(()=>H.filter(lc),[H]),Z=l.useMemo(()=>H.filter(cc),[H]),se=l.useMemo(()=>{if(O.length>0)return O;const B=a?.tracking?.includes("/")?a.tracking.split("/")[0]:null;return B||L?[{name:B||"origin",fetchUrl:L??"",pushUrl:L??""}]:[]},[L,O,a?.tracking]),ae=Ue(l.useCallback(B=>!i||b.type!=="diff"?null:B.directories.get(i)?.diffCache.get(Vn(b.path,b.staged))??null,[i,b])),he=l.useMemo(()=>b.type!=="diff"?null:H.find(B=>B.path===b.path)??null,[H,b]),oe=l.useCallback(async(B=!0)=>{if(i)try{await Promise.all([p(i,r),g(i,r)])}catch(G){B&&ce.error(G instanceof Error?G.message:o("gitView.toast.refreshRepositoryFailed"))}},[i,g,p,r,o]),U=l.useCallback(async()=>{if(!i){z([]),te(null);return}try{const[B,G]=await Promise.all([r.getRemotes(i).catch(()=>[]),r.getRemoteUrl?r.getRemoteUrl(i).catch(()=>null):Promise.resolve(null)]);z(B),te(G)}catch{z([]),te(null)}},[i,r]);l.useEffect(()=>{i&&(f(i),d(i,r))},[i,d,r,f]),l.useEffect(()=>{U()},[U]),l.useEffect(()=>{if(!i||H.length===0)return;const B=Array.from(new Set([...W.map(re=>re.path),...v,...H.slice(0,20).map(re=>re.path)])).filter(Boolean);if(B.length===0)return;const G=window.setTimeout(()=>{h(i,r,B,{maxFiles:40})},120);return()=>window.clearTimeout(G)},[H,i,r,h,W,v]),l.useEffect(()=>{if(b.type!=="diff"){D(null);return}const B=Vn(b.path,b.staged);if(!i||x(i,B)){D(null);return}let G=!1;const re=yt();return D(null),r.getGitFileDiff(i,{path:b.path,staged:b.staged||void 0}).then(le=>{G||j(i,B,{original:le.original??"",modified:le.modified??"",isBinary:le.isBinary},re)}).catch(le=>{G||D(le instanceof Error?le.message:String(le))}),()=>{G=!0}},[i,J,x,r,b,j]);const ie=async(B,G)=>{if(i){E(B);try{const re=le=>{const Ce=`${le.name}/`,xe=a?.tracking?.startsWith(Ce)?a.tracking.slice(Ce.length):void 0;return{remote:le.name,branch:xe,rebase:!0}};if(B==="fetch"){if(!G)throw new Error(o("mobile.changes.noRemote"));await r.gitFetch(i,{remote:G.name}),ce.success(o("gitView.toast.fetchedFromRemote",{name:G.name}))}else if(B==="sync"){if(!G)throw new Error(o("mobile.changes.noRemote"));await r.gitFetch(i,{remote:G.name});const le=await r.getGitStatus(i);if((le.behind??0)>0){if((le.files?.length??0)>0){ce.error(o("gitView.toast.commitOrStashBeforeSync"));return}await r.gitPull(i,re(G))}((await r.getGitStatus(i)).ahead??0)>0&&await r.gitPush(i),ce.success(o("gitView.toast.alreadyUpToDate"))}await oe(!1),await U()}catch(re){ce.error(re instanceof Error?re.message:o("gitView.toast.syncActionFailed",{action:o("gitView.sync.syncChanges")}))}finally{E(null)}}},V=l.useCallback(async(B,G)=>{if(!(!i||B.length===0))try{G==="stage"?B.length>1?await ti(i,B):await si(i,B[0]):B.length>1?await ni(i,B):await ri(i,B[0]),await oe(!1)}catch(re){ce.error(re instanceof Error?re.message:o(G==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[i,oe,o]),de=l.useCallback((B,G=!1)=>{I({type:"diff",path:B,staged:G})},[]),Ne=l.useCallback(async B=>{if(i){y(G=>new Set(G).add(B));try{await r.revertGitFile(i,B),ce.success(o("gitView.toast.revertedFile",{path:B})),await oe(!1)}catch(G){ce.error(G instanceof Error?G.message:o("gitView.toast.revertFailed"))}finally{y(G=>{const re=new Set(G);return re.delete(B),re})}}},[i,r,oe,o]),ke=l.useCallback(async B=>{if(!i||B.length===0||A)return;const G=Array.from(new Set(B));M(!0),y(new Set(G));try{await Promise.all(G.map(re=>r.revertGitFile(i,re))),await oe(!1),ce.success(G.length===1?o("gitView.toast.revertedFilesSingle",{count:G.length}):o("gitView.toast.revertedFilesPlural",{count:G.length}))}catch(re){ce.error(re instanceof Error?re.message:o("gitView.toast.revertFailed"))}finally{y(new Set),M(!1)}},[i,r,A,oe,o]),Pe=l.useCallback(B=>{const G=B.map(re=>re.trim()).filter(Boolean);if(G.length===0){$([]);return}w(re=>`${re.trim()}${re.trim()?`
23
+
24
+ `:""}${G.join(`
25
+ `)}`.trim()),$([])},[]),Le=l.useCallback(async()=>{if(!i)return;const B=W.map(G=>G.path).sort();if(B.length===0){ce.error(o("gitView.toast.selectFileToDescribe"));return}N(!0);try{const{message:G}=await oi(i,B);w(G.subject?.trim()??""),$(Array.isArray(G.highlights)?G.highlights:[])}catch(G){ce.error(G instanceof Error?G.message:o("gitView.toast.generateCommitMessageFailed"))}finally{N(!1)}},[i,W,o]),Te=async(B={})=>{if(!i)return;if(!P.trim()){ce.error(o("gitView.toast.enterCommitMessage"));return}const G=W.map(re=>re.path).sort();if(G.length===0){ce.error(o("gitView.toast.selectFileToCommit"));return}k(B.pushAfter?"commitAndPush":"commit");try{if(await r.createGitCommit(i,P.trim(),{files:G}),ce.success(o("gitView.toast.commitCreated")),w(""),$([]),B.pushAfter){const re=a?.tracking?.split("/")[0],le=se.find(We=>We.name===re)??se[0];if(!le)throw new Error(o("mobile.changes.noRemote"));E("sync");const Ce=`${le.name}/`,xe=a?.tracking?.startsWith(Ce)?a.tracking.slice(Ce.length):void 0;await r.gitFetch(i,{remote:le.name}),((await r.getGitStatus(i)).behind??0)>0&&await r.gitPull(i,{remote:le.name,branch:xe,rebase:!0}),((await r.getGitStatus(i)).ahead??0)>0&&await r.gitPush(i),await oe(!1),await U()}else await oe(!1)}catch(re){ce.error(re instanceof Error?re.message:o("gitView.toast.createCommitFailed"))}finally{k(null),B.pushAfter&&E(null)}},Ie=l.useMemo(()=>{const B=[];return W.length>0&&B.push({id:"staged",title:o("gitView.changes.stagedTitle"),entries:W,actionSymbol:"-",actionAllLabel:o("gitView.changes.unstageAllAria"),getActionLabel:G=>o("gitView.changes.unstageFileAria",{path:G}),onActionFile:G=>{V([G],"unstage")},onActionAll:G=>{V(G,"unstage")},onViewDiff:G=>de(G,!0),onRevertFile:Ne,showRevertActions:!1,accent:!0}),Z.length>0&&B.push({id:"unstaged",title:o("gitView.changes.title"),entries:Z,actionSymbol:"+",actionAllLabel:o("gitView.changes.stageAllAria"),getActionLabel:G=>o("gitView.changes.stageFileAria",{path:G}),onActionFile:G=>{V([G],"stage")},onActionAll:G=>{V(G,"stage")},onViewDiff:G=>de(G,!1),onRevertFile:Ne}),B},[Ne,de,V,W,o,Z]),we=B=>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:[n?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-primary","aria-label":o("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(ee,{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:a?.current||i||""})]})]}),t.jsx("div",{className:"min-h-0 flex-1",children:B})]});return i?u&&c===null?we(t.jsx(He,{loading:!0,message:o("gitView.loading.checkingRepository")})):c===!1?we(t.jsx(He,{icon:!0,message:o("gitView.empty.notGitRepository"),description:o("gitView.empty.notGitRepositoryDescription")})):b.type==="diff"?t.jsx(dc,{path:b.path,diff:ae,fileExists:!!he,error:Q,onBack:()=>I({type:"list"}),onRetry:()=>K(B=>B+1)}):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:[n?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-primary","aria-label":o("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(ee,{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:a?.current||i})]}),t.jsx(qi,{syncAction:S,remotes:se,onFetch:B=>{ie("fetch",B)},onSync:B=>{ie("sync",B)},disabled:T!==null||u,aheadCount:a?.ahead??0,behindCount:a?.behind??0,trackingRemoteName:a?.tracking?.split("/")[0],hasUncommittedChanges:H.length>0})]}),H.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(ya,{groups:Ie,diffStats:a?.diffStats,revertingPaths:R,onRevertAll:ke,isRevertingAll:A,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:_})}),t.jsx("div",{className:"shrink-0 border-t border-border/70 px-4 pb-4 pt-3",children:t.jsx(va,{stagedCount:W.length,commitMessage:P,onCommitMessageChange:w,generatedHighlights:q,onInsertHighlights:Pe,onGenerateMessage:Le,isGeneratingMessage:C,onCommit:()=>{Te({pushAfter:!1})},onCommitAndPush:()=>{Te({pushAfter:!0})},commitAction:T,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(He,{icon:!0,message:o("gitView.empty.cleanTitle"),description:o("mobile.changes.cleanDescription")})})]}):we(t.jsx(He,{message:o("gitView.empty.selectSessionOrDirectory")}))},He=n=>{const e=ue.c(13),{message:s,description:o,loading:r,icon:i}=n,a=r===void 0?!1:r,c=i===void 0?!1:i;let u;e[0]!==a?(u=a?t.jsx(ee,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=u):u=e[1];let f;e[2]!==c?(f=c?t.jsx(ee,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=c,e[3]=f):f=e[3];let d;e[4]!==s?(d=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[4]=s,e[5]=d):d=e[5];let p;e[6]!==o?(p=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[6]=o,e[7]=p):p=e[7];let g;return e[8]!==u||e[9]!==f||e[10]!==d||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:[u,f,d,p]})}),e[8]=u,e[9]=f,e[10]=d,e[11]=p,e[12]=g):g=e[12],g},dc=n=>{const e=ue.c(24),{path:s,diff:o,fileExists:r,error:i,onBack:a,onRetry:c}=n,{t:u}=me();let f;e[0]!==s?(f=ii(s)||"text",e[0]=s,e[1]=f):f=e[1];const d=f;let p;e[2]!==u?(p=u("header.actions.backAria"),e[2]=u,e[3]=p):p=e[3];let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=t.jsx(ee,{name:"arrow-left",className:"size-5"}),e[4]=g):g=e[4];let h;e[5]!==a||e[6]!==p?(h=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-primary","aria-label":p,onClick:a,children:g}),e[5]=a,e[6]=p,e[7]=h):h=e[7];let x;e[8]!==s?(x=t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:s})}),e[8]=s,e[9]=x):x=e[9];let j;e[10]!==h||e[11]!==x?(j=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:[h,x]}),e[10]=h,e[11]=x,e[12]=j):j=e[12];let b;e[13]!==o||e[14]!==i||e[15]!==r||e[16]!==d||e[17]!==c||e[18]!==s||e[19]!==u?(b=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r?i?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:u("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:i}),t.jsx(ye,{type:"button",size:"sm",variant:"outline",onClick:c,children:u("diffView.actions.retry")})]})}):o?o.isBinary?t.jsx(He,{icon:!0,message:u("diffView.binary.unavailable")}):ai(s)?t.jsx(He,{icon:!0,message:u("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(Rs,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(wa,{original:o.original,modified:o.modified,language:d,fileName:s,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(He,{loading:!0,message:u("diffView.state.loadingDiff")}):t.jsx(He,{icon:!0,message:u("mobile.changes.diffDetail.missingTitle"),description:u("mobile.changes.diffDetail.missingDescription")})}),e[13]=o,e[14]=i,e[15]=r,e[16]=d,e[17]=c,e[18]=s,e[19]=u,e[20]=b):b=e[20];let I;return e[21]!==j||e[22]!==b?(I=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[j,b]}),e[21]=j,e[22]=b,e[23]=I):I=e[23],I},fc=l.lazy(()=>pt(()=>import("./FilesView-DQOa7Lgz.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])).then(n=>({default:n.FilesView}))),tt=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),Dt=n=>{const e=tt(n);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},mc=n=>{const e=tt(n);if(!e||e==="/")return null;const s=e.lastIndexOf("/");return s<=0?e.startsWith("/")?"/":null:e.slice(0,s)},pc=(n,e)=>{const s=tt(n),o=tt(e);return!o||s===o?Dt(s):s.startsWith(`${o}/`)?s.slice(o.length+1):s},hc=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 o of e){if(s<1024||o===e[e.length-1])return`${s.toFixed(s>=10?0:1)} ${o}`;s/=1024}return""},gc=({onClose:n})=>{const{t:e}=me(),{files:s}=Es(),o=xo(v=>v.setSelectedPath),r=tt(Ps()??null),[i,a]=l.useState(()=>({type:"browser",directory:r})),[c,u]=l.useState([]),[f,d]=l.useState(!1),[p,g]=l.useState(null),[h,x]=l.useState(""),[j,b]=l.useState([]),[I,S]=l.useState(!1),E=l.useRef(0);l.useEffect(()=>{r&&a(v=>v.type==="browser"&&v.directory?v:{type:"browser",directory:r})},[r]);const T=i.type==="browser"?i.directory:i.returnDirectory,k=l.useCallback(async v=>{if(!v)return;const _=E.current+1;E.current=_,d(!0),g(null);try{const O=await s.listDirectory(v);if(E.current!==_)return;u(O.entries.slice().sort((z,L)=>z.isDirectory!==L.isDirectory?z.isDirectory?-1:1:z.name.localeCompare(L.name)))}catch(O){if(E.current!==_)return;u([]),g(O instanceof Error?O.message:e("mobile.files.error.listFailed"))}finally{E.current===_&&d(!1)}},[s,e]);l.useEffect(()=>{i.type==="browser"&&k(i.directory)},[k,i]),l.useEffect(()=>{if(i.type!=="browser")return;const v=h.trim();if(!v){b([]),S(!1);return}let _=!1;const O=window.setTimeout(()=>{S(!0),s.search({directory:i.directory,query:v,maxResults:40}).then(z=>{_||b(z)}).catch(()=>{_||b([])}).finally(()=>{_||S(!1)})},250);return()=>{_=!0,window.clearTimeout(O)}},[s,h,i]);const P=v=>{x(""),a({type:"browser",directory:v})},w=v=>{o(r,v),a({type:"file",path:v,returnDirectory:T||r})},R=Ge(v=>v.pendingFileFocusPath),y=Ge(v=>v.pendingFileNavigation);if(l.useEffect(()=>{const v=tt(y?.path??R??"");!v||!r||v!==r&&!v.startsWith(`${r}/`)||(o(r,v),a({type:"file",path:v,returnDirectory:r}),R&&Ge.getState().setPendingFileFocusPath(null))},[R,y,r,o]),!r)return t.jsx(Mt,{message:e("mobile.files.empty.noDirectory")});if(i.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-primary","aria-label":e("header.actions.backAria"),onClick:()=>a({type:"browser",directory:i.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(xn,{className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:Dt(i.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Oe,{children:t.jsx(l.Suspense,{fallback:t.jsx(Mt,{loading:!0,message:e("filesView.state.loading")}),children:t.jsx(fc,{mode:"editor-only"})})})})]});const A=i.directory===r?e("mobile.files.rootDirectory"):Dt(i.directory),M=h.trim()?j:[],C=mc(i.directory),N=i.directory!==r&&C!==null&&(C===r||C.startsWith(`${r}/`)),q=N&&!h.trim(),$=N?C:null;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 px-3 text-foreground",children:[n?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-primary","aria-label":e("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(br,{className:"size-5"})}):null,q&&$?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-primary","aria-label":e("mobile.files.backToParentAria",{name:Dt($)}),onClick:()=>P($),style:{touchAction:"manipulation"},children:t.jsx(xn,{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:A})}),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-primary","aria-label":e("mobile.files.refreshAria"),onClick:()=>{k(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(pa,{className:X("size-5",f&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(gr,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(Cs,{value:h,onChange:v=>x(v.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(Rs,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:p?t.jsx(Mt,{message:p}):h.trim()?t.jsx(bc,{results:M,isSearching:I,onOpenFile:w}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:[c.length===0&&!f?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:e("mobile.files.empty.directory")}):null,c.map(v=>t.jsx(Wr,{name:v.name,path:v.path,directory:v.isDirectory,meta:v.isDirectory?void 0:hc(v.size),onClick:()=>v.isDirectory?P(v.path):w(v.path)},v.path))]})})]})},Wr=n=>{const e=ue.c(16),{name:s,path:o,directory:r,meta:i,onClick:a}=n;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={touchAction:"manipulation"},e[0]=c):c=e[0];let u;e[1]!==r||e[2]!==o?(u=r?t.jsx(ha,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(li,{filePath:o,className:"size-5 shrink-0"}),e[1]=r,e[2]=o,e[3]=u):u=e[3];let f;e[4]!==s?(f=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:s}),e[4]=s,e[5]=f):f=e[5];let d;e[6]!==i?(d=i?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,e[6]=i,e[7]=d):d=e[7];let p;e[8]!==r?(p=r?t.jsx(ga,{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]!==u||e[12]!==f||e[13]!==d||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-primary focus-visible:ring-inset",onClick:a,style:c,children:[u,f,d,p]}),e[10]=a,e[11]=u,e[12]=f,e[13]=d,e[14]=p,e[15]=g):g=e[15],g},bc=n=>{const e=ue.c(10),{results:s,isSearching:o,onOpenFile:r}=n,{t:i}=me(),a=tt(Ps()??null);if(o){let d;e[0]!==i?(d=i("common.loading"),e[0]=i,e[1]=d):d=e[1];let p;return e[2]!==d?(p=t.jsx(Mt,{loading:!0,message:d}),e[2]=d,e[3]=p):p=e[3],p}if(s.length===0){let d;e[4]!==i?(d=i("mobile.files.search.empty"),e[4]=i,e[5]=d):d=e[5];let p;return e[6]!==d?(p=t.jsx(Mt,{message:d}),e[6]=d,e[7]=p):p=e[7],p}const c="overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",u=s.map(d=>t.jsx(Wr,{name:Dt(d.path),path:d.path,directory:!1,meta:pc(d.path,a),onClick:()=>r(d.path)},d.path));let f;return e[8]!==u?(f=t.jsx("div",{className:c,children:u}),e[8]=u,e[9]=f):f=e[9],f},Mt=n=>{const e=ue.c(7),{message:s,loading:o}=n,r=o===void 0?!1:o;let i;e[0]!==r?(i=r?t.jsx(ba,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(xa,{className:"size-6 text-muted-foreground"}),e[0]=r,e[1]=i):i=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]!==i||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:[i,a]})}),e[4]=i,e[5]=a,e[6]=c):c=e[6],c},Gn="mobile-surface-root",xc=16,Kn=320,yc="cubic-bezier(0.22, 1, 0.36, 1)",vc=n=>{const e=ue.c(36),{onOpenMcpSettings:s}=n,{t:o}=me(),[r,i]=l.useState(!1),a=Qe(wc),c=Rt(jc),u=dt(kc);let f;e[0]!==a||e[1]!==r||e[2]!==u||e[3]!==c?(f=()=>{if(r)return;i(!0);const A=new Promise(Sc);Promise.all([c({directory:a||null,silent:!0}),u({force:!0}),A]).finally(()=>i(!1))},e[0]=a,e[1]=r,e[2]=u,e[3]=c,e[4]=f):f=e[4];const d=f;let p;e[5]!==o?(p=o("settings.mcp.sidebar.actions.addServerTitle"),e[5]=o,e[6]=p):p=e[6];let g;e[7]!==o?(g=o("settings.mcp.sidebar.actions.addServerTitle"),e[7]=o,e[8]=g):g=e[8];let h,x;e[9]===Symbol.for("react.memo_cache_sentinel")?(h={touchAction:"manipulation"},x=t.jsx(ee,{name:"add",className:"size-5"}),e[9]=h,e[10]=x):(h=e[9],x=e[10]);let j;e[11]!==s||e[12]!==p||e[13]!==g?(j=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-primary",onClick:s,"aria-label":p,title:g,style:h,children:x}),e[11]=s,e[12]=p,e[13]=g,e[14]=j):j=e[14];let b;e[15]!==o?(b=o("mcpDropdown.actions.refreshAria"),e[15]=o,e[16]=b):b=e[16];let I;e[17]!==o?(I=o("mcpDropdown.actions.refreshAria"),e[17]=o,e[18]=I):I=e[18];let S;e[19]===Symbol.for("react.memo_cache_sentinel")?(S={touchAction:"manipulation"},e[19]=S):S=e[19];const E=r&&"animate-spin";let T;e[20]!==E?(T=X("size-5",E),e[20]=E,e[21]=T):T=e[21];let k;e[22]!==T?(k=t.jsx(ee,{name:"refresh",className:T}),e[22]=T,e[23]=k):k=e[23];let P;e[24]!==r||e[25]!==d||e[26]!==k||e[27]!==b||e[28]!==I?(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-primary",onClick:d,disabled:r,"aria-label":b,title:I,style:S,children:k}),e[24]=r,e[25]=d,e[26]=k,e[27]=b,e[28]=I,e[29]=P):P=e[29];let w;e[30]!==P||e[31]!==j?(w=t.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1 px-2 pt-1",children:[j,P]}),e[30]=P,e[31]=j,e[32]=w):w=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(ic,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})}),e[33]=R):R=e[33];let y;return e[34]!==w?(y=t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[w,R]}),e[34]=w,e[35]=y):y=e[35],y},Hn=({open:n,onClose:e,tab:s,onTabChange:o,pendingChangesDiff:r,onOpenPlan:i,onOpenMcpSettings:a,variant:c="drawer"})=>{const{t:u}=me(),f=l.useRef(null),[d,p]=l.useState(!1),[g,h]=l.useState(n),x=l.useRef(e);l.useEffect(()=>{x.current=e},[e]);const j=l.useRef(s);l.useEffect(()=>{j.current=s},[s]);const[b,I]=l.useState(()=>new Set);if(l.useEffect(()=>{n&&I(T=>{if(T.has(s))return T;const k=new Set(T);return k.add(s),k})},[n,s]),typeof document<"u"&&!f.current){let T=document.getElementById(Gn);T||(T=document.createElement("div"),T.id=Gn,document.body.appendChild(T)),f.current=T}if(l.useEffect(()=>{if(n){h(!0);const k=window.setTimeout(()=>p(!0),xc);return()=>window.clearTimeout(k)}p(!1);const T=window.setTimeout(()=>h(!1),Kn+40);return()=>window.clearTimeout(T)},[n]),l.useEffect(()=>{if(!n)return;const T=document.body.style.overflow;c==="drawer"&&(document.body.style.overflow="hidden");const k=P=>{P.key==="Escape"&&j.current!=="terminal"&&x.current()};return document.addEventListener("keydown",k),()=>{c==="drawer"&&(document.body.style.overflow=T),document.removeEventListener("keydown",k)}},[n,c]),c==="drawer"&&!f.current)return null;const S=[{id:"changes",label:u("mobile.menu.changes"),icon:t.jsx(ee,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"files",label:u("mobile.menu.files"),icon:t.jsx(ee,{name:"file-text",className:"h-3.5 w-3.5"})},{id:"terminal",label:u("mobile.menu.terminal"),icon:t.jsx(ee,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"notes",label:u("contextRail.surface.notes"),icon:t.jsx(ee,{name:"sticky-note",className:"h-3.5 w-3.5"})},{id:"mcp",label:u("mobile.menu.mcp"),icon:t.jsx(ci,{className:"h-3.5 w-3.5"})}],E=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:g?t.jsx(Yi,{items:S,activeId:s,onSelect:T=>o(T),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-primary","aria-label":u("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(ee,{name:"close",className:"size-5"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[b.has("changes")?t.jsx("div",{className:X("h-full",s!=="changes"&&"hidden"),children:t.jsx(Oe,{children:t.jsx(uc,{initialDiffPath:r?.path??null,initialDiffStaged:r?.staged===!0})})},r?`changes:${r.path}:${r.staged}`:"changes"):null,b.has("files")?t.jsx("div",{className:X("h-full",s!=="files"&&"hidden"),children:t.jsx(Oe,{children:t.jsx(gc,{})})}):null,b.has("terminal")?t.jsx("div",{className:X("h-full",s!=="terminal"&&"hidden"),children:t.jsx(Oe,{children:t.jsx(Ji,{visible:n&&s==="terminal"})})}):null,b.has("notes")?t.jsx("div",{className:X("h-full",s!=="notes"&&"hidden"),children:t.jsx(Oe,{children:t.jsx(Xi,{onActionComplete:e,onOpenPlan:i})})}):null,b.has("mcp")?t.jsx("div",{className:X("h-full",s!=="mcp"&&"hidden"),children:t.jsx(Oe,{children:t.jsx(vc,{onOpenMcpSettings:a})})}):null]})]});return c==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:E}):mt.createPortal(t.jsx("section",{role:"dialog","aria-modal":"true","aria-label":u("mobile.header.openWorkspaceAria"),"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:d?"none":"translateX(100%)",transition:`transform ${Kn}ms ${yc}`,visibility:g?"visible":"hidden",pointerEvents:n?"auto":"none"},children:E}),f.current)};function wc(n){return n.currentDirectory}function jc(n){return n.refresh}function kc(n){return n.loadMcpConfigs}function Sc(n){return window.setTimeout(n,500)}function Nc(n){const e=ue.c(4),s=2500,{uiFont:o}=ui(),[r,i]=l.useState(!1);let a,c;return e[0]!==s||e[1]!==o?(a=()=>{let u=!1;const f=()=>{u||i(!0)},d=()=>{requestAnimationFrame(()=>requestAnimationFrame(f))},p=Promise.all([di(o).catch(Tc),document.fonts?.ready?.then(Pc).catch(Rc)??Promise.resolve(),ja.catch(Ec)]).then(Cc),g=new Promise(h=>{window.setTimeout(h,s)});return Promise.race([p,g]).then(d),()=>{u=!0}},c=[o,s],e[0]=s,e[1]=o,e[2]=a,e[3]=c):(a=e[2],c=e[3]),l.useEffect(a,c),r}function Cc(){}function Ec(){}function Rc(){}function Pc(){}function Tc(){}const Ac="openchamber",Ic=n=>n.replace(/^\/+|\/+$/g,""),_c=n=>{const e=Ic(n.pathname).split("/").filter(Boolean);return n.host?[n.host,...e]:e};function Dc(n){if(typeof n!="string"||n.length===0)return null;let e;try{e=new URL(n)}catch{return null}if(e.protocol!==`${Ac}:`)return null;const s=_c(e),o=(s[0]??"").toLowerCase(),r=s.slice(1),i=e.searchParams;switch(o){case"session":{const a=r[0]||i.get("id")||"";return a?{type:"session",sessionId:a,directory:i.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:i.get("dir")??void 0,projectId:i.get("project")??void 0,agent:i.get("agent")??void 0,model:i.get("model")??void 0};case"sessions":{const a=i.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]||i.get("section")||void 0};case"changes":return{type:"changes",path:r.join("/")||i.get("path")||void 0,staged:i.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 De={},Ur=!1,_t=null;const Mc=n=>{switch(n.type){case"session":return je.getState().setCurrentSession(n.sessionId,n.directory??null),!0;case"new-session":{const e=je.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 De.openSessions?(De.openSessions(n.filter),!0):!1;case"status":return De.openSessions?(De.openSessions(),!0):!1;case"view":return De.openView?(De.openView(n.target),!0):!1;case"changes":return De.openChanges?(De.openChanges({path:n.path,staged:n.staged}),!0):!1;case"settings":return De.openSettings?(De.openSettings(n.section),!0):!1}},Js=()=>{if(!Ur||!_t)return;const n=_t;_t=null,Mc(n)||(_t=n)},Vr=n=>{_t=n,Js()},qn=n=>{const e=Dc(n);e&&Vr(e)},zc=n=>{Ur=n,Js()},Oc=n=>{const e=ue.c(3);let s,o;e[0]!==n?(s=()=>(De=n,Js(),()=>{De===n&&(De={})}),o=[n],e[0]=n,e[1]=s,e[2]=o):(s=e[1],o=e[2]),l.useEffect(s,o)},Lc=n=>{const{ready:e}=n;l.useEffect(()=>{zc(e)},[e]),l.useEffect(()=>{if(!Re())return;let s=!1;const o=[];return pt(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([125,4,126])).then(async({App:r})=>{if(s)return;const i=await r.addListener("appUrlOpen",a=>{qn(a?.url)});if(s){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),pt(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([127,126])).then(async({PushNotifications:r})=>{if(s)return;const i=await r.addListener("pushNotificationActionPerformed",a=>{const c=a?.notification?.data,u=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(u){qn(u);return}const f=typeof c?.sessionId=="string"?c.sessionId:void 0;f&&Vr({type:"session",sessionId:f})});if(s){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),()=>{s=!0,o.forEach(r=>r())}},[])},Bc=32,$c=80,Fc=64,Wc=.7,Uc=(n,e)=>{const s=l.useRef(e);s.current=e,l.useEffect(()=>{const o=n.current;if(!o)return;const i=window.Capacitor?.getPlatform?.()==="android"?$c:Bc;let a=!1,c=!1,u=0,f=0;const d=g=>{if(g.touches.length!==1){a=!1;return}const h=g.touches[0],x=o.clientWidth,j=h.clientX<=i,b=h.clientX>=x-i;a=j||b,c=j,u=h.clientX,f=h.clientY},p=g=>{if(!a)return;a=!1;const h=g.changedTouches[0];if(!h)return;const x=h.clientX-u,j=h.clientY-f;Math.abs(x)<Fc||Math.abs(j)>Math.abs(x)*Wc||c&&x<=0||!c&&x>=0||(c?s.current.onLeftEdgeSwipe?.():s.current.onRightEdgeSwipe?.())};return o.addEventListener("touchstart",d,{passive:!0}),o.addEventListener("touchend",p,{passive:!0}),()=>{o.removeEventListener("touchstart",d),o.removeEventListener("touchend",p)}},[n])},Vc=()=>{if(typeof window>"u")return;const n=window.__OPENCHAMBER_APNS_ENV__;if(n==="development")return"sandbox";if(n==="production")return"production"},Gc=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},Kc=n=>{const{enabled:e}=n,s=Ge(r=>r.nativeNotificationsEnabled),o=l.useRef(null);l.useEffect(()=>{if(!e||!s||!Gc())return;let r=!1;const i=[];return pt(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([127,126])).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 u=await a.addListener("registration",d=>{o.current=d.value,fn()?.push?.registerApnsToken?.({token:d.value,platform:Qn(),environment:Vc()})}),f=await a.addListener("registrationError",d=>{console.warn("[Push] APNs registration error:",d)});if(await a.register().catch(()=>{}),r){u.remove(),f.remove();return}i.push(()=>{u.remove()},()=>{f.remove()})}).catch(()=>{}),()=>{r=!0,i.forEach(a=>a())}},[e,s]),l.useEffect(()=>{if(s)return;const r=o.current;if(!r)return;o.current=null,fn()?.push?.unregisterApnsToken?.({token:r})},[s])},Yn=n=>{const e=ue.c(12),{side:s,isResizing:o,ariaLabel:r,handleProps:i}=n,a=s==="left"?"right-0":"left-0";let c;e[0]!==a?(c=X("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",a),e[0]=a,e[1]=c):c=e[1];const u=s==="left"?"right-0":"left-0",f=o&&"bg-[var(--interactive-border)]";let d;e[2]!==u||e[3]!==f?(d=X("absolute inset-y-0 w-[3px] transition-colors",u,f),e[2]=u,e[3]=f,e[4]=d):d=e[4];let p;e[5]!==d?(p=t.jsx("div",{className:d}),e[5]=d,e[6]=p):p=e[6];let g;return e[7]!==r||e[8]!==i||e[9]!==c||e[10]!==p?(g=t.jsx("div",{className:c,role:"separator","aria-orientation":"vertical","aria-label":r,...i,children:p}),e[7]=r,e[8]=i,e[9]=c,e[10]=p,e[11]=g):g=e[11],g},Hc=320,qc=380,Jn=280,Yc=560,Jc=900;function Xn(n,e,s,o){const r=ue.c(23),i=o===void 0?Yc:o,a=l.useRef(null);let c;r[0]!==s||r[1]!==i||r[2]!==e?(c=()=>{if(typeof window>"u")return s;const N=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(N)?Math.min(i,Math.max(Jn,N)):s},r[0]=s,r[1]=i,r[2]=e,r[3]=c):c=r[3];const[u,f]=l.useState(c),[d,p]=l.useState(!1),g=l.useRef(0),h=l.useRef(u),x=l.useRef(null),j=l.useRef(null);let b;r[4]!==i?(b=N=>Math.min(i,Math.max(Jn,Math.round(N))),r[4]=i,r[5]=b):b=r[5];const I=b;let S;r[6]===Symbol.for("react.memo_cache_sentinel")?(S=N=>{const q=a.current;q&&(q.style.width=`${N}px`,q.style.minWidth=`${N}px`,q.style.maxWidth=`${N}px`,q.style.setProperty("--oc-ipad-sidebar-width",`${N}px`))},r[6]=S):S=r[6];const E=S;let T;r[7]!==u?(T=N=>{try{N.currentTarget.setPointerCapture(N.pointerId)}catch{}j.current=N.pointerId,g.current=N.clientX,h.current=u,x.current=u,p(!0),N.preventDefault()},r[7]=u,r[8]=T):T=r[8];const k=T;let P;r[9]!==I||r[10]!==n?(P=N=>{if(j.current!==N.pointerId)return;const q=N.clientX-g.current,$=I(h.current+(n==="left"?q:-q));x.current!==$&&(x.current=$,E($))},r[9]=I,r[10]=n,r[11]=P):P=r[11];const w=P;let R;r[12]!==I||r[13]!==e?(R=N=>{if(j.current!==N.pointerId)return;try{N.currentTarget.releasePointerCapture(N.pointerId)}catch{}const q=I(x.current??h.current);j.current=null,x.current=null,p(!1),f(q);try{window.localStorage.setItem(e,String(q))}catch{}},r[12]=I,r[13]=e,r[14]=R):R=r[14];const y=R;let A;r[15]!==k||r[16]!==y||r[17]!==w?(A={onPointerDown:k,onPointerMove:w,onPointerUp:y,onPointerCancel:y},r[15]=k,r[16]=y,r[17]=w,r[18]=A):A=r[18];const M=A;let C;return r[19]!==M||r[20]!==d||r[21]!==u?(C={asideRef:a,width:u,isResizing:d,handleProps:M},r[19]=M,r[20]=d,r[21]=u,r[22]=C):C=r[22],C}const Xc=["general","appearance","chat","notifications","sessions","git","magic-prompts","behavior","mcp","providers","usage","voice","integrations","about"],Qc=1e3,Zc=({onActiveConnectionDeleted:n})=>{const{t:e}=me(),[s,o]=l.useState(!1),[r,i]=l.useState(null),[a,c]=l.useState(!1),[u,f]=l.useState("changes"),[d,p]=l.useState(null),[g,h]=l.useState("nav"),[x,j]=l.useState(null),b=Ge(V=>V.setSettingsPage),I=Ge(V=>V.wideChatLayoutEnabled),S=ct(V=>V.available),E=ct(V=>V.runtimeType),T=l.useMemo(()=>mr(),[]),k=dt(V=>V.mcpServers),P=dt(V=>V.setMcpDraft),w=dt(V=>V.setSelectedMcp),R=l.useCallback(()=>{i(null),p(null)},[]),y=l.useCallback(V=>{i(V)},[]),A=l.useCallback(()=>{c(!1)},[]),M=l.useCallback(V=>{h(V),y("settings")},[y]),{enabled:C,roomyForPanels:N}=Ss(),$=Pi()==="portrait",v=Ti(),[_,O]=l.useState(()=>Ai().roomyForPanels),z=l.useCallback(()=>{O(V=>!V)},[]);l.useEffect(()=>{C||O(!1)},[C]);const L=l.useCallback(()=>{j(null),f("files"),c(!0)},[]),te=l.useCallback((V=null)=>{j(V),f("changes"),c(!0)},[]),Q=Xn("left","openchamber.ipad.leftSidebarWidth",Hc),D=Xn("right","openchamber.ipad.rightSidebarWidth",qc,Jc),J=N,K=J&&a?D.width:0,H=C&&_?Q.width:0;l.useEffect(()=>{if(typeof document>"u")return;const V=document.documentElement;return V.style.setProperty("--oc-chat-inset-left",`${H}px`),V.style.setProperty("--oc-chat-inset-right",`${K}px`),()=>{V.style.removeProperty("--oc-chat-inset-left"),V.style.removeProperty("--oc-chat-inset-right")}},[H,K]),l.useEffect(()=>{if(typeof document>"u")return;const V=document.documentElement;return V.classList.toggle("wide-chat-layout",I),()=>V.classList.remove("wide-chat-layout")},[I]),l.useEffect(()=>{if(typeof document>"u")return;const V=C&&($||v),de=document.documentElement;return de.classList.toggle("oc-keep-draft-starters",V),()=>de.classList.remove("oc-keep-draft-starters")},[v,C,$]);const W=l.useMemo(()=>({openChanges:({diffPath:V,staged:de}={})=>{te(V?{path:V,staged:de===!0}:null)},openFiles:()=>L(),openSettings:()=>M("nav")}),[te,L,M]),Z=l.useMemo(()=>({openSessions:()=>{C?O(!0):o(!0)},openView:V=>{if(V==="files"){L();return}if(V==="mcp"){f("mcp"),c(!0);return}y(V)},openChanges:({path:V,staged:de}={})=>{te(V?{path:V,staged:de===!0}:null)},openSettings:V=>{V&&b(V),M(V?"page-content":"nav")}}),[C,te,L,M,y,b]);Oc(Z);const se=l.useRef(null);Uc(se,{onLeftEdgeSwipe:()=>{C?O(!0):o(!0)},onRightEdgeSwipe:()=>c(!0)});const ae=l.useCallback(()=>d?(p(null),!0):r?(R(),!0):a?(A(),!0):s?(o(!1),!0):!1,[r,R,A,d,s,a]);Ii(ae);const he=!T&&S&&(E==="desktop"||E==="web"),oe=C?"dialog":"fullscreen",U=l.useMemo(()=>({instanceLabel:T?Pt():null,onOpenInstances:T?()=>y("instances"):void 0,onOpenSettings:()=>M("nav"),onOpenUpdate:he?()=>y("update"):void 0}),[M,y,T,he]),ie=l.useCallback(()=>{const V="new-mcp-server";let de=V,Ne=1;for(;k.some(Pe=>Pe.name===de);)de=`${V}-${Ne}`,Ne+=1;P({name:de,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),w(de),b("mcp"),M("page-content")},[k,M,P,w,b]);return t.jsx(_i,{actions:W,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:[C?t.jsxs("aside",{ref:Q.asideRef,className:X("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!_&&"border-r-0"),style:{width:_?Q.width:0,minWidth:_?Q.width:0,maxWidth:_?Q.width:0,"--oc-ipad-sidebar-width":`${Q.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:Q.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!_,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:X("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",Q.isResizing&&"pointer-events-none",!_&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Oe,{children:t.jsx($n,{open:!0,variant:"sidebar",onOpenChange:V=>{!V&&!N&&O(!1)},footer:U})})}),_?t.jsx(Yn,{side:"left",isResizing:Q.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:Q.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(Al,{onOpenSessions:()=>C?z():o(!0),onOpenWorkspace:()=>c(!0),compactTitle:C}),t.jsx("main",{ref:se,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(Oe,{children:t.jsx(ra,{})})})})]}),C?null:t.jsx($n,{open:s,onOpenChange:o,footer:U}),C?t.jsxs("aside",{ref:D.asideRef,className:X("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!K&&"border-l-0"),style:{width:K,minWidth:K,maxWidth:K,"--oc-ipad-sidebar-width":`${D.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:D.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!K,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:X("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",D.isResizing&&"pointer-events-none",!K&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Oe,{children:t.jsx(Hn,{open:a,onClose:A,tab:u,onTabChange:f,pendingChangesDiff:x,onOpenPlan:p,onOpenMcpSettings:ie,variant:J?"panel":"drawer"})})}),K?t.jsx(Yn,{side:"right",isResizing:D.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:D.handleProps}):null]}):t.jsx(Hn,{open:a,onClose:A,tab:u,onTabChange:f,pendingChangesDiff:x,onOpenPlan:p,onOpenMcpSettings:ie}),d?t.jsx(It,{open:!0,variant:oe,onClose:()=>p(null),ariaLabel:d.title,title:d.title,children:t.jsx(Oe,{children:t.jsx(la,{savedProjectPlan:{projectRef:d.projectRef,planId:d.id},onNavigatedToChat:()=>{R(),A()}})})}):null,r==="instances"&&T?t.jsx(It,{open:!0,variant:oe,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(Ml,{onConnect:R,onActiveConnectionDeleted:n})}):null,r==="settings"?t.jsx(It,{open:!0,variant:oe,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Oe,{children:t.jsx(ia,{forceMobile:!0,isWindowed:!0,initialMobileStage:g,visiblePageSlugs:Xc.filter(V=>!(T&&V==="about")),onClose:R})})}):null,r==="update"?t.jsx(It,{open:!0,variant:oe,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Oe,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(aa,{initialUpdateDialogOpen:!0})})})}):null]})})};function eu({apis:n}){const{t:e}=me(),s=Me(D=>D.initializeApp),o=Me(D=>D.isInitialized),r=Me(D=>D.isConnected),i=Me(D=>D.connectionPhase),a=Me(D=>D.providers.length),c=Me(D=>D.agents.length),u=Me(D=>D.loadProviders),f=Me(D=>D.loadAgents),d=Qe(D=>D.currentDirectory),p=je(D=>D.error),g=je(D=>D.clearError),h=Ge(D=>D.setIsMobile),x=fi(D=>D.refreshStatus),j=mi(D=>D.setPlanModeEnabled),b=ze(D=>D.projects),[I,S]=l.useState(0),[E,T]=l.useState(0),[k,P]=l.useState(!1),[w,R]=l.useState("pending"),[y,A]=l.useState(null),M=l.useMemo(()=>Pt(),[]),[,C]=l.useReducer(D=>D+1,0),N=l.useMemo(()=>mr(),[]),q=l.useRef(0),$=l.useRef(0),v=l.useCallback(()=>{const D=Ve(),J=$.current+1;if($.current=J,!D){Ct("resume:auto-connect",{}),Et();return}Ct("resume:reprobe",{});const K=()=>{s(),x(n.github,{force:!0}),a===0&&u({source:"mobileApp:nativeResume"}),c===0&&f({source:"mobileApp:nativeResume"})},H=Z=>{Ct("resume:disconnect",{reason:Z}),lt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(se=>se+1)};Kt().then(Z=>{if($.current===J){if(Z==="no-connection"){H("no-connection");return}if(Z==="needs-login"){A({kind:"auth-expired",label:Pt()??""}),H("needs-login");return}if(Z==="unreachable"){const se=[4e3,1e4],ae=he=>{window.setTimeout(()=>{if($.current!==J)return;const oe=he===se.length-1;Kt({fast:!oe}).then(U=>{if($.current===J&&U!=="switched"){if(U==="unchanged"){K();return}if(U==="needs-login"){A({kind:"auth-expired",label:Pt()??""}),H("retry-needs-login");return}if(!oe){ae(he+1);return}H(`retry-${U}`)}})},se[he])};ae(0);return}Z!=="switched"&&K()}});const W=Date.now();W-q.current>=Qc&&(q.current=W,window.dispatchEvent(new Event("openchamber:system-resume")))},[c,n.github,s,f,u,a,x]);pi(),hi(v),l.useEffect(()=>{if(!N)return;let D;const J=()=>{window.clearTimeout(D),D=window.setTimeout(()=>v(),1500)};return window.addEventListener("online",J),()=>{window.removeEventListener("online",J),window.clearTimeout(D)}},[N,v]),l.useEffect(()=>{if(N)return mn.subscribe((D,J)=>{D.state==="expired"&&J.state!=="expired"&&(v(),mn.getState().markAuthenticated())})},[N,v]),l.useEffect(()=>(pn(n),()=>pn(null)),[n]),l.useEffect(()=>yo(D=>{if(Ct("endpoint:changed",{runtimeKey:D.runtimeKey||"none",previousRuntimeKey:D.previousRuntimeKey||"none",connected:!!D.apiBaseUrl}),!!D.runtimeKey&&D.runtimeKey===D.previousRuntimeKey){Qi(),C();return}Zi(D),T(K=>K+1),S(K=>K+1)}),[]),l.useEffect(()=>{if(!N||r||Ve()){R("done");return}let D=!1;return R("attempting"),(async()=>{const J=await Et().catch(()=>({status:"no-candidate"}));D||(J.status==="unreachable"?A({kind:"unreachable",label:J.label}):J.status==="needs-login"&&A({kind:"auth-expired",label:J.label}),R("done"),J.status==="unreachable"&&Et({fast:!1,skipIfConnected:!0}).catch(()=>null))})(),()=>{D=!0}},[]),l.useEffect(()=>{if(!N||!Ve())return;let D=!1;const J=K=>{Ct("cold-launch:drop",{kind:K?.kind??"unknown"}),K&&A(K),lt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(H=>H+1)};return Kt().then(async K=>{if(D||K==="switched"||K==="unchanged")return;const H=Pt();if(K==="needs-login"){J({kind:"auth-expired",label:H??""});return}if(K==="unreachable"){J(H?{kind:"unreachable",label:H}:null),Et({fast:!1,skipIfConnected:!0}).catch(()=>null);return}const W=await Et().catch(()=>({status:"no-candidate"}));D||W.status==="connected"||(W.status==="needs-login"?J({kind:"auth-expired",label:W.label}):W.status==="unreachable"?J({kind:"unreachable",label:W.label}):J(null))}),()=>{D=!0}},[]),l.useEffect(()=>{h(!0)},[h]),l.useEffect(()=>{N&&!Ve()||s()},[I,s,N]),l.useEffect(()=>{r&&(a===0&&u({source:"mobileApp:recovery"}),c===0&&f({source:"mobileApp:recovery"}))},[c,r,f,u,a]);const _=l.useRef(!1),[O,z]=l.useState(N);l.useEffect(()=>{if(!N||!r||_.current)return;if(je.getState().currentSessionId){_.current=!0,z(!1);return}const D=yt(),J=gi(D);if(!J){_.current=!0,z(!1);return}let K=!1;const H=window.setTimeout(()=>z(!1),6e3);return(async()=>{const W=await Ns().catch(()=>null);if(K)return;if(!W){z(!1);return}_.current=!0;const Z=W.activeSessions.find(ae=>ae.id===J.sessionId);if(!Z){bi(D),z(!1);return}const se=je.getState();se.currentSessionId||se.setCurrentSession(Z.id,ks(Z)??J.directory??void 0),z(!1)})(),()=>{K=!0,window.clearTimeout(H)}},[I,r,N]),l.useEffect(()=>{r&&hn.setDirectory(d)},[d,r]),l.useEffect(()=>{r&&x(n.github,{force:!0})},[n.github,r,x]),l.useEffect(()=>{if(!r||b.length===0)return;let D=!1;return(async()=>{const K=new Map(je.getState().availableWorktreesByProject);if(await Promise.all(b.map(async Z=>{const se=Z.path.replace(/\\/g,"/").replace(/\/+$/,"");if(se)try{if(!(Ue.getState().directories.get(se)?.isGitRepo??await pt(()=>import("./useAppFontEffects-KP8_yiGW.js").then(U=>U.i4),__vite__mapDeps([9,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82])).then(U=>U.checkIsGitRepository(se))))return;const oe=await dr({id:Z.id,path:se});if(D)return;K.set(se,oe)}catch{}})),D)return;const H=fr(b,K),W=je.getState().availableWorktreesByProject;Ri(H,W)||je.setState({availableWorktrees:[...H.values()].flat(),availableWorktreesByProject:H})})(),()=>{D=!0}},[r,b]),l.useEffect(()=>{let D=!1;return(async()=>{const K=await ws("/health",{method:"GET"}).catch(()=>null);if(!K||!K.ok||D)return;const H=await K.json().catch(()=>null);if(!H||D)return;const W=H.planModeExperimentalEnabled;j(W===!0||W===1||W==="1"||W==="true")})(),()=>{D=!0}},[j]),l.useEffect(()=>{if(!p)return;const D=window.setTimeout(()=>g(),5e3);return()=>window.clearTimeout(D)},[g,p]),l.useEffect(()=>{if(!(!r&&(N?!!Ve():!0))){P(!1);return}const J=window.setTimeout(()=>{P(!0)},N?4e3:8e3);return()=>window.clearTimeout(J)},[r,N,I,E]),xi(),yi({enabled:!0}),ea(),vi(),ta(),Kc({enabled:N&&r}),Lc({ready:N&&r&&o});const L=Nc(),te=!r&&i==="reconnecting";if(!L)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Ye,{width:120,height:120,isAnimated:!0})});const Q=!!Ve();return N&&(!Q||!r&&!te)?Q?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:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(Ye,{width:120,height:120,isAnimated:!k}),k?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(ye,{type:"button",variant:"outline",onClick:()=>{lt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(D=>D+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):w!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(Ye,{width:120,height:120,isAnimated:!0}),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(wi,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(gl,{onConnected:()=>S(D=>D+1),notice:y})}):!r&&!te?k?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-background text-foreground",children:t.jsx(Ye,{width:120,height:120,isAnimated:!0})}):t.jsx(Oe,{children:t.jsx(ji,{sdk:hn.getSdkClient(),directory:d||"",children:t.jsx(ki,{apis:n,children:t.jsx(Si,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[N&&O?t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:t.jsx(Ye,{width:120,height:120,isAnimated:!0})}):null,t.jsx(Ni,{embeddedBackgroundWorkEnabled:o}),t.jsx(sa,{}),t.jsx(Aa,{}),t.jsx(Zc,{onActiveConnectionDeleted:()=>{lt({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),S(D=>D+1)}}),t.jsx(Ci,{}),t.jsx(Ei,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),o?t.jsx(na,{}):null]})})})},E)})}const tu=()=>{$i(),vo().then(()=>{Promise.all([wo(),Fi()]).catch(n=>{console.error("[mobile-main] settings init failed:",n)}),Wi(),Ui(),Vi()}).catch(n=>{console.error("[mobile-main] appearance init failed:",n)}).finally(()=>{ka()})};function Rf(n){window.__OPENCHAMBER_SURFACE__="mobile",Di(),tu(),Ta(),Mi();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const o=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",r=o?{...n,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:n,i=t.jsx(eu,{apis:r});mo.createRoot(e).render(t.jsx(ms.StrictMode,{children:t.jsx(zi,{children:t.jsx(Oi,{children:t.jsx(Li,{children:t.jsx(oa,{children:o?i:t.jsx(Bi,{children:i})})})})})}))}export{Rf as renderMobileApp};