tide-commander 1.133.2 → 1.134.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{BossLogsModal-DwuIK9m6.js → BossLogsModal-3bGm1kXY.js} +1 -1
- package/dist/assets/{BossSpawnModal-Dj3RAYvK.js → BossSpawnModal-C8hvV7_4.js} +1 -1
- package/dist/assets/{ControlsModal-2RYmmfrr.js → ControlsModal-DWISYGgp.js} +1 -1
- package/dist/assets/{DockerLogsModal-CtK69VXz.js → DockerLogsModal-80VlQu9M.js} +1 -1
- package/dist/assets/{EmbeddedEditor-D4dyGPWp.js → EmbeddedEditor--X_L8Y9G.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-D4WIJQPh.js → GmailOAuthSetup-fcTiMp7j.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-CeOoPjBn.js → GoogleOAuthSetup-X-CdXRR_.js} +1 -1
- package/dist/assets/{IframeModal-Czpk8nNY.js → IframeModal-DrWydU4Y.js} +1 -1
- package/dist/assets/{IntegrationsPanel-BTWvtUqh.js → IntegrationsPanel-pg7KDtlu.js} +2 -2
- package/dist/assets/{LogViewerModal-BoFD-vk1.js → LogViewerModal-DjUtP8e8.js} +1 -1
- package/dist/assets/{MonitoringModal-ChR0ELIz.js → MonitoringModal-BGCbxkry.js} +1 -1
- package/dist/assets/{PM2LogsModal-CoCnLncV.js → PM2LogsModal-Dvt1smtl.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-DPTPKLHh.js → RestoreArchivedAreaModal-rYwebAjM.js} +1 -1
- package/dist/assets/{Scene2DCanvas-BH-47TIq.js → Scene2DCanvas-BKVdpglJ.js} +1 -1
- package/dist/assets/{SceneManager-IluWBEFk.js → SceneManager-CZiOgb-i.js} +1 -1
- package/dist/assets/{SkillsPanel-XcUykivP.js → SkillsPanel-D8aOQ8Oh.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-DeLiUle3.js → SlackMultiInstanceSetup-Cl3iDhEl.js} +1 -1
- package/dist/assets/{SpawnModal-BZfIZTdq.js → SpawnModal-DyYlni47.js} +1 -1
- package/dist/assets/{StatisticsModal-C0Ets4vl.js → StatisticsModal-OT9iixr7.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-BMT6EK_E.js → SubordinateAssignmentModal-Dhs-7Ng7.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-Bnwo6pTt.js → TriggerManagerPanel-BJdipZjh.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-D0G14Ebq.js → WorkflowEditorPanel-B6IdT7xg.js} +1 -1
- package/dist/assets/{area-logos-C5XZBFfj.js → area-logos-Nrw3H05l.js} +1 -1
- package/dist/assets/{index-D-ETqZcB.js → index-BxIh8DUH.js} +2 -2
- package/dist/assets/{index-D5ufwk7t.js → index-Caqnrau0.js} +1 -1
- package/dist/assets/{index-BV42oiJT.js → index-Ccl3Wq4E.js} +1 -1
- package/dist/assets/{index-bY0k_5jo.js → index-Cik009FU.js} +1 -1
- package/dist/assets/{index-D_shYCrx.js → index-D0HrQcCe.js} +1 -1
- package/dist/assets/{index-B3k628ul.js → index-DSc2bBsi.js} +1 -1
- package/dist/assets/{index-AlXP8uuc.js → index-Dfsw9BYI.js} +3 -3
- package/dist/assets/{index-GtO7k8QG.js → index-Fi1hX3PU.js} +1 -1
- package/dist/assets/{index-Bd5JKG69.js → index-nloclgk3.js} +1 -1
- package/dist/assets/{main-DZgTocNE.js → main-BDtz2sl7.js} +99 -99
- package/dist/assets/{web-zQ3wpRl0.js → web-BJadsgmu.js} +1 -1
- package/dist/assets/{web-CwRGXDj6.js → web-DHjr-W87.js} +1 -1
- package/dist/assets/{web-i9NDpV0L.js → web-Dee5J9g6.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor
|
|
2
|
-
import{r as t,h as W,i as V,G as Yt,Z as Bs,S as Ht,_ as _s,s as Be,u as re,j as e,I as M,bJ as zt,f as Vs,bK as Ks,bL as Gn,bM as Ws,bN as qs,bO as Un,bP as Bn,bQ as Pt,bR as _n,bS as Vn,bT as Kn,bU as es,bV as Wn,bW as Ys,bX as Lt,bY as $t,ak as ct,bZ as xt,b_ as yt,b$ as Is,c0 as qn,be as Yn,c1 as Zt,c2 as Ft,c3 as Jn,c4 as Xn,c5 as Qn,c6 as Zn,c7 as ea,c8 as Ps,C as ta,o as sa}from"./main-DZgTocNE.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function na(s){const[n,l]=t.useState(null),[d,r]=t.useState(!1),i=t.useCallback(async()=>{if(s){r(!0);try{const m=await W(V(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await m.json();m.ok?l(o):l({isGitRepo:!1,files:[]})}catch(m){console.error("[FileExplorer] Failed to load git status:",m),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[s]);return{gitStatus:n,loading:d,loadGitStatus:i}}async function aa(s){try{const n=await W(V(`/api/files/git-original?path=${encodeURIComponent(s)}`)),l=await n.json();return n.ok&&!l.isNew?{content:l.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const ra=new Set([".txt",".md",".markdown",".json",".yaml",".yml",".xml",".html",".htm",".css",".scss",".sass",".less",".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".rb",".c",".cpp",".h",".hpp",".cs",".go",".rs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".hs",".ml",".fs",".sql",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".toml",".ini",".cfg",".conf",".env",".gitignore",".dockerignore",".editorconfig",".prettierrc",".eslintrc",".babelrc",".log",".csv",".tsv",".svg",""]),ia=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),la=new Set([".pdf"]),oa=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".zip",".tar",".gz",".rar",".7z",".exe",".dmg",".app",".deb",".rpm",".apk",".aab",".ipa",".msi",".mp3",".mp4",".wav",".avi",".mov",".mkv",".flac",".ogg",".webm",".ttf",".otf",".woff",".woff2",".eot",".sqlite",".db",".so",".dll",".dylib",".a",".o",".obj",".bin",".dat",".iso",".img",".jar",".war",".ear",".class"]);function ca(s){const n=s.toLowerCase();return ia.has(n)?"image":la.has(n)?"pdf":oa.has(n)?"binary":(ra.has(n),"text")}function da(){const[s,n]=t.useState(null),[l,d]=t.useState(!1),[r,i]=t.useState(null),m=t.useCallback(async h=>{var p,j;d(!0),i(null);try{const f=h.substring(h.lastIndexOf(".")).toLowerCase(),b=ca(f),w=h.substring(h.lastIndexOf("/")+1);if(b==="image"){const k=await W(V(`/api/files/binary?path=${encodeURIComponent(h)}`));if(!k.ok){const C=await k.json().catch(()=>({error:"Failed to load image"}));i(C.error||"Failed to load image"),n(null);return}const x=await k.blob(),v=URL.createObjectURL(x);n({path:h,filename:w,extension:f,content:"",size:x.size,modified:new Date().toISOString(),fileType:"image",dataUrl:v});return}if(b==="pdf"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(!k.ok){i(x.error||"Failed to load PDF info"),n(null);return}n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"pdf",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&token=${encodeURIComponent(Yt())}`)});return}if(b==="binary"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(!k.ok){i(x.error||"Failed to load file info"),n(null);return}n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&download=true&token=${encodeURIComponent(Yt())}`)});return}const R=await W(V(`/api/files/read?path=${encodeURIComponent(h)}`)),g=await R.json();if(!R.ok){if((p=g.error)!=null&&p.includes("too large")||(j=g.error)!=null&&j.includes("binary")){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(k.ok){n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&download=true&token=${encodeURIComponent(Yt())}`)});return}}i(g.error||"Failed to load file"),n(null);return}n({...g,fileType:"text"})}catch(f){const b=f instanceof Error?f.message:"Failed to load file";i(b),n(null)}finally{d(!1)}},[]),o=t.useCallback(()=>{n(h=>(h!=null&&h.dataUrl&&h.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(h.dataUrl),null)),i(null)},[]);return{file:s,loading:l,error:r,loadFile:m,clearFile:o,setFile:n}}const Jt="file-explorer-state",ua=10080*60*1e3;function ha(s,n){return n?`${Jt}-folder-${n}`:s?`${Jt}-area-${s}`:`${Jt}-default`}async function ma(s){try{const n=await W(V(`/api/files/exists?path=${encodeURIComponent(s)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function fa({areaId:s,folderPath:n,isOpen:l}){const d=ha(s,n),r=t.useRef(!1);t.useEffect(()=>{r.current=!1},[s,n]);const i=t.useCallback(async()=>{if(r.current)return null;r.current=!0;try{const o=localStorage.getItem(d);if(!o)return null;const h=JSON.parse(o);if(Date.now()-h.timestamp>ua)return localStorage.removeItem(d),null;const j=(await Promise.all(h.tabs.map(async b=>({tab:b,exists:await ma(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let f=h.activeTabPath;return f&&!j.some(b=>b.path===f)&&(f=j.length>0?j[0].path:null),{tabs:j,activeTabPath:f,viewMode:h.viewMode||"files",selectedFolderIndex:h.selectedFolderIndex||0,expandedPaths:new Set(h.expandedPaths||[])}}catch(o){return console.error("[FileExplorerStorage] Failed to load state:",o),null}},[d]),m=t.useCallback(o=>{if(l)try{const h={tabs:o.tabs,activeTabPath:o.activeTabPath,viewMode:o.viewMode,selectedFolderIndex:o.selectedFolderIndex,expandedPaths:Array.from(o.expandedPaths),timestamp:Date.now()};localStorage.setItem(d,JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save state:",h)}},[d,l]);return{loadStoredState:i,saveState:m}}const Ls=280,$s=150,Hs=1200;function pa(){const[s,n]=t.useState(()=>{const p=Bs(Ht.TREE_PANEL_WIDTH,Ls);return p>=$s&&p<=Hs?p:Ls}),l=t.useRef(!1),[d,r]=t.useState(!1),i=t.useRef(0),m=t.useRef(0),o=t.useRef(s);o.current=s;const h=t.useCallback(p=>{p.preventDefault(),l.current=!0,r(!0),i.current=p.clientX,m.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const p=f=>{if(!l.current)return;const b=f.clientX-i.current,w=Math.min(Hs,Math.max($s,m.current+b));n(w)},j=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",_s(Ht.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",p),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",j)}},[]),{treePanelWidth:s,handleResizeStart:h,isResizing:d}}const ga=100,xa=.65,ya=36;function ba(){const[s,n]=t.useState(()=>Bs(Ht.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const d=t.useRef(0),r=t.useRef(0),i=()=>Math.floor((window.innerHeight-ya)*xa),m=f=>Math.min(i(),Math.max(ga,f)),o=t.useCallback(f=>{n(f);const b=document.querySelector(".file-explorer-main");b&&b.style.setProperty("--fe-mobile-tree-height",`${f}px`)},[]),h=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",_s(Ht.MOBILE_TREE_PANEL_HEIGHT,l.current),Be.setTerminalResizing(!1)},[]),p=t.useCallback(f=>{f.preventDefault();const b=document.querySelector(".file-explorer-tree-panel"),w=l.current>0?l.current:(b==null?void 0:b.getBoundingClientRect().height)??240;d.current=f.clientY,r.current=w,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Be.setTerminalResizing(!0);const R=k=>{const x=k.clientY-d.current;o(m(r.current+x))},g=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",g),h()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",g)},[o,h]),j=t.useCallback(f=>{if(f.touches.length!==1)return;const b=document.querySelector(".file-explorer-tree-panel"),w=l.current>0?l.current:(b==null?void 0:b.getBoundingClientRect().height)??240;d.current=f.touches[0].clientY,r.current=w,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Be.setTerminalResizing(!0);const R=k=>{if(k.touches.length!==1)return;k.preventDefault();const x=k.touches[0].clientY-d.current;o(m(r.current+x))},g=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",g),document.removeEventListener("touchcancel",g),h()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",g),document.addEventListener("touchcancel",g)},[o,h]);return{mobileTreeHeight:s,handleResizeMouseDown:p,handleResizeTouchStart:j}}function ts(){const[s,n]=t.useState([]),[l,d]=t.useState(!1),[r,i]=t.useState(null),[m,o]=t.useState(null),h=t.useCallback(async k=>{d(!0),i(null);try{const x=await W(V(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),v=await x.json();x.ok?n(v.branches||[]):(i(v.error||"Failed to load branches"),n([]))}catch(x){console.error("[GitBranches] Failed to load branches:",x),i("Failed to load branches"),n([])}finally{d(!1)}},[]),p=t.useCallback(async(k,x)=>{o("checkout"),i(null);try{const v=await W(V("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:x})}),C=await v.json();return v.ok||i(C.error||"Checkout failed"),C}catch(v){console.error("[GitBranches] Checkout failed:",v);const C={success:!1,error:"Checkout failed"};return i(C.error),C}finally{o(null)}},[]),j=t.useCallback(async(k,x,v)=>{o("create"),i(null);try{const C=await W(V("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:x,startPoint:v})}),D=await C.json();return C.ok||i(D.error||"Failed to create branch"),D}catch(C){console.error("[GitBranches] Create branch failed:",C);const D={success:!1,error:"Failed to create branch"};return i(D.error),D}finally{o(null)}},[]),f=t.useCallback(async k=>{o("pull"),i(null);try{const x=await W(V("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return!x.ok&&!v.conflicts&&i(v.error||"Pull failed"),v}catch(x){console.error("[GitBranches] Pull failed:",x);const v={success:!1,error:"Pull failed"};return i(v.error),v}finally{o(null)}},[]),b=t.useCallback(async k=>{o("push"),i(null);try{const x=await W(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Push failed"),v}catch(x){console.error("[GitBranches] Push failed:",x);const v={success:!1,error:"Push failed"};return i(v.error),v}finally{o(null)}},[]),w=t.useCallback(async(k,x)=>{o("merge"),i(null);try{const v=await W(V("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:x})}),C=await v.json();return!v.ok&&!C.conflicts&&i(C.error||"Merge failed"),C}catch(v){console.error("[GitBranches] Merge failed:",v);const C={success:!1,error:"Merge failed"};return i(C.error),C}finally{o(null)}},[]),R=t.useCallback(async k=>{o("merge-abort"),i(null);try{const x=await W(V("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Merge abort failed"),v}catch(x){console.error("[GitBranches] Merge abort failed:",x);const v={success:!1,error:"Merge abort failed"};return i(v.error),v}finally{o(null)}},[]),g=t.useCallback(async k=>{o("merge-continue"),i(null);try{const x=await W(V("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Merge continue failed"),v}catch(x){console.error("[GitBranches] Merge continue failed:",x);const v={success:!1,error:"Merge continue failed"};return i(v.error),v}finally{o(null)}},[]);return{branches:s,loading:l,error:r,operationInProgress:m,loadBranches:h,checkoutBranch:p,createBranch:j,pullFromRemote:f,pushToRemote:b,mergeBranch:w,mergeAbort:R,mergeContinue:g}}const ja=50,va=400,zs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function wa(){const[s,n]=t.useState([]),[l,d]=t.useState(!1),[r,i]=t.useState(!1),[m,o]=t.useState(null),[h,p]=t.useState(!1),[j,f]=t.useState(0),[b,w]=t.useState({...zs}),[R,g]=t.useState(null),[k,x]=t.useState([]),[v,C]=t.useState(!1),[D,N]=t.useState([]),[U,_]=t.useState(!1),O=t.useRef(null),se=t.useRef(""),Q=t.useCallback((z,I,$)=>{const P=$||b,ee=new URLSearchParams;return ee.set("path",z),ee.set("limit",String(ja)),ee.set("offset",String(I)),P.branch&&ee.set("branch",P.branch),P.author&&ee.set("author",P.author),P.since&&ee.set("since",P.since),P.until&&ee.set("until",P.until),P.searchPath&&ee.set("searchPath",P.searchPath),P.search&&ee.set("search",P.search),ee.toString()},[b]),T=t.useCallback(async z=>{se.current=z,d(!0),o(null),g(null),x([]);try{const I=Q(z,0),$=await W(V(`/api/files/git-log?${I}`)),P=await $.json();$.ok?(n(P.commits||[]),f(P.total||0),p(P.hasMore||!1)):(o(P.error||"Failed to load git history"),n([]))}catch(I){console.error("[useGitHistory] loadHistory error:",I),o("Failed to load git history"),n([])}finally{d(!1)}},[Q]),F=t.useCallback(async z=>{if(!(r||!h)){i(!0);try{const I=Q(z,s.length),$=await W(V(`/api/files/git-log?${I}`)),P=await $.json();$.ok&&(n(ee=>[...ee,...P.commits||[]]),f(P.total||0),p(P.hasMore||!1))}catch(I){console.error("[useGitHistory] loadMore error:",I)}finally{i(!1)}}},[Q,s.length,h,r]),K=t.useCallback(async z=>{if(g(z),!z){x([]);return}C(!0);try{const I=se.current,$=new URLSearchParams({path:I,hash:z.hash}),P=await W(V(`/api/files/git-commit-files?${$}`)),ee=await P.json();P.ok?x(ee.files||[]):x([])}catch(I){console.error("[useGitHistory] selectCommit files error:",I),x([])}finally{C(!1)}},[]),ne=t.useCallback((z,I)=>{w($=>({...$,[z]:I}))},[]),ie=t.useCallback(()=>{w({...zs})},[]);t.useEffect(()=>{const z=se.current;if(z)return O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{T(z)},va),()=>{O.current&&clearTimeout(O.current)}},[b]);const fe=t.useCallback(async z=>{_(!0);try{const I=new URLSearchParams({path:z}),$=await W(V(`/api/files/git-authors?${I}`)),P=await $.json();$.ok&&N(P.authors||[])}catch(I){console.error("[useGitHistory] loadAuthors error:",I)}finally{_(!1)}},[]);return{commits:s,loading:l,loadingMore:r,error:m,hasMore:h,total:j,filters:b,setFilter:ne,resetFilters:ie,selectedCommit:R,selectCommit:K,commitFiles:k,commitFilesLoading:v,loadHistory:T,loadMore:F,authors:D,authorsLoading:U,loadAuthors:fe}}function Ca(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const d=s.current.querySelector(l);if(d&&Os(d))return d}return Os(s.current)?s.current:null}function Os(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function Js(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function Xt(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Na(s){const{scrollTop:n,scrollHeight:l,clientHeight:d}=s;return l<=d?100:Math.round(n/(l-d)*100)}function ka(s,n){const l=Js(s),d=s.scrollTop,r=Math.floor(d/l)+1,i=n.split(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor--X_L8Y9G.js","assets/main-BDtz2sl7.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-rrlO1Py8.css","assets/EmbeddedEditor-O_u2UVA4.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as t,h as W,i as V,G as Yt,Z as Bs,S as Ht,_ as _s,s as Be,u as re,j as e,I as M,bJ as zt,f as Vs,bK as Ks,bL as Gn,bM as Ws,bN as qs,bO as Un,bP as Bn,bQ as Pt,bR as _n,bS as Vn,bT as Kn,bU as es,bV as Wn,bW as Ys,bX as Lt,bY as $t,ak as ct,bZ as xt,b_ as yt,b$ as Is,c0 as qn,be as Yn,c1 as Zt,c2 as Ft,c3 as Jn,c4 as Xn,c5 as Qn,c6 as Zn,c7 as ea,c8 as Ps,C as ta,o as sa}from"./main-BDtz2sl7.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function na(s){const[n,l]=t.useState(null),[d,r]=t.useState(!1),i=t.useCallback(async()=>{if(s){r(!0);try{const m=await W(V(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await m.json();m.ok?l(o):l({isGitRepo:!1,files:[]})}catch(m){console.error("[FileExplorer] Failed to load git status:",m),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[s]);return{gitStatus:n,loading:d,loadGitStatus:i}}async function aa(s){try{const n=await W(V(`/api/files/git-original?path=${encodeURIComponent(s)}`)),l=await n.json();return n.ok&&!l.isNew?{content:l.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const ra=new Set([".txt",".md",".markdown",".json",".yaml",".yml",".xml",".html",".htm",".css",".scss",".sass",".less",".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".rb",".c",".cpp",".h",".hpp",".cs",".go",".rs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".hs",".ml",".fs",".sql",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".toml",".ini",".cfg",".conf",".env",".gitignore",".dockerignore",".editorconfig",".prettierrc",".eslintrc",".babelrc",".log",".csv",".tsv",".svg",""]),ia=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),la=new Set([".pdf"]),oa=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".zip",".tar",".gz",".rar",".7z",".exe",".dmg",".app",".deb",".rpm",".apk",".aab",".ipa",".msi",".mp3",".mp4",".wav",".avi",".mov",".mkv",".flac",".ogg",".webm",".ttf",".otf",".woff",".woff2",".eot",".sqlite",".db",".so",".dll",".dylib",".a",".o",".obj",".bin",".dat",".iso",".img",".jar",".war",".ear",".class"]);function ca(s){const n=s.toLowerCase();return ia.has(n)?"image":la.has(n)?"pdf":oa.has(n)?"binary":(ra.has(n),"text")}function da(){const[s,n]=t.useState(null),[l,d]=t.useState(!1),[r,i]=t.useState(null),m=t.useCallback(async h=>{var p,j;d(!0),i(null);try{const f=h.substring(h.lastIndexOf(".")).toLowerCase(),b=ca(f),w=h.substring(h.lastIndexOf("/")+1);if(b==="image"){const k=await W(V(`/api/files/binary?path=${encodeURIComponent(h)}`));if(!k.ok){const C=await k.json().catch(()=>({error:"Failed to load image"}));i(C.error||"Failed to load image"),n(null);return}const x=await k.blob(),v=URL.createObjectURL(x);n({path:h,filename:w,extension:f,content:"",size:x.size,modified:new Date().toISOString(),fileType:"image",dataUrl:v});return}if(b==="pdf"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(!k.ok){i(x.error||"Failed to load PDF info"),n(null);return}n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"pdf",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&token=${encodeURIComponent(Yt())}`)});return}if(b==="binary"){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(!k.ok){i(x.error||"Failed to load file info"),n(null);return}n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&download=true&token=${encodeURIComponent(Yt())}`)});return}const R=await W(V(`/api/files/read?path=${encodeURIComponent(h)}`)),g=await R.json();if(!R.ok){if((p=g.error)!=null&&p.includes("too large")||(j=g.error)!=null&&j.includes("binary")){const k=await W(V(`/api/files/info?path=${encodeURIComponent(h)}`)),x=await k.json();if(k.ok){n({path:h,filename:w,extension:f,content:"",size:x.size,modified:x.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(h)}&download=true&token=${encodeURIComponent(Yt())}`)});return}}i(g.error||"Failed to load file"),n(null);return}n({...g,fileType:"text"})}catch(f){const b=f instanceof Error?f.message:"Failed to load file";i(b),n(null)}finally{d(!1)}},[]),o=t.useCallback(()=>{n(h=>(h!=null&&h.dataUrl&&h.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(h.dataUrl),null)),i(null)},[]);return{file:s,loading:l,error:r,loadFile:m,clearFile:o,setFile:n}}const Jt="file-explorer-state",ua=10080*60*1e3;function ha(s,n){return n?`${Jt}-folder-${n}`:s?`${Jt}-area-${s}`:`${Jt}-default`}async function ma(s){try{const n=await W(V(`/api/files/exists?path=${encodeURIComponent(s)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function fa({areaId:s,folderPath:n,isOpen:l}){const d=ha(s,n),r=t.useRef(!1);t.useEffect(()=>{r.current=!1},[s,n]);const i=t.useCallback(async()=>{if(r.current)return null;r.current=!0;try{const o=localStorage.getItem(d);if(!o)return null;const h=JSON.parse(o);if(Date.now()-h.timestamp>ua)return localStorage.removeItem(d),null;const j=(await Promise.all(h.tabs.map(async b=>({tab:b,exists:await ma(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let f=h.activeTabPath;return f&&!j.some(b=>b.path===f)&&(f=j.length>0?j[0].path:null),{tabs:j,activeTabPath:f,viewMode:h.viewMode||"files",selectedFolderIndex:h.selectedFolderIndex||0,expandedPaths:new Set(h.expandedPaths||[])}}catch(o){return console.error("[FileExplorerStorage] Failed to load state:",o),null}},[d]),m=t.useCallback(o=>{if(l)try{const h={tabs:o.tabs,activeTabPath:o.activeTabPath,viewMode:o.viewMode,selectedFolderIndex:o.selectedFolderIndex,expandedPaths:Array.from(o.expandedPaths),timestamp:Date.now()};localStorage.setItem(d,JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save state:",h)}},[d,l]);return{loadStoredState:i,saveState:m}}const Ls=280,$s=150,Hs=1200;function pa(){const[s,n]=t.useState(()=>{const p=Bs(Ht.TREE_PANEL_WIDTH,Ls);return p>=$s&&p<=Hs?p:Ls}),l=t.useRef(!1),[d,r]=t.useState(!1),i=t.useRef(0),m=t.useRef(0),o=t.useRef(s);o.current=s;const h=t.useCallback(p=>{p.preventDefault(),l.current=!0,r(!0),i.current=p.clientX,m.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const p=f=>{if(!l.current)return;const b=f.clientX-i.current,w=Math.min(Hs,Math.max($s,m.current+b));n(w)},j=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",_s(Ht.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",p),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",j)}},[]),{treePanelWidth:s,handleResizeStart:h,isResizing:d}}const ga=100,xa=.65,ya=36;function ba(){const[s,n]=t.useState(()=>Bs(Ht.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const d=t.useRef(0),r=t.useRef(0),i=()=>Math.floor((window.innerHeight-ya)*xa),m=f=>Math.min(i(),Math.max(ga,f)),o=t.useCallback(f=>{n(f);const b=document.querySelector(".file-explorer-main");b&&b.style.setProperty("--fe-mobile-tree-height",`${f}px`)},[]),h=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",_s(Ht.MOBILE_TREE_PANEL_HEIGHT,l.current),Be.setTerminalResizing(!1)},[]),p=t.useCallback(f=>{f.preventDefault();const b=document.querySelector(".file-explorer-tree-panel"),w=l.current>0?l.current:(b==null?void 0:b.getBoundingClientRect().height)??240;d.current=f.clientY,r.current=w,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Be.setTerminalResizing(!0);const R=k=>{const x=k.clientY-d.current;o(m(r.current+x))},g=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",g),h()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",g)},[o,h]),j=t.useCallback(f=>{if(f.touches.length!==1)return;const b=document.querySelector(".file-explorer-tree-panel"),w=l.current>0?l.current:(b==null?void 0:b.getBoundingClientRect().height)??240;d.current=f.touches[0].clientY,r.current=w,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Be.setTerminalResizing(!0);const R=k=>{if(k.touches.length!==1)return;k.preventDefault();const x=k.touches[0].clientY-d.current;o(m(r.current+x))},g=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",g),document.removeEventListener("touchcancel",g),h()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",g),document.addEventListener("touchcancel",g)},[o,h]);return{mobileTreeHeight:s,handleResizeMouseDown:p,handleResizeTouchStart:j}}function ts(){const[s,n]=t.useState([]),[l,d]=t.useState(!1),[r,i]=t.useState(null),[m,o]=t.useState(null),h=t.useCallback(async k=>{d(!0),i(null);try{const x=await W(V(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),v=await x.json();x.ok?n(v.branches||[]):(i(v.error||"Failed to load branches"),n([]))}catch(x){console.error("[GitBranches] Failed to load branches:",x),i("Failed to load branches"),n([])}finally{d(!1)}},[]),p=t.useCallback(async(k,x)=>{o("checkout"),i(null);try{const v=await W(V("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:x})}),C=await v.json();return v.ok||i(C.error||"Checkout failed"),C}catch(v){console.error("[GitBranches] Checkout failed:",v);const C={success:!1,error:"Checkout failed"};return i(C.error),C}finally{o(null)}},[]),j=t.useCallback(async(k,x,v)=>{o("create"),i(null);try{const C=await W(V("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:x,startPoint:v})}),D=await C.json();return C.ok||i(D.error||"Failed to create branch"),D}catch(C){console.error("[GitBranches] Create branch failed:",C);const D={success:!1,error:"Failed to create branch"};return i(D.error),D}finally{o(null)}},[]),f=t.useCallback(async k=>{o("pull"),i(null);try{const x=await W(V("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return!x.ok&&!v.conflicts&&i(v.error||"Pull failed"),v}catch(x){console.error("[GitBranches] Pull failed:",x);const v={success:!1,error:"Pull failed"};return i(v.error),v}finally{o(null)}},[]),b=t.useCallback(async k=>{o("push"),i(null);try{const x=await W(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Push failed"),v}catch(x){console.error("[GitBranches] Push failed:",x);const v={success:!1,error:"Push failed"};return i(v.error),v}finally{o(null)}},[]),w=t.useCallback(async(k,x)=>{o("merge"),i(null);try{const v=await W(V("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:x})}),C=await v.json();return!v.ok&&!C.conflicts&&i(C.error||"Merge failed"),C}catch(v){console.error("[GitBranches] Merge failed:",v);const C={success:!1,error:"Merge failed"};return i(C.error),C}finally{o(null)}},[]),R=t.useCallback(async k=>{o("merge-abort"),i(null);try{const x=await W(V("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Merge abort failed"),v}catch(x){console.error("[GitBranches] Merge abort failed:",x);const v={success:!1,error:"Merge abort failed"};return i(v.error),v}finally{o(null)}},[]),g=t.useCallback(async k=>{o("merge-continue"),i(null);try{const x=await W(V("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await x.json();return x.ok||i(v.error||"Merge continue failed"),v}catch(x){console.error("[GitBranches] Merge continue failed:",x);const v={success:!1,error:"Merge continue failed"};return i(v.error),v}finally{o(null)}},[]);return{branches:s,loading:l,error:r,operationInProgress:m,loadBranches:h,checkoutBranch:p,createBranch:j,pullFromRemote:f,pushToRemote:b,mergeBranch:w,mergeAbort:R,mergeContinue:g}}const ja=50,va=400,zs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function wa(){const[s,n]=t.useState([]),[l,d]=t.useState(!1),[r,i]=t.useState(!1),[m,o]=t.useState(null),[h,p]=t.useState(!1),[j,f]=t.useState(0),[b,w]=t.useState({...zs}),[R,g]=t.useState(null),[k,x]=t.useState([]),[v,C]=t.useState(!1),[D,N]=t.useState([]),[U,_]=t.useState(!1),O=t.useRef(null),se=t.useRef(""),Q=t.useCallback((z,I,$)=>{const P=$||b,ee=new URLSearchParams;return ee.set("path",z),ee.set("limit",String(ja)),ee.set("offset",String(I)),P.branch&&ee.set("branch",P.branch),P.author&&ee.set("author",P.author),P.since&&ee.set("since",P.since),P.until&&ee.set("until",P.until),P.searchPath&&ee.set("searchPath",P.searchPath),P.search&&ee.set("search",P.search),ee.toString()},[b]),T=t.useCallback(async z=>{se.current=z,d(!0),o(null),g(null),x([]);try{const I=Q(z,0),$=await W(V(`/api/files/git-log?${I}`)),P=await $.json();$.ok?(n(P.commits||[]),f(P.total||0),p(P.hasMore||!1)):(o(P.error||"Failed to load git history"),n([]))}catch(I){console.error("[useGitHistory] loadHistory error:",I),o("Failed to load git history"),n([])}finally{d(!1)}},[Q]),F=t.useCallback(async z=>{if(!(r||!h)){i(!0);try{const I=Q(z,s.length),$=await W(V(`/api/files/git-log?${I}`)),P=await $.json();$.ok&&(n(ee=>[...ee,...P.commits||[]]),f(P.total||0),p(P.hasMore||!1))}catch(I){console.error("[useGitHistory] loadMore error:",I)}finally{i(!1)}}},[Q,s.length,h,r]),K=t.useCallback(async z=>{if(g(z),!z){x([]);return}C(!0);try{const I=se.current,$=new URLSearchParams({path:I,hash:z.hash}),P=await W(V(`/api/files/git-commit-files?${$}`)),ee=await P.json();P.ok?x(ee.files||[]):x([])}catch(I){console.error("[useGitHistory] selectCommit files error:",I),x([])}finally{C(!1)}},[]),ne=t.useCallback((z,I)=>{w($=>({...$,[z]:I}))},[]),ie=t.useCallback(()=>{w({...zs})},[]);t.useEffect(()=>{const z=se.current;if(z)return O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{T(z)},va),()=>{O.current&&clearTimeout(O.current)}},[b]);const fe=t.useCallback(async z=>{_(!0);try{const I=new URLSearchParams({path:z}),$=await W(V(`/api/files/git-authors?${I}`)),P=await $.json();$.ok&&N(P.authors||[])}catch(I){console.error("[useGitHistory] loadAuthors error:",I)}finally{_(!1)}},[]);return{commits:s,loading:l,loadingMore:r,error:m,hasMore:h,total:j,filters:b,setFilter:ne,resetFilters:ie,selectedCommit:R,selectCommit:K,commitFiles:k,commitFilesLoading:v,loadHistory:T,loadMore:F,authors:D,authorsLoading:U,loadAuthors:fe}}function Ca(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const d=s.current.querySelector(l);if(d&&Os(d))return d}return Os(s.current)?s.current:null}function Os(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function Js(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function Xt(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Na(s){const{scrollTop:n,scrollHeight:l,clientHeight:d}=s;return l<=d?100:Math.round(n/(l-d)*100)}function ka(s,n){const l=Js(s),d=s.scrollTop,r=Math.floor(d/l)+1,i=n.split(`
|
|
3
3
|
`).length;return Math.min(r,i)}function Ea(s,n,l=!1){if(!n)return[];l||s.toLowerCase();const d=l?n:n.toLowerCase(),r=[];let i=0;const m=s.split(`
|
|
4
4
|
`);let o=0;for(let h=0;h<m.length;h++){const p=m[h],j=l?p:p.toLowerCase();let f=0,b=j.indexOf(d);for(;b!==-1;){const w=o+b;r.push({index:i++,line:h+1,column:b,length:d.length,charIndex:w}),f=b+d.length,b=j.indexOf(d,f)}o+=p.length+1}return r}function dt(s){return/[\w]/.test(s)}function _e(s){return/\s/.test(s)}function Sa(s,n,l){let d=n-1,r=l;const i=s.length,m=s[d]||"";if(r<m.length){const p=dt(m[r]);if(!_e(m[r]))for(;r<m.length&&!_e(m[r])&&dt(m[r])===p;)r++}for(;d<i;){const p=s[d]||"";for(;r<p.length&&_e(p[r]);)r++;if(r<p.length)return{line:d+1,col:r};d++,r=0}const o=i,h=Math.max(0,(s[i-1]||"").length-1);return{line:o,col:h}}function Ta(s,n,l){let d=n-1,r=l+1;const i=s.length;for(;d<i;){const h=s[d]||"";for(;r<h.length&&_e(h[r]);)r++;if(r<h.length)break;d++,r=0}if(d>=i)return{line:i,col:Math.max(0,(s[i-1]||"").length-1)};const m=s[d]||"",o=dt(m[r]);for(;r+1<m.length&&!_e(m[r+1])&&dt(m[r+1])===o;)r++;return{line:d+1,col:r}}function Ma(s,n,l){let d=n-1,r=l-1;for(;d>=0;){const o=s[d]||"";for(;r>=0&&_e(o[r]);)r--;if(r>=0)break;d--,d>=0&&(r=(s[d]||"").length-1)}if(d<0)return{line:1,col:0};const i=s[d]||"",m=dt(i[r]);for(;r>0&&!_e(i[r-1])&&dt(i[r-1])===m;)r--;return{line:d+1,col:r}}function Da(s,n,l,d){if(d==="none")return"";const{anchorLine:r,anchorCol:i,headLine:m,headCol:o}=l;if(d==="line"){const w=Math.min(r,m),R=Math.max(r,m);return n.slice(w-1,R).join(`
|
|
5
5
|
`)}let h,p,j,f;if(r<m||r===m&&i<=o?(h=r,p=i,j=m,f=o):(h=m,p=o,j=r,f=i),h===j)return(n[h-1]||"").substring(p,f+1);const b=[];b.push((n[h-1]||"").substring(p));for(let w=h;w<j-1;w++)b.push(n[w]||"");return b.push((n[j-1]||"").substring(0,f+1)),b.join(`
|
|
6
6
|
`)}function Xs(s){const{containerRef:n,isEnabled:l=!0,content:d="",onClose:r,onSearchOpen:i}=s,m=t.useRef({percentage:0,line:1,column:1}),o=t.useRef(null),h=t.useRef(19.5),p=t.useMemo(()=>d.split(`
|
|
7
|
-
`),[d]),j=p.length,[f,b]=t.useState(1),[w,R]=t.useState(0),[g,k]=t.useState(!1),[x,v]=t.useState("none"),[C,D]=t.useState(null),[N,U]=t.useState(!1),[_,O]=t.useState(""),[se,Q]=t.useState(0),[T,F]=t.useState(!1),K=t.useMemo(()=>Ea(d,_,!1),[d,_]),ne=t.useCallback(()=>{const c=o.current;if(!c)return;const G=Na(c),ae=ka(c,d),A=Math.max(1,Math.round(c.scrollLeft/7.8)+1);m.current={percentage:G,line:ae,column:A}},[d]),ie=t.useCallback(()=>{U(!0),O(""),Q(0),i==null||i()},[i]),fe=t.useCallback(()=>{U(!1),O(""),Q(0)},[]),z=t.useCallback(()=>{F(c=>!c)},[]),I=t.useCallback(c=>{const G=o.current;if(!G)return;const ae=G.querySelector(".file-viewer-pre"),ce=ae&&parseFloat(getComputedStyle(ae).lineHeight)||h.current,A=ae&&parseFloat(getComputedStyle(ae).paddingTop)||0,q=(ae?ae.offsetTop:0)+A+(c-1)*ce,Z=ce*3;G.scrollTo({top:Math.max(0,q-Z),behavior:"smooth"})},[]);t.useEffect(()=>{!N||K.length===0||Q(0)},[K,N]),t.useEffect(()=>{if(!N||K.length===0)return;const c=K[se];c&&(b(c.line),R(c.column),I(c.line))},[N,K,se,I]);const $=t.useCallback(()=>{K.length!==0&&Q(c=>(c+1)%K.length)},[K]),P=t.useCallback(()=>{K.length!==0&&Q(c=>(c-1+K.length)%K.length)},[K]),ee=t.useCallback(c=>{const G=o.current;if(!G)return;const ae=G.querySelector(".file-viewer-pre");if(!ae)return;const ce=parseFloat(getComputedStyle(ae).lineHeight),A=isNaN(ce)?h.current:ce,S=parseFloat(getComputedStyle(ae).paddingTop)||0,Z=ae.offsetTop+S+(c-1)*A,Te=Z+A,ve=G.scrollTop,X=ve+G.clientHeight;Z<ve?G.scrollTo({top:Math.max(0,Z),behavior:"auto"}):Te>X&&G.scrollTo({top:Te-G.clientHeight,behavior:"auto"})},[]),te=t.useCallback((c,G)=>{b(c),R(G),ee(c),x!=="none"&&D(ae=>ae?{...ae,headLine:c,headCol:G}:null)},[x,ee]),ge=t.useCallback(()=>{if(x==="none"||!C)return;const c=Da(d,p,C,x);c&&navigator.clipboard.writeText(c).catch(()=>{const G=document.createElement("textarea");G.value=c,G.style.position="fixed",G.style.left="-9999px",document.body.appendChild(G),G.select(),document.execCommand("copy"),document.body.removeChild(G)}),v("none"),D(null)},[x,C,d,p]),je=t.useCallback(c=>{const G=c.target;if((G.tagName==="INPUT"||G.tagName==="TEXTAREA")&&c.key!=="Escape")return;const ce=o.current;if(!ce)return;let A=!1;const S=h.current,q=Math.max(1,Math.floor(ce.clientHeight/S)),Z=Math.max(1,Math.floor(q/2)),Te=(X,xe)=>{const ze=Math.max(0,(p[X-1]||"").length-1);return Math.min(xe,Math.max(0,ze))},ve=(X,xe)=>{const ze=Te(X,xe);te(X,ze)};if(c.key==="v"&&!c.shiftKey&&!c.ctrlKey&&!N)c.preventDefault(),c.stopPropagation(),x==="char"?(v("none"),D(null)):(v("char"),D({anchorLine:f,anchorCol:w,headLine:f,headCol:w})),A=!0;else if(c.key==="V"&&c.shiftKey&&!c.ctrlKey&&!N)c.preventDefault(),c.stopPropagation(),x==="line"?(v("none"),D(null)):(v("line"),D({anchorLine:f,anchorCol:0,headLine:f,headCol:0})),A=!0;else if(c.key==="y"&&!c.ctrlKey&&x!=="none")c.preventDefault(),c.stopPropagation(),ge(),A=!0;else if(c.key==="j"||c.key==="ArrowDown"){c.preventDefault(),c.stopPropagation();const X=Math.min(f+1,j);ve(X,w),A=!0}else if(c.key==="k"||c.key==="ArrowUp"){c.preventDefault(),c.stopPropagation();const X=Math.max(f-1,1);ve(X,w),A=!0}else if(c.key==="d"&&c.ctrlKey||c.key==="d"&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.min(f+Z,j);ve(X,w),A=!0}else if(c.key==="u"&&c.ctrlKey||c.key==="u"&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.max(f-Z,1);ve(X,w),A=!0}else if((c.ctrlKey||c.metaKey)&&c.key==="f")c.preventDefault(),c.stopPropagation(),ie(),A=!0;else if(c.key==="f"&&!c.ctrlKey&&!c.metaKey&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.min(f+q,j);ve(X,w),A=!0}else if(c.key===" "||c.key==="PageDown"){c.preventDefault(),c.stopPropagation();const X=Math.min(f+q,j);ve(X,w),A=!0}else if(c.key==="b"&&!g&&x==="none"&&!N||c.key==="PageUp"){c.preventDefault(),c.stopPropagation();const X=Math.max(f-q,1);ve(X,w),A=!0}else if(c.key==="g"&&!c.shiftKey&&x==="none"&&!N)c.preventDefault(),c.stopPropagation(),te(1,0),Xt(ce,!1),A=!0;else if(c.key==="Home")c.preventDefault(),c.stopPropagation(),te(1,0),Xt(ce,!1),A=!0;else if(c.key==="G"&&c.shiftKey||c.key==="End")c.preventDefault(),c.stopPropagation(),te(j,0),Xt(ce,!0),A=!0;else if(c.key==="h"||c.key==="ArrowLeft")c.preventDefault(),c.stopPropagation(),te(f,Math.max(0,w-1)),A=!0;else if(c.key==="l"||c.key==="ArrowRight"){c.preventDefault(),c.stopPropagation();const X=(p[f-1]||"").length;te(f,Math.min(w+1,Math.max(0,X-1))),A=!0}else if(c.key==="w"&&!c.ctrlKey&&!N){c.preventDefault(),c.stopPropagation();const X=Sa(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="e"&&!c.ctrlKey&&!N){c.preventDefault(),c.stopPropagation();const X=Ta(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="b"&&!N){c.preventDefault(),c.stopPropagation();const X=Ma(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="0")c.preventDefault(),c.stopPropagation(),te(f,0),A=!0;else if(c.key==="$")c.preventDefault(),c.stopPropagation(),te(f,Math.max(0,(p[f-1]||"").length-1)),A=!0;else if(c.key==="^"){c.preventDefault(),c.stopPropagation();const xe=(p[f-1]||"").search(/\S/);te(f,xe>=0?xe:0),A=!0}else c.key==="/"?(c.preventDefault(),c.stopPropagation(),ie(),A=!0):c.key==="n"&&!N?(c.preventDefault(),c.stopPropagation(),$(),A=!0):c.key==="N"&&c.shiftKey&&!N?(c.preventDefault(),c.stopPropagation(),P(),A=!0):c.key==="?"&&x==="none"?(c.preventDefault(),c.stopPropagation(),z(),A=!0):c.key==="q"&&x==="none"?(c.preventDefault(),c.stopPropagation(),r==null||r(),A=!0):c.key==="Escape"&&(x!=="none"?(c.preventDefault(),c.stopPropagation(),v("none"),D(null),A=!0):N?(c.preventDefault(),c.stopPropagation(),fe(),A=!0):g&&(c.preventDefault(),c.stopPropagation(),k(!1),A=!0));A&&(c.key!=="Escape"&&!g&&k(!0),requestAnimationFrame(ne))},[r,ne,j,p,f,w,ee,N,fe,x,g,te,ge,ie,$,P,z]);return t.useEffect(()=>{if(!l)return;const c=Ca(n);if(o.current=c,!c){console.warn("[useLessNavigation] Could not find scrollable container");return}h.current=Js(c);const G=()=>{ne()};return window.addEventListener("keydown",je,{capture:!0}),c.addEventListener("scroll",G,{passive:!0}),ne(),()=>{window.removeEventListener("keydown",je,{capture:!0}),c.removeEventListener("scroll",G)}},[l,je,ne]),{scrollPercentage:m.current.percentage,currentLine:m.current.line,currentColumn:m.current.column,totalLines:j,cursorLine:f,cursorCol:w,cursorModeActive:g,visualMode:x,selection:C,searchActive:N,searchQuery:_,searchMatches:K,currentMatchIndex:se,startSearch:ie,setSearchQuery:O,nextMatch:$,prevMatch:P,clearSearch:fe,helpActive:T,toggleHelp:z}}const ss=({query:s,onQueryChange:n,matchCount:l,currentIndex:d,onNext:r,onPrev:i,onClose:m})=>{const{t:o}=re(["terminal"]),h=t.useRef(null);t.useEffect(()=>{var f;(f=h.current)==null||f.focus()},[]);const p=t.useCallback(f=>{f.stopPropagation(),f.key==="Enter"||f.key==="ArrowDown"?(f.preventDefault(),r()):f.key==="ArrowUp"&&(f.preventDefault(),i())},[r,i]),j=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${d+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:h,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:f=>n(f.target.value),onKeyDown:p,autoComplete:"off",spellCheck:"false"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:j}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:i,disabled:l===0,title:o("terminal:fileExplorer.previousMatch"),"aria-label":o("terminal:fileExplorer.previousMatch"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:r,disabled:l===0,title:o("terminal:fileExplorer.nextMatch"),"aria-label":o("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:m,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};ss.displayName="SearchBar";const Ra=[{keys:["j","↓"],description:"Move cursor down one line",category:"Navigation"},{keys:["k","↑"],description:"Move cursor up one line",category:"Navigation"},{keys:["h","←"],description:"Move cursor left",category:"Navigation"},{keys:["l","→"],description:"Move cursor right",category:"Navigation"},{keys:["0"],description:"Jump to start of line",category:"Navigation"},{keys:["$"],description:"Jump to end of line",category:"Navigation"},{keys:["^"],description:"First non-whitespace char",category:"Navigation"},{keys:["d","Ctrl+D"],description:"Half page down",category:"Navigation"},{keys:["u","Ctrl+U"],description:"Half page up",category:"Navigation"},{keys:["f","Space"],description:"Full page down",category:"Navigation"},{keys:["b","Page Up"],description:"Full page up",category:"Navigation"},{keys:["g","Home"],description:"Jump to top of file",category:"Navigation"},{keys:["G","End"],description:"Jump to bottom of file",category:"Navigation"},{keys:["w"],description:"Next word start",category:"Word Motion"},{keys:["e"],description:"Next word end",category:"Word Motion"},{keys:["b"],description:"Previous word start",category:"Word Motion"},{keys:["v"],description:"Character visual mode",category:"Visual Mode"},{keys:["V"],description:"Line visual mode",category:"Visual Mode"},{keys:["y"],description:"Yank (copy) selection",category:"Visual Mode"},{keys:["Escape"],description:"Exit visual mode",category:"Visual Mode"},{keys:["/"],description:"Open search bar",category:"Search"},{keys:["n"],description:"Next match",category:"Search"},{keys:["N"],description:"Previous match",category:"Search"},{keys:["?"],description:"Toggle this help overlay",category:"Help"},{keys:["Escape"],description:"Exit cursor mode (or visual/search)",category:"Help"},{keys:["Alt+E"],description:"Close file viewer",category:"Help"},{keys:["q"],description:"Close file viewer",category:"Help"}],ns=({onClose:s})=>{const{t:n}=re(["terminal"]),l=t.useCallback(i=>{i.target===i.currentTarget&&s()},[s]),d=t.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),s())},[s]),r=Ra.reduce((i,m)=>(i[m.category]||(i[m.category]=[]),i[m.category].push(m),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:d,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(r).map(([i,m])=>e.jsxs("div",{className:"keybindings-help-category",children:[e.jsx("h3",{className:"keybindings-help-category-title",children:i}),e.jsx("div",{className:"keybindings-help-list",children:m.map((o,h)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((p,j)=>e.jsx("kbd",{className:"keybindings-help-key",children:p},j))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},h))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};ns.displayName="KeybindingsHelp";const As=t.lazy(()=>Gn(()=>import("./EmbeddedEditor-D4dyGPWp.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Fa=[".md",".mdx",".markdown"],Gs="file-viewer-markdown-render",Ia=[".puml",".plantuml",".iuml",".pu"],Us="file-viewer-plantuml-render",Pa="https://kroki.io/plantuml/svg";function La(s){return Fa.includes(s.toLowerCase())}function $a(s){return Ia.includes(s.toLowerCase())}function Ha(){const[s,n]=t.useState(()=>{try{const d=localStorage.getItem(Gs);return d===null?!0:d==="true"}catch{return!0}}),l=t.useCallback(()=>{n(d=>{const r=!d;try{localStorage.setItem(Gs,String(r))}catch{}return r})},[]);return[s,l]}function za(){const[s,n]=t.useState(()=>{try{const d=localStorage.getItem(Us);return d===null?!0:d==="true"}catch{return!0}}),l=t.useCallback(()=>{n(d=>{const r=!d;try{localStorage.setItem(Us,String(r))}catch{}return r})},[]);return[s,l]}function Oa(s){const n=new TextEncoder().encode(s);let l="";for(const d of n)l+=String.fromCharCode(d);return`data:image/svg+xml;base64,${window.btoa(l)}`}function Ve({file:s,rightContent:n,onRevealInTree:l,editMode:d,onToggleEdit:r}){const{t:i}=re(["terminal","common"]),[m,o]=t.useState("idle"),[h,p]=t.useState("idle"),[j,f]=t.useState("idle"),b=s.fileType==="text"?zt(s.extension):s.extension.slice(1).toUpperCase(),w=s.fileType==="text"&&s.content!=null,{settings:R}=Vs(),g=async()=>{try{await Pt(s.content),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},k=()=>{const D=new Blob([s.content],{type:"text/plain;charset=utf-8"}),N=URL.createObjectURL(D),U=document.createElement("a");U.href=N,U.download=s.filename,document.body.appendChild(U),U.click(),U.remove(),setTimeout(()=>URL.revokeObjectURL(N),1e3)},x=async()=>{o("loading");try{const D=await W(V("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!D.ok){const N=await D.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",N),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(D){console.error("Error opening file in editor:",D),o("error"),setTimeout(()=>o("idle"),2e3)}},v=async()=>{if(s.path)try{await Kn(s.path),p("success"),setTimeout(()=>p("idle"),2e3)}catch(D){console.error("Error opening file explorer:",D),p("error"),setTimeout(()=>p("idle"),2e3)}},C=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:s.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[Ks(s.size)," • ",b,s.content&&` • ${s.content.split(`
|
|
7
|
+
`),[d]),j=p.length,[f,b]=t.useState(1),[w,R]=t.useState(0),[g,k]=t.useState(!1),[x,v]=t.useState("none"),[C,D]=t.useState(null),[N,U]=t.useState(!1),[_,O]=t.useState(""),[se,Q]=t.useState(0),[T,F]=t.useState(!1),K=t.useMemo(()=>Ea(d,_,!1),[d,_]),ne=t.useCallback(()=>{const c=o.current;if(!c)return;const G=Na(c),ae=ka(c,d),A=Math.max(1,Math.round(c.scrollLeft/7.8)+1);m.current={percentage:G,line:ae,column:A}},[d]),ie=t.useCallback(()=>{U(!0),O(""),Q(0),i==null||i()},[i]),fe=t.useCallback(()=>{U(!1),O(""),Q(0)},[]),z=t.useCallback(()=>{F(c=>!c)},[]),I=t.useCallback(c=>{const G=o.current;if(!G)return;const ae=G.querySelector(".file-viewer-pre"),ce=ae&&parseFloat(getComputedStyle(ae).lineHeight)||h.current,A=ae&&parseFloat(getComputedStyle(ae).paddingTop)||0,q=(ae?ae.offsetTop:0)+A+(c-1)*ce,Z=ce*3;G.scrollTo({top:Math.max(0,q-Z),behavior:"smooth"})},[]);t.useEffect(()=>{!N||K.length===0||Q(0)},[K,N]),t.useEffect(()=>{if(!N||K.length===0)return;const c=K[se];c&&(b(c.line),R(c.column),I(c.line))},[N,K,se,I]);const $=t.useCallback(()=>{K.length!==0&&Q(c=>(c+1)%K.length)},[K]),P=t.useCallback(()=>{K.length!==0&&Q(c=>(c-1+K.length)%K.length)},[K]),ee=t.useCallback(c=>{const G=o.current;if(!G)return;const ae=G.querySelector(".file-viewer-pre");if(!ae)return;const ce=parseFloat(getComputedStyle(ae).lineHeight),A=isNaN(ce)?h.current:ce,S=parseFloat(getComputedStyle(ae).paddingTop)||0,Z=ae.offsetTop+S+(c-1)*A,Te=Z+A,ve=G.scrollTop,X=ve+G.clientHeight;Z<ve?G.scrollTo({top:Math.max(0,Z),behavior:"auto"}):Te>X&&G.scrollTo({top:Te-G.clientHeight,behavior:"auto"})},[]),te=t.useCallback((c,G)=>{b(c),R(G),ee(c),x!=="none"&&D(ae=>ae?{...ae,headLine:c,headCol:G}:null)},[x,ee]),ge=t.useCallback(()=>{if(x==="none"||!C)return;const c=Da(d,p,C,x);c&&navigator.clipboard.writeText(c).catch(()=>{const G=document.createElement("textarea");G.value=c,G.style.position="fixed",G.style.left="-9999px",document.body.appendChild(G),G.select(),document.execCommand("copy"),document.body.removeChild(G)}),v("none"),D(null)},[x,C,d,p]),je=t.useCallback(c=>{const G=c.target;if((G.tagName==="INPUT"||G.tagName==="TEXTAREA")&&c.key!=="Escape")return;const ce=o.current;if(!ce)return;let A=!1;const S=h.current,q=Math.max(1,Math.floor(ce.clientHeight/S)),Z=Math.max(1,Math.floor(q/2)),Te=(X,xe)=>{const ze=Math.max(0,(p[X-1]||"").length-1);return Math.min(xe,Math.max(0,ze))},ve=(X,xe)=>{const ze=Te(X,xe);te(X,ze)};if(c.key==="v"&&!c.shiftKey&&!c.ctrlKey&&!N)c.preventDefault(),c.stopPropagation(),x==="char"?(v("none"),D(null)):(v("char"),D({anchorLine:f,anchorCol:w,headLine:f,headCol:w})),A=!0;else if(c.key==="V"&&c.shiftKey&&!c.ctrlKey&&!N)c.preventDefault(),c.stopPropagation(),x==="line"?(v("none"),D(null)):(v("line"),D({anchorLine:f,anchorCol:0,headLine:f,headCol:0})),A=!0;else if(c.key==="y"&&!c.ctrlKey&&x!=="none")c.preventDefault(),c.stopPropagation(),ge(),A=!0;else if(c.key==="j"||c.key==="ArrowDown"){c.preventDefault(),c.stopPropagation();const X=Math.min(f+1,j);ve(X,w),A=!0}else if(c.key==="k"||c.key==="ArrowUp"){c.preventDefault(),c.stopPropagation();const X=Math.max(f-1,1);ve(X,w),A=!0}else if(c.key==="d"&&c.ctrlKey||c.key==="d"&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.min(f+Z,j);ve(X,w),A=!0}else if(c.key==="u"&&c.ctrlKey||c.key==="u"&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.max(f-Z,1);ve(X,w),A=!0}else if((c.ctrlKey||c.metaKey)&&c.key==="f")c.preventDefault(),c.stopPropagation(),ie(),A=!0;else if(c.key==="f"&&!c.ctrlKey&&!c.metaKey&&x==="none"&&!N){c.preventDefault(),c.stopPropagation();const X=Math.min(f+q,j);ve(X,w),A=!0}else if(c.key===" "||c.key==="PageDown"){c.preventDefault(),c.stopPropagation();const X=Math.min(f+q,j);ve(X,w),A=!0}else if(c.key==="b"&&!g&&x==="none"&&!N||c.key==="PageUp"){c.preventDefault(),c.stopPropagation();const X=Math.max(f-q,1);ve(X,w),A=!0}else if(c.key==="g"&&!c.shiftKey&&x==="none"&&!N)c.preventDefault(),c.stopPropagation(),te(1,0),Xt(ce,!1),A=!0;else if(c.key==="Home")c.preventDefault(),c.stopPropagation(),te(1,0),Xt(ce,!1),A=!0;else if(c.key==="G"&&c.shiftKey||c.key==="End")c.preventDefault(),c.stopPropagation(),te(j,0),Xt(ce,!0),A=!0;else if(c.key==="h"||c.key==="ArrowLeft")c.preventDefault(),c.stopPropagation(),te(f,Math.max(0,w-1)),A=!0;else if(c.key==="l"||c.key==="ArrowRight"){c.preventDefault(),c.stopPropagation();const X=(p[f-1]||"").length;te(f,Math.min(w+1,Math.max(0,X-1))),A=!0}else if(c.key==="w"&&!c.ctrlKey&&!N){c.preventDefault(),c.stopPropagation();const X=Sa(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="e"&&!c.ctrlKey&&!N){c.preventDefault(),c.stopPropagation();const X=Ta(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="b"&&!N){c.preventDefault(),c.stopPropagation();const X=Ma(p,f,w);te(X.line,X.col),A=!0}else if(c.key==="0")c.preventDefault(),c.stopPropagation(),te(f,0),A=!0;else if(c.key==="$")c.preventDefault(),c.stopPropagation(),te(f,Math.max(0,(p[f-1]||"").length-1)),A=!0;else if(c.key==="^"){c.preventDefault(),c.stopPropagation();const xe=(p[f-1]||"").search(/\S/);te(f,xe>=0?xe:0),A=!0}else c.key==="/"?(c.preventDefault(),c.stopPropagation(),ie(),A=!0):c.key==="n"&&!N?(c.preventDefault(),c.stopPropagation(),$(),A=!0):c.key==="N"&&c.shiftKey&&!N?(c.preventDefault(),c.stopPropagation(),P(),A=!0):c.key==="?"&&x==="none"?(c.preventDefault(),c.stopPropagation(),z(),A=!0):c.key==="q"&&x==="none"?(c.preventDefault(),c.stopPropagation(),r==null||r(),A=!0):c.key==="Escape"&&(x!=="none"?(c.preventDefault(),c.stopPropagation(),v("none"),D(null),A=!0):N?(c.preventDefault(),c.stopPropagation(),fe(),A=!0):g&&(c.preventDefault(),c.stopPropagation(),k(!1),A=!0));A&&(c.key!=="Escape"&&!g&&k(!0),requestAnimationFrame(ne))},[r,ne,j,p,f,w,ee,N,fe,x,g,te,ge,ie,$,P,z]);return t.useEffect(()=>{if(!l)return;const c=Ca(n);if(o.current=c,!c){console.warn("[useLessNavigation] Could not find scrollable container");return}h.current=Js(c);const G=()=>{ne()};return window.addEventListener("keydown",je,{capture:!0}),c.addEventListener("scroll",G,{passive:!0}),ne(),()=>{window.removeEventListener("keydown",je,{capture:!0}),c.removeEventListener("scroll",G)}},[l,je,ne]),{scrollPercentage:m.current.percentage,currentLine:m.current.line,currentColumn:m.current.column,totalLines:j,cursorLine:f,cursorCol:w,cursorModeActive:g,visualMode:x,selection:C,searchActive:N,searchQuery:_,searchMatches:K,currentMatchIndex:se,startSearch:ie,setSearchQuery:O,nextMatch:$,prevMatch:P,clearSearch:fe,helpActive:T,toggleHelp:z}}const ss=({query:s,onQueryChange:n,matchCount:l,currentIndex:d,onNext:r,onPrev:i,onClose:m})=>{const{t:o}=re(["terminal"]),h=t.useRef(null);t.useEffect(()=>{var f;(f=h.current)==null||f.focus()},[]);const p=t.useCallback(f=>{f.stopPropagation(),f.key==="Enter"||f.key==="ArrowDown"?(f.preventDefault(),r()):f.key==="ArrowUp"&&(f.preventDefault(),i())},[r,i]),j=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${d+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:h,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:f=>n(f.target.value),onKeyDown:p,autoComplete:"off",spellCheck:"false"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:j}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:i,disabled:l===0,title:o("terminal:fileExplorer.previousMatch"),"aria-label":o("terminal:fileExplorer.previousMatch"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:r,disabled:l===0,title:o("terminal:fileExplorer.nextMatch"),"aria-label":o("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:m,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};ss.displayName="SearchBar";const Ra=[{keys:["j","↓"],description:"Move cursor down one line",category:"Navigation"},{keys:["k","↑"],description:"Move cursor up one line",category:"Navigation"},{keys:["h","←"],description:"Move cursor left",category:"Navigation"},{keys:["l","→"],description:"Move cursor right",category:"Navigation"},{keys:["0"],description:"Jump to start of line",category:"Navigation"},{keys:["$"],description:"Jump to end of line",category:"Navigation"},{keys:["^"],description:"First non-whitespace char",category:"Navigation"},{keys:["d","Ctrl+D"],description:"Half page down",category:"Navigation"},{keys:["u","Ctrl+U"],description:"Half page up",category:"Navigation"},{keys:["f","Space"],description:"Full page down",category:"Navigation"},{keys:["b","Page Up"],description:"Full page up",category:"Navigation"},{keys:["g","Home"],description:"Jump to top of file",category:"Navigation"},{keys:["G","End"],description:"Jump to bottom of file",category:"Navigation"},{keys:["w"],description:"Next word start",category:"Word Motion"},{keys:["e"],description:"Next word end",category:"Word Motion"},{keys:["b"],description:"Previous word start",category:"Word Motion"},{keys:["v"],description:"Character visual mode",category:"Visual Mode"},{keys:["V"],description:"Line visual mode",category:"Visual Mode"},{keys:["y"],description:"Yank (copy) selection",category:"Visual Mode"},{keys:["Escape"],description:"Exit visual mode",category:"Visual Mode"},{keys:["/"],description:"Open search bar",category:"Search"},{keys:["n"],description:"Next match",category:"Search"},{keys:["N"],description:"Previous match",category:"Search"},{keys:["?"],description:"Toggle this help overlay",category:"Help"},{keys:["Escape"],description:"Exit cursor mode (or visual/search)",category:"Help"},{keys:["Alt+E"],description:"Close file viewer",category:"Help"},{keys:["q"],description:"Close file viewer",category:"Help"}],ns=({onClose:s})=>{const{t:n}=re(["terminal"]),l=t.useCallback(i=>{i.target===i.currentTarget&&s()},[s]),d=t.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),s())},[s]),r=Ra.reduce((i,m)=>(i[m.category]||(i[m.category]=[]),i[m.category].push(m),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:d,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(r).map(([i,m])=>e.jsxs("div",{className:"keybindings-help-category",children:[e.jsx("h3",{className:"keybindings-help-category-title",children:i}),e.jsx("div",{className:"keybindings-help-list",children:m.map((o,h)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((p,j)=>e.jsx("kbd",{className:"keybindings-help-key",children:p},j))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},h))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};ns.displayName="KeybindingsHelp";const As=t.lazy(()=>Gn(()=>import("./EmbeddedEditor--X_L8Y9G.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Fa=[".md",".mdx",".markdown"],Gs="file-viewer-markdown-render",Ia=[".puml",".plantuml",".iuml",".pu"],Us="file-viewer-plantuml-render",Pa="https://kroki.io/plantuml/svg";function La(s){return Fa.includes(s.toLowerCase())}function $a(s){return Ia.includes(s.toLowerCase())}function Ha(){const[s,n]=t.useState(()=>{try{const d=localStorage.getItem(Gs);return d===null?!0:d==="true"}catch{return!0}}),l=t.useCallback(()=>{n(d=>{const r=!d;try{localStorage.setItem(Gs,String(r))}catch{}return r})},[]);return[s,l]}function za(){const[s,n]=t.useState(()=>{try{const d=localStorage.getItem(Us);return d===null?!0:d==="true"}catch{return!0}}),l=t.useCallback(()=>{n(d=>{const r=!d;try{localStorage.setItem(Us,String(r))}catch{}return r})},[]);return[s,l]}function Oa(s){const n=new TextEncoder().encode(s);let l="";for(const d of n)l+=String.fromCharCode(d);return`data:image/svg+xml;base64,${window.btoa(l)}`}function Ve({file:s,rightContent:n,onRevealInTree:l,editMode:d,onToggleEdit:r}){const{t:i}=re(["terminal","common"]),[m,o]=t.useState("idle"),[h,p]=t.useState("idle"),[j,f]=t.useState("idle"),b=s.fileType==="text"?zt(s.extension):s.extension.slice(1).toUpperCase(),w=s.fileType==="text"&&s.content!=null,{settings:R}=Vs(),g=async()=>{try{await Pt(s.content),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},k=()=>{const D=new Blob([s.content],{type:"text/plain;charset=utf-8"}),N=URL.createObjectURL(D),U=document.createElement("a");U.href=N,U.download=s.filename,document.body.appendChild(U),U.click(),U.remove(),setTimeout(()=>URL.revokeObjectURL(N),1e3)},x=async()=>{o("loading");try{const D=await W(V("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!D.ok){const N=await D.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",N),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(D){console.error("Error opening file in editor:",D),o("error"),setTimeout(()=>o("idle"),2e3)}},v=async()=>{if(s.path)try{await Kn(s.path),p("success"),setTimeout(()=>p("idle"),2e3)}catch(D){console.error("Error opening file explorer:",D),p("error"),setTimeout(()=>p("idle"),2e3)}},C=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:s.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[Ks(s.size)," • ",b,s.content&&` • ${s.content.split(`
|
|
8
8
|
`).length} lines`]})]}),e.jsxs("div",{className:"file-viewer-header-right",children:[r&&s.fileType==="text"&&e.jsx("button",{className:`file-viewer-edit-btn${d?" active":""}`,onClick:r,title:i(d?"terminal:fileExplorer.exitEdit":"terminal:fileExplorer.editFile"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L3.463 11.1a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.25.25 0 00.108-.064l8.61-8.61a.25.25 0 000-.354l-1.086-1.086z"})})}),w&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${j}`,onClick:g,title:i("terminal:fileExplorer.copyAllTitle"),children:i(j==="copied"?"terminal:fileExplorer.copied":j==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyAll")}),e.jsx("button",{className:"file-viewer-download-btn",onClick:k,title:i("terminal:fileExplorer.downloadFileTitle"),children:i("common:buttons.download")})]}),e.jsx("button",{className:`file-viewer-reveal-explorer-btn ${h}`,onClick:v,disabled:!s.path,title:C,"aria-label":C,children:h==="success"?e.jsx(M,{name:"check",size:14}):h==="error"?e.jsx(M,{name:"cross",size:14}):e.jsx(M,{name:"folder-open",size:14})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${m}`,onClick:x,disabled:m==="loading",title:i(m==="error"?"terminal:fileExplorer.failedToOpenEditor":m==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:m==="success"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 11-1.06-1.06l7.25-7.25a.75.75 0 011.06 0z"})}):m==="error"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1.5 1h6v1.5h-5v11h11v-5H15v6.5H0V1h1.5zm8 0H15v5.5h-1.5V3.56L7.28 9.78l-1.06-1.06L12.44 2.5H9.5V1z"})})}),l&&e.jsx("button",{className:"file-viewer-locate-btn",onClick:()=>l(s.path),title:i("terminal:fileExplorer.locateInTree"),children:e.jsx(M,{name:"target",size:14})}),n]})]})}function Aa({file:s,onRevealInTree:n,renderMarkdown:l,onToggleRender:d,editMode:r,onToggleEdit:i}){const m=t.useRef(null),o=t.useRef(null),h=t.useRef(null),{t:p}=re(["terminal","common"]),[j,f]=t.useState("idle"),[b,w]=t.useState("idle"),[R,g]=t.useState("idle"),[k,x]=t.useState("idle"),v=Xs({containerRef:h,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&m.current){const O=zt(s.extension);Ws(O).then(()=>{m.current&&qs(m.current)})}},[s,l]);const C=t.useCallback(async()=>{if(!o.current){f("error"),setTimeout(()=>f("idle"),2e3);return}try{const O=o.current.innerHTML,se=Un(O),Q=o.current.innerText;await Bn(se,Q),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},[]),D=t.useCallback(async()=>{if(!o.current){w("error"),setTimeout(()=>w("idle"),2e3);return}try{const O=o.current.innerHTML;await Pt(O),w("copied"),setTimeout(()=>w("idle"),2e3)}catch{w("error"),setTimeout(()=>w("idle"),2e3)}},[]),N=t.useCallback(async()=>{try{await Pt(s.content),g("copied"),setTimeout(()=>g("idle"),2e3)}catch{g("error"),setTimeout(()=>g("idle"),2e3)}},[s.content]),U=t.useCallback(async()=>{try{await Pt(s.content),x("copied"),setTimeout(()=>x("idle"),2e3)}catch{x("error"),setTimeout(()=>x("idle"),2e3)}},[s.content]),_=e.jsxs("div",{className:"file-viewer-header-buttons",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${j}`,onClick:C,title:p("terminal:fileExplorer.copyRichTextTitle"),children:p(j==="copied"?"terminal:fileExplorer.copied":j==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:D,title:p("terminal:fileExplorer.copyHtmlTitle"),children:p(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${R}`,onClick:N,title:p("terminal:fileExplorer.copyMarkdownTitle"),children:p(R==="copied"?"terminal:fileExplorer.copied":R==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${k}`,onClick:U,title:p("terminal:fileExplorer.copyOriginalTitle"),children:p(k==="copied"?"terminal:fileExplorer.copied":k==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:d,title:p(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:l?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:_,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:h,children:[l?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:o,children:e.jsx(_n,{remarkPlugins:[Vn],children:s.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:m,className:"language-markdown",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${v.currentLine}/${v.totalLines}`,children:v.scrollPercentage===100?"END":v.scrollPercentage===0?"TOP":`${v.scrollPercentage}%`}),v.searchActive&&e.jsx(ss,{query:v.searchQuery,onQueryChange:v.setSearchQuery,matchCount:v.searchMatches.length,currentIndex:v.currentMatchIndex,onNext:v.nextMatch,onPrev:v.prevMatch,onClose:v.clearSearch})]}),v.helpActive&&e.jsx(ns,{onClose:v.toggleHelp})]})}function Ga({file:s,onRevealInTree:n,renderPlantUml:l,onToggleRender:d,editMode:r,onToggleEdit:i}){const{t:m}=re(["terminal"]),o=t.useRef(null),h=t.useRef(null),[p,j]=t.useState(null),[f,b]=t.useState(!1),[w,R]=t.useState(null),g=Xs({containerRef:h,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&o.current){const x=zt(s.extension);Ws(x).then(()=>{o.current&&qs(o.current)})}},[s,l]),t.useEffect(()=>{if(!l)return;if(!s.content.trim()){j(null),R("Diagram is empty");return}const x=new AbortController;return b(!0),R(null),(async()=>{try{const C=await fetch(Pa,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:s.content,signal:x.signal});if(!C.ok)throw new Error(`Render failed (${C.status})`);const D=await C.text();if(!D.includes("<svg"))throw new Error("Invalid SVG output");j(Oa(D))}catch(C){if(x.signal.aborted)return;const D=C instanceof Error?C.message:"Failed to render diagram";R(D),j(null)}finally{x.signal.aborted||b(!1)}})(),()=>x.abort()},[s.path,s.content,l]);const k=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:d,title:m(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:l?"</>":m("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:k,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:h,children:[l?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[f&&e.jsx("div",{className:"file-viewer-placeholder",children:m("terminal:fileExplorer.renderingDiagram")}),!f&&p&&e.jsx("img",{src:p,alt:s.filename,className:"file-viewer-diagram-image"}),!f&&w&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[m("terminal:fileExplorer.couldNotRender"),": ",w]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:d,children:m("terminal:fileExplorer.showSource")})]})]}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:o,className:"language-plaintext",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${g.currentLine}/${g.totalLines}`,children:g.scrollPercentage===100?"END":g.scrollPercentage===0?"TOP":`${g.scrollPercentage}%`}),g.searchActive&&e.jsx(ss,{query:g.searchQuery,onQueryChange:g.setSearchQuery,matchCount:g.searchMatches.length,currentIndex:g.currentMatchIndex,onNext:g.nextMatch,onPrev:g.prevMatch,onClose:g.clearSearch})]}),g.helpActive&&e.jsx(ns,{onClose:g.toggleHelp})]})}function Ua({file:s,onRevealInTree:n}){const{t:l}=re(["common","terminal"]),d=()=>{if(s.dataUrl){const r=document.createElement("a");r.href=s.dataUrl,r.download=s.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:d,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper",children:s.dataUrl?e.jsx("img",{src:s.dataUrl,alt:s.filename,className:"file-viewer-image"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadImage")})})]})}function Ba({file:s,onRevealInTree:n}){const{t:l}=re(["common","terminal"]),d=()=>{if(s.dataUrl){const r=document.createElement("a");r.href=s.dataUrl,r.download=s.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:d,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:s.dataUrl?e.jsx("iframe",{src:s.dataUrl,title:s.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadPdf")})})]})}function _a({file:s,onRevealInTree:n}){const{t:l}=re(["terminal","common"]),d=()=>{if(s.dataUrl){const i=document.createElement("a");i.href=s.dataUrl,i.download=s.filename,i.click()}},r=()=>{const i=s.extension.toLowerCase();return[".xlsx",".xls"].includes(i)?e.jsx(M,{name:"dashboard",size:48}):[".docx",".doc"].includes(i)?e.jsx(M,{name:"edit",size:48}):[".pptx",".ppt"].includes(i)?e.jsx(M,{name:"film",size:48}):[".zip",".tar",".gz",".rar",".7z"].includes(i)?e.jsx(M,{name:"file-zip",size:48}):[".mp3",".wav",".flac",".ogg"].includes(i)?e.jsx(M,{name:"music-note",size:48}):[".mp4",".avi",".mov",".mkv",".webm"].includes(i)?e.jsx(M,{name:"film",size:48}):[".exe",".dmg",".app",".msi"].includes(i)?e.jsx(M,{name:"gear",size:48}):[".apk",".aab",".ipa"].includes(i)?e.jsx(M,{name:"mobile",size:48}):[".jar",".war",".ear"].includes(i)?e.jsx(M,{name:"coffee",size:48}):[".iso",".img"].includes(i)?e.jsx(M,{name:"disc",size:48}):[".so",".dll",".dylib"].includes(i)?e.jsx(M,{name:"wrench",size:48}):e.jsx(M,{name:"folder",size:48})};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{file:s,onRevealInTree:n}),e.jsxs("div",{className:"file-viewer-binary",children:[e.jsx("div",{className:"file-viewer-binary-icon",children:r()}),e.jsx("div",{className:"file-viewer-binary-name",children:s.filename}),e.jsx("div",{className:"file-viewer-binary-size",children:Ks(s.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:l("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:d,children:l("terminal:fileExplorer.downloadFile")})]})]})}function Va({file:s,loading:n,error:l,onRevealInTree:d,onFileEdited:r}){const{t:i}=re(["terminal","common"]),[m,o]=Ha(),[h,p]=za(),[j,f]=t.useState(!1);t.useEffect(()=>{f(!1)},[s==null?void 0:s.path]);const b=t.useCallback(async C=>{if(!s)return;const D=await W(V("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,content:C})});if(!D.ok){const N=await D.json().catch(()=>({error:"Save failed"}));throw new Error(N.error||"Save failed")}},[s]),w=t.useCallback(()=>{f(C=>(C&&s&&(r==null||r(s.path)),!C))},[s,r]),R=t.useCallback(()=>{s&&(r==null||r(s.path))},[s,r]);if(n)return e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")});if(l)return e.jsx("div",{className:"file-viewer-placeholder error",children:l});if(!s)return e.jsxs("div",{className:"file-viewer-placeholder",children:[e.jsx("div",{className:"placeholder-icon",children:e.jsx(M,{name:"folder-open",size:32})}),e.jsx("div",{className:"placeholder-text",children:i("terminal:fileExplorer.selectFileToView")})]});const g=s.fileType||"text",k=g==="text"&&La(s.extension),x=g==="text"&&$a(s.extension),v=k||x;return v&&j&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:d,editMode:!0,onToggleEdit:w}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(As,{content:s.content,extension:s.extension,onSave:b,onCancel:w},s.path)})]}):g==="text"&&!v&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ve,{file:s,onRevealInTree:d}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(As,{content:s.content,extension:s.extension,onSave:b,onCancel:R},s.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[k&&e.jsx(Aa,{file:s,onRevealInTree:d,renderMarkdown:m,onToggleRender:o,editMode:j,onToggleEdit:w}),x&&!k&&e.jsx(Ga,{file:s,onRevealInTree:d,renderPlantUml:h,onToggleRender:p,editMode:j,onToggleEdit:w}),g==="image"&&e.jsx(Ua,{file:s,onRevealInTree:d}),g==="pdf"&&e.jsx(Ba,{file:s,onRevealInTree:d}),g==="binary"&&e.jsx(_a,{file:s,onRevealInTree:d})]})}const Qs=t.memo(Va,(s,n)=>s.loading!==n.loading||s.error!==n.error?!1:s.file===null&&n.file===null?!0:s.file===null||n.file===null?!1:s.file.path===n.file.path&&s.file.content===n.file.content&&s.file.modified===n.file.modified);Qs.displayName="FileViewer";function Zs({text:s,query:n}){if(!n)return e.jsx(e.Fragment,{children:s});const l=Wn(s,n);if(l)return e.jsxs(e.Fragment,{children:[s.slice(0,l.start),e.jsx("mark",{className:"search-highlight",children:s.slice(l.start,l.end)}),s.slice(l.end)]});const d=n.toLowerCase(),i=s.toLowerCase().indexOf(d);return i===-1?e.jsx(e.Fragment,{children:s}):e.jsxs(e.Fragment,{children:[s.slice(0,i),e.jsx("mark",{className:"search-highlight",children:s.slice(i,i+n.length)}),s.slice(i+n.length)]})}const Ka=t.memo(function({node:n,query:l,isSelected:d,onSelect:r,lineNumber:i}){const m=n.isDirectory?null:es(n),o=n.path.split("/");o[o.length-1];const h=o.slice(0,-1).join("/");return e.jsxs("div",{className:`search-result-item ${d?"selected":""}`,onClick:()=>r(n),children:[n.isDirectory?e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"folder",size:14})}):m?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${m}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{className:"search-result-info",children:[e.jsxs("span",{className:"search-result-name",children:[e.jsx(Zs,{text:n.name,query:l}),i&&e.jsxs("span",{className:"search-result-line-badge",children:[":",i]})]}),e.jsx("span",{className:"search-result-path",children:h})]})]})}),Wa=t.memo(function({match:n,query:l,isSelected:d,onSelect:r}){const{t:i}=re(["terminal"]),m={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},o=es(m),h=n.path.split("/"),p=h[h.length-1],j=h.slice(0,-1).join("/");return e.jsxs("div",{className:`content-search-item ${d?"selected":""}`,children:[e.jsxs("div",{className:`content-search-header ${d?"selected":""}`,onClick:()=>r(n.path),children:[o?e.jsx("span",{className:"content-search-icon",style:{backgroundImage:`url('${o}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"content-search-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"2px"},children:[e.jsx("span",{className:"content-search-name",children:p}),e.jsx("span",{className:"search-result-path",style:{fontSize:"10px"},children:j})]}),e.jsx("span",{className:"content-search-count",children:n.matches.length})]}),e.jsxs("div",{className:"content-search-matches",children:[n.matches.slice(0,5).map((f,b)=>e.jsxs("div",{className:"content-search-match",onClick:()=>r(n.path,f.line),children:[e.jsx("span",{className:"content-search-line-num",children:f.line}),e.jsx("span",{className:"content-search-line-content",children:e.jsx(Zs,{text:f.content.trim(),query:l})})]},`${n.path}-${f.line}-${b}`)),n.matches.length>5&&e.jsxs("div",{className:"content-search-match",style:{opacity:.6,cursor:"default"},children:[e.jsx("span",{className:"content-search-line-num",children:"..."}),e.jsx("span",{className:"content-search-line-content",children:i("terminal:fileExplorer.moreMatches",{count:n.matches.length-5})})]})]})]})});function qa({filenameResults:s,contentResults:n,onSelectFile:l,onSelectContent:d,selectedPath:r,query:i,lineNumber:m}){const{t:o}=re(["terminal"]),h=s.length>0,p=n.length>0;return!h&&!p?e.jsx("div",{className:"search-no-results",children:o("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[h&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:s.length})]}),e.jsx("div",{className:"unified-search-section-content",children:s.map(j=>e.jsx(Ka,{node:j,query:i,isSelected:r===j.path,onSelect:l,lineNumber:m},j.path))})]}),p&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"edit",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.content")}),e.jsx("span",{className:"unified-search-section-count",children:o("terminal:fileExplorer.matchesInFiles",{matches:n.reduce((j,f)=>j+f.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(j=>e.jsx(Wa,{match:j,query:i,isSelected:r===j.path,onSelect:d},j.path))})]})]})}const en=t.memo(qa,(s,n)=>!(s.query!==n.query||s.selectedPath!==n.selectedPath||s.filenameResults.length!==n.filenameResults.length||s.contentResults.length!==n.contentResults.length));en.displayName="UnifiedSearchResults";const Ya=t.memo(function({file:n,isSelected:l,onSelect:d,onStage:r,isStaging:i,showDirPath:m,isChecked:o,onToggleCheck:h,onContextMenu:p,onDiscard:j}){const{t:f}=re(["terminal"]),b=n.status,w=yt[b],R=b==="deleted",g=b==="untracked"&&r,k=n.name.includes(".")?"."+n.name.split(".").pop():"",x=m&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!R&&d(n.path,b),onContextMenu:v=>{v.preventDefault(),p==null||p(v,n,b)},style:{cursor:R?"not-allowed":"pointer"},title:n.path,children:[h&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:o||!1,onChange:v=>{v.stopPropagation(),h(n.path)},onClick:v=>v.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:xt(k),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,x&&e.jsx("span",{className:"git-file-dir",children:x})]}),e.jsx("span",{className:"git-file-status",style:{color:w.color},children:w.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.oldPath.split("/").pop()]}),g&&e.jsx("button",{className:`git-stage-btn ${i?"staging":""}`,onClick:v=>{v.stopPropagation(),i||r(n.path)},title:f("terminal:fileExplorer.stageFile"),disabled:i,children:i?"...":"+"}),j&&e.jsx("button",{className:"git-discard-btn",onClick:v=>{v.stopPropagation(),j(n,b)},title:b==="untracked"||b==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}),Ja=16,Xa=22,Qa=t.memo(function s({node:n,depth:l,expandedDirs:d,onToggleDir:r,selectedPath:i,onSelect:m,onStage:o,stagingPaths:h,checkedFiles:p,onToggleCheck:j,onContextMenu:f,onDirContextMenu:b,onDiscard:w}){const{t:R}=re(["terminal"]),g=l*Ja;if(!n.isDirectory){const x=n.file.status,v=yt[x];return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>x!=="deleted"&&m(n.file.path,x),onContextMenu:C=>{C.preventDefault(),f==null||f(C,n.file,x)},style:{paddingLeft:`${g+Xa}px`,cursor:x==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[j&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(p==null?void 0:p.has(n.file.path))||!1,onChange:C=>{C.stopPropagation(),j(n.file.path)},onClick:C=>C.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:xt(n.file.name.includes(".")?"."+n.file.name.split(".").pop():""),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:v.color},children:v.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.file.oldPath.split("/").pop()]}),x==="untracked"&&o&&e.jsx("button",{className:`git-stage-btn ${h!=null&&h.has(n.path)?"staging":""}`,onClick:C=>{C.stopPropagation(),h!=null&&h.has(n.path)||o(n.file.path)},title:R("terminal:fileExplorer.stageFile"),disabled:h==null?void 0:h.has(n.path),children:h!=null&&h.has(n.path)?"...":"+"}),w&&e.jsx("button",{className:"git-discard-btn",onClick:C=>{C.stopPropagation(),w(n.file,x)},title:x==="untracked"||x==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}const k=d.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${k?"expanded":""}`,style:{paddingLeft:`${g}px`},onClick:()=>r(n.path),onContextMenu:x=>{x.preventDefault(),x.stopPropagation(),b==null||b(x,n)},children:[e.jsx("span",{className:`tree-arrow ${k?"expanded":""}`,children:e.jsx(M,{name:"caret-right",size:10})}),e.jsx("img",{className:"tree-folder-icon",src:k?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:R("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),k&&e.jsx("div",{className:"tree-children",children:n.children.map(x=>e.jsx(s,{node:x,depth:l+1,expandedDirs:d,onToggleDir:r,selectedPath:i,onSelect:m,onStage:o,stagingPaths:h,checkedFiles:p,onToggleCheck:j,onContextMenu:f,onDirContextMenu:b,onDiscard:w},x.path))})]})}),Qt=t.memo(function({groupLabel:n,groupIcon:l,groupColor:d,files:r,treeNodes:i,viewMode:m,selectedPath:o,expandedDirs:h,onToggleDir:p,onFileSelect:j,onStageFile:f,onStageAll:b,stagingPaths:w,checkedFiles:R,onToggleCheck:g,onContextMenu:k,onDirContextMenu:x,onDiscardFile:v,onDiscardAll:C}){const{t:D}=re(["terminal"]);if(r.length===0)return null;const N=r.some(O=>O.status==="untracked"),U=N&&b&&r.length>0,_=w?r.every(O=>w.has(O.path)):!1;return e.jsxs("div",{className:"git-status-group",children:[e.jsxs("div",{className:"git-status-group-header",style:{color:d},children:[e.jsx("span",{className:"git-status-badge",style:{background:d},children:l}),n," (",r.length,")",U&&e.jsx("button",{className:`git-stage-all-btn ${_?"staging":""}`,onClick:O=>{O.stopPropagation(),_||b()},title:D("terminal:fileExplorer.stageAllUntracked"),disabled:_,children:_?"...":D("terminal:fileExplorer.stageAll")}),C&&e.jsxs("button",{className:"git-discard-all-btn",onClick:O=>{O.stopPropagation(),C()},title:N?`Delete all ${r.length} files`:`Discard all ${r.length} changes`,children:[e.jsx(M,{name:"revert",size:12})," All"]})]}),m==="tree"?e.jsx("div",{className:"git-tree-content",children:i.map(O=>e.jsx(Qa,{node:O,depth:0,expandedDirs:h,onToggleDir:p,selectedPath:o,onSelect:j,onStage:f,stagingPaths:w,checkedFiles:R,onToggleCheck:g,onContextMenu:k,onDirContextMenu:x,onDiscard:v},O.path))}):e.jsx("div",{className:"git-flat-content",children:r.map(O=>e.jsx(Ya,{file:O,isSelected:o===O.path,onSelect:j,onStage:O.status==="untracked"?f:void 0,isStaging:w==null?void 0:w.has(O.path),showDirPath:!0,isChecked:R==null?void 0:R.has(O.path),onToggleCheck:g,onContextMenu:k,onDiscard:v},O.path))})]})});function Za({gitStatus:s,loading:n,onFileSelect:l,selectedPath:d,onRefresh:r,onStageFiles:i,stagingPaths:m,currentFolder:o,onCommitComplete:h,mergeInProgress:p,mergingBranch:j,onMergeContinue:f,onMergeAbort:b,onConflictOpen:w,onRevealInTree:R}){const{t:g}=re(["terminal","common"]),[k,x]=t.useState("tree"),[v,C]=t.useState(new Set),[D,N]=t.useState(""),[U,_]=t.useState(""),[O,se]=t.useState(!1),[Q,T]=t.useState(new Set),[F,K]=t.useState(!1),[ne,ie]=t.useState(null),fe=t.useRef(null),{showToast:z}=Ys(),[I,$]=t.useState(null),[P,ee]=t.useState(null),[te,ge]=t.useState(null),je=t.useCallback((E,L)=>{ge({files:[E],label:E.name})},[]),c=t.useCallback(async()=>{if(!(!te||!o))try{const E=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:te.files.map(B=>({path:B.path,status:B.status})),directory:o})}),L=await E.json();E.ok&&L.success?(z("success","Discarded",`Reverted ${te.files.length} file(s)`),r()):z("error","Discard Failed",L.error||"Could not discard changes")}catch{z("error","Discard Failed","Network error")}finally{ge(null)}},[te,o,r,z]),G=t.useCallback((E,L,B)=>{E.preventDefault(),E.stopPropagation(),$({isOpen:!0,position:{x:E.clientX,y:E.clientY},file:L,status:B})},[]),ae=t.useCallback(async(E,L)=>{if(o)try{const B=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:E.path,status:L}],directory:o})}),pe=await B.json();B.ok&&pe.success?(z("success","Discarded",`Restored ${E.name}`),r()):z("error","Discard Failed",pe.error||"Could not discard changes")}catch{z("error","Discard Failed","Network error")}},[o,r,z]),ce=t.useCallback(async E=>{try{await navigator.clipboard.writeText(E),z("success","Copied","Full path copied")}catch{z("error","Copy Failed","Could not copy path")}},[z]),A=t.useCallback(async E=>{const L=o&&E.startsWith(o+"/")?E.slice(o.length+1):E;try{await navigator.clipboard.writeText(L),z("success","Copied","Relative path copied")}catch{z("error","Copy Failed","Could not copy path")}},[o,z]),S=t.useMemo(()=>{if(!I)return[];const{file:E,status:L}=I,B=[];return L==="conflict"&&w?B.push({id:"open-conflict",label:g("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>w(E.path)}):L!=="deleted"&&B.push({id:"open-file",label:g("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>l(E.path,L)}),L!=="conflict"&&B.push({id:"stage-file",label:g("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i([E.path])}}),B.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(L==="modified"||L==="deleted"||L==="renamed"||L==="conflict")&&B.push({id:"discard-changes",label:g("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{ae(E,L)}}),(L==="untracked"||L==="added")&&B.push({id:"delete-file",label:g("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{ae(E,L)}}),B.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),B.push({id:"copy-full-path",label:g("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{ce(E.path)}}),B.push({id:"copy-relative-path",label:g("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{A(E.path)}}),R&&L!=="deleted"&&B.push({id:"reveal-in-tree",label:g("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>R(E.path)}),B},[I,l,i,w,R,ae,ce,A,g]),q=t.useCallback((E,L)=>{E.preventDefault(),E.stopPropagation(),ee({isOpen:!0,position:{x:E.clientX,y:E.clientY},node:L})},[]),Z=t.useCallback(E=>!E.isDirectory&&E.file?[E.file]:E.children.flatMap(L=>Z(L)),[]),Te=t.useCallback(async E=>{if(!o)return;const L=Z(E);if(L.length!==0)try{const B=await W(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:L.map(ye=>({path:ye.path,status:ye.status})),directory:o})}),pe=await B.json();B.ok&&pe.success?(z("success","Discarded",`Reverted ${L.length} file(s) in ${E.name}`),r()):z("error","Discard Failed",pe.error||"Could not discard changes")}catch{z("error","Discard Failed","Network error")}},[o,Z,r,z]),ve=t.useMemo(()=>{if(!P)return[];const{node:E}=P,L=Z(E);return[{id:"discard-dir",label:`Discard Changes (${L.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{Te(E)}},{id:"stage-dir",label:`Stage All (${L.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i(L.map(B=>B.path))}}]},[P,Z,Te,i]),X=t.useCallback(E=>{C(L=>{const B=new Set(L);return B.has(E)?B.delete(E):B.add(E),B})},[]),{conflictFiles:xe,conflictTree:ze,changesFiles:Le,changesTree:bt,untrackedFiles:de,untrackedTree:ue,allDirPaths:Ee}=t.useMemo(()=>{if(!s||!s.isGitRepo||s.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const E=new Set,L=s.files.filter(De=>De.status==="conflict"),B=Lt(L);$t(B,E);const pe=s.files.filter(De=>De.status==="modified"||De.status==="added"||De.status==="deleted"||De.status==="renamed"),ye=Lt(pe);$t(ye,E);const Je=s.files.filter(De=>De.status==="untracked"),$e=Lt(Je);return $t($e,E),{conflictFiles:L,conflictTree:B,changesFiles:pe,changesTree:ye,untrackedFiles:Je,untrackedTree:$e,allDirPaths:E}},[s]);t.useEffect(()=>{C(Ee)},[Ee]),t.useEffect(()=>{s!=null&&s.files&&T(new Set(s.files.map(E=>E.path)))},[s==null?void 0:s.files]);const we=t.useCallback(()=>{Le.length!==0&&ge({files:Le,label:`${Le.length} changed files`})},[Le]),Ke=t.useCallback(()=>{de.length!==0&&ge({files:de,label:`${de.length} unversioned files`})},[de]),Oe=t.useCallback(()=>{xe.length!==0&&ge({files:xe,label:`${xe.length} conflicted files`})},[xe]),jt=xe.length>0;t.useEffect(()=>{if(ne){const E=ne.type==="error"?8e3:4e3,L=setTimeout(()=>ie(null),E);return()=>clearTimeout(L)}},[ne]);const We=t.useCallback(async()=>{const E=!O;if(se(E),E&&o){_(D);try{const B=await(await W(V(`/api/files/git-log-message?path=${encodeURIComponent(o)}`))).json();B.message&&N(B.message)}catch{}}else N(U)},[O,o,D,U]),ut=t.useCallback(E=>{T(L=>{const B=new Set(L);return B.has(E)?B.delete(E):B.add(E),B})},[]),qe=t.useCallback(()=>{if(!(s!=null&&s.files))return;const E=s.files.map(B=>B.path),L=E.every(B=>Q.has(B));T(L?new Set:new Set(E))},[s==null?void 0:s.files,Q]),Ye=t.useCallback(async E=>{if(!(!o||!D.trim()||Q.size===0||F)){K(!0),ie(null);try{const L=await W(V("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o,message:D.trim(),amend:O,paths:Array.from(Q)})}),B=await L.json();if(!L.ok||!B.success){ie({type:"error",text:B.error||"Commit failed"}),K(!1);return}if(E)try{const pe=await W(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o})}),ye=await pe.json();pe.ok&&ye.success?ie({type:"success",text:g("terminal:fileExplorer.committedAndPushed")}):ie({type:"error",text:g("terminal:fileExplorer.committedButPushFailed",{error:ye.error||"Unknown error"})})}catch{ie({type:"error",text:g("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else ie({type:"success",text:g("terminal:fileExplorer.committedSuccessfully")});N(""),_(""),se(!1),r(),h==null||h()}catch(L){ie({type:"error",text:L.message||"Commit failed"})}finally{K(!1)}}},[o,D,O,Q,F,r,h]);if(n)return e.jsx("div",{className:"git-changes-loading",children:g("terminal:fileExplorer.loadingGitStatus")});if(!s||!s.isGitRepo)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"package",size:32})}),e.jsx("div",{className:"git-empty-text",children:g("terminal:fileExplorer.notGitRepo")})]});if(s.files.length===0)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"sparkle",size:32})}),e.jsx("div",{className:"git-empty-text",children:g("terminal:fileExplorer.workingTreeClean")}),e.jsx("div",{className:"git-empty-branch",children:g("terminal:fileExplorer.onBranch",{branch:s.branch})})]});const ht=E=>{i([E])},vt=()=>{const E=de.map(L=>L.path);E.length>0&&i(E)},Ce=(E,L)=>{L==="conflict"&&w?w(E):l(E,L)};return e.jsxs("div",{className:"git-changes",children:[e.jsxs("div",{className:"git-changes-header",children:[e.jsxs("span",{className:"git-branch",children:[e.jsx("span",{className:"git-branch-icon",children:e.jsx(M,{name:"git-branch",size:12})}),s.branch]}),s.counts&&e.jsxs("div",{className:"git-changes-summary",children:[(s.counts.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[s.counts.conflict,"C"]}),s.counts.modified>0&&e.jsxs("span",{className:"git-count modified",children:[s.counts.modified,"M"]}),s.counts.added>0&&e.jsxs("span",{className:"git-count added",children:[s.counts.added,"A"]}),s.counts.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[s.counts.deleted,"D"]}),s.counts.untracked>0&&e.jsxs("span",{className:"git-count untracked",children:[s.counts.untracked,"?"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${k==="flat"?"active":""}`,onClick:()=>x("flat"),title:g("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${k==="tree"?"active":""}`,onClick:()=>x("tree"),title:g("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"git-refresh-btn",onClick:r,title:g("common:buttons.refresh"),children:e.jsx(M,{name:"refresh",size:12})})]}),p&&e.jsxs("div",{className:"git-merge-banner",children:[e.jsx("span",{className:"git-merge-banner-icon",children:"⚠"}),e.jsx("span",{className:"git-merge-banner-text",children:g("terminal:fileExplorer.mergeInProgress",{branch:j?` (${j})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:f,disabled:jt,title:g(jt?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:g("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:b,title:g("terminal:fileExplorer.abortMerge"),children:g("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(Qt,{groupLabel:g("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:xe,treeNodes:ze,viewMode:k,selectedPath:d,expandedDirs:v,onToggleDir:X,onFileSelect:Ce,checkedFiles:Q,onToggleCheck:ut,onContextMenu:G,onDirContextMenu:q,onDiscardFile:je,onDiscardAll:Oe}),e.jsx(Qt,{groupLabel:g("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:Le,treeNodes:bt,viewMode:k,selectedPath:d,expandedDirs:v,onToggleDir:X,onFileSelect:Ce,checkedFiles:Q,onToggleCheck:ut,onContextMenu:G,onDirContextMenu:q,onDiscardFile:je,onDiscardAll:we}),e.jsx(Qt,{groupLabel:g("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:de,treeNodes:ue,viewMode:k,selectedPath:d,expandedDirs:v,onToggleDir:X,onFileSelect:Ce,onStageFile:ht,onStageAll:vt,stagingPaths:m,checkedFiles:Q,onToggleCheck:ut,onContextMenu:G,onDirContextMenu:q,onDiscardFile:je,onDiscardAll:Ke})]}),e.jsxs("div",{className:"git-commit-panel",children:[e.jsxs("div",{className:"git-commit-options",children:[e.jsxs("label",{className:"git-commit-amend-label",children:[e.jsx("input",{type:"checkbox",className:"git-commit-amend-checkbox",checked:O,onChange:We}),g("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:g("terminal:fileExplorer.fileCount",{count:Q.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:qe,title:Q.size===s.files.length?g("terminal:fileExplorer.deselectAll"):g("terminal:fileExplorer.selectAll"),children:Q.size===s.files.length?g("terminal:fileExplorer.deselectAll"):g("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:fe,className:"git-commit-message",placeholder:g("terminal:fileExplorer.commitMessagePlaceholder"),value:D,onChange:E=>N(E.target.value),onKeyDown:E=>{(E.metaKey||E.ctrlKey)&&E.key==="Enter"&&(E.preventDefault(),Ye(!1)),(E.metaKey||E.ctrlKey)&&E.shiftKey&&E.key==="Enter"&&(E.preventDefault(),Ye(!0)),E.stopPropagation()},rows:3,disabled:F}),ne&&e.jsx("div",{className:`git-commit-status ${ne.type}`,children:ne.text}),e.jsxs("div",{className:"git-commit-actions",children:[e.jsx("button",{className:"git-commit-btn",onClick:()=>Ye(!1),disabled:!D.trim()||Q.size===0||F,title:g("terminal:fileExplorer.commitCtrlEnter"),children:g(F?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>Ye(!0),disabled:!D.trim()||Q.size===0||F,title:g("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:F?"...":g("terminal:fileExplorer.commitAndPush")})]})]}),I&&e.jsx(ct,{isOpen:I.isOpen,position:I.position,worldPosition:{x:0,z:0},actions:S,onClose:()=>$(null)}),P&&e.jsx(ct,{isOpen:P.isOpen,position:P.position,worldPosition:{x:0,z:0},actions:ve,onClose:()=>ee(null)}),te&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>ge(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:E=>E.stopPropagation(),children:[e.jsx("p",{children:te.files.some(E=>E.status==="untracked"||E.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:te.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:te.label}),"?"]})}),e.jsx("p",{className:"git-discard-confirm-hint",children:"This cannot be undone."}),e.jsxs("div",{className:"git-discard-confirm-actions",children:[e.jsx("button",{className:"git-discard-confirm-cancel",onClick:()=>ge(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:c,children:te.files.some(E=>E.status==="untracked"||E.status==="added")?"Delete":"Discard"})]})]})})]})}const tn=t.memo(Za,(s,n)=>s.loading!==n.loading||s.selectedPath!==n.selectedPath||s.stagingPaths!==n.stagingPaths||s.currentFolder!==n.currentFolder||s.mergeInProgress!==n.mergeInProgress||s.mergingBranch!==n.mergingBranch?!1:s.gitStatus===null&&n.gitStatus===null?!0:!(s.gitStatus===null||n.gitStatus===null||s.gitStatus.isGitRepo!==n.gitStatus.isGitRepo||s.gitStatus.branch!==n.gitStatus.branch||s.gitStatus.files.length!==n.gitStatus.files.length||s.gitStatus.mergeInProgress!==n.gitStatus.mergeInProgress));tn.displayName="GitChanges";const er=t.memo(function({tab:n,isActive:l,onSelect:d,onClose:r,onContextMenu:i}){const{t:m}=re(["terminal"]),o={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},h=t.useCallback(()=>{d(n.path)},[d,n.path]),p=t.useCallback(b=>{b.button===1&&(b.preventDefault(),b.stopPropagation(),r(n.path))},[r,n.path]),j=t.useCallback(b=>{b.preventDefault(),b.stopPropagation(),r(n.path)},[r,n.path]),f=t.useCallback(b=>{b.preventDefault(),b.stopPropagation(),i(b,n)},[i,n]);return e.jsxs("div",{className:`file-tab ${l?"active":""}`,onClick:h,onMouseDown:p,onContextMenu:f,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:es(o),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:j,title:m("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function tr(s){return typeof s.path=="string"&&s.path.startsWith("/")}function sr({tabs:s,activeTabPath:n,onSelectTab:l,onCloseTab:d,onCloseAllTabs:r,onShowGitHistory:i}){const{t:m}=re(["terminal"]),[o,h]=t.useState(null),p=t.useCallback((b,w)=>{h({isOpen:!0,position:{x:b.clientX,y:b.clientY},tab:w})},[]),j=t.useCallback(()=>h(null),[]),f=t.useMemo(()=>{if(!o)return[];const b=o.tab,w=!!i&&tr(b),R=[{id:"git-history",label:m("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!w,onClick:()=>{w&&i(b.path)}}];return r&&R.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:m("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(M,{name:"cross",size:14}),danger:!0,onClick:()=>r()}),R},[o,i,r,m]);return s.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:s.map(b=>e.jsx(er,{tab:b,isActive:n===b.path,onSelect:l,onClose:d,onContextMenu:p},b.path))}),o&&e.jsx(ct,{isOpen:o.isOpen,position:o.position,worldPosition:{x:0,z:0},actions:f,onClose:j})]})}const sn=t.memo(sr,(s,n)=>{if(s.activeTabPath!==n.activeTabPath||s.tabs.length!==n.tabs.length||s.onShowGitHistory!==n.onShowGitHistory||s.onCloseAllTabs!==n.onCloseAllTabs)return!1;for(let l=0;l<s.tabs.length;l++)if(s.tabs[l].path!==n.tabs[l].path)return!1;return!0});sn.displayName="FileTabs";const nr=t.memo(function({currentFolder:n,gitStatus:l,onBranchChanged:d,onMerge:r,onCompare:i,onPullConflicts:m}){const{t:o}=re(["terminal","common"]),[h,p]=t.useState(!1),[j,f]=t.useState(""),[b,w]=t.useState(!1),[R,g]=t.useState(""),[k,x]=t.useState(!1),[v,C]=t.useState(null),[D,N]=t.useState(null),U=t.useRef(null),_=t.useRef(null),O=t.useRef(null),{branches:se,loading:Q,operationInProgress:T,loadBranches:F,checkoutBranch:K,createBranch:ne,pullFromRemote:ie,pushToRemote:fe}=ts();t.useEffect(()=>{h&&n&&(F(n),setTimeout(()=>{var S;return(S=_.current)==null?void 0:S.focus()},50)),h||(f(""),w(!1),g(""),C(null))},[h,n,F]),t.useEffect(()=>{if(v){const S=v.type==="error"?8e3:3e3,q=setTimeout(()=>C(null),S);return()=>clearTimeout(q)}},[v]),t.useEffect(()=>{b&&setTimeout(()=>{var S;return(S=O.current)==null?void 0:S.focus()},50)},[b]),t.useEffect(()=>{if(!h)return;const S=Z=>{const Te=Z.target;!Te.closest(".branch-widget-selector")&&!Te.closest(".branch-widget-dropdown")&&p(!1)},q=Z=>{Z.key==="Escape"&&(Z.preventDefault(),Z.stopPropagation(),p(!1))};return document.addEventListener("click",S),document.addEventListener("keydown",q,!0),()=>{document.removeEventListener("click",S),document.removeEventListener("keydown",q,!0)}},[h]);const z=t.useCallback(async S=>{if(!n||T||S.isCurrent)return;const q=await K(n,S.name);q.success?(C({type:"success",text:o("terminal:fileExplorer.switchedToBranch",{branch:q.branch||S.name})}),d(),F(n)):C({type:"error",text:q.error||o("terminal:fileExplorer.checkoutFailed")})},[n,T,K,d,F]),I=t.useCallback(async()=>{if(!n||!R.trim()||T)return;const S=await ne(n,R.trim());S.success?(C({type:"success",text:o("terminal:fileExplorer.createdBranch",{branch:S.branch})}),w(!1),g(""),d(),F(n)):C({type:"error",text:S.error||o("terminal:fileExplorer.createBranchFailed")})},[n,R,T,ne,d,F]),$=t.useCallback(async()=>{if(!n||T)return;const S=await ie(n);S.success?(S.stashConflicts&&S.stashConflicts.length>0?(C({type:"error",text:`Pull succeeded but stash pop had conflicts: ${S.stashConflicts.length} file(s). Resolve manually.`}),m==null||m(S.stashConflicts),p(!1)):S.stashed?C({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):C({type:"success",text:o("terminal:fileExplorer.pullComplete")}),d(),F(n)):S.conflicts&&S.conflicts.length>0?(C({type:"error",text:`Pull conflicts: ${S.conflicts.length} file(s)`}),m==null||m(S.conflicts),p(!1)):C({type:"error",text:S.error||o("terminal:fileExplorer.pullFailed")})},[n,T,ie,d,F,m]),P=t.useCallback(async()=>{if(!n||T)return;const S=await fe(n);S.success?C({type:"success",text:o("terminal:fileExplorer.pushComplete")}):C({type:"error",text:S.error||o("terminal:fileExplorer.pushFailed")})},[n,T,fe]),[ee,te]=t.useState(!1),ge=t.useCallback(async()=>{if(!(!n||T||ee)){te(!0);try{const S=await W(V("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(S.ok)C({type:"success",text:"Fetch complete"}),d(),F(n);else{const q=await S.json().catch(()=>({error:"Fetch failed"}));C({type:"error",text:q.error||"Fetch failed"})}}catch{C({type:"error",text:"Fetch failed"})}finally{te(!1)}}},[n,T,ee,d,F]),je=(l==null?void 0:l.branch)||"unknown",c=!!T,G=t.useCallback((S,q)=>{q.isCurrent||(S.preventDefault(),S.stopPropagation(),N({isOpen:!0,position:{x:S.clientX,y:S.clientY},branch:q.name}))},[]),ae=t.useMemo(()=>{if(!D)return[];const S=!!T||(l==null?void 0:l.mergeInProgress);return[{id:"compare",label:o("terminal:fileExplorer.showDiffWith",{branch:D.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!T,onClick:()=>{i==null||i(D.branch),p(!1)}},{id:"merge",label:o("terminal:fileExplorer.mergeInto",{source:D.branch,target:je}),icon:"⤵",disabled:!!S,onClick:()=>{r&&r(D.branch),p(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:o("terminal:fileExplorer.checkoutBranch",{branch:D.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!T,onClick:()=>{const q=se.find(Z=>Z.name===D.branch);q&&z(q)}}]},[D,T,l==null?void 0:l.mergeInProgress,je,r,i,se,z]),ce=t.useMemo(()=>{const S=se.filter(Z=>!Z.isRemote);if(!j)return S;const q=j.toLowerCase();return S.filter(Z=>Z.name.toLowerCase().includes(q))},[se,j]),A=t.useMemo(()=>{const S=se.filter(Z=>Z.isRemote);if(!j)return S;const q=j.toLowerCase();return S.filter(Z=>Z.name.toLowerCase().includes(q))},[se,j]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:S=>{S.stopPropagation(),p(!h)},title:`Branch: ${je}`,children:[e.jsx("svg",{className:"branch-widget-icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M5 3.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Zm0 2.122a2.25 2.25 0 1 0-1 0v1.836A2.25 2.25 0 0 0 5.75 9.5h1.378a2.251 2.251 0 1 0 0-1H5.75a1.25 1.25 0 0 1-1.25-1.25V5.372Zm7.75 4.878a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3-8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"})}),e.jsx("span",{className:"branch-widget-name",children:je}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),h&&e.jsxs("div",{className:"branch-widget-dropdown",ref:U,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:_,type:"text",className:"branch-widget-search-input",placeholder:o("terminal:fileExplorer.searchBranches"),value:j,onChange:S=>f(S.target.value),onKeyDown:S=>S.stopPropagation()})}),v&&e.jsx("div",{className:`branch-widget-status ${v.type}`,children:v.text}),e.jsx("div",{className:"branch-widget-section-header",children:o("terminal:fileExplorer.actions")}),e.jsxs("div",{className:"branch-widget-actions",children:[e.jsxs("div",{className:`branch-widget-action-item ${c||ee?"disabled":""}`,onClick:ge,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 13l-3-3h2V6h2v4h2l-3 3zM8 3l3 3h-2v4H7V6H5l3-3z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:ee?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${c?"disabled":""}`,onClick:$,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 12l-4-4h2.5V3h3v5H12L8 12z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(T==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),e.jsxs("div",{className:`branch-widget-action-item ${c?"disabled":""}`,onClick:P,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 4l4 4h-2.5v5h-3V8H4l4-4z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(T==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${c?"disabled":""}`,onClick:()=>{c||w(!b)},children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 2v5H3v2h5v5h2V9h5V7H10V2H8z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o("terminal:fileExplorer.newBranch")})]})]}),b&&e.jsxs("div",{className:"branch-widget-new-branch",children:[e.jsx("input",{ref:O,type:"text",className:"branch-widget-new-branch-input",placeholder:o("terminal:fileExplorer.branchNamePlaceholder"),value:R,onChange:S=>g(S.target.value),onKeyDown:S=>{S.stopPropagation(),S.key==="Enter"&&I(),S.key==="Escape"&&(w(!1),g(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:I,disabled:!R.trim()||c,children:T==="create"?"...":o("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[o("terminal:fileExplorer.localBranches"),Q&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",o("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[ce.length===0&&!Q&&e.jsx("div",{className:"branch-widget-empty",children:o("terminal:fileExplorer.noBranchesFound")}),ce.map(S=>e.jsxs("div",{className:`branch-widget-branch-item ${S.isCurrent?"current":""} ${c?"disabled":""}`,onClick:()=>z(S),onContextMenu:q=>G(q,S),title:S.lastMessage||S.name,children:[e.jsxs("span",{className:"branch-widget-branch-name",children:[S.isCurrent&&e.jsx("span",{className:"branch-widget-current-marker",children:"*"}),S.name]}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))]}),A.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>x(!k),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:k?"▾":"▸"}),o("terminal:fileExplorer.remoteBranches",{count:A.length})]}),k&&e.jsx("div",{className:"branch-widget-branch-list",children:A.map(S=>e.jsxs("div",{className:`branch-widget-branch-item remote ${c?"disabled":""}`,onClick:()=>z(S),onContextMenu:q=>G(q,S),title:S.lastMessage||S.name,children:[e.jsx("span",{className:"branch-widget-branch-name",children:S.name}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))})]})]}),D&&e.jsx(ct,{isOpen:D.isOpen,position:D.position,worldPosition:{x:0,z:0},actions:ae,onClose:()=>N(null)})]})});function ar(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function It(s,n){if(!s)return"";const l=Is.languages[n];return l?Is.highlight(s,l,n):ar(s)}function rr(s){const n=[],l=s.split(`
|
|
9
9
|
`);let d=[],r=!1,i=[],m=[],o=!1;for(const h of l)h.startsWith("<<<<<<<")?(d.length>0&&(n.push({type:"unchanged",content:d.join(`
|
|
10
10
|
`)}),d=[]),r=!0,o=!1,i=[],m=[]):h.startsWith("=======")&&r?o=!0:h.startsWith(">>>>>>>")&&r?(n.push({type:"conflict",ours:i.join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as At,i as yt,aw as Et,a1 as xt,a2 as Ct,c9 as Mt,ca as Ft,aF as wt,r as d,X as St,S as me,cb as vt,cc as fe,s as J,cd as Bt,j as f,I as ne,ce as Ve,cf as It,a6 as _t,cg as Dt,ch as kt,ci as Ee,al as Be,W as Rt,p as nt,u as Fe,cj as Je}from"./main-DZgTocNE.js";import{ck as Ls,cl as $s,cm as js,cn as Ns,co as Ps}from"./main-DZgTocNE.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function q(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&it(t)=="[object Boolean]"}function ct(t){return typeof t=="object"}function $t(t){return ct(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let c=ot(r);this._keys.push(c),this._keyMap[c.id]=c,n+=c.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,c=1,i=null;if(q(t)||re(t))r=t,e=Ze(t),n=_e(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(c=t.weight,c<=0))throw new Error(Ot(o));e=Ze(o),n=_e(o),i=t.getFn}return{path:e,id:n,weight:c,src:r,getFn:i}}function Ze(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const c=(i,o,a)=>{if(G(i))if(!o[a])n.push(i);else{let u=o[a];const l=i[u];if(!G(l))return;if(a===o.length-1&&(q(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)c(l[h],o,a+1)}else o.length&&c(l,o,a+1)}};return c(t,q(e)?e.split("."):e,0),r?n:n[0]}const Qt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={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},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(c){const i=c.match(Yt).length;if(n.has(i))return n.get(i);const o=1/Math.pow(i,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(i,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,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((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,q(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();q(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!G(e)||Ie(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((c,i)=>{let o=c.getFn?c.getFn(e):this.getFn(e,c.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(q(h)&&!Ie(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,x)=>{u.push({nestedArrIndex:x,value:E})})}r.$[i]=a}else if(q(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[i]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const c=new Le({getFn:n,fieldNormWeight:r});return c.setKeys(t.map(ot)),c.setSources(e),c.create(),c}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:c}=t,i=new Le({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(c),i}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:c=y.distance,ignoreLocation:i=y.ignoreLocation}={}){const o=e/t.length;if(i)return o;const a=Math.abs(r-n);return c?o+a/c:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,c=-1,i=0;for(let o=t.length;i<o;i+=1){let a=t[i];a&&r===-1?r=i:!a&&r!==-1&&(c=i-1,c-r+1>=e&&n.push([r,c]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const le=32;function Zt(t,e,n,{location:r=y.location,distance:c=y.distance,threshold:i=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let g=i,m=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,m))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:c,ignoreLocation:l});if(g=Math.min($,g),m=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}m=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:c,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,v=Array(H+2);v[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),v[R]=(v[R+1]<<1|1)&O,$&&(v[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),v[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:c,ignoreLocation:l}),Q<=g)){if(g=Q,m=X,m<=x)break;ae=Math.max(1,2*x-m)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:c,ignoreLocation:l})>g)break;j=v}const ce={isMatch:m>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ce.indices=$):ce.isMatch=!1}return ce}function qt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const c=t.charAt(n);e[c]=(e[c]||0)|1<<r-n-1}return e}const Ce=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 ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,m)=>{this.chunks.push({pattern:g,alphabet:qt(g),startIndex:m})},x=this.pattern.length;if(x>le){let g=0;const m=x%le,S=x-m;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(m){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return c&&(S.indices=[[0,e.length-1]]),S}const{location:i,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=Zt(e,S,w,{location:i+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:c,ignoreLocation:h});j&&(g=!0),x+=Q,j&&W&&(E=[...E,...W])});let m={isMatch:g,score:g?x/this.chunks.length:1};return g&&c&&(m.indices=E),m}}class ie{constructor(e){this.pattern=e}static isMultiMatch(e){return qe(e,this.multiRegex)}static isSingleMatch(e){return qe(e,this.singleRegex)}search(){}}function qe(t,e){const n=t.match(e);return n?n[1]:null}class es extends ie{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ie{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ie{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ie{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ie{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class cs extends ie{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ie{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:c,includeMatches:i,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 ht extends ie{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const c=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,c.push([r,n-1]);const o=!!c.length;return{isMatch:o,score:o?0:1,indices:c}}}const De=[es,ht,ss,ns,cs,rs,ts,lt],et=De.length,is=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(is).filter(i=>i&&!!i.trim()),c=[];for(let i=0,o=r.length;i<o;i+=1){const a=r[i];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(c.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){c.push(new h(E,e));break}}}return c})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:c=y.includeMatches,minMatchCharLength:i=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c,minMatchCharLength:i,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:c,ignoreDiacritics:i}=this.options;e=c?e:e.toLowerCase(),e=i?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,g=E.length;x<g;x+=1){const m=E[x],{isMatch:S,indices:w,score:T}=m.search(e);if(S){if(o+=1,u+=T,r){const j=m.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let c=ke[n];if(c.condition(t,e))return new c(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&ct(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=c=>{let i=Object.keys(c);const o=ds(c);if(!o&&i.length>1&&!Te(c))return r(tt(c));if(fs(c)){const u=o?c[be.PATH]:i[0],l=o?c[be.PATTERN]:c[u];if(!q(l))throw new Error(Nt(u));const h={keyId:_e(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:i[0]};return i.forEach(u=>{const l=c[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:c,norm:i,score:o})=>{const a=c?c.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:i))}),n.score=r})}function ms(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:c,value:i}=r;let o={indices:c,value:i};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ps(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const c=[];return n&&c.push(ms),r&&c.push(ps),t.map(i=>{const{idx:o}=i,a={item:e[o],refIndex:o};return c.length&&c.forEach(u=>{u(i,a)}),a})}class Z{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){G(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,c=this._docs.length;r<c;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,c-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:c,shouldSort:i,sortFn:o,ignoreFieldNorm:a}=this.options;let u=q(e)?q(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),i&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:c})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,c=[];return r.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=n.searchIn(i);u&&c.push({item:i,idx:o,matches:[{score:l,value:i,norm:a,indices:h}]})}),c}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const g=a.children[E],m=r(g,u,l);if(m.length)h.push(...m);else if(a.operator===Me.AND)return[]}return h},c=this._myIndex.records,i={},o=[];return c.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(i[u]||(i[u]={idx:u,item:a,matches:[]},o.push(i[u])),l.forEach(({matches:h})=>{i[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:c}=this._myIndex,i=[];return c.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&i.push({idx:a,item:o,matches:u})}),i}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let c=[];if(re(n))n.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=r.searchIn(i);u&&c.push({score:l,key:e,value:i,idx:o,norm:a,indices:h})});else{const{v:i,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(i);a&&c.push({score:u,key:e,value:i,norm:o,indices:l})}return c}}Z.version="7.1.0";Z.createIndex=at;Z.parseIndex=Jt;Z.config=y;Z.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const c=await n.json().catch(()=>({}));throw new Error(c.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(me.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(me.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(me.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),g=Mt(),m=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(c);Q.current=c;const W=d.useRef(i);W.current=i;const oe=d.useRef(o);oe.current=o;const ce=d.useRef(a);ce.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,v]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(me.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),v(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let p=!1;const C=setTimeout(()=>{ys(s).then(F=>{p||O(F)}).catch(()=>{p||O([])})},250);return()=>{p=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),vt(me.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const p=fe.indexOf($e.current),C=fe[(p+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{v(0)},[M]);const Se=J.getShortcuts(),ge=d.useMemo(()=>t?Bt():{},[t]),pe=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),p=Se.find(C=>C.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?Ve(s):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:p?Ve(p):"Ctrl+K",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const p=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(p)],F=C.map(Y=>Y.split("/").pop()||Y),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),B.length>0&&(k+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),J.selectAgent(s.id),J.getState().viewMode!=="flat"&&J.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var p;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((p=s.directories)==null?void 0:p.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{w.current(),J.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const p of he)p._agentId&&s.set(p._agentId,p);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const p of h.values()){const C=J.getAreaForAgent(p.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(p):s.set(C.id,[p])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const p of m)s.has(p.agentId)||s.set(p.agentId,p.timestamp);return s},[m]),ve=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),p=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),C=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const B of C){const k=(Ne.get(B.id)||[]).slice().sort(p).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const p=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${F} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:p}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ce.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?J.openTestsBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,x]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],p=new Set,C=[];for(const F of s){if(p.has(F.filePath))continue;p.add(F.filePath);const B=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(J.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(F.filePath.startsWith(U)){J.setFileViewerPath(F.filePath),W.current(P.id);return}J.selectAgent(F.agentId)}}),C.length>=50)break}return C},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const p=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:p,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),J.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new Z(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new Z(pe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[pe]),Qe=d.useMemo(()=>new Z(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new Z(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new Z(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...pe.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),p=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),B=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of p){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,We,He,pe,he,Ae,ye,Oe,ge]),V=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return ve.flatMap(s=>s.agents);case"all":default:return de}},[M,de,ve]);d.useEffect(()=>{H>=V.length&&v(Math.max(0,V.length-1))},[V.length,H]);const mt=d.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const p=s.key.toLowerCase();v(p==="p"?C=>C>0?C-1:V.length-1:C=>C<V.length-1?C+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),v(p=>p>0?p-1:V.length-1);break;case"ArrowDown":s.preventDefault(),v(p=>p<V.length-1?p+1:0);break;case"Enter":s.preventDefault(),V[H]&&V[H].action();break}},[V,H]),pt=d.useCallback((s,p)=>{if(!p||!s)return s;const C=s.toLowerCase(),F=p.toLowerCase(),B=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&B.push(s.slice(L,k)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+p.length))),L=k+p.length,k=C.indexOf(F,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:v,results:V,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:ve,handleKeyDown:mt,highlightMatch:pt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:c},i){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:i,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),c()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(c=>f.jsx("button",{type:"button",role:"tab","aria-selected":c===e,tabIndex:-1,className:`spotlight-tab${c===e?" active":""}`,onClick:()=>n(c),children:r(`terminal:spotlight.tabs.${c}`)},c)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),vs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:c,areaSections:i,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const m=()=>{h.current=!0};return g.addEventListener("mousemove",m),()=>{g.removeEventListener("mousemove",m)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},x=d.useMemo(()=>{const g=[];let m=null,S=[];return e.forEach((w,T)=>{w.type!==m&&(m!==null&&S.length>0&&g.push([m,S]),m=w.type,S=[]),S.push({result:w,index:T})}),m!==null&&S.length>0&&g.push([m,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const m=g.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),c==="areas"){if(i.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:i.map(m=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:m.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:m.areaName}),f.jsx("span",{className:"spotlight-area-count",children:m.agents.length})]}),m.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):m.agents.map(S=>{const w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},m.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:x.map(([g,m])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),m.map(({result:S,index:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),Bs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),g=d.useRef(0),{query:m,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ce,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var v,M;(v=h.current)==null||v.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${v.height}px`,R.style.top=`${v.offsetTop}px`)};return M(),v.addEventListener("resize",M),v.addEventListener("scroll",M),()=>{v.removeEventListener("resize",M),v.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const v=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=d.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:m,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(vs,{ref:x,results:j,selectedIndex:w,query:m,activeTab:Q,areaSections:ce,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,vs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
|
|
1
|
+
import{h as At,i as yt,aw as Et,a1 as xt,a2 as Ct,c9 as Mt,ca as Ft,aF as wt,r as d,X as St,S as me,cb as vt,cc as fe,s as J,cd as Bt,j as f,I as ne,ce as Ve,cf as It,a6 as _t,cg as Dt,ch as kt,ci as Ee,al as Be,W as Rt,p as nt,u as Fe,cj as Je}from"./main-BDtz2sl7.js";import{ck as Ls,cl as $s,cm as js,cn as Ns,co as Ps}from"./main-BDtz2sl7.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function q(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&it(t)=="[object Boolean]"}function ct(t){return typeof t=="object"}function $t(t){return ct(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let c=ot(r);this._keys.push(c),this._keyMap[c.id]=c,n+=c.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,c=1,i=null;if(q(t)||re(t))r=t,e=Ze(t),n=_e(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(c=t.weight,c<=0))throw new Error(Ot(o));e=Ze(o),n=_e(o),i=t.getFn}return{path:e,id:n,weight:c,src:r,getFn:i}}function Ze(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const c=(i,o,a)=>{if(G(i))if(!o[a])n.push(i);else{let u=o[a];const l=i[u];if(!G(l))return;if(a===o.length-1&&(q(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)c(l[h],o,a+1)}else o.length&&c(l,o,a+1)}};return c(t,q(e)?e.split("."):e,0),r?n:n[0]}const Qt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={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},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(c){const i=c.match(Yt).length;if(n.has(i))return n.get(i);const o=1/Math.pow(i,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(i,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,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((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,q(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();q(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!G(e)||Ie(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((c,i)=>{let o=c.getFn?c.getFn(e):this.getFn(e,c.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(q(h)&&!Ie(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,x)=>{u.push({nestedArrIndex:x,value:E})})}r.$[i]=a}else if(q(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[i]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const c=new Le({getFn:n,fieldNormWeight:r});return c.setKeys(t.map(ot)),c.setSources(e),c.create(),c}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:c}=t,i=new Le({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(c),i}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:c=y.distance,ignoreLocation:i=y.ignoreLocation}={}){const o=e/t.length;if(i)return o;const a=Math.abs(r-n);return c?o+a/c:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,c=-1,i=0;for(let o=t.length;i<o;i+=1){let a=t[i];a&&r===-1?r=i:!a&&r!==-1&&(c=i-1,c-r+1>=e&&n.push([r,c]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const le=32;function Zt(t,e,n,{location:r=y.location,distance:c=y.distance,threshold:i=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let g=i,m=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,m))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:c,ignoreLocation:l});if(g=Math.min($,g),m=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}m=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:c,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,v=Array(H+2);v[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),v[R]=(v[R+1]<<1|1)&O,$&&(v[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),v[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:c,ignoreLocation:l}),Q<=g)){if(g=Q,m=X,m<=x)break;ae=Math.max(1,2*x-m)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:c,ignoreLocation:l})>g)break;j=v}const ce={isMatch:m>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ce.indices=$):ce.isMatch=!1}return ce}function qt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const c=t.charAt(n);e[c]=(e[c]||0)|1<<r-n-1}return e}const Ce=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 ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,m)=>{this.chunks.push({pattern:g,alphabet:qt(g),startIndex:m})},x=this.pattern.length;if(x>le){let g=0;const m=x%le,S=x-m;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(m){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return c&&(S.indices=[[0,e.length-1]]),S}const{location:i,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=Zt(e,S,w,{location:i+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:c,ignoreLocation:h});j&&(g=!0),x+=Q,j&&W&&(E=[...E,...W])});let m={isMatch:g,score:g?x/this.chunks.length:1};return g&&c&&(m.indices=E),m}}class ie{constructor(e){this.pattern=e}static isMultiMatch(e){return qe(e,this.multiRegex)}static isSingleMatch(e){return qe(e,this.singleRegex)}search(){}}function qe(t,e){const n=t.match(e);return n?n[1]:null}class es extends ie{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ie{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ie{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ie{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ie{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class cs extends ie{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ie{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:c,includeMatches:i,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 ht extends ie{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const c=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,c.push([r,n-1]);const o=!!c.length;return{isMatch:o,score:o?0:1,indices:c}}}const De=[es,ht,ss,ns,cs,rs,ts,lt],et=De.length,is=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(is).filter(i=>i&&!!i.trim()),c=[];for(let i=0,o=r.length;i<o;i+=1){const a=r[i];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(c.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){c.push(new h(E,e));break}}}return c})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:c=y.includeMatches,minMatchCharLength:i=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c,minMatchCharLength:i,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:c,ignoreDiacritics:i}=this.options;e=c?e:e.toLowerCase(),e=i?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,g=E.length;x<g;x+=1){const m=E[x],{isMatch:S,indices:w,score:T}=m.search(e);if(S){if(o+=1,u+=T,r){const j=m.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let c=ke[n];if(c.condition(t,e))return new c(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&ct(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=c=>{let i=Object.keys(c);const o=ds(c);if(!o&&i.length>1&&!Te(c))return r(tt(c));if(fs(c)){const u=o?c[be.PATH]:i[0],l=o?c[be.PATTERN]:c[u];if(!q(l))throw new Error(Nt(u));const h={keyId:_e(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:i[0]};return i.forEach(u=>{const l=c[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:c,norm:i,score:o})=>{const a=c?c.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:i))}),n.score=r})}function ms(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:c,value:i}=r;let o={indices:c,value:i};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ps(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const c=[];return n&&c.push(ms),r&&c.push(ps),t.map(i=>{const{idx:o}=i,a={item:e[o],refIndex:o};return c.length&&c.forEach(u=>{u(i,a)}),a})}class Z{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){G(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,c=this._docs.length;r<c;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,c-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:c,shouldSort:i,sortFn:o,ignoreFieldNorm:a}=this.options;let u=q(e)?q(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),i&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:c})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,c=[];return r.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=n.searchIn(i);u&&c.push({item:i,idx:o,matches:[{score:l,value:i,norm:a,indices:h}]})}),c}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const g=a.children[E],m=r(g,u,l);if(m.length)h.push(...m);else if(a.operator===Me.AND)return[]}return h},c=this._myIndex.records,i={},o=[];return c.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(i[u]||(i[u]={idx:u,item:a,matches:[]},o.push(i[u])),l.forEach(({matches:h})=>{i[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:c}=this._myIndex,i=[];return c.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&i.push({idx:a,item:o,matches:u})}),i}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let c=[];if(re(n))n.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=r.searchIn(i);u&&c.push({score:l,key:e,value:i,idx:o,norm:a,indices:h})});else{const{v:i,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(i);a&&c.push({score:u,key:e,value:i,norm:o,indices:l})}return c}}Z.version="7.1.0";Z.createIndex=at;Z.parseIndex=Jt;Z.config=y;Z.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const c=await n.json().catch(()=>({}));throw new Error(c.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(me.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(me.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(me.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),g=Mt(),m=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(c);Q.current=c;const W=d.useRef(i);W.current=i;const oe=d.useRef(o);oe.current=o;const ce=d.useRef(a);ce.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,v]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(me.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),v(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let p=!1;const C=setTimeout(()=>{ys(s).then(F=>{p||O(F)}).catch(()=>{p||O([])})},250);return()=>{p=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),vt(me.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const p=fe.indexOf($e.current),C=fe[(p+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{v(0)},[M]);const Se=J.getShortcuts(),ge=d.useMemo(()=>t?Bt():{},[t]),pe=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),p=Se.find(C=>C.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?Ve(s):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:p?Ve(p):"Ctrl+K",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const p=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(p)],F=C.map(Y=>Y.split("/").pop()||Y),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),B.length>0&&(k+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),J.selectAgent(s.id),J.getState().viewMode!=="flat"&&J.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var p;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((p=s.directories)==null?void 0:p.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{w.current(),J.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const p of he)p._agentId&&s.set(p._agentId,p);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const p of h.values()){const C=J.getAreaForAgent(p.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(p):s.set(C.id,[p])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const p of m)s.has(p.agentId)||s.set(p.agentId,p.timestamp);return s},[m]),ve=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),p=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),C=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const B of C){const k=(Ne.get(B.id)||[]).slice().sort(p).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const p=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${F} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:p}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ce.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?J.openTestsBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,x]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],p=new Set,C=[];for(const F of s){if(p.has(F.filePath))continue;p.add(F.filePath);const B=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(J.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(F.filePath.startsWith(U)){J.setFileViewerPath(F.filePath),W.current(P.id);return}J.selectAgent(F.agentId)}}),C.length>=50)break}return C},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const p=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:p,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),J.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new Z(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new Z(pe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[pe]),Qe=d.useMemo(()=>new Z(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new Z(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new Z(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...pe.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),p=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),B=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of p){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,We,He,pe,he,Ae,ye,Oe,ge]),V=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return ve.flatMap(s=>s.agents);case"all":default:return de}},[M,de,ve]);d.useEffect(()=>{H>=V.length&&v(Math.max(0,V.length-1))},[V.length,H]);const mt=d.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const p=s.key.toLowerCase();v(p==="p"?C=>C>0?C-1:V.length-1:C=>C<V.length-1?C+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),v(p=>p>0?p-1:V.length-1);break;case"ArrowDown":s.preventDefault(),v(p=>p<V.length-1?p+1:0);break;case"Enter":s.preventDefault(),V[H]&&V[H].action();break}},[V,H]),pt=d.useCallback((s,p)=>{if(!p||!s)return s;const C=s.toLowerCase(),F=p.toLowerCase(),B=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&B.push(s.slice(L,k)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+p.length))),L=k+p.length,k=C.indexOf(F,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:v,results:V,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:ve,handleKeyDown:mt,highlightMatch:pt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:c},i){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:i,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),c()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(c=>f.jsx("button",{type:"button",role:"tab","aria-selected":c===e,tabIndex:-1,className:`spotlight-tab${c===e?" active":""}`,onClick:()=>n(c),children:r(`terminal:spotlight.tabs.${c}`)},c)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),vs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:c,areaSections:i,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const m=()=>{h.current=!0};return g.addEventListener("mousemove",m),()=>{g.removeEventListener("mousemove",m)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},x=d.useMemo(()=>{const g=[];let m=null,S=[];return e.forEach((w,T)=>{w.type!==m&&(m!==null&&S.length>0&&g.push([m,S]),m=w.type,S=[]),S.push({result:w,index:T})}),m!==null&&S.length>0&&g.push([m,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const m=g.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),c==="areas"){if(i.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:i.map(m=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:m.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:m.areaName}),f.jsx("span",{className:"spotlight-area-count",children:m.agents.length})]}),m.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):m.agents.map(S=>{const w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},m.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:x.map(([g,m])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),m.map(({result:S,index:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),Bs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),g=d.useRef(0),{query:m,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ce,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var v,M;(v=h.current)==null||v.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${v.height}px`,R.style.top=`${v.offsetTop}px`)};return M(),v.addEventListener("resize",M),v.addEventListener("scroll",M),()=>{v.removeEventListener("resize",M),v.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const v=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=d.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:m,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(vs,{ref:x,results:j,selectedIndex:w,query:m,activeTab:Q,areaSections:ce,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,vs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
|