tide-commander 1.111.2 → 1.112.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 (41) hide show
  1. package/dist/assets/{BossLogsModal-DLTh_jKZ.js → BossLogsModal-CwHTS7Io.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-DzivoRl1.js → BossSpawnModal-BXfNSkDz.js} +1 -1
  3. package/dist/assets/{ControlsModal-B8j6My0t.js → ControlsModal-DR0t4ILF.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-BNwx7lVp.js → DockerLogsModal-DwnzwL14.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-CBoOoGL8.js → EmbeddedEditor-Cgbf4PPi.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-BACIjX54.js → GmailOAuthSetup-COUn-rL4.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-BuASGyWh.js → GoogleOAuthSetup-DY-oV0lC.js} +1 -1
  8. package/dist/assets/{IframeModal-ckpeQpQB.js → IframeModal-Cw0HXgic.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-Dh7UOnTC.js → IntegrationsPanel-Barw4hcr.js} +2 -2
  10. package/dist/assets/{LogViewerModal-Cj7Hv-mD.js → LogViewerModal-Wbt81evL.js} +1 -1
  11. package/dist/assets/{MonitoringModal-Bx4vcjBr.js → MonitoringModal-CNicCwC1.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-RBIjfi4J.js → PM2LogsModal-CjxdOw_Q.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-BBYlYIso.js → RestoreArchivedAreaModal-DMQSgBDn.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-CYB1Y5Wa.js → Scene2DCanvas-Bv96khxo.js} +1 -1
  15. package/dist/assets/{SceneManager-6vk047Kd.js → SceneManager-BegYb5dZ.js} +1 -1
  16. package/dist/assets/{SkillsPanel-CRRypqdy.js → SkillsPanel-BMXqdVzv.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-DisMBGxX.js → SlackMultiInstanceSetup-C00oSgQy.js} +1 -1
  18. package/dist/assets/{SpawnModal-qiu5nT-F.js → SpawnModal-pU2K5vrz.js} +1 -1
  19. package/dist/assets/StatisticsModal-CC9rhzmt.js +1 -0
  20. package/dist/assets/{SubordinateAssignmentModal-AUCAiGkE.js → SubordinateAssignmentModal-BPSip6u2.js} +1 -1
  21. package/dist/assets/{TriggerManagerPanel-56SuYzNh.js → TriggerManagerPanel-DPSqS7Vo.js} +1 -1
  22. package/dist/assets/{WorkflowEditorPanel-H0IGkyMd.js → WorkflowEditorPanel-Cq7ZF7dg.js} +1 -1
  23. package/dist/assets/{index-pRI5GcXd.js → index-44R4VNzL.js} +1 -1
  24. package/dist/assets/{index--3sQ1gHE.js → index-B-I8YHsB.js} +3 -3
  25. package/dist/assets/{index-DFWA70Lq.js → index-BL_PuMCK.js} +1 -1
  26. package/dist/assets/{index-C-kx99MP.js → index-ByFl2HJL.js} +1 -1
  27. package/dist/assets/{index-DY395tVJ.js → index-CiYtVsF2.js} +2 -2
  28. package/dist/assets/{index-94AqwQn0.js → index-DFJv26as.js} +1 -1
  29. package/dist/assets/{index-Dv0tQnLX.js → index-DKYfRvHE.js} +1 -1
  30. package/dist/assets/{index-DZP3fZ3b.js → index-DhZrpzSa.js} +1 -1
  31. package/dist/assets/{index-9NugNkE4.js → index-WmtsKBi6.js} +1 -1
  32. package/dist/assets/{main-Bon1sZAi.js → main-D9ETZv9V.js} +20 -20
  33. package/dist/assets/{main-BUSv52j9.css → main-OfLIQ_-I.css} +1 -1
  34. package/dist/assets/{web-RZLwjKCT.js → web-B5kMJoeB.js} +1 -1
  35. package/dist/assets/{web-CccJFC0m.js → web-DthvRrDx.js} +1 -1
  36. package/dist/assets/{web-CdhZGenV.js → web-gLG4upzZ.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/src/packages/server/routes/agents.js +17 -1
  39. package/dist/src/packages/server/services/claude-usage-service.js +164 -9
  40. package/package.json +1 -1
  41. package/dist/assets/StatisticsModal-Bzk7qqOd.js +0 -1
@@ -1,10 +1,10 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-CBoOoGL8.js","assets/main-Bon1sZAi.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-BUSv52j9.css","assets/EmbeddedEditor-O_u2UVA4.css"])))=>i.map(i=>d[i]);
2
- import{r as s,aM as Y,l as K,a_ as Kt,M as $s,S as Rt,N as Hs,s as mt,u as le,j as e,I as M,bB as Ft,f as zs,bC as As,bD as Rn,bE as Os,bF as Gs,bG as Fn,bH as In,bI as Tt,bJ as Pn,bK as Ln,bL as $n,bM as Xt,bN as Hn,bO as Us,bP as Mt,bQ as Dt,ac as it,bR as ft,bS as pt,bT as Es,bU as zn,b6 as An,bV as Jt,bW as On,bX as Gn,bY as Ss,C as Un,n as Bn}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function _n(t){const[n,o]=s.useState(null),[c,r]=s.useState(!1),i=s.useCallback(async()=>{if(t){r(!0);try{const f=await Y(K(`/api/files/git-status?path=${encodeURIComponent(t)}`)),l=await f.json();f.ok?o(l):o({isGitRepo:!1,files:[]})}catch(f){console.error("[FileExplorer] Failed to load git status:",f),o({isGitRepo:!1,files:[]})}finally{r(!1)}}},[t]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function Vn(t){try{const n=await Y(K(`/api/files/git-original?path=${encodeURIComponent(t)}`)),o=await n.json();return n.ok&&!o.isNew?{content:o.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const Kn=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",""]),Wn=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),Yn=new Set([".pdf"]),qn=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 Jn(t){const n=t.toLowerCase();return Wn.has(n)?"image":Yn.has(n)?"pdf":qn.has(n)?"binary":(Kn.has(n),"text")}function Xn(){const[t,n]=s.useState(null),[o,c]=s.useState(!1),[r,i]=s.useState(null),f=s.useCallback(async u=>{var g,j;c(!0),i(null);try{const p=u.substring(u.lastIndexOf(".")).toLowerCase(),y=Jn(p),C=u.substring(u.lastIndexOf("/")+1);if(y==="image"){const N=await Y(K(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!N.ok){const w=await N.json().catch(()=>({error:"Failed to load image"}));i(w.error||"Failed to load image"),n(null);return}const d=await N.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(y==="pdf"){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(!N.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(Kt())}`)});return}if(y==="binary"){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(!N.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(Kt())}`)});return}const R=await Y(K(`/api/files/read?path=${encodeURIComponent(u)}`)),x=await R.json();if(!R.ok){if((g=x.error)!=null&&g.includes("too large")||(j=x.error)!=null&&j.includes("binary")){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(N.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(Kt())}`)});return}}i(x.error||"Failed to load file"),n(null);return}n({...x,fileType:"text"})}catch(p){const y=p instanceof Error?p.message:"Failed to load file";i(y),n(null)}finally{c(!1)}},[]),l=s.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),i(null)},[]);return{file:t,loading:o,error:r,loadFile:f,clearFile:l,setFile:n}}const Wt="file-explorer-state",Qn=10080*60*1e3;function Zn(t,n){return n?`${Wt}-folder-${n}`:t?`${Wt}-area-${t}`:`${Wt}-default`}async function ea(t){try{const n=await Y(K(`/api/files/exists?path=${encodeURIComponent(t)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function ta({areaId:t,folderPath:n,isOpen:o}){const c=Zn(t,n),r=s.useRef(!1);s.useEffect(()=>{r.current=!1},[t,n]);const i=s.useCallback(async()=>{if(r.current)return null;r.current=!0;try{const l=localStorage.getItem(c);if(!l)return null;const u=JSON.parse(l);if(Date.now()-u.timestamp>Qn)return localStorage.removeItem(c),null;const j=(await Promise.all(u.tabs.map(async y=>({tab:y,exists:await ea(y.path)})))).filter(({exists:y})=>y).map(({tab:y})=>y);let p=u.activeTabPath;return p&&!j.some(y=>y.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(l){return console.error("[FileExplorerStorage] Failed to load state:",l),null}},[c]),f=s.useCallback(l=>{if(o)try{const u={tabs:l.tabs,activeTabPath:l.activeTabPath,viewMode:l.viewMode,selectedFolderIndex:l.selectedFolderIndex,expandedPaths:Array.from(l.expandedPaths),timestamp:Date.now()};localStorage.setItem(c,JSON.stringify(u))}catch(u){console.error("[FileExplorerStorage] Failed to save state:",u)}},[c,o]);return{loadStoredState:i,saveState:f}}const Ts=280,Ms=150,Ds=1200;function sa(){const[t,n]=s.useState(()=>{const g=$s(Rt.TREE_PANEL_WIDTH,Ts);return g>=Ms&&g<=Ds?g:Ts}),o=s.useRef(!1),[c,r]=s.useState(!1),i=s.useRef(0),f=s.useRef(0),l=s.useRef(t);l.current=t;const u=s.useCallback(g=>{g.preventDefault(),o.current=!0,r(!0),i.current=g.clientX,f.current=t,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[t]);return s.useEffect(()=>{const g=p=>{if(!o.current)return;const y=p.clientX-i.current,C=Math.min(Ds,Math.max(Ms,f.current+y));n(C)},j=()=>{o.current&&(o.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Hs(Rt.TREE_PANEL_WIDTH,l.current))};return document.addEventListener("mousemove",g),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",j)}},[]),{treePanelWidth:t,handleResizeStart:u,isResizing:c}}const na=100,aa=.65,ra=36;function ia(){const[t,n]=s.useState(()=>$s(Rt.MOBILE_TREE_PANEL_HEIGHT,0)),o=s.useRef(t);o.current=t;const c=s.useRef(0),r=s.useRef(0),i=()=>Math.floor((window.innerHeight-ra)*aa),f=p=>Math.min(i(),Math.max(na,p)),l=s.useCallback(p=>{n(p);const y=document.querySelector(".file-explorer-main");y&&y.style.setProperty("--fe-mobile-tree-height",`${p}px`)},[]),u=s.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Hs(Rt.MOBILE_TREE_PANEL_HEIGHT,o.current),mt.setTerminalResizing(!1)},[]),g=s.useCallback(p=>{p.preventDefault();const y=document.querySelector(".file-explorer-tree-panel"),C=o.current>0?o.current:(y==null?void 0:y.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 R=N=>{const d=N.clientY-c.current;l(f(r.current+d))},x=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",x),u()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",x)},[l,u]),j=s.useCallback(p=>{if(p.touches.length!==1)return;const y=document.querySelector(".file-explorer-tree-panel"),C=o.current>0?o.current:(y==null?void 0:y.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 R=N=>{if(N.touches.length!==1)return;N.preventDefault();const d=N.touches[0].clientY-c.current;l(f(r.current+d))},x=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x),u()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x)},[l,u]);return{mobileTreeHeight:t,handleResizeMouseDown:g,handleResizeTouchStart:j}}function Qt(){const[t,n]=s.useState([]),[o,c]=s.useState(!1),[r,i]=s.useState(null),[f,l]=s.useState(null),u=s.useCallback(async N=>{c(!0),i(null);try{const d=await Y(K(`/api/files/git-branches?path=${encodeURIComponent(N)}`)),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=s.useCallback(async(N,d)=>{l("checkout"),i(null);try{const v=await Y(K("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,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{l(null)}},[]),j=s.useCallback(async(N,d,v)=>{l("create"),i(null);try{const w=await Y(K("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,name:d,startPoint:v})}),S=await w.json();return w.ok||i(S.error||"Failed to create branch"),S}catch(w){console.error("[GitBranches] Create branch failed:",w);const S={success:!1,error:"Failed to create branch"};return i(S.error),S}finally{l(null)}},[]),p=s.useCallback(async N=>{l("pull"),i(null);try{const d=await Y(K("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),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{l(null)}},[]),y=s.useCallback(async N=>{l("push"),i(null);try{const d=await Y(K("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),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{l(null)}},[]),C=s.useCallback(async(N,d)=>{l("merge"),i(null);try{const v=await Y(K("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,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{l(null)}},[]),R=s.useCallback(async N=>{l("merge-abort"),i(null);try{const d=await Y(K("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),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{l(null)}},[]),x=s.useCallback(async N=>{l("merge-continue"),i(null);try{const d=await Y(K("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),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{l(null)}},[]);return{branches:t,loading:o,error:r,operationInProgress:f,loadBranches:u,checkoutBranch:g,createBranch:j,pullFromRemote:p,pushToRemote:y,mergeBranch:C,mergeAbort:R,mergeContinue:x}}const la=50,oa=400,Rs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function ca(){const[t,n]=s.useState([]),[o,c]=s.useState(!1),[r,i]=s.useState(!1),[f,l]=s.useState(null),[u,g]=s.useState(!1),[j,p]=s.useState(0),[y,C]=s.useState({...Rs}),[R,x]=s.useState(null),[N,d]=s.useState([]),[v,w]=s.useState(!1),[S,A]=s.useState([]),[H,G]=s.useState(!1),z=s.useRef(null),ae=s.useRef(""),ee=s.useCallback((O,Z,L)=>{const T=L||y,W=new URLSearchParams;return W.set("path",O),W.set("limit",String(la)),W.set("offset",String(Z)),T.branch&&W.set("branch",T.branch),T.author&&W.set("author",T.author),T.since&&W.set("since",T.since),T.until&&W.set("until",T.until),T.searchPath&&W.set("searchPath",T.searchPath),T.search&&W.set("search",T.search),W.toString()},[y]),D=s.useCallback(async O=>{ae.current=O,c(!0),l(null),x(null),d([]);try{const Z=ee(O,0),L=await Y(K(`/api/files/git-log?${Z}`)),T=await L.json();L.ok?(n(T.commits||[]),p(T.total||0),g(T.hasMore||!1)):(l(T.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),l("Failed to load git history"),n([])}finally{c(!1)}},[ee]),F=s.useCallback(async O=>{if(!(r||!u)){i(!0);try{const Z=ee(O,t.length),L=await Y(K(`/api/files/git-log?${Z}`)),T=await L.json();L.ok&&(n(W=>[...W,...T.commits||[]]),p(T.total||0),g(T.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{i(!1)}}},[ee,t.length,u,r]),I=s.useCallback(async O=>{if(x(O),!O){d([]);return}w(!0);try{const Z=ae.current,L=new URLSearchParams({path:Z,hash:O.hash}),T=await Y(K(`/api/files/git-commit-files?${L}`)),W=await T.json();T.ok?d(W.files||[]):d([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),d([])}finally{w(!1)}},[]),re=s.useCallback((O,Z)=>{C(L=>({...L,[O]:Z}))},[]),_=s.useCallback(()=>{C({...Rs})},[]);s.useEffect(()=>{const O=ae.current;if(O)return z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{D(O)},oa),()=>{z.current&&clearTimeout(z.current)}},[y]);const ge=s.useCallback(async O=>{G(!0);try{const Z=new URLSearchParams({path:O}),L=await Y(K(`/api/files/git-authors?${Z}`)),T=await L.json();L.ok&&A(T.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{G(!1)}},[]);return{commits:t,loading:o,loadingMore:r,error:f,hasMore:u,total:j,filters:y,setFilter:re,resetFilters:_,selectedCommit:R,selectCommit:I,commitFiles:N,commitFilesLoading:v,loadHistory:D,loadMore:F,authors:S,authorsLoading:H,loadAuthors:ge}}function da(t){if(!t.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 o of n){const c=t.current.querySelector(o);if(c&&Fs(c))return c}return Fs(t.current)?t.current:null}function Fs(t){const n=["auto","scroll"].includes(getComputedStyle(t).overflowY),o=t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;return n&&o}function Bs(t){if(!t)return 19.5;const n=parseFloat(getComputedStyle(t).lineHeight);return isNaN(n)?19.5:n}function Yt(t,n=!0){const o=n?t.scrollHeight:0;t.scrollTo({top:o,behavior:"smooth"})}function ua(t){const{scrollTop:n,scrollHeight:o,clientHeight:c}=t;return o<=c?100:Math.round(n/(o-c)*100)}function ha(t,n){const o=Bs(t),c=t.scrollTop,r=Math.floor(c/o)+1,i=n.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-Cgbf4PPi.js","assets/main-D9ETZv9V.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-OfLIQ_-I.css","assets/EmbeddedEditor-O_u2UVA4.css"])))=>i.map(i=>d[i]);
2
+ import{r as s,aM as Y,l as K,a_ as Kt,M as $s,S as Rt,N as Hs,s as mt,u as le,j as e,I as M,bB as Ft,f as zs,bC as As,bD as Rn,bE as Os,bF as Gs,bG as Fn,bH as In,bI as Tt,bJ as Pn,bK as Ln,bL as $n,bM as Xt,bN as Hn,bO as Us,bP as Mt,bQ as Dt,ac as it,bR as ft,bS as pt,bT as Es,bU as zn,b6 as An,bV as Jt,bW as On,bX as Gn,bY as Ss,C as Un,n as Bn}from"./main-D9ETZv9V.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function _n(t){const[n,o]=s.useState(null),[c,r]=s.useState(!1),i=s.useCallback(async()=>{if(t){r(!0);try{const f=await Y(K(`/api/files/git-status?path=${encodeURIComponent(t)}`)),l=await f.json();f.ok?o(l):o({isGitRepo:!1,files:[]})}catch(f){console.error("[FileExplorer] Failed to load git status:",f),o({isGitRepo:!1,files:[]})}finally{r(!1)}}},[t]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function Vn(t){try{const n=await Y(K(`/api/files/git-original?path=${encodeURIComponent(t)}`)),o=await n.json();return n.ok&&!o.isNew?{content:o.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const Kn=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",""]),Wn=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),Yn=new Set([".pdf"]),qn=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 Jn(t){const n=t.toLowerCase();return Wn.has(n)?"image":Yn.has(n)?"pdf":qn.has(n)?"binary":(Kn.has(n),"text")}function Xn(){const[t,n]=s.useState(null),[o,c]=s.useState(!1),[r,i]=s.useState(null),f=s.useCallback(async u=>{var g,j;c(!0),i(null);try{const p=u.substring(u.lastIndexOf(".")).toLowerCase(),y=Jn(p),C=u.substring(u.lastIndexOf("/")+1);if(y==="image"){const N=await Y(K(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!N.ok){const w=await N.json().catch(()=>({error:"Failed to load image"}));i(w.error||"Failed to load image"),n(null);return}const d=await N.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(y==="pdf"){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(!N.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(Kt())}`)});return}if(y==="binary"){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(!N.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(Kt())}`)});return}const R=await Y(K(`/api/files/read?path=${encodeURIComponent(u)}`)),x=await R.json();if(!R.ok){if((g=x.error)!=null&&g.includes("too large")||(j=x.error)!=null&&j.includes("binary")){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(N.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(Kt())}`)});return}}i(x.error||"Failed to load file"),n(null);return}n({...x,fileType:"text"})}catch(p){const y=p instanceof Error?p.message:"Failed to load file";i(y),n(null)}finally{c(!1)}},[]),l=s.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),i(null)},[]);return{file:t,loading:o,error:r,loadFile:f,clearFile:l,setFile:n}}const Wt="file-explorer-state",Qn=10080*60*1e3;function Zn(t,n){return n?`${Wt}-folder-${n}`:t?`${Wt}-area-${t}`:`${Wt}-default`}async function ea(t){try{const n=await Y(K(`/api/files/exists?path=${encodeURIComponent(t)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function ta({areaId:t,folderPath:n,isOpen:o}){const c=Zn(t,n),r=s.useRef(!1);s.useEffect(()=>{r.current=!1},[t,n]);const i=s.useCallback(async()=>{if(r.current)return null;r.current=!0;try{const l=localStorage.getItem(c);if(!l)return null;const u=JSON.parse(l);if(Date.now()-u.timestamp>Qn)return localStorage.removeItem(c),null;const j=(await Promise.all(u.tabs.map(async y=>({tab:y,exists:await ea(y.path)})))).filter(({exists:y})=>y).map(({tab:y})=>y);let p=u.activeTabPath;return p&&!j.some(y=>y.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(l){return console.error("[FileExplorerStorage] Failed to load state:",l),null}},[c]),f=s.useCallback(l=>{if(o)try{const u={tabs:l.tabs,activeTabPath:l.activeTabPath,viewMode:l.viewMode,selectedFolderIndex:l.selectedFolderIndex,expandedPaths:Array.from(l.expandedPaths),timestamp:Date.now()};localStorage.setItem(c,JSON.stringify(u))}catch(u){console.error("[FileExplorerStorage] Failed to save state:",u)}},[c,o]);return{loadStoredState:i,saveState:f}}const Ts=280,Ms=150,Ds=1200;function sa(){const[t,n]=s.useState(()=>{const g=$s(Rt.TREE_PANEL_WIDTH,Ts);return g>=Ms&&g<=Ds?g:Ts}),o=s.useRef(!1),[c,r]=s.useState(!1),i=s.useRef(0),f=s.useRef(0),l=s.useRef(t);l.current=t;const u=s.useCallback(g=>{g.preventDefault(),o.current=!0,r(!0),i.current=g.clientX,f.current=t,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[t]);return s.useEffect(()=>{const g=p=>{if(!o.current)return;const y=p.clientX-i.current,C=Math.min(Ds,Math.max(Ms,f.current+y));n(C)},j=()=>{o.current&&(o.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Hs(Rt.TREE_PANEL_WIDTH,l.current))};return document.addEventListener("mousemove",g),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",j)}},[]),{treePanelWidth:t,handleResizeStart:u,isResizing:c}}const na=100,aa=.65,ra=36;function ia(){const[t,n]=s.useState(()=>$s(Rt.MOBILE_TREE_PANEL_HEIGHT,0)),o=s.useRef(t);o.current=t;const c=s.useRef(0),r=s.useRef(0),i=()=>Math.floor((window.innerHeight-ra)*aa),f=p=>Math.min(i(),Math.max(na,p)),l=s.useCallback(p=>{n(p);const y=document.querySelector(".file-explorer-main");y&&y.style.setProperty("--fe-mobile-tree-height",`${p}px`)},[]),u=s.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Hs(Rt.MOBILE_TREE_PANEL_HEIGHT,o.current),mt.setTerminalResizing(!1)},[]),g=s.useCallback(p=>{p.preventDefault();const y=document.querySelector(".file-explorer-tree-panel"),C=o.current>0?o.current:(y==null?void 0:y.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 R=N=>{const d=N.clientY-c.current;l(f(r.current+d))},x=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",x),u()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",x)},[l,u]),j=s.useCallback(p=>{if(p.touches.length!==1)return;const y=document.querySelector(".file-explorer-tree-panel"),C=o.current>0?o.current:(y==null?void 0:y.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 R=N=>{if(N.touches.length!==1)return;N.preventDefault();const d=N.touches[0].clientY-c.current;l(f(r.current+d))},x=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x),u()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x)},[l,u]);return{mobileTreeHeight:t,handleResizeMouseDown:g,handleResizeTouchStart:j}}function Qt(){const[t,n]=s.useState([]),[o,c]=s.useState(!1),[r,i]=s.useState(null),[f,l]=s.useState(null),u=s.useCallback(async N=>{c(!0),i(null);try{const d=await Y(K(`/api/files/git-branches?path=${encodeURIComponent(N)}`)),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=s.useCallback(async(N,d)=>{l("checkout"),i(null);try{const v=await Y(K("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,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{l(null)}},[]),j=s.useCallback(async(N,d,v)=>{l("create"),i(null);try{const w=await Y(K("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,name:d,startPoint:v})}),S=await w.json();return w.ok||i(S.error||"Failed to create branch"),S}catch(w){console.error("[GitBranches] Create branch failed:",w);const S={success:!1,error:"Failed to create branch"};return i(S.error),S}finally{l(null)}},[]),p=s.useCallback(async N=>{l("pull"),i(null);try{const d=await Y(K("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),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{l(null)}},[]),y=s.useCallback(async N=>{l("push"),i(null);try{const d=await Y(K("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),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{l(null)}},[]),C=s.useCallback(async(N,d)=>{l("merge"),i(null);try{const v=await Y(K("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,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{l(null)}},[]),R=s.useCallback(async N=>{l("merge-abort"),i(null);try{const d=await Y(K("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),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{l(null)}},[]),x=s.useCallback(async N=>{l("merge-continue"),i(null);try{const d=await Y(K("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),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{l(null)}},[]);return{branches:t,loading:o,error:r,operationInProgress:f,loadBranches:u,checkoutBranch:g,createBranch:j,pullFromRemote:p,pushToRemote:y,mergeBranch:C,mergeAbort:R,mergeContinue:x}}const la=50,oa=400,Rs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function ca(){const[t,n]=s.useState([]),[o,c]=s.useState(!1),[r,i]=s.useState(!1),[f,l]=s.useState(null),[u,g]=s.useState(!1),[j,p]=s.useState(0),[y,C]=s.useState({...Rs}),[R,x]=s.useState(null),[N,d]=s.useState([]),[v,w]=s.useState(!1),[S,A]=s.useState([]),[H,G]=s.useState(!1),z=s.useRef(null),ae=s.useRef(""),ee=s.useCallback((O,Z,L)=>{const T=L||y,W=new URLSearchParams;return W.set("path",O),W.set("limit",String(la)),W.set("offset",String(Z)),T.branch&&W.set("branch",T.branch),T.author&&W.set("author",T.author),T.since&&W.set("since",T.since),T.until&&W.set("until",T.until),T.searchPath&&W.set("searchPath",T.searchPath),T.search&&W.set("search",T.search),W.toString()},[y]),D=s.useCallback(async O=>{ae.current=O,c(!0),l(null),x(null),d([]);try{const Z=ee(O,0),L=await Y(K(`/api/files/git-log?${Z}`)),T=await L.json();L.ok?(n(T.commits||[]),p(T.total||0),g(T.hasMore||!1)):(l(T.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),l("Failed to load git history"),n([])}finally{c(!1)}},[ee]),F=s.useCallback(async O=>{if(!(r||!u)){i(!0);try{const Z=ee(O,t.length),L=await Y(K(`/api/files/git-log?${Z}`)),T=await L.json();L.ok&&(n(W=>[...W,...T.commits||[]]),p(T.total||0),g(T.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{i(!1)}}},[ee,t.length,u,r]),I=s.useCallback(async O=>{if(x(O),!O){d([]);return}w(!0);try{const Z=ae.current,L=new URLSearchParams({path:Z,hash:O.hash}),T=await Y(K(`/api/files/git-commit-files?${L}`)),W=await T.json();T.ok?d(W.files||[]):d([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),d([])}finally{w(!1)}},[]),re=s.useCallback((O,Z)=>{C(L=>({...L,[O]:Z}))},[]),_=s.useCallback(()=>{C({...Rs})},[]);s.useEffect(()=>{const O=ae.current;if(O)return z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{D(O)},oa),()=>{z.current&&clearTimeout(z.current)}},[y]);const ge=s.useCallback(async O=>{G(!0);try{const Z=new URLSearchParams({path:O}),L=await Y(K(`/api/files/git-authors?${Z}`)),T=await L.json();L.ok&&A(T.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{G(!1)}},[]);return{commits:t,loading:o,loadingMore:r,error:f,hasMore:u,total:j,filters:y,setFilter:re,resetFilters:_,selectedCommit:R,selectCommit:I,commitFiles:N,commitFilesLoading:v,loadHistory:D,loadMore:F,authors:S,authorsLoading:H,loadAuthors:ge}}function da(t){if(!t.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 o of n){const c=t.current.querySelector(o);if(c&&Fs(c))return c}return Fs(t.current)?t.current:null}function Fs(t){const n=["auto","scroll"].includes(getComputedStyle(t).overflowY),o=t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;return n&&o}function Bs(t){if(!t)return 19.5;const n=parseFloat(getComputedStyle(t).lineHeight);return isNaN(n)?19.5:n}function Yt(t,n=!0){const o=n?t.scrollHeight:0;t.scrollTo({top:o,behavior:"smooth"})}function ua(t){const{scrollTop:n,scrollHeight:o,clientHeight:c}=t;return o<=c?100:Math.round(n/(o-c)*100)}function ha(t,n){const o=Bs(t),c=t.scrollTop,r=Math.floor(c/o)+1,i=n.split(`
3
3
  `).length;return Math.min(r,i)}function ma(t,n,o=!1){if(!n)return[];o||t.toLowerCase();const c=o?n:n.toLowerCase(),r=[];let i=0;const f=t.split(`
4
4
  `);let l=0;for(let u=0;u<f.length;u++){const g=f[u],j=o?g:g.toLowerCase();let p=0,y=j.indexOf(c);for(;y!==-1;){const C=l+y;r.push({index:i++,line:u+1,column:y,length:c.length,charIndex:C}),p=y+c.length,y=j.indexOf(c,p)}l+=g.length+1}return r}function lt(t){return/[\w]/.test(t)}function Ge(t){return/\s/.test(t)}function fa(t,n,o){let c=n-1,r=o;const i=t.length,f=t[c]||"";if(r<f.length){const g=lt(f[r]);if(!Ge(f[r]))for(;r<f.length&&!Ge(f[r])&&lt(f[r])===g;)r++}for(;c<i;){const g=t[c]||"";for(;r<g.length&&Ge(g[r]);)r++;if(r<g.length)return{line:c+1,col:r};c++,r=0}const l=i,u=Math.max(0,(t[i-1]||"").length-1);return{line:l,col:u}}function pa(t,n,o){let c=n-1,r=o+1;const i=t.length;for(;c<i;){const u=t[c]||"";for(;r<u.length&&Ge(u[r]);)r++;if(r<u.length)break;c++,r=0}if(c>=i)return{line:i,col:Math.max(0,(t[i-1]||"").length-1)};const f=t[c]||"",l=lt(f[r]);for(;r+1<f.length&&!Ge(f[r+1])&&lt(f[r+1])===l;)r++;return{line:c+1,col:r}}function ga(t,n,o){let c=n-1,r=o-1;for(;c>=0;){const l=t[c]||"";for(;r>=0&&Ge(l[r]);)r--;if(r>=0)break;c--,c>=0&&(r=(t[c]||"").length-1)}if(c<0)return{line:1,col:0};const i=t[c]||"",f=lt(i[r]);for(;r>0&&!Ge(i[r-1])&&lt(i[r-1])===f;)r--;return{line:c+1,col:r}}function xa(t,n,o,c){if(c==="none")return"";const{anchorLine:r,anchorCol:i,headLine:f,headCol:l}=o;if(c==="line"){const C=Math.min(r,f),R=Math.max(r,f);return n.slice(C-1,R).join(`
5
5
  `)}let u,g,j,p;if(r<f||r===f&&i<=l?(u=r,g=i,j=f,p=l):(u=f,g=l,j=r,p=i),u===j)return(n[u-1]||"").substring(g,p+1);const y=[];y.push((n[u-1]||"").substring(g));for(let C=u;C<j-1;C++)y.push(n[C]||"");return y.push((n[j-1]||"").substring(0,p+1)),y.join(`
6
6
  `)}function _s(t){const{containerRef:n,isEnabled:o=!0,content:c="",onClose:r,onSearchOpen:i}=t,f=s.useRef({percentage:0,line:1,column:1}),l=s.useRef(null),u=s.useRef(19.5),g=s.useMemo(()=>c.split(`
7
- `),[c]),j=g.length,[p,y]=s.useState(1),[C,R]=s.useState(0),[x,N]=s.useState(!1),[d,v]=s.useState("none"),[w,S]=s.useState(null),[A,H]=s.useState(!1),[G,z]=s.useState(""),[ae,ee]=s.useState(0),[D,F]=s.useState(!1),I=s.useMemo(()=>ma(c,G,!1),[c,G]),re=s.useCallback(()=>{const m=l.current;if(!m)return;const q=ua(m),ie=ha(m,c),V=Math.max(1,Math.round(m.scrollLeft/7.8)+1);f.current={percentage:q,line:ie,column:V}},[c]),_=s.useCallback(()=>{H(!0),z(""),ee(0),i==null||i()},[i]),ge=s.useCallback(()=>{H(!1),z(""),ee(0)},[]),O=s.useCallback(()=>{F(m=>!m)},[]),Z=s.useCallback(m=>{const q=l.current;if(!q)return;const ie=q.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;q.scrollTo({top:Math.max(0,Q-te),behavior:"smooth"})},[]);s.useEffect(()=>{!A||I.length===0||ee(0)},[I,A]),s.useEffect(()=>{if(!A||I.length===0)return;const m=I[ae];m&&(y(m.line),R(m.column),Z(m.line))},[A,I,ae,Z]);const L=s.useCallback(()=>{I.length!==0&&ee(m=>(m+1)%I.length)},[I]),T=s.useCallback(()=>{I.length!==0&&ee(m=>(m-1+I.length)%I.length)},[I]),W=s.useCallback(m=>{const q=l.current;if(!q)return;const ie=q.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=q.scrollTop,U=xe+q.clientHeight;te<xe?q.scrollTo({top:Math.max(0,te),behavior:"auto"}):Ne>U&&q.scrollTo({top:Ne-q.clientHeight,behavior:"auto"})},[]),ne=s.useCallback((m,q)=>{y(m),R(q),W(m),d!=="none"&&S(ie=>ie?{...ie,headLine:m,headCol:q}:null)},[d,W]),be=s.useCallback(()=>{if(d==="none"||!w)return;const m=xa(c,g,w,d);m&&navigator.clipboard.writeText(m).catch(()=>{const q=document.createElement("textarea");q.value=m,q.style.position="fixed",q.style.left="-9999px",document.body.appendChild(q),q.select(),document.execCommand("copy"),document.body.removeChild(q)}),v("none"),S(null)},[d,w,c,g]),de=s.useCallback(m=>{const q=m.target;if((q.tagName==="INPUT"||q.tagName==="TEXTAREA")&&m.key!=="Escape")return;const ue=l.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,se)=>{const pe=Math.max(0,(g[U-1]||"").length-1);return Math.min(se,Math.max(0,pe))},xe=(U,se)=>{const pe=Ne(U,se);ne(U,pe)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),d==="char"?(v("none"),S(null)):(v("char"),S({anchorLine:p,anchorCol:C,headLine:p,headCol:C})),V=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),d==="line"?(v("none"),S(null)):(v("line"),S({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"&&!A){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"&&!A){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"&&!A){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"&&!A||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"&&!A)m.preventDefault(),m.stopPropagation(),ne(1,0),Yt(ue,!1),V=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),ne(1,0),Yt(ue,!1),V=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),ne(j,0),Yt(ue,!0),V=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),ne(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;ne(p,Math.min(C+1,Math.max(0,U-1))),V=!0}else if(m.key==="w"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const U=fa(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="e"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const U=pa(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="b"&&!A){m.preventDefault(),m.stopPropagation();const U=ga(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),ne(p,0),V=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),ne(p,Math.max(0,(g[p-1]||"").length-1)),V=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const se=(g[p-1]||"").search(/\S/);ne(p,se>=0?se:0),V=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),_(),V=!0):m.key==="n"&&!A?(m.preventDefault(),m.stopPropagation(),L(),V=!0):m.key==="N"&&m.shiftKey&&!A?(m.preventDefault(),m.stopPropagation(),T(),V=!0):m.key==="?"&&d==="none"?(m.preventDefault(),m.stopPropagation(),O(),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"),S(null),V=!0):A?(m.preventDefault(),m.stopPropagation(),ge(),V=!0):x&&(m.preventDefault(),m.stopPropagation(),N(!1),V=!0));V&&(m.key!=="Escape"&&!x&&N(!0),requestAnimationFrame(re))},[r,re,j,g,p,C,W,A,ge,d,x,ne,be,_,L,T,O]);return s.useEffect(()=>{if(!o)return;const m=da(n);if(l.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=Bs(m);const q=()=>{re()};return window.addEventListener("keydown",de,{capture:!0}),m.addEventListener("scroll",q,{passive:!0}),re(),()=>{window.removeEventListener("keydown",de,{capture:!0}),m.removeEventListener("scroll",q)}},[o,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:A,searchQuery:G,searchMatches:I,currentMatchIndex:ae,startSearch:_,setSearchQuery:z,nextMatch:L,prevMatch:T,clearSearch:ge,helpActive:D,toggleHelp:O}}const Zt=({query:t,onQueryChange:n,matchCount:o,currentIndex:c,onNext:r,onPrev:i,onClose:f})=>{const{t:l}=le(["terminal"]),u=s.useRef(null);s.useEffect(()=>{var p;(p=u.current)==null||p.focus()},[]);const g=s.useCallback(p=>{p.stopPropagation(),p.key==="Enter"||p.key==="ArrowDown"?(p.preventDefault(),r()):p.key==="ArrowUp"&&(p.preventDefault(),i())},[r,i]),j=o===0&&t?l("terminal:fileExplorer.noMatches"):o>0?`${c+1}/${o}`:"";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:l("terminal:fileExplorer.searchInFile"),value:t,onChange:p=>n(p.target.value),onKeyDown:g,autoComplete:"off",spellCheck:"false"})]}),t&&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:o===0,title:l("terminal:fileExplorer.previousMatch"),"aria-label":l("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:o===0,title:l("terminal:fileExplorer.nextMatch"),"aria-label":l("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:f,title:l("terminal:fileExplorer.closeSearch"),"aria-label":l("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};Zt.displayName="SearchBar";const ya=[{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:t})=>{const{t:n}=le(["terminal"]),o=s.useCallback(i=>{i.target===i.currentTarget&&t()},[t]),c=s.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),t())},[t]),r=ya.reduce((i,f)=>(i[f.category]||(i[f.category]=[]),i[f.category].push(f),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:o,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:t,"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((l,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:l.keys.map((g,j)=>e.jsx("kbd",{className:"keybindings-help-key",children:g},j))}),e.jsx("div",{className:"keybindings-help-description",children:l.description})]},u))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};es.displayName="KeybindingsHelp";const Is=s.lazy(()=>Rn(()=>import("./EmbeddedEditor-CBoOoGL8.js"),__vite__mapDeps([0,1,2,3,4,5])).then(t=>({default:t.EmbeddedEditor}))),ba=[".md",".mdx",".markdown"],Ps="file-viewer-markdown-render",ja=[".puml",".plantuml",".iuml",".pu"],Ls="file-viewer-plantuml-render",va="https://kroki.io/plantuml/svg";function wa(t){return ba.includes(t.toLowerCase())}function Ca(t){return ja.includes(t.toLowerCase())}function Na(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ps);return c===null?!0:c==="true"}catch{return!0}}),o=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ps,String(r))}catch{}return r})},[]);return[t,o]}function ka(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ls);return c===null?!0:c==="true"}catch{return!0}}),o=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ls,String(r))}catch{}return r})},[]);return[t,o]}function Ea(t){const n=new TextEncoder().encode(t);let o="";for(const c of n)o+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(o)}`}function Ue({file:t,rightContent:n,onRevealInTree:o,editMode:c,onToggleEdit:r}){const{t:i}=le(["terminal","common"]),[f,l]=s.useState("idle"),[u,g]=s.useState("idle"),[j,p]=s.useState("idle"),y=t.fileType==="text"?Ft(t.extension):t.extension.slice(1).toUpperCase(),C=t.fileType==="text"&&t.content!=null,{settings:R}=zs(),x=async()=>{try{await Tt(t.content),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},N=()=>{const S=new Blob([t.content],{type:"text/plain;charset=utf-8"}),A=URL.createObjectURL(S),H=document.createElement("a");H.href=A,H.download=t.filename,document.body.appendChild(H),H.click(),H.remove(),setTimeout(()=>URL.revokeObjectURL(A),1e3)},d=async()=>{l("loading");try{const S=await Y(K("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!S.ok){const A=await S.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",A),l("error"),setTimeout(()=>l("idle"),2e3);return}l("success"),setTimeout(()=>l("idle"),2e3)}catch(S){console.error("Error opening file in editor:",S),l("error"),setTimeout(()=>l("idle"),2e3)}},v=async()=>{if(t.path)try{await $n(t.path),g("success"),setTimeout(()=>g("idle"),2e3)}catch(S){console.error("Error opening file explorer:",S),g("error"),setTimeout(()=>g("idle"),2e3)}},w=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:t.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[As(t.size)," • ",y,t.content&&` • ${t.content.split(`
7
+ `),[c]),j=g.length,[p,y]=s.useState(1),[C,R]=s.useState(0),[x,N]=s.useState(!1),[d,v]=s.useState("none"),[w,S]=s.useState(null),[A,H]=s.useState(!1),[G,z]=s.useState(""),[ae,ee]=s.useState(0),[D,F]=s.useState(!1),I=s.useMemo(()=>ma(c,G,!1),[c,G]),re=s.useCallback(()=>{const m=l.current;if(!m)return;const q=ua(m),ie=ha(m,c),V=Math.max(1,Math.round(m.scrollLeft/7.8)+1);f.current={percentage:q,line:ie,column:V}},[c]),_=s.useCallback(()=>{H(!0),z(""),ee(0),i==null||i()},[i]),ge=s.useCallback(()=>{H(!1),z(""),ee(0)},[]),O=s.useCallback(()=>{F(m=>!m)},[]),Z=s.useCallback(m=>{const q=l.current;if(!q)return;const ie=q.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;q.scrollTo({top:Math.max(0,Q-te),behavior:"smooth"})},[]);s.useEffect(()=>{!A||I.length===0||ee(0)},[I,A]),s.useEffect(()=>{if(!A||I.length===0)return;const m=I[ae];m&&(y(m.line),R(m.column),Z(m.line))},[A,I,ae,Z]);const L=s.useCallback(()=>{I.length!==0&&ee(m=>(m+1)%I.length)},[I]),T=s.useCallback(()=>{I.length!==0&&ee(m=>(m-1+I.length)%I.length)},[I]),W=s.useCallback(m=>{const q=l.current;if(!q)return;const ie=q.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=q.scrollTop,U=xe+q.clientHeight;te<xe?q.scrollTo({top:Math.max(0,te),behavior:"auto"}):Ne>U&&q.scrollTo({top:Ne-q.clientHeight,behavior:"auto"})},[]),ne=s.useCallback((m,q)=>{y(m),R(q),W(m),d!=="none"&&S(ie=>ie?{...ie,headLine:m,headCol:q}:null)},[d,W]),be=s.useCallback(()=>{if(d==="none"||!w)return;const m=xa(c,g,w,d);m&&navigator.clipboard.writeText(m).catch(()=>{const q=document.createElement("textarea");q.value=m,q.style.position="fixed",q.style.left="-9999px",document.body.appendChild(q),q.select(),document.execCommand("copy"),document.body.removeChild(q)}),v("none"),S(null)},[d,w,c,g]),de=s.useCallback(m=>{const q=m.target;if((q.tagName==="INPUT"||q.tagName==="TEXTAREA")&&m.key!=="Escape")return;const ue=l.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,se)=>{const pe=Math.max(0,(g[U-1]||"").length-1);return Math.min(se,Math.max(0,pe))},xe=(U,se)=>{const pe=Ne(U,se);ne(U,pe)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),d==="char"?(v("none"),S(null)):(v("char"),S({anchorLine:p,anchorCol:C,headLine:p,headCol:C})),V=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),d==="line"?(v("none"),S(null)):(v("line"),S({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"&&!A){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"&&!A){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"&&!A){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"&&!A||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"&&!A)m.preventDefault(),m.stopPropagation(),ne(1,0),Yt(ue,!1),V=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),ne(1,0),Yt(ue,!1),V=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),ne(j,0),Yt(ue,!0),V=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),ne(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;ne(p,Math.min(C+1,Math.max(0,U-1))),V=!0}else if(m.key==="w"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const U=fa(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="e"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const U=pa(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="b"&&!A){m.preventDefault(),m.stopPropagation();const U=ga(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),ne(p,0),V=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),ne(p,Math.max(0,(g[p-1]||"").length-1)),V=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const se=(g[p-1]||"").search(/\S/);ne(p,se>=0?se:0),V=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),_(),V=!0):m.key==="n"&&!A?(m.preventDefault(),m.stopPropagation(),L(),V=!0):m.key==="N"&&m.shiftKey&&!A?(m.preventDefault(),m.stopPropagation(),T(),V=!0):m.key==="?"&&d==="none"?(m.preventDefault(),m.stopPropagation(),O(),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"),S(null),V=!0):A?(m.preventDefault(),m.stopPropagation(),ge(),V=!0):x&&(m.preventDefault(),m.stopPropagation(),N(!1),V=!0));V&&(m.key!=="Escape"&&!x&&N(!0),requestAnimationFrame(re))},[r,re,j,g,p,C,W,A,ge,d,x,ne,be,_,L,T,O]);return s.useEffect(()=>{if(!o)return;const m=da(n);if(l.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=Bs(m);const q=()=>{re()};return window.addEventListener("keydown",de,{capture:!0}),m.addEventListener("scroll",q,{passive:!0}),re(),()=>{window.removeEventListener("keydown",de,{capture:!0}),m.removeEventListener("scroll",q)}},[o,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:A,searchQuery:G,searchMatches:I,currentMatchIndex:ae,startSearch:_,setSearchQuery:z,nextMatch:L,prevMatch:T,clearSearch:ge,helpActive:D,toggleHelp:O}}const Zt=({query:t,onQueryChange:n,matchCount:o,currentIndex:c,onNext:r,onPrev:i,onClose:f})=>{const{t:l}=le(["terminal"]),u=s.useRef(null);s.useEffect(()=>{var p;(p=u.current)==null||p.focus()},[]);const g=s.useCallback(p=>{p.stopPropagation(),p.key==="Enter"||p.key==="ArrowDown"?(p.preventDefault(),r()):p.key==="ArrowUp"&&(p.preventDefault(),i())},[r,i]),j=o===0&&t?l("terminal:fileExplorer.noMatches"):o>0?`${c+1}/${o}`:"";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:l("terminal:fileExplorer.searchInFile"),value:t,onChange:p=>n(p.target.value),onKeyDown:g,autoComplete:"off",spellCheck:"false"})]}),t&&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:o===0,title:l("terminal:fileExplorer.previousMatch"),"aria-label":l("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:o===0,title:l("terminal:fileExplorer.nextMatch"),"aria-label":l("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:f,title:l("terminal:fileExplorer.closeSearch"),"aria-label":l("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};Zt.displayName="SearchBar";const ya=[{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:t})=>{const{t:n}=le(["terminal"]),o=s.useCallback(i=>{i.target===i.currentTarget&&t()},[t]),c=s.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),t())},[t]),r=ya.reduce((i,f)=>(i[f.category]||(i[f.category]=[]),i[f.category].push(f),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:o,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:t,"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((l,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:l.keys.map((g,j)=>e.jsx("kbd",{className:"keybindings-help-key",children:g},j))}),e.jsx("div",{className:"keybindings-help-description",children:l.description})]},u))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};es.displayName="KeybindingsHelp";const Is=s.lazy(()=>Rn(()=>import("./EmbeddedEditor-Cgbf4PPi.js"),__vite__mapDeps([0,1,2,3,4,5])).then(t=>({default:t.EmbeddedEditor}))),ba=[".md",".mdx",".markdown"],Ps="file-viewer-markdown-render",ja=[".puml",".plantuml",".iuml",".pu"],Ls="file-viewer-plantuml-render",va="https://kroki.io/plantuml/svg";function wa(t){return ba.includes(t.toLowerCase())}function Ca(t){return ja.includes(t.toLowerCase())}function Na(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ps);return c===null?!0:c==="true"}catch{return!0}}),o=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ps,String(r))}catch{}return r})},[]);return[t,o]}function ka(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ls);return c===null?!0:c==="true"}catch{return!0}}),o=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ls,String(r))}catch{}return r})},[]);return[t,o]}function Ea(t){const n=new TextEncoder().encode(t);let o="";for(const c of n)o+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(o)}`}function Ue({file:t,rightContent:n,onRevealInTree:o,editMode:c,onToggleEdit:r}){const{t:i}=le(["terminal","common"]),[f,l]=s.useState("idle"),[u,g]=s.useState("idle"),[j,p]=s.useState("idle"),y=t.fileType==="text"?Ft(t.extension):t.extension.slice(1).toUpperCase(),C=t.fileType==="text"&&t.content!=null,{settings:R}=zs(),x=async()=>{try{await Tt(t.content),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},N=()=>{const S=new Blob([t.content],{type:"text/plain;charset=utf-8"}),A=URL.createObjectURL(S),H=document.createElement("a");H.href=A,H.download=t.filename,document.body.appendChild(H),H.click(),H.remove(),setTimeout(()=>URL.revokeObjectURL(A),1e3)},d=async()=>{l("loading");try{const S=await Y(K("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!S.ok){const A=await S.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",A),l("error"),setTimeout(()=>l("idle"),2e3);return}l("success"),setTimeout(()=>l("idle"),2e3)}catch(S){console.error("Error opening file in editor:",S),l("error"),setTimeout(()=>l("idle"),2e3)}},v=async()=>{if(t.path)try{await $n(t.path),g("success"),setTimeout(()=>g("idle"),2e3)}catch(S){console.error("Error opening file explorer:",S),g("error"),setTimeout(()=>g("idle"),2e3)}},w=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:t.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[As(t.size)," • ",y,t.content&&` • ${t.content.split(`
8
8
  `).length} lines`]})]}),e.jsxs("div",{className:"file-viewer-header-right",children:[r&&t.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"})})}),C&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${j}`,onClick:x,title:i("terminal:fileExplorer.copyAllTitle"),children:i(j==="copied"?"terminal:fileExplorer.copied":j==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyAll")}),e.jsx("button",{className:"file-viewer-download-btn",onClick:N,title:i("terminal:fileExplorer.downloadFileTitle"),children:i("common:buttons.download")})]}),e.jsx("button",{className:`file-viewer-reveal-explorer-btn ${u}`,onClick:v,disabled:!t.path,title:w,"aria-label":w,children:u==="success"?e.jsx(M,{name:"check",size:14}):u==="error"?e.jsx(M,{name:"cross",size:14}):e.jsx(M,{name:"folder-open",size:14})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${f}`,onClick:d,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"})})}),o&&e.jsx("button",{className:"file-viewer-locate-btn",onClick:()=>o(t.path),title:i("terminal:fileExplorer.locateInTree"),children:e.jsx(M,{name:"target",size:14})}),n]})]})}function Sa({file:t,onRevealInTree:n,renderMarkdown:o,onToggleRender:c,editMode:r,onToggleEdit:i}){const f=s.useRef(null),l=s.useRef(null),u=s.useRef(null),{t:g}=le(["terminal","common"]),[j,p]=s.useState("idle"),[y,C]=s.useState("idle"),[R,x]=s.useState("idle"),[N,d]=s.useState("idle"),v=_s({containerRef:u,isEnabled:!0,content:t.content});s.useEffect(()=>{if(!o&&f.current){const z=Ft(t.extension);Os(z).then(()=>{f.current&&Gs(f.current)})}},[t,o]);const w=s.useCallback(async()=>{if(!l.current){p("error"),setTimeout(()=>p("idle"),2e3);return}try{const z=l.current.innerHTML,ae=Fn(z),ee=l.current.innerText;await In(ae,ee),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},[]),S=s.useCallback(async()=>{if(!l.current){C("error"),setTimeout(()=>C("idle"),2e3);return}try{const z=l.current.innerHTML;await Tt(z),C("copied"),setTimeout(()=>C("idle"),2e3)}catch{C("error"),setTimeout(()=>C("idle"),2e3)}},[]),A=s.useCallback(async()=>{try{await Tt(t.content),x("copied"),setTimeout(()=>x("idle"),2e3)}catch{x("error"),setTimeout(()=>x("idle"),2e3)}},[t.content]),H=s.useCallback(async()=>{try{await Tt(t.content),d("copied"),setTimeout(()=>d("idle"),2e3)}catch{d("error"),setTimeout(()=>d("idle"),2e3)}},[t.content]),G=e.jsxs("div",{className:"file-viewer-header-buttons",children:[o&&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 ${y}`,onClick:S,title:g("terminal:fileExplorer.copyHtmlTitle"),children:g(y==="copied"?"terminal:fileExplorer.copied":y==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${R}`,onClick:A,title:g("terminal:fileExplorer.copyMarkdownTitle"),children:g(R==="copied"?"terminal:fileExplorer.copied":R==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${N}`,onClick:H,title:g("terminal:fileExplorer.copyOriginalTitle"),children:g(N==="copied"?"terminal:fileExplorer.copied":N==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${o?"active":""}`,onClick:c,title:g(o?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:o?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,onRevealInTree:n,rightContent:G,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[o?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:l,children:e.jsx(Pn,{remarkPlugins:[Ln],children:t.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:t.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 Ta({file:t,onRevealInTree:n,renderPlantUml:o,onToggleRender:c,editMode:r,onToggleEdit:i}){const{t:f}=le(["terminal"]),l=s.useRef(null),u=s.useRef(null),[g,j]=s.useState(null),[p,y]=s.useState(!1),[C,R]=s.useState(null),x=_s({containerRef:u,isEnabled:!0,content:t.content});s.useEffect(()=>{if(!o&&l.current){const d=Ft(t.extension);Os(d).then(()=>{l.current&&Gs(l.current)})}},[t,o]),s.useEffect(()=>{if(!o)return;if(!t.content.trim()){j(null),R("Diagram is empty");return}const d=new AbortController;return y(!0),R(null),(async()=>{try{const w=await fetch(va,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:t.content,signal:d.signal});if(!w.ok)throw new Error(`Render failed (${w.status})`);const S=await w.text();if(!S.includes("<svg"))throw new Error("Invalid SVG output");j(Ea(S))}catch(w){if(d.signal.aborted)return;const S=w instanceof Error?w.message:"Failed to render diagram";R(S),j(null)}finally{d.signal.aborted||y(!1)}})(),()=>d.abort()},[t.path,t.content,o]);const N=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${o?"active":""}`,onClick:c,title:f(o?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:o?"</>":f("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,onRevealInTree:n,rightContent:N,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[o?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:t.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:l,className:"language-plaintext",children:t.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 Ma({file:t,onRevealInTree:n}){const{t:o}=le(["common","terminal"]),c=()=>{if(t.dataUrl){const r=document.createElement("a");r.href=t.dataUrl,r.download=t.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:o("common:buttons.download"),children:o("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper",children:t.dataUrl?e.jsx("img",{src:t.dataUrl,alt:t.filename,className:"file-viewer-image"}):e.jsx("div",{className:"file-viewer-placeholder",children:o("terminal:fileExplorer.failedToLoadImage")})})]})}function Da({file:t,onRevealInTree:n}){const{t:o}=le(["common","terminal"]),c=()=>{if(t.dataUrl){const r=document.createElement("a");r.href=t.dataUrl,r.download=t.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:o("common:buttons.download"),children:o("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:t.dataUrl?e.jsx("iframe",{src:t.dataUrl,title:t.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:o("terminal:fileExplorer.failedToLoadPdf")})})]})}function Ra({file:t,onRevealInTree:n}){const{t:o}=le(["terminal","common"]),c=()=>{if(t.dataUrl){const i=document.createElement("a");i.href=t.dataUrl,i.download=t.filename,i.click()}},r=()=>{const i=t.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(Ue,{file:t,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:t.filename}),e.jsx("div",{className:"file-viewer-binary-size",children:As(t.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:o("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:c,children:o("terminal:fileExplorer.downloadFile")})]})]})}function Fa({file:t,loading:n,error:o,onRevealInTree:c,onFileEdited:r}){const{t:i}=le(["terminal","common"]),[f,l]=Na(),[u,g]=ka(),[j,p]=s.useState(!1);s.useEffect(()=>{p(!1)},[t==null?void 0:t.path]);const y=s.useCallback(async w=>{if(!t)return;const S=await Y(K("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t.path,content:w})});if(!S.ok){const A=await S.json().catch(()=>({error:"Save failed"}));throw new Error(A.error||"Save failed")}},[t]),C=s.useCallback(()=>{p(w=>(w&&t&&(r==null||r(t.path)),!w))},[t,r]),R=s.useCallback(()=>{t&&(r==null||r(t.path))},[t,r]);if(n)return e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")});if(o)return e.jsx("div",{className:"file-viewer-placeholder error",children:o});if(!t)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=t.fileType||"text",N=x==="text"&&wa(t.extension),d=x==="text"&&Ca(t.extension),v=N||d;return v&&j&&t.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ue,{file:t,onRevealInTree:c,editMode:!0,onToggleEdit:C}),e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Is,{content:t.content,extension:t.extension,onSave:y,onCancel:C},t.path)})]}):x==="text"&&!v&&t.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ue,{file:t,onRevealInTree:c}),e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Is,{content:t.content,extension:t.extension,onSave:y,onCancel:R},t.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[N&&e.jsx(Sa,{file:t,onRevealInTree:c,renderMarkdown:f,onToggleRender:l,editMode:j,onToggleEdit:C}),d&&!N&&e.jsx(Ta,{file:t,onRevealInTree:c,renderPlantUml:u,onToggleRender:g,editMode:j,onToggleEdit:C}),x==="image"&&e.jsx(Ma,{file:t,onRevealInTree:c}),x==="pdf"&&e.jsx(Da,{file:t,onRevealInTree:c}),x==="binary"&&e.jsx(Ra,{file:t,onRevealInTree:c})]})}const Vs=s.memo(Fa,(t,n)=>t.loading!==n.loading||t.error!==n.error?!1:t.file===null&&n.file===null?!0:t.file===null||n.file===null?!1:t.file.path===n.file.path&&t.file.content===n.file.content&&t.file.modified===n.file.modified);Vs.displayName="FileViewer";function Ks({text:t,query:n}){if(!n)return e.jsx(e.Fragment,{children:t});const o=Hn(t,n);if(o)return e.jsxs(e.Fragment,{children:[t.slice(0,o.start),e.jsx("mark",{className:"search-highlight",children:t.slice(o.start,o.end)}),t.slice(o.end)]});const c=n.toLowerCase(),i=t.toLowerCase().indexOf(c);return i===-1?e.jsx(e.Fragment,{children:t}):e.jsxs(e.Fragment,{children:[t.slice(0,i),e.jsx("mark",{className:"search-highlight",children:t.slice(i,i+n.length)}),t.slice(i+n.length)]})}const Ia=s.memo(function({node:n,query:o,isSelected:c,onSelect:r,lineNumber:i}){const f=n.isDirectory?null:Xt(n),l=n.path.split("/");l[l.length-1];const u=l.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:o}),i&&e.jsxs("span",{className:"search-result-line-badge",children:[":",i]})]}),e.jsx("span",{className:"search-result-path",children:u})]})]})}),Pa=s.memo(function({match:n,query:o,isSelected:c,onSelect:r}){const{t:i}=le(["terminal"]),f={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},l=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:[l?e.jsx("span",{className:"content-search-icon",style:{backgroundImage:`url('${l}')`},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,y)=>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:o})})]},`${n.path}-${p.line}-${y}`)),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 La({filenameResults:t,contentResults:n,onSelectFile:o,onSelectContent:c,selectedPath:r,query:i,lineNumber:f}){const{t:l}=le(["terminal"]),u=t.length>0,g=n.length>0;return!u&&!g?e.jsx("div",{className:"search-no-results",children:l("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:l("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:t.length})]}),e.jsx("div",{className:"unified-search-section-content",children:t.map(j=>e.jsx(Ia,{node:j,query:i,isSelected:r===j.path,onSelect:o,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:l("terminal:fileExplorer.content")}),e.jsx("span",{className:"unified-search-section-count",children:l("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(Pa,{match:j,query:i,isSelected:r===j.path,onSelect:c},j.path))})]})]})}const Ws=s.memo(La,(t,n)=>!(t.query!==n.query||t.selectedPath!==n.selectedPath||t.filenameResults.length!==n.filenameResults.length||t.contentResults.length!==n.contentResults.length));Ws.displayName="UnifiedSearchResults";const $a=s.memo(function({file:n,isSelected:o,onSelect:c,onStage:r,isStaging:i,showDirPath:f,isChecked:l,onToggleCheck:u,onContextMenu:g,onDiscard:j}){const{t:p}=le(["terminal"]),y=n.status,C=pt[y],R=y==="deleted",x=y==="untracked"&&r,N=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 ${o?"selected":""}`,onClick:()=>!R&&c(n.path,y),onContextMenu:v=>{v.preventDefault(),g==null||g(v,n,y)},style:{cursor:R?"not-allowed":"pointer"},title:n.path,children:[u&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:l||!1,onChange:v=>{v.stopPropagation(),u(n.path)},onClick:v=>v.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:ft(N),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,y)},title:y==="untracked"||y==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}),Ha=16,za=22,Aa=s.memo(function t({node:n,depth:o,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:f,onStage:l,stagingPaths:u,checkedFiles:g,onToggleCheck:j,onContextMenu:p,onDirContextMenu:y,onDiscard:C}){const{t:R}=le(["terminal"]),x=o*Ha;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+za}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"&&l&&e.jsx("button",{className:`git-stage-btn ${u!=null&&u.has(n.path)?"staging":""}`,onClick:w=>{w.stopPropagation(),u!=null&&u.has(n.path)||l(n.file.path)},title:R("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 N=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${N?"expanded":""}`,style:{paddingLeft:`${x}px`},onClick:()=>r(n.path),onContextMenu:d=>{d.preventDefault(),d.stopPropagation(),y==null||y(d,n)},children:[e.jsx("span",{className:`tree-arrow ${N?"expanded":""}`,children:e.jsx(M,{name:"caret-right",size:10})}),e.jsx("img",{className:"tree-folder-icon",src:N?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:R("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),N&&e.jsx("div",{className:"tree-children",children:n.children.map(d=>e.jsx(t,{node:d,depth:o+1,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:f,onStage:l,stagingPaths:u,checkedFiles:g,onToggleCheck:j,onContextMenu:p,onDirContextMenu:y,onDiscard:C},d.path))})]})}),qt=s.memo(function({groupLabel:n,groupIcon:o,groupColor:c,files:r,treeNodes:i,viewMode:f,selectedPath:l,expandedDirs:u,onToggleDir:g,onFileSelect:j,onStageFile:p,onStageAll:y,stagingPaths:C,checkedFiles:R,onToggleCheck:x,onContextMenu:N,onDirContextMenu:d,onDiscardFile:v,onDiscardAll:w}){const{t:S}=le(["terminal"]);if(r.length===0)return null;const A=r.some(z=>z.status==="untracked"),H=A&&y&&r.length>0,G=C?r.every(z=>C.has(z.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:o}),n," (",r.length,")",H&&e.jsx("button",{className:`git-stage-all-btn ${G?"staging":""}`,onClick:z=>{z.stopPropagation(),G||y()},title:S("terminal:fileExplorer.stageAllUntracked"),disabled:G,children:G?"...":S("terminal:fileExplorer.stageAll")}),w&&e.jsxs("button",{className:"git-discard-all-btn",onClick:z=>{z.stopPropagation(),w()},title:A?`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(z=>e.jsx(Aa,{node:z,depth:0,expandedDirs:u,onToggleDir:g,selectedPath:l,onSelect:j,onStage:p,stagingPaths:C,checkedFiles:R,onToggleCheck:x,onContextMenu:N,onDirContextMenu:d,onDiscard:v},z.path))}):e.jsx("div",{className:"git-flat-content",children:r.map(z=>e.jsx($a,{file:z,isSelected:l===z.path,onSelect:j,onStage:z.status==="untracked"?p:void 0,isStaging:C==null?void 0:C.has(z.path),showDirPath:!0,isChecked:R==null?void 0:R.has(z.path),onToggleCheck:x,onContextMenu:N,onDiscard:v},z.path))})]})});function Oa({gitStatus:t,loading:n,onFileSelect:o,selectedPath:c,onRefresh:r,onStageFiles:i,stagingPaths:f,currentFolder:l,onCommitComplete:u,mergeInProgress:g,mergingBranch:j,onMergeContinue:p,onMergeAbort:y,onConflictOpen:C,onRevealInTree:R}){const{t:x}=le(["terminal","common"]),[N,d]=s.useState("tree"),[v,w]=s.useState(new Set),[S,A]=s.useState(""),[H,G]=s.useState(""),[z,ae]=s.useState(!1),[ee,D]=s.useState(new Set),[F,I]=s.useState(!1),[re,_]=s.useState(null),ge=s.useRef(null),{showToast:O}=Us(),[Z,L]=s.useState(null),[T,W]=s.useState(null),[ne,be]=s.useState(null),de=s.useCallback((k,P)=>{be({files:[k],label:k.name})},[]),m=s.useCallback(async()=>{if(!(!ne||!l))try{const k=await Y(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:ne.files.map(B=>({path:B.path,status:B.status})),directory:l})}),P=await k.json();k.ok&&P.success?(O("success","Discarded",`Reverted ${ne.files.length} file(s)`),r()):O("error","Discard Failed",P.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}finally{be(null)}},[ne,l,r,O]),q=s.useCallback((k,P,B)=>{k.preventDefault(),k.stopPropagation(),L({isOpen:!0,position:{x:k.clientX,y:k.clientY},file:P,status:B})},[]),ie=s.useCallback(async(k,P)=>{if(l)try{const B=await Y(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:k.path,status:P}],directory:l})}),ke=await B.json();B.ok&&ke.success?(O("success","Discarded",`Restored ${k.name}`),r()):O("error","Discard Failed",ke.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}},[l,r,O]),ue=s.useCallback(async k=>{try{await navigator.clipboard.writeText(k),O("success","Copied","Full path copied")}catch{O("error","Copy Failed","Could not copy path")}},[O]),V=s.useCallback(async k=>{const P=l&&k.startsWith(l+"/")?k.slice(l.length+1):k;try{await navigator.clipboard.writeText(P),O("success","Copied","Relative path copied")}catch{O("error","Copy Failed","Could not copy path")}},[l,O]),E=s.useMemo(()=>{if(!Z)return[];const{file:k,status:P}=Z,B=[];return P==="conflict"&&C?B.push({id:"open-conflict",label:x("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>C(k.path)}):P!=="deleted"&&B.push({id:"open-file",label:x("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>o(k.path,P)}),P!=="conflict"&&B.push({id:"stage-file",label:x("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i([k.path])}}),B.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(P==="modified"||P==="deleted"||P==="renamed"||P==="conflict")&&B.push({id:"discard-changes",label:x("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{ie(k,P)}}),(P==="untracked"||P==="added")&&B.push({id:"delete-file",label:x("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{ie(k,P)}}),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(k.path)}}),B.push({id:"copy-relative-path",label:x("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{V(k.path)}}),R&&P!=="deleted"&&B.push({id:"reveal-in-tree",label:x("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>R(k.path)}),B},[Z,o,i,C,R,ie,ue,V,x]),Q=s.useCallback((k,P)=>{k.preventDefault(),k.stopPropagation(),W({isOpen:!0,position:{x:k.clientX,y:k.clientY},node:P})},[]),te=s.useCallback(k=>!k.isDirectory&&k.file?[k.file]:k.children.flatMap(P=>te(P)),[]),Ne=s.useCallback(async k=>{if(!l)return;const P=te(k);if(P.length!==0)try{const B=await Y(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:P.map(Te=>({path:Te.path,status:Te.status})),directory:l})}),ke=await B.json();B.ok&&ke.success?(O("success","Discarded",`Reverted ${P.length} file(s) in ${k.name}`),r()):O("error","Discard Failed",ke.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}},[l,te,r,O]),xe=s.useMemo(()=>{if(!T)return[];const{node:k}=T,P=te(k);return[{id:"discard-dir",label:`Discard Changes (${P.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{Ne(k)}},{id:"stage-dir",label:`Stage All (${P.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i(P.map(B=>B.path))}}]},[T,te,Ne,i]),U=s.useCallback(k=>{w(P=>{const B=new Set(P);return B.has(k)?B.delete(k):B.add(k),B})},[]),{conflictFiles:se,conflictTree:pe,changesFiles:me,changesTree:Be,untrackedFiles:Se,untrackedTree:It,allDirPaths:He}=s.useMemo(()=>{if(!t||!t.isGitRepo||t.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const k=new Set,P=t.files.filter(Re=>Re.status==="conflict"),B=Mt(P);Dt(B,k);const ke=t.files.filter(Re=>Re.status==="modified"||Re.status==="added"||Re.status==="deleted"||Re.status==="renamed"),Te=Mt(ke);Dt(Te,k);const ot=t.files.filter(Re=>Re.status==="untracked"),We=Mt(ot);return Dt(We,k),{conflictFiles:P,conflictTree:B,changesFiles:ke,changesTree:Te,untrackedFiles:ot,untrackedTree:We,allDirPaths:k}},[t]);s.useEffect(()=>{w(He)},[He]),s.useEffect(()=>{t!=null&&t.files&&D(new Set(t.files.map(k=>k.path)))},[t==null?void 0:t.files]);const Pt=s.useCallback(()=>{me.length!==0&&be({files:me,label:`${me.length} changed files`})},[me]),_e=s.useCallback(()=>{Se.length!==0&&be({files:Se,label:`${Se.length} unversioned files`})},[Se]),Lt=s.useCallback(()=>{se.length!==0&&be({files:se,label:`${se.length} conflicted files`})},[se]),Ve=se.length>0;s.useEffect(()=>{if(re){const k=re.type==="error"?8e3:4e3,P=setTimeout(()=>_(null),k);return()=>clearTimeout(P)}},[re]);const gt=s.useCallback(async()=>{const k=!z;if(ae(k),k&&l){G(S);try{const B=await(await Y(K(`/api/files/git-log-message?path=${encodeURIComponent(l)}`))).json();B.message&&A(B.message)}catch{}}else A(H)},[z,l,S,H]),je=s.useCallback(k=>{D(P=>{const B=new Set(P);return B.has(k)?B.delete(k):B.add(k),B})},[]),$t=s.useCallback(()=>{if(!(t!=null&&t.files))return;const k=t.files.map(B=>B.path),P=k.every(B=>ee.has(B));D(P?new Set:new Set(k))},[t==null?void 0:t.files,ee]),ve=s.useCallback(async k=>{if(!(!l||!S.trim()||ee.size===0||F)){I(!0),_(null);try{const P=await Y(K("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:l,message:S.trim(),amend:z,paths:Array.from(ee)})}),B=await P.json();if(!P.ok||!B.success){_({type:"error",text:B.error||"Commit failed"}),I(!1);return}if(k)try{const ke=await Y(K("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:l})}),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")});A(""),G(""),ae(!1),r(),u==null||u()}catch(P){_({type:"error",text:P.message||"Commit failed"})}finally{I(!1)}}},[l,S,z,ee,F,r,u]);if(n)return e.jsx("div",{className:"git-changes-loading",children:x("terminal:fileExplorer.loadingGitStatus")});if(!t||!t.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(t.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:t.branch})})]});const xt=k=>{i([k])},Ke=()=>{const k=Se.map(P=>P.path);k.length>0&&i(k)},De=(k,P)=>{P==="conflict"&&C?C(k):o(k,P)};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})}),t.branch]}),t.counts&&e.jsxs("div",{className:"git-changes-summary",children:[(t.counts.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[t.counts.conflict,"C"]}),t.counts.modified>0&&e.jsxs("span",{className:"git-count modified",children:[t.counts.modified,"M"]}),t.counts.added>0&&e.jsxs("span",{className:"git-count added",children:[t.counts.added,"A"]}),t.counts.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[t.counts.deleted,"D"]}),t.counts.untracked>0&&e.jsxs("span",{className:"git-count untracked",children:[t.counts.untracked,"?"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${N==="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 ${N==="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:Ve,title:x(Ve?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:x("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:y,title:x("terminal:fileExplorer.abortMerge"),children:x("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(qt,{groupLabel:x("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:se,treeNodes:pe,viewMode:N,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,checkedFiles:ee,onToggleCheck:je,onContextMenu:q,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:Lt}),e.jsx(qt,{groupLabel:x("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:me,treeNodes:Be,viewMode:N,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,checkedFiles:ee,onToggleCheck:je,onContextMenu:q,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:Pt}),e.jsx(qt,{groupLabel:x("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:Se,treeNodes:It,viewMode:N,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,onStageFile:xt,onStageAll:Ke,stagingPaths:f,checkedFiles:ee,onToggleCheck:je,onContextMenu:q,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:_e})]}),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:z,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:$t,title:ee.size===t.files.length?x("terminal:fileExplorer.deselectAll"):x("terminal:fileExplorer.selectAll"),children:ee.size===t.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:S,onChange:k=>A(k.target.value),onKeyDown:k=>{(k.metaKey||k.ctrlKey)&&k.key==="Enter"&&(k.preventDefault(),ve(!1)),(k.metaKey||k.ctrlKey)&&k.shiftKey&&k.key==="Enter"&&(k.preventDefault(),ve(!0)),k.stopPropagation()},rows:3,disabled:F}),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:!S.trim()||ee.size===0||F,title:x("terminal:fileExplorer.commitCtrlEnter"),children:x(F?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>ve(!0),disabled:!S.trim()||ee.size===0||F,title:x("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:F?"...":x("terminal:fileExplorer.commitAndPush")})]})]}),Z&&e.jsx(it,{isOpen:Z.isOpen,position:Z.position,worldPosition:{x:0,z:0},actions:E,onClose:()=>L(null)}),T&&e.jsx(it,{isOpen:T.isOpen,position:T.position,worldPosition:{x:0,z:0},actions:xe,onClose:()=>W(null)}),ne&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>be(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:k=>k.stopPropagation(),children:[e.jsx("p",{children:ne.files.some(k=>k.status==="untracked"||k.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:ne.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:ne.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:ne.files.some(k=>k.status==="untracked"||k.status==="added")?"Delete":"Discard"})]})]})})]})}const Ys=s.memo(Oa,(t,n)=>t.loading!==n.loading||t.selectedPath!==n.selectedPath||t.stagingPaths!==n.stagingPaths||t.currentFolder!==n.currentFolder||t.mergeInProgress!==n.mergeInProgress||t.mergingBranch!==n.mergingBranch?!1:t.gitStatus===null&&n.gitStatus===null?!0:!(t.gitStatus===null||n.gitStatus===null||t.gitStatus.isGitRepo!==n.gitStatus.isGitRepo||t.gitStatus.branch!==n.gitStatus.branch||t.gitStatus.files.length!==n.gitStatus.files.length||t.gitStatus.mergeInProgress!==n.gitStatus.mergeInProgress));Ys.displayName="GitChanges";const Ga=s.memo(function({tab:n,isActive:o,onSelect:c,onClose:r,onContextMenu:i}){const{t:f}=le(["terminal"]),l={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},u=s.useCallback(()=>{c(n.path)},[c,n.path]),g=s.useCallback(y=>{y.button===1&&(y.preventDefault(),y.stopPropagation(),r(n.path))},[r,n.path]),j=s.useCallback(y=>{y.preventDefault(),y.stopPropagation(),r(n.path)},[r,n.path]),p=s.useCallback(y=>{y.preventDefault(),y.stopPropagation(),i(y,n)},[i,n]);return e.jsxs("div",{className:`file-tab ${o?"active":""}`,onClick:u,onMouseDown:g,onContextMenu:p,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:Xt(l),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 Ua(t){return typeof t.path=="string"&&t.path.startsWith("/")}function Ba({tabs:t,activeTabPath:n,onSelectTab:o,onCloseTab:c,onCloseAllTabs:r,onShowGitHistory:i}){const{t:f}=le(["terminal"]),[l,u]=s.useState(null),g=s.useCallback((y,C)=>{u({isOpen:!0,position:{x:y.clientX,y:y.clientY},tab:C})},[]),j=s.useCallback(()=>u(null),[]),p=s.useMemo(()=>{if(!l)return[];const y=l.tab,C=!!i&&Ua(y),R=[{id:"git-history",label:f("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!C,onClick:()=>{C&&i(y.path)}}];return r&&R.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:f("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(M,{name:"cross",size:14}),danger:!0,onClick:()=>r()}),R},[l,i,r,f]);return t.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:t.map(y=>e.jsx(Ga,{tab:y,isActive:n===y.path,onSelect:o,onClose:c,onContextMenu:g},y.path))}),l&&e.jsx(it,{isOpen:l.isOpen,position:l.position,worldPosition:{x:0,z:0},actions:p,onClose:j})]})}const qs=s.memo(Ba,(t,n)=>{if(t.activeTabPath!==n.activeTabPath||t.tabs.length!==n.tabs.length||t.onShowGitHistory!==n.onShowGitHistory||t.onCloseAllTabs!==n.onCloseAllTabs)return!1;for(let o=0;o<t.tabs.length;o++)if(t.tabs[o].path!==n.tabs[o].path)return!1;return!0});qs.displayName="FileTabs";const _a=s.memo(function({currentFolder:n,gitStatus:o,onBranchChanged:c,onMerge:r,onCompare:i,onPullConflicts:f}){const{t:l}=le(["terminal","common"]),[u,g]=s.useState(!1),[j,p]=s.useState(""),[y,C]=s.useState(!1),[R,x]=s.useState(""),[N,d]=s.useState(!1),[v,w]=s.useState(null),[S,A]=s.useState(null),H=s.useRef(null),G=s.useRef(null),z=s.useRef(null),{branches:ae,loading:ee,operationInProgress:D,loadBranches:F,checkoutBranch:I,createBranch:re,pullFromRemote:_,pushToRemote:ge}=Qt();s.useEffect(()=>{u&&n&&(F(n),setTimeout(()=>{var E;return(E=G.current)==null?void 0:E.focus()},50)),u||(p(""),C(!1),x(""),w(null))},[u,n,F]),s.useEffect(()=>{if(v){const E=v.type==="error"?8e3:3e3,Q=setTimeout(()=>w(null),E);return()=>clearTimeout(Q)}},[v]),s.useEffect(()=>{y&&setTimeout(()=>{var E;return(E=z.current)==null?void 0:E.focus()},50)},[y]),s.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 O=s.useCallback(async E=>{if(!n||D||E.isCurrent)return;const Q=await I(n,E.name);Q.success?(w({type:"success",text:l("terminal:fileExplorer.switchedToBranch",{branch:Q.branch||E.name})}),c(),F(n)):w({type:"error",text:Q.error||l("terminal:fileExplorer.checkoutFailed")})},[n,D,I,c,F]),Z=s.useCallback(async()=>{if(!n||!R.trim()||D)return;const E=await re(n,R.trim());E.success?(w({type:"success",text:l("terminal:fileExplorer.createdBranch",{branch:E.branch})}),C(!1),x(""),c(),F(n)):w({type:"error",text:E.error||l("terminal:fileExplorer.createBranchFailed")})},[n,R,D,re,c,F]),L=s.useCallback(async()=>{if(!n||D)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:l("terminal:fileExplorer.pullComplete")}),c(),F(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||l("terminal:fileExplorer.pullFailed")})},[n,D,_,c,F,f]),T=s.useCallback(async()=>{if(!n||D)return;const E=await ge(n);E.success?w({type:"success",text:l("terminal:fileExplorer.pushComplete")}):w({type:"error",text:E.error||l("terminal:fileExplorer.pushFailed")})},[n,D,ge]),[W,ne]=s.useState(!1),be=s.useCallback(async()=>{if(!(!n||D||W)){ne(!0);try{const E=await Y(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(),F(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{ne(!1)}}},[n,D,W,c,F]),de=(o==null?void 0:o.branch)||"unknown",m=!!D,q=s.useCallback((E,Q)=>{Q.isCurrent||(E.preventDefault(),E.stopPropagation(),A({isOpen:!0,position:{x:E.clientX,y:E.clientY},branch:Q.name}))},[]),ie=s.useMemo(()=>{if(!S)return[];const E=!!D||(o==null?void 0:o.mergeInProgress);return[{id:"compare",label:l("terminal:fileExplorer.showDiffWith",{branch:S.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!D,onClick:()=>{i==null||i(S.branch),g(!1)}},{id:"merge",label:l("terminal:fileExplorer.mergeInto",{source:S.branch,target:de}),icon:"⤵",disabled:!!E,onClick:()=>{r&&r(S.branch),g(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:l("terminal:fileExplorer.checkoutBranch",{branch:S.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!D,onClick:()=>{const Q=ae.find(te=>te.name===S.branch);Q&&O(Q)}}]},[S,D,o==null?void 0:o.mergeInProgress,de,r,i,ae,O]),ue=s.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=s.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:H,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:G,type:"text",className:"branch-widget-search-input",placeholder:l("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:l("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:l(D==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:T,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:l(D==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:()=>{m||C(!y)},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:l("terminal:fileExplorer.newBranch")})]})]}),y&&e.jsxs("div",{className:"branch-widget-new-branch",children:[e.jsx("input",{ref:z,type:"text",className:"branch-widget-new-branch-input",placeholder:l("terminal:fileExplorer.branchNamePlaceholder"),value:R,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:!R.trim()||m,children:D==="create"?"...":l("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[l("terminal:fileExplorer.localBranches"),ee&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",l("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[ue.length===0&&!ee&&e.jsx("div",{className:"branch-widget-empty",children:l("terminal:fileExplorer.noBranchesFound")}),ue.map(E=>e.jsxs("div",{className:`branch-widget-branch-item ${E.isCurrent?"current":""} ${m?"disabled":""}`,onClick:()=>O(E),onContextMenu:Q=>q(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(!N),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:N?"▾":"▸"}),l("terminal:fileExplorer.remoteBranches",{count:V.length})]}),N&&e.jsx("div",{className:"branch-widget-branch-list",children:V.map(E=>e.jsxs("div",{className:`branch-widget-branch-item remote ${m?"disabled":""}`,onClick:()=>O(E),onContextMenu:Q=>q(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))})]})]}),S&&e.jsx(it,{isOpen:S.isOpen,position:S.position,worldPosition:{x:0,z:0},actions:ie,onClose:()=>A(null)})]})});function Va(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function St(t,n){if(!t)return"";const o=Es.languages[n];return o?Es.highlight(t,o,n):Va(t)}function Ka(t){const n=[],o=t.split(`
9
9
  `);let c=[],r=!1,i=[],f=[],l=!1;for(const u of o)u.startsWith("<<<<<<<")?(c.length>0&&(n.push({type:"unchanged",content:c.join(`
10
10
  `)}),c=[]),r=!0,l=!1,i=[],f=[]):u.startsWith("=======")&&r?l=!0:u.startsWith(">>>>>>>")&&r?(n.push({type:"conflict",ours:i.join(`
@@ -1 +1 @@
1
- import{j as d,I as Z,ak as st,U as nt,W as rt,bZ as it,r as y,s as ne,b_ as Re,_ as ct,ad as ge,u as Fe}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function se(t){return Array.isArray?Array.isArray(t):We(t)==="[object Array]"}function ot(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function at(t){return t==null?"":ot(t)}function ee(t){return typeof t=="string"}function ze(t){return typeof t=="number"}function ut(t){return t===!0||t===!1||lt(t)&&We(t)=="[object Boolean]"}function Qe(t){return typeof t=="object"}function lt(t){return Qe(t)&&t!==null}function Q(t){return t!=null}function pe(t){return!t.trim().length}function We(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const ht="Incorrect 'index' type",dt=t=>`Invalid value for key ${t}`,ft=t=>`Pattern length exceeds max of ${t}.`,mt=t=>`Missing ${t} property in key`,gt=t=>`Property 'weight' in key '${t}' must be a positive integer`,je=Object.prototype.hasOwnProperty;class pt{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(n=>{let r=Ve(n);this._keys.push(r),this._keyMap[r.id]=r,s+=r.weight}),this._keys.forEach(n=>{n.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Ve(t){let e=null,s=null,n=null,r=1,c=null;if(ee(t)||se(t))n=t,e=$e(t),s=Ae(t);else{if(!je.call(t,"name"))throw new Error(mt("name"));const o=t.name;if(n=o,je.call(t,"weight")&&(r=t.weight,r<=0))throw new Error(gt(o));e=$e(o),s=Ae(o),c=t.getFn}return{path:e,id:s,weight:r,src:n,getFn:c}}function $e(t){return se(t)?t:t.split(".")}function Ae(t){return se(t)?t.join("."):t}function At(t,e){let s=[],n=!1;const r=(c,o,a)=>{if(Q(c))if(!o[a])s.push(c);else{let u=o[a];const l=c[u];if(!Q(l))return;if(a===o.length-1&&(ee(l)||ze(l)||ut(l)))s.push(at(l));else if(se(l)){n=!0;for(let h=0,f=l.length;h<f;h+=1)r(l[h],o,a+1)}else o.length&&r(l,o,a+1)}};return r(t,ee(e)?e.split("."):e,0),n?s:s[0]}const yt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Et={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},xt={location:0,threshold:.6,distance:100},Ct={useExtendedSearch:!1,getFn:At,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var g={...Et,...yt,...xt,...Ct};const wt=/[^ ]+/g;function Ft(t=1,e=3){const s=new Map,n=Math.pow(10,e);return{get(r){const c=r.match(wt).length;if(s.has(c))return s.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*n)/n);return s.set(c,a),a},clear(){s.clear()}}}class Me{constructor({getFn:e=g.getFn,fieldNormWeight:s=g.fieldNormWeight}={}){this.norm=Ft(s,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((s,n)=>{this._keysMap[s.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,ee(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();ee(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,n=this.size();s<n;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!Q(e)||pe(e))return;let n={v:e,i:s,n:this.norm.get(e)};this.records.push(n)}_addObject(e,s){let n={i:s,$:{}};this.keys.forEach((r,c)=>{let o=r.getFn?r.getFn(e):this.getFn(e,r.path);if(Q(o)){if(se(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(Q(h))if(ee(h)&&!pe(h)){let f={v:h,i:l,n:this.norm.get(h)};a.push(f)}else se(h)&&h.forEach((f,m)=>{u.push({nestedArrIndex:m,value:f})})}n.$[c]=a}else if(ee(o)&&!pe(o)){let a={v:o,n:this.norm.get(o)};n.$[c]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Ye(t,e,{getFn:s=g.getFn,fieldNormWeight:n=g.fieldNormWeight}={}){const r=new Me({getFn:s,fieldNormWeight:n});return r.setKeys(t.map(Ve)),r.setSources(e),r.create(),r}function Mt(t,{getFn:e=g.getFn,fieldNormWeight:s=g.fieldNormWeight}={}){const{keys:n,records:r}=t,c=new Me({getFn:e,fieldNormWeight:s});return c.setKeys(n),c.setIndexRecords(r),c}function he(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=g.distance,ignoreLocation:c=g.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(n-s);return r?o+a/r:a?1:o}function It(t=[],e=g.minMatchCharLength){let s=[],n=-1,r=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&n===-1?n=c:!a&&n!==-1&&(r=c-1,r-n+1>=e&&s.push([n,r]),n=-1)}return t[c-1]&&c-n>=e&&s.push([n,c-1]),s}const ce=32;function St(t,e,s,{location:n=g.location,distance:r=g.distance,threshold:c=g.threshold,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,includeMatches:u=g.includeMatches,ignoreLocation:l=g.ignoreLocation}={}){if(e.length>ce)throw new Error(ft(ce));const h=e.length,f=t.length,m=Math.max(0,Math.min(n,f));let A=c,E=m;const k=a>1||u,v=k?Array(f):[];let b;for(;(b=t.indexOf(e,E))>-1;){let x=he(e,{currentLocation:b,expectedLocation:m,distance:r,ignoreLocation:l});if(A=Math.min(x,A),E=b+h,k){let C=0;for(;C<h;)v[b+C]=1,C+=1}}E=-1;let L=[],Y=1,W=h+f;const oe=1<<h-1;for(let x=0;x<h;x+=1){let C=0,B=W;for(;C<B;)he(e,{errors:x,currentLocation:m+B,expectedLocation:m,distance:r,ignoreLocation:l})<=A?C=B:W=B,B=Math.floor((W-C)/2+C);W=B;let O=Math.max(1,m-B+1),K=o?f:Math.min(m+B,f)+h,V=Array(K+2);V[K+1]=(1<<x)-1;for(let R=K;R>=O;R-=1){let te=R-1,ie=s[t.charAt(te)];if(k&&(v[te]=+!!ie),V[R]=(V[R+1]<<1|1)&ie,x&&(V[R]|=(L[R+1]|L[R])<<1|1|L[R+1]),V[R]&oe&&(Y=he(e,{errors:x,currentLocation:te,expectedLocation:m,distance:r,ignoreLocation:l}),Y<=A)){if(A=Y,E=te,E<=m)break;O=Math.max(1,2*m-E)}}if(he(e,{errors:x+1,currentLocation:m,expectedLocation:m,distance:r,ignoreLocation:l})>A)break;L=V}const H={isMatch:E>=0,score:Math.max(.001,Y)};if(k){const x=It(v,a);x.length?u&&(H.indices=x):H.isMatch=!1}return H}function Bt(t){let e={};for(let s=0,n=t.length;s<n;s+=1){const r=t.charAt(s);e[r]=(e[r]||0)|1<<n-s-1}return e}const fe=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class Ge{constructor(e,{location:s=g.location,threshold:n=g.threshold,distance:r=g.distance,includeMatches:c=g.includeMatches,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,isCaseSensitive:u=g.isCaseSensitive,ignoreDiacritics:l=g.ignoreDiacritics,ignoreLocation:h=g.ignoreLocation}={}){if(this.options={location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?fe(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const f=(A,E)=>{this.chunks.push({pattern:A,alphabet:Bt(A),startIndex:E})},m=this.pattern.length;if(m>ce){let A=0;const E=m%ce,k=m-E;for(;A<k;)f(this.pattern.substr(A,ce),A),A+=ce;if(E){const v=m-ce;f(this.pattern.substr(v),v)}}else f(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=s?e:e.toLowerCase(),e=n?fe(e):e,this.pattern===e){let k={isMatch:!0,score:0};return r&&(k.indices=[[0,e.length-1]]),k}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let f=[],m=0,A=!1;this.chunks.forEach(({pattern:k,alphabet:v,startIndex:b})=>{const{isMatch:L,score:Y,indices:W}=St(e,k,v,{location:c+b,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:h});L&&(A=!0),m+=Y,L&&W&&(f=[...f,...W])});let E={isMatch:A,score:A?m/this.chunks.length:1};return A&&r&&(E.indices=f),E}}class re{constructor(e){this.pattern=e}static isMultiMatch(e){return Le(e,this.multiRegex)}static isSingleMatch(e){return Le(e,this.singleRegex)}search(){}}function Le(t,e){const s=t.match(e);return s?s[1]:null}class Dt extends re{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class kt extends re{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class Nt extends re{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class _t extends re{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class bt extends re{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class vt extends re{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class Ue extends re{constructor(e,{location:s=g.location,threshold:n=g.threshold,distance:r=g.distance,includeMatches:c=g.includeMatches,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,isCaseSensitive:u=g.isCaseSensitive,ignoreDiacritics:l=g.ignoreDiacritics,ignoreLocation:h=g.ignoreLocation}={}){super(e),this._bitapSearch=new Ge(e,{location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class He extends re{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,n;const r=[],c=this.pattern.length;for(;(n=e.indexOf(this.pattern,s))>-1;)s=n+c,r.push([n,s-1]);const o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}const ye=[Dt,He,Nt,_t,vt,bt,kt,Ue],Te=ye.length,Rt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,jt="|";function $t(t,e={}){return t.split(jt).map(s=>{let n=s.trim().split(Rt).filter(c=>c&&!!c.trim()),r=[];for(let c=0,o=n.length;c<o;c+=1){const a=n[c];let u=!1,l=-1;for(;!u&&++l<Te;){const h=ye[l];let f=h.isMultiMatch(a);f&&(r.push(new h(f,e)),u=!0)}if(!u)for(l=-1;++l<Te;){const h=ye[l];let f=h.isSingleMatch(a);if(f){r.push(new h(f,e));break}}}return r})}const Lt=new Set([Ue.type,He.type]);class Tt{constructor(e,{isCaseSensitive:s=g.isCaseSensitive,ignoreDiacritics:n=g.ignoreDiacritics,includeMatches:r=g.includeMatches,minMatchCharLength:c=g.minMatchCharLength,ignoreLocation:o=g.ignoreLocation,findAllMatches:a=g.findAllMatches,location:u=g.location,threshold:l=g.threshold,distance:h=g.distance}={}){this.query=null,this.options={isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=s?e:e.toLowerCase(),e=n?fe(e):e,this.pattern=e,this.query=$t(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:c}=this.options;e=r?e:e.toLowerCase(),e=c?fe(e):e;let o=0,a=[],u=0;for(let l=0,h=s.length;l<h;l+=1){const f=s[l];a.length=0,o=0;for(let m=0,A=f.length;m<A;m+=1){const E=f[m],{isMatch:k,indices:v,score:b}=E.search(e);if(k){if(o+=1,u+=b,n){const L=E.constructor.type;Lt.has(L)?a=[...a,...v]:a.push(v)}}else{u=0,o=0,a.length=0;break}}if(o){let m={isMatch:!0,score:u/o};return n&&(m.indices=a),m}}return{isMatch:!1,score:1}}}const Ee=[];function Pt(...t){Ee.push(...t)}function xe(t,e){for(let s=0,n=Ee.length;s<n;s+=1){let r=Ee[s];if(r.condition(t,e))return new r(t,e)}return new Ge(t,e)}const me={AND:"$and",OR:"$or"},Ce={PATH:"$path",PATTERN:"$val"},we=t=>!!(t[me.AND]||t[me.OR]),Ot=t=>!!t[Ce.PATH],Kt=t=>!se(t)&&Qe(t)&&!we(t),Pe=t=>({[me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function Je(t,e,{auto:s=!0}={}){const n=r=>{let c=Object.keys(r);const o=Ot(r);if(!o&&c.length>1&&!we(r))return n(Pe(r));if(Kt(r)){const u=o?r[Ce.PATH]:c[0],l=o?r[Ce.PATTERN]:r[u];if(!ee(l))throw new Error(dt(u));const h={keyId:Ae(u),pattern:l};return s&&(h.searcher=xe(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=r[u];se(l)&&l.forEach(h=>{a.children.push(n(h))})}),a};return we(t)||(t=Pe(t)),n(t)}function zt(t,{ignoreFieldNorm:e=g.ignoreFieldNorm}){t.forEach(s=>{let n=1;s.matches.forEach(({key:r,norm:c,score:o})=>{const a=r?r.weight:null;n*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),s.score=n})}function Qt(t,e){const s=t.matches;e.matches=[],Q(s)&&s.forEach(n=>{if(!Q(n.indices)||!n.indices.length)return;const{indices:r,value:c}=n;let o={indices:r,value:c};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),e.matches.push(o)})}function Wt(t,e){e.score=t.score}function Vt(t,e,{includeMatches:s=g.includeMatches,includeScore:n=g.includeScore}={}){const r=[];return s&&r.push(Qt),n&&r.push(Wt),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return r.length&&r.forEach(u=>{u(c,a)}),a})}class q{constructor(e,s={},n){this.options={...g,...s},this.options.useExtendedSearch,this._keyStore=new pt(this.options.keys),this.setCollection(e,n)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Me))throw new Error(ht);this._myIndex=s||Ye(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Q(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let n=0,r=this._docs.length;n<r;n+=1){const c=this._docs[n];e(c,n)&&(this.removeAt(n),n-=1,r-=1,s.push(c))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=ee(e)?ee(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return zt(u,{ignoreFieldNorm:a}),c&&u.sort(o),ze(s)&&s>-1&&(u=u.slice(0,s)),Vt(u,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const s=xe(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:c,i:o,n:a})=>{if(!Q(c))return;const{isMatch:u,score:l,indices:h}=s.searchIn(c);u&&r.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),r}_searchLogical(e){const s=Je(e,this.options),n=(a,u,l)=>{if(!a.children){const{keyId:f,searcher:m}=a,A=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(u,f),searcher:m});return A&&A.length?[{idx:l,item:u,matches:A}]:[]}const h=[];for(let f=0,m=a.children.length;f<m;f+=1){const A=a.children[f],E=n(A,u,l);if(E.length)h.push(...E);else if(a.operator===me.AND)return[]}return h},r=this._myIndex.records,c={},o=[];return r.forEach(({$:a,i:u})=>{if(Q(a)){let l=n(s,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const s=xe(e,this.options),{keys:n,records:r}=this._myIndex,c=[];return r.forEach(({$:o,i:a})=>{if(!Q(o))return;let u=[];n.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:s}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:s,searcher:n}){if(!Q(s))return[];let r=[];if(se(s))s.forEach(({v:c,i:o,n:a})=>{if(!Q(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&r.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=s,{isMatch:a,score:u,indices:l}=n.searchIn(c);a&&r.push({score:u,key:e,value:c,norm:o,indices:l})}return r}}q.version="7.1.0";q.createIndex=Ye;q.parseIndex=Mt;q.config=g;q.parseQuery=Je;Pt(Tt);const Oe={".ts":"file-code",".tsx":"atom",".js":"file-code",".jsx":"atom",".py":"file-code",".rs":"file-code",".go":"file-code",".md":"file-text",".json":"clipboard",".yaml":"gear",".yml":"gear",".css":"palette",".scss":"palette",".html":"globe",".sql":"database",".sh":"terminal",".env":"lock",".toml":"gear",".lock":"lock",default:"file-text"};function Yt(t){switch(t){case"scout":return"class-scout";case"builder":return"class-builder";case"debugger":return"class-debugger";case"architect":return"class-architect";case"warrior":return"class-warrior";case"support":return"class-support";case"boss":return"class-boss";default:return"class-default"}}function Gt(t,e=16){var r;const s="."+(((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""),n=Oe[s]||Oe.default;return d.jsx(Z,{name:n,size:e})}function cs(t,e=16){return d.jsx(Z,{name:Yt(t),size:e,weight:"fill"})}function Xe(t){const e=Math.floor(t/1e3),s=Math.floor(e/60),n=Math.floor(s/60),r=Math.floor(n/24);return r>0?`${r}d ${n%24}h ago`:n>0?`${n}h ${s%60}m ago`:s>0?`${s}m ago`:"just now"}function os(t){const s=Date.now()-t;return Xe(s)}const Ze="tide-commander:spotlight-recent-agents",Ut=15;function qe(){try{const t=localStorage.getItem(Ze);if(!t)return[];const e=JSON.parse(t);return Array.isArray(e)?e.filter(s=>typeof s=="string"):[]}catch{return[]}}function Ht(t){try{const e=[t,...qe().filter(s=>s!==t)].slice(0,Ut);localStorage.setItem(Ze,JSON.stringify(e))}catch{}}function de(t,e){if(!t)return Number.POSITIVE_INFINITY;const s=e.indexOf(t);return s===-1?Number.POSITIVE_INFINITY:s}function Ke(t){switch(t){case"agent":return"Agent";case"command":return"Command";case"area":return"Area";case"modified-file":return"Changed";case"building":return"Server";default:return t}}const Jt=["command","agent","building","area","modified-file"];function Xt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=st(),f=nt(),m=rt(),A=it(),E=y.useRef(e);E.current=e;const k=y.useRef(s);k.current=s;const v=y.useRef(n);v.current=n;const b=y.useRef(r);b.current=r;const L=y.useRef(c);L.current=c;const Y=y.useRef(o);Y.current=o;const W=y.useRef(a);W.current=a;const oe=y.useRef(u);oe.current=u;const H=y.useRef(l);H.current=l;const[x,C]=y.useState(""),[B,O]=y.useState(0);y.useEffect(()=>{t&&(C(""),O(0))},[t]);const K=ne.getShortcuts(),V=y.useMemo(()=>t?qe():[],[t]),ae=y.useMemo(()=>{if(!t)return[];const i=K.find(I=>I.id==="spawn-agent"),M=K.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:i?Re(i):"Alt+N",icon:d.jsx(Z,{name:"plus",size:16}),action:()=>{E.current(),k.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:M?Re(M):"Ctrl+K",icon:d.jsx(Z,{name:"dashboard",size:16}),action:()=>{E.current(),v.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(Z,{name:"gear",size:16}),action:()=>{E.current(),b.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(Z,{name:"chart-line",size:16}),action:()=>{var I;E.current(),(I=H.current)==null||I.call(H)}}]},[t,K]),R=y.useMemo(()=>t?Array.from(h.values()).map(i=>{const M=(A||[]).filter(T=>T.agentId===i.id).map(T=>T.filePath),I=[...new Set(M)],S=I.map(T=>T.split("/").pop()||T),N=[];i.lastAssignedTask&&N.push(i.lastAssignedTask);const j=`${i.class} • ${i.status} • ${i.cwd}`;let _=`${i.name} ${j}`;S.length>0&&(_+=` ${S.join(" ")} ${I.join(" ")}`),N.length>0&&(_+=` ${N.join(" ")}`);const z=Date.now()-i.lastActivity;let J;return i.lastAssignedTask&&(i.lastAssignedTask.length>150?J=i.lastAssignedTask.slice(0,150)+"...":J=i.lastAssignedTask),{id:`agent-${i.id}`,type:"agent",title:i.name,subtitle:j,lastUserInput:J,timeAway:z,icon:d.jsx(ct,{agent:i,size:20}),_searchText:_,_modifiedFiles:I,_userQueries:N,_agentId:i.id,action:()=>{E.current(),Ht(i.id),ne.selectAgent(i.id),ne.getState().viewMode!=="flat"&&ne.requestTerminalExpand()}}}):[],[t,h,A]),te=y.useMemo(()=>t?Array.from(f.values()).map(i=>{var M;return{id:`area-${i.id}`,type:"area",title:i.name,subtitle:`${i.assignedAgentIds.length} agents • ${((M=i.directories)==null?void 0:M.length)||0} folders`,icon:d.jsx(Z,{name:"map",size:16}),action:()=>{E.current(),ne.selectArea(i.id)}}}):[],[t,f]),ie=y.useMemo(()=>t?Array.from(m.values()).filter(i=>i.type==="server"||i.type==="boss"||i.type==="database").map(i=>{var _,z,J,T;const M=i.status==="running"?"#4ade80":i.status==="stopped"?"#f87171":"#facc15",I=i.type==="boss"?"crown":i.type==="database"?"database":"desktop";let N=`${i.type==="boss"?"Boss":i.type==="database"?"Database":"Server"} • ${i.status}`;if(i.type==="database"&&((z=(_=i.database)==null?void 0:_.connections)!=null&&z.length)){const $=i.database.connections[0];N+=` • ${$.engine} @ ${$.host}`}else i.cwd&&(N+=` • ${i.cwd}`);let j=`${i.name} ${i.type} ${i.status} ${i.cwd||""} ${((J=i.pm2)==null?void 0:J.name)||""}`;if(i.type==="database"&&((T=i.database)!=null&&T.connections))for(const $ of i.database.connections)j+=` ${$.name} ${$.engine} ${$.host} ${$.database||""} mysql postgresql sql`;return{id:`building-${i.id}`,type:"building",title:i.name,subtitle:N,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(Z,{name:"status-pending",size:10,weight:"fill",color:M}),d.jsx(Z,{name:I,size:16})]}),_searchText:j,action:()=>{var $;E.current(),i.type==="boss"?W.current(i.id):i.type==="database"?oe.current(i.id):($=i.pm2)!=null&&$.enabled&&Y.current(i.id)}}}):[],[t,m]),Ie=y.useMemo(()=>{if(!t)return[];const i=A||[],M=new Set,I=[];for(const S of i){if(M.has(S.filePath))continue;M.add(S.filePath);const N=S.filePath.split("/").pop()||S.filePath,j=S.action==="created"?"Created":S.action==="modified"?"Modified":S.action==="deleted"?"Deleted":"Read";if(I.push({id:`modified-${S.filePath}-${S.timestamp}`,type:"modified-file",title:N,subtitle:`${j} by ${S.agentName} • ${S.filePath}`,matchedText:S.filePath,icon:S.action==="deleted"?d.jsx(Z,{name:"trash",size:16}):Gt(S.filePath),action:()=>{E.current();const _=Array.from(ne.getState().areas.values());for(const z of _)for(const J of z.directories||[])if(S.filePath.startsWith(J)){ne.setFileViewerPath(S.filePath),L.current(z.id);return}ne.selectAgent(S.agentId)}}),I.length>=50)break}return I},[t,A]),Se=y.useMemo(()=>new q(R,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[R]),Be=y.useMemo(()=>new q(ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[ae]),De=y.useMemo(()=>new q(te,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[te]),ke=y.useMemo(()=>new q(Ie,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ie]),Ne=y.useMemo(()=>new q(ie,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ie]),G=y.useMemo(()=>{if(!x.trim()){const p=[];p.push(...ie);const w=[...R].sort((D,P)=>{const X=de(D._agentId,V),U=de(P._agentId,V);if(X!==U)return X-U;const ue=D.timeAway??0,le=P.timeAway??0;return ue-le});p.push(...w),p.push(...ae.slice(0,2)),p.push(...te.slice(0,2));const F={};return Jt.forEach((D,P)=>{F[D]=P}),p.sort((D,P)=>(F[D.type]??999)-(F[P.type]??999)),p}const i=x.trim().toLowerCase(),M=Se.search(x).slice(0,8),I=Be.search(x).slice(0,3),S=De.search(x).slice(0,2),N=ke.search(x).slice(0,3),j=Ne.search(x).filter(p=>{const w=p.score??1;return`${p.item.title} ${p.item.subtitle||""} ${p.item._searchText||""}`.toLowerCase().includes(i)||w<=.2}).slice(0,4),_={agent:5,building:4,command:3,area:2,"modified-file":1},z=p=>{if(!i)return 1;const w=p.title.toLowerCase();return w===i?6:w.startsWith(i)?5:w.split(/[^a-z0-9]+/i).includes(i)?4:w.includes(i)?3:`${p.subtitle||""} ${p._searchText||""} ${p.matchedText||""}`.toLowerCase().includes(i)?2:1},J=(p,w)=>{const F=(1-Math.min(1,w??1))*4;return z(p)*100+(_[p.type]??0)*5+F},T=new Map,$=(p,w)=>{const F=T.get(p.type),D={item:p,score:J(p,w)};F?F.push(D):T.set(p.type,[D])};for(const p of M){const w={...p.item};if(w._modifiedFiles&&w._modifiedFiles.length>0){const F=w._modifiedFiles.filter(D=>{var U;const P=((U=D.split("/").pop())==null?void 0:U.toLowerCase())||"",X=D.toLowerCase();return P.includes(i)||X.includes(i)});F.length>0&&(w.matchedFiles=F)}if(w._userQueries&&w._userQueries.length>0){const F=w._userQueries.find(D=>D.toLowerCase().includes(i));if(F)if(F.length>200){const P=F.toLowerCase().indexOf(i),X=Math.max(0,P-60),U=Math.min(F.length,P+i.length+100);w.matchedQuery=(X>0?"...":"")+F.slice(X,U)+(U<F.length?"...":"")}else w.matchedQuery=F}$(w,p.score)}for(const p of j)$(p.item,p.score);for(const p of I)$(p.item,p.score);for(const p of S)$(p.item,p.score);for(const p of N)$(p.item,p.score);for(const[p,w]of T)p==="agent"?w.sort((F,D)=>{const P=z(F.item),X=z(D.item);if(X!==P)return X-P;const U=de(F.item._agentId,V),ue=de(D.item._agentId,V);if(U!==ue)return U-ue;const le=F.item.timeAway??Number.POSITIVE_INFINITY,ve=D.item.timeAway??Number.POSITIVE_INFINITY;return le!==ve?le-ve:D.score-F.score}):w.sort((F,D)=>D.score-F.score);const _e=p=>p.reduce((w,F)=>Math.max(w,F.score),-1),be=[];return Array.from(T.values()).sort((p,w)=>_e(w)-_e(p)).forEach(p=>{for(const w of p)be.push(w.item)}),be},[x,Se,Be,De,ke,Ne,ae,R,te,ie,V]);y.useEffect(()=>{B>=G.length&&O(Math.max(0,G.length-1))},[G.length,B]);const et=y.useCallback(i=>{if(i.altKey&&!i.ctrlKey&&!i.metaKey&&(i.key==="p"||i.key==="n"||i.key==="P"||i.key==="N")){i.preventDefault(),i.stopPropagation(),i.nativeEvent.stopImmediatePropagation();const M=i.key.toLowerCase();O(M==="p"?I=>I>0?I-1:G.length-1:I=>I<G.length-1?I+1:0);return}switch(i.key){case"Escape":i.preventDefault(),E.current();break;case"ArrowUp":i.preventDefault(),O(M=>M>0?M-1:G.length-1);break;case"ArrowDown":i.preventDefault(),O(M=>M<G.length-1?M+1:0);break;case"Enter":i.preventDefault(),G[B]&&G[B].action();break}},[G,B]),tt=y.useCallback((i,M)=>{if(!M||!i)return i;const I=i.toLowerCase(),S=M.toLowerCase(),N=[];let j=0,_=I.indexOf(S),z=0;for(;_!==-1;)_>j&&N.push(i.slice(j,_)),N.push(ge.createElement("mark",{key:z++,className:"spotlight-highlight"},i.slice(_,_+M.length))),j=_+M.length,_=I.indexOf(S,j);return j<i.length&&N.push(i.slice(j)),N.length>0?ge.createElement(ge.Fragment,null,...N):i},[]);return{query:x,setQuery:C,selectedIndex:B,setSelectedIndex:O,results:G,handleKeyDown:et,highlightMatch:tt}}const Zt=y.forwardRef(function({query:e,onQueryChange:s,onKeyDown:n,onResetSelection:r},c){const{t:o}=Fe(["common"]);return d.jsxs("div",{className:"spotlight-input-wrapper",children:[d.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),d.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{s(a.target.value),r()},onKeyDown:n,autoFocus:!0,spellCheck:!1}),d.jsxs("div",{className:"spotlight-input-hints",children:[d.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),qt=y.memo(function({result:e,isSelected:s,query:n,highlightMatch:r,onClick:c,onMouseEnter:o}){const a=e.activityText||e.matchedFiles&&e.matchedFiles.length>0||e.matchedQuery;return d.jsxs("div",{className:`spotlight-item ${s?"selected":""} ${e.activityText?"has-activity":""}`,onClick:c,onMouseEnter:o,role:"option","aria-selected":s,children:[d.jsx("span",{className:"spotlight-item-icon","aria-hidden":"true",children:e.icon}),d.jsxs("div",{className:"spotlight-item-content",children:[d.jsxs("div",{className:"spotlight-item-header",children:[d.jsx("span",{className:"spotlight-item-title",children:r(e.title,n)}),d.jsx("span",{className:`spotlight-item-type ${e.type}`,"aria-label":Ke(e.type),children:Ke(e.type)})]}),e.subtitle&&d.jsx("span",{className:"spotlight-item-subtitle",children:r(e.subtitle,n)}),e.activityText&&d.jsx("span",{className:"spotlight-item-activity",children:r(e.activityText,n)}),a&&d.jsxs("div",{className:"spotlight-item-details",children:[e.matchedFiles&&e.matchedFiles.length>0&&d.jsx("span",{className:"spotlight-item-files",children:e.matchedFiles.map((u,l)=>d.jsxs("span",{className:"file-badge",children:[l>0&&d.jsx("span",{className:"file-separator",children:"•"}),r(u.split("/").pop()||u,n)]},u))}),e.matchedQuery&&d.jsx("span",{className:"spotlight-item-query",children:r(e.matchedQuery,n)})]}),e.timeAway!==void 0&&d.jsx("span",{className:"spotlight-item-time",children:d.jsxs("span",{className:"spotlight-time-away",children:["Idle: ",Xe(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&d.jsxs("span",{className:"spotlight-item-last-input",children:['"',r(e.lastUserInput,n),'"']})]})]})}),es=y.forwardRef(function({results:e,selectedIndex:s,query:n,highlightMatch:r,onSelectIndex:c},o){const{t:a}=Fe(["terminal"]),u=y.useRef(!1);y.useEffect(()=>{u.current=!1},[e]),y.useEffect(()=>{const f=typeof o=="function"?null:o==null?void 0:o.current;if(!f)return;const m=()=>{u.current=!0};return f.addEventListener("mousemove",m),()=>{f.removeEventListener("mousemove",m)}},[o,e]);const l={command:a("terminal:spotlight.categories.commands"),agent:a("terminal:spotlight.categories.agents"),building:a("terminal:spotlight.categories.infrastructure"),area:a("terminal:spotlight.categories.areas"),"modified-file":a("terminal:spotlight.categories.modifiedFiles")},h=y.useMemo(()=>{const f=[];let m=null,A=[];return e.forEach((E,k)=>{E.type!==m&&(m!==null&&A.length>0&&f.push([m,A]),m=E.type,A=[]),A.push({result:E,index:k})}),m!==null&&A.length>0&&f.push([m,A]),f},[e]);return y.useEffect(()=>{if(!o||typeof o=="function")return;const f=o.current;if(!f)return;const m=f.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[s,o]),e.length===0?d.jsx("div",{className:"spotlight-results",ref:o,children:d.jsx("div",{className:"spotlight-empty",children:a("terminal:spotlight.noResults")})}):d.jsx("div",{className:"spotlight-results",ref:o,children:h.map(([f,m])=>d.jsxs("div",{children:[h.length>1&&d.jsx("div",{className:"spotlight-category-header",children:l[f]||f}),m.map(({result:A,index:E})=>d.jsx(qt,{result:A,isSelected:E===s,query:n,highlightMatch:r,onClick:()=>A.action(),onMouseEnter:()=>{u.current&&c(E)}},A.id))]},f))})}),ts=y.memo(function(){const{t:e}=Fe(["terminal"]);return d.jsxs("div",{className:"spotlight-footer",children:[d.jsxs("div",{className:"spotlight-footer-left",children:[d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"↑"}),d.jsx("kbd",{children:"↓"})," ",d.jsx("kbd",{children:"Alt+N"}),d.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]})]}),d.jsx("div",{className:"spotlight-footer-right",children:d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),ss=768;function as({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=y.useRef(null),f=y.useRef(null),m=y.useRef(null),A=y.useRef(0),{query:E,setQuery:k,selectedIndex:v,setSelectedIndex:b,results:L,handleKeyDown:Y,highlightMatch:W}=Xt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});A.current=L.length,y.useEffect(()=>{t&&setTimeout(()=>{var x;(x=h.current)==null||x.focus()},50)},[t]),y.useEffect(()=>{if(!t)return;const x=window.visualViewport;if(!x||window.innerWidth>ss)return;const C=()=>{const B=f.current;B&&(B.style.height=`${x.height}px`,B.style.top=`${x.offsetTop}px`)};return C(),x.addEventListener("resize",C),x.addEventListener("scroll",C),()=>{x.removeEventListener("resize",C),x.removeEventListener("scroll",C);const B=f.current;B&&(B.style.height="",B.style.top="")}},[t]),y.useEffect(()=>{if(!t)return;const x=C=>{if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),e();return}if(C.altKey&&!C.ctrlKey&&!C.metaKey&&(C.key==="n"||C.key==="p"||C.key==="N"||C.key==="P")){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation();const B=C.key.toLowerCase(),O=A.current;b(B==="p"?K=>K>0?K-1:O-1:K=>K<O-1?K+1:0);return}};return window.addEventListener("keydown",x,{capture:!0}),()=>{window.removeEventListener("keydown",x,{capture:!0})}},[t,e]);const oe=y.useCallback(x=>{x.target===x.currentTarget&&e()},[e]),H=y.useCallback(()=>{b(0)},[b]);return t?d.jsx("div",{ref:f,className:"spotlight-overlay",onClick:oe,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(Zt,{ref:h,query:E,onQueryChange:k,onKeyDown:Y,onResetSelection:H}),d.jsx(es,{ref:m,results:L,selectedIndex:v,query:E,highlightMatch:W,onSelectIndex:b}),d.jsx(ts,{})]})}):null}export{Oe as FILE_ICON_NAMES,as as Spotlight,ts as SpotlightFooter,Zt as SpotlightInput,qt as SpotlightItem,es as SpotlightResults,Xe as formatDuration,os as formatRelativeTime,cs as getAgentIcon,Gt as getFileIconFromPath,Ke as getTypeLabel,Xt as useSpotlightSearch};
1
+ import{j as d,I as Z,ak as st,U as nt,W as rt,bZ as it,r as y,s as ne,b_ as Re,_ as ct,ad as ge,u as Fe}from"./main-D9ETZv9V.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function se(t){return Array.isArray?Array.isArray(t):We(t)==="[object Array]"}function ot(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function at(t){return t==null?"":ot(t)}function ee(t){return typeof t=="string"}function ze(t){return typeof t=="number"}function ut(t){return t===!0||t===!1||lt(t)&&We(t)=="[object Boolean]"}function Qe(t){return typeof t=="object"}function lt(t){return Qe(t)&&t!==null}function Q(t){return t!=null}function pe(t){return!t.trim().length}function We(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const ht="Incorrect 'index' type",dt=t=>`Invalid value for key ${t}`,ft=t=>`Pattern length exceeds max of ${t}.`,mt=t=>`Missing ${t} property in key`,gt=t=>`Property 'weight' in key '${t}' must be a positive integer`,je=Object.prototype.hasOwnProperty;class pt{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(n=>{let r=Ve(n);this._keys.push(r),this._keyMap[r.id]=r,s+=r.weight}),this._keys.forEach(n=>{n.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Ve(t){let e=null,s=null,n=null,r=1,c=null;if(ee(t)||se(t))n=t,e=$e(t),s=Ae(t);else{if(!je.call(t,"name"))throw new Error(mt("name"));const o=t.name;if(n=o,je.call(t,"weight")&&(r=t.weight,r<=0))throw new Error(gt(o));e=$e(o),s=Ae(o),c=t.getFn}return{path:e,id:s,weight:r,src:n,getFn:c}}function $e(t){return se(t)?t:t.split(".")}function Ae(t){return se(t)?t.join("."):t}function At(t,e){let s=[],n=!1;const r=(c,o,a)=>{if(Q(c))if(!o[a])s.push(c);else{let u=o[a];const l=c[u];if(!Q(l))return;if(a===o.length-1&&(ee(l)||ze(l)||ut(l)))s.push(at(l));else if(se(l)){n=!0;for(let h=0,f=l.length;h<f;h+=1)r(l[h],o,a+1)}else o.length&&r(l,o,a+1)}};return r(t,ee(e)?e.split("."):e,0),n?s:s[0]}const yt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Et={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},xt={location:0,threshold:.6,distance:100},Ct={useExtendedSearch:!1,getFn:At,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var g={...Et,...yt,...xt,...Ct};const wt=/[^ ]+/g;function Ft(t=1,e=3){const s=new Map,n=Math.pow(10,e);return{get(r){const c=r.match(wt).length;if(s.has(c))return s.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*n)/n);return s.set(c,a),a},clear(){s.clear()}}}class Me{constructor({getFn:e=g.getFn,fieldNormWeight:s=g.fieldNormWeight}={}){this.norm=Ft(s,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((s,n)=>{this._keysMap[s.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,ee(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();ee(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,n=this.size();s<n;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!Q(e)||pe(e))return;let n={v:e,i:s,n:this.norm.get(e)};this.records.push(n)}_addObject(e,s){let n={i:s,$:{}};this.keys.forEach((r,c)=>{let o=r.getFn?r.getFn(e):this.getFn(e,r.path);if(Q(o)){if(se(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(Q(h))if(ee(h)&&!pe(h)){let f={v:h,i:l,n:this.norm.get(h)};a.push(f)}else se(h)&&h.forEach((f,m)=>{u.push({nestedArrIndex:m,value:f})})}n.$[c]=a}else if(ee(o)&&!pe(o)){let a={v:o,n:this.norm.get(o)};n.$[c]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Ye(t,e,{getFn:s=g.getFn,fieldNormWeight:n=g.fieldNormWeight}={}){const r=new Me({getFn:s,fieldNormWeight:n});return r.setKeys(t.map(Ve)),r.setSources(e),r.create(),r}function Mt(t,{getFn:e=g.getFn,fieldNormWeight:s=g.fieldNormWeight}={}){const{keys:n,records:r}=t,c=new Me({getFn:e,fieldNormWeight:s});return c.setKeys(n),c.setIndexRecords(r),c}function he(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=g.distance,ignoreLocation:c=g.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(n-s);return r?o+a/r:a?1:o}function It(t=[],e=g.minMatchCharLength){let s=[],n=-1,r=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&n===-1?n=c:!a&&n!==-1&&(r=c-1,r-n+1>=e&&s.push([n,r]),n=-1)}return t[c-1]&&c-n>=e&&s.push([n,c-1]),s}const ce=32;function St(t,e,s,{location:n=g.location,distance:r=g.distance,threshold:c=g.threshold,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,includeMatches:u=g.includeMatches,ignoreLocation:l=g.ignoreLocation}={}){if(e.length>ce)throw new Error(ft(ce));const h=e.length,f=t.length,m=Math.max(0,Math.min(n,f));let A=c,E=m;const k=a>1||u,v=k?Array(f):[];let b;for(;(b=t.indexOf(e,E))>-1;){let x=he(e,{currentLocation:b,expectedLocation:m,distance:r,ignoreLocation:l});if(A=Math.min(x,A),E=b+h,k){let C=0;for(;C<h;)v[b+C]=1,C+=1}}E=-1;let L=[],Y=1,W=h+f;const oe=1<<h-1;for(let x=0;x<h;x+=1){let C=0,B=W;for(;C<B;)he(e,{errors:x,currentLocation:m+B,expectedLocation:m,distance:r,ignoreLocation:l})<=A?C=B:W=B,B=Math.floor((W-C)/2+C);W=B;let O=Math.max(1,m-B+1),K=o?f:Math.min(m+B,f)+h,V=Array(K+2);V[K+1]=(1<<x)-1;for(let R=K;R>=O;R-=1){let te=R-1,ie=s[t.charAt(te)];if(k&&(v[te]=+!!ie),V[R]=(V[R+1]<<1|1)&ie,x&&(V[R]|=(L[R+1]|L[R])<<1|1|L[R+1]),V[R]&oe&&(Y=he(e,{errors:x,currentLocation:te,expectedLocation:m,distance:r,ignoreLocation:l}),Y<=A)){if(A=Y,E=te,E<=m)break;O=Math.max(1,2*m-E)}}if(he(e,{errors:x+1,currentLocation:m,expectedLocation:m,distance:r,ignoreLocation:l})>A)break;L=V}const H={isMatch:E>=0,score:Math.max(.001,Y)};if(k){const x=It(v,a);x.length?u&&(H.indices=x):H.isMatch=!1}return H}function Bt(t){let e={};for(let s=0,n=t.length;s<n;s+=1){const r=t.charAt(s);e[r]=(e[r]||0)|1<<n-s-1}return e}const fe=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class Ge{constructor(e,{location:s=g.location,threshold:n=g.threshold,distance:r=g.distance,includeMatches:c=g.includeMatches,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,isCaseSensitive:u=g.isCaseSensitive,ignoreDiacritics:l=g.ignoreDiacritics,ignoreLocation:h=g.ignoreLocation}={}){if(this.options={location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?fe(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const f=(A,E)=>{this.chunks.push({pattern:A,alphabet:Bt(A),startIndex:E})},m=this.pattern.length;if(m>ce){let A=0;const E=m%ce,k=m-E;for(;A<k;)f(this.pattern.substr(A,ce),A),A+=ce;if(E){const v=m-ce;f(this.pattern.substr(v),v)}}else f(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=s?e:e.toLowerCase(),e=n?fe(e):e,this.pattern===e){let k={isMatch:!0,score:0};return r&&(k.indices=[[0,e.length-1]]),k}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let f=[],m=0,A=!1;this.chunks.forEach(({pattern:k,alphabet:v,startIndex:b})=>{const{isMatch:L,score:Y,indices:W}=St(e,k,v,{location:c+b,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:h});L&&(A=!0),m+=Y,L&&W&&(f=[...f,...W])});let E={isMatch:A,score:A?m/this.chunks.length:1};return A&&r&&(E.indices=f),E}}class re{constructor(e){this.pattern=e}static isMultiMatch(e){return Le(e,this.multiRegex)}static isSingleMatch(e){return Le(e,this.singleRegex)}search(){}}function Le(t,e){const s=t.match(e);return s?s[1]:null}class Dt extends re{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class kt extends re{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class Nt extends re{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class _t extends re{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class bt extends re{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class vt extends re{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class Ue extends re{constructor(e,{location:s=g.location,threshold:n=g.threshold,distance:r=g.distance,includeMatches:c=g.includeMatches,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,isCaseSensitive:u=g.isCaseSensitive,ignoreDiacritics:l=g.ignoreDiacritics,ignoreLocation:h=g.ignoreLocation}={}){super(e),this._bitapSearch=new Ge(e,{location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class He extends re{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,n;const r=[],c=this.pattern.length;for(;(n=e.indexOf(this.pattern,s))>-1;)s=n+c,r.push([n,s-1]);const o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}const ye=[Dt,He,Nt,_t,vt,bt,kt,Ue],Te=ye.length,Rt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,jt="|";function $t(t,e={}){return t.split(jt).map(s=>{let n=s.trim().split(Rt).filter(c=>c&&!!c.trim()),r=[];for(let c=0,o=n.length;c<o;c+=1){const a=n[c];let u=!1,l=-1;for(;!u&&++l<Te;){const h=ye[l];let f=h.isMultiMatch(a);f&&(r.push(new h(f,e)),u=!0)}if(!u)for(l=-1;++l<Te;){const h=ye[l];let f=h.isSingleMatch(a);if(f){r.push(new h(f,e));break}}}return r})}const Lt=new Set([Ue.type,He.type]);class Tt{constructor(e,{isCaseSensitive:s=g.isCaseSensitive,ignoreDiacritics:n=g.ignoreDiacritics,includeMatches:r=g.includeMatches,minMatchCharLength:c=g.minMatchCharLength,ignoreLocation:o=g.ignoreLocation,findAllMatches:a=g.findAllMatches,location:u=g.location,threshold:l=g.threshold,distance:h=g.distance}={}){this.query=null,this.options={isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=s?e:e.toLowerCase(),e=n?fe(e):e,this.pattern=e,this.query=$t(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:c}=this.options;e=r?e:e.toLowerCase(),e=c?fe(e):e;let o=0,a=[],u=0;for(let l=0,h=s.length;l<h;l+=1){const f=s[l];a.length=0,o=0;for(let m=0,A=f.length;m<A;m+=1){const E=f[m],{isMatch:k,indices:v,score:b}=E.search(e);if(k){if(o+=1,u+=b,n){const L=E.constructor.type;Lt.has(L)?a=[...a,...v]:a.push(v)}}else{u=0,o=0,a.length=0;break}}if(o){let m={isMatch:!0,score:u/o};return n&&(m.indices=a),m}}return{isMatch:!1,score:1}}}const Ee=[];function Pt(...t){Ee.push(...t)}function xe(t,e){for(let s=0,n=Ee.length;s<n;s+=1){let r=Ee[s];if(r.condition(t,e))return new r(t,e)}return new Ge(t,e)}const me={AND:"$and",OR:"$or"},Ce={PATH:"$path",PATTERN:"$val"},we=t=>!!(t[me.AND]||t[me.OR]),Ot=t=>!!t[Ce.PATH],Kt=t=>!se(t)&&Qe(t)&&!we(t),Pe=t=>({[me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function Je(t,e,{auto:s=!0}={}){const n=r=>{let c=Object.keys(r);const o=Ot(r);if(!o&&c.length>1&&!we(r))return n(Pe(r));if(Kt(r)){const u=o?r[Ce.PATH]:c[0],l=o?r[Ce.PATTERN]:r[u];if(!ee(l))throw new Error(dt(u));const h={keyId:Ae(u),pattern:l};return s&&(h.searcher=xe(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=r[u];se(l)&&l.forEach(h=>{a.children.push(n(h))})}),a};return we(t)||(t=Pe(t)),n(t)}function zt(t,{ignoreFieldNorm:e=g.ignoreFieldNorm}){t.forEach(s=>{let n=1;s.matches.forEach(({key:r,norm:c,score:o})=>{const a=r?r.weight:null;n*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),s.score=n})}function Qt(t,e){const s=t.matches;e.matches=[],Q(s)&&s.forEach(n=>{if(!Q(n.indices)||!n.indices.length)return;const{indices:r,value:c}=n;let o={indices:r,value:c};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),e.matches.push(o)})}function Wt(t,e){e.score=t.score}function Vt(t,e,{includeMatches:s=g.includeMatches,includeScore:n=g.includeScore}={}){const r=[];return s&&r.push(Qt),n&&r.push(Wt),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return r.length&&r.forEach(u=>{u(c,a)}),a})}class q{constructor(e,s={},n){this.options={...g,...s},this.options.useExtendedSearch,this._keyStore=new pt(this.options.keys),this.setCollection(e,n)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Me))throw new Error(ht);this._myIndex=s||Ye(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Q(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let n=0,r=this._docs.length;n<r;n+=1){const c=this._docs[n];e(c,n)&&(this.removeAt(n),n-=1,r-=1,s.push(c))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=ee(e)?ee(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return zt(u,{ignoreFieldNorm:a}),c&&u.sort(o),ze(s)&&s>-1&&(u=u.slice(0,s)),Vt(u,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const s=xe(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:c,i:o,n:a})=>{if(!Q(c))return;const{isMatch:u,score:l,indices:h}=s.searchIn(c);u&&r.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),r}_searchLogical(e){const s=Je(e,this.options),n=(a,u,l)=>{if(!a.children){const{keyId:f,searcher:m}=a,A=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(u,f),searcher:m});return A&&A.length?[{idx:l,item:u,matches:A}]:[]}const h=[];for(let f=0,m=a.children.length;f<m;f+=1){const A=a.children[f],E=n(A,u,l);if(E.length)h.push(...E);else if(a.operator===me.AND)return[]}return h},r=this._myIndex.records,c={},o=[];return r.forEach(({$:a,i:u})=>{if(Q(a)){let l=n(s,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const s=xe(e,this.options),{keys:n,records:r}=this._myIndex,c=[];return r.forEach(({$:o,i:a})=>{if(!Q(o))return;let u=[];n.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:s}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:s,searcher:n}){if(!Q(s))return[];let r=[];if(se(s))s.forEach(({v:c,i:o,n:a})=>{if(!Q(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&r.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=s,{isMatch:a,score:u,indices:l}=n.searchIn(c);a&&r.push({score:u,key:e,value:c,norm:o,indices:l})}return r}}q.version="7.1.0";q.createIndex=Ye;q.parseIndex=Mt;q.config=g;q.parseQuery=Je;Pt(Tt);const Oe={".ts":"file-code",".tsx":"atom",".js":"file-code",".jsx":"atom",".py":"file-code",".rs":"file-code",".go":"file-code",".md":"file-text",".json":"clipboard",".yaml":"gear",".yml":"gear",".css":"palette",".scss":"palette",".html":"globe",".sql":"database",".sh":"terminal",".env":"lock",".toml":"gear",".lock":"lock",default:"file-text"};function Yt(t){switch(t){case"scout":return"class-scout";case"builder":return"class-builder";case"debugger":return"class-debugger";case"architect":return"class-architect";case"warrior":return"class-warrior";case"support":return"class-support";case"boss":return"class-boss";default:return"class-default"}}function Gt(t,e=16){var r;const s="."+(((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""),n=Oe[s]||Oe.default;return d.jsx(Z,{name:n,size:e})}function cs(t,e=16){return d.jsx(Z,{name:Yt(t),size:e,weight:"fill"})}function Xe(t){const e=Math.floor(t/1e3),s=Math.floor(e/60),n=Math.floor(s/60),r=Math.floor(n/24);return r>0?`${r}d ${n%24}h ago`:n>0?`${n}h ${s%60}m ago`:s>0?`${s}m ago`:"just now"}function os(t){const s=Date.now()-t;return Xe(s)}const Ze="tide-commander:spotlight-recent-agents",Ut=15;function qe(){try{const t=localStorage.getItem(Ze);if(!t)return[];const e=JSON.parse(t);return Array.isArray(e)?e.filter(s=>typeof s=="string"):[]}catch{return[]}}function Ht(t){try{const e=[t,...qe().filter(s=>s!==t)].slice(0,Ut);localStorage.setItem(Ze,JSON.stringify(e))}catch{}}function de(t,e){if(!t)return Number.POSITIVE_INFINITY;const s=e.indexOf(t);return s===-1?Number.POSITIVE_INFINITY:s}function Ke(t){switch(t){case"agent":return"Agent";case"command":return"Command";case"area":return"Area";case"modified-file":return"Changed";case"building":return"Server";default:return t}}const Jt=["command","agent","building","area","modified-file"];function Xt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=st(),f=nt(),m=rt(),A=it(),E=y.useRef(e);E.current=e;const k=y.useRef(s);k.current=s;const v=y.useRef(n);v.current=n;const b=y.useRef(r);b.current=r;const L=y.useRef(c);L.current=c;const Y=y.useRef(o);Y.current=o;const W=y.useRef(a);W.current=a;const oe=y.useRef(u);oe.current=u;const H=y.useRef(l);H.current=l;const[x,C]=y.useState(""),[B,O]=y.useState(0);y.useEffect(()=>{t&&(C(""),O(0))},[t]);const K=ne.getShortcuts(),V=y.useMemo(()=>t?qe():[],[t]),ae=y.useMemo(()=>{if(!t)return[];const i=K.find(I=>I.id==="spawn-agent"),M=K.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:i?Re(i):"Alt+N",icon:d.jsx(Z,{name:"plus",size:16}),action:()=>{E.current(),k.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:M?Re(M):"Ctrl+K",icon:d.jsx(Z,{name:"dashboard",size:16}),action:()=>{E.current(),v.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(Z,{name:"gear",size:16}),action:()=>{E.current(),b.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(Z,{name:"chart-line",size:16}),action:()=>{var I;E.current(),(I=H.current)==null||I.call(H)}}]},[t,K]),R=y.useMemo(()=>t?Array.from(h.values()).map(i=>{const M=(A||[]).filter(T=>T.agentId===i.id).map(T=>T.filePath),I=[...new Set(M)],S=I.map(T=>T.split("/").pop()||T),N=[];i.lastAssignedTask&&N.push(i.lastAssignedTask);const j=`${i.class} • ${i.status} • ${i.cwd}`;let _=`${i.name} ${j}`;S.length>0&&(_+=` ${S.join(" ")} ${I.join(" ")}`),N.length>0&&(_+=` ${N.join(" ")}`);const z=Date.now()-i.lastActivity;let J;return i.lastAssignedTask&&(i.lastAssignedTask.length>150?J=i.lastAssignedTask.slice(0,150)+"...":J=i.lastAssignedTask),{id:`agent-${i.id}`,type:"agent",title:i.name,subtitle:j,lastUserInput:J,timeAway:z,icon:d.jsx(ct,{agent:i,size:20}),_searchText:_,_modifiedFiles:I,_userQueries:N,_agentId:i.id,action:()=>{E.current(),Ht(i.id),ne.selectAgent(i.id),ne.getState().viewMode!=="flat"&&ne.requestTerminalExpand()}}}):[],[t,h,A]),te=y.useMemo(()=>t?Array.from(f.values()).map(i=>{var M;return{id:`area-${i.id}`,type:"area",title:i.name,subtitle:`${i.assignedAgentIds.length} agents • ${((M=i.directories)==null?void 0:M.length)||0} folders`,icon:d.jsx(Z,{name:"map",size:16}),action:()=>{E.current(),ne.selectArea(i.id)}}}):[],[t,f]),ie=y.useMemo(()=>t?Array.from(m.values()).filter(i=>i.type==="server"||i.type==="boss"||i.type==="database").map(i=>{var _,z,J,T;const M=i.status==="running"?"#4ade80":i.status==="stopped"?"#f87171":"#facc15",I=i.type==="boss"?"crown":i.type==="database"?"database":"desktop";let N=`${i.type==="boss"?"Boss":i.type==="database"?"Database":"Server"} • ${i.status}`;if(i.type==="database"&&((z=(_=i.database)==null?void 0:_.connections)!=null&&z.length)){const $=i.database.connections[0];N+=` • ${$.engine} @ ${$.host}`}else i.cwd&&(N+=` • ${i.cwd}`);let j=`${i.name} ${i.type} ${i.status} ${i.cwd||""} ${((J=i.pm2)==null?void 0:J.name)||""}`;if(i.type==="database"&&((T=i.database)!=null&&T.connections))for(const $ of i.database.connections)j+=` ${$.name} ${$.engine} ${$.host} ${$.database||""} mysql postgresql sql`;return{id:`building-${i.id}`,type:"building",title:i.name,subtitle:N,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(Z,{name:"status-pending",size:10,weight:"fill",color:M}),d.jsx(Z,{name:I,size:16})]}),_searchText:j,action:()=>{var $;E.current(),i.type==="boss"?W.current(i.id):i.type==="database"?oe.current(i.id):($=i.pm2)!=null&&$.enabled&&Y.current(i.id)}}}):[],[t,m]),Ie=y.useMemo(()=>{if(!t)return[];const i=A||[],M=new Set,I=[];for(const S of i){if(M.has(S.filePath))continue;M.add(S.filePath);const N=S.filePath.split("/").pop()||S.filePath,j=S.action==="created"?"Created":S.action==="modified"?"Modified":S.action==="deleted"?"Deleted":"Read";if(I.push({id:`modified-${S.filePath}-${S.timestamp}`,type:"modified-file",title:N,subtitle:`${j} by ${S.agentName} • ${S.filePath}`,matchedText:S.filePath,icon:S.action==="deleted"?d.jsx(Z,{name:"trash",size:16}):Gt(S.filePath),action:()=>{E.current();const _=Array.from(ne.getState().areas.values());for(const z of _)for(const J of z.directories||[])if(S.filePath.startsWith(J)){ne.setFileViewerPath(S.filePath),L.current(z.id);return}ne.selectAgent(S.agentId)}}),I.length>=50)break}return I},[t,A]),Se=y.useMemo(()=>new q(R,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[R]),Be=y.useMemo(()=>new q(ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[ae]),De=y.useMemo(()=>new q(te,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[te]),ke=y.useMemo(()=>new q(Ie,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ie]),Ne=y.useMemo(()=>new q(ie,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ie]),G=y.useMemo(()=>{if(!x.trim()){const p=[];p.push(...ie);const w=[...R].sort((D,P)=>{const X=de(D._agentId,V),U=de(P._agentId,V);if(X!==U)return X-U;const ue=D.timeAway??0,le=P.timeAway??0;return ue-le});p.push(...w),p.push(...ae.slice(0,2)),p.push(...te.slice(0,2));const F={};return Jt.forEach((D,P)=>{F[D]=P}),p.sort((D,P)=>(F[D.type]??999)-(F[P.type]??999)),p}const i=x.trim().toLowerCase(),M=Se.search(x).slice(0,8),I=Be.search(x).slice(0,3),S=De.search(x).slice(0,2),N=ke.search(x).slice(0,3),j=Ne.search(x).filter(p=>{const w=p.score??1;return`${p.item.title} ${p.item.subtitle||""} ${p.item._searchText||""}`.toLowerCase().includes(i)||w<=.2}).slice(0,4),_={agent:5,building:4,command:3,area:2,"modified-file":1},z=p=>{if(!i)return 1;const w=p.title.toLowerCase();return w===i?6:w.startsWith(i)?5:w.split(/[^a-z0-9]+/i).includes(i)?4:w.includes(i)?3:`${p.subtitle||""} ${p._searchText||""} ${p.matchedText||""}`.toLowerCase().includes(i)?2:1},J=(p,w)=>{const F=(1-Math.min(1,w??1))*4;return z(p)*100+(_[p.type]??0)*5+F},T=new Map,$=(p,w)=>{const F=T.get(p.type),D={item:p,score:J(p,w)};F?F.push(D):T.set(p.type,[D])};for(const p of M){const w={...p.item};if(w._modifiedFiles&&w._modifiedFiles.length>0){const F=w._modifiedFiles.filter(D=>{var U;const P=((U=D.split("/").pop())==null?void 0:U.toLowerCase())||"",X=D.toLowerCase();return P.includes(i)||X.includes(i)});F.length>0&&(w.matchedFiles=F)}if(w._userQueries&&w._userQueries.length>0){const F=w._userQueries.find(D=>D.toLowerCase().includes(i));if(F)if(F.length>200){const P=F.toLowerCase().indexOf(i),X=Math.max(0,P-60),U=Math.min(F.length,P+i.length+100);w.matchedQuery=(X>0?"...":"")+F.slice(X,U)+(U<F.length?"...":"")}else w.matchedQuery=F}$(w,p.score)}for(const p of j)$(p.item,p.score);for(const p of I)$(p.item,p.score);for(const p of S)$(p.item,p.score);for(const p of N)$(p.item,p.score);for(const[p,w]of T)p==="agent"?w.sort((F,D)=>{const P=z(F.item),X=z(D.item);if(X!==P)return X-P;const U=de(F.item._agentId,V),ue=de(D.item._agentId,V);if(U!==ue)return U-ue;const le=F.item.timeAway??Number.POSITIVE_INFINITY,ve=D.item.timeAway??Number.POSITIVE_INFINITY;return le!==ve?le-ve:D.score-F.score}):w.sort((F,D)=>D.score-F.score);const _e=p=>p.reduce((w,F)=>Math.max(w,F.score),-1),be=[];return Array.from(T.values()).sort((p,w)=>_e(w)-_e(p)).forEach(p=>{for(const w of p)be.push(w.item)}),be},[x,Se,Be,De,ke,Ne,ae,R,te,ie,V]);y.useEffect(()=>{B>=G.length&&O(Math.max(0,G.length-1))},[G.length,B]);const et=y.useCallback(i=>{if(i.altKey&&!i.ctrlKey&&!i.metaKey&&(i.key==="p"||i.key==="n"||i.key==="P"||i.key==="N")){i.preventDefault(),i.stopPropagation(),i.nativeEvent.stopImmediatePropagation();const M=i.key.toLowerCase();O(M==="p"?I=>I>0?I-1:G.length-1:I=>I<G.length-1?I+1:0);return}switch(i.key){case"Escape":i.preventDefault(),E.current();break;case"ArrowUp":i.preventDefault(),O(M=>M>0?M-1:G.length-1);break;case"ArrowDown":i.preventDefault(),O(M=>M<G.length-1?M+1:0);break;case"Enter":i.preventDefault(),G[B]&&G[B].action();break}},[G,B]),tt=y.useCallback((i,M)=>{if(!M||!i)return i;const I=i.toLowerCase(),S=M.toLowerCase(),N=[];let j=0,_=I.indexOf(S),z=0;for(;_!==-1;)_>j&&N.push(i.slice(j,_)),N.push(ge.createElement("mark",{key:z++,className:"spotlight-highlight"},i.slice(_,_+M.length))),j=_+M.length,_=I.indexOf(S,j);return j<i.length&&N.push(i.slice(j)),N.length>0?ge.createElement(ge.Fragment,null,...N):i},[]);return{query:x,setQuery:C,selectedIndex:B,setSelectedIndex:O,results:G,handleKeyDown:et,highlightMatch:tt}}const Zt=y.forwardRef(function({query:e,onQueryChange:s,onKeyDown:n,onResetSelection:r},c){const{t:o}=Fe(["common"]);return d.jsxs("div",{className:"spotlight-input-wrapper",children:[d.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),d.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{s(a.target.value),r()},onKeyDown:n,autoFocus:!0,spellCheck:!1}),d.jsxs("div",{className:"spotlight-input-hints",children:[d.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),qt=y.memo(function({result:e,isSelected:s,query:n,highlightMatch:r,onClick:c,onMouseEnter:o}){const a=e.activityText||e.matchedFiles&&e.matchedFiles.length>0||e.matchedQuery;return d.jsxs("div",{className:`spotlight-item ${s?"selected":""} ${e.activityText?"has-activity":""}`,onClick:c,onMouseEnter:o,role:"option","aria-selected":s,children:[d.jsx("span",{className:"spotlight-item-icon","aria-hidden":"true",children:e.icon}),d.jsxs("div",{className:"spotlight-item-content",children:[d.jsxs("div",{className:"spotlight-item-header",children:[d.jsx("span",{className:"spotlight-item-title",children:r(e.title,n)}),d.jsx("span",{className:`spotlight-item-type ${e.type}`,"aria-label":Ke(e.type),children:Ke(e.type)})]}),e.subtitle&&d.jsx("span",{className:"spotlight-item-subtitle",children:r(e.subtitle,n)}),e.activityText&&d.jsx("span",{className:"spotlight-item-activity",children:r(e.activityText,n)}),a&&d.jsxs("div",{className:"spotlight-item-details",children:[e.matchedFiles&&e.matchedFiles.length>0&&d.jsx("span",{className:"spotlight-item-files",children:e.matchedFiles.map((u,l)=>d.jsxs("span",{className:"file-badge",children:[l>0&&d.jsx("span",{className:"file-separator",children:"•"}),r(u.split("/").pop()||u,n)]},u))}),e.matchedQuery&&d.jsx("span",{className:"spotlight-item-query",children:r(e.matchedQuery,n)})]}),e.timeAway!==void 0&&d.jsx("span",{className:"spotlight-item-time",children:d.jsxs("span",{className:"spotlight-time-away",children:["Idle: ",Xe(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&d.jsxs("span",{className:"spotlight-item-last-input",children:['"',r(e.lastUserInput,n),'"']})]})]})}),es=y.forwardRef(function({results:e,selectedIndex:s,query:n,highlightMatch:r,onSelectIndex:c},o){const{t:a}=Fe(["terminal"]),u=y.useRef(!1);y.useEffect(()=>{u.current=!1},[e]),y.useEffect(()=>{const f=typeof o=="function"?null:o==null?void 0:o.current;if(!f)return;const m=()=>{u.current=!0};return f.addEventListener("mousemove",m),()=>{f.removeEventListener("mousemove",m)}},[o,e]);const l={command:a("terminal:spotlight.categories.commands"),agent:a("terminal:spotlight.categories.agents"),building:a("terminal:spotlight.categories.infrastructure"),area:a("terminal:spotlight.categories.areas"),"modified-file":a("terminal:spotlight.categories.modifiedFiles")},h=y.useMemo(()=>{const f=[];let m=null,A=[];return e.forEach((E,k)=>{E.type!==m&&(m!==null&&A.length>0&&f.push([m,A]),m=E.type,A=[]),A.push({result:E,index:k})}),m!==null&&A.length>0&&f.push([m,A]),f},[e]);return y.useEffect(()=>{if(!o||typeof o=="function")return;const f=o.current;if(!f)return;const m=f.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[s,o]),e.length===0?d.jsx("div",{className:"spotlight-results",ref:o,children:d.jsx("div",{className:"spotlight-empty",children:a("terminal:spotlight.noResults")})}):d.jsx("div",{className:"spotlight-results",ref:o,children:h.map(([f,m])=>d.jsxs("div",{children:[h.length>1&&d.jsx("div",{className:"spotlight-category-header",children:l[f]||f}),m.map(({result:A,index:E})=>d.jsx(qt,{result:A,isSelected:E===s,query:n,highlightMatch:r,onClick:()=>A.action(),onMouseEnter:()=>{u.current&&c(E)}},A.id))]},f))})}),ts=y.memo(function(){const{t:e}=Fe(["terminal"]);return d.jsxs("div",{className:"spotlight-footer",children:[d.jsxs("div",{className:"spotlight-footer-left",children:[d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"↑"}),d.jsx("kbd",{children:"↓"})," ",d.jsx("kbd",{children:"Alt+N"}),d.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]})]}),d.jsx("div",{className:"spotlight-footer-right",children:d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),ss=768;function as({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=y.useRef(null),f=y.useRef(null),m=y.useRef(null),A=y.useRef(0),{query:E,setQuery:k,selectedIndex:v,setSelectedIndex:b,results:L,handleKeyDown:Y,highlightMatch:W}=Xt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});A.current=L.length,y.useEffect(()=>{t&&setTimeout(()=>{var x;(x=h.current)==null||x.focus()},50)},[t]),y.useEffect(()=>{if(!t)return;const x=window.visualViewport;if(!x||window.innerWidth>ss)return;const C=()=>{const B=f.current;B&&(B.style.height=`${x.height}px`,B.style.top=`${x.offsetTop}px`)};return C(),x.addEventListener("resize",C),x.addEventListener("scroll",C),()=>{x.removeEventListener("resize",C),x.removeEventListener("scroll",C);const B=f.current;B&&(B.style.height="",B.style.top="")}},[t]),y.useEffect(()=>{if(!t)return;const x=C=>{if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),e();return}if(C.altKey&&!C.ctrlKey&&!C.metaKey&&(C.key==="n"||C.key==="p"||C.key==="N"||C.key==="P")){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation();const B=C.key.toLowerCase(),O=A.current;b(B==="p"?K=>K>0?K-1:O-1:K=>K<O-1?K+1:0);return}};return window.addEventListener("keydown",x,{capture:!0}),()=>{window.removeEventListener("keydown",x,{capture:!0})}},[t,e]);const oe=y.useCallback(x=>{x.target===x.currentTarget&&e()},[e]),H=y.useCallback(()=>{b(0)},[b]);return t?d.jsx("div",{ref:f,className:"spotlight-overlay",onClick:oe,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(Zt,{ref:h,query:E,onQueryChange:k,onKeyDown:Y,onResetSelection:H}),d.jsx(es,{ref:m,results:L,selectedIndex:v,query:E,highlightMatch:W,onSelectIndex:b}),d.jsx(ts,{})]})}):null}export{Oe as FILE_ICON_NAMES,as as Spotlight,ts as SpotlightFooter,Zt as SpotlightInput,qt as SpotlightItem,es as SpotlightResults,Xe as formatDuration,os as formatRelativeTime,cs as getAgentIcon,Gt as getFileIconFromPath,Ke as getTypeLabel,Xt as useSpotlightSearch};