@pi-chamber/web 0.8.2 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +22 -6
  2. package/bin/cli.js +16 -3
  3. package/bin/cli.test.js +62 -0
  4. package/bin/lib/DOCUMENTATION.md +6 -6
  5. package/bin/lib/cli-args.js +26 -7
  6. package/bin/lib/cli-lifecycle.js +3 -0
  7. package/bin/lib/cli-paths.js +6 -0
  8. package/bin/lib/cli-process.js +1 -0
  9. package/bin/lib/cli-tunnel-profiles.js +15 -10
  10. package/bin/lib/commands-connect-url.js +9 -1
  11. package/bin/lib/commands-lifecycle.js +14 -0
  12. package/bin/lib/commands-logs.js +24 -5
  13. package/bin/lib/commands-serve.js +176 -4
  14. package/bin/lib/commands-tunnel.js +35 -0
  15. package/bin/lib/commands-update.js +107 -39
  16. package/bin/lib/commands-update.test.js +97 -1
  17. package/dist/assets/{DiagramEditor-DerMrS6m.js → DiagramEditor-DoEOH0hY.js} +1 -1
  18. package/dist/assets/{DiagramView-DdipXAq8.js → DiagramView-y9Ystuhv.js} +1 -1
  19. package/dist/assets/DiffView-ScM4XoqZ.js +18 -0
  20. package/dist/assets/{FilesView-BXp0yc0j.js → FilesView-CjkhMFqJ.js} +3 -3
  21. package/dist/assets/GitView-Bqi6H8I-.js +8 -0
  22. package/dist/assets/JsonTreeView-DWhlH6NK.js +1 -0
  23. package/dist/assets/{MarkdownRendererImpl-DNZQgQua.js → MarkdownRendererImpl-CEOKZ1qH.js} +1 -1
  24. package/dist/assets/{PatchDiff-B_NFEIX7.js → PatchDiff-ClnfJJ2J.js} +1 -1
  25. package/dist/assets/{SessionSwitcherContent-Q4P2TGBr.js → SessionSwitcherContent-e6JzUXD_.js} +1 -1
  26. package/dist/assets/{SessionSwitcherDropdown-Cgw2mQIO.js → SessionSwitcherDropdown-C4etG8dv.js} +2 -2
  27. package/dist/assets/{SessionUnreadDot-BxtTkvHB.js → SessionUnreadDot-BVTSwRiG.js} +1 -1
  28. package/dist/assets/SettingsView-C0S0Sx-S.js +2 -0
  29. package/dist/assets/{SettingsWindow-BEjHL1ET.js → SettingsWindow-Cy9tmnMg.js} +1 -1
  30. package/dist/assets/ToolOutputDialog-Csrc0Uk2.js +8 -0
  31. package/dist/assets/{ToolPartDiffPreview-ClV785zX.js → ToolPartDiffPreview-6oH6KD44.js} +1 -1
  32. package/dist/assets/{VirtualizedFileDiff-DrxkW2WQ.js → VirtualizedFileDiff-DJNcTQNp.js} +4 -4
  33. package/dist/assets/{collapsible-CR3-hRMy.js → collapsible-DxgVLhi9.js} +1 -1
  34. package/dist/assets/computeVirtualFileMetrics-B-WoeBMW.js +3 -0
  35. package/dist/assets/{contextFileOpenGuard-BRc5Z0g-.js → contextFileOpenGuard-DQ4U9xRH.js} +1 -1
  36. package/dist/assets/gitStatusPredicates-CIFSGjJs.js +134 -0
  37. package/dist/assets/index-D2C3q2xD.js +8 -0
  38. package/dist/assets/index-DNoEeZ2U.css +1 -0
  39. package/dist/assets/{index-CMfiVUIr.js → index-DmNPBaSo.js} +1 -1
  40. package/dist/assets/{isDiffPlainText-MmBA1REG.js → isDiffPlainText-CrvpUauF.js} +1 -1
  41. package/dist/assets/{isFilePlainText-bQAPxqO9.js → isFilePlainText-CKvhS32g.js} +1 -1
  42. package/dist/assets/{main-zZrKd3hZ.js → main-BFv8slLp.js} +2 -2
  43. package/dist/assets/main-CjM7g4Gq.js +135 -0
  44. package/dist/assets/{markdownCore-B9jXCPry.js → markdownCore-DKrraAqT.js} +1 -1
  45. package/dist/assets/{miniChat-Di2oVS5o.js → miniChat-hQnLS5mt.js} +2 -2
  46. package/dist/assets/{mobile-VU_G_SgX.js → mobile-DuXOBGs_.js} +2 -2
  47. package/dist/assets/renderElectronMiniChatApp-ClJBZVGy.js +2 -0
  48. package/dist/assets/renderMobileApp-DofX2wjB.js +11 -0
  49. package/dist/assets/runtimeEndpointReset-BZeYg6eN.js +54 -0
  50. package/dist/assets/{runtimeSurface-CBaS2Ank.js → runtimeSurface-C7CBxDbh.js} +1 -1
  51. package/dist/assets/{useAppFontEffects-8ZU-TTIW.js → useAppFontEffects-Cs0f1dKn.js} +102 -102
  52. package/dist/assets/{useFilesViewSearch-COow9O9x.js → useFilesViewSearch-D1hcbBEc.js} +1 -1
  53. package/dist/assets/usePushVisibilityBeacon-DqHkuVS5.js +10 -0
  54. package/dist/assets/{useSwitcherItems-DOQqhi-e.js → useSwitcherItems-BEoW7LlC.js} +1 -1
  55. package/dist/assets/{vendor-codemirror-language-data-B_0wrsbo.js → vendor-codemirror-language-data-B8Ac62S_.js} +2 -2
  56. package/dist/assets/{vendor-dnd-kit-core-CP8ck10N.js → vendor-dnd-kit-core-C9qcAm_1.js} +1 -1
  57. package/dist/assets/{vendor-dnd-kit-sortable-B-Icjoj4.js → vendor-dnd-kit-sortable-D8ozj8M-.js} +1 -1
  58. package/dist/assets/vendor-xterm-addon-fit-DX4qG4td.js +1 -0
  59. package/dist/assets/vendor-xterm-xterm-CrXqRur4.js +16 -0
  60. package/dist/assets/vendor-xterm-xterm-DDGTF8rc.css +1 -0
  61. package/dist/assets/{web-components-C9ENH49P.js → web-components-Dy-Tz_LJ.js} +3 -3
  62. package/dist/index.html +4 -4
  63. package/dist/mini-chat.html +3 -3
  64. package/dist/mobile.html +3 -3
  65. package/package.json +3 -4
  66. package/server/index.js +26 -7
  67. package/server/lib/client-auth/pairing.js +13 -2
  68. package/server/lib/client-auth/remote-clients.js +13 -2
  69. package/server/lib/fs/DOCUMENTATION.md +3 -1
  70. package/server/lib/fs/routes.test.js +74 -0
  71. package/server/lib/git/DOCUMENTATION.md +1 -1
  72. package/server/lib/git/identity-storage.js +10 -1
  73. package/server/lib/package-manager.js +1 -1
  74. package/server/lib/package-manager.test.js +11 -0
  75. package/server/lib/pi/archive-store.js +3 -2
  76. package/server/lib/pi/model-config-store.js +6 -2
  77. package/server/lib/pi/routes.js +11 -2
  78. package/server/lib/pi/session-daemon/DOCUMENTATION.md +12 -6
  79. package/server/lib/pi/session-daemon/daemon-process.js +48 -13
  80. package/server/lib/pi/session-daemon/session-daemon.js +226 -40
  81. package/server/lib/pi/session-daemon/session-daemon.test.js +207 -0
  82. package/server/lib/pi/session-daemon/session-lease.js +151 -0
  83. package/server/lib/pi/session-daemon/session-lease.test.js +108 -0
  84. package/server/lib/pi/session-daemon/supervisor.js +244 -54
  85. package/server/lib/pi/session-daemon/supervisor.test.js +202 -6
  86. package/server/lib/pi/session-folders-store.js +20 -2
  87. package/server/lib/pi/session-folders-store.test.js +17 -0
  88. package/server/lib/pi/settings-store.js +3 -2
  89. package/server/lib/pi/snippets-store.js +4 -1
  90. package/server/lib/pi/ui-settings-store.js +3 -2
  91. package/server/lib/server/cross-process-lock.js +112 -0
  92. package/server/lib/server/cross-process-lock.test.js +70 -0
  93. package/server/lib/server/server-profile.js +110 -0
  94. package/server/lib/server/server-profile.test.js +58 -0
  95. package/server/lib/server/tunnel-service.DOCUMENTATION.md +7 -8
  96. package/server/lib/server/tunnel-service.js +8 -1
  97. package/server/lib/stt/DOCUMENTATION.md +1 -1
  98. package/server/lib/stt/config-store.js +3 -2
  99. package/server/lib/terminal/DOCUMENTATION.md +3 -3
  100. package/server/lib/tunnels/DOCUMENTATION.md +38 -18
  101. package/server/lib/ui-auth/ui-auth.js +9 -2
  102. package/server/lib/ui-auth/ui-passkeys.js +9 -1
  103. package/dist/assets/DiffView-Gh9wjthp.js +0 -18
  104. package/dist/assets/GitView-BmNCkkoC.js +0 -8
  105. package/dist/assets/JsonTreeView-CxXRXXzk.js +0 -1
  106. package/dist/assets/SettingsView-CFzxRzUq.js +0 -2
  107. package/dist/assets/ToolOutputDialog-C_7vJLEq.js +0 -8
  108. package/dist/assets/computeVirtualFileMetrics-D0mQcleY.js +0 -3
  109. package/dist/assets/gitStatusPredicates-DBGDfr1K.js +0 -134
  110. package/dist/assets/index-CzO3ooje.css +0 -1
  111. package/dist/assets/index-ivrh3jfy.js +0 -8
  112. package/dist/assets/main-BoVfUG73.js +0 -135
  113. package/dist/assets/renderElectronMiniChatApp-Bi1927c8.js +0 -2
  114. package/dist/assets/renderMobileApp-D9mxhuaM.js +0 -11
  115. package/dist/assets/runtimeEndpointReset-DImT35Ug.js +0 -54
  116. package/dist/assets/usePushVisibilityBeacon-zYd3ppNh.js +0 -10
  117. package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
@@ -1,8 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-Gh9wjthp.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-ivrh3jfy.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-CzO3ooje.css","assets/useAppFontEffects-8ZU-TTIW.js","assets/vendor-base-ui-vkqQ2P9o.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-CBaS2Ank.js","assets/vendor-dnd-kit-core-CP8ck10N.js","assets/vendor-dnd-kit-utilities-DTY1C6ST.js","assets/vendor-dnd-kit-accessibility-DZKKhs9S.js","assets/vendor-dnd-kit-sortable-B-Icjoj4.js","assets/vendor-cmdk-zXx6sGnS.js","assets/vendor-radix-ui-react-dialog-D2yhEu2p.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js","assets/vendor-radix-ui-react-context-CFsX-AUC.js","assets/vendor-radix-ui-react-id-D2kS9K1j.js","assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js","assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js","assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js","assets/vendor-radix-ui-react-primitive-DkH8dMOR.js","assets/vendor-radix-ui-react-slot-BIDFZX0-.js","assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js","assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js","assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js","assets/vendor-radix-ui-react-portal-YgCRIyi7.js","assets/vendor-radix-ui-react-presence-D432pCMB.js","assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js","assets/vendor-react-remove-scroll-vR1dy1aP.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-CSAHp1YF.js","assets/vendor-react-style-singleton-Ctw6HnYx.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-Vv4V8Nd1.js","assets/vendor-use-callback-ref-CVVuCyLj.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BByA_dGF.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-wd6iRebq.js","assets/vendor-codemirror-lang-json-CZ07HmNC.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-djiuoTi8.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CKHqhW5R.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-DtcZDGqe.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-B_0wrsbo.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-DYppkHEk.js","assets/vendor-tanstack-react-virtual-2skouoFw.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CfplGuM0.js","assets/vendor-motion-dom-DhJ-sYS5.js","assets/vendor-motion-utils-CKEGc_YG.js","assets/gitStatusPredicates-DBGDfr1K.js","assets/web-components-C9ENH49P.js","assets/computeVirtualFileMetrics-D0mQcleY.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-yJ9XpNMI.js","assets/vendor-pierre-theming-Dgp7B_O4.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-DrxkW2WQ.js","assets/isDiffPlainText-MmBA1REG.js","assets/vendor-diff-C3JhlQdm.js","assets/runtimeEndpointReset-DImT35Ug.js","assets/SessionUnreadDot-BxtTkvHB.js","assets/permissionStore-iKN1K2_x.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/contextFileOpenGuard-BRc5Z0g-.js"])))=>i.map(i=>d[i]);
2
- import{_ as gs}from"./vendor-vite-runtime-DD1OZmLC.js";import{R as n,j as e,r as Ge}from"./vendor-react-B5Z1Mdn3.js";import{j as ot,k as $t,bv as Xt,aQ as ve,aR as we,bi as Ce,I,bj as Ne,bk as Fe,U as T,t as S,E as Pe,F as Ae,G as ze,D as xs,a as bs,b as ys,bm as Dn,aP as js,bC as Bn,ao as Tn,cd as Gn,ce as On,cf as _n,cg as Hn,ch as Un,bM as vs,bN as ws,bO as Cs,bP as Ns,bQ as Pt,bR as At,ci as Vn,bl as _e,bg as Zt,cj as Wn,ck as Kn,b9 as qn,af as Yn,b6 as Jn,bh as Ss,cl as Qn,bD as ks,p as Xn,aB as Zn,ba as ea,bb as ta,cm as sa,cn as na,co as aa,bc as ra,cp as ia,Q as oa,L as la,be as ca}from"./useAppFontEffects-8ZU-TTIW.js";import{J as da,K as ua,L as ha,N as ma}from"./runtimeEndpointReset-DImT35Ug.js";import{u as es}from"./vendor-zustand-GVb4H8HE.js";import{u as lt,ae as fa,c as ee,n as st}from"./index-ivrh3jfy.js";import{C as pa,a as ga,b as xa}from"./collapsible-CR3-hRMy.js";import{P as Rs,d as ba,i as ts,a as ya}from"./gitStatusPredicates-DBGDfr1K.js";import{u as ja}from"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-vkqQ2P9o.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./runtimeSurface-CBaS2Ank.js";import"./vendor-dnd-kit-core-CP8ck10N.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-B-Icjoj4.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-B_0wrsbo.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-DYppkHEk.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./SessionUnreadDot-BxtTkvHB.js";import"./permissionStore-iKN1K2_x.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./web-components-C9ENH49P.js";import"./computeVirtualFileMetrics-D0mQcleY.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-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-DrxkW2WQ.js";import"./isDiffPlainText-MmBA1REG.js";import"./vendor-diff-C3JhlQdm.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";const Es="gitmojiCache",va=1e3*60*60*24*7,Fs="1",wa="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Is=r=>{if(!r||typeof r!="object")return!1;const s=r;return typeof s.emoji=="string"&&typeof s.code=="string"&&typeof s.description=="string"},Et=()=>{if(typeof window>"u")return null;try{const r=window.localStorage.getItem(Es);if(!r)return null;const s=JSON.parse(r);return!s||s.version!==Fs||typeof s.fetchedAt!="number"||!Array.isArray(s.gitmojis)?null:{gitmojis:s.gitmojis.filter(Is),fetchedAt:s.fetchedAt,version:s.version}}catch{return null}},Ca=r=>{if(!(typeof window>"u"))try{const s={gitmojis:r,fetchedAt:Date.now(),version:Fs};window.localStorage.setItem(Es,JSON.stringify(s))}catch{return}},ss=r=>Date.now()-r.fetchedAt<va;let nt=null;const Oe=new Set,ns=async()=>{if(nt)return nt;const r=(async()=>{try{const s=await fetch(wa);if(!s.ok)throw new Error(`Failed to load gitmojis: ${s.statusText}`);const c=await s.json(),h=Array.isArray(c.gitmojis)?c.gitmojis.filter(Is):[];return Ca(h),Oe.forEach(a=>a(h)),h}catch(s){console.warn("Failed to load gitmoji list:",s);const c=[];return Oe.forEach(h=>h(c)),c}finally{nt=null}})();return nt=r,r},Na=r=>{const[s,c]=n.useState(()=>r?Et()?.gitmojis??[]:[]),[h,a]=n.useState(!1),t=n.useRef(r);t.current=r,n.useEffect(()=>{if(!r){Oe.delete(c),c([]),a(!1);return}const b=Et();if(b&&(c(b.gitmojis),ss(b)))return;Oe.add(c),a(!0);let d=!1;return ns().finally(()=>{!d&&t.current&&a(!1)}),()=>{d=!0,Oe.delete(c)}},[r]);const m=n.useCallback(async()=>{if(!t.current)return[];if(s.length>0)return s;const b=Et();return b&&ss(b)?b.gitmojis:ns()},[s]);return{gitmojis:s,isLoading:h,ensureLoaded:m}},Sa=({open:r,onOpenChange:s,conflictFiles:c=[],directory:h,operation:a,onAbort:t,onClearState:m})=>{const{git:b}=ot(),d=$t(x=>x.openNewSessionDraft),y=$t(x=>x.currentSessionId),C=Xt(x=>x.setPendingInputText),k=Xt(x=>x.setPendingSyntheticParts),j=lt(x=>x.setActiveMainTab),[p,o]=n.useState(!1),[w,R]=n.useState(null),[E,M]=n.useState(null);n.useEffect(()=>{!r||!h||(o(!0),M(null),R(null),b.getConflictDetails(h).then(x=>{R(x)}).catch(x=>{const D=x instanceof Error?x.message:"Failed to load conflict details";M(D)}).finally(()=>{o(!1)}))},[h,b,r]);const U=n.useCallback(async()=>{if(!w)return null;const x=a==="merge"?"merge":"rebase",D=w.headInfo||(a==="merge"?"MERGE_HEAD":"REBASE_HEAD"),J=a==="merge"?"git commit --no-edit":"git rebase --continue",X=`Investigate the ${x} conflicts and concisely report the intended resolution strategy without making modifications. Wait for confirmation before resolving, staging, or continuing the ${x}. Preserve the intent of changes from ${D}.`,te=`Git ${x} operation is in progress with conflicts.
3
- - Directory: ${h}
4
- - Operation: ${a}
5
- - Head Info: ${w.headInfo||"N/A"}
6
-
7
- Inspect each conflicted file and both sides of every conflict. Report a concise per-file resolution strategy and any assumptions or tradeoffs. Wait for explicit user confirmation before editing, staging, or running ${J}. After confirmation, remove all conflict markers, preserve intent from both sides, verify syntax, and complete the ${x}.`,q=`${x} conflict context (JSON)
8
- ${JSON.stringify({directory:h,operation:w.operation,headInfo:w.headInfo,statusPorcelain:w.statusPorcelain,unmergedFiles:w.unmergedFiles,diff:w.diff},null,2)}`;return{visibleText:X,instructionsText:te,payloadText:q}},[w,h,a]),V=()=>{t(),s(!1)},G=()=>{m?.(),s(!1)},P=async()=>{const x=await U();if(!x){S.error("No conflict details available");return}if(!y){S.error("No active session",{description:"Open or create a session to resolve conflicts."});return}C(x.visibleText,"replace"),k([{text:x.instructionsText,synthetic:!0},{text:x.payloadText,synthetic:!0}]),j("chat"),m?.(),s(!1)},A=async()=>{const x=await U();if(!x){S.error("No conflict details available");return}d({directoryOverride:h,initialPrompt:x.visibleText,syntheticParts:[{text:x.instructionsText,synthetic:!0},{text:x.payloadText,synthetic:!0}]}),j("chat"),m?.(),s(!1)},$=a==="merge"?"Merge":"Rebase",z=w?.unmergedFiles||c;return e.jsx(ve,{open:r,onOpenChange:s,children:e.jsx(we,{className:"max-w-md w-[calc(100vw-2rem)]",children:e.jsxs("div",{className:"flex flex-col gap-4 overflow-hidden",children:[e.jsxs(Ce,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e.jsx(Ne,{children:`${$} conflicts detected`})]}),e.jsx(Fe,{children:`Resolve the ${a} conflicts to continue.`})]}),p&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"typography-meta",children:"Loading conflict details..."})]}),E&&e.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:`Failed to load conflict details: ${E}`}),z.length>0&&e.jsxs("div",{className:"space-y-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Conflicted files:"}),e.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:z.length})]}),e.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:e.jsx("ul",{className:"space-y-1",children:z.map(x=>e.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:x,children:x},x))})})]}),w?.headInfo&&e.jsxs("div",{className:"space-y-1 overflow-hidden",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"HEAD information:"}),e.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:w.headInfo})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-2",children:[e.jsxs(T,{variant:"default",onClick:()=>{A()},disabled:p||!w,className:"w-full gap-2",children:[p?e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(I,{name:"add",className:"size-4"}),"Resolve in new session"]}),e.jsxs(T,{variant:"outline",onClick:()=>{P()},disabled:p||!w||!y,className:"w-full gap-2",children:[p?e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(I,{name:"chat-1",className:"size-4"}),"Resolve in current session"]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(T,{variant:"ghost",size:"sm",onClick:G,className:"flex-1",children:"Continue later"}),e.jsx(T,{variant:"destructive",size:"sm",onClick:V,className:"flex-1",children:`Abort ${$}`})]})]})]})})})},Re=8,ka=({laned:r,totalLanes:s,isExpanded:c})=>{const{lane:h,color:a,connectors:t}=r,b=Math.max(s,h+1)*Re+Re/2,d=n.useRef(null),y=n.useRef(null);return n.useLayoutEffect(()=>{const C=d.current,k=y.current;if(!C||!k)return;const j=C.offsetHeight;if(j===0)return;const p=window.devicePixelRatio||1;k.width=b*p,k.height=j*p;const o=k.getContext("2d");if(!o)return;o.scale(p,p),o.clearRect(0,0,b,j);const w=j/2,R=h*Re+Re/2,E=getComputedStyle(k),M=E.getPropertyValue("--surface-muted-foreground").trim()||E.color,U=P=>{if(!P.startsWith("var("))return P;const A=P.slice(4,-1).trim();return E.getPropertyValue(A).trim()||M},V=[...t].sort((P,A)=>{const $=z=>z==="branch-out"||z==="merge-in";return($(P.type)?1:0)-($(A.type)?1:0)});for(const P of V){const A=P.fromLane*Re+Re/2,$=P.toLane*Re+Re/2,z=P.type==="passing"?.72:P.type==="branch-out"||P.type==="merge-in"?.95:1;switch(o.beginPath(),o.strokeStyle=U(P.color),o.globalAlpha=z,o.lineWidth=1.25,o.lineCap="round",P.type){case"passing":case"commit-lane":o.moveTo(A,0),o.lineTo(A,j);break;case"top-stub":o.moveTo(A,0),o.lineTo(A,w);break;case"bottom-stub":o.moveTo(A,w),o.lineTo(A,j);break;case"branch-out":{const x=(w+j)/2;o.moveTo(R,w),o.bezierCurveTo(R,x,$,x,$,j);break}case"merge-in":{const x=w/2;o.moveTo(A,0),o.bezierCurveTo(A,x,R,x,R,w);break}default:continue}o.stroke(),o.globalAlpha=1}const G=E.getPropertyValue("--background").trim()||E.getPropertyValue("--surface-background").trim();o.beginPath(),o.arc(R,w,4,0,Math.PI*2),o.fillStyle=U(a),o.fill(),o.beginPath(),o.arc(R,w,5,0,Math.PI*2),o.strokeStyle=G||M,o.lineWidth=2,o.stroke()},[r,h,a,t,s,c,b]),e.jsx("div",{ref:d,style:{width:b,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},children:e.jsx("canvas",{ref:y,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}})})},as=15e3,rs=500,is=12,os=8*1024*1024,ls=r=>typeof r=="string"?0:(r.original?.length??0)+(r.modified?.length??0),cs=r=>{if(r.size<=is){let a=0;for(const t of r.values())a+=ls(t);if(a<=os)return r}const s=Array.from(r.entries()).reverse(),c=new Map;let h=0;for(const[a,t]of s){if(c.size>=is)continue;const m=ls(t);h+m>os&&c.size>0||(c.set(a,t),h+=m)}return new Map(Array.from(c.entries()).reverse())};function ds(r,s){const c=new Date(r);return Number.isNaN(c.getTime())?r:Bn(c,s,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Ra(r){switch(r){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function Ea(r){return r?r.split(",").map(s=>s.trim()).filter(Boolean).map(s=>{const c=s.startsWith("HEAD ->");return{label:c?s.replace("HEAD -> ",""):s.replace("tag: ",""),isHead:c,isTag:s.startsWith("tag: ")}}):[]}const Fa=n.memo(({entry:r,mode:s="history",laned:c,totalLanes:h,isExpanded:a,onToggle:t,files:m,isLoadingFiles:b,onCopyHash:d,directory:y,onConflict:C,onActionSuccess:k})=>{const{git:j}=ot(),p=lt(l=>l.timeFormatPreference),o=s==="graph",w={checkout:"Check out this commit as detached HEAD?",cherryPick:"Cherry-pick this commit onto the current branch?",revert:"Stage a revert of this commit?",merge:"Merge this commit into the current branch?",rebase:"Rebase current branch onto this commit?",resetSoft:"Soft reset — HEAD moves, staged changes preserved.",resetMixed:"Mixed reset — HEAD moves, changes unstaged.",resetHard:"Hard reset — HEAD moves, all uncommitted changes permanently discarded."},R={soft:"Soft — keep staged",mixed:"Mixed — unstage changes",hard:"Hard — discard all changes"},[E,M]=n.useState(null),[U,V]=n.useState(!1),[G,P]=n.useState(""),[A,$]=n.useState(null),[z,x]=n.useState(new Set),[D,J]=n.useState(new Map),[X,te]=n.useState(new Set),q=async()=>{if(y){M("checkout");try{await j.checkoutCommit(y,r.hash),S.success("Checked out (detached HEAD)"),k?.()}catch(l){S.error(String(l.message))}finally{M(null)}}},_=async()=>{if(!(!y||!G.trim())){M("createBranch");try{await j.createBranch(y,G.trim(),r.hash),V(!1),P(""),k?.()}catch(l){S.error(String(l.message))}finally{M(null)}}},re=async()=>{if(y){M("cherryPick");try{const l=await j.cherryPick(y,r.hash);l.conflict?C?.({conflict:!0,conflictFiles:l.conflictFiles,operation:"cherry-pick"}):k?.()}catch(l){S.error(String(l.message))}finally{M(null)}}},ie=async()=>{if(y){M("revert");try{const l=await j.revertCommit(y,r.hash);l.conflict?C?.({conflict:!0,conflictFiles:l.conflictFiles,operation:"revert"}):k?.()}catch(l){S.error(String(l.message))}finally{M(null)}}},oe=async(l,F=!1)=>{if(!(!y||E!==null)){M("reset");try{await j.resetToCommit(y,r.hash,l,F),k?.()}catch(W){S.error(String(W.message))}finally{M(null)}}},H=async()=>{if(!A)return;const l=A;switch($(null),l){case"checkout":return q();case"cherryPick":return re();case"revert":return ie();case"merge":return O();case"rebase":return B();case"resetSoft":return oe("soft");case"resetMixed":return oe("mixed");case"resetHard":return oe("hard",!0)}},O=async()=>{if(y){M("merge");try{const l=await j.merge(y,{branch:r.hash});l.conflict?C?.({conflict:!0,conflictFiles:l.conflictFiles,operation:"merge"}):k?.()}catch(l){S.error(String(l.message))}finally{M(null)}}},B=async()=>{if(y){M("rebase");try{const l=await j.rebase(y,{onto:r.hash});l.conflict?C?.({conflict:!0,conflictFiles:l.conflictFiles,operation:"rebase"}):k?.()}catch(l){S.error(String(l.message))}finally{M(null)}}},v=n.useCallback(async l=>{const F=l.path;if(!y){J(W=>new Map(W).set(F,"error"));return}J(W=>cs(new Map(W).set(F,"loading")));try{const Z=(j.getCommitFileDiff??fa)(y,r.hash,l.path,!1),ue=new Promise((se,De)=>{setTimeout(()=>De(new Error(`Timed out after ${as}ms`)),as)}),le=await Promise.race([Z,ue]);J(se=>cs(new Map(se).set(F,le)))}catch{J(W=>new Map(W).set(F,"error"))}},[y,r.hash,j.getCommitFileDiff]),N=n.useCallback(async l=>{const F=l.path;if(l.changeType==="R"||l.isBinary){x(le=>{const se=new Set(le);return se.has(F)?se.delete(F):se.add(F),se});return}const W=D.get(F);if(z.has(F)&&W&&W!=="error"){x(le=>{const se=new Set(le);return se.delete(F),se});return}x(le=>{const se=new Set(le);return se.add(F),se}),!(W&&W!=="error"||l.insertions+l.deletions>rs&&!X.has(F))&&await v(l)},[D,X,v,z]);return e.jsxs("li",{children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":a,onClick:t,onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),t())},className:ee("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",o?"hover:bg-[var(--interactive-hover)]/40":a?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[o&&c&&h!==void 0?e.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:e.jsx(ka,{laned:c,totalLanes:h,isExpanded:a})}):e.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[o?(()=>{const l=Ea(r.refs);return l.length>0?e.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:l.map(F=>e.jsx("span",{className:ee("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",F.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":F.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:F.label},F.label))}):null})():null,e.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:r.message}),e.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[e.jsx("span",{className:"truncate min-w-[3ch]",title:r.author_name,children:r.author_name}),e.jsx("span",{className:"shrink-0",children:"·"}),e.jsx("span",{className:"truncate min-w-0",title:ds(r.date,p),children:ds(r.date,p)})]}),e.jsx("span",{className:"shrink-0",children:"·"}),e.jsx("code",{className:"shrink-0 font-mono",children:r.hash.slice(0,8)}),e.jsxs(Pe,{children:[e.jsx(Ae,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:l=>{l.stopPropagation(),d(r.hash)},children:e.jsx(I,{name:"file-copy",className:"size-3"})})}),e.jsx(ze,{sideOffset:8,children:"Copy SHA"})]})]})]})]}),a&&e.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[o&&A?e.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[e.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:w[A]}),e.jsxs(T,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:E!==null,onClick:l=>{l.stopPropagation(),H()},children:[E!==null?e.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Confirm"]}),e.jsx(T,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:E!==null,onClick:l=>{l.stopPropagation(),$(null)},children:"Cancel"})]}):o?e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[e.jsx(T,{variant:"outline",size:"xs",className:"h-6",disabled:E!==null,onClick:l=>{l.stopPropagation(),$("checkout")},children:"Checkout"}),U?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{autoFocus:!0,value:G,onChange:l=>P(l.target.value),onKeyDown:l=>{l.key==="Enter"&&_(),l.key==="Escape"&&(V(!1),P(""))},placeholder:"Branch name",className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),e.jsxs(T,{variant:"outline",size:"xs",className:"h-6",disabled:!G.trim()||E!==null,onClick:l=>{l.stopPropagation(),_()},children:[E==="createBranch"?e.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Create"]})]}):e.jsx(T,{variant:"outline",size:"xs",className:"h-6",onClick:l=>{l.stopPropagation(),V(!0)},children:"Create branch here"}),e.jsx(T,{variant:"outline",size:"xs",className:"h-6",disabled:E!==null,onClick:l=>{l.stopPropagation(),$("cherryPick")},children:"Cherry-pick"}),e.jsx(T,{variant:"outline",size:"xs",className:"h-6",disabled:E!==null,onClick:l=>{l.stopPropagation(),$("revert")},children:"Revert"}),e.jsxs(xs,{children:[e.jsx(bs,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"xs",className:"h-6",disabled:E!==null,onClick:l=>l.stopPropagation(),children:[E==="reset"?e.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Reset..."]})}),e.jsx(ys,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(l=>e.jsx(Dn,{disabled:E!==null,onSelect:F=>{F.stopPropagation(),$(`reset${l.charAt(0).toUpperCase()+l.slice(1)}`)},children:R[l]},l))})]}),e.jsx(T,{variant:"outline",size:"xs",className:"h-6",disabled:E!==null,onClick:l=>{l.stopPropagation(),$("merge")},children:"Merge into current"}),e.jsx(T,{variant:"outline",size:"xs",className:"h-6",disabled:E!==null,onClick:l=>{l.stopPropagation(),$("rebase")},children:"Rebase onto this"})]}):null,b?e.jsxs("div",{className:"flex items-center gap-2 py-2",children:[e.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"typography-micro text-muted-foreground",children:"Loading files..."})]}):m.length===0?e.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:"No files"}):e.jsx("ul",{className:"space-y-0.5 py-2",children:m.map(l=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>N(l),className:ee("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",z.has(l.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[e.jsx("span",{className:ee("font-semibold w-3 text-center shrink-0",Ra(l.changeType)),children:l.changeType}),e.jsx("span",{className:"truncate text-foreground min-w-0",title:l.path,children:l.path}),!l.isBinary&&e.jsxs("span",{className:"shrink-0",children:[e.jsxs("span",{style:{color:"var(--status-success)"},children:["+",l.insertions]}),e.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),e.jsxs("span",{style:{color:"var(--status-error)"},children:["-",l.deletions]})]}),l.isBinary&&e.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:"Binary"}),e.jsx(I,{name:z.has(l.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),z.has(l.path)&&e.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:l.changeType==="R"?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Renamed file — diff not supported"}):l.isBinary?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Binary file — no diff available"}):(()=>{const F=l.insertions+l.deletions;if(!X.has(l.path)&&F>rs)return e.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${F} changed lines)`}),e.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),e.jsx(T,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{te(Z=>new Set(Z).add(l.path)),v(l)},children:"Render anyway"})]});const W=D.get(l.path);return W==="loading"||W===void 0?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Loading diff..."}):W==="error"?e.jsx("button",{type:"button",onClick:()=>N(l),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:"Failed to load diff. Click to retry."}):e.jsx(Rs,{original:W.original,modified:W.modified,language:js(l.path)||"",fileName:l.path,renderSideBySide:!1,layout:"inline"})})()})]},l.path))})]})]})}),us=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function at(r){return us[r%us.length]}function Ia(r){if(r.length===0)return[];const s=[],c=[];for(let h=0;h<r.length;h++){const a=r[h],t=[];for(let p=0;p<s.length;p++)s[p]===a.hash&&t.push(p);let m=t.length>0?t[0]:-1;if(m===-1){const p=s.indexOf(null);p!==-1?m=p:(m=s.length,s.push(null))}const b=t.slice(1),d=at(m),y=s[m]===a.hash,C=a.parents.length>0;C?s[m]=a.parents[0]:s[m]=null;const k=[];for(let p=1;p<a.parents.length;p++){const o=a.parents[p],w=s.indexOf(o);if(w!==-1)k.push(w);else{const R=s.indexOf(null),E=R!==-1?R:s.length;s[E]=o,E===s.length&&s.push(o),k.push(E)}}const j=[];y&&C?j.push({fromLane:m,toLane:m,color:d,type:"commit-lane"}):y&&!C?j.push({fromLane:m,toLane:m,color:d,type:"top-stub"}):!y&&C&&j.push({fromLane:m,toLane:m,color:d,type:"bottom-stub"});for(const p of b)j.push({fromLane:p,toLane:m,color:at(p),type:"merge-in"}),s[p]=null;for(const p of k)j.push({fromLane:m,toLane:p,color:at(p),type:"branch-out"});for(let p=0;p<s.length;p++)s[p]!==null&&p!==m&&(k.includes(p)||j.push({fromLane:p,toLane:p,color:at(p),type:"passing"}));c.push({commit:a,lane:m,color:d,connectors:j})}return c}const Ma=[{label:"25 commits",value:25},{label:"50 commits",value:50},{label:"100 commits",value:100}],La=({mode:r="history",log:s,isLogLoading:c,logMaxCount:h,onLogMaxCountChange:a,expandedCommitHashes:t,onToggleCommit:m,commitFilesMap:b,loadingCommitHashes:d,onCopyHash:y,directory:C,showHeader:k=!0,contentMaxHeightClassName:j="max-h-[50vh]",branchDivider:p=null,onConflict:o,onActionSuccess:w})=>{const[R,E]=n.useState(!0),M=r==="graph",U=n.useMemo(()=>M&&s?Ia(s.all):[],[M,s]),V=n.useMemo(()=>Math.max(1,...U.map(q=>q.lane+1)),[U]),G=n.useMemo(()=>new Map(U.map(q=>[q.commit.hash,q])),[U]);if(!s)return null;const P=p!==null&&p.insertBeforeIndex>0&&p.insertBeforeIndex<s.all.length,A=p!==null&&p.insertBeforeIndex===s.all.length,$=P||A,z=P?s.all.slice(0,p.insertBeforeIndex):A?s.all:[],x=P?s.all.slice(p.insertBeforeIndex):[],D=p?.direction==="down"?e.jsx(I,{name:"arrow-down-s",className:"size-3.5"}):e.jsx(I,{name:"arrow-up",className:"size-3.5"}),J=q=>e.jsx("ul",{className:"divide-y divide-border/60",children:q.map(_=>e.jsx(Fa,{entry:_,mode:r,laned:M?G.get(_.hash):void 0,totalLanes:M?V:void 0,isExpanded:t.has(_.hash),onToggle:()=>m(_.hash),files:b.get(_.hash)??[],isLoadingFiles:d.has(_.hash),onCopyHash:y,directory:C,onConflict:o,onActionSuccess:w},_.hash))}),X=s.all.length>=h?e.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:e.jsx(T,{type:"button",variant:"ghost",size:"xs",onClick:()=>a(h+25),disabled:c,className:"px-3 text-muted-foreground hover:text-foreground",children:c?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(I,{name:"loader-4",className:"size-3 animate-spin"}),"Loading..."]}):"Load more"})}):null,te=e.jsx(Tn,{outerClassName:`min-h-0 ${j}`,className:"h-full w-full",children:s.all.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-4",children:e.jsx("p",{className:"typography-ui-label text-muted-foreground",children:"No commits found"})}):$&&p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-0",children:[z.length>0?e.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:J(z)}):null,e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[e.jsx("span",{className:"h-px flex-1 bg-border/60"}),e.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[e.jsx("span",{className:"truncate",title:p.branchName,children:p.branchName}),D]}),e.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),x.length>0?e.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:J(x)}):null]}),X]}):e.jsxs(e.Fragment,{children:[J(s.all),X]})});return k?e.jsxs(pa,{open:R,onOpenChange:E,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[e.jsxs(ga,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[e.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"History"}),e.jsxs("div",{className:"flex items-center gap-2",children:[R&&e.jsx("div",{onClick:q=>q.stopPropagation(),onPointerDown:q=>q.stopPropagation(),children:e.jsxs(Gn,{value:String(h),onValueChange:q=>a(Number(q)),disabled:c,children:[e.jsx(On,{size:"sm",className:"w-auto",disabled:c,children:e.jsx(_n,{placeholder:"Commits"})}),e.jsx(Hn,{children:Ma.map(q=>e.jsx(Un,{value:String(q.value),children:q.label},q.value))})]})}),R?e.jsx(I,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):e.jsx(I,{name:"arrow-down-s",className:"size-4 text-muted-foreground"})]})]}),e.jsx(xa,{children:te})]}):$?e.jsx("section",{className:"h-full min-h-0",children:te}):e.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:te})},$a=n.memo(function({mode:s,onOpenChange:c,onRefresh:h,isRefreshing:a,log:t,maxCount:m,onMaxCountChange:b,expandedCommitHashes:d,onToggleCommit:y,commitFilesMap:C,loadingCommitHashes:k,onCopyHash:j,directory:p,branchDivider:o,onConflict:w,onActionSuccess:R}){return s?e.jsx(ve,{open:s!==null,onOpenChange:c,children:e.jsxs(we,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[e.jsxs(Ce,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(Ne,{children:s==="graph"?"Graph":"History"}),e.jsxs(T,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:h,disabled:a,title:"Refresh","aria-label":"Refresh",children:[e.jsx(I,{name:"refresh",className:ee("size-4",a&&"animate-spin")}),"Refresh"]})]}),e.jsx(Fe,{children:"Browse recent commits and inspect changed files."})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(La,{mode:s==="graph"?"graph":"history",log:t,isLogLoading:a,logMaxCount:m,onLogMaxCountChange:b,expandedCommitHashes:d,onToggleCommit:y,commitFilesMap:C,loadingCommitHashes:k,onCopyHash:j,directory:p,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:s==="graph"?null:o,onConflict:s==="graph"?w:void 0,onActionSuccess:s==="graph"?R:void 0})})]})}):null}),Pa=n.memo(function({open:s,onOpenChange:c,gitmojis:h,onSelect:a}){const[t,m]=Ge.useState(""),b=n.useMemo(()=>{if(h.length===0)return[];const d=t.trim().toLowerCase();return d?h.filter(y=>y.emoji.includes(d)||y.code.toLowerCase().includes(d)||y.description.toLowerCase().includes(d)):h},[h,t]);return e.jsx(ve,{open:s,onOpenChange:c,children:e.jsxs(we,{className:"max-w-md p-0 overflow-hidden",children:[e.jsx(Ce,{className:"px-4 pt-4",children:e.jsx(Ne,{children:"Insert gitmoji"})}),e.jsxs(vs,{className:"h-[420px]",children:[e.jsx(ws,{placeholder:"Search gitmoji...",value:t,onValueChange:m}),e.jsxs(Cs,{children:[e.jsx(Ns,{children:"No gitmoji found"}),e.jsx(Pt,{children:b.map(d=>e.jsxs(At,{onSelect:()=>a(d.emoji,d.code),children:[e.jsx("span",{className:"text-lg",children:d.emoji}),e.jsx("span",{className:"typography-ui-label text-foreground",children:d.code}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:d.description})]},d.code))})]})]})]})})}),Aa=({open:r,onOpenChange:s,operation:c,targetBranch:h,onConfirm:a})=>{const[t,m]=n.useState(!0),[b,d]=n.useState(!1),y=c==="merge"?"Merge":"Rebase",C=async()=>{d(!0);try{await a(t),s(!1)}catch(j){const p=j instanceof Error?j.message:`Failed to ${c}`;S.error(p)}finally{d(!1)}},k=()=>{b||s(!1)};return e.jsx(ve,{open:r,onOpenChange:b?void 0:s,children:e.jsxs(we,{className:"max-w-md",children:[e.jsxs(Ce,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),e.jsx(Ne,{children:"Uncommitted Changes"})]}),e.jsx(Fe,{children:`Stash your local changes before starting the ${c}.`})]}),e.jsxs("div",{className:"py-2",children:[e.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:"This will:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[e.jsx("li",{children:"Stash your uncommitted changes"}),e.jsxs("li",{children:[c==="merge"?"Merge":"Rebase"," ",c==="merge"?"with":"onto"," ",e.jsx("span",{className:"font-mono text-primary",children:h})]}),t&&e.jsx("li",{children:"Restore your stashed changes"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 py-2",children:[e.jsx(Vn,{checked:t,onChange:m,disabled:b,ariaLabel:"Restore stashed changes after operation"}),e.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!b&&m(!t),children:`Restore stashed changes after ${c}`})]}),e.jsxs(_e,{className:"gap-2",children:[e.jsx(T,{variant:"ghost",size:"sm",onClick:k,disabled:b,children:"Cancel"}),e.jsx(T,{variant:"default",size:"sm",onClick:C,disabled:b,className:"gap-1.5",children:b?e.jsxs(e.Fragment,{children:[e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),"Processing..."]}):`${y}`})]})]})})},za=({open:r,onOpenChange:s,directory:c,hasUncommittedChanges:h,hasStagedChanges:a=!1,uncommittedFileCount:t,onChanged:m})=>{const{git:b}=ot(),[d,y]=n.useState([]),[C,k]=n.useState(!1),[j,p]=n.useState(""),[o,w]=n.useState(""),[R,E]=n.useState(null),[M,U]=n.useState({}),V=n.useCallback(async()=>{if(c){k(!0);try{const x=await b.listGitStashes(c);y(x.stashes),U({})}catch(x){S.error(x instanceof Error?x.message:"Failed to load stashes")}finally{k(!1)}}},[c,b]);n.useEffect(()=>{r&&V()},[V,r]),n.useEffect(()=>{if(!r||!c||d.length===0)return;let x=!1;const D=d.map(J=>J.ref);return b.countGitStashFiles(c,D).then(J=>{x||U(J.counts)}).catch(()=>{}),()=>{x=!0}},[c,b,r,d]);const G=n.useMemo(()=>{const x=j.trim().toLowerCase();return x?d.filter(D=>`${D.ref} ${D.message} ${D.relativeTime}`.toLowerCase().includes(x)):d},[j,d]),P=n.useCallback(async x=>{await V(),await m?.(x)},[V,m]),A=async()=>{if(!(!c||R)){E("create");try{const x=await b.stashGitChanges(c,{message:o.trim()||void 0});x.created?(S.success("Changes stashed"),w("")):S.info("No local changes to stash"),await P({affectsIndex:!!(x.created&&a)})}catch(x){S.error(x instanceof Error?x.message:"Failed to stash changes")}finally{E(null)}}},$=async(x,D)=>{if(!(!c||R)&&!(D==="drop"&&!window.confirm(`Drop ${x.ref}?`))){E(`${D}:${x.ref}`);try{D==="apply"&&await b.applyGitStash(c,{ref:x.ref}),D==="pop"&&await b.popGitStash(c,{ref:x.ref}),D==="drop"&&await b.dropGitStash(c,{ref:x.ref});const J=D==="apply"?"Stash applied":D==="pop"?"Stash popped":"Stash dropped";S.success(J),await P({affectsIndex:D!=="drop"})}catch(J){const X=D==="apply"?"Failed to apply stash":D==="pop"?"Failed to pop stash":"Failed to drop stash";S.error(J instanceof Error?J.message:X),await P({affectsIndex:D!=="drop"})}finally{E(null)}}},z=R!==null;return e.jsx(ve,{open:r,onOpenChange:s,children:e.jsxs(we,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[e.jsxs(Ce,{children:[e.jsxs(Ne,{className:"flex items-center gap-2",children:[e.jsx(I,{name:"archive-stack",className:"h-5 w-5"}),"Stashes"]}),e.jsx(Fe,{children:"Save, restore, and clean up Git stashes for this repository."})]}),e.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(Zt,{value:o,onChange:x=>w(x.target.value),placeholder:"Stash name",disabled:z||!h,className:"flex-1"}),e.jsxs(T,{onClick:A,disabled:!h||z||!c,children:[R==="create"?e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(I,{name:"inbox-archive",className:"size-4"}),`Stash ${t} files`]})]}),e.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:"Untracked files are included automatically."})]}),e.jsxs("div",{className:"relative mt-2",children:[e.jsx(I,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(Zt,{value:j,onChange:x=>p(x.target.value),placeholder:"Search stashes",className:"pl-9"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:C?e.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:e.jsx(I,{name:"loader-4",className:"size-5 animate-spin"})}):G.length===0?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:j?"No matching stashes.":"No stashes yet."}):G.map((x,D)=>e.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[e.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[e.jsx("p",{className:"typography-small truncate text-foreground",children:x.message||"Untitled stash"}),e.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[e.jsxs(Pe,{children:[e.jsx(Ae,{asChild:!0,children:e.jsx("span",{children:D===0&&!j.trim()?"Latest":`#${D+1}`})}),e.jsx(ze,{sideOffset:6,children:x.ref})]})," · ",x.relativeTime," · ",typeof M[x.ref]=="number"?`${M[x.ref]} files`:"counting files..."]})]}),e.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[e.jsx(Ft,{label:"Apply",loading:R===`apply:${x.ref}`,onClick:()=>$(x,"apply"),disabled:z,children:e.jsx(I,{name:"inbox-unarchive",className:"size-4"})}),e.jsx(Ft,{label:"Pop",loading:R===`pop:${x.ref}`,onClick:()=>$(x,"pop"),disabled:z,children:e.jsx(I,{name:"inbox-unarchive-fill",className:"size-4"})}),e.jsx(Ft,{label:"Drop",loading:R===`drop:${x.ref}`,onClick:()=>$(x,"drop"),disabled:z,destructive:!0,children:e.jsx(I,{name:"delete-bin",className:"size-4"})})]})]},x.ref))})]})})},Ft=({label:r,loading:s,disabled:c,destructive:h,onClick:a,children:t})=>e.jsxs(Pe,{children:[e.jsx(Ae,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":r,"aria-busy":s||void 0,className:ee("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",h?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground"),onClick:a,disabled:c,children:s?e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):t})}),e.jsx(ze,{sideOffset:6,children:r})]}),Da=({currentBranch:r,localBranches:s,remoteBranches:c,onMerge:h,onRebase:a,disabled:t=!1,isOperating:m=!1,operationLogs:b=[],onOperationComplete:d,mode:y="dialog",defaultTargetBranch:C})=>{const[k,j]=n.useState(!1),[p,o]=n.useState("merge"),[w,R]=n.useState(null),[E,M]=n.useState(!1),[U,V]=n.useState(""),G=n.useRef(null),P=n.useRef(null),A=t||m,$=r||"current branch",z=b.length>0&&b.every(B=>B.status==="done"||B.status==="error"),x=b.some(B=>B.status==="error");n.useEffect(()=>{P.current&&(P.current.scrollTop=P.current.scrollHeight)},[b]);const D=n.useMemo(()=>{const B=U.toLowerCase(),v=new Set(c.map(l=>l.slice(l.indexOf("/")+1)).filter(Boolean)),N=s.filter(l=>l!==r&&!v.has(l));return B?N.filter(l=>l.toLowerCase().includes(B)):N},[U,s,r,c]),J=n.useMemo(()=>{const B=U.toLowerCase();return B?c.filter(v=>v.toLowerCase().includes(B)):c},[U,c]),X=n.useCallback(()=>C&&(c.includes(C)||s.includes(C))?C:null,[C,s,c]),te=()=>{j(!0),R(X()),o("merge"),V("")},q=B=>{R(B),M(!1),V("")},_=()=>{w&&(p==="merge"?h(w):a(w))},re=()=>{m||(R(null),o("merge"),V(""),j(!1))},ie=()=>{m&&!z||(z&&d?.(),R(null),o("merge"),V(""),j(!1))};n.useEffect(()=>{E||V("")},[E]),n.useEffect(()=>{y==="dialog"||w||R(X())},[y,X,w]);const O=m?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{ref:P,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:e.jsx("div",{className:"space-y-2",children:b.map((B,v)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"mt-0.5 shrink-0",children:[B.status==="running"&&e.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),B.status==="done"&&e.jsx(I,{name:"check",className:"size-3.5 text-success"}),B.status==="error"&&e.jsx(I,{name:"close",className:"size-3.5 text-destructive"}),B.status==="pending"&&e.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),e.jsx("span",{className:ee("typography-micro",B.status==="error"&&"text-destructive",B.status==="done"&&"text-muted-foreground",B.status==="running"&&"text-foreground",B.status==="pending"&&"text-muted-foreground/60"),children:B.message})]},v))})}),z?y==="dialog"?e.jsx(_e,{children:e.jsx(T,{variant:"default",size:"sm",onClick:ie,children:x?"Close":"Done"})}):e.jsx("div",{className:"flex justify-end",children:e.jsx(T,{variant:"default",size:"sm",onClick:ie,children:x?"Close":"Done"})}):null]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Operation"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>o("merge"),className:ee("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",p==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{name:"git-merge",className:ee("size-4",p==="merge"?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:ee("typography-ui-label",p==="merge"?"text-foreground":"text-muted-foreground"),children:"Merge"})]}),e.jsx("p",{className:"typography-micro text-muted-foreground",children:"Create a merge commit and preserve branch history."})]}),e.jsxs("button",{type:"button",onClick:()=>o("rebase"),className:ee("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",p==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{name:"git-branch",className:ee("size-4",p==="rebase"?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:ee("typography-ui-label",p==="rebase"?"text-foreground":"text-muted-foreground"),children:"Rebase"})]}),e.jsx("p",{className:"typography-micro text-muted-foreground",children:"Replay your commits on top of the selected branch."})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:p==="merge"?`Branch to merge into ${$}`:"Branch to rebase onto"}),e.jsxs(xs,{open:E,onOpenChange:M,modal:!1,children:[e.jsx(bs,{asChild:!0,children:e.jsxs("button",{type:"button",className:ee(Wn({size:"default"}),"w-full"),children:[e.jsx("span",{className:ee("truncate",!w&&"text-muted-foreground"),children:w||"Select Branch"}),e.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),e.jsx(ys,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:e.jsxs(vs,{className:"h-full min-h-0",children:[e.jsx(ws,{ref:G,placeholder:"Search branches...",value:U,onValueChange:V,onKeyDown:B=>B.stopPropagation()}),e.jsxs(Cs,{className:"h-full min-h-0",disableHorizontal:!0,children:[e.jsx(Ns,{children:"No branches found."}),D.length>0&&e.jsx(Pt,{heading:"Local branches",children:D.map(B=>e.jsx(At,{onSelect:()=>q(B),children:e.jsx("span",{className:"typography-ui-label text-foreground truncate",children:B})},`local-${B}`))}),D.length>0&&J.length>0?e.jsx(Kn,{}):null,J.length>0&&e.jsx(Pt,{heading:"Remote branches",children:J.map(B=>e.jsx(At,{onSelect:()=>q(B),children:e.jsx("span",{className:"typography-ui-label text-foreground truncate",children:B})},`remote-${B}`))})]})]})})]})]}),w?e.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:e.jsx("p",{className:"typography-meta text-muted-foreground",children:p==="merge"?e.jsxs(e.Fragment,{children:["This will merge"," ",e.jsx("span",{className:"font-mono text-foreground",children:w})," ","into"," ",e.jsx("span",{className:"font-mono text-foreground",children:$})]}):e.jsxs(e.Fragment,{children:["This will rebase"," ",e.jsx("span",{className:"font-mono text-foreground",children:$})," ","onto"," ",e.jsx("span",{className:"font-mono text-foreground",children:w})]})})}):null,y==="dialog"?e.jsxs(_e,{className:"gap-2 pt-1",children:[e.jsx(T,{variant:"ghost",size:"sm",onClick:re,children:"Cancel"}),e.jsx(T,{variant:"default",size:"sm",onClick:_,disabled:!w,className:"gap-1.5",children:p==="merge"?e.jsxs(e.Fragment,{children:[e.jsx(I,{name:"git-merge",className:"size-4"}),"Merge"]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{name:"git-branch",className:"size-4"}),"Rebase"]})})]}):e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(T,{variant:"destructive",size:"sm",onClick:re,disabled:A,children:"Reset"}),e.jsx("div",{className:"flex-1"}),e.jsx(T,{variant:"default",size:"sm",onClick:_,disabled:A||!w,children:p==="merge"?"Merge":"Rebase"})]})]});return y==="bare"?O:y==="inline"?e.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[e.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:"Update branch"}),e.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Bring the latest changes into"," ",e.jsx("span",{className:"font-mono text-foreground",children:$}),"."]})]})}),e.jsx("div",{className:"pt-3",children:O})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Pe,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"sm",className:"gap-1.5",onClick:te,disabled:A,children:[m?e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(I,{name:"git-merge",className:"size-4"}),e.jsx("span",{children:"Merge/Rebase"})]})}),e.jsx(ze,{sideOffset:8,children:"Update this branch from another branch."})]}),e.jsx(ve,{open:k,onOpenChange:B=>{B?j(!0):ie()},children:e.jsxs(we,{className:"max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(Ne,{children:"Update branch"}),e.jsx(Fe,{children:m?z?x?"Operation Failed":"Operation Completed":p==="merge"?"Merging In Progress":"Rebasing In Progress":e.jsxs(e.Fragment,{children:["Choose how to bring another branch into"," ",e.jsx("span",{className:"font-mono text-foreground",children:$}),"."]})})]}),O]})})]})},Ba=n.memo(function({open:s,onOpenChange:c,branchOperation:h,currentBranch:a,localBranches:t,remoteBranches:m,defaultTargetBranch:b,onMerge:d,onRebase:y,disabled:C,operationLogs:k,onOperationComplete:j,canShowBranchWorkflows:p}){return e.jsx(ve,{open:s,onOpenChange:o=>{!o&&h!==null||c(o)},children:e.jsxs(we,{className:"max-w-2xl min-h-[26rem]",children:[e.jsxs(Ce,{children:[e.jsx(Ne,{children:"Update branch"}),e.jsxs(Fe,{children:["Bring the latest changes into"," ",e.jsx("span",{className:"font-mono text-foreground",children:a??""}),"."]})]}),p?e.jsx(Da,{mode:"bare",currentBranch:a,localBranches:t,remoteBranches:m,defaultTargetBranch:b??void 0,onMerge:d,onRebase:y,disabled:C,isOperating:h!==null,operationLogs:k,onOperationComplete:j}):e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Branch actions unavailable in this repository state"})]})})}),Ta=({currentDirectory:r,isUpdateBranchDialogOpen:s,setIsUpdateBranchDialogOpen:c,branchOperation:h,currentBranch:a,localBranches:t,remoteBranches:m,updateTargetBranch:b,onMerge:d,onRebase:y,isBusy:C,operationLogs:k,onOperationComplete:j,canShowBranchWorkflows:p,gitLogDialogMode:o,setGitLogDialogMode:w,onRefreshHistory:R,isLogRefreshing:E,log:M,maxCount:U,onMaxCountChange:V,expandedCommitHashes:G,onToggleCommit:P,commitFilesMap:A,loadingCommitHashes:$,onCopyHash:z,historyBranchDivider:x,onConflict:D,onActionSuccess:J,isStashesDialogOpen:X,setIsStashesDialogOpen:te,hasUncommittedChanges:q,hasStagedChanges:_,uncommittedFileCount:re,onStashesChanged:ie,isGitmojiPickerOpen:oe,setIsGitmojiPickerOpen:H,gitmojiEmojis:O,onSelectGitmoji:B,conflictDialogOpen:v,setConflictDialogOpen:N,conflictFiles:l,conflictOperation:F,onAbortConflict:W,onClearConflictState:Z,stashDialogOpen:ue,setStashDialogOpen:le,stashDialogOperation:se,stashDialogBranch:De,onConfirmStashAndRetry:Be})=>e.jsxs(e.Fragment,{children:[e.jsx(Ba,{open:s,onOpenChange:c,branchOperation:h,currentBranch:a,localBranches:t,remoteBranches:m,defaultTargetBranch:b,onMerge:d,onRebase:y,disabled:C,operationLogs:k,onOperationComplete:j,canShowBranchWorkflows:p}),e.jsx($a,{mode:o,onOpenChange:He=>{He||w(null)},onRefresh:R,isRefreshing:E,log:M,maxCount:U,onMaxCountChange:V,expandedCommitHashes:G,onToggleCommit:P,commitFilesMap:A,loadingCommitHashes:$,onCopyHash:z,directory:r??void 0,branchDivider:x,onConflict:D,onActionSuccess:J}),e.jsx(za,{open:X,onOpenChange:te,directory:r,hasUncommittedChanges:q,hasStagedChanges:_,uncommittedFileCount:re,onChanged:ie}),e.jsx(Pa,{open:oe,onOpenChange:H,gitmojis:O,onSelect:B}),r&&e.jsx(Sa,{open:v,onOpenChange:N,conflictFiles:l,directory:r,operation:F,onAbort:W,onClearState:Z}),e.jsx(Aa,{open:ue,onOpenChange:le,operation:se,targetBranch:De,onConfirm:Be})]}),Ga=20,$e=new Map;function Oa(r){return $e.get(r)??null}function _a(r,s){if($e.delete(r),$e.set(r,s),$e.size>Ga){const c=$e.keys().next().value;c!==void 0&&$e.delete(c)}}const It=38,rt=200,Ha=({value:r,onChange:s,placeholder:c,disabled:h=!1,hasTouchInput:a=!1,isMobile:t=!1})=>{const m=n.useRef(null),b=lt(d=>d.inputSpellcheckEnabled);return n.useLayoutEffect(()=>{const d=m.current;if(!d)return;const y=document.activeElement===d,C=()=>{d.style.height=`${It}px`;const j=d.scrollHeight,p=Math.min(Math.max(j,It),rt);d.style.height=`${p}px`,d.style.overflowY=j>rt?"auto":"hidden",j>rt&&!y&&(d.scrollTop=d.scrollHeight)};C();const k=window.requestAnimationFrame(C);return()=>{window.cancelAnimationFrame(k)}},[r]),e.jsx("textarea",{ref:m,value:r,onChange:d=>s(d.target.value),placeholder:c??"Commit message",rows:1,disabled:h,autoCorrect:a?"on":"off",autoCapitalize:a?"sentences":"off",spellCheck:t||b,className:ee("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",h&&"opacity-50"),style:{minHeight:It,maxHeight:rt}})},Ms=({stagedCount:r,commitMessage:s,onCommitMessageChange:c,onCommit:h,onCommitAndPush:a,commitAction:t,hasPendingIndexMutation:m=!1,gitmojiEnabled:b,onOpenGitmojiPicker:d})=>{const y=r>0,C=s.trim()&&y&&t===null&&!m,{isMobile:k,hasTouchInput:j}=qn();return e.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[e.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[e.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"Commit"}),y?null:e.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:"Stage files to enable commit."})]}),e.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[e.jsx(Ha,{value:s,onChange:c,placeholder:"Commit message",disabled:t!==null,hasTouchInput:j,isMobile:k}),b&&e.jsxs(T,{variant:"outline",size:"sm",onClick:d,className:"w-fit",type:"button",children:[e.jsx(I,{name:"emotion-happy",className:"size-4"}),"Add gitmoji"]}),e.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"flex-1"}),e.jsx(T,{size:"sm",variant:"outline",onClick:h,disabled:!C,className:"commit-actions__btn whitespace-nowrap","aria-label":"Commit aria label",children:t==="commit"?e.jsxs(e.Fragment,{children:[e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"commit-actions__label",children:"Committing..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{name:"git-commit",className:"size-4"}),e.jsx("span",{className:"commit-actions__label",children:"Commit"})]})}),k?e.jsxs(Pe,{children:[e.jsx(Ae,{asChild:!0,children:e.jsx(T,{variant:"default",size:"sm",onClick:()=>a(),disabled:!C,className:"h-7 w-7 p-0","aria-label":"Commit and sync",children:t==="commitAndPush"?e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(I,{name:"arrow-up",className:"size-3.5"})})}),e.jsx(ze,{side:"top",children:e.jsx("p",{children:"Commit & sync"})})]}):e.jsx(T,{size:"sm",variant:"default",onClick:()=>a(),disabled:!C,className:"commit-actions__btn","aria-label":"Commit and sync",children:t==="commitAndPush"?e.jsxs(e.Fragment,{children:[e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:"Syncing..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{name:"arrow-up",className:"size-3.5"}),e.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:"Commit & sync"})]})})]})]})]})},Ua=({onOpenStashes:r})=>e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[e.jsx(I,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:"Working tree clean"}),e.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:"All changes have been committed"}),r?e.jsxs(T,{type:"button",variant:"outline",size:"sm",onClick:r,className:"gap-1.5",children:[e.jsx(I,{name:"archive-stack",className:"size-4"}),"Stashes"]}):null]}),Va=({mergeInProgress:r,rebaseInProgress:s,onContinue:c,onAbort:h,onResolveWithAI:a,conflictCount:t=0,isLoading:m=!1})=>{const[b,d]=n.useState(null),y=r&&r.head,C=s&&(s.headName||s.onto),k=y?"merge":C?"rebase":null;if(!k)return null;const j=async()=>{d("continue");try{await c()}finally{d(null)}},p=async()=>{d("abort");try{await h()}finally{d(null)}},o=b!==null,w=t>0,R=k==="merge"?"Merge":"Rebase";let E="";r?E=r.message?`Merging: ${r.message}`:`Merging ${r.head}`:s&&(E=s.headName?`Rebasing ${s.headName} onto ${s.onto||""}`:"Rebase in progress");const M=w?t===1?`${R} in progress: ${t} conflict`:`${R} in progress: ${t} conflicts`:`${R} in progress`,U=w?"Resolve conflicts, then continue the operation.":"All conflicts resolved. Continue to finish the operation.";return e.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:e.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:M}),E&&e.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:E})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:U}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(T,{variant:"ghost",size:"sm",onClick:p,disabled:o||m,className:"gap-1.5",children:[b==="abort"?e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(I,{name:"close",className:"size-4"}),"Abort"]}),w?a&&e.jsx(T,{variant:"default",size:"sm",onClick:a,disabled:o||m,children:"Resolve with AI"}):e.jsxs(T,{variant:"default",size:"sm",onClick:j,disabled:o||m,className:"gap-1.5",children:[b==="continue"?e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(I,{name:"check",className:"size-4"}),"Continue"]})]})]})]})})};function Wa(r,s){const[c,h]=n.useState(new Set),[a,t]=n.useState(new Map),[m,b]=n.useState(new Set),d=n.useRef(a),y=n.useRef(m),C=n.useCallback(j=>{Yn(j).then(p=>{if(p.ok){S.success("Commit hash copied");return}S.error("Failed to copy")})},[]),k=n.useCallback(j=>{h(p=>{const o=new Set(p);return o.has(j)?o.delete(j):o.add(j),o})},[]);return n.useEffect(()=>{d.current=a},[a]),n.useEffect(()=>{y.current=m},[m]),n.useEffect(()=>{if(!r||!s)return;const j=Array.from(c).filter(o=>!d.current.has(o)&&!y.current.has(o));if(j.length===0)return;let p=!1;return b(o=>{const w=new Set(o);for(const R of j)w.add(R);return y.current=w,w}),Promise.all(j.map(o=>s.getCommitFiles(r,o).then(w=>({hash:o,files:w.files})).catch(w=>(console.error("Failed to fetch commit files:",w),{hash:o,files:[]})))).then(o=>{p||(t(w=>{const R=new Map(w);for(const{hash:E,files:M}of o)R.set(E,M);return d.current=R,R}),b(w=>{const R=new Set(w);for(const{hash:E}of o)R.delete(E);return y.current=R,R}))}),()=>{p=!0,b(o=>{let w=!1;const R=new Set(o);for(const E of j)R.delete(E)&&(w=!0);return w?(y.current=R,R):o})}},[c,r,s]),{expandedCommitHashes:c,commitFilesMap:a,loadingCommitHashes:m,handleCopyCommitHash:C,handleToggleCommit:k}}const Ka=r=>{const{remoteNames:s,localBranches:c,worktreeCreatedFromBranch:h,rootBranchHint:a,defaultBranch:t,headBranch:m}=r,b=typeof m=="string"?m.trim():"",d=p=>{if(!p)return"";let o=p.trim();if(!o||o==="HEAD")return"";if(c.includes(o))return o;o.startsWith("refs/heads/")&&(o=o.slice(11)),o.startsWith("heads/")&&(o=o.slice(6)),o.startsWith("remotes/")&&(o=o.slice(8));const w=o.indexOf("/");if(w>0){const R=o.slice(0,w);if(s.has(R)){const E=o.slice(w+1).trim();E&&(o=E)}}return o},y=p=>{const o=d(typeof p=="string"?p:"");return o&&o!==b?o:""},C=y(h);if(C)return C;const k=y(a);if(k)return k;const j=y(t);return j||(c.includes("main")?"main":c.includes("master")?"master":c.includes("develop")?"develop":"main")},qa=r=>{const{baseBranch:s,localBranches:c,remoteBranches:h}=r;return c.includes(s)?!0:h.some(a=>{const t=a.indexOf("/");return t>0&&a.slice(t+1)===s})},Ya=r=>r?r.filter(s=>!s.startsWith("remotes/")).sort():[],Ja=r=>r?r.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],Qa=(r,s,c,h)=>{if(r.length>0)return r;const a=new Set,t=c?.trim();t&&t.includes("/")&&a.add(t.split("/")[0]);for(const m of s){const b=m.indexOf("/");b>0&&a.add(m.slice(0,b))}return a.size===0&&h&&a.add("origin"),Array.from(a).map(m=>({name:m,fetchUrl:h??"",pushUrl:h??""}))},Xa=(r,s)=>{const c=s?.trim().split("/")[0];return(c&&r?.[c])??r?.origin},Za=(r,s,c)=>c?r.map(t=>t.name).map(t=>`${t}/${c}`).find(t=>s.includes(t))??c:null;function er({branches:r,status:s,remotes:c,remoteUrl:h,git:a}){const t=n.useMemo(()=>Ya(r?.all),[r?.all]),m=n.useMemo(()=>Ja(r?.all),[r?.all]),b=n.useMemo(()=>Qa(c,m,s?.tracking,h),[c,m,h,s?.tracking]),d=s?.current??null,y=n.useMemo(()=>Xa(r?.defaultBranches,s?.tracking),[r?.defaultBranches,s?.tracking]),C=n.useMemo(()=>Ka({remoteNames:new Set(b.map(p=>p.name)),localBranches:t,defaultBranch:y,headBranch:d}),[d,y,b,t]),k=!!(d&&C&&d!==C&&(s?.tracking||b.length>0)&&typeof a?.getGitRangeDiff=="function"&&qa({baseBranch:C,localBranches:t,remoteBranches:m})),j=n.useMemo(()=>Za(b,m,C),[C,b,m]);return{localBranches:t,remoteBranches:m,effectiveRemotes:b,currentBranch:d,defaultBranch:y,baseBranch:C,branchScopeAvailable:k,updateTargetBranch:j}}const tr=r=>{if(!r)return null;try{let s=r.trim();s.startsWith("git@")&&(s=`https://${s.slice(4).replace(":","/")}`),s.endsWith(".git")&&(s=s.slice(0,-4));const c=new URL(s);return c.hostname+c.pathname}catch{return null}},sr=(r,s,c)=>{const h=new Map;s&&h.set(s.id,s);const a=tr(c);for(const t of r){if(t.authType!=="token"){h.set(t.id,t);continue}const m=t.host;if(!m){h.set(t.id,t);continue}if(!m.includes("/")){h.set(t.id,t);continue}a&&a===m&&h.set(t.id,t)}return Array.from(h.values())},nr=(r,s,c)=>{if(r?.userName&&r?.userEmail){const h=s.find(a=>a.userName===r.userName&&a.userEmail===r.userEmail);return h||(c&&c.userName===r.userName&&c.userEmail===r.userEmail?c:{id:"local-config",name:r.userName,userName:r.userName,userEmail:r.userEmail,sshKey:r.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return c??null};function ar({profiles:r,globalIdentity:s,currentIdentity:c,remoteUrl:h}){const a=n.useMemo(()=>sr(r,s,h),[r,s,h]),t=n.useMemo(()=>nr(c,r,s),[c,r,s]);return{availableIdentities:a,activeIdentityProfile:t}}function rr({currentSessionId:r,currentDirectory:s}){const[c,h]=n.useState(!1),[a,t]=n.useState([]),[m,b]=n.useState("merge"),d=n.useMemo(()=>r?`pichamber.conflict:${r}`:null,[r]),y=n.useCallback((k,j,p)=>{if(!d||typeof window>"u")return;const o={directory:k,conflictFiles:j,operation:p};window.localStorage.setItem(d,JSON.stringify(o))},[d]),C=n.useCallback(()=>{!d||typeof window>"u"||window.localStorage.removeItem(d)},[d]);return n.useEffect(()=>{if(!d||typeof window>"u"||!s)return;const k=window.localStorage.getItem(d);if(k)try{const j=JSON.parse(k);if(j.directory!==s){window.localStorage.removeItem(d);return}t(j.conflictFiles??[]),b(j.operation??"merge"),h(!0)}catch{window.localStorage.removeItem(d)}},[d,s]),{conflictDialogOpen:c,setConflictDialogOpen:h,conflictFiles:a,setConflictFiles:t,conflictOperation:m,setConflictOperation:b,persistConflictState:y,clearConflictState:C}}const ir=({runMutation:r,onMutationComplete:s,onMutationError:c,onPathsComplete:h,scheduleFlush:a})=>{const t=[];let m=!1;return{enqueue:d=>{const y=t[t.length-1];if(y?.directory===d.directory&&y.direction===d.direction){d.paths.forEach(C=>y.paths.add(C));return}t.push(d)},flush:()=>{if(m)return;const d=t.shift();if(!d)return;m=!0;const y={directory:d.directory,direction:d.direction,paths:Array.from(d.paths),rollback:d.rollback};(async()=>{try{await r(y),s(y)}catch(C){c(y,C)}finally{h(y.paths),m=!1,t.length>0&&a()}})()},clear:()=>{t.length=0},size:()=>t.length,isRunning:()=>m}},or=n.memo(function({file:s,actionLabel:c,actionSymbol:h,onAction:a,onViewDiff:t,onRevert:m,isReverting:b,stats:d,rowPaddingClassName:y,indentPx:C=0,actionAtStart:k=!1,showRevert:j=!0}){const p=Ge.useMemo(()=>ba(s),[s]),o=p.description,w=d?.insertions??0,R=d?.deletions??0,E=Ge.useCallback(G=>{G.key===" "?(G.preventDefault(),a()):G.key==="Enter"&&(G.preventDefault(),t())},[a,t]),M=Ge.useCallback(G=>{G.preventDefault(),G.stopPropagation(),a()},[a]),U=Ge.useCallback(G=>{G.preventDefault(),G.stopPropagation(),m()},[m]),V=e.jsx("button",{type:"button",onClick:M,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":c,title:c,children:h});return e.jsxs("div",{className:`group flex items-center gap-2 py-1.5 cursor-pointer ${y??"px-3"}`,role:"button",tabIndex:0,onClick:t,onKeyDown:E,style:C>0?{paddingLeft:`${C}px`}:void 0,children:[k?V:null,e.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:p.color},title:o,"aria-label":o,children:p.code}),e.jsx(Jn,{filePath:s.path,className:"h-3.5 w-3.5 shrink-0"}),(()=>{const G=s.path.lastIndexOf("/");if(G===-1)return e.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:s.path,children:s.path});const P=s.path.slice(0,G),A=s.path.slice(G);return e.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:s.path,children:[e.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:P}),e.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[e.jsx("span",{className:"text-muted-foreground",children:"/"}),e.jsx("span",{className:"text-foreground",children:A.slice(1)})]})]})})(),e.jsxs("span",{className:"shrink-0 typography-micro",children:[e.jsxs("span",{style:{color:"var(--status-success)"},children:["+",w]}),e.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),e.jsxs("span",{style:{color:"var(--status-error)"},children:["-",R]})]}),j?e.jsxs(Pe,{children:[e.jsx(Ae,{asChild:!0,children:e.jsx("button",{type:"button",onClick:U,disabled:b,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${s.path}`,children:b?e.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):e.jsx(I,{name:"arrow-go-back",className:"size-3.5"})})}),e.jsx(ze,{sideOffset:8,children:"Revert changes"})]}):null,k?null:V]})}),hs=14,Ls=r=>r.replace(/\\/g,"/").replace(/^\/+/,"").trim(),ms=(r,s)=>({id:`dir:${r}`,path:r,name:s,children:new Map,directFiles:[],files:[]}),lr=r=>{const s=ms("","");for(const c of r){const h=Ls(c.path);if(!h)continue;const t=h.split("/").filter(Boolean).slice(0,-1);let m=s;if(m.files.push(c),t.length>0){let b="";for(const d of t){b=b?`${b}/${d}`:d;const y=m.children.get(d);if(y){y.files.push(c),m=y;continue}const C=ms(b,d);C.files.push(c),m.children.set(d,C),m=C}}m.directFiles.push(c)}return s},cr=(r,s)=>{const c=[],h=(a,t)=>{const m=Array.from(a.children.values()).sort((d,y)=>d.path.localeCompare(y.path));for(const d of m)c.push({key:d.id,kind:"directory",depth:t,directory:d}),s.has(d.path)&&h(d,t+1);const b=[...a.directFiles].sort((d,y)=>d.path.localeCompare(y.path));for(const d of b)c.push({key:`file:${Ls(d.path)}`,kind:"file",depth:t,file:d})};return h(r,0),c},dr=1e3,fs=34,Mt=30,it="pl-0 pr-2",Lt=(r,s)=>`${r} ${s}`,ur=({groups:r,diffStats:s,revertingPaths:c,isRevertingAll:h=!1,headerBackgroundClassName:a="bg-sidebar",onVisiblePathsChange:t,onRevertAll:m,onRevertDirectory:b})=>{const d=n.useRef(null),C=lt(v=>v.gitChangesViewMode)==="tree",k=n.useMemo(()=>r.filter(v=>v.entries.length>0),[r]),[j,p]=n.useState(new Set),[o,w]=n.useState(new Set),[R,E]=n.useState(!1),[M,U]=n.useState(null),V=n.useMemo(()=>k.map(v=>lr(v.entries)),[k]),G=n.useMemo(()=>{const v=[];return k.forEach((N,l)=>{Array.from(V[l]?.children.values()??[]).forEach(F=>{v.push(Lt(N.id,F.path))})}),v},[V,k]);n.useEffect(()=>{C&&w(v=>{const N=new Set,l=new Set(G);return v.forEach(F=>{(F.slice(F.indexOf(" ")+1).includes("/")||l.has(F))&&N.add(F)}),G.forEach(F=>N.add(F)),N})},[C,G]);const P=n.useMemo(()=>{const v=[];return k.forEach((N,l)=>{if(v.push({type:"header",key:`header:${N.id}`,groupIndex:l}),!j.has(N.id)){if(C){const F=new Set;o.forEach(Z=>{Z.startsWith(`${N.id} `)&&F.add(Z.slice(N.id.length+1))}),cr(V[l],F).forEach(Z=>{Z.kind==="file"?v.push({type:"file",key:`${N.id}:${Z.key}`,groupIndex:l,file:Z.file,depth:Z.depth}):v.push({type:"directory",key:`${N.id}:${Z.key}`,groupIndex:l,directory:Z.directory,depth:Z.depth})});return}N.entries.forEach(F=>{v.push({type:"file",key:`${N.id}:file:${F.path}`,groupIndex:l,file:F,depth:0})})}}),m&&k.length>0&&v.push({type:"revert-all",key:"revert-all"}),v},[j,o,C,m,V,k]),A=P.length,$=A>=dr,z=ja({count:A,enabled:$,getScrollElement:()=>d.current,estimateSize:()=>fs,overscan:12,getItemKey:v=>P[v]?.key??v}),x=z.getVirtualItems(),D=n.useMemo(()=>{if(!$)return 0;const v=d.current?.scrollTop??0;return x.find(l=>l.end>v)?.index??0},[$,x,d]);n.useEffect(()=>{if(!t)return;const v=N=>N&&N.type==="file"?N.file.path:null;if(A===0){t([]);return}if(!$){const N=[];for(const l of P)if(l.type==="file"&&(N.push(l.file.path),N.length>=Mt))break;t(N);return}t(P.slice(D,D+Math.ceil((d.current?.clientHeight??0)/fs)+Mt).map(N=>v(N)).filter(N=>!!N).slice(0,Mt))},[t,A,P,$,D]);const J=n.useCallback(v=>{p(N=>{const l=new Set(N);return l.has(v)?l.delete(v):l.add(v),l})},[]),X=n.useCallback((v,N)=>{w(l=>{const F=new Set(l),W=Lt(v,N);return F.has(W)?F.delete(W):F.add(W),F})},[]),te=n.useMemo(()=>{const v=new Set;return k.forEach(N=>N.entries.forEach(l=>v.add(l.path))),Array.from(v)},[k]),q=te.length,_=M?h||M.paths.some(v=>c.has(v)):!1,re=n.useCallback(async()=>{!m||h||te.length===0||(await m(te),E(!1))},[te,h,m]),ie=n.useCallback(async()=>{!b||!M||_||(await b(M.paths),U(null))},[_,b,M]),oe=n.useCallback((v,N)=>{const l=j.has(v.id),F=v.entries.length;return e.jsxs("div",{className:ee("sticky top-0 z-10 flex items-center gap-2 py-2",a,it,!N&&"mt-1 border-t border-border/40"),children:[e.jsx("button",{type:"button",onClick:()=>v.onActionAll(v.entries.map(W=>W.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":v.actionAllLabel,title:v.actionAllLabel,children:v.actionSymbol}),e.jsxs("button",{type:"button",onClick:()=>J(v.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!l,children:[e.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:v.title}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:F}),e.jsx(I,{name:"arrow-down-s",className:ee("size-3.5 shrink-0 text-muted-foreground transition-transform",l&&"-rotate-90")})]})]})},[j,a,J]),H=n.useCallback((v,N,l)=>{const F=o.has(Lt(v.id,N.path)),W=N.files.map(ue=>ue.path),Z=h||W.some(ue=>c.has(ue));return e.jsxs("div",{className:ee("group flex items-center gap-2 py-1.5",it),style:{paddingLeft:`${l*hs}px`},children:[e.jsxs("button",{type:"button",onClick:()=>X(v.id,N.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":F?`Collapse directory ${N.path}`:`Expand directory ${N.path}`,children:[F?e.jsx(I,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):e.jsx(I,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:N.path,children:N.name}),e.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:N.files.length})]}),v.showRevertActions!==!1&&b?e.jsx("button",{type:"button",onClick:()=>U({path:N.path,paths:W,count:W.length}),disabled:Z,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${N.path}`,title:"Revert folder changes",children:Z?e.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):e.jsx(I,{name:"arrow-go-back",className:"size-3.5"})}):null,e.jsx("button",{type:"button",onClick:()=>v.onActionAll(N.files.map(ue=>ue.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":v.actionSymbol==="+"?`Stage all changes in ${N.path}`:`Unstage all changes in ${N.path}`,title:v.actionSymbol==="+"?`Stage all changes in ${N.path}`:`Unstage all changes in ${N.path}`,children:v.actionSymbol})]})},[o,h,b,c,X]),O=n.useCallback((v,N)=>{if(v.type==="revert-all")return e.jsx("div",{className:ee("flex justify-end py-2",it),children:e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>E(!0),disabled:h,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[e.jsx(I,{name:"arrow-go-back",className:"size-3.5"}),"Revert all"]})});const l=k[v.groupIndex];if(!l)return null;if(v.type==="header")return oe(l,N);if(v.type==="directory")return H(l,v.directory,v.depth);const F=v.file;return e.jsx(or,{file:F,actionLabel:l.getActionLabel(F.path),actionSymbol:l.actionSymbol,onAction:()=>l.onActionFile(F.path),stats:s?.[F.path],onViewDiff:()=>l.onViewDiff(F.path),onRevert:()=>l.onRevertFile(F.path),isReverting:c.has(F.path)||h,rowPaddingClassName:it,indentPx:v.depth*hs,actionAtStart:!C,showRevert:l.showRevertActions!==!1})},[s,h,C,H,oe,c,k]),B=n.useCallback(v=>{const N=P[v],l=P[v-1];return!N||!l||N.type!=="file"&&N.type!=="directory"||l.type!=="file"&&l.type!=="directory"?!1:l.groupIndex===N.groupIndex},[P]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[e.jsx(Ss,{ref:d,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:$?e.jsx("div",{style:{height:z.getTotalSize(),position:"relative"},children:x.map(v=>{const N=P[v.index];return N?e.jsx("div",{"data-index":v.index,ref:z.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${v.start}px)`},className:ee(B(v.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:O(N,v.index===0)},N.key):null})}):e.jsx("div",{role:"list","aria-label":"Changed files",children:P.map((v,N)=>e.jsx("div",{className:ee("relative",B(N)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:O(v,N===0)},v.key))})}),e.jsx(Qn,{containerRef:d,disableHorizontal:!0})]}),e.jsx(ve,{open:R,onOpenChange:v=>{!h&&!v&&E(!1)},children:e.jsxs(we,{className:"max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(Ne,{children:"Revert all changes?"}),e.jsx(Fe,{children:q===1?`Revert ${q} changed file? This cannot be undone.`:`Revert ${q} changed files? This cannot be undone.`})]}),e.jsxs(_e,{children:[e.jsx(T,{variant:"outline",size:"sm",onClick:()=>E(!1),disabled:h,children:"Cancel"}),e.jsx(T,{variant:"destructive",size:"sm",onClick:()=>{re()},disabled:h,children:h?"Reverting...":"Revert all"})]})]})}),e.jsx(ve,{open:!!M,onOpenChange:v=>{!_&&!v&&U(null)},children:e.jsxs(we,{className:"max-w-md",children:[e.jsxs(Ce,{children:[e.jsx(Ne,{children:"Revert folder changes?"}),e.jsx(Fe,{children:M?M.count===1?`This will discard local changes in ${M.count} file under ${M.path}.`:`This will discard local changes in ${M.count} files under ${M.path}.`:null})]}),e.jsxs(_e,{children:[e.jsx(T,{variant:"outline",size:"sm",onClick:()=>U(null),disabled:_,children:"Cancel"}),e.jsx(T,{variant:"destructive",size:"sm",onClick:()=>{ie()},disabled:_||!M,children:_?"Reverting...":"Revert folder"})]})]})})]})},hr=ks(()=>gs(()=>import("./DiffView-Gh9wjthp.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117])).then(r=>({default:r.DiffView}))),mr=({currentDirectory:r,status:s,isGitRepo:c,isLoadingStatus:h,changeEntries:a,stagedChangeEntries:t,unstagedChangeEntries:m,effectiveRemotes:b,syncAction:d,commitAction:y,commitMessage:C,hasPendingIndexMutation:k,revertingPaths:j,isRevertingAll:p,initialDiffPath:o,initialDiffStaged:w=!1,onSyncAction:R,onMoveChangePaths:E,onRevertFile:M,onRevertAll:U,onCommitMessageChange:V,onCommit:G,onVisiblePathsChange:P,loadDiff:A})=>{const[$,z]=n.useState(()=>o?{type:"diff",path:o,staged:w}:{type:"list"}),[x,D]=n.useState(null),[J,X]=n.useState(null),[te,q]=n.useState(0);n.useEffect(()=>{o&&z(H=>H.type==="diff"&&H.path===o&&H.staged===w?H:{type:"diff",path:o,staged:w})},[o,w]);const _=n.useMemo(()=>$.type==="diff"&&a.some(H=>H.path===$.path),[a,$]);n.useEffect(()=>{if($.type!=="diff"||!_){D(null),X(null);return}let H=!1;return D(null),X(null),A($.path,$.staged).then(O=>{H||D(O)}).catch(O=>{H||X(O instanceof Error?O.message:String(O))}),()=>{H=!0}},[te,A,$,_]);const re=n.useCallback((H,O=!1)=>{z({type:"diff",path:H,staged:O})},[]),ie=n.useMemo(()=>{const H=[];return t.length>0&&H.push({id:"staged",title:"Staged",entries:t,actionSymbol:"-",actionAllLabel:"Unstage all changes",getActionLabel:O=>`Unstage ${O}`,onActionFile:O=>E([O],"unstage"),onActionAll:O=>E(O,"unstage"),onViewDiff:O=>re(O,!0),onRevertFile:M,showRevertActions:!1,accent:!0}),m.length>0&&H.push({id:"unstaged",title:"Changes",entries:m,actionSymbol:"+",actionAllLabel:"Stage all changes",getActionLabel:O=>`Stage ${O}`,onActionFile:O=>E([O],"stage"),onActionAll:O=>E(O,"stage"),onViewDiff:O=>re(O,!1),onRevertFile:M}),H},[re,E,M,t,m]),oe=n.useCallback(H=>e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsx("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:e.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:s?.current||r||""})}),e.jsx("div",{className:"min-h-0 flex-1",children:H})]}),[r,s]);return r?c===null||c===!0&&!s?oe(e.jsx(Ee,{loading:!0,message:"Checking repository..."})):c===!1?oe(e.jsx(n.Suspense,{fallback:e.jsx(Ee,{loading:!0,message:"Loading last turn changes..."}),children:e.jsx(hr,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})):$.type==="diff"?e.jsx(fr,{path:$.path,diff:x,fileExists:_,error:J,onBack:()=>z({type:"list"}),onRetry:()=>q(H=>H+1)}):e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[e.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:s?.current||r}),e.jsx(da,{syncAction:d,remotes:b,onFetch:H=>R("fetch",H),onSync:H=>R("sync",H),disabled:y!==null||h,aheadCount:s?.ahead??0,behindCount:s?.behind??0,trackingRemoteName:s?.tracking?.split("/")[0],hasUncommittedChanges:a.length>0})]}),a.length>0?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-3 pt-2",children:e.jsx(ur,{groups:ie,diffStats:s?.diffStats,revertingPaths:j,onRevertAll:U,isRevertingAll:p,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:P})}),e.jsx("div",{className:"shrink-0 border-t border-border/40 px-3 pb-3 pt-3",children:e.jsx(Ms,{stagedCount:t.length,commitMessage:C,onCommitMessageChange:V,onCommit:()=>{if(!C.trim()){S.error("Enter a commit message");return}if(t.length===0){S.error("Select at least one file to commit");return}G({pushAfter:!1})},onCommitAndPush:()=>{if(!C.trim()){S.error("Enter a commit message");return}if(t.length===0){S.error("Select at least one file to commit");return}G({pushAfter:!0})},commitAction:y,hasPendingIndexMutation:k,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Ee,{icon:!0,message:"Working tree clean",description:"There are no changed files in this workspace."})})]}):oe(e.jsx(Ee,{message:"Select a session or directory to view Git status"}))},Ee=({message:r,description:s,loading:c=!1,icon:h=!1})=>e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[c?e.jsx(I,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,h?e.jsx(I,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:r}),s?e.jsx("p",{className:"typography-meta text-muted-foreground",children:s}):null]})}),fr=({path:r,diff:s,fileExists:c,error:h,onBack:a,onRetry:t})=>{const m=n.useMemo(()=>js(r)||"text",[r]);return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[e.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back",onClick:a,children:e.jsx(I,{name:"arrow-left",className:"size-5"})}),e.jsx("div",{className:"min-w-0 flex-1 px-2",children:e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:r})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:c?h?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),e.jsx("p",{className:"typography-meta text-muted-foreground",children:h}),e.jsx(T,{type:"button",size:"sm",variant:"outline",onClick:t,children:"Retry"})]})}):s?s.isBinary?e.jsx(Ee,{icon:!0,message:"Content of this file cannot be viewed."}):Xn(r)?e.jsx(Ee,{icon:!0,message:"Image diffs are not available in mobile Changes yet."}):e.jsx(Ss,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:e.jsx(Rs,{original:s.original,modified:s.modified,language:m,fileName:r,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):e.jsx(Ee,{loading:!0,message:"Loading diff..."}):e.jsx(Ee,{icon:!0,message:"File is no longer changed",description:"Go back to Changes and refresh the list."})})]})},ps=ks(()=>gs(()=>import("./DiffView-Gh9wjthp.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117])).then(r=>({default:r.DiffView}))),pr=15e3,gr=40,xr=20,Ro=({isActive:r,chrome:s="desktop",initialDiffPath:c=null,initialDiffStaged:h=!1})=>{const{git:a}=ot(),t=Zn(),m=$t(i=>i.currentSessionId),{profiles:b,globalIdentity:d,defaultGitIdentityId:y,loadProfiles:C,loadGlobalIdentity:k,loadDefaultGitIdentityId:j}=ua(es(i=>({profiles:i.profiles,globalIdentity:i.globalIdentity,defaultGitIdentityId:i.defaultGitIdentityId,loadProfiles:i.loadProfiles,loadGlobalIdentity:i.loadGlobalIdentity,loadDefaultGitIdentityId:i.loadDefaultGitIdentityId}))),p=ea(t??null),o=ta(t??null),w=sa(t??null),R=na(t??null),E=aa(t??null),M=ra(t??null),U=ia(t??null),{setActiveDirectory:V,fetchAll:G,ensureAll:P,fetchStatus:A,fetchBranches:$,fetchLog:z,setLogMaxCount:x,fetchIdentity:D,prefetchDiffs:J,clearDiffCache:X,moveStatusPathsOptimistically:te,restoreStatus:q,bumpIndexRevision:_}=oa(es(i=>({setActiveDirectory:i.setActiveDirectory,fetchAll:i.fetchAll,ensureAll:i.ensureAll,fetchStatus:i.fetchStatus,fetchBranches:i.fetchBranches,fetchLog:i.fetchLog,setLogMaxCount:i.setLogMaxCount,fetchIdentity:i.fetchIdentity,prefetchDiffs:i.prefetchDiffs,clearDiffCache:i.clearDiffCache,moveStatusPathsOptimistically:i.moveStatusPathsOptimistically,restoreStatus:i.restoreStatus,bumpIndexRevision:i.bumpIndexRevision})));n.useRef(null);const re=n.useRef(null),ie=n.useRef(null),oe=n.useRef(null),H=n.useRef(!0);n.useEffect(()=>()=>{H.current=!1},[]);const O=n.useCallback(()=>{re.current!==null&&(window.clearTimeout(re.current),re.current=null)},[]),B=n.useCallback(i=>{O(),re.current=window.setTimeout(()=>{re.current=null,st(i)===st(t)&&A(i,a,{silent:!0})},pr)},[O,t,A,a]);n.useEffect(()=>O,[O]);const v=n.useCallback(()=>{ie.current!==null&&(window.clearTimeout(ie.current),ie.current=null)},[]),N=n.useCallback(()=>{ie.current===null&&(ie.current=window.setTimeout(()=>{ie.current=null,oe.current?.()},0))},[]),l=n.useCallback(async(i,u,f)=>{if(u==="stage"){if(a.stageGitFiles){await a.stageGitFiles(i,f);return}await Promise.all(f.map(g=>a.stageGitFile(i,g)));return}if(a.unstageGitFiles){await a.unstageGitFiles(i,f);return}await Promise.all(f.map(g=>a.unstageGitFile(i,g)))},[a]),F=n.useMemo(()=>ir({runMutation:({directory:i,direction:u,paths:f})=>l(i,u,f),onMutationComplete:({directory:i})=>{_(i),B(i)},onMutationError:({directory:i,direction:u,rollback:f},g)=>{f?.(),_(i),B(i);const L=u==="stage"?"Failed to stage changes":"Failed to unstage changes";S.error(g instanceof Error?g.message:L)},onPathsComplete:i=>{Tt(u=>{const f=new Set(u);return i.forEach(g=>f.delete(g)),f})},scheduleFlush:N}),[_,l,N,B]);n.useEffect(()=>(oe.current=F.flush,()=>{oe.current=null}),[F]),n.useEffect(()=>()=>F.clear(),[F]),n.useEffect(()=>v,[v]);const W=n.useMemo(()=>t?Oa(t):null,[t]),Z=la(i=>i.settingsGitmojiEnabled),{gitmojis:ue}=Na(Z),[le,se]=n.useState(W?.commitMessage??""),[De,Be]=n.useState(!1),He=n.useRef(null),[ct,Ue]=n.useState(null),[$s,dt]=n.useState(!1),[ut,zt]=n.useState(null),[pe,Ps]=n.useState(25),[As,Dt]=n.useState(!1),{triggerFireworks:zs}=ha(),Bt=n.useRef(new Map),Ve=n.useRef(0),ht=n.useCallback(()=>{Ve.current+=1,H.current&&Dt(!0)},[]),mt=n.useCallback(()=>{Ve.current=Math.max(0,Ve.current-1),H.current&&Ve.current===0&&Dt(!1)},[]),[ft,We]=n.useState(new Set),[Ds,Tt]=n.useState(new Set),[pt,Gt]=n.useState(!1),[Ot,Bs]=n.useState([]),[br,Ts]=n.useState(0),[Gs,_t]=n.useState(!1),Ht=Ds.size>0||F.size()>0||F.isRunning();n.useCallback(()=>{const i=He.current;i&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{i.scrollTo({top:i.scrollHeight,behavior:"smooth"})})})},[]);const{expandedCommitHashes:Os,commitFilesMap:_s,loadingCommitHashes:Hs,handleCopyCommitHash:Us,handleToggleCommit:Vs}=Wa(t,a),{conflictDialogOpen:Ws,setConflictDialogOpen:ge,conflictFiles:Ks,setConflictFiles:xe,conflictOperation:Ke,setConflictOperation:be,persistConflictState:ye,clearConflictState:he}=rr({currentSessionId:m,currentDirectory:t}),[qs,gt]=n.useState([]),[Ut,xt]=n.useState(null),[Ys,Vt]=n.useState(null),[Js,bt]=n.useState(null),[Qs,qe]=n.useState([]),[Xs,yt]=n.useState(null),[Zs,Wt]=n.useState(!1),[jt,en]=n.useState(100),[tn,sn]=n.useState(0),[me,Ye]=n.useState(null),[nn,Me]=n.useState(null),[an,vt]=n.useState(!1),[wt,Kt]=n.useState("merge"),[Ct,qt]=n.useState("");n.useEffect(()=>{t&&_a(t,{directory:t,commitMessage:le})},[le,t]),n.useEffect(()=>{r&&(C(),k(),j())},[r,C,k,j]),n.useEffect(()=>{if(!r)return;if(!t||!a?.getRemoteUrl){xt(null);return}let i=!1;return a.getRemoteUrl(t).then(u=>{i||xt(u)}).catch(()=>{i||xt(null)}),()=>{i=!0}},[r,t,a]);const Je=n.useCallback(async()=>{if(!t||!a?.getRemotes){gt([]);return}try{const i=await a.getRemotes(t);H.current&&gt(i)}catch{H.current&&gt([])}},[t,a]);n.useEffect(()=>{r&&Je()},[r,Je]),n.useEffect(()=>{r&&t&&(V(t),P(t,a))},[r,t,V,P,a]),n.useEffect(()=>{if(r&&t)return ca.onGitRefreshHint(i=>{st(i.directory)===st(t)&&(i.paths?.length&&X(t,i.paths),A(t,a,{silent:!0}))})},[r,X,t,A,a]);const Q=n.useCallback(async(i=!0)=>{if(t)try{await Promise.all([A(t,a),$(t,a)])}catch(u){if(i){const f=u instanceof Error?u.message:"Failed to refresh repository";S.error(f)}}},[t,a,A,$]),ne=n.useCallback(async()=>{t&&await z(t,a,pe)},[t,a,z,pe]),Nt=n.useCallback(async()=>{t&&await D(t,a)},[t,a,D]);n.useEffect(()=>{if(!r||!t||!a?.hasLocalIdentity||p!==!0)return;const i=typeof y=="string"?y.trim():"";if(!i||i==="global"||Bt.current.get(t)===i)return;let f=!1;return(async()=>{try{const L=await a.hasLocalIdentity?.(t);if(f||L===!0)return;ht(),await a.setGitIdentity(t,i),Bt.current.set(t,i),await Nt()}catch(L){console.warn("Failed to auto-apply default git identity:",L)}finally{f||mt()}})(),()=>{f=!0}},[r,ht,t,y,mt,a,p,Nt]);const fe=n.useMemo(()=>o?[...o.files??[]].sort((u,f)=>u.path.localeCompare(f.path)):[],[o]),Se=n.useMemo(()=>fe.filter(ts),[fe]),rn=n.useMemo(()=>fe.filter(ya),[fe]);n.useEffect(()=>{if(!t||fe.length===0)return;const i=[],u=new Set,f=L=>{!L||u.has(L)||(u.add(L),i.push(L))};if(Se.forEach(L=>f(L.path)),s==="mobile"&&Ot.forEach(f),fe.slice(0,xr).forEach(L=>f(L.path)),i.length===0)return;const g=window.setTimeout(()=>{J(t,a,i,{maxFiles:gr})},120);return()=>{window.clearTimeout(g)}},[fe,s,t,a,Ot,J,Se]);const Yt=i=>i?.pushed[0]?.remote||o?.tracking?.split("/")[0]||je.find(u=>u.name==="origin")?.name||je[0]?.name||"origin",St=async(i,u)=>{if(t){Ue(i);try{const f=g=>{const L=`${g.name}/`,K=o?.tracking?.startsWith(L)?o.tracking.slice(L.length):void 0;return{remote:g.name,branch:K,rebase:!0}};if(i==="fetch"){if(!u)throw new Error("No remote available for fetch");await a.gitFetch(t,{remote:u.name}),S.success(`Fetched from ${u.name}`)}else if(i==="pull"){if(!u)throw new Error("No remote available for pull");const g=await a.gitPull(t,f(u));S.success(g.files.length===1?`Pulled ${g.files.length} file from ${u.name}`:`Pulled ${g.files.length} files from ${u.name}`)}else if(i==="push"){const g=await a.gitPush(t);S.success(`Pushed to ${Yt(g)}`)}else if(i==="sync"){if(!u)throw new Error("No remote available for sync");let g=0,L=!1;await a.gitFetch(t,{remote:u.name});const K=await a.getGitStatus(t);if((K.behind??0)>0){if((K.files?.length??0)>0){S.error("Commit or stash your changes before syncing");return}g=(await a.gitPull(t,f(u))).files.length}((await a.getGitStatus(t)).ahead??0)>0&&(await a.gitPush(t),L=!0),g>0&&L?S.success(g===1?`Pulled ${g} file from ${u.name} and pushed to upstream`:`Pulled ${g} files from ${u.name} and pushed to upstream`):g>0?S.success(g===1?`Pulled ${g} file from ${u.name}`:`Pulled ${g} files from ${u.name}`):L?S.success(`Pushed to ${u.name}`):S.success("Already up to date")}await Q(!1),await ne()}catch(f){const g=f instanceof Error?f.message:`${i==="sync"?"Sync Changes":i==="pull"?"Pull":i} failed`;S.error(g)}finally{Ue(null)}}},on=n.useCallback(async(i,u)=>{if(!t)throw new Error("No active directory");const f=await a.getGitFileDiff(t,{path:i,staged:u||void 0});return{original:f.original??"",modified:f.modified??"",isBinary:f.isBinary}},[t,a]),ln=n.useCallback(async i=>{if(!t)return;const u=i.name.trim();if(!u){S.error("Remote name is required");return}if(u==="origin"){S.error("Cannot remove the origin remote");return}Vt(u);try{await a.removeRemote(t,{remote:u}),S.success(`Removed remote ${u}`),await Promise.all([Q(!1),Je()])}catch(f){const g=f instanceof Error?f.message:`Failed to remove ${u}`;S.error(g)}finally{Vt(null)}},[t,a,Je,Q]),kt=async(i={})=>{if(!t)return;if(!le.trim()){S.error("Enter a commit message");return}const u=Se.map(g=>g.path).sort();if(u.length===0){S.error("Stage at least one file to commit");return}const f=i.pushAfter?"commitAndPush":"commit";zt(f);try{if(await a.createGitCommit(t,le.trim(),{files:u,stageFiles:[]}),_(t),S.success("Commit created"),se(""),await Q(),i.pushAfter){const g=o?.tracking?.split("/")[0],L=je.find(zn=>zn.name===g)??je[0];if(!L)throw new Error("No remote available");Ue("sync");const K=`${L.name}/`,ae=o?.tracking?.startsWith(K)?o.tracking.slice(K.length):void 0;await a.gitFetch(t,{remote:L.name});const Y=await a.getGitStatus(t);if((Y.behind??0)>0){if((Y.files?.length??0)>0){S.error("Commit or stash your changes before syncing"),await Q(!1);return}await a.gitPull(t,{remote:L.name,branch:ae,rebase:!0})}const de=await a.getGitStatus(t);let Le;(de.ahead??0)>0&&(Le=await a.gitPush(t)),S.success(`Pushed to ${Yt(Le)}`),s!=="mobile"&&zs(),await Q(!1)}else await Q(!1);await ne(),Ts(g=>g+1)}catch(g){const L=g instanceof Error?g.message:"Failed to create commit";S.error(L)}finally{zt(null),i.pushAfter&&Ue(null)}},cn=async(i,u)=>{if(!t||!o)return;const f=o.current??null,g=u?.name??"origin";try{await a.createBranch(t,i,f??"HEAD"),S.success(`Created branch ${i}`),await a.checkoutBranch(t,i);let L=!1;try{await a.gitPush(t,{remote:g,branch:i,options:["--set-upstream"]}),L=!0}catch(K){const ae=K instanceof Error?K.message:`Unable to push new branch to ${g}.`;S.warning("Branch created locally, but failed to set upstream.",{description:e.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",ae]})})}await Q(),await ne(),L&&S.success(`Set upstream for ${i} to ${g}`)}catch(L){const K=L instanceof Error?L.message:"Failed to create branch";throw S.error(K),L}},dn=async(i,u)=>{if(t)try{await a.renameBranch(t,i,u),S.success(`Renamed ${i} to ${u}`),await Q(),await ne()}catch(f){const g=f instanceof Error?f.message:`Failed to rename ${i} to ${u}`;S.error(g)}},un=async i=>{if(!t)return;const u=i.replace(/^remotes\//,"");if(o?.current!==u)try{await a.checkoutBranch(t,u),S.success(`Checked out ${u}`),await Q(),await ne()}catch(f){const g=f instanceof Error?f.message:`Failed to checkout ${u}`;S.error(g)}},hn=async i=>{if(t){ht();try{await a.setGitIdentity(t,i.id),S.success(`Applied identity: ${i.name}`),await Nt()}catch(u){const f=u instanceof Error?u.message:"Failed to apply identity";S.error(f)}finally{mt()}}},{localBranches:Jt,remoteBranches:Qe,effectiveRemotes:je,currentBranch:Ie,baseBranch:Te,branchScopeAvailable:Rt,updateTargetBranch:mn}=er({branches:w,status:o,remotes:qs,remoteUrl:Ut,git:a}),{availableIdentities:fn,activeIdentityProfile:pn}=ar({profiles:b,globalIdentity:d,currentIdentity:E,remoteUrl:Ut}),gn=Se.length,xn=M||ct!==null||ut!==null,Qt=!!Ie;n.useEffect(()=>{if(!t||!a||!R?.all?.length||!Ie||!Te||Ie===Te){Me(null);return}let i=!1;return(async()=>{try{const f=await a.getGitLog(t,{from:Te,to:"HEAD",maxCount:pe});if(i)return;const g=new Set((f?.all??[]).map(K=>K.hash).filter(K=>typeof K=="string"&&K.length>0));if(g.size===0){Me(null);return}const L=R.all.findIndex(K=>!g.has(K.hash));if(L===0){Me(null);return}if(L===-1){Me({insertBeforeIndex:R.all.length,branchName:Ie,direction:"up"});return}Me({insertBeforeIndex:L,branchName:Ie,direction:"up"})}catch{i||Me(null)}})(),()=>{i=!0}},[Te,Ie,t,a,R,pe]),n.useEffect(()=>{yt(null)},[t]),n.useEffect(()=>{if(me!=="graph"||!t){me!=="graph"&&yt(null);return}let i=!1;return Wt(!0),a.getGitLog(t,{maxCount:jt,all:!0}).then(u=>{i||yt(u)}).catch(u=>{console.error("Failed to fetch graph log:",u)}).finally(()=>{i||Wt(!1)}),()=>{i=!0}},[me,t,jt,tn,a]);const bn=n.useCallback((i,u)=>{if(!t||i.length===0)return;const f=Array.from(new Set(i));Tt(L=>{const K=new Set(L);return f.forEach(ae=>K.add(ae)),K});const g=te(t,f,u);F.enqueue({directory:t,direction:u,paths:new Set(f),rollback:()=>q(t,g)}),N()},[t,F,te,q,N]),yn=n.useCallback(async i=>{if(t){We(u=>{const f=new Set(u);return f.add(i),f});try{await a.revertGitFile(t,i,{scope:"working"}),S.success(`Reverted ${i}`),await Q(!1)}catch(u){const f=u instanceof Error?u.message:"Failed to revert changes";S.error(f)}finally{We(u=>{const f=new Set(u);return f.delete(i),f})}}},[t,Q,a]),Xe=n.useCallback(async(i,u,f="all")=>{if(!t||i.length===0)return;const g=Array.from(new Set(i));if(pt||g.some(Y=>ft.has(Y)))return;const L=new Set(Se.map(Y=>Y.path)),K=f==="all"&&g.some(Y=>L.has(Y));u&&Gt(!0),We(Y=>{const de=new Set(Y);return g.forEach(Le=>de.add(Le)),de});const ae=[];try{if(await Promise.all(g.map(async Y=>{try{await a.revertGitFile(t,Y,{scope:f})}catch(de){ae.push({path:Y,message:de instanceof Error?de.message:"Failed to revert changes"})}})),K&&ae.length<g.length&&_(t),await Q(!1),ae.length===0)S.success(g.length===1?`Reverted ${g.length} file`:`Reverted ${g.length} files`);else if(ae.length===g.length)S.error(ae[0]?.message||"Failed to revert changes");else{const Y=g.length-ae.length;S.warning(Y===1?`Reverted ${Y} file, ${ae.length} failed`:`Reverted ${Y} files, ${ae.length} failed`)}}finally{We(Y=>{const de=new Set(Y);return g.forEach(Le=>de.delete(Le)),de}),u&&Gt(!1)}},[_,t,a,pt,Q,ft,Se]),jn=n.useCallback(async i=>{await Xe(i,!0)},[Xe]);n.useCallback(async i=>{await Xe(i,!1,"working")},[Xe]);const vn=n.useCallback(()=>dt(!0),[]),wn=n.useCallback((i,u)=>{const f=u||i;se(g=>{const L=g.trimStart();return L.startsWith(i)||u&&L.startsWith(u)?g:`${f.endsWith(" ")?f:`${f} `}${g}`.trimStart()}),Be(!1)},[]),Ze=n.useCallback(i=>{const u=i instanceof Error?i.message.toLowerCase():"";return u.includes("uncommitted changes")||u.includes("local changes")||u.includes("your local changes would be overwritten")||u.includes("please commit your changes or stash them")||u.includes("cannot rebase: you have unstaged changes")||u.includes("error: cannot pull with rebase")},[]),ke=n.useCallback((i,u)=>{qe(f=>[...f,{message:i,status:u,timestamp:Date.now()}])},[]),ce=n.useCallback((i,u)=>{qe(f=>{if(f.length===0)return f;const g=[...f];return g[g.length-1]={...g[g.length-1],status:i,...u?{message:u}:{}},g})},[]),et=n.useCallback(()=>{qe([])},[]),Cn=n.useCallback(()=>{qe([]),bt(null)},[]),tt=n.useCallback(i=>{const u=i.trim(),f=new Set(je.map(L=>L.name)),g=u.indexOf("/");if(g>0){const L=u.slice(0,g),K=u.slice(g+1);if(f.has(L)&&K)return{branch:u,remote:L,remoteBranch:K}}for(const L of je){const K=`${L.name}/${u}`;if(Qe.includes(K))return{branch:K,remote:L.name,remoteBranch:u}}return{branch:u,remote:null,remoteBranch:null}},[je,Qe]),Nn=n.useCallback(async i=>{if(!t)return;bt("merge"),et();const u=o?.current,f=tt(i);try{f.remote&&f.remoteBranch&&(ke(`Fetching ${f.remote}/${f.remoteBranch}...`,"running"),await a.gitFetch(t,{remote:f.remote,branch:f.remoteBranch}),ce("done",`Fetched ${f.remote}/${f.remoteBranch}`)),ke(`Merging ${f.branch} into ${u}...`,"running");const g=await a.merge(t,{branch:f.branch});g.conflict?(ce("error","Merge conflicts detected"),xe(g.conflictFiles??[]),be("merge"),ge(!0),ye(t,g.conflictFiles??[],"merge")):(ce("done",`Merged ${f.branch} into ${u}`),he(),ke("Refreshing repository status...","running"),await Q(),await ne(),ce("done","Repository status updated"))}catch(g){if(Ze(g))ce("error","Uncommitted changes detected"),Kt("merge"),qt(f.branch),vt(!0);else{const L=g instanceof Error?g.message:`Failed to merge ${f.branch}`;ce("error",L)}}},[t,a,o,tt,Q,ne,Ze,ye,he,ke,ce,et]),Sn=n.useCallback(async i=>{if(!t)return;bt("rebase"),et();const u=o?.current,f=tt(i);try{f.remote&&f.remoteBranch&&(ke(`Fetching ${f.remote}/${f.remoteBranch}...`,"running"),await a.gitFetch(t,{remote:f.remote,branch:f.remoteBranch}),ce("done",`Fetched ${f.remote}/${f.remoteBranch}`)),ke(`Rebasing ${u} onto ${f.branch}...`,"running");const g=await a.rebase(t,{onto:f.branch});g.conflict?(ce("error","Rebase conflicts detected"),xe(g.conflictFiles??[]),be("rebase"),ge(!0),ye(t,g.conflictFiles??[],"rebase")):(ce("done",`Rebased ${u} onto ${f.branch}`),he(),ke("Refreshing repository status...","running"),await Q(),await ne(),ce("done","Repository status updated"))}catch(g){if(Ze(g))ce("error","Uncommitted changes detected"),Kt("rebase"),qt(f.branch),vt(!0);else{const L=g instanceof Error?g.message:`Failed to rebase onto ${f.branch}`;ce("error",L)}}},[t,a,o,tt,Q,ne,Ze,ye,he,ke,ce,et]),kn=n.useCallback(async()=>{if(t)try{Ke==="merge"?(await a.abortMerge(t),S.success("Merge aborted")):(await a.abortRebase(t),S.success("Rebase aborted")),he(),await Q(),await ne()}catch(i){const u=i instanceof Error?i.message:`Failed to abort ${Ke}`;S.error(u)}},[t,a,Ke,Q,ne,he]),Rn=n.useMemo(()=>o?.files?o.files.filter(i=>i.index==="U"||i.working_dir==="U"||i.index==="A"&&i.working_dir==="A"||i.index==="D"&&i.working_dir==="D").length:0,[o?.files]),En=n.useCallback(async()=>{if(t)try{const i=!!o?.mergeInProgress?.head,u=!!(o?.rebaseInProgress?.headName||o?.rebaseInProgress?.onto);if(i){const f=await a.continueMerge(t);f.conflict?(xe(f.conflictFiles??[]),be("merge"),ge(!0),ye(t,f.conflictFiles??[],"merge"),S.error("Merge conflicts detected")):(he(),S.success("Merge completed"),await Q(),await ne())}else if(u){const f=await a.continueRebase(t);f.conflict?(xe(f.conflictFiles??[]),be("rebase"),ge(!0),ye(t,f.conflictFiles??[],"rebase"),S.error("Rebase conflicts detected")):(he(),S.success("Rebase step completed"),await Q(),await ne())}}catch(i){const u=i instanceof Error?i.message:"Failed to continue operation";S.error(u)}},[t,a,o,Q,ne,ye,he]),Fn=n.useCallback(async()=>{if(t)try{!!o?.mergeInProgress?.head?(await a.abortMerge(t),S.success("Merge aborted")):(await a.abortRebase(t),S.success("Rebase aborted")),he(),await Q(),await ne()}catch(i){const u=i instanceof Error?i.message:"Failed to abort operation";S.error(u)}},[t,a,o,Q,ne,he]),In=n.useCallback(()=>{if(!t)return;const u=!!o?.mergeInProgress?.head?"merge":"rebase",f=o?.files?.filter(g=>g.index==="U"||g.working_dir==="U").map(g=>g.path)??[];f.length>0&&xe(f),be(u),ge(!0)},[t,o]),Mn=n.useCallback(async i=>{if(!t)return;const u=o?.current,f=wt,g=Ct,L=(o?.files??[]).some(ts);try{await a.stash(t,{message:`Auto-stash before ${f} with ${g}`,includeUntracked:!0}),L&&_(t)}catch(Y){const de=Y instanceof Error?Y.message:"Failed to stash changes";S.error(de);return}let K=!1,ae=!1;try{if(f==="merge"){const Y=await a.merge(t,{branch:g});Y.conflict?(ae=!0,xe(Y.conflictFiles??[]),be("merge"),ge(!0)):(K=!0,S.success(`Merged ${g} into ${u||""}`))}else{const Y=await a.rebase(t,{onto:g});Y.conflict?(ae=!0,xe(Y.conflictFiles??[]),be("rebase"),ge(!0)):(K=!0,S.success(`Rebased ${u||""} onto ${g}`))}if(i&&K)try{await a.stashPop(t),_(t),S.success("Stashed changes restored")}catch(Y){const de=Y instanceof Error?Y.message:"Failed to restore stash";S.error(de)}else i&&ae&&S.info("Stash restored manually required");await Q(),await ne()}catch(Y){if(i)try{await a.stashPop(t),_(t)}catch{}throw Y}},[_,t,a,o,wt,Ct,Q,ne]),Ln=n.useCallback(i=>{Ps(i),t&&(x(t,i),z(t,a,i))},[t,z,a,x]),$n=n.useCallback(i=>{en(i)},[]),Pn=n.useCallback(()=>{Ye(null),t&&(A(t,a),$(t,a),z(t,a,pe))},[t,A,$,z,pe,a]),An=n.useCallback(i=>{if(i.conflict){if(i.operation==="cherry-pick"||i.operation==="revert"){S.error("Conflict",{description:`Conflicts in: ${i.conflictFiles?.join(", ")??"unknown files"}. Resolve manually and commit, or abort with git cherry-pick/revert --abort.`}),t&&(A(t,a),$(t,a),z(t,a,pe));return}xe(i.conflictFiles??[]),be(i.operation),ge(!0),t&&ye(t,i.conflictFiles??[],i.operation)}},[xe,be,ge,ye,t,A,$,z,pe,a]);return s==="mobile"?e.jsx(mr,{currentDirectory:t??null,status:o,isGitRepo:p,isLoadingStatus:M,changeEntries:fe,stagedChangeEntries:Se,unstagedChangeEntries:rn,effectiveRemotes:je,syncAction:ct,commitAction:ut,commitMessage:le,hasPendingIndexMutation:Ht,revertingPaths:ft,isRevertingAll:pt,initialDiffPath:c,initialDiffStaged:h,onSyncAction:(i,u)=>{St(i,u)},onMoveChangePaths:bn,onRevertFile:i=>{yn(i)},onRevertAll:jn,onCommitMessageChange:se,onCommit:i=>{kt(i)},onVisiblePathsChange:Bs,loadDiff:on}):t?p===null||p===!0&&!o?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"typography-ui-label",children:"Checking repository..."})]})}):p===!1?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(n.Suspense,{fallback:null,children:e.jsx(ps,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})}):e.jsxs("div",{className:ee("flex h-full flex-col overflow-hidden"),children:[e.jsx(ma,{status:o,localBranches:Jt,remoteBranches:Qe,branchInfo:w?.branches,syncAction:ct,remotes:je,onFetch:i=>St("fetch",i),onSync:i=>St("sync",i),onRemoveRemote:ln,removingRemoteName:Ys,onCheckoutBranch:un,onCreateBranch:cn,onRenameBranch:dn,activeIdentityProfile:pn,availableIdentities:fn,onSelectIdentity:hn,isApplyingIdentity:As,isWorktreeMode:!1,onOpenHistory:()=>Ye("history"),onOpenGraph:()=>Ye("graph"),onOpenStashes:vn,onOpenUpdateBranch:Qt?()=>_t(!0):void 0,pullRequest:null,prChecks:null}),t&&(o?.mergeInProgress?.head||o?.rebaseInProgress?.headName||o?.rebaseInProgress?.onto)&&e.jsx(Va,{mergeInProgress:o?.mergeInProgress,rebaseInProgress:o?.rebaseInProgress,onContinue:En,onAbort:Fn,onResolveWithAI:In,conflictCount:Rn,isLoading:M}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col",children:(fe?.length??0)>0||Rt?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(n.Suspense,{fallback:null,children:e.jsx(ps,{diffScope:fe.length>0?"all":"branch",branchBase:Rt?Te:null,branchHead:Rt?Ie:null,showOpenInEditorAction:!0,hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})}),fe.length>0?e.jsx("div",{ref:He,className:"shrink-0 px-4 pb-4 pt-2",children:e.jsx(Ms,{stagedCount:gn,commitMessage:le,onCommitMessageChange:se,onCommit:()=>kt({pushAfter:!1}),onCommitAndPush:()=>kt({pushAfter:!0}),commitAction:ut,hasPendingIndexMutation:Ht,gitmojiEnabled:Z,onOpenGitmojiPicker:()=>Be(!0)})}):null]}):e.jsx(Ua,{onOpenStashes:()=>dt(!0)})})}),e.jsx(Ta,{currentDirectory:t,isUpdateBranchDialogOpen:Gs,setIsUpdateBranchDialogOpen:_t,branchOperation:Js,currentBranch:o?.current,localBranches:Jt,remoteBranches:Qe,updateTargetBranch:mn,onMerge:Nn,onRebase:Sn,isBusy:xn,operationLogs:Qs,onOperationComplete:Cn,canShowBranchWorkflows:Qt,gitLogDialogMode:me,setGitLogDialogMode:Ye,onRefreshHistory:()=>{if(me==="graph"){sn(i=>i+1);return}t&&z(t,a,pe)},isLogRefreshing:me==="graph"?Zs:U,log:me==="graph"?Xs??R:R,maxCount:me==="graph"?jt:pe,onMaxCountChange:me==="graph"?$n:Ln,expandedCommitHashes:Os,onToggleCommit:Vs,commitFilesMap:_s,loadingCommitHashes:Hs,onCopyHash:Us,historyBranchDivider:nn,onConflict:me==="graph"?An:void 0,onActionSuccess:me==="graph"?Pn:void 0,isStashesDialogOpen:$s,setIsStashesDialogOpen:dt,hasUncommittedChanges:(o?.files?.length??0)>0,hasStagedChanges:Se.length>0,uncommittedFileCount:o?.files?.length??0,onStashesChanged:async i=>{t&&i?.affectsIndex&&_(t),await Q(!1),await ne()},isGitmojiPickerOpen:De,setIsGitmojiPickerOpen:Be,gitmojiEmojis:ue,onSelectGitmoji:wn,conflictDialogOpen:Ws,setConflictDialogOpen:ge,conflictFiles:Ks,conflictOperation:Ke,onAbortConflict:kn,onClearConflictState:he,stashDialogOpen:an,setStashDialogOpen:vt,stashDialogOperation:wt,stashDialogBranch:Ct,onConfirmStashAndRetry:Mn})]}):e.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:e.jsx("p",{className:"typography-ui-label text-muted-foreground",children:"Select a session or directory to view Git status"})})};export{Ro as GitView};
@@ -1 +0,0 @@
1
- import{y as H,aE as Z,aF as Fe,ab as Ce,aG as ke,aH as Ie,aI as ze,aJ as Ne,ac as Oe,U as ee,I as te,aK as Ve}from"./useAppFontEffects-8ZU-TTIW.js";import{b as ie,s as Pe,c as Se,d as ne,e as ve,f as Be,h as re,g as I,i as De,j as Ue,k as _e,l as We,R as Ge,I as je,p as se,m as $e,n as Ke,o as qe,q as Je,w as Ye,r as ae,u as Xe,t as Qe,v as Ze,x as et,y as oe,S as tt,z as it,A as nt,B as rt,a as ye,C as he,F as st}from"./web-components-C9ENH49P.js";import{G as at,u as ot,W as ht,a as lt,b as dt,n as le,t as ct}from"./Virtualizer-BSHVMKgK.js";import{j as C,r as k,R as L}from"./vendor-react-B5Z1Mdn3.js";import{o as ut,g as j,l as A,h as ft,q as de,s as pt,t as ce,j as gt,u as ue,a as mt,w as B,x as fe}from"./computeVirtualFileMetrics-D0mQcleY.js";import{a as F,i as q,l as pe,h as Ct,r as St}from"./isFilePlainText-bQAPxqO9.js";import{t as M}from"./vendor-hast-util-to-html-BKBhbTDb.js";let vt=-1;var yt=class{options;onRenderUpdate;workerManager;__id=`file-renderer:${++vt}`;highlighter;renderCache;computedLang="text";lineAnnotations={};lineCache;textDoucmentCache=new WeakMap;constructor(i={theme:H},e,t){this.options=i,this.onRenderUpdate=e,this.workerManager=t,t?.isWorkingPool()!==!0&&(this.highlighter=ie(i.theme??H)?ut():void 0)}setOptions(i){this.options=i}mergeOptions(i){this.options={...this.options,...i}}setLineAnnotations(i){this.lineAnnotations={};for(const e of i){const t=this.lineAnnotations[e.lineNumber]??[];this.lineAnnotations[e.lineNumber]=t,t.push(e)}}cleanUp(){this.recycle(),this.workerManager=void 0,this.onRenderUpdate=void 0}recycle(){this.clearRenderCache(),this.highlighter=void 0,this.workerManager?.cleanUpTasks(this),this.lineCache=void 0}clearRenderCache(){const i=this.renderCache;this.renderCache=void 0,i!=null&&i.isDirty===!0&&i.file.cacheKey!=null&&this.workerManager?.evictFileFromCache(i.file.cacheKey)}hydrate(i){const{options:e}=this.getRenderOptions(i),t=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());let n=this.workerManager?.getFileResultCache(i);n!=null&&!F(e,n.options)&&(n=void 0),this.renderCache??={file:i,options:e,highlighted:!t&&!q(i),result:t?void 0:n?.result,renderRange:void 0},this.workerManager?.isWorkingPool()===!0?this.renderCache.result==null&&!t&&this.workerManager.highlightFileAST(this,i):this.highlighter==null&&(this.computedLang=i.lang??j(i.name),this.initializeHighlighter())}getRenderOptions(i){const e=(()=>{if(this.workerManager?.isWorkingPool()===!0)return this.workerManager.getFileRenderOptions();const{theme:n=H,tokenizeMaxLineLength:r=1e3}=this.options;return{theme:n,useTokenTransformer:Pe(this.options),tokenizeMaxLineLength:r}})(),{renderCache:t}=this;return t?.result==null?{options:e,forceHighlight:!0}:!A(i,t.file)||!F(e,t.options)?{options:e,forceHighlight:!0}:{options:e,forceHighlight:!1}}getOrCreateLineCache(i){if(i.cacheKey==null)return this.lineCache=void 0,pe(i.contents);let{lineCache:e}=this;return(e==null||e.cacheKey!==i.cacheKey)&&(e={cacheKey:i.cacheKey,lines:pe(i.contents)}),this.lineCache=e,e.lines}getLineCount(i){return this.textDoucmentCache.get(i)?.lineCount??this.getOrCreateLineCache(i).length}updateRenderCache(i,e){if(this.renderCache==null)return;const{result:t}=this.renderCache;if(t!=null){for(const[n,r]of i)t.code[n]={type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:r.map(([s,a,o])=>s===0&&a===""?o===""?{type:"element",tagName:"br",properties:{},children:[]}:{type:"text",value:o}:{type:"element",tagName:"span",properties:{"data-char":s,style:`--diffs-token-${e}:${a};`},children:[{type:"text",value:o}]})};t.baseThemeType=e,this.renderCache.isDirty=!0}}applyDocumentChange(i){if(this.renderCache==null)return;const{file:e,result:t}=this.renderCache;if(t!=null&&t.code.length!==i.lineCount){t.code.length=Math.min(t.code.length,i.lineCount);for(let n=t.code.length;n<i.lineCount;n++)t.code.push({type:"element",tagName:"div",properties:{"data-line":n+1,"data-line-type":"context","data-line-index":n},children:[{type:"element",tagName:"span",properties:{"data-char":0},children:[{type:"text",value:i.getLineText(n)}]}]});this.renderCache.isDirty=!0}this.textDoucmentCache.set(e,i)}renderFile(i=this.renderCache?.file,e=Z){if(i==null)return;let{options:t,forceHighlight:n}=this.getRenderOptions(i);const r=this.getMatchingWorkerResultCache(i,t);r!=null&&!this.hasHighlightedRenderCache(i,t)&&(this.renderCache={file:i,highlighted:!0,renderRange:void 0,...r},n=!1),this.renderCache??={file:i,highlighted:!1,options:t,result:void 0,renderRange:void 0};const s=this.getOrCreateLineCache(i),a=i.contents.length>0,o=!a||q(i)||$(s.length,this.getTokenizeMaxLength()),h=!A(i,this.renderCache.file),d=!Se(this.renderCache.renderRange,e);if(this.workerManager?.isWorkingPool()===!0)(o||this.renderCache.result==null||!this.renderCache.highlighted&&(h||d))&&(this.renderCache.file=i,this.renderCache.options=t,this.renderCache.highlighted=!1,(this.renderCache.result==null||h||d||n)&&(this.renderCache.result=this.workerManager.getPlainFileAST(i,e.startingLine,e.totalLines,s)),this.renderCache.renderRange=e),!o&&a&&(!this.renderCache.highlighted||n)&&this.workerManager.highlightFileAST(this,i);else{this.computedLang=i.lang??j(i.name);const l=this.highlighter!=null&&ie(t.theme),c=this.highlighter!=null&&ne(this.computedLang),u=!o&&c;if(this.highlighter!=null&&l&&(n||o||!this.renderCache.highlighted&&u||this.renderCache.result==null)){const{result:p,options:f}=this.renderFileWithHighlighter(i,this.highlighter,o||!c);this.renderCache={file:i,options:f,highlighted:u,result:p,renderRange:void 0}}(!l||!o&&!c)&&this.asyncHighlight(i).then(({result:p,options:f})=>{this.renderCache!=null&&(this.renderCache.highlighted=!1),this.onHighlightSuccess(i,p,f,!o)})}return this.renderCache.result!=null?this.processFileResult(this.renderCache.file,e,this.renderCache.result):void 0}async asyncRender(i,e=Z){const{result:t}=await this.asyncHighlight(i);return this.processFileResult(i,e,t)}async asyncHighlight(i){const e=$(this.getOrCreateLineCache(i).length,this.getTokenizeMaxLength());this.computedLang=e?"text":i.lang??j(i.name);const t=this.highlighter!=null&&Ct(ft(this.options.theme)),n=e||this.highlighter!=null&&ne(this.computedLang);return(this.highlighter==null||!t||!n)&&(this.highlighter=await this.initializeHighlighter()),this.renderFileWithHighlighter(i,this.highlighter,e)}renderFileWithHighlighter(i,e,t=!1){const{options:n}=this.getRenderOptions(i);return{result:St(i,e,n,{forcePlainText:t}),options:n}}processFileResult(i,e,{code:t,themeStyles:n,baseThemeType:r}){const s=this.getLineCount(i),{disableFileHeader:a=!1}=this.options,o=[],h=ue(),d=Math.min(e.startingLine+e.totalLines,s);let l=0;const c=ve(e)?Be(this.lineAnnotations):void 0;c!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:-1,lineIndex:-1,annotations:c.map(u=>I(u))})),l++);for(let u=e.startingLine;u<d;u++){const p=u+1,f=t[u];if(f==null){const g="FileRenderer.processFileResult: Line doesnt exist";throw console.error(g,{name:i.name,lineIndex:u,lineNumber:p}),new Error(g)}h.children.push(pt("context",p,`${u}`)),o.push(f),l++;const S=this.lineAnnotations[p];S!=null&&(h.children.push(de("context","annotation",1)),o.push(re({hunkIndex:0,lineIndex:p,annotations:S.map(g=>I(g))})),l++)}return h.properties.style=`grid-row: span ${l}`,{gutterAST:h.children??[],contentAST:o,preAST:this.createPreElement(s),headerAST:a?void 0:this.renderHeader(i),totalLines:s,rowCount:l,themeStyles:n,baseThemeType:r,bufferBefore:e.bufferBefore,bufferAfter:e.bufferAfter,css:""}}renderHeader(i){const{headerRenderMode:e="default",stickyHeader:t=!1}=this.options;return De({fileOrDiff:i,mode:e,stickyHeader:t})}renderFullHTML(i){return M(this.renderFullAST(i))}renderFullAST(i,e=[]){return e.push(ce({tagName:"code",children:this.renderCodeAST(i),properties:{"data-code":""}})),{...i.preAST,children:e}}renderCodeAST(i){const e=ue();return e.children=i.gutterAST,e.properties.style=`grid-row: span ${i.rowCount}`,[e,Ue(i.contentAST,i.rowCount)]}renderPartialHTML(i,e=!1){return e?M(ce({tagName:"code",children:i,properties:{"data-code":""}})):M(i)}async initializeHighlighter(){return this.highlighter=await gt(_e(this.computedLang,this.options)),this.highlighter}onHighlightSuccess(i,e,t,n=!0){if(this.renderCache==null)return;const r=!A(i,this.renderCache.file)||!this.renderCache.highlighted||!F(t,this.renderCache.options);this.renderCache={file:i,options:t,highlighted:n,result:e,renderRange:void 0},r&&this.onRenderUpdate?.()}getMatchingWorkerResultCache(i,e){const t=this.workerManager?.getFileResultCache(i);if(!(t==null||!F(e,t.options)))return t}hasHighlightedRenderCache(i,e){const{renderCache:t}=this;return t?.result!=null&&t.highlighted&&A(i,t.file)&&F(e,t.options)}onHighlightError(i){console.error(i)}getTokenizeMaxLength(){return this.options.tokenizeMaxLength??1e5}createPreElement(i){const{disableLineNumbers:e=!1,overflow:t="scroll"}=this.options;return We({type:"file",diffIndicators:"none",disableBackground:!0,disableLineNumbers:e,overflow:t,split:!1,totalLines:i})}};function $(i,e){return i>e}function Tt(i,e){return i.lineNumber===e.lineNumber&&i.metadata===e.metadata}function ge(i){return{theme:i?.theme,disableLineNumbers:i?.disableLineNumbers,overflow:i?.overflow,themeType:i?.themeType,collapsed:i?.collapsed,disableFileHeader:i?.disableFileHeader,disableVirtualizationBuffers:i?.disableVirtualizationBuffers,stickyHeader:i?.stickyHeader,preferredHighlighter:i?.preferredHighlighter,useCSSClasses:i?.useCSSClasses,useTokenTransformer:i?.useTokenTransformer,tokenizeMaxLineLength:i?.tokenizeMaxLineLength,tokenizeMaxLength:i?.tokenizeMaxLength,unsafeCSS:i?.unsafeCSS,headerRenderMode:i?.renderCustomHeader!=null?"custom":"default"}}const bt=[""];let Rt=-1;var Te=class{options;workerManager;isContainerManaged;static LoadedCustomComponent=!0;__id=`file:${++Rt}`;type="file";fileContainer;spriteSVG;pre;code;bufferBefore;bufferAfter;themeCSSStyle;appliedThemeCSS;hasAdoptedThemeCSS=!1;unsafeCSSStyle;appliedUnsafeCSS;gutterUtilityContent;errorWrapper;placeHolder;lastRenderedHeaderHTML;cachedHeaderHTML;appliedPreAttributes;lastRowCount;mounted=!1;headerElement;headerCustom;headerPrefix;headerFilenameSuffix;headerMetadata;fileRenderer;resizeManager;interactionManager;annotationCache=new Map;lineAnnotations=[];managersDirty=!1;file;renderRange;enabled=!0;editor;constructor(e={theme:H},t,n=!1){this.options=e,this.workerManager=t,this.isContainerManaged=n,this.fileRenderer=new yt(e,this.handleHighlightRender,this.workerManager),this.resizeManager=new Ge,this.interactionManager=new je("file",se(e)),this.workerManager?.subscribeToThemeChanges(this)}handleHighlightRender=()=>{this.rerender()};rerender(){!this.enabled||this.file==null||this.render({file:this.file,forceRender:!0,renderRange:this.renderRange})}onThemeChange(){this.fileRenderer.clearRenderCache(),this.rerender()}setOptions(e){e!=null&&(this.options=e,this.cachedHeaderHTML=void 0,this.syncInteractionOptions())}syncInteractionOptions(){this.interactionManager.setOptions(se(this.options))}mergeOptions(e){this.options={...this.options,...e}}setThemeType(e){(this.options.themeType??"system")!==e&&(this.mergeOptions({themeType:e}),this.applyCachedThemeState(e))}applyCachedThemeState(e){if(typeof this.options.theme=="string"||this.fileContainer==null||this.appliedThemeCSS==null)return!1;const t=this.appliedThemeCSS.baseThemeType??e;return this.appliedThemeCSS.themeType===t?!1:(this.applyThemeState(this.fileContainer,this.appliedThemeCSS.themeStyles,e,this.appliedThemeCSS.baseThemeType),!0)}hasThemeChanged(){return this.appliedThemeCSS!=null&&!mt(this.appliedThemeCSS.theme,this.options.theme??H)}getHoveredLine=()=>this.interactionManager.getHoveredLine();setLineAnnotations(e){this.lineAnnotations=e}setSelectedLines(e,t){this.interactionManager.setSelection(e,t)}flushManagers(){if(!this.managersDirty||this.pre==null){this.managersDirty=!1;return}const{overflow:e="scroll"}=this.options;this.interactionManager.setup(this.pre),this.resizeManager.setup(this.pre,e==="wrap"),this.managersDirty=!1}cleanUp(e=!1){this.emitPostRender(!0),this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.managersDirty=!1,this.workerManager?.unsubscribeToThemeChanges(this),this.renderRange=void 0,this.isContainerManaged||this.fileContainer?.remove(),this.fileContainer=void 0,this.mounted=!1,e||(this.lineAnnotations=[]),this.annotationCache.clear(),this.pre=void 0,this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0,this.headerElement=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.lastRenderedHeaderHTML=void 0,e||(this.cachedHeaderHTML=void 0),this.errorWrapper=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.placeHolder=void 0,this.unsafeCSSStyle=void 0,e?this.fileRenderer.recycle():(this.fileRenderer.cleanUp(),this.workerManager=void 0,this.file=void 0),this.enabled=!1,this.editor?.cleanUp(),this.editor=void 0}virtualizedSetup(){this.enabled=!0,this.workerManager?.subscribeToThemeChanges(this)}hydrate(e){const{fileContainer:t,prerenderedHTML:n,preventEmit:r=!1,file:s,lineAnnotations:a}=e;this.hydrateElements(t,n),Lt(this.pre,s,this.options.collapsed)||At(this.headerElement,s,this.options.disableFileHeader)?this.render({...e,preventEmit:!0}):this.hydrationSetup({file:s,lineAnnotations:a}),r||this.emitPostRender()}hydrateElements(e,t){this.fileContainer!==e&&this.emitPostRender(!0),$e(e,t);for(const n of Array.from(e.shadowRoot?.children??[])){if(n instanceof SVGElement){this.spriteSVG=n;continue}if(n instanceof HTMLElement){if(n instanceof HTMLPreElement){this.pre=n,this.appliedPreAttributes=void 0;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-theme-css")){this.themeCSSStyle=n;continue}if(n instanceof HTMLStyleElement&&n.hasAttribute("data-unsafe-css")){this.unsafeCSSStyle=n,this.appliedUnsafeCSS=n.textContent;continue}if("diffsHeader"in n.dataset){this.headerElement=n,this.lastRenderedHeaderHTML=void 0;continue}}}this.pre!=null&&(this.syncCodeNodeFromPre(this.pre),this.pre.removeAttribute("data-dehydrated")),this.fileContainer=e,this.hydrateMeasuredScrollbar()}hydrationSetup({file:e,lineAnnotations:t}){this.lineAnnotations=t??this.lineAnnotations,this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),this.pre!=null&&(this.fileRenderer.hydrate(e),this.renderAnnotations(),this.renderGutterUtility(),this.injectUnsafeCSS(),this.managersDirty=!0,this.flushManagers())}getOrCreateLineCache(e=this.file){return e!=null?this.fileRenderer.getOrCreateLineCache(e):bt}updateBuffers(e){this.pre!=null&&this.applyBuffers(this.pre,e)}syncRenderViewToEditor(){const e=this.editor,t=this.fileContainer,n=this.file;e!=null&&t!=null&&n!=null&&this.fileRenderer.initializeHighlighter().then(r=>{e.__syncRenderView(r,t,n,this.lineAnnotations,this.renderRange)})}attachEditor(e){return this.editor?.cleanUp(),this.editor=e,this.interactionManager.setEditorAttached(!0),this.syncRenderViewToEditor(),()=>{this.editor=void 0,this.interactionManager.setEditorAttached(!1)}}applyDocumentChange(e,t){this.fileRenderer.applyDocumentChange(e),t!=null&&t!==this.lineAnnotations&&this.file!=null&&(this.setLineAnnotations(t),this.fileRenderer.setLineAnnotations(this.lineAnnotations),this.renderAnnotations())}updateRenderCache(e,t){this.fileRenderer.updateRenderCache(e,t)}render({file:e,fileContainer:t,forceRender:n=!1,preventEmit:r=!1,containerWrapper:s,deferManagers:a=!1,lineAnnotations:o,renderRange:h}){if(!this.enabled)throw new Error("File.render: attempting to call render after cleaned up");this.editor?.__postponeBackgroundTokenizeToNextFrame();const{collapsed:d=!1,themeType:l="system"}=this.options,c=d?void 0:h,u=this.renderRange,p=this.hasThemeChanged(),f=o!=null&&(o.length>0||this.lineAnnotations.length>0)?o!==this.lineAnnotations:!1,S=!A(this.file,e);if(!d&&!n&&Se(c,this.renderRange)&&!S&&!f&&!p)return this.applyCachedThemeState(l);this.renderRange=c,S&&(this.cachedHeaderHTML=void 0),this.file=e,this.fileRenderer.setOptions(ge(this.options)),this.syncInteractionOptions(),o!=null&&this.setLineAnnotations(o),this.fileRenderer.setLineAnnotations(this.lineAnnotations);const{disableErrorHandling:g=!1,disableFileHeader:y=!1}=this.options;if(y&&(this.headerElement!=null&&(this.headerElement.remove(),this.headerElement=void 0,this.lastRenderedHeaderHTML=void 0),this.clearHeaderSlots()),t=this.getOrCreateFileContainerNode(t,s),this.applyCachedThemeState(l),d){this.removeRenderedCode(),this.clearAuxiliaryNodes();try{const m=this.fileRenderer.renderFile(e,Fe);m!=null&&this.applyThemeState(t,m.themeStyles,l,m.baseThemeType),m?.headerAST!=null&&this.applyHeaderToDOM(m.headerAST,t),this.injectUnsafeCSS()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}try{const m=this.getOrCreatePreNode(t);if(!this.canPartiallyRender(n,f,S||p)||!this.applyPartialRender(u,c)){const v=this.fileRenderer.renderFile(e,c);if(v==null)return this.workerManager?.isInitialized()===!1&&this.workerManager.initialize().then(()=>this.rerender()),!1;this.applyThemeState(t,v.themeStyles,l,v.baseThemeType),v.headerAST!=null&&this.applyHeaderToDOM(v.headerAST,t),this.applyFullRender(v,m)}this.applyBuffers(m,c),this.injectUnsafeCSS(),this.managersDirty=!0,a||this.flushManagers(),this.renderAnnotations(),this.renderGutterUtility(),this.editor!=null&&this.syncRenderViewToEditor()}catch(m){if(g)throw m;console.error(m),m instanceof Error&&this.applyErrorToDOM(m,t)}return r||this.emitPostRender(),!0}emitPostRender(e=!1){const{fileContainer:t,options:{onPostRender:n}}=this;if(e){if(!this.mounted||(this.mounted=!1,t==null))return;n?.(t,this,"unmount");return}if(t==null)return;const r=this.mounted?"update":"mount";this.mounted=!0,n?.(t,this,r)}removeRenderedCode(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferBefore?.remove(),this.bufferBefore=void 0,this.bufferAfter?.remove(),this.bufferAfter=void 0,this.code?.remove(),this.code=void 0,this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0,this.lastRowCount=void 0}clearAuxiliaryNodes(){for(const{element:e}of this.annotationCache.values())e.remove();this.annotationCache.clear(),this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0}canPartiallyRender(e,t,n){return!(e||t||n)}renderPlaceholder(e){if(this.fileContainer==null)return!1;if(this.emitPostRender(!0),this.cleanChildNodes(),this.placeHolder==null){const t=this.fileContainer.shadowRoot??this.fileContainer.attachShadow({mode:"open"});this.placeHolder=document.createElement("div"),this.placeHolder.dataset.placeholder="",t.appendChild(this.placeHolder)}return this.placeHolder.style.setProperty("height",`${e}px`),!0}primeHighlightCache(){const{file:e,workerManager:t}=this;e==null||e.cacheKey==null||t==null||q(e)||this.fileRenderer.getOrCreateLineCache(e).length>(this.options.tokenizeMaxLength??1e5)||t.primeFileHighlightCache(e)}cleanChildNodes(){this.resizeManager.cleanUp(),this.interactionManager.cleanUp(),this.bufferAfter?.remove(),this.bufferBefore?.remove(),this.code?.remove(),this.errorWrapper?.remove(),this.headerElement?.remove(),this.gutterUtilityContent?.remove(),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.pre?.remove(),this.spriteSVG?.remove(),this.themeCSSStyle?.remove(),this.unsafeCSSStyle?.remove(),this.bufferAfter=void 0,this.bufferBefore=void 0,this.code=void 0,this.errorWrapper=void 0,this.headerElement=void 0,this.gutterUtilityContent=void 0,this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0,this.pre=void 0,this.spriteSVG=void 0,this.themeCSSStyle=void 0,this.appliedThemeCSS=void 0,this.hasAdoptedThemeCSS=!1,this.unsafeCSSStyle=void 0,this.appliedUnsafeCSS=void 0,this.lastRenderedHeaderHTML=void 0,this.lastRowCount=void 0,this.mounted=!1}renderAnnotations(){if(this.isContainerManaged||this.fileContainer==null){for(const{element:n}of this.annotationCache.values())n.remove();this.annotationCache.clear();return}const e=new Map(this.annotationCache),{renderAnnotation:t}=this.options;if(t!=null&&this.lineAnnotations.length>0)for(const[n,r]of this.lineAnnotations.entries()){const s=`${n}-${I(r)}`;let a=this.annotationCache.get(s);if(a==null||!Tt(r,a.annotation)){a?.element.remove();const o=t(r);if(o==null)continue;a={element:Ke(I(r)),annotation:r},a.element.appendChild(o),this.fileContainer.appendChild(a.element),this.annotationCache.set(s,a)}e.delete(s)}for(const[n,{element:r}]of e.entries())this.annotationCache.delete(n),r.remove()}renderGutterUtility(){const{renderGutterUtility:e}=this.options;if(this.fileContainer==null||e==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const t=e(this.interactionManager.getHoveredLine);if(t!=null&&this.gutterUtilityContent!=null)return;if(t==null){this.gutterUtilityContent?.remove(),this.gutterUtilityContent=void 0;return}const n=qe();n.appendChild(t),this.fileContainer.appendChild(n),this.gutterUtilityContent=n}injectUnsafeCSS(){const{unsafeCSS:e}=this.options,t=this.fileContainer?.shadowRoot;if(t!=null){if(e==null||e===""){this.unsafeCSSStyle!=null&&(this.unsafeCSSStyle.remove(),this.unsafeCSSStyle=void 0),this.appliedUnsafeCSS=void 0;return}this.unsafeCSSStyle?.parentNode===t&&this.appliedUnsafeCSS===e||(this.unsafeCSSStyle??=Je(),this.unsafeCSSStyle.parentNode!==t&&t.appendChild(this.unsafeCSSStyle),this.unsafeCSSStyle.textContent=Ye(e),this.appliedUnsafeCSS=e)}}applyThemeState(e,t,n,r){const s=e.shadowRoot??e.attachShadow({mode:"open"}),a=r??n,o=this.options.theme??H,h=typeof o=="string"?o:{...o},d=ae(s);if(this.themeCSSStyle?.parentNode===s&&this.appliedThemeCSS?.themeStyles===t&&this.appliedThemeCSS.themeType===a&&this.appliedThemeCSS.scrollbarGutter===d){this.appliedThemeCSS.theme=h;return}if(this.hasAdoptedThemeCSS&&this.themeCSSStyle?.parentNode===s){this.hasAdoptedThemeCSS=!1,this.appliedThemeCSS={theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:d};return}this.themeCSSStyle=Xe({shadowRoot:s,currentNode:this.themeCSSStyle,themeCSS:Qe(t,a,d)}),this.appliedThemeCSS=this.themeCSSStyle!=null?{theme:h,themeStyles:t,themeType:a,baseThemeType:r,scrollbarGutter:d}:void 0}hydrateMeasuredScrollbar(){const e=this.fileContainer?.shadowRoot;e==null||this.themeCSSStyle==null||(this.themeCSSStyle.textContent=Ze(this.themeCSSStyle.textContent??"",ae(e)))}applyFullRender(e,t){this.cleanupErrorWrapper(),this.applyPreNodeAttributes(t,e),this.code=et({code:this.code});const n=this.fileRenderer.renderCodeAST(e);if(this.code.childElementCount>=2)for(let r=0;r<2;r++){const s=this.code.children[r],a=n[r];s.innerHTML=M(a.children),s.style.cssText=a.properties.style}else this.code.innerHTML=M(n);t.contains(this.code)||t.replaceChildren(this.code),this.lastRowCount=e.rowCount}applyPartialRender(e,t){if(e==null||t==null)return!1;const{file:n,code:r}=this,s=r!=null?this.getColumns(r):void 0;if(n==null||r==null||s==null)return!1;const a=e.startingLine,o=t.startingLine,h=e.totalLines===1/0?Number.POSITIVE_INFINITY:a+e.totalLines,d=t.totalLines===1/0?Number.POSITIVE_INFINITY:o+t.totalLines,l=Math.max(a,o),c=Math.min(h,d);if(c<=l||!this.trimDOMToOverlap(s.gutter,l,c)||!this.trimDOMToOverlap(s.content,l,c))return!1;let{length:u}=s.content.children;const p=(y,m)=>{if(!(m<=0))return this.fileRenderer.renderFile(n,{startingLine:y,totalLines:m,bufferBefore:0,bufferAfter:0})},f=o<l?p(o,l-o):void 0;if(f===void 0&&o<l)return!1;const S=d===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:Math.max(0,d-c),g=d>c?p(c,S):void 0;return g===void 0&&d>c?!1:(this.cleanupErrorWrapper(),f!=null&&(s.gutter.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.gutterAST)),s.content.insertAdjacentHTML("afterbegin",this.fileRenderer.renderPartialHTML(f.contentAST)),u+=f.rowCount),g!=null&&(s.gutter.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.gutterAST)),s.content.insertAdjacentHTML("beforeend",this.fileRenderer.renderPartialHTML(g.contentAST)),u+=g.rowCount),this.lastRowCount!==u&&(s.gutter.style.setProperty("grid-row",`span ${u}`),s.content.style.setProperty("grid-row",`span ${u}`),this.lastRowCount=u),!0)}getColumns(e){const t=e.children[0],n=e.children[1];if(!(!(t instanceof HTMLElement)||!(n instanceof HTMLElement)||t.dataset.gutter==null||n.dataset.content==null))return{gutter:t,content:n}}trimDOMToOverlap(e,t,n){const r=this.getDOMBoundaryIndices(e,[t,n]),s=r.get(t)??e.children.length,a=r.get(n)??e.children.length;if(s>a)return!1;for(let o=e.children.length-1;o>=a;o-=1)e.children[o]?.remove();for(let o=s-1;o>=0;o-=1)e.children[o]?.remove();return!0}getDOMBoundaryIndices(e,t){const n=[...new Set(t)].sort((h,d)=>h-d),r=new Map;if(n.length===0)return r;let s=0,a=n[s];const{children:o}=e;a===0&&(r.set(0,0),s+=1,a=n[s]);for(let h=0;h<o.length;h+=1){const d=o[h];if(!(d instanceof HTMLElement))continue;const l=this.getLineIndexFromDOMNode(d);if(l!=null){for(;a!=null&&l>=a;)r.set(a,h),s+=1,a=n[s];if(s>=n.length)break}}for(const h of n)r.has(h)||r.set(h,o.length);return r}getLineIndexFromDOMNode(e){const t=e.dataset.lineIndex;if(t==null)return;const n=Number(t);return Number.isNaN(n)?void 0:n}applyBuffers(e,t){if(t==null||this.shouldDisableVirtualizationBuffers()){this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0);return}t.bufferBefore>0?(this.bufferBefore==null&&(this.bufferBefore=document.createElement("div"),this.bufferBefore.dataset.virtualizerBuffer="before",e.before(this.bufferBefore)),this.bufferBefore.style.setProperty("height",`${t.bufferBefore}px`),this.bufferBefore.style.setProperty("contain","strict")):this.bufferBefore!=null&&(this.bufferBefore.remove(),this.bufferBefore=void 0),t.bufferAfter>0?(this.bufferAfter==null&&(this.bufferAfter=document.createElement("div"),this.bufferAfter.dataset.virtualizerBuffer="after",e.after(this.bufferAfter)),this.bufferAfter.style.setProperty("height",`${t.bufferAfter}px`),this.bufferAfter.style.setProperty("contain","strict")):this.bufferAfter!=null&&(this.bufferAfter.remove(),this.bufferAfter=void 0)}shouldDisableVirtualizationBuffers(){return this.options.disableVirtualizationBuffers??!1}applyHeaderToDOM(e,t){const{file:n}=this;if(n==null)return;this.cleanupErrorWrapper(),this.placeHolder?.remove(),this.placeHolder=void 0;const r=this.cachedHeaderHTML??M(e);if(this.cachedHeaderHTML=r,r!==this.lastRenderedHeaderHTML){const d=document.createElement("div");d.innerHTML=r;const l=d.firstElementChild;if(!(l instanceof HTMLElement))return;this.headerElement!=null?t.shadowRoot?.replaceChild(l,this.headerElement):t.shadowRoot?.prepend(l),this.headerElement=l,this.lastRenderedHeaderHTML=r}if(this.isContainerManaged)return;const{renderHeaderPrefix:s,renderHeaderFilenameSuffix:a,renderCustomHeader:o,renderHeaderMetadata:h}=this.options;if(o!=null){const d=o(n)??void 0;this.headerCustom=this.upsertHeaderSlotElement(t,this.headerCustom,Ce,d),this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0}else{const d=s?.(n)??void 0,l=a?.(n)??void 0,c=h?.(n)??void 0;this.headerPrefix=this.upsertHeaderSlotElement(t,this.headerPrefix,ke,d),this.headerFilenameSuffix=this.upsertHeaderSlotElement(t,this.headerFilenameSuffix,Ie,l),this.headerMetadata=this.upsertHeaderSlotElement(t,this.headerMetadata,ze,c),this.headerCustom?.remove(),this.headerCustom=void 0}}clearHeaderSlots(){this.headerPrefix?.remove(),this.headerFilenameSuffix?.remove(),this.headerMetadata?.remove(),this.headerCustom?.remove(),this.headerPrefix=void 0,this.headerFilenameSuffix=void 0,this.headerMetadata=void 0,this.headerCustom=void 0}upsertHeaderSlotElement(e,t,n,r){if(r==null){t?.remove();return}const s=t??this.createHeaderSlotElement(n);return t==null&&e.appendChild(s),this.replaceHeaderSlotContent(s,r),s}replaceHeaderSlotContent(e,t){e.replaceChildren(),t instanceof Element?e.appendChild(t):e.innerText=`${t}`}createHeaderSlotElement(e){const t=document.createElement("div");return t.slot=e,t}getOrCreateFileContainerNode(e,t){const{fileContainer:n}=this,r=e??n??document.createElement("diffs-container"),s=n!==r;return s&&this.emitPostRender(!0),this.fileContainer=r,n!=null&&s&&(this.lastRenderedHeaderHTML=void 0,this.headerElement=void 0),t!=null&&this.fileContainer.parentNode!==t&&t.appendChild(this.fileContainer),s&&this.adoptReusableShellElements(this.fileContainer),this.ensureSpriteSVG(this.fileContainer),this.fileContainer}adoptReusableShellElements(e){const{shadowRoot:t}=e;if(t!=null)for(const n of t.children)n instanceof SVGElement?this.spriteSVG??=n:oe(n)&&n.hasAttribute("data-theme-css")?(this.themeCSSStyle??=n,this.hasAdoptedThemeCSS=!0):oe(n)&&n.hasAttribute("data-unsafe-css")&&(this.unsafeCSSStyle??=n,this.appliedUnsafeCSS??=this.options.unsafeCSS??void 0)}ensureSpriteSVG(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});if(this.spriteSVG==null){const n=document.createElement("div");n.innerHTML=tt;const r=n.firstChild;r instanceof SVGElement&&(this.spriteSVG=r)}this.spriteSVG!=null&&this.spriteSVG.parentNode!==t&&t.appendChild(this.spriteSVG)}getOrCreatePreNode(e){const t=e.shadowRoot??e.attachShadow({mode:"open"});return this.pre==null?(this.pre=document.createElement("pre"),this.appliedPreAttributes=void 0,this.code=void 0,t.appendChild(this.pre)):this.pre.parentNode!==t&&(e.shadowRoot?.appendChild(this.pre),this.appliedPreAttributes=void 0),this.placeHolder?.remove(),this.placeHolder=void 0,this.pre}syncCodeNodeFromPre(e){this.code=void 0;for(const t of Array.from(e.children))if(t instanceof HTMLElement&&t.hasAttribute("data-code")){this.code=t;return}}applyPreNodeAttributes(e,{totalLines:t}){const{overflow:n="scroll",disableLineNumbers:r=!1}=this.options,s={type:"file",split:!1,overflow:n,disableLineNumbers:r,diffIndicators:"none",disableBackground:!0,totalLines:t};it(s,this.appliedPreAttributes)||(nt(e,s),this.appliedPreAttributes=s)}applyErrorToDOM(e,t){this.cleanupErrorWrapper(),this.pre?.remove(),this.pre=void 0,this.appliedPreAttributes=void 0;const n=t.shadowRoot??t.attachShadow({mode:"open"});this.errorWrapper??=document.createElement("div"),this.errorWrapper.dataset.errorWrapper="",this.errorWrapper.textContent="",n.appendChild(this.errorWrapper);const r=document.createElement("div");r.dataset.errorMessage="",r.innerText=e.message,this.errorWrapper.appendChild(r);const s=document.createElement("pre");s.dataset.errorStack="",s.innerText=e.stack??"No Error Stack",this.errorWrapper.appendChild(s)}cleanupErrorWrapper(){this.errorWrapper?.remove(),this.errorWrapper=void 0}};function Lt(i,e,t=!1){return!t&&i==null&&e!=null}function At(i,e,t=!1){return i==null&&e!=null&&!t}const Ht=5e3;let Mt=-1;function xt(i,e){return(i.overflow??"scroll")!==(e.overflow??"scroll")||(i.collapsed??!1)!==(e.collapsed??!1)||(i.disableLineNumbers??!1)!==(e.disableLineNumbers??!1)||(i.disableFileHeader??!1)!==(e.disableFileHeader??!1)||i.unsafeCSS!==e.unsafeCSS}var wt=class extends Te{virtualizer;metrics;__id=`virtualized-file:${++Mt}`;top;height=0;cache={heights:new Map,checkpoints:[],fileAnnotationHeight:0};isVisible=!1;isSetup=!1;layoutDirty=!0;forceRenderOverride;currentCollapsed;constructor(i,e,t=Ne,n,r=!1){super(i,n,r),this.virtualizer=e,this.metrics=t}setMetrics(i,e=!1){!e&&rt(this.metrics,i)||(this.metrics=i,this.resetLayoutCache())}setLineAnnotations(i){this.syncLineAnnotations(i)&&this.resetLayoutCache()}syncLineAnnotations(i){return i==null||i===this.lineAnnotations||i.length===0&&this.lineAnnotations.length===0?!1:(super.setLineAnnotations(i),!0)}hasLineAnnotations(){return this.lineAnnotations.some(i=>i.lineNumber>0)}getLineHeight(i,e=!1){const t=this.cache.heights.get(i);if(t!=null)return t;const n=e?2:1;return this.metrics.lineHeight*n}setOptions(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setOptions cannot be used inside CodeView. Update CodeView options instead.");if(i==null)return;const{options:e}=this,t=!ye(e,i),n=xt(e,i);super.setOptions(i),n&&this.resetLayoutCache(!0),t&&(this.forceRenderOverride=!0),t&&this.virtualizer.instanceChanged(this,n)}setThemeType(i){if(this.isAdvancedMode())throw new Error("VirtualizedFile.setThemeType cannot be used inside CodeView. Update CodeView options instead.");super.setThemeType(i)}resetLayoutCache(i=!1){this.layoutDirty=!0,this.cache.fileAnnotationHeight=0,this.cache.heights.size>0&&this.cache.heights.clear(),this.cache.checkpoints.length>0&&(this.cache.checkpoints.length=0),this.renderRange!=null&&(this.renderRange=void 0),i&&this.isSimpleMode()&&this.computeApproximateSize()}reconcileHeights(){let i=!1;if(this.fileContainer==null||this.file==null)return this.height!==0&&(i=!0),this.height=0,i;const{overflow:e="scroll"}=this.options;if(this.top=this.getVirtualizedTop(),e==="scroll"&&this.lineAnnotations.length===0&&!this.isResizeDebuggingEnabled()||this.code==null)return i;const t=this.code.children[1];if(!(t instanceof HTMLElement))return i;const n=he(this.lineAnnotations);if(this.renderRange!=null&&n&&ve(this.renderRange)){const r=Et(t)??0;r!==this.cache.fileAnnotationHeight&&(this.cache.fileAnnotationHeight=r,i=!0)}else!n&&this.cache.fileAnnotationHeight!==0&&(this.cache.fileAnnotationHeight=0,i=!0);for(const r of t.children){if(!(r instanceof HTMLElement))continue;const s=r.dataset.lineIndex;if(s==null)continue;const a=Number(s);let o=r.getBoundingClientRect().height,h=!1;r.nextElementSibling instanceof HTMLElement&&("lineAnnotation"in r.nextElementSibling.dataset||"noNewline"in r.nextElementSibling.dataset)&&("noNewline"in r.nextElementSibling.dataset&&(h=!0),o+=r.nextElementSibling.getBoundingClientRect().height);const d=this.getLineHeight(a,h);o!==d&&(i=!0,o===this.metrics.lineHeight*(h?2:1)?this.cache.heights.delete(a):this.cache.heights.set(a,o))}return(i||this.isResizeDebuggingEnabled())&&this.computeApproximateSize(!0),i}onRender=i=>this.fileContainer==null||this.file==null?!1:(i&&(this.top=this.getVirtualizedTop()),this.render({file:this.file}));prepareCodeViewItem(i,e,t,n){const r=this.syncLineAnnotations(n);let s=t?.resetFileLayoutCache===!0||r;t?.metrics!=null&&(this.metrics=t.metrics,s=!0);const{collapsed:a=!1}=this.options;return this.currentCollapsed!==a&&(this.currentCollapsed=a,s=!0),s&&this.resetLayoutCache(),this.file!==i&&(this.layoutDirty=!0),this.file=i,this.top=e,this.computeApproximateSize(),this.height}getLinePosition(i){if(this.file==null||i<1)return;const{disableFileHeader:e=!1,collapsed:t=!1}=this.options,n=this.fileRenderer.getLineCount(this.file)-1;let r=B(this.metrics,e);if(t||n<0)return{top:r,height:0};const s=Math.min(Math.max(i-1,0),n),{overflow:a="scroll"}=this.options,{lineHeight:o}=this.metrics;if(r+=this.cache.fileAnnotationHeight,a==="scroll"&&!this.hasLineAnnotations())return{top:r+s*o,height:o};const h=this.getLayoutCheckpointBeforeLineIndex(s);r=h?.top??r;for(let d=h?.lineIndex??0;d<s;d++)r+=this.getLineHeight(d,!1);return{top:r,height:this.getLineHeight(s,!1)}}getNumericScrollAnchor(i){if(this.file==null||this.renderRange==null)return;const{disableFileHeader:e=!1,collapsed:t=!1,overflow:n="scroll"}=this.options;if(t||this.renderRange.totalLines<=0)return;const r=this.fileRenderer.getLineCount(this.file)-1;if(r<0)return;const s=B(this.metrics,e),a=Math.min(this.renderRange.startingLine,r),o=Math.min(a+this.renderRange.totalLines-1,r);if(o<a)return;const{fileAnnotationHeight:h}=this.cache;if(n==="scroll"&&!this.hasLineAnnotations()){const{lineHeight:l}=this.metrics,c=s+(a===0?h:this.renderRange.bufferBefore),u=a+Math.max(Math.ceil((i-c)/l),0);return u>o?void 0:{lineNumber:u+1,top:s+h+u*l}}let d=s+(a===0?h:this.renderRange.bufferBefore);for(let l=a;l<=o;l++){if(d>=i)return{lineNumber:l+1,top:d};d+=this.getLineHeight(l)}}getVirtualizedHeight(){return this.height}getAdvancedStickySpecs(i){if(this.top==null||this.file==null)return;if(this.options.collapsed===!0)return{topOffset:this.top,height:this.height};const e=i!=null?this.computeRenderRangeFromWindow(this.file,this.top,i):this.renderRange;if(e==null)return;const{bufferBefore:t,bufferAfter:n,totalLines:r}=e;let s=0;if(r===0){const a=i??this.virtualizer.getWindowSpecs();this.top<a.top&&(s=n)}return{topOffset:this.top+t+s,height:this.height-(t+n)}}cleanUp(i=!1){this.fileContainer!=null&&this.isSimpleMode()&&this.getSimpleVirtualizer()?.disconnect(this.fileContainer),i||this.resetLayoutCache(),this.isSetup=!1,super.cleanUp(i)}computeApproximateSize(i=!1){const e=this.isResizeDebuggingEnabled();if(!i&&!this.layoutDirty&&!e)return;const t=this.height===0;if(this.height=0,this.cache.checkpoints=[],this.file==null){this.layoutDirty=!1;return}const{disableFileHeader:n=!1,collapsed:r=!1,overflow:s="scroll"}=this.options,{lineHeight:a}=this.metrics,o=this.fileRenderer.getLineCount(this.file),h=B(this.metrics,n),d=fe(this.metrics);if(this.height+=h,r){this.layoutDirty=!1;return}if(this.height+=this.cache.fileAnnotationHeight,s==="scroll"&&!this.hasLineAnnotations())this.height+=o*a;else for(let l=0;l<o;l++)this.addLayoutCheckpoint(l,this.height),this.height+=this.getLineHeight(l,!1);if(o>0&&(this.height+=d),this.fileContainer!=null&&e&&!t){const l=this.fileContainer.getBoundingClientRect();l.height!==this.height?console.log("VirtualizedFile.computeApproximateSize: computed height doesnt match",{name:this.file.name,elementHeight:l.height,computedHeight:this.height}):console.log("VirtualizedFile.computeApproximateSize: computed height IS CORRECT")}this.layoutDirty=!1}setVisibility(i){this.isAdvancedMode()||this.fileContainer==null||(i&&!this.isVisible?(this.top=this.getVirtualizedTop(),this.isVisible=!0):!i&&this.isVisible&&(this.isVisible=!1,this.rerender()))}rerender(){!this.enabled||this.file==null||(this.forceRenderOverride=!0,this.virtualizer.instanceChanged(this,!1))}applyDocumentChange(i,e,t=!1){const{heights:n,checkpoints:r}=this.cache,s=this.renderRange;if(super.applyDocumentChange(i,e),this.getSimpleVirtualizer()?.markDOMDirty(),this.layoutDirty=!0,n.size>0&&n.clear(),r.length>0&&(r.length=0),this.isSimpleMode()&&this.computeApproximateSize(),t&&s!==void 0&&this.file!==void 0){const a=this.virtualizer.getWindowSpecs(),o=this.computeRenderRangeFromWindow(this.file,this.top??0,a);o.bufferAfter!==s.bufferAfter&&this.updateBuffers(o)}}render({fileContainer:i,file:e,forceRender:t=!1,lineAnnotations:n,...r}){const s=this.file==null||!A(this.file,e),{forceRenderOverride:a,isSetup:o}=this;this.forceRenderOverride=void 0;const h=this.syncLineAnnotations(n);if(h&&this.resetLayoutCache(),this.file=e,i=this.getOrCreateFileContainerNode(i),this.file==null)return console.error("VirtualizedFile.render: attempting to virtually render when we dont have file"),!1;if(o)this.top??=this.getVirtualizedTop(),s&&this.isSimpleMode()&&(this.getSimpleVirtualizer()?.markDOMDirty(),this.resetLayoutCache(!0));else{this.computeApproximateSize();const u=this.getSimpleVirtualizer();if(this.top??=this.getVirtualizedTop(),this.isAdvancedMode())this.isVisible=!0;else{if(u==null)throw new Error("VirtualizedFile.render: simple virtualizer is not available");u.connect(i,this),this.isVisible=u.isInstanceVisible(this.top??0,this.height)}this.isSetup=!0}if(!this.isVisible&&this.isSimpleMode())return this.renderPlaceholder(this.height);const d=this.virtualizer.getWindowSpecs(),l=this.top??0,c=this.computeRenderRangeFromWindow(this.file,l,d);return super.render({file:this.file,fileContainer:i,renderRange:c,lineAnnotations:n,forceRender:(a??t)||h,...r})}syncVirtualizedTop(){this.top=this.getVirtualizedTop()}shouldDisableVirtualizationBuffers(){return this.isAdvancedMode()||super.shouldDisableVirtualizationBuffers()}isSimpleMode(){return this.virtualizer.type==="simple"}isAdvancedMode(){return this.virtualizer.type==="advanced"}addLayoutCheckpoint(i,e){i%Ht===0&&this.cache.checkpoints.push({lineIndex:i,top:e})}getLayoutCheckpointBeforeLineIndex(i){if(i<=0||this.cache.checkpoints.length===0)return;let e=0,t=this.cache.checkpoints.length-1,n;for(;e<=t;){const r=e+t>>1,s=this.cache.checkpoints[r];if(s==null)throw new Error("VirtualizedFile: invalid checkpoint index");s.lineIndex<=i?(n=s,e=r+1):t=r-1}return n}getLayoutCheckpointBeforeTop(i,e){let t=0,n=this.cache.checkpoints.length-1,r=-1;for(;t<=n;){const s=t+n>>1,a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");a.top<=i?(r=s,t=s+1):n=s-1}if(e==null)return r>=0?this.cache.checkpoints[r]:void 0;for(let s=r;s>=0;s--){const a=this.cache.checkpoints[s];if(a==null)throw new Error("VirtualizedFile: invalid checkpoint index");if(a.lineIndex%e===0)return a}}getVirtualizedTop(){return this.virtualizer.type==="advanced"?this.virtualizer.getLocalTopForInstance(this):this.fileContainer!=null?this.virtualizer.getOffsetInScrollContainer(this.fileContainer):0}getSimpleVirtualizer(){return this.virtualizer.type==="simple"?this.virtualizer:void 0}isResizeDebuggingEnabled(){return this.getSimpleVirtualizer()?.config.resizeDebugging??!1}computeRenderRangeFromWindow(i,e,{top:t,bottom:n}){const{disableFileHeader:r=!1,overflow:s="scroll"}=this.options,{hunkLineCount:a,lineHeight:o}=this.metrics,h=this.fileRenderer.getLineCount(i),d=this.height,l=B(this.metrics,r),c=h>0?fe(this.metrics):0,{fileAnnotationHeight:u}=this.cache,p=l+u,f=Math.max(0,d-l-u-c),S=he(this.lineAnnotations),g=e+l,y=u>0&&S&&g<n&&g+u>t;if(e<t-d||e>n)return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};if(h<=a)return{startingLine:0,totalLines:a,bufferBefore:0,bufferAfter:0};const m=Math.ceil(Math.max(n-t,0)/o),v=Math.ceil(m/a)*a+a*2,z=v/a,D=(t+n)/2;if(s==="scroll"&&!this.hasLineAnnotations()){const R=e+p,P=R+f;if(!y&&!(R<n&&P>t))return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};const w=Math.floor(y&&D<e+p?0:(D-(e+p))/o),b=Math.floor(w/a)-Math.floor(z/2),xe=Math.ceil(h/a),E=Math.max(0,Math.min(b,xe))*a,Q=b<0?v+b*a:v,we=E===0?0:u+E*o,Ee=Math.min(Q,h-E);return{startingLine:E,totalLines:Q,bufferBefore:we,bufferAfter:Math.max(0,(h-E-Ee)*o)}}const be=z,N=[],U=this.getLayoutCheckpointBeforeTop(Math.max(0,t-e-v*o*2),a);let T=e+(U?.top??p),_=U?.lineIndex??0,O,V,x;const Re=U?.lineIndex??0;for(let R=Re;R<h;R++){const P=_%a===0,w=Math.floor(_/a);if(P&&(N[w]=T-(e+p),x!=null)){if(x<=0)break;x--}const b=this.getLineHeight(R,!1);T>t-b&&T<n&&(O??=w),T+b>D&&(V??=w),x==null&&T>=n&&P&&(x=be),_++,T+=b}if(O==null)if(y)O=0,V=0;else return{startingLine:0,totalLines:0,bufferBefore:0,bufferAfter:d-l-c};V??=O;const W=Math.round(V-z/2),Le=Math.max(0,Math.ceil(h/a)-z),G=Math.max(0,Math.min(W,Le)),J=G*a,Y=W<0?v+W*a:v,Ae=N[G]??0,He=J===0?0:u+Ae,X=G+Y/a,Me=X<N.length?f-N[X]:f-(T-e-p);return{startingLine:J,totalLines:Y,bufferBefore:He,bufferAfter:Math.max(0,Me)}}};function Et(i){let e;for(const t of i.children)t instanceof HTMLElement&&t.dataset.lineAnnotation===st&&(e=Math.max(e??0,t.getBoundingClientRect().height));return e}function Ft({file:i,renderCustomHeader:e,renderHeaderPrefix:t,renderHeaderFilenameSuffix:n,renderHeaderMetadata:r,renderAnnotation:s,lineAnnotations:a,renderGutterUtility:o,getHoveredLine:h}){const d=e?.(i),l=t?.(i),c=n?.(i),u=r?.(i);return C.jsxs(C.Fragment,{children:[d!=null?C.jsx("div",{slot:Ce,children:d}):C.jsxs(C.Fragment,{children:[l!=null&&C.jsx("div",{slot:"header-prefix",children:l}),c!=null&&C.jsx("div",{slot:"header-filename-suffix",children:c}),u!=null&&C.jsx("div",{slot:"header-metadata",children:u})]}),s!=null&&a?.map((p,f)=>C.jsx("div",{slot:I(p),children:s(p)},f)),o!=null&&C.jsx("div",{slot:"gutter-utility-slot",style:at,children:o(h)})]})}const me=typeof window>"u"?k.useEffect:k.useLayoutEffect;function kt({file:i,options:e,lineAnnotations:t,selectedLines:n,prerenderedHTML:r,metrics:s,hasGutterRenderUtility:a,hasCustomHeader:o,disableWorkerPool:h,contentEditable:d}){const l=ot(),c=n!==void 0,u=k.useContext(ht),p=lt(),f=k.useRef(null),S=dt(g=>{if(g!=null){if(f.current!=null)throw new Error("File: An instance should not already exist when a node is created");l!=null?f.current=new wt(K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),l,s,h?void 0:u,!0):f.current=new Te(K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),h?void 0:u,!0),f.current.hydrate({file:i,fileContainer:g,lineAnnotations:t,prerenderedHTML:r})}else{if(f.current==null)throw new Error("File: A File instance should exist when unmounting");f.current.cleanUp(),f.current=null}});return me(()=>{if(f.current==null)return;const g=K({controlledSelection:c,contentEditable:d,hasCustomHeader:o,hasEditor:p!==void 0,hasGutterRenderUtility:a,options:e}),y=!ye(f.current.options,g);f.current.setOptions(g),f.current.render({file:i,lineAnnotations:t,forceRender:y}),n!==void 0&&f.current.setSelectedLines(n)}),me(()=>{if(d&&f.current!=null){if(p===void 0)throw new Error("File: Editor is not attached");return p.edit(f.current)}},[d,p]),{ref:S,getHoveredLine:k.useCallback(()=>f.current?.getHoveredLine(),[])}}function K({options:i,controlledSelection:e,contentEditable:t,hasCustomHeader:n,hasEditor:r,hasGutterRenderUtility:s}){const a=t&&r,o=e||s||n;if(!o&&!a)return i;let h={...i};return o&&(h={...h,controlledSelection:e,renderCustomHeader:n?le:i?.renderCustomHeader,renderGutterUtility:s?le:i?.renderGutterUtility}),a&&(h={...h,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,lineHoverHighlight:"disabled"}),h}function Ut({file:i,lineAnnotations:e,selectedLines:t,options:n,metrics:r,className:s,style:a,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:d,renderHeaderFilenameSuffix:l,renderHeaderMetadata:c,prerenderedHTML:u,renderGutterUtility:p,disableWorkerPool:f=!1,contentEditable:S=!1}){const{ref:g,getHoveredLine:y}=kt({file:i,options:n,metrics:r,lineAnnotations:e,selectedLines:t,prerenderedHTML:u,hasGutterRenderUtility:p!=null,hasCustomHeader:h!=null,disableWorkerPool:f,contentEditable:S});return C.jsx(Oe,{ref:g,className:s,style:a,children:ct(Ft({file:i,renderAnnotation:o,renderCustomHeader:h,renderHeaderPrefix:d,renderHeaderFilenameSuffix:l,renderHeaderMetadata:c,renderGutterUtility:p,lineAnnotations:e,getHoveredLine:y}),u)})}const _t=L.memo(function({jsonString:e,className:t,maxHeight:n="100%",initiallyExpandedDepth:r=2}){const s=L.useRef(null),[a,o]=L.useState(null),h=L.useMemo(()=>{try{const c=e.trim();if(!c)return o("Empty JSON content"),null;const u=JSON.parse(c);return o(null),u}catch(c){return o(c instanceof Error?c.message:"Invalid JSON"),null}},[e]),d=L.useCallback(()=>{s.current?.expandAll()},[]),l=L.useCallback(()=>{s.current?.collapseAll()},[]);return a?C.jsx("div",{className:t,children:C.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--syntax-base-background)] p-4",children:[C.jsx("div",{className:"mb-1 font-medium text-[var(--surface-foreground)]",children:"Invalid JSON"}),C.jsx("div",{className:"font-mono text-xs text-[var(--surface-mutedForeground)]",children:a})]})}):h===null?null:C.jsxs("div",{className:t,children:[C.jsxs("div",{className:"flex items-center gap-1 border-b border-[var(--interactive-border)] px-2 py-1",children:[C.jsxs(ee,{variant:"ghost",size:"xs",onClick:d,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-down-s",className:"h-3 w-3"}),"Expand All"]}),C.jsxs(ee,{variant:"ghost",size:"xs",onClick:l,className:"gap-1 text-xs text-muted-foreground",children:[C.jsx(te,{name:"arrow-up-s",className:"h-3 w-3"}),"Collapse All"]})]}),C.jsx("div",{className:"bg-[var(--syntax-base-background)] py-1",style:{maxHeight:n,overflow:"auto"},children:C.jsx(Ve,{ref:s,data:h,maxHeight:n,initiallyExpandedDepth:r})})]})});export{Ut as F,_t as J};