@openchamber/web 1.21.1 → 1.22.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.
- package/dist/assets/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
- package/dist/assets/{CommitSection-DwGiXyjf.js → CommitSection-CC5mFzO2.js} +1 -1
- package/dist/assets/DiffView-6xGdyI0n.js +4 -0
- package/dist/assets/FilesView-Bm3vT63N.js +17 -0
- package/dist/assets/GitView-B6y1Y69c.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-rwHz84MX.js} +1 -1
- package/dist/assets/LinearIssuesView-B0UM_Rkx.js +1 -0
- package/dist/assets/MarkdownImageGallery-sGilV9Hs.js +1 -0
- package/dist/assets/MarkdownRendererImpl--4sRsKBn.js +12 -0
- package/dist/assets/OnboardingScreen-CECL_Cms.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BGPl1s-U.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-Cvz9Z-io.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-BFMsnHk3.js} +4 -4
- package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-C1Qa09YO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-DzQlzMF4.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-C7kBQNAA.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
- package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-C3luvSd_.js} +4 -4
- package/dist/assets/{es-DwyXCqaL.js → es-CmU4HLv9.js} +3 -3
- package/dist/assets/{fr-CS7Csln9.js → fr-Bgyni40l.js} +4 -4
- package/dist/assets/index-C57jT0Sa.css +1 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-CWYs7sMK.js} +1 -1
- package/dist/assets/index-b0zDkWyg.js +7 -0
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-BO_q5ezD.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-D8qPqUAf.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-C1ImKinT.js} +4 -4
- package/dist/assets/{ko-CXuSfZv5.js → ko-CP7OdxYH.js} +4 -4
- package/dist/assets/main-D4rd8Hy5.js +928 -0
- package/dist/assets/{main-D5RWr6sJ.js → main-D7fwjW2z.js} +2 -2
- package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-D5rraz-g.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-Cg_DE3KL.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Bpql0QGw.js} +3 -3
- package/dist/assets/{pl-BJxry0Mi.js → pl-DQYSiGYX.js} +4 -4
- package/dist/assets/{pt-BR-DxLmkhdv.js → pt-BR-DytpsW4M.js} +3 -3
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-B_Bn7BbN.js} +2 -2
- package/dist/assets/renderMobileApp-DLfxMzGJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-HlRmXFGW.js +16 -0
- package/dist/assets/scheduledTasksApi-BPvxrynl.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CFAVs_lu.js} +1 -1
- package/dist/assets/tr-aizaUvft.js +6 -0
- package/dist/assets/{uk-ClgQjmlw.js → uk-DwnRxJZd.js} +3 -3
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-DWXGRUPZ.js} +191 -151
- package/dist/assets/useInlineCommentController-Cc0OCXr0.js +2 -0
- package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-CD-GFayc.js} +4 -4
- package/dist/assets/{zh-CN-Ba6y8H-i.js → zh-CN-UDNMxm7r.js} +3 -3
- package/dist/assets/zh-TW-BsswdYL-.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +4 -0
- package/server/lib/dictation/DOCUMENTATION.md +19 -6
- package/server/lib/dictation/local/model-catalog.js +220 -0
- package/server/lib/dictation/local/model-catalog.test.js +42 -0
- package/server/lib/dictation/local/sherpa-tts.js +41 -20
- package/server/lib/dictation/local/worker-process.js +2 -0
- package/server/lib/dictation/runtime.js +4 -0
- package/server/lib/dictation/service.js +27 -4
- package/server/lib/fs/DOCUMENTATION.md +4 -0
- package/server/lib/fs/routes.js +129 -0
- package/server/lib/fs/routes.test.js +219 -0
- package/server/lib/linear/DOCUMENTATION.md +97 -0
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
- package/server/lib/linear/auth.js +436 -0
- package/server/lib/linear/auth.test.js +242 -0
- package/server/lib/linear/client.js +191 -0
- package/server/lib/linear/index.js +61 -0
- package/server/lib/linear/issues.js +499 -0
- package/server/lib/linear/issues.test.js +512 -0
- package/server/lib/linear/mapping.js +188 -0
- package/server/lib/linear/mapping.test.js +147 -0
- package/server/lib/linear/oauth.js +345 -0
- package/server/lib/linear/oauth.test.js +166 -0
- package/server/lib/linear/parse.js +23 -0
- package/server/lib/linear/routes.js +432 -0
- package/server/lib/linear/routes.test.js +661 -0
- package/server/lib/linear/status-runtime.js +64 -0
- package/server/lib/linear/status-runtime.test.js +167 -0
- package/server/lib/linear/status.js +280 -0
- package/server/lib/linear/status.test.js +271 -0
- package/server/lib/linear/teams.js +72 -0
- package/server/lib/linear/teams.test.js +94 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/tts/DOCUMENTATION.md +1 -0
- package/server/lib/tts/language-detect.js +210 -0
- package/server/lib/tts/language-detect.test.js +76 -0
- package/server/lib/tts/routes.js +23 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/dist/assets/DiffView-Db6bjVv1.js +0 -4
- package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
- package/dist/assets/GitView-CHzJxTi0.js +0 -6
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
- package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
- package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
- package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
- package/dist/assets/index-CUKcHnUA.css +0 -1
- package/dist/assets/index-DIvDEKE-.js +0 -7
- package/dist/assets/main-DLlfDjQ_.js +0 -926
- package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
- package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/zh-TW-Dv8yyhN1.js +0 -15
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import{f as gt,R as n,c as Nn,j as s,r as nr}from"./vendor-react-BUCujlKS.js";import{Q as aa,R as oa,S as la,T as ca,ak as Cn,n as He,u as ht,d1 as ua,C as Sn,w as da,r as kn,V as Rn,e as fa,c$ as ma,aN as pa,d0 as ha,a as ga}from"./index-DIvDEKE-.js";import{f as Bt,y as Tn,ab as Jn,bQ as xa,h as q,hi as va,fc as wa,S as ss,B as z,I as b,V as ba,L as ya,bo as ja,ac as Fa,c6 as Na,hj as Vn,hk as Ca,gP as Sa,t as Q,l as En,al as ir,c1 as Fs,cB as ka,b as Ra,hl as ar,bD as Ta,am as Dn,hm as Pn,c2 as Mn,c3 as Va,g2 as Ea,hn as Da,ho as Pa,hp as Ma,bE as Qn,bF as Yn,bG as Zn,bH as ei,bI as ti,bJ as si,b2 as fr,a$ as mr,ao as Cs,b1 as pr,a_ as Ss,c0 as or,an as lr,bY as zn,a6 as zt,a7 as At,a8 as Lt,bB as za,bC as Aa,g as Rs,b0 as La,b8 as Ia}from"./useAppFontEffects-KP8_yiGW.js";import{Z as Oa,w as Ba,x as $a,y as Wa,z as _a,A as Ua}from"./runtimeEndpointReset-D6SmNZaP.js";import{c as An,s as Ka,C as Ln,P as cr}from"./shikiHighlight-fGmFkxAM.js";import{a as Ha}from"./vendor-codemirror-state-C9awkmn-.js";import{E as jt}from"./vendor-codemirror-view-CiLROUVV.js";import{J as Ga,F as qa}from"./JsonTreeView-CggOsLot.js";import{ensurePierreThemeRegistered as In,getResolvedShikiTheme as Xa}from"./appThemeRegistry-BK0dHKa6.js";import{V as Ja,W as Qa}from"./Virtualizer-CZlLSacm.js";import{V as Ya}from"./Virtualizer-D_a8gKmg.js";import{u as Ns,c as Za,e as eo}from"./scheduledTasksApi-mjMDet_H.js";import{D as to}from"./vendor-react-drawio-Ct3Q0DsD.js";import{I as so,u as ro,n as no}from"./useInlineCommentController-HIjtuhxD.js";import{b as io}from"./CodeMirrorCommentWidgets-BGj8TJxW.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C9abMBTb.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DrTPkHl4.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./web-components-DOXvU-tB.js";import"./computeVirtualFileMetrics-CZ0xPeaT.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./isFilePlainText-DiLRrkJr.js";import"./registerCustomTheme-BBXUCRnG.js";function On(a){const e=gt.c(41),{containerRef:r,filePath:d,fileContent:v}=a,{t:g}=Bt(),x=Tn(po),w=Tn(mo),f=Jn(),C=xa(fo),[h,F]=n.useState(null),[N,k]=n.useState(""),[j,T]=n.useState(!1),o=n.useRef(!1),L=n.useRef(null),I=n.useRef(null),[W,A]=n.useState(null);let E;e[0]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{F(null),k(""),T(!1),o.current=!1,I.current=null,A(null)},e[0]=E):E=e[0];const V=E;let S,M;e[1]!==r?(S=()=>{const B=r.current;if(!B)return;const G=()=>{if(o.current)return;const re=window.getSelection(),Se=re?.toString().trim()??"";if(!re||!Se||re.rangeCount===0){V();return}const ie=re.getRangeAt(0);if(!B.contains(ie.commonAncestorContainer)){V();return}const ae=ie.getBoundingClientRect();I.current=ie.cloneRange(),k(Se),F({x:ae.left+ae.width/2,y:ae.top-10})},se=re=>{L.current?.contains(re.target)||o.current&&V()};return document.addEventListener("selectionchange",G),document.addEventListener("pointerdown",se),()=>{document.removeEventListener("selectionchange",G),document.removeEventListener("pointerdown",se)}},M=[r,V],e[1]=r,e[2]=S,e[3]=M):(S=e[2],M=e[3]),n.useEffect(S,M);let $;e[4]!==v?($=B=>{const G=de=>v.slice(0,de).split(`
|
|
2
|
-
`).length,se=co,re=(de,Ve)=>{for(const Ee of se(de)){const ke=v.indexOf(Ee,Ve);if(ke>=0)return ke}return-1},Se=B.length>=8?v.indexOf(B):-1;if(Se>=0){const de=G(Se);return{start:de,end:de+B.split(`
|
|
3
|
-
`).length-1}}const ie=B.split(`
|
|
4
|
-
`).map(lo).filter(Boolean);if(ie.length===0)return null;const ae=re(ie[0],0);if(ae<0)return null;const ye=G(ae);if(ie.length===1)return{start:ye,end:ye};const Te=re(ie[ie.length-1],ae);return Te<0?null:{start:ye,end:Math.max(ye,G(Te))}},e[4]=v,e[5]=$):$=e[5];const P=$;let J;e[6]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{const B=I.current;if(!B){A(null);return}A(va(B))},e[6]=J):J=e[6];const Ne=J;let H,Y;e[7]!==j?(H=()=>{if(!j)return;let B=null;const G=()=>{B===null&&(B=window.requestAnimationFrame(()=>{B=null,Ne()}))};return document.addEventListener("scroll",G,{capture:!0,passive:!0}),window.addEventListener("resize",G),()=>{B!==null&&window.cancelAnimationFrame(B),document.removeEventListener("scroll",G,{capture:!0}),window.removeEventListener("resize",G)}},Y=[j,Ne],e[7]=j,e[8]=H,e[9]=Y):(H=e[8],Y=e[9]),n.useEffect(H,Y);let ee;e[10]!==N?(ee=()=>{N&&(T(!0),o.current=!0,Ne(),window.getSelection()?.removeAllRanges())},e[10]=N,e[11]=ee):ee=e[11];const le=ee;let te;e[12]!==C||e[13]!==x||e[14]!==f||e[15]!==d||e[16]!==w||e[17]!==P||e[18]!==N?(te=B=>{const G=x??(w?"draft":null);if(!N||!G||!f){V();return}const se=P(N);C({directory:f,sessionKey:G},{source:"file-quote",fileLabel:d,startLine:se?.start??0,endLine:se?.end??0,code:N,language:"",text:B.trim()}),V(),queueMicrotask(oo)},e[12]=C,e[13]=x,e[14]=f,e[15]=d,e[16]=w,e[17]=P,e[18]=N,e[19]=te):te=e[19];const Ce=te;if(!h)return null;let O;e[20]!==j||e[21]!==P||e[22]!==N?(O=j?P(N):null,e[20]=j,e[21]=P,e[22]=N,e[23]=O):O=e[23];const ve=O;let we;e[24]!==h.x||e[25]!==h.y?(we={left:h.x,top:h.y,transform:"translate(-50%, -100%)"},e[24]=h.x,e[25]=h.y,e[26]=we):we=e[26];let ce;e[27]!==j||e[28]!==W?(ce=j&&W&&W.length>0?Nn.createPortal(s.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:W.map(ao)}),document.body):null,e[27]=j,e[28]=W,e[29]=ce):ce=e[29];let ue;e[30]!==j||e[31]!==d||e[32]!==ve||e[33]!==le||e[34]!==Ce||e[35]!==g?(ue=j?s.jsx("div",{className:"w-[min(420px,80vw)]",children:s.jsx(so,{fileLabel:d,lineRange:ve?{start:ve.start,end:ve.end}:void 0,onSave:Ce,onCancel:V})}):s.jsx("div",{className:q("flex items-center whitespace-nowrap","oc-glass-popover rounded-full border border-[var(--interactive-border)]","shadow-[0_4px_16px_-4px_rgb(0_0_0_/_0.12)]","p-1"),children:s.jsx("button",{type:"button",onClick:le,className:q("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-[var(--surface-foreground)]","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:g("chat.textSelection.title.commentOnSelection"),children:g("chat.textSelection.actions.comment")})}),e[30]=j,e[31]=d,e[32]=ve,e[33]=le,e[34]=Ce,e[35]=g,e[36]=ue):ue=e[36];let be;return e[37]!==we||e[38]!==ce||e[39]!==ue?(be=Nn.createPortal(s.jsxs("div",{ref:L,className:"fixed z-50",style:we,children:[ce,ue]}),document.body),e[37]=we,e[38]=ce,e[39]=ue,e[40]=be):be=e[40],be}function ao(a,e){return s.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:a.left,top:a.top,width:a.width,height:a.height}},e)}function oo(){wa()}function lo(a){return a.trim()}function co(a){const e=a.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(uo)}function uo(a){return a.length>=8}function fo(a){return a.addDraft}function mo(a){return a.newSessionDraft?.open}function po(a){return a.currentSessionId}const ho=(a,e)=>{if(!e)return null;const r=Number.parseInt(a.trim(),10);return!Number.isFinite(r)||r<1?null:Math.min(r,e.state.doc.lines)},Bn=(a,e)=>{const r=a.state.doc.lineAt(e.main.head);return{lineNumber:r.number,character:e.main.head-r.from+1,selection:e}},$n=(a,e,r)=>{const d=a.state.doc.line(e),v=Math.max(1,Math.min(r,d.length+1)),g=d.from+v-1;a.dispatch({selection:Ha.cursor(g),effects:jt.scrollIntoView(g,{y:"center"})})};function go({open:a,onOpenChange:e,view:r,variant:d="overlay"}){const{t:v}=Bt(),[g,x]=n.useState(""),w=n.useRef(null),f=n.useRef(!1),C=n.useRef(null),h=n.useRef(null),F=n.useMemo(()=>ho(g,r),[g,r]);n.useEffect(()=>{!a||!r||(f.current=!1,w.current=Bn(r,r.state.selection),x(""))},[a,r]),n.useEffect(()=>{a&&window.requestAnimationFrame(()=>{h.current?.focus(),h.current?.select()})},[a]),n.useEffect(()=>{if(!(!a||!r||!w.current)){if(F===null){const{selection:o}=w.current;r.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})});return}$n(r,F,w.current.character)}},[F,a,r]);const N=n.useCallback(()=>{if(!r||f.current||!w.current)return;const{selection:o}=w.current;r.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})})},[r]),k=n.useCallback(o=>{o||N(),e(o)},[e,N]),j=n.useCallback(()=>{!r||F===null||!w.current||(f.current=!0,$n(r,F,w.current.character),e(!1),r.focus())},[F,e,r]);n.useEffect(()=>{if(!a)return;const o=I=>{const W=C.current,A=I.target;!W||!(A instanceof Node)||W.contains(A)||k(!1)},L=I=>{I.key==="Escape"&&(I.preventDefault(),k(!1))};return document.addEventListener("pointerdown",o,!0),document.addEventListener("keydown",L,!0),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("keydown",L,!0)}},[k,a,d]);const T=n.useMemo(()=>{if(!r)return v("goToLineDialog.helper.editorUnavailable");if(F===null){const o=w.current??Bn(r,r.state.selection);return v("goToLineDialog.helper.currentLineRange",{current:o.lineNumber,max:r.state.doc.lines})}return v("goToLineDialog.helper.goToLine",{line:F})},[F,v,r]);return d==="inline"?a?s.jsxs("div",{ref:C,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(ss,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>x(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:v("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(z,{variant:"outline",size:"xs",onClick:j,disabled:!r||F===null,className:"h-6 px-2",children:v("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:C,className:q("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",a?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(ss,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>x(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:v("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:T})]})})}const xo=(a,e)=>{const r=e.trim().toLowerCase(),d=[];if(!r)return d;const v=a.toLowerCase();let g=0;for(;;){const x=v.indexOf(r,g);if(x===-1)break;d.push({start:x,end:x+r.length}),g=x+r.length}return d},Vs="data-md-find",ur="data-md-find-current",ri="rounded-[2px] bg-status-warning/30 text-foreground",vo="rounded-[2px] bg-status-warning/60 text-foreground",wo=120,bo=a=>a instanceof Element&&a.hasAttribute(Vs),yo=a=>a.target instanceof Element&&a.target.hasAttribute(Vs)?!0:[...a.addedNodes].some(e=>bo(e)),ni=a=>{const e=new Set;a.querySelectorAll(`mark[${Vs}]`).forEach(r=>{const d=r.parentNode;d&&(d.replaceChild(document.createTextNode(r.textContent??""),r),e.add(d))}),e.forEach(r=>r.normalize())},jo=(a,e)=>{ni(a);const r=e.trim().toLowerCase();if(!r)return[];const d=[],v=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode(x){const w=x.parentElement;return!w||w.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),g=[];for(;v.nextNode();){const x=v.currentNode;x instanceof Text&&g.push(x)}for(const x of g){const w=x.nodeValue??"";if(!w)continue;const f=xo(w,r);if(f.length===0)continue;const C=x.parentNode;if(!C)continue;const h=document.createDocumentFragment();let F=0;for(const N of f){N.start>F&&h.appendChild(document.createTextNode(w.slice(F,N.start)));const k=document.createElement("mark");k.setAttribute(Vs,""),k.className=ri,k.textContent=w.slice(N.start,N.end),h.appendChild(k),d.push(k),F=N.end}F<w.length&&h.appendChild(document.createTextNode(w.slice(F))),C.replaceChild(h,x)}return d},Wn=({containerRef:a,open:e,onOpenChange:r,focusNonce:d,className:v})=>{const{t:g}=Bt(),[x,w]=n.useState(""),[f,C]=n.useState(0),[h,F]=n.useState(0),N=n.useRef(null),k=n.useRef([]),j=n.useRef(x);j.current=x;const T=n.useRef(null),o=n.useRef(null),L=n.useCallback((S,M=!1)=>{const $=a.current;if(!$){k.current=[],C(0),F(0);return}k.current=jo($,S);const P=k.current.length;C(P),F(J=>!M||P===0?0:Math.min(J,P-1))},[a]),I=n.useCallback((S,M=!1)=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{T.current=null,L(S,M)},wo)},[L]);n.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const W=n.useCallback(()=>{r(!1);const S=o.current;o.current=null,S?.isConnected&&S.focus()},[r]);n.useEffect(()=>{const S=a.current;if(!e||!S)return;const M=new MutationObserver($=>{!j.current.trim()||!$.some(J=>!yo(J))||I(j.current,!0)});return M.observe(S,{childList:!0,subtree:!0,characterData:!0}),()=>{M.disconnect(),ni(S)}},[a,e,I]),n.useEffect(()=>{if(!e)return;const S=document.activeElement;S instanceof HTMLElement&&!o.current&&(o.current=S),N.current?.focus()},[e]),n.useEffect(()=>{e&&d>0&&(N.current?.focus(),N.current?.select())},[e,d]),n.useEffect(()=>{const S=a.current;if(!S||(S.querySelectorAll(`mark[${ur}]`).forEach($=>{$.removeAttribute(ur),$.className=ri}),f===0))return;const M=k.current[Math.min(Math.max(h,0),f-1)];M&&(M.setAttribute(ur,""),M.className=vo,M.scrollIntoView({block:"nearest"}))},[a,h,f]);const A=n.useCallback(()=>{F(S=>f===0?0:(S+1)%f)},[f]),E=n.useCallback(()=>{F(S=>f===0?0:(S-1+f)%f)},[f]),V=n.useCallback(S=>{S.key==="Enter"?(S.preventDefault(),S.shiftKey?E():A()):S.key==="Escape"&&(S.preventDefault(),W())},[W,A,E]);return e?s.jsxs("div",{className:q("absolute right-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-1.5 py-1 shadow-lg",v),children:[s.jsx(b,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),s.jsx(ss,{ref:N,value:x,onChange:S=>{w(S.target.value),I(S.target.value)},onKeyDown:V,placeholder:g("filesView.preview.find.placeholder"),"aria-label":g("filesView.preview.find.placeholder"),className:"h-7 w-40 rounded-md px-2 py-0 text-sm md:w-56"}),s.jsx("span",{className:"min-w-12 px-1 text-center typography-micro text-muted-foreground tabular-nums","aria-live":"polite","aria-label":f>0?g("filesView.preview.find.countAria",{current:h+1,total:f}):g("filesView.preview.find.noMatches"),children:x.trim()&&f===0?g("filesView.preview.find.noMatches"):f>0?`${h+1}/${f}`:""}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:E,title:g("filesView.preview.find.previousAria"),"aria-label":g("filesView.preview.find.previousAria"),disabled:f===0,children:s.jsx(b,{name:"arrow-up",className:"size-3.5"})}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:A,title:g("filesView.preview.find.nextAria"),"aria-label":g("filesView.preview.find.nextAria"),disabled:f===0,children:s.jsx(b,{name:"arrow-down",className:"size-3.5"})}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:W,title:g("filesView.preview.find.closeAria"),"aria-label":g("filesView.preview.find.closeAria"),children:s.jsx(b,{name:"close",className:"size-3.5"})})]}):null};function _n(){const a=gt.c(8),[e]=nr.useState(Fo),r=nr.useRef(!1);let d;a[0]!==e?(d=f=>{if(f==null){e.cleanUp(),r.current=!1;return}r.current||(r.current=!0,e.setup(f,f.firstElementChild??void 0))},a[0]=e,a[1]=d):d=a[1];const v=d;let g,x;a[2]!==e?(g=()=>()=>{r.current=!1,e.cleanUp()},x=[e],a[2]=e,a[3]=g,a[4]=x):(g=a[3],x=a[4]),nr.useLayoutEffect(g,x);let w;return a[5]!==v||a[6]!==e?(w={virtualizer:e,setScroller:v},a[5]=v,a[6]=e,a[7]=w):w=a[7],w}function Fo(){return new Ya}function No(a){return!(!a.autoSaveEnabled||!a.isDirty||!a.canWrite||a.isSaving||a.fileLoading||a.isNonEditableBinary||!a.selectedFilePath||a.loadedFilePath!==a.selectedFilePath)}function Co(a){return a.selectedFilePath?a.isDirty?!(a.fileLoading||a.loadedFilePath!==a.selectedFilePath||a.isNonEditableBinary||a.draftContent===""&&a.fileContent!==""&&a.loadedFilePath!==a.selectedFilePath):!0:!1}const So='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function Un(){if(typeof document>"u")return!1;const a=document.documentElement.getAttribute("data-theme");return a==="dark"||!a&&window.matchMedia("(prefers-color-scheme: dark)").matches}const ko=n.forwardRef(function({xml:e,readOnly:r,className:d,onChange:v},g){const x=n.useRef(e),w=n.useRef(null),f=n.useRef(!1),[C,h]=n.useState(Un),F=n.useRef(e),N=n.useRef(e);N.current!==e&&(N.current=e,F.current=e,x.current=e);const k=n.useRef(C);k.current!==C&&(k.current=C,F.current=x.current);const j=n.useRef(null);n.useEffect(()=>{const L=()=>h(Un());L();const I=new MutationObserver(L);return I.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>I.disconnect()},[]),n.useEffect(()=>{const L=setTimeout(()=>{j.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(L)},[]),n.useImperativeHandle(g,()=>({getXml:()=>x.current}));const T=n.useCallback(()=>{!e&&!f.current&&(f.current=!0,setTimeout(()=>{w.current?.template({})},500))},[e]),o=n.useCallback(L=>{x.current=L.xml,v?.(L.xml)},[v]);return s.jsx("div",{ref:j,className:q("h-full w-full",d),children:s.jsx(to,{ref:w,xml:F.current||So,autosave:!0,urlParameters:{ui:r?"simple":C?"dark":"kennedy",spin:!0,libraries:!r,chrome:r,nav:r,layers:r,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:T,onAutoSave:o},C?"dark":"light")})}),Ro=a=>{const e=K(a);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const r=e.lastIndexOf("/");if(r<0)return e;if(r===0)return"/";const d=e.slice(0,r);return/^[A-Za-z]:$/.test(d)?`${d}/`:d},To=a=>{const e=gt.c(8),{label:r,iconDataUrl:d}=a,[v,g]=n.useState(!1);let x;e[0]!==r?(x=r.trim().slice(0,1).toUpperCase()||"?",e[0]=r,e[1]=x):x=e[1];const w=x;if(d&&!v){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>g(!0),e[2]=h):h=e[2];let F;return e[3]!==d?(F=s.jsx("img",{src:d,alt:"",className:"size-4 rounded-sm",onError:h}),e[3]=d,e[4]=F):F=e[4],F}let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=q("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=f):f=e[5];let C;return e[6]!==w?(C=s.jsx("span",{className:f,children:w}),e[6]=w,e[7]=C):C=e[7],C},Vo=a=>a.slice().sort((e,r)=>e.type!==r.type?e.type==="directory"?-1:1:e.name.localeCompare(r.name)),K=a=>{if(!a)return"";const e=a.replace(/\\/g,"/"),r=e.startsWith("//");let d=e.replace(/\/+/g,"/");r&&!d.startsWith("//")&&(d=`/${d}`);const v=d==="/",g=/^[A-Za-z]:\/$/.test(d);return!v&&!g&&(d=d.replace(/\/+$/,"")),d},Eo=a=>a.startsWith("/")||a.startsWith("//")||/^[A-Za-z]:\//.test(a),Ot=a=>/^[A-Za-z]:\//.test(a)?a.toLowerCase():a,Ts=(a,e)=>{const r=K(e),d=K(a);if(!r||!d)return!1;const v=Ot(r),g=Ot(d);return g===v||g.startsWith(`${v}/`)},Kn=(a,e)=>{const r=K(e),d=K(a);if(!Ts(d,r))return[];const g=d.slice(r.length).replace(/^\//,"").split("/"),x=[];let w=r;for(let f=0;f<g.length-1;f++)w=w?`${w}/${g[f]}`:g[f],x.push(w);return x},ks=(a,e)=>{if(!e)return"";const r=K(e);if(!a||!Ts(r,a))return r;const d=r.slice(a.length);return d.startsWith("/")?d.slice(1):d},Do=new Set(["node_modules"]),Po=a=>{const e=gt.c(3),{status:r}=a;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=d):d=e[0];const v=d[r];let g;return e[1]!==v?(g=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:v}}),e[1]=v,e[2]=g):g=e[2],g},Hn=a=>{const e=gt.c(11),{name:r}=a,d=n.useRef(null),v=n.useRef(null),[g,x]=n.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{const N=d.current,k=v.current;if(!N||!k)return;const j=()=>{x(k.scrollWidth>N.clientWidth+1)};j();const T=new ResizeObserver(j);return T.observe(N),T.observe(k),()=>{T.disconnect()}},e[0]=w):w=e[0];let f;e[1]!==r?(f=[r],e[1]=r,e[2]=f):f=e[2],n.useLayoutEffect(w,f);let C;e[3]!==r?(C=s.jsx("span",{ref:v,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:r}),e[3]=r,e[4]=C):C=e[4];let h;e[5]!==r||e[6]!==g?(h=g?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:r}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:r})]}):s.jsx("span",{className:"block min-w-0 truncate",children:r}),e[5]=r,e[6]=g,e[7]=h):h=e[7];let F;return e[8]!==C||e[9]!==h?(F=s.jsxs("span",{ref:d,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[C,h]}),e[8]=C,e[9]=h,e[10]=F):F=e[10],F},Mo=a=>Do.has(a),zo=a=>{const e=K(a);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ao=a=>{const r=(a instanceof Error?a.message:String(a??"")).toLowerCase();return r.includes("is a directory")||r.includes("eisdir")},Gn=a=>{const r=(a instanceof Error?a.message:String(a??"")).toLowerCase();return r.includes("file not found")||r.includes("enoent")||r.includes("no such file")||r.includes("does not exist")},It=2e5;function Lo(a){const e=a.length>400?`${a.slice(0,200)}${a.slice(-200)}`:a;let r=2166136261;for(let d=0;d<e.length;d+=1)r^=e.charCodeAt(d),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return`${a.length}:${r.toString(16)}`}const Io=a=>{let e=0,r=0;for(let d=0;d<a.length;d+=1)a.charCodeAt(d)===10&&(d>0&&a.charCodeAt(d-1)===13?e+=1:r+=1);return e>r?`\r
|
|
5
|
-
`:`
|
|
6
|
-
`},ii=a=>a.replace(/\r\n/g,`
|
|
7
|
-
`).replace(/\r/g,`
|
|
8
|
-
`),Oo=(a,e)=>{const r=ii(a);return e===`\r
|
|
9
|
-
`?r.replace(/\n/g,`\r
|
|
10
|
-
`):r},ai=(a,e)=>s.jsx(Cs,{filePath:a,extension:e}),qn=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},Bo=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},dr=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="html"||e==="htm"},$o=a=>{const e=gt.c(76),{node:r,root:d,isExpanded:v,isActive:g,isMobile:x,isBrowserClient:w,alwaysShowActions:f,status:C,badge:h,permissions:F,downloadFile:N,contextMenuPath:k,setContextMenuPath:j,rightClickMenuPath:T,setRightClickMenuPath:o,onSelect:L,onToggle:I,onRevealPath:W,onOpenDialog:A}=a,{t:E}=Bt(),V=r.type==="directory",{canRename:S,canCreateFile:M,canCreateFolder:$,canDelete:P,canReveal:J}=F,Ne=!V&&!!N,H=J&&!w,Y=S||M||$||P||Ne||H;let ee;e[0]!==Y||e[1]!==r.path||e[2]!==o?(ee=fe=>{Y&&(fe?.preventDefault(),o(r.path))},e[0]=Y,e[1]=r.path,e[2]=o,e[3]=ee):ee=e[3];const le=ee;let te;e[4]!==V||e[5]!==r||e[6]!==L||e[7]!==I?(te=()=>{V?I(r.path):L(r)},e[4]=V,e[5]=r,e[6]=L,e[7]=I,e[8]=te):te=e[8];const Ce=te;let O;e[9]!==r.path||e[10]!==j||e[11]!==o?(O=fe=>{fe.stopPropagation(),o(null),j(r.path)},e[9]=r.path,e[10]=j,e[11]=o,e[12]=O):O=e[12];const ve=O;let we;e[13]!==M||e[14]!==$||e[15]!==P||e[16]!==S||e[17]!==H||e[18]!==N||e[19]!==w||e[20]!==V||e[21]!==r||e[22]!==A||e[23]!==W||e[24]!==d||e[25]!==E?(we=fe=>{const{Item:he,Separator:Ze}=fe;return s.jsxs(s.Fragment,{children:[S&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("rename",r)},children:[s.jsx(b,{name:"edit",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.rename")]}),s.jsxs(he,{onClick:X=>{X.stopPropagation(),Rs(r.path).then(at=>{if(at.ok){Q.success(E("sidebarFilesTree.toast.pathCopied"));return}Q.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(b,{name:"file-copy",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.copyPath")]}),s.jsxs(he,{onClick:X=>{X.stopPropagation();const at=ks(d,r.path)||r.path;Rs(at).then(me=>{if(me.ok){Q.success(E("filesView.toast.relativePathCopied"));return}Q.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(b,{name:"file-copy-2",className:"mr-2 size-4"})," ",E("filesView.tree.menu.copyRelativePath")]}),!V&&N&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),N(r.path).catch(at=>{console.error("Download failed:",at),Q.error(E("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"})," ",E(w?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),H&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),W(r.path)},children:[s.jsx(b,{name:"folder-received",className:"mr-2 size-4"})," ",E(Ia())]}),V&&(M||$)&&s.jsxs(s.Fragment,{children:[s.jsx(Ze,{}),M&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("createFile",r)},children:[s.jsx(b,{name:"file-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFile")]}),$&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("createFolder",r)},children:[s.jsx(b,{name:"folder-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(Ze,{}),s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("delete",r)},className:"text-destructive focus:text-destructive",children:[s.jsx(b,{name:"delete-bin",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.delete")]})]})]})},e[13]=M,e[14]=$,e[15]=P,e[16]=S,e[17]=H,e[18]=N,e[19]=w,e[20]=V,e[21]=r,e[22]=A,e[23]=W,e[24]=d,e[25]=E,e[26]=we):we=e[26];const ce=we,ue=T===r.path;let be;e[27]!==r.path||e[28]!==o?(be=fe=>o(fe?r.path:null),e[27]=r.path,e[28]=o,e[29]=be):be=e[29];const B=x?void 0:le;let G;e[30]!==B?(G=s.jsx("div",{className:"group relative flex items-center",onContextMenu:B}),e[30]=B,e[31]=G):G=e[31];const se=x?void 0:le,re=g?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Se;e[32]!==re?(Se=q("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",re),e[32]=re,e[33]=Se):Se=e[33];let ie;e[34]!==V||e[35]!==v||e[36]!==r.extension||e[37]!==r.path?(ie=V?v?s.jsx(b,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(b,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):ai(r.path,r.extension),e[34]=V,e[35]=v,e[36]=r.extension,e[37]=r.path,e[38]=ie):ie=e[38];let ae;e[39]!==r.name||e[40]!==r.path?(ae=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:r.path,children:r.name}),e[39]=r.name,e[40]=r.path,e[41]=ae):ae=e[41];let ye;e[42]!==V||e[43]!==C?(ye=!V&&C&&s.jsx(Po,{status:C}),e[42]=V,e[43]=C,e[44]=ye):ye=e[44];let Te;e[45]!==h||e[46]!==V?(Te=V&&h&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[h.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",h.modified]}),h.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",h.added]})]}),e[45]=h,e[46]=V,e[47]=Te):Te=e[47];let de;e[48]!==Ce||e[49]!==Se||e[50]!==ie||e[51]!==ae||e[52]!==ye||e[53]!==Te||e[54]!==se?(de=s.jsxs("button",{type:"button",onClick:Ce,onContextMenu:se,className:Se,children:[ie,ae,ye,Te]}),e[48]=Ce,e[49]=Se,e[50]=ie,e[51]=ae,e[52]=ye,e[53]=Te,e[54]=se,e[55]=de):de=e[55];let Ve;e[56]!==f||e[57]!==k||e[58]!==ve||e[59]!==Y||e[60]!==x||e[61]!==r.path||e[62]!==ce||e[63]!==j?(Ve=Y&&s.jsx("div",{className:q("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(fr,{open:k===r.path,onOpenChange:fe=>j(fe?r.path:null),children:[s.jsx(mr,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"icon",className:"size-6",onClick:ve,children:s.jsx(b,{name:"more-2-fill",className:"size-4"})})}),s.jsx(pr,{align:"end",side:"bottom",onCloseAutoFocus:()=>j(null),children:ce({Item:Ss,Separator:La})})]})}),e[56]=f,e[57]=k,e[58]=ve,e[59]=Y,e[60]=x,e[61]=r.path,e[62]=ce,e[63]=j,e[64]=Ve):Ve=e[64];let Ee;e[65]!==de||e[66]!==Ve||e[67]!==G?(Ee=s.jsxs(_a,{render:G,children:[de,Ve]}),e[65]=de,e[66]=Ve,e[67]=G,e[68]=Ee):Ee=e[68];let ke;e[69]!==ce?(ke=s.jsx(Ba,{className:"min-w-[180px]",children:ce({Item:Wa,Separator:$a})}),e[69]=ce,e[70]=ke):ke=e[70];let Z;return e[71]!==Ee||e[72]!==ke||e[73]!==ue||e[74]!==be?(Z=s.jsxs(Ua,{open:ue,onOpenChange:be,children:[Ee,ke]}),e[71]=Ee,e[72]=ke,e[73]=ue,e[74]=be,e[75]=Z):Z=e[75],Z},Wo=a=>{const e=gt.c(83),{activeDialog:r,dialogData:d,dialogInputValue:v,onDialogInputChange:g,isDialogSubmitting:x,onDialogSubmit:w,onClose:f,inputRef:C}=a,{t:h}=Bt(),F=!!r;let N;e[0]!==f?(N=O=>!O&&f(),e[0]=f,e[1]=N):N=e[1];let k;e[2]!==r||e[3]!==h?(k=r==="createFile"&&h("filesView.dialog.createFile.title"),e[2]=r,e[3]=h,e[4]=k):k=e[4];let j;e[5]!==r||e[6]!==h?(j=r==="createFolder"&&h("filesView.dialog.createFolder.title"),e[5]=r,e[6]=h,e[7]=j):j=e[7];let T;e[8]!==r||e[9]!==h?(T=r==="rename"&&h("filesView.dialog.rename.title"),e[8]=r,e[9]=h,e[10]=T):T=e[10];let o;e[11]!==r||e[12]!==h?(o=r==="delete"&&h("filesView.dialog.delete.title"),e[11]=r,e[12]=h,e[13]=o):o=e[13];let L;e[14]!==k||e[15]!==j||e[16]!==T||e[17]!==o?(L=s.jsxs(ei,{children:[k,j,T,o]}),e[14]=k,e[15]=j,e[16]=T,e[17]=o,e[18]=L):L=e[18];let I;e[19]!==r||e[20]!==d?.path||e[21]!==h?(I=r==="createFile"&&h("filesView.dialog.createFile.description",{path:d?.path??h("filesView.dialog.rootFallback")}),e[19]=r,e[20]=d?.path,e[21]=h,e[22]=I):I=e[22];let W;e[23]!==r||e[24]!==d?.path||e[25]!==h?(W=r==="createFolder"&&h("filesView.dialog.createFolder.description",{path:d?.path??h("filesView.dialog.rootFallback")}),e[23]=r,e[24]=d?.path,e[25]=h,e[26]=W):W=e[26];let A;e[27]!==r||e[28]!==d?.name||e[29]!==h?(A=r==="rename"&&h("filesView.dialog.rename.description",{name:d?.name??""}),e[27]=r,e[28]=d?.name,e[29]=h,e[30]=A):A=e[30];let E;e[31]!==r||e[32]!==d?.name||e[33]!==h?(E=r==="delete"&&h("filesView.dialog.delete.description",{name:d?.name??""}),e[31]=r,e[32]=d?.name,e[33]=h,e[34]=E):E=e[34];let V;e[35]!==A||e[36]!==E||e[37]!==I||e[38]!==W?(V=s.jsxs(ti,{children:[I,W,A,E]}),e[35]=A,e[36]=E,e[37]=I,e[38]=W,e[39]=V):V=e[39];let S;e[40]!==V||e[41]!==L?(S=s.jsxs(Zn,{children:[L,V]}),e[40]=V,e[41]=L,e[42]=S):S=e[42];let M;e[43]!==r||e[44]!==v||e[45]!==C||e[46]!==g||e[47]!==w||e[48]!==h?(M=r!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(ss,{value:v,onChange:O=>g(O.target.value),placeholder:h(r==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:O=>{O.key==="Enter"&&w()},ref:C})}),e[43]=r,e[44]=v,e[45]=C,e[46]=g,e[47]=w,e[48]=h,e[49]=M):M=e[49];let $;e[50]!==h?($=h("filesView.dialog.cancel"),e[50]=h,e[51]=$):$=e[51];let P;e[52]!==x||e[53]!==f||e[54]!==$?(P=s.jsx(z,{variant:"outline",onClick:f,disabled:x,children:$}),e[52]=x,e[53]=f,e[54]=$,e[55]=P):P=e[55];const J=r==="delete"?"destructive":"default";let Ne;e[56]!==w?(Ne=()=>{w()},e[56]=w,e[57]=Ne):Ne=e[57];let H;e[58]!==r||e[59]!==v||e[60]!==x?(H=x||r!=="delete"&&!v.trim(),e[58]=r,e[59]=v,e[60]=x,e[61]=H):H=e[61];let Y;e[62]!==r||e[63]!==x||e[64]!==h?(Y=x?s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}):h(r==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=r,e[63]=x,e[64]=h,e[65]=Y):Y=e[65];let ee;e[66]!==J||e[67]!==Ne||e[68]!==H||e[69]!==Y?(ee=s.jsx(z,{variant:J,onClick:Ne,disabled:H,children:Y}),e[66]=J,e[67]=Ne,e[68]=H,e[69]=Y,e[70]=ee):ee=e[70];let le;e[71]!==P||e[72]!==ee?(le=s.jsxs(si,{children:[P,ee]}),e[71]=P,e[72]=ee,e[73]=le):le=e[73];let te;e[74]!==C||e[75]!==S||e[76]!==M||e[77]!==le?(te=s.jsxs(Yn,{initialFocus:C,children:[S,M,le]}),e[74]=C,e[75]=S,e[76]=M,e[77]=le,e[78]=te):te=e[78];let Ce;return e[79]!==F||e[80]!==N||e[81]!==te?(Ce=s.jsx(Qn,{open:F,onOpenChange:N,children:te}),e[79]=F,e[80]=N,e[81]=te,e[82]=Ce):Ce=e[82],Ce},Xn=(a,e,r)=>{const d=gt.c(8),[v,g]=n.useState(""),[x,w]=n.useState(0);let f,C;d[0]!==a||d[1]!==r||d[2]!==e?(f=()=>{if(!a){g("");return}let F=!1;g("");const N=fa(),k=ma(N);pa(N).then(T=>{F||!T||(g(a),e(null))}).catch(T=>{F||(e(T instanceof Error?T.message:r),g(a))});const j=ha(()=>{F||(g(a),w(_o),e(null))});return()=>{F=!0,k(),j()}},C=[a,e,r],d[0]=a,d[1]=r,d[2]=e,d[3]=f,d[4]=C):(f=d[3],C=d[4]),n.useEffect(f,C);let h;return d[5]!==x||d[6]!==v?(h={readyKey:v,nonce:x},d[5]=x,d[6]=v,d[7]=h):h=d[7],h},uu=({mode:a="full"})=>{const{t:e}=Bt(),{files:r,runtime:d}=ba(),{currentTheme:v,availableThemes:g,lightThemeId:x,darkThemeId:w}=ya(),{isMobile:f,isTablet:C,screenWidth:h}=ja(),F=aa(d.platform),N=f||C,k=oa(),j=la(),T=Jn()??"",o=K(T.trim()),L=a!=="editor-only",I=a==="editor-only"&&!f,W=ca(t=>t.searchFiles),A=Fa(T),[E,V]=n.useState(""),S=Na(E,200),M=n.useRef(null),[$,P]=n.useState(!1),[J,Ne]=n.useState(!0),[H,Y]=n.useState(!1),[ee,le]=n.useState(!1),te=n.useRef(0),Ce=n.useCallback(t=>{te.current=Math.max(0,te.current+(t?1:-1))},[]),[O,ve]=n.useState("edit"),[we,ce]=n.useState("edit"),[ue,be]=n.useState("tree"),[B,G]=n.useState("edit"),[se,re]=n.useState("preview"),[Se,ie]=n.useState(0),ae=n.useRef({}),ye=n.useRef({}),Te=n.useRef({}),de=n.useRef({}),Ve=n.useMemo(()=>g.find(t=>t.metadata.id===x)??Cn(!1),[g,x]),Ee=n.useMemo(()=>g.find(t=>t.metadata.id===w)??Cn(!0),[g,w]);n.useEffect(()=>{In(Ve),In(Ee)},[Ve,Ee]);const ke=n.useMemo(()=>[],[]),Z=He(t=>o?t.byRoot[o]?.openPaths??ke:ke),fe=He(t=>o?t.byRoot[o]?.selectedPath??null:null),he=He(t=>o?t.byRoot[o]?.expandedPaths??ke:ke),Ze=He(t=>t.removeOpenPath),X=He(t=>t.removeOpenPathsByPrefix),at=He(t=>t.removeExpandedPathsByPrefix),me=He(t=>t.setSelectedPath),hr=He(t=>t.toggleExpandedPath),rs=He(t=>t.expandPaths),Ft=n.useCallback(t=>{const i=K(t),l=i.split("/"),u=l[l.length-1]||i,p=u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;return{name:u,path:i,type:"file",extension:p}},[]),Nt=n.useMemo(()=>Z.map(Ft),[Z,Ft]),Es=n.useMemo(()=>{if(fe){const t=Ot(fe);if(Z.some(i=>Ot(i)===t))return fe}return Z[0]??null},[Z,fe]),c=n.useMemo(()=>Es?Ft(Es):null,[Es,Ft]),Ge=c?.path??"",[,oi]=n.useState(0);n.useEffect(()=>{if(!o||!fe)return;const t=Ot(fe);Z.some(l=>Ot(l)===t)||me(o,Z[0]??null)},[Z,o,fe,me]);const ns=!!(o&&Ge&&!Ts(Ge,o)),gr=ns?Vn(Ge):void 0,xt=n.useMemo(()=>({allowOutsideWorkspace:a==="editor-only"&&ns,outsideFileGrant:gr,directory:o||void 0}),[a,ns,gr,o]),qe=n.useCallback(async t=>{const i=Vn(t),l=await Ca(t,o,a==="editor-only");return l.outsideFileGrant&&l.outsideFileGrant!==i&&oi(u=>u+1),l},[a,o]),Ds=n.useRef(null),[xr,li]=n.useState({left:!1,right:!1}),vr=n.useCallback(()=>{const t=Ds.current;t&&li({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),wr=n.useRef(vr);wr.current=vr,n.useEffect(()=>{const t=Ds.current;if(!t)return;const i=()=>wr.current();i(),t.addEventListener("scroll",i,{passive:!0});const l=new ResizeObserver(i);return l.observe(t),()=>{t.removeEventListener("scroll",i),l.disconnect()}},[Nt.length]);const[br,Ps]=n.useState({}),[is,$t]=n.useState({}),ze=n.useRef(new Set),Ae=n.useRef(new Set),et=n.useRef(new Map),yr=n.useRef(0),[jr,as]=n.useState([]),[ci,os]=n.useState(!1),[D,pe]=n.useState(""),{isPlaying:ls,play:ui,stop:di}=Sa(),[Be,ot]=n.useState(!1),[tt,ge]=n.useState(null),[fi,Le]=n.useState(""),[De,oe]=n.useState(null),[ne,xe]=n.useState(""),[Wt,Ms]=n.useState(!1),[Fr,mi]=n.useState(`
|
|
11
|
-
`),pi=n.useRef(null),Xe=n.useRef(null),Pe=n.useRef(null),lt=n.useRef(""),_t=n.useRef(""),st=n.useRef(null),Nr=n.useRef(null),Je=n.useRef(null),Ut=n.useRef(0),Ct=n.useRef(null),[cs,hi]=n.useState(0),[gi,St]=n.useState("idle"),[xi,us]=n.useState(!1),[Kt,Cr]=n.useState(!1),je=ht(t=>t.autoSaveEnabled),vi=ht(t=>t.setAutoSaveEnabled),[zs,Ht]=n.useState(!1),kt=n.useRef(null),Gt=n.useRef(null),qt=n.useRef(!1),Xt=n.useRef(null),Jt=n.useRef(null),$e=n.useRef(null),ds=n.useRef(null),[wi,As]=n.useState(0),Rt=n.useRef(null),vt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{Rt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Rt.current),Rt.current=null)},[]);const[wt,Ls]=n.useState(null),[bt,bi]=n.useState(null),[ct,Sr]=n.useState(""),[yi,Is]=n.useState(!1),[ji,Fi]=n.useState(null),[Ni,Ci]=n.useState(null),[Si,kr]=n.useState(!1),[ki,Rr]=n.useState(!1),[Ri,Os]=n.useState(!1),[Tr,fs]=n.useState(!1),[Vr,Er]=n.useState(0),Bs=n.useRef(null),$s=n.useRef(null),Dr=!!r.writeFile,Pr=!!r.createDirectory,Mr=!!r.rename,zr=!!r.delete,Ar=!!r.revealPath,Ti=Ns(t=>t.availableApps),Vi=Ns(t=>t.isCacheStale),Lr=Ns(t=>t.initialize),Ei=Ns(t=>t.loadInstalledApps);n.useEffect(()=>{Lr()},[Lr]);const Di=n.useCallback(t=>{r.revealPath&&r.revealPath(t).catch(()=>{Q.error(e("sidebarFilesTree.toast.revealFailed"))})},[r,e]),Pi=n.useCallback(async t=>{if(!c?.path||await ua(c.path,t.id,t.appName)||await Sn(c.path,t.appName))return;const u=Ro(c.path)||o;u&&await Sn(u,t.appName)||Q.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[o,c?.path,e]),Ws=n.useCallback((t,i)=>{Ls(t),bi(i),Sr(t==="rename"&&i.name||""),Is(!1)},[]),[_,We]=n.useState(null),Tt=n.useRef(!1),ut=n.useRef(null),[Ir,Vt]=n.useState(!1),Qe=ht(t=>t.pendingFileNavigation),ms=ht(t=>t.setPendingFileNavigation),_s=ht(t=>t.pendingFileFocusPath),Us=ht(t=>t.setPendingFileFocusPath),Or=ht(t=>t.fileEditorKeymap),Qt=En(t=>t.settingsDefaultFileViewerPreview),Mi=En(t=>t.showMessageTTSButtons);n.useEffect(()=>{const t=()=>{Tt.current=!1,ut.current=null,Vt(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Xt.current!==null&&window.clearTimeout(Xt.current),Jt.current!==null&&window.clearTimeout(Jt.current)},[]);const zi=n.useCallback((t,i)=>{const l=t.split(`
|
|
12
|
-
`),u=Math.max(1,i.start),p=Math.min(l.length,i.end);return u>p?"":l.slice(u-1,p).join(`
|
|
13
|
-
`)},[]),ps=n.useRef(null),Ai=ro({source:"file",fileLabel:c?.path??null,language:c?.path&&ir(c.path)||"text",getCodeForRange:t=>zi(D,no(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Br,commentText:hs,setCommentText:$r,editingDraftId:gs,setSelection:Wr,saveComment:_r,cancel:Yt,reset:Ur,startEdit:Kr,deleteDraft:Hr}=Ai;n.useEffect(()=>{We(null),Ur(),xe(""),Ms(!1)},[c?.path,Ur]),n.useEffect(()=>{Wr(_)},[_,Wr]),n.useEffect(()=>{if(!_&&!gs)return;const t=l=>{const u=l.target;u.closest('[data-comment-input="true"]')||u.closest('[data-comment-card="true"]')||u.closest(".cm-gutterElement")||u.closest("[data-sonner-toast]")||u.closest("[data-sonner-toaster]")||hs.trim()||(We(null),Yt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Yt,hs,gs,_]);const Gr=n.useCallback((t,i)=>{const l=i??_??void 0;i&&We(i),_r(t,l),We(null)},[_,_r]),qr=n.useCallback((t,i)=>{const l=[];for(const u of i){if(!(u&&typeof u.name=="string"&&u.name.length>0)||!k&&u.name.startsWith(".")||!j&&Mo(u.name))continue;const p=u.name,m=K(u.path||""),y=m?Eo(m)?m:K(`${t}/${m}`):K(`${t}/${p}`),R=u.isDirectory?"directory":"file",U=R==="file"&&p.includes(".")?p.split(".").pop()?.toLowerCase():void 0;l.push({name:p,path:y,type:R,extension:U})}return Vo(l)},[j,k]),Ie=n.useCallback(async t=>{const i=K(t.trim());if(!i||ze.current.has(i)||Ae.current.has(i))return;Ae.current=new Set(Ae.current),Ae.current.add(i);const l=yr.current+1;yr.current=l,et.current=new Map(et.current),et.current.set(i,l);const u=()=>et.current.get(i)===l;await(r.listDirectory?r.listDirectory(i).then(m=>m.entries.map(y=>({name:y.name,path:y.path,isDirectory:y.isDirectory}))):da.listLocalDirectory(i).then(m=>m.map(y=>({name:y.name,path:y.path,isDirectory:y.isDirectory})))).then(m=>{if(!u())return;const y=qr(i,m);ze.current=new Set(ze.current),ze.current.add(i),$t(R=>{if(!R[i])return R;const U={...R};return delete U[i],U}),Ps(R=>({...R,[i]:y}))}).catch(m=>{if(!u())return;const y=m instanceof Error?m.message:String(m??"");if(y==="Directory not found"&&o&&i!==o){at(o,i),$t(R=>{if(!R[i])return R;const U={...R};return delete U[i],U});return}console.error("Failed to load files directory:",m),$t(R=>({...R,[i]:y}))}).finally(()=>{u()&&(et.current=new Map(et.current),et.current.delete(i),Ae.current=new Set(Ae.current),Ae.current.delete(i))})},[r,qr,at,o]),xs=n.useCallback(async()=>{o&&(ze.current=new Set,Ae.current=new Set,et.current=new Map,$t({}),Ps(t=>Object.keys(t).length===0?t:{}),await Ie(o))},[Ie,o]),Ye=n.useCallback(async t=>{if(!t){await xs();return}const i=K(t);ze.current=new Set(ze.current),ze.current.delete(i),Ae.current=new Set(Ae.current),Ae.current.delete(i),await Ie(i)},[Ie,xs]),Xr=n.useRef(""),Jr=n.useRef("");n.useEffect(()=>{if(!o)return;const t=`${o}|h${k?"1":"0"}|g${j?"1":"0"}`,i=Xr.current!==o,l=Jr.current!==t;!i&&!l||(i&&(Xr.current=o,pe(""),ge(null),Le(""),oe(null),P(!1)),l&&(Jr.current=t,ze.current=new Set,Ae.current=new Set,et.current=new Map,$t({}),Ps(u=>Object.keys(u).length===0?u:{}),Ie(o)))},[Ie,o,j,k]),n.useEffect(()=>{if(!r.listDirectory)return;const t=()=>{if(!document.hidden&&he.length>0)for(const i of he)Ye(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[he,r.listDirectory,Ye]),n.useEffect(()=>{if(!r.listDirectory||he.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of he)Ye(i)},8e3);return()=>clearInterval(t)},[he,r.listDirectory,Ye]);const Li=n.useCallback(async t=>{if(t?.preventDefault(),!bt||!wt)return;Is(!0);const i=()=>{Ls(null)},l=p=>{Q.error(p)},u=()=>{Is(!1)};if(wt==="createFile"){if(!ct.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),u();return}if(!r.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),u();return}const p=bt.path,m=p?`${p}/`:"",y=K(`${m}${ct.trim()}`);await r.writeFile(y,"").then(async R=>{R.success&&(Q.success(e("sidebarFilesTree.toast.fileCreated")),await Ye(p)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="createFolder"){if(!ct.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),u();return}const p=bt.path,m=p?`${p}/`:"",y=K(`${m}${ct.trim()}`);await r.createDirectory(y).then(async R=>{R.success&&(Q.success(e("sidebarFilesTree.toast.folderCreated")),await Ye(p)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="rename"){if(!ct.trim()){l(e("sidebarFilesTree.toast.nameRequired")),u();return}if(!r.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),u();return}const p=bt.path,m=p.split("/").slice(0,-1).join("/"),y=m?`${m}/`:"",R=K(`${y}${ct.trim()}`);await r.rename(p,R).then(async U=>{U.success&&(Q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Ye(m),o&&X(o,p),(c?.path===p||c?.path.startsWith(`${p}/`))&&(o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="delete"){if(!r.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),u();return}const p=bt.path,m=p.split("/").slice(0,-1).join("/");await r.delete(p).then(async y=>{y.success&&(Q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Ye(m),o&&X(o,p),(c?.path===p||c?.path.startsWith(`${p}/`))&&(o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}u()},[wt,bt,ct,r,Ye,f,X,o,c?.path,me,e]);n.useEffect(()=>{if(!T){as([]),os(!1);return}const t=S.trim();if(!t){as([]),os(!1);return}let i=!1;return os(!0),W(T,t,150,{includeHidden:k,respectGitignore:!j,type:"file"}).then(l=>{if(i)return;const p=l.filter(m=>j||!zo(m.path)).map(m=>({name:m.name,path:K(m.path),type:"file",extension:m.extension,relativePath:m.relativePath}));as(p)}).catch(()=>{i||as([])}).finally(()=>{i||os(!1)}),()=>{i=!0}},[T,S,W,k,j]);const Qr=n.useCallback(async t=>{const i=await qe(t);if(r.readFile)return(await r.readFile(t,{...i,directory:o||void 0})).content??"";const l=new URLSearchParams({path:t});i.allowOutsideWorkspace&&l.set("allowOutsideWorkspace","true"),i.outsideFileGrant&&l.set("outsideFileGrant",i.outsideFileGrant),o&&l.set("directory",o);const u=await kn(`/api/fs/read?${l.toString()}`);if(!u.ok){const p=await u.json().catch(()=>({error:u.statusText}));throw new Error(p.error||e("filesView.error.readFileFailed"))}return u.text()},[r,qe,o,e]),dt=n.useCallback(async t=>{if(r.statFile){const i=await qe(t),l=await r.statFile(t,{...i,directory:o||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[r,qe,o]);n.useEffect(()=>{if(!o||!r.statFile||Z.length===0)return;let t=!1;const i=[...Z];return Promise.all(i.map(async l=>{try{const u=await qe(l),p=await r.statFile?.(l,{...u,directory:o||void 0});!t&&p&&!p.isFile&&X(o,l)}catch(u){!t&&Gn(u)&&X(o,l)}})),()=>{t=!0}},[r,Z,X,qe,o]);const Ks=n.useMemo(()=>D.length>It?`${D.slice(0,It)}
|
|
14
|
-
|
|
15
|
-
… truncated …`:D,[D]),Me=ne!==Ks,Et=n.useCallback(async()=>{if(!c||!r.writeFile)return Q.error(e("filesView.toast.savingNotSupported")),!1;const t=Fs(c.path)||Kt;if(!Co({selectedFilePath:c.path,loadedFilePath:De,fileLoading:Be,isDirty:Me,draftContent:ne,fileContent:D,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):ne===""&&D!==""&&De!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${D.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!Me)return!0;Ms(!0);try{const i=Oo(ne,Fr);if(!(await r.writeFile(c.path,i))?.success)return Q.error(e("filesView.toast.writeFileFailed")),!1;if(pe(ne),o&&Ts(c.path,o)){const u=ks(o,c.path);u&&ka.requestGitRefresh({directory:o,paths:[u]})}if(o&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(K(c.path))){const u=Ra.getState().projects.find(p=>K(p.path)===K(o));if(u)try{await Za(u.id)}catch{Q.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&ar(c.path)&&(lt.current=ne,_t.current=ne),dt(c.path).then(u=>{u&&(Je.current=u)}).catch(()=>{}),!0}catch(i){return Q.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Ms(!1)}},[Kt,ne,D,Be,r,Me,Fr,De,dt,o,c,e]);n.useEffect(()=>{je||(St("idle"),Xe.current&&(clearTimeout(Xe.current),Xe.current=null))},[je]);const Yr=1500;n.useEffect(()=>{const t=!!(c&&r.writeFile),i=!!(c?.path&&(Fs(c.path)||Kt));if(No({autoSaveEnabled:je,isDirty:Me,canWrite:t,isSaving:Wt,fileLoading:Be,selectedFilePath:c?.path,loadedFilePath:De,isNonEditableBinary:i}))return Xe.current=setTimeout(()=>{Et().then(l=>{l&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},Yr),()=>{Xe.current&&(clearTimeout(Xe.current),Xe.current=null)}},[je,Kt,ne,Be,Me,De,c,r.writeFile,Wt,Et]),n.useEffect(()=>{St("idle")},[c?.path]),Ta({save_file:t=>{if(!(t.target instanceof Node)||!ds.current?.contains(t.target))return!1;Xe.current&&(clearTimeout(Xe.current),Xe.current=null),Wt||Et().then(i=>{i&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node))return!1;if(nt&&Ue()==="preview"){if(f||!(H?$s.current:Bs.current)?.contains(t.target))return!1;fs(!0),Er(l=>l+1);return}if(!ds.current?.contains(t.target))return!1;le(!0)}});const Zr=n.useCallback(async t=>{const i=Ut.current+1;Ut.current=i;const l=()=>{if(!o)return!1;const R=He.getState().byRoot[o],U=R?.selectedPath??R?.openPaths[0]??null;return Ut.current===i&&U===t.path};if(ge(null),Le(""),oe(null),Cr(!1),ot(!0),await qe(t.path),!l())return;const u=Dn(t.path),p=Pn(t.path),m=Mn(t.path),y=Fs(t.path);if(f&&P(!0),d.isDesktop&&u&&!p){pe(""),xe("");return}if(!d.isDesktop&&u&&!p){pe(""),xe(""),oe(t.path),ot(!1);return}if(m){pe(""),xe(""),oe(t.path),ot(!1);return}if(y){pe(""),xe(""),oe(t.path),ot(!1);return}await Qr(t.path).then(R=>{if(!l())return;if(Va(R)){Cr(!0),pe(""),xe(""),oe(t.path);return}const U=ii(R);mi(Io(R)),pe(U),lt.current=U,_t.current=U,xe(U.length>It?`${U.slice(0,It)}
|
|
16
|
-
|
|
17
|
-
… truncated …`:U),oe(t.path),dt(t.path).then(mt=>{mt&&l()&&(Je.current=mt)}).catch(()=>{})}).catch(R=>{if(l()){if(Ao(R)){if(ot(!1),o&&me(o,null),ge(null),pe(""),xe(""),oe(null),Je.current=null,E.trim().length>0&&V(""),f&&P(!1),o){const mt=[...Kn(t.path,o),t.path];mt.length>0&&rs(o,mt);for(const pt of mt)ze.current.has(pt)||Ie(pt)}return}if(Gn(R)){o&&X(o,t.path),pe(""),xe(""),ge(null),Je.current=null,f&&P(!1);return}pe(""),xe(""),ge(R instanceof Error?R.message:e("filesView.error.readFileFailed")),Je.current=null}}).finally(()=>{l()&&ot(!1)})},[rs,f,Ie,Qr,dt,X,qe,o,d.isDesktop,E,me,e]),vs=n.useCallback(async(t,i)=>{if(!o)return;const l=Kn(t,o),u=i?[...l,t]:l;u.length>0&&rs(o,u);const p=u.map(m=>{if(!ze.current.has(m))return Ie(m)}).filter(Boolean);await Promise.all(p)},[rs,Ie,o]),en=n.useCallback((t,i)=>{const l=i.findIndex(u=>u.path===t);return l===-1||i.length<=1?null:i[l+1]??i[l-1]??null},[]),Re=n.useCallback(async t=>{if(qt.current)qt.current=!1;else if(Me){Ht(!0),kt.current=t;return}o&&(me(o,t.path),vs(t.path,!1)),ge(null),Le(""),pe(""),lt.current="",_t.current="",xe(""),oe(null),f&&P(!0)},[vs,Me,f,o,me]);n.useEffect(()=>{c?.path&&vs(c.path,!1)},[vs,c?.path]),n.useEffect(()=>{if(!c){Ut.current+=1,Ct.current=null,ot(!1);return}if(De===c.path||Ct.current===c.path)return;const t=c.path;Ct.current=t,Zr(c).finally(()=>{Ct.current===t&&(Ct.current=null)})},[cs,Zr,De,c]);const Hs=n.useRef(Me);Hs.current=Me,n.useEffect(()=>eo(({runtimeKey:t,paths:i})=>{const l=c?.path;t!==ga()||!l||Hs.current||!i.includes(K(l))||(Ut.current+=1,Ct.current=null,Je.current=null,Le(""),ge(null),oe(null),hi(u=>u+1))}),[c?.path]),n.useEffect(()=>{if(!c?.path||De!==c.path)return;let t=!1;const i=window.setInterval(()=>{document.hidden||dt(c.path).then(l=>{if(t||!l)return;const u=Je.current;if(!u||u.path!==c.path){Je.current=l;return}const p=l.mtimeMs!==void 0&&u.mtimeMs!==void 0&&l.mtimeMs!==u.mtimeMs,m=l.size!==u.size;!p&&!m||Hs.current||(Je.current=l,oe(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(i)}},[De,dt,c?.path]);const Ii=n.useCallback(()=>{const t=kt.current,i=Gt.current;if(kt.current=null,Gt.current=null,qt.current=!0,Ht(!1),xe(Ks),i){o&&Ze(o,i),c?.path===i&&(t?Re(t):(o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1)));return}if(t){Re(t);return}},[Ks,Re,f,Ze,o,c?.path,me]),Oi=n.useCallback(async()=>{const t=kt.current,i=Gt.current;if(!await Et()){qt.current=!1;return}if(kt.current=null,Gt.current=null,qt.current=!0,Ht(!1),i){o&&Ze(o,i),c?.path===i&&(t?await Re(t):(o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1)));return}if(t){await Re(t);return}},[Re,f,Ze,o,Et,c?.path,me]),tn=n.useCallback(t=>{const i=c?.path===t,l=en(t,Nt);if(i&&Me){Ht(!0),kt.current=l,Gt.current=t;return}if(o&&Ze(o,t),!!i){if(l){Re(l);return}o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1)}},[en,Re,Me,f,Nt,Ze,o,c?.path,me]),Bi=n.useCallback(t=>{if(Z.includes(t))return"open";if(A?.files){const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=A.files.find(u=>u.path===i);if(l){if(l.index==="A"||l.working_dir==="?")return"git-added";if(l.index==="D")return"git-deleted";if(l.index==="M"||l.working_dir==="M")return"git-modified"}}return null},[Z,A,o]),$i=n.useCallback(t=>{if(!A?.files)return null;const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=i?`${i}/`:"";let u=0,p=0;for(const m of A.files)m.path.startsWith(l)&&((m.index==="M"||m.working_dir==="M")&&u++,(m.index==="A"||m.working_dir==="?")&&p++);return u+p>0?{modified:u,added:p}:null},[A,o]),Wi=n.useCallback(async t=>{const i=K(t);o&&(hr(o,i),ze.current.has(i)||await Ie(i))},[Ie,o,hr]),_i=n.useMemo(()=>({canRename:Mr,canCreateFile:Dr,canCreateFolder:Pr,canDelete:zr,canReveal:Ar}),[Mr,Dr,Pr,zr,Ar]);function sn(t,i){const l=br[t]??[];return l.map((u,p)=>{const m=u.type==="directory",y=m&&he.includes(u.path),R=c?.path===u.path,U=p===l.length-1;return s.jsxs("li",{className:"relative",children:[i>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),U&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx($o,{node:u,root:o,isExpanded:y,isActive:R,isMobile:f,isBrowserClient:F,alwaysShowActions:N,status:m?void 0:Bi(u.path),badge:m?$i(u.path):void 0,permissions:_i,downloadFile:r.downloadFile,contextMenuPath:ji,setContextMenuPath:Fi,rightClickMenuPath:Ni,setRightClickMenuPath:Ci,onSelect:Re,onToggle:Wi,onRevealPath:Di,onOpenDialog:Ws}),m&&y&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[is[u.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:is[u.path],children:is[u.path]}),s.jsxs(z,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ye(u.path)},children:[s.jsx(b,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,sn(u.path,i+1)]})]},u.path)})}const Fe=!!(c?.path&&Dn(c.path)),ws=!!(c?.path&&Pn(c.path)),Oe=!!(c?.path&&Mn(c.path)),Gs=!!(c?.path&&(Fs(c.path)||Kt)),rt=Gs&&!Fe&&!Oe,rn=n.useMemo(()=>K(Qe?.path??""),[Qe?.path]),Dt=!!(Qe&&rn&&Ge&&Ge===rn&&!Be&&!tt&&!Fe&&!Oe&&!rt),ft=n.useMemo(()=>ks(o,Ge),[Ge,o]),Ui=!!(c&&(!Fe||ws)&&!Oe&&!rt&&D.length>0),Ki=!!(c&&ft.length>0),_e=!!(c&&!ns&&!Gs&&!Fe&&r.writeFile&&D.length<=It),nt=!!(c?.path&&qn(c.path)),Zt=!!(c?.path&&Bo(c.path)),Pt=!!(c?.path&&dr(c.path)),es=!!(c?.path&&ar(c.path)),qs=!!(c&&!Gs&&!Fe)&&!nt&&!es&&!(Pt&&B==="preview"),Hi=nt&&we==="edit"||Pt&&B==="edit"||Zt&&ue==="text"||!nt&&!Pt&&!Zt&&O==="edit",bs=n.useMemo(()=>Ge?Ea(Ge):null,[Ge]),[nn,Xs]=n.useState(null);n.useEffect(()=>{let t=!1;const i=c?.path;if(!i||bs){Xs(null);return}return Xs(null),Da(i).then(l=>{t||Xs(l)}),()=>{t=!0}},[c?.path,bs]),n.useEffect(()=>{!_e&&O==="edit"&&ve("view")},[_e,O]);const Js="openchamber:files:md-viewer-mode",Qs="openchamber:files:html-viewer-mode",Ys="openchamber:files:json-viewer-mode";n.useEffect(()=>{const t=c?.path;if(!t)return;ve(ae.current[t]??"edit");let i=Qt?"preview":"edit";try{const p=localStorage.getItem(Js);(p==="preview"||p==="edit")&&(i=p)}catch{}ce(ye.current[t]??i);let l=Qt?"preview":"edit";try{const p=localStorage.getItem(Qs);(p==="preview"||p==="edit")&&(l=p)}catch{}G(Te.current[t]??l),re(de.current[t]??(Qt?"preview":"edit"));let u=Qt?"tree":"text";try{const p=localStorage.getItem(Ys);(p==="tree"||p==="text")&&(u=p)}catch{}be(u)},[c?.path,Qt]);const Gi=n.useCallback(t=>{const i=c?.path;i&&(ae.current[i]=t),ve(t)},[c?.path]),qi=n.useCallback(t=>{const i=c?.path;i&&(ye.current[i]=t),ce(t);try{localStorage.setItem(Js,t)}catch{}},[c?.path]),Ue=n.useCallback(()=>we,[we]),Xi=n.useCallback(t=>{be(t);try{localStorage.setItem(Ys,t)}catch{}},[]),Ji=n.useCallback(t=>{const i=c?.path;i&&(Te.current[i]=t),G(t);try{localStorage.setItem(Qs,t)}catch{}},[c?.path]),Qi=n.useCallback(t=>{const i=c?.path;if(i&&(de.current[i]=t),Pe.current&&(clearTimeout(Pe.current),Pe.current=null),st.current!==null&&(cancelAnimationFrame(st.current),st.current=null),t==="edit")xe(lt.current||D),re(t);else{lt.current=ne;const l=i;re("edit"),st.current=requestAnimationFrame(()=>{st.current=requestAnimationFrame(()=>{st.current=null,!(o&&l&&He.getState().byRoot[o]?.selectedPath!==l)&&(ie(u=>u+1),re("preview"))})});return}},[ne,D,o,c?.path]),Zs=n.useCallback(async(t,i)=>{if(!r.writeFile||i===_t.current)return!1;if(!(await r.writeFile(t,i))?.success)return Q.error(e("filesView.toast.writeFileFailed")),!1;lt.current=i,_t.current=i,xe(i);const u=await dt(t).catch(()=>null);return u&&(Je.current=u),!0},[r,dt,e]);n.useEffect(()=>()=>{Pe.current&&(clearTimeout(Pe.current),Pe.current=null),st.current!==null&&(cancelAnimationFrame(st.current),st.current=null)},[se,c?.path]);const Yi=n.useCallback(t=>{if(lt.current=t,!je||!c?.path||se!=="preview"||!r.writeFile)return;Pe.current&&clearTimeout(Pe.current);const i=c.path;Pe.current=setTimeout(()=>{Pe.current=null,Zs(i,t).then(l=>{l&&(us(!0),setTimeout(()=>us(!1),1500))}).catch(l=>{Q.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},Yr)},[je,se,r.writeFile,Zs,c?.path,e]),Zi=n.useMemo(()=>es&&(lt.current||ne)||D,[ne,D,es]),an=n.useCallback(()=>B,[B]);n.useEffect(()=>{const t=l=>{const u=l?"preview":"edit",p=l?"tree":"text";for(const m of Z)ae.current[m]="edit",qn(m)&&(ye.current[m]=u),dr(m)&&(Te.current[m]=u),ar(m)&&(de.current[m]=u);ve("edit"),ce(u),G(u),re(u),be(p);try{localStorage.setItem(Js,u),localStorage.setItem(Qs,u),localStorage.setItem(Ys,p)}catch{}},i=l=>{const u=!!l.detail?.enabled;t(u)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",i)}},[Z]),n.useEffect(()=>{if(!Qe||!o)return;const t=()=>{typeof window>"u"||Rt.current===null&&(Rt.current=window.requestAnimationFrame(()=>{Rt.current=null,As(it=>it+1)}))},i=(it,yt)=>{if(it.state.doc.length!==yt.length)return!1;if(yt.length===0)return!0;const rr=Math.min(128,yt.length);if(it.state.sliceDoc(0,rr)!==yt.slice(0,rr))return!1;const Fn=Math.max(0,yt.length-rr);return it.state.sliceDoc(Fn,yt.length)===yt.slice(Fn)},l=K(Qe.path);if(!l){ms(null),vt.current={key:"",attempts:0};return}const u=`${l}:${Qe.line}:${Qe.column??1}`;if(vt.current.key!==u&&(vt.current={key:u,attempts:0}),c?.path!==l){if(zs)return;Re(Ft(l));return}if(Be||De!==l)return;if(tt||Fe||Oe||rt){ms(null),vt.current={key:"",attempts:0};return}if(!_e)return;if(O!=="edit"){ve("edit");return}const p=$e.current;if(!p){t();return}if(!i(p,ne)){t();return}const m=Math.max(1,Math.min(Qe.line,p.state.doc.lines)),y=p.state.doc.line(m),R=Math.max(1,Qe.column||1),U=Math.max(0,y.to-y.from),mt=Math.min(U,R-1),pt=y.from+mt;if(!(p.state.selection.main.head===pt)||vt.current.attempts===0){vt.current.attempts+=1,p.dispatch({selection:{anchor:pt},effects:jt.scrollIntoView(pt,{y:"center"})}),p.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const it=$e.current;it&&(it.dispatch({selection:{anchor:pt},effects:jt.scrollIntoView(pt,{y:"center"})}),it.focus())}),ms(null),vt.current={key:"",attempts:0}},[_e,zs,ne,wi,tt,Be,Fe,Oe,rt,De,Re,Qe,o,c?.path,ms,O,Ft]),n.useEffect(()=>{if(!_s||!o)return;const t=K(_s);if(!t){Us(null);return}c?.path===t&&(Be||De!==t||(!tt&&!Fe&&!Oe&&!rt&&_e&&O==="edit"&&$e.current?.focus(),Us(null)))},[_e,tt,Be,Fe,Oe,rt,De,_s,o,c?.path,Us,O]);const Mt=n.useCallback(t=>{if(!f||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const l=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,l-(i.offsetTop+i.height))<=0)return;const p=t.state.selection.main.head,m=t.coordsAtPos(p);if(!m)return;const y=Math.round(i.offsetTop+i.height),U=m.bottom+20-y;U<=0||(t.scrollDOM.scrollTop+=U)},[f]);n.useEffect(()=>{if(!f||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{Mt($e.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[f,Mt]),Pa("open_go_to_line",t=>{if(!_e||O!=="edit"||f)return!1;const i=t.target;if(i?.closest('[role="dialog"]')||!(i instanceof Node)||!ds.current?.contains(i))return!1;const l=!!i?.closest(".cm-editor");if(!!i?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!l)return!1;Os(!0)});const ys=ht(t=>t.editorFontSize),on=n.useMemo(()=>{if(!c?.path)return[An(v,{fontSize:ys})];const t=ir(c.path),i=[An(v,t?{syntaxColors:!1,fontSize:ys}:{fontSize:ys})],l=bs??nn;return l&&i.push(l),t&&i.push(Ka({language:t,themeName:v.metadata.id,theme:Xa(v)})),J&&i.push(jt.lineWrapping),f&&i.push(jt.updateListener.of(u=>{u.view.hasFocus&&(u.selectionSet||u.focusChanged||u.viewportChanged||u.geometryChanged)&&window.requestAnimationFrame(()=>{Mt(u.view)})})),i},[v,c?.path,bs,nn,J,f,Mt,ys]),ln=n.useMemo(()=>({light:Ve.metadata.id,dark:Ee.metadata.id}),[Ve.metadata.id,Ee.metadata.id]),ts=c?.path&&Oe&&(!xt.allowOutsideWorkspace||xt.outsideFileGrant)?`${c.path}|${xt.allowOutsideWorkspace?"outside":"workspace"}|${xt.outsideFileGrant??""}|${cs}`:"",js=c?.path&&Pt&&B==="preview"&&!d.isVSCode?`${c.path}|${cs}`:"",cn=e("filesView.error.readFileFailed"),{readyKey:un,nonce:ea}=Xn(js,ge,cn),{readyKey:dn,nonce:fn}=Xn(ts,ge,cn),ta=!!(js&&un!==js),mn=!!(ts&&dn!==ts),pn=c?.path&&Fe?ws?`data:${Ma(c.path)};utf8,${encodeURIComponent(D)}`:fi:"",hn=c?.path&&Oe&&ts&&dn===ts?Rn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:xt.allowOutsideWorkspace?"true":void 0,outsideFileGrant:xt.outsideFileGrant,directory:o||void 0}):"",gn=n.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:hn,className:"h-full w-full border-0",title:t.name},fn)}),[hn,fn]);n.useEffect(()=>{let t=!1,i="";return(async()=>{if(!c?.path||!Fe||ws){Le("");return}ge(null);const u=await qe(c.path);if(t)return;await(r.readFileBinary?r.readFileBinary(c.path,u).then(m=>m.dataUrl):(async()=>{const m=await kn("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:u.allowOutsideWorkspace?"true":void 0,outsideFileGrant:u.outsideFileGrant,directory:o||void 0}});if(!m.ok)throw new Error(e("filesView.error.readFileFailed"));const y=await m.blob();return i=URL.createObjectURL(y),t?(URL.revokeObjectURL(i),i="",""):i})()).then(m=>{t||(Le(m),oe(c.path))}).catch(m=>{t||(Le(""),ge(m instanceof Error?m.message:e("filesView.error.readFileFailed")),oe(null))}).finally(()=>{t||ot(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[cs,r,Fe,ws,qe,o,c?.path,xt,e]);const sa=n.useCallback(()=>Ls(null),[]),ra=n.useMemo(()=>io({drafts:Br,editingDraftId:gs,commentText:hs,onTextChange:$r,selection:_,isDragging:Ir,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Gr,onCancel:()=>{We(null),Yt()},onEdit:t=>{Kr(t),We({start:t.startLine,end:t.endLine})},onDelete:Hr}),[Yt,hs,Hr,gs,Br,Gr,Ir,_,c?.path,$r,Kr]),xn=_n(),vn=_n(),er=Oa("unified"),Ke=D.length>It,tr=n.useMemo(()=>Ke?Lo(D):void 0,[D,Ke]),wn=n.useCallback((t,i,l)=>{const u={name:t.name,contents:i,lang:ir(t.path)||void 0},p=m=>s.jsx(qa,{file:Ke&&tr?{...u,cacheKey:`${t.path}:${tr}`}:u,options:{disableFileHeader:!0,overflow:J?"wrap":"scroll",theme:ln,themeType:v.metadata.variant==="dark"?"dark":"light"},className:Ke?"block w-full":"block h-full w-full",style:Ke?void 0:{height:"100%"}},m);return Ke?s.jsx("div",{className:"h-full",children:s.jsx(Ja.Provider,{value:l.virtualizer,children:s.jsx(Qa.Provider,{value:er,children:p(`${t.path}:${er?"pool":"pending"}`)})})}):s.jsx("div",{className:"h-full",children:p(t.path)})},[v.metadata.variant,Ke,tr,ln,er,J]),bn=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!c)return null;const l=i==="docked",u=za(Aa("save_file")),p=l?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",m=(y,R)=>s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:R})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:y})]});return s.jsxs("div",{className:p,children:[_e&&Hi&&s.jsxs(s.Fragment,{children:[Wt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(b,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):je&&gi==="saved"&&!Me?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(b,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Me?m(e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{Et()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),"aria-label":e("filesView.editor.saveAria",{shortcut:u}),children:s.jsx(b,{name:"save-3",className:"size-4"})})):null,m(e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>vi(!je),className:q("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",je?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:je?s.jsx(b,{name:"file-check-fill",className:"size-4"}):s.jsx(b,{name:"file-check",className:"size-4"})}))]}),s.jsxs(fr,{onOpenChange:Ce,children:[s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(mr,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(b,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(pr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ti.map(y=>s.jsxs(Ss,{className:"flex items-center gap-2",onClick:()=>{Pi(y)},children:[s.jsx(To,{label:y.label,iconDataUrl:y.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:y.label})]},y.id)),Vi?s.jsxs(Ss,{className:"flex items-center gap-2",onClick:()=>{Ei(!0)},children:[s.jsx(b,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Fe&&!Oe&&!rt&&s.jsxs(s.Fragment,{children:[m(e(J?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ne(!J),className:q("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",J?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(J?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(b,{name:"text-wrap",className:"size-4"})})),O==="edit"&&s.jsxs(s.Fragment,{children:[m(e("filesView.editor.findInFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:y=>{le(!ee),y.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(b,{name:"search",className:"size-4"})})),m(e("filesView.editor.goToLine"),s.jsx(z,{variant:"ghost",size:"sm",onClick:y=>{Os(R=>!R),y.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(b,{name:"menu-fold-2",className:"size-4"})})),s.jsx(go,{open:Ri,onOpenChange:Os,view:$e.current,variant:"inline"})]})]}),qs&&_e&&!Zt&&!Pt&&s.jsx(cr,{currentMode:O==="view"?"preview":"edit",onToggle:()=>{Gi(O==="view"?"edit":"view")}}),nt&&m(e(Ue()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>qi(Ue()==="preview"?"edit":"preview"),className:q("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",Ue()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(Ue()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(Ue()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(b,{name:Ue()==="preview"?"eye":"eye-off",className:"size-4"})})),dr(c?.path??"")&&s.jsx(cr,{currentMode:an(),onToggle:()=>{Ji(an()==="preview"?"edit":"preview")}}),nt&&Ue()==="preview"&&m(e("filesView.editor.findInFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{fs(!0),Er(y=>y+1)},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(b,{name:"search",className:"size-4"})})),nt&&Ue()==="preview"&&Mi&&s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(ls?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{ls?di():D.trim()&&ui(D)},children:ls?s.jsx(b,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"volume-up",className:"size-4"})})}),s.jsx(Lt,{sideOffset:8,children:e(ls?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),es&&s.jsxs(s.Fragment,{children:[s.jsx(cr,{currentMode:se,onToggle:()=>Qi(se==="preview"?"edit":"preview")}),se==="preview"&&s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{const y=Nr.current?.getXml();if(Pe.current&&(clearTimeout(Pe.current),Pe.current=null),c?.path&&y){if(!await Zs(c.path,y))return;us(!0),setTimeout(()=>us(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:xi?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"save-3",className:"size-4"})})]}),Zt&&m(e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Xi(ue==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ue==="tree"?s.jsx(b,{name:"code-sslash",className:"size-4"}):s.jsx(b,{name:"node-tree",className:"size-4"})})),Ui&&m(e("filesView.editor.copyFileContents"),s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Rs(D)).ok?(kr(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{kr(!1)},1200)):Q.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Si?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"clipboard",className:"size-4"})})),Ki&&m(e("filesView.editor.copyFilePathTitle",{path:ft}),s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Rs(ft)).ok?(Rr(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{Rr(!1)},1200)):Q.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ft}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ft}),children:ki?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"file-copy-2",className:"size-4"})})),r.downloadFile&&m(e("filesView.editor.saveFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{const y=r.downloadFile;y&&y(c.path).catch(R=>{console.error("Download failed:",R),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(b,{name:"download",className:"size-4"})})),t?m(e("filesView.editor.exitFullscreen"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Y(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(b,{name:"fullscreen-exit",className:"size-4"})})):!f&&a==="full"&&m(e(H?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Y(!H),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(H?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(H?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:H?s.jsx(b,{name:"fullscreen-exit",className:"size-4"}):s.jsx(b,{name:"fullscreen",className:"size-4"})}))]})},sr=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Qn,{open:zs,onOpenChange:t=>{t||Ht(!0)},children:s.jsxs(Yn,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Zn,{children:[s.jsx(ei,{children:e("filesView.unsaved.title")}),s.jsx(ti,{children:e("filesView.unsaved.description")})]}),s.jsxs(si,{children:[s.jsx(z,{variant:"outline",onClick:()=>{Oi()},disabled:Wt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(z,{variant:"destructive",onClick:Ii,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:q("flex flex-col flex-shrink-0",L&&"border-b border-border/40"),children:[L?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[f&&$&&s.jsx("button",{type:"button",onClick:()=>P(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(b,{name:"arrow-left-s",className:"size-5"})}),f?c?s.jsxs(fr,{children:[s.jsx(mr,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(Cs,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Hn,{name:c.name}),s.jsx(b,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(pr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Nt.map(t=>{const i=c?.path===t.path;return s.jsxs(Ss,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}i||Re(t)},className:q("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Cs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Hn,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),tn(t.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(b,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Nt.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[xr.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),xr.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Ds,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Nt.map(t=>{const i=c?.path===t.path;return s.jsxs("div",{title:ks(o,t.path),className:q("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(Cs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{i||Re(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),tn(t.path)},className:q("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!N&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(b,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,c?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[ft&&!f?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ft,children:ft}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:bn({layout:"docked"})})]}):null]}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(or,{ref:xn.setScroller,outerClassName:"h-full min-w-0",className:q("h-full min-w-0",Ke&&"[overflow-anchor:none]"),children:c?Be||mn?I?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):tt?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:tt}):Fe?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:pn,alt:c?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Oe?gn(c):rt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&es&&se==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(ko,{ref:Nr,xml:Zi,onChange:Yi},`${c.path}:${Se}`)}):c&&Zt&&ue==="tree"?s.jsx(lr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Ga,{jsonString:D,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&nt&&Ue()==="preview"?s.jsxs("div",{className:"relative h-full min-h-0",children:[s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3",ref:t=>{ps.current=t,Bs.current=t},children:[s.jsx(On,{containerRef:ps,filePath:c.path,fileContent:D}),D.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(lr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(zn,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),!H&&s.jsx(Wn,{containerRef:Bs,open:Tr,onOpenChange:fs,focusNonce:Vr})]}):c&&Pt&&B==="preview"?ta?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!d.isVSCode&&un===js?(()=>{const t=c.path.split("/").map(i=>encodeURIComponent(i)).join("/");return Rn().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:d.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?D.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):D})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},ea)}):c&&qs&&O==="view"?wn(c,Ke?D:ne,xn):s.jsxs("div",{className:q("relative h-full",Dt&&"overflow-hidden"),ref:ds,children:[s.jsx("div",{className:q("h-full",Dt&&"invisible"),children:s.jsx(Ln,{value:ne,onChange:xe,readOnly:!_e,vimMode:Or==="vim",extensions:on,className:"h-full",blockWidgets:ra,onViewReady:t=>{$e.current=t,As(i=>i+1),window.requestAnimationFrame(()=>{Mt(t)})},onViewDestroy:()=>{$e.current&&($e.current=null),As(t=>t+1)},enableSearch:!0,searchOpen:ee,onSearchOpenChange:le,highlightLines:_?{start:Math.min(_.start,_.end),end:Math.max(_.start,_.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const u=t.state.doc.lineAt(i.from).number;if(_&&!l.shiftKey&&Math.min(_.start,_.end)===u&&Math.max(_.start,_.end)===u)return We(null),Yt(),Tt.current=!1,ut.current=null,Vt(!1),!0;if(f&&_&&!l.shiftKey){const p=Math.min(_.start,_.end,u),m=Math.max(_.start,_.end,u);return We({start:p,end:m}),Tt.current=!1,ut.current=null,Vt(!1),!0}if(Tt.current=!0,ut.current=u,Vt(!0),_&&l.shiftKey){const p=Math.min(_.start,u),m=Math.max(_.end,u);We({start:p,end:m})}else We({start:u,end:u});return!0},mouseover:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Tt.current||ut.current===null)return!1;const u=t.state.doc.lineAt(i.from).number,p=Math.min(ut.current,u),m=Math.max(ut.current,u);return We({start:p,end:m}),Vt(!0),!1},mouseup:()=>(Tt.current=!1,ut.current=null,Vt(!1),!1)}}})}),Dt&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})})]}),na=!!(o&&br[o]),yn=o?is[o]:null,jn=s.jsxs("section",{className:q("flex min-h-0 flex-col overflow-hidden",f?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:q("flex flex-col gap-2 py-2",f?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(b,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(ss,{ref:M,value:E,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),E.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{V(""),M.current?.focus()},children:s.jsx(b,{name:"close",className:"size-4"})})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ws("createFile",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(b,{name:"file-add",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ws("createFolder",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(b,{name:"folder-add",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{xs()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(b,{name:"refresh",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(or,{outerClassName:"flex-1 min-h-0",className:q("py-2",f?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:ci?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):jr.length>0?jr.map(t=>{const i=c?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Re(t)},className:q("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[ai(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):yn?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:yn}),s.jsxs(z,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{xs()},children:[s.jsx(b,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):na?sn(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),ia=a==="full"&&H&&c&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:bn({exitFullscreenOnly:!0})}),s.jsx(or,{ref:vn.setScroller,outerClassName:"h-full min-w-0",className:q("h-full min-w-0",Ke&&"[overflow-anchor:none]"),children:Be||mn?I?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):tt?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:tt}):Fe?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:pn,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Oe?gn(c):rt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):nt&&Ue()==="preview"?s.jsxs("div",{className:"relative h-full min-h-0",children:[s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4",ref:t=>{ps.current=t,$s.current=t},children:[c?s.jsx(On,{containerRef:ps,filePath:c.path,fileContent:D}):null,D.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(lr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(zn,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),s.jsx(Wn,{containerRef:$s,open:Tr,onOpenChange:fs,focusNonce:Vr,className:"right-4 top-16"})]}):qs&&O==="view"?wn(c,Ke?D:ne,vn):s.jsxs("div",{className:q("relative h-full",Dt&&"overflow-hidden"),children:[s.jsx("div",{className:q("h-full",Dt&&"invisible"),children:s.jsx(Ln,{value:ne,onChange:xe,readOnly:!_e,vimMode:Or==="vim",extensions:on,className:"h-full",onViewReady:t=>{$e.current=t,window.requestAnimationFrame(()=>{Mt(t)})},onViewDestroy:()=>{$e.current&&($e.current=null)}})}),Dt&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(Wo,{activeDialog:wt,dialogData:bt,dialogInputValue:ct,onDialogInputChange:Sr,isDialogSubmitting:yi,onDialogSubmit:Li,onClose:sa,inputRef:pi}),ia,f?$?sr:jn:a==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:sr})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[h>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:jn}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:sr})]})]})};function _o(a){return a+1}export{uu as FilesView};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{R as l,r as be,j as t,f as Ct}from"./vendor-react-BUCujlKS.js";import{f as et,y as Xe,a0 as Rt,hK as Pn,cS as Jt,cd as Kt,t as b,I as T,b2 as Ps,a$ as Fs,cQ as br,b1 as Rs,cw as Bs,cx as Ds,cy as Ms,cz as Ts,cr as qt,cs as Yt,B as W,hL as Fn,hM as Rn,bE as ht,bF as gt,bG as ft,bH as pt,bI as yt,S as ir,a6 as Qt,a7 as Zt,a8 as Xt,hN as Bn,h as Ve,hO as Dn,hP as Mn,hQ as Tn,hR as En,a_ as Ln,al as An,bP as On,hS as zn,hT as Gn,hU as _n,hV as $n,hW as Hn,hX as Wn,hY as Un,c0 as vr,bS as Jn,bT as Kn,bU as qn,bV as Yn,bW as Qn,hZ as Zn,bZ as Xn,bJ as Is,eJ as ea,V as ta,ab as sa,ad as ra,ac as na,bu as aa,h_ as ia,b_ as oa,h$ as la,i0 as ca,ae as da,i1 as ua,af as ma,bN as ha,hD as ga,l as fa,b$ as pa,g as xa,cB as wa,ak as ya,a1 as ba,i2 as va,i3 as Ss}from"./useAppFontEffects-KP8_yiGW.js";import{a as ja,b as Ca,d as Na}from"./main-DLlfDjQ_.js";import{v as Sa,s as ka,q as Va,R as Ia,_ as Pa}from"./runtimeEndpointReset-D6SmNZaP.js";import{u as or}from"./vendor-zustand-BAGL70zf.js";import{r as Fa,u as Pt}from"./index-DIvDEKE-.js";import{C as Ra,a as Ba}from"./CommitSection-DwGiXyjf.js";import{P as Da}from"./PierreDiffViewer-CY2bx_SB.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C9abMBTb.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DrTPkHl4.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-BLfBSgBh.js";import"./useRootScrollLock-BSiQ5F75.js";import"./scheduledTasksApi-mjMDet_H.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-DOXvU-tB.js";import"./computeVirtualFileMetrics-CZ0xPeaT.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-BP7ebDFF.js";import"./isDiffPlainText-ZBvDxhVB.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-HIjtuhxD.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const jr="gitmojiCache",Ma=1e3*60*60*24*7,Cr="1",Ta="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Nr=i=>{if(!i||typeof i!="object")return!1;const e=i;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},ks=()=>{if(typeof window>"u")return null;try{const i=window.localStorage.getItem(jr);if(!i)return null;const e=JSON.parse(i);return!e||e.version!==Cr||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Nr),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Ea=i=>{if(!(typeof window>"u"))try{const e={gitmojis:i,fetchedAt:Date.now(),version:Cr};window.localStorage.setItem(jr,JSON.stringify(e))}catch{return}},lr=i=>Date.now()-i.fetchedAt<Ma;let Wt=null;const Ft=new Set,cr=async()=>{if(Wt)return Wt;const i=(async()=>{try{const e=await fetch(Ta);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(Nr):[];return Ea(r),Ft.forEach(v=>v(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return Ft.forEach(r=>r(n)),n}finally{Wt=null}})();return Wt=i,i},La=i=>{const[e,n]=l.useState(()=>i?ks()?.gitmojis??[]:[]),[r,v]=l.useState(!1),h=l.useRef(i);h.current=i,l.useEffect(()=>{if(!i){Ft.delete(n),n([]),v(!1);return}const f=ks();if(f&&(n(f.gitmojis),lr(f)))return;Ft.add(n),v(!0);let m=!1;return cr().finally(()=>{!m&&h.current&&v(!1)}),()=>{m=!0,Ft.delete(n)}},[i]);const p=l.useCallback(async()=>{if(!h.current)return[];if(e.length>0)return e;const f=ks();return f&&lr(f)?f.gitmojis:cr()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:p}},Nt=async(i,e)=>{const n=await Fa(`/api/git/integrate/${i}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function It(i){return Nt("plan",i)}async function Aa(i){return Nt("conflict-details",{tempWorktreePath:i})}async function Oa(i){return(await Nt("cherry-pick-status",{tempWorktreePath:i})).inProgress}async function za(i){return Nt("run",{plan:i})}async function Ga(i){await Nt("abort",{state:i})}async function _a(i){return Nt("continue",{state:i})}const $a=({repoRoot:i,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:v,refreshKey:h,onRefresh:p,showHeader:f=!0})=>{const{t:m}=et(),x=Xe(u=>u.currentSessionId),[M,y]=be.useState(!1),[k,L]=be.useState(""),N=be.useRef(null),O=be.useMemo(()=>Rt(r,k,u=>[u]),[r,k]),[j,w]=be.useState(v);be.useEffect(()=>{w(v)},[v]),be.useEffect(()=>{if(M){const u=setTimeout(()=>{N.current?.focus()},0);return()=>clearTimeout(u)}},[M]);const B=!!(i&&e&&j&&j!=="HEAD"&&e!==j),[S,R]=be.useState({kind:"idle"}),[I,P]=be.useState(!1),[g,H]=be.useState([]),E=be.useMemo(()=>x?`openchamber.integrate.conflict:${x}`:null,[x]);be.useEffect(()=>{if(!E||typeof window>"u")return;const u=window.localStorage.getItem(E);if(!u)return;let d=!1;try{const F=JSON.parse(u);if(!F?.tempWorktreePath||F.repoRoot!==i){window.localStorage.removeItem(E);return}(async()=>{const A=await Oa(F.tempWorktreePath).catch(()=>!1);if(d)return;if(!A){window.localStorage.removeItem(E);return}const q=await Aa(F.tempWorktreePath).catch(()=>null);d||q&&R({kind:"conflict",state:F,details:q})})()}catch{window.localStorage.removeItem(E)}return()=>{d=!0}},[E,i]),be.useEffect(()=>{if(!B){R({kind:"idle"});return}let u=!1;return R({kind:"loading"}),(async()=>{try{const d=await It({repoRoot:i,sourceBranch:e,targetBranch:j});if(u)return;if(R({kind:"ready",plan:d}),d.commits.length>0){const A=d.commits.slice(-50).reverse(),q=await Pn(i,A);u||(H(q),P(!1))}else u||(H([]),P(!1))}catch{u||R({kind:"idle"})}})(),()=>{u=!0}},[B,i,e,j,h]);const V=be.useCallback(u=>{x&&Xe.getState().setWorktreeMetadata(x,{...n,createdFromBranch:u})},[x,n]),D=Xe(u=>u.openNewSessionDraft),U=be.useCallback(async u=>{const d=await Jt("git.integrate.cherrypick.resolve.visible",{current_commit:u.state.currentCommit,target_branch:u.state.targetBranch}),F=await Jt("git.integrate.cherrypick.resolve.instructions",{repo_root:u.state.repoRoot,temp_worktree_path:u.state.tempWorktreePath,source_branch:u.state.sourceBranch,target_branch:u.state.targetBranch,current_commit:u.state.currentCommit}),A=`Cherry-pick conflict context (JSON)
|
|
2
|
-
${JSON.stringify({repoRoot:u.state.repoRoot,tempWorktreePath:u.state.tempWorktreePath,sourceBranch:u.state.sourceBranch,targetBranch:u.state.targetBranch,currentCommit:u.state.currentCommit,remainingCommits:u.state.remainingCommits,statusPorcelain:u.details.statusPorcelain,unmergedFiles:u.details.unmergedFiles,currentPatchMeta:u.details.currentPatchMeta,currentPatch:u.details.currentPatch,diff:u.details.diff},null,2)}`;return{visibleText:d,instructionsText:F,payloadText:A}},[]),$=Kt(u=>u.setPendingInputText),_=Kt(u=>u.setPendingSyntheticParts),Y=be.useCallback(async(u,d)=>{const F=await U(u);if(d){D({directoryOverride:u.state.tempWorktreePath,initialPrompt:F.visibleText,syntheticParts:[{text:F.instructionsText,synthetic:!0},{text:F.payloadText,synthetic:!0}]});return}if(!x){b.error(m("gitView.integrate.noActiveSession"),{description:m("gitView.integrate.noActiveSessionDescription")});return}$(F.visibleText,"replace"),_([{text:F.instructionsText,synthetic:!0},{text:F.payloadText,synthetic:!0}])},[x,U,D,$,_,m]),ee=be.useCallback(async()=>{if(S.kind==="ready"){if(S.plan.commits.length===0){b.message(m("gitView.integrate.noCommitsToMoveToast"));return}R({kind:"running",plan:S.plan});try{const u=await za(S.plan);if(u.kind==="success"){b.success(m("gitView.integrate.commitsMovedToast"),{description:u.moved===1?m("gitView.integrate.commitsMovedDescriptionSingle",{count:u.moved,branch:S.plan.targetBranch}):m("gitView.integrate.commitsMovedDescriptionPlural",{count:u.moved,branch:S.plan.targetBranch})});const d=await It(S.plan);R({kind:"ready",plan:d}),p?.();return}u.kind==="conflict"&&(b.error(m("gitView.integrate.cherryPickConflictToast"),{description:m("gitView.integrate.cherryPickConflictDescription")}),R({kind:"conflict",state:u.state,details:u.details}),E&&typeof window<"u"&&window.localStorage.setItem(E,JSON.stringify(u.state)))}catch(u){const d=u instanceof Error?u.message:String(u);b.error(m("gitView.integrate.failedToMoveToast"),{description:d});const F=await It({repoRoot:i,sourceBranch:e,targetBranch:j}).catch(()=>null);R(F?{kind:"ready",plan:F}:{kind:"idle"})}}},[S,p,i,e,j,E,m]),X=be.useCallback(async()=>{if(S.kind==="conflict")try{await Ga(S.state),b.message(m("gitView.integrate.cherryPickAbortedToast")),E&&typeof window<"u"&&window.localStorage.removeItem(E)}finally{const u=await It({repoRoot:i,sourceBranch:e,targetBranch:j}).catch(()=>null);R(u?{kind:"ready",plan:u}:{kind:"idle"})}},[S,i,e,j,E,m]),oe=be.useCallback(async()=>{if(S.kind==="conflict")try{const u=await _a(S.state);if(u.kind==="success"){b.success(m("gitView.integrate.cherryPickFinishedToast"));const d=await It({repoRoot:i,sourceBranch:e,targetBranch:j}).catch(()=>null);R(d?{kind:"ready",plan:d}:{kind:"idle"}),E&&typeof window<"u"&&window.localStorage.removeItem(E),p?.();return}u.kind==="conflict"&&(R({kind:"conflict",state:u.state,details:u.details}),E&&typeof window<"u"&&window.localStorage.setItem(E,JSON.stringify(u.state)))}catch(u){const d=u instanceof Error?u.message:String(u);b.error(m("gitView.integrate.cherryPickContinueFailedToast"),{description:d})}},[S,i,e,j,p,E,m]);return!i||!e?null:t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[f?t.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(T,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:m("gitView.integrate.title")}),S.kind==="ready"&&S.plan.commits.length>0?t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:m("gitView.integrate.toMoveCount",{count:S.plan.commits.length})}):null]}),t.jsx("div",{className:"flex items-center gap-2",children:S.kind==="loading"||S.kind==="running"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}):null,t.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"typography-ui-label text-foreground",children:m("gitView.integrate.moveCommits")}),t.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",j]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Ps,{open:M,onOpenChange:y,children:[t.jsx(Fs,{asChild:!0,children:t.jsxs("button",{type:"button",className:br({size:"default"}),children:[m("gitView.integrate.target"),t.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:j}),t.jsx(T,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),t.jsx(Rs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:t.jsxs(Bs,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Ds,{ref:N,placeholder:m("gitView.branch.searchPlaceholder"),value:k,onValueChange:L,onKeyDown:u=>u.stopPropagation()}),t.jsxs(Ms,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[t.jsx(Ts,{children:m("gitView.branch.empty")}),t.jsx(qt,{heading:m("gitView.branch.localBranches"),children:O.map(u=>t.jsx(Yt,{value:u,onSelect:()=>{w(u),V(u),y(!1),L("")},children:u},u))})]})]})})]}),S.kind==="ready"?t.jsx(W,{size:"sm",onClick:()=>{ee()},disabled:!B||S.plan.commits.length===0,children:m("gitView.integrate.move")}):S.kind==="loading"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:m("gitView.integrate.checking")}):S.kind==="running"?t.jsx(W,{size:"sm",variant:"outline",disabled:!0,children:m("gitView.integrate.moving")}):null]}),S.kind==="ready"&&S.plan.commits.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:m("gitView.integrate.noCommitsToMove")}),S.kind==="ready"&&S.plan.commits.length>0&&t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"typography-meta text-foreground",children:[m("gitView.integrate.commitsToMove"),t.jsxs("span",{className:"text-muted-foreground",children:[" (",S.plan.commits.length,")"]})]}),g.length>0&&S.plan.commits.length>5&&t.jsx("button",{type:"button",onClick:()=>P(u=>!u),className:"typography-micro text-muted-foreground hover:text-foreground",children:m(I?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(I?g:g.slice(0,5)).map(u=>t.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[t.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:u.short}),t.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:u.subject||u.sha})]},u.sha)),g.length===0&&t.jsx("div",{className:"typography-meta text-muted-foreground",children:m("gitView.integrate.previewUnavailable")}),S.plan.commits.length>g.length&&t.jsx("div",{className:"typography-micro text-muted-foreground/70",children:m("gitView.integrate.showingFirstCommits",{count:g.length})})]})]}),S.kind==="conflict"&&t.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[t.jsx("div",{className:"typography-meta text-foreground",children:m("gitView.integrate.conflictsInFiles",{count:S.details.unmergedFiles.length})}),t.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[m("gitView.integrate.currentCommit"),": ",t.jsx("span",{className:"font-mono",children:S.state.currentCommit.slice(0,7)})]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[S.details.unmergedFiles.slice(0,6).map(u=>t.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:u},u)),S.details.unmergedFiles.length>6&&t.jsx("span",{className:"text-xs text-muted-foreground",children:m("gitView.integrate.moreFiles",{count:S.details.unmergedFiles.length-6})})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{X()},children:m("gitView.operation.abort")}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!x,onClick:()=>{Y({state:S.state,details:S.details},!1)},children:[t.jsx(T,{name:"sparkling",className:"size-3.5"}),m("gitView.integrate.currentSession")]}),t.jsxs(W,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{Y({state:S.state,details:S.details},!0)},children:[t.jsx(T,{name:"sparkling",className:"size-3.5"}),m("gitView.integrate.newSession")]}),t.jsx(W,{size:"sm",className:"typography-meta",onClick:()=>{oe()},children:m("gitView.operation.continue")})]})]})]})]})},Ha=({open:i,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:v=!1,uncommittedFileCount:h,onChanged:p})=>{const{t:f}=et(),[m,x]=l.useState([]),[M,y]=l.useState(!1),[k,L]=l.useState(""),[N,O]=l.useState(""),[j,w]=l.useState(null),[B,S]=l.useState({}),R=l.useCallback(async()=>{if(n){y(!0);try{const V=await Fn(n);x(V.stashes),S({})}catch(V){b.error(V instanceof Error?V.message:f("gitView.stashes.toast.loadFailed"))}finally{y(!1)}}},[n,f]);l.useEffect(()=>{i&&R()},[R,i]),l.useEffect(()=>{if(!i||!n||m.length===0)return;let V=!1;const D=m.map(U=>U.ref);return Rn(n,D).then(U=>{V||S(U.counts)}).catch(()=>{}),()=>{V=!0}},[n,i,m]);const I=l.useMemo(()=>Rt(m,k,V=>[V.message,V.ref,V.relativeTime]),[k,m]),P=l.useCallback(async V=>{await R(),await p?.(V)},[R,p]),g=async()=>{if(!(!n||j)){w("create");try{const V=await Bn(n,{message:N.trim()||void 0});V.created?(b.success(f("gitView.stashes.toast.created")),O("")):b.info(f("gitView.stashes.toast.noChanges")),await P({affectsIndex:!!(V.created&&v)})}catch(V){b.error(V instanceof Error?V.message:f("gitView.stashes.toast.createFailed"))}finally{w(null)}}},H=async(V,D)=>{if(!(!n||j)&&!(D==="drop"&&!window.confirm(f("gitView.stashes.confirm.drop",{ref:V.ref})))){w(`${D}:${V.ref}`);try{D==="apply"&&await Dn(n,{ref:V.ref}),D==="pop"&&await Mn(n,{ref:V.ref}),D==="drop"&&await Tn(n,{ref:V.ref});const U=D==="apply"?"gitView.stashes.toast.applySuccess":D==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";b.success(f(U)),await P({affectsIndex:D!=="drop"})}catch(U){const $=D==="apply"?"gitView.stashes.toast.applyFailed":D==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";b.error(U instanceof Error?U.message:f($)),await P({affectsIndex:D!=="drop"})}finally{w(null)}}},E=j!==null;return t.jsx(ht,{open:i,onOpenChange:e,children:t.jsxs(gt,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[t.jsxs(ft,{children:[t.jsxs(pt,{className:"flex items-center gap-2",children:[t.jsx(T,{name:"archive-stack",className:"h-5 w-5"}),f("gitView.stashes.title")]}),t.jsx(yt,{children:f("gitView.stashes.description")})]}),t.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(ir,{value:N,onChange:V=>O(V.target.value),placeholder:f("gitView.stashes.messagePlaceholder"),disabled:E||!r,className:"flex-1"}),t.jsxs(W,{onClick:g,disabled:!r||E||!n,children:[j==="create"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"inbox-archive",className:"size-4"}),f("gitView.stashes.actions.stashCurrentWithCount",{count:h})]})]}),t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:f("gitView.stashes.includeUntrackedHint")})]}),t.jsxs("div",{className:"relative mt-2",children:[t.jsx(T,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ir,{value:k,onChange:V=>L(V.target.value),placeholder:f("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:M?t.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:t.jsx(T,{name:"loader-4",className:"size-5 animate-spin"})}):I.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:f(k?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):I.map((V,D)=>t.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[t.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[t.jsx("p",{className:"typography-small truncate text-foreground",children:V.message||f("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(Qt,{children:[t.jsx(Zt,{asChild:!0,children:t.jsx("span",{children:D===0&&!k.trim()?f("gitView.stashes.latestLabel"):f("gitView.stashes.itemNumber",{number:D+1})})}),t.jsx(Xt,{sideOffset:6,children:V.ref})]})," · ",V.relativeTime," · ",typeof B[V.ref]=="number"?f("gitView.stashes.fileCount",{count:B[V.ref]}):f("gitView.stashes.fileCountLoading")]})]}),t.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[t.jsx(Vs,{label:f("gitView.stashes.actions.apply"),loading:j===`apply:${V.ref}`,onClick:()=>H(V,"apply"),disabled:E,children:t.jsx(T,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(Vs,{label:f("gitView.stashes.actions.pop"),loading:j===`pop:${V.ref}`,onClick:()=>H(V,"pop"),disabled:E,children:t.jsx(T,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(Vs,{label:f("gitView.stashes.actions.drop"),loading:j===`drop:${V.ref}`,onClick:()=>H(V,"drop"),disabled:E,destructive:!0,children:t.jsx(T,{name:"delete-bin",className:"size-4"})})]})]},V.ref))})]})})},Vs=i=>{const e=Ct.c(17),{label:n,loading:r,disabled:v,destructive:h,onClick:p,children:f}=i,m=r||void 0,x=h?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let M;e[0]!==x?(M=Ve("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",x),e[0]=x,e[1]=M):M=e[1];let y;e[2]!==f||e[3]!==r?(y=r?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):f,e[2]=f,e[3]=r,e[4]=y):y=e[4];let k;e[5]!==v||e[6]!==n||e[7]!==p||e[8]!==m||e[9]!==M||e[10]!==y?(k=t.jsx(Zt,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":n,"aria-busy":m,className:M,onClick:p,disabled:v,children:y})}),e[5]=v,e[6]=n,e[7]=p,e[8]=m,e[9]=M,e[10]=y,e[11]=k):k=e[11];let L;e[12]!==n?(L=t.jsx(Xt,{sideOffset:6,children:n}),e[12]=n,e[13]=L):L=e[13];let N;return e[14]!==k||e[15]!==L?(N=t.jsxs(Qt,{children:[k,L]}),e[14]=k,e[15]=L,e[16]=N):N=e[16],N},Wa=i=>{const e=Ct.c(16),{onOpenStashes:n}=i,{t:r}=et();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(T,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=v):v=e[0];let h;e[1]!==r?(h=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=h):h=e[2];let p;e[3]!==h?(p=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:h}),e[3]=h,e[4]=p):p=e[4];let f;e[5]!==r?(f=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=f):f=e[6];let m;e[7]!==f?(m=t.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:f}),e[7]=f,e[8]=m):m=e[8];let x;e[9]!==n||e[10]!==r?(x=n?t.jsxs(W,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[t.jsx(T,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=x):x=e[11];let M;return e[12]!==p||e[13]!==m||e[14]!==x?(M=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[v,p,m,x]}),e[12]=p,e[13]=m,e[14]=x,e[15]=M):M=e[15],M},mt=8,Ua=i=>{const e=Ct.c(18),{laned:n,totalLanes:r,isExpanded:v}=i,{lane:h,color:p,connectors:f}=n,x=Math.max(r,h+1)*mt+mt/2,M=l.useRef(null),y=l.useRef(null);let k;e[0]!==p||e[1]!==f||e[2]!==h||e[3]!==x?(k=()=>{const w=M.current,B=y.current;if(!w||!B)return;const S=w.offsetHeight;if(S===0)return;const R=window.devicePixelRatio||1;B.width=x*R,B.height=S*R;const I=B.getContext("2d");if(!I)return;I.scale(R,R),I.clearRect(0,0,x,S);const P=S/2,g=h*mt+mt/2,H=getComputedStyle(B),E=H.getPropertyValue("--surface-muted-foreground").trim()||H.color,V=$=>{if(!$.startsWith("var("))return $;const _=$.slice(4,-1).trim();return H.getPropertyValue(_).trim()||E},D=[...f].sort(Ka);for(const $ of D){const _=$.fromLane*mt+mt/2,Y=$.toLane*mt+mt/2,ee=$.type==="passing"?.72:$.type==="branch-out"||$.type==="merge-in"?.95:1;I.beginPath(),I.strokeStyle=V($.color),I.globalAlpha=ee,I.lineWidth=1.25,I.lineCap="round";e:switch($.type){case"passing":case"commit-lane":{I.moveTo(_,0),I.lineTo(_,S);break e}case"top-stub":{I.moveTo(_,0),I.lineTo(_,P);break e}case"bottom-stub":{I.moveTo(_,P),I.lineTo(_,S);break e}case"branch-out":{const X=(P+S)/2;I.moveTo(g,P),I.bezierCurveTo(g,X,Y,X,Y,S);break e}case"merge-in":{const X=P/2;I.moveTo(_,0),I.bezierCurveTo(_,X,g,X,g,P);break e}default:continue}I.stroke(),I.globalAlpha=1}const U=H.getPropertyValue("--background").trim()||H.getPropertyValue("--surface-background").trim();I.beginPath(),I.arc(g,P,4,0,Math.PI*2),I.fillStyle=V(p),I.fill(),I.beginPath(),I.arc(g,P,5,0,Math.PI*2),I.strokeStyle=U||E,I.lineWidth=2,I.stroke()},e[0]=p,e[1]=f,e[2]=h,e[3]=x,e[4]=k):k=e[4];let L;e[5]!==p||e[6]!==f||e[7]!==v||e[8]!==h||e[9]!==n||e[10]!==r||e[11]!==x?(L=[n,h,p,f,r,v,x],e[5]=p,e[6]=f,e[7]=v,e[8]=h,e[9]=n,e[10]=r,e[11]=x,e[12]=L):L=e[12],l.useLayoutEffect(k,L);let N;e[13]!==x?(N={width:x,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=x,e[14]=N):N=e[14];let O;e[15]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx("canvas",{ref:y,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=O):O=e[15];let j;return e[16]!==N?(j=t.jsx("div",{ref:M,style:N,children:O}),e[16]=N,e[17]=j):j=e[17],j};function Ja(i){return i==="branch-out"||i==="merge-in"}function Ka(i,e){const n=Ja;return(n(i.type)?1:0)-(n(e.type)?1:0)}const dr=15e3,ur=500,mr=12,hr=8*1024*1024,gr=i=>typeof i=="string"?0:(i.original?.length??0)+(i.modified?.length??0),fr=i=>{if(i.size<=mr){let v=0;for(const h of i.values())v+=gr(h);if(v<=hr)return i}const e=Array.from(i.entries()).reverse(),n=new Map;let r=0;for(const[v,h]of e){if(n.size>=mr)continue;const p=gr(h);r+p>hr&&n.size>0||(n.set(v,h),r+=p)}return new Map(Array.from(n.entries()).reverse())};function pr(i,e){const n=new Date(i);return Number.isNaN(n.getTime())?i:On(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function qa(i){switch(i){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 Ya(i){return i?i.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const Qa=l.memo(({entry:i,mode:e="history",laned:n,totalLanes:r,isExpanded:v,onToggle:h,files:p,isLoadingFiles:f,onCopyHash:m,directory:x,onConflict:M,onActionSuccess:y})=>{const{t:k}=et(),L=Pt(d=>d.timeFormatPreference),N=e==="graph",[O,j]=l.useState(null),[w,B]=l.useState(!1),[S,R]=l.useState(""),[I,P]=l.useState(null),[g,H]=l.useState(new Set),[E,V]=l.useState(new Map),[D,U]=l.useState(new Set),$=async()=>{if(x){j("checkout");try{await Un(x,i.hash),b.success(k("gitView.history.actions.detachedHead")),y?.()}catch(d){b.error(String(d.message))}finally{j(null)}}},_=async()=>{if(!(!x||!S.trim())){j("createBranch");try{await zn(x,S.trim(),i.hash),B(!1),R(""),y?.()}catch(d){b.error(String(d.message))}finally{j(null)}}},Y=async()=>{if(x){j("cherryPick");try{const d=await Wn(x,i.hash);d.conflict?M?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"cherry-pick"}):y?.()}catch(d){b.error(String(d.message))}finally{j(null)}}},ee=async()=>{if(x){j("revert");try{const d=await Hn(x,i.hash);d.conflict?M?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"revert"}):y?.()}catch(d){b.error(String(d.message))}finally{j(null)}}},X=async(d,F=!1)=>{if(!(!x||O!==null)){j("reset");try{await Gn(x,i.hash,d,F),y?.()}catch(A){b.error(String(A.message))}finally{j(null)}}},oe=async()=>{if(!I)return;const d=I;switch(P(null),d){case"checkout":return $();case"cherryPick":return Y();case"revert":return ee();case"merge":return de();case"rebase":return Q();case"resetSoft":return X("soft");case"resetMixed":return X("mixed");case"resetHard":return X("hard",!0)}},de=async()=>{if(x){j("merge");try{const d=await $n(x,{branch:i.hash});d.conflict?M?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"merge"}):y?.()}catch(d){b.error(String(d.message))}finally{j(null)}}},Q=async()=>{if(x){j("rebase");try{const d=await _n(x,{onto:i.hash});d.conflict?M?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"rebase"}):y?.()}catch(d){b.error(String(d.message))}finally{j(null)}}},te=l.useCallback(async d=>{const F=d.path;if(!x){V(A=>new Map(A).set(F,"error"));return}V(A=>fr(new Map(A).set(F,"loading")));try{const A=En(x,i.hash,d.path,!1),q=new Promise((se,G)=>{setTimeout(()=>G(new Error(`Timed out after ${dr}ms`)),dr)}),ie=await Promise.race([A,q]);V(se=>fr(new Map(se).set(F,ie)))}catch{V(A=>new Map(A).set(F,"error"))}},[x,i.hash]),u=l.useCallback(async d=>{const F=d.path;if(d.changeType==="R"||d.isBinary){H(se=>{const G=new Set(se);return G.has(F)?G.delete(F):G.add(F),G});return}const A=E.get(F);if(g.has(F)&&A&&A!=="error"){H(se=>{const G=new Set(se);return G.delete(F),G});return}H(se=>{const G=new Set(se);return G.add(F),G}),!(A&&A!=="error"||d.insertions+d.deletions>ur&&!D.has(F))&&await te(d)},[E,D,te,g]);return t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:h,className:Ve("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",N?"hover:bg-[var(--interactive-hover)]/40":v?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[N&&n&&r!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(Ua,{laned:n,totalLanes:r,isExpanded:v})}):t.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 flex-1",children:[N?(()=>{const d=Ya(i.refs);return d.length>0?t.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:d.map(F=>t.jsx("span",{className:Ve("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",F.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":F.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:F.label},F.label))}):null})():null,t.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:i.message}),t.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[t.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[t.jsx("span",{className:"truncate min-w-[3ch]",title:i.author_name,children:i.author_name}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("span",{className:"truncate min-w-0",title:pr(i.date,L),children:pr(i.date,L)})]}),t.jsx("span",{className:"shrink-0",children:"·"}),t.jsx("code",{className:"shrink-0 font-mono",children:i.hash.slice(0,8)}),t.jsxs(Qt,{children:[t.jsx(Zt,{asChild:!0,children:t.jsx(W,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:d=>{d.stopPropagation(),m(i.hash)},children:t.jsx(T,{name:"file-copy",className:"size-3"})})}),t.jsx(Xt,{sideOffset:8,children:k("gitView.history.copySha")})]})]})]})]}),v&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[N&&I?t.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:k(`gitView.history.actions.${I}Confirm`)}),t.jsxs(W,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:O!==null,onClick:d=>{d.stopPropagation(),oe()},children:[O!==null?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.confirmButton")]}),t.jsx(W,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:O!==null,onClick:d=>{d.stopPropagation(),P(null)},children:k("gitView.history.actions.cancelButton")})]}):N?t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("checkout")},children:k("gitView.history.actions.checkout")}),w?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{autoFocus:!0,value:S,onChange:d=>R(d.target.value),onKeyDown:d=>{d.key==="Enter"&&_(),d.key==="Escape"&&(B(!1),R(""))},placeholder:k("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:!S.trim()||O!==null,onClick:d=>{d.stopPropagation(),_()},children:[O==="createBranch"?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(W,{variant:"outline",size:"xs",className:"h-6",onClick:d=>{d.stopPropagation(),B(!0)},children:k("gitView.history.actions.createBranch")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("cherryPick")},children:k("gitView.history.actions.cherryPick")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("revert")},children:k("gitView.history.actions.revert")}),t.jsxs(Ps,{children:[t.jsx(Fs,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>d.stopPropagation(),children:[O==="reset"?t.jsx(T,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,k("gitView.history.actions.reset")]})}),t.jsx(Rs,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(d=>t.jsx(Ln,{disabled:O!==null,onSelect:F=>{F.stopPropagation(),P(`reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},children:k(`gitView.history.actions.reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},d))})]}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("merge")},children:k("gitView.history.actions.merge")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("rebase")},children:k("gitView.history.actions.rebase")})]}):null,f?t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"typography-micro text-muted-foreground",children:k("gitView.history.loadingFiles")})]}):p.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:k("gitView.history.noFiles")}):t.jsx("ul",{className:"space-y-0.5 py-2",children:p.map(d=>t.jsxs("li",{children:[t.jsxs("button",{type:"button",onClick:()=>u(d),className:Ve("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",g.has(d.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[t.jsx("span",{className:Ve("font-semibold w-3 text-center shrink-0",qa(d.changeType)),children:d.changeType}),t.jsx("span",{className:"truncate text-foreground min-w-0",title:d.path,children:d.path}),!d.isBinary&&t.jsxs("span",{className:"shrink-0",children:[t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",d.insertions]}),t.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",d.deletions]})]}),d.isBinary&&t.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:k("gitView.history.binary")}),t.jsx(T,{name:g.has(d.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),g.has(d.path)&&t.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:d.changeType==="R"?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.renamedNoDiff")}):d.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.binaryNoDiff")}):(()=>{const F=d.insertions+d.deletions;if(!D.has(d.path)&&F>ur)return t.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:k("gitView.history.largeDiffTitle",{count:F})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:k("gitView.history.largeDiffDescription")}),t.jsx(W,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{U(q=>new Set(q).add(d.path)),te(d)},children:k("gitView.history.renderDiffAnyway")})]});const A=E.get(d.path);return A==="loading"||A===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:k("gitView.history.loadingDiff")}):A==="error"?t.jsx("button",{type:"button",onClick:()=>u(d),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:k("gitView.history.diffError")}):t.jsx(Da,{original:A.original,modified:A.modified,language:An(d.path)||"",fileName:d.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},d.path))})]})]})}),xr=["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 Ut(i){return xr[i%xr.length]}function Za(i){if(i.length===0)return[];const e=[],n=[];for(let r=0;r<i.length;r++){const v=i[r],h=[];for(let N=0;N<e.length;N++)e[N]===v.hash&&h.push(N);let p=h.length>0?h[0]:-1;if(p===-1){const N=e.indexOf(null);N!==-1?p=N:(p=e.length,e.push(null))}const f=h.slice(1),m=Ut(p),x=e[p]===v.hash,M=v.parents.length>0;M?e[p]=v.parents[0]:e[p]=null;const y=[],k=new Set;for(let N=1;N<v.parents.length;N++){const O=v.parents[N],j=e.indexOf(O);if(j!==-1)y.push(j);else{const w=e.indexOf(null);if(w!==-1)e[w]=O,y.push(w),k.add(w);else{const B=e.length;e.push(O),y.push(B),k.add(B)}}}const L=[];x&&M?L.push({fromLane:p,toLane:p,color:m,type:"commit-lane"}):x&&!M?L.push({fromLane:p,toLane:p,color:m,type:"top-stub"}):!x&&M&&L.push({fromLane:p,toLane:p,color:m,type:"bottom-stub"});for(const N of f)L.push({fromLane:N,toLane:p,color:Ut(N),type:"merge-in"}),e[N]=null;for(const N of y)L.push({fromLane:p,toLane:N,color:Ut(N),type:"branch-out"});for(let N=0;N<e.length;N++)e[N]!==null&&N!==p&&(k.has(N)||L.push({fromLane:N,toLane:N,color:Ut(N),type:"passing"}));n.push({commit:v,lane:p,color:m,connectors:L})}return n}const Xa=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],ei=i=>{const e=Ct.c(84),{mode:n,log:r,isLogLoading:v,logMaxCount:h,onLogMaxCountChange:p,expandedCommitHashes:f,onToggleCommit:m,commitFilesMap:x,loadingCommitHashes:M,onCopyHash:y,directory:k,showHeader:L,contentMaxHeightClassName:N,branchDivider:O,onConflict:j,onActionSuccess:w}=i,B=n===void 0?"history":n,S=L===void 0?!0:L,R=N===void 0?"max-h-[50vh]":N,I=O===void 0?null:O,{t:P}=et(),[g,H]=l.useState(!0),E=B==="graph";let V;e[0]!==E||e[1]!==r?(V=E&&r?Za(r.all):[],e[0]=E,e[1]=r,e[2]=V):V=e[2];const D=V;let U;e[3]!==D?(U=Math.max(1,...D.map(ti)),e[3]=D,e[4]=U):U=e[4];const $=U;let _;e[5]!==D?(_=new Map(D.map(si)),e[5]=D,e[6]=_):_=e[6];const Y=_;if(!r)return null;const ee=I!==null&&I.insertBeforeIndex>0&&I.insertBeforeIndex<r.all.length,X=I!==null&&I.insertBeforeIndex===r.all.length,oe=ee||X;let de;e[7]!==I||e[8]!==ee||e[9]!==X||e[10]!==r.all?(de=ee?r.all.slice(0,I.insertBeforeIndex):X?r.all:[],e[7]=I,e[8]=ee,e[9]=X,e[10]=r.all,e[11]=de):de=e[11];const Q=de;let te;if(e[12]!==I||e[13]!==x||e[14]!==R||e[15]!==k||e[16]!==f||e[17]!==ee||e[18]!==oe||e[19]!==E||e[20]!==v||e[21]!==Y||e[22]!==M||e[23]!==r.all||e[24]!==h||e[25]!==$||e[26]!==B||e[27]!==w||e[28]!==j||e[29]!==y||e[30]!==p||e[31]!==m||e[32]!==P||e[33]!==Q){const re=ee?r.all.slice(I.insertBeforeIndex):[];let le;e[35]!==I?.direction?(le=I?.direction==="down"?t.jsx(T,{name:"arrow-down-s",className:"size-3.5"}):t.jsx(T,{name:"arrow-up",className:"size-3.5"}),e[35]=I?.direction,e[36]=le):le=e[36];const ve=le;let pe;e[37]!==x||e[38]!==k||e[39]!==f||e[40]!==E||e[41]!==Y||e[42]!==M||e[43]!==$||e[44]!==B||e[45]!==w||e[46]!==j||e[47]!==y||e[48]!==m?(pe=ge=>t.jsx("ul",{className:"divide-y divide-border/60",children:ge.map(ce=>t.jsx(Qa,{entry:ce,mode:B,laned:E?Y.get(ce.hash):void 0,totalLanes:E?$:void 0,isExpanded:f.has(ce.hash),onToggle:()=>m(ce.hash),files:x.get(ce.hash)??[],isLoadingFiles:M.has(ce.hash),onCopyHash:y,directory:k,onConflict:j,onActionSuccess:w},ce.hash))}),e[37]=x,e[38]=k,e[39]=f,e[40]=E,e[41]=Y,e[42]=M,e[43]=$,e[44]=B,e[45]=w,e[46]=j,e[47]=y,e[48]=m,e[49]=pe):pe=e[49];const ue=pe;let me;e[50]!==v||e[51]!==r.all.length||e[52]!==h||e[53]!==p||e[54]!==P?(me=r.all.length>=h?t.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:t.jsx(W,{type:"button",variant:"ghost",size:"xs",onClick:()=>p(h+25),disabled:v,className:"px-3 text-muted-foreground hover:text-foreground",children:v?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx(T,{name:"loader-4",className:"size-3 animate-spin"}),P("gitView.history.loadingMore")]}):P("gitView.history.loadMore")})}):null,e[50]=v,e[51]=r.all.length,e[52]=h,e[53]=p,e[54]=P,e[55]=me):me=e[55];const he=me;te=t.jsx(vr,{outerClassName:`min-h-0 ${R}`,className:"h-full w-full",children:r.all.length===0?t.jsx("div",{className:"flex h-full items-center justify-center p-4",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:P("gitView.history.noCommits")})}):oe&&I?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-col gap-0",children:[Q.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ue(Q)}):null,t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[t.jsx("span",{className:"h-px flex-1 bg-border/60"}),t.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[t.jsx("span",{className:"truncate",title:I.branchName,children:I.branchName}),ve]}),t.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),re.length>0?t.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ue(re)}):null]}),he]}):t.jsxs(t.Fragment,{children:[ue(r.all),he]})}),e[12]=I,e[13]=x,e[14]=R,e[15]=k,e[16]=f,e[17]=ee,e[18]=oe,e[19]=E,e[20]=v,e[21]=Y,e[22]=M,e[23]=r.all,e[24]=h,e[25]=$,e[26]=B,e[27]=w,e[28]=j,e[29]=y,e[30]=p,e[31]=m,e[32]=P,e[33]=Q,e[34]=te}else te=e[34];const u=te;if(!S){if(oe){let le;return e[56]!==u?(le=t.jsx("section",{className:"h-full min-h-0",children:u}),e[56]=u,e[57]=le):le=e[57],le}let re;return e[58]!==u?(re=t.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:u}),e[58]=u,e[59]=re):re=e[59],re}let d;e[60]!==P?(d=P("gitView.history.title"),e[60]=P,e[61]=d):d=e[61];let F;e[62]!==d?(F=t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:d}),e[62]=d,e[63]=F):F=e[63];let A;e[64]!==v||e[65]!==g||e[66]!==h||e[67]!==p||e[68]!==P?(A=g&&t.jsx("div",{onClick:ri,onPointerDown:ni,children:t.jsxs(Jn,{value:String(h),onValueChange:re=>p(Number(re)),disabled:v,children:[t.jsx(Kn,{size:"sm",className:"w-auto",disabled:v,children:t.jsx(qn,{placeholder:P("gitView.history.commitsPlaceholder")})}),t.jsx(Yn,{children:Xa.map(re=>t.jsx(Qn,{value:String(re.value),children:P(re.labelKey)},re.value))})]})}),e[64]=v,e[65]=g,e[66]=h,e[67]=p,e[68]=P,e[69]=A):A=e[69];let q;e[70]!==g?(q=g?t.jsx(T,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):t.jsx(T,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=g,e[71]=q):q=e[71];let ie;e[72]!==A||e[73]!==q?(ie=t.jsxs("div",{className:"flex items-center gap-2",children:[A,q]}),e[72]=A,e[73]=q,e[74]=ie):ie=e[74];let se;e[75]!==F||e[76]!==ie?(se=t.jsxs(Sa,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[F,ie]}),e[75]=F,e[76]=ie,e[77]=se):se=e[77];let G;e[78]!==u?(G=t.jsx(ka,{children:u}),e[78]=u,e[79]=G):G=e[79];let fe;return e[80]!==g||e[81]!==se||e[82]!==G?(fe=t.jsxs(Va,{open:g,onOpenChange:H,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[se,G]}),e[80]=g,e[81]=se,e[82]=G,e[83]=fe):fe=e[83],fe};function ti(i){return i.lane+1}function si(i){return[i.commit.hash,i]}function ri(i){return i.stopPropagation()}function ni(i){return i.stopPropagation()}const ai=i=>{const e=Ct.c(148),{open:n,onOpenChange:r,conflictFiles:v,directory:h,operation:p,onAbort:f,onClearState:m}=i;let x;e[0]!==v?(x=v===void 0?[]:v,e[0]=v,e[1]=x):x=e[1];const M=x,{t:y}=et(),k=Xe(ii),L=Xe(oi),N=Kt(li),O=Kt(ci),[j,w]=l.useState(!1),[B,S]=l.useState(null),[R,I]=l.useState(null);let P,g;e[2]!==h||e[3]!==n||e[4]!==y?(P=()=>{!n||!h||(w(!0),I(null),S(null),Zn(h).then(K=>{S(K)}).catch(K=>{const xe=K instanceof Error?K.message:y("gitView.conflict.loadFailed");I(xe)}).finally(()=>{w(!1)}))},g=[n,h,y],e[2]=h,e[3]=n,e[4]=y,e[5]=P,e[6]=g):(P=e[5],g=e[6]),l.useEffect(P,g);let H;e[7]!==B||e[8]!==h||e[9]!==p?(H=async()=>{if(!B)return null;const K=p==="merge"?"merge":"rebase",xe=B.headInfo||(p==="merge"?"MERGE_HEAD":"REBASE_HEAD"),Te=p==="merge"?"git commit --no-edit":"git rebase --continue",Ge=await Jt("git.conflict.resolve.visible",{operation_label:K,head_ref:xe}),Ie=await Jt("git.conflict.resolve.instructions",{operation_label:K,directory:h,operation:p,head_info:B.headInfo||"N/A",continue_cmd:Te}),Ne=`${K} conflict context (JSON)
|
|
3
|
-
${JSON.stringify({directory:h,operation:B.operation,headInfo:B.headInfo,statusPorcelain:B.statusPorcelain,unmergedFiles:B.unmergedFiles,diff:B.diff},null,2)}`;return{visibleText:Ge,instructionsText:Ie,payloadText:Ne}},e[7]=B,e[8]=h,e[9]=p,e[10]=H):H=e[10];const E=H;let V;e[11]!==f||e[12]!==r?(V=()=>{f(),r(!1)},e[11]=f,e[12]=r,e[13]=V):V=e[13];const D=V;let U;e[14]!==m||e[15]!==r?(U=()=>{m?.(),r(!1)},e[14]=m,e[15]=r,e[16]=U):U=e[16];const $=U;let _;e[17]!==E||e[18]!==L||e[19]!==m||e[20]!==r||e[21]!==N||e[22]!==O||e[23]!==y?(_=async()=>{const K=await E();if(!K){b.error(y("gitView.conflict.noDetailsAvailable"));return}if(!L){b.error(y("gitView.conflict.noActiveSession"),{description:y("gitView.conflict.noActiveSessionDescription")});return}N(K.visibleText,"replace"),O([{text:K.instructionsText,synthetic:!0},{text:K.payloadText,synthetic:!0}]),m?.(),r(!1)},e[17]=E,e[18]=L,e[19]=m,e[20]=r,e[21]=N,e[22]=O,e[23]=y,e[24]=_):_=e[24];const Y=_;let ee;e[25]!==E||e[26]!==h||e[27]!==m||e[28]!==r||e[29]!==k||e[30]!==y?(ee=async()=>{const K=await E();if(!K){b.error(y("gitView.conflict.noDetailsAvailable"));return}k({directoryOverride:h,initialPrompt:K.visibleText,syntheticParts:[{text:K.instructionsText,synthetic:!0},{text:K.payloadText,synthetic:!0}]}),m?.(),r(!1)},e[25]=E,e[26]=h,e[27]=m,e[28]=r,e[29]=k,e[30]=y,e[31]=ee):ee=e[31];const X=ee;let oe,de,Q,te,u,d,F,A,q,ie,se,G,fe,re,le,ve,pe,ue,me,he,ge,ce;if(e[32]!==B||e[33]!==M||e[34]!==L||e[35]!==D||e[36]!==$||e[37]!==Y||e[38]!==X||e[39]!==j||e[40]!==R||e[41]!==r||e[42]!==n||e[43]!==p||e[44]!==y){const K=y(p==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),xe=B?.unmergedFiles||M;Q=ht,ge=n,ce=r,de=gt,he="max-w-md w-[calc(100vw-2rem)]",re="flex flex-col gap-4 overflow-hidden";let Te;e[67]===Symbol.for("react.memo_cache_sentinel")?(Te=t.jsx(T,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[67]=Te):Te=e[67];const Ge=t.jsxs("div",{className:"flex items-center gap-2",children:[Te,t.jsx(pt,{children:y("gitView.conflict.detectedTitle",{operation:K})})]});let Ie;e[68]!==p||e[69]!==y?(Ie=y("gitView.conflict.detectedDescription",{operation:p}),e[68]=p,e[69]=y,e[70]=Ie):Ie=e[70];let Ne;e[71]!==Ie?(Ne=t.jsx(yt,{children:Ie}),e[71]=Ie,e[72]=Ne):Ne=e[72],e[73]!==Ge||e[74]!==Ne?(le=t.jsxs(ft,{children:[Ge,Ne]}),e[73]=Ge,e[74]=Ne,e[75]=le):le=e[75],e[76]!==j||e[77]!==y?(ve=j&&t.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:y("gitView.conflict.loading")})]}),e[76]=j,e[77]=y,e[78]=ve):ve=e[78],e[79]!==R||e[80]!==y?(pe=R&&t.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:y("gitView.conflict.errorLoadingDetails",{message:R})}),e[79]=R,e[80]=y,e[81]=pe):pe=e[81],e[82]!==xe||e[83]!==y?(ue=xe.length>0&&t.jsxs("div",{className:"space-y-2 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:y("gitView.conflict.conflictedFiles")}),t.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:xe.length})]}),t.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:t.jsx("ul",{className:"space-y-1",children:xe.map(di)})})]}),e[82]=xe,e[83]=y,e[84]=ue):ue=e[84],e[85]!==B||e[86]!==y?(me=B?.headInfo&&t.jsxs("div",{className:"space-y-1 overflow-hidden",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:y("gitView.conflict.headInfo")}),t.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:B.headInfo})]}),e[85]=B,e[86]=y,e[87]=me):me=e[87],se="flex flex-col gap-2 pt-2";let Se;e[88]!==X?(Se=()=>{X()},e[88]=X,e[89]=Se):Se=e[89];const Be=j||!B;let Pe;e[90]!==j?(Pe=j?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"add",className:"size-4"}),e[90]=j,e[91]=Pe):Pe=e[91];let ke;e[92]!==y?(ke=y("gitView.conflict.resolveNewSession"),e[92]=y,e[93]=ke):ke=e[93],e[94]!==Se||e[95]!==Be||e[96]!==Pe||e[97]!==ke?(G=t.jsxs(W,{variant:"default",onClick:Se,disabled:Be,className:"w-full gap-2",children:[Pe,ke]}),e[94]=Se,e[95]=Be,e[96]=Pe,e[97]=ke,e[98]=G):G=e[98];let we;e[99]!==Y?(we=()=>{Y()},e[99]=Y,e[100]=we):we=e[100];const De=j||!B||!L;let Le;e[101]!==j?(Le=j?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"chat-1",className:"size-4"}),e[101]=j,e[102]=Le):Le=e[102];let Z;e[103]!==y?(Z=y("gitView.conflict.resolveCurrentSession"),e[103]=y,e[104]=Z):Z=e[104],e[105]!==we||e[106]!==De||e[107]!==Le||e[108]!==Z?(fe=t.jsxs(W,{variant:"outline",onClick:we,disabled:De,className:"w-full gap-2",children:[Le,Z]}),e[105]=we,e[106]=De,e[107]=Le,e[108]=Z,e[109]=fe):fe=e[109],q="flex gap-2 pt-1";let Fe;e[110]!==y?(Fe=y("gitView.conflict.continueLater"),e[110]=y,e[111]=Fe):Fe=e[111],e[112]!==$||e[113]!==Fe?(ie=t.jsx(W,{variant:"ghost",size:"sm",onClick:$,className:"flex-1",children:Fe}),e[112]=$,e[113]=Fe,e[114]=ie):ie=e[114],oe=W,te="destructive",u="sm",d=D,F="flex-1",A=y("gitView.conflict.abortOperation",{operation:K}),e[32]=B,e[33]=M,e[34]=L,e[35]=D,e[36]=$,e[37]=Y,e[38]=X,e[39]=j,e[40]=R,e[41]=r,e[42]=n,e[43]=p,e[44]=y,e[45]=oe,e[46]=de,e[47]=Q,e[48]=te,e[49]=u,e[50]=d,e[51]=F,e[52]=A,e[53]=q,e[54]=ie,e[55]=se,e[56]=G,e[57]=fe,e[58]=re,e[59]=le,e[60]=ve,e[61]=pe,e[62]=ue,e[63]=me,e[64]=he,e[65]=ge,e[66]=ce}else oe=e[45],de=e[46],Q=e[47],te=e[48],u=e[49],d=e[50],F=e[51],A=e[52],q=e[53],ie=e[54],se=e[55],G=e[56],fe=e[57],re=e[58],le=e[59],ve=e[60],pe=e[61],ue=e[62],me=e[63],he=e[64],ge=e[65],ce=e[66];let ze;e[115]!==oe||e[116]!==te||e[117]!==u||e[118]!==d||e[119]!==F||e[120]!==A?(ze=t.jsx(oe,{variant:te,size:u,onClick:d,className:F,children:A}),e[115]=oe,e[116]=te,e[117]=u,e[118]=d,e[119]=F,e[120]=A,e[121]=ze):ze=e[121];let $e;e[122]!==q||e[123]!==ie||e[124]!==ze?($e=t.jsxs("div",{className:q,children:[ie,ze]}),e[122]=q,e[123]=ie,e[124]=ze,e[125]=$e):$e=e[125];let je;e[126]!==se||e[127]!==G||e[128]!==fe||e[129]!==$e?(je=t.jsxs("div",{className:se,children:[G,fe,$e]}),e[126]=se,e[127]=G,e[128]=fe,e[129]=$e,e[130]=je):je=e[130];let Re;e[131]!==re||e[132]!==le||e[133]!==ve||e[134]!==pe||e[135]!==ue||e[136]!==me||e[137]!==je?(Re=t.jsxs("div",{className:re,children:[le,ve,pe,ue,me,je]}),e[131]=re,e[132]=le,e[133]=ve,e[134]=pe,e[135]=ue,e[136]=me,e[137]=je,e[138]=Re):Re=e[138];let Ce;e[139]!==de||e[140]!==he||e[141]!==Re?(Ce=t.jsx(de,{className:he,children:Re}),e[139]=de,e[140]=he,e[141]=Re,e[142]=Ce):Ce=e[142];let Ee;return e[143]!==Q||e[144]!==ge||e[145]!==ce||e[146]!==Ce?(Ee=t.jsx(Q,{open:ge,onOpenChange:ce,children:Ce}),e[143]=Q,e[144]=ge,e[145]=ce,e[146]=Ce,e[147]=Ee):Ee=e[147],Ee};function ii(i){return i.openNewSessionDraft}function oi(i){return i.currentSessionId}function li(i){return i.setPendingInputText}function ci(i){return i.setPendingSyntheticParts}function di(i){return t.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:i,children:i},i)}const ui=({open:i,onOpenChange:e,operation:n,targetBranch:r,onConfirm:v})=>{const{t:h}=et(),[p,f]=l.useState(!0),[m,x]=l.useState(!1),M=h(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),y=async()=>{x(!0);try{await v(p),e(!1)}catch(L){const N=L instanceof Error?L.message:`Failed to ${n}`;b.error(N)}finally{x(!1)}},k=()=>{m||e(!1)};return t.jsx(ht,{open:i,onOpenChange:m?void 0:e,children:t.jsxs(gt,{className:"max-w-md",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),t.jsx(pt,{children:h("gitView.stash.title")})]}),t.jsx(yt,{children:h("gitView.stash.description",{operation:n})})]}),t.jsxs("div",{className:"py-2",children:[t.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:h("gitView.stash.thisWill")}),t.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[t.jsx("li",{children:h("gitView.stash.stepStash")}),t.jsxs("li",{children:[h(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",h(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",t.jsx("span",{className:"font-mono text-primary",children:r})]}),p&&t.jsx("li",{children:h("gitView.stash.stepRestore")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 py-2",children:[t.jsx(Xn,{checked:p,onChange:f,disabled:m,ariaLabel:h("gitView.stash.restoreAria")}),t.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!m&&f(!p),children:h("gitView.stash.restoreAfterOperation",{operation:n})})]}),t.jsxs(Is,{className:"gap-2",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:k,disabled:m,children:h("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:y,disabled:m,className:"gap-1.5",children:m?t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),h("gitView.common.processing")]}):h("gitView.stash.confirmButton",{operation:M})})]})]})})},mi=({mergeInProgress:i,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:v,conflictCount:h=0,isLoading:p=!1})=>{const{t:f}=et(),[m,x]=l.useState(null),M=i&&i.head,y=e&&(e.headName||e.onto),k=M?"merge":y?"rebase":null;if(!k)return null;const L=async()=>{x("continue");try{await n()}finally{x(null)}},N=async()=>{x("abort");try{await r()}finally{x(null)}},O=m!==null,j=h>0,w=f(k==="merge"?"gitView.operation.merge":"gitView.operation.rebase");let B="";i?B=i.message?f("gitView.operation.mergingMessage",{message:i.message}):f("gitView.operation.mergeInProgressWithHead",{head:i.head}):e&&(B=e.headName?f("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):f("gitView.operation.rebaseInProgress"));const S=j?h===1?f("gitView.operation.inProgressTitleOneConflict",{operation:w,count:h}):f("gitView.operation.inProgressTitleManyConflicts",{operation:w,count:h}):f("gitView.operation.inProgressTitle",{operation:w}),R=f(j?"gitView.operation.resolveConflictsHint":"gitView.operation.readyToContinueHint");return t.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:t.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:S}),B&&t.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:B})]}),t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:R}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[t.jsxs(W,{variant:"ghost",size:"sm",onClick:N,disabled:O||p,className:"gap-1.5",children:[m==="abort"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"close",className:"size-4"}),f("gitView.operation.abort")]}),j?v&&t.jsx(W,{variant:"default",size:"sm",onClick:v,disabled:O||p,children:f("gitView.operation.resolveWithAi")}):t.jsxs(W,{variant:"default",size:"sm",onClick:L,disabled:O||p,className:"gap-1.5",children:[m==="continue"?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"check",className:"size-4"}),f("gitView.operation.continue")]})]})]})]})})},hi=i=>{const e=Ct.c(104),{currentBranch:n,localBranches:r,remoteBranches:v,onMerge:h,onRebase:p,disabled:f,isOperating:m,operationLogs:x,onOperationComplete:M,mode:y,defaultTargetBranch:k}=i,L=f===void 0?!1:f,N=m===void 0?!1:m,O=x===void 0?[]:x,j=y===void 0?"dialog":y,{t:w}=et(),[B,S]=l.useState(!1),[R,I]=l.useState("merge"),[P,g]=l.useState(null),[H,E]=l.useState(!1),[V,D]=l.useState(""),U=l.useRef(null),$=l.useRef(null),_=L||N,Y=n||w("gitView.branch.currentBranchFallback"),ee=O.length>0&&O.every(gi),X=O.some(fi);let oe;e[0]===Symbol.for("react.memo_cache_sentinel")?(oe=()=>{$.current&&($.current.scrollTop=$.current.scrollHeight)},e[0]=oe):oe=e[0],l.useEffect(oe,[O]);let de;e[1]!==v?(de=new Set(v.map(pi).filter(Boolean)),e[1]=v,e[2]=de):de=e[2];const Q=de;let te;if(e[3]!==V||e[4]!==n||e[5]!==r||e[6]!==Q){let Z;e[8]!==n||e[9]!==Q?(Z=_e=>_e!==n&&!Q.has(_e),e[8]=n,e[9]=Q,e[10]=Z):Z=e[10];const Fe=r.filter(Z);te=Rt(Fe,V,xi),e[3]=V,e[4]=n,e[5]=r,e[6]=Q,e[7]=te}else te=e[7];const u=te;let d;e[11]!==V||e[12]!==v?(d=Rt(v,V,wi),e[11]=V,e[12]=v,e[13]=d):d=e[13];const F=d;let A;e[14]!==k||e[15]!==r||e[16]!==v?(A=()=>k&&(v.includes(k)||r.includes(k))?k:null,e[14]=k,e[15]=r,e[16]=v,e[17]=A):A=e[17];const q=A;let ie;e[18]!==q||e[19]!==S?(ie=()=>{S(!0),g(q()),I("merge"),D("")},e[18]=q,e[19]=S,e[20]=ie):ie=e[20];const se=ie;let G;e[21]===Symbol.for("react.memo_cache_sentinel")?(G=Z=>{g(Z),E(!1),D("")},e[21]=G):G=e[21];const fe=G;let re;e[22]!==h||e[23]!==p||e[24]!==R||e[25]!==P?(re=()=>{P&&(R==="merge"?h(P):p(P))},e[22]=h,e[23]=p,e[24]=R,e[25]=P,e[26]=re):re=e[26];const le=re;let ve;e[27]!==N||e[28]!==S?(ve=()=>{N||(g(null),I("merge"),D(""),S(!1))},e[27]=N,e[28]=S,e[29]=ve):ve=e[29];const pe=ve,ue=()=>{N&&!ee||(ee&&M?.(),g(null),I("merge"),D(""),S(!1))};let me,he;e[30]!==H?(me=()=>{H||D("")},he=[H],e[30]=H,e[31]=me,e[32]=he):(me=e[31],he=e[32]),l.useEffect(me,he);let ge,ce;e[33]!==j||e[34]!==q||e[35]!==P?(ge=()=>{j==="dialog"||P||g(q())},ce=[j,q,P],e[33]=j,e[34]=q,e[35]=P,e[36]=ge,e[37]=ce):(ge=e[36],ce=e[37]),l.useEffect(ge,ce);const je=N?t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{ref:$,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:t.jsx("div",{className:"space-y-2",children:O.map(yi)})}),ee?j==="dialog"?t.jsx(Is,{children:t.jsx(W,{variant:"default",size:"sm",onClick:ue,children:w(X?"gitView.common.close":"gitView.common.done")})}):t.jsx("div",{className:"flex justify-end",children:t.jsx(W,{variant:"default",size:"sm",onClick:ue,children:w(X?"gitView.common.close":"gitView.common.done")})}):null]}):t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:w("gitView.branch.operation")}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("button",{type:"button",onClick:()=>I("merge"),className:Ve("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",R==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"git-merge",className:Ve("size-4",R==="merge"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Ve("typography-ui-label",R==="merge"?"text-foreground":"text-muted-foreground"),children:w("gitView.operation.merge")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:w("gitView.branch.mergeDescription")})]}),t.jsxs("button",{type:"button",onClick:()=>I("rebase"),className:Ve("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",R==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"git-branch",className:Ve("size-4",R==="rebase"?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:Ve("typography-ui-label",R==="rebase"?"text-foreground":"text-muted-foreground"),children:w("gitView.operation.rebase")})]}),t.jsx("p",{className:"typography-micro text-muted-foreground",children:w("gitView.branch.rebaseDescription")})]})]})]}),t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:R==="merge"?w("gitView.branch.branchToMergeInto",{branch:Y}):w("gitView.branch.branchToRebaseOnto")}),t.jsxs(Ps,{open:H,onOpenChange:E,modal:!1,children:[t.jsx(Fs,{asChild:!0,children:t.jsxs("button",{type:"button",className:Ve(br({size:"default"}),"w-full"),children:[t.jsx("span",{className:Ve("truncate",!P&&"text-muted-foreground"),children:P||w("gitView.branch.selectBranch")}),t.jsx(T,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),t.jsx(Rs,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:t.jsxs(Bs,{className:"h-full min-h-0",shouldFilter:!1,children:[t.jsx(Ds,{ref:U,placeholder:w("gitView.branch.searchPlaceholder"),value:V,onValueChange:D,onKeyDown:bi}),t.jsxs(Ms,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(Ts,{children:w("gitView.branch.empty")}),u.length>0&&t.jsx(qt,{heading:w("gitView.branch.localBranches"),children:u.map(Z=>t.jsx(Yt,{onSelect:()=>fe(Z),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Z})},`local-${Z}`))}),u.length>0&&F.length>0?t.jsx(ea,{}):null,F.length>0&&t.jsx(qt,{heading:w("gitView.branch.remoteBranches"),children:F.map(Z=>t.jsx(Yt,{onSelect:()=>fe(Z),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Z})},`remote-${Z}`))})]})]})})]})]}),P?t.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:t.jsx("p",{className:"typography-meta text-muted-foreground",children:R==="merge"?t.jsxs(t.Fragment,{children:[w("gitView.branch.summaryMergePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P})," ",w("gitView.branch.summaryMergeInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Y})]}):t.jsxs(t.Fragment,{children:[w("gitView.branch.summaryRebasePrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Y})," ",w("gitView.branch.summaryRebaseInfix")," ",t.jsx("span",{className:"font-mono text-foreground",children:P})]})})}):null,j==="dialog"?t.jsxs(Is,{className:"gap-2 pt-1",children:[t.jsx(W,{variant:"ghost",size:"sm",onClick:pe,children:w("gitView.common.cancel")}),t.jsx(W,{variant:"default",size:"sm",onClick:le,disabled:!P,className:"gap-1.5",children:R==="merge"?t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"git-merge",className:"size-4"}),w("gitView.operation.merge")]}):t.jsxs(t.Fragment,{children:[t.jsx(T,{name:"git-branch",className:"size-4"}),w("gitView.operation.rebase")]})})]}):t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx(W,{variant:"destructive",size:"sm",onClick:pe,disabled:_,children:w("gitView.common.reset")}),t.jsx("div",{className:"flex-1"}),t.jsx(W,{variant:"default",size:"sm",onClick:le,disabled:_||!P,children:w(R==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(j==="bare")return je;if(j==="inline"){let Z;e[38]!==w?(Z=w("gitView.branch.updateTitle"),e[38]=w,e[39]=Z):Z=e[39];let Fe;e[40]!==Z?(Fe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:Z}),e[40]=Z,e[41]=Fe):Fe=e[41];let _e;e[42]!==w?(_e=w("gitView.branch.updateDescriptionPrefix"),e[42]=w,e[43]=_e):_e=e[43];let tt;e[44]!==Y?(tt=t.jsx("span",{className:"font-mono text-foreground",children:Y}),e[44]=Y,e[45]=tt):tt=e[45];let st;e[46]!==_e||e[47]!==tt?(st=t.jsxs("div",{className:"typography-micro text-muted-foreground",children:[_e," ",tt,"."]}),e[46]=_e,e[47]=tt,e[48]=st):st=e[48];let Je;e[49]!==Fe||e[50]!==st?(Je=t.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:t.jsxs("div",{className:"space-y-1",children:[Fe,st]})}),e[49]=Fe,e[50]=st,e[51]=Je):Je=e[51];let at;e[52]!==je?(at=t.jsx("div",{className:"pt-3",children:je}),e[52]=je,e[53]=at):at=e[53];let it;return e[54]!==Je||e[55]!==at?(it=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Je,at]}),e[54]=Je,e[55]=at,e[56]=it):it=e[56],it}let Re;e[57]!==N?(Re=N?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"git-merge",className:"size-4"}),e[57]=N,e[58]=Re):Re=e[58];let Ce;e[59]!==w?(Ce=w("gitView.branch.mergeRebase"),e[59]=w,e[60]=Ce):Ce=e[60];let Ee;e[61]!==Ce?(Ee=t.jsx("span",{children:Ce}),e[61]=Ce,e[62]=Ee):Ee=e[62];let K;e[63]!==se||e[64]!==_||e[65]!==Re||e[66]!==Ee?(K=t.jsx(Zt,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"sm",className:"gap-1.5",onClick:se,disabled:_,children:[Re,Ee]})}),e[63]=se,e[64]=_,e[65]=Re,e[66]=Ee,e[67]=K):K=e[67];let xe;e[68]!==w?(xe=w("gitView.branch.mergeRebaseTooltip"),e[68]=w,e[69]=xe):xe=e[69];let Te;e[70]!==xe?(Te=t.jsx(Xt,{sideOffset:8,children:xe}),e[70]=xe,e[71]=Te):Te=e[71];let Ge;e[72]!==K||e[73]!==Te?(Ge=t.jsxs(Qt,{children:[K,Te]}),e[72]=K,e[73]=Te,e[74]=Ge):Ge=e[74];let Ie;e[75]!==ue||e[76]!==S?(Ie=Z=>{Z?S(!0):ue()},e[75]=ue,e[76]=S,e[77]=Ie):Ie=e[77];let Ne;e[78]!==w?(Ne=w("gitView.branch.updateTitle"),e[78]=w,e[79]=Ne):Ne=e[79];let Se;e[80]!==Ne?(Se=t.jsx(pt,{children:Ne}),e[80]=Ne,e[81]=Se):Se=e[81];let Be;e[82]!==X||e[83]!==N||e[84]!==R||e[85]!==ee||e[86]!==w||e[87]!==Y?(Be=N?w(ee?X?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":R==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):t.jsxs(t.Fragment,{children:[w("gitView.branch.dialogDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:Y}),"."]}),e[82]=X,e[83]=N,e[84]=R,e[85]=ee,e[86]=w,e[87]=Y,e[88]=Be):Be=e[88];let Pe;e[89]!==Be?(Pe=t.jsx(yt,{children:Be}),e[89]=Be,e[90]=Pe):Pe=e[90];let ke;e[91]!==Se||e[92]!==Pe?(ke=t.jsxs(ft,{children:[Se,Pe]}),e[91]=Se,e[92]=Pe,e[93]=ke):ke=e[93];let we;e[94]!==je||e[95]!==ke?(we=t.jsxs(gt,{className:"max-w-md",children:[ke,je]}),e[94]=je,e[95]=ke,e[96]=we):we=e[96];let De;e[97]!==B||e[98]!==Ie||e[99]!==we?(De=t.jsx(ht,{open:B,onOpenChange:Ie,children:we}),e[97]=B,e[98]=Ie,e[99]=we,e[100]=De):De=e[100];let Le;return e[101]!==Ge||e[102]!==De?(Le=t.jsxs(t.Fragment,{children:[Ge,De]}),e[101]=Ge,e[102]=De,e[103]=Le):Le=e[103],Le};function gi(i){return i.status==="done"||i.status==="error"}function fi(i){return i.status==="error"}function pi(i){return i.slice(i.indexOf("/")+1)}function xi(i){return[i]}function wi(i){return[i]}function yi(i,e){return t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsxs("div",{className:"mt-0.5 shrink-0",children:[i.status==="running"&&t.jsx(T,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),i.status==="done"&&t.jsx(T,{name:"check",className:"size-3.5 text-success"}),i.status==="error"&&t.jsx(T,{name:"close",className:"size-3.5 text-destructive"}),i.status==="pending"&&t.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),t.jsx("span",{className:Ve("typography-micro",i.status==="error"&&"text-destructive",i.status==="done"&&"text-muted-foreground",i.status==="running"&&"text-foreground",i.status==="pending"&&"text-muted-foreground/60"),children:i.message})]},e)}function bi(i){return i.stopPropagation()}const vi=({runMutation:i,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:v})=>{const h=[];let p=!1;return{enqueue:m=>{const x=h[h.length-1];if(x?.directory===m.directory&&x.direction===m.direction){m.paths.forEach(M=>x.paths.add(M));return}h.push(m)},flush:()=>{if(p)return;const m=h.shift();if(!m)return;p=!0;const x={directory:m.directory,direction:m.direction,paths:Array.from(m.paths),rollback:m.rollback};(async()=>{try{await i(x),e(x)}catch(M){n(x,M)}finally{r(x.paths),p=!1,h.length>0&&v()}})()},clear:()=>{h.length=0},size:()=>h.length,isRunning:()=>p}},ji=15e3,Ci=40,Ni=20,wr={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Si=(i,e)=>{const n=i.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,v=n.match(r);if(v){const f=v[1],m=wr[f];if(m)return e.find(x=>x.code===m)||null}const h=n.split(" ")[0],p=wr[h];return p&&e.find(f=>f.code===p)||null},ki=20,jt=new Map,Vi=(i,e)=>{if(jt.delete(i),jt.set(i,e),jt.size>ki){const n=jt.keys().next().value;n!==void 0&&jt.delete(n)}},nt=i=>(i||"").replace(/\\/g,"/").replace(/\/+$/,""),yr=i=>{const e=i.index?.trim();return!!(e&&e!=="?")},Ii=i=>{const e=i.working_dir?.trim(),n=i.index?.trim();return!!(e||n==="?")},Wl=({isActive:i})=>{const{t:e}=et(),{git:n}=ta(),r=sa(),[v,h]=l.useState(null),[p,f]=l.useState(!1),m=Xe(s=>s.currentSessionId),x=Xe(s=>s.newSessionDraft),M=Xe(s=>s.setDraftBootstrapPendingDirectory),y=Xe(s=>s.worktreeMetadata),k=Xe(s=>s.availableWorktrees),L=nt(r),N=l.useMemo(()=>{if(!L)return;const s=k.find(a=>nt(a.path)===L);if(s)return s;for(const a of y.values())if(nt(a.path)===L)return a},[k,L,y]),O=l.useMemo(()=>{if(m)return y.get(m)??N;if(x?.open)return N},[m,N,x?.open,y]),{profiles:j,globalIdentity:w,defaultGitIdentityId:B,loadProfiles:S,loadGlobalIdentity:R,loadDefaultGitIdentityId:I}=Ia(or(s=>({profiles:s.profiles,globalIdentity:s.globalIdentity,defaultGitIdentityId:s.defaultGitIdentityId,loadProfiles:s.loadProfiles,loadGlobalIdentity:s.loadGlobalIdentity,loadDefaultGitIdentityId:s.loadDefaultGitIdentityId}))),P=ra(r??null),g=na(r??null),H=aa(s=>m?s.getAttachment(m):void 0),E=H?ia(H):[],V=H&&!H.degraded&&!H.legacy?H.worktreeRoot??void 0:void 0,D=ja(r,O,g?.current??void 0),U=oa(r??null),$=la(r??null),_=ca(r??null),Y=da(r??null),ee=ua(r??null),{setActiveDirectory:X,fetchAll:oe,ensureAll:de,fetchStatus:Q,fetchBranches:te,fetchLog:u,setLogMaxCount:d,fetchIdentity:F,prefetchDiffs:A,clearDiffCache:q,moveStatusPathsOptimistically:ie,restoreStatus:se,bumpIndexRevision:G}=ma(or(s=>({setActiveDirectory:s.setActiveDirectory,fetchAll:s.fetchAll,ensureAll:s.ensureAll,fetchStatus:s.fetchStatus,fetchBranches:s.fetchBranches,fetchLog:s.fetchLog,setLogMaxCount:s.setLogMaxCount,fetchIdentity:s.fetchIdentity,prefetchDiffs:s.prefetchDiffs,clearDiffCache:s.clearDiffCache,moveStatusPathsOptimistically:s.moveStatusPathsOptimistically,restoreStatus:s.restoreStatus,bumpIndexRevision:s.bumpIndexRevision}))),fe=Pt(s=>s.isMobile),re=Pt(s=>s.openContextDiff),le=Pt(s=>s.openContextSurface),ve=g?.current??null,pe=ha(s=>!r||!ve?null:ga(s.entries,r,ve)),ue=Pt(s=>s.navigateToDiff),me=l.useRef(null),he=l.useRef(null),ge=l.useRef(null),ce=l.useRef(null),ze=l.useRef(!0);l.useEffect(()=>()=>{ze.current=!1},[]);const $e=l.useCallback(()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null)},[]),je=l.useCallback(s=>{$e(),he.current=window.setTimeout(()=>{he.current=null,nt(s)===nt(r)&&Q(s,n,{silent:!0})},ji)},[$e,r,Q,n]);l.useEffect(()=>$e,[$e]);const Re=l.useCallback(()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null)},[]),Ce=l.useCallback(()=>{ge.current===null&&(ge.current=window.setTimeout(()=>{ge.current=null,ce.current?.()},0))},[]),Ee=l.useCallback(async(s,a,o)=>{if(a==="stage"){if(n.stageGitFiles){await n.stageGitFiles(s,o);return}await Promise.all(o.map(c=>n.stageGitFile(s,c)));return}if(n.unstageGitFiles){await n.unstageGitFiles(s,o);return}await Promise.all(o.map(c=>n.unstageGitFile(s,c)))},[n]),K=l.useMemo(()=>vi({runMutation:({directory:s,direction:a,paths:o})=>Ee(s,a,o),onMutationComplete:({directory:s})=>{G(s),je(s)},onMutationError:({directory:s,direction:a,rollback:o},c)=>{o?.(),G(s),je(s);const C=e(a==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");b.error(c instanceof Error?c.message:C)},onPathsComplete:s=>{zs(a=>{const o=new Set(a);return s.forEach(c=>o.delete(c)),o})},scheduleFlush:Ce}),[G,Ee,Ce,je,e]);l.useEffect(()=>(ce.current=K.flush,()=>{ce.current=null}),[K]),l.useEffect(()=>()=>K.clear(),[K]),l.useEffect(()=>Re,[Re]),l.useEffect(()=>{if(!i)return;if(!r){h(null),f(!1);return}let s=!1,a=null;const o=async()=>{try{const c=await va(r);if(s)return;h(c.status),c.status==="pending"&&(a=window.setTimeout(()=>{o()},500))}catch{s||h(null)}};return o(),()=>{s=!0,a!==null&&window.clearTimeout(a)}},[i,r]),l.useEffect(()=>{const s=me.current;me.current=v,!(!r||!n)&&(s==="pending"&&v==="ready"&&(f(!0),oe(r,n).finally(()=>{window.setTimeout(()=>{f(!1)},1200)})),v==="failed"&&(M(null),f(!1)))},[r,oe,n,M,v]);const xe=nt(x?.bootstrapPendingDirectory??null),Te=!!(r&&xe&&xe===nt(r)),Ie=!!(r&&(v==="pending"||Te))||p,Ne=l.useMemo(()=>r?jt.get(r)??null:null,[r]),Se=fa(s=>s.settingsGitmojiEnabled),[Be,Pe]=l.useState(null),{gitmojis:ke}=La(Se);l.useEffect(()=>{const s=V||D?.projectDirectory;if(!s){Pe(null);return}let a=!1;return pa(s).then(o=>{if(a)return;const c=o.trim();Pe(c&&c!=="HEAD"?c:null)}).catch(()=>{a||Pe(null)}),()=>{a=!0}},[V,D?.projectDirectory]);const[we,De]=l.useState(Ne?.commitMessage??""),[Le,Z]=l.useState([]),[Fe,_e]=l.useState(!1),tt=l.useRef(null),[st,Je]=l.useState(null),[at,it]=l.useState(!1),[Es,Ls]=l.useState(null),[Ke,Sr]=l.useState(25),[kr,As]=l.useState(!1),{triggerFireworks:Vr}=Ca(),Os=l.useRef(new Map),Bt=l.useRef(0),es=l.useCallback(()=>{Bt.current+=1,ze.current&&As(!0)},[]),ts=l.useCallback(()=>{Bt.current=Math.max(0,Bt.current-1),ze.current&&Bt.current===0&&As(!1)},[]),[ss,Dt]=l.useState(new Set),[Ir,zs]=l.useState(new Set),[rs,Gs]=l.useState(!1),[Pr,Fr]=l.useState(0),[Rr,_s]=l.useState(!1),[ns,$s]=l.useState(Ne?.generatedHighlights??[]),Br=Ir.size>0||K.size()>0||K.isRunning(),Hs=l.useCallback(()=>{const s=tt.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),as=V||D?.projectDirectory||null,is=g?.current||null,Dr=l.useMemo(()=>{const s=g?.tracking;return s?s.startsWith("origin/"):!0},[g?.tracking]),Ws=l.useMemo(()=>{const s=D?.createdFromBranch,a=typeof s=="string"?s.trim():"",o=typeof g?.current=="string"?g.current.trim():"",c=typeof Be=="string"?Be.trim():"";return a?a===o&&a.startsWith("opencode/")&&c.length>0&&c!==a?c:a:c||o||"HEAD"},[D?.createdFromBranch,g,Be]),Mt=l.useCallback(()=>{$s([])},[]),[os,Mr]=l.useState(new Set),[Tt,Tr]=l.useState(new Map),[Et,ls]=l.useState(new Set),cs=l.useRef(Tt),St=l.useRef(Et),[Er,bt]=l.useState(null),[xt,ds]=l.useState(null),[Us,Js]=l.useState(""),[Me,Lt]=l.useState(null),[Lr,Ks]=l.useState(!1),[Ar,qs]=l.useState(!1),[us,ms]=l.useState([]),[Or,Ys]=l.useState(null),[Qs,hs]=l.useState(null),[zr,At]=l.useState([]),[Gr,qe]=l.useState(!1),[_r,Qe]=l.useState([]),[Ot,Ze]=l.useState("merge"),[$r,gs]=l.useState(null),[fs,Zs]=l.useState(!1),[ps,Hr]=l.useState(100),[Wr,Ur]=l.useState(0),Ye=l.useMemo(()=>m?`openchamber.conflict:${m}`:null,[m]),rt=l.useCallback((s,a,o)=>{if(!Ye||typeof window>"u")return;const c={directory:s,conflictFiles:a,operation:o};window.localStorage.setItem(Ye,JSON.stringify(c))},[Ye]),He=l.useCallback(()=>{!Ye||typeof window>"u"||window.localStorage.removeItem(Ye)},[Ye]);l.useEffect(()=>{if(!Ye||typeof window>"u"||!r)return;const s=window.localStorage.getItem(Ye);if(s)try{const a=JSON.parse(s);if(a.directory!==r){window.localStorage.removeItem(Ye);return}Qe(a.conflictFiles??[]),Ze(a.operation??"merge"),qe(!0)}catch{window.localStorage.removeItem(Ye)}},[Ye,r]);const[Jr,xs]=l.useState(!1),[ws,Xs]=l.useState("merge"),[ys,er]=l.useState(""),Kr=l.useCallback(s=>{xa(s).then(a=>{if(a.ok){b.success(e("gitView.toast.commitHashCopied"));return}b.error(e("gitView.toast.copyFailed"))})},[e]),qr=l.useCallback(s=>{Mr(a=>{const o=new Set(a);return o.has(s)?o.delete(s):o.add(s),o})},[]);l.useEffect(()=>{cs.current=Tt},[Tt]),l.useEffect(()=>{St.current=Et},[Et]),l.useEffect(()=>{if(!r||!n)return;const s=Array.from(os).filter(o=>!cs.current.has(o)&&!St.current.has(o));if(s.length===0)return;let a=!1;return ls(o=>{const c=new Set(o);for(const C of s)c.add(C);return St.current=c,c}),Promise.all(s.map(o=>n.getCommitFiles(r,o).then(c=>({hash:o,files:c.files})).catch(c=>(console.error("Failed to fetch commit files:",c),{hash:o,files:[]})))).then(o=>{a||(Tr(c=>{const C=new Map(c);for(const{hash:z,files:ae}of o)C.set(z,ae);return cs.current=C,C}),ls(c=>{const C=new Set(c);for(const{hash:z}of o)C.delete(z);return St.current=C,C}))}),()=>{a=!0,ls(o=>{let c=!1;const C=new Set(o);for(const z of s)C.delete(z)&&(c=!0);return c?(St.current=C,C):o})}},[os,r,n]),l.useEffect(()=>{r&&Vi(r,{directory:r,commitMessage:we,generatedHighlights:ns})},[we,r,ns]),l.useEffect(()=>{i&&(S(),R(),I())},[i,S,R,I]),l.useEffect(()=>{if(!i)return;if(!r||!n?.getRemoteUrl){ds(null);return}let s=!1;return n.getRemoteUrl(r).then(a=>{s||ds(a)}).catch(()=>{s||ds(null)}),()=>{s=!0}},[i,r,n]);const zt=l.useCallback(async()=>{if(!r||!n?.getRemotes){ms([]);return}try{const s=await n.getRemotes(r);ze.current&&ms(s)}catch{ze.current&&ms([])}},[r,n]);l.useEffect(()=>{i&&zt()},[i,zt]),l.useEffect(()=>{i&&r&&(X(r),de(r,n))},[i,r,X,de,n]),l.useEffect(()=>{if(i&&r)return wa.onGitRefreshHint(s=>{nt(s.directory)===nt(r)&&(s.paths?.length&&q(r,s.paths),Q(r,n,{silent:!0}))})},[i,q,r,Q,n]);const ne=l.useCallback(async(s=!0)=>{if(r)try{await Promise.all([Q(r,n),te(r,n)])}catch(a){if(s){const o=a instanceof Error?a.message:e("gitView.toast.refreshRepositoryFailed");b.error(o)}}},[r,n,Q,te,e]),ye=l.useCallback(async()=>{r&&await u(r,n,Ke)},[r,n,u,Ke]),bs=l.useCallback(async()=>{r&&await F(r,n)},[r,n,F]);l.useEffect(()=>{if(!i||!r||!n?.hasLocalIdentity||P!==!0)return;const s=typeof B=="string"?B.trim():"";if(!s||s==="global"||Os.current.get(r)===s)return;let o=!1;return(async()=>{try{const C=await n.hasLocalIdentity?.(r);if(o||C===!0)return;es(),await n.setGitIdentity(r,s),Os.current.set(r,s),await bs()}catch(C){console.warn("Failed to auto-apply default git identity:",C)}finally{o||ts()}})(),()=>{o=!0}},[i,es,r,B,ts,n,P,bs]);const ot=l.useMemo(()=>g?[...g.files??[]].sort((a,o)=>a.path.localeCompare(o.path)):[],[g]),We=l.useMemo(()=>ot.filter(yr),[ot]),vs=l.useMemo(()=>ot.filter(Ii),[ot]);l.useEffect(()=>{if(!r||ot.length===0)return;const s=[],a=new Set,o=C=>{!C||a.has(C)||(a.add(C),s.push(C))};if(We.forEach(C=>o(C.path)),Le.forEach(o),ot.slice(0,Ni).forEach(C=>o(C.path)),s.length===0)return;const c=window.setTimeout(()=>{A(r,n,s,{maxFiles:Ci})},120);return()=>{window.clearTimeout(c)}},[ot,r,n,A,We,Le]);const tr=s=>s?.pushed[0]?.remote||g?.tracking?.split("/")[0]||Ue.find(a=>a.name==="origin")?.name||Ue[0]?.name||"origin",sr=async(s,a)=>{if(r){Je(s);try{const o=c=>{const C=`${c.name}/`,z=g?.tracking?.startsWith(C)?g.tracking.slice(C.length):void 0;return{remote:c.name,branch:z,rebase:!0}};if(s==="fetch"){if(!a)throw new Error("No remote available for fetch");await n.gitFetch(r,{remote:a.name}),b.success(e("gitView.toast.fetchedFromRemote",{name:a.name}))}else if(s==="pull"){if(!a)throw new Error("No remote available for pull");const c=await n.gitPull(r,o(a));b.success(c.files.length===1?e("gitView.toast.pulledFilesSingle",{count:c.files.length,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c.files.length,name:a.name}))}else if(s==="push"){const c=await n.gitPush(r);b.success(e("gitView.toast.pushedToUpstream",{name:tr(c)}))}else if(s==="sync"){if(!a)throw new Error("No remote available for sync");let c=0,C=!1;await n.gitFetch(r,{remote:a.name});const z=await n.getGitStatus(r);if((z.behind??0)>0){if((z.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync"));return}c=(await n.gitPull(r,o(a))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),C=!0),c>0&&C?b.success(c===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:c,name:a.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:c,name:a.name})):c>0?b.success(c===1?e("gitView.toast.pulledFilesSingle",{count:c,name:a.name}):e("gitView.toast.pulledFilesPlural",{count:c,name:a.name})):C?b.success(e("gitView.toast.pushedToUpstream",{name:a.name})):b.success(e("gitView.toast.alreadyUpToDate"))}await ne(!1),await ye()}catch(o){const c=o instanceof Error?o.message:e("gitView.toast.syncActionFailed",{action:s==="sync"?e("gitView.sync.syncChanges"):s==="pull"?e("gitView.sync.pull"):s});b.error(c)}finally{Je(null)}}},Yr=l.useCallback(async s=>{if(!r)return;const a=s.name.trim();if(!a){b.error(e("gitView.toast.remoteNameRequired"));return}if(a==="origin"){b.error(e("gitView.toast.cannotRemoveOriginRemote"));return}Ys(a);try{await n.removeRemote(r,{remote:a}),b.success(e("gitView.toast.removedRemote",{name:a})),await Promise.all([ne(!1),zt()])}catch(o){const c=o instanceof Error?o.message:`Failed to remove ${a}`;b.error(c)}finally{Ys(null)}},[r,n,zt,ne,e]),rr=async(s={})=>{if(!r)return;if(!we.trim()){b.error(e("gitView.toast.enterCommitMessage"));return}const a=We.map(c=>c.path).sort();if(a.length===0){b.error(e("gitView.toast.stageFileToCommit"));return}const o=s.pushAfter?"commitAndPush":"commit";Ls(o);try{if(await n.createGitCommit(r,we.trim(),{files:a,stageFiles:[]}),G(r),b.success(e("gitView.toast.commitCreated")),De(""),Mt(),await ne(),s.pushAfter){const c=g?.tracking?.split("/")[0],C=Ue.find(In=>In.name===c)??Ue[0];if(!C)throw new Error(e("mobile.changes.noRemote"));Je("sync");const z=`${C.name}/`,ae=g?.tracking?.startsWith(z)?g.tracking.slice(z.length):void 0;await n.gitFetch(r,{remote:C.name});const J=await n.getGitStatus(r);if((J.behind??0)>0){if((J.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync")),await ne(!1);return}await n.gitPull(r,{remote:C.name,branch:ae,rebase:!0})}const Oe=await n.getGitStatus(r);let vt;(Oe.ahead??0)>0&&(vt=await n.gitPush(r)),b.success(e("gitView.toast.pushedToUpstream",{name:tr(vt)})),Vr(),await ne(!1)}else await ne(!1);await ye(),Fr(c=>c+1)}catch(c){const C=c instanceof Error?c.message:e("gitView.toast.createCommitFailed");b.error(C)}finally{Ls(null),s.pushAfter&&Je(null)}},Qr=l.useCallback(async()=>{if(!r)return;const s=We.map(a=>a.path).sort();if(s.length===0){b.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:s.length}),_s(!0);try{const{message:a}=await ya(r,s),o=a.subject?.trim()??"",c=Array.isArray(a.highlights)?a.highlights:[];if(o){let C=o;if(Se&&ke.length>0){const z=Si(o,ke);if(z){const{code:ae,emoji:J}=z;!o.startsWith(ae)&&!o.startsWith(J)&&(C=`${ae} ${o}`)}}De(C)}$s(c),Hs()}catch(a){console.error("[git-generation][browser] GitView generate handler failed",{message:a instanceof Error?a.message:String(a),error:a});const o=a instanceof Error?a.message:e("gitView.toast.generateCommitMessageFailed");b.error(o)}finally{_s(!1)}},[r,We,Se,ke,Hs,e]),js=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",Zr=async(s,a)=>{if(!r||!g)return;const o=Ss(H);if(o.length>0){b.error(e("gitView.toast.cannotCreateBranch",{reason:js(o[0])}));return}const c=g.current??null,C=a?.name??"origin";try{await n.createBranch(r,s,c??"HEAD"),b.success(e("gitView.toast.createdBranch",{name:s})),await n.checkoutBranch(r,s);let z=!1;try{await n.gitPush(r,{remote:C,branch:s,options:["--set-upstream"]}),z=!0}catch(ae){const J=ae instanceof Error?ae.message:`Unable to push new branch to ${C}.`;b.warning(e("gitView.toast.branchCreatedLocally"),{description:t.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",J]})})}await ne(),await ye(),z&&b.success(e("gitView.toast.upstreamSet",{branch:s,remote:C}))}catch(z){const ae=z instanceof Error?z.message:e("gitView.toast.createBranchFailed");throw b.error(ae),z}},Xr=async(s,a)=>{if(!r)return;const o=Ss(H);if(o.length>0){b.error(e("gitView.toast.cannotRenameBranch",{reason:js(o[0])}));return}try{await n.renameBranch(r,s,a),b.success(e("gitView.toast.renamedBranch",{oldName:s,newName:a})),await ne(),await ye()}catch(c){const C=c instanceof Error?c.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:a});b.error(C)}},en=async s=>{if(!r)return;const a=Ss(H);if(a.length>0){b.error(e("gitView.toast.cannotCheckout",{reason:js(a[0])}));return}const o=s.replace(/^remotes\//,"");if(g?.current!==o)try{const c=await n.checkoutBranch(r,o);b.success(e("gitView.toast.checkedOut",{name:c?.branch||o})),await ne(),await ye()}catch(c){const C=c instanceof Error?c.message:e("gitView.toast.checkoutFailed",{name:o});b.error(C)}},tn=async s=>{if(r){es();try{await n.setGitIdentity(r,s.id),b.success(e("gitView.toast.appliedIdentity",{name:s.name})),await bs()}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.applyIdentityFailed");b.error(o)}finally{ts()}}},kt=l.useMemo(()=>U?.all?U.all.filter(s=>!s.startsWith("remotes/")).sort():[],[U]),lt=l.useMemo(()=>U?.all?U.all.filter(s=>s.startsWith("remotes/")).map(s=>s.replace(/^remotes\//,"")).sort():[],[U]),Ue=l.useMemo(()=>{if(us.length>0)return us;const s=new Set,a=g?.tracking?.trim();a&&a.includes("/")&&s.add(a.split("/")[0]);for(const o of lt){const c=o.indexOf("/");c>0&&s.add(o.slice(0,c))}return s.size===0&&xt&&s.add("origin"),Array.from(s).map(o=>({name:o,fetchUrl:xt??"",pushUrl:xt??""}))},[us,lt,xt,g?.tracking]),ct=g?.current??null,nr=l.useMemo(()=>{const s=g?.tracking?.trim().split("/")[0];return(s&&U?.defaultBranches?.[s])??U?.defaultBranches?.origin},[U,g?.tracking]),wt=l.useMemo(()=>Na({remoteNames:new Set(Ue.map(s=>s.name)),localBranches:kt,worktreeCreatedFromBranch:D?.createdFromBranch,rootBranchHint:Be,defaultBranch:nr,headBranch:ct}),[ct,nr,Ue,kt,Be,D?.createdFromBranch]),sn=l.useMemo(()=>Ue.map(o=>o.name).map(o=>`${o}/${wt}`).find(o=>lt.includes(o))??wt,[wt,Ue,lt]),rn=l.useMemo(()=>{const s=new Map;w&&s.set(w.id,w);let a=null;if(xt)try{let o=xt.trim();o.startsWith("git@")&&(o=`https://${o.slice(4).replace(":","/")}`),o.endsWith(".git")&&(o=o.slice(0,-4));const c=new URL(o);a=c.hostname+c.pathname}catch{}for(const o of j){if(o.authType!=="token"){s.set(o.id,o);continue}const c=o.host;if(!c){s.set(o.id,o);continue}if(!c.includes("/")){s.set(o.id,o);continue}a&&a===c&&s.set(o.id,o)}return Array.from(s.values())},[j,w,xt]),nn=l.useMemo(()=>{if(_?.userName&&_?.userEmail){const s=j.find(a=>a.userName===_.userName&&a.userEmail===_.userEmail);return s||(w&&w.userName===_.userName&&w.userEmail===_.userEmail?w:{id:"local-config",name:_.userName,userName:_.userName,userEmail:_.userEmail,sshKey:_.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return w??null},[_,j,w]),an=We.length,on=Y||st!==null||Es!==null,ln=!!(D&&as&&is&&Dr),ar=!!ct,dt=ln&&as&&is&&D?{repoRoot:as,sourceBranch:is,worktreeMetadata:D}:null;l.useEffect(()=>{if(!r||!n||!$?.all?.length||!ct||!wt||ct===wt){bt(null);return}let s=!1;return(async()=>{try{const o=await n.getGitLog(r,{from:wt,to:"HEAD",maxCount:Ke});if(s)return;const c=new Set((o?.all??[]).map(z=>z.hash).filter(z=>typeof z=="string"&&z.length>0));if(c.size===0){bt(null);return}const C=$.all.findIndex(z=>!c.has(z.hash));if(C===0){bt(null);return}if(C===-1){bt({insertBeforeIndex:$.all.length,branchName:ct,direction:"up"});return}bt({insertBeforeIndex:C,branchName:ct,direction:"up"})}catch{s||bt(null)}})(),()=>{s=!0}},[wt,ct,r,n,$,Ke]),l.useEffect(()=>{gs(null)},[r]),l.useEffect(()=>{if(Me!=="graph"||!r){Me!=="graph"&&gs(null);return}let s=!1;return Zs(!0),n.getGitLog(r,{maxCount:ps,all:!0}).then(a=>{s||gs(a)}).catch(a=>{console.error("Failed to fetch graph log:",a)}).finally(()=>{s||Zs(!1)}),()=>{s=!0}},[Me,r,ps,Wr,n]);const Vt=l.useCallback((s,a)=>{if(!r||s.length===0)return;const o=Array.from(new Set(s));zs(C=>{const z=new Set(C);return o.forEach(ae=>z.add(ae)),z});const c=ie(r,o,a);K.enqueue({directory:r,direction:a,paths:new Set(o),rollback:()=>se(r,c)}),Ce()},[r,K,ie,se,Ce]),Cs=l.useCallback(async s=>{if(r){Dt(a=>{const o=new Set(a);return o.add(s),o});try{await n.revertGitFile(r,s,{scope:"working"}),b.success(e("gitView.toast.revertedFile",{path:s})),await ne(!1)}catch(a){const o=a instanceof Error?a.message:e("gitView.toast.revertFailed");b.error(o)}finally{Dt(a=>{const o=new Set(a);return o.delete(s),o})}}},[r,ne,n,e]),Gt=l.useCallback(async(s,a,o="all")=>{if(!r||s.length===0)return;const c=Array.from(new Set(s));if(rs||c.some(J=>ss.has(J)))return;const C=new Set(We.map(J=>J.path)),z=o==="all"&&c.some(J=>C.has(J));a&&Gs(!0),Dt(J=>{const Oe=new Set(J);return c.forEach(vt=>Oe.add(vt)),Oe});const ae=[];try{if(await Promise.all(c.map(async J=>{try{await n.revertGitFile(r,J,{scope:o})}catch(Oe){ae.push({path:J,message:Oe instanceof Error?Oe.message:e("gitView.toast.revertFailed")})}})),z&&ae.length<c.length&&G(r),await ne(!1),ae.length===0)b.success(c.length===1?e("gitView.toast.revertedFilesSingle",{count:c.length}):e("gitView.toast.revertedFilesPlural",{count:c.length}));else if(ae.length===c.length)b.error(ae[0]?.message||e("gitView.toast.revertFailed"));else{const J=c.length-ae.length;b.warning(J===1?e("gitView.toast.revertedSomeSingle",{success:J,failed:ae.length}):e("gitView.toast.revertedSomePlural",{success:J,failed:ae.length}))}}finally{Dt(J=>{const Oe=new Set(J);return c.forEach(vt=>Oe.delete(vt)),Oe}),a&&Gs(!1)}},[G,r,n,rs,ne,ss,We,e]),cn=l.useCallback(async s=>{await Gt(s,!0)},[Gt]),dn=l.useCallback(async s=>{await Gt(s,!1,"working")},[Gt]),Ns=l.useCallback((s,a)=>{if(r&&!fe){re(r,s,a);return}ue(s,a)},[r,fe,ue,re]),un=l.useCallback(()=>it(!0),[]),mn=l.useMemo(()=>{const s=[];return We.length>0&&s.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:We,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:a=>e("gitView.changes.unstageFileAria",{path:a}),onActionFile:a=>{Vt([a],"unstage")},onActionAll:a=>{Vt(a,"unstage")},onViewDiff:a=>Ns(a,!0),onRevertFile:Cs,showRevertActions:!1,accent:!0}),vs.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:vs,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:a=>e("gitView.changes.stageFileAria",{path:a}),onActionFile:a=>{Vt([a],"stage")},onActionAll:a=>{Vt(a,"stage")},onViewDiff:a=>Ns(a,!1),onRevertFile:Cs}),s},[Cs,Ns,Vt,We,e,vs]),hn=l.useCallback(s=>{if(s.length===0)return;const a=s.map(o=>o.trim()).filter(Boolean);if(a.length===0){Mt();return}De(o=>{const c=o.trim(),C=c.length>0?`
|
|
4
|
-
|
|
5
|
-
`:"";return`${c}${C}${a.join(`
|
|
6
|
-
`)}`.trim()}),Mt()},[Mt]),gn=l.useCallback((s,a)=>{const o=a||s;De(c=>{const C=c.trimStart();return C.startsWith(s)||a&&C.startsWith(a)?c:`${o.endsWith(" ")?o:`${o} `}${c}`.trimStart()}),Js(""),_e(!1)},[]),_t=l.useCallback(s=>{const a=s instanceof Error?s.message.toLowerCase():"";return a.includes("uncommitted changes")||a.includes("local changes")||a.includes("your local changes would be overwritten")||a.includes("please commit your changes or stash them")||a.includes("cannot rebase: you have unstaged changes")||a.includes("error: cannot pull with rebase")},[]),ut=l.useCallback((s,a)=>{At(o=>[...o,{message:s,status:a,timestamp:Date.now()}])},[]),Ae=l.useCallback((s,a)=>{At(o=>{if(o.length===0)return o;const c=[...o];return c[c.length-1]={...c[c.length-1],status:s,...a?{message:a}:{}},c})},[]),$t=l.useCallback(()=>{At([])},[]),fn=l.useCallback(()=>{At([]),hs(null)},[]),Ht=l.useCallback(s=>{const a=s.trim(),o=new Set(Ue.map(C=>C.name)),c=a.indexOf("/");if(c>0){const C=a.slice(0,c),z=a.slice(c+1);if(o.has(C)&&z)return{branch:a,remote:C,remoteBranch:z}}for(const C of Ue){const z=`${C.name}/${a}`;if(lt.includes(z))return{branch:z,remote:C.name,remoteBranch:a}}return{branch:a,remote:null,remoteBranch:null}},[Ue,lt]),pn=l.useCallback(async s=>{if(!r)return;hs("merge"),$t();const a=g?.current,o=Ht(s);try{o.remote&&o.remoteBranch&&(ut(`Fetching ${o.remote}/${o.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:o.remote,branch:o.remoteBranch}),Ae("done",`Fetched ${o.remote}/${o.remoteBranch}`)),ut(`Merging ${o.branch} into ${a}...`,"running");const c=await n.merge(r,{branch:o.branch});c.conflict?(Ae("error","Merge conflicts detected"),Qe(c.conflictFiles??[]),Ze("merge"),qe(!0),rt(r,c.conflictFiles??[],"merge")):(Ae("done",`Merged ${o.branch} into ${a}`),He(),ut("Refreshing repository status...","running"),await ne(),await ye(),Ae("done","Repository status updated"))}catch(c){if(_t(c))Ae("error","Uncommitted changes detected"),Xs("merge"),er(o.branch),xs(!0);else{const C=c instanceof Error?c.message:`Failed to merge ${o.branch}`;Ae("error",C)}}},[r,n,g,Ht,ne,ye,_t,rt,He,ut,Ae,$t]),xn=l.useCallback(async s=>{if(!r)return;hs("rebase"),$t();const a=g?.current,o=Ht(s);try{o.remote&&o.remoteBranch&&(ut(`Fetching ${o.remote}/${o.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:o.remote,branch:o.remoteBranch}),Ae("done",`Fetched ${o.remote}/${o.remoteBranch}`)),ut(`Rebasing ${a} onto ${o.branch}...`,"running");const c=await n.rebase(r,{onto:o.branch});c.conflict?(Ae("error","Rebase conflicts detected"),Qe(c.conflictFiles??[]),Ze("rebase"),qe(!0),rt(r,c.conflictFiles??[],"rebase")):(Ae("done",`Rebased ${a} onto ${o.branch}`),He(),ut("Refreshing repository status...","running"),await ne(),await ye(),Ae("done","Repository status updated"))}catch(c){if(_t(c))Ae("error","Uncommitted changes detected"),Xs("rebase"),er(o.branch),xs(!0);else{const C=c instanceof Error?c.message:`Failed to rebase onto ${o.branch}`;Ae("error",C)}}},[r,n,g,Ht,ne,ye,_t,rt,He,ut,Ae,$t]),wn=l.useCallback(async()=>{if(r)try{Ot==="merge"?(await n.abortMerge(r),b.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),b.success(e("gitView.toast.rebaseAborted"))),He(),await ne(),await ye()}catch(s){const a=s instanceof Error?s.message:`Failed to abort ${Ot}`;b.error(a)}},[r,n,Ot,ne,ye,He,e]),yn=l.useMemo(()=>g?.files?g.files.filter(s=>s.index==="U"||s.working_dir==="U"||s.index==="A"&&s.working_dir==="A"||s.index==="D"&&s.working_dir==="D").length:0,[g?.files]),bn=l.useCallback(async()=>{if(r)try{const s=!!g?.mergeInProgress?.head,a=!!(g?.rebaseInProgress?.headName||g?.rebaseInProgress?.onto);if(s){const o=await n.continueMerge(r);o.conflict?(Qe(o.conflictFiles??[]),Ze("merge"),qe(!0),rt(r,o.conflictFiles??[],"merge"),b.error(e("gitView.toast.mergeConflictsDetected"))):(He(),b.success(e("gitView.toast.mergeCompleted")),await ne(),await ye())}else if(a){const o=await n.continueRebase(r);o.conflict?(Qe(o.conflictFiles??[]),Ze("rebase"),qe(!0),rt(r,o.conflictFiles??[],"rebase"),b.error(e("gitView.toast.rebaseConflictsDetected"))):(He(),b.success(e("gitView.toast.rebaseStepCompleted")),await ne(),await ye())}}catch(s){const a=s instanceof Error?s.message:e("gitView.toast.continueOperationFailed");b.error(a)}},[r,n,g,ne,ye,rt,He,e]),vn=l.useCallback(async()=>{if(r)try{!!g?.mergeInProgress?.head?(await n.abortMerge(r),b.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),b.success(e("gitView.toast.rebaseAborted"))),He(),await ne(),await ye()}catch(s){const a=s instanceof Error?s.message:e("gitView.toast.abortOperationFailed");b.error(a)}},[r,n,g,ne,ye,He,e]),jn=l.useCallback(()=>{if(!r)return;const a=!!g?.mergeInProgress?.head?"merge":"rebase",o=g?.files?.filter(c=>c.index==="U"||c.working_dir==="U").map(c=>c.path)??[];o.length>0&&Qe(o),Ze(a),qe(!0)},[r,g]),Cn=l.useCallback(async s=>{if(!r)return;const a=g?.current,o=ws,c=ys,C=(g?.files??[]).some(yr);try{await n.stash(r,{message:`Auto-stash before ${o} with ${c}`,includeUntracked:!0}),C&&G(r)}catch(J){const Oe=J instanceof Error?J.message:"Failed to stash changes";b.error(Oe);return}let z=!1,ae=!1;try{if(o==="merge"){const J=await n.merge(r,{branch:c});J.conflict?(ae=!0,Qe(J.conflictFiles??[]),Ze("merge"),qe(!0)):(z=!0,b.success(e("gitView.toast.mergedIntoBranch",{branch:c,currentBranch:a||""})))}else{const J=await n.rebase(r,{onto:c});J.conflict?(ae=!0,Qe(J.conflictFiles??[]),Ze("rebase"),qe(!0)):(z=!0,b.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:a||"",branch:c})))}if(s&&z)try{await n.stashPop(r),G(r),b.success(e("gitView.toast.stashedRestored"))}catch(J){const Oe=J instanceof Error?J.message:e("gitView.toast.restoreStashFailed");b.error(Oe)}else s&&ae&&b.info(e("gitView.toast.restoreStashManually"));await ne(),await ye()}catch(J){if(s)try{await n.stashPop(r),G(r)}catch{}throw J}},[G,r,n,g,ws,ys,ne,ye,e]),Nn=l.useCallback(s=>{Sr(s),r&&(d(r,s),u(r,n,s))},[r,u,n,d]),Sn=l.useCallback(s=>{Hr(s)},[]),kn=l.useCallback(()=>{Lt(null),r&&(Q(r,n),te(r,n),u(r,n,Ke))},[r,Q,te,u,Ke,n]),Vn=l.useCallback(s=>{if(s.conflict){if(s.operation==="cherry-pick"||s.operation==="revert"){b.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:s.conflictFiles?.join(", ")??"unknown files"})}),r&&(Q(r,n),te(r,n),u(r,n,Ke));return}Qe(s.conflictFiles??[]),Ze(s.operation),qe(!0),r&&rt(r,s.conflictFiles??[],s.operation)}},[e,Qe,Ze,qe,rt,r,Q,te,u,Ke,n]);return r?P===null||P===!0&&!g?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),t.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):P===!1?Ie?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[t.jsx(T,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.worktreeSetupInProgress")}),t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):t.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[t.jsx(T,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.notGitRepository")}),t.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.notGitRepositoryDescription")}),E.includes("open-without-worktree-features")?t.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):null]}):t.jsxs("div",{className:Ve("flex h-full flex-col overflow-hidden"),children:[t.jsx(Pa,{status:g,localBranches:kt,remoteBranches:lt,branchInfo:U?.branches,syncAction:st,remotes:Ue,onFetch:s=>sr("fetch",s),onSync:s=>sr("sync",s),onRemoveRemote:Yr,removingRemoteName:Or,onCheckoutBranch:en,onCreateBranch:Zr,onRenameBranch:Xr,activeIdentityProfile:nn,availableIdentities:rn,onSelectIdentity:tn,isApplyingIdentity:kr,isWorktreeMode:!!D,onOpenHistory:()=>Lt("history"),onOpenGraph:()=>Lt("graph"),onOpenStashes:un,onOpenUpdateBranch:ar?()=>Ks(!0):void 0,onOpenReintegrateCommits:dt?()=>qs(!0):void 0,pullRequest:pe?.pr??null,prChecks:pe?.checks??null,onOpenPullRequest:r?()=>le(r,"pr"):void 0}),r&&(g?.mergeInProgress?.head||g?.rebaseInProgress?.headName||g?.rebaseInProgress?.onto)&&t.jsx(mi,{mergeInProgress:g?.mergeInProgress,rebaseInProgress:g?.rebaseInProgress,onContinue:bn,onAbort:vn,onResolveWithAI:jn,conflictCount:yn,isLoading:Y}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:t.jsx("div",{className:"h-full min-h-0 flex flex-col",children:t.jsx("div",{className:Ve("min-w-0 min-h-0 h-full flex flex-col"),children:t.jsx(vr,{as:ba,ref:tt,outerClassName:"flex-1 min-h-0",className:Ve("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:t.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(ot?.length??0)>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Ra,{groups:mn,diffStats:g?.diffStats,revertingPaths:ss,isRevertingAll:rs,onVisiblePathsChange:Z,onRevertAll:cn,onRevertDirectory:dn,headerBackgroundClassName:"bg-background"})}),t.jsx(Ba,{stagedCount:an,commitMessage:we,onCommitMessageChange:De,generatedHighlights:ns,onInsertHighlights:hn,onGenerateMessage:Qr,isGeneratingMessage:Rr,onCommit:()=>rr({pushAfter:!1}),onCommitAndPush:()=>rr({pushAfter:!0}),commitAction:Es,hasPendingIndexMutation:Br,gitmojiEnabled:Se,onOpenGitmojiPicker:()=>_e(!0)})]}):t.jsx(Wa,{onOpenStashes:()=>it(!0)})})})})})}),t.jsx(ht,{open:Lr,onOpenChange:s=>{!s&&Qs!==null||Ks(s)},children:t.jsxs(gt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(pt,{children:e("gitView.branch.updateTitle")}),t.jsxs(yt,{children:[e("gitView.branch.updateDescriptionPrefix")," ",t.jsx("span",{className:"font-mono text-foreground",children:g?.current??""}),"."]})]}),ar?t.jsx(hi,{mode:"bare",currentBranch:g?.current,localBranches:kt,remoteBranches:lt,defaultTargetBranch:sn,onMerge:pn,onRebase:xn,disabled:on,isOperating:Qs!==null,operationLogs:zr,onOperationComplete:fn}):t.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),t.jsx(ht,{open:Ar,onOpenChange:qs,children:t.jsxs(gt,{className:"max-w-2xl min-h-[26rem]",children:[t.jsxs(ft,{children:[t.jsx(pt,{children:e("gitView.integrate.title")}),t.jsx(yt,{children:dt?t.jsxs("span",{className:"font-mono text-foreground",children:[dt.sourceBranch," → ",Ws]}):null})]}),dt?t.jsx($a,{repoRoot:dt.repoRoot,sourceBranch:dt.sourceBranch,worktreeMetadata:dt.worktreeMetadata,localBranches:kt,defaultTargetBranch:Ws,refreshKey:Pr,showHeader:!1,onRefresh:()=>{r&&(Q(r,n),te(r,n),u(r,n,Ke))}},dt.worktreeMetadata.path):null]})}),t.jsx(ht,{open:Me!==null,onOpenChange:s=>{s||Lt(null)},children:t.jsxs(gt,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[t.jsxs(ft,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx(pt,{children:e(Me==="graph"?"gitView.graph.title":"gitView.history.title")}),t.jsxs(W,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(Me==="graph"){Ur(s=>s+1);return}r&&u(r,n,Ke)},disabled:Me==="graph"?fs:ee,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[t.jsx(T,{name:"refresh",className:Ve("size-4",(Me==="graph"?fs:ee)&&"animate-spin")}),e("gitView.history.refresh")]})]}),t.jsx(yt,{children:e("gitView.history.dialogDescription")})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(ei,{mode:Me==="graph"?"graph":"history",log:Me==="graph"?$r??$:$,isLogLoading:Me==="graph"&&fs||ee,logMaxCount:Me==="graph"?ps:Ke,onLogMaxCountChange:Me==="graph"?Sn:Nn,expandedCommitHashes:os,onToggleCommit:qr,commitFilesMap:Tt,loadingCommitHashes:Et,onCopyHash:Kr,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Me==="graph"?null:Er,onConflict:Me==="graph"?Vn:void 0,onActionSuccess:Me==="graph"?kn:void 0})})]})}),t.jsx(Ha,{open:at,onOpenChange:it,directory:r,hasUncommittedChanges:(g?.files?.length??0)>0,hasStagedChanges:We.length>0,uncommittedFileCount:g?.files?.length??0,onChanged:async s=>{r&&s?.affectsIndex&&G(r),await ne(!1),await ye()}}),t.jsx(ht,{open:Fe,onOpenChange:_e,children:t.jsxs(gt,{className:"max-w-md p-0 overflow-hidden",children:[t.jsx(ft,{className:"px-4 pt-4",children:t.jsx(pt,{children:e("gitView.gitmoji.title")})}),t.jsxs(Bs,{className:"h-[420px]",shouldFilter:!1,children:[t.jsx(Ds,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:Us,onValueChange:Js}),t.jsxs(Ms,{children:[t.jsx(Ts,{children:e("gitView.gitmoji.empty")}),t.jsx(qt,{children:Rt(ke,Us,s=>[s.code,s.description,s.emoji]).map(s=>t.jsxs(Yt,{onSelect:()=>gn(s.emoji,s.code),children:[t.jsx("span",{className:"text-lg",children:s.emoji}),t.jsx("span",{className:"typography-ui-label text-foreground",children:s.code}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s.description})]},s.code))})]})]})]})}),r&&t.jsx(ai,{open:Gr,onOpenChange:qe,conflictFiles:_r,directory:r,operation:Ot,onAbort:wn,onClearState:He}),t.jsx(ui,{open:Jr,onOpenChange:xs,operation:ws,targetBranch:ys,onConfirm:Cn})]}):t.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:t.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})};export{Wl as GitView};
|