@vantran-se/openchamber-web 2.4.2 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/assets/{AboutDialog-Dz_8z7Rq.js → AboutDialog-C8mAGhnz.js} +1 -1
  2. package/dist/assets/{ArchiveView-BoMjLD0N.js → ArchiveView-4-LVDLmf.js} +1 -1
  3. package/dist/assets/{ChangedPathLabel-BirEUxH2.js → ChangedPathLabel-BCiU4QDF.js} +1 -1
  4. package/dist/assets/{CommandPalette-DkLX-AKB.js → CommandPalette-DEcmPHdC.js} +1 -1
  5. package/dist/assets/{DiffView-DwyXDHsF.js → DiffView-CaDZ4gTk.js} +3 -3
  6. package/dist/assets/{FilesView-BFi9HBg1.js → FilesView-Csrs_BGv.js} +1 -1
  7. package/dist/assets/{GitView-BzWRNg_F.js → GitView-DvxCZgCW.js} +3 -3
  8. package/dist/assets/{GuestSurfacePane-zDcKyz78.js → GuestSurfacePane-DNg0xBTD.js} +1 -1
  9. package/dist/assets/{HelpDialog-DZVlv3x2.js → HelpDialog-CLyz3_xd.js} +1 -1
  10. package/dist/assets/{InProgressOperationBanner-BiEntIfh.js → InProgressOperationBanner-BVDKUDqn.js} +2 -2
  11. package/dist/assets/{IntegrationsCatalogView-CCHFMcZP.js → IntegrationsCatalogView-u1gS0Vk8.js} +1 -1
  12. package/dist/assets/{JsonTreeView-BwELoub1.js → JsonTreeView-BpJU14WJ.js} +1 -1
  13. package/dist/assets/{MarkdownRendererImpl-DxBYkSKd.js → MarkdownRendererImpl-t3OoYn_0.js} +1 -1
  14. package/dist/assets/{MemoryDebugPanel-C9zpPXVo.js → MemoryDebugPanel-9z1jGWze.js} +1 -1
  15. package/dist/assets/{OnboardingScreen-Cnzzs_TQ.js → OnboardingScreen-xzT7ckY0.js} +1 -1
  16. package/dist/assets/{OpenCodeStatusDialog-DizE9xAy.js → OpenCodeStatusDialog-skpJZSjK.js} +1 -1
  17. package/dist/assets/{PatchDiff-Cz_UxB-k.js → PatchDiff-BWW_8bob.js} +1 -1
  18. package/dist/assets/{PierreDiffViewer-BT3MrXwN.js → PierreDiffViewer-BZDNV4Uj.js} +1 -1
  19. package/dist/assets/{PlanView-B-SCCd7M.js → PlanView-D7wshtfZ.js} +1 -1
  20. package/dist/assets/{ProjectActionsDialog-4OSNuzpG.js → ProjectActionsDialog-BPh74BCt.js} +1 -1
  21. package/dist/assets/{PullRequestComparisonSelector-lp98DrYm.js → PullRequestComparisonSelector-BBdU2rL1.js} +3 -3
  22. package/dist/assets/{RunOverview-DJhjR9uR.js → RunOverview-Cngm2OOp.js} +2 -2
  23. package/dist/assets/{ScheduledTasksDialog-Dwil7zsx.js → ScheduledTasksDialog-DUjDdkw2.js} +1 -1
  24. package/dist/assets/{SettingsView-DVcV2Rk9.js → SettingsView-CCZOw018.js} +2 -2
  25. package/dist/assets/{SettingsWindow-DbbAS4Se.js → SettingsWindow-Cndsj5Vu.js} +1 -1
  26. package/dist/assets/{SourceBoardView-BVcmYpvE.js → SourceBoardView-8Wp0oUvB.js} +1 -1
  27. package/dist/assets/{SpaceAccessDialog-DxjFUcHZ.js → SpaceAccessDialog-CxfCzTpe.js} +1 -1
  28. package/dist/assets/{SpaceApplyDialog-Dbrbh-j4.js → SpaceApplyDialog-CYp0A76N.js} +1 -1
  29. package/dist/assets/{SpaceRow-Cwam4mHh.js → SpaceRow-CQp4PkPJ.js} +1 -1
  30. package/dist/assets/{SpaceSetupOutput-B_w02jDi.js → SpaceSetupOutput-RNo0mWrR.js} +1 -1
  31. package/dist/assets/{SpacesView-CGrFWnO-.js → SpacesView-BwcDCv3D.js} +1 -1
  32. package/dist/assets/{SubmoduleDiffSummary-DFL-m_eu.js → SubmoduleDiffSummary-BQduif5s.js} +1 -1
  33. package/dist/assets/{ToolOutputDialog-Co0VXa0y.js → ToolOutputDialog-BVCvqYsK.js} +1 -1
  34. package/dist/assets/{ToolPartDiffPreview-CBSzwkat.js → ToolPartDiffPreview-BXpCHBW9.js} +1 -1
  35. package/dist/assets/{UsageStatsView-BjtTNSt8.js → UsageStatsView-CsC_RzAH.js} +1 -1
  36. package/dist/assets/{Virtualizer-Cmng0Q1E.js → Virtualizer-nenVQKi3.js} +1 -1
  37. package/dist/assets/{WalkthroughView-C7AkVuHQ.js → WalkthroughView-CdIYpttA.js} +1 -1
  38. package/dist/assets/{WorktreesView-CYU2KJ6E.js → WorktreesView-D102xE1o.js} +1 -1
  39. package/dist/assets/{appThemeRegistry-CDGE1wtP.js → appThemeRegistry-BWap7OfW.js} +1 -1
  40. package/dist/assets/{ar-BlEU--PN.js → ar-9CiK5cuu.js} +3 -3
  41. package/dist/assets/{computeVirtualFileMetrics-BgqasG86.js → computeVirtualFileMetrics-DDyA16hp.js} +1 -1
  42. package/dist/assets/{de-DWs4Mcjc.js → de-Drq6oIkP.js} +3 -3
  43. package/dist/assets/{decorate-CpxLqoVw.js → decorate-CemSwkUs.js} +1 -1
  44. package/dist/assets/{es-k5T7CE97.js → es-0bkFr34F.js} +3 -3
  45. package/dist/assets/{flexokiTheme-BG4cSAMb.js → flexokiTheme-PoX6Vqyn.js} +1 -1
  46. package/dist/assets/{fr-CzmypgZ8.js → fr-CjgWVupK.js} +3 -3
  47. package/dist/assets/{he-DdkxJnUn.js → he-BrJa9oPB.js} +4 -4
  48. package/dist/assets/{index-BrL960j-.js → index-B2WHEal3.js} +1 -1
  49. package/dist/assets/{initializeSharedPreferences-CrnmmfFs.js → initializeSharedPreferences-1Vo6G7CM.js} +1 -1
  50. package/dist/assets/{install-DvRQsTjX.js → install-FletzeYD.js} +1 -1
  51. package/dist/assets/{isDiffPlainText-KGYbp86N.js → isDiffPlainText-yXcpftjI.js} +1 -1
  52. package/dist/assets/{isFilePlainText-D7rclQrA.js → isFilePlainText-Dpm-_Qu8.js} +1 -1
  53. package/dist/assets/{ja-Qqkyglaf.js → ja-cfyrqWPa.js} +3 -3
  54. package/dist/assets/katex.min-F4TD1ekM.js +69 -0
  55. package/dist/assets/{ko-B8idPK2d.js → ko-herKAlGO.js} +3 -3
  56. package/dist/assets/{main-D4-y6PQ0.js → main-CO7wKNtS.js} +2 -2
  57. package/dist/assets/{main-Cmc8m6dZ.js → main-DN47yDMe.js} +19 -19
  58. package/dist/assets/markdownCore-BY21GJ_M.js +10 -0
  59. package/dist/assets/{miniChat-CjJ77DDL.js → miniChat-BmFJFQph.js} +2 -2
  60. package/dist/assets/{mobile-DlFdLxjR.js → mobile-DTi98S93.js} +2 -2
  61. package/dist/assets/{moveWorkspacePath-CVdEBQ6v.js → moveWorkspacePath-CENAo75W.js} +1 -1
  62. package/dist/assets/{nl-CFXZKHp7.js → nl-mZ4VCoiQ.js} +3 -3
  63. package/dist/assets/{parseDiffFromFile-DWemyyqU.js → parseDiffFromFile-BSmRvd3V.js} +1 -1
  64. package/dist/assets/{pierreDiffTint-B7qPTZmL.js → pierreDiffTint-cyYFR1bm.js} +1 -1
  65. package/dist/assets/{pl-slLgZWDu.js → pl-C98lvkcZ.js} +4 -4
  66. package/dist/assets/{pt-BR-C319g_nn.js → pt-BR-CB63WPLS.js} +3 -3
  67. package/dist/assets/{relocateRestoredSession-cOuWlgWB.js → relocateRestoredSession-D8Sf_FG_.js} +1 -1
  68. package/dist/assets/{renderElectronMiniChatApp-DFnEi5Tr.js → renderElectronMiniChatApp-DmQ8i5jp.js} +2 -2
  69. package/dist/assets/{renderMobileApp-C2TYqVOV.js → renderMobileApp-CND9CafV.js} +3 -3
  70. package/dist/assets/{restartOpenCode-Dvk4CWW7.js → restartOpenCode-D8ExMl55.js} +1 -1
  71. package/dist/assets/{runtimeEndpointReset-D7viEboD.js → runtimeEndpointReset-lg1O2gVX.js} +3 -3
  72. package/dist/assets/{scheduledTasksApi-FZ9stPNl.js → scheduledTasksApi-CJBNpwgy.js} +1 -1
  73. package/dist/assets/{selectionMarkdown-CCursbAw.js → selectionMarkdown-B_3WTOUr.js} +1 -1
  74. package/dist/assets/{shikiHighlight-CLj7Oan9.js → shikiHighlight-DBj_a_TN.js} +1 -1
  75. package/dist/assets/{space-apply-DdhqZWNy.js → space-apply-COMscpEL.js} +1 -1
  76. package/dist/assets/{space-close-KXdazynX.js → space-close-DDLvYCUc.js} +1 -1
  77. package/dist/assets/{spaceNetwork-DzU3SK9K.js → spaceNetwork-CNxs51y4.js} +1 -1
  78. package/dist/assets/{textMateThemeFromAppTheme-C-jxkZJj.js → textMateThemeFromAppTheme-tYpAceV3.js} +1 -1
  79. package/dist/assets/{tr-DNnJ5oqk.js → tr-C5KUa-8X.js} +3 -3
  80. package/dist/assets/{uk-Bw0BJwHw.js → uk-D44Grdmc.js} +3 -3
  81. package/dist/assets/{useAppFontEffects-DAUhSLPu.js → useAppFontEffects-Dm6zEvrf.js} +200 -199
  82. package/dist/assets/{useCallableModelProviders-B-UCRuyn.js → useCallableModelProviders-BK3j8Sde.js} +1 -1
  83. package/dist/assets/{useDiffFindSurface-CU_63uoI.js → useDiffFindSurface-CaCh-qt2.js} +1 -1
  84. package/dist/assets/{useInlineCommentController-bYCeqE6r.js → useInlineCommentController-a2JepiF3.js} +1 -1
  85. package/dist/assets/{useMarkdownLocalAssets-CnMxnDdI.js → useMarkdownLocalAssets-BEApAshz.js} +2 -2
  86. package/dist/assets/{useRootScrollLock-DNYaZ34X.js → useRootScrollLock-mqVhK2HB.js} +2 -2
  87. package/dist/assets/{useWalkthroughReview-DGPyQ634.js → useWalkthroughReview-BspAr9Aa.js} +1 -1
  88. package/dist/assets/{vendor-codemirror-language-data-KulAIuMz.js → vendor-codemirror-language-data-VzNDjH03.js} +2 -2
  89. package/dist/assets/{zh-CN-Brx5Btej.js → zh-CN-DwBC4Qtd.js} +3 -3
  90. package/dist/assets/{zh-TW-WokiutLA.js → zh-TW-DXEqDBAm.js} +3 -3
  91. package/dist/index.html +2 -2
  92. package/dist/mini-chat.html +2 -2
  93. package/dist/mobile.html +2 -2
  94. package/package.json +2 -2
  95. package/server/lib/git/service.test.js +1 -1
  96. package/server/lib/opencode/openchamber-routes.test.js +1 -0
  97. package/server/lib/opencode/settings-helpers.js +2 -2
  98. package/server/lib/opencode/settings-helpers.test.js +1 -1
  99. package/server/lib/opencode/settings-registry.json +1 -1
  100. package/server/lib/outbound-proxy.test.js +2 -2
  101. package/server/lib/spaces/tools.test.js +2 -2
  102. package/dist/assets/katex.min-u4DtE8E5.js +0 -69
  103. package/dist/assets/markdownCore-D_5e0Wl7.js +0 -10
