@pi-chamber/web 0.9.9-rc.3 → 1.0.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 (46) hide show
  1. package/README.md +70 -67
  2. package/dist/assets/{DiagramView-Dy4F1cil.js → DiagramView-CbSxUe1D.js} +1 -1
  3. package/dist/assets/{DiffView-C76KYB1I.js → DiffView-VyBf4ilo.js} +1 -1
  4. package/dist/assets/{FileSaveConflictDialog-C-TUbGz7.js → FileSaveConflictDialog-BCvbQ234.js} +1 -1
  5. package/dist/assets/{FilesView-D05cD0Vv.js → FilesView-DasA5EU2.js} +1 -1
  6. package/dist/assets/{GitView-BrSR7uJk.js → GitView-DU3mOECp.js} +3 -3
  7. package/dist/assets/{JsonTreeView-Ds6UD-nj.js → JsonTreeView-xZiWDwua.js} +1 -1
  8. package/dist/assets/{MarkdownRendererImpl-D_ClsZYB.js → MarkdownRendererImpl-BBwdI2OF.js} +2 -2
  9. package/dist/assets/{PatchDiff-DaZ-PTug.js → PatchDiff-BhKm_JPT.js} +1 -1
  10. package/dist/assets/{SessionSwitcherContent-FaYzgplj.js → SessionSwitcherContent-DTGSP_RB.js} +1 -1
  11. package/dist/assets/{SessionSwitcherDropdown-D_9pieby.js → SessionSwitcherDropdown-CedOB-xC.js} +2 -2
  12. package/dist/assets/{SessionUnreadDot-DGuqqVhb.js → SessionUnreadDot-CZSNKram.js} +1 -1
  13. package/dist/assets/SettingsView-B5nmu8x4.js +2 -0
  14. package/dist/assets/{SettingsWindow-Dpw6aF2F.js → SettingsWindow-y33YrpBE.js} +1 -1
  15. package/dist/assets/{ToolOutputDialog-CcbJkYYg.js → ToolOutputDialog-JqIXJWAH.js} +3 -3
  16. package/dist/assets/{ToolPartDiffPreview-C0c8f4Nt.js → ToolPartDiffPreview-CRi_33jE.js} +1 -1
  17. package/dist/assets/{VirtualizedFileDiff-BvU0E4qX.js → VirtualizedFileDiff-ehLQSR5W.js} +4 -4
  18. package/dist/assets/{collapsible-B6bVtxgp.js → collapsible-Vypq-nMP.js} +1 -1
  19. package/dist/assets/{computeVirtualFileMetrics-hWwF-t_o.js → computeVirtualFileMetrics-BTfrj_fR.js} +2 -2
  20. package/dist/assets/{contextFileOpenGuard-Y5Z8LQyY.js → contextFileOpenGuard-Dl6mFfD1.js} +1 -1
  21. package/dist/assets/{gitStatusPredicates-Dmaw5g31.js → gitStatusPredicates-LAsJAhCL.js} +1 -1
  22. package/dist/assets/{index-BXgR2dKM.css → index-BXX8l7mM.css} +1 -1
  23. package/dist/assets/{index-BOtRfXre.js → index-DvNeSFO9.js} +1 -1
  24. package/dist/assets/{index-CqdQEvR2.js → index-OveFsNBm.js} +1 -1
  25. package/dist/assets/{isDiffPlainText-C1dRfEBh.js → isDiffPlainText-CNZohQ4q.js} +1 -1
  26. package/dist/assets/{isFilePlainText-wlC41gsX.js → isFilePlainText-Dz8UubRT.js} +1 -1
  27. package/dist/assets/{main-CkViwsz_.js → main-BsDkATRV.js} +3 -3
  28. package/dist/assets/{main-CfNlfHvj.js → main-C393Ywhx.js} +2 -2
  29. package/dist/assets/{markdownCore-Ci_ipXBM.js → markdownCore-Bz9-Y75q.js} +1 -1
  30. package/dist/assets/{miniChat-BFzjOj9l.js → miniChat-CWEerp3c.js} +2 -2
  31. package/dist/assets/{mobile-D4xKl_yN.js → mobile-YxV9KcxF.js} +2 -2
  32. package/dist/assets/{renderElectronMiniChatApp-BQBx6mC4.js → renderElectronMiniChatApp-GrLmBQRb.js} +2 -2
  33. package/dist/assets/{renderMobileApp-D1Q-yGOv.js → renderMobileApp-C29wquBe.js} +3 -3
  34. package/dist/assets/{runtimeEndpointReset-Co9SkOQC.js → runtimeEndpointReset-DHARMv9w.js} +14 -14
  35. package/dist/assets/{runtimeSurface-CPm7KWaN.js → runtimeSurface-DUXw4-oa.js} +1 -1
  36. package/dist/assets/{useAppFontEffects-D00QsL7D.js → useAppFontEffects-ad-lZJ6o.js} +86 -86
  37. package/dist/assets/{useFilesViewSearch-BsC82OOk.js → useFilesViewSearch-C4oOHPml.js} +1 -1
  38. package/dist/assets/{usePushVisibilityBeacon-Pg0Sln_M.js → usePushVisibilityBeacon-xd8Q10cI.js} +1 -1
  39. package/dist/assets/{useSwitcherItems-BXn8MrAT.js → useSwitcherItems-B6VC7tug.js} +1 -1
  40. package/dist/assets/{vendor-codemirror-language-data-DhJ96dYN.js → vendor-codemirror-language-data-B4j3gkaT.js} +2 -2
  41. package/dist/assets/{web-components-Bb-NxfNy.js → web-components-B0RFakat.js} +3 -3
  42. package/dist/index.html +4 -4
  43. package/dist/mini-chat.html +3 -3
  44. package/dist/mobile.html +3 -3
  45. package/package.json +1 -1
  46. package/dist/assets/SettingsView-C-YJztlm.js +0 -2
