@openchamber/web 1.21.0 → 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/bin/cli.test.js +35 -0
- package/bin/lib/DOCUMENTATION.md +12 -0
- package/bin/lib/cli-settings-accessors.js +111 -0
- package/bin/lib/cli-settings-accessors.test.js +189 -0
- package/bin/lib/cli-startup.js +29 -9
- package/bin/lib/commands-connect-url.js +12 -14
- package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
- package/dist/assets/CommitSection-CC5mFzO2.js +1 -0
- 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-osju7J70.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-Dan3mADn.js → PatchDiff-BGPl1s-U.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-Cvz9Z-io.js} +2 -2
- package/dist/assets/PlanView-BFMsnHk3.js +5 -0
- package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
- package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-C1Qa09YO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-DzQlzMF4.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
- package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
- package/dist/assets/de-C3luvSd_.js +9 -0
- package/dist/assets/es-CmU4HLv9.js +15 -0
- package/dist/assets/fr-Bgyni40l.js +13 -0
- package/dist/assets/index-C57jT0Sa.css +1 -0
- package/dist/assets/{index-Brm3X9rs.js → index-CWYs7sMK.js} +1 -1
- package/dist/assets/index-b0zDkWyg.js +7 -0
- package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-BO_q5ezD.js} +1 -1
- package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-D8qPqUAf.js} +1 -1
- package/dist/assets/ja-C1ImKinT.js +15 -0
- package/dist/assets/ko-CP7OdxYH.js +15 -0
- package/dist/assets/main-D4rd8Hy5.js +928 -0
- package/dist/assets/{main-vUCh0VB0.js → main-D7fwjW2z.js} +2 -2
- package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
- package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
- package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-D5rraz-g.js} +2 -2
- package/dist/assets/{mobile-CkX6H-IT.js → mobile-Cg_DE3KL.js} +2 -2
- package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-Bpql0QGw.js} +3 -3
- package/dist/assets/pl-DQYSiGYX.js +15 -0
- package/dist/assets/pt-BR-DytpsW4M.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.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-BgTPSITe.js → shikiHighlight-CFAVs_lu.js} +1 -1
- package/dist/assets/tr-aizaUvft.js +6 -0
- package/dist/assets/uk-DwnRxJZd.js +15 -0
- package/dist/assets/useAppFontEffects-DWXGRUPZ.js +7310 -0
- package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-Cc0OCXr0.js} +2 -2
- package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
- package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
- package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
- package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
- package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
- package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
- package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
- package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
- package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
- package/dist/assets/{web-components-DLnGY4fs.js → web-components-CD-GFayc.js} +4 -4
- package/dist/assets/zh-CN-UDNMxm7r.js +15 -0
- package/dist/assets/zh-TW-BsswdYL-.js +15 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/dist/site.webmanifest +1 -1
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/public/site.webmanifest +1 -1
- package/server/index.js +6 -2
- package/server/lib/cloudflare-tunnel.js +1 -1
- 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 +5 -0
- package/server/lib/fs/routes.js +150 -0
- package/server/lib/fs/routes.test.js +308 -3
- package/server/lib/git/DOCUMENTATION.md +4 -3
- package/server/lib/git/service.js +128 -6
- package/server/lib/git/service.test.js +191 -1
- 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/markdown-image-grants/DOCUMENTATION.md +4 -0
- package/server/lib/markdown-image-grants/routes.js +3 -1
- package/server/lib/markdown-image-grants/routes.test.js +14 -0
- package/server/lib/openchamber-sessions/routes.js +4 -1
- package/server/lib/openchamber-sessions/routes.test.js +23 -0
- package/server/lib/opencode/env-runtime.js +17 -1
- package/server/lib/opencode/env-runtime.test.js +56 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/lifecycle.js +48 -9
- package/server/lib/opencode/lifecycle.test.js +125 -1
- package/server/lib/opencode/managed-process-registry.d.ts +13 -0
- package/server/lib/opencode/managed-process-registry.js +213 -163
- package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
- package/server/lib/opencode/project-directory-runtime.js +16 -11
- package/server/lib/opencode/project-directory-runtime.test.js +32 -12
- package/server/lib/opencode/pwa-manifest-routes.js +1 -1
- package/server/lib/opencode/routes-upgrade.test.js +96 -12
- package/server/lib/opencode/routes.js +53 -5
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +10 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/opencode/theme-runtime.js +1 -1
- package/server/lib/opencode/theme-runtime.test.js +129 -0
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/quota/DOCUMENTATION.md +19 -0
- package/server/lib/quota/providers/copilot.js +26 -10
- package/server/lib/quota/providers/copilot.test.js +78 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/small-model/DOCUMENTATION.md +11 -5
- package/server/lib/small-model/call.js +64 -20
- package/server/lib/small-model/call.test.js +184 -2
- 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/server/lib/tunnels/install-help.js +2 -2
- package/server/lib/tunnels/install-help.test.js +9 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
- package/dist/assets/DiffView-D5cvbEPb.js +0 -4
- package/dist/assets/FilesView-DPU8aNPL.js +0 -17
- package/dist/assets/GitView-Ct6xWrVH.js +0 -6
- package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
- package/dist/assets/OnboardingScreen-w2VG4fWY.js +0 -1
- package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
- package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
- package/dist/assets/WalkthroughView-D9Q4lr5x.js +0 -4
- package/dist/assets/de-B_LdJwEM.js +0 -9
- package/dist/assets/es-CubfsAYV.js +0 -15
- package/dist/assets/fr-5qJM0nFS.js +0 -13
- package/dist/assets/index-BW82eK5v.css +0 -1
- package/dist/assets/index-rlLjZUM5.js +0 -7
- package/dist/assets/ja-DJYIBUlH.js +0 -15
- package/dist/assets/ko-DcUBkB7y.js +0 -15
- package/dist/assets/main-DLBxKIoX.js +0 -926
- package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
- package/dist/assets/pl-rB6BLcio.js +0 -15
- package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
- package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
- package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
- package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +0 -1
- package/dist/assets/uk-INZlFD9A.js +0 -15
- package/dist/assets/useAppFontEffects-Cll4gnsh.js +0 -7268
- package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
- package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import{f as pt,R as r,c as gr,j as s,r as en}from"./vendor-react-BUCujlKS.js";import{Q as Xi,R as Ji,S as Yi,T as Zi,ak as xr,n as Ke,u as ht,cY as Qi,C as vr,w as ea,r as wr,V as br,e as ta,cW as sa,aK as na,cX as ra,a as ia}from"./index-rlLjZUM5.js";import{f as ts,y as yr,a9 as $r,bL as aa,h as U,he as oa,f9 as la,S as Ss,B as z,V as ca,L as ua,bj as da,aa as fa,c1 as ma,hf as jr,hg as ha,gL as pa,t as G,l as Fr,aj as tn,bY as ys,cw as ga,b as xa,hh as sn,by as va,ak as Nr,hi as Cr,bZ as Sr,b_ as wa,f_ as ba,hj as ya,hk as ja,hl as Fa,bz as Wr,bA as _r,bB as Ur,bC as Kr,bD as Gr,bE as Hr,I as w,b0 as ln,aZ as cn,am as Fs,a$ as un,aY as Ns,bX as nn,al as rn,bT as kr,a4 as zt,a5 as Lt,a6 as It,bw as Na,bx as Ca,g as ks,a_ as Sa,b6 as ka}from"./useAppFontEffects-Cll4gnsh.js";import{Q as Ra,v as Va,w as Ta,x as Da,y as Pa,z as Ea}from"./runtimeEndpointReset-BDh7r8BL.js";import{c as Rr,s as Ma,C as Vr,P as an}from"./shikiHighlight-BgTPSITe.js";import{a as za}from"./vendor-codemirror-state-C9awkmn-.js";import{E as jt}from"./vendor-codemirror-view-CiLROUVV.js";import{J as La,F as Ia}from"./JsonTreeView-osju7J70.js";import{ensurePierreThemeRegistered as Tr,getResolvedShikiTheme as Aa}from"./appThemeRegistry-BK0dHKa6.js";import{V as Oa,W as Ba}from"./Virtualizer-CZlLSacm.js";import{V as $a}from"./Virtualizer-D_a8gKmg.js";import{u as js,c as Wa,e as _a}from"./scheduledTasksApi-CAGPh_gZ.js";import{D as Ua}from"./vendor-react-drawio-Ct3Q0DsD.js";import{I as Ka,u as Ga,n as Ha}from"./useInlineCommentController-DFFv0hae.js";import{b as qa}from"./CodeMirrorCommentWidgets-C2BopIs3.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-_6j2xOWl.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CpzVNWAv.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-DkQX2EBa.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-DLnGY4fs.js";import"./computeVirtualFileMetrics-Gi1d5eU1.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-CVKy_dgB.js";import"./registerCustomTheme-BBXUCRnG.js";function Dr(a){const e=pt.c(41),{containerRef:n,filePath:d,fileContent:g}=a,{t:x}=ts(),y=yr(so),b=yr(to),h=$r(),F=aa(eo),[p,C]=r.useState(null),[S,V]=r.useState(""),[j,D]=r.useState(!1),o=r.useRef(!1),L=r.useRef(null),$=r.useRef(null),[H,I]=r.useState(null);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{C(null),V(""),D(!1),o.current=!1,$.current=null,I(null)},e[0]=T):T=e[0];const k=T;let Z,X;e[1]!==n?(Z=()=>{const M=n.current;if(!M)return;const W=()=>{if(o.current)return;const ne=window.getSelection(),Se=ne?.toString().trim()??"";if(!ne||!Se||ne.rangeCount===0){k();return}const ie=ne.getRangeAt(0);if(!M.contains(ie.commonAncestorContainer)){k();return}const ae=ie.getBoundingClientRect();$.current=ie.cloneRange(),V(Se),C({x:ae.left+ae.width/2,y:ae.top-10})},se=ne=>{L.current?.contains(ne.target)||o.current&&k()};return document.addEventListener("selectionchange",W),document.addEventListener("pointerdown",se),()=>{document.removeEventListener("selectionchange",W),document.removeEventListener("pointerdown",se)}},X=[n,k],e[1]=n,e[2]=Z,e[3]=X):(Z=e[2],X=e[3]),r.useEffect(Z,X);let J;e[4]!==g?(J=M=>{const W=de=>g.slice(0,de).split(`
|
|
2
|
-
`).length,se=Za,ne=(de,Te)=>{for(const De of se(de)){const ke=g.indexOf(De,Te);if(ke>=0)return ke}return-1},Se=M.length>=8?g.indexOf(M):-1;if(Se>=0){const de=W(Se);return{start:de,end:de+M.split(`
|
|
3
|
-
`).length-1}}const ie=M.split(`
|
|
4
|
-
`).map(Ya).filter(Boolean);if(ie.length===0)return null;const ae=ne(ie[0],0);if(ae<0)return null;const ye=W(ae);if(ie.length===1)return{start:ye,end:ye};const Ve=ne(ie[ie.length-1],ae);return Ve<0?null:{start:ye,end:Math.max(ye,W(Ve))}},e[4]=g,e[5]=J):J=e[5];const P=J;let Q;e[6]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>{const M=$.current;if(!M){I(null);return}I(oa(M))},e[6]=Q):Q=e[6];const Ne=Q;let K,q;e[7]!==j?(K=()=>{if(!j)return;let M=null;const W=()=>{M===null&&(M=window.requestAnimationFrame(()=>{M=null,Ne()}))};return document.addEventListener("scroll",W,{capture:!0,passive:!0}),window.addEventListener("resize",W),()=>{M!==null&&window.cancelAnimationFrame(M),document.removeEventListener("scroll",W,{capture:!0}),window.removeEventListener("resize",W)}},q=[j,Ne],e[7]=j,e[8]=K,e[9]=q):(K=e[8],q=e[9]),r.useEffect(K,q);let ee;e[10]!==S?(ee=()=>{S&&(D(!0),o.current=!0,Ne(),window.getSelection()?.removeAllRanges())},e[10]=S,e[11]=ee):ee=e[11];const le=ee;let te;e[12]!==F||e[13]!==y||e[14]!==h||e[15]!==d||e[16]!==b||e[17]!==P||e[18]!==S?(te=M=>{const W=y??(b?"draft":null);if(!S||!W||!h){k();return}const se=P(S);F({directory:h,sessionKey:W},{source:"file-quote",fileLabel:d,startLine:se?.start??0,endLine:se?.end??0,code:S,language:"",text:M.trim()}),k(),queueMicrotask(Ja)},e[12]=F,e[13]=y,e[14]=h,e[15]=d,e[16]=b,e[17]=P,e[18]=S,e[19]=te):te=e[19];const Ce=te;if(!p)return null;let E;e[20]!==j||e[21]!==P||e[22]!==S?(E=j?P(S):null,e[20]=j,e[21]=P,e[22]=S,e[23]=E):E=e[23];const ve=E;let we;e[24]!==p.x||e[25]!==p.y?(we={left:p.x,top:p.y,transform:"translate(-50%, -100%)"},e[24]=p.x,e[25]=p.y,e[26]=we):we=e[26];let ce;e[27]!==j||e[28]!==H?(ce=j&&H&&H.length>0?gr.createPortal(s.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:H.map(Xa)}),document.body):null,e[27]=j,e[28]=H,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]!==x?(ue=j?s.jsx("div",{className:"w-[min(420px,80vw)]",children:s.jsx(Ka,{fileLabel:d,lineRange:ve?{start:ve.start,end:ve.end}:void 0,onSave:Ce,onCancel:k})}):s.jsx("div",{className:U("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:U("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:x("chat.textSelection.title.commentOnSelection"),children:x("chat.textSelection.actions.comment")})}),e[30]=j,e[31]=d,e[32]=ve,e[33]=le,e[34]=Ce,e[35]=x,e[36]=ue):ue=e[36];let be;return e[37]!==we||e[38]!==ce||e[39]!==ue?(be=gr.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 Xa(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 Ja(){la()}function Ya(a){return a.trim()}function Za(a){const e=a.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(Qa)}function Qa(a){return a.length>=8}function eo(a){return a.addDraft}function to(a){return a.newSessionDraft?.open}function so(a){return a.currentSessionId}const no=(a,e)=>{if(!e)return null;const n=Number.parseInt(a.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},Pr=(a,e)=>{const n=a.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Er=(a,e,n)=>{const d=a.state.doc.line(e),g=Math.max(1,Math.min(n,d.length+1)),x=d.from+g-1;a.dispatch({selection:za.cursor(x),effects:jt.scrollIntoView(x,{y:"center"})})};function ro({open:a,onOpenChange:e,view:n,variant:d="overlay"}){const{t:g}=ts(),[x,y]=r.useState(""),b=r.useRef(null),h=r.useRef(!1),F=r.useRef(null),p=r.useRef(null),C=r.useMemo(()=>no(x,n),[x,n]);r.useEffect(()=>{!a||!n||(h.current=!1,b.current=Pr(n,n.state.selection),y(""))},[a,n]),r.useEffect(()=>{a&&window.requestAnimationFrame(()=>{p.current?.focus(),p.current?.select()})},[a]),r.useEffect(()=>{if(!(!a||!n||!b.current)){if(C===null){const{selection:o}=b.current;n.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})});return}Er(n,C,b.current.character)}},[C,a,n]);const S=r.useCallback(()=>{if(!n||h.current||!b.current)return;const{selection:o}=b.current;n.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})})},[n]),V=r.useCallback(o=>{o||S(),e(o)},[e,S]),j=r.useCallback(()=>{!n||C===null||!b.current||(h.current=!0,Er(n,C,b.current.character),e(!1),n.focus())},[C,e,n]);r.useEffect(()=>{if(!a)return;const o=$=>{const H=F.current,I=$.target;!H||!(I instanceof Node)||H.contains(I)||V(!1)},L=$=>{$.key==="Escape"&&($.preventDefault(),V(!1))};return document.addEventListener("pointerdown",o,!0),document.addEventListener("keydown",L,!0),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("keydown",L,!0)}},[V,a,d]);const D=r.useMemo(()=>{if(!n)return g("goToLineDialog.helper.editorUnavailable");if(C===null){const o=b.current??Pr(n,n.state.selection);return g("goToLineDialog.helper.currentLineRange",{current:o.lineNumber,max:n.state.doc.lines})}return g("goToLineDialog.helper.goToLine",{line:C})},[C,g,n]);return d==="inline"?a?s.jsxs("div",{ref:F,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Ss,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:x,onChange:o=>y(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:g("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:!n||C===null,className:"h-6 px-2",children:g("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:F,className:U("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:p,type:"number",min:1,step:1,inputMode:"numeric",value:x,onChange:o=>y(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:g("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:D})]})})}function Mr(){const a=pt.c(8),[e]=en.useState(io),n=en.useRef(!1);let d;a[0]!==e?(d=h=>{if(h==null){e.cleanUp(),n.current=!1;return}n.current||(n.current=!0,e.setup(h,h.firstElementChild??void 0))},a[0]=e,a[1]=d):d=a[1];const g=d;let x,y;a[2]!==e?(x=()=>()=>{n.current=!1,e.cleanUp()},y=[e],a[2]=e,a[3]=x,a[4]=y):(x=a[3],y=a[4]),en.useLayoutEffect(x,y);let b;return a[5]!==g||a[6]!==e?(b={virtualizer:e,setScroller:g},a[5]=g,a[6]=e,a[7]=b):b=a[7],b}function io(){return new $a}function ao(a){return!(!a.autoSaveEnabled||!a.isDirty||!a.canWrite||a.isSaving||a.fileLoading||a.isNonEditableBinary||!a.selectedFilePath||a.loadedFilePath!==a.selectedFilePath)}function oo(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 lo='<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 zr(){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 co=r.forwardRef(function({xml:e,readOnly:n,className:d,onChange:g},x){const y=r.useRef(e),b=r.useRef(null),h=r.useRef(!1),[F,p]=r.useState(zr),C=r.useRef(e),S=r.useRef(e);S.current!==e&&(S.current=e,C.current=e,y.current=e);const V=r.useRef(F);V.current!==F&&(V.current=F,C.current=y.current);const j=r.useRef(null);r.useEffect(()=>{const L=()=>p(zr());L();const $=new MutationObserver(L);return $.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>$.disconnect()},[]),r.useEffect(()=>{const L=setTimeout(()=>{j.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(L)},[]),r.useImperativeHandle(x,()=>({getXml:()=>y.current}));const D=r.useCallback(()=>{!e&&!h.current&&(h.current=!0,setTimeout(()=>{b.current?.template({})},500))},[e]),o=r.useCallback(L=>{y.current=L.xml,g?.(L.xml)},[g]);return s.jsx("div",{ref:j,className:U("h-full w-full",d),children:s.jsx(Ua,{ref:b,xml:C.current||lo,autosave:!0,urlParameters:{ui:n?"simple":F?"dark":"kennedy",spin:!0,libraries:!n,chrome:n,nav:n,layers:n,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:D,onAutoSave:o},F?"dark":"light")})}),uo=a=>{const e=B(a);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const d=e.slice(0,n);return/^[A-Za-z]:$/.test(d)?`${d}/`:d},fo=a=>{const e=pt.c(8),{label:n,iconDataUrl:d}=a,[g,x]=r.useState(!1);let y;e[0]!==n?(y=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=y):y=e[1];const b=y;if(d&&!g){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>x(!0),e[2]=p):p=e[2];let C;return e[3]!==d?(C=s.jsx("img",{src:d,alt:"",className:"size-4 rounded-sm",onError:p}),e[3]=d,e[4]=C):C=e[4],C}let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=U("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=h):h=e[5];let F;return e[6]!==b?(F=s.jsx("span",{className:h,children:b}),e[6]=b,e[7]=F):F=e[7],F},mo=a=>a.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),B=a=>{if(!a)return"";const e=a.replace(/\\/g,"/"),n=e.startsWith("//");let d=e.replace(/\/+/g,"/");n&&!d.startsWith("//")&&(d=`/${d}`);const g=d==="/",x=/^[A-Za-z]:\/$/.test(d);return!g&&!x&&(d=d.replace(/\/+$/,"")),d},ho=a=>a.startsWith("/")||a.startsWith("//")||/^[A-Za-z]:\//.test(a),Ot=a=>/^[A-Za-z]:\//.test(a)?a.toLowerCase():a,Rs=(a,e)=>{const n=B(e),d=B(a);if(!n||!d)return!1;const g=Ot(n),x=Ot(d);return x===g||x.startsWith(`${g}/`)},Lr=(a,e)=>{const n=B(e),d=B(a);if(!Rs(d,n))return[];const x=d.slice(n.length).replace(/^\//,"").split("/"),y=[];let b=n;for(let h=0;h<x.length-1;h++)b=b?`${b}/${x[h]}`:x[h],y.push(b);return y},Cs=(a,e)=>{if(!e)return"";const n=B(e);if(!a||!Rs(n,a))return n;const d=n.slice(a.length);return d.startsWith("/")?d.slice(1):d},po=new Set(["node_modules"]),go=a=>{const e=pt.c(3),{status:n}=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 g=d[n];let x;return e[1]!==g?(x=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:g}}),e[1]=g,e[2]=x):x=e[2],x},Ir=a=>{const e=pt.c(11),{name:n}=a,d=r.useRef(null),g=r.useRef(null),[x,y]=r.useState(!1);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const S=d.current,V=g.current;if(!S||!V)return;const j=()=>{y(V.scrollWidth>S.clientWidth+1)};j();const D=new ResizeObserver(j);return D.observe(S),D.observe(V),()=>{D.disconnect()}},e[0]=b):b=e[0];let h;e[1]!==n?(h=[n],e[1]=n,e[2]=h):h=e[2],r.useLayoutEffect(b,h);let F;e[3]!==n?(F=s.jsx("span",{ref:g,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:n}),e[3]=n,e[4]=F):F=e[4];let p;e[5]!==n||e[6]!==x?(p=x?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:n}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:n})]}):s.jsx("span",{className:"block min-w-0 truncate",children:n}),e[5]=n,e[6]=x,e[7]=p):p=e[7];let C;return e[8]!==F||e[9]!==p?(C=s.jsxs("span",{ref:d,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[F,p]}),e[8]=F,e[9]=p,e[10]=C):C=e[10],C},xo=a=>po.has(a),vo=a=>{const e=B(a);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},wo=a=>{const n=(a instanceof Error?a.message:String(a??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Ar=a=>{const n=(a instanceof Error?a.message:String(a??"")).toLowerCase();return n.includes("file not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")},At=2e5;function bo(a){const e=a.length>400?`${a.slice(0,200)}${a.slice(-200)}`:a;let n=2166136261;for(let d=0;d<e.length;d+=1)n^=e.charCodeAt(d),n=n+((n<<1)+(n<<4)+(n<<7)+(n<<8)+(n<<24))>>>0;return`${a.length}:${n.toString(16)}`}const yo=a=>{let e=0,n=0;for(let d=0;d<a.length;d+=1)a.charCodeAt(d)===10&&(d>0&&a.charCodeAt(d-1)===13?e+=1:n+=1);return e>n?`\r
|
|
5
|
-
`:`
|
|
6
|
-
`},qr=a=>a.replace(/\r\n/g,`
|
|
7
|
-
`).replace(/\r/g,`
|
|
8
|
-
`),jo=(a,e)=>{const n=qr(a);return e===`\r
|
|
9
|
-
`?n.replace(/\n/g,`\r
|
|
10
|
-
`):n},Xr=(a,e)=>s.jsx(Fs,{filePath:a,extension:e}),Or=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},Fo=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},on=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="html"||e==="htm"},No=a=>{const e=pt.c(76),{node:n,root:d,isExpanded:g,isActive:x,isMobile:y,isBrowserClient:b,alwaysShowActions:h,status:F,badge:p,permissions:C,downloadFile:S,contextMenuPath:V,setContextMenuPath:j,rightClickMenuPath:D,setRightClickMenuPath:o,onSelect:L,onToggle:$,onRevealPath:H,onOpenDialog:I}=a,{t:T}=ts(),k=n.type==="directory",{canRename:Z,canCreateFile:X,canCreateFolder:J,canDelete:P,canReveal:Q}=C,Ne=!k&&!!S,K=Q&&!b,q=Z||X||J||P||Ne||K;let ee;e[0]!==q||e[1]!==n.path||e[2]!==o?(ee=fe=>{q&&(fe?.preventDefault(),o(n.path))},e[0]=q,e[1]=n.path,e[2]=o,e[3]=ee):ee=e[3];const le=ee;let te;e[4]!==k||e[5]!==n||e[6]!==L||e[7]!==$?(te=()=>{k?$(n.path):L(n)},e[4]=k,e[5]=n,e[6]=L,e[7]=$,e[8]=te):te=e[8];const Ce=te;let E;e[9]!==n.path||e[10]!==j||e[11]!==o?(E=fe=>{fe.stopPropagation(),o(null),j(n.path)},e[9]=n.path,e[10]=j,e[11]=o,e[12]=E):E=e[12];const ve=E;let we;e[13]!==X||e[14]!==J||e[15]!==P||e[16]!==Z||e[17]!==K||e[18]!==S||e[19]!==b||e[20]!==k||e[21]!==n||e[22]!==I||e[23]!==H||e[24]!==d||e[25]!==T?(we=fe=>{const{Item:pe,Separator:Ze}=fe;return s.jsxs(s.Fragment,{children:[Z&&s.jsxs(pe,{onClick:_=>{_.stopPropagation(),I("rename",n)},children:[s.jsx(w,{name:"edit",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.rename")]}),s.jsxs(pe,{onClick:_=>{_.stopPropagation(),ks(n.path).then(it=>{if(it.ok){G.success(T("sidebarFilesTree.toast.pathCopied"));return}G.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(w,{name:"file-copy",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.copyPath")]}),s.jsxs(pe,{onClick:_=>{_.stopPropagation();const it=Cs(d,n.path)||n.path;ks(it).then(me=>{if(me.ok){G.success(T("filesView.toast.relativePathCopied"));return}G.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(w,{name:"file-copy-2",className:"mr-2 size-4"})," ",T("filesView.tree.menu.copyRelativePath")]}),!k&&S&&s.jsxs(pe,{onClick:_=>{_.stopPropagation(),S(n.path).catch(it=>{console.error("Download failed:",it),G.error(T("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(w,{name:"download",className:"mr-2 size-4"})," ",T(b?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),K&&s.jsxs(pe,{onClick:_=>{_.stopPropagation(),H(n.path)},children:[s.jsx(w,{name:"folder-received",className:"mr-2 size-4"})," ",T(ka())]}),k&&(X||J)&&s.jsxs(s.Fragment,{children:[s.jsx(Ze,{}),X&&s.jsxs(pe,{onClick:_=>{_.stopPropagation(),I("createFile",n)},children:[s.jsx(w,{name:"file-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFile")]}),J&&s.jsxs(pe,{onClick:_=>{_.stopPropagation(),I("createFolder",n)},children:[s.jsx(w,{name:"folder-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(Ze,{}),s.jsxs(pe,{onClick:_=>{_.stopPropagation(),I("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(w,{name:"delete-bin",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.delete")]})]})]})},e[13]=X,e[14]=J,e[15]=P,e[16]=Z,e[17]=K,e[18]=S,e[19]=b,e[20]=k,e[21]=n,e[22]=I,e[23]=H,e[24]=d,e[25]=T,e[26]=we):we=e[26];const ce=we,ue=D===n.path;let be;e[27]!==n.path||e[28]!==o?(be=fe=>o(fe?n.path:null),e[27]=n.path,e[28]=o,e[29]=be):be=e[29];const M=y?void 0:le;let W;e[30]!==M?(W=s.jsx("div",{className:"group relative flex items-center",onContextMenu:M}),e[30]=M,e[31]=W):W=e[31];const se=y?void 0:le,ne=x?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Se;e[32]!==ne?(Se=U("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",ne),e[32]=ne,e[33]=Se):Se=e[33];let ie;e[34]!==k||e[35]!==g||e[36]!==n.extension||e[37]!==n.path?(ie=k?g?s.jsx(w,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(w,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):Xr(n.path,n.extension),e[34]=k,e[35]=g,e[36]=n.extension,e[37]=n.path,e[38]=ie):ie=e[38];let ae;e[39]!==n.name||e[40]!==n.path?(ae=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[39]=n.name,e[40]=n.path,e[41]=ae):ae=e[41];let ye;e[42]!==k||e[43]!==F?(ye=!k&&F&&s.jsx(go,{status:F}),e[42]=k,e[43]=F,e[44]=ye):ye=e[44];let Ve;e[45]!==p||e[46]!==k?(Ve=k&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[45]=p,e[46]=k,e[47]=Ve):Ve=e[47];let de;e[48]!==Ce||e[49]!==Se||e[50]!==ie||e[51]!==ae||e[52]!==ye||e[53]!==Ve||e[54]!==se?(de=s.jsxs("button",{type:"button",onClick:Ce,onContextMenu:se,className:Se,children:[ie,ae,ye,Ve]}),e[48]=Ce,e[49]=Se,e[50]=ie,e[51]=ae,e[52]=ye,e[53]=Ve,e[54]=se,e[55]=de):de=e[55];let Te;e[56]!==h||e[57]!==V||e[58]!==ve||e[59]!==q||e[60]!==y||e[61]!==n.path||e[62]!==ce||e[63]!==j?(Te=q&&s.jsx("div",{className:U("absolute right-1 top-1/2 -translate-y-1/2",h?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(ln,{open:V===n.path,onOpenChange:fe=>j(fe?n.path:null),children:[s.jsx(cn,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"icon",className:"size-6",onClick:ve,children:s.jsx(w,{name:"more-2-fill",className:"size-4"})})}),s.jsx(un,{align:"end",side:"bottom",onCloseAutoFocus:()=>j(null),children:ce({Item:Ns,Separator:Sa})})]})}),e[56]=h,e[57]=V,e[58]=ve,e[59]=q,e[60]=y,e[61]=n.path,e[62]=ce,e[63]=j,e[64]=Te):Te=e[64];let De;e[65]!==de||e[66]!==Te||e[67]!==W?(De=s.jsxs(Pa,{render:W,children:[de,Te]}),e[65]=de,e[66]=Te,e[67]=W,e[68]=De):De=e[68];let ke;e[69]!==ce?(ke=s.jsx(Va,{className:"min-w-[180px]",children:ce({Item:Da,Separator:Ta})}),e[69]=ce,e[70]=ke):ke=e[70];let Y;return e[71]!==De||e[72]!==ke||e[73]!==ue||e[74]!==be?(Y=s.jsxs(Ea,{open:ue,onOpenChange:be,children:[De,ke]}),e[71]=De,e[72]=ke,e[73]=ue,e[74]=be,e[75]=Y):Y=e[75],Y},Co=a=>{const e=pt.c(83),{activeDialog:n,dialogData:d,dialogInputValue:g,onDialogInputChange:x,isDialogSubmitting:y,onDialogSubmit:b,onClose:h,inputRef:F}=a,{t:p}=ts(),C=!!n;let S;e[0]!==h?(S=E=>!E&&h(),e[0]=h,e[1]=S):S=e[1];let V;e[2]!==n||e[3]!==p?(V=n==="createFile"&&p("filesView.dialog.createFile.title"),e[2]=n,e[3]=p,e[4]=V):V=e[4];let j;e[5]!==n||e[6]!==p?(j=n==="createFolder"&&p("filesView.dialog.createFolder.title"),e[5]=n,e[6]=p,e[7]=j):j=e[7];let D;e[8]!==n||e[9]!==p?(D=n==="rename"&&p("filesView.dialog.rename.title"),e[8]=n,e[9]=p,e[10]=D):D=e[10];let o;e[11]!==n||e[12]!==p?(o=n==="delete"&&p("filesView.dialog.delete.title"),e[11]=n,e[12]=p,e[13]=o):o=e[13];let L;e[14]!==V||e[15]!==j||e[16]!==D||e[17]!==o?(L=s.jsxs(Kr,{children:[V,j,D,o]}),e[14]=V,e[15]=j,e[16]=D,e[17]=o,e[18]=L):L=e[18];let $;e[19]!==n||e[20]!==d?.path||e[21]!==p?($=n==="createFile"&&p("filesView.dialog.createFile.description",{path:d?.path??p("filesView.dialog.rootFallback")}),e[19]=n,e[20]=d?.path,e[21]=p,e[22]=$):$=e[22];let H;e[23]!==n||e[24]!==d?.path||e[25]!==p?(H=n==="createFolder"&&p("filesView.dialog.createFolder.description",{path:d?.path??p("filesView.dialog.rootFallback")}),e[23]=n,e[24]=d?.path,e[25]=p,e[26]=H):H=e[26];let I;e[27]!==n||e[28]!==d?.name||e[29]!==p?(I=n==="rename"&&p("filesView.dialog.rename.description",{name:d?.name??""}),e[27]=n,e[28]=d?.name,e[29]=p,e[30]=I):I=e[30];let T;e[31]!==n||e[32]!==d?.name||e[33]!==p?(T=n==="delete"&&p("filesView.dialog.delete.description",{name:d?.name??""}),e[31]=n,e[32]=d?.name,e[33]=p,e[34]=T):T=e[34];let k;e[35]!==I||e[36]!==T||e[37]!==$||e[38]!==H?(k=s.jsxs(Gr,{children:[$,H,I,T]}),e[35]=I,e[36]=T,e[37]=$,e[38]=H,e[39]=k):k=e[39];let Z;e[40]!==k||e[41]!==L?(Z=s.jsxs(Ur,{children:[L,k]}),e[40]=k,e[41]=L,e[42]=Z):Z=e[42];let X;e[43]!==n||e[44]!==g||e[45]!==F||e[46]!==x||e[47]!==b||e[48]!==p?(X=n!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Ss,{value:g,onChange:E=>x(E.target.value),placeholder:p(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:E=>{E.key==="Enter"&&b()},ref:F})}),e[43]=n,e[44]=g,e[45]=F,e[46]=x,e[47]=b,e[48]=p,e[49]=X):X=e[49];let J;e[50]!==p?(J=p("filesView.dialog.cancel"),e[50]=p,e[51]=J):J=e[51];let P;e[52]!==y||e[53]!==h||e[54]!==J?(P=s.jsx(z,{variant:"outline",onClick:h,disabled:y,children:J}),e[52]=y,e[53]=h,e[54]=J,e[55]=P):P=e[55];const Q=n==="delete"?"destructive":"default";let Ne;e[56]!==b?(Ne=()=>{b()},e[56]=b,e[57]=Ne):Ne=e[57];let K;e[58]!==n||e[59]!==g||e[60]!==y?(K=y||n!=="delete"&&!g.trim(),e[58]=n,e[59]=g,e[60]=y,e[61]=K):K=e[61];let q;e[62]!==n||e[63]!==y||e[64]!==p?(q=y?s.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}):p(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=y,e[64]=p,e[65]=q):q=e[65];let ee;e[66]!==Q||e[67]!==Ne||e[68]!==K||e[69]!==q?(ee=s.jsx(z,{variant:Q,onClick:Ne,disabled:K,children:q}),e[66]=Q,e[67]=Ne,e[68]=K,e[69]=q,e[70]=ee):ee=e[70];let le;e[71]!==P||e[72]!==ee?(le=s.jsxs(Hr,{children:[P,ee]}),e[71]=P,e[72]=ee,e[73]=le):le=e[73];let te;e[74]!==F||e[75]!==Z||e[76]!==X||e[77]!==le?(te=s.jsxs(_r,{initialFocus:F,children:[Z,X,le]}),e[74]=F,e[75]=Z,e[76]=X,e[77]=le,e[78]=te):te=e[78];let Ce;return e[79]!==C||e[80]!==S||e[81]!==te?(Ce=s.jsx(Wr,{open:C,onOpenChange:S,children:te}),e[79]=C,e[80]=S,e[81]=te,e[82]=Ce):Ce=e[82],Ce},Br=(a,e,n)=>{const d=pt.c(8),[g,x]=r.useState(""),[y,b]=r.useState(0);let h,F;d[0]!==a||d[1]!==n||d[2]!==e?(h=()=>{if(!a){x("");return}let C=!1;x("");const S=ta(),V=sa(S);na(S).then(D=>{C||!D||(x(a),e(null))}).catch(D=>{C||(e(D instanceof Error?D.message:n),x(a))});const j=ra(()=>{C||(x(a),b(So),e(null))});return()=>{C=!0,V(),j()}},F=[a,e,n],d[0]=a,d[1]=n,d[2]=e,d[3]=h,d[4]=F):(h=d[3],F=d[4]),r.useEffect(h,F);let p;return d[5]!==y||d[6]!==g?(p={readyKey:g,nonce:y},d[5]=y,d[6]=g,d[7]=p):p=d[7],p},Hc=({mode:a="full"})=>{const{t:e}=ts(),{files:n,runtime:d}=ca(),{currentTheme:g,availableThemes:x,lightThemeId:y,darkThemeId:b}=ua(),{isMobile:h,isTablet:F,screenWidth:p}=da(),C=Xi(d.platform),S=h||F,V=Ji(),j=Yi(),D=$r()??"",o=B(D.trim()),L=a!=="editor-only",$=a==="editor-only"&&!h,H=Zi(t=>t.searchFiles),I=fa(D),[T,k]=r.useState(""),Z=ma(T,200),X=r.useRef(null),[J,P]=r.useState(!1),[Q,Ne]=r.useState(!0),[K,q]=r.useState(!1),[ee,le]=r.useState(!1),te=r.useRef(0),Ce=r.useCallback(t=>{te.current=Math.max(0,te.current+(t?1:-1))},[]),[E,ve]=r.useState("edit"),[we,ce]=r.useState("edit"),[ue,be]=r.useState("tree"),[M,W]=r.useState("edit"),[se,ne]=r.useState("preview"),[Se,ie]=r.useState(0),ae=r.useRef({}),ye=r.useRef({}),Ve=r.useRef({}),de=r.useRef({}),Te=r.useMemo(()=>x.find(t=>t.metadata.id===y)??xr(!1),[x,y]),De=r.useMemo(()=>x.find(t=>t.metadata.id===b)??xr(!0),[x,b]);r.useEffect(()=>{Tr(Te),Tr(De)},[Te,De]);const ke=r.useMemo(()=>[],[]),Y=Ke(t=>o?t.byRoot[o]?.openPaths??ke:ke),fe=Ke(t=>o?t.byRoot[o]?.selectedPath??null:null),pe=Ke(t=>o?t.byRoot[o]?.expandedPaths??ke:ke),Ze=Ke(t=>t.removeOpenPath),_=Ke(t=>t.removeOpenPathsByPrefix),it=Ke(t=>t.removeExpandedPathsByPrefix),me=Ke(t=>t.setSelectedPath),dn=Ke(t=>t.toggleExpandedPath),ss=Ke(t=>t.expandPaths),Ft=r.useCallback(t=>{const i=B(t),l=i.split("/"),u=l[l.length-1]||i,m=u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;return{name:u,path:i,type:"file",extension:m}},[]),Nt=r.useMemo(()=>Y.map(Ft),[Y,Ft]),Vs=r.useMemo(()=>{if(fe){const t=Ot(fe);if(Y.some(i=>Ot(i)===t))return fe}return Y[0]??null},[Y,fe]),c=r.useMemo(()=>Vs?Ft(Vs):null,[Vs,Ft]),Ge=c?.path??"",[,Jr]=r.useState(0);r.useEffect(()=>{if(!o||!fe)return;const t=Ot(fe);Y.some(l=>Ot(l)===t)||me(o,Y[0]??null)},[Y,o,fe,me]);const ns=!!(o&&Ge&&!Rs(Ge,o)),fn=ns?jr(Ge):void 0,gt=r.useMemo(()=>({allowOutsideWorkspace:a==="editor-only"&&ns,outsideFileGrant:fn,directory:o||void 0}),[a,ns,fn,o]),He=r.useCallback(async t=>{const i=jr(t),l=await ha(t,o,a==="editor-only");return l.outsideFileGrant&&l.outsideFileGrant!==i&&Jr(u=>u+1),l},[a,o]),Ts=r.useRef(null),[mn,Yr]=r.useState({left:!1,right:!1}),hn=r.useCallback(()=>{const t=Ts.current;t&&Yr({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),pn=r.useRef(hn);pn.current=hn,r.useEffect(()=>{const t=Ts.current;if(!t)return;const i=()=>pn.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[gn,Ds]=r.useState({}),[rs,Bt]=r.useState({}),ze=r.useRef(new Set),Le=r.useRef(new Set),Qe=r.useRef(new Map),xn=r.useRef(0),[vn,is]=r.useState([]),[Zr,as]=r.useState(!1),[R,he]=r.useState(""),{isPlaying:os,play:Qr,stop:ei}=pa(),[Be,at]=r.useState(!1),[et,ge]=r.useState(null),[ti,Ie]=r.useState(""),[Pe,oe]=r.useState(null),[re,xe]=r.useState(""),[$t,Ps]=r.useState(!1),[wn,si]=r.useState(`
|
|
11
|
-
`),ni=r.useRef(null),qe=r.useRef(null),Ee=r.useRef(null),ot=r.useRef(""),Wt=r.useRef(""),tt=r.useRef(null),bn=r.useRef(null),Xe=r.useRef(null),_t=r.useRef(0),Ct=r.useRef(null),[ls,ri]=r.useState(0),[ii,St]=r.useState("idle"),[ai,cs]=r.useState(!1),[Ut,yn]=r.useState(!1),je=ht(t=>t.autoSaveEnabled),oi=ht(t=>t.setAutoSaveEnabled),[Es,Kt]=r.useState(!1),kt=r.useRef(null),Gt=r.useRef(null),Ht=r.useRef(!1),qt=r.useRef(null),Xt=r.useRef(null),$e=r.useRef(null),us=r.useRef(null),[li,Ms]=r.useState(0),Rt=r.useRef(null),xt=r.useRef({key:"",attempts:0});r.useEffect(()=>()=>{Rt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Rt.current),Rt.current=null)},[]);const[vt,zs]=r.useState(null),[wt,ci]=r.useState(null),[lt,jn]=r.useState(""),[ui,Ls]=r.useState(!1),[di,fi]=r.useState(null),[mi,hi]=r.useState(null),[pi,Fn]=r.useState(!1),[gi,Nn]=r.useState(!1),[xi,Is]=r.useState(!1),Cn=!!n.writeFile,Sn=!!n.createDirectory,kn=!!n.rename,Rn=!!n.delete,Vn=!!n.revealPath,vi=js(t=>t.availableApps),wi=js(t=>t.isCacheStale),Tn=js(t=>t.initialize),bi=js(t=>t.loadInstalledApps);r.useEffect(()=>{Tn()},[Tn]);const yi=r.useCallback(t=>{n.revealPath&&n.revealPath(t).catch(()=>{G.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),ji=r.useCallback(async t=>{if(!c?.path||await Qi(c.path,t.id,t.appName)||await vr(c.path,t.appName))return;const u=uo(c.path)||o;u&&await vr(u,t.appName)||G.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[o,c?.path,e]),As=r.useCallback((t,i)=>{zs(t),ci(i),jn(t==="rename"&&i.name||""),Ls(!1)},[]),[A,We]=r.useState(null),Vt=r.useRef(!1),ct=r.useRef(null),[Dn,Tt]=r.useState(!1),Je=ht(t=>t.pendingFileNavigation),ds=ht(t=>t.setPendingFileNavigation),Os=ht(t=>t.pendingFileFocusPath),Bs=ht(t=>t.setPendingFileFocusPath),Pn=ht(t=>t.fileEditorKeymap),Jt=Fr(t=>t.settingsDefaultFileViewerPreview),Fi=Fr(t=>t.showMessageTTSButtons);r.useEffect(()=>{const t=()=>{Vt.current=!1,ct.current=null,Tt(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),r.useEffect(()=>()=>{qt.current!==null&&window.clearTimeout(qt.current),Xt.current!==null&&window.clearTimeout(Xt.current)},[]);const Ni=r.useCallback((t,i)=>{const l=t.split(`
|
|
12
|
-
`),u=Math.max(1,i.start),m=Math.min(l.length,i.end);return u>m?"":l.slice(u-1,m).join(`
|
|
13
|
-
`)},[]),fs=r.useRef(null),Ci=Ga({source:"file",fileLabel:c?.path??null,language:c?.path&&tn(c.path)||"text",getCodeForRange:t=>Ni(R,Ha(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:En,commentText:ms,setCommentText:Mn,editingDraftId:hs,setSelection:zn,saveComment:Ln,cancel:Yt,reset:In,startEdit:An,deleteDraft:On}=Ci;r.useEffect(()=>{We(null),In(),xe(""),Ps(!1)},[c?.path,In]),r.useEffect(()=>{zn(A)},[A,zn]),r.useEffect(()=>{if(!A&&!hs)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]")||ms.trim()||(We(null),Yt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Yt,ms,hs,A]);const Bn=r.useCallback((t,i)=>{const l=i??A??void 0;i&&We(i),Ln(t,l),We(null)},[A,Ln]),$n=r.useCallback((t,i)=>{const l=[];for(const u of i){if(!(u&&typeof u.name=="string"&&u.name.length>0)||!V&&u.name.startsWith(".")||!j&&xo(u.name))continue;const m=u.name,f=B(u.path||""),v=f?ho(f)?f:B(`${t}/${f}`):B(`${t}/${m}`),N=u.isDirectory?"directory":"file",O=N==="file"&&m.includes(".")?m.split(".").pop()?.toLowerCase():void 0;l.push({name:m,path:v,type:N,extension:O})}return mo(l)},[j,V]),Ae=r.useCallback(async t=>{const i=B(t.trim());if(!i||ze.current.has(i)||Le.current.has(i))return;Le.current=new Set(Le.current),Le.current.add(i);const l=xn.current+1;xn.current=l,Qe.current=new Map(Qe.current),Qe.current.set(i,l);const u=()=>Qe.current.get(i)===l;await(n.listDirectory?n.listDirectory(i).then(f=>f.entries.map(v=>({name:v.name,path:v.path,isDirectory:v.isDirectory}))):ea.listLocalDirectory(i).then(f=>f.map(v=>({name:v.name,path:v.path,isDirectory:v.isDirectory})))).then(f=>{if(!u())return;const v=$n(i,f);ze.current=new Set(ze.current),ze.current.add(i),Bt(N=>{if(!N[i])return N;const O={...N};return delete O[i],O}),Ds(N=>({...N,[i]:v}))}).catch(f=>{if(!u())return;const v=f instanceof Error?f.message:String(f??"");if(v==="Directory not found"&&o&&i!==o){it(o,i),Bt(N=>{if(!N[i])return N;const O={...N};return delete O[i],O});return}console.error("Failed to load files directory:",f),Bt(N=>({...N,[i]:v}))}).finally(()=>{u()&&(Qe.current=new Map(Qe.current),Qe.current.delete(i),Le.current=new Set(Le.current),Le.current.delete(i))})},[n,$n,it,o]),ps=r.useCallback(async()=>{o&&(ze.current=new Set,Le.current=new Set,Qe.current=new Map,Bt({}),Ds(t=>Object.keys(t).length===0?t:{}),await Ae(o))},[Ae,o]),Ye=r.useCallback(async t=>{if(!t){await ps();return}const i=B(t);ze.current=new Set(ze.current),ze.current.delete(i),Le.current=new Set(Le.current),Le.current.delete(i),await Ae(i)},[Ae,ps]),Wn=r.useRef(""),_n=r.useRef("");r.useEffect(()=>{if(!o)return;const t=`${o}|h${V?"1":"0"}|g${j?"1":"0"}`,i=Wn.current!==o,l=_n.current!==t;!i&&!l||(i&&(Wn.current=o,he(""),ge(null),Ie(""),oe(null),P(!1)),l&&(_n.current=t,ze.current=new Set,Le.current=new Set,Qe.current=new Map,Bt({}),Ds(u=>Object.keys(u).length===0?u:{}),Ae(o)))},[Ae,o,j,V]),r.useEffect(()=>{if(!n.listDirectory)return;const t=()=>{if(!document.hidden&&pe.length>0)for(const i of pe)Ye(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[pe,n.listDirectory,Ye]),r.useEffect(()=>{if(!n.listDirectory||pe.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of pe)Ye(i)},8e3);return()=>clearInterval(t)},[pe,n.listDirectory,Ye]);const Si=r.useCallback(async t=>{if(t?.preventDefault(),!wt||!vt)return;Ls(!0);const i=()=>{zs(null)},l=m=>{G.error(m)},u=()=>{Ls(!1)};if(vt==="createFile"){if(!lt.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),u();return}if(!n.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),u();return}const m=wt.path,f=m?`${m}/`:"",v=B(`${f}${lt.trim()}`);await n.writeFile(v,"").then(async N=>{N.success&&(G.success(e("sidebarFilesTree.toast.fileCreated")),await Ye(m)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(vt==="createFolder"){if(!lt.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),u();return}const m=wt.path,f=m?`${m}/`:"",v=B(`${f}${lt.trim()}`);await n.createDirectory(v).then(async N=>{N.success&&(G.success(e("sidebarFilesTree.toast.folderCreated")),await Ye(m)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(vt==="rename"){if(!lt.trim()){l(e("sidebarFilesTree.toast.nameRequired")),u();return}if(!n.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),u();return}const m=wt.path,f=m.split("/").slice(0,-1).join("/"),v=f?`${f}/`:"",N=B(`${v}${lt.trim()}`);await n.rename(m,N).then(async O=>{O.success&&(G.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Ye(f),o&&_(o,m),(c?.path===m||c?.path.startsWith(`${m}/`))&&(o&&me(o,null),he(""),ge(null),Ie(""),oe(null),h&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(vt==="delete"){if(!n.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),u();return}const m=wt.path,f=m.split("/").slice(0,-1).join("/");await n.delete(m).then(async v=>{v.success&&(G.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Ye(f),o&&_(o,m),(c?.path===m||c?.path.startsWith(`${m}/`))&&(o&&me(o,null),he(""),ge(null),Ie(""),oe(null),h&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}u()},[vt,wt,lt,n,Ye,h,_,o,c?.path,me,e]);r.useEffect(()=>{if(!D){is([]),as(!1);return}const t=Z.trim();if(!t){is([]),as(!1);return}let i=!1;return as(!0),H(D,t,150,{includeHidden:V,respectGitignore:!j,type:"file"}).then(l=>{if(i)return;const m=l.filter(f=>j||!vo(f.path)).map(f=>({name:f.name,path:B(f.path),type:"file",extension:f.extension,relativePath:f.relativePath}));is(m)}).catch(()=>{i||is([])}).finally(()=>{i||as(!1)}),()=>{i=!0}},[D,Z,H,V,j]);const Un=r.useCallback(async t=>{const i=await He(t);if(n.readFile)return(await n.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 wr(`/api/fs/read?${l.toString()}`);if(!u.ok){const m=await u.json().catch(()=>({error:u.statusText}));throw new Error(m.error||e("filesView.error.readFileFailed"))}return u.text()},[n,He,o,e]),ut=r.useCallback(async t=>{if(n.statFile){const i=await He(t),l=await n.statFile(t,{...i,directory:o||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[n,He,o]);r.useEffect(()=>{if(!o||!n.statFile||Y.length===0)return;let t=!1;const i=[...Y];return Promise.all(i.map(async l=>{try{const u=await He(l),m=await n.statFile?.(l,{...u,directory:o||void 0});!t&&m&&!m.isFile&&_(o,l)}catch(u){!t&&Ar(u)&&_(o,l)}})),()=>{t=!0}},[n,Y,_,He,o]);const $s=r.useMemo(()=>R.length>At?`${R.slice(0,At)}
|
|
14
|
-
|
|
15
|
-
… truncated …`:R,[R]),Me=re!==$s,Dt=r.useCallback(async()=>{if(!c||!n.writeFile)return G.error(e("filesView.toast.savingNotSupported")),!1;const t=ys(c.path)||Ut;if(!oo({selectedFilePath:c.path,loadedFilePath:Pe,fileLoading:Be,isDirty:Me,draftContent:re,fileContent:R,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):re===""&&R!==""&&Pe!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${R.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;Ps(!0);try{const i=jo(re,wn);if(!(await n.writeFile(c.path,i))?.success)return G.error(e("filesView.toast.writeFileFailed")),!1;if(he(re),o&&Rs(c.path,o)){const u=Cs(o,c.path);u&&ga.requestGitRefresh({directory:o,paths:[u]})}if(o&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(B(c.path))){const u=xa.getState().projects.find(m=>B(m.path)===B(o));if(u)try{await Wa(u.id)}catch{G.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&sn(c.path)&&(ot.current=re,Wt.current=re),ut(c.path).then(u=>{u&&(Xe.current=u)}).catch(()=>{}),!0}catch(i){return G.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Ps(!1)}},[Ut,re,R,Be,n,Me,wn,Pe,ut,o,c,e]);r.useEffect(()=>{je||(St("idle"),qe.current&&(clearTimeout(qe.current),qe.current=null))},[je]);const Kn=1500;r.useEffect(()=>{const t=!!(c&&n.writeFile),i=!!(c?.path&&(ys(c.path)||Ut));if(ao({autoSaveEnabled:je,isDirty:Me,canWrite:t,isSaving:$t,fileLoading:Be,selectedFilePath:c?.path,loadedFilePath:Pe,isNonEditableBinary:i}))return qe.current=setTimeout(()=>{Dt().then(l=>{l&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},Kn),()=>{qe.current&&(clearTimeout(qe.current),qe.current=null)}},[je,Ut,re,Be,Me,Pe,c,n.writeFile,$t,Dt]),r.useEffect(()=>{St("idle")},[c?.path]),va({save_file:t=>{if(!(t.target instanceof Node)||!us.current?.contains(t.target))return!1;qe.current&&(clearTimeout(qe.current),qe.current=null),$t||Dt().then(i=>{i&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node)||!us.current?.contains(t.target))return!1;le(!0)}});const Gn=r.useCallback(async t=>{const i=_t.current+1;_t.current=i;const l=()=>{if(!o)return!1;const N=Ke.getState().byRoot[o],O=N?.selectedPath??N?.openPaths[0]??null;return _t.current===i&&O===t.path};if(ge(null),Ie(""),oe(null),yn(!1),at(!0),await He(t.path),!l())return;const u=Nr(t.path),m=Cr(t.path),f=Sr(t.path),v=ys(t.path);if(h&&P(!0),d.isDesktop&&u&&!m){he(""),xe("");return}if(!d.isDesktop&&u&&!m){he(""),xe(""),oe(t.path),at(!1);return}if(f){he(""),xe(""),oe(t.path),at(!1);return}if(v){he(""),xe(""),oe(t.path),at(!1);return}await Un(t.path).then(N=>{if(!l())return;if(wa(N)){yn(!0),he(""),xe(""),oe(t.path);return}const O=qr(N);si(yo(N)),he(O),ot.current=O,Wt.current=O,xe(O.length>At?`${O.slice(0,At)}
|
|
16
|
-
|
|
17
|
-
… truncated …`:O),oe(t.path),ut(t.path).then(ft=>{ft&&l()&&(Xe.current=ft)}).catch(()=>{})}).catch(N=>{if(l()){if(wo(N)){if(at(!1),o&&me(o,null),ge(null),he(""),xe(""),oe(null),Xe.current=null,T.trim().length>0&&k(""),h&&P(!1),o){const ft=[...Lr(t.path,o),t.path];ft.length>0&&ss(o,ft);for(const mt of ft)ze.current.has(mt)||Ae(mt)}return}if(Ar(N)){o&&_(o,t.path),he(""),xe(""),ge(null),Xe.current=null,h&&P(!1);return}he(""),xe(""),ge(N instanceof Error?N.message:e("filesView.error.readFileFailed")),Xe.current=null}}).finally(()=>{l()&&at(!1)})},[ss,h,Ae,Un,ut,_,He,o,d.isDesktop,T,me,e]),gs=r.useCallback(async(t,i)=>{if(!o)return;const l=Lr(t,o),u=i?[...l,t]:l;u.length>0&&ss(o,u);const m=u.map(f=>{if(!ze.current.has(f))return Ae(f)}).filter(Boolean);await Promise.all(m)},[ss,Ae,o]),Hn=r.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=r.useCallback(async t=>{if(Ht.current)Ht.current=!1;else if(Me){Kt(!0),kt.current=t;return}o&&(me(o,t.path),gs(t.path,!1)),ge(null),Ie(""),he(""),ot.current="",Wt.current="",xe(""),oe(null),h&&P(!0)},[gs,Me,h,o,me]);r.useEffect(()=>{c?.path&&gs(c.path,!1)},[gs,c?.path]),r.useEffect(()=>{if(!c){_t.current+=1,Ct.current=null,at(!1);return}if(Pe===c.path||Ct.current===c.path)return;const t=c.path;Ct.current=t,Gn(c).finally(()=>{Ct.current===t&&(Ct.current=null)})},[ls,Gn,Pe,c]);const Ws=r.useRef(Me);Ws.current=Me,r.useEffect(()=>_a(({runtimeKey:t,paths:i})=>{const l=c?.path;t!==ia()||!l||Ws.current||!i.includes(B(l))||(_t.current+=1,Ct.current=null,Xe.current=null,Ie(""),ge(null),oe(null),ri(u=>u+1))}),[c?.path]),r.useEffect(()=>{if(!c?.path||Pe!==c.path)return;let t=!1;const i=window.setInterval(()=>{document.hidden||ut(c.path).then(l=>{if(t||!l)return;const u=Xe.current;if(!u||u.path!==c.path){Xe.current=l;return}const m=l.mtimeMs!==void 0&&u.mtimeMs!==void 0&&l.mtimeMs!==u.mtimeMs,f=l.size!==u.size;!m&&!f||Ws.current||(Xe.current=l,oe(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(i)}},[Pe,ut,c?.path]);const ki=r.useCallback(()=>{const t=kt.current,i=Gt.current;if(kt.current=null,Gt.current=null,Ht.current=!0,Kt(!1),xe($s),i){o&&Ze(o,i),c?.path===i&&(t?Re(t):(o&&me(o,null),he(""),ge(null),Ie(""),oe(null),h&&P(!1)));return}if(t){Re(t);return}},[$s,Re,h,Ze,o,c?.path,me]),Ri=r.useCallback(async()=>{const t=kt.current,i=Gt.current;if(!await Dt()){Ht.current=!1;return}if(kt.current=null,Gt.current=null,Ht.current=!0,Kt(!1),i){o&&Ze(o,i),c?.path===i&&(t?await Re(t):(o&&me(o,null),he(""),ge(null),Ie(""),oe(null),h&&P(!1)));return}if(t){await Re(t);return}},[Re,h,Ze,o,Dt,c?.path,me]),qn=r.useCallback(t=>{const i=c?.path===t,l=Hn(t,Nt);if(i&&Me){Kt(!0),kt.current=l,Gt.current=t;return}if(o&&Ze(o,t),!!i){if(l){Re(l);return}o&&me(o,null),he(""),ge(null),Ie(""),oe(null),h&&P(!1)}},[Hn,Re,Me,h,Nt,Ze,o,c?.path,me]),Vi=r.useCallback(t=>{if(Y.includes(t))return"open";if(I?.files){const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=I.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},[Y,I,o]),Ti=r.useCallback(t=>{if(!I?.files)return null;const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=i?`${i}/`:"";let u=0,m=0;for(const f of I.files)f.path.startsWith(l)&&((f.index==="M"||f.working_dir==="M")&&u++,(f.index==="A"||f.working_dir==="?")&&m++);return u+m>0?{modified:u,added:m}:null},[I,o]),Di=r.useCallback(async t=>{const i=B(t);o&&(dn(o,i),ze.current.has(i)||await Ae(i))},[Ae,o,dn]),Pi=r.useMemo(()=>({canRename:kn,canCreateFile:Cn,canCreateFolder:Sn,canDelete:Rn,canReveal:Vn}),[kn,Cn,Sn,Rn,Vn]);function Xn(t,i){const l=gn[t]??[];return l.map((u,m)=>{const f=u.type==="directory",v=f&&pe.includes(u.path),N=c?.path===u.path,O=m===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"}),O&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(No,{node:u,root:o,isExpanded:v,isActive:N,isMobile:h,isBrowserClient:C,alwaysShowActions:S,status:f?void 0:Vi(u.path),badge:f?Ti(u.path):void 0,permissions:Pi,downloadFile:n.downloadFile,contextMenuPath:di,setContextMenuPath:fi,rightClickMenuPath:mi,setRightClickMenuPath:hi,onSelect:Re,onToggle:Di,onRevealPath:yi,onOpenDialog:As}),f&&v&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[rs[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:rs[u.path],children:rs[u.path]}),s.jsxs(z,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ye(u.path)},children:[s.jsx(w,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,Xn(u.path,i+1)]})]},u.path)})}const Fe=!!(c?.path&&Nr(c.path)),xs=!!(c?.path&&Cr(c.path)),Oe=!!(c?.path&&Sr(c.path)),_s=!!(c?.path&&(ys(c.path)||Ut)),st=_s&&!Fe&&!Oe,Jn=r.useMemo(()=>B(Je?.path??""),[Je?.path]),Pt=!!(Je&&Jn&&Ge&&Ge===Jn&&!Be&&!et&&!Fe&&!Oe&&!st),dt=r.useMemo(()=>Cs(o,Ge),[Ge,o]),Ei=!!(c&&(!Fe||xs)&&!Oe&&!st&&R.length>0),Mi=!!(c&&dt.length>0),_e=!!(c&&!ns&&!_s&&!Fe&&n.writeFile&&R.length<=At),bt=!!(c?.path&&Or(c.path)),Zt=!!(c?.path&&Fo(c.path)),Et=!!(c?.path&&on(c.path)),Qt=!!(c?.path&&sn(c.path)),Us=!!(c&&!_s&&!Fe)&&!bt&&!Qt&&!(Et&&M==="preview"),zi=bt&&we==="edit"||Et&&M==="edit"||Zt&&ue==="text"||!bt&&!Et&&!Zt&&E==="edit",vs=r.useMemo(()=>Ge?ba(Ge):null,[Ge]),[Yn,Ks]=r.useState(null);r.useEffect(()=>{let t=!1;const i=c?.path;if(!i||vs){Ks(null);return}return Ks(null),ya(i).then(l=>{t||Ks(l)}),()=>{t=!0}},[c?.path,vs]),r.useEffect(()=>{!_e&&E==="edit"&&ve("view")},[_e,E]);const Gs="openchamber:files:md-viewer-mode",Hs="openchamber:files:html-viewer-mode",qs="openchamber:files:json-viewer-mode";r.useEffect(()=>{const t=c?.path;if(!t)return;ve(ae.current[t]??"edit");let i=Jt?"preview":"edit";try{const m=localStorage.getItem(Gs);(m==="preview"||m==="edit")&&(i=m)}catch{}ce(ye.current[t]??i);let l=Jt?"preview":"edit";try{const m=localStorage.getItem(Hs);(m==="preview"||m==="edit")&&(l=m)}catch{}W(Ve.current[t]??l),ne(de.current[t]??(Jt?"preview":"edit"));let u=Jt?"tree":"text";try{const m=localStorage.getItem(qs);(m==="tree"||m==="text")&&(u=m)}catch{}be(u)},[c?.path,Jt]);const Li=r.useCallback(t=>{const i=c?.path;i&&(ae.current[i]=t),ve(t)},[c?.path]),Ii=r.useCallback(t=>{const i=c?.path;i&&(ye.current[i]=t),ce(t);try{localStorage.setItem(Gs,t)}catch{}},[c?.path]),nt=r.useCallback(()=>we,[we]),Ai=r.useCallback(t=>{be(t);try{localStorage.setItem(qs,t)}catch{}},[]),Oi=r.useCallback(t=>{const i=c?.path;i&&(Ve.current[i]=t),W(t);try{localStorage.setItem(Hs,t)}catch{}},[c?.path]),Bi=r.useCallback(t=>{const i=c?.path;if(i&&(de.current[i]=t),Ee.current&&(clearTimeout(Ee.current),Ee.current=null),tt.current!==null&&(cancelAnimationFrame(tt.current),tt.current=null),t==="edit")xe(ot.current||R),ne(t);else{ot.current=re;const l=i;ne("edit"),tt.current=requestAnimationFrame(()=>{tt.current=requestAnimationFrame(()=>{tt.current=null,!(o&&l&&Ke.getState().byRoot[o]?.selectedPath!==l)&&(ie(u=>u+1),ne("preview"))})});return}},[re,R,o,c?.path]),Xs=r.useCallback(async(t,i)=>{if(!n.writeFile||i===Wt.current)return!1;if(!(await n.writeFile(t,i))?.success)return G.error(e("filesView.toast.writeFileFailed")),!1;ot.current=i,Wt.current=i,xe(i);const u=await ut(t).catch(()=>null);return u&&(Xe.current=u),!0},[n,ut,e]);r.useEffect(()=>()=>{Ee.current&&(clearTimeout(Ee.current),Ee.current=null),tt.current!==null&&(cancelAnimationFrame(tt.current),tt.current=null)},[se,c?.path]);const $i=r.useCallback(t=>{if(ot.current=t,!je||!c?.path||se!=="preview"||!n.writeFile)return;Ee.current&&clearTimeout(Ee.current);const i=c.path;Ee.current=setTimeout(()=>{Ee.current=null,Xs(i,t).then(l=>{l&&(cs(!0),setTimeout(()=>cs(!1),1500))}).catch(l=>{G.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},Kn)},[je,se,n.writeFile,Xs,c?.path,e]),Wi=r.useMemo(()=>Qt&&(ot.current||re)||R,[re,R,Qt]),Zn=r.useCallback(()=>M,[M]);r.useEffect(()=>{const t=l=>{const u=l?"preview":"edit",m=l?"tree":"text";for(const f of Y)ae.current[f]="edit",Or(f)&&(ye.current[f]=u),on(f)&&(Ve.current[f]=u),sn(f)&&(de.current[f]=u);ve("edit"),ce(u),W(u),ne(u),be(m);try{localStorage.setItem(Gs,u),localStorage.setItem(Hs,u),localStorage.setItem(qs,m)}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)}},[Y]),r.useEffect(()=>{if(!Je||!o)return;const t=()=>{typeof window>"u"||Rt.current===null&&(Rt.current=window.requestAnimationFrame(()=>{Rt.current=null,Ms(rt=>rt+1)}))},i=(rt,yt)=>{if(rt.state.doc.length!==yt.length)return!1;if(yt.length===0)return!0;const Qs=Math.min(128,yt.length);if(rt.state.sliceDoc(0,Qs)!==yt.slice(0,Qs))return!1;const pr=Math.max(0,yt.length-Qs);return rt.state.sliceDoc(pr,yt.length)===yt.slice(pr)},l=B(Je.path);if(!l){ds(null),xt.current={key:"",attempts:0};return}const u=`${l}:${Je.line}:${Je.column??1}`;if(xt.current.key!==u&&(xt.current={key:u,attempts:0}),c?.path!==l){if(Es)return;Re(Ft(l));return}if(Be||Pe!==l)return;if(et||Fe||Oe||st){ds(null),xt.current={key:"",attempts:0};return}if(!_e)return;if(E!=="edit"){ve("edit");return}const m=$e.current;if(!m){t();return}if(!i(m,re)){t();return}const f=Math.max(1,Math.min(Je.line,m.state.doc.lines)),v=m.state.doc.line(f),N=Math.max(1,Je.column||1),O=Math.max(0,v.to-v.from),ft=Math.min(O,N-1),mt=v.from+ft;if(!(m.state.selection.main.head===mt)||xt.current.attempts===0){xt.current.attempts+=1,m.dispatch({selection:{anchor:mt},effects:jt.scrollIntoView(mt,{y:"center"})}),m.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const rt=$e.current;rt&&(rt.dispatch({selection:{anchor:mt},effects:jt.scrollIntoView(mt,{y:"center"})}),rt.focus())}),ds(null),xt.current={key:"",attempts:0}},[_e,Es,re,li,et,Be,Fe,Oe,st,Pe,Re,Je,o,c?.path,ds,E,Ft]),r.useEffect(()=>{if(!Os||!o)return;const t=B(Os);if(!t){Bs(null);return}c?.path===t&&(Be||Pe!==t||(!et&&!Fe&&!Oe&&!st&&_e&&E==="edit"&&$e.current?.focus(),Bs(null)))},[_e,et,Be,Fe,Oe,st,Pe,Os,o,c?.path,Bs,E]);const Mt=r.useCallback(t=>{if(!h||!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 m=t.state.selection.main.head,f=t.coordsAtPos(m);if(!f)return;const v=Math.round(i.offsetTop+i.height),O=f.bottom+20-v;O<=0||(t.scrollDOM.scrollTop+=O)},[h]);r.useEffect(()=>{if(!h||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)}},[h,Mt]),ja("open_go_to_line",t=>{if(!_e||E!=="edit"||h)return!1;const i=t.target;if(i?.closest('[role="dialog"]')||!(i instanceof Node)||!us.current?.contains(i))return!1;const l=!!i?.closest(".cm-editor");if(!!i?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!l)return!1;Is(!0)});const ws=ht(t=>t.editorFontSize),Qn=r.useMemo(()=>{if(!c?.path)return[Rr(g,{fontSize:ws})];const t=tn(c.path),i=[Rr(g,t?{syntaxColors:!1,fontSize:ws}:{fontSize:ws})],l=vs??Yn;return l&&i.push(l),t&&i.push(Ma({language:t,themeName:g.metadata.id,theme:Aa(g)})),Q&&i.push(jt.lineWrapping),h&&i.push(jt.updateListener.of(u=>{u.view.hasFocus&&(u.selectionSet||u.focusChanged||u.viewportChanged||u.geometryChanged)&&window.requestAnimationFrame(()=>{Mt(u.view)})})),i},[g,c?.path,vs,Yn,Q,h,Mt,ws]),er=r.useMemo(()=>({light:Te.metadata.id,dark:De.metadata.id}),[Te.metadata.id,De.metadata.id]),es=c?.path&&Oe&&(!gt.allowOutsideWorkspace||gt.outsideFileGrant)?`${c.path}|${gt.allowOutsideWorkspace?"outside":"workspace"}|${gt.outsideFileGrant??""}|${ls}`:"",bs=c?.path&&Et&&M==="preview"&&!d.isVSCode?`${c.path}|${ls}`:"",tr=e("filesView.error.readFileFailed"),{readyKey:sr,nonce:_i}=Br(bs,ge,tr),{readyKey:nr,nonce:rr}=Br(es,ge,tr),Ui=!!(bs&&sr!==bs),ir=!!(es&&nr!==es),ar=c?.path&&Fe?xs?`data:${Fa(c.path)};utf8,${encodeURIComponent(R)}`:ti:"",or=c?.path&&Oe&&es&&nr===es?br().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:gt.allowOutsideWorkspace?"true":void 0,outsideFileGrant:gt.outsideFileGrant,directory:o||void 0}):"",lr=r.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:or,className:"h-full w-full border-0",title:t.name},rr)}),[or,rr]);r.useEffect(()=>{let t=!1,i="";return(async()=>{if(!c?.path||!Fe||xs){Ie("");return}ge(null);const u=await He(c.path);if(t)return;await(n.readFileBinary?n.readFileBinary(c.path,u).then(f=>f.dataUrl):(async()=>{const f=await wr("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:u.allowOutsideWorkspace?"true":void 0,outsideFileGrant:u.outsideFileGrant,directory:o||void 0}});if(!f.ok)throw new Error(e("filesView.error.readFileFailed"));const v=await f.blob();return i=URL.createObjectURL(v),t?(URL.revokeObjectURL(i),i="",""):i})()).then(f=>{t||(Ie(f),oe(c.path))}).catch(f=>{t||(Ie(""),ge(f instanceof Error?f.message:e("filesView.error.readFileFailed")),oe(null))}).finally(()=>{t||at(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[ls,n,Fe,xs,He,o,c?.path,gt,e]);const Ki=r.useCallback(()=>zs(null),[]),Gi=r.useMemo(()=>qa({drafts:En,editingDraftId:hs,commentText:ms,onTextChange:Mn,selection:A,isDragging:Dn,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Bn,onCancel:()=>{We(null),Yt()},onEdit:t=>{An(t),We({start:t.startLine,end:t.endLine})},onDelete:On}),[Yt,ms,On,hs,En,Bn,Dn,A,c?.path,Mn,An]),cr=Mr(),ur=Mr(),Js=Ra("unified"),Ue=R.length>At,Ys=r.useMemo(()=>Ue?bo(R):void 0,[R,Ue]),dr=r.useCallback((t,i,l)=>{const u={name:t.name,contents:i,lang:tn(t.path)||void 0},m=f=>s.jsx(Ia,{file:Ue&&Ys?{...u,cacheKey:`${t.path}:${Ys}`}:u,options:{disableFileHeader:!0,overflow:Q?"wrap":"scroll",theme:er,themeType:g.metadata.variant==="dark"?"dark":"light"},className:Ue?"block w-full":"block h-full w-full",style:Ue?void 0:{height:"100%"}},f);return Ue?s.jsx("div",{className:"h-full",children:s.jsx(Oa.Provider,{value:l.virtualizer,children:s.jsx(Ba.Provider,{value:Js,children:m(`${t.path}:${Js?"pool":"pending"}`)})})}):s.jsx("div",{className:"h-full",children:m(t.path)})},[g.metadata.variant,Ue,Ys,er,Js,Q]),fr=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!c)return null;const l=i==="docked",u=Na(Ca("save_file")),m=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",f=(v,N)=>s.jsxs(zt,{children:[s.jsx(Lt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:N})}),s.jsx(It,{side:"bottom",sideOffset:6,children:v})]});return s.jsxs("div",{className:m,children:[_e&&zi&&s.jsxs(s.Fragment,{children:[$t?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(w,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):je&&ii==="saved"&&!Me?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(w,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Me?f(e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{Dt()},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(w,{name:"save-3",className:"size-4"})})):null,f(e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>oi(!je),className:U("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(w,{name:"file-check-fill",className:"size-4"}):s.jsx(w,{name:"file-check",className:"size-4"})}))]}),s.jsxs(ln,{onOpenChange:Ce,children:[s.jsxs(zt,{children:[s.jsx(Lt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(cn,{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(w,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(un,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[vi.map(v=>s.jsxs(Ns,{className:"flex items-center gap-2",onClick:()=>{ji(v)},children:[s.jsx(fo,{label:v.label,iconDataUrl:v.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:v.label})]},v.id)),wi?s.jsxs(Ns,{className:"flex items-center gap-2",onClick:()=>{bi(!0)},children:[s.jsx(w,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Fe&&!Oe&&!st&&s.jsxs(s.Fragment,{children:[f(e(Q?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ne(!Q),className:U("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Q?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(Q?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(w,{name:"text-wrap",className:"size-4"})})),E==="edit"&&s.jsxs(s.Fragment,{children:[f(e("filesView.editor.findInFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:v=>{le(!ee),v.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(w,{name:"search",className:"size-4"})})),f(e("filesView.editor.goToLine"),s.jsx(z,{variant:"ghost",size:"sm",onClick:v=>{Is(N=>!N),v.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(w,{name:"menu-fold-2",className:"size-4"})})),s.jsx(ro,{open:xi,onOpenChange:Is,view:$e.current,variant:"inline"})]})]}),Us&&_e&&!Zt&&!Et&&s.jsx(an,{currentMode:E==="view"?"preview":"edit",onToggle:()=>{Li(E==="view"?"edit":"view")}}),bt&&f(e(nt()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ii(nt()==="preview"?"edit":"preview"),className:U("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",nt()==="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(nt()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(nt()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(w,{name:nt()==="preview"?"eye":"eye-off",className:"size-4"})})),on(c?.path??"")&&s.jsx(an,{currentMode:Zn(),onToggle:()=>{Oi(Zn()==="preview"?"edit":"preview")}}),bt&&nt()==="preview"&&Fi&&s.jsxs(zt,{children:[s.jsx(Lt,{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(os?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{os?ei():R.trim()&&Qr(R)},children:os?s.jsx(w,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(w,{name:"volume-up",className:"size-4"})})}),s.jsx(It,{sideOffset:8,children:e(os?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),Qt&&s.jsxs(s.Fragment,{children:[s.jsx(an,{currentMode:se,onToggle:()=>Bi(se==="preview"?"edit":"preview")}),se==="preview"&&s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{const v=bn.current?.getXml();if(Ee.current&&(clearTimeout(Ee.current),Ee.current=null),c?.path&&v){if(!await Xs(c.path,v))return;cs(!0),setTimeout(()=>cs(!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:ai?s.jsx(w,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(w,{name:"save-3",className:"size-4"})})]}),Zt&&f(e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ai(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(w,{name:"code-sslash",className:"size-4"}):s.jsx(w,{name:"node-tree",className:"size-4"})})),Ei&&f(e("filesView.editor.copyFileContents"),s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await ks(R)).ok?(Fn(!0),qt.current!==null&&window.clearTimeout(qt.current),qt.current=window.setTimeout(()=>{Fn(!1)},1200)):G.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:pi?s.jsx(w,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(w,{name:"clipboard",className:"size-4"})})),Mi&&f(e("filesView.editor.copyFilePathTitle",{path:dt}),s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await ks(dt)).ok?(Nn(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{Nn(!1)},1200)):G.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:dt}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:dt}),children:gi?s.jsx(w,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(w,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&f(e("filesView.editor.saveFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{const v=n.downloadFile;v&&v(c.path).catch(N=>{console.error("Download failed:",N),G.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(w,{name:"download",className:"size-4"})})),t?f(e("filesView.editor.exitFullscreen"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>q(!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(w,{name:"fullscreen-exit",className:"size-4"})})):!h&&a==="full"&&f(e(K?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>q(!K),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(K?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(K?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:K?s.jsx(w,{name:"fullscreen-exit",className:"size-4"}):s.jsx(w,{name:"fullscreen",className:"size-4"})}))]})},Zs=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Wr,{open:Es,onOpenChange:t=>{t||Kt(!0)},children:s.jsxs(_r,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Ur,{children:[s.jsx(Kr,{children:e("filesView.unsaved.title")}),s.jsx(Gr,{children:e("filesView.unsaved.description")})]}),s.jsxs(Hr,{children:[s.jsx(z,{variant:"outline",onClick:()=>{Ri()},disabled:$t,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:ki,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:U("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:[h&&J&&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(w,{name:"arrow-left-s",className:"size-5"})}),h?c?s.jsxs(ln,{children:[s.jsx(cn,{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(Fs,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ir,{name:c.name}),s.jsx(w,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(un,{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(Ns,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}i||Re(t)},className:U("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(Fs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ir,{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(),qn(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(w,{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:[mn.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"}),mn.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:Ts,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:Cs(o,t.path),className:U("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(Fs,{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(),qn(t.path)},className:U("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!S&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(w,{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:[dt&&!h?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:dt,children:dt}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:fr({layout:"docked"})})]}):null]}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(nn,{ref:cr.setScroller,outerClassName:"h-full min-w-0",className:U("h-full min-w-0",Ue&&"[overflow-anchor:none]"),children:c?Be||ir?$?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(w,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):et?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:et}):Fe?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:ar,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?lr(c):st?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")}),n.downloadFile?s.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=n.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),G.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(w,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&Qt&&se==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(co,{ref:bn,xml:Wi,onChange:$i},`${c.path}:${Se}`)}):c&&Zt&&ue==="tree"?s.jsx(rn,{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(La,{jsonString:R,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&bt&&nt()==="preview"?s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3",ref:fs,children:[s.jsx(Dr,{containerRef:fs,filePath:c.path,fileContent:R}),R.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(R.length/1024)})}),s.jsx(rn,{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(kr,{content:R,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):c&&Et&&M==="preview"?Ui?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&&sr===bs?(()=>{const t=c.path.split("/").map(i=>encodeURIComponent(i)).join("/");return br().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?R.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):R})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},_i)}):c&&Us&&E==="view"?dr(c,Ue?R:re,cr):s.jsxs("div",{className:U("relative h-full",Pt&&"overflow-hidden"),ref:us,children:[s.jsx("div",{className:U("h-full",Pt&&"invisible"),children:s.jsx(Vr,{value:re,onChange:xe,readOnly:!_e,vimMode:Pn==="vim",extensions:Qn,className:"h-full",blockWidgets:Gi,onViewReady:t=>{$e.current=t,Ms(i=>i+1),window.requestAnimationFrame(()=>{Mt(t)})},onViewDestroy:()=>{$e.current&&($e.current=null),Ms(t=>t+1)},enableSearch:!0,searchOpen:ee,onSearchOpenChange:le,highlightLines:A?{start:Math.min(A.start,A.end),end:Math.max(A.start,A.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(A&&!l.shiftKey&&Math.min(A.start,A.end)===u&&Math.max(A.start,A.end)===u)return We(null),Yt(),Vt.current=!1,ct.current=null,Tt(!1),!0;if(h&&A&&!l.shiftKey){const m=Math.min(A.start,A.end,u),f=Math.max(A.start,A.end,u);return We({start:m,end:f}),Vt.current=!1,ct.current=null,Tt(!1),!0}if(Vt.current=!0,ct.current=u,Tt(!0),A&&l.shiftKey){const m=Math.min(A.start,u),f=Math.max(A.end,u);We({start:m,end:f})}else We({start:u,end:u});return!0},mouseover:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Vt.current||ct.current===null)return!1;const u=t.state.doc.lineAt(i.from).number,m=Math.min(ct.current,u),f=Math.max(ct.current,u);return We({start:m,end:f}),Tt(!0),!1},mouseup:()=>(Vt.current=!1,ct.current=null,Tt(!1),!1)}}})}),Pt&&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(w,{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")})})})]}),Hi=!!(o&&gn[o]),mr=o?rs[o]:null,hr=s.jsxs("section",{className:U("flex min-h-0 flex-col overflow-hidden",h?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:U("flex flex-col gap-2 py-2",h?"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(w,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Ss,{ref:X,value:T,onChange:t=>k(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),T.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:()=>{k(""),X.current?.focus()},children:s.jsx(w,{name:"close",className:"size-4"})})]}),s.jsxs(zt,{children:[s.jsx(Lt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>As("createFile",{path:D,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(w,{name:"file-add",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(zt,{children:[s.jsx(Lt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>As("createFolder",{path:D,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(w,{name:"folder-add",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(zt,{children:[s.jsx(Lt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{ps()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(w,{name:"refresh",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(nn,{outerClassName:"flex-1 min-h-0",className:U("py-2",h?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Zr?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(w,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):vn.length>0?vn.map(t=>{const i=c?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Re(t)},className:U("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:[Xr(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)}):mr?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:mr}),s.jsxs(z,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ps()},children:[s.jsx(w,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):Hi?Xn(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),qi=a==="full"&&K&&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:fr({exitFullscreenOnly:!0})}),s.jsx(nn,{ref:ur.setScroller,outerClassName:"h-full min-w-0",className:U("h-full min-w-0",Ue&&"[overflow-anchor:none]"),children:Be||ir?$?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(w,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):et?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:et}):Fe?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:ar,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Oe?lr(c):st?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")}),n.downloadFile?s.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=n.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),G.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(w,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):bt&&nt()==="preview"?s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4",ref:fs,children:[c?s.jsx(Dr,{containerRef:fs,filePath:c.path,fileContent:R}):null,R.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(R.length/1024)})}),s.jsx(rn,{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(kr,{content:R,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):Us&&E==="view"?dr(c,Ue?R:re,ur):s.jsxs("div",{className:U("relative h-full",Pt&&"overflow-hidden"),children:[s.jsx("div",{className:U("h-full",Pt&&"invisible"),children:s.jsx(Vr,{value:re,onChange:xe,readOnly:!_e,vimMode:Pn==="vim",extensions:Qn,className:"h-full",onViewReady:t=>{$e.current=t,window.requestAnimationFrame(()=>{Mt(t)})},onViewDestroy:()=>{$e.current&&($e.current=null)}})}),Pt&&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(w,{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(Co,{activeDialog:vt,dialogData:wt,dialogInputValue:lt,onDialogInputChange:jn,isDialogSubmitting:ui,onDialogSubmit:Si,onClose:Ki,inputRef:ni}),qi,h?J?Zs:hr: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:Zs})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[p>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:hr}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Zs})]})]})};function So(a){return a+1}export{Hc 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 Ze,_ as Rt,hG as Pn,cP as Kt,c8 as Jt,t as b,I as T,b0 as Ps,aZ as Fs,cN as br,a$ as Rs,cr as Bs,cs as Ds,ct as Ms,cu as Es,cm as qt,cn as Yt,B as W,hH as Fn,hI as Rn,bz as ht,bA as gt,bB as ft,bC as pt,bD as yt,S as ir,a4 as Qt,a5 as Xt,a6 as Zt,hJ as Bn,h as Ve,hK as Dn,hL as Mn,hM as En,hN as Tn,aY as An,aj as Ln,bK as On,hO as zn,hP as Gn,hQ as _n,hR as $n,hS as Hn,hT as Wn,hU as Un,bX as jr,bN as Kn,bO as Jn,bP as qn,bQ as Yn,bR as Qn,hV as Xn,bU as Zn,bE as Is,eI as ea,V as ta,a9 as sa,ab as ra,aa as na,bp as aa,hW as ia,bV as oa,hX as la,hY as ca,ac as da,hZ as ua,ad as ma,bI as ha,hz as ga,l as fa,bW as pa,g as xa,cw as wa,ai as ya,$ as ba,h_ as ja,h$ as Ss}from"./useAppFontEffects-Cll4gnsh.js";import{a as va,b as Ca,d as Na}from"./main-DLBxKIoX.js";import{s as Sa,q as ka,p as Va,I as Ia,R as Pa}from"./runtimeEndpointReset-BDh7r8BL.js";import{u as or}from"./vendor-zustand-BAGL70zf.js";import{r as Fa,u as Pt}from"./index-rlLjZUM5.js";import{C as Ra,a as Ba}from"./CommitSection-HJeMUAWb.js";import{P as Da}from"./PierreDiffViewer-CGoI2v0q.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-base-ui-_6j2xOWl.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CpzVNWAv.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-DkQX2EBa.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"./SessionSwitcherDropdown-CJTrc8K7.js";import"./scheduledTasksApi-CAGPh_gZ.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./web-components-DLnGY4fs.js";import"./computeVirtualFileMetrics-Gi1d5eU1.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-CN_BctrR.js";import"./isDiffPlainText-pH9kAJQH.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-DFFv0hae.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";const vr="gitmojiCache",Ma=1e3*60*60*24*7,Cr="1",Ea="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(vr);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}},Ta=i=>{if(!(typeof window>"u"))try{const e={gitmojis:i,fetchedAt:Date.now(),version:Cr};window.localStorage.setItem(vr,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(Ea);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 Ta(r),Ft.forEach(j=>j(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},Aa=i=>{const[e,n]=l.useState(()=>i?ks()?.gitmojis??[]:[]),[r,j]=l.useState(!1),h=l.useRef(i);h.current=i,l.useEffect(()=>{if(!i){Ft.delete(n),n([]),j(!1);return}const f=ks();if(f&&(n(f.gitmojis),lr(f)))return;Ft.add(n),j(!0);let m=!1;return cr().finally(()=>{!m&&h.current&&j(!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 La(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:j,refreshKey:h,onRefresh:p,showHeader:f=!0})=>{const{t:m}=et(),x=Ze(u=>u.currentSessionId),[E,y]=be.useState(!1),[C,I]=be.useState(""),D=be.useRef(null),O=be.useMemo(()=>Rt(r,C,u=>[u]),[r,C]),[v,w]=be.useState(j);be.useEffect(()=>{w(j)},[j]),be.useEffect(()=>{if(E){const u=setTimeout(()=>{D.current?.focus()},0);return()=>clearTimeout(u)}},[E]);const B=!!(i&&e&&v&&v!=="HEAD"&&e!==v),[S,R]=be.useState({kind:"idle"}),[V,P]=be.useState(!1),[g,H]=be.useState([]),A=be.useMemo(()=>x?`openchamber.integrate.conflict:${x}`:null,[x]);be.useEffect(()=>{if(!A||typeof window>"u")return;const u=window.localStorage.getItem(A);if(!u)return;let d=!1;try{const F=JSON.parse(u);if(!F?.tempWorktreePath||F.repoRoot!==i){window.localStorage.removeItem(A);return}(async()=>{const L=await Oa(F.tempWorktreePath).catch(()=>!1);if(d)return;if(!L){window.localStorage.removeItem(A);return}const q=await La(F.tempWorktreePath).catch(()=>null);d||q&&R({kind:"conflict",state:F,details:q})})()}catch{window.localStorage.removeItem(A)}return()=>{d=!0}},[A,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:v});if(u)return;if(R({kind:"ready",plan:d}),d.commits.length>0){const L=d.commits.slice(-50).reverse(),q=await Pn(i,L);u||(H(q),P(!1))}else u||(H([]),P(!1))}catch{u||R({kind:"idle"})}})(),()=>{u=!0}},[B,i,e,v,h]);const k=be.useCallback(u=>{x&&Ze.getState().setWorktreeMetadata(x,{...n,createdFromBranch:u})},[x,n]),M=Ze(u=>u.openNewSessionDraft),U=be.useCallback(async u=>{const d=await Kt("git.integrate.cherrypick.resolve.visible",{current_commit:u.state.currentCommit,target_branch:u.state.targetBranch}),F=await Kt("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}),L=`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:L}},[]),$=Jt(u=>u.setPendingInputText),_=Jt(u=>u.setPendingSyntheticParts),Y=be.useCallback(async(u,d)=>{const F=await U(u);if(d){M({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,M,$,_,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}),A&&typeof window<"u"&&window.localStorage.setItem(A,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:v}).catch(()=>null);R(F?{kind:"ready",plan:F}:{kind:"idle"})}}},[S,p,i,e,v,A,m]),Z=be.useCallback(async()=>{if(S.kind==="conflict")try{await Ga(S.state),b.message(m("gitView.integrate.cherryPickAbortedToast")),A&&typeof window<"u"&&window.localStorage.removeItem(A)}finally{const u=await It({repoRoot:i,sourceBranch:e,targetBranch:v}).catch(()=>null);R(u?{kind:"ready",plan:u}:{kind:"idle"})}},[S,i,e,v,A,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:v}).catch(()=>null);R(d?{kind:"ready",plan:d}:{kind:"idle"}),A&&typeof window<"u"&&window.localStorage.removeItem(A),p?.();return}u.kind==="conflict"&&(R({kind:"conflict",state:u.state,details:u.details}),A&&typeof window<"u"&&window.localStorage.setItem(A,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,v,p,A,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," → ",v]})]}),t.jsx("div",{className:"flex-1"}),t.jsxs(Ps,{open:E,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:v}),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:D,placeholder:m("gitView.branch.searchPlaceholder"),value:C,onValueChange:I,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(Es,{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),k(u),y(!1),I("")},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(V?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),t.jsxs("div",{className:"space-y-1",children:[(V?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:()=>{Z()},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:j=!1,uncommittedFileCount:h,onChanged:p})=>{const{t:f}=et(),[m,x]=l.useState([]),[E,y]=l.useState(!1),[C,I]=l.useState(""),[D,O]=l.useState(""),[v,w]=l.useState(null),[B,S]=l.useState({}),R=l.useCallback(async()=>{if(n){y(!0);try{const k=await Fn(n);x(k.stashes),S({})}catch(k){b.error(k instanceof Error?k.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 k=!1;const M=m.map(U=>U.ref);return Rn(n,M).then(U=>{k||S(U.counts)}).catch(()=>{}),()=>{k=!0}},[n,i,m]);const V=l.useMemo(()=>Rt(m,C,k=>[k.message,k.ref,k.relativeTime]),[C,m]),P=l.useCallback(async k=>{await R(),await p?.(k)},[R,p]),g=async()=>{if(!(!n||v)){w("create");try{const k=await Bn(n,{message:D.trim()||void 0});k.created?(b.success(f("gitView.stashes.toast.created")),O("")):b.info(f("gitView.stashes.toast.noChanges")),await P({affectsIndex:!!(k.created&&j)})}catch(k){b.error(k instanceof Error?k.message:f("gitView.stashes.toast.createFailed"))}finally{w(null)}}},H=async(k,M)=>{if(!(!n||v)&&!(M==="drop"&&!window.confirm(f("gitView.stashes.confirm.drop",{ref:k.ref})))){w(`${M}:${k.ref}`);try{M==="apply"&&await Dn(n,{ref:k.ref}),M==="pop"&&await Mn(n,{ref:k.ref}),M==="drop"&&await En(n,{ref:k.ref});const U=M==="apply"?"gitView.stashes.toast.applySuccess":M==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";b.success(f(U)),await P({affectsIndex:M!=="drop"})}catch(U){const $=M==="apply"?"gitView.stashes.toast.applyFailed":M==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";b.error(U instanceof Error?U.message:f($)),await P({affectsIndex:M!=="drop"})}finally{w(null)}}},A=v!==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:D,onChange:k=>O(k.target.value),placeholder:f("gitView.stashes.messagePlaceholder"),disabled:A||!r,className:"flex-1"}),t.jsxs(W,{onClick:g,disabled:!r||A||!n,children:[v==="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:C,onChange:k=>I(k.target.value),placeholder:f("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:E?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"})}):V.length===0?t.jsx("div",{className:"py-8 text-center text-muted-foreground",children:f(C?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):V.map((k,M)=>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:k.message||f("gitView.stashes.untitled")}),t.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[t.jsxs(Qt,{children:[t.jsx(Xt,{asChild:!0,children:t.jsx("span",{children:M===0&&!C.trim()?f("gitView.stashes.latestLabel"):f("gitView.stashes.itemNumber",{number:M+1})})}),t.jsx(Zt,{sideOffset:6,children:k.ref})]})," · ",k.relativeTime," · ",typeof B[k.ref]=="number"?f("gitView.stashes.fileCount",{count:B[k.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:v===`apply:${k.ref}`,onClick:()=>H(k,"apply"),disabled:A,children:t.jsx(T,{name:"inbox-unarchive",className:"size-4"})}),t.jsx(Vs,{label:f("gitView.stashes.actions.pop"),loading:v===`pop:${k.ref}`,onClick:()=>H(k,"pop"),disabled:A,children:t.jsx(T,{name:"inbox-unarchive-fill",className:"size-4"})}),t.jsx(Vs,{label:f("gitView.stashes.actions.drop"),loading:v===`drop:${k.ref}`,onClick:()=>H(k,"drop"),disabled:A,destructive:!0,children:t.jsx(T,{name:"delete-bin",className:"size-4"})})]})]},k.ref))})]})})},Vs=i=>{const e=Ct.c(17),{label:n,loading:r,disabled:j,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 E;e[0]!==x?(E=Ve("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",x),e[0]=x,e[1]=E):E=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 C;e[5]!==j||e[6]!==n||e[7]!==p||e[8]!==m||e[9]!==E||e[10]!==y?(C=t.jsx(Xt,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":n,"aria-busy":m,className:E,onClick:p,disabled:j,children:y})}),e[5]=j,e[6]=n,e[7]=p,e[8]=m,e[9]=E,e[10]=y,e[11]=C):C=e[11];let I;e[12]!==n?(I=t.jsx(Zt,{sideOffset:6,children:n}),e[12]=n,e[13]=I):I=e[13];let D;return e[14]!==C||e[15]!==I?(D=t.jsxs(Qt,{children:[C,I]}),e[14]=C,e[15]=I,e[16]=D):D=e[16],D},Wa=i=>{const e=Ct.c(16),{onOpenStashes:n}=i,{t:r}=et();let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=t.jsx(T,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=j):j=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 E;return e[12]!==p||e[13]!==m||e[14]!==x?(E=t.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[j,p,m,x]}),e[12]=p,e[13]=m,e[14]=x,e[15]=E):E=e[15],E},mt=8,Ua=i=>{const e=Ct.c(18),{laned:n,totalLanes:r,isExpanded:j}=i,{lane:h,color:p,connectors:f}=n,x=Math.max(r,h+1)*mt+mt/2,E=l.useRef(null),y=l.useRef(null);let C;e[0]!==p||e[1]!==f||e[2]!==h||e[3]!==x?(C=()=>{const w=E.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 V=B.getContext("2d");if(!V)return;V.scale(R,R),V.clearRect(0,0,x,S);const P=S/2,g=h*mt+mt/2,H=getComputedStyle(B),A=H.getPropertyValue("--surface-muted-foreground").trim()||H.color,k=$=>{if(!$.startsWith("var("))return $;const _=$.slice(4,-1).trim();return H.getPropertyValue(_).trim()||A},M=[...f].sort(Ja);for(const $ of M){const _=$.fromLane*mt+mt/2,Y=$.toLane*mt+mt/2,ee=$.type==="passing"?.72:$.type==="branch-out"||$.type==="merge-in"?.95:1;V.beginPath(),V.strokeStyle=k($.color),V.globalAlpha=ee,V.lineWidth=1.25,V.lineCap="round";e:switch($.type){case"passing":case"commit-lane":{V.moveTo(_,0),V.lineTo(_,S);break e}case"top-stub":{V.moveTo(_,0),V.lineTo(_,P);break e}case"bottom-stub":{V.moveTo(_,P),V.lineTo(_,S);break e}case"branch-out":{const Z=(P+S)/2;V.moveTo(g,P),V.bezierCurveTo(g,Z,Y,Z,Y,S);break e}case"merge-in":{const Z=P/2;V.moveTo(_,0),V.bezierCurveTo(_,Z,g,Z,g,P);break e}default:continue}V.stroke(),V.globalAlpha=1}const U=H.getPropertyValue("--background").trim()||H.getPropertyValue("--surface-background").trim();V.beginPath(),V.arc(g,P,4,0,Math.PI*2),V.fillStyle=k(p),V.fill(),V.beginPath(),V.arc(g,P,5,0,Math.PI*2),V.strokeStyle=U||A,V.lineWidth=2,V.stroke()},e[0]=p,e[1]=f,e[2]=h,e[3]=x,e[4]=C):C=e[4];let I;e[5]!==p||e[6]!==f||e[7]!==j||e[8]!==h||e[9]!==n||e[10]!==r||e[11]!==x?(I=[n,h,p,f,r,j,x],e[5]=p,e[6]=f,e[7]=j,e[8]=h,e[9]=n,e[10]=r,e[11]=x,e[12]=I):I=e[12],l.useLayoutEffect(C,I);let D;e[13]!==x?(D={width:x,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=x,e[14]=D):D=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 v;return e[16]!==D?(v=t.jsx("div",{ref:E,style:D,children:O}),e[16]=D,e[17]=v):v=e[17],v};function Ka(i){return i==="branch-out"||i==="merge-in"}function Ja(i,e){const n=Ka;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 j=0;for(const h of i.values())j+=gr(h);if(j<=hr)return i}const e=Array.from(i.entries()).reverse(),n=new Map;let r=0;for(const[j,h]of e){if(n.size>=mr)continue;const p=gr(h);r+p>hr&&n.size>0||(n.set(j,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:j,onToggle:h,files:p,isLoadingFiles:f,onCopyHash:m,directory:x,onConflict:E,onActionSuccess:y})=>{const{t:C}=et(),I=Pt(d=>d.timeFormatPreference),D=e==="graph",[O,v]=l.useState(null),[w,B]=l.useState(!1),[S,R]=l.useState(""),[V,P]=l.useState(null),[g,H]=l.useState(new Set),[A,k]=l.useState(new Map),[M,U]=l.useState(new Set),$=async()=>{if(x){v("checkout");try{await Un(x,i.hash),b.success(C("gitView.history.actions.detachedHead")),y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},_=async()=>{if(!(!x||!S.trim())){v("createBranch");try{await zn(x,S.trim(),i.hash),B(!1),R(""),y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},Y=async()=>{if(x){v("cherryPick");try{const d=await Wn(x,i.hash);d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"cherry-pick"}):y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},ee=async()=>{if(x){v("revert");try{const d=await Hn(x,i.hash);d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"revert"}):y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},Z=async(d,F=!1)=>{if(!(!x||O!==null)){v("reset");try{await Gn(x,i.hash,d,F),y?.()}catch(L){b.error(String(L.message))}finally{v(null)}}},oe=async()=>{if(!V)return;const d=V;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 Z("soft");case"resetMixed":return Z("mixed");case"resetHard":return Z("hard",!0)}},de=async()=>{if(x){v("merge");try{const d=await $n(x,{branch:i.hash});d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"merge"}):y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},Q=async()=>{if(x){v("rebase");try{const d=await _n(x,{onto:i.hash});d.conflict?E?.({conflict:!0,conflictFiles:d.conflictFiles,operation:"rebase"}):y?.()}catch(d){b.error(String(d.message))}finally{v(null)}}},te=l.useCallback(async d=>{const F=d.path;if(!x){k(L=>new Map(L).set(F,"error"));return}k(L=>fr(new Map(L).set(F,"loading")));try{const L=Tn(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([L,q]);k(se=>fr(new Map(se).set(F,ie)))}catch{k(L=>new Map(L).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 L=A.get(F);if(g.has(F)&&L&&L!=="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}),!(L&&L!=="error"||d.insertions+d.deletions>ur&&!M.has(F))&&await te(d)},[A,M,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",D?"hover:bg-[var(--interactive-hover)]/40":j?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[D&&n&&r!==void 0?t.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:t.jsx(Ua,{laned:n,totalLanes:r,isExpanded:j})}):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:[D?(()=>{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,I),children:pr(i.date,I)})]}),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(Xt,{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(Zt,{sideOffset:8,children:C("gitView.history.copySha")})]})]})]})]}),j&&t.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[D&&V?t.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:C(`gitView.history.actions.${V}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,C("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:C("gitView.history.actions.cancelButton")})]}):D?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:C("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:C("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,C("gitView.history.actions.createBranchConfirm")]})]}):t.jsx(W,{variant:"outline",size:"xs",className:"h-6",onClick:d=>{d.stopPropagation(),B(!0)},children:C("gitView.history.actions.createBranch")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("cherryPick")},children:C("gitView.history.actions.cherryPick")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("revert")},children:C("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,C("gitView.history.actions.reset")]})}),t.jsx(Rs,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(d=>t.jsx(An,{disabled:O!==null,onSelect:F=>{F.stopPropagation(),P(`reset${d.charAt(0).toUpperCase()+d.slice(1)}`)},children:C(`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:C("gitView.history.actions.merge")}),t.jsx(W,{variant:"outline",size:"xs",className:"h-6",disabled:O!==null,onClick:d=>{d.stopPropagation(),P("rebase")},children:C("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:C("gitView.history.loadingFiles")})]}):p.length===0?t.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:C("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:C("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:C("gitView.history.renamedNoDiff")}):d.isBinary?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.binaryNoDiff")}):(()=>{const F=d.insertions+d.deletions;if(!M.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:C("gitView.history.largeDiffTitle",{count:F})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:C("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:C("gitView.history.renderDiffAnyway")})]});const L=A.get(d.path);return L==="loading"||L===void 0?t.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:C("gitView.history.loadingDiff")}):L==="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:C("gitView.history.diffError")}):t.jsx(Da,{original:L.original,modified:L.modified,language:Ln(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 Xa(i){if(i.length===0)return[];const e=[],n=[];for(let r=0;r<i.length;r++){const j=i[r],h=[];for(let I=0;I<e.length;I++)e[I]===j.hash&&h.push(I);let p=h.length>0?h[0]:-1;if(p===-1){const I=e.indexOf(null);I!==-1?p=I:(p=e.length,e.push(null))}const f=h.slice(1),m=Ut(p),x=e[p]===j.hash,E=j.parents.length>0;E?e[p]=j.parents[0]:e[p]=null;const y=[];for(let I=1;I<j.parents.length;I++){const D=j.parents[I],O=e.indexOf(D);if(O!==-1)y.push(O);else{const v=e.indexOf(null),w=v!==-1?v:e.length;e[w]=D,w===e.length&&e.push(D),y.push(w)}}const C=[];x&&E?C.push({fromLane:p,toLane:p,color:m,type:"commit-lane"}):x&&!E?C.push({fromLane:p,toLane:p,color:m,type:"top-stub"}):!x&&E&&C.push({fromLane:p,toLane:p,color:m,type:"bottom-stub"});for(const I of f)C.push({fromLane:I,toLane:p,color:Ut(I),type:"merge-in"}),e[I]=null;for(const I of y)C.push({fromLane:p,toLane:I,color:Ut(I),type:"branch-out"});for(let I=0;I<e.length;I++)e[I]!==null&&I!==p&&(y.includes(I)||C.push({fromLane:I,toLane:I,color:Ut(I),type:"passing"}));n.push({commit:j,lane:p,color:m,connectors:C})}return n}const Za=[{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:j,logMaxCount:h,onLogMaxCountChange:p,expandedCommitHashes:f,onToggleCommit:m,commitFilesMap:x,loadingCommitHashes:E,onCopyHash:y,directory:C,showHeader:I,contentMaxHeightClassName:D,branchDivider:O,onConflict:v,onActionSuccess:w}=i,B=n===void 0?"history":n,S=I===void 0?!0:I,R=D===void 0?"max-h-[50vh]":D,V=O===void 0?null:O,{t:P}=et(),[g,H]=l.useState(!0),A=B==="graph";let k;e[0]!==A||e[1]!==r?(k=A&&r?Xa(r.all):[],e[0]=A,e[1]=r,e[2]=k):k=e[2];const M=k;let U;e[3]!==M?(U=Math.max(1,...M.map(ti)),e[3]=M,e[4]=U):U=e[4];const $=U;let _;e[5]!==M?(_=new Map(M.map(si)),e[5]=M,e[6]=_):_=e[6];const Y=_;if(!r)return null;const ee=V!==null&&V.insertBeforeIndex>0&&V.insertBeforeIndex<r.all.length,Z=V!==null&&V.insertBeforeIndex===r.all.length,oe=ee||Z;let de;e[7]!==V||e[8]!==ee||e[9]!==Z||e[10]!==r.all?(de=ee?r.all.slice(0,V.insertBeforeIndex):Z?r.all:[],e[7]=V,e[8]=ee,e[9]=Z,e[10]=r.all,e[11]=de):de=e[11];const Q=de;let te;if(e[12]!==V||e[13]!==x||e[14]!==R||e[15]!==C||e[16]!==f||e[17]!==ee||e[18]!==oe||e[19]!==A||e[20]!==j||e[21]!==Y||e[22]!==E||e[23]!==r.all||e[24]!==h||e[25]!==$||e[26]!==B||e[27]!==w||e[28]!==v||e[29]!==y||e[30]!==p||e[31]!==m||e[32]!==P||e[33]!==Q){const re=ee?r.all.slice(V.insertBeforeIndex):[];let le;e[35]!==V?.direction?(le=V?.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]=V?.direction,e[36]=le):le=e[36];const je=le;let pe;e[37]!==x||e[38]!==C||e[39]!==f||e[40]!==A||e[41]!==Y||e[42]!==E||e[43]!==$||e[44]!==B||e[45]!==w||e[46]!==v||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:A?Y.get(ce.hash):void 0,totalLanes:A?$:void 0,isExpanded:f.has(ce.hash),onToggle:()=>m(ce.hash),files:x.get(ce.hash)??[],isLoadingFiles:E.has(ce.hash),onCopyHash:y,directory:C,onConflict:v,onActionSuccess:w},ce.hash))}),e[37]=x,e[38]=C,e[39]=f,e[40]=A,e[41]=Y,e[42]=E,e[43]=$,e[44]=B,e[45]=w,e[46]=v,e[47]=y,e[48]=m,e[49]=pe):pe=e[49];const ue=pe;let me;e[50]!==j||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:j,className:"px-3 text-muted-foreground hover:text-foreground",children:j?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]=j,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(jr,{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&&V?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:V.branchName,children:V.branchName}),je]}),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]=V,e[13]=x,e[14]=R,e[15]=C,e[16]=f,e[17]=ee,e[18]=oe,e[19]=A,e[20]=j,e[21]=Y,e[22]=E,e[23]=r.all,e[24]=h,e[25]=$,e[26]=B,e[27]=w,e[28]=v,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 L;e[64]!==j||e[65]!==g||e[66]!==h||e[67]!==p||e[68]!==P?(L=g&&t.jsx("div",{onClick:ri,onPointerDown:ni,children:t.jsxs(Kn,{value:String(h),onValueChange:re=>p(Number(re)),disabled:j,children:[t.jsx(Jn,{size:"sm",className:"w-auto",disabled:j,children:t.jsx(qn,{placeholder:P("gitView.history.commitsPlaceholder")})}),t.jsx(Yn,{children:Za.map(re=>t.jsx(Qn,{value:String(re.value),children:P(re.labelKey)},re.value))})]})}),e[64]=j,e[65]=g,e[66]=h,e[67]=p,e[68]=P,e[69]=L):L=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]!==L||e[73]!==q?(ie=t.jsxs("div",{className:"flex items-center gap-2",children:[L,q]}),e[72]=L,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:j,directory:h,operation:p,onAbort:f,onClearState:m}=i;let x;e[0]!==j?(x=j===void 0?[]:j,e[0]=j,e[1]=x):x=e[1];const E=x,{t:y}=et(),C=Ze(ii),I=Ze(oi),D=Jt(li),O=Jt(ci),[v,w]=l.useState(!1),[B,S]=l.useState(null),[R,V]=l.useState(null);let P,g;e[2]!==h||e[3]!==n||e[4]!==y?(P=()=>{!n||!h||(w(!0),V(null),S(null),Xn(h).then(J=>{S(J)}).catch(J=>{const xe=J instanceof Error?J.message:y("gitView.conflict.loadFailed");V(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 J=p==="merge"?"merge":"rebase",xe=B.headInfo||(p==="merge"?"MERGE_HEAD":"REBASE_HEAD"),Ee=p==="merge"?"git commit --no-edit":"git rebase --continue",Ge=await Kt("git.conflict.resolve.visible",{operation_label:J,head_ref:xe}),Ie=await Kt("git.conflict.resolve.instructions",{operation_label:J,directory:h,operation:p,head_info:B.headInfo||"N/A",continue_cmd:Ee}),Ne=`${J} 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 A=H;let k;e[11]!==f||e[12]!==r?(k=()=>{f(),r(!1)},e[11]=f,e[12]=r,e[13]=k):k=e[13];const M=k;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]!==A||e[18]!==I||e[19]!==m||e[20]!==r||e[21]!==D||e[22]!==O||e[23]!==y?(_=async()=>{const J=await A();if(!J){b.error(y("gitView.conflict.noDetailsAvailable"));return}if(!I){b.error(y("gitView.conflict.noActiveSession"),{description:y("gitView.conflict.noActiveSessionDescription")});return}D(J.visibleText,"replace"),O([{text:J.instructionsText,synthetic:!0},{text:J.payloadText,synthetic:!0}]),m?.(),r(!1)},e[17]=A,e[18]=I,e[19]=m,e[20]=r,e[21]=D,e[22]=O,e[23]=y,e[24]=_):_=e[24];const Y=_;let ee;e[25]!==A||e[26]!==h||e[27]!==m||e[28]!==r||e[29]!==C||e[30]!==y?(ee=async()=>{const J=await A();if(!J){b.error(y("gitView.conflict.noDetailsAvailable"));return}C({directoryOverride:h,initialPrompt:J.visibleText,syntheticParts:[{text:J.instructionsText,synthetic:!0},{text:J.payloadText,synthetic:!0}]}),m?.(),r(!1)},e[25]=A,e[26]=h,e[27]=m,e[28]=r,e[29]=C,e[30]=y,e[31]=ee):ee=e[31];const Z=ee;let oe,de,Q,te,u,d,F,L,q,ie,se,G,fe,re,le,je,pe,ue,me,he,ge,ce;if(e[32]!==B||e[33]!==E||e[34]!==I||e[35]!==M||e[36]!==$||e[37]!==Y||e[38]!==Z||e[39]!==v||e[40]!==R||e[41]!==r||e[42]!==n||e[43]!==p||e[44]!==y){const J=y(p==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),xe=B?.unmergedFiles||E;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 Ee;e[67]===Symbol.for("react.memo_cache_sentinel")?(Ee=t.jsx(T,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[67]=Ee):Ee=e[67];const Ge=t.jsxs("div",{className:"flex items-center gap-2",children:[Ee,t.jsx(pt,{children:y("gitView.conflict.detectedTitle",{operation:J})})]});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]!==v||e[77]!==y?(je=v&&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]=v,e[77]=y,e[78]=je):je=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]!==Z?(Se=()=>{Z()},e[88]=Z,e[89]=Se):Se=e[89];const Be=v||!B;let Pe;e[90]!==v?(Pe=v?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"add",className:"size-4"}),e[90]=v,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=v||!B||!I;let Ae;e[101]!==v?(Ae=v?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"chat-1",className:"size-4"}),e[101]=v,e[102]=Ae):Ae=e[102];let X;e[103]!==y?(X=y("gitView.conflict.resolveCurrentSession"),e[103]=y,e[104]=X):X=e[104],e[105]!==we||e[106]!==De||e[107]!==Ae||e[108]!==X?(fe=t.jsxs(W,{variant:"outline",onClick:we,disabled:De,className:"w-full gap-2",children:[Ae,X]}),e[105]=we,e[106]=De,e[107]=Ae,e[108]=X,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=M,F="flex-1",L=y("gitView.conflict.abortOperation",{operation:J}),e[32]=B,e[33]=E,e[34]=I,e[35]=M,e[36]=$,e[37]=Y,e[38]=Z,e[39]=v,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]=L,e[53]=q,e[54]=ie,e[55]=se,e[56]=G,e[57]=fe,e[58]=re,e[59]=le,e[60]=je,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],L=e[52],q=e[53],ie=e[54],se=e[55],G=e[56],fe=e[57],re=e[58],le=e[59],je=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]!==L?(ze=t.jsx(oe,{variant:te,size:u,onClick:d,className:F,children:L}),e[115]=oe,e[116]=te,e[117]=u,e[118]=d,e[119]=F,e[120]=L,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 ve;e[126]!==se||e[127]!==G||e[128]!==fe||e[129]!==$e?(ve=t.jsxs("div",{className:se,children:[G,fe,$e]}),e[126]=se,e[127]=G,e[128]=fe,e[129]=$e,e[130]=ve):ve=e[130];let Re;e[131]!==re||e[132]!==le||e[133]!==je||e[134]!==pe||e[135]!==ue||e[136]!==me||e[137]!==ve?(Re=t.jsxs("div",{className:re,children:[le,je,pe,ue,me,ve]}),e[131]=re,e[132]=le,e[133]=je,e[134]=pe,e[135]=ue,e[136]=me,e[137]=ve,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 Te;return e[143]!==Q||e[144]!==ge||e[145]!==ce||e[146]!==Ce?(Te=t.jsx(Q,{open:ge,onOpenChange:ce,children:Ce}),e[143]=Q,e[144]=ge,e[145]=ce,e[146]=Ce,e[147]=Te):Te=e[147],Te};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:j})=>{const{t:h}=et(),[p,f]=l.useState(!0),[m,x]=l.useState(!1),E=h(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),y=async()=>{x(!0);try{await j(p),e(!1)}catch(I){const D=I instanceof Error?I.message:`Failed to ${n}`;b.error(D)}finally{x(!1)}},C=()=>{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(Zn,{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:C,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:E})})]})]})})},mi=({mergeInProgress:i,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:j,conflictCount:h=0,isLoading:p=!1})=>{const{t:f}=et(),[m,x]=l.useState(null),E=i&&i.head,y=e&&(e.headName||e.onto),C=E?"merge":y?"rebase":null;if(!C)return null;const I=async()=>{x("continue");try{await n()}finally{x(null)}},D=async()=>{x("abort");try{await r()}finally{x(null)}},O=m!==null,v=h>0,w=f(C==="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=v?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(v?"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:D,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")]}),v?j&&t.jsx(W,{variant:"default",size:"sm",onClick:j,disabled:O||p,children:f("gitView.operation.resolveWithAi")}):t.jsxs(W,{variant:"default",size:"sm",onClick:I,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:j,onMerge:h,onRebase:p,disabled:f,isOperating:m,operationLogs:x,onOperationComplete:E,mode:y,defaultTargetBranch:C}=i,I=f===void 0?!1:f,D=m===void 0?!1:m,O=x===void 0?[]:x,v=y===void 0?"dialog":y,{t:w}=et(),[B,S]=l.useState(!1),[R,V]=l.useState("merge"),[P,g]=l.useState(null),[H,A]=l.useState(!1),[k,M]=l.useState(""),U=l.useRef(null),$=l.useRef(null),_=I||D,Y=n||w("gitView.branch.currentBranchFallback"),ee=O.length>0&&O.every(gi),Z=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]!==j?(de=new Set(j.map(pi).filter(Boolean)),e[1]=j,e[2]=de):de=e[2];const Q=de;let te;if(e[3]!==k||e[4]!==n||e[5]!==r||e[6]!==Q){let X;e[8]!==n||e[9]!==Q?(X=_e=>_e!==n&&!Q.has(_e),e[8]=n,e[9]=Q,e[10]=X):X=e[10];const Fe=r.filter(X);te=Rt(Fe,k,xi),e[3]=k,e[4]=n,e[5]=r,e[6]=Q,e[7]=te}else te=e[7];const u=te;let d;e[11]!==k||e[12]!==j?(d=Rt(j,k,wi),e[11]=k,e[12]=j,e[13]=d):d=e[13];const F=d;let L;e[14]!==C||e[15]!==r||e[16]!==j?(L=()=>C&&(j.includes(C)||r.includes(C))?C:null,e[14]=C,e[15]=r,e[16]=j,e[17]=L):L=e[17];const q=L;let ie;e[18]!==q||e[19]!==S?(ie=()=>{S(!0),g(q()),V("merge"),M("")},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=X=>{g(X),A(!1),M("")},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 je;e[27]!==D||e[28]!==S?(je=()=>{D||(g(null),V("merge"),M(""),S(!1))},e[27]=D,e[28]=S,e[29]=je):je=e[29];const pe=je,ue=()=>{D&&!ee||(ee&&E?.(),g(null),V("merge"),M(""),S(!1))};let me,he;e[30]!==H?(me=()=>{H||M("")},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]!==v||e[34]!==q||e[35]!==P?(ge=()=>{v==="dialog"||P||g(q())},ce=[v,q,P],e[33]=v,e[34]=q,e[35]=P,e[36]=ge,e[37]=ce):(ge=e[36],ce=e[37]),l.useEffect(ge,ce);const ve=D?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?v==="dialog"?t.jsx(Is,{children:t.jsx(W,{variant:"default",size:"sm",onClick:ue,children:w(Z?"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(Z?"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:()=>V("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:()=>V("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:A,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:k,onValueChange:M,onKeyDown:bi}),t.jsxs(Ms,{className:"h-full min-h-0",disableHorizontal:!0,children:[t.jsx(Es,{children:w("gitView.branch.empty")}),u.length>0&&t.jsx(qt,{heading:w("gitView.branch.localBranches"),children:u.map(X=>t.jsx(Yt,{onSelect:()=>fe(X),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:X})},`local-${X}`))}),u.length>0&&F.length>0?t.jsx(ea,{}):null,F.length>0&&t.jsx(qt,{heading:w("gitView.branch.remoteBranches"),children:F.map(X=>t.jsx(Yt,{onSelect:()=>fe(X),children:t.jsx("span",{className:"typography-ui-label text-foreground truncate",children:X})},`remote-${X}`))})]})]})})]})]}),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,v==="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(v==="bare")return ve;if(v==="inline"){let X;e[38]!==w?(X=w("gitView.branch.updateTitle"),e[38]=w,e[39]=X):X=e[39];let Fe;e[40]!==X?(Fe=t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:X}),e[40]=X,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 Ke;e[49]!==Fe||e[50]!==st?(Ke=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]=Ke):Ke=e[51];let at;e[52]!==ve?(at=t.jsx("div",{className:"pt-3",children:ve}),e[52]=ve,e[53]=at):at=e[53];let it;return e[54]!==Ke||e[55]!==at?(it=t.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Ke,at]}),e[54]=Ke,e[55]=at,e[56]=it):it=e[56],it}let Re;e[57]!==D?(Re=D?t.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(T,{name:"git-merge",className:"size-4"}),e[57]=D,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 Te;e[61]!==Ce?(Te=t.jsx("span",{children:Ce}),e[61]=Ce,e[62]=Te):Te=e[62];let J;e[63]!==se||e[64]!==_||e[65]!==Re||e[66]!==Te?(J=t.jsx(Xt,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"sm",className:"gap-1.5",onClick:se,disabled:_,children:[Re,Te]})}),e[63]=se,e[64]=_,e[65]=Re,e[66]=Te,e[67]=J):J=e[67];let xe;e[68]!==w?(xe=w("gitView.branch.mergeRebaseTooltip"),e[68]=w,e[69]=xe):xe=e[69];let Ee;e[70]!==xe?(Ee=t.jsx(Zt,{sideOffset:8,children:xe}),e[70]=xe,e[71]=Ee):Ee=e[71];let Ge;e[72]!==J||e[73]!==Ee?(Ge=t.jsxs(Qt,{children:[J,Ee]}),e[72]=J,e[73]=Ee,e[74]=Ge):Ge=e[74];let Ie;e[75]!==ue||e[76]!==S?(Ie=X=>{X?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]!==Z||e[83]!==D||e[84]!==R||e[85]!==ee||e[86]!==w||e[87]!==Y?(Be=D?w(ee?Z?"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]=Z,e[83]=D,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]!==ve||e[95]!==ke?(we=t.jsxs(gt,{className:"max-w-md",children:[ke,ve]}),e[94]=ve,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 Ae;return e[101]!==Ge||e[102]!==De?(Ae=t.jsxs(t.Fragment,{children:[Ge,De]}),e[101]=Ge,e[102]=De,e[103]=Ae):Ae=e[103],Ae};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 ji=({runMutation:i,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:j})=>{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(E=>x.paths.add(E));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(E){n(x,E)}finally{r(x.paths),p=!1,h.length>0&&j()}})()},clear:()=>{h.length=0},size:()=>h.length,isRunning:()=>p}},vi=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]+)(?:\(.*\))?!?:/,j=n.match(r);if(j){const f=j[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,vt=new Map,Vi=(i,e)=>{if(vt.delete(i),vt.set(i,e),vt.size>ki){const n=vt.keys().next().value;n!==void 0&&vt.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(),[j,h]=l.useState(null),[p,f]=l.useState(!1),m=Ze(s=>s.currentSessionId),x=Ze(s=>s.newSessionDraft),E=Ze(s=>s.setDraftBootstrapPendingDirectory),y=Ze(s=>s.worktreeMetadata),C=Ze(s=>s.availableWorktrees),I=nt(r),D=l.useMemo(()=>{if(!I)return;const s=C.find(a=>nt(a.path)===I);if(s)return s;for(const a of y.values())if(nt(a.path)===I)return a},[C,I,y]),O=l.useMemo(()=>{if(m)return y.get(m)??D;if(x?.open)return D},[m,D,x?.open,y]),{profiles:v,globalIdentity:w,defaultGitIdentityId:B,loadProfiles:S,loadGlobalIdentity:R,loadDefaultGitIdentityId:V}=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),A=H?ia(H):[],k=H&&!H.degraded&&!H.legacy?H.worktreeRoot??void 0:void 0,M=va(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:Z,fetchAll:oe,ensureAll:de,fetchStatus:Q,fetchBranches:te,fetchLog:u,setLogMaxCount:d,fetchIdentity:F,prefetchDiffs:L,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),je=g?.current??null,pe=ha(s=>!r||!je?null:ga(s.entries,r,je)),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)},[]),ve=l.useCallback(s=>{$e(),he.current=window.setTimeout(()=>{he.current=null,nt(s)===nt(r)&&Q(s,n,{silent:!0})},vi)},[$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))},[]),Te=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]),J=l.useMemo(()=>ji({runMutation:({directory:s,direction:a,paths:o})=>Te(s,a,o),onMutationComplete:({directory:s})=>{G(s),ve(s)},onMutationError:({directory:s,direction:a,rollback:o},c)=>{o?.(),G(s),ve(s);const N=e(a==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");b.error(c instanceof Error?c.message:N)},onPathsComplete:s=>{zs(a=>{const o=new Set(a);return s.forEach(c=>o.delete(c)),o})},scheduleFlush:Ce}),[G,Te,Ce,ve,e]);l.useEffect(()=>(ce.current=J.flush,()=>{ce.current=null}),[J]),l.useEffect(()=>()=>J.clear(),[J]),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 ja(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=j,!(!r||!n)&&(s==="pending"&&j==="ready"&&(f(!0),oe(r,n).finally(()=>{window.setTimeout(()=>{f(!1)},1200)})),j==="failed"&&(E(null),f(!1)))},[r,oe,n,E,j]);const xe=nt(x?.bootstrapPendingDirectory??null),Ee=!!(r&&xe&&xe===nt(r)),Ie=!!(r&&(j==="pending"||Ee))||p,Ne=l.useMemo(()=>r?vt.get(r)??null:null,[r]),Se=fa(s=>s.settingsGitmojiEnabled),[Be,Pe]=l.useState(null),{gitmojis:ke}=Aa(Se);l.useEffect(()=>{const s=k||M?.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}},[k,M?.projectDirectory]);const[we,De]=l.useState(Ne?.commitMessage??""),[Ae,X]=l.useState([]),[Fe,_e]=l.useState(!1),tt=l.useRef(null),[st,Ke]=l.useState(null),[at,it]=l.useState(!1),[Ts,As]=l.useState(null),[Je,Sr]=l.useState(25),[kr,Ls]=l.useState(!1),{triggerFireworks:Vr}=Ca(),Os=l.useRef(new Map),Bt=l.useRef(0),es=l.useCallback(()=>{Bt.current+=1,ze.current&&Ls(!0)},[]),ts=l.useCallback(()=>{Bt.current=Math.max(0,Bt.current-1),ze.current&&Bt.current===0&&Ls(!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||J.size()>0||J.isRunning(),Hs=l.useCallback(()=>{const s=tt.current;s&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.scrollTo({top:s.scrollHeight,behavior:"smooth"})})})},[]),as=k||M?.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=M?.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"},[M?.createdFromBranch,g,Be]),Mt=l.useCallback(()=>{$s([])},[]),[os,Mr]=l.useState(new Set),[Et,Er]=l.useState(new Map),[Tt,ls]=l.useState(new Set),cs=l.useRef(Et),St=l.useRef(Tt),[Tr,bt]=l.useState(null),[xt,ds]=l.useState(null),[Us,Ks]=l.useState(""),[Me,At]=l.useState(null),[Ar,Js]=l.useState(!1),[Lr,qs]=l.useState(!1),[us,ms]=l.useState([]),[Or,Ys]=l.useState(null),[Qs,hs]=l.useState(null),[zr,Lt]=l.useState([]),[Gr,qe]=l.useState(!1),[_r,Qe]=l.useState([]),[Ot,Xe]=l.useState("merge"),[$r,gs]=l.useState(null),[fs,Xs]=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??[]),Xe(a.operation??"merge"),qe(!0)}catch{window.localStorage.removeItem(Ye)}},[Ye,r]);const[Kr,xs]=l.useState(!1),[ws,Zs]=l.useState("merge"),[ys,er]=l.useState(""),Jr=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=Et},[Et]),l.useEffect(()=>{St.current=Tt},[Tt]),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 N of s)c.add(N);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||(Er(c=>{const N=new Map(c);for(const{hash:z,files:ae}of o)N.set(z,ae);return cs.current=N,N}),ls(c=>{const N=new Set(c);for(const{hash:z}of o)N.delete(z);return St.current=N,N}))}),()=>{a=!0,ls(o=>{let c=!1;const N=new Set(o);for(const z of s)N.delete(z)&&(c=!0);return c?(St.current=N,N):o})}},[os,r,n]),l.useEffect(()=>{r&&Vi(r,{directory:r,commitMessage:we,generatedHighlights:ns})},[we,r,ns]),l.useEffect(()=>{i&&(S(),R(),V())},[i,S,R,V]),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&&(Z(r),de(r,n))},[i,r,Z,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,Je)},[r,n,u,Je]),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 N=await n.hasLocalIdentity?.(r);if(o||N===!0)return;es(),await n.setGitIdentity(r,s),Os.current.set(r,s),await bs()}catch(N){console.warn("Failed to auto-apply default git identity:",N)}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]),js=l.useMemo(()=>ot.filter(Ii),[ot]);l.useEffect(()=>{if(!r||ot.length===0)return;const s=[],a=new Set,o=N=>{!N||a.has(N)||(a.add(N),s.push(N))};if(We.forEach(N=>o(N.path)),Ae.forEach(o),ot.slice(0,Ni).forEach(N=>o(N.path)),s.length===0)return;const c=window.setTimeout(()=>{L(r,n,s,{maxFiles:Ci})},120);return()=>{window.clearTimeout(c)}},[ot,r,n,L,We,Ae]);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){Ke(s);try{const o=c=>{const N=`${c.name}/`,z=g?.tracking?.startsWith(N)?g.tracking.slice(N.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,N=!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),N=!0),c>0&&N?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})):N?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{Ke(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";As(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],N=Ue.find(In=>In.name===c)??Ue[0];if(!N)throw new Error(e("mobile.changes.noRemote"));Ke("sync");const z=`${N.name}/`,ae=g?.tracking?.startsWith(z)?g.tracking.slice(z.length):void 0;await n.gitFetch(r,{remote:N.name});const K=await n.getGitStatus(r);if((K.behind??0)>0){if((K.files?.length??0)>0){b.error(e("gitView.toast.commitOrStashBeforeSync")),await ne(!1);return}await n.gitPull(r,{remote:N.name,branch:ae,rebase:!0})}const Oe=await n.getGitStatus(r);let jt;(Oe.ahead??0)>0&&(jt=await n.gitPush(r)),b.success(e("gitView.toast.pushedToUpstream",{name:tr(jt)})),Vr(),await ne(!1)}else await ne(!1);await ye(),Fr(c=>c+1)}catch(c){const N=c instanceof Error?c.message:e("gitView.toast.createCommitFailed");b.error(N)}finally{As(null),s.pushAfter&&Ke(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 N=o;if(Se&&ke.length>0){const z=Si(o,ke);if(z){const{code:ae,emoji:K}=z;!o.startsWith(ae)&&!o.startsWith(K)&&(N=`${ae} ${o}`)}}De(N)}$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]),vs=s=>s.reason==="attention"?`${s.attentionReason} in progress`:s.reason==="missing"?"worktree is missing":"worktree is invalid",Xr=async(s,a)=>{if(!r||!g)return;const o=Ss(H);if(o.length>0){b.error(e("gitView.toast.cannotCreateBranch",{reason:vs(o[0])}));return}const c=g.current??null,N=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:N,branch:s,options:["--set-upstream"]}),z=!0}catch(ae){const K=ae instanceof Error?ae.message:`Unable to push new branch to ${N}.`;b.warning(e("gitView.toast.branchCreatedLocally"),{description:t.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",K]})})}await ne(),await ye(),z&&b.success(e("gitView.toast.upstreamSet",{branch:s,remote:N}))}catch(z){const ae=z instanceof Error?z.message:e("gitView.toast.createBranchFailed");throw b.error(ae),z}},Zr=async(s,a)=>{if(!r)return;const o=Ss(H);if(o.length>0){b.error(e("gitView.toast.cannotRenameBranch",{reason:vs(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 N=c instanceof Error?c.message:e("gitView.toast.renameBranchFailed",{oldName:s,newName:a});b.error(N)}},en=async s=>{if(!r)return;const a=Ss(H);if(a.length>0){b.error(e("gitView.toast.cannotCheckout",{reason:vs(a[0])}));return}const o=s.replace(/^remotes\//,"");if(g?.current!==o)try{await n.checkoutBranch(r,o),b.success(e("gitView.toast.checkedOut",{name:o})),await ne(),await ye()}catch(c){const N=c instanceof Error?c.message:e("gitView.toast.checkoutFailed",{name:o});b.error(N)}},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:M?.createdFromBranch,rootBranchHint:Be,defaultBranch:nr,headBranch:ct}),[ct,nr,Ue,kt,Be,M?.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 v){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())},[v,w,xt]),nn=l.useMemo(()=>{if(_?.userName&&_?.userEmail){const s=v.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},[_,v,w]),an=We.length,on=Y||st!==null||Ts!==null,ln=!!(M&&as&&is&&Dr),ar=!!ct,dt=ln&&as&&is&&M?{repoRoot:as,sourceBranch:is,worktreeMetadata:M}: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:Je});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 N=$.all.findIndex(z=>!c.has(z.hash));if(N===0){bt(null);return}if(N===-1){bt({insertBeforeIndex:$.all.length,branchName:ct,direction:"up"});return}bt({insertBeforeIndex:N,branchName:ct,direction:"up"})}catch{s||bt(null)}})(),()=>{s=!0}},[wt,ct,r,n,$,Je]),l.useEffect(()=>{gs(null)},[r]),l.useEffect(()=>{if(Me!=="graph"||!r){Me!=="graph"&&gs(null);return}let s=!1;return Xs(!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||Xs(!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(N=>{const z=new Set(N);return o.forEach(ae=>z.add(ae)),z});const c=ie(r,o,a);J.enqueue({directory:r,direction:a,paths:new Set(o),rollback:()=>se(r,c)}),Ce()},[r,J,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(K=>ss.has(K)))return;const N=new Set(We.map(K=>K.path)),z=o==="all"&&c.some(K=>N.has(K));a&&Gs(!0),Dt(K=>{const Oe=new Set(K);return c.forEach(jt=>Oe.add(jt)),Oe});const ae=[];try{if(await Promise.all(c.map(async K=>{try{await n.revertGitFile(r,K,{scope:o})}catch(Oe){ae.push({path:K,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 K=c.length-ae.length;b.warning(K===1?e("gitView.toast.revertedSomeSingle",{success:K,failed:ae.length}):e("gitView.toast.revertedSomePlural",{success:K,failed:ae.length}))}}finally{Dt(K=>{const Oe=new Set(K);return c.forEach(jt=>Oe.delete(jt)),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}),js.length>0&&s.push({id:"unstaged",title:e("gitView.changes.title"),entries:js,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,js]),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(),N=c.length>0?`
|
|
4
|
-
|
|
5
|
-
`:"";return`${c}${N}${a.join(`
|
|
6
|
-
`)}`.trim()}),Mt()},[Mt]),gn=l.useCallback((s,a)=>{const o=a||s;De(c=>{const N=c.trimStart();return N.startsWith(s)||a&&N.startsWith(a)?c:`${o.endsWith(" ")?o:`${o} `}${c}`.trimStart()}),Ks(""),_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)=>{Lt(o=>[...o,{message:s,status:a,timestamp:Date.now()}])},[]),Le=l.useCallback((s,a)=>{Lt(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(()=>{Lt([])},[]),fn=l.useCallback(()=>{Lt([]),hs(null)},[]),Ht=l.useCallback(s=>{const a=s.trim(),o=new Set(Ue.map(N=>N.name)),c=a.indexOf("/");if(c>0){const N=a.slice(0,c),z=a.slice(c+1);if(o.has(N)&&z)return{branch:a,remote:N,remoteBranch:z}}for(const N of Ue){const z=`${N.name}/${a}`;if(lt.includes(z))return{branch:z,remote:N.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}),Le("done",`Fetched ${o.remote}/${o.remoteBranch}`)),ut(`Merging ${o.branch} into ${a}...`,"running");const c=await n.merge(r,{branch:o.branch});c.conflict?(Le("error","Merge conflicts detected"),Qe(c.conflictFiles??[]),Xe("merge"),qe(!0),rt(r,c.conflictFiles??[],"merge")):(Le("done",`Merged ${o.branch} into ${a}`),He(),ut("Refreshing repository status...","running"),await ne(),await ye(),Le("done","Repository status updated"))}catch(c){if(_t(c))Le("error","Uncommitted changes detected"),Zs("merge"),er(o.branch),xs(!0);else{const N=c instanceof Error?c.message:`Failed to merge ${o.branch}`;Le("error",N)}}},[r,n,g,Ht,ne,ye,_t,rt,He,ut,Le,$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}),Le("done",`Fetched ${o.remote}/${o.remoteBranch}`)),ut(`Rebasing ${a} onto ${o.branch}...`,"running");const c=await n.rebase(r,{onto:o.branch});c.conflict?(Le("error","Rebase conflicts detected"),Qe(c.conflictFiles??[]),Xe("rebase"),qe(!0),rt(r,c.conflictFiles??[],"rebase")):(Le("done",`Rebased ${a} onto ${o.branch}`),He(),ut("Refreshing repository status...","running"),await ne(),await ye(),Le("done","Repository status updated"))}catch(c){if(_t(c))Le("error","Uncommitted changes detected"),Zs("rebase"),er(o.branch),xs(!0);else{const N=c instanceof Error?c.message:`Failed to rebase onto ${o.branch}`;Le("error",N)}}},[r,n,g,Ht,ne,ye,_t,rt,He,ut,Le,$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??[]),Xe("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??[]),Xe("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]),jn=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]),vn=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),Xe(a),qe(!0)},[r,g]),Cn=l.useCallback(async s=>{if(!r)return;const a=g?.current,o=ws,c=ys,N=(g?.files??[]).some(yr);try{await n.stash(r,{message:`Auto-stash before ${o} with ${c}`,includeUntracked:!0}),N&&G(r)}catch(K){const Oe=K instanceof Error?K.message:"Failed to stash changes";b.error(Oe);return}let z=!1,ae=!1;try{if(o==="merge"){const K=await n.merge(r,{branch:c});K.conflict?(ae=!0,Qe(K.conflictFiles??[]),Xe("merge"),qe(!0)):(z=!0,b.success(e("gitView.toast.mergedIntoBranch",{branch:c,currentBranch:a||""})))}else{const K=await n.rebase(r,{onto:c});K.conflict?(ae=!0,Qe(K.conflictFiles??[]),Xe("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(K){const Oe=K instanceof Error?K.message:e("gitView.toast.restoreStashFailed");b.error(Oe)}else s&&ae&&b.info(e("gitView.toast.restoreStashManually"));await ne(),await ye()}catch(K){if(s)try{await n.stashPop(r),G(r)}catch{}throw K}},[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(()=>{At(null),r&&(Q(r,n),te(r,n),u(r,n,Je))},[r,Q,te,u,Je,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,Je));return}Qe(s.conflictFiles??[]),Xe(s.operation),qe(!0),r&&rt(r,s.conflictFiles??[],s.operation)}},[e,Qe,Xe,qe,rt,r,Q,te,u,Je,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")}),A.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:Xr,onRenameBranch:Zr,activeIdentityProfile:nn,availableIdentities:rn,onSelectIdentity:tn,isApplyingIdentity:kr,isWorktreeMode:!!M,onOpenHistory:()=>At("history"),onOpenGraph:()=>At("graph"),onOpenStashes:un,onOpenUpdateBranch:ar?()=>Js(!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:jn,onResolveWithAI:vn,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(jr,{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:X,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:Ts,hasPendingIndexMutation:Br,gitmojiEnabled:Se,onOpenGitmojiPicker:()=>_e(!0)})]}):t.jsx(Wa,{onOpenStashes:()=>it(!0)})})})})})}),t.jsx(ht,{open:Ar,onOpenChange:s=>{!s&&Qs!==null||Js(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:Lr,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,Je))}},dt.worktreeMetadata.path):null]})}),t.jsx(ht,{open:Me!==null,onOpenChange:s=>{s||At(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,Je)},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:Je,onLogMaxCountChange:Me==="graph"?Sn:Nn,expandedCommitHashes:os,onToggleCommit:qr,commitFilesMap:Et,loadingCommitHashes:Tt,onCopyHash:Jr,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:Me==="graph"?null:Tr,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:Ks}),t.jsxs(Ms,{children:[t.jsx(Es,{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:Kr,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};
|