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