@aiworker/web 1.22.2 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/bin/cli.js +7 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-CSICpWQD.js → CodeMirrorCommentWidgets-B1Gizi3a.js} +1 -1
  3. package/dist/assets/DiffView-DXjVsEOw.js +4 -0
  4. package/dist/assets/{DirtyBranchSwitchDialog-C22HdWj4.js → DirtyBranchSwitchDialog-aig6zJjg.js} +1 -1
  5. package/dist/assets/FilesView-CJdG0-wk.js +17 -0
  6. package/dist/assets/{GitView-VQQkYuUw.js → GitView-BXsS3jG6.js} +4 -4
  7. package/dist/assets/{JsonTreeView-6lrhwD3q.js → JsonTreeView-D_hpXBnF.js} +1 -1
  8. package/dist/assets/{LinearIssuesView-Ba6Q9569.js → LinearIssuesView-BoUiLQG1.js} +1 -1
  9. package/dist/assets/MarkdownImageGallery-B_B_a9KS.js +1 -0
  10. package/dist/assets/MarkdownRendererImpl-xgyyLiBM.js +12 -0
  11. package/dist/assets/OnboardingScreen-DIp84OWt.js +1 -0
  12. package/dist/assets/{PatchDiff-BzcZPlOq.js → PatchDiff-8p6nLJaU.js} +1 -1
  13. package/dist/assets/PierreDiffViewer-DjC8nTk9.js +161 -0
  14. package/dist/assets/{PlanView-DyDt_nZ_.js → PlanView-CJTmOF6I.js} +2 -2
  15. package/dist/assets/SettingsView-DD-JqIJx.js +28 -0
  16. package/dist/assets/{SettingsWindow-DDQYaKWQ.js → SettingsWindow-Cpb4hM6q.js} +1 -1
  17. package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
  18. package/dist/assets/{ToolOutputDialog-iYF8Y2bz.js → ToolOutputDialog-DfaKZXNU.js} +6 -6
  19. package/dist/assets/{ToolPartDiffPreview-CdjbOVMM.js → ToolPartDiffPreview-DtZLzrSK.js} +2 -2
  20. package/dist/assets/{VirtualizedFileDiff-fFFm2QgH.js → VirtualizedFileDiff-C8i9HpTB.js} +1 -1
  21. package/dist/assets/WalkthroughView-DeKMvZlL.js +4 -0
  22. package/dist/assets/{computeVirtualFileMetrics-CzgLum_K.js → computeVirtualFileMetrics-BBI7ZwrC.js} +2 -2
  23. package/dist/assets/contextPanelEmbeddedChat-BdA6bdky.js +1 -0
  24. package/dist/assets/de-DCrsQ5zS.js +10 -0
  25. package/dist/assets/es-Dwv4YfH6.js +16 -0
  26. package/dist/assets/fr-BCWg4Cnx.js +14 -0
  27. package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
  28. package/dist/assets/index-B68h5S5B.css +1 -0
  29. package/dist/assets/index-DVwMarHI.js +39 -0
  30. package/dist/assets/{index-Bl3LSbjn.js → index-jXSK5RrB.js} +1 -1
  31. package/dist/assets/{isDiffPlainText-Dx-dB_8l.js → isDiffPlainText-B_x_rVon.js} +1 -1
  32. package/dist/assets/{isFilePlainText-CWFPwmnU.js → isFilePlainText-DW_xMer1.js} +1 -1
  33. package/dist/assets/ja-Bruw3RYC.js +16 -0
  34. package/dist/assets/ko-idhXGF8j.js +16 -0
  35. package/dist/assets/main-BkyaQhJX.js +930 -0
  36. package/dist/assets/{main-DnBAoktx.js → main-CzdPuL0s.js} +2 -2
  37. package/dist/assets/markdownCore-Cn4Tyejo.js +5 -0
  38. package/dist/assets/{miniChat-BKyvLseN.js → miniChat-CCkqKOLp.js} +2 -2
  39. package/dist/assets/{mobile-DKjeFgMN.js → mobile-mvxTo055.js} +2 -2
  40. package/dist/assets/patchFileDiff-Csk4iNUi.js +13 -0
  41. package/dist/assets/pl-CGZWUqZJ.js +16 -0
  42. package/dist/assets/pt-BR-B8V7u7tA.js +16 -0
  43. package/dist/assets/renderElectronMiniChatApp-BxoyujA5.js +2 -0
  44. package/dist/assets/renderMobileApp-B48CsP4r.js +25 -0
  45. package/dist/assets/runtimeEndpointReset-Bg5gx18H.js +17 -0
  46. package/dist/assets/scheduledTasksApi-BW0Etzwz.js +1 -0
  47. package/dist/assets/{shikiHighlight-TEQCmzW8.js → shikiHighlight-CRl0SUC9.js} +1 -1
  48. package/dist/assets/surface-oMvhsog3.js +1 -0
  49. package/dist/assets/tr-BK_KiO2V.js +7 -0
  50. package/dist/assets/uk-CG74xV8N.js +16 -0
  51. package/dist/assets/{useAppFontEffects-D7sNpuL2.js → useAppFontEffects-CPKeOpUo.js} +160 -157
  52. package/dist/assets/useGitComparison-DH220WmO.js +1 -0
  53. package/dist/assets/useInlineCommentController-BiWz4AVb.js +2 -0
  54. package/dist/assets/useRootScrollLock-BS4-kr7P.js +1 -0
  55. package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
  56. package/dist/assets/{vendor-codemirror-language-data-Dp3KMRQG.js → vendor-codemirror-language-data-Bg4AEeCr.js} +2 -2
  57. package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
  58. package/dist/assets/{web-components-_mNEMjFY.js → web-components-z7hfnS8n.js} +1 -1
  59. package/dist/assets/zh-CN-T4AXofZI.js +16 -0
  60. package/dist/assets/zh-TW-Dte40sxp.js +16 -0
  61. package/dist/index.html +5 -43
  62. package/dist/mini-chat.html +4 -4
  63. package/dist/mobile.html +4 -4
  64. package/package.json +2 -3
  65. package/server/index.d.ts +15 -0
  66. package/server/index.js +45 -9
  67. package/server/lib/data-dir-migration.js +40 -0
  68. package/server/lib/data-dir-migration.test.js +59 -0
  69. package/server/lib/event-stream/runtime.test.js +12 -12
  70. package/server/lib/fs/DOCUMENTATION.md +3 -0
  71. package/server/lib/fs/routes.js +31 -0
  72. package/server/lib/fs/routes.test.js +110 -1
  73. package/server/lib/git/DOCUMENTATION.md +29 -5
  74. package/server/lib/git/routes.js +24 -4
  75. package/server/lib/git/service.js +184 -198
  76. package/server/lib/git/service.test.js +422 -25
  77. package/server/lib/inherited-env.js +16 -9
  78. package/server/lib/inherited-env.test.js +8 -9
  79. package/server/lib/message-queue/DOCUMENTATION.md +4 -1
  80. package/server/lib/network-defaults.js +23 -0
  81. package/server/lib/network-defaults.test.js +52 -0
  82. package/server/lib/opencode/DOCUMENTATION.md +17 -1
  83. package/server/lib/opencode/bootstrap-runtime.js +2 -0
  84. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  85. package/server/lib/opencode/openchamber-routes.js +64 -4
  86. package/server/lib/opencode/openchamber-routes.test.js +128 -1
  87. package/server/lib/opencode/routes.js +5 -3
  88. package/server/lib/opencode/settings-files.js +214 -0
  89. package/server/lib/opencode/settings-helpers.js +85 -41
  90. package/server/lib/opencode/settings-helpers.test.js +166 -1
  91. package/server/lib/opencode/settings-registry.json +747 -0
  92. package/server/lib/opencode/settings-runtime.js +139 -18
  93. package/server/lib/opencode/settings-runtime.test.js +163 -5
  94. package/server/lib/project-context/DOCUMENTATION.md +25 -1
  95. package/server/lib/project-context/routes.http.test.js +18 -0
  96. package/server/lib/project-context/routes.js +15 -0
  97. package/server/lib/project-context/runtime.js +248 -23
  98. package/server/lib/project-context/runtime.test.js +106 -3
  99. package/server/lib/projects/DOCUMENTATION.md +76 -0
  100. package/server/lib/projects/project-config.js +142 -9
  101. package/server/lib/projects/project-id.js +17 -0
  102. package/server/lib/projects/project-setup.js +409 -0
  103. package/server/lib/projects/project-setup.test.js +557 -0
  104. package/server/lib/projects/routes.js +59 -0
  105. package/server/lib/quota/DOCUMENTATION.md +31 -1
  106. package/server/lib/quota/providers/cline-pass.js +125 -0
  107. package/server/lib/quota/providers/cline-pass.test.js +103 -0
  108. package/server/lib/quota/providers/index.js +7 -0
  109. package/server/lib/quota/providers/neuralwatt.js +3 -6
  110. package/server/lib/quota/providers/neuralwatt.test.js +7 -7
  111. package/server/lib/quota/providers/ollama-cloud.js +31 -0
  112. package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
  113. package/server/lib/quota/providers/opencode-go.js +1 -1
  114. package/server/lib/quota/providers/opencode-go.test.js +26 -1
  115. package/server/lib/quota/providers/openrouter.js +119 -24
  116. package/server/lib/quota/providers/openrouter.test.js +330 -0
  117. package/server/lib/relay/DOCUMENTATION.md +55 -0
  118. package/server/lib/relay/cross-compat.test.js +26 -0
  119. package/server/lib/relay/downstream-scheduler.js +154 -0
  120. package/server/lib/relay/downstream-scheduler.test.js +162 -0
  121. package/server/lib/relay/e2ee.js +10 -8
  122. package/server/lib/relay/flow-control.test.js +177 -0
  123. package/server/lib/relay/host-client.js +37 -8
  124. package/server/lib/relay/tunnel-codec.js +9 -0
  125. package/server/lib/relay/tunnel-host.js +66 -17
  126. package/server/lib/session-assist/runtime.js +6 -10
  127. package/server/lib/session-goal/runtime.js +4 -9
  128. package/server/lib/small-model/DOCUMENTATION.md +3 -2
  129. package/server/lib/small-model/call.js +9 -4
  130. package/server/lib/small-model/call.test.js +29 -0
  131. package/server/lib/small-model/index.js +5 -10
  132. package/server/lib/small-model/runtime-providers.js +15 -7
  133. package/server/lib/small-model/runtime-providers.test.js +7 -1
  134. package/server/lib/terminal/DOCUMENTATION.md +4 -4
  135. package/server/lib/terminal/runtime.js +11 -6
  136. package/server/lib/terminal/runtime.test.js +20 -13
  137. package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
  138. package/server/lib/walkthrough/model-settings.js +8 -12
  139. package/server/lib/walkthrough/prompt.js +3 -1
  140. package/server/lib/walkthrough/sources.js +23 -2
  141. package/dist/assets/DiffView-hDBKesA_.js +0 -4
  142. package/dist/assets/FilesView-CdWzeOp9.js +0 -17
  143. package/dist/assets/MarkdownImageGallery-Czv_mhvS.js +0 -1
  144. package/dist/assets/MarkdownRendererImpl-BrMcswiy.js +0 -12
  145. package/dist/assets/OnboardingScreen-ChxQoAkx.js +0 -1
  146. package/dist/assets/PierreDiffViewer-BchBtZlp.js +0 -157
  147. package/dist/assets/SettingsView-BKf5xBsP.js +0 -28
  148. package/dist/assets/WalkthroughView-DOeCsMju.js +0 -4
  149. package/dist/assets/contextPanelEmbeddedChat-C0ZLAepL.js +0 -1
  150. package/dist/assets/de-B5JaA3SA.js +0 -10
  151. package/dist/assets/es-EPIH88ii.js +0 -16
  152. package/dist/assets/fr-CAMfxUdZ.js +0 -14
  153. package/dist/assets/index-DF5kMP-i.js +0 -39
  154. package/dist/assets/index-Dl3xbAB_.css +0 -1
  155. package/dist/assets/ja-CifOE1VN.js +0 -16
  156. package/dist/assets/ko-BBDyAyYQ.js +0 -16
  157. package/dist/assets/main-MhSaOZoB.js +0 -930
  158. package/dist/assets/markdownCore-BrBwOOMn.js +0 -3
  159. package/dist/assets/patchFileDiff-o8ms1me8.js +0 -10
  160. package/dist/assets/pl-DgEHYfFM.js +0 -16
  161. package/dist/assets/pt-BR-DuWHojUw.js +0 -16
  162. package/dist/assets/renderElectronMiniChatApp-CDgBwwCS.js +0 -2
  163. package/dist/assets/renderMobileApp-DJIKIK1r.js +0 -25
  164. package/dist/assets/runtimeEndpointReset-CYJ9O_xX.js +0 -17
  165. package/dist/assets/scheduledTasksApi-D8yamh1b.js +0 -1
  166. package/dist/assets/tr-D5m2yIWL.js +0 -7
  167. package/dist/assets/uk-D_q60oog.js +0 -16
  168. package/dist/assets/useInlineCommentController-Brz_cLcQ.js +0 -2
  169. package/dist/assets/useRootScrollLock-lXEnWlaU.js +0 -1
  170. package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
  171. package/dist/assets/vendor-zod-CK21ihK-.js +0 -39
  172. package/dist/assets/zh-CN-D8QvsVeg.js +0 -16
  173. package/dist/assets/zh-TW-B9t7rQQO.js +0 -16
