tide-commander 1.128.0 → 1.129.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{BossLogsModal-BqJ9gP1c.js → BossLogsModal-C_z1JzI-.js} +1 -1
- package/dist/assets/{BossSpawnModal-3Vg_NEN2.js → BossSpawnModal-B9AuxTmd.js} +1 -1
- package/dist/assets/{ControlsModal-Dm9600en.js → ControlsModal-BXxZjks_.js} +1 -1
- package/dist/assets/{DockerLogsModal-Dxo-MA7-.js → DockerLogsModal-BQjpp4lj.js} +1 -1
- package/dist/assets/{EmbeddedEditor-DKu0BvvX.js → EmbeddedEditor-C4gQ9cLk.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-5Q-s-D_9.js → GmailOAuthSetup-DHgp8RSO.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-D1N443qY.js → GoogleOAuthSetup-DZ_83P-Y.js} +1 -1
- package/dist/assets/{IframeModal-C1kZT8NW.js → IframeModal-DbjNOXKz.js} +1 -1
- package/dist/assets/{IntegrationsPanel-DAY5axRa.js → IntegrationsPanel-CnvFTjRQ.js} +2 -2
- package/dist/assets/{LogViewerModal-rs-7EcJP.js → LogViewerModal-BfgVn06N.js} +1 -1
- package/dist/assets/{MonitoringModal-BA1CQmZa.js → MonitoringModal-BTRMhtxv.js} +1 -1
- package/dist/assets/{PM2LogsModal-DLOEsocR.js → PM2LogsModal-CDwt_Jai.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-Cg-0avEu.js → RestoreArchivedAreaModal-CYOJ_uTt.js} +1 -1
- package/dist/assets/{Scene2DCanvas-CriswUae.js → Scene2DCanvas-BWBWM519.js} +1 -1
- package/dist/assets/SceneManager-CWp8ES8Z.js +104 -0
- package/dist/assets/{SkillsPanel-qHpg2VsU.js → SkillsPanel-C2sdGrMJ.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-snZDmcJq.js → SlackMultiInstanceSetup-NmcYdN-r.js} +1 -1
- package/dist/assets/{SpawnModal-DOc-7xaw.js → SpawnModal-DAVpw4Ua.js} +1 -1
- package/dist/assets/{StatisticsModal-NyLpg86O.js → StatisticsModal-CO2dq4Jq.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-wRwbtJ16.js → SubordinateAssignmentModal-D5CgdBMg.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-C8synm6n.js → TriggerManagerPanel-C24eB0yM.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-DDu7FJ8Y.js → WorkflowEditorPanel-C6LVEaLe.js} +1 -1
- package/dist/assets/{area-logos-D2sg3x7E.js → area-logos-Dm5yLK6S.js} +1 -1
- package/dist/assets/{index-IyzhrAAr.js → index-BR4FMR2x.js} +2 -2
- package/dist/assets/{index-vdKLkyTo.js → index-CCRzFjTC.js} +1 -1
- package/dist/assets/{index-DDGW5unE.js → index-CpnCiWTV.js} +1 -1
- package/dist/assets/index-D3Hb8Eia.js +19 -0
- package/dist/assets/{index-BC2-TUxs.js → index-DUd2IFRK.js} +1 -1
- package/dist/assets/{index-Oxj3G4GI.js → index-Dwg5JJJ1.js} +1 -1
- package/dist/assets/{index-DhqtMfQN.js → index-GaRJHdJw.js} +1 -1
- package/dist/assets/{index-xGscgLMH.js → index-t9CiHYbj.js} +1 -1
- package/dist/assets/{index-BmIKoMUh.js → index-zF-Yzhxm.js} +1 -1
- package/dist/assets/{main-CvN1lcU9.js → main-Bi4grTFP.js} +90 -90
- package/dist/assets/{web-ZH1b2mXs.js → web-B5-Tp8cv.js} +1 -1
- package/dist/assets/{web-DSyO1ltb.js → web-DxS4BBTf.js} +1 -1
- package/dist/assets/{web-B6U44omE.js → web-Ye7eWObV.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/src/packages/server/routes/files.js +34 -12
- package/dist/src/packages/server/routes/folders.js +4 -2
- package/package.json +1 -1
- package/dist/assets/SceneManager-Bu2gDgPK.js +0 -104
- package/dist/assets/index--BIqCr6s.js +0 -19
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-C4gQ9cLk.js","assets/main-Bi4grTFP.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-D086vUF0.css","assets/EmbeddedEditor-O_u2UVA4.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as t,h as W,i as V,G as Yt,Z as Bs,S as Ht,_ as _s,s as Be,u as re,j as e,I as M,bI as zt,f as Vs,bJ as Ks,bK as Gn,bL as Ws,bM as qs,bN as Un,bO as Bn,bP as Pt,bQ as _n,bR as Vn,bS as Kn,bT as es,bU as Wn,bV as Ys,bW as Lt,bX as $t,ak as ct,bY as xt,bZ as yt,b_ as Is,b$ as qn,bd as Yn,c0 as Zt,c1 as Ft,c2 as Jn,c3 as Xn,c4 as Qn,c5 as Zn,c6 as ea,c7 as Ps,C as ta,o as sa}from"./main-Bi4grTFP.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function na(s){const[n,l]=t.useState(null),[d,r]=t.useState(!1),i=t.useCallback(async()=>{if(s){r(!0);try{const m=await W(V(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await m.json();m.ok?l(o):l({isGitRepo:!1,files:[]})}catch(m){console.error("[FileExplorer] Failed to load git status:",m),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[s]);return{gitStatus:n,loading:d,loadGitStatus:i}}async function aa(s){try{const n=await W(V(`/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 ra=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",""]),ia=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),la=new Set([".pdf"]),oa=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 ca(s){const n=s.toLowerCase();return ia.has(n)?"image":la.has(n)?"pdf":oa.has(n)?"binary":(ra.has(n),"text")}function da(){const[s,n]=t.useState(null),[l,d]=t.useState(!1),[r,i]=t.useState(null),m=t.useCallback(async h=>{var p,j;d(!0),i(null);try{const f=h.substring(h.lastIndexOf(".")).toLowerCase(),b=ca(f),w=h.substring(h.lastIndexOf("/")+1);if(b==="image"){const k=await W(V(`/api/files/binary?path=${encodeURIComponent(h)}`));if(!k.ok){const C=await k.json().catch(()=>({error:"Failed to load image"}));i(C.error||"Failed to load image"),n(null);return}const x=await k.blob(),v=URL.createObjectURL(x);n({path:h,filename:w,extension:f,content:"",size:x.size,modified:new Date().toISOString(),fileType:"image",dataUrl:v});return}if(b==="pdf"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(!k.ok){i(x.error||"Failed to load PDF info"),n(null);return}n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"pdf",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&token=${encodeURIComponent(Yt())}`)});return}if(b==="binary"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(!k.ok){i(x.error||"Failed to load file info"),n(null);return}n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&download=true&token=${encodeURIComponent(Yt())}`)});return}const R=await W(V(`/api/files/read?path=${encodeURIComponent(h)}`)),g=await R.json();if(!R.ok){if((p=g.error)!=null&&p.includes("too large")||(j=g.error)!=null&&j.includes("binary")){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(k.ok){n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&download=true&token=${encodeURIComponent(Yt())}`)});return}}i(g.error||"Failed to load file"),n(null);return}n({...g,fileType:"text"})}catch(f){const b=f instanceof Error?f.message:"Failed to load file";i(b),n(null)}finally{d(!1)}},[]),o=t.useCallback(()=>{n(h=>(h!=null&&h.dataUrl&&h.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(h.dataUrl),null)),i(null)},[]);return{file:s,loading:l,error:r,loadFile:m,clearFile:o,setFile:n}}const Jt="file-explorer-state",ua=10080*60*1e3;function ha(s,n){return n?`${Jt}-folder-${n}`:s?`${Jt}-area-${s}`:`${Jt}-default`}async function ma(s){try{const n=await W(V(`/api/files/exists?path=${encodeURIComponent(s)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function fa({areaId:s,folderPath:n,isOpen:l}){const d=ha(s,n),r=t.useRef(!1);t.useEffect(()=>{r.current=!1},[s,n]);const i=t.useCallback(async()=>{if(r.current)return null;r.current=!0;try{const o=localStorage.getItem(d);if(!o)return null;const h=JSON.parse(o);if(Date.now()-h.timestamp>ua)return localStorage.removeItem(d),null;const j=(await Promise.all(h.tabs.map(async b=>({tab:b,exists:await ma(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let f=h.activeTabPath;return f&&!j.some(b=>b.path===f)&&(f=j.length>0?j[0].path:null),{tabs:j,activeTabPath:f,viewMode:h.viewMode||"files",selectedFolderIndex:h.selectedFolderIndex||0,expandedPaths:new Set(h.expandedPaths||[])}}catch(o){return console.error("[FileExplorerStorage] Failed to load state:",o),null}},[d]),m=t.useCallback(o=>{if(l)try{const h={tabs:o.tabs,activeTabPath:o.activeTabPath,viewMode:o.viewMode,selectedFolderIndex:o.selectedFolderIndex,expandedPaths:Array.from(o.expandedPaths),timestamp:Date.now()};localStorage.setItem(d,JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save state:",h)}},[d,l]);return{loadStoredState:i,saveState:m}}const Ls=280,$s=150,Hs=1200;function pa(){const[s,n]=t.useState(()=>{const p=Bs(Ht.TREE_PANEL_WIDTH,Ls);return p>=$s&&p<=Hs?p:Ls}),l=t.useRef(!1),[d,r]=t.useState(!1),i=t.useRef(0),m=t.useRef(0),o=t.useRef(s);o.current=s;const h=t.useCallback(p=>{p.preventDefault(),l.current=!0,r(!0),i.current=p.clientX,m.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 b=f.clientX-i.current,w=Math.min(Hs,Math.max($s,m.current+b));n(w)},j=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",_s(Ht.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",p),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",j)}},[]),{treePanelWidth:s,handleResizeStart:h,isResizing:d}}const ga=100,xa=.65,ya=36;function ba(){const[s,n]=t.useState(()=>Bs(Ht.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const d=t.useRef(0),r=t.useRef(0),i=()=>Math.floor((window.innerHeight-ya)*xa),m=f=>Math.min(i(),Math.max(ga,f)),o=t.useCallback(f=>{n(f);const b=document.querySelector(".file-explorer-main");b&&b.style.setProperty("--fe-mobile-tree-height",`${f}px`)},[]),h=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",_s(Ht.MOBILE_TREE_PANEL_HEIGHT,l.current),Be.setTerminalResizing(!1)},[]),p=t.useCallback(f=>{f.preventDefault();const b=document.querySelector(".file-explorer-tree-panel"),w=l.current>0?l.current:(b==null?void 0:b.getBoundingClientRect().height)??240;d.current=f.clientY,r.current=w,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Be.setTerminalResizing(!0);const R=k=>{const x=k.clientY-d.current;o(m(r.current+x))},g=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",g),h()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",g)},[o,h]),j=t.useCallback(f=>{if(f.touches.length!==1)return;const b=document.querySelector(".file-explorer-tree-panel"),w=l.current>0?l.current:(b==null?void 0:b.getBoundingClientRect().height)??240;d.current=f.touches[0].clientY,r.current=w,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Be.setTerminalResizing(!0);const R=k=>{if(k.touches.length!==1)return;k.preventDefault();const x=k.touches[0].clientY-d.current;o(m(r.current+x))},g=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",g),document.removeEventListener("touchcancel",g),h()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",g),document.addEventListener("touchcancel",g)},[o,h]);return{mobileTreeHeight:s,handleResizeMouseDown:p,handleResizeTouchStart:j}}function ts(){const[s,n]=t.useState([]),[l,d]=t.useState(!1),[r,i]=t.useState(null),[m,o]=t.useState(null),h=t.useCallback(async k=>{d(!0),i(null);try{const x=await W(V(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),v=await x.json();x.ok?n(v.branches||[]):(i(v.error||"Failed to load branches"),n([]))}catch(x){console.error("[GitBranches] Failed to load branches:",x),i("Failed to load branches"),n([])}finally{d(!1)}},[]),p=t.useCallback(async(k,x)=>{o("checkout"),i(null);try{const v=await W(V("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:x})}),C=await v.json();return v.ok||i(C.error||"Checkout failed"),C}catch(v){console.error("[GitBranches] Checkout failed:",v);const C={success:!1,error:"Checkout failed"};return i(C.error),C}finally{o(null)}},[]),j=t.useCallback(async(k,x,v)=>{o("create"),i(null);try{const C=await W(V("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:x,startPoint:v})}),D=await C.json();return C.ok||i(D.error||"Failed to create branch"),D}catch(C){console.error("[GitBranches] Create branch failed:",C);const D={success:!1,error:"Failed to create branch"};return i(D.error),D}finally{o(null)}},[]),f=t.useCallback(async k=>{o("pull"),i(null);try{const x=await W(V("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return!x.ok&&!v.conflicts&&i(v.error||"Pull failed"),v}catch(x){console.error("[GitBranches] Pull failed:",x);const v={success:!1,error:"Pull failed"};return i(v.error),v}finally{o(null)}},[]),b=t.useCallback(async k=>{o("push"),i(null);try{const x=await W(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Push failed"),v}catch(x){console.error("[GitBranches] Push failed:",x);const v={success:!1,error:"Push failed"};return i(v.error),v}finally{o(null)}},[]),w=t.useCallback(async(k,x)=>{o("merge"),i(null);try{const v=await W(V("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:x})}),C=await v.json();return!v.ok&&!C.conflicts&&i(C.error||"Merge failed"),C}catch(v){console.error("[GitBranches] Merge failed:",v);const C={success:!1,error:"Merge failed"};return i(C.error),C}finally{o(null)}},[]),R=t.useCallback(async k=>{o("merge-abort"),i(null);try{const x=await W(V("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Merge abort failed"),v}catch(x){console.error("[GitBranches] Merge abort failed:",x);const v={success:!1,error:"Merge abort failed"};return i(v.error),v}finally{o(null)}},[]),g=t.useCallback(async k=>{o("merge-continue"),i(null);try{const x=await W(V("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Merge continue failed"),v}catch(x){console.error("[GitBranches] Merge continue failed:",x);const v={success:!1,error:"Merge continue failed"};return i(v.error),v}finally{o(null)}},[]);return{branches:s,loading:l,error:r,operationInProgress:m,loadBranches:h,checkoutBranch:p,createBranch:j,pullFromRemote:f,pushToRemote:b,mergeBranch:w,mergeAbort:R,mergeContinue:g}}const ja=50,va=400,zs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function wa(){const[s,n]=t.useState([]),[l,d]=t.useState(!1),[r,i]=t.useState(!1),[m,o]=t.useState(null),[h,p]=t.useState(!1),[j,f]=t.useState(0),[b,w]=t.useState({...zs}),[R,g]=t.useState(null),[k,x]=t.useState([]),[v,C]=t.useState(!1),[D,N]=t.useState([]),[U,_]=t.useState(!1),O=t.useRef(null),se=t.useRef(""),Q=t.useCallback((z,I,$)=>{const P=$||b,ee=new URLSearchParams;return ee.set("path",z),ee.set("limit",String(ja)),ee.set("offset",String(I)),P.branch&&ee.set("branch",P.branch),P.author&&ee.set("author",P.author),P.since&&ee.set("since",P.since),P.until&&ee.set("until",P.until),P.searchPath&&ee.set("searchPath",P.searchPath),P.search&&ee.set("search",P.search),ee.toString()},[b]),T=t.useCallback(async z=>{se.current=z,d(!0),o(null),g(null),x([]);try{const I=Q(z,0),$=await W(V(`/api/files/git-log?${I}`)),P=await $.json();$.ok?(n(P.commits||[]),f(P.total||0),p(P.hasMore||!1)):(o(P.error||"Failed to load git history"),n([]))}catch(I){console.error("[useGitHistory] loadHistory error:",I),o("Failed to load git history"),n([])}finally{d(!1)}},[Q]),F=t.useCallback(async z=>{if(!(r||!h)){i(!0);try{const I=Q(z,s.length),$=await W(V(`/api/files/git-log?${I}`)),P=await $.json();$.ok&&(n(ee=>[...ee,...P.commits||[]]),f(P.total||0),p(P.hasMore||!1))}catch(I){console.error("[useGitHistory] loadMore error:",I)}finally{i(!1)}}},[Q,s.length,h,r]),K=t.useCallback(async z=>{if(g(z),!z){x([]);return}C(!0);try{const I=se.current,$=new URLSearchParams({path:I,hash:z.hash}),P=await W(V(`/api/files/git-commit-files?${$}`)),ee=await P.json();P.ok?x(ee.files||[]):x([])}catch(I){console.error("[useGitHistory] selectCommit files error:",I),x([])}finally{C(!1)}},[]),ne=t.useCallback((z,I)=>{w($=>({...$,[z]:I}))},[]),ie=t.useCallback(()=>{w({...zs})},[]);t.useEffect(()=>{const z=se.current;if(z)return O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{T(z)},va),()=>{O.current&&clearTimeout(O.current)}},[b]);const fe=t.useCallback(async z=>{_(!0);try{const I=new URLSearchParams({path:z}),$=await W(V(`/api/files/git-authors?${I}`)),P=await $.json();$.ok&&N(P.authors||[])}catch(I){console.error("[useGitHistory] loadAuthors error:",I)}finally{_(!1)}},[]);return{commits:s,loading:l,loadingMore:r,error:m,hasMore:h,total:j,filters:b,setFilter:ne,resetFilters:ie,selectedCommit:R,selectCommit:K,commitFiles:k,commitFilesLoading:v,loadHistory:T,loadMore:F,authors:D,authorsLoading:U,loadAuthors:fe}}function Ca(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 d=s.current.querySelector(l);if(d&&Os(d))return d}return Os(s.current)?s.current:null}function Os(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function Js(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function Xt(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Na(s){const{scrollTop:n,scrollHeight:l,clientHeight:d}=s;return l<=d?100:Math.round(n/(l-d)*100)}function ka(s,n){const l=Js(s),d=s.scrollTop,r=Math.floor(d/l)+1,i=n.split(`
|
|
3
|
+
`).length;return Math.min(r,i)}function Ea(s,n,l=!1){if(!n)return[];l||s.toLowerCase();const d=l?n:n.toLowerCase(),r=[];let i=0;const m=s.split(`
|
|
4
|
+
`);let o=0;for(let h=0;h<m.length;h++){const p=m[h],j=l?p:p.toLowerCase();let f=0,b=j.indexOf(d);for(;b!==-1;){const w=o+b;r.push({index:i++,line:h+1,column:b,length:d.length,charIndex:w}),f=b+d.length,b=j.indexOf(d,f)}o+=p.length+1}return r}function dt(s){return/[\w]/.test(s)}function _e(s){return/\s/.test(s)}function Sa(s,n,l){let d=n-1,r=l;const i=s.length,m=s[d]||"";if(r<m.length){const p=dt(m[r]);if(!_e(m[r]))for(;r<m.length&&!_e(m[r])&&dt(m[r])===p;)r++}for(;d<i;){const p=s[d]||"";for(;r<p.length&&_e(p[r]);)r++;if(r<p.length)return{line:d+1,col:r};d++,r=0}const o=i,h=Math.max(0,(s[i-1]||"").length-1);return{line:o,col:h}}function Ta(s,n,l){let d=n-1,r=l+1;const i=s.length;for(;d<i;){const h=s[d]||"";for(;r<h.length&&_e(h[r]);)r++;if(r<h.length)break;d++,r=0}if(d>=i)return{line:i,col:Math.max(0,(s[i-1]||"").length-1)};const m=s[d]||"",o=dt(m[r]);for(;r+1<m.length&&!_e(m[r+1])&&dt(m[r+1])===o;)r++;return{line:d+1,col:r}}function Ma(s,n,l){let d=n-1,r=l-1;for(;d>=0;){const o=s[d]||"";for(;r>=0&&_e(o[r]);)r--;if(r>=0)break;d--,d>=0&&(r=(s[d]||"").length-1)}if(d<0)return{line:1,col:0};const i=s[d]||"",m=dt(i[r]);for(;r>0&&!_e(i[r-1])&&dt(i[r-1])===m;)r--;return{line:d+1,col:r}}function Da(s,n,l,d){if(d==="none")return"";const{anchorLine:r,anchorCol:i,headLine:m,headCol:o}=l;if(d==="line"){const w=Math.min(r,m),R=Math.max(r,m);return n.slice(w-1,R).join(`
|
|
5
|
+
`)}let h,p,j,f;if(r<m||r===m&&i<=o?(h=r,p=i,j=m,f=o):(h=m,p=o,j=r,f=i),h===j)return(n[h-1]||"").substring(p,f+1);const b=[];b.push((n[h-1]||"").substring(p));for(let w=h;w<j-1;w++)b.push(n[w]||"");return b.push((n[j-1]||"").substring(0,f+1)),b.join(`
|
|
6
|
+
`)}function Xs(s){const{containerRef:n,isEnabled:l=!0,content:d="",onClose:r,onSearchOpen:i}=s,m=t.useRef({percentage:0,line:1,column:1}),o=t.useRef(null),h=t.useRef(19.5),p=t.useMemo(()=>d.split(`
|
|
7
|
+
`),[d]),j=p.length,[f,b]=t.useState(1),[w,R]=t.useState(0),[g,k]=t.useState(!1),[x,v]=t.useState("none"),[C,D]=t.useState(null),[N,U]=t.useState(!1),[_,O]=t.useState(""),[se,Q]=t.useState(0),[T,F]=t.useState(!1),K=t.useMemo(()=>Ea(d,_,!1),[d,_]),ne=t.useCallback(()=>{const c=o.current;if(!c)return;const G=Na(c),ae=ka(c,d),A=Math.max(1,Math.round(c.scrollLeft/7.8)+1);m.current={percentage:G,line:ae,column:A}},[d]),ie=t.useCallback(()=>{U(!0),O(""),Q(0),i==null||i()},[i]),fe=t.useCallback(()=>{U(!1),O(""),Q(0)},[]),z=t.useCallback(()=>{F(c=>!c)},[]),I=t.useCallback(c=>{const G=o.current;if(!G)return;const ae=G.querySelector(".file-viewer-pre"),ce=ae&&parseFloat(getComputedStyle(ae).lineHeight)||h.current,A=ae&&parseFloat(getComputedStyle(ae).paddingTop)||0,q=(ae?ae.offsetTop:0)+A+(c-1)*ce,Z=ce*3;G.scrollTo({top:Math.max(0,q-Z),behavior:"smooth"})},[]);t.useEffect(()=>{!N||K.length===0||Q(0)},[K,N]),t.useEffect(()=>{if(!N||K.length===0)return;const c=K[se];c&&(b(c.line),R(c.column),I(c.line))},[N,K,se,I]);const $=t.useCallback(()=>{K.length!==0&&Q(c=>(c+1)%K.length)},[K]),P=t.useCallback(()=>{K.length!==0&&Q(c=>(c-1+K.length)%K.length)},[K]),ee=t.useCallback(c=>{const G=o.current;if(!G)return;const ae=G.querySelector(".file-viewer-pre");if(!ae)return;const ce=parseFloat(getComputedStyle(ae).lineHeight),A=isNaN(ce)?h.current:ce,S=parseFloat(getComputedStyle(ae).paddingTop)||0,Z=ae.offsetTop+S+(c-1)*A,Te=Z+A,ve=G.scrollTop,X=ve+G.clientHeight;Z<ve?G.scrollTo({top:Math.max(0,Z),behavior:"auto"}):Te>X&&G.scrollTo({top:Te-G.clientHeight,behavior:"auto"})},[]),te=t.useCallback((c,G)=>{b(c),R(G),ee(c),x!=="none"&&D(ae=>ae?{...ae,headLine:c,headCol:G}:null)},[x,ee]),ge=t.useCallback(()=>{if(x==="none"||!C)return;const c=Da(d,p,C,x);c&&navigator.clipboard.writeText(c).catch(()=>{const G=document.createElement("textarea");G.value=c,G.style.position="fixed",G.style.left="-9999px",document.body.appendChild(G),G.select(),document.execCommand("copy"),document.body.removeChild(G)}),v("none"),D(null)},[x,C,d,p]),je=t.useCallback(c=>{const G=c.target;if((G.tagName==="INPUT"||G.tagName==="TEXTAREA")&&c.key!=="Escape")return;const ce=o.current;if(!ce)return;let A=!1;const S=h.current,q=Math.max(1,Math.floor(ce.clientHeight/S)),Z=Math.max(1,Math.floor(q/2)),Te=(X,xe)=>{const ze=Math.max(0,(p[X-1]||"").length-1);return Math.min(xe,Math.max(0,ze))},ve=(X,xe)=>{const ze=Te(X,xe);te(X,ze)};if(c.key==="v"&&!c.shiftKey&&!c.ctrlKey&&!N)c.preventDefault(),c.stopPropagation(),x==="char"?(v("none"),D(null)):(v("char"),D({anchorLine:f,anchorCol:w,headLine:f,headCol:w})),A=!0;else if(c.key==="V"&&c.shiftKey&&!c.ctrlKey&&!N)c.preventDefault(),c.stopPropagation(),x==="line"?(v("none"),D(null)):(v("line"),D({anchorLine:f,anchorCol:0,headLine:f,headCol:0})),A=!0;else if(c.key==="y"&&!c.ctrlKey&&x!=="none")c.preventDefault(),c.stopPropagation(),ge(),A=!0;else if(c.key==="j"||c.key==="ArrowDown"){c.preventDefault(),c.stopPropagation();const X=Math.min(f+1,j);ve(X,w),A=!0}else if(c.key==="k"||c.key==="ArrowUp"){c.preventDefault(),c.stopPropagation();const X=Math.max(f-1,1);ve(X,w),A=!0}else if(c.key==="d"&&c.ctrlKey||c.key==="d"&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.min(f+Z,j);ve(X,w),A=!0}else if(c.key==="u"&&c.ctrlKey||c.key==="u"&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.max(f-Z,1);ve(X,w),A=!0}else if((c.ctrlKey||c.metaKey)&&c.key==="f")c.preventDefault(),c.stopPropagation(),ie(),A=!0;else if(c.key==="f"&&!c.ctrlKey&&!c.metaKey&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.min(f+q,j);ve(X,w),A=!0}else if(c.key===" "||c.key==="PageDown"){c.preventDefault(),c.stopPropagation();const X=Math.min(f+q,j);ve(X,w),A=!0}else if(c.key==="b"&&!g&&x==="none"&&!N||c.key==="PageUp"){c.preventDefault(),c.stopPropagation();const X=Math.max(f-q,1);ve(X,w),A=!0}else if(c.key==="g"&&!c.shiftKey&&x==="none"&&!N)c.preventDefault(),c.stopPropagation(),te(1,0),Xt(ce,!1),A=!0;else if(c.key==="Home")c.preventDefault(),c.stopPropagation(),te(1,0),Xt(ce,!1),A=!0;else if(c.key==="G"&&c.shiftKey||c.key==="End")c.preventDefault(),c.stopPropagation(),te(j,0),Xt(ce,!0),A=!0;else if(c.key==="h"||c.key==="ArrowLeft")c.preventDefault(),c.stopPropagation(),te(f,Math.max(0,w-1)),A=!0;else if(c.key==="l"||c.key==="ArrowRight"){c.preventDefault(),c.stopPropagation();const X=(p[f-1]||"").length;te(f,Math.min(w+1,Math.max(0,X-1))),A=!0}else if(c.key==="w"&&!c.ctrlKey&&!N){c.preventDefault(),c.stopPropagation();const X=Sa(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="e"&&!c.ctrlKey&&!N){c.preventDefault(),c.stopPropagation();const X=Ta(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="b"&&!N){c.preventDefault(),c.stopPropagation();const X=Ma(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="0")c.preventDefault(),c.stopPropagation(),te(f,0),A=!0;else if(c.key==="$")c.preventDefault(),c.stopPropagation(),te(f,Math.max(0,(p[f-1]||"").length-1)),A=!0;else if(c.key==="^"){c.preventDefault(),c.stopPropagation();const xe=(p[f-1]||"").search(/\S/);te(f,xe>=0?xe:0),A=!0}else c.key==="/"?(c.preventDefault(),c.stopPropagation(),ie(),A=!0):c.key==="n"&&!N?(c.preventDefault(),c.stopPropagation(),$(),A=!0):c.key==="N"&&c.shiftKey&&!N?(c.preventDefault(),c.stopPropagation(),P(),A=!0):c.key==="?"&&x==="none"?(c.preventDefault(),c.stopPropagation(),z(),A=!0):c.key==="q"&&x==="none"?(c.preventDefault(),c.stopPropagation(),r==null||r(),A=!0):c.key==="Escape"&&(x!=="none"?(c.preventDefault(),c.stopPropagation(),v("none"),D(null),A=!0):N?(c.preventDefault(),c.stopPropagation(),fe(),A=!0):g&&(c.preventDefault(),c.stopPropagation(),k(!1),A=!0));A&&(c.key!=="Escape"&&!g&&k(!0),requestAnimationFrame(ne))},[r,ne,j,p,f,w,ee,N,fe,x,g,te,ge,ie,$,P,z]);return t.useEffect(()=>{if(!l)return;const c=Ca(n);if(o.current=c,!c){console.warn("[useLessNavigation] Could not find scrollable container");return}h.current=Js(c);const G=()=>{ne()};return window.addEventListener("keydown",je,{capture:!0}),c.addEventListener("scroll",G,{passive:!0}),ne(),()=>{window.removeEventListener("keydown",je,{capture:!0}),c.removeEventListener("scroll",G)}},[l,je,ne]),{scrollPercentage:m.current.percentage,currentLine:m.current.line,currentColumn:m.current.column,totalLines:j,cursorLine:f,cursorCol:w,cursorModeActive:g,visualMode:x,selection:C,searchActive:N,searchQuery:_,searchMatches:K,currentMatchIndex:se,startSearch:ie,setSearchQuery:O,nextMatch:$,prevMatch:P,clearSearch:fe,helpActive:T,toggleHelp:z}}const ss=({query:s,onQueryChange:n,matchCount:l,currentIndex:d,onNext:r,onPrev:i,onClose:m})=>{const{t:o}=re(["terminal"]),h=t.useRef(null);t.useEffect(()=>{var f;(f=h.current)==null||f.focus()},[]);const p=t.useCallback(f=>{f.stopPropagation(),f.key==="Enter"||f.key==="ArrowDown"?(f.preventDefault(),r()):f.key==="ArrowUp"&&(f.preventDefault(),i())},[r,i]),j=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${d+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:h,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:j}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:i,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:r,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:m,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};ss.displayName="SearchBar";const Ra=[{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"}],ns=({onClose:s})=>{const{t:n}=re(["terminal"]),l=t.useCallback(i=>{i.target===i.currentTarget&&s()},[s]),d=t.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),s())},[s]),r=Ra.reduce((i,m)=>(i[m.category]||(i[m.category]=[]),i[m.category].push(m),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:d,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(r).map(([i,m])=>e.jsxs("div",{className:"keybindings-help-category",children:[e.jsx("h3",{className:"keybindings-help-category-title",children:i}),e.jsx("div",{className:"keybindings-help-list",children:m.map((o,h)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((p,j)=>e.jsx("kbd",{className:"keybindings-help-key",children:p},j))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},h))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};ns.displayName="KeybindingsHelp";const As=t.lazy(()=>Gn(()=>import("./EmbeddedEditor-C4gQ9cLk.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Fa=[".md",".mdx",".markdown"],Gs="file-viewer-markdown-render",Ia=[".puml",".plantuml",".iuml",".pu"],Us="file-viewer-plantuml-render",Pa="https://kroki.io/plantuml/svg";function La(s){return Fa.includes(s.toLowerCase())}function $a(s){return Ia.includes(s.toLowerCase())}function Ha(){const[s,n]=t.useState(()=>{try{const d=localStorage.getItem(Gs);return d===null?!0:d==="true"}catch{return!0}}),l=t.useCallback(()=>{n(d=>{const r=!d;try{localStorage.setItem(Gs,String(r))}catch{}return r})},[]);return[s,l]}function za(){const[s,n]=t.useState(()=>{try{const d=localStorage.getItem(Us);return d===null?!0:d==="true"}catch{return!0}}),l=t.useCallback(()=>{n(d=>{const r=!d;try{localStorage.setItem(Us,String(r))}catch{}return r})},[]);return[s,l]}function Oa(s){const n=new TextEncoder().encode(s);let l="";for(const d of n)l+=String.fromCharCode(d);return`data:image/svg+xml;base64,${window.btoa(l)}`}function Ve({file:s,rightContent:n,onRevealInTree:l,editMode:d,onToggleEdit:r}){const{t:i}=re(["terminal","common"]),[m,o]=t.useState("idle"),[h,p]=t.useState("idle"),[j,f]=t.useState("idle"),b=s.fileType==="text"?zt(s.extension):s.extension.slice(1).toUpperCase(),w=s.fileType==="text"&&s.content!=null,{settings:R}=Vs(),g=async()=>{try{await Pt(s.content),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},k=()=>{const D=new Blob([s.content],{type:"text/plain;charset=utf-8"}),N=URL.createObjectURL(D),U=document.createElement("a");U.href=N,U.download=s.filename,document.body.appendChild(U),U.click(),U.remove(),setTimeout(()=>URL.revokeObjectURL(N),1e3)},x=async()=>{o("loading");try{const D=await W(V("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!D.ok){const N=await D.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",N),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(D){console.error("Error opening file in editor:",D),o("error"),setTimeout(()=>o("idle"),2e3)}},v=async()=>{if(s.path)try{await Kn(s.path),p("success"),setTimeout(()=>p("idle"),2e3)}catch(D){console.error("Error opening file explorer:",D),p("error"),setTimeout(()=>p("idle"),2e3)}},C=i("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:[Ks(s.size)," • ",b,s.content&&` • ${s.content.split(`
|
|
8
|
+
`).length} lines`]})]}),e.jsxs("div",{className:"file-viewer-header-right",children:[r&&s.fileType==="text"&&e.jsx("button",{className:`file-viewer-edit-btn${d?" active":""}`,onClick:r,title:i(d?"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"})})}),w&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${j}`,onClick:g,title:i("terminal:fileExplorer.copyAllTitle"),children:i(j==="copied"?"terminal:fileExplorer.copied":j==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyAll")}),e.jsx("button",{className:"file-viewer-download-btn",onClick:k,title:i("terminal:fileExplorer.downloadFileTitle"),children:i("common:buttons.download")})]}),e.jsx("button",{className:`file-viewer-reveal-explorer-btn ${h}`,onClick:v,disabled:!s.path,title:C,"aria-label":C,children:h==="success"?e.jsx(M,{name:"check",size:14}):h==="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 ${m}`,onClick:x,disabled:m==="loading",title:i(m==="error"?"terminal:fileExplorer.failedToOpenEditor":m==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:m==="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"})}):m==="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:i("terminal:fileExplorer.locateInTree"),children:e.jsx(M,{name:"target",size:14})}),n]})]})}function Aa({file:s,onRevealInTree:n,renderMarkdown:l,onToggleRender:d,editMode:r,onToggleEdit:i}){const m=t.useRef(null),o=t.useRef(null),h=t.useRef(null),{t:p}=re(["terminal","common"]),[j,f]=t.useState("idle"),[b,w]=t.useState("idle"),[R,g]=t.useState("idle"),[k,x]=t.useState("idle"),v=Xs({containerRef:h,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&m.current){const O=zt(s.extension);Ws(O).then(()=>{m.current&&qs(m.current)})}},[s,l]);const C=t.useCallback(async()=>{if(!o.current){f("error"),setTimeout(()=>f("idle"),2e3);return}try{const O=o.current.innerHTML,se=Un(O),Q=o.current.innerText;await Bn(se,Q),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},[]),D=t.useCallback(async()=>{if(!o.current){w("error"),setTimeout(()=>w("idle"),2e3);return}try{const O=o.current.innerHTML;await Pt(O),w("copied"),setTimeout(()=>w("idle"),2e3)}catch{w("error"),setTimeout(()=>w("idle"),2e3)}},[]),N=t.useCallback(async()=>{try{await Pt(s.content),g("copied"),setTimeout(()=>g("idle"),2e3)}catch{g("error"),setTimeout(()=>g("idle"),2e3)}},[s.content]),U=t.useCallback(async()=>{try{await Pt(s.content),x("copied"),setTimeout(()=>x("idle"),2e3)}catch{x("error"),setTimeout(()=>x("idle"),2e3)}},[s.content]),_=e.jsxs("div",{className:"file-viewer-header-buttons",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${j}`,onClick:C,title:p("terminal:fileExplorer.copyRichTextTitle"),children:p(j==="copied"?"terminal:fileExplorer.copied":j==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:D,title:p("terminal:fileExplorer.copyHtmlTitle"),children:p(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${R}`,onClick:N,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:U,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:d,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:_,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:h,children:[l?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:o,children:e.jsx(_n,{remarkPlugins:[Vn],children:s.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:m,className:"language-markdown",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${v.currentLine}/${v.totalLines}`,children:v.scrollPercentage===100?"END":v.scrollPercentage===0?"TOP":`${v.scrollPercentage}%`}),v.searchActive&&e.jsx(ss,{query:v.searchQuery,onQueryChange:v.setSearchQuery,matchCount:v.searchMatches.length,currentIndex:v.currentMatchIndex,onNext:v.nextMatch,onPrev:v.prevMatch,onClose:v.clearSearch})]}),v.helpActive&&e.jsx(ns,{onClose:v.toggleHelp})]})}function Ga({file:s,onRevealInTree:n,renderPlantUml:l,onToggleRender:d,editMode:r,onToggleEdit:i}){const{t:m}=re(["terminal"]),o=t.useRef(null),h=t.useRef(null),[p,j]=t.useState(null),[f,b]=t.useState(!1),[w,R]=t.useState(null),g=Xs({containerRef:h,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&o.current){const x=zt(s.extension);Ws(x).then(()=>{o.current&&qs(o.current)})}},[s,l]),t.useEffect(()=>{if(!l)return;if(!s.content.trim()){j(null),R("Diagram is empty");return}const x=new AbortController;return b(!0),R(null),(async()=>{try{const C=await fetch(Pa,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:s.content,signal:x.signal});if(!C.ok)throw new Error(`Render failed (${C.status})`);const D=await C.text();if(!D.includes("<svg"))throw new Error("Invalid SVG output");j(Oa(D))}catch(C){if(x.signal.aborted)return;const D=C instanceof Error?C.message:"Failed to render diagram";R(D),j(null)}finally{x.signal.aborted||b(!1)}})(),()=>x.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:d,title:m(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:l?"</>":m("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:k,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:h,children:[l?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[f&&e.jsx("div",{className:"file-viewer-placeholder",children:m("terminal:fileExplorer.renderingDiagram")}),!f&&p&&e.jsx("img",{src:p,alt:s.filename,className:"file-viewer-diagram-image"}),!f&&w&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[m("terminal:fileExplorer.couldNotRender"),": ",w]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:d,children:m("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 ${g.currentLine}/${g.totalLines}`,children:g.scrollPercentage===100?"END":g.scrollPercentage===0?"TOP":`${g.scrollPercentage}%`}),g.searchActive&&e.jsx(ss,{query:g.searchQuery,onQueryChange:g.setSearchQuery,matchCount:g.searchMatches.length,currentIndex:g.currentMatchIndex,onNext:g.nextMatch,onPrev:g.prevMatch,onClose:g.clearSearch})]}),g.helpActive&&e.jsx(ns,{onClose:g.toggleHelp})]})}function Ua({file:s,onRevealInTree:n}){const{t:l}=re(["common","terminal"]),d=()=>{if(s.dataUrl){const r=document.createElement("a");r.href=s.dataUrl,r.download=s.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:d,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper",children:s.dataUrl?e.jsx("img",{src:s.dataUrl,alt:s.filename,className:"file-viewer-image"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadImage")})})]})}function Ba({file:s,onRevealInTree:n}){const{t:l}=re(["common","terminal"]),d=()=>{if(s.dataUrl){const r=document.createElement("a");r.href=s.dataUrl,r.download=s.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:d,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 _a({file:s,onRevealInTree:n}){const{t:l}=re(["terminal","common"]),d=()=>{if(s.dataUrl){const i=document.createElement("a");i.href=s.dataUrl,i.download=s.filename,i.click()}},r=()=>{const i=s.extension.toLowerCase();return[".xlsx",".xls"].includes(i)?e.jsx(M,{name:"dashboard",size:48}):[".docx",".doc"].includes(i)?e.jsx(M,{name:"edit",size:48}):[".pptx",".ppt"].includes(i)?e.jsx(M,{name:"film",size:48}):[".zip",".tar",".gz",".rar",".7z"].includes(i)?e.jsx(M,{name:"file-zip",size:48}):[".mp3",".wav",".flac",".ogg"].includes(i)?e.jsx(M,{name:"music-note",size:48}):[".mp4",".avi",".mov",".mkv",".webm"].includes(i)?e.jsx(M,{name:"film",size:48}):[".exe",".dmg",".app",".msi"].includes(i)?e.jsx(M,{name:"gear",size:48}):[".apk",".aab",".ipa"].includes(i)?e.jsx(M,{name:"mobile",size:48}):[".jar",".war",".ear"].includes(i)?e.jsx(M,{name:"coffee",size:48}):[".iso",".img"].includes(i)?e.jsx(M,{name:"disc",size:48}):[".so",".dll",".dylib"].includes(i)?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:r()}),e.jsx("div",{className:"file-viewer-binary-name",children:s.filename}),e.jsx("div",{className:"file-viewer-binary-size",children:Ks(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:d,children:l("terminal:fileExplorer.downloadFile")})]})]})}function Va({file:s,loading:n,error:l,onRevealInTree:d,onFileEdited:r}){const{t:i}=re(["terminal","common"]),[m,o]=Ha(),[h,p]=za(),[j,f]=t.useState(!1);t.useEffect(()=>{f(!1)},[s==null?void 0:s.path]);const b=t.useCallback(async C=>{if(!s)return;const D=await W(V("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,content:C})});if(!D.ok){const N=await D.json().catch(()=>({error:"Save failed"}));throw new Error(N.error||"Save failed")}},[s]),w=t.useCallback(()=>{f(C=>(C&&s&&(r==null||r(s.path)),!C))},[s,r]),R=t.useCallback(()=>{s&&(r==null||r(s.path))},[s,r]);if(n)return e.jsx("div",{className:"file-viewer-placeholder",children:i("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:i("terminal:fileExplorer.selectFileToView")})]});const g=s.fileType||"text",k=g==="text"&&La(s.extension),x=g==="text"&&$a(s.extension),v=k||x;return v&&j&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:d,editMode:!0,onToggleEdit:w}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(As,{content:s.content,extension:s.extension,onSave:b,onCancel:w},s.path)})]}):g==="text"&&!v&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:d}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(As,{content:s.content,extension:s.extension,onSave:b,onCancel:R},s.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[k&&e.jsx(Aa,{file:s,onRevealInTree:d,renderMarkdown:m,onToggleRender:o,editMode:j,onToggleEdit:w}),x&&!k&&e.jsx(Ga,{file:s,onRevealInTree:d,renderPlantUml:h,onToggleRender:p,editMode:j,onToggleEdit:w}),g==="image"&&e.jsx(Ua,{file:s,onRevealInTree:d}),g==="pdf"&&e.jsx(Ba,{file:s,onRevealInTree:d}),g==="binary"&&e.jsx(_a,{file:s,onRevealInTree:d})]})}const Qs=t.memo(Va,(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);Qs.displayName="FileViewer";function Zs({text:s,query:n}){if(!n)return e.jsx(e.Fragment,{children:s});const l=Wn(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 d=n.toLowerCase(),i=s.toLowerCase().indexOf(d);return i===-1?e.jsx(e.Fragment,{children:s}):e.jsxs(e.Fragment,{children:[s.slice(0,i),e.jsx("mark",{className:"search-highlight",children:s.slice(i,i+n.length)}),s.slice(i+n.length)]})}const Ka=t.memo(function({node:n,query:l,isSelected:d,onSelect:r,lineNumber:i}){const m=n.isDirectory?null:es(n),o=n.path.split("/");o[o.length-1];const h=o.slice(0,-1).join("/");return e.jsxs("div",{className:`search-result-item ${d?"selected":""}`,onClick:()=>r(n),children:[n.isDirectory?e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"folder",size:14})}):m?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${m}')`},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(Zs,{text:n.name,query:l}),i&&e.jsxs("span",{className:"search-result-line-badge",children:[":",i]})]}),e.jsx("span",{className:"search-result-path",children:h})]})]})}),Wa=t.memo(function({match:n,query:l,isSelected:d,onSelect:r}){const{t:i}=re(["terminal"]),m={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},o=es(m),h=n.path.split("/"),p=h[h.length-1],j=h.slice(0,-1).join("/");return e.jsxs("div",{className:`content-search-item ${d?"selected":""}`,children:[e.jsxs("div",{className:`content-search-header ${d?"selected":""}`,onClick:()=>r(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:j})]}),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,b)=>e.jsxs("div",{className:"content-search-match",onClick:()=>r(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(Zs,{text:f.content.trim(),query:l})})]},`${n.path}-${f.line}-${b}`)),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:i("terminal:fileExplorer.moreMatches",{count:n.matches.length-5})})]})]})]})});function qa({filenameResults:s,contentResults:n,onSelectFile:l,onSelectContent:d,selectedPath:r,query:i,lineNumber:m}){const{t:o}=re(["terminal"]),h=s.length>0,p=n.length>0;return!h&&!p?e.jsx("div",{className:"search-no-results",children:o("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[h&&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(j=>e.jsx(Ka,{node:j,query:i,isSelected:r===j.path,onSelect:l,lineNumber:m},j.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((j,f)=>j+f.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(j=>e.jsx(Wa,{match:j,query:i,isSelected:r===j.path,onSelect:d},j.path))})]})]})}const en=t.memo(qa,(s,n)=>!(s.query!==n.query||s.selectedPath!==n.selectedPath||s.filenameResults.length!==n.filenameResults.length||s.contentResults.length!==n.contentResults.length));en.displayName="UnifiedSearchResults";const Ya=t.memo(function({file:n,isSelected:l,onSelect:d,onStage:r,isStaging:i,showDirPath:m,isChecked:o,onToggleCheck:h,onContextMenu:p,onDiscard:j}){const{t:f}=re(["terminal"]),b=n.status,w=yt[b],R=b==="deleted",g=b==="untracked"&&r,k=n.name.includes(".")?"."+n.name.split(".").pop():"",x=m&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!R&&d(n.path,b),onContextMenu:v=>{v.preventDefault(),p==null||p(v,n,b)},style:{cursor:R?"not-allowed":"pointer"},title:n.path,children:[h&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:o||!1,onChange:v=>{v.stopPropagation(),h(n.path)},onClick:v=>v.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:xt(k),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,x&&e.jsx("span",{className:"git-file-dir",children:x})]}),e.jsx("span",{className:"git-file-status",style:{color:w.color},children:w.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()]}),g&&e.jsx("button",{className:`git-stage-btn ${i?"staging":""}`,onClick:v=>{v.stopPropagation(),i||r(n.path)},title:f("terminal:fileExplorer.stageFile"),disabled:i,children:i?"...":"+"}),j&&e.jsx("button",{className:"git-discard-btn",onClick:v=>{v.stopPropagation(),j(n,b)},title:b==="untracked"||b==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}),Ja=16,Xa=22,Qa=t.memo(function s({node:n,depth:l,expandedDirs:d,onToggleDir:r,selectedPath:i,onSelect:m,onStage:o,stagingPaths:h,checkedFiles:p,onToggleCheck:j,onContextMenu:f,onDirContextMenu:b,onDiscard:w}){const{t:R}=re(["terminal"]),g=l*Ja;if(!n.isDirectory){const x=n.file.status,v=yt[x];return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>x!=="deleted"&&m(n.file.path,x),onContextMenu:C=>{C.preventDefault(),f==null||f(C,n.file,x)},style:{paddingLeft:`${g+Xa}px`,cursor:x==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[j&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(p==null?void 0:p.has(n.file.path))||!1,onChange:C=>{C.stopPropagation(),j(n.file.path)},onClick:C=>C.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:xt(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:v.color},children:v.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()]}),x==="untracked"&&o&&e.jsx("button",{className:`git-stage-btn ${h!=null&&h.has(n.path)?"staging":""}`,onClick:C=>{C.stopPropagation(),h!=null&&h.has(n.path)||o(n.file.path)},title:R("terminal:fileExplorer.stageFile"),disabled:h==null?void 0:h.has(n.path),children:h!=null&&h.has(n.path)?"...":"+"}),w&&e.jsx("button",{className:"git-discard-btn",onClick:C=>{C.stopPropagation(),w(n.file,x)},title:x==="untracked"||x==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}const k=d.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${k?"expanded":""}`,style:{paddingLeft:`${g}px`},onClick:()=>r(n.path),onContextMenu:x=>{x.preventDefault(),x.stopPropagation(),b==null||b(x,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(x=>e.jsx(s,{node:x,depth:l+1,expandedDirs:d,onToggleDir:r,selectedPath:i,onSelect:m,onStage:o,stagingPaths:h,checkedFiles:p,onToggleCheck:j,onContextMenu:f,onDirContextMenu:b,onDiscard:w},x.path))})]})}),Qt=t.memo(function({groupLabel:n,groupIcon:l,groupColor:d,files:r,treeNodes:i,viewMode:m,selectedPath:o,expandedDirs:h,onToggleDir:p,onFileSelect:j,onStageFile:f,onStageAll:b,stagingPaths:w,checkedFiles:R,onToggleCheck:g,onContextMenu:k,onDirContextMenu:x,onDiscardFile:v,onDiscardAll:C}){const{t:D}=re(["terminal"]);if(r.length===0)return null;const N=r.some(O=>O.status==="untracked"),U=N&&b&&r.length>0,_=w?r.every(O=>w.has(O.path)):!1;return e.jsxs("div",{className:"git-status-group",children:[e.jsxs("div",{className:"git-status-group-header",style:{color:d},children:[e.jsx("span",{className:"git-status-badge",style:{background:d},children:l}),n," (",r.length,")",U&&e.jsx("button",{className:`git-stage-all-btn ${_?"staging":""}`,onClick:O=>{O.stopPropagation(),_||b()},title:D("terminal:fileExplorer.stageAllUntracked"),disabled:_,children:_?"...":D("terminal:fileExplorer.stageAll")}),C&&e.jsxs("button",{className:"git-discard-all-btn",onClick:O=>{O.stopPropagation(),C()},title:N?`Delete all ${r.length} files`:`Discard all ${r.length} changes`,children:[e.jsx(M,{name:"revert",size:12})," All"]})]}),m==="tree"?e.jsx("div",{className:"git-tree-content",children:i.map(O=>e.jsx(Qa,{node:O,depth:0,expandedDirs:h,onToggleDir:p,selectedPath:o,onSelect:j,onStage:f,stagingPaths:w,checkedFiles:R,onToggleCheck:g,onContextMenu:k,onDirContextMenu:x,onDiscard:v},O.path))}):e.jsx("div",{className:"git-flat-content",children:r.map(O=>e.jsx(Ya,{file:O,isSelected:o===O.path,onSelect:j,onStage:O.status==="untracked"?f:void 0,isStaging:w==null?void 0:w.has(O.path),showDirPath:!0,isChecked:R==null?void 0:R.has(O.path),onToggleCheck:g,onContextMenu:k,onDiscard:v},O.path))})]})});function Za({gitStatus:s,loading:n,onFileSelect:l,selectedPath:d,onRefresh:r,onStageFiles:i,stagingPaths:m,currentFolder:o,onCommitComplete:h,mergeInProgress:p,mergingBranch:j,onMergeContinue:f,onMergeAbort:b,onConflictOpen:w,onRevealInTree:R}){const{t:g}=re(["terminal","common"]),[k,x]=t.useState("tree"),[v,C]=t.useState(new Set),[D,N]=t.useState(""),[U,_]=t.useState(""),[O,se]=t.useState(!1),[Q,T]=t.useState(new Set),[F,K]=t.useState(!1),[ne,ie]=t.useState(null),fe=t.useRef(null),{showToast:z}=Ys(),[I,$]=t.useState(null),[P,ee]=t.useState(null),[te,ge]=t.useState(null),je=t.useCallback((E,L)=>{ge({files:[E],label:E.name})},[]),c=t.useCallback(async()=>{if(!(!te||!o))try{const E=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:te.files.map(B=>({path:B.path,status:B.status})),directory:o})}),L=await E.json();E.ok&&L.success?(z("success","Discarded",`Reverted ${te.files.length} file(s)`),r()):z("error","Discard Failed",L.error||"Could not discard changes")}catch{z("error","Discard Failed","Network error")}finally{ge(null)}},[te,o,r,z]),G=t.useCallback((E,L,B)=>{E.preventDefault(),E.stopPropagation(),$({isOpen:!0,position:{x:E.clientX,y:E.clientY},file:L,status:B})},[]),ae=t.useCallback(async(E,L)=>{if(o)try{const B=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:E.path,status:L}],directory:o})}),pe=await B.json();B.ok&&pe.success?(z("success","Discarded",`Restored ${E.name}`),r()):z("error","Discard Failed",pe.error||"Could not discard changes")}catch{z("error","Discard Failed","Network error")}},[o,r,z]),ce=t.useCallback(async E=>{try{await navigator.clipboard.writeText(E),z("success","Copied","Full path copied")}catch{z("error","Copy Failed","Could not copy path")}},[z]),A=t.useCallback(async E=>{const L=o&&E.startsWith(o+"/")?E.slice(o.length+1):E;try{await navigator.clipboard.writeText(L),z("success","Copied","Relative path copied")}catch{z("error","Copy Failed","Could not copy path")}},[o,z]),S=t.useMemo(()=>{if(!I)return[];const{file:E,status:L}=I,B=[];return L==="conflict"&&w?B.push({id:"open-conflict",label:g("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>w(E.path)}):L!=="deleted"&&B.push({id:"open-file",label:g("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>l(E.path,L)}),L!=="conflict"&&B.push({id:"stage-file",label:g("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i([E.path])}}),B.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(L==="modified"||L==="deleted"||L==="renamed"||L==="conflict")&&B.push({id:"discard-changes",label:g("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{ae(E,L)}}),(L==="untracked"||L==="added")&&B.push({id:"delete-file",label:g("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{ae(E,L)}}),B.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),B.push({id:"copy-full-path",label:g("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{ce(E.path)}}),B.push({id:"copy-relative-path",label:g("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{A(E.path)}}),R&&L!=="deleted"&&B.push({id:"reveal-in-tree",label:g("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>R(E.path)}),B},[I,l,i,w,R,ae,ce,A,g]),q=t.useCallback((E,L)=>{E.preventDefault(),E.stopPropagation(),ee({isOpen:!0,position:{x:E.clientX,y:E.clientY},node:L})},[]),Z=t.useCallback(E=>!E.isDirectory&&E.file?[E.file]:E.children.flatMap(L=>Z(L)),[]),Te=t.useCallback(async E=>{if(!o)return;const L=Z(E);if(L.length!==0)try{const B=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:L.map(ye=>({path:ye.path,status:ye.status})),directory:o})}),pe=await B.json();B.ok&&pe.success?(z("success","Discarded",`Reverted ${L.length} file(s) in ${E.name}`),r()):z("error","Discard Failed",pe.error||"Could not discard changes")}catch{z("error","Discard Failed","Network error")}},[o,Z,r,z]),ve=t.useMemo(()=>{if(!P)return[];const{node:E}=P,L=Z(E);return[{id:"discard-dir",label:`Discard Changes (${L.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{Te(E)}},{id:"stage-dir",label:`Stage All (${L.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i(L.map(B=>B.path))}}]},[P,Z,Te,i]),X=t.useCallback(E=>{C(L=>{const B=new Set(L);return B.has(E)?B.delete(E):B.add(E),B})},[]),{conflictFiles:xe,conflictTree:ze,changesFiles:Le,changesTree:bt,untrackedFiles:de,untrackedTree:ue,allDirPaths:Ee}=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(De=>De.status==="conflict"),B=Lt(L);$t(B,E);const pe=s.files.filter(De=>De.status==="modified"||De.status==="added"||De.status==="deleted"||De.status==="renamed"),ye=Lt(pe);$t(ye,E);const Je=s.files.filter(De=>De.status==="untracked"),$e=Lt(Je);return $t($e,E),{conflictFiles:L,conflictTree:B,changesFiles:pe,changesTree:ye,untrackedFiles:Je,untrackedTree:$e,allDirPaths:E}},[s]);t.useEffect(()=>{C(Ee)},[Ee]),t.useEffect(()=>{s!=null&&s.files&&T(new Set(s.files.map(E=>E.path)))},[s==null?void 0:s.files]);const we=t.useCallback(()=>{Le.length!==0&&ge({files:Le,label:`${Le.length} changed files`})},[Le]),Ke=t.useCallback(()=>{de.length!==0&&ge({files:de,label:`${de.length} unversioned files`})},[de]),Oe=t.useCallback(()=>{xe.length!==0&&ge({files:xe,label:`${xe.length} conflicted files`})},[xe]),jt=xe.length>0;t.useEffect(()=>{if(ne){const E=ne.type==="error"?8e3:4e3,L=setTimeout(()=>ie(null),E);return()=>clearTimeout(L)}},[ne]);const We=t.useCallback(async()=>{const E=!O;if(se(E),E&&o){_(D);try{const B=await(await W(V(`/api/files/git-log-message?path=${encodeURIComponent(o)}`))).json();B.message&&N(B.message)}catch{}}else N(U)},[O,o,D,U]),ut=t.useCallback(E=>{T(L=>{const B=new Set(L);return B.has(E)?B.delete(E):B.add(E),B})},[]),qe=t.useCallback(()=>{if(!(s!=null&&s.files))return;const E=s.files.map(B=>B.path),L=E.every(B=>Q.has(B));T(L?new Set:new Set(E))},[s==null?void 0:s.files,Q]),Ye=t.useCallback(async E=>{if(!(!o||!D.trim()||Q.size===0||F)){K(!0),ie(null);try{const L=await W(V("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o,message:D.trim(),amend:O,paths:Array.from(Q)})}),B=await L.json();if(!L.ok||!B.success){ie({type:"error",text:B.error||"Commit failed"}),K(!1);return}if(E)try{const pe=await W(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o})}),ye=await pe.json();pe.ok&&ye.success?ie({type:"success",text:g("terminal:fileExplorer.committedAndPushed")}):ie({type:"error",text:g("terminal:fileExplorer.committedButPushFailed",{error:ye.error||"Unknown error"})})}catch{ie({type:"error",text:g("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else ie({type:"success",text:g("terminal:fileExplorer.committedSuccessfully")});N(""),_(""),se(!1),r(),h==null||h()}catch(L){ie({type:"error",text:L.message||"Commit failed"})}finally{K(!1)}}},[o,D,O,Q,F,r,h]);if(n)return e.jsx("div",{className:"git-changes-loading",children:g("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:g("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:g("terminal:fileExplorer.workingTreeClean")}),e.jsx("div",{className:"git-empty-branch",children:g("terminal:fileExplorer.onBranch",{branch:s.branch})})]});const ht=E=>{i([E])},vt=()=>{const E=de.map(L=>L.path);E.length>0&&i(E)},Ce=(E,L)=>{L==="conflict"&&w?w(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:()=>x("flat"),title:g("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:()=>x("tree"),title:g("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:r,title:g("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:g("terminal:fileExplorer.mergeInProgress",{branch:j?` (${j})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:f,disabled:jt,title:g(jt?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:g("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:b,title:g("terminal:fileExplorer.abortMerge"),children:g("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(Qt,{groupLabel:g("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:xe,treeNodes:ze,viewMode:k,selectedPath:d,expandedDirs:v,onToggleDir:X,onFileSelect:Ce,checkedFiles:Q,onToggleCheck:ut,onContextMenu:G,onDirContextMenu:q,onDiscardFile:je,onDiscardAll:Oe}),e.jsx(Qt,{groupLabel:g("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:Le,treeNodes:bt,viewMode:k,selectedPath:d,expandedDirs:v,onToggleDir:X,onFileSelect:Ce,checkedFiles:Q,onToggleCheck:ut,onContextMenu:G,onDirContextMenu:q,onDiscardFile:je,onDiscardAll:we}),e.jsx(Qt,{groupLabel:g("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:de,treeNodes:ue,viewMode:k,selectedPath:d,expandedDirs:v,onToggleDir:X,onFileSelect:Ce,onStageFile:ht,onStageAll:vt,stagingPaths:m,checkedFiles:Q,onToggleCheck:ut,onContextMenu:G,onDirContextMenu:q,onDiscardFile:je,onDiscardAll:Ke})]}),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:We}),g("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:g("terminal:fileExplorer.fileCount",{count:Q.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:qe,title:Q.size===s.files.length?g("terminal:fileExplorer.deselectAll"):g("terminal:fileExplorer.selectAll"),children:Q.size===s.files.length?g("terminal:fileExplorer.deselectAll"):g("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:fe,className:"git-commit-message",placeholder:g("terminal:fileExplorer.commitMessagePlaceholder"),value:D,onChange:E=>N(E.target.value),onKeyDown:E=>{(E.metaKey||E.ctrlKey)&&E.key==="Enter"&&(E.preventDefault(),Ye(!1)),(E.metaKey||E.ctrlKey)&&E.shiftKey&&E.key==="Enter"&&(E.preventDefault(),Ye(!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:()=>Ye(!1),disabled:!D.trim()||Q.size===0||F,title:g("terminal:fileExplorer.commitCtrlEnter"),children:g(F?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>Ye(!0),disabled:!D.trim()||Q.size===0||F,title:g("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:F?"...":g("terminal:fileExplorer.commitAndPush")})]})]}),I&&e.jsx(ct,{isOpen:I.isOpen,position:I.position,worldPosition:{x:0,z:0},actions:S,onClose:()=>$(null)}),P&&e.jsx(ct,{isOpen:P.isOpen,position:P.position,worldPosition:{x:0,z:0},actions:ve,onClose:()=>ee(null)}),te&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>ge(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:E=>E.stopPropagation(),children:[e.jsx("p",{children:te.files.some(E=>E.status==="untracked"||E.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:te.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:te.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:()=>ge(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:c,children:te.files.some(E=>E.status==="untracked"||E.status==="added")?"Delete":"Discard"})]})]})})]})}const tn=t.memo(Za,(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));tn.displayName="GitChanges";const er=t.memo(function({tab:n,isActive:l,onSelect:d,onClose:r,onContextMenu:i}){const{t:m}=re(["terminal"]),o={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},h=t.useCallback(()=>{d(n.path)},[d,n.path]),p=t.useCallback(b=>{b.button===1&&(b.preventDefault(),b.stopPropagation(),r(n.path))},[r,n.path]),j=t.useCallback(b=>{b.preventDefault(),b.stopPropagation(),r(n.path)},[r,n.path]),f=t.useCallback(b=>{b.preventDefault(),b.stopPropagation(),i(b,n)},[i,n]);return e.jsxs("div",{className:`file-tab ${l?"active":""}`,onClick:h,onMouseDown:p,onContextMenu:f,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:es(o),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:j,title:m("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function tr(s){return typeof s.path=="string"&&s.path.startsWith("/")}function sr({tabs:s,activeTabPath:n,onSelectTab:l,onCloseTab:d,onCloseAllTabs:r,onShowGitHistory:i}){const{t:m}=re(["terminal"]),[o,h]=t.useState(null),p=t.useCallback((b,w)=>{h({isOpen:!0,position:{x:b.clientX,y:b.clientY},tab:w})},[]),j=t.useCallback(()=>h(null),[]),f=t.useMemo(()=>{if(!o)return[];const b=o.tab,w=!!i&&tr(b),R=[{id:"git-history",label:m("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!w,onClick:()=>{w&&i(b.path)}}];return r&&R.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:m("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(M,{name:"cross",size:14}),danger:!0,onClick:()=>r()}),R},[o,i,r,m]);return s.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:s.map(b=>e.jsx(er,{tab:b,isActive:n===b.path,onSelect:l,onClose:d,onContextMenu:p},b.path))}),o&&e.jsx(ct,{isOpen:o.isOpen,position:o.position,worldPosition:{x:0,z:0},actions:f,onClose:j})]})}const sn=t.memo(sr,(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});sn.displayName="FileTabs";const nr=t.memo(function({currentFolder:n,gitStatus:l,onBranchChanged:d,onMerge:r,onCompare:i,onPullConflicts:m}){const{t:o}=re(["terminal","common"]),[h,p]=t.useState(!1),[j,f]=t.useState(""),[b,w]=t.useState(!1),[R,g]=t.useState(""),[k,x]=t.useState(!1),[v,C]=t.useState(null),[D,N]=t.useState(null),U=t.useRef(null),_=t.useRef(null),O=t.useRef(null),{branches:se,loading:Q,operationInProgress:T,loadBranches:F,checkoutBranch:K,createBranch:ne,pullFromRemote:ie,pushToRemote:fe}=ts();t.useEffect(()=>{h&&n&&(F(n),setTimeout(()=>{var S;return(S=_.current)==null?void 0:S.focus()},50)),h||(f(""),w(!1),g(""),C(null))},[h,n,F]),t.useEffect(()=>{if(v){const S=v.type==="error"?8e3:3e3,q=setTimeout(()=>C(null),S);return()=>clearTimeout(q)}},[v]),t.useEffect(()=>{b&&setTimeout(()=>{var S;return(S=O.current)==null?void 0:S.focus()},50)},[b]),t.useEffect(()=>{if(!h)return;const S=Z=>{const Te=Z.target;!Te.closest(".branch-widget-selector")&&!Te.closest(".branch-widget-dropdown")&&p(!1)},q=Z=>{Z.key==="Escape"&&(Z.preventDefault(),Z.stopPropagation(),p(!1))};return document.addEventListener("click",S),document.addEventListener("keydown",q,!0),()=>{document.removeEventListener("click",S),document.removeEventListener("keydown",q,!0)}},[h]);const z=t.useCallback(async S=>{if(!n||T||S.isCurrent)return;const q=await K(n,S.name);q.success?(C({type:"success",text:o("terminal:fileExplorer.switchedToBranch",{branch:q.branch||S.name})}),d(),F(n)):C({type:"error",text:q.error||o("terminal:fileExplorer.checkoutFailed")})},[n,T,K,d,F]),I=t.useCallback(async()=>{if(!n||!R.trim()||T)return;const S=await ne(n,R.trim());S.success?(C({type:"success",text:o("terminal:fileExplorer.createdBranch",{branch:S.branch})}),w(!1),g(""),d(),F(n)):C({type:"error",text:S.error||o("terminal:fileExplorer.createBranchFailed")})},[n,R,T,ne,d,F]),$=t.useCallback(async()=>{if(!n||T)return;const S=await ie(n);S.success?(S.stashConflicts&&S.stashConflicts.length>0?(C({type:"error",text:`Pull succeeded but stash pop had conflicts: ${S.stashConflicts.length} file(s). Resolve manually.`}),m==null||m(S.stashConflicts),p(!1)):S.stashed?C({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):C({type:"success",text:o("terminal:fileExplorer.pullComplete")}),d(),F(n)):S.conflicts&&S.conflicts.length>0?(C({type:"error",text:`Pull conflicts: ${S.conflicts.length} file(s)`}),m==null||m(S.conflicts),p(!1)):C({type:"error",text:S.error||o("terminal:fileExplorer.pullFailed")})},[n,T,ie,d,F,m]),P=t.useCallback(async()=>{if(!n||T)return;const S=await fe(n);S.success?C({type:"success",text:o("terminal:fileExplorer.pushComplete")}):C({type:"error",text:S.error||o("terminal:fileExplorer.pushFailed")})},[n,T,fe]),[ee,te]=t.useState(!1),ge=t.useCallback(async()=>{if(!(!n||T||ee)){te(!0);try{const S=await W(V("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(S.ok)C({type:"success",text:"Fetch complete"}),d(),F(n);else{const q=await S.json().catch(()=>({error:"Fetch failed"}));C({type:"error",text:q.error||"Fetch failed"})}}catch{C({type:"error",text:"Fetch failed"})}finally{te(!1)}}},[n,T,ee,d,F]),je=(l==null?void 0:l.branch)||"unknown",c=!!T,G=t.useCallback((S,q)=>{q.isCurrent||(S.preventDefault(),S.stopPropagation(),N({isOpen:!0,position:{x:S.clientX,y:S.clientY},branch:q.name}))},[]),ae=t.useMemo(()=>{if(!D)return[];const S=!!T||(l==null?void 0:l.mergeInProgress);return[{id:"compare",label:o("terminal:fileExplorer.showDiffWith",{branch:D.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!T,onClick:()=>{i==null||i(D.branch),p(!1)}},{id:"merge",label:o("terminal:fileExplorer.mergeInto",{source:D.branch,target:je}),icon:"⤵",disabled:!!S,onClick:()=>{r&&r(D.branch),p(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:o("terminal:fileExplorer.checkoutBranch",{branch:D.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!T,onClick:()=>{const q=se.find(Z=>Z.name===D.branch);q&&z(q)}}]},[D,T,l==null?void 0:l.mergeInProgress,je,r,i,se,z]),ce=t.useMemo(()=>{const S=se.filter(Z=>!Z.isRemote);if(!j)return S;const q=j.toLowerCase();return S.filter(Z=>Z.name.toLowerCase().includes(q))},[se,j]),A=t.useMemo(()=>{const S=se.filter(Z=>Z.isRemote);if(!j)return S;const q=j.toLowerCase();return S.filter(Z=>Z.name.toLowerCase().includes(q))},[se,j]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:S=>{S.stopPropagation(),p(!h)},title:`Branch: ${je}`,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:je}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),h&&e.jsxs("div",{className:"branch-widget-dropdown",ref:U,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:_,type:"text",className:"branch-widget-search-input",placeholder:o("terminal:fileExplorer.searchBranches"),value:j,onChange:S=>f(S.target.value),onKeyDown:S=>S.stopPropagation()})}),v&&e.jsx("div",{className:`branch-widget-status ${v.type}`,children:v.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 ${c||ee?"disabled":""}`,onClick:ge,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:ee?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${c?"disabled":""}`,onClick:$,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(T==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),e.jsxs("div",{className:`branch-widget-action-item ${c?"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 4l4 4h-2.5v5h-3V8H4l4-4z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(T==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${c?"disabled":""}`,onClick:()=>{c||w(!b)},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")})]})]}),b&&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=>g(S.target.value),onKeyDown:S=>{S.stopPropagation(),S.key==="Enter"&&I(),S.key==="Escape"&&(w(!1),g(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:I,disabled:!R.trim()||c,children:T==="create"?"...":o("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[o("terminal:fileExplorer.localBranches"),Q&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",o("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[ce.length===0&&!Q&&e.jsx("div",{className:"branch-widget-empty",children:o("terminal:fileExplorer.noBranchesFound")}),ce.map(S=>e.jsxs("div",{className:`branch-widget-branch-item ${S.isCurrent?"current":""} ${c?"disabled":""}`,onClick:()=>z(S),onContextMenu:q=>G(q,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))]}),A.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>x(!k),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:k?"▾":"▸"}),o("terminal:fileExplorer.remoteBranches",{count:A.length})]}),k&&e.jsx("div",{className:"branch-widget-branch-list",children:A.map(S=>e.jsxs("div",{className:`branch-widget-branch-item remote ${c?"disabled":""}`,onClick:()=>z(S),onContextMenu:q=>G(q,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))})]})]}),D&&e.jsx(ct,{isOpen:D.isOpen,position:D.position,worldPosition:{x:0,z:0},actions:ae,onClose:()=>N(null)})]})});function ar(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function It(s,n){if(!s)return"";const l=Is.languages[n];return l?Is.highlight(s,l,n):ar(s)}function rr(s){const n=[],l=s.split(`
|
|
9
|
+
`);let d=[],r=!1,i=[],m=[],o=!1;for(const h of l)h.startsWith("<<<<<<<")?(d.length>0&&(n.push({type:"unchanged",content:d.join(`
|
|
10
|
+
`)}),d=[]),r=!0,o=!1,i=[],m=[]):h.startsWith("=======")&&r?o=!0:h.startsWith(">>>>>>>")&&r?(n.push({type:"conflict",ours:i.join(`
|
|
11
|
+
`),theirs:m.join(`
|
|
12
|
+
`),resolved:null}),r=!1,o=!1):r?o?m.push(h):i.push(h):d.push(h);return d.length>0&&n.push({type:"unchanged",content:d.join(`
|
|
13
|
+
`)}),n}const ir=t.memo(function({file:n,versions:l,loading:d,onResolve:r,onClose:i,currentBranch:m,mergingBranch:o}){const{t:h}=re(["terminal"]),p=t.useMemo(()=>{var F;if(!(l!=null&&l.filename))return"plaintext";const T="."+((F=l.filename.split(".").pop())==null?void 0:F.toLowerCase());return zt(T)},[l==null?void 0:l.filename]),j=t.useMemo(()=>l!=null&&l.merged?rr(l.merged):[],[l==null?void 0:l.merged]),[f,b]=t.useState(j),[w,R]=t.useState(!1);t.useMemo(()=>{b(j)},[j]);const g=t.useRef(null),[k,x]=t.useState(0),v=t.useMemo(()=>f.map((T,F)=>T.type==="conflict"?F:-1).filter(T=>T!==-1),[f]),C=v.length,D=t.useCallback(T=>{const F=g.current;if(!F||T<0||T>=v.length)return;const K=v[T],ne=F.querySelector(`[data-section-idx="${K}"]`);ne&&(ne.scrollIntoView({behavior:"smooth",block:"center"}),x(T))},[v]),N=t.useCallback(()=>{D(k>0?k-1:v.length-1)},[k,v.length,D]),U=t.useCallback(()=>{D(k<v.length-1?k+1:0)},[k,v.length,D]);t.useEffect(()=>{if(v.length>0&&g.current){const T=setTimeout(()=>D(0),100);return()=>clearTimeout(T)}},[v.length,D]);const _=t.useMemo(()=>{const T=f.filter(F=>F.type==="conflict");return T.length>0&&T.every(F=>F.resolved!==null)},[f]),O=t.useCallback((T,F)=>{b(K=>K.map((ne,ie)=>ie!==T||ne.type!=="conflict"?ne:{...ne,resolved:F}))},[]),se=t.useCallback(T=>{b(F=>F.map(K=>K.type!=="conflict"?K:{...K,resolved:T}))},[]),Q=t.useCallback(async()=>{R(!0);try{const T=f.map(F=>F.type==="unchanged"?F.content:F.resolved==="ours"?F.ours:F.resolved==="theirs"?F.theirs:F.resolved==="both"?F.ours+`
|
|
14
|
+
`+F.theirs:`<<<<<<< ${m}
|
|
15
|
+
${F.ours}
|
|
16
|
+
=======
|
|
17
|
+
${F.theirs}
|
|
18
|
+
>>>>>>> ${o}`).join(`
|
|
19
|
+
`);await r(T)}finally{R(!1)}},[f,r,m,o]);return e.jsxs("div",{className:"conflict-resolver",children:[e.jsxs("div",{className:"conflict-header",children:[e.jsx("span",{className:"conflict-header-title",children:h("terminal:fileExplorer.resolveFile",{filename:l==null?void 0:l.filename})}),C>0&&e.jsxs("div",{className:"conflict-nav",children:[e.jsx("button",{className:"conflict-nav-btn",onClick:N,title:h("terminal:fileExplorer.prevConflict"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsxs("span",{className:"conflict-nav-counter",children:[k+1," / ",C]}),e.jsx("button",{className:"conflict-nav-btn",onClick:U,title:h("terminal:fileExplorer.nextConflict"),children:e.jsx(M,{name:"caret-down",size:10})})]}),e.jsx("button",{className:"conflict-close-btn",onClick:i,children:"×"})]}),d||!l?e.jsx("div",{className:"conflict-loading",children:h("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:h("terminal:fileExplorer.currentBranchLabel",{branch:m})}),e.jsx("div",{className:"conflict-pane-header incoming",children:h("terminal:fileExplorer.incomingBranchLabel",{branch:o})})]}),e.jsx("div",{className:"conflict-content",ref:g,children:f.map((T,F)=>T.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(T.content,p)}})}),e.jsx("div",{className:"conflict-pane theirs",children:e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(T.content,p)}})})]})},F):e.jsxs("div",{"data-section-idx":F,className:`conflict-section-conflict ${T.resolved?"resolved":""}`,children:[e.jsxs("div",{className:"conflict-panes",children:[e.jsxs("div",{className:`conflict-pane ours ${T.resolved==="ours"||T.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(T.ours,p)}}),e.jsx("button",{className:"conflict-accept-btn ours",onClick:()=>O(F,"ours"),disabled:T.resolved==="ours",children:T.resolved==="ours"?h("terminal:fileExplorer.accepted"):h("terminal:fileExplorer.acceptCurrent")})]}),e.jsxs("div",{className:`conflict-pane theirs ${T.resolved==="theirs"||T.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:It(T.theirs,p)}}),e.jsx("button",{className:"conflict-accept-btn theirs",onClick:()=>O(F,"theirs"),disabled:T.resolved==="theirs",children:T.resolved==="theirs"?h("terminal:fileExplorer.accepted"):h("terminal:fileExplorer.acceptIncoming")})]})]}),e.jsx("button",{className:`conflict-accept-both-btn ${T.resolved==="both"?"accepted":""}`,onClick:()=>O(F,"both"),disabled:T.resolved==="both",children:T.resolved==="both"?h("terminal:fileExplorer.accepted"):h("terminal:fileExplorer.acceptBoth")})]},F))}),e.jsxs("div",{className:"conflict-actions",children:[e.jsx("button",{className:"conflict-action-btn accept-all-current",onClick:()=>se("ours"),children:h("terminal:fileExplorer.acceptAllCurrent")}),e.jsx("button",{className:"conflict-action-btn accept-all-incoming",onClick:()=>se("theirs"),children:h("terminal:fileExplorer.acceptAllIncoming")}),e.jsx("button",{className:"conflict-action-btn accept-all-both",onClick:()=>se("both"),children:h("terminal:fileExplorer.acceptAllBoth")}),e.jsx("button",{className:"conflict-action-btn save-resolved",onClick:Q,disabled:!_||w,children:h(w?"terminal:fileExplorer.saving":"terminal:fileExplorer.saveAndResolve")})]})]})]})}),lr=16,or=t.memo(function s({node:n,depth:l,expandedDirs:d,onToggleDir:r,selectedPath:i,onSelect:m}){const{t:o}=re(["terminal"]),h=l*lr;if(!n.isDirectory){const j=n.file.status,f=yt[j],b=j==="deleted",w=n.file.name.includes(".")?"."+n.file.name.split(".").pop():"";return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>!b&&m(n.file.path,j),style:{paddingLeft:`${h+4}px`,cursor:b?"not-allowed":"pointer"},title:n.file.path,children:[e.jsx("span",{className:"tree-arrow-spacer"}),e.jsx("img",{className:"tree-icon",src:xt(w),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=d.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${p?"expanded":""}`,style:{paddingLeft:`${h+4}px`},onClick:()=>r(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(j=>e.jsx(s,{node:j,depth:l+1,expandedDirs:d,onToggleDir:r,selectedPath:i,onSelect:m},j.path))})]})}),cr=t.memo(function({file:n,isSelected:l,onSelect:d}){const r=yt[n.status],i=n.status==="deleted",m=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:()=>!i&&d(n.path,n.status),style:{cursor:i?"not-allowed":"pointer"},title:n.path,children:[e.jsx("span",{className:"tree-arrow-spacer"}),e.jsx("img",{className:"tree-icon",src:xt(m),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:r.color},children:r.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:["← ",n.oldPath.split("/").pop()]})]})});function dr({compareResult:s,loading:n,onFileSelect:l,selectedPath:d,onClose:r}){const{t:i}=re(["terminal"]),[m,o]=t.useState("tree"),[h,p]=t.useState(new Set),j=t.useMemo(()=>!s||s.files.length===0?[]:Lt(s.files),[s]),f=t.useMemo(()=>{const C=new Set;return $t(j,C),C},[j]);t.useEffect(()=>{p(f)},[f]);const b=t.useCallback(C=>{p(D=>{const N=new Set(D);return N.has(C)?N.delete(C):N.add(C),N})},[]),w=t.useMemo(()=>s?[...s.files].sort((C,D)=>C.path.toLowerCase().localeCompare(D.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:i("terminal:fileExplorer.comparingBranches")}),e.jsx("button",{className:"branch-comparison-close",onClick:r,title:i("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsx("div",{className:"branch-comparison-empty",children:e.jsx("div",{className:"branch-comparison-empty-text",children:i("terminal:fileExplorer.comparingBranches")})})]});if(!s)return null;const{files:R,counts:g,baseBranch:k,currentBranch:x}=s,v=R.length;return v===0?e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsxs("span",{className:"branch-comparison-title",children:[x," vs ",k]}),e.jsx("button",{className:"branch-comparison-close",onClick:r,title:i("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:i("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:["⇔ ",x," vs ",k]}),e.jsx("span",{className:"branch-comparison-file-count",children:i("terminal:fileExplorer.fileCount",{count:v})}),e.jsxs("div",{className:"git-changes-summary",children:[g.modified>0&&e.jsxs("span",{className:"git-count modified",children:[g.modified,"M"]}),g.added>0&&e.jsxs("span",{className:"git-count added",children:[g.added,"A"]}),g.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[g.deleted,"D"]}),g.renamed>0&&e.jsxs("span",{className:"git-count renamed",children:[g.renamed,"R"]}),(g.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[g.conflict,"C"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${m==="flat"?"active":""}`,onClick:()=>o("flat"),title:i("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 ${m==="tree"?"active":""}`,onClick:()=>o("tree"),title:i("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:r,title:i("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsx("div",{className:"branch-comparison-list",children:m==="tree"?j.map(C=>e.jsx(or,{node:C,depth:0,expandedDirs:h,onToggleDir:b,selectedPath:d,onSelect:l},C.path)):w.map(C=>e.jsx(cr,{file:C,isSelected:d===C.path,onSelect:l},C.path))})]})}const nn=t.memo(dr);nn.displayName="BranchComparison";function ur(s){const n=new Date(s);if(isNaN(n.getTime()))return s||"—";const d=Date.now()-n.getTime(),r=Math.floor(d/6e4),i=Math.floor(r/60),m=Math.floor(i/24);if(m<4)return r<1?"just now":r<60?`${r}m ago`:i<24?`${i}h ago`:`${m}d ago`;const o=n.getFullYear(),h=String(n.getMonth()+1).padStart(2,"0"),p=String(n.getDate()).padStart(2,"0"),j=String(n.getHours()).padStart(2,"0"),f=String(n.getMinutes()).padStart(2,"0");return`${o}-${h}-${p} ${j}:${f}`}const hr=t.memo(function({commit:n,isSelected:l,onSelect:d}){return e.jsxs("div",{className:`gh-row ${l?"selected":""}`,onClick:()=>d(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(r=>e.jsx("span",{className:"gh-badge gh-badge-branch",children:r},r)),n.refs.tags.map(r=>e.jsx("span",{className:"gh-badge gh-badge-tag",children:r},r))]}),e.jsx("span",{className:"gh-col-author",children:n.author}),e.jsx("span",{className:"gh-col-date",children:ur(n.date)})]})}),mr=t.memo(function({files:n,loading:l,selectedFilePath:d,onSelectFile:r}){const{t:i}=re(["common"]);return l?e.jsx("div",{className:"gh-files-loading",children:i("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(m=>{const o=m.path.split("/").pop()||m.path,h=m.path.includes("/")?m.path.substring(0,m.path.lastIndexOf("/")):"",p=yt[m.status],j=o.includes(".")?"."+o.split(".").pop():"";return e.jsxs("div",{className:`gh-file-row ${d===m.path?"selected":""}`,onClick:()=>r==null?void 0:r(m.path),title:m.path,children:[e.jsx("span",{className:"gh-file-status",style:{color:p.color},children:p.icon}),e.jsx("img",{className:"gh-file-icon",src:xt(j),alt:""}),e.jsx("span",{className:"gh-file-name",children:o}),h&&e.jsx("span",{className:"gh-file-dir",children:h})]},m.path)})})}),fr=t.memo(function({history:n,currentFolder:l,onFileSelect:d}){const{t:r}=re(["terminal","common"]),i=t.useRef(null),[m,o]=t.useState(null),[h,p]=t.useState(!1),{commits:j,loading:f,loadingMore:b,error:w,hasMore:R,total:g,filters:k,setFilter:x,resetFilters:v,selectedCommit:C,selectCommit:D,commitFiles:N,commitFilesLoading:U,loadHistory:_,loadMore:O,authors:se,loadAuthors:Q}=n,{branches:T,loadBranches:F}=ts();t.useEffect(()=>{l&&(_(l),Q(l),F(l))},[l,_,Q,F]);const K=qn({count:j.length,getScrollElement:()=>i.current,estimateSize:()=>28,overscan:20}),ne=t.useCallback(()=>{const $=i.current;if(!$||b||!R||!l)return;const{scrollTop:P,scrollHeight:ee,clientHeight:te}=$;ee-P-te<200&&O(l)},[b,R,l,O]),ie=t.useCallback($=>{o($),d&&C&&d($,C.hash)},[d,C]),fe=t.useMemo(()=>T.filter($=>!$.isRemote).map($=>$.name),[T]),z=!!(k.branch||k.author||k.since||k.until||k.searchPath||k.search),I=K.getVirtualItems();return e.jsxs("div",{className:"gh-panel",children:[e.jsxs("div",{className:"gh-toolbar",children:[e.jsx("span",{className:"gh-toolbar-title",children:r("terminal:fileExplorer.gitHistory.title")}),e.jsx("span",{className:"gh-toolbar-count",children:f?"...":g>0?g:j.length}),e.jsx("input",{type:"text",className:"gh-search-input",placeholder:r("terminal:fileExplorer.gitHistory.searchPlaceholder"),value:k.search,onChange:$=>x("search",$.target.value)}),e.jsx("button",{className:`gh-filter-toggle ${h?"active":""} ${z?"has-filters":""}`,onClick:()=>p(!h),title:"Filters",children:e.jsx(M,{name:"gear",size:12})}),z&&e.jsx("button",{className:"gh-reset-btn",onClick:v,children:r("terminal:fileExplorer.gitHistory.resetFilters")})]}),h&&e.jsxs("div",{className:"gh-filters-row",children:[e.jsxs("select",{className:"gh-filter-select",value:k.branch,onChange:$=>x("branch",$.target.value),children:[e.jsx("option",{value:"",children:r("terminal:fileExplorer.gitHistory.allBranches")}),fe.map($=>e.jsx("option",{value:$,children:$},$))]}),e.jsxs("select",{className:"gh-filter-select",value:k.author,onChange:$=>x("author",$.target.value),children:[e.jsx("option",{value:"",children:r("terminal:fileExplorer.gitHistory.allAuthors")}),se.map($=>e.jsx("option",{value:$,children:$},$))]}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.since,onChange:$=>x("since",$.target.value),title:r("terminal:fileExplorer.gitHistory.since")}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.until,onChange:$=>x("until",$.target.value),title:r("terminal:fileExplorer.gitHistory.until")}),e.jsx("input",{type:"text",className:"gh-filter-input",placeholder:r("terminal:fileExplorer.gitHistory.pathFilter"),value:k.searchPath,onChange:$=>x("searchPath",$.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&&j.length===0?e.jsx("div",{className:"gh-state-msg",children:r("common:status.loading")}):w?e.jsx("div",{className:"gh-state-msg gh-error",children:w}):j.length===0?e.jsx("div",{className:"gh-state-msg",children:r("terminal:fileExplorer.gitHistory.noCommits")}):e.jsxs("div",{className:"gh-commit-scroll",ref:i,onScroll:ne,children:[e.jsx("div",{style:{height:`${K.getTotalSize()}px`,width:"100%",position:"relative"},children:I.map($=>e.jsx("div",{"data-index":$.index,ref:K.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${$.start}px)`},children:e.jsx(hr,{commit:j[$.index],isSelected:(C==null?void 0:C.hash)===j[$.index].hash,onSelect:D})},$.key))}),b&&e.jsx("div",{className:"gh-loading-more",children:r("common:status.loading")})]})]}),C&&e.jsxs("div",{className:"gh-files-section",children:[e.jsxs("div",{className:"gh-files-header",children:[e.jsxs("span",{className:"gh-files-title",children:[N.length," ",N.length===1?"file":"files"]}),e.jsx("span",{className:"gh-files-commit-info",children:C.shortHash})]}),e.jsx(mr,{files:N,loading:U,selectedFilePath:m,onSelectFile:ie})]})]})]})});async function pr({path:s,cwd:n,limit:l}){const d=new URLSearchParams({path:s,cwd:n});Number.isFinite(l)&&d.set("limit",String(l));const r=await W(V(`/api/files/git-file-history?${d.toString()}`));if(!r.ok){const m=await r.json().catch(()=>({}));throw new Error(m.error||`Failed to load file git history: ${r.statusText}`)}const i=await r.json();return{commits:Array.isArray(i.commits)?i.commits:[]}}async function gr({path:s,cwd:n,sha:l}){const d=new URLSearchParams({path:s,cwd:n,sha:l}),r=await W(V(`/api/files/git-file-commit-diff?${d.toString()}`));if(!r.ok){const m=await r.json().catch(()=>({}));throw new Error(m.error||`Failed to load commit diff: ${r.statusText}`)}const i=await r.json();return i.binary===!0?{binary:!0,filename:i.filename??"",changeType:i.changeType??"modified"}:{binary:!1,filename:i.filename??"",language:i.language??"plaintext",changeType:i.changeType??"modified",originalContent:typeof i.originalContent=="string"?i.originalContent:"",modifiedContent:typeof i.modifiedContent=="string"?i.modifiedContent:""}}const xr=100;function yr(s){if(!s)return"";const n=Date.parse(s);if(Number.isNaN(n))return s;const l=Date.now()-n,d=Math.round(l/1e3);if(d<60)return`${d}s ago`;const r=Math.round(d/60);if(r<60)return`${r}m ago`;const i=Math.round(r/60);if(i<24)return`${i}h ago`;const m=Math.round(i/24);if(m<30)return`${m}d ago`;const o=Math.round(m/30);return o<12?`${o}mo ago`:`${Math.round(o/12)}y ago`}function br(s){if(!s)return"";const n=s.lastIndexOf("/");return n>=0?s.slice(n+1):s}function jr({isOpen:s,onClose:n,filePath:l,cwd:d}){const{t:r}=re(["terminal","common"]),[i,m]=t.useState([]),[o,h]=t.useState(!1),[p,j]=t.useState(null),[f,b]=t.useState(null),[w,R]=t.useState(null),[g,k]=t.useState(!1),[x,v]=t.useState(null);t.useEffect(()=>{if(!s)return;let U=!1;return m([]),b(null),R(null),v(null),j(null),h(!0),(async()=>{try{const _=await pr({path:l,cwd:d,limit:xr});if(U)return;m(_.commits),_.commits.length>0&&b(_.commits[0].sha)}catch(_){if(U)return;j(_ instanceof Error?_.message:r("terminal:fileGitHistory.error"))}finally{U||h(!1)}})(),()=>{U=!0}},[s,l,d,r]),t.useEffect(()=>{if(!s||!f){R(null);return}let U=!1;return k(!0),v(null),R(null),(async()=>{try{const _=await gr({path:l,cwd:d,sha:f});if(U)return;R(_)}catch(_){if(U)return;v(_ instanceof Error?_.message:r("terminal:fileGitHistory.error"))}finally{U||k(!1)}})(),()=>{U=!0}},[s,f,l,d,r]);const C=t.useCallback(U=>{U.key==="Escape"&&(U.preventDefault(),n())},[n]),D=t.useMemo(()=>br(l),[l]),N=()=>g?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:r("terminal:fileGitHistory.loading")})]}):x?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:20}),e.jsx("p",{children:x})]}):w?w.binary?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"file",size:20}),e.jsx("p",{children:r("terminal:fileGitHistory.binaryFile")})]}):e.jsx(Zt,{originalContent:w.originalContent,modifiedContent:w.modifiedContent,filename:w.filename||D,filePath:l,language:w.language}):e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:r("terminal:fileGitHistory.selectCommit")})});return s?e.jsx(Yn,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"git-file-history-modal",onClick:U=>U.stopPropagation(),onKeyDown:C,tabIndex:-1,children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{className:"git-file-history-title",children:[e.jsx("h2",{children:r("terminal:fileGitHistory.title")}),e.jsx("span",{className:"git-file-history-filepath",title:l,children:D})]}),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":r("terminal:fileGitHistory.title"),children:o?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:r("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})]}):i.length===0?e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:r("terminal:fileGitHistory.empty")})}):e.jsx("ul",{className:"git-file-history-commits",role:"listbox",children:i.map(U=>{const _=U.sha===f;return e.jsxs("li",{className:`git-file-history-commit ${_?"selected":""}`,role:"option","aria-selected":_,onClick:()=>b(U.sha),children:[e.jsxs("div",{className:"git-file-history-commit-row",children:[e.jsx("span",{className:"git-file-history-sha",children:U.shortSha}),e.jsx("span",{className:"git-file-history-date",title:U.date,children:yr(U.date)})]}),e.jsx("div",{className:"git-file-history-subject",title:U.subject,children:U.subject}),e.jsx("div",{className:"git-file-history-author",title:U.email,children:U.author})]},U.sha)})})}),e.jsx("section",{className:"git-file-history-diff","aria-live":"polite",children:N()})]})]})})}):null}function Nr({isOpen:s,areaId:n,onClose:l,onChangeArea:d,folderPath:r}){const{t:i}=re(["terminal","common"]),m=Vs(),o=!!r&&!n,h=!o&&n?m.areas.get(n):null,p=o?[r]:(h==null?void 0:h.directories)||[],j=Array.from(m.areas.values()),[f,b]=t.useState(0),[w,R]=t.useState(null),[g,k]=t.useState(!1),[x,v]=t.useState(""),C=t.useRef(null),D=p[f]||p[0]||null,N=D?D.replace(/\\/g,"/"):null,U=N?Ft(N):"";t.useEffect(()=>{b(0)},[r,o]),t.useEffect(()=>{!o&&r&&R(r)},[o,r]),t.useEffect(()=>{if(s)try{o&&r?localStorage.setItem("file-explorer-last-opened",JSON.stringify({type:"folder",path:r})):n&&localStorage.setItem("file-explorer-last-opened",JSON.stringify({type:"area",areaId:n}))}catch{}},[s,o,r,n]);const _=t.useMemo(()=>{const a=[];for(const u of j)for(const y of u.directories)a.push({path:y,areaId:u.id,areaName:u.name,areaColor:u.color});return a},[j]),O=t.useMemo(()=>{const a=x.trim().toLowerCase();return a?_.filter(u=>{const y=(u.path.split("/").pop()||u.path).toLowerCase();return u.path.toLowerCase().includes(a)||y.includes(a)}):_},[_,x]);t.useEffect(()=>{var a;g?(a=C.current)==null||a.focus():v("")},[g]);const{tree:se,loading:Q,expandedPaths:T,loadTree:F,reloadDirectory:K,renamePathInTree:ne,togglePath:ie,expandToPath:fe,setExpandedPaths:z}=Jn(N),{gitStatus:I,loading:$,loadGitStatus:P}=na(N),{mergeBranch:ee,mergeAbort:te,mergeContinue:ge}=ts(),je=wa(),{showToast:c}=Ys(),{file:G,loading:ae,error:ce,loadFile:A,clearFile:S,setFile:q}=da(),{treePanelWidth:Z,handleResizeStart:Te,isResizing:ve}=pa(),{mobileTreeHeight:X,handleResizeMouseDown:xe,handleResizeTouchStart:ze}=ba(),{loadStoredState:Le,saveState:bt}=fa({areaId:n||null,folderPath:r||null,isOpen:s}),[de,ue]=t.useState(null),[Ee,we]=t.useState("files"),[Ke,Oe]=t.useState(""),[jt,We]=t.useState([]),[ut,qe]=t.useState([]),[Ye,ht]=t.useState(!1),[vt,Ce]=t.useState(null),[E,L]=t.useState(null),[B,pe]=t.useState(!1),[ye,Je]=t.useState(!1),[$e,De]=t.useState(!1),[an,as]=t.useState(new Set),[rs]=t.useState(!1),[Ot,rn]=t.useState(!1),[At,ln]=t.useState(250),mt=t.useRef(null),[He,wt]=t.useState(null),[on,is]=t.useState(!1),[Xe,ls]=t.useState(null),[Qe,os]=t.useState(null),[Ze,cn]=t.useState(null),[Gt,Ut]=t.useState({open:!1,path:"",cwd:""}),[he,Ae]=t.useState({isOpen:!1,node:null,value:"",submitting:!1}),[be,et]=t.useState({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1}),[Se,cs]=t.useState(null),dn=Xn(),Ct=Qn(dn),un=Zn(),[Re,Ge]=t.useState([]),[le,Fe]=t.useState(null),ft=t.useRef([]),tt=t.useRef(-1),Bt=t.useRef(!1),[hn,mn]=t.useState(!1),[fn,pn]=t.useState(!1),[,_t]=t.useState(void 0),[ds,st]=t.useState(null),[pt,gt]=t.useState(null),[gn,nt]=t.useState(null),[xn,us]=t.useState(!1),[Nt,Vt]=t.useState(null),[hs,Kt]=t.useState(!1),[kt,Et]=t.useState(null),ms=t.useRef(null),Wt=t.useRef(null),fs=t.useRef(null),St=t.useRef(null);t.useEffect(()=>{if(!s||ye)return;(async()=>{const u=await Le();if(u){let y=u.selectedFolderIndex;if(w){const H=p.indexOf(w);y=H>=0?H:0,R(null)}else{const H=Math.max(0,p.length-1);y=Math.min(Math.max(0,y),H)}Ge(u.tabs),Fe(u.activeTabPath),we(u.viewMode),b(y),z(u.expandedPaths),St.current=u.expandedPaths,pe(!0),u.activeTabPath&&(ue(u.activeTabPath),A(u.activeTabPath))}Je(!0)})()},[s,ye,Le,z,A,w,p]),t.useEffect(()=>{St.current&&!Q&&se.length>0&&(z(St.current),St.current=null)},[Q,se,z]),t.useEffect(()=>{if(!s||!ye)return;const a=setTimeout(()=>{bt({tabs:Re,activeTabPath:le,viewMode:Ee,selectedFolderIndex:f,expandedPaths:T})},500);return()=>clearTimeout(a)},[s,ye,Re,le,Ee,f,T,bt]),t.useEffect(()=>{Je(!1)},[n,r]),t.useEffect(()=>{if(!he.isOpen)return;const a=window.setTimeout(()=>{var u,y;(u=Wt.current)==null||u.focus(),(y=Wt.current)==null||y.select()},0);return()=>window.clearTimeout(a)},[he.isOpen]),t.useEffect(()=>{if(!be.isOpen)return;const a=window.setTimeout(()=>{var u;(u=fs.current)==null||u.focus()},0);return()=>window.clearTimeout(a)},[be.isOpen]);const Ie=t.useMemo(()=>{const a=Ke.trim(),u=a.match(/^(.+):(\d+)$/);return u?{query:u[1],lineNumber:parseInt(u[2],10)}:{query:a,lineNumber:void 0}},[Ke]);t.useEffect(()=>{if(!Ie.query||!N){We([]),qe([]),ht(!1);return}ht(!0);const a=setTimeout(async()=>{try{const u=Ie.query,y=W(V(`/api/files/search?path=${encodeURIComponent(N)}&q=${encodeURIComponent(u)}&limit=200`)).then(me=>me.json()).catch(()=>({results:[]})),H=u.length>=2&&!Ie.lineNumber?W(V(`/api/files/search-content?path=${encodeURIComponent(N)}&q=${encodeURIComponent(u)}&limit=200`)).then(me=>me.json()).catch(()=>({results:[]})):Promise.resolve({results:[]}),[Y,J]=await Promise.all([y,H]);We(Y.results||[]),qe(J.results||[])}catch(u){console.error("[FileExplorer] Search failed:",u),We([]),qe([])}ht(!1)},300);return()=>clearTimeout(a)},[Ie.query,Ie.lineNumber,N]),t.useEffect(()=>{s&&N&&(S(),ue(null),Ce(null),L(null),pe(!1),F(),P())},[s,N,F,P,S]),t.useEffect(()=>{if(m.fileViewerPath&&s){const a=m.fileViewerPath;if(m.fileViewerRevealInTree){const u=Ft(a),y=a.substring(a.lastIndexOf(".")).toLowerCase();Tt(a,u,y),Dt(a)}else A(a),ue(a);Be.clearFileViewerPath()}},[m.fileViewerPath,m.fileViewerRevealInTree,s,A]),t.useEffect(()=>{ye&&!B&&I&&pe(!0)},[I,B,ye,Ee]),t.useEffect(()=>{if(n&&(S(),ue(null),Oe(""),qe([]),We([]),Ce(null),L(null),pe(!1),Je(!1),w)){const a=m.areas.get(n);a!=null&&a.directories.includes(w)||R(null)}},[n,w,m.areas,S]),t.useEffect(()=>{const a=y=>{var Y;if(!s)return;if(y.altKey&&y.key==="e"){y.preventDefault(),y.stopPropagation(),l();return}if(y.key==="Escape"){if(he.isOpen){y.preventDefault(),y.stopPropagation(),he.submitting||Ae({isOpen:!1,node:null,value:"",submitting:!1});return}if(rs)return;if(g){y.preventDefault(),y.stopPropagation(),k(!1);return}y.preventDefault(),y.stopPropagation(),l();return}(y.metaKey||y.ctrlKey)&&y.key==="p"&&(y.preventDefault(),(Y=ms.current)==null||Y.focus());const H=Be.getShortcuts().find(J=>J.id==="file-explorer-close-tab");if(sa(y,H)){if(y.repeat)return;y.preventDefault(),y.stopPropagation(),le&&bs(le)}},u=y=>{const H=y.target;g&&!H.closest(".file-explorer-folder-selector")&&!H.closest(".file-explorer-folder-dropdown")&&k(!1)};return document.addEventListener("keydown",a,!0),document.addEventListener("click",u),()=>{document.removeEventListener("keydown",a,!0),document.removeEventListener("click",u)}},[s,l,g,le,rs,he]);const ps=t.useMemo(()=>{const a=new Map;if(I!=null&&I.files)for(const u of I.files)a.set(u.path,u.status);return a},[I==null?void 0:I.files]),qt=t.useMemo(()=>{const a=new Map;if(!(I!=null&&I.files))return a;const u={conflict:0,modified:1,added:2,deleted:3,untracked:4,renamed:5};for(const y of I.files){let H=y.path.replace(/\\/g,"/");for(;;){const Y=H.lastIndexOf("/");if(Y<=0)break;H=H.substring(0,Y);const J=a.get(H);J?u[y.status]<u[J]&&a.set(H,y.status):a.set(H,y.status)}}return a},[I==null?void 0:I.files]),gs=t.useMemo(()=>{const a=u=>({...u,gitStatus:u.isDirectory?qt.get(u.path):ps.get(u.path),hasGitChanges:u.isDirectory&&qt.has(u.path)||void 0,children:u.children?u.children.map(a):void 0});return se.map(a)},[se,ps,qt]),Tt=(a,u,y,H)=>{if(!Re.find(J=>J.path===a)){const J={path:a,filename:u,extension:y};Ge(me=>[...me,J])}Fe(a),ue(a),_t(H),A(a)},xs=async a=>{if(a.isDirectory){we("files"),Oe(""),await fe(a.path),ue(a.path),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let u=a.path,y=document.querySelector(`[data-path="${u}"]`);for(;!y&&u.includes("/");)u=u.substring(0,u.lastIndexOf("/")),y=document.querySelector(`[data-path="${u}"]`);y instanceof HTMLElement&&y.scrollIntoView({behavior:"smooth",block:"center"})})});return}L(null),Ce(null),Tt(a.path,a.name,a.extension,Ie.lineNumber)},yn=(a,u)=>{L(null),Ce(null);const y=Ft(a),H=a.substring(a.lastIndexOf(".")).toLowerCase();Tt(a,y,H,u)},bn=async(a,u)=>{L(u),Ce(null);const y=Ft(a),H=a.substring(a.lastIndexOf(".")).toLowerCase();if(Tt(a,y,H),u==="modified"){const{content:Y}=await aa(a);Y!==null&&Ce(Y)}},Ue=t.useCallback(()=>{const a=ft.current,u=tt.current;mn(u>0),pn(u>=0&&u<a.length-1)},[]);t.useEffect(()=>{if(!le){ft.current=[],tt.current=-1,Ue();return}if(Bt.current){Bt.current=!1,Ue();return}const a=ft.current,u=tt.current;if(u>=0&&a[u]===le){Ue();return}const y=u<a.length-1?a.slice(0,u+1):a.slice();y.push(le),y.length>100&&y.shift(),ft.current=y,tt.current=y.length-1,Ue()},[le,Ue]);const ys=a=>{Fe(a),ue(a),L(null),Ce(null),_t(void 0);const u=Re.find(y=>y.path===a);u!=null&&u.data||A(a)},Mt=t.useCallback(a=>{const u=ft.current;if(u.length===0)return;let y=tt.current+a;for(;y>=0&&y<u.length;){const H=u[y];if(Re.some(Y=>Y.path===H)){Bt.current=!0,tt.current=y,Ue(),ys(H);return}y+=a}},[Re,Ue]),jn=t.useCallback(()=>Mt(-1),[Mt]),vn=t.useCallback(()=>Mt(1),[Mt]),bs=a=>{Ge(u=>{var Y;const y=u.filter(J=>J.path!==a),H=u.findIndex(J=>J.path===a);if(H!==-1&&((Y=u[H])==null?void 0:Y.path)===a&&(le===a||u.find(J=>J.path===le)),y.length>0){if(!y.some(me=>me.path===le)){const me=u.findIndex(ke=>ke.path===a),oe=Math.max(0,Math.min(me,y.length-1)),Ne=y[oe];Ne&&(Fe(Ne.path),ue(Ne.path),A(Ne.path))}}else Fe(null),ue(null),S();return y})},wn=t.useCallback(()=>{Ge([]),Fe(null),ue(null),S()},[S]),js=a=>{if(k(!1),a.areaId!==n)R(a.path),d&&d(a.areaId);else{const u=p.indexOf(a.path);b(u>=0?u:0)}},Pe=t.useCallback(a=>{const u=a.lastIndexOf("/");return u<=0?"/":a.slice(0,u)},[]),at=t.useCallback((a,u,y)=>a===u?y:a.startsWith(`${u}/`)?`${y}${a.slice(u.length)}`:a,[]),Cn=t.useCallback((a,u)=>{ue(u.path),ls({isOpen:!0,position:{x:a.clientX,y:a.clientY},node:u})},[]),Nn=t.useCallback(a=>{a.defaultPrevented||N&&(a.preventDefault(),os({isOpen:!0,position:{x:a.clientX,y:a.clientY},parentDir:N}))},[N]),vs=t.useCallback(a=>{Ae({isOpen:!0,node:a,value:a.name,submitting:!1})},[]),rt=t.useCallback(()=>{Ae({isOpen:!1,node:null,value:"",submitting:!1})},[]),it=t.useCallback((a,u)=>{a&&et({isOpen:!0,parentDir:a,isDirectory:u,value:"",submitting:!1})},[]),lt=t.useCallback(()=>{et({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1})},[]),ws=t.useCallback(a=>{cs({node:a})},[]),kn=t.useCallback(async()=>{const a=Se==null?void 0:Se.node;if(a)try{const u=await W(V("/api/files/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,recursive:a.isDirectory})}),y=await u.json().catch(()=>({}));if(!u.ok){c("error","Delete Failed",y.error||"Unable to delete item");return}Ge(Y=>Y.filter(J=>J.path!==a.path&&!J.path.startsWith(`${a.path}/`))),(le===a.path||le!=null&&le.startsWith(`${a.path}/`))&&(Fe(null),S()),(de===a.path||de!=null&&de.startsWith(`${a.path}/`))&&ue(null);const H=Pe(a.path);await K(H),await P(),c("success",a.isDirectory?"Folder Deleted":"File Deleted",a.name)}catch(u){console.error("[FileExplorer] Delete failed:",u),c("error","Delete Failed","Unable to delete item")}},[Se,le,de,Pe,K,P,c,S]),Cs=t.useCallback(async()=>{const{parentDir:a,isDirectory:u,value:y}=be,H=y.trim();if(!a||!H){lt();return}if(H.includes("/")||H.includes("\\")){c("error","Invalid Name","Name must not contain path separators");return}et(Y=>({...Y,submitting:!0}));try{const Y=await W(V("/api/files/create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({parentDir:a,name:H,isDirectory:u})}),J=await Y.json();if(!Y.ok){c("error","Create Failed",J.error||"Unable to create item"),et(Ne=>({...Ne,submitting:!1}));return}const me=J.path,oe=new Set(T);oe.add(a),await K(a),z(oe),await P(),ue(me),c("success",u?"Folder Created":"File Created",H),lt()}catch(Y){console.error("[FileExplorer] Create failed:",Y),c("error","Create Failed","Unable to create item"),et(J=>({...J,submitting:!1}))}},[be,T,K,z,P,c,lt]),Ns=t.useCallback(async()=>{const a=he.node;if(!a)return;const u=he.value.trim();if(!u||u===a.name){rt();return}Ae(y=>({...y,submitting:!0}));try{const y=await W(V("/api/files/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,newName:u})}),H=await y.json();if(!y.ok){c("error","Rename Failed",H.error||"Unable to rename item"),Ae(ke=>({...ke,submitting:!1}));return}const Y=H.newPath,J=a.path,me=new Set(Array.from(T).map(ke=>at(ke,J,Y))),oe=Pe(J),Ne=Pe(Y);if(Ge(ke=>ke.map(Me=>{if(!Me.path.startsWith(J))return Me;const ot=at(Me.path,J,Y),Rt=ot.split("/").pop()||ot,Fs=Rt.includes(".")?`.${Rt.split(".").pop()}`:"";return{...Me,path:ot,filename:Rt,extension:Fs.toLowerCase(),data:Me.data?{...Me.data,path:ot,filename:Rt,extension:Fs.toLowerCase()}:Me.data}})),le&&Fe(at(le,J,Y)),de&&ue(at(de,J,Y)),G!=null&&G.path){const ke=at(G.path,J,Y);if(ke!==G.path){const Me=ke.split("/").pop()||ke,ot=Me.includes(".")?`.${Me.split(".").pop()}`:"";q({...G,path:ke,filename:Me,extension:ot.toLowerCase()})}}ne(J,Y),z(me),await K(oe),Ne!==oe&&await K(Ne),await P(),c("success","Renamed",`${a.name} renamed`),rt()}catch(y){console.error("[FileExplorer] Rename failed:",y),c("error","Rename Failed","Unable to rename item"),Ae(H=>({...H,submitting:!1}))}},[he,rt,le,de,G,T,at,Pe,ne,z,K,P,c,q]),ks=t.useCallback(a=>{cn({sourcePath:a.path,isDirectory:a.isDirectory,name:a.name}),c("info","Copied",`${a.name} ready to paste`)},[c]),Es=t.useCallback(async a=>{if(!Ze)return;const u=a.isDirectory?a.path:Pe(a.path),y=new Set(T);y.add(u);try{const H=await W(V("/api/files/paste"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourcePath:Ze.sourcePath,targetDir:u})}),Y=await H.json();if(!H.ok){c("error","Paste Failed",Y.error||"Unable to paste item");return}await K(u),z(y),await P(),Y.destinationPath&&ue(Y.destinationPath),c("success","Pasted",`${Ze.name} pasted`)}catch(H){console.error("[FileExplorer] Paste failed:",H),c("error","Paste Failed","Unable to paste item")}},[Ze,Pe,T,K,z,P,c]),Ss=t.useCallback(async a=>{try{await navigator.clipboard.writeText(a.path),c("success","Copied","Full path copied")}catch(u){console.error("[FileExplorer] Copy path failed:",u),c("error","Copy Failed","Could not copy path")}},[c]),Ts=t.useCallback(a=>{a.isDirectory||!N||Ut({open:!0,path:a.path,cwd:N})},[N]),En=t.useCallback(a=>{!N||!a||Ut({open:!0,path:a,cwd:N})},[N]),Ms=t.useCallback(async a=>{try{await Be.runTests(a.path)}catch(u){c("error","Run Tests Failed",u instanceof Error?u.message:"Unable to start tests")}},[c]),Sn=t.useMemo(()=>{if(!Xe)return[];const a=Xe.node,u=a.isDirectory?a.path:Pe(a.path),y=[{id:"create-file",label:a.isDirectory?"New File...":"New File Here...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>it(u,!1)},{id:"create-folder",label:a.isDirectory?"New Folder...":"New Folder Here...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>it(u,!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:()=>vs(a)},{id:"copy",label:a.isDirectory?"Copy Folder":"Copy File",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>ks(a)},{id:"paste",label:a.isDirectory?"Paste Into Folder":"Paste Here",icon:e.jsx(M,{name:"clipboard",size:14}),disabled:!Ze,onClick:()=>{Es(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:()=>{Ss(a)}}];return a.runnerType&&y.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:()=>{Ms(a)}}),a.isDirectory||y.push({id:"divider-git-history",label:"",divider:!0,onClick:()=>{}},{id:"git-history",label:i("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),onClick:()=>Ts(a)}),y.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:()=>ws(a)}),y},[Xe,Ze,Pe,it,vs,ks,Es,Ss,Ts,ws,Ms,i]),Tn=t.useMemo(()=>{if(!Qe)return[];const a=Qe.parentDir;return[{id:"create-file-root",label:"New File...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>it(a,!1)},{id:"create-folder-root",label:"New Folder...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>it(a,!0)}]},[Qe,it]),Dt=t.useCallback(async a=>{we("files"),Oe(""),await fe(a),ue(a),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let u=a,y=document.querySelector(`[data-path="${u}"]`);for(;!y&&u.includes("/");)u=u.substring(0,u.lastIndexOf("/")),y=document.querySelector(`[data-path="${u}"]`);y instanceof HTMLElement&&y.scrollIntoView({behavior:"smooth",block:"center"})})})},[fe]),Mn=t.useCallback(async a=>{if(!(!N||a.length===0)){as(u=>{const y=new Set(u);for(const H of a)y.add(H);return y});try{const u=await W(V("/api/files/git-add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:a,directory:N})});if(u.ok)await P();else{const y=await u.json();console.error("[FileExplorer] Git add failed:",y.error)}}catch(u){console.error("[FileExplorer] Git add failed:",u)}finally{as(u=>{const y=new Set(u);for(const H of a)y.delete(H);return y})}}},[N,P]),Dn=t.useCallback(async a=>{if(!N)return;st(a);const u=await ee(N,a);if(await P(),u.success)st(null),c("success","Merge Complete",`Merged '${a}' successfully`),F();else if(u.conflicts&&u.conflicts.length>0){const y=u.conflicts.length;c("warning","Merge Conflicts",`${y} conflict${y>1?"s":""} found — resolve to continue`),we("git")}else st(null),c("error","Merge Failed",u.error||"Merge failed")},[N,ee,P,F,c]),Rn=t.useCallback(async a=>{st("remote"),await P();const u=a.length;c("warning","Pull Conflicts",`${u} conflict${u>1?"s":""} found — resolve to continue`),we("git")},[P,c]),Fn=t.useCallback(async a=>{if(N){gt(a),us(!0),nt(null);try{const u=await W(V(`/api/files/git-conflict-file?path=${encodeURIComponent(N)}&file=${encodeURIComponent(a)}`)),y=await u.json();u.ok?nt(y):console.error("[FileExplorer] Failed to load conflict file:",y.error)}catch(u){console.error("[FileExplorer] Failed to load conflict file:",u)}finally{us(!1)}}},[N]),In=t.useCallback(async a=>{if(!(!N||!pt))try{const u=await W(V("/api/files/git-resolve-conflict"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,file:pt,content:a})}),y=await u.json();u.ok&&y.success?(gt(null),nt(null),await P()):console.error("[FileExplorer] Failed to resolve conflict:",y.error)}catch(u){console.error("[FileExplorer] Failed to resolve conflict:",u)}},[N,pt,P]),Pn=t.useCallback(async()=>{if(!N)return;const a=await ge(N);a.success?(st(null),gt(null),nt(null),c("success","Merge Complete","Merge completed successfully"),await P(),F()):c("error","Merge Failed",a.error||"Merge continue failed")},[N,ge,P,F,c]),Ln=t.useCallback(async()=>{if(!N)return;const a=await te(N);a.success?(st(null),gt(null),nt(null),c("info","Merge Aborted","Merge has been aborted"),await P(),F()):c("error","Abort Failed",a.error||"Failed to abort merge")},[N,te,P,F,c]),$n=t.useCallback(async a=>{if(N){Et(a),Kt(!0),Vt(null),we("compare");try{const u=await W(V(`/api/files/git-branch-compare?directory=${encodeURIComponent(N)}&branch=${encodeURIComponent(a)}`)),y=await u.json();u.ok?Vt(y):(c("error","Compare Failed",y.error||"Failed to compare branches"),we("files"),Et(null))}catch(u){console.error("[FileExplorer] Branch compare failed:",u),c("error","Compare Failed","Network error during comparison"),we("files"),Et(null)}finally{Kt(!1)}}},[N,c]),Hn=t.useCallback(async(a,u)=>{if(!N||!kt)return;const y=a.split("/").pop()||a,H=a.substring(a.lastIndexOf(".")).toLowerCase();Re.find(oe=>oe.path===a)||Ge(oe=>[...oe,{path:a,filename:y,extension:H}]),Fe(a),ue(a),_t(void 0);const J=async oe=>{try{const Ne=await W(V(`/api/files/git-show?path=${encodeURIComponent(a)}&ref=${encodeURIComponent(oe)}`)),ke=await Ne.json();return Ne.ok?ke.content??"":""}catch{return""}},me=oe=>({path:a,filename:y,extension:H,content:oe,fileType:"text",size:oe.length,modified:""});if(u==="modified"||u==="renamed"){const[oe,Ne]=await Promise.all([J(kt),J("HEAD")]);Ce(oe),q(me(Ne)),L("modified")}else if(u==="deleted"){const oe=await J(kt);Ce(oe),q(me("")),L("modified")}else if(u==="added"){const oe=await J("HEAD");Ce(""),q(me(oe)),L("modified")}},[N,kt,Re]),Ds=t.useCallback(()=>{we("files"),Vt(null),Et(null),Kt(!1)},[]),zn=t.useCallback(async(a,u)=>{if(N){is(!0);try{const y=new URLSearchParams({path:N,hash:u,file:a}),H=await W(V(`/api/files/git-commit-file-diff?${y}`)),Y=await H.json();H.ok?wt(Y):wt(null)}catch(y){console.error("[FileExplorer] commit diff fetch error:",y),wt(null)}finally{is(!1)}}},[N]),On=t.useCallback(()=>{wt(null)},[]),An=t.useCallback(a=>{a.preventDefault(),mt.current={startY:a.clientY,startHeight:At};const u=H=>{if(!mt.current)return;const Y=mt.current.startY-H.clientY,J=Math.max(120,Math.min(600,mt.current.startHeight+Y));ln(J)},y=()=>{mt.current=null,document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",y)};document.addEventListener("mousemove",u),document.addEventListener("mouseup",y)},[At]);if(!s||!h&&!o)return null;const Rs=(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-title",children:[e.jsxs("div",{className:"file-explorer-nav-group",role:"group","aria-label":"Tab history navigation",children:[e.jsx("button",{type:"button",className:"file-explorer-nav-btn",onClick:jn,disabled:!hn,title:"Back to previous file","aria-label":"Back to previous file",children:e.jsx(M,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"file-explorer-nav-btn",onClick:vn,disabled:!fn,title:"Forward to next file","aria-label":"Forward to next file",children:e.jsx(M,{name:"arrow-right",size:14})})]}),N&&e.jsxs("div",{className:"file-explorer-folder-selector",onClick:()=>_.length>0&&k(!g),style:{cursor:_.length>0?"pointer":"default"},title:N,children:[e.jsx("span",{className:"file-explorer-panel-dot",style:{background:(h==null?void 0:h.color)||"#ffd700"}}),e.jsx("span",{className:"file-explorer-folder-name",children:U}),e.jsx("span",{className:"file-explorer-folder-path-hint",children:N}),_.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)&&N&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"file-explorer-path-separator",children:"/"}),e.jsx(nr,{currentFolder:N,gitStatus:I,onBranchChanged:()=>{P(),F()},onMerge:Dn,onCompare:$n,onPullConflicts:Rn})]}),G&&e.jsxs("span",{className:"file-explorer-current-file",children:["/ ",G.filename]}),g&&_.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:C,type:"text",className:"file-explorer-folder-dropdown-search-input",placeholder:"Filter folders…",value:x,onChange:a=>v(a.target.value),onKeyDown:a=>{a.key==="Enter"&&O.length>0&&(a.preventDefault(),js(O[0]))},spellCheck:!1,autoComplete:"off","aria-label":"Filter folders"})}),O.length===0?e.jsx("div",{className:"file-explorer-folder-dropdown-empty",children:"No matching folders"}):O.map(a=>e.jsxs("div",{className:`file-explorer-folder-option ${a.path===N?"active":""}`,onClick:u=>{u.stopPropagation(),js(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 ${Ot?"active":""}`,onClick:()=>rn(!Ot),title:i("terminal:fileExplorer.gitHistory.title"),children:e.jsx(M,{name:"status-waiting-input",size:14})}),Ct&&!un&&e.jsxs("button",{className:`file-explorer-test-results-toggle status-${Ct.status}`,onClick:()=>Be.openTestResults(),title:Ct.status==="running"?"Tests running — open results":"Open last test results",children:[e.jsx(M,{name:"flask",size:14}),Ct.status==="running"&&e.jsx("span",{className:"fe-test-run-dot"})]}),e.jsx("button",{className:"file-explorer-panel-close",onClick:l,children:"×"})]}),e.jsxs("div",{className:"file-explorer-main",style:X>0?{"--fe-mobile-tree-height":`${X}px`}:void 0,children:[e.jsxs("div",{className:`file-explorer-tree-panel ${$e?"collapsed":""}`,style:{width:Z},children:[e.jsxs("div",{className:"file-explorer-tabs",children:[e.jsx("button",{className:"file-explorer-tree-toggle",onClick:()=>De(!$e),title:i($e?"terminal:fileExplorer.expandTree":"terminal:fileExplorer.collapseTree"),children:e.jsx(M,{name:$e?"caret-down":"caret-up",size:12})}),e.jsxs("button",{className:`file-explorer-tab ${Ee==="files"?"active":""}`,onClick:()=>we("files"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"folder",size:14})}),i("terminal:spotlight.files")]}),e.jsxs("button",{className:`file-explorer-tab ${Ee==="git"?"active":""}`,onClick:()=>we("git"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"git-branch",size:14})}),i("terminal:fileExplorer.gitChanges"),Rs>0&&e.jsx("span",{className:"tab-badge",children:Rs})]}),(Nt||hs)&&e.jsxs("button",{className:`file-explorer-tab ${Ee==="compare"?"active":""}`,onClick:()=>we("compare"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"arrows-horizontal",size:14})}),i("terminal:fileExplorer.diffView"),Nt&&e.jsx("span",{className:"tab-badge",children:Nt.files.length}),e.jsx("span",{className:"tab-close-btn",onClick:a=>{a.stopPropagation(),Ds()},children:"×"})]})]}),Ee==="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:ms,type:"text",className:"file-explorer-search-input",placeholder:i("terminal:fileExplorer.searchPlaceholder"),value:Ke,onChange:a=>Oe(a.target.value)}),Ke&&e.jsx("button",{className:"file-explorer-search-clear",onClick:()=>Oe(""),children:"×"})]}),e.jsxs("div",{className:"file-explorer-toolbar-buttons",children:[e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>z(new Set),title:i("terminal:fileExplorer.collapseAll"),children:"⊟"}),le&&e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>Dt(le),title:i("terminal:fileExplorer.revealInTree"),children:e.jsx(M,{name:"target",size:14})})]})]}),e.jsx("div",{className:"file-explorer-tree-content",onContextMenu:Ee==="files"?Nn:void 0,children:Ee==="compare"?e.jsx(nn,{compareResult:Nt,loading:hs,onFileSelect:Hn,selectedPath:de,onClose:Ds}):Ee==="files"?Q?e.jsx("div",{className:"tree-loading",children:i("common:status.loading")}):Ie.query?Ye?e.jsx("div",{className:"tree-loading",children:i("terminal:fileExplorer.searching")}):e.jsx(en,{filenameResults:jt,contentResults:ut,onSelectFile:xs,onSelectContent:yn,selectedPath:de,query:Ie.query,lineNumber:Ie.lineNumber}):e.jsx("div",{className:"file-tree",children:gs.length===0?e.jsx("div",{className:"tree-empty",children:i("terminal:fileExplorer.noDirectoriesLinked")}):gs.map(a=>e.jsx(ea,{node:a,depth:0,selectedPath:de,expandedPaths:T,onSelect:xs,onToggle:ie,onContextMenu:Cn,searchQuery:""},a.path))}):e.jsx(tn,{gitStatus:I,loading:$,onFileSelect:bn,selectedPath:de,onRefresh:P,onStageFiles:Mn,stagingPaths:an,currentFolder:N,onCommitComplete:()=>{P(),F()},mergeInProgress:I==null?void 0:I.mergeInProgress,mergingBranch:ds,onMergeContinue:Pn,onMergeAbort:Ln,onConflictOpen:Fn,onRevealInTree:Dt})})]}),e.jsx("div",{className:`file-explorer-resize-handle ${ve?"active":""}`,onMouseDown:Te}),!$e&&e.jsx("div",{className:"fe-mobile-resize-handle",onMouseDown:xe,onTouchStart:ze}),e.jsx("div",{className:"file-explorer-viewer-panel",children:pt?e.jsx(ir,{file:pt,versions:gn,loading:xn,onResolve:In,onClose:()=>{gt(null),nt(null)},currentBranch:(I==null?void 0:I.branch)||"HEAD",mergingBranch:ds||"incoming"}):He?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"commit-diff-header",children:[e.jsx("span",{className:"commit-diff-file",children:He.filePath}),e.jsx("span",{className:"commit-diff-hash",children:He.hash.slice(0,8)}),e.jsx("button",{className:"commit-diff-close",onClick:On,children:"×"})]}),e.jsx(Zt,{originalContent:He.beforeContent,modifiedContent:He.afterContent,filename:He.filename,filePath:He.filePath,language:Ps[He.extension]||"plaintext"})]}):on?e.jsx("div",{className:"commit-diff-loading",children:i("common:status.loading")}):e.jsxs(e.Fragment,{children:[e.jsx(sn,{tabs:Re,activeTabPath:le,onSelectTab:ys,onCloseTab:bs,onCloseAllTabs:wn,onShowGitHistory:En}),E==="modified"&&vt!==null&&G?e.jsx(Zt,{originalContent:vt,modifiedContent:G.content,filename:G.filename,filePath:G.path,language:Ps[G.extension]||"plaintext"}):e.jsx(Qs,{file:G,loading:ae,error:ce,onRevealInTree:Dt,onFileEdited:A})]})})]}),Ot&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"git-history-resize-handle",onMouseDown:An}),e.jsx("div",{className:"git-history-bottom-panel",style:{height:At},children:e.jsx(fr,{history:je,currentFolder:N,onFileSelect:zn})})]}),he.isOpen&&he.node&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:rt,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["Rename ",he.node.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:he.node.path,children:he.node.path}),e.jsx("input",{ref:Wt,type:"text",className:"file-explorer-rename-input",value:he.value,onChange:a=>Ae(u=>({...u,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Ns()):a.key==="Escape"&&(a.preventDefault(),rt())},disabled:he.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:rt,disabled:he.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{Ns()},disabled:he.submitting||!he.value.trim(),children:he.submitting?"Renaming...":"Rename"})]})]})}),Xe&&e.jsx(ct,{isOpen:Xe.isOpen,position:Xe.position,worldPosition:{x:0,z:0},actions:Sn,onClose:()=>ls(null)}),Qe&&e.jsx(ct,{isOpen:Qe.isOpen,position:Qe.position,worldPosition:{x:0,z:0},actions:Tn,onClose:()=>os(null)}),be.isOpen&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:lt,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["New ",be.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:be.parentDir,children:be.parentDir}),e.jsx("input",{ref:fs,type:"text",className:"file-explorer-rename-input",placeholder:be.isDirectory?"folder name":"file name",value:be.value,onChange:a=>et(u=>({...u,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Cs()):a.key==="Escape"&&(a.preventDefault(),lt())},disabled:be.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:lt,disabled:be.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{Cs()},disabled:be.submitting||!be.value.trim(),children:be.submitting?"Creating...":"Create"})]})]})}),e.jsx(jr,{isOpen:Gt.open,filePath:Gt.path,cwd:Gt.cwd,onClose:()=>Ut(a=>({...a,open:!1}))}),e.jsx(ta,{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:()=>{kn()},onClose:()=>cs(null)})]})}export{Nr as FileExplorerPanel};
|