tide-commander 1.96.0 → 1.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/assets/{BossLogsModal-BFy6Rxdn.js → BossLogsModal-P6MiZVuY.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-KQyJYj_B.js → BossSpawnModal-DZJ1Ngsz.js} +1 -1
  3. package/dist/assets/{ControlsModal-W_ghuG_Q.js → ControlsModal-BjV0a1kc.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-valTcuRy.js → DockerLogsModal-DtddubKa.js} +1 -1
  5. package/dist/assets/EmbeddedEditor-ByRepTwR.js +33 -0
  6. package/dist/assets/{GmailOAuthSetup-AcW1zAlk.js → GmailOAuthSetup-DS6NmxUi.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-C9uZ46Oe.js → GoogleOAuthSetup-kQyKInRW.js} +1 -1
  8. package/dist/assets/{IframeModal-CmWv7GXl.js → IframeModal-BuTPDTx1.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-CNvzosgx.js → IntegrationsPanel-Bm19ZAd6.js} +2 -2
  10. package/dist/assets/{LogViewerModal-imTE-619.js → LogViewerModal-DFlUtkDD.js} +1 -1
  11. package/dist/assets/{MonitoringModal-DLxBY738.js → MonitoringModal-BEEPwGu5.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-S4n0D11V.js → PM2LogsModal-Di5MjyxZ.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-B32sqCxN.js → RestoreArchivedAreaModal-CNjmR7BX.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-bEu0UPUm.js → Scene2DCanvas-CA29sh9R.js} +1 -1
  15. package/dist/assets/{SceneManager-Ce3X0awy.js → SceneManager-duyCA_TD.js} +1 -1
  16. package/dist/assets/{SkillsPanel-Dj22nDU8.js → SkillsPanel-CkV4ci4Q.js} +1 -1
  17. package/dist/assets/SlackMultiInstanceSetup-iHZNQX3B.js +2 -0
  18. package/dist/assets/{SpawnModal-F9nspdWd.js → SpawnModal-bzQlnSQy.js} +1 -1
  19. package/dist/assets/{SubordinateAssignmentModal-DT31CkPr.js → SubordinateAssignmentModal-D6Ak_XQ1.js} +1 -1
  20. package/dist/assets/TriggerManagerPanel-CT8aMQ5P.js +9 -0
  21. package/dist/assets/{WorkflowEditorPanel-BYRi0cU9.js → WorkflowEditorPanel-DcV9ErU4.js} +1 -1
  22. package/dist/assets/{index-ByfAbkqv.js → index-BQQV5Xax.js} +1 -1
  23. package/dist/assets/index-Ba8umpS_.js +1 -0
  24. package/dist/assets/{index-B9G4hrFR.js → index-C0fIrrTS.js} +1 -1
  25. package/dist/assets/index-CDHzSAgq.js +1 -0
  26. package/dist/assets/index-CK8NcQSU.css +1 -0
  27. package/dist/assets/{index-CLr8DpLX.js → index-Cirz97EK.js} +2 -2
  28. package/dist/assets/index-Cnj2pM08.js +19 -0
  29. package/dist/assets/{index-DqZhHROd.js → index-D2L5oc5D.js} +1 -1
  30. package/dist/assets/{index-DkjWoHhy.js → index-DR7uaDtK.js} +1 -1
  31. package/dist/assets/{index-BmjrPptb.js → index-Dww2MWLN.js} +1 -1
  32. package/dist/assets/main-CD03IZnY.css +1 -0
  33. package/dist/assets/main-XbhAPjbi.js +214 -0
  34. package/dist/assets/{web-D-a3phls.js → web-C-JnApw7.js} +1 -1
  35. package/dist/assets/{web-CLuvtqCm.js → web-C4LpSGoH.js} +1 -1
  36. package/dist/assets/{web-DM2bFWBN.js → web-CaPUSaID.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/locales/en/config.json +44 -0
  39. package/dist/locales/en/terminal.json +10 -0
  40. package/dist/src/packages/server/claude/backend.js +42 -0
  41. package/dist/src/packages/server/claude/permission-prompt-server.mjs +188 -0
  42. package/dist/src/packages/server/claude/runner/process-lifecycle.js +3 -0
  43. package/dist/src/packages/server/claude/runner/stdout-pipeline.js +8 -0
  44. package/dist/src/packages/server/claude/runner/tmux-helper.js +14 -0
  45. package/dist/src/packages/server/data/event-queries.js +143 -1
  46. package/dist/src/packages/server/data/migrations/007_whatsapp_messages.sql +48 -0
  47. package/dist/src/packages/server/index.js +1 -0
  48. package/dist/src/packages/server/integrations/gmail/gmail-client.js +139 -24
  49. package/dist/src/packages/server/integrations/gmail/gmail-routes.js +162 -0
  50. package/dist/src/packages/server/integrations/slack/slack-config.js +13 -0
  51. package/dist/src/packages/server/integrations/slack/slack-trigger-handler.js +12 -4
  52. package/dist/src/packages/server/integrations/whatsapp/whatsapp-routes.js +81 -0
  53. package/dist/src/packages/server/integrations/whatsapp/whatsapp-trigger-handler.js +29 -0
  54. package/dist/src/packages/server/routes/agent-prompt.js +57 -0
  55. package/dist/src/packages/server/routes/index.js +6 -1
  56. package/dist/src/packages/server/routes/skills.js +193 -0
  57. package/dist/src/packages/server/routes/trigger-routes.js +74 -17
  58. package/dist/src/packages/server/routes/webhook-signatures.js +20 -7
  59. package/dist/src/packages/server/services/agent-prompt-service.js +100 -0
  60. package/dist/src/packages/server/services/index.js +1 -0
  61. package/dist/src/packages/server/websocket/handler.js +2 -1
  62. package/dist/src/packages/server/websocket/listeners/agent-prompt-listeners.js +13 -0
  63. package/dist/src/packages/server/websocket/listeners/index.js +2 -0
  64. package/dist/src/packages/shared/whatsapp-types.js +1 -0
  65. package/package.json +2 -2
  66. package/dist/assets/EmbeddedEditor-CIsFWo6A.js +0 -1
  67. package/dist/assets/SlackMultiInstanceSetup-J9NdRY0U.js +0 -2
  68. package/dist/assets/TriggerManagerPanel-CVJ9ozHz.js +0 -9
  69. package/dist/assets/index-BPy8NE5B.js +0 -51
  70. package/dist/assets/index-BdGz_GAe.css +0 -1
  71. package/dist/assets/index-C5wC_Xis.js +0 -1
  72. package/dist/assets/index-DJm7oMXk.js +0 -1
  73. package/dist/assets/main-9uTEp9Lr.js +0 -214
  74. package/dist/assets/main-BfT_95fk.css +0 -1
@@ -0,0 +1,19 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-ByRepTwR.js","assets/main-XbhAPjbi.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-CD03IZnY.css","assets/EmbeddedEditor-Dx2pJa2-.css"])))=>i.map(i=>d[i]);
2
+ import{r as t,aJ as q,l as K,aX as Vt,M as $s,S as Tt,N as Hs,s as mt,u as le,j as e,I as M,bA as Mt,f as zs,bB as Os,bC as Dn,bD as As,bE as Gs,bF as Rn,bG as Fn,bH as Kt,bI as Pn,bJ as In,bK as Xt,bL as Ln,bM as Us,bN as Et,bO as St,aa as it,bP as ft,bQ as pt,bR as Es,bS as $n,b3 as Hn,bT as Yt,bU as zn,bV as On,bW as Ss,C as An,n as Gn}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Un(s){const[n,l]=t.useState(null),[c,r]=t.useState(!1),i=t.useCallback(async()=>{if(s){r(!0);try{const f=await q(K(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await f.json();f.ok?l(o):l({isGitRepo:!1,files:[]})}catch(f){console.error("[FileExplorer] Failed to load git status:",f),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[s]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function Bn(s){try{const n=await q(K(`/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 _n=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",""]),Vn=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),Kn=new Set([".pdf"]),Wn=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 qn(s){const n=s.toLowerCase();return Vn.has(n)?"image":Kn.has(n)?"pdf":Wn.has(n)?"binary":(_n.has(n),"text")}function Jn(){const[s,n]=t.useState(null),[l,c]=t.useState(!1),[r,i]=t.useState(null),f=t.useCallback(async u=>{var g,j;c(!0),i(null);try{const p=u.substring(u.lastIndexOf(".")).toLowerCase(),b=qn(p),C=u.substring(u.lastIndexOf("/")+1);if(b==="image"){const k=await q(K(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!k.ok){const w=await k.json().catch(()=>({error:"Failed to load image"}));i(w.error||"Failed to load image"),n(null);return}const d=await k.blob(),v=URL.createObjectURL(d);n({path:u,filename:C,extension:p,content:"",size:d.size,modified:new Date().toISOString(),fileType:"image",dataUrl:v});return}if(b==="pdf"){const k=await q(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await k.json();if(!k.ok){i(d.error||"Failed to load PDF info"),n(null);return}n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"pdf",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&token=${encodeURIComponent(Vt())}`)});return}if(b==="binary"){const k=await q(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await k.json();if(!k.ok){i(d.error||"Failed to load file info"),n(null);return}n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"binary",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Vt())}`)});return}const P=await q(K(`/api/files/read?path=${encodeURIComponent(u)}`)),x=await P.json();if(!P.ok){if((g=x.error)!=null&&g.includes("too large")||(j=x.error)!=null&&j.includes("binary")){const k=await q(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await k.json();if(k.ok){n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"binary",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Vt())}`)});return}}i(x.error||"Failed to load file"),n(null);return}n({...x,fileType:"text"})}catch(p){const b=p instanceof Error?p.message:"Failed to load file";i(b),n(null)}finally{c(!1)}},[]),o=t.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),i(null)},[]);return{file:s,loading:l,error:r,loadFile:f,clearFile:o,setFile:n}}const Wt="file-explorer-state",Yn=10080*60*1e3;function Xn(s,n){return n?`${Wt}-folder-${n}`:s?`${Wt}-area-${s}`:`${Wt}-default`}async function Qn(s){try{const n=await q(K(`/api/files/exists?path=${encodeURIComponent(s)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function Zn({areaId:s,folderPath:n,isOpen:l}){const c=Xn(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(c);if(!o)return null;const u=JSON.parse(o);if(Date.now()-u.timestamp>Yn)return localStorage.removeItem(c),null;const j=(await Promise.all(u.tabs.map(async b=>({tab:b,exists:await Qn(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let p=u.activeTabPath;return p&&!j.some(b=>b.path===p)&&(p=j.length>0?j[0].path:null),{tabs:j,activeTabPath:p,viewMode:u.viewMode||"files",selectedFolderIndex:u.selectedFolderIndex||0,expandedPaths:new Set(u.expandedPaths||[])}}catch(o){return console.error("[FileExplorerStorage] Failed to load state:",o),null}},[c]),f=t.useCallback(o=>{if(l)try{const u={tabs:o.tabs,activeTabPath:o.activeTabPath,viewMode:o.viewMode,selectedFolderIndex:o.selectedFolderIndex,expandedPaths:Array.from(o.expandedPaths),timestamp:Date.now()};localStorage.setItem(c,JSON.stringify(u))}catch(u){console.error("[FileExplorerStorage] Failed to save state:",u)}},[c,l]);return{loadStoredState:i,saveState:f}}const Ts=280,Ms=150,Ds=1200;function ea(){const[s,n]=t.useState(()=>{const g=$s(Tt.TREE_PANEL_WIDTH,Ts);return g>=Ms&&g<=Ds?g:Ts}),l=t.useRef(!1),[c,r]=t.useState(!1),i=t.useRef(0),f=t.useRef(0),o=t.useRef(s);o.current=s;const u=t.useCallback(g=>{g.preventDefault(),l.current=!0,r(!0),i.current=g.clientX,f.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const g=p=>{if(!l.current)return;const b=p.clientX-i.current,C=Math.min(Ds,Math.max(Ms,f.current+b));n(C)},j=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Hs(Tt.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",g),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",j)}},[]),{treePanelWidth:s,handleResizeStart:u,isResizing:c}}const ta=100,sa=.65,na=36;function aa(){const[s,n]=t.useState(()=>$s(Tt.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const c=t.useRef(0),r=t.useRef(0),i=()=>Math.floor((window.innerHeight-na)*sa),f=p=>Math.min(i(),Math.max(ta,p)),o=t.useCallback(p=>{n(p);const b=document.querySelector(".file-explorer-main");b&&b.style.setProperty("--fe-mobile-tree-height",`${p}px`)},[]),u=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Hs(Tt.MOBILE_TREE_PANEL_HEIGHT,l.current),mt.setTerminalResizing(!1)},[]),g=t.useCallback(p=>{p.preventDefault();const b=document.querySelector(".file-explorer-tree-panel"),C=l.current>0?l.current:(b==null?void 0:b.getBoundingClientRect().height)??240;c.current=p.clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",mt.setTerminalResizing(!0);const P=k=>{const d=k.clientY-c.current;o(f(r.current+d))},x=()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",x),u()};document.addEventListener("mousemove",P),document.addEventListener("mouseup",x)},[o,u]),j=t.useCallback(p=>{if(p.touches.length!==1)return;const b=document.querySelector(".file-explorer-tree-panel"),C=l.current>0?l.current:(b==null?void 0:b.getBoundingClientRect().height)??240;c.current=p.touches[0].clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",mt.setTerminalResizing(!0);const P=k=>{if(k.touches.length!==1)return;k.preventDefault();const d=k.touches[0].clientY-c.current;o(f(r.current+d))},x=()=>{document.removeEventListener("touchmove",P),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x),u()};document.addEventListener("touchmove",P,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x)},[o,u]);return{mobileTreeHeight:s,handleResizeMouseDown:g,handleResizeTouchStart:j}}function Qt(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(null),[f,o]=t.useState(null),u=t.useCallback(async k=>{c(!0),i(null);try{const d=await q(K(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),v=await d.json();d.ok?n(v.branches||[]):(i(v.error||"Failed to load branches"),n([]))}catch(d){console.error("[GitBranches] Failed to load branches:",d),i("Failed to load branches"),n([])}finally{c(!1)}},[]),g=t.useCallback(async(k,d)=>{o("checkout"),i(null);try{const v=await q(K("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:d})}),w=await v.json();return v.ok||i(w.error||"Checkout failed"),w}catch(v){console.error("[GitBranches] Checkout failed:",v);const w={success:!1,error:"Checkout failed"};return i(w.error),w}finally{o(null)}},[]),j=t.useCallback(async(k,d,v)=>{o("create"),i(null);try{const w=await q(K("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:d,startPoint:v})}),R=await w.json();return w.ok||i(R.error||"Failed to create branch"),R}catch(w){console.error("[GitBranches] Create branch failed:",w);const R={success:!1,error:"Failed to create branch"};return i(R.error),R}finally{o(null)}},[]),p=t.useCallback(async k=>{o("pull"),i(null);try{const d=await q(K("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await d.json();return!d.ok&&!v.conflicts&&i(v.error||"Pull failed"),v}catch(d){console.error("[GitBranches] Pull failed:",d);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 d=await q(K("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await d.json();return d.ok||i(v.error||"Push failed"),v}catch(d){console.error("[GitBranches] Push failed:",d);const v={success:!1,error:"Push failed"};return i(v.error),v}finally{o(null)}},[]),C=t.useCallback(async(k,d)=>{o("merge"),i(null);try{const v=await q(K("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:d})}),w=await v.json();return!v.ok&&!w.conflicts&&i(w.error||"Merge failed"),w}catch(v){console.error("[GitBranches] Merge failed:",v);const w={success:!1,error:"Merge failed"};return i(w.error),w}finally{o(null)}},[]),P=t.useCallback(async k=>{o("merge-abort"),i(null);try{const d=await q(K("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await d.json();return d.ok||i(v.error||"Merge abort failed"),v}catch(d){console.error("[GitBranches] Merge abort failed:",d);const v={success:!1,error:"Merge abort failed"};return i(v.error),v}finally{o(null)}},[]),x=t.useCallback(async k=>{o("merge-continue"),i(null);try{const d=await q(K("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await d.json();return d.ok||i(v.error||"Merge continue failed"),v}catch(d){console.error("[GitBranches] Merge continue failed:",d);const v={success:!1,error:"Merge continue failed"};return i(v.error),v}finally{o(null)}},[]);return{branches:s,loading:l,error:r,operationInProgress:f,loadBranches:u,checkoutBranch:g,createBranch:j,pullFromRemote:p,pushToRemote:b,mergeBranch:C,mergeAbort:P,mergeContinue:x}}const ra=50,ia=400,Rs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function la(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(!1),[f,o]=t.useState(null),[u,g]=t.useState(!1),[j,p]=t.useState(0),[b,C]=t.useState({...Rs}),[P,x]=t.useState(null),[k,d]=t.useState([]),[v,w]=t.useState(!1),[R,z]=t.useState([]),[O,G]=t.useState(!1),H=t.useRef(null),ae=t.useRef(""),ee=t.useCallback((A,Z,L)=>{const S=L||b,W=new URLSearchParams;return W.set("path",A),W.set("limit",String(ra)),W.set("offset",String(Z)),S.branch&&W.set("branch",S.branch),S.author&&W.set("author",S.author),S.since&&W.set("since",S.since),S.until&&W.set("until",S.until),S.searchPath&&W.set("searchPath",S.searchPath),S.search&&W.set("search",S.search),W.toString()},[b]),T=t.useCallback(async A=>{ae.current=A,c(!0),o(null),x(null),d([]);try{const Z=ee(A,0),L=await q(K(`/api/files/git-log?${Z}`)),S=await L.json();L.ok?(n(S.commits||[]),p(S.total||0),g(S.hasMore||!1)):(o(S.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),o("Failed to load git history"),n([])}finally{c(!1)}},[ee]),D=t.useCallback(async A=>{if(!(r||!u)){i(!0);try{const Z=ee(A,s.length),L=await q(K(`/api/files/git-log?${Z}`)),S=await L.json();L.ok&&(n(W=>[...W,...S.commits||[]]),p(S.total||0),g(S.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{i(!1)}}},[ee,s.length,u,r]),F=t.useCallback(async A=>{if(x(A),!A){d([]);return}w(!0);try{const Z=ae.current,L=new URLSearchParams({path:Z,hash:A.hash}),S=await q(K(`/api/files/git-commit-files?${L}`)),W=await S.json();S.ok?d(W.files||[]):d([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),d([])}finally{w(!1)}},[]),re=t.useCallback((A,Z)=>{C(L=>({...L,[A]:Z}))},[]),_=t.useCallback(()=>{C({...Rs})},[]);t.useEffect(()=>{const A=ae.current;if(A)return H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{T(A)},ia),()=>{H.current&&clearTimeout(H.current)}},[b]);const ge=t.useCallback(async A=>{G(!0);try{const Z=new URLSearchParams({path:A}),L=await q(K(`/api/files/git-authors?${Z}`)),S=await L.json();L.ok&&z(S.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{G(!1)}},[]);return{commits:s,loading:l,loadingMore:r,error:f,hasMore:u,total:j,filters:b,setFilter:re,resetFilters:_,selectedCommit:P,selectCommit:F,commitFiles:k,commitFilesLoading:v,loadHistory:T,loadMore:D,authors:R,authorsLoading:O,loadAuthors:ge}}function oa(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const c=s.current.querySelector(l);if(c&&Fs(c))return c}return Fs(s.current)?s.current:null}function Fs(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function Bs(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function qt(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function ca(s){const{scrollTop:n,scrollHeight:l,clientHeight:c}=s;return l<=c?100:Math.round(n/(l-c)*100)}function da(s,n){const l=Bs(s),c=s.scrollTop,r=Math.floor(c/l)+1,i=n.split(`
3
+ `).length;return Math.min(r,i)}function ua(s,n,l=!1){if(!n)return[];l||s.toLowerCase();const c=l?n:n.toLowerCase(),r=[];let i=0;const f=s.split(`
4
+ `);let o=0;for(let u=0;u<f.length;u++){const g=f[u],j=l?g:g.toLowerCase();let p=0,b=j.indexOf(c);for(;b!==-1;){const C=o+b;r.push({index:i++,line:u+1,column:b,length:c.length,charIndex:C}),p=b+c.length,b=j.indexOf(c,p)}o+=g.length+1}return r}function lt(s){return/[\w]/.test(s)}function Ae(s){return/\s/.test(s)}function ha(s,n,l){let c=n-1,r=l;const i=s.length,f=s[c]||"";if(r<f.length){const g=lt(f[r]);if(!Ae(f[r]))for(;r<f.length&&!Ae(f[r])&&lt(f[r])===g;)r++}for(;c<i;){const g=s[c]||"";for(;r<g.length&&Ae(g[r]);)r++;if(r<g.length)return{line:c+1,col:r};c++,r=0}const o=i,u=Math.max(0,(s[i-1]||"").length-1);return{line:o,col:u}}function ma(s,n,l){let c=n-1,r=l+1;const i=s.length;for(;c<i;){const u=s[c]||"";for(;r<u.length&&Ae(u[r]);)r++;if(r<u.length)break;c++,r=0}if(c>=i)return{line:i,col:Math.max(0,(s[i-1]||"").length-1)};const f=s[c]||"",o=lt(f[r]);for(;r+1<f.length&&!Ae(f[r+1])&&lt(f[r+1])===o;)r++;return{line:c+1,col:r}}function fa(s,n,l){let c=n-1,r=l-1;for(;c>=0;){const o=s[c]||"";for(;r>=0&&Ae(o[r]);)r--;if(r>=0)break;c--,c>=0&&(r=(s[c]||"").length-1)}if(c<0)return{line:1,col:0};const i=s[c]||"",f=lt(i[r]);for(;r>0&&!Ae(i[r-1])&&lt(i[r-1])===f;)r--;return{line:c+1,col:r}}function pa(s,n,l,c){if(c==="none")return"";const{anchorLine:r,anchorCol:i,headLine:f,headCol:o}=l;if(c==="line"){const C=Math.min(r,f),P=Math.max(r,f);return n.slice(C-1,P).join(`
5
+ `)}let u,g,j,p;if(r<f||r===f&&i<=o?(u=r,g=i,j=f,p=o):(u=f,g=o,j=r,p=i),u===j)return(n[u-1]||"").substring(g,p+1);const b=[];b.push((n[u-1]||"").substring(g));for(let C=u;C<j-1;C++)b.push(n[C]||"");return b.push((n[j-1]||"").substring(0,p+1)),b.join(`
6
+ `)}function _s(s){const{containerRef:n,isEnabled:l=!0,content:c="",onClose:r,onSearchOpen:i}=s,f=t.useRef({percentage:0,line:1,column:1}),o=t.useRef(null),u=t.useRef(19.5),g=t.useMemo(()=>c.split(`
7
+ `),[c]),j=g.length,[p,b]=t.useState(1),[C,P]=t.useState(0),[x,k]=t.useState(!1),[d,v]=t.useState("none"),[w,R]=t.useState(null),[z,O]=t.useState(!1),[G,H]=t.useState(""),[ae,ee]=t.useState(0),[T,D]=t.useState(!1),F=t.useMemo(()=>ua(c,G,!1),[c,G]),re=t.useCallback(()=>{const m=o.current;if(!m)return;const J=ca(m),ie=da(m,c),V=Math.max(1,Math.round(m.scrollLeft/7.8)+1);f.current={percentage:J,line:ie,column:V}},[c]),_=t.useCallback(()=>{O(!0),H(""),ee(0),i==null||i()},[i]),ge=t.useCallback(()=>{O(!1),H(""),ee(0)},[]),A=t.useCallback(()=>{D(m=>!m)},[]),Z=t.useCallback(m=>{const J=o.current;if(!J)return;const ie=J.querySelector(".file-viewer-pre"),ue=ie&&parseFloat(getComputedStyle(ie).lineHeight)||u.current,V=ie&&parseFloat(getComputedStyle(ie).paddingTop)||0,Q=(ie?ie.offsetTop:0)+V+(m-1)*ue,te=ue*3;J.scrollTo({top:Math.max(0,Q-te),behavior:"smooth"})},[]);t.useEffect(()=>{!z||F.length===0||ee(0)},[F,z]),t.useEffect(()=>{if(!z||F.length===0)return;const m=F[ae];m&&(b(m.line),P(m.column),Z(m.line))},[z,F,ae,Z]);const L=t.useCallback(()=>{F.length!==0&&ee(m=>(m+1)%F.length)},[F]),S=t.useCallback(()=>{F.length!==0&&ee(m=>(m-1+F.length)%F.length)},[F]),W=t.useCallback(m=>{const J=o.current;if(!J)return;const ie=J.querySelector(".file-viewer-pre");if(!ie)return;const ue=parseFloat(getComputedStyle(ie).lineHeight),V=isNaN(ue)?u.current:ue,E=parseFloat(getComputedStyle(ie).paddingTop)||0,te=ie.offsetTop+E+(m-1)*V,Ne=te+V,xe=J.scrollTop,U=xe+J.clientHeight;te<xe?J.scrollTo({top:Math.max(0,te),behavior:"auto"}):Ne>U&&J.scrollTo({top:Ne-J.clientHeight,behavior:"auto"})},[]),se=t.useCallback((m,J)=>{b(m),P(J),W(m),d!=="none"&&R(ie=>ie?{...ie,headLine:m,headCol:J}:null)},[d,W]),be=t.useCallback(()=>{if(d==="none"||!w)return;const m=pa(c,g,w,d);m&&navigator.clipboard.writeText(m).catch(()=>{const J=document.createElement("textarea");J.value=m,J.style.position="fixed",J.style.left="-9999px",document.body.appendChild(J),J.select(),document.execCommand("copy"),document.body.removeChild(J)}),v("none"),R(null)},[d,w,c,g]),de=t.useCallback(m=>{const J=m.target;if((J.tagName==="INPUT"||J.tagName==="TEXTAREA")&&m.key!=="Escape")return;const ue=o.current;if(!ue)return;let V=!1;const E=u.current,Q=Math.max(1,Math.floor(ue.clientHeight/E)),te=Math.max(1,Math.floor(Q/2)),Ne=(U,ne)=>{const pe=Math.max(0,(g[U-1]||"").length-1);return Math.min(ne,Math.max(0,pe))},xe=(U,ne)=>{const pe=Ne(U,ne);se(U,pe)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!z)m.preventDefault(),m.stopPropagation(),d==="char"?(v("none"),R(null)):(v("char"),R({anchorLine:p,anchorCol:C,headLine:p,headCol:C})),V=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!z)m.preventDefault(),m.stopPropagation(),d==="line"?(v("none"),R(null)):(v("line"),R({anchorLine:p,anchorCol:0,headLine:p,headCol:0})),V=!0;else if(m.key==="y"&&!m.ctrlKey&&d!=="none")m.preventDefault(),m.stopPropagation(),be(),V=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const U=Math.min(p+1,j);xe(U,C),V=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const U=Math.max(p-1,1);xe(U,C),V=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&d==="none"&&!z){m.preventDefault(),m.stopPropagation();const U=Math.min(p+te,j);xe(U,C),V=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&d==="none"&&!z){m.preventDefault(),m.stopPropagation();const U=Math.max(p-te,1);xe(U,C),V=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),_(),V=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&d==="none"&&!z){m.preventDefault(),m.stopPropagation();const U=Math.min(p+Q,j);xe(U,C),V=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const U=Math.min(p+Q,j);xe(U,C),V=!0}else if(m.key==="b"&&!x&&d==="none"&&!z||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const U=Math.max(p-Q,1);xe(U,C),V=!0}else if(m.key==="g"&&!m.shiftKey&&d==="none"&&!z)m.preventDefault(),m.stopPropagation(),se(1,0),qt(ue,!1),V=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),se(1,0),qt(ue,!1),V=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),se(j,0),qt(ue,!0),V=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),se(p,Math.max(0,C-1)),V=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const U=(g[p-1]||"").length;se(p,Math.min(C+1,Math.max(0,U-1))),V=!0}else if(m.key==="w"&&!m.ctrlKey&&!z){m.preventDefault(),m.stopPropagation();const U=ha(g,p,C);se(U.line,U.col),V=!0}else if(m.key==="e"&&!m.ctrlKey&&!z){m.preventDefault(),m.stopPropagation();const U=ma(g,p,C);se(U.line,U.col),V=!0}else if(m.key==="b"&&!z){m.preventDefault(),m.stopPropagation();const U=fa(g,p,C);se(U.line,U.col),V=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),se(p,0),V=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),se(p,Math.max(0,(g[p-1]||"").length-1)),V=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const ne=(g[p-1]||"").search(/\S/);se(p,ne>=0?ne:0),V=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),_(),V=!0):m.key==="n"&&!z?(m.preventDefault(),m.stopPropagation(),L(),V=!0):m.key==="N"&&m.shiftKey&&!z?(m.preventDefault(),m.stopPropagation(),S(),V=!0):m.key==="?"&&d==="none"?(m.preventDefault(),m.stopPropagation(),A(),V=!0):m.key==="q"&&d==="none"?(m.preventDefault(),m.stopPropagation(),r==null||r(),V=!0):m.key==="Escape"&&(d!=="none"?(m.preventDefault(),m.stopPropagation(),v("none"),R(null),V=!0):z?(m.preventDefault(),m.stopPropagation(),ge(),V=!0):x&&(m.preventDefault(),m.stopPropagation(),k(!1),V=!0));V&&(m.key!=="Escape"&&!x&&k(!0),requestAnimationFrame(re))},[r,re,j,g,p,C,W,z,ge,d,x,se,be,_,L,S,A]);return t.useEffect(()=>{if(!l)return;const m=oa(n);if(o.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=Bs(m);const J=()=>{re()};return window.addEventListener("keydown",de,{capture:!0}),m.addEventListener("scroll",J,{passive:!0}),re(),()=>{window.removeEventListener("keydown",de,{capture:!0}),m.removeEventListener("scroll",J)}},[l,de,re]),{scrollPercentage:f.current.percentage,currentLine:f.current.line,currentColumn:f.current.column,totalLines:j,cursorLine:p,cursorCol:C,cursorModeActive:x,visualMode:d,selection:w,searchActive:z,searchQuery:G,searchMatches:F,currentMatchIndex:ae,startSearch:_,setSearchQuery:H,nextMatch:L,prevMatch:S,clearSearch:ge,helpActive:T,toggleHelp:A}}const Zt=({query:s,onQueryChange:n,matchCount:l,currentIndex:c,onNext:r,onPrev:i,onClose:f})=>{const{t:o}=le(["terminal"]),u=t.useRef(null);t.useEffect(()=>{var p;(p=u.current)==null||p.focus()},[]);const g=t.useCallback(p=>{p.stopPropagation(),p.key==="Enter"||p.key==="ArrowDown"?(p.preventDefault(),r()):p.key==="ArrowUp"&&(p.preventDefault(),i())},[r,i]),j=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${c+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:u,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:p=>n(p.target.value),onKeyDown:g,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:f,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};Zt.displayName="SearchBar";const ga=[{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"}],es=({onClose:s})=>{const{t:n}=le(["terminal"]),l=t.useCallback(i=>{i.target===i.currentTarget&&s()},[s]),c=t.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),s())},[s]),r=ga.reduce((i,f)=>(i[f.category]||(i[f.category]=[]),i[f.category].push(f),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:c,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(r).map(([i,f])=>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:f.map((o,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((g,j)=>e.jsx("kbd",{className:"keybindings-help-key",children:g},j))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},u))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};es.displayName="KeybindingsHelp";const Ps=t.lazy(()=>Dn(()=>import("./EmbeddedEditor-ByRepTwR.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),xa=[".md",".mdx",".markdown"],Is="file-viewer-markdown-render",ya=[".puml",".plantuml",".iuml",".pu"],Ls="file-viewer-plantuml-render",ba="https://kroki.io/plantuml/svg";function ja(s){return xa.includes(s.toLowerCase())}function va(s){return ya.includes(s.toLowerCase())}function wa(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Is);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Is,String(r))}catch{}return r})},[]);return[s,l]}function Ca(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Ls);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ls,String(r))}catch{}return r})},[]);return[s,l]}function Na(s){const n=new TextEncoder().encode(s);let l="";for(const c of n)l+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(l)}`}function Ge({file:s,rightContent:n,onRevealInTree:l,editMode:c,onToggleEdit:r}){const{t:i}=le(["terminal","common"]),[f,o]=t.useState("idle"),u=s.fileType==="text"?Mt(s.extension):s.extension.slice(1).toUpperCase(),{settings:g}=zs(),j=async()=>{o("loading");try{const p=await q(K("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,...g.externalEditorCommand&&{editorCommand:g.externalEditorCommand}})});if(!p.ok){const b=await p.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",b),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(p){console.error("Error opening file in editor:",p),o("error"),setTimeout(()=>o("idle"),2e3)}};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:[Os(s.size)," • ",u,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${c?" active":""}`,onClick:r,title:i(c?"terminal:fileExplorer.exitEdit":"terminal:fileExplorer.editFile"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L3.463 11.1a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.25.25 0 00.108-.064l8.61-8.61a.25.25 0 000-.354l-1.086-1.086z"})})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${f}`,onClick:j,disabled:f==="loading",title:i(f==="error"?"terminal:fileExplorer.failedToOpenEditor":f==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:f==="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"})}):f==="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 ka({file:s,onRevealInTree:n,renderMarkdown:l,onToggleRender:c,editMode:r,onToggleEdit:i}){const f=t.useRef(null),o=t.useRef(null),u=t.useRef(null),{t:g}=le(["terminal","common"]),[j,p]=t.useState("idle"),[b,C]=t.useState("idle"),[P,x]=t.useState("idle"),[k,d]=t.useState("idle"),v=_s({containerRef:u,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&f.current){const H=Mt(s.extension);As(H).then(()=>{f.current&&Gs(f.current)})}},[s,l]);const w=t.useCallback(async()=>{if(!o.current){p("error"),setTimeout(()=>p("idle"),2e3);return}try{const H=o.current.innerHTML,ae=Rn(H),ee=o.current.innerText;await Fn(ae,ee),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},[]),R=t.useCallback(async()=>{if(!o.current){C("error"),setTimeout(()=>C("idle"),2e3);return}try{const H=o.current.innerHTML;await Kt(H),C("copied"),setTimeout(()=>C("idle"),2e3)}catch{C("error"),setTimeout(()=>C("idle"),2e3)}},[]),z=t.useCallback(async()=>{try{await Kt(s.content),x("copied"),setTimeout(()=>x("idle"),2e3)}catch{x("error"),setTimeout(()=>x("idle"),2e3)}},[s.content]),O=t.useCallback(async()=>{try{await Kt(s.content),d("copied"),setTimeout(()=>d("idle"),2e3)}catch{d("error"),setTimeout(()=>d("idle"),2e3)}},[s.content]),G=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:w,title:g("terminal:fileExplorer.copyRichTextTitle"),children:g(j==="copied"?"terminal:fileExplorer.copied":j==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:R,title:g("terminal:fileExplorer.copyHtmlTitle"),children:g(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${P}`,onClick:z,title:g("terminal:fileExplorer.copyMarkdownTitle"),children:g(P==="copied"?"terminal:fileExplorer.copied":P==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${k}`,onClick:O,title:g("terminal:fileExplorer.copyOriginalTitle"),children:g(k==="copied"?"terminal:fileExplorer.copied":k==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:g(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:l?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ge,{file:s,onRevealInTree:n,rightContent:G,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[l?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:o,children:e.jsx(Pn,{remarkPlugins:[In],children:s.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:f,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(Zt,{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(es,{onClose:v.toggleHelp})]})}function Ea({file:s,onRevealInTree:n,renderPlantUml:l,onToggleRender:c,editMode:r,onToggleEdit:i}){const{t:f}=le(["terminal"]),o=t.useRef(null),u=t.useRef(null),[g,j]=t.useState(null),[p,b]=t.useState(!1),[C,P]=t.useState(null),x=_s({containerRef:u,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&o.current){const d=Mt(s.extension);As(d).then(()=>{o.current&&Gs(o.current)})}},[s,l]),t.useEffect(()=>{if(!l)return;if(!s.content.trim()){j(null),P("Diagram is empty");return}const d=new AbortController;return b(!0),P(null),(async()=>{try{const w=await fetch(ba,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:s.content,signal:d.signal});if(!w.ok)throw new Error(`Render failed (${w.status})`);const R=await w.text();if(!R.includes("<svg"))throw new Error("Invalid SVG output");j(Na(R))}catch(w){if(d.signal.aborted)return;const R=w instanceof Error?w.message:"Failed to render diagram";P(R),j(null)}finally{d.signal.aborted||b(!1)}})(),()=>d.abort()},[s.path,s.content,l]);const k=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:f(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:l?"</>":f("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(Ge,{file:s,onRevealInTree:n,rightContent:k,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[l?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[p&&e.jsx("div",{className:"file-viewer-placeholder",children:f("terminal:fileExplorer.renderingDiagram")}),!p&&g&&e.jsx("img",{src:g,alt:s.filename,className:"file-viewer-diagram-image"}),!p&&C&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[f("terminal:fileExplorer.couldNotRender"),": ",C]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:c,children:f("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 ${x.currentLine}/${x.totalLines}`,children:x.scrollPercentage===100?"END":x.scrollPercentage===0?"TOP":`${x.scrollPercentage}%`}),x.searchActive&&e.jsx(Zt,{query:x.searchQuery,onQueryChange:x.setSearchQuery,matchCount:x.searchMatches.length,currentIndex:x.currentMatchIndex,onNext:x.nextMatch,onPrev:x.prevMatch,onClose:x.clearSearch})]}),x.helpActive&&e.jsx(es,{onClose:x.toggleHelp})]})}function Sa({file:s,onRevealInTree:n}){const{t:l}=le(["common","terminal"]),c=()=>{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(Ge,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper",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 Ta({file:s,onRevealInTree:n}){const{t:l}=le(["common","terminal"]),c=()=>{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(Ge,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:s.dataUrl?e.jsx("iframe",{src:s.dataUrl,title:s.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadPdf")})})]})}function Ma({file:s,onRevealInTree:n}){const{t:l}=le(["terminal","common"]),c=()=>{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(Ge,{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:Os(s.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:l("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:c,children:l("terminal:fileExplorer.downloadFile")})]})]})}function Da({file:s,loading:n,error:l,onRevealInTree:c,onFileEdited:r}){const{t:i}=le(["terminal","common"]),[f,o]=wa(),[u,g]=Ca(),[j,p]=t.useState(!1);t.useEffect(()=>{p(!1)},[s==null?void 0:s.path]);const b=t.useCallback(async w=>{if(!s)return;const R=await q(K("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,content:w})});if(!R.ok){const z=await R.json().catch(()=>({error:"Save failed"}));throw new Error(z.error||"Save failed")}},[s]),C=t.useCallback(()=>{p(w=>(w&&s&&(r==null||r(s.path)),!w))},[s,r]),P=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 x=s.fileType||"text",k=x==="text"&&ja(s.extension),d=x==="text"&&va(s.extension),v=k||d;return v&&j&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ge,{file:s,onRevealInTree:c,editMode:!0,onToggleEdit:C}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Ps,{content:s.content,extension:s.extension,onSave:b,onCancel:C},s.path)})]}):x==="text"&&!v&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ge,{file:s,onRevealInTree:c}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Ps,{content:s.content,extension:s.extension,onSave:b,onCancel:P},s.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[k&&e.jsx(ka,{file:s,onRevealInTree:c,renderMarkdown:f,onToggleRender:o,editMode:j,onToggleEdit:C}),d&&!k&&e.jsx(Ea,{file:s,onRevealInTree:c,renderPlantUml:u,onToggleRender:g,editMode:j,onToggleEdit:C}),x==="image"&&e.jsx(Sa,{file:s,onRevealInTree:c}),x==="pdf"&&e.jsx(Ta,{file:s,onRevealInTree:c}),x==="binary"&&e.jsx(Ma,{file:s,onRevealInTree:c})]})}const Vs=t.memo(Da,(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);Vs.displayName="FileViewer";function Ks({text:s,query:n}){if(!n)return e.jsx(e.Fragment,{children:s});const l=Ln(s,n);if(l)return e.jsxs(e.Fragment,{children:[s.slice(0,l.start),e.jsx("mark",{className:"search-highlight",children:s.slice(l.start,l.end)}),s.slice(l.end)]});const c=n.toLowerCase(),i=s.toLowerCase().indexOf(c);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 Ra=t.memo(function({node:n,query:l,isSelected:c,onSelect:r,lineNumber:i}){const f=n.isDirectory?null:Xt(n),o=n.path.split("/");o[o.length-1];const u=o.slice(0,-1).join("/");return e.jsxs("div",{className:`search-result-item ${c?"selected":""}`,onClick:()=>r(n),children:[n.isDirectory?e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"folder",size:14})}):f?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${f}')`},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(Ks,{text:n.name,query:l}),i&&e.jsxs("span",{className:"search-result-line-badge",children:[":",i]})]}),e.jsx("span",{className:"search-result-path",children:u})]})]})}),Fa=t.memo(function({match:n,query:l,isSelected:c,onSelect:r}){const{t:i}=le(["terminal"]),f={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},o=Xt(f),u=n.path.split("/"),g=u[u.length-1],j=u.slice(0,-1).join("/");return e.jsxs("div",{className:`content-search-item ${c?"selected":""}`,children:[e.jsxs("div",{className:`content-search-header ${c?"selected":""}`,onClick:()=>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:g}),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((p,b)=>e.jsxs("div",{className:"content-search-match",onClick:()=>r(n.path,p.line),children:[e.jsx("span",{className:"content-search-line-num",children:p.line}),e.jsx("span",{className:"content-search-line-content",children:e.jsx(Ks,{text:p.content.trim(),query:l})})]},`${n.path}-${p.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 Pa({filenameResults:s,contentResults:n,onSelectFile:l,onSelectContent:c,selectedPath:r,query:i,lineNumber:f}){const{t:o}=le(["terminal"]),u=s.length>0,g=n.length>0;return!u&&!g?e.jsx("div",{className:"search-no-results",children:o("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[u&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:s.length})]}),e.jsx("div",{className:"unified-search-section-content",children:s.map(j=>e.jsx(Ra,{node:j,query:i,isSelected:r===j.path,onSelect:l,lineNumber:f},j.path))})]}),g&&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,p)=>j+p.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(j=>e.jsx(Fa,{match:j,query:i,isSelected:r===j.path,onSelect:c},j.path))})]})]})}const Ws=t.memo(Pa,(s,n)=>!(s.query!==n.query||s.selectedPath!==n.selectedPath||s.filenameResults.length!==n.filenameResults.length||s.contentResults.length!==n.contentResults.length));Ws.displayName="UnifiedSearchResults";const Ia=t.memo(function({file:n,isSelected:l,onSelect:c,onStage:r,isStaging:i,showDirPath:f,isChecked:o,onToggleCheck:u,onContextMenu:g,onDiscard:j}){const{t:p}=le(["terminal"]),b=n.status,C=pt[b],P=b==="deleted",x=b==="untracked"&&r,k=n.name.includes(".")?"."+n.name.split(".").pop():"",d=f&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!P&&c(n.path,b),onContextMenu:v=>{v.preventDefault(),g==null||g(v,n,b)},style:{cursor:P?"not-allowed":"pointer"},title:n.path,children:[u&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:o||!1,onChange:v=>{v.stopPropagation(),u(n.path)},onClick:v=>v.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:ft(k),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,d&&e.jsx("span",{className:"git-file-dir",children:d})]}),e.jsx("span",{className:"git-file-status",style:{color:C.color},children:C.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()]}),x&&e.jsx("button",{className:`git-stage-btn ${i?"staging":""}`,onClick:v=>{v.stopPropagation(),i||r(n.path)},title:p("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})})]})}),La=16,$a=22,Ha=t.memo(function s({node:n,depth:l,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:f,onStage:o,stagingPaths:u,checkedFiles:g,onToggleCheck:j,onContextMenu:p,onDirContextMenu:b,onDiscard:C}){const{t:P}=le(["terminal"]),x=l*La;if(!n.isDirectory){const d=n.file.status,v=pt[d];return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>d!=="deleted"&&f(n.file.path,d),onContextMenu:w=>{w.preventDefault(),p==null||p(w,n.file,d)},style:{paddingLeft:`${x+$a}px`,cursor:d==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[j&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(g==null?void 0:g.has(n.file.path))||!1,onChange:w=>{w.stopPropagation(),j(n.file.path)},onClick:w=>w.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:ft(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()]}),d==="untracked"&&o&&e.jsx("button",{className:`git-stage-btn ${u!=null&&u.has(n.path)?"staging":""}`,onClick:w=>{w.stopPropagation(),u!=null&&u.has(n.path)||o(n.file.path)},title:P("terminal:fileExplorer.stageFile"),disabled:u==null?void 0:u.has(n.path),children:u!=null&&u.has(n.path)?"...":"+"}),C&&e.jsx("button",{className:"git-discard-btn",onClick:w=>{w.stopPropagation(),C(n.file,d)},title:d==="untracked"||d==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}const k=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${k?"expanded":""}`,style:{paddingLeft:`${x}px`},onClick:()=>r(n.path),onContextMenu:d=>{d.preventDefault(),d.stopPropagation(),b==null||b(d,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:P("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),k&&e.jsx("div",{className:"tree-children",children:n.children.map(d=>e.jsx(s,{node:d,depth:l+1,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:f,onStage:o,stagingPaths:u,checkedFiles:g,onToggleCheck:j,onContextMenu:p,onDirContextMenu:b,onDiscard:C},d.path))})]})}),Jt=t.memo(function({groupLabel:n,groupIcon:l,groupColor:c,files:r,treeNodes:i,viewMode:f,selectedPath:o,expandedDirs:u,onToggleDir:g,onFileSelect:j,onStageFile:p,onStageAll:b,stagingPaths:C,checkedFiles:P,onToggleCheck:x,onContextMenu:k,onDirContextMenu:d,onDiscardFile:v,onDiscardAll:w}){const{t:R}=le(["terminal"]);if(r.length===0)return null;const z=r.some(H=>H.status==="untracked"),O=z&&b&&r.length>0,G=C?r.every(H=>C.has(H.path)):!1;return e.jsxs("div",{className:"git-status-group",children:[e.jsxs("div",{className:"git-status-group-header",style:{color:c},children:[e.jsx("span",{className:"git-status-badge",style:{background:c},children:l}),n," (",r.length,")",O&&e.jsx("button",{className:`git-stage-all-btn ${G?"staging":""}`,onClick:H=>{H.stopPropagation(),G||b()},title:R("terminal:fileExplorer.stageAllUntracked"),disabled:G,children:G?"...":R("terminal:fileExplorer.stageAll")}),w&&e.jsxs("button",{className:"git-discard-all-btn",onClick:H=>{H.stopPropagation(),w()},title:z?`Delete all ${r.length} files`:`Discard all ${r.length} changes`,children:[e.jsx(M,{name:"revert",size:12})," All"]})]}),f==="tree"?e.jsx("div",{className:"git-tree-content",children:i.map(H=>e.jsx(Ha,{node:H,depth:0,expandedDirs:u,onToggleDir:g,selectedPath:o,onSelect:j,onStage:p,stagingPaths:C,checkedFiles:P,onToggleCheck:x,onContextMenu:k,onDirContextMenu:d,onDiscard:v},H.path))}):e.jsx("div",{className:"git-flat-content",children:r.map(H=>e.jsx(Ia,{file:H,isSelected:o===H.path,onSelect:j,onStage:H.status==="untracked"?p:void 0,isStaging:C==null?void 0:C.has(H.path),showDirPath:!0,isChecked:P==null?void 0:P.has(H.path),onToggleCheck:x,onContextMenu:k,onDiscard:v},H.path))})]})});function za({gitStatus:s,loading:n,onFileSelect:l,selectedPath:c,onRefresh:r,onStageFiles:i,stagingPaths:f,currentFolder:o,onCommitComplete:u,mergeInProgress:g,mergingBranch:j,onMergeContinue:p,onMergeAbort:b,onConflictOpen:C,onRevealInTree:P}){const{t:x}=le(["terminal","common"]),[k,d]=t.useState("tree"),[v,w]=t.useState(new Set),[R,z]=t.useState(""),[O,G]=t.useState(""),[H,ae]=t.useState(!1),[ee,T]=t.useState(new Set),[D,F]=t.useState(!1),[re,_]=t.useState(null),ge=t.useRef(null),{showToast:A}=Us(),[Z,L]=t.useState(null),[S,W]=t.useState(null),[se,be]=t.useState(null),de=t.useCallback((N,I)=>{be({files:[N],label:N.name})},[]),m=t.useCallback(async()=>{if(!(!se||!o))try{const N=await q(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:se.files.map(B=>({path:B.path,status:B.status})),directory:o})}),I=await N.json();N.ok&&I.success?(A("success","Discarded",`Reverted ${se.files.length} file(s)`),r()):A("error","Discard Failed",I.error||"Could not discard changes")}catch{A("error","Discard Failed","Network error")}finally{be(null)}},[se,o,r,A]),J=t.useCallback((N,I,B)=>{N.preventDefault(),N.stopPropagation(),L({isOpen:!0,position:{x:N.clientX,y:N.clientY},file:I,status:B})},[]),ie=t.useCallback(async(N,I)=>{if(o)try{const B=await q(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:N.path,status:I}],directory:o})}),ke=await B.json();B.ok&&ke.success?(A("success","Discarded",`Restored ${N.name}`),r()):A("error","Discard Failed",ke.error||"Could not discard changes")}catch{A("error","Discard Failed","Network error")}},[o,r,A]),ue=t.useCallback(async N=>{try{await navigator.clipboard.writeText(N),A("success","Copied","Full path copied")}catch{A("error","Copy Failed","Could not copy path")}},[A]),V=t.useCallback(async N=>{const I=o&&N.startsWith(o+"/")?N.slice(o.length+1):N;try{await navigator.clipboard.writeText(I),A("success","Copied","Relative path copied")}catch{A("error","Copy Failed","Could not copy path")}},[o,A]),E=t.useMemo(()=>{if(!Z)return[];const{file:N,status:I}=Z,B=[];return I==="conflict"&&C?B.push({id:"open-conflict",label:x("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>C(N.path)}):I!=="deleted"&&B.push({id:"open-file",label:x("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>l(N.path,I)}),I!=="conflict"&&B.push({id:"stage-file",label:x("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i([N.path])}}),B.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(I==="modified"||I==="deleted"||I==="renamed"||I==="conflict")&&B.push({id:"discard-changes",label:x("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{ie(N,I)}}),(I==="untracked"||I==="added")&&B.push({id:"delete-file",label:x("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{ie(N,I)}}),B.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),B.push({id:"copy-full-path",label:x("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{ue(N.path)}}),B.push({id:"copy-relative-path",label:x("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{V(N.path)}}),P&&I!=="deleted"&&B.push({id:"reveal-in-tree",label:x("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>P(N.path)}),B},[Z,l,i,C,P,ie,ue,V,x]),Q=t.useCallback((N,I)=>{N.preventDefault(),N.stopPropagation(),W({isOpen:!0,position:{x:N.clientX,y:N.clientY},node:I})},[]),te=t.useCallback(N=>!N.isDirectory&&N.file?[N.file]:N.children.flatMap(I=>te(I)),[]),Ne=t.useCallback(async N=>{if(!o)return;const I=te(N);if(I.length!==0)try{const B=await q(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:I.map(Te=>({path:Te.path,status:Te.status})),directory:o})}),ke=await B.json();B.ok&&ke.success?(A("success","Discarded",`Reverted ${I.length} file(s) in ${N.name}`),r()):A("error","Discard Failed",ke.error||"Could not discard changes")}catch{A("error","Discard Failed","Network error")}},[o,te,r,A]),xe=t.useMemo(()=>{if(!S)return[];const{node:N}=S,I=te(N);return[{id:"discard-dir",label:`Discard Changes (${I.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{Ne(N)}},{id:"stage-dir",label:`Stage All (${I.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i(I.map(B=>B.path))}}]},[S,te,Ne,i]),U=t.useCallback(N=>{w(I=>{const B=new Set(I);return B.has(N)?B.delete(N):B.add(N),B})},[]),{conflictFiles:ne,conflictTree:pe,changesFiles:me,changesTree:Ue,untrackedFiles:Se,untrackedTree:Dt,allDirPaths:$e}=t.useMemo(()=>{if(!s||!s.isGitRepo||s.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const N=new Set,I=s.files.filter(Re=>Re.status==="conflict"),B=Et(I);St(B,N);const ke=s.files.filter(Re=>Re.status==="modified"||Re.status==="added"||Re.status==="deleted"||Re.status==="renamed"),Te=Et(ke);St(Te,N);const ot=s.files.filter(Re=>Re.status==="untracked"),Ke=Et(ot);return St(Ke,N),{conflictFiles:I,conflictTree:B,changesFiles:ke,changesTree:Te,untrackedFiles:ot,untrackedTree:Ke,allDirPaths:N}},[s]);t.useEffect(()=>{w($e)},[$e]),t.useEffect(()=>{s!=null&&s.files&&T(new Set(s.files.map(N=>N.path)))},[s==null?void 0:s.files]);const Rt=t.useCallback(()=>{me.length!==0&&be({files:me,label:`${me.length} changed files`})},[me]),Be=t.useCallback(()=>{Se.length!==0&&be({files:Se,label:`${Se.length} unversioned files`})},[Se]),Ft=t.useCallback(()=>{ne.length!==0&&be({files:ne,label:`${ne.length} conflicted files`})},[ne]),_e=ne.length>0;t.useEffect(()=>{if(re){const N=re.type==="error"?8e3:4e3,I=setTimeout(()=>_(null),N);return()=>clearTimeout(I)}},[re]);const gt=t.useCallback(async()=>{const N=!H;if(ae(N),N&&o){G(R);try{const B=await(await q(K(`/api/files/git-log-message?path=${encodeURIComponent(o)}`))).json();B.message&&z(B.message)}catch{}}else z(O)},[H,o,R,O]),je=t.useCallback(N=>{T(I=>{const B=new Set(I);return B.has(N)?B.delete(N):B.add(N),B})},[]),Pt=t.useCallback(()=>{if(!(s!=null&&s.files))return;const N=s.files.map(B=>B.path),I=N.every(B=>ee.has(B));T(I?new Set:new Set(N))},[s==null?void 0:s.files,ee]),ve=t.useCallback(async N=>{if(!(!o||!R.trim()||ee.size===0||D)){F(!0),_(null);try{const I=await q(K("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o,message:R.trim(),amend:H,paths:Array.from(ee)})}),B=await I.json();if(!I.ok||!B.success){_({type:"error",text:B.error||"Commit failed"}),F(!1);return}if(N)try{const ke=await q(K("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o})}),Te=await ke.json();ke.ok&&Te.success?_({type:"success",text:x("terminal:fileExplorer.committedAndPushed")}):_({type:"error",text:x("terminal:fileExplorer.committedButPushFailed",{error:Te.error||"Unknown error"})})}catch{_({type:"error",text:x("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else _({type:"success",text:x("terminal:fileExplorer.committedSuccessfully")});z(""),G(""),ae(!1),r(),u==null||u()}catch(I){_({type:"error",text:I.message||"Commit failed"})}finally{F(!1)}}},[o,R,H,ee,D,r,u]);if(n)return e.jsx("div",{className:"git-changes-loading",children:x("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:x("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:x("terminal:fileExplorer.workingTreeClean")}),e.jsx("div",{className:"git-empty-branch",children:x("terminal:fileExplorer.onBranch",{branch:s.branch})})]});const xt=N=>{i([N])},Ve=()=>{const N=Se.map(I=>I.path);N.length>0&&i(N)},De=(N,I)=>{I==="conflict"&&C?C(N):l(N,I)};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:()=>d("flat"),title:x("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:()=>d("tree"),title:x("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:x("common:buttons.refresh"),children:e.jsx(M,{name:"refresh",size:12})})]}),g&&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:x("terminal:fileExplorer.mergeInProgress",{branch:j?` (${j})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:p,disabled:_e,title:x(_e?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:x("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:b,title:x("terminal:fileExplorer.abortMerge"),children:x("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(Jt,{groupLabel:x("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:ne,treeNodes:pe,viewMode:k,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,checkedFiles:ee,onToggleCheck:je,onContextMenu:J,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:Ft}),e.jsx(Jt,{groupLabel:x("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:me,treeNodes:Ue,viewMode:k,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,checkedFiles:ee,onToggleCheck:je,onContextMenu:J,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:Rt}),e.jsx(Jt,{groupLabel:x("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:Se,treeNodes:Dt,viewMode:k,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,onStageFile:xt,onStageAll:Ve,stagingPaths:f,checkedFiles:ee,onToggleCheck:je,onContextMenu:J,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:Be})]}),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:H,onChange:gt}),x("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:x("terminal:fileExplorer.fileCount",{count:ee.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:Pt,title:ee.size===s.files.length?x("terminal:fileExplorer.deselectAll"):x("terminal:fileExplorer.selectAll"),children:ee.size===s.files.length?x("terminal:fileExplorer.deselectAll"):x("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:ge,className:"git-commit-message",placeholder:x("terminal:fileExplorer.commitMessagePlaceholder"),value:R,onChange:N=>z(N.target.value),onKeyDown:N=>{(N.metaKey||N.ctrlKey)&&N.key==="Enter"&&(N.preventDefault(),ve(!1)),(N.metaKey||N.ctrlKey)&&N.shiftKey&&N.key==="Enter"&&(N.preventDefault(),ve(!0)),N.stopPropagation()},rows:3,disabled:D}),re&&e.jsx("div",{className:`git-commit-status ${re.type}`,children:re.text}),e.jsxs("div",{className:"git-commit-actions",children:[e.jsx("button",{className:"git-commit-btn",onClick:()=>ve(!1),disabled:!R.trim()||ee.size===0||D,title:x("terminal:fileExplorer.commitCtrlEnter"),children:x(D?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>ve(!0),disabled:!R.trim()||ee.size===0||D,title:x("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:D?"...":x("terminal:fileExplorer.commitAndPush")})]})]}),Z&&e.jsx(it,{isOpen:Z.isOpen,position:Z.position,worldPosition:{x:0,z:0},actions:E,onClose:()=>L(null)}),S&&e.jsx(it,{isOpen:S.isOpen,position:S.position,worldPosition:{x:0,z:0},actions:xe,onClose:()=>W(null)}),se&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>be(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:N=>N.stopPropagation(),children:[e.jsx("p",{children:se.files.some(N=>N.status==="untracked"||N.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:se.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:se.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:()=>be(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:m,children:se.files.some(N=>N.status==="untracked"||N.status==="added")?"Delete":"Discard"})]})]})})]})}const qs=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));qs.displayName="GitChanges";const Oa=t.memo(function({tab:n,isActive:l,onSelect:c,onClose:r,onContextMenu:i}){const{t:f}=le(["terminal"]),o={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},u=t.useCallback(()=>{c(n.path)},[c,n.path]),g=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]),p=t.useCallback(b=>{b.preventDefault(),b.stopPropagation(),i(b,n)},[i,n]);return e.jsxs("div",{className:`file-tab ${l?"active":""}`,onClick:u,onMouseDown:g,onContextMenu:p,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:Xt(o),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:j,title:f("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function Aa(s){return typeof s.path=="string"&&s.path.startsWith("/")}function Ga({tabs:s,activeTabPath:n,onSelectTab:l,onCloseTab:c,onShowGitHistory:r}){const{t:i}=le(["terminal"]),[f,o]=t.useState(null),u=t.useCallback((p,b)=>{o({isOpen:!0,position:{x:p.clientX,y:p.clientY},tab:b})},[]),g=t.useCallback(()=>o(null),[]),j=t.useMemo(()=>{if(!f)return[];const p=f.tab,b=!!r&&Aa(p);return[{id:"git-history",label:i("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!b,onClick:()=>{b&&r(p.path)}}]},[f,r,i]);return s.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:s.map(p=>e.jsx(Oa,{tab:p,isActive:n===p.path,onSelect:l,onClose:c,onContextMenu:u},p.path))}),f&&e.jsx(it,{isOpen:f.isOpen,position:f.position,worldPosition:{x:0,z:0},actions:j,onClose:g})]})}const Js=t.memo(Ga,(s,n)=>{if(s.activeTabPath!==n.activeTabPath||s.tabs.length!==n.tabs.length||s.onShowGitHistory!==n.onShowGitHistory)return!1;for(let l=0;l<s.tabs.length;l++)if(s.tabs[l].path!==n.tabs[l].path)return!1;return!0});Js.displayName="FileTabs";const Ua=t.memo(function({currentFolder:n,gitStatus:l,onBranchChanged:c,onMerge:r,onCompare:i,onPullConflicts:f}){const{t:o}=le(["terminal","common"]),[u,g]=t.useState(!1),[j,p]=t.useState(""),[b,C]=t.useState(!1),[P,x]=t.useState(""),[k,d]=t.useState(!1),[v,w]=t.useState(null),[R,z]=t.useState(null),O=t.useRef(null),G=t.useRef(null),H=t.useRef(null),{branches:ae,loading:ee,operationInProgress:T,loadBranches:D,checkoutBranch:F,createBranch:re,pullFromRemote:_,pushToRemote:ge}=Qt();t.useEffect(()=>{u&&n&&(D(n),setTimeout(()=>{var E;return(E=G.current)==null?void 0:E.focus()},50)),u||(p(""),C(!1),x(""),w(null))},[u,n,D]),t.useEffect(()=>{if(v){const E=v.type==="error"?8e3:3e3,Q=setTimeout(()=>w(null),E);return()=>clearTimeout(Q)}},[v]),t.useEffect(()=>{b&&setTimeout(()=>{var E;return(E=H.current)==null?void 0:E.focus()},50)},[b]),t.useEffect(()=>{if(!u)return;const E=te=>{const Ne=te.target;!Ne.closest(".branch-widget-selector")&&!Ne.closest(".branch-widget-dropdown")&&g(!1)},Q=te=>{te.key==="Escape"&&(te.preventDefault(),te.stopPropagation(),g(!1))};return document.addEventListener("click",E),document.addEventListener("keydown",Q,!0),()=>{document.removeEventListener("click",E),document.removeEventListener("keydown",Q,!0)}},[u]);const A=t.useCallback(async E=>{if(!n||T||E.isCurrent)return;const Q=await F(n,E.name);Q.success?(w({type:"success",text:o("terminal:fileExplorer.switchedToBranch",{branch:Q.branch||E.name})}),c(),D(n)):w({type:"error",text:Q.error||o("terminal:fileExplorer.checkoutFailed")})},[n,T,F,c,D]),Z=t.useCallback(async()=>{if(!n||!P.trim()||T)return;const E=await re(n,P.trim());E.success?(w({type:"success",text:o("terminal:fileExplorer.createdBranch",{branch:E.branch})}),C(!1),x(""),c(),D(n)):w({type:"error",text:E.error||o("terminal:fileExplorer.createBranchFailed")})},[n,P,T,re,c,D]),L=t.useCallback(async()=>{if(!n||T)return;const E=await _(n);E.success?(E.stashConflicts&&E.stashConflicts.length>0?(w({type:"error",text:`Pull succeeded but stash pop had conflicts: ${E.stashConflicts.length} file(s). Resolve manually.`}),f==null||f(E.stashConflicts),g(!1)):E.stashed?w({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):w({type:"success",text:o("terminal:fileExplorer.pullComplete")}),c(),D(n)):E.conflicts&&E.conflicts.length>0?(w({type:"error",text:`Pull conflicts: ${E.conflicts.length} file(s)`}),f==null||f(E.conflicts),g(!1)):w({type:"error",text:E.error||o("terminal:fileExplorer.pullFailed")})},[n,T,_,c,D,f]),S=t.useCallback(async()=>{if(!n||T)return;const E=await ge(n);E.success?w({type:"success",text:o("terminal:fileExplorer.pushComplete")}):w({type:"error",text:E.error||o("terminal:fileExplorer.pushFailed")})},[n,T,ge]),[W,se]=t.useState(!1),be=t.useCallback(async()=>{if(!(!n||T||W)){se(!0);try{const E=await q(K("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(E.ok)w({type:"success",text:"Fetch complete"}),c(),D(n);else{const Q=await E.json().catch(()=>({error:"Fetch failed"}));w({type:"error",text:Q.error||"Fetch failed"})}}catch{w({type:"error",text:"Fetch failed"})}finally{se(!1)}}},[n,T,W,c,D]),de=(l==null?void 0:l.branch)||"unknown",m=!!T,J=t.useCallback((E,Q)=>{Q.isCurrent||(E.preventDefault(),E.stopPropagation(),z({isOpen:!0,position:{x:E.clientX,y:E.clientY},branch:Q.name}))},[]),ie=t.useMemo(()=>{if(!R)return[];const E=!!T||(l==null?void 0:l.mergeInProgress);return[{id:"compare",label:o("terminal:fileExplorer.showDiffWith",{branch:R.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!T,onClick:()=>{i==null||i(R.branch),g(!1)}},{id:"merge",label:o("terminal:fileExplorer.mergeInto",{source:R.branch,target:de}),icon:"⤵",disabled:!!E,onClick:()=>{r&&r(R.branch),g(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:o("terminal:fileExplorer.checkoutBranch",{branch:R.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!T,onClick:()=>{const Q=ae.find(te=>te.name===R.branch);Q&&A(Q)}}]},[R,T,l==null?void 0:l.mergeInProgress,de,r,i,ae,A]),ue=t.useMemo(()=>{const E=ae.filter(te=>!te.isRemote);if(!j)return E;const Q=j.toLowerCase();return E.filter(te=>te.name.toLowerCase().includes(Q))},[ae,j]),V=t.useMemo(()=>{const E=ae.filter(te=>te.isRemote);if(!j)return E;const Q=j.toLowerCase();return E.filter(te=>te.name.toLowerCase().includes(Q))},[ae,j]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:E=>{E.stopPropagation(),g(!u)},title:`Branch: ${de}`,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:de}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),u&&e.jsxs("div",{className:"branch-widget-dropdown",ref:O,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:G,type:"text",className:"branch-widget-search-input",placeholder:o("terminal:fileExplorer.searchBranches"),value:j,onChange:E=>p(E.target.value),onKeyDown:E=>E.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 ${m||W?"disabled":""}`,onClick:be,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:W?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:L,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 ${m?"disabled":""}`,onClick:S,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 ${m?"disabled":""}`,onClick:()=>{m||C(!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:H,type:"text",className:"branch-widget-new-branch-input",placeholder:o("terminal:fileExplorer.branchNamePlaceholder"),value:P,onChange:E=>x(E.target.value),onKeyDown:E=>{E.stopPropagation(),E.key==="Enter"&&Z(),E.key==="Escape"&&(C(!1),x(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:Z,disabled:!P.trim()||m,children:T==="create"?"...":o("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[o("terminal:fileExplorer.localBranches"),ee&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",o("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[ue.length===0&&!ee&&e.jsx("div",{className:"branch-widget-empty",children:o("terminal:fileExplorer.noBranchesFound")}),ue.map(E=>e.jsxs("div",{className:`branch-widget-branch-item ${E.isCurrent?"current":""} ${m?"disabled":""}`,onClick:()=>A(E),onContextMenu:Q=>J(Q,E),title:E.lastMessage||E.name,children:[e.jsxs("span",{className:"branch-widget-branch-name",children:[E.isCurrent&&e.jsx("span",{className:"branch-widget-current-marker",children:"*"}),E.name]}),E.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:E.lastCommit})]},E.name))]}),V.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>d(!k),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:k?"▾":"▸"}),o("terminal:fileExplorer.remoteBranches",{count:V.length})]}),k&&e.jsx("div",{className:"branch-widget-branch-list",children:V.map(E=>e.jsxs("div",{className:`branch-widget-branch-item remote ${m?"disabled":""}`,onClick:()=>A(E),onContextMenu:Q=>J(Q,E),title:E.lastMessage||E.name,children:[e.jsx("span",{className:"branch-widget-branch-name",children:E.name}),E.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:E.lastCommit})]},E.name))})]})]}),R&&e.jsx(it,{isOpen:R.isOpen,position:R.position,worldPosition:{x:0,z:0},actions:ie,onClose:()=>z(null)})]})});function Ba(s){return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function kt(s,n){if(!s)return"";const l=Es.languages[n];return l?Es.highlight(s,l,n):Ba(s)}function _a(s){const n=[],l=s.split(`
9
+ `);let c=[],r=!1,i=[],f=[],o=!1;for(const u of l)u.startsWith("<<<<<<<")?(c.length>0&&(n.push({type:"unchanged",content:c.join(`
10
+ `)}),c=[]),r=!0,o=!1,i=[],f=[]):u.startsWith("=======")&&r?o=!0:u.startsWith(">>>>>>>")&&r?(n.push({type:"conflict",ours:i.join(`
11
+ `),theirs:f.join(`
12
+ `),resolved:null}),r=!1,o=!1):r?o?f.push(u):i.push(u):c.push(u);return c.length>0&&n.push({type:"unchanged",content:c.join(`
13
+ `)}),n}const Va=t.memo(function({file:n,versions:l,loading:c,onResolve:r,onClose:i,currentBranch:f,mergingBranch:o}){const{t:u}=le(["terminal"]),g=t.useMemo(()=>{var D;if(!(l!=null&&l.filename))return"plaintext";const T="."+((D=l.filename.split(".").pop())==null?void 0:D.toLowerCase());return Mt(T)},[l==null?void 0:l.filename]),j=t.useMemo(()=>l!=null&&l.merged?_a(l.merged):[],[l==null?void 0:l.merged]),[p,b]=t.useState(j),[C,P]=t.useState(!1);t.useMemo(()=>{b(j)},[j]);const x=t.useRef(null),[k,d]=t.useState(0),v=t.useMemo(()=>p.map((T,D)=>T.type==="conflict"?D:-1).filter(T=>T!==-1),[p]),w=v.length,R=t.useCallback(T=>{const D=x.current;if(!D||T<0||T>=v.length)return;const F=v[T],re=D.querySelector(`[data-section-idx="${F}"]`);re&&(re.scrollIntoView({behavior:"smooth",block:"center"}),d(T))},[v]),z=t.useCallback(()=>{R(k>0?k-1:v.length-1)},[k,v.length,R]),O=t.useCallback(()=>{R(k<v.length-1?k+1:0)},[k,v.length,R]);t.useEffect(()=>{if(v.length>0&&x.current){const T=setTimeout(()=>R(0),100);return()=>clearTimeout(T)}},[v.length,R]);const G=t.useMemo(()=>{const T=p.filter(D=>D.type==="conflict");return T.length>0&&T.every(D=>D.resolved!==null)},[p]),H=t.useCallback((T,D)=>{b(F=>F.map((re,_)=>_!==T||re.type!=="conflict"?re:{...re,resolved:D}))},[]),ae=t.useCallback(T=>{b(D=>D.map(F=>F.type!=="conflict"?F:{...F,resolved:T}))},[]),ee=t.useCallback(async()=>{P(!0);try{const T=p.map(D=>D.type==="unchanged"?D.content:D.resolved==="ours"?D.ours:D.resolved==="theirs"?D.theirs:D.resolved==="both"?D.ours+`
14
+ `+D.theirs:`<<<<<<< ${f}
15
+ ${D.ours}
16
+ =======
17
+ ${D.theirs}
18
+ >>>>>>> ${o}`).join(`
19
+ `);await r(T)}finally{P(!1)}},[p,r,f,o]);return e.jsxs("div",{className:"conflict-resolver",children:[e.jsxs("div",{className:"conflict-header",children:[e.jsx("span",{className:"conflict-header-title",children:u("terminal:fileExplorer.resolveFile",{filename:l==null?void 0:l.filename})}),w>0&&e.jsxs("div",{className:"conflict-nav",children:[e.jsx("button",{className:"conflict-nav-btn",onClick:z,title:u("terminal:fileExplorer.prevConflict"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsxs("span",{className:"conflict-nav-counter",children:[k+1," / ",w]}),e.jsx("button",{className:"conflict-nav-btn",onClick:O,title:u("terminal:fileExplorer.nextConflict"),children:e.jsx(M,{name:"caret-down",size:10})})]}),e.jsx("button",{className:"conflict-close-btn",onClick:i,children:"×"})]}),c||!l?e.jsx("div",{className:"conflict-loading",children:u("terminal:fileExplorer.loadingConflictData")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"conflict-pane-headers",children:[e.jsx("div",{className:"conflict-pane-header current",children:u("terminal:fileExplorer.currentBranchLabel",{branch:f})}),e.jsx("div",{className:"conflict-pane-header incoming",children:u("terminal:fileExplorer.incomingBranchLabel",{branch:o})})]}),e.jsx("div",{className:"conflict-content",ref:x,children:p.map((T,D)=>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:kt(T.content,g)}})}),e.jsx("div",{className:"conflict-pane theirs",children:e.jsx("pre",{dangerouslySetInnerHTML:{__html:kt(T.content,g)}})})]})},D):e.jsxs("div",{"data-section-idx":D,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:kt(T.ours,g)}}),e.jsx("button",{className:"conflict-accept-btn ours",onClick:()=>H(D,"ours"),disabled:T.resolved==="ours",children:T.resolved==="ours"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptCurrent")})]}),e.jsxs("div",{className:`conflict-pane theirs ${T.resolved==="theirs"||T.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:kt(T.theirs,g)}}),e.jsx("button",{className:"conflict-accept-btn theirs",onClick:()=>H(D,"theirs"),disabled:T.resolved==="theirs",children:T.resolved==="theirs"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptIncoming")})]})]}),e.jsx("button",{className:`conflict-accept-both-btn ${T.resolved==="both"?"accepted":""}`,onClick:()=>H(D,"both"),disabled:T.resolved==="both",children:T.resolved==="both"?u("terminal:fileExplorer.accepted"):u("terminal:fileExplorer.acceptBoth")})]},D))}),e.jsxs("div",{className:"conflict-actions",children:[e.jsx("button",{className:"conflict-action-btn accept-all-current",onClick:()=>ae("ours"),children:u("terminal:fileExplorer.acceptAllCurrent")}),e.jsx("button",{className:"conflict-action-btn accept-all-incoming",onClick:()=>ae("theirs"),children:u("terminal:fileExplorer.acceptAllIncoming")}),e.jsx("button",{className:"conflict-action-btn accept-all-both",onClick:()=>ae("both"),children:u("terminal:fileExplorer.acceptAllBoth")}),e.jsx("button",{className:"conflict-action-btn save-resolved",onClick:ee,disabled:!G||C,children:u(C?"terminal:fileExplorer.saving":"terminal:fileExplorer.saveAndResolve")})]})]})]})}),Ka=16,Wa=t.memo(function s({node:n,depth:l,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:f}){const{t:o}=le(["terminal"]),u=l*Ka;if(!n.isDirectory){const j=n.file.status,p=pt[j],b=j==="deleted",C=n.file.name.includes(".")?"."+n.file.name.split(".").pop():"";return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>!b&&f(n.file.path,j),style:{paddingLeft:`${u+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:ft(C),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:p.color},children:p.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:["← ",n.file.oldPath.split("/").pop()]})]})}const g=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${g?"expanded":""}`,style:{paddingLeft:`${u+4}px`},onClick:()=>r(n.path),children:[e.jsx("span",{className:`tree-arrow ${g?"expanded":""}`,children:"►"}),e.jsx("img",{className:"tree-folder-icon",src:g?"/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})})]}),g&&e.jsx("div",{className:"tree-children",children:n.children.map(j=>e.jsx(s,{node:j,depth:l+1,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:f},j.path))})]})}),qa=t.memo(function({file:n,isSelected:l,onSelect:c}){const r=pt[n.status],i=n.status==="deleted",f=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&&c(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:ft(f),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 Ja({compareResult:s,loading:n,onFileSelect:l,selectedPath:c,onClose:r}){const{t:i}=le(["terminal"]),[f,o]=t.useState("tree"),[u,g]=t.useState(new Set),j=t.useMemo(()=>!s||s.files.length===0?[]:Et(s.files),[s]),p=t.useMemo(()=>{const w=new Set;return St(j,w),w},[j]);t.useEffect(()=>{g(p)},[p]);const b=t.useCallback(w=>{g(R=>{const z=new Set(R);return z.has(w)?z.delete(w):z.add(w),z})},[]),C=t.useMemo(()=>s?[...s.files].sort((w,R)=>w.path.toLowerCase().localeCompare(R.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:P,counts:x,baseBranch:k,currentBranch:d}=s,v=P.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:[d," 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:["⇔ ",d," 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:[x.modified>0&&e.jsxs("span",{className:"git-count modified",children:[x.modified,"M"]}),x.added>0&&e.jsxs("span",{className:"git-count added",children:[x.added,"A"]}),x.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[x.deleted,"D"]}),x.renamed>0&&e.jsxs("span",{className:"git-count renamed",children:[x.renamed,"R"]}),(x.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[x.conflict,"C"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${f==="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 ${f==="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:f==="tree"?j.map(w=>e.jsx(Wa,{node:w,depth:0,expandedDirs:u,onToggleDir:b,selectedPath:c,onSelect:l},w.path)):C.map(w=>e.jsx(qa,{file:w,isSelected:c===w.path,onSelect:l},w.path))})]})}const Ys=t.memo(Ja);Ys.displayName="BranchComparison";function Ya(s){const n=new Date(s);if(isNaN(n.getTime()))return s||"—";const c=Date.now()-n.getTime(),r=Math.floor(c/6e4),i=Math.floor(r/60),f=Math.floor(i/24);if(f<4)return r<1?"just now":r<60?`${r}m ago`:i<24?`${i}h ago`:`${f}d ago`;const o=n.getFullYear(),u=String(n.getMonth()+1).padStart(2,"0"),g=String(n.getDate()).padStart(2,"0"),j=String(n.getHours()).padStart(2,"0"),p=String(n.getMinutes()).padStart(2,"0");return`${o}-${u}-${g} ${j}:${p}`}const Xa=t.memo(function({commit:n,isSelected:l,onSelect:c}){return e.jsxs("div",{className:`gh-row ${l?"selected":""}`,onClick:()=>c(n),children:[e.jsx("span",{className:"gh-col-hash",children:n.shortHash}),e.jsxs("span",{className:"gh-col-message",children:[e.jsx("span",{className:"gh-subject",children:n.subject}),n.refs.isHead&&e.jsx("span",{className:"gh-badge gh-badge-head",children:"HEAD"}),n.refs.branches.map(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:Ya(n.date)})]})}),Qa=t.memo(function({files:n,loading:l,selectedFilePath:c,onSelectFile:r}){const{t:i}=le(["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(f=>{const o=f.path.split("/").pop()||f.path,u=f.path.includes("/")?f.path.substring(0,f.path.lastIndexOf("/")):"",g=pt[f.status],j=o.includes(".")?"."+o.split(".").pop():"";return e.jsxs("div",{className:`gh-file-row ${c===f.path?"selected":""}`,onClick:()=>r==null?void 0:r(f.path),title:f.path,children:[e.jsx("span",{className:"gh-file-status",style:{color:g.color},children:g.icon}),e.jsx("img",{className:"gh-file-icon",src:ft(j),alt:""}),e.jsx("span",{className:"gh-file-name",children:o}),u&&e.jsx("span",{className:"gh-file-dir",children:u})]},f.path)})})}),Za=t.memo(function({history:n,currentFolder:l,onFileSelect:c}){const{t:r}=le(["terminal","common"]),i=t.useRef(null),[f,o]=t.useState(null),[u,g]=t.useState(!1),{commits:j,loading:p,loadingMore:b,error:C,hasMore:P,total:x,filters:k,setFilter:d,resetFilters:v,selectedCommit:w,selectCommit:R,commitFiles:z,commitFilesLoading:O,loadHistory:G,loadMore:H,authors:ae,loadAuthors:ee}=n,{branches:T,loadBranches:D}=Qt();t.useEffect(()=>{l&&(G(l),ee(l),D(l))},[l,G,ee,D]);const F=$n({count:j.length,getScrollElement:()=>i.current,estimateSize:()=>28,overscan:20}),re=t.useCallback(()=>{const L=i.current;if(!L||b||!P||!l)return;const{scrollTop:S,scrollHeight:W,clientHeight:se}=L;W-S-se<200&&H(l)},[b,P,l,H]),_=t.useCallback(L=>{o(L),c&&w&&c(L,w.hash)},[c,w]),ge=t.useMemo(()=>T.filter(L=>!L.isRemote).map(L=>L.name),[T]),A=!!(k.branch||k.author||k.since||k.until||k.searchPath||k.search),Z=F.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:p?"...":x>0?x:j.length}),e.jsx("input",{type:"text",className:"gh-search-input",placeholder:r("terminal:fileExplorer.gitHistory.searchPlaceholder"),value:k.search,onChange:L=>d("search",L.target.value)}),e.jsx("button",{className:`gh-filter-toggle ${u?"active":""} ${A?"has-filters":""}`,onClick:()=>g(!u),title:"Filters",children:e.jsx(M,{name:"gear",size:12})}),A&&e.jsx("button",{className:"gh-reset-btn",onClick:v,children:r("terminal:fileExplorer.gitHistory.resetFilters")})]}),u&&e.jsxs("div",{className:"gh-filters-row",children:[e.jsxs("select",{className:"gh-filter-select",value:k.branch,onChange:L=>d("branch",L.target.value),children:[e.jsx("option",{value:"",children:r("terminal:fileExplorer.gitHistory.allBranches")}),ge.map(L=>e.jsx("option",{value:L,children:L},L))]}),e.jsxs("select",{className:"gh-filter-select",value:k.author,onChange:L=>d("author",L.target.value),children:[e.jsx("option",{value:"",children:r("terminal:fileExplorer.gitHistory.allAuthors")}),ae.map(L=>e.jsx("option",{value:L,children:L},L))]}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.since,onChange:L=>d("since",L.target.value),title:r("terminal:fileExplorer.gitHistory.since")}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.until,onChange:L=>d("until",L.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:L=>d("searchPath",L.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"})]}),p&&j.length===0?e.jsx("div",{className:"gh-state-msg",children:r("common:status.loading")}):C?e.jsx("div",{className:"gh-state-msg gh-error",children:C}):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:re,children:[e.jsx("div",{style:{height:`${F.getTotalSize()}px`,width:"100%",position:"relative"},children:Z.map(L=>e.jsx("div",{"data-index":L.index,ref:F.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${L.start}px)`},children:e.jsx(Xa,{commit:j[L.index],isSelected:(w==null?void 0:w.hash)===j[L.index].hash,onSelect:R})},L.key))}),b&&e.jsx("div",{className:"gh-loading-more",children:r("common:status.loading")})]})]}),w&&e.jsxs("div",{className:"gh-files-section",children:[e.jsxs("div",{className:"gh-files-header",children:[e.jsxs("span",{className:"gh-files-title",children:[z.length," ",z.length===1?"file":"files"]}),e.jsx("span",{className:"gh-files-commit-info",children:w.shortHash})]}),e.jsx(Qa,{files:z,loading:O,selectedFilePath:f,onSelectFile:_})]})]})]})});async function er({path:s,cwd:n,limit:l}){const c=new URLSearchParams({path:s,cwd:n});Number.isFinite(l)&&c.set("limit",String(l));const r=await q(K(`/api/files/git-file-history?${c.toString()}`));if(!r.ok){const f=await r.json().catch(()=>({}));throw new Error(f.error||`Failed to load file git history: ${r.statusText}`)}const i=await r.json();return{commits:Array.isArray(i.commits)?i.commits:[]}}async function tr({path:s,cwd:n,sha:l}){const c=new URLSearchParams({path:s,cwd:n,sha:l}),r=await q(K(`/api/files/git-file-commit-diff?${c.toString()}`));if(!r.ok){const f=await r.json().catch(()=>({}));throw new Error(f.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 sr=100;function nr(s){if(!s)return"";const n=Date.parse(s);if(Number.isNaN(n))return s;const l=Date.now()-n,c=Math.round(l/1e3);if(c<60)return`${c}s ago`;const r=Math.round(c/60);if(r<60)return`${r}m ago`;const i=Math.round(r/60);if(i<24)return`${i}h ago`;const f=Math.round(i/24);if(f<30)return`${f}d ago`;const o=Math.round(f/30);return o<12?`${o}mo ago`:`${Math.round(o/12)}y ago`}function ar(s){if(!s)return"";const n=s.lastIndexOf("/");return n>=0?s.slice(n+1):s}function rr({isOpen:s,onClose:n,filePath:l,cwd:c}){const{t:r}=le(["terminal","common"]),[i,f]=t.useState([]),[o,u]=t.useState(!1),[g,j]=t.useState(null),[p,b]=t.useState(null),[C,P]=t.useState(null),[x,k]=t.useState(!1),[d,v]=t.useState(null);t.useEffect(()=>{if(!s)return;let O=!1;return f([]),b(null),P(null),v(null),j(null),u(!0),(async()=>{try{const G=await er({path:l,cwd:c,limit:sr});if(O)return;f(G.commits),G.commits.length>0&&b(G.commits[0].sha)}catch(G){if(O)return;j(G instanceof Error?G.message:r("terminal:fileGitHistory.error"))}finally{O||u(!1)}})(),()=>{O=!0}},[s,l,c,r]),t.useEffect(()=>{if(!s||!p){P(null);return}let O=!1;return k(!0),v(null),P(null),(async()=>{try{const G=await tr({path:l,cwd:c,sha:p});if(O)return;P(G)}catch(G){if(O)return;v(G instanceof Error?G.message:r("terminal:fileGitHistory.error"))}finally{O||k(!1)}})(),()=>{O=!0}},[s,p,l,c,r]);const w=t.useCallback(O=>{O.key==="Escape"&&(O.preventDefault(),n())},[n]),R=t.useMemo(()=>ar(l),[l]),z=()=>x?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:r("terminal:fileGitHistory.loading")})]}):d?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:20}),e.jsx("p",{children:d})]}):C?C.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(Yt,{originalContent:C.originalContent,modifiedContent:C.modifiedContent,filename:C.filename||R,language:C.language}):e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:r("terminal:fileGitHistory.selectCommit")})});return s?e.jsx(Hn,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"git-file-history-modal",onClick:O=>O.stopPropagation(),onKeyDown:w,tabIndex:-1,children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{className:"git-file-history-title",children:[e.jsx("h2",{children:r("terminal:fileGitHistory.title")}),e.jsx("span",{className:"git-file-history-filepath",title:l,children:R})]}),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")})]}):g?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:18}),e.jsx("p",{children:g})]}):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(O=>{const G=O.sha===p;return e.jsxs("li",{className:`git-file-history-commit ${G?"selected":""}`,role:"option","aria-selected":G,onClick:()=>b(O.sha),children:[e.jsxs("div",{className:"git-file-history-commit-row",children:[e.jsx("span",{className:"git-file-history-sha",children:O.shortSha}),e.jsx("span",{className:"git-file-history-date",title:O.date,children:nr(O.date)})]}),e.jsx("div",{className:"git-file-history-subject",title:O.subject,children:O.subject}),e.jsx("div",{className:"git-file-history-author",title:O.email,children:O.author})]},O.sha)})})}),e.jsx("section",{className:"git-file-history-diff","aria-live":"polite",children:z()})]})]})})}):null}function cr({isOpen:s,areaId:n,onClose:l,onChangeArea:c,folderPath:r}){const{t:i}=le(["terminal","common"]),f=zs(),o=!!r&&!n,u=!o&&n?f.areas.get(n):null,g=o?[r]:(u==null?void 0:u.directories)||[],j=Array.from(f.areas.values()),[p,b]=t.useState(0),[C,P]=t.useState(null),[x,k]=t.useState(!1),d=g[p]||g[0]||null,v=(d==null?void 0:d.split("/").pop())||d||"";t.useEffect(()=>{b(0)},[r,o]),t.useEffect(()=>{!o&&r&&P(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 w=t.useMemo(()=>{const a=[];for(const h of j)for(const y of h.directories)a.push({path:y,areaId:h.id,areaName:h.name,areaColor:h.color});return a},[j]),{tree:R,loading:z,expandedPaths:O,loadTree:G,reloadDirectory:H,renamePathInTree:ae,togglePath:ee,expandToPath:T,setExpandedPaths:D}=zn(d),{gitStatus:F,loading:re,loadGitStatus:_}=Un(d),{mergeBranch:ge,mergeAbort:A,mergeContinue:Z}=Qt(),L=la(),{showToast:S}=Us(),{file:W,loading:se,error:be,loadFile:de,clearFile:m,setFile:J}=Jn(),{treePanelWidth:ie,handleResizeStart:ue,isResizing:V}=ea(),{mobileTreeHeight:E,handleResizeMouseDown:Q,handleResizeTouchStart:te}=aa(),{loadStoredState:Ne,saveState:xe}=Zn({areaId:n||null,folderPath:r||null,isOpen:s}),[U,ne]=t.useState(null),[pe,me]=t.useState("files"),[Ue,Se]=t.useState(""),[Dt,$e]=t.useState([]),[Rt,Be]=t.useState([]),[Ft,_e]=t.useState(!1),[gt,je]=t.useState(null),[Pt,ve]=t.useState(null),[xt,Ve]=t.useState(!1),[De,N]=t.useState(!1),[I,B]=t.useState(!1),[ke,Te]=t.useState(new Set),[ot]=t.useState(!1),[Ke,Re]=t.useState(!1),[It,Xs]=t.useState(250),ct=t.useRef(null),[He,yt]=t.useState(null),[Qs,ts]=t.useState(!1),[We,ss]=t.useState(null),[qe,ns]=t.useState(null),[Je,Zs]=t.useState(null),[Lt,$t]=t.useState({open:!1,path:"",cwd:""}),[he,ze]=t.useState({isOpen:!1,node:null,value:"",submitting:!1}),[ye,Ye]=t.useState({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1}),[Ee,as]=t.useState(null),[Fe,Xe]=t.useState([]),[oe,Le]=t.useState(null),dt=t.useRef([]),Qe=t.useRef(-1),Ht=t.useRef(!1),[en,tn]=t.useState(!1),[sn,nn]=t.useState(!1),[,zt]=t.useState(void 0),[rs,Ze]=t.useState(null),[ut,ht]=t.useState(null),[an,et]=t.useState(null),[rn,is]=t.useState(!1),[bt,Ot]=t.useState(null),[ls,At]=t.useState(!1),[jt,vt]=t.useState(null),os=t.useRef(null),Gt=t.useRef(null),cs=t.useRef(null),wt=t.useRef(null);t.useEffect(()=>{if(!s||De)return;(async()=>{const h=await Ne();if(h){let y=h.selectedFolderIndex;if(C){const $=g.indexOf(C);y=$>=0?$:0,P(null)}else{const $=Math.max(0,g.length-1);y=Math.min(Math.max(0,y),$)}Xe(h.tabs),Le(h.activeTabPath),me(h.viewMode),b(y),D(h.expandedPaths),wt.current=h.expandedPaths,Ve(!0),h.activeTabPath&&(ne(h.activeTabPath),de(h.activeTabPath))}N(!0)})()},[s,De,Ne,D,de,C,g]),t.useEffect(()=>{wt.current&&!z&&R.length>0&&(D(wt.current),wt.current=null)},[z,R,D]),t.useEffect(()=>{if(!s||!De)return;const a=setTimeout(()=>{xe({tabs:Fe,activeTabPath:oe,viewMode:pe,selectedFolderIndex:p,expandedPaths:O})},500);return()=>clearTimeout(a)},[s,De,Fe,oe,pe,p,O,xe]),t.useEffect(()=>{N(!1)},[n,r]),t.useEffect(()=>{if(!he.isOpen)return;const a=window.setTimeout(()=>{var h,y;(h=Gt.current)==null||h.focus(),(y=Gt.current)==null||y.select()},0);return()=>window.clearTimeout(a)},[he.isOpen]),t.useEffect(()=>{if(!ye.isOpen)return;const a=window.setTimeout(()=>{var h;(h=cs.current)==null||h.focus()},0);return()=>window.clearTimeout(a)},[ye.isOpen]);const Pe=t.useMemo(()=>{const a=Ue.trim(),h=a.match(/^(.+):(\d+)$/);return h?{query:h[1],lineNumber:parseInt(h[2],10)}:{query:a,lineNumber:void 0}},[Ue]);t.useEffect(()=>{if(!Pe.query||!d){$e([]),Be([]),_e(!1);return}_e(!0);const a=setTimeout(async()=>{try{const h=Pe.query,y=q(K(`/api/files/search?path=${encodeURIComponent(d)}&q=${encodeURIComponent(h)}&limit=200`)).then(fe=>fe.json()).catch(()=>({results:[]})),$=h.length>=2&&!Pe.lineNumber?q(K(`/api/files/search-content?path=${encodeURIComponent(d)}&q=${encodeURIComponent(h)}&limit=200`)).then(fe=>fe.json()).catch(()=>({results:[]})):Promise.resolve({results:[]}),[Y,X]=await Promise.all([y,$]);$e(Y.results||[]),Be(X.results||[])}catch(h){console.error("[FileExplorer] Search failed:",h),$e([]),Be([])}_e(!1)},300);return()=>clearTimeout(a)},[Pe.query,Pe.lineNumber,d]),t.useEffect(()=>{s&&d&&(m(),ne(null),je(null),ve(null),Ve(!1),G(),_())},[s,d,G,_,m]),t.useEffect(()=>{f.fileViewerPath&&s&&(de(f.fileViewerPath),ne(f.fileViewerPath),mt.clearFileViewerPath())},[f.fileViewerPath,s,de]),t.useEffect(()=>{De&&!xt&&F&&Ve(!0)},[F,xt,De,pe]),t.useEffect(()=>{if(n&&(m(),ne(null),Se(""),Be([]),$e([]),je(null),ve(null),Ve(!1),N(!1),C)){const a=f.areas.get(n);a!=null&&a.directories.includes(C)||P(null)}},[n,C,f.areas,m]),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||ze({isOpen:!1,node:null,value:"",submitting:!1});return}if(ot)return;if(x){y.preventDefault(),y.stopPropagation(),k(!1);return}y.preventDefault(),y.stopPropagation(),l();return}(y.metaKey||y.ctrlKey)&&y.key==="p"&&(y.preventDefault(),(Y=os.current)==null||Y.focus());const $=mt.getShortcuts().find(X=>X.id==="file-explorer-close-tab");if(Gn(y,$)){if(y.repeat)return;y.preventDefault(),y.stopPropagation(),oe&&fs(oe)}},h=y=>{const $=y.target;x&&!$.closest(".file-explorer-folder-selector")&&!$.closest(".file-explorer-folder-dropdown")&&k(!1)};return document.addEventListener("keydown",a,!0),document.addEventListener("click",h),()=>{document.removeEventListener("keydown",a,!0),document.removeEventListener("click",h)}},[s,l,x,oe,ot,he]);const ds=t.useMemo(()=>{const a=new Map;if(F!=null&&F.files)for(const h of F.files)a.set(h.path,h.status);return a},[F==null?void 0:F.files]),Ut=t.useMemo(()=>{const a=new Map;if(!(F!=null&&F.files))return a;const h={conflict:0,modified:1,added:2,deleted:3,untracked:4,renamed:5};for(const y of F.files){let $=y.path;for(;;){const Y=$.lastIndexOf("/");if(Y<=0)break;$=$.substring(0,Y);const X=a.get($);X?h[y.status]<h[X]&&a.set($,y.status):a.set($,y.status)}}return a},[F==null?void 0:F.files]),us=t.useMemo(()=>{const a=h=>({...h,gitStatus:h.isDirectory?Ut.get(h.path):ds.get(h.path),hasGitChanges:h.isDirectory&&Ut.has(h.path)||void 0,children:h.children?h.children.map(a):void 0});return R.map(a)},[R,ds,Ut]),Bt=(a,h,y,$)=>{if(!Fe.find(X=>X.path===a)){const X={path:a,filename:h,extension:y};Xe(fe=>[...fe,X])}Le(a),ne(a),zt($),de(a)},hs=async a=>{if(a.isDirectory){me("files"),Se(""),await T(a.path),ne(a.path),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let h=a.path,y=document.querySelector(`[data-path="${h}"]`);for(;!y&&h.includes("/");)h=h.substring(0,h.lastIndexOf("/")),y=document.querySelector(`[data-path="${h}"]`);y instanceof HTMLElement&&y.scrollIntoView({behavior:"smooth",block:"center"})})});return}ve(null),je(null),Bt(a.path,a.name,a.extension,Pe.lineNumber)},ln=(a,h)=>{ve(null),je(null);const y=a.split("/").pop()||a,$=a.substring(a.lastIndexOf(".")).toLowerCase();Bt(a,y,$,h)},on=async(a,h)=>{ve(h),je(null);const y=a.split("/").pop()||a,$=a.substring(a.lastIndexOf(".")).toLowerCase();if(Bt(a,y,$),h==="modified"){const{content:Y}=await Bn(a);Y!==null&&je(Y)}},Oe=t.useCallback(()=>{const a=dt.current,h=Qe.current;tn(h>0),nn(h>=0&&h<a.length-1)},[]);t.useEffect(()=>{if(!oe){dt.current=[],Qe.current=-1,Oe();return}if(Ht.current){Ht.current=!1,Oe();return}const a=dt.current,h=Qe.current;if(h>=0&&a[h]===oe){Oe();return}const y=h<a.length-1?a.slice(0,h+1):a.slice();y.push(oe),y.length>100&&y.shift(),dt.current=y,Qe.current=y.length-1,Oe()},[oe,Oe]);const ms=a=>{Le(a),ne(a),ve(null),je(null),zt(void 0);const h=Fe.find(y=>y.path===a);h!=null&&h.data||de(a)},Ct=t.useCallback(a=>{const h=dt.current;if(h.length===0)return;let y=Qe.current+a;for(;y>=0&&y<h.length;){const $=h[y];if(Fe.some(Y=>Y.path===$)){Ht.current=!0,Qe.current=y,Oe(),ms($);return}y+=a}},[Fe,Oe]),cn=t.useCallback(()=>Ct(-1),[Ct]),dn=t.useCallback(()=>Ct(1),[Ct]),fs=a=>{Xe(h=>{var Y;const y=h.filter(X=>X.path!==a),$=h.findIndex(X=>X.path===a);if($!==-1&&((Y=h[$])==null?void 0:Y.path)===a&&(oe===a||h.find(X=>X.path===oe)),y.length>0){if(!y.some(fe=>fe.path===oe)){const fe=h.findIndex(Ce=>Ce.path===a),ce=Math.max(0,Math.min(fe,y.length-1)),we=y[ce];we&&(Le(we.path),ne(we.path),de(we.path))}}else Le(null),ne(null),m();return y})},un=a=>{if(k(!1),a.areaId!==n)P(a.path),c&&c(a.areaId);else{const h=g.indexOf(a.path);b(h>=0?h:0)}},Ie=t.useCallback(a=>{const h=a.lastIndexOf("/");return h<=0?"/":a.slice(0,h)},[]),tt=t.useCallback((a,h,y)=>a===h?y:a.startsWith(`${h}/`)?`${y}${a.slice(h.length)}`:a,[]),hn=t.useCallback((a,h)=>{ne(h.path),ss({isOpen:!0,position:{x:a.clientX,y:a.clientY},node:h})},[]),mn=t.useCallback(a=>{a.defaultPrevented||d&&(a.preventDefault(),ns({isOpen:!0,position:{x:a.clientX,y:a.clientY},parentDir:d}))},[d]),ps=t.useCallback(a=>{ze({isOpen:!0,node:a,value:a.name,submitting:!1})},[]),st=t.useCallback(()=>{ze({isOpen:!1,node:null,value:"",submitting:!1})},[]),nt=t.useCallback((a,h)=>{a&&Ye({isOpen:!0,parentDir:a,isDirectory:h,value:"",submitting:!1})},[]),at=t.useCallback(()=>{Ye({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1})},[]),gs=t.useCallback(a=>{as({node:a})},[]),fn=t.useCallback(async()=>{const a=Ee==null?void 0:Ee.node;if(a)try{const h=await q(K("/api/files/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,recursive:a.isDirectory})}),y=await h.json().catch(()=>({}));if(!h.ok){S("error","Delete Failed",y.error||"Unable to delete item");return}Xe(Y=>Y.filter(X=>X.path!==a.path&&!X.path.startsWith(`${a.path}/`))),(oe===a.path||oe!=null&&oe.startsWith(`${a.path}/`))&&(Le(null),m()),(U===a.path||U!=null&&U.startsWith(`${a.path}/`))&&ne(null);const $=Ie(a.path);await H($),await _(),S("success",a.isDirectory?"Folder Deleted":"File Deleted",a.name)}catch(h){console.error("[FileExplorer] Delete failed:",h),S("error","Delete Failed","Unable to delete item")}},[Ee,oe,U,Ie,H,_,S,m]),xs=t.useCallback(async()=>{const{parentDir:a,isDirectory:h,value:y}=ye,$=y.trim();if(!a||!$){at();return}if($.includes("/")||$.includes("\\")){S("error","Invalid Name","Name must not contain path separators");return}Ye(Y=>({...Y,submitting:!0}));try{const Y=await q(K("/api/files/create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({parentDir:a,name:$,isDirectory:h})}),X=await Y.json();if(!Y.ok){S("error","Create Failed",X.error||"Unable to create item"),Ye(we=>({...we,submitting:!1}));return}const fe=X.path,ce=new Set(O);ce.add(a),await H(a),D(ce),await _(),ne(fe),S("success",h?"Folder Created":"File Created",$),at()}catch(Y){console.error("[FileExplorer] Create failed:",Y),S("error","Create Failed","Unable to create item"),Ye(X=>({...X,submitting:!1}))}},[ye,O,H,D,_,S,at]),ys=t.useCallback(async()=>{const a=he.node;if(!a)return;const h=he.value.trim();if(!h||h===a.name){st();return}ze(y=>({...y,submitting:!0}));try{const y=await q(K("/api/files/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,newName:h})}),$=await y.json();if(!y.ok){S("error","Rename Failed",$.error||"Unable to rename item"),ze(Ce=>({...Ce,submitting:!1}));return}const Y=$.newPath,X=a.path,fe=new Set(Array.from(O).map(Ce=>tt(Ce,X,Y))),ce=Ie(X),we=Ie(Y);if(Xe(Ce=>Ce.map(Me=>{if(!Me.path.startsWith(X))return Me;const rt=tt(Me.path,X,Y),Nt=rt.split("/").pop()||rt,ks=Nt.includes(".")?`.${Nt.split(".").pop()}`:"";return{...Me,path:rt,filename:Nt,extension:ks.toLowerCase(),data:Me.data?{...Me.data,path:rt,filename:Nt,extension:ks.toLowerCase()}:Me.data}})),oe&&Le(tt(oe,X,Y)),U&&ne(tt(U,X,Y)),W!=null&&W.path){const Ce=tt(W.path,X,Y);if(Ce!==W.path){const Me=Ce.split("/").pop()||Ce,rt=Me.includes(".")?`.${Me.split(".").pop()}`:"";J({...W,path:Ce,filename:Me,extension:rt.toLowerCase()})}}ae(X,Y),D(fe),await H(ce),we!==ce&&await H(we),await _(),S("success","Renamed",`${a.name} renamed`),st()}catch(y){console.error("[FileExplorer] Rename failed:",y),S("error","Rename Failed","Unable to rename item"),ze($=>({...$,submitting:!1}))}},[he,st,oe,U,W,O,tt,Ie,ae,D,H,_,S,J]),bs=t.useCallback(a=>{Zs({sourcePath:a.path,isDirectory:a.isDirectory,name:a.name}),S("info","Copied",`${a.name} ready to paste`)},[S]),js=t.useCallback(async a=>{if(!Je)return;const h=a.isDirectory?a.path:Ie(a.path),y=new Set(O);y.add(h);try{const $=await q(K("/api/files/paste"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourcePath:Je.sourcePath,targetDir:h})}),Y=await $.json();if(!$.ok){S("error","Paste Failed",Y.error||"Unable to paste item");return}await H(h),D(y),await _(),Y.destinationPath&&ne(Y.destinationPath),S("success","Pasted",`${Je.name} pasted`)}catch($){console.error("[FileExplorer] Paste failed:",$),S("error","Paste Failed","Unable to paste item")}},[Je,Ie,O,H,D,_,S]),vs=t.useCallback(async a=>{try{await navigator.clipboard.writeText(a.path),S("success","Copied","Full path copied")}catch(h){console.error("[FileExplorer] Copy path failed:",h),S("error","Copy Failed","Could not copy path")}},[S]),ws=t.useCallback(a=>{a.isDirectory||!d||$t({open:!0,path:a.path,cwd:d})},[d]),pn=t.useCallback(a=>{!d||!a||$t({open:!0,path:a,cwd:d})},[d]),gn=t.useMemo(()=>{if(!We)return[];const a=We.node,h=a.isDirectory?a.path:Ie(a.path),y=[{id:"create-file",label:a.isDirectory?"New File...":"New File Here...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>nt(h,!1)},{id:"create-folder",label:a.isDirectory?"New Folder...":"New Folder Here...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>nt(h,!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:()=>ps(a)},{id:"copy",label:a.isDirectory?"Copy Folder":"Copy File",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>bs(a)},{id:"paste",label:a.isDirectory?"Paste Into Folder":"Paste Here",icon:e.jsx(M,{name:"clipboard",size:14}),disabled:!Je,onClick:()=>{js(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:()=>{vs(a)}}];return 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:()=>ws(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:()=>gs(a)}),y},[We,Je,Ie,nt,ps,bs,js,vs,ws,gs,i]),xn=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:()=>nt(a,!1)},{id:"create-folder-root",label:"New Folder...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>nt(a,!0)}]},[qe,nt]),_t=t.useCallback(async a=>{me("files"),Se(""),await T(a),ne(a),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let h=a,y=document.querySelector(`[data-path="${h}"]`);for(;!y&&h.includes("/");)h=h.substring(0,h.lastIndexOf("/")),y=document.querySelector(`[data-path="${h}"]`);y instanceof HTMLElement&&y.scrollIntoView({behavior:"smooth",block:"center"})})})},[T]),yn=t.useCallback(async a=>{if(!(!d||a.length===0)){Te(h=>{const y=new Set(h);for(const $ of a)y.add($);return y});try{const h=await q(K("/api/files/git-add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:a,directory:d})});if(h.ok)await _();else{const y=await h.json();console.error("[FileExplorer] Git add failed:",y.error)}}catch(h){console.error("[FileExplorer] Git add failed:",h)}finally{Te(h=>{const y=new Set(h);for(const $ of a)y.delete($);return y})}}},[d,_]),bn=t.useCallback(async a=>{if(!d)return;Ze(a);const h=await ge(d,a);if(await _(),h.success)Ze(null),S("success","Merge Complete",`Merged '${a}' successfully`),G();else if(h.conflicts&&h.conflicts.length>0){const y=h.conflicts.length;S("warning","Merge Conflicts",`${y} conflict${y>1?"s":""} found — resolve to continue`),me("git")}else Ze(null),S("error","Merge Failed",h.error||"Merge failed")},[d,ge,_,G,S]),jn=t.useCallback(async a=>{Ze("remote"),await _();const h=a.length;S("warning","Pull Conflicts",`${h} conflict${h>1?"s":""} found — resolve to continue`),me("git")},[_,S]),vn=t.useCallback(async a=>{if(d){ht(a),is(!0),et(null);try{const h=await q(K(`/api/files/git-conflict-file?path=${encodeURIComponent(d)}&file=${encodeURIComponent(a)}`)),y=await h.json();h.ok?et(y):console.error("[FileExplorer] Failed to load conflict file:",y.error)}catch(h){console.error("[FileExplorer] Failed to load conflict file:",h)}finally{is(!1)}}},[d]),wn=t.useCallback(async a=>{if(!(!d||!ut))try{const h=await q(K("/api/files/git-resolve-conflict"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:d,file:ut,content:a})}),y=await h.json();h.ok&&y.success?(ht(null),et(null),await _()):console.error("[FileExplorer] Failed to resolve conflict:",y.error)}catch(h){console.error("[FileExplorer] Failed to resolve conflict:",h)}},[d,ut,_]),Cn=t.useCallback(async()=>{if(!d)return;const a=await Z(d);a.success?(Ze(null),ht(null),et(null),S("success","Merge Complete","Merge completed successfully"),await _(),G()):S("error","Merge Failed",a.error||"Merge continue failed")},[d,Z,_,G,S]),Nn=t.useCallback(async()=>{if(!d)return;const a=await A(d);a.success?(Ze(null),ht(null),et(null),S("info","Merge Aborted","Merge has been aborted"),await _(),G()):S("error","Abort Failed",a.error||"Failed to abort merge")},[d,A,_,G,S]),kn=t.useCallback(async a=>{if(d){vt(a),At(!0),Ot(null),me("compare");try{const h=await q(K(`/api/files/git-branch-compare?directory=${encodeURIComponent(d)}&branch=${encodeURIComponent(a)}`)),y=await h.json();h.ok?Ot(y):(S("error","Compare Failed",y.error||"Failed to compare branches"),me("files"),vt(null))}catch(h){console.error("[FileExplorer] Branch compare failed:",h),S("error","Compare Failed","Network error during comparison"),me("files"),vt(null)}finally{At(!1)}}},[d,S]),En=t.useCallback(async(a,h)=>{if(!d||!jt)return;const y=a.split("/").pop()||a,$=a.substring(a.lastIndexOf(".")).toLowerCase();Fe.find(ce=>ce.path===a)||Xe(ce=>[...ce,{path:a,filename:y,extension:$}]),Le(a),ne(a),zt(void 0);const X=async ce=>{try{const we=await q(K(`/api/files/git-show?path=${encodeURIComponent(a)}&ref=${encodeURIComponent(ce)}`)),Ce=await we.json();return we.ok?Ce.content??"":""}catch{return""}},fe=ce=>({path:a,filename:y,extension:$,content:ce,fileType:"text",size:ce.length,modified:""});if(h==="modified"||h==="renamed"){const[ce,we]=await Promise.all([X(jt),X("HEAD")]);je(ce),J(fe(we)),ve("modified")}else if(h==="deleted"){const ce=await X(jt);je(ce),J(fe("")),ve("modified")}else if(h==="added"){const ce=await X("HEAD");je(""),J(fe(ce)),ve("modified")}},[d,jt,Fe]),Cs=t.useCallback(()=>{me("files"),Ot(null),vt(null),At(!1)},[]),Sn=t.useCallback(async(a,h)=>{if(d){ts(!0);try{const y=new URLSearchParams({path:d,hash:h,file:a}),$=await q(K(`/api/files/git-commit-file-diff?${y}`)),Y=await $.json();$.ok?yt(Y):yt(null)}catch(y){console.error("[FileExplorer] commit diff fetch error:",y),yt(null)}finally{ts(!1)}}},[d]),Tn=t.useCallback(()=>{yt(null)},[]),Mn=t.useCallback(a=>{a.preventDefault(),ct.current={startY:a.clientY,startHeight:It};const h=$=>{if(!ct.current)return;const Y=ct.current.startY-$.clientY,X=Math.max(120,Math.min(600,ct.current.startHeight+Y));Xs(X)},y=()=>{ct.current=null,document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",y)};document.addEventListener("mousemove",h),document.addEventListener("mouseup",y)},[It]);if(!s||!u&&!o)return null;const Ns=(F==null?void 0:F.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:cn,disabled:!en,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:dn,disabled:!sn,title:"Forward to next file","aria-label":"Forward to next file",children:e.jsx(M,{name:"arrow-right",size:14})})]}),d&&e.jsxs("div",{className:"file-explorer-folder-selector",onClick:()=>!o&&w.length>0&&k(!x),style:{cursor:!o&&w.length>0?"pointer":"default"},title:d,children:[e.jsx("span",{className:"file-explorer-panel-dot",style:{background:(u==null?void 0:u.color)||"#ffd700"}}),e.jsx("span",{className:"file-explorer-folder-name",children:v}),e.jsx("span",{className:"file-explorer-folder-path-hint",children:d}),!o&&w.length>1&&e.jsx("span",{className:"file-explorer-folder-dropdown-icon",children:e.jsx(M,{name:"caret-down",size:10})})]}),(F==null?void 0:F.isGitRepo)&&d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"file-explorer-path-separator",children:"/"}),e.jsx(Ua,{currentFolder:d,gitStatus:F,onBranchChanged:()=>{_(),G()},onMerge:bn,onCompare:kn,onPullConflicts:jn})]}),W&&e.jsxs("span",{className:"file-explorer-current-file",children:["/ ",W.filename]}),!o&&x&&w.length>0&&e.jsx("div",{className:"file-explorer-folder-dropdown",onWheel:a=>{a.preventDefault(),a.currentTarget.scrollTop+=a.deltaY*.35},children:w.map(a=>e.jsxs("div",{className:`file-explorer-folder-option ${a.path===d?"active":""}`,onClick:h=>{h.stopPropagation(),un(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}`))})]}),(F==null?void 0:F.isGitRepo)&&e.jsx("button",{className:`file-explorer-history-toggle ${Ke?"active":""}`,onClick:()=>Re(!Ke),title:i("terminal:fileExplorer.gitHistory.title"),children:e.jsx(M,{name:"status-waiting-input",size:14})}),e.jsx("button",{className:"file-explorer-panel-close",onClick:l,children:"×"})]}),e.jsxs("div",{className:"file-explorer-main",style:E>0?{"--fe-mobile-tree-height":`${E}px`}:void 0,children:[e.jsxs("div",{className:`file-explorer-tree-panel ${I?"collapsed":""}`,style:{width:ie},children:[e.jsxs("div",{className:"file-explorer-tabs",children:[e.jsx("button",{className:"file-explorer-tree-toggle",onClick:()=>B(!I),title:i(I?"terminal:fileExplorer.expandTree":"terminal:fileExplorer.collapseTree"),children:e.jsx(M,{name:I?"caret-down":"caret-up",size:12})}),e.jsxs("button",{className:`file-explorer-tab ${pe==="files"?"active":""}`,onClick:()=>me("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 ${pe==="git"?"active":""}`,onClick:()=>me("git"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"git-branch",size:14})}),i("terminal:fileExplorer.gitChanges"),Ns>0&&e.jsx("span",{className:"tab-badge",children:Ns})]}),(bt||ls)&&e.jsxs("button",{className:`file-explorer-tab ${pe==="compare"?"active":""}`,onClick:()=>me("compare"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"arrows-horizontal",size:14})}),i("terminal:fileExplorer.diffView"),bt&&e.jsx("span",{className:"tab-badge",children:bt.files.length}),e.jsx("span",{className:"tab-close-btn",onClick:a=>{a.stopPropagation(),Cs()},children:"×"})]})]}),pe==="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:os,type:"text",className:"file-explorer-search-input",placeholder:i("terminal:fileExplorer.searchPlaceholder"),value:Ue,onChange:a=>Se(a.target.value)}),Ue&&e.jsx("button",{className:"file-explorer-search-clear",onClick:()=>Se(""),children:"×"})]}),e.jsxs("div",{className:"file-explorer-toolbar-buttons",children:[e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>D(new Set),title:i("terminal:fileExplorer.collapseAll"),children:"⊟"}),oe&&e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>_t(oe),title:i("terminal:fileExplorer.revealInTree"),children:e.jsx(M,{name:"target",size:14})})]})]}),e.jsx("div",{className:"file-explorer-tree-content",onContextMenu:pe==="files"?mn:void 0,children:pe==="compare"?e.jsx(Ys,{compareResult:bt,loading:ls,onFileSelect:En,selectedPath:U,onClose:Cs}):pe==="files"?z?e.jsx("div",{className:"tree-loading",children:i("common:status.loading")}):Pe.query?Ft?e.jsx("div",{className:"tree-loading",children:i("terminal:fileExplorer.searching")}):e.jsx(Ws,{filenameResults:Dt,contentResults:Rt,onSelectFile:hs,onSelectContent:ln,selectedPath:U,query:Pe.query,lineNumber:Pe.lineNumber}):e.jsx("div",{className:"file-tree",children:us.length===0?e.jsx("div",{className:"tree-empty",children:i("terminal:fileExplorer.noDirectoriesLinked")}):us.map(a=>e.jsx(On,{node:a,depth:0,selectedPath:U,expandedPaths:O,onSelect:hs,onToggle:ee,onContextMenu:hn,searchQuery:""},a.path))}):e.jsx(qs,{gitStatus:F,loading:re,onFileSelect:on,selectedPath:U,onRefresh:_,onStageFiles:yn,stagingPaths:ke,currentFolder:d,onCommitComplete:()=>{_(),G()},mergeInProgress:F==null?void 0:F.mergeInProgress,mergingBranch:rs,onMergeContinue:Cn,onMergeAbort:Nn,onConflictOpen:vn,onRevealInTree:_t})})]}),e.jsx("div",{className:`file-explorer-resize-handle ${V?"active":""}`,onMouseDown:ue}),!I&&e.jsx("div",{className:"fe-mobile-resize-handle",onMouseDown:Q,onTouchStart:te}),e.jsx("div",{className:"file-explorer-viewer-panel",children:ut?e.jsx(Va,{file:ut,versions:an,loading:rn,onResolve:wn,onClose:()=>{ht(null),et(null)},currentBranch:(F==null?void 0:F.branch)||"HEAD",mergingBranch:rs||"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:Tn,children:"×"})]}),e.jsx(Yt,{originalContent:He.beforeContent,modifiedContent:He.afterContent,filename:He.filename,language:Ss[He.extension]||"plaintext"})]}):Qs?e.jsx("div",{className:"commit-diff-loading",children:i("common:status.loading")}):e.jsxs(e.Fragment,{children:[e.jsx(Js,{tabs:Fe,activeTabPath:oe,onSelectTab:ms,onCloseTab:fs,onShowGitHistory:pn}),Pt==="modified"&&gt!==null&&W?e.jsx(Yt,{originalContent:gt,modifiedContent:W.content,filename:W.filename,language:Ss[W.extension]||"plaintext"}):e.jsx(Vs,{file:W,loading:se,error:be,onRevealInTree:_t,onFileEdited:de})]})})]}),Ke&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"git-history-resize-handle",onMouseDown:Mn}),e.jsx("div",{className:"git-history-bottom-panel",style:{height:It},children:e.jsx(Za,{history:L,currentFolder:d,onFileSelect:Sn})})]}),he.isOpen&&he.node&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:st,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["Rename ",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:Gt,type:"text",className:"file-explorer-rename-input",value:he.value,onChange:a=>ze(h=>({...h,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),ys()):a.key==="Escape"&&(a.preventDefault(),st())},disabled:he.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:st,disabled:he.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{ys()},disabled:he.submitting||!he.value.trim(),children:he.submitting?"Renaming...":"Rename"})]})]})}),We&&e.jsx(it,{isOpen:We.isOpen,position:We.position,worldPosition:{x:0,z:0},actions:gn,onClose:()=>ss(null)}),qe&&e.jsx(it,{isOpen:qe.isOpen,position:qe.position,worldPosition:{x:0,z:0},actions:xn,onClose:()=>ns(null)}),ye.isOpen&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:at,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["New ",ye.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:ye.parentDir,children:ye.parentDir}),e.jsx("input",{ref:cs,type:"text",className:"file-explorer-rename-input",placeholder:ye.isDirectory?"folder name":"file name",value:ye.value,onChange:a=>Ye(h=>({...h,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),xs()):a.key==="Escape"&&(a.preventDefault(),at())},disabled:ye.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:at,disabled:ye.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{xs()},disabled:ye.submitting||!ye.value.trim(),children:ye.submitting?"Creating...":"Create"})]})]})}),e.jsx(rr,{isOpen:Lt.open,filePath:Lt.path,cwd:Lt.cwd,onClose:()=>$t(a=>({...a,open:!1}))}),e.jsx(An,{isOpen:!!Ee,title:Ee!=null&&Ee.node.isDirectory?"Delete Folder":"Delete File",message:Ee?e.jsxs(e.Fragment,{children:["Permanently delete ",e.jsx("strong",{children:Ee.node.name}),"?"]}):"",note:Ee!=null&&Ee.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:()=>{fn()},onClose:()=>as(null)})]})}export{cr as FileExplorerPanel};
@@ -1 +1 @@
1
- import{ab as as,u as ts,ar as vs,as as bs,at as zs,j as s,I as F,_ as Is,au as Es,av as $s,aw as Ds,ax as Ms,r as c,a2 as Ls,ah as Ss,W as Xs,U as Ps,H as Rs,ay as Ys,az as Us,aA as Gs,aB as ms,aC as _s,s as M,aD as Fs,n as G}from"./main-9uTEp9Lr.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fs=as.memo(({agent:a,isSelected:A,isKeyboardFocused:L=!1,onSelect:S,onDoubleClick:n,onChat:g,onFocus:h,onKill:w,onDragStart:X})=>{const{t:x}=ts(["dashboard","common"]),P=vs().has(a.id),N=bs(a.status),H=zs(a),j=Ms(H),I=a.taskLabel?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"task",size:12})," ",a.taskLabel]}):a.currentTask||a.lastAssignedTask,m=a.status==="idle"&&a.lastActivity>0,[,B]=as.useState(0);return as.useEffect(()=>{if(!m)return;const b=window.setInterval(()=>B(T=>T+1),15e3);return()=>window.clearInterval(b)},[m]),s.jsxs("div",{className:`dash-card dash-card--${N} ${A?"dash-card--selected":""} ${L?"dash-card--keyboard-focused":""}`,"data-agent-id":a.id,onClick:S,onDoubleClick:b=>{b.stopPropagation(),n()},onDragStart:b=>{X==null||X(a),b.dataTransfer.effectAllowed="move"},draggable:!0,title:x("cards.doubleClickHint"),children:[s.jsxs("div",{className:"dash-card__row1",children:[s.jsx("span",{className:`dash-card__status-dot dash-card__status-dot--${N}`}),s.jsx("span",{className:"dash-card__name",children:a.name}),s.jsxs("span",{className:"dash-card__class",children:[s.jsx(Is,{agent:a,size:14})," ",a.class]}),s.jsxs("span",{className:`dash-card__provider dash-card__provider--${a.provider}`,children:[s.jsx(F,{name:a.provider==="codex"||a.provider==="opencode"?"status-pending":"robot",size:11,weight:a.provider==="codex"||a.provider==="opencode"?"fill":"regular",color:a.provider==="codex"?"#a16207":a.provider==="opencode"?"#4ade80":void 0})," ",a.provider]}),P&&s.jsx("span",{className:"dash-card__unseen-badge",title:"New output available - click to view",children:"!"})]}),s.jsxs("div",{className:"dash-card__row2",children:[s.jsx("span",{className:`dash-card__status dash-card__status--${N}`,children:P?"Unseen":a.status}),s.jsxs("div",{className:"dash-card__context",children:[s.jsx("div",{className:"dash-card__context-bar",children:s.jsx("div",{className:`dash-card__context-fill dash-card__context-fill--${j}`,style:{width:`${H}%`}})}),s.jsxs("span",{className:`dash-card__context-pct dash-card__context-pct--${j}`,children:[H,"%"]})]})]}),s.jsxs("div",{className:"dash-card__row3",children:[s.jsxs("span",{className:"dash-card__workdir",title:a.cwd,children:[s.jsx(F,{name:"folder",size:11})," ",a.cwd.split("/").pop()||a.cwd]}),m&&s.jsxs("span",{className:"dash-card__idle-time",style:{color:Ds(a.lastActivity)},title:$s(a.lastActivity),children:[s.jsx(F,{name:"status-waiting-input",size:10})," ",Es(a.lastActivity)]})]}),I&&s.jsx("div",{className:"dash-card__row4",children:s.jsx("span",{className:"dash-card__task",children:I})}),s.jsxs("div",{className:"dash-card__actions",children:[g&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--chat",onClick:b=>{b.stopPropagation(),g()},title:x("cards.openTerminal"),children:x("cards.chat")}),w&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--danger",onClick:b=>{b.stopPropagation(),w()},title:x("cards.killAgent"),children:x("cards.stop")})]})]})});fs.displayName="AgentCard";const ws=({buildings:a,onSelectBuilding:A})=>{const{t:L}=ts(["dashboard"]),S=c.useMemo(()=>Array.from(a.values()).sort((n,g)=>n.name.localeCompare(g.name)),[a]);return s.jsxs("div",{className:"dashboard-view__buildings",children:[s.jsxs("div",{className:"dashboard-view__buildings-header",children:[s.jsx("span",{className:"dashboard-view__buildings-title",children:L("buildings.title")}),s.jsx("span",{className:"dashboard-view__buildings-count",children:S.length})]}),s.jsx("div",{className:"dashboard-view__buildings-row",children:S.map(n=>{const g=bs(n.status),h=Ls(n.type);return s.jsxs("button",{className:`dash-pill dash-pill--${g}`,onClick:()=>A==null?void 0:A(n.id),title:`${n.name} (${n.type}) - ${n.status}`,children:[s.jsx("span",{className:"dash-pill__icon",children:s.jsx(F,{name:h,size:14})}),s.jsx("span",{className:"dash-pill__name",children:n.name}),s.jsx("span",{className:`dash-pill__dot dash-pill__dot--${g}`})]},n.id)})})]})};ws.displayName="BuildingPills";function Zs({onSelectAgent:a,onFocusAgent:A,onKillAgent:L,onSelectBuilding:S,onOpenTerminal:n,onFocusZone:g}){const{t:h}=ts(["dashboard","common"]),w=Ss(),X=Xs(),x=Ps(),rs=Rs(),P=vs(),[N,H]=c.useState(""),[j,I]=c.useState("all"),[m,B]=c.useState("zone"),[b,T]=c.useState(new Set),[k,J]=c.useState(null),[ps,Z]=c.useState(null),[R,Q]=c.useState(!1),[p,W]=c.useState(null),K=c.useMemo(()=>{const e=Array.from(w.values());return{total:e.length,working:e.filter(i=>i.status==="working"||i.status==="waiting"||i.status==="waiting_permission").length,idle:e.filter(i=>i.status==="idle").length,error:e.filter(i=>i.status==="error"||i.status==="offline"||i.status==="orphaned").length}},[w]),ns=c.useMemo(()=>m==="zone"?Ys(w,x):m==="status"?Us(w,P):Gs(w),[w,x,m,P]),V=c.useMemo(()=>{const e=N.toLowerCase().trim(),i=ns.map(l=>({...l,agents:l.agents.filter(_=>{if(j==="working"){if(_.status!=="working"&&_.status!=="waiting"&&_.status!=="waiting_permission")return!1}else if(j==="error"&&_.status!=="error"&&_.status!=="offline"&&_.status!=="orphaned")return!1;return!(e&&!_.name.toLowerCase().includes(e)&&!_.class.toLowerCase().includes(e))})}));return m==="zone"?i:i.filter(l=>l.agents.length>0)},[ns,j,N,m]),O=c.useCallback(e=>e.area?`area:${e.area.id}`:`${m}:${e.label}`,[m]),C=c.useMemo(()=>{const e=[];return V.forEach(i=>{const l=O(i);if(b.has(l))return;const _=m==="status"?ms(i.agents,{prioritizeRecentlyIdle:!0}):_s(i.agents);e.push(..._)}),e},[V,b,m,O]),gs=c.useCallback(e=>{T(i=>{const l=new Set(i);return l.has(e)?l.delete(e):l.add(e),l})},[]),xs=c.useCallback(e=>{n==null||n(e)},[n]),js=c.useCallback(e=>{J(e)},[]),Ns=c.useCallback((e,i)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",Z(i)},[]),ks=c.useCallback(()=>{Z(null)},[]),Cs=c.useCallback(e=>{if(!k)return;if(e===null){const E=M.getState(),t=Array.from(E.areas.values()).find(r=>r.assignedAgentIds.includes(k.id));t&&M.unassignAgentFromArea(k.id,t.id),J(null),Z(null);return}const i=x.get(e);if(!i)return;const l=Array.from(w.values()),_=Fs(i,l,k.position);M.updateAgent({...k,position:{...k.position,x:_.x,z:_.z}}),M.assignAgentToArea(k.id,e),J(null),Z(null)},[k,x,w]);return c.useEffect(()=>{if(C.length===0){Q(!1),W(null);return}R&&(!p||!C.some(e=>e.id===p))&&(W(C[0].id),a==null||a(C[0].id))},[C,R,p,a]),c.useEffect(()=>{const e=t=>t instanceof HTMLElement?t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable:!1,i=t=>t instanceof HTMLElement?!!t.closest(".guake-terminal")||t.classList.contains("guake-input")||t.classList.contains("agent-panel-input"):!1,l=t=>{const r=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).find(z=>z.dataset.agentId===t);r==null||r.scrollIntoView({block:"nearest",inline:"nearest"})},_=(t,r)=>{var ds,os,cs,ls,us,hs;const z=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).map(d=>{const u=d.dataset.agentId;if(!u)return null;const y=d.getBoundingClientRect();return{id:u,centerX:y.left+y.width/2,centerY:y.top+y.height/2,height:y.height}}).filter(d=>d!==null).sort((d,u)=>d.centerY-u.centerY||d.centerX-u.centerX);if(z.length===0)return t;const ss=z.reduce((d,u)=>d+u.height,0)/z.length,es=Math.max(18,ss*.6),f=[];for(const d of z){const u=f[f.length-1];if(!u){f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}]);continue}const y=u.reduce((ys,As)=>ys+As.centerY,0)/u.length;Math.abs(d.centerY-y)<=es?u.push({id:d.id,centerX:d.centerX,centerY:d.centerY}):f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}])}f.forEach(d=>d.sort((u,y)=>u.centerX-y.centerX));const Y=f.findIndex(d=>d.some(u=>u.id===t));if(Y===-1)return((os=(ds=f[0])==null?void 0:ds[0])==null?void 0:os.id)??t;const $=f[Y],v=$.findIndex(d=>d.id===t);if(v===-1)return((ls=(cs=f[0])==null?void 0:cs[0])==null?void 0:ls.id)??t;if(r==="left")return((us=$[Math.max(0,v-1)])==null?void 0:us.id)??t;if(r==="right")return((hs=$[Math.min($.length-1,v+1)])==null?void 0:hs.id)??t;const q=r==="up"?Math.max(0,Y-1):Math.min(f.length-1,Y+1),o=f[q],U=$[v].centerX;let D=o[0],is=Math.abs(D.centerX-U);for(const d of o){const u=Math.abs(d.centerX-U);u<is&&(D=d,is=u)}return(D==null?void 0:D.id)??t},E=t=>{const r=M.getShortcuts(),z=r.find(o=>o.id==="dashboard-selector-toggle"),ss=r.find(o=>o.id==="dashboard-vim-left"),es=r.find(o=>o.id==="dashboard-vim-down"),f=r.find(o=>o.id==="dashboard-vim-up"),Y=r.find(o=>o.id==="dashboard-vim-right"),$=r.find(o=>o.id==="open-terminal"),v=M.getState();if(e(t.target))if(!v.terminalOpen&&i(t.target)&&document.activeElement instanceof HTMLElement)document.activeElement.blur();else return;if(G(t,z)){if(C.length===0)return;t.preventDefault(),t.stopPropagation(),Q(!0),W(o=>{const U=o&&C.some(D=>D.id===o)?o:C[0].id;return a==null||a(U),window.setTimeout(()=>l(U),0),U});return}const q=G(t,ss)||t.key==="ArrowLeft"?"left":G(t,es)||t.key==="ArrowDown"?"down":G(t,f)||t.key==="ArrowUp"?"up":G(t,Y)||t.key==="ArrowRight"?"right":null;if(q&&R&&p){t.preventDefault(),t.stopPropagation();const o=_(p,q);o!==p&&(W(o),a==null||a(o),window.setTimeout(()=>l(o),0));return}if(G(t,$)){if(v.terminalOpen)return;if(R&&p&&v.agents.has(p)){t.preventDefault(),n==null||n(p);return}if(v.selectedAgentIds.size===1){t.preventDefault();const o=Array.from(v.selectedAgentIds)[0];n==null||n(o);return}if(v.lastSelectedAgentId&&v.agents.has(v.lastSelectedAgentId)){t.preventDefault(),n==null||n(v.lastSelectedAgentId);return}}};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[C,R,p,n,a]),c.useEffect(()=>{const e=document.activeElement;e instanceof HTMLElement&&e.closest(".guake-terminal")&&!M.getState().terminalOpen&&e.blur()},[]),s.jsxs("div",{className:"dashboard-view",children:[s.jsxs("div",{className:"dashboard-view__topbar",children:[s.jsxs("div",{className:"dashboard-view__metrics",children:[s.jsxs("button",{className:`dashboard-view__metric-btn ${j==="all"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.total}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:labels.agents")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--working ${j==="working"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("working"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.working}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.working")})]}),s.jsxs("button",{className:"dashboard-view__metric-btn dashboard-view__metric-btn--idle ",onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.idle}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.idle")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--error ${j==="error"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("error"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.error}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.error")})]})]}),s.jsx("input",{className:"dashboard-view__search",type:"text",placeholder:h("searchPlaceholder"),value:N,onChange:e=>H(e.target.value)})]}),s.jsxs("div",{className:"dashboard-view__grouping",children:[s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="zone"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("zone"),children:h("grouping.byZone")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="status"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("status"),children:h("grouping.byStatus")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="activity"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("activity"),children:h("grouping.byActivity")})]}),s.jsxs("div",{className:"dashboard-view__content",children:[V.map(e=>{const i=O(e),l=b.has(i),_=m==="status"?ms(e.agents,{prioritizeRecentlyIdle:!0}):_s(e.agents),E=e.agents.filter(r=>r.status==="working"||r.status==="waiting"||r.status==="waiting_permission").length,t=e.agents.filter(r=>P.has(r.id)).length;return s.jsxs("div",{className:`dashboard-view__zone ${ps===(e.area?e.area.id:null)&&k?"dashboard-view__zone--drag-over":""}`,onDragOver:r=>Ns(r,e.area?e.area.id:null),onDragLeave:ks,onDrop:()=>Cs(e.area?e.area.id:null),children:[s.jsxs("div",{className:"dashboard-view__zone-header",onClick:()=>gs(i),children:[s.jsxs("div",{className:"dashboard-view__zone-left",children:[s.jsx("span",{className:`dashboard-view__zone-chevron ${l?"dashboard-view__zone-chevron--collapsed":""}`,children:s.jsx(F,{name:"caret-down",size:12})}),s.jsx("span",{className:"dashboard-view__zone-dot",style:{backgroundColor:e.color}}),s.jsx("span",{className:"dashboard-view__zone-name",children:e.label}),s.jsxs("span",{className:"dashboard-view__zone-count",children:[h("agentCount",{count:e.agents.length}),E>0&&s.jsxs("span",{className:"dashboard-view__zone-working",children:[" · ",E," ",h("working")]}),t>0&&s.jsxs("span",{className:"dashboard-view__zone-unseen",children:[" · ",t," Unseen"]})]})]}),e.area&&g&&s.jsx("button",{className:"dashboard-view__zone-focus",onClick:r=>{r.stopPropagation(),g(e.area.id)},title:h("focusZone"),children:h("focusZone")})]}),!l&&s.jsx("div",{className:"dashboard-view__zone-grid",children:_.map(r=>s.jsx(fs,{agent:r,isSelected:rs.has(r.id),isKeyboardFocused:R&&p===r.id,onSelect:()=>{a==null||a(r.id),Q(!0),W(r.id)},onDoubleClick:()=>xs(r.id),onChat:()=>n==null?void 0:n(r.id),onFocus:A?()=>A(r.id):void 0,onKill:L?()=>L(r.id):void 0,onDragStart:js},r.id))})]},i)}),V.length===0&&s.jsx("div",{className:"dashboard-view__empty",children:N?h("noAgentsMatching",{search:N}):h("noAgentsSpawned")}),X.size>0&&s.jsx(ws,{buildings:X,onSelectBuilding:S})]})]})}export{Zs as DashboardView};
1
+ import{ab as as,u as ts,ar as vs,as as bs,at as zs,j as s,I as F,_ as Is,au as Es,av as $s,aw as Ds,ax as Ms,r as c,a2 as Ls,ah as Ss,W as Xs,U as Ps,H as Rs,ay as Ys,az as Us,aA as Gs,aB as ms,aC as _s,s as M,aD as Fs,n as G}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fs=as.memo(({agent:a,isSelected:A,isKeyboardFocused:L=!1,onSelect:S,onDoubleClick:n,onChat:g,onFocus:h,onKill:w,onDragStart:X})=>{const{t:x}=ts(["dashboard","common"]),P=vs().has(a.id),N=bs(a.status),H=zs(a),j=Ms(H),I=a.taskLabel?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"task",size:12})," ",a.taskLabel]}):a.currentTask||a.lastAssignedTask,m=a.status==="idle"&&a.lastActivity>0,[,B]=as.useState(0);return as.useEffect(()=>{if(!m)return;const b=window.setInterval(()=>B(T=>T+1),15e3);return()=>window.clearInterval(b)},[m]),s.jsxs("div",{className:`dash-card dash-card--${N} ${A?"dash-card--selected":""} ${L?"dash-card--keyboard-focused":""}`,"data-agent-id":a.id,onClick:S,onDoubleClick:b=>{b.stopPropagation(),n()},onDragStart:b=>{X==null||X(a),b.dataTransfer.effectAllowed="move"},draggable:!0,title:x("cards.doubleClickHint"),children:[s.jsxs("div",{className:"dash-card__row1",children:[s.jsx("span",{className:`dash-card__status-dot dash-card__status-dot--${N}`}),s.jsx("span",{className:"dash-card__name",children:a.name}),s.jsxs("span",{className:"dash-card__class",children:[s.jsx(Is,{agent:a,size:14})," ",a.class]}),s.jsxs("span",{className:`dash-card__provider dash-card__provider--${a.provider}`,children:[s.jsx(F,{name:a.provider==="codex"||a.provider==="opencode"?"status-pending":"robot",size:11,weight:a.provider==="codex"||a.provider==="opencode"?"fill":"regular",color:a.provider==="codex"?"#a16207":a.provider==="opencode"?"#4ade80":void 0})," ",a.provider]}),P&&s.jsx("span",{className:"dash-card__unseen-badge",title:"New output available - click to view",children:"!"})]}),s.jsxs("div",{className:"dash-card__row2",children:[s.jsx("span",{className:`dash-card__status dash-card__status--${N}`,children:P?"Unseen":a.status}),s.jsxs("div",{className:"dash-card__context",children:[s.jsx("div",{className:"dash-card__context-bar",children:s.jsx("div",{className:`dash-card__context-fill dash-card__context-fill--${j}`,style:{width:`${H}%`}})}),s.jsxs("span",{className:`dash-card__context-pct dash-card__context-pct--${j}`,children:[H,"%"]})]})]}),s.jsxs("div",{className:"dash-card__row3",children:[s.jsxs("span",{className:"dash-card__workdir",title:a.cwd,children:[s.jsx(F,{name:"folder",size:11})," ",a.cwd.split("/").pop()||a.cwd]}),m&&s.jsxs("span",{className:"dash-card__idle-time",style:{color:Ds(a.lastActivity)},title:$s(a.lastActivity),children:[s.jsx(F,{name:"status-waiting-input",size:10})," ",Es(a.lastActivity)]})]}),I&&s.jsx("div",{className:"dash-card__row4",children:s.jsx("span",{className:"dash-card__task",children:I})}),s.jsxs("div",{className:"dash-card__actions",children:[g&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--chat",onClick:b=>{b.stopPropagation(),g()},title:x("cards.openTerminal"),children:x("cards.chat")}),w&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--danger",onClick:b=>{b.stopPropagation(),w()},title:x("cards.killAgent"),children:x("cards.stop")})]})]})});fs.displayName="AgentCard";const ws=({buildings:a,onSelectBuilding:A})=>{const{t:L}=ts(["dashboard"]),S=c.useMemo(()=>Array.from(a.values()).sort((n,g)=>n.name.localeCompare(g.name)),[a]);return s.jsxs("div",{className:"dashboard-view__buildings",children:[s.jsxs("div",{className:"dashboard-view__buildings-header",children:[s.jsx("span",{className:"dashboard-view__buildings-title",children:L("buildings.title")}),s.jsx("span",{className:"dashboard-view__buildings-count",children:S.length})]}),s.jsx("div",{className:"dashboard-view__buildings-row",children:S.map(n=>{const g=bs(n.status),h=Ls(n.type);return s.jsxs("button",{className:`dash-pill dash-pill--${g}`,onClick:()=>A==null?void 0:A(n.id),title:`${n.name} (${n.type}) - ${n.status}`,children:[s.jsx("span",{className:"dash-pill__icon",children:s.jsx(F,{name:h,size:14})}),s.jsx("span",{className:"dash-pill__name",children:n.name}),s.jsx("span",{className:`dash-pill__dot dash-pill__dot--${g}`})]},n.id)})})]})};ws.displayName="BuildingPills";function Zs({onSelectAgent:a,onFocusAgent:A,onKillAgent:L,onSelectBuilding:S,onOpenTerminal:n,onFocusZone:g}){const{t:h}=ts(["dashboard","common"]),w=Ss(),X=Xs(),x=Ps(),rs=Rs(),P=vs(),[N,H]=c.useState(""),[j,I]=c.useState("all"),[m,B]=c.useState("zone"),[b,T]=c.useState(new Set),[k,J]=c.useState(null),[ps,Z]=c.useState(null),[R,Q]=c.useState(!1),[p,W]=c.useState(null),K=c.useMemo(()=>{const e=Array.from(w.values());return{total:e.length,working:e.filter(i=>i.status==="working"||i.status==="waiting"||i.status==="waiting_permission").length,idle:e.filter(i=>i.status==="idle").length,error:e.filter(i=>i.status==="error"||i.status==="offline"||i.status==="orphaned").length}},[w]),ns=c.useMemo(()=>m==="zone"?Ys(w,x):m==="status"?Us(w,P):Gs(w),[w,x,m,P]),V=c.useMemo(()=>{const e=N.toLowerCase().trim(),i=ns.map(l=>({...l,agents:l.agents.filter(_=>{if(j==="working"){if(_.status!=="working"&&_.status!=="waiting"&&_.status!=="waiting_permission")return!1}else if(j==="error"&&_.status!=="error"&&_.status!=="offline"&&_.status!=="orphaned")return!1;return!(e&&!_.name.toLowerCase().includes(e)&&!_.class.toLowerCase().includes(e))})}));return m==="zone"?i:i.filter(l=>l.agents.length>0)},[ns,j,N,m]),O=c.useCallback(e=>e.area?`area:${e.area.id}`:`${m}:${e.label}`,[m]),C=c.useMemo(()=>{const e=[];return V.forEach(i=>{const l=O(i);if(b.has(l))return;const _=m==="status"?ms(i.agents,{prioritizeRecentlyIdle:!0}):_s(i.agents);e.push(..._)}),e},[V,b,m,O]),gs=c.useCallback(e=>{T(i=>{const l=new Set(i);return l.has(e)?l.delete(e):l.add(e),l})},[]),xs=c.useCallback(e=>{n==null||n(e)},[n]),js=c.useCallback(e=>{J(e)},[]),Ns=c.useCallback((e,i)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",Z(i)},[]),ks=c.useCallback(()=>{Z(null)},[]),Cs=c.useCallback(e=>{if(!k)return;if(e===null){const E=M.getState(),t=Array.from(E.areas.values()).find(r=>r.assignedAgentIds.includes(k.id));t&&M.unassignAgentFromArea(k.id,t.id),J(null),Z(null);return}const i=x.get(e);if(!i)return;const l=Array.from(w.values()),_=Fs(i,l,k.position);M.updateAgent({...k,position:{...k.position,x:_.x,z:_.z}}),M.assignAgentToArea(k.id,e),J(null),Z(null)},[k,x,w]);return c.useEffect(()=>{if(C.length===0){Q(!1),W(null);return}R&&(!p||!C.some(e=>e.id===p))&&(W(C[0].id),a==null||a(C[0].id))},[C,R,p,a]),c.useEffect(()=>{const e=t=>t instanceof HTMLElement?t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable:!1,i=t=>t instanceof HTMLElement?!!t.closest(".guake-terminal")||t.classList.contains("guake-input")||t.classList.contains("agent-panel-input"):!1,l=t=>{const r=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).find(z=>z.dataset.agentId===t);r==null||r.scrollIntoView({block:"nearest",inline:"nearest"})},_=(t,r)=>{var ds,os,cs,ls,us,hs;const z=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).map(d=>{const u=d.dataset.agentId;if(!u)return null;const y=d.getBoundingClientRect();return{id:u,centerX:y.left+y.width/2,centerY:y.top+y.height/2,height:y.height}}).filter(d=>d!==null).sort((d,u)=>d.centerY-u.centerY||d.centerX-u.centerX);if(z.length===0)return t;const ss=z.reduce((d,u)=>d+u.height,0)/z.length,es=Math.max(18,ss*.6),f=[];for(const d of z){const u=f[f.length-1];if(!u){f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}]);continue}const y=u.reduce((ys,As)=>ys+As.centerY,0)/u.length;Math.abs(d.centerY-y)<=es?u.push({id:d.id,centerX:d.centerX,centerY:d.centerY}):f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}])}f.forEach(d=>d.sort((u,y)=>u.centerX-y.centerX));const Y=f.findIndex(d=>d.some(u=>u.id===t));if(Y===-1)return((os=(ds=f[0])==null?void 0:ds[0])==null?void 0:os.id)??t;const $=f[Y],v=$.findIndex(d=>d.id===t);if(v===-1)return((ls=(cs=f[0])==null?void 0:cs[0])==null?void 0:ls.id)??t;if(r==="left")return((us=$[Math.max(0,v-1)])==null?void 0:us.id)??t;if(r==="right")return((hs=$[Math.min($.length-1,v+1)])==null?void 0:hs.id)??t;const q=r==="up"?Math.max(0,Y-1):Math.min(f.length-1,Y+1),o=f[q],U=$[v].centerX;let D=o[0],is=Math.abs(D.centerX-U);for(const d of o){const u=Math.abs(d.centerX-U);u<is&&(D=d,is=u)}return(D==null?void 0:D.id)??t},E=t=>{const r=M.getShortcuts(),z=r.find(o=>o.id==="dashboard-selector-toggle"),ss=r.find(o=>o.id==="dashboard-vim-left"),es=r.find(o=>o.id==="dashboard-vim-down"),f=r.find(o=>o.id==="dashboard-vim-up"),Y=r.find(o=>o.id==="dashboard-vim-right"),$=r.find(o=>o.id==="open-terminal"),v=M.getState();if(e(t.target))if(!v.terminalOpen&&i(t.target)&&document.activeElement instanceof HTMLElement)document.activeElement.blur();else return;if(G(t,z)){if(C.length===0)return;t.preventDefault(),t.stopPropagation(),Q(!0),W(o=>{const U=o&&C.some(D=>D.id===o)?o:C[0].id;return a==null||a(U),window.setTimeout(()=>l(U),0),U});return}const q=G(t,ss)||t.key==="ArrowLeft"?"left":G(t,es)||t.key==="ArrowDown"?"down":G(t,f)||t.key==="ArrowUp"?"up":G(t,Y)||t.key==="ArrowRight"?"right":null;if(q&&R&&p){t.preventDefault(),t.stopPropagation();const o=_(p,q);o!==p&&(W(o),a==null||a(o),window.setTimeout(()=>l(o),0));return}if(G(t,$)){if(v.terminalOpen)return;if(R&&p&&v.agents.has(p)){t.preventDefault(),n==null||n(p);return}if(v.selectedAgentIds.size===1){t.preventDefault();const o=Array.from(v.selectedAgentIds)[0];n==null||n(o);return}if(v.lastSelectedAgentId&&v.agents.has(v.lastSelectedAgentId)){t.preventDefault(),n==null||n(v.lastSelectedAgentId);return}}};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[C,R,p,n,a]),c.useEffect(()=>{const e=document.activeElement;e instanceof HTMLElement&&e.closest(".guake-terminal")&&!M.getState().terminalOpen&&e.blur()},[]),s.jsxs("div",{className:"dashboard-view",children:[s.jsxs("div",{className:"dashboard-view__topbar",children:[s.jsxs("div",{className:"dashboard-view__metrics",children:[s.jsxs("button",{className:`dashboard-view__metric-btn ${j==="all"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.total}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:labels.agents")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--working ${j==="working"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("working"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.working}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.working")})]}),s.jsxs("button",{className:"dashboard-view__metric-btn dashboard-view__metric-btn--idle ",onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.idle}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.idle")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--error ${j==="error"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("error"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.error}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.error")})]})]}),s.jsx("input",{className:"dashboard-view__search",type:"text",placeholder:h("searchPlaceholder"),value:N,onChange:e=>H(e.target.value)})]}),s.jsxs("div",{className:"dashboard-view__grouping",children:[s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="zone"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("zone"),children:h("grouping.byZone")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="status"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("status"),children:h("grouping.byStatus")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="activity"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("activity"),children:h("grouping.byActivity")})]}),s.jsxs("div",{className:"dashboard-view__content",children:[V.map(e=>{const i=O(e),l=b.has(i),_=m==="status"?ms(e.agents,{prioritizeRecentlyIdle:!0}):_s(e.agents),E=e.agents.filter(r=>r.status==="working"||r.status==="waiting"||r.status==="waiting_permission").length,t=e.agents.filter(r=>P.has(r.id)).length;return s.jsxs("div",{className:`dashboard-view__zone ${ps===(e.area?e.area.id:null)&&k?"dashboard-view__zone--drag-over":""}`,onDragOver:r=>Ns(r,e.area?e.area.id:null),onDragLeave:ks,onDrop:()=>Cs(e.area?e.area.id:null),children:[s.jsxs("div",{className:"dashboard-view__zone-header",onClick:()=>gs(i),children:[s.jsxs("div",{className:"dashboard-view__zone-left",children:[s.jsx("span",{className:`dashboard-view__zone-chevron ${l?"dashboard-view__zone-chevron--collapsed":""}`,children:s.jsx(F,{name:"caret-down",size:12})}),s.jsx("span",{className:"dashboard-view__zone-dot",style:{backgroundColor:e.color}}),s.jsx("span",{className:"dashboard-view__zone-name",children:e.label}),s.jsxs("span",{className:"dashboard-view__zone-count",children:[h("agentCount",{count:e.agents.length}),E>0&&s.jsxs("span",{className:"dashboard-view__zone-working",children:[" · ",E," ",h("working")]}),t>0&&s.jsxs("span",{className:"dashboard-view__zone-unseen",children:[" · ",t," Unseen"]})]})]}),e.area&&g&&s.jsx("button",{className:"dashboard-view__zone-focus",onClick:r=>{r.stopPropagation(),g(e.area.id)},title:h("focusZone"),children:h("focusZone")})]}),!l&&s.jsx("div",{className:"dashboard-view__zone-grid",children:_.map(r=>s.jsx(fs,{agent:r,isSelected:rs.has(r.id),isKeyboardFocused:R&&p===r.id,onSelect:()=>{a==null||a(r.id),Q(!0),W(r.id)},onDoubleClick:()=>xs(r.id),onChat:()=>n==null?void 0:n(r.id),onFocus:A?()=>A(r.id):void 0,onKill:L?()=>L(r.id):void 0,onDragStart:js},r.id))})]},i)}),V.length===0&&s.jsx("div",{className:"dashboard-view__empty",children:N?h("noAgentsMatching",{search:N}):h("noAgentsSpawned")}),X.size>0&&s.jsx(ws,{buildings:X,onSelectBuilding:S})]})]})}export{Zs as DashboardView};