@@ -0,0 +1,17 @@
1
+ import{f as ot,R as s,c as Ws,j as r,r as at}from"./vendor-react-BUCujlKS.js";import{Z as Pa,_ as Ma,$ as Da,a0 as za,t as Xe,a as Us,u as vt,dA as La,G as Ks,A as Aa,h as Hs,a5 as qs,e as Ia,dy as Oa,a4 as Ba,dz as $a}from"./index-DVwMarHI.js";import{f as Ht,y as Gs,ac as gi,bY as _a,h as q,hI as Wa,fw as Ua,T as lr,B as O,I as F,W as Ka,N as Ha,bb as qa,ae as Ga,cc as Xa,eg as Xs,hJ as Js,hK as Ja,h6 as Qa,fx as Ya,t as Q,l as Qs,au as pn,c7 as or,cK as Za,b as eo,hL as Dr,bK as to,av as gn,hM as Ys,c8 as Zs,c9 as ei,gm as ro,hN as no,hO as so,hP as io,bL as vi,bM as xi,bN as wi,bO as bi,bP as yi,bQ as ji,ao as jn,ap as Fn,aw as Ar,ar as Nn,b9 as Ir,bR as vn,ax as xn,c4 as ti,a7 as Ot,a8 as Bt,a9 as $t,bI as ao,bJ as oo,g as Br,ba as lo,bl as co}from"./useAppFontEffects-CPKeOpUo.js";import{a9 as uo,J as fo,K as mo,L as ho,M as po,Q as go}from"./runtimeEndpointReset-Bg5gx18H.js";import{c as ri,s as vo,P as wn,C as xo}from"./shikiHighlight-CRl0SUC9.js";import{a as wo}from"./vendor-codemirror-state-C9awkmn-.js";import{E as Nt}from"./vendor-codemirror-view-CiLROUVV.js";import{V as bo,J as yo,F as jo}from"./JsonTreeView-D_hpXBnF.js";import{ensurePierreThemeRegistered as ni,getResolvedShikiTheme as Fo}from"./appThemeRegistry-BK0dHKa6.js";import{V as No,W as Co}from"./Virtualizer-CZlLSacm.js";import{V as So}from"./Virtualizer-D_a8gKmg.js";import{u as zr,c as ko,e as Ro}from"./scheduledTasksApi-BW0Etzwz.js";import{D as To}from"./vendor-react-drawio-Ct3Q0DsD.js";import{I as Eo,u as Vo,n as Po}from"./useInlineCommentController-BiWz4AVb.js";import{b as Mo}from"./CodeMirrorCommentWidgets-B1Gizi3a.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.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-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.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-sonner-DFyL3AvE.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-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.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-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.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-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./web-components-z7hfnS8n.js";import"./computeVirtualFileMetrics-BBI7ZwrC.js";import"./vendor-shiki-Bbf2GEcE.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-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.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"./isFilePlainText-DW_xMer1.js";import"./registerCustomTheme-BBXUCRnG.js";function si(a){const e=ot.c(41),{containerRef:n,filePath:d,fileContent:x}=a,{t:g}=Ht(),w=Gs($o),v=Gs(Bo),f=gi(),j=_a(Oo),[m,y]=s.useState(null),[N,S]=s.useState(""),[C,T]=s.useState(!1),o=s.useRef(!1),E=s.useRef(null),D=s.useRef(null),[A,V]=s.useState(null);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{y(null),S(""),T(!1),o.current=!1,D.current=null,V(null)},e[0]=P):P=e[0];const M=P;let k,I;e[1]!==n?(k=()=>{const $=n.current;if(!$)return;const H=()=>{if(o.current)return;const ne=window.getSelection(),ke=ne?.toString().trim()??"";if(!ne||!ke||ne.rangeCount===0){M();return}const oe=ne.getRangeAt(0);if(!$.contains(oe.commonAncestorContainer)){M();return}const le=oe.getBoundingClientRect();D.current=oe.cloneRange(),S(ke),y({x:le.left+le.width/2,y:le.top-10})},re=ne=>{E.current?.contains(ne.target)||o.current&&M()};return document.addEventListener("selectionchange",H),document.addEventListener("pointerdown",re),()=>{document.removeEventListener("selectionchange",H),document.removeEventListener("pointerdown",re)}},I=[n,M],e[1]=n,e[2]=k,e[3]=I):(k=e[2],I=e[3]),s.useEffect(k,I);let _;e[4]!==x?(_=$=>{const H=de=>x.slice(0,de).split(`
2
+ `).length,re=Ao,ne=(de,Ve)=>{for(const Pe of re(de)){const Re=x.indexOf(Pe,Ve);if(Re>=0)return Re}return-1},ke=$.length>=8?x.indexOf($):-1;if(ke>=0){const de=H(ke);return{start:de,end:de+$.split(`
3
+ `).length-1}}const oe=$.split(`
4
+ `).map(Lo).filter(Boolean);if(oe.length===0)return null;const le=ne(oe[0],0);if(le<0)return null;const be=H(le);if(oe.length===1)return{start:be,end:be};const Ee=ne(oe[oe.length-1],le);return Ee<0?null:{start:be,end:Math.max(be,H(Ee))}},e[4]=x,e[5]=_):_=e[5];const L=_;let X;e[6]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{const $=D.current;if(!$){V(null);return}V(Wa($))},e[6]=X):X=e[6];const Ce=X;let W,Y;e[7]!==C?(W=()=>{if(!C)return;let $=null;const H=()=>{$===null&&($=window.requestAnimationFrame(()=>{$=null,Ce()}))};return document.addEventListener("scroll",H,{capture:!0,passive:!0}),window.addEventListener("resize",H),()=>{$!==null&&window.cancelAnimationFrame($),document.removeEventListener("scroll",H,{capture:!0}),window.removeEventListener("resize",H)}},Y=[C,Ce],e[7]=C,e[8]=W,e[9]=Y):(W=e[8],Y=e[9]),s.useEffect(W,Y);let ee;e[10]!==N?(ee=()=>{N&&(T(!0),o.current=!0,Ce(),window.getSelection()?.removeAllRanges())},e[10]=N,e[11]=ee):ee=e[11];const ce=ee;let te;e[12]!==j||e[13]!==w||e[14]!==f||e[15]!==d||e[16]!==v||e[17]!==L||e[18]!==N?(te=$=>{const H=w??(v?"draft":null);if(!N||!H||!f){M();return}const re=L(N);j({directory:f,sessionKey:H},{source:"file-quote",fileLabel:d,startLine:re?.start??0,endLine:re?.end??0,code:N,language:"",text:$.trim()}),M(),queueMicrotask(zo)},e[12]=j,e[13]=w,e[14]=f,e[15]=d,e[16]=v,e[17]=L,e[18]=N,e[19]=te):te=e[19];const Se=te;if(!m)return null;let B;e[20]!==C||e[21]!==L||e[22]!==N?(B=C?L(N):null,e[20]=C,e[21]=L,e[22]=N,e[23]=B):B=e[23];const ve=B;let xe;e[24]!==m.x||e[25]!==m.y?(xe={left:m.x,top:m.y,transform:"translate(-50%, -100%)"},e[24]=m.x,e[25]=m.y,e[26]=xe):xe=e[26];let ue;e[27]!==C||e[28]!==A?(ue=C&&A&&A.length>0?Ws.createPortal(r.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:A.map(Do)}),document.body):null,e[27]=C,e[28]=A,e[29]=ue):ue=e[29];let ae;e[30]!==C||e[31]!==d||e[32]!==ve||e[33]!==ce||e[34]!==Se||e[35]!==g?(ae=C?r.jsx("div",{className:"w-[min(420px,80vw)]",children:r.jsx(Eo,{fileLabel:d,lineRange:ve?{start:ve.start,end:ve.end}:void 0,onSave:Se,onCancel:M})}):r.jsx("div",{className:q("flex items-center whitespace-nowrap","oc-glass-popover rounded-full border border-[var(--interactive-border)]","shadow-[0_4px_16px_-4px_rgb(0_0_0_/_0.12)]","p-1"),children:r.jsx("button",{type:"button",onClick:ce,className:q("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-[var(--surface-foreground)]","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:g("chat.textSelection.title.commentOnSelection"),children:g("chat.textSelection.actions.comment")})}),e[30]=C,e[31]=d,e[32]=ve,e[33]=ce,e[34]=Se,e[35]=g,e[36]=ae):ae=e[36];let we;return e[37]!==xe||e[38]!==ue||e[39]!==ae?(we=Ws.createPortal(r.jsxs("div",{ref:E,className:"fixed z-50",style:xe,children:[ue,ae]}),document.body),e[37]=xe,e[38]=ue,e[39]=ae,e[40]=we):we=e[40],we}function Do(a,e){return r.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:a.left,top:a.top,width:a.width,height:a.height}},e)}function zo(){Ua()}function Lo(a){return a.trim()}function Ao(a){const e=a.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(Io)}function Io(a){return a.length>=8}function Oo(a){return a.addDraft}function Bo(a){return a.newSessionDraft?.open}function $o(a){return a.currentSessionId}const _o=(a,e)=>{if(!e)return null;const n=Number.parseInt(a.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},ii=(a,e)=>{const n=a.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},ai=(a,e,n)=>{const d=a.state.doc.line(e),x=Math.max(1,Math.min(n,d.length+1)),g=d.from+x-1;a.dispatch({selection:wo.cursor(g),effects:Nt.scrollIntoView(g,{y:"center"})})};function Wo({open:a,onOpenChange:e,view:n,variant:d="overlay"}){const{t:x}=Ht(),[g,w]=s.useState(""),v=s.useRef(null),f=s.useRef(!1),j=s.useRef(null),m=s.useRef(null),y=s.useMemo(()=>_o(g,n),[g,n]);s.useEffect(()=>{!a||!n||(f.current=!1,v.current=ii(n,n.state.selection),w(""))},[a,n]),s.useEffect(()=>{a&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[a]),s.useEffect(()=>{if(!(!a||!n||!v.current)){if(y===null){const{selection:o}=v.current;n.dispatch({selection:o,effects:Nt.scrollIntoView(o.main.from,{y:"center"})});return}ai(n,y,v.current.character)}},[y,a,n]);const N=s.useCallback(()=>{if(!n||f.current||!v.current)return;const{selection:o}=v.current;n.dispatch({selection:o,effects:Nt.scrollIntoView(o.main.from,{y:"center"})})},[n]),S=s.useCallback(o=>{o||N(),e(o)},[e,N]),C=s.useCallback(()=>{!n||y===null||!v.current||(f.current=!0,ai(n,y,v.current.character),e(!1),n.focus())},[y,e,n]);s.useEffect(()=>{if(!a)return;const o=D=>{const A=j.current,V=D.target;!A||!(V instanceof Node)||A.contains(V)||S(!1)},E=D=>{D.key==="Escape"&&(D.preventDefault(),S(!1))};return document.addEventListener("pointerdown",o,!0),document.addEventListener("keydown",E,!0),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("keydown",E,!0)}},[S,a,d]);const T=s.useMemo(()=>{if(!n)return x("goToLineDialog.helper.editorUnavailable");if(y===null){const o=v.current??ii(n,n.state.selection);return x("goToLineDialog.helper.currentLineRange",{current:o.lineNumber,max:n.state.doc.lines})}return x("goToLineDialog.helper.goToLine",{line:y})},[y,x,n]);return d==="inline"?a?r.jsxs("div",{ref:j,className:"ml-1 flex h-6 items-center gap-1",children:[r.jsx(lr,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>w(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),C())},placeholder:x("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),r.jsx(O,{variant:"outline",size:"xs",onClick:C,disabled:!n||y===null,className:"h-6 px-2",children:x("goToLineDialog.actions.go")})]}):null:r.jsx("div",{ref:j,className:q("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",a?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:r.jsxs("div",{className:"min-w-0",children:[r.jsx(lr,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>w(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),C())},placeholder:x("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),r.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:T})]})})}const Uo=(a,e)=>{const n=e.trim().toLowerCase(),d=[];if(!n)return d;const x=a.toLowerCase();let g=0;for(;;){const w=x.indexOf(n,g);if(w===-1)break;d.push({start:w,end:w+n.length}),g=w+n.length}return d},_r="data-md-find",bn="data-md-find-current",Fi="rounded-[2px] bg-status-warning/30 text-foreground",Ko="rounded-[2px] bg-status-warning/60 text-foreground",Ho=120,qo=a=>a instanceof Element&&a.hasAttribute(_r),Go=a=>a.target instanceof Element&&a.target.hasAttribute(_r)?!0:[...a.addedNodes].some(e=>qo(e)),Ni=a=>{const e=new Set;a.querySelectorAll(`mark[${_r}]`).forEach(n=>{const d=n.parentNode;d&&(d.replaceChild(document.createTextNode(n.textContent??""),n),e.add(d))}),e.forEach(n=>n.normalize())},Xo=(a,e)=>{Ni(a);const n=e.trim().toLowerCase();if(!n)return[];const d=[],x=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode(w){const v=w.parentElement;return!v||v.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),g=[];for(;x.nextNode();){const w=x.currentNode;w instanceof Text&&g.push(w)}for(const w of g){const v=w.nodeValue??"";if(!v)continue;const f=Uo(v,n);if(f.length===0)continue;const j=w.parentNode;if(!j)continue;const m=document.createDocumentFragment();let y=0;for(const N of f){N.start>y&&m.appendChild(document.createTextNode(v.slice(y,N.start)));const S=document.createElement("mark");S.setAttribute(_r,""),S.className=Fi,S.textContent=v.slice(N.start,N.end),m.appendChild(S),d.push(S),y=N.end}y<v.length&&m.appendChild(document.createTextNode(v.slice(y))),j.replaceChild(m,w)}return d},oi=({containerRef:a,open:e,onOpenChange:n,focusNonce:d,className:x})=>{const{t:g}=Ht(),[w,v]=s.useState(""),[f,j]=s.useState(0),[m,y]=s.useState(0),N=s.useRef(null),S=s.useRef([]),C=s.useRef(w);C.current=w;const T=s.useRef(null),o=s.useRef(null),E=s.useCallback((k,I=!1)=>{const _=a.current;if(!_){S.current=[],j(0),y(0);return}S.current=Xo(_,k);const L=S.current.length;j(L),y(X=>!I||L===0?0:Math.min(X,L-1))},[a]),D=s.useCallback((k,I=!1)=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{T.current=null,E(k,I)},Ho)},[E]);s.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const A=s.useCallback(()=>{n(!1);const k=o.current;o.current=null,k?.isConnected&&k.focus()},[n]);s.useEffect(()=>{const k=a.current;if(!e||!k)return;const I=new MutationObserver(_=>{!C.current.trim()||!_.some(X=>!Go(X))||D(C.current,!0)});return I.observe(k,{childList:!0,subtree:!0,characterData:!0}),()=>{I.disconnect(),Ni(k)}},[a,e,D]),s.useEffect(()=>{if(!e)return;const k=document.activeElement;k instanceof HTMLElement&&!o.current&&(o.current=k),N.current?.focus()},[e]),s.useEffect(()=>{e&&d>0&&(N.current?.focus(),N.current?.select())},[e,d]),s.useEffect(()=>{const k=a.current;if(!k||(k.querySelectorAll(`mark[${bn}]`).forEach(_=>{_.removeAttribute(bn),_.className=Fi}),f===0))return;const I=S.current[Math.min(Math.max(m,0),f-1)];I&&(I.setAttribute(bn,""),I.className=Ko,I.scrollIntoView({block:"nearest"}))},[a,m,f]);const V=s.useCallback(()=>{y(k=>f===0?0:(k+1)%f)},[f]),P=s.useCallback(()=>{y(k=>f===0?0:(k-1+f)%f)},[f]),M=s.useCallback(k=>{k.key==="Enter"?(k.preventDefault(),k.shiftKey?P():V()):k.key==="Escape"&&(k.preventDefault(),A())},[A,V,P]);return e?r.jsxs("div",{className:q("absolute right-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-1.5 py-1 shadow-lg",x),children:[r.jsx(F,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),r.jsx(lr,{ref:N,value:w,onChange:k=>{v(k.target.value),D(k.target.value)},onKeyDown:M,placeholder:g("filesView.preview.find.placeholder"),"aria-label":g("filesView.preview.find.placeholder"),className:"h-7 w-40 rounded-md px-2 py-0 text-sm md:w-56"}),r.jsx("span",{className:"min-w-12 px-1 text-center typography-micro text-muted-foreground tabular-nums","aria-live":"polite","aria-label":f>0?g("filesView.preview.find.countAria",{current:m+1,total:f}):g("filesView.preview.find.noMatches"),children:w.trim()&&f===0?g("filesView.preview.find.noMatches"):f>0?`${m+1}/${f}`:""}),r.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:P,title:g("filesView.preview.find.previousAria"),"aria-label":g("filesView.preview.find.previousAria"),disabled:f===0,children:r.jsx(F,{name:"arrow-up",className:"size-3.5"})}),r.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:V,title:g("filesView.preview.find.nextAria"),"aria-label":g("filesView.preview.find.nextAria"),disabled:f===0,children:r.jsx(F,{name:"arrow-down",className:"size-3.5"})}),r.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:A,title:g("filesView.preview.find.closeAria"),"aria-label":g("filesView.preview.find.closeAria"),children:r.jsx(F,{name:"close",className:"size-3.5"})})]}):null},Jo=a=>{let e=!0;return{poll:async()=>{if(!e||a.isDirty())return!1;const n=a.getLoadedContent(),d=a.getLoadedRevision();try{const x=await a.readContent();if(!e||a.isDirty()||d!==a.getLoadedRevision())return!1;if(x===n)return!0;const g=await a.readContent();return!e||a.isDirty()||g!==x||d!==a.getLoadedRevision()?!1:(a.applyContent(x),!0)}catch{return!1}},dispose:()=>{e=!1}}},Qo=1,Yo=(a,e)=>e.size!==a.size||e.mtimeMs!==void 0&&a.mtimeMs!==void 0&&Math.abs(e.mtimeMs-a.mtimeMs)>=Qo;function li(){const a=ot.c(8),[e]=at.useState(Zo),n=at.useRef(!1);let d;a[0]!==e?(d=f=>{if(f==null){e.cleanUp(),n.current=!1;return}n.current||(n.current=!0,e.setup(f,f.firstElementChild??void 0))},a[0]=e,a[1]=d):d=a[1];const x=d;let g,w;a[2]!==e?(g=()=>()=>{n.current=!1,e.cleanUp()},w=[e],a[2]=e,a[3]=g,a[4]=w):(g=a[3],w=a[4]),at.useLayoutEffect(g,w);let v;return a[5]!==x||a[6]!==e?(v={virtualizer:e,setScroller:x},a[5]=x,a[6]=e,a[7]=v):v=a[7],v}function Zo(){return new So}const _t=new Map,el=100;function Lr(a){const[e,n]=at.useState(null),d=at.useRef(null),x=at.useRef(null),g=at.useRef(null),w=at.useCallback((v,f)=>{v&&f instanceof bo&&(g.current={key:a,file:f,node:v});const j=d.current,m=x.current,y=()=>{d.current===j&&(j?.(),m?.())};f?queueMicrotask(y):y()},[a]);return at.useLayoutEffect(()=>{if(!e||!a)return;const v=_t.get(a)??{top:0,left:0};let f=!0;const j=()=>g.current?.key===a?g.current.file:null,m=E=>g.current?.key===a?g.current.node.shadowRoot?.querySelector(`[data-line][data-line-index="${E-1}"]`):null,y=()=>{S.disconnect(),C.disconnect()},N=()=>{if(!f)return;const E=j(),D=v.line&&E?.getLinePosition(v.line.number),A=v.line&&m(v.line.number);let V=v.top;v.line&&D&&(V=(E?.top??0)+D.top-v.line.offset),v.line&&A&&(V=e.scrollTop+A.getBoundingClientRect().top-e.getBoundingClientRect().top-v.line.offset),e.scrollTop=V,e.scrollLeft=v.left,(!v.line||A)&&Math.abs(e.scrollTop-V)<1&&Math.abs(e.scrollLeft-v.left)<1&&(f=!1,y())},S=new ResizeObserver(N),C=new MutationObserver(()=>{if(f){for(const E of e.children)S.observe(E);N()}});S.observe(e);for(const E of e.children)S.observe(E);C.observe(e,{childList:!0,subtree:!0});const T=()=>{if(f)return;const E=j(),D=E?.getNumericScrollAnchor(e.scrollTop-(E.top??0)),A=D&&m(D.lineNumber),V=A?A.getBoundingClientRect().top-e.getBoundingClientRect().top:null;if(_t.delete(a),_t.set(a,{top:e.scrollTop,left:e.scrollLeft,line:D&&V!==null&&V>=0&&V<e.clientHeight?{number:D.lineNumber,offset:V}:void 0}),_t.size>el){const P=_t.keys().next().value;P!==void 0&&_t.delete(P)}},o=()=>{f=!1,y()};return d.current=N,x.current=T,N(),e.addEventListener("scroll",T,{passive:!0}),e.addEventListener("wheel",o,{passive:!0}),e.addEventListener("touchstart",o,{passive:!0}),e.addEventListener("pointerdown",o,{passive:!0}),e.addEventListener("keydown",o),()=>{d.current=null,x.current=null,g.current?.key===a&&(g.current=null),y(),e.removeEventListener("scroll",T),e.removeEventListener("wheel",o),e.removeEventListener("touchstart",o),e.removeEventListener("pointerdown",o),e.removeEventListener("keydown",o)}},[a,e]),{setScroller:n,restore:w}}function tl(a){return!(!a.autoSaveEnabled||!a.isDirty||!a.canWrite||a.isSaving||a.fileLoading||a.isNonEditableBinary||!a.selectedFilePath||a.loadedFilePath!==a.selectedFilePath)}function rl(a){return a.selectedFilePath?a.isDirty?!(a.fileLoading||a.loadedFilePath!==a.selectedFilePath||a.isNonEditableBinary||a.draftContent===""&&a.fileContent!==""&&a.loadedFilePath!==a.selectedFilePath):!0:!1}const nl='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function ci(){if(typeof document>"u")return!1;const a=document.documentElement.getAttribute("data-theme");return a==="dark"||!a&&window.matchMedia("(prefers-color-scheme: dark)").matches}const sl=s.forwardRef(function({xml:e,readOnly:n,className:d,onChange:x},g){const w=s.useRef(e),v=s.useRef(null),f=s.useRef(!1),[j,m]=s.useState(ci),y=s.useRef(e),N=s.useRef(e);N.current!==e&&(N.current=e,y.current=e,w.current=e);const S=s.useRef(j);S.current!==j&&(S.current=j,y.current=w.current);const C=s.useRef(null);s.useEffect(()=>{const E=()=>m(ci());E();const D=new MutationObserver(E);return D.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>D.disconnect()},[]),s.useEffect(()=>{const E=setTimeout(()=>{C.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(E)},[]),s.useImperativeHandle(g,()=>({getXml:()=>w.current}));const T=s.useCallback(()=>{!e&&!f.current&&(f.current=!0,setTimeout(()=>{v.current?.template({})},500))},[e]),o=s.useCallback(E=>{w.current=E.xml,x?.(E.xml)},[x]);return r.jsx("div",{ref:C,className:q("h-full w-full",d),children:r.jsx(To,{ref:v,xml:y.current||nl,autosave:!0,urlParameters:{ui:n?"simple":j?"dark":"kennedy",spin:!0,libraries:!n,chrome:n,nav:n,layers:n,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:T,onAutoSave:o},j?"dark":"light")})}),il=a=>{const e=K(a);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const d=e.slice(0,n);return/^[A-Za-z]:$/.test(d)?`${d}/`:d},al=a=>{const e=ot.c(8),{label:n,iconDataUrl:d}=a,[x,g]=s.useState(!1);let w;e[0]!==n?(w=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=w):w=e[1];const v=w;if(d&&!x){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>g(!0),e[2]=m):m=e[2];let y;return e[3]!==d?(y=r.jsx("img",{src:d,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=d,e[4]=y):y=e[4],y}let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=q("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=f):f=e[5];let j;return e[6]!==v?(j=r.jsx("span",{className:f,children:v}),e[6]=v,e[7]=j):j=e[7],j},ol=a=>a.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),K=a=>{if(!a)return"";const e=a.replace(/\\/g,"/"),n=e.startsWith("//");let d=e.replace(/\/+/g,"/");n&&!d.startsWith("//")&&(d=`/${d}`);const x=d==="/",g=/^[A-Za-z]:\/$/.test(d);return!x&&!g&&(d=d.replace(/\/+$/,"")),d},ll=a=>a.startsWith("/")||a.startsWith("//")||/^[A-Za-z]:\//.test(a),Kt=a=>/^[A-Za-z]:\//.test(a)?a.toLowerCase():a,$r=(a,e)=>{const n=K(e),d=K(a);if(!n||!d)return!1;const x=Kt(n),g=Kt(d);return g===x||g.startsWith(`${x}/`)},ui=(a,e)=>{const n=K(e),d=K(a);if(!$r(d,n))return[];const g=d.slice(n.length).replace(/^\//,"").split("/"),w=[];let v=n;for(let f=0;f<g.length-1;f++)v=v?`${v}/${g[f]}`:g[f],w.push(v);return w},Or=(a,e)=>{if(!e)return"";const n=K(e);if(!a||!$r(n,a))return n;const d=n.slice(a.length);return d.startsWith("/")?d.slice(1):d},cl=new Set(["node_modules"]),ul=a=>{const e=ot.c(3),{status:n}=a;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=d):d=e[0];const x=d[n];let g;return e[1]!==x?(g=r.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:x}}),e[1]=x,e[2]=g):g=e[2],g},di=a=>{const e=ot.c(11),{name:n}=a,d=s.useRef(null),x=s.useRef(null),[g,w]=s.useState(!1);let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{const N=d.current,S=x.current;if(!N||!S)return;const C=()=>{w(S.scrollWidth>N.clientWidth+1)};C();const T=new ResizeObserver(C);return T.observe(N),T.observe(S),()=>{T.disconnect()}},e[0]=v):v=e[0];let f;e[1]!==n?(f=[n],e[1]=n,e[2]=f):f=e[2],s.useLayoutEffect(v,f);let j;e[3]!==n?(j=r.jsx("span",{ref:x,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=j):j=e[4];let m;e[5]!==n||e[6]!==g?(m=g?r.jsxs("span",{className:"open-file-name-marquee-track",children:[r.jsx("span",{className:"open-file-name-marquee-item",children:n}),r.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):r.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=g,e[7]=m):m=e[7];let y;return e[8]!==j||e[9]!==m?(y=r.jsxs("span",{ref:d,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[j,m]}),e[8]=j,e[9]=m,e[10]=y):y=e[10],y},dl=a=>cl.has(a),fl=a=>{const e=K(a);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},ml=a=>{const n=(a instanceof Error?a.message:String(a??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},fi=a=>{const n=(a instanceof Error?a.message:String(a??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},Wt=2e5,hl=2e5;function pl(a){const e=a.length>400?`${a.slice(0,200)}${a.slice(-200)}`:a;let n=2166136261;for(let d=0;d<e.length;d+=1)n^=e.charCodeAt(d),n=n+((n<<1)+(n<<4)+(n<<7)+(n<<8)+(n<<24))>>>0;return`${a.length}:${n.toString(16)}`}const gl=a=>{let e=0,n=0;for(let d=0;d<a.length;d+=1)a.charCodeAt(d)===10&&(d>0&&a.charCodeAt(d-1)===13?e+=1:n+=1);return e>n?`\r
5
+ `:`
6
+ `},Ci=a=>a.replace(/\r\n/g,`
7
+ `).replace(/\r/g,`
8
+ `),vl=(a,e)=>{const n=Ci(a);return e===`\r
9
+ `?n.replace(/\n/g,`\r
10
+ `):n},Si=(a,e)=>r.jsx(Ar,{filePath:a,extension:e}),mi=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},xl=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},yn=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="html"||e==="htm"},wl=a=>{const e=ot.c(76),{node:n,root:d,isExpanded:x,isActive:g,isMobile:w,isBrowserClient:v,alwaysShowActions:f,status:j,badge:m,permissions:y,downloadFile:N,contextMenuPath:S,setContextMenuPath:C,rightClickMenuPath:T,setRightClickMenuPath:o,onSelect:E,onToggle:D,onRevealPath:A,onOpenDialog:V}=a,{t:P}=Ht(),M=n.type==="directory",{canRename:k,canCreateFile:I,canCreateFolder:_,canDelete:L,canReveal:X}=y,Ce=!M&&!!N,W=X&&!v,Y=k||I||_||L||Ce||W;let ee;e[0]!==Y||e[1]!==n.path||e[2]!==o?(ee=fe=>{Y&&(fe?.preventDefault(),o(n.path))},e[0]=Y,e[1]=n.path,e[2]=o,e[3]=ee):ee=e[3];const ce=ee;let te;e[4]!==M||e[5]!==n||e[6]!==E||e[7]!==D?(te=()=>{M?D(n.path):E(n)},e[4]=M,e[5]=n,e[6]=E,e[7]=D,e[8]=te):te=e[8];const Se=te;let B;e[9]!==n.path||e[10]!==C||e[11]!==o?(B=fe=>{fe.stopPropagation(),o(null),C(n.path)},e[9]=n.path,e[10]=C,e[11]=o,e[12]=B):B=e[12];const ve=B;let xe;e[13]!==I||e[14]!==_||e[15]!==L||e[16]!==k||e[17]!==W||e[18]!==N||e[19]!==v||e[20]!==M||e[21]!==n||e[22]!==V||e[23]!==A||e[24]!==d||e[25]!==P?(xe=fe=>{const{Item:pe,Separator:tt}=fe;return r.jsxs(r.Fragment,{children:[k&&r.jsxs(pe,{onClick:G=>{G.stopPropagation(),V("rename",n)},children:[r.jsx(F,{name:"edit",className:"mr-2 size-4"})," ",P("sidebarFilesTree.menu.rename")]}),r.jsxs(pe,{onClick:G=>{G.stopPropagation(),Br(n.path).then(lt=>{if(lt.ok){Q.success(P("sidebarFilesTree.toast.pathCopied"));return}Q.error(P("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(F,{name:"file-copy",className:"mr-2 size-4"})," ",P("sidebarFilesTree.menu.copyPath")]}),r.jsxs(pe,{onClick:G=>{G.stopPropagation();const lt=Or(d,n.path)||n.path;Br(lt).then(me=>{if(me.ok){Q.success(P("filesView.toast.relativePathCopied"));return}Q.error(P("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(F,{name:"file-copy-2",className:"mr-2 size-4"})," ",P("filesView.tree.menu.copyRelativePath")]}),!M&&N&&r.jsxs(pe,{onClick:G=>{G.stopPropagation(),N(n.path).catch(lt=>{console.error("Download failed:",lt),Q.error(P("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(F,{name:"download",className:"mr-2 size-4"})," ",P(v?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),W&&r.jsxs(pe,{onClick:G=>{G.stopPropagation(),A(n.path)},children:[r.jsx(F,{name:"folder-received",className:"mr-2 size-4"})," ",P(co())]}),M&&(I||_)&&r.jsxs(r.Fragment,{children:[r.jsx(tt,{}),I&&r.jsxs(pe,{onClick:G=>{G.stopPropagation(),V("createFile",n)},children:[r.jsx(F,{name:"file-add",className:"mr-2 size-4"})," ",P("sidebarFilesTree.menu.newFile")]}),_&&r.jsxs(pe,{onClick:G=>{G.stopPropagation(),V("createFolder",n)},children:[r.jsx(F,{name:"folder-add",className:"mr-2 size-4"})," ",P("sidebarFilesTree.menu.newFolder")]})]}),L&&r.jsxs(r.Fragment,{children:[r.jsx(tt,{}),r.jsxs(pe,{onClick:G=>{G.stopPropagation(),V("delete",n)},className:"text-destructive focus:text-destructive",children:[r.jsx(F,{name:"delete-bin",className:"mr-2 size-4"})," ",P("sidebarFilesTree.menu.delete")]})]})]})},e[13]=I,e[14]=_,e[15]=L,e[16]=k,e[17]=W,e[18]=N,e[19]=v,e[20]=M,e[21]=n,e[22]=V,e[23]=A,e[24]=d,e[25]=P,e[26]=xe):xe=e[26];const ue=xe,ae=T===n.path;let we;e[27]!==n.path||e[28]!==o?(we=fe=>o(fe?n.path:null),e[27]=n.path,e[28]=o,e[29]=we):we=e[29];const $=w?void 0:ce;let H;e[30]!==$?(H=r.jsx("div",{className:"group relative flex items-center",onContextMenu:$}),e[30]=$,e[31]=H):H=e[31];const re=w?void 0:ce,ne=g?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let ke;e[32]!==ne?(ke=q("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",ne),e[32]=ne,e[33]=ke):ke=e[33];let oe;e[34]!==M||e[35]!==x||e[36]!==n.extension||e[37]!==n.path?(oe=M?x?r.jsx(F,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):r.jsx(F,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):Si(n.path,n.extension),e[34]=M,e[35]=x,e[36]=n.extension,e[37]=n.path,e[38]=oe):oe=e[38];let le;e[39]!==n.name||e[40]!==n.path?(le=r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[39]=n.name,e[40]=n.path,e[41]=le):le=e[41];let be;e[42]!==M||e[43]!==j?(be=!M&&j&&r.jsx(ul,{status:j}),e[42]=M,e[43]=j,e[44]=be):be=e[44];let Ee;e[45]!==m||e[46]!==M?(Ee=M&&m&&r.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[m.modified>0&&r.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",m.modified]}),m.added>0&&r.jsxs("span",{className:"text-[var(--status-success)]",children:["+",m.added]})]}),e[45]=m,e[46]=M,e[47]=Ee):Ee=e[47];let de;e[48]!==Se||e[49]!==ke||e[50]!==oe||e[51]!==le||e[52]!==be||e[53]!==Ee||e[54]!==re?(de=r.jsxs("button",{type:"button",onClick:Se,onContextMenu:re,className:ke,children:[oe,le,be,Ee]}),e[48]=Se,e[49]=ke,e[50]=oe,e[51]=le,e[52]=be,e[53]=Ee,e[54]=re,e[55]=de):de=e[55];let Ve;e[56]!==f||e[57]!==S||e[58]!==ve||e[59]!==Y||e[60]!==w||e[61]!==n.path||e[62]!==ue||e[63]!==C?(Ve=Y&&r.jsx("div",{className:q("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:r.jsxs(jn,{open:S===n.path,onOpenChange:fe=>C(fe?n.path:null),children:[r.jsx(Fn,{asChild:!0,children:r.jsx(O,{variant:"ghost",size:"icon",className:"size-6",onClick:ve,children:r.jsx(F,{name:"more-2-fill",className:"size-4"})})}),r.jsx(Nn,{align:"end",side:"bottom",onCloseAutoFocus:()=>C(null),children:ue({Item:Ir,Separator:lo})})]})}),e[56]=f,e[57]=S,e[58]=ve,e[59]=Y,e[60]=w,e[61]=n.path,e[62]=ue,e[63]=C,e[64]=Ve):Ve=e[64];let Pe;e[65]!==de||e[66]!==Ve||e[67]!==H?(Pe=r.jsxs(po,{render:H,children:[de,Ve]}),e[65]=de,e[66]=Ve,e[67]=H,e[68]=Pe):Pe=e[68];let Re;e[69]!==ue?(Re=r.jsx(fo,{className:"min-w-[180px]",children:ue({Item:ho,Separator:mo})}),e[69]=ue,e[70]=Re):Re=e[70];let Z;return e[71]!==Pe||e[72]!==Re||e[73]!==ae||e[74]!==we?(Z=r.jsxs(go,{open:ae,onOpenChange:we,children:[Pe,Re]}),e[71]=Pe,e[72]=Re,e[73]=ae,e[74]=we,e[75]=Z):Z=e[75],Z},bl=a=>{const e=ot.c(83),{activeDialog:n,dialogData:d,dialogInputValue:x,onDialogInputChange:g,isDialogSubmitting:w,onDialogSubmit:v,onClose:f,inputRef:j}=a,{t:m}=Ht(),y=!!n;let N;e[0]!==f?(N=B=>!B&&f(),e[0]=f,e[1]=N):N=e[1];let S;e[2]!==n||e[3]!==m?(S=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=S):S=e[4];let C;e[5]!==n||e[6]!==m?(C=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=C):C=e[7];let T;e[8]!==n||e[9]!==m?(T=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=T):T=e[10];let o;e[11]!==n||e[12]!==m?(o=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=o):o=e[13];let E;e[14]!==S||e[15]!==C||e[16]!==T||e[17]!==o?(E=r.jsxs(bi,{children:[S,C,T,o]}),e[14]=S,e[15]=C,e[16]=T,e[17]=o,e[18]=E):E=e[18];let D;e[19]!==n||e[20]!==d?.path||e[21]!==m?(D=n==="createFile"&&m("filesView.dialog.createFile.description",{path:d?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=d?.path,e[21]=m,e[22]=D):D=e[22];let A;e[23]!==n||e[24]!==d?.path||e[25]!==m?(A=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:d?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=d?.path,e[25]=m,e[26]=A):A=e[26];let V;e[27]!==n||e[28]!==d?.name||e[29]!==m?(V=n==="rename"&&m("filesView.dialog.rename.description",{name:d?.name??""}),e[27]=n,e[28]=d?.name,e[29]=m,e[30]=V):V=e[30];let P;e[31]!==n||e[32]!==d?.name||e[33]!==m?(P=n==="delete"&&m("filesView.dialog.delete.description",{name:d?.name??""}),e[31]=n,e[32]=d?.name,e[33]=m,e[34]=P):P=e[34];let M;e[35]!==V||e[36]!==P||e[37]!==D||e[38]!==A?(M=r.jsxs(yi,{children:[D,A,V,P]}),e[35]=V,e[36]=P,e[37]=D,e[38]=A,e[39]=M):M=e[39];let k;e[40]!==M||e[41]!==E?(k=r.jsxs(wi,{children:[E,M]}),e[40]=M,e[41]=E,e[42]=k):k=e[42];let I;e[43]!==n||e[44]!==x||e[45]!==j||e[46]!==g||e[47]!==v||e[48]!==m?(I=n!=="delete"&&r.jsx("div",{className:"py-4",children:r.jsx(lr,{value:x,onChange:B=>g(B.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:B=>{B.key==="Enter"&&v()},ref:j})}),e[43]=n,e[44]=x,e[45]=j,e[46]=g,e[47]=v,e[48]=m,e[49]=I):I=e[49];let _;e[50]!==m?(_=m("filesView.dialog.cancel"),e[50]=m,e[51]=_):_=e[51];let L;e[52]!==w||e[53]!==f||e[54]!==_?(L=r.jsx(O,{variant:"outline",onClick:f,disabled:w,children:_}),e[52]=w,e[53]=f,e[54]=_,e[55]=L):L=e[55];const X=n==="delete"?"destructive":"default";let Ce;e[56]!==v?(Ce=()=>{v()},e[56]=v,e[57]=Ce):Ce=e[57];let W;e[58]!==n||e[59]!==x||e[60]!==w?(W=w||n!=="delete"&&!x.trim(),e[58]=n,e[59]=x,e[60]=w,e[61]=W):W=e[61];let Y;e[62]!==n||e[63]!==w||e[64]!==m?(Y=w?r.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=w,e[64]=m,e[65]=Y):Y=e[65];let ee;e[66]!==X||e[67]!==Ce||e[68]!==W||e[69]!==Y?(ee=r.jsx(O,{variant:X,onClick:Ce,disabled:W,children:Y}),e[66]=X,e[67]=Ce,e[68]=W,e[69]=Y,e[70]=ee):ee=e[70];let ce;e[71]!==L||e[72]!==ee?(ce=r.jsxs(ji,{children:[L,ee]}),e[71]=L,e[72]=ee,e[73]=ce):ce=e[73];let te;e[74]!==j||e[75]!==k||e[76]!==I||e[77]!==ce?(te=r.jsxs(xi,{initialFocus:j,children:[k,I,ce]}),e[74]=j,e[75]=k,e[76]=I,e[77]=ce,e[78]=te):te=e[78];let Se;return e[79]!==y||e[80]!==N||e[81]!==te?(Se=r.jsx(vi,{open:y,onOpenChange:N,children:te}),e[79]=y,e[80]=N,e[81]=te,e[82]=Se):Se=e[82],Se},Ut=new Map,yl=100,hi=a=>{const e=ot.c(13);let n,d,x;e[0]!==a?({positionKey:d,onViewReady:n,...x}=a,e[0]=a,e[1]=n,e[2]=d,e[3]=x):(n=e[1],d=e[2],x=e[3]);const g=s.useRef(null);let w,v;e[4]!==d?(w=()=>()=>{const m=g.current;if(!m)return;const{anchor:y,head:N}=m.state.selection.main;if(Ut.delete(d),Ut.set(d,{scroll:m.scrollSnapshot(),anchor:y,head:N}),Ut.size>yl){const S=Ut.keys().next().value;S!==void 0&&Ut.delete(S)}},v=[d],e[4]=d,e[5]=w,e[6]=v):(w=e[5],v=e[6]),s.useLayoutEffect(w,v);let f;e[7]!==n||e[8]!==d?(f=m=>{g.current=m;const y=Ut.get(d);y&&m.dispatch({selection:{anchor:Math.min(y.anchor,m.state.doc.length),head:Math.min(y.head,m.state.doc.length)},effects:y.scroll}),n?.(m)},e[7]=n,e[8]=d,e[9]=f):f=e[9];let j;return e[10]!==x||e[11]!==f?(j=r.jsx(xo,{...x,onViewReady:f}),e[10]=x,e[11]=f,e[12]=j):j=e[12],j},pi=(a,e,n)=>{const d=ot.c(8),[x,g]=s.useState(""),[w,v]=s.useState(0);let f,j;d[0]!==a||d[1]!==n||d[2]!==e?(f=()=>{if(!a){g("");return}let y=!1;g("");const N=Ia(),S=Oa(N);Ba(N).then(T=>{y||!T||(g(a),e(null))}).catch(T=>{y||(e(T instanceof Error?T.message:n),g(a))});const C=$a(()=>{y||(g(a),v(jl),e(null))});return()=>{y=!0,S(),C()}},j=[a,e,n],d[0]=a,d[1]=n,d[2]=e,d[3]=f,d[4]=j):(f=d[3],j=d[4]),s.useEffect(f,j);let m;return d[5]!==w||d[6]!==x?(m={readyKey:x,nonce:w},d[5]=w,d[6]=x,d[7]=m):m=d[7],m},Wu=({mode:a="full"})=>{const{t:e}=Ht(),{files:n,runtime:d}=Ka(),{currentTheme:x,availableThemes:g,lightThemeId:w,darkThemeId:v}=Ha(),{isMobile:f,isTablet:j,screenWidth:m}=qa(),y=Pa(d.platform),N=f||j,S=Ma(),C=Da(),T=gi()??"",o=K(T.trim()),E=a!=="editor-only",D=a==="editor-only"&&!f,A=za(t=>t.searchFiles),V=Ga(T),[P,M]=s.useState(""),k=Xa(P,200),I=s.useRef(null),[_,L]=s.useState(!1),[X,Ce]=s.useState(!0),[W,Y]=s.useState(!1),[ee,ce]=s.useState(!1),te=s.useRef(0),Se=s.useCallback(t=>{te.current=Math.max(0,te.current+(t?1:-1))},[]),[B,ve]=s.useState("edit"),[xe,ue]=s.useState("edit"),[ae,we]=s.useState("tree"),[$,H]=s.useState("edit"),[re,ne]=s.useState("preview"),[ke,oe]=s.useState(0),le=s.useRef({}),be=s.useRef({}),Ee=s.useRef({}),de=s.useRef({}),Ve=s.useMemo(()=>g.find(t=>t.metadata.id===w)??Xs(!1),[g,w]),Pe=s.useMemo(()=>g.find(t=>t.metadata.id===v)??Xs(!0),[g,v]);s.useEffect(()=>{ni(Ve),ni(Pe)},[Ve,Pe]);const Re=s.useMemo(()=>[],[]),Z=Xe(t=>o?t.byRoot[o]?.openPaths??Re:Re),fe=Xe(t=>o?t.byRoot[o]?.selectedPath??null:null),pe=Xe(t=>o?t.byRoot[o]?.expandedPaths??Re:Re),tt=Xe(t=>t.removeOpenPath),G=Xe(t=>t.removeOpenPathsByPrefix),lt=Xe(t=>t.removeExpandedPathsByPrefix),me=Xe(t=>t.setSelectedPath),Cn=Xe(t=>t.toggleExpandedPath),cr=Xe(t=>t.expandPaths),Ct=s.useCallback(t=>{const i=K(t),l=i.split("/"),u=l[l.length-1]||i,p=u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;return{name:u,path:i,type:"file",extension:p}},[]),St=s.useMemo(()=>Z.map(Ct),[Z,Ct]),Wr=s.useMemo(()=>{if(fe){const t=Kt(fe);if(Z.some(i=>Kt(i)===t))return fe}return Z[0]??null},[Z,fe]),c=s.useMemo(()=>Wr?Ct(Wr):null,[Wr,Ct]),_e=c?.path??"",[,ki]=s.useState(0);s.useEffect(()=>{if(!o||!fe)return;const t=Kt(fe);Z.some(l=>Kt(l)===t)||me(o,Z[0]??null)},[Z,o,fe,me]);const ur=!!(o&&_e&&!$r(_e,o)),Sn=ur?Js(_e):void 0,xt=s.useMemo(()=>({allowOutsideWorkspace:a==="editor-only"&&ur,outsideFileGrant:Sn,directory:o||void 0}),[a,ur,Sn,o]),Je=s.useCallback(async t=>{const i=Js(t),l=await Ja(t,o,a==="editor-only");return l.outsideFileGrant&&l.outsideFileGrant!==i&&ki(u=>u+1),l},[a,o]),Ur=s.useRef(null),[kn,Ri]=s.useState({left:!1,right:!1}),Rn=s.useCallback(()=>{const t=Ur.current;t&&Ri({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),Tn=s.useRef(Rn);Tn.current=Rn,s.useEffect(()=>{const t=Ur.current;if(!t)return;const i=()=>Tn.current();i(),t.addEventListener("scroll",i,{passive:!0});const l=new ResizeObserver(i);return l.observe(t),()=>{t.removeEventListener("scroll",i),l.disconnect()}},[St.length]);const[En,Kr]=s.useState({}),[dr,qt]=s.useState({}),Ae=s.useRef(new Set),Ie=s.useRef(new Set),rt=s.useRef(new Map),Vn=s.useRef(0),[Pn,fr]=s.useState([]),[Ti,mr]=s.useState(!1),[z,he]=s.useState(""),{isPlaying:hr,play:Ei,stop:Vi}=Qa(),[Me,ct]=s.useState(!1),[Qe,ge]=s.useState(null),[Pi,Oe]=s.useState(""),[ye,se]=s.useState(null),ut=JSON.stringify([Us(),o,ye]),[ie,je]=s.useState(""),[Gt,Hr]=s.useState(!1),[Mn,Mi]=s.useState(`
11
+ `),Di=s.useRef(null),Ye=s.useRef(null),De=s.useRef(null),dt=s.useRef(""),Xt=s.useRef(""),nt=s.useRef(null),Dn=s.useRef(null),We=s.useRef(null),qr=s.useRef(""),Gr=s.useRef(0),Jt=s.useRef(0),kt=s.useRef(null),[pr,zi]=s.useState(0),[Li,Rt]=s.useState("idle"),[Ai,gr]=s.useState(!1),[wt,zn]=s.useState(!1),Fe=vt(t=>t.autoSaveEnabled),Ii=vt(t=>t.setAutoSaveEnabled),[Xr,Qt]=s.useState(!1),Tt=s.useRef(null),Yt=s.useRef(null),Zt=s.useRef(!1),er=s.useRef(null),tr=s.useRef(null),Ue=s.useRef(null),vr=s.useRef(null),[Oi,Jr]=s.useState(0),Et=s.useRef(null),bt=s.useRef({key:"",attempts:0});s.useEffect(()=>()=>{Et.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Et.current),Et.current=null)},[]);const[yt,Qr]=s.useState(null),[jt,Bi]=s.useState(null),[ft,Ln]=s.useState(""),[$i,Yr]=s.useState(!1),[_i,Wi]=s.useState(null),[Ui,Ki]=s.useState(null),[Hi,An]=s.useState(!1),[qi,In]=s.useState(!1),[Gi,Zr]=s.useState(!1),[On,xr]=s.useState(!1),[Bn,$n]=s.useState(0),wr=s.useRef(null),br=s.useCallback(t=>{const i=t?.currentTarget??wr.current;if(!i)return;const l=document.activeElement;l&&l!==document.body&&l!==i&&(Ya(l)||i.contains(l))||i.focus({preventScroll:!0})},[]),yr=s.useRef(null),_n=!!n.writeFile,Wn=!!n.createDirectory,Un=!!n.rename,Kn=!!n.delete,Hn=!!n.revealPath,Xi=zr(t=>t.availableApps),Ji=zr(t=>t.isCacheStale),qn=zr(t=>t.initialize),Qi=zr(t=>t.loadInstalledApps);s.useEffect(()=>{qn()},[qn]);const Yi=s.useCallback(t=>{n.revealPath&&n.revealPath(t).catch(()=>{Q.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),Zi=s.useCallback(async t=>{if(!c?.path||await La(c.path,t.id,t.appName)||await Ks(c.path,t.appName))return;const u=il(c.path)||o;u&&await Ks(u,t.appName)||Q.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[o,c?.path,e]),en=s.useCallback((t,i)=>{Qr(t),Bi(i),Ln(t==="rename"&&i.name||""),Yr(!1)},[]),[U,Ke]=s.useState(null),Vt=s.useRef(!1),mt=s.useRef(null),[Gn,Pt]=s.useState(!1),Ze=vt(t=>t.pendingFileNavigation),jr=vt(t=>t.setPendingFileNavigation),tn=vt(t=>t.pendingFileFocusPath),rn=vt(t=>t.setPendingFileFocusPath),Xn=vt(t=>t.fileEditorKeymap),rr=Qs(t=>t.settingsDefaultFileViewerPreview),ea=Qs(t=>t.showMessageTTSButtons);s.useEffect(()=>{const t=()=>{Vt.current=!1,mt.current=null,Pt(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),s.useEffect(()=>()=>{er.current!==null&&window.clearTimeout(er.current),tr.current!==null&&window.clearTimeout(tr.current)},[]);const ta=s.useCallback((t,i)=>{const l=t.split(`
12
+ `),u=Math.max(1,i.start),p=Math.min(l.length,i.end);return u>p?"":l.slice(u-1,p).join(`
13
+ `)},[]),Jn=s.useRef(null),ra=Vo({source:"file",fileLabel:c?.path??null,language:c?.path&&pn(c.path)||"text",getCodeForRange:t=>ta(z,Po(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Qn,commentText:Fr,setCommentText:Yn,editingDraftId:Nr,setSelection:Zn,saveComment:es,cancel:nr,reset:ts,startEdit:rs,deleteDraft:ns}=ra;s.useEffect(()=>{Ke(null),ts(),je(""),Hr(!1)},[c?.path,ts]),s.useEffect(()=>{Zn(U)},[U,Zn]),s.useEffect(()=>{if(!U&&!Nr)return;const t=l=>{const u=l.target;u.closest('[data-comment-input="true"]')||u.closest('[data-comment-card="true"]')||u.closest(".cm-gutterElement")||u.closest("[data-sonner-toast]")||u.closest("[data-sonner-toaster]")||Fr.trim()||(Ke(null),nr())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[nr,Fr,Nr,U]);const ss=s.useCallback((t,i)=>{const l=i??U??void 0;i&&Ke(i),es(t,l),Ke(null)},[U,es]),is=s.useCallback((t,i)=>{const l=[];for(const u of i){if(!(u&&typeof u.name=="string"&&u.name.length>0)||!S&&u.name.startsWith(".")||!C&&dl(u.name))continue;const p=u.name,h=K(u.path||""),b=h?ll(h)?h:K(`${t}/${h}`):K(`${t}/${p}`),R=u.isDirectory?"directory":"file",J=R==="file"&&p.includes(".")?p.split(".").pop()?.toLowerCase():void 0;l.push({name:p,path:b,type:R,extension:J})}return ol(l)},[C,S]),Be=s.useCallback(async t=>{const i=K(t.trim());if(!i||Ae.current.has(i)||Ie.current.has(i))return;Ie.current=new Set(Ie.current),Ie.current.add(i);const l=Vn.current+1;Vn.current=l,rt.current=new Map(rt.current),rt.current.set(i,l);const u=()=>rt.current.get(i)===l;await(n.listDirectory?n.listDirectory(i).then(h=>h.entries.map(b=>({name:b.name,path:b.path,isDirectory:b.isDirectory}))):Aa.listLocalDirectory(i).then(h=>h.map(b=>({name:b.name,path:b.path,isDirectory:b.isDirectory})))).then(h=>{if(!u())return;const b=is(i,h);Ae.current=new Set(Ae.current),Ae.current.add(i),qt(R=>{if(!R[i])return R;const J={...R};return delete J[i],J}),Kr(R=>({...R,[i]:b}))}).catch(h=>{if(!u())return;const b=h instanceof Error?h.message:String(h??"");if(b==="Directory not found"&&o&&i!==o){lt(o,i),qt(R=>{if(!R[i])return R;const J={...R};return delete J[i],J});return}console.error("Failed to load files directory:",h),qt(R=>({...R,[i]:b}))}).finally(()=>{u()&&(rt.current=new Map(rt.current),rt.current.delete(i),Ie.current=new Set(Ie.current),Ie.current.delete(i))})},[n,is,lt,o]),Cr=s.useCallback(async()=>{o&&(Ae.current=new Set,Ie.current=new Set,rt.current=new Map,qt({}),Kr(t=>Object.keys(t).length===0?t:{}),await Be(o))},[Be,o]),et=s.useCallback(async t=>{if(!t){await Cr();return}const i=K(t);Ae.current=new Set(Ae.current),Ae.current.delete(i),Ie.current=new Set(Ie.current),Ie.current.delete(i),await Be(i)},[Be,Cr]),as=s.useRef(""),os=s.useRef("");s.useEffect(()=>{if(!o)return;const t=`${o}|h${S?"1":"0"}|g${C?"1":"0"}`,i=as.current!==o,l=os.current!==t;!i&&!l||(i&&(as.current=o,he(""),ge(null),Oe(""),se(null),L(!1)),l&&(os.current=t,Ae.current=new Set,Ie.current=new Set,rt.current=new Map,qt({}),Kr(u=>Object.keys(u).length===0?u:{}),Be(o)))},[Be,o,C,S]),s.useEffect(()=>{if(!n.listDirectory)return;const t=()=>{if(!document.hidden&&pe.length>0)for(const i of pe)et(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[pe,n.listDirectory,et]),s.useEffect(()=>{if(!n.listDirectory||pe.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of pe)et(i)},8e3);return()=>clearInterval(t)},[pe,n.listDirectory,et]);const na=s.useCallback(async t=>{if(t?.preventDefault(),!jt||!yt)return;Yr(!0);const i=()=>{Qr(null)},l=p=>{Q.error(p)},u=()=>{Yr(!1)};if(yt==="createFile"){if(!ft.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),u();return}if(!n.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),u();return}const p=jt.path,h=p?`${p}/`:"",b=K(`${h}${ft.trim()}`);await n.writeFile(b,"").then(async R=>{R.success&&(Q.success(e("sidebarFilesTree.toast.fileCreated")),await et(p)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(yt==="createFolder"){if(!ft.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),u();return}const p=jt.path,h=p?`${p}/`:"",b=K(`${h}${ft.trim()}`);await n.createDirectory(b).then(async R=>{R.success&&(Q.success(e("sidebarFilesTree.toast.folderCreated")),await et(p)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(yt==="rename"){if(!ft.trim()){l(e("sidebarFilesTree.toast.nameRequired")),u();return}if(!n.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),u();return}const p=jt.path,h=p.split("/").slice(0,-1).join("/"),b=h?`${h}/`:"",R=K(`${b}${ft.trim()}`);await n.rename(p,R).then(async J=>{J.success&&(Q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await et(h),o&&G(o,p),(c?.path===p||c?.path.startsWith(`${p}/`))&&(o&&me(o,null),he(""),ge(null),Oe(""),se(null),f&&L(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(yt==="delete"){if(!n.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),u();return}const p=jt.path,h=p.split("/").slice(0,-1).join("/");await n.delete(p).then(async b=>{b.success&&(Q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await et(h),o&&G(o,p),(c?.path===p||c?.path.startsWith(`${p}/`))&&(o&&me(o,null),he(""),ge(null),Oe(""),se(null),f&&L(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}u()},[yt,jt,ft,n,et,f,G,o,c?.path,me,e]);s.useEffect(()=>{if(!T){fr([]),mr(!1);return}const t=k.trim();if(!t){fr([]),mr(!1);return}let i=!1;return mr(!0),A(T,t,150,{includeHidden:S,respectGitignore:!C,type:"file"}).then(l=>{if(i)return;const p=l.filter(h=>C||!fl(h.path)).map(h=>({name:h.name,path:K(h.path),type:"file",extension:h.extension,relativePath:h.relativePath}));fr(p)}).catch(()=>{i||fr([])}).finally(()=>{i||mr(!1)}),()=>{i=!0}},[T,k,A,S,C]);const Sr=s.useCallback(async(t,i)=>{const l=await Je(t);if(n.readFile)return(await n.readFile(t,{...l,directory:o||void 0,...i})).content??"";const u=new URLSearchParams({path:t});l.allowOutsideWorkspace&&u.set("allowOutsideWorkspace","true"),l.outsideFileGrant&&u.set("outsideFileGrant",l.outsideFileGrant),o&&u.set("directory",o);const p=await Hs(`/api/fs/read?${u.toString()}`,i?.fresh?{cache:"no-store"}:void 0);if(!p.ok){const h=await p.json().catch(()=>({error:p.statusText}));throw new Error(h.error||e("filesView.error.readFileFailed"))}return p.text()},[n,Je,o,e]),ht=s.useCallback(async t=>{if(n.statFile){const i=await Je(t),l=await n.statFile(t,{...i,directory:o||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[n,Je,o]);s.useEffect(()=>{if(!o||!n.statFile||Z.length===0)return;let t=!1;const i=[...Z];return Promise.all(i.map(async l=>{try{const u=await Je(l),p=await n.statFile?.(l,{...u,directory:o||void 0});!t&&p&&!p.isFile&&G(o,l)}catch(u){!t&&fi(u)&&G(o,l)}})),()=>{t=!0}},[n,Z,G,Je,o]);const nn=s.useMemo(()=>z.length>Wt?`${z.slice(0,Wt)}
14
+
15
+ … truncated …`:z,[z]),ze=ie!==nn,Mt=s.useCallback(async()=>{if(!c||!n.writeFile)return Q.error(e("filesView.toast.savingNotSupported")),!1;const t=or(c.path)||wt;if(!rl({selectedFilePath:c.path,loadedFilePath:ye,fileLoading:Me,isDirty:ze,draftContent:ie,fileContent:z,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):ie===""&&z!==""&&ye!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${z.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!ze)return!0;Hr(!0);try{const i=vl(ie,Mn);if(!(await n.writeFile(c.path,i))?.success)return Q.error(e("filesView.toast.writeFileFailed")),!1;if(he(ie),qr.current=i,Gr.current+=1,o&&$r(c.path,o)){const u=Or(o,c.path);u&&Za.requestGitRefresh({directory:o,paths:[u]})}if(o&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(K(c.path))){const u=eo.getState().projects.find(p=>K(p.path)===K(o));if(u)try{await ko(u.id)}catch{Q.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&Dr(c.path)&&(dt.current=ie,Xt.current=ie),ht(c.path).then(u=>{u&&(We.current=u)}).catch(()=>{}),!0}catch(i){return Q.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Hr(!1)}},[wt,ie,z,Me,n,ze,Mn,ye,ht,o,c,e]);s.useEffect(()=>{Fe||(Rt("idle"),Ye.current&&(clearTimeout(Ye.current),Ye.current=null))},[Fe]);const ls=1500;s.useEffect(()=>{const t=!!(c&&n.writeFile),i=!!(c?.path&&(or(c.path)||wt));if(tl({autoSaveEnabled:Fe,isDirty:ze,canWrite:t,isSaving:Gt,fileLoading:Me,selectedFilePath:c?.path,loadedFilePath:ye,isNonEditableBinary:i}))return Ye.current=setTimeout(()=>{Mt().then(l=>{l&&(Rt("saved"),setTimeout(()=>Rt("idle"),2e3))})},ls),()=>{Ye.current&&(clearTimeout(Ye.current),Ye.current=null)}},[Fe,wt,ie,Me,ze,ye,c,n.writeFile,Gt,Mt]),s.useEffect(()=>{Rt("idle")},[c?.path]),to({save_file:t=>{if(!(t.target instanceof Node)||!vr.current?.contains(t.target))return!1;Ye.current&&(clearTimeout(Ye.current),Ye.current=null),Gt||Mt().then(i=>{i&&(Rt("saved"),setTimeout(()=>Rt("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node))return!1;if(qe&&Le()==="preview"){if(f||!(W?yr.current:wr.current)?.contains(t.target))return!1;xr(!0),$n(l=>l+1);return}if(!vr.current?.contains(t.target))return!1;ce(!0)}});const Dt=s.useCallback(t=>{const i=Ci(t);qr.current=t,Gr.current+=1,Mi(gl(t)),he(i),dt.current=i,Xt.current=i,je(i.length>Wt?`${i.slice(0,Wt)}
16
+
17
+ … truncated …`:i)},[]),cs=s.useCallback(async t=>{const i=Jt.current+1;Jt.current=i;const l=()=>{if(!o)return!1;const R=Xe.getState().byRoot[o],J=R?.selectedPath??R?.openPaths[0]??null;return Jt.current===i&&J===t.path};if(ge(null),Oe(""),se(null),zn(!1),ct(!0),await Je(t.path),!l())return;const u=gn(t.path),p=Ys(t.path),h=Zs(t.path),b=or(t.path);if(f&&L(!0),d.isDesktop&&u&&!p){he(""),je("");return}if(!d.isDesktop&&u&&!p){he(""),je(""),se(t.path),ct(!1);return}if(h){he(""),je(""),se(t.path),ct(!1);return}if(b){he(""),je(""),se(t.path),ct(!1);return}await Sr(t.path).then(R=>{if(l()){if(ei(R)){zn(!0),he(""),je(""),se(t.path);return}Dt(R),se(t.path),ht(t.path).then(J=>{J&&l()&&(We.current=J)}).catch(()=>{})}}).catch(R=>{if(l()){if(ml(R)){if(ct(!1),o&&me(o,null),ge(null),he(""),je(""),se(null),We.current=null,P.trim().length>0&&M(""),f&&L(!1),o){const ar=[...ui(t.path,o),t.path];ar.length>0&&cr(o,ar);for(const gt of ar)Ae.current.has(gt)||Be(gt)}return}if(fi(R)){o&&G(o,t.path),he(""),je(""),ge(null),We.current=null,f&&L(!1);return}he(""),je(""),ge(R instanceof Error?R.message:e("filesView.error.readFileFailed")),We.current=null}}).finally(()=>{l()&&ct(!1)})},[Dt,cr,f,Be,Sr,ht,G,Je,o,d.isDesktop,P,me,e]),kr=s.useCallback(async(t,i)=>{if(!o)return;const l=ui(t,o),u=i?[...l,t]:l;u.length>0&&cr(o,u);const p=u.map(h=>{if(!Ae.current.has(h))return Be(h)}).filter(Boolean);await Promise.all(p)},[cr,Be,o]),us=s.useCallback((t,i)=>{const l=i.findIndex(u=>u.path===t);return l===-1||i.length<=1?null:i[l+1]??i[l-1]??null},[]),Te=s.useCallback(async t=>{if(Zt.current)Zt.current=!1;else if(ze){Qt(!0),Tt.current=t;return}o&&(me(o,t.path),kr(t.path,!1)),ge(null),Oe(""),he(""),dt.current="",Xt.current="",je(""),se(null),f&&L(!0)},[kr,ze,f,o,me]);s.useEffect(()=>{c?.path&&kr(c.path,!1)},[kr,c?.path]),s.useEffect(()=>{if(!c){Jt.current+=1,kt.current=null,ct(!1);return}if(ye===c.path||kt.current===c.path)return;const t=c.path;kt.current=t,cs(c).finally(()=>{kt.current===t&&(kt.current=null)})},[pr,cs,ye,c]);const Rr=s.useRef(ze);Rr.current=ze,s.useEffect(()=>Ro(({runtimeKey:t,paths:i})=>{const l=c?.path;t!==Us()||!l||Rr.current||!i.includes(K(l))||(Jt.current+=1,kt.current=null,We.current=null,Oe(""),ge(null),se(null),zi(u=>u+1))}),[c?.path]),s.useEffect(()=>{if(!c?.path||ye!==c.path)return;const t=c.path,i=()=>Rr.current||Dr(t)&&dt.current!==Xt.current,l=!or(t)&&!gn(t)&&!wt?Jo({readContent:()=>Sr(t,{fresh:!0}),getLoadedContent:()=>qr.current,getLoadedRevision:()=>Gr.current,isDirty:i,applyContent:b=>{if(ei(b)){se(null);return}Dt(b)}}):null;let u=!1,p=!1;const h=window.setInterval(()=>{document.hidden||p||(p=!0,ht(t).then(async b=>{if(u||!b)return;const R=We.current;if(!R||R.path!==t){We.current=b;return}if(Yo(R,b)){if(l&&b.size<=hl){await l.poll()&&!u&&(We.current=b);return}Rr.current||(We.current=b,se(null))}}).catch(()=>{}).finally(()=>{p=!1}))},2e3);return()=>{u=!0,l?.dispose(),window.clearInterval(h)}},[Dt,wt,ye,Sr,ht,c?.path]);const sa=s.useCallback(()=>{const t=Tt.current,i=Yt.current;if(Tt.current=null,Yt.current=null,Zt.current=!0,Qt(!1),je(nn),i){o&&tt(o,i),c?.path===i&&(t?Te(t):(o&&me(o,null),he(""),ge(null),Oe(""),se(null),f&&L(!1)));return}if(t){Te(t);return}},[nn,Te,f,tt,o,c?.path,me]),ia=s.useCallback(async()=>{const t=Tt.current,i=Yt.current;if(!await Mt()){Zt.current=!1;return}if(Tt.current=null,Yt.current=null,Zt.current=!0,Qt(!1),i){o&&tt(o,i),c?.path===i&&(t?await Te(t):(o&&me(o,null),he(""),ge(null),Oe(""),se(null),f&&L(!1)));return}if(t){await Te(t);return}},[Te,f,tt,o,Mt,c?.path,me]),ds=s.useCallback(t=>{const i=c?.path===t,l=us(t,St);if(i&&ze){Qt(!0),Tt.current=l,Yt.current=t;return}if(o&&tt(o,t),!!i){if(l){Te(l);return}o&&me(o,null),he(""),ge(null),Oe(""),se(null),f&&L(!1)}},[us,Te,ze,f,St,tt,o,c?.path,me]),aa=s.useCallback(t=>{if(Z.includes(t))return"open";if(V?.files){const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=V.files.find(u=>u.path===i);if(l){if(l.index==="A"||l.working_dir==="?")return"git-added";if(l.index==="D")return"git-deleted";if(l.index==="M"||l.working_dir==="M")return"git-modified"}}return null},[Z,V,o]),oa=s.useCallback(t=>{if(!V?.files)return null;const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=i?`${i}/`:"";let u=0,p=0;for(const h of V.files)h.path.startsWith(l)&&((h.index==="M"||h.working_dir==="M")&&u++,(h.index==="A"||h.working_dir==="?")&&p++);return u+p>0?{modified:u,added:p}:null},[V,o]),la=s.useCallback(async t=>{const i=K(t);o&&(Cn(o,i),Ae.current.has(i)||await Be(i))},[Be,o,Cn]),ca=s.useMemo(()=>({canRename:Un,canCreateFile:_n,canCreateFolder:Wn,canDelete:Kn,canReveal:Hn}),[Un,_n,Wn,Kn,Hn]);function fs(t,i){const l=En[t]??[];return l.map((u,p)=>{const h=u.type==="directory",b=h&&pe.includes(u.path),R=c?.path===u.path,J=p===l.length-1;return r.jsxs("li",{className:"relative",children:[i>0&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),J&&r.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),r.jsx(wl,{node:u,root:o,isExpanded:b,isActive:R,isMobile:f,isBrowserClient:y,alwaysShowActions:N,status:h?void 0:aa(u.path),badge:h?oa(u.path):void 0,permissions:ca,downloadFile:n.downloadFile,contextMenuPath:_i,setContextMenuPath:Wi,rightClickMenuPath:Ui,setRightClickMenuPath:Ki,onSelect:Te,onToggle:la,onRevealPath:Yi,onOpenDialog:en}),h&&b&&r.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[dr[u.path]?r.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:dr[u.path],children:dr[u.path]}),r.jsxs(O,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{et(u.path)},children:[r.jsx(F,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,fs(u.path,i+1)]})]},u.path)})}const Ne=!!(c?.path&&gn(c.path)),Tr=!!(c?.path&&Ys(c.path)),$e=!!(c?.path&&Zs(c.path)),sn=!!(c?.path&&(or(c.path)||wt)),st=sn&&!Ne&&!$e,ms=s.useMemo(()=>K(Ze?.path??""),[Ze?.path]),zt=!!(Ze&&ms&&_e&&_e===ms&&!Me&&!Qe&&!Ne&&!$e&&!st),pt=s.useMemo(()=>Or(o,_e),[_e,o]),ua=!!(c&&(!Ne||Tr)&&!$e&&!st&&z.length>0),da=!!(c&&pt.length>0),He=!!(c&&!ur&&!sn&&!Ne&&n.writeFile&&z.length<=Wt),qe=!!(c?.path&&mi(c.path)),Lt=!!(c?.path&&xl(c.path)),At=!!(c?.path&&yn(c.path)),sr=!!(c?.path&&Dr(c.path)),Er=!!(c&&!sn&&!Ne)&&!qe&&!sr&&!(At&&$==="preview"),fa=qe&&xe==="edit"||At&&$==="edit"||Lt&&ae==="text"||!qe&&!At&&!Lt&&B==="edit",Vr=s.useMemo(()=>_e?ro(_e):null,[_e]),[hs,an]=s.useState(null);s.useEffect(()=>{let t=!1;const i=c?.path;if(!i||Vr){an(null);return}return an(null),no(i).then(l=>{t||an(l)}),()=>{t=!0}},[c?.path,Vr]),s.useEffect(()=>{!He&&B==="edit"&&ve("view")},[He,B]);const on="aiworker:files:md-viewer-mode",ln="aiworker:files:html-viewer-mode",cn="aiworker:files:json-viewer-mode";s.useEffect(()=>{const t=c?.path;if(!t)return;ve(le.current[t]??"edit");let i=rr?"preview":"edit";try{const p=localStorage.getItem(on);(p==="preview"||p==="edit")&&(i=p)}catch{}ue(be.current[t]??i);let l=rr?"preview":"edit";try{const p=localStorage.getItem(ln);(p==="preview"||p==="edit")&&(l=p)}catch{}H(Ee.current[t]??l),ne(de.current[t]??(rr?"preview":"edit"));let u=rr?"tree":"text";try{const p=localStorage.getItem(cn);(p==="tree"||p==="text")&&(u=p)}catch{}we(u)},[c?.path,rr]);const ma=s.useCallback(t=>{const i=c?.path;i&&(le.current[i]=t),ve(t)},[c?.path]),ha=s.useCallback(t=>{const i=c?.path;i&&(be.current[i]=t),ue(t);try{localStorage.setItem(on,t)}catch{}},[c?.path]),Le=s.useCallback(()=>xe,[xe]),ps=c&&qe&&Le()==="preview"&&!Me?c.path:null;s.useEffect(()=>{!ps||f||br()},[br,W,f,ps]);const pa=s.useCallback(t=>{we(t);try{localStorage.setItem(cn,t)}catch{}},[]),ga=s.useCallback(t=>{const i=c?.path;i&&(Ee.current[i]=t),H(t);try{localStorage.setItem(ln,t)}catch{}},[c?.path]),va=s.useCallback(t=>{const i=c?.path;if(i&&(de.current[i]=t),De.current&&(clearTimeout(De.current),De.current=null),nt.current!==null&&(cancelAnimationFrame(nt.current),nt.current=null),t==="edit")je(dt.current||z),ne(t);else{dt.current=ie;const l=i;ne("edit"),nt.current=requestAnimationFrame(()=>{nt.current=requestAnimationFrame(()=>{nt.current=null,!(o&&l&&Xe.getState().byRoot[o]?.selectedPath!==l)&&(oe(u=>u+1),ne("preview"))})});return}},[ie,z,o,c?.path]),un=s.useCallback(async(t,i)=>{if(!n.writeFile||i===Xt.current)return!1;if(!(await n.writeFile(t,i))?.success)return Q.error(e("filesView.toast.writeFileFailed")),!1;Dt(i);const u=await ht(t).catch(()=>null);return u&&(We.current=u),!0},[Dt,n,ht,e]);s.useEffect(()=>()=>{De.current&&(clearTimeout(De.current),De.current=null),nt.current!==null&&(cancelAnimationFrame(nt.current),nt.current=null)},[re,c?.path]);const xa=s.useCallback(t=>{if(dt.current=t,!Fe||!c?.path||re!=="preview"||!n.writeFile)return;De.current&&clearTimeout(De.current);const i=c.path;De.current=setTimeout(()=>{De.current=null,un(i,t).then(l=>{l&&(gr(!0),setTimeout(()=>gr(!1),1500))}).catch(l=>{Q.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},ls)},[Fe,re,n.writeFile,un,c?.path,e]),wa=s.useMemo(()=>sr&&(dt.current||ie)||z,[ie,z,sr]),gs=s.useCallback(()=>$,[$]);s.useEffect(()=>{const t=l=>{const u=l?"preview":"edit",p=l?"tree":"text";for(const h of Z)le.current[h]="edit",mi(h)&&(be.current[h]=u),yn(h)&&(Ee.current[h]=u),Dr(h)&&(de.current[h]=u);ve("edit"),ue(u),H(u),ne(u),we(p);try{localStorage.setItem(on,u),localStorage.setItem(ln,u),localStorage.setItem(cn,p)}catch{}},i=l=>{const u=!!l.detail?.enabled;t(u)};return window.addEventListener("aiworker:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("aiworker:file-viewer-preview-mode-changed",i)}},[Z]),s.useEffect(()=>{if(!Ze||!o)return;const t=()=>{typeof window>"u"||Et.current===null&&(Et.current=window.requestAnimationFrame(()=>{Et.current=null,Jr(it=>it+1)}))},i=(it,Ft)=>{if(it.state.doc.length!==Ft.length)return!1;if(Ft.length===0)return!0;const hn=Math.min(128,Ft.length);if(it.state.sliceDoc(0,hn)!==Ft.slice(0,hn))return!1;const _s=Math.max(0,Ft.length-hn);return it.state.sliceDoc(_s,Ft.length)===Ft.slice(_s)},l=K(Ze.path);if(!l){jr(null),bt.current={key:"",attempts:0};return}const u=`${l}:${Ze.line}:${Ze.column??1}`;if(bt.current.key!==u&&(bt.current={key:u,attempts:0}),c?.path!==l){if(Xr)return;Te(Ct(l));return}if(Me||ye!==l)return;if(Qe||Ne||$e||st){jr(null),bt.current={key:"",attempts:0};return}if(!He)return;if(B!=="edit"){ve("edit");return}const p=Ue.current;if(!p){t();return}if(!i(p,ie)){t();return}const h=Math.max(1,Math.min(Ze.line,p.state.doc.lines)),b=p.state.doc.line(h),R=Math.max(1,Ze.column||1),J=Math.max(0,b.to-b.from),ar=Math.min(J,R-1),gt=b.from+ar;if(!(p.state.selection.main.head===gt)||bt.current.attempts===0){bt.current.attempts+=1,p.dispatch({selection:{anchor:gt},effects:Nt.scrollIntoView(gt,{y:"center"})}),p.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const it=Ue.current;it&&(it.dispatch({selection:{anchor:gt},effects:Nt.scrollIntoView(gt,{y:"center"})}),it.focus())}),jr(null),bt.current={key:"",attempts:0}},[He,Xr,ie,Oi,Qe,Me,Ne,$e,st,ye,Te,Ze,o,c?.path,jr,B,Ct]),s.useEffect(()=>{if(!tn||!o)return;const t=K(tn);if(!t){rn(null);return}c?.path===t&&(Me||ye!==t||(!Qe&&!Ne&&!$e&&!st&&He&&B==="edit"&&Ue.current?.focus(),rn(null)))},[He,Qe,Me,Ne,$e,st,ye,tn,o,c?.path,rn,B]);const It=s.useCallback(t=>{if(!f||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const l=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,l-(i.offsetTop+i.height))<=0)return;const p=t.state.selection.main.head,h=t.coordsAtPos(p);if(!h)return;const b=Math.round(i.offsetTop+i.height),J=h.bottom+20-b;J<=0||(t.scrollDOM.scrollTop+=J)},[f]);s.useEffect(()=>{if(!f||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{It(Ue.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[f,It]),so("open_go_to_line",t=>{if(!He||B!=="edit"||f)return!1;const i=t.target;if(i?.closest('[role="dialog"]')||!(i instanceof Node)||!vr.current?.contains(i))return!1;const l=!!i?.closest(".cm-editor");if(!!i?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!l)return!1;Zr(!0)});const Pr=vt(t=>t.editorFontSize),vs=s.useMemo(()=>{if(!c?.path)return[ri(x,{fontSize:Pr})];const t=pn(c.path),i=[ri(x,t?{syntaxColors:!1,fontSize:Pr}:{fontSize:Pr})],l=Vr??hs;return l&&i.push(l),t&&i.push(vo({language:t,themeName:x.metadata.id,theme:Fo(x)})),X&&i.push(Nt.lineWrapping),f&&i.push(Nt.updateListener.of(u=>{u.view.hasFocus&&(u.selectionSet||u.focusChanged||u.viewportChanged||u.geometryChanged)&&window.requestAnimationFrame(()=>{It(u.view)})})),i},[x,c?.path,Vr,hs,X,f,It,Pr]),xs=s.useMemo(()=>({light:Ve.metadata.id,dark:Pe.metadata.id}),[Ve.metadata.id,Pe.metadata.id]),ir=c?.path&&$e&&(!xt.allowOutsideWorkspace||xt.outsideFileGrant)?`${c.path}|${xt.allowOutsideWorkspace?"outside":"workspace"}|${xt.outsideFileGrant??""}|${pr}`:"",Mr=c?.path&&At&&$==="preview"&&!d.isVSCode?`${c.path}|${pr}`:"",ws=e("filesView.error.readFileFailed"),{readyKey:bs,nonce:ba}=pi(Mr,ge,ws),{readyKey:ys,nonce:js}=pi(ir,ge,ws),ya=!!(Mr&&bs!==Mr),Fs=!!(ir&&ys!==ir),Ns=c?.path&&Ne?Tr?`data:${io(c.path)};utf8,${encodeURIComponent(z)}`:Pi:"",Cs=c?.path&&$e&&ir&&ys===ir?qs().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:xt.allowOutsideWorkspace?"true":void 0,outsideFileGrant:xt.outsideFileGrant,directory:o||void 0}):"",Ss=s.useCallback(t=>r.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:r.jsx("iframe",{src:Cs,className:"h-full w-full border-0",title:t.name},js)}),[Cs,js]);s.useEffect(()=>{let t=!1,i="";return(async()=>{if(!c?.path||!Ne||Tr){Oe("");return}ge(null);const u=await Je(c.path);if(t)return;await(n.readFileBinary?n.readFileBinary(c.path,u).then(h=>h.dataUrl):(async()=>{const h=await Hs("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:u.allowOutsideWorkspace?"true":void 0,outsideFileGrant:u.outsideFileGrant,directory:o||void 0}});if(!h.ok)throw new Error(e("filesView.error.readFileFailed"));const b=await h.blob();return i=URL.createObjectURL(b),t?(URL.revokeObjectURL(i),i="",""):i})()).then(h=>{t||(Oe(h),se(c.path))}).catch(h=>{t||(Oe(""),ge(h instanceof Error?h.message:e("filesView.error.readFileFailed")),se(null))}).finally(()=>{t||ct(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[pr,n,Ne,Tr,Je,o,c?.path,xt,e]);const ja=s.useCallback(()=>Qr(null),[]),Fa=s.useMemo(()=>Mo({drafts:Qn,editingDraftId:Nr,commentText:Fr,onTextChange:Yn,selection:U,isDragging:Gn,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:ss,onCancel:()=>{Ke(null),nr()},onEdit:t=>{rs(t),Ke({start:t.startLine,end:t.endLine})},onDelete:ns}),[nr,Fr,ns,Nr,Qn,ss,Gn,U,c?.path,Yn,rs]),ks=li(),Rs=li(),Ts=!Me&&!Qe&&ye===_e,Es=Ts&&Er&&B==="view"&&!(Lt&&ae==="tree"),Vs=Ts&&qe&&Le()==="preview",{setScroller:Ps,restore:Na}=Lr(Es?`${ut}:code`:null),{setScroller:Ms,restore:Ca}=Lr(Es?`${ut}:code:fullscreen`:null),{setScroller:Ds}=Lr(Vs?`${ut}:markdown`:null),{setScroller:zs}=Lr(Vs?`${ut}:markdown:fullscreen`:null),{setScroller:Ls}=ks,{setScroller:As}=Rs,Sa=s.useCallback(t=>{Ls(t),Ps(t)},[Ls,Ps]),ka=s.useCallback(t=>{As(t),Ms(t)},[As,Ms]),Ra=s.useCallback(t=>{Jn.current=t,wr.current=t,Ds(t)},[Ds]),Ta=s.useCallback(t=>{yr.current=t,zs(t)},[zs]),dn=uo("unified"),Ge=z.length>Wt,fn=s.useMemo(()=>Ge?pl(z):void 0,[z,Ge]),Is=s.useCallback((t,i,l,u)=>{const p={name:t.name,contents:i,lang:pn(t.path)||void 0},h=b=>r.jsx(jo,{file:Ge&&fn?{...p,cacheKey:`${t.path}:${fn}`}:p,options:{disableFileHeader:!0,overflow:X?"wrap":"scroll",theme:xs,themeType:x.metadata.variant==="dark"?"dark":"light",onPostRender:u},className:Ge?"block w-full":"block h-full w-full",style:Ge?void 0:{height:"100%"}},b);return Ge?r.jsx("div",{className:"h-full",children:r.jsx(No.Provider,{value:l.virtualizer,children:r.jsx(Co.Provider,{value:dn,children:h(`${t.path}:${dn?"pool":"pending"}`)})})}):r.jsx("div",{className:"h-full",children:h(t.path)})},[x.metadata.variant,Ge,fn,xs,dn,X]),Os=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!c)return null;const l=i==="docked",u=ao(oo("save_file")),p=l?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",h=(b,R)=>r.jsxs(Ot,{children:[r.jsx(Bt,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:R})}),r.jsx($t,{side:"bottom",sideOffset:6,children:b})]});return r.jsxs("div",{className:p,children:[He&&fa&&r.jsxs(r.Fragment,{children:[Gt?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[r.jsx(F,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):Fe&&Li==="saved"&&!ze?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[r.jsx(F,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):ze?h(e(Fe?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>{Mt()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Fe?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),"aria-label":e("filesView.editor.saveAria",{shortcut:u}),children:r.jsx(F,{name:"save-3",className:"size-4"})})):null,h(e(Fe?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>Ii(!Fe),className:q("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Fe?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(Fe?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(Fe?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:Fe?r.jsx(F,{name:"file-check-fill",className:"size-4"}):r.jsx(F,{name:"file-check",className:"size-4"})}))]}),r.jsxs(jn,{onOpenChange:Se,children:[r.jsxs(Ot,{children:[r.jsx(Bt,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:r.jsx(Fn,{asChild:!0,children:r.jsx(O,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:r.jsx(F,{name:"file-transfer",className:"size-4"})})})})}),r.jsx($t,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),r.jsxs(Nn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Xi.map(b=>r.jsxs(Ir,{className:"flex items-center gap-2",onClick:()=>{Zi(b)},children:[r.jsx(al,{label:b.label,iconDataUrl:b.iconDataUrl}),r.jsx("span",{className:"typography-ui-label text-foreground",children:b.label})]},b.id)),Ji?r.jsxs(Ir,{className:"flex items-center gap-2",onClick:()=>{Qi(!0)},children:[r.jsx(F,{name:"refresh",className:"size-4"}),r.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Ne&&!$e&&!st&&r.jsxs(r.Fragment,{children:[h(e(X?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>Ce(!X),className:q("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",X?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(X?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:r.jsx(F,{name:"text-wrap",className:"size-4"})})),B==="edit"&&r.jsxs(r.Fragment,{children:[h(e("filesView.editor.findInFile"),r.jsx(O,{variant:"ghost",size:"sm",onClick:b=>{ce(!ee),b.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:r.jsx(F,{name:"search",className:"size-4"})})),h(e("filesView.editor.goToLine"),r.jsx(O,{variant:"ghost",size:"sm",onClick:b=>{Zr(R=>!R),b.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:r.jsx(F,{name:"menu-fold-2",className:"size-4"})})),r.jsx(Wo,{open:Gi,onOpenChange:Zr,view:Ue.current,variant:"inline"})]})]}),Er&&He&&!Lt&&!At&&r.jsx(wn,{currentMode:B==="view"?"preview":"edit",onToggle:()=>{ma(B==="view"?"edit":"view")}}),qe&&h(e(Le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>ha(Le()==="preview"?"edit":"preview"),className:q("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",Le()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(Le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(Le()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:r.jsx(F,{name:Le()==="preview"?"eye":"eye-off",className:"size-4"})})),yn(c?.path??"")&&r.jsx(wn,{currentMode:gs(),onToggle:()=>{ga(gs()==="preview"?"edit":"preview")}}),qe&&Le()==="preview"&&h(e("filesView.editor.findInFile"),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>{xr(!0),$n(b=>b+1)},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:r.jsx(F,{name:"search",className:"size-4"})})),qe&&Le()==="preview"&&ea&&r.jsxs(Ot,{children:[r.jsx(Bt,{asChild:!0,children:r.jsx(O,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(hr?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{hr?Vi():z.trim()&&Ei(z)},children:hr?r.jsx(F,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(F,{name:"volume-up",className:"size-4"})})}),r.jsx($t,{sideOffset:8,children:e(hr?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),sr&&r.jsxs(r.Fragment,{children:[r.jsx(wn,{currentMode:re,onToggle:()=>va(re==="preview"?"edit":"preview")}),re==="preview"&&r.jsx(O,{variant:"ghost",size:"sm",onClick:async()=>{const b=Dn.current?.getXml();if(De.current&&(clearTimeout(De.current),De.current=null),c?.path&&b){if(!await un(c.path,b))return;gr(!0),setTimeout(()=>gr(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:Ai?r.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(F,{name:"save-3",className:"size-4"})})]}),Lt&&h(e(ae==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>pa(ae==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ae==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ae==="tree"?r.jsx(F,{name:"code-sslash",className:"size-4"}):r.jsx(F,{name:"node-tree",className:"size-4"})})),ua&&h(e("filesView.editor.copyFileContents"),r.jsx(O,{variant:"ghost",size:"sm",onClick:async()=>{(await Br(z)).ok?(An(!0),er.current!==null&&window.clearTimeout(er.current),er.current=window.setTimeout(()=>{An(!1)},1200)):Q.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Hi?r.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(F,{name:"clipboard",className:"size-4"})})),da&&h(e("filesView.editor.copyFilePathTitle",{path:pt}),r.jsx(O,{variant:"ghost",size:"sm",onClick:async()=>{(await Br(pt)).ok?(In(!0),tr.current!==null&&window.clearTimeout(tr.current),tr.current=window.setTimeout(()=>{In(!1)},1200)):Q.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:pt}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:pt}),children:qi?r.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(F,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&h(e("filesView.editor.saveFile"),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>{const b=n.downloadFile;b&&b(c.path).catch(R=>{console.error("Download failed:",R),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:r.jsx(F,{name:"download",className:"size-4"})})),t?h(e("filesView.editor.exitFullscreen"),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>Y(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:r.jsx(F,{name:"fullscreen-exit",className:"size-4"})})):!f&&a==="full"&&h(e(W?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>Y(!W),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(W?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(W?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:W?r.jsx(F,{name:"fullscreen-exit",className:"size-4"}):r.jsx(F,{name:"fullscreen",className:"size-4"})}))]})},mn=r.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[r.jsx(vi,{open:Xr,onOpenChange:t=>{t||Qt(!0)},children:r.jsxs(xi,{showCloseButton:!1,className:"max-w-md",children:[r.jsxs(wi,{children:[r.jsx(bi,{children:e("filesView.unsaved.title")}),r.jsx(yi,{children:e("filesView.unsaved.description")})]}),r.jsxs(ji,{children:[r.jsx(O,{variant:"outline",onClick:()=>{ia()},disabled:Gt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),r.jsx(O,{variant:"destructive",onClick:sa,children:e("filesView.unsaved.discard")})]})]})}),r.jsxs("div",{className:q("flex flex-col flex-shrink-0",E&&"border-b border-border/40"),children:[E?r.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[f&&_&&r.jsx("button",{type:"button",onClick:()=>L(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:r.jsx(F,{name:"arrow-left-s",className:"size-5"})}),f?c?r.jsxs(jn,{children:[r.jsx(Fn,{asChild:!0,children:r.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[r.jsx(Ar,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(di,{name:c.name}),r.jsx(F,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),r.jsx(Nn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:St.map(t=>{const i=c?.path===t.path;return r.jsxs(Ir,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}i||Te(t)},className:q("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[r.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[r.jsx(Ar,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(di,{name:t.name})]}),r.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),ds(t.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(F,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):St.length>0?r.jsxs("div",{className:"relative min-w-0 flex-1",children:[kn.left&&r.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),kn.right&&r.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),r.jsx("div",{ref:Ur,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:St.map(t=>{const i=c?.path===t.path;return r.jsxs("div",{title:Or(o,t.path),className:q("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[r.jsx(Ar,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx("button",{type:"button",onClick:()=>{i||Te(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),r.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),ds(t.path)},className:q("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!N&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(F,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,c?r.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[pt&&!f?r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:pt,children:pt}):null,r.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Os({layout:"docked"})})]}):null]}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:r.jsx(vn,{ref:Sa,outerClassName:"h-full min-w-0",className:q("h-full min-w-0",Ge&&"[overflow-anchor:none]"),children:c?Me||Fs?D?r.jsx("div",{className:"p-3"}):r.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):Qe?r.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Qe}):Ne?r.jsx("div",{className:"flex h-full items-center justify-center p-3",children:r.jsx("img",{src:Ns,alt:c?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):$e?Ss(c):st?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[r.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),r.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),n.downloadFile?r.jsxs(O,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=n.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(F,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&sr&&re==="preview"?r.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:r.jsx(sl,{ref:Dn,xml:wa,onChange:xa},`${c.path}:${ke}`)}):c&&Lt&&ae==="tree"?r.jsx(xn,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:r.jsx("div",{className:"h-full overflow-auto",children:r.jsx(yo,{jsonString:z,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&qe&&Le()==="preview"?r.jsxs("div",{className:"relative h-full min-h-0",children:[r.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3 outline-none",tabIndex:-1,onMouseDown:br,ref:Ra,children:[r.jsx(si,{containerRef:Jn,filePath:c.path,fileContent:z}),z.length>500*1024&&r.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(z.length/1024)})}),r.jsx(xn,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:r.jsx(ti,{content:z,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),!W&&r.jsx(oi,{containerRef:wr,open:On,onOpenChange:xr,focusNonce:Bn})]}):c&&At&&$==="preview"?ya?r.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):r.jsx("div",{className:"h-full overflow-hidden",children:r.jsx("iframe",{src:!d.isVSCode&&bs===Mr?(()=>{const t=c.path.split("/").map(i=>encodeURIComponent(i)).join("/");return qs().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:d.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?z.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):z})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},ba)}):c&&Er&&B==="view"?Is(c,Ge?z:ie,ks,Na):r.jsxs("div",{className:q("relative h-full",zt&&"overflow-hidden"),ref:vr,children:[r.jsx("div",{className:q("h-full",zt&&"invisible"),children:r.jsx(hi,{positionKey:ut,value:ie,onChange:je,readOnly:!He,vimMode:Xn==="vim",extensions:vs,className:"h-full",blockWidgets:Fa,onViewReady:t=>{Ue.current=t,Jr(i=>i+1),window.requestAnimationFrame(()=>{It(t)})},onViewDestroy:()=>{Ue.current&&(Ue.current=null),Jr(t=>t+1)},enableSearch:!0,searchOpen:ee,onSearchOpenChange:ce,highlightLines:U?{start:Math.min(U.start,U.end),end:Math.max(U.start,U.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const u=t.state.doc.lineAt(i.from).number;if(U&&!l.shiftKey&&Math.min(U.start,U.end)===u&&Math.max(U.start,U.end)===u)return Ke(null),nr(),Vt.current=!1,mt.current=null,Pt(!1),!0;if(f&&U&&!l.shiftKey){const p=Math.min(U.start,U.end,u),h=Math.max(U.start,U.end,u);return Ke({start:p,end:h}),Vt.current=!1,mt.current=null,Pt(!1),!0}if(Vt.current=!0,mt.current=u,Pt(!0),U&&l.shiftKey){const p=Math.min(U.start,u),h=Math.max(U.end,u);Ke({start:p,end:h})}else Ke({start:u,end:u});return!0},mouseover:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Vt.current||mt.current===null)return!1;const u=t.state.doc.lineAt(i.from).number,p=Math.min(mt.current,u),h=Math.max(mt.current,u);return Ke({start:p,end:h}),Pt(!0),!1},mouseup:()=>(Vt.current=!1,mt.current=null,Pt(!1),!1)}}},ut)}),zt&&r.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:r.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):r.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})})]}),Ea=!!(o&&En[o]),Bs=o?dr[o]:null,$s=r.jsxs("section",{className:q("flex min-h-0 flex-col overflow-hidden",f?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[r.jsx("div",{className:q("flex flex-col gap-2 py-2",f?"px-3":"px-2"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative flex-1 min-w-0",children:[r.jsx(F,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),r.jsx(lr,{ref:I,value:P,onChange:t=>M(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),P.trim().length>0&&r.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{M(""),I.current?.focus()},children:r.jsx(F,{name:"close",className:"size-4"})})]}),r.jsxs(Ot,{children:[r.jsx(Bt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>en("createFile",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:r.jsx(F,{name:"file-add",className:"size-4"})})})}),r.jsx($t,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),r.jsxs(Ot,{children:[r.jsx(Bt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>en("createFolder",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:r.jsx(F,{name:"folder-add",className:"size-4"})})})}),r.jsx($t,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),r.jsxs(Ot,{children:[r.jsx(Bt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(O,{variant:"ghost",size:"sm",onClick:()=>{Cr()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:r.jsx(F,{name:"refresh",className:"size-4"})})})}),r.jsx($t,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),r.jsx(vn,{outerClassName:"flex-1 min-h-0",className:q("py-2",f?"px-3":"px-2"),children:r.jsx("ul",{className:"flex flex-col",children:Ti?r.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):Pn.length>0?Pn.map(t=>{const i=c?.path===t.path;return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>{Te(t)},className:q("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Si(t.path,t.extension),r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):Bs?r.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx("span",{className:"text-[var(--status-error)]",children:Bs}),r.jsxs(O,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{Cr()},children:[r.jsx(F,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):Ea?fs(o,0):r.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Va=a==="full"&&W&&c&&r.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:r.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[r.jsx("div",{className:"absolute right-4 top-4 z-30",children:Os({exitFullscreenOnly:!0})}),r.jsx(vn,{ref:ka,outerClassName:"h-full min-w-0",className:q("h-full min-w-0",Ge&&"[overflow-anchor:none]"),children:Me||Fs?D?r.jsx("div",{className:"p-4"}):r.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Qe?r.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Qe}):Ne?r.jsx("div",{className:"flex h-full items-center justify-center p-4",children:r.jsx("img",{src:Ns,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):$e?Ss(c):st?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[r.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),r.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),n.downloadFile?r.jsxs(O,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=n.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(F,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):qe&&Le()==="preview"?r.jsxs("div",{className:"relative h-full min-h-0",children:[r.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4 outline-none",tabIndex:-1,onMouseDown:br,ref:Ta,children:[c?r.jsx(si,{containerRef:yr,filePath:c.path,fileContent:z}):null,z.length>500*1024&&r.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(z.length/1024)})}),r.jsx(xn,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:r.jsx(ti,{content:z,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),r.jsx(oi,{containerRef:yr,open:On,onOpenChange:xr,focusNonce:Bn,className:"right-4 top-16"})]}):Er&&B==="view"?Is(c,Ge?z:ie,Rs,Ca):r.jsxs("div",{className:q("relative h-full",zt&&"overflow-hidden"),children:[r.jsx("div",{className:q("h-full",zt&&"invisible"),children:r.jsx(hi,{positionKey:`${ut}:fullscreen`,value:ie,onChange:je,readOnly:!He,vimMode:Xn==="vim",extensions:vs,className:"h-full",onViewReady:t=>{Ue.current=t,window.requestAnimationFrame(()=>{It(t)})},onViewDestroy:()=>{Ue.current&&(Ue.current=null)}},`${ut}:fullscreen`)}),zt&&r.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:r.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return r.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[r.jsx(bl,{activeDialog:yt,dialogData:jt,dialogInputValue:ft,onDialogInputChange:Ln,isDialogSubmitting:$i,onDialogSubmit:na,onClose:ja,inputRef:Di}),Va,f?_?mn:$s:a==="editor-only"?r.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:mn})}):r.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[m>=700&&r.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:$s}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:mn})]})]})};function jl(a){return a+1}export{Wu as FilesView};