tide-commander 1.165.1 → 1.167.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/CHANGELOG.md +24 -0
- package/dist/assets/{BossLogsModal-IqVqHwz-.js → BossLogsModal-CLmSG1H0.js} +1 -1
- package/dist/assets/BossSpawnModal-DZlB8KRy.js +1 -0
- package/dist/assets/ControlsModal-B1-STBnD.js +1 -0
- package/dist/assets/DockerLogsModal-CWnhsG_r.js +2 -0
- package/dist/assets/{EmbeddedEditor-BA9mX_Lg.js → EmbeddedEditor-5po-iz0Q.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-7nj6aLot.js → GmailOAuthSetup-BB10r44e.js} +1 -1
- package/dist/assets/GoogleOAuthSetup-CW_Ib5kq.js +270 -0
- package/dist/assets/{IframeModal-DkkCx6nq.js → IframeModal-CPt5x5fr.js} +1 -1
- package/dist/assets/IntegrationsPanel-CO-5iHtn.js +2 -0
- package/dist/assets/{LogViewerModal-DKYB8dHo.js → LogViewerModal-DicJq6l-.js} +1 -1
- package/dist/assets/{MonitoringModal-DOKMIa5U.js → MonitoringModal-B3nwcYZn.js} +1 -1
- package/dist/assets/{PM2LogsModal-XlbT9uoY.js → PM2LogsModal-Viw6fBjN.js} +2 -2
- package/dist/assets/RestoreArchivedAreaModal-BVH9wxhk.js +1 -0
- package/dist/assets/Scene2DCanvas-D6TCimYq.js +1 -0
- package/dist/assets/SceneManager-BdJs75zx.js +104 -0
- package/dist/assets/{SkillsPanel-BKjpKM1N.js → SkillsPanel-D1WonIBN.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-C0k60ioO.js → SlackMultiInstanceSetup-DSTZ5Hry.js} +1 -1
- package/dist/assets/SpawnModal-DUpIkQ08.js +1 -0
- package/dist/assets/StatisticsModal-BoDgM_8E.js +1 -0
- package/dist/assets/SubordinateAssignmentModal-LysAkNGy.js +1 -0
- package/dist/assets/{TriggerManagerPanel-RWrID12k.js → TriggerManagerPanel-BHxmBRvy.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-Ccwm4H5t.js → WorkflowEditorPanel-BHayKmMV.js} +1 -1
- package/dist/assets/abnfDiagram-VRR7QNED-DBZ5EpAj.js +1 -0
- package/dist/assets/arc-UCe2q9lp.js +1 -0
- package/dist/assets/architectureDiagram-ZJ3FMSHR-D5zOdUA8.js +36 -0
- package/dist/assets/{area-logos-DnrrrkFh.js → area-logos-4nlUPBxf.js} +1 -1
- package/dist/assets/blockDiagram-677ZJIJ3-7S-qZlh0.js +132 -0
- package/dist/assets/c4Diagram-LMCZKHZV-CgLv5SCO.js +10 -0
- package/dist/assets/channel-C59jtig-.js +1 -0
- package/dist/assets/chunk-2Q5K7J3B-J08qsAGr.js +1 -0
- package/dist/assets/chunk-32BRIVSS-Xy5D5wu7.js +1 -0
- package/dist/assets/chunk-5VM5RSS4-DqhmRB6E.js +15 -0
- package/dist/assets/chunk-EX3LRPZG-QE89_WgA.js +231 -0
- package/dist/assets/chunk-JWPE2WC7-YSc_ua_g.js +1 -0
- package/dist/assets/chunk-MOJQB5TN-CcH7NM7I.js +88 -0
- package/dist/assets/chunk-RYQCIY6F-CndQTJJ1.js +1 -0
- package/dist/assets/chunk-V7JOEXUC-Dauixo5p.js +206 -0
- package/dist/assets/chunk-VR4S4FIN-BBU6oFw0.js +1 -0
- package/dist/assets/chunk-XXDRQBXY-DXMolb4D.js +1 -0
- package/dist/assets/classDiagram-OUVF2IWQ-DHvVmqF9.js +1 -0
- package/dist/assets/classDiagram-v2-EOCWNBFH-DHvVmqF9.js +1 -0
- package/dist/assets/cose-bilkent-JH36ORCC-Dd9IB924.js +1 -0
- package/dist/assets/cynefin-VYW2F7L2-BQxwdSSb.js +178 -0
- package/dist/assets/cynefinDiagram-TSTJHNR4-BLnxgd0m.js +62 -0
- package/dist/assets/cytoscape.esm-DTSO7Bv0.js +331 -0
- package/dist/assets/dagre-VKFMJZFB-BZ7fXVWR.js +4 -0
- package/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/dist/assets/diagram-FQU43EPY-BFQ1xjHE.js +3 -0
- package/dist/assets/diagram-G47NLZAW-sXsGErM6.js +24 -0
- package/dist/assets/diagram-NH7WQ7WH-D6SPifDp.js +24 -0
- package/dist/assets/diagram-OA4YK3LP-Mu16f_2g.js +30 -0
- package/dist/assets/diagram-WEI45ONY-3BTJg43I.js +41 -0
- package/dist/assets/ebnfDiagram-CCIWWBDH-BGl2hs1X.js +1 -0
- package/dist/assets/erDiagram-Q63AITRT-D03B1rgc.js +85 -0
- package/dist/assets/flowDiagram-23GEKE2U-BCaZJGGE.js +156 -0
- package/dist/assets/ganttDiagram-NO4QXBWP-DrTSQR9G.js +292 -0
- package/dist/assets/gitGraphDiagram-IHSO6WYX-BvrZLcji.js +106 -0
- package/dist/assets/graph-C9eacEi8.js +1 -0
- package/dist/assets/index-B7l8Nsf8.js +1 -0
- package/dist/assets/index-BK7LL53p.js +1 -0
- package/dist/assets/index-CJ6x10Zs.js +2 -0
- package/dist/assets/index-D6btqUwj.js +2 -0
- package/dist/assets/{index-D-MKKw7S.js → index-DAXUzeVz.js} +6 -6
- package/dist/assets/{index-Cjgy2CnG.js → index-DcD9tVKJ.js} +3 -3
- package/dist/assets/{index-DZ7i37eV.js → index-Dzup44Dy.js} +6 -6
- package/dist/assets/index-JEgWBCoB.js +1 -0
- package/dist/assets/index-J_xWyk3Q.js +1 -0
- package/dist/assets/infoDiagram-FWYZ7A6U-Bw9k-wkS.js +2 -0
- package/dist/assets/init-Gi6I4Gst.js +1 -0
- package/dist/assets/ishikawaDiagram-FXEZZL3T-C2oVKtw0.js +70 -0
- package/dist/assets/journeyDiagram-5HDEW3XC-pRpwSEa5.js +139 -0
- package/dist/assets/kanban-definition-HUTT4EX6-CYq_poR1.js +89 -0
- package/dist/assets/katex-C5jXJg4s.js +257 -0
- package/dist/assets/layout-DEXfKzaS.js +1 -0
- package/dist/assets/linear-DLT2RlFJ.js +1 -0
- package/dist/assets/{main-DIf9R6Jx.js → main-06kmV-SQ.js} +125 -125
- package/dist/assets/main-BzGnAbiA.css +1 -0
- package/dist/assets/map-Czzmt4hB.js +1 -0
- package/dist/assets/mermaid.core-DmOBz9SE.js +314 -0
- package/dist/assets/mindmap-definition-LN4V7U3C-DzucjpI_.js +96 -0
- package/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/dist/assets/pegDiagram-2B236MQR-CIf_bLf4.js +1 -0
- package/dist/assets/pieDiagram-ENE6RG2P-Dh9HXeSf.js +39 -0
- package/dist/assets/quadrantDiagram-ABIIQ3AL-B5hZRZ5w.js +7 -0
- package/dist/assets/railroadDiagram-RFXS5EU6-B1oWAO1u.js +1 -0
- package/dist/assets/requirementDiagram-TGXJPOKE-Cg7bjm4O.js +84 -0
- package/dist/assets/sankeyDiagram-HTMAVEWB-TLCrcbtk.js +40 -0
- package/dist/assets/sequenceDiagram-DBY2YBRQ-BD3b_psw.js +162 -0
- package/dist/assets/sizeCapture-X5ZJPWSS-D26nx1uQ.js +1 -0
- package/dist/assets/stateDiagram-2N3HPSRC-CIwRQUnK.js +1 -0
- package/dist/assets/stateDiagram-v2-6OUMAXLB-C5qcZ4o1.js +1 -0
- package/dist/assets/swimlanes-5IMT3BWC-DYbes851.js +2 -0
- package/dist/assets/swimlanesDiagram-G3AALYLV-Ke-NRRIa.js +8 -0
- package/dist/assets/timeline-definition-FHXFAJF6-Fr9U6JU6.js +120 -0
- package/dist/assets/{vendor-three-Chj50gSY.js → vendor-three-3OKhI9bz.js} +1 -1
- package/dist/assets/vennDiagram-L72KCM5P-Cns-KLq7.js +34 -0
- package/dist/assets/wardleyDiagram-EHGQE667-DHA7rD9Z.js +78 -0
- package/dist/assets/{web-DDxnPoTK.js → web-B7c8sthS.js} +1 -1
- package/dist/assets/{web-DhZ0XCan.js → web-C05qFIA-.js} +1 -1
- package/dist/assets/{web-Dlc8Nyra.js → web-Dja1kfLs.js} +1 -1
- package/dist/assets/xychartDiagram-FW5EYKEG-DCnL05Wq.js +7 -0
- package/dist/build-info.json +1 -1
- package/dist/index.html +3 -3
- package/dist/src/packages/server/claude/runner/watchdog.js +27 -0
- package/dist/src/packages/server/codex/app-server/codex-app-server-runner.js +34 -4
- package/dist/src/packages/server/data/builtin-skills/index.js +2 -0
- package/dist/src/packages/server/data/builtin-skills/mermaid-diagrams.js +76 -0
- package/dist/src/packages/server/integrations/gmail/gmail-client.js +73 -5
- package/dist/src/packages/server/integrations/gmail/gmail-routes.js +9 -4
- package/dist/src/packages/server/integrations/google-auth/token-health.js +196 -0
- package/dist/src/packages/server/integrations/google-calendar/calendar-client.js +61 -6
- package/dist/src/packages/server/integrations/google-calendar/calendar-routes.js +9 -4
- package/dist/src/packages/server/integrations/google-drive/drive-client.js +61 -6
- package/dist/src/packages/server/integrations/google-drive/drive-routes.js +9 -4
- package/dist/src/packages/server/opencode/server/opencode-server-process.js +102 -7
- package/dist/src/packages/server/opencode/server/opencode-server-runner.js +13 -0
- package/dist/src/packages/server/services/agent-service.js +7 -0
- package/dist/src/packages/server/services/runtime-events.js +1 -0
- package/package.json +2 -1
- package/dist/assets/BossSpawnModal-Dj9ayWfR.js +0 -1
- package/dist/assets/ControlsModal-ki85jvDA.js +0 -1
- package/dist/assets/DockerLogsModal-CeIuKlvk.js +0 -2
- package/dist/assets/GoogleOAuthSetup-Bh-Cy-dE.js +0 -236
- package/dist/assets/IntegrationsPanel-DHjpWEFF.js +0 -2
- package/dist/assets/RestoreArchivedAreaModal-Du1f8Urv.js +0 -1
- package/dist/assets/Scene2DCanvas-BTnpyyK6.js +0 -1
- package/dist/assets/SceneManager-owoMSHKT.js +0 -104
- package/dist/assets/SpawnModal-Cww_6dcz.js +0 -1
- package/dist/assets/StatisticsModal-Dl5loLLI.js +0 -1
- package/dist/assets/SubordinateAssignmentModal-DefQL38f.js +0 -1
- package/dist/assets/index-B5iakYkB.js +0 -1
- package/dist/assets/index-CbJ-R04c.js +0 -2
- package/dist/assets/index-CcHBNDP_.js +0 -2
- package/dist/assets/index-DG7HgtQn.js +0 -1
- package/dist/assets/index-Fcs4x2Vj.js +0 -1
- package/dist/assets/index-g0yAcpoy.js +0 -1
- package/dist/assets/main-Dnp-3iMX.css +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-
|
|
2
|
-
import{r as t,i as W,k as B,K as Zt,a1 as Ys,S as zt,a2 as Xs,s as _e,u as oe,j as e,I as M,cd as At,as as _n,ce as Qs,cf as Kn,cg as Zs,ch as en,ci as Vn,cj as Wn,ck as Lt,cl as qn,cm as Jn,cn as Yn,co as Ot,cp as Xn,cq as as,cr as Qn,cs as tn,ct as $t,cu as Ht,ap as it,cv as gt,cw as xt,cx as As,cy as Zn,bB as ea,cz as ns,a5 as ta,cA as sa,cB as na,cC as Pt,cD as aa,cE as ra,cF as ia,cG as la,cH as oa,cI as Os,C as ca,t as da}from"./main-DIf9R6Jx.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ua(s){const[n,l]=t.useState(null),[c,i]=t.useState(!1),r=t.useCallback(async()=>{if(s){i(!0);try{const h=await W(B(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await h.json();h.ok?l(o):l({isGitRepo:!1,files:[]})}catch(h){console.error("[FileExplorer] Failed to load git status:",h),l({isGitRepo:!1,files:[]})}finally{i(!1)}}},[s]);return{gitStatus:n,loading:c,loadGitStatus:r}}async function ha(s){try{const n=await W(B(`/api/files/git-original?path=${encodeURIComponent(s)}`)),l=await n.json();return n.ok&&!l.isNew?{content:l.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const ma=new Set([".txt",".md",".markdown",".json",".yaml",".yml",".xml",".html",".htm",".css",".scss",".sass",".less",".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".rb",".c",".cpp",".h",".hpp",".cs",".go",".rs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".hs",".ml",".fs",".sql",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".toml",".ini",".cfg",".conf",".env",".gitignore",".dockerignore",".editorconfig",".prettierrc",".eslintrc",".babelrc",".log",".csv",".tsv",".svg",""]),fa=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),pa=new Set([".pdf"]),ga=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".zip",".tar",".gz",".rar",".7z",".exe",".dmg",".app",".deb",".rpm",".apk",".aab",".ipa",".msi",".mp3",".mp4",".wav",".avi",".mov",".mkv",".flac",".ogg",".webm",".ttf",".otf",".woff",".woff2",".eot",".sqlite",".db",".so",".dll",".dylib",".a",".o",".obj",".bin",".dat",".iso",".img",".jar",".war",".ear",".class"]);function xa(s){const n=s.toLowerCase();return fa.has(n)?"image":pa.has(n)?"pdf":ga.has(n)?"binary":(ma.has(n),"text")}function ya(){const[s,n]=t.useState(null),[l,c]=t.useState(!1),[i,r]=t.useState(null),h=t.useCallback(async u=>{var p,b;c(!0),r(null);try{const f=u.substring(u.lastIndexOf(".")).toLowerCase(),v=xa(f),N=u.substring(u.lastIndexOf("/")+1);if(v==="image"){const k=await W(B(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!k.ok){const w=await k.json().catch(()=>({error:"Failed to load image"}));r(w.error||"Failed to load image"),n(null);return}const g=await k.blob(),j=URL.createObjectURL(g);n({path:u,filename:N,extension:f,content:"",size:g.size,modified:new Date().toISOString(),fileType:"image",dataUrl:j});return}if(v==="pdf"){const k=await W(B(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(!k.ok){r(g.error||"Failed to load PDF info"),n(null);return}n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"pdf",dataUrl:B(`/api/files/binary?path=${encodeURIComponent(u)}&token=${encodeURIComponent(Zt())}`)});return}if(v==="binary"){const k=await W(B(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(!k.ok){r(g.error||"Failed to load file info"),n(null);return}n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"binary",dataUrl:B(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Zt())}`)});return}const R=await W(B(`/api/files/read?path=${encodeURIComponent(u)}`)),y=await R.json();if(!R.ok){if((p=y.error)!=null&&p.includes("too large")||(b=y.error)!=null&&b.includes("binary")){const k=await W(B(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(k.ok){n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"binary",dataUrl:B(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Zt())}`)});return}}r(y.error||"Failed to load file"),n(null);return}n({...y,fileType:"text"})}catch(f){const v=f instanceof Error?f.message:"Failed to load file";r(v),n(null)}finally{c(!1)}},[]),o=t.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),r(null)},[]);return{file:s,loading:l,error:i,loadFile:h,clearFile:o,setFile:n}}const ba="file-explorer-state",Gs="file-explorer-recent-projects",ja=10080*60*1e3,va=12;function es(s){return`${ba}-folder-${s}`}async function wa(s){try{const n=await W(B(`/api/files/exists?path=${encodeURIComponent(s)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function Ca(){const s=t.useCallback(async i=>{if(!i)return null;try{const r=localStorage.getItem(es(i));if(!r)return null;const h=JSON.parse(r);if(Date.now()-h.timestamp>ja)return localStorage.removeItem(es(i)),null;const u=(await Promise.all((h.tabs||[]).map(async b=>({tab:b,exists:await wa(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let p=h.activeTabPath;return p&&!u.some(b=>b.path===p)&&(p=u.length>0?u[0].path:null),{tabs:u,activeTabPath:p,viewMode:h.viewMode||"files",expandedPaths:new Set(h.expandedPaths||[])}}catch(r){return console.error("[FileExplorerStorage] Failed to load project state:",r),null}},[]),n=t.useCallback((i,r)=>{if(i)try{const h={tabs:r.tabs,activeTabPath:r.activeTabPath,viewMode:r.viewMode,expandedPaths:Array.from(r.expandedPaths),timestamp:Date.now()};localStorage.setItem(es(i),JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save project state:",h)}},[]),l=t.useCallback(()=>{try{const i=localStorage.getItem(Gs);if(!i)return[];const r=JSON.parse(i);return Array.isArray(r)?r.filter(h=>typeof h=="string"):[]}catch{return[]}},[]),c=t.useCallback(i=>{if(!i)return l();const r=[i,...l().filter(h=>h!==i)].slice(0,va);try{localStorage.setItem(Gs,JSON.stringify(r))}catch{}return r},[l]);return{loadProjectState:s,saveProjectState:n,loadRecentProjects:l,pushRecentProject:c}}const Us=280,Bs=150,_s=1200;function Na(){const[s,n]=t.useState(()=>{const p=Ys(zt.TREE_PANEL_WIDTH,Us);return p>=Bs&&p<=_s?p:Us}),l=t.useRef(!1),[c,i]=t.useState(!1),r=t.useRef(0),h=t.useRef(0),o=t.useRef(s);o.current=s;const u=t.useCallback(p=>{p.preventDefault(),l.current=!0,i(!0),r.current=p.clientX,h.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const p=f=>{if(!l.current)return;const v=f.clientX-r.current,N=Math.min(_s,Math.max(Bs,h.current+v));n(N)},b=()=>{l.current&&(l.current=!1,i(!1),document.body.style.cursor="",document.body.style.userSelect="",Xs(zt.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",p),document.addEventListener("mouseup",b),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",b)}},[]),{treePanelWidth:s,handleResizeStart:u,isResizing:c}}const ka=100,Ea=.65,Sa=36;function Ta(){const[s,n]=t.useState(()=>Ys(zt.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const c=t.useRef(0),i=t.useRef(0),r=()=>Math.floor((window.innerHeight-Sa)*Ea),h=f=>Math.min(r(),Math.max(ka,f)),o=t.useCallback(f=>{n(f);const v=document.querySelector(".file-explorer-main");v&&v.style.setProperty("--fe-mobile-tree-height",`${f}px`)},[]),u=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Xs(zt.MOBILE_TREE_PANEL_HEIGHT,l.current),_e.setTerminalResizing(!1)},[]),p=t.useCallback(f=>{f.preventDefault();const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=f.clientY,i.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",_e.setTerminalResizing(!0);const R=k=>{const g=k.clientY-c.current;o(h(i.current+g))},y=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",y),u()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",y)},[o,u]),b=t.useCallback(f=>{if(f.touches.length!==1)return;const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=f.touches[0].clientY,i.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",_e.setTerminalResizing(!0);const R=k=>{if(k.touches.length!==1)return;k.preventDefault();const g=k.touches[0].clientY-c.current;o(h(i.current+g))},y=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",y),document.removeEventListener("touchcancel",y),u()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",y),document.addEventListener("touchcancel",y)},[o,u]);return{mobileTreeHeight:s,handleResizeMouseDown:p,handleResizeTouchStart:b}}function rs(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[i,r]=t.useState(null),[h,o]=t.useState(null),u=t.useCallback(async k=>{c(!0),r(null);try{const g=await W(B(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),j=await g.json();g.ok?n(j.branches||[]):(r(j.error||"Failed to load branches"),n([]))}catch(g){console.error("[GitBranches] Failed to load branches:",g),r("Failed to load branches"),n([])}finally{c(!1)}},[]),p=t.useCallback(async(k,g)=>{o("checkout"),r(null);try{const j=await W(B("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:g})}),w=await j.json();return j.ok||r(w.error||"Checkout failed"),w}catch(j){console.error("[GitBranches] Checkout failed:",j);const w={success:!1,error:"Checkout failed"};return r(w.error),w}finally{o(null)}},[]),b=t.useCallback(async(k,g,j)=>{o("create"),r(null);try{const w=await W(B("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:g,startPoint:j})}),T=await w.json();return w.ok||r(T.error||"Failed to create branch"),T}catch(w){console.error("[GitBranches] Create branch failed:",w);const T={success:!1,error:"Failed to create branch"};return r(T.error),T}finally{o(null)}},[]),f=t.useCallback(async k=>{o("pull"),r(null);try{const g=await W(B("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return!g.ok&&!j.conflicts&&r(j.error||"Pull failed"),j}catch(g){console.error("[GitBranches] Pull failed:",g);const j={success:!1,error:"Pull failed"};return r(j.error),j}finally{o(null)}},[]),v=t.useCallback(async k=>{o("push"),r(null);try{const g=await W(B("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||r(j.error||"Push failed"),j}catch(g){console.error("[GitBranches] Push failed:",g);const j={success:!1,error:"Push failed"};return r(j.error),j}finally{o(null)}},[]),N=t.useCallback(async(k,g)=>{o("merge"),r(null);try{const j=await W(B("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:g})}),w=await j.json();return!j.ok&&!w.conflicts&&r(w.error||"Merge failed"),w}catch(j){console.error("[GitBranches] Merge failed:",j);const w={success:!1,error:"Merge failed"};return r(w.error),w}finally{o(null)}},[]),R=t.useCallback(async k=>{o("merge-abort"),r(null);try{const g=await W(B("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||r(j.error||"Merge abort failed"),j}catch(g){console.error("[GitBranches] Merge abort failed:",g);const j={success:!1,error:"Merge abort failed"};return r(j.error),j}finally{o(null)}},[]),y=t.useCallback(async k=>{o("merge-continue"),r(null);try{const g=await W(B("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||r(j.error||"Merge continue failed"),j}catch(g){console.error("[GitBranches] Merge continue failed:",g);const j={success:!1,error:"Merge continue failed"};return r(j.error),j}finally{o(null)}},[]);return{branches:s,loading:l,error:i,operationInProgress:h,loadBranches:u,checkoutBranch:p,createBranch:b,pullFromRemote:f,pushToRemote:v,mergeBranch:N,mergeAbort:R,mergeContinue:y}}const Ma=50,Da=400,Ks={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function Ra(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[i,r]=t.useState(!1),[h,o]=t.useState(null),[u,p]=t.useState(!1),[b,f]=t.useState(0),[v,N]=t.useState({...Ks}),[R,y]=t.useState(null),[k,g]=t.useState([]),[j,w]=t.useState(!1),[T,A]=t.useState([]),[K,C]=t.useState(!1),O=t.useRef(null),ae=t.useRef(""),Y=t.useCallback((U,Z,P)=>{const G=P||v,I=new URLSearchParams;return I.set("path",U),I.set("limit",String(Ma)),I.set("offset",String(Z)),G.branch&&I.set("branch",G.branch),G.author&&I.set("author",G.author),G.since&&I.set("since",G.since),G.until&&I.set("until",G.until),G.searchPath&&I.set("searchPath",G.searchPath),G.search&&I.set("search",G.search),I.toString()},[v]),D=t.useCallback(async U=>{ae.current=U,c(!0),o(null),y(null),g([]);try{const Z=Y(U,0),P=await W(B(`/api/files/git-log?${Z}`)),G=await P.json();P.ok?(n(G.commits||[]),f(G.total||0),p(G.hasMore||!1)):(o(G.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),o("Failed to load git history"),n([])}finally{c(!1)}},[Y]),F=t.useCallback(async U=>{if(!(i||!u)){r(!0);try{const Z=Y(U,s.length),P=await W(B(`/api/files/git-log?${Z}`)),G=await P.json();P.ok&&(n(I=>[...I,...G.commits||[]]),f(G.total||0),p(G.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{r(!1)}}},[Y,s.length,u,i]),V=t.useCallback(async U=>{if(y(U),!U){g([]);return}w(!0);try{const Z=ae.current,P=new URLSearchParams({path:Z,hash:U.hash}),G=await W(B(`/api/files/git-commit-files?${P}`)),I=await G.json();G.ok?g(I.files||[]):g([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),g([])}finally{w(!1)}},[]),ne=t.useCallback((U,Z)=>{N(P=>({...P,[U]:Z}))},[]),re=t.useCallback(()=>{N({...Ks})},[]);t.useEffect(()=>{const U=ae.current;if(U)return O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{D(U)},Da),()=>{O.current&&clearTimeout(O.current)}},[v]);const je=t.useCallback(async U=>{C(!0);try{const Z=new URLSearchParams({path:U}),P=await W(B(`/api/files/git-authors?${Z}`)),G=await P.json();P.ok&&A(G.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{C(!1)}},[]);return{commits:s,loading:l,loadingMore:i,error:h,hasMore:u,total:b,filters:v,setFilter:ne,resetFilters:re,selectedCommit:R,selectCommit:V,commitFiles:k,commitFilesLoading:j,loadHistory:D,loadMore:F,authors:T,authorsLoading:K,loadAuthors:je}}function Fa(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const c=s.current.querySelector(l);if(c&&Vs(c))return c}return Vs(s.current)?s.current:null}function Vs(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function sn(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function ts(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Pa(s){const{scrollTop:n,scrollHeight:l,clientHeight:c}=s;return l<=c?100:Math.round(n/(l-c)*100)}function Ia(s,n){const l=sn(s),c=s.scrollTop,i=Math.floor(c/l)+1,r=n.split(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-5po-iz0Q.js","assets/main-06kmV-SQ.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-3OKhI9bz.js","assets/main-BzGnAbiA.css","assets/EmbeddedEditor-BipHj7Fz.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as t,c as W,d as B,K as Zt,a_ as Ys,S as Ht,a$ as Xs,s as _e,u as oe,j as e,I as M,ca as At,bj as _n,cb as Qs,$ as Kn,cc as Zs,cd as en,ce as Vn,cf as Wn,cg as Lt,ch as qn,ci as Jn,cj as Yn,ck as Ot,cl as Xn,cm as as,cn as Qn,co as tn,cp as $t,cq as zt,bi as it,cr as gt,cs as xt,ct as As,cu as Zn,a2 as ea,cv as ns,_ as ta,cw as sa,cx as na,cy as Pt,cz as aa,cA as ra,cB as ia,cC as la,cD as oa,cE as Os,X as ca,al as da}from"./main-06kmV-SQ.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-3OKhI9bz.js";function ua(s){const[n,l]=t.useState(null),[c,i]=t.useState(!1),r=t.useCallback(async()=>{if(s){i(!0);try{const h=await W(B(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await h.json();h.ok?l(o):l({isGitRepo:!1,files:[]})}catch(h){console.error("[FileExplorer] Failed to load git status:",h),l({isGitRepo:!1,files:[]})}finally{i(!1)}}},[s]);return{gitStatus:n,loading:c,loadGitStatus:r}}async function ha(s){try{const n=await W(B(`/api/files/git-original?path=${encodeURIComponent(s)}`)),l=await n.json();return n.ok&&!l.isNew?{content:l.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const ma=new Set([".txt",".md",".markdown",".json",".yaml",".yml",".xml",".html",".htm",".css",".scss",".sass",".less",".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".rb",".c",".cpp",".h",".hpp",".cs",".go",".rs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".hs",".ml",".fs",".sql",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".toml",".ini",".cfg",".conf",".env",".gitignore",".dockerignore",".editorconfig",".prettierrc",".eslintrc",".babelrc",".log",".csv",".tsv",".svg",""]),fa=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),pa=new Set([".pdf"]),ga=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".zip",".tar",".gz",".rar",".7z",".exe",".dmg",".app",".deb",".rpm",".apk",".aab",".ipa",".msi",".mp3",".mp4",".wav",".avi",".mov",".mkv",".flac",".ogg",".webm",".ttf",".otf",".woff",".woff2",".eot",".sqlite",".db",".so",".dll",".dylib",".a",".o",".obj",".bin",".dat",".iso",".img",".jar",".war",".ear",".class"]);function xa(s){const n=s.toLowerCase();return fa.has(n)?"image":pa.has(n)?"pdf":ga.has(n)?"binary":(ma.has(n),"text")}function ya(){const[s,n]=t.useState(null),[l,c]=t.useState(!1),[i,r]=t.useState(null),h=t.useCallback(async u=>{var p,b;c(!0),r(null);try{const f=u.substring(u.lastIndexOf(".")).toLowerCase(),v=xa(f),N=u.substring(u.lastIndexOf("/")+1);if(v==="image"){const k=await W(B(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!k.ok){const w=await k.json().catch(()=>({error:"Failed to load image"}));r(w.error||"Failed to load image"),n(null);return}const g=await k.blob(),j=URL.createObjectURL(g);n({path:u,filename:N,extension:f,content:"",size:g.size,modified:new Date().toISOString(),fileType:"image",dataUrl:j});return}if(v==="pdf"){const k=await W(B(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(!k.ok){r(g.error||"Failed to load PDF info"),n(null);return}n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"pdf",dataUrl:B(`/api/files/binary?path=${encodeURIComponent(u)}&token=${encodeURIComponent(Zt())}`)});return}if(v==="binary"){const k=await W(B(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(!k.ok){r(g.error||"Failed to load file info"),n(null);return}n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"binary",dataUrl:B(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Zt())}`)});return}const R=await W(B(`/api/files/read?path=${encodeURIComponent(u)}`)),y=await R.json();if(!R.ok){if((p=y.error)!=null&&p.includes("too large")||(b=y.error)!=null&&b.includes("binary")){const k=await W(B(`/api/files/info?path=${encodeURIComponent(u)}`)),g=await k.json();if(k.ok){n({path:u,filename:N,extension:f,content:"",size:g.size,modified:g.modified,fileType:"binary",dataUrl:B(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Zt())}`)});return}}r(y.error||"Failed to load file"),n(null);return}n({...y,fileType:"text"})}catch(f){const v=f instanceof Error?f.message:"Failed to load file";r(v),n(null)}finally{c(!1)}},[]),o=t.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),r(null)},[]);return{file:s,loading:l,error:i,loadFile:h,clearFile:o,setFile:n}}const ba="file-explorer-state",Gs="file-explorer-recent-projects",ja=10080*60*1e3,va=12;function es(s){return`${ba}-folder-${s}`}async function wa(s){try{const n=await W(B(`/api/files/exists?path=${encodeURIComponent(s)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function Ca(){const s=t.useCallback(async i=>{if(!i)return null;try{const r=localStorage.getItem(es(i));if(!r)return null;const h=JSON.parse(r);if(Date.now()-h.timestamp>ja)return localStorage.removeItem(es(i)),null;const u=(await Promise.all((h.tabs||[]).map(async b=>({tab:b,exists:await wa(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let p=h.activeTabPath;return p&&!u.some(b=>b.path===p)&&(p=u.length>0?u[0].path:null),{tabs:u,activeTabPath:p,viewMode:h.viewMode||"files",expandedPaths:new Set(h.expandedPaths||[])}}catch(r){return console.error("[FileExplorerStorage] Failed to load project state:",r),null}},[]),n=t.useCallback((i,r)=>{if(i)try{const h={tabs:r.tabs,activeTabPath:r.activeTabPath,viewMode:r.viewMode,expandedPaths:Array.from(r.expandedPaths),timestamp:Date.now()};localStorage.setItem(es(i),JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save project state:",h)}},[]),l=t.useCallback(()=>{try{const i=localStorage.getItem(Gs);if(!i)return[];const r=JSON.parse(i);return Array.isArray(r)?r.filter(h=>typeof h=="string"):[]}catch{return[]}},[]),c=t.useCallback(i=>{if(!i)return l();const r=[i,...l().filter(h=>h!==i)].slice(0,va);try{localStorage.setItem(Gs,JSON.stringify(r))}catch{}return r},[l]);return{loadProjectState:s,saveProjectState:n,loadRecentProjects:l,pushRecentProject:c}}const Us=280,Bs=150,_s=1200;function Na(){const[s,n]=t.useState(()=>{const p=Ys(Ht.TREE_PANEL_WIDTH,Us);return p>=Bs&&p<=_s?p:Us}),l=t.useRef(!1),[c,i]=t.useState(!1),r=t.useRef(0),h=t.useRef(0),o=t.useRef(s);o.current=s;const u=t.useCallback(p=>{p.preventDefault(),l.current=!0,i(!0),r.current=p.clientX,h.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const p=f=>{if(!l.current)return;const v=f.clientX-r.current,N=Math.min(_s,Math.max(Bs,h.current+v));n(N)},b=()=>{l.current&&(l.current=!1,i(!1),document.body.style.cursor="",document.body.style.userSelect="",Xs(Ht.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",p),document.addEventListener("mouseup",b),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",b)}},[]),{treePanelWidth:s,handleResizeStart:u,isResizing:c}}const ka=100,Ea=.65,Sa=36;function Ta(){const[s,n]=t.useState(()=>Ys(Ht.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const c=t.useRef(0),i=t.useRef(0),r=()=>Math.floor((window.innerHeight-Sa)*Ea),h=f=>Math.min(r(),Math.max(ka,f)),o=t.useCallback(f=>{n(f);const v=document.querySelector(".file-explorer-main");v&&v.style.setProperty("--fe-mobile-tree-height",`${f}px`)},[]),u=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Xs(Ht.MOBILE_TREE_PANEL_HEIGHT,l.current),_e.setTerminalResizing(!1)},[]),p=t.useCallback(f=>{f.preventDefault();const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=f.clientY,i.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",_e.setTerminalResizing(!0);const R=k=>{const g=k.clientY-c.current;o(h(i.current+g))},y=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",y),u()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",y)},[o,u]),b=t.useCallback(f=>{if(f.touches.length!==1)return;const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=f.touches[0].clientY,i.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",_e.setTerminalResizing(!0);const R=k=>{if(k.touches.length!==1)return;k.preventDefault();const g=k.touches[0].clientY-c.current;o(h(i.current+g))},y=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",y),document.removeEventListener("touchcancel",y),u()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",y),document.addEventListener("touchcancel",y)},[o,u]);return{mobileTreeHeight:s,handleResizeMouseDown:p,handleResizeTouchStart:b}}function rs(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[i,r]=t.useState(null),[h,o]=t.useState(null),u=t.useCallback(async k=>{c(!0),r(null);try{const g=await W(B(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),j=await g.json();g.ok?n(j.branches||[]):(r(j.error||"Failed to load branches"),n([]))}catch(g){console.error("[GitBranches] Failed to load branches:",g),r("Failed to load branches"),n([])}finally{c(!1)}},[]),p=t.useCallback(async(k,g)=>{o("checkout"),r(null);try{const j=await W(B("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:g})}),w=await j.json();return j.ok||r(w.error||"Checkout failed"),w}catch(j){console.error("[GitBranches] Checkout failed:",j);const w={success:!1,error:"Checkout failed"};return r(w.error),w}finally{o(null)}},[]),b=t.useCallback(async(k,g,j)=>{o("create"),r(null);try{const w=await W(B("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:g,startPoint:j})}),T=await w.json();return w.ok||r(T.error||"Failed to create branch"),T}catch(w){console.error("[GitBranches] Create branch failed:",w);const T={success:!1,error:"Failed to create branch"};return r(T.error),T}finally{o(null)}},[]),f=t.useCallback(async k=>{o("pull"),r(null);try{const g=await W(B("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return!g.ok&&!j.conflicts&&r(j.error||"Pull failed"),j}catch(g){console.error("[GitBranches] Pull failed:",g);const j={success:!1,error:"Pull failed"};return r(j.error),j}finally{o(null)}},[]),v=t.useCallback(async k=>{o("push"),r(null);try{const g=await W(B("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||r(j.error||"Push failed"),j}catch(g){console.error("[GitBranches] Push failed:",g);const j={success:!1,error:"Push failed"};return r(j.error),j}finally{o(null)}},[]),N=t.useCallback(async(k,g)=>{o("merge"),r(null);try{const j=await W(B("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:g})}),w=await j.json();return!j.ok&&!w.conflicts&&r(w.error||"Merge failed"),w}catch(j){console.error("[GitBranches] Merge failed:",j);const w={success:!1,error:"Merge failed"};return r(w.error),w}finally{o(null)}},[]),R=t.useCallback(async k=>{o("merge-abort"),r(null);try{const g=await W(B("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||r(j.error||"Merge abort failed"),j}catch(g){console.error("[GitBranches] Merge abort failed:",g);const j={success:!1,error:"Merge abort failed"};return r(j.error),j}finally{o(null)}},[]),y=t.useCallback(async k=>{o("merge-continue"),r(null);try{const g=await W(B("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await g.json();return g.ok||r(j.error||"Merge continue failed"),j}catch(g){console.error("[GitBranches] Merge continue failed:",g);const j={success:!1,error:"Merge continue failed"};return r(j.error),j}finally{o(null)}},[]);return{branches:s,loading:l,error:i,operationInProgress:h,loadBranches:u,checkoutBranch:p,createBranch:b,pullFromRemote:f,pushToRemote:v,mergeBranch:N,mergeAbort:R,mergeContinue:y}}const Ma=50,Da=400,Ks={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function Ra(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[i,r]=t.useState(!1),[h,o]=t.useState(null),[u,p]=t.useState(!1),[b,f]=t.useState(0),[v,N]=t.useState({...Ks}),[R,y]=t.useState(null),[k,g]=t.useState([]),[j,w]=t.useState(!1),[T,A]=t.useState([]),[K,C]=t.useState(!1),O=t.useRef(null),ae=t.useRef(""),Y=t.useCallback((U,Z,P)=>{const G=P||v,I=new URLSearchParams;return I.set("path",U),I.set("limit",String(Ma)),I.set("offset",String(Z)),G.branch&&I.set("branch",G.branch),G.author&&I.set("author",G.author),G.since&&I.set("since",G.since),G.until&&I.set("until",G.until),G.searchPath&&I.set("searchPath",G.searchPath),G.search&&I.set("search",G.search),I.toString()},[v]),D=t.useCallback(async U=>{ae.current=U,c(!0),o(null),y(null),g([]);try{const Z=Y(U,0),P=await W(B(`/api/files/git-log?${Z}`)),G=await P.json();P.ok?(n(G.commits||[]),f(G.total||0),p(G.hasMore||!1)):(o(G.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),o("Failed to load git history"),n([])}finally{c(!1)}},[Y]),F=t.useCallback(async U=>{if(!(i||!u)){r(!0);try{const Z=Y(U,s.length),P=await W(B(`/api/files/git-log?${Z}`)),G=await P.json();P.ok&&(n(I=>[...I,...G.commits||[]]),f(G.total||0),p(G.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{r(!1)}}},[Y,s.length,u,i]),V=t.useCallback(async U=>{if(y(U),!U){g([]);return}w(!0);try{const Z=ae.current,P=new URLSearchParams({path:Z,hash:U.hash}),G=await W(B(`/api/files/git-commit-files?${P}`)),I=await G.json();G.ok?g(I.files||[]):g([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),g([])}finally{w(!1)}},[]),ne=t.useCallback((U,Z)=>{N(P=>({...P,[U]:Z}))},[]),re=t.useCallback(()=>{N({...Ks})},[]);t.useEffect(()=>{const U=ae.current;if(U)return O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{D(U)},Da),()=>{O.current&&clearTimeout(O.current)}},[v]);const je=t.useCallback(async U=>{C(!0);try{const Z=new URLSearchParams({path:U}),P=await W(B(`/api/files/git-authors?${Z}`)),G=await P.json();P.ok&&A(G.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{C(!1)}},[]);return{commits:s,loading:l,loadingMore:i,error:h,hasMore:u,total:b,filters:v,setFilter:ne,resetFilters:re,selectedCommit:R,selectCommit:V,commitFiles:k,commitFilesLoading:j,loadHistory:D,loadMore:F,authors:T,authorsLoading:K,loadAuthors:je}}function Fa(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const c=s.current.querySelector(l);if(c&&Vs(c))return c}return Vs(s.current)?s.current:null}function Vs(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function sn(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function ts(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Pa(s){const{scrollTop:n,scrollHeight:l,clientHeight:c}=s;return l<=c?100:Math.round(n/(l-c)*100)}function Ia(s,n){const l=sn(s),c=s.scrollTop,i=Math.floor(c/l)+1,r=n.split(`
|
|
3
3
|
`).length;return Math.min(i,r)}function La(s,n,l=!1){if(!n)return[];l||s.toLowerCase();const c=l?n:n.toLowerCase(),i=[];let r=0;const h=s.split(`
|
|
4
|
-
`);let o=0;for(let u=0;u<h.length;u++){const p=h[u],b=l?p:p.toLowerCase();let f=0,v=b.indexOf(c);for(;v!==-1;){const N=o+v;i.push({index:r++,line:u+1,column:v,length:c.length,charIndex:N}),f=v+c.length,v=b.indexOf(c,f)}o+=p.length+1}return i}function lt(s){return/[\w]/.test(s)}function Ke(s){return/\s/.test(s)}function $a(s,n,l){let c=n-1,i=l;const r=s.length,h=s[c]||"";if(i<h.length){const p=lt(h[i]);if(!Ke(h[i]))for(;i<h.length&&!Ke(h[i])&<(h[i])===p;)i++}for(;c<r;){const p=s[c]||"";for(;i<p.length&&Ke(p[i]);)i++;if(i<p.length)return{line:c+1,col:i};c++,i=0}const o=r,u=Math.max(0,(s[r-1]||"").length-1);return{line:o,col:u}}function
|
|
4
|
+
`);let o=0;for(let u=0;u<h.length;u++){const p=h[u],b=l?p:p.toLowerCase();let f=0,v=b.indexOf(c);for(;v!==-1;){const N=o+v;i.push({index:r++,line:u+1,column:v,length:c.length,charIndex:N}),f=v+c.length,v=b.indexOf(c,f)}o+=p.length+1}return i}function lt(s){return/[\w]/.test(s)}function Ke(s){return/\s/.test(s)}function $a(s,n,l){let c=n-1,i=l;const r=s.length,h=s[c]||"";if(i<h.length){const p=lt(h[i]);if(!Ke(h[i]))for(;i<h.length&&!Ke(h[i])&<(h[i])===p;)i++}for(;c<r;){const p=s[c]||"";for(;i<p.length&&Ke(p[i]);)i++;if(i<p.length)return{line:c+1,col:i};c++,i=0}const o=r,u=Math.max(0,(s[r-1]||"").length-1);return{line:o,col:u}}function za(s,n,l){let c=n-1,i=l+1;const r=s.length;for(;c<r;){const u=s[c]||"";for(;i<u.length&&Ke(u[i]);)i++;if(i<u.length)break;c++,i=0}if(c>=r)return{line:r,col:Math.max(0,(s[r-1]||"").length-1)};const h=s[c]||"",o=lt(h[i]);for(;i+1<h.length&&!Ke(h[i+1])&<(h[i+1])===o;)i++;return{line:c+1,col:i}}function Ha(s,n,l){let c=n-1,i=l-1;for(;c>=0;){const o=s[c]||"";for(;i>=0&&Ke(o[i]);)i--;if(i>=0)break;c--,c>=0&&(i=(s[c]||"").length-1)}if(c<0)return{line:1,col:0};const r=s[c]||"",h=lt(r[i]);for(;i>0&&!Ke(r[i-1])&<(r[i-1])===h;)i--;return{line:c+1,col:i}}function Aa(s,n,l,c){if(c==="none")return"";const{anchorLine:i,anchorCol:r,headLine:h,headCol:o}=l;if(c==="line"){const N=Math.min(i,h),R=Math.max(i,h);return n.slice(N-1,R).join(`
|
|
5
5
|
`)}let u,p,b,f;if(i<h||i===h&&r<=o?(u=i,p=r,b=h,f=o):(u=h,p=o,b=i,f=r),u===b)return(n[u-1]||"").substring(p,f+1);const v=[];v.push((n[u-1]||"").substring(p));for(let N=u;N<b-1;N++)v.push(n[N]||"");return v.push((n[b-1]||"").substring(0,f+1)),v.join(`
|
|
6
6
|
`)}function nn(s){const{containerRef:n,isEnabled:l=!0,content:c="",onClose:i,onSearchOpen:r}=s,h=t.useRef({percentage:0,line:1,column:1}),o=t.useRef(null),u=t.useRef(19.5),p=t.useMemo(()=>c.split(`
|
|
7
|
-
`),[c]),b=p.length,[f,v]=t.useState(1),[N,R]=t.useState(0),[y,k]=t.useState(!1),[g,j]=t.useState("none"),[w,T]=t.useState(null),[A,K]=t.useState(!1),[C,O]=t.useState(""),[ae,Y]=t.useState(0),[D,F]=t.useState(!1),V=t.useMemo(()=>La(c,C,!1),[c,C]),ne=t.useCallback(()=>{const m=o.current;if(!m)return;const X=Pa(m),le=Ia(m,c),$=Math.max(1,Math.round(m.scrollLeft/7.8)+1);h.current={percentage:X,line:le,column:$}},[c]),re=t.useCallback(()=>{K(!0),O(""),Y(0),r==null||r()},[r]),je=t.useCallback(()=>{K(!1),O(""),Y(0)},[]),U=t.useCallback(()=>{F(m=>!m)},[]),Z=t.useCallback(m=>{const X=o.current;if(!X)return;const le=X.querySelector(".file-viewer-pre"),z=le&&parseFloat(getComputedStyle(le).lineHeight)||u.current,$=le&&parseFloat(getComputedStyle(le).paddingTop)||0,te=(le?le.offsetTop:0)+$+(m-1)*z,Q=z*3;X.scrollTo({top:Math.max(0,te-Q),behavior:"smooth"})},[]);t.useEffect(()=>{!A||V.length===0||Y(0)},[V,A]),t.useEffect(()=>{if(!A||V.length===0)return;const m=V[ae];m&&(v(m.line),R(m.column),Z(m.line))},[A,V,ae,Z]);const P=t.useCallback(()=>{V.length!==0&&Y(m=>(m+1)%V.length)},[V]),G=t.useCallback(()=>{V.length!==0&&Y(m=>(m-1+V.length)%V.length)},[V]),I=t.useCallback(m=>{const X=o.current;if(!X)return;const le=X.querySelector(".file-viewer-pre");if(!le)return;const z=parseFloat(getComputedStyle(le).lineHeight),$=isNaN(z)?u.current:z,S=parseFloat(getComputedStyle(le).paddingTop)||0,Q=le.offsetTop+S+(m-1)*$,de=Q+$,pe=X.scrollTop,se=pe+X.clientHeight;Q<pe?X.scrollTo({top:Math.max(0,Q),behavior:"auto"}):de>se&&X.scrollTo({top:de-X.clientHeight,behavior:"auto"})},[]),ie=t.useCallback((m,X)=>{v(m),R(X),I(m),g!=="none"&&T(le=>le?{...le,headLine:m,headCol:X}:null)},[g,I]),ee=t.useCallback(()=>{if(g==="none"||!w)return;const m=Aa(c,p,w,g);m&&navigator.clipboard.writeText(m).catch(()=>{const X=document.createElement("textarea");X.value=m,X.style.position="fixed",X.style.left="-9999px",document.body.appendChild(X),X.select(),document.execCommand("copy"),document.body.removeChild(X)}),j("none"),T(null)},[g,w,c,p]),ve=t.useCallback(m=>{const X=m.target;if((X.tagName==="INPUT"||X.tagName==="TEXTAREA")&&m.key!=="Escape")return;const z=o.current;if(!z)return;let $=!1;const S=u.current,te=Math.max(1,Math.floor(z.clientHeight/S)),Q=Math.max(1,Math.floor(te/2)),de=(se,we)=>{const Ge=Math.max(0,(p[se-1]||"").length-1);return Math.min(we,Math.max(0,Ge))},pe=(se,we)=>{const Ge=de(se,we);ie(se,Ge)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),g==="char"?(j("none"),T(null)):(j("char"),T({anchorLine:f,anchorCol:N,headLine:f,headCol:N})),$=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),g==="line"?(j("none"),T(null)):(j("line"),T({anchorLine:f,anchorCol:0,headLine:f,headCol:0})),$=!0;else if(m.key==="y"&&!m.ctrlKey&&g!=="none")m.preventDefault(),m.stopPropagation(),ee(),$=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const se=Math.min(f+1,b);pe(se,N),$=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const se=Math.max(f-1,1);pe(se,N),$=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.min(f+Q,b);pe(se,N),$=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.max(f-Q,1);pe(se,N),$=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),re(),$=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.min(f+te,b);pe(se,N),$=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const se=Math.min(f+te,b);pe(se,N),$=!0}else if(m.key==="b"&&!y&&g==="none"&&!A||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const se=Math.max(f-te,1);pe(se,N),$=!0}else if(m.key==="g"&&!m.shiftKey&&g==="none"&&!A)m.preventDefault(),m.stopPropagation(),ie(1,0),ts(z,!1),$=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),ie(1,0),ts(z,!1),$=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),ie(b,0),ts(z,!0),$=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),ie(f,Math.max(0,N-1)),$=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const se=(p[f-1]||"").length;ie(f,Math.min(N+1,Math.max(0,se-1))),$=!0}else if(m.key==="w"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const se=$a(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="e"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const se=Ha(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="b"&&!A){m.preventDefault(),m.stopPropagation();const se=za(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),ie(f,0),$=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),ie(f,Math.max(0,(p[f-1]||"").length-1)),$=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const we=(p[f-1]||"").search(/\S/);ie(f,we>=0?we:0),$=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),re(),$=!0):m.key==="n"&&!A?(m.preventDefault(),m.stopPropagation(),P(),$=!0):m.key==="N"&&m.shiftKey&&!A?(m.preventDefault(),m.stopPropagation(),G(),$=!0):m.key==="?"&&g==="none"?(m.preventDefault(),m.stopPropagation(),U(),$=!0):m.key==="q"&&g==="none"?(m.preventDefault(),m.stopPropagation(),i==null||i(),$=!0):m.key==="Escape"&&(g!=="none"?(m.preventDefault(),m.stopPropagation(),j("none"),T(null),$=!0):A?(m.preventDefault(),m.stopPropagation(),je(),$=!0):y&&(m.preventDefault(),m.stopPropagation(),k(!1),$=!0));$&&(m.key!=="Escape"&&!y&&k(!0),requestAnimationFrame(ne))},[i,ne,b,p,f,N,I,A,je,g,y,ie,ee,re,P,G,U]);return t.useEffect(()=>{if(!l)return;const m=Fa(n);if(o.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=sn(m);const X=()=>{ne()};return window.addEventListener("keydown",ve,{capture:!0}),m.addEventListener("scroll",X,{passive:!0}),ne(),()=>{window.removeEventListener("keydown",ve,{capture:!0}),m.removeEventListener("scroll",X)}},[l,ve,ne]),{scrollPercentage:h.current.percentage,currentLine:h.current.line,currentColumn:h.current.column,totalLines:b,cursorLine:f,cursorCol:N,cursorModeActive:y,visualMode:g,selection:w,searchActive:A,searchQuery:C,searchMatches:V,currentMatchIndex:ae,startSearch:re,setSearchQuery:O,nextMatch:P,prevMatch:G,clearSearch:je,helpActive:D,toggleHelp:U}}const is=({query:s,onQueryChange:n,matchCount:l,currentIndex:c,onNext:i,onPrev:r,onClose:h})=>{const{t:o}=oe(["terminal"]),u=t.useRef(null);t.useEffect(()=>{var f;(f=u.current)==null||f.focus()},[]);const p=t.useCallback(f=>{f.stopPropagation(),f.key==="Enter"||f.key==="ArrowDown"?(f.preventDefault(),i()):f.key==="ArrowUp"&&(f.preventDefault(),r())},[i,r]),b=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${c+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:u,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:f=>n(f.target.value),onKeyDown:p,autoComplete:"off",spellCheck:"false"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:b}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:r,disabled:l===0,title:o("terminal:fileExplorer.previousMatch"),"aria-label":o("terminal:fileExplorer.previousMatch"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:i,disabled:l===0,title:o("terminal:fileExplorer.nextMatch"),"aria-label":o("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:h,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};is.displayName="SearchBar";const Oa=[{keys:["j","↓"],description:"Move cursor down one line",category:"Navigation"},{keys:["k","↑"],description:"Move cursor up one line",category:"Navigation"},{keys:["h","←"],description:"Move cursor left",category:"Navigation"},{keys:["l","→"],description:"Move cursor right",category:"Navigation"},{keys:["0"],description:"Jump to start of line",category:"Navigation"},{keys:["$"],description:"Jump to end of line",category:"Navigation"},{keys:["^"],description:"First non-whitespace char",category:"Navigation"},{keys:["d","Ctrl+D"],description:"Half page down",category:"Navigation"},{keys:["u","Ctrl+U"],description:"Half page up",category:"Navigation"},{keys:["f","Space"],description:"Full page down",category:"Navigation"},{keys:["b","Page Up"],description:"Full page up",category:"Navigation"},{keys:["g","Home"],description:"Jump to top of file",category:"Navigation"},{keys:["G","End"],description:"Jump to bottom of file",category:"Navigation"},{keys:["w"],description:"Next word start",category:"Word Motion"},{keys:["e"],description:"Next word end",category:"Word Motion"},{keys:["b"],description:"Previous word start",category:"Word Motion"},{keys:["v"],description:"Character visual mode",category:"Visual Mode"},{keys:["V"],description:"Line visual mode",category:"Visual Mode"},{keys:["y"],description:"Yank (copy) selection",category:"Visual Mode"},{keys:["Escape"],description:"Exit visual mode",category:"Visual Mode"},{keys:["/"],description:"Open search bar",category:"Search"},{keys:["n"],description:"Next match",category:"Search"},{keys:["N"],description:"Previous match",category:"Search"},{keys:["?"],description:"Toggle this help overlay",category:"Help"},{keys:["Escape"],description:"Exit cursor mode (or visual/search)",category:"Help"},{keys:["Alt+E"],description:"Close file viewer",category:"Help"},{keys:["q"],description:"Close file viewer",category:"Help"}],ls=({onClose:s})=>{const{t:n}=oe(["terminal"]),l=t.useCallback(r=>{r.target===r.currentTarget&&s()},[s]),c=t.useCallback(r=>{(r.key==="Escape"||r.key==="?")&&(r.preventDefault(),r.stopPropagation(),s())},[s]),i=Oa.reduce((r,h)=>(r[h.category]||(r[h.category]=[]),r[h.category].push(h),r),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:c,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(i).map(([r,h])=>e.jsxs("div",{className:"keybindings-help-category",children:[e.jsx("h3",{className:"keybindings-help-category-title",children:r}),e.jsx("div",{className:"keybindings-help-list",children:h.map((o,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((p,b)=>e.jsx("kbd",{className:"keybindings-help-key",children:p},b))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},u))})]},r))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};ls.displayName="KeybindingsHelp";const Ws=t.lazy(()=>Kn(()=>import("./EmbeddedEditor-BA9mX_Lg.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Ga=[".md",".mdx",".markdown"],qs="file-viewer-markdown-render",Ua=[".puml",".plantuml",".iuml",".pu"],Js="file-viewer-plantuml-render",Ba="https://kroki.io/plantuml/svg";function _a(s){return Ga.includes(s.toLowerCase())}function Ka(s){return Ua.includes(s.toLowerCase())}function Va(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(qs);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const i=!c;try{localStorage.setItem(qs,String(i))}catch{}return i})},[]);return[s,l]}function Wa(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Js);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const i=!c;try{localStorage.setItem(Js,String(i))}catch{}return i})},[]);return[s,l]}function qa(s){const n=new TextEncoder().encode(s);let l="";for(const c of n)l+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(l)}`}function Ve({file:s,rightContent:n,onRevealInTree:l,editMode:c,onToggleEdit:i}){const{t:r}=oe(["terminal","common"]),[h,o]=t.useState("idle"),[u,p]=t.useState("idle"),[b,f]=t.useState("idle"),v=s.fileType==="text"?At(s.extension):s.extension.slice(1).toUpperCase(),N=s.fileType==="text"&&s.content!=null,R=_n(),y=async()=>{try{await Lt(s.content),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},k=async()=>{const T=B(`/api/files/binary?path=${encodeURIComponent(s.path)}&download=true`);await Ot(T,s.filename,"text/plain;charset=utf-8")},g=async()=>{o("loading");try{const T=await W(B("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!T.ok){const A=await T.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",A),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(T){console.error("Error opening file in editor:",T),o("error"),setTimeout(()=>o("idle"),2e3)}},j=async()=>{if(s.path)try{await Xn(s.path),p("success"),setTimeout(()=>p("idle"),2e3)}catch(T){console.error("Error opening file explorer:",T),p("error"),setTimeout(()=>p("idle"),2e3)}},w=r("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:s.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[Qs(s.size)," • ",v,s.content&&` • ${s.content.split(`
|
|
8
|
-
`).length} lines`]})]}),e.jsxs("div",{className:"file-viewer-header-right",children:[i&&s.fileType==="text"&&e.jsx("button",{className:`file-viewer-edit-btn${c?" active":""}`,onClick:i,title:r(c?"terminal:fileExplorer.exitEdit":"terminal:fileExplorer.editFile"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L3.463 11.1a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.25.25 0 00.108-.064l8.61-8.61a.25.25 0 000-.354l-1.086-1.086z"})})}),N&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:y,title:r("terminal:fileExplorer.copyAllTitle"),children:r(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyAll")}),e.jsx("button",{className:"file-viewer-download-btn",onClick:k,title:r("terminal:fileExplorer.downloadFileTitle"),children:r("common:buttons.download")})]}),e.jsx("button",{className:`file-viewer-reveal-explorer-btn ${u}`,onClick:j,disabled:!s.path,title:w,"aria-label":w,children:u==="success"?e.jsx(M,{name:"check",size:14}):u==="error"?e.jsx(M,{name:"cross",size:14}):e.jsx(M,{name:"folder-open",size:14})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${h}`,onClick:g,disabled:h==="loading",title:r(h==="error"?"terminal:fileExplorer.failedToOpenEditor":h==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:h==="success"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 11-1.06-1.06l7.25-7.25a.75.75 0 011.06 0z"})}):h==="error"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1.5 1h6v1.5h-5v11h11v-5H15v6.5H0V1h1.5zm8 0H15v5.5h-1.5V3.56L7.28 9.78l-1.06-1.06L12.44 2.5H9.5V1z"})})}),l&&e.jsx("button",{className:"file-viewer-locate-btn",onClick:()=>l(s.path),title:r("terminal:fileExplorer.locateInTree"),children:e.jsx(M,{name:"target",size:14})}),n]})]})}function Ja({file:s,onRevealInTree:n,renderMarkdown:l,onToggleRender:c,editMode:i,onToggleEdit:r}){const h=t.useRef(null),o=t.useRef(null),u=t.useRef(null),{t:p}=oe(["terminal","common"]),[b,f]=t.useState("idle"),[v,N]=t.useState("idle"),[R,y]=t.useState("idle"),[k,g]=t.useState("idle"),j=nn({containerRef:u,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&h.current){const O=At(s.extension);Zs(O).then(()=>{h.current&&en(h.current)})}},[s,l]);const w=t.useCallback(async()=>{if(!o.current){f("error"),setTimeout(()=>f("idle"),2e3);return}try{const O=o.current.innerHTML,ae=Vn(O),Y=o.current.innerText;await Wn(ae,Y),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},[]),T=t.useCallback(async()=>{if(!o.current){N("error"),setTimeout(()=>N("idle"),2e3);return}try{const O=o.current.innerHTML;await Lt(O),N("copied"),setTimeout(()=>N("idle"),2e3)}catch{N("error"),setTimeout(()=>N("idle"),2e3)}},[]),A=t.useCallback(async()=>{try{await Lt(s.content),y("copied"),setTimeout(()=>y("idle"),2e3)}catch{y("error"),setTimeout(()=>y("idle"),2e3)}},[s.content]),K=t.useCallback(async()=>{try{await Lt(s.content),g("copied"),setTimeout(()=>g("idle"),2e3)}catch{g("error"),setTimeout(()=>g("idle"),2e3)}},[s.content]),C=e.jsxs("div",{className:"file-viewer-header-buttons",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:w,title:p("terminal:fileExplorer.copyRichTextTitle"),children:p(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${v}`,onClick:T,title:p("terminal:fileExplorer.copyHtmlTitle"),children:p(v==="copied"?"terminal:fileExplorer.copied":v==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${R}`,onClick:A,title:p("terminal:fileExplorer.copyMarkdownTitle"),children:p(R==="copied"?"terminal:fileExplorer.copied":R==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${k}`,onClick:K,title:p("terminal:fileExplorer.copyOriginalTitle"),children:p(k==="copied"?"terminal:fileExplorer.copied":k==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:p(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:l?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:C,editMode:i,onToggleEdit:r}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[l?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:o,children:e.jsx(qn,{remarkPlugins:[Jn],children:s.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:h,className:"language-markdown",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${j.currentLine}/${j.totalLines}`,children:j.scrollPercentage===100?"END":j.scrollPercentage===0?"TOP":`${j.scrollPercentage}%`}),j.searchActive&&e.jsx(is,{query:j.searchQuery,onQueryChange:j.setSearchQuery,matchCount:j.searchMatches.length,currentIndex:j.currentMatchIndex,onNext:j.nextMatch,onPrev:j.prevMatch,onClose:j.clearSearch})]}),j.helpActive&&e.jsx(ls,{onClose:j.toggleHelp})]})}function Ya({file:s,onRevealInTree:n,renderPlantUml:l,onToggleRender:c,editMode:i,onToggleEdit:r}){const{t:h}=oe(["terminal"]),o=t.useRef(null),u=t.useRef(null),[p,b]=t.useState(null),[f,v]=t.useState(!1),[N,R]=t.useState(null),y=nn({containerRef:u,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&o.current){const g=At(s.extension);Zs(g).then(()=>{o.current&&en(o.current)})}},[s,l]),t.useEffect(()=>{if(!l)return;if(!s.content.trim()){b(null),R("Diagram is empty");return}const g=new AbortController;return v(!0),R(null),(async()=>{try{const w=await fetch(Ba,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:s.content,signal:g.signal});if(!w.ok)throw new Error(`Render failed (${w.status})`);const T=await w.text();if(!T.includes("<svg"))throw new Error("Invalid SVG output");b(qa(T))}catch(w){if(g.signal.aborted)return;const T=w instanceof Error?w.message:"Failed to render diagram";R(T),b(null)}finally{g.signal.aborted||v(!1)}})(),()=>g.abort()},[s.path,s.content,l]);const k=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:h(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:l?"</>":h("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:k,editMode:i,onToggleEdit:r}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[l?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[f&&e.jsx("div",{className:"file-viewer-placeholder",children:h("terminal:fileExplorer.renderingDiagram")}),!f&&p&&e.jsx("img",{src:p,alt:s.filename,className:"file-viewer-diagram-image"}),!f&&N&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[h("terminal:fileExplorer.couldNotRender"),": ",N]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:c,children:h("terminal:fileExplorer.showSource")})]})]}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:o,className:"language-plaintext",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${y.currentLine}/${y.totalLines}`,children:y.scrollPercentage===100?"END":y.scrollPercentage===0?"TOP":`${y.scrollPercentage}%`}),y.searchActive&&e.jsx(is,{query:y.searchQuery,onQueryChange:y.setSearchQuery,matchCount:y.searchMatches.length,currentIndex:y.currentMatchIndex,onNext:y.nextMatch,onPrev:y.prevMatch,onClose:y.clearSearch})]}),y.helpActive&&e.jsx(ls,{onClose:y.toggleHelp})]})}function Xa({file:s,onRevealInTree:n}){const{t:l}=oe(["common","terminal"]),c=async()=>{const i=B(`/api/files/binary?path=${encodeURIComponent(s.path)}&download=true`);await Ot(i,s.filename)};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper zoomable",children:s.dataUrl?e.jsx(Yn,{src:s.dataUrl,alt:s.filename}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadImage")})})]})}function Qa({file:s,onRevealInTree:n}){const{t:l}=oe(["common","terminal"]),c=async()=>{const i=B(`/api/files/binary?path=${encodeURIComponent(s.path)}&download=true`);await Ot(i,s.filename,"application/pdf")};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:s.dataUrl?e.jsx("iframe",{src:s.dataUrl,title:s.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadPdf")})})]})}function Za({file:s,onRevealInTree:n}){const{t:l}=oe(["terminal","common"]),c=async()=>{const r=B(`/api/files/binary?path=${encodeURIComponent(s.path)}&download=true`);await Ot(r,s.filename)},i=()=>{const r=s.extension.toLowerCase();return[".xlsx",".xls"].includes(r)?e.jsx(M,{name:"dashboard",size:48}):[".docx",".doc"].includes(r)?e.jsx(M,{name:"edit",size:48}):[".pptx",".ppt"].includes(r)?e.jsx(M,{name:"film",size:48}):[".zip",".tar",".gz",".rar",".7z"].includes(r)?e.jsx(M,{name:"file-zip",size:48}):[".mp3",".wav",".flac",".ogg"].includes(r)?e.jsx(M,{name:"music-note",size:48}):[".mp4",".avi",".mov",".mkv",".webm"].includes(r)?e.jsx(M,{name:"film",size:48}):[".exe",".dmg",".app",".msi"].includes(r)?e.jsx(M,{name:"gear",size:48}):[".apk",".aab",".ipa"].includes(r)?e.jsx(M,{name:"mobile",size:48}):[".jar",".war",".ear"].includes(r)?e.jsx(M,{name:"coffee",size:48}):[".iso",".img"].includes(r)?e.jsx(M,{name:"disc",size:48}):[".so",".dll",".dylib"].includes(r)?e.jsx(M,{name:"wrench",size:48}):e.jsx(M,{name:"folder",size:48})};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n}),e.jsxs("div",{className:"file-viewer-binary",children:[e.jsx("div",{className:"file-viewer-binary-icon",children:i()}),e.jsx("div",{className:"file-viewer-binary-name",children:s.filename}),e.jsx("div",{className:"file-viewer-binary-size",children:Qs(s.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:l("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:c,children:l("terminal:fileExplorer.downloadFile")})]})]})}function er({file:s,loading:n,error:l,onRevealInTree:c,onFileEdited:i}){const{t:r}=oe(["terminal","common"]),[h,o]=Va(),[u,p]=Wa(),[b,f]=t.useState(!1);t.useEffect(()=>{f(!1)},[s==null?void 0:s.path]);const v=t.useCallback(async w=>{if(!s)return;const T=await W(B("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,content:w})});if(!T.ok){const A=await T.json().catch(()=>({error:"Save failed"}));throw new Error(A.error||"Save failed")}},[s]),N=t.useCallback(()=>{f(w=>(w&&s&&(i==null||i(s.path)),!w))},[s,i]),R=t.useCallback(()=>{s&&(i==null||i(s.path))},[s,i]);if(n)return e.jsx("div",{className:"file-viewer-placeholder",children:r("common:status.loading")});if(l)return e.jsx("div",{className:"file-viewer-placeholder error",children:l});if(!s)return e.jsxs("div",{className:"file-viewer-placeholder",children:[e.jsx("div",{className:"placeholder-icon",children:e.jsx(M,{name:"folder-open",size:32})}),e.jsx("div",{className:"placeholder-text",children:r("terminal:fileExplorer.selectFileToView")})]});const y=s.fileType||"text",k=y==="text"&&_a(s.extension),g=y==="text"&&Ka(s.extension),j=k||g;return j&&b&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:c,editMode:!0,onToggleEdit:N}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:r("common:status.loading")}),children:e.jsx(Ws,{content:s.content,extension:s.extension,onSave:v,onCancel:N},s.path)})]}):y==="text"&&!j&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:c}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:r("common:status.loading")}),children:e.jsx(Ws,{content:s.content,extension:s.extension,onSave:v,onCancel:R},s.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[k&&e.jsx(Ja,{file:s,onRevealInTree:c,renderMarkdown:h,onToggleRender:o,editMode:b,onToggleEdit:N}),g&&!k&&e.jsx(Ya,{file:s,onRevealInTree:c,renderPlantUml:u,onToggleRender:p,editMode:b,onToggleEdit:N}),y==="image"&&e.jsx(Xa,{file:s,onRevealInTree:c}),y==="pdf"&&e.jsx(Qa,{file:s,onRevealInTree:c}),y==="binary"&&e.jsx(Za,{file:s,onRevealInTree:c})]})}const an=t.memo(er,(s,n)=>s.loading!==n.loading||s.error!==n.error?!1:s.file===null&&n.file===null?!0:s.file===null||n.file===null?!1:s.file.path===n.file.path&&s.file.content===n.file.content&&s.file.modified===n.file.modified);an.displayName="FileViewer";function rn({text:s,query:n}){if(!n)return e.jsx(e.Fragment,{children:s});const l=Qn(s,n);if(l)return e.jsxs(e.Fragment,{children:[s.slice(0,l.start),e.jsx("mark",{className:"search-highlight",children:s.slice(l.start,l.end)}),s.slice(l.end)]});const c=n.toLowerCase(),r=s.toLowerCase().indexOf(c);return r===-1?e.jsx(e.Fragment,{children:s}):e.jsxs(e.Fragment,{children:[s.slice(0,r),e.jsx("mark",{className:"search-highlight",children:s.slice(r,r+n.length)}),s.slice(r+n.length)]})}const tr=t.memo(function({node:n,query:l,isSelected:c,onSelect:i,lineNumber:r}){const h=n.isDirectory?null:as(n),o=n.path.split("/");o[o.length-1];const u=o.slice(0,-1).join("/");return e.jsxs("div",{className:`search-result-item ${c?"selected":""}`,onClick:()=>i(n),children:[n.isDirectory?e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"folder",size:14})}):h?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${h}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{className:"search-result-info",children:[e.jsxs("span",{className:"search-result-name",children:[e.jsx(rn,{text:n.name,query:l}),r&&e.jsxs("span",{className:"search-result-line-badge",children:[":",r]})]}),e.jsx("span",{className:"search-result-path",children:u})]})]})}),sr=t.memo(function({match:n,query:l,isSelected:c,onSelect:i}){const{t:r}=oe(["terminal"]),h={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},o=as(h),u=n.path.split("/"),p=u[u.length-1],b=u.slice(0,-1).join("/");return e.jsxs("div",{className:`content-search-item ${c?"selected":""}`,children:[e.jsxs("div",{className:`content-search-header ${c?"selected":""}`,onClick:()=>i(n.path),children:[o?e.jsx("span",{className:"content-search-icon",style:{backgroundImage:`url('${o}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"content-search-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"2px"},children:[e.jsx("span",{className:"content-search-name",children:p}),e.jsx("span",{className:"search-result-path",style:{fontSize:"10px"},children:b})]}),e.jsx("span",{className:"content-search-count",children:n.matches.length})]}),e.jsxs("div",{className:"content-search-matches",children:[n.matches.slice(0,5).map((f,v)=>e.jsxs("div",{className:"content-search-match",onClick:()=>i(n.path,f.line),children:[e.jsx("span",{className:"content-search-line-num",children:f.line}),e.jsx("span",{className:"content-search-line-content",children:e.jsx(rn,{text:f.content.trim(),query:l})})]},`${n.path}-${f.line}-${v}`)),n.matches.length>5&&e.jsxs("div",{className:"content-search-match",style:{opacity:.6,cursor:"default"},children:[e.jsx("span",{className:"content-search-line-num",children:"..."}),e.jsx("span",{className:"content-search-line-content",children:r("terminal:fileExplorer.moreMatches",{count:n.matches.length-5})})]})]})]})});function nr({filenameResults:s,contentResults:n,onSelectFile:l,onSelectContent:c,selectedPath:i,query:r,lineNumber:h}){const{t:o}=oe(["terminal"]),u=s.length>0,p=n.length>0;return!u&&!p?e.jsx("div",{className:"search-no-results",children:o("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[u&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:s.length})]}),e.jsx("div",{className:"unified-search-section-content",children:s.map(b=>e.jsx(tr,{node:b,query:r,isSelected:i===b.path,onSelect:l,lineNumber:h},b.path))})]}),p&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"edit",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.content")}),e.jsx("span",{className:"unified-search-section-count",children:o("terminal:fileExplorer.matchesInFiles",{matches:n.reduce((b,f)=>b+f.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(b=>e.jsx(sr,{match:b,query:r,isSelected:i===b.path,onSelect:c},b.path))})]})]})}const ln=t.memo(nr,(s,n)=>!(s.query!==n.query||s.selectedPath!==n.selectedPath||s.filenameResults.length!==n.filenameResults.length||s.contentResults.length!==n.contentResults.length));ln.displayName="UnifiedSearchResults";const ar=t.memo(function({file:n,isSelected:l,onSelect:c,onStage:i,isStaging:r,showDirPath:h,isChecked:o,onToggleCheck:u,onContextMenu:p,onDiscard:b}){const{t:f}=oe(["terminal"]),v=n.status,N=xt[v],R=v==="deleted",y=v==="untracked"&&i,k=n.name.includes(".")?"."+n.name.split(".").pop():"",g=h&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!R&&c(n.path,v),onContextMenu:j=>{j.preventDefault(),p==null||p(j,n,v)},style:{cursor:R?"not-allowed":"pointer"},title:n.path,children:[u&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:o||!1,onChange:j=>{j.stopPropagation(),u(n.path)},onClick:j=>j.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:gt(k),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,g&&e.jsx("span",{className:"git-file-dir",children:g})]}),e.jsx("span",{className:"git-file-status",style:{color:N.color},children:N.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.oldPath.split("/").pop()]}),y&&e.jsx("button",{className:`git-stage-btn ${r?"staging":""}`,onClick:j=>{j.stopPropagation(),r||i(n.path)},title:f("terminal:fileExplorer.stageFile"),disabled:r,children:r?"...":"+"}),b&&e.jsx("button",{className:"git-discard-btn",onClick:j=>{j.stopPropagation(),b(n,v)},title:v==="untracked"||v==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}),rr=16,ir=22,lr=t.memo(function s({node:n,depth:l,expandedDirs:c,onToggleDir:i,selectedPath:r,onSelect:h,onStage:o,stagingPaths:u,checkedFiles:p,onToggleCheck:b,onContextMenu:f,onDirContextMenu:v,onDiscard:N}){const{t:R}=oe(["terminal"]),y=l*rr;if(!n.isDirectory){const g=n.file.status,j=xt[g];return e.jsxs("div",{className:`git-file-item ${r===n.path?"selected":""}`,onClick:()=>g!=="deleted"&&h(n.file.path,g),onContextMenu:w=>{w.preventDefault(),f==null||f(w,n.file,g)},style:{paddingLeft:`${y+ir}px`,cursor:g==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[b&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(p==null?void 0:p.has(n.file.path))||!1,onChange:w=>{w.stopPropagation(),b(n.file.path)},onClick:w=>w.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:gt(n.file.name.includes(".")?"."+n.file.name.split(".").pop():""),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:j.color},children:j.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.file.oldPath.split("/").pop()]}),g==="untracked"&&o&&e.jsx("button",{className:`git-stage-btn ${u!=null&&u.has(n.path)?"staging":""}`,onClick:w=>{w.stopPropagation(),u!=null&&u.has(n.path)||o(n.file.path)},title:R("terminal:fileExplorer.stageFile"),disabled:u==null?void 0:u.has(n.path),children:u!=null&&u.has(n.path)?"...":"+"}),N&&e.jsx("button",{className:"git-discard-btn",onClick:w=>{w.stopPropagation(),N(n.file,g)},title:g==="untracked"||g==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}const k=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${k?"expanded":""}`,style:{paddingLeft:`${y}px`},onClick:()=>i(n.path),onContextMenu:g=>{g.preventDefault(),g.stopPropagation(),v==null||v(g,n)},children:[e.jsx("span",{className:`tree-arrow ${k?"expanded":""}`,children:e.jsx(M,{name:"caret-right",size:10})}),e.jsx("img",{className:"tree-folder-icon",src:k?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:R("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),k&&e.jsx("div",{className:"tree-children",children:n.children.map(g=>e.jsx(s,{node:g,depth:l+1,expandedDirs:c,onToggleDir:i,selectedPath:r,onSelect:h,onStage:o,stagingPaths:u,checkedFiles:p,onToggleCheck:b,onContextMenu:f,onDirContextMenu:v,onDiscard:N},g.path))})]})}),ss=t.memo(function({groupLabel:n,groupIcon:l,groupColor:c,files:i,treeNodes:r,viewMode:h,selectedPath:o,expandedDirs:u,onToggleDir:p,onFileSelect:b,onStageFile:f,onStageAll:v,stagingPaths:N,checkedFiles:R,onToggleCheck:y,onContextMenu:k,onDirContextMenu:g,onDiscardFile:j,onDiscardAll:w}){const{t:T}=oe(["terminal"]);if(i.length===0)return null;const A=i.some(O=>O.status==="untracked"),K=A&&v&&i.length>0,C=N?i.every(O=>N.has(O.path)):!1;return e.jsxs("div",{className:"git-status-group",children:[e.jsxs("div",{className:"git-status-group-header",style:{color:c},children:[e.jsx("span",{className:"git-status-badge",style:{background:c},children:l}),n," (",i.length,")",K&&e.jsx("button",{className:`git-stage-all-btn ${C?"staging":""}`,onClick:O=>{O.stopPropagation(),C||v()},title:T("terminal:fileExplorer.stageAllUntracked"),disabled:C,children:C?"...":T("terminal:fileExplorer.stageAll")}),w&&e.jsxs("button",{className:"git-discard-all-btn",onClick:O=>{O.stopPropagation(),w()},title:A?`Delete all ${i.length} files`:`Discard all ${i.length} changes`,children:[e.jsx(M,{name:"revert",size:12})," All"]})]}),h==="tree"?e.jsx("div",{className:"git-tree-content",children:r.map(O=>e.jsx(lr,{node:O,depth:0,expandedDirs:u,onToggleDir:p,selectedPath:o,onSelect:b,onStage:f,stagingPaths:N,checkedFiles:R,onToggleCheck:y,onContextMenu:k,onDirContextMenu:g,onDiscard:j},O.path))}):e.jsx("div",{className:"git-flat-content",children:i.map(O=>e.jsx(ar,{file:O,isSelected:o===O.path,onSelect:b,onStage:O.status==="untracked"?f:void 0,isStaging:N==null?void 0:N.has(O.path),showDirPath:!0,isChecked:R==null?void 0:R.has(O.path),onToggleCheck:y,onContextMenu:k,onDiscard:j},O.path))})]})});function or({gitStatus:s,loading:n,onFileSelect:l,selectedPath:c,onRefresh:i,onStageFiles:r,stagingPaths:h,currentFolder:o,onCommitComplete:u,mergeInProgress:p,mergingBranch:b,onMergeContinue:f,onMergeAbort:v,onConflictOpen:N,onRevealInTree:R}){const{t:y}=oe(["terminal","common"]),[k,g]=t.useState("tree"),[j,w]=t.useState(new Set),[T,A]=t.useState(""),[K,C]=t.useState(""),[O,ae]=t.useState(!1),[Y,D]=t.useState(new Set),[F,V]=t.useState(!1),[ne,re]=t.useState(null),je=t.useRef(null),{showToast:U}=tn(),[Z,P]=t.useState(null),[G,I]=t.useState(null),[ie,ee]=t.useState(null),ve=t.useCallback((E,L)=>{ee({files:[E],label:E.name})},[]),m=t.useCallback(async()=>{if(!(!ie||!o))try{const E=await W(B("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:ie.files.map(_=>({path:_.path,status:_.status})),directory:o})}),L=await E.json();E.ok&&L.success?(U("success","Discarded",`Reverted ${ie.files.length} file(s)`),i()):U("error","Discard Failed",L.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}finally{ee(null)}},[ie,o,i,U]),X=t.useCallback((E,L,_)=>{E.preventDefault(),E.stopPropagation(),P({isOpen:!0,position:{x:E.clientX,y:E.clientY},file:L,status:_})},[]),le=t.useCallback(async(E,L)=>{if(o)try{const _=await W(B("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:E.path,status:L}],directory:o})}),be=await _.json();_.ok&&be.success?(U("success","Discarded",`Restored ${E.name}`),i()):U("error","Discard Failed",be.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}},[o,i,U]),z=t.useCallback(async E=>{try{await navigator.clipboard.writeText(E),U("success","Copied","Full path copied")}catch{U("error","Copy Failed","Could not copy path")}},[U]),$=t.useCallback(async E=>{const L=o&&E.startsWith(o+"/")?E.slice(o.length+1):E;try{await navigator.clipboard.writeText(L),U("success","Copied","Relative path copied")}catch{U("error","Copy Failed","Could not copy path")}},[o,U]),S=t.useMemo(()=>{if(!Z)return[];const{file:E,status:L}=Z,_=[];return L==="conflict"&&N?_.push({id:"open-conflict",label:y("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>N(E.path)}):L!=="deleted"&&_.push({id:"open-file",label:y("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>l(E.path,L)}),L!=="conflict"&&_.push({id:"stage-file",label:y("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{r([E.path])}}),_.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(L==="modified"||L==="deleted"||L==="renamed"||L==="conflict")&&_.push({id:"discard-changes",label:y("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{le(E,L)}}),(L==="untracked"||L==="added")&&_.push({id:"delete-file",label:y("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{le(E,L)}}),_.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),_.push({id:"copy-full-path",label:y("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{z(E.path)}}),_.push({id:"copy-relative-path",label:y("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{$(E.path)}}),R&&L!=="deleted"&&_.push({id:"reveal-in-tree",label:y("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>R(E.path)}),_},[Z,l,r,N,R,le,z,$,y]),te=t.useCallback((E,L)=>{E.preventDefault(),E.stopPropagation(),I({isOpen:!0,position:{x:E.clientX,y:E.clientY},node:L})},[]),Q=t.useCallback(E=>!E.isDirectory&&E.file?[E.file]:E.children.flatMap(L=>Q(L)),[]),de=t.useCallback(async E=>{if(!o)return;const L=Q(E);if(L.length!==0)try{const _=await W(B("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:L.map(Me=>({path:Me.path,status:Me.status})),directory:o})}),be=await _.json();_.ok&&be.success?(U("success","Discarded",`Reverted ${L.length} file(s) in ${E.name}`),i()):U("error","Discard Failed",be.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}},[o,Q,i,U]),pe=t.useMemo(()=>{if(!G)return[];const{node:E}=G,L=Q(E);return[{id:"discard-dir",label:`Discard Changes (${L.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{de(E)}},{id:"stage-dir",label:`Stage All (${L.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{r(L.map(_=>_.path))}}]},[G,Q,de,r]),se=t.useCallback(E=>{w(L=>{const _=new Set(L);return _.has(E)?_.delete(E):_.add(E),_})},[]),{conflictFiles:we,conflictTree:Ge,changesFiles:He,changesTree:Gt,untrackedFiles:ze,untrackedTree:yt,allDirPaths:Ue}=t.useMemo(()=>{if(!s||!s.isGitRepo||s.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const E=new Set,L=s.files.filter(me=>me.status==="conflict"),_=$t(L);Ht(_,E);const be=s.files.filter(me=>me.status==="modified"||me.status==="added"||me.status==="deleted"||me.status==="renamed"),Me=$t(be);Ht(Me,E);const qe=s.files.filter(me=>me.status==="untracked"),ct=$t(qe);return Ht(ct,E),{conflictFiles:L,conflictTree:_,changesFiles:be,changesTree:Me,untrackedFiles:qe,untrackedTree:ct,allDirPaths:E}},[s]);t.useEffect(()=>{w(Ue)},[Ue]),t.useEffect(()=>{s!=null&&s.files&&D(new Set(s.files.map(E=>E.path)))},[s==null?void 0:s.files]);const ot=t.useCallback(()=>{He.length!==0&&ee({files:He,label:`${He.length} changed files`})},[He]),bt=t.useCallback(()=>{ze.length!==0&&ee({files:ze,label:`${ze.length} unversioned files`})},[ze]),jt=t.useCallback(()=>{we.length!==0&&ee({files:we,label:`${we.length} conflicted files`})},[we]),vt=we.length>0;t.useEffect(()=>{if(ne){const E=ne.type==="error"?8e3:4e3,L=setTimeout(()=>re(null),E);return()=>clearTimeout(L)}},[ne]);const wt=t.useCallback(async()=>{const E=!O;if(ae(E),E&&o){C(T);try{const _=await(await W(B(`/api/files/git-log-message?path=${encodeURIComponent(o)}`))).json();_.message&&A(_.message)}catch{}}else A(K)},[O,o,T,K]),ye=t.useCallback(E=>{D(L=>{const _=new Set(L);return _.has(E)?_.delete(E):_.add(E),_})},[]),ue=t.useCallback(()=>{if(!(s!=null&&s.files))return;const E=s.files.map(_=>_.path),L=E.every(_=>Y.has(_));D(L?new Set:new Set(E))},[s==null?void 0:s.files,Y]),xe=t.useCallback(async E=>{if(!(!o||!T.trim()||Y.size===0||F)){V(!0),re(null);try{const L=await W(B("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o,message:T.trim(),amend:O,paths:Array.from(Y)})}),_=await L.json();if(!L.ok||!_.success){re({type:"error",text:_.error||"Commit failed"}),V(!1);return}if(E)try{const be=await W(B("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o})}),Me=await be.json();be.ok&&Me.success?re({type:"success",text:y("terminal:fileExplorer.committedAndPushed")}):re({type:"error",text:y("terminal:fileExplorer.committedButPushFailed",{error:Me.error||"Unknown error"})})}catch{re({type:"error",text:y("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else re({type:"success",text:y("terminal:fileExplorer.committedSuccessfully")});A(""),C(""),ae(!1),i(),u==null||u()}catch(L){re({type:"error",text:L.message||"Commit failed"})}finally{V(!1)}}},[o,T,O,Y,F,i,u]);if(n)return e.jsx("div",{className:"git-changes-loading",children:y("terminal:fileExplorer.loadingGitStatus")});if(!s||!s.isGitRepo)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"package",size:32})}),e.jsx("div",{className:"git-empty-text",children:y("terminal:fileExplorer.notGitRepo")})]});if(s.files.length===0)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"sparkle",size:32})}),e.jsx("div",{className:"git-empty-text",children:y("terminal:fileExplorer.workingTreeClean")}),e.jsx("div",{className:"git-empty-branch",children:y("terminal:fileExplorer.onBranch",{branch:s.branch})})]});const ke=E=>{r([E])},We=()=>{const E=ze.map(L=>L.path);E.length>0&&r(E)},Re=(E,L)=>{L==="conflict"&&N?N(E):l(E,L)};return e.jsxs("div",{className:"git-changes",children:[e.jsxs("div",{className:"git-changes-header",children:[e.jsxs("span",{className:"git-branch",children:[e.jsx("span",{className:"git-branch-icon",children:e.jsx(M,{name:"git-branch",size:12})}),s.branch]}),s.counts&&e.jsxs("div",{className:"git-changes-summary",children:[(s.counts.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[s.counts.conflict,"C"]}),s.counts.modified>0&&e.jsxs("span",{className:"git-count modified",children:[s.counts.modified,"M"]}),s.counts.added>0&&e.jsxs("span",{className:"git-count added",children:[s.counts.added,"A"]}),s.counts.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[s.counts.deleted,"D"]}),s.counts.untracked>0&&e.jsxs("span",{className:"git-count untracked",children:[s.counts.untracked,"?"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${k==="flat"?"active":""}`,onClick:()=>g("flat"),title:y("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${k==="tree"?"active":""}`,onClick:()=>g("tree"),title:y("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"git-refresh-btn",onClick:i,title:y("common:buttons.refresh"),children:e.jsx(M,{name:"refresh",size:12})})]}),p&&e.jsxs("div",{className:"git-merge-banner",children:[e.jsx("span",{className:"git-merge-banner-icon",children:"⚠"}),e.jsx("span",{className:"git-merge-banner-text",children:y("terminal:fileExplorer.mergeInProgress",{branch:b?` (${b})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:f,disabled:vt,title:y(vt?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:y("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:v,title:y("terminal:fileExplorer.abortMerge"),children:y("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(ss,{groupLabel:y("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:we,treeNodes:Ge,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:jt}),e.jsx(ss,{groupLabel:y("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:He,treeNodes:Gt,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:ot}),e.jsx(ss,{groupLabel:y("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:ze,treeNodes:yt,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,onStageFile:ke,onStageAll:We,stagingPaths:h,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:bt})]}),e.jsxs("div",{className:"git-commit-panel",children:[e.jsxs("div",{className:"git-commit-options",children:[e.jsxs("label",{className:"git-commit-amend-label",children:[e.jsx("input",{type:"checkbox",className:"git-commit-amend-checkbox",checked:O,onChange:wt}),y("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:y("terminal:fileExplorer.fileCount",{count:Y.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:ue,title:Y.size===s.files.length?y("terminal:fileExplorer.deselectAll"):y("terminal:fileExplorer.selectAll"),children:Y.size===s.files.length?y("terminal:fileExplorer.deselectAll"):y("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:je,className:"git-commit-message",placeholder:y("terminal:fileExplorer.commitMessagePlaceholder"),value:T,onChange:E=>A(E.target.value),onKeyDown:E=>{(E.metaKey||E.ctrlKey)&&E.key==="Enter"&&(E.preventDefault(),xe(!1)),(E.metaKey||E.ctrlKey)&&E.shiftKey&&E.key==="Enter"&&(E.preventDefault(),xe(!0)),E.stopPropagation()},rows:3,disabled:F}),ne&&e.jsx("div",{className:`git-commit-status ${ne.type}`,children:ne.text}),e.jsxs("div",{className:"git-commit-actions",children:[e.jsx("button",{className:"git-commit-btn",onClick:()=>xe(!1),disabled:!T.trim()||Y.size===0||F,title:y("terminal:fileExplorer.commitCtrlEnter"),children:y(F?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>xe(!0),disabled:!T.trim()||Y.size===0||F,title:y("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:F?"...":y("terminal:fileExplorer.commitAndPush")})]})]}),Z&&e.jsx(it,{isOpen:Z.isOpen,position:Z.position,worldPosition:{x:0,z:0},actions:S,onClose:()=>P(null)}),G&&e.jsx(it,{isOpen:G.isOpen,position:G.position,worldPosition:{x:0,z:0},actions:pe,onClose:()=>I(null)}),ie&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>ee(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:E=>E.stopPropagation(),children:[e.jsx("p",{children:ie.files.some(E=>E.status==="untracked"||E.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:ie.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:ie.label}),"?"]})}),e.jsx("p",{className:"git-discard-confirm-hint",children:"This cannot be undone."}),e.jsxs("div",{className:"git-discard-confirm-actions",children:[e.jsx("button",{className:"git-discard-confirm-cancel",onClick:()=>ee(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:m,children:ie.files.some(E=>E.status==="untracked"||E.status==="added")?"Delete":"Discard"})]})]})})]})}const on=t.memo(or,(s,n)=>s.loading!==n.loading||s.selectedPath!==n.selectedPath||s.stagingPaths!==n.stagingPaths||s.currentFolder!==n.currentFolder||s.mergeInProgress!==n.mergeInProgress||s.mergingBranch!==n.mergingBranch?!1:s.gitStatus===null&&n.gitStatus===null?!0:!(s.gitStatus===null||n.gitStatus===null||s.gitStatus.isGitRepo!==n.gitStatus.isGitRepo||s.gitStatus.branch!==n.gitStatus.branch||s.gitStatus.files.length!==n.gitStatus.files.length||s.gitStatus.mergeInProgress!==n.gitStatus.mergeInProgress));on.displayName="GitChanges";const cr=t.memo(function({tab:n,isActive:l,onSelect:c,onClose:i,onContextMenu:r}){const{t:h}=oe(["terminal"]),o={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},u=t.useCallback(()=>{c(n.path)},[c,n.path]),p=t.useCallback(v=>{v.button===1&&(v.preventDefault(),v.stopPropagation(),i(n.path))},[i,n.path]),b=t.useCallback(v=>{v.preventDefault(),v.stopPropagation(),i(n.path)},[i,n.path]),f=t.useCallback(v=>{v.preventDefault(),v.stopPropagation(),r(v,n)},[r,n]);return e.jsxs("div",{className:`file-tab ${l?"active":""}`,onClick:u,onMouseDown:p,onContextMenu:f,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:as(o),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:b,title:h("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function dr(s){return typeof s.path=="string"&&s.path.startsWith("/")}function ur({tabs:s,activeTabPath:n,onSelectTab:l,onCloseTab:c,onCloseAllTabs:i,onShowGitHistory:r}){const{t:h}=oe(["terminal"]),[o,u]=t.useState(null),p=t.useCallback((v,N)=>{u({isOpen:!0,position:{x:v.clientX,y:v.clientY},tab:N})},[]),b=t.useCallback(()=>u(null),[]),f=t.useMemo(()=>{if(!o)return[];const v=o.tab,N=!!r&&dr(v),R=[{id:"git-history",label:h("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!N,onClick:()=>{N&&r(v.path)}}];return i&&R.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:h("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(M,{name:"cross",size:14}),danger:!0,onClick:()=>i()}),R},[o,r,i,h]);return s.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:s.map(v=>e.jsx(cr,{tab:v,isActive:n===v.path,onSelect:l,onClose:c,onContextMenu:p},v.path))}),o&&e.jsx(it,{isOpen:o.isOpen,position:o.position,worldPosition:{x:0,z:0},actions:f,onClose:b})]})}const cn=t.memo(ur,(s,n)=>{if(s.activeTabPath!==n.activeTabPath||s.tabs.length!==n.tabs.length||s.onShowGitHistory!==n.onShowGitHistory||s.onCloseAllTabs!==n.onCloseAllTabs)return!1;for(let l=0;l<s.tabs.length;l++)if(s.tabs[l].path!==n.tabs[l].path)return!1;return!0});cn.displayName="FileTabs";const hr=t.memo(function({currentFolder:n,gitStatus:l,onBranchChanged:c,onMerge:i,onCompare:r,onPullConflicts:h}){const{t:o}=oe(["terminal","common"]),[u,p]=t.useState(!1),[b,f]=t.useState(""),[v,N]=t.useState(!1),[R,y]=t.useState(""),[k,g]=t.useState(!1),[j,w]=t.useState(null),[T,A]=t.useState(null),K=t.useRef(null),C=t.useRef(null),O=t.useRef(null),{branches:ae,loading:Y,operationInProgress:D,loadBranches:F,checkoutBranch:V,createBranch:ne,pullFromRemote:re,pushToRemote:je}=rs();t.useEffect(()=>{u&&n&&(F(n),setTimeout(()=>{var S;return(S=C.current)==null?void 0:S.focus()},50)),u||(f(""),N(!1),y(""),w(null))},[u,n,F]),t.useEffect(()=>{if(j){const S=j.type==="error"?8e3:3e3,te=setTimeout(()=>w(null),S);return()=>clearTimeout(te)}},[j]),t.useEffect(()=>{v&&setTimeout(()=>{var S;return(S=O.current)==null?void 0:S.focus()},50)},[v]),t.useEffect(()=>{if(!u)return;const S=Q=>{const de=Q.target;!de.closest(".branch-widget-selector")&&!de.closest(".branch-widget-dropdown")&&p(!1)},te=Q=>{Q.key==="Escape"&&(Q.preventDefault(),Q.stopPropagation(),p(!1))};return document.addEventListener("click",S),document.addEventListener("keydown",te,!0),()=>{document.removeEventListener("click",S),document.removeEventListener("keydown",te,!0)}},[u]);const U=t.useCallback(async S=>{if(!n||D||S.isCurrent)return;const te=await V(n,S.name);te.success?(w({type:"success",text:o("terminal:fileExplorer.switchedToBranch",{branch:te.branch||S.name})}),c(),F(n)):w({type:"error",text:te.error||o("terminal:fileExplorer.checkoutFailed")})},[n,D,V,c,F]),Z=t.useCallback(async()=>{if(!n||!R.trim()||D)return;const S=await ne(n,R.trim());S.success?(w({type:"success",text:o("terminal:fileExplorer.createdBranch",{branch:S.branch})}),N(!1),y(""),c(),F(n)):w({type:"error",text:S.error||o("terminal:fileExplorer.createBranchFailed")})},[n,R,D,ne,c,F]),P=t.useCallback(async()=>{if(!n||D)return;const S=await re(n);S.success?(S.stashConflicts&&S.stashConflicts.length>0?(w({type:"error",text:`Pull succeeded but stash pop had conflicts: ${S.stashConflicts.length} file(s). Resolve manually.`}),h==null||h(S.stashConflicts),p(!1)):S.stashed?w({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):w({type:"success",text:o("terminal:fileExplorer.pullComplete")}),c(),F(n)):S.conflicts&&S.conflicts.length>0?(w({type:"error",text:`Pull conflicts: ${S.conflicts.length} file(s)`}),h==null||h(S.conflicts),p(!1)):w({type:"error",text:S.error||o("terminal:fileExplorer.pullFailed")})},[n,D,re,c,F,h]),G=t.useCallback(async()=>{if(!n||D)return;const S=await je(n);S.success?w({type:"success",text:o("terminal:fileExplorer.pushComplete")}):w({type:"error",text:S.error||o("terminal:fileExplorer.pushFailed")})},[n,D,je]),[I,ie]=t.useState(!1),ee=t.useCallback(async()=>{if(!(!n||D||I)){ie(!0);try{const S=await W(B("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(S.ok)w({type:"success",text:"Fetch complete"}),c(),F(n);else{const te=await S.json().catch(()=>({error:"Fetch failed"}));w({type:"error",text:te.error||"Fetch failed"})}}catch{w({type:"error",text:"Fetch failed"})}finally{ie(!1)}}},[n,D,I,c,F]),ve=(l==null?void 0:l.branch)||"unknown",m=!!D,X=t.useCallback((S,te)=>{te.isCurrent||(S.preventDefault(),S.stopPropagation(),A({isOpen:!0,position:{x:S.clientX,y:S.clientY},branch:te.name}))},[]),le=t.useMemo(()=>{if(!T)return[];const S=!!D||(l==null?void 0:l.mergeInProgress);return[{id:"compare",label:o("terminal:fileExplorer.showDiffWith",{branch:T.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!D,onClick:()=>{r==null||r(T.branch),p(!1)}},{id:"merge",label:o("terminal:fileExplorer.mergeInto",{source:T.branch,target:ve}),icon:"⤵",disabled:!!S,onClick:()=>{i&&i(T.branch),p(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:o("terminal:fileExplorer.checkoutBranch",{branch:T.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!D,onClick:()=>{const te=ae.find(Q=>Q.name===T.branch);te&&U(te)}}]},[T,D,l==null?void 0:l.mergeInProgress,ve,i,r,ae,U]),z=t.useMemo(()=>{const S=ae.filter(Q=>!Q.isRemote);if(!b)return S;const te=b.toLowerCase();return S.filter(Q=>Q.name.toLowerCase().includes(te))},[ae,b]),$=t.useMemo(()=>{const S=ae.filter(Q=>Q.isRemote);if(!b)return S;const te=b.toLowerCase();return S.filter(Q=>Q.name.toLowerCase().includes(te))},[ae,b]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:S=>{S.stopPropagation(),p(!u)},title:`Branch: ${ve}`,children:[e.jsx("svg",{className:"branch-widget-icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M5 3.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Zm0 2.122a2.25 2.25 0 1 0-1 0v1.836A2.25 2.25 0 0 0 5.75 9.5h1.378a2.251 2.251 0 1 0 0-1H5.75a1.25 1.25 0 0 1-1.25-1.25V5.372Zm7.75 4.878a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3-8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"})}),e.jsx("span",{className:"branch-widget-name",children:ve}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),u&&e.jsxs("div",{className:"branch-widget-dropdown",ref:K,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:C,type:"text",className:"branch-widget-search-input",placeholder:o("terminal:fileExplorer.searchBranches"),value:b,onChange:S=>f(S.target.value),onKeyDown:S=>S.stopPropagation()})}),j&&e.jsx("div",{className:`branch-widget-status ${j.type}`,children:j.text}),e.jsx("div",{className:"branch-widget-section-header",children:o("terminal:fileExplorer.actions")}),e.jsxs("div",{className:"branch-widget-actions",children:[e.jsxs("div",{className:`branch-widget-action-item ${m||I?"disabled":""}`,onClick:ee,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 13l-3-3h2V6h2v4h2l-3 3zM8 3l3 3h-2v4H7V6H5l3-3z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:I?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:P,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 12l-4-4h2.5V3h3v5H12L8 12z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(D==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:G,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 4l4 4h-2.5v5h-3V8H4l4-4z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(D==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:()=>{m||N(!v)},children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 2v5H3v2h5v5h2V9h5V7H10V2H8z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o("terminal:fileExplorer.newBranch")})]})]}),v&&e.jsxs("div",{className:"branch-widget-new-branch",children:[e.jsx("input",{ref:O,type:"text",className:"branch-widget-new-branch-input",placeholder:o("terminal:fileExplorer.branchNamePlaceholder"),value:R,onChange:S=>y(S.target.value),onKeyDown:S=>{S.stopPropagation(),S.key==="Enter"&&Z(),S.key==="Escape"&&(N(!1),y(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:Z,disabled:!R.trim()||m,children:D==="create"?"...":o("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[o("terminal:fileExplorer.localBranches"),Y&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",o("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[z.length===0&&!Y&&e.jsx("div",{className:"branch-widget-empty",children:o("terminal:fileExplorer.noBranchesFound")}),z.map(S=>e.jsxs("div",{className:`branch-widget-branch-item ${S.isCurrent?"current":""} ${m?"disabled":""}`,onClick:()=>U(S),onContextMenu:te=>X(te,S),title:S.lastMessage||S.name,children:[e.jsxs("span",{className:"branch-widget-branch-name",children:[S.isCurrent&&e.jsx("span",{className:"branch-widget-current-marker",children:"*"}),S.name]}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))]}),$.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>g(!k),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:k?"▾":"▸"}),o("terminal:fileExplorer.remoteBranches",{count:$.length})]}),k&&e.jsx("div",{className:"branch-widget-branch-list",children:$.map(S=>e.jsxs("div",{className:`branch-widget-branch-item remote ${m?"disabled":""}`,onClick:()=>U(S),onContextMenu:te=>X(te,S),title:S.lastMessage||S.name,children:[e.jsx("span",{className:"branch-widget-branch-name",children:S.name}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))})]})]}),T&&e.jsx(it,{isOpen:T.isOpen,position:T.position,worldPosition:{x:0,z:0},actions:le,onClose:()=>A(null)})]})});function mr(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function It(s,n){if(!s)return"";const l=As.languages[n];return l?As.highlight(s,l,n):mr(s)}function fr(s){const n=[],l=s.split(`
|
|
7
|
+
`),[c]),b=p.length,[f,v]=t.useState(1),[N,R]=t.useState(0),[y,k]=t.useState(!1),[g,j]=t.useState("none"),[w,T]=t.useState(null),[A,K]=t.useState(!1),[C,O]=t.useState(""),[ae,Y]=t.useState(0),[D,F]=t.useState(!1),V=t.useMemo(()=>La(c,C,!1),[c,C]),ne=t.useCallback(()=>{const m=o.current;if(!m)return;const X=Pa(m),le=Ia(m,c),$=Math.max(1,Math.round(m.scrollLeft/7.8)+1);h.current={percentage:X,line:le,column:$}},[c]),re=t.useCallback(()=>{K(!0),O(""),Y(0),r==null||r()},[r]),je=t.useCallback(()=>{K(!1),O(""),Y(0)},[]),U=t.useCallback(()=>{F(m=>!m)},[]),Z=t.useCallback(m=>{const X=o.current;if(!X)return;const le=X.querySelector(".file-viewer-pre"),H=le&&parseFloat(getComputedStyle(le).lineHeight)||u.current,$=le&&parseFloat(getComputedStyle(le).paddingTop)||0,te=(le?le.offsetTop:0)+$+(m-1)*H,Q=H*3;X.scrollTo({top:Math.max(0,te-Q),behavior:"smooth"})},[]);t.useEffect(()=>{!A||V.length===0||Y(0)},[V,A]),t.useEffect(()=>{if(!A||V.length===0)return;const m=V[ae];m&&(v(m.line),R(m.column),Z(m.line))},[A,V,ae,Z]);const P=t.useCallback(()=>{V.length!==0&&Y(m=>(m+1)%V.length)},[V]),G=t.useCallback(()=>{V.length!==0&&Y(m=>(m-1+V.length)%V.length)},[V]),I=t.useCallback(m=>{const X=o.current;if(!X)return;const le=X.querySelector(".file-viewer-pre");if(!le)return;const H=parseFloat(getComputedStyle(le).lineHeight),$=isNaN(H)?u.current:H,S=parseFloat(getComputedStyle(le).paddingTop)||0,Q=le.offsetTop+S+(m-1)*$,de=Q+$,pe=X.scrollTop,se=pe+X.clientHeight;Q<pe?X.scrollTo({top:Math.max(0,Q),behavior:"auto"}):de>se&&X.scrollTo({top:de-X.clientHeight,behavior:"auto"})},[]),ie=t.useCallback((m,X)=>{v(m),R(X),I(m),g!=="none"&&T(le=>le?{...le,headLine:m,headCol:X}:null)},[g,I]),ee=t.useCallback(()=>{if(g==="none"||!w)return;const m=Aa(c,p,w,g);m&&navigator.clipboard.writeText(m).catch(()=>{const X=document.createElement("textarea");X.value=m,X.style.position="fixed",X.style.left="-9999px",document.body.appendChild(X),X.select(),document.execCommand("copy"),document.body.removeChild(X)}),j("none"),T(null)},[g,w,c,p]),ve=t.useCallback(m=>{const X=m.target;if((X.tagName==="INPUT"||X.tagName==="TEXTAREA")&&m.key!=="Escape")return;const H=o.current;if(!H)return;let $=!1;const S=u.current,te=Math.max(1,Math.floor(H.clientHeight/S)),Q=Math.max(1,Math.floor(te/2)),de=(se,we)=>{const Ge=Math.max(0,(p[se-1]||"").length-1);return Math.min(we,Math.max(0,Ge))},pe=(se,we)=>{const Ge=de(se,we);ie(se,Ge)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),g==="char"?(j("none"),T(null)):(j("char"),T({anchorLine:f,anchorCol:N,headLine:f,headCol:N})),$=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),g==="line"?(j("none"),T(null)):(j("line"),T({anchorLine:f,anchorCol:0,headLine:f,headCol:0})),$=!0;else if(m.key==="y"&&!m.ctrlKey&&g!=="none")m.preventDefault(),m.stopPropagation(),ee(),$=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const se=Math.min(f+1,b);pe(se,N),$=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const se=Math.max(f-1,1);pe(se,N),$=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.min(f+Q,b);pe(se,N),$=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.max(f-Q,1);pe(se,N),$=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),re(),$=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&g==="none"&&!A){m.preventDefault(),m.stopPropagation();const se=Math.min(f+te,b);pe(se,N),$=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const se=Math.min(f+te,b);pe(se,N),$=!0}else if(m.key==="b"&&!y&&g==="none"&&!A||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const se=Math.max(f-te,1);pe(se,N),$=!0}else if(m.key==="g"&&!m.shiftKey&&g==="none"&&!A)m.preventDefault(),m.stopPropagation(),ie(1,0),ts(H,!1),$=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),ie(1,0),ts(H,!1),$=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),ie(b,0),ts(H,!0),$=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),ie(f,Math.max(0,N-1)),$=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const se=(p[f-1]||"").length;ie(f,Math.min(N+1,Math.max(0,se-1))),$=!0}else if(m.key==="w"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const se=$a(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="e"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const se=za(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="b"&&!A){m.preventDefault(),m.stopPropagation();const se=Ha(p,f,N);ie(se.line,se.col),$=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),ie(f,0),$=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),ie(f,Math.max(0,(p[f-1]||"").length-1)),$=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const we=(p[f-1]||"").search(/\S/);ie(f,we>=0?we:0),$=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),re(),$=!0):m.key==="n"&&!A?(m.preventDefault(),m.stopPropagation(),P(),$=!0):m.key==="N"&&m.shiftKey&&!A?(m.preventDefault(),m.stopPropagation(),G(),$=!0):m.key==="?"&&g==="none"?(m.preventDefault(),m.stopPropagation(),U(),$=!0):m.key==="q"&&g==="none"?(m.preventDefault(),m.stopPropagation(),i==null||i(),$=!0):m.key==="Escape"&&(g!=="none"?(m.preventDefault(),m.stopPropagation(),j("none"),T(null),$=!0):A?(m.preventDefault(),m.stopPropagation(),je(),$=!0):y&&(m.preventDefault(),m.stopPropagation(),k(!1),$=!0));$&&(m.key!=="Escape"&&!y&&k(!0),requestAnimationFrame(ne))},[i,ne,b,p,f,N,I,A,je,g,y,ie,ee,re,P,G,U]);return t.useEffect(()=>{if(!l)return;const m=Fa(n);if(o.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=sn(m);const X=()=>{ne()};return window.addEventListener("keydown",ve,{capture:!0}),m.addEventListener("scroll",X,{passive:!0}),ne(),()=>{window.removeEventListener("keydown",ve,{capture:!0}),m.removeEventListener("scroll",X)}},[l,ve,ne]),{scrollPercentage:h.current.percentage,currentLine:h.current.line,currentColumn:h.current.column,totalLines:b,cursorLine:f,cursorCol:N,cursorModeActive:y,visualMode:g,selection:w,searchActive:A,searchQuery:C,searchMatches:V,currentMatchIndex:ae,startSearch:re,setSearchQuery:O,nextMatch:P,prevMatch:G,clearSearch:je,helpActive:D,toggleHelp:U}}const is=({query:s,onQueryChange:n,matchCount:l,currentIndex:c,onNext:i,onPrev:r,onClose:h})=>{const{t:o}=oe(["terminal"]),u=t.useRef(null);t.useEffect(()=>{var f;(f=u.current)==null||f.focus()},[]);const p=t.useCallback(f=>{f.stopPropagation(),f.key==="Enter"||f.key==="ArrowDown"?(f.preventDefault(),i()):f.key==="ArrowUp"&&(f.preventDefault(),r())},[i,r]),b=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${c+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:u,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:f=>n(f.target.value),onKeyDown:p,autoComplete:"off",spellCheck:"false"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:b}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:r,disabled:l===0,title:o("terminal:fileExplorer.previousMatch"),"aria-label":o("terminal:fileExplorer.previousMatch"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:i,disabled:l===0,title:o("terminal:fileExplorer.nextMatch"),"aria-label":o("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:h,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};is.displayName="SearchBar";const Oa=[{keys:["j","↓"],description:"Move cursor down one line",category:"Navigation"},{keys:["k","↑"],description:"Move cursor up one line",category:"Navigation"},{keys:["h","←"],description:"Move cursor left",category:"Navigation"},{keys:["l","→"],description:"Move cursor right",category:"Navigation"},{keys:["0"],description:"Jump to start of line",category:"Navigation"},{keys:["$"],description:"Jump to end of line",category:"Navigation"},{keys:["^"],description:"First non-whitespace char",category:"Navigation"},{keys:["d","Ctrl+D"],description:"Half page down",category:"Navigation"},{keys:["u","Ctrl+U"],description:"Half page up",category:"Navigation"},{keys:["f","Space"],description:"Full page down",category:"Navigation"},{keys:["b","Page Up"],description:"Full page up",category:"Navigation"},{keys:["g","Home"],description:"Jump to top of file",category:"Navigation"},{keys:["G","End"],description:"Jump to bottom of file",category:"Navigation"},{keys:["w"],description:"Next word start",category:"Word Motion"},{keys:["e"],description:"Next word end",category:"Word Motion"},{keys:["b"],description:"Previous word start",category:"Word Motion"},{keys:["v"],description:"Character visual mode",category:"Visual Mode"},{keys:["V"],description:"Line visual mode",category:"Visual Mode"},{keys:["y"],description:"Yank (copy) selection",category:"Visual Mode"},{keys:["Escape"],description:"Exit visual mode",category:"Visual Mode"},{keys:["/"],description:"Open search bar",category:"Search"},{keys:["n"],description:"Next match",category:"Search"},{keys:["N"],description:"Previous match",category:"Search"},{keys:["?"],description:"Toggle this help overlay",category:"Help"},{keys:["Escape"],description:"Exit cursor mode (or visual/search)",category:"Help"},{keys:["Alt+E"],description:"Close file viewer",category:"Help"},{keys:["q"],description:"Close file viewer",category:"Help"}],ls=({onClose:s})=>{const{t:n}=oe(["terminal"]),l=t.useCallback(r=>{r.target===r.currentTarget&&s()},[s]),c=t.useCallback(r=>{(r.key==="Escape"||r.key==="?")&&(r.preventDefault(),r.stopPropagation(),s())},[s]),i=Oa.reduce((r,h)=>(r[h.category]||(r[h.category]=[]),r[h.category].push(h),r),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:c,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(i).map(([r,h])=>e.jsxs("div",{className:"keybindings-help-category",children:[e.jsx("h3",{className:"keybindings-help-category-title",children:r}),e.jsx("div",{className:"keybindings-help-list",children:h.map((o,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((p,b)=>e.jsx("kbd",{className:"keybindings-help-key",children:p},b))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},u))})]},r))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};ls.displayName="KeybindingsHelp";const Ws=t.lazy(()=>Kn(()=>import("./EmbeddedEditor-5po-iz0Q.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Ga=[".md",".mdx",".markdown"],qs="file-viewer-markdown-render",Ua=[".puml",".plantuml",".iuml",".pu"],Js="file-viewer-plantuml-render",Ba="https://kroki.io/plantuml/svg";function _a(s){return Ga.includes(s.toLowerCase())}function Ka(s){return Ua.includes(s.toLowerCase())}function Va(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(qs);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const i=!c;try{localStorage.setItem(qs,String(i))}catch{}return i})},[]);return[s,l]}function Wa(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Js);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const i=!c;try{localStorage.setItem(Js,String(i))}catch{}return i})},[]);return[s,l]}function qa(s){const n=new TextEncoder().encode(s);let l="";for(const c of n)l+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(l)}`}function Ve({file:s,rightContent:n,onRevealInTree:l,editMode:c,onToggleEdit:i}){const{t:r}=oe(["terminal","common"]),[h,o]=t.useState("idle"),[u,p]=t.useState("idle"),[b,f]=t.useState("idle"),v=s.fileType==="text"?At(s.extension):s.extension.slice(1).toUpperCase(),N=s.fileType==="text"&&s.content!=null,R=_n(),y=async()=>{try{await Lt(s.content),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},k=async()=>{const T=B(`/api/files/binary?path=${encodeURIComponent(s.path)}&download=true`);await Ot(T,s.filename,"text/plain;charset=utf-8")},g=async()=>{o("loading");try{const T=await W(B("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!T.ok){const A=await T.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",A),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(T){console.error("Error opening file in editor:",T),o("error"),setTimeout(()=>o("idle"),2e3)}},j=async()=>{if(s.path)try{await Xn(s.path),p("success"),setTimeout(()=>p("idle"),2e3)}catch(T){console.error("Error opening file explorer:",T),p("error"),setTimeout(()=>p("idle"),2e3)}},w=r("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:s.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[Qs(s.size)," • ",v,s.content&&` • ${s.content.split(`
|
|
8
|
+
`).length} lines`]})]}),e.jsxs("div",{className:"file-viewer-header-right",children:[i&&s.fileType==="text"&&e.jsx("button",{className:`file-viewer-edit-btn${c?" active":""}`,onClick:i,title:r(c?"terminal:fileExplorer.exitEdit":"terminal:fileExplorer.editFile"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L3.463 11.1a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.25.25 0 00.108-.064l8.61-8.61a.25.25 0 000-.354l-1.086-1.086z"})})}),N&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:y,title:r("terminal:fileExplorer.copyAllTitle"),children:r(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyAll")}),e.jsx("button",{className:"file-viewer-download-btn",onClick:k,title:r("terminal:fileExplorer.downloadFileTitle"),children:r("common:buttons.download")})]}),e.jsx("button",{className:`file-viewer-reveal-explorer-btn ${u}`,onClick:j,disabled:!s.path,title:w,"aria-label":w,children:u==="success"?e.jsx(M,{name:"check",size:14}):u==="error"?e.jsx(M,{name:"cross",size:14}):e.jsx(M,{name:"folder-open",size:14})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${h}`,onClick:g,disabled:h==="loading",title:r(h==="error"?"terminal:fileExplorer.failedToOpenEditor":h==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:h==="success"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 11-1.06-1.06l7.25-7.25a.75.75 0 011.06 0z"})}):h==="error"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1.5 1h6v1.5h-5v11h11v-5H15v6.5H0V1h1.5zm8 0H15v5.5h-1.5V3.56L7.28 9.78l-1.06-1.06L12.44 2.5H9.5V1z"})})}),l&&e.jsx("button",{className:"file-viewer-locate-btn",onClick:()=>l(s.path),title:r("terminal:fileExplorer.locateInTree"),children:e.jsx(M,{name:"target",size:14})}),n]})]})}function Ja({file:s,onRevealInTree:n,renderMarkdown:l,onToggleRender:c,editMode:i,onToggleEdit:r}){const h=t.useRef(null),o=t.useRef(null),u=t.useRef(null),{t:p}=oe(["terminal","common"]),[b,f]=t.useState("idle"),[v,N]=t.useState("idle"),[R,y]=t.useState("idle"),[k,g]=t.useState("idle"),j=nn({containerRef:u,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&h.current){const O=At(s.extension);Zs(O).then(()=>{h.current&&en(h.current)})}},[s,l]);const w=t.useCallback(async()=>{if(!o.current){f("error"),setTimeout(()=>f("idle"),2e3);return}try{const O=o.current.innerHTML,ae=Vn(O),Y=o.current.innerText;await Wn(ae,Y),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},[]),T=t.useCallback(async()=>{if(!o.current){N("error"),setTimeout(()=>N("idle"),2e3);return}try{const O=o.current.innerHTML;await Lt(O),N("copied"),setTimeout(()=>N("idle"),2e3)}catch{N("error"),setTimeout(()=>N("idle"),2e3)}},[]),A=t.useCallback(async()=>{try{await Lt(s.content),y("copied"),setTimeout(()=>y("idle"),2e3)}catch{y("error"),setTimeout(()=>y("idle"),2e3)}},[s.content]),K=t.useCallback(async()=>{try{await Lt(s.content),g("copied"),setTimeout(()=>g("idle"),2e3)}catch{g("error"),setTimeout(()=>g("idle"),2e3)}},[s.content]),C=e.jsxs("div",{className:"file-viewer-header-buttons",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:w,title:p("terminal:fileExplorer.copyRichTextTitle"),children:p(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${v}`,onClick:T,title:p("terminal:fileExplorer.copyHtmlTitle"),children:p(v==="copied"?"terminal:fileExplorer.copied":v==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${R}`,onClick:A,title:p("terminal:fileExplorer.copyMarkdownTitle"),children:p(R==="copied"?"terminal:fileExplorer.copied":R==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${k}`,onClick:K,title:p("terminal:fileExplorer.copyOriginalTitle"),children:p(k==="copied"?"terminal:fileExplorer.copied":k==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:p(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:l?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:C,editMode:i,onToggleEdit:r}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[l?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:o,children:e.jsx(qn,{remarkPlugins:[Jn],children:s.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:h,className:"language-markdown",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${j.currentLine}/${j.totalLines}`,children:j.scrollPercentage===100?"END":j.scrollPercentage===0?"TOP":`${j.scrollPercentage}%`}),j.searchActive&&e.jsx(is,{query:j.searchQuery,onQueryChange:j.setSearchQuery,matchCount:j.searchMatches.length,currentIndex:j.currentMatchIndex,onNext:j.nextMatch,onPrev:j.prevMatch,onClose:j.clearSearch})]}),j.helpActive&&e.jsx(ls,{onClose:j.toggleHelp})]})}function Ya({file:s,onRevealInTree:n,renderPlantUml:l,onToggleRender:c,editMode:i,onToggleEdit:r}){const{t:h}=oe(["terminal"]),o=t.useRef(null),u=t.useRef(null),[p,b]=t.useState(null),[f,v]=t.useState(!1),[N,R]=t.useState(null),y=nn({containerRef:u,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&o.current){const g=At(s.extension);Zs(g).then(()=>{o.current&&en(o.current)})}},[s,l]),t.useEffect(()=>{if(!l)return;if(!s.content.trim()){b(null),R("Diagram is empty");return}const g=new AbortController;return v(!0),R(null),(async()=>{try{const w=await fetch(Ba,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:s.content,signal:g.signal});if(!w.ok)throw new Error(`Render failed (${w.status})`);const T=await w.text();if(!T.includes("<svg"))throw new Error("Invalid SVG output");b(qa(T))}catch(w){if(g.signal.aborted)return;const T=w instanceof Error?w.message:"Failed to render diagram";R(T),b(null)}finally{g.signal.aborted||v(!1)}})(),()=>g.abort()},[s.path,s.content,l]);const k=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:h(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:l?"</>":h("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:k,editMode:i,onToggleEdit:r}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[l?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[f&&e.jsx("div",{className:"file-viewer-placeholder",children:h("terminal:fileExplorer.renderingDiagram")}),!f&&p&&e.jsx("img",{src:p,alt:s.filename,className:"file-viewer-diagram-image"}),!f&&N&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[h("terminal:fileExplorer.couldNotRender"),": ",N]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:c,children:h("terminal:fileExplorer.showSource")})]})]}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:o,className:"language-plaintext",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${y.currentLine}/${y.totalLines}`,children:y.scrollPercentage===100?"END":y.scrollPercentage===0?"TOP":`${y.scrollPercentage}%`}),y.searchActive&&e.jsx(is,{query:y.searchQuery,onQueryChange:y.setSearchQuery,matchCount:y.searchMatches.length,currentIndex:y.currentMatchIndex,onNext:y.nextMatch,onPrev:y.prevMatch,onClose:y.clearSearch})]}),y.helpActive&&e.jsx(ls,{onClose:y.toggleHelp})]})}function Xa({file:s,onRevealInTree:n}){const{t:l}=oe(["common","terminal"]),c=async()=>{const i=B(`/api/files/binary?path=${encodeURIComponent(s.path)}&download=true`);await Ot(i,s.filename)};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper zoomable",children:s.dataUrl?e.jsx(Yn,{src:s.dataUrl,alt:s.filename}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadImage")})})]})}function Qa({file:s,onRevealInTree:n}){const{t:l}=oe(["common","terminal"]),c=async()=>{const i=B(`/api/files/binary?path=${encodeURIComponent(s.path)}&download=true`);await Ot(i,s.filename,"application/pdf")};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:s.dataUrl?e.jsx("iframe",{src:s.dataUrl,title:s.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadPdf")})})]})}function Za({file:s,onRevealInTree:n}){const{t:l}=oe(["terminal","common"]),c=async()=>{const r=B(`/api/files/binary?path=${encodeURIComponent(s.path)}&download=true`);await Ot(r,s.filename)},i=()=>{const r=s.extension.toLowerCase();return[".xlsx",".xls"].includes(r)?e.jsx(M,{name:"dashboard",size:48}):[".docx",".doc"].includes(r)?e.jsx(M,{name:"edit",size:48}):[".pptx",".ppt"].includes(r)?e.jsx(M,{name:"film",size:48}):[".zip",".tar",".gz",".rar",".7z"].includes(r)?e.jsx(M,{name:"file-zip",size:48}):[".mp3",".wav",".flac",".ogg"].includes(r)?e.jsx(M,{name:"music-note",size:48}):[".mp4",".avi",".mov",".mkv",".webm"].includes(r)?e.jsx(M,{name:"film",size:48}):[".exe",".dmg",".app",".msi"].includes(r)?e.jsx(M,{name:"gear",size:48}):[".apk",".aab",".ipa"].includes(r)?e.jsx(M,{name:"mobile",size:48}):[".jar",".war",".ear"].includes(r)?e.jsx(M,{name:"coffee",size:48}):[".iso",".img"].includes(r)?e.jsx(M,{name:"disc",size:48}):[".so",".dll",".dylib"].includes(r)?e.jsx(M,{name:"wrench",size:48}):e.jsx(M,{name:"folder",size:48})};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n}),e.jsxs("div",{className:"file-viewer-binary",children:[e.jsx("div",{className:"file-viewer-binary-icon",children:i()}),e.jsx("div",{className:"file-viewer-binary-name",children:s.filename}),e.jsx("div",{className:"file-viewer-binary-size",children:Qs(s.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:l("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:c,children:l("terminal:fileExplorer.downloadFile")})]})]})}function er({file:s,loading:n,error:l,onRevealInTree:c,onFileEdited:i}){const{t:r}=oe(["terminal","common"]),[h,o]=Va(),[u,p]=Wa(),[b,f]=t.useState(!1);t.useEffect(()=>{f(!1)},[s==null?void 0:s.path]);const v=t.useCallback(async w=>{if(!s)return;const T=await W(B("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,content:w})});if(!T.ok){const A=await T.json().catch(()=>({error:"Save failed"}));throw new Error(A.error||"Save failed")}},[s]),N=t.useCallback(()=>{f(w=>(w&&s&&(i==null||i(s.path)),!w))},[s,i]),R=t.useCallback(()=>{s&&(i==null||i(s.path))},[s,i]);if(n)return e.jsx("div",{className:"file-viewer-placeholder",children:r("common:status.loading")});if(l)return e.jsx("div",{className:"file-viewer-placeholder error",children:l});if(!s)return e.jsxs("div",{className:"file-viewer-placeholder",children:[e.jsx("div",{className:"placeholder-icon",children:e.jsx(M,{name:"folder-open",size:32})}),e.jsx("div",{className:"placeholder-text",children:r("terminal:fileExplorer.selectFileToView")})]});const y=s.fileType||"text",k=y==="text"&&_a(s.extension),g=y==="text"&&Ka(s.extension),j=k||g;return j&&b&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:c,editMode:!0,onToggleEdit:N}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:r("common:status.loading")}),children:e.jsx(Ws,{content:s.content,extension:s.extension,onSave:v,onCancel:N},s.path)})]}):y==="text"&&!j&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:c}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:r("common:status.loading")}),children:e.jsx(Ws,{content:s.content,extension:s.extension,onSave:v,onCancel:R},s.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[k&&e.jsx(Ja,{file:s,onRevealInTree:c,renderMarkdown:h,onToggleRender:o,editMode:b,onToggleEdit:N}),g&&!k&&e.jsx(Ya,{file:s,onRevealInTree:c,renderPlantUml:u,onToggleRender:p,editMode:b,onToggleEdit:N}),y==="image"&&e.jsx(Xa,{file:s,onRevealInTree:c}),y==="pdf"&&e.jsx(Qa,{file:s,onRevealInTree:c}),y==="binary"&&e.jsx(Za,{file:s,onRevealInTree:c})]})}const an=t.memo(er,(s,n)=>s.loading!==n.loading||s.error!==n.error?!1:s.file===null&&n.file===null?!0:s.file===null||n.file===null?!1:s.file.path===n.file.path&&s.file.content===n.file.content&&s.file.modified===n.file.modified);an.displayName="FileViewer";function rn({text:s,query:n}){if(!n)return e.jsx(e.Fragment,{children:s});const l=Qn(s,n);if(l)return e.jsxs(e.Fragment,{children:[s.slice(0,l.start),e.jsx("mark",{className:"search-highlight",children:s.slice(l.start,l.end)}),s.slice(l.end)]});const c=n.toLowerCase(),r=s.toLowerCase().indexOf(c);return r===-1?e.jsx(e.Fragment,{children:s}):e.jsxs(e.Fragment,{children:[s.slice(0,r),e.jsx("mark",{className:"search-highlight",children:s.slice(r,r+n.length)}),s.slice(r+n.length)]})}const tr=t.memo(function({node:n,query:l,isSelected:c,onSelect:i,lineNumber:r}){const h=n.isDirectory?null:as(n),o=n.path.split("/");o[o.length-1];const u=o.slice(0,-1).join("/");return e.jsxs("div",{className:`search-result-item ${c?"selected":""}`,onClick:()=>i(n),children:[n.isDirectory?e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"folder",size:14})}):h?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${h}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{className:"search-result-info",children:[e.jsxs("span",{className:"search-result-name",children:[e.jsx(rn,{text:n.name,query:l}),r&&e.jsxs("span",{className:"search-result-line-badge",children:[":",r]})]}),e.jsx("span",{className:"search-result-path",children:u})]})]})}),sr=t.memo(function({match:n,query:l,isSelected:c,onSelect:i}){const{t:r}=oe(["terminal"]),h={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},o=as(h),u=n.path.split("/"),p=u[u.length-1],b=u.slice(0,-1).join("/");return e.jsxs("div",{className:`content-search-item ${c?"selected":""}`,children:[e.jsxs("div",{className:`content-search-header ${c?"selected":""}`,onClick:()=>i(n.path),children:[o?e.jsx("span",{className:"content-search-icon",style:{backgroundImage:`url('${o}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"content-search-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"2px"},children:[e.jsx("span",{className:"content-search-name",children:p}),e.jsx("span",{className:"search-result-path",style:{fontSize:"10px"},children:b})]}),e.jsx("span",{className:"content-search-count",children:n.matches.length})]}),e.jsxs("div",{className:"content-search-matches",children:[n.matches.slice(0,5).map((f,v)=>e.jsxs("div",{className:"content-search-match",onClick:()=>i(n.path,f.line),children:[e.jsx("span",{className:"content-search-line-num",children:f.line}),e.jsx("span",{className:"content-search-line-content",children:e.jsx(rn,{text:f.content.trim(),query:l})})]},`${n.path}-${f.line}-${v}`)),n.matches.length>5&&e.jsxs("div",{className:"content-search-match",style:{opacity:.6,cursor:"default"},children:[e.jsx("span",{className:"content-search-line-num",children:"..."}),e.jsx("span",{className:"content-search-line-content",children:r("terminal:fileExplorer.moreMatches",{count:n.matches.length-5})})]})]})]})});function nr({filenameResults:s,contentResults:n,onSelectFile:l,onSelectContent:c,selectedPath:i,query:r,lineNumber:h}){const{t:o}=oe(["terminal"]),u=s.length>0,p=n.length>0;return!u&&!p?e.jsx("div",{className:"search-no-results",children:o("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[u&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:s.length})]}),e.jsx("div",{className:"unified-search-section-content",children:s.map(b=>e.jsx(tr,{node:b,query:r,isSelected:i===b.path,onSelect:l,lineNumber:h},b.path))})]}),p&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"edit",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.content")}),e.jsx("span",{className:"unified-search-section-count",children:o("terminal:fileExplorer.matchesInFiles",{matches:n.reduce((b,f)=>b+f.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(b=>e.jsx(sr,{match:b,query:r,isSelected:i===b.path,onSelect:c},b.path))})]})]})}const ln=t.memo(nr,(s,n)=>!(s.query!==n.query||s.selectedPath!==n.selectedPath||s.filenameResults.length!==n.filenameResults.length||s.contentResults.length!==n.contentResults.length));ln.displayName="UnifiedSearchResults";const ar=t.memo(function({file:n,isSelected:l,onSelect:c,onStage:i,isStaging:r,showDirPath:h,isChecked:o,onToggleCheck:u,onContextMenu:p,onDiscard:b}){const{t:f}=oe(["terminal"]),v=n.status,N=xt[v],R=v==="deleted",y=v==="untracked"&&i,k=n.name.includes(".")?"."+n.name.split(".").pop():"",g=h&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!R&&c(n.path,v),onContextMenu:j=>{j.preventDefault(),p==null||p(j,n,v)},style:{cursor:R?"not-allowed":"pointer"},title:n.path,children:[u&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:o||!1,onChange:j=>{j.stopPropagation(),u(n.path)},onClick:j=>j.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:gt(k),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,g&&e.jsx("span",{className:"git-file-dir",children:g})]}),e.jsx("span",{className:"git-file-status",style:{color:N.color},children:N.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.oldPath.split("/").pop()]}),y&&e.jsx("button",{className:`git-stage-btn ${r?"staging":""}`,onClick:j=>{j.stopPropagation(),r||i(n.path)},title:f("terminal:fileExplorer.stageFile"),disabled:r,children:r?"...":"+"}),b&&e.jsx("button",{className:"git-discard-btn",onClick:j=>{j.stopPropagation(),b(n,v)},title:v==="untracked"||v==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}),rr=16,ir=22,lr=t.memo(function s({node:n,depth:l,expandedDirs:c,onToggleDir:i,selectedPath:r,onSelect:h,onStage:o,stagingPaths:u,checkedFiles:p,onToggleCheck:b,onContextMenu:f,onDirContextMenu:v,onDiscard:N}){const{t:R}=oe(["terminal"]),y=l*rr;if(!n.isDirectory){const g=n.file.status,j=xt[g];return e.jsxs("div",{className:`git-file-item ${r===n.path?"selected":""}`,onClick:()=>g!=="deleted"&&h(n.file.path,g),onContextMenu:w=>{w.preventDefault(),f==null||f(w,n.file,g)},style:{paddingLeft:`${y+ir}px`,cursor:g==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[b&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(p==null?void 0:p.has(n.file.path))||!1,onChange:w=>{w.stopPropagation(),b(n.file.path)},onClick:w=>w.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:gt(n.file.name.includes(".")?"."+n.file.name.split(".").pop():""),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:j.color},children:j.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.file.oldPath.split("/").pop()]}),g==="untracked"&&o&&e.jsx("button",{className:`git-stage-btn ${u!=null&&u.has(n.path)?"staging":""}`,onClick:w=>{w.stopPropagation(),u!=null&&u.has(n.path)||o(n.file.path)},title:R("terminal:fileExplorer.stageFile"),disabled:u==null?void 0:u.has(n.path),children:u!=null&&u.has(n.path)?"...":"+"}),N&&e.jsx("button",{className:"git-discard-btn",onClick:w=>{w.stopPropagation(),N(n.file,g)},title:g==="untracked"||g==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}const k=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${k?"expanded":""}`,style:{paddingLeft:`${y}px`},onClick:()=>i(n.path),onContextMenu:g=>{g.preventDefault(),g.stopPropagation(),v==null||v(g,n)},children:[e.jsx("span",{className:`tree-arrow ${k?"expanded":""}`,children:e.jsx(M,{name:"caret-right",size:10})}),e.jsx("img",{className:"tree-folder-icon",src:k?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:R("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),k&&e.jsx("div",{className:"tree-children",children:n.children.map(g=>e.jsx(s,{node:g,depth:l+1,expandedDirs:c,onToggleDir:i,selectedPath:r,onSelect:h,onStage:o,stagingPaths:u,checkedFiles:p,onToggleCheck:b,onContextMenu:f,onDirContextMenu:v,onDiscard:N},g.path))})]})}),ss=t.memo(function({groupLabel:n,groupIcon:l,groupColor:c,files:i,treeNodes:r,viewMode:h,selectedPath:o,expandedDirs:u,onToggleDir:p,onFileSelect:b,onStageFile:f,onStageAll:v,stagingPaths:N,checkedFiles:R,onToggleCheck:y,onContextMenu:k,onDirContextMenu:g,onDiscardFile:j,onDiscardAll:w}){const{t:T}=oe(["terminal"]);if(i.length===0)return null;const A=i.some(O=>O.status==="untracked"),K=A&&v&&i.length>0,C=N?i.every(O=>N.has(O.path)):!1;return e.jsxs("div",{className:"git-status-group",children:[e.jsxs("div",{className:"git-status-group-header",style:{color:c},children:[e.jsx("span",{className:"git-status-badge",style:{background:c},children:l}),n," (",i.length,")",K&&e.jsx("button",{className:`git-stage-all-btn ${C?"staging":""}`,onClick:O=>{O.stopPropagation(),C||v()},title:T("terminal:fileExplorer.stageAllUntracked"),disabled:C,children:C?"...":T("terminal:fileExplorer.stageAll")}),w&&e.jsxs("button",{className:"git-discard-all-btn",onClick:O=>{O.stopPropagation(),w()},title:A?`Delete all ${i.length} files`:`Discard all ${i.length} changes`,children:[e.jsx(M,{name:"revert",size:12})," All"]})]}),h==="tree"?e.jsx("div",{className:"git-tree-content",children:r.map(O=>e.jsx(lr,{node:O,depth:0,expandedDirs:u,onToggleDir:p,selectedPath:o,onSelect:b,onStage:f,stagingPaths:N,checkedFiles:R,onToggleCheck:y,onContextMenu:k,onDirContextMenu:g,onDiscard:j},O.path))}):e.jsx("div",{className:"git-flat-content",children:i.map(O=>e.jsx(ar,{file:O,isSelected:o===O.path,onSelect:b,onStage:O.status==="untracked"?f:void 0,isStaging:N==null?void 0:N.has(O.path),showDirPath:!0,isChecked:R==null?void 0:R.has(O.path),onToggleCheck:y,onContextMenu:k,onDiscard:j},O.path))})]})});function or({gitStatus:s,loading:n,onFileSelect:l,selectedPath:c,onRefresh:i,onStageFiles:r,stagingPaths:h,currentFolder:o,onCommitComplete:u,mergeInProgress:p,mergingBranch:b,onMergeContinue:f,onMergeAbort:v,onConflictOpen:N,onRevealInTree:R}){const{t:y}=oe(["terminal","common"]),[k,g]=t.useState("tree"),[j,w]=t.useState(new Set),[T,A]=t.useState(""),[K,C]=t.useState(""),[O,ae]=t.useState(!1),[Y,D]=t.useState(new Set),[F,V]=t.useState(!1),[ne,re]=t.useState(null),je=t.useRef(null),{showToast:U}=tn(),[Z,P]=t.useState(null),[G,I]=t.useState(null),[ie,ee]=t.useState(null),ve=t.useCallback((E,L)=>{ee({files:[E],label:E.name})},[]),m=t.useCallback(async()=>{if(!(!ie||!o))try{const E=await W(B("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:ie.files.map(_=>({path:_.path,status:_.status})),directory:o})}),L=await E.json();E.ok&&L.success?(U("success","Discarded",`Reverted ${ie.files.length} file(s)`),i()):U("error","Discard Failed",L.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}finally{ee(null)}},[ie,o,i,U]),X=t.useCallback((E,L,_)=>{E.preventDefault(),E.stopPropagation(),P({isOpen:!0,position:{x:E.clientX,y:E.clientY},file:L,status:_})},[]),le=t.useCallback(async(E,L)=>{if(o)try{const _=await W(B("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:E.path,status:L}],directory:o})}),be=await _.json();_.ok&&be.success?(U("success","Discarded",`Restored ${E.name}`),i()):U("error","Discard Failed",be.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}},[o,i,U]),H=t.useCallback(async E=>{try{await navigator.clipboard.writeText(E),U("success","Copied","Full path copied")}catch{U("error","Copy Failed","Could not copy path")}},[U]),$=t.useCallback(async E=>{const L=o&&E.startsWith(o+"/")?E.slice(o.length+1):E;try{await navigator.clipboard.writeText(L),U("success","Copied","Relative path copied")}catch{U("error","Copy Failed","Could not copy path")}},[o,U]),S=t.useMemo(()=>{if(!Z)return[];const{file:E,status:L}=Z,_=[];return L==="conflict"&&N?_.push({id:"open-conflict",label:y("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>N(E.path)}):L!=="deleted"&&_.push({id:"open-file",label:y("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>l(E.path,L)}),L!=="conflict"&&_.push({id:"stage-file",label:y("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{r([E.path])}}),_.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(L==="modified"||L==="deleted"||L==="renamed"||L==="conflict")&&_.push({id:"discard-changes",label:y("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{le(E,L)}}),(L==="untracked"||L==="added")&&_.push({id:"delete-file",label:y("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{le(E,L)}}),_.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),_.push({id:"copy-full-path",label:y("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{H(E.path)}}),_.push({id:"copy-relative-path",label:y("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{$(E.path)}}),R&&L!=="deleted"&&_.push({id:"reveal-in-tree",label:y("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>R(E.path)}),_},[Z,l,r,N,R,le,H,$,y]),te=t.useCallback((E,L)=>{E.preventDefault(),E.stopPropagation(),I({isOpen:!0,position:{x:E.clientX,y:E.clientY},node:L})},[]),Q=t.useCallback(E=>!E.isDirectory&&E.file?[E.file]:E.children.flatMap(L=>Q(L)),[]),de=t.useCallback(async E=>{if(!o)return;const L=Q(E);if(L.length!==0)try{const _=await W(B("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:L.map(Me=>({path:Me.path,status:Me.status})),directory:o})}),be=await _.json();_.ok&&be.success?(U("success","Discarded",`Reverted ${L.length} file(s) in ${E.name}`),i()):U("error","Discard Failed",be.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}},[o,Q,i,U]),pe=t.useMemo(()=>{if(!G)return[];const{node:E}=G,L=Q(E);return[{id:"discard-dir",label:`Discard Changes (${L.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{de(E)}},{id:"stage-dir",label:`Stage All (${L.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{r(L.map(_=>_.path))}}]},[G,Q,de,r]),se=t.useCallback(E=>{w(L=>{const _=new Set(L);return _.has(E)?_.delete(E):_.add(E),_})},[]),{conflictFiles:we,conflictTree:Ge,changesFiles:ze,changesTree:Gt,untrackedFiles:He,untrackedTree:yt,allDirPaths:Ue}=t.useMemo(()=>{if(!s||!s.isGitRepo||s.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const E=new Set,L=s.files.filter(me=>me.status==="conflict"),_=$t(L);zt(_,E);const be=s.files.filter(me=>me.status==="modified"||me.status==="added"||me.status==="deleted"||me.status==="renamed"),Me=$t(be);zt(Me,E);const qe=s.files.filter(me=>me.status==="untracked"),ct=$t(qe);return zt(ct,E),{conflictFiles:L,conflictTree:_,changesFiles:be,changesTree:Me,untrackedFiles:qe,untrackedTree:ct,allDirPaths:E}},[s]);t.useEffect(()=>{w(Ue)},[Ue]),t.useEffect(()=>{s!=null&&s.files&&D(new Set(s.files.map(E=>E.path)))},[s==null?void 0:s.files]);const ot=t.useCallback(()=>{ze.length!==0&&ee({files:ze,label:`${ze.length} changed files`})},[ze]),bt=t.useCallback(()=>{He.length!==0&&ee({files:He,label:`${He.length} unversioned files`})},[He]),jt=t.useCallback(()=>{we.length!==0&&ee({files:we,label:`${we.length} conflicted files`})},[we]),vt=we.length>0;t.useEffect(()=>{if(ne){const E=ne.type==="error"?8e3:4e3,L=setTimeout(()=>re(null),E);return()=>clearTimeout(L)}},[ne]);const wt=t.useCallback(async()=>{const E=!O;if(ae(E),E&&o){C(T);try{const _=await(await W(B(`/api/files/git-log-message?path=${encodeURIComponent(o)}`))).json();_.message&&A(_.message)}catch{}}else A(K)},[O,o,T,K]),ye=t.useCallback(E=>{D(L=>{const _=new Set(L);return _.has(E)?_.delete(E):_.add(E),_})},[]),ue=t.useCallback(()=>{if(!(s!=null&&s.files))return;const E=s.files.map(_=>_.path),L=E.every(_=>Y.has(_));D(L?new Set:new Set(E))},[s==null?void 0:s.files,Y]),xe=t.useCallback(async E=>{if(!(!o||!T.trim()||Y.size===0||F)){V(!0),re(null);try{const L=await W(B("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o,message:T.trim(),amend:O,paths:Array.from(Y)})}),_=await L.json();if(!L.ok||!_.success){re({type:"error",text:_.error||"Commit failed"}),V(!1);return}if(E)try{const be=await W(B("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o})}),Me=await be.json();be.ok&&Me.success?re({type:"success",text:y("terminal:fileExplorer.committedAndPushed")}):re({type:"error",text:y("terminal:fileExplorer.committedButPushFailed",{error:Me.error||"Unknown error"})})}catch{re({type:"error",text:y("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else re({type:"success",text:y("terminal:fileExplorer.committedSuccessfully")});A(""),C(""),ae(!1),i(),u==null||u()}catch(L){re({type:"error",text:L.message||"Commit failed"})}finally{V(!1)}}},[o,T,O,Y,F,i,u]);if(n)return e.jsx("div",{className:"git-changes-loading",children:y("terminal:fileExplorer.loadingGitStatus")});if(!s||!s.isGitRepo)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"package",size:32})}),e.jsx("div",{className:"git-empty-text",children:y("terminal:fileExplorer.notGitRepo")})]});if(s.files.length===0)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"sparkle",size:32})}),e.jsx("div",{className:"git-empty-text",children:y("terminal:fileExplorer.workingTreeClean")}),e.jsx("div",{className:"git-empty-branch",children:y("terminal:fileExplorer.onBranch",{branch:s.branch})})]});const ke=E=>{r([E])},We=()=>{const E=He.map(L=>L.path);E.length>0&&r(E)},Re=(E,L)=>{L==="conflict"&&N?N(E):l(E,L)};return e.jsxs("div",{className:"git-changes",children:[e.jsxs("div",{className:"git-changes-header",children:[e.jsxs("span",{className:"git-branch",children:[e.jsx("span",{className:"git-branch-icon",children:e.jsx(M,{name:"git-branch",size:12})}),s.branch]}),s.counts&&e.jsxs("div",{className:"git-changes-summary",children:[(s.counts.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[s.counts.conflict,"C"]}),s.counts.modified>0&&e.jsxs("span",{className:"git-count modified",children:[s.counts.modified,"M"]}),s.counts.added>0&&e.jsxs("span",{className:"git-count added",children:[s.counts.added,"A"]}),s.counts.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[s.counts.deleted,"D"]}),s.counts.untracked>0&&e.jsxs("span",{className:"git-count untracked",children:[s.counts.untracked,"?"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${k==="flat"?"active":""}`,onClick:()=>g("flat"),title:y("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${k==="tree"?"active":""}`,onClick:()=>g("tree"),title:y("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"git-refresh-btn",onClick:i,title:y("common:buttons.refresh"),children:e.jsx(M,{name:"refresh",size:12})})]}),p&&e.jsxs("div",{className:"git-merge-banner",children:[e.jsx("span",{className:"git-merge-banner-icon",children:"⚠"}),e.jsx("span",{className:"git-merge-banner-text",children:y("terminal:fileExplorer.mergeInProgress",{branch:b?` (${b})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:f,disabled:vt,title:y(vt?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:y("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:v,title:y("terminal:fileExplorer.abortMerge"),children:y("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(ss,{groupLabel:y("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:we,treeNodes:Ge,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:jt}),e.jsx(ss,{groupLabel:y("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:ze,treeNodes:Gt,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:ot}),e.jsx(ss,{groupLabel:y("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:He,treeNodes:yt,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:se,onFileSelect:Re,onStageFile:ke,onStageAll:We,stagingPaths:h,checkedFiles:Y,onToggleCheck:ye,onContextMenu:X,onDirContextMenu:te,onDiscardFile:ve,onDiscardAll:bt})]}),e.jsxs("div",{className:"git-commit-panel",children:[e.jsxs("div",{className:"git-commit-options",children:[e.jsxs("label",{className:"git-commit-amend-label",children:[e.jsx("input",{type:"checkbox",className:"git-commit-amend-checkbox",checked:O,onChange:wt}),y("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:y("terminal:fileExplorer.fileCount",{count:Y.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:ue,title:Y.size===s.files.length?y("terminal:fileExplorer.deselectAll"):y("terminal:fileExplorer.selectAll"),children:Y.size===s.files.length?y("terminal:fileExplorer.deselectAll"):y("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:je,className:"git-commit-message",placeholder:y("terminal:fileExplorer.commitMessagePlaceholder"),value:T,onChange:E=>A(E.target.value),onKeyDown:E=>{(E.metaKey||E.ctrlKey)&&E.key==="Enter"&&(E.preventDefault(),xe(!1)),(E.metaKey||E.ctrlKey)&&E.shiftKey&&E.key==="Enter"&&(E.preventDefault(),xe(!0)),E.stopPropagation()},rows:3,disabled:F}),ne&&e.jsx("div",{className:`git-commit-status ${ne.type}`,children:ne.text}),e.jsxs("div",{className:"git-commit-actions",children:[e.jsx("button",{className:"git-commit-btn",onClick:()=>xe(!1),disabled:!T.trim()||Y.size===0||F,title:y("terminal:fileExplorer.commitCtrlEnter"),children:y(F?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>xe(!0),disabled:!T.trim()||Y.size===0||F,title:y("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:F?"...":y("terminal:fileExplorer.commitAndPush")})]})]}),Z&&e.jsx(it,{isOpen:Z.isOpen,position:Z.position,worldPosition:{x:0,z:0},actions:S,onClose:()=>P(null)}),G&&e.jsx(it,{isOpen:G.isOpen,position:G.position,worldPosition:{x:0,z:0},actions:pe,onClose:()=>I(null)}),ie&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>ee(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:E=>E.stopPropagation(),children:[e.jsx("p",{children:ie.files.some(E=>E.status==="untracked"||E.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:ie.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:ie.label}),"?"]})}),e.jsx("p",{className:"git-discard-confirm-hint",children:"This cannot be undone."}),e.jsxs("div",{className:"git-discard-confirm-actions",children:[e.jsx("button",{className:"git-discard-confirm-cancel",onClick:()=>ee(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:m,children:ie.files.some(E=>E.status==="untracked"||E.status==="added")?"Delete":"Discard"})]})]})})]})}const on=t.memo(or,(s,n)=>s.loading!==n.loading||s.selectedPath!==n.selectedPath||s.stagingPaths!==n.stagingPaths||s.currentFolder!==n.currentFolder||s.mergeInProgress!==n.mergeInProgress||s.mergingBranch!==n.mergingBranch?!1:s.gitStatus===null&&n.gitStatus===null?!0:!(s.gitStatus===null||n.gitStatus===null||s.gitStatus.isGitRepo!==n.gitStatus.isGitRepo||s.gitStatus.branch!==n.gitStatus.branch||s.gitStatus.files.length!==n.gitStatus.files.length||s.gitStatus.mergeInProgress!==n.gitStatus.mergeInProgress));on.displayName="GitChanges";const cr=t.memo(function({tab:n,isActive:l,onSelect:c,onClose:i,onContextMenu:r}){const{t:h}=oe(["terminal"]),o={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},u=t.useCallback(()=>{c(n.path)},[c,n.path]),p=t.useCallback(v=>{v.button===1&&(v.preventDefault(),v.stopPropagation(),i(n.path))},[i,n.path]),b=t.useCallback(v=>{v.preventDefault(),v.stopPropagation(),i(n.path)},[i,n.path]),f=t.useCallback(v=>{v.preventDefault(),v.stopPropagation(),r(v,n)},[r,n]);return e.jsxs("div",{className:`file-tab ${l?"active":""}`,onClick:u,onMouseDown:p,onContextMenu:f,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:as(o),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:b,title:h("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function dr(s){return typeof s.path=="string"&&s.path.startsWith("/")}function ur({tabs:s,activeTabPath:n,onSelectTab:l,onCloseTab:c,onCloseAllTabs:i,onShowGitHistory:r}){const{t:h}=oe(["terminal"]),[o,u]=t.useState(null),p=t.useCallback((v,N)=>{u({isOpen:!0,position:{x:v.clientX,y:v.clientY},tab:N})},[]),b=t.useCallback(()=>u(null),[]),f=t.useMemo(()=>{if(!o)return[];const v=o.tab,N=!!r&&dr(v),R=[{id:"git-history",label:h("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!N,onClick:()=>{N&&r(v.path)}}];return i&&R.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:h("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(M,{name:"cross",size:14}),danger:!0,onClick:()=>i()}),R},[o,r,i,h]);return s.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:s.map(v=>e.jsx(cr,{tab:v,isActive:n===v.path,onSelect:l,onClose:c,onContextMenu:p},v.path))}),o&&e.jsx(it,{isOpen:o.isOpen,position:o.position,worldPosition:{x:0,z:0},actions:f,onClose:b})]})}const cn=t.memo(ur,(s,n)=>{if(s.activeTabPath!==n.activeTabPath||s.tabs.length!==n.tabs.length||s.onShowGitHistory!==n.onShowGitHistory||s.onCloseAllTabs!==n.onCloseAllTabs)return!1;for(let l=0;l<s.tabs.length;l++)if(s.tabs[l].path!==n.tabs[l].path)return!1;return!0});cn.displayName="FileTabs";const hr=t.memo(function({currentFolder:n,gitStatus:l,onBranchChanged:c,onMerge:i,onCompare:r,onPullConflicts:h}){const{t:o}=oe(["terminal","common"]),[u,p]=t.useState(!1),[b,f]=t.useState(""),[v,N]=t.useState(!1),[R,y]=t.useState(""),[k,g]=t.useState(!1),[j,w]=t.useState(null),[T,A]=t.useState(null),K=t.useRef(null),C=t.useRef(null),O=t.useRef(null),{branches:ae,loading:Y,operationInProgress:D,loadBranches:F,checkoutBranch:V,createBranch:ne,pullFromRemote:re,pushToRemote:je}=rs();t.useEffect(()=>{u&&n&&(F(n),setTimeout(()=>{var S;return(S=C.current)==null?void 0:S.focus()},50)),u||(f(""),N(!1),y(""),w(null))},[u,n,F]),t.useEffect(()=>{if(j){const S=j.type==="error"?8e3:3e3,te=setTimeout(()=>w(null),S);return()=>clearTimeout(te)}},[j]),t.useEffect(()=>{v&&setTimeout(()=>{var S;return(S=O.current)==null?void 0:S.focus()},50)},[v]),t.useEffect(()=>{if(!u)return;const S=Q=>{const de=Q.target;!de.closest(".branch-widget-selector")&&!de.closest(".branch-widget-dropdown")&&p(!1)},te=Q=>{Q.key==="Escape"&&(Q.preventDefault(),Q.stopPropagation(),p(!1))};return document.addEventListener("click",S),document.addEventListener("keydown",te,!0),()=>{document.removeEventListener("click",S),document.removeEventListener("keydown",te,!0)}},[u]);const U=t.useCallback(async S=>{if(!n||D||S.isCurrent)return;const te=await V(n,S.name);te.success?(w({type:"success",text:o("terminal:fileExplorer.switchedToBranch",{branch:te.branch||S.name})}),c(),F(n)):w({type:"error",text:te.error||o("terminal:fileExplorer.checkoutFailed")})},[n,D,V,c,F]),Z=t.useCallback(async()=>{if(!n||!R.trim()||D)return;const S=await ne(n,R.trim());S.success?(w({type:"success",text:o("terminal:fileExplorer.createdBranch",{branch:S.branch})}),N(!1),y(""),c(),F(n)):w({type:"error",text:S.error||o("terminal:fileExplorer.createBranchFailed")})},[n,R,D,ne,c,F]),P=t.useCallback(async()=>{if(!n||D)return;const S=await re(n);S.success?(S.stashConflicts&&S.stashConflicts.length>0?(w({type:"error",text:`Pull succeeded but stash pop had conflicts: ${S.stashConflicts.length} file(s). Resolve manually.`}),h==null||h(S.stashConflicts),p(!1)):S.stashed?w({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):w({type:"success",text:o("terminal:fileExplorer.pullComplete")}),c(),F(n)):S.conflicts&&S.conflicts.length>0?(w({type:"error",text:`Pull conflicts: ${S.conflicts.length} file(s)`}),h==null||h(S.conflicts),p(!1)):w({type:"error",text:S.error||o("terminal:fileExplorer.pullFailed")})},[n,D,re,c,F,h]),G=t.useCallback(async()=>{if(!n||D)return;const S=await je(n);S.success?w({type:"success",text:o("terminal:fileExplorer.pushComplete")}):w({type:"error",text:S.error||o("terminal:fileExplorer.pushFailed")})},[n,D,je]),[I,ie]=t.useState(!1),ee=t.useCallback(async()=>{if(!(!n||D||I)){ie(!0);try{const S=await W(B("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(S.ok)w({type:"success",text:"Fetch complete"}),c(),F(n);else{const te=await S.json().catch(()=>({error:"Fetch failed"}));w({type:"error",text:te.error||"Fetch failed"})}}catch{w({type:"error",text:"Fetch failed"})}finally{ie(!1)}}},[n,D,I,c,F]),ve=(l==null?void 0:l.branch)||"unknown",m=!!D,X=t.useCallback((S,te)=>{te.isCurrent||(S.preventDefault(),S.stopPropagation(),A({isOpen:!0,position:{x:S.clientX,y:S.clientY},branch:te.name}))},[]),le=t.useMemo(()=>{if(!T)return[];const S=!!D||(l==null?void 0:l.mergeInProgress);return[{id:"compare",label:o("terminal:fileExplorer.showDiffWith",{branch:T.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!D,onClick:()=>{r==null||r(T.branch),p(!1)}},{id:"merge",label:o("terminal:fileExplorer.mergeInto",{source:T.branch,target:ve}),icon:"⤵",disabled:!!S,onClick:()=>{i&&i(T.branch),p(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:o("terminal:fileExplorer.checkoutBranch",{branch:T.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!D,onClick:()=>{const te=ae.find(Q=>Q.name===T.branch);te&&U(te)}}]},[T,D,l==null?void 0:l.mergeInProgress,ve,i,r,ae,U]),H=t.useMemo(()=>{const S=ae.filter(Q=>!Q.isRemote);if(!b)return S;const te=b.toLowerCase();return S.filter(Q=>Q.name.toLowerCase().includes(te))},[ae,b]),$=t.useMemo(()=>{const S=ae.filter(Q=>Q.isRemote);if(!b)return S;const te=b.toLowerCase();return S.filter(Q=>Q.name.toLowerCase().includes(te))},[ae,b]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:S=>{S.stopPropagation(),p(!u)},title:`Branch: ${ve}`,children:[e.jsx("svg",{className:"branch-widget-icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M5 3.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Zm0 2.122a2.25 2.25 0 1 0-1 0v1.836A2.25 2.25 0 0 0 5.75 9.5h1.378a2.251 2.251 0 1 0 0-1H5.75a1.25 1.25 0 0 1-1.25-1.25V5.372Zm7.75 4.878a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3-8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"})}),e.jsx("span",{className:"branch-widget-name",children:ve}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),u&&e.jsxs("div",{className:"branch-widget-dropdown",ref:K,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:C,type:"text",className:"branch-widget-search-input",placeholder:o("terminal:fileExplorer.searchBranches"),value:b,onChange:S=>f(S.target.value),onKeyDown:S=>S.stopPropagation()})}),j&&e.jsx("div",{className:`branch-widget-status ${j.type}`,children:j.text}),e.jsx("div",{className:"branch-widget-section-header",children:o("terminal:fileExplorer.actions")}),e.jsxs("div",{className:"branch-widget-actions",children:[e.jsxs("div",{className:`branch-widget-action-item ${m||I?"disabled":""}`,onClick:ee,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 13l-3-3h2V6h2v4h2l-3 3zM8 3l3 3h-2v4H7V6H5l3-3z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:I?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:P,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 12l-4-4h2.5V3h3v5H12L8 12z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(D==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:G,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 4l4 4h-2.5v5h-3V8H4l4-4z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(D==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:()=>{m||N(!v)},children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 2v5H3v2h5v5h2V9h5V7H10V2H8z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o("terminal:fileExplorer.newBranch")})]})]}),v&&e.jsxs("div",{className:"branch-widget-new-branch",children:[e.jsx("input",{ref:O,type:"text",className:"branch-widget-new-branch-input",placeholder:o("terminal:fileExplorer.branchNamePlaceholder"),value:R,onChange:S=>y(S.target.value),onKeyDown:S=>{S.stopPropagation(),S.key==="Enter"&&Z(),S.key==="Escape"&&(N(!1),y(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:Z,disabled:!R.trim()||m,children:D==="create"?"...":o("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[o("terminal:fileExplorer.localBranches"),Y&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",o("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[H.length===0&&!Y&&e.jsx("div",{className:"branch-widget-empty",children:o("terminal:fileExplorer.noBranchesFound")}),H.map(S=>e.jsxs("div",{className:`branch-widget-branch-item ${S.isCurrent?"current":""} ${m?"disabled":""}`,onClick:()=>U(S),onContextMenu:te=>X(te,S),title:S.lastMessage||S.name,children:[e.jsxs("span",{className:"branch-widget-branch-name",children:[S.isCurrent&&e.jsx("span",{className:"branch-widget-current-marker",children:"*"}),S.name]}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))]}),$.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>g(!k),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:k?"▾":"▸"}),o("terminal:fileExplorer.remoteBranches",{count:$.length})]}),k&&e.jsx("div",{className:"branch-widget-branch-list",children:$.map(S=>e.jsxs("div",{className:`branch-widget-branch-item remote ${m?"disabled":""}`,onClick:()=>U(S),onContextMenu:te=>X(te,S),title:S.lastMessage||S.name,children:[e.jsx("span",{className:"branch-widget-branch-name",children:S.name}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))})]})]}),T&&e.jsx(it,{isOpen:T.isOpen,position:T.position,worldPosition:{x:0,z:0},actions:le,onClose:()=>A(null)})]})});function mr(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function It(s,n){if(!s)return"";const l=As.languages[n];return l?As.highlight(s,l,n):mr(s)}function fr(s){const n=[],l=s.split(`
|
|
9
9
|
`);let c=[],i=!1,r=[],h=[],o=!1;for(const u of l)u.startsWith("<<<<<<<")?(c.length>0&&(n.push({type:"unchanged",content:c.join(`
|
|
10
10
|
`)}),c=[]),i=!0,o=!1,r=[],h=[]):u.startsWith("=======")&&i?o=!0:u.startsWith(">>>>>>>")&&i?(n.push({type:"conflict",ours:r.join(`
|
|
11
11
|
`),theirs:h.join(`
|
|
@@ -16,4 +16,4 @@ ${F.ours}
|
|
|
16
16
|
=======
|
|
17
17
|
${F.theirs}
|
|
18
18
|
>>>>>>> ${o}`).join(`
|
|
19
|
-
`);await i(D)}finally{R(!1)}},[f,i,h,o]);return e.jsxs("div",{className:"conflict-resolver",children:[e.jsxs("div",{className:"conflict-header",children:[e.jsx("span",{className:"conflict-header-title",children:u("terminal:fileExplorer.resolveFile",{filename:l==null?void 0:l.filename})}),w>0&&e.jsxs("div",{className:"conflict-nav",children:[e.jsx("button",{className:"conflict-nav-btn",onClick:A,title:u("terminal:fileExplorer.prevConflict"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsxs("span",{className:"conflict-nav-counter",children:[k+1," / ",w]}),e.jsx("button",{className:"conflict-nav-btn",onClick:K,title:u("terminal:fileExplorer.nextConflict"),children:e.jsx(M,{name:"caret-down",size:10})})]}),e.jsx("button",{className:"conflict-close-btn",onClick:r,children:"×"})]}),c||!l?e.jsx("div",{className:"conflict-loading",children:u("terminal:fileExplorer.loadingConflictData")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"conflict-pane-headers",children:[e.jsx("div",{className:"conflict-pane-header current",children:u("terminal:fileExplorer.currentBranchLabel",{branch:h})}),e.jsx("div",{className:"conflict-pane-header incoming",children:u("terminal:fileExplorer.incomingBranchLabel",{branch:o})})]}),e.jsx("div",{className:"conflict-content",ref:y,children:f.map((D,F)=>D.type==="unchanged"?e.jsx("div",{className:"conflict-section-unchanged",children:e.jsxs("div",{className:"conflict-panes",children:[e.jsx("div",{className:"conflict-pane ours",children:e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(D.content,p)}})}),e.jsx("div",{className:"conflict-pane theirs",children:e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(D.content,p)}})})]})},F):e.jsxs("div",{"data-section-idx":F,className:`conflict-section-conflict ${D.resolved?"resolved":""}`,children:[e.jsxs("div",{className:"conflict-panes",children:[e.jsxs("div",{className:`conflict-pane ours ${D.resolved==="ours"||D.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(D.ours,p)}}),e.jsx("button",{className:"conflict-accept-btn ours",onClick:()=>O(F,"ours"),disabled:D.resolved==="ours",children:D.resolved==="ours"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptCurrent")})]}),e.jsxs("div",{className:`conflict-pane theirs ${D.resolved==="theirs"||D.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(D.theirs,p)}}),e.jsx("button",{className:"conflict-accept-btn theirs",onClick:()=>O(F,"theirs"),disabled:D.resolved==="theirs",children:D.resolved==="theirs"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptIncoming")})]})]}),e.jsx("button",{className:`conflict-accept-both-btn ${D.resolved==="both"?"accepted":""}`,onClick:()=>O(F,"both"),disabled:D.resolved==="both",children:D.resolved==="both"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptBoth")})]},F))}),e.jsxs("div",{className:"conflict-actions",children:[e.jsx("button",{className:"conflict-action-btn accept-all-current",onClick:()=>ae("ours"),children:u("terminal:fileExplorer.acceptAllCurrent")}),e.jsx("button",{className:"conflict-action-btn accept-all-incoming",onClick:()=>ae("theirs"),children:u("terminal:fileExplorer.acceptAllIncoming")}),e.jsx("button",{className:"conflict-action-btn accept-all-both",onClick:()=>ae("both"),children:u("terminal:fileExplorer.acceptAllBoth")}),e.jsx("button",{className:"conflict-action-btn save-resolved",onClick:Y,disabled:!C||N,children:u(N?"terminal:fileExplorer.saving":"terminal:fileExplorer.saveAndResolve")})]})]})]})}),gr=16,xr=t.memo(function s({node:n,depth:l,expandedDirs:c,onToggleDir:i,selectedPath:r,onSelect:h}){const{t:o}=oe(["terminal"]),u=l*gr;if(!n.isDirectory){const b=n.file.status,f=xt[b],v=b==="deleted",N=n.file.name.includes(".")?"."+n.file.name.split(".").pop():"";return e.jsxs("div",{className:`git-file-item ${r===n.path?"selected":""}`,onClick:()=>!v&&h(n.file.path,b),style:{paddingLeft:`${u+4}px`,cursor:v?"not-allowed":"pointer"},title:n.file.path,children:[e.jsx("span",{className:"tree-arrow-spacer"}),e.jsx("img",{className:"tree-icon",src:gt(N),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:f.color},children:f.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:["← ",n.file.oldPath.split("/").pop()]})]})}const p=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${p?"expanded":""}`,style:{paddingLeft:`${u+4}px`},onClick:()=>i(n.path),children:[e.jsx("span",{className:`tree-arrow ${p?"expanded":""}`,children:"►"}),e.jsx("img",{className:"tree-folder-icon",src:p?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:o("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),p&&e.jsx("div",{className:"tree-children",children:n.children.map(b=>e.jsx(s,{node:b,depth:l+1,expandedDirs:c,onToggleDir:i,selectedPath:r,onSelect:h},b.path))})]})}),yr=t.memo(function({file:n,isSelected:l,onSelect:c}){const i=xt[n.status],r=n.status==="deleted",h=n.name.includes(".")?"."+n.name.split(".").pop():"",o=n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!r&&c(n.path,n.status),style:{cursor:r?"not-allowed":"pointer"},title:n.path,children:[e.jsx("span",{className:"tree-arrow-spacer"}),e.jsx("img",{className:"tree-icon",src:gt(h),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,o&&e.jsx("span",{className:"git-file-dir",children:o})]}),e.jsx("span",{className:"git-file-status",style:{color:i.color},children:i.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:["← ",n.oldPath.split("/").pop()]})]})});function br({compareResult:s,loading:n,onFileSelect:l,selectedPath:c,onClose:i}){const{t:r}=oe(["terminal"]),[h,o]=t.useState("tree"),[u,p]=t.useState(new Set),b=t.useMemo(()=>!s||s.files.length===0?[]:$t(s.files),[s]),f=t.useMemo(()=>{const w=new Set;return Ht(b,w),w},[b]);t.useEffect(()=>{p(f)},[f]);const v=t.useCallback(w=>{p(T=>{const A=new Set(T);return A.has(w)?A.delete(w):A.add(w),A})},[]),N=t.useMemo(()=>s?[...s.files].sort((w,T)=>w.path.toLowerCase().localeCompare(T.path.toLowerCase())):[],[s]);if(n)return e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsx("span",{className:"branch-comparison-title",children:r("terminal:fileExplorer.comparingBranches")}),e.jsx("button",{className:"branch-comparison-close",onClick:i,title:r("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsx("div",{className:"branch-comparison-empty",children:e.jsx("div",{className:"branch-comparison-empty-text",children:r("terminal:fileExplorer.comparingBranches")})})]});if(!s)return null;const{files:R,counts:y,baseBranch:k,currentBranch:g}=s,j=R.length;return j===0?e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsxs("span",{className:"branch-comparison-title",children:[g," vs ",k]}),e.jsx("button",{className:"branch-comparison-close",onClick:i,title:r("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsxs("div",{className:"branch-comparison-empty",children:[e.jsx("div",{className:"branch-comparison-empty-icon",children:"✨"}),e.jsx("div",{className:"branch-comparison-empty-text",children:r("terminal:fileExplorer.noDifferences")})]})]}):e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsxs("span",{className:"branch-comparison-title",children:["⇔ ",g," vs ",k]}),e.jsx("span",{className:"branch-comparison-file-count",children:r("terminal:fileExplorer.fileCount",{count:j})}),e.jsxs("div",{className:"git-changes-summary",children:[y.modified>0&&e.jsxs("span",{className:"git-count modified",children:[y.modified,"M"]}),y.added>0&&e.jsxs("span",{className:"git-count added",children:[y.added,"A"]}),y.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[y.deleted,"D"]}),y.renamed>0&&e.jsxs("span",{className:"git-count renamed",children:[y.renamed,"R"]}),(y.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[y.conflict,"C"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${h==="flat"?"active":""}`,onClick:()=>o("flat"),title:r("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${h==="tree"?"active":""}`,onClick:()=>o("tree"),title:r("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"branch-comparison-close",onClick:i,title:r("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsx("div",{className:"branch-comparison-list",children:h==="tree"?b.map(w=>e.jsx(xr,{node:w,depth:0,expandedDirs:u,onToggleDir:v,selectedPath:c,onSelect:l},w.path)):N.map(w=>e.jsx(yr,{file:w,isSelected:c===w.path,onSelect:l},w.path))})]})}const dn=t.memo(br);dn.displayName="BranchComparison";function jr(s){const n=new Date(s);if(isNaN(n.getTime()))return s||"—";const c=Date.now()-n.getTime(),i=Math.floor(c/6e4),r=Math.floor(i/60),h=Math.floor(r/24);if(h<4)return i<1?"just now":i<60?`${i}m ago`:r<24?`${r}h ago`:`${h}d ago`;const o=n.getFullYear(),u=String(n.getMonth()+1).padStart(2,"0"),p=String(n.getDate()).padStart(2,"0"),b=String(n.getHours()).padStart(2,"0"),f=String(n.getMinutes()).padStart(2,"0");return`${o}-${u}-${p} ${b}:${f}`}const vr=t.memo(function({commit:n,isSelected:l,onSelect:c}){return e.jsxs("div",{className:`gh-row ${l?"selected":""}`,onClick:()=>c(n),children:[e.jsx("span",{className:"gh-col-hash",children:n.shortHash}),e.jsxs("span",{className:"gh-col-message",children:[e.jsx("span",{className:"gh-subject",children:n.subject}),n.refs.isHead&&e.jsx("span",{className:"gh-badge gh-badge-head",children:"HEAD"}),n.refs.branches.map(i=>e.jsx("span",{className:"gh-badge gh-badge-branch",children:i},i)),n.refs.tags.map(i=>e.jsx("span",{className:"gh-badge gh-badge-tag",children:i},i))]}),e.jsx("span",{className:"gh-col-author",children:n.author}),e.jsx("span",{className:"gh-col-date",children:jr(n.date)})]})}),wr=t.memo(function({files:n,loading:l,selectedFilePath:c,onSelectFile:i}){const{t:r}=oe(["common"]);return l?e.jsx("div",{className:"gh-files-loading",children:r("common:status.loading")}):n.length===0?e.jsx("div",{className:"gh-files-empty",children:"No changed files"}):e.jsx("div",{className:"gh-files-list",children:n.map(h=>{const o=h.path.split("/").pop()||h.path,u=h.path.includes("/")?h.path.substring(0,h.path.lastIndexOf("/")):"",p=xt[h.status],b=o.includes(".")?"."+o.split(".").pop():"";return e.jsxs("div",{className:`gh-file-row ${c===h.path?"selected":""}`,onClick:()=>i==null?void 0:i(h.path),title:h.path,children:[e.jsx("span",{className:"gh-file-status",style:{color:p.color},children:p.icon}),e.jsx("img",{className:"gh-file-icon",src:gt(b),alt:""}),e.jsx("span",{className:"gh-file-name",children:o}),u&&e.jsx("span",{className:"gh-file-dir",children:u})]},h.path)})})}),Cr=t.memo(function({history:n,currentFolder:l,onFileSelect:c}){const{t:i}=oe(["terminal","common"]),r=t.useRef(null),[h,o]=t.useState(null),[u,p]=t.useState(!1),{commits:b,loading:f,loadingMore:v,error:N,hasMore:R,total:y,filters:k,setFilter:g,resetFilters:j,selectedCommit:w,selectCommit:T,commitFiles:A,commitFilesLoading:K,loadHistory:C,loadMore:O,authors:ae,loadAuthors:Y}=n,{branches:D,loadBranches:F}=rs();t.useEffect(()=>{l&&(C(l),Y(l),F(l))},[l,C,Y,F]);const V=Zn({count:b.length,getScrollElement:()=>r.current,estimateSize:()=>28,overscan:20}),ne=t.useCallback(()=>{const P=r.current;if(!P||v||!R||!l)return;const{scrollTop:G,scrollHeight:I,clientHeight:ie}=P;I-G-ie<200&&O(l)},[v,R,l,O]),re=t.useCallback(P=>{o(P),c&&w&&c(P,w.hash)},[c,w]),je=t.useMemo(()=>D.filter(P=>!P.isRemote).map(P=>P.name),[D]),U=!!(k.branch||k.author||k.since||k.until||k.searchPath||k.search),Z=V.getVirtualItems();return e.jsxs("div",{className:"gh-panel",children:[e.jsxs("div",{className:"gh-toolbar",children:[e.jsx("span",{className:"gh-toolbar-title",children:i("terminal:fileExplorer.gitHistory.title")}),e.jsx("span",{className:"gh-toolbar-count",children:f?"...":y>0?y:b.length}),e.jsx("input",{type:"text",className:"gh-search-input",placeholder:i("terminal:fileExplorer.gitHistory.searchPlaceholder"),value:k.search,onChange:P=>g("search",P.target.value)}),e.jsx("button",{className:`gh-filter-toggle ${u?"active":""} ${U?"has-filters":""}`,onClick:()=>p(!u),title:"Filters",children:e.jsx(M,{name:"gear",size:12})}),U&&e.jsx("button",{className:"gh-reset-btn",onClick:j,children:i("terminal:fileExplorer.gitHistory.resetFilters")})]}),u&&e.jsxs("div",{className:"gh-filters-row",children:[e.jsxs("select",{className:"gh-filter-select",value:k.branch,onChange:P=>g("branch",P.target.value),children:[e.jsx("option",{value:"",children:i("terminal:fileExplorer.gitHistory.allBranches")}),je.map(P=>e.jsx("option",{value:P,children:P},P))]}),e.jsxs("select",{className:"gh-filter-select",value:k.author,onChange:P=>g("author",P.target.value),children:[e.jsx("option",{value:"",children:i("terminal:fileExplorer.gitHistory.allAuthors")}),ae.map(P=>e.jsx("option",{value:P,children:P},P))]}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.since,onChange:P=>g("since",P.target.value),title:i("terminal:fileExplorer.gitHistory.since")}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.until,onChange:P=>g("until",P.target.value),title:i("terminal:fileExplorer.gitHistory.until")}),e.jsx("input",{type:"text",className:"gh-filter-input",placeholder:i("terminal:fileExplorer.gitHistory.pathFilter"),value:k.searchPath,onChange:P=>g("searchPath",P.target.value)})]}),e.jsxs("div",{className:"gh-body",children:[e.jsxs("div",{className:"gh-commits-section",children:[e.jsxs("div",{className:"gh-header-row",children:[e.jsx("span",{className:"gh-col-hash",children:"Hash"}),e.jsx("span",{className:"gh-col-message",children:"Message"}),e.jsx("span",{className:"gh-col-author",children:"Author"}),e.jsx("span",{className:"gh-col-date",children:"Date"})]}),f&&b.length===0?e.jsx("div",{className:"gh-state-msg",children:i("common:status.loading")}):N?e.jsx("div",{className:"gh-state-msg gh-error",children:N}):b.length===0?e.jsx("div",{className:"gh-state-msg",children:i("terminal:fileExplorer.gitHistory.noCommits")}):e.jsxs("div",{className:"gh-commit-scroll",ref:r,onScroll:ne,children:[e.jsx("div",{style:{height:`${V.getTotalSize()}px`,width:"100%",position:"relative"},children:Z.map(P=>e.jsx("div",{"data-index":P.index,ref:V.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${P.start}px)`},children:e.jsx(vr,{commit:b[P.index],isSelected:(w==null?void 0:w.hash)===b[P.index].hash,onSelect:T})},P.key))}),v&&e.jsx("div",{className:"gh-loading-more",children:i("common:status.loading")})]})]}),w&&e.jsxs("div",{className:"gh-files-section",children:[e.jsxs("div",{className:"gh-files-header",children:[e.jsxs("span",{className:"gh-files-title",children:[A.length," ",A.length===1?"file":"files"]}),e.jsx("span",{className:"gh-files-commit-info",children:w.shortHash})]}),e.jsx(wr,{files:A,loading:K,selectedFilePath:h,onSelectFile:re})]})]})]})});async function Nr({path:s,cwd:n,limit:l}){const c=new URLSearchParams({path:s,cwd:n});Number.isFinite(l)&&c.set("limit",String(l));const i=await W(B(`/api/files/git-file-history?${c.toString()}`));if(!i.ok){const h=await i.json().catch(()=>({}));throw new Error(h.error||`Failed to load file git history: ${i.statusText}`)}const r=await i.json();return{commits:Array.isArray(r.commits)?r.commits:[]}}async function kr({path:s,cwd:n,sha:l}){const c=new URLSearchParams({path:s,cwd:n,sha:l}),i=await W(B(`/api/files/git-file-commit-diff?${c.toString()}`));if(!i.ok){const h=await i.json().catch(()=>({}));throw new Error(h.error||`Failed to load commit diff: ${i.statusText}`)}const r=await i.json();return r.binary===!0?{binary:!0,filename:r.filename??"",changeType:r.changeType??"modified"}:{binary:!1,filename:r.filename??"",language:r.language??"plaintext",changeType:r.changeType??"modified",originalContent:typeof r.originalContent=="string"?r.originalContent:"",modifiedContent:typeof r.modifiedContent=="string"?r.modifiedContent:""}}const Er=100;function Sr(s){if(!s)return"";const n=Date.parse(s);if(Number.isNaN(n))return s;const l=Date.now()-n,c=Math.round(l/1e3);if(c<60)return`${c}s ago`;const i=Math.round(c/60);if(i<60)return`${i}m ago`;const r=Math.round(i/60);if(r<24)return`${r}h ago`;const h=Math.round(r/24);if(h<30)return`${h}d ago`;const o=Math.round(h/30);return o<12?`${o}mo ago`:`${Math.round(o/12)}y ago`}function Tr(s){if(!s)return"";const n=s.lastIndexOf("/");return n>=0?s.slice(n+1):s}function Mr({isOpen:s,onClose:n,filePath:l,cwd:c}){const{t:i}=oe(["terminal","common"]),[r,h]=t.useState([]),[o,u]=t.useState(!1),[p,b]=t.useState(null),[f,v]=t.useState(null),[N,R]=t.useState(null),[y,k]=t.useState(!1),[g,j]=t.useState(null);t.useEffect(()=>{if(!s)return;let K=!1;return h([]),v(null),R(null),j(null),b(null),u(!0),(async()=>{try{const C=await Nr({path:l,cwd:c,limit:Er});if(K)return;h(C.commits),C.commits.length>0&&v(C.commits[0].sha)}catch(C){if(K)return;b(C instanceof Error?C.message:i("terminal:fileGitHistory.error"))}finally{K||u(!1)}})(),()=>{K=!0}},[s,l,c,i]),t.useEffect(()=>{if(!s||!f){R(null);return}let K=!1;return k(!0),j(null),R(null),(async()=>{try{const C=await kr({path:l,cwd:c,sha:f});if(K)return;R(C)}catch(C){if(K)return;j(C instanceof Error?C.message:i("terminal:fileGitHistory.error"))}finally{K||k(!1)}})(),()=>{K=!0}},[s,f,l,c,i]);const w=t.useCallback(K=>{K.key==="Escape"&&(K.preventDefault(),n())},[n]),T=t.useMemo(()=>Tr(l),[l]),A=()=>y?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:i("terminal:fileGitHistory.loading")})]}):g?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:20}),e.jsx("p",{children:g})]}):N?N.binary?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"file",size:20}),e.jsx("p",{children:i("terminal:fileGitHistory.binaryFile")})]}):e.jsx(ns,{originalContent:N.originalContent,modifiedContent:N.modifiedContent,filename:N.filename||T,filePath:l,language:N.language}):e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:i("terminal:fileGitHistory.selectCommit")})});return s?e.jsx(ea,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"git-file-history-modal",onClick:K=>K.stopPropagation(),onKeyDown:w,tabIndex:-1,children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{className:"git-file-history-title",children:[e.jsx("h2",{children:i("terminal:fileGitHistory.title")}),e.jsx("span",{className:"git-file-history-filepath",title:l,children:T})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(M,{name:"close",size:16})})]}),e.jsxs("div",{className:"git-file-history-body",children:[e.jsx("aside",{className:"git-file-history-commit-list","aria-label":i("terminal:fileGitHistory.title"),children:o?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:i("terminal:fileGitHistory.loading")})]}):p?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:18}),e.jsx("p",{children:p})]}):r.length===0?e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:i("terminal:fileGitHistory.empty")})}):e.jsx("ul",{className:"git-file-history-commits",role:"listbox",children:r.map(K=>{const C=K.sha===f;return e.jsxs("li",{className:`git-file-history-commit ${C?"selected":""}`,role:"option","aria-selected":C,onClick:()=>v(K.sha),children:[e.jsxs("div",{className:"git-file-history-commit-row",children:[e.jsx("span",{className:"git-file-history-sha",children:K.shortSha}),e.jsx("span",{className:"git-file-history-date",title:K.date,children:Sr(K.date)})]}),e.jsx("div",{className:"git-file-history-subject",title:K.subject,children:K.subject}),e.jsx("div",{className:"git-file-history-author",title:K.email,children:K.author})]},K.sha)})})}),e.jsx("section",{className:"git-file-history-diff","aria-live":"polite",children:A()})]})]})})}):null}function Pr({isOpen:s,areaId:n,onClose:l,onChangeArea:c,folderPath:i}){const{t:r}=oe(["terminal","common"]),h=ta(),o=sa(),u=na(),p=!!i&&!n,b=!p&&n?h.get(n):null,f=p?[i]:(b==null?void 0:b.directories)||[],v=Array.from(h.values()),[N,R]=t.useState(0),[y,k]=t.useState(null),[g,j]=t.useState(!1),[w,T]=t.useState(""),A=t.useRef(null),K=f[N]||f[0]||null,C=K?K.replace(/\\/g,"/"):null,O=C?Pt(C):"";t.useEffect(()=>{R(0)},[i,p]),t.useEffect(()=>{!p&&i&&k(i)},[p,i]),t.useEffect(()=>{if(s)try{p&&i?localStorage.setItem("file-explorer-last-opened",JSON.stringify({type:"folder",path:i})):n&&localStorage.setItem("file-explorer-last-opened",JSON.stringify({type:"area",areaId:n}))}catch{}},[s,p,i,n]);const ae=t.useMemo(()=>{const a=[];for(const d of v)for(const x of d.directories)a.push({path:x,areaId:d.id,areaName:d.name,areaColor:d.color});return a},[v]),Y=t.useMemo(()=>{const a=w.trim().toLowerCase();return a?ae.filter(d=>{const x=(d.path.split("/").pop()||d.path).toLowerCase();return d.path.toLowerCase().includes(a)||x.includes(a)}):ae},[ae,w]);t.useEffect(()=>{var a;g?(a=A.current)==null||a.focus():T("")},[g]);const{tree:D,loading:F,expandedPaths:V,loadTree:ne,reloadDirectory:re,renamePathInTree:je,togglePath:U,expandToPath:Z,restoreExpandedPaths:P,setExpandedPaths:G}=aa(C),{gitStatus:I,loading:ie,loadGitStatus:ee}=ua(C),{mergeBranch:ve,mergeAbort:m,mergeContinue:X}=rs(),le=Ra(),{showToast:z}=tn(),{file:$,loading:S,error:te,loadFile:Q,clearFile:de,setFile:pe}=ya(),{treePanelWidth:se,handleResizeStart:we,isResizing:Ge}=Na(),{mobileTreeHeight:He,handleResizeMouseDown:Gt,handleResizeTouchStart:ze}=Ta(),{loadProjectState:yt,saveProjectState:Ue,loadRecentProjects:ot,pushRecentProject:bt}=Ca(),[jt,vt]=t.useState(()=>ot()),wt=t.useMemo(()=>{const a=new Map(ae.map(x=>[x.path.replace(/\\/g,"/"),x])),d=[];for(const x of jt){const H=a.get(x);if(H&&d.push(H),d.length>=5)break}return d},[jt,ae]),[ye,ue]=t.useState(null),[xe,ke]=t.useState("files"),[We,Re]=t.useState(""),[E,L]=t.useState([]),[_,be]=t.useState([]),[Me,qe]=t.useState(!1),[ct,me]=t.useState(null),[un,Fe]=t.useState(null),[os,Ct]=t.useState(!1),[Pe,Ut]=t.useState(!1),[dt,hn]=t.useState(!1),[mn,cs]=t.useState(new Set),[ds]=t.useState(!1),[Bt,fn]=t.useState(!1),[_t,pn]=t.useState(250),ut=t.useRef(null),[Ae,Nt]=t.useState(null),[gn,us]=t.useState(!1),[Je,hs]=t.useState(null),[Ye,ms]=t.useState(null),[Xe,xn]=t.useState(null),[Kt,Vt]=t.useState({open:!1,path:"",cwd:""}),[fe,Be]=t.useState({isOpen:!1,node:null,value:"",submitting:!1}),[Ce,Qe]=t.useState({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1}),[Se,fs]=t.useState(null),yn=ra(),kt=ia(yn),bn=la(),[Ie,Oe]=t.useState([]),[he,De]=t.useState(null),[,Wt]=t.useState(void 0),[ps,Ze]=t.useState(null),[ht,mt]=t.useState(null),[jn,et]=t.useState(null),[vn,gs]=t.useState(!1),[Et,qt]=t.useState(null),[xs,Jt]=t.useState(!1),[St,Tt]=t.useState(null),ys=t.useRef(null),Yt=t.useRef(null),bs=t.useRef(null),ft=t.useRef(null),js=t.useRef(C);t.useEffect(()=>{js.current=C},[C]);const Mt=t.useRef(!1);t.useEffect(()=>{Mt.current=!1},[n,i]),t.useEffect(()=>{if(!s||Mt.current)return;if(p){Mt.current=!0,R(0);return}if(f.length===0)return;if(Mt.current=!0,y){const x=f.indexOf(y);R(x>=0?x:0),k(null);return}const a=f.map(x=>x.replace(/\\/g,"/")),d=ot().find(x=>a.includes(x));R(d?a.indexOf(d):0)},[s,p,f,y,ot]),t.useEffect(()=>{if(!s||!C)return;const a=setTimeout(()=>vt(bt(C)),250);return()=>clearTimeout(a)},[s,C,bt]),t.useEffect(()=>{if(!s||Pe||!C)return;const a=C;(async()=>{const x=await yt(a);js.current===a&&(x?(Oe(x.tabs),De(x.activeTabPath),ke(x.viewMode),G(x.expandedPaths),ft.current=x.expandedPaths,Ct(!0),x.activeTabPath?(ue(x.activeTabPath),Q(x.activeTabPath)):(ue(null),de())):(Oe([]),De(null),ue(null),de(),ft.current=null),Ut(!0))})()},[s,Pe,C,yt,G,Q,de]),t.useEffect(()=>{if(ft.current&&!F&&D.length>0){const a=ft.current;ft.current=null,P(a)}},[F,D,Pe,P]);const vs=t.useRef(null);t.useEffect(()=>{vs.current=Pe&&C?{key:C,state:{tabs:Ie,activeTabPath:he,viewMode:xe,expandedPaths:V}}:null},[Pe,C,Ie,he,xe,V]);const pt=t.useCallback(()=>{const a=vs.current;a&&Ue(a.key,a.state)},[Ue]);t.useEffect(()=>{if(!s||!Pe||!C)return;const a=C,d=setTimeout(()=>{Ue(a,{tabs:Ie,activeTabPath:he,viewMode:xe,expandedPaths:V})},500);return()=>clearTimeout(d)},[s,Pe,C,Ie,he,xe,V,Ue]),t.useEffect(()=>()=>pt(),[pt]);const ws=t.useRef(s);t.useEffect(()=>{ws.current&&!s&&pt(),ws.current=s},[s,pt]),t.useEffect(()=>{Ut(!1)},[C]),t.useEffect(()=>{if(!fe.isOpen)return;const a=window.setTimeout(()=>{var d,x;(d=Yt.current)==null||d.focus(),(x=Yt.current)==null||x.select()},0);return()=>window.clearTimeout(a)},[fe.isOpen]),t.useEffect(()=>{if(!Ce.isOpen)return;const a=window.setTimeout(()=>{var d;(d=bs.current)==null||d.focus()},0);return()=>window.clearTimeout(a)},[Ce.isOpen]);const Le=t.useMemo(()=>{const a=We.trim(),d=a.match(/^(.+):(\d+)$/);return d?{query:d[1],lineNumber:parseInt(d[2],10)}:{query:a,lineNumber:void 0}},[We]);t.useEffect(()=>{if(!Le.query||!C){L([]),be([]),qe(!1);return}qe(!0);const a=new AbortController,{signal:d}=a,x=setTimeout(async()=>{try{const H=Le.query,J=W(B(`/api/files/search?path=${encodeURIComponent(C)}&q=${encodeURIComponent(H)}&limit=200`),{signal:d}).then(ge=>ge.json()).catch(()=>({results:[]})),q=H.length>=2&&!Le.lineNumber?W(B(`/api/files/search-content?path=${encodeURIComponent(C)}&q=${encodeURIComponent(H)}&limit=200`),{signal:d}).then(ge=>ge.json()).catch(()=>({results:[]})):Promise.resolve({results:[]}),[Ne,ce]=await Promise.all([J,q]);if(d.aborted)return;L(Ne.results||[]),be(ce.results||[])}catch(H){if(d.aborted)return;console.error("[FileExplorer] Search failed:",H),L([]),be([])}d.aborted||qe(!1)},300);return()=>{clearTimeout(x),a.abort()}},[Le.query,Le.lineNumber,C]),t.useEffect(()=>{s&&C&&(de(),ue(null),me(null),Fe(null),Ct(!1),ne(),ee())},[s,C,ne,ee,de]),t.useEffect(()=>{if(o&&s){const a=o;if(u){const d=Pt(a),x=a.substring(a.lastIndexOf(".")).toLowerCase();Dt(a,d,x),Rt(a)}else Q(a),ue(a);_e.clearFileViewerPath()}},[o,u,s,Q]),t.useEffect(()=>{Pe&&!os&&I&&Ct(!0)},[I,os,Pe,xe]),t.useEffect(()=>{if(n&&(de(),ue(null),Re(""),be([]),L([]),me(null),Fe(null),Ct(!1),Ut(!1),y)){const a=h.get(n);a!=null&&a.directories.includes(y)||k(null)}},[n,y,h,de]),t.useEffect(()=>{const a=x=>{var J;if(!s)return;if(x.altKey&&x.key==="e"){x.preventDefault(),x.stopPropagation(),l();return}if(x.key==="Escape"){if(fe.isOpen){x.preventDefault(),x.stopPropagation(),fe.submitting||Be({isOpen:!1,node:null,value:"",submitting:!1});return}if(ds)return;if(g){x.preventDefault(),x.stopPropagation(),j(!1);return}x.preventDefault(),x.stopPropagation(),l();return}(x.metaKey||x.ctrlKey)&&x.key==="p"&&(x.preventDefault(),(J=ys.current)==null||J.focus());const H=_e.getShortcuts().find(q=>q.id==="file-explorer-close-tab");if(da(x,H)){if(x.repeat)return;x.preventDefault(),x.stopPropagation(),he&&Es(he)}},d=x=>{const H=x.target;g&&!H.closest(".file-explorer-folder-selector")&&!H.closest(".file-explorer-folder-dropdown")&&j(!1)};return document.addEventListener("keydown",a,!0),document.addEventListener("click",d),()=>{document.removeEventListener("keydown",a,!0),document.removeEventListener("click",d)}},[s,l,g,he,ds,fe]);const Cs=t.useMemo(()=>{const a=new Map;if(I!=null&&I.files)for(const d of I.files)a.set(d.path,d.status);return a},[I==null?void 0:I.files]),Xt=t.useMemo(()=>{const a=new Map;if(!(I!=null&&I.files))return a;const d={conflict:0,modified:1,added:2,deleted:3,untracked:4,renamed:5};for(const x of I.files){let H=x.path.replace(/\\/g,"/");for(;;){const J=H.lastIndexOf("/");if(J<=0)break;H=H.substring(0,J);const q=a.get(H);q?d[x.status]<d[q]&&a.set(H,x.status):a.set(H,x.status)}}return a},[I==null?void 0:I.files]),Ns=t.useMemo(()=>{const a=d=>({...d,gitStatus:d.isDirectory?Xt.get(d.path):Cs.get(d.path),hasGitChanges:d.isDirectory&&Xt.has(d.path)||void 0,children:d.children?d.children.map(a):void 0});return D.map(a)},[D,Cs,Xt]),Dt=(a,d,x,H)=>{if(!Ie.find(q=>q.path===a)){const q={path:a,filename:d,extension:x};Oe(Ne=>[...Ne,q])}De(a),ue(a),Wt(H),Q(a)},ks=async a=>{if(a.isDirectory){ke("files"),Re(""),await Z(a.path),ue(a.path),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let d=a.path,x=document.querySelector(`[data-path="${d}"]`);for(;!x&&d.includes("/");)d=d.substring(0,d.lastIndexOf("/")),x=document.querySelector(`[data-path="${d}"]`);x instanceof HTMLElement&&x.scrollIntoView({behavior:"smooth",block:"center"})})});return}Fe(null),me(null),Dt(a.path,a.name,a.extension,Le.lineNumber)},wn=(a,d)=>{Fe(null),me(null);const x=Pt(a),H=a.substring(a.lastIndexOf(".")).toLowerCase();Dt(a,x,H,d)},Cn=async(a,d)=>{Fe(d),me(null);const x=Pt(a),H=a.substring(a.lastIndexOf(".")).toLowerCase();if(Dt(a,x,H),d==="modified"){const{content:J}=await ha(a);J!==null&&me(J)}},Nn=a=>{De(a),ue(a),Fe(null),me(null),Wt(void 0);const d=Ie.find(x=>x.path===a);d!=null&&d.data||Q(a)},Es=a=>{Oe(d=>{var J;const x=d.filter(q=>q.path!==a),H=d.findIndex(q=>q.path===a);if(H!==-1&&((J=d[H])==null?void 0:J.path)===a&&(he===a||d.find(q=>q.path===he)),x.length>0){if(!x.some(Ne=>Ne.path===he)){const Ne=d.findIndex(Ee=>Ee.path===a),ce=Math.max(0,Math.min(Ne,x.length-1)),ge=x[ce];ge&&(De(ge.path),ue(ge.path),Q(ge.path))}}else De(null),ue(null),de();return x})},kn=t.useCallback(()=>{Oe([]),De(null),ue(null),de()},[de]),Qt=a=>{if(j(!1),a.path.replace(/\\/g,"/")!==C)if(pt(),a.areaId!==n)k(a.path),c&&c(a.areaId);else{const d=f.indexOf(a.path);R(d>=0?d:0)}},$e=t.useCallback(a=>{const d=a.lastIndexOf("/");return d<=0?"/":a.slice(0,d)},[]),tt=t.useCallback((a,d,x)=>a===d?x:a.startsWith(`${d}/`)?`${x}${a.slice(d.length)}`:a,[]),En=t.useCallback((a,d)=>{ue(d.path),hs({isOpen:!0,position:{x:a.clientX,y:a.clientY},node:d})},[]),Sn=t.useCallback(a=>{a.defaultPrevented||C&&(a.preventDefault(),ms({isOpen:!0,position:{x:a.clientX,y:a.clientY},parentDir:C}))},[C]),Ss=t.useCallback(a=>{Be({isOpen:!0,node:a,value:a.name,submitting:!1})},[]),st=t.useCallback(()=>{Be({isOpen:!1,node:null,value:"",submitting:!1})},[]),nt=t.useCallback((a,d)=>{a&&Qe({isOpen:!0,parentDir:a,isDirectory:d,value:"",submitting:!1})},[]),at=t.useCallback(()=>{Qe({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1})},[]),Ts=t.useCallback(a=>{fs({node:a})},[]),Tn=t.useCallback(async()=>{const a=Se==null?void 0:Se.node;if(a)try{const d=await W(B("/api/files/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,recursive:a.isDirectory})}),x=await d.json().catch(()=>({}));if(!d.ok){z("error","Delete Failed",x.error||"Unable to delete item");return}Oe(J=>J.filter(q=>q.path!==a.path&&!q.path.startsWith(`${a.path}/`))),(he===a.path||he!=null&&he.startsWith(`${a.path}/`))&&(De(null),de()),(ye===a.path||ye!=null&&ye.startsWith(`${a.path}/`))&&ue(null);const H=$e(a.path);await re(H),await ee(),z("success",a.isDirectory?"Folder Deleted":"File Deleted",a.name)}catch(d){console.error("[FileExplorer] Delete failed:",d),z("error","Delete Failed","Unable to delete item")}},[Se,he,ye,$e,re,ee,z,de]),Ms=t.useCallback(async()=>{const{parentDir:a,isDirectory:d,value:x}=Ce,H=x.trim();if(!a||!H){at();return}if(H.includes("/")||H.includes("\\")){z("error","Invalid Name","Name must not contain path separators");return}Qe(J=>({...J,submitting:!0}));try{const J=await W(B("/api/files/create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({parentDir:a,name:H,isDirectory:d})}),q=await J.json();if(!J.ok){z("error","Create Failed",q.error||"Unable to create item"),Qe(ge=>({...ge,submitting:!1}));return}const Ne=q.path,ce=new Set(V);ce.add(a),await re(a),G(ce),await ee(),ue(Ne),z("success",d?"Folder Created":"File Created",H),at()}catch(J){console.error("[FileExplorer] Create failed:",J),z("error","Create Failed","Unable to create item"),Qe(q=>({...q,submitting:!1}))}},[Ce,V,re,G,ee,z,at]),Ds=t.useCallback(async()=>{const a=fe.node;if(!a)return;const d=fe.value.trim();if(!d||d===a.name){st();return}Be(x=>({...x,submitting:!0}));try{const x=await W(B("/api/files/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,newName:d})}),H=await x.json();if(!x.ok){z("error","Rename Failed",H.error||"Unable to rename item"),Be(Ee=>({...Ee,submitting:!1}));return}const J=H.newPath,q=a.path,Ne=new Set(Array.from(V).map(Ee=>tt(Ee,q,J))),ce=$e(q),ge=$e(J);if(Oe(Ee=>Ee.map(Te=>{if(!Te.path.startsWith(q))return Te;const rt=tt(Te.path,q,J),Ft=rt.split("/").pop()||rt,zs=Ft.includes(".")?`.${Ft.split(".").pop()}`:"";return{...Te,path:rt,filename:Ft,extension:zs.toLowerCase(),data:Te.data?{...Te.data,path:rt,filename:Ft,extension:zs.toLowerCase()}:Te.data}})),he&&De(tt(he,q,J)),ye&&ue(tt(ye,q,J)),$!=null&&$.path){const Ee=tt($.path,q,J);if(Ee!==$.path){const Te=Ee.split("/").pop()||Ee,rt=Te.includes(".")?`.${Te.split(".").pop()}`:"";pe({...$,path:Ee,filename:Te,extension:rt.toLowerCase()})}}je(q,J),G(Ne),await re(ce),ge!==ce&&await re(ge),await ee(),z("success","Renamed",`${a.name} renamed`),st()}catch(x){console.error("[FileExplorer] Rename failed:",x),z("error","Rename Failed","Unable to rename item"),Be(H=>({...H,submitting:!1}))}},[fe,st,he,ye,$,V,tt,$e,je,G,re,ee,z,pe]),Rs=t.useCallback(a=>{xn({sourcePath:a.path,isDirectory:a.isDirectory,name:a.name}),z("info","Copied",`${a.name} ready to paste`)},[z]),Fs=t.useCallback(async a=>{if(!Xe)return;const d=a.isDirectory?a.path:$e(a.path),x=new Set(V);x.add(d);try{const H=await W(B("/api/files/paste"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourcePath:Xe.sourcePath,targetDir:d})}),J=await H.json();if(!H.ok){z("error","Paste Failed",J.error||"Unable to paste item");return}await re(d),G(x),await ee(),J.destinationPath&&ue(J.destinationPath),z("success","Pasted",`${Xe.name} pasted`)}catch(H){console.error("[FileExplorer] Paste failed:",H),z("error","Paste Failed","Unable to paste item")}},[Xe,$e,V,re,G,ee,z]),Ps=t.useCallback(async a=>{try{await navigator.clipboard.writeText(a.path),z("success","Copied","Full path copied")}catch(d){console.error("[FileExplorer] Copy path failed:",d),z("error","Copy Failed","Could not copy path")}},[z]),Is=t.useCallback(a=>{a.isDirectory||!C||Vt({open:!0,path:a.path,cwd:C})},[C]),Mn=t.useCallback(a=>{!C||!a||Vt({open:!0,path:a,cwd:C})},[C]),Ls=t.useCallback(async a=>{try{await _e.runTests(a.path)}catch(d){z("error","Run Tests Failed",d instanceof Error?d.message:"Unable to start tests")}},[z]),Dn=t.useMemo(()=>{if(!Je)return[];const a=Je.node,d=a.isDirectory?a.path:$e(a.path),x=[{id:"create-file",label:a.isDirectory?"New File...":"New File Here...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>nt(d,!1)},{id:"create-folder",label:a.isDirectory?"New Folder...":"New Folder Here...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>nt(d,!0)},{id:"divider-create",label:"",divider:!0,onClick:()=>{}},{id:"rename",label:a.isDirectory?"Rename Folder":"Rename File",icon:e.jsx(M,{name:"edit",size:14}),onClick:()=>Ss(a)},{id:"copy",label:a.isDirectory?"Copy Folder":"Copy File",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>Rs(a)},{id:"paste",label:a.isDirectory?"Paste Into Folder":"Paste Here",icon:e.jsx(M,{name:"clipboard",size:14}),disabled:!Xe,onClick:()=>{Fs(a)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"copy-full-path",label:"Copy Full Path",icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{Ps(a)}}];return a.runnerType&&x.push({id:"divider-run-tests",label:"",divider:!0,onClick:()=>{}},{id:"run-tests",label:a.isDirectory?"Run Tests":"Run This Test",icon:e.jsx(M,{name:"flask",size:14}),onClick:()=>{Ls(a)}}),a.isDirectory||x.push({id:"divider-git-history",label:"",divider:!0,onClick:()=>{}},{id:"git-history",label:r("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),onClick:()=>Is(a)}),x.push({id:"divider-delete",label:"",divider:!0,onClick:()=>{}},{id:"delete",label:a.isDirectory?"Delete Folder":"Delete File",icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>Ts(a)}),x},[Je,Xe,$e,nt,Ss,Rs,Fs,Ps,Is,Ts,Ls,r]),Rn=t.useMemo(()=>{if(!Ye)return[];const a=Ye.parentDir;return[{id:"create-file-root",label:"New File...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>nt(a,!1)},{id:"create-folder-root",label:"New Folder...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>nt(a,!0)}]},[Ye,nt]),Rt=t.useCallback(async a=>{ke("files"),Re(""),await Z(a),ue(a),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let d=a,x=document.querySelector(`[data-path="${d}"]`);for(;!x&&d.includes("/");)d=d.substring(0,d.lastIndexOf("/")),x=document.querySelector(`[data-path="${d}"]`);x instanceof HTMLElement&&x.scrollIntoView({behavior:"smooth",block:"center"})})})},[Z]),Fn=t.useCallback(async a=>{if(!(!C||a.length===0)){cs(d=>{const x=new Set(d);for(const H of a)x.add(H);return x});try{const d=await W(B("/api/files/git-add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:a,directory:C})});if(d.ok)await ee();else{const x=await d.json();console.error("[FileExplorer] Git add failed:",x.error)}}catch(d){console.error("[FileExplorer] Git add failed:",d)}finally{cs(d=>{const x=new Set(d);for(const H of a)x.delete(H);return x})}}},[C,ee]),Pn=t.useCallback(async a=>{if(!C)return;Ze(a);const d=await ve(C,a);if(await ee(),d.success)Ze(null),z("success","Merge Complete",`Merged '${a}' successfully`),ne();else if(d.conflicts&&d.conflicts.length>0){const x=d.conflicts.length;z("warning","Merge Conflicts",`${x} conflict${x>1?"s":""} found — resolve to continue`),ke("git")}else Ze(null),z("error","Merge Failed",d.error||"Merge failed")},[C,ve,ee,ne,z]),In=t.useCallback(async a=>{Ze("remote"),await ee();const d=a.length;z("warning","Pull Conflicts",`${d} conflict${d>1?"s":""} found — resolve to continue`),ke("git")},[ee,z]),Ln=t.useCallback(async a=>{if(C){mt(a),gs(!0),et(null);try{const d=await W(B(`/api/files/git-conflict-file?path=${encodeURIComponent(C)}&file=${encodeURIComponent(a)}`)),x=await d.json();d.ok?et(x):console.error("[FileExplorer] Failed to load conflict file:",x.error)}catch(d){console.error("[FileExplorer] Failed to load conflict file:",d)}finally{gs(!1)}}},[C]),$n=t.useCallback(async a=>{if(!(!C||!ht))try{const d=await W(B("/api/files/git-resolve-conflict"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:C,file:ht,content:a})}),x=await d.json();d.ok&&x.success?(mt(null),et(null),await ee()):console.error("[FileExplorer] Failed to resolve conflict:",x.error)}catch(d){console.error("[FileExplorer] Failed to resolve conflict:",d)}},[C,ht,ee]),Hn=t.useCallback(async()=>{if(!C)return;const a=await X(C);a.success?(Ze(null),mt(null),et(null),z("success","Merge Complete","Merge completed successfully"),await ee(),ne()):z("error","Merge Failed",a.error||"Merge continue failed")},[C,X,ee,ne,z]),zn=t.useCallback(async()=>{if(!C)return;const a=await m(C);a.success?(Ze(null),mt(null),et(null),z("info","Merge Aborted","Merge has been aborted"),await ee(),ne()):z("error","Abort Failed",a.error||"Failed to abort merge")},[C,m,ee,ne,z]),An=t.useCallback(async a=>{if(C){Tt(a),Jt(!0),qt(null),ke("compare");try{const d=await W(B(`/api/files/git-branch-compare?directory=${encodeURIComponent(C)}&branch=${encodeURIComponent(a)}`)),x=await d.json();d.ok?qt(x):(z("error","Compare Failed",x.error||"Failed to compare branches"),ke("files"),Tt(null))}catch(d){console.error("[FileExplorer] Branch compare failed:",d),z("error","Compare Failed","Network error during comparison"),ke("files"),Tt(null)}finally{Jt(!1)}}},[C,z]),On=t.useCallback(async(a,d)=>{if(!C||!St)return;const x=a.split("/").pop()||a,H=a.substring(a.lastIndexOf(".")).toLowerCase();Ie.find(ce=>ce.path===a)||Oe(ce=>[...ce,{path:a,filename:x,extension:H}]),De(a),ue(a),Wt(void 0);const q=async ce=>{try{const ge=await W(B(`/api/files/git-show?path=${encodeURIComponent(a)}&ref=${encodeURIComponent(ce)}`)),Ee=await ge.json();return ge.ok?Ee.content??"":""}catch{return""}},Ne=ce=>({path:a,filename:x,extension:H,content:ce,fileType:"text",size:ce.length,modified:""});if(d==="modified"||d==="renamed"){const[ce,ge]=await Promise.all([q(St),q("HEAD")]);me(ce),pe(Ne(ge)),Fe("modified")}else if(d==="deleted"){const ce=await q(St);me(ce),pe(Ne("")),Fe("modified")}else if(d==="added"){const ce=await q("HEAD");me(""),pe(Ne(ce)),Fe("modified")}},[C,St,Ie]),$s=t.useCallback(()=>{ke("files"),qt(null),Tt(null),Jt(!1)},[]),Gn=t.useCallback(async(a,d)=>{if(C){us(!0);try{const x=new URLSearchParams({path:C,hash:d,file:a}),H=await W(B(`/api/files/git-commit-file-diff?${x}`)),J=await H.json();H.ok?Nt(J):Nt(null)}catch(x){console.error("[FileExplorer] commit diff fetch error:",x),Nt(null)}finally{us(!1)}}},[C]),Un=t.useCallback(()=>{Nt(null)},[]),Bn=t.useCallback(a=>{a.preventDefault(),ut.current={startY:a.clientY,startHeight:_t};const d=H=>{if(!ut.current)return;const J=ut.current.startY-H.clientY,q=Math.max(120,Math.min(600,ut.current.startHeight+J));pn(q)},x=()=>{ut.current=null,document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",x)};document.addEventListener("mousemove",d),document.addEventListener("mouseup",x)},[_t]);if(!s||!b&&!p)return null;const Hs=(I==null?void 0:I.files.length)||0;return e.jsxs("div",{className:"file-explorer-panel ide-style",children:[e.jsxs("div",{className:"file-explorer-panel-header",children:[e.jsxs("div",{className:"file-explorer-panel-header-row",children:[e.jsxs("div",{className:"file-explorer-panel-title",children:[C&&e.jsxs("div",{className:"file-explorer-folder-selector",onClick:()=>ae.length>0&&j(!g),style:{cursor:ae.length>0?"pointer":"default"},title:C,children:[e.jsx("span",{className:"file-explorer-panel-dot",style:{background:(b==null?void 0:b.color)||"#ffd700"}}),e.jsx("span",{className:"file-explorer-folder-name",children:O}),e.jsx("span",{className:"file-explorer-folder-path-hint",children:C}),ae.length>1&&e.jsx("span",{className:"file-explorer-folder-dropdown-icon",children:e.jsx(M,{name:"caret-down",size:10})})]}),(I==null?void 0:I.isGitRepo)&&C&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"file-explorer-path-separator",children:"/"}),e.jsx(hr,{currentFolder:C,gitStatus:I,onBranchChanged:()=>{ee(),ne()},onMerge:Pn,onCompare:An,onPullConflicts:In})]}),$&&e.jsxs("span",{className:"file-explorer-current-file",children:["/ ",$.filename]}),g&&ae.length>0&&e.jsxs("div",{className:"file-explorer-folder-dropdown",onWheel:a=>{a.preventDefault(),a.currentTarget.scrollTop+=a.deltaY*.35},children:[e.jsx("div",{className:"file-explorer-folder-dropdown-search",onClick:a=>a.stopPropagation(),children:e.jsx("input",{ref:A,type:"text",className:"file-explorer-folder-dropdown-search-input",placeholder:"Filter folders…",value:w,onChange:a=>T(a.target.value),onKeyDown:a=>{a.key==="Enter"&&Y.length>0&&(a.preventDefault(),Qt(Y[0]))},spellCheck:!1,autoComplete:"off","aria-label":"Filter folders"})}),Y.length===0?e.jsx("div",{className:"file-explorer-folder-dropdown-empty",children:"No matching folders"}):Y.map(a=>e.jsxs("div",{className:`file-explorer-folder-option ${a.path===C?"active":""}`,onClick:d=>{d.stopPropagation(),Qt(a)},children:[e.jsxs("span",{className:"file-explorer-folder-option-name",children:[e.jsx("span",{className:"file-explorer-folder-option-dot",style:{background:a.areaColor}}),a.path.split("/").pop()||a.path]}),(a.path.split("/").pop()||a.path)!==a.path&&e.jsx("span",{className:"file-explorer-folder-option-path",children:a.path}),e.jsx("span",{className:"file-explorer-folder-option-area",children:a.areaName})]},`${a.areaId}-${a.path}`))]})]}),(I==null?void 0:I.isGitRepo)&&e.jsx("button",{className:`file-explorer-history-toggle ${Bt?"active":""}`,onClick:()=>fn(!Bt),title:r("terminal:fileExplorer.gitHistory.title"),children:e.jsx(M,{name:"status-waiting-input",size:14})}),kt&&!bn&&e.jsxs("button",{className:`file-explorer-test-results-toggle status-${kt.status}`,onClick:()=>_e.openTestResults(),title:kt.status==="running"?"Tests running — open results":"Open last test results",children:[e.jsx(M,{name:"flask",size:14}),kt.status==="running"&&e.jsx("span",{className:"fe-test-run-dot"})]}),e.jsx("button",{className:"file-explorer-panel-close",onClick:l,children:"×"})]}),wt.length>1&&e.jsx("div",{className:"file-explorer-recent-projects",role:"group","aria-label":"Recent projects",children:wt.map(a=>{const d=a.path.split("/").pop()||a.path,x=a.path.replace(/\\/g,"/")===C;return e.jsxs("button",{type:"button",className:`file-explorer-recent-chip ${x?"active":""}`,onClick:()=>Qt(a),title:a.path,children:[e.jsx("span",{className:"file-explorer-recent-chip-dot",style:{background:a.areaColor}}),e.jsx("span",{className:"file-explorer-recent-chip-name",children:d})]},`${a.areaId}-${a.path}`)})})]}),e.jsxs("div",{className:"file-explorer-main",style:He>0?{"--fe-mobile-tree-height":`${He}px`}:void 0,children:[e.jsxs("div",{className:`file-explorer-tree-panel ${dt?"collapsed":""}`,style:{width:se},children:[e.jsxs("div",{className:"file-explorer-tabs",children:[e.jsx("button",{className:"file-explorer-tree-toggle",onClick:()=>hn(!dt),title:r(dt?"terminal:fileExplorer.expandTree":"terminal:fileExplorer.collapseTree"),children:e.jsx(M,{name:dt?"caret-down":"caret-up",size:12})}),e.jsxs("button",{className:`file-explorer-tab ${xe==="files"?"active":""}`,onClick:()=>ke("files"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"folder",size:14})}),r("terminal:spotlight.files")]}),e.jsxs("button",{className:`file-explorer-tab ${xe==="git"?"active":""}`,onClick:()=>ke("git"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"git-branch",size:14})}),r("terminal:fileExplorer.gitChanges"),Hs>0&&e.jsx("span",{className:"tab-badge",children:Hs})]}),(Et||xs)&&e.jsxs("button",{className:`file-explorer-tab ${xe==="compare"?"active":""}`,onClick:()=>ke("compare"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"arrows-horizontal",size:14})}),r("terminal:fileExplorer.diffView"),Et&&e.jsx("span",{className:"tab-badge",children:Et.files.length}),e.jsx("span",{className:"tab-close-btn",onClick:a=>{a.stopPropagation(),$s()},children:"×"})]})]}),xe==="files"&&e.jsxs("div",{className:"file-explorer-toolbar",children:[e.jsxs("div",{className:"file-explorer-search",children:[e.jsx("span",{className:"file-explorer-search-icon",children:e.jsx(M,{name:"search",size:14})}),e.jsx("input",{ref:ys,type:"text",className:"file-explorer-search-input",placeholder:r("terminal:fileExplorer.searchPlaceholder"),value:We,onChange:a=>Re(a.target.value)}),We&&e.jsx("button",{className:"file-explorer-search-clear",onClick:()=>Re(""),children:"×"})]}),e.jsxs("div",{className:"file-explorer-toolbar-buttons",children:[e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>G(new Set),title:r("terminal:fileExplorer.collapseAll"),children:"⊟"}),he&&e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>Rt(he),title:r("terminal:fileExplorer.revealInTree"),children:e.jsx(M,{name:"target",size:14})})]})]}),e.jsx("div",{className:"file-explorer-tree-content",onContextMenu:xe==="files"?Sn:void 0,children:xe==="compare"?e.jsx(dn,{compareResult:Et,loading:xs,onFileSelect:On,selectedPath:ye,onClose:$s}):xe==="files"?F?e.jsx("div",{className:"tree-loading",children:r("common:status.loading")}):Le.query?Me?e.jsx("div",{className:"tree-loading",children:r("terminal:fileExplorer.searching")}):e.jsx(ln,{filenameResults:E,contentResults:_,onSelectFile:ks,onSelectContent:wn,selectedPath:ye,query:Le.query,lineNumber:Le.lineNumber}):e.jsx("div",{className:"file-tree",children:Ns.length===0?e.jsx("div",{className:"tree-empty",children:r("terminal:fileExplorer.noDirectoriesLinked")}):Ns.map(a=>e.jsx(oa,{node:a,depth:0,selectedPath:ye,expandedPaths:V,onSelect:ks,onToggle:U,onContextMenu:En,searchQuery:""},a.path))}):e.jsx(on,{gitStatus:I,loading:ie,onFileSelect:Cn,selectedPath:ye,onRefresh:ee,onStageFiles:Fn,stagingPaths:mn,currentFolder:C,onCommitComplete:()=>{ee(),ne()},mergeInProgress:I==null?void 0:I.mergeInProgress,mergingBranch:ps,onMergeContinue:Hn,onMergeAbort:zn,onConflictOpen:Ln,onRevealInTree:Rt})})]}),e.jsx("div",{className:`file-explorer-resize-handle ${Ge?"active":""}`,onMouseDown:we}),!dt&&e.jsx("div",{className:"fe-mobile-resize-handle",onMouseDown:Gt,onTouchStart:ze}),e.jsx("div",{className:"file-explorer-viewer-panel",children:ht?e.jsx(pr,{file:ht,versions:jn,loading:vn,onResolve:$n,onClose:()=>{mt(null),et(null)},currentBranch:(I==null?void 0:I.branch)||"HEAD",mergingBranch:ps||"incoming"}):Ae?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"commit-diff-header",children:[e.jsx("span",{className:"commit-diff-file",children:Ae.filePath}),e.jsx("span",{className:"commit-diff-hash",children:Ae.hash.slice(0,8)}),e.jsx("button",{className:"commit-diff-close",onClick:Un,children:"×"})]}),e.jsx(ns,{originalContent:Ae.beforeContent,modifiedContent:Ae.afterContent,filename:Ae.filename,filePath:Ae.filePath,language:Os[Ae.extension]||"plaintext"})]}):gn?e.jsx("div",{className:"commit-diff-loading",children:r("common:status.loading")}):e.jsxs(e.Fragment,{children:[e.jsx(cn,{tabs:Ie,activeTabPath:he,onSelectTab:Nn,onCloseTab:Es,onCloseAllTabs:kn,onShowGitHistory:Mn}),un==="modified"&&ct!==null&&$?e.jsx(ns,{originalContent:ct,modifiedContent:$.content,filename:$.filename,filePath:$.path,language:Os[$.extension]||"plaintext"}):e.jsx(an,{file:$,loading:S,error:te,onRevealInTree:Rt,onFileEdited:Q})]})})]}),Bt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"git-history-resize-handle",onMouseDown:Bn}),e.jsx("div",{className:"git-history-bottom-panel",style:{height:_t},children:e.jsx(Cr,{history:le,currentFolder:C,onFileSelect:Gn})})]}),fe.isOpen&&fe.node&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:st,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["Rename ",fe.node.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:fe.node.path,children:fe.node.path}),e.jsx("input",{ref:Yt,type:"text",className:"file-explorer-rename-input",value:fe.value,onChange:a=>Be(d=>({...d,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Ds()):a.key==="Escape"&&(a.preventDefault(),st())},disabled:fe.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:st,disabled:fe.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{Ds()},disabled:fe.submitting||!fe.value.trim(),children:fe.submitting?"Renaming...":"Rename"})]})]})}),Je&&e.jsx(it,{isOpen:Je.isOpen,position:Je.position,worldPosition:{x:0,z:0},actions:Dn,onClose:()=>hs(null)}),Ye&&e.jsx(it,{isOpen:Ye.isOpen,position:Ye.position,worldPosition:{x:0,z:0},actions:Rn,onClose:()=>ms(null)}),Ce.isOpen&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:at,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["New ",Ce.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:Ce.parentDir,children:Ce.parentDir}),e.jsx("input",{ref:bs,type:"text",className:"file-explorer-rename-input",placeholder:Ce.isDirectory?"folder name":"file name",value:Ce.value,onChange:a=>Qe(d=>({...d,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Ms()):a.key==="Escape"&&(a.preventDefault(),at())},disabled:Ce.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:at,disabled:Ce.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{Ms()},disabled:Ce.submitting||!Ce.value.trim(),children:Ce.submitting?"Creating...":"Create"})]})]})}),e.jsx(Mr,{isOpen:Kt.open,filePath:Kt.path,cwd:Kt.cwd,onClose:()=>Vt(a=>({...a,open:!1}))}),e.jsx(ca,{isOpen:!!Se,title:Se!=null&&Se.node.isDirectory?"Delete Folder":"Delete File",message:Se?e.jsxs(e.Fragment,{children:["Permanently delete ",e.jsx("strong",{children:Se.node.name}),"?"]}):"",note:Se!=null&&Se.node.isDirectory?"The folder and everything inside it will be removed from disk.":"The file will be removed from disk.",confirmLabel:"Delete",cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Tn()},onClose:()=>fs(null)})]})}export{Pr as FileExplorerPanel};
|
|
19
|
+
`);await i(D)}finally{R(!1)}},[f,i,h,o]);return e.jsxs("div",{className:"conflict-resolver",children:[e.jsxs("div",{className:"conflict-header",children:[e.jsx("span",{className:"conflict-header-title",children:u("terminal:fileExplorer.resolveFile",{filename:l==null?void 0:l.filename})}),w>0&&e.jsxs("div",{className:"conflict-nav",children:[e.jsx("button",{className:"conflict-nav-btn",onClick:A,title:u("terminal:fileExplorer.prevConflict"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsxs("span",{className:"conflict-nav-counter",children:[k+1," / ",w]}),e.jsx("button",{className:"conflict-nav-btn",onClick:K,title:u("terminal:fileExplorer.nextConflict"),children:e.jsx(M,{name:"caret-down",size:10})})]}),e.jsx("button",{className:"conflict-close-btn",onClick:r,children:"×"})]}),c||!l?e.jsx("div",{className:"conflict-loading",children:u("terminal:fileExplorer.loadingConflictData")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"conflict-pane-headers",children:[e.jsx("div",{className:"conflict-pane-header current",children:u("terminal:fileExplorer.currentBranchLabel",{branch:h})}),e.jsx("div",{className:"conflict-pane-header incoming",children:u("terminal:fileExplorer.incomingBranchLabel",{branch:o})})]}),e.jsx("div",{className:"conflict-content",ref:y,children:f.map((D,F)=>D.type==="unchanged"?e.jsx("div",{className:"conflict-section-unchanged",children:e.jsxs("div",{className:"conflict-panes",children:[e.jsx("div",{className:"conflict-pane ours",children:e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(D.content,p)}})}),e.jsx("div",{className:"conflict-pane theirs",children:e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(D.content,p)}})})]})},F):e.jsxs("div",{"data-section-idx":F,className:`conflict-section-conflict ${D.resolved?"resolved":""}`,children:[e.jsxs("div",{className:"conflict-panes",children:[e.jsxs("div",{className:`conflict-pane ours ${D.resolved==="ours"||D.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(D.ours,p)}}),e.jsx("button",{className:"conflict-accept-btn ours",onClick:()=>O(F,"ours"),disabled:D.resolved==="ours",children:D.resolved==="ours"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptCurrent")})]}),e.jsxs("div",{className:`conflict-pane theirs ${D.resolved==="theirs"||D.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(D.theirs,p)}}),e.jsx("button",{className:"conflict-accept-btn theirs",onClick:()=>O(F,"theirs"),disabled:D.resolved==="theirs",children:D.resolved==="theirs"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptIncoming")})]})]}),e.jsx("button",{className:`conflict-accept-both-btn ${D.resolved==="both"?"accepted":""}`,onClick:()=>O(F,"both"),disabled:D.resolved==="both",children:D.resolved==="both"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptBoth")})]},F))}),e.jsxs("div",{className:"conflict-actions",children:[e.jsx("button",{className:"conflict-action-btn accept-all-current",onClick:()=>ae("ours"),children:u("terminal:fileExplorer.acceptAllCurrent")}),e.jsx("button",{className:"conflict-action-btn accept-all-incoming",onClick:()=>ae("theirs"),children:u("terminal:fileExplorer.acceptAllIncoming")}),e.jsx("button",{className:"conflict-action-btn accept-all-both",onClick:()=>ae("both"),children:u("terminal:fileExplorer.acceptAllBoth")}),e.jsx("button",{className:"conflict-action-btn save-resolved",onClick:Y,disabled:!C||N,children:u(N?"terminal:fileExplorer.saving":"terminal:fileExplorer.saveAndResolve")})]})]})]})}),gr=16,xr=t.memo(function s({node:n,depth:l,expandedDirs:c,onToggleDir:i,selectedPath:r,onSelect:h}){const{t:o}=oe(["terminal"]),u=l*gr;if(!n.isDirectory){const b=n.file.status,f=xt[b],v=b==="deleted",N=n.file.name.includes(".")?"."+n.file.name.split(".").pop():"";return e.jsxs("div",{className:`git-file-item ${r===n.path?"selected":""}`,onClick:()=>!v&&h(n.file.path,b),style:{paddingLeft:`${u+4}px`,cursor:v?"not-allowed":"pointer"},title:n.file.path,children:[e.jsx("span",{className:"tree-arrow-spacer"}),e.jsx("img",{className:"tree-icon",src:gt(N),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:f.color},children:f.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:["← ",n.file.oldPath.split("/").pop()]})]})}const p=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${p?"expanded":""}`,style:{paddingLeft:`${u+4}px`},onClick:()=>i(n.path),children:[e.jsx("span",{className:`tree-arrow ${p?"expanded":""}`,children:"►"}),e.jsx("img",{className:"tree-folder-icon",src:p?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:o("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),p&&e.jsx("div",{className:"tree-children",children:n.children.map(b=>e.jsx(s,{node:b,depth:l+1,expandedDirs:c,onToggleDir:i,selectedPath:r,onSelect:h},b.path))})]})}),yr=t.memo(function({file:n,isSelected:l,onSelect:c}){const i=xt[n.status],r=n.status==="deleted",h=n.name.includes(".")?"."+n.name.split(".").pop():"",o=n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!r&&c(n.path,n.status),style:{cursor:r?"not-allowed":"pointer"},title:n.path,children:[e.jsx("span",{className:"tree-arrow-spacer"}),e.jsx("img",{className:"tree-icon",src:gt(h),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,o&&e.jsx("span",{className:"git-file-dir",children:o})]}),e.jsx("span",{className:"git-file-status",style:{color:i.color},children:i.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:["← ",n.oldPath.split("/").pop()]})]})});function br({compareResult:s,loading:n,onFileSelect:l,selectedPath:c,onClose:i}){const{t:r}=oe(["terminal"]),[h,o]=t.useState("tree"),[u,p]=t.useState(new Set),b=t.useMemo(()=>!s||s.files.length===0?[]:$t(s.files),[s]),f=t.useMemo(()=>{const w=new Set;return zt(b,w),w},[b]);t.useEffect(()=>{p(f)},[f]);const v=t.useCallback(w=>{p(T=>{const A=new Set(T);return A.has(w)?A.delete(w):A.add(w),A})},[]),N=t.useMemo(()=>s?[...s.files].sort((w,T)=>w.path.toLowerCase().localeCompare(T.path.toLowerCase())):[],[s]);if(n)return e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsx("span",{className:"branch-comparison-title",children:r("terminal:fileExplorer.comparingBranches")}),e.jsx("button",{className:"branch-comparison-close",onClick:i,title:r("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsx("div",{className:"branch-comparison-empty",children:e.jsx("div",{className:"branch-comparison-empty-text",children:r("terminal:fileExplorer.comparingBranches")})})]});if(!s)return null;const{files:R,counts:y,baseBranch:k,currentBranch:g}=s,j=R.length;return j===0?e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsxs("span",{className:"branch-comparison-title",children:[g," vs ",k]}),e.jsx("button",{className:"branch-comparison-close",onClick:i,title:r("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsxs("div",{className:"branch-comparison-empty",children:[e.jsx("div",{className:"branch-comparison-empty-icon",children:"✨"}),e.jsx("div",{className:"branch-comparison-empty-text",children:r("terminal:fileExplorer.noDifferences")})]})]}):e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsxs("span",{className:"branch-comparison-title",children:["⇔ ",g," vs ",k]}),e.jsx("span",{className:"branch-comparison-file-count",children:r("terminal:fileExplorer.fileCount",{count:j})}),e.jsxs("div",{className:"git-changes-summary",children:[y.modified>0&&e.jsxs("span",{className:"git-count modified",children:[y.modified,"M"]}),y.added>0&&e.jsxs("span",{className:"git-count added",children:[y.added,"A"]}),y.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[y.deleted,"D"]}),y.renamed>0&&e.jsxs("span",{className:"git-count renamed",children:[y.renamed,"R"]}),(y.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[y.conflict,"C"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${h==="flat"?"active":""}`,onClick:()=>o("flat"),title:r("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${h==="tree"?"active":""}`,onClick:()=>o("tree"),title:r("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"branch-comparison-close",onClick:i,title:r("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsx("div",{className:"branch-comparison-list",children:h==="tree"?b.map(w=>e.jsx(xr,{node:w,depth:0,expandedDirs:u,onToggleDir:v,selectedPath:c,onSelect:l},w.path)):N.map(w=>e.jsx(yr,{file:w,isSelected:c===w.path,onSelect:l},w.path))})]})}const dn=t.memo(br);dn.displayName="BranchComparison";function jr(s){const n=new Date(s);if(isNaN(n.getTime()))return s||"—";const c=Date.now()-n.getTime(),i=Math.floor(c/6e4),r=Math.floor(i/60),h=Math.floor(r/24);if(h<4)return i<1?"just now":i<60?`${i}m ago`:r<24?`${r}h ago`:`${h}d ago`;const o=n.getFullYear(),u=String(n.getMonth()+1).padStart(2,"0"),p=String(n.getDate()).padStart(2,"0"),b=String(n.getHours()).padStart(2,"0"),f=String(n.getMinutes()).padStart(2,"0");return`${o}-${u}-${p} ${b}:${f}`}const vr=t.memo(function({commit:n,isSelected:l,onSelect:c}){return e.jsxs("div",{className:`gh-row ${l?"selected":""}`,onClick:()=>c(n),children:[e.jsx("span",{className:"gh-col-hash",children:n.shortHash}),e.jsxs("span",{className:"gh-col-message",children:[e.jsx("span",{className:"gh-subject",children:n.subject}),n.refs.isHead&&e.jsx("span",{className:"gh-badge gh-badge-head",children:"HEAD"}),n.refs.branches.map(i=>e.jsx("span",{className:"gh-badge gh-badge-branch",children:i},i)),n.refs.tags.map(i=>e.jsx("span",{className:"gh-badge gh-badge-tag",children:i},i))]}),e.jsx("span",{className:"gh-col-author",children:n.author}),e.jsx("span",{className:"gh-col-date",children:jr(n.date)})]})}),wr=t.memo(function({files:n,loading:l,selectedFilePath:c,onSelectFile:i}){const{t:r}=oe(["common"]);return l?e.jsx("div",{className:"gh-files-loading",children:r("common:status.loading")}):n.length===0?e.jsx("div",{className:"gh-files-empty",children:"No changed files"}):e.jsx("div",{className:"gh-files-list",children:n.map(h=>{const o=h.path.split("/").pop()||h.path,u=h.path.includes("/")?h.path.substring(0,h.path.lastIndexOf("/")):"",p=xt[h.status],b=o.includes(".")?"."+o.split(".").pop():"";return e.jsxs("div",{className:`gh-file-row ${c===h.path?"selected":""}`,onClick:()=>i==null?void 0:i(h.path),title:h.path,children:[e.jsx("span",{className:"gh-file-status",style:{color:p.color},children:p.icon}),e.jsx("img",{className:"gh-file-icon",src:gt(b),alt:""}),e.jsx("span",{className:"gh-file-name",children:o}),u&&e.jsx("span",{className:"gh-file-dir",children:u})]},h.path)})})}),Cr=t.memo(function({history:n,currentFolder:l,onFileSelect:c}){const{t:i}=oe(["terminal","common"]),r=t.useRef(null),[h,o]=t.useState(null),[u,p]=t.useState(!1),{commits:b,loading:f,loadingMore:v,error:N,hasMore:R,total:y,filters:k,setFilter:g,resetFilters:j,selectedCommit:w,selectCommit:T,commitFiles:A,commitFilesLoading:K,loadHistory:C,loadMore:O,authors:ae,loadAuthors:Y}=n,{branches:D,loadBranches:F}=rs();t.useEffect(()=>{l&&(C(l),Y(l),F(l))},[l,C,Y,F]);const V=Zn({count:b.length,getScrollElement:()=>r.current,estimateSize:()=>28,overscan:20}),ne=t.useCallback(()=>{const P=r.current;if(!P||v||!R||!l)return;const{scrollTop:G,scrollHeight:I,clientHeight:ie}=P;I-G-ie<200&&O(l)},[v,R,l,O]),re=t.useCallback(P=>{o(P),c&&w&&c(P,w.hash)},[c,w]),je=t.useMemo(()=>D.filter(P=>!P.isRemote).map(P=>P.name),[D]),U=!!(k.branch||k.author||k.since||k.until||k.searchPath||k.search),Z=V.getVirtualItems();return e.jsxs("div",{className:"gh-panel",children:[e.jsxs("div",{className:"gh-toolbar",children:[e.jsx("span",{className:"gh-toolbar-title",children:i("terminal:fileExplorer.gitHistory.title")}),e.jsx("span",{className:"gh-toolbar-count",children:f?"...":y>0?y:b.length}),e.jsx("input",{type:"text",className:"gh-search-input",placeholder:i("terminal:fileExplorer.gitHistory.searchPlaceholder"),value:k.search,onChange:P=>g("search",P.target.value)}),e.jsx("button",{className:`gh-filter-toggle ${u?"active":""} ${U?"has-filters":""}`,onClick:()=>p(!u),title:"Filters",children:e.jsx(M,{name:"gear",size:12})}),U&&e.jsx("button",{className:"gh-reset-btn",onClick:j,children:i("terminal:fileExplorer.gitHistory.resetFilters")})]}),u&&e.jsxs("div",{className:"gh-filters-row",children:[e.jsxs("select",{className:"gh-filter-select",value:k.branch,onChange:P=>g("branch",P.target.value),children:[e.jsx("option",{value:"",children:i("terminal:fileExplorer.gitHistory.allBranches")}),je.map(P=>e.jsx("option",{value:P,children:P},P))]}),e.jsxs("select",{className:"gh-filter-select",value:k.author,onChange:P=>g("author",P.target.value),children:[e.jsx("option",{value:"",children:i("terminal:fileExplorer.gitHistory.allAuthors")}),ae.map(P=>e.jsx("option",{value:P,children:P},P))]}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.since,onChange:P=>g("since",P.target.value),title:i("terminal:fileExplorer.gitHistory.since")}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.until,onChange:P=>g("until",P.target.value),title:i("terminal:fileExplorer.gitHistory.until")}),e.jsx("input",{type:"text",className:"gh-filter-input",placeholder:i("terminal:fileExplorer.gitHistory.pathFilter"),value:k.searchPath,onChange:P=>g("searchPath",P.target.value)})]}),e.jsxs("div",{className:"gh-body",children:[e.jsxs("div",{className:"gh-commits-section",children:[e.jsxs("div",{className:"gh-header-row",children:[e.jsx("span",{className:"gh-col-hash",children:"Hash"}),e.jsx("span",{className:"gh-col-message",children:"Message"}),e.jsx("span",{className:"gh-col-author",children:"Author"}),e.jsx("span",{className:"gh-col-date",children:"Date"})]}),f&&b.length===0?e.jsx("div",{className:"gh-state-msg",children:i("common:status.loading")}):N?e.jsx("div",{className:"gh-state-msg gh-error",children:N}):b.length===0?e.jsx("div",{className:"gh-state-msg",children:i("terminal:fileExplorer.gitHistory.noCommits")}):e.jsxs("div",{className:"gh-commit-scroll",ref:r,onScroll:ne,children:[e.jsx("div",{style:{height:`${V.getTotalSize()}px`,width:"100%",position:"relative"},children:Z.map(P=>e.jsx("div",{"data-index":P.index,ref:V.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${P.start}px)`},children:e.jsx(vr,{commit:b[P.index],isSelected:(w==null?void 0:w.hash)===b[P.index].hash,onSelect:T})},P.key))}),v&&e.jsx("div",{className:"gh-loading-more",children:i("common:status.loading")})]})]}),w&&e.jsxs("div",{className:"gh-files-section",children:[e.jsxs("div",{className:"gh-files-header",children:[e.jsxs("span",{className:"gh-files-title",children:[A.length," ",A.length===1?"file":"files"]}),e.jsx("span",{className:"gh-files-commit-info",children:w.shortHash})]}),e.jsx(wr,{files:A,loading:K,selectedFilePath:h,onSelectFile:re})]})]})]})});async function Nr({path:s,cwd:n,limit:l}){const c=new URLSearchParams({path:s,cwd:n});Number.isFinite(l)&&c.set("limit",String(l));const i=await W(B(`/api/files/git-file-history?${c.toString()}`));if(!i.ok){const h=await i.json().catch(()=>({}));throw new Error(h.error||`Failed to load file git history: ${i.statusText}`)}const r=await i.json();return{commits:Array.isArray(r.commits)?r.commits:[]}}async function kr({path:s,cwd:n,sha:l}){const c=new URLSearchParams({path:s,cwd:n,sha:l}),i=await W(B(`/api/files/git-file-commit-diff?${c.toString()}`));if(!i.ok){const h=await i.json().catch(()=>({}));throw new Error(h.error||`Failed to load commit diff: ${i.statusText}`)}const r=await i.json();return r.binary===!0?{binary:!0,filename:r.filename??"",changeType:r.changeType??"modified"}:{binary:!1,filename:r.filename??"",language:r.language??"plaintext",changeType:r.changeType??"modified",originalContent:typeof r.originalContent=="string"?r.originalContent:"",modifiedContent:typeof r.modifiedContent=="string"?r.modifiedContent:""}}const Er=100;function Sr(s){if(!s)return"";const n=Date.parse(s);if(Number.isNaN(n))return s;const l=Date.now()-n,c=Math.round(l/1e3);if(c<60)return`${c}s ago`;const i=Math.round(c/60);if(i<60)return`${i}m ago`;const r=Math.round(i/60);if(r<24)return`${r}h ago`;const h=Math.round(r/24);if(h<30)return`${h}d ago`;const o=Math.round(h/30);return o<12?`${o}mo ago`:`${Math.round(o/12)}y ago`}function Tr(s){if(!s)return"";const n=s.lastIndexOf("/");return n>=0?s.slice(n+1):s}function Mr({isOpen:s,onClose:n,filePath:l,cwd:c}){const{t:i}=oe(["terminal","common"]),[r,h]=t.useState([]),[o,u]=t.useState(!1),[p,b]=t.useState(null),[f,v]=t.useState(null),[N,R]=t.useState(null),[y,k]=t.useState(!1),[g,j]=t.useState(null);t.useEffect(()=>{if(!s)return;let K=!1;return h([]),v(null),R(null),j(null),b(null),u(!0),(async()=>{try{const C=await Nr({path:l,cwd:c,limit:Er});if(K)return;h(C.commits),C.commits.length>0&&v(C.commits[0].sha)}catch(C){if(K)return;b(C instanceof Error?C.message:i("terminal:fileGitHistory.error"))}finally{K||u(!1)}})(),()=>{K=!0}},[s,l,c,i]),t.useEffect(()=>{if(!s||!f){R(null);return}let K=!1;return k(!0),j(null),R(null),(async()=>{try{const C=await kr({path:l,cwd:c,sha:f});if(K)return;R(C)}catch(C){if(K)return;j(C instanceof Error?C.message:i("terminal:fileGitHistory.error"))}finally{K||k(!1)}})(),()=>{K=!0}},[s,f,l,c,i]);const w=t.useCallback(K=>{K.key==="Escape"&&(K.preventDefault(),n())},[n]),T=t.useMemo(()=>Tr(l),[l]),A=()=>y?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:i("terminal:fileGitHistory.loading")})]}):g?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:20}),e.jsx("p",{children:g})]}):N?N.binary?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"file",size:20}),e.jsx("p",{children:i("terminal:fileGitHistory.binaryFile")})]}):e.jsx(ns,{originalContent:N.originalContent,modifiedContent:N.modifiedContent,filename:N.filename||T,filePath:l,language:N.language}):e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:i("terminal:fileGitHistory.selectCommit")})});return s?e.jsx(ea,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"git-file-history-modal",onClick:K=>K.stopPropagation(),onKeyDown:w,tabIndex:-1,children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{className:"git-file-history-title",children:[e.jsx("h2",{children:i("terminal:fileGitHistory.title")}),e.jsx("span",{className:"git-file-history-filepath",title:l,children:T})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(M,{name:"close",size:16})})]}),e.jsxs("div",{className:"git-file-history-body",children:[e.jsx("aside",{className:"git-file-history-commit-list","aria-label":i("terminal:fileGitHistory.title"),children:o?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:i("terminal:fileGitHistory.loading")})]}):p?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:18}),e.jsx("p",{children:p})]}):r.length===0?e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:i("terminal:fileGitHistory.empty")})}):e.jsx("ul",{className:"git-file-history-commits",role:"listbox",children:r.map(K=>{const C=K.sha===f;return e.jsxs("li",{className:`git-file-history-commit ${C?"selected":""}`,role:"option","aria-selected":C,onClick:()=>v(K.sha),children:[e.jsxs("div",{className:"git-file-history-commit-row",children:[e.jsx("span",{className:"git-file-history-sha",children:K.shortSha}),e.jsx("span",{className:"git-file-history-date",title:K.date,children:Sr(K.date)})]}),e.jsx("div",{className:"git-file-history-subject",title:K.subject,children:K.subject}),e.jsx("div",{className:"git-file-history-author",title:K.email,children:K.author})]},K.sha)})})}),e.jsx("section",{className:"git-file-history-diff","aria-live":"polite",children:A()})]})]})})}):null}function Pr({isOpen:s,areaId:n,onClose:l,onChangeArea:c,folderPath:i}){const{t:r}=oe(["terminal","common"]),h=ta(),o=sa(),u=na(),p=!!i&&!n,b=!p&&n?h.get(n):null,f=p?[i]:(b==null?void 0:b.directories)||[],v=Array.from(h.values()),[N,R]=t.useState(0),[y,k]=t.useState(null),[g,j]=t.useState(!1),[w,T]=t.useState(""),A=t.useRef(null),K=f[N]||f[0]||null,C=K?K.replace(/\\/g,"/"):null,O=C?Pt(C):"";t.useEffect(()=>{R(0)},[i,p]),t.useEffect(()=>{!p&&i&&k(i)},[p,i]),t.useEffect(()=>{if(s)try{p&&i?localStorage.setItem("file-explorer-last-opened",JSON.stringify({type:"folder",path:i})):n&&localStorage.setItem("file-explorer-last-opened",JSON.stringify({type:"area",areaId:n}))}catch{}},[s,p,i,n]);const ae=t.useMemo(()=>{const a=[];for(const d of v)for(const x of d.directories)a.push({path:x,areaId:d.id,areaName:d.name,areaColor:d.color});return a},[v]),Y=t.useMemo(()=>{const a=w.trim().toLowerCase();return a?ae.filter(d=>{const x=(d.path.split("/").pop()||d.path).toLowerCase();return d.path.toLowerCase().includes(a)||x.includes(a)}):ae},[ae,w]);t.useEffect(()=>{var a;g?(a=A.current)==null||a.focus():T("")},[g]);const{tree:D,loading:F,expandedPaths:V,loadTree:ne,reloadDirectory:re,renamePathInTree:je,togglePath:U,expandToPath:Z,restoreExpandedPaths:P,setExpandedPaths:G}=aa(C),{gitStatus:I,loading:ie,loadGitStatus:ee}=ua(C),{mergeBranch:ve,mergeAbort:m,mergeContinue:X}=rs(),le=Ra(),{showToast:H}=tn(),{file:$,loading:S,error:te,loadFile:Q,clearFile:de,setFile:pe}=ya(),{treePanelWidth:se,handleResizeStart:we,isResizing:Ge}=Na(),{mobileTreeHeight:ze,handleResizeMouseDown:Gt,handleResizeTouchStart:He}=Ta(),{loadProjectState:yt,saveProjectState:Ue,loadRecentProjects:ot,pushRecentProject:bt}=Ca(),[jt,vt]=t.useState(()=>ot()),wt=t.useMemo(()=>{const a=new Map(ae.map(x=>[x.path.replace(/\\/g,"/"),x])),d=[];for(const x of jt){const z=a.get(x);if(z&&d.push(z),d.length>=5)break}return d},[jt,ae]),[ye,ue]=t.useState(null),[xe,ke]=t.useState("files"),[We,Re]=t.useState(""),[E,L]=t.useState([]),[_,be]=t.useState([]),[Me,qe]=t.useState(!1),[ct,me]=t.useState(null),[un,Fe]=t.useState(null),[os,Ct]=t.useState(!1),[Pe,Ut]=t.useState(!1),[dt,hn]=t.useState(!1),[mn,cs]=t.useState(new Set),[ds]=t.useState(!1),[Bt,fn]=t.useState(!1),[_t,pn]=t.useState(250),ut=t.useRef(null),[Ae,Nt]=t.useState(null),[gn,us]=t.useState(!1),[Je,hs]=t.useState(null),[Ye,ms]=t.useState(null),[Xe,xn]=t.useState(null),[Kt,Vt]=t.useState({open:!1,path:"",cwd:""}),[fe,Be]=t.useState({isOpen:!1,node:null,value:"",submitting:!1}),[Ce,Qe]=t.useState({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1}),[Se,fs]=t.useState(null),yn=ra(),kt=ia(yn),bn=la(),[Ie,Oe]=t.useState([]),[he,De]=t.useState(null),[,Wt]=t.useState(void 0),[ps,Ze]=t.useState(null),[ht,mt]=t.useState(null),[jn,et]=t.useState(null),[vn,gs]=t.useState(!1),[Et,qt]=t.useState(null),[xs,Jt]=t.useState(!1),[St,Tt]=t.useState(null),ys=t.useRef(null),Yt=t.useRef(null),bs=t.useRef(null),ft=t.useRef(null),js=t.useRef(C);t.useEffect(()=>{js.current=C},[C]);const Mt=t.useRef(!1);t.useEffect(()=>{Mt.current=!1},[n,i]),t.useEffect(()=>{if(!s||Mt.current)return;if(p){Mt.current=!0,R(0);return}if(f.length===0)return;if(Mt.current=!0,y){const x=f.indexOf(y);R(x>=0?x:0),k(null);return}const a=f.map(x=>x.replace(/\\/g,"/")),d=ot().find(x=>a.includes(x));R(d?a.indexOf(d):0)},[s,p,f,y,ot]),t.useEffect(()=>{if(!s||!C)return;const a=setTimeout(()=>vt(bt(C)),250);return()=>clearTimeout(a)},[s,C,bt]),t.useEffect(()=>{if(!s||Pe||!C)return;const a=C;(async()=>{const x=await yt(a);js.current===a&&(x?(Oe(x.tabs),De(x.activeTabPath),ke(x.viewMode),G(x.expandedPaths),ft.current=x.expandedPaths,Ct(!0),x.activeTabPath?(ue(x.activeTabPath),Q(x.activeTabPath)):(ue(null),de())):(Oe([]),De(null),ue(null),de(),ft.current=null),Ut(!0))})()},[s,Pe,C,yt,G,Q,de]),t.useEffect(()=>{if(ft.current&&!F&&D.length>0){const a=ft.current;ft.current=null,P(a)}},[F,D,Pe,P]);const vs=t.useRef(null);t.useEffect(()=>{vs.current=Pe&&C?{key:C,state:{tabs:Ie,activeTabPath:he,viewMode:xe,expandedPaths:V}}:null},[Pe,C,Ie,he,xe,V]);const pt=t.useCallback(()=>{const a=vs.current;a&&Ue(a.key,a.state)},[Ue]);t.useEffect(()=>{if(!s||!Pe||!C)return;const a=C,d=setTimeout(()=>{Ue(a,{tabs:Ie,activeTabPath:he,viewMode:xe,expandedPaths:V})},500);return()=>clearTimeout(d)},[s,Pe,C,Ie,he,xe,V,Ue]),t.useEffect(()=>()=>pt(),[pt]);const ws=t.useRef(s);t.useEffect(()=>{ws.current&&!s&&pt(),ws.current=s},[s,pt]),t.useEffect(()=>{Ut(!1)},[C]),t.useEffect(()=>{if(!fe.isOpen)return;const a=window.setTimeout(()=>{var d,x;(d=Yt.current)==null||d.focus(),(x=Yt.current)==null||x.select()},0);return()=>window.clearTimeout(a)},[fe.isOpen]),t.useEffect(()=>{if(!Ce.isOpen)return;const a=window.setTimeout(()=>{var d;(d=bs.current)==null||d.focus()},0);return()=>window.clearTimeout(a)},[Ce.isOpen]);const Le=t.useMemo(()=>{const a=We.trim(),d=a.match(/^(.+):(\d+)$/);return d?{query:d[1],lineNumber:parseInt(d[2],10)}:{query:a,lineNumber:void 0}},[We]);t.useEffect(()=>{if(!Le.query||!C){L([]),be([]),qe(!1);return}qe(!0);const a=new AbortController,{signal:d}=a,x=setTimeout(async()=>{try{const z=Le.query,J=W(B(`/api/files/search?path=${encodeURIComponent(C)}&q=${encodeURIComponent(z)}&limit=200`),{signal:d}).then(ge=>ge.json()).catch(()=>({results:[]})),q=z.length>=2&&!Le.lineNumber?W(B(`/api/files/search-content?path=${encodeURIComponent(C)}&q=${encodeURIComponent(z)}&limit=200`),{signal:d}).then(ge=>ge.json()).catch(()=>({results:[]})):Promise.resolve({results:[]}),[Ne,ce]=await Promise.all([J,q]);if(d.aborted)return;L(Ne.results||[]),be(ce.results||[])}catch(z){if(d.aborted)return;console.error("[FileExplorer] Search failed:",z),L([]),be([])}d.aborted||qe(!1)},300);return()=>{clearTimeout(x),a.abort()}},[Le.query,Le.lineNumber,C]),t.useEffect(()=>{s&&C&&(de(),ue(null),me(null),Fe(null),Ct(!1),ne(),ee())},[s,C,ne,ee,de]),t.useEffect(()=>{if(o&&s){const a=o;if(u){const d=Pt(a),x=a.substring(a.lastIndexOf(".")).toLowerCase();Dt(a,d,x),Rt(a)}else Q(a),ue(a);_e.clearFileViewerPath()}},[o,u,s,Q]),t.useEffect(()=>{Pe&&!os&&I&&Ct(!0)},[I,os,Pe,xe]),t.useEffect(()=>{if(n&&(de(),ue(null),Re(""),be([]),L([]),me(null),Fe(null),Ct(!1),Ut(!1),y)){const a=h.get(n);a!=null&&a.directories.includes(y)||k(null)}},[n,y,h,de]),t.useEffect(()=>{const a=x=>{var J;if(!s)return;if(x.altKey&&x.key==="e"){x.preventDefault(),x.stopPropagation(),l();return}if(x.key==="Escape"){if(fe.isOpen){x.preventDefault(),x.stopPropagation(),fe.submitting||Be({isOpen:!1,node:null,value:"",submitting:!1});return}if(ds)return;if(g){x.preventDefault(),x.stopPropagation(),j(!1);return}x.preventDefault(),x.stopPropagation(),l();return}(x.metaKey||x.ctrlKey)&&x.key==="p"&&(x.preventDefault(),(J=ys.current)==null||J.focus());const z=_e.getShortcuts().find(q=>q.id==="file-explorer-close-tab");if(da(x,z)){if(x.repeat)return;x.preventDefault(),x.stopPropagation(),he&&Es(he)}},d=x=>{const z=x.target;g&&!z.closest(".file-explorer-folder-selector")&&!z.closest(".file-explorer-folder-dropdown")&&j(!1)};return document.addEventListener("keydown",a,!0),document.addEventListener("click",d),()=>{document.removeEventListener("keydown",a,!0),document.removeEventListener("click",d)}},[s,l,g,he,ds,fe]);const Cs=t.useMemo(()=>{const a=new Map;if(I!=null&&I.files)for(const d of I.files)a.set(d.path,d.status);return a},[I==null?void 0:I.files]),Xt=t.useMemo(()=>{const a=new Map;if(!(I!=null&&I.files))return a;const d={conflict:0,modified:1,added:2,deleted:3,untracked:4,renamed:5};for(const x of I.files){let z=x.path.replace(/\\/g,"/");for(;;){const J=z.lastIndexOf("/");if(J<=0)break;z=z.substring(0,J);const q=a.get(z);q?d[x.status]<d[q]&&a.set(z,x.status):a.set(z,x.status)}}return a},[I==null?void 0:I.files]),Ns=t.useMemo(()=>{const a=d=>({...d,gitStatus:d.isDirectory?Xt.get(d.path):Cs.get(d.path),hasGitChanges:d.isDirectory&&Xt.has(d.path)||void 0,children:d.children?d.children.map(a):void 0});return D.map(a)},[D,Cs,Xt]),Dt=(a,d,x,z)=>{if(!Ie.find(q=>q.path===a)){const q={path:a,filename:d,extension:x};Oe(Ne=>[...Ne,q])}De(a),ue(a),Wt(z),Q(a)},ks=async a=>{if(a.isDirectory){ke("files"),Re(""),await Z(a.path),ue(a.path),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let d=a.path,x=document.querySelector(`[data-path="${d}"]`);for(;!x&&d.includes("/");)d=d.substring(0,d.lastIndexOf("/")),x=document.querySelector(`[data-path="${d}"]`);x instanceof HTMLElement&&x.scrollIntoView({behavior:"smooth",block:"center"})})});return}Fe(null),me(null),Dt(a.path,a.name,a.extension,Le.lineNumber)},wn=(a,d)=>{Fe(null),me(null);const x=Pt(a),z=a.substring(a.lastIndexOf(".")).toLowerCase();Dt(a,x,z,d)},Cn=async(a,d)=>{Fe(d),me(null);const x=Pt(a),z=a.substring(a.lastIndexOf(".")).toLowerCase();if(Dt(a,x,z),d==="modified"){const{content:J}=await ha(a);J!==null&&me(J)}},Nn=a=>{De(a),ue(a),Fe(null),me(null),Wt(void 0);const d=Ie.find(x=>x.path===a);d!=null&&d.data||Q(a)},Es=a=>{Oe(d=>{var J;const x=d.filter(q=>q.path!==a),z=d.findIndex(q=>q.path===a);if(z!==-1&&((J=d[z])==null?void 0:J.path)===a&&(he===a||d.find(q=>q.path===he)),x.length>0){if(!x.some(Ne=>Ne.path===he)){const Ne=d.findIndex(Ee=>Ee.path===a),ce=Math.max(0,Math.min(Ne,x.length-1)),ge=x[ce];ge&&(De(ge.path),ue(ge.path),Q(ge.path))}}else De(null),ue(null),de();return x})},kn=t.useCallback(()=>{Oe([]),De(null),ue(null),de()},[de]),Qt=a=>{if(j(!1),a.path.replace(/\\/g,"/")!==C)if(pt(),a.areaId!==n)k(a.path),c&&c(a.areaId);else{const d=f.indexOf(a.path);R(d>=0?d:0)}},$e=t.useCallback(a=>{const d=a.lastIndexOf("/");return d<=0?"/":a.slice(0,d)},[]),tt=t.useCallback((a,d,x)=>a===d?x:a.startsWith(`${d}/`)?`${x}${a.slice(d.length)}`:a,[]),En=t.useCallback((a,d)=>{ue(d.path),hs({isOpen:!0,position:{x:a.clientX,y:a.clientY},node:d})},[]),Sn=t.useCallback(a=>{a.defaultPrevented||C&&(a.preventDefault(),ms({isOpen:!0,position:{x:a.clientX,y:a.clientY},parentDir:C}))},[C]),Ss=t.useCallback(a=>{Be({isOpen:!0,node:a,value:a.name,submitting:!1})},[]),st=t.useCallback(()=>{Be({isOpen:!1,node:null,value:"",submitting:!1})},[]),nt=t.useCallback((a,d)=>{a&&Qe({isOpen:!0,parentDir:a,isDirectory:d,value:"",submitting:!1})},[]),at=t.useCallback(()=>{Qe({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1})},[]),Ts=t.useCallback(a=>{fs({node:a})},[]),Tn=t.useCallback(async()=>{const a=Se==null?void 0:Se.node;if(a)try{const d=await W(B("/api/files/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,recursive:a.isDirectory})}),x=await d.json().catch(()=>({}));if(!d.ok){H("error","Delete Failed",x.error||"Unable to delete item");return}Oe(J=>J.filter(q=>q.path!==a.path&&!q.path.startsWith(`${a.path}/`))),(he===a.path||he!=null&&he.startsWith(`${a.path}/`))&&(De(null),de()),(ye===a.path||ye!=null&&ye.startsWith(`${a.path}/`))&&ue(null);const z=$e(a.path);await re(z),await ee(),H("success",a.isDirectory?"Folder Deleted":"File Deleted",a.name)}catch(d){console.error("[FileExplorer] Delete failed:",d),H("error","Delete Failed","Unable to delete item")}},[Se,he,ye,$e,re,ee,H,de]),Ms=t.useCallback(async()=>{const{parentDir:a,isDirectory:d,value:x}=Ce,z=x.trim();if(!a||!z){at();return}if(z.includes("/")||z.includes("\\")){H("error","Invalid Name","Name must not contain path separators");return}Qe(J=>({...J,submitting:!0}));try{const J=await W(B("/api/files/create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({parentDir:a,name:z,isDirectory:d})}),q=await J.json();if(!J.ok){H("error","Create Failed",q.error||"Unable to create item"),Qe(ge=>({...ge,submitting:!1}));return}const Ne=q.path,ce=new Set(V);ce.add(a),await re(a),G(ce),await ee(),ue(Ne),H("success",d?"Folder Created":"File Created",z),at()}catch(J){console.error("[FileExplorer] Create failed:",J),H("error","Create Failed","Unable to create item"),Qe(q=>({...q,submitting:!1}))}},[Ce,V,re,G,ee,H,at]),Ds=t.useCallback(async()=>{const a=fe.node;if(!a)return;const d=fe.value.trim();if(!d||d===a.name){st();return}Be(x=>({...x,submitting:!0}));try{const x=await W(B("/api/files/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,newName:d})}),z=await x.json();if(!x.ok){H("error","Rename Failed",z.error||"Unable to rename item"),Be(Ee=>({...Ee,submitting:!1}));return}const J=z.newPath,q=a.path,Ne=new Set(Array.from(V).map(Ee=>tt(Ee,q,J))),ce=$e(q),ge=$e(J);if(Oe(Ee=>Ee.map(Te=>{if(!Te.path.startsWith(q))return Te;const rt=tt(Te.path,q,J),Ft=rt.split("/").pop()||rt,Hs=Ft.includes(".")?`.${Ft.split(".").pop()}`:"";return{...Te,path:rt,filename:Ft,extension:Hs.toLowerCase(),data:Te.data?{...Te.data,path:rt,filename:Ft,extension:Hs.toLowerCase()}:Te.data}})),he&&De(tt(he,q,J)),ye&&ue(tt(ye,q,J)),$!=null&&$.path){const Ee=tt($.path,q,J);if(Ee!==$.path){const Te=Ee.split("/").pop()||Ee,rt=Te.includes(".")?`.${Te.split(".").pop()}`:"";pe({...$,path:Ee,filename:Te,extension:rt.toLowerCase()})}}je(q,J),G(Ne),await re(ce),ge!==ce&&await re(ge),await ee(),H("success","Renamed",`${a.name} renamed`),st()}catch(x){console.error("[FileExplorer] Rename failed:",x),H("error","Rename Failed","Unable to rename item"),Be(z=>({...z,submitting:!1}))}},[fe,st,he,ye,$,V,tt,$e,je,G,re,ee,H,pe]),Rs=t.useCallback(a=>{xn({sourcePath:a.path,isDirectory:a.isDirectory,name:a.name}),H("info","Copied",`${a.name} ready to paste`)},[H]),Fs=t.useCallback(async a=>{if(!Xe)return;const d=a.isDirectory?a.path:$e(a.path),x=new Set(V);x.add(d);try{const z=await W(B("/api/files/paste"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourcePath:Xe.sourcePath,targetDir:d})}),J=await z.json();if(!z.ok){H("error","Paste Failed",J.error||"Unable to paste item");return}await re(d),G(x),await ee(),J.destinationPath&&ue(J.destinationPath),H("success","Pasted",`${Xe.name} pasted`)}catch(z){console.error("[FileExplorer] Paste failed:",z),H("error","Paste Failed","Unable to paste item")}},[Xe,$e,V,re,G,ee,H]),Ps=t.useCallback(async a=>{try{await navigator.clipboard.writeText(a.path),H("success","Copied","Full path copied")}catch(d){console.error("[FileExplorer] Copy path failed:",d),H("error","Copy Failed","Could not copy path")}},[H]),Is=t.useCallback(a=>{a.isDirectory||!C||Vt({open:!0,path:a.path,cwd:C})},[C]),Mn=t.useCallback(a=>{!C||!a||Vt({open:!0,path:a,cwd:C})},[C]),Ls=t.useCallback(async a=>{try{await _e.runTests(a.path)}catch(d){H("error","Run Tests Failed",d instanceof Error?d.message:"Unable to start tests")}},[H]),Dn=t.useMemo(()=>{if(!Je)return[];const a=Je.node,d=a.isDirectory?a.path:$e(a.path),x=[{id:"create-file",label:a.isDirectory?"New File...":"New File Here...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>nt(d,!1)},{id:"create-folder",label:a.isDirectory?"New Folder...":"New Folder Here...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>nt(d,!0)},{id:"divider-create",label:"",divider:!0,onClick:()=>{}},{id:"rename",label:a.isDirectory?"Rename Folder":"Rename File",icon:e.jsx(M,{name:"edit",size:14}),onClick:()=>Ss(a)},{id:"copy",label:a.isDirectory?"Copy Folder":"Copy File",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>Rs(a)},{id:"paste",label:a.isDirectory?"Paste Into Folder":"Paste Here",icon:e.jsx(M,{name:"clipboard",size:14}),disabled:!Xe,onClick:()=>{Fs(a)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"copy-full-path",label:"Copy Full Path",icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{Ps(a)}}];return a.runnerType&&x.push({id:"divider-run-tests",label:"",divider:!0,onClick:()=>{}},{id:"run-tests",label:a.isDirectory?"Run Tests":"Run This Test",icon:e.jsx(M,{name:"flask",size:14}),onClick:()=>{Ls(a)}}),a.isDirectory||x.push({id:"divider-git-history",label:"",divider:!0,onClick:()=>{}},{id:"git-history",label:r("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),onClick:()=>Is(a)}),x.push({id:"divider-delete",label:"",divider:!0,onClick:()=>{}},{id:"delete",label:a.isDirectory?"Delete Folder":"Delete File",icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>Ts(a)}),x},[Je,Xe,$e,nt,Ss,Rs,Fs,Ps,Is,Ts,Ls,r]),Rn=t.useMemo(()=>{if(!Ye)return[];const a=Ye.parentDir;return[{id:"create-file-root",label:"New File...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>nt(a,!1)},{id:"create-folder-root",label:"New Folder...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>nt(a,!0)}]},[Ye,nt]),Rt=t.useCallback(async a=>{ke("files"),Re(""),await Z(a),ue(a),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let d=a,x=document.querySelector(`[data-path="${d}"]`);for(;!x&&d.includes("/");)d=d.substring(0,d.lastIndexOf("/")),x=document.querySelector(`[data-path="${d}"]`);x instanceof HTMLElement&&x.scrollIntoView({behavior:"smooth",block:"center"})})})},[Z]),Fn=t.useCallback(async a=>{if(!(!C||a.length===0)){cs(d=>{const x=new Set(d);for(const z of a)x.add(z);return x});try{const d=await W(B("/api/files/git-add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:a,directory:C})});if(d.ok)await ee();else{const x=await d.json();console.error("[FileExplorer] Git add failed:",x.error)}}catch(d){console.error("[FileExplorer] Git add failed:",d)}finally{cs(d=>{const x=new Set(d);for(const z of a)x.delete(z);return x})}}},[C,ee]),Pn=t.useCallback(async a=>{if(!C)return;Ze(a);const d=await ve(C,a);if(await ee(),d.success)Ze(null),H("success","Merge Complete",`Merged '${a}' successfully`),ne();else if(d.conflicts&&d.conflicts.length>0){const x=d.conflicts.length;H("warning","Merge Conflicts",`${x} conflict${x>1?"s":""} found — resolve to continue`),ke("git")}else Ze(null),H("error","Merge Failed",d.error||"Merge failed")},[C,ve,ee,ne,H]),In=t.useCallback(async a=>{Ze("remote"),await ee();const d=a.length;H("warning","Pull Conflicts",`${d} conflict${d>1?"s":""} found — resolve to continue`),ke("git")},[ee,H]),Ln=t.useCallback(async a=>{if(C){mt(a),gs(!0),et(null);try{const d=await W(B(`/api/files/git-conflict-file?path=${encodeURIComponent(C)}&file=${encodeURIComponent(a)}`)),x=await d.json();d.ok?et(x):console.error("[FileExplorer] Failed to load conflict file:",x.error)}catch(d){console.error("[FileExplorer] Failed to load conflict file:",d)}finally{gs(!1)}}},[C]),$n=t.useCallback(async a=>{if(!(!C||!ht))try{const d=await W(B("/api/files/git-resolve-conflict"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:C,file:ht,content:a})}),x=await d.json();d.ok&&x.success?(mt(null),et(null),await ee()):console.error("[FileExplorer] Failed to resolve conflict:",x.error)}catch(d){console.error("[FileExplorer] Failed to resolve conflict:",d)}},[C,ht,ee]),zn=t.useCallback(async()=>{if(!C)return;const a=await X(C);a.success?(Ze(null),mt(null),et(null),H("success","Merge Complete","Merge completed successfully"),await ee(),ne()):H("error","Merge Failed",a.error||"Merge continue failed")},[C,X,ee,ne,H]),Hn=t.useCallback(async()=>{if(!C)return;const a=await m(C);a.success?(Ze(null),mt(null),et(null),H("info","Merge Aborted","Merge has been aborted"),await ee(),ne()):H("error","Abort Failed",a.error||"Failed to abort merge")},[C,m,ee,ne,H]),An=t.useCallback(async a=>{if(C){Tt(a),Jt(!0),qt(null),ke("compare");try{const d=await W(B(`/api/files/git-branch-compare?directory=${encodeURIComponent(C)}&branch=${encodeURIComponent(a)}`)),x=await d.json();d.ok?qt(x):(H("error","Compare Failed",x.error||"Failed to compare branches"),ke("files"),Tt(null))}catch(d){console.error("[FileExplorer] Branch compare failed:",d),H("error","Compare Failed","Network error during comparison"),ke("files"),Tt(null)}finally{Jt(!1)}}},[C,H]),On=t.useCallback(async(a,d)=>{if(!C||!St)return;const x=a.split("/").pop()||a,z=a.substring(a.lastIndexOf(".")).toLowerCase();Ie.find(ce=>ce.path===a)||Oe(ce=>[...ce,{path:a,filename:x,extension:z}]),De(a),ue(a),Wt(void 0);const q=async ce=>{try{const ge=await W(B(`/api/files/git-show?path=${encodeURIComponent(a)}&ref=${encodeURIComponent(ce)}`)),Ee=await ge.json();return ge.ok?Ee.content??"":""}catch{return""}},Ne=ce=>({path:a,filename:x,extension:z,content:ce,fileType:"text",size:ce.length,modified:""});if(d==="modified"||d==="renamed"){const[ce,ge]=await Promise.all([q(St),q("HEAD")]);me(ce),pe(Ne(ge)),Fe("modified")}else if(d==="deleted"){const ce=await q(St);me(ce),pe(Ne("")),Fe("modified")}else if(d==="added"){const ce=await q("HEAD");me(""),pe(Ne(ce)),Fe("modified")}},[C,St,Ie]),$s=t.useCallback(()=>{ke("files"),qt(null),Tt(null),Jt(!1)},[]),Gn=t.useCallback(async(a,d)=>{if(C){us(!0);try{const x=new URLSearchParams({path:C,hash:d,file:a}),z=await W(B(`/api/files/git-commit-file-diff?${x}`)),J=await z.json();z.ok?Nt(J):Nt(null)}catch(x){console.error("[FileExplorer] commit diff fetch error:",x),Nt(null)}finally{us(!1)}}},[C]),Un=t.useCallback(()=>{Nt(null)},[]),Bn=t.useCallback(a=>{a.preventDefault(),ut.current={startY:a.clientY,startHeight:_t};const d=z=>{if(!ut.current)return;const J=ut.current.startY-z.clientY,q=Math.max(120,Math.min(600,ut.current.startHeight+J));pn(q)},x=()=>{ut.current=null,document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",x)};document.addEventListener("mousemove",d),document.addEventListener("mouseup",x)},[_t]);if(!s||!b&&!p)return null;const zs=(I==null?void 0:I.files.length)||0;return e.jsxs("div",{className:"file-explorer-panel ide-style",children:[e.jsxs("div",{className:"file-explorer-panel-header",children:[e.jsxs("div",{className:"file-explorer-panel-header-row",children:[e.jsxs("div",{className:"file-explorer-panel-title",children:[C&&e.jsxs("div",{className:"file-explorer-folder-selector",onClick:()=>ae.length>0&&j(!g),style:{cursor:ae.length>0?"pointer":"default"},title:C,children:[e.jsx("span",{className:"file-explorer-panel-dot",style:{background:(b==null?void 0:b.color)||"#ffd700"}}),e.jsx("span",{className:"file-explorer-folder-name",children:O}),e.jsx("span",{className:"file-explorer-folder-path-hint",children:C}),ae.length>1&&e.jsx("span",{className:"file-explorer-folder-dropdown-icon",children:e.jsx(M,{name:"caret-down",size:10})})]}),(I==null?void 0:I.isGitRepo)&&C&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"file-explorer-path-separator",children:"/"}),e.jsx(hr,{currentFolder:C,gitStatus:I,onBranchChanged:()=>{ee(),ne()},onMerge:Pn,onCompare:An,onPullConflicts:In})]}),$&&e.jsxs("span",{className:"file-explorer-current-file",children:["/ ",$.filename]}),g&&ae.length>0&&e.jsxs("div",{className:"file-explorer-folder-dropdown",onWheel:a=>{a.preventDefault(),a.currentTarget.scrollTop+=a.deltaY*.35},children:[e.jsx("div",{className:"file-explorer-folder-dropdown-search",onClick:a=>a.stopPropagation(),children:e.jsx("input",{ref:A,type:"text",className:"file-explorer-folder-dropdown-search-input",placeholder:"Filter folders…",value:w,onChange:a=>T(a.target.value),onKeyDown:a=>{a.key==="Enter"&&Y.length>0&&(a.preventDefault(),Qt(Y[0]))},spellCheck:!1,autoComplete:"off","aria-label":"Filter folders"})}),Y.length===0?e.jsx("div",{className:"file-explorer-folder-dropdown-empty",children:"No matching folders"}):Y.map(a=>e.jsxs("div",{className:`file-explorer-folder-option ${a.path===C?"active":""}`,onClick:d=>{d.stopPropagation(),Qt(a)},children:[e.jsxs("span",{className:"file-explorer-folder-option-name",children:[e.jsx("span",{className:"file-explorer-folder-option-dot",style:{background:a.areaColor}}),a.path.split("/").pop()||a.path]}),(a.path.split("/").pop()||a.path)!==a.path&&e.jsx("span",{className:"file-explorer-folder-option-path",children:a.path}),e.jsx("span",{className:"file-explorer-folder-option-area",children:a.areaName})]},`${a.areaId}-${a.path}`))]})]}),(I==null?void 0:I.isGitRepo)&&e.jsx("button",{className:`file-explorer-history-toggle ${Bt?"active":""}`,onClick:()=>fn(!Bt),title:r("terminal:fileExplorer.gitHistory.title"),children:e.jsx(M,{name:"status-waiting-input",size:14})}),kt&&!bn&&e.jsxs("button",{className:`file-explorer-test-results-toggle status-${kt.status}`,onClick:()=>_e.openTestResults(),title:kt.status==="running"?"Tests running — open results":"Open last test results",children:[e.jsx(M,{name:"flask",size:14}),kt.status==="running"&&e.jsx("span",{className:"fe-test-run-dot"})]}),e.jsx("button",{className:"file-explorer-panel-close",onClick:l,children:"×"})]}),wt.length>1&&e.jsx("div",{className:"file-explorer-recent-projects",role:"group","aria-label":"Recent projects",children:wt.map(a=>{const d=a.path.split("/").pop()||a.path,x=a.path.replace(/\\/g,"/")===C;return e.jsxs("button",{type:"button",className:`file-explorer-recent-chip ${x?"active":""}`,onClick:()=>Qt(a),title:a.path,children:[e.jsx("span",{className:"file-explorer-recent-chip-dot",style:{background:a.areaColor}}),e.jsx("span",{className:"file-explorer-recent-chip-name",children:d})]},`${a.areaId}-${a.path}`)})})]}),e.jsxs("div",{className:"file-explorer-main",style:ze>0?{"--fe-mobile-tree-height":`${ze}px`}:void 0,children:[e.jsxs("div",{className:`file-explorer-tree-panel ${dt?"collapsed":""}`,style:{width:se},children:[e.jsxs("div",{className:"file-explorer-tabs",children:[e.jsx("button",{className:"file-explorer-tree-toggle",onClick:()=>hn(!dt),title:r(dt?"terminal:fileExplorer.expandTree":"terminal:fileExplorer.collapseTree"),children:e.jsx(M,{name:dt?"caret-down":"caret-up",size:12})}),e.jsxs("button",{className:`file-explorer-tab ${xe==="files"?"active":""}`,onClick:()=>ke("files"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"folder",size:14})}),r("terminal:spotlight.files")]}),e.jsxs("button",{className:`file-explorer-tab ${xe==="git"?"active":""}`,onClick:()=>ke("git"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"git-branch",size:14})}),r("terminal:fileExplorer.gitChanges"),zs>0&&e.jsx("span",{className:"tab-badge",children:zs})]}),(Et||xs)&&e.jsxs("button",{className:`file-explorer-tab ${xe==="compare"?"active":""}`,onClick:()=>ke("compare"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"arrows-horizontal",size:14})}),r("terminal:fileExplorer.diffView"),Et&&e.jsx("span",{className:"tab-badge",children:Et.files.length}),e.jsx("span",{className:"tab-close-btn",onClick:a=>{a.stopPropagation(),$s()},children:"×"})]})]}),xe==="files"&&e.jsxs("div",{className:"file-explorer-toolbar",children:[e.jsxs("div",{className:"file-explorer-search",children:[e.jsx("span",{className:"file-explorer-search-icon",children:e.jsx(M,{name:"search",size:14})}),e.jsx("input",{ref:ys,type:"text",className:"file-explorer-search-input",placeholder:r("terminal:fileExplorer.searchPlaceholder"),value:We,onChange:a=>Re(a.target.value)}),We&&e.jsx("button",{className:"file-explorer-search-clear",onClick:()=>Re(""),children:"×"})]}),e.jsxs("div",{className:"file-explorer-toolbar-buttons",children:[e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>G(new Set),title:r("terminal:fileExplorer.collapseAll"),children:"⊟"}),he&&e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>Rt(he),title:r("terminal:fileExplorer.revealInTree"),children:e.jsx(M,{name:"target",size:14})})]})]}),e.jsx("div",{className:"file-explorer-tree-content",onContextMenu:xe==="files"?Sn:void 0,children:xe==="compare"?e.jsx(dn,{compareResult:Et,loading:xs,onFileSelect:On,selectedPath:ye,onClose:$s}):xe==="files"?F?e.jsx("div",{className:"tree-loading",children:r("common:status.loading")}):Le.query?Me?e.jsx("div",{className:"tree-loading",children:r("terminal:fileExplorer.searching")}):e.jsx(ln,{filenameResults:E,contentResults:_,onSelectFile:ks,onSelectContent:wn,selectedPath:ye,query:Le.query,lineNumber:Le.lineNumber}):e.jsx("div",{className:"file-tree",children:Ns.length===0?e.jsx("div",{className:"tree-empty",children:r("terminal:fileExplorer.noDirectoriesLinked")}):Ns.map(a=>e.jsx(oa,{node:a,depth:0,selectedPath:ye,expandedPaths:V,onSelect:ks,onToggle:U,onContextMenu:En,searchQuery:""},a.path))}):e.jsx(on,{gitStatus:I,loading:ie,onFileSelect:Cn,selectedPath:ye,onRefresh:ee,onStageFiles:Fn,stagingPaths:mn,currentFolder:C,onCommitComplete:()=>{ee(),ne()},mergeInProgress:I==null?void 0:I.mergeInProgress,mergingBranch:ps,onMergeContinue:zn,onMergeAbort:Hn,onConflictOpen:Ln,onRevealInTree:Rt})})]}),e.jsx("div",{className:`file-explorer-resize-handle ${Ge?"active":""}`,onMouseDown:we}),!dt&&e.jsx("div",{className:"fe-mobile-resize-handle",onMouseDown:Gt,onTouchStart:He}),e.jsx("div",{className:"file-explorer-viewer-panel",children:ht?e.jsx(pr,{file:ht,versions:jn,loading:vn,onResolve:$n,onClose:()=>{mt(null),et(null)},currentBranch:(I==null?void 0:I.branch)||"HEAD",mergingBranch:ps||"incoming"}):Ae?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"commit-diff-header",children:[e.jsx("span",{className:"commit-diff-file",children:Ae.filePath}),e.jsx("span",{className:"commit-diff-hash",children:Ae.hash.slice(0,8)}),e.jsx("button",{className:"commit-diff-close",onClick:Un,children:"×"})]}),e.jsx(ns,{originalContent:Ae.beforeContent,modifiedContent:Ae.afterContent,filename:Ae.filename,filePath:Ae.filePath,language:Os[Ae.extension]||"plaintext"})]}):gn?e.jsx("div",{className:"commit-diff-loading",children:r("common:status.loading")}):e.jsxs(e.Fragment,{children:[e.jsx(cn,{tabs:Ie,activeTabPath:he,onSelectTab:Nn,onCloseTab:Es,onCloseAllTabs:kn,onShowGitHistory:Mn}),un==="modified"&&ct!==null&&$?e.jsx(ns,{originalContent:ct,modifiedContent:$.content,filename:$.filename,filePath:$.path,language:Os[$.extension]||"plaintext"}):e.jsx(an,{file:$,loading:S,error:te,onRevealInTree:Rt,onFileEdited:Q})]})})]}),Bt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"git-history-resize-handle",onMouseDown:Bn}),e.jsx("div",{className:"git-history-bottom-panel",style:{height:_t},children:e.jsx(Cr,{history:le,currentFolder:C,onFileSelect:Gn})})]}),fe.isOpen&&fe.node&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:st,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["Rename ",fe.node.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:fe.node.path,children:fe.node.path}),e.jsx("input",{ref:Yt,type:"text",className:"file-explorer-rename-input",value:fe.value,onChange:a=>Be(d=>({...d,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Ds()):a.key==="Escape"&&(a.preventDefault(),st())},disabled:fe.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:st,disabled:fe.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{Ds()},disabled:fe.submitting||!fe.value.trim(),children:fe.submitting?"Renaming...":"Rename"})]})]})}),Je&&e.jsx(it,{isOpen:Je.isOpen,position:Je.position,worldPosition:{x:0,z:0},actions:Dn,onClose:()=>hs(null)}),Ye&&e.jsx(it,{isOpen:Ye.isOpen,position:Ye.position,worldPosition:{x:0,z:0},actions:Rn,onClose:()=>ms(null)}),Ce.isOpen&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:at,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["New ",Ce.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:Ce.parentDir,children:Ce.parentDir}),e.jsx("input",{ref:bs,type:"text",className:"file-explorer-rename-input",placeholder:Ce.isDirectory?"folder name":"file name",value:Ce.value,onChange:a=>Qe(d=>({...d,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Ms()):a.key==="Escape"&&(a.preventDefault(),at())},disabled:Ce.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:at,disabled:Ce.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{Ms()},disabled:Ce.submitting||!Ce.value.trim(),children:Ce.submitting?"Creating...":"Create"})]})]})}),e.jsx(Mr,{isOpen:Kt.open,filePath:Kt.path,cwd:Kt.cwd,onClose:()=>Vt(a=>({...a,open:!1}))}),e.jsx(ca,{isOpen:!!Se,title:Se!=null&&Se.node.isDirectory?"Delete Folder":"Delete File",message:Se?e.jsxs(e.Fragment,{children:["Permanently delete ",e.jsx("strong",{children:Se.node.name}),"?"]}):"",note:Se!=null&&Se.node.isDirectory?"The folder and everything inside it will be removed from disk.":"The file will be removed from disk.",confirmLabel:"Delete",cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Tn()},onClose:()=>fs(null)})]})}export{Pr as FileExplorerPanel};
|