@@ -1,8 +1,8 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-C76KYB1I.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-BOtRfXre.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-BXgR2dKM.css","assets/useAppFontEffects-D00QsL7D.js","assets/vendor-base-ui-DXSHfszQ.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-CPm7KWaN.js","assets/vendor-dnd-kit-core-C9qcAm_1.js","assets/vendor-dnd-kit-utilities-DTY1C6ST.js","assets/vendor-dnd-kit-accessibility-DZKKhs9S.js","assets/vendor-dnd-kit-sortable-D8ozj8M-.js","assets/vendor-cmdk-zXx6sGnS.js","assets/vendor-radix-ui-react-dialog-D2yhEu2p.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js","assets/vendor-radix-ui-react-context-CFsX-AUC.js","assets/vendor-radix-ui-react-id-D2kS9K1j.js","assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js","assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js","assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js","assets/vendor-radix-ui-react-primitive-DkH8dMOR.js","assets/vendor-radix-ui-react-slot-BIDFZX0-.js","assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js","assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js","assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js","assets/vendor-radix-ui-react-portal-YgCRIyi7.js","assets/vendor-radix-ui-react-presence-D432pCMB.js","assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js","assets/vendor-react-remove-scroll-vR1dy1aP.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-CSAHp1YF.js","assets/vendor-react-style-singleton-Ctw6HnYx.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-Vv4V8Nd1.js","assets/vendor-use-callback-ref-CVVuCyLj.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BByA_dGF.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-wd6iRebq.js","assets/vendor-codemirror-lang-json-CZ07HmNC.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-djiuoTi8.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CKHqhW5R.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-DtcZDGqe.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-DhJ96dYN.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-CNlncqrr.js","assets/vendor-tanstack-react-virtual-2skouoFw.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CfplGuM0.js","assets/vendor-motion-dom-DhJ-sYS5.js","assets/vendor-motion-utils-CKEGc_YG.js","assets/gitStatusPredicates-Dmaw5g31.js","assets/web-components-Bb-NxfNy.js","assets/computeVirtualFileMetrics-hWwF-t_o.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-yJ9XpNMI.js","assets/vendor-pierre-theming-Dgp7B_O4.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-BvU0E4qX.js","assets/isDiffPlainText-C1dRfEBh.js","assets/vendor-diff-C3JhlQdm.js","assets/runtimeEndpointReset-Co9SkOQC.js","assets/SessionUnreadDot-DGuqqVhb.js","assets/vendor-xterm-xterm-CrXqRur4.js","assets/vendor-xterm-xterm-DDGTF8rc.css","assets/permissionStore-iKN1K2_x.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/contextFileOpenGuard-Y5Z8LQyY.js"])))=>i.map(i=>d[i]);
2
- import{_ as vs}from"./vendor-vite-runtime-DD1OZmLC.js";import{R as a,j as e,r as it,b as Aa}from"./vendor-react-B5Z1Mdn3.js";import{a1 as He,a2 as we,a3 as Ne,a4 as Ue,B as _,I as w,a5 as Ce,a6 as Ve,aI as ws,aJ as Ns,aK as Cs,aL as Ss,aM as Oe,aN as De,cf as Dt,a8 as pe,a9 as Ba,aa as ut,e as Lt,_ as rs,af as Fe,ag as ze,ah as Ie,ai as $e,aj as Me,t as R,c5 as ks,ar as Ta,ae as Ga,cg as Oa,ch as _a,ci as Ha,cj as Ua,ck as Va,aY as Wa,ak as _e,ad as is,b7 as Ka,Z as qa,a7 as Ya,a0 as Za,c3 as Rs,cl as Ja,as as Es,c6 as Qa,ab as Xa,at as en,ac as tn,cm as sn,cn as an,co as nn,cp as rn,cq as on,ax as ln,aF as cn}from"./useAppFontEffects-D00QsL7D.js";import{K as dn,L as un,N as hn}from"./runtimeEndpointReset-Co9SkOQC.js";import{u as os}from"./vendor-zustand-GVb4H8HE.js";import{o as te,u as Pt,bY as mn,B as ot}from"./index-BOtRfXre.js";import{C as fn,P as Fs,d as pn,i as ls,a as gn}from"./gitStatusPredicates-Dmaw5g31.js";import{C as xn,a as bn,b as yn}from"./collapsible-B6bVtxgp.js";import{u as jn}from"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-DXSHfszQ.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./runtimeSurface-CPm7KWaN.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DhJ96dYN.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./SessionUnreadDot-DGuqqVhb.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./web-components-Bb-NxfNy.js";import"./computeVirtualFileMetrics-hWwF-t_o.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-BvU0E4qX.js";import"./isDiffPlainText-C1dRfEBh.js";import"./vendor-diff-C3JhlQdm.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";const vn=n=>n.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),wn=({currentBranch:n,localBranches:r,remoteBranches:c,branchInfo:m,onCheckout:h,onCreate:s,remotes:t=[],disabled:g=!1})=>{const[u,y]=a.useState(!1),[C,S]=a.useState(""),[v,f]=a.useState(!1),[l,d]=a.useState(!1),[E,k]=a.useState(""),[$,T]=a.useState(!1),H=a.useRef(null),A=a.useCallback(I=>{I.stopPropagation()},[]),L=t.length>1,M=a.useMemo(()=>vn(E),[E]),z=a.useMemo(()=>{const I=C.toLowerCase();return I?r.filter(X=>X.toLowerCase().includes(I)):r},[C,r]),G=a.useMemo(()=>{const I=C.toLowerCase();return I?c.filter(X=>X.toLowerCase().includes(I)):c},[C,c]),x=I=>{if(I===n){y(!1);return}h(I),y(!1),S("")},B=()=>{f(!0),setTimeout(()=>H.current?.focus(),50)},q=async()=>{if(!(!M||$)){if(L){d(!0);return}T(!0);try{await s(M,t[0]),k(""),f(!1),y(!1)}finally{T(!1)}}},Q=async I=>{if(!(!M||$)){T(!0);try{await s(M,I),k(""),f(!1),d(!1),y(!1)}finally{T(!1)}}},U=()=>{d(!1)},W=()=>{k(""),f(!1),d(!1)};return a.useEffect(()=>{u||(S(""),f(!1),d(!1),k(""))},[u]),e.jsxs(He,{open:u,onOpenChange:y,children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx(Ue,{asChild:!0,children:e.jsxs(_,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:g,children:[e.jsx(w,{name:"git-branch",className:"size-4 text-primary"}),e.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:n||"Detached HEAD"}),e.jsx(w,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),e.jsx(Ce,{sideOffset:8,children:"Current branch"})]}),e.jsx(Ve,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:e.jsxs(ws,{className:"h-full min-h-0",children:[e.jsx(Ns,{placeholder:"Search branches...",value:C,onValueChange:S,onKeyDown:A}),e.jsxs(Cs,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[e.jsx(Ss,{children:"No branches found."}),e.jsx(Oe,{children:l?e.jsxs("div",{className:"px-2 py-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("button",{type:"button",onClick:U,disabled:$,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:e.jsx(w,{name:"arrow-left",className:"size-4"})}),e.jsxs("span",{className:"typography-meta text-muted-foreground",children:["Push To Prefix"," ",e.jsx("span",{className:"text-foreground font-medium",children:M})," ","Push To Suffix"]})]}),e.jsx("div",{className:"flex flex-col gap-1",children:t.map(I=>e.jsxs("button",{type:"button",onClick:()=>Q(I),disabled:$,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[e.jsxs("span",{className:"typography-ui-label text-foreground",children:[$?e.jsx(w,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,I.name]}),e.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:I.pushUrl})]},I.name))})]}):v?e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[e.jsx("input",{ref:H,placeholder:"New branch name",value:E,onChange:I=>k(I.target.value),onClick:I=>I.stopPropagation(),onKeyDown:I=>{A(I),I.key==="Enter"?(I.preventDefault(),q()):I.key==="Escape"&&(I.preventDefault(),W())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),e.jsx("button",{type:"button",onClick:q,disabled:!M||$,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:$?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"add",className:"size-4"})}),e.jsx("button",{type:"button",onClick:W,disabled:$,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:e.jsx(w,{name:"close",className:"size-4"})})]}):e.jsxs(De,{onSelect:B,children:[e.jsx(w,{name:"add",className:"size-4"}),e.jsx("span",{children:"Create new branch..."})]})}),e.jsx(Dt,{}),e.jsxs(Oe,{heading:"Local branches",children:[z.map(I=>e.jsxs(De,{onSelect:()=>x(I),children:[e.jsxs("span",{className:"flex flex-1 flex-col",children:[e.jsx("span",{className:"typography-ui-label text-foreground",children:I}),(m?.[I]?.ahead||m?.[I]?.behind)&&e.jsxs("span",{className:"typography-micro text-muted-foreground",children:[m[I].ahead||0," ahead ·"," ",m[I].behind||0," behind"]})]}),n===I&&e.jsx("span",{className:"typography-micro text-primary",children:"Current"})]},`local-${I}`)),z.length===0&&e.jsx(De,{disabled:!0,className:"justify-center",children:e.jsx("span",{className:"typography-meta text-muted-foreground",children:"No local branches"})})]}),e.jsx(Dt,{}),e.jsxs(Oe,{heading:"Remote branches",children:[G.map(I=>e.jsx(De,{onSelect:()=>x(I),children:e.jsx("span",{className:"typography-ui-label text-foreground",children:I})},`remote-${I}`)),G.length===0&&e.jsx(De,{disabled:!0,className:"justify-center",children:e.jsx("span",{className:"typography-meta text-muted-foreground",children:"No remote branches"})})]})]})]})})]})},Nn=n=>n.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Cn=({currentBranch:n,onRename:r,showEditButton:c=!0})=>{const[m,h]=a.useState(!1),[s,t]=a.useState(n||""),[g,u]=a.useState(!1),y=a.useRef(null),C=()=>{!n||!r||(t(n),h(!0),setTimeout(()=>y.current?.focus(),0))},S=async()=>{if(!n||!r||!s.trim())return;const l=Nn(s);if(l===n){h(!1);return}u(!0);try{await r(n,l),h(!1),t("")}finally{u(!1)}},v=()=>{h(!1),t("")},f=l=>{l.key==="Enter"?(l.preventDefault(),S()):l.key==="Escape"&&(l.preventDefault(),v())};return m?e.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:e.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:l=>{l.preventDefault(),S()},children:[e.jsx(w,{name:"git-branch",className:"size-4 text-primary"}),e.jsx("input",{ref:y,value:s,onChange:l=>t(l.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:"Branch name",onKeyDown:f,autoFocus:!0}),e.jsx("button",{type:"submit",disabled:g,"aria-label":g?"Saving branch name":"Save branch name",title:g?"Saving branch name":"Save branch name",className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:g?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"check",className:"size-4"})}),e.jsx("button",{type:"button",onClick:v,disabled:g,"aria-label":"Cancel branch rename",title:"Cancel branch rename",className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:e.jsx(w,{name:"close",className:"size-4"})})]})}):e.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[e.jsx(w,{name:"git-branch",className:"size-4 text-primary shrink-0"}),e.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[e.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:n||"Detached HEAD"}),c&&r&&n&&e.jsx(_,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:C,title:"Rename branch",children:e.jsx(w,{name:"edit",className:"size-4"})})]})]})},zs=({syncAction:n,remotes:r=[],onFetch:c,onSync:m,onRemoveRemote:h,disabled:s,removingRemoteName:t=null,aheadCount:g=0,behindCount:u=0,trackingRemoteName:y,hasUncommittedChanges:C=!1,iconOnly:S=!1,upstreamTarget:v=null})=>{const f=a.useRef(!1),l=!!t,d=r.find(M=>M.name===y)??r[0],E=u>0&&C,k=s||n!==null||l||!d||E,$=s||n!==null||l||r.length===0,T=g>0||u>0,H=["sync",u>0?`↓${u}`:null,g>0?`↑${g}`:null].filter(Boolean).join(" "),A=E?"Commit or stash your changes before syncing":d?[T?`Sync Changes (${u} down, ${g} up)`:"Sync Changes",v?`Compared with ${v}`:null].filter(Boolean).join(". "):"No remotes configured",L=()=>{d&&m(d)};return e.jsxs("div",{className:"inline-flex items-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] border border-border/60 bg-[var(--surface-elevated)] overflow-hidden",children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("span",{className:"inline-flex",tabIndex:E?0:void 0,children:e.jsxs("button",{type:"button",onClick:L,disabled:k,className:te("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),"aria-label":"Sync Changes",children:[n==="sync"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"refresh",className:"size-4"}),S?T?e.jsx("span",{className:"whitespace-nowrap tabular-nums",children:[u>0?`↓${u}`:null,g>0?`↑${g}`:null].filter(Boolean).join(" ")}):null:e.jsx("span",{className:"whitespace-nowrap tabular-nums",children:H})]})})}),e.jsx(Ce,{sideOffset:8,children:A})]}),e.jsxs(He,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx("button",{type:"button",className:te("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),disabled:$,"aria-label":"More sync actions",children:e.jsx(w,{name:"arrow-down-s",className:"size-4"})})}),e.jsx(Ve,{align:"start",alignOffset:-40,className:"w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",children:r.map(M=>e.jsx(pe,{onSelect:z=>{if(f.current){z.preventDefault(),f.current=!1;return}c(M)},children:e.jsxs("div",{className:"flex w-full items-center gap-2",children:[e.jsx(w,{name:"refresh",className:"size-4 text-muted-foreground"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"typography-ui-label text-foreground",children:`Fetch from ${M.name}`}),e.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:M.fetchUrl})]})}),h&&M.name!==y?e.jsx(_,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||l,onPointerDown:z=>{f.current=!0,z.preventDefault(),z.stopPropagation()},onClick:z=>{f.current=!0,z.preventDefault(),z.stopPropagation(),h(M)},"aria-label":`Remove remote ${M.name}`,title:`Remove remote ${M.name}`,children:t===M.name?e.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin"}):e.jsx(w,{name:"close",className:"size-3.5"})}):null]})},M.name))})]})]})},Sn=({status:n,localBranches:r,remoteBranches:c,branchInfo:m,syncAction:h,remotes:s,onFetch:t,onSync:g,onRemoveRemote:u,removingRemoteName:y,onCheckoutBranch:C,onCreateBranch:S,onRenameBranch:v,activeIdentityProfile:f,availableIdentities:l,onSelectIdentity:d,isApplyingIdentity:E,isWorktreeMode:k,upstreamTarget:$,onOpenHistory:T,onOpenGraph:H,onOpenStashes:A,onOpenUpdateBranch:L,onOpenReintegrateCommits:M,diffScope:z,onDiffScopeChange:G,allCount:x,workingCount:B,stagedCount:q,branchAvailable:Q,diffHeaderState:U})=>{const W=T||H||A||L||M,I=(U?.totalCount??0)>0,X=z!=="turn"&&z!=="branch",ne=W||U!==null;return e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:[e.jsx("div",{className:"min-w-0 flex-shrink",children:k?e.jsx(Cn,{currentBranch:n.current,onRename:v}):e.jsx(wn,{currentBranch:n.current,localBranches:r,remoteBranches:c,branchInfo:m,onCheckout:C,onCreate:S,remotes:s})}),e.jsx("div",{className:"shrink-0",children:e.jsx(dn,{activeProfile:f,identities:l,onSelect:d,isApplying:E,iconOnly:!0})}),e.jsx("div",{className:"min-w-0 shrink-0",children:e.jsx(fn,{scope:z,isGitRepo:!0,branchAvailable:Q,allCount:x,workingCount:B,stagedCount:q,turnCount:U?.turnCount??0,branchCount:U?.branchCount??0,onScopeChange:G})}),e.jsx("div",{className:"min-w-0 flex-1"}),e.jsx("div",{className:"shrink-0",children:e.jsx(zs,{syncAction:h,remotes:s,onFetch:t,onSync:g,onRemoveRemote:u,removingRemoteName:y,disabled:!n,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:n.tracking?.split("/")[0],hasUncommittedChanges:(n.files?.length??0)>0,upstreamTarget:$})}),ne?e.jsx("div",{className:"shrink-0",children:e.jsxs(He,{children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx(Ue,{asChild:!0,children:e.jsx(_,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":"Repository views",children:e.jsx(w,{name:"more-fill",className:"size-4"})})})}),e.jsx(Ce,{sideOffset:8,children:"Repository views"})]}),e.jsxs(Ve,{align:"end",children:[T?e.jsxs(pe,{onSelect:T,children:[e.jsx(w,{name:"history",className:"size-4"}),"History"]}):null,H?e.jsxs(pe,{onSelect:H,children:[e.jsx(w,{name:"git-branch",className:"size-4"}),"Graph"]}):null,A?e.jsxs(pe,{onSelect:A,children:[e.jsx(w,{name:"archive-stack",className:"size-4"}),"Stashes"]}):null,L?e.jsxs(pe,{onSelect:L,children:[e.jsx(w,{name:"git-merge",className:"size-4"}),"Update branch"]}):null,M?e.jsxs(pe,{onSelect:M,children:[e.jsx(w,{name:"split-cells-horizontal",className:"size-4"}),"Re-integrate commits"]}):null,W&&U!==null?e.jsx(Ba,{}):null,U!==null?e.jsxs(pe,{disabled:!I,onSelect:U.onExpandOrCollapseAll,children:[e.jsx(w,{name:"expand-up-down",className:"size-4"}),U.expandedCount>0?"Collapse all":"Expand all"]}):null,U!==null?e.jsxs(pe,{disabled:!I||!X,onSelect:U.onToggleLoadFullFiles,children:[e.jsx(w,{name:"file-download",className:"size-4"}),e.jsx("span",{className:"flex-1",children:"Load full files"}),U.loadFullFiles?e.jsx(w,{name:"check",className:"size-4"}):null]}):null,U!==null?e.jsxs(pe,{disabled:!I,onSelect:U.onToggleWrapLines,children:[e.jsx(w,{name:"text-wrap",className:"size-4"}),e.jsx("span",{className:"flex-1",children:"Wrap lines"}),U.wrapLines?e.jsx(w,{name:"check",className:"size-4"}):null]}):null,U!==null?e.jsxs(pe,{disabled:U.layoutMode===null,onSelect:U.onToggleLayout,children:[e.jsx(w,{name:U.layoutMode==="side-by-side"?"layout-column":"align-justify",className:"size-4"}),U.layoutMode==="side-by-side"?"Switch to unified view":"Switch to side-by-side view"]}):null]})]})}):null]})},kn=({open:n,onOpenChange:r,conflictFiles:c=[],directory:m,operation:h,onAbort:s,onClearState:t})=>{const{git:g}=ut(),u=Lt(x=>x.openNewSessionDraft),y=Lt(x=>x.currentSessionId),C=rs(x=>x.setPendingInputText),S=rs(x=>x.setPendingSyntheticParts),v=Pt(x=>x.setActiveMainTab),[f,l]=a.useState(!1),[d,E]=a.useState(null),[k,$]=a.useState(null);a.useEffect(()=>{!n||!m||(l(!0),$(null),E(null),g.getConflictDetails(m).then(x=>{E(x)}).catch(x=>{const B=x instanceof Error?x.message:"Failed to load conflict details";$(B)}).finally(()=>{l(!1)}))},[m,g,n]);const T=a.useCallback(async()=>{if(!d)return null;const x=h==="merge"?"merge":"rebase",B=d.headInfo||(h==="merge"?"MERGE_HEAD":"REBASE_HEAD"),q=h==="merge"?"git commit --no-edit":"git rebase --continue",Q=`Investigate the ${x} conflicts and concisely report the intended resolution strategy without making modifications. Wait for confirmation before resolving, staging, or continuing the ${x}. Preserve the intent of changes from ${B}.`,U=`Git ${x} operation is in progress with conflicts.
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiffView-VyBf4ilo.js","assets/vendor-react-B5Z1Mdn3.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-DvNeSFO9.js","assets/vendor-zustand-GVb4H8HE.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-BXX8l7mM.css","assets/useAppFontEffects-ad-lZJ6o.js","assets/vendor-base-ui-DXSHfszQ.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-BZOGXAGe.js","assets/vendor-use-sync-external-store-D0AXkdQC.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-sonner-BDtm25td.js","assets/vendor-codemirror-view-Ct4T37Ue.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/runtimeSurface-DUXw4-oa.js","assets/vendor-dnd-kit-core-C9qcAm_1.js","assets/vendor-dnd-kit-utilities-DTY1C6ST.js","assets/vendor-dnd-kit-accessibility-DZKKhs9S.js","assets/vendor-dnd-kit-sortable-D8ozj8M-.js","assets/vendor-cmdk-zXx6sGnS.js","assets/vendor-radix-ui-react-dialog-D2yhEu2p.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js","assets/vendor-radix-ui-react-context-CFsX-AUC.js","assets/vendor-radix-ui-react-id-D2kS9K1j.js","assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js","assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js","assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js","assets/vendor-radix-ui-react-primitive-DkH8dMOR.js","assets/vendor-radix-ui-react-slot-BIDFZX0-.js","assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js","assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js","assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js","assets/vendor-radix-ui-react-portal-YgCRIyi7.js","assets/vendor-radix-ui-react-presence-D432pCMB.js","assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js","assets/vendor-react-remove-scroll-vR1dy1aP.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-CSAHp1YF.js","assets/vendor-react-style-singleton-Ctw6HnYx.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-Vv4V8Nd1.js","assets/vendor-use-callback-ref-CVVuCyLj.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BByA_dGF.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-wd6iRebq.js","assets/vendor-codemirror-lang-json-CZ07HmNC.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-djiuoTi8.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CKHqhW5R.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-DtcZDGqe.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-B4j3gkaT.js","assets/vendor-codemirror-lang-python-DzzokVau.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-CNlncqrr.js","assets/vendor-tanstack-react-virtual-2skouoFw.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CfplGuM0.js","assets/vendor-motion-dom-DhJ-sYS5.js","assets/vendor-motion-utils-CKEGc_YG.js","assets/gitStatusPredicates-LAsJAhCL.js","assets/web-components-B0RFakat.js","assets/computeVirtualFileMetrics-BTfrj_fR.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-yJ9XpNMI.js","assets/vendor-pierre-theming-Dgp7B_O4.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-ehLQSR5W.js","assets/isDiffPlainText-CNZohQ4q.js","assets/vendor-diff-C3JhlQdm.js","assets/runtimeEndpointReset-DHARMv9w.js","assets/SessionUnreadDot-CZSNKram.js","assets/vendor-xterm-xterm-CrXqRur4.js","assets/vendor-xterm-xterm-DDGTF8rc.css","assets/permissionStore-iKN1K2_x.js","assets/runtimeEndpointReset-BV3KOtdA.css","assets/appThemeRegistry-gegrE2dq.js","assets/registerCustomTheme-DmolaWWZ.js","assets/contextFileOpenGuard-Dl6mFfD1.js"])))=>i.map(i=>d[i]);
2
+ import{_ as vs}from"./vendor-vite-runtime-DD1OZmLC.js";import{R as a,j as e,r as it,b as Aa}from"./vendor-react-B5Z1Mdn3.js";import{a2 as He,a3 as we,a4 as Ne,a5 as Ue,B as _,I as w,a6 as Ce,a7 as Ve,aJ as ws,aK as Ns,aL as Cs,aM as Ss,aN as Oe,aO as De,cg as Dt,a9 as pe,aa as Ba,ab as ut,f as Lt,$ as rs,ag as Fe,ah as ze,ai as $e,aj as Ie,ak as Me,t as R,c6 as ks,as as Ta,af as Ga,ch as Oa,ci as _a,cj as Ha,ck as Ua,cl as Va,aZ as Wa,al as _e,ae as is,b8 as Ka,_ as qa,a8 as Ya,a1 as Za,c4 as Rs,cm as Ja,at as Es,c7 as Qa,ac as Xa,au as en,ad as tn,cn as sn,co as an,cp as nn,cq as rn,cr as on,ay as ln,aG as cn}from"./useAppFontEffects-ad-lZJ6o.js";import{J as dn,K as un,L as hn}from"./runtimeEndpointReset-DHARMv9w.js";import{u as os}from"./vendor-zustand-GVb4H8HE.js";import{o as te,u as Pt,bZ as mn,B as ot}from"./index-DvNeSFO9.js";import{C as fn,P as Fs,d as pn,i as ls,a as gn}from"./gitStatusPredicates-LAsJAhCL.js";import{C as xn,a as bn,b as yn}from"./collapsible-Vypq-nMP.js";import{u as jn}from"./vendor-tanstack-react-virtual-2skouoFw.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-base-ui-DXSHfszQ.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-BZOGXAGe.js";import"./vendor-use-sync-external-store-D0AXkdQC.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-sonner-BDtm25td.js";import"./vendor-codemirror-view-Ct4T37Ue.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./runtimeSurface-DUXw4-oa.js";import"./vendor-dnd-kit-core-C9qcAm_1.js";import"./vendor-dnd-kit-utilities-DTY1C6ST.js";import"./vendor-dnd-kit-accessibility-DZKKhs9S.js";import"./vendor-dnd-kit-sortable-D8ozj8M-.js";import"./vendor-cmdk-zXx6sGnS.js";import"./vendor-radix-ui-react-dialog-D2yhEu2p.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-8xy6TJML.js";import"./vendor-radix-ui-react-context-CFsX-AUC.js";import"./vendor-radix-ui-react-id-D2kS9K1j.js";import"./vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js";import"./vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js";import"./vendor-radix-ui-react-dismissable-layer-DrorBNg9.js";import"./vendor-radix-ui-react-primitive-DkH8dMOR.js";import"./vendor-radix-ui-react-slot-BIDFZX0-.js";import"./vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js";import"./vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js";import"./vendor-radix-ui-react-focus-scope-D2BkImwt.js";import"./vendor-radix-ui-react-portal-YgCRIyi7.js";import"./vendor-radix-ui-react-presence-D432pCMB.js";import"./vendor-radix-ui-react-focus-guards-BfdFmL7c.js";import"./vendor-react-remove-scroll-vR1dy1aP.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-CSAHp1YF.js";import"./vendor-react-style-singleton-Ctw6HnYx.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-Vv4V8Nd1.js";import"./vendor-use-callback-ref-CVVuCyLj.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BByA_dGF.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-DuOEwJ3f.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-wd6iRebq.js";import"./vendor-codemirror-lang-json-CZ07HmNC.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-djiuoTi8.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CKHqhW5R.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-DtcZDGqe.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-B4j3gkaT.js";import"./vendor-codemirror-lang-python-DzzokVau.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-CNlncqrr.js";import"./vendor-framer-motion-CfplGuM0.js";import"./vendor-motion-dom-DhJ-sYS5.js";import"./vendor-motion-utils-CKEGc_YG.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./SessionUnreadDot-CZSNKram.js";import"./vendor-xterm-xterm-CrXqRur4.js";import"./permissionStore-iKN1K2_x.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./web-components-B0RFakat.js";import"./computeVirtualFileMetrics-BTfrj_fR.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-ehLQSR5W.js";import"./isDiffPlainText-CNZohQ4q.js";import"./vendor-diff-C3JhlQdm.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";const vn=n=>n.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),wn=({currentBranch:n,localBranches:r,remoteBranches:c,branchInfo:m,onCheckout:h,onCreate:s,remotes:t=[],disabled:g=!1})=>{const[u,y]=a.useState(!1),[C,S]=a.useState(""),[v,f]=a.useState(!1),[l,d]=a.useState(!1),[E,k]=a.useState(""),[I,T]=a.useState(!1),H=a.useRef(null),A=a.useCallback($=>{$.stopPropagation()},[]),L=t.length>1,M=a.useMemo(()=>vn(E),[E]),z=a.useMemo(()=>{const $=C.toLowerCase();return $?r.filter(X=>X.toLowerCase().includes($)):r},[C,r]),G=a.useMemo(()=>{const $=C.toLowerCase();return $?c.filter(X=>X.toLowerCase().includes($)):c},[C,c]),x=$=>{if($===n){y(!1);return}h($),y(!1),S("")},B=()=>{f(!0),setTimeout(()=>H.current?.focus(),50)},q=async()=>{if(!(!M||I)){if(L){d(!0);return}T(!0);try{await s(M,t[0]),k(""),f(!1),y(!1)}finally{T(!1)}}},Q=async $=>{if(!(!M||I)){T(!0);try{await s(M,$),k(""),f(!1),d(!1),y(!1)}finally{T(!1)}}},U=()=>{d(!1)},W=()=>{k(""),f(!1),d(!1)};return a.useEffect(()=>{u||(S(""),f(!1),d(!1),k(""))},[u]),e.jsxs(He,{open:u,onOpenChange:y,children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx(Ue,{asChild:!0,children:e.jsxs(_,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:g,children:[e.jsx(w,{name:"git-branch",className:"size-4 text-primary"}),e.jsx("span",{className:"min-w-0 truncate font-medium text-left",children:n||"Detached HEAD"}),e.jsx(w,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),e.jsx(Ce,{sideOffset:8,children:"Current branch"})]}),e.jsx(Ve,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:e.jsxs(ws,{className:"h-full min-h-0",children:[e.jsx(Ns,{placeholder:"Search branches...",value:C,onValueChange:S,onKeyDown:A}),e.jsxs(Cs,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[e.jsx(Ss,{children:"No branches found."}),e.jsx(Oe,{children:l?e.jsxs("div",{className:"px-2 py-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("button",{type:"button",onClick:U,disabled:I,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:e.jsx(w,{name:"arrow-left",className:"size-4"})}),e.jsxs("span",{className:"typography-meta text-muted-foreground",children:["Push To Prefix"," ",e.jsx("span",{className:"text-foreground font-medium",children:M})," ","Push To Suffix"]})]}),e.jsx("div",{className:"flex flex-col gap-1",children:t.map($=>e.jsxs("button",{type:"button",onClick:()=>Q($),disabled:I,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[e.jsxs("span",{className:"typography-ui-label text-foreground",children:[I?e.jsx(w,{name:"loader-4",className:"inline size-3 mr-1.5 animate-spin"}):null,$.name]}),e.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:$.pushUrl})]},$.name))})]}):v?e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[e.jsx("input",{ref:H,placeholder:"New branch name",value:E,onChange:$=>k($.target.value),onClick:$=>$.stopPropagation(),onKeyDown:$=>{A($),$.key==="Enter"?($.preventDefault(),q()):$.key==="Escape"&&($.preventDefault(),W())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),e.jsx("button",{type:"button",onClick:q,disabled:!M||I,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:I?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"add",className:"size-4"})}),e.jsx("button",{type:"button",onClick:W,disabled:I,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:e.jsx(w,{name:"close",className:"size-4"})})]}):e.jsxs(De,{onSelect:B,children:[e.jsx(w,{name:"add",className:"size-4"}),e.jsx("span",{children:"Create new branch..."})]})}),e.jsx(Dt,{}),e.jsxs(Oe,{heading:"Local branches",children:[z.map($=>e.jsxs(De,{onSelect:()=>x($),children:[e.jsxs("span",{className:"flex flex-1 flex-col",children:[e.jsx("span",{className:"typography-ui-label text-foreground",children:$}),(m?.[$]?.ahead||m?.[$]?.behind)&&e.jsxs("span",{className:"typography-micro text-muted-foreground",children:[m[$].ahead||0," ahead ·"," ",m[$].behind||0," behind"]})]}),n===$&&e.jsx("span",{className:"typography-micro text-primary",children:"Current"})]},`local-${$}`)),z.length===0&&e.jsx(De,{disabled:!0,className:"justify-center",children:e.jsx("span",{className:"typography-meta text-muted-foreground",children:"No local branches"})})]}),e.jsx(Dt,{}),e.jsxs(Oe,{heading:"Remote branches",children:[G.map($=>e.jsx(De,{onSelect:()=>x($),children:e.jsx("span",{className:"typography-ui-label text-foreground",children:$})},`remote-${$}`)),G.length===0&&e.jsx(De,{disabled:!0,className:"justify-center",children:e.jsx("span",{className:"typography-meta text-muted-foreground",children:"No remote branches"})})]})]})]})})]})},Nn=n=>n.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Cn=({currentBranch:n,onRename:r,showEditButton:c=!0})=>{const[m,h]=a.useState(!1),[s,t]=a.useState(n||""),[g,u]=a.useState(!1),y=a.useRef(null),C=()=>{!n||!r||(t(n),h(!0),setTimeout(()=>y.current?.focus(),0))},S=async()=>{if(!n||!r||!s.trim())return;const l=Nn(s);if(l===n){h(!1);return}u(!0);try{await r(n,l),h(!1),t("")}finally{u(!1)}},v=()=>{h(!1),t("")},f=l=>{l.key==="Enter"?(l.preventDefault(),S()):l.key==="Escape"&&(l.preventDefault(),v())};return m?e.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:e.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:l=>{l.preventDefault(),S()},children:[e.jsx(w,{name:"git-branch",className:"size-4 text-primary"}),e.jsx("input",{ref:y,value:s,onChange:l=>t(l.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:"Branch name",onKeyDown:f,autoFocus:!0}),e.jsx("button",{type:"submit",disabled:g,"aria-label":g?"Saving branch name":"Save branch name",title:g?"Saving branch name":"Save branch name",className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:g?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"check",className:"size-4"})}),e.jsx("button",{type:"button",onClick:v,disabled:g,"aria-label":"Cancel branch rename",title:"Cancel branch rename",className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:e.jsx(w,{name:"close",className:"size-4"})})]})}):e.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1.5 px-2 py-1 h-8",children:[e.jsx(w,{name:"git-branch",className:"size-4 text-primary shrink-0"}),e.jsxs("div",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[e.jsx("span",{className:"truncate typography-ui-label font-normal text-foreground",children:n||"Detached HEAD"}),c&&r&&n&&e.jsx(_,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:C,title:"Rename branch",children:e.jsx(w,{name:"edit",className:"size-4"})})]})]})},zs=({syncAction:n,remotes:r=[],onFetch:c,onSync:m,onRemoveRemote:h,disabled:s,removingRemoteName:t=null,aheadCount:g=0,behindCount:u=0,trackingRemoteName:y,hasUncommittedChanges:C=!1,iconOnly:S=!1,upstreamTarget:v=null})=>{const f=a.useRef(!1),l=!!t,d=r.find(M=>M.name===y)??r[0],E=u>0&&C,k=s||n!==null||l||!d||E,I=s||n!==null||l||r.length===0,T=g>0||u>0,H=["sync",u>0?`↓${u}`:null,g>0?`↑${g}`:null].filter(Boolean).join(" "),A=E?"Commit or stash your changes before syncing":d?[T?`Sync Changes (${u} down, ${g} up)`:"Sync Changes",v?`Compared with ${v}`:null].filter(Boolean).join(". "):"No remotes configured",L=()=>{d&&m(d)};return e.jsxs("div",{className:"inline-flex items-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] border border-border/60 bg-[var(--surface-elevated)] overflow-hidden",children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("span",{className:"inline-flex",tabIndex:E?0:void 0,children:e.jsxs("button",{type:"button",onClick:L,disabled:k,className:te("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),"aria-label":"Sync Changes",children:[n==="sync"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"refresh",className:"size-4"}),S?T?e.jsx("span",{className:"whitespace-nowrap tabular-nums",children:[u>0?`↓${u}`:null,g>0?`↑${g}`:null].filter(Boolean).join(" ")}):null:e.jsx("span",{className:"whitespace-nowrap tabular-nums",children:H})]})})}),e.jsx(Ce,{sideOffset:8,children:A})]}),e.jsxs(He,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx("button",{type:"button",className:te("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),disabled:I,"aria-label":"More sync actions",children:e.jsx(w,{name:"arrow-down-s",className:"size-4"})})}),e.jsx(Ve,{align:"start",alignOffset:-40,className:"w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",children:r.map(M=>e.jsx(pe,{onSelect:z=>{if(f.current){z.preventDefault(),f.current=!1;return}c(M)},children:e.jsxs("div",{className:"flex w-full items-center gap-2",children:[e.jsx(w,{name:"refresh",className:"size-4 text-muted-foreground"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"typography-ui-label text-foreground",children:`Fetch from ${M.name}`}),e.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:M.fetchUrl})]})}),h&&M.name!==y?e.jsx(_,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||l,onPointerDown:z=>{f.current=!0,z.preventDefault(),z.stopPropagation()},onClick:z=>{f.current=!0,z.preventDefault(),z.stopPropagation(),h(M)},"aria-label":`Remove remote ${M.name}`,title:`Remove remote ${M.name}`,children:t===M.name?e.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin"}):e.jsx(w,{name:"close",className:"size-3.5"})}):null]})},M.name))})]})]})},Sn=({status:n,localBranches:r,remoteBranches:c,branchInfo:m,syncAction:h,remotes:s,onFetch:t,onSync:g,onRemoveRemote:u,removingRemoteName:y,onCheckoutBranch:C,onCreateBranch:S,onRenameBranch:v,activeIdentityProfile:f,availableIdentities:l,onSelectIdentity:d,isApplyingIdentity:E,isWorktreeMode:k,upstreamTarget:I,onOpenHistory:T,onOpenGraph:H,onOpenStashes:A,onOpenUpdateBranch:L,onOpenReintegrateCommits:M,diffScope:z,onDiffScopeChange:G,allCount:x,workingCount:B,stagedCount:q,branchAvailable:Q,diffHeaderState:U})=>{const W=T||H||A||L||M,$=(U?.totalCount??0)>0,X=z!=="turn"&&z!=="branch",ne=W||U!==null;return e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:[e.jsx("div",{className:"min-w-0 flex-shrink",children:k?e.jsx(Cn,{currentBranch:n.current,onRename:v}):e.jsx(wn,{currentBranch:n.current,localBranches:r,remoteBranches:c,branchInfo:m,onCheckout:C,onCreate:S,remotes:s})}),e.jsx("div",{className:"shrink-0",children:e.jsx(dn,{activeProfile:f,identities:l,onSelect:d,isApplying:E,iconOnly:!0})}),e.jsx("div",{className:"min-w-0 shrink-0",children:e.jsx(fn,{scope:z,isGitRepo:!0,branchAvailable:Q,allCount:x,workingCount:B,stagedCount:q,turnCount:U?.turnCount??0,branchCount:U?.branchCount??0,onScopeChange:G})}),e.jsx("div",{className:"min-w-0 flex-1"}),e.jsx("div",{className:"shrink-0",children:e.jsx(zs,{syncAction:h,remotes:s,onFetch:t,onSync:g,onRemoveRemote:u,removingRemoteName:y,disabled:!n,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:n.tracking?.split("/")[0],hasUncommittedChanges:(n.files?.length??0)>0,upstreamTarget:I})}),ne?e.jsx("div",{className:"shrink-0",children:e.jsxs(He,{children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx(Ue,{asChild:!0,children:e.jsx(_,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":"Repository views",children:e.jsx(w,{name:"more-fill",className:"size-4"})})})}),e.jsx(Ce,{sideOffset:8,children:"Repository views"})]}),e.jsxs(Ve,{align:"end",children:[T?e.jsxs(pe,{onSelect:T,children:[e.jsx(w,{name:"history",className:"size-4"}),"History"]}):null,H?e.jsxs(pe,{onSelect:H,children:[e.jsx(w,{name:"git-branch",className:"size-4"}),"Graph"]}):null,A?e.jsxs(pe,{onSelect:A,children:[e.jsx(w,{name:"archive-stack",className:"size-4"}),"Stashes"]}):null,L?e.jsxs(pe,{onSelect:L,children:[e.jsx(w,{name:"git-merge",className:"size-4"}),"Update branch"]}):null,M?e.jsxs(pe,{onSelect:M,children:[e.jsx(w,{name:"split-cells-horizontal",className:"size-4"}),"Re-integrate commits"]}):null,W&&U!==null?e.jsx(Ba,{}):null,U!==null?e.jsxs(pe,{disabled:!$,onSelect:U.onExpandOrCollapseAll,children:[e.jsx(w,{name:"expand-up-down",className:"size-4"}),U.expandedCount>0?"Collapse all":"Expand all"]}):null,U!==null?e.jsxs(pe,{disabled:!$||!X,onSelect:U.onToggleLoadFullFiles,children:[e.jsx(w,{name:"file-download",className:"size-4"}),e.jsx("span",{className:"flex-1",children:"Load full files"}),U.loadFullFiles?e.jsx(w,{name:"check",className:"size-4"}):null]}):null,U!==null?e.jsxs(pe,{disabled:!$,onSelect:U.onToggleWrapLines,children:[e.jsx(w,{name:"text-wrap",className:"size-4"}),e.jsx("span",{className:"flex-1",children:"Wrap lines"}),U.wrapLines?e.jsx(w,{name:"check",className:"size-4"}):null]}):null,U!==null?e.jsxs(pe,{disabled:U.layoutMode===null,onSelect:U.onToggleLayout,children:[e.jsx(w,{name:U.layoutMode==="side-by-side"?"layout-column":"align-justify",className:"size-4"}),U.layoutMode==="side-by-side"?"Switch to unified view":"Switch to side-by-side view"]}):null]})]})}):null]})},kn=({open:n,onOpenChange:r,conflictFiles:c=[],directory:m,operation:h,onAbort:s,onClearState:t})=>{const{git:g}=ut(),u=Lt(x=>x.openNewSessionDraft),y=Lt(x=>x.currentSessionId),C=rs(x=>x.setPendingInputText),S=rs(x=>x.setPendingSyntheticParts),v=Pt(x=>x.setActiveMainTab),[f,l]=a.useState(!1),[d,E]=a.useState(null),[k,I]=a.useState(null);a.useEffect(()=>{!n||!m||(l(!0),I(null),E(null),g.getConflictDetails(m).then(x=>{E(x)}).catch(x=>{const B=x instanceof Error?x.message:"Failed to load conflict details";I(B)}).finally(()=>{l(!1)}))},[m,g,n]);const T=a.useCallback(async()=>{if(!d)return null;const x=h==="merge"?"merge":"rebase",B=d.headInfo||(h==="merge"?"MERGE_HEAD":"REBASE_HEAD"),q=h==="merge"?"git commit --no-edit":"git rebase --continue",Q=`Investigate the ${x} conflicts and concisely report the intended resolution strategy without making modifications. Wait for confirmation before resolving, staging, or continuing the ${x}. Preserve the intent of changes from ${B}.`,U=`Git ${x} operation is in progress with conflicts.
3
3
  - Directory: ${m}
4
4
  - Operation: ${h}
5
5
  - Head Info: ${d.headInfo||"N/A"}
6
6
 
7
7
  Inspect each conflicted file and both sides of every conflict. Report a concise per-file resolution strategy and any assumptions or tradeoffs. Wait for explicit user confirmation before editing, staging, or running ${q}. After confirmation, remove all conflict markers, preserve intent from both sides, verify syntax, and complete the ${x}.`,W=`${x} conflict context (JSON)
8
- ${JSON.stringify({directory:m,operation:d.operation,headInfo:d.headInfo,statusPorcelain:d.statusPorcelain,unmergedFiles:d.unmergedFiles,diff:d.diff},null,2)}`;return{visibleText:Q,instructionsText:U,payloadText:W}},[d,m,h]),H=()=>{s(),r(!1)},A=()=>{t?.(),r(!1)},L=async()=>{const x=await T();if(!x){R.error("No conflict details available");return}if(!y){R.error("No active session",{description:"Open or create a session to resolve conflicts."});return}C(x.visibleText,"replace"),S([{text:x.instructionsText,synthetic:!0},{text:x.payloadText,synthetic:!0}]),v("chat"),t?.(),r(!1)},M=async()=>{const x=await T();if(!x){R.error("No conflict details available");return}u({directoryOverride:m,initialPrompt:x.visibleText,syntheticParts:[{text:x.instructionsText,synthetic:!0},{text:x.payloadText,synthetic:!0}]}),v("chat"),t?.(),r(!1)},z=h==="merge"?"Merge":"Rebase",G=d?.unmergedFiles||c;return e.jsx(Fe,{open:n,onOpenChange:r,children:e.jsx(ze,{className:"max-w-md w-[calc(100vw-2rem)]",children:e.jsxs("div",{className:"flex flex-col gap-4 overflow-hidden",children:[e.jsxs(Ie,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e.jsx($e,{children:`${z} conflicts detected`})]}),e.jsx(Me,{children:`Resolve the ${h} conflicts to continue.`})]}),f&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"typography-meta",children:"Loading conflict details..."})]}),k&&e.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:`Failed to load conflict details: ${k}`}),G.length>0&&e.jsxs("div",{className:"space-y-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Conflicted files:"}),e.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:G.length})]}),e.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:e.jsx("ul",{className:"space-y-1",children:G.map(x=>e.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:x,children:x},x))})})]}),d?.headInfo&&e.jsxs("div",{className:"space-y-1 overflow-hidden",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"HEAD information:"}),e.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:d.headInfo})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-2",children:[e.jsxs(_,{variant:"default",onClick:()=>{M()},disabled:f||!d,className:"w-full gap-2",children:[f?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"add",className:"size-4"}),"Resolve in new session"]}),e.jsxs(_,{variant:"outline",onClick:()=>{L()},disabled:f||!d||!y,className:"w-full gap-2",children:[f?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"chat-1",className:"size-4"}),"Resolve in current session"]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(_,{variant:"ghost",size:"sm",onClick:A,className:"flex-1",children:"Continue later"}),e.jsx(_,{variant:"destructive",size:"sm",onClick:H,className:"flex-1",children:`Abort ${z}`})]})]})]})})})},Re=8,Rn=({laned:n,totalLanes:r,isExpanded:c})=>{const{lane:m,color:h,connectors:s}=n,g=Math.max(r,m+1)*Re+Re/2,u=a.useRef(null),y=a.useRef(null);return a.useLayoutEffect(()=>{const C=u.current,S=y.current;if(!C||!S)return;const v=C.offsetHeight;if(v===0)return;const f=window.devicePixelRatio||1;S.width=g*f,S.height=v*f;const l=S.getContext("2d");if(!l)return;l.scale(f,f),l.clearRect(0,0,g,v);const d=v/2,E=m*Re+Re/2,k=getComputedStyle(S),$=k.getPropertyValue("--surface-muted-foreground").trim()||k.color,T=L=>{if(!L.startsWith("var("))return L;const M=L.slice(4,-1).trim();return k.getPropertyValue(M).trim()||$},H=[...s].sort((L,M)=>{const z=G=>G==="branch-out"||G==="merge-in";return(z(L.type)?1:0)-(z(M.type)?1:0)});for(const L of H){const M=L.fromLane*Re+Re/2,z=L.toLane*Re+Re/2,G=L.type==="passing"?.72:L.type==="branch-out"||L.type==="merge-in"?.95:1;switch(l.beginPath(),l.strokeStyle=T(L.color),l.globalAlpha=G,l.lineWidth=1.25,l.lineCap="round",L.type){case"passing":case"commit-lane":l.moveTo(M,0),l.lineTo(M,v);break;case"top-stub":l.moveTo(M,0),l.lineTo(M,d);break;case"bottom-stub":l.moveTo(M,d),l.lineTo(M,v);break;case"branch-out":{const x=(d+v)/2;l.moveTo(E,d),l.bezierCurveTo(E,x,z,x,z,v);break}case"merge-in":{const x=d/2;l.moveTo(M,0),l.bezierCurveTo(M,x,E,x,E,d);break}default:continue}l.stroke(),l.globalAlpha=1}const A=k.getPropertyValue("--background").trim()||k.getPropertyValue("--surface-background").trim();l.beginPath(),l.arc(E,d,4,0,Math.PI*2),l.fillStyle=T(h),l.fill(),l.beginPath(),l.arc(E,d,5,0,Math.PI*2),l.strokeStyle=A||$,l.lineWidth=2,l.stroke()},[n,m,h,s,r,c,g]),e.jsx("div",{ref:u,style:{width:g,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},children:e.jsx("canvas",{ref:y,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}})})},cs=15e3,ds=500,us=12,hs=8*1024*1024,ms=n=>typeof n=="string"?0:(n.original?.length??0)+(n.modified?.length??0),fs=n=>{if(n.size<=us){let h=0;for(const s of n.values())h+=ms(s);if(h<=hs)return n}const r=Array.from(n.entries()).reverse(),c=new Map;let m=0;for(const[h,s]of r){if(c.size>=us)continue;const t=ms(s);m+t>hs&&c.size>0||(c.set(h,s),m+=t)}return new Map(Array.from(c.entries()).reverse())};function ps(n,r){const c=new Date(n);return Number.isNaN(c.getTime())?n:Ta(c,r,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function En(n){switch(n){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 Fn(n){return n?n.split(",").map(r=>r.trim()).filter(Boolean).map(r=>{const c=r.startsWith("HEAD ->");return{label:c?r.replace("HEAD -> ",""):r.replace("tag: ",""),isHead:c,isTag:r.startsWith("tag: ")}}):[]}const zn=a.memo(({entry:n,mode:r="history",laned:c,totalLanes:m,isExpanded:h,onToggle:s,files:t,isLoadingFiles:g,onCopyHash:u,directory:y,onConflict:C,onActionSuccess:S})=>{const{git:v}=ut(),f=Pt(o=>o.timeFormatPreference),l=r==="graph",d={checkout:"Check out this commit as detached HEAD?",cherryPick:"Cherry-pick this commit onto the current branch?",revert:"Stage a revert of this commit?",merge:"Merge this commit into the current branch?",rebase:"Rebase current branch onto this commit?",resetSoft:"Soft reset — HEAD moves, staged changes preserved.",resetMixed:"Mixed reset — HEAD moves, changes unstaged.",resetHard:"Hard reset — HEAD moves, all uncommitted changes permanently discarded."},E={soft:"Soft — keep staged",mixed:"Mixed — unstage changes",hard:"Hard — discard all changes"},[k,$]=a.useState(null),[T,H]=a.useState(!1),[A,L]=a.useState(""),[M,z]=a.useState(null),[G,x]=a.useState(new Set),[B,q]=a.useState(new Map),[Q,U]=a.useState(new Set),W=async()=>{if(y){$("checkout");try{await v.checkoutCommit(y,n.hash),R.success("Checked out (detached HEAD)"),S?.()}catch(o){R.error(String(o.message))}finally{$(null)}}},I=async()=>{if(!(!y||!A.trim())){$("createBranch");try{await v.createBranch(y,A.trim(),n.hash),H(!1),L(""),S?.()}catch(o){R.error(String(o.message))}finally{$(null)}}},X=async()=>{if(y){$("cherryPick");try{const o=await v.cherryPick(y,n.hash);o.conflict?C?.({conflict:!0,conflictFiles:o.conflictFiles,operation:"cherry-pick"}):S?.()}catch(o){R.error(String(o.message))}finally{$(null)}}},ne=async()=>{if(y){$("revert");try{const o=await v.revertCommit(y,n.hash);o.conflict?C?.({conflict:!0,conflictFiles:o.conflictFiles,operation:"revert"}):S?.()}catch(o){R.error(String(o.message))}finally{$(null)}}},ae=async(o,D=!1)=>{if(!(!y||k!==null)){$("reset");try{await v.resetToCommit(y,n.hash,o,D),S?.()}catch(V){R.error(String(V.message))}finally{$(null)}}},Y=async()=>{if(!M)return;const o=M;switch(z(null),o){case"checkout":return W();case"cherryPick":return X();case"revert":return ne();case"merge":return K();case"rebase":return O();case"resetSoft":return ae("soft");case"resetMixed":return ae("mixed");case"resetHard":return ae("hard",!0)}},K=async()=>{if(y){$("merge");try{const o=await v.merge(y,{branch:n.hash});o.conflict?C?.({conflict:!0,conflictFiles:o.conflictFiles,operation:"merge"}):S?.()}catch(o){R.error(String(o.message))}finally{$(null)}}},O=async()=>{if(y){$("rebase");try{const o=await v.rebase(y,{onto:n.hash});o.conflict?C?.({conflict:!0,conflictFiles:o.conflictFiles,operation:"rebase"}):S?.()}catch(o){R.error(String(o.message))}finally{$(null)}}},N=a.useCallback(async o=>{const D=o.path;if(!y){q(V=>new Map(V).set(D,"error"));return}q(V=>fs(new Map(V).set(D,"loading")));try{const se=(v.getCommitFileDiff??mn)(y,n.hash,o.path,!1),oe=new Promise((le,Ge)=>{setTimeout(()=>Ge(new Error(`Timed out after ${cs}ms`)),cs)}),he=await Promise.race([se,oe]);q(le=>fs(new Map(le).set(D,he)))}catch{q(V=>new Map(V).set(D,"error"))}},[y,n.hash,v.getCommitFileDiff]),F=a.useCallback(async o=>{const D=o.path;if(o.changeType==="R"||o.isBinary){x(he=>{const le=new Set(he);return le.has(D)?le.delete(D):le.add(D),le});return}const V=B.get(D);if(G.has(D)&&V&&V!=="error"){x(he=>{const le=new Set(he);return le.delete(D),le});return}x(he=>{const le=new Set(he);return le.add(D),le}),!(V&&V!=="error"||o.insertions+o.deletions>ds&&!Q.has(D))&&await N(o)},[B,Q,N,G]);return e.jsxs("li",{children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":h,onClick:s,onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),s())},className:te("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",l?"hover:bg-[var(--interactive-hover)]/40":h?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[l&&c&&m!==void 0?e.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:e.jsx(Rn,{laned:c,totalLanes:m,isExpanded:h})}):e.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[l?(()=>{const o=Fn(n.refs);return o.length>0?e.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:o.map(D=>e.jsx("span",{className:te("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",D.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":D.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:D.label},D.label))}):null})():null,e.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[e.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e.jsx("span",{className:"shrink-0",children:"·"}),e.jsx("span",{className:"truncate min-w-0",title:ps(n.date,f),children:ps(n.date,f)})]}),e.jsx("span",{className:"shrink-0",children:"·"}),e.jsx("code",{className:"shrink-0 font-mono",children:n.hash.slice(0,8)}),e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx(_,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:o=>{o.stopPropagation(),u(n.hash)},children:e.jsx(w,{name:"file-copy",className:"size-3"})})}),e.jsx(Ce,{sideOffset:8,children:"Copy SHA"})]})]})]})]}),h&&e.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[l&&M?e.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[e.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:d[M]}),e.jsxs(_,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:k!==null,onClick:o=>{o.stopPropagation(),Y()},children:[k!==null?e.jsx(w,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Confirm"]}),e.jsx(_,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:k!==null,onClick:o=>{o.stopPropagation(),z(null)},children:"Cancel"})]}):l?e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("checkout")},children:"Checkout"}),T?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{autoFocus:!0,value:A,onChange:o=>L(o.target.value),onKeyDown:o=>{o.key==="Enter"&&I(),o.key==="Escape"&&(H(!1),L(""))},placeholder:"Branch name",className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),e.jsxs(_,{variant:"outline",size:"xs",className:"h-6",disabled:!A.trim()||k!==null,onClick:o=>{o.stopPropagation(),I()},children:[k==="createBranch"?e.jsx(w,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Create"]})]}):e.jsx(_,{variant:"outline",size:"xs",className:"h-6",onClick:o=>{o.stopPropagation(),H(!0)},children:"Create branch here"}),e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("cherryPick")},children:"Cherry-pick"}),e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("revert")},children:"Revert"}),e.jsxs(He,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>o.stopPropagation(),children:[k==="reset"?e.jsx(w,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Reset..."]})}),e.jsx(Ve,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(o=>e.jsx(pe,{disabled:k!==null,onSelect:D=>{D.stopPropagation(),z(`reset${o.charAt(0).toUpperCase()+o.slice(1)}`)},children:E[o]},o))})]}),e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("merge")},children:"Merge into current"}),e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("rebase")},children:"Rebase onto this"})]}):null,g?e.jsxs("div",{className:"flex items-center gap-2 py-2",children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"typography-micro text-muted-foreground",children:"Loading files..."})]}):t.length===0?e.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:"No files"}):e.jsx("ul",{className:"space-y-0.5 py-2",children:t.map(o=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>F(o),className:te("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",G.has(o.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[e.jsx("span",{className:te("font-semibold w-3 text-center shrink-0",En(o.changeType)),children:o.changeType}),e.jsx("span",{className:"truncate text-foreground min-w-0",title:o.path,children:o.path}),!o.isBinary&&e.jsxs("span",{className:"shrink-0",children:[e.jsxs("span",{style:{color:"var(--status-success)"},children:["+",o.insertions]}),e.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),e.jsxs("span",{style:{color:"var(--status-error)"},children:["-",o.deletions]})]}),o.isBinary&&e.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:"Binary"}),e.jsx(w,{name:G.has(o.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),G.has(o.path)&&e.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:o.changeType==="R"?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Renamed file — diff not supported"}):o.isBinary?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Binary file — no diff available"}):(()=>{const D=o.insertions+o.deletions;if(!Q.has(o.path)&&D>ds)return e.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${D} changed lines)`}),e.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),e.jsx(_,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{U(se=>new Set(se).add(o.path)),N(o)},children:"Render anyway"})]});const V=B.get(o.path);return V==="loading"||V===void 0?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Loading diff..."}):V==="error"?e.jsx("button",{type:"button",onClick:()=>F(o),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:"Failed to load diff. Click to retry."}):e.jsx(Fs,{original:V.original,modified:V.modified,language:ks(o.path)||"",fileName:o.path,renderSideBySide:!1,layout:"inline"})})()})]},o.path))})]})]})}),gs=["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 lt(n){return gs[n%gs.length]}function In(n){if(n.length===0)return[];const r=[],c=[];for(let m=0;m<n.length;m++){const h=n[m],s=[];for(let f=0;f<r.length;f++)r[f]===h.hash&&s.push(f);let t=s.length>0?s[0]:-1;if(t===-1){const f=r.indexOf(null);f!==-1?t=f:(t=r.length,r.push(null))}const g=s.slice(1),u=lt(t),y=r[t]===h.hash,C=h.parents.length>0;C?r[t]=h.parents[0]:r[t]=null;const S=[];for(let f=1;f<h.parents.length;f++){const l=h.parents[f],d=r.indexOf(l);if(d!==-1)S.push(d);else{const E=r.indexOf(null),k=E!==-1?E:r.length;r[k]=l,k===r.length&&r.push(l),S.push(k)}}const v=[];y&&C?v.push({fromLane:t,toLane:t,color:u,type:"commit-lane"}):y&&!C?v.push({fromLane:t,toLane:t,color:u,type:"top-stub"}):!y&&C&&v.push({fromLane:t,toLane:t,color:u,type:"bottom-stub"});for(const f of g)v.push({fromLane:f,toLane:t,color:lt(f),type:"merge-in"}),r[f]=null;for(const f of S)v.push({fromLane:t,toLane:f,color:lt(f),type:"branch-out"});for(let f=0;f<r.length;f++)r[f]!==null&&f!==t&&(S.includes(f)||v.push({fromLane:f,toLane:f,color:lt(f),type:"passing"}));c.push({commit:h,lane:t,color:u,connectors:v})}return c}const $n=[{label:"25 commits",value:25},{label:"50 commits",value:50},{label:"100 commits",value:100}],Mn=({mode:n="history",log:r,isLogLoading:c,logMaxCount:m,onLogMaxCountChange:h,expandedCommitHashes:s,onToggleCommit:t,commitFilesMap:g,loadingCommitHashes:u,onCopyHash:y,directory:C,showHeader:S=!0,contentMaxHeightClassName:v="max-h-[50vh]",branchDivider:f=null,onConflict:l,onActionSuccess:d})=>{const[E,k]=a.useState(!0),$=n==="graph",T=a.useMemo(()=>$&&r?In(r.all):[],[$,r]),H=a.useMemo(()=>Math.max(1,...T.map(W=>W.lane+1)),[T]),A=a.useMemo(()=>new Map(T.map(W=>[W.commit.hash,W])),[T]);if(!r)return null;const L=f!==null&&f.insertBeforeIndex>0&&f.insertBeforeIndex<r.all.length,M=f!==null&&f.insertBeforeIndex===r.all.length,z=L||M,G=L?r.all.slice(0,f.insertBeforeIndex):M?r.all:[],x=L?r.all.slice(f.insertBeforeIndex):[],B=f?.direction==="down"?e.jsx(w,{name:"arrow-down-s",className:"size-3.5"}):e.jsx(w,{name:"arrow-up",className:"size-3.5"}),q=W=>e.jsx("ul",{className:"divide-y divide-border/60",children:W.map(I=>e.jsx(zn,{entry:I,mode:n,laned:$?A.get(I.hash):void 0,totalLanes:$?H:void 0,isExpanded:s.has(I.hash),onToggle:()=>t(I.hash),files:g.get(I.hash)??[],isLoadingFiles:u.has(I.hash),onCopyHash:y,directory:C,onConflict:l,onActionSuccess:d},I.hash))}),Q=r.all.length>=m?e.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:e.jsx(_,{type:"button",variant:"ghost",size:"xs",onClick:()=>h(m+25),disabled:c,className:"px-3 text-muted-foreground hover:text-foreground",children:c?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(w,{name:"loader-4",className:"size-3 animate-spin"}),"Loading..."]}):"Load more"})}):null,U=e.jsx(Ga,{outerClassName:`min-h-0 ${v}`,className:"h-full w-full",children:r.all.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-4",children:e.jsx("p",{className:"typography-ui-label text-muted-foreground",children:"No commits found"})}):z&&f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-0",children:[G.length>0?e.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:q(G)}):null,e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[e.jsx("span",{className:"h-px flex-1 bg-border/60"}),e.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[e.jsx("span",{className:"truncate",title:f.branchName,children:f.branchName}),B]}),e.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),x.length>0?e.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:q(x)}):null]}),Q]}):e.jsxs(e.Fragment,{children:[q(r.all),Q]})});return S?e.jsxs(xn,{open:E,onOpenChange:k,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[e.jsxs(bn,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[e.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"History"}),e.jsxs("div",{className:"flex items-center gap-2",children:[E&&e.jsx("div",{onClick:W=>W.stopPropagation(),onPointerDown:W=>W.stopPropagation(),children:e.jsxs(Oa,{value:String(m),onValueChange:W=>h(Number(W)),disabled:c,children:[e.jsx(_a,{size:"sm",className:"w-auto",disabled:c,children:e.jsx(Ha,{placeholder:"Commits"})}),e.jsx(Ua,{children:$n.map(W=>e.jsx(Va,{value:String(W.value),children:W.label},W.value))})]})}),E?e.jsx(w,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):e.jsx(w,{name:"arrow-down-s",className:"size-4 text-muted-foreground"})]})]}),e.jsx(yn,{children:U})]}):z?e.jsx("section",{className:"h-full min-h-0",children:U}):e.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:U})},Dn=a.memo(function({mode:r,onOpenChange:c,onRefresh:m,isRefreshing:h,log:s,maxCount:t,onMaxCountChange:g,expandedCommitHashes:u,onToggleCommit:y,commitFilesMap:C,loadingCommitHashes:S,onCopyHash:v,directory:f,branchDivider:l,onConflict:d,onActionSuccess:E}){return r?e.jsx(Fe,{open:r!==null,onOpenChange:c,children:e.jsxs(ze,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[e.jsxs(Ie,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx($e,{children:r==="graph"?"Graph":"History"}),e.jsxs(_,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:m,disabled:h,title:"Refresh","aria-label":"Refresh",children:[e.jsx(w,{name:"refresh",className:te("size-4",h&&"animate-spin")}),"Refresh"]})]}),e.jsx(Me,{children:"Browse recent commits and inspect changed files."})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Mn,{mode:r==="graph"?"graph":"history",log:s,isLogLoading:h,logMaxCount:t,onLogMaxCountChange:g,expandedCommitHashes:u,onToggleCommit:y,commitFilesMap:C,loadingCommitHashes:S,onCopyHash:v,directory:f,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:r==="graph"?null:l,onConflict:r==="graph"?d:void 0,onActionSuccess:r==="graph"?E:void 0})})]})}):null}),Ln=({open:n,onOpenChange:r,operation:c,targetBranch:m,onConfirm:h})=>{const[s,t]=a.useState(!0),[g,u]=a.useState(!1),y=c==="merge"?"Merge":"Rebase",C=async()=>{u(!0);try{await h(s),r(!1)}catch(v){const f=v instanceof Error?v.message:`Failed to ${c}`;R.error(f)}finally{u(!1)}},S=()=>{g||r(!1)};return e.jsx(Fe,{open:n,onOpenChange:g?void 0:r,children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs(Ie,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),e.jsx($e,{children:"Uncommitted Changes"})]}),e.jsx(Me,{children:`Stash your local changes before starting the ${c}.`})]}),e.jsxs("div",{className:"py-2",children:[e.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:"This will:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[e.jsx("li",{children:"Stash your uncommitted changes"}),e.jsxs("li",{children:[c==="merge"?"Merge":"Rebase"," ",c==="merge"?"with":"onto"," ",e.jsx("span",{className:"font-mono text-primary",children:m})]}),s&&e.jsx("li",{children:"Restore your stashed changes"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 py-2",children:[e.jsx(Wa,{checked:s,onChange:t,disabled:g,ariaLabel:"Restore stashed changes after operation"}),e.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!g&&t(!s),children:`Restore stashed changes after ${c}`})]}),e.jsxs(_e,{className:"gap-2",children:[e.jsx(_,{variant:"ghost",size:"sm",onClick:S,disabled:g,children:"Cancel"}),e.jsx(_,{variant:"default",size:"sm",onClick:C,disabled:g,className:"gap-1.5",children:g?e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),"Processing..."]}):`${y}`})]})]})})},Pn=({open:n,onOpenChange:r,directory:c,hasUncommittedChanges:m,hasStagedChanges:h=!1,uncommittedFileCount:s,onChanged:t})=>{const{git:g}=ut(),[u,y]=a.useState([]),[C,S]=a.useState(!1),[v,f]=a.useState(""),[l,d]=a.useState(""),[E,k]=a.useState(null),[$,T]=a.useState({}),H=a.useCallback(async()=>{if(c){S(!0);try{const x=await g.listGitStashes(c);y(x.stashes),T({})}catch(x){R.error(x instanceof Error?x.message:"Failed to load stashes")}finally{S(!1)}}},[c,g]);a.useEffect(()=>{n&&H()},[H,n]),a.useEffect(()=>{if(!n||!c||u.length===0)return;let x=!1;const B=u.map(q=>q.ref);return g.countGitStashFiles(c,B).then(q=>{x||T(q.counts)}).catch(()=>{}),()=>{x=!0}},[c,g,n,u]);const A=a.useMemo(()=>{const x=v.trim().toLowerCase();return x?u.filter(B=>`${B.ref} ${B.message} ${B.relativeTime}`.toLowerCase().includes(x)):u},[v,u]),L=a.useCallback(async x=>{await H(),await t?.(x)},[H,t]),M=async()=>{if(!(!c||E)){k("create");try{const x=await g.stashGitChanges(c,{message:l.trim()||void 0});x.created?(R.success("Changes stashed"),d("")):R.info("No local changes to stash"),await L({affectsIndex:!!(x.created&&h)})}catch(x){R.error(x instanceof Error?x.message:"Failed to stash changes")}finally{k(null)}}},z=async(x,B)=>{if(!(!c||E)&&!(B==="drop"&&!window.confirm(`Drop ${x.ref}?`))){k(`${B}:${x.ref}`);try{B==="apply"&&await g.applyGitStash(c,{ref:x.ref}),B==="pop"&&await g.popGitStash(c,{ref:x.ref}),B==="drop"&&await g.dropGitStash(c,{ref:x.ref});const q=B==="apply"?"Stash applied":B==="pop"?"Stash popped":"Stash dropped";R.success(q),await L({affectsIndex:B!=="drop"})}catch(q){const Q=B==="apply"?"Failed to apply stash":B==="pop"?"Failed to pop stash":"Failed to drop stash";R.error(q instanceof Error?q.message:Q),await L({affectsIndex:B!=="drop"})}finally{k(null)}}},G=E!==null;return e.jsx(Fe,{open:n,onOpenChange:r,children:e.jsxs(ze,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[e.jsxs(Ie,{children:[e.jsxs($e,{className:"flex items-center gap-2",children:[e.jsx(w,{name:"archive-stack",className:"h-5 w-5"}),"Stashes"]}),e.jsx(Me,{children:"Save, restore, and clean up Git stashes for this repository."})]}),e.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(is,{value:l,onChange:x=>d(x.target.value),placeholder:"Stash name",disabled:G||!m,className:"flex-1"}),e.jsxs(_,{onClick:M,disabled:!m||G||!c,children:[E==="create"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"inbox-archive",className:"size-4"}),`Stash ${s} files`]})]}),e.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:"Untracked files are included automatically."})]}),e.jsxs("div",{className:"relative mt-2",children:[e.jsx(w,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(is,{value:v,onChange:x=>f(x.target.value),placeholder:"Search stashes",className:"pl-9"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:C?e.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:e.jsx(w,{name:"loader-4",className:"size-5 animate-spin"})}):A.length===0?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:v?"No matching stashes.":"No stashes yet."}):A.map((x,B)=>e.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[e.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[e.jsx("p",{className:"typography-small truncate text-foreground",children:x.message||"Untitled stash"}),e.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("span",{children:B===0&&!v.trim()?"Latest":`#${B+1}`})}),e.jsx(Ce,{sideOffset:6,children:x.ref})]})," · ",x.relativeTime," · ",typeof $[x.ref]=="number"?`${$[x.ref]} files`:"counting files..."]})]}),e.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[e.jsx(zt,{label:"Apply",loading:E===`apply:${x.ref}`,onClick:()=>z(x,"apply"),disabled:G,children:e.jsx(w,{name:"inbox-unarchive",className:"size-4"})}),e.jsx(zt,{label:"Pop",loading:E===`pop:${x.ref}`,onClick:()=>z(x,"pop"),disabled:G,children:e.jsx(w,{name:"inbox-unarchive-fill",className:"size-4"})}),e.jsx(zt,{label:"Drop",loading:E===`drop:${x.ref}`,onClick:()=>z(x,"drop"),disabled:G,destructive:!0,children:e.jsx(w,{name:"delete-bin",className:"size-4"})})]})]},x.ref))})]})})},zt=({label:n,loading:r,disabled:c,destructive:m,onClick:h,children:s})=>e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":n,"aria-busy":r||void 0,className:te("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",m?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground"),onClick:h,disabled:c,children:r?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):s})}),e.jsx(Ce,{sideOffset:6,children:n})]}),An=({currentBranch:n,localBranches:r,remoteBranches:c,onMerge:m,onRebase:h,disabled:s=!1,isOperating:t=!1,operationLogs:g=[],onOperationComplete:u,mode:y="dialog",defaultTargetBranch:C})=>{const[S,v]=a.useState(!1),[f,l]=a.useState("merge"),[d,E]=a.useState(null),[k,$]=a.useState(!1),[T,H]=a.useState(""),A=a.useRef(null),L=a.useRef(null),M=s||t,z=n||"current branch",G=g.length>0&&g.every(O=>O.status==="done"||O.status==="error"),x=g.some(O=>O.status==="error");a.useEffect(()=>{L.current&&(L.current.scrollTop=L.current.scrollHeight)},[g]);const B=a.useMemo(()=>{const O=T.toLowerCase(),N=new Set(c.map(o=>o.slice(o.indexOf("/")+1)).filter(Boolean)),F=r.filter(o=>o!==n&&!N.has(o));return O?F.filter(o=>o.toLowerCase().includes(O)):F},[T,r,n,c]),q=a.useMemo(()=>{const O=T.toLowerCase();return O?c.filter(N=>N.toLowerCase().includes(O)):c},[T,c]),Q=a.useCallback(()=>C&&(c.includes(C)||r.includes(C))?C:null,[C,r,c]),U=()=>{v(!0),E(Q()),l("merge"),H("")},W=O=>{E(O),$(!1),H("")},I=()=>{d&&(f==="merge"?m(d):h(d))},X=()=>{t||(E(null),l("merge"),H(""),v(!1))},ne=()=>{t&&!G||(G&&u?.(),E(null),l("merge"),H(""),v(!1))};a.useEffect(()=>{k||H("")},[k]),a.useEffect(()=>{y==="dialog"||d||E(Q())},[y,Q,d]);const K=t?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{ref:L,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:e.jsx("div",{className:"space-y-2",children:g.map((O,N)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"mt-0.5 shrink-0",children:[O.status==="running"&&e.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),O.status==="done"&&e.jsx(w,{name:"check",className:"size-3.5 text-success"}),O.status==="error"&&e.jsx(w,{name:"close",className:"size-3.5 text-destructive"}),O.status==="pending"&&e.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),e.jsx("span",{className:te("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})]},N))})}),G?y==="dialog"?e.jsx(_e,{children:e.jsx(_,{variant:"default",size:"sm",onClick:ne,children:x?"Close":"Done"})}):e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"default",size:"sm",onClick:ne,children:x?"Close":"Done"})}):null]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Operation"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>l("merge"),className:te("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",f==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{name:"git-merge",className:te("size-4",f==="merge"?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:te("typography-ui-label",f==="merge"?"text-foreground":"text-muted-foreground"),children:"Merge"})]}),e.jsx("p",{className:"typography-micro text-muted-foreground",children:"Create a merge commit and preserve branch history."})]}),e.jsxs("button",{type:"button",onClick:()=>l("rebase"),className:te("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",f==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{name:"git-branch",className:te("size-4",f==="rebase"?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:te("typography-ui-label",f==="rebase"?"text-foreground":"text-muted-foreground"),children:"Rebase"})]}),e.jsx("p",{className:"typography-micro text-muted-foreground",children:"Replay your commits on top of the selected branch."})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:f==="merge"?`Branch to merge into ${z}`:"Branch to rebase onto"}),e.jsxs(He,{open:k,onOpenChange:$,modal:!1,children:[e.jsx(Ue,{asChild:!0,children:e.jsxs("button",{type:"button",className:te(Ka({size:"default"}),"w-full"),children:[e.jsx("span",{className:te("truncate",!d&&"text-muted-foreground"),children:d||"Select Branch"}),e.jsx(w,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),e.jsx(Ve,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:e.jsxs(ws,{className:"h-full min-h-0",children:[e.jsx(Ns,{ref:A,placeholder:"Search branches...",value:T,onValueChange:H,onKeyDown:O=>O.stopPropagation()}),e.jsxs(Cs,{className:"h-full min-h-0",disableHorizontal:!0,children:[e.jsx(Ss,{children:"No branches found."}),B.length>0&&e.jsx(Oe,{heading:"Local branches",children:B.map(O=>e.jsx(De,{onSelect:()=>W(O),children:e.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`local-${O}`))}),B.length>0&&q.length>0?e.jsx(Dt,{}):null,q.length>0&&e.jsx(Oe,{heading:"Remote branches",children:q.map(O=>e.jsx(De,{onSelect:()=>W(O),children:e.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`remote-${O}`))})]})]})})]})]}),d?e.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:e.jsx("p",{className:"typography-meta text-muted-foreground",children:f==="merge"?e.jsxs(e.Fragment,{children:["This will merge"," ",e.jsx("span",{className:"font-mono text-foreground",children:d})," ","into"," ",e.jsx("span",{className:"font-mono text-foreground",children:z})]}):e.jsxs(e.Fragment,{children:["This will rebase"," ",e.jsx("span",{className:"font-mono text-foreground",children:z})," ","onto"," ",e.jsx("span",{className:"font-mono text-foreground",children:d})]})})}):null,y==="dialog"?e.jsxs(_e,{className:"gap-2 pt-1",children:[e.jsx(_,{variant:"ghost",size:"sm",onClick:X,children:"Cancel"}),e.jsx(_,{variant:"default",size:"sm",onClick:I,disabled:!d,className:"gap-1.5",children:f==="merge"?e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"git-merge",className:"size-4"}),"Merge"]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"git-branch",className:"size-4"}),"Rebase"]})})]}):e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(_,{variant:"destructive",size:"sm",onClick:X,disabled:M,children:"Reset"}),e.jsx("div",{className:"flex-1"}),e.jsx(_,{variant:"default",size:"sm",onClick:I,disabled:M||!d,children:f==="merge"?"Merge":"Rebase"})]})]});return y==="bare"?K:y==="inline"?e.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[e.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:"Update branch"}),e.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Bring the latest changes into"," ",e.jsx("span",{className:"font-mono text-foreground",children:z}),"."]})]})}),e.jsx("div",{className:"pt-3",children:K})]}):e.jsxs(e.Fragment,{children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"gap-1.5",onClick:U,disabled:M,children:[t?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"git-merge",className:"size-4"}),e.jsx("span",{children:"Merge/Rebase"})]})}),e.jsx(Ce,{sideOffset:8,children:"Update this branch from another branch."})]}),e.jsx(Fe,{open:S,onOpenChange:O=>{O?v(!0):ne()},children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs(Ie,{children:[e.jsx($e,{children:"Update branch"}),e.jsx(Me,{children:t?G?x?"Operation Failed":"Operation Completed":f==="merge"?"Merging In Progress":"Rebasing In Progress":e.jsxs(e.Fragment,{children:["Choose how to bring another branch into"," ",e.jsx("span",{className:"font-mono text-foreground",children:z}),"."]})})]}),K]})})]})},Bn=a.memo(function({open:r,onOpenChange:c,branchOperation:m,currentBranch:h,localBranches:s,remoteBranches:t,defaultTargetBranch:g,onMerge:u,onRebase:y,disabled:C,operationLogs:S,onOperationComplete:v,canShowBranchWorkflows:f}){return e.jsx(Fe,{open:r,onOpenChange:l=>{!l&&m!==null||c(l)},children:e.jsxs(ze,{className:"max-w-2xl min-h-[26rem]",children:[e.jsxs(Ie,{children:[e.jsx($e,{children:"Update branch"}),e.jsxs(Me,{children:["Bring the latest changes into"," ",e.jsx("span",{className:"font-mono text-foreground",children:h??""}),"."]})]}),f?e.jsx(An,{mode:"bare",currentBranch:h,localBranches:s,remoteBranches:t,defaultTargetBranch:g??void 0,onMerge:u,onRebase:y,disabled:C,isOperating:m!==null,operationLogs:S,onOperationComplete:v}):e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Branch actions unavailable in this repository state"})]})})}),Tn=({currentDirectory:n,isUpdateBranchDialogOpen:r,setIsUpdateBranchDialogOpen:c,branchOperation:m,currentBranch:h,localBranches:s,remoteBranches:t,updateTargetBranch:g,onMerge:u,onRebase:y,isBusy:C,operationLogs:S,onOperationComplete:v,canShowBranchWorkflows:f,gitLogDialogMode:l,setGitLogDialogMode:d,onRefreshHistory:E,isLogRefreshing:k,log:$,maxCount:T,onMaxCountChange:H,expandedCommitHashes:A,onToggleCommit:L,commitFilesMap:M,loadingCommitHashes:z,onCopyHash:G,historyBranchDivider:x,onConflict:B,onActionSuccess:q,isStashesDialogOpen:Q,setIsStashesDialogOpen:U,hasUncommittedChanges:W,hasStagedChanges:I,uncommittedFileCount:X,onStashesChanged:ne,conflictDialogOpen:ae,setConflictDialogOpen:Y,conflictFiles:K,conflictOperation:O,onAbortConflict:N,onClearConflictState:F,stashDialogOpen:o,setStashDialogOpen:D,stashDialogOperation:V,stashDialogBranch:se,onConfirmStashAndRetry:oe})=>e.jsxs(e.Fragment,{children:[e.jsx(Bn,{open:r,onOpenChange:c,branchOperation:m,currentBranch:h,localBranches:s,remoteBranches:t,defaultTargetBranch:g,onMerge:u,onRebase:y,disabled:C,operationLogs:S,onOperationComplete:v,canShowBranchWorkflows:f}),e.jsx(Dn,{mode:l,onOpenChange:he=>{he||d(null)},onRefresh:E,isRefreshing:k,log:$,maxCount:T,onMaxCountChange:H,expandedCommitHashes:A,onToggleCommit:L,commitFilesMap:M,loadingCommitHashes:z,onCopyHash:G,directory:n??void 0,branchDivider:x,onConflict:B,onActionSuccess:q}),e.jsx(Pn,{open:Q,onOpenChange:U,directory:n,hasUncommittedChanges:W,hasStagedChanges:I,uncommittedFileCount:X,onChanged:ne}),n&&e.jsx(kn,{open:ae,onOpenChange:Y,conflictFiles:K,directory:n,operation:O,onAbort:N,onClearState:F}),e.jsx(Ln,{open:o,onOpenChange:D,operation:V,targetBranch:se,onConfirm:oe})]}),Gn=20,Te=new Map;function On(n){return Te.get(n)??null}function _n(n,r){if(Te.delete(n),Te.set(n,r),Te.size>Gn){const c=Te.keys().next().value;c!==void 0&&Te.delete(c)}}const It=38,ct=200,Hn=({value:n,onChange:r,placeholder:c,disabled:m=!1,hasTouchInput:h=!1,isMobile:s=!1})=>{const t=a.useRef(null);return a.useLayoutEffect(()=>{const g=t.current;if(!g)return;const u=document.activeElement===g,y=()=>{g.style.height=`${It}px`;const S=g.scrollHeight,v=Math.min(Math.max(S,It),ct);g.style.height=`${v}px`,g.style.overflowY=S>ct?"auto":"hidden",S>ct&&!u&&(g.scrollTop=g.scrollHeight)};y();const C=window.requestAnimationFrame(y);return()=>{window.cancelAnimationFrame(C)}},[n]),e.jsx("textarea",{ref:t,value:n,onChange:g=>r(g.target.value),placeholder:c??"Commit message",rows:1,disabled:m,autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:s,className:te("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",m&&"opacity-50"),style:{minHeight:It,maxHeight:ct}})},Is=({stagedCount:n,commitMessage:r,onCommitMessageChange:c,onCommit:m,onCommitAndPush:h,commitAction:s,hasPendingIndexMutation:t=!1})=>{const g=n>0,u=r.trim()&&g&&s===null&&!t,{isMobile:y,hasTouchInput:C}=qa();return e.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[e.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[e.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"Commit"}),g?null:e.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:"Stage files to enable commit."})]}),e.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[e.jsx(Hn,{value:r,onChange:c,placeholder:"Commit message",disabled:s!==null,hasTouchInput:C,isMobile:y}),e.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"flex-1"}),e.jsx(_,{size:"sm",variant:"outline",onClick:m,disabled:!u,className:"commit-actions__btn whitespace-nowrap","aria-label":"Commit aria label",children:s==="commit"?e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"commit-actions__label",children:"Committing..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"git-commit",className:"size-4"}),e.jsx("span",{className:"commit-actions__label",children:"Commit"})]})}),y?e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx(_,{variant:"default",size:"sm",onClick:()=>h(),disabled:!u,className:"h-7 w-7 p-0","aria-label":"Commit and sync",children:s==="commitAndPush"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"arrow-up",className:"size-3.5"})})}),e.jsx(Ce,{side:"top",children:e.jsx("p",{children:"Commit & sync"})})]}):e.jsx(_,{size:"sm",variant:"default",onClick:()=>h(),disabled:!u,className:"commit-actions__btn","aria-label":"Commit and sync",children:s==="commitAndPush"?e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:"Syncing..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"arrow-up",className:"size-3.5"}),e.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:"Commit & sync"})]})})]})]})]})},Un=({onOpenStashes:n})=>e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[e.jsx(w,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:"Working tree clean"}),e.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:"All changes have been committed"}),n?e.jsxs(_,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[e.jsx(w,{name:"archive-stack",className:"size-4"}),"Stashes"]}):null]}),Vn=({mergeInProgress:n,rebaseInProgress:r,onContinue:c,onAbort:m,onResolveWithAI:h,conflictCount:s=0,isLoading:t=!1})=>{const[g,u]=a.useState(null),y=n&&n.head,C=r&&(r.headName||r.onto),S=y?"merge":C?"rebase":null;if(!S)return null;const v=async()=>{u("continue");try{await c()}finally{u(null)}},f=async()=>{u("abort");try{await m()}finally{u(null)}},l=g!==null,d=s>0,E=S==="merge"?"Merge":"Rebase";let k="";n?k=n.message?`Merging: ${n.message}`:`Merging ${n.head}`:r&&(k=r.headName?`Rebasing ${r.headName} onto ${r.onto||""}`:"Rebase in progress");const $=d?s===1?`${E} in progress: ${s} conflict`:`${E} in progress: ${s} conflicts`:`${E} in progress`,T=d?"Resolve conflicts, then continue the operation.":"All conflicts resolved. Continue to finish the operation.";return e.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:e.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:$}),k&&e.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:k})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:T}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:f,disabled:l||t,className:"gap-1.5",children:[g==="abort"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"close",className:"size-4"}),"Abort"]}),d?h&&e.jsx(_,{variant:"default",size:"sm",onClick:h,disabled:l||t,children:"Resolve with AI"}):e.jsxs(_,{variant:"default",size:"sm",onClick:v,disabled:l||t,className:"gap-1.5",children:[g==="continue"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"check",className:"size-4"}),"Continue"]})]})]})]})})};function Wn(n,r){const[c,m]=a.useState(new Set),[h,s]=a.useState(new Map),[t,g]=a.useState(new Set),u=a.useRef(h),y=a.useRef(t),C=a.useCallback(v=>{Ya(v).then(f=>{if(f.ok){R.success("Commit hash copied");return}R.error("Failed to copy")})},[]),S=a.useCallback(v=>{m(f=>{const l=new Set(f);return l.has(v)?l.delete(v):l.add(v),l})},[]);return a.useEffect(()=>{u.current=h},[h]),a.useEffect(()=>{y.current=t},[t]),a.useEffect(()=>{if(!n||!r)return;const v=Array.from(c).filter(l=>!u.current.has(l)&&!y.current.has(l));if(v.length===0)return;let f=!1;return g(l=>{const d=new Set(l);for(const E of v)d.add(E);return y.current=d,d}),Promise.all(v.map(l=>r.getCommitFiles(n,l).then(d=>({hash:l,files:d.files})).catch(d=>(console.error("Failed to fetch commit files:",d),{hash:l,files:[]})))).then(l=>{f||(s(d=>{const E=new Map(d);for(const{hash:k,files:$}of l)E.set(k,$);return u.current=E,E}),g(d=>{const E=new Set(d);for(const{hash:k}of l)E.delete(k);return y.current=E,E}))}),()=>{f=!0,g(l=>{let d=!1;const E=new Set(l);for(const k of v)E.delete(k)&&(d=!0);return d?(y.current=E,E):l})}},[c,n,r]),{expandedCommitHashes:c,commitFilesMap:h,loadingCommitHashes:t,handleCopyCommitHash:C,handleToggleCommit:S}}const Kn=n=>{const{remoteNames:r,localBranches:c,worktreeCreatedFromBranch:m,rootBranchHint:h,defaultBranch:s,headBranch:t}=n,g=typeof t=="string"?t.trim():"",u=f=>{if(!f)return"";let l=f.trim();if(!l||l==="HEAD")return"";if(c.includes(l))return l;l.startsWith("refs/heads/")&&(l=l.slice(11)),l.startsWith("heads/")&&(l=l.slice(6)),l.startsWith("remotes/")&&(l=l.slice(8));const d=l.indexOf("/");if(d>0){const E=l.slice(0,d);if(r.has(E)){const k=l.slice(d+1).trim();k&&(l=k)}}return l},y=f=>{const l=u(typeof f=="string"?f:"");return l&&l!==g?l:""},C=y(m);if(C)return C;const S=y(h);if(S)return S;const v=y(s);return v||(c.includes("main")?"main":c.includes("master")?"master":c.includes("develop")?"develop":"main")},qn=n=>{const{baseBranch:r,localBranches:c,remoteBranches:m}=n;return c.includes(r)?!0:m.some(h=>{const s=h.indexOf("/");return s>0&&h.slice(s+1)===r})},Yn=n=>n?n.filter(r=>!r.startsWith("remotes/")).sort():[],Zn=n=>n?n.filter(r=>r.startsWith("remotes/")).map(r=>r.replace(/^remotes\//,"")).sort():[],Jn=(n,r,c,m)=>{if(n.length>0)return n;const h=new Set,s=c?.trim();s&&s.includes("/")&&h.add(s.split("/")[0]);for(const t of r){const g=t.indexOf("/");g>0&&h.add(t.slice(0,g))}return h.size===0&&m&&h.add("origin"),Array.from(h).map(t=>({name:t,fetchUrl:m??"",pushUrl:m??""}))},Qn=(n,r)=>{const c=r?.trim().split("/")[0];return(c&&n?.[c])??n?.origin},Xn=(n,r,c)=>c?n.map(s=>s.name).map(s=>`${s}/${c}`).find(s=>r.includes(s))??c:null;function er({branches:n,status:r,remotes:c,remoteUrl:m,git:h}){const s=a.useMemo(()=>Yn(n?.all),[n?.all]),t=a.useMemo(()=>Zn(n?.all),[n?.all]),g=a.useMemo(()=>Jn(c,t,r?.tracking,m),[c,t,m,r?.tracking]),u=r?.current??null,y=a.useMemo(()=>Qn(n?.defaultBranches,r?.tracking),[n?.defaultBranches,r?.tracking]),C=a.useMemo(()=>Kn({remoteNames:new Set(g.map(f=>f.name)),localBranches:s,defaultBranch:y,headBranch:u}),[u,y,g,s]),S=!!(u&&C&&u!==C&&(r?.tracking||g.length>0)&&typeof h?.getGitRangeDiff=="function"&&qn({baseBranch:C,localBranches:s,remoteBranches:t})),v=a.useMemo(()=>Xn(g,t,C),[C,g,t]);return{localBranches:s,remoteBranches:t,effectiveRemotes:g,currentBranch:u,defaultBranch:y,baseBranch:C,branchScopeAvailable:S,updateTargetBranch:v}}const tr=n=>{if(!n)return null;try{let r=n.trim();r.startsWith("git@")&&(r=`https://${r.slice(4).replace(":","/")}`),r.endsWith(".git")&&(r=r.slice(0,-4));const c=new URL(r);return c.hostname+c.pathname}catch{return null}},sr=(n,r,c)=>{const m=new Map;r&&m.set(r.id,r);const h=tr(c);for(const s of n){if(s.authType!=="token"){m.set(s.id,s);continue}const t=s.host;if(!t){m.set(s.id,s);continue}if(!t.includes("/")){m.set(s.id,s);continue}h&&h===t&&m.set(s.id,s)}return Array.from(m.values())},ar=(n,r,c)=>{if(n?.userName&&n?.userEmail){const m=r.find(h=>h.userName===n.userName&&h.userEmail===n.userEmail);return m||(c&&c.userName===n.userName&&c.userEmail===n.userEmail?c:{id:"local-config",name:n.userName,userName:n.userName,userEmail:n.userEmail,sshKey:n.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return c??null};function nr({profiles:n,globalIdentity:r,currentIdentity:c,remoteUrl:m}){const h=a.useMemo(()=>sr(n,r,m),[n,r,m]),s=a.useMemo(()=>ar(c,n,r),[c,n,r]);return{availableIdentities:h,activeIdentityProfile:s}}function rr({currentSessionId:n,currentDirectory:r}){const[c,m]=a.useState(!1),[h,s]=a.useState([]),[t,g]=a.useState("merge"),u=a.useMemo(()=>n?`pichamber.conflict:${n}`:null,[n]),y=a.useCallback((S,v,f)=>{if(!u||typeof window>"u")return;const l={directory:S,conflictFiles:v,operation:f};window.localStorage.setItem(u,JSON.stringify(l))},[u]),C=a.useCallback(()=>{!u||typeof window>"u"||window.localStorage.removeItem(u)},[u]);return a.useEffect(()=>{if(!u||typeof window>"u"||!r)return;const S=window.localStorage.getItem(u);if(S)try{const v=JSON.parse(S);if(v.directory!==r){window.localStorage.removeItem(u);return}s(v.conflictFiles??[]),g(v.operation??"merge"),m(!0)}catch{window.localStorage.removeItem(u)}},[u,r]),{conflictDialogOpen:c,setConflictDialogOpen:m,conflictFiles:h,setConflictFiles:s,conflictOperation:t,setConflictOperation:g,persistConflictState:y,clearConflictState:C}}const ir=({runMutation:n,onMutationComplete:r,onMutationError:c,onPathsComplete:m,scheduleFlush:h})=>{const s=[];let t=!1;return{enqueue:u=>{const y=s[s.length-1];if(y?.directory===u.directory&&y.direction===u.direction){u.paths.forEach(C=>y.paths.add(C));return}s.push(u)},flush:()=>{if(t)return;const u=s.shift();if(!u)return;t=!0;const y={directory:u.directory,direction:u.direction,paths:Array.from(u.paths),rollback:u.rollback};(async()=>{try{await n(y),r(y)}catch(C){c(y,C)}finally{m(y.paths),t=!1,s.length>0&&h()}})()},clear:()=>{s.length=0},size:()=>s.length,isRunning:()=>t}},or=a.memo(function({file:r,actionLabel:c,actionSymbol:m,onAction:h,onViewDiff:s,onRevert:t,isReverting:g,stats:u,rowPaddingClassName:y,indentPx:C=0,actionAtStart:S=!1,showRevert:v=!0}){const f=it.useMemo(()=>pn(r),[r]),l=f.description,d=u?.insertions??0,E=u?.deletions??0,k=it.useCallback(A=>{A.key===" "?(A.preventDefault(),h()):A.key==="Enter"&&(A.preventDefault(),s())},[h,s]),$=it.useCallback(A=>{A.preventDefault(),A.stopPropagation(),h()},[h]),T=it.useCallback(A=>{A.preventDefault(),A.stopPropagation(),t()},[t]),H=e.jsx("button",{type:"button",onClick:$,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":c,title:c,children:m});return e.jsxs("div",{className:`group flex items-center gap-2 py-1.5 cursor-pointer ${y??"px-3"}`,role:"button",tabIndex:0,onClick:s,onKeyDown:k,style:C>0?{paddingLeft:`${C}px`}:void 0,children:[S?H:null,e.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:f.color},title:l,"aria-label":l,children:f.code}),e.jsx(Za,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),(()=>{const A=r.path.lastIndexOf("/");if(A===-1)return e.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:r.path,children:r.path});const L=r.path.slice(0,A),M=r.path.slice(A);return e.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[e.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:L}),e.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[e.jsx("span",{className:"text-muted-foreground",children:"/"}),e.jsx("span",{className:"text-foreground",children:M.slice(1)})]})]})})(),e.jsxs("span",{className:"shrink-0 typography-micro",children:[e.jsxs("span",{style:{color:"var(--status-success)"},children:["+",d]}),e.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),e.jsxs("span",{style:{color:"var(--status-error)"},children:["-",E]})]}),v?e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("button",{type:"button",onClick:T,disabled:g,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${r.path}`,children:g?e.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin"}):e.jsx(w,{name:"arrow-go-back",className:"size-3.5"})})}),e.jsx(Ce,{sideOffset:8,children:"Revert changes"})]}):null,S?null:H]})}),xs=14,$s=n=>n.replace(/\\/g,"/").replace(/^\/+/,"").trim(),bs=(n,r)=>({id:`dir:${n}`,path:n,name:r,children:new Map,directFiles:[],files:[]}),lr=n=>{const r=bs("","");for(const c of n){const m=$s(c.path);if(!m)continue;const s=m.split("/").filter(Boolean).slice(0,-1);let t=r;if(t.files.push(c),s.length>0){let g="";for(const u of s){g=g?`${g}/${u}`:u;const y=t.children.get(u);if(y){y.files.push(c),t=y;continue}const C=bs(g,u);C.files.push(c),t.children.set(u,C),t=C}}t.directFiles.push(c)}return r},cr=(n,r)=>{const c=[],m=(h,s)=>{const t=Array.from(h.children.values()).sort((u,y)=>u.path.localeCompare(y.path));for(const u of t)c.push({key:u.id,kind:"directory",depth:s,directory:u}),r.has(u.path)&&m(u,s+1);const g=[...h.directFiles].sort((u,y)=>u.path.localeCompare(y.path));for(const u of g)c.push({key:`file:${$s(u.path)}`,kind:"file",depth:s,file:u})};return m(n,0),c},dr=1e3,ys=34,$t=30,dt="pl-0 pr-2",Mt=(n,r)=>`${n} ${r}`,ur=({groups:n,diffStats:r,revertingPaths:c,isRevertingAll:m=!1,headerBackgroundClassName:h="bg-sidebar",onVisiblePathsChange:s,onRevertAll:t,onRevertDirectory:g})=>{const u=a.useRef(null),C=Pt(N=>N.gitChangesViewMode)==="tree",S=a.useMemo(()=>n.filter(N=>N.entries.length>0),[n]),[v,f]=a.useState(new Set),[l,d]=a.useState(new Set),[E,k]=a.useState(!1),[$,T]=a.useState(null),H=a.useMemo(()=>S.map(N=>lr(N.entries)),[S]),A=a.useMemo(()=>{const N=[];return S.forEach((F,o)=>{Array.from(H[o]?.children.values()??[]).forEach(D=>{N.push(Mt(F.id,D.path))})}),N},[H,S]);a.useEffect(()=>{C&&d(N=>{const F=new Set,o=new Set(A);return N.forEach(D=>{(D.slice(D.indexOf(" ")+1).includes("/")||o.has(D))&&F.add(D)}),A.forEach(D=>F.add(D)),F})},[C,A]);const L=a.useMemo(()=>{const N=[];return S.forEach((F,o)=>{if(N.push({type:"header",key:`header:${F.id}`,groupIndex:o}),!v.has(F.id)){if(C){const D=new Set;l.forEach(se=>{se.startsWith(`${F.id} `)&&D.add(se.slice(F.id.length+1))}),cr(H[o],D).forEach(se=>{se.kind==="file"?N.push({type:"file",key:`${F.id}:${se.key}`,groupIndex:o,file:se.file,depth:se.depth}):N.push({type:"directory",key:`${F.id}:${se.key}`,groupIndex:o,directory:se.directory,depth:se.depth})});return}F.entries.forEach(D=>{N.push({type:"file",key:`${F.id}:file:${D.path}`,groupIndex:o,file:D,depth:0})})}}),t&&S.length>0&&N.push({type:"revert-all",key:"revert-all"}),N},[v,l,C,t,H,S]),M=L.length,z=M>=dr,G=jn({count:M,enabled:z,getScrollElement:()=>u.current,estimateSize:()=>ys,overscan:12,getItemKey:N=>L[N]?.key??N}),x=G.getVirtualItems(),B=a.useMemo(()=>{if(!z)return 0;const N=u.current?.scrollTop??0;return x.find(o=>o.end>N)?.index??0},[z,x,u]);a.useEffect(()=>{if(!s)return;const N=F=>F&&F.type==="file"?F.file.path:null;if(M===0){s([]);return}if(!z){const F=[];for(const o of L)if(o.type==="file"&&(F.push(o.file.path),F.length>=$t))break;s(F);return}s(L.slice(B,B+Math.ceil((u.current?.clientHeight??0)/ys)+$t).map(F=>N(F)).filter(F=>!!F).slice(0,$t))},[s,M,L,z,B]);const q=a.useCallback(N=>{f(F=>{const o=new Set(F);return o.has(N)?o.delete(N):o.add(N),o})},[]),Q=a.useCallback((N,F)=>{d(o=>{const D=new Set(o),V=Mt(N,F);return D.has(V)?D.delete(V):D.add(V),D})},[]),U=a.useMemo(()=>{const N=new Set;return S.forEach(F=>F.entries.forEach(o=>N.add(o.path))),Array.from(N)},[S]),W=U.length,I=$?m||$.paths.some(N=>c.has(N)):!1,X=a.useCallback(async()=>{!t||m||U.length===0||(await t(U),k(!1))},[U,m,t]),ne=a.useCallback(async()=>{!g||!$||I||(await g($.paths),T(null))},[I,g,$]),ae=a.useCallback((N,F)=>{const o=v.has(N.id),D=N.entries.length;return e.jsxs("div",{className:te("sticky top-0 z-10 flex items-center gap-2 py-2",h,dt,!F&&"mt-1 border-t border-border/40"),children:[e.jsx("button",{type:"button",onClick:()=>N.onActionAll(N.entries.map(V=>V.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":N.actionAllLabel,title:N.actionAllLabel,children:N.actionSymbol}),e.jsxs("button",{type:"button",onClick:()=>q(N.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!o,children:[e.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:N.title}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:D}),e.jsx(w,{name:"arrow-down-s",className:te("size-3.5 shrink-0 text-muted-foreground transition-transform",o&&"-rotate-90")})]})]})},[v,h,q]),Y=a.useCallback((N,F,o)=>{const D=l.has(Mt(N.id,F.path)),V=F.files.map(oe=>oe.path),se=m||V.some(oe=>c.has(oe));return e.jsxs("div",{className:te("group flex items-center gap-2 py-1.5",dt),style:{paddingLeft:`${o*xs}px`},children:[e.jsxs("button",{type:"button",onClick:()=>Q(N.id,F.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":D?`Collapse directory ${F.path}`:`Expand directory ${F.path}`,children:[D?e.jsx(w,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):e.jsx(w,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:F.path,children:F.name}),e.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:F.files.length})]}),N.showRevertActions!==!1&&g?e.jsx("button",{type:"button",onClick:()=>T({path:F.path,paths:V,count:V.length}),disabled:se,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${F.path}`,title:"Revert folder changes",children:se?e.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin"}):e.jsx(w,{name:"arrow-go-back",className:"size-3.5"})}):null,e.jsx("button",{type:"button",onClick:()=>N.onActionAll(F.files.map(oe=>oe.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":N.actionSymbol==="+"?`Stage all changes in ${F.path}`:`Unstage all changes in ${F.path}`,title:N.actionSymbol==="+"?`Stage all changes in ${F.path}`:`Unstage all changes in ${F.path}`,children:N.actionSymbol})]})},[l,m,g,c,Q]),K=a.useCallback((N,F)=>{if(N.type==="revert-all")return e.jsx("div",{className:te("flex justify-end py-2",dt),children:e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>k(!0),disabled:m,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[e.jsx(w,{name:"arrow-go-back",className:"size-3.5"}),"Revert all"]})});const o=S[N.groupIndex];if(!o)return null;if(N.type==="header")return ae(o,F);if(N.type==="directory")return Y(o,N.directory,N.depth);const D=N.file;return e.jsx(or,{file:D,actionLabel:o.getActionLabel(D.path),actionSymbol:o.actionSymbol,onAction:()=>o.onActionFile(D.path),stats:r?.[D.path],onViewDiff:()=>o.onViewDiff(D.path),onRevert:()=>o.onRevertFile(D.path),isReverting:c.has(D.path)||m,rowPaddingClassName:dt,indentPx:N.depth*xs,actionAtStart:!C,showRevert:o.showRevertActions!==!1})},[r,m,C,Y,ae,c,S]),O=a.useCallback(N=>{const F=L[N],o=L[N-1];return!F||!o||F.type!=="file"&&F.type!=="directory"||o.type!=="file"&&o.type!=="directory"?!1:o.groupIndex===F.groupIndex},[L]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[e.jsx(Rs,{ref:u,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:z?e.jsx("div",{style:{height:G.getTotalSize(),position:"relative"},children:x.map(N=>{const F=L[N.index];return F?e.jsx("div",{"data-index":N.index,ref:G.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${N.start}px)`},className:te(O(N.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:K(F,N.index===0)},F.key):null})}):e.jsx("div",{role:"list","aria-label":"Changed files",children:L.map((N,F)=>e.jsx("div",{className:te("relative",O(F)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:K(N,F===0)},N.key))})}),e.jsx(Ja,{containerRef:u,disableHorizontal:!0})]}),e.jsx(Fe,{open:E,onOpenChange:N=>{!m&&!N&&k(!1)},children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs(Ie,{children:[e.jsx($e,{children:"Revert all changes?"}),e.jsx(Me,{children:W===1?`Revert ${W} changed file? This cannot be undone.`:`Revert ${W} changed files? This cannot be undone.`})]}),e.jsxs(_e,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>k(!1),disabled:m,children:"Cancel"}),e.jsx(_,{variant:"destructive",size:"sm",onClick:()=>{X()},disabled:m,children:m?"Reverting...":"Revert all"})]})]})}),e.jsx(Fe,{open:!!$,onOpenChange:N=>{!I&&!N&&T(null)},children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs(Ie,{children:[e.jsx($e,{children:"Revert folder changes?"}),e.jsx(Me,{children:$?$.count===1?`This will discard local changes in ${$.count} file under ${$.path}.`:`This will discard local changes in ${$.count} files under ${$.path}.`:null})]}),e.jsxs(_e,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>T(null),disabled:I,children:"Cancel"}),e.jsx(_,{variant:"destructive",size:"sm",onClick:()=>{ne()},disabled:I||!$,children:I?"Reverting...":"Revert folder"})]})]})})]})},hr=Es(()=>vs(()=>import("./DiffView-C76KYB1I.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(n=>({default:n.DiffView}))),mr=({currentDirectory:n,status:r,isGitRepo:c,isLoadingStatus:m,changeEntries:h,stagedChangeEntries:s,unstagedChangeEntries:t,effectiveRemotes:g,syncAction:u,commitAction:y,commitMessage:C,hasPendingIndexMutation:S,revertingPaths:v,isRevertingAll:f,initialDiffPath:l,initialDiffStaged:d=!1,onSyncAction:E,onMoveChangePaths:k,onRevertFile:$,onRevertAll:T,onCommitMessageChange:H,onCommit:A,onVisiblePathsChange:L,loadDiff:M})=>{const[z,G]=a.useState(()=>l?{type:"diff",path:l,staged:d}:{type:"list"}),[x,B]=a.useState(null),[q,Q]=a.useState(null),[U,W]=a.useState(0);a.useEffect(()=>{l&&G(Y=>Y.type==="diff"&&Y.path===l&&Y.staged===d?Y:{type:"diff",path:l,staged:d})},[l,d]);const I=a.useMemo(()=>z.type==="diff"&&h.some(Y=>Y.path===z.path),[h,z]);a.useEffect(()=>{if(z.type!=="diff"||!I){B(null),Q(null);return}let Y=!1;return B(null),Q(null),M(z.path,z.staged).then(K=>{Y||B(K)}).catch(K=>{Y||Q(K instanceof Error?K.message:String(K))}),()=>{Y=!0}},[U,M,z,I]);const X=a.useCallback((Y,K=!1)=>{G({type:"diff",path:Y,staged:K})},[]),ne=a.useMemo(()=>{const Y=[];return s.length>0&&Y.push({id:"staged",title:"Staged",entries:s,actionSymbol:"-",actionAllLabel:"Unstage all changes",getActionLabel:K=>`Unstage ${K}`,onActionFile:K=>k([K],"unstage"),onActionAll:K=>k(K,"unstage"),onViewDiff:K=>X(K,!0),onRevertFile:$,showRevertActions:!1,accent:!0}),t.length>0&&Y.push({id:"unstaged",title:"Changes",entries:t,actionSymbol:"+",actionAllLabel:"Stage all changes",getActionLabel:K=>`Stage ${K}`,onActionFile:K=>k([K],"stage"),onActionAll:K=>k(K,"stage"),onViewDiff:K=>X(K,!1),onRevertFile:$}),Y},[X,k,$,s,t]),ae=a.useCallback(Y=>e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsx("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:e.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:r?.current||n||""})}),e.jsx("div",{className:"min-h-0 flex-1",children:Y})]}),[n,r]);return n?c===null||c===!0&&!r?ae(e.jsx(Ee,{loading:!0,message:"Checking repository..."})):c===!1?ae(e.jsx(a.Suspense,{fallback:e.jsx(Ee,{loading:!0,message:"Loading last turn changes..."}),children:e.jsx(hr,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})):z.type==="diff"?e.jsx(fr,{path:z.path,diff:x,fileExists:I,error:q,onBack:()=>G({type:"list"}),onRetry:()=>W(Y=>Y+1)}):e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[e.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:r?.current||n}),e.jsx(zs,{syncAction:u,remotes:g,onFetch:Y=>E("fetch",Y),onSync:Y=>E("sync",Y),disabled:y!==null||m,aheadCount:r?.ahead??0,behindCount:r?.behind??0,trackingRemoteName:r?.tracking?.split("/")[0],hasUncommittedChanges:h.length>0})]}),h.length>0?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-3 pt-2",children:e.jsx(ur,{groups:ne,diffStats:r?.diffStats,revertingPaths:v,onRevertAll:T,isRevertingAll:f,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:L})}),e.jsx("div",{className:"shrink-0 border-t border-border/40 px-3 pb-3 pt-3",children:e.jsx(Is,{stagedCount:s.length,commitMessage:C,onCommitMessageChange:H,onCommit:()=>{if(!C.trim()){R.error("Enter a commit message");return}if(s.length===0){R.error("Select at least one file to commit");return}A({pushAfter:!1})},onCommitAndPush:()=>{if(!C.trim()){R.error("Enter a commit message");return}if(s.length===0){R.error("Select at least one file to commit");return}A({pushAfter:!0})},commitAction:y,hasPendingIndexMutation:S})})]}):e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Ee,{icon:!0,message:"Working tree clean",description:"There are no changed files in this workspace."})})]}):ae(e.jsx(Ee,{message:"Select a session or directory to view Git status"}))},Ee=({message:n,description:r,loading:c=!1,icon:m=!1})=>e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[c?e.jsx(w,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,m?e.jsx(w,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),r?e.jsx("p",{className:"typography-meta text-muted-foreground",children:r}):null]})}),fr=({path:n,diff:r,fileExists:c,error:m,onBack:h,onRetry:s})=>{const t=a.useMemo(()=>ks(n)||"text",[n]);return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[e.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back",onClick:h,children:e.jsx(w,{name:"arrow-left",className:"size-5"})}),e.jsx("div",{className:"min-w-0 flex-1 px-2",children:e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:n})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:c?m?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),e.jsx("p",{className:"typography-meta text-muted-foreground",children:m}),e.jsx(_,{type:"button",size:"sm",variant:"outline",onClick:s,children:"Retry"})]})}):r?r.isBinary?e.jsx(Ee,{icon:!0,message:"Content of this file cannot be viewed."}):Qa(n)?e.jsx(Ee,{icon:!0,message:"Image diffs are not available in mobile Changes yet."}):e.jsx(Rs,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:e.jsx(Fs,{original:r.original,modified:r.modified,language:t,fileName:n,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):e.jsx(Ee,{loading:!0,message:"Loading diff..."}):e.jsx(Ee,{icon:!0,message:"File is no longer changed",description:"Go back to Changes and refresh the list."})})]})},js=Es(()=>vs(()=>import("./DiffView-C76KYB1I.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(n=>({default:n.DiffView}))),pr=15e3,gr=40,xr=20,Eo=({isActive:n,chrome:r="desktop",initialDiffPath:c=null,initialDiffStaged:m=!1,gitHeaderSlot:h=null})=>{const{git:s}=ut(),t=Xa(),g=Lt(i=>i.currentSessionId),{profiles:u,globalIdentity:y,defaultGitIdentityId:C,loadProfiles:S,loadGlobalIdentity:v,loadDefaultGitIdentityId:f}=un(os(i=>({profiles:i.profiles,globalIdentity:i.globalIdentity,defaultGitIdentityId:i.defaultGitIdentityId,loadProfiles:i.loadProfiles,loadGlobalIdentity:i.loadGlobalIdentity,loadDefaultGitIdentityId:i.loadDefaultGitIdentityId}))),l=en(t??null),d=tn(t??null),E=sn(t??null),k=an(t??null),$=nn(t??null),T=rn(t??null),H=on(t??null),{setActiveDirectory:A,fetchAll:L,ensureAll:M,fetchStatus:z,fetchBranches:G,fetchLog:x,setLogMaxCount:B,fetchIdentity:q,prefetchDiffs:Q,clearDiffCache:U,moveStatusPathsOptimistically:W,restoreStatus:I,bumpIndexRevision:X}=ln(os(i=>({setActiveDirectory:i.setActiveDirectory,fetchAll:i.fetchAll,ensureAll:i.ensureAll,fetchStatus:i.fetchStatus,fetchBranches:i.fetchBranches,fetchLog:i.fetchLog,setLogMaxCount:i.setLogMaxCount,fetchIdentity:i.fetchIdentity,prefetchDiffs:i.prefetchDiffs,clearDiffCache:i.clearDiffCache,moveStatusPathsOptimistically:i.moveStatusPathsOptimistically,restoreStatus:i.restoreStatus,bumpIndexRevision:i.bumpIndexRevision})));a.useRef(null);const ne=a.useRef(null),ae=a.useRef(null),Y=a.useRef(null),K=a.useRef(!0);a.useEffect(()=>()=>{K.current=!1},[]);const O=a.useCallback(()=>{ne.current!==null&&(window.clearTimeout(ne.current),ne.current=null)},[]),N=a.useCallback(i=>{O(),ne.current=window.setTimeout(()=>{ne.current=null,ot(i)===ot(t)&&z(i,s,{silent:!0})},pr)},[O,t,z,s]);a.useEffect(()=>O,[O]);const F=a.useCallback(()=>{ae.current!==null&&(window.clearTimeout(ae.current),ae.current=null)},[]),o=a.useCallback(()=>{ae.current===null&&(ae.current=window.setTimeout(()=>{ae.current=null,Y.current?.()},0))},[]),D=a.useCallback(async(i,p,b)=>{if(p==="stage"){if(s.stageGitFiles){await s.stageGitFiles(i,b);return}await Promise.all(b.map(j=>s.stageGitFile(i,j)));return}if(s.unstageGitFiles){await s.unstageGitFiles(i,b);return}await Promise.all(b.map(j=>s.unstageGitFile(i,j)))},[s]),V=a.useMemo(()=>ir({runMutation:({directory:i,direction:p,paths:b})=>D(i,p,b),onMutationComplete:({directory:i})=>{X(i),N(i)},onMutationError:({directory:i,direction:p,rollback:b},j)=>{b?.(),X(i),N(i);const P=p==="stage"?"Failed to stage changes":"Failed to unstage changes";R.error(j instanceof Error?j.message:P)},onPathsComplete:i=>{Gt(p=>{const b=new Set(p);return i.forEach(j=>b.delete(j)),b})},scheduleFlush:o}),[X,D,o,N]);a.useEffect(()=>(Y.current=V.flush,()=>{Y.current=null}),[V]),a.useEffect(()=>()=>V.clear(),[V]),a.useEffect(()=>F,[F]);const se=a.useMemo(()=>t?On(t):null,[t]),[oe,he]=a.useState(se?.commitMessage??""),le=a.useRef(null),[Ge,We]=a.useState(null),[Ms,ht]=a.useState(!1),[mt,At]=a.useState(null),[ge,Ds]=a.useState(25),[Ls,Bt]=a.useState(!1),{triggerFireworks:Ps}=hn(),Tt=a.useRef(new Map),Ke=a.useRef(0),ft=a.useCallback(()=>{Ke.current+=1,K.current&&Bt(!0)},[]),pt=a.useCallback(()=>{Ke.current=Math.max(0,Ke.current-1),K.current&&Ke.current===0&&Bt(!1)},[]),[gt,qe]=a.useState(new Set),[As,Gt]=a.useState(new Set),[xt,Ot]=a.useState(!1),[_t,Bs]=a.useState([]),[br,Ts]=a.useState(0),[Gs,Ht]=a.useState(!1),Ut=As.size>0||V.size()>0||V.isRunning();a.useCallback(()=>{const i=le.current;i&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{i.scrollTo({top:i.scrollHeight,behavior:"smooth"})})})},[]);const{expandedCommitHashes:Os,commitFilesMap:_s,loadingCommitHashes:Hs,handleCopyCommitHash:Us,handleToggleCommit:Vs}=Wn(t,s),{conflictDialogOpen:Ws,setConflictDialogOpen:xe,conflictFiles:Ks,setConflictFiles:be,conflictOperation:Ye,setConflictOperation:ye,persistConflictState:je,clearConflictState:me}=rr({currentSessionId:g,currentDirectory:t}),[qs,bt]=a.useState([]),[Vt,yt]=a.useState(null),[Ys,Wt]=a.useState(null),[Zs,jt]=a.useState(null),[Js,Ze]=a.useState([]),[Qs,vt]=a.useState(null),[Xs,Kt]=a.useState(!1),[wt,ea]=a.useState(100),[ta,sa]=a.useState(0),[fe,Je]=a.useState(null),[aa,Le]=a.useState(null),[na,Nt]=a.useState(!1),[Ct,qt]=a.useState("merge"),[St,Yt]=a.useState("");a.useEffect(()=>{t&&_n(t,{directory:t,commitMessage:oe})},[oe,t]),a.useEffect(()=>{n&&(S(),v(),f())},[n,S,v,f]),a.useEffect(()=>{if(!n)return;if(!t||!s?.getRemoteUrl){yt(null);return}let i=!1;return s.getRemoteUrl(t).then(p=>{i||yt(p)}).catch(()=>{i||yt(null)}),()=>{i=!0}},[n,t,s]);const Qe=a.useCallback(async()=>{if(!t||!s?.getRemotes){bt([]);return}try{const i=await s.getRemotes(t);K.current&&bt(i)}catch{K.current&&bt([])}},[t,s]);a.useEffect(()=>{n&&Qe()},[n,Qe]),a.useEffect(()=>{n&&t&&(A(t),M(t,s))},[n,t,A,M,s]),a.useEffect(()=>{if(n&&t)return cn.onGitRefreshHint(i=>{ot(i.directory)===ot(t)&&(i.paths?.length&&U(t,i.paths),z(t,s,{silent:!0}))})},[n,U,t,z,s]);const ee=a.useCallback(async(i=!0)=>{if(t)try{await Promise.all([z(t,s),G(t,s)])}catch(p){if(i){const b=p instanceof Error?p.message:"Failed to refresh repository";R.error(b)}}},[t,s,z,G]),re=a.useCallback(async()=>{t&&await x(t,s,ge)},[t,s,x,ge]),kt=a.useCallback(async()=>{t&&await q(t,s)},[t,s,q]);a.useEffect(()=>{if(!n||!t||!s?.hasLocalIdentity||l!==!0)return;const i=typeof C=="string"?C.trim():"";if(!i||i==="global"||Tt.current.get(t)===i)return;let b=!1;return(async()=>{try{const P=await s.hasLocalIdentity?.(t);if(b||P===!0)return;ft(),await s.setGitIdentity(t,i),Tt.current.set(t,i),await kt()}catch(P){console.warn("Failed to auto-apply default git identity:",P)}finally{b||pt()}})(),()=>{b=!0}},[n,ft,t,C,pt,s,l,kt]);const ce=a.useMemo(()=>d?[...d.files??[]].sort((p,b)=>p.path.localeCompare(b.path)):[],[d]),Se=a.useMemo(()=>ce.filter(ls),[ce]),Zt=a.useMemo(()=>ce.filter(gn),[ce]);a.useEffect(()=>{if(!t||ce.length===0)return;const i=[],p=new Set,b=P=>{!P||p.has(P)||(p.add(P),i.push(P))};if(Se.forEach(P=>b(P.path)),r==="mobile"&&_t.forEach(b),ce.slice(0,xr).forEach(P=>b(P.path)),i.length===0)return;const j=window.setTimeout(()=>{Q(t,s,i,{maxFiles:gr})},120);return()=>{window.clearTimeout(j)}},[ce,r,t,s,_t,Q,Se]);const Jt=i=>i?.pushed[0]?.remote||d?.tracking?.split("/")[0]||ve.find(p=>p.name==="origin")?.name||ve[0]?.name||"origin",Rt=async(i,p)=>{if(t){We(i);try{const b=j=>{const P=`${j.name}/`,Z=d?.tracking?.startsWith(P)?d.tracking.slice(P.length):void 0;return{remote:j.name,branch:Z,rebase:!0}};if(i==="fetch"){if(!p)throw new Error("No remote available for fetch");await s.gitFetch(t,{remote:p.name}),R.success(`Fetched from ${p.name}`)}else if(i==="pull"){if(!p)throw new Error("No remote available for pull");const j=await s.gitPull(t,b(p));R.success(j.files.length===1?`Pulled ${j.files.length} file from ${p.name}`:`Pulled ${j.files.length} files from ${p.name}`)}else if(i==="push"){const j=await s.gitPush(t);R.success(`Pushed to ${Jt(j)}`)}else if(i==="sync"){if(!p)throw new Error("No remote available for sync");let j=0,P=!1;await s.gitFetch(t,{remote:p.name});const Z=await s.getGitStatus(t);if((Z.behind??0)>0){if((Z.files?.length??0)>0){R.error("Commit or stash your changes before syncing");return}j=(await s.gitPull(t,b(p))).files.length}((await s.getGitStatus(t)).ahead??0)>0&&(await s.gitPush(t),P=!0),j>0&&P?R.success(j===1?`Pulled ${j} file from ${p.name} and pushed to upstream`:`Pulled ${j} files from ${p.name} and pushed to upstream`):j>0?R.success(j===1?`Pulled ${j} file from ${p.name}`:`Pulled ${j} files from ${p.name}`):P?R.success(`Pushed to ${p.name}`):R.success("Already up to date")}await ee(!1),await re()}catch(b){const j=b instanceof Error?b.message:`${i==="sync"?"Sync Changes":i==="pull"?"Pull":i} failed`;R.error(j)}finally{We(null)}}},ra=a.useCallback(async(i,p)=>{if(!t)throw new Error("No active directory");const b=await s.getGitFileDiff(t,{path:i,staged:p||void 0});return{original:b.original??"",modified:b.modified??"",isBinary:b.isBinary}},[t,s]),ia=a.useCallback(async i=>{if(!t)return;const p=i.name.trim();if(!p){R.error("Remote name is required");return}if(p==="origin"){R.error("Cannot remove the origin remote");return}Wt(p);try{await s.removeRemote(t,{remote:p}),R.success(`Removed remote ${p}`),await Promise.all([ee(!1),Qe()])}catch(b){const j=b instanceof Error?b.message:`Failed to remove ${p}`;R.error(j)}finally{Wt(null)}},[t,s,Qe,ee]),Et=async(i={})=>{if(!t)return;if(!oe.trim()){R.error("Enter a commit message");return}const p=Se.map(j=>j.path).sort();if(p.length===0){R.error("Stage at least one file to commit");return}const b=i.pushAfter?"commitAndPush":"commit";At(b);try{if(await s.createGitCommit(t,oe.trim(),{files:p,stageFiles:[]}),X(t),R.success("Commit created"),he(""),await ee(),i.pushAfter){const j=d?.tracking?.split("/")[0],P=ve.find(Pa=>Pa.name===j)??ve[0];if(!P)throw new Error("No remote available");We("sync");const Z=`${P.name}/`,ie=d?.tracking?.startsWith(Z)?d.tracking.slice(Z.length):void 0;await s.gitFetch(t,{remote:P.name});const J=await s.getGitStatus(t);if((J.behind??0)>0){if((J.files?.length??0)>0){R.error("Commit or stash your changes before syncing"),await ee(!1);return}await s.gitPull(t,{remote:P.name,branch:ie,rebase:!0})}const ue=await s.getGitStatus(t);let Be;(ue.ahead??0)>0&&(Be=await s.gitPush(t)),R.success(`Pushed to ${Jt(Be)}`),r!=="mobile"&&Ps(),await ee(!1)}else await ee(!1);await re(),Ts(j=>j+1)}catch(j){const P=j instanceof Error?j.message:"Failed to create commit";R.error(P)}finally{At(null),i.pushAfter&&We(null)}},oa=async(i,p)=>{if(!t||!d)return;const b=d.current??null,j=p?.name??"origin";try{await s.createBranch(t,i,b??"HEAD"),R.success(`Created branch ${i}`),await s.checkoutBranch(t,i);let P=!1;try{await s.gitPush(t,{remote:j,branch:i,options:["--set-upstream"]}),P=!0}catch(Z){const ie=Z instanceof Error?Z.message:`Unable to push new branch to ${j}.`;R.warning("Branch created locally, but failed to set upstream.",{description:e.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",ie]})})}await ee(),await re(),P&&R.success(`Set upstream for ${i} to ${j}`)}catch(P){const Z=P instanceof Error?P.message:"Failed to create branch";throw R.error(Z),P}},la=async(i,p)=>{if(t)try{await s.renameBranch(t,i,p),R.success(`Renamed ${i} to ${p}`),await ee(),await re()}catch(b){const j=b instanceof Error?b.message:`Failed to rename ${i} to ${p}`;R.error(j)}},ca=async i=>{if(!t)return;const p=i.replace(/^remotes\//,"");if(d?.current!==p)try{await s.checkoutBranch(t,p),R.success(`Checked out ${p}`),await ee(),await re()}catch(b){const j=b instanceof Error?b.message:`Failed to checkout ${p}`;R.error(j)}},da=async i=>{if(t){ft();try{await s.setGitIdentity(t,i.id),R.success(`Applied identity: ${i.name}`),await kt()}catch(p){const b=p instanceof Error?p.message:"Failed to apply identity";R.error(b)}finally{pt()}}},{localBranches:Qt,remoteBranches:Xe,effectiveRemotes:ve,currentBranch:Pe,baseBranch:et,branchScopeAvailable:Ae,updateTargetBranch:ua}=er({branches:E,status:d,remotes:qs,remoteUrl:Vt,git:s}),{availableIdentities:ha,activeIdentityProfile:ma}=nr({profiles:u,globalIdentity:y,currentIdentity:$,remoteUrl:Vt}),Xt=Se.length,fa=T||Ge!==null||mt!==null,es=!!Pe;a.useEffect(()=>{if(!t||!s||!k?.all?.length||!Pe||!et||!Ae){Le(null);return}let i=!1;return(async()=>{try{const b=await s.getGitLog(t,{from:et,to:"HEAD",maxCount:ge});if(i)return;const j=new Set((b?.all??[]).map(Z=>Z.hash).filter(Z=>typeof Z=="string"&&Z.length>0));if(j.size===0){Le(null);return}const P=k.all.findIndex(Z=>!j.has(Z.hash));if(P===0){Le(null);return}if(P===-1){Le({insertBeforeIndex:k.all.length,branchName:Pe,direction:"up"});return}Le({insertBeforeIndex:P,branchName:Pe,direction:"up"})}catch{i||Le(null)}})(),()=>{i=!0}},[et,Ae,Pe,t,s,k,ge]),a.useEffect(()=>{vt(null)},[t]),a.useEffect(()=>{if(fe!=="graph"||!t){fe!=="graph"&&vt(null);return}let i=!1;return Kt(!0),s.getGitLog(t,{maxCount:wt,all:!0}).then(p=>{i||vt(p)}).catch(p=>{console.error("Failed to fetch graph log:",p)}).finally(()=>{i||Kt(!1)}),()=>{i=!0}},[fe,t,wt,ta,s]);const pa=a.useCallback((i,p)=>{if(!t||i.length===0)return;const b=Array.from(new Set(i));Gt(P=>{const Z=new Set(P);return b.forEach(ie=>Z.add(ie)),Z});const j=W(t,b,p);V.enqueue({directory:t,direction:p,paths:new Set(b),rollback:()=>I(t,j)}),o()},[t,V,W,I,o]),ga=a.useCallback(async i=>{if(t){qe(p=>{const b=new Set(p);return b.add(i),b});try{await s.revertGitFile(t,i,{scope:"working"}),R.success(`Reverted ${i}`),await ee(!1)}catch(p){const b=p instanceof Error?p.message:"Failed to revert changes";R.error(b)}finally{qe(p=>{const b=new Set(p);return b.delete(i),b})}}},[t,ee,s]),tt=a.useCallback(async(i,p,b="all")=>{if(!t||i.length===0)return;const j=Array.from(new Set(i));if(xt||j.some(J=>gt.has(J)))return;const P=new Set(Se.map(J=>J.path)),Z=b==="all"&&j.some(J=>P.has(J));p&&Ot(!0),qe(J=>{const ue=new Set(J);return j.forEach(Be=>ue.add(Be)),ue});const ie=[];try{if(await Promise.all(j.map(async J=>{try{await s.revertGitFile(t,J,{scope:b})}catch(ue){ie.push({path:J,message:ue instanceof Error?ue.message:"Failed to revert changes"})}})),Z&&ie.length<j.length&&X(t),await ee(!1),ie.length===0)R.success(j.length===1?`Reverted ${j.length} file`:`Reverted ${j.length} files`);else if(ie.length===j.length)R.error(ie[0]?.message||"Failed to revert changes");else{const J=j.length-ie.length;R.warning(J===1?`Reverted ${J} file, ${ie.length} failed`:`Reverted ${J} files, ${ie.length} failed`)}}finally{qe(J=>{const ue=new Set(J);return j.forEach(Be=>ue.delete(Be)),ue}),p&&Ot(!1)}},[X,t,s,xt,ee,gt,Se]),xa=a.useCallback(async i=>{await tt(i,!0)},[tt]);a.useCallback(async i=>{await tt(i,!1,"working")},[tt]);const ba=a.useCallback(()=>ht(!0),[]),st=a.useCallback(i=>{const p=i instanceof Error?i.message.toLowerCase():"";return p.includes("uncommitted changes")||p.includes("local changes")||p.includes("your local changes would be overwritten")||p.includes("please commit your changes or stash them")||p.includes("cannot rebase: you have unstaged changes")||p.includes("error: cannot pull with rebase")},[]),ke=a.useCallback((i,p)=>{Ze(b=>[...b,{message:i,status:p,timestamp:Date.now()}])},[]),de=a.useCallback((i,p)=>{Ze(b=>{if(b.length===0)return b;const j=[...b];return j[j.length-1]={...j[j.length-1],status:i,...p?{message:p}:{}},j})},[]),at=a.useCallback(()=>{Ze([])},[]),ya=a.useCallback(()=>{Ze([]),jt(null)},[]),nt=a.useCallback(i=>{const p=i.trim(),b=new Set(ve.map(P=>P.name)),j=p.indexOf("/");if(j>0){const P=p.slice(0,j),Z=p.slice(j+1);if(b.has(P)&&Z)return{branch:p,remote:P,remoteBranch:Z}}for(const P of ve){const Z=`${P.name}/${p}`;if(Xe.includes(Z))return{branch:Z,remote:P.name,remoteBranch:p}}return{branch:p,remote:null,remoteBranch:null}},[ve,Xe]),ja=a.useCallback(async i=>{if(!t)return;jt("merge"),at();const p=d?.current,b=nt(i);try{b.remote&&b.remoteBranch&&(ke(`Fetching ${b.remote}/${b.remoteBranch}...`,"running"),await s.gitFetch(t,{remote:b.remote,branch:b.remoteBranch}),de("done",`Fetched ${b.remote}/${b.remoteBranch}`)),ke(`Merging ${b.branch} into ${p}...`,"running");const j=await s.merge(t,{branch:b.branch});j.conflict?(de("error","Merge conflicts detected"),be(j.conflictFiles??[]),ye("merge"),xe(!0),je(t,j.conflictFiles??[],"merge")):(de("done",`Merged ${b.branch} into ${p}`),me(),ke("Refreshing repository status...","running"),await ee(),await re(),de("done","Repository status updated"))}catch(j){if(st(j))de("error","Uncommitted changes detected"),qt("merge"),Yt(b.branch),Nt(!0);else{const P=j instanceof Error?j.message:`Failed to merge ${b.branch}`;de("error",P)}}},[t,s,d,nt,ee,re,st,je,me,ke,de,at]),va=a.useCallback(async i=>{if(!t)return;jt("rebase"),at();const p=d?.current,b=nt(i);try{b.remote&&b.remoteBranch&&(ke(`Fetching ${b.remote}/${b.remoteBranch}...`,"running"),await s.gitFetch(t,{remote:b.remote,branch:b.remoteBranch}),de("done",`Fetched ${b.remote}/${b.remoteBranch}`)),ke(`Rebasing ${p} onto ${b.branch}...`,"running");const j=await s.rebase(t,{onto:b.branch});j.conflict?(de("error","Rebase conflicts detected"),be(j.conflictFiles??[]),ye("rebase"),xe(!0),je(t,j.conflictFiles??[],"rebase")):(de("done",`Rebased ${p} onto ${b.branch}`),me(),ke("Refreshing repository status...","running"),await ee(),await re(),de("done","Repository status updated"))}catch(j){if(st(j))de("error","Uncommitted changes detected"),qt("rebase"),Yt(b.branch),Nt(!0);else{const P=j instanceof Error?j.message:`Failed to rebase onto ${b.branch}`;de("error",P)}}},[t,s,d,nt,ee,re,st,je,me,ke,de,at]),wa=a.useCallback(async()=>{if(t)try{Ye==="merge"?(await s.abortMerge(t),R.success("Merge aborted")):(await s.abortRebase(t),R.success("Rebase aborted")),me(),await ee(),await re()}catch(i){const p=i instanceof Error?i.message:`Failed to abort ${Ye}`;R.error(p)}},[t,s,Ye,ee,re,me]),Na=a.useMemo(()=>d?.files?d.files.filter(i=>i.index==="U"||i.working_dir==="U"||i.index==="A"&&i.working_dir==="A"||i.index==="D"&&i.working_dir==="D").length:0,[d?.files]),Ca=a.useCallback(async()=>{if(t)try{const i=!!d?.mergeInProgress?.head,p=!!(d?.rebaseInProgress?.headName||d?.rebaseInProgress?.onto);if(i){const b=await s.continueMerge(t);b.conflict?(be(b.conflictFiles??[]),ye("merge"),xe(!0),je(t,b.conflictFiles??[],"merge"),R.error("Merge conflicts detected")):(me(),R.success("Merge completed"),await ee(),await re())}else if(p){const b=await s.continueRebase(t);b.conflict?(be(b.conflictFiles??[]),ye("rebase"),xe(!0),je(t,b.conflictFiles??[],"rebase"),R.error("Rebase conflicts detected")):(me(),R.success("Rebase step completed"),await ee(),await re())}}catch(i){const p=i instanceof Error?i.message:"Failed to continue operation";R.error(p)}},[t,s,d,ee,re,je,me]),Sa=a.useCallback(async()=>{if(t)try{!!d?.mergeInProgress?.head?(await s.abortMerge(t),R.success("Merge aborted")):(await s.abortRebase(t),R.success("Rebase aborted")),me(),await ee(),await re()}catch(i){const p=i instanceof Error?i.message:"Failed to abort operation";R.error(p)}},[t,s,d,ee,re,me]),ka=a.useCallback(()=>{if(!t)return;const p=!!d?.mergeInProgress?.head?"merge":"rebase",b=d?.files?.filter(j=>j.index==="U"||j.working_dir==="U").map(j=>j.path)??[];b.length>0&&be(b),ye(p),xe(!0)},[t,d]),Ra=a.useCallback(async i=>{if(!t)return;const p=d?.current,b=Ct,j=St,P=(d?.files??[]).some(ls);try{await s.stash(t,{message:`Auto-stash before ${b} with ${j}`,includeUntracked:!0}),P&&X(t)}catch(J){const ue=J instanceof Error?J.message:"Failed to stash changes";R.error(ue);return}let Z=!1,ie=!1;try{if(b==="merge"){const J=await s.merge(t,{branch:j});J.conflict?(ie=!0,be(J.conflictFiles??[]),ye("merge"),xe(!0)):(Z=!0,R.success(`Merged ${j} into ${p||""}`))}else{const J=await s.rebase(t,{onto:j});J.conflict?(ie=!0,be(J.conflictFiles??[]),ye("rebase"),xe(!0)):(Z=!0,R.success(`Rebased ${p||""} onto ${j}`))}if(i&&Z)try{await s.stashPop(t),X(t),R.success("Stashed changes restored")}catch(J){const ue=J instanceof Error?J.message:"Failed to restore stash";R.error(ue)}else i&&ie&&R.info("Stash restored manually required");await ee(),await re()}catch(J){if(i)try{await s.stashPop(t),X(t)}catch{}throw J}},[X,t,s,d,Ct,St,ee,re]),Ea=a.useCallback(i=>{Ds(i),t&&(B(t,i),x(t,s,i))},[t,x,s,B]),Fa=a.useCallback(i=>{ea(i)},[]),za=a.useCallback(()=>{Je(null),t&&(z(t,s),G(t,s),x(t,s,ge))},[t,z,G,x,ge,s]),Ia=a.useCallback(i=>{if(i.conflict){if(i.operation==="cherry-pick"||i.operation==="revert"){R.error("Conflict",{description:`Conflicts in: ${i.conflictFiles?.join(", ")??"unknown files"}. Resolve manually and commit, or abort with git cherry-pick/revert --abort.`}),t&&(z(t,s),G(t,s),x(t,s,ge));return}be(i.conflictFiles??[]),ye(i.operation),xe(!0),t&&je(t,i.conflictFiles??[],i.operation)}},[be,ye,xe,je,t,z,G,x,ge,s]),[ts,ss]=a.useState(()=>ce.length>0?"all":"branch"),[$a,Ma]=a.useState(null),rt=`${t??""}:${ce.length>0?"nonempty":"empty"}`,as=a.useRef(rt);a.useEffect(()=>{as.current!==rt&&(as.current=rt,ss(ce.length>0?"all":"branch"))},[ce.length,rt]);const ns=a.useCallback(i=>{ss(i)},[]),Da=a.useCallback(i=>{Ma(i)},[]),Ft=l===!0&&d?e.jsx(Sn,{status:d,localBranches:Qt,remoteBranches:Xe,branchInfo:E?.branches,syncAction:Ge,remotes:ve,onFetch:i=>Rt("fetch",i),onSync:i=>Rt("sync",i),onRemoveRemote:ia,removingRemoteName:Ys,onCheckoutBranch:ca,onCreateBranch:oa,onRenameBranch:la,activeIdentityProfile:ma,availableIdentities:ha,onSelectIdentity:da,isApplyingIdentity:Ls,isWorktreeMode:!1,upstreamTarget:d.upstreamComparison?`${d.upstreamComparison.remote}/${d.upstreamComparison.branch}`:null,onOpenHistory:()=>Je("history"),onOpenGraph:()=>Je("graph"),onOpenStashes:ba,onOpenUpdateBranch:es?()=>Ht(!0):void 0,diffScope:ts,onDiffScopeChange:ns,allCount:ce.length,workingCount:Zt.length,stagedCount:Xt,branchAvailable:Ae,diffHeaderState:$a}):null,La=Ft?h?Aa.createPortal(e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:Ft}),h):e.jsx("div",{className:"flex h-10 shrink-0 items-center gap-1 border-b border-border px-2",children:Ft}):null;return r==="mobile"?e.jsx(mr,{currentDirectory:t??null,status:d,isGitRepo:l,isLoadingStatus:T,changeEntries:ce,stagedChangeEntries:Se,unstagedChangeEntries:Zt,effectiveRemotes:ve,syncAction:Ge,commitAction:mt,commitMessage:oe,hasPendingIndexMutation:Ut,revertingPaths:gt,isRevertingAll:xt,initialDiffPath:c,initialDiffStaged:m,onSyncAction:(i,p)=>{Rt(i,p)},onMoveChangePaths:pa,onRevertFile:i=>{ga(i)},onRevertAll:xa,onCommitMessageChange:he,onCommit:i=>{Et(i)},onVisiblePathsChange:Bs,loadDiff:ra}):t?l===null||l===!0&&!d?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"typography-ui-label",children:"Checking repository..."})]})}):l===!1?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(a.Suspense,{fallback:null,children:e.jsx(js,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0,toolbarSlot:h})})}):e.jsxs("div",{className:te("flex h-full flex-col overflow-hidden"),children:[La,t&&(d?.mergeInProgress?.head||d?.rebaseInProgress?.headName||d?.rebaseInProgress?.onto)&&e.jsx(Vn,{mergeInProgress:d?.mergeInProgress,rebaseInProgress:d?.rebaseInProgress,onContinue:Ca,onAbort:Sa,onResolveWithAI:ka,conflictCount:Na,isLoading:T}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col",children:(ce?.length??0)>0||Ae?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:null,children:e.jsx(js,{diffScope:ts,onDiffScopeChange:ns,branchBase:Ae?et:null,branchHead:Ae?Pe:null,showOpenInEditorAction:!0,hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0,hideToolbar:!0,onHeaderControlsStateChange:Da})})}),ce.length>0?e.jsx("div",{ref:le,className:"shrink-0 px-4 pb-4 pt-2",children:e.jsx(Is,{stagedCount:Xt,commitMessage:oe,onCommitMessageChange:he,onCommit:()=>Et({pushAfter:!1}),onCommitAndPush:()=>Et({pushAfter:!0}),commitAction:mt,hasPendingIndexMutation:Ut})}):null]}):e.jsx(Un,{onOpenStashes:()=>ht(!0)})})}),e.jsx(Tn,{currentDirectory:t,isUpdateBranchDialogOpen:Gs,setIsUpdateBranchDialogOpen:Ht,branchOperation:Zs,currentBranch:d?.current,localBranches:Qt,remoteBranches:Xe,updateTargetBranch:ua,onMerge:ja,onRebase:va,isBusy:fa,operationLogs:Js,onOperationComplete:ya,canShowBranchWorkflows:es,gitLogDialogMode:fe,setGitLogDialogMode:Je,onRefreshHistory:()=>{if(fe==="graph"){sa(i=>i+1);return}t&&x(t,s,ge)},isLogRefreshing:fe==="graph"?Xs:H,log:fe==="graph"?Qs??k:k,maxCount:fe==="graph"?wt:ge,onMaxCountChange:fe==="graph"?Fa:Ea,expandedCommitHashes:Os,onToggleCommit:Vs,commitFilesMap:_s,loadingCommitHashes:Hs,onCopyHash:Us,historyBranchDivider:aa,onConflict:fe==="graph"?Ia:void 0,onActionSuccess:fe==="graph"?za:void 0,isStashesDialogOpen:Ms,setIsStashesDialogOpen:ht,hasUncommittedChanges:(d?.files?.length??0)>0,hasStagedChanges:Se.length>0,uncommittedFileCount:d?.files?.length??0,onStashesChanged:async i=>{t&&i?.affectsIndex&&X(t),await ee(!1),await re()},conflictDialogOpen:Ws,setConflictDialogOpen:xe,conflictFiles:Ks,conflictOperation:Ye,onAbortConflict:wa,onClearConflictState:me,stashDialogOpen:na,setStashDialogOpen:Nt,stashDialogOperation:Ct,stashDialogBranch:St,onConfirmStashAndRetry:Ra})]}):e.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:e.jsx("p",{className:"typography-ui-label text-muted-foreground",children:"Select a session or directory to view Git status"})})};export{Eo as GitView};
8
+ ${JSON.stringify({directory:m,operation:d.operation,headInfo:d.headInfo,statusPorcelain:d.statusPorcelain,unmergedFiles:d.unmergedFiles,diff:d.diff},null,2)}`;return{visibleText:Q,instructionsText:U,payloadText:W}},[d,m,h]),H=()=>{s(),r(!1)},A=()=>{t?.(),r(!1)},L=async()=>{const x=await T();if(!x){R.error("No conflict details available");return}if(!y){R.error("No active session",{description:"Open or create a session to resolve conflicts."});return}C(x.visibleText,"replace"),S([{text:x.instructionsText,synthetic:!0},{text:x.payloadText,synthetic:!0}]),v("chat"),t?.(),r(!1)},M=async()=>{const x=await T();if(!x){R.error("No conflict details available");return}u({directoryOverride:m,initialPrompt:x.visibleText,syntheticParts:[{text:x.instructionsText,synthetic:!0},{text:x.payloadText,synthetic:!0}]}),v("chat"),t?.(),r(!1)},z=h==="merge"?"Merge":"Rebase",G=d?.unmergedFiles||c;return e.jsx(Fe,{open:n,onOpenChange:r,children:e.jsx(ze,{className:"max-w-md w-[calc(100vw-2rem)]",children:e.jsxs("div",{className:"flex flex-col gap-4 overflow-hidden",children:[e.jsxs($e,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e.jsx(Ie,{children:`${z} conflicts detected`})]}),e.jsx(Me,{children:`Resolve the ${h} conflicts to continue.`})]}),f&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"typography-meta",children:"Loading conflict details..."})]}),k&&e.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:`Failed to load conflict details: ${k}`}),G.length>0&&e.jsxs("div",{className:"space-y-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Conflicted files:"}),e.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:G.length})]}),e.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:e.jsx("ul",{className:"space-y-1",children:G.map(x=>e.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:x,children:x},x))})})]}),d?.headInfo&&e.jsxs("div",{className:"space-y-1 overflow-hidden",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"HEAD information:"}),e.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:d.headInfo})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-2",children:[e.jsxs(_,{variant:"default",onClick:()=>{M()},disabled:f||!d,className:"w-full gap-2",children:[f?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"add",className:"size-4"}),"Resolve in new session"]}),e.jsxs(_,{variant:"outline",onClick:()=>{L()},disabled:f||!d||!y,className:"w-full gap-2",children:[f?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"chat-1",className:"size-4"}),"Resolve in current session"]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(_,{variant:"ghost",size:"sm",onClick:A,className:"flex-1",children:"Continue later"}),e.jsx(_,{variant:"destructive",size:"sm",onClick:H,className:"flex-1",children:`Abort ${z}`})]})]})]})})})},Re=8,Rn=({laned:n,totalLanes:r,isExpanded:c})=>{const{lane:m,color:h,connectors:s}=n,g=Math.max(r,m+1)*Re+Re/2,u=a.useRef(null),y=a.useRef(null);return a.useLayoutEffect(()=>{const C=u.current,S=y.current;if(!C||!S)return;const v=C.offsetHeight;if(v===0)return;const f=window.devicePixelRatio||1;S.width=g*f,S.height=v*f;const l=S.getContext("2d");if(!l)return;l.scale(f,f),l.clearRect(0,0,g,v);const d=v/2,E=m*Re+Re/2,k=getComputedStyle(S),I=k.getPropertyValue("--surface-muted-foreground").trim()||k.color,T=L=>{if(!L.startsWith("var("))return L;const M=L.slice(4,-1).trim();return k.getPropertyValue(M).trim()||I},H=[...s].sort((L,M)=>{const z=G=>G==="branch-out"||G==="merge-in";return(z(L.type)?1:0)-(z(M.type)?1:0)});for(const L of H){const M=L.fromLane*Re+Re/2,z=L.toLane*Re+Re/2,G=L.type==="passing"?.72:L.type==="branch-out"||L.type==="merge-in"?.95:1;switch(l.beginPath(),l.strokeStyle=T(L.color),l.globalAlpha=G,l.lineWidth=1.25,l.lineCap="round",L.type){case"passing":case"commit-lane":l.moveTo(M,0),l.lineTo(M,v);break;case"top-stub":l.moveTo(M,0),l.lineTo(M,d);break;case"bottom-stub":l.moveTo(M,d),l.lineTo(M,v);break;case"branch-out":{const x=(d+v)/2;l.moveTo(E,d),l.bezierCurveTo(E,x,z,x,z,v);break}case"merge-in":{const x=d/2;l.moveTo(M,0),l.bezierCurveTo(M,x,E,x,E,d);break}default:continue}l.stroke(),l.globalAlpha=1}const A=k.getPropertyValue("--background").trim()||k.getPropertyValue("--surface-background").trim();l.beginPath(),l.arc(E,d,4,0,Math.PI*2),l.fillStyle=T(h),l.fill(),l.beginPath(),l.arc(E,d,5,0,Math.PI*2),l.strokeStyle=A||I,l.lineWidth=2,l.stroke()},[n,m,h,s,r,c,g]),e.jsx("div",{ref:u,style:{width:g,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},children:e.jsx("canvas",{ref:y,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}})})},cs=15e3,ds=500,us=12,hs=8*1024*1024,ms=n=>typeof n=="string"?0:(n.original?.length??0)+(n.modified?.length??0),fs=n=>{if(n.size<=us){let h=0;for(const s of n.values())h+=ms(s);if(h<=hs)return n}const r=Array.from(n.entries()).reverse(),c=new Map;let m=0;for(const[h,s]of r){if(c.size>=us)continue;const t=ms(s);m+t>hs&&c.size>0||(c.set(h,s),m+=t)}return new Map(Array.from(c.entries()).reverse())};function ps(n,r){const c=new Date(n);return Number.isNaN(c.getTime())?n:Ta(c,r,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function En(n){switch(n){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 Fn(n){return n?n.split(",").map(r=>r.trim()).filter(Boolean).map(r=>{const c=r.startsWith("HEAD ->");return{label:c?r.replace("HEAD -> ",""):r.replace("tag: ",""),isHead:c,isTag:r.startsWith("tag: ")}}):[]}const zn=a.memo(({entry:n,mode:r="history",laned:c,totalLanes:m,isExpanded:h,onToggle:s,files:t,isLoadingFiles:g,onCopyHash:u,directory:y,onConflict:C,onActionSuccess:S})=>{const{git:v}=ut(),f=Pt(o=>o.timeFormatPreference),l=r==="graph",d={checkout:"Check out this commit as detached HEAD?",cherryPick:"Cherry-pick this commit onto the current branch?",revert:"Stage a revert of this commit?",merge:"Merge this commit into the current branch?",rebase:"Rebase current branch onto this commit?",resetSoft:"Soft reset — HEAD moves, staged changes preserved.",resetMixed:"Mixed reset — HEAD moves, changes unstaged.",resetHard:"Hard reset — HEAD moves, all uncommitted changes permanently discarded."},E={soft:"Soft — keep staged",mixed:"Mixed — unstage changes",hard:"Hard — discard all changes"},[k,I]=a.useState(null),[T,H]=a.useState(!1),[A,L]=a.useState(""),[M,z]=a.useState(null),[G,x]=a.useState(new Set),[B,q]=a.useState(new Map),[Q,U]=a.useState(new Set),W=async()=>{if(y){I("checkout");try{await v.checkoutCommit(y,n.hash),R.success("Checked out (detached HEAD)"),S?.()}catch(o){R.error(String(o.message))}finally{I(null)}}},$=async()=>{if(!(!y||!A.trim())){I("createBranch");try{await v.createBranch(y,A.trim(),n.hash),H(!1),L(""),S?.()}catch(o){R.error(String(o.message))}finally{I(null)}}},X=async()=>{if(y){I("cherryPick");try{const o=await v.cherryPick(y,n.hash);o.conflict?C?.({conflict:!0,conflictFiles:o.conflictFiles,operation:"cherry-pick"}):S?.()}catch(o){R.error(String(o.message))}finally{I(null)}}},ne=async()=>{if(y){I("revert");try{const o=await v.revertCommit(y,n.hash);o.conflict?C?.({conflict:!0,conflictFiles:o.conflictFiles,operation:"revert"}):S?.()}catch(o){R.error(String(o.message))}finally{I(null)}}},ae=async(o,D=!1)=>{if(!(!y||k!==null)){I("reset");try{await v.resetToCommit(y,n.hash,o,D),S?.()}catch(V){R.error(String(V.message))}finally{I(null)}}},Y=async()=>{if(!M)return;const o=M;switch(z(null),o){case"checkout":return W();case"cherryPick":return X();case"revert":return ne();case"merge":return K();case"rebase":return O();case"resetSoft":return ae("soft");case"resetMixed":return ae("mixed");case"resetHard":return ae("hard",!0)}},K=async()=>{if(y){I("merge");try{const o=await v.merge(y,{branch:n.hash});o.conflict?C?.({conflict:!0,conflictFiles:o.conflictFiles,operation:"merge"}):S?.()}catch(o){R.error(String(o.message))}finally{I(null)}}},O=async()=>{if(y){I("rebase");try{const o=await v.rebase(y,{onto:n.hash});o.conflict?C?.({conflict:!0,conflictFiles:o.conflictFiles,operation:"rebase"}):S?.()}catch(o){R.error(String(o.message))}finally{I(null)}}},N=a.useCallback(async o=>{const D=o.path;if(!y){q(V=>new Map(V).set(D,"error"));return}q(V=>fs(new Map(V).set(D,"loading")));try{const se=(v.getCommitFileDiff??mn)(y,n.hash,o.path,!1),oe=new Promise((le,Ge)=>{setTimeout(()=>Ge(new Error(`Timed out after ${cs}ms`)),cs)}),he=await Promise.race([se,oe]);q(le=>fs(new Map(le).set(D,he)))}catch{q(V=>new Map(V).set(D,"error"))}},[y,n.hash,v.getCommitFileDiff]),F=a.useCallback(async o=>{const D=o.path;if(o.changeType==="R"||o.isBinary){x(he=>{const le=new Set(he);return le.has(D)?le.delete(D):le.add(D),le});return}const V=B.get(D);if(G.has(D)&&V&&V!=="error"){x(he=>{const le=new Set(he);return le.delete(D),le});return}x(he=>{const le=new Set(he);return le.add(D),le}),!(V&&V!=="error"||o.insertions+o.deletions>ds&&!Q.has(D))&&await N(o)},[B,Q,N,G]);return e.jsxs("li",{children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":h,onClick:s,onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),s())},className:te("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",l?"hover:bg-[var(--interactive-hover)]/40":h?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[l&&c&&m!==void 0?e.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:e.jsx(Rn,{laned:c,totalLanes:m,isExpanded:h})}):e.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[l?(()=>{const o=Fn(n.refs);return o.length>0?e.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:o.map(D=>e.jsx("span",{className:te("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",D.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":D.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:D.label},D.label))}):null})():null,e.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[e.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e.jsx("span",{className:"shrink-0",children:"·"}),e.jsx("span",{className:"truncate min-w-0",title:ps(n.date,f),children:ps(n.date,f)})]}),e.jsx("span",{className:"shrink-0",children:"·"}),e.jsx("code",{className:"shrink-0 font-mono",children:n.hash.slice(0,8)}),e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx(_,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:o=>{o.stopPropagation(),u(n.hash)},children:e.jsx(w,{name:"file-copy",className:"size-3"})})}),e.jsx(Ce,{sideOffset:8,children:"Copy SHA"})]})]})]})]}),h&&e.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[l&&M?e.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[e.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:d[M]}),e.jsxs(_,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:k!==null,onClick:o=>{o.stopPropagation(),Y()},children:[k!==null?e.jsx(w,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Confirm"]}),e.jsx(_,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:k!==null,onClick:o=>{o.stopPropagation(),z(null)},children:"Cancel"})]}):l?e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("checkout")},children:"Checkout"}),T?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{autoFocus:!0,value:A,onChange:o=>L(o.target.value),onKeyDown:o=>{o.key==="Enter"&&$(),o.key==="Escape"&&(H(!1),L(""))},placeholder:"Branch name",className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),e.jsxs(_,{variant:"outline",size:"xs",className:"h-6",disabled:!A.trim()||k!==null,onClick:o=>{o.stopPropagation(),$()},children:[k==="createBranch"?e.jsx(w,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Create"]})]}):e.jsx(_,{variant:"outline",size:"xs",className:"h-6",onClick:o=>{o.stopPropagation(),H(!0)},children:"Create branch here"}),e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("cherryPick")},children:"Cherry-pick"}),e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("revert")},children:"Revert"}),e.jsxs(He,{children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>o.stopPropagation(),children:[k==="reset"?e.jsx(w,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,"Reset..."]})}),e.jsx(Ve,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(o=>e.jsx(pe,{disabled:k!==null,onSelect:D=>{D.stopPropagation(),z(`reset${o.charAt(0).toUpperCase()+o.slice(1)}`)},children:E[o]},o))})]}),e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("merge")},children:"Merge into current"}),e.jsx(_,{variant:"outline",size:"xs",className:"h-6",disabled:k!==null,onClick:o=>{o.stopPropagation(),z("rebase")},children:"Rebase onto this"})]}):null,g?e.jsxs("div",{className:"flex items-center gap-2 py-2",children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"typography-micro text-muted-foreground",children:"Loading files..."})]}):t.length===0?e.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:"No files"}):e.jsx("ul",{className:"space-y-0.5 py-2",children:t.map(o=>e.jsxs("li",{children:[e.jsxs("button",{type:"button",onClick:()=>F(o),className:te("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",G.has(o.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[e.jsx("span",{className:te("font-semibold w-3 text-center shrink-0",En(o.changeType)),children:o.changeType}),e.jsx("span",{className:"truncate text-foreground min-w-0",title:o.path,children:o.path}),!o.isBinary&&e.jsxs("span",{className:"shrink-0",children:[e.jsxs("span",{style:{color:"var(--status-success)"},children:["+",o.insertions]}),e.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),e.jsxs("span",{style:{color:"var(--status-error)"},children:["-",o.deletions]})]}),o.isBinary&&e.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:"Binary"}),e.jsx(w,{name:G.has(o.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),G.has(o.path)&&e.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:o.changeType==="R"?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Renamed file — diff not supported"}):o.isBinary?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Binary file — no diff available"}):(()=>{const D=o.insertions+o.deletions;if(!Q.has(o.path)&&D>ds)return e.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${D} changed lines)`}),e.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),e.jsx(_,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{U(se=>new Set(se).add(o.path)),N(o)},children:"Render anyway"})]});const V=B.get(o.path);return V==="loading"||V===void 0?e.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:"Loading diff..."}):V==="error"?e.jsx("button",{type:"button",onClick:()=>F(o),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:"Failed to load diff. Click to retry."}):e.jsx(Fs,{original:V.original,modified:V.modified,language:ks(o.path)||"",fileName:o.path,renderSideBySide:!1,layout:"inline"})})()})]},o.path))})]})]})}),gs=["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 lt(n){return gs[n%gs.length]}function $n(n){if(n.length===0)return[];const r=[],c=[];for(let m=0;m<n.length;m++){const h=n[m],s=[];for(let f=0;f<r.length;f++)r[f]===h.hash&&s.push(f);let t=s.length>0?s[0]:-1;if(t===-1){const f=r.indexOf(null);f!==-1?t=f:(t=r.length,r.push(null))}const g=s.slice(1),u=lt(t),y=r[t]===h.hash,C=h.parents.length>0;C?r[t]=h.parents[0]:r[t]=null;const S=[];for(let f=1;f<h.parents.length;f++){const l=h.parents[f],d=r.indexOf(l);if(d!==-1)S.push(d);else{const E=r.indexOf(null),k=E!==-1?E:r.length;r[k]=l,k===r.length&&r.push(l),S.push(k)}}const v=[];y&&C?v.push({fromLane:t,toLane:t,color:u,type:"commit-lane"}):y&&!C?v.push({fromLane:t,toLane:t,color:u,type:"top-stub"}):!y&&C&&v.push({fromLane:t,toLane:t,color:u,type:"bottom-stub"});for(const f of g)v.push({fromLane:f,toLane:t,color:lt(f),type:"merge-in"}),r[f]=null;for(const f of S)v.push({fromLane:t,toLane:f,color:lt(f),type:"branch-out"});for(let f=0;f<r.length;f++)r[f]!==null&&f!==t&&(S.includes(f)||v.push({fromLane:f,toLane:f,color:lt(f),type:"passing"}));c.push({commit:h,lane:t,color:u,connectors:v})}return c}const In=[{label:"25 commits",value:25},{label:"50 commits",value:50},{label:"100 commits",value:100}],Mn=({mode:n="history",log:r,isLogLoading:c,logMaxCount:m,onLogMaxCountChange:h,expandedCommitHashes:s,onToggleCommit:t,commitFilesMap:g,loadingCommitHashes:u,onCopyHash:y,directory:C,showHeader:S=!0,contentMaxHeightClassName:v="max-h-[50vh]",branchDivider:f=null,onConflict:l,onActionSuccess:d})=>{const[E,k]=a.useState(!0),I=n==="graph",T=a.useMemo(()=>I&&r?$n(r.all):[],[I,r]),H=a.useMemo(()=>Math.max(1,...T.map(W=>W.lane+1)),[T]),A=a.useMemo(()=>new Map(T.map(W=>[W.commit.hash,W])),[T]);if(!r)return null;const L=f!==null&&f.insertBeforeIndex>0&&f.insertBeforeIndex<r.all.length,M=f!==null&&f.insertBeforeIndex===r.all.length,z=L||M,G=L?r.all.slice(0,f.insertBeforeIndex):M?r.all:[],x=L?r.all.slice(f.insertBeforeIndex):[],B=f?.direction==="down"?e.jsx(w,{name:"arrow-down-s",className:"size-3.5"}):e.jsx(w,{name:"arrow-up",className:"size-3.5"}),q=W=>e.jsx("ul",{className:"divide-y divide-border/60",children:W.map($=>e.jsx(zn,{entry:$,mode:n,laned:I?A.get($.hash):void 0,totalLanes:I?H:void 0,isExpanded:s.has($.hash),onToggle:()=>t($.hash),files:g.get($.hash)??[],isLoadingFiles:u.has($.hash),onCopyHash:y,directory:C,onConflict:l,onActionSuccess:d},$.hash))}),Q=r.all.length>=m?e.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:e.jsx(_,{type:"button",variant:"ghost",size:"xs",onClick:()=>h(m+25),disabled:c,className:"px-3 text-muted-foreground hover:text-foreground",children:c?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(w,{name:"loader-4",className:"size-3 animate-spin"}),"Loading..."]}):"Load more"})}):null,U=e.jsx(Ga,{outerClassName:`min-h-0 ${v}`,className:"h-full w-full",children:r.all.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-4",children:e.jsx("p",{className:"typography-ui-label text-muted-foreground",children:"No commits found"})}):z&&f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-0",children:[G.length>0?e.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:q(G)}):null,e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[e.jsx("span",{className:"h-px flex-1 bg-border/60"}),e.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[e.jsx("span",{className:"truncate",title:f.branchName,children:f.branchName}),B]}),e.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),x.length>0?e.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:q(x)}):null]}),Q]}):e.jsxs(e.Fragment,{children:[q(r.all),Q]})});return S?e.jsxs(xn,{open:E,onOpenChange:k,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[e.jsxs(bn,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[e.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"History"}),e.jsxs("div",{className:"flex items-center gap-2",children:[E&&e.jsx("div",{onClick:W=>W.stopPropagation(),onPointerDown:W=>W.stopPropagation(),children:e.jsxs(Oa,{value:String(m),onValueChange:W=>h(Number(W)),disabled:c,children:[e.jsx(_a,{size:"sm",className:"w-auto",disabled:c,children:e.jsx(Ha,{placeholder:"Commits"})}),e.jsx(Ua,{children:In.map(W=>e.jsx(Va,{value:String(W.value),children:W.label},W.value))})]})}),E?e.jsx(w,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):e.jsx(w,{name:"arrow-down-s",className:"size-4 text-muted-foreground"})]})]}),e.jsx(yn,{children:U})]}):z?e.jsx("section",{className:"h-full min-h-0",children:U}):e.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:U})},Dn=a.memo(function({mode:r,onOpenChange:c,onRefresh:m,isRefreshing:h,log:s,maxCount:t,onMaxCountChange:g,expandedCommitHashes:u,onToggleCommit:y,commitFilesMap:C,loadingCommitHashes:S,onCopyHash:v,directory:f,branchDivider:l,onConflict:d,onActionSuccess:E}){return r?e.jsx(Fe,{open:r!==null,onOpenChange:c,children:e.jsxs(ze,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[e.jsxs($e,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(Ie,{children:r==="graph"?"Graph":"History"}),e.jsxs(_,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:m,disabled:h,title:"Refresh","aria-label":"Refresh",children:[e.jsx(w,{name:"refresh",className:te("size-4",h&&"animate-spin")}),"Refresh"]})]}),e.jsx(Me,{children:"Browse recent commits and inspect changed files."})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Mn,{mode:r==="graph"?"graph":"history",log:s,isLogLoading:h,logMaxCount:t,onLogMaxCountChange:g,expandedCommitHashes:u,onToggleCommit:y,commitFilesMap:C,loadingCommitHashes:S,onCopyHash:v,directory:f,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:r==="graph"?null:l,onConflict:r==="graph"?d:void 0,onActionSuccess:r==="graph"?E:void 0})})]})}):null}),Ln=({open:n,onOpenChange:r,operation:c,targetBranch:m,onConfirm:h})=>{const[s,t]=a.useState(!0),[g,u]=a.useState(!1),y=c==="merge"?"Merge":"Rebase",C=async()=>{u(!0);try{await h(s),r(!1)}catch(v){const f=v instanceof Error?v.message:`Failed to ${c}`;R.error(f)}finally{u(!1)}},S=()=>{g||r(!1)};return e.jsx(Fe,{open:n,onOpenChange:g?void 0:r,children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs($e,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),e.jsx(Ie,{children:"Uncommitted Changes"})]}),e.jsx(Me,{children:`Stash your local changes before starting the ${c}.`})]}),e.jsxs("div",{className:"py-2",children:[e.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:"This will:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[e.jsx("li",{children:"Stash your uncommitted changes"}),e.jsxs("li",{children:[c==="merge"?"Merge":"Rebase"," ",c==="merge"?"with":"onto"," ",e.jsx("span",{className:"font-mono text-primary",children:m})]}),s&&e.jsx("li",{children:"Restore your stashed changes"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 py-2",children:[e.jsx(Wa,{checked:s,onChange:t,disabled:g,ariaLabel:"Restore stashed changes after operation"}),e.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!g&&t(!s),children:`Restore stashed changes after ${c}`})]}),e.jsxs(_e,{className:"gap-2",children:[e.jsx(_,{variant:"ghost",size:"sm",onClick:S,disabled:g,children:"Cancel"}),e.jsx(_,{variant:"default",size:"sm",onClick:C,disabled:g,className:"gap-1.5",children:g?e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),"Processing..."]}):`${y}`})]})]})})},Pn=({open:n,onOpenChange:r,directory:c,hasUncommittedChanges:m,hasStagedChanges:h=!1,uncommittedFileCount:s,onChanged:t})=>{const{git:g}=ut(),[u,y]=a.useState([]),[C,S]=a.useState(!1),[v,f]=a.useState(""),[l,d]=a.useState(""),[E,k]=a.useState(null),[I,T]=a.useState({}),H=a.useCallback(async()=>{if(c){S(!0);try{const x=await g.listGitStashes(c);y(x.stashes),T({})}catch(x){R.error(x instanceof Error?x.message:"Failed to load stashes")}finally{S(!1)}}},[c,g]);a.useEffect(()=>{n&&H()},[H,n]),a.useEffect(()=>{if(!n||!c||u.length===0)return;let x=!1;const B=u.map(q=>q.ref);return g.countGitStashFiles(c,B).then(q=>{x||T(q.counts)}).catch(()=>{}),()=>{x=!0}},[c,g,n,u]);const A=a.useMemo(()=>{const x=v.trim().toLowerCase();return x?u.filter(B=>`${B.ref} ${B.message} ${B.relativeTime}`.toLowerCase().includes(x)):u},[v,u]),L=a.useCallback(async x=>{await H(),await t?.(x)},[H,t]),M=async()=>{if(!(!c||E)){k("create");try{const x=await g.stashGitChanges(c,{message:l.trim()||void 0});x.created?(R.success("Changes stashed"),d("")):R.info("No local changes to stash"),await L({affectsIndex:!!(x.created&&h)})}catch(x){R.error(x instanceof Error?x.message:"Failed to stash changes")}finally{k(null)}}},z=async(x,B)=>{if(!(!c||E)&&!(B==="drop"&&!window.confirm(`Drop ${x.ref}?`))){k(`${B}:${x.ref}`);try{B==="apply"&&await g.applyGitStash(c,{ref:x.ref}),B==="pop"&&await g.popGitStash(c,{ref:x.ref}),B==="drop"&&await g.dropGitStash(c,{ref:x.ref});const q=B==="apply"?"Stash applied":B==="pop"?"Stash popped":"Stash dropped";R.success(q),await L({affectsIndex:B!=="drop"})}catch(q){const Q=B==="apply"?"Failed to apply stash":B==="pop"?"Failed to pop stash":"Failed to drop stash";R.error(q instanceof Error?q.message:Q),await L({affectsIndex:B!=="drop"})}finally{k(null)}}},G=E!==null;return e.jsx(Fe,{open:n,onOpenChange:r,children:e.jsxs(ze,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[e.jsxs($e,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(w,{name:"archive-stack",className:"h-5 w-5"}),"Stashes"]}),e.jsx(Me,{children:"Save, restore, and clean up Git stashes for this repository."})]}),e.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(is,{value:l,onChange:x=>d(x.target.value),placeholder:"Stash name",disabled:G||!m,className:"flex-1"}),e.jsxs(_,{onClick:M,disabled:!m||G||!c,children:[E==="create"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"inbox-archive",className:"size-4"}),`Stash ${s} files`]})]}),e.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:"Untracked files are included automatically."})]}),e.jsxs("div",{className:"relative mt-2",children:[e.jsx(w,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(is,{value:v,onChange:x=>f(x.target.value),placeholder:"Search stashes",className:"pl-9"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:C?e.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:e.jsx(w,{name:"loader-4",className:"size-5 animate-spin"})}):A.length===0?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:v?"No matching stashes.":"No stashes yet."}):A.map((x,B)=>e.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[e.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[e.jsx("p",{className:"typography-small truncate text-foreground",children:x.message||"Untitled stash"}),e.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("span",{children:B===0&&!v.trim()?"Latest":`#${B+1}`})}),e.jsx(Ce,{sideOffset:6,children:x.ref})]})," · ",x.relativeTime," · ",typeof I[x.ref]=="number"?`${I[x.ref]} files`:"counting files..."]})]}),e.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[e.jsx(zt,{label:"Apply",loading:E===`apply:${x.ref}`,onClick:()=>z(x,"apply"),disabled:G,children:e.jsx(w,{name:"inbox-unarchive",className:"size-4"})}),e.jsx(zt,{label:"Pop",loading:E===`pop:${x.ref}`,onClick:()=>z(x,"pop"),disabled:G,children:e.jsx(w,{name:"inbox-unarchive-fill",className:"size-4"})}),e.jsx(zt,{label:"Drop",loading:E===`drop:${x.ref}`,onClick:()=>z(x,"drop"),disabled:G,destructive:!0,children:e.jsx(w,{name:"delete-bin",className:"size-4"})})]})]},x.ref))})]})})},zt=({label:n,loading:r,disabled:c,destructive:m,onClick:h,children:s})=>e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":n,"aria-busy":r||void 0,className:te("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",m?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground"),onClick:h,disabled:c,children:r?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):s})}),e.jsx(Ce,{sideOffset:6,children:n})]}),An=({currentBranch:n,localBranches:r,remoteBranches:c,onMerge:m,onRebase:h,disabled:s=!1,isOperating:t=!1,operationLogs:g=[],onOperationComplete:u,mode:y="dialog",defaultTargetBranch:C})=>{const[S,v]=a.useState(!1),[f,l]=a.useState("merge"),[d,E]=a.useState(null),[k,I]=a.useState(!1),[T,H]=a.useState(""),A=a.useRef(null),L=a.useRef(null),M=s||t,z=n||"current branch",G=g.length>0&&g.every(O=>O.status==="done"||O.status==="error"),x=g.some(O=>O.status==="error");a.useEffect(()=>{L.current&&(L.current.scrollTop=L.current.scrollHeight)},[g]);const B=a.useMemo(()=>{const O=T.toLowerCase(),N=new Set(c.map(o=>o.slice(o.indexOf("/")+1)).filter(Boolean)),F=r.filter(o=>o!==n&&!N.has(o));return O?F.filter(o=>o.toLowerCase().includes(O)):F},[T,r,n,c]),q=a.useMemo(()=>{const O=T.toLowerCase();return O?c.filter(N=>N.toLowerCase().includes(O)):c},[T,c]),Q=a.useCallback(()=>C&&(c.includes(C)||r.includes(C))?C:null,[C,r,c]),U=()=>{v(!0),E(Q()),l("merge"),H("")},W=O=>{E(O),I(!1),H("")},$=()=>{d&&(f==="merge"?m(d):h(d))},X=()=>{t||(E(null),l("merge"),H(""),v(!1))},ne=()=>{t&&!G||(G&&u?.(),E(null),l("merge"),H(""),v(!1))};a.useEffect(()=>{k||H("")},[k]),a.useEffect(()=>{y==="dialog"||d||E(Q())},[y,Q,d]);const K=t?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{ref:L,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:e.jsx("div",{className:"space-y-2",children:g.map((O,N)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"mt-0.5 shrink-0",children:[O.status==="running"&&e.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),O.status==="done"&&e.jsx(w,{name:"check",className:"size-3.5 text-success"}),O.status==="error"&&e.jsx(w,{name:"close",className:"size-3.5 text-destructive"}),O.status==="pending"&&e.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),e.jsx("span",{className:te("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})]},N))})}),G?y==="dialog"?e.jsx(_e,{children:e.jsx(_,{variant:"default",size:"sm",onClick:ne,children:x?"Close":"Done"})}):e.jsx("div",{className:"flex justify-end",children:e.jsx(_,{variant:"default",size:"sm",onClick:ne,children:x?"Close":"Done"})}):null]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Operation"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>l("merge"),className:te("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",f==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{name:"git-merge",className:te("size-4",f==="merge"?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:te("typography-ui-label",f==="merge"?"text-foreground":"text-muted-foreground"),children:"Merge"})]}),e.jsx("p",{className:"typography-micro text-muted-foreground",children:"Create a merge commit and preserve branch history."})]}),e.jsxs("button",{type:"button",onClick:()=>l("rebase"),className:te("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",f==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{name:"git-branch",className:te("size-4",f==="rebase"?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:te("typography-ui-label",f==="rebase"?"text-foreground":"text-muted-foreground"),children:"Rebase"})]}),e.jsx("p",{className:"typography-micro text-muted-foreground",children:"Replay your commits on top of the selected branch."})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"typography-meta text-muted-foreground",children:f==="merge"?`Branch to merge into ${z}`:"Branch to rebase onto"}),e.jsxs(He,{open:k,onOpenChange:I,modal:!1,children:[e.jsx(Ue,{asChild:!0,children:e.jsxs("button",{type:"button",className:te(Ka({size:"default"}),"w-full"),children:[e.jsx("span",{className:te("truncate",!d&&"text-muted-foreground"),children:d||"Select Branch"}),e.jsx(w,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),e.jsx(Ve,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:e.jsxs(ws,{className:"h-full min-h-0",children:[e.jsx(Ns,{ref:A,placeholder:"Search branches...",value:T,onValueChange:H,onKeyDown:O=>O.stopPropagation()}),e.jsxs(Cs,{className:"h-full min-h-0",disableHorizontal:!0,children:[e.jsx(Ss,{children:"No branches found."}),B.length>0&&e.jsx(Oe,{heading:"Local branches",children:B.map(O=>e.jsx(De,{onSelect:()=>W(O),children:e.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`local-${O}`))}),B.length>0&&q.length>0?e.jsx(Dt,{}):null,q.length>0&&e.jsx(Oe,{heading:"Remote branches",children:q.map(O=>e.jsx(De,{onSelect:()=>W(O),children:e.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`remote-${O}`))})]})]})})]})]}),d?e.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:e.jsx("p",{className:"typography-meta text-muted-foreground",children:f==="merge"?e.jsxs(e.Fragment,{children:["This will merge"," ",e.jsx("span",{className:"font-mono text-foreground",children:d})," ","into"," ",e.jsx("span",{className:"font-mono text-foreground",children:z})]}):e.jsxs(e.Fragment,{children:["This will rebase"," ",e.jsx("span",{className:"font-mono text-foreground",children:z})," ","onto"," ",e.jsx("span",{className:"font-mono text-foreground",children:d})]})})}):null,y==="dialog"?e.jsxs(_e,{className:"gap-2 pt-1",children:[e.jsx(_,{variant:"ghost",size:"sm",onClick:X,children:"Cancel"}),e.jsx(_,{variant:"default",size:"sm",onClick:$,disabled:!d,className:"gap-1.5",children:f==="merge"?e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"git-merge",className:"size-4"}),"Merge"]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"git-branch",className:"size-4"}),"Rebase"]})})]}):e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(_,{variant:"destructive",size:"sm",onClick:X,disabled:M,children:"Reset"}),e.jsx("div",{className:"flex-1"}),e.jsx(_,{variant:"default",size:"sm",onClick:$,disabled:M||!d,children:f==="merge"?"Merge":"Rebase"})]})]});return y==="bare"?K:y==="inline"?e.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[e.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:"Update branch"}),e.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Bring the latest changes into"," ",e.jsx("span",{className:"font-mono text-foreground",children:z}),"."]})]})}),e.jsx("div",{className:"pt-3",children:K})]}):e.jsxs(e.Fragment,{children:[e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsxs(_,{variant:"outline",size:"sm",className:"gap-1.5",onClick:U,disabled:M,children:[t?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"git-merge",className:"size-4"}),e.jsx("span",{children:"Merge/Rebase"})]})}),e.jsx(Ce,{sideOffset:8,children:"Update this branch from another branch."})]}),e.jsx(Fe,{open:S,onOpenChange:O=>{O?v(!0):ne()},children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs($e,{children:[e.jsx(Ie,{children:"Update branch"}),e.jsx(Me,{children:t?G?x?"Operation Failed":"Operation Completed":f==="merge"?"Merging In Progress":"Rebasing In Progress":e.jsxs(e.Fragment,{children:["Choose how to bring another branch into"," ",e.jsx("span",{className:"font-mono text-foreground",children:z}),"."]})})]}),K]})})]})},Bn=a.memo(function({open:r,onOpenChange:c,branchOperation:m,currentBranch:h,localBranches:s,remoteBranches:t,defaultTargetBranch:g,onMerge:u,onRebase:y,disabled:C,operationLogs:S,onOperationComplete:v,canShowBranchWorkflows:f}){return e.jsx(Fe,{open:r,onOpenChange:l=>{!l&&m!==null||c(l)},children:e.jsxs(ze,{className:"max-w-2xl min-h-[26rem]",children:[e.jsxs($e,{children:[e.jsx(Ie,{children:"Update branch"}),e.jsxs(Me,{children:["Bring the latest changes into"," ",e.jsx("span",{className:"font-mono text-foreground",children:h??""}),"."]})]}),f?e.jsx(An,{mode:"bare",currentBranch:h,localBranches:s,remoteBranches:t,defaultTargetBranch:g??void 0,onMerge:u,onRebase:y,disabled:C,isOperating:m!==null,operationLogs:S,onOperationComplete:v}):e.jsx("p",{className:"typography-meta text-muted-foreground",children:"Branch actions unavailable in this repository state"})]})})}),Tn=({currentDirectory:n,isUpdateBranchDialogOpen:r,setIsUpdateBranchDialogOpen:c,branchOperation:m,currentBranch:h,localBranches:s,remoteBranches:t,updateTargetBranch:g,onMerge:u,onRebase:y,isBusy:C,operationLogs:S,onOperationComplete:v,canShowBranchWorkflows:f,gitLogDialogMode:l,setGitLogDialogMode:d,onRefreshHistory:E,isLogRefreshing:k,log:I,maxCount:T,onMaxCountChange:H,expandedCommitHashes:A,onToggleCommit:L,commitFilesMap:M,loadingCommitHashes:z,onCopyHash:G,historyBranchDivider:x,onConflict:B,onActionSuccess:q,isStashesDialogOpen:Q,setIsStashesDialogOpen:U,hasUncommittedChanges:W,hasStagedChanges:$,uncommittedFileCount:X,onStashesChanged:ne,conflictDialogOpen:ae,setConflictDialogOpen:Y,conflictFiles:K,conflictOperation:O,onAbortConflict:N,onClearConflictState:F,stashDialogOpen:o,setStashDialogOpen:D,stashDialogOperation:V,stashDialogBranch:se,onConfirmStashAndRetry:oe})=>e.jsxs(e.Fragment,{children:[e.jsx(Bn,{open:r,onOpenChange:c,branchOperation:m,currentBranch:h,localBranches:s,remoteBranches:t,defaultTargetBranch:g,onMerge:u,onRebase:y,disabled:C,operationLogs:S,onOperationComplete:v,canShowBranchWorkflows:f}),e.jsx(Dn,{mode:l,onOpenChange:he=>{he||d(null)},onRefresh:E,isRefreshing:k,log:I,maxCount:T,onMaxCountChange:H,expandedCommitHashes:A,onToggleCommit:L,commitFilesMap:M,loadingCommitHashes:z,onCopyHash:G,directory:n??void 0,branchDivider:x,onConflict:B,onActionSuccess:q}),e.jsx(Pn,{open:Q,onOpenChange:U,directory:n,hasUncommittedChanges:W,hasStagedChanges:$,uncommittedFileCount:X,onChanged:ne}),n&&e.jsx(kn,{open:ae,onOpenChange:Y,conflictFiles:K,directory:n,operation:O,onAbort:N,onClearState:F}),e.jsx(Ln,{open:o,onOpenChange:D,operation:V,targetBranch:se,onConfirm:oe})]}),Gn=20,Te=new Map;function On(n){return Te.get(n)??null}function _n(n,r){if(Te.delete(n),Te.set(n,r),Te.size>Gn){const c=Te.keys().next().value;c!==void 0&&Te.delete(c)}}const $t=38,ct=200,Hn=({value:n,onChange:r,placeholder:c,disabled:m=!1,hasTouchInput:h=!1,isMobile:s=!1})=>{const t=a.useRef(null);return a.useLayoutEffect(()=>{const g=t.current;if(!g)return;const u=document.activeElement===g,y=()=>{g.style.height=`${$t}px`;const S=g.scrollHeight,v=Math.min(Math.max(S,$t),ct);g.style.height=`${v}px`,g.style.overflowY=S>ct?"auto":"hidden",S>ct&&!u&&(g.scrollTop=g.scrollHeight)};y();const C=window.requestAnimationFrame(y);return()=>{window.cancelAnimationFrame(C)}},[n]),e.jsx("textarea",{ref:t,value:n,onChange:g=>r(g.target.value),placeholder:c??"Commit message",rows:1,disabled:m,autoCorrect:h?"on":"off",autoCapitalize:h?"sentences":"off",spellCheck:s,className:te("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",m&&"opacity-50"),style:{minHeight:$t,maxHeight:ct}})},$s=({stagedCount:n,commitMessage:r,onCommitMessageChange:c,onCommit:m,onCommitAndPush:h,commitAction:s,hasPendingIndexMutation:t=!1})=>{const g=n>0,u=r.trim()&&g&&s===null&&!t,{isMobile:y,hasTouchInput:C}=qa();return e.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[e.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[e.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"Commit"}),g?null:e.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:"Stage files to enable commit."})]}),e.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[e.jsx(Hn,{value:r,onChange:c,placeholder:"Commit message",disabled:s!==null,hasTouchInput:C,isMobile:y}),e.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"flex-1"}),e.jsx(_,{size:"sm",variant:"outline",onClick:m,disabled:!u,className:"commit-actions__btn whitespace-nowrap","aria-label":"Commit aria label",children:s==="commit"?e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"commit-actions__label",children:"Committing..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"git-commit",className:"size-4"}),e.jsx("span",{className:"commit-actions__label",children:"Commit"})]})}),y?e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx(_,{variant:"default",size:"sm",onClick:()=>h(),disabled:!u,className:"h-7 w-7 p-0","aria-label":"Commit and sync",children:s==="commitAndPush"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"arrow-up",className:"size-3.5"})})}),e.jsx(Ce,{side:"top",children:e.jsx("p",{children:"Commit & sync"})})]}):e.jsx(_,{size:"sm",variant:"default",onClick:()=>h(),disabled:!u,className:"commit-actions__btn","aria-label":"Commit and sync",children:s==="commitAndPush"?e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:"Syncing..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{name:"arrow-up",className:"size-3.5"}),e.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:"Commit & sync"})]})})]})]})]})},Un=({onOpenStashes:n})=>e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[e.jsx(w,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:"Working tree clean"}),e.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:"All changes have been committed"}),n?e.jsxs(_,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[e.jsx(w,{name:"archive-stack",className:"size-4"}),"Stashes"]}):null]}),Vn=({mergeInProgress:n,rebaseInProgress:r,onContinue:c,onAbort:m,onResolveWithAI:h,conflictCount:s=0,isLoading:t=!1})=>{const[g,u]=a.useState(null),y=n&&n.head,C=r&&(r.headName||r.onto),S=y?"merge":C?"rebase":null;if(!S)return null;const v=async()=>{u("continue");try{await c()}finally{u(null)}},f=async()=>{u("abort");try{await m()}finally{u(null)}},l=g!==null,d=s>0,E=S==="merge"?"Merge":"Rebase";let k="";n?k=n.message?`Merging: ${n.message}`:`Merging ${n.head}`:r&&(k=r.headName?`Rebasing ${r.headName} onto ${r.onto||""}`:"Rebase in progress");const I=d?s===1?`${E} in progress: ${s} conflict`:`${E} in progress: ${s} conflicts`:`${E} in progress`,T=d?"Resolve conflicts, then continue the operation.":"All conflicts resolved. Continue to finish the operation.";return e.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:e.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:I}),k&&e.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:k})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:T}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(_,{variant:"ghost",size:"sm",onClick:f,disabled:l||t,className:"gap-1.5",children:[g==="abort"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"close",className:"size-4"}),"Abort"]}),d?h&&e.jsx(_,{variant:"default",size:"sm",onClick:h,disabled:l||t,children:"Resolve with AI"}):e.jsxs(_,{variant:"default",size:"sm",onClick:v,disabled:l||t,className:"gap-1.5",children:[g==="continue"?e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):e.jsx(w,{name:"check",className:"size-4"}),"Continue"]})]})]})]})})};function Wn(n,r){const[c,m]=a.useState(new Set),[h,s]=a.useState(new Map),[t,g]=a.useState(new Set),u=a.useRef(h),y=a.useRef(t),C=a.useCallback(v=>{Ya(v).then(f=>{if(f.ok){R.success("Commit hash copied");return}R.error("Failed to copy")})},[]),S=a.useCallback(v=>{m(f=>{const l=new Set(f);return l.has(v)?l.delete(v):l.add(v),l})},[]);return a.useEffect(()=>{u.current=h},[h]),a.useEffect(()=>{y.current=t},[t]),a.useEffect(()=>{if(!n||!r)return;const v=Array.from(c).filter(l=>!u.current.has(l)&&!y.current.has(l));if(v.length===0)return;let f=!1;return g(l=>{const d=new Set(l);for(const E of v)d.add(E);return y.current=d,d}),Promise.all(v.map(l=>r.getCommitFiles(n,l).then(d=>({hash:l,files:d.files})).catch(d=>(console.error("Failed to fetch commit files:",d),{hash:l,files:[]})))).then(l=>{f||(s(d=>{const E=new Map(d);for(const{hash:k,files:I}of l)E.set(k,I);return u.current=E,E}),g(d=>{const E=new Set(d);for(const{hash:k}of l)E.delete(k);return y.current=E,E}))}),()=>{f=!0,g(l=>{let d=!1;const E=new Set(l);for(const k of v)E.delete(k)&&(d=!0);return d?(y.current=E,E):l})}},[c,n,r]),{expandedCommitHashes:c,commitFilesMap:h,loadingCommitHashes:t,handleCopyCommitHash:C,handleToggleCommit:S}}const Kn=n=>{const{remoteNames:r,localBranches:c,worktreeCreatedFromBranch:m,rootBranchHint:h,defaultBranch:s,headBranch:t}=n,g=typeof t=="string"?t.trim():"",u=f=>{if(!f)return"";let l=f.trim();if(!l||l==="HEAD")return"";if(c.includes(l))return l;l.startsWith("refs/heads/")&&(l=l.slice(11)),l.startsWith("heads/")&&(l=l.slice(6)),l.startsWith("remotes/")&&(l=l.slice(8));const d=l.indexOf("/");if(d>0){const E=l.slice(0,d);if(r.has(E)){const k=l.slice(d+1).trim();k&&(l=k)}}return l},y=f=>{const l=u(typeof f=="string"?f:"");return l&&l!==g?l:""},C=y(m);if(C)return C;const S=y(h);if(S)return S;const v=y(s);return v||(c.includes("main")?"main":c.includes("master")?"master":c.includes("develop")?"develop":"main")},qn=n=>{const{baseBranch:r,localBranches:c,remoteBranches:m}=n;return c.includes(r)?!0:m.some(h=>{const s=h.indexOf("/");return s>0&&h.slice(s+1)===r})},Yn=n=>n?n.filter(r=>!r.startsWith("remotes/")).sort():[],Zn=n=>n?n.filter(r=>r.startsWith("remotes/")).map(r=>r.replace(/^remotes\//,"")).sort():[],Jn=(n,r,c,m)=>{if(n.length>0)return n;const h=new Set,s=c?.trim();s&&s.includes("/")&&h.add(s.split("/")[0]);for(const t of r){const g=t.indexOf("/");g>0&&h.add(t.slice(0,g))}return h.size===0&&m&&h.add("origin"),Array.from(h).map(t=>({name:t,fetchUrl:m??"",pushUrl:m??""}))},Qn=(n,r)=>{const c=r?.trim().split("/")[0];return(c&&n?.[c])??n?.origin},Xn=(n,r,c)=>c?n.map(s=>s.name).map(s=>`${s}/${c}`).find(s=>r.includes(s))??c:null;function er({branches:n,status:r,remotes:c,remoteUrl:m,git:h}){const s=a.useMemo(()=>Yn(n?.all),[n?.all]),t=a.useMemo(()=>Zn(n?.all),[n?.all]),g=a.useMemo(()=>Jn(c,t,r?.tracking,m),[c,t,m,r?.tracking]),u=r?.current??null,y=a.useMemo(()=>Qn(n?.defaultBranches,r?.tracking),[n?.defaultBranches,r?.tracking]),C=a.useMemo(()=>Kn({remoteNames:new Set(g.map(f=>f.name)),localBranches:s,defaultBranch:y,headBranch:u}),[u,y,g,s]),S=!!(u&&C&&u!==C&&(r?.tracking||g.length>0)&&typeof h?.getGitRangeDiff=="function"&&qn({baseBranch:C,localBranches:s,remoteBranches:t})),v=a.useMemo(()=>Xn(g,t,C),[C,g,t]);return{localBranches:s,remoteBranches:t,effectiveRemotes:g,currentBranch:u,defaultBranch:y,baseBranch:C,branchScopeAvailable:S,updateTargetBranch:v}}const tr=n=>{if(!n)return null;try{let r=n.trim();r.startsWith("git@")&&(r=`https://${r.slice(4).replace(":","/")}`),r.endsWith(".git")&&(r=r.slice(0,-4));const c=new URL(r);return c.hostname+c.pathname}catch{return null}},sr=(n,r,c)=>{const m=new Map;r&&m.set(r.id,r);const h=tr(c);for(const s of n){if(s.authType!=="token"){m.set(s.id,s);continue}const t=s.host;if(!t){m.set(s.id,s);continue}if(!t.includes("/")){m.set(s.id,s);continue}h&&h===t&&m.set(s.id,s)}return Array.from(m.values())},ar=(n,r,c)=>{if(n?.userName&&n?.userEmail){const m=r.find(h=>h.userName===n.userName&&h.userEmail===n.userEmail);return m||(c&&c.userName===n.userName&&c.userEmail===n.userEmail?c:{id:"local-config",name:n.userName,userName:n.userName,userEmail:n.userEmail,sshKey:n.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return c??null};function nr({profiles:n,globalIdentity:r,currentIdentity:c,remoteUrl:m}){const h=a.useMemo(()=>sr(n,r,m),[n,r,m]),s=a.useMemo(()=>ar(c,n,r),[c,n,r]);return{availableIdentities:h,activeIdentityProfile:s}}function rr({currentSessionId:n,currentDirectory:r}){const[c,m]=a.useState(!1),[h,s]=a.useState([]),[t,g]=a.useState("merge"),u=a.useMemo(()=>n?`pichamber.conflict:${n}`:null,[n]),y=a.useCallback((S,v,f)=>{if(!u||typeof window>"u")return;const l={directory:S,conflictFiles:v,operation:f};window.localStorage.setItem(u,JSON.stringify(l))},[u]),C=a.useCallback(()=>{!u||typeof window>"u"||window.localStorage.removeItem(u)},[u]);return a.useEffect(()=>{if(!u||typeof window>"u"||!r)return;const S=window.localStorage.getItem(u);if(S)try{const v=JSON.parse(S);if(v.directory!==r){window.localStorage.removeItem(u);return}s(v.conflictFiles??[]),g(v.operation??"merge"),m(!0)}catch{window.localStorage.removeItem(u)}},[u,r]),{conflictDialogOpen:c,setConflictDialogOpen:m,conflictFiles:h,setConflictFiles:s,conflictOperation:t,setConflictOperation:g,persistConflictState:y,clearConflictState:C}}const ir=({runMutation:n,onMutationComplete:r,onMutationError:c,onPathsComplete:m,scheduleFlush:h})=>{const s=[];let t=!1;return{enqueue:u=>{const y=s[s.length-1];if(y?.directory===u.directory&&y.direction===u.direction){u.paths.forEach(C=>y.paths.add(C));return}s.push(u)},flush:()=>{if(t)return;const u=s.shift();if(!u)return;t=!0;const y={directory:u.directory,direction:u.direction,paths:Array.from(u.paths),rollback:u.rollback};(async()=>{try{await n(y),r(y)}catch(C){c(y,C)}finally{m(y.paths),t=!1,s.length>0&&h()}})()},clear:()=>{s.length=0},size:()=>s.length,isRunning:()=>t}},or=a.memo(function({file:r,actionLabel:c,actionSymbol:m,onAction:h,onViewDiff:s,onRevert:t,isReverting:g,stats:u,rowPaddingClassName:y,indentPx:C=0,actionAtStart:S=!1,showRevert:v=!0}){const f=it.useMemo(()=>pn(r),[r]),l=f.description,d=u?.insertions??0,E=u?.deletions??0,k=it.useCallback(A=>{A.key===" "?(A.preventDefault(),h()):A.key==="Enter"&&(A.preventDefault(),s())},[h,s]),I=it.useCallback(A=>{A.preventDefault(),A.stopPropagation(),h()},[h]),T=it.useCallback(A=>{A.preventDefault(),A.stopPropagation(),t()},[t]),H=e.jsx("button",{type:"button",onClick:I,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":c,title:c,children:m});return e.jsxs("div",{className:`group flex items-center gap-2 py-1.5 cursor-pointer ${y??"px-3"}`,role:"button",tabIndex:0,onClick:s,onKeyDown:k,style:C>0?{paddingLeft:`${C}px`}:void 0,children:[S?H:null,e.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:f.color},title:l,"aria-label":l,children:f.code}),e.jsx(Za,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),(()=>{const A=r.path.lastIndexOf("/");if(A===-1)return e.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:r.path,children:r.path});const L=r.path.slice(0,A),M=r.path.slice(A);return e.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[e.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:L}),e.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[e.jsx("span",{className:"text-muted-foreground",children:"/"}),e.jsx("span",{className:"text-foreground",children:M.slice(1)})]})]})})(),e.jsxs("span",{className:"shrink-0 typography-micro",children:[e.jsxs("span",{style:{color:"var(--status-success)"},children:["+",d]}),e.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),e.jsxs("span",{style:{color:"var(--status-error)"},children:["-",E]})]}),v?e.jsxs(we,{children:[e.jsx(Ne,{asChild:!0,children:e.jsx("button",{type:"button",onClick:T,disabled:g,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${r.path}`,children:g?e.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin"}):e.jsx(w,{name:"arrow-go-back",className:"size-3.5"})})}),e.jsx(Ce,{sideOffset:8,children:"Revert changes"})]}):null,S?null:H]})}),xs=14,Is=n=>n.replace(/\\/g,"/").replace(/^\/+/,"").trim(),bs=(n,r)=>({id:`dir:${n}`,path:n,name:r,children:new Map,directFiles:[],files:[]}),lr=n=>{const r=bs("","");for(const c of n){const m=Is(c.path);if(!m)continue;const s=m.split("/").filter(Boolean).slice(0,-1);let t=r;if(t.files.push(c),s.length>0){let g="";for(const u of s){g=g?`${g}/${u}`:u;const y=t.children.get(u);if(y){y.files.push(c),t=y;continue}const C=bs(g,u);C.files.push(c),t.children.set(u,C),t=C}}t.directFiles.push(c)}return r},cr=(n,r)=>{const c=[],m=(h,s)=>{const t=Array.from(h.children.values()).sort((u,y)=>u.path.localeCompare(y.path));for(const u of t)c.push({key:u.id,kind:"directory",depth:s,directory:u}),r.has(u.path)&&m(u,s+1);const g=[...h.directFiles].sort((u,y)=>u.path.localeCompare(y.path));for(const u of g)c.push({key:`file:${Is(u.path)}`,kind:"file",depth:s,file:u})};return m(n,0),c},dr=1e3,ys=34,It=30,dt="pl-0 pr-2",Mt=(n,r)=>`${n} ${r}`,ur=({groups:n,diffStats:r,revertingPaths:c,isRevertingAll:m=!1,headerBackgroundClassName:h="bg-sidebar",onVisiblePathsChange:s,onRevertAll:t,onRevertDirectory:g})=>{const u=a.useRef(null),C=Pt(N=>N.gitChangesViewMode)==="tree",S=a.useMemo(()=>n.filter(N=>N.entries.length>0),[n]),[v,f]=a.useState(new Set),[l,d]=a.useState(new Set),[E,k]=a.useState(!1),[I,T]=a.useState(null),H=a.useMemo(()=>S.map(N=>lr(N.entries)),[S]),A=a.useMemo(()=>{const N=[];return S.forEach((F,o)=>{Array.from(H[o]?.children.values()??[]).forEach(D=>{N.push(Mt(F.id,D.path))})}),N},[H,S]);a.useEffect(()=>{C&&d(N=>{const F=new Set,o=new Set(A);return N.forEach(D=>{(D.slice(D.indexOf(" ")+1).includes("/")||o.has(D))&&F.add(D)}),A.forEach(D=>F.add(D)),F})},[C,A]);const L=a.useMemo(()=>{const N=[];return S.forEach((F,o)=>{if(N.push({type:"header",key:`header:${F.id}`,groupIndex:o}),!v.has(F.id)){if(C){const D=new Set;l.forEach(se=>{se.startsWith(`${F.id} `)&&D.add(se.slice(F.id.length+1))}),cr(H[o],D).forEach(se=>{se.kind==="file"?N.push({type:"file",key:`${F.id}:${se.key}`,groupIndex:o,file:se.file,depth:se.depth}):N.push({type:"directory",key:`${F.id}:${se.key}`,groupIndex:o,directory:se.directory,depth:se.depth})});return}F.entries.forEach(D=>{N.push({type:"file",key:`${F.id}:file:${D.path}`,groupIndex:o,file:D,depth:0})})}}),t&&S.length>0&&N.push({type:"revert-all",key:"revert-all"}),N},[v,l,C,t,H,S]),M=L.length,z=M>=dr,G=jn({count:M,enabled:z,getScrollElement:()=>u.current,estimateSize:()=>ys,overscan:12,getItemKey:N=>L[N]?.key??N}),x=G.getVirtualItems(),B=a.useMemo(()=>{if(!z)return 0;const N=u.current?.scrollTop??0;return x.find(o=>o.end>N)?.index??0},[z,x,u]);a.useEffect(()=>{if(!s)return;const N=F=>F&&F.type==="file"?F.file.path:null;if(M===0){s([]);return}if(!z){const F=[];for(const o of L)if(o.type==="file"&&(F.push(o.file.path),F.length>=It))break;s(F);return}s(L.slice(B,B+Math.ceil((u.current?.clientHeight??0)/ys)+It).map(F=>N(F)).filter(F=>!!F).slice(0,It))},[s,M,L,z,B]);const q=a.useCallback(N=>{f(F=>{const o=new Set(F);return o.has(N)?o.delete(N):o.add(N),o})},[]),Q=a.useCallback((N,F)=>{d(o=>{const D=new Set(o),V=Mt(N,F);return D.has(V)?D.delete(V):D.add(V),D})},[]),U=a.useMemo(()=>{const N=new Set;return S.forEach(F=>F.entries.forEach(o=>N.add(o.path))),Array.from(N)},[S]),W=U.length,$=I?m||I.paths.some(N=>c.has(N)):!1,X=a.useCallback(async()=>{!t||m||U.length===0||(await t(U),k(!1))},[U,m,t]),ne=a.useCallback(async()=>{!g||!I||$||(await g(I.paths),T(null))},[$,g,I]),ae=a.useCallback((N,F)=>{const o=v.has(N.id),D=N.entries.length;return e.jsxs("div",{className:te("sticky top-0 z-10 flex items-center gap-2 py-2",h,dt,!F&&"mt-1 border-t border-border/40"),children:[e.jsx("button",{type:"button",onClick:()=>N.onActionAll(N.entries.map(V=>V.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":N.actionAllLabel,title:N.actionAllLabel,children:N.actionSymbol}),e.jsxs("button",{type:"button",onClick:()=>q(N.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!o,children:[e.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:N.title}),e.jsx("span",{className:"typography-meta text-muted-foreground",children:D}),e.jsx(w,{name:"arrow-down-s",className:te("size-3.5 shrink-0 text-muted-foreground transition-transform",o&&"-rotate-90")})]})]})},[v,h,q]),Y=a.useCallback((N,F,o)=>{const D=l.has(Mt(N.id,F.path)),V=F.files.map(oe=>oe.path),se=m||V.some(oe=>c.has(oe));return e.jsxs("div",{className:te("group flex items-center gap-2 py-1.5",dt),style:{paddingLeft:`${o*xs}px`},children:[e.jsxs("button",{type:"button",onClick:()=>Q(N.id,F.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":D?`Collapse directory ${F.path}`:`Expand directory ${F.path}`,children:[D?e.jsx(w,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):e.jsx(w,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:F.path,children:F.name}),e.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:F.files.length})]}),N.showRevertActions!==!1&&g?e.jsx("button",{type:"button",onClick:()=>T({path:F.path,paths:V,count:V.length}),disabled:se,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50","aria-label":`Revert changes in ${F.path}`,title:"Revert folder changes",children:se?e.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin"}):e.jsx(w,{name:"arrow-go-back",className:"size-3.5"})}):null,e.jsx("button",{type:"button",onClick:()=>N.onActionAll(F.files.map(oe=>oe.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":N.actionSymbol==="+"?`Stage all changes in ${F.path}`:`Unstage all changes in ${F.path}`,title:N.actionSymbol==="+"?`Stage all changes in ${F.path}`:`Unstage all changes in ${F.path}`,children:N.actionSymbol})]})},[l,m,g,c,Q]),K=a.useCallback((N,F)=>{if(N.type==="revert-all")return e.jsx("div",{className:te("flex justify-end py-2",dt),children:e.jsxs(_,{variant:"ghost",size:"sm",onClick:()=>k(!0),disabled:m,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[e.jsx(w,{name:"arrow-go-back",className:"size-3.5"}),"Revert all"]})});const o=S[N.groupIndex];if(!o)return null;if(N.type==="header")return ae(o,F);if(N.type==="directory")return Y(o,N.directory,N.depth);const D=N.file;return e.jsx(or,{file:D,actionLabel:o.getActionLabel(D.path),actionSymbol:o.actionSymbol,onAction:()=>o.onActionFile(D.path),stats:r?.[D.path],onViewDiff:()=>o.onViewDiff(D.path),onRevert:()=>o.onRevertFile(D.path),isReverting:c.has(D.path)||m,rowPaddingClassName:dt,indentPx:N.depth*xs,actionAtStart:!C,showRevert:o.showRevertActions!==!1})},[r,m,C,Y,ae,c,S]),O=a.useCallback(N=>{const F=L[N],o=L[N-1];return!F||!o||F.type!=="file"&&F.type!=="directory"||o.type!=="file"&&o.type!=="directory"?!1:o.groupIndex===F.groupIndex},[L]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[e.jsx(Rs,{ref:u,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:z?e.jsx("div",{style:{height:G.getTotalSize(),position:"relative"},children:x.map(N=>{const F=L[N.index];return F?e.jsx("div",{"data-index":N.index,ref:G.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${N.start}px)`},className:te(O(N.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:K(F,N.index===0)},F.key):null})}):e.jsx("div",{role:"list","aria-label":"Changed files",children:L.map((N,F)=>e.jsx("div",{className:te("relative",O(F)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:K(N,F===0)},N.key))})}),e.jsx(Ja,{containerRef:u,disableHorizontal:!0})]}),e.jsx(Fe,{open:E,onOpenChange:N=>{!m&&!N&&k(!1)},children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs($e,{children:[e.jsx(Ie,{children:"Revert all changes?"}),e.jsx(Me,{children:W===1?`Revert ${W} changed file? This cannot be undone.`:`Revert ${W} changed files? This cannot be undone.`})]}),e.jsxs(_e,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>k(!1),disabled:m,children:"Cancel"}),e.jsx(_,{variant:"destructive",size:"sm",onClick:()=>{X()},disabled:m,children:m?"Reverting...":"Revert all"})]})]})}),e.jsx(Fe,{open:!!I,onOpenChange:N=>{!$&&!N&&T(null)},children:e.jsxs(ze,{className:"max-w-md",children:[e.jsxs($e,{children:[e.jsx(Ie,{children:"Revert folder changes?"}),e.jsx(Me,{children:I?I.count===1?`This will discard local changes in ${I.count} file under ${I.path}.`:`This will discard local changes in ${I.count} files under ${I.path}.`:null})]}),e.jsxs(_e,{children:[e.jsx(_,{variant:"outline",size:"sm",onClick:()=>T(null),disabled:$,children:"Cancel"}),e.jsx(_,{variant:"destructive",size:"sm",onClick:()=>{ne()},disabled:$||!I,children:$?"Reverting...":"Revert folder"})]})]})})]})},hr=Es(()=>vs(()=>import("./DiffView-VyBf4ilo.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(n=>({default:n.DiffView}))),mr=({currentDirectory:n,status:r,isGitRepo:c,isLoadingStatus:m,changeEntries:h,stagedChangeEntries:s,unstagedChangeEntries:t,effectiveRemotes:g,syncAction:u,commitAction:y,commitMessage:C,hasPendingIndexMutation:S,revertingPaths:v,isRevertingAll:f,initialDiffPath:l,initialDiffStaged:d=!1,onSyncAction:E,onMoveChangePaths:k,onRevertFile:I,onRevertAll:T,onCommitMessageChange:H,onCommit:A,onVisiblePathsChange:L,loadDiff:M})=>{const[z,G]=a.useState(()=>l?{type:"diff",path:l,staged:d}:{type:"list"}),[x,B]=a.useState(null),[q,Q]=a.useState(null),[U,W]=a.useState(0);a.useEffect(()=>{l&&G(Y=>Y.type==="diff"&&Y.path===l&&Y.staged===d?Y:{type:"diff",path:l,staged:d})},[l,d]);const $=a.useMemo(()=>z.type==="diff"&&h.some(Y=>Y.path===z.path),[h,z]);a.useEffect(()=>{if(z.type!=="diff"||!$){B(null),Q(null);return}let Y=!1;return B(null),Q(null),M(z.path,z.staged).then(K=>{Y||B(K)}).catch(K=>{Y||Q(K instanceof Error?K.message:String(K))}),()=>{Y=!0}},[U,M,z,$]);const X=a.useCallback((Y,K=!1)=>{G({type:"diff",path:Y,staged:K})},[]),ne=a.useMemo(()=>{const Y=[];return s.length>0&&Y.push({id:"staged",title:"Staged",entries:s,actionSymbol:"-",actionAllLabel:"Unstage all changes",getActionLabel:K=>`Unstage ${K}`,onActionFile:K=>k([K],"unstage"),onActionAll:K=>k(K,"unstage"),onViewDiff:K=>X(K,!0),onRevertFile:I,showRevertActions:!1,accent:!0}),t.length>0&&Y.push({id:"unstaged",title:"Changes",entries:t,actionSymbol:"+",actionAllLabel:"Stage all changes",getActionLabel:K=>`Stage ${K}`,onActionFile:K=>k([K],"stage"),onActionAll:K=>k(K,"stage"),onViewDiff:K=>X(K,!1),onRevertFile:I}),Y},[X,k,I,s,t]),ae=a.useCallback(Y=>e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsx("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:e.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:r?.current||n||""})}),e.jsx("div",{className:"min-h-0 flex-1",children:Y})]}),[n,r]);return n?c===null||c===!0&&!r?ae(e.jsx(Ee,{loading:!0,message:"Checking repository..."})):c===!1?ae(e.jsx(a.Suspense,{fallback:e.jsx(Ee,{loading:!0,message:"Loading last turn changes..."}),children:e.jsx(hr,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0})})):z.type==="diff"?e.jsx(fr,{path:z.path,diff:x,fileExists:$,error:q,onBack:()=>G({type:"list"}),onRetry:()=>W(Y=>Y+1)}):e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[e.jsx("p",{className:"min-w-0 flex-1 truncate typography-ui-label text-muted-foreground",children:r?.current||n}),e.jsx(zs,{syncAction:u,remotes:g,onFetch:Y=>E("fetch",Y),onSync:Y=>E("sync",Y),disabled:y!==null||m,aheadCount:r?.ahead??0,behindCount:r?.behind??0,trackingRemoteName:r?.tracking?.split("/")[0],hasUncommittedChanges:h.length>0})]}),h.length>0?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-3 pt-2",children:e.jsx(ur,{groups:ne,diffStats:r?.diffStats,revertingPaths:v,onRevertAll:T,isRevertingAll:f,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:L})}),e.jsx("div",{className:"shrink-0 border-t border-border/40 px-3 pb-3 pt-3",children:e.jsx($s,{stagedCount:s.length,commitMessage:C,onCommitMessageChange:H,onCommit:()=>{if(!C.trim()){R.error("Enter a commit message");return}if(s.length===0){R.error("Select at least one file to commit");return}A({pushAfter:!1})},onCommitAndPush:()=>{if(!C.trim()){R.error("Enter a commit message");return}if(s.length===0){R.error("Select at least one file to commit");return}A({pushAfter:!0})},commitAction:y,hasPendingIndexMutation:S})})]}):e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Ee,{icon:!0,message:"Working tree clean",description:"There are no changed files in this workspace."})})]}):ae(e.jsx(Ee,{message:"Select a session or directory to view Git status"}))},Ee=({message:n,description:r,loading:c=!1,icon:m=!1})=>e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[c?e.jsx(w,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,m?e.jsx(w,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),r?e.jsx("p",{className:"typography-meta text-muted-foreground",children:r}):null]})}),fr=({path:n,diff:r,fileExists:c,error:m,onBack:h,onRetry:s})=>{const t=a.useMemo(()=>ks(n)||"text",[n]);return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-transparent text-foreground",children:[e.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-1 px-2 text-foreground",children:[e.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":"Back",onClick:h,children:e.jsx(w,{name:"arrow-left",className:"size-5"})}),e.jsx("div",{className:"min-w-0 flex-1 px-2",children:e.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:n})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:c?m?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[e.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),e.jsx("p",{className:"typography-meta text-muted-foreground",children:m}),e.jsx(_,{type:"button",size:"sm",variant:"outline",onClick:s,children:"Retry"})]})}):r?r.isBinary?e.jsx(Ee,{icon:!0,message:"Content of this file cannot be viewed."}):Qa(n)?e.jsx(Ee,{icon:!0,message:"Image diffs are not available in mobile Changes yet."}):e.jsx(Rs,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:e.jsx(Fs,{original:r.original,modified:r.modified,language:t,fileName:n,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):e.jsx(Ee,{loading:!0,message:"Loading diff..."}):e.jsx(Ee,{icon:!0,message:"File is no longer changed",description:"Go back to Changes and refresh the list."})})]})},js=Es(()=>vs(()=>import("./DiffView-VyBf4ilo.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119])).then(n=>({default:n.DiffView}))),pr=15e3,gr=40,xr=20,Eo=({isActive:n,chrome:r="desktop",initialDiffPath:c=null,initialDiffStaged:m=!1,gitHeaderSlot:h=null})=>{const{git:s}=ut(),t=Xa(),g=Lt(i=>i.currentSessionId),{profiles:u,globalIdentity:y,defaultGitIdentityId:C,loadProfiles:S,loadGlobalIdentity:v,loadDefaultGitIdentityId:f}=un(os(i=>({profiles:i.profiles,globalIdentity:i.globalIdentity,defaultGitIdentityId:i.defaultGitIdentityId,loadProfiles:i.loadProfiles,loadGlobalIdentity:i.loadGlobalIdentity,loadDefaultGitIdentityId:i.loadDefaultGitIdentityId}))),l=en(t??null),d=tn(t??null),E=sn(t??null),k=an(t??null),I=nn(t??null),T=rn(t??null),H=on(t??null),{setActiveDirectory:A,fetchAll:L,ensureAll:M,fetchStatus:z,fetchBranches:G,fetchLog:x,setLogMaxCount:B,fetchIdentity:q,prefetchDiffs:Q,clearDiffCache:U,moveStatusPathsOptimistically:W,restoreStatus:$,bumpIndexRevision:X}=ln(os(i=>({setActiveDirectory:i.setActiveDirectory,fetchAll:i.fetchAll,ensureAll:i.ensureAll,fetchStatus:i.fetchStatus,fetchBranches:i.fetchBranches,fetchLog:i.fetchLog,setLogMaxCount:i.setLogMaxCount,fetchIdentity:i.fetchIdentity,prefetchDiffs:i.prefetchDiffs,clearDiffCache:i.clearDiffCache,moveStatusPathsOptimistically:i.moveStatusPathsOptimistically,restoreStatus:i.restoreStatus,bumpIndexRevision:i.bumpIndexRevision})));a.useRef(null);const ne=a.useRef(null),ae=a.useRef(null),Y=a.useRef(null),K=a.useRef(!0);a.useEffect(()=>()=>{K.current=!1},[]);const O=a.useCallback(()=>{ne.current!==null&&(window.clearTimeout(ne.current),ne.current=null)},[]),N=a.useCallback(i=>{O(),ne.current=window.setTimeout(()=>{ne.current=null,ot(i)===ot(t)&&z(i,s,{silent:!0})},pr)},[O,t,z,s]);a.useEffect(()=>O,[O]);const F=a.useCallback(()=>{ae.current!==null&&(window.clearTimeout(ae.current),ae.current=null)},[]),o=a.useCallback(()=>{ae.current===null&&(ae.current=window.setTimeout(()=>{ae.current=null,Y.current?.()},0))},[]),D=a.useCallback(async(i,p,b)=>{if(p==="stage"){if(s.stageGitFiles){await s.stageGitFiles(i,b);return}await Promise.all(b.map(j=>s.stageGitFile(i,j)));return}if(s.unstageGitFiles){await s.unstageGitFiles(i,b);return}await Promise.all(b.map(j=>s.unstageGitFile(i,j)))},[s]),V=a.useMemo(()=>ir({runMutation:({directory:i,direction:p,paths:b})=>D(i,p,b),onMutationComplete:({directory:i})=>{X(i),N(i)},onMutationError:({directory:i,direction:p,rollback:b},j)=>{b?.(),X(i),N(i);const P=p==="stage"?"Failed to stage changes":"Failed to unstage changes";R.error(j instanceof Error?j.message:P)},onPathsComplete:i=>{Gt(p=>{const b=new Set(p);return i.forEach(j=>b.delete(j)),b})},scheduleFlush:o}),[X,D,o,N]);a.useEffect(()=>(Y.current=V.flush,()=>{Y.current=null}),[V]),a.useEffect(()=>()=>V.clear(),[V]),a.useEffect(()=>F,[F]);const se=a.useMemo(()=>t?On(t):null,[t]),[oe,he]=a.useState(se?.commitMessage??""),le=a.useRef(null),[Ge,We]=a.useState(null),[Ms,ht]=a.useState(!1),[mt,At]=a.useState(null),[ge,Ds]=a.useState(25),[Ls,Bt]=a.useState(!1),{triggerFireworks:Ps}=hn(),Tt=a.useRef(new Map),Ke=a.useRef(0),ft=a.useCallback(()=>{Ke.current+=1,K.current&&Bt(!0)},[]),pt=a.useCallback(()=>{Ke.current=Math.max(0,Ke.current-1),K.current&&Ke.current===0&&Bt(!1)},[]),[gt,qe]=a.useState(new Set),[As,Gt]=a.useState(new Set),[xt,Ot]=a.useState(!1),[_t,Bs]=a.useState([]),[br,Ts]=a.useState(0),[Gs,Ht]=a.useState(!1),Ut=As.size>0||V.size()>0||V.isRunning();a.useCallback(()=>{const i=le.current;i&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{i.scrollTo({top:i.scrollHeight,behavior:"smooth"})})})},[]);const{expandedCommitHashes:Os,commitFilesMap:_s,loadingCommitHashes:Hs,handleCopyCommitHash:Us,handleToggleCommit:Vs}=Wn(t,s),{conflictDialogOpen:Ws,setConflictDialogOpen:xe,conflictFiles:Ks,setConflictFiles:be,conflictOperation:Ye,setConflictOperation:ye,persistConflictState:je,clearConflictState:me}=rr({currentSessionId:g,currentDirectory:t}),[qs,bt]=a.useState([]),[Vt,yt]=a.useState(null),[Ys,Wt]=a.useState(null),[Zs,jt]=a.useState(null),[Js,Ze]=a.useState([]),[Qs,vt]=a.useState(null),[Xs,Kt]=a.useState(!1),[wt,ea]=a.useState(100),[ta,sa]=a.useState(0),[fe,Je]=a.useState(null),[aa,Le]=a.useState(null),[na,Nt]=a.useState(!1),[Ct,qt]=a.useState("merge"),[St,Yt]=a.useState("");a.useEffect(()=>{t&&_n(t,{directory:t,commitMessage:oe})},[oe,t]),a.useEffect(()=>{n&&(S(),v(),f())},[n,S,v,f]),a.useEffect(()=>{if(!n)return;if(!t||!s?.getRemoteUrl){yt(null);return}let i=!1;return s.getRemoteUrl(t).then(p=>{i||yt(p)}).catch(()=>{i||yt(null)}),()=>{i=!0}},[n,t,s]);const Qe=a.useCallback(async()=>{if(!t||!s?.getRemotes){bt([]);return}try{const i=await s.getRemotes(t);K.current&&bt(i)}catch{K.current&&bt([])}},[t,s]);a.useEffect(()=>{n&&Qe()},[n,Qe]),a.useEffect(()=>{n&&t&&(A(t),M(t,s))},[n,t,A,M,s]),a.useEffect(()=>{if(n&&t)return cn.onGitRefreshHint(i=>{ot(i.directory)===ot(t)&&(i.paths?.length&&U(t,i.paths),z(t,s,{silent:!0}))})},[n,U,t,z,s]);const ee=a.useCallback(async(i=!0)=>{if(t)try{await Promise.all([z(t,s),G(t,s)])}catch(p){if(i){const b=p instanceof Error?p.message:"Failed to refresh repository";R.error(b)}}},[t,s,z,G]),re=a.useCallback(async()=>{t&&await x(t,s,ge)},[t,s,x,ge]),kt=a.useCallback(async()=>{t&&await q(t,s)},[t,s,q]);a.useEffect(()=>{if(!n||!t||!s?.hasLocalIdentity||l!==!0)return;const i=typeof C=="string"?C.trim():"";if(!i||i==="global"||Tt.current.get(t)===i)return;let b=!1;return(async()=>{try{const P=await s.hasLocalIdentity?.(t);if(b||P===!0)return;ft(),await s.setGitIdentity(t,i),Tt.current.set(t,i),await kt()}catch(P){console.warn("Failed to auto-apply default git identity:",P)}finally{b||pt()}})(),()=>{b=!0}},[n,ft,t,C,pt,s,l,kt]);const ce=a.useMemo(()=>d?[...d.files??[]].sort((p,b)=>p.path.localeCompare(b.path)):[],[d]),Se=a.useMemo(()=>ce.filter(ls),[ce]),Zt=a.useMemo(()=>ce.filter(gn),[ce]);a.useEffect(()=>{if(!t||ce.length===0)return;const i=[],p=new Set,b=P=>{!P||p.has(P)||(p.add(P),i.push(P))};if(Se.forEach(P=>b(P.path)),r==="mobile"&&_t.forEach(b),ce.slice(0,xr).forEach(P=>b(P.path)),i.length===0)return;const j=window.setTimeout(()=>{Q(t,s,i,{maxFiles:gr})},120);return()=>{window.clearTimeout(j)}},[ce,r,t,s,_t,Q,Se]);const Jt=i=>i?.pushed[0]?.remote||d?.tracking?.split("/")[0]||ve.find(p=>p.name==="origin")?.name||ve[0]?.name||"origin",Rt=async(i,p)=>{if(t){We(i);try{const b=j=>{const P=`${j.name}/`,Z=d?.tracking?.startsWith(P)?d.tracking.slice(P.length):void 0;return{remote:j.name,branch:Z,rebase:!0}};if(i==="fetch"){if(!p)throw new Error("No remote available for fetch");await s.gitFetch(t,{remote:p.name}),R.success(`Fetched from ${p.name}`)}else if(i==="pull"){if(!p)throw new Error("No remote available for pull");const j=await s.gitPull(t,b(p));R.success(j.files.length===1?`Pulled ${j.files.length} file from ${p.name}`:`Pulled ${j.files.length} files from ${p.name}`)}else if(i==="push"){const j=await s.gitPush(t);R.success(`Pushed to ${Jt(j)}`)}else if(i==="sync"){if(!p)throw new Error("No remote available for sync");let j=0,P=!1;await s.gitFetch(t,{remote:p.name});const Z=await s.getGitStatus(t);if((Z.behind??0)>0){if((Z.files?.length??0)>0){R.error("Commit or stash your changes before syncing");return}j=(await s.gitPull(t,b(p))).files.length}((await s.getGitStatus(t)).ahead??0)>0&&(await s.gitPush(t),P=!0),j>0&&P?R.success(j===1?`Pulled ${j} file from ${p.name} and pushed to upstream`:`Pulled ${j} files from ${p.name} and pushed to upstream`):j>0?R.success(j===1?`Pulled ${j} file from ${p.name}`:`Pulled ${j} files from ${p.name}`):P?R.success(`Pushed to ${p.name}`):R.success("Already up to date")}await ee(!1),await re()}catch(b){const j=b instanceof Error?b.message:`${i==="sync"?"Sync Changes":i==="pull"?"Pull":i} failed`;R.error(j)}finally{We(null)}}},ra=a.useCallback(async(i,p)=>{if(!t)throw new Error("No active directory");const b=await s.getGitFileDiff(t,{path:i,staged:p||void 0});return{original:b.original??"",modified:b.modified??"",isBinary:b.isBinary}},[t,s]),ia=a.useCallback(async i=>{if(!t)return;const p=i.name.trim();if(!p){R.error("Remote name is required");return}if(p==="origin"){R.error("Cannot remove the origin remote");return}Wt(p);try{await s.removeRemote(t,{remote:p}),R.success(`Removed remote ${p}`),await Promise.all([ee(!1),Qe()])}catch(b){const j=b instanceof Error?b.message:`Failed to remove ${p}`;R.error(j)}finally{Wt(null)}},[t,s,Qe,ee]),Et=async(i={})=>{if(!t)return;if(!oe.trim()){R.error("Enter a commit message");return}const p=Se.map(j=>j.path).sort();if(p.length===0){R.error("Stage at least one file to commit");return}const b=i.pushAfter?"commitAndPush":"commit";At(b);try{if(await s.createGitCommit(t,oe.trim(),{files:p,stageFiles:[]}),X(t),R.success("Commit created"),he(""),await ee(),i.pushAfter){const j=d?.tracking?.split("/")[0],P=ve.find(Pa=>Pa.name===j)??ve[0];if(!P)throw new Error("No remote available");We("sync");const Z=`${P.name}/`,ie=d?.tracking?.startsWith(Z)?d.tracking.slice(Z.length):void 0;await s.gitFetch(t,{remote:P.name});const J=await s.getGitStatus(t);if((J.behind??0)>0){if((J.files?.length??0)>0){R.error("Commit or stash your changes before syncing"),await ee(!1);return}await s.gitPull(t,{remote:P.name,branch:ie,rebase:!0})}const ue=await s.getGitStatus(t);let Be;(ue.ahead??0)>0&&(Be=await s.gitPush(t)),R.success(`Pushed to ${Jt(Be)}`),r!=="mobile"&&Ps(),await ee(!1)}else await ee(!1);await re(),Ts(j=>j+1)}catch(j){const P=j instanceof Error?j.message:"Failed to create commit";R.error(P)}finally{At(null),i.pushAfter&&We(null)}},oa=async(i,p)=>{if(!t||!d)return;const b=d.current??null,j=p?.name??"origin";try{await s.createBranch(t,i,b??"HEAD"),R.success(`Created branch ${i}`),await s.checkoutBranch(t,i);let P=!1;try{await s.gitPush(t,{remote:j,branch:i,options:["--set-upstream"]}),P=!0}catch(Z){const ie=Z instanceof Error?Z.message:`Unable to push new branch to ${j}.`;R.warning("Branch created locally, but failed to set upstream.",{description:e.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",ie]})})}await ee(),await re(),P&&R.success(`Set upstream for ${i} to ${j}`)}catch(P){const Z=P instanceof Error?P.message:"Failed to create branch";throw R.error(Z),P}},la=async(i,p)=>{if(t)try{await s.renameBranch(t,i,p),R.success(`Renamed ${i} to ${p}`),await ee(),await re()}catch(b){const j=b instanceof Error?b.message:`Failed to rename ${i} to ${p}`;R.error(j)}},ca=async i=>{if(!t)return;const p=i.replace(/^remotes\//,"");if(d?.current!==p)try{await s.checkoutBranch(t,p),R.success(`Checked out ${p}`),await ee(),await re()}catch(b){const j=b instanceof Error?b.message:`Failed to checkout ${p}`;R.error(j)}},da=async i=>{if(t){ft();try{await s.setGitIdentity(t,i.id),R.success(`Applied identity: ${i.name}`),await kt()}catch(p){const b=p instanceof Error?p.message:"Failed to apply identity";R.error(b)}finally{pt()}}},{localBranches:Qt,remoteBranches:Xe,effectiveRemotes:ve,currentBranch:Pe,baseBranch:et,branchScopeAvailable:Ae,updateTargetBranch:ua}=er({branches:E,status:d,remotes:qs,remoteUrl:Vt,git:s}),{availableIdentities:ha,activeIdentityProfile:ma}=nr({profiles:u,globalIdentity:y,currentIdentity:I,remoteUrl:Vt}),Xt=Se.length,fa=T||Ge!==null||mt!==null,es=!!Pe;a.useEffect(()=>{if(!t||!s||!k?.all?.length||!Pe||!et||!Ae){Le(null);return}let i=!1;return(async()=>{try{const b=await s.getGitLog(t,{from:et,to:"HEAD",maxCount:ge});if(i)return;const j=new Set((b?.all??[]).map(Z=>Z.hash).filter(Z=>typeof Z=="string"&&Z.length>0));if(j.size===0){Le(null);return}const P=k.all.findIndex(Z=>!j.has(Z.hash));if(P===0){Le(null);return}if(P===-1){Le({insertBeforeIndex:k.all.length,branchName:Pe,direction:"up"});return}Le({insertBeforeIndex:P,branchName:Pe,direction:"up"})}catch{i||Le(null)}})(),()=>{i=!0}},[et,Ae,Pe,t,s,k,ge]),a.useEffect(()=>{vt(null)},[t]),a.useEffect(()=>{if(fe!=="graph"||!t){fe!=="graph"&&vt(null);return}let i=!1;return Kt(!0),s.getGitLog(t,{maxCount:wt,all:!0}).then(p=>{i||vt(p)}).catch(p=>{console.error("Failed to fetch graph log:",p)}).finally(()=>{i||Kt(!1)}),()=>{i=!0}},[fe,t,wt,ta,s]);const pa=a.useCallback((i,p)=>{if(!t||i.length===0)return;const b=Array.from(new Set(i));Gt(P=>{const Z=new Set(P);return b.forEach(ie=>Z.add(ie)),Z});const j=W(t,b,p);V.enqueue({directory:t,direction:p,paths:new Set(b),rollback:()=>$(t,j)}),o()},[t,V,W,$,o]),ga=a.useCallback(async i=>{if(t){qe(p=>{const b=new Set(p);return b.add(i),b});try{await s.revertGitFile(t,i,{scope:"working"}),R.success(`Reverted ${i}`),await ee(!1)}catch(p){const b=p instanceof Error?p.message:"Failed to revert changes";R.error(b)}finally{qe(p=>{const b=new Set(p);return b.delete(i),b})}}},[t,ee,s]),tt=a.useCallback(async(i,p,b="all")=>{if(!t||i.length===0)return;const j=Array.from(new Set(i));if(xt||j.some(J=>gt.has(J)))return;const P=new Set(Se.map(J=>J.path)),Z=b==="all"&&j.some(J=>P.has(J));p&&Ot(!0),qe(J=>{const ue=new Set(J);return j.forEach(Be=>ue.add(Be)),ue});const ie=[];try{if(await Promise.all(j.map(async J=>{try{await s.revertGitFile(t,J,{scope:b})}catch(ue){ie.push({path:J,message:ue instanceof Error?ue.message:"Failed to revert changes"})}})),Z&&ie.length<j.length&&X(t),await ee(!1),ie.length===0)R.success(j.length===1?`Reverted ${j.length} file`:`Reverted ${j.length} files`);else if(ie.length===j.length)R.error(ie[0]?.message||"Failed to revert changes");else{const J=j.length-ie.length;R.warning(J===1?`Reverted ${J} file, ${ie.length} failed`:`Reverted ${J} files, ${ie.length} failed`)}}finally{qe(J=>{const ue=new Set(J);return j.forEach(Be=>ue.delete(Be)),ue}),p&&Ot(!1)}},[X,t,s,xt,ee,gt,Se]),xa=a.useCallback(async i=>{await tt(i,!0)},[tt]);a.useCallback(async i=>{await tt(i,!1,"working")},[tt]);const ba=a.useCallback(()=>ht(!0),[]),st=a.useCallback(i=>{const p=i instanceof Error?i.message.toLowerCase():"";return p.includes("uncommitted changes")||p.includes("local changes")||p.includes("your local changes would be overwritten")||p.includes("please commit your changes or stash them")||p.includes("cannot rebase: you have unstaged changes")||p.includes("error: cannot pull with rebase")},[]),ke=a.useCallback((i,p)=>{Ze(b=>[...b,{message:i,status:p,timestamp:Date.now()}])},[]),de=a.useCallback((i,p)=>{Ze(b=>{if(b.length===0)return b;const j=[...b];return j[j.length-1]={...j[j.length-1],status:i,...p?{message:p}:{}},j})},[]),at=a.useCallback(()=>{Ze([])},[]),ya=a.useCallback(()=>{Ze([]),jt(null)},[]),nt=a.useCallback(i=>{const p=i.trim(),b=new Set(ve.map(P=>P.name)),j=p.indexOf("/");if(j>0){const P=p.slice(0,j),Z=p.slice(j+1);if(b.has(P)&&Z)return{branch:p,remote:P,remoteBranch:Z}}for(const P of ve){const Z=`${P.name}/${p}`;if(Xe.includes(Z))return{branch:Z,remote:P.name,remoteBranch:p}}return{branch:p,remote:null,remoteBranch:null}},[ve,Xe]),ja=a.useCallback(async i=>{if(!t)return;jt("merge"),at();const p=d?.current,b=nt(i);try{b.remote&&b.remoteBranch&&(ke(`Fetching ${b.remote}/${b.remoteBranch}...`,"running"),await s.gitFetch(t,{remote:b.remote,branch:b.remoteBranch}),de("done",`Fetched ${b.remote}/${b.remoteBranch}`)),ke(`Merging ${b.branch} into ${p}...`,"running");const j=await s.merge(t,{branch:b.branch});j.conflict?(de("error","Merge conflicts detected"),be(j.conflictFiles??[]),ye("merge"),xe(!0),je(t,j.conflictFiles??[],"merge")):(de("done",`Merged ${b.branch} into ${p}`),me(),ke("Refreshing repository status...","running"),await ee(),await re(),de("done","Repository status updated"))}catch(j){if(st(j))de("error","Uncommitted changes detected"),qt("merge"),Yt(b.branch),Nt(!0);else{const P=j instanceof Error?j.message:`Failed to merge ${b.branch}`;de("error",P)}}},[t,s,d,nt,ee,re,st,je,me,ke,de,at]),va=a.useCallback(async i=>{if(!t)return;jt("rebase"),at();const p=d?.current,b=nt(i);try{b.remote&&b.remoteBranch&&(ke(`Fetching ${b.remote}/${b.remoteBranch}...`,"running"),await s.gitFetch(t,{remote:b.remote,branch:b.remoteBranch}),de("done",`Fetched ${b.remote}/${b.remoteBranch}`)),ke(`Rebasing ${p} onto ${b.branch}...`,"running");const j=await s.rebase(t,{onto:b.branch});j.conflict?(de("error","Rebase conflicts detected"),be(j.conflictFiles??[]),ye("rebase"),xe(!0),je(t,j.conflictFiles??[],"rebase")):(de("done",`Rebased ${p} onto ${b.branch}`),me(),ke("Refreshing repository status...","running"),await ee(),await re(),de("done","Repository status updated"))}catch(j){if(st(j))de("error","Uncommitted changes detected"),qt("rebase"),Yt(b.branch),Nt(!0);else{const P=j instanceof Error?j.message:`Failed to rebase onto ${b.branch}`;de("error",P)}}},[t,s,d,nt,ee,re,st,je,me,ke,de,at]),wa=a.useCallback(async()=>{if(t)try{Ye==="merge"?(await s.abortMerge(t),R.success("Merge aborted")):(await s.abortRebase(t),R.success("Rebase aborted")),me(),await ee(),await re()}catch(i){const p=i instanceof Error?i.message:`Failed to abort ${Ye}`;R.error(p)}},[t,s,Ye,ee,re,me]),Na=a.useMemo(()=>d?.files?d.files.filter(i=>i.index==="U"||i.working_dir==="U"||i.index==="A"&&i.working_dir==="A"||i.index==="D"&&i.working_dir==="D").length:0,[d?.files]),Ca=a.useCallback(async()=>{if(t)try{const i=!!d?.mergeInProgress?.head,p=!!(d?.rebaseInProgress?.headName||d?.rebaseInProgress?.onto);if(i){const b=await s.continueMerge(t);b.conflict?(be(b.conflictFiles??[]),ye("merge"),xe(!0),je(t,b.conflictFiles??[],"merge"),R.error("Merge conflicts detected")):(me(),R.success("Merge completed"),await ee(),await re())}else if(p){const b=await s.continueRebase(t);b.conflict?(be(b.conflictFiles??[]),ye("rebase"),xe(!0),je(t,b.conflictFiles??[],"rebase"),R.error("Rebase conflicts detected")):(me(),R.success("Rebase step completed"),await ee(),await re())}}catch(i){const p=i instanceof Error?i.message:"Failed to continue operation";R.error(p)}},[t,s,d,ee,re,je,me]),Sa=a.useCallback(async()=>{if(t)try{!!d?.mergeInProgress?.head?(await s.abortMerge(t),R.success("Merge aborted")):(await s.abortRebase(t),R.success("Rebase aborted")),me(),await ee(),await re()}catch(i){const p=i instanceof Error?i.message:"Failed to abort operation";R.error(p)}},[t,s,d,ee,re,me]),ka=a.useCallback(()=>{if(!t)return;const p=!!d?.mergeInProgress?.head?"merge":"rebase",b=d?.files?.filter(j=>j.index==="U"||j.working_dir==="U").map(j=>j.path)??[];b.length>0&&be(b),ye(p),xe(!0)},[t,d]),Ra=a.useCallback(async i=>{if(!t)return;const p=d?.current,b=Ct,j=St,P=(d?.files??[]).some(ls);try{await s.stash(t,{message:`Auto-stash before ${b} with ${j}`,includeUntracked:!0}),P&&X(t)}catch(J){const ue=J instanceof Error?J.message:"Failed to stash changes";R.error(ue);return}let Z=!1,ie=!1;try{if(b==="merge"){const J=await s.merge(t,{branch:j});J.conflict?(ie=!0,be(J.conflictFiles??[]),ye("merge"),xe(!0)):(Z=!0,R.success(`Merged ${j} into ${p||""}`))}else{const J=await s.rebase(t,{onto:j});J.conflict?(ie=!0,be(J.conflictFiles??[]),ye("rebase"),xe(!0)):(Z=!0,R.success(`Rebased ${p||""} onto ${j}`))}if(i&&Z)try{await s.stashPop(t),X(t),R.success("Stashed changes restored")}catch(J){const ue=J instanceof Error?J.message:"Failed to restore stash";R.error(ue)}else i&&ie&&R.info("Stash restored manually required");await ee(),await re()}catch(J){if(i)try{await s.stashPop(t),X(t)}catch{}throw J}},[X,t,s,d,Ct,St,ee,re]),Ea=a.useCallback(i=>{Ds(i),t&&(B(t,i),x(t,s,i))},[t,x,s,B]),Fa=a.useCallback(i=>{ea(i)},[]),za=a.useCallback(()=>{Je(null),t&&(z(t,s),G(t,s),x(t,s,ge))},[t,z,G,x,ge,s]),$a=a.useCallback(i=>{if(i.conflict){if(i.operation==="cherry-pick"||i.operation==="revert"){R.error("Conflict",{description:`Conflicts in: ${i.conflictFiles?.join(", ")??"unknown files"}. Resolve manually and commit, or abort with git cherry-pick/revert --abort.`}),t&&(z(t,s),G(t,s),x(t,s,ge));return}be(i.conflictFiles??[]),ye(i.operation),xe(!0),t&&je(t,i.conflictFiles??[],i.operation)}},[be,ye,xe,je,t,z,G,x,ge,s]),[ts,ss]=a.useState(()=>ce.length>0?"all":"branch"),[Ia,Ma]=a.useState(null),rt=`${t??""}:${ce.length>0?"nonempty":"empty"}`,as=a.useRef(rt);a.useEffect(()=>{as.current!==rt&&(as.current=rt,ss(ce.length>0?"all":"branch"))},[ce.length,rt]);const ns=a.useCallback(i=>{ss(i)},[]),Da=a.useCallback(i=>{Ma(i)},[]),Ft=l===!0&&d?e.jsx(Sn,{status:d,localBranches:Qt,remoteBranches:Xe,branchInfo:E?.branches,syncAction:Ge,remotes:ve,onFetch:i=>Rt("fetch",i),onSync:i=>Rt("sync",i),onRemoveRemote:ia,removingRemoteName:Ys,onCheckoutBranch:ca,onCreateBranch:oa,onRenameBranch:la,activeIdentityProfile:ma,availableIdentities:ha,onSelectIdentity:da,isApplyingIdentity:Ls,isWorktreeMode:!1,upstreamTarget:d.upstreamComparison?`${d.upstreamComparison.remote}/${d.upstreamComparison.branch}`:null,onOpenHistory:()=>Je("history"),onOpenGraph:()=>Je("graph"),onOpenStashes:ba,onOpenUpdateBranch:es?()=>Ht(!0):void 0,diffScope:ts,onDiffScopeChange:ns,allCount:ce.length,workingCount:Zt.length,stagedCount:Xt,branchAvailable:Ae,diffHeaderState:Ia}):null,La=Ft?h?Aa.createPortal(e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:Ft}),h):e.jsx("div",{className:"flex h-10 shrink-0 items-center gap-1 border-b border-border px-2",children:Ft}):null;return r==="mobile"?e.jsx(mr,{currentDirectory:t??null,status:d,isGitRepo:l,isLoadingStatus:T,changeEntries:ce,stagedChangeEntries:Se,unstagedChangeEntries:Zt,effectiveRemotes:ve,syncAction:Ge,commitAction:mt,commitMessage:oe,hasPendingIndexMutation:Ut,revertingPaths:gt,isRevertingAll:xt,initialDiffPath:c,initialDiffStaged:m,onSyncAction:(i,p)=>{Rt(i,p)},onMoveChangePaths:pa,onRevertFile:i=>{ga(i)},onRevertAll:xa,onCommitMessageChange:he,onCommit:i=>{Et(i)},onVisiblePathsChange:Bs,loadDiff:ra}):t?l===null||l===!0&&!d?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e.jsx("span",{className:"typography-ui-label",children:"Checking repository..."})]})}):l===!1?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(a.Suspense,{fallback:null,children:e.jsx(js,{diffScope:"turn",hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0,toolbarSlot:h})})}):e.jsxs("div",{className:te("flex h-full flex-col overflow-hidden"),children:[La,t&&(d?.mergeInProgress?.head||d?.rebaseInProgress?.headName||d?.rebaseInProgress?.onto)&&e.jsx(Vn,{mergeInProgress:d?.mergeInProgress,rebaseInProgress:d?.rebaseInProgress,onContinue:Ca,onAbort:Sa,onResolveWithAI:ka,conflictCount:Na,isLoading:T}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col",children:(ce?.length??0)>0||Ae?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:null,children:e.jsx(js,{diffScope:ts,onDiffScopeChange:ns,branchBase:Ae?et:null,branchHead:Ae?Pe:null,showOpenInEditorAction:!0,hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,flushContent:!0,hideToolbar:!0,onHeaderControlsStateChange:Da})})}),ce.length>0?e.jsx("div",{ref:le,className:"shrink-0 px-4 pb-4 pt-2",children:e.jsx($s,{stagedCount:Xt,commitMessage:oe,onCommitMessageChange:he,onCommit:()=>Et({pushAfter:!1}),onCommitAndPush:()=>Et({pushAfter:!0}),commitAction:mt,hasPendingIndexMutation:Ut})}):null]}):e.jsx(Un,{onOpenStashes:()=>ht(!0)})})}),e.jsx(Tn,{currentDirectory:t,isUpdateBranchDialogOpen:Gs,setIsUpdateBranchDialogOpen:Ht,branchOperation:Zs,currentBranch:d?.current,localBranches:Qt,remoteBranches:Xe,updateTargetBranch:ua,onMerge:ja,onRebase:va,isBusy:fa,operationLogs:Js,onOperationComplete:ya,canShowBranchWorkflows:es,gitLogDialogMode:fe,setGitLogDialogMode:Je,onRefreshHistory:()=>{if(fe==="graph"){sa(i=>i+1);return}t&&x(t,s,ge)},isLogRefreshing:fe==="graph"?Xs:H,log:fe==="graph"?Qs??k:k,maxCount:fe==="graph"?wt:ge,onMaxCountChange:fe==="graph"?Fa:Ea,expandedCommitHashes:Os,onToggleCommit:Vs,commitFilesMap:_s,loadingCommitHashes:Hs,onCopyHash:Us,historyBranchDivider:aa,onConflict:fe==="graph"?$a:void 0,onActionSuccess:fe==="graph"?za:void 0,isStashesDialogOpen:Ms,setIsStashesDialogOpen:ht,hasUncommittedChanges:(d?.files?.length??0)>0,hasStagedChanges:Se.length>0,uncommittedFileCount:d?.files?.length??0,onStashesChanged:async i=>{t&&i?.affectsIndex&&X(t),await ee(!1),await re()},conflictDialogOpen:Ws,setConflictDialogOpen:xe,conflictFiles:Ks,conflictOperation:Ye,onAbortConflict:wa,onClearConflictState:me,stashDialogOpen:na,setStashDialogOpen:Nt,stashDialogOperation:Ct,stashDialogBranch:St,onConfirmStashAndRetry:Ra})]}):e.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:e.jsx("p",{className:"typography-ui-label text-muted-foreground",children:"Select a session or directory to view Git status"})})};export{Eo as GitView};