@@ -1,5 +1,5 @@
1
- import{R as i,r as he,j as t,f as Ht}from"./vendor-react-BUCujlKS.js";import{u as it,G as at,L as _t,fH as Na,aL as Or,fb as Tr,A as p,I as _,aR as Js,aS as Ys,be as on,aT as Qs,az as Xs,ay as Zs,as as er,at as tr,au as os,av as ls,B as K,fI as ka,fJ as Va,t as ht,q as mt,D as ft,l as gt,F as jt,y as Er,V as us,W as ds,X as hs,fK as Ra,N as fe,fL as Ia,fM as Pa,fN as Fa,fO as Da,aU as Ba,bT as Ma,c5 as Aa,fP as Oa,fQ as Ta,fR as Ea,fS as La,fT as za,fU as Ga,fV as _a,n as ln,cc as Ha,ca as $a,c9 as Wa,cb as Ua,c3 as Ka,C as qa,o as qs,fW as Ja,z as cs,fX as be,fe as Ya,fj as Qa,fY as Xa,b7 as Za,aE as ei,fZ as ti,dA as Lr,b3 as si,bd as ri,b5 as ni,dx as ai,f_ as ii,b6 as oi,f$ as li,fi as ci,ej as ui,g0 as di,aD as hi,b8 as mi,g1 as fi,fg as gi,b9 as zr,ah as ns,bb as Gr,ba as _r,eX as pi,g2 as xi,a1 as yi,g3 as wi,aA as bi,P as vi,g4 as Hr,fd as ji,g5 as Ci,g6 as $r,cQ as Si,g7 as Ni,g8 as ki,g9 as Vi,ga as $s,gb as Ri,fp as Et,gc as Wr}from"./useAppFontEffects-DAUhSLPu.js";import{u as Ii,b as Pi}from"./main-Cmc8m6dZ.js";import{f as Fi,g as Di,h as Bi,$ as Mi,a0 as Ai,R as Oi,a1 as Ti,X as Ei,V as Li,a2 as zi,a3 as Ws,a4 as Gi,N as _i,a5 as Hi,Y as $i,a6 as Wi,a7 as Ui,a8 as Ki}from"./runtimeEndpointReset-D7viEboD.js";import{u as Ur}from"./vendor-zustand-BAGL70zf.js";import{k as qi,u as zt,a_ as Ji,n as Ke,a5 as ut}from"./katex.min-u4DtE8E5.js";import{R as Yi,I as Qi,C as Xi,a as Zi,b as eo,D as to}from"./InProgressOperationBanner-BiEntIfh.js";import{P as so}from"./PierreDiffViewer-BT3MrXwN.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-CPKyhvxM.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-zod-DDir2TeQ.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-tanstack-react-virtual-Bmi0tTrf.js";import"./vendor-tanstack-virtual-core-CdGDGrnp.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-dar6chwA.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-B66jUSmE.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-DyL0aCoH.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-streamparser-CmlTsbN2.js";import"./vendor-codemirror-lang-javascript-Cem6LjJ8.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CIqXJolH.js";import"./vendor-codemirror-lang-json-C9rLLO0q.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-9qjxcVkg.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-D7VQUxeE.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-Cikh4w2I.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-KulAIuMz.js";import"./vendor-codemirror-lang-python-DVl8-2Op.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-capacitor-core-B4EWRrHz.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-legendapp-list-D2O6oUGf.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./useRootScrollLock-DNYaZ34X.js";import"./moveWorkspacePath-CVdEBQ6v.js";import"./vendor-opencode-client-h8RufjAw.js";import"./ChangedPathLabel-BirEUxH2.js";import"./parseDiffFromFile-DWemyyqU.js";import"./computeVirtualFileMetrics-BgqasG86.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"./vendor-diff-C3JhlQdm.js";import"./isDiffPlainText-KGYbp86N.js";import"./pierreDiffTint-B7qPTZmL.js";import"./Virtualizer-Cmng0Q1E.js";import"./useInlineCommentController-bYCeqE6r.js";import"./appThemeRegistry-CDGE1wtP.js";import"./textMateThemeFromAppTheme-C-jxkZJj.js";const cn="gitmojiCache",ro=1e3*60*60*24*7,un="1",no="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",dn=o=>{if(!o||typeof o!="object")return!1;const e=o;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Us=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(cn);if(!o)return null;const e=JSON.parse(o);return!e||e.version!==un||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(dn),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},ao=o=>{if(!(typeof window>"u"))try{const e={gitmojis:o,fetchedAt:Date.now(),version:un};window.localStorage.setItem(cn,JSON.stringify(e))}catch{return}},Kr=o=>Date.now()-o.fetchedAt<ro;let as=null;const Gt=new Set,qr=async()=>{if(as)return as;const o=(async()=>{try{const e=await fetch(no);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),h=Array.isArray(n.gitmojis)?n.gitmojis.filter(dn):[];return ao(h),Gt.forEach(x=>x(h)),h}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return Gt.forEach(h=>h(n)),n}finally{as=null}})();return as=o,o},io=o=>{const[e,n]=i.useState(()=>o?Us()?.gitmojis??[]:[]),[h,x]=i.useState(!1),g=i.useRef(o);g.current=o,i.useEffect(()=>{if(!o){Gt.delete(n),n([]),x(!1);return}const m=Us();if(m&&(n(m.gitmojis),Kr(m)))return;Gt.add(n),x(!0);let f=!1;return qr().finally(()=>{!f&&g.current&&x(!1)}),()=>{f=!0,Gt.delete(n)}},[o]);const y=i.useCallback(async()=>{if(!g.current)return[];if(e.length>0)return e;const m=Us();return m&&Kr(m)?m.gitmojis:qr()},[e]);return{gitmojis:e,isLoading:h,ensureLoaded:y}},Ct=async(o,e)=>{const n=await qi(`/api/git/integrate/${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const h=await n.json().catch(()=>null);throw new Error(h?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function Lt(o){return Ct("plan",o)}async function oo(o){return Ct("conflict-details",{tempWorktreePath:o})}async function lo(o){return(await Ct("cherry-pick-status",{tempWorktreePath:o})).inProgress}async function co(o){return Ct("run",{plan:o})}async function uo(o){await Ct("abort",{state:o})}async function ho(o){return Ct("continue",{state:o})}const mo=({repoRoot:o,sourceBranch:e,worktreeMetadata:n,localBranches:h,defaultTargetBranch:x,refreshKey:g,onRefresh:y,showHeader:m=!0})=>{const{t:f}=it(),w=at(d=>d.currentSessionId),[M,O]=he.useState(!1),[k,T]=he.useState(""),C=he.useRef(null),z=he.useMemo(()=>_t(h,k,d=>[d]),[h,k]),[P,b]=he.useState(x);he.useEffect(()=>{b(x)},[x]),he.useEffect(()=>{if(M){const d=setTimeout(()=>{C.current?.focus()},0);return()=>clearTimeout(d)}},[M]);const H=!!(o&&e&&P&&P!=="HEAD"&&e!==P),[S,D]=he.useState({kind:"idle"}),[V,F]=he.useState(!1),[G,Z]=he.useState([]),A=he.useMemo(()=>w?`openchamber.integrate.conflict:${w}`:null,[w]);he.useEffect(()=>{if(!A||typeof window>"u")return;const d=window.localStorage.getItem(A);if(!d)return;let c=!1;try{const I=JSON.parse(d);if(!I?.tempWorktreePath||I.repoRoot!==o){window.localStorage.removeItem(A);return}(async()=>{const L=await lo(I.tempWorktreePath).catch(()=>!1);if(c)return;if(!L){window.localStorage.removeItem(A);return}const re=await oo(I.tempWorktreePath).catch(()=>null);c||re&&D({kind:"conflict",state:I,details:re})})()}catch{window.localStorage.removeItem(A)}return()=>{c=!0}},[A,o]),he.useEffect(()=>{if(!H){D({kind:"idle"});return}let d=!1;return D({kind:"loading"}),(async()=>{try{const c=await Lt({repoRoot:o,sourceBranch:e,targetBranch:P});if(d)return;if(D({kind:"ready",plan:c}),c.commits.length>0){const L=c.commits.slice(-50).reverse(),re=await Na(o,L);d||(Z(re),F(!1))}else d||(Z([]),F(!1))}catch{d||D({kind:"idle"})}})(),()=>{d=!0}},[H,o,e,P,g]);const R=he.useCallback(d=>{w&&at.getState().setWorktreeMetadata(w,{...n,createdFromBranch:d})},[w,n]),E=at(d=>d.openNewSessionDraft),a=he.useCallback(async d=>{const c=await Or("git.integrate.cherrypick.resolve.visible",{current_commit:d.state.currentCommit,target_branch:d.state.targetBranch}),I=await Or("git.integrate.cherrypick.resolve.instructions",{repo_root:d.state.repoRoot,temp_worktree_path:d.state.tempWorktreePath,source_branch:d.state.sourceBranch,target_branch:d.state.targetBranch,current_commit:d.state.currentCommit}),L=`Cherry-pick conflict context (JSON)
2
- ${JSON.stringify({repoRoot:d.state.repoRoot,tempWorktreePath:d.state.tempWorktreePath,sourceBranch:d.state.sourceBranch,targetBranch:d.state.targetBranch,currentCommit:d.state.currentCommit,remainingCommits:d.state.remainingCommits,statusPorcelain:d.details.statusPorcelain,unmergedFiles:d.details.unmergedFiles,currentPatchMeta:d.details.currentPatchMeta,currentPatch:d.details.currentPatch,diff:d.details.diff},null,2)}`;return{visibleText:c,instructionsText:I,payloadText:L}},[]),Y=Tr(d=>d.setPendingInputText),q=Tr(d=>d.setPendingSyntheticParts),J=he.useCallback(async(d,c)=>{const I=await a(d);if(c){E({directoryOverride:d.state.tempWorktreePath,initialPrompt:I.visibleText,syntheticParts:[{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}]});return}if(!w){p.error(f("gitView.integrate.noActiveSession"),{description:f("gitView.integrate.noActiveSessionDescription")});return}Y(I.visibleText,"replace"),q([{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}])},[w,a,E,Y,q,f]),j=he.useCallback(async()=>{if(S.kind==="ready"){if(S.plan.commits.length===0){p.message(f("gitView.integrate.noCommitsToMoveToast"));return}D({kind:"running",plan:S.plan});try{const d=await co(S.plan);if(d.kind==="success"){p.success(f("gitView.integrate.commitsMovedToast"),{description:d.moved===1?f("gitView.integrate.commitsMovedDescriptionSingle",{count:d.moved,branch:S.plan.targetBranch}):f("gitView.integrate.commitsMovedDescriptionPlural",{count:d.moved,branch:S.plan.targetBranch})});const c=await Lt(S.plan);D({kind:"ready",plan:c}),y?.();return}d.kind==="conflict"&&(p.error(f("gitView.integrate.cherryPickConflictToast"),{description:f("gitView.integrate.cherryPickConflictDescription")}),D({kind:"conflict",state:d.state,details:d.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,JSON.stringify(d.state)))}catch(d){const c=d instanceof Error?d.message:String(d);p.error(f("gitView.integrate.failedToMoveToast"),{description:c});const I=await Lt({repoRoot:o,sourceBranch:e,targetBranch:P}).catch(()=>null);D(I?{kind:"ready",plan:I}:{kind:"idle"})}}},[S,y,o,e,P,A,f]),U=he.useCallback(async()=>{if(S.kind==="conflict")try{await uo(S.state),p.message(f("gitView.integrate.cherryPickAbortedToast")),A&&typeof window<"u"&&window.localStorage.removeItem(A)}finally{const d=await Lt({repoRoot:o,sourceBranch:e,targetBranch:P}).catch(()=>null);D(d?{kind:"ready",plan:d}:{kind:"idle"})}},[S,o,e,P,A,f]),te=he.useCallback(async()=>{if(S.kind==="conflict")try{const d=await ho(S.state);if(d.kind==="success"){p.success(f("gitView.integrate.cherryPickFinishedToast"));const c=await Lt({repoRoot:o,sourceBranch:e,targetBranch:P}).catch(()=>null);D(c?{kind:"ready",plan:c}:{kind:"idle"}),A&&typeof window<"u"&&window.localStorage.removeItem(A),y?.();return}d.kind==="conflict"&&(D({kind:"conflict",state:d.state,details:d.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,JSON.stringify(d.state)))}catch(d){const c=d instanceof Error?d.message:String(d);p.error(f("gitView.integrate.cherryPickContinueFailedToast"),{description:c})}},[S,o,e,P,y,A,f]);return!o||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[m?t.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(_,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:f("gitView.integrate.title")}),S.kind==="ready"&&S.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:f("gitView.integrate.toMoveCount",{count:S.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:S.kind==="loading"||S.kind==="running"?t.jsx(_,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}):null,t.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:f("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",P]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Js,{open:M,onOpenChange:O,children:[t.jsx(Ys,{asChild:!0,children:t.jsxs("button",{type:"button",className:on({size:"default"}),children:[f("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:P}),t.jsx(_,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Qs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Xs,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Zs,{ref:C,placeholder:f("gitView.branch.searchPlaceholder"),value:k,onValueChange:T,onKeyDown:d=>d.stopPropagation()}),t.jsxs(er,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(tr,{children:f("gitView.branch.empty")}),t.jsx(os,{heading:f("gitView.branch.localBranches"),children:z.map(d=>t.jsx(ls,{value:d,onSelect:()=>{b(d),R(d),O(!1),T("")},children:d},d))})]})]})})]}),S.kind==="ready"?t.jsx(K,{size:"sm",onClick:()=>{j()},disabled:!H||S.plan.commits.length===0,children:f("gitView.integrate.move")}):S.kind==="loading"?t.jsx(K,{size:"sm",variant:"outline",disabled:!0,children:f("gitView.integrate.checking")}):S.kind==="running"?t.jsx(K,{size:"sm",variant:"outline",disabled:!0,children:f("gitView.integrate.moving")}):null]}),S.kind==="ready"&&S.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:f("gitView.integrate.noCommitsToMove")}),S.kind==="ready"&&S.plan.commits.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"typography-meta text-foreground",children:[f("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",S.plan.commits.length,")"]})]}),G.length>0&&S.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>F(d=>!d),className:"typography-micro text-muted-foreground hover:text-foreground",children:f(V?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(V?G:G.slice(0,5)).map(d=>t.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[t.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:d.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:d.subject||d.sha})]},d.sha)),G.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:f("gitView.integrate.previewUnavailable")}),S.plan.commits.length>G.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:f("gitView.integrate.showingFirstCommits",{count:G.length})})]})]}),S.kind==="conflict"&&t.jsxs("div",{className:"rounded-md oc-tile p-3 space-y-2",children:[t.jsx("div",{className:"typography-meta text-foreground",children:f("gitView.integrate.conflictsInFiles",{count:S.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[f("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:S.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[S.details.unmergedFiles.slice(0,6).map(d=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded oc-tile-inset text-muted-foreground",children:d},d)),S.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:f("gitView.integrate.moreFiles",{count:S.details.unmergedFiles.length-6})})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(K,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{U()},children:f("gitView.operation.abort")}),t.jsxs(K,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!w,onClick:()=>{J({state:S.state,details:S.details},!1)},children:[t.jsx(_,{name:"sparkling",className:"size-3.5"}),f("gitView.integrate.currentSession")]}),t.jsxs(K,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{J({state:S.state,details:S.details},!0)},children:[t.jsx(_,{name:"sparkling",className:"size-3.5"}),f("gitView.integrate.newSession")]}),t.jsx(K,{size:"sm",className:"typography-meta",onClick:()=>{te()},children:f("gitView.operation.continue")})]})]})]})]})},fo=({open:o,onOpenChange:e,directory:n,hasUncommittedChanges:h,hasStagedChanges:x=!1,uncommittedFileCount:g,onChanged:y})=>{const{t:m}=it(),[f,w]=i.useState([]),[M,O]=i.useState(!1),[k,T]=i.useState(""),[C,z]=i.useState(""),[P,b]=i.useState(null),[H,S]=i.useState({}),D=i.useCallback(async()=>{if(n){O(!0);try{const R=await ka(n);w(R.stashes),S({})}catch(R){p.error(R instanceof Error?R.message:m("gitView.stashes.toast.loadFailed"))}finally{O(!1)}}},[n,m]);i.useEffect(()=>{o&&D()},[D,o]),i.useEffect(()=>{if(!o||!n||f.length===0)return;let R=!1;const E=f.map(a=>a.ref);return Va(n,E).then(a=>{R||S(a.counts)}).catch(()=>{}),()=>{R=!0}},[n,o,f]);const V=i.useMemo(()=>_t(f,k,R=>[R.message,R.ref,R.relativeTime]),[k,f]),F=i.useCallback(async R=>{await D(),await y?.(R)},[D,y]),G=async()=>{if(!(!n||P)){b("create");try{const R=await Ra(n,{message:C.trim()||void 0});R.created?(p.success(m("gitView.stashes.toast.created")),z("")):p.info(m("gitView.stashes.toast.noChanges")),await F({affectsIndex:!!(R.created&&x)})}catch(R){p.error(R instanceof Error?R.message:m("gitView.stashes.toast.createFailed"))}finally{b(null)}}},Z=async(R,E)=>{if(!(!n||P)&&!(E==="drop"&&!window.confirm(m("gitView.stashes.confirm.drop",{ref:R.ref})))){b(`${E}:${R.ref}`);try{E==="apply"&&await Ia(n,{ref:R.ref}),E==="pop"&&await Pa(n,{ref:R.ref}),E==="drop"&&await Fa(n,{ref:R.ref});const a=E==="apply"?"gitView.stashes.toast.applySuccess":E==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";p.success(m(a)),await F({affectsIndex:E!=="drop"})}catch(a){const Y=E==="apply"?"gitView.stashes.toast.applyFailed":E==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";p.error(a instanceof Error?a.message:m(Y)),await F({affectsIndex:E!=="drop"})}finally{b(null)}}},A=P!==null;return t.jsx(ht,{open:o,onOpenChange:e,children:t.jsxs(mt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsxs(ft,{children:[t.jsxs(gt,{className:"flex items-center gap-2",children:[t.jsx(_,{name:"archive-stack",className:"size-4 text-muted-foreground"}),m("gitView.stashes.title")]}),t.jsx(jt,{children:m("gitView.stashes.description")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(Er,{value:C,onChange:R=>z(R.target.value),placeholder:m("gitView.stashes.messagePlaceholder"),disabled:A||!h,className:"flex-1"}),t.jsxs(K,{onClick:G,disabled:!h||A||!n,children:[P==="create"?t.jsx(_,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(_,{name:"inbox-archive",className:"size-4"}),m("gitView.stashes.actions.stashCurrentWithCount",{count:g})]})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:m("gitView.stashes.includeUntrackedHint")})]}),t.jsx("div",{className:"-mx-5 border-t border-border/60"}),t.jsxs("div",{className:"relative",children:[t.jsx(_,{name:"search",className:"absolute inset-s-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),t.jsx(Er,{value:k,onChange:R=>T(R.target.value),placeholder:m("gitView.stashes.searchPlaceholder"),className:"ps-8"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:M?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(_,{name:"loader-4",className:"size-5 animate-spin"})}):V.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:m(k?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):V.map((R,E)=>t.jsxs("div",{className:"group -mx-2 flex items-center gap-2 rounded-md px-2 py-1.5 transition-colors hover:bg-interactive-hover",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"typography-ui-label truncate text-foreground",children:R.message||m("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-micro truncate text-muted-foreground",children:[t.jsxs(us,{children:[t.jsx(ds,{asChild:!0,children:t.jsx("span",{children:E===0&&!k.trim()?m("gitView.stashes.latestLabel"):m("gitView.stashes.itemNumber",{number:E+1})})}),t.jsx(hs,{sideOffset:6,children:R.ref})]})," · ",R.relativeTime," · ",typeof H[R.ref]=="number"?m("gitView.stashes.fileCount",{count:H[R.ref]}):m("gitView.stashes.fileCountLoading")]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[t.jsx(Ks,{label:m("gitView.stashes.actions.apply"),loading:P===`apply:${R.ref}`,onClick:()=>Z(R,"apply"),disabled:A,children:t.jsx(_,{name:"inbox-unarchive",className:"size-3.5"})}),t.jsx(Ks,{label:m("gitView.stashes.actions.pop"),loading:P===`pop:${R.ref}`,onClick:()=>Z(R,"pop"),disabled:A,children:t.jsx(_,{name:"inbox-unarchive-fill",className:"size-3.5"})}),t.jsx(Ks,{label:m("gitView.stashes.actions.drop"),loading:P===`drop:${R.ref}`,onClick:()=>Z(R,"drop"),disabled:A,destructive:!0,children:t.jsx(_,{name:"delete-bin",className:"size-3.5"})})]})]},R.ref))})]})})},Ks=o=>{const e=Ht.c(17),{label:n,loading:h,disabled:x,destructive:g,onClick:y,children:m}=o,f=h||void 0,w=g?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let M;e[0]!==w?(M=fe("flex size-6 items-center justify-center rounded-md transition-colors hover:bg-interactive-hover disabled:opacity-50",w),e[0]=w,e[1]=M):M=e[1];let O;e[2]!==m||e[3]!==h?(O=h?t.jsx(_,{name:"loader-4",className:"size-3.5 animate-spin"}):m,e[2]=m,e[3]=h,e[4]=O):O=e[4];let k;e[5]!==x||e[6]!==n||e[7]!==y||e[8]!==f||e[9]!==M||e[10]!==O?(k=t.jsx(ds,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":n,"aria-busy":f,className:M,onClick:y,disabled:x,children:O})}),e[5]=x,e[6]=n,e[7]=y,e[8]=f,e[9]=M,e[10]=O,e[11]=k):k=e[11];let T;e[12]!==n?(T=t.jsx(hs,{sideOffset:6,children:n}),e[12]=n,e[13]=T):T=e[13];let C;return e[14]!==k||e[15]!==T?(C=t.jsxs(us,{children:[k,T]}),e[14]=k,e[15]=T,e[16]=C):C=e[16],C},go=o=>{const e=Ht.c(16),{onOpenStashes:n}=o,{t:h}=it();let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx(_,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=x):x=e[0];let g;e[1]!==h?(g=h("gitView.empty.cleanTitle"),e[1]=h,e[2]=g):g=e[2];let y;e[3]!==g?(y=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:g}),e[3]=g,e[4]=y):y=e[4];let m;e[5]!==h?(m=h("gitView.empty.cleanDescription"),e[5]=h,e[6]=m):m=e[6];let f;e[7]!==m?(f=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:m}),e[7]=m,e[8]=f):f=e[8];let w;e[9]!==n||e[10]!==h?(w=n?t.jsxs(K,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[t.jsx(_,{name:"archive-stack",className:"size-4"}),h("gitView.stashes.title")]}):null,e[9]=n,e[10]=h,e[11]=w):w=e[11];let M;return e[12]!==y||e[13]!==f||e[14]!==w?(M=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[x,y,f,w]}),e[12]=y,e[13]=f,e[14]=w,e[15]=M):M=e[15],M},nt=8,po=o=>{const e=Ht.c(18),{laned:n,totalLanes:h,isExpanded:x}=o,{lane:g,color:y,connectors:m}=n,w=Math.max(h,g+1)*nt+nt/2,M=i.useRef(null),O=i.useRef(null);let k;e[0]!==y||e[1]!==m||e[2]!==g||e[3]!==w?(k=()=>{const b=M.current,H=O.current;if(!b||!H)return;const S=b.offsetHeight;if(S===0)return;const D=window.devicePixelRatio||1;H.width=w*D,H.height=S*D;const V=H.getContext("2d");if(!V)return;V.scale(D,D),V.clearRect(0,0,w,S);const F=S/2,G=g*nt+nt/2,Z=getComputedStyle(H),A=Z.getPropertyValue("--surface-muted-foreground").trim()||Z.color,R=Y=>{if(!Y.startsWith("var("))return Y;const q=Y.slice(4,-1).trim();return Z.getPropertyValue(q).trim()||A},E=[...m].sort(yo);for(const Y of E){const q=Y.fromLane*nt+nt/2,J=Y.toLane*nt+nt/2,j=Y.type==="passing"?.72:Y.type==="branch-out"||Y.type==="merge-in"?.95:1;V.beginPath(),V.strokeStyle=R(Y.color),V.globalAlpha=j,V.lineWidth=1.25,V.lineCap="round";e:switch(Y.type){case"passing":case"commit-lane":{V.moveTo(q,0),V.lineTo(q,S);break e}case"top-stub":{V.moveTo(q,0),V.lineTo(q,F);break e}case"bottom-stub":{V.moveTo(q,F),V.lineTo(q,S);break e}case"branch-out":{const U=(F+S)/2;V.moveTo(G,F),V.bezierCurveTo(G,U,J,U,J,S);break e}case"merge-in":{const U=F/2;V.moveTo(q,0),V.bezierCurveTo(q,U,G,U,G,F);break e}default:continue}V.stroke(),V.globalAlpha=1}const a=Z.getPropertyValue("--background").trim()||Z.getPropertyValue("--surface-background").trim();V.beginPath(),V.arc(G,F,4,0,Math.PI*2),V.fillStyle=R(y),V.fill(),V.beginPath(),V.arc(G,F,5,0,Math.PI*2),V.strokeStyle=a||A,V.lineWidth=2,V.stroke()},e[0]=y,e[1]=m,e[2]=g,e[3]=w,e[4]=k):k=e[4];let T;e[5]!==y||e[6]!==m||e[7]!==x||e[8]!==g||e[9]!==n||e[10]!==h||e[11]!==w?(T=[n,g,y,m,h,x,w],e[5]=y,e[6]=m,e[7]=x,e[8]=g,e[9]=n,e[10]=h,e[11]=w,e[12]=T):T=e[12],i.useLayoutEffect(k,T);let C;e[13]!==w?(C={width:w,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=w,e[14]=C):C=e[14];let z;e[15]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx("canvas",{ref:O,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=z):z=e[15];let P;return e[16]!==C?(P=t.jsx("div",{ref:M,style:C,children:z}),e[16]=C,e[17]=P):P=e[17],P};function xo(o){return o==="branch-out"||o==="merge-in"}function yo(o,e){const n=xo;return(n(o.type)?1:0)-(n(e.type)?1:0)}const Jr=15e3,Yr=500,Qr=12,Xr=8*1024*1024,vt="h-6 text-foreground/80 hover:bg-transparent hover:text-foreground",Zr=o=>typeof o=="string"?0:(o.original?.length??0)+(o.modified?.length??0),en=o=>{if(o.size<=Qr){let x=0;for(const g of o.values())x+=Zr(g);if(x<=Xr)return o}const e=Array.from(o.entries()).reverse(),n=new Map;let h=0;for(const[x,g]of e){if(n.size>=Qr)continue;const y=Zr(g);h+y>Xr&&n.size>0||(n.set(x,g),h+=y)}return new Map(Array.from(n.entries()).reverse())};function tn(o,e){const n=new Date(o);return Number.isNaN(n.getTime())?o:Aa(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function wo(o){switch(o){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 bo(o){return o?o.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const vo=i.memo(({entry:o,mode:e="history",laned:n,totalLanes:h,isExpanded:x,onToggle:g,files:y,isLoadingFiles:m,onCopyHash:f,directory:w,onConflict:M,onActionSuccess:O})=>{const{t:k}=it(),T=zt(c=>c.timeFormatPreference),C=e==="graph",[z,P]=i.useState(null),[b,H]=i.useState(!1),[S,D]=i.useState(""),[V,F]=i.useState(null),[G,Z]=i.useState(new Set),[A,R]=i.useState(new Map),[E,a]=i.useState(new Set),Y=async()=>{if(w){P("checkout");try{await _a(w,o.hash),p.success(k("gitView.history.actions.detachedHead")),O?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},q=async()=>{if(!(!w||!S.trim())){P("createBranch");try{await Oa(w,S.trim(),o.hash),H(!1),D(""),O?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},J=async()=>{if(w){P("cherryPick");try{const c=await Ga(w,o.hash);c.conflict?M?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"cherry-pick"}):O?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},j=async()=>{if(w){P("revert");try{const c=await za(w,o.hash);c.conflict?M?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"revert"}):O?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},U=async(c,I=!1)=>{if(!(!w||z!==null)){P("reset");try{await Ta(w,o.hash,c,I),O?.()}catch(L){p.error(String(L.message))}finally{P(null)}}},te=async()=>{if(!V)return;const c=V;switch(F(null),c){case"checkout":return Y();case"cherryPick":return J();case"revert":return j();case"merge":return oe();case"rebase":return xe();case"resetSoft":return U("soft");case"resetMixed":return U("mixed");case"resetHard":return U("hard",!0)}},oe=async()=>{if(w){P("merge");try{const c=await La(w,{branch:o.hash});c.conflict?M?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"merge"}):O?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},xe=async()=>{if(w){P("rebase");try{const c=await Ea(w,{onto:o.hash});c.conflict?M?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"rebase"}):O?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},me=i.useCallback(async c=>{const I=c.path;if(!w){R(L=>new Map(L).set(I,"error"));return}R(L=>en(new Map(L).set(I,"loading")));try{const L=Da(w,o.hash,c.path,!1),re=new Promise((ce,ee)=>{setTimeout(()=>ee(new Error(`Timed out after ${Jr}ms`)),Jr)}),de=await Promise.race([L,re]);R(ce=>en(new Map(ce).set(I,de)))}catch{R(L=>new Map(L).set(I,"error"))}},[w,o.hash]),d=i.useCallback(async c=>{const I=c.path;if(c.changeType==="R"||c.isBinary){Z(ce=>{const ee=new Set(ce);return ee.has(I)?ee.delete(I):ee.add(I),ee});return}const L=A.get(I);if(G.has(I)&&L&&L!=="error"){Z(ce=>{const ee=new Set(ce);return ee.delete(I),ee});return}Z(ce=>{const ee=new Set(ce);return ee.add(I),ee}),!(L&&L!=="error"||c.insertions+c.deletions>Yr&&!E.has(I))&&await me(c)},[A,E,me,G]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:g,className:fe("w-full flex items-start gap-3 px-3 py-2 text-start transition-colors",C?"hover:bg-[var(--interactive-hover)]/40":x?"oc-tile-inset":"oc-tile-hover"),children:[C&&n&&h!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(po,{laned:n,totalLanes:h,isExpanded:x})}):t.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 flex-1",children:[C?(()=>{const c=bo(o.refs);return c.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:c.map(I=>t.jsx("span",{className:fe("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",I.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":I.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:I.label},I.label))}):null})():null,t.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:o.message}),t.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[t.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[t.jsx("span",{className:"truncate min-w-[3ch]",title:o.author_name,children:o.author_name}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("span",{className:"truncate min-w-0",title:tn(o.date,T),children:tn(o.date,T)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:o.hash.slice(0,8)}),t.jsxs(us,{children:[t.jsx(ds,{asChild:!0,children:t.jsx(K,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:c=>{c.stopPropagation(),f(o.hash)},children:t.jsx(_,{name:"file-copy",className:"size-3"})})}),t.jsx(hs,{sideOffset:8,children:k("gitView.history.copySha")})]})]})]})]}),x&&t.jsxs("div",{className:"oc-tile-inset px-3 pb-2 ps-8",children:[C&&V?t.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:k(`gitView.history.actions.${V}Confirm`)}),t.jsxs(K,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:z!==null,onClick:c=>{c.stopPropagation(),te()},children:[z!==null?t.jsx(_,{name:"loader-4",className:"size-3 animate-spin me-1"}):null,k("gitView.history.actions.confirmButton")]}),t.jsx(K,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:z!==null,onClick:c=>{c.stopPropagation(),F(null)},children:k("gitView.history.actions.cancelButton")})]}):C?t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[t.jsx(K,{variant:"outline",size:"xs",className:"h-6",disabled:z!==null,onClick:c=>{c.stopPropagation(),F("checkout")},children:k("gitView.history.actions.checkout")}),b?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:S,onChange:c=>D(c.target.value),onKeyDown:c=>{c.key==="Enter"&&q(),c.key==="Escape"&&(H(!1),D(""))},placeholder:k("gitView.history.actions.createBranchPlaceholder"),className:"oc-raised oc-field h-6 text-xs px-2 rounded bg-surface-elevated outline-none min-w-0 w-32"}),t.jsxs(K,{variant:"outline",size:"xs",className:"h-6",disabled:!S.trim()||z!==null,onClick:c=>{c.stopPropagation(),q()},children:[z==="createBranch"?t.jsx(_,{name:"loader-4",className:"size-3 animate-spin me-1"}):null,k("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(K,{variant:"ghost",size:"xs",className:vt,onClick:c=>{c.stopPropagation(),H(!0)},children:k("gitView.history.actions.createBranch")}),t.jsx(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>{c.stopPropagation(),F("cherryPick")},children:k("gitView.history.actions.cherryPick")}),t.jsx(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>{c.stopPropagation(),F("revert")},children:k("gitView.history.actions.revert")}),t.jsxs(Js,{children:[t.jsx(Ys,{asChild:!0,children:t.jsxs(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>c.stopPropagation(),children:[z==="reset"?t.jsx(_,{name:"loader-4",className:"size-3 animate-spin me-1"}):null,k("gitView.history.actions.reset")]})}),t.jsx(Qs,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(c=>t.jsx(Ba,{disabled:z!==null,onSelect:I=>{I.stopPropagation(),F(`reset${c.charAt(0).toUpperCase()+c.slice(1)}`)},children:k(`gitView.history.actions.reset${c.charAt(0).toUpperCase()+c.slice(1)}`)},c))})]}),t.jsx(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>{c.stopPropagation(),F("merge")},children:k("gitView.history.actions.merge")}),t.jsx(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>{c.stopPropagation(),F("rebase")},children:k("gitView.history.actions.rebase")})]}):null,m?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(_,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:k("gitView.history.loadingFiles")})]}):y.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:k("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:y.map(c=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>d(c),className:"oc-tile-hover w-full flex items-center gap-2 typography-micro text-start cursor-pointer rounded px-1",children:[t.jsx("span",{className:fe("font-semibold w-3 text-center shrink-0",wo(c.changeType)),children:c.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:c.path,children:c.path}),!c.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",c.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",c.deletions]})]}),c.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:k("gitView.history.binary")}),t.jsx(_,{name:G.has(c.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),G.has(c.path)&&t.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:c.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.renamedNoDiff")}):c.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.binaryNoDiff")}):(()=>{const I=c.insertions+c.deletions;if(!E.has(c.path)&&I>Yr)return t.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:k("gitView.history.largeDiffTitle",{count:I})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:k("gitView.history.largeDiffDescription")}),t.jsx(K,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{a(re=>new Set(re).add(c.path)),me(c)},children:k("gitView.history.renderDiffAnyway")})]});const L=A.get(c.path);return L==="loading"||L===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.loadingDiff")}):L==="error"?t.jsx("button",{type:"button",onClick:()=>d(c),className:"w-full text-start px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:k("gitView.history.diffError")}):t.jsx(so,{original:L.original,modified:L.modified,language:Ma(c.path)||"",fileName:c.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},c.path))})]})]})}),sn=["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 is(o){return sn[o%sn.length]}function jo(o){if(o.length===0)return[];const e=[],n=[];for(let h=0;h<o.length;h++){const x=o[h],g=[];for(let C=0;C<e.length;C++)e[C]===x.hash&&g.push(C);let y=g.length>0?g[0]:-1;if(y===-1){const C=e.indexOf(null);C!==-1?y=C:(y=e.length,e.push(null))}const m=g.slice(1),f=is(y),w=e[y]===x.hash,M=x.parents.length>0;M?e[y]=x.parents[0]:e[y]=null;const O=[],k=new Set;for(let C=1;C<x.parents.length;C++){const z=x.parents[C],P=e.indexOf(z);if(P!==-1)O.push(P);else{const b=e.indexOf(null);if(b!==-1)e[b]=z,O.push(b),k.add(b);else{const H=e.length;e.push(z),O.push(H),k.add(H)}}}const T=[];w&&M?T.push({fromLane:y,toLane:y,color:f,type:"commit-lane"}):w&&!M?T.push({fromLane:y,toLane:y,color:f,type:"top-stub"}):!w&&M&&T.push({fromLane:y,toLane:y,color:f,type:"bottom-stub"});for(const C of m)T.push({fromLane:C,toLane:y,color:is(C),type:"merge-in"}),e[C]=null;for(const C of O)T.push({fromLane:y,toLane:C,color:is(C),type:"branch-out"});for(let C=0;C<e.length;C++)e[C]!==null&&C!==y&&(k.has(C)||T.push({fromLane:C,toLane:C,color:is(C),type:"passing"}));n.push({commit:x,lane:y,color:f,connectors:T})}return n}const Co=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],So=o=>{const e=Ht.c(84),{mode:n,log:h,isLogLoading:x,logMaxCount:g,onLogMaxCountChange:y,expandedCommitHashes:m,onToggleCommit:f,commitFilesMap:w,loadingCommitHashes:M,onCopyHash:O,directory:k,showHeader:T,contentMaxHeightClassName:C,branchDivider:z,onConflict:P,onActionSuccess:b}=o,H=n===void 0?"history":n,S=T===void 0?!0:T,D=C===void 0?"max-h-[50vh]":C,V=z===void 0?null:z,{t:F}=it(),[G,Z]=i.useState(!0),A=H==="graph";let R;e[0]!==A||e[1]!==h?(R=A&&h?jo(h.all):[],e[0]=A,e[1]=h,e[2]=R):R=e[2];const E=R;let a;e[3]!==E?(a=Math.max(1,...E.map(No)),e[3]=E,e[4]=a):a=e[4];const Y=a;let q;e[5]!==E?(q=new Map(E.map(ko)),e[5]=E,e[6]=q):q=e[6];const J=q;if(!h)return null;const j=V!==null&&V.insertBeforeIndex>0&&V.insertBeforeIndex<h.all.length,U=V!==null&&V.insertBeforeIndex===h.all.length,te=j||U;let oe;e[7]!==V||e[8]!==j||e[9]!==U||e[10]!==h.all?(oe=j?h.all.slice(0,V.insertBeforeIndex):U?h.all:[],e[7]=V,e[8]=j,e[9]=U,e[10]=h.all,e[11]=oe):oe=e[11];const xe=oe;let me;if(e[12]!==V||e[13]!==w||e[14]!==D||e[15]!==k||e[16]!==m||e[17]!==j||e[18]!==te||e[19]!==A||e[20]!==x||e[21]!==J||e[22]!==M||e[23]!==h.all||e[24]!==g||e[25]!==Y||e[26]!==H||e[27]!==b||e[28]!==P||e[29]!==O||e[30]!==y||e[31]!==f||e[32]!==F||e[33]!==xe){const X=j?h.all.slice(V.insertBeforeIndex):[];let ae;e[35]!==V?.direction?(ae=V?.direction==="down"?t.jsx(_,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(_,{name:"arrow-up",className:"size-3.5"}),e[35]=V?.direction,e[36]=ae):ae=e[36];const De=ae;let ve;e[37]!==w||e[38]!==k||e[39]!==m||e[40]!==A||e[41]!==J||e[42]!==M||e[43]!==Y||e[44]!==H||e[45]!==b||e[46]!==P||e[47]!==O||e[48]!==f?(ve=St=>t.jsx("ul",{className:"divide-y divide-border/60",children:St.map(le=>t.jsx(vo,{entry:le,mode:H,laned:A?J.get(le.hash):void 0,totalLanes:A?Y:void 0,isExpanded:m.has(le.hash),onToggle:()=>f(le.hash),files:w.get(le.hash)??[],isLoadingFiles:M.has(le.hash),onCopyHash:O,directory:k,onConflict:P,onActionSuccess:b},le.hash))}),e[37]=w,e[38]=k,e[39]=m,e[40]=A,e[41]=J,e[42]=M,e[43]=Y,e[44]=H,e[45]=b,e[46]=P,e[47]=O,e[48]=f,e[49]=ve):ve=e[49];const ke=ve;let je;e[50]!==x||e[51]!==h.all.length||e[52]!==g||e[53]!==y||e[54]!==F?(je=h.all.length>=g?t.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:t.jsx(K,{type:"button",variant:"ghost",size:"xs",onClick:()=>y(g+25),disabled:x,className:"px-3 text-muted-foreground hover:text-foreground",children:x?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(_,{name:"loader-4",className:"size-3 animate-spin"}),F("gitView.history.loadingMore")]}):F("gitView.history.loadMore")})}):null,e[50]=x,e[51]=h.all.length,e[52]=g,e[53]=y,e[54]=F,e[55]=je):je=e[55];const Be=je;me=t.jsx(ln,{outerClassName:`min-h-0 ${D}`,className:"h-full w-full",children:h.all.length===0?t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:F("gitView.history.noCommits")})}):te&&V?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[xe.length>0?t.jsx("div",{className:"rounded-xl oc-tile overflow-hidden",children:ke(xe)}):null,t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[t.jsx("span",{className:"h-px flex-1 bg-border/60"}),t.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[t.jsx("span",{className:"truncate",title:V.branchName,children:V.branchName}),De]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),X.length>0?t.jsx("div",{className:"rounded-xl oc-tile overflow-hidden",children:ke(X)}):null]}),Be]}):t.jsxs(t.Fragment,{children:[ke(h.all),Be]})}),e[12]=V,e[13]=w,e[14]=D,e[15]=k,e[16]=m,e[17]=j,e[18]=te,e[19]=A,e[20]=x,e[21]=J,e[22]=M,e[23]=h.all,e[24]=g,e[25]=Y,e[26]=H,e[27]=b,e[28]=P,e[29]=O,e[30]=y,e[31]=f,e[32]=F,e[33]=xe,e[34]=me}else me=e[34];const d=me;if(!S){if(te){let ae;return e[56]!==d?(ae=t.jsx("section",{className:"h-full min-h-0",children:d}),e[56]=d,e[57]=ae):ae=e[57],ae}let X;return e[58]!==d?(X=t.jsx("section",{className:"h-full min-h-0 rounded-xl oc-tile overflow-hidden",children:d}),e[58]=d,e[59]=X):X=e[59],X}let c;e[60]!==F?(c=F("gitView.history.title"),e[60]=F,e[61]=c):c=e[61];let I;e[62]!==c?(I=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:c}),e[62]=c,e[63]=I):I=e[63];let L;e[64]!==x||e[65]!==G||e[66]!==g||e[67]!==y||e[68]!==F?(L=G&&t.jsx("div",{onClick:Vo,onPointerDown:Ro,children:t.jsxs(Ha,{value:String(g),onValueChange:X=>y(Number(X)),disabled:x,children:[t.jsx($a,{className:"w-auto",disabled:x,children:t.jsx(Wa,{placeholder:F("gitView.history.commitsPlaceholder")})}),t.jsx(Ua,{children:Co.map(X=>t.jsx(Ka,{value:String(X.value),children:F(X.labelKey)},X.value))})]})}),e[64]=x,e[65]=G,e[66]=g,e[67]=y,e[68]=F,e[69]=L):L=e[69];let re;e[70]!==G?(re=G?t.jsx(_,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(_,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=G,e[71]=re):re=e[71];let de;e[72]!==L||e[73]!==re?(de=t.jsxs("div",{className:"flex items-center gap-2",children:[L,re]}),e[72]=L,e[73]=re,e[74]=de):de=e[74];let ce;e[75]!==I||e[76]!==de?(ce=t.jsxs(Fi,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[I,de]}),e[75]=I,e[76]=de,e[77]=ce):ce=e[77];let ee;e[78]!==d?(ee=t.jsx(Di,{children:d}),e[78]=d,e[79]=ee):ee=e[79];let ne;return e[80]!==G||e[81]!==ce||e[82]!==ee?(ne=t.jsxs(Bi,{open:G,onOpenChange:Z,className:"rounded-xl oc-tile overflow-hidden",children:[ce,ee]}),e[80]=G,e[81]=ce,e[82]=ee,e[83]=ne):ne=e[83],ne};function No(o){return o.lane+1}function ko(o){return[o.commit.hash,o]}function Vo(o){return o.stopPropagation()}function Ro(o){return o.stopPropagation()}const Io=({open:o,onOpenChange:e,operation:n,targetBranch:h,onConfirm:x})=>{const{t:g}=it(),[y,m]=i.useState(!0),[f,w]=i.useState(!1),M=g(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),O=async()=>{w(!0);try{await x(y),e(!1)}catch(T){const C=T instanceof Error?T.message:`Failed to ${n}`;p.error(C)}finally{w(!1)}},k=()=>{f||e(!1)};return t.jsx(ht,{open:o,onOpenChange:f?void 0:e,children:t.jsxs(mt,{className:"max-w-md",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(_,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(gt,{children:g("gitView.stash.title")})]}),t.jsx(jt,{children:g("gitView.stash.description",{operation:n})})]}),t.jsxs("div",{className:"py-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:g("gitView.stash.thisWill")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[t.jsx("li",{children:g("gitView.stash.stepStash")}),t.jsxs("li",{children:[g(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",g(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:h})]}),y&&t.jsx("li",{children:g("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(qa,{checked:y,onChange:m,disabled:f,ariaLabel:g("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!f&&m(!y),children:g("gitView.stash.restoreAfterOperation",{operation:n})})]}),t.jsxs(qs,{className:"gap-2",children:[t.jsx(K,{variant:"ghost",size:"sm",onClick:k,disabled:f,children:g("gitView.common.cancel")}),t.jsx(K,{variant:"default",size:"sm",onClick:O,disabled:f,className:"gap-1.5",children:f?t.jsxs(t.Fragment,{children:[t.jsx(_,{name:"loader-4",className:"size-4 animate-spin"}),g("gitView.common.processing")]}):g("gitView.stash.confirmButton",{operation:M})})]})]})})},Po=o=>{const e=Ht.c(100),{currentBranch:n,localBranches:h,remoteBranches:x,onMerge:g,onRebase:y,disabled:m,isOperating:f,operationLogs:w,onOperationComplete:M,mode:O,defaultTargetBranch:k}=o,T=m===void 0?!1:m,C=f===void 0?!1:f,z=w===void 0?[]:w,P=O===void 0?"dialog":O,{t:b}=it(),[H,S]=i.useState(!1),[D,V]=i.useState("merge"),[F,G]=i.useState(null),[Z,A]=i.useState(!1),[R,E]=i.useState(""),a=i.useRef(null),Y=i.useRef(null),q=T||C,J=n||b("gitView.branch.currentBranchFallback"),j=z.length>0&&z.every(Fo),U=z.some(Do);let te;e[0]===Symbol.for("react.memo_cache_sentinel")?(te=()=>{Y.current&&(Y.current.scrollTop=Y.current.scrollHeight)},e[0]=te):te=e[0],i.useEffect(te,[z]);let oe;if(e[1]!==R||e[2]!==n||e[3]!==h){let Q;e[5]!==n?(Q=ye=>ye!==n,e[5]=n,e[6]=Q):Q=e[6];const pe=h.filter(Q);oe=_t(pe,R,Bo),e[1]=R,e[2]=n,e[3]=h,e[4]=oe}else oe=e[4];const xe=oe;let me;e[7]!==R||e[8]!==x?(me=_t(x,R,Mo),e[7]=R,e[8]=x,e[9]=me):me=e[9];const d=me;let c;e[10]!==k||e[11]!==h||e[12]!==x?(c=()=>{if(!k)return null;const Q=x.find(pe=>pe.label===k);return Q||(h.includes(k)?{kind:"local",branch:k,label:k}:null)},e[10]=k,e[11]=h,e[12]=x,e[13]=c):c=e[13];const I=c;let L;e[14]!==I||e[15]!==S?(L=()=>{S(!0),G(I()),V("merge"),E("")},e[14]=I,e[15]=S,e[16]=L):L=e[16];const re=L;let de;e[17]===Symbol.for("react.memo_cache_sentinel")?(de=Q=>{G(Q),A(!1),E("")},e[17]=de):de=e[17];const ce=de;let ee;e[18]!==g||e[19]!==y||e[20]!==D||e[21]!==F?(ee=()=>{F&&(D==="merge"?g(F):y(F))},e[18]=g,e[19]=y,e[20]=D,e[21]=F,e[22]=ee):ee=e[22];const ne=ee;let X;e[23]!==C||e[24]!==S?(X=()=>{C||(G(null),V("merge"),E(""),S(!1))},e[23]=C,e[24]=S,e[25]=X):X=e[25];const ae=X,De=()=>{C&&!j||(j&&M?.(),G(null),V("merge"),E(""),S(!1))};let ve,ke;e[26]!==Z?(ve=()=>{Z||E("")},ke=[Z],e[26]=Z,e[27]=ve,e[28]=ke):(ve=e[27],ke=e[28]),i.useEffect(ve,ke);let je,Be;e[29]!==P||e[30]!==I||e[31]!==F?(je=()=>{P==="dialog"||F||G(I())},Be=[P,I,F],e[29]=P,e[30]=I,e[31]=F,e[32]=je,e[33]=Be):(je=e[32],Be=e[33]),i.useEffect(je,Be);const Le=C?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:Y,className:"rounded-lg oc-tile p-3 max-h-48 overflow-y-auto",children:t.jsx("div",{className:"space-y-2",children:z.map(Ao)})}),j?P==="dialog"?t.jsx(qs,{children:t.jsx(K,{variant:"default",size:"sm",onClick:De,children:b(U?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(K,{variant:"default",size:"sm",onClick:De,children:b(U?"gitView.common.close":"gitView.common.done")})}):null]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:b("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>V("merge"),className:fe("flex flex-col items-start gap-1 rounded-lg p-3 text-start",D==="merge"?"bg-interactive-selection text-interactive-selection-foreground":"oc-tile oc-tile-hover"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(_,{name:"git-merge",className:fe("size-4",D==="merge"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:fe("typography-ui-label",D==="merge"?"text-foreground":"text-muted-foreground"),children:b("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:b("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>V("rebase"),className:fe("flex flex-col items-start gap-1 rounded-lg p-3 text-start",D==="rebase"?"bg-interactive-selection text-interactive-selection-foreground":"oc-tile oc-tile-hover"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(_,{name:"git-branch",className:fe("size-4",D==="rebase"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:fe("typography-ui-label",D==="rebase"?"text-foreground":"text-muted-foreground"),children:b("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:b("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:D==="merge"?b("gitView.branch.branchToMergeInto",{branch:J}):b("gitView.branch.branchToRebaseOnto")}),t.jsxs(Js,{open:Z,onOpenChange:A,modal:!1,children:[t.jsx(Ys,{asChild:!0,children:t.jsxs("button",{type:"button",className:fe(on({size:"default"}),"w-full"),children:[t.jsx("span",{className:fe("truncate",!F&&"text-muted-foreground"),children:F?.label||b("gitView.branch.selectBranch")}),t.jsx(_,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Qs,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:t.jsxs(Xs,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Zs,{ref:a,placeholder:b("gitView.branch.searchPlaceholder"),value:R,onValueChange:E,onKeyDown:Oo}),t.jsxs(er,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(tr,{children:b("gitView.branch.empty")}),xe.length>0&&t.jsx(os,{heading:b("gitView.branch.localBranches"),children:xe.map(Q=>t.jsx(ls,{onSelect:()=>ce({kind:"local",branch:Q,label:Q}),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q})},`local-${Q}`))}),xe.length>0&&d.length>0?t.jsx(Ja,{}):null,d.length>0&&t.jsx(os,{heading:b("gitView.branch.remoteBranches"),children:d.map(Q=>t.jsx(ls,{onSelect:()=>ce(Q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q.label})},`remote-${Q.label}`))})]})]})})]})]}),F?t.jsx("div",{className:"rounded-lg oc-tile p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:D==="merge"?t.jsxs(t.Fragment,{children:[b("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:F.label})," ",b("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:J})]}):t.jsxs(t.Fragment,{children:[b("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:J})," ",b("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:F.label})]})})}):null,P==="dialog"?t.jsxs(qs,{className:"gap-2 pt-1",children:[t.jsx(K,{variant:"ghost",size:"sm",onClick:ae,children:b("gitView.common.cancel")}),t.jsx(K,{variant:"default",size:"sm",onClick:ne,disabled:!F,className:"gap-1.5",children:D==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(_,{name:"git-merge",className:"size-4"}),b("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(_,{name:"git-branch",className:"size-4"}),b("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(K,{variant:"destructive",size:"sm",onClick:ae,disabled:q,children:b("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(K,{variant:"default",size:"sm",onClick:ne,disabled:q||!F,children:b(D==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(P==="bare")return Le;if(P==="inline"){let Q;e[34]!==b?(Q=b("gitView.branch.updateTitle"),e[34]=b,e[35]=Q):Q=e[35];let pe;e[36]!==Q?(pe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:Q}),e[36]=Q,e[37]=pe):pe=e[37];let ye;e[38]!==b?(ye=b("gitView.branch.updateDescriptionPrefix"),e[38]=b,e[39]=ye):ye=e[39];let $e;e[40]!==J?($e=t.jsx("span",{className:"font-mono text-foreground",children:J}),e[40]=J,e[41]=$e):$e=e[41];let Ce;e[42]!==ye||e[43]!==$e?(Ce=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[ye," ",$e,"."]}),e[42]=ye,e[43]=$e,e[44]=Ce):Ce=e[44];let We;e[45]!==pe||e[46]!==Ce?(We=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[pe,Ce]})}),e[45]=pe,e[46]=Ce,e[47]=We):We=e[47];let Se;e[48]!==Le?(Se=t.jsx("div",{className:"pt-3",children:Le}),e[48]=Le,e[49]=Se):Se=e[49];let Re;return e[50]!==We||e[51]!==Se?(Re=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[We,Se]}),e[50]=We,e[51]=Se,e[52]=Re):Re=e[52],Re}let qe;e[53]!==C?(qe=C?t.jsx(cs,{className:"size-4"}):t.jsx(_,{name:"git-merge",className:"size-4"}),e[53]=C,e[54]=qe):qe=e[54];let ze;e[55]!==b?(ze=b("gitView.branch.mergeRebase"),e[55]=b,e[56]=ze):ze=e[56];let Ge;e[57]!==ze?(Ge=t.jsx("span",{children:ze}),e[57]=ze,e[58]=Ge):Ge=e[58];let Je;e[59]!==re||e[60]!==q||e[61]!==qe||e[62]!==Ge?(Je=t.jsx(ds,{asChild:!0,children:t.jsxs(K,{variant:"outline",size:"sm",className:"gap-1.5",onClick:re,disabled:q,children:[qe,Ge]})}),e[59]=re,e[60]=q,e[61]=qe,e[62]=Ge,e[63]=Je):Je=e[63];let Ve;e[64]!==b?(Ve=b("gitView.branch.mergeRebaseTooltip"),e[64]=b,e[65]=Ve):Ve=e[65];let Me;e[66]!==Ve?(Me=t.jsx(hs,{sideOffset:8,children:Ve}),e[66]=Ve,e[67]=Me):Me=e[67];let $;e[68]!==Je||e[69]!==Me?($=t.jsxs(us,{children:[Je,Me]}),e[68]=Je,e[69]=Me,e[70]=$):$=e[70];let Ye;e[71]!==De||e[72]!==S?(Ye=Q=>{Q?S(!0):De()},e[71]=De,e[72]=S,e[73]=Ye):Ye=e[73];let _e;e[74]!==b?(_e=b("gitView.branch.updateTitle"),e[74]=b,e[75]=_e):_e=e[75];let Qe;e[76]!==_e?(Qe=t.jsx(gt,{children:_e}),e[76]=_e,e[77]=Qe):Qe=e[77];let Ae;e[78]!==U||e[79]!==C||e[80]!==D||e[81]!==j||e[82]!==b||e[83]!==J?(Ae=C?b(j?U?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":D==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[b("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:J}),"."]}),e[78]=U,e[79]=C,e[80]=D,e[81]=j,e[82]=b,e[83]=J,e[84]=Ae):Ae=e[84];let Xe;e[85]!==Ae?(Xe=t.jsx(jt,{children:Ae}),e[85]=Ae,e[86]=Xe):Xe=e[86];let Oe;e[87]!==Qe||e[88]!==Xe?(Oe=t.jsxs(ft,{children:[Qe,Xe]}),e[87]=Qe,e[88]=Xe,e[89]=Oe):Oe=e[89];let Ze;e[90]!==Le||e[91]!==Oe?(Ze=t.jsxs(mt,{className:"max-w-md",children:[Oe,Le]}),e[90]=Le,e[91]=Oe,e[92]=Ze):Ze=e[92];let He;e[93]!==H||e[94]!==Ye||e[95]!==Ze?(He=t.jsx(ht,{open:H,onOpenChange:Ye,children:Ze}),e[93]=H,e[94]=Ye,e[95]=Ze,e[96]=He):He=e[96];let ot;return e[97]!==$||e[98]!==He?(ot=t.jsxs(t.Fragment,{children:[$,He]}),e[97]=$,e[98]=He,e[99]=ot):ot=e[99],ot};function Fo(o){return o.status==="done"||o.status==="error"}function Do(o){return o.status==="error"}function Bo(o){return[o]}function Mo(o){return[o.label,o.branch,o.remote]}function Ao(o,e){return t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("div",{className:"mt-0.5 shrink-0",children:[o.status==="running"&&t.jsx(cs,{className:"size-3.5 text-primary"}),o.status==="done"&&t.jsx(_,{name:"check",className:"size-3.5 text-success"}),o.status==="error"&&t.jsx(_,{name:"close",className:"size-3.5 text-destructive"}),o.status==="pending"&&t.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),t.jsx("span",{className:fe("typography-micro",o.status==="error"&&"text-destructive",o.status==="done"&&"text-muted-foreground",o.status==="running"&&"text-foreground",o.status==="pending"&&"text-muted-foreground/60"),children:o.message})]},e)}function Oo(o){return o.stopPropagation()}const To=/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/i,Eo=(o,e)=>{const n=[...o].sort((h,x)=>x.length-h.length);return e.flatMap(h=>{const x=n.find(y=>h.startsWith(`${y}/`));if(!x)return[];const g=h.slice(x.length+1);return g?[{kind:"remote",branch:g,destinationRef:`refs/remotes/${x}/${g}`,label:h,remote:x,sourceRef:`refs/heads/${g}`}]:[]})},Lo=async({directory:o,git:e,runPlannedFetch:n,target:h})=>{if(h.kind==="local")return h.branch;await n(h);const g=(await e.getGitLog(o,{to:h.destinationRef,maxCount:1})).latest?.hash.trim();if(!g||!To.test(g))throw new be("invalid-terminal-state");return g},zo=({runMutation:o,onMutationComplete:e,onMutationError:n,onPathsComplete:h,scheduleFlush:x})=>{const g=[];let y=!1;return{enqueue:f=>{const w=g[g.length-1];if(w?.directory===f.directory&&w.direction===f.direction){f.paths.forEach(M=>w.paths.add(M));return}g.push(f)},flush:()=>{if(y)return;const f=g.shift();if(!f)return;y=!0;const w={directory:f.directory,direction:f.direction,paths:Array.from(f.paths),rollback:f.rollback};(async()=>{try{await o(w),e(w)}catch(M){n(w,M)}finally{h(w.paths),y=!1,g.length>0&&x()}})()},clear:()=>{g.length=0},size:()=>g.length,isRunning:()=>y}},Go=(o,e,n)=>Ya(o,e,h=>Ji(h)&&Qa(h,n)),_o=(o,e,n,h)=>Xa(o,e,n,x=>({id:"local-config",name:x.userName,...x,color:"info",icon:"user"}),h),Ho=(o,e,n,h)=>{if(e){const x=n.filter(g=>e.startsWith(`${g}/`)&&e.length>g.length+1).sort((g,y)=>y.length-g.length)[0];if(x)return{remoteName:x,destinationRef:`refs/heads/${e.slice(x.length+1)}`}}return h?{remoteName:h,destinationRef:`refs/heads/${o}`}:null},$o=15e3,Wo=40,Uo=20,Ko=2,rn={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},nn=(o,e)=>{const n=o.toLowerCase(),h=/^([a-z]+)(?:\(.*\))?!?:/,x=n.match(h);if(x){const m=x[1],f=rn[m];if(f)return e.find(w=>w.code===f)||null}const g=n.split(" ")[0],y=rn[g];return y&&e.find(m=>m.code===y)||null},qo=20,dt=new Map,Jo=(o,e)=>{if(dt.delete(o),dt.set(o,e),dt.size>qo){const n=dt.keys().next().value;n!==void 0&&dt.delete(n)}},an=o=>{const e=o.index?.trim();return!!(e&&e!=="?")},Yo=o=>{const e=o.working_dir?.trim(),n=o.index?.trim();return!!(e||n==="?")},hu=({isActive:o})=>{const{t:e}=it(),{git:n,sourceControl:h,runtime:x}=Za(),g=ei(),y=Mi(),m=ti(y,g)??void 0,f=Ai(),[w,M]=i.useState(null),[O,k]=i.useState(null),T=at(s=>s.currentSessionId),C=at(s=>s.newSessionDraft),z=at(s=>s.setDraftBootstrapPendingDirectory),P=at(s=>s.worktreeMetadata),b=at(s=>s.availableWorktrees),H=Ke(m),S=i.useMemo(()=>{if(H)return Lr(b,H)??Lr(P.values(),H)},[b,H,P]),D=i.useMemo(()=>{if(T)return P.get(T)??S;if(C?.open)return S},[T,S,C?.open,P]),{profiles:V,globalIdentity:F,defaultGitIdentityId:G,loadProfiles:Z,loadGlobalIdentity:A,loadDefaultGitIdentityId:R}=Oi(Ur(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),{rootIsGitRepo:E,gitDirectory:a,nestedRepos:Y,repositoryOptions:q}=si(m??null,{enabled:o,recheckOnOpen:!0}),J=ri(a??null),j=ni(a??null),U=Ti({directory:a,branch:j?.current,chooseContributor:f.choose}),te=Ei(a,n,h),oe=ai(s=>T?s.getAttachment(T):void 0),xe=oe?ii(oe):[],me=oe&&!oe.degraded&&!oe.legacy?oe.worktreeRoot??void 0:void 0,d=Ii(m,D,j?.current??void 0),c=oi(a??null),I=li(a??null),L=ci(a??null),re=ui(a??null),de=di(a??null),{setActiveDirectory:ce,ensureAll:ee,fetchStatus:ne,fetchBranches:X,fetchLog:ae,setLogMaxCount:De,fetchIdentity:ve,prefetchDiffs:ke,clearDiffCache:je,moveStatusPathsOptimistically:Be,restoreStatus:St,bumpIndexRevision:le,ensureNestedRepos:Le,selectNestedRepo:qe}=hi(Ur(s=>({setActiveDirectory:s.setActiveDirectory,ensureAll:s.ensureAll,fetchStatus:s.fetchStatus,fetchBranches:s.fetchBranches,fetchLog:s.fetchLog,setLogMaxCount:s.setLogMaxCount,fetchIdentity:s.fetchIdentity,prefetchDiffs:s.prefetchDiffs,clearDiffCache:s.clearDiffCache,moveStatusPathsOptimistically:s.moveStatusPathsOptimistically,restoreStatus:s.restoreStatus,bumpIndexRevision:s.bumpIndexRevision,ensureNestedRepos:s.ensureNestedRepos,selectNestedRepo:s.selectNestedRepo}))),ze=zt(s=>s.isMobile),Ge=zt(s=>s.openContextDiff),Je=zt(s=>s.openContextPanelTab),[Ve,Me]=i.useState([]),$=mi(a,h,o),[Ye,_e]=i.useState(!1),Qe=i.useMemo(()=>{const s=$.read;return!s?.binding||$.status!=="ready"||s.binding.state==="bound"?null:fi(s.binding)?e("gitView.identity.configChanged"):e("gitView.context.needsAttention")},[$.read,$.status,e]),Ae=$.read?.binding?.remotes[0]?.name??$.read?.repository.remotes.find(s=>s.name==="origin")?.name??$.read?.repository.remotes[0]?.name??"",Xe=i.useCallback(s=>{const r=$.read?.repository.remotes.find(l=>l.name===Ae);return r?Li(s,gi(r.fetch.displayUrl)):{applicable:!0}},[$.read,Ae]),Oe=zr(s=>s.entries),Ze=zr(s=>s.refreshIdentityAccounts),He=ns(s=>s.beginActiveContextsLoad),ot=ns(s=>s.commitActiveContexts),Q=ns(s=>s.releaseActiveContexts),pe=i.useId();i.useEffect(()=>{if(!o||!m)return;const s=$.scope.runtimeKey,r=He(s,m,pe);return ot(s,m,pe,r,$.contexts.filter(l=>Gr(Oe[_r(l)],l).connected)),()=>{Q(s,m,pe)}},[He,$.contexts,$.scope.runtimeKey,ot,m,o,Q,Oe,pe]);const ye=$.contexts[0]??null,$e=j?.current??null,Ce=ns(s=>!$e||!ye||!Gr(Oe[_r(ye)],ye).connected?null:pi(s.entries,ye,$e)),We=zt(s=>s.navigateToDiff),Se=i.useRef(null),Re=i.useRef(null),ms=i.useRef(null),Nt=i.useRef(!0);i.useEffect(()=>()=>{Nt.current=!1},[]);const $t=i.useCallback(()=>{Se.current!==null&&(window.clearTimeout(Se.current),Se.current=null)},[]),fs=i.useCallback(s=>{$t(),Se.current=window.setTimeout(()=>{Se.current=null,Ke(s)===Ke(a)&&ne(s,n,{silent:!0})},$o)},[$t,a,ne,n]);i.useEffect(()=>$t,[$t]);const sr=i.useCallback(()=>{Re.current!==null&&(window.clearTimeout(Re.current),Re.current=null)},[]),Wt=i.useCallback(()=>{Re.current===null&&(Re.current=window.setTimeout(()=>{Re.current=null,ms.current?.()},0))},[]),rr=i.useCallback(async(s,r,l)=>{if(r==="stage"){if(n.stageGitFiles){await n.stageGitFiles(s,l);return}await Promise.all(l.map(u=>n.stageGitFile(s,u)));return}if(n.unstageGitFiles){await n.unstageGitFiles(s,l);return}await Promise.all(l.map(u=>n.unstageGitFile(s,u)))},[n]),et=i.useMemo(()=>zo({runMutation:({directory:s,direction:r,paths:l})=>rr(s,r,l),onMutationComplete:({directory:s})=>{le(s),fs(s)},onMutationError:({directory:s,direction:r,rollback:l},u)=>{l?.(),le(s),fs(s);const N=e(r==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");p.error(u instanceof Error?u.message:N)},onPathsComplete:s=>{fr(r=>{const l=new Set(r);return s.forEach(u=>l.delete(u)),l})},scheduleFlush:Wt}),[le,rr,Wt,fs,e]);i.useEffect(()=>(ms.current=et.flush,()=>{ms.current=null}),[et]),i.useEffect(()=>()=>et.clear(),[et]),i.useEffect(()=>sr,[sr]),i.useEffect(()=>{if(!o)return;if(!m){M(null);return}const s=Ke(m)??m;M({directory:s,status:null});let r=!1,l=null;const u=async()=>{try{const N=await ki(m);if(r)return;M({directory:s,status:N.status}),N.status==="pending"&&(l=window.setTimeout(()=>{u()},500))}catch{r||M({directory:s,status:null})}};return u(),()=>{r=!0,l!==null&&window.clearTimeout(l)}},[o,m]);const nr=Ke(C?.bootstrapPendingDirectory??null),hn=!!(m&&nr&&nr===Ke(m)),mn=xi(m??null),we=Ke(m),gs=w?.directory===we?w.status:null,ps=!!(m&&(mn||gs==="pending"||hn&&C?.pendingWorktreeRequestId)),ar=!!(we&&O?.directory===we);i.useEffect(()=>{if(!we)return;if(gs==="failed"){z(null),k(r=>r?.directory===we?null:r);return}if(ps){k(r=>r?.directory===we&&r.status==="refreshing"?r:{directory:we,status:"refreshing"});return}if(O?.directory!==we||O.status!=="refreshing"||!a||!n)return;let s=!1;return ne(a,n,{force:!0,silent:!0,throwOnError:!0}).then(()=>{s||k(r=>r?.directory===we?null:r)}).catch(()=>{s||k(r=>r?.directory===we?{...r,status:"failed"}:r)}),()=>{s=!0}},[ne,n,a,ps,we,gs,O,z]);const fn=ps||ar,xs=ar&&O?.status==="failed",ir=i.useMemo(()=>a?dt.get(a)??null:null,[a]),kt=yi(s=>s.settingsGitmojiEnabled),[Vt,ys]=i.useState(null),{gitmojis:pt}=io(kt);i.useEffect(()=>{const s=me||d?.projectDirectory;if(!s){ys(null);return}let r=!1;return wi(s).then(l=>{if(r)return;const u=l.trim();ys(u&&u!=="HEAD"?u:null)}).catch(()=>{r||ys(null)}),()=>{r=!0}},[me,d?.projectDirectory]);const[Rt,xt]=i.useState(ir?.commitMessage??""),[or,gn]=i.useState([]),[pn,ws]=i.useState(!1),lr=i.useRef(null),[cr,Ut]=i.useState(null),[xn,bs]=i.useState(!1),[ur,dr]=i.useState(null),[Ie,yn]=i.useState(25),[wn,hr]=i.useState(!1),{triggerFireworks:bn}=Pi(),mr=i.useRef(new Map),Kt=i.useRef(0),vs=i.useCallback(()=>{Kt.current+=1,Nt.current&&hr(!0)},[]),js=i.useCallback(()=>{Kt.current=Math.max(0,Kt.current-1),Nt.current&&Kt.current===0&&hr(!1)},[]),[Cs,qt]=i.useState(new Set),[vn,fr]=i.useState(new Set),[Ss,gr]=i.useState(!1),[jn,Cn]=i.useState(0),[Sn,pr]=i.useState(!1),[Ns,ks]=i.useState(ir?.generatedHighlights??[]),Nn=vn.size>0||et.size()>0||et.isRunning(),xr=i.useCallback(()=>{const s=lr.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),Vs=me||d?.projectDirectory||null,Rs=j?.current||null,kn=i.useMemo(()=>{const s=j?.tracking;return s?s.startsWith("origin/"):!0},[j?.tracking]),yr=i.useMemo(()=>{const s=d?.createdFromBranch,r=typeof s=="string"?s.trim():"",l=typeof j?.current=="string"?j.current.trim():"",u=typeof Vt=="string"?Vt.trim():"";return r?r===l&&r.startsWith("opencode/")&&u.length>0&&u!==r?u:r:u||l||"HEAD"},[d?.createdFromBranch,j,Vt]),Jt=i.useCallback(()=>{ks([])},[]),[Is,Vn]=i.useState(new Set),[Yt,Rn]=i.useState(new Map),[Qt,Ps]=i.useState(new Set),Fs=i.useRef(Yt),It=i.useRef(Qt),[In,yt]=i.useState(null),[wr,br]=i.useState(""),[ge,Xt]=i.useState(null),[Pn,vr]=i.useState(!1),[Fn,jr]=i.useState(!1),[Dn,Cr]=i.useState(null),[Sr,Nr]=i.useState(null),[Bn,Zt]=i.useState([]),[Mn,wt]=i.useState(!1),[An,Pt]=i.useState([]),[es,Ft]=i.useState("merge"),[On,Ds]=i.useState(null),[Bs,kr]=i.useState(!1),[Ms,Tn]=i.useState(100),[En,Ln]=i.useState(0),Pe=i.useMemo(()=>T?`openchamber.conflict:${T}`:null,[T]),Vr=i.useCallback((s,r,l)=>{if(!Pe||typeof window>"u")return;const u={directory:s,conflictFiles:r,operation:l};window.localStorage.setItem(Pe,JSON.stringify(u))},[Pe]),Fe=i.useCallback(()=>{!Pe||typeof window>"u"||window.localStorage.removeItem(Pe)},[Pe]),Ue=i.useCallback((s,r)=>{Pt(s),Ft(r),wt(!0),a&&Vr(a,s,r)},[a,Vr]);i.useEffect(()=>{if(!Pe||typeof window>"u"||!a)return;const s=window.localStorage.getItem(Pe);if(s)try{const r=JSON.parse(s);if(r.directory!==a){window.localStorage.removeItem(Pe);return}Pt(r.conflictFiles??[]),Ft(r.operation??"merge"),wt(!0)}catch{window.localStorage.removeItem(Pe)}},[Pe,a]);const[zn,Rr]=i.useState(!1),[ts,Dt]=i.useState(null),[As,Gn]=i.useState("merge"),[Os,_n]=i.useState(""),[Ts,Hn]=i.useState(""),$n=i.useCallback(s=>{bi(s).then(r=>{if(r.ok){p.success(e("gitView.toast.commitHashCopied"));return}p.error(e("gitView.toast.copyFailed"))})},[e]),Wn=i.useCallback(s=>{Vn(r=>{const l=new Set(r);return l.has(s)?l.delete(s):l.add(s),l})},[]);i.useEffect(()=>{Fs.current=Yt},[Yt]),i.useEffect(()=>{It.current=Qt},[Qt]),i.useEffect(()=>{if(!a||!n)return;const s=Array.from(Is).filter(l=>!Fs.current.has(l)&&!It.current.has(l));if(s.length===0)return;let r=!1;return Ps(l=>{const u=new Set(l);for(const N of s)u.add(N);return It.current=u,u}),Promise.all(s.map(l=>n.getCommitFiles(a,l).then(u=>({hash:l,files:u.files})).catch(u=>(console.error("Failed to fetch commit files:",u),{hash:l,files:[]})))).then(l=>{r||(Rn(u=>{const N=new Map(u);for(const{hash:v,files:B}of l)N.set(v,B);return Fs.current=N,N}),Ps(u=>{const N=new Set(u);for(const{hash:v}of l)N.delete(v);return It.current=N,N}))}),()=>{r=!0,Ps(l=>{let u=!1;const N=new Set(l);for(const v of s)N.delete(v)&&(u=!0);return u?(It.current=N,N):l})}},[Is,a,n]),i.useEffect(()=>{if(!a)return;const s=dt.get(a)??null;xt(s?.commitMessage??""),ks(s?.generatedHighlights??[])},[a]),i.useEffect(()=>{a&&Jo(a,{directory:a,commitMessage:Rt,generatedHighlights:Ns})},[Rt,a,Ns]),i.useEffect(()=>{o&&(Z(),A(),R())},[o,Z,A,R]);const ss=i.useCallback(async()=>{if(!a||!n?.getRemotes||J!==!0){Me([]);return}try{const s=await n.getRemotes(a);Nt.current&&Me(s)}catch{Nt.current&&Me([])}},[a,n,J]);i.useEffect(()=>{o&&ss()},[o,ss]),i.useEffect(()=>{o&&m&&a&&(ce(m),ee(a,n))},[o,m,a,ce,ee,n]),i.useEffect(()=>{if(o&&a)return vi.onGitRefreshHint(s=>{Ke(s.directory)===Ke(a)&&(s.paths?.length&&je(a,s.paths),ne(a,n,{silent:!0}))})},[o,je,a,ne,n]);const se=i.useCallback(async(s=!0)=>{if(a)try{await Promise.all([ne(a,n),X(a,n)])}catch(r){if(s){const l=r instanceof Error?r.message:e("gitView.toast.refreshRepositoryFailed");p.error(l)}}},[a,n,ne,X,e]),ue=i.useCallback(async()=>{a&&await ae(a,n,Ie)},[a,n,ae,Ie]),lt=i.useCallback(async s=>{if(!a)return;const r=Promise.allSettled([X(a,n),ue()]);s&&r.then(s),await ne(a,n).catch(()=>{})},[a,n,X,ne,ue]),Es=i.useCallback(async()=>{a&&await ve(a,n)},[a,n,ve]);i.useEffect(()=>{if(!o||!a||!n?.hasLocalIdentity||J!==!0)return;const s=typeof G=="string"?G.trim():"";if(!s||s==="global")return;const r=ut(),l=JSON.stringify([r,a]);if(mr.current.get(l)===s)return;let N=!1,v=!1;return(async()=>{try{const W=await n.hasLocalIdentity?.(a);if(N||ut()!==r||W===!0||(vs(),v=!0,await n.setGitIdentity(a,s),N||ut()!==r))return;mr.current.set(l,s),await Es()}catch(W){!N&&ut()===r&&console.warn("Failed to auto-apply default git identity:",W)}finally{v&&js()}})(),()=>{N=!0}},[o,vs,a,G,js,n,J,Es]);const tt=i.useMemo(()=>j?[...j.files??[]].sort((r,l)=>r.path.localeCompare(l.path)):[],[j]),Ne=i.useMemo(()=>tt.filter(an),[tt]),Ls=i.useMemo(()=>tt.filter(Yo),[tt]);i.useEffect(()=>{if(!o||!a||tt.length===0)return;const s=[],r=new Set,l=N=>{!N||r.has(N)||(r.add(N),s.push(N))};if(Ne.forEach(N=>l(N.path)),or.forEach(l),tt.slice(0,Uo).forEach(N=>l(N.path)),s.length===0)return;const u=window.setTimeout(()=>{ke(a,n,s,{maxFiles:Wo})},120);return()=>{window.clearTimeout(u)}},[o,tt,a,n,ke,Ne,or]);const Bt=async(s,r,l=!1)=>{if(!a)return;const u=te.start();if(!u)return;Ut(s);const N=e(s==="fetch"?"gitView.sync.fetch":s==="pull"?"gitView.sync.pull":s==="publish"?"gitView.publish.title":"gitView.sync.syncChanges");let v=null;try{if(s==="sync"||s==="publish"){const B=await U.prepare(s==="publish"?"push":"sync",{forceChoose:l,onOperation:u.onOperation});v=Ri(await B())}else if(r&&j)await $r({action:s,directory:a,remoteName:r.name,status:j,sourceControl:h,git:n,onOperation:u.onOperation});else throw new be("tracking-required");if(!u.isCurrent())return;s==="fetch"&&r?p.success(e("gitView.toast.fetchedFromRemote",{name:r.name})):s==="pull"&&r?p.success(e("gitView.toast.pulledFromRemote",{name:r.name})):s==="sync"?p.success(v?.kind==="up-to-date"?e("gitView.toast.alreadyUpToDate"):v?.kind==="pulled"?e("gitView.toast.pulledFromRemote",{name:v.remoteName}):v?.kind==="pushed"?e("gitView.toast.pushedToUpstream",{name:v.remoteName}):e("gitView.toast.syncedChanges")):s==="publish"&&p.success(e("gitView.publish.succeeded")),await lt()}catch(B){if(B instanceof Et||B instanceof Wr){if(B instanceof Et&&B.read.availability==="available"&&p.error(e("gitView.toast.syncActionFailed",{action:N}),{description:B.message||void 0}),u.isCurrent()&&await lt(),u.isCurrent()&&B instanceof Et&&B.read.availability==="available"&&B.read.operation.state==="conflicted"&&B.read.operation.error.code==="CONFLICT"){const Ee=((await n.getGitStatus(a).catch(()=>null))?.files??[]).filter(Ws).map(Sa=>Sa.path);Ee.length>0&&Ue(Ee,"merge")}return}if(B instanceof be&&B.code==="stale-runtime")return;if(B instanceof be&&U.errorMessage(B)){p.info(U.errorMessage(B));return}await lt();const W=B instanceof be?B.code==="contributor-publish-cancelled-after-update"?e("gitView.toast.contributorPublishCancelledAfterUpdate"):B.code==="contributor-publish-cancelled"?e("gitView.toast.contributorPublishCancelled"):e("gitView.toast.syncActionFailed",{action:N}):B instanceof Error?B.message:e("gitView.toast.syncActionFailed",{action:N});p.error(W)}finally{u.finish(),u.isCurrent()&&Ut(null)}},Un=i.useCallback(async s=>{if(!a)return;const r=s.name.trim();if(!r){p.error(e("gitView.toast.remoteNameRequired"));return}if(r==="origin"){p.error(e("gitView.toast.cannotRemoveOriginRemote"));return}Cr(r);try{await n.removeRemote(a,{remote:r}),p.success(e("gitView.toast.removedRemote",{name:r})),await Promise.all([se(!1),ss()])}catch(l){const u=l instanceof Error?l.message:`Failed to remove ${r}`;p.error(u)}finally{Cr(null)}},[a,n,ss,se,e]),Ir=async(s={})=>{if(!a)return;if(!Rt.trim()){p.error(e("gitView.toast.enterCommitMessage"));return}const r=Ne.map(v=>v.path).sort();if(r.length===0){p.error(e("gitView.toast.stageFileToCommit"));return}const l=s.pushAfter?"commitAndPush":"commit";dr(l);let u=null,N="pending";try{if(await n.createGitCommit(a,Rt.trim(),{files:r,stageFiles:[]}),N="local",le(a),le(a),p.success(e("gitView.toast.commitCreated")),xt(""),Jt(),s.pushAfter){if(u=te.start(),!u){p.warning(e("gitView.publish.commitKept")),await lt();return}const v=await U.prepare("push",{onOperation:u.onOperation});Ut("publish"),await v(),N="published",p.success(e("gitView.publish.succeeded")),bn()}await lt(()=>Cn(v=>v+1))}catch(v){if(s.pushAfter&&N==="local"&&p.warning(e("gitView.publish.commitKept")),v instanceof Et||v instanceof Wr){v instanceof Et&&v.read.availability==="available"&&p.error(e("gitView.toast.pushFailed"),{description:v.message||void 0}),await lt();return}if(v instanceof be&&v.code==="stale-runtime")return;if(v instanceof be&&U.errorMessage(v)){p.info(U.errorMessage(v));return}s.pushAfter&&await lt();const B=v instanceof be?v.code==="contributor-publish-cancelled-after-update"?e("gitView.toast.contributorPublishCancelledAfterUpdate"):v.code==="contributor-publish-cancelled"?e("gitView.toast.contributorPublishCancelled"):e("gitView.toast.syncActionFailed",{action:e("gitView.sync.syncChanges")}):v instanceof Error?v.message:e("gitView.toast.createCommitFailed");p.error(B)}finally{u?.finish(),dr(null),s.pushAfter&&Ut(null)}},Kn=i.useCallback(async()=>{if(!a)return;const s=Ne.map(r=>r.path).sort();if(s.length===0){p.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:a,selectedFiles:s.length}),pr(!0);try{const{message:r}=await Hr(a,s),l=r.subject?.trim()??"",u=Array.isArray(r.highlights)?r.highlights:[];if(l){let N=l;if(kt&&pt.length>0){const v=nn(l,pt);if(v){const{code:B,emoji:W}=v;!l.startsWith(B)&&!l.startsWith(W)&&(N=`${B} ${l}`)}}xt(N)}ks(u),xr()}catch(r){console.error("[git-generation][browser] GitView generate handler failed",{message:r instanceof Error?r.message:String(r),error:r});const l=r instanceof Error?r.message:e("gitView.toast.generateCommitMessageFailed");p.error(l)}finally{pr(!1)}},[a,Ne,kt,pt,xr,e]),zs=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",qn=async s=>{if(!a||!j)return;const r=$s(oe);if(r.length>0){p.error(e("gitView.toast.cannotCreateBranch",{reason:zs(r[0])}));return}const l=j.current??null;try{await n.createBranch(a,s,l??"HEAD"),p.success(e("gitView.toast.createdBranch",{name:s})),await n.checkoutBranch(a,s),await se(),await ue()}catch(u){if(u instanceof be&&u.code==="stale-runtime")return;const N=u instanceof Error?u.message:e("gitView.toast.createBranchFailed");throw p.error(N),u}},Jn=async(s,r)=>{if(!a)return;const l=$s(oe);if(l.length>0){p.error(e("gitView.toast.cannotRenameBranch",{reason:zs(l[0])}));return}try{await n.renameBranch(a,s,r),p.success(e("gitView.toast.renamedBranch",{oldName:s,newName:r})),await se(),await ue()}catch(u){const N=u instanceof Error?u.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:r});p.error(N)}},Yn=async s=>{if(!a)return;const r=$s(oe);if(r.length>0){p.error(e("gitView.toast.cannotCheckout",{reason:zs(r[0])}));return}const l=s.replace(/^remotes\//,"");if(j?.current!==l){if((j?.files?.length??0)>0){Dt(l);return}await Gs(l)}},Gs=async s=>{if(!a)return;const r=s;try{const l=await n.checkoutBranch(a,r);p.success(e("gitView.toast.checkedOut",{name:l?.branch||r})),await se(),await ue()}catch(l){const u=l instanceof Error?l.message:e("gitView.toast.checkoutFailed",{name:r});p.error(u)}},Qn=async s=>{if(!a)return;const r=ut();vs();try{const l=await Ki({directory:a,identity:s,remoteName:Ae||null},{git:n,sourceControl:h});if(ut()!==r)return;l.status==="failed"?p.error(e("gitView.toast.applyIdentityFailed")):p.success(e("gitView.toast.appliedIdentity",{name:Vi(s,e)})),await Es()}catch(l){if(ut()!==r)return;const u=l instanceof Error?l.message:e("gitView.toast.applyIdentityFailed");p.error(u)}finally{js()}},Mt=i.useMemo(()=>c?.all?c.all.filter(s=>!s.startsWith("remotes/")).sort():[],[c]),At=i.useMemo(()=>c?.all?c.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[c]),Xn=i.useMemo(()=>Eo(Ve.map(s=>s.name),At),[Ve,At]),st=j?.current??null,Pr=i.useMemo(()=>{const s=$.contexts[0]?.primaryRemote;return s?c?.defaultBranches?.[s]:void 0},[$.contexts,c]),ct=i.useMemo(()=>zi({remoteNames:new Set($.contexts[0]?.primaryRemote?[$.contexts[0].primaryRemote]:[]),knownRemoteNames:new Set($.read?.repository.remotes.map(s=>s.name)??[]),localBranches:Mt,worktreeCreatedFromBranch:d?.createdFromBranch,rootBranchHint:Vt,defaultBranch:Pr,headBranch:st,fallbackToConventional:!1}),[st,Pr,$.contexts,Mt,$.read,Vt,d?.createdFromBranch]),Zn=i.useMemo(()=>{const s=$.contexts[0]?.primaryRemote,r=s?`${s}/${ct}`:null;return r&&At.includes(r)?r:ct},[ct,$.contexts,At]),Fr=ji(),ea=i.useMemo(()=>Go(V,F,Fr),[V,F,Fr]),Dr=$.read?$.read.binding?.providers.find(s=>s.readiness==="ready")?.accountId??null:void 0,ta=i.useMemo(()=>_o(V,F,L,Dr),[Dr,L,V,F]),sa=Ne.length,ra=re||cr!==null||ur!==null,na=!!(d&&Vs&&Rs&&kn),Br=!!st,rt=na&&Vs&&Rs&&d?{repoRoot:Vs,sourceBranch:Rs,worktreeMetadata:d}:null;i.useEffect(()=>{if(!a||!n||!I?.all?.length||!st||!ct||st===ct){yt(null);return}let s=!1;return(async()=>{try{const l=await n.getGitLog(a,{from:ct,to:"HEAD",maxCount:Ie});if(s)return;const u=new Set((l?.all??[]).map(v=>v.hash).filter(v=>typeof v=="string"&&v.length>0));if(u.size===0){yt(null);return}const N=I.all.findIndex(v=>!u.has(v.hash));if(N===0){yt(null);return}if(N===-1){yt({insertBeforeIndex:I.all.length,branchName:st,direction:"up"});return}yt({insertBeforeIndex:N,branchName:st,direction:"up"})}catch{s||yt(null)}})(),()=>{s=!0}},[ct,st,a,n,I,Ie]),i.useEffect(()=>{Ds(null)},[a]),i.useEffect(()=>{if(ge!=="graph"||!a){ge!=="graph"&&Ds(null);return}let s=!1;return kr(!0),n.getGitLog(a,{maxCount:Ms,all:!0}).then(r=>{s||Ds(r)}).catch(r=>{console.error("Failed to fetch graph log:",r)}).finally(()=>{s||kr(!1)}),()=>{s=!0}},[ge,a,Ms,En,n]);const Ot=i.useCallback((s,r)=>{if(!a||s.length===0)return;const l=Array.from(new Set(s));fr(N=>{const v=new Set(N);return l.forEach(B=>v.add(B)),v});const u=Be(a,l,r);et.enqueue({directory:a,direction:r,paths:new Set(l),rollback:()=>St(a,u)}),Wt()},[a,et,Be,St,Wt]),_s=i.useCallback(async s=>{if(a){qt(r=>{const l=new Set(r);return l.add(s),l});try{await n.revertGitFile(a,s,{scope:"working"}),p.success(e("gitView.toast.revertedFile",{path:s})),await se(!1)}catch(r){const l=r instanceof Error?r.message:e("gitView.toast.revertFailed");p.error(l)}finally{qt(r=>{const l=new Set(r);return l.delete(s),l})}}},[a,se,n,e]),Tt=i.useCallback(async(s,r,l="all")=>{if(!a||s.length===0)return;const u=Array.from(new Set(s));if(Ss||u.some(W=>Cs.has(W)))return;const N=new Set(Ne.map(W=>W.path)),v=l==="all"&&u.some(W=>N.has(W));r&&gr(!0),qt(W=>{const ie=new Set(W);return u.forEach(Ee=>ie.add(Ee)),ie});const B=[];try{if(await Ci(u,Ko,async W=>{try{await n.revertGitFile(a,W,{scope:l})}catch(ie){B.push({path:W,message:ie instanceof Error?ie.message:e("gitView.toast.revertFailed")})}}),v&&B.length<u.length&&le(a),await se(!1),B.length===0)p.success(u.length===1?e("gitView.toast.revertedFilesSingle",{count:u.length}):e("gitView.toast.revertedFilesPlural",{count:u.length}));else if(B.length===u.length)p.error(B[0]?.message||e("gitView.toast.revertFailed"));else{const W=u.length-B.length;p.warning(W===1?e("gitView.toast.revertedSomeSingle",{success:W,failed:B.length}):e("gitView.toast.revertedSomePlural",{success:W,failed:B.length}))}}finally{qt(W=>{const ie=new Set(W);return u.forEach(Ee=>ie.delete(Ee)),ie}),r&&gr(!1)}},[le,a,n,Ss,se,Cs,Ne,e]),aa=i.useCallback(async s=>{await Tt(s,!0)},[Tt]),ia=i.useCallback(async s=>{await Tt(s,!1,"working")},[Tt]),Hs=i.useCallback((s,r)=>{if(g&&!ze){Ge(g,s,r);return}We(s,r)},[g,ze,We,Ge]),oa=i.useCallback(()=>bs(!0),[]),la=i.useMemo(()=>{const s=[];return Ne.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:Ne,statsScope:"staged",actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:r=>e("gitView.changes.unstageFileAria",{path:r}),onActionFile:r=>{Ot([r],"unstage")},onActionAll:r=>{Ot(r,"unstage")},onViewDiff:r=>Hs(r,!0),onRevertFile:_s,showRevertActions:!1,accent:!0}),Ls.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:Ls,statsScope:"working",actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:r=>e("gitView.changes.stageFileAria",{path:r}),onActionFile:r=>{Ot([r],"stage")},onActionAll:r=>{Ot(r,"stage")},onViewDiff:r=>Hs(r,!1),onRevertFile:_s}),s},[_s,Hs,Ot,Ne,e,Ls]),ca=i.useCallback(s=>{if(s.length===0)return;const r=s.map(l=>l.trim()).filter(Boolean);if(r.length===0){Jt();return}xt(l=>{const u=l.trim(),N=u.length>0?`
1
+ import{R as i,r as he,j as t,f as Ht}from"./vendor-react-BUCujlKS.js";import{u as it,G as at,L as _t,fI as Na,aL as Ar,fc as Tr,A as p,I as _,aR as Js,aS as Ys,be as on,aT as Qs,az as Xs,ay as Zs,as as er,at as tr,au as os,av as ls,B as K,fJ as ka,fK as Va,t as ht,q as mt,D as ft,l as gt,F as jt,y as Er,V as us,W as ds,X as hs,fL as Ra,N as fe,fM as Ia,fN as Pa,fO as Fa,fP as Da,aU as Ba,bU as Ma,c6 as Oa,fQ as Aa,fR as Ta,fS as Ea,fT as La,fU as za,fV as Ga,fW as _a,n as ln,cd as Ha,cb as $a,ca as Wa,cc as Ua,c4 as Ka,C as qa,o as qs,fX as Ja,z as cs,fY as be,ff as Ya,fk as Qa,fZ as Xa,b7 as Za,aE as ei,f_ as ti,dB as Lr,b3 as si,bd as ri,b5 as ni,dy as ai,f$ as ii,b6 as oi,g0 as li,fj as ci,ek as ui,g1 as di,aD as hi,b8 as mi,g2 as fi,fh as gi,b9 as zr,ah as ns,bb as Gr,ba as _r,eY as pi,g3 as xi,a1 as yi,g4 as wi,aA as bi,P as vi,g5 as Hr,fe as ji,g6 as Ci,g7 as $r,cR as Si,g8 as Ni,g9 as ki,ga as Vi,gb as $s,gc as Ri,fq as Et,gd as Wr}from"./useAppFontEffects-Dm6zEvrf.js";import{u as Ii,b as Pi}from"./main-DN47yDMe.js";import{f as Fi,g as Di,h as Bi,$ as Mi,a0 as Oi,R as Ai,a1 as Ti,X as Ei,V as Li,a2 as zi,a3 as Ws,a4 as Gi,N as _i,a5 as Hi,Y as $i,a6 as Wi,a7 as Ui,a8 as Ki}from"./runtimeEndpointReset-lg1O2gVX.js";import{u as Ur}from"./vendor-zustand-BAGL70zf.js";import{k as qi,u as zt,a_ as Ji,n as Ke,a5 as ut}from"./katex.min-F4TD1ekM.js";import{R as Yi,I as Qi,C as Xi,a as Zi,b as eo,D as to}from"./InProgressOperationBanner-BVDKUDqn.js";import{P as so}from"./PierreDiffViewer-BZDNV4Uj.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-CPKyhvxM.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-zod-DDir2TeQ.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-tanstack-react-virtual-Bmi0tTrf.js";import"./vendor-tanstack-virtual-core-CdGDGrnp.js";import"./vendor-framer-motion-DxDVhOLc.js";import"./vendor-motion-dom-HXPOMxb7.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-codemirror-commands-dar6chwA.js";import"./vendor-codemirror-state-Dek9sMtw.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-B66jUSmE.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-language-DyL0aCoH.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-streamparser-CmlTsbN2.js";import"./vendor-codemirror-lang-javascript-Cem6LjJ8.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CIqXJolH.js";import"./vendor-codemirror-lang-json-C9rLLO0q.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-9qjxcVkg.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-D7VQUxeE.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-Cikh4w2I.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-VzNDjH03.js";import"./vendor-codemirror-lang-python-DVl8-2Op.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-capacitor-core-B4EWRrHz.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-legendapp-list-D2O6oUGf.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./useRootScrollLock-mqVhK2HB.js";import"./moveWorkspacePath-CENAo75W.js";import"./vendor-opencode-client-h8RufjAw.js";import"./ChangedPathLabel-BCiU4QDF.js";import"./parseDiffFromFile-BSmRvd3V.js";import"./computeVirtualFileMetrics-DDyA16hp.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"./vendor-diff-C3JhlQdm.js";import"./isDiffPlainText-yXcpftjI.js";import"./pierreDiffTint-cyYFR1bm.js";import"./Virtualizer-nenVQKi3.js";import"./useInlineCommentController-a2JepiF3.js";import"./appThemeRegistry-BWap7OfW.js";import"./textMateThemeFromAppTheme-tYpAceV3.js";const cn="gitmojiCache",ro=1e3*60*60*24*7,un="1",no="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",dn=o=>{if(!o||typeof o!="object")return!1;const e=o;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Us=()=>{if(typeof window>"u")return null;try{const o=window.localStorage.getItem(cn);if(!o)return null;const e=JSON.parse(o);return!e||e.version!==un||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(dn),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},ao=o=>{if(!(typeof window>"u"))try{const e={gitmojis:o,fetchedAt:Date.now(),version:un};window.localStorage.setItem(cn,JSON.stringify(e))}catch{return}},Kr=o=>Date.now()-o.fetchedAt<ro;let as=null;const Gt=new Set,qr=async()=>{if(as)return as;const o=(async()=>{try{const e=await fetch(no);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),h=Array.isArray(n.gitmojis)?n.gitmojis.filter(dn):[];return ao(h),Gt.forEach(x=>x(h)),h}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return Gt.forEach(h=>h(n)),n}finally{as=null}})();return as=o,o},io=o=>{const[e,n]=i.useState(()=>o?Us()?.gitmojis??[]:[]),[h,x]=i.useState(!1),g=i.useRef(o);g.current=o,i.useEffect(()=>{if(!o){Gt.delete(n),n([]),x(!1);return}const m=Us();if(m&&(n(m.gitmojis),Kr(m)))return;Gt.add(n),x(!0);let f=!1;return qr().finally(()=>{!f&&g.current&&x(!1)}),()=>{f=!0,Gt.delete(n)}},[o]);const y=i.useCallback(async()=>{if(!g.current)return[];if(e.length>0)return e;const m=Us();return m&&Kr(m)?m.gitmojis:qr()},[e]);return{gitmojis:e,isLoading:h,ensureLoaded:y}},Ct=async(o,e)=>{const n=await qi(`/api/git/integrate/${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const h=await n.json().catch(()=>null);throw new Error(h?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function Lt(o){return Ct("plan",o)}async function oo(o){return Ct("conflict-details",{tempWorktreePath:o})}async function lo(o){return(await Ct("cherry-pick-status",{tempWorktreePath:o})).inProgress}async function co(o){return Ct("run",{plan:o})}async function uo(o){await Ct("abort",{state:o})}async function ho(o){return Ct("continue",{state:o})}const mo=({repoRoot:o,sourceBranch:e,worktreeMetadata:n,localBranches:h,defaultTargetBranch:x,refreshKey:g,onRefresh:y,showHeader:m=!0})=>{const{t:f}=it(),w=at(d=>d.currentSessionId),[M,A]=he.useState(!1),[k,T]=he.useState(""),C=he.useRef(null),z=he.useMemo(()=>_t(h,k,d=>[d]),[h,k]),[P,b]=he.useState(x);he.useEffect(()=>{b(x)},[x]),he.useEffect(()=>{if(M){const d=setTimeout(()=>{C.current?.focus()},0);return()=>clearTimeout(d)}},[M]);const H=!!(o&&e&&P&&P!=="HEAD"&&e!==P),[S,D]=he.useState({kind:"idle"}),[V,F]=he.useState(!1),[G,Z]=he.useState([]),O=he.useMemo(()=>w?`openchamber.integrate.conflict:${w}`:null,[w]);he.useEffect(()=>{if(!O||typeof window>"u")return;const d=window.localStorage.getItem(O);if(!d)return;let c=!1;try{const I=JSON.parse(d);if(!I?.tempWorktreePath||I.repoRoot!==o){window.localStorage.removeItem(O);return}(async()=>{const L=await lo(I.tempWorktreePath).catch(()=>!1);if(c)return;if(!L){window.localStorage.removeItem(O);return}const re=await oo(I.tempWorktreePath).catch(()=>null);c||re&&D({kind:"conflict",state:I,details:re})})()}catch{window.localStorage.removeItem(O)}return()=>{c=!0}},[O,o]),he.useEffect(()=>{if(!H){D({kind:"idle"});return}let d=!1;return D({kind:"loading"}),(async()=>{try{const c=await Lt({repoRoot:o,sourceBranch:e,targetBranch:P});if(d)return;if(D({kind:"ready",plan:c}),c.commits.length>0){const L=c.commits.slice(-50).reverse(),re=await Na(o,L);d||(Z(re),F(!1))}else d||(Z([]),F(!1))}catch{d||D({kind:"idle"})}})(),()=>{d=!0}},[H,o,e,P,g]);const R=he.useCallback(d=>{w&&at.getState().setWorktreeMetadata(w,{...n,createdFromBranch:d})},[w,n]),E=at(d=>d.openNewSessionDraft),a=he.useCallback(async d=>{const c=await Ar("git.integrate.cherrypick.resolve.visible",{current_commit:d.state.currentCommit,target_branch:d.state.targetBranch}),I=await Ar("git.integrate.cherrypick.resolve.instructions",{repo_root:d.state.repoRoot,temp_worktree_path:d.state.tempWorktreePath,source_branch:d.state.sourceBranch,target_branch:d.state.targetBranch,current_commit:d.state.currentCommit}),L=`Cherry-pick conflict context (JSON)
2
+ ${JSON.stringify({repoRoot:d.state.repoRoot,tempWorktreePath:d.state.tempWorktreePath,sourceBranch:d.state.sourceBranch,targetBranch:d.state.targetBranch,currentCommit:d.state.currentCommit,remainingCommits:d.state.remainingCommits,statusPorcelain:d.details.statusPorcelain,unmergedFiles:d.details.unmergedFiles,currentPatchMeta:d.details.currentPatchMeta,currentPatch:d.details.currentPatch,diff:d.details.diff},null,2)}`;return{visibleText:c,instructionsText:I,payloadText:L}},[]),Y=Tr(d=>d.setPendingInputText),q=Tr(d=>d.setPendingSyntheticParts),J=he.useCallback(async(d,c)=>{const I=await a(d);if(c){E({directoryOverride:d.state.tempWorktreePath,initialPrompt:I.visibleText,syntheticParts:[{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}]});return}if(!w){p.error(f("gitView.integrate.noActiveSession"),{description:f("gitView.integrate.noActiveSessionDescription")});return}Y(I.visibleText,"replace"),q([{text:I.instructionsText,synthetic:!0},{text:I.payloadText,synthetic:!0}])},[w,a,E,Y,q,f]),j=he.useCallback(async()=>{if(S.kind==="ready"){if(S.plan.commits.length===0){p.message(f("gitView.integrate.noCommitsToMoveToast"));return}D({kind:"running",plan:S.plan});try{const d=await co(S.plan);if(d.kind==="success"){p.success(f("gitView.integrate.commitsMovedToast"),{description:d.moved===1?f("gitView.integrate.commitsMovedDescriptionSingle",{count:d.moved,branch:S.plan.targetBranch}):f("gitView.integrate.commitsMovedDescriptionPlural",{count:d.moved,branch:S.plan.targetBranch})});const c=await Lt(S.plan);D({kind:"ready",plan:c}),y?.();return}d.kind==="conflict"&&(p.error(f("gitView.integrate.cherryPickConflictToast"),{description:f("gitView.integrate.cherryPickConflictDescription")}),D({kind:"conflict",state:d.state,details:d.details}),O&&typeof window<"u"&&window.localStorage.setItem(O,JSON.stringify(d.state)))}catch(d){const c=d instanceof Error?d.message:String(d);p.error(f("gitView.integrate.failedToMoveToast"),{description:c});const I=await Lt({repoRoot:o,sourceBranch:e,targetBranch:P}).catch(()=>null);D(I?{kind:"ready",plan:I}:{kind:"idle"})}}},[S,y,o,e,P,O,f]),U=he.useCallback(async()=>{if(S.kind==="conflict")try{await uo(S.state),p.message(f("gitView.integrate.cherryPickAbortedToast")),O&&typeof window<"u"&&window.localStorage.removeItem(O)}finally{const d=await Lt({repoRoot:o,sourceBranch:e,targetBranch:P}).catch(()=>null);D(d?{kind:"ready",plan:d}:{kind:"idle"})}},[S,o,e,P,O,f]),te=he.useCallback(async()=>{if(S.kind==="conflict")try{const d=await ho(S.state);if(d.kind==="success"){p.success(f("gitView.integrate.cherryPickFinishedToast"));const c=await Lt({repoRoot:o,sourceBranch:e,targetBranch:P}).catch(()=>null);D(c?{kind:"ready",plan:c}:{kind:"idle"}),O&&typeof window<"u"&&window.localStorage.removeItem(O),y?.();return}d.kind==="conflict"&&(D({kind:"conflict",state:d.state,details:d.details}),O&&typeof window<"u"&&window.localStorage.setItem(O,JSON.stringify(d.state)))}catch(d){const c=d instanceof Error?d.message:String(d);p.error(f("gitView.integrate.cherryPickContinueFailedToast"),{description:c})}},[S,o,e,P,y,O,f]);return!o||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[m?t.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(_,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:f("gitView.integrate.title")}),S.kind==="ready"&&S.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:f("gitView.integrate.toMoveCount",{count:S.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:S.kind==="loading"||S.kind==="running"?t.jsx(_,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}):null,t.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:f("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",P]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Js,{open:M,onOpenChange:A,children:[t.jsx(Ys,{asChild:!0,children:t.jsxs("button",{type:"button",className:on({size:"default"}),children:[f("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:P}),t.jsx(_,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Qs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Xs,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Zs,{ref:C,placeholder:f("gitView.branch.searchPlaceholder"),value:k,onValueChange:T,onKeyDown:d=>d.stopPropagation()}),t.jsxs(er,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(tr,{children:f("gitView.branch.empty")}),t.jsx(os,{heading:f("gitView.branch.localBranches"),children:z.map(d=>t.jsx(ls,{value:d,onSelect:()=>{b(d),R(d),A(!1),T("")},children:d},d))})]})]})})]}),S.kind==="ready"?t.jsx(K,{size:"sm",onClick:()=>{j()},disabled:!H||S.plan.commits.length===0,children:f("gitView.integrate.move")}):S.kind==="loading"?t.jsx(K,{size:"sm",variant:"outline",disabled:!0,children:f("gitView.integrate.checking")}):S.kind==="running"?t.jsx(K,{size:"sm",variant:"outline",disabled:!0,children:f("gitView.integrate.moving")}):null]}),S.kind==="ready"&&S.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:f("gitView.integrate.noCommitsToMove")}),S.kind==="ready"&&S.plan.commits.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"typography-meta text-foreground",children:[f("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",S.plan.commits.length,")"]})]}),G.length>0&&S.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>F(d=>!d),className:"typography-micro text-muted-foreground hover:text-foreground",children:f(V?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(V?G:G.slice(0,5)).map(d=>t.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[t.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:d.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:d.subject||d.sha})]},d.sha)),G.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:f("gitView.integrate.previewUnavailable")}),S.plan.commits.length>G.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:f("gitView.integrate.showingFirstCommits",{count:G.length})})]})]}),S.kind==="conflict"&&t.jsxs("div",{className:"rounded-md oc-tile p-3 space-y-2",children:[t.jsx("div",{className:"typography-meta text-foreground",children:f("gitView.integrate.conflictsInFiles",{count:S.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[f("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:S.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[S.details.unmergedFiles.slice(0,6).map(d=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded oc-tile-inset text-muted-foreground",children:d},d)),S.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:f("gitView.integrate.moreFiles",{count:S.details.unmergedFiles.length-6})})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(K,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{U()},children:f("gitView.operation.abort")}),t.jsxs(K,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!w,onClick:()=>{J({state:S.state,details:S.details},!1)},children:[t.jsx(_,{name:"sparkling",className:"size-3.5"}),f("gitView.integrate.currentSession")]}),t.jsxs(K,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{J({state:S.state,details:S.details},!0)},children:[t.jsx(_,{name:"sparkling",className:"size-3.5"}),f("gitView.integrate.newSession")]}),t.jsx(K,{size:"sm",className:"typography-meta",onClick:()=>{te()},children:f("gitView.operation.continue")})]})]})]})]})},fo=({open:o,onOpenChange:e,directory:n,hasUncommittedChanges:h,hasStagedChanges:x=!1,uncommittedFileCount:g,onChanged:y})=>{const{t:m}=it(),[f,w]=i.useState([]),[M,A]=i.useState(!1),[k,T]=i.useState(""),[C,z]=i.useState(""),[P,b]=i.useState(null),[H,S]=i.useState({}),D=i.useCallback(async()=>{if(n){A(!0);try{const R=await ka(n);w(R.stashes),S({})}catch(R){p.error(R instanceof Error?R.message:m("gitView.stashes.toast.loadFailed"))}finally{A(!1)}}},[n,m]);i.useEffect(()=>{o&&D()},[D,o]),i.useEffect(()=>{if(!o||!n||f.length===0)return;let R=!1;const E=f.map(a=>a.ref);return Va(n,E).then(a=>{R||S(a.counts)}).catch(()=>{}),()=>{R=!0}},[n,o,f]);const V=i.useMemo(()=>_t(f,k,R=>[R.message,R.ref,R.relativeTime]),[k,f]),F=i.useCallback(async R=>{await D(),await y?.(R)},[D,y]),G=async()=>{if(!(!n||P)){b("create");try{const R=await Ra(n,{message:C.trim()||void 0});R.created?(p.success(m("gitView.stashes.toast.created")),z("")):p.info(m("gitView.stashes.toast.noChanges")),await F({affectsIndex:!!(R.created&&x)})}catch(R){p.error(R instanceof Error?R.message:m("gitView.stashes.toast.createFailed"))}finally{b(null)}}},Z=async(R,E)=>{if(!(!n||P)&&!(E==="drop"&&!window.confirm(m("gitView.stashes.confirm.drop",{ref:R.ref})))){b(`${E}:${R.ref}`);try{E==="apply"&&await Ia(n,{ref:R.ref}),E==="pop"&&await Pa(n,{ref:R.ref}),E==="drop"&&await Fa(n,{ref:R.ref});const a=E==="apply"?"gitView.stashes.toast.applySuccess":E==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";p.success(m(a)),await F({affectsIndex:E!=="drop"})}catch(a){const Y=E==="apply"?"gitView.stashes.toast.applyFailed":E==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";p.error(a instanceof Error?a.message:m(Y)),await F({affectsIndex:E!=="drop"})}finally{b(null)}}},O=P!==null;return t.jsx(ht,{open:o,onOpenChange:e,children:t.jsxs(mt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsxs(ft,{children:[t.jsxs(gt,{className:"flex items-center gap-2",children:[t.jsx(_,{name:"archive-stack",className:"size-4 text-muted-foreground"}),m("gitView.stashes.title")]}),t.jsx(jt,{children:m("gitView.stashes.description")})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(Er,{value:C,onChange:R=>z(R.target.value),placeholder:m("gitView.stashes.messagePlaceholder"),disabled:O||!h,className:"flex-1"}),t.jsxs(K,{onClick:G,disabled:!h||O||!n,children:[P==="create"?t.jsx(_,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(_,{name:"inbox-archive",className:"size-4"}),m("gitView.stashes.actions.stashCurrentWithCount",{count:g})]})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:m("gitView.stashes.includeUntrackedHint")})]}),t.jsx("div",{className:"-mx-5 border-t border-border/60"}),t.jsxs("div",{className:"relative",children:[t.jsx(_,{name:"search",className:"absolute inset-s-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),t.jsx(Er,{value:k,onChange:R=>T(R.target.value),placeholder:m("gitView.stashes.searchPlaceholder"),className:"ps-8"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:M?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(_,{name:"loader-4",className:"size-5 animate-spin"})}):V.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:m(k?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):V.map((R,E)=>t.jsxs("div",{className:"group -mx-2 flex items-center gap-2 rounded-md px-2 py-1.5 transition-colors hover:bg-interactive-hover",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"typography-ui-label truncate text-foreground",children:R.message||m("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-micro truncate text-muted-foreground",children:[t.jsxs(us,{children:[t.jsx(ds,{asChild:!0,children:t.jsx("span",{children:E===0&&!k.trim()?m("gitView.stashes.latestLabel"):m("gitView.stashes.itemNumber",{number:E+1})})}),t.jsx(hs,{sideOffset:6,children:R.ref})]})," · ",R.relativeTime," · ",typeof H[R.ref]=="number"?m("gitView.stashes.fileCount",{count:H[R.ref]}):m("gitView.stashes.fileCountLoading")]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[t.jsx(Ks,{label:m("gitView.stashes.actions.apply"),loading:P===`apply:${R.ref}`,onClick:()=>Z(R,"apply"),disabled:O,children:t.jsx(_,{name:"inbox-unarchive",className:"size-3.5"})}),t.jsx(Ks,{label:m("gitView.stashes.actions.pop"),loading:P===`pop:${R.ref}`,onClick:()=>Z(R,"pop"),disabled:O,children:t.jsx(_,{name:"inbox-unarchive-fill",className:"size-3.5"})}),t.jsx(Ks,{label:m("gitView.stashes.actions.drop"),loading:P===`drop:${R.ref}`,onClick:()=>Z(R,"drop"),disabled:O,destructive:!0,children:t.jsx(_,{name:"delete-bin",className:"size-3.5"})})]})]},R.ref))})]})})},Ks=o=>{const e=Ht.c(17),{label:n,loading:h,disabled:x,destructive:g,onClick:y,children:m}=o,f=h||void 0,w=g?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let M;e[0]!==w?(M=fe("flex size-6 items-center justify-center rounded-md transition-colors hover:bg-interactive-hover disabled:opacity-50",w),e[0]=w,e[1]=M):M=e[1];let A;e[2]!==m||e[3]!==h?(A=h?t.jsx(_,{name:"loader-4",className:"size-3.5 animate-spin"}):m,e[2]=m,e[3]=h,e[4]=A):A=e[4];let k;e[5]!==x||e[6]!==n||e[7]!==y||e[8]!==f||e[9]!==M||e[10]!==A?(k=t.jsx(ds,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":n,"aria-busy":f,className:M,onClick:y,disabled:x,children:A})}),e[5]=x,e[6]=n,e[7]=y,e[8]=f,e[9]=M,e[10]=A,e[11]=k):k=e[11];let T;e[12]!==n?(T=t.jsx(hs,{sideOffset:6,children:n}),e[12]=n,e[13]=T):T=e[13];let C;return e[14]!==k||e[15]!==T?(C=t.jsxs(us,{children:[k,T]}),e[14]=k,e[15]=T,e[16]=C):C=e[16],C},go=o=>{const e=Ht.c(16),{onOpenStashes:n}=o,{t:h}=it();let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx(_,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=x):x=e[0];let g;e[1]!==h?(g=h("gitView.empty.cleanTitle"),e[1]=h,e[2]=g):g=e[2];let y;e[3]!==g?(y=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:g}),e[3]=g,e[4]=y):y=e[4];let m;e[5]!==h?(m=h("gitView.empty.cleanDescription"),e[5]=h,e[6]=m):m=e[6];let f;e[7]!==m?(f=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:m}),e[7]=m,e[8]=f):f=e[8];let w;e[9]!==n||e[10]!==h?(w=n?t.jsxs(K,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[t.jsx(_,{name:"archive-stack",className:"size-4"}),h("gitView.stashes.title")]}):null,e[9]=n,e[10]=h,e[11]=w):w=e[11];let M;return e[12]!==y||e[13]!==f||e[14]!==w?(M=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[x,y,f,w]}),e[12]=y,e[13]=f,e[14]=w,e[15]=M):M=e[15],M},nt=8,po=o=>{const e=Ht.c(18),{laned:n,totalLanes:h,isExpanded:x}=o,{lane:g,color:y,connectors:m}=n,w=Math.max(h,g+1)*nt+nt/2,M=i.useRef(null),A=i.useRef(null);let k;e[0]!==y||e[1]!==m||e[2]!==g||e[3]!==w?(k=()=>{const b=M.current,H=A.current;if(!b||!H)return;const S=b.offsetHeight;if(S===0)return;const D=window.devicePixelRatio||1;H.width=w*D,H.height=S*D;const V=H.getContext("2d");if(!V)return;V.scale(D,D),V.clearRect(0,0,w,S);const F=S/2,G=g*nt+nt/2,Z=getComputedStyle(H),O=Z.getPropertyValue("--surface-muted-foreground").trim()||Z.color,R=Y=>{if(!Y.startsWith("var("))return Y;const q=Y.slice(4,-1).trim();return Z.getPropertyValue(q).trim()||O},E=[...m].sort(yo);for(const Y of E){const q=Y.fromLane*nt+nt/2,J=Y.toLane*nt+nt/2,j=Y.type==="passing"?.72:Y.type==="branch-out"||Y.type==="merge-in"?.95:1;V.beginPath(),V.strokeStyle=R(Y.color),V.globalAlpha=j,V.lineWidth=1.25,V.lineCap="round";e:switch(Y.type){case"passing":case"commit-lane":{V.moveTo(q,0),V.lineTo(q,S);break e}case"top-stub":{V.moveTo(q,0),V.lineTo(q,F);break e}case"bottom-stub":{V.moveTo(q,F),V.lineTo(q,S);break e}case"branch-out":{const U=(F+S)/2;V.moveTo(G,F),V.bezierCurveTo(G,U,J,U,J,S);break e}case"merge-in":{const U=F/2;V.moveTo(q,0),V.bezierCurveTo(q,U,G,U,G,F);break e}default:continue}V.stroke(),V.globalAlpha=1}const a=Z.getPropertyValue("--background").trim()||Z.getPropertyValue("--surface-background").trim();V.beginPath(),V.arc(G,F,4,0,Math.PI*2),V.fillStyle=R(y),V.fill(),V.beginPath(),V.arc(G,F,5,0,Math.PI*2),V.strokeStyle=a||O,V.lineWidth=2,V.stroke()},e[0]=y,e[1]=m,e[2]=g,e[3]=w,e[4]=k):k=e[4];let T;e[5]!==y||e[6]!==m||e[7]!==x||e[8]!==g||e[9]!==n||e[10]!==h||e[11]!==w?(T=[n,g,y,m,h,x,w],e[5]=y,e[6]=m,e[7]=x,e[8]=g,e[9]=n,e[10]=h,e[11]=w,e[12]=T):T=e[12],i.useLayoutEffect(k,T);let C;e[13]!==w?(C={width:w,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=w,e[14]=C):C=e[14];let z;e[15]===Symbol.for("react.memo_cache_sentinel")?(z=t.jsx("canvas",{ref:A,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=z):z=e[15];let P;return e[16]!==C?(P=t.jsx("div",{ref:M,style:C,children:z}),e[16]=C,e[17]=P):P=e[17],P};function xo(o){return o==="branch-out"||o==="merge-in"}function yo(o,e){const n=xo;return(n(o.type)?1:0)-(n(e.type)?1:0)}const Jr=15e3,Yr=500,Qr=12,Xr=8*1024*1024,vt="h-6 text-foreground/80 hover:bg-transparent hover:text-foreground",Zr=o=>typeof o=="string"?0:(o.original?.length??0)+(o.modified?.length??0),en=o=>{if(o.size<=Qr){let x=0;for(const g of o.values())x+=Zr(g);if(x<=Xr)return o}const e=Array.from(o.entries()).reverse(),n=new Map;let h=0;for(const[x,g]of e){if(n.size>=Qr)continue;const y=Zr(g);h+y>Xr&&n.size>0||(n.set(x,g),h+=y)}return new Map(Array.from(n.entries()).reverse())};function tn(o,e){const n=new Date(o);return Number.isNaN(n.getTime())?o:Oa(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function wo(o){switch(o){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 bo(o){return o?o.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const vo=i.memo(({entry:o,mode:e="history",laned:n,totalLanes:h,isExpanded:x,onToggle:g,files:y,isLoadingFiles:m,onCopyHash:f,directory:w,onConflict:M,onActionSuccess:A})=>{const{t:k}=it(),T=zt(c=>c.timeFormatPreference),C=e==="graph",[z,P]=i.useState(null),[b,H]=i.useState(!1),[S,D]=i.useState(""),[V,F]=i.useState(null),[G,Z]=i.useState(new Set),[O,R]=i.useState(new Map),[E,a]=i.useState(new Set),Y=async()=>{if(w){P("checkout");try{await _a(w,o.hash),p.success(k("gitView.history.actions.detachedHead")),A?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},q=async()=>{if(!(!w||!S.trim())){P("createBranch");try{await Aa(w,S.trim(),o.hash),H(!1),D(""),A?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},J=async()=>{if(w){P("cherryPick");try{const c=await Ga(w,o.hash);c.conflict?M?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"cherry-pick"}):A?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},j=async()=>{if(w){P("revert");try{const c=await za(w,o.hash);c.conflict?M?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"revert"}):A?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},U=async(c,I=!1)=>{if(!(!w||z!==null)){P("reset");try{await Ta(w,o.hash,c,I),A?.()}catch(L){p.error(String(L.message))}finally{P(null)}}},te=async()=>{if(!V)return;const c=V;switch(F(null),c){case"checkout":return Y();case"cherryPick":return J();case"revert":return j();case"merge":return oe();case"rebase":return xe();case"resetSoft":return U("soft");case"resetMixed":return U("mixed");case"resetHard":return U("hard",!0)}},oe=async()=>{if(w){P("merge");try{const c=await La(w,{branch:o.hash});c.conflict?M?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"merge"}):A?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},xe=async()=>{if(w){P("rebase");try{const c=await Ea(w,{onto:o.hash});c.conflict?M?.({conflict:!0,conflictFiles:c.conflictFiles,operation:"rebase"}):A?.()}catch(c){p.error(String(c.message))}finally{P(null)}}},me=i.useCallback(async c=>{const I=c.path;if(!w){R(L=>new Map(L).set(I,"error"));return}R(L=>en(new Map(L).set(I,"loading")));try{const L=Da(w,o.hash,c.path,!1),re=new Promise((ce,ee)=>{setTimeout(()=>ee(new Error(`Timed out after ${Jr}ms`)),Jr)}),de=await Promise.race([L,re]);R(ce=>en(new Map(ce).set(I,de)))}catch{R(L=>new Map(L).set(I,"error"))}},[w,o.hash]),d=i.useCallback(async c=>{const I=c.path;if(c.changeType==="R"||c.isBinary){Z(ce=>{const ee=new Set(ce);return ee.has(I)?ee.delete(I):ee.add(I),ee});return}const L=O.get(I);if(G.has(I)&&L&&L!=="error"){Z(ce=>{const ee=new Set(ce);return ee.delete(I),ee});return}Z(ce=>{const ee=new Set(ce);return ee.add(I),ee}),!(L&&L!=="error"||c.insertions+c.deletions>Yr&&!E.has(I))&&await me(c)},[O,E,me,G]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:g,className:fe("w-full flex items-start gap-3 px-3 py-2 text-start transition-colors",C?"hover:bg-[var(--interactive-hover)]/40":x?"oc-tile-inset":"oc-tile-hover"),children:[C&&n&&h!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(po,{laned:n,totalLanes:h,isExpanded:x})}):t.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 flex-1",children:[C?(()=>{const c=bo(o.refs);return c.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:c.map(I=>t.jsx("span",{className:fe("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",I.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":I.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:I.label},I.label))}):null})():null,t.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:o.message}),t.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[t.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[t.jsx("span",{className:"truncate min-w-[3ch]",title:o.author_name,children:o.author_name}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("span",{className:"truncate min-w-0",title:tn(o.date,T),children:tn(o.date,T)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:o.hash.slice(0,8)}),t.jsxs(us,{children:[t.jsx(ds,{asChild:!0,children:t.jsx(K,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:c=>{c.stopPropagation(),f(o.hash)},children:t.jsx(_,{name:"file-copy",className:"size-3"})})}),t.jsx(hs,{sideOffset:8,children:k("gitView.history.copySha")})]})]})]})]}),x&&t.jsxs("div",{className:"oc-tile-inset px-3 pb-2 ps-8",children:[C&&V?t.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:k(`gitView.history.actions.${V}Confirm`)}),t.jsxs(K,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:z!==null,onClick:c=>{c.stopPropagation(),te()},children:[z!==null?t.jsx(_,{name:"loader-4",className:"size-3 animate-spin me-1"}):null,k("gitView.history.actions.confirmButton")]}),t.jsx(K,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:z!==null,onClick:c=>{c.stopPropagation(),F(null)},children:k("gitView.history.actions.cancelButton")})]}):C?t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[t.jsx(K,{variant:"outline",size:"xs",className:"h-6",disabled:z!==null,onClick:c=>{c.stopPropagation(),F("checkout")},children:k("gitView.history.actions.checkout")}),b?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:S,onChange:c=>D(c.target.value),onKeyDown:c=>{c.key==="Enter"&&q(),c.key==="Escape"&&(H(!1),D(""))},placeholder:k("gitView.history.actions.createBranchPlaceholder"),className:"oc-raised oc-field h-6 text-xs px-2 rounded bg-surface-elevated outline-none min-w-0 w-32"}),t.jsxs(K,{variant:"outline",size:"xs",className:"h-6",disabled:!S.trim()||z!==null,onClick:c=>{c.stopPropagation(),q()},children:[z==="createBranch"?t.jsx(_,{name:"loader-4",className:"size-3 animate-spin me-1"}):null,k("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(K,{variant:"ghost",size:"xs",className:vt,onClick:c=>{c.stopPropagation(),H(!0)},children:k("gitView.history.actions.createBranch")}),t.jsx(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>{c.stopPropagation(),F("cherryPick")},children:k("gitView.history.actions.cherryPick")}),t.jsx(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>{c.stopPropagation(),F("revert")},children:k("gitView.history.actions.revert")}),t.jsxs(Js,{children:[t.jsx(Ys,{asChild:!0,children:t.jsxs(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>c.stopPropagation(),children:[z==="reset"?t.jsx(_,{name:"loader-4",className:"size-3 animate-spin me-1"}):null,k("gitView.history.actions.reset")]})}),t.jsx(Qs,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(c=>t.jsx(Ba,{disabled:z!==null,onSelect:I=>{I.stopPropagation(),F(`reset${c.charAt(0).toUpperCase()+c.slice(1)}`)},children:k(`gitView.history.actions.reset${c.charAt(0).toUpperCase()+c.slice(1)}`)},c))})]}),t.jsx(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>{c.stopPropagation(),F("merge")},children:k("gitView.history.actions.merge")}),t.jsx(K,{variant:"ghost",size:"xs",className:vt,disabled:z!==null,onClick:c=>{c.stopPropagation(),F("rebase")},children:k("gitView.history.actions.rebase")})]}):null,m?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(_,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:k("gitView.history.loadingFiles")})]}):y.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:k("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:y.map(c=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>d(c),className:"oc-tile-hover w-full flex items-center gap-2 typography-micro text-start cursor-pointer rounded px-1",children:[t.jsx("span",{className:fe("font-semibold w-3 text-center shrink-0",wo(c.changeType)),children:c.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:c.path,children:c.path}),!c.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",c.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",c.deletions]})]}),c.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:k("gitView.history.binary")}),t.jsx(_,{name:G.has(c.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),G.has(c.path)&&t.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:c.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.renamedNoDiff")}):c.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.binaryNoDiff")}):(()=>{const I=c.insertions+c.deletions;if(!E.has(c.path)&&I>Yr)return t.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:k("gitView.history.largeDiffTitle",{count:I})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:k("gitView.history.largeDiffDescription")}),t.jsx(K,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{a(re=>new Set(re).add(c.path)),me(c)},children:k("gitView.history.renderDiffAnyway")})]});const L=O.get(c.path);return L==="loading"||L===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.loadingDiff")}):L==="error"?t.jsx("button",{type:"button",onClick:()=>d(c),className:"w-full text-start px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:k("gitView.history.diffError")}):t.jsx(so,{original:L.original,modified:L.modified,language:Ma(c.path)||"",fileName:c.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},c.path))})]})]})}),sn=["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 is(o){return sn[o%sn.length]}function jo(o){if(o.length===0)return[];const e=[],n=[];for(let h=0;h<o.length;h++){const x=o[h],g=[];for(let C=0;C<e.length;C++)e[C]===x.hash&&g.push(C);let y=g.length>0?g[0]:-1;if(y===-1){const C=e.indexOf(null);C!==-1?y=C:(y=e.length,e.push(null))}const m=g.slice(1),f=is(y),w=e[y]===x.hash,M=x.parents.length>0;M?e[y]=x.parents[0]:e[y]=null;const A=[],k=new Set;for(let C=1;C<x.parents.length;C++){const z=x.parents[C],P=e.indexOf(z);if(P!==-1)A.push(P);else{const b=e.indexOf(null);if(b!==-1)e[b]=z,A.push(b),k.add(b);else{const H=e.length;e.push(z),A.push(H),k.add(H)}}}const T=[];w&&M?T.push({fromLane:y,toLane:y,color:f,type:"commit-lane"}):w&&!M?T.push({fromLane:y,toLane:y,color:f,type:"top-stub"}):!w&&M&&T.push({fromLane:y,toLane:y,color:f,type:"bottom-stub"});for(const C of m)T.push({fromLane:C,toLane:y,color:is(C),type:"merge-in"}),e[C]=null;for(const C of A)T.push({fromLane:y,toLane:C,color:is(C),type:"branch-out"});for(let C=0;C<e.length;C++)e[C]!==null&&C!==y&&(k.has(C)||T.push({fromLane:C,toLane:C,color:is(C),type:"passing"}));n.push({commit:x,lane:y,color:f,connectors:T})}return n}const Co=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],So=o=>{const e=Ht.c(84),{mode:n,log:h,isLogLoading:x,logMaxCount:g,onLogMaxCountChange:y,expandedCommitHashes:m,onToggleCommit:f,commitFilesMap:w,loadingCommitHashes:M,onCopyHash:A,directory:k,showHeader:T,contentMaxHeightClassName:C,branchDivider:z,onConflict:P,onActionSuccess:b}=o,H=n===void 0?"history":n,S=T===void 0?!0:T,D=C===void 0?"max-h-[50vh]":C,V=z===void 0?null:z,{t:F}=it(),[G,Z]=i.useState(!0),O=H==="graph";let R;e[0]!==O||e[1]!==h?(R=O&&h?jo(h.all):[],e[0]=O,e[1]=h,e[2]=R):R=e[2];const E=R;let a;e[3]!==E?(a=Math.max(1,...E.map(No)),e[3]=E,e[4]=a):a=e[4];const Y=a;let q;e[5]!==E?(q=new Map(E.map(ko)),e[5]=E,e[6]=q):q=e[6];const J=q;if(!h)return null;const j=V!==null&&V.insertBeforeIndex>0&&V.insertBeforeIndex<h.all.length,U=V!==null&&V.insertBeforeIndex===h.all.length,te=j||U;let oe;e[7]!==V||e[8]!==j||e[9]!==U||e[10]!==h.all?(oe=j?h.all.slice(0,V.insertBeforeIndex):U?h.all:[],e[7]=V,e[8]=j,e[9]=U,e[10]=h.all,e[11]=oe):oe=e[11];const xe=oe;let me;if(e[12]!==V||e[13]!==w||e[14]!==D||e[15]!==k||e[16]!==m||e[17]!==j||e[18]!==te||e[19]!==O||e[20]!==x||e[21]!==J||e[22]!==M||e[23]!==h.all||e[24]!==g||e[25]!==Y||e[26]!==H||e[27]!==b||e[28]!==P||e[29]!==A||e[30]!==y||e[31]!==f||e[32]!==F||e[33]!==xe){const X=j?h.all.slice(V.insertBeforeIndex):[];let ae;e[35]!==V?.direction?(ae=V?.direction==="down"?t.jsx(_,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(_,{name:"arrow-up",className:"size-3.5"}),e[35]=V?.direction,e[36]=ae):ae=e[36];const De=ae;let ve;e[37]!==w||e[38]!==k||e[39]!==m||e[40]!==O||e[41]!==J||e[42]!==M||e[43]!==Y||e[44]!==H||e[45]!==b||e[46]!==P||e[47]!==A||e[48]!==f?(ve=St=>t.jsx("ul",{className:"divide-y divide-border/60",children:St.map(le=>t.jsx(vo,{entry:le,mode:H,laned:O?J.get(le.hash):void 0,totalLanes:O?Y:void 0,isExpanded:m.has(le.hash),onToggle:()=>f(le.hash),files:w.get(le.hash)??[],isLoadingFiles:M.has(le.hash),onCopyHash:A,directory:k,onConflict:P,onActionSuccess:b},le.hash))}),e[37]=w,e[38]=k,e[39]=m,e[40]=O,e[41]=J,e[42]=M,e[43]=Y,e[44]=H,e[45]=b,e[46]=P,e[47]=A,e[48]=f,e[49]=ve):ve=e[49];const ke=ve;let je;e[50]!==x||e[51]!==h.all.length||e[52]!==g||e[53]!==y||e[54]!==F?(je=h.all.length>=g?t.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:t.jsx(K,{type:"button",variant:"ghost",size:"xs",onClick:()=>y(g+25),disabled:x,className:"px-3 text-muted-foreground hover:text-foreground",children:x?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(_,{name:"loader-4",className:"size-3 animate-spin"}),F("gitView.history.loadingMore")]}):F("gitView.history.loadMore")})}):null,e[50]=x,e[51]=h.all.length,e[52]=g,e[53]=y,e[54]=F,e[55]=je):je=e[55];const Be=je;me=t.jsx(ln,{outerClassName:`min-h-0 ${D}`,className:"h-full w-full",children:h.all.length===0?t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:F("gitView.history.noCommits")})}):te&&V?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[xe.length>0?t.jsx("div",{className:"rounded-xl oc-tile overflow-hidden",children:ke(xe)}):null,t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[t.jsx("span",{className:"h-px flex-1 bg-border/60"}),t.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[t.jsx("span",{className:"truncate",title:V.branchName,children:V.branchName}),De]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),X.length>0?t.jsx("div",{className:"rounded-xl oc-tile overflow-hidden",children:ke(X)}):null]}),Be]}):t.jsxs(t.Fragment,{children:[ke(h.all),Be]})}),e[12]=V,e[13]=w,e[14]=D,e[15]=k,e[16]=m,e[17]=j,e[18]=te,e[19]=O,e[20]=x,e[21]=J,e[22]=M,e[23]=h.all,e[24]=g,e[25]=Y,e[26]=H,e[27]=b,e[28]=P,e[29]=A,e[30]=y,e[31]=f,e[32]=F,e[33]=xe,e[34]=me}else me=e[34];const d=me;if(!S){if(te){let ae;return e[56]!==d?(ae=t.jsx("section",{className:"h-full min-h-0",children:d}),e[56]=d,e[57]=ae):ae=e[57],ae}let X;return e[58]!==d?(X=t.jsx("section",{className:"h-full min-h-0 rounded-xl oc-tile overflow-hidden",children:d}),e[58]=d,e[59]=X):X=e[59],X}let c;e[60]!==F?(c=F("gitView.history.title"),e[60]=F,e[61]=c):c=e[61];let I;e[62]!==c?(I=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:c}),e[62]=c,e[63]=I):I=e[63];let L;e[64]!==x||e[65]!==G||e[66]!==g||e[67]!==y||e[68]!==F?(L=G&&t.jsx("div",{onClick:Vo,onPointerDown:Ro,children:t.jsxs(Ha,{value:String(g),onValueChange:X=>y(Number(X)),disabled:x,children:[t.jsx($a,{className:"w-auto",disabled:x,children:t.jsx(Wa,{placeholder:F("gitView.history.commitsPlaceholder")})}),t.jsx(Ua,{children:Co.map(X=>t.jsx(Ka,{value:String(X.value),children:F(X.labelKey)},X.value))})]})}),e[64]=x,e[65]=G,e[66]=g,e[67]=y,e[68]=F,e[69]=L):L=e[69];let re;e[70]!==G?(re=G?t.jsx(_,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(_,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=G,e[71]=re):re=e[71];let de;e[72]!==L||e[73]!==re?(de=t.jsxs("div",{className:"flex items-center gap-2",children:[L,re]}),e[72]=L,e[73]=re,e[74]=de):de=e[74];let ce;e[75]!==I||e[76]!==de?(ce=t.jsxs(Fi,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[I,de]}),e[75]=I,e[76]=de,e[77]=ce):ce=e[77];let ee;e[78]!==d?(ee=t.jsx(Di,{children:d}),e[78]=d,e[79]=ee):ee=e[79];let ne;return e[80]!==G||e[81]!==ce||e[82]!==ee?(ne=t.jsxs(Bi,{open:G,onOpenChange:Z,className:"rounded-xl oc-tile overflow-hidden",children:[ce,ee]}),e[80]=G,e[81]=ce,e[82]=ee,e[83]=ne):ne=e[83],ne};function No(o){return o.lane+1}function ko(o){return[o.commit.hash,o]}function Vo(o){return o.stopPropagation()}function Ro(o){return o.stopPropagation()}const Io=({open:o,onOpenChange:e,operation:n,targetBranch:h,onConfirm:x})=>{const{t:g}=it(),[y,m]=i.useState(!0),[f,w]=i.useState(!1),M=g(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),A=async()=>{w(!0);try{await x(y),e(!1)}catch(T){const C=T instanceof Error?T.message:`Failed to ${n}`;p.error(C)}finally{w(!1)}},k=()=>{f||e(!1)};return t.jsx(ht,{open:o,onOpenChange:f?void 0:e,children:t.jsxs(mt,{className:"max-w-md",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(_,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(gt,{children:g("gitView.stash.title")})]}),t.jsx(jt,{children:g("gitView.stash.description",{operation:n})})]}),t.jsxs("div",{className:"py-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:g("gitView.stash.thisWill")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[t.jsx("li",{children:g("gitView.stash.stepStash")}),t.jsxs("li",{children:[g(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",g(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:h})]}),y&&t.jsx("li",{children:g("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(qa,{checked:y,onChange:m,disabled:f,ariaLabel:g("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!f&&m(!y),children:g("gitView.stash.restoreAfterOperation",{operation:n})})]}),t.jsxs(qs,{className:"gap-2",children:[t.jsx(K,{variant:"ghost",size:"sm",onClick:k,disabled:f,children:g("gitView.common.cancel")}),t.jsx(K,{variant:"default",size:"sm",onClick:A,disabled:f,className:"gap-1.5",children:f?t.jsxs(t.Fragment,{children:[t.jsx(_,{name:"loader-4",className:"size-4 animate-spin"}),g("gitView.common.processing")]}):g("gitView.stash.confirmButton",{operation:M})})]})]})})},Po=o=>{const e=Ht.c(100),{currentBranch:n,localBranches:h,remoteBranches:x,onMerge:g,onRebase:y,disabled:m,isOperating:f,operationLogs:w,onOperationComplete:M,mode:A,defaultTargetBranch:k}=o,T=m===void 0?!1:m,C=f===void 0?!1:f,z=w===void 0?[]:w,P=A===void 0?"dialog":A,{t:b}=it(),[H,S]=i.useState(!1),[D,V]=i.useState("merge"),[F,G]=i.useState(null),[Z,O]=i.useState(!1),[R,E]=i.useState(""),a=i.useRef(null),Y=i.useRef(null),q=T||C,J=n||b("gitView.branch.currentBranchFallback"),j=z.length>0&&z.every(Fo),U=z.some(Do);let te;e[0]===Symbol.for("react.memo_cache_sentinel")?(te=()=>{Y.current&&(Y.current.scrollTop=Y.current.scrollHeight)},e[0]=te):te=e[0],i.useEffect(te,[z]);let oe;if(e[1]!==R||e[2]!==n||e[3]!==h){let Q;e[5]!==n?(Q=ye=>ye!==n,e[5]=n,e[6]=Q):Q=e[6];const pe=h.filter(Q);oe=_t(pe,R,Bo),e[1]=R,e[2]=n,e[3]=h,e[4]=oe}else oe=e[4];const xe=oe;let me;e[7]!==R||e[8]!==x?(me=_t(x,R,Mo),e[7]=R,e[8]=x,e[9]=me):me=e[9];const d=me;let c;e[10]!==k||e[11]!==h||e[12]!==x?(c=()=>{if(!k)return null;const Q=x.find(pe=>pe.label===k);return Q||(h.includes(k)?{kind:"local",branch:k,label:k}:null)},e[10]=k,e[11]=h,e[12]=x,e[13]=c):c=e[13];const I=c;let L;e[14]!==I||e[15]!==S?(L=()=>{S(!0),G(I()),V("merge"),E("")},e[14]=I,e[15]=S,e[16]=L):L=e[16];const re=L;let de;e[17]===Symbol.for("react.memo_cache_sentinel")?(de=Q=>{G(Q),O(!1),E("")},e[17]=de):de=e[17];const ce=de;let ee;e[18]!==g||e[19]!==y||e[20]!==D||e[21]!==F?(ee=()=>{F&&(D==="merge"?g(F):y(F))},e[18]=g,e[19]=y,e[20]=D,e[21]=F,e[22]=ee):ee=e[22];const ne=ee;let X;e[23]!==C||e[24]!==S?(X=()=>{C||(G(null),V("merge"),E(""),S(!1))},e[23]=C,e[24]=S,e[25]=X):X=e[25];const ae=X,De=()=>{C&&!j||(j&&M?.(),G(null),V("merge"),E(""),S(!1))};let ve,ke;e[26]!==Z?(ve=()=>{Z||E("")},ke=[Z],e[26]=Z,e[27]=ve,e[28]=ke):(ve=e[27],ke=e[28]),i.useEffect(ve,ke);let je,Be;e[29]!==P||e[30]!==I||e[31]!==F?(je=()=>{P==="dialog"||F||G(I())},Be=[P,I,F],e[29]=P,e[30]=I,e[31]=F,e[32]=je,e[33]=Be):(je=e[32],Be=e[33]),i.useEffect(je,Be);const Le=C?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:Y,className:"rounded-lg oc-tile p-3 max-h-48 overflow-y-auto",children:t.jsx("div",{className:"space-y-2",children:z.map(Oo)})}),j?P==="dialog"?t.jsx(qs,{children:t.jsx(K,{variant:"default",size:"sm",onClick:De,children:b(U?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(K,{variant:"default",size:"sm",onClick:De,children:b(U?"gitView.common.close":"gitView.common.done")})}):null]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:b("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>V("merge"),className:fe("flex flex-col items-start gap-1 rounded-lg p-3 text-start",D==="merge"?"bg-interactive-selection text-interactive-selection-foreground":"oc-tile oc-tile-hover"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(_,{name:"git-merge",className:fe("size-4",D==="merge"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:fe("typography-ui-label",D==="merge"?"text-foreground":"text-muted-foreground"),children:b("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:b("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>V("rebase"),className:fe("flex flex-col items-start gap-1 rounded-lg p-3 text-start",D==="rebase"?"bg-interactive-selection text-interactive-selection-foreground":"oc-tile oc-tile-hover"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(_,{name:"git-branch",className:fe("size-4",D==="rebase"?"text-inherit":"text-muted-foreground")}),t.jsx("span",{className:fe("typography-ui-label",D==="rebase"?"text-foreground":"text-muted-foreground"),children:b("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:b("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:D==="merge"?b("gitView.branch.branchToMergeInto",{branch:J}):b("gitView.branch.branchToRebaseOnto")}),t.jsxs(Js,{open:Z,onOpenChange:O,modal:!1,children:[t.jsx(Ys,{asChild:!0,children:t.jsxs("button",{type:"button",className:fe(on({size:"default"}),"w-full"),children:[t.jsx("span",{className:fe("truncate",!F&&"text-muted-foreground"),children:F?.label||b("gitView.branch.selectBranch")}),t.jsx(_,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Qs,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:t.jsxs(Xs,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Zs,{ref:a,placeholder:b("gitView.branch.searchPlaceholder"),value:R,onValueChange:E,onKeyDown:Ao}),t.jsxs(er,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(tr,{children:b("gitView.branch.empty")}),xe.length>0&&t.jsx(os,{heading:b("gitView.branch.localBranches"),children:xe.map(Q=>t.jsx(ls,{onSelect:()=>ce({kind:"local",branch:Q,label:Q}),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q})},`local-${Q}`))}),xe.length>0&&d.length>0?t.jsx(Ja,{}):null,d.length>0&&t.jsx(os,{heading:b("gitView.branch.remoteBranches"),children:d.map(Q=>t.jsx(ls,{onSelect:()=>ce(Q),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q.label})},`remote-${Q.label}`))})]})]})})]})]}),F?t.jsx("div",{className:"rounded-lg oc-tile p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:D==="merge"?t.jsxs(t.Fragment,{children:[b("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:F.label})," ",b("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:J})]}):t.jsxs(t.Fragment,{children:[b("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:J})," ",b("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:F.label})]})})}):null,P==="dialog"?t.jsxs(qs,{className:"gap-2 pt-1",children:[t.jsx(K,{variant:"ghost",size:"sm",onClick:ae,children:b("gitView.common.cancel")}),t.jsx(K,{variant:"default",size:"sm",onClick:ne,disabled:!F,className:"gap-1.5",children:D==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(_,{name:"git-merge",className:"size-4"}),b("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(_,{name:"git-branch",className:"size-4"}),b("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(K,{variant:"destructive",size:"sm",onClick:ae,disabled:q,children:b("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(K,{variant:"default",size:"sm",onClick:ne,disabled:q||!F,children:b(D==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(P==="bare")return Le;if(P==="inline"){let Q;e[34]!==b?(Q=b("gitView.branch.updateTitle"),e[34]=b,e[35]=Q):Q=e[35];let pe;e[36]!==Q?(pe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:Q}),e[36]=Q,e[37]=pe):pe=e[37];let ye;e[38]!==b?(ye=b("gitView.branch.updateDescriptionPrefix"),e[38]=b,e[39]=ye):ye=e[39];let $e;e[40]!==J?($e=t.jsx("span",{className:"font-mono text-foreground",children:J}),e[40]=J,e[41]=$e):$e=e[41];let Ce;e[42]!==ye||e[43]!==$e?(Ce=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[ye," ",$e,"."]}),e[42]=ye,e[43]=$e,e[44]=Ce):Ce=e[44];let We;e[45]!==pe||e[46]!==Ce?(We=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[pe,Ce]})}),e[45]=pe,e[46]=Ce,e[47]=We):We=e[47];let Se;e[48]!==Le?(Se=t.jsx("div",{className:"pt-3",children:Le}),e[48]=Le,e[49]=Se):Se=e[49];let Re;return e[50]!==We||e[51]!==Se?(Re=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[We,Se]}),e[50]=We,e[51]=Se,e[52]=Re):Re=e[52],Re}let qe;e[53]!==C?(qe=C?t.jsx(cs,{className:"size-4"}):t.jsx(_,{name:"git-merge",className:"size-4"}),e[53]=C,e[54]=qe):qe=e[54];let ze;e[55]!==b?(ze=b("gitView.branch.mergeRebase"),e[55]=b,e[56]=ze):ze=e[56];let Ge;e[57]!==ze?(Ge=t.jsx("span",{children:ze}),e[57]=ze,e[58]=Ge):Ge=e[58];let Je;e[59]!==re||e[60]!==q||e[61]!==qe||e[62]!==Ge?(Je=t.jsx(ds,{asChild:!0,children:t.jsxs(K,{variant:"outline",size:"sm",className:"gap-1.5",onClick:re,disabled:q,children:[qe,Ge]})}),e[59]=re,e[60]=q,e[61]=qe,e[62]=Ge,e[63]=Je):Je=e[63];let Ve;e[64]!==b?(Ve=b("gitView.branch.mergeRebaseTooltip"),e[64]=b,e[65]=Ve):Ve=e[65];let Me;e[66]!==Ve?(Me=t.jsx(hs,{sideOffset:8,children:Ve}),e[66]=Ve,e[67]=Me):Me=e[67];let $;e[68]!==Je||e[69]!==Me?($=t.jsxs(us,{children:[Je,Me]}),e[68]=Je,e[69]=Me,e[70]=$):$=e[70];let Ye;e[71]!==De||e[72]!==S?(Ye=Q=>{Q?S(!0):De()},e[71]=De,e[72]=S,e[73]=Ye):Ye=e[73];let _e;e[74]!==b?(_e=b("gitView.branch.updateTitle"),e[74]=b,e[75]=_e):_e=e[75];let Qe;e[76]!==_e?(Qe=t.jsx(gt,{children:_e}),e[76]=_e,e[77]=Qe):Qe=e[77];let Oe;e[78]!==U||e[79]!==C||e[80]!==D||e[81]!==j||e[82]!==b||e[83]!==J?(Oe=C?b(j?U?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":D==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[b("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:J}),"."]}),e[78]=U,e[79]=C,e[80]=D,e[81]=j,e[82]=b,e[83]=J,e[84]=Oe):Oe=e[84];let Xe;e[85]!==Oe?(Xe=t.jsx(jt,{children:Oe}),e[85]=Oe,e[86]=Xe):Xe=e[86];let Ae;e[87]!==Qe||e[88]!==Xe?(Ae=t.jsxs(ft,{children:[Qe,Xe]}),e[87]=Qe,e[88]=Xe,e[89]=Ae):Ae=e[89];let Ze;e[90]!==Le||e[91]!==Ae?(Ze=t.jsxs(mt,{className:"max-w-md",children:[Ae,Le]}),e[90]=Le,e[91]=Ae,e[92]=Ze):Ze=e[92];let He;e[93]!==H||e[94]!==Ye||e[95]!==Ze?(He=t.jsx(ht,{open:H,onOpenChange:Ye,children:Ze}),e[93]=H,e[94]=Ye,e[95]=Ze,e[96]=He):He=e[96];let ot;return e[97]!==$||e[98]!==He?(ot=t.jsxs(t.Fragment,{children:[$,He]}),e[97]=$,e[98]=He,e[99]=ot):ot=e[99],ot};function Fo(o){return o.status==="done"||o.status==="error"}function Do(o){return o.status==="error"}function Bo(o){return[o]}function Mo(o){return[o.label,o.branch,o.remote]}function Oo(o,e){return t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("div",{className:"mt-0.5 shrink-0",children:[o.status==="running"&&t.jsx(cs,{className:"size-3.5 text-primary"}),o.status==="done"&&t.jsx(_,{name:"check",className:"size-3.5 text-success"}),o.status==="error"&&t.jsx(_,{name:"close",className:"size-3.5 text-destructive"}),o.status==="pending"&&t.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),t.jsx("span",{className:fe("typography-micro",o.status==="error"&&"text-destructive",o.status==="done"&&"text-muted-foreground",o.status==="running"&&"text-foreground",o.status==="pending"&&"text-muted-foreground/60"),children:o.message})]},e)}function Ao(o){return o.stopPropagation()}const To=/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/i,Eo=(o,e)=>{const n=[...o].sort((h,x)=>x.length-h.length);return e.flatMap(h=>{const x=n.find(y=>h.startsWith(`${y}/`));if(!x)return[];const g=h.slice(x.length+1);return g?[{kind:"remote",branch:g,destinationRef:`refs/remotes/${x}/${g}`,label:h,remote:x,sourceRef:`refs/heads/${g}`}]:[]})},Lo=async({directory:o,git:e,runPlannedFetch:n,target:h})=>{if(h.kind==="local")return h.branch;await n(h);const g=(await e.getGitLog(o,{to:h.destinationRef,maxCount:1})).latest?.hash.trim();if(!g||!To.test(g))throw new be("invalid-terminal-state");return g},zo=({runMutation:o,onMutationComplete:e,onMutationError:n,onPathsComplete:h,scheduleFlush:x})=>{const g=[];let y=!1;return{enqueue:f=>{const w=g[g.length-1];if(w?.directory===f.directory&&w.direction===f.direction){f.paths.forEach(M=>w.paths.add(M));return}g.push(f)},flush:()=>{if(y)return;const f=g.shift();if(!f)return;y=!0;const w={directory:f.directory,direction:f.direction,paths:Array.from(f.paths),rollback:f.rollback};(async()=>{try{await o(w),e(w)}catch(M){n(w,M)}finally{h(w.paths),y=!1,g.length>0&&x()}})()},clear:()=>{g.length=0},size:()=>g.length,isRunning:()=>y}},Go=(o,e,n)=>Ya(o,e,h=>Ji(h)&&Qa(h,n)),_o=(o,e,n,h)=>Xa(o,e,n,x=>({id:"local-config",name:x.userName,...x,color:"info",icon:"user"}),h),Ho=(o,e,n,h)=>{if(e){const x=n.filter(g=>e.startsWith(`${g}/`)&&e.length>g.length+1).sort((g,y)=>y.length-g.length)[0];if(x)return{remoteName:x,destinationRef:`refs/heads/${e.slice(x.length+1)}`}}return h?{remoteName:h,destinationRef:`refs/heads/${o}`}:null},$o=15e3,Wo=40,Uo=20,Ko=2,rn={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},nn=(o,e)=>{const n=o.toLowerCase(),h=/^([a-z]+)(?:\(.*\))?!?:/,x=n.match(h);if(x){const m=x[1],f=rn[m];if(f)return e.find(w=>w.code===f)||null}const g=n.split(" ")[0],y=rn[g];return y&&e.find(m=>m.code===y)||null},qo=20,dt=new Map,Jo=(o,e)=>{if(dt.delete(o),dt.set(o,e),dt.size>qo){const n=dt.keys().next().value;n!==void 0&&dt.delete(n)}},an=o=>{const e=o.index?.trim();return!!(e&&e!=="?")},Yo=o=>{const e=o.working_dir?.trim(),n=o.index?.trim();return!!(e||n==="?")},hu=({isActive:o})=>{const{t:e}=it(),{git:n,sourceControl:h,runtime:x}=Za(),g=ei(),y=Mi(),m=ti(y,g)??void 0,f=Oi(),[w,M]=i.useState(null),[A,k]=i.useState(null),T=at(s=>s.currentSessionId),C=at(s=>s.newSessionDraft),z=at(s=>s.setDraftBootstrapPendingDirectory),P=at(s=>s.worktreeMetadata),b=at(s=>s.availableWorktrees),H=Ke(m),S=i.useMemo(()=>{if(H)return Lr(b,H)??Lr(P.values(),H)},[b,H,P]),D=i.useMemo(()=>{if(T)return P.get(T)??S;if(C?.open)return S},[T,S,C?.open,P]),{profiles:V,globalIdentity:F,defaultGitIdentityId:G,loadProfiles:Z,loadGlobalIdentity:O,loadDefaultGitIdentityId:R}=Ai(Ur(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),{rootIsGitRepo:E,gitDirectory:a,nestedRepos:Y,repositoryOptions:q}=si(m??null,{enabled:o,recheckOnOpen:!0}),J=ri(a??null),j=ni(a??null),U=Ti({directory:a,branch:j?.current,chooseContributor:f.choose}),te=Ei(a,n,h),oe=ai(s=>T?s.getAttachment(T):void 0),xe=oe?ii(oe):[],me=oe&&!oe.degraded&&!oe.legacy?oe.worktreeRoot??void 0:void 0,d=Ii(m,D,j?.current??void 0),c=oi(a??null),I=li(a??null),L=ci(a??null),re=ui(a??null),de=di(a??null),{setActiveDirectory:ce,ensureAll:ee,fetchStatus:ne,fetchBranches:X,fetchLog:ae,setLogMaxCount:De,fetchIdentity:ve,prefetchDiffs:ke,clearDiffCache:je,moveStatusPathsOptimistically:Be,restoreStatus:St,bumpIndexRevision:le,ensureNestedRepos:Le,selectNestedRepo:qe}=hi(Ur(s=>({setActiveDirectory:s.setActiveDirectory,ensureAll:s.ensureAll,fetchStatus:s.fetchStatus,fetchBranches:s.fetchBranches,fetchLog:s.fetchLog,setLogMaxCount:s.setLogMaxCount,fetchIdentity:s.fetchIdentity,prefetchDiffs:s.prefetchDiffs,clearDiffCache:s.clearDiffCache,moveStatusPathsOptimistically:s.moveStatusPathsOptimistically,restoreStatus:s.restoreStatus,bumpIndexRevision:s.bumpIndexRevision,ensureNestedRepos:s.ensureNestedRepos,selectNestedRepo:s.selectNestedRepo}))),ze=zt(s=>s.isMobile),Ge=zt(s=>s.openContextDiff),Je=zt(s=>s.openContextPanelTab),[Ve,Me]=i.useState([]),$=mi(a,h,o),[Ye,_e]=i.useState(!1),Qe=i.useMemo(()=>{const s=$.read;return!s?.binding||$.status!=="ready"||s.binding.state==="bound"?null:fi(s.binding)?e("gitView.identity.configChanged"):e("gitView.context.needsAttention")},[$.read,$.status,e]),Oe=$.read?.binding?.remotes[0]?.name??$.read?.repository.remotes.find(s=>s.name==="origin")?.name??$.read?.repository.remotes[0]?.name??"",Xe=i.useCallback(s=>{const r=$.read?.repository.remotes.find(l=>l.name===Oe);return r?Li(s,gi(r.fetch.displayUrl)):{applicable:!0}},[$.read,Oe]),Ae=zr(s=>s.entries),Ze=zr(s=>s.refreshIdentityAccounts),He=ns(s=>s.beginActiveContextsLoad),ot=ns(s=>s.commitActiveContexts),Q=ns(s=>s.releaseActiveContexts),pe=i.useId();i.useEffect(()=>{if(!o||!m)return;const s=$.scope.runtimeKey,r=He(s,m,pe);return ot(s,m,pe,r,$.contexts.filter(l=>Gr(Ae[_r(l)],l).connected)),()=>{Q(s,m,pe)}},[He,$.contexts,$.scope.runtimeKey,ot,m,o,Q,Ae,pe]);const ye=$.contexts[0]??null,$e=j?.current??null,Ce=ns(s=>!$e||!ye||!Gr(Ae[_r(ye)],ye).connected?null:pi(s.entries,ye,$e)),We=zt(s=>s.navigateToDiff),Se=i.useRef(null),Re=i.useRef(null),ms=i.useRef(null),Nt=i.useRef(!0);i.useEffect(()=>()=>{Nt.current=!1},[]);const $t=i.useCallback(()=>{Se.current!==null&&(window.clearTimeout(Se.current),Se.current=null)},[]),fs=i.useCallback(s=>{$t(),Se.current=window.setTimeout(()=>{Se.current=null,Ke(s)===Ke(a)&&ne(s,n,{silent:!0})},$o)},[$t,a,ne,n]);i.useEffect(()=>$t,[$t]);const sr=i.useCallback(()=>{Re.current!==null&&(window.clearTimeout(Re.current),Re.current=null)},[]),Wt=i.useCallback(()=>{Re.current===null&&(Re.current=window.setTimeout(()=>{Re.current=null,ms.current?.()},0))},[]),rr=i.useCallback(async(s,r,l)=>{if(r==="stage"){if(n.stageGitFiles){await n.stageGitFiles(s,l);return}await Promise.all(l.map(u=>n.stageGitFile(s,u)));return}if(n.unstageGitFiles){await n.unstageGitFiles(s,l);return}await Promise.all(l.map(u=>n.unstageGitFile(s,u)))},[n]),et=i.useMemo(()=>zo({runMutation:({directory:s,direction:r,paths:l})=>rr(s,r,l),onMutationComplete:({directory:s})=>{le(s),fs(s)},onMutationError:({directory:s,direction:r,rollback:l},u)=>{l?.(),le(s),fs(s);const N=e(r==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");p.error(u instanceof Error?u.message:N)},onPathsComplete:s=>{fr(r=>{const l=new Set(r);return s.forEach(u=>l.delete(u)),l})},scheduleFlush:Wt}),[le,rr,Wt,fs,e]);i.useEffect(()=>(ms.current=et.flush,()=>{ms.current=null}),[et]),i.useEffect(()=>()=>et.clear(),[et]),i.useEffect(()=>sr,[sr]),i.useEffect(()=>{if(!o)return;if(!m){M(null);return}const s=Ke(m)??m;M({directory:s,status:null});let r=!1,l=null;const u=async()=>{try{const N=await ki(m);if(r)return;M({directory:s,status:N.status}),N.status==="pending"&&(l=window.setTimeout(()=>{u()},500))}catch{r||M({directory:s,status:null})}};return u(),()=>{r=!0,l!==null&&window.clearTimeout(l)}},[o,m]);const nr=Ke(C?.bootstrapPendingDirectory??null),hn=!!(m&&nr&&nr===Ke(m)),mn=xi(m??null),we=Ke(m),gs=w?.directory===we?w.status:null,ps=!!(m&&(mn||gs==="pending"||hn&&C?.pendingWorktreeRequestId)),ar=!!(we&&A?.directory===we);i.useEffect(()=>{if(!we)return;if(gs==="failed"){z(null),k(r=>r?.directory===we?null:r);return}if(ps){k(r=>r?.directory===we&&r.status==="refreshing"?r:{directory:we,status:"refreshing"});return}if(A?.directory!==we||A.status!=="refreshing"||!a||!n)return;let s=!1;return ne(a,n,{force:!0,silent:!0,throwOnError:!0}).then(()=>{s||k(r=>r?.directory===we?null:r)}).catch(()=>{s||k(r=>r?.directory===we?{...r,status:"failed"}:r)}),()=>{s=!0}},[ne,n,a,ps,we,gs,A,z]);const fn=ps||ar,xs=ar&&A?.status==="failed",ir=i.useMemo(()=>a?dt.get(a)??null:null,[a]),kt=yi(s=>s.settingsGitmojiEnabled),[Vt,ys]=i.useState(null),{gitmojis:pt}=io(kt);i.useEffect(()=>{const s=me||d?.projectDirectory;if(!s){ys(null);return}let r=!1;return wi(s).then(l=>{if(r)return;const u=l.trim();ys(u&&u!=="HEAD"?u:null)}).catch(()=>{r||ys(null)}),()=>{r=!0}},[me,d?.projectDirectory]);const[Rt,xt]=i.useState(ir?.commitMessage??""),[or,gn]=i.useState([]),[pn,ws]=i.useState(!1),lr=i.useRef(null),[cr,Ut]=i.useState(null),[xn,bs]=i.useState(!1),[ur,dr]=i.useState(null),[Ie,yn]=i.useState(25),[wn,hr]=i.useState(!1),{triggerFireworks:bn}=Pi(),mr=i.useRef(new Map),Kt=i.useRef(0),vs=i.useCallback(()=>{Kt.current+=1,Nt.current&&hr(!0)},[]),js=i.useCallback(()=>{Kt.current=Math.max(0,Kt.current-1),Nt.current&&Kt.current===0&&hr(!1)},[]),[Cs,qt]=i.useState(new Set),[vn,fr]=i.useState(new Set),[Ss,gr]=i.useState(!1),[jn,Cn]=i.useState(0),[Sn,pr]=i.useState(!1),[Ns,ks]=i.useState(ir?.generatedHighlights??[]),Nn=vn.size>0||et.size()>0||et.isRunning(),xr=i.useCallback(()=>{const s=lr.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),Vs=me||d?.projectDirectory||null,Rs=j?.current||null,kn=i.useMemo(()=>{const s=j?.tracking;return s?s.startsWith("origin/"):!0},[j?.tracking]),yr=i.useMemo(()=>{const s=d?.createdFromBranch,r=typeof s=="string"?s.trim():"",l=typeof j?.current=="string"?j.current.trim():"",u=typeof Vt=="string"?Vt.trim():"";return r?r===l&&r.startsWith("opencode/")&&u.length>0&&u!==r?u:r:u||l||"HEAD"},[d?.createdFromBranch,j,Vt]),Jt=i.useCallback(()=>{ks([])},[]),[Is,Vn]=i.useState(new Set),[Yt,Rn]=i.useState(new Map),[Qt,Ps]=i.useState(new Set),Fs=i.useRef(Yt),It=i.useRef(Qt),[In,yt]=i.useState(null),[wr,br]=i.useState(""),[ge,Xt]=i.useState(null),[Pn,vr]=i.useState(!1),[Fn,jr]=i.useState(!1),[Dn,Cr]=i.useState(null),[Sr,Nr]=i.useState(null),[Bn,Zt]=i.useState([]),[Mn,wt]=i.useState(!1),[On,Pt]=i.useState([]),[es,Ft]=i.useState("merge"),[An,Ds]=i.useState(null),[Bs,kr]=i.useState(!1),[Ms,Tn]=i.useState(100),[En,Ln]=i.useState(0),Pe=i.useMemo(()=>T?`openchamber.conflict:${T}`:null,[T]),Vr=i.useCallback((s,r,l)=>{if(!Pe||typeof window>"u")return;const u={directory:s,conflictFiles:r,operation:l};window.localStorage.setItem(Pe,JSON.stringify(u))},[Pe]),Fe=i.useCallback(()=>{!Pe||typeof window>"u"||window.localStorage.removeItem(Pe)},[Pe]),Ue=i.useCallback((s,r)=>{Pt(s),Ft(r),wt(!0),a&&Vr(a,s,r)},[a,Vr]);i.useEffect(()=>{if(!Pe||typeof window>"u"||!a)return;const s=window.localStorage.getItem(Pe);if(s)try{const r=JSON.parse(s);if(r.directory!==a){window.localStorage.removeItem(Pe);return}Pt(r.conflictFiles??[]),Ft(r.operation??"merge"),wt(!0)}catch{window.localStorage.removeItem(Pe)}},[Pe,a]);const[zn,Rr]=i.useState(!1),[ts,Dt]=i.useState(null),[Os,Gn]=i.useState("merge"),[As,_n]=i.useState(""),[Ts,Hn]=i.useState(""),$n=i.useCallback(s=>{bi(s).then(r=>{if(r.ok){p.success(e("gitView.toast.commitHashCopied"));return}p.error(e("gitView.toast.copyFailed"))})},[e]),Wn=i.useCallback(s=>{Vn(r=>{const l=new Set(r);return l.has(s)?l.delete(s):l.add(s),l})},[]);i.useEffect(()=>{Fs.current=Yt},[Yt]),i.useEffect(()=>{It.current=Qt},[Qt]),i.useEffect(()=>{if(!a||!n)return;const s=Array.from(Is).filter(l=>!Fs.current.has(l)&&!It.current.has(l));if(s.length===0)return;let r=!1;return Ps(l=>{const u=new Set(l);for(const N of s)u.add(N);return It.current=u,u}),Promise.all(s.map(l=>n.getCommitFiles(a,l).then(u=>({hash:l,files:u.files})).catch(u=>(console.error("Failed to fetch commit files:",u),{hash:l,files:[]})))).then(l=>{r||(Rn(u=>{const N=new Map(u);for(const{hash:v,files:B}of l)N.set(v,B);return Fs.current=N,N}),Ps(u=>{const N=new Set(u);for(const{hash:v}of l)N.delete(v);return It.current=N,N}))}),()=>{r=!0,Ps(l=>{let u=!1;const N=new Set(l);for(const v of s)N.delete(v)&&(u=!0);return u?(It.current=N,N):l})}},[Is,a,n]),i.useEffect(()=>{if(!a)return;const s=dt.get(a)??null;xt(s?.commitMessage??""),ks(s?.generatedHighlights??[])},[a]),i.useEffect(()=>{a&&Jo(a,{directory:a,commitMessage:Rt,generatedHighlights:Ns})},[Rt,a,Ns]),i.useEffect(()=>{o&&(Z(),O(),R())},[o,Z,O,R]);const ss=i.useCallback(async()=>{if(!a||!n?.getRemotes||J!==!0){Me([]);return}try{const s=await n.getRemotes(a);Nt.current&&Me(s)}catch{Nt.current&&Me([])}},[a,n,J]);i.useEffect(()=>{o&&ss()},[o,ss]),i.useEffect(()=>{o&&m&&a&&(ce(m),ee(a,n))},[o,m,a,ce,ee,n]),i.useEffect(()=>{if(o&&a)return vi.onGitRefreshHint(s=>{Ke(s.directory)===Ke(a)&&(s.paths?.length&&je(a,s.paths),ne(a,n,{silent:!0}))})},[o,je,a,ne,n]);const se=i.useCallback(async(s=!0)=>{if(a)try{await Promise.all([ne(a,n),X(a,n)])}catch(r){if(s){const l=r instanceof Error?r.message:e("gitView.toast.refreshRepositoryFailed");p.error(l)}}},[a,n,ne,X,e]),ue=i.useCallback(async()=>{a&&await ae(a,n,Ie)},[a,n,ae,Ie]),lt=i.useCallback(async s=>{if(!a)return;const r=Promise.allSettled([X(a,n),ue()]);s&&r.then(s),await ne(a,n).catch(()=>{})},[a,n,X,ne,ue]),Es=i.useCallback(async()=>{a&&await ve(a,n)},[a,n,ve]);i.useEffect(()=>{if(!o||!a||!n?.hasLocalIdentity||J!==!0)return;const s=typeof G=="string"?G.trim():"";if(!s||s==="global")return;const r=ut(),l=JSON.stringify([r,a]);if(mr.current.get(l)===s)return;let N=!1,v=!1;return(async()=>{try{const W=await n.hasLocalIdentity?.(a);if(N||ut()!==r||W===!0||(vs(),v=!0,await n.setGitIdentity(a,s),N||ut()!==r))return;mr.current.set(l,s),await Es()}catch(W){!N&&ut()===r&&console.warn("Failed to auto-apply default git identity:",W)}finally{v&&js()}})(),()=>{N=!0}},[o,vs,a,G,js,n,J,Es]);const tt=i.useMemo(()=>j?[...j.files??[]].sort((r,l)=>r.path.localeCompare(l.path)):[],[j]),Ne=i.useMemo(()=>tt.filter(an),[tt]),Ls=i.useMemo(()=>tt.filter(Yo),[tt]);i.useEffect(()=>{if(!o||!a||tt.length===0)return;const s=[],r=new Set,l=N=>{!N||r.has(N)||(r.add(N),s.push(N))};if(Ne.forEach(N=>l(N.path)),or.forEach(l),tt.slice(0,Uo).forEach(N=>l(N.path)),s.length===0)return;const u=window.setTimeout(()=>{ke(a,n,s,{maxFiles:Wo})},120);return()=>{window.clearTimeout(u)}},[o,tt,a,n,ke,Ne,or]);const Bt=async(s,r,l=!1)=>{if(!a)return;const u=te.start();if(!u)return;Ut(s);const N=e(s==="fetch"?"gitView.sync.fetch":s==="pull"?"gitView.sync.pull":s==="publish"?"gitView.publish.title":"gitView.sync.syncChanges");let v=null;try{if(s==="sync"||s==="publish"){const B=await U.prepare(s==="publish"?"push":"sync",{forceChoose:l,onOperation:u.onOperation});v=Ri(await B())}else if(r&&j)await $r({action:s,directory:a,remoteName:r.name,status:j,sourceControl:h,git:n,onOperation:u.onOperation});else throw new be("tracking-required");if(!u.isCurrent())return;s==="fetch"&&r?p.success(e("gitView.toast.fetchedFromRemote",{name:r.name})):s==="pull"&&r?p.success(e("gitView.toast.pulledFromRemote",{name:r.name})):s==="sync"?p.success(v?.kind==="up-to-date"?e("gitView.toast.alreadyUpToDate"):v?.kind==="pulled"?e("gitView.toast.pulledFromRemote",{name:v.remoteName}):v?.kind==="pushed"?e("gitView.toast.pushedToUpstream",{name:v.remoteName}):e("gitView.toast.syncedChanges")):s==="publish"&&p.success(e("gitView.publish.succeeded")),await lt()}catch(B){if(B instanceof Et||B instanceof Wr){if(B instanceof Et&&B.read.availability==="available"&&p.error(e("gitView.toast.syncActionFailed",{action:N}),{description:B.message||void 0}),u.isCurrent()&&await lt(),u.isCurrent()&&B instanceof Et&&B.read.availability==="available"&&B.read.operation.state==="conflicted"&&B.read.operation.error.code==="CONFLICT"){const Ee=((await n.getGitStatus(a).catch(()=>null))?.files??[]).filter(Ws).map(Sa=>Sa.path);Ee.length>0&&Ue(Ee,"merge")}return}if(B instanceof be&&B.code==="stale-runtime")return;if(B instanceof be&&U.errorMessage(B)){p.info(U.errorMessage(B));return}await lt();const W=B instanceof be?B.code==="contributor-publish-cancelled-after-update"?e("gitView.toast.contributorPublishCancelledAfterUpdate"):B.code==="contributor-publish-cancelled"?e("gitView.toast.contributorPublishCancelled"):e("gitView.toast.syncActionFailed",{action:N}):B instanceof Error?B.message:e("gitView.toast.syncActionFailed",{action:N});p.error(W)}finally{u.finish(),u.isCurrent()&&Ut(null)}},Un=i.useCallback(async s=>{if(!a)return;const r=s.name.trim();if(!r){p.error(e("gitView.toast.remoteNameRequired"));return}if(r==="origin"){p.error(e("gitView.toast.cannotRemoveOriginRemote"));return}Cr(r);try{await n.removeRemote(a,{remote:r}),p.success(e("gitView.toast.removedRemote",{name:r})),await Promise.all([se(!1),ss()])}catch(l){const u=l instanceof Error?l.message:`Failed to remove ${r}`;p.error(u)}finally{Cr(null)}},[a,n,ss,se,e]),Ir=async(s={})=>{if(!a)return;if(!Rt.trim()){p.error(e("gitView.toast.enterCommitMessage"));return}const r=Ne.map(v=>v.path).sort();if(r.length===0){p.error(e("gitView.toast.stageFileToCommit"));return}const l=s.pushAfter?"commitAndPush":"commit";dr(l);let u=null,N="pending";try{if(await n.createGitCommit(a,Rt.trim(),{files:r,stageFiles:[]}),N="local",le(a),le(a),p.success(e("gitView.toast.commitCreated")),xt(""),Jt(),s.pushAfter){if(u=te.start(),!u){p.warning(e("gitView.publish.commitKept")),await lt();return}const v=await U.prepare("push",{onOperation:u.onOperation});Ut("publish"),await v(),N="published",p.success(e("gitView.publish.succeeded")),bn()}await lt(()=>Cn(v=>v+1))}catch(v){if(s.pushAfter&&N==="local"&&p.warning(e("gitView.publish.commitKept")),v instanceof Et||v instanceof Wr){v instanceof Et&&v.read.availability==="available"&&p.error(e("gitView.toast.pushFailed"),{description:v.message||void 0}),await lt();return}if(v instanceof be&&v.code==="stale-runtime")return;if(v instanceof be&&U.errorMessage(v)){p.info(U.errorMessage(v));return}s.pushAfter&&await lt();const B=v instanceof be?v.code==="contributor-publish-cancelled-after-update"?e("gitView.toast.contributorPublishCancelledAfterUpdate"):v.code==="contributor-publish-cancelled"?e("gitView.toast.contributorPublishCancelled"):e("gitView.toast.syncActionFailed",{action:e("gitView.sync.syncChanges")}):v instanceof Error?v.message:e("gitView.toast.createCommitFailed");p.error(B)}finally{u?.finish(),dr(null),s.pushAfter&&Ut(null)}},Kn=i.useCallback(async()=>{if(!a)return;const s=Ne.map(r=>r.path).sort();if(s.length===0){p.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:a,selectedFiles:s.length}),pr(!0);try{const{message:r}=await Hr(a,s),l=r.subject?.trim()??"",u=Array.isArray(r.highlights)?r.highlights:[];if(l){let N=l;if(kt&&pt.length>0){const v=nn(l,pt);if(v){const{code:B,emoji:W}=v;!l.startsWith(B)&&!l.startsWith(W)&&(N=`${B} ${l}`)}}xt(N)}ks(u),xr()}catch(r){console.error("[git-generation][browser] GitView generate handler failed",{message:r instanceof Error?r.message:String(r),error:r});const l=r instanceof Error?r.message:e("gitView.toast.generateCommitMessageFailed");p.error(l)}finally{pr(!1)}},[a,Ne,kt,pt,xr,e]),zs=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",qn=async s=>{if(!a||!j)return;const r=$s(oe);if(r.length>0){p.error(e("gitView.toast.cannotCreateBranch",{reason:zs(r[0])}));return}const l=j.current??null;try{await n.createBranch(a,s,l??"HEAD"),p.success(e("gitView.toast.createdBranch",{name:s})),await n.checkoutBranch(a,s),await se(),await ue()}catch(u){if(u instanceof be&&u.code==="stale-runtime")return;const N=u instanceof Error?u.message:e("gitView.toast.createBranchFailed");throw p.error(N),u}},Jn=async(s,r)=>{if(!a)return;const l=$s(oe);if(l.length>0){p.error(e("gitView.toast.cannotRenameBranch",{reason:zs(l[0])}));return}try{await n.renameBranch(a,s,r),p.success(e("gitView.toast.renamedBranch",{oldName:s,newName:r})),await se(),await ue()}catch(u){const N=u instanceof Error?u.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:r});p.error(N)}},Yn=async s=>{if(!a)return;const r=$s(oe);if(r.length>0){p.error(e("gitView.toast.cannotCheckout",{reason:zs(r[0])}));return}const l=s.replace(/^remotes\//,"");if(j?.current!==l){if((j?.files?.length??0)>0){Dt(l);return}await Gs(l)}},Gs=async s=>{if(!a)return;const r=s;try{const l=await n.checkoutBranch(a,r);p.success(e("gitView.toast.checkedOut",{name:l?.branch||r})),await se(),await ue()}catch(l){const u=l instanceof Error?l.message:e("gitView.toast.checkoutFailed",{name:r});p.error(u)}},Qn=async s=>{if(!a)return;const r=ut();vs();try{const l=await Ki({directory:a,identity:s,remoteName:Oe||null},{git:n,sourceControl:h});if(ut()!==r)return;l.status==="failed"?p.error(e("gitView.toast.applyIdentityFailed")):p.success(e("gitView.toast.appliedIdentity",{name:Vi(s,e)})),await Es()}catch(l){if(ut()!==r)return;const u=l instanceof Error?l.message:e("gitView.toast.applyIdentityFailed");p.error(u)}finally{js()}},Mt=i.useMemo(()=>c?.all?c.all.filter(s=>!s.startsWith("remotes/")).sort():[],[c]),Ot=i.useMemo(()=>c?.all?c.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[c]),Xn=i.useMemo(()=>Eo(Ve.map(s=>s.name),Ot),[Ve,Ot]),st=j?.current??null,Pr=i.useMemo(()=>{const s=$.contexts[0]?.primaryRemote;return s?c?.defaultBranches?.[s]:void 0},[$.contexts,c]),ct=i.useMemo(()=>zi({remoteNames:new Set($.contexts[0]?.primaryRemote?[$.contexts[0].primaryRemote]:[]),knownRemoteNames:new Set($.read?.repository.remotes.map(s=>s.name)??[]),localBranches:Mt,worktreeCreatedFromBranch:d?.createdFromBranch,rootBranchHint:Vt,defaultBranch:Pr,headBranch:st,fallbackToConventional:!1}),[st,Pr,$.contexts,Mt,$.read,Vt,d?.createdFromBranch]),Zn=i.useMemo(()=>{const s=$.contexts[0]?.primaryRemote,r=s?`${s}/${ct}`:null;return r&&Ot.includes(r)?r:ct},[ct,$.contexts,Ot]),Fr=ji(),ea=i.useMemo(()=>Go(V,F,Fr),[V,F,Fr]),Dr=$.read?$.read.binding?.providers.find(s=>s.readiness==="ready")?.accountId??null:void 0,ta=i.useMemo(()=>_o(V,F,L,Dr),[Dr,L,V,F]),sa=Ne.length,ra=re||cr!==null||ur!==null,na=!!(d&&Vs&&Rs&&kn),Br=!!st,rt=na&&Vs&&Rs&&d?{repoRoot:Vs,sourceBranch:Rs,worktreeMetadata:d}:null;i.useEffect(()=>{if(!a||!n||!I?.all?.length||!st||!ct||st===ct){yt(null);return}let s=!1;return(async()=>{try{const l=await n.getGitLog(a,{from:ct,to:"HEAD",maxCount:Ie});if(s)return;const u=new Set((l?.all??[]).map(v=>v.hash).filter(v=>typeof v=="string"&&v.length>0));if(u.size===0){yt(null);return}const N=I.all.findIndex(v=>!u.has(v.hash));if(N===0){yt(null);return}if(N===-1){yt({insertBeforeIndex:I.all.length,branchName:st,direction:"up"});return}yt({insertBeforeIndex:N,branchName:st,direction:"up"})}catch{s||yt(null)}})(),()=>{s=!0}},[ct,st,a,n,I,Ie]),i.useEffect(()=>{Ds(null)},[a]),i.useEffect(()=>{if(ge!=="graph"||!a){ge!=="graph"&&Ds(null);return}let s=!1;return kr(!0),n.getGitLog(a,{maxCount:Ms,all:!0}).then(r=>{s||Ds(r)}).catch(r=>{console.error("Failed to fetch graph log:",r)}).finally(()=>{s||kr(!1)}),()=>{s=!0}},[ge,a,Ms,En,n]);const At=i.useCallback((s,r)=>{if(!a||s.length===0)return;const l=Array.from(new Set(s));fr(N=>{const v=new Set(N);return l.forEach(B=>v.add(B)),v});const u=Be(a,l,r);et.enqueue({directory:a,direction:r,paths:new Set(l),rollback:()=>St(a,u)}),Wt()},[a,et,Be,St,Wt]),_s=i.useCallback(async s=>{if(a){qt(r=>{const l=new Set(r);return l.add(s),l});try{await n.revertGitFile(a,s,{scope:"working"}),p.success(e("gitView.toast.revertedFile",{path:s})),await se(!1)}catch(r){const l=r instanceof Error?r.message:e("gitView.toast.revertFailed");p.error(l)}finally{qt(r=>{const l=new Set(r);return l.delete(s),l})}}},[a,se,n,e]),Tt=i.useCallback(async(s,r,l="all")=>{if(!a||s.length===0)return;const u=Array.from(new Set(s));if(Ss||u.some(W=>Cs.has(W)))return;const N=new Set(Ne.map(W=>W.path)),v=l==="all"&&u.some(W=>N.has(W));r&&gr(!0),qt(W=>{const ie=new Set(W);return u.forEach(Ee=>ie.add(Ee)),ie});const B=[];try{if(await Ci(u,Ko,async W=>{try{await n.revertGitFile(a,W,{scope:l})}catch(ie){B.push({path:W,message:ie instanceof Error?ie.message:e("gitView.toast.revertFailed")})}}),v&&B.length<u.length&&le(a),await se(!1),B.length===0)p.success(u.length===1?e("gitView.toast.revertedFilesSingle",{count:u.length}):e("gitView.toast.revertedFilesPlural",{count:u.length}));else if(B.length===u.length)p.error(B[0]?.message||e("gitView.toast.revertFailed"));else{const W=u.length-B.length;p.warning(W===1?e("gitView.toast.revertedSomeSingle",{success:W,failed:B.length}):e("gitView.toast.revertedSomePlural",{success:W,failed:B.length}))}}finally{qt(W=>{const ie=new Set(W);return u.forEach(Ee=>ie.delete(Ee)),ie}),r&&gr(!1)}},[le,a,n,Ss,se,Cs,Ne,e]),aa=i.useCallback(async s=>{await Tt(s,!0)},[Tt]),ia=i.useCallback(async s=>{await Tt(s,!1,"working")},[Tt]),Hs=i.useCallback((s,r)=>{if(g&&!ze){Ge(g,s,r);return}We(s,r)},[g,ze,We,Ge]),oa=i.useCallback(()=>bs(!0),[]),la=i.useMemo(()=>{const s=[];return Ne.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:Ne,statsScope:"staged",actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:r=>e("gitView.changes.unstageFileAria",{path:r}),onActionFile:r=>{At([r],"unstage")},onActionAll:r=>{At(r,"unstage")},onViewDiff:r=>Hs(r,!0),onRevertFile:_s,showRevertActions:!1,accent:!0}),Ls.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:Ls,statsScope:"working",actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:r=>e("gitView.changes.stageFileAria",{path:r}),onActionFile:r=>{At([r],"stage")},onActionAll:r=>{At(r,"stage")},onViewDiff:r=>Hs(r,!1),onRevertFile:_s}),s},[_s,Hs,At,Ne,e,Ls]),ca=i.useCallback(s=>{if(s.length===0)return;const r=s.map(l=>l.trim()).filter(Boolean);if(r.length===0){Jt();return}xt(l=>{const u=l.trim(),N=u.length>0?`
3
3
 
