@vantran-se/openchamber-web 2.0.4 → 2.0.6

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 (243) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DZF8ntaq.js → CodeMirrorCommentWidgets-BlzB2e0C.js} +1 -1
  2. package/dist/assets/DiffView-D7JQzQVZ.js +4 -0
  3. package/dist/assets/FilesView-DC2gadXM.js +17 -0
  4. package/dist/assets/{GitView-DwQwqDvu.js → GitView-Gzl0wbdd.js} +4 -4
  5. package/dist/assets/{GuestAttachDialog-CoXM0gh_.js → GuestAttachDialog-CQdDIeco.js} +1 -1
  6. package/dist/assets/GuestSurfacePane-CrOhlIdt.js +1 -0
  7. package/dist/assets/{JsonTreeView-Cq_27v0y.js → JsonTreeView-C3QZifYe.js} +1 -1
  8. package/dist/assets/{LinearIssuesView-CsSSRMhn.js → LinearIssuesView-X27TCI3v.js} +1 -1
  9. package/dist/assets/MarkdownImageGallery-BlTWU9oH.js +1 -0
  10. package/dist/assets/MarkdownRendererImpl-Cno7QsJO.js +12 -0
  11. package/dist/assets/{OnboardingScreen-ClatMQAX.js → OnboardingScreen-Wr_UzNtt.js} +1 -1
  12. package/dist/assets/{PatchDiff-DOwlrIK9.js → PatchDiff-D6pWS7cD.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-CrcGqqD_.js → PierreDiffViewer-DDljFbJJ.js} +3 -3
  14. package/dist/assets/{PlanView-BGLsMgQk.js → PlanView-LcfEbBPi.js} +4 -4
  15. package/dist/assets/PluginPane-DPWPLc2f.js +3 -0
  16. package/dist/assets/SettingsView-CFe9O3EM.js +30 -0
  17. package/dist/assets/{SettingsWindow-B0BAy-f9.js → SettingsWindow-DT1xhvgi.js} +1 -1
  18. package/dist/assets/{SubmoduleDiffSummary-fcdDzCSW.js → SubmoduleDiffSummary-CBHXaIkB.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-B7xaUz2H.js → ToolOutputDialog-B_ZX8ZbZ.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-CkWCaUmZ.js → ToolPartDiffPreview-D_HQzkXU.js} +2 -2
  21. package/dist/assets/{VirtualizedFileDiff-DONC4eI2.js → VirtualizedFileDiff-BUK1ujXg.js} +1 -1
  22. package/dist/assets/{WalkthroughView-CXDImOXW.js → WalkthroughView-H-tYOvhO.js} +2 -2
  23. package/dist/assets/{appThemeRegistry-Br2TLSlb.js → appThemeRegistry-BoJGAwCP.js} +1 -1
  24. package/dist/assets/changesTree-CePHbFcj.js +1 -0
  25. package/dist/assets/commitAndPush-BzZrF8bK.js +1 -0
  26. package/dist/assets/{computeVirtualFileMetrics-_-20umCs.js → computeVirtualFileMetrics-kYyVjXLu.js} +2 -2
  27. package/dist/assets/de-ByfQDcPj.js +10 -0
  28. package/dist/assets/es-DzNbjsQS.js +16 -0
  29. package/dist/assets/fr-B8AVLrnX.js +14 -0
  30. package/dist/assets/{index-OKDYjcMF.js → index-0-ON1L7L.js} +1 -1
  31. package/dist/assets/index-DUke1nme.css +1 -0
  32. package/dist/assets/index-Di6zUe5h.js +41 -0
  33. package/dist/assets/{isDiffPlainText-D77M6q1f.js → isDiffPlainText-Bgm_aLpu.js} +1 -1
  34. package/dist/assets/{isFilePlainText-C54B4Mns.js → isFilePlainText-D5GMgURH.js} +1 -1
  35. package/dist/assets/ja-1g6S0G19.js +16 -0
  36. package/dist/assets/ko-CxplvYkJ.js +16 -0
  37. package/dist/assets/{main-CGEvLMd2.js → main--Y98ZLsD.js} +2 -2
  38. package/dist/assets/main-GjXmVNpD.js +896 -0
  39. package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
  40. package/dist/assets/markdownCore-CVdUcVCi.js +7 -0
  41. package/dist/assets/{miniChat-BSxkRQLj.js → miniChat-tTx5mpbd.js} +2 -2
  42. package/dist/assets/{mobile-C5KRTNOB.js → mobile-BmbiDWGb.js} +2 -2
  43. package/dist/assets/patchFileDiff-CV4iVQ8L.js +13 -0
  44. package/dist/assets/pl-f3QyqvIB.js +16 -0
  45. package/dist/assets/pt-BR-BsaoaiCK.js +16 -0
  46. package/dist/assets/{renderElectronMiniChatApp-CnkAQV6o.js → renderElectronMiniChatApp-BnCdnDhv.js} +2 -2
  47. package/dist/assets/renderMobileApp-CKn8nbSW.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-sCi88eed.js +27 -0
  49. package/dist/assets/scheduledTasksApi-Dahv3ws0.js +1 -0
  50. package/dist/assets/{shikiHighlight-4O0ZM14D.js → shikiHighlight-O5_xLmWt.js} +1 -1
  51. package/dist/assets/{textMateThemeFromAppTheme-yNq7b0DZ.js → textMateThemeFromAppTheme-XM4VefqN.js} +1 -1
  52. package/dist/assets/tr-BNFsa6nz.js +7 -0
  53. package/dist/assets/uk-CJ9y5ULA.js +16 -0
  54. package/dist/assets/{useAppFontEffects-Bzyszv2N.js → useAppFontEffects-BN06mgHB.js} +160 -156
  55. package/dist/assets/{useInlineCommentController-zOf6ORAq.js → useInlineCommentController-Bb9Gjz1Q.js} +2 -2
  56. package/dist/assets/{useRootScrollLock-DCaZ4BWi.js → useRootScrollLock-Chk1cFUw.js} +2 -2
  57. package/dist/assets/{vendor-codemirror-language-data-6cEFPNUR.js → vendor-codemirror-language-data-C2qMZiA7.js} +2 -2
  58. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
  59. package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
  60. package/dist/assets/{web-components-BEo4-ISu.js → web-components-BQWjCn_U.js} +1 -1
  61. package/dist/assets/zh-CN-U0QjVlAA.js +16 -0
  62. package/dist/assets/zh-TW-J9PTJQJi.js +16 -0
  63. package/dist/index.html +5 -5
  64. package/dist/mini-chat.html +5 -5
  65. package/dist/mobile.html +5 -5
  66. package/package.json +4 -4
  67. package/server/index.js +82 -0
  68. package/server/lib/agent-tool/DOCUMENTATION.md +132 -47
  69. package/server/lib/agent-tool/runtime.js +34 -15
  70. package/server/lib/agent-tool/runtime.test.js +15 -0
  71. package/server/lib/browser-control/DOCUMENTATION.md +14 -2
  72. package/server/lib/event-stream/global-hub.js +23 -1
  73. package/server/lib/event-stream/global-hub.test.js +35 -0
  74. package/server/lib/event-stream/global-ws-bridge.js +3 -1
  75. package/server/lib/event-stream/upstream-reader.js +3 -2
  76. package/server/lib/git/DOCUMENTATION.md +1 -1
  77. package/server/lib/git/service.js +22 -0
  78. package/server/lib/git/service.test.js +8 -0
  79. package/server/lib/guests/DOCUMENTATION.md +4 -3
  80. package/server/lib/guests/catalog.js +19 -1
  81. package/server/lib/guests/catalog.test.js +22 -0
  82. package/server/lib/guests/html-styles.js +5 -3
  83. package/server/lib/guests/html-styles.test.js +3 -1
  84. package/server/lib/guests/routes.js +11 -3
  85. package/server/lib/guests/service.js +5 -0
  86. package/server/lib/guests/surface.js +55 -9
  87. package/server/lib/guests/surface.test.js +56 -6
  88. package/server/lib/notifications/DOCUMENTATION.md +10 -0
  89. package/server/lib/notifications/emit-route.js +118 -0
  90. package/server/lib/notifications/emit-route.test.js +112 -0
  91. package/server/lib/openchamber-control/actions.js +16 -2
  92. package/server/lib/openchamber-control/service.js +23 -0
  93. package/server/lib/openchamber-control/service.test.js +31 -0
  94. package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
  95. package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
  96. package/server/lib/openchamber-sessions/routes.js +11 -0
  97. package/server/lib/openchamber-sessions/routes.test.js +18 -0
  98. package/server/lib/opencode/bootstrap-runtime.js +14 -1
  99. package/server/lib/opencode/compatibility.js +6 -3
  100. package/server/lib/opencode/compatibility.test.js +8 -0
  101. package/server/lib/opencode/config-entity-v2.test.js +27 -0
  102. package/server/lib/opencode/config-paths.test.js +12 -0
  103. package/server/lib/opencode/config-v2.d.ts +2 -0
  104. package/server/lib/opencode/config-v2.js +42 -0
  105. package/server/lib/opencode/config-v2.test.js +17 -0
  106. package/server/lib/opencode/core-routes.js +20 -4
  107. package/server/lib/opencode/core-routes.test.js +41 -0
  108. package/server/lib/opencode/env-runtime.js +1 -8
  109. package/server/lib/opencode/feature-routes-runtime.js +2 -1
  110. package/server/lib/opencode/lifecycle.js +30 -2
  111. package/server/lib/opencode/lifecycle.test.js +27 -0
  112. package/server/lib/opencode/managed-config-file.js +18 -6
  113. package/server/lib/opencode/managed-config-file.test.js +23 -7
  114. package/server/lib/opencode/mcp.js +7 -2
  115. package/server/lib/opencode/npm-registry-config.d.ts +1 -0
  116. package/server/lib/opencode/npm-registry-config.js +123 -0
  117. package/server/lib/opencode/npm-registry-config.test.js +167 -0
  118. package/server/lib/opencode/npm-registry.js +5 -6
  119. package/server/lib/opencode/npm-registry.test.js +30 -0
  120. package/server/lib/opencode/openchamber-routes.js +29 -11
  121. package/server/lib/opencode/openchamber-routes.test.js +18 -0
  122. package/server/lib/opencode/project-directory-runtime.js +8 -0
  123. package/server/lib/opencode/project-directory-runtime.test.js +13 -0
  124. package/server/lib/opencode/provider-source-route.test.js +59 -0
  125. package/server/lib/opencode/providers.js +3 -0
  126. package/server/lib/opencode/providers.test.js +62 -0
  127. package/server/lib/opencode/proxy.js +38 -2
  128. package/server/lib/opencode/routes-upgrade.test.js +1 -1
  129. package/server/lib/opencode/routes.js +36 -1
  130. package/server/lib/opencode/server-utils-runtime.js +5 -0
  131. package/server/lib/opencode/settings-helpers.js +10 -0
  132. package/server/lib/opencode/settings-helpers.test.js +2 -2
  133. package/server/lib/opencode/settings-registry.json +17 -0
  134. package/server/lib/opencode/settings-runtime.js +1 -0
  135. package/server/lib/opencode/shared.js +49 -4
  136. package/server/lib/opencode/shared.test.js +78 -1
  137. package/server/lib/opencode/shutdown-runtime.js +3 -0
  138. package/server/lib/opencode/skill-routes.js +28 -12
  139. package/server/lib/opencode/skill-routes.test.js +121 -1
  140. package/server/lib/opencode/upgrade-capability.js +0 -14
  141. package/server/lib/opencode/v1-migration-topup.js +21 -15
  142. package/server/lib/opencode/v1-migration-topup.test.js +14 -6
  143. package/server/lib/opencode/v2-install.d.ts +1 -0
  144. package/server/lib/opencode/v2-install.js +8 -7
  145. package/server/lib/opencode/v2-install.test.js +13 -4
  146. package/server/lib/opencode/watcher.js +3 -1
  147. package/server/lib/opencode/websearch-config.js +13 -1
  148. package/server/lib/quota/providers/kimi.js +1 -1
  149. package/server/lib/realtime-proxy.js +5 -1
  150. package/server/lib/realtime-proxy.test.js +29 -0
  151. package/server/lib/relay/tunnel-host.js +4 -1
  152. package/server/lib/relay/tunnel-host.test.js +11 -0
  153. package/server/lib/session-assist/DOCUMENTATION.md +17 -5
  154. package/server/lib/session-assist/runtime.js +19 -2
  155. package/server/lib/session-assist/runtime.test.js +8 -0
  156. package/server/lib/session-goal/DOCUMENTATION.md +11 -0
  157. package/server/lib/small-model/DOCUMENTATION.md +11 -10
  158. package/server/lib/small-model/index.js +27 -32
  159. package/server/lib/small-model/index.test.js +28 -16
  160. package/server/lib/spaces/DOCUMENTATION.md +404 -32
  161. package/server/lib/spaces/code-in-bait.js +145 -6
  162. package/server/lib/spaces/code-in.js +10 -150
  163. package/server/lib/spaces/code-in.test.js +7 -83
  164. package/server/lib/spaces/code-out.js +1819 -0
  165. package/server/lib/spaces/code-out.test.js +3945 -0
  166. package/server/lib/spaces/code-transfer.js +173 -0
  167. package/server/lib/spaces/command-stream.test.js +181 -0
  168. package/server/lib/spaces/dispatcher.js +670 -0
  169. package/server/lib/spaces/dispatcher.test.js +582 -0
  170. package/server/lib/spaces/gatekeeper-channel.js +61 -7
  171. package/server/lib/spaces/gatekeeper-channel.test.js +43 -7
  172. package/server/lib/spaces/gatekeeper-program.cjs +68 -14
  173. package/server/lib/spaces/gatekeeper-program.test.js +118 -3
  174. package/server/lib/spaces/hardening.js +20 -4
  175. package/server/lib/spaces/hardening.test.js +18 -3
  176. package/server/lib/spaces/host-git.js +7 -4
  177. package/server/lib/spaces/host-git.test.js +6 -2
  178. package/server/lib/spaces/host.js +310 -0
  179. package/server/lib/spaces/host.test.js +273 -0
  180. package/server/lib/spaces/journey.js +552 -0
  181. package/server/lib/spaces/journey.test.js +589 -0
  182. package/server/lib/spaces/layout.js +42 -8
  183. package/server/lib/spaces/manager.js +4 -3
  184. package/server/lib/spaces/manager.test.js +6 -0
  185. package/server/lib/spaces/places/code-out.docker.live.test.js +412 -0
  186. package/server/lib/spaces/places/contract-suite.js +36 -0
  187. package/server/lib/spaces/places/dispatcher.docker.live.test.js +296 -0
  188. package/server/lib/spaces/places/docker-live-support.js +27 -4
  189. package/server/lib/spaces/places/docker.js +33 -5
  190. package/server/lib/spaces/places/docker.test.js +42 -3
  191. package/server/lib/spaces/places/escape-suite.js +118 -14
  192. package/server/lib/spaces/places/fake-docker.js +3 -1
  193. package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
  194. package/server/lib/spaces/places/memory-place.js +24 -1
  195. package/server/lib/spaces/places/registry.js +1 -1
  196. package/server/lib/spaces/places/server.docker.live.test.js +69 -33
  197. package/server/lib/spaces/places/sessions.docker.live.test.js +222 -0
  198. package/server/lib/spaces/routes.js +216 -0
  199. package/server/lib/spaces/routes.test.js +213 -0
  200. package/server/lib/spaces/run-command.js +261 -8
  201. package/server/lib/spaces/run-command.test.js +193 -3
  202. package/server/lib/spaces/space-events.js +153 -0
  203. package/server/lib/spaces/space-events.test.js +160 -0
  204. package/server/lib/spaces/space-opencode.js +52 -0
  205. package/server/lib/spaces/space-opencode.test.js +41 -0
  206. package/server/lib/spaces/space-records.js +150 -0
  207. package/server/lib/spaces/space-records.test.js +113 -0
  208. package/server/lib/spaces/space-sessions.js +210 -0
  209. package/server/lib/spaces/space-sessions.test.js +161 -0
  210. package/server/lib/spaces/websocket.js +329 -0
  211. package/server/lib/spaces/websocket.test.js +345 -0
  212. package/server/lib/ui-auth/ui-auth.js +8 -2
  213. package/server/lib/ui-auth/ui-auth.test.js +29 -0
  214. package/server/opencode-proxy.test.js +113 -0
  215. package/dist/assets/DiffView-D2p4Ar0H.js +0 -4
  216. package/dist/assets/FilesView-BeTtbsip.js +0 -17
  217. package/dist/assets/GuestSurfacePane-DIJvkkM-.js +0 -1
  218. package/dist/assets/MarkdownImageGallery-CY0dWTaE.js +0 -1
  219. package/dist/assets/MarkdownRendererImpl-ILdXzLrt.js +0 -12
  220. package/dist/assets/PluginPane-B39JEUL8.js +0 -3
  221. package/dist/assets/SettingsView-13B2_G-A.js +0 -29
  222. package/dist/assets/commitAndPush-CcI4ol7c.js +0 -1
  223. package/dist/assets/de-BtYnUgII.js +0 -10
  224. package/dist/assets/es-crP5qPye.js +0 -16
  225. package/dist/assets/fr-CLSRuALk.js +0 -14
  226. package/dist/assets/index-CLcM8HKx.css +0 -1
  227. package/dist/assets/index-CvLgnuNI.js +0 -41
  228. package/dist/assets/ja-SZ1-ucLV.js +0 -16
  229. package/dist/assets/ko-HthbT_Ve.js +0 -16
  230. package/dist/assets/main-BJklC7Cl.js +0 -896
  231. package/dist/assets/markdownCore-BzQuETm0.js +0 -5
  232. package/dist/assets/patchFileDiff-DGw2KryM.js +0 -13
  233. package/dist/assets/pl-C8eYfjL1.js +0 -16
  234. package/dist/assets/pt-BR-cYOrZdxS.js +0 -16
  235. package/dist/assets/renderMobileApp-CMxjwisj.js +0 -25
  236. package/dist/assets/runtimeEndpointReset-C45jrFq4.js +0 -27
  237. package/dist/assets/scheduledTasksApi-CkK1F9s2.js +0 -1
  238. package/dist/assets/tr-B4IQ5t-T.js +0 -7
  239. package/dist/assets/uk-DCoXG6ve.js +0 -16
  240. package/dist/assets/vendor-opencode-client-_BAHQo4R.js +0 -12
  241. package/dist/assets/vendor-zod-Gea9uBlY.js +0 -39
  242. package/dist/assets/zh-CN-BXBoxsFk.js +0 -16
  243. package/dist/assets/zh-TW-C6oelpnL.js +0 -16
@@ -1 +1 @@
1
- import{j as a}from"./vendor-react-BUCujlKS.js";import{I as l,a as I}from"./useInlineCommentController-zOf6ORAq.js";function E(g){const{drafts:x,editingDraftId:d,commentText:o,onTextChange:r,selection:n,isDragging:u,fileLabel:s,newWidgetId:f,mapDraftToRange:p,onSave:m,onCancel:c,onEdit:C,onDelete:h}=g,t=[];for(const e of x){const i=p(e);if(e.id===d){t.push({afterLine:i.end,id:`edit-${e.id}`,content:a.jsx(l,{initialText:o,onTextChange:r,fileLabel:s,lineRange:i,isEditing:!0,onSave:m,onCancel:c},`edit-${e.id}`)});continue}t.push({afterLine:i.end,id:`card-${e.id}`,content:a.jsx(I,{draft:e,onEdit:()=>C(e),onDelete:()=>h(e)},`card-${e.id}`)})}if(n&&!d&&!u){const e={...n,start:Math.min(n.start,n.end),end:Math.max(n.start,n.end)};t.push({afterLine:e.end,id:f,content:a.jsx(l,{initialText:o,onTextChange:r,fileLabel:s,lineRange:e,isEditing:!1,onSave:m,onCancel:c},f)})}return t}export{E as b};
1
+ import{j as a}from"./vendor-react-BUCujlKS.js";import{I as l,a as I}from"./useInlineCommentController-Bb9Gjz1Q.js";function E(g){const{drafts:x,editingDraftId:d,commentText:o,onTextChange:r,selection:n,isDragging:u,fileLabel:s,newWidgetId:f,mapDraftToRange:p,onSave:m,onCancel:c,onEdit:C,onDelete:h}=g,t=[];for(const e of x){const i=p(e);if(e.id===d){t.push({afterLine:i.end,id:`edit-${e.id}`,content:a.jsx(l,{initialText:o,onTextChange:r,fileLabel:s,lineRange:i,isEditing:!0,onSave:m,onCancel:c},`edit-${e.id}`)});continue}t.push({afterLine:i.end,id:`card-${e.id}`,content:a.jsx(I,{draft:e,onEdit:()=>C(e),onDelete:()=>h(e)},`card-${e.id}`)})}if(n&&!d&&!u){const e={...n,start:Math.min(n.start,n.end),end:Math.max(n.start,n.end)};t.push({afterLine:e.end,id:f,content:a.jsx(l,{initialText:o,onTextChange:r,fileLabel:s,lineRange:e,isEditing:!1,onSave:m,onCancel:c},f)})}return t}export{E as b};
@@ -0,0 +1,4 @@
1
+ import{R as r,f as Qe,j as n}from"./vendor-react-BUCujlKS.js";import{u as Q,P as Fe,C as Zn,a as Re,G as es}from"./index-Di6zUe5h.js";import{c as ts,b as ns,u as ss,a as rs,B as is,C as os,P as on,h as as,e as ls,g as cs,i as us,f as ds}from"./patchFileDiff-CV4iVQ8L.js";import{c as fs,b as ms,i as ps,u as hs,a as gs,d as xs,S as ys}from"./SubmoduleDiffSummary-CBHXaIkB.js";import{f as ze,B as je,I as O,h as le,_ as xn,ai as ws,K as ae,aj as bs,bj as vs,J as js,ak as ks,am as Ss,z as an,k as Ns,da as yn,t as Ye,l7 as Cs,az as lt,kY as wn,l8 as Fs,aA as _t,gZ as Rs,ax as at,ay as Ds,c8 as zt,at as As,av as Es,aw as Ts,as as Ls}from"./useAppFontEffects-BN06mgHB.js";import{j as Vs,f as Ms}from"./runtimeEndpointReset-sCi88eed.js";import{P as Bs}from"./PierreDiffViewer-DDljFbJJ.js";import{u as Is,v as Ps,g as _s,W as zs}from"./main-GjXmVNpD.js";import{b as Os,c as Ks}from"./changesTree-CePHbFcj.js";import{p as $s}from"./VirtualizedFileDiff-BUK1ujXg.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-BSoePkpP.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-opencode-client-DSZl7jSi.js";import"./PluginPane-DPWPLc2f.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-CsXYnR5c.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-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-tanstack-react-virtual-ClYN8CzB.js";import"./vendor-tanstack-virtual-core-BewVQryB.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./contextPanelEmbeddedChat-CirXEPJq.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-C2qMZiA7.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./GuestAttachDialog-CQdDIeco.js";import"./web-components-BQWjCn_U.js";import"./computeVirtualFileMetrics-kYyVjXLu.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"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-Bb9Gjz1Q.js";import"./appThemeRegistry-BoJGAwCP.js";import"./textMateThemeFromAppTheme-XM4VefqN.js";import"./vendor-katex-CHD9BdDO.js";import"./useRootScrollLock-Chk1cFUw.js";import"./scheduledTasksApi-Dahv3ws0.js";import"./vendor-cron-parser-CjvYVigk.js";import"./vendor-luxon-BZ0puJYg.js";import"./isDiffPlainText-Bgm_aLpu.js";import"./vendor-diff-C3JhlQdm.js";const Gs=r.memo(function(e){const s=Qe.c(13),{index:u,staged:g,busyHunk:m,disabled:w,onAction:k}=e,{t:v}=ze();let a;s[0]!==g?(a=g?["unstage"]:["discard","stage"],s[0]=g,s[1]=a):a=s[1];const j=a;let N;s[2]===Symbol.for("react.memo_cache_sentinel")?(N={top:"var(--oc-hunk-action-offset, 0.25rem)"},s[2]=N):N=s[2];let p;s[3]!==j||s[4]!==m||s[5]!==w||s[6]!==u||s[7]!==k||s[8]!==v?(p=n.jsx("div",{className:"pointer-events-auto flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-sm backdrop-blur-md",children:j.map(b=>{const C=v(b==="stage"?"diffView.hunk.stageTitle":b==="unstage"?"diffView.hunk.unstageTitle":"diffView.hunk.discardTitle",{index:u+1}),V=m?.index===u&&m.action===b;return n.jsx(je,{variant:"ghost",size:"xs",className:le("rounded-full bg-transparent text-muted-foreground hover:bg-transparent hover:text-foreground",b==="discard"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",b==="stage"&&"text-[var(--status-success)] hover:text-[var(--status-success)]"),disabled:w||m!==null,title:C,"aria-label":C,onPointerDown:Ws,onClick:f=>{f.stopPropagation(),k(u,b)},children:n.jsx(O,{name:V?"loader-4":b==="stage"?"add":"arrow-go-back",className:le(b==="stage"?"size-4":"size-3.5",V&&"animate-spin")})},b)})}),s[3]=j,s[4]=m,s[5]=w,s[6]=u,s[7]=k,s[8]=v,s[9]=p):p=s[9];let E;return s[10]!==u||s[11]!==p?(E=n.jsx("div",{className:"pointer-events-none absolute right-3 z-20",style:N,"data-hunk-actions":u,children:p}),s[10]=u,s[11]=p,s[12]=E):E=s[12],E});function Ws(o){return o.stopPropagation()}const ln=(o,e)=>{if(e.length===0)return null;let s=null,u=null;for(const m of e)m.top<=o?(!s||m.top>s.top)&&(s=m):(!u||m.top<u.top)&&(u=m);const g=s??u;return g?{path:g.path,topOffset:g.top-o}:null},Hs=(o,e,s,u)=>Math.min(Math.max(0,u),Math.max(0,o+s-e)),Mt=o=>o.slice(o.lastIndexOf("/")+1),bn=(o,e)=>{const s=[],u=(g,m)=>{const w=Array.from(g.children.values()).sort((v,a)=>v.name.localeCompare(a.name));for(const v of w){const{node:a,label:j}=Ks(v),N=!e.has(a.path);s.push({kind:"directory",key:`dir:${a.path}`,depth:m,path:a.path,label:j,fileCount:a.files.length,expanded:N}),N&&u(a,m+1)}const k=[...g.directFiles].sort((v,a)=>Mt(v.path).localeCompare(Mt(a.path)));for(const v of k)s.push({kind:"file",key:`file:${v.path}`,depth:m,name:Mt(v.path),file:v})};return u(Os(o),0),s},cn=o=>{if(!o)return null;const e=o.split(`
2
+ `);let s=null;for(const u of e){const g=u.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(g){const m=Number.parseInt(g[1]??"",10);s=Number.isFinite(m)&&m>=1?m:null;continue}if(s!==null){if(u.startsWith(" ")){s+=1;continue}if(u.startsWith("+"))return s;if(u.startsWith("-"))return Math.max(1,s)}}return null},qs=1100,Us=15e3,un=500,dn=300,vn=1e6,It=3,Xs=o=>o<=6?o:o<=12?6:o<=25?4:2,fn={status:"loading"},Js=3,Ys=r.memo(()=>{const o=Qe.c(4),{t:e}=ze();let s;o[0]!==e?(s=e("diffView.binary.unavailable"),o[0]=e,o[1]=s):s=o[1];let u;return o[2]!==s?(u=n.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:n.jsx("div",{className:"typography-meta text-muted-foreground",children:s})}),o[2]=s,o[3]=u):u=o[3],u}),jn={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},Qs=jn.M,Zs=o=>{const e=o.index?.trim(),s=o.working_dir?.trim();return e&&e!=="?"?e.charAt(0):s?s.charAt(0):e?.charAt(0)||s?.charAt(0)||"M"},Ot=o=>{const e=Zs(o);return jn[e]??Qs},er=o=>{const{index:e,working_dir:s}=o;return e==="A"||s==="A"||e==="?"||s==="?"},mn=o=>{const e=o.index?.trim();return!!(e&&e!=="?")},pn=o=>!!o.working_dir?.trim()||o.index==="?",tr=(o,e)=>Rs(o,e),hn=o=>(o||"").replace(/\\/g,"/").replace(/\/+$/,""),gn=(o,e)=>{const s=o.split(`
3
+ `),u=e.split(`
4
+ `),g=Math.min(s.length,u.length);for(let m=0;m<g;m+=1)if(s[m]!==u[m])return m+1;return u.length>s.length?s.length+1:s.length>u.length?Math.max(1,u.length):1},nr=o=>o==="added"?"A":o==="deleted"?"D":"M",Pt=(o,e,s)=>us(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:s}:{original:"",modified:"",patch:e,fileDiff:ds(o,e),contextMode:s},kn=(o,e,s)=>{const u=o??0,g=e??0;return!u&&!g?null:n.jsxs("span",{className:le("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",s?.className),children:[u?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",u]}):null,g?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",g]}):null]})},sr=r.memo(o=>{const e=Qe.c(68),{scope:s,workingCount:u,stagedCount:g,turnCount:m,branchCount:w,commitCount:k,prCount:v,showCommitOption:a,showBranchOption:j,onScopeChange:N}=o,{t:p}=ze(),[E,b]=r.useState(!1),C=s==="pr"?v??0:s==="staged"?g:s==="turn"?m:s==="branch"?w??0:s==="commit"?k??0:u;let V;e[0]!==s||e[1]!==p?(V=p(s==="pr"?"session.githubIntegration.tabs.pullRequests":s==="staged"?"diffView.scope.staged":s==="turn"?"diffView.scope.lastTurn":s==="branch"?"diffView.scope.branch":s==="commit"?"commitComparison.mode":"diffView.scope.changed"),e[0]=s,e[1]=p,e[2]=V):V=e[2];const f=V;let S;e[3]!==p?(S=p("diffView.scope.selectorAria"),e[3]=p,e[4]=S):S=e[4];let M;e[5]!==C?(M=n.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",C]}),e[5]=C,e[6]=M):M=e[6];let I;e[7]!==f||e[8]!==M?(I=n.jsxs("span",{className:"whitespace-nowrap",children:[f,M]}),e[7]=f,e[8]=M,e[9]=I):I=e[9];let ce;e[10]===Symbol.for("react.memo_cache_sentinel")?(ce=n.jsx(O,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=ce):ce=e[10];let U;e[11]!==S||e[12]!==I?(U=n.jsx(As,{asChild:!0,children:n.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":S,children:[I,ce]})}),e[11]=S,e[12]=I,e[13]=U):U=e[13];let y;e[14]!==N?(y=H=>{(H==="working"||H==="staged"||H==="turn"||H==="branch"||H==="commit"||H==="pr")&&(N?.(H),b(!1))},e[14]=N,e[15]=y):y=e[15];let K;e[16]!==p?(K=p("diffView.scope.changed"),e[16]=p,e[17]=K):K=e[17];let X;e[18]!==K?(X=n.jsx("span",{children:K}),e[18]=K,e[19]=X):X=e[19];let ue;e[20]!==u?(ue=n.jsx("span",{className:"typography-meta text-muted-foreground",children:u}),e[20]=u,e[21]=ue):ue=e[21];let se;e[22]!==ue||e[23]!==X?(se=n.jsx(at,{value:"working",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[X,ue]})}),e[22]=ue,e[23]=X,e[24]=se):se=e[24];let xe;e[25]!==p?(xe=p("diffView.scope.staged"),e[25]=p,e[26]=xe):xe=e[26];let re;e[27]!==xe?(re=n.jsx("span",{children:xe}),e[27]=xe,e[28]=re):re=e[28];let ye;e[29]!==g?(ye=n.jsx("span",{className:"typography-meta text-muted-foreground",children:g}),e[29]=g,e[30]=ye):ye=e[30];let ee;e[31]!==re||e[32]!==ye?(ee=n.jsx(at,{value:"staged",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[re,ye]})}),e[31]=re,e[32]=ye,e[33]=ee):ee=e[33];let _;e[34]!==p?(_=p("diffView.scope.lastTurn"),e[34]=p,e[35]=_):_=e[35];let te;e[36]!==_?(te=n.jsx("span",{children:_}),e[36]=_,e[37]=te):te=e[37];let ne;e[38]!==m?(ne=n.jsx("span",{className:"typography-meta text-muted-foreground",children:m}),e[38]=m,e[39]=ne):ne=e[39];let $;e[40]!==te||e[41]!==ne?($=n.jsx(at,{value:"turn",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[te,ne]})}),e[40]=te,e[41]=ne,e[42]=$):$=e[42];let ke;e[43]!==w||e[44]!==j||e[45]!==p?(ke=j?n.jsx(at,{value:"branch",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[n.jsx("span",{children:p("diffView.scope.branch")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:w??"…"})]})}):null,e[43]=w,e[44]=j,e[45]=p,e[46]=ke):ke=e[46];let T;e[47]!==k||e[48]!==a||e[49]!==p?(T=a&&n.jsx(at,{value:"commit",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[n.jsx("span",{children:p("commitComparison.mode")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:k??"…"})]})}),e[47]=k,e[48]=a,e[49]=p,e[50]=T):T=e[50];let W;e[51]!==v||e[52]!==a||e[53]!==p?(W=a&&n.jsx(at,{value:"pr",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[n.jsx("span",{children:p("session.githubIntegration.tabs.pullRequests")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:v??"…"})]})}),e[51]=v,e[52]=a,e[53]=p,e[54]=W):W=e[54];let A;e[55]!==s||e[56]!==se||e[57]!==ee||e[58]!==$||e[59]!==ke||e[60]!==T||e[61]!==W||e[62]!==y?(A=n.jsx(Es,{align:"start",className:"w-40",children:n.jsxs(Ts,{value:s,onValueChange:y,children:[se,ee,$,ke,T,W]})}),e[55]=s,e[56]=se,e[57]=ee,e[58]=$,e[59]=ke,e[60]=T,e[61]=W,e[62]=y,e[63]=A):A=e[63];let de;return e[64]!==E||e[65]!==A||e[66]!==U?(de=n.jsxs(Ls,{open:E,onOpenChange:b,children:[U,A]}),e[64]=E,e[65]=A,e[66]=U,e[67]=de):de=e[67],de}),rr=r.memo(o=>{const e=Qe.c(11),{changedFiles:s,selectedFile:u,onSelectFile:g}=o,{t:m}=ze();if(s.length===0)return null;let w;if(e[0]!==s||e[1]!==g||e[2]!==u||e[3]!==m){let v;e[5]!==g||e[6]!==u||e[7]!==m?(v=a=>{const j=Ot(a),N=u===a.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>g(a.path),className:le("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",N?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(_t,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),n.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:j.color},title:m(j.descriptionKey),"aria-label":m(j.descriptionKey),children:j.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:a.path,children:a.path}),kn(a.insertions,a.deletions)]})},a.path)},e[5]=g,e[6]=u,e[7]=m,e[8]=v):v=e[8],w=s.map(v),e[0]=s,e[1]=g,e[2]=u,e[3]=m,e[4]=w}else w=e[4];let k;return e[9]!==w?(k=n.jsx(zt,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:w})}),e[9]=w,e[10]=k):k=e[10],k}),Sn=12,Nn=8,Bt=160,ir=.5,or=r.memo(o=>{const e=Qe.c(18),{changedFiles:s,selectedFile:u,onSelectFile:g}=o,{t:m}=ze(),[w,k]=r.useState(ur);let v;e[0]!==s||e[1]!==w?(v=bn(s,w),e[0]=s,e[1]=w,e[2]=v):v=e[2];const a=v;let j,N;e[3]!==u?(j=()=>{u&&k(f=>{const S=Array.from(f).filter(I=>u.startsWith(`${I}/`));if(S.length===0)return f;const M=new Set(f);return S.forEach(I=>M.delete(I)),M})},N=[u],e[3]=u,e[4]=j,e[5]=N):(j=e[4],N=e[5]),r.useEffect(j,N);let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=f=>{k(S=>{const M=new Set(S);return M.delete(f)||M.add(f),M})},e[6]=p):p=e[6];const E=p,b=fr;let C;if(e[7]!==g||e[8]!==a||e[9]!==u||e[10]!==m){let f;e[12]!==g||e[13]!==u||e[14]!==m?(f=S=>{const M=`${Nn+S.depth*Sn}px`;if(S.kind==="directory")return n.jsxs("li",{className:"relative",children:[b(S.depth),n.jsxs("button",{type:"button",onClick:()=>E(S.path),"aria-expanded":S.expanded,"aria-label":S.expanded?m("diffView.fileTree.collapseDirectoryAria",{path:S.path}):m("diffView.fileTree.expandDirectoryAria",{path:S.path}),className:"flex w-full items-center gap-1 rounded-md py-1 pr-2 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground",style:{paddingLeft:M},title:S.path,children:[n.jsx(O,{name:"arrow-right-s",className:le("size-3.5 flex-shrink-0 transition-transform",S.expanded&&"rotate-90")}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:S.label})]})]},S.key);const I=Ot(S.file),ce=u===S.file.path;return n.jsxs("li",{className:"relative",children:[b(S.depth),n.jsxs("button",{type:"button",onClick:()=>g(S.file.path),"aria-current":ce?"true":void 0,className:le("flex w-full items-center gap-1.5 rounded-md py-1 pr-2 text-left transition-colors",ce?"bg-interactive-selection text-interactive-selection-foreground":"text-foreground/90 hover:bg-interactive-hover hover:text-foreground"),style:{paddingLeft:M},title:S.file.path,children:[n.jsx(_t,{filePath:S.file.path,className:"ml-0.5 size-3.5 flex-shrink-0"}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:S.name}),n.jsx("span",{className:"typography-micro font-semibold w-3 text-center uppercase",style:{color:I.color},title:m(I.descriptionKey),"aria-label":m(I.descriptionKey),children:I.code})]})]},S.key)},e[12]=g,e[13]=u,e[14]=m,e[15]=f):f=e[15],C=a.map(f),e[7]=g,e[8]=a,e[9]=u,e[10]=m,e[11]=C}else C=e[11];let V;return e[16]!==C?(V=n.jsx(zt,{outerClassName:"flex-1 min-h-0",className:"px-1.5 py-1.5",children:n.jsx("ul",{className:"flex flex-col",children:C})}),e[16]=C,e[17]=V):V=e[17],V}),ar=r.memo(o=>{const e=Qe.c(20),{filePath:s,diff:u,renderSideBySide:g}=o,{t:m}=ze(),w=u.original.length>0,k=u.modified.length>0,v=g?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",a=g?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j={contain:"layout"},e[0]=j):j=e[0];let N;e[1]!==u.original||e[2]!==s||e[3]!==w||e[4]!==a||e[5]!==g||e[6]!==m?(N=w&&n.jsxs("div",{className:a,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:m("diffView.image.original")}),n.jsx("img",{src:u.original,alt:m("diffView.image.originalAlt",{path:s}),className:g?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=u.original,e[2]=s,e[3]=w,e[4]=a,e[5]=g,e[6]=m,e[7]=N):N=e[7];let p;e[8]!==u.modified||e[9]!==s||e[10]!==k||e[11]!==w||e[12]!==a||e[13]!==g||e[14]!==m?(p=k&&n.jsxs("div",{className:a,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:m(w?"diffView.image.modified":"diffView.image.new")}),n.jsx("img",{src:u.modified,alt:m("diffView.image.modifiedAlt",{path:s}),className:g?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=u.modified,e[9]=s,e[10]=k,e[11]=w,e[12]=a,e[13]=g,e[14]=m,e[15]=p):p=e[15];let E;return e[16]!==v||e[17]!==N||e[18]!==p?(E=n.jsx("div",{className:"w-full overflow-auto p-4",style:j,children:n.jsxs("div",{className:v,children:[N,p]})}),e[16]=v,e[17]=N,e[18]=p,e[19]=E):E=e[19],E}),lr=r.memo(o=>{const e=Qe.c(23),{filePath:s,diff:u,staged:g,renderSideBySide:m,wrapLines:w,hunkActions:k,onExpandContextRequest:v,pendingContextExpansion:a,contextLoading:j}=o;let N;e[0]!==s?(N=Ds(s)||"text",e[0]=s,e[1]=N):N=e[1];const p=N;if(u.submodule){let C;return e[2]!==u.submodule||e[3]!==g?(C=n.jsx(ys,{state:u.submodule,staged:g}),e[2]=u.submodule,e[3]=g,e[4]=C):C=e[4],C}if(u.isBinary){let C;return e[5]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(Ys,{}),e[5]=C):C=e[5],C}if(lt(s)){let C;return e[6]!==u||e[7]!==s||e[8]!==m?(C=n.jsx(ar,{filePath:s,diff:u,renderSideBySide:m}),e[6]=u,e[7]=s,e[8]=m,e[9]=C):C=e[9],C}let E;e[10]===Symbol.for("react.memo_cache_sentinel")?(E={contain:"layout"},e[10]=E):E=e[10];let b;return e[11]!==j||e[12]!==u.fileDiff||e[13]!==u.modified||e[14]!==u.original||e[15]!==s||e[16]!==k||e[17]!==p||e[18]!==v||e[19]!==a||e[20]!==m||e[21]!==w?(b=n.jsx("div",{className:"w-full",style:E,children:n.jsx(Bs,{original:u.original,modified:u.modified,fileDiff:u.fileDiff,language:p,fileName:s,renderSideBySide:m,wrapLines:w,layout:"inline",hunkActions:k,onExpandContextRequest:v,pendingContextExpansion:a,contextLoading:j})}),e[11]=j,e[12]=u.fileDiff,e[13]=u.modified,e[14]=u.original,e[15]=s,e[16]=k,e[17]=p,e[18]=v,e[19]=a,e[20]=m,e[21]=w,e[22]=b):b=e[22],b}),cr=r.memo(({visible:o=!0,directory:e,file:s,layout:u,wrapLines:g,isSelected:m,isExpanded:w,isMounted:k,onSelect:v,onExpandedChange:a,registerSectionRef:j,showOpenInEditorAction:N=!1,isOpeningInEditor:p=!1,onOpenInEditor:E,staged:b=!1,loadFullFiles:C=!1,initialDiffData:V=null,comparisonDiff:f,onRetryComparisonDiff:S,loadFullComparisonDiff:M,readOnlyActions:I=!1,hunkActionsEnabled:ce=!1,contentRevision:U=0})=>{const{t:y}=ze(),{git:K}=xn(),X=ae(r.useCallback(x=>x.directories.get(e)?.diffCache.get(s.path)??null,[e,s.path])),ue=ae(x=>x.setDiff),se=ae(x=>x.fetchStatus),xe=Q(x=>x.setDiffFileLayout),[re,ye]=r.useState(0),[ee,_]=r.useState(null),[te,ne]=r.useState(!1),[$,ke]=r.useState(null),T=$!==null&&$.source===f?$.result:f,W=!!e&&!V&&(!f||!!M),A=r.useMemo(()=>T?T.status==="error"?{kind:"error",message:T.message}:null:ee,[T,ee]),de=T?T.status==="loading":te,[H,xt]=r.useState(null),Oe=r.useRef(!1),[Ke,ct]=r.useState(null),[yt,Ft]=r.useState(!1),[ut,$e]=r.useState(null),[Ze,Ge]=r.useState(null),[c,De]=r.useState(null),ie=C||c!==null;r.useEffect(()=>{if(!c||!M||!f||f.status!=="ready"||$?.source===f)return;let x=!1;return M(s.path).then(z=>{if(!x){if(z.status==="error"){Ye.error(z.message),De(null);return}ke({source:f,result:z})}}),()=>{x=!0}},[c,s.path,$,M,f]);const we=r.useRef(null),Ae=r.useRef(null),We=r.useMemo(()=>Ot(s),[s]),et=u==="side-by-side",He=ie?"full":"patch",Se=`${s.index}:${s.working_dir}:${s.insertions}:${s.deletions}`,fe=ce&&!I&&!V&&!T&&!lt(s.path),tt=JSON.stringify([Re(),e,s.path,b,Se,re,U]),G=Ke?.scope===tt?Ke.patch:null,wt=Ke?.scope===tt?Ke.submodule:null,me=r.useMemo(()=>T?T.status==="ready"?T.data:null:V||(b?Ze:ut||(X?{original:X.original,modified:X.modified,isBinary:X.isBinary,submodule:X.submodule,contextMode:"full"}:null)),[T,X,V,ut,b,Ze]),pe=me?.contextMode===He,dt=r.useCallback(x=>{Ae.current=x,j(s.path,x)},[s.path,j]),nt=r.useCallback(x=>{a(s.path,x)},[s.path,a]),st=r.useCallback(()=>{v(s.path)},[s.path,v]),qe=r.useRef({fileStatusKey:Se,staged:b});r.useEffect(()=>{if(!o)return;const x=qe.current;x.fileStatusKey===Se&&x.staged===b||(qe.current={fileStatusKey:Se,staged:b},b?Ge(null):$e(null),_(null),we.current=null)},[Se,b,o]);const[Ue,Rt]=r.useState(U),rt=Ue===U;r.useEffect(()=>{rt||(_(null),we.current=null)},[rt]),r.useEffect(()=>{if(!o||!w||!k||ee)return;if(!e||T||V||me&&pe&&rt&&(!fe||G!==null)){we.current=null,ne(!1);return}const x=`${e}::${s.path}::${b?"staged":"unstaged"}::${Se}::${He}::${re}::${U}`;if(we.current===x)return;we.current=x,_(null),ne(!0);let z=!1;const he=Re(),Le=ie?vn:It,Z=lt(s.path)?K.getGitFileDiff(e,{path:s.path,staged:b}):!ie&&G!==null?Promise.resolve({diff:G,submodule:wt}):K.getGitDiff(e,{path:s.path,staged:b,contextLines:Le}),Ve=fe&&ie&&G===null?K.getGitDiff(e,{path:s.path,staged:b,contextLines:It}).then(L=>L.diff):Promise.resolve(G),Ne=Promise.all([Z,Ve]),Me=Us;let it;const Dt=new Promise((L,ft)=>{it=setTimeout(()=>ft(new Error(`Timed out after ${Me}ms`)),Me)});return Promise.race([Ne,Dt]).then(([L,ft])=>{if(z||he!==Re())return;const Be="diff"in L&&!ie?L.diff:ft;if(fe&&ie&&Be!==null&&/^@@\s/m.test(Be)&&"diff"in L&&L.diff!==Be&&!as(L.diff,Be))throw ct(null),new Error(y("diffView.hunk.unavailable"));if(fe&&Be!==null&&ct({scope:tt,patch:Be,submodule:L.submodule}),"diff"in L){const Xe={...Pt(s.path,L.diff,He),submodule:L.submodule};b?Ge(Xe):$e(Xe)}else{const Xe={original:L.original??"",modified:L.modified??"",isBinary:L.isBinary,submodule:L.submodule,contextMode:"full"};b?Ge(Xe):ue(e,s.path,Xe,he)}Rt(U),ne(!1)}).catch(L=>{if(!(z||he!==Re())){if(ne(!1),L instanceof es){_({kind:"unavailable",reason:L.reason}),L.reason==="path_not_found"&&se(e,K,{force:!0,silent:!0});return}_({kind:"error",message:L instanceof Error?L.message:String(L)})}}).finally(()=>clearTimeout(it)),()=>{z=!0,clearTimeout(it),we.current===x&&(we.current=null)}},[G,wt,U,fe,rt,tt,T,He,me,pe,re,e,se,s.path,Se,K,V,w,k,ie,ee,ue,b,y,o]);const bt=r.useCallback(()=>{nt(!w),st()},[nt,st,w]),oe=r.useCallback(()=>{_(null),ct(null),$e(null),Ge(null),we.current=null,ye(x=>x+1)},[]),Ee=r.useCallback(async(x,z)=>{if(!e||!fe||de||A||Oe.current||H!==null)return;const he=G?ls(G,x):null;if(!he){Ye.error(y("diffView.hunk.unavailable"));return}if(b&&z!=="unstage"||!b&&z==="unstage")return;Oe.current=!0;const Le=Re();xt({index:x,action:z});try{const Z=z==="stage"?K.stageGitHunk:z==="unstage"?K.unstageGitHunk:K.revertGitHunk;if(!Z){Ye.error(y("diffView.hunk.unsupported"));return}if(await Z(e,s.path,he),Le!==Re())return;oe(),yn.requestGitRefresh({directory:e,paths:[s.path]}),await se(e,K)}catch(Z){if(Le!==Re())return;oe(),Ye.error(Z instanceof Error&&Z.message?Z.message:y("diffView.hunk.unavailable"))}finally{Oe.current=!1,xt(Z=>Z?.index===x&&Z.action===z?null:Z)}},[G,fe,de,A,e,se,s.path,K,H,oe,b,y]),be=r.useMemo(()=>fe&&G!==null?cs(G):[],[G,fe]),q=r.useCallback(x=>n.jsx(Gs,{index:x,staged:b,busyHunk:H,disabled:de||!!A,onAction:Ee}),[A,Ee,H,de,b]),Te=r.useMemo(()=>be.length>0?{anchors:be,render:q}:void 0,[be,q]);return n.jsxs("div",{ref:dt,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[n.jsx("div",{className:"sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:n.jsxs("div",{role:"button",tabIndex:0,onClick:bt,onKeyDown:x=>{x.target===x.currentTarget&&(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),bt())},className:le("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",m?"bg-[var(--interactive-selection)]/35":null),children:[n.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),n.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[n.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:w?n.jsx(O,{name:"arrow-down-s",className:"size-4"}):n.jsx(O,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:We.color},title:y(We.descriptionKey),"aria-label":y(We.descriptionKey),children:We.code}),n.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:s.path,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(_t,{filePath:s.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const x=s.path.lastIndexOf("/");if(x===-1)return n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:s.path});const z=s.path.slice(0,x),he=s.path.slice(x+1);return n.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[n.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:z}),n.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[n.jsx("span",{className:"text-muted-foreground",children:"/"}),n.jsx("span",{className:"text-foreground",children:he})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[kn(s.insertions,s.deletions),N&&E?n.jsx(je,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:y("diffView.actions.openFileInEditorAtChange"),onClick:x=>{x.stopPropagation(),E(s.path,me)},disabled:p,children:p?n.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(O,{name:"edit",className:"size-3.5"})}):null,n.jsx(wn,{mode:et?"side-by-side":"unified",onModeChange:x=>{const z=x==="side-by-side"?"side-by-side":"inline";xe(s.path,z)},className:"opacity-70"})]})]})}),w&&n.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!k&&!A?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,A?.kind==="unavailable"?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:A.reason==="nested_repository"?y("diffView.unavailable.nestedRepositoryTitle"):A.reason==="untracked_directory"?y("diffView.unavailable.untrackedDirectoryTitle"):y("diffView.unavailable.missingTitle")}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:A.reason==="nested_repository"?y("diffView.unavailable.nestedRepositoryDescription"):A.reason==="untracked_directory"?y("diffView.unavailable.untrackedDirectoryDescription"):y("diffView.unavailable.missingDescription")}),A.reason==="path_not_found"?n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:oe,children:y("diffView.actions.retry")}):null]}):null,A?.kind==="error"?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:y("diffView.state.failedToLoadDiff")}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:A.message}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>T?S?.():oe(),children:y("diffView.actions.retry")})]}):null,k&&de&&!me&&!A?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(O,{name:"loader-4",className:"size-4 animate-spin"}),y("diffView.state.loadingDiff")]}):null,k&&me&&!yt&&s.insertions+s.deletions>un?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:y("diffView.state.largeDiff",{count:s.insertions+s.deletions})}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:y("diffView.state.largeDiffDescription")}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>Ft(!0),children:y("diffView.actions.renderAnyway")})]}):null,k&&me&&(yt||s.insertions+s.deletions<=un)?n.jsx(n.Fragment,{children:n.jsx(lr,{filePath:s.path,diff:me,staged:b,renderSideBySide:et,wrapLines:g,hunkActions:Te,onExpandContextRequest:W?De:void 0,pendingContextExpansion:c,contextLoading:c!==null&&me.contextMode!=="full"&&!A})}):null]})]})}),Vo=({visible:o=!0,hideStackedFileSidebar:e=!1,stackedDefaultCollapsedAll:s=!1,pinSelectedFileHeaderToTopOnNavigate:u=!1,showOpenInEditorAction:g=!1,diffScope:m="all",onDiffScopeChange:w,targetFilePath:k=null,flushContent:v=!1})=>{const{t:a}=ze(),{git:j,files:N}=xn(),p=ws(),E=ae(t=>t.runtimeKey),{rootIsGitRepo:b,gitDirectory:C,nestedRepos:V}=bs(p??null,{enabled:o}),f=C??p,S=Q(t=>t.openContextSurface),M=Is(t=>t.requestSource),{screenWidth:I,isMobile:ce}=vs(),U=js(f??null),y=ks(f??null),K=Ss(f??null),X=ae(t=>t.setActiveDirectory),ue=ae(t=>t.ensureStatus),se=ae(t=>t.selectNestedRepo),xe=ae(t=>t.fetchStatus),re=ae(t=>t.fetchBranches),ye=ae(t=>t.clearDiffCache),ee=ae(t=>t.setDiff),[_,te]=r.useState(null),[ne,$]=r.useState(!1),[ke,T]=r.useState(null),[W,A]=r.useState(()=>new Set),[de,H]=r.useState(()=>new Set),[xt,Oe]=r.useState(0),[Ke,ct]=r.useState(()=>new Map),[yt,Ft]=r.useState(0),[ut,$e]=r.useState(!1),[Ze,Ge]=r.useState(!1),[c,De]=r.useState(m);r.useEffect(()=>{De(m)},[m]);const ie=Q(t=>t.pendingDiffFile),we=Q(t=>t.pendingDiffStaged),Ae=Q(t=>t.pendingDiffScope),We=Q(t=>t.setPendingDiffFile),et=Q(t=>t.diffLayoutPreference),He=Q(t=>t.diffFileLayout),Se=Q(t=>t.setDiffFileLayout),fe=Q(t=>t.diffWrapLines),tt=Q(t=>t.setDiffWrapLines),G=Q(t=>t.diffFileListMode),wt=Q(t=>t.setDiffFileListMode),me=Q(t=>t.openContextFileAtLine),pe=an(t=>t.currentSessionId),dt=Ns(c==="turn"?pe??"":"",p??void 0),nt=fe,st=c==="staged"?!0:c==="working"?!1:null,qe=st??ne,Ue=ce||I<=768,Rt=!!pe&&c!=="turn"&&c!=="commit"&&c!=="pr"&&!Ue&&!Fe(),rt=c!=="turn"&&!Ue&&!Fe(),bt=!e&&!Ue&&I>=1024,oe=r.useRef(null),Ee=r.useRef(new Map),be=r.useRef(null),q=r.useRef(null),Te=r.useRef(!1),x=r.useRef(null),z=r.useRef(null),he=r.useRef(null),Le=r.useRef(null),Z=r.useCallback(()=>{const t=oe.current;if(!t)return null;const i=t.getBoundingClientRect().top,l=[];for(const[d,h]of Ee.current)h&&l.push({path:d,top:h.getBoundingClientRect().top});return ln(i,l)},[]),Ve=r.useCallback(()=>{be.current=null,Te.current=!1,T(null),q.current!==null&&(window.cancelAnimationFrame(q.current),q.current=null)},[]),Ne=r.useCallback(t=>{A(i=>{if(i.has(t))return i;const l=new Set(i);return l.add(t),l})},[]),[Me,it]=r.useState([]),Dt=dt.length>0?dt[dt.length-1].id:"";r.useEffect(()=>{if(c!=="turn"||!pe||!o)return;let t=!1;return Zn.getSessionTurnDiff(pe,{directory:p??void 0}).then(i=>{t||it(i.map(l=>({file:l.file,patch:l.patch,status:l.status,additions:l.additions,deletions:l.deletions})))}).catch(i=>{t||(console.warn("[diff-view] turn diff unavailable:",i instanceof Error?i.message:i),it([]))}),()=>{t=!0}},[c,pe,Dt,p,o]);const L=r.useMemo(()=>{const t=new Map;for(const i of Me)if(i.file){if(typeof i.patch=="string"){t.set(i.file,Pt(i.file,i.patch,"patch"));continue}t.set(i.file,{original:i.before??"",modified:i.after??"",contextMode:"full"})}return t},[Me]),ft=r.useMemo(()=>y?.files?y.files.filter(pn).length:0,[y]),Be=r.useMemo(()=>y?.files?y.files.filter(mn).length:0,[y]),Xe=Me.length,J=y?.current??null,Ie=ts(f??null,J,o&&c==="pr"&&!Fe()),Pe=Ie.selectedSource,_e=ns(f??null,J,o&&c==="commit"&&!Fe()),Je=_e.selectedCommit?.hash??null;r.useEffect(()=>{(c==="commit"||c==="pr")&&Fe()&&(De("working"),w?.("working"))},[c,w]);const ot=ae(t=>f?t.directories.get(f)?.branches??null:null),Cn=ae(t=>f?t.directories.get(f)?.isLoadingBranches??!1:!1),Fn=r.useCallback(()=>{f&&re(f,j)},[f,re,j]),Rn=fs(f??null,o&&U!==!1,Cn,!!ot,Fn,Js),Kt=r.useMemo(()=>{const t=y?.tracking?.trim().split("/")[0];return(t&&ot?.defaultBranches?.[t])??ot?.defaultBranches?.origin??null},[ot,y?.tracking]),$t=!Fe()&&ms(J,Kt),Dn=y!==null,Gt=Fe()||Rn||ps(J,Kt,Dn,ot!==null),An=ss(t=>t.setOverride),{base:Ce,resolved:En,revision:Wt}=rs(f??null,J,o&&$t&&c==="branch"),[Tn,Ln]=r.useState(0);r.useEffect(()=>{const t=xs(c,!Gt);t!==c&&(De(t),t==="working"&&w?.("working"))},[c,Gt,w]);const Vn=r.useMemo(()=>c==="pr"?Pe:c==="commit"&&Je?{kind:"commit",hash:Je}:c==="branch"&&Ce&&J?{kind:"branch",baseRef:Ce,headRef:J}:null,[c,Ce,J,Je,Pe]),P=hs(f??null,Vn,o&&!Fe(),c==="branch"?Wt:""),{fetchDiff:Ht,fetchFullFile:qt}=P,Ut=c==="commit"?P.files:null,Xt=c==="commit"?P.error:null,vt=c==="branch"?P.files:null,Jt=c==="branch"?P.error:null,Yt=P.files?c==="pr"?JSON.stringify([P.key,P.revision]):P.key:null,Mn=r.useMemo(()=>c==="branch"||c==="commit"||c==="pr"?Array.from(W).sort().join("\0"):"",[c,W]),At=r.useCallback(async(t,i=!1)=>{try{const l=await Ht(t,i?vn:It);return{status:"ready",data:Pt(t,l.diff,i?"full":"patch")}}catch(l){return{status:"error",message:l instanceof Error?l.message:a("diffView.state.failedToLoadDiff")}}},[Ht,a]),Qt=r.useCallback(async t=>{try{const{original:i,modified:l}=await qt(t),d=$s({name:t,contents:i},{name:t,contents:l});return{status:"ready",data:{original:i,modified:l,fileDiff:d,contextMode:"full"}}}catch(i){return{status:"error",message:i instanceof Error?i.message:a("diffView.state.failedToLoadDiff")}}},[qt,a]),Bn=r.useMemo(()=>c==="branch"||c==="commit"?t=>At(t,!0):c==="pr"?Qt:void 0,[c,At,Qt]),In=gs(Yt,o?Mn:"",Yt?At:null,fn,JSON.stringify([c==="branch"?Wt:"",c==="pr"?P.revision:0,Tn])),Pn=vt?.length??null,D=r.useMemo(()=>{if(c==="commit"||c==="pr")return(P.files??[]).map(d=>({path:d.path,index:"",working_dir:d.status,insertions:d.insertions,deletions:d.deletions,isNew:d.status==="A"}));if(c==="branch")return(vt??[]).map(d=>({path:d.path,index:"",working_dir:d.status,insertions:0,deletions:0,isNew:d.status==="A"})).sort((d,h)=>d.path.localeCompare(h.path));if(c==="turn")return Me.map(d=>({path:d.file??"",index:"",working_dir:nr(d.status),insertions:d.additions??0,deletions:d.deletions??0,isNew:d.status==="added"})).filter(d=>d.path).sort((d,h)=>d.path.localeCompare(h.path));if(!y?.files)return[];const t=y.diffStats,i=c==="staged"?mn:c==="working"?pn:()=>!0,l=d=>{const h=t?.staged?.[d],F=t?.working?.[d];return c==="staged"?{insertions:h?.insertions??0,deletions:h?.deletions??0}:c==="working"?{insertions:F?.insertions??0,deletions:F?.deletions??0}:{insertions:(h?.insertions??0)+(F?.insertions??0),deletions:(h?.deletions??0)+(F?.deletions??0)}};return y.files.filter(i).map(d=>{const h=l(d.path);return{...d,insertions:h.insertions,deletions:h.deletions,isNew:er(d)}}).sort((d,h)=>d.path.localeCompare(h.path))},[c,vt,P.files,Me,y]),Et=r.useMemo(()=>D.map(t=>t.path).join("\0"),[D]);r.useEffect(()=>{const t=Et?Et.split("\0"):[],i=new Set(t),l=`${f??""}:${c}:${s?"collapsed":"default"}`,d=z.current!==l;z.current=l,A(h=>{if(d){const B=s?0:Xs(t.length);return new Set(t.slice(0,B))}let F=!1;const R=new Set;for(const B of h){if(!i.has(B)){F=!0;continue}R.add(B)}return F?R:h}),H(h=>{if(d)return new Set;let F=!1;const R=new Set;for(const B of h){if(!i.has(B)){F=!0;continue}R.add(B)}return F?R:h})},[c,Et,f,s]);const Zt=r.useCallback(()=>{if(x.current=null,!o)return;const t=oe.current;if(!t)return;const i=t.getBoundingClientRect(),l=i.top-dn,d=i.bottom+dn,h={},F=[];for(const[R,B]of Ee.current){if(!B)continue;const Y=B.getBoundingClientRect();F.push({path:R,top:Y.top}),W.has(R)&&(Y.bottom<l||Y.top>d||(h[R]=!0))}he.current=ln(i.top,F),H(R=>{let B=!1;const Y=new Set(R);for(const gt of Object.keys(h))Y.has(gt)||(Y.add(gt),B=!0);return B?Y:R})},[W,o]),ge=r.useCallback(()=>{o&&(typeof window>"u"||x.current===null&&(x.current=window.requestAnimationFrame(Zt)))},[Zt,o]);r.useEffect(()=>{const t=oe.current;if(!(!o||!t))return ge(),t.addEventListener("scroll",ge,{passive:!0}),window.addEventListener("resize",ge),()=>{t.removeEventListener("scroll",ge),window.removeEventListener("resize",ge),x.current!==null&&(window.cancelAnimationFrame(x.current),x.current=null)}},[D,W,ge,o]);const Tt=r.useCallback(t=>{const i=He[t.path];if(i)return i;if(et==="inline")return"inline";if(et==="side-by-side")return"side-by-side";const l=I<qs;return t.isNew||l?"inline":"side-by-side"},[He,et,I]),en=r.useMemo(()=>D.length===0?null:D.every(t=>Tt(t)==="side-by-side")?"side-by-side":"inline",[D,Tt]);r.useEffect(()=>{o&&f&&(X(f),ue(f,j))},[f,X,ue,j,o]);const jt=JSON.stringify([E,f]),Lt=r.useRef({scope:jt,paths:new Set,dirty:!1,unscoped:!1}),tn=r.useRef(o);r.useEffect(()=>{const t=o&&!tn.current;if(tn.current=o,Lt.current.scope!==jt&&(Lt.current={scope:jt,paths:new Set,dirty:!1,unscoped:!1}),!f)return;const i=(d,h)=>{d.length&&(Le.current=Z()??he.current,ye(f,d),ct(F=>{const R=new Map(F);for(const B of d)R.set(B,(R.get(B)??0)+1);return R})),h&&Ft(F=>F+1),xe(f,j,{silent:!0})},l=Lt.current;return o&&(t||l.dirty)&&(i([...l.paths],l.unscoped),l.paths.clear(),l.dirty=!1,l.unscoped=!1),yn.onGitRefreshHint(d=>{if(hn(d.directory)!==hn(f))return;const h=d.paths??[],F=h.length===0;if(!o){l.dirty=!0,l.unscoped||=F;for(const R of h)l.paths.add(R);return}i(h,F)})},[Z,ye,f,xe,j,jt,o]),r.useLayoutEffect(()=>{const t=Le.current;if(!t)return;Le.current=null;const i=oe.current,l=Ee.current.get(t.path);if(!i||!l)return;const d=i.getBoundingClientRect().top,h=l.getBoundingClientRect().top-d;i.scrollTop=Hs(i.scrollTop,t.topOffset,h,i.scrollHeight-i.clientHeight),he.current=t},[Ke]),r.useEffect(()=>{!o||c!=="all"&&!Ae||ie&&(Ae&&De(Ae),te(ie),$(Ae==="staged"||!Ae&&we),We(null),Te.current=!0,be.current=ie,Ne(ie),Oe(t=>t+1))},[c,Ne,ie,Ae,we,We,o]),r.useEffect(()=>{if(c==="all")return;const t=k?.trim();t&&(te(t),$(c==="staged"),Te.current=!0,be.current=t,Ne(t),Oe(i=>i+1))},[c,Ne,k]),r.useEffect(()=>{if(!_)return;D.some(i=>i.path===_)||(te(null),$(!1))},[D,_]);const _n=r.useCallback((t,i)=>{const l=Ee.current;i?l.set(t,i):l.delete(t),ge()},[ge]),zn=r.useCallback((t,i)=>{Ve(),A(l=>{const d=l.has(t);if(i===d)return l;const h=new Set(l);return i?h.add(t):h.delete(t),h}),i||H(l=>{if(!l.has(t))return l;const d=new Set(l);return d.delete(t),d}),ge()},[Ve,ge]),On=r.useCallback(()=>{Ve(),A(t=>t.size>0?new Set:new Set(D.map(i=>i.path))),H(new Set),ge()},[Ve,D,ge]),Kn=r.useCallback(async t=>{if(!pe)return;const i=an.getState().getDirectoryForSession(pe)||p||"";if(!i){Ye.error(a("diffView.reviewDialog.toast.noSessionDirectory"));return}Ge(!0);try{await Cs({originalSessionID:pe,directory:i,providerID:t.providerID,modelID:t.modelID,agent:t.agent||void 0,variant:t.variant||void 0,generateHandoff:t.generateHandoff,returnAfterHandoffRequest:t.generateHandoff,autoReview:t.autoReview}),$e(!1)}catch(l){console.error("[review-flow] failed to start review flow",l),Ye.error(l instanceof Error?l.message:a("diffView.reviewDialog.toast.startFailed"))}finally{Ge(!1)}},[pe,p,a]),kt=r.useCallback(t=>{const i=Ee.current.get(t),l=oe.current;if(!i||!l)return!1;const d=i.getBoundingClientRect().top-l.getBoundingClientRect().top;return l.scrollTo({top:l.scrollTop+d,behavior:"auto"}),!0},[]);r.useEffect(()=>{const t=be.current;if(!o||!t)return;let i=0;const l=20;let d=!1;const h=(R=!0)=>{d||(d=!0,be.current=null,Te.current=!1,R&&T(null),q.current!==null&&(window.cancelAnimationFrame(q.current),q.current=null))},F=()=>{if(d){q.current=null;return}const R=be.current;if(!R){h(),q.current=null;return}if(!kt(R)){i+=1,i<l?q.current=window.requestAnimationFrame(F):(h(),q.current=null);return}if(u&&Te.current){T(R),h(!1);return}h()};return q.current=window.requestAnimationFrame(F),()=>{d=!0,q.current!==null&&(window.cancelAnimationFrame(q.current),q.current=null)}},[u,xt,kt,o]);const $n=r.useCallback(t=>{},[]),ve=G==="tree"&&!Ue,Gn=Q(t=>t.diffFileTreeWidth),St=Q(t=>t.setDiffFileTreeWidth),nn=r.useRef(null),[Wn,sn]=r.useState(!1),mt=Math.max(Gn,Bt),Nt=r.useCallback(t=>{const i=Math.max(Bt,(nn.current?.clientWidth??0)*ir);return Math.min(i,Math.max(Bt,t))},[]),Hn=r.useCallback(t=>{t.preventDefault();const i=t.clientX,l=mt;sn(!0);const d=F=>{St(Nt(l+F.clientX-i))},h=()=>{sn(!1),window.removeEventListener("pointermove",d),window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",h)};window.addEventListener("pointermove",d),window.addEventListener("pointerup",h),window.addEventListener("pointercancel",h)},[Nt,mt,St]),qn=r.useCallback(t=>{const i=t.shiftKey?40:10,l=t.key==="ArrowLeft"?-i:t.key==="ArrowRight"?i:0;l!==0&&(t.preventDefault(),St(Nt(mt+l)))},[Nt,mt,St]),Vt=r.useMemo(()=>ve?bn(D,new Set).flatMap(t=>t.kind==="file"?[t.file]:[]):[],[D,ve]),pt=ve?Vt:D,ht=ve?Vt.find(t=>t.path===_)??Vt[0]??null:null,Ct=r.useCallback(t=>{if(Ve(),ve){te(t),$(!1),Ne(t),oe.current?.scrollTo({top:0});return}te(t),$(!1),Te.current=!0,be.current=t,Ne(t),Oe(i=>i+1),kt(t)},[Ve,Ne,ve,kt]);r.useEffect(()=>{const t=i=>{if(!o||!i.altKey||i.metaKey||i.ctrlKey||i.shiftKey||i.key!=="ArrowDown"&&i.key!=="ArrowUp")return;const l=i.target;if(l instanceof HTMLElement&&(l.isContentEditable||l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.closest('[role="dialog"]'))||pt.length===0)return;const d=i.key==="ArrowDown"?1:-1,h=ve?ht?.path:_,F=h?pt.findIndex(Y=>Y.path===h):-1,R=F===-1?d>0?0:pt.length-1:F+d,B=pt[R];B&&(i.preventDefault(),Ct(B.path))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[_,Ct,ve,pt,ht,o]);const Un=r.useCallback(t=>{const i=t==="side-by-side"?"side-by-side":"inline";D.forEach(l=>{Se(l.path,i)})},[D,Se]),[Xn,rn]=r.useState(null),Jn=r.useCallback(async(t,i)=>{if(!f||!t)return;rn(t);const l=Re();try{let d=null;if(i?.patch&&!i.isBinary&&!lt(t)?d=cn(i.patch):i&&i.contextMode==="full"&&!i.isBinary&&!lt(t)&&(d=gn(i.original,i.modified)),d===null)try{const Y=await j.getGitDiff(f,{path:t,staged:qe,contextLines:3});d=cn(Y.diff)}catch{d=null}let h=i;if(d===null||!h){const Y=await j.getGitFileDiff(f,{path:t,staged:qe}),gt={original:Y.original??"",modified:Y.modified??"",isBinary:Y.isBinary,submodule:Y.submodule};h=gt,qe||ee(f,t,gt,l)}const F=d??(h.isBinary||lt(t)?1:gn(h.original,h.modified)),R=tr(f,t),B=await Ps(N,R,{directory:f});if(!B.ok){Ye.error(_s(B.reason));return}me(f,R,F,1)}finally{rn(d=>d===t?null:d)}},[qe,f,N,j,me,ee]),Yn=()=>{if(!f)return null;const t=(l,d=!1)=>n.jsx(cr,{visible:o,directory:f,file:l,layout:Tt(l),wrapLines:nt,isSelected:!1,isExpanded:d||W.has(l.path),isMounted:d||de.has(l.path)||l.path===ke,onSelect:$n,onExpandedChange:zn,registerSectionRef:_n,showOpenInEditorAction:g&&c!=="turn",isOpeningInEditor:Xn===l.path,onOpenInEditor:(h,F)=>{Jn(h,F)},staged:i(l.path),readOnlyActions:c==="branch"||c==="commit"||c==="pr",hunkActionsEnabled:c==="all"||c==="working"||c==="staged",contentRevision:yt,comparisonDiff:c==="branch"||c==="commit"||c==="pr"?In.get(l.path)??fn:void 0,onRetryComparisonDiff:()=>Ln(h=>h+1),loadFullComparisonDiff:Bn,initialDiffData:c==="turn"?L.get(l.path)??null:null},`${Re()}:${f}:${l.path}:${Ke.get(l.path)??0}`),i=l=>st!==null?st:ne&&l===_;return n.jsxs("div",{ref:nn,className:le("flex min-w-0 flex-1 min-h-0 h-full",v?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[ve&&n.jsxs(n.Fragment,{children:[n.jsx("section",{className:"flex max-w-[50%] flex-shrink-0 flex-col",style:{width:`${mt}px`},children:n.jsx(or,{changedFiles:D,selectedFile:ht?.path??null,onSelectFile:Ct})}),n.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":a("diffView.fileTree.resize"),tabIndex:0,onPointerDown:Hn,onKeyDown:qn,className:le("relative w-px shrink-0 cursor-col-resize bg-[var(--interactive-border)]/40","before:absolute before:inset-y-0 before:-left-1 before:-right-1 before:content-['']","hover:bg-interactive-selection focus-visible:bg-interactive-selection focus-visible:outline-none",Wn&&"bg-interactive-selection")})]}),bt&&!ve&&n.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[n.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:a("diffView.section.files")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:D.length})]}),n.jsx(rr,{changedFiles:D,selectedFile:null,onSelectFile:Ct})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(zt,{ref:oe,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:n.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:ve?ht&&t(ht,!0):D.map(l=>t(l))})})})]})},Qn=()=>{if(!f)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a("diffView.state.selectSessionDirectory")});if(c!=="turn"&&K&&!y)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(O,{name:"loader-4",className:"size-4 animate-spin"}),a("diffView.state.loadingRepositoryStatus")]});if(c!=="turn"&&U===!1)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a("diffView.state.notGitRepository")});if(c==="pr"){if(!Pe||P.error)return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",children:[n.jsx("p",{className:"typography-meta text-muted-foreground",children:P.error??Ie.error??(Ie.loading?a("session.githubPrPicker.loading.pullRequests"):a("pullRequestComparison.select"))}),(P.error||Ie.error)&&n.jsx(je,{variant:"outline",size:"sm",onClick:()=>{Pe?P.refresh():Ie.refresh()},children:a("diffView.actions.retry")}),!Pe&&!Ie.loading&&n.jsx(on,{comparison:Ie})]});if(!P.files)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 typography-meta text-muted-foreground",children:[n.jsx(O,{name:"loader-4",className:"size-4 animate-spin"}),a("diffView.state.loadingDiff")]})}if(c==="commit"){if(Xt)return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",children:[n.jsx("p",{className:"typography-meta text-muted-foreground",children:Xt}),n.jsx(je,{variant:"outline",size:"sm",onClick:()=>{P.refresh()},children:a("diffView.actions.retry")})]});if(!Je&&!_e.loading)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:_e.error??a("commitComparison.noCommits")});if(!Ut)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(O,{name:"loader-4",className:"size-4 animate-spin"}),a("diffView.state.loadingDiff")]})}if(c==="branch"){if(!En)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(O,{name:"loader-4",className:"size-4 animate-spin"}),a("diffView.branch.resolvingBase")]});if(!Ce)return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx(O,{name:"git-branch",className:"size-6 text-muted-foreground"}),n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:a("diffView.branch.noBaseTitle")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:a("gitView.pr.toast.baseBranchRequired")})]});if(Jt)return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:a("diffView.branch.loadError")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:Jt}),n.jsx(je,{variant:"outline",size:"sm",onClick:()=>{P.refresh()},children:a("diffView.actions.retry")})]});if(vt===null)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(O,{name:"loader-4",className:"size-4 animate-spin"}),a("diffView.branch.loadingFiles")]})}return D.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c==="turn"?a("diffView.state.noLastTurnChanges"):c==="pr"?a("walkthrough.blocked.emptyDiff.description"):c==="commit"?a("commitComparison.emptyDiff"):c==="branch"&&Ce?a("diffView.branch.empty",{base:Ms(Ce)}):a("diffView.state.cleanWorkingTree")}):Yn()};return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[n.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[b===!1&&Array.isArray(V)&&V.length>0?n.jsx(Vs,{repositories:V,selectedRepository:C??null,onSelectRepository:t=>{p&&se(p,t)},repositoryRoot:p??void 0}):null,!ce&&(c!=="all"?n.jsx(sr,{scope:c,workingCount:ft,stagedCount:Be,turnCount:Xe,branchCount:Pn,commitCount:c==="commit"?Ut?.length??null:null,prCount:c==="pr"?P.files?.length??null:null,showCommitOption:!Fe(),showBranchOption:$t,onScopeChange:t=>{De(t),w?.(t)}}):n.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:n.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:K&&!y?a("diffView.state.loadingChanges"):D.length===1?a("diffView.summary.changedFilesSingle",{count:D.length}):a("diffView.summary.changedFilesPlural",{count:D.length})})})),c==="branch"&&n.jsx(is,{branches:ot?.all??[],currentBranch:J,base:Ce,onSelect:t=>{f&&J&&An(f,J,t)}},JSON.stringify([f,J])),c==="commit"&&n.jsx(os,{commits:_e.commits,selectedHash:Je,loading:_e.loading,error:_e.error,onSelect:_e.select,onRefresh:()=>{_e.refresh()}},JSON.stringify([f,J])),c==="pr"&&n.jsxs(n.Fragment,{children:[n.jsx(on,{comparison:Ie},JSON.stringify([E,f,J])),Pe&&n.jsx(je,{variant:"ghost",size:"sm",disabled:P.loading,"aria-label":a("session.githubIssuePicker.actions.refresh"),title:a("session.githubIssuePicker.actions.refresh"),onClick:()=>{P.refresh()},children:n.jsx(O,{name:"refresh",className:"size-4"})})]}),D.length>0&&n.jsxs(je,{variant:"ghost",size:"sm",onClick:On,className:le("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:W.size>0?a("diffView.actions.collapseAll"):a("diffView.actions.expandAll"),children:[n.jsx(O,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:W.size>0?a("diffView.actions.collapseAll"):a("diffView.actions.expandAll")})]}),D.length>0&&Rt&&n.jsxs(je,{variant:"default",size:"sm",onClick:()=>$e(!0),disabled:Ze,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":a("diffView.actions.reviewAria"),children:[Ze?n.jsx(O,{name:"loader-4",className:"size-4 animate-spin"}):n.jsx(O,{name:"search-eye",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:a("diffView.actions.review")})]}),D.length>0&&rt&&n.jsxs(je,{variant:"outline",size:"sm",onClick:()=>{const t=f??"";M(t,c==="pr"&&Pe?Pe:c==="commit"&&Je?{kind:"commit",hash:Je}:c==="branch"&&Ce&&J?{kind:"branch",baseRef:Ce,headRef:J}:{kind:"working-tree",scope:c==="staged"||c==="working"?c:"all"}),S(p??t,"walkthrough")},className:le("diff-toolbar__walkthrough-button h-7 flex-shrink-0 gap-1.5 px-2",zs),"aria-label":a("walkthrough.action.open"),children:[n.jsx(O,{name:"route",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__walkthrough-label typography-ui-label",children:a("walkthrough.action.open")})]}),D.length>0&&!Ue&&n.jsx(je,{variant:"ghost",size:"sm",onClick:()=>wt(G==="tree"?"flat":"tree"),"aria-pressed":G==="tree",className:le("h-5 w-5 p-0 transition-opacity",G==="tree"?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:a(G==="tree"?"diffView.fileTree.showAsList":"diffView.fileTree.showAsTree"),children:n.jsx(O,{name:"node-tree",className:"size-4"})}),D.length>0&&n.jsx(je,{variant:"ghost",size:"sm",onClick:()=>tt(!fe),className:le("h-5 w-5 p-0 transition-opacity",nt?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:a(nt?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:n.jsx(O,{name:"text-wrap",className:"size-4"})}),en&&n.jsx(wn,{mode:en==="side-by-side"?"side-by-side":"unified",onModeChange:Un})]}),n.jsx(Fs,{open:ut,onOpenChange:$e,projectDirectory:f??null,submitting:Ze,onConfirm:Kn}),Qn()]})};function ur(){return new Set}function dr(o,e){return n.jsx("span",{"aria-hidden":!0,className:"pointer-events-none absolute inset-y-0 w-px bg-border/50",style:{left:`${Nn+e*Sn+7}px`}},e)}function fr(o){return Array.from({length:o},dr)}export{Vo as DiffView,cr as MultiFileDiffEntry};
@@ -0,0 +1,17 @@
1
+ import{f as Re,R as i,c as Ei,j as r,r as ht}from"./vendor-react-BUCujlKS.js";import{a as tt,h as en,Z as Mo,_ as Do,$ as zo,a0 as Lo,x as et,u as mt,eb as Ao,J as Vi,C as Io,a4 as Pi,e8 as Oo,e as Bo,e9 as $o,a3 as _o,ea as Wo}from"./index-Di6zUe5h.js";import{f as st,z as Mi,ai as sa,cf as Uo,h as W,kI as Ko,g8 as Ho,X as Cs,B as I,I as E,kJ as qo,aA as Ns,gZ as Go,gX as Xo,_ as Jo,T as Zo,bj as Yo,K as Qo,ak as el,cA as tl,eI as Di,iD as sl,gu as rl,t as re,l as zi,ay as Kr,ct as bs,da as nl,b as il,kK as ys,c1 as al,az as Hr,kL as qr,cu as Li,cv as Ai,kM as Ii,kN as Oi,kO as ol,kP as ll,kQ as cl,hE as ul,kR as dl,kS as fl,kT as ml,c2 as ra,c3 as na,c4 as ia,c5 as aa,c6 as oa,c7 as la,as as tn,at as sn,av as rn,bh as ur,c8 as Gr,aB as ar,cp as Xr,ae as Mt,af as Dt,ag as zt,b$ as hl,c0 as pl,g as fr,bi as gl,cz as xl}from"./useAppFontEffects-BN06mgHB.js";import{l as vl,az as wl,ay as bl,Z as yl,_ as jl,$ as Nl,a0 as Sl,a1 as Cl}from"./runtimeEndpointReset-sCi88eed.js";import{c as Bi,s as Fl,P as js,C as kl}from"./shikiHighlight-O5_xLmWt.js";import{a as Rl}from"./vendor-codemirror-state-C9awkmn-.js";import{E as Lt}from"./vendor-codemirror-view-CiLROUVV.js";import{V as Tl,J as El,F as Vl}from"./JsonTreeView-C3QZifYe.js";import{ensurePierreThemeRegistered as $i,getResolvedShikiTheme as Pl}from"./appThemeRegistry-BoJGAwCP.js";import{V as Ml,W as Dl}from"./Virtualizer-CZlLSacm.js";import{V as zl}from"./Virtualizer-D_a8gKmg.js";import{D as Ll}from"./vendor-react-drawio-Ct3Q0DsD.js";import{a as Al,u as or,b as Il,g as Ol,h as Bl}from"./scheduledTasksApi-Dahv3ws0.js";import{I as $l,u as _l,n as Wl}from"./useInlineCommentController-Bb9Gjz1Q.js";import{b as Ul}from"./CodeMirrorCommentWidgets-BlzB2e0C.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-BSoePkpP.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-opencode-client-DSZl7jSi.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-CsXYnR5c.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-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-tanstack-react-virtual-ClYN8CzB.js";import"./vendor-tanstack-virtual-core-BewVQryB.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./contextPanelEmbeddedChat-CirXEPJq.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-C2qMZiA7.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./GuestAttachDialog-CQdDIeco.js";import"./PluginPane-DPWPLc2f.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-BQWjCn_U.js";import"./computeVirtualFileMetrics-kYyVjXLu.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-D5GMgURH.js";import"./textMateThemeFromAppTheme-XM4VefqN.js";function _i(n){const e=Re.c(41),{containerRef:s,filePath:a,fileContent:w}=n,{t:f}=st(),v=Mi(Yl),d=Mi(Zl),x=sa(),p=Uo(Jl),[m,b]=i.useState(null),[y,F]=i.useState(""),[N,S]=i.useState(!1),g=i.useRef(!1),l=i.useRef(null),T=i.useRef(null),[R,M]=i.useState(null);let D;e[0]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{b(null),F(""),S(!1),g.current=!1,T.current=null,M(null)},e[0]=D):D=e[0];const A=D;let k,V;e[1]!==s?(k=()=>{const K=s.current;if(!K)return;const ie=()=>{if(g.current)return;const ae=window.getSelection(),fe=ae?.toString().trim()??"";if(!ae||!fe||ae.rangeCount===0){A();return}const me=ae.getRangeAt(0);if(!K.contains(me.commonAncestorContainer)){A();return}const le=me.getBoundingClientRect();T.current=me.cloneRange(),F(fe),b({x:le.left+le.width/2,y:le.top-10})},_=ae=>{l.current?.contains(ae.target)||g.current&&A()};return document.addEventListener("selectionchange",ie),document.addEventListener("pointerdown",_),()=>{document.removeEventListener("selectionchange",ie),document.removeEventListener("pointerdown",_)}},V=[s,A],e[1]=s,e[2]=k,e[3]=V):(k=e[2],V=e[3]),i.useEffect(k,V);let z;e[4]!==w?(z=K=>{const ie=he=>w.slice(0,he).split(`
2
+ `).length,_=Gl,ae=(he,ve)=>{for(const Ee of _(he)){const ye=w.indexOf(Ee,ve);if(ye>=0)return ye}return-1},fe=K.length>=8?w.indexOf(K):-1;if(fe>=0){const he=ie(fe);return{start:he,end:he+K.split(`
3
+ `).length-1}}const me=K.split(`
4
+ `).map(ql).filter(Boolean);if(me.length===0)return null;const le=ae(me[0],0);if(le<0)return null;const be=ie(le);if(me.length===1)return{start:be,end:be};const xe=ae(me[me.length-1],le);return xe<0?null:{start:be,end:Math.max(be,ie(xe))}},e[4]=w,e[5]=z):z=e[5];const B=z;let U;e[6]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{const K=T.current;if(!K){M(null);return}M(Ko(K))},e[6]=U):U=e[6];const Y=U;let te,ee;e[7]!==N?(te=()=>{if(!N)return;let K=null;const ie=()=>{K===null&&(K=window.requestAnimationFrame(()=>{K=null,Y()}))};return document.addEventListener("scroll",ie,{capture:!0,passive:!0}),window.addEventListener("resize",ie),()=>{K!==null&&window.cancelAnimationFrame(K),document.removeEventListener("scroll",ie,{capture:!0}),window.removeEventListener("resize",ie)}},ee=[N,Y],e[7]=N,e[8]=te,e[9]=ee):(te=e[8],ee=e[9]),i.useEffect(te,ee);let G;e[10]!==y?(G=()=>{y&&(S(!0),g.current=!0,Y(),window.getSelection()?.removeAllRanges())},e[10]=y,e[11]=G):G=e[11];const X=G;let J;e[12]!==p||e[13]!==v||e[14]!==x||e[15]!==a||e[16]!==d||e[17]!==B||e[18]!==y?(J=K=>{const ie=v??(d?"draft":null);if(!y||!ie||!x){A();return}const _=B(y);p({directory:x,sessionKey:ie},{source:"file-quote",fileLabel:a,startLine:_?.start??0,endLine:_?.end??0,code:y,language:"",text:K.trim()}),A(),queueMicrotask(Hl)},e[12]=p,e[13]=v,e[14]=x,e[15]=a,e[16]=d,e[17]=B,e[18]=y,e[19]=J):J=e[19];const q=J;if(!m)return null;let Q;e[20]!==N||e[21]!==B||e[22]!==y?(Q=N?B(y):null,e[20]=N,e[21]=B,e[22]=y,e[23]=Q):Q=e[23];const _e=Q;let ne;e[24]!==m.x||e[25]!==m.y?(ne={left:m.x,top:m.y,transform:"translate(-50%, -100%)"},e[24]=m.x,e[25]=m.y,e[26]=ne):ne=e[26];let Te;e[27]!==N||e[28]!==R?(Te=N&&R&&R.length>0?Ei.createPortal(r.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:R.map(Kl)}),document.body):null,e[27]=N,e[28]=R,e[29]=Te):Te=e[29];let De;e[30]!==N||e[31]!==a||e[32]!==_e||e[33]!==X||e[34]!==q||e[35]!==f?(De=N?r.jsx("div",{className:"w-[min(420px,80vw)]",children:r.jsx($l,{fileLabel:a,lineRange:_e?{start:_e.start,end:_e.end}:void 0,onSave:q,onCancel:A})}):r.jsx("div",{className:W("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:X,className:W("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-foreground","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:f("chat.textSelection.title.commentOnSelection"),children:f("chat.textSelection.actions.comment")})}),e[30]=N,e[31]=a,e[32]=_e,e[33]=X,e[34]=q,e[35]=f,e[36]=De):De=e[36];let ze;return e[37]!==ne||e[38]!==Te||e[39]!==De?(ze=Ei.createPortal(r.jsxs("div",{ref:l,className:"fixed z-50",style:ne,children:[Te,De]}),document.body),e[37]=ne,e[38]=Te,e[39]=De,e[40]=ze):ze=e[40],ze}function Kl(n,e){return r.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:n.left,top:n.top,width:n.width,height:n.height}},e)}function Hl(){Ho()}function ql(n){return n.trim()}function Gl(n){const e=n.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(Xl)}function Xl(n){return n.length>=8}function Jl(n){return n.addDraft}function Zl(n){return n.newSessionDraft?.open}function Yl(n){return n.currentSessionId}const Ql=(n,e)=>{if(!e)return null;const s=Number.parseInt(n.trim(),10);return!Number.isFinite(s)||s<1?null:Math.min(s,e.state.doc.lines)},Wi=(n,e)=>{const s=n.state.doc.lineAt(e.main.head);return{lineNumber:s.number,character:e.main.head-s.from+1,selection:e}},Ui=(n,e,s)=>{const a=n.state.doc.line(e),w=Math.max(1,Math.min(s,a.length+1)),f=a.from+w-1;n.dispatch({selection:Rl.cursor(f),effects:Lt.scrollIntoView(f,{y:"center"})})};function ec({open:n,onOpenChange:e,view:s,variant:a="overlay"}){const{t:w}=st(),[f,v]=i.useState(""),d=i.useRef(null),x=i.useRef(!1),p=i.useRef(null),m=i.useRef(null),b=i.useMemo(()=>Ql(f,s),[f,s]);i.useEffect(()=>{!n||!s||(x.current=!1,d.current=Wi(s,s.state.selection),v(""))},[n,s]),i.useEffect(()=>{n&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[n]),i.useEffect(()=>{if(!(!n||!s||!d.current)){if(b===null){const{selection:g}=d.current;s.dispatch({selection:g,effects:Lt.scrollIntoView(g.main.from,{y:"center"})});return}Ui(s,b,d.current.character)}},[b,n,s]);const y=i.useCallback(()=>{if(!s||x.current||!d.current)return;const{selection:g}=d.current;s.dispatch({selection:g,effects:Lt.scrollIntoView(g.main.from,{y:"center"})})},[s]),F=i.useCallback(g=>{g||y(),e(g)},[e,y]),N=i.useCallback(()=>{!s||b===null||!d.current||(x.current=!0,Ui(s,b,d.current.character),e(!1),s.focus())},[b,e,s]);i.useEffect(()=>{if(!n)return;const g=T=>{const R=p.current,M=T.target;!R||!(M instanceof Node)||R.contains(M)||F(!1)},l=T=>{T.key==="Escape"&&(T.preventDefault(),F(!1))};return document.addEventListener("pointerdown",g,!0),document.addEventListener("keydown",l,!0),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("keydown",l,!0)}},[F,n,a]);const S=i.useMemo(()=>{if(!s)return w("goToLineDialog.helper.editorUnavailable");if(b===null){const g=d.current??Wi(s,s.state.selection);return w("goToLineDialog.helper.currentLineRange",{current:g.lineNumber,max:s.state.doc.lines})}return w("goToLineDialog.helper.goToLine",{line:b})},[b,w,s]);return a==="inline"?n?r.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[r.jsx(Cs,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:f,onChange:g=>v(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),N())},placeholder:w("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),r.jsx(I,{variant:"outline",size:"xs",onClick:N,disabled:!s||b===null,className:"h-6 px-2",children:w("goToLineDialog.actions.go")})]}):null:r.jsx("div",{ref:p,className:W("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",n?"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(Cs,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:f,onChange:g=>v(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),N())},placeholder:w("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-surface-elevated/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:S})]})})}const tc=(n,e)=>{const s=e.trim().toLowerCase(),a=[];if(!s)return a;const w=n.toLowerCase();let f=0;for(;;){const v=w.indexOf(s,f);if(v===-1)break;a.push({start:v,end:v+s.length}),f=v+s.length}return a},mr="data-md-find",Jr="data-md-find-current",ca="rounded-[2px] bg-status-warning/30 text-foreground",sc="rounded-[2px] bg-status-warning/60 text-foreground",rc=120,nc=n=>n instanceof Element&&n.hasAttribute(mr),ic=n=>n.target instanceof Element&&n.target.hasAttribute(mr)?!0:[...n.addedNodes].some(e=>nc(e)),ua=n=>{const e=new Set;n.querySelectorAll(`mark[${mr}]`).forEach(s=>{const a=s.parentNode;a&&(a.replaceChild(document.createTextNode(s.textContent??""),s),e.add(a))}),e.forEach(s=>s.normalize())},ac=(n,e)=>{ua(n);const s=e.trim().toLowerCase();if(!s)return[];const a=[],w=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(v){const d=v.parentElement;return!d||d.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),f=[];for(;w.nextNode();){const v=w.currentNode;v instanceof Text&&f.push(v)}for(const v of f){const d=v.nodeValue??"";if(!d)continue;const x=tc(d,s);if(x.length===0)continue;const p=v.parentNode;if(!p)continue;const m=document.createDocumentFragment();let b=0;for(const y of x){y.start>b&&m.appendChild(document.createTextNode(d.slice(b,y.start)));const F=document.createElement("mark");F.setAttribute(mr,""),F.className=ca,F.textContent=d.slice(y.start,y.end),m.appendChild(F),a.push(F),b=y.end}b<d.length&&m.appendChild(document.createTextNode(d.slice(b))),p.replaceChild(m,v)}return a},Ki=({containerRef:n,open:e,onOpenChange:s,focusNonce:a,className:w})=>{const{t:f}=st(),[v,d]=i.useState(""),[x,p]=i.useState(0),[m,b]=i.useState(0),y=i.useRef(null),F=i.useRef([]),N=i.useRef(v);N.current=v;const S=i.useRef(null),g=i.useRef(null),l=i.useCallback((k,V=!1)=>{const z=n.current;if(!z){F.current=[],p(0),b(0);return}F.current=ac(z,k);const B=F.current.length;p(B),b(U=>!V||B===0?0:Math.min(U,B-1))},[n]),T=i.useCallback((k,V=!1)=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{S.current=null,l(k,V)},rc)},[l]);i.useEffect(()=>()=>{S.current&&clearTimeout(S.current)},[]);const R=i.useCallback(()=>{s(!1);const k=g.current;g.current=null,k?.isConnected&&k.focus()},[s]);i.useEffect(()=>{const k=n.current;if(!e||!k)return;const V=new MutationObserver(z=>{!N.current.trim()||!z.some(U=>!ic(U))||T(N.current,!0)});return V.observe(k,{childList:!0,subtree:!0,characterData:!0}),()=>{V.disconnect(),ua(k)}},[n,e,T]),i.useEffect(()=>{if(!e)return;const k=document.activeElement;k instanceof HTMLElement&&!g.current&&(g.current=k),y.current?.focus()},[e]),i.useEffect(()=>{e&&a>0&&(y.current?.focus(),y.current?.select())},[e,a]),i.useEffect(()=>{const k=n.current;if(!k||(k.querySelectorAll(`mark[${Jr}]`).forEach(z=>{z.removeAttribute(Jr),z.className=ca}),x===0))return;const V=F.current[Math.min(Math.max(m,0),x-1)];V&&(V.setAttribute(Jr,""),V.className=sc,V.scrollIntoView({block:"nearest"}))},[n,m,x]);const M=i.useCallback(()=>{b(k=>x===0?0:(k+1)%x)},[x]),D=i.useCallback(()=>{b(k=>x===0?0:(k-1+x)%x)},[x]),A=i.useCallback(k=>{k.key==="Enter"?(k.preventDefault(),k.shiftKey?D():M()):k.key==="Escape"&&(k.preventDefault(),R())},[R,M,D]);return e?r.jsxs("div",{className:W("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",w),children:[r.jsx(E,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),r.jsx(Cs,{ref:y,value:v,onChange:k=>{d(k.target.value),T(k.target.value)},onKeyDown:A,placeholder:f("filesView.preview.find.placeholder"),"aria-label":f("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":x>0?f("filesView.preview.find.countAria",{current:m+1,total:x}):f("filesView.preview.find.noMatches"),children:v.trim()&&x===0?f("filesView.preview.find.noMatches"):x>0?`${m+1}/${x}`:""}),r.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:D,title:f("filesView.preview.find.previousAria"),"aria-label":f("filesView.preview.find.previousAria"),disabled:x===0,children:r.jsx(E,{name:"arrow-up",className:"size-3.5"})}),r.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:M,title:f("filesView.preview.find.nextAria"),"aria-label":f("filesView.preview.find.nextAria"),disabled:x===0,children:r.jsx(E,{name:"arrow-down",className:"size-3.5"})}),r.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:R,title:f("filesView.preview.find.closeAria"),"aria-label":f("filesView.preview.find.closeAria"),children:r.jsx(E,{name:"close",className:"size-3.5"})})]}):null},oc=n=>{let e=!0;return{poll:async()=>{if(!e||n.isDirty())return!1;const s=n.getLoadedContent(),a=n.getLoadedRevision();try{const w=await n.readContent();if(!e||n.isDirty()||a!==n.getLoadedRevision())return!1;if(w===s)return!0;const f=await n.readContent();return!e||n.isDirty()||f!==w||a!==n.getLoadedRevision()?!1:(n.applyContent(w),!0)}catch{return!1}},dispose:()=>{e=!1}}},lc=1,cc=(n,e)=>e.size!==n.size||e.mtimeMs!==void 0&&n.mtimeMs!==void 0&&Math.abs(e.mtimeMs-n.mtimeMs)>=lc;function Hi(){const n=Re.c(8),[e]=ht.useState(uc),s=ht.useRef(!1);let a;n[0]!==e?(a=x=>{if(x==null){e.cleanUp(),s.current=!1;return}s.current||(s.current=!0,e.setup(x,x.firstElementChild??void 0))},n[0]=e,n[1]=a):a=n[1];const w=a;let f,v;n[2]!==e?(f=()=>()=>{s.current=!1,e.cleanUp()},v=[e],n[2]=e,n[3]=f,n[4]=v):(f=n[3],v=n[4]),ht.useLayoutEffect(f,v);let d;return n[5]!==w||n[6]!==e?(d={virtualizer:e,setScroller:w},n[5]=w,n[6]=e,n[7]=d):d=n[7],d}function uc(){return new zl}const rs=new Map,dc=100;function lr(n){const[e,s]=ht.useState(null),a=ht.useRef(null),w=ht.useRef(null),f=ht.useRef(null),v=ht.useCallback((d,x)=>{d&&x instanceof Tl&&(f.current={key:n,file:x,node:d});const p=a.current,m=w.current,b=()=>{a.current===p&&(p?.(),m?.())};x?queueMicrotask(b):b()},[n]);return ht.useLayoutEffect(()=>{if(!e||!n)return;const d=rs.get(n)??{top:0,left:0};let x=!0;const p=()=>f.current?.key===n?f.current.file:null,m=l=>f.current?.key===n?f.current.node.shadowRoot?.querySelector(`[data-line][data-line-index="${l-1}"]`):null,b=()=>{F.disconnect(),N.disconnect()},y=()=>{if(!x)return;const l=p(),T=d.line&&l?.getLinePosition(d.line.number),R=d.line&&m(d.line.number);let M=d.top;d.line&&T&&(M=(l?.top??0)+T.top-d.line.offset),d.line&&R&&(M=e.scrollTop+R.getBoundingClientRect().top-e.getBoundingClientRect().top-d.line.offset),e.scrollTop=M,e.scrollLeft=d.left,(!d.line||R)&&Math.abs(e.scrollTop-M)<1&&Math.abs(e.scrollLeft-d.left)<1&&(x=!1,b())},F=new ResizeObserver(y),N=new MutationObserver(()=>{if(x){for(const l of e.children)F.observe(l);y()}});F.observe(e);for(const l of e.children)F.observe(l);N.observe(e,{childList:!0,subtree:!0});const S=()=>{if(x)return;const l=p(),T=l?.getNumericScrollAnchor(e.scrollTop-(l.top??0)),R=T&&m(T.lineNumber),M=R?R.getBoundingClientRect().top-e.getBoundingClientRect().top:null;if(rs.delete(n),rs.set(n,{top:e.scrollTop,left:e.scrollLeft,line:T&&M!==null&&M>=0&&M<e.clientHeight?{number:T.lineNumber,offset:M}:void 0}),rs.size>dc){const D=rs.keys().next().value;D!==void 0&&rs.delete(D)}},g=()=>{x=!1,b()};return a.current=y,w.current=S,y(),e.addEventListener("scroll",S,{passive:!0}),e.addEventListener("wheel",g,{passive:!0}),e.addEventListener("touchstart",g,{passive:!0}),e.addEventListener("pointerdown",g,{passive:!0}),e.addEventListener("keydown",g),()=>{a.current=null,w.current=null,f.current?.key===n&&(f.current=null),b(),e.removeEventListener("scroll",S),e.removeEventListener("wheel",g),e.removeEventListener("touchstart",g),e.removeEventListener("pointerdown",g),e.removeEventListener("keydown",g)}},[n,e]),{setScroller:s,restore:v}}function fc(n){return!(!n.autoSaveEnabled||!n.isDirty||!n.canWrite||n.isSaving||n.fileLoading||n.isNonEditableBinary||!n.selectedFilePath||n.loadedFilePath!==n.selectedFilePath)}function mc(n){return n.selectedFilePath?n.isDirty?!(n.fileLoading||n.loadedFilePath!==n.selectedFilePath||n.isNonEditableBinary||n.draftContent===""&&n.fileContent!==""&&n.loadedFilePath!==n.selectedFilePath):!0:!1}const da=2e5,hc=n=>{let e=0,s=0;for(let a=0;a<n.length;a++)n.charCodeAt(a)===10&&(a>0&&n.charCodeAt(a-1)===13?e++:s++);return e>s?`\r
5
+ `:`
6
+ `},fa=n=>n.replace(/\r\n/g,`
7
+ `).replace(/\r/g,`
8
+ `),pc=n=>({content:fa(n),lineEnding:hc(n)}),gc=(n,e)=>{const s=fa(n);return e===`\r
9
+ `?s.replace(/\n/g,`\r
10
+ `):s},xc=(n,e)=>e??(n.length>da?"view":"edit"),vc=n=>{let e=2166136261;for(let s=0;s<n.length;s++)e^=n.charCodeAt(s),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return`${n.length}:${e.toString(16)}`},wc='<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 qi(){if(typeof document>"u")return!1;const n=document.documentElement.getAttribute("data-theme");return n==="dark"||!n&&window.matchMedia("(prefers-color-scheme: dark)").matches}const bc=i.forwardRef(function({xml:e,readOnly:s,className:a,onChange:w},f){const v=i.useRef(e),d=i.useRef(null),x=i.useRef(!1),[p,m]=i.useState(qi),b=i.useRef(e),y=i.useRef(e);y.current!==e&&(y.current=e,b.current=e,v.current=e);const F=i.useRef(p);F.current!==p&&(F.current=p,b.current=v.current);const N=i.useRef(null);i.useEffect(()=>{const l=()=>m(qi());l();const T=new MutationObserver(l);return T.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>T.disconnect()},[]),i.useEffect(()=>{const l=setTimeout(()=>{N.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(l)},[]),i.useImperativeHandle(f,()=>({getXml:()=>v.current}));const S=i.useCallback(()=>{!e&&!x.current&&(x.current=!0,setTimeout(()=>{d.current?.template({})},500))},[e]),g=i.useCallback(l=>{v.current=l.xml,w?.(l.xml)},[w]);return r.jsx("div",{ref:N,className:W("h-full w-full",a),children:r.jsx(Ll,{ref:d,xml:b.current||wc,autosave:!0,urlParameters:{ui:s?"simple":p?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:S,onAutoSave:g},p?"dark":"light")})}),Fs=n=>{const e=Re.c(18),{items:s,actions:a,className:w}=n;let f,v,d,x;if(e[0]!==a||e[1]!==w||e[2]!==s){x=Symbol.for("react.early_return_sentinel");e:{const y=s.filter(yc);if(y.length===0&&!a){x=null;break e}e[7]!==w?(d=W("flex min-h-7 items-center gap-2 border-b border-border/40 bg-[var(--surface-subtle)] px-3 py-1",w),e[7]=w,e[8]=d):d=e[8],f="min-w-0 flex-1 truncate typography-meta text-muted-foreground",v=y.join(" · ")}e[0]=a,e[1]=w,e[2]=s,e[3]=f,e[4]=v,e[5]=d,e[6]=x}else f=e[3],v=e[4],d=e[5],x=e[6];if(x!==Symbol.for("react.early_return_sentinel"))return x;let p;e[9]!==f||e[10]!==v?(p=r.jsx("div",{className:f,children:v}),e[9]=f,e[10]=v,e[11]=p):p=e[11];let m;e[12]!==a?(m=a?r.jsx("div",{className:"flex shrink-0 items-center gap-1",children:a}):null,e[12]=a,e[13]=m):m=e[13];let b;return e[14]!==d||e[15]!==p||e[16]!==m?(b=r.jsxs("div",{className:d,children:[p,m]}),e[14]=d,e[15]=p,e[16]=m,e[17]=b):b=e[17],b};function yc(n){return n.length>0}const ks=n=>{if(n===null||!Number.isFinite(n)||n<0)return"";if(n<1024)return`${n} B`;const e=["KB","MB","GB"];let s=n/1024;for(const a of e){if(s<1024||a===e[e.length-1])return`${s.toFixed(s>=10?0:1)} ${a}`;s/=1024}return""},jc=n=>{if(n===null||!Number.isFinite(n)||n<0)return"";const e=Math.round(n),s=Math.floor(e/3600),a=Math.floor(e%3600/60),w=e%60,f=v=>String(v).padStart(2,"0");return s>0?`${s}:${f(a)}:${f(w)}`:`${a}:${f(w)}`},ma=n=>n&&n.width>0&&n.height>0?`${n.width} × ${n.height}`:"",Nc=n=>{const e=Re.c(28),{name:s,path:a,sizeBytes:w,download:f}=n,{t:v}=st();let d,x,p,m,b,y,F;if(e[0]!==s||e[1]!==a||e[2]!==w||e[3]!==v){const l=qo(a).toUpperCase();y="flex h-full min-h-0 flex-col",F=r.jsx(Fs,{items:[l,ks(w)]}),p="flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",e[11]!==a?(m=r.jsx(Ns,{filePath:a,className:"size-10"}),e[11]=a,e[12]=m):m=e[12],e[13]!==s?(b=r.jsx("div",{className:"max-w-full truncate typography-ui-header text-foreground",children:s}),e[13]=s,e[14]=b):b=e[14],d="max-w-md typography-ui text-muted-foreground",x=l?v("filesView.artifact.binary.descriptionWithType",{extension:l}):v("filesView.artifact.binary.description"),e[0]=s,e[1]=a,e[2]=w,e[3]=v,e[4]=d,e[5]=x,e[6]=p,e[7]=m,e[8]=b,e[9]=y,e[10]=F}else d=e[4],x=e[5],p=e[6],m=e[7],b=e[8],y=e[9],F=e[10];let N;e[15]!==d||e[16]!==x?(N=r.jsx("div",{className:d,children:x}),e[15]=d,e[16]=x,e[17]=N):N=e[17];let S;e[18]!==f||e[19]!==p||e[20]!==m||e[21]!==b||e[22]!==N?(S=r.jsxs("div",{className:p,children:[m,b,N,f]}),e[18]=f,e[19]=p,e[20]=m,e[21]=b,e[22]=N,e[23]=S):S=e[23];let g;return e[24]!==y||e[25]!==F||e[26]!==S?(g=r.jsxs("div",{className:y,children:[F,S]}),e[24]=y,e[25]=F,e[26]=S,e[27]=g):g=e[27],g},Sc=[48,32,24,18,14],Cc=["ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz",`0123456789 .,;:!?&@#%()[]{}<>+-=/\\*"'`];let Zr=0;const Fc=n=>{const e=Re.c(16),{src:s,name:a,sizeBytes:w}=n,{t:f}=st(),[v,d]=i.useState("loading"),[x]=i.useState(kc);let p,m;e[0]!==x||e[1]!==s?(p=()=>{let S=!1;d("loading");const g=new FontFace(x,`url("${s.replace(/"/g,"%22")}")`);return document.fonts.add(g),g.load().then(()=>{S||d("ready")}).catch(()=>{S||d("failed")}),()=>{S=!0,document.fonts.delete(g)}},m=[x,s],e[0]=x,e[1]=s,e[2]=p,e[3]=m):(p=e[2],m=e[3]),i.useEffect(p,m);let b;e[4]!==w?(b=ks(w),e[4]=w,e[5]=b):b=e[5];let y;e[6]!==a||e[7]!==b?(y=r.jsx(Fs,{items:[a,b]}),e[6]=a,e[7]=b,e[8]=y):y=e[8];let F;e[9]!==x||e[10]!==v||e[11]!==f?(F=v==="failed"?r.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-center typography-ui text-muted-foreground",children:f("filesView.artifact.font.loadFailed")}):v==="loading"?r.jsxs("div",{className:"flex items-center gap-2 p-3 typography-ui text-muted-foreground",children:[r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),f("common.loading")]}):r.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-4",style:{fontFamily:`"${x}"`},children:r.jsxs("div",{className:"flex flex-col gap-4",children:[Sc.map(S=>r.jsxs("div",{className:"flex items-baseline gap-3",children:[r.jsx("span",{className:"w-8 shrink-0 text-right font-sans typography-meta text-muted-foreground",children:S}),r.jsx("span",{className:"min-w-0 break-words leading-tight text-foreground",style:{fontSize:`${S}px`},children:f("filesView.artifact.font.sample")})]},S)),r.jsx("div",{className:"mt-2 flex flex-col gap-1 border-t border-border/40 pt-4 text-foreground",style:{fontSize:"20px"},children:Cc.map(Rc)})]})}),e[9]=x,e[10]=v,e[11]=f,e[12]=F):F=e[12];let N;return e[13]!==y||e[14]!==F?(N=r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[y,F]}),e[13]=y,e[14]=F,e[15]=N):N=e[15],N};function kc(){return Zr=Zr+1,`oc-font-preview-${Zr}`}function Rc(n){return r.jsx("div",{className:"break-all leading-relaxed",children:n},n)}const Tc=n=>{const e=Re.c(46),{src:s,name:a,sizeBytes:w}=n,{t:f}=st(),[v,d]=i.useState("fit"),[x,p]=i.useState(null);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{p(null),d("fit")},e[0]=m):m=e[0];let b;e[1]!==s?(b=[s],e[1]=s,e[2]=b):b=e[2],i.useEffect(m,b);let y;e[3]!==x?(y=ma(x),e[3]=x,e[4]=y):y=e[4];let F;e[5]!==w?(F=ks(w),e[5]=w,e[6]=F):F=e[6];let N;e[7]!==y||e[8]!==F?(N=[y,F],e[7]=y,e[8]=F,e[9]=N):N=e[9];const S=v==="fit";let g;e[10]!==f?(g=f("filesView.artifact.image.fitTitle"),e[10]=f,e[11]=g):g=e[11];let l;e[12]===Symbol.for("react.memo_cache_sentinel")?(l=()=>d("fit"),e[12]=l):l=e[12];let T;e[13]!==f?(T=f("filesView.artifact.image.fit"),e[13]=f,e[14]=T):T=e[14];let R;e[15]!==S||e[16]!==g||e[17]!==T?(R=r.jsx(I,{variant:"chip",size:"xs","aria-pressed":S,title:g,onClick:l,children:T}),e[15]=S,e[16]=g,e[17]=T,e[18]=R):R=e[18];const M=v==="actual";let D;e[19]!==f?(D=f("filesView.artifact.image.actualTitle"),e[19]=f,e[20]=D):D=e[20];let A;e[21]===Symbol.for("react.memo_cache_sentinel")?(A=()=>d("actual"),e[21]=A):A=e[21];let k;e[22]!==M||e[23]!==D?(k=r.jsx(I,{variant:"chip",size:"xs","aria-pressed":M,title:D,onClick:A,children:"1:1"}),e[22]=M,e[23]=D,e[24]=k):k=e[24];let V;e[25]!==R||e[26]!==k?(V=r.jsxs(r.Fragment,{children:[R,k]}),e[25]=R,e[26]=k,e[27]=V):V=e[27];let z;e[28]!==V||e[29]!==N?(z=r.jsx(Fs,{items:N,actions:V}),e[28]=V,e[29]=N,e[30]=z):z=e[30];const B=v==="fit"&&"flex items-center justify-center";let U;e[31]!==B?(U=W("min-h-0 flex-1 overflow-auto p-3",B),e[31]=B,e[32]=U):U=e[32];let Y;e[33]===Symbol.for("react.memo_cache_sentinel")?(Y=q=>{const Q=q.currentTarget;p({width:Q.naturalWidth,height:Q.naturalHeight})},e[33]=Y):Y=e[33];const te=v==="fit"?"max-h-full max-w-full object-contain":"max-w-none";let ee;e[34]!==te?(ee=W("rounded-md border border-border/30 bg-primary/10",te),e[34]=te,e[35]=ee):ee=e[35];let G;e[36]!==a||e[37]!==s||e[38]!==ee?(G=r.jsx("img",{src:s,alt:a,draggable:!1,onLoad:Y,className:ee},s),e[36]=a,e[37]=s,e[38]=ee,e[39]=G):G=e[39];let X;e[40]!==U||e[41]!==G?(X=r.jsx("div",{className:U,children:G}),e[40]=U,e[41]=G,e[42]=X):X=e[42];let J;return e[43]!==z||e[44]!==X?(J=r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[z,X]}),e[43]=z,e[44]=X,e[45]=J):J=e[45],J},Ec=n=>{const e=Re.c(24),{kind:s,src:a,name:w,sizeBytes:f,download:v}=n,{t:d}=st(),[x,p]=i.useState(null),[m,b]=i.useState(null),[y,F]=i.useState(!1);let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N=()=>{p(null),b(null),F(!1)},e[0]=N):N=e[0];let S;e[1]!==a?(S=[a],e[1]=a,e[2]=S):S=e[2],i.useEffect(N,S);let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g=V=>{const z=V.currentTarget;p(Number.isFinite(z.duration)?z.duration:null),z instanceof HTMLVideoElement&&b({width:z.videoWidth,height:z.videoHeight})},e[3]=g):g=e[3];const l=g;let T;e[4]!==x?(T=jc(x),e[4]=x,e[5]=T):T=e[5];let R;e[6]!==m?(R=ma(m),e[6]=m,e[7]=R):R=e[7];let M;e[8]!==f?(M=ks(f),e[8]=f,e[9]=M):M=e[9];let D;e[10]!==T||e[11]!==R||e[12]!==M?(D=r.jsx(Fs,{items:[T,R,M]}),e[10]=T,e[11]=R,e[12]=M,e[13]=D):D=e[13];let A;e[14]!==v||e[15]!==y||e[16]!==s||e[17]!==w||e[18]!==a||e[19]!==d?(A=y?r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",children:[r.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:d("filesView.artifact.media.unplayable")}),v]}):s==="video"?r.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center bg-[var(--surface-background)] p-3",children:r.jsx("video",{src:a,controls:!0,playsInline:!0,preload:"metadata",title:w,className:"max-h-full max-w-full rounded-md",onLoadedMetadata:l,onError:()=>F(!0)},a)}):r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4 p-6",children:[r.jsx("div",{className:"typography-ui-label truncate text-foreground",children:w}),r.jsx("audio",{src:a,controls:!0,preload:"metadata",title:w,className:"w-full max-w-lg",onLoadedMetadata:l,onError:()=>F(!0)},a)]}),e[14]=v,e[15]=y,e[16]=s,e[17]=w,e[18]=a,e[19]=d,e[20]=A):A=e[20];let k;return e[21]!==D||e[22]!==A?(k=r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[D,A]}),e[21]=D,e[22]=A,e[23]=k):k=e[23],k},Vc=2e3,Pc=n=>n.toLowerCase().endsWith(".tsv")?" ":",",Mc=(n,e,s=Vc)=>{const a=[];let w=0,f="",v=[],d=!1,x=!1;const p=()=>{v.push(f),f="",v.length===1&&v[0]===""&&!x||((w===0||a.length<=s)&&a.push(v),w+=1),v=[],x=!1},m=n.charCodeAt(0)===65279?n.slice(1):n;for(let S=0;S<m.length;S+=1){const g=m[S];if(d){g==='"'?m[S+1]==='"'?(f+='"',S+=1):d=!1:f+=g;continue}if(g==='"'){d=!0,x=!0;continue}if(g===e){v.push(f),f="",x=!0;continue}if(g===`
11
+ `||g==="\r"){g==="\r"&&m[S+1]===`
12
+ `&&(S+=1),p();continue}f+=g}(f.length>0||v.length>0||d)&&p();const b=a[0]??[],y=a.slice(1),F=a.reduce((S,g)=>Math.max(S,g.length),0),N=Math.max(0,w-1);return{header:b,rows:y,totalRows:N,columnCount:F,truncated:y.length<N}},Dc=n=>{const e=Re.c(29),{path:s,content:a,sizeBytes:w}=n,{t:f}=st();let v;e[0]!==a||e[1]!==s?(v=Mc(a,Pc(s)),e[0]=a,e[1]=s,e[2]=v):v=e[2];const d=v;let x;e[3]!==f||e[4]!==d.columnCount||e[5]!==d.totalRows?(x=d.totalRows===1?f("filesView.artifact.table.rowsSingle",{rows:d.totalRows,columns:d.columnCount}):f("filesView.artifact.table.rowsPlural",{rows:d.totalRows,columns:d.columnCount}),e[3]=f,e[4]=d.columnCount,e[5]=d.totalRows,e[6]=x):x=e[6];const p=x;let m;e[7]!==d.columnCount?(m=Array.from({length:d.columnCount},zc),e[7]=d.columnCount,e[8]=m):m=e[8];const b=m;let y;e[9]!==f||e[10]!==d.rows||e[11]!==d.totalRows||e[12]!==d.truncated?(y=d.truncated?f("filesView.artifact.table.truncated",{shown:d.rows.length,total:d.totalRows}):"",e[9]=f,e[10]=d.rows,e[11]=d.totalRows,e[12]=d.truncated,e[13]=y):y=e[13];let F;e[14]!==w?(F=ks(w),e[14]=w,e[15]=F):F=e[15];let N;e[16]!==p||e[17]!==y||e[18]!==F?(N=r.jsx(Fs,{items:[p,y,F]}),e[16]=p,e[17]=y,e[18]=F,e[19]=N):N=e[19];let S;e[20]!==b||e[21]!==f||e[22]!==d.columnCount||e[23]!==d.header||e[24]!==d.rows?(S=d.columnCount===0?r.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:f("filesView.artifact.table.empty")}):r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:r.jsxs("table",{className:"min-w-full border-separate border-spacing-0 font-mono typography-meta",children:[r.jsx("thead",{className:"sticky top-0 z-10 bg-[var(--surface-subtle)]",children:r.jsx("tr",{children:b.map(l=>r.jsx("th",{scope:"col",className:"whitespace-nowrap border-b border-r border-border/40 px-2 py-1 text-left font-medium text-foreground last:border-r-0",children:d.header[l]??""},l))})}),r.jsx("tbody",{children:d.rows.map((l,T)=>r.jsx("tr",{className:"odd:bg-[var(--surface-background)] even:bg-[var(--surface-subtle)]/40",children:b.map(R=>r.jsx("td",{className:"max-w-[32rem] truncate border-b border-r border-border/30 px-2 py-1 align-top text-foreground last:border-r-0",title:l[R]??"",children:l[R]??""},R))},T))})]})}),e[20]=b,e[21]=f,e[22]=d.columnCount,e[23]=d.header,e[24]=d.rows,e[25]=S):S=e[25];let g;return e[26]!==N||e[27]!==S?(g=r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[N,S]}),e[26]=N,e[27]=S,e[28]=g):g=e[28],g};function zc(n,e){return e}const Yr="data-oc-local-asset",Lc=25*1024*1024,Gi=n=>{const e=n.trim();return!e||e.startsWith("#")||e.startsWith("//")?!1:!/^[a-z][a-z\d+.-]*:/i.test(e)},Ac=n=>n.split(/[?#]/,1)[0]??"",Ic=n=>n.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").replace(/\s+/g,"-"),Oc=(n,e)=>{const s=ha(e.replace(/^#/,"")).toLowerCase();if(!s)return!1;for(const a of Array.from(n.querySelectorAll("h1, h2, h3, h4, h5, h6")))if(a.id===s||Ic(a.textContent??"")===s)return a.scrollIntoView({block:"start"}),!0;return!1},ha=n=>{try{return decodeURIComponent(n)}catch{return n}},Xi=({container:n,filePath:e,workspaceRoot:s,onOpenFile:a,enabled:w})=>{const f=i.useRef(a);f.current=a,i.useEffect(()=>{if(!w||!n||!e)return;const v=e.slice(0,e.lastIndexOf("/")+1)||"/",d=g=>Go(v,ha(Ac(g))),x=g=>({path:g,allowOutsideWorkspace:s&&Xo(g,s)?void 0:"true",directory:s||void 0});let p=!1;const m=tt(),b=new Map,y=g=>{const l=b.get(g);if(l)return l;const T=(async()=>{const R=await en("/api/fs/raw",{query:x(g),signal:AbortSignal.timeout(3e4)});if(!R.ok)throw new Error(`Image read failed (${R.status})`);const M=await R.blob();if(M.size>Lc)throw new Error("Image too large for preview");if(p||tt()!==m)throw new Error("Preview closed");return URL.createObjectURL(M)})();return b.set(g,T),T.catch(()=>b.delete(g)),T},F=()=>{for(const g of Array.from(n.querySelectorAll("img[src]"))){const l=g.getAttribute("src")??"";if(!Gi(l))continue;const T=d(l);g.setAttribute(Yr,T),y(T).then(R=>{p||g.getAttribute(Yr)!==T||g.getAttribute("src")!==R&&(g.src=R)}).catch(()=>{p||g.removeAttribute(Yr)})}},N=g=>{if(g.defaultPrevented||g.button!==0||g.metaKey||g.ctrlKey||g.shiftKey||g.altKey)return;const l=g.target;if(!(l instanceof Element))return;const T=l.closest("a[href]");if(!(T instanceof HTMLAnchorElement)||!n.contains(T))return;const R=T.getAttribute("href")??"";if(R.startsWith("#")){g.preventDefault(),g.stopPropagation(),Oc(n,R);return}Gi(R)&&(g.preventDefault(),g.stopPropagation(),f.current(d(R)))};F();const S=new MutationObserver(F);return S.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]}),n.addEventListener("click",N,!0),()=>{p=!0,S.disconnect(),n.removeEventListener("click",N,!0);for(const g of b.values())g.then(l=>URL.revokeObjectURL(l)).catch(()=>{})}},[n,w,e,s])},Bc=n=>{const e=Z(n);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const s=e.lastIndexOf("/");if(s<0)return e;if(s===0)return"/";const a=e.slice(0,s);return/^[A-Za-z]:$/.test(a)?`${a}/`:a},$c=n=>{const e=Re.c(8),{label:s,iconDataUrl:a}=n,[w,f]=i.useState(!1);let v;e[0]!==s?(v=s.trim().slice(0,1).toUpperCase()||"?",e[0]=s,e[1]=v):v=e[1];const d=v;if(a&&!w){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>f(!0),e[2]=m):m=e[2];let b;return e[3]!==a?(b=r.jsx("img",{src:a,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=a,e[4]=b):b=e[4],b}let x;e[5]===Symbol.for("react.memo_cache_sentinel")?(x=W("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=x):x=e[5];let p;return e[6]!==d?(p=r.jsx("span",{className:x,children:d}),e[6]=d,e[7]=p):p=e[7],p},_c=n=>n.slice().sort((e,s)=>e.type!==s.type?e.type==="directory"?-1:1:e.name.localeCompare(s.name)),Z=n=>{if(!n)return"";const e=n.replace(/\\/g,"/"),s=e.startsWith("//");let a=e.replace(/\/+/g,"/");s&&!a.startsWith("//")&&(a=`/${a}`);const w=a==="/",f=/^[A-Za-z]:\/$/.test(a);return!w&&!f&&(a=a.replace(/\/+$/,"")),a},Wc=n=>n.startsWith("/")||n.startsWith("//")||/^[A-Za-z]:\//.test(n),is=n=>/^[A-Za-z]:\//.test(n)?n.toLowerCase():n,Ss=(n,e)=>{const s=Z(e),a=Z(n);if(!s||!a)return!1;const w=is(s),f=is(a);return f===w||f.startsWith(`${w}/`)},Ji=(n,e)=>{const s=Z(e),a=Z(n);if(!Ss(a,s))return[];const f=a.slice(s.length).replace(/^\//,"").split("/"),v=[];let d=s;for(let x=0;x<f.length-1;x++)d=d?`${d}/${f[x]}`:f[x],v.push(d);return v},dr=(n,e)=>{if(!e)return"";const s=Z(e);if(!n||!Ss(s,n))return s;const a=s.slice(n.length);return a.startsWith("/")?a.slice(1):a},Uc=new Set(["node_modules"]),Kc=n=>{const e=Re.c(3),{status:s}=n;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={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]=a):a=e[0];const w=a[s];let f;return e[1]!==w?(f=r.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:w}}),e[1]=w,e[2]=f):f=e[2],f},Zi=n=>{const e=Re.c(11),{name:s}=n,a=i.useRef(null),w=i.useRef(null),[f,v]=i.useState(!1);let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{const y=a.current,F=w.current;if(!y||!F)return;const N=()=>{v(F.scrollWidth>y.clientWidth+1)};N();const S=new ResizeObserver(N);return S.observe(y),S.observe(F),()=>{S.disconnect()}},e[0]=d):d=e[0];let x;e[1]!==s?(x=[s],e[1]=s,e[2]=x):x=e[2],i.useLayoutEffect(d,x);let p;e[3]!==s?(p=r.jsx("span",{ref:w,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:s}),e[3]=s,e[4]=p):p=e[4];let m;e[5]!==s||e[6]!==f?(m=f?r.jsxs("span",{className:"open-file-name-marquee-track",children:[r.jsx("span",{className:"open-file-name-marquee-item",children:s}),r.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:s})]}):r.jsx("span",{className:"block min-w-0 truncate",children:s}),e[5]=s,e[6]=f,e[7]=m):m=e[7];let b;return e[8]!==p||e[9]!==m?(b=r.jsxs("span",{ref:a,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[p,m]}),e[8]=p,e[9]=m,e[10]=b):b=e[10],b},Hc=n=>Uc.has(n),qc=n=>{const e=Z(n);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Gc=n=>{const s=(n instanceof Error?n.message:String(n??"")).toLowerCase();return s.includes("is a directory")||s.includes("eisdir")},Yi=n=>{const s=(n instanceof Error?n.message:String(n??"")).toLowerCase();return s.includes("file not found")||s.includes("enoent")||s.includes("no such file")||s.includes("does not exist")},Xc=2e5,pa=(n,e)=>r.jsx(Ns,{filePath:n,extension:e}),Qr=n=>{if(!n)return!1;const e=n.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},Qi=n=>{if(!n)return!1;const e=n.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},cr=n=>{if(!n)return!1;const e=n.toLowerCase().split(".").pop();return e==="html"||e==="htm"},Jc=n=>{const e=Re.c(78),{node:s,root:a,isExpanded:w,isActive:f,isMobile:v,isBrowserClient:d,alwaysShowActions:x,status:p,badge:m,permissions:b,downloadFile:y,contextMenuPath:F,setContextMenuPath:N,rightClickMenuPath:S,setRightClickMenuPath:g,onSelect:l,onToggle:T,onRevealPath:R,onOpenDialog:M,canUpload:D,onPickFiles:A}=n,{t:k}=st(),V=s.type==="directory",{canRename:z,canCreateFile:B,canCreateFolder:U,canDelete:Y,canReveal:te}=b,ee=!V&&!!y,G=te&&!d,X=V&&D,J=z||B||U||X||Y||ee||G;let q;e[0]!==J||e[1]!==s.path||e[2]!==g?(q=Ue=>{J&&(Ue?.preventDefault(),g(s.path))},e[0]=J,e[1]=s.path,e[2]=g,e[3]=q):q=e[3];const Q=q;let _e;e[4]!==V||e[5]!==s||e[6]!==l||e[7]!==T?(_e=()=>{V?T(s.path):l(s)},e[4]=V,e[5]=s,e[6]=l,e[7]=T,e[8]=_e):_e=e[8];const ne=_e;let Te;e[9]!==s.path||e[10]!==N||e[11]!==g?(Te=Ue=>{Ue.stopPropagation(),g(null),N(s.path)},e[9]=s.path,e[10]=N,e[11]=g,e[12]=Te):Te=e[12];const De=Te;let ze;e[13]!==B||e[14]!==U||e[15]!==Y||e[16]!==z||e[17]!==G||e[18]!==X||e[19]!==y||e[20]!==d||e[21]!==V||e[22]!==s||e[23]!==M||e[24]!==A||e[25]!==R||e[26]!==a||e[27]!==k?(ze=Ue=>{const{Item:je,Separator:as}=Ue;return r.jsxs(r.Fragment,{children:[z&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),M("rename",s)},children:[r.jsx(E,{name:"edit",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.rename")]}),r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),fr(s.path).then(St=>{if(St.ok){re.success(k("sidebarFilesTree.toast.pathCopied"));return}re.error(k("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(E,{name:"file-copy",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.copyPath")]}),r.jsxs(je,{onClick:ce=>{ce.stopPropagation();const St=dr(a,s.path)||s.path;fr(St).then(At=>{if(At.ok){re.success(k("filesView.toast.relativePathCopied"));return}re.error(k("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(E,{name:"file-copy-2",className:"mr-2 size-4"})," ",k("filesView.tree.menu.copyRelativePath")]}),!V&&y&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),y(s.path).catch(St=>{console.error("Download failed:",St),re.error(k("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(E,{name:"download",className:"mr-2 size-4"})," ",k(d?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),G&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),R(s.path)},children:[r.jsx(E,{name:"folder-received",className:"mr-2 size-4"})," ",k(xl())]}),V&&(B||U||X)&&r.jsxs(r.Fragment,{children:[r.jsx(as,{}),B&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),M("createFile",s)},children:[r.jsx(E,{name:"file-add",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.newFile")]}),U&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),M("createFolder",s)},children:[r.jsx(E,{name:"folder-add",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.newFolder")]}),X&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),A(s.path)},children:[r.jsx(E,{name:"upload-2",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.uploadFiles")]})]}),Y&&r.jsxs(r.Fragment,{children:[r.jsx(as,{}),r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),M("delete",s)},className:"text-destructive focus:text-destructive",children:[r.jsx(E,{name:"delete-bin",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.delete")]})]})]})},e[13]=B,e[14]=U,e[15]=Y,e[16]=z,e[17]=G,e[18]=X,e[19]=y,e[20]=d,e[21]=V,e[22]=s,e[23]=M,e[24]=A,e[25]=R,e[26]=a,e[27]=k,e[28]=ze):ze=e[28];const K=ze,ie=S===s.path;let _;e[29]!==s.path||e[30]!==g?(_=Ue=>g(Ue?s.path:null),e[29]=s.path,e[30]=g,e[31]=_):_=e[31];const ae=v?void 0:Q;let fe;e[32]!==ae?(fe=r.jsx("div",{className:"group relative flex items-center",onContextMenu:ae}),e[32]=ae,e[33]=fe):fe=e[33];const me=v?void 0:Q,le=f?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let be;e[34]!==le?(be=W("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",le),e[34]=le,e[35]=be):be=e[35];let xe;e[36]!==V||e[37]!==w||e[38]!==s.extension||e[39]!==s.path?(xe=V?w?r.jsx(E,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):r.jsx(E,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):pa(s.path,s.extension),e[36]=V,e[37]=w,e[38]=s.extension,e[39]=s.path,e[40]=xe):xe=e[40];let he;e[41]!==s.name||e[42]!==s.path?(he=r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:s.path,children:s.name}),e[41]=s.name,e[42]=s.path,e[43]=he):he=e[43];let ve;e[44]!==V||e[45]!==p?(ve=!V&&p&&r.jsx(Kc,{status:p}),e[44]=V,e[45]=p,e[46]=ve):ve=e[46];let Ee;e[47]!==m||e[48]!==V?(Ee=V&&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[47]=m,e[48]=V,e[49]=Ee):Ee=e[49];let ye;e[50]!==ne||e[51]!==be||e[52]!==xe||e[53]!==he||e[54]!==ve||e[55]!==Ee||e[56]!==me?(ye=r.jsxs("button",{type:"button",onClick:ne,onContextMenu:me,className:be,children:[xe,he,ve,Ee]}),e[50]=ne,e[51]=be,e[52]=xe,e[53]=he,e[54]=ve,e[55]=Ee,e[56]=me,e[57]=ye):ye=e[57];let lt;e[58]!==x||e[59]!==F||e[60]!==De||e[61]!==J||e[62]!==v||e[63]!==s.path||e[64]!==K||e[65]!==N?(lt=J&&r.jsx("div",{className:W("absolute right-1 top-1/2 -translate-y-1/2",x?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:r.jsxs(tn,{open:F===s.path,onOpenChange:Ue=>N(Ue?s.path:null),children:[r.jsx(sn,{asChild:!0,children:r.jsx(I,{variant:"ghost",size:"icon",className:"size-6",onClick:De,children:r.jsx(E,{name:"more-2-fill",className:"size-4"})})}),r.jsx(rn,{align:"end",side:"bottom",onCloseAutoFocus:()=>N(null),children:K({Item:ur,Separator:gl})})]})}),e[58]=x,e[59]=F,e[60]=De,e[61]=J,e[62]=v,e[63]=s.path,e[64]=K,e[65]=N,e[66]=lt):lt=e[66];let We;e[67]!==ye||e[68]!==lt||e[69]!==fe?(We=r.jsxs(Sl,{render:fe,children:[ye,lt]}),e[67]=ye,e[68]=lt,e[69]=fe,e[70]=We):We=e[70];let ct;e[71]!==K?(ct=r.jsx(yl,{className:"min-w-[180px]",children:K({Item:Nl,Separator:jl})}),e[71]=K,e[72]=ct):ct=e[72];let Le;return e[73]!==We||e[74]!==ct||e[75]!==ie||e[76]!==_?(Le=r.jsxs(Cl,{open:ie,onOpenChange:_,children:[We,ct]}),e[73]=We,e[74]=ct,e[75]=ie,e[76]=_,e[77]=Le):Le=e[77],Le},Zc=n=>{const e=Re.c(83),{activeDialog:s,dialogData:a,dialogInputValue:w,onDialogInputChange:f,isDialogSubmitting:v,onDialogSubmit:d,onClose:x,inputRef:p}=n,{t:m}=st(),b=!!s;let y;e[0]!==x?(y=Q=>!Q&&x(),e[0]=x,e[1]=y):y=e[1];let F;e[2]!==s||e[3]!==m?(F=s==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=s,e[3]=m,e[4]=F):F=e[4];let N;e[5]!==s||e[6]!==m?(N=s==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=s,e[6]=m,e[7]=N):N=e[7];let S;e[8]!==s||e[9]!==m?(S=s==="rename"&&m("filesView.dialog.rename.title"),e[8]=s,e[9]=m,e[10]=S):S=e[10];let g;e[11]!==s||e[12]!==m?(g=s==="delete"&&m("filesView.dialog.delete.title"),e[11]=s,e[12]=m,e[13]=g):g=e[13];let l;e[14]!==F||e[15]!==N||e[16]!==S||e[17]!==g?(l=r.jsxs(aa,{children:[F,N,S,g]}),e[14]=F,e[15]=N,e[16]=S,e[17]=g,e[18]=l):l=e[18];let T;e[19]!==s||e[20]!==a?.path||e[21]!==m?(T=s==="createFile"&&m("filesView.dialog.createFile.description",{path:a?.path??m("filesView.dialog.rootFallback")}),e[19]=s,e[20]=a?.path,e[21]=m,e[22]=T):T=e[22];let R;e[23]!==s||e[24]!==a?.path||e[25]!==m?(R=s==="createFolder"&&m("filesView.dialog.createFolder.description",{path:a?.path??m("filesView.dialog.rootFallback")}),e[23]=s,e[24]=a?.path,e[25]=m,e[26]=R):R=e[26];let M;e[27]!==s||e[28]!==a?.name||e[29]!==m?(M=s==="rename"&&m("filesView.dialog.rename.description",{name:a?.name??""}),e[27]=s,e[28]=a?.name,e[29]=m,e[30]=M):M=e[30];let D;e[31]!==s||e[32]!==a?.name||e[33]!==m?(D=s==="delete"&&m("filesView.dialog.delete.description",{name:a?.name??""}),e[31]=s,e[32]=a?.name,e[33]=m,e[34]=D):D=e[34];let A;e[35]!==M||e[36]!==D||e[37]!==T||e[38]!==R?(A=r.jsxs(oa,{children:[T,R,M,D]}),e[35]=M,e[36]=D,e[37]=T,e[38]=R,e[39]=A):A=e[39];let k;e[40]!==A||e[41]!==l?(k=r.jsxs(ia,{children:[l,A]}),e[40]=A,e[41]=l,e[42]=k):k=e[42];let V;e[43]!==s||e[44]!==w||e[45]!==p||e[46]!==f||e[47]!==d||e[48]!==m?(V=s!=="delete"&&r.jsx("div",{className:"py-4",children:r.jsx(Cs,{value:w,onChange:Q=>f(Q.target.value),placeholder:m(s==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:Q=>{Q.key==="Enter"&&d()},ref:p})}),e[43]=s,e[44]=w,e[45]=p,e[46]=f,e[47]=d,e[48]=m,e[49]=V):V=e[49];let z;e[50]!==m?(z=m("filesView.dialog.cancel"),e[50]=m,e[51]=z):z=e[51];let B;e[52]!==v||e[53]!==x||e[54]!==z?(B=r.jsx(I,{variant:"outline",onClick:x,disabled:v,children:z}),e[52]=v,e[53]=x,e[54]=z,e[55]=B):B=e[55];const U=s==="delete"?"destructive":"default";let Y;e[56]!==d?(Y=()=>{d()},e[56]=d,e[57]=Y):Y=e[57];let te;e[58]!==s||e[59]!==w||e[60]!==v?(te=v||s!=="delete"&&!w.trim(),e[58]=s,e[59]=w,e[60]=v,e[61]=te):te=e[61];let ee;e[62]!==s||e[63]!==v||e[64]!==m?(ee=v?r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):m(s==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=s,e[63]=v,e[64]=m,e[65]=ee):ee=e[65];let G;e[66]!==U||e[67]!==Y||e[68]!==te||e[69]!==ee?(G=r.jsx(I,{variant:U,onClick:Y,disabled:te,children:ee}),e[66]=U,e[67]=Y,e[68]=te,e[69]=ee,e[70]=G):G=e[70];let X;e[71]!==B||e[72]!==G?(X=r.jsxs(la,{children:[B,G]}),e[71]=B,e[72]=G,e[73]=X):X=e[73];let J;e[74]!==p||e[75]!==k||e[76]!==V||e[77]!==X?(J=r.jsxs(na,{initialFocus:p,children:[k,V,X]}),e[74]=p,e[75]=k,e[76]=V,e[77]=X,e[78]=J):J=e[78];let q;return e[79]!==b||e[80]!==y||e[81]!==J?(q=r.jsx(ra,{open:b,onOpenChange:y,children:J}),e[79]=b,e[80]=y,e[81]=J,e[82]=q):q=e[82],q},ns=new Map,Yc=100,ea=n=>{const e=Re.c(13);let s,a,w;e[0]!==n?({positionKey:a,onViewReady:s,...w}=n,e[0]=n,e[1]=s,e[2]=a,e[3]=w):(s=e[1],a=e[2],w=e[3]);const f=i.useRef(null);let v,d;e[4]!==a?(v=()=>()=>{const m=f.current;if(!m)return;const{anchor:b,head:y}=m.state.selection.main;if(ns.delete(a),ns.set(a,{scroll:m.scrollSnapshot(),anchor:b,head:y}),ns.size>Yc){const F=ns.keys().next().value;F!==void 0&&ns.delete(F)}},d=[a],e[4]=a,e[5]=v,e[6]=d):(v=e[5],d=e[6]),i.useLayoutEffect(v,d);let x;e[7]!==s||e[8]!==a?(x=m=>{f.current=m;const b=ns.get(a);b&&m.dispatch({selection:{anchor:Math.min(b.anchor,m.state.doc.length),head:Math.min(b.head,m.state.doc.length)},effects:b.scroll}),s?.(m)},e[7]=s,e[8]=a,e[9]=x):x=e[9];let p;return e[10]!==w||e[11]!==x?(p=r.jsx(kl,{...w,onViewReady:x}),e[10]=w,e[11]=x,e[12]=p):p=e[12],p},ta=(n,e,s)=>{const a=Re.c(8),[w,f]=i.useState(""),[v,d]=i.useState(0);let x,p;a[0]!==n||a[1]!==s||a[2]!==e?(x=()=>{if(!n){f("");return}let b=!1;f("");const y=Bo(),F=$o(y);_o(y).then(S=>{b||!S||(f(n),e(null))}).catch(S=>{b||(e(S instanceof Error?S.message:s),f(n))});const N=Wo(()=>{b||(f(n),d(Qc),e(null))});return()=>{b=!0,F(),N()}},p=[n,e,s],a[0]=n,a[1]=s,a[2]=e,a[3]=x,a[4]=p):(x=a[3],p=a[4]),i.useEffect(x,p);let m;return a[5]!==v||a[6]!==w?(m={readyKey:w,nonce:v},a[5]=v,a[6]=w,a[7]=m):m=a[7],m},jf=({mode:n="full",visible:e=!0})=>{const{t:s}=st(),{files:a,runtime:w}=Jo(),{currentTheme:f,availableThemes:v,lightThemeId:d,darkThemeId:x}=Zo(),{isMobile:p,isTablet:m,screenWidth:b}=Yo(),y=Mo(w.platform),F=p||m,N=Do(),S=zo(),g=sa()??"",l=Z(g.trim()),T=p||n==="full",R=T&&e,M=Qo(t=>t.runtimeKey),D=JSON.stringify([M,l]),A=i.useRef(D);A.current=D;const k=JSON.stringify([M,l,N,S]),V=i.useRef(k);V.current=k;const z=n!=="editor-only",B=n==="editor-only"&&!p,U=Lo(t=>t.searchFiles),Y=el(R?g:null),[te,ee]=i.useState(""),G=tl(te,200),X=i.useRef(null),[J,q]=i.useState(!1),[Q,_e]=i.useState(!0),[ne,Te]=i.useState(!1),[De,ze]=i.useState(!1),K=i.useRef(0),ie=i.useCallback(t=>{K.current=Math.max(0,K.current+(t?1:-1))},[]),[_,ae]=i.useState("edit"),[fe,me]=i.useState("edit"),[le,be]=i.useState("tree"),[xe,he]=i.useState("edit"),[ve,Ee]=i.useState("preview"),[ye,lt]=i.useState("preview"),[We,ct]=i.useState("preview"),[Le,Ue]=i.useState("table"),[je,as]=i.useState(null),[ce,St]=i.useState(0),At=i.useRef({}),hr=i.useRef({}),pr=i.useRef({}),nn=i.useRef({}),an=i.useRef({}),on=i.useRef({}),gr=i.useRef({}),Rs=i.useMemo(()=>v.find(t=>t.metadata.id===d)??Di(!1),[v,d]),Ts=i.useMemo(()=>v.find(t=>t.metadata.id===x)??Di(!0),[v,x]);i.useEffect(()=>{$i(Rs),$i(Ts)},[Rs,Ts]);const Es=i.useMemo(()=>[],[]),Ne=et(t=>l?t.byRoot[l]?.openPaths??Es:Es),Ct=et(t=>l?t.byRoot[l]?.selectedPath??null:null),rt=et(t=>l?t.byRoot[l]?.expandedPaths??Es:Es),ga=i.useMemo(()=>new Set(rt),[rt]),It=et(t=>t.removeOpenPath),pt=et(t=>t.removeOpenPathsByPrefix),ln=et(t=>t.removeExpandedPathsByPrefix),Se=et(t=>t.setSelectedPath),cn=et(t=>t.toggleExpandedPath),Vs=et(t=>t.expandPaths),Ot=i.useCallback(t=>{const o=Z(t),u=o.split("/"),h=u[u.length-1]||o,j=h.includes(".")?h.split(".").pop()?.toLowerCase():void 0;return{name:h,path:o,type:"file",extension:j}},[]),Bt=i.useMemo(()=>Ne.map(Ot),[Ne,Ot]),xr=i.useMemo(()=>{if(Ct){const t=is(Ct);if(Ne.some(o=>is(o)===t))return Ct}return Ne[0]??null},[Ne,Ct]),c=i.useMemo(()=>xr?Ot(xr):null,[xr,Ot]),nt=c?.path??"";i.useEffect(()=>{if(!l||!Ct)return;const t=is(Ct);Ne.some(u=>is(u)===t)||Se(l,Ne[0]??null)},[Ne,l,Ct,Se]);const vr=!!(l&&nt&&!Ss(nt,l)),wr=i.useMemo(()=>({allowOutsideWorkspace:vr,directory:l||void 0}),[vr,l]),gt=i.useCallback(t=>({allowOutsideWorkspace:!!(l&&!Ss(t,l))}),[l]),br=i.useRef(null),[un,xa]=i.useState({left:!1,right:!1}),dn=i.useCallback(()=>{const t=br.current;t&&xa({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),fn=i.useRef(dn);fn.current=dn,i.useEffect(()=>{const t=br.current;if(!t)return;const o=()=>fn.current();o(),t.addEventListener("scroll",o,{passive:!0});const u=new ResizeObserver(o);return u.observe(t),()=>{t.removeEventListener("scroll",o),u.disconnect()}},[Bt.length]);const[mn,yr]=i.useState({}),[Ps,os]=i.useState({}),Ke=i.useRef(new Set),Ve=i.useMemo(()=>new Al,[]);i.useEffect(()=>()=>Ve.clear(),[Ve]);const[hn,Ms]=i.useState([]),[va,Ds]=i.useState(!1),[$,pe]=i.useState(""),{isPlaying:zs,play:wa,stop:ba}=sl(),[Ce,xt]=i.useState(!1),[Je,we]=i.useState(null),[ya,He]=i.useState(""),[ge,ue]=i.useState(null),vt=JSON.stringify([tt(),l,ge]),[se,Fe]=i.useState(""),[ls,jr]=i.useState(!1),[pn,ja]=i.useState(`
13
+ `),Na=i.useRef(null),it=i.useRef(null),Ae=i.useRef(null),wt=i.useRef(""),cs=i.useRef(""),ut=i.useRef(null),gn=i.useRef(null),Ze=i.useRef(null),Nr=i.useRef(""),Sr=i.useRef(0),$t=i.useRef(0),Ft=i.useRef(null),[us,Sa]=i.useState(0),[Ca,_t]=i.useState("idle"),[Fa,Ls]=i.useState(!1),[kt,xn]=i.useState(!1),ke=mt(t=>t.autoSaveEnabled),ka=mt(t=>t.setAutoSaveEnabled),[Cr,ds]=i.useState(!1),Wt=i.useRef(null),fs=i.useRef(null),ms=i.useRef(!1),hs=i.useRef(null),ps=i.useRef(null),qe=i.useRef(null),As=i.useRef(null),[Ra,Fr]=i.useState(0),Ut=i.useRef(null),Rt=i.useRef({key:"",attempts:0});i.useEffect(()=>()=>{Ut.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Ut.current),Ut.current=null)},[]);const[Tt,kr]=i.useState(null),[Et,Ta]=i.useState(null),[bt,vn]=i.useState(""),[Ea,Rr]=i.useState(!1),[Va,Pa]=i.useState(null),[Ma,Da]=i.useState(null),[za,wn]=i.useState(!1),[La,bn]=i.useState(!1),[Aa,Tr]=i.useState(!1),[yn,Is]=i.useState(!1),[jn,Nn]=i.useState(0),Os=i.useRef(null),Bs=i.useCallback(t=>{const o=t?.currentTarget??Os.current;if(!o)return;const u=document.activeElement;u&&u!==document.body&&u!==o&&(rl(u)||o.contains(u))||o.focus({preventScroll:!0})},[]),$s=i.useRef(null),Sn=!!a.writeFile,Cn=!!a.createDirectory,Fn=!!a.rename,kn=!!a.delete,Rn=!!a.revealPath,Ia=or(t=>t.availableApps),Oa=or(t=>t.isCacheStale),Tn=or(t=>t.initialize),Ba=or(t=>t.loadInstalledApps);i.useEffect(()=>{Tn()},[Tn]);const $a=i.useCallback(t=>{a.revealPath&&a.revealPath(t).catch(()=>{re.error(s("sidebarFilesTree.toast.revealFailed"))})},[a,s]),_a=i.useCallback(async t=>{if(!c?.path||await Ao(c.path,t.id,t.appName)||await Vi(c.path,t.appName))return;const h=Bc(c.path)||l;h&&await Vi(h,t.appName)||re.error(s("filesView.toast.openInAppFailed",{app:t.appName}))},[l,c?.path,s]),Er=i.useCallback((t,o)=>{kr(t),Ta(o),vn(t==="rename"&&o.name||""),Rr(!1)},[]),[H,Ye]=i.useState(null),Kt=i.useRef(!1),yt=i.useRef(null),[En,Ht]=i.useState(!1),at=mt(t=>t.pendingFileNavigation),_s=mt(t=>t.setPendingFileNavigation),Vr=mt(t=>t.pendingFileFocusPath),Pr=mt(t=>t.setPendingFileFocusPath),Vn=mt(t=>t.fileEditorKeymap),gs=zi(t=>t.settingsDefaultFileViewerPreview),Wa=zi(t=>t.showMessageTTSButtons);i.useEffect(()=>{const t=()=>{Kt.current=!1,yt.current=null,Ht(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),i.useEffect(()=>()=>{hs.current!==null&&window.clearTimeout(hs.current),ps.current!==null&&window.clearTimeout(ps.current)},[]);const Ua=i.useCallback((t,o)=>{const u=t.split(`
14
+ `),h=Math.max(1,o.start),j=Math.min(u.length,o.end);return h>j?"":u.slice(h-1,j).join(`
15
+ `)},[]),Pn=i.useRef(null),Ka=_l({source:"file",fileLabel:c?.path??null,language:c?.path&&Kr(c.path)||"text",getCodeForRange:t=>Ua($,Wl(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Mn,commentText:Ws,setCommentText:Dn,editingDraftId:Us,setSelection:zn,saveComment:Ln,cancel:xs,reset:An,startEdit:In,deleteDraft:On}=Ka;i.useEffect(()=>{Ye(null),An(),Fe(""),jr(!1)},[c?.path,An]),i.useEffect(()=>{zn(H)},[H,zn]),i.useEffect(()=>{if(!H&&!Us)return;const t=u=>{const h=u.target;h.closest('[data-comment-input="true"]')||h.closest('[data-comment-card="true"]')||h.closest(".cm-gutterElement")||h.closest("[data-sonner-toast]")||h.closest("[data-sonner-toaster]")||Ws.trim()||(Ye(null),xs())},o=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(o),document.removeEventListener("click",t)}},[xs,Ws,Us,H]),i.useEffect(()=>{if(!p||!H)return;const t=qe.current;if(!t)return;const o=t.state.selection.main;o.empty||t.dispatch({selection:{anchor:o.head}});const u=document.getSelection();u&&!u.isCollapsed&&u.anchorNode&&t.contentDOM.contains(u.anchorNode)&&u.removeAllRanges()},[p,H]);const Bn=i.useCallback((t,o)=>{const u=o??H??void 0;o&&Ye(o),Ln(t,u),Ye(null)},[H,Ln]),$n=i.useCallback((t,o)=>{const u=[];for(const h of o){if(!(h&&typeof h.name=="string"&&h.name.length>0)||!N&&h.name.startsWith(".")||!S&&Hc(h.name))continue;const j=h.name,C=Z(h.path||""),P=C?Wc(C)?C:Z(`${t}/${C}`):Z(`${t}/${j}`),O=h.isDirectory?"directory":"file",de=O==="file"&&j.includes(".")?j.split(".").pop()?.toLowerCase():void 0;u.push({name:j,path:P,type:O,extension:de})}return _c(u)},[S,N]),Pe=i.useCallback(async(t,o=!1)=>{if(!R)return;const u=Z(t.trim());if(!u||!o&&Ke.current.has(u))return;const h=V.current,j=tt();return Ve.run(u,async C=>{const P=()=>C()&&V.current===h&&tt()===j;try{const O=a.listDirectory?(await a.listDirectory(u)).entries:await Io.listLocalDirectory(u);if(!P())return;const de=$n(u,O);Ke.current=new Set(Ke.current),Ke.current.add(u),os(L=>{if(!L[u])return L;const oe={...L};return delete oe[u],oe}),yr(L=>L[u]&&Il(L[u],de)?L:{...L,[u]:de})}catch(O){if(!P())return;const de=O instanceof Error?O.message:String(O??"");if(de==="Directory not found"&&l&&u!==l){ln(l,u),os(L=>{if(!L[u])return L;const oe={...L};return delete oe[u],oe});return}console.error("Failed to load files directory:",O),os(L=>({...L,[u]:de}))}},o)},[Ve,a,$n,ln,l,R]),Ks=i.useCallback(async()=>{l&&(Ke.current=new Set,Ve.clear(),os({}),yr(t=>Object.keys(t).length===0?t:{}),await Pe(l))},[Ve,Pe,l]),Ie=i.useCallback(async t=>{if(!t){await Ks();return}const o=Z(t);Ke.current=new Set(Ke.current),Ke.current.delete(o),await Pe(o,!0)},[Pe,Ks]),{canUpload:_n,uploadingDirectory:Ha,pickFiles:Wn,uploadElements:qa}=vl({root:l,refreshDirectory:Ie}),Hs=Ha!==null,Un=i.useRef(""),Kn=i.useRef("");i.useEffect(()=>{if(!l)return;const t=k,o=Un.current!==D,u=Kn.current!==t;!o&&!u||(o&&(Un.current=D,$t.current+=1,Ft.current=null,pe(""),we(null),He(""),ue(null),q(!1)),u&&(Kn.current=t,Ke.current=new Set,Ve.clear(),os({}),yr(h=>Object.keys(h).length===0?h:{}),Pe(l)))},[Ve,D,Pe,l,k]),i.useEffect(()=>{if(!R||!a.listDirectory)return;const t=()=>{if(!document.hidden&&rt.length>0)for(const o of rt)Ve.has(o)||Ie(o)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[Ve,rt,a.listDirectory,Ie,R]);const Hn=i.useRef(!1);i.useEffect(()=>{const t=R&&!Hn.current;if(Hn.current=R,!(!R||!l)&&(Pe(l),t))for(const o of rt)Ve.has(o)||Ie(o)},[Ve,rt,Pe,Ie,l,R]),i.useEffect(()=>{if(!R||!a.listDirectory||rt.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const o of rt)Ve.has(o)||Ie(o)},8e3);return()=>clearInterval(t)},[Ve,rt,a.listDirectory,Ie,R]);const Ga=i.useCallback(async t=>{if(t?.preventDefault(),!Et||!Tt)return;Rr(!0);const o=()=>{kr(null)},u=j=>{re.error(j)},h=()=>{Rr(!1)};if(Tt==="createFile"){if(!bt.trim()){u(s("sidebarFilesTree.toast.filenameRequired")),h();return}if(!a.writeFile){u(s("sidebarFilesTree.toast.writeNotSupported")),h();return}const j=Et.path,C=j?`${j}/`:"",P=Z(`${C}${bt.trim()}`);await a.writeFile(P,"").then(async O=>{O.success&&(re.success(s("sidebarFilesTree.toast.fileCreated")),await Ie(j)),o()}).catch(()=>u(s("sidebarFilesTree.toast.operationFailed"))).finally(h);return}if(Tt==="createFolder"){if(!bt.trim()){u(s("sidebarFilesTree.toast.folderNameRequired")),h();return}const j=Et.path,C=j?`${j}/`:"",P=Z(`${C}${bt.trim()}`);await a.createDirectory(P).then(async O=>{O.success&&(re.success(s("sidebarFilesTree.toast.folderCreated")),await Ie(j)),o()}).catch(()=>u(s("sidebarFilesTree.toast.operationFailed"))).finally(h);return}if(Tt==="rename"){if(!bt.trim()){u(s("sidebarFilesTree.toast.nameRequired")),h();return}if(!a.rename){u(s("sidebarFilesTree.toast.renameNotSupported")),h();return}const j=Et.path,C=j.split("/").slice(0,-1).join("/"),P=C?`${C}/`:"",O=Z(`${P}${bt.trim()}`);await a.rename(j,O).then(async de=>{de.success&&(re.success(s("sidebarFilesTree.toast.renamedSuccessfully")),await Ie(C),l&&pt(l,j),(c?.path===j||c?.path.startsWith(`${j}/`))&&(l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1))),o()}).catch(()=>u(s("sidebarFilesTree.toast.operationFailed"))).finally(h);return}if(Tt==="delete"){if(!a.delete){u(s("sidebarFilesTree.toast.deleteNotSupported")),h();return}const j=Et.path,C=j.split("/").slice(0,-1).join("/");await a.delete(j).then(async P=>{P.success&&(re.success(s("sidebarFilesTree.toast.deletedSuccessfully")),await Ie(C),l&&pt(l,j),(c?.path===j||c?.path.startsWith(`${j}/`))&&(l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1))),o()}).catch(()=>u(s("sidebarFilesTree.toast.operationFailed"))).finally(h);return}h()},[Tt,Et,bt,a,Ie,p,pt,l,c?.path,Se,s]);i.useEffect(()=>{if(!g){Ms([]),Ds(!1);return}const t=G.trim();if(!t){Ms([]),Ds(!1);return}let o=!1;return Ds(!0),U(g,t,150,{includeHidden:N,respectGitignore:!S,type:"file"}).then(u=>{if(o)return;const j=u.filter(C=>S||!qc(C.path)).map(C=>({name:C.name,path:Z(C.path),type:"file",extension:C.extension,relativePath:C.relativePath}));Ms(j)}).catch(()=>{o||Ms([])}).finally(()=>{o||Ds(!1)}),()=>{o=!0}},[g,G,U,N,S]);const qs=i.useCallback(async(t,o)=>{const u=gt(t);if(a.readFile)return(await a.readFile(t,{...u,directory:l||void 0,...o})).content??"";const h=new URLSearchParams({path:t});u.allowOutsideWorkspace&&h.set("allowOutsideWorkspace","true"),l&&h.set("directory",l);const j=await en(`/api/fs/read?${h.toString()}`,{cache:o?.fresh?"no-store":"default",signal:AbortSignal.timeout(3e4)});if(!j.ok){const C=await j.json().catch(()=>({error:j.statusText}));throw new Error(C.error||s("filesView.error.readFileFailed"))}return j.text()},[a,gt,l,s]),ot=i.useCallback(async t=>{if(a.statFile){const o=gt(t),u=await a.statFile(t,{...o,directory:l||void 0});return{path:u.path,size:u.size,mtimeMs:u.mtimeMs}}return null},[a,gt,l]);i.useEffect(()=>{if(!l||!a.statFile||Ne.length===0)return;let t=!1;const o=[...Ne];return Promise.all(o.map(async u=>{try{const h=gt(u),j=await a.statFile?.(u,{...h,directory:l||void 0});!t&&j&&!j.isFile&&pt(l,u)}catch(h){!t&&Yi(h)&&pt(l,u)}})),()=>{t=!0}},[a,Ne,pt,gt,l]);const Oe=se!==$,qt=i.useCallback(async()=>{if(!c||!a.writeFile)return re.error(s("filesView.toast.savingNotSupported")),!1;const t=bs(c.path)||kt;if(!mc({selectedFilePath:c.path,loadedFilePath:ge,fileLoading:Ce,isDirty:Oe,draftContent:se,fileContent:$,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):se===""&&$!==""&&ge!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${$.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(!Oe)return!0;jr(!0);try{const o=gc(se,pn);if(!(await a.writeFile(c.path,o))?.success)return re.error(s("filesView.toast.writeFileFailed")),!1;if(pe(se),Nr.current=o,Sr.current+=1,l&&Ss(c.path,l)){const h=dr(l,c.path);h&&nl.requestGitRefresh({directory:l,paths:[h]})}if(l&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(Z(c.path))){const h=il.getState().projects.find(j=>Z(j.path)===Z(l));if(h)try{await Ol(h.id)}catch{re.error(s("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&ys(c.path)&&(wt.current=se,cs.current=se),ot(c.path).then(h=>{h&&(Ze.current=h)}).catch(()=>{}),!0}catch(o){return re.error(o instanceof Error?o.message:s("filesView.toast.saveFailed")),!1}finally{jr(!1)}},[kt,se,$,Ce,a,Oe,pn,ge,ot,l,c,s]);i.useEffect(()=>{ke||(_t("idle"),it.current&&(clearTimeout(it.current),it.current=null))},[ke]);const qn=1500;i.useEffect(()=>{const t=!!(c&&a.writeFile),o=!!(c?.path&&(bs(c.path)||kt));if(fc({autoSaveEnabled:ke,isDirty:Oe,canWrite:t,isSaving:ls,fileLoading:Ce,selectedFilePath:c?.path,loadedFilePath:ge,isNonEditableBinary:o}))return it.current=setTimeout(()=>{qt().then(u=>{u&&(_t("saved"),setTimeout(()=>_t("idle"),2e3))})},qn),()=>{it.current&&(clearTimeout(it.current),it.current=null)}},[ke,kt,se,Ce,Oe,ge,c,a.writeFile,ls,qt]),i.useEffect(()=>{_t("idle")},[c?.path]),al({save_file:t=>{if(!(t.target instanceof Node)||!As.current?.contains(t.target))return!1;it.current&&(clearTimeout(it.current),it.current=null),ls||qt().then(o=>{o&&(_t("saved"),setTimeout(()=>_t("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node))return!1;if(Xe&&$e()==="preview"){if(p||!(ne?$s.current:Os.current)?.contains(t.target))return!1;Is(!0),Nn(u=>u+1);return}if(!As.current?.contains(t.target))return!1;ze(!0)}});const Gt=i.useCallback(t=>{const{content:o,lineEnding:u}=pc(t);return Nr.current=t,Sr.current+=1,ja(u),pe(o),wt.current=o,cs.current=o,Fe(o),o},[]),Gn=i.useCallback(async t=>{const o=$t.current+1;$t.current=o;const u=tt(),h=A.current,j=()=>{if(!l||tt()!==u||A.current!==h)return!1;const L=et.getState().byRoot[l],oe=L?.selectedPath??L?.openPaths[0]??null;return $t.current===o&&oe===t.path};we(null),He(""),ue(null),xn(!1),xt(!0);const C=Hr(t.path),P=qr(t.path),O=Li(t.path),de=bs(t.path);if(p&&q(!0),w.isDesktop&&C&&!P){pe(""),Fe("");return}if(!w.isDesktop&&C&&!P){pe(""),Fe(""),ue(t.path),xt(!1);return}if(O){pe(""),Fe(""),ue(t.path),xt(!1);return}if(de){pe(""),Fe(""),ue(t.path),xt(!1);return}await qs(t.path).then(L=>{if(!j())return;if(Ai(L)){xn(!0),pe(""),Fe(""),ue(t.path);return}const oe=Gt(L),Vt=Qr(t.path)||cr(t.path)||Qi(t.path)||ys(t.path)||qr(t.path)||Ii(t.path)||Oi(t.path);ae(Vt?"edit":xc(oe,At.current[t.path])),ue(t.path),ot(t.path).then(ss=>{ss&&j()&&(Ze.current=ss)}).catch(()=>{})}).catch(L=>{if(j()){if(Gc(L)){if(xt(!1),l&&Se(l,null),we(null),pe(""),Fe(""),ue(null),Ze.current=null,te.trim().length>0&&ee(""),p&&q(!1),l){const Vt=[...Ji(t.path,l),t.path];Vt.length>0&&Vs(l,Vt);for(const ss of Vt)Ke.current.has(ss)||Pe(ss)}return}if(Yi(L)){l&&pt(l,t.path),pe(""),Fe(""),we(null),Ze.current=null,p&&q(!1);return}pe(""),Fe(""),we(L instanceof Error?L.message:s("filesView.error.readFileFailed")),Ze.current=null}}).finally(()=>{j()&&xt(!1)})},[Gt,Vs,p,Pe,qs,ot,pt,l,w.isDesktop,te,Se,s]),Gs=i.useCallback(async(t,o)=>{if(!e||!l)return;const u=Ji(t,l),h=o?[...u,t]:u;if(h.length>0&&Vs(l,h),!R)return;const j=h.map(C=>{if(!Ke.current.has(C))return Pe(C)}).filter(Boolean);await Promise.all(j)},[Vs,Pe,l,R,e]),Xn=i.useCallback((t,o)=>{const u=o.findIndex(h=>h.path===t);return u===-1||o.length<=1?null:o[u+1]??o[u-1]??null},[]),Me=i.useCallback(async t=>{if(ms.current)ms.current=!1;else if(Oe){ds(!0),Wt.current=t;return}l&&(Se(l,t.path),Gs(t.path,!1)),we(null),He(""),pe(""),wt.current="",cs.current="",Fe(""),ue(null),p&&q(!0)},[Gs,Oe,p,l,Se]);i.useEffect(()=>{c?.path&&Gs(c.path,!1)},[Gs,c?.path]),i.useEffect(()=>{if(!e)return;if(!c){$t.current+=1,Ft.current=null,xt(!1);return}if(ge===c.path||Ft.current===c.path)return;const t=c.path;Ft.current=t,Gn(c).finally(()=>{Ft.current===t&&(Ft.current=null)})},[us,Gn,ge,c,e]);const Xs=i.useRef(Oe);Xs.current=Oe,i.useEffect(()=>wl(({runtimeKey:t,paths:o})=>{const u=c?.path;t!==tt()||!u||Xs.current||!o.includes(Z(u))||($t.current+=1,Ft.current=null,Ze.current=null,He(""),we(null),ue(null),Sa(h=>h+1))}),[c?.path]),i.useEffect(()=>{if(!e||!c?.path||ge!==c.path)return;const t=c.path,o=tt(),u=A.current,h=()=>Xs.current||ys(t)&&wt.current!==cs.current,j=!bs(t)&&!Hr(t)&&!kt?oc({readContent:()=>qs(t,{fresh:!0}),getLoadedContent:()=>Nr.current,getLoadedRevision:()=>Sr.current,isDirty:h,applyContent:L=>{if(!(C||tt()!==o||A.current!==u)){if(Ai(L)){ue(null);return}Gt(L)}}}):null;let C=!1,P=!1;const O=()=>{document.hidden||P||(P=!0,ot(t).then(async L=>{if(C||tt()!==o||A.current!==u||!L)return;const oe=Ze.current;if(!oe||oe.path!==t){Ze.current=L;return}if(cc(oe,L)){if(j&&L.size<=Xc){await j.poll()&&!C&&(Ze.current=L);return}Xs.current||(Ze.current=L,ue(null))}}).catch(()=>{}).finally(()=>{P=!1}))};O();const de=window.setInterval(O,2e3);return()=>{C=!0,j?.dispose(),window.clearInterval(de)}},[Gt,kt,ge,qs,ot,c?.path,e]);const Xa=i.useCallback(()=>{const t=Wt.current,o=fs.current;if(Wt.current=null,fs.current=null,ms.current=!0,ds(!1),Fe($),o){l&&It(l,o),c?.path===o&&(t?Me(t):(l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1)));return}if(t){Me(t);return}},[$,Me,p,It,l,c?.path,Se]),Ja=i.useCallback(async()=>{const t=Wt.current,o=fs.current;if(!await qt()){ms.current=!1;return}if(Wt.current=null,fs.current=null,ms.current=!0,ds(!1),o){l&&It(l,o),c?.path===o&&(t?await Me(t):(l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1)));return}if(t){await Me(t);return}},[Me,p,It,l,qt,c?.path,Se]),Jn=i.useCallback(t=>{const o=c?.path===t,u=Xn(t,Bt);if(o&&Oe){ds(!0),Wt.current=u,fs.current=t;return}if(l&&It(l,t),!!o){if(u){Me(u);return}l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1)}},[Xn,Me,Oe,p,Bt,It,l,c?.path,Se]),Zn=i.useMemo(()=>new Set(Ne),[Ne]),Js=i.useMemo(()=>Bl(T?Y?.files??[]:[]),[Y?.files,T]),Za=i.useCallback(t=>{if(Zn.has(t))return"open";const o=t.startsWith(l+"/")?t.slice(l.length+1):t;return Js.statusByPath.get(o)??null},[Zn,Js,l]),Ya=i.useCallback(t=>{if(!Y?.files)return null;const o=t.startsWith(l+"/")?t.slice(l.length+1):t;return Js.badgeByDir.get(o)??null},[Y,Js,l]),Qa=i.useCallback(async t=>{const o=Z(t);l&&(cn(l,o),Ke.current.has(o)||await Pe(o))},[Pe,l,cn]),eo=i.useMemo(()=>({canRename:Fn,canCreateFile:Sn,canCreateFolder:Cn,canDelete:kn,canReveal:Rn}),[Fn,Sn,Cn,kn,Rn]);function Yn(t,o){const u=mn[t]??[];return u.map((h,j)=>{const C=h.type==="directory",P=C&&ga.has(h.path),O=c?.path===h.path,de=j===u.length-1;return r.jsxs("li",{className:"relative",children:[o>0&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),de&&r.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),r.jsx(Jc,{node:h,root:l,isExpanded:P,isActive:O,isMobile:p,isBrowserClient:y,alwaysShowActions:F,status:C?void 0:Za(h.path),badge:C?Ya(h.path):void 0,permissions:eo,downloadFile:a.downloadFile,contextMenuPath:Va,setContextMenuPath:Pa,rightClickMenuPath:Ma,setRightClickMenuPath:Da,onSelect:Me,onToggle:Qa,onRevealPath:$a,onOpenDialog:Er,canUpload:_n&&!Hs,onPickFiles:Wn}),C&&P&&r.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[Ps[h.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:Ps[h.path],children:Ps[h.path]}),r.jsxs(I,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ie(h.path)},children:[r.jsx(E,{name:"refresh",className:"size-3.5"}),s("filesView.tree.actions.refreshTitle")]})]}):null,Yn(h.path,o+1)]})]},h.path)})}const Be=!!(c?.path&&Hr(c.path)),Ge=!!(c?.path&&qr(c.path)),Qn=Ge&&ye==="edit",jt=!!(c?.path&&Li(c.path)),ei=!!(c?.path&&ol(c.path)),Mr=ei||!!(c?.path&&ll(c.path)),Dr=!!(c?.path&&cl(c.path)),Zs=!!(c?.path&&(bs(c.path)||kt)),Xt=Zs&&!Be&&!jt&&!Mr&&!Dr,ti=Zs||Be&&!Qn,si=i.useMemo(()=>Z(at?.path??""),[at?.path]),Jt=!!(at&&si&&nt&&nt===si&&!Ce&&!Je&&!ti),Nt=i.useMemo(()=>dr(l,nt),[nt,l]),to=!!(c&&(!Be||Ge)&&!jt&&!Xt&&$.length>0),so=!!(c&&Nt.length>0),Qe=!!(c&&!vr&&!Zs&&(!Be||Ge)&&a.writeFile),Xe=!!(c?.path&&Qr(c.path)),Zt=!!(c?.path&&Qi(c.path)),Yt=!!(c?.path&&cr(c.path)),vs=!!(c?.path&&ys(c.path)),Qt=!!(c?.path&&Ii(c.path)),es=!!(c?.path&&Oi(c.path)),Ys=!!(c&&!Zs&&(!Be||Ge))&&!Xe&&!vs&&!(Yt&&xe==="preview")&&!(Ge&&ye==="preview")&&!(Qt&&We==="preview")&&!(es&&Le==="table"),ro=Xe&&fe==="edit"||Yt&&xe==="edit"||Ge&&ye==="edit"||Qt&&We==="edit"||es&&Le==="text"||Zt&&le==="text"||!Xe&&!Yt&&!Zt&&!Ge&&!Qt&&!es&&_==="edit",Qs=i.useMemo(()=>nt?ul(nt):null,[nt]),[ri,zr]=i.useState(null);i.useEffect(()=>{let t=!1;const o=c?.path;if(!o||Qs){zr(null);return}return zr(null),dl(o).then(u=>{t||zr(u)}),()=>{t=!0}},[c?.path,Qs]),i.useEffect(()=>{!Qe&&_==="edit"&&ae("view")},[Qe,_]);const Lr="openchamber:files:md-viewer-mode",Ar="openchamber:files:html-viewer-mode",Ir="openchamber:files:json-viewer-mode";i.useEffect(()=>{const t=c?.path;if(!t)return;ae(At.current[t]??"edit");let o=gs?"preview":"edit";try{const j=localStorage.getItem(Lr);(j==="preview"||j==="edit")&&(o=j)}catch{}me(hr.current[t]??o);let u=gs?"preview":"edit";try{const j=localStorage.getItem(Ar);(j==="preview"||j==="edit")&&(u=j)}catch{}he(pr.current[t]??u),Ee(gr.current[t]??(gs?"preview":"edit")),lt(nn.current[t]??"preview"),ct(an.current[t]??"preview"),Ue(on.current[t]??"table");let h=gs?"tree":"text";try{const j=localStorage.getItem(Ir);(j==="tree"||j==="text")&&(h=j)}catch{}be(h)},[c?.path,gs]);const no=i.useCallback(t=>{const o=c?.path;o&&(At.current[o]=t),ae(t)},[c?.path]),io=i.useCallback(t=>{const o=c?.path;o&&(hr.current[o]=t),me(t);try{localStorage.setItem(Lr,t)}catch{}},[c?.path]),$e=i.useCallback(()=>fe,[fe]),ao=i.useCallback(t=>{const o=c?.path;o&&(nn.current[o]=t),lt(t)},[c?.path]),oo=i.useCallback(t=>{const o=c?.path;o&&(an.current[o]=t),ct(t)},[c?.path]),lo=i.useCallback(t=>{const o=c?.path;o&&(on.current[o]=t),Ue(t)},[c?.path]);i.useEffect(()=>{const t=c?.path;if(as(null),!t||ge!==t)return;let o=!1;return ot(t).then(u=>{!o&&u&&as(u.size)}).catch(()=>{}),()=>{o=!0}},[us,ge,ot,c?.path]);const ni=c&&Xe&&$e()==="preview"&&!Ce?c.path:null;i.useEffect(()=>{!ni||p||Bs()},[Bs,ne,p,ni]);const co=i.useCallback(t=>{be(t);try{localStorage.setItem(Ir,t)}catch{}},[]),uo=i.useCallback(t=>{const o=c?.path;o&&(pr.current[o]=t),he(t);try{localStorage.setItem(Ar,t)}catch{}},[c?.path]),fo=i.useCallback(t=>{const o=c?.path;if(o&&(gr.current[o]=t),Ae.current&&(clearTimeout(Ae.current),Ae.current=null),ut.current!==null&&(cancelAnimationFrame(ut.current),ut.current=null),t==="edit")Fe(wt.current||$),Ee(t);else{wt.current=se;const u=o;Ee("edit"),ut.current=requestAnimationFrame(()=>{ut.current=requestAnimationFrame(()=>{ut.current=null,!(l&&u&&et.getState().byRoot[l]?.selectedPath!==u)&&(St(h=>h+1),Ee("preview"))})});return}},[se,$,l,c?.path]),Or=i.useCallback(async(t,o)=>{if(!a.writeFile||o===cs.current)return!1;if(!(await a.writeFile(t,o))?.success)return re.error(s("filesView.toast.writeFileFailed")),!1;Gt(o);const h=await ot(t).catch(()=>null);return h&&(Ze.current=h),!0},[Gt,a,ot,s]);i.useEffect(()=>()=>{Ae.current&&(clearTimeout(Ae.current),Ae.current=null),ut.current!==null&&(cancelAnimationFrame(ut.current),ut.current=null)},[ve,c?.path]);const mo=i.useCallback(t=>{if(wt.current=t,!ke||!c?.path||ve!=="preview"||!a.writeFile)return;Ae.current&&clearTimeout(Ae.current);const o=c.path;Ae.current=setTimeout(()=>{Ae.current=null,Or(o,t).then(u=>{u&&(Ls(!0),setTimeout(()=>Ls(!1),1500))}).catch(u=>{re.error(u instanceof Error?u.message:s("filesView.toast.saveFailed"))})},qn)},[ke,ve,a.writeFile,Or,c?.path,s]),ho=i.useMemo(()=>vs&&(wt.current||se)||$,[se,$,vs]),ii=i.useCallback(()=>xe,[xe]);i.useEffect(()=>{const t=u=>{const h=u?"preview":"edit",j=u?"tree":"text";for(const C of Ne)At.current[C]="edit",Qr(C)&&(hr.current[C]=h),cr(C)&&(pr.current[C]=h),ys(C)&&(gr.current[C]=h);ae("edit"),me(h),he(h),Ee(h),be(j);try{localStorage.setItem(Lr,h),localStorage.setItem(Ar,h),localStorage.setItem(Ir,j)}catch{}},o=u=>{const h=!!u.detail?.enabled;t(h)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",o),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",o)}},[Ne]),i.useEffect(()=>{if(!at||!l)return;const t=()=>{typeof window>"u"||Ut.current===null&&(Ut.current=window.requestAnimationFrame(()=>{Ut.current=null,Fr(ft=>ft+1)}))},o=(ft,Pt)=>{if(ft.state.doc.length!==Pt.length)return!1;if(Pt.length===0)return!0;const Ur=Math.min(128,Pt.length);if(ft.state.sliceDoc(0,Ur)!==Pt.slice(0,Ur))return!1;const Ti=Math.max(0,Pt.length-Ur);return ft.state.sliceDoc(Ti,Pt.length)===Pt.slice(Ti)},u=Z(at.path);if(!u){_s(null),Rt.current={key:"",attempts:0};return}const h=`${u}:${at.line}:${at.column??1}`;if(Rt.current.key!==h&&(Rt.current={key:h,attempts:0}),c?.path!==u){if(Cr)return;Me(Ot(u));return}if(Ce||ge!==u)return;if(Je||Be||jt||Xt){_s(null),Rt.current={key:"",attempts:0};return}if(!Qe)return;if(_!=="edit"){ae("edit");return}const j=qe.current;if(!j){t();return}if(!o(j,se)){t();return}const C=Math.max(1,Math.min(at.line,j.state.doc.lines)),P=j.state.doc.line(C),O=Math.max(1,at.column||1),de=Math.max(0,P.to-P.from),L=Math.min(de,O-1),oe=P.from+L;if(!(j.state.selection.main.head===oe)||Rt.current.attempts===0){Rt.current.attempts+=1,j.dispatch({selection:{anchor:oe},effects:Lt.scrollIntoView(oe,{y:"center"})}),j.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const ft=qe.current;ft&&(ft.dispatch({selection:{anchor:oe},effects:Lt.scrollIntoView(oe,{y:"center"})}),ft.focus())}),_s(null),Rt.current={key:"",attempts:0}},[Qe,Cr,se,Ra,Je,Ce,Be,jt,Xt,ge,Me,at,l,c?.path,_s,_,Ot]),i.useEffect(()=>{if(!Vr||!l)return;const t=Z(Vr);if(!t){Pr(null);return}c?.path===t&&(Ce||ge!==t||(!Je&&!Be&&!jt&&!Xt&&Qe&&_==="edit"&&qe.current?.focus(),Pr(null)))},[Qe,Je,Ce,Be,jt,Xt,ge,Vr,l,c?.path,Pr,_]);const ts=i.useCallback(t=>{if(!p||!t||typeof window>"u")return;const o=document.activeElement,u=!t.hasFocus&&o instanceof HTMLElement&&t.dom.contains(o)?o.closest('[data-comment-input="true"]'):null;if(!t.hasFocus&&!u)return;const h=window.visualViewport;if(!h)return;const j=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,j-(h.offsetTop+h.height))<=0)return;const P=u?u.getBoundingClientRect():t.coordsAtPos(t.state.selection.main.head);if(!P)return;const O=Math.round(h.offsetTop+h.height),L=P.bottom+20-O;L<=0||(t.scrollDOM.scrollTop+=L)},[p]);i.useEffect(()=>{if(!p||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{ts(qe.current)})},o=window.visualViewport;return o?.addEventListener("resize",t),o?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{o?.removeEventListener("resize",t),o?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[p,ts]),fl("open_go_to_line",t=>{if(!Qe||_!=="edit"||p)return!1;const o=t.target;if(o?.closest('[role="dialog"]')||!(o instanceof Node)||!As.current?.contains(o))return!1;const u=!!o?.closest(".cm-editor");if(!!o?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!u)return!1;Tr(!0)});const er=mt(t=>t.editorFontSize),ai=i.useMemo(()=>{if(!c?.path)return[Bi(f,{fontSize:er})];const t=Kr(c.path),o=[Bi(f,t?{syntaxColors:!1,fontSize:er}:{fontSize:er})],u=Qs??ri;return u&&o.push(u),t&&o.push(Fl({language:t,themeName:f.metadata.id,theme:Pl(f)})),Q&&o.push(Lt.lineWrapping),p&&o.push(Lt.updateListener.of(h=>{h.view.hasFocus&&(h.selectionSet||h.focusChanged||h.viewportChanged||h.geometryChanged)&&window.requestAnimationFrame(()=>{ts(h.view)})})),o},[f,c?.path,Qs,ri,Q,p,ts,er]),oi=i.useMemo(()=>({light:Rs.metadata.id,dark:Ts.metadata.id}),[Rs.metadata.id,Ts.metadata.id]),li=jt||Mr||Dr,ws=c?.path&&li?`${c.path}|${wr.allowOutsideWorkspace?"outside":"workspace"}|${us}`:"",tr=c?.path&&Yt&&xe==="preview"&&!w.isVSCode?`${c.path}|${us}`:"",ci=s("filesView.error.readFileFailed"),{readyKey:ui,nonce:po}=ta(tr,we,ci),{readyKey:di,nonce:sr}=ta(ws,we,ci),go=!!(tr&&ui!==tr),Br=!!(ws&&di!==ws),xo=c?.path&&Be?Ge?`data:${ml(c.path)};utf8,${encodeURIComponent($)}`:ya:"",rr=c?.path&&li&&ws&&di===ws?Pi().authenticatedAsset(Oo("/api/fs/raw",l),{path:c.path,allowOutsideWorkspace:wr.allowOutsideWorkspace?"true":void 0,directory:l||void 0}):"",vo=i.useCallback(t=>r.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:r.jsx("iframe",{src:rr,className:"h-full w-full border-0",title:t.name},sr)}),[rr,sr]),fi=c&&a.downloadFile?r.jsxs(I,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=a.downloadFile;!t||!c||t(c.path).catch(o=>{console.error("Download failed:",o),re.error(s("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(E,{name:"download",className:"mr-2 size-4"}),s("filesView.editor.saveFile")]}):null,nr=c&&!Ce&&!Br&&!Je?(t=>Be&&!Qn?r.jsx(Tc,{src:xo,name:t.name,sizeBytes:je}):jt?vo(t):Mr?r.jsx(Ec,{kind:ei?"video":"audio",src:rr,name:t.name,sizeBytes:je,download:fi},sr):Dr?r.jsx(Fc,{src:rr,name:t.name,sizeBytes:je},sr):Xt?r.jsx(Nc,{name:t.name,path:t.path,sizeBytes:je,download:fi}):es&&Le==="table"?r.jsx(Dc,{path:t.path,content:$,sizeBytes:je}):Qt&&We==="preview"?r.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:r.jsx(ar,{fallback:r.jsxs("div",{className:"m-3 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:s("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:s("filesView.error.switchToEditMode")})]}),children:r.jsx(Xr,{content:`\`\`\`mermaid
16
+ ${$}
17
+ \`\`\``,className:"markdown-mermaid-fullscreen h-full",enableFileReferences:!1,allowMermaidWheelEvents:!0})})}):null)(c):null;i.useEffect(()=>{let t=!1,o="";return(async()=>{if(!c?.path||!Be||Ge){He("");return}we(null);const h=gt(c.path);if(t)return;await(a.readFileBinary?a.readFileBinary(c.path,h).then(C=>C.dataUrl):(async()=>{const C=await en("/api/fs/raw",{signal:AbortSignal.timeout(3e4),query:{path:c.path,allowOutsideWorkspace:h.allowOutsideWorkspace?"true":void 0,directory:l||void 0}});if(!C.ok)throw new Error(s("filesView.error.readFileFailed"));const P=await C.blob();return o=URL.createObjectURL(P),t?(URL.revokeObjectURL(o),o="",""):o})()).then(C=>{t||(He(C),ue(c.path))}).catch(C=>{t||(He(""),we(C instanceof Error?C.message:s("filesView.error.readFileFailed")),ue(null))}).finally(()=>{t||xt(!1)})})(),()=>{t=!0,o&&URL.revokeObjectURL(o)}},[us,a,Be,Ge,gt,l,c?.path,wr,s]);const wo=i.useCallback(()=>kr(null),[]),bo=i.useMemo(()=>Ul({drafts:Mn,editingDraftId:Us,commentText:Ws,onTextChange:Dn,selection:H,isDragging:En,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Bn,onCancel:()=>{Ye(null),xs()},onEdit:t=>{In(t),Ye({start:t.startLine,end:t.endLine})},onDelete:On}),[xs,Ws,On,Us,Mn,Bn,En,H,c?.path,Dn,In]),mi=Hi(),hi=Hi(),pi=!Ce&&!Je&&ge===nt,ir=pi&&Ys&&_==="view"&&!(Zt&&le==="tree"),gi=pi&&Xe&&$e()==="preview",{setScroller:xi,restore:yo}=lr(ir?`${vt}:code`:null),{setScroller:vi,restore:jo}=lr(ir?`${vt}:code:fullscreen`:null),{setScroller:wi}=lr(gi?`${vt}:markdown`:null),{setScroller:bi}=lr(gi?`${vt}:markdown:fullscreen`:null),{setScroller:yi}=mi,{setScroller:ji}=hi,No=i.useCallback(t=>{yi(t),xi(t)},[yi,xi]),So=i.useCallback(t=>{ji(t),vi(t)},[ji,vi]),[Co,Fo]=i.useState(null),[ko,Ro]=i.useState(null),To=i.useCallback(t=>{Pn.current=t,Os.current=t,Fo(t),wi(t)},[wi]),Eo=i.useCallback(t=>{$s.current=t,Ro(t),bi(t)},[bi]),Ni=i.useCallback(t=>{l&&mt.getState().openContextFile(l,t)},[l]),Si=Xe&&fe==="preview"&&!Ce;Xi({container:Co,filePath:c?.path??null,workspaceRoot:l||null,onOpenFile:Ni,enabled:Si}),Xi({container:ko,filePath:c?.path??null,workspaceRoot:l||null,onOpenFile:Ni,enabled:Si});const $r=bl("unified"),dt=se.length>da,_r=i.useMemo(()=>dt&&ir?vc(se):void 0,[ir,se,dt]),Ci=i.useCallback((t,o,u,h)=>{const j={name:t.name,contents:o,lang:Kr(t.path)||void 0},C=P=>r.jsx(Vl,{file:dt&&_r?{...j,cacheKey:`${t.path}:${_r}`}:j,options:{disableFileHeader:!0,overflow:Q?"wrap":"scroll",theme:oi,themeType:f.metadata.variant==="dark"?"dark":"light",onPostRender:h},className:dt?"block w-full":"block h-full w-full",style:dt?void 0:{height:"100%"}},P);return dt?r.jsx("div",{className:"h-full",children:r.jsx(Ml.Provider,{value:u.virtualizer,children:r.jsx(Dl.Provider,{value:$r,children:C(`${t.path}:${$r?"pool":"pending"}`)})})}):r.jsx("div",{className:"h-full",children:C(t.path)})},[f.metadata.variant,dt,_r,oi,$r,Q]),Fi=({exitFullscreenOnly:t=!1,layout:o="floating"}={})=>{if(!c)return null;const u=o==="docked",h=hl(pl("save_file")),j=u?"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",C=(P,O)=>r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:O})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:P})]});return r.jsxs("div",{className:j,children:[Qe&&ro&&r.jsxs(r.Fragment,{children:[ls?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[r.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"}),s("filesView.editor.saving")]}):ke&&Ca==="saved"&&!Oe?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[r.jsx(E,{name:"check",className:"size-3.5"}),s("filesView.editor.saved")]}):Oe?C(s(ke?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:h}),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{qt()},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:s(ke?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:h}),"aria-label":s("filesView.editor.saveAria",{shortcut:h}),children:r.jsx(E,{name:"save-3",className:"size-4"})})):null,C(s(ke?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>ka(!ke),className:W("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ke?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:s(ke?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":s(ke?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:ke?r.jsx(E,{name:"file-check-fill",className:"size-4"}):r.jsx(E,{name:"file-check",className:"size-4"})}))]}),r.jsxs(tn,{onOpenChange:ie,children:[r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:r.jsx(sn,{asChild:!0,children:r.jsx(I,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.openInDesktopApp"),"aria-label":s("filesView.editor.openInDesktopApp"),children:r.jsx(E,{name:"file-transfer",className:"size-4"})})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("filesView.editor.openInDesktopApp")})]}),r.jsxs(rn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ia.map(P=>r.jsxs(ur,{className:"flex items-center gap-2",onClick:()=>{_a(P)},children:[r.jsx($c,{label:P.label,iconDataUrl:P.iconDataUrl}),r.jsx("span",{className:"typography-ui-label text-foreground",children:P.label})]},P.id)),Oa?r.jsxs(ur,{className:"flex items-center gap-2",onClick:()=>{Ba(!0)},children:[r.jsx(E,{name:"refresh",className:"size-4"}),r.jsx("span",{className:"typography-ui-label text-foreground",children:s("filesView.editor.refreshApps")})]}):null]})]}),!ti&&r.jsxs(r.Fragment,{children:[C(s(Q?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>_e(!Q),className:W("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Q?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:s(Q?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:r.jsx(E,{name:"text-wrap",className:"size-4"})})),_==="edit"&&r.jsxs(r.Fragment,{children:[C(s("filesView.editor.findInFile"),r.jsx(I,{variant:"ghost",size:"sm",onClick:P=>{ze(!De),P.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.findInFile"),children:r.jsx(E,{name:"search",className:"size-4"})})),C(s("filesView.editor.goToLine"),r.jsx(I,{variant:"ghost",size:"sm",onClick:P=>{Tr(O=>!O),P.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.goToLine"),children:r.jsx(E,{name:"menu-fold-2",className:"size-4"})})),r.jsx(ec,{open:Aa,onOpenChange:Tr,view:qe.current,variant:"inline"})]})]}),Ys&&Qe&&!Zt&&!Yt&&!Ge&&!Qt&&!es&&r.jsx(js,{currentMode:_==="view"?"preview":"edit",onToggle:()=>{no(_==="view"?"edit":"view")}}),Xe&&C(s($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>io($e()==="preview"?"edit":"preview"),className:W("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",$e()==="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:s($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":s($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:r.jsx(E,{name:$e()==="preview"?"eye":"eye-off",className:"size-4"})})),cr(c?.path??"")&&r.jsx(js,{currentMode:ii(),onToggle:()=>{uo(ii()==="preview"?"edit":"preview")}}),Ge&&r.jsx(js,{currentMode:ye,onToggle:()=>ao(ye==="preview"?"edit":"preview")}),Qt&&r.jsx(js,{currentMode:We,onToggle:()=>oo(We==="preview"?"edit":"preview")}),es&&C(s(Le==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>lo(Le==="table"?"text":"table"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:s(Le==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),"aria-label":s(Le==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),children:Le==="table"?r.jsx(E,{name:"code-sslash",className:"size-4"}):r.jsx(E,{name:"table-2",className:"size-4"})})),Xe&&$e()==="preview"&&C(s("filesView.editor.findInFile"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{Is(!0),Nn(P=>P+1)},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.findInFile"),children:r.jsx(E,{name:"search",className:"size-4"})})),Xe&&$e()==="preview"&&Wa&&r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx(I,{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":s(zs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{zs?ba():$.trim()&&wa($)},children:zs?r.jsx(E,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(E,{name:"volume-up",className:"size-4"})})}),r.jsx(zt,{sideOffset:8,children:s(zs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),vs&&r.jsxs(r.Fragment,{children:[r.jsx(js,{currentMode:ve,onToggle:()=>fo(ve==="preview"?"edit":"preview")}),ve==="preview"&&r.jsx(I,{variant:"ghost",size:"sm",onClick:async()=>{const P=gn.current?.getXml();if(Ae.current&&(clearTimeout(Ae.current),Ae.current=null),c?.path&&P){if(!await Or(c.path,P))return;Ls(!0),setTimeout(()=>Ls(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.diagram.saveDiagram"),children:Fa?r.jsx(E,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(E,{name:"save-3",className:"size-4"})})]}),Zt&&C(s(le==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>co(le==="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:s(le==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:le==="tree"?r.jsx(E,{name:"code-sslash",className:"size-4"}):r.jsx(E,{name:"node-tree",className:"size-4"})})),to&&C(s("filesView.editor.copyFileContents"),r.jsx(I,{variant:"ghost",size:"sm",onClick:async()=>{(await fr($)).ok?(wn(!0),hs.current!==null&&window.clearTimeout(hs.current),hs.current=window.setTimeout(()=>{wn(!1)},1200)):re.error(s("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.copyFileContents"),"aria-label":s("filesView.editor.copyFileContents"),children:za?r.jsx(E,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(E,{name:"clipboard",className:"size-4"})})),so&&C(s("filesView.editor.copyFilePathTitle",{path:Nt}),r.jsx(I,{variant:"ghost",size:"sm",onClick:async()=>{(await fr(Nt)).ok?(bn(!0),ps.current!==null&&window.clearTimeout(ps.current),ps.current=window.setTimeout(()=>{bn(!1)},1200)):re.error(s("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.copyFilePathTitle",{path:Nt}),"aria-label":s("filesView.editor.copyFilePathTitle",{path:Nt}),children:La?r.jsx(E,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(E,{name:"file-copy-2",className:"size-4"})})),a.downloadFile&&C(s("filesView.editor.saveFile"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{const P=a.downloadFile;P&&P(c.path).catch(O=>{console.error("Download failed:",O),re.error(s("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.saveFile"),"aria-label":s("filesView.editor.saveFile"),children:r.jsx(E,{name:"download",className:"size-4"})})),t?C(s("filesView.editor.exitFullscreen"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Te(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.exitFullscreen"),"aria-label":s("filesView.editor.exitFullscreen"),children:r.jsx(E,{name:"fullscreen-exit",className:"size-4"})})):!p&&n==="full"&&C(s(ne?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Te(!ne),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s(ne?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":s(ne?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:ne?r.jsx(E,{name:"fullscreen-exit",className:"size-4"}):r.jsx(E,{name:"fullscreen",className:"size-4"})}))]})},Wr=r.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[r.jsx(ra,{open:Cr,onOpenChange:t=>{t||ds(!0)},children:r.jsxs(na,{showCloseButton:!1,className:"max-w-md",children:[r.jsxs(ia,{children:[r.jsx(aa,{children:s("filesView.unsaved.title")}),r.jsx(oa,{children:s("filesView.unsaved.description")})]}),r.jsxs(la,{children:[r.jsx(I,{variant:"outline",onClick:()=>{Ja()},disabled:ls,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:s("filesView.unsaved.saveChanges")}),r.jsx(I,{variant:"destructive",onClick:Xa,children:s("filesView.unsaved.discard")})]})]})}),r.jsxs("div",{className:W("flex flex-col flex-shrink-0",z&&"border-b border-border/40"),children:[z?r.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[p&&J&&r.jsx("button",{type:"button",onClick:()=>q(!1),"aria-label":s("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-ring",children:r.jsx(E,{name:"arrow-left-s",className:"size-5"})}),p?c?r.jsxs(tn,{children:[r.jsx(sn,{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":s("filesView.editor.openFilesAria"),children:[r.jsx(Ns,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(Zi,{name:c.name}),r.jsx(E,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),r.jsx(rn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Bt.map(t=>{const o=c?.path===t.path;return r.jsxs(ur,{onSelect:u=>{if(u.target.closest("[data-close-open-file]")){u.preventDefault();return}o||Me(t)},className:W("flex min-w-0 items-center justify-between gap-2 overflow-hidden",o&&"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(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(Zi,{name:t.name})]}),r.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:u=>{u.preventDefault(),u.stopPropagation()},onClick:u=>{u.preventDefault(),u.stopPropagation(),Jn(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":s("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(E,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:s("filesView.editor.selectFile")}):Bt.length>0?r.jsxs("div",{className:"relative min-w-0 flex-1",children:[un.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"}),un.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:br,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Bt.map(t=>{const o=c?.path===t.path;return r.jsxs("div",{title:dr(l,t.path),className:W("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",o?"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(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx("button",{type:"button",onClick:()=>{o||Me(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),r.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),Jn(t.path)},className:W("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!o&&!F&&"opacity-0 group-hover:opacity-100"),"aria-label":s("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(E,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:s("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:[Nt&&!p?r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:Nt,children:Nt}):null,r.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Fi({layout:"docked"})})]}):null]}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:r.jsx(Gr,{ref:No,outerClassName:"h-full min-w-0",className:W("h-full min-w-0",dt&&"[overflow-anchor:none]"),children:c?Ce||Br?B?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(E,{name:"loader-4",className:"size-4 animate-spin"}),s("filesView.state.loading")]}):Je?r.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Je}):nr||(c&&vs&&ve==="preview"?r.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:r.jsx(bc,{ref:gn,xml:ho,onChange:mo},`${c.path}:${ce}`)}):c&&Zt&&le==="tree"?r.jsx(ar,{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:s("filesView.error.jsonViewerUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:s("filesView.error.switchToTextMode")})]}),children:r.jsx("div",{className:"h-full overflow-auto",children:r.jsx(El,{jsonString:$,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&Xe&&$e()==="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:Bs,ref:To,children:[r.jsx(_i,{containerRef:Pn,filePath:c.path,fileContent:$}),$.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:s("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round($.length/1024)})}),r.jsx(ar,{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:s("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:s("filesView.error.switchToEditMode")})]}),children:r.jsx(Xr,{content:$,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),!ne&&r.jsx(Ki,{containerRef:Os,open:yn,onOpenChange:Is,focusNonce:jn})]}):c&&Yt&&xe==="preview"?go?r.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:s("common.loading")}):r.jsx("div",{className:"h-full overflow-hidden",children:r.jsx("iframe",{src:!w.isVSCode&&ui===tr?(()=>{const t=c.path.split("/").map(o=>encodeURIComponent(o)).join("/");return Pi().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:w.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?$.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):$})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:s("filesView.editor.htmlPreviewTitle")},po)}):c&&Ys&&_==="view"?Ci(c,se,mi,yo):r.jsxs("div",{className:W("relative h-full",Jt&&"overflow-hidden"),ref:As,children:[r.jsx("div",{className:W("h-full",Jt&&"invisible"),children:r.jsx(ea,{positionKey:vt,value:se,onChange:Fe,readOnly:!Qe,vimMode:Vn==="vim",extensions:ai,className:"h-full",blockWidgets:bo,onViewReady:t=>{qe.current=t,Fr(o=>o+1),window.requestAnimationFrame(()=>{ts(t)})},onViewDestroy:()=>{qe.current&&(qe.current=null),Fr(t=>t+1)},enableSearch:!0,searchOpen:De,onSearchOpenChange:ze,highlightLines:H?{start:Math.min(H.start,H.end),end:Math.max(H.start,H.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,o,u)=>{if(!(u instanceof MouseEvent)||u.button!==0)return!1;u.preventDefault();const h=t.state.doc.lineAt(o.from).number;if(H&&!u.shiftKey&&Math.min(H.start,H.end)===h&&Math.max(H.start,H.end)===h)return Ye(null),xs(),Kt.current=!1,yt.current=null,Ht(!1),!0;if(p&&H&&!u.shiftKey){const j=Math.min(H.start,H.end,h),C=Math.max(H.start,H.end,h);return Ye({start:j,end:C}),Kt.current=!1,yt.current=null,Ht(!1),!0}if(Kt.current=!0,yt.current=h,Ht(!0),H&&u.shiftKey){const j=Math.min(H.start,h),C=Math.max(H.end,h);Ye({start:j,end:C})}else Ye({start:h,end:h});return!0},mouseover:(t,o,u)=>{if(!(u instanceof MouseEvent)||u.buttons!==1||!Kt.current||yt.current===null)return!1;const h=t.state.doc.lineAt(o.from).number,j=Math.min(yt.current,h),C=Math.max(yt.current,h);return Ye({start:j,end:C}),Ht(!0),!1},mouseup:()=>(Kt.current=!1,yt.current=null,Ht(!1),!1)}}},vt)}),Jt&&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(E,{name:"loader-4",className:"size-4 animate-spin"}),s("filesView.state.openingFileAtChange")]})})]})):r.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:s("filesView.editor.pickFileFromTree")})})})]}),Vo=!!(l&&mn[l]),ki=l?Ps[l]:null,Ri=T?r.jsxs("section",{className:W("flex min-h-0 flex-col overflow-hidden",p?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[r.jsx("div",{className:W("flex flex-col gap-2 py-2",p?"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(E,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),r.jsx(Cs,{ref:X,value:te,onChange:t=>ee(t.target.value),placeholder:s("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),te.trim().length>0&&r.jsx("button",{type:"button","aria-label":s("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:()=>{ee(""),X.current?.focus()},children:r.jsx(E,{name:"close",className:"size-4"})})]}),r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Er("createFile",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:s("filesView.tree.actions.newFileTitle"),"aria-label":s("filesView.tree.actions.newFileTitle"),children:r.jsx(E,{name:"file-add",className:"size-4"})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("filesView.tree.actions.newFileTitle")})]}),r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Er("createFolder",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:s("filesView.tree.actions.newFolderTitle"),"aria-label":s("filesView.tree.actions.newFolderTitle"),children:r.jsx(E,{name:"folder-add",className:"size-4"})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("filesView.tree.actions.newFolderTitle")})]}),_n&&r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Wn(l),disabled:!l||Hs,className:"size-8 p-0 flex-shrink-0",title:s("sidebarFilesTree.actions.uploadFilesTitle"),"aria-label":s("sidebarFilesTree.actions.uploadFilesTitle"),children:r.jsx(E,{name:Hs?"loader-4":"upload-2",className:W("size-4",Hs&&"animate-spin")})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("sidebarFilesTree.actions.uploadFilesTitle")})]}),r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{Ks()},className:"size-8 p-0 flex-shrink-0",title:s("filesView.tree.actions.refreshTitle"),"aria-label":s("filesView.tree.actions.refreshTitle"),children:r.jsx(E,{name:"refresh",className:"size-4"})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("filesView.tree.actions.refreshTitle")})]})]})}),r.jsx(Gr,{outerClassName:"flex-1 min-h-0",className:W("py-2",p?"px-3":"px-2"),children:r.jsx("ul",{className:"flex flex-col",children:va?r.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),s("filesView.tree.search.searching")]}):hn.length>0?hn.map(t=>{const o=c?.path===t.path;return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>{Me(t)},className:W("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",o?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[pa(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)}):ki?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:ki}),r.jsxs(I,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{Ks()},children:[r.jsx(E,{name:"refresh",className:"size-3.5"}),s("filesView.tree.actions.refreshTitle")]})]}):Vo?Yn(l,0):r.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:s("filesView.state.loading")})})})]}):null,Po=n==="full"&&ne&&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:Fi({exitFullscreenOnly:!0})}),r.jsx(Gr,{ref:So,outerClassName:"h-full min-w-0",className:W("h-full min-w-0",dt&&"[overflow-anchor:none]"),children:Ce||Br?B?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(E,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Je?r.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Je}):nr||(Xe&&$e()==="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:Bs,ref:Eo,children:[c?r.jsx(_i,{containerRef:$s,filePath:c.path,fileContent:$}):null,$.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:s("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round($.length/1024)})}),r.jsx(ar,{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:s("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:s("filesView.error.switchToEditMode")})]}),children:r.jsx(Xr,{content:$,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),r.jsx(Ki,{containerRef:$s,open:yn,onOpenChange:Is,focusNonce:jn,className:"right-4 top-16"})]}):Ys&&_==="view"?Ci(c,se,hi,jo):r.jsxs("div",{className:W("relative h-full",Jt&&"overflow-hidden"),children:[r.jsx("div",{className:W("h-full",Jt&&"invisible"),children:r.jsx(ea,{positionKey:`${vt}:fullscreen`,value:se,onChange:Fe,readOnly:!Qe,vimMode:Vn==="vim",extensions:ai,className:"h-full",onViewReady:t=>{qe.current=t,window.requestAnimationFrame(()=>{ts(t)})},onViewDestroy:()=>{qe.current&&(qe.current=null)}},`${vt}:fullscreen`)}),Jt&&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(E,{name:"loader-4",className:"size-4 animate-spin"}),s("filesView.state.openingFileAtChange")]})})]}))})]})});return r.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[r.jsx(Zc,{activeDialog:Tt,dialogData:Et,dialogInputValue:bt,onDialogInputChange:vn,isDialogSubmitting:Ea,onDialogSubmit:Ga,onClose:wo,inputRef:Na}),qa,Po,p?J?Wr:Ri:n==="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:Wr})}):r.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[b>=700&&r.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Ri}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Wr})]})]})};function Qc(n){return n+1}export{jf as FilesView};