@openchamber/web 1.24.0 → 1.24.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 (131) hide show
  1. package/bin/cli.test.js +7 -6
  2. package/bin/lib/cli-http.js +5 -1
  3. package/dist/assets/{CodeMirrorCommentWidgets-C9kV-n7r.js → CodeMirrorCommentWidgets-DvUH815P.js} +1 -1
  4. package/dist/assets/DiffView-DkC3xlRJ.js +4 -0
  5. package/dist/assets/{FilesView-vjJx7VaM.js → FilesView-D0bM9FVB.js} +6 -6
  6. package/dist/assets/GitView-Bxuv3dfP.js +6 -0
  7. package/dist/assets/GuestAttachDialog-B0u3Q5uO.js +1 -0
  8. package/dist/assets/{JsonTreeView-D_4G5X6-.js → JsonTreeView-BBVPFM5K.js} +1 -1
  9. package/dist/assets/{LinearIssuesView-1uKhePfH.js → LinearIssuesView-UI1FcSC8.js} +1 -1
  10. package/dist/assets/{MarkdownImageGallery-Ix7N_2wp.js → MarkdownImageGallery-CUJxH8Le.js} +1 -1
  11. package/dist/assets/{MarkdownRendererImpl-Deel_y5S.js → MarkdownRendererImpl-D5BZOg8X.js} +1 -1
  12. package/dist/assets/{OnboardingScreen-ToIakxb_.js → OnboardingScreen-5Gou9cGD.js} +1 -1
  13. package/dist/assets/{PatchDiff-BjMgezr1.js → PatchDiff-C4rE5k6z.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-53Ghfnlr.js → PierreDiffViewer-ByRVu6ss.js} +1 -1
  15. package/dist/assets/{PlanView-BGAzxDwD.js → PlanView-u2yi5XGJ.js} +4 -4
  16. package/dist/assets/PluginPane-QxjsKYeO.js +3 -0
  17. package/dist/assets/SettingsView-Fo5ZqMaT.js +29 -0
  18. package/dist/assets/SettingsWindow-HVDVANjJ.js +1 -0
  19. package/dist/assets/{SubmoduleDiffSummary--YFqK6Ih.js → SubmoduleDiffSummary-D3hzkybB.js} +1 -1
  20. package/dist/assets/{ToolOutputDialog-DRWBvdaJ.js → ToolOutputDialog-3J6IRayW.js} +6 -6
  21. package/dist/assets/{ToolPartDiffPreview-BxZJCU28.js → ToolPartDiffPreview-DarxPjSd.js} +1 -1
  22. package/dist/assets/{VirtualizedFileDiff-DCXjBGRf.js → VirtualizedFileDiff-CZgXWHjU.js} +4 -4
  23. package/dist/assets/{WalkthroughView-CfIPvWWa.js → WalkthroughView-wSpED5L4.js} +2 -2
  24. package/dist/assets/{appThemeRegistry-DDROzcUO.js → appThemeRegistry-Cf8KitzT.js} +1 -1
  25. package/dist/assets/commitAndPush-DZnzlhvc.js +1 -0
  26. package/dist/assets/{computeVirtualFileMetrics-DHgQIkUq.js → computeVirtualFileMetrics-VYnT_A2h.js} +1 -1
  27. package/dist/assets/{de-CX_f-T5U.js → de-BM_8EDD3.js} +4 -4
  28. package/dist/assets/{es-BERmWNn_.js → es-CxZjlqpo.js} +3 -3
  29. package/dist/assets/{fr-BjYYE_-z.js → fr-VCixCnMW.js} +4 -4
  30. package/dist/assets/{index-WjufPkIV.js → index-3U4CtS9b.js} +1 -1
  31. package/dist/assets/index-B9Hvzjwl.css +1 -0
  32. package/dist/assets/index-DLHQogv8.js +40 -0
  33. package/dist/assets/{isDiffPlainText-D9faP70y.js → isDiffPlainText-ImDG3Uhg.js} +1 -1
  34. package/dist/assets/{isFilePlainText-6qOcz5Ky.js → isFilePlainText-D_YDVYDb.js} +1 -1
  35. package/dist/assets/{ja-DxqeAk9N.js → ja-CZ5k_GyD.js} +4 -4
  36. package/dist/assets/{ko-Dty1aUod.js → ko-7YM3A1Xh.js} +4 -4
  37. package/dist/assets/{main-Bjcre_GE.js → main-CycplCph.js} +2 -2
  38. package/dist/assets/main-DFYTCx5o.js +896 -0
  39. package/dist/assets/markdownCore-DHvqMxPn.js +5 -0
  40. package/dist/assets/{miniChat-Dz_bPgMc.js → miniChat-DIQKfY2V.js} +2 -2
  41. package/dist/assets/{mobile-BbZPBJrK.js → mobile-BMwz5q-m.js} +2 -2
  42. package/dist/assets/{patchFileDiff-BvU6KOQC.js → patchFileDiff-DDQ6Rq5e.js} +3 -3
  43. package/dist/assets/{pl-CX-_ROkr.js → pl-BcgDO_w5.js} +4 -4
  44. package/dist/assets/{pt-BR-DhRR1arx.js → pt-BR-CU2u_1q5.js} +3 -3
  45. package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +2 -0
  46. package/dist/assets/renderMobileApp-D0Y8DtkA.js +25 -0
  47. package/dist/assets/runtimeEndpointReset-DhC3REb2.js +25 -0
  48. package/dist/assets/{scheduledTasksApi-DW3xqMQ8.js → scheduledTasksApi-D8pq6gQz.js} +1 -1
  49. package/dist/assets/{shikiHighlight-DsxD9QEa.js → shikiHighlight-1imXsir9.js} +1 -1
  50. package/dist/assets/{textMateThemeFromAppTheme-Da7ed8qM.js → textMateThemeFromAppTheme-Dgqc63LZ.js} +1 -1
  51. package/dist/assets/tr-DuYhOzNe.js +7 -0
  52. package/dist/assets/{uk-CD21CXFV.js → uk-Cuk7-uvq.js} +3 -3
  53. package/dist/assets/{useAppFontEffects-hfv2s6mZ.js → useAppFontEffects-BItUWdo4.js} +147 -147
  54. package/dist/assets/{useInlineCommentController-BmtfVbo8.js → useInlineCommentController-CkbKsm7m.js} +2 -2
  55. package/dist/assets/useRootScrollLock-vmzxZjWA.js +2 -0
  56. package/dist/assets/{vendor-codemirror-language-data-BPMJpOpT.js → vendor-codemirror-language-data-BDyxuqK4.js} +2 -2
  57. package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
  58. package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
  59. package/dist/assets/{web-components-U-hWbgJo.js → web-components-D7FinaeH.js} +1 -1
  60. package/dist/assets/{zh-CN-BWvlPHY-.js → zh-CN-CUWoiRHd.js} +3 -3
  61. package/dist/assets/{zh-TW-CRp5dJU2.js → zh-TW-CQ8EBSBN.js} +3 -3
  62. package/dist/index.html +3 -3
  63. package/dist/mini-chat.html +3 -3
  64. package/dist/mobile.html +3 -3
  65. package/package.json +4 -3
  66. package/server/index.js +26 -7
  67. package/server/lib/changelog/update-notes.js +2 -1
  68. package/server/lib/changelog/update-notes.test.js +19 -0
  69. package/server/lib/event-stream/DOCUMENTATION.md +23 -0
  70. package/server/lib/event-stream/delta-coalescer.js +0 -0
  71. package/server/lib/event-stream/delta-coalescer.test.js +292 -0
  72. package/server/lib/event-stream/global-hub.js +53 -23
  73. package/server/lib/event-stream/global-hub.test.js +160 -0
  74. package/server/lib/event-stream/global-ws-bridge.js +1 -0
  75. package/server/lib/event-stream/index.js +4 -0
  76. package/server/lib/git/DOCUMENTATION.md +17 -4
  77. package/server/lib/git/routes.js +1 -1
  78. package/server/lib/git/serial-refresh.js +93 -0
  79. package/server/lib/git/serial-refresh.test.js +112 -0
  80. package/server/lib/git/service.js +232 -62
  81. package/server/lib/git/service.test.js +273 -0
  82. package/server/lib/github/pr-status.js +5 -5
  83. package/server/lib/github/pr-status.test.js +1 -1
  84. package/server/lib/github/routes.js +4 -4
  85. package/server/lib/guests/DOCUMENTATION.md +5 -3
  86. package/server/lib/guests/background.test.js +83 -0
  87. package/server/lib/guests/catalog.js +20 -9
  88. package/server/lib/guests/catalog.test.js +5 -5
  89. package/server/lib/guests/routes.js +2 -2
  90. package/server/lib/message-queue/DOCUMENTATION.md +6 -0
  91. package/server/lib/message-queue/runtime.js +5 -0
  92. package/server/lib/message-queue/runtime.test.js +32 -1
  93. package/server/lib/opencode/feature-routes-runtime.js +5 -0
  94. package/server/lib/opencode/settings-helpers.js +3 -0
  95. package/server/lib/opencode/settings-registry.json +8 -0
  96. package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
  97. package/server/lib/permission-auto-accept/runtime.js +13 -0
  98. package/server/lib/permission-auto-accept/runtime.test.js +37 -1
  99. package/server/lib/routing/DOCUMENTATION.md +81 -0
  100. package/server/lib/routing/defaults.js +98 -0
  101. package/server/lib/routing/feature-flag.js +11 -0
  102. package/server/lib/routing/history.js +34 -0
  103. package/server/lib/routing/jev.js +98 -0
  104. package/server/lib/routing/routes.http.test.js +100 -0
  105. package/server/lib/routing/routes.js +81 -0
  106. package/server/lib/routing/runtime.js +217 -0
  107. package/server/lib/routing/runtime.test.js +188 -0
  108. package/server/lib/routing/store.js +249 -0
  109. package/server/lib/routing/store.test.js +96 -0
  110. package/server/lib/security/request-security.js +9 -5
  111. package/server/lib/security/request-security.test.js +37 -0
  112. package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
  113. package/server/lib/ui-auth/session-cookie.js +51 -0
  114. package/server/lib/ui-auth/session-cookie.test.js +46 -0
  115. package/server/lib/ui-auth/ui-auth.js +13 -9
  116. package/server/lib/ui-auth/ui-auth.test.js +56 -0
  117. package/dist/assets/DiffView-B7YkbY-u.js +0 -4
  118. package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +0 -1
  119. package/dist/assets/GitView-BLhlMYEY.js +0 -6
  120. package/dist/assets/GuestAttachDialog-B-fwE8r3.js +0 -3
  121. package/dist/assets/SettingsView-n2X-jfBB.js +0 -29
  122. package/dist/assets/SettingsWindow-Bi8LE9XI.js +0 -1
  123. package/dist/assets/index-DpzTz2UH.css +0 -1
  124. package/dist/assets/index-Dy8xgawx.js +0 -40
  125. package/dist/assets/main-BOYSXfYn.js +0 -896
  126. package/dist/assets/markdownCore-DPrwM1rU.js +0 -5
  127. package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +0 -2
  128. package/dist/assets/renderMobileApp-BK1kFlcJ.js +0 -25
  129. package/dist/assets/runtimeEndpointReset-BULHvOwb.js +0 -25
  130. package/dist/assets/tr-cIQtYBpg.js +0 -7
  131. package/dist/assets/useRootScrollLock-Cwc4kSl2.js +0 -1
@@ -1,25 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-vjJx7VaM.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-Dy8xgawx.js","assets/vendor-zod-fZppILAM.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-zustand-BAGL70zf.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/index-DpzTz2UH.css","assets/useAppFontEffects-hfv2s6mZ.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-CsXYnR5c.js","assets/vendor-floating-ui-utils-D6FqdtJt.js","assets/vendor-floating-ui-react-dom-DxYCWdHj.js","assets/vendor-floating-ui-dom-BTvzWks8.js","assets/vendor-floating-ui-core-PuGzNPnN.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-framer-motion-Bq3iTZ6r.js","assets/vendor-motion-dom-DcCgeG69.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/contextPanelEmbeddedChat-CirXEPJq.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BgPj_McA.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-C9awkmn-.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-CiLROUVV.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-DzPz9Wgq.js","assets/vendor-codemirror-lang-json-CMBS2tG9.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-O0cZX78y.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CfgK872x.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-BPGOH9ye.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-BPMJpOpT.js","assets/vendor-codemirror-lang-python-HahnQaAS.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-B7H_j0iU.js","assets/vendor-legendapp-list-BuBPBC3R.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/runtimeEndpointReset-BULHvOwb.js","assets/GuestAttachDialog-B-fwE8r3.js","assets/shikiHighlight-DsxD9QEa.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-D_4G5X6-.js","assets/web-components-U-hWbgJo.js","assets/computeVirtualFileMetrics-DHgQIkUq.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-6qOcz5Ky.js","assets/appThemeRegistry-DDROzcUO.js","assets/textMateThemeFromAppTheme-Da7ed8qM.js","assets/Virtualizer-D_a8gKmg.js","assets/scheduledTasksApi-DW3xqMQ8.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/useInlineCommentController-BmtfVbo8.js","assets/CodeMirrorCommentWidgets-C9kV-n7r.js","assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-capacitor-push-notifications-KNe1zSBF.js"])))=>i.map(i=>d[i]);
2
- import{f as le,r as ln,j as t,R as c,c as Ot,h as Oo}from"./vendor-react-BUCujlKS.js";import{u as it,a as Ut,b as $r,d as qn,i as Be,e as ot,s as Tt,f as gs,h as hn,j as Bo,k as Fr,l as Lo,p as $o,m as Fo,n as yt,o as Wo,q as Jn,t as Uo,G as Yn,v as Vo,x as Xn,y as Qn,z as Zn,A as Go,B as er,M as Es,C as Ko,D as Ho}from"./index-Dy8xgawx.js";import{u as gn,a as qo,b as We,c as Wr,d as Ur,r as bn,e as Jo,f as de,t as ce,o as Yo,I as X,B as pe,g as Xo,O as It,h as J,P as Qo,i as Zo,j as ei,k as ti,l as Je,m as si,n as gt,p as ni,q as tr,s as ri,v as oi,w as xn,x as ii,y as ai,z as Ne,A as li,C as Vr,D as Gr,E as Kr,F as ci,G as yn,H as ui,J as Hr,K as He,L as qr,M as di,N as fi,Q as mi,R as Jr,S as Yr,T as Xr,U as Qr,V as Zr,W as eo,X as pi,Y as hi,Z as vn,_ as gi,$ as bi,a0 as rs,a1 as Qs,a2 as xi,a3 as to,a4 as yi,a5 as Fs,a6 as so,a7 as no,a8 as as,a9 as Mt,aa as vi,ab as wi,ac as ji,ad as ki,ae as Si,af as wn,ag as Ni,ah as Ci,ai as Ei,aj as Ri,ak as Pi,al as Ai,am as Ti,an as Ii,ao as sr,ap as Di,aq as _i,ar as Mi,as as zi,at as Oi,au as Rs,av as Bi,aw as Li,ax as ro,ay as Ye,az as $i,aA as Fi,aB as Wi,aC as Ui,aD as Vi,aE as Gi,aF as Ki,aG as oo,aH as Hi,aI as qi,aJ as Ji,aK as Yi,aL as Xi,aM as Qi,aN as Zi,aO as ea,aP as ta,aQ as sa,aR as na,aS as ra,aT as oa,aU as ia,aV as aa,aW as la,aX as ca,aY as ua,aZ as da,a_ as fa,a$ as ma,b0 as pa,b1 as ha,b2 as ga,b3 as ba,b4 as xa,b5 as ya,b6 as va,b7 as wa,b8 as ja,b9 as ka,ba as Sa,bb as Na,bc as Ca}from"./useAppFontEffects-hfv2s6mZ.js";import{u as Dt,S as io,s as Ea,p as Ra,a as Pa,D as Aa,N as Ta,b as Ia,r as Da,c as _a,g as Ma,h as za,d as Oa,B as Ba,e as La,f as $a,i as Fa,j as Wa,T as Ua,P as Va,k as Ga,l as Ka,m as Ha,n as qa,A as Ja,O as Ya,C as Xa,o as Qa,q as Za,t as el}from"./runtimeEndpointReset-BULHvOwb.js";import{_ as Bt}from"./vendor-vite-runtime-DD1OZmLC.js";import{S as tl,A as sl}from"./SettingsView-n2X-jfBB.js";import{PlanView as nl}from"./PlanView-BGAzxDwD.js";import{p as rl}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as ol}from"./vendor-capacitor-core-B4EWRrHz.js";import{k as cn,s as ao,M as jn,a as Ms,J as un,p as il,_ as nr,d as al,f as kn,V as ll,K as rr,P as cl,b as ul,c as dl,Q as fl,r as ml,U as pl,Z as hl}from"./vendor-remixicon-react-BDmGmFCA.js";import{f as Sn,h as Lt,i as Nn,P as Cn,D as En,j as Rn}from"./vendor-dnd-kit-core-BZknOX2w.js";import{s as Pn,S as An,v as Tn,u as In}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as Dn}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{c as _n,p as lo}from"./vendor-zustand-BAGL70zf.js";import{toast as or}from"./vendor-sonner-DFyL3AvE.js";import{C as gl,a as bl,D as xl}from"./DirtyBranchSwitchDialog-CU0A93Zx.js";import{u as yl,a as vl,b as wl,c as jl,i as kl,f as Sl,B as Nl,C as Cl,P as ir}from"./patchFileDiff-BvU6KOQC.js";import{u as El,a as Rl,i as Pl,S as Al,b as Tl}from"./SubmoduleDiffSummary--YFqK6Ih.js";import{P as Il}from"./PierreDiffViewer-53Ghfnlr.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-fZppILAM.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-CsXYnR5c.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./contextPanelEmbeddedChat-CirXEPJq.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BPMJpOpT.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./GuestAttachDialog-B-fwE8r3.js";import"./vendor-yaml-3778uTud.js";import"./shikiHighlight-DsxD9QEa.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-DDROzcUO.js";import"./textMateThemeFromAppTheme-Da7ed8qM.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-strip-json-comments-5dJlOkP1.js";import"./useInlineCommentController-BmtfVbo8.js";import"./CodeMirrorCommentWidgets-C9kV-n7r.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./VirtualizedFileDiff-DCXjBGRf.js";import"./web-components-U-hWbgJo.js";import"./computeVirtualFileMetrics-DHgQIkUq.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./isDiffPlainText-D9faP70y.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";let co=null,ar=!1;const Dl=new Promise(n=>{co=n});function _l(){ar||(ar=!0,co?.())}const Ml=6,zl=n=>n.parentID??null,lr=n=>{const e=n.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},Ol=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),Bl=(n,e)=>{if(!n)return"";let s=null,o=-1;for(const r of e){const i=Ol(r.path);(n===i||n.startsWith(`${i}/`))&&i.length>o&&(s=r,o=i.length)}return s?s.label?.trim()||lr(s.path):lr(n)},Ll=()=>{const n=gn.getState().activeSessions,e=qo.getState().index.session.unseenCount,s=it.getState().notifyOnSubtasks,o=We.getState().projects,r=Wr.getState().ids,i=Ur.getState().rankById;let a=0;const u=[];for(const f of n){const l=zl(f)!==null,b=(e[f.id]??0)>0&&(!l||s);b&&(a+=1),l||u.push({session:f,unread:b,project:Bl(bn(f),o)})}u.sort((f,l)=>Jo(f.session,l.session,r,i));const d=u.slice(0,Ml).map(({session:f,unread:l,project:p})=>({id:f.id,title:f.title??"",unread:l,project:p}));return{runtimeKey:Ut(),attentionCount:a,recentSessions:d}},$l="__OPENCHAMBER_WIDGET_SNAPSHOT__",Fl=()=>{typeof window>"u"||(window[$l]=()=>{try{return JSON.stringify(Ll())}catch{return null}})},Zs="mobile-app-update-available",cr="mobile-app-update-toast-dismissed-version",Wl=()=>{const n=le.c(8),{t:e}=de(),s=Dt(Ul),o=Dt(Vl),r=Dt(Gl),i=Dt(Kl);let a;n[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,n[0]=a):a=n[0];const u=ln.useRef(a);let d,f;return n[1]!==s||n[2]!==i||n[3]!==o||n[4]!==e||n[5]!==r?(d=()=>{if($r()!=="android"||o!=="mobile"||!s||!r||!i){ce.dismiss(Zs);return}qn().getItem(cr)!==r&&(u.current.has(r)||(u.current.add(r),ce.info(e("mobileUpdate.toast.available.title"),{id:Zs,description:e("mobileUpdate.toast.available.description",{version:r}),duration:1/0,icon:t.jsx(X,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{Yo(i)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{qn().setItem(cr,r),ce.dismiss(Zs)}}})))},f=[s,i,o,e,r],n[1]=s,n[2]=i,n[3]=o,n[4]=e,n[5]=r,n[6]=d,n[7]=f):(d=n[6],f=n[7]),ln.useEffect(d,f),null};function Ul(n){return n.available}function Vl(n){return n.runtimeType}function Gl(n){return n.info?.version}function Kl(n){return n.info?.downloadUrl}const ur=300,Hl="openchamber.mobile.connectLog.v1",_t=[];if(typeof window<"u")try{window.localStorage.removeItem(Hl)}catch{}const Mn=(n,e)=>{_t.push({at:Date.now(),step:n,detail:e}),_t.length>ur&&_t.splice(0,_t.length-ur)};typeof window<"u"&&Mn("app:launch","{}");const ql=()=>[..._t],Jl=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)}`},uo=n=>`${Jl(n.at)} ${n.step}${n.detail&&n.detail!=="{}"?` ${n.detail}`:""}`,Yl=()=>_t.map(uo).join(`
3
- `),fo=(n,e)=>{const s=le.c(10),o=700,r=c.useRef(null),i=c.useRef(null),a=c.useRef(!1);let u;s[0]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{r.current!==null&&window.clearTimeout(r.current),r.current=null,i.current=null},s[0]=u):u=s[0];const d=u;let f,l;s[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>d,l=[d],s[1]=f,s[2]=l):(f=s[1],l=s[2]),c.useEffect(f,l);let p;s[3]!==o||s[4]!==n?(p=N=>{a.current=!1,i.current={x:N.clientX,y:N.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 b=p;let h;s[6]===Symbol.for("react.memo_cache_sentinel")?(h=N=>{const E=i.current;E&&(Math.abs(N.clientX-E.x)>10||Math.abs(N.clientY-E.y)>10)&&d()},s[6]=h):h=s[6];const v=h;let S;s[7]===Symbol.for("react.memo_cache_sentinel")?(S=N=>{a.current&&(a.current=!1,N.preventDefault(),N.stopPropagation())},s[7]=S):S=s[7];const w=S;let T;return s[8]!==b?(T={onPointerDown:b,onPointerMove:v,onPointerUp:d,onPointerCancel:d,onClickCapture:w},s[8]=b,s[9]=T):T=s[9],T},zs="openchamber.mobile.connections.v1",Xl="openchamber.mobile.",dr="openchamber.mobile.deviceId",Ql=()=>{try{const n=window.localStorage.getItem(dr);if(n&&n.trim())return n.trim();const e=crypto.randomUUID();return window.localStorage.setItem(dr,e),e}catch{return crypto.randomUUID()}},fr=()=>`mobile:${Ql()}`,mr=()=>{try{const n=ol.getPlatform();return n==="ios"||n==="android"?n:void 0}catch{return}},mo=12,po=8e3,Zl=2500,ec=3e3,Os=2500,tc=()=>{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(/\/+$/,"")},Is=n=>{try{return new URL(n).host}catch{return n}},$t=n=>{try{return Vt(n)}catch{return n.trim().replace(/\/+$/g,"")}},ho=(n,e)=>$t(n)===$t(e),go=n=>`relay:${n.serverId}@${n.relayUrl.trim()}`,sc=n=>`relay://${n.serverId}`,Ws=n=>n.candidates.filter(e=>e.kind==="direct"),vt=n=>{const e=n.candidates.find(s=>s.kind==="relay");return e&&e.kind==="relay"?e.relay:null},at=n=>{const e=Ws(n)[0];if(e)return e.url;const s=vt(n);return s?sc(s):""},Ie=n=>{const e=vt(n);if(e)return go(e);const s=Ws(n)[0];return s?$t(s.url):""},Bs=(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=>$t(i.url)));return e.some(i=>i.kind==="relay"?o!==null&&i.relay.serverId===o:r.has($t(i.url)))},zn=n=>{const e=(()=>{try{return Vt(n)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},pr=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(...zn(n.url)),n.relay&&e.push({kind:"relay",relay:n.relay}),e},On=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}}},bo=n=>{try{return JSON.stringify(n)}catch{return String(n)}},ge=(n,e={})=>{const s=bo(e);console.info("[mobile-connect]",n,s),Mn(n,s)},os=(n,e={})=>{ge(n,e)},Ft=(n,e={})=>{const s=bo(e);console.info("[mobile-storage]",n,s),Mn(n,s)},nc=n=>{if(typeof n!="string")return n;try{return JSON.parse(n)}catch{return n}},rc=n=>{if(typeof n!="string")return n??void 0;try{return JSON.parse(n)}catch{return n}},oc=async(n,e)=>{if(!Be())return null;try{const{CapacitorHttp:s}=await Bt(async()=>{const{CapacitorHttp:i}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:i}},[]),o=Lo(n,new Headers(e?.headers)),r=await s.request({url:n,method:e?.method||"GET",headers:Object.fromEntries(o.entries()),data:rc(e?.body)});return{ok:r.status>=200&&r.status<300,status:r.status,source:"native-http",json:async()=>nc(r.data)}}catch(s){return ge("native-http:failed",{url:n,error:s instanceof Error?s.message:String(s)}),null}},ic=async(n,e)=>{const s=await fetch(n,e).catch(o=>(ge("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},ft=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)}},wt=async(n,e,s)=>{const o=s?.totalTimeoutMs??po,r=Date.now(),i=await ft(Math.min(Zl,o),oc(n,e));if(i)return i;const a=new AbortController,u=Math.max(500,o-(Date.now()-r));return ft(u,ic(n,{...e,signal:a.signal}),()=>a.abort())},Us=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}},Wt=15e3,ac=async(n,e,s,o=Wt,r)=>{const i=Fr({relayUrl:n.relayUrl,serverId:n.serverId,hostEncPubJwk:n.hostEncPubJwk}),a=u=>u==="ok"&&r?.keepTunnel?{outcome:u,tunnel:i}:(i.close(),{outcome:u});try{const u=e?{Authorization:`Bearer ${e}`}:void 0,d=await ft(o,i.fetch("/auth/session",{headers:u}).catch(()=>null));if(ge("relay:session",{ok:d?.ok===!0,status:d?.status??null,hasToken:!!e}),!d)return a("unreachable");if(d.status===401)return a(e?"auth-failed":"needs-login");if(!d.ok&&d.status!==404)return a("auth-failed");const f=await Us(d);return f&&f.disabled!==!0&&f.authenticated===!1?a(e?"auth-failed":"needs-login"):a("ok")}catch(u){throw i.close(),u}},lc=(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&&Bo(a,r),Tt({apiBaseUrl:i,clientToken:e,runtimeKey:o??go(n),relay:a})},cc=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=On(e.relay);return s?{kind:"relay",relay:s}:null}return null},uc=n=>{if(n.mode==="relay"){const e=On(n.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof n.url=="string"?zn(n.url):[]},kt=()=>{if(typeof window>"u")return[];let n;try{n=JSON.parse(window.localStorage.getItem(zs)||"[]")}catch{return[]}if(!Array.isArray(n))return[];const e=Be();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(cc).filter(d=>!!d):uc(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:Is(at({candidates:r})),u={id:o.id,label:a,candidates:r,lastUsedAt:typeof o.lastUsedAt=="number"?o.lastUsedAt:0};return e?[{...u,hasToken:!!o.hasToken||!!i}]:[{...u,clientToken:i,hasToken:!!i}]}).sort((s,o)=>o.lastUsedAt-s.lastUsedAt)},dn=n=>n.kind==="relay"?{kind:"relay",relay:{relayUrl:n.relay.relayUrl,serverId:n.relay.serverId,hostEncPubJwk:n.relay.hostEncPubJwk}}:{kind:"direct",url:n.url},Bn=n=>{if(typeof window>"u")return;const e=Be(),s=n.slice(0,mo).map(o=>{const r={id:o.id,label:o.label,candidates:o.candidates.map(dn),lastUsedAt:o.lastUsedAt};return e?{...r,hasToken:!!(o.hasToken||o.clientToken)}:{...r,clientToken:o.clientToken}});try{window.localStorage.setItem(zs,JSON.stringify(s))}catch(o){console.warn("[mobile-storage] failed to persist connection metadata",o)}},xo=(n,e)=>{const s=n.find(i=>e.id&&i.id===e.id||Bs(i.candidates,e.candidates)),o=Be(),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&&!Bs(i.candidates,e.candidates))].slice(0,mo)},Ln=rl,dc=0,$n=n=>`${Xl}token.${encodeURIComponent(n)}`,fc=async(n,e)=>{let s;const o=new Promise(r=>{s=window.setTimeout(()=>r(e),ec)});try{return await Promise.race([n.catch(()=>e),o])}finally{s!==void 0&&window.clearTimeout(s)}},Fn=async(n,e,s)=>Be()?fc(e().catch(o=>(console.warn(`[mobile-storage] ${n} failed`,o),s)),s):s,bs=async n=>{Ft("secure:read-start",{key:n});const e=await Fn("secure:read",async()=>(await Ln.internalGetItem({prefixedKey:$n(n),sync:!1})).data,null),s=typeof e=="string"&&e.trim()?e:void 0;return Ft("secure:read",{key:n,hasToken:!!s}),s},bt=async(n,e)=>{Ft("secure:write-start",{key:n});const s=await Fn("secure:write",async()=>(await Ln.internalSetItem({prefixedKey:$n(n),data:e,sync:!1,access:dc}),!0),!1);return Ft("secure:write",{key:n,ok:s}),s},mc=async n=>{await Fn("secure:delete",async()=>(await Ln.internalRemoveItem({prefixedKey:$n(n),sync:!1}),!0),!1)},pc=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,u=typeof a.url=="string"?a.url:null,d=typeof a.clientToken=="string"?a.clientToken.trim():"";if(!u||!d)return i;if(!await e(u,d))return o+=1,i;s+=1;const{clientToken:f,...l}=a;return{...l,hasToken:!0}})),migrated:s,failed:o}},yo=async()=>{if(typeof window>"u"||!Be())return;let n;try{n=JSON.parse(window.localStorage.getItem(zs)||"[]")}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;Ft("secure:migrate-start",{count:e.length});const s=await pc(n,async(o,r)=>{const i=$t(o);return await bt(i,r)?await bs(i)===r:!1});if(s.migrated>0)try{window.localStorage.setItem(zs,JSON.stringify(s.records))}catch(o){console.warn("[mobile-storage] failed to finalize secure token migration",o);return}Ft("secure:migrate-done",{migrated:s.migrated,failed:s.failed})},hc=async()=>(await yo(),kt()),Ls=async n=>{const e=xo(kt(),n);return Bn(e),Be()&&n.clientToken&&await bt(Ie({candidates:n.candidates}),n.clientToken),e},gc=async n=>{const e=kt(),s=e.find(r=>r.id===n)??null,o=e.filter(r=>r.id!==n);return Bn(o),s&&Be()&&await mc(Ie(s)),o},bc=1500,$s=async(n,e,s)=>{const o=s?.fast?{totalTimeoutMs:Os}:void 0,r=vt({candidates:n})?.serverId??null,i=n.find(f=>f.kind==="relay")??null,a=n.filter(f=>f.kind==="direct"),u=async()=>{for(const f of a){const l=Vt(f.url)||f.url,p=e?{Authorization:`Bearer ${e}`}:void 0,b=await wt(`${l}/health`,{method:"GET"},o);if(ge("probe:direct:health",{url:l,ok:b?.ok===!0,status:b?.status??null,source:b?.source??null}),!b?.ok)continue;if(r){const w=await b.json().catch(()=>null),T=w&&typeof w=="object"?w.serverId:null;if(typeof T=="string"&&T&&T!==r){ge("probe:server-id-mismatch",{url:l});continue}}const h=await wt(`${l}/auth/session`,{method:"GET",credentials:e?"omit":"include",headers:p},o);if(ge("probe:direct:session",{url:l,ok:h?.ok===!0,status:h?.status??null,source:h?.source??null,hasToken:!!e}),h?.status===401)return{status:"needs-login"};if(!h||!h.ok&&h.status!==404)continue;const v=await Us(h);if(v&&v.disabled!==!0&&v.authenticated===!1)return{status:"needs-login"};const S=v?.disabled===!0;return!e&&Be()&&!S&&v?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:l}}}return{status:"unreachable"}},d=async()=>{if(!i)return{status:"unreachable"};const{outcome:f,tunnel:l}=await ac(i.relay,e,void 0,s?.fast?Os:po,{keepTunnel:!0});return f==="ok"?{status:"ok",transport:{kind:"relay",relay:i.relay,tunnel:l}}:f==="needs-login"||f==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return i?a.length===0?d():new Promise(f=>{let l=!1,p=!1,b,h=null,v=null;const S=N=>{N?.status==="ok"&&N.transport.kind==="relay"&&N.transport.tunnel?.close()},w=N=>{l||(l=!0,f(N))},T=()=>{p||l||(b!==void 0&&(window.clearTimeout(b),b=void 0),d().then(N=>{if(v=N,l||p){S(N);return}if(N.status==="ok"||N.status==="needs-login"){w(N);return}h&&w(h)}))};u().then(N=>{if(h=N,!l){if(N.status==="ok"||N.status==="needs-login"){p=!0,b!==void 0&&window.clearTimeout(b),S(v),w(N);return}if(v){w(v);return}T()}}),b=window.setTimeout(T,bc)}):u()},xt=(n,e,s)=>{n.kind==="relay"?lc(n.relay,e,s?.grant,s?.runtimeKey,n.tunnel):Tt({apiBaseUrl:n.url,clientToken:e,runtimeKey:s?.runtimeKey}),wo()},ls=()=>{const n=kt()[0];return n?.label?.trim()?n.label:null},is=async n=>{const e=n?.fast!==!1;await yo();const s=kt()[0];if(ge("auto-connect:start",{hasCandidate:!!s,fast:e}),!s)return{status:"no-candidate"};let o;if(Be()){if(s.hasToken&&(o=await bs(Ie(s)),!o))return{status:"no-candidate"}}else if(o=s.clientToken,!o&&s.hasToken)return{status:"no-candidate"};const r=await $s(s.candidates,o,{fast:e});return ge("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&&ot()?(r.transport.kind==="relay"&&r.transport.tunnel?.close(),ge("auto-connect:superseded",{}),{status:"no-candidate"}):(await Ls({id:s.id,label:s.label,candidates:s.candidates}),xt(r.transport,o??null,{runtimeKey:Ie(s)}),{status:"connected"})},xc=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:Os}:void 0;if(!(await wt(`${s}/health`,{method:"GET",headers:r},i))?.ok)return!1;const u=await wt(`${s}/auth/session`,{method:"GET",credentials:o?"omit":"include",headers:r},i);if(!u||!u.ok&&u.status!==404)return!1;const d=await Us(u);return!(d&&d.disabled!==!0&&d.authenticated===!1)},yc=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=On({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return s?[{kind:"relay",relay:s}]:[]}return zn(e.url)}),hr=async n=>{const e=vt({candidates:n})?.serverId??null;for(const s of n){if(s.kind==="relay"){const i=Fr(s.relay),a=await ft(Wt,i.fetch("/health").catch(()=>null));if(ge("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 wt(`${o}/health`,{method:"GET"});if(ge("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){ge("establish:server-id-mismatch",{url:o});continue}}return{kind:"direct",url:o}}}return null},vc=async(n,e)=>{if(!gs())return xc(n,e);const s=await ft(e?.fast?Os:Wt,hn("/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 Us(s);return!(o&&o.disabled!==!0&&o.authenticated===!1)},wc=n=>n.kind==="relay"?gs():!gs()&&ho(n.url,ot()),vo=()=>{const n=Ut();return n?kt().find(e=>Ie(e)===n)??null:null},gr=n=>{const e=Ut();return!!e&&Ie(n)===e},Ds=async n=>{const e=n?.fast!==!1,s=vo();if(!s)return ge("reprobe:no-connection",{runtimeKey:!!Ut()}),"no-connection";let o;if(Be()?o=s.hasToken?await bs(Ie(s)):void 0:o=s.clientToken,!o&&s.hasToken)return ge("reprobe:no-token",{hasToken:!0}),"unreachable";ge("reprobe:start",{candidates:s.candidates.map(f=>f.kind),fast:e,hasToken:!!o});const r=s.candidates.findIndex(f=>wc(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 $s(i,o,{fast:e});if(ge("reprobe:better",{status:a.status,probed:i.length}),a.status==="ok")return await Ls({id:s.id,label:s.label,candidates:s.candidates}),xt(a.transport,o??null,{runtimeKey:Ie(s)}),"switched";if(a.status==="needs-login")return"needs-login";if(r>=0){const f=await vc({url:ot(),clientToken:o},{fast:e});if(ge("reprobe:current",{stillValid:f}),f)return wo(),"unchanged"}const u=r>=0?s.candidates.slice(r+1):[],d=await $s(u,o,{fast:e});return ge("reprobe:fallback",{status:d.status,probed:u.length}),d.status==="ok"?(await Ls({id:s.id,label:s.label,candidates:s.candidates}),xt(d.transport,o??null,{runtimeKey:Ie(s)}),"switched"):d.status==="needs-login"?"needs-login":"unreachable"},jc=5e3;let en=!1;const kc=async()=>{if(en)return"skipped";const n=vo();if(!n)return ge("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=vt(n);if(!e)return ge("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";en=!0;try{const s=await ft(Wt,hn("/api/client-auth/connection/candidates").then(f=>f).catch(()=>null));if(!s?.ok)return ge("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 ge("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 l=f;if(!(l.type!=="lan"||typeof l.url!="string"))try{const p=Vt(l.url);p&&!i.includes(p)&&i.push(p)}catch{}}if(i.length===0)return ge("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const a=Ws(n).filter(f=>f.url.startsWith("https://")),u=[...i.map(f=>({kind:"direct",url:f})),...a,{kind:"relay",relay:e}];return JSON.stringify(n.candidates.map(dn))===JSON.stringify(u.map(dn))?"unchanged":(ge("candidates:refreshed",{lanCount:i.length}),await Ls({id:n.id,label:n.label,candidates:u}),"updated")}finally{en=!1}},wo=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const n=await kc().catch(()=>"skipped");ge("candidates:refresh-result",{result:n}),n==="updated"&&gs()&&await Ds().catch(()=>null)})()},jc)},jo=n=>{const{t:e}=de(),[s,o]=c.useState(()=>kt()),[r,i]=c.useState(null),[a,u]=c.useState(null),[d,f]=c.useState(null),l=c.useRef(s),p=c.useRef(null),b=c.useRef(tc()),h=c.useCallback(k=>{l.current=k,o(k)},[]),v=c.useCallback(k=>{p.current=k,i(k)},[]),S=c.useCallback(k=>{p.current===k&&(p.current=null,i(null))},[]);c.useEffect(()=>{let k=!1;return hc().then(R=>{k||h(R)}),()=>{k=!0}},[h]);const w=c.useCallback(k=>{const R=xo(l.current,k);return h(R),Bn(R),R},[h]),T=c.useCallback(async k=>{u(null),v("connect");try{const R=pr(k);if(R.length===0){u(e("mobile.connect.error.urlRequired"));return}const y=k.id?l.current.find(K=>K.id===k.id):l.current.find(K=>Bs(K.candidates,R)),z=k.label?.trim()||y?.label||Is(at({candidates:R})),M=k.relayGrant;let C=k.clientToken?.trim()||void 0;const x=!!C;C||(Be()?y?.hasToken&&(C=await bs(Ie({candidates:R}))):C=y?.clientToken),ge("connect:start",{candidates:R.map(K=>K.kind),hasToken:!!C});const D=await $s(R,C);if(ge("connect:probe",{status:D.status}),D.status==="unreachable"){u(e("mobile.connect.error.unreachable"));return}if(D.status==="needs-login"){w({id:y?.id,label:z,candidates:R}),f({id:y?.id??crypto.randomUUID(),label:z,candidates:R,relay:vt({candidates:R})??void 0,relayGrant:M});return}C&&x&&Be()&&await bt(Ie({candidates:R}),C),w({id:y?.id,label:z,candidates:R,clientToken:C}),xt(D.transport,C??null,{runtimeKey:Ie({candidates:R}),grant:M}),n()}catch(R){console.warn("[mobile-connect] connect threw",R),u(e("mobile.connect.error.invalidUrl"))}finally{S("connect")}},[v,S,n,w,e]),N=c.useCallback(async k=>{if(p.current==="pairing")return;u(null),v("pairing");const R=yc(k.candidates);let y=null,z=!1;try{if(y=await hr(R),!y){u(e("mobile.connect.error.unreachable"));return}const M=JSON.stringify({pairingId:k.pairingId,secret:k.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:mr(),dedupeKey:fr()}),C={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:M},x=y.kind==="relay"?await ft(Wt,y.tunnel.fetch("/api/client-auth/pairing/redeem",C).catch(()=>null)):await wt(`${y.url}/api/client-auth/pairing/redeem`,C);if(!x?.ok){u(e("mobile.connect.error.authRequired"));return}const D=await x.json().catch(()=>null),K=typeof D?.clientToken=="string"?D.clientToken.trim():"";if(!K){u(e("mobile.connect.error.authRequired"));return}const g=typeof D?.server?.label=="string"?D.server.label:"",L=k.label||g||Is(at({candidates:R}));if(Be()&&!await bt(Ie({candidates:R}),K)){u(e("mobile.connect.error.authRequired"));return}w({label:L,candidates:R,clientToken:K}),xt(y.kind==="relay"?{kind:"relay",relay:y.relay,tunnel:y.tunnel}:{kind:"direct",url:y.url},K,{runtimeKey:Ie({candidates:R})}),z=y.kind==="relay",n()}catch(M){console.warn("[mobile-connect] pairing threw",M),u(e("mobile.connect.error.authRequired"))}finally{!z&&y?.kind==="relay"&&y.tunnel.close(),S("pairing")}},[v,S,n,w,e]),E=c.useCallback(async k=>{if(!d||!k.trim()||p.current==="password")return;u(null),v("password");const R=b.current.begin(),y=()=>b.current.isCurrent(R),{id:z,label:M,candidates:C}=d;let x=null,D=!1;try{if(x=await hr(C),!y())return;if(!x){u(e("mobile.connect.error.unreachable"));return}const K={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:k,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile",clientKind:"mobile",devicePlatform:mr(),dedupeKey:fr()})};ge("password:start",{transport:x.kind});const g=x.kind==="relay"?await ft(Wt,x.tunnel.fetch("/auth/session",K).catch(()=>null)):await wt(`${x.url}/auth/session`,K);if(!y())return;if(ge("password:done",{ok:g?.ok===!0,status:g?.status??null}),!g?.ok){u(e("mobile.connect.error.passwordFailed"));return}const L=await g.json().catch(()=>null);if(!y())return;const F=typeof L?.clientToken=="string"?L.clientToken.trim():"";if(ge("password:token",{issued:!!F}),!F){if(x.kind==="direct"&&!Be()){w({id:z,label:M,candidates:C}),f(null),xt({kind:"direct",url:x.url},null,{runtimeKey:Ie({candidates:C})}),n();return}u(e("mobile.connect.error.authRequired"));return}if(Be()&&(!y()||(await bt(Ie({candidates:C}),F),!y()))||!y()||(w({id:z,label:M,candidates:C,clientToken:F}),f(null),xt(x.kind==="relay"?{kind:"relay",relay:x.relay,tunnel:x.tunnel}:{kind:"direct",url:x.url},F,{runtimeKey:Ie({candidates:C})}),D=x.kind==="relay",!y()))return;n()}catch(K){if(!y())return;console.warn("[mobile-connect] password threw",K),u(e("mobile.connect.error.passwordFailed"))}finally{!D&&x?.kind==="relay"&&x.tunnel.close(),y()&&S("password")}},[v,S,n,d,w,e]),I=c.useCallback(()=>{b.current.cancel(),S("password"),f(null),u(null)},[S]),j=c.useCallback(async k=>{u(null);let R=pr(k);const y=k.id?l.current.find(x=>x.id===k.id)??null:null;if(y){const x=R.filter(g=>g.kind==="direct"),D=Ws(y).filter(g=>g.url.startsWith("https://")&&!x.some(L=>ho(L.url,g.url))),K=vt(y);R=[...x,...D,...K?[{kind:"relay",relay:K}]:[]]}if(R.length===0)return u(e("mobile.connect.error.urlRequired")),null;const z=k.clientToken?.trim()||void 0,M=k.label?.trim()||Is(at({candidates:R}));if(Be()){const x=Ie({candidates:R});if(z)await bt(x,z);else if(y?.hasToken){const D=Ie(y);if(D&&x&&D!==x){const K=await bs(D);K&&await bt(x,K)}}}return w({id:k.id,label:M,candidates:R,clientToken:z}).find(x=>Bs(x.candidates,R))??null},[w,e]),P=c.useCallback(async k=>{const R=l.current.find(z=>z.id===k)??null,y=await gc(k);return h(y),R},[h]);return{connections:s,isBusy:r!==null,isPasswordBusy:r==="password",error:a,pendingConnection:d,connect:T,redeemPairingConnection:N,submitPassword:E,cancelPassword:I,saveConnection:j,removeConnection:P,setError:u}},ko=n=>{const e=le.c(31),{onClose:s}=n,{t:o}=de(),[r,i]=c.useState(!1);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=ql(),e[0]=a):a=e[0];const u=a;let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{Xo(Yl()).then(k=>{k.ok&&(i(!0),window.setTimeout(()=>i(!1),2e3))})},e[1]=d):d=e[1];const f=d;let l;e[2]!==o?(l=o("mobile.connectionDebug.title"),e[2]=o,e[3]=l):l=e[3];let p;e[4]!==l?(p=t.jsx("h2",{className:"min-w-0 truncate typography-ui-label text-foreground",children:l}),e[4]=l,e[5]=p):p=e[5];const b=r?"check":"file-copy";let h;e[6]!==b?(h=t.jsx(X,{name:b,className:"size-4"}),e[6]=b,e[7]=h):h=e[7];let v;e[8]!==r||e[9]!==o?(v=o(r?"mobile.connectionDebug.copied":"mobile.connectionDebug.copy"),e[8]=r,e[9]=o,e[10]=v):v=e[10];let S;e[11]!==h||e[12]!==v?(S=t.jsxs(pe,{type:"button",variant:"outline",size:"sm",onClick:f,disabled:u.length===0,children:[h,v]}),e[11]=h,e[12]=v,e[13]=S):S=e[13];let w;e[14]!==o?(w=o("mobile.connectionDebug.close"),e[14]=o,e[15]=w):w=e[15];let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(X,{name:"close",className:"size-[18px]"}),e[16]=T):T=e[16];let N;e[17]!==s||e[18]!==w?(N=t.jsx(pe,{type:"button",variant:"ghost",size:"icon","aria-label":w,onClick:s,children:T}),e[17]=s,e[18]=w,e[19]=N):N=e[19];let E;e[20]!==N||e[21]!==S?(E=t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[S,N]}),e[20]=N,e[21]=S,e[22]=E):E=e[22];let I;e[23]!==E||e[24]!==p?(I=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]=I):I=e[25];let j;e[26]!==o?(j=t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-3",children:u.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:u.map(uo).join(`
4
- `)})}),e[26]=o,e[27]=j):j=e[27];let P;return e[28]!==I||e[29]!==j?(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:[I,j]}),e[28]=I,e[29]=j,e[30]=P):P=e[30],P},So=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&(typeof e.scan=="function"||typeof e.startScan=="function")?e:null},Sc=()=>window.Capacitor?.getPlatform?.()==="android",No=n=>{const e=n.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e)){const s=$o(e);return s?{pairing:s}:null}return/^https?:\/\//i.test(e)?{url:e}:null},Co=(n,e)=>{const s=No(n);if(!s&&e?.pairingStringFallback){const o=Fo(n);if(o)return{status:"pairing",pairing:o}}return s?"pairing"in s?{status:"pairing",...s}:{status:"ok",...s}:{status:"invalid"}},Nc=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}),u=f=>{r||(r=!0,i(f))},d=()=>u({status:"cancelled"});e?.addEventListener("abort",d,{once:!0});try{return(await Promise.allSettled([Promise.resolve(n.addListener("barcodesScanned",({barcodes:l})=>{const p=l?.[0],b=(p?.rawValue??p?.displayValue??"").trim();b&&u(Co(b,{pairingStringFallback:!0}))})).then(l=>{s=l}),Promise.resolve(n.addListener("scanError",()=>u({status:"failed"}))).then(l=>{o=l})])).some(({status:l})=>l==="rejected")?u({status:"failed"}):r||n.startScan({formats:["QR_CODE"]}).catch(()=>u({status:"failed"})),await a}finally{e?.removeEventListener("abort",d),await Promise.allSettled([Promise.resolve(s?.remove()),Promise.resolve(o?.remove()),n.stopScan()])}},fn=()=>So()!==null,Eo=async n=>{const e=So();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(Sc())return Nc(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?Co(r):{status:"cancelled"}}catch{return{status:"failed"}}},zt={autoComplete:"off",autoCorrect:"off",spellCheck:!1},cs="oc-surface-elevated h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-interactive-border-focus focus:ring-2 focus:ring-ring",Ro=n=>{const e=le.c(22),{onCancel:s}=n,{t:o}=de(),r=c.useRef(null);let i,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{const T={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},N={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,I=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(I);const j=new MutationObserver(P=>{P.forEach(k=>k.addedNodes.forEach(I))});return j.observe(document.body,{childList:!0}),()=>{j.disconnect(),E.forEach(Cc),T.value?document.documentElement.style.setProperty("background-color",T.value,T.priority):document.documentElement.style.removeProperty("background-color"),N.value?document.body.style.setProperty("background-color",N.value,N.priority):document.body.style.removeProperty("background-color")}},a=[],e[0]=i,e[1]=a):(i=e[0],a=e[1]),c.useLayoutEffect(i,a);let u,d;e[2]!==s?(u=()=>{const T=()=>{document.visibilityState==="hidden"&&s()};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},d=[s],e[2]=s,e[3]=u,e[4]=d):(u=e[3],d=e[4]),c.useEffect(u,d);let f;e[5]!==o?(f=o("mobile.connect.scanQr"),e[5]=o,e[6]=f):f=e[6];let l;e[7]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),e[7]=l):l=e[7];let p;e[8]!==o?(p=o("mobile.connect.welcome.scanHint"),e[8]=o,e[9]=p):p=e[9];let b;e[10]!==p?(b=t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[l,t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:p})]}),e[10]=p,e[11]=b):b=e[11];let h;e[12]===Symbol.for("react.memo_cache_sentinel")?(h=t.jsx(X,{name:"close",className:"size-[18px]"}),e[12]=h):h=e[12];let v;e[13]!==o?(v=o("mobile.instances.cancelEdit"),e[13]=o,e[14]=v):v=e[14];let S;e[15]!==s||e[16]!==v?(S=t.jsxs(pe,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:s,children:[h,v]}),e[15]=s,e[16]=v,e[17]=S):S=e[17];let w;return e[18]!==S||e[19]!==f||e[20]!==b?(w=Ot.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:[b,S]}),document.body),e[18]=S,e[19]=f,e[20]=b,e[21]=w):w=e[21],w},Po=()=>{const n=le.c(6),{t:e}=de();let s;n[0]===Symbol.for("react.memo_cache_sentinel")?(s=t.jsx(It,{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(X,{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=Ot.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 Cc(n,e){e.style.opacity=n.opacity,e.style.pointerEvents=n.pointerEvents}const Ec=({onConnected:n,notice:e=null})=>{const{t:s}=de(),o=jo(n),{connections:r,isBusy:i,isPasswordBusy:a,error:u,pendingConnection:d}=o,[f,l]=c.useState(""),[p,b]=c.useState(""),[h,v]=c.useState(""),[S,w]=c.useState(!1),[T,N]=c.useState(!1),E=c.useRef(null),I=c.useMemo(()=>fn(),[]),[j,P]=c.useState(()=>!fn()),[k,R]=c.useState(null),[y,z]=c.useState(""),[M,C]=c.useState(!1),x=fo(c.useCallback(()=>C(!0),[])),D=c.useCallback(B=>{B.preventDefault(),o.connect({url:f,clientToken:h,label:p})},[h,o,p,f]),K=c.useCallback(B=>{if(/^openchamber:\/\//i.test(B.trim())){const W=No(B);if(W){if("pairing"in W){o.redeemPairingConnection(W.pairing);return}l(W.url),W.label&&b(W.label),W.clientToken&&v(W.clientToken);return}}l(B)},[o]),g=c.useCallback(async()=>{if(E.current||i)return;o.setError(null),w(!0);const B=new AbortController;E.current=B;try{const W=await Eo({signal:B.signal});switch(E.current===B&&(E.current=null,w(!1)),W.status){case"ok":N(!0),l(W.url),W.label&&b(W.label),W.clientToken&&v(W.clientToken),await o.connect({url:W.url,clientToken:W.clientToken,label:W.label});break;case"pairing":N(!0),await o.redeemPairingConnection(W.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{N(!1),E.current===B&&(E.current=null,w(!1))}},[o,i,s]);c.useEffect(()=>()=>E.current?.abort(),[]);const L=c.useCallback(B=>{B.preventDefault(),o.submitPassword(y)},[o,y]),F=c.useCallback(()=>{z(""),o.cancelPassword()},[o]);return t.jsxs(t.Fragment,{children:[S?t.jsx(Ro,{onCancel:()=>E.current?.abort()}):null,T?t.jsx(Po,{}):null,M?t.jsx(ko,{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",{...x,className:"select-none",style:{touchAction:"manipulation"},children:t.jsx(It,{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(X,{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,d?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:L,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(X,{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:d.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:d.candidates.some(B=>B.kind==="direct")?at(d):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...zt,value:y,onChange:B=>z(B.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:cs}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null,t.jsx(pe,{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(pe,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:F,children:s("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[I?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(pe,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{g()},disabled:S||i,children:[t.jsx(X,{name:"scan-2",className:J("size-[18px]",S&&"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,u&&!j?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):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(B=>{const W=k===B.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-ring disabled:opacity-70",onClick:()=>{R(B.id),o.connect({id:B.id,candidates:B.candidates,clientToken:B.clientToken,label:B.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(X,{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:B.label}),t.jsx("span",{className:J("block truncate typography-small",W?"text-foreground":"text-muted-foreground"),children:W?s("mobile.connect.connecting"):B.candidates.some(re=>re.kind==="direct")?at(B):s("mobile.connect.relay.badge")})]}),W?t.jsx(X,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(X,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},B.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[I?t.jsxs("button",{type:"button",onClick:()=>P(B=>!B),"aria-expanded":j,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[t.jsx("span",{children:s("mobile.connect.manual.toggle")}),t.jsx(X,{name:"arrow-down-s",className:J("size-4 transition-transform duration-200",j&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:j?"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:D,children:[t.jsx("input",{...zt,value:f,onChange:B=>K(B.target.value),placeholder:s("mobile.connect.url.placeholder"),"aria-label":s("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:j?void 0:-1,className:J(cs,"text-center")}),t.jsx("input",{value:p,onChange:B=>b(B.target.value),placeholder:s("mobile.instances.label.placeholder"),"aria-label":s("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:j?void 0:-1,className:J(cs,"text-center")}),t.jsx("input",{...zt,value:h,onChange:B=>v(B.target.value),placeholder:s("mobile.connect.token.placeholder"),"aria-label":s("mobile.connect.token.label"),tabIndex:j?void 0:-1,autoCapitalize:"none",className:J(cs,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null,t.jsx(pe,{type:"submit",variant:I?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||S||!f.trim(),children:s(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})]})},Rc=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"},Pc=n=>{const e=le.c(12),{groups:s,displayMode:o,timeFormatPreference:r,className:i}=n;let a;e[0]!==i?(a=J("space-y-1.5",i),e[0]=i,e[1]=a):a=e[1];let u;if(e[2]!==o||e[3]!==s||e[4]!==r){let f;e[6]!==o||e[7]!==r?(f=l=>t.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-2.5",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Qo,{providerId:l.providerId,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground",children:l.providerName}),l.planLabel?t.jsx("span",{className:"shrink-0 typography-micro capitalize text-muted-foreground",children:l.planLabel}):null,l.status&&l.rows.length===0?t.jsx("span",{className:"shrink-0 truncate typography-micro text-muted-foreground",children:l.status}):null]}),l.rows.length>0?t.jsx("div",{className:"mt-1.5 space-y-1",children:l.rows.map(p=>{const b=o==="remaining"?p.window.remainingPercent:p.window.usedPercent,h=Zo(p.window.valueLabel,b),v=ei(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}),v?t.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground/70",children:v}):null]}),t.jsx("span",{className:J("shrink-0 typography-ui-label font-semibold tabular-nums",Rc(p.window)),children:h==="-"?"":h})]},p.key)})}):null,l.status&&l.rows.length>0?t.jsx("div",{className:"mt-1.5 typography-micro text-muted-foreground",children:l.status}):null]},l.providerId),e[6]=o,e[7]=r,e[8]=f):f=e[8],u=s.map(f),e[2]=o,e[3]=s,e[4]=r,e[5]=u}else u=e[5];let d;return e[9]!==a||e[10]!==u?(d=t.jsx("div",{className:a,children:u}),e[9]=a,e[10]=u,e[11]=d):d=e[11],d},br=380,Ac=(n,e)=>{if(!n||typeof n!="object")return;const s=n[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},tn=n=>n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(n),Tc="—",Ao=n=>{const e=le.c(20),{percentage:s}=n;let o,r,i,a,u,d,f;if(e[0]!==s){i=ii(s??0)??0;const h=ai(s??0);r=h==="critical"?"var(--status-error)":h==="warn"?"var(--status-warning)":"var(--status-success)",o=2*Math.PI*7.5,a="0 0 18 18",u="size-[18px] -rotate-90",d="progressbar",f=s===null?void 0:Math.round(i),e[0]=s,e[1]=o,e[2]=r,e[3]=i,e[4]=a,e[5]=u,e[6]=d,e[7]=f}else o=e[1],r=e[2],i=e[3],a=e[4],u=e[5],d=e[6],f=e[7];let l;e[8]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=l):l=e[8];let p;e[9]!==o||e[10]!==s||e[11]!==r||e[12]!==i?(p=s===null?null:t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:r,strokeWidth:3,strokeLinecap:"round",strokeDasharray:o,strokeDashoffset:o*(1-i/100),className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=o,e[10]=s,e[11]=r,e[12]=i,e[13]=p):p=e[13];let b;return e[14]!==a||e[15]!==u||e[16]!==d||e[17]!==f||e[18]!==p?(b=t.jsxs("svg",{viewBox:a,className:u,role:d,"aria-valuenow":f,"aria-valuemin":0,"aria-valuemax":100,children:[l,p]}),e[14]=a,e[15]=u,e[16]=d,e[17]=f,e[18]=p,e[19]=b):b=e[19],b},Ic=n=>{const e=le.c(13),{icon:s,iconNode:o,label:r,children:i}=n;let a;e[0]!==s||e[1]!==o?(a=o??(s?t.jsx(X,{name:s,className:"size-[18px]"}):null),e[0]=s,e[1]=o,e[2]=a):a=e[2];let u;e[3]!==a?(u=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:a}),e[3]=a,e[4]=u):u=e[4];let d;e[5]!==r?(d=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:r}),e[5]=r,e[6]=d):d=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 l;return e[9]!==u||e[10]!==d||e[11]!==f?(l=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[u,d,f]}),e[9]=u,e[10]=d,e[11]=f,e[12]=l):l=e[12],l},Dc=n=>{const e=le.c(53),{open:s,onClose:o,anchorRef:r,contextDisplay:i,usageGroups:a,usageDisplayMode:u,isUsageLoading:d,timeFormatPreference:f}=n,{t:l}=de(),p=c.useRef(null),[b,h]=c.useState(s),[v,S]=c.useState(!1),{enabled:w}=xn(),T=c.useRef(null),[N,E]=c.useState(null);let I,j;e[0]!==r||e[1]!==w||e[2]!==s||e[3]!==b?(I=()=>{if(!s||!w||!b)return;const U=()=>{const se=r.current?.getBoundingClientRect(),ae=T.current?.getBoundingClientRect();if(!se||!ae){E(null);return}const ue=se.left-ae.left,V=Math.min(Math.max(ue,8),Math.max(8,ae.width-br-8));E(V)};U();const Z=T.current;if(typeof ResizeObserver>"u"||!Z)return;const te=new ResizeObserver(U);return te.observe(Z),()=>te.disconnect()},j=[r,w,s,b],e[0]=r,e[1]=w,e[2]=s,e[3]=b,e[4]=I,e[5]=j):(I=e[4],j=e[5]),c.useLayoutEffect(I,j);const P=w&&N!==null;let k,R;e[6]!==s||e[7]!==b?(k=()=>{if(s){h(!0),S(!1);return}if(!b)return;S(!0);const U=window.setTimeout(()=>{h(!1),S(!1)},140);return()=>window.clearTimeout(U)},R=[s,b],e[6]=s,e[7]=b,e[8]=k,e[9]=R):(k=e[8],R=e[9]),c.useEffect(k,R);let y,z;e[10]!==o||e[11]!==s?(y=()=>{if(!s)return;const U=Z=>{Z.key==="Escape"&&o()};return document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)},z=[o,s],e[10]=o,e[11]=s,e[12]=y,e[13]=z):(y=e[12],z=e[13]),c.useEffect(y,z);let M,C;if(e[14]!==r||e[15]!==o||e[16]!==s?(M=()=>{if(!s)return;const U=Z=>{const te=Z.target;if(!(te instanceof Node)){o();return}p.current?.contains(te)||r.current?.contains(te)||o()};return document.addEventListener("pointerdown",U,!0),document.addEventListener("wheel",U,!0),()=>{document.removeEventListener("pointerdown",U,!0),document.removeEventListener("wheel",U,!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]),c.useEffect(M,C),!b)return null;let x;e[19]!==l?(x=l("mobile.header.openMetadataAria"),e[19]=l,e[20]=x):x=e[20];const D=P?"absolute origin-top-left":"mx-3 mt-2",K=v?"pointer-events-none":"pointer-events-auto";let g;e[21]!==D||e[22]!==K?(g=J("oc-surface-elevated overflow-y-auto overscroll-contain rounded-[20px] border border-border/70 bg-surface-elevated p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",D,K),e[21]=D,e[22]=K,e[23]=g):g=e[23];const L=`${v?"session-metadata-out":"session-metadata-in"} ${v?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let F;e[24]!==N||e[25]!==P?(F=P?{top:8,left:N??8,width:`min(${br}px, calc(100% - 16px))`}:null,e[24]=N,e[25]=P,e[26]=F):F=e[26];let B;e[27]!==L||e[28]!==F?(B={animation:L,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...F},e[27]=L,e[28]=F,e[29]=B):B=e[29];let W;e[30]!==i||e[31]!==l?(W=i?t.jsx(Ic,{iconNode:t.jsx(Ao,{percentage:i.state==="measured"?i.percentage:null}),label:l("mobile.header.metadata.context"),children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[i.state==="measured"?t.jsxs("span",{className:J("font-semibold",i.colorClass),children:[i.percentage.toFixed(1),"%"]}):null,t.jsx("span",{className:"text-muted-foreground",children:i.tokens})]})}):null,e[30]=i,e[31]=l,e[32]=W):W=e[32];let re;e[33]!==i?.state||e[34]!==l?(re=i?.state==="compacted"?t.jsx("p",{className:"px-2.5 pb-1 typography-meta text-muted-foreground",children:l("contextUsage.compacted.description")}):null,e[33]=i?.state,e[34]=l,e[35]=re):re=e[35];let ne;e[36]!==d||e[37]!==f||e[38]!==u||e[39]!==a?(ne=t.jsx(_c,{groups:a,displayMode:u,isLoading:d,timeFormatPreference:f}),e[36]=d,e[37]=f,e[38]=u,e[39]=a,e[40]=ne):ne=e[40];let ee;e[41]!==W||e[42]!==re||e[43]!==ne?(ee=t.jsxs("div",{className:"space-y-1",children:[W,re,ne]}),e[41]=W,e[42]=re,e[43]=ne,e[44]=ee):ee=e[44];let _;e[45]!==g||e[46]!==B||e[47]!==ee||e[48]!==x?(_=t.jsx("div",{ref:p,role:"dialog","aria-label":x,className:g,style:B,children:ee}),e[45]=g,e[46]=B,e[47]=ee,e[48]=x,e[49]=_):_=e[49];let G;e[50]===Symbol.for("react.memo_cache_sentinel")?(G=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[50]=G):G=e[50];let Y;return e[51]!==_?(Y=t.jsxs("div",{ref:T,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[_,G]}),e[51]=_,e[52]=Y):Y=e[52],Y},_c=n=>{const e=le.c(30),{groups:s,displayMode:o,isLoading:r,timeFormatPreference:i}=n,{t:a}=de();let u;e[0]!==o||e[1]!==a?(u=a(o==="remaining"?"header.services.remaining":"header.services.used"),e[0]=o,e[1]=a,e[2]=u):u=e[2];const d=u;if(s.length===0){if(!r)return null;let N;e[3]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(X,{name:"loader-4",className:"size-4 animate-spin","aria-hidden":!0}),e[3]=N):N=e[3];let E;e[4]!==a?(E=a("common.loading"),e[4]=a,e[5]=E):E=e[5];let I;return e[6]!==E?(I=t.jsxs("div",{className:"flex items-center justify-center gap-2 px-2.5 py-6 text-muted-foreground",children:[N,t.jsx("span",{className:"typography-ui-label",children:E})]}),e[6]=E,e[7]=I):I=e[7],I}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(X,{name:"timer",className:"size-[18px]"})}),e[8]=f):f=e[8];let l;e[9]!==a?(l=a("mobile.header.metadata.usage"),e[9]=a,e[10]=l):l=e[10];let p;e[11]!==l?(p=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:l}),e[11]=l,e[12]=p):p=e[12];let b;e[13]!==r?(b=r?t.jsx(X,{name:"refresh",className:"size-3.5 animate-spin"}):null,e[13]=r,e[14]=b):b=e[14];let h;e[15]!==d?(h=t.jsx("span",{className:"truncate",children:d}),e[15]=d,e[16]=h):h=e[16];let v;e[17]!==b||e[18]!==h?(v=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:[b,h]}),e[17]=b,e[18]=h,e[19]=v):v=e[19];let S;e[20]!==p||e[21]!==v?(S=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-2.5 pb-1.5",children:[f,p,v]}),e[20]=p,e[21]=v,e[22]=S):S=e[22];let w;e[23]!==o||e[24]!==s||e[25]!==i?(w=t.jsx(Pc,{groups:s,displayMode:o,timeFormatPreference:i}),e[23]=o,e[24]=s,e[25]=i,e[26]=w):w=e[26];let T;return e[27]!==S||e[28]!==w?(T=t.jsxs("div",{className:"pt-2.5",children:[S,w]}),e[27]=S,e[28]=w,e[29]=T):T=e[29],T},Mc=c.memo(function({open:e,onOpenChange:s,currentSessionId:o,effectiveDirectory:r,isNewSessionDraftOpen:i}){const{t:a}=de(),u=c.useRef(null),d=ti(o??"",r||void 0),f=Je(g=>g.providers),l=Je(g=>g.currentProviderId),p=Je(g=>g.currentModelId),b=Je(g=>g.getModelMetadata);Je(g=>g.modelsMetadata.size);const h=si(c.useCallback(g=>o?g.sessionModelSelections.get(o)??null:null,[o])),v=gt(g=>g.results),S=gt(g=>g.refreshErrors),w=c.useRef(!1),T=gt(g=>g.loadSettings),N=gt(g=>g.fetchAllQuotas),E=gt(g=>g.isLoading),I=gt(g=>g.displayMode),j=gt(g=>g.dropdownProviderIds),P=it(g=>g.timeFormatPreference);ni(),c.useEffect(()=>{T()},[T]),c.useEffect(()=>{tr(j)},[j]),c.useEffect(()=>{if(!e){w.current=!1;return}w.current||E||!j.some(L=>!v.some(F=>F.providerId===L)||S[L])||(w.current=!0,N())},[j,N,E,e,v,S]);const R=c.useMemo(()=>{for(let g=d.length-1;g>=0;g-=1){const L=d[g];if(L.role!=="user")continue;const F=typeof L.model?.providerID=="string"&&L.model.providerID.trim().length>0?L.model.providerID:void 0,B=typeof L.model?.modelID=="string"&&L.model.modelID.trim().length>0?L.model.modelID:void 0;if(F&&B)return{providerID:F,modelID:B}}return null},[d])??(h?{providerID:h.providerId,modelID:h.modelId}:null)??(l&&p?{providerID:l,modelID:p}:null),z=(R?f.find(g=>g.id===R.providerID):void 0)?.models.find(g=>g.id===R?.modelID),M=R?b(R.providerID,R.modelID):void 0,C=Ac(z?.limit,"context")??M?.limit?.context??0,x=c.useMemo(()=>ri(d),[d]),D=c.useMemo(()=>{if(i||!x||C<=0)return null;if(x.state==="compacted")return{state:"compacted",tokens:`${Tc}/${tn(C)}`};const g=Math.min(x.totalTokens/C*100,999),L=g>=90?"text-[var(--status-error)]":g>=75?"text-[var(--status-warning)]":"text-[var(--status-success)]";return{state:"measured",percentage:g,tokens:`${tn(x.totalTokens)}/${tn(C)}`,colorClass:L}},[x,C,i]),K=oi();return c.useEffect(()=>{!e||K.length===0||tr(K.map(g=>g.providerId))},[e,K]),t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:u,type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":a("mobile.header.openMetadataAria"),"aria-expanded":e,onClick:()=>s(g=>!g),style:{touchAction:"manipulation"},children:t.jsx(Ao,{percentage:D?.state==="compacted"?null:D?.percentage??0})}),t.jsx(Dc,{open:e,onClose:()=>s(!1),anchorRef:u,contextDisplay:D,usageGroups:K,usageDisplayMode:I,isUsageLoading:E,timeFormatPreference:P})]})}),zc=10,xr=380,Oc=(n,e)=>n.title?.trim()||e,Bc=n=>{const e=le.c(32),{session:s,meta:o,active:r,onSelect:i}=n,{t:a}=de(),u=Vr(s.id),d=Gr(s.id),f=u?.type??"idle",l=f==="busy"||f==="retry",p=!l&&d>0&&!r,b=Kr(s.id,l),h=(l||p)&&b,v=s.time?.updated??s.time?.created??0;let S;e[0]!==v?(S=ci(v),e[0]=v,e[1]=S):S=e[1];const w=S,T=r&&"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]";let N;e[2]!==T?(N=J("flex w-full items-center gap-3 rounded-xl px-2.5 py-2 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",T),e[2]=T,e[3]=N):N=e[3];let E;e[4]===Symbol.for("react.memo_cache_sentinel")?(E={touchAction:"manipulation"},e[4]=E):E=e[4];const I=r?"text-primary":"text-foreground";let j;e[5]!==I?(j=J("block truncate typography-ui-label",I),e[5]=I,e[6]=j):j=e[6];let P;e[7]!==s||e[8]!==a?(P=Oc(s,a("sessions.sidebar.session.untitled")),e[7]=s,e[8]=a,e[9]=P):P=e[9];let k;e[10]!==j||e[11]!==P?(k=t.jsx("span",{className:j,children:P}),e[10]=j,e[11]=P,e[12]=k):k=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]!==k?(y=t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[k,R]}),e[15]=R,e[16]=k,e[17]=y):y=e[17];let z;e[18]!==l||e[19]!==p?(z=l||p?t.jsx("span",{className:J("size-1.5 shrink-0 rounded-full",l?"bg-primary":"bg-[var(--status-info)]"),"aria-hidden":!0}):null,e[18]=l,e[19]=p,e[20]=z):z=e[20];let M;e[21]!==l||e[22]!==s.id||e[23]!==h||e[24]!==w?(M=h?t.jsx(io,{sessionId:s.id,running:l,className:"typography-micro"}):w?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:w}):null,e[21]=l,e[22]=s.id,e[23]=h,e[24]=w,e[25]=M):M=e[25];let C;return e[26]!==i||e[27]!==y||e[28]!==z||e[29]!==M||e[30]!==N?(C=t.jsxs("button",{type:"button",className:N,onClick:i,style:E,children:[y,z,M]}),e[26]=i,e[27]=y,e[28]=z,e[29]=M,e[30]=N,e[31]=C):C=e[31],C},Lc=n=>{const e=le.c(50),{open:s,onClose:o,anchorRef:r}=n,{t:i}=de(),a=c.useRef(null),[u,d]=c.useState(s),[f,l]=c.useState(!1),{enabled:p}=xn(),b=c.useRef(null),[h,v]=c.useState(null);let S,w;e[0]!==r||e[1]!==p||e[2]!==s||e[3]!==u?(S=()=>{if(!s||!p||!u)return;const U=()=>{const se=r.current?.getBoundingClientRect(),ae=b.current?.getBoundingClientRect();if(!se||!ae){v(null);return}const ue=se.left-ae.left;v(Math.min(Math.max(ue,8),Math.max(8,ae.width-xr-8)))};U();const Z=b.current;if(typeof ResizeObserver>"u"||!Z)return;const te=new ResizeObserver(U);return te.observe(Z),()=>te.disconnect()},w=[r,p,s,u],e[0]=r,e[1]=p,e[2]=s,e[3]=u,e[4]=S,e[5]=w):(S=e[4],w=e[5]),c.useLayoutEffect(S,w);const T=p&&h!==null,N=Ne($c),E=Ne(Fc),I=We(Wc);let j;e[6]===Symbol.for("react.memo_cache_sentinel")?(j={maxParents:zc},e[6]=j):j=e[6];const P=li(s||u,j);let k,R;e[7]!==s||e[8]!==u?(k=()=>{if(s){yn(),d(!0),l(!1);return}if(!u)return;l(!0);const U=window.setTimeout(()=>{d(!1),l(!1)},140);return()=>window.clearTimeout(U)},R=[s,u],e[7]=s,e[8]=u,e[9]=k,e[10]=R):(k=e[9],R=e[10]),c.useEffect(k,R);let y,z;e[11]!==o||e[12]!==s?(y=()=>{if(!s)return;const U=Z=>{Z.key==="Escape"&&o()};return document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)},z=[o,s],e[11]=o,e[12]=s,e[13]=y,e[14]=z):(y=e[13],z=e[14]),c.useEffect(y,z);let M,C;e[15]!==r||e[16]!==o||e[17]!==s?(M=()=>{if(!s)return;const U=Z=>{const te=Z.target;if(!(te instanceof Node)){o();return}a.current?.contains(te)||r.current?.contains(te)||o()};return document.addEventListener("pointerdown",U,!0),()=>document.removeEventListener("pointerdown",U,!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]),c.useEffect(M,C);let x;e[20]!==o||e[21]!==E?(x=U=>{E(U.id,bn(U)),o()},e[20]=o,e[21]=E,e[22]=x):x=e[22];const D=x;if(!u)return null;let K;e[23]!==i?(K=i("sessions.switcher.openAria"),e[23]=i,e[24]=K):K=e[24];const g=T?"absolute origin-top-left":"mx-3 mt-2",L=f?"pointer-events-none":"pointer-events-auto";let F;e[25]!==g||e[26]!==L?(F=J("oc-surface-elevated flex flex-col overflow-hidden rounded-[20px] border border-border/70 bg-surface-elevated p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",g,L),e[25]=g,e[26]=L,e[27]=F):F=e[27];const B=`${f?"session-switcher-out":"session-switcher-in"} ${f?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let W;e[28]!==h||e[29]!==T?(W=T?{top:8,left:h??8,width:`min(${xr}px, calc(100% - 16px))`}:null,e[28]=h,e[29]=T,e[30]=W):W=e[30];let re;e[31]!==B||e[32]!==W?(re={animation:B,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...W},e[31]=B,e[32]=W,e[33]=re):re=e[33];let ne;e[34]!==N||e[35]!==D||e[36]!==P||e[37]!==I||e[38]!==i?(ne=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(U=>{const Z=U.node.session,te=[U.secondaryMeta?.projectLabel,U.secondaryMeta?.branchLabel].filter(Boolean).join(" · ");return t.jsx(Bc,{session:Z,meta:te,active:Z.id===N,onSelect:()=>{U.projectId&&I(U.projectId),D(Z)}},Z.id)}),e[34]=N,e[35]=D,e[36]=P,e[37]=I,e[38]=i,e[39]=ne):ne=e[39];let ee;e[40]!==ne?(ee=t.jsx("div",{className:"oc-hide-scrollbar min-h-0 flex-1 space-y-0.5 overflow-y-auto overscroll-contain",children:ne}),e[40]=ne,e[41]=ee):ee=e[41];let _;e[42]!==K||e[43]!==F||e[44]!==re||e[45]!==ee?(_=t.jsx("div",{ref:a,role:"dialog","aria-label":K,className:F,style:re,children:ee}),e[42]=K,e[43]=F,e[44]=re,e[45]=ee,e[46]=_):_=e[46];let G;e[47]===Symbol.for("react.memo_cache_sentinel")?(G=t.jsx("style",{children:`
14
- @keyframes session-switcher-in {
15
- from { opacity: 0; transform: translateY(-8px) scale(0.985); }
16
- to { opacity: 1; transform: translateY(0) scale(1); }
17
- }
18
- @keyframes session-switcher-out {
19
- from { opacity: 1; transform: translateY(0) scale(1); }
20
- to { opacity: 0; transform: translateY(-6px) scale(0.985); }
21
- }
22
- `}),e[47]=G):G=e[47];let Y;return e[48]!==_?(Y=t.jsxs("div",{ref:b,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[_,G]}),e[48]=_,e[49]=Y):Y=e[49],Y};function $c(n){return n.currentSessionId}function Fc(n){return n.setCurrentSession}function Wc(n){return n.setActiveProjectIdOnly}const Uc=n=>{const e=le.c(78),{onOpenSessions:s,onOpenWorkspace:o,compactTitle:r}=n,i=r===void 0?!1:r,{t:a}=de(),[u,d]=c.useState(!1),[f,l]=c.useState(!1),p=c.useRef(null),b=yt(Vc),h=Ne(Gc);let v;e[0]!==h?(v=Ce=>h?Ce.getDirectoryForSession(h):null,e[0]=h,e[1]=v):v=e[1];const w=Ne(v)||b,T=ui(h,w||void 0),N=Ne(Kc),E=Hr(w||null);let I;e[2]!==w||e[3]!==E?(I=Ce=>{if(!w||E!==!0)return!1;const Ee=Ce.directories.get(w)?.status;return!!(Ee&&!Ee.isClean)},e[2]=w,e[3]=E,e[4]=I):I=e[4];const j=He(I);let P;e[5]!==T?.title?(P=T?.title?.trim(),e[5]=T?.title,e[6]=P):P=e[6];const k=P;let R;e[7]!==h||e[8]!==k||e[9]!==a?(R=k||a(h?"mobile.sessions.untitled":"sessions.switcher.draftTitle"),e[7]=h,e[8]=k,e[9]=a,e[10]=R):R=e[10];const y=R;let z;e[11]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{d(!1),l(!1)},e[11]=z):z=e[11];let M;e[12]!==h||e[13]!==w?(M=[h,w],e[12]=h,e[13]=w,e[14]=M):M=e[14],c.useEffect(z,M);let C;e[15]!==s?(C=()=>{d(!1),l(!1),s()},e[15]=s,e[16]=C):C=e[16];const x=C;let D;e[17]===Symbol.for("react.memo_cache_sentinel")?(D=Ce=>{d(Ee=>{const we=typeof Ce=="function"?Ce(Ee):Ce;return we&&l(!1),we})},e[17]=D):D=e[17];const K=D;let g;e[18]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{l(Ce=>{const Ee=!Ce;return Ee&&d(!1),Ee})},e[18]=g):g=e[18];const L=g;let F;e[19]===Symbol.for("react.memo_cache_sentinel")?(F={paddingTop:"var(--oc-safe-area-top, 0px)"},e[19]=F):F=e[19];let B;e[20]!==a?(B=a("mobile.sessions.openSheetAria"),e[20]=a,e[21]=B):B=e[21];let W,re;e[22]===Symbol.for("react.memo_cache_sentinel")?(W={touchAction:"manipulation"},re=t.jsx(X,{name:"list-unordered",className:"size-5"}),e[22]=W,e[23]=re):(W=e[22],re=e[23]);let ne;e[24]!==x||e[25]!==B?(ne=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":B,onClick:x,style:W,children:re}),e[24]=x,e[25]=B,e[26]=ne):ne=e[26];const ee=i?"shrink":"flex-1";let _;e[27]!==ee?(_=J("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",ee),e[27]=ee,e[28]=_):_=e[28];let G;e[29]!==a?(G=a("sessions.switcher.openAria"),e[29]=a,e[30]=G):G=e[30];let Y;e[31]===Symbol.for("react.memo_cache_sentinel")?(Y={touchAction:"manipulation"},e[31]=Y):Y=e[31];let U;e[32]!==y?(U=t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:y}),e[32]=y,e[33]=U):U=e[33];const Z=f&&"rotate-180";let te;e[34]!==Z?(te=J("size-4 shrink-0 text-muted-foreground transition-transform duration-150",Z),e[34]=Z,e[35]=te):te=e[35];let se;e[36]!==te?(se=t.jsx(X,{name:"arrow-down-s",className:te}),e[36]=te,e[37]=se):se=e[37];let ae;e[38]!==U||e[39]!==se?(ae=t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[U,se]}),e[38]=U,e[39]=se,e[40]=ae):ae=e[40];let ue;e[41]!==f||e[42]!==_||e[43]!==G||e[44]!==ae?(ue=t.jsx("button",{ref:p,type:"button",className:_,"aria-label":G,"aria-haspopup":"dialog","aria-expanded":f,onClick:L,style:Y,children:ae}),e[41]=f,e[42]=_,e[43]=G,e[44]=ae,e[45]=ue):ue=e[45];let V;e[46]!==i?(V=i?t.jsx("div",{className:"min-w-0 flex-1"}):null,e[46]=i,e[47]=V):V=e[47];let ie;e[48]!==h||e[49]!==w||e[50]!==N||e[51]!==u?(ie=t.jsx(Mc,{open:u,onOpenChange:K,currentSessionId:h,effectiveDirectory:w,isNewSessionDraftOpen:N}),e[48]=h,e[49]=w,e[50]=N,e[51]=u,e[52]=ie):ie=e[52];let ye;e[53]!==j||e[54]!==a?(ye=a(j?"mobile.header.openWorkspaceWithChangesAria":"mobile.header.openWorkspaceAria"),e[53]=j,e[54]=a,e[55]=ye):ye=e[55];let ke;e[56]!==o?(ke=()=>{d(!1),l(!1),o()},e[56]=o,e[57]=ke):ke=e[57];let q,ve;e[58]===Symbol.for("react.memo_cache_sentinel")?(q={touchAction:"manipulation"},ve=t.jsx(X,{name:"pencil-ruler-2",className:"size-5"}),e[58]=q,e[59]=ve):(q=e[58],ve=e[59]);let Re;e[60]!==j?(Re=j?t.jsx("span",{className:"absolute right-1.5 top-1.5 size-2.5 rounded-full border-2 border-[var(--background)] bg-[var(--status-warning)]","aria-hidden":!0}):null,e[60]=j,e[61]=Re):Re=e[61];let De;e[62]!==ye||e[63]!==ke||e[64]!==Re?(De=t.jsxs("button",{type:"button",className:"relative flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":ye,onClick:ke,style:q,children:[ve,Re]}),e[62]=ye,e[63]=ke,e[64]=Re,e[65]=De):De=e[65];let _e;e[66]!==ne||e[67]!==ue||e[68]!==V||e[69]!==ie||e[70]!==De?(_e=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:F,children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[ne,ue,V,ie,De]})}),e[66]=ne,e[67]=ue,e[68]=V,e[69]=ie,e[70]=De,e[71]=_e):_e=e[71];let Ue;e[72]===Symbol.for("react.memo_cache_sentinel")?(Ue=()=>l(!1),e[72]=Ue):Ue=e[72];let Me;e[73]!==f?(Me=t.jsx(Lc,{open:f,onClose:Ue,anchorRef:p}),e[73]=f,e[74]=Me):Me=e[74];let Fe;return e[75]!==_e||e[76]!==Me?(Fe=t.jsxs(t.Fragment,{children:[_e,Me]}),e[75]=_e,e[76]=Me,e[77]=Fe):Fe=e[77],Fe};function Vc(n){return n.currentDirectory}function Gc(n){return n.currentSessionId}function Kc(n){return!!n.newSessionDraft?.open}const Hc=({onActiveConnectionDeleted:n,onConnect:e})=>{const{t:s}=de(),o=jo(e),{connections:r,isBusy:i,isPasswordBusy:a,error:u,pendingConnection:d,connect:f,submitPassword:l,cancelPassword:p,saveConnection:b,removeConnection:h,setError:v}=o,[S,w]=c.useState(null),T=S?r.find(V=>V.id===S)??null:null,[N,E]=c.useState(null),[I,j]=c.useState(""),[P,k]=c.useState(""),[R,y]=c.useState(""),[z,M]=c.useState(""),[C,x]=c.useState(!1),[D,K]=c.useState(!1),g=c.useRef(null),L=c.useMemo(()=>fn(),[]),[F,B]=c.useState(!1),[W,re]=c.useState(null),[ne,ee]=c.useState(!1),_=fo(c.useCallback(()=>ee(!0),[])),G=c.useCallback(()=>{w(null),j(""),k(""),y(""),v(null),B(!1)},[v]),Y=c.useCallback(V=>{V.preventDefault(),b({id:S??void 0,url:I,label:P,clientToken:R}).then(ie=>{ie&&G()})},[R,S,P,G,b,I]),U=c.useCallback(async()=>{if(g.current)return;v(null),x(!0);const V=new AbortController;g.current=V;try{const ie=await Eo({signal:V.signal});switch(g.current===V&&(g.current=null,x(!1)),ie.status){case"ok":j(ie.url),ie.label&&k(ie.label),ie.clientToken&&y(ie.clientToken),B(!0);break;case"pairing":K(!0),await o.redeemPairingConnection(ie.pairing);break;case"permission-denied":v(s("mobile.connect.scan.permissionDenied"));break;case"invalid":v(s("mobile.connect.scan.invalid"));break;case"unsupported":v(s("mobile.connect.scan.unsupported"));break;case"failed":v(s("mobile.connect.scan.failed"));break;default:break}}finally{K(!1),g.current===V&&(g.current=null,x(!1))}},[o,v,s]);c.useEffect(()=>()=>g.current?.abort(),[]);const Z=c.useCallback(V=>{V.preventDefault(),l(z)},[z,l]),te=c.useCallback(()=>{M(""),p()},[p]),se=c.useCallback(V=>{E(ie=>ie===V?null:V)},[]),ae=c.useCallback(V=>{E(null),S===V&&G();const ie=r.length===1;h(V).then(ye=>{ye&&(ie||gr(ye))&&n()})},[r.length,S,n,h,G]),ue=cs;return d?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(X,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:d.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:d.candidates.some(V=>V.kind==="direct")?at(d):s("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...zt,value:z,onChange:V=>M(V.target.value),placeholder:s("mobile.connect.password.placeholder"),"aria-label":s("mobile.connect.password.label"),type:"password",autoFocus:!0,className:ue}),u?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:u}):null,t.jsx(pe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!z.trim(),children:s(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(pe,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:te,children:s("mobile.connect.cancelPassword")})]})})}):t.jsxs(t.Fragment,{children:[C?t.jsx(Ro,{onCancel:()=>g.current?.abort()}):null,D?t.jsx(Po,{}):null,ne?t.jsx(ko,{onClose:()=>ee(!1)}):null,t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[r.length>0?t.jsx("div",{..._,className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(V=>{const ie=N===V.id,ye=gr(V),ke=W===V.id,q=ke?s("mobile.connect.connecting"):ye?gs()?s("mobile.instances.status.connectedRelay"):s("mobile.instances.status.connectedDirect"):V.candidates.some(ve=>ve.kind==="direct")?at(V):s("mobile.connect.relay.badge");return t.jsxs("div",{className:J("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-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:opacity-60",onClick:()=>{ye||(re(V.id),f({id:V.id,candidates:V.candidates,clientToken:V.clientToken,label:V.label}).finally(()=>re(null)))},disabled:i&&!ke||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(X,{name:"server",className:"size-[18px]"}),ye?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:V.label}),t.jsx("span",{className:J("block truncate typography-small",ye&&!ke?"text-[var(--status-success)]":"text-muted-foreground"),children:q})]}),ke?t.jsx(X,{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:V.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:()=>ae(V.id),style:{touchAction:"manipulation"},children:[t.jsx(X,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:s("mobile.instances.delete")})]}):V.candidates.some(ve=>ve.kind==="direct")?t.jsx("button",{type:"button","aria-label":s("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>{w(V.id),j(at(V)),k(V.label),y(V.clientToken||""),v(null)},style:{touchAction:"manipulation"},children:t.jsx(X,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":ie?s("mobile.instances.cancelDeleteAria",{label:V.label}):s("mobile.instances.deleteAria",{label:V.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>se(V.id),style:{touchAction:"manipulation"},children:t.jsx(X,{name:ie?"close":"delete-bin",className:"size-[18px]"})})]})]},V.id)})}):t.jsx("p",{..._,className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:s("mobile.connect.saved.empty")}),!F&&!T?t.jsxs("div",{className:"space-y-2",children:[L?t.jsxs(pe,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{U()},disabled:C,children:[t.jsx(X,{name:"scan-2",className:J("size-[18px]",C&&"animate-pulse")}),s("mobile.connect.scanQr")]}):null,t.jsxs(pe,{type:"button",variant:L?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{v(null),B(!0)},children:[t.jsx(X,{name:"add",className:"size-[18px]"}),s("mobile.instances.addManual")]}),u?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:u}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:Y,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(T?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(pe,{type:"button",variant:"ghost",size:"xs",onClick:G,children:s("mobile.instances.cancelEdit")})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.url.label")}),t.jsx("input",{...zt,value:I,onChange:V=>j(V.target.value),placeholder:s("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:ue})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.instances.label.label")}),t.jsx("input",{value:P,onChange:V=>k(V.target.value),placeholder:s("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:ue})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:s("mobile.connect.token.label")}),t.jsx("input",{...zt,value:R,onChange:V=>y(V.target.value),placeholder:s("mobile.connect.token.placeholder"),autoCapitalize:"none",className:ue}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:s("mobile.connect.token.hint")})]}),u?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:u}):null,t.jsx(pe,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:s(T?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})]})},Te=n=>Wo(n)??"",sn=n=>{const e=Te(n);if(!e)return"";const s=e.split("/").filter(Boolean);return s[s.length-1]?.replace(/[-_]/g," ")||e},yr=_n(n=>({expandedParents:{},toggleParent:e=>n(s=>{const o={...s.expandedParents};return o[e]?delete o[e]:o[e]=!0,{expandedParents:o}})})),Ps=_n()(lo(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"})),mn=_n()(lo(n=>({orderByProject:{},setWorktreeOrder:(e,s)=>n(o=>({orderByProject:{...o.orderByProject,[e]:s}}))}),{name:"mobile-worktree-order"})),vr=n=>n.replace(/\\/g,"/").replace(/\/+$/,""),qc=(n,e)=>{if(!n||n.length===0)return e;const s=new Map(n.map((r,i)=>[vr(r),i])),o=r=>s.get(vr(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)},us=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Jc=n=>{const e=n;return us(e.directory??e.project?.worktree??null)},To=({open:n,project:e,worktree:s,onClose:o,onDeleted:r})=>{const{t:i}=de(),a=qr(),u=gn(y=>y.activeSessions),d=Ne(y=>y.archiveSessions),f=yt(y=>y.currentDirectory),[l,p]=c.useState(!1),[b,h]=c.useState(!1),[v,S]=c.useState(!1),[w,T]=c.useState(!1),N=us(s?.path),E=typeof s?.branch=="string"&&s.branch.trim().length>0,I=c.useMemo(()=>{if(!N)return[];const y=new Map;for(const z of[...u,...a])Jc(z)===N&&y.set(z.id,z);return Array.from(y.values())},[u,a,N]);c.useEffect(()=>{if(!n){p(!1),h(!1),S(!1),T(!1);return}if(!s?.path)return;let y=!1;return di(s.path).then(z=>{y||S(!!z?.isDirty)}).catch(()=>{y||S(!!s.status?.isDirty)}),()=>{y=!0}},[n,s?.path,s?.status?.isDirty]);const j=c.useCallback((y,z)=>{const M=fi(y),C=ce.loading(i("sessions.sidebar.sessionDialogs.worktree.removingTitle",{name:M}));(async()=>{try{if(z.length>0){const{failedIds:x}=await d(z);if(x.length>0){ce.error(x.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:x.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:x.length}),{id:C,description:i("sessions.sidebar.dialogs.deleteResult.tryAgain")});return}}await mi(e,y,{deleteRemoteBranch:E&&b,deleteLocalBranch:E&&l}),us(f)===N&&us(e.path)&&yt.getState().setDirectory(us(e.path),{showOverlay:!1}),ce.success(i("sessions.sidebar.sessionDialogs.worktree.removedTitle",{name:M}),{id:C,description:i(E&&b?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),r?.()}catch(x){ce.error(i("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle",{name:M}),{id:C,description:x instanceof Error?x.message:i("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[d,f,l,b,E,r,e,i,N]),P=()=>{!s||w||(T(!0),j(s,I.map(y=>y.id)),o())};if(!s)return null;const k=s.branch||s.label||s.path,R=(y,z,M,C)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":y,disabled:C,onClick:()=>z(!y),className:J("flex w-full items-center justify-between gap-3 rounded-xl border border-border/70 px-3.5 py-3 text-left transition-colors","hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",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:J("relative h-6 w-10 shrink-0 rounded-full transition-colors",y?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:J("absolute top-0.5 size-5 rounded-full bg-white transition-transform",y?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(Jr,{open:n,onClose:o,title:i("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(pe,{variant:"ghost",className:"flex-1",onClick:o,disabled:w,children:i("projectEditDialog.actions.cancel")}),t.jsx(pe,{variant:"destructive",className:"flex-1",onClick:()=>{P()},disabled:w,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:k})}),v?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,I.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.deleteWorktreeArchiveNote",{count:I.length})}):null,E?t.jsxs("div",{className:"flex flex-col gap-2",children:[R(l,p,i("mobile.projectEdit.deleteLocalBranch"),w),R(b,h,i("mobile.projectEdit.deleteRemoteBranch"),w)]}):null]})})},wr="mobile-surface-root",nn=16,As=200,Yc=()=>{if(typeof document>"u")return null;let n=document.getElementById(wr);return n||(n=document.createElement("div"),n.id=wr,document.body.appendChild(n)),n},ds=({open:n,onClose:e,title:s,subtitle:o,trailing:r,disableEscapeDismiss:i=!1,headerless:a=!1,noHeaderBorder:u=!1,ariaLabel:d,variant:f="fullscreen",dialogAlign:l="chat",children:p})=>{const{t:b}=de(),h=c.useRef(null),[v,S]=c.useState(!1),[w,T]=c.useState(!1),N=c.useRef(null),E=c.useRef(null),I=c.useRef(e);if(c.useEffect(()=>{I.current=e},[e]),typeof document<"u"&&!h.current&&(h.current=Yc()),c.useEffect(()=>{if(!n){S(!1);return}const k=window.setTimeout(()=>S(!0),nn);return()=>window.clearTimeout(k)},[n]),c.useEffect(()=>{if(!n){T(!1);return}const k=window.setTimeout(()=>T(!0),nn+As+80);return()=>window.clearTimeout(k)},[n]),c.useEffect(()=>{if(!n)return;const k=document.body.style.overflow;E.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const R=()=>{const M=N.current;if(!M)return;(M.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??M).focus({preventScroll:!0})},y=window.setTimeout(R,nn),z=M=>{if(M.key==="Escape"&&!i){I.current();return}if(M.key!=="Tab")return;const C=N.current;if(!C)return;const x=Array.from(C.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(L=>!L.hasAttribute("disabled")&&L.getAttribute("aria-hidden")!=="true");if(x.length===0){M.preventDefault(),C.focus({preventScroll:!0});return}const D=x[0],K=x[x.length-1],g=document.activeElement;M.shiftKey&&g===D?(M.preventDefault(),K.focus({preventScroll:!0})):!M.shiftKey&&g===K&&(M.preventDefault(),D.focus({preventScroll:!0}))};return document.addEventListener("keydown",z),()=>{window.clearTimeout(y),document.body.style.overflow=k,document.removeEventListener("keydown",z),E.current?.focus?.({preventScroll:!0}),E.current=null}},[i,n]),!n||!h.current)return null;const j=f==="dialog",P=t.jsxs("section",{ref:N,role:"dialog","aria-modal":"true","aria-label":d,tabIndex:-1,className:J("flex flex-col bg-background text-foreground",j?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50"),style:j?{opacity:v?1:0,transform:v?"none":"scale(0.97)",transition:`opacity ${As}ms ease-out, transform ${As}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:v?"none":"translateX(100%)",transition:`transform ${As}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:k=>{v&&k.target===k.currentTarget&&k.propertyName==="transform"&&T(!0)},children:[a?null:t.jsxs("header",{className:J("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!u&&"border-b border-border/70"),children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":b("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(X,{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:w?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 j?Ot.createPortal(t.jsx("div",{className:"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:v?1:0,paddingLeft:l==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:l==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:e,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:k=>k.stopPropagation(),children:P})}),h.current):Ot.createPortal(P,h.current)},Xc=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/,""),Qc=n=>{const e=le.c(36),{worktree:s,onDelete:o}=n,{t:r}=de();let i;e[0]!==s.path?(i={id:s.path},e[0]=s.path,e[1]=i):i=e[1];const{attributes:a,listeners:u,setNodeRef:d,transform:f,transition:l,isDragging:p}=In(i);let b;e[2]!==f?(b=Dn.Transform.toString(f),e[2]=f,e[3]=b):b=e[3];const h=p?10:1;let v;e[4]!==b||e[5]!==h||e[6]!==l?(v={transform:b,transition:l,zIndex:h},e[4]=b,e[5]=h,e[6]=l,e[7]=v):v=e[7];const S=v,w=s.branch||s.label||s.path,T=p&&"shadow-lg shadow-black/20";let N;e[8]!==T?(N=J("flex items-center gap-1 rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",T),e[8]=T,e[9]=N):N=e[9];let E;e[10]!==w||e[11]!==r?(E=r("mobile.projectEdit.dragWorktreeAria",{label:w}),e[10]=w,e[11]=r,e[12]=E):E=e[12];let I;e[13]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx(jn,{className:"size-4"}),e[13]=I):I=e[13];let j;e[14]!==a||e[15]!==u||e[16]!==E?(j=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,...u,children:I}),e[14]=a,e[15]=u,e[16]=E,e[17]=j):j=e[17];let P;e[18]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(X,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=P):P=e[18];let k;e[19]!==w?(k=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:w}),e[19]=w,e[20]=k):k=e[20];let R;e[21]!==w||e[22]!==r?(R=r("mobile.projectEdit.deleteWorktreeAria",{label:w}),e[21]=w,e[22]=r,e[23]=R):R=e[23];let y,z;e[24]===Symbol.for("react.memo_cache_sentinel")?(y={touchAction:"manipulation"},z=t.jsx(Ms,{className:"size-4"}),e[24]=y,e[25]=z):(y=e[24],z=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:z}),e[26]=o,e[27]=R,e[28]=M):M=e[28];let C;return e[29]!==d||e[30]!==S||e[31]!==k||e[32]!==M||e[33]!==N||e[34]!==j?(C=t.jsxs("div",{ref:d,style:S,className:N,children:[j,P,k,M]}),e[29]=d,e[30]=S,e[31]=k,e[32]=M,e[33]=N,e[34]=j,e[35]=C):C=e[35],C},Zc=({open:n,project:e,onClose:s,onWorktreesChanged:o})=>{const{t:r}=de(),{currentTheme:i}=Yr(),a=We(g=>g.updateProjectMeta),u=We(g=>g.discoverProjectIcon),d=We(g=>g.removeProjectIcon),f=mn(g=>g.setWorktreeOrder),l=We(g=>e?g.projects.find(L=>L.id===e.id)?.iconImage??null:null),[p,b]=c.useState(""),[h,v]=c.useState(null),[S,w]=c.useState(null),[T,N]=c.useState(!1),[E,I]=c.useState([]),[j,P]=c.useState(null),k=e?.id??null;c.useEffect(()=>{!n||!e||(b(e.label),v(e.icon??null),w(e.color??null),I(e.worktrees))},[n,k]),c.useEffect(()=>{!n||!e||I(g=>{const L=e.worktrees.map(W=>W.path),F=g.map(W=>W.path);return L.length===F.length&&L.every(W=>F.includes(W))?g:e.worktrees})},[e?.worktrees]);const R=Sn(Lt(Cn,{activationConstraint:{distance:8}}),Lt(Nn,{coordinateGetter:Pn})),y=()=>{if(!e)return;const g=p.trim();a(e.id,{label:g||e.label,icon:h,color:S}),s()},z=()=>{!e||T||(N(!0),u(e.id).then(g=>{if(!g.ok){ce.error(g.error||r("projectEditDialog.toast.failedToDiscoverIcon"));return}if(g.skipped){ce.success(r("projectEditDialog.toast.customIconAlreadySet"));return}ce.success(r("projectEditDialog.toast.iconDiscovered"))}).finally(()=>N(!1)))},M=()=>{e&&d(e.id).then(g=>{if(!g.ok){ce.error(g.error||r("projectEditDialog.toast.failedToRemoveIcon"));return}ce.success(r("projectEditDialog.toast.iconRemoved"))})},C=g=>{const{active:L,over:F}=g;if(!F||L.id===F.id||!e)return;const B=E.findIndex(ee=>ee.path===L.id),W=E.findIndex(ee=>ee.path===F.id);if(B<0||W<0)return;const re=[...E],[ne]=re.splice(B,1);re.splice(W,0,ne),I(re),f(e.id,re.map(ee=>Xc(ee.path)))},x=S?Xr[S]??null:null,D=h?Qr[h]:null,K=!!l;return t.jsxs(t.Fragment,{children:[t.jsx(ds,{open:n,onClose:s,title:r("projectEditDialog.title"),ariaLabel:r("projectEditDialog.title"),noHeaderBorder:!0,trailing:t.jsxs(pe,{type:"button",variant:"default",size:"sm","aria-label":r("projectEditDialog.actions.save"),onClick:y,disabled:!p.trim(),style:{touchAction:"manipulation"},children:[t.jsx(ao,{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:K?t.jsx(Zr,{project:{id:e.id,iconImage:l},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(cn,{className:"size-7"})}):D?t.jsx(X,{name:D,className:"size-7",style:x?{color:x}:void 0}):t.jsx(cn,{className:"size-7",style:x?{color:x}:void 0})})}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.name")}),t.jsx(eo,{value:p,onChange:g=>b(g.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:()=>w(null),"aria-label":r("projectEditDialog.option.none"),className:J("flex size-9 items-center justify-center rounded-xl border-2 transition-all",S===null?"border-foreground":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),pi.map(g=>t.jsx("button",{type:"button",onClick:()=>w(g.key),"aria-label":g.label,title:g.label,className:J("size-9 rounded-xl border-2 transition-all",S===g.key?"border-foreground":"border-transparent hover:border-border/70"),style:{backgroundColor:g.cssVar,touchAction:"manipulation"}},g.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:()=>v(null),"aria-label":r("projectEditDialog.option.none"),className:J("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"})}),hi.map(g=>t.jsx("button",{type:"button",onClick:()=>v(g.key),"aria-label":g.label,title:g.label,className:J("flex size-9 items-center justify-center rounded-xl border-2 transition-all",h===g.key?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx(X,{name:g.Icon,className:"size-4",style:x?{color:x}:void 0})},g.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(pe,{size:"sm",variant:"outline",onClick:z,disabled:T,children:r(T?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),K?t.jsx(pe,{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(En,{sensors:R,collisionDetection:Rn,onDragEnd:C,children:t.jsx(An,{items:E.map(g=>g.path),strategy:Tn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:E.map(g=>t.jsx(Qc,{worktree:g,onDelete:()=>P(g)},g.path))})})})]})]}):null]}):null}),e?t.jsx(To,{open:!!j,project:{id:e.id,path:e.path},worktree:j,onClose:()=>P(null),onDeleted:()=>{I(g=>g.filter(L=>L.path!==j?.path)),o?.()}}):null]})},eu=32,tu=80,su=64,nu=.7,Wn=(n,e)=>{const s=c.useRef(e);s.current=e;const o=e.enabled??!0;c.useEffect(()=>{if(!o)return;const r=n.current;if(!r)return;const a=window.Capacitor?.getPlatform?.()==="android"?tu:eu;let u=!1,d=!1,f=0,l=0;const p=h=>{if(h.touches.length!==1){u=!1;return}const v=h.touches[0],S=r.clientWidth,w=v.clientX<=a,T=v.clientX>=S-a;u=w||T,d=w,f=v.clientX,l=v.clientY},b=h=>{if(!u)return;u=!1;const v=h.changedTouches[0];if(!v)return;const S=v.clientX-f,w=v.clientY-l;Math.abs(S)<su||Math.abs(w)>Math.abs(S)*nu||d&&S<=0||!d&&S>=0||(d?s.current.onLeftEdgeSwipe?.():s.current.onRightEdgeSwipe?.())};return r.addEventListener("touchstart",p,{passive:!0}),r.addEventListener("touchend",b,{passive:!0}),()=>{r.removeEventListener("touchstart",p),r.removeEventListener("touchend",b)}},[o,n])},ru=new Set,ou=[["manual","sessions.sidebar.header.projectSort.manual"],["a-z","sessions.sidebar.header.projectSort.aToZ"],["z-a","sessions.sidebar.header.projectSort.zToA"],["date-added","sessions.sidebar.header.projectSort.dateAdded"],["recent","sessions.sidebar.header.projectSort.recent"]],rn=7,Ts=40,iu=16,Rt=n=>n.parentID??null,fs=n=>{const e=n;return Te(e.directory??e.project?.worktree??null)},au=n=>{const e=n.time?.updated??n.time?.created,s=typeof e=="number"?e:Number(e);return Number.isFinite(s)&&s>0?s:0},lu=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))},cu=(n,e)=>{const s=Te(n),o=Te(e),r=o.endsWith("/")?o:`${o}/`;return!!(s&&o&&(s===o||s.startsWith(r)))},_s=(n,e)=>n.worktrees.find(s=>Te(s.path)===e)??null,Io=(n,e)=>e===n.path||!!_s(n,e),on=(n,e)=>{const s=Te(e);return s?n.find(o=>Io(o,s))??null:null},an=(n,e,s)=>to([n.title,n.id,fs(n),e],s),pn=n=>{const e=le.c(17),{project:s,size:o}=n,r=o===void 0?"md":o,{currentTheme:i}=Yr(),a=s.icon?Qr[s.icon]:null,u=s.color?Xr[s.color]??null:null,d=r==="sm"?"size-6 rounded-md":"size-8 rounded-lg",f=r==="sm"?"size-3.5":"size-4";let l;e[0]!==a||e[1]!==u||e[2]!==f?(l=a?t.jsx(X,{name:a,className:f,style:u?{color:u}:void 0}):t.jsx(cn,{className:f,style:u?{color:u}:void 0}),e[0]=a,e[1]=u,e[2]=f,e[3]=l):l=e[3];const p=l;let b;e[4]!==d?(b=J("flex shrink-0 items-center justify-center overflow-hidden bg-[var(--surface-muted)] text-muted-foreground",d),e[4]=d,e[5]=b):b=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 v;e[8]!==i||e[9]!==p||e[10]!==s.iconImage||e[11]!==s.id?(v=s.iconImage?t.jsx(Zr,{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]=v):v=e[12];let S;return e[13]!==b||e[14]!==h||e[15]!==v?(S=t.jsx("span",{className:b,style:h,children:v}),e[13]=b,e[14]=h,e[15]=v,e[16]=S):S=e[16],S},uu=n=>{const e=le.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},jr=n=>{const e=le.c(12),{onClick:s,className:o}=n,{t:r}=de();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 u;e[2]!==o?(u=J("flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",o),e[2]=o,e[3]=u):u=e[3];let d;e[4]!==s?(d=b=>{b.stopPropagation(),s()},e[4]=s,e[5]=d):d=e[5];let f,l;e[6]===Symbol.for("react.memo_cache_sentinel")?(f={touchAction:"manipulation"},l=t.jsx(X,{name:"node-tree",className:"size-4"}),e[6]=f,e[7]=l):(f=e[6],l=e[7]);let p;return e[8]!==a||e[9]!==u||e[10]!==d?(p=t.jsx("button",{type:"button",className:u,"aria-label":a,title:a,onClick:d,style:f,children:l}),e[8]=a,e[9]=u,e[10]=d,e[11]=p):p=e[11],p},kr=n=>{const e=le.c(10),{label:s,onClick:o,className:r}=n;let i;e[0]!==r?(i=J("flex size-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",r),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==o?(a=l=>{l.stopPropagation(),o()},e[2]=o,e[3]=a):a=e[3];let u,d;e[4]===Symbol.for("react.memo_cache_sentinel")?(u={touchAction:"manipulation"},d=t.jsx(X,{name:"add",className:"size-4"}),e[4]=u,e[5]=d):(u=e[4],d=e[5]);let f;return e[6]!==s||e[7]!==i||e[8]!==a?(f=t.jsx("button",{type:"button",className:i,"aria-label":s,title:s,onClick:a,style:u,children:d}),e[6]=s,e[7]=i,e[8]=a,e[9]=f):f=e[9],f},Pt=192,Do=180,Sr=n=>{const e=le.c(25),{actionsWidth:s,actions:o,revealed:r,onRevealedChange:i,children:a}=n,u=c.useRef(null),d=c.useRef(null),f=c.useRef(!1),l=c.useRef(0),p=c.useRef(r);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=(C,x)=>{const D=u.current;D&&(D.style.transition=x?`transform ${Do}ms ease-out`:"none",D.style.transform=C===0?"none":`translateX(${C}px)`,l.current=C)},e[0]=b):b=e[0];const h=b;let v,S;e[1]!==s||e[2]!==r?(v=()=>{p.current=r,h(r?s:0,!0)},S=[s,h,r],e[1]=s,e[2]=r,e[3]=v,e[4]=S):(v=e[3],S=e[4]),c.useEffect(v,S);let w;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=C=>{if(C.touches.length!==1)return;const x=C.touches[0];d.current={x:x.clientX,y:x.clientY},f.current=!1},e[5]=w):w=e[5];const T=w;let N;e[6]!==s?(N=C=>{if(!d.current)return;const x=C.touches[0],D=x.clientX-d.current.x,K=x.clientY-d.current.y;if(!f.current){if(Math.abs(D)<8||Math.abs(D)<=Math.abs(K))return;f.current=!0}const g=p.current?s:0;h(Math.max(0,Math.min(s,g+D)),!1)},e[6]=s,e[7]=N):N=e[7];const E=N;let I;e[8]!==s||e[9]!==i?(I=()=>{if(d.current=null,!f.current)return;f.current=!1;const C=l.current>s/2;h(C?s:0,!0),C!==p.current&&i(C)},e[8]=s,e[9]=i,e[10]=I):I=e[10];const j=I;let P;e[11]===Symbol.for("react.memo_cache_sentinel")?(P={touchAction:"pan-y"},e[11]=P):P=e[11];let k;e[12]!==s?(k={width:s},e[12]=s,e[13]=k):k=e[13];const R=!r;let y;e[14]!==o||e[15]!==k||e[16]!==R?(y=t.jsx("div",{className:"absolute inset-y-0 left-0 flex items-stretch",style:k,"aria-hidden":R,children:o}),e[14]=o,e[15]=k,e[16]=R,e[17]=y):y=e[17];let z;e[18]!==a?(z=t.jsx("div",{ref:u,className:"relative flex w-full items-center bg-background",children:a}),e[18]=a,e[19]=z):z=e[19];let M;return e[20]!==j||e[21]!==E||e[22]!==y||e[23]!==z?(M=t.jsxs("div",{className:"relative overflow-hidden",onTouchStart:T,onTouchMove:E,onTouchEnd:j,onTouchCancel:j,style:P,children:[y,z]}),e[20]=j,e[21]=E,e[22]=y,e[23]=z,e[24]=M):M=e[24],M},du=n=>{const e=le.c(41),{initialTitle:s,indent:o,onSubmit:r,onCancel:i}=n,{t:a}=de(),[u,d]=c.useState(s),f=yu;let l;e[0]!==s||e[1]!==i||e[2]!==r||e[3]!==u?(l=()=>{const x=u.trim();if(!x||x===s.trim()){i();return}r(x)},e[0]=s,e[1]=i,e[2]=r,e[3]=u,e[4]=l):l=e[4];const p=l;let b;e[5]!==o?(b={paddingLeft:o},e[5]=o,e[6]=b):b=e[6];let h;e[7]!==p?(h=x=>{x.preventDefault(),p()},e[7]=p,e[8]=h):h=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=x=>d(x.target.value),e[9]=v):v=e[9];let S;e[10]!==i?(S=x=>za(x,i),e[10]=i,e[11]=S):S=e[11];let w;e[12]!==a?(w=a("sessions.sidebar.session.rename.save"),e[12]=a,e[13]=w):w=e[13];let T;e[14]!==a?(T=a("sessions.sidebar.session.menu.rename"),e[14]=a,e[15]=T):T=e[15];let N;e[16]===Symbol.for("react.memo_cache_sentinel")?(N={minHeight:0},e[16]=N):N=e[16];let E;e[17]!==S||e[18]!==w||e[19]!==T||e[20]!==u?(E=t.jsx("input",{ref:f,value:u,onChange:v,onKeyDown:S,"aria-label":w,placeholder:T,className:"min-w-0 flex-1 bg-transparent text-[16px] typography-ui-label text-foreground outline-none placeholder:text-muted-foreground",style:N,enterKeyHint:"done"}),e[17]=S,e[18]=w,e[19]=T,e[20]=u,e[21]=E):E=e[21];let I;e[22]!==a?(I=a("sessions.sidebar.session.rename.save"),e[22]=a,e[23]=I):I=e[23];let j,P;e[24]===Symbol.for("react.memo_cache_sentinel")?(j={touchAction:"manipulation",minHeight:0,minWidth:0},P=t.jsx(X,{name:"check",className:"size-4"}),e[24]=j,e[25]=P):(j=e[24],P=e[25]);let k;e[26]!==I?(k=t.jsx("button",{type:"submit","aria-label":I,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:j,children:P}),e[26]=I,e[27]=k):k=e[27];let R;e[28]!==a?(R=a("sessions.sidebar.session.rename.cancel"),e[28]=a,e[29]=R):R=e[29];let y,z;e[30]===Symbol.for("react.memo_cache_sentinel")?(y={touchAction:"manipulation",minHeight:0,minWidth:0},z=t.jsx(X,{name:"close",className:"size-4"}),e[30]=y,e[31]=z):(y=e[30],z=e[31]);let M;e[32]!==i||e[33]!==R?(M=t.jsx("button",{type:"button",onClick:i,"aria-label":R,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:y,children:z}),e[32]=i,e[33]=R,e[34]=M):M=e[34];let C;return e[35]!==k||e[36]!==M||e[37]!==b||e[38]!==h||e[39]!==E?(C=t.jsxs("form",{className:"flex h-9 min-w-0 flex-1 items-center gap-2 pr-2",style:b,onSubmit:h,children:[E,k,M]}),e[35]=k,e[36]=M,e[37]=b,e[38]=h,e[39]=E,e[40]=C):C=e[40],C},Nr=n=>{const e=le.c(52),{session:s,active:o,indent:r,contextLabel:i,hasChildren:a,expanded:u,onToggleChildren:d,onSelect:f,revealed:l,onRevealedChange:p,confirmingDelete:b,onArchive:h,onRequestDelete:v,onConfirmDelete:S,renaming:w,onRequestRename:T,onSubmitRename:N,onCancelRename:E}=n,I=a===void 0?!1:a,j=u===void 0?!1:u,P=l===void 0?!1:l,k=b===void 0?!1:b,R=w===void 0?!1:w,{t:y}=de();let z;e[0]!==s?(z=lu(au(s)),e[0]=s,e[1]=z):z=e[1];const M=z,C=s.title?.trim()||y("mobile.sessions.untitled"),x=!!(p&&h),D=Ia(s.id,s.directory,x&&P),K=Vr(s.id),g=Gr(s.id),L=K?.type??"idle",F=L==="busy"||L==="retry",B=!F&&g>0&&!o,W=Kr(s.id,F),re=(F||B)&&W,ne=c.useRef(null),ee=c.useRef(null),_=c.useRef(!1),G=c.useRef(0),Y=c.useRef(P);let U;e[2]===Symbol.for("react.memo_cache_sentinel")?(U=(Ae,Xe)=>{const Pe=ne.current;Pe&&(Pe.style.transition=Xe?`transform ${Do}ms ease-out`:"none",Pe.style.transform=Ae===0?"none":`translateX(${Ae}px)`,G.current=Ae)},e[2]=U):U=e[2];const Z=U;let te,se;e[3]!==P?(te=()=>{Y.current=P,Z(P?Pt:0,!0)},se=[Z,P],e[3]=P,e[4]=te,e[5]=se):(te=e[4],se=e[5]),c.useEffect(te,se);let ae;e[6]!==x?(ae=Ae=>{if(!x||Ae.touches.length!==1)return;const Xe=Ae.touches[0];ee.current={x:Xe.clientX,y:Xe.clientY},_.current=!1},e[6]=x,e[7]=ae):ae=e[7];const ue=ae;let V;e[8]!==x?(V=Ae=>{if(!x||!ee.current)return;const Xe=Ae.touches[0],Pe=Xe.clientX-ee.current.x,lt=Xe.clientY-ee.current.y;if(!_.current){if(Math.abs(Pe)<8||Math.abs(Pe)<=Math.abs(lt))return;_.current=!0}const Gt=Y.current?Pt:0,$e=Math.max(0,Math.min(Pt,Gt+Pe));Z($e,!1)},e[8]=x,e[9]=V):V=e[9];const ie=V;let ye;e[10]!==p?(ye=()=>{if(ee.current=null,!_.current)return;_.current=!1;const Ae=G.current>Pt/2;Z(Ae?Pt:0,!0),Ae!==Y.current&&p?.(Ae)},e[10]=p,e[11]=ye):ye=e[11];const ke=ye,q=o||void 0,ve="relative overflow-hidden";let Re;e[12]!==x?(Re=x?{touchAction:"pan-y"}:void 0,e[12]=x,e[13]=Re):Re=e[13];const De=x?t.jsxs("div",{className:"absolute inset-y-0 left-0 flex items-stretch",style:{width:Pt},"aria-hidden":!P,children:[t.jsx("button",{type:"button",tabIndex:P?0:-1,className:J("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",k?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":k?y("mobile.sessions.confirmDeleteSessionAria",{title:C}):y("mobile.sessions.deleteSessionAria",{title:C}),onClick:k?S:v,style:{touchAction:"manipulation"},children:t.jsx(Ms,{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-ring","aria-label":y("mobile.sessions.archiveSessionAria",{title:C}),onClick:h,style:{touchAction:"manipulation"},children:t.jsx(al,{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-ring","aria-label":y("mobile.sessions.renameSessionAria",{title:C}),onClick:T,style:{touchAction:"manipulation"},children:t.jsx(un,{className:"size-[18px]"})}),t.jsx(pe,{variant:"ghost",size:"icon",tabIndex:P?0:-1,className:"flex-1 self-center text-muted-foreground",disabled:D.disabled,"aria-label":y("sessions.aiRename.action"),"aria-description":D.hint,title:D.hint,onClick:()=>{D.run(),p?.(!1)},style:{touchAction:"manipulation"},children:t.jsx(X,{name:D.pending?"loader-4":"ai-generate-2",className:D.pending?"size-[18px] animate-spin":"size-[18px]"})})]}):null,_e=x&&"bg-background",Ue=o&&(x?"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]":"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]");let Me;e[14]!==_e||e[15]!==Ue?(Me=J("relative flex items-center gap-1 transition-colors",_e,Ue),e[14]=_e,e[15]=Ue,e[16]=Me):Me=e[16];let Fe;e[17]!==D.pending||e[18]!==j||e[19]!==I||e[20]!==r||e[21]!==F||e[22]!==d||e[23]!==B||e[24]!==y?(Fe=D.pending||F||B||I&&d?t.jsx("button",{type:"button",className:"absolute z-10 flex w-6 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",style:{left:Math.max(r-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":D.pending?y("sessions.aiRename.generating"):y(j?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),disabled:!I||!d,onClick:Ae=>{Ae.stopPropagation(),d?.()},children:D.pending?t.jsx(X,{name:"loader-4",className:"size-3 animate-spin text-primary","aria-label":y("sessions.aiRename.generating")}):F||B?t.jsx("span",{className:J("size-1.5 rounded-full",F?"bg-primary":"bg-[var(--status-info)]"),"aria-hidden":!0}):t.jsx(kn,{className:J("size-[18px] transition-transform duration-150",j?"rotate-0":"-rotate-90")})}):null,e[17]=D.pending,e[18]=j,e[19]=I,e[20]=r,e[21]=F,e[22]=d,e[23]=B,e[24]=y,e[25]=Fe):Fe=e[25];let Ce;e[26]!==o||e[27]!==i||e[28]!==r||e[29]!==F||e[30]!==E||e[31]!==p||e[32]!==f||e[33]!==N||e[34]!==R||e[35]!==s.id||e[36]!==re||e[37]!==M||e[38]!==C?(Ce=R&&N&&E?t.jsx(du,{initialTitle:C,indent:r,onSubmit:N,onCancel:E}):t.jsx("button",{type:"button",className:J("flex min-w-0 flex-1 items-center gap-2.5 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",i?"min-h-10 py-1":"h-9"),style:{paddingLeft:r,touchAction:"manipulation"},onClick:()=>{if(Y.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:J("block min-w-0 flex-1 truncate typography-ui-label",o?"text-primary":"text-foreground"),children:C}),re?t.jsx(io,{sessionId:s.id,running:F,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[26]=o,e[27]=i,e[28]=r,e[29]=F,e[30]=E,e[31]=p,e[32]=f,e[33]=N,e[34]=R,e[35]=s.id,e[36]=re,e[37]=M,e[38]=C,e[39]=Ce):Ce=e[39];let Ee;e[40]!==Me||e[41]!==Fe||e[42]!==Ce?(Ee=t.jsxs("div",{ref:ne,className:Me,children:[Fe,Ce]}),e[40]=Me,e[41]=Fe,e[42]=Ce,e[43]=Ee):Ee=e[43];let we;return e[44]!==ke||e[45]!==ie||e[46]!==ue||e[47]!==q||e[48]!==Re||e[49]!==De||e[50]!==Ee?(we=t.jsxs("div",{"data-active-session":q,className:ve,onTouchStart:ue,onTouchMove:ie,onTouchEnd:ke,onTouchCancel:ke,style:Re,children:[De,Ee]}),e[44]=ke,e[45]=ie,e[46]=ue,e[47]=q,e[48]=Re,e[49]=De,e[50]=Ee,e[51]=we):we=e[51],we},fu=n=>{const e=le.c(11),{indent:s,onClick:o}=n,{t:r}=de();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(kn,{className:"size-4"}),e[2]=a):a=e[2];let u;e[3]!==r?(u=r("sessions.sidebar.group.showMore"),e[3]=r,e[4]=u):u=e[4];let d;e[5]!==u?(d=t.jsx("span",{className:"typography-micro",children:u}),e[5]=u,e[6]=d):d=e[6];let f;return e[7]!==o||e[8]!==i||e[9]!==d?(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-ring focus-visible:ring-inset",style:i,onClick:o,children:[a,d]}),e[7]=o,e[8]=i,e[9]=d,e[10]=f):f=e[10],f},mu=n=>{const e=le.c(11),{indent:s,onClick:o}=n,{t:r}=de();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(ll,{className:"size-4"}),e[2]=a):a=e[2];let u;e[3]!==r?(u=r("sessions.sidebar.group.showFewer"),e[3]=r,e[4]=u):u=e[4];let d;e[5]!==u?(d=t.jsx("span",{className:"typography-micro",children:u}),e[5]=u,e[6]=d):d=e[6];let f;return e[7]!==o||e[8]!==i||e[9]!==d?(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-ring focus-visible:ring-inset",style:i,onClick:o,children:[a,d]}),e[7]=o,e[8]=i,e[9]=d,e[10]=f):f=e[10],f},pu=n=>{const e=le.c(29),{worktree:s}=n,{t:o}=de();let r;e[0]!==s.path?(r=Te(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:u,listeners:d,setNodeRef:f,transform:l,transition:p,isDragging:b}=In(a),h=s.branch||s.label||s.path;let v;e[4]!==l?(v=Dn.Transform.toString(l),e[4]=l,e[5]=v):v=e[5];const S=b?10:1;let w;e[6]!==v||e[7]!==S||e[8]!==p?(w={transform:v,transition:p,zIndex:S},e[6]=v,e[7]=S,e[8]=p,e[9]=w):w=e[9];const T=b&&"shadow-lg shadow-black/20";let N;e[10]!==T?(N=J("flex items-center gap-1 rounded-xl bg-background px-1 py-1",T),e[10]=T,e[11]=N):N=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 I;e[15]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx(jn,{className:"size-4"}),e[15]=I):I=e[15];let j;e[16]!==u||e[17]!==d||e[18]!==E?(j=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,...u,...d,children:I}),e[16]=u,e[17]=d,e[18]=E,e[19]=j):j=e[19];let P;e[20]===Symbol.for("react.memo_cache_sentinel")?(P=t.jsx(X,{name:"git-branch",className:"size-4 shrink-0 text-muted-foreground"}),e[20]=P):P=e[20];let k;e[21]!==h?(k=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]=k):k=e[22];let R;return e[23]!==f||e[24]!==j||e[25]!==k||e[26]!==w||e[27]!==N?(R=t.jsxs("div",{ref:f,style:w,className:N,children:[j,P,k]}),e[23]=f,e[24]=j,e[25]=k,e[26]=w,e[27]=N,e[28]=R):R=e[28],R},hu=n=>{const e=le.c(61),{project:s,totalSessions:o,expanded:r,onToggleExpanded:i,onReorderWorktrees:a}=n,{t:u}=de();let d;e[0]!==s.id?(d={id:s.id},e[0]=s.id,e[1]=d):d=e[1];const{attributes:f,listeners:l,setNodeRef:p,transform:b,transition:h,isDragging:v}=In(d);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S={activationConstraint:{distance:8}},e[2]=S):S=e[2];let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w={coordinateGetter:Pn},e[3]=w):w=e[3];const T=Sn(Lt(Cn,S),Lt(Nn,w)),N=s.worktrees.length>0;let E;e[4]!==a||e[5]!==s.worktrees?(E=_=>{const{active:G,over:Y}=_;if(!Y||G.id===Y.id)return;const U=s.worktrees.map(vu),Z=U.indexOf(String(G.id)),te=U.indexOf(String(Y.id));if(Z<0||te<0)return;const se=[...U],[ae]=se.splice(Z,1);se.splice(te,0,ae),a(se)},e[4]=a,e[5]=s.worktrees,e[6]=E):E=e[6];const I=E;let j;e[7]!==b?(j=Dn.Transform.toString(b),e[7]=b,e[8]=j):j=e[8];const P=v?10:1;let k;e[9]!==j||e[10]!==P||e[11]!==h?(k={transform:j,transition:h,zIndex:P},e[9]=j,e[10]=P,e[11]=h,e[12]=k):k=e[12];const R=v&&"shadow-lg shadow-black/20";let y;e[13]!==R?(y=J("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 z;e[15]!==s.label||e[16]!==u?(z=u("mobile.sessions.dragHandleAria",{label:s.label}),e[15]=s.label,e[16]=u,e[17]=z):z=e[17];let M;e[18]===Symbol.for("react.memo_cache_sentinel")?(M=t.jsx(jn,{className:"size-4"}),e[18]=M):M=e[18];let C;e[19]!==f||e[20]!==l||e[21]!==z?(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":z,...f,...l,children:M}),e[19]=f,e[20]=l,e[21]=z,e[22]=C):C=e[22];let x;e[23]!==r||e[24]!==s.label||e[25]!==u?(x=r?u("sessions.sidebar.group.collapseAria",{label:s.label}):u("sessions.sidebar.group.expandAria",{label:s.label}),e[23]=r,e[24]=s.label,e[25]=u,e[26]=x):x=e[26];const D=!N;let K;e[27]===Symbol.for("react.memo_cache_sentinel")?(K={touchAction:"manipulation"},e[27]=K):K=e[27];let g;e[28]!==s?(g=t.jsx(pn,{project:s}),e[28]=s,e[29]=g):g=e[29];let L;e[30]!==s.label?(L=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]=L):L=e[31];let F;e[32]!==o?(F=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:o}),e[32]=o,e[33]=F):F=e[33];let B;e[34]!==r||e[35]!==N?(B=N?t.jsx(kn,{className:J("size-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-180")}):null,e[34]=r,e[35]=N,e[36]=B):B=e[36];let W;e[37]!==r||e[38]!==i||e[39]!==x||e[40]!==D||e[41]!==g||e[42]!==L||e[43]!==F||e[44]!==B?(W=t.jsxs("button",{type:"button",className:"flex min-h-9 min-w-0 flex-1 items-center gap-2 rounded-xl px-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",onClick:i,"aria-expanded":r,"aria-label":x,disabled:D,style:K,children:[g,L,F,B]}),e[37]=r,e[38]=i,e[39]=x,e[40]=D,e[41]=g,e[42]=L,e[43]=F,e[44]=B,e[45]=W):W=e[45];let re;e[46]!==C||e[47]!==W?(re=t.jsxs("div",{className:"flex items-center gap-1",children:[C,W]}),e[46]=C,e[47]=W,e[48]=re):re=e[48];let ne;e[49]!==r||e[50]!==I||e[51]!==N||e[52]!==s.worktrees||e[53]!==T?(ne=r&&N?t.jsx(En,{sensors:T,collisionDetection:Rn,onDragEnd:I,children:t.jsx(An,{items:s.worktrees.map(wu),strategy:Tn,children:t.jsx("div",{className:"mt-1 flex flex-col gap-0.5 pl-3",children:s.worktrees.map(ju)})})}):null,e[49]=r,e[50]=I,e[51]=N,e[52]=s.worktrees,e[53]=T,e[54]=ne):ne=e[54];let ee;return e[55]!==p||e[56]!==re||e[57]!==ne||e[58]!==k||e[59]!==y?(ee=t.jsxs("div",{ref:p,style:k,className:y,children:[re,ne]}),e[55]=p,e[56]=re,e[57]=ne,e[58]=k,e[59]=y,e[60]=ee):ee=e[60],ee},Cr=({open:n,onOpenChange:e,variant:s="drawer",footer:o})=>{const{t:r}=de(),{git:i}=vn(),a=qr(),u=gn(m=>m.activeSessions),d=Wr(c.useCallback(m=>n||s==="sidebar"?m.ids:ru,[n,s])),f=Ur(c.useCallback(m=>n||s==="sidebar"?m.rankById:gi,[n,s])),l=We(m=>m.projects),p=We(m=>m.activeProjectId),b=yt(m=>m.currentDirectory),h=Ne(m=>m.currentSessionId),v=Ne(m=>m.setCurrentSession),S=Ne(m=>m.archiveSession),w=Ne(m=>m.archiveSessions),T=Ne(m=>m.deleteSession),N=Ne(m=>m.deleteSessions),E=Ne(m=>m.updateSessionTitle),I=Ne(m=>m.openNewSessionDraft),j=We(m=>m.setActiveProject),P=We(m=>m.setActiveProjectIdOnly),k=We(m=>m.reorderProjects),R=We(m=>m.manualProjectOrder),y=Jn(m=>m.projectSortOrder),z=Jn(m=>m.setProjectSortOrder),M=We(m=>m.removeProject),C=Ps(m=>m.projectExpanded),x=Ps(m=>m.worktreeExpanded),D=Ps(m=>m.setProjectExpanded),K=Ps(m=>m.setWorktreeExpanded),g=mn(m=>m.orderByProject),L=mn(m=>m.setWorktreeOrder),F=yr(m=>m.expandedParents),B=yr(m=>m.toggleParent),[W,re]=c.useState(""),[ne,ee]=c.useState(null),[_,G]=c.useState(null),[Y,U]=c.useState(null),[Z,te]=c.useState(null),[se,ae]=c.useState(null),[ue,V]=c.useState(null),[ie,ye]=c.useState(null),[ke,q]=c.useState(0),[ve,Re]=c.useState(!1),[De,_e]=c.useState(!1),[Ue,Me]=c.useState(!1),[Fe,Ce]=c.useState(null),[Ee,we]=c.useState(()=>new Map(Ne.getState().availableWorktreesByProject)),[Ae,Xe]=c.useState(()=>{const m=new Set;for(const[$,H]of Ne.getState().availableWorktreesByProject)H.length>0&&m.add($);return m}),[Pe,lt]=c.useState(!1),[Gt,$e]=c.useState(new Set),[Ve,tt]=c.useState(new Map);c.useEffect(()=>{if(!n){re(""),lt(!1),$e(new Set),tt(new Map),ee(null),G(null),U(null),te(null),ae(null),V(null);return}yn(a)},[n]),c.useEffect(()=>{Pe||$e(new Set)},[Pe]),c.useEffect(()=>{if(!n||l.length===0)return;let m=!1;return(async()=>{const H=await Promise.all(l.map(async me=>{const fe=Te(me.path);if(!fe)return null;const Le=await i.checkIsGitRepository(fe).catch(()=>!1),Ze=Le?await so({id:me.id,path:fe}).catch(()=>[]):[];return[fe,Ze,Le]}));if(m)return;const oe=new Map,he=new Set;for(const me of H)me&&(oe.set(me[0],me[1]),me[2]&&he.add(me[0]));we(no(l,oe)),Xe(he)})(),()=>{m=!0}},[i,n,l,ke]);const je=c.useMemo(()=>Ea(l.map(m=>({id:m.id,label:m.label?.trim()||sn(m.path),path:Te(m.path),icon:m.icon,color:m.color,iconImage:m.iconImage,iconBackground:m.iconBackground,isGitRepo:Ae.has(Te(m.path)),worktrees:qc(g[m.id],Ee.get(Te(m.path))??[]),addedAt:m.addedAt,lastOpenedAt:m.lastOpenedAt})),y,R),[Ae,R,y,l,g,Ee]),Ge=c.useMemo(()=>{const m=new Map(a.map(oe=>[oe.id,oe])),$=u.map(oe=>{const he=m.get(oe.id);return he?bi(he,oe):oe}),H=new Set($.map(oe=>oe.id));for(const oe of a)H.has(oe.id)||$.push(oe);return $.filter(oe=>!oe.time?.archived)},[u,a]),Vs=c.useMemo(()=>{const m=new Map;for(const $ of Ge){const H=Rt($);if(!H)continue;const oe=m.get(H)??[];oe.push($),m.set(H,oe)}return m},[Ge]),{projectSessions:Kt,chatSessions:be}=c.useMemo(()=>Ra(Ge,!1),[Ge]),Ht=c.useMemo(()=>({key:rs,label:"",path:"",worktree:null,sessions:Qs(be,d,f)}),[be,d,f]),qt=`${rs}::${rs}`,rt=c.useMemo(()=>be.filter(m=>!Rt(m)).length,[be]),ze=W.trim().toLowerCase(),xs=c.useRef(null);c.useEffect(()=>{if(!n)return;const m=window.requestAnimationFrame(()=>{const $=xs.current;if(!$)return;($.querySelector('[data-active-session="true"]')??$.querySelector('[data-active-project="true"]'))?.scrollIntoView({block:"center"})});return()=>window.cancelAnimationFrame(m)},[n]);const St=c.useMemo(()=>{const m=je.map(H=>({project:H,buckets:[],totalSessions:0,isActive:H.id===p})),$=(H,oe,he)=>{const me=Te(oe)||H.project.path,fe=me||"__root__";let Le=H.buckets.find(Ze=>Ze.key===fe);return Le||(Le={key:fe,label:he?.branch||sn(me),path:me,worktree:he,sessions:[]},H.buckets.push(Le)),Le};for(const H of m){$(H,H.project.path,null);for(const oe of H.project.worktrees)$(H,oe.path,oe)}for(const H of Kt){const oe=fs(H);if(!oe)continue;const he=Te(oe),me=m.find(Ze=>Io(Ze.project,he));if(!me)continue;const fe=_s(me.project,he);(fe?$(me,fe.path,fe):$(me,me.project.path,null)).sessions.push(H)}for(const H of m)for(const oe of H.buckets){oe.sessions=Qs(oe.sessions,d,f);for(const he of oe.sessions)Rt(he)||(H.totalSessions+=1)}return m},[p,d,Kt,je,f]),ys=Te(b),mt=m=>m.isActive?ys===m.project.path?m.project.path:m.project.worktrees.find(H=>cu(ys,H.path))?.path??m.project.path:null,Ke=m=>C[m.project.id]??!0,st=(m,$)=>x[`${m.project.id}::${$.key}`]??!0,Nt=m=>{tt($=>{if(!$.has(m))return $;const H=new Map($);return H.delete(m),H})},ct=m=>{tt($=>{let H=!1;const oe=new Map($),he=`${m}::`;for(const me of oe.keys())me.startsWith(he)&&(oe.delete(me),H=!0);return H?oe:$})},Gs=(m,$)=>{tt(H=>{const oe=new Map(H);return oe.set(m,$+rn),oe})},Jt=(m,$,H)=>{const oe=new Set($.sessions.map(Se=>Se.id)),he=new Map;for(const Se of $.sessions){const nt=Rt(Se);if(nt&&oe.has(nt)){const ss=he.get(nt)??[];ss.push(Se),he.set(nt,ss)}}const me=$.sessions.filter(Se=>{const nt=Rt(Se);return!nt||!oe.has(nt)}),fe=Ve.get(m)??rn,Le=me.slice(0,fe),Ze=me.length-Le.length,Ys=me.length>rn&&Ze===0,Kn=(Se,nt)=>{const ss=he.get(Se.id)??[],Xs=ss.length>0,Hn=!!F[Se.id];return t.jsxs(c.Fragment,{children:[t.jsx(Nr,{session:Se,active:h===Se.id,indent:nt,hasChildren:Xs,expanded:Hn,onToggleChildren:Xs?()=>B(Se.id):void 0,onSelect:()=>vs(Se),revealed:_===Se.id,onRevealedChange:ns=>Ct(Se.id,ns),confirmingDelete:Y===Se.id,onArchive:()=>{Et(Se)},onRequestDelete:()=>U(Se.id),onConfirmDelete:()=>{js(Se)},renaming:Z===Se.id,onRequestRename:()=>ht(Se.id),onSubmitRename:ns=>{Yt(Se.id,ns)},onCancelRename:()=>te(null)}),Xs&&Hn?ss.map(ns=>Kn(ns,nt+iu)):null]},Se.id)};return t.jsxs("div",{children:[Le.map(Se=>Kn(Se,H)),Ze>0?t.jsx(fu,{indent:H,onClick:()=>Gs(m,Le.length)}):null,Ys?t.jsx(mu,{indent:H,onClick:()=>Nt(m)}):null]})},Oe=(m,$)=>{D(m,!$),ct(m)},Ks=(m,$,H)=>{K(`${m}::${$}`,!H),Nt(`${m}::${$}`)},vs=m=>{const $=fs(m)||null,H=on(je,$??"");if(H){P(H.id),D(H.id,!0);const oe=_s(H,Te($??""));oe&&K(`${H.id}::${Te(oe.path)}`,!0)}v(m.id,$),e(!1)},Ct=(m,$)=>{G($?m:null),U(null),ae(null),V(null)},pt=(m,$)=>{ae($?m:null),V(null),G(null),U(null)},ws=(m,$)=>(G(null),U(null),Da(m,$,_a($.id,Ma(Vs,$.id),m==="delete"),{archiveSession:S,archiveSessions:w,deleteSession:T,deleteSessions:N},r)),Et=m=>ws("archive",m),js=m=>ws("delete",m),ht=m=>{G(null),U(null),te(m)},Yt=async(m,$)=>{te(null);try{await E(m,$)}catch{ce.error(r("mobile.sessions.renameError"))}},Xt=()=>{I(),e(!1)},Qt=m=>{Ce(m),P(m),Me(!0)},Hs=Sn(Lt(Cn,{activationConstraint:{distance:8}}),Lt(Nn,{coordinateGetter:Pn})),qs=m=>{z(m),Uo({sidebarProjectSortOrder:m}),m!=="manual"&&lt(!1)},ks=m=>{const{active:$,over:H}=m;if(!H||$.id===H.id)return;const oe=je.findIndex(me=>me.id===$.id),he=je.findIndex(me=>me.id===H.id);oe<0||he<0||k(oe,he)},Js=m=>{$e($=>{const H=new Set($);return H.has(m)?H.delete(m):H.add(m),H})},Zt=c.useCallback(m=>{const $=fs(m);if(xi($))return r("mobile.sessions.section.chats");const H=on(je,$);if(!H)return sn($)||$;const oe=_s(H,Te($));return oe?.branch?`${H.label} · ${oe.branch}`:H.label},[je,r]),Ss=m=>{j(m.id),e(!1)},es=m=>{P(m.id),I({selectedProjectId:m.id,directoryOverride:m.path}),e(!1)},A=c.useMemo(()=>ze?St.filter(m=>to([m.project.label,m.project.path],ze)?!0:m.buckets.some($=>$.sessions.some(H=>an(H,m.project.label,ze)))):St,[ze,St]),O=c.useMemo(()=>ze?Qs(Ge.filter(m=>{if(Rt(m))return!1;const $=fs(m),H=on(je,$);return an(m,H?.label??"",ze)}),d,f):[],[ze,d,je,f,Ge]),Q=c.useMemo(()=>ze?yi(je,ze,m=>[m.label,m.path]):[],[ze,je]),xe=ze&&O.length===0&&Q.length===0,Qe=!ze&&je.length>1&&y==="manual",ut=!Pe&&!ze&&je.length>1?t.jsx(pe,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.sortProjects"),title:r("sessions.sidebar.header.actions.sortProjects"),onClick:()=>Re(!0),style:{touchAction:"manipulation"},children:t.jsx(X,{name:"equalizer-2",className:"size-4"})}):null,dt=Qe?t.jsx(pe,{type:"button",variant:"chip",size:"sm","aria-label":r(Pe?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":Pe,onClick:()=>lt(m=>!m),style:{touchAction:"manipulation"},children:Pe?t.jsx(ao,{className:"size-4"}):t.jsx(un,{className:"size-4"})}):null,ts=!Pe&&je.length>0?t.jsxs(pe,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:Xt,style:{touchAction:"manipulation"},children:[t.jsx(il,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,Ns=Pe?null:t.jsx(pe,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>_e(!0),style:{touchAction:"manipulation"},children:t.jsx(nr,{className:"size-4"})}),Cs=ts||Ns||ut||dt?t.jsxs(t.Fragment,{children:[Ns,ut,dt,ts]}):null,Gn=t.jsxs("div",{ref:xs,className:"flex min-h-0 flex-1 flex-col",children:[t.jsxs(Fs,{className:"min-h-0 flex-1 overflow-y-auto pb-4",children:[t.jsx("div",{className:J("px-4 pb-2 pt-1",Pe&&"hidden"),children:t.jsx(Pa,{value:W,onSearch:re,active:n||s==="sidebar",mobile:!0,placeholder:r("mobile.sessions.search.placeholder"),clearLabel:r("mobile.sessions.clearSearchAria")})}),je.length===0&&be.length===0?t.jsx(Pr,{title:r("mobile.sessions.empty.noProjectsTitle"),description:r("mobile.sessions.empty.noProjectsDescription"),action:t.jsxs("button",{type:"button",className:"flex items-center justify-center gap-2 rounded-2xl bg-primary px-5 py-3 typography-ui-label text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:()=>_e(!0),children:[t.jsx(nr,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):xe?t.jsx(Pr,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):ze&&!Pe?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[O.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:O.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:O.map((m,$)=>t.jsx("div",{className:J($>0&&"border-t border-border/70"),children:t.jsx(Nr,{session:m,active:h===m.id,indent:12,contextLabel:Zt(m),onSelect:()=>vs(m)})},m.id))})]}):null,Q.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:Q.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Q.map((m,$)=>t.jsxs("div",{className:J("flex items-center",$>0&&"border-t border-border/70"),children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-3 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>Ss(m),style:{touchAction:"manipulation"},children:[t.jsx(pn,{project:m}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:m.label})]}),m.isGitRepo?t.jsx(jr,{onClick:()=>Qt(m.id)}):null,t.jsx(kr,{className:"mr-2",label:r("mobile.sessions.newSessionInProjectAria",{label:m.label}),onClick:()=>es(m)})]},m.id))})]}):null]}):Pe?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(En,{sensors:Hs,collisionDetection:Rn,onDragEnd:ks,children:t.jsx(An,{items:je.map(m=>m.id),strategy:Tn,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:je.map(m=>{const $=St.find(H=>H.project.id===m.id);return t.jsx(hu,{project:m,totalSessions:$?.totalSessions??0,expanded:Gt.has(m.id),onToggleExpanded:()=>Js(m.id),onReorderWorktrees:H=>L(m.id,H)},m.id)})})})})]}):t.jsxs("div",{className:"flex flex-col",children:[(()=>{const m=C[rs]??!0,$=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-ring focus-visible:ring-inset",onClick:()=>{if(se){pt(se,!1);return}Oe(rs,m)},"aria-expanded":m,"aria-label":m?r("sessions.sidebar.group.collapseAria",{label:$}):r("sessions.sidebar.group.expandAria",{label:$}),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(X,{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:$}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:rt})]})}),m?t.jsx("div",{className:"pb-2",children:Ht.sessions.length>0?Jt(qt,Ht,Ts):t.jsx("p",{className:"px-3 pb-1 typography-micro text-muted-foreground",style:{paddingLeft:Ts},children:r("sessions.sidebar.activity.chatsEmpty")})}):null]})})(),A.map(m=>{const $=Ke(m),H=ze?m.buckets.filter(he=>he.sessions.some(me=>an(me,m.project.label,ze))):m.buckets,oe=mt(m);return t.jsxs("section",{className:"border-t border-border/70",children:[t.jsx(Sr,{actionsWidth:96,revealed:se===`project:${m.project.id}`,onRevealedChange:he=>pt(`project:${m.project.id}`,he),actions:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",tabIndex:se===`project:${m.project.id}`?0:-1,className:J("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",ue===m.project.id?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":ue===m.project.id?r("mobile.sessions.confirmRemoveProjectAria",{label:m.project.label}):r("mobile.sessions.removeProjectAria",{label:m.project.label}),onClick:()=>{if(ue===m.project.id){ae(null),V(null),M(m.project.id),ce.success(r("mobile.sessions.toast.projectRemoved",{label:m.project.label}));return}V(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(Ms,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:se===`project:${m.project.id}`?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring","aria-label":r("mobile.sessions.editProjectAria",{label:m.project.label}),onClick:()=>{ae(null),ee(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(un,{className:"size-[18px]"})})]}),children:t.jsxs("div",{"data-active-project":m.isActive||void 0,className:"flex min-h-12 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(se){pt(se,!1);return}Oe(m.project.id,$)},"aria-expanded":$,"aria-label":$?r("sessions.sidebar.group.collapseAria",{label:m.project.label}):r("sessions.sidebar.group.expandAria",{label:m.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(pn,{project:m.project}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:m.project.label})]}),m.project.isGitRepo?t.jsx(jr,{onClick:()=>Qt(m.project.id)}):null,t.jsx(kr,{className:"mr-2",label:r("mobile.sessions.newSessionInProjectAria",{label:m.project.label}),onClick:()=>es(m.project)})]})}),$?t.jsx("div",{className:"pb-2",children:(()=>{const he=H.find(fe=>fe.worktree===null),me=H.filter(fe=>fe.worktree!==null);return t.jsxs(t.Fragment,{children:[he&&he.sessions.length>0?Jt(`${m.project.id}::${he.key}`,he,Ts):null,me.map(fe=>{const Le=st(m,fe),Ze=oe===fe.path;return t.jsxs("div",{children:[t.jsx(Sr,{actionsWidth:48,revealed:se===`wt:${fe.key}`,onRevealedChange:Ys=>pt(`wt:${fe.key}`,Ys),actions:t.jsx("button",{type:"button",tabIndex:se===`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:()=>{ae(null),fe.worktree&&ye({project:m.project,worktree:fe.worktree})},style:{touchAction:"manipulation"},children:t.jsx(Ms,{className:"size-[18px]"})}),children:t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 px-3 py-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:()=>{if(se){pt(se,!1);return}Ks(m.project.id,fe.key,Le)},"aria-expanded":Le,"aria-label":Le?r("sessions.sidebar.group.collapseAria",{label:fe.label}):r("sessions.sidebar.group.expandAria",{label:fe.label}),style:{touchAction:"manipulation"},children:[t.jsx(X,{name:"git-branch",className:J("size-4 shrink-0",Ze?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:J("block min-w-0 flex-1 truncate typography-ui-label font-bold",Ze?"text-foreground":"text-muted-foreground"),children:fe.label}),Ze?t.jsx(uu,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:fe.sessions.length})]})}),Le?Jt(`${m.project.id}::${fe.key}`,fe,Ts):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(pe,{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(X,{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(pe,{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(X,{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(pe,{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(X,{name:"settings-3",className:"size-5"})})]})]}):null,t.jsx(Aa,{open:De,onOpenChange:_e}),t.jsx(Ta,{open:Ue,onOpenChange:m=>{Me(m),m||Ce(null)},onWorktreeCreated:(m,$)=>{$?.sessionId?v($.sessionId,m):I({selectedProjectId:Fe,directoryOverride:m,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(Zc,{open:ne!==null,project:je.find(m=>m.id===ne)??null,onClose:()=>ee(null),onWorktreesChanged:()=>q(m=>m+1)}),t.jsx(Jr,{open:ve,onClose:()=>Re(!1),title:r("sessions.sidebar.header.actions.sortProjects"),children:t.jsx("div",{className:"flex flex-col",children:ou.map(([m,$])=>t.jsxs("button",{type:"button",className:J("flex min-h-11 w-full items-center justify-between rounded-lg px-3 text-left transition-colors active:bg-interactive-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",y===m?"text-primary":"text-foreground"),onClick:()=>{qs(m),Re(!1)},style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label",children:r($)}),y===m?t.jsx(X,{name:"check",className:"size-4"}):null]},m))})}),ie?t.jsx(To,{open:!0,project:{id:ie.project.id,path:ie.project.path},worktree:ie.worktree,onClose:()=>ye(null),onDeleted:()=>q(m=>m+1)}):null]});return s==="sidebar"?n?t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center justify-between gap-2 border-b border-border/70 px-4",children:[t.jsx("h2",{className:"truncate typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Cs?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Cs}):null]}),Gn]}):null:t.jsxs(xu,{open:n,onClose:()=>e(!1),onSwipeClose:()=>{if(_||se){G(null),ae(null),U(null),V(null);return}e(!1)},ariaLabel:r("mobile.sessions.sheet.title"),children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":r("mobile.surface.closeAria"),onClick:()=>e(!1),style:{touchAction:"manipulation"},children:t.jsx(X,{name:"close",className:"size-5"})}),t.jsx("h2",{className:"min-w-0 flex-1 truncate px-1 typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Cs?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Cs}):null]}),Gn]})},Er="mobile-surface-root",gu=16,Rr=320,bu="cubic-bezier(0.22, 1, 0.36, 1)",xu=({open:n,onClose:e,onSwipeClose:s,ariaLabel:o,children:r})=>{const i=c.useRef(null),a=c.useRef(null),[u,d]=c.useState(!1),[f,l]=c.useState(n),p=c.useRef(e);c.useEffect(()=>{p.current=e},[e]);const b=c.useRef(s);if(c.useEffect(()=>{b.current=s},[s]),Wn(a,{enabled:n,onRightEdgeSwipe:()=>(b.current??p.current)()}),typeof document<"u"&&!i.current){let h=document.getElementById(Er);h||(h=document.createElement("div"),h.id=Er,document.body.appendChild(h)),i.current=h}return c.useEffect(()=>{if(n){l(!0);const v=window.setTimeout(()=>d(!0),gu);return()=>window.clearTimeout(v)}d(!1);const h=window.setTimeout(()=>l(!1),Rr+40);return()=>window.clearTimeout(h)},[n]),c.useEffect(()=>{if(!n)return;const h=document.body.style.overflow;document.body.style.overflow="hidden";const v=S=>{S.key==="Escape"&&p.current()};return document.addEventListener("keydown",v),()=>{document.body.style.overflow=h,document.removeEventListener("keydown",v)}},[n]),i.current?Ot.createPortal(t.jsx("section",{ref:a,role:"dialog","aria-modal":"true","aria-label":o,"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:u?"none":"translateX(-100%)",transition:`transform ${Rr}ms ${bu}`,visibility:f?"visible":"hidden",pointerEvents:n?"auto":"none"},children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:r})}),i.current):null},Pr=n=>{const e=le.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 u;e[4]!==r?(u=r?t.jsx("div",{className:"pt-2",children:r}):null,e[4]=r,e[5]=u):u=e[5];let d;return e[6]!==i||e[7]!==a||e[8]!==u?(d=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[i,a,u]}),e[6]=i,e[7]=a,e[8]=u,e[9]=d):d=e[9],d};function yu(n){n&&(n.focus(),n.select())}function vu(n){return Te(n.path)}function wu(n){return Te(n.path)}function ju(n){return t.jsx(pu,{worktree:n},Te(n.path))}const ku=(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}},Su=n=>{switch(n?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Nu=({active:n,className:e,headerAction:s,listClassName:o,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:a}=de(),d=yt(j=>j.currentDirectory)??null,f=as(j=>j.getStatusForDirectory(d)),l=as(j=>j.refresh),p=as(j=>j.connect),b=as(j=>j.disconnect),h=Mt(j=>j.mcpServers),v=Mt(j=>j.loadMcpConfigs),[S,w]=c.useState(!1),[T,N]=c.useState(null);c.useEffect(()=>{l({directory:d,silent:!0})},[l,d]),c.useEffect(()=>{v({force:!0})},[v]),c.useEffect(()=>{n&&Promise.all([l({directory:d,silent:!0}),v({force:!0})])},[n,l,d,v]);const E=c.useMemo(()=>{const j=new Set(Object.keys(f));for(const P of h)P?.name&&j.add(P.name);return Array.from(j).sort((P,k)=>P.localeCompare(k))},[h,f]),I=c.useCallback(j=>{if(j?.preventDefault(),S)return;w(!0);const P=new Promise(k=>setTimeout(k,500));Promise.all([l({directory:d}),P]).finally(()=>{w(!1)})},[S,l,d]);return t.jsxs("div",{className:J("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")}),d&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:d.split("/").pop()||d})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",disabled:S,onClick:I,"aria-label":a("mcpDropdown.actions.refreshAria"),children:t.jsx(X,{name:"refresh",className:J("h-4 w-4",S&&"animate-spin")})})]})]})}),t.jsx("div",{className:J("max-h-64 overflow-y-auto",i?"space-y-1 py-3":"px-3 py-2.5",o),children:t.jsxs("div",{className:J(!i&&E.length>0&&"rounded-xl bg-[var(--surface-muted)] p-1.5"),children:[E.map(j=>{const P=f[j],k=Su(P),R=P?.status==="connected",y=T===j,z=ku(P,a);return t.jsxs("div",{className:J("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(vi,{children:[t.jsx(wi,{asChild:!0,children:t.jsx("span",{className:J("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",k==="success"&&"bg-status-success",k==="error"&&"bg-status-error",k==="warning"&&"bg-status-warning",k==="default"&&"bg-muted-foreground/40"),"aria-label":z})}),t.jsx(ji,{side:"left",children:t.jsx("p",{children:z})})]}),t.jsx("span",{className:J("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:j})]})}),t.jsx(ki,{checked:R,disabled:y,className:"data-[checked]:bg-status-info",onCheckedChange:async M=>{N(j);try{if(!M){await b(j,d);return}const C=f?.[j]?.status;if(C==="needs_auth"||C==="needs_client_registration"){const{opened:x}=await Si({name:j,directory:d});x||or.error(a("mcpDropdown.toast.authorizeOpenFailed"));return}await p(j,d)}catch(C){or.error(C instanceof Error?C.message:a("mcpDropdown.toast.authorizeFailed"))}finally{N(null)}}})]},j)}),E.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:a("mcpDropdown.empty.configureInConfig")})]})})]})},Ar={status:"loading"},At={type:"list"},Cu=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),Eu=n=>{const e=n.index?.trim();return!!(e&&e!=="?")},Ru=n=>{const e=n.working_dir?.trim(),s=n.index?.trim();return!!(e||s==="?")},Tr=(n,e)=>e?`${n}\0staged`:n,Pu=n=>{const e=le.c(8),s=wn()??null;let o;e[0]!==s?(o=Cu(s),e[0]=s,e[1]=o):o=e[1];const r=o,i=n.visible??!0;let a;e[2]!==i?(a={enabled:i},e[2]=i,e[3]=a):a=e[3];const u=Ni(r||null,a);let d;return e[4]!==n||e[5]!==u||e[6]!==r?(d=t.jsx(Au,{...n,rootDirectory:r,repository:u}),e[4]=n,e[5]=u,e[6]=r,e[7]=d):d=e[7],d},Au=({rootDirectory:n,repository:e,onClose:s,initialDiff:o,visible:r=!0})=>{const{t:i}=de(),{git:a}=vn(),{rootIsGitRepo:u,gitDirectory:d,nestedRepos:f}=e,l=d??n,p=Ci(l||null),b=Ei(l||null),h=Hr(l||null),v=Ri(l||null),S=He(A=>A.setActiveDirectory),w=He(A=>A.ensureAll),T=He(A=>A.ensureNestedRepos),N=He(A=>A.selectNestedRepo),E=He(A=>A.fetchStatus),I=He(A=>A.fetchBranches),j=He(A=>A.prefetchDiffs),P=He(A=>A.getDiff),k=He(A=>A.setDiff),R=He(A=>A.runtimeKey),y=JSON.stringify([R,l]),z=c.useRef(y);z.current=y;const[M,C]=c.useState(()=>({ownerKey:y,mode:"working",route:o?.path?{type:"diff",path:o.path,staged:o.staged}:At})),x=M.ownerKey===y?M.mode:"working",D=M.ownerKey===y?M.route:At,[K,g]=c.useState(!1),L=c.useCallback(A=>{C({ownerKey:y,mode:A,route:At}),g(!1)},[y]),F=c.useCallback(A=>{C(O=>({ownerKey:y,mode:O.ownerKey===y?O.mode:"working",route:A}))},[y]);c.useEffect(()=>{C(A=>A.ownerKey===y?A:{ownerKey:y,mode:"working",route:At}),g(!1)},[y]),c.useEffect(()=>{r||g(!1)},[r]),c.useEffect(()=>{o?.path&&C({ownerKey:z.current,mode:"working",route:{type:"diff",path:o.path,staged:o.staged}})},[o]);const[B,W]=c.useState(null),[re,ne]=c.useState(null),[ee,_]=c.useState(""),[G,Y]=c.useState(new Set),[U,Z]=c.useState(!1),[te,se]=c.useState(!1),[ae,ue]=c.useState([]),[V,ie]=c.useState([]),[ye,ke]=c.useState([]),[q,ve]=c.useState(null),[Re,De]=c.useState(null),[_e,Ue]=c.useState(null),[Me,Fe]=c.useState(0),[Ce,Ee]=c.useState(null),we=p?.current??null,Ae=p?.tracking?.trim().split("/")[0],Xe=(Ae&&b?.defaultBranches?.[Ae])??b?.defaultBranches?.origin??null,Pe=Tl(we,Xe),lt=h===!1||Pl(we,Xe,p!==null,b!==null),Gt=yl(A=>A.setOverride),$e=vl(l||null,we,r&&x==="branch"&&Pe),Ve=wl(l||null,we,r&&x==="commit"&&h===!0),tt=Ve.selectedCommit?.hash??null,je=jl(l||null,we,r&&x==="pr"&&h===!0),Ge=je.selectedSource,Vs=c.useMemo(()=>x==="pr"?Ge:x==="branch"&&we&&$e.base?{kind:"branch",baseRef:$e.base,headRef:we}:x==="commit"&&tt?{kind:"commit",hash:tt}:null,[$e.base,we,x,tt,Ge]),Kt=x==="branch"?$e.revision:"",be=El(l||null,Vs,r&&h===!0,Kt),{fetchDiff:Ht}=be,qt=c.useMemo(()=>be.files?[...be.files].sort((A,O)=>A.path.localeCompare(O.path)):null,[be.files]),rt=D.type==="comparison"&&D.sourceKey===be.key?D.path:null,[ze,xs]=c.useState(0),St=c.useCallback(async A=>{try{const{diff:O}=await Ht(A),Q={original:"",modified:"",isBinary:kl(O)};return Q.isBinary||(Q.fileDiff=Sl(A,O)),{status:"ready",diff:Q}}catch(O){return{status:"error",message:O instanceof Error?O.message:i("diffView.state.failedToLoadDiff")}}},[Ht,i]),ys=Rl(be.files?x==="pr"?JSON.stringify([be.key,be.revision]):be.key:null,r&&rt?rt:"",r?St:null,Ar,JSON.stringify([Kt,x==="pr"?be.revision:0,ze])),mt=rt?ys.get(rt)??Ar:null;c.useEffect(()=>{x==="branch"&&lt&&L("working")},[lt,L,x]),c.useEffect(()=>{C(A=>A.ownerKey===y&&A.route.type==="comparison"&&A.route.sourceKey!==be.key?{...A,route:At}:A)},[be.key,y]);const Ke=c.useMemo(()=>{const A=p?.files??[],O=new Map;for(const Q of A)O.set(Q.path,Q);return Array.from(O.values()).sort((Q,xe)=>Q.path.localeCompare(xe.path))},[p?.files]),st=c.useMemo(()=>Ke.filter(Eu),[Ke]),Nt=c.useMemo(()=>Ke.filter(Ru),[Ke]),ct=c.useMemo(()=>{if(ye.length>0)return ye;const A=p?.tracking?.includes("/")?p.tracking.split("/")[0]:null;return A||q?[{name:A||"origin",fetchUrl:q??"",pushUrl:q??""}]:[]},[q,ye,p?.tracking]),Gs=He(c.useCallback(A=>!l||D.type!=="diff"?null:A.directories.get(l)?.diffCache.get(Tr(D.path,D.staged))??null,[l,D])),Jt=c.useMemo(()=>D.type!=="diff"?null:Ke.find(A=>A.path===D.path)??null,[Ke,D]),Oe=c.useCallback(async(A=!0)=>{if(l)try{await Promise.all([E(l,a),I(l,a)])}catch(O){A&&ce.error(O instanceof Error?O.message:i("gitView.toast.refreshRepositoryFailed"))}},[l,I,E,a,i]),Ks=c.useMemo(()=>(b?.all??[]).filter(A=>!A.startsWith("remotes/")).sort(),[b]),vs=c.useMemo(()=>(b?.all??[]).filter(A=>A.startsWith("remotes/")).map(A=>A.replace(/^remotes\//,"")).sort(),[b]),Ct=c.useCallback(async A=>{if(!l)return;const O=A.replace(/^remotes\//,"");try{const Q=await a.checkoutBranch(l,O);ce.success(i("gitView.toast.checkedOut",{name:Q.branch||O})),await Oe()}catch(Q){ce.error(Q instanceof Error?Q.message:i("gitView.toast.checkoutFailed",{name:O}))}},[l,a,Oe,i]),pt=c.useCallback(A=>{const O=A.replace(/^remotes\//,"");if((p?.files?.length??0)>0){Ee(O);return}Ct(O)},[Ct,p?.files]),ws=c.useCallback(async(A,O)=>{if(l)try{await a.createBranch(l,A,we??"HEAD"),await a.checkoutBranch(l,A),O&&await a.gitPush(l,{remote:O.name,branch:A,options:["--set-upstream"]}),await Oe()}catch(Q){throw ce.error(Q instanceof Error?Q.message:i("gitView.toast.createBranchFailed")),Q}},[we,l,a,Oe,i]),Et=c.useCallback(async()=>{if(!l){ke([]),ve(null);return}try{const[A,O]=await Promise.all([a.getRemotes(l).catch(()=>[]),a.getRemoteUrl?a.getRemoteUrl(l).catch(()=>null):Promise.resolve(null)]);ke(A),ve(O)}catch{ke([]),ve(null)}},[l,a]);c.useEffect(()=>{!l||!r||(S(l),w(l,a))},[l,w,a,S,r]),c.useEffect(()=>{r&&Et()},[Et,r]),c.useEffect(()=>{if(!r||x!=="working"||!l||Ke.length===0)return;const A=Array.from(new Set([...st.map(Q=>Q.path),...V,...Ke.slice(0,20).map(Q=>Q.path)])).filter(Boolean);if(A.length===0)return;const O=window.setTimeout(()=>{j(l,a,A,{maxFiles:40})},120);return()=>window.clearTimeout(O)},[Ke,l,a,x,j,st,V,r]),c.useEffect(()=>{if(!r)return;if(D.type!=="diff"){De(null);return}const A=Tr(D.path,D.staged);if(Ue(null),!l||P(l,A)){De(null);return}let O=!1;const Q=Ut();return De(null),a.getGitFileDiff(l,{path:D.path,staged:D.staged||void 0}).then(xe=>{O||k(l,A,{original:xe.original??"",modified:xe.modified??"",isBinary:xe.isBinary,submodule:xe.submodule},Q)}).catch(xe=>{if(!O){if(xe instanceof Yn&&xe.reason==="nested_repository"){Ue(`${l}\0${D.path}`);return}xe instanceof Yn&&E(l,a,{force:!0,silent:!0}),De(xe instanceof Error?xe.message:String(xe))}}),()=>{O=!0}},[l,Me,E,P,a,D,k,r]);const js=async(A,O)=>{if(l){W(A);try{const Q=xe=>{const Qe=`${xe.name}/`,ut=p?.tracking?.startsWith(Qe)?p.tracking.slice(Qe.length):void 0;return{remote:xe.name,branch:ut,rebase:!0}};if(A==="fetch"){if(!O)throw new Error(i("mobile.changes.noRemote"));await a.gitFetch(l,{remote:O.name}),ce.success(i("gitView.toast.fetchedFromRemote",{name:O.name}))}else if(A==="sync"){if(!O)throw new Error(i("mobile.changes.noRemote"));await a.gitFetch(l,{remote:O.name});const xe=await a.getGitStatus(l);if((xe.behind??0)>0){if((xe.files?.length??0)>0){ce.error(i("gitView.toast.commitOrStashBeforeSync"));return}await a.gitPull(l,Q(O))}((await a.getGitStatus(l)).ahead??0)>0&&await a.gitPush(l),ce.success(i("gitView.toast.alreadyUpToDate"))}await Oe(!1),await Et()}catch(Q){ce.error(Q instanceof Error?Q.message:i("gitView.toast.syncActionFailed",{action:i("gitView.sync.syncChanges")}))}finally{W(null)}}},ht=c.useCallback(async(A,O)=>{if(!(!l||A.length===0))try{O==="stage"?A.length>1?await Pi(l,A):await Ai(l,A[0]):A.length>1?await Ti(l,A):await Ii(l,A[0]),await Oe(!1)}catch(Q){ce.error(Q instanceof Error?Q.message:i(O==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[l,Oe,i]),Yt=c.useCallback((A,O=!1)=>{F({type:"diff",path:A,staged:O})},[F]),Xt=c.useCallback(async A=>{if(l){Y(O=>new Set(O).add(A));try{await a.revertGitFile(l,A),ce.success(i("gitView.toast.revertedFile",{path:A})),await Oe(!1)}catch(O){ce.error(O instanceof Error?O.message:i("gitView.toast.revertFailed"))}finally{Y(O=>{const Q=new Set(O);return Q.delete(A),Q})}}},[l,a,Oe,i]),Qt=c.useCallback(async A=>{if(!l||A.length===0||U)return;const O=Array.from(new Set(A));Z(!0),Y(new Set(O));try{await Promise.all(O.map(Q=>a.revertGitFile(l,Q))),await Oe(!1),ce.success(O.length===1?i("gitView.toast.revertedFilesSingle",{count:O.length}):i("gitView.toast.revertedFilesPlural",{count:O.length}))}catch(Q){ce.error(Q instanceof Error?Q.message:i("gitView.toast.revertFailed"))}finally{Y(new Set),Z(!1)}},[l,a,U,Oe,i]),Hs=c.useCallback(A=>{const O=A.map(Q=>Q.trim()).filter(Boolean);if(O.length===0){ue([]);return}_(Q=>`${Q.trim()}${Q.trim()?`
23
-
24
- `:""}${O.join(`
25
- `)}`.trim()),ue([])},[]),qs=c.useCallback(async()=>{if(!l)return;const A=st.map(O=>O.path).sort();if(A.length===0){ce.error(i("gitView.toast.selectFileToDescribe"));return}se(!0);try{const{message:O}=await sr(l,A);_(O.subject?.trim()??""),ue(Array.isArray(O.highlights)?O.highlights:[])}catch(O){ce.error(O instanceof Error?O.message:i("gitView.toast.generateCommitMessageFailed"))}finally{se(!1)}},[l,st,i]),ks=async(A={})=>{if(!l)return;if(!ee.trim()){ce.error(i("gitView.toast.enterCommitMessage"));return}const O=st.map(Q=>Q.path).sort();if(O.length===0){ce.error(i("gitView.toast.selectFileToCommit"));return}ne(A.pushAfter?"commitAndPush":"commit");try{if(await a.createGitCommit(l,ee.trim(),{files:O}),ce.success(i("gitView.toast.commitCreated")),_(""),ue([]),A.pushAfter){const Q=p?.tracking?.split("/")[0],xe=ct.find(Ns=>Ns.name===Q)??ct[0];if(!xe)throw new Error(i("mobile.changes.noRemote"));W("sync");const Qe=`${xe.name}/`,ut=p?.tracking?.startsWith(Qe)?p.tracking.slice(Qe.length):void 0;await a.gitFetch(l,{remote:xe.name}),((await a.getGitStatus(l)).behind??0)>0&&await a.gitPull(l,{remote:xe.name,branch:ut,rebase:!0}),((await a.getGitStatus(l)).ahead??0)>0&&await a.gitPush(l),await Oe(!1),await Et()}else await Oe(!1)}catch(Q){ce.error(Q instanceof Error?Q.message:i("gitView.toast.createCommitFailed"))}finally{ne(null),A.pushAfter&&W(null)}},Js=c.useMemo(()=>{const A=[];return st.length>0&&A.push({id:"staged",title:i("gitView.changes.stagedTitle"),entries:st,actionSymbol:"-",actionAllLabel:i("gitView.changes.unstageAllAria"),getActionLabel:O=>i("gitView.changes.unstageFileAria",{path:O}),onActionFile:O=>{ht([O],"unstage")},onActionAll:O=>{ht(O,"unstage")},onViewDiff:O=>Yt(O,!0),onRevertFile:Xt,showRevertActions:!1,accent:!0}),Nt.length>0&&A.push({id:"unstaged",title:i("gitView.changes.title"),entries:Nt,actionSymbol:"+",actionAllLabel:i("gitView.changes.stageAllAria"),getActionLabel:O=>i("gitView.changes.stageFileAria",{path:O}),onActionFile:O=>{ht([O],"stage")},onActionAll:O=>{ht(O,"stage")},onViewDiff:O=>Yt(O,!1),onRevertFile:Xt}),A},[Xt,Yt,ht,st,i,Nt]),Zt=A=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":i("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(X,{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:i("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:p?.current||l||""})]}),u===!1&&Array.isArray(f)&&f.length>0?t.jsx($a,{repositories:f,selectedRepository:d??null,onSelectRepository:O=>{n&&N(n,O)},repositoryRoot:n??void 0}):null]}),t.jsx("div",{className:"min-h-0 flex-1",children:A})]});if(!l)return Zt(t.jsx(et,{message:i("gitView.empty.selectSessionOrDirectory")}));if(u===!1&&h!==!0)return Zt(t.jsx(Fa,{rootIsGitRepo:u,resolvedIsGitRepo:h,nestedRepos:f,onRetryDiscovery:()=>{n&&T(n,{force:!0})}}));if(v&&h===null)return Zt(t.jsx(et,{loading:!0,message:i("gitView.loading.checkingRepository")}));if(D.type==="diff")return t.jsx(Ir,{path:D.path,diff:Gs,staged:D.staged,fileExists:!!Jt,isNestedRepository:_e===`${l}\0${D.path}`,error:Re,onBack:()=>F({type:"list"}),onRetry:()=>Fe(A=>A+1)});const Ss=i(x==="pr"?"session.githubIntegration.tabs.pullRequests":x==="branch"?"diffView.scope.branch":x==="commit"?"commitComparison.mode":"mobile.nav.changes"),es=x==="branch"&&$e.base?Oa($e.base):x==="commit"?tt?.slice(0,8):x==="pr"&&Ge?`#${Ge.number}`:null;if(rt&&mt)return t.jsx(Ir,{path:rt,subtitle:[Ss,es].filter(Boolean).join(" · "),diff:mt.status==="ready"?mt.diff:null,fileExists:!be.files||be.files.some(A=>A.path===rt),error:be.error??(mt.status==="error"?mt.message:null),onBack:()=>F(At),onRetry:()=>{be.error&&be.refresh(),xs(A=>A+1)}});const Vn=()=>x==="pr"&&!Ge?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx(et,{loading:je.loading,message:je.error??(je.loading?i("session.githubPrPicker.loading.pullRequests"):i("pullRequestComparison.select"))}),!je.loading&&t.jsx(ir,{mobile:!0,comparison:je})]}):x==="branch"&&!$e.base?t.jsx(et,{loading:!$e.resolved,message:$e.resolved?i("gitView.pr.toast.baseBranchRequired"):i("diffView.branch.resolvingBase")}):x==="commit"&&!tt?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[Ve.loading&&t.jsx(X,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:Ve.loading?i("diffView.state.loadingChanges"):Ve.error??i("commitComparison.noCommits")}),Ve.error&&t.jsx(pe,{variant:"outline",size:"lg",onClick:()=>{Ve.refresh()},children:i("diffView.actions.retry")})]}):be.error?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx("p",{className:"typography-ui-label font-semibold",children:i("diffView.state.failedToLoadDiff")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:be.error}),t.jsx(pe,{variant:"outline",size:"lg",onClick:()=>{be.refresh()},children:i("diffView.actions.retry")})]}):qt?qt.length===0?t.jsx(et,{icon:x==="branch",message:x==="pr"?i("walkthrough.blocked.emptyDiff.description"):x==="commit"?i("commitComparison.emptyDiff"):i("diffView.branch.empty",{base:es??""})}):t.jsx(Tu,{files:qt,onSelect:A=>{be.key&&F({type:"comparison",path:A,sourceKey:be.key})}}):t.jsx(et,{loading:!0,message:i("diffView.state.loadingChanges")});return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":i("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(X,{name:"close",className:"size-5"})}):null,t.jsxs(Di,{open:K,onOpenChange:g,children:[t.jsx(_i,{asChild:!0,children:t.jsxs(pe,{variant:"outline",className:Mi({size:"default"}),"data-mobile-comparison-trigger":!0,"aria-label":i("diffView.scope.selectorAria"),children:[t.jsx("span",{children:Ss}),t.jsx(X,{name:"arrow-down-s",className:"size-4"})]})}),t.jsx(zi,{align:"start",children:t.jsxs(Oi,{value:x,onValueChange:A=>{(A==="working"||A==="branch"||A==="commit"||A==="pr")&&L(A)},children:[t.jsx(Rs,{value:"working",className:"min-h-8 items-center",children:i("mobile.nav.changes")}),Pe&&t.jsx(Rs,{value:"branch",className:"min-h-8 items-center",children:i("diffView.scope.branch")}),t.jsx(Rs,{value:"commit",className:"min-h-8 items-center",children:i("commitComparison.mode")}),t.jsx(Rs,{value:"pr",className:"min-h-8 items-center",children:i("session.githubIntegration.tabs.pullRequests")})]})})]}),r&&x==="branch"&&t.jsx(Nl,{mobile:!0,branches:b?.all??[],currentBranch:we,base:$e.base,onSelect:A=>{we&&Gt(l,we,A)}},JSON.stringify([y,we])),r&&x==="commit"&&t.jsx(Cl,{mobile:!0,commits:Ve.commits,selectedHash:tt,loading:Ve.loading,error:Ve.error,onSelect:Ve.select,onRefresh:()=>{Ve.refresh()}},JSON.stringify([y,we])),r&&x==="pr"&&t.jsxs(t.Fragment,{children:[t.jsx(ir,{mobile:!0,comparison:je},JSON.stringify([y,we])),Ge&&t.jsx(pe,{variant:"ghost",size:"sm",disabled:be.loading,"aria-label":i("session.githubIssuePicker.actions.refresh"),onClick:()=>{be.refresh()},children:t.jsx(X,{name:"refresh",className:"size-4"})})]})]}),x==="working"&&t.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(Ba,{currentBranch:p?.current,localBranches:Ks,remoteBranches:vs,branchInfo:b?.branches,currentBranchAhead:p?.ahead,onCheckout:A=>{pt(A)},onCreate:ws,remotes:ct,disabled:v,directory:l,switchBlockedNotice:(p?.files?.length??0)>0?i("gitView.branch.switchBlockedNotice"):null})}),t.jsx(La,{syncAction:B,remotes:ct,onFetch:A=>{js("fetch",A)},onSync:A=>{js("sync",A)},disabled:re!==null||v,aheadCount:p?.ahead??0,behindCount:p?.behind??0,trackingRemoteName:p?.tracking?.split("/")[0],hasUncommittedChanges:Ke.length>0})]}),x!=="working"?t.jsx("div",{className:"min-h-0 flex-1",children:Vn()}):Ke.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(gl,{groups:Js,diffStats:p?.diffStats,revertingPaths:G,onRevertAll:Qt,isRevertingAll:U,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:ie})}),t.jsx("div",{className:"shrink-0 border-t border-border/70 px-4 pb-4 pt-3",children:t.jsx(bl,{stagedCount:st.length,commitMessage:ee,onCommitMessageChange:_,generatedHighlights:ae,onInsertHighlights:Hs,onGenerateMessage:qs,isGeneratingMessage:te,onCommit:()=>{ks({pushAfter:!1})},onCommitAndPush:()=>{ks({pushAfter:!0})},commitAction:re,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(et,{icon:!0,message:i("gitView.empty.cleanTitle"),description:i("mobile.changes.cleanDescription")})}),t.jsx(xl,{open:Ce!==null,onOpenChange:A=>{A||Ee(null)},targetBranch:Ce??"",changedFileCount:p?.files?.length??0,onCommitAndSwitch:async(A,O)=>{const Q=Ce;if(!Q||!l)return;const xe=p?.current??null;await a.createGitCommit(l,A,{addAll:!0});let Qe=null;if(O){const ut=p?.tracking?.split("/")[0],dt=ct.find(ts=>ts.name===ut)??ct[0];try{if(!dt)throw new Error(i("mobile.changes.noRemote"));await a.gitPush(l,p?.tracking?{remote:dt.name}:{remote:dt.name,branch:xe??void 0,options:["--set-upstream"]}),Qe=dt.name}catch{ce.error(i("gitView.dirtySwitch.pushFailed")),await Oe(),Ee(null);return}}ce.success(xe?Qe?i("gitView.toast.pushedToUpstream",{name:Qe}):i("gitView.dirtySwitch.committedNotPushed",{branch:xe}):i("gitView.toast.commitCreated")),await Oe(),Ee(null),await Ct(Q)},onGenerateMessage:async()=>{if(!l)return"";const A=(p?.files??[]).map(Q=>Q.path).sort(),{message:O}=await sr(l,A);return O.subject?.trim()??""},onRevertAndSwitch:async()=>{const A=Ce;if(!A||!l)return;await Qt((p?.files??[]).map(Q=>Q.path));const O=await a.getGitStatus(l);if(!O.isClean&&(O.files?.length??0)>0){ce.error(i("gitView.dirtySwitch.revertIncomplete"));return}Ee(null),await Ct(A)}})]})},et=n=>{const e=le.c(13),{message:s,description:o,loading:r,icon:i}=n,a=r===void 0?!1:r,u=i===void 0?!1:i;let d;e[0]!==a?(d=a?t.jsx(X,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=d):d=e[1];let f;e[2]!==u?(f=u?t.jsx(X,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=u,e[3]=f):f=e[3];let l;e[4]!==s?(l=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:s}),e[4]=s,e[5]=l):l=e[5];let p;e[6]!==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 b;return e[8]!==d||e[9]!==f||e[10]!==l||e[11]!==p?(b=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:[d,f,l,p]})}),e[8]=d,e[9]=f,e[10]=l,e[11]=p,e[12]=b):b=e[12],b},Ir=n=>{const e=le.c(31),{path:s,subtitle:o,diff:r,staged:i,fileExists:a,isNestedRepository:u,error:d,onBack:f,onRetry:l}=n,p=i===void 0?!1:i,b=u===void 0?!1:u,{t:h}=de();let v;e[0]!==s?(v=Bi(s)||"text",e[0]=s,e[1]=v):v=e[1];const S=v;let w;e[2]!==h?(w=h("header.actions.backAria"),e[2]=h,e[3]=w):w=e[3];let T;e[4]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(X,{name:"arrow-left",className:"size-5"}),e[4]=T):T=e[4];let N;e[5]!==f||e[6]!==w?(N=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":w,onClick:f,children:T}),e[5]=f,e[6]=w,e[7]=N):N=e[7];let E;e[8]!==s?(E=t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:s}),e[8]=s,e[9]=E):E=e[9];let I;e[10]!==o?(I=o&&t.jsx("p",{className:"truncate typography-meta text-muted-foreground",children:o}),e[10]=o,e[11]=I):I=e[11];let j;e[12]!==E||e[13]!==I?(j=t.jsxs("div",{className:"min-w-0 flex-1 px-2",children:[E,I]}),e[12]=E,e[13]=I,e[14]=j):j=e[14];let P;e[15]!==N||e[16]!==j?(P=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/70 px-3 text-foreground",children:[N,j]}),e[15]=N,e[16]=j,e[17]=P):P=e[17];let k;e[18]!==r||e[19]!==d||e[20]!==a||e[21]!==b||e[22]!==S||e[23]!==l||e[24]!==s||e[25]!==p||e[26]!==h?(k=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:a?b?t.jsx(et,{icon:!0,message:h("diffView.unavailable.nestedRepositoryTitle"),description:h("diffView.unavailable.nestedRepositoryDescription")}):d?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:h("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:d}),t.jsx(pe,{type:"button",size:"sm",variant:"outline",onClick:l,children:h("diffView.actions.retry")})]})}):r?r.submodule?t.jsx("div",{className:"p-3",children:t.jsx(Al,{state:r.submodule,staged:p})}):r.isBinary?t.jsx(et,{icon:!0,message:h("diffView.binary.unavailable")}):Li(s)&&!r.fileDiff?t.jsx(et,{icon:!0,message:h("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(Fs,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(Il,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:S,fileName:s,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(et,{loading:!0,message:h("diffView.state.loadingDiff")}):t.jsx(et,{icon:!0,message:h("mobile.changes.diffDetail.missingTitle"),description:h("mobile.changes.diffDetail.missingDescription")})}),e[18]=r,e[19]=d,e[20]=a,e[21]=b,e[22]=S,e[23]=l,e[24]=s,e[25]=p,e[26]=h,e[27]=k):k=e[27];let R;return e[28]!==P||e[29]!==k?(R=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[P,k]}),e[28]=P,e[29]=k,e[30]=R):R=e[30],R},Tu=n=>{const e=le.c(12),{files:s,onSelect:o}=n,{t:r}=de();let i;e[0]!==r?(i=r("gitView.changes.changedFilesAria"),e[0]=r,e[1]=i):i=e[1];let a;if(e[2]!==s||e[3]!==o||e[4]!==r){let d;e[6]!==o||e[7]!==r?(d=f=>{const l=f.status==="A"?r("diffView.change.new"):f.status==="D"?r("diffView.change.deleted"):f.status==="R"?r("diffView.change.renamed"):f.status==="C"?r("diffView.change.copied"):r("diffView.change.modified"),p=f.status==="A"?"var(--status-success)":f.status==="D"?"var(--status-error)":f.status==="R"||f.status==="C"?"var(--status-info)":"var(--status-warning)";return t.jsx("li",{children:t.jsxs(pe,{variant:"ghost",size:"lg",className:"w-full justify-start gap-2.5 text-left normal-case",onClick:()=>o(f.path),children:[t.jsx("span",{className:"w-4 shrink-0 text-center typography-meta font-semibold uppercase",style:{color:p},"aria-label":l,children:f.status}),t.jsx(ro,{filePath:f.path,className:"size-4 shrink-0"}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label",title:f.path,children:f.path}),(f.insertions>0||f.deletions>0)&&t.jsxs("span",{className:"shrink-0 typography-meta text-muted-foreground",children:["+",f.insertions," -",f.deletions]}),t.jsx(X,{name:"arrow-right-s",className:"size-4 shrink-0 text-muted-foreground"})]})},f.path)},e[6]=o,e[7]=r,e[8]=d):d=e[8],a=s.map(d),e[2]=s,e[3]=o,e[4]=r,e[5]=a}else a=e[5];let u;return e[9]!==i||e[10]!==a?(u=t.jsx(Fs,{className:"h-full overflow-y-auto overflow-x-hidden px-3 py-2",children:t.jsx("ul",{"aria-label":i,className:"flex flex-col gap-1",children:a})}),e[9]=i,e[10]=a,e[11]=u):u=e[11],u},Iu=c.lazy(()=>Bt(()=>import("./FilesView-vjJx7VaM.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125])).then(n=>({default:n.FilesView}))),jt=n=>(n||"").replace(/\\/g,"/").replace(/\/+$/g,""),ps=n=>{const e=jt(n);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},Du=n=>{const e=jt(n);if(!e||e==="/")return null;const s=e.lastIndexOf("/");return s<=0?e.startsWith("/")?"/":null:e.slice(0,s)},_u=(n,e)=>{const s=jt(n),o=jt(e);return!o||s===o?ps(s):s.startsWith(`${o}/`)?s.slice(o.length+1):s},Mu=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""},zu=({onClose:n})=>{const{t:e}=de(),{files:s}=vn(),o=Vo(g=>g.setSelectedPath),r=jt(wn()??null),[i,a]=c.useState(()=>({type:"browser",directory:r})),[u,d]=c.useState([]),[f,l]=c.useState(!1),[p,b]=c.useState(null),[h,v]=c.useState(""),[S,w]=c.useState([]),[T,N]=c.useState(!1),E=c.useRef(0);c.useEffect(()=>{r&&a(g=>g.type==="browser"&&g.directory?g:{type:"browser",directory:r})},[r]);const I=i.type==="browser"?i.directory:i.returnDirectory,j=c.useCallback(async g=>{if(!g)return;const L=E.current+1;E.current=L,l(!0),b(null);try{const F=await s.listDirectory(g);if(E.current!==L)return;d(F.entries.slice().sort((B,W)=>B.isDirectory!==W.isDirectory?B.isDirectory?-1:1:B.name.localeCompare(W.name)))}catch(F){if(E.current!==L)return;d([]),b(F instanceof Error?F.message:e("mobile.files.error.listFailed"))}finally{E.current===L&&l(!1)}},[s,e]);c.useEffect(()=>{i.type==="browser"&&j(i.directory)},[j,i]),c.useEffect(()=>{if(i.type!=="browser")return;const g=h.trim();if(!g){w([]),N(!1);return}let L=!1;const F=window.setTimeout(()=>{N(!0),s.search({directory:i.directory,query:g,maxResults:40}).then(B=>{L||w(B)}).catch(()=>{L||w([])}).finally(()=>{L||N(!1)})},250);return()=>{L=!0,window.clearTimeout(F)}},[s,h,i]);const P=g=>{v(""),a({type:"browser",directory:g})},k=g=>{o(r,g),a({type:"file",path:g,returnDirectory:I||r})},R=it(g=>g.pendingFileFocusPath),y=it(g=>g.pendingFileNavigation);if(c.useEffect(()=>{const g=jt(y?.path??R??"");!g||!r||g!==r&&!g.startsWith(`${r}/`)||(o(r,g),a({type:"file",path:g,returnDirectory:r}),R&&it.getState().setPendingFileFocusPath(null))},[R,y,r,o]),!r)return t.jsx(hs,{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-ring","aria-label":e("header.actions.backAria"),onClick:()=>a({type:"browser",directory:i.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(rr,{className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:ps(i.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Ye,{children:t.jsx(c.Suspense,{fallback:t.jsx(hs,{loading:!0,message:e("filesView.state.loading")}),children:t.jsx(Iu,{mode:"editor-only"})})})})]});const z=i.directory===r?e("mobile.files.rootDirectory"):ps(i.directory),M=h.trim()?S:[],C=Du(i.directory),x=i.directory!==r&&C!==null&&(C===r||C.startsWith(`${r}/`)),D=x&&!h.trim(),K=x?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-ring","aria-label":e("mobile.surface.closeAria"),onClick:n,style:{touchAction:"manipulation"},children:t.jsx(cl,{className:"size-5"})}):null,D&&K?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("mobile.files.backToParentAria",{name:ps(K)}),onClick:()=>P(K),style:{touchAction:"manipulation"},children:t.jsx(rr,{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:z})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("mobile.files.refreshAria"),onClick:()=>{j(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(ul,{className:J("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(dl,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(eo,{value:h,onChange:g=>v(g.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(Fs,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:p?t.jsx(hs,{message:p}):h.trim()?t.jsx(Ou,{results:M,isSearching:T,onOpenFile:k}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:[u.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,u.map(g=>t.jsx(_o,{name:g.name,path:g.path,directory:g.isDirectory,meta:g.isDirectory?void 0:Mu(g.size),onClick:()=>g.isDirectory?P(g.path):k(g.path)},g.path))]})})]})},_o=n=>{const e=le.c(16),{name:s,path:o,directory:r,meta:i,onClick:a}=n;let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={touchAction:"manipulation"},e[0]=u):u=e[0];let d;e[1]!==r||e[2]!==o?(d=r?t.jsx(fl,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(ro,{filePath:o,className:"size-5 shrink-0"}),e[1]=r,e[2]=o,e[3]=d):d=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 l;e[6]!==i?(l=i?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,e[6]=i,e[7]=l):l=e[7];let p;e[8]!==r?(p=r?t.jsx(ml,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=r,e[9]=p):p=e[9];let b;return e[10]!==a||e[11]!==d||e[12]!==f||e[13]!==l||e[14]!==p?(b=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",onClick:a,style:u,children:[d,f,l,p]}),e[10]=a,e[11]=d,e[12]=f,e[13]=l,e[14]=p,e[15]=b):b=e[15],b},Ou=n=>{const e=le.c(10),{results:s,isSearching:o,onOpenFile:r}=n,{t:i}=de(),a=jt(wn()??null);if(o){let l;e[0]!==i?(l=i("common.loading"),e[0]=i,e[1]=l):l=e[1];let p;return e[2]!==l?(p=t.jsx(hs,{loading:!0,message:l}),e[2]=l,e[3]=p):p=e[3],p}if(s.length===0){let l;e[4]!==i?(l=i("mobile.files.search.empty"),e[4]=i,e[5]=l):l=e[5];let p;return e[6]!==l?(p=t.jsx(hs,{message:l}),e[6]=l,e[7]=p):p=e[7],p}const u="overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",d=s.map(l=>t.jsx(_o,{name:ps(l.path),path:l.path,directory:!1,meta:_u(l.path,a),onClick:()=>r(l.path)},l.path));let f;return e[8]!==d?(f=t.jsx("div",{className:u,children:d}),e[8]=d,e[9]=f):f=e[9],f},hs=n=>{const e=le.c(7),{message:s,loading:o}=n,r=o===void 0?!1:o;let i;e[0]!==r?(i=r?t.jsx(pl,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(hl,{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 u;return e[4]!==i||e[5]!==a?(u=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]=u):u=e[6],u},Dr="mobile-surface-root",Bu=16,_r=320,Lu="cubic-bezier(0.22, 1, 0.36, 1)",$u=n=>{const e=le.c(36),{onOpenMcpSettings:s}=n,{t:o}=de(),[r,i]=c.useState(!1),a=yt(Fu),u=as(Wu),d=Mt(Uu);let f;e[0]!==a||e[1]!==r||e[2]!==d||e[3]!==u?(f=()=>{if(r)return;i(!0);const z=new Promise(Vu);Promise.all([u({directory:a||null,silent:!0}),d({force:!0}),z]).finally(()=>i(!1))},e[0]=a,e[1]=r,e[2]=d,e[3]=u,e[4]=f):f=e[4];const l=f;let p;e[5]!==o?(p=o("settings.mcp.sidebar.actions.addServerTitle"),e[5]=o,e[6]=p):p=e[6];let b;e[7]!==o?(b=o("settings.mcp.sidebar.actions.addServerTitle"),e[7]=o,e[8]=b):b=e[8];let h,v;e[9]===Symbol.for("react.memo_cache_sentinel")?(h={touchAction:"manipulation"},v=t.jsx(X,{name:"add",className:"size-5"}),e[9]=h,e[10]=v):(h=e[9],v=e[10]);let S;e[11]!==s||e[12]!==p||e[13]!==b?(S=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:s,"aria-label":p,title:b,style:h,children:v}),e[11]=s,e[12]=p,e[13]=b,e[14]=S):S=e[14];let w;e[15]!==o?(w=o("mcpDropdown.actions.refreshAria"),e[15]=o,e[16]=w):w=e[16];let T;e[17]!==o?(T=o("mcpDropdown.actions.refreshAria"),e[17]=o,e[18]=T):T=e[18];let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N={touchAction:"manipulation"},e[19]=N):N=e[19];const E=r&&"animate-spin";let I;e[20]!==E?(I=J("size-5",E),e[20]=E,e[21]=I):I=e[21];let j;e[22]!==I?(j=t.jsx(X,{name:"refresh",className:I}),e[22]=I,e[23]=j):j=e[23];let P;e[24]!==r||e[25]!==l||e[26]!==j||e[27]!==w||e[28]!==T?(P=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:l,disabled:r,"aria-label":w,title:T,style:N,children:j}),e[24]=r,e[25]=l,e[26]=j,e[27]=w,e[28]=T,e[29]=P):P=e[29];let k;e[30]!==P||e[31]!==S?(k=t.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1 px-2 pt-1",children:[S,P]}),e[30]=P,e[31]=S,e[32]=k):k=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(Nu,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})}),e[33]=R):R=e[33];let y;return e[34]!==k?(y=t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[k,R]}),e[34]=k,e[35]=y):y=e[35],y},Mr=({open:n,onClose:e,tab:s,onTabChange:o,pendingChangesDiff:r,onOpenPlan:i,onOpenMcpSettings:a,variant:u="drawer"})=>{const{t:d}=de(),f=c.useRef(null),l=c.useRef(null),[p,b]=c.useState(!1),[h,v]=c.useState(n),S=c.useRef(e);c.useEffect(()=>{S.current=e},[e]);const w=c.useRef(s);c.useEffect(()=>{w.current=s},[s]),Wn(l,{enabled:u==="drawer"&&n,onLeftEdgeSwipe:()=>S.current()});const[T,N]=c.useState(()=>new Set);if(c.useEffect(()=>{n&&N(j=>{if(j.has(s))return j;const P=new Set(j);return P.add(s),P})},[n,s]),typeof document<"u"&&!f.current){let j=document.getElementById(Dr);j||(j=document.createElement("div"),j.id=Dr,document.body.appendChild(j)),f.current=j}if(c.useEffect(()=>{if(n){v(!0);const P=window.setTimeout(()=>b(!0),Bu);return()=>window.clearTimeout(P)}b(!1);const j=window.setTimeout(()=>v(!1),_r+40);return()=>window.clearTimeout(j)},[n]),c.useEffect(()=>{if(!n)return;const j=document.body.style.overflow;u==="drawer"&&(document.body.style.overflow="hidden");const P=k=>{k.key!=="Escape"||w.current==="terminal"||Fi(k.target)||S.current()};return document.addEventListener("keydown",P),()=>{u==="drawer"&&(document.body.style.overflow=j),document.removeEventListener("keydown",P)}},[n,u]),u==="drawer"&&!f.current)return null;const E=[{id:"changes",label:d("mobile.menu.changes"),icon:t.jsx(X,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"files",label:d("mobile.menu.files"),icon:t.jsx(X,{name:"file-text",className:"h-3.5 w-3.5"})},{id:"terminal",label:d("mobile.menu.terminal"),icon:t.jsx(X,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"notes",label:d("contextRail.surface.notes"),icon:t.jsx(X,{name:"sticky-note",className:"h-3.5 w-3.5"})},{id:"mcp",label:d("mobile.menu.mcp"),icon:t.jsx($i,{className:"h-3.5 w-3.5"})}],I=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("div",{className:"flex h-9 min-w-0 flex-1 items-center",children:h?t.jsx(Wa,{items:E,activeId:s,onSelect:j=>o(j),layoutMode:"fit",variant:"active-pill",nonCompositedIndicator:!0,inactiveTabsIconOnly:!0,className:"h-full"}):null}),t.jsx("button",{type:"button",className:"-mr-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":d("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(X,{name:"close",className:"size-5"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[T.has("changes")?t.jsx("div",{className:J("h-full",s!=="changes"&&"hidden"),children:t.jsx(Ye,{children:t.jsx(Pu,{visible:n&&s==="changes",initialDiff:r})})},r?`changes:${r.path}:${r.staged}`:"changes"):null,T.has("files")?t.jsx("div",{className:J("h-full",s!=="files"&&"hidden"),children:t.jsx(Ye,{children:t.jsx(zu,{})})}):null,T.has("terminal")?t.jsx("div",{className:J("h-full",s!=="terminal"&&"hidden"),children:t.jsx(Ye,{children:t.jsx(Ua,{visible:n&&s==="terminal"})})}):null,T.has("notes")?t.jsx("div",{className:J("h-full",s!=="notes"&&"hidden"),children:t.jsx(Ye,{children:t.jsx(Va,{onActionComplete:e,onOpenPlan:i})})}):null,T.has("mcp")?t.jsx("div",{className:J("h-full",s!=="mcp"&&"hidden"),children:t.jsx(Ye,{children:t.jsx($u,{onOpenMcpSettings:a})})}):null]})]});return u==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:I}):Ot.createPortal(t.jsx("section",{ref:l,role:"dialog","aria-modal":"true","aria-label":d("mobile.header.openWorkspaceAria"),"aria-hidden":!n,className:"oc-keyboard-inset-surface oc-bottom-safe-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:p?"none":"translateX(100%)",transition:`transform ${_r}ms ${Lu}`,visibility:h?"visible":"hidden",pointerEvents:n?"auto":"none"},children:I}),f.current)};function Fu(n){return n.currentDirectory}function Wu(n){return n.refresh}function Uu(n){return n.loadMcpConfigs}function Vu(n){return window.setTimeout(n,500)}function Gu(n){const e=le.c(4),s=2500,{uiFont:o}=Wi(),[r,i]=c.useState(!1);let a,u;return e[0]!==s||e[1]!==o?(a=()=>{let d=!1;const f=()=>{d||i(!0)},l=()=>{requestAnimationFrame(()=>requestAnimationFrame(f))},p=Promise.all([Ui(o).catch(Yu),document.fonts?.ready?.then(Ju).catch(qu)??Promise.resolve(),Dl.catch(Hu)]).then(Ku),b=new Promise(h=>{window.setTimeout(h,s)});return Promise.race([p,b]).then(l),()=>{d=!0}},u=[o,s],e[0]=s,e[1]=o,e[2]=a,e[3]=u):(a=e[2],u=e[3]),c.useEffect(a,u),r}function Ku(){}function Hu(){}function qu(){}function Ju(){}function Yu(){}const Xu="openchamber",Qu=n=>n.replace(/^\/+|\/+$/g,""),Zu=n=>{const e=Qu(n.pathname).split("/").filter(Boolean);return n.host?[n.host,...e]:e};function ed(n){if(typeof n!="string"||n.length===0)return null;let e;try{e=new URL(n)}catch{return null}if(e.protocol!==`${Xu}:`)return null;const s=Zu(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 qe={},Mo=!1,ms=null;const td=n=>{switch(n.type){case"session":return Ne.getState().setCurrentSession(n.sessionId,n.directory??null),!0;case"new-session":{const e=Ne.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 qe.openSessions?(qe.openSessions(n.filter),!0):!1;case"status":return qe.openSessions?(qe.openSessions(),!0):!1;case"view":return qe.openView?(qe.openView(n.target),!0):!1;case"changes":return qe.openChanges?(qe.openChanges({path:n.path,staged:n.staged}),!0):!1;case"settings":return qe.openSettings?(qe.openSettings(n.section),!0):!1}},Un=()=>{if(!Mo||!ms)return;const n=ms;ms=null,td(n)||(ms=n)},zo=n=>{ms=n,Un()},zr=n=>{const e=ed(n);e&&zo(e)},sd=n=>{Mo=n,Un()},nd=n=>{const e=le.c(3);let s,o;e[0]!==n?(s=()=>(qe=n,Un(),()=>{qe===n&&(qe={})}),o=[n],e[0]=n,e[1]=s,e[2]=o):(s=e[1],o=e[2]),c.useEffect(s,o)},rd=n=>{const{ready:e}=n;c.useEffect(()=>{sd(e)},[e]),c.useEffect(()=>{if(!Be())return;let s=!1;const o=[];return Bt(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([126,5,127])).then(async({App:r})=>{if(s)return;const i=await r.addListener("appUrlOpen",a=>{zr(a?.url)});if(s){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),Bt(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([128,127])).then(async({PushNotifications:r})=>{if(s)return;const i=await r.addListener("pushNotificationActionPerformed",a=>{const u=a?.notification?.data,d=typeof u?.url=="string"?u.url:typeof u?.deeplink=="string"?u.deeplink:void 0;if(d){zr(d);return}const f=typeof u?.sessionId=="string"?u.sessionId:void 0;f&&zo({type:"session",sessionId:f})});if(s){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),()=>{s=!0,o.forEach(r=>r())}},[])},od=()=>{if(typeof window>"u")return;const n=window.__OPENCHAMBER_APNS_ENV__;if(n==="development")return"sandbox";if(n==="production")return"production"},id=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},ad=n=>{const{enabled:e}=n,s=it(r=>r.nativeNotificationsEnabled),o=c.useRef(null);c.useEffect(()=>{if(!e||!s||!id())return;let r=!1;const i=[];return Bt(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([128,127])).then(async({PushNotifications:a})=>{if(r)return;let u=await a.checkPermissions().catch(()=>null);if(u?.receive!=="granted"&&(u=await a.requestPermissions().catch(()=>null)),u?.receive!=="granted")return;const d=await a.addListener("registration",l=>{o.current=l.value,Xn()?.push?.registerApnsToken?.({token:l.value,platform:$r(),environment:od()})}),f=await a.addListener("registrationError",l=>{console.warn("[Push] APNs registration error:",l)});if(await a.register().catch(()=>{}),r){d.remove(),f.remove();return}i.push(()=>{d.remove()},()=>{f.remove()})}).catch(()=>{}),()=>{r=!0,i.forEach(a=>a())}},[e,s]),c.useEffect(()=>{if(s)return;const r=o.current;if(!r)return;o.current=null,Xn()?.push?.unregisterApnsToken?.({token:r})},[s])},Or=n=>{const e=le.c(12),{side:s,isResizing:o,ariaLabel:r,handleProps:i}=n,a=s==="left"?"right-0":"left-0";let u;e[0]!==a?(u=J("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",a),e[0]=a,e[1]=u):u=e[1];const d=s==="left"?"right-0":"left-0",f=o&&"bg-[var(--interactive-border)]";let l;e[2]!==d||e[3]!==f?(l=J("absolute inset-y-0 w-[3px] transition-colors",d,f),e[2]=d,e[3]=f,e[4]=l):l=e[4];let p;e[5]!==l?(p=t.jsx("div",{className:l}),e[5]=l,e[6]=p):p=e[6];let b;return e[7]!==r||e[8]!==i||e[9]!==u||e[10]!==p?(b=t.jsx("div",{className:u,role:"separator","aria-orientation":"vertical","aria-label":r,...i,children:p}),e[7]=r,e[8]=i,e[9]=u,e[10]=p,e[11]=b):b=e[11],b},ld=320,cd=380,Br=280,ud=560,dd=900;function Lr(n,e,s,o){const r=le.c(23),i=o===void 0?ud:o,a=c.useRef(null);let u;r[0]!==s||r[1]!==i||r[2]!==e?(u=()=>{if(typeof window>"u")return s;const x=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(x)?Math.min(i,Math.max(Br,x)):s},r[0]=s,r[1]=i,r[2]=e,r[3]=u):u=r[3];const[d,f]=c.useState(u),[l,p]=c.useState(!1),b=c.useRef(0),h=c.useRef(d),v=c.useRef(null),S=c.useRef(null);let w;r[4]!==i?(w=x=>Math.min(i,Math.max(Br,Math.round(x))),r[4]=i,r[5]=w):w=r[5];const T=w;let N;r[6]===Symbol.for("react.memo_cache_sentinel")?(N=x=>{const D=a.current;D&&(D.style.width=`${x}px`,D.style.minWidth=`${x}px`,D.style.maxWidth=`${x}px`,D.style.setProperty("--oc-ipad-sidebar-width",`${x}px`))},r[6]=N):N=r[6];const E=N;let I;r[7]!==d?(I=x=>{try{x.currentTarget.setPointerCapture(x.pointerId)}catch{}S.current=x.pointerId,b.current=x.clientX,h.current=d,v.current=d,p(!0),x.preventDefault()},r[7]=d,r[8]=I):I=r[8];const j=I;let P;r[9]!==T||r[10]!==n?(P=x=>{if(S.current!==x.pointerId)return;const D=x.clientX-b.current,K=T(h.current+(n==="left"?D:-D));v.current!==K&&(v.current=K,E(K))},r[9]=T,r[10]=n,r[11]=P):P=r[11];const k=P;let R;r[12]!==T||r[13]!==e?(R=x=>{if(S.current!==x.pointerId)return;try{x.currentTarget.releasePointerCapture(x.pointerId)}catch{}const D=T(v.current??h.current);S.current=null,v.current=null,p(!1),f(D);try{window.localStorage.setItem(e,String(D))}catch{}},r[12]=T,r[13]=e,r[14]=R):R=r[14];const y=R;let z;r[15]!==j||r[16]!==y||r[17]!==k?(z={onPointerDown:j,onPointerMove:k,onPointerUp:y,onPointerCancel:y},r[15]=j,r[16]=y,r[17]=k,r[18]=z):z=r[18];const M=z;let C;return r[19]!==M||r[20]!==l||r[21]!==d?(C={asideRef:a,width:d,isResizing:l,handleProps:M},r[19]=M,r[20]=l,r[21]=d,r[22]=C):C=r[22],C}const fd=["general","appearance","chat","notifications","sessions","git","magic-prompts","snippets","behavior","agents","commands","mcp","plugins","skills.installed","skills.catalog","providers","usage","voice","integrations","about"],md=1e3,pd=({onActiveConnectionDeleted:n})=>{const{t:e}=de();Qa();const[s,o]=c.useState(!1),[r,i]=c.useState(null),[a,u]=c.useState(!1),[d,f]=c.useState("changes"),[l,p]=c.useState(null),[b,h]=c.useState("nav"),[v,S]=c.useState(null),w=it(q=>q.setSettingsPage),T=it(q=>q.wideChatLayoutEnabled),N=Dt(q=>q.available),E=Dt(q=>q.runtimeType),I=c.useMemo(()=>oo(),[]),j=Mt(q=>q.mcpServers),P=Mt(q=>q.setMcpDraft),k=Mt(q=>q.setSelectedMcp),R=c.useCallback(()=>{i(null),p(null)},[]),y=c.useCallback(q=>{i(q)},[]),z=c.useCallback(()=>{u(!1)},[]),M=c.useCallback(q=>{h(q),y("settings")},[y]),{enabled:C,roomyForPanels:x}=xn(),K=da()==="portrait",g=fa(),[L,F]=c.useState(()=>ma().roomyForPanels),B=c.useCallback(()=>{F(q=>!q)},[]);c.useEffect(()=>{C||F(!1)},[C]);const W=c.useCallback(()=>{S(null),f("files"),u(!0)},[]),re=c.useCallback((q=null)=>{S(q),f("changes"),u(!0)},[]),ne=Lr("left","openchamber.ipad.leftSidebarWidth",ld),ee=Lr("right","openchamber.ipad.rightSidebarWidth",cd,dd),_=x,G=_&&a?ee.width:0,Y=C&&L?ne.width:0;c.useEffect(()=>{if(typeof document>"u")return;const q=document.documentElement;return q.style.setProperty("--oc-chat-inset-left",`${Y}px`),q.style.setProperty("--oc-chat-inset-right",`${G}px`),()=>{q.style.removeProperty("--oc-chat-inset-left"),q.style.removeProperty("--oc-chat-inset-right")}},[Y,G]),c.useEffect(()=>{if(typeof document>"u")return;const q=document.documentElement;return q.classList.toggle("wide-chat-layout",T),()=>q.classList.remove("wide-chat-layout")},[T]),c.useEffect(()=>{if(typeof document>"u")return;const q=C&&(K||g),ve=document.documentElement;return ve.classList.toggle("oc-keep-draft-starters",q),()=>ve.classList.remove("oc-keep-draft-starters")},[g,C,K]);const U=c.useMemo(()=>({openChanges:({diffPath:q,staged:ve}={})=>{re(q?{path:q,staged:ve===!0}:null)},openFiles:()=>W(),openSettings:()=>M("nav")}),[re,W,M]),Z=c.useMemo(()=>({openSessions:()=>{C?F(!0):o(!0)},openView:q=>{if(q==="files"){W();return}if(q==="mcp"){f("mcp"),u(!0);return}y(q)},openChanges:({path:q,staged:ve}={})=>{re(q?{path:q,staged:ve===!0}:null)},openSettings:q=>{q&&w(q),M(q?"page-content":"nav")}}),[C,re,W,M,y,w]);nd(Z);const te=c.useRef(null);Wn(te,{onLeftEdgeSwipe:()=>{C?F(!0):o(!0)},onRightEdgeSwipe:()=>u(!0)});const se=c.useRef(null),ae=c.useCallback(q=>{se.current=q},[]),ue=c.useCallback(()=>l?(p(null),!0):r==="settings"&&se.current?.()?!0:r?(R(),!0):a?(z(),!0):s?(o(!1),!0):!1,[r,R,z,l,s,a]);pa(ue);const V=!I&&N&&(E==="desktop"||E==="web"),ie=C?"dialog":"fullscreen",ye=c.useMemo(()=>({instanceLabel:I?ls():null,onOpenInstances:I?()=>y("instances"):void 0,onOpenSettings:()=>M("nav"),onOpenUpdate:V?()=>y("update"):void 0}),[M,y,I,V]),ke=c.useCallback(()=>{const q="new-mcp-server";let ve=q,Re=1;for(;j.some(_e=>_e.name===ve);)ve=`${q}-${Re}`,Re+=1;P({name:ve,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),k(ve),w("mcp"),M("page-content")},[j,M,P,k,w]);return t.jsx(ha,{actions:U,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:ne.asideRef,className:J("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!L&&"border-r-0"),style:{width:L?ne.width:0,minWidth:L?ne.width:0,maxWidth:L?ne.width:0,"--oc-ipad-sidebar-width":`${ne.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ne.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!L,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:J("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",ne.isResizing&&"pointer-events-none",!L&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Ye,{children:t.jsx(Cr,{open:!0,variant:"sidebar",onOpenChange:q=>{!q&&!x&&F(!1)},footer:ye})})}),L?t.jsx(Or,{side:"left",isResizing:ne.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:ne.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(Uc,{onOpenSessions:()=>C?B():o(!0),onOpenWorkspace:()=>u(!0),compactTitle:C}),t.jsx("main",{ref:te,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(Ye,{children:t.jsx(Za,{})})})})]}),C?null:t.jsx(Cr,{open:s,onOpenChange:o,footer:ye}),C?t.jsxs("aside",{ref:ee.asideRef,className:J("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!G&&"border-l-0"),style:{width:G,minWidth:G,maxWidth:G,"--oc-ipad-sidebar-width":`${ee.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:ee.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!G,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:J("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",ee.isResizing&&"pointer-events-none",!G&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Ye,{children:t.jsx(Mr,{open:a,onClose:z,tab:d,onTabChange:f,pendingChangesDiff:v,onOpenPlan:p,onOpenMcpSettings:ke,variant:_?"panel":"drawer"})})}),G?t.jsx(Or,{side:"right",isResizing:ee.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:ee.handleProps}):null]}):t.jsx(Mr,{open:a,onClose:z,tab:d,onTabChange:f,pendingChangesDiff:v,onOpenPlan:p,onOpenMcpSettings:ke}),l?t.jsx(ds,{open:!0,variant:ie,onClose:()=>p(null),ariaLabel:l.title,title:l.title,children:t.jsx(Ye,{children:t.jsx(nl,{savedProjectPlan:{projectRef:l.projectRef,planId:l.id},onNavigatedToChat:()=>{R(),z()}})})}):null,r==="instances"&&I?t.jsx(ds,{open:!0,variant:ie,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(Hc,{onConnect:R,onActiveConnectionDeleted:n})}):null,r==="settings"?t.jsx(ds,{open:!0,variant:ie,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Ye,{children:t.jsx(tl,{forceMobile:!0,isWindowed:!0,initialMobileStage:b,registerBackHandler:ae,visiblePageSlugs:fd.filter(q=>!(I&&q==="about")),onClose:R})})}):null,r==="update"?t.jsx(ds,{open:!0,variant:ie,dialogAlign:"app",onClose:R,ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Ye,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(sl,{initialUpdateDialogOpen:!0})})})}):null]})})};function hd({apis:n}){const{t:e}=de(),s=Je(_=>_.initializeApp),o=Je(_=>_.isInitialized),r=Je(_=>_.isConnected),i=Je(_=>_.connectionPhase),a=Je(_=>_.providers.length),u=Je(_=>_.agents.length),d=Je(_=>_.loadProviders),f=Je(_=>_.loadAgents),l=yt(_=>_.currentDirectory),p=Ne(_=>_.error),b=Ne(_=>_.clearError),h=it(_=>_.setIsMobile),v=Vi(_=>_.refreshStatus),S=Gi(_=>_.refreshStatus),w=Ki(_=>_.setPlanModeEnabled),T=We(_=>_.projects),[N,E]=c.useState(0),[I,j]=c.useState(0),[P,k]=c.useState(!1),[R,y]=c.useState("pending"),[z,M]=c.useState(null),C=c.useMemo(()=>ls(),[]),[,x]=c.useReducer(_=>_+1,0),D=c.useMemo(()=>oo(),[]),K=c.useRef(0),g=c.useRef(0),L=c.useCallback(()=>{const _=ot(),G=g.current+1;if(g.current=G,!_){os("resume:auto-connect",{}),is();return}os("resume:reprobe",{});const Y=()=>{s(),v(n.github,{force:!0}),S(n.linear,{force:!0}),a===0&&d({source:"mobileApp:nativeResume"}),u===0&&f({source:"mobileApp:nativeResume"})},U=te=>{os("resume:disconnect",{reason:te}),Tt({apiBaseUrl:"",clientToken:null,runtimeKey:Es}),E(se=>se+1)};Ds().then(te=>{if(g.current===G){if(te==="no-connection"){U("no-connection");return}if(te==="needs-login"){M({kind:"auth-expired",label:ls()??""}),U("needs-login");return}if(te==="unreachable"){const se=[4e3,1e4],ae=ue=>{window.setTimeout(()=>{if(g.current!==G)return;const V=ue===se.length-1;Ds({fast:!V}).then(ie=>{if(g.current===G&&ie!=="switched"){if(ie==="unchanged"){Y();return}if(ie==="needs-login"){M({kind:"auth-expired",label:ls()??""}),U("retry-needs-login");return}if(!V){ae(ue+1);return}U(`retry-${ie}`)}})},se[ue])};ae(0);return}te!=="switched"&&Y()}});const Z=Date.now();Z-K.current>=md&&(K.current=Z,window.dispatchEvent(new Event("openchamber:system-resume")))},[u,n.github,n.linear,s,f,d,a,v,S]);Hi(),qi(L),c.useEffect(()=>{if(!D)return;let _;const G=()=>{window.clearTimeout(_),_=window.setTimeout(()=>L(),1500)};return window.addEventListener("online",G),()=>{window.removeEventListener("online",G),window.clearTimeout(_)}},[D,L]),c.useEffect(()=>{if(D)return Qn.subscribe((_,G)=>{_.state==="expired"&&G.state!=="expired"&&(L(),Qn.getState().markAuthenticated())})},[D,L]),c.useEffect(()=>(Zn(n),()=>Zn(null)),[n]),c.useEffect(()=>Go(_=>{if(os("endpoint:changed",{runtimeKey:_.runtimeKey||"none",previousRuntimeKey:_.previousRuntimeKey||"none",connected:!!_.apiBaseUrl}),!!_.runtimeKey&&_.runtimeKey===_.previousRuntimeKey){Ga(),x();return}Ka(_),j(Y=>Y+1),E(Y=>Y+1)}),[]),c.useEffect(()=>{if(!D||r||ot()){y("done");return}let _=!1;return y("attempting"),(async()=>{const G=await is().catch(()=>({status:"no-candidate"}));_||(G.status==="unreachable"?M({kind:"unreachable",label:G.label}):G.status==="needs-login"&&M({kind:"auth-expired",label:G.label}),y("done"),G.status==="unreachable"&&is({fast:!1,skipIfConnected:!0}).catch(()=>null))})(),()=>{_=!0}},[]),c.useEffect(()=>{if(!D||!ot())return;let _=!1;const G=Y=>{os("cold-launch:drop",{kind:Y?.kind??"unknown"}),Y&&M(Y),Tt({apiBaseUrl:"",clientToken:null,runtimeKey:Es}),E(U=>U+1)};return Ds().then(async Y=>{if(_||Y==="switched"||Y==="unchanged")return;const U=ls();if(Y==="needs-login"){G({kind:"auth-expired",label:U??""});return}if(Y==="unreachable"){G(U?{kind:"unreachable",label:U}:null),is({fast:!1,skipIfConnected:!0}).catch(()=>null);return}const Z=await is().catch(()=>({status:"no-candidate"}));_||Z.status==="connected"||(Z.status==="needs-login"?G({kind:"auth-expired",label:Z.label}):Z.status==="unreachable"?G({kind:"unreachable",label:Z.label}):G(null))}),()=>{_=!0}},[]),c.useEffect(()=>{h(!0)},[h]),c.useEffect(()=>{D&&!ot()||s()},[N,s,D]),c.useEffect(()=>{r&&(a===0&&d({source:"mobileApp:recovery"}),u===0&&f({source:"mobileApp:recovery"}))},[u,r,f,d,a]);const F=c.useRef(!1),[B,W]=c.useState(D);c.useEffect(()=>{if(!D||!r||F.current)return;if(Ne.getState().currentSessionId){F.current=!0,W(!1);return}const _=Ut(),G=Ji(_);if(!G){F.current=!0,W(!1);return}let Y=!1;const U=window.setTimeout(()=>W(!1),6e3);return(async()=>{const Z=await yn().catch(()=>null);if(Y)return;if(!Z){W(!1);return}F.current=!0;const te=Z.activeSessions.find(ae=>ae.id===G.sessionId);if(!te){Yi(_),W(!1);return}const se=Ne.getState();se.currentSessionId||se.setCurrentSession(te.id,bn(te)??G.directory??void 0),W(!1)})(),()=>{Y=!0,window.clearTimeout(U)}},[N,r,D]),c.useEffect(()=>{r&&er.setDirectory(l)},[l,r]),c.useEffect(()=>{r&&(v(n.github,{force:!0}),S(n.linear,{force:!0}))},[n.github,n.linear,r,v,S]),c.useEffect(()=>{if(!r||T.length===0)return;let _=!1;return(async()=>{const Y=new Map(Ne.getState().availableWorktreesByProject);if(await Promise.all(T.map(async te=>{const se=te.path.replace(/\\/g,"/").replace(/\/+$/,"");if(se)try{if(!(He.getState().directories.get(se)?.isGitRepo??await Bt(()=>import("./useAppFontEffects-hfv2s6mZ.js").then(ie=>ie.kB),__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(ie=>ie.checkIsGitRepository(se))))return;const V=await so({id:te.id,path:se});if(_)return;Y.set(se,V)}catch{}})),_)return;const U=no(T,Y),Z=Ne.getState().availableWorktreesByProject;ca(U,Z)||Ne.setState({availableWorktrees:[...U.values()].flat(),availableWorktreesByProject:U})})(),()=>{_=!0}},[r,T]),c.useEffect(()=>{if(!r)return;let _=!1;const G=Xi(Y=>{Y.type==="worktree-changed"&&ua(T,Y.directories,()=>_)});return()=>{_=!0,G()}},[r,T]),c.useEffect(()=>{let _=!1;return(async()=>{const Y=await hn("/health",{method:"GET"}).catch(()=>null);if(!Y||!Y.ok||_)return;const U=await Y.json().catch(()=>null);if(!U||_)return;const Z=U.planModeExperimentalEnabled;w(Z===!0||Z===1||Z==="1"||Z==="true")})(),()=>{_=!0}},[w]),c.useEffect(()=>{if(!p)return;const _=window.setTimeout(()=>b(),5e3);return()=>window.clearTimeout(_)},[b,p]),c.useEffect(()=>{if(!(!r&&(D?!!ot():!0))){k(!1);return}const G=window.setTimeout(()=>{k(!0)},D?4e3:8e3);return()=>window.clearTimeout(G)},[r,D,N,I]),Qi(),Zi({enabled:!0}),Ha(),ea(),qa(),ad({enabled:D&&r}),rd({ready:D&&r&&o});const re=Gu(),ne=!r&&i==="reconnecting";if(!re)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:t.jsx(It,{width:120,height:120,isAnimated:!0,variant:"splash"})});const ee=!!ot();return D&&(!ee||!r&&!ne)?ee?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(It,{width:120,height:120,isAnimated:!P,variant:"splash"}),P?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("mobile.connect.recovery.description")})]}),t.jsx(pe,{type:"button",variant:"outline",onClick:()=>{Tt({apiBaseUrl:"",clientToken:null,runtimeKey:Es}),E(_=>_+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):R!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:[t.jsx(It,{width:120,height:120,isAnimated:!0,variant:"splash"}),C?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:[C,t.jsx(ta,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx(Ec,{onConnected:()=>E(_=>_+1),notice:z})}):!r&&!ne?P?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-[var(--splash-background,var(--surface-background))] text-foreground",children:t.jsx(It,{width:120,height:120,isAnimated:!0,variant:"splash"})}):t.jsx(Ye,{children:t.jsx(sa,{sdk:er.getSdkClient(),directory:l||"",children:t.jsx(na,{apis:n,children:t.jsx(ra,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[t.jsx(Ja,{ready:!D||!B,animated:!0}),t.jsx(oa,{embeddedBackgroundWorkEnabled:o}),t.jsx(Ya,{}),t.jsx(Wl,{}),t.jsx(pd,{onActiveConnectionDeleted:()=>{Tt({apiBaseUrl:"",clientToken:null,runtimeKey:Es}),E(_=>_+1)}}),t.jsx(ia,{}),t.jsx(aa,{}),t.jsx(la,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),o?t.jsx(Xa,{}):null]})})})},I)})}const gd=()=>{ja(),Ko().then(()=>{Promise.all([Ho(),ka()]).catch(n=>{console.error("[mobile-main] settings init failed:",n)}),Sa(),Na(),Ca()}).catch(n=>{console.error("[mobile-main] appearance init failed:",n)}).finally(()=>{_l()})};function Gm(n){window.__OPENCHAMBER_SURFACE__="mobile",ga(),gd(),Fl(),ba();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(hd,{apis:r});Oo.createRoot(e).render(t.jsx(ln.StrictMode,{children:t.jsx(xa,{children:t.jsx(ya,{children:t.jsx(va,{children:t.jsx(el,{children:o?i:t.jsx(wa,{children:i})})})})})}))}export{Gm as renderMobileApp};