4
4
  `:"";return`${u}${N}${r.join(`
5
- `)}`.trim()}),Jt()},[Jt]),ua=i.useCallback((s,r)=>{const l=r||s;xt(u=>{const N=u.trimStart();return N.startsWith(s)||r&&N.startsWith(r)?u:`${l.endsWith(" ")?l:`${l} `}${u}`.trimStart()}),br(""),ws(!1)},[]),Mr=i.useCallback(s=>{const r=s instanceof Error?s.message.toLowerCase():"";return r.includes("uncommitted changes")||r.includes("local changes")||r.includes("your local changes would be overwritten")||r.includes("please commit your changes or stash them")||r.includes("cannot rebase: you have unstaged changes")||r.includes("error: cannot pull with rebase")},[]),bt=i.useCallback((s,r)=>{Zt(l=>[...l,{message:s,status:r,timestamp:Date.now()}])},[]),Te=i.useCallback((s,r)=>{Zt(l=>{if(l.length===0)return l;const u=[...l];return u[u.length-1]={...u[u.length-1],status:s,...r?{message:r}:{}},u})},[]),Ar=i.useCallback(()=>{Zt([])},[]),da=i.useCallback(()=>{Zt([]),Nr(null)},[]),rs=i.useCallback(async(s,r)=>{if(!a)return;const l=r.kind==="remote"?te.start():null;if(r.kind==="remote"&&!l)return;Nr(s),Ar();const u=j?.current;let N=r.branch;try{if(N=await Lo({directory:a,git:n,target:r,runPlannedFetch:async v=>{if(bt(`Fetching ${v.label}...`,"running"),!j||!l)throw new be("branch-required");if(await $r({action:"fetch",directory:a,fetchTarget:{remoteName:v.remote,sourceRef:v.sourceRef,destinationRef:v.destinationRef},remoteName:v.remote,status:j,sourceControl:h,git:n,onOperation:l.onOperation}),!l.isCurrent())throw new be("stale-runtime");Te("done",`Fetched ${v.label}`)}}),l&&!l.isCurrent())throw new be("stale-runtime");if(s==="merge"){bt(`Merging ${r.label} into ${u}...`,"running");const v=await n.merge(a,{branch:N});v.conflict?(Te("error","Merge conflicts detected"),Ue(v.conflictFiles??[],"merge")):(Te("done",`Merged ${r.label} into ${u}`),Fe(),bt("Refreshing repository status...","running"),await se(),await ue(),Te("done","Repository status updated"))}else{bt(`Rebasing ${u} onto ${r.label}...`,"running");const v=await n.rebase(a,{onto:N});v.conflict?(Te("error","Rebase conflicts detected"),Ue(v.conflictFiles??[],"rebase")):(Te("done",`Rebased ${u} onto ${r.label}`),Fe(),bt("Refreshing repository status...","running"),await se(),await ue(),Te("done","Repository status updated"))}}catch(v){if(Mr(v))Te("error","Uncommitted changes detected"),Gn(s),_n(N),Hn(r.label),Rr(!0);else{const B=v instanceof be?e("gitView.toast.syncActionFailed",{action:e("gitView.sync.fetch")}):v instanceof Error?v.message:s==="merge"?`Failed to merge ${r.label}`:`Failed to rebase onto ${r.label}`;Te("error",B)}}finally{l?.finish()}},[a,n,h,j,te,se,ue,Mr,Ue,Fe,bt,Te,Ar,e]),ha=i.useCallback(s=>{rs("merge",s)},[rs]),ma=i.useCallback(s=>{rs("rebase",s)},[rs]),fa=i.useCallback(async()=>{if(a)try{es==="merge"?(await n.abortMerge(a),p.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(a),p.success(e("gitView.toast.rebaseAborted"))),Fe(),await se(),await ue()}catch(s){const r=s instanceof Error?s.message:`Failed to abort ${es}`;p.error(r)}},[a,n,es,se,ue,Fe,e]),ga=i.useMemo(()=>(j?.files??[]).filter(Ws).length,[j?.files]),pa=i.useCallback(async()=>{if(a)try{const s=!!j?.mergeInProgress?.head,r=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(s){const l=await n.continueMerge(a);l.conflict?(Ue(l.conflictFiles??[],"merge"),p.error(e("gitView.toast.mergeConflictsDetected"))):(Fe(),p.success(e("gitView.toast.mergeCompleted")),await se(),await ue())}else if(r){const l=await n.continueRebase(a);l.conflict?(Ue(l.conflictFiles??[],"rebase"),p.error(e("gitView.toast.rebaseConflictsDetected"))):(Fe(),p.success(e("gitView.toast.rebaseStepCompleted")),await se(),await ue())}}catch(s){const r=s instanceof Error?s.message:e("gitView.toast.continueOperationFailed");p.error(r)}},[a,n,j,se,ue,Ue,Fe,e]),xa=i.useCallback(async()=>{if(a)try{!!j?.mergeInProgress?.head?(await n.abortMerge(a),p.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(a),p.success(e("gitView.toast.rebaseAborted"))),Fe(),await se(),await ue()}catch(s){const r=s instanceof Error?s.message:e("gitView.toast.abortOperationFailed");p.error(r)}},[a,n,j,se,ue,Fe,e]),ya=i.useCallback(()=>{if(!a)return;const r=!!j?.mergeInProgress?.head?"merge":"rebase",l=(j?.files??[]).filter(Ws).map(u=>u.path);l.length>0&&Pt(l),Ft(r),wt(!0)},[a,j]),wa=i.useCallback(async s=>{if(!a)return;const r=j?.current,l=As,u=Os,N=Ts||u,v=(j?.files??[]).some(an);try{await n.stash(a,{message:`Auto-stash before ${l} with ${N}`,includeUntracked:!0}),v&&le(a)}catch(ie){const Ee=ie instanceof Error?ie.message:"Failed to stash changes";p.error(Ee);return}let B=!1,W=!1;try{if(l==="merge"){const ie=await n.merge(a,{branch:u});ie.conflict?(W=!0,Pt(ie.conflictFiles??[]),Ft("merge"),wt(!0)):(B=!0,p.success(e("gitView.toast.mergedIntoBranch",{branch:N,currentBranch:r||""})))}else{const ie=await n.rebase(a,{onto:u});ie.conflict?(W=!0,Pt(ie.conflictFiles??[]),Ft("rebase"),wt(!0)):(B=!0,p.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:r||"",branch:N})))}if(s&&B)try{await n.stashPop(a),le(a),p.success(e("gitView.toast.stashedRestored"))}catch(ie){const Ee=ie instanceof Error?ie.message:e("gitView.toast.restoreStashFailed");p.error(Ee)}else s&&W&&p.info(e("gitView.toast.restoreStashManually"));await se(),await ue()}catch(ie){if(s)try{await n.stashPop(a),le(a)}catch{}throw ie}},[le,a,n,j,As,Os,Ts,se,ue,e]),ba=i.useCallback(s=>{yn(s),a&&(De(a,s),ae(a,n,s))},[a,ae,n,De]),va=i.useCallback(s=>{Tn(s)},[]),ja=i.useCallback(()=>{Xt(null),a&&(ne(a,n),X(a,n),ae(a,n,Ie))},[a,ne,X,ae,Ie,n]),Ca=i.useCallback(s=>{if(s.conflict){if(s.operation==="cherry-pick"||s.operation==="revert"){p.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:s.conflictFiles?.join(", ")??"unknown files"})}),a&&(ne(a,n),X(a,n),ae(a,n,Ie));return}Ue(s.conflictFiles??[],s.operation)}},[e,Ue,a,ne,X,ae,Ie,n]);return y?.kind==="preparing"?t.jsx(Gi,{}):m?fn?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[xs?null:t.jsx(cs,{className:"mb-3 size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e(xs?"gitView.toast.refreshRepositoryFailed":"gitView.empty.worktreeSetupInProgress")}),xs?t.jsx(K,{type:"button",variant:"outline",size:"sm",className:"mt-3",onClick:()=>{we&&k({directory:we,status:"refreshing"})},children:e("gitView.empty.retryDiscovery")}):t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):J===null||J===!0&&!j?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(cs,{className:"size-4"}),t.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):J===!1?t.jsx(_i,{root:m,rootIsGitRepo:E,resolvedIsGitRepo:J,nestedRepos:Y,onRetryDiscovery:()=>{m&&Le(m,{force:!0})},emptyStateFooter:xe.includes("open-without-worktree-features")?t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):void 0}):t.jsxs("div",{className:fe("flex h-full flex-col overflow-hidden"),children:[t.jsx(Hi,{directory:a??"",status:j,localBranches:Mt,remoteBranches:At,branchInfo:c?.branches,syncAction:te.entry?.executing?cr:null,operationBlocked:te.blocked,remotes:Ve,onFetch:s=>Bt("fetch",s),onPull:s=>Bt("pull",s),onSync:s=>Bt("sync",s),onPublish:()=>{Bt("publish")},onChooseSyncTargets:()=>{Bt("sync",void 0,!0)},onRemoveRemote:Un,removingRemoteName:Dn,onCheckoutBranch:Yn,onCreateBranch:qn,onRenameBranch:Jn,activeIdentityProfile:ta,availableIdentities:ea,onSelectIdentity:Qn,isApplyingIdentity:wn,identityAttention:Qe,identityApplicability:Xe,onConfigureRepository:x.isVSCode?void 0:()=>_e(!0),onIdentityMenuOpen:()=>{Ze(h,V.map(s=>s.account))},isWorktreeMode:!!d,onOpenHistory:()=>Xt("history"),onOpenGraph:()=>Xt("graph"),onOpenStashes:oa,onOpenUpdateBranch:Br?()=>vr(!0):void 0,onOpenReintegrateCommits:rt?()=>jr(!0):void 0,pullRequest:Ce?.changeRequest??Ce?.pr??null,pullRequestProvider:Ce?.changeRequest?.provider??null,prChecks:Ce?.ci?.summary??Ce?.checks??null,onOpenPullRequest:a?()=>Je(g??a,{mode:"pr"}):void 0,repositoryOptions:q??void 0,selectedRepository:q?a:null,onSelectRepository:q&&m?s=>qe(m,s):void 0,repositoryRoot:q?m??void 0:void 0}),x.isVSCode?null:t.jsx(Yi,{open:Ye,onOpenChange:_e,directory:o?a??"":""}),t.jsx($i,{className:"mx-4 mt-3",entry:te.entry,onRefresh:()=>{te.refresh()},onCancel:()=>{te.cancel()}}),m&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&t.jsx(Qi,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:pa,onAbort:xa,onResolveWithAI:ya,conflictCount:ga,isLoading:re}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:t.jsx("div",{className:"h-full min-h-0 flex flex-col",children:t.jsx("div",{className:fe("min-w-0 min-h-0 h-full flex flex-col"),children:t.jsx(ln,{as:Si,ref:lr,outerClassName:"flex-1 min-h-0",className:fe("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:t.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(tt?.length??0)>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Xi,{groups:la,diffStats:j?.diffStats,revertingPaths:Cs,isRevertingAll:Ss,onVisiblePathsChange:gn,onRevertAll:aa,onRevertDirectory:ia,headerBackgroundClassName:"bg-background"})}),t.jsx(Zi,{stagedCount:sa,commitMessage:Rt,onCommitMessageChange:xt,generatedHighlights:Ns,onInsertHighlights:ca,onGenerateMessage:Kn,isGeneratingMessage:Sn,onCommit:()=>Ir({pushAfter:!1}),onCommitAndPush:()=>Ir({pushAfter:!0}),commitAction:ur,networkOperationBlocked:te.blocked,hasPendingIndexMutation:Nn,gitmojiEnabled:kt,onOpenGitmojiPicker:()=>ws(!0)})]}):t.jsx(go,{onOpenStashes:()=>bs(!0)})})})})})}),t.jsx(ht,{open:Pn,onOpenChange:s=>{!s&&Sr!==null||vr(s)},children:t.jsxs(mt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(gt,{children:e("gitView.branch.updateTitle")}),t.jsxs(jt,{children:[e("gitView.branch.updateDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:j?.current??""}),"."]})]}),Br?t.jsx(Po,{mode:"bare",currentBranch:j?.current,localBranches:Mt,remoteBranches:Xn,defaultTargetBranch:Zn,onMerge:ha,onRebase:ma,disabled:ra||te.blocked,isOperating:Sr!==null,operationLogs:Bn,onOperationComplete:da}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),t.jsx(ht,{open:Fn,onOpenChange:jr,children:t.jsxs(mt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(gt,{children:e("gitView.integrate.title")}),t.jsx(jt,{children:rt?t.jsxs("span",{className:"font-mono text-foreground",children:[rt.sourceBranch," → ",yr]}):null})]}),rt?t.jsx(mo,{repoRoot:rt.repoRoot,sourceBranch:rt.sourceBranch,worktreeMetadata:rt.worktreeMetadata,localBranches:Mt,defaultTargetBranch:yr,refreshKey:jn,showHeader:!1,onRefresh:()=>{a&&(ne(a,n),X(a,n),ae(a,n,Ie))}},rt.worktreeMetadata.path):null]})}),t.jsx(ht,{open:ge!==null,onOpenChange:s=>{s||Xt(null)},children:t.jsxs(mt,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(gt,{children:e(ge==="graph"?"gitView.graph.title":"gitView.history.title")}),t.jsxs(K,{type:"button",variant:"ghost",size:"sm",className:"me-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(ge==="graph"){Ln(s=>s+1);return}a&&ae(a,n,Ie)},disabled:ge==="graph"?Bs:de,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[t.jsx(_,{name:"refresh",className:fe("size-4",(ge==="graph"?Bs:de)&&"animate-spin")}),e("gitView.history.refresh")]})]}),t.jsx(jt,{children:e("gitView.history.dialogDescription")})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(So,{mode:ge==="graph"?"graph":"history",log:ge==="graph"?On??I:I,isLogLoading:ge==="graph"&&Bs||de,logMaxCount:ge==="graph"?Ms:Ie,onLogMaxCountChange:ge==="graph"?va:ba,expandedCommitHashes:Is,onToggleCommit:Wn,commitFilesMap:Yt,loadingCommitHashes:Qt,onCopyHash:$n,directory:a??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ge==="graph"?null:In,onConflict:ge==="graph"?Ca:void 0,onActionSuccess:ge==="graph"?ja:void 0})})]})}),t.jsx(fo,{open:xn,onOpenChange:bs,directory:a,hasUncommittedChanges:(j?.files?.length??0)>0,hasStagedChanges:Ne.length>0,uncommittedFileCount:j?.files?.length??0,onChanged:async s=>{a&&s?.affectsIndex&&le(a),await se(!1),await ue()}}),t.jsx(ht,{open:pn,onOpenChange:ws,children:t.jsxs(mt,{className:"max-w-md p-0 overflow-hidden",children:[t.jsx(ft,{className:"px-4 pt-4",children:t.jsx(gt,{children:e("gitView.gitmoji.title")})}),t.jsxs(Xs,{className:"h-[420px]",shouldFilter:!1,children:[t.jsx(Zs,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:wr,onValueChange:br}),t.jsxs(er,{children:[t.jsx(tr,{children:e("gitView.gitmoji.empty")}),t.jsx(os,{children:_t(pt,wr,s=>[s.code,s.description,s.emoji]).map(s=>t.jsxs(ls,{onSelect:()=>ua(s.emoji,s.code),children:[t.jsx("span",{className:"text-lg",children:s.emoji}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s.code}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s.description})]},s.code))})]})]})]})}),U.context?t.jsx(Wi,{context:U.context,onSelect:U.settle}):null,U.confirmDialog,t.jsx(Ui,{candidates:f.candidates,onSelect:f.settle}),a&&t.jsx(eo,{open:Mn,onOpenChange:wt,conflictFiles:An,directory:a,operation:es,onAbort:fa,onClearState:Fe}),t.jsx(to,{open:ts!==null,onOpenChange:s=>{s||Dt(null)},targetBranch:ts??"",changedFileCount:j?.files?.length??0,onCommitAndSwitch:async(s,r)=>{const l=ts;if(!l||!a)return;const u=j?.current??null;await n.createGitCommit(a,s,{addAll:!0}),le(a);let N=null;if(r){const v=$.read?.repository.remotes.map(W=>W.name)??Ve.map(W=>W.name),B=u?Ho(u,j?.tracking,v,$.contexts[0]?.primaryRemote??v[0]??null):null;try{if(!B||!u)throw new Error(e("mobile.changes.noRemote"));await Ni({directory:a,branch:u,remoteName:B.remoteName,sourceControl:h,git:n,choose:f.choose,destinationRef:B.destinationRef}),N=B.remoteName}catch(W){console.error("Push after commit failed:",W),p.error(e("gitView.dirtySwitch.pushFailed")),await se(),await ue(),Dt(null);return}}p.success(N?e("gitView.toast.pushedToUpstream",{name:N}):u?e("gitView.dirtySwitch.committedNotPushed",{branch:u}):e("gitView.toast.commitCreated")),await se(),await ue(),Dt(null),await Gs(l)},onGenerateMessage:async()=>{if(!a)return"";const s=(j?.files??[]).map(u=>u.path).sort(),{message:r}=await Hr(a,s),l=r.subject?.trim()??"";if(l&&kt&&pt.length>0){const u=nn(l,pt);if(u&&!l.startsWith(u.code)&&!l.startsWith(u.emoji))return`${u.code} ${l}`}return l},onRevertAndSwitch:async()=>{const s=ts;if(!s||!a)return;const r=(j?.files??[]).map(u=>u.path);await Tt(r,!0,"all");const l=await n.getGitStatus(a);if(!l.isClean&&(l.files?.length??0)>0){p.error(e("gitView.dirtySwitch.revertIncomplete"));return}Dt(null),await Gs(s)}}),t.jsx(Io,{open:zn,onOpenChange:Rr,operation:As,targetBranch:Ts||Os,onConfirm:wa})]}):t.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})};export{hu as GitView};
5
+ `)}`.trim()}),Jt()},[Jt]),ua=i.useCallback((s,r)=>{const l=r||s;xt(u=>{const N=u.trimStart();return N.startsWith(s)||r&&N.startsWith(r)?u:`${l.endsWith(" ")?l:`${l} `}${u}`.trimStart()}),br(""),ws(!1)},[]),Mr=i.useCallback(s=>{const r=s instanceof Error?s.message.toLowerCase():"";return r.includes("uncommitted changes")||r.includes("local changes")||r.includes("your local changes would be overwritten")||r.includes("please commit your changes or stash them")||r.includes("cannot rebase: you have unstaged changes")||r.includes("error: cannot pull with rebase")},[]),bt=i.useCallback((s,r)=>{Zt(l=>[...l,{message:s,status:r,timestamp:Date.now()}])},[]),Te=i.useCallback((s,r)=>{Zt(l=>{if(l.length===0)return l;const u=[...l];return u[u.length-1]={...u[u.length-1],status:s,...r?{message:r}:{}},u})},[]),Or=i.useCallback(()=>{Zt([])},[]),da=i.useCallback(()=>{Zt([]),Nr(null)},[]),rs=i.useCallback(async(s,r)=>{if(!a)return;const l=r.kind==="remote"?te.start():null;if(r.kind==="remote"&&!l)return;Nr(s),Or();const u=j?.current;let N=r.branch;try{if(N=await Lo({directory:a,git:n,target:r,runPlannedFetch:async v=>{if(bt(`Fetching ${v.label}...`,"running"),!j||!l)throw new be("branch-required");if(await $r({action:"fetch",directory:a,fetchTarget:{remoteName:v.remote,sourceRef:v.sourceRef,destinationRef:v.destinationRef},remoteName:v.remote,status:j,sourceControl:h,git:n,onOperation:l.onOperation}),!l.isCurrent())throw new be("stale-runtime");Te("done",`Fetched ${v.label}`)}}),l&&!l.isCurrent())throw new be("stale-runtime");if(s==="merge"){bt(`Merging ${r.label} into ${u}...`,"running");const v=await n.merge(a,{branch:N});v.conflict?(Te("error","Merge conflicts detected"),Ue(v.conflictFiles??[],"merge")):(Te("done",`Merged ${r.label} into ${u}`),Fe(),bt("Refreshing repository status...","running"),await se(),await ue(),Te("done","Repository status updated"))}else{bt(`Rebasing ${u} onto ${r.label}...`,"running");const v=await n.rebase(a,{onto:N});v.conflict?(Te("error","Rebase conflicts detected"),Ue(v.conflictFiles??[],"rebase")):(Te("done",`Rebased ${u} onto ${r.label}`),Fe(),bt("Refreshing repository status...","running"),await se(),await ue(),Te("done","Repository status updated"))}}catch(v){if(Mr(v))Te("error","Uncommitted changes detected"),Gn(s),_n(N),Hn(r.label),Rr(!0);else{const B=v instanceof be?e("gitView.toast.syncActionFailed",{action:e("gitView.sync.fetch")}):v instanceof Error?v.message:s==="merge"?`Failed to merge ${r.label}`:`Failed to rebase onto ${r.label}`;Te("error",B)}}finally{l?.finish()}},[a,n,h,j,te,se,ue,Mr,Ue,Fe,bt,Te,Or,e]),ha=i.useCallback(s=>{rs("merge",s)},[rs]),ma=i.useCallback(s=>{rs("rebase",s)},[rs]),fa=i.useCallback(async()=>{if(a)try{es==="merge"?(await n.abortMerge(a),p.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(a),p.success(e("gitView.toast.rebaseAborted"))),Fe(),await se(),await ue()}catch(s){const r=s instanceof Error?s.message:`Failed to abort ${es}`;p.error(r)}},[a,n,es,se,ue,Fe,e]),ga=i.useMemo(()=>(j?.files??[]).filter(Ws).length,[j?.files]),pa=i.useCallback(async()=>{if(a)try{const s=!!j?.mergeInProgress?.head,r=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(s){const l=await n.continueMerge(a);l.conflict?(Ue(l.conflictFiles??[],"merge"),p.error(e("gitView.toast.mergeConflictsDetected"))):(Fe(),p.success(e("gitView.toast.mergeCompleted")),await se(),await ue())}else if(r){const l=await n.continueRebase(a);l.conflict?(Ue(l.conflictFiles??[],"rebase"),p.error(e("gitView.toast.rebaseConflictsDetected"))):(Fe(),p.success(e("gitView.toast.rebaseStepCompleted")),await se(),await ue())}}catch(s){const r=s instanceof Error?s.message:e("gitView.toast.continueOperationFailed");p.error(r)}},[a,n,j,se,ue,Ue,Fe,e]),xa=i.useCallback(async()=>{if(a)try{!!j?.mergeInProgress?.head?(await n.abortMerge(a),p.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(a),p.success(e("gitView.toast.rebaseAborted"))),Fe(),await se(),await ue()}catch(s){const r=s instanceof Error?s.message:e("gitView.toast.abortOperationFailed");p.error(r)}},[a,n,j,se,ue,Fe,e]),ya=i.useCallback(()=>{if(!a)return;const r=!!j?.mergeInProgress?.head?"merge":"rebase",l=(j?.files??[]).filter(Ws).map(u=>u.path);l.length>0&&Pt(l),Ft(r),wt(!0)},[a,j]),wa=i.useCallback(async s=>{if(!a)return;const r=j?.current,l=Os,u=As,N=Ts||u,v=(j?.files??[]).some(an);try{await n.stash(a,{message:`Auto-stash before ${l} with ${N}`,includeUntracked:!0}),v&&le(a)}catch(ie){const Ee=ie instanceof Error?ie.message:"Failed to stash changes";p.error(Ee);return}let B=!1,W=!1;try{if(l==="merge"){const ie=await n.merge(a,{branch:u});ie.conflict?(W=!0,Pt(ie.conflictFiles??[]),Ft("merge"),wt(!0)):(B=!0,p.success(e("gitView.toast.mergedIntoBranch",{branch:N,currentBranch:r||""})))}else{const ie=await n.rebase(a,{onto:u});ie.conflict?(W=!0,Pt(ie.conflictFiles??[]),Ft("rebase"),wt(!0)):(B=!0,p.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:r||"",branch:N})))}if(s&&B)try{await n.stashPop(a),le(a),p.success(e("gitView.toast.stashedRestored"))}catch(ie){const Ee=ie instanceof Error?ie.message:e("gitView.toast.restoreStashFailed");p.error(Ee)}else s&&W&&p.info(e("gitView.toast.restoreStashManually"));await se(),await ue()}catch(ie){if(s)try{await n.stashPop(a),le(a)}catch{}throw ie}},[le,a,n,j,Os,As,Ts,se,ue,e]),ba=i.useCallback(s=>{yn(s),a&&(De(a,s),ae(a,n,s))},[a,ae,n,De]),va=i.useCallback(s=>{Tn(s)},[]),ja=i.useCallback(()=>{Xt(null),a&&(ne(a,n),X(a,n),ae(a,n,Ie))},[a,ne,X,ae,Ie,n]),Ca=i.useCallback(s=>{if(s.conflict){if(s.operation==="cherry-pick"||s.operation==="revert"){p.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:s.conflictFiles?.join(", ")??"unknown files"})}),a&&(ne(a,n),X(a,n),ae(a,n,Ie));return}Ue(s.conflictFiles??[],s.operation)}},[e,Ue,a,ne,X,ae,Ie,n]);return y?.kind==="preparing"?t.jsx(Gi,{}):m?fn?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[xs?null:t.jsx(cs,{className:"mb-3 size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e(xs?"gitView.toast.refreshRepositoryFailed":"gitView.empty.worktreeSetupInProgress")}),xs?t.jsx(K,{type:"button",variant:"outline",size:"sm",className:"mt-3",onClick:()=>{we&&k({directory:we,status:"refreshing"})},children:e("gitView.empty.retryDiscovery")}):t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):J===null||J===!0&&!j?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(cs,{className:"size-4"}),t.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):J===!1?t.jsx(_i,{root:m,rootIsGitRepo:E,resolvedIsGitRepo:J,nestedRepos:Y,onRetryDiscovery:()=>{m&&Le(m,{force:!0})},emptyStateFooter:xe.includes("open-without-worktree-features")?t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):void 0}):t.jsxs("div",{className:fe("flex h-full flex-col overflow-hidden"),children:[t.jsx(Hi,{directory:a??"",status:j,localBranches:Mt,remoteBranches:Ot,branchInfo:c?.branches,syncAction:te.entry?.executing?cr:null,operationBlocked:te.blocked,remotes:Ve,onFetch:s=>Bt("fetch",s),onPull:s=>Bt("pull",s),onSync:s=>Bt("sync",s),onPublish:()=>{Bt("publish")},onChooseSyncTargets:()=>{Bt("sync",void 0,!0)},onRemoveRemote:Un,removingRemoteName:Dn,onCheckoutBranch:Yn,onCreateBranch:qn,onRenameBranch:Jn,activeIdentityProfile:ta,availableIdentities:ea,onSelectIdentity:Qn,isApplyingIdentity:wn,identityAttention:Qe,identityApplicability:Xe,onConfigureRepository:x.isVSCode?void 0:()=>_e(!0),onIdentityMenuOpen:()=>{Ze(h,V.map(s=>s.account))},isWorktreeMode:!!d,onOpenHistory:()=>Xt("history"),onOpenGraph:()=>Xt("graph"),onOpenStashes:oa,onOpenUpdateBranch:Br?()=>vr(!0):void 0,onOpenReintegrateCommits:rt?()=>jr(!0):void 0,pullRequest:Ce?.changeRequest??Ce?.pr??null,pullRequestProvider:Ce?.changeRequest?.provider??null,prChecks:Ce?.ci?.summary??Ce?.checks??null,onOpenPullRequest:a?()=>Je(g??a,{mode:"pr"}):void 0,repositoryOptions:q??void 0,selectedRepository:q?a:null,onSelectRepository:q&&m?s=>qe(m,s):void 0,repositoryRoot:q?m??void 0:void 0}),x.isVSCode?null:t.jsx(Yi,{open:Ye,onOpenChange:_e,directory:o?a??"":""}),t.jsx($i,{className:"mx-4 mt-3",entry:te.entry,onRefresh:()=>{te.refresh()},onCancel:()=>{te.cancel()}}),m&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&t.jsx(Qi,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:pa,onAbort:xa,onResolveWithAI:ya,conflictCount:ga,isLoading:re}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:t.jsx("div",{className:"h-full min-h-0 flex flex-col",children:t.jsx("div",{className:fe("min-w-0 min-h-0 h-full flex flex-col"),children:t.jsx(ln,{as:Si,ref:lr,outerClassName:"flex-1 min-h-0",className:fe("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:t.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(tt?.length??0)>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Xi,{groups:la,diffStats:j?.diffStats,revertingPaths:Cs,isRevertingAll:Ss,onVisiblePathsChange:gn,onRevertAll:aa,onRevertDirectory:ia,headerBackgroundClassName:"bg-background"})}),t.jsx(Zi,{stagedCount:sa,commitMessage:Rt,onCommitMessageChange:xt,generatedHighlights:Ns,onInsertHighlights:ca,onGenerateMessage:Kn,isGeneratingMessage:Sn,onCommit:()=>Ir({pushAfter:!1}),onCommitAndPush:()=>Ir({pushAfter:!0}),commitAction:ur,networkOperationBlocked:te.blocked,hasPendingIndexMutation:Nn,gitmojiEnabled:kt,onOpenGitmojiPicker:()=>ws(!0)})]}):t.jsx(go,{onOpenStashes:()=>bs(!0)})})})})})}),t.jsx(ht,{open:Pn,onOpenChange:s=>{!s&&Sr!==null||vr(s)},children:t.jsxs(mt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(gt,{children:e("gitView.branch.updateTitle")}),t.jsxs(jt,{children:[e("gitView.branch.updateDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:j?.current??""}),"."]})]}),Br?t.jsx(Po,{mode:"bare",currentBranch:j?.current,localBranches:Mt,remoteBranches:Xn,defaultTargetBranch:Zn,onMerge:ha,onRebase:ma,disabled:ra||te.blocked,isOperating:Sr!==null,operationLogs:Bn,onOperationComplete:da}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),t.jsx(ht,{open:Fn,onOpenChange:jr,children:t.jsxs(mt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(gt,{children:e("gitView.integrate.title")}),t.jsx(jt,{children:rt?t.jsxs("span",{className:"font-mono text-foreground",children:[rt.sourceBranch," → ",yr]}):null})]}),rt?t.jsx(mo,{repoRoot:rt.repoRoot,sourceBranch:rt.sourceBranch,worktreeMetadata:rt.worktreeMetadata,localBranches:Mt,defaultTargetBranch:yr,refreshKey:jn,showHeader:!1,onRefresh:()=>{a&&(ne(a,n),X(a,n),ae(a,n,Ie))}},rt.worktreeMetadata.path):null]})}),t.jsx(ht,{open:ge!==null,onOpenChange:s=>{s||Xt(null)},children:t.jsxs(mt,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(gt,{children:e(ge==="graph"?"gitView.graph.title":"gitView.history.title")}),t.jsxs(K,{type:"button",variant:"ghost",size:"sm",className:"me-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(ge==="graph"){Ln(s=>s+1);return}a&&ae(a,n,Ie)},disabled:ge==="graph"?Bs:de,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[t.jsx(_,{name:"refresh",className:fe("size-4",(ge==="graph"?Bs:de)&&"animate-spin")}),e("gitView.history.refresh")]})]}),t.jsx(jt,{children:e("gitView.history.dialogDescription")})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(So,{mode:ge==="graph"?"graph":"history",log:ge==="graph"?An??I:I,isLogLoading:ge==="graph"&&Bs||de,logMaxCount:ge==="graph"?Ms:Ie,onLogMaxCountChange:ge==="graph"?va:ba,expandedCommitHashes:Is,onToggleCommit:Wn,commitFilesMap:Yt,loadingCommitHashes:Qt,onCopyHash:$n,directory:a??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ge==="graph"?null:In,onConflict:ge==="graph"?Ca:void 0,onActionSuccess:ge==="graph"?ja:void 0})})]})}),t.jsx(fo,{open:xn,onOpenChange:bs,directory:a,hasUncommittedChanges:(j?.files?.length??0)>0,hasStagedChanges:Ne.length>0,uncommittedFileCount:j?.files?.length??0,onChanged:async s=>{a&&s?.affectsIndex&&le(a),await se(!1),await ue()}}),t.jsx(ht,{open:pn,onOpenChange:ws,children:t.jsxs(mt,{className:"max-w-md p-0 overflow-hidden",children:[t.jsx(ft,{className:"px-4 pt-4",children:t.jsx(gt,{children:e("gitView.gitmoji.title")})}),t.jsxs(Xs,{className:"h-[420px]",shouldFilter:!1,children:[t.jsx(Zs,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:wr,onValueChange:br}),t.jsxs(er,{children:[t.jsx(tr,{children:e("gitView.gitmoji.empty")}),t.jsx(os,{children:_t(pt,wr,s=>[s.code,s.description,s.emoji]).map(s=>t.jsxs(ls,{onSelect:()=>ua(s.emoji,s.code),children:[t.jsx("span",{className:"text-lg",children:s.emoji}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s.code}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s.description})]},s.code))})]})]})]})}),U.context?t.jsx(Wi,{context:U.context,onSelect:U.settle}):null,U.confirmDialog,t.jsx(Ui,{candidates:f.candidates,onSelect:f.settle}),a&&t.jsx(eo,{open:Mn,onOpenChange:wt,conflictFiles:On,directory:a,operation:es,onAbort:fa,onClearState:Fe}),t.jsx(to,{open:ts!==null,onOpenChange:s=>{s||Dt(null)},targetBranch:ts??"",changedFileCount:j?.files?.length??0,onCommitAndSwitch:async(s,r)=>{const l=ts;if(!l||!a)return;const u=j?.current??null;await n.createGitCommit(a,s,{addAll:!0}),le(a);let N=null;if(r){const v=$.read?.repository.remotes.map(W=>W.name)??Ve.map(W=>W.name),B=u?Ho(u,j?.tracking,v,$.contexts[0]?.primaryRemote??v[0]??null):null;try{if(!B||!u)throw new Error(e("mobile.changes.noRemote"));await Ni({directory:a,branch:u,remoteName:B.remoteName,sourceControl:h,git:n,choose:f.choose,destinationRef:B.destinationRef}),N=B.remoteName}catch(W){console.error("Push after commit failed:",W),p.error(e("gitView.dirtySwitch.pushFailed")),await se(),await ue(),Dt(null);return}}p.success(N?e("gitView.toast.pushedToUpstream",{name:N}):u?e("gitView.dirtySwitch.committedNotPushed",{branch:u}):e("gitView.toast.commitCreated")),await se(),await ue(),Dt(null),await Gs(l)},onGenerateMessage:async()=>{if(!a)return"";const s=(j?.files??[]).map(u=>u.path).sort(),{message:r}=await Hr(a,s),l=r.subject?.trim()??"";if(l&&kt&&pt.length>0){const u=nn(l,pt);if(u&&!l.startsWith(u.code)&&!l.startsWith(u.emoji))return`${u.code} ${l}`}return l},onRevertAndSwitch:async()=>{const s=ts;if(!s||!a)return;const r=(j?.files??[]).map(u=>u.path);await Tt(r,!0,"all");const l=await n.getGitStatus(a);if(!l.isClean&&(l.files?.length??0)>0){p.error(e("gitView.dirtySwitch.revertIncomplete"));return}Dt(null),await Gs(s)}}),t.jsx(Io,{open:zn,onOpenChange:Rr,operation:Os,targetBranch:Ts||As,onConfirm:wa})]}):t.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})};export{hu as